Quick fix for Ai fast-forward crash in exteriors (Fixes #2241)

This commit is contained in:
scrawl 2015-01-01 18:11:37 +01:00
parent dc1c52bda7
commit 559ddbb480
2 changed files with 17 additions and 3 deletions

View file

@ -1653,7 +1653,10 @@ namespace MWMechanics
{ {
if (!MWBase::Environment::get().getMechanicsManager()->isAIActive()) if (!MWBase::Environment::get().getMechanicsManager()->isAIActive())
return; return;
for (PtrActorMap::iterator it = mActors.begin(); it != mActors.end(); ++it)
// making a copy since fast-forward could move actor to a different cell and invalidate the mActors iterator
PtrActorMap map = mActors;
for (PtrActorMap::iterator it = map.begin(); it != map.end(); ++it)
{ {
MWWorld::Ptr ptr = it->first; MWWorld::Ptr ptr = it->first;
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())

View file

@ -499,9 +499,14 @@ namespace MWMechanics
// convert dest to use world co-ordinates // convert dest to use world co-ordinates
ESM::Pathgrid::Point dest; ESM::Pathgrid::Point dest;
dest.mX = destNodePos[0] + currentCell->getCell()->mData.mX * ESM::Land::REAL_SIZE; dest.mX = destNodePos[0];
dest.mY = destNodePos[1] + currentCell->getCell()->mData.mY * ESM::Land::REAL_SIZE; dest.mY = destNodePos[1];
dest.mZ = destNodePos[2]; dest.mZ = destNodePos[2];
if (currentCell->getCell()->isExterior())
{
dest.mX += currentCell->getCell()->mData.mX * ESM::Land::REAL_SIZE;
dest.mY += currentCell->getCell()->mData.mY * ESM::Land::REAL_SIZE;
}
// actor position is already in world co-ordinates // actor position is already in world co-ordinates
ESM::Pathgrid::Point start; ESM::Pathgrid::Point start;
@ -670,6 +675,12 @@ namespace MWMechanics
dest.mX += Ogre::Math::RangeRandom(-64, 64); dest.mX += Ogre::Math::RangeRandom(-64, 64);
dest.mY += Ogre::Math::RangeRandom(-64, 64); dest.mY += Ogre::Math::RangeRandom(-64, 64);
if (actor.getCell()->isExterior())
{
dest.mX += actor.getCell()->getCell()->mData.mX * ESM::Land::REAL_SIZE;
dest.mY += actor.getCell()->getCell()->mData.mY * ESM::Land::REAL_SIZE;
}
MWBase::Environment::get().getWorld()->moveObject(actor, dest.mX, dest.mY, dest.mZ); MWBase::Environment::get().getWorld()->moveObject(actor, dest.mX, dest.mY, dest.mZ);
actor.getClass().adjustPosition(actor, false); actor.getClass().adjustPosition(actor, false);
} }