From 0ce29a61314f088202274e631b0ec6720a57a781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 16 Feb 2022 20:21:10 +0200 Subject: [PATCH] Simplify logic in AiSequence::execute --- apps/openmw/mwmechanics/aisequence.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 8506e1daf0..0cb1e97603 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -238,8 +238,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac return; } - auto packageIt = mPackages.begin(); - MWMechanics::AiPackage* package = packageIt->get(); + auto* package = mPackages.front().get(); if (!package->alwaysActive() && outOfRange) return; @@ -301,8 +300,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac std::rotate(mPackages.begin(), itActualCombat, std::next(itActualCombat)); } - packageIt = mPackages.begin(); - package = packageIt->get(); + package = mPackages.front().get(); packageTypeId = package->getTypeId(); } @@ -310,8 +308,6 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac { 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 if (isActualAiPackage(packageTypeId) && package->getRepeat()) { @@ -319,12 +315,9 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac 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 // (e.g. AiPursue executing a dialogue script that uses startCombat) - erase(packageIt); + erase(mPackages.begin()); if (isActualAiPackage(packageTypeId)) mDone = true; }