From 3897c49e30920cb6bd40c2f3614b9f3346650943 Mon Sep 17 00:00:00 2001 From: Allofich Date: Sat, 18 Feb 2017 01:38:21 +0900 Subject: [PATCH] Fix loading 0-duration Follow and Escort packages (Fixes #3755) --- apps/openmw/mwmechanics/aiescort.cpp | 21 +++++++++++---------- apps/openmw/mwmechanics/aifollow.cpp | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index f655fee85..4c9b5fd4f 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -45,8 +45,8 @@ namespace MWMechanics , mCellY(std::numeric_limits::max()) { // mDuration isn't saved in the save file, so just giving it "1" for now if the package has a duration. - // The exact value of mDuration only matters for repeating packages - if (mRemainingDuration != 0) + // The exact value of mDuration only matters for repeating packages. + if (mRemainingDuration > 0) // Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should fix old saves. mDuration = 1; else mDuration = 0; @@ -62,7 +62,7 @@ namespace MWMechanics { // If AiEscort has ran for as long or longer then the duration specified // and the duration is not infinite, the package is complete. - if(mDuration > 0) + if (mDuration > 0) { mRemainingDuration -= ((duration*MWBase::Environment::get().getWorld()->getTimeScaleFactor()) / 3600); if (mRemainingDuration <= 0) @@ -90,13 +90,13 @@ namespace MWMechanics (differenceBetween[0] * differenceBetween[0]) + (differenceBetween[1] * differenceBetween[1]) + (differenceBetween[2] * differenceBetween[2]); - if(distanceBetweenResult <= mMaxDist * mMaxDist) + if (distanceBetweenResult <= mMaxDist * mMaxDist) { ESM::Pathgrid::Point point(static_cast(mX), static_cast(mY), static_cast(mZ)); point.mAutogenerated = 0; point.mConnectionNum = 0; point.mUnknown = 0; - if(pathTo(actor,point,duration)) //Returns true on path complete + if (pathTo(actor,point,duration)) //Returns true on path complete { mRemainingDuration = mDuration; return true; @@ -140,10 +140,11 @@ namespace MWMechanics sequence.mPackages.push_back(package); } -void AiEscort::fastForward(const MWWorld::Ptr& actor, AiState &state) -{ - // Update duration counter - mRemainingDuration--; -} + void AiEscort::fastForward(const MWWorld::Ptr& actor, AiState &state) + { + // Update duration counter if this package has a duration + if (mDuration > 0) + mRemainingDuration--; + } } diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index fb080d046..9d79d4ba9 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -52,9 +52,9 @@ AiFollow::AiFollow(const ESM::AiSequence::AiFollow *follow) , mActorRefId(follow->mTargetId), mActorId(-1) , mCellId(follow->mCellId), mActive(follow->mActive), mFollowIndex(mFollowIndexCounter++) { -// mDuration isn't saved in the save file, so just giving it "1" for now if the package has a duration. -// The exact value of mDuration only matters for repeating packages - if (mRemainingDuration != 0) +// mDuration isn't saved in the save file, so just giving it "1" for now if the package had a duration. +// The exact value of mDuration only matters for repeating packages. + if (mRemainingDuration > 0) // Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should fix old saves. mDuration = 1; else mDuration = 0; @@ -104,10 +104,10 @@ bool AiFollow::execute (const MWWorld::Ptr& actor, CharacterController& characte ++i; } - if(!mAlwaysFollow) //Update if you only follow for a bit + if (!mAlwaysFollow) //Update if you only follow for a bit { //Check if we've run out of time - if (mDuration != 0) + if (mDuration > 0) { mRemainingDuration -= ((duration*MWBase::Environment::get().getWorld()->getTimeScaleFactor()) / 3600); if (mRemainingDuration <= 0) @@ -117,18 +117,18 @@ bool AiFollow::execute (const MWWorld::Ptr& actor, CharacterController& characte } } - if((pos.pos[0]-mX)*(pos.pos[0]-mX) + + if ((pos.pos[0]-mX)*(pos.pos[0]-mX) + (pos.pos[1]-mY)*(pos.pos[1]-mY) + (pos.pos[2]-mZ)*(pos.pos[2]-mZ) < followDistance*followDistance) //Close-ish to final position { - if(actor.getCell()->isExterior()) //Outside? + if (actor.getCell()->isExterior()) //Outside? { - if(mCellId == "") //No cell to travel to + if (mCellId == "") //No cell to travel to return true; } else { - if(mCellId == actor.getCell()->getCell()->mName) //Cell to travel to + if (mCellId == actor.getCell()->getCell()->mName) //Cell to travel to return true; } } @@ -228,8 +228,9 @@ int AiFollow::getFollowIndex() const void AiFollow::fastForward(const MWWorld::Ptr& actor, AiState &state) { - // Update duration counter - mRemainingDuration--; + // Update duration counter if this package has a duration + if (mDuration > 0) + mRemainingDuration--; } }