From 28ef236f0e878523f0c36544136d2516d14764ee Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 29 Apr 2014 11:17:07 +0200 Subject: [PATCH] Don't allow setting a new return position if there already is one and we haven't reached it yet --- apps/openmw/mwmechanics/aiwander.cpp | 42 +++++++++++++++++----------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 722010686..7120ff5af 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -341,26 +341,29 @@ namespace MWMechanics mChooseAction = false; mIdleNow = false; - Ogre::Vector3 destNodePos = mReturnPosition; + if (!mPathFinder.isPathConstructed()) + { + Ogre::Vector3 destNodePos = mReturnPosition; - ESM::Pathgrid::Point dest; - dest.mX = destNodePos[0]; - dest.mY = destNodePos[1]; - dest.mZ = destNodePos[2]; + ESM::Pathgrid::Point dest; + dest.mX = destNodePos[0]; + dest.mY = destNodePos[1]; + dest.mZ = destNodePos[2]; - // actor position is already in world co-ordinates - ESM::Pathgrid::Point start; - start.mX = pos.pos[0]; - start.mY = pos.pos[1]; - start.mZ = pos.pos[2]; + // actor position is already in world co-ordinates + ESM::Pathgrid::Point start; + start.mX = pos.pos[0]; + start.mY = pos.pos[1]; + start.mZ = pos.pos[2]; - // don't take shortcuts for wandering - mPathFinder.buildPath(start, dest, actor.getCell(), false); + // don't take shortcuts for wandering + mPathFinder.buildPath(start, dest, actor.getCell(), false); - if(mPathFinder.isPathConstructed()) - { - mMoveNow = false; - mWalking = true; + if(mPathFinder.isPathConstructed()) + { + mMoveNow = false; + mWalking = true; + } } } @@ -529,6 +532,7 @@ namespace MWMechanics mMoveNow = false; mWalking = false; mChooseAction = true; + mHasReturnPosition = false; } return false; // AiWander package not yet completed @@ -615,7 +619,11 @@ namespace MWMechanics void AiWander::setReturnPosition(const Ogre::Vector3& position) { - mHasReturnPosition = true; mReturnPosition = position; + if (!mHasReturnPosition) + { + mHasReturnPosition = true; + mReturnPosition = position; + } } void AiWander::getRandomIdle()