equal
deleted
inserted
replaced
158 /// to access inherited path finder |
158 /// to access inherited path finder |
159 Tpf& Yapf() {return *static_cast<Tpf*>(this);} |
159 Tpf& Yapf() {return *static_cast<Tpf*>(this);} |
160 FORCEINLINE char TransportTypeChar() const {return 'T';} |
160 FORCEINLINE char TransportTypeChar() const {return 'T';} |
161 |
161 |
162 /** Called by YAPF to move from the given node to the next tile. For each |
162 /** Called by YAPF to move from the given node to the next tile. For each |
163 * reachable trackdir on the new tile creates new node, initializes it |
163 * reachable trackdir on the new tile creates new node, initializes it |
164 * and adds it to the open list by calling Yapf().AddNewNode(n) */ |
164 * and adds it to the open list by calling Yapf().AddNewNode(n) */ |
165 FORCEINLINE void PfFollowNode(Node& org) |
165 FORCEINLINE void PfFollowNode(Node& org) |
166 { |
166 { |
167 int x_org = org.m_key.m_x; |
167 int x_org = org.m_key.m_x; |
168 int y_org = org.m_key.m_y; |
168 int y_org = org.m_key.m_y; |
169 int z_org = Map::MapZ(x_org, y_org); |
169 int z_org = Map::MapZ(x_org, y_org); |
205 n1.m_key.m_exitdir = TrackdirToExitdir(n1.m_key.m_td); |
205 n1.m_key.m_exitdir = TrackdirToExitdir(n1.m_key.m_td); |
206 Yapf().AddStartupNode(n1); |
206 Yapf().AddStartupNode(n1); |
207 } |
207 } |
208 |
208 |
209 /** Called by YAPF to calculate the cost from the origin to the given node. |
209 /** Called by YAPF to calculate the cost from the origin to the given node. |
210 * Calculates only the cost of given node, adds it to the parent node cost |
210 * Calculates only the cost of given node, adds it to the parent node cost |
211 * and stores the result into Node::m_cost member */ |
211 * and stores the result into Node::m_cost member */ |
212 FORCEINLINE bool PfCalcCost(Node& n) |
212 FORCEINLINE bool PfCalcCost(Node& n) |
213 { |
213 { |
214 // base tile cost depending on distance |
214 // base tile cost depending on distance |
215 int c = IsDiagonalTrackdir(n.m_key.m_td) ? 10 : 7; |
215 int c = IsDiagonalTrackdir(n.m_key.m_td) ? 10 : 7; |
216 // additional penalty for curve |
216 // additional penalty for curve |
223 n.m_cost = n.m_parent->m_cost + c; |
223 n.m_cost = n.m_parent->m_cost + c; |
224 return true; |
224 return true; |
225 } |
225 } |
226 |
226 |
227 /** Called by YAPF to calculate cost estimate. Calculates distance to the destination |
227 /** Called by YAPF to calculate cost estimate. Calculates distance to the destination |
228 * adds it to the actual cost from origin and stores the sum to the Node::m_estimate */ |
228 * adds it to the actual cost from origin and stores the sum to the Node::m_estimate */ |
229 FORCEINLINE bool PfCalcEstimate(Node& n) |
229 FORCEINLINE bool PfCalcEstimate(Node& n) |
230 { |
230 { |
231 int dx = abs(n.m_key.m_x - m_x2); |
231 int dx = abs(n.m_key.m_x - m_x2); |
232 int dy = abs(n.m_key.m_y - m_y2); |
232 int dy = abs(n.m_key.m_y - m_y2); |
233 int dd = min(dx, dy); |
233 int dd = min(dx, dy); |