OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pathgrid.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWMECHANICS_PATHGRID_H
2 #define GAME_MWMECHANICS_PATHGRID_H
3 
4 #include <list>
5 
7 
8 namespace ESM
9 {
10  struct Cell;
11 }
12 
13 namespace MWWorld
14 {
15  class CellStore;
16 }
17 
18 namespace MWMechanics
19 {
21  {
22  public:
23  PathgridGraph(const MWWorld::CellStore* cell);
24 
25  bool load(const MWWorld::CellStore *cell);
26 
27  const ESM::Pathgrid* getPathgrid() const;
28 
29  // returns true if end point is strongly connected (i.e. reachable
30  // from start point) both start and end are pathgrid point indexes
31  bool isPointConnected(const int start, const int end) const;
32 
33  // get neighbouring nodes for index node and put them to "nodes" vector
34  void getNeighbouringPoints(const int index, ESM::Pathgrid::PointList &nodes) const;
35 
36  // the input parameters are pathgrid point indexes
37  // the output list is in local (internal cells) or world (external
38  // cells) coordinates
39  //
40  // NOTE: if start equals end an empty path is returned
41  std::list<ESM::Pathgrid::Point> aStarSearch(const int start,
42  const int end) const;
43  private:
44 
45  const ESM::Cell *mCell;
48 
49  struct ConnectedPoint // edge
50  {
51  int index; // pathgrid point index of neighbour
52  float cost;
53  };
54 
55  struct Node // point
56  {
58  std::vector<ConnectedPoint> edges; // neighbours
59  };
60 
61  // componentId is an integer indicating the groups of connected
62  // pathgrid points (all connected points will have the same value)
63  //
64  // In Seyda Neen there are 3:
65  //
66  // 52, 53 and 54 are one set (enclosed yard)
67  // 48, 49, 50, 51, 84, 85, 86, 87, 88, 89, 90 (ship & office)
68  // all other pathgrid points are the third set
69  //
70  std::vector<Node> mGraph;
72 
73  // variables used to calculate connected components
74  int mSCCId;
75  int mSCCIndex;
76  std::vector<int> mSCCStack;
77  typedef std::pair<int, int> VPair; // first is index, second is lowlink
78  std::vector<VPair> mSCCPoint;
79  // methods used to calculate connected components
80  void recursiveStrongConnect(int v);
81  void buildConnectedPoints();
82  };
83 }
84 
85 #endif
std::pair< int, int > VPair
Definition: pathgrid.hpp:77
Definition: pathgrid.hpp:55
std::vector< Point > PointList
Definition: loadpgrd.hpp:53
void getNeighbouringPoints(const int index, ESM::Pathgrid::PointList &nodes) const
Definition: pathgrid.cpp:223
int mSCCId
Definition: pathgrid.hpp:74
std::vector< int > mSCCStack
Definition: pathgrid.hpp:76
void buildConnectedPoints()
Definition: pathgrid.cpp:202
const ESM::Pathgrid * getPathgrid() const
Definition: pathgrid.cpp:134
bool mIsExterior
Definition: pathgrid.hpp:47
int mSCCIndex
Definition: pathgrid.hpp:75
std::vector< Node > mGraph
Definition: pathgrid.hpp:70
void recursiveStrongConnect(int v)
Definition: pathgrid.cpp:140
int index
Definition: pathgrid.hpp:51
std::list< ESM::Pathgrid::Point > aStarSearch(const int start, const int end) const
Definition: pathgrid.cpp:260
Mutable state of a cell.
Definition: cellstore.hpp:51
std::vector< VPair > mSCCPoint
Definition: pathgrid.hpp:78
std::vector< ConnectedPoint > edges
Definition: pathgrid.hpp:58
Definition: loadpgrd.hpp:16
Definition: loadcell.hpp:64
PathgridGraph(const MWWorld::CellStore *cell)
Definition: pathgrid.cpp:52
const ESM::Cell * mCell
Definition: pathgrid.hpp:45
Definition: pathgrid.hpp:20
float cost
Definition: pathgrid.hpp:52
const ESM::Pathgrid * mPathgrid
Definition: pathgrid.hpp:46
bool isPointConnected(const int start, const int end) const
Definition: pathgrid.cpp:218
bool mIsGraphConstructed
Definition: pathgrid.hpp:71
bool load(const MWWorld::CellStore *cell)
Definition: pathgrid.cpp:100
int componentId
Definition: pathgrid.hpp:57