1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-31 20:45:32 +00:00

Remember package iterator to erase it from list without find call

This commit is contained in:
elsid 2020-05-17 22:37:44 +02:00
parent d48eead038
commit a4fbcb8a10
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40

View file

@ -212,7 +212,8 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
return;
}
MWMechanics::AiPackage* package = mPackages.front();
auto packageIt = mPackages.begin();
MWMechanics::AiPackage* package = *packageIt;
if (!package->alwaysActive() && outOfRange)
return;
@ -274,7 +275,8 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
mPackages.splice(mPackages.begin(), mPackages, itActualCombat);
}
package = mPackages.front();
packageIt = mPackages.begin();
package = *packageIt;
packageTypeId = package->getTypeId();
}
@ -290,9 +292,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
}
// To account for the rare case where AiPackage::execute() queued another AI package
// (e.g. AiPursue executing a dialogue script that uses startCombat)
std::list<MWMechanics::AiPackage*>::iterator toRemove =
std::find(mPackages.begin(), mPackages.end(), package);
mPackages.erase(toRemove);
mPackages.erase(packageIt);
delete package;
if (isActualAiPackage(packageTypeId))
mDone = true;