extracted function setPathToAnAllowedNode()

This commit is contained in:
dteviot 2015-07-12 16:35:15 +12:00
parent b508846a64
commit df421fce92
2 changed files with 35 additions and 27 deletions

View file

@ -504,13 +504,24 @@ namespace MWMechanics
// Construct a new path if there isn't one
if(!storage.mPathFinder.isPathConstructed())
{
assert(mAllowedNodes.size());
if (mAllowedNodes.size())
{
setPathToAnAllowedNode(actor, storage, pos);
}
}
}
return false; // AiWander package not yet completed
}
void AiWander::setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos)
{
unsigned int randNode = Misc::Rng::rollDice(mAllowedNodes.size());
ESM::Pathgrid::Point dest(mAllowedNodes[randNode]);
ToWorldCoordinates(dest, currentCell->getCell());
ToWorldCoordinates(dest, storage.mCell->getCell());
// actor position is already in world co-ordinates
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(actorPos));
// don't take shortcuts for wandering
storage.mPathFinder.buildSyncedPath(start, dest, actor.getCell(), false);
@ -527,17 +538,13 @@ namespace MWMechanics
mAllowedNodes.push_back(mCurrentNode);
mCurrentNode = temp;
moveNow = false;
walking = true;
storage.mMoveNow = false;
storage.mWalking = true;
}
// Choose a different node and delete this one from possible nodes because it is uncreachable:
else
mAllowedNodes.erase(mAllowedNodes.begin() + randNode);
}
}
return false; // AiWander package not yet completed
}
void AiWander::ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell)
{

View file

@ -71,6 +71,7 @@ namespace MWMechanics
void playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
void getRandomIdle(unsigned short& playedIdle);
void setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos);
int mDistance; // how far the actor can wander from the spawn point
int mDuration;