TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TaxiPathGraph Class Reference

#include <TaxiPathGraph.h>

Classes

struct  EdgeCost
 

Public Member Functions

void Initialize ()
 
std::size_t GetCompleteNodeRoute (TaxiNodesEntry const *from, TaxiNodesEntry const *to, Player const *player, std::vector< uint32 > &shortestPath)
 

Static Public Member Functions

static TaxiPathGraphInstance ()
 

Private Types

typedef boost::adjacency_list
< boost::listS, boost::vecS,
boost::directedS,
boost::property
< boost::vertex_index_t,
uint32 >, boost::property
< boost::edge_weight_t,
EdgeCost > > 
Graph
 
typedef boost::property_map
< Graph, boost::edge_weight_t >
::type 
WeightMap
 
typedef Graph::vertex_descriptor vertex_descriptor
 
typedef Graph::edge_descriptor edge_descriptor
 
typedef std::pair< uint32, uint32edge
 

Private Member Functions

 TaxiPathGraph ()
 
 ~TaxiPathGraph ()
 
void AddVerticeAndEdgeFromNodeInfo (TaxiNodesEntry const *from, TaxiNodesEntry const *to, uint32 pathId, std::vector< std::pair< edge, EdgeCost >> &edges)
 
vertex_descriptor GetVertexIDFromNodeID (TaxiNodesEntry const *node)
 
uint32 GetNodeIDFromVertexID (vertex_descriptor vertexID)
 
vertex_descriptor CreateVertexFromFromNodeInfoIfNeeded (TaxiNodesEntry const *node)
 
std::size_t GetVertexCount ()
 
 TaxiPathGraph (TaxiPathGraph const &)=delete
 
TaxiPathGraphoperator= (TaxiPathGraph const &)=delete
 

Private Attributes

Graph m_graph
 
std::vector< TaxiNodesEntry
const * > 
m_vertices
 

Member Typedef Documentation

typedef std::pair<uint32, uint32> TaxiPathGraph::edge
private
typedef Graph::edge_descriptor TaxiPathGraph::edge_descriptor
private
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, boost::property<boost::vertex_index_t, uint32>, boost::property<boost::edge_weight_t, EdgeCost> > TaxiPathGraph::Graph
private
typedef Graph::vertex_descriptor TaxiPathGraph::vertex_descriptor
private
typedef boost::property_map<Graph, boost::edge_weight_t>::type TaxiPathGraph::WeightMap
private

Constructor & Destructor Documentation

TaxiPathGraph::TaxiPathGraph ( )
inlineprivate
49 { }
TaxiPathGraph::~TaxiPathGraph ( )
inlineprivate
50 { }
TaxiPathGraph::TaxiPathGraph ( TaxiPathGraph const )
privatedelete

Member Function Documentation

void TaxiPathGraph::AddVerticeAndEdgeFromNodeInfo ( TaxiNodesEntry const from,
TaxiNodesEntry const to,
uint32  pathId,
std::vector< std::pair< edge, EdgeCost >> &  edges 
)
private
81 {
82  if (from != to)
83  {
86 
87  float totalDist = 0.0f;
88  TaxiPathNodeList const& nodes = sTaxiPathNodesByPath[pathId];
89  if (nodes.size() < 2)
90  {
91  edges.push_back(std::make_pair(edge(fromVertexID, toVertexID), EdgeCost{ to, 0xFFFF }));
92  return;
93  }
94 
95  std::size_t last = nodes.size();
96  std::size_t first = 0;
97  if (nodes.size() > 2)
98  {
99  --last;
100  ++first;
101  }
102 
103  for (std::size_t i = first + 1; i < last; ++i)
104  {
105  if (nodes[i - 1]->Flags & TAXI_PATH_NODE_FLAG_TELEPORT)
106  continue;
107 
108  uint32 map1, map2;
109  DBCPosition2D pos1, pos2;
110 
111  DeterminaAlternateMapPosition(nodes[i - 1]->MapID, nodes[i - 1]->Loc.X, nodes[i - 1]->Loc.Y, nodes[i - 1]->Loc.Z, &map1, &pos1);
112  DeterminaAlternateMapPosition(nodes[i]->MapID, nodes[i]->Loc.X, nodes[i]->Loc.Y, nodes[i]->Loc.Z, &map2, &pos2);
113 
114  if (map1 != map2)
115  continue;
116 
117  totalDist += std::sqrt(
118  std::pow(pos2.X - pos1.X, 2) +
119  std::pow(pos2.Y - pos1.Y, 2) +
120  std::pow(nodes[i]->Loc.Z - nodes[i - 1]->Loc.Z, 2));
121  }
122 
123  uint32 dist = uint32(totalDist);
124  if (dist > 0xFFFF)
125  dist = 0xFFFF;
126 
127  edges.push_back(std::make_pair(edge(fromVertexID, toVertexID), EdgeCost{ to, dist }));
128  }
129 }
std::pair< uint32, uint32 > edge
Definition: TaxiPathGraph.h:47
void DeterminaAlternateMapPosition(uint32 mapId, float x, float y, float z, uint32 *newMapId, DBCPosition2D *newPos)
Definition: DBCStores.cpp:861
Definition: DBCEnums.h:26
TaxiPathNodesByPath sTaxiPathNodesByPath
Definition: DB2Stores.cpp:139
float X
Definition: DBCEnums.h:28
Graph::vertex_descriptor vertex_descriptor
Definition: TaxiPathGraph.h:45
float Y
Definition: DBCEnums.h:29
uint32_t uint32
Definition: Define.h:150
vertex_descriptor CreateVertexFromFromNodeInfoIfNeeded(TaxiNodesEntry const *node)
Definition: TaxiPathGraph.cpp:172
G3D::Quat pow(const G3D::Quat &q, double x)
Definition: Quat.h:761
uint32_t uint32
Definition: g3dmath.h:168
Definition: DBCEnums.h:701
std::vector< TaxiPathNodeEntry const * > TaxiPathNodeList
Definition: DB2Structure.h:1449

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TaxiPathGraph::vertex_descriptor TaxiPathGraph::CreateVertexFromFromNodeInfoIfNeeded ( TaxiNodesEntry const node)
private
173 {
174  //Check if we need a new one or if it may be already created
175  if (m_vertices.size() <= node->LearnableIndex)
176  m_vertices.resize(node->LearnableIndex + 1);
177 
178  m_vertices[node->LearnableIndex] = node;
179  return node->LearnableIndex;
180 }
std::vector< TaxiNodesEntry const * > m_vertices
Definition: TaxiPathGraph.h:59

+ Here is the caller graph for this function:

std::size_t TaxiPathGraph::GetCompleteNodeRoute ( TaxiNodesEntry const from,
TaxiNodesEntry const to,
Player const player,
std::vector< uint32 > &  shortestPath 
)
132 {
133  /*
134  Information about node algorithm from client
135  Since client does not give information about *ALL* nodes you have to pass by when going from sourceNodeID to destinationNodeID, we need to use Dijkstra algorithm.
136  Examining several paths I discovered the following algorithm:
137  * If destinationNodeID has is the next destination, connected directly to sourceNodeID, then, client just pick up this route regardless of distance
138  * else we use dijkstra to find the shortest path.
139  * When early landing is requested, according to behavior on retail, you can never end in a node you did not discovered before
140  */
141 
142  // Find if we have a direct path
143  uint32 pathId, goldCost;
144  sObjectMgr->GetTaxiPath(from->ID, to->ID, pathId, goldCost);
145  if (pathId)
146  shortestPath = { from->ID, to->ID };
147  else
148  {
149  shortestPath.clear();
150  std::vector<vertex_descriptor> p(boost::num_vertices(m_graph));
151 
152  boost::dijkstra_shortest_paths(m_graph, GetVertexIDFromNodeID(from),
153  boost::predecessor_map(boost::make_iterator_property_map(p.begin(), boost::get(boost::vertex_index, m_graph)))
154  .weight_map(boost::make_transform_value_property_map(
155  [player](EdgeCost const& edgeCost) { return edgeCost.EvaluateDistance(player); },
156  boost::get(boost::edge_weight, m_graph))));
157 
158  // found a path to the goal
159  for (vertex_descriptor v = GetVertexIDFromNodeID(to); ; v = p[v])
160  {
161  shortestPath.push_back(GetNodeIDFromVertexID(v));
162  if (v == p[v])
163  break;
164  }
165 
166  std::reverse(shortestPath.begin(), shortestPath.end());
167  }
168 
169  return shortestPath.size();
170 }
#define sObjectMgr
Definition: ObjectMgr.h:1567
Graph::vertex_descriptor vertex_descriptor
Definition: TaxiPathGraph.h:45
vertex_descriptor GetVertexIDFromNodeID(TaxiNodesEntry const *node)
Definition: TaxiPathGraph.cpp:69
uint32_t uint32
Definition: Define.h:150
Graph m_graph
Definition: TaxiPathGraph.h:58
uint32 GetNodeIDFromVertexID(vertex_descriptor vertexID)
Definition: TaxiPathGraph.cpp:61

+ Here is the call graph for this function:

uint32 TaxiPathGraph::GetNodeIDFromVertexID ( vertex_descriptor  vertexID)
private
62 {
63  if (vertexID < m_vertices.size())
64  return m_vertices[vertexID]->ID;
65 
67 }
std::vector< TaxiNodesEntry const * > m_vertices
Definition: TaxiPathGraph.h:59
T max(const T &x, const T &y)
Definition: g3dmath.h:320

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::size_t TaxiPathGraph::GetVertexCount ( )
private
75 {
76  //So we can use this function for readability, we define either max defined vertices or already loaded in graph count
77  return std::max(boost::num_vertices(m_graph), m_vertices.size());
78 }
std::vector< TaxiNodesEntry const * > m_vertices
Definition: TaxiPathGraph.h:59
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Graph m_graph
Definition: TaxiPathGraph.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TaxiPathGraph::vertex_descriptor TaxiPathGraph::GetVertexIDFromNodeID ( TaxiNodesEntry const node)
private
70 {
71  return node->LearnableIndex;
72 }

+ Here is the caller graph for this function:

void TaxiPathGraph::Initialize ( )
35 {
36  if (GetVertexCount() > 0)
37  return;
38 
39  std::vector<std::pair<edge, EdgeCost>> edges;
40 
41  // Initialize here
42  for (TaxiPathEntry const* path : sTaxiPathStore)
43  {
44  TaxiNodesEntry const* from = sTaxiNodesStore.LookupEntry(path->From);
45  TaxiNodesEntry const* to = sTaxiNodesStore.LookupEntry(path->To);
47  AddVerticeAndEdgeFromNodeInfo(from, to, path->ID, edges);
48  }
49 
50  // create graph
52  WeightMap weightmap = boost::get(boost::edge_weight, m_graph);
53 
54  for (std::size_t j = 0; j < edges.size(); ++j)
55  {
56  edge_descriptor e = boost::add_edge(edges[j].first.first, edges[j].first.second, m_graph).first;
57  weightmap[e] = edges[j].second;
58  }
59 }
uint32 ID
Definition: DB2Structure.h:1326
Definition: DBCEnums.h:696
boost::property_map< Graph, boost::edge_weight_t >::type WeightMap
Definition: TaxiPathGraph.h:44
Definition: DBCEnums.h:695
DB2Storage< TaxiPathEntry > sTaxiPathStore("TaxiPath.db2", TaxiPathFormat, HOTFIX_SEL_TAXI_PATH)
uint32 Flags
Definition: DB2Structure.h:1333
Definition: DB2Structure.h:1337
Definition: DB2Structure.h:1324
void AddVerticeAndEdgeFromNodeInfo(TaxiNodesEntry const *from, TaxiNodesEntry const *to, uint32 pathId, std::vector< std::pair< edge, EdgeCost >> &edges)
Definition: TaxiPathGraph.cpp:80
Graph::edge_descriptor edge_descriptor
Definition: TaxiPathGraph.h:46
boost::adjacency_list< boost::listS, boost::vecS, boost::directedS, boost::property< boost::vertex_index_t, uint32 >, boost::property< boost::edge_weight_t, EdgeCost > > Graph
Definition: TaxiPathGraph.h:43
DB2Storage< TaxiNodesEntry > sTaxiNodesStore("TaxiNodes.db2", TaxiNodesFormat, HOTFIX_SEL_TAXI_NODES)
std::size_t GetVertexCount()
Definition: TaxiPathGraph.cpp:74
Graph m_graph
Definition: TaxiPathGraph.h:58

+ Here is the call graph for this function:

TaxiPathGraph & TaxiPathGraph::Instance ( )
static
29 {
30  static TaxiPathGraph instance;
31  return instance;
32 }
Definition: TaxiPathGraph.h:28
TaxiPathGraph& TaxiPathGraph::operator= ( TaxiPathGraph const )
privatedelete

Member Data Documentation

Graph TaxiPathGraph::m_graph
private
std::vector<TaxiNodesEntry const*> TaxiPathGraph::m_vertices
private

The documentation for this class was generated from the following files: