fix bugs in aisequence::execute

deque
mrcheko 11 years ago
parent 638df221a6
commit 56881cb7c9

@ -137,7 +137,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration)
float nearestDist = std::numeric_limits<float>::max(); float nearestDist = std::numeric_limits<float>::max();
Ogre::Vector3 vActorPos = Ogre::Vector3(actor.getRefData().getPosition().pos); Ogre::Vector3 vActorPos = Ogre::Vector3(actor.getRefData().getPosition().pos);
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end(); ++it) for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end();)
{ {
if ((*it)->getTypeId() != AiPackage::TypeIdCombat) break; if ((*it)->getTypeId() != AiPackage::TypeIdCombat) break;
@ -147,7 +147,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration)
if (target.isEmpty()) if (target.isEmpty())
{ {
delete *it; delete *it;
mPackages.erase(it++); it = mPackages.erase(it);
} }
else else
{ {
@ -159,19 +159,25 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration)
nearestDist = distTo; nearestDist = distTo;
itActualCombat = it; itActualCombat = it;
} }
++it;
} }
} }
// all targets disappeared if (!mPackages.empty())
if (nearestDist == std::numeric_limits<float>::max())
{ {
mDone = true; if (nearestDist < std::numeric_limits<float>::max() && mPackages.begin() != itActualCombat)
return; {
// move combat package with nearest target to the front
mPackages.splice(mPackages.begin(), mPackages, itActualCombat);
}
package = mPackages.front();
mLastAiPackage = package->getTypeId();
} }
else if (mPackages.begin() != itActualCombat) else
{ {
// move combat package with nearest target to the front mDone = true;
mPackages.splice(mPackages.begin(), mPackages, itActualCombat); return;
} }
} }

Loading…
Cancel
Save