mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-07 13:20:25 +00:00
extracted function returnToStartLocation().
This commit is contained in:
parent
5e519ef550
commit
c7aacaee70
@ -233,23 +233,10 @@ namespace MWMechanics
|
|||||||
// For stationary NPCs, move back to the starting location if another AiPackage moved us elsewhere
|
// For stationary NPCs, move back to the starting location if another AiPackage moved us elsewhere
|
||||||
if (cellChange)
|
if (cellChange)
|
||||||
mHasReturnPosition = false;
|
mHasReturnPosition = false;
|
||||||
if (mDistance == 0 && mHasReturnPosition && (pos.asVec3() - mReturnPosition).length2() > 20*20)
|
if (mDistance == 0 && mHasReturnPosition
|
||||||
|
&& (pos.asVec3() - mReturnPosition).length2() > (DESTINATION_TOLERANCE * DESTINATION_TOLERANCE))
|
||||||
{
|
{
|
||||||
if (!storage.mPathFinder.isPathConstructed())
|
returnToStartLocation(actor, storage, pos);
|
||||||
{
|
|
||||||
ESM::Pathgrid::Point dest(PathFinder::MakePathgridPoint(mReturnPosition));
|
|
||||||
|
|
||||||
// actor position is already in world co-ordinates
|
|
||||||
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
|
|
||||||
|
|
||||||
// don't take shortcuts for wandering
|
|
||||||
storage.mPathFinder.buildSyncedPath(start, dest, actor.getCell(), false);
|
|
||||||
|
|
||||||
if(storage.mPathFinder.isPathConstructed())
|
|
||||||
{
|
|
||||||
storage.mState = Wander_Walking;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow interrupting a walking actor to trigger a greeting
|
// Allow interrupting a walking actor to trigger a greeting
|
||||||
@ -298,6 +285,25 @@ namespace MWMechanics
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AiWander::returnToStartLocation(const MWWorld::Ptr& actor, AiWanderStorage& storage, ESM::Position& pos)
|
||||||
|
{
|
||||||
|
if (!storage.mPathFinder.isPathConstructed())
|
||||||
|
{
|
||||||
|
ESM::Pathgrid::Point dest(PathFinder::MakePathgridPoint(mReturnPosition));
|
||||||
|
|
||||||
|
// actor position is already in world co-ordinates
|
||||||
|
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
|
||||||
|
|
||||||
|
// don't take shortcuts for wandering
|
||||||
|
storage.mPathFinder.buildSyncedPath(start, dest, actor.getCell(), false);
|
||||||
|
|
||||||
|
if (storage.mPathFinder.isPathConstructed())
|
||||||
|
{
|
||||||
|
storage.mState = Wander_Walking;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AiWander::doPerFrameActionsForState(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos)
|
void AiWander::doPerFrameActionsForState(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos)
|
||||||
{
|
{
|
||||||
switch (storage.mState)
|
switch (storage.mState)
|
||||||
|
@ -90,6 +90,7 @@ namespace MWMechanics
|
|||||||
bool reactionTimeActions(const MWWorld::Ptr& actor, AiWanderStorage& storage,
|
bool reactionTimeActions(const MWWorld::Ptr& actor, AiWanderStorage& storage,
|
||||||
const MWWorld::CellStore*& currentCell, bool cellChange, ESM::Position& pos);
|
const MWWorld::CellStore*& currentCell, bool cellChange, ESM::Position& pos);
|
||||||
bool isPackageCompleted(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
bool isPackageCompleted(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
||||||
|
void returnToStartLocation(const MWWorld::Ptr& actor, AiWanderStorage& storage, ESM::Position& pos);
|
||||||
|
|
||||||
int mDistance; // how far the actor can wander from the spawn point
|
int mDistance; // how far the actor can wander from the spawn point
|
||||||
int mDuration;
|
int mDuration;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user