diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index 2d7b8b9f6..f655fee85 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -68,7 +68,6 @@ namespace MWMechanics if (mRemainingDuration <= 0) { mRemainingDuration = mDuration; - mStarted = false; // Reset to false so this package will build path again when repeating return true; } } @@ -100,7 +99,6 @@ namespace MWMechanics if(pathTo(actor,point,duration)) //Returns true on path complete { mRemainingDuration = mDuration; - mStarted = false; // Reset to false so this package will build path again when repeating return true; } mMaxDist = 450; diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index dc23f922c..34cf9b921 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -51,7 +51,7 @@ bool MWMechanics::AiPackage::getRepeat() const return false; } -MWMechanics::AiPackage::AiPackage() : mTimer(0.26f), mStarted(false) { //mTimer starts at .26 to force initial pathbuild +MWMechanics::AiPackage::AiPackage() : mTimer(0.26f) { //mTimer starts at .26 to force initial pathbuild } @@ -79,14 +79,8 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po //*********************** if(mTimer > 0.25) { - const ESM::Cell *cell = actor.getCell()->getCell(); - // If repeating an AI package (mStarted has been set to false again), build a new path if needed so package doesn't immediately end - if (!mStarted && distance(pos.pos, dest) > 10) { - mStarted = true; - mPathFinder.buildSyncedPath(pos.pos, dest, actor.getCell(), true); //Rebuild path, in case the target has moved - mPrevDest = dest; - } - else if (doesPathNeedRecalc(dest, cell)) { //Only rebuild path if it's moved + const ESM::Cell *cell = actor.getCell()->getCell(); + if (doesPathNeedRecalc(dest, cell)) { //Only rebuild path if it's moved mPathFinder.buildSyncedPath(pos.pos, dest, actor.getCell(), true); //Rebuild path, in case the target has moved mPrevDest = dest; } @@ -146,7 +140,7 @@ void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float dur bool MWMechanics::AiPackage::doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell) { - return distance(mPrevDest, dest) > 10; + return mPathFinder.getPath().empty() || (distance(mPrevDest, dest) > 10); } bool MWMechanics::AiPackage::isTargetMagicallyHidden(const MWWorld::Ptr& target) diff --git a/apps/openmw/mwmechanics/aipackage.hpp b/apps/openmw/mwmechanics/aipackage.hpp index 277629770..637d4f066 100644 --- a/apps/openmw/mwmechanics/aipackage.hpp +++ b/apps/openmw/mwmechanics/aipackage.hpp @@ -108,9 +108,6 @@ namespace MWMechanics float mTimer; - // Set to true once package starts actually being executed - bool mStarted; - ESM::Pathgrid::Point mPrevDest; private: diff --git a/apps/openmw/mwmechanics/aitravel.cpp b/apps/openmw/mwmechanics/aitravel.cpp index 5375644be..1585a3007 100644 --- a/apps/openmw/mwmechanics/aitravel.cpp +++ b/apps/openmw/mwmechanics/aitravel.cpp @@ -58,13 +58,9 @@ namespace MWMechanics if (!isWithinMaxRange(osg::Vec3f(mX, mY, mZ), pos.asVec3())) return false; - if (!mStarted) - mStarted = true; - if (pathTo(actor, ESM::Pathgrid::Point(static_cast(mX), static_cast(mY), static_cast(mZ)), duration)) { actor.getClass().getMovementSettings(actor).mPosition[1] = 0; - mStarted = false; // Reset to false so this package will build path again when repeating return true; } return false;