2014-04-04 06:13:47 +11:00
|
|
|
#ifndef GAME_MWMECHANICS_PATHGRID_H
|
|
|
|
#define GAME_MWMECHANICS_PATHGRID_H
|
|
|
|
|
2018-08-19 00:28:11 +03:00
|
|
|
#include <deque>
|
2014-04-04 06:13:47 +11:00
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/loadpgrd.hpp>
|
2016-06-17 23:07:16 +09:00
|
|
|
|
2014-04-04 06:13:47 +11:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
class PathgridGraph
|
|
|
|
{
|
2023-04-08 00:32:43 +00:00
|
|
|
PathgridGraph()
|
|
|
|
: mPathgrid(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-04-08 00:32:43 +00:00
|
|
|
public:
|
|
|
|
explicit PathgridGraph(const ESM::Pathgrid& pathGrid);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-04-08 00:32:43 +00:00
|
|
|
const ESM::Pathgrid* getPathgrid() const { return mPathgrid; }
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-04-04 06:13:47 +11:00
|
|
|
// returns true if end point is strongly connected (i.e. reachable
|
|
|
|
// from start point) both start and end are pathgrid point indexes
|
2023-04-08 00:32:43 +00:00
|
|
|
bool isPointConnected(const size_t start, const size_t end) const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2017-11-11 12:31:18 +04:00
|
|
|
// get neighbouring nodes for index node and put them to "nodes" vector
|
2023-04-08 00:32:43 +00:00
|
|
|
void getNeighbouringPoints(const size_t index, ESM::Pathgrid::PointList& nodes) const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-04-04 18:17:42 +11:00
|
|
|
// the input parameters are pathgrid point indexes
|
|
|
|
// the output list is in local (internal cells) or world (external
|
2016-12-14 22:11:22 +01:00
|
|
|
// cells) coordinates
|
2014-04-20 08:31:02 +10:00
|
|
|
//
|
|
|
|
// NOTE: if start equals end an empty path is returned
|
2023-04-08 00:32:43 +00:00
|
|
|
std::deque<ESM::Pathgrid::Point> aStarSearch(const size_t start, const size_t end) const;
|
|
|
|
|
|
|
|
static const PathgridGraph sEmpty;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-04-04 06:13:47 +11:00
|
|
|
private:
|
|
|
|
const ESM::Pathgrid* mPathgrid;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-04-08 00:32:43 +00:00
|
|
|
class Builder;
|
|
|
|
|
2014-04-04 06:13:47 +11:00
|
|
|
struct ConnectedPoint // edge
|
|
|
|
{
|
2023-04-08 00:32:43 +00:00
|
|
|
size_t index; // pathgrid point index of neighbour
|
2014-04-04 06:13:47 +11:00
|
|
|
float cost;
|
|
|
|
};
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-04-04 06:13:47 +11:00
|
|
|
struct Node // point
|
|
|
|
{
|
|
|
|
int componentId;
|
|
|
|
std::vector<ConnectedPoint> edges; // neighbours
|
|
|
|
};
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-04-04 06:13:47 +11:00
|
|
|
// componentId is 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 (ship & office)
|
|
|
|
// all other pathgrid points are the third set
|
|
|
|
//
|
|
|
|
std::vector<Node> mGraph;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|