2013-03-31 17:30:03 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_PATHFINDING_H
|
|
|
|
#define GAME_MWMECHANICS_PATHFINDING_H
|
|
|
|
|
|
|
|
#include <components/esm/loadpgrd.hpp>
|
|
|
|
#include <list>
|
2014-01-12 17:42:31 +00:00
|
|
|
|
2014-03-16 22:38:51 +00:00
|
|
|
#include <OgreMath.h>
|
|
|
|
|
2014-01-12 17:42:31 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class CellStore;
|
|
|
|
}
|
2013-03-31 17:30:03 +00:00
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
class PathFinder
|
|
|
|
{
|
2013-05-29 22:59:23 +00:00
|
|
|
public:
|
|
|
|
PathFinder();
|
2013-03-31 17:30:03 +00:00
|
|
|
|
2014-03-16 22:38:51 +00:00
|
|
|
static float sgn(Ogre::Radian a)
|
|
|
|
{
|
|
|
|
if(a.valueRadians() > 0)
|
|
|
|
return 1.0;
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float sgn(float a)
|
|
|
|
{
|
|
|
|
if(a > 0)
|
|
|
|
return 1.0;
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
2013-05-29 22:59:23 +00:00
|
|
|
void clearPath();
|
2014-01-12 17:42:31 +00:00
|
|
|
|
2014-01-26 20:53:55 +00:00
|
|
|
void buildPathgridGraph(const ESM::Pathgrid* pathGrid);
|
2014-01-12 17:42:31 +00:00
|
|
|
|
2013-08-30 02:17:27 +00:00
|
|
|
void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
|
2014-01-12 17:42:31 +00:00
|
|
|
const MWWorld::CellStore* cell, bool allowShortcuts = true);
|
2013-03-31 17:30:03 +00:00
|
|
|
|
2013-05-30 03:05:17 +00:00
|
|
|
bool checkPathCompleted(float x, float y, float z);
|
2013-05-30 00:33:33 +00:00
|
|
|
///< \Returns true if the last point of the path has been reached.
|
2014-01-29 19:29:07 +00:00
|
|
|
|
2013-10-07 08:20:02 +00:00
|
|
|
bool checkWaypoint(float x, float y, float z);
|
|
|
|
///< \Returns true if a way point was reached
|
2014-01-29 19:29:07 +00:00
|
|
|
|
2013-08-30 02:17:27 +00:00
|
|
|
float getZAngleToNext(float x, float y) const;
|
2013-03-31 17:30:03 +00:00
|
|
|
|
2014-01-23 21:14:20 +00:00
|
|
|
float getDistToNext(float x, float y, float z);
|
|
|
|
|
2013-08-30 02:17:27 +00:00
|
|
|
bool isPathConstructed() const
|
|
|
|
{
|
|
|
|
return mIsPathConstructed;
|
|
|
|
}
|
2013-03-31 17:30:03 +00:00
|
|
|
|
2013-10-07 08:20:02 +00:00
|
|
|
int getPathSize() const
|
|
|
|
{
|
|
|
|
return mPath.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<ESM::Pathgrid::Point> getPath() const
|
|
|
|
{
|
|
|
|
return mPath;
|
|
|
|
}
|
|
|
|
|
2014-03-29 08:28:30 +00:00
|
|
|
// When first point of newly created path is the nearest to actor point,
|
|
|
|
// then a situation can occure when this point is undesirable
|
|
|
|
// (if the 2nd point of new path == the 1st point of old path)
|
|
|
|
// This functions deletes that point.
|
2014-01-19 20:09:51 +00:00
|
|
|
void syncStart(const std::list<ESM::Pathgrid::Point> &path);
|
|
|
|
|
2014-01-07 20:10:57 +00:00
|
|
|
void addPointToPath(ESM::Pathgrid::Point &point)
|
|
|
|
{
|
|
|
|
mPath.push_back(point);
|
|
|
|
}
|
|
|
|
|
2014-03-29 08:28:30 +00:00
|
|
|
// While a public method is defined here, it is anticipated that
|
|
|
|
// mSCComp will only be used internally.
|
|
|
|
std::vector<int> getSCComp() const
|
|
|
|
{
|
|
|
|
return mSCComp;
|
|
|
|
}
|
|
|
|
|
2013-05-29 22:59:23 +00:00
|
|
|
private:
|
2014-01-26 20:53:55 +00:00
|
|
|
|
|
|
|
struct Edge
|
|
|
|
{
|
|
|
|
int destination;
|
|
|
|
float cost;
|
|
|
|
};
|
|
|
|
struct Node
|
|
|
|
{
|
|
|
|
int label;
|
|
|
|
std::vector<Edge> edges;
|
|
|
|
int parent;//used in pathfinding
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<float> mGScore;
|
|
|
|
std::vector<float> mFScore;
|
|
|
|
|
|
|
|
std::list<ESM::Pathgrid::Point> aStarSearch(const ESM::Pathgrid* pathGrid,int start,int goal,float xCell = 0, float yCell = 0);
|
|
|
|
void cleanUpAStar();
|
|
|
|
|
|
|
|
std::vector<Node> mGraph;
|
2013-05-29 22:59:23 +00:00
|
|
|
bool mIsPathConstructed;
|
2014-01-12 17:42:31 +00:00
|
|
|
|
2014-01-26 20:53:55 +00:00
|
|
|
|
|
|
|
std::list<ESM::Pathgrid::Point> mPath;
|
2014-01-12 17:42:31 +00:00
|
|
|
bool mIsGraphConstructed;
|
|
|
|
const MWWorld::CellStore* mCell;
|
2014-03-29 08:28:30 +00:00
|
|
|
|
|
|
|
// contains an integer indicating the groups of connected pathgrid points
|
|
|
|
// (all connected points will have the same value)
|
|
|
|
//
|
|
|
|
// In Seyda Neen there are 3:
|
|
|
|
//
|
|
|
|
// 52, 53 and 54 are one set (enclosed yard)
|
|
|
|
// 48, 49, 50, 51, 84, 85, 86, 87, 88, 89, 90 are another (ship & office)
|
|
|
|
// all other pathgrid points are the third set
|
|
|
|
//
|
|
|
|
std::vector<int> mSCComp;
|
|
|
|
// variables used to calculate mSCComp
|
|
|
|
int mSCCId;
|
|
|
|
int mSCCIndex;
|
|
|
|
std::list<int> mSCCStack;
|
|
|
|
typedef std::pair<int, int> VPair; // first is index, second is lowlink
|
|
|
|
std::vector<VPair> mSCCPoint;
|
|
|
|
// methods used to calculate mSCComp
|
|
|
|
void recursiveStrongConnect(int v);
|
|
|
|
void buildConnectedPoints(const ESM::Pathgrid* pathGrid);
|
2013-03-31 17:30:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-05-29 22:59:23 +00:00
|
|
|
#endif
|