From 48ac0bef3ed17024957e4715b3d85396be30665f Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 11 Feb 2016 16:34:02 +0100 Subject: [PATCH] Repair save games affected by bug #3080 (Fixes #3160) --- apps/openmw/mwmechanics/aisequence.cpp | 46 ++++++++++++++------------ 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 04ac96b11..71733d613 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -351,60 +351,64 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence) for (std::vector::const_iterator it = sequence.mPackages.begin(); it != sequence.mPackages.end(); ++it) { + MWMechanics::AiPackage* package = NULL; switch (it->mType) { case ESM::AiSequence::Ai_Wander: { - MWMechanics::AiWander* wander = new AiWander( - static_cast(it->mPackage)); - mPackages.push_back(wander); + package = new AiWander(static_cast(it->mPackage)); break; } case ESM::AiSequence::Ai_Travel: { - MWMechanics::AiTravel* travel = new AiTravel( - static_cast(it->mPackage)); - mPackages.push_back(travel); + package = new AiTravel(static_cast(it->mPackage)); break; } case ESM::AiSequence::Ai_Escort: { - MWMechanics::AiEscort* escort = new AiEscort( - static_cast(it->mPackage)); - mPackages.push_back(escort); + package = new AiEscort(static_cast(it->mPackage)); break; } case ESM::AiSequence::Ai_Follow: { - MWMechanics::AiFollow* follow = new AiFollow( - static_cast(it->mPackage)); - mPackages.push_back(follow); + package = new AiFollow(static_cast(it->mPackage)); break; } case ESM::AiSequence::Ai_Activate: { - MWMechanics::AiActivate* activate = new AiActivate( - static_cast(it->mPackage)); - mPackages.push_back(activate); + package = new AiActivate(static_cast(it->mPackage)); break; } case ESM::AiSequence::Ai_Combat: { - MWMechanics::AiCombat* combat = new AiCombat( - static_cast(it->mPackage)); - mPackages.push_back(combat); + package = new AiCombat(static_cast(it->mPackage)); break; } case ESM::AiSequence::Ai_Pursue: { - MWMechanics::AiPursue* pursue = new AiPursue( - static_cast(it->mPackage)); - mPackages.push_back(pursue); + package = new AiPursue(static_cast(it->mPackage)); break; } default: break; } + + if (!package) + continue; + + // remove previous packages if required + if (package->shouldCancelPreviousAi()) + { + for(std::list::iterator it = mPackages.begin(); it != mPackages.end();) + { + if((*it)->canCancel()) + it = mPackages.erase(it); + else + ++it; + } + } + + mPackages.push_back(package); } }