1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-31 14:36:39 +00:00

Merge branch 'fix-6618' into 'master'

Fix #6618

Closes #6618

See merge request OpenMW/openmw!1666
This commit is contained in:
psi29a 2022-02-16 21:24:21 +00:00
commit 8da1cc3dd2

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;
@ -291,7 +290,8 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
} }
} }
assert(!mPackages.empty()); if (mPackages.empty())
return;
if (nearestDist < std::numeric_limits<float>::max() && mPackages.begin() != itActualCombat) if (nearestDist < std::numeric_limits<float>::max() && mPackages.begin() != itActualCombat)
{ {
@ -300,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();
} }
@ -309,15 +308,16 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
{ {
if (package->execute(actor, characterController, mAiState, duration)) if (package->execute(actor, characterController, mAiState, duration))
{ {
// Put repeating noncombat 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())
{ {
package->reset(); package->reset();
mPackages.push_back(package->clone()); mPackages.push_back(package->clone());
} }
// 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;
} }