1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-04 04:06:41 +00:00

Unifiy evadeObstacles() logic between AiWander and AiPackage

Can't use same code, but logic is now same.
This commit is contained in:
dteviot 2015-08-30 08:32:47 +12:00
parent f59e918a3b
commit 31d82b6b0c
4 changed files with 44 additions and 31 deletions

View file

@ -91,6 +91,13 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
if(mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1])) //Path finished? if(mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1])) //Path finished?
return true; return true;
else else
{
evadeObstacles(actor, duration, pos);
}
return false;
}
void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float duration, ESM::Position& pos)
{ {
zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1])); zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
@ -115,8 +122,6 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
movement.mPosition[1] = 1; //Just run forward movement.mPosition[1] = 1; //Just run forward
} }
} }
return false;
}
bool MWMechanics::AiPackage::doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell) bool MWMechanics::AiPackage::doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell)
{ {

View file

@ -85,6 +85,10 @@ namespace MWMechanics
float mTimer; float mTimer;
ESM::Pathgrid::Point mPrevDest; ESM::Pathgrid::Point mPrevDest;
private:
void evadeObstacles(const MWWorld::Ptr& actor, float duration, ESM::Position& pos);
}; };
} }

View file

@ -381,11 +381,7 @@ namespace MWMechanics
else else
{ {
// have not yet reached the destination // have not yet reached the destination
//... turn towards the next point in mPath evadeObstacles(actor, storage, duration, pos);
zTurn(actor, storage.mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
actor.getClass().getMovementSettings(actor).mPosition[1] = 1;
evadeObstacles(actor, storage, duration);
} }
} }
@ -417,8 +413,12 @@ namespace MWMechanics
storage.mState = Wander_IdleNow; storage.mState = Wander_IdleNow;
} }
void AiWander::evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration) void AiWander::evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration, ESM::Position& pos)
{ {
// turn towards the next point in mPath
zTurn(actor, storage.mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor);
if (mObstacleCheck.check(actor, duration)) if (mObstacleCheck.check(actor, duration))
{ {
// first check if we're walking into a door // first check if we're walking into a door
@ -435,11 +435,15 @@ namespace MWMechanics
{ {
// TODO: diagonal should have same animation as walk forward // TODO: diagonal should have same animation as walk forward
// but doesn't seem to do that? // but doesn't seem to do that?
actor.getClass().getMovementSettings(actor).mPosition[0] = 1; movement.mPosition[0] = 1;
actor.getClass().getMovementSettings(actor).mPosition[1] = 0.1f; movement.mPosition[1] = 0.1f;
} }
mStuckCount++; // TODO: maybe no longer needed mStuckCount++; // TODO: maybe no longer needed
} }
else
{
movement.mPosition[1] = 1;
}
//#if 0 //#if 0
// TODO: maybe no longer needed // TODO: maybe no longer needed
if (mStuckCount >= COUNT_BEFORE_RESET) // something has gone wrong, reset if (mStuckCount >= COUNT_BEFORE_RESET) // something has gone wrong, reset

View file

@ -83,7 +83,7 @@ namespace MWMechanics
short unsigned getRandomIdle(); short unsigned getRandomIdle();
void setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos); void setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos);
void playGreetingIfPlayerGetsTooClose(const MWWorld::Ptr& actor, AiWanderStorage& storage); void playGreetingIfPlayerGetsTooClose(const MWWorld::Ptr& actor, AiWanderStorage& storage);
void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration); void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration, ESM::Position& pos);
void playIdleDialogueRandomly(const MWWorld::Ptr& actor); void playIdleDialogueRandomly(const MWWorld::Ptr& actor);
void turnActorToFacePlayer(const osg::Vec3f& actorPosition, const osg::Vec3f& playerPosition, AiWanderStorage& storage); void turnActorToFacePlayer(const osg::Vec3f& actorPosition, const osg::Vec3f& playerPosition, AiWanderStorage& storage);
void doPerFrameActionsForState(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos); void doPerFrameActionsForState(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos);