Waypoint check only considers X & Y distance (Fixes #2423)

When pathfinder checks if actor has reached a waypoint, ignore actor's altitude.
celladd
dteviot 10 years ago
parent 9ab25dbf6b
commit eb1090a1b6

@ -581,7 +581,7 @@ namespace MWMechanics
buildNewPath(actor, target); //may fail to build a path, check before use
//delete visited path node
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]);
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1]);
// This works on the borders between the path grid and areas with no waypoints.
if(inLOS && mPathFinder.getPath().size() > 1)

@ -86,7 +86,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, ESM::Pathgrid::Po
//************************
/// Checks if you aren't moving; attempts to unstick you
//************************
if(mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2])) //Path finished?
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
{

@ -100,7 +100,7 @@ namespace MWMechanics
mPathFinder.buildPath(start, dest, actor.getCell(), true);
}
if(mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2]))
if(mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1]))
{
movement.mPosition[1] = 0;
return true;

@ -205,7 +205,7 @@ namespace MWMechanics
// Are we there yet?
bool& chooseAction = storage.mChooseAction;
if(walking &&
storage.mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2], 64.f))
storage.mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], 64.f))
{
stopWalking(actor, storage);
moveNow = false;

@ -90,12 +90,11 @@ namespace
namespace MWMechanics
{
float sqrDistanceZCorrected(ESM::Pathgrid::Point point, float x, float y, float z)
float sqrDistanceIgnoreZ(ESM::Pathgrid::Point point, float x, float y)
{
x -= point.mX;
y -= point.mY;
z -= point.mZ;
return (x * x + y * y + 0.1f * z * z);
return (x * x + y * y);
}
float distance(ESM::Pathgrid::Point point, float x, float y, float z)
@ -283,13 +282,13 @@ namespace MWMechanics
return Ogre::Math::ATan2(directionX,directionY).valueDegrees();
}
bool PathFinder::checkPathCompleted(float x, float y, float z, float tolerance)
bool PathFinder::checkPathCompleted(float x, float y, float tolerance)
{
if(mPath.empty())
return true;
ESM::Pathgrid::Point nextPoint = *mPath.begin();
if(sqrDistanceZCorrected(nextPoint, x, y, z) < tolerance*tolerance)
if (sqrDistanceIgnoreZ(nextPoint, x, y) < tolerance*tolerance)
{
mPath.pop_front();
if(mPath.empty())

@ -41,7 +41,7 @@ namespace MWMechanics
void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const MWWorld::CellStore* cell, bool allowShortcuts = true);
bool checkPathCompleted(float x, float y, float z, float tolerance=32.f);
bool checkPathCompleted(float x, float y, float tolerance=32.f);
///< \Returns true if we are within \a tolerance units of the last path point.
float getZAngleToNext(float x, float y) const;

Loading…
Cancel
Save