1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

movement logic in AiPackage uses ObstacleCheck.

This commit is contained in:
dteviot 2015-08-29 17:21:18 +12:00
parent a9f9a8d58e
commit 0677799839
2 changed files with 10 additions and 19 deletions

View File

@ -19,7 +19,7 @@
MWMechanics::AiPackage::~AiPackage() {}
MWMechanics::AiPackage::AiPackage() : mTimer(0.26f), mStuckTimer(0) { //mTimer starts at .26 to force initial pathbuild
MWMechanics::AiPackage::AiPackage() : mTimer(0.26f) { //mTimer starts at .26 to force initial pathbuild
}
@ -28,7 +28,6 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
{
//Update various Timers
mTimer += duration; //Update timer
mStuckTimer += duration; //Update stuck timer
ESM::Position pos = actor.getRefData().getPosition(); //position of the actor
@ -91,11 +90,13 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
//************************
if(mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1])) //Path finished?
return true;
else if(mStuckTimer>0.5) //Every half second see if we need to take action to avoid something
else
{
/// TODO (tluppi#1#): Use ObstacleCheck here. Not working for some reason
//if(mObstacleCheck.check(actor, duration)) {
if(distance(start, mStuckPos.pos[0], mStuckPos.pos[1], mStuckPos.pos[2]) < actor.getClass().getSpeed(actor)*0.05 && distance(dest, start) > 20) { //Actually stuck, and far enough away from destination to care
zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor);
if(mObstacleCheck.check(actor, duration))
{
// first check if we're walking into a door
MWWorld::Ptr door = getNearbyDoor(actor);
if(door != MWWorld::Ptr()) // NOTE: checks interior cells only
@ -106,24 +107,16 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
}
else // probably walking into another NPC
{
actor.getClass().getMovementSettings(actor).mPosition[0] = 1;
actor.getClass().getMovementSettings(actor).mPosition[1] = 1;
movement.mPosition[0] = 1;
movement.mPosition[1] = 1;
// change the angle a bit, too
zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0] + 1, pos.pos[1]));
}
}
else { //Not stuck, so reset things
mStuckTimer = 0;
mStuckPos = pos;
actor.getClass().getMovementSettings(actor).mPosition[1] = 1; //Just run forward
movement.mPosition[1] = 1; //Just run forward
}
}
else {
actor.getClass().getMovementSettings(actor).mPosition[1] = 1; //Just run forward the rest of the time
}
zTurn(actor, mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]));
return false;
}

View File

@ -83,9 +83,7 @@ namespace MWMechanics
ObstacleCheck mObstacleCheck;
float mTimer;
float mStuckTimer;
ESM::Position mStuckPos;
ESM::Pathgrid::Point mPrevDest;
};
}