1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-19 08:41:35 +00:00

Simplify logic in AiSequence::execute

This commit is contained in:
ζeh Matt 2022-02-16 20:21:10 +02:00
parent e60e0b55eb
commit 0ce29a6131
No known key found for this signature in database
GPG key ID: 18CE582C71A225B0

View file

@ -238,8 +238,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
return; return;
} }
auto packageIt = mPackages.begin(); auto* package = mPackages.front().get();
MWMechanics::AiPackage* package = packageIt->get();
if (!package->alwaysActive() && outOfRange) if (!package->alwaysActive() && outOfRange)
return; return;
@ -301,8 +300,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
std::rotate(mPackages.begin(), itActualCombat, std::next(itActualCombat)); std::rotate(mPackages.begin(), itActualCombat, std::next(itActualCombat));
} }
packageIt = mPackages.begin(); package = mPackages.front().get();
package = packageIt->get();
packageTypeId = package->getTypeId(); packageTypeId = package->getTypeId();
} }
@ -310,8 +308,6 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
{ {
if (package->execute(actor, characterController, mAiState, duration)) if (package->execute(actor, characterController, mAiState, duration))
{ {
const auto packageIdx = std::distance(mPackages.begin(), packageIt);
// Put repeating non-combat AI packages on the end of the stack so they can be used again // Put repeating non-combat AI packages on the end of the stack so they can be used again
if (isActualAiPackage(packageTypeId) && package->getRepeat()) if (isActualAiPackage(packageTypeId) && package->getRepeat())
{ {
@ -319,12 +315,9 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
mPackages.push_back(package->clone()); mPackages.push_back(package->clone());
} }
// Iterator may have been invalidated by push back ensure its correct.
packageIt = mPackages.begin() + packageIdx;
// To account for the rare case where AiPackage::execute() queued another AI package // To account for the rare case where AiPackage::execute() queued another AI package
// (e.g. AiPursue executing a dialogue script that uses startCombat) // (e.g. AiPursue executing a dialogue script that uses startCombat)
erase(packageIt); erase(mPackages.begin());
if (isActualAiPackage(packageTypeId)) if (isActualAiPackage(packageTypeId))
mDone = true; mDone = true;
} }