mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-19 19:41:33 +00:00
Simplify logic in AiSequence::execute
This commit is contained in:
parent
e60e0b55eb
commit
0ce29a6131
1 changed files with 3 additions and 10 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue