Merge pull request #2856 from elsid/aisequence_cleanup

AiSequence cleanup
pull/2861/head
Bret Curtis 5 years ago committed by GitHub
commit 730d0493db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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;
@ -223,7 +224,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
// if active package is combat one, choose nearest target
if (packageTypeId == AiPackage::TypeIdCombat)
{
std::list<AiPackage *>::iterator itActualCombat;
auto itActualCombat = mPackages.end();
float nearestDist = std::numeric_limits<float>::max();
osg::Vec3f vActorPos = actor.getRefData().getPosition().asVec3();
@ -265,16 +266,18 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
}
}
if (!mPackages.empty())
{
if (nearestDist < std::numeric_limits<float>::max() && mPackages.begin() != itActualCombat)
{
// move combat package with nearest target to the front
mPackages.splice(mPackages.begin(), mPackages, itActualCombat);
}
assert(!mPackages.empty());
package = mPackages.front();
if (nearestDist < std::numeric_limits<float>::max() && mPackages.begin() != itActualCombat)
{
assert(itActualCombat != mPackages.end());
// move combat package with nearest target to the front
mPackages.splice(mPackages.begin(), mPackages, itActualCombat);
}
packageIt = mPackages.begin();
package = *packageIt;
packageTypeId = package->getTypeId();
}
try
@ -289,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;

Loading…
Cancel
Save