AiPackage: fix path recalc on cell change

AiTravel: remove unneeded code
This commit is contained in:
mrcheko 2016-09-06 01:11:10 +03:00
parent a22fc43947
commit aa441f2648
6 changed files with 10 additions and 27 deletions

View file

@ -101,7 +101,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const ESM::Pathgr
if (!mIsShortcutting) if (!mIsShortcutting)
{ {
if (wasShortcutting || doesPathNeedRecalc(dest)) // if need to rebuild path if (wasShortcutting || doesPathNeedRecalc(dest, actor.getCell())) // if need to rebuild path
{ {
mPathFinder.buildSyncedPath(start, dest, actor.getCell()); mPathFinder.buildSyncedPath(start, dest, actor.getCell());
@ -257,9 +257,9 @@ bool MWMechanics::AiPackage::checkWayIsClearForActor(const ESM::Pathgrid::Point&
return isClear; return isClear;
} }
bool MWMechanics::AiPackage::doesPathNeedRecalc(const ESM::Pathgrid::Point& newDest) bool MWMechanics::AiPackage::doesPathNeedRecalc(const ESM::Pathgrid::Point& newDest, const MWWorld::CellStore* currentCell)
{ {
return mPathFinder.getPath().empty() || (distance(mPathFinder.getPath().back(), newDest) > 10); return mPathFinder.getPath().empty() || (distance(mPathFinder.getPath().back(), newDest) > 10) || mPathFinder.getPathCell() != currentCell;
} }
bool MWMechanics::AiPackage::isTargetMagicallyHidden(const MWWorld::Ptr& target) bool MWMechanics::AiPackage::isTargetMagicallyHidden(const MWWorld::Ptr& target)

View file

@ -111,7 +111,7 @@ namespace MWMechanics
/// Check if the way to the destination is clear, taking into account actor speed /// Check if the way to the destination is clear, taking into account actor speed
bool checkWayIsClearForActor(const ESM::Pathgrid::Point& startPoint, const ESM::Pathgrid::Point& endPoint, const MWWorld::Ptr& actor); bool checkWayIsClearForActor(const ESM::Pathgrid::Point& startPoint, const ESM::Pathgrid::Point& endPoint, const MWWorld::Ptr& actor);
virtual bool doesPathNeedRecalc(const ESM::Pathgrid::Point& newDest); virtual bool doesPathNeedRecalc(const ESM::Pathgrid::Point& newDest, const MWWorld::CellStore* currentCell);
void evadeObstacles(const MWWorld::Ptr& actor, float duration, const ESM::Position& pos); void evadeObstacles(const MWWorld::Ptr& actor, float duration, const ESM::Position& pos);

View file

@ -30,15 +30,11 @@ namespace MWMechanics
{ {
AiTravel::AiTravel(float x, float y, float z) AiTravel::AiTravel(float x, float y, float z)
: mX(x),mY(y),mZ(z) : mX(x),mY(y),mZ(z)
, mCellX(std::numeric_limits<int>::max())
, mCellY(std::numeric_limits<int>::max())
{ {
} }
AiTravel::AiTravel(const ESM::AiSequence::AiTravel *travel) AiTravel::AiTravel(const ESM::AiSequence::AiTravel *travel)
: mX(travel->mData.mX), mY(travel->mData.mY), mZ(travel->mData.mZ) : mX(travel->mData.mX), mY(travel->mData.mY), mZ(travel->mData.mZ)
, mCellX(std::numeric_limits<int>::max())
, mCellY(std::numeric_limits<int>::max())
{ {
} }
@ -66,18 +62,6 @@ namespace MWMechanics
return false; return false;
} }
bool AiTravel::doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell)
{
bool cellChange = cell->mData.mX != mCellX || cell->mData.mY != mCellY;
if (!mPathFinder.isPathConstructed() || cellChange)
{
mCellX = cell->mData.mX;
mCellY = cell->mData.mY;
return true;
}
return false;
}
int AiTravel::getTypeId() const int AiTravel::getTypeId() const
{ {
return TypeIdTravel; return TypeIdTravel;

View file

@ -34,17 +34,10 @@ namespace MWMechanics
virtual int getTypeId() const; virtual int getTypeId() const;
protected:
virtual bool doesPathNeedRecalc(ESM::Pathgrid::Point dest, const ESM::Cell *cell);
private: private:
float mX; float mX;
float mY; float mY;
float mZ; float mZ;
int mCellX;
int mCellY;
}; };
} }

View file

@ -328,4 +328,8 @@ namespace MWMechanics
} }
} }
const MWWorld::CellStore* PathFinder::getPathCell() const
{
return mCell;
}
} }

View file

@ -79,6 +79,8 @@ namespace MWMechanics
return mPath; return mPath;
} }
const MWWorld::CellStore* getPathCell() const;
/** Synchronize new path with old one to avoid visiting 1 waypoint 2 times /** Synchronize new path with old one to avoid visiting 1 waypoint 2 times
@note @note
BuildPath() takes closest PathGrid point to NPC as first point of path. BuildPath() takes closest PathGrid point to NPC as first point of path.