OpenTTD
yapf_road.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "../../stdafx.h"
13 #include "yapf.hpp"
14 #include "yapf_node_road.hpp"
15 #include "../../roadstop_base.h"
16 
17 #include "../../safeguards.h"
18 
19 
20 template <class Types>
22 {
23 public:
24  typedef typename Types::Tpf Tpf;
25  typedef typename Types::TrackFollower TrackFollower;
26  typedef typename Types::NodeList::Titem Node;
27  typedef typename Node::Key Key;
28 
29 protected:
30  int m_max_cost;
31 
32  CYapfCostRoadT() : m_max_cost(0) {};
33 
35  Tpf& Yapf()
36  {
37  return *static_cast<Tpf *>(this);
38  }
39 
40  int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
41  {
42  /* height of the center of the current tile */
43  int x1 = TileX(tile) * TILE_SIZE;
44  int y1 = TileY(tile) * TILE_SIZE;
45  int z1 = GetSlopePixelZ(x1 + TILE_SIZE / 2, y1 + TILE_SIZE / 2);
46 
47  /* height of the center of the next tile */
48  int x2 = TileX(next_tile) * TILE_SIZE;
49  int y2 = TileY(next_tile) * TILE_SIZE;
50  int z2 = GetSlopePixelZ(x2 + TILE_SIZE / 2, y2 + TILE_SIZE / 2);
51 
52  if (z2 - z1 > 1) {
53  /* Slope up */
54  return Yapf().PfGetSettings().road_slope_penalty;
55  }
56  return 0;
57  }
58 
60  inline int OneTileCost(TileIndex tile, Trackdir trackdir)
61  {
62  int cost = 0;
63  /* set base cost */
64  if (IsDiagonalTrackdir(trackdir)) {
65  cost += YAPF_TILE_LENGTH;
66  switch (GetTileType(tile)) {
67  case MP_ROAD:
68  /* Increase the cost for level crossings */
69  if (IsLevelCrossing(tile)) {
70  cost += Yapf().PfGetSettings().road_crossing_penalty;
71  }
72  break;
73 
74  case MP_STATION: {
75  const RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
76  if (IsDriveThroughStopTile(tile)) {
77  /* Increase the cost for drive-through road stops */
78  cost += Yapf().PfGetSettings().road_stop_penalty;
79  DiagDirection dir = TrackdirToExitdir(trackdir);
81  /* When we're the first road stop in a 'queue' of them we increase
82  * cost based on the fill percentage of the whole queue. */
83  const RoadStop::Entry *entry = rs->GetEntry(dir);
84  cost += entry->GetOccupied() * Yapf().PfGetSettings().road_stop_occupied_penalty / entry->GetLength();
85  }
86  } else {
87  /* Increase cost for filled road stops */
88  cost += Yapf().PfGetSettings().road_stop_bay_occupied_penalty * (!rs->IsFreeBay(0) + !rs->IsFreeBay(1)) / 2;
89  }
90  break;
91  }
92 
93  default:
94  break;
95  }
96  } else {
97  /* non-diagonal trackdir */
98  cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
99  }
100  return cost;
101  }
102 
103 public:
104  inline void SetMaxCost(int max_cost)
105  {
106  m_max_cost = max_cost;
107  }
108 
114  inline bool PfCalcCost(Node &n, const TrackFollower *tf)
115  {
116  int segment_cost = 0;
117  uint tiles = 0;
118  /* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
119  TileIndex tile = n.m_key.m_tile;
120  Trackdir trackdir = n.m_key.m_td;
121  int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
122 
123  for (;;) {
124  /* base tile cost depending on distance between edges */
125  segment_cost += Yapf().OneTileCost(tile, trackdir);
126 
127  const RoadVehicle *v = Yapf().GetVehicle();
128  /* we have reached the vehicle's destination - segment should end here to avoid target skipping */
129  if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
130 
131  /* Finish if we already exceeded the maximum path cost (i.e. when
132  * searching for the nearest depot). */
133  if (m_max_cost > 0 && (parent_cost + segment_cost) > m_max_cost) {
134  return false;
135  }
136 
137  /* stop if we have just entered the depot */
139  /* next time we will reverse and leave the depot */
140  break;
141  }
142 
143  /* if there are no reachable trackdirs on new tile, we have end of road */
144  TrackFollower F(Yapf().GetVehicle());
145  if (!F.Follow(tile, trackdir)) break;
146 
147  /* if there are more trackdirs available & reachable, we are at the end of segment */
148  if (KillFirstBit(F.m_new_td_bits) != TRACKDIR_BIT_NONE) break;
149 
150  Trackdir new_td = (Trackdir)FindFirstBit2x64(F.m_new_td_bits);
151 
152  /* stop if RV is on simple loop with no junctions */
153  if (F.m_new_tile == n.m_key.m_tile && new_td == n.m_key.m_td) return false;
154 
155  /* if we skipped some tunnel tiles, add their cost */
156  segment_cost += F.m_tiles_skipped * YAPF_TILE_LENGTH;
157  tiles += F.m_tiles_skipped + 1;
158 
159  /* add hilly terrain penalty */
160  segment_cost += Yapf().SlopeCost(tile, F.m_new_tile, trackdir);
161 
162  /* add min/max speed penalties */
163  int min_speed = 0;
164  int max_veh_speed = v->GetDisplayMaxSpeed();
165  int max_speed = F.GetSpeedLimit(&min_speed);
166  if (max_speed < max_veh_speed) segment_cost += 1 * (max_veh_speed - max_speed);
167  if (min_speed > max_veh_speed) segment_cost += 10 * (min_speed - max_veh_speed);
168 
169  /* move to the next tile */
170  tile = F.m_new_tile;
171  trackdir = new_td;
172  if (tiles > MAX_MAP_SIZE) break;
173  }
174 
175  /* save end of segment back to the node */
176  n.m_segment_last_tile = tile;
177  n.m_segment_last_td = trackdir;
178 
179  /* save also tile cost */
180  n.m_cost = parent_cost + segment_cost;
181  return true;
182  }
183 };
184 
185 
186 template <class Types>
188 {
189 public:
190  typedef typename Types::Tpf Tpf;
191  typedef typename Types::TrackFollower TrackFollower;
192  typedef typename Types::NodeList::Titem Node;
193  typedef typename Node::Key Key;
194 
196  Tpf& Yapf()
197  {
198  return *static_cast<Tpf *>(this);
199  }
200 
202  inline bool PfDetectDestination(Node &n)
203  {
204  return IsRoadDepotTile(n.m_segment_last_tile);
205  }
206 
207  inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
208  {
209  return IsRoadDepotTile(tile);
210  }
211 
216  inline bool PfCalcEstimate(Node &n)
217  {
218  n.m_estimate = n.m_cost;
219  return true;
220  }
221 };
222 
223 
224 template <class Types>
226 {
227 public:
228  typedef typename Types::Tpf Tpf;
229  typedef typename Types::TrackFollower TrackFollower;
230  typedef typename Types::NodeList::Titem Node;
231  typedef typename Node::Key Key;
232 
233 protected:
234  TileIndex m_destTile;
235  TrackdirBits m_destTrackdirs;
236  StationID m_dest_station;
237  bool m_bus;
238  bool m_non_artic;
239 
240 public:
241  void SetDestination(const RoadVehicle *v)
242  {
243  if (v->current_order.IsType(OT_GOTO_STATION)) {
244  m_dest_station = v->current_order.GetDestination();
245  m_bus = v->IsBus();
246  m_destTile = CalcClosestStationTile(m_dest_station, v->tile, m_bus ? STATION_BUS : STATION_TRUCK);
247  m_non_artic = !v->HasArticulatedPart();
248  m_destTrackdirs = INVALID_TRACKDIR_BIT;
249  } else {
250  m_dest_station = INVALID_STATION;
251  m_destTile = v->dest_tile;
252  m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, v->compatible_roadtypes));
253  }
254  }
255 
256 protected:
258  Tpf& Yapf()
259  {
260  return *static_cast<Tpf *>(this);
261  }
262 
263 public:
265  inline bool PfDetectDestination(Node &n)
266  {
267  return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
268  }
269 
270  inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
271  {
272  if (m_dest_station != INVALID_STATION) {
273  return IsTileType(tile, MP_STATION) &&
274  GetStationIndex(tile) == m_dest_station &&
275  (m_bus ? IsBusStop(tile) : IsTruckStop(tile)) &&
276  (m_non_artic || IsDriveThroughStopTile(tile));
277  }
278 
279  return tile == m_destTile && HasTrackdir(m_destTrackdirs, trackdir);
280  }
281 
286  inline bool PfCalcEstimate(Node &n)
287  {
288  static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
289  static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
290  if (PfDetectDestination(n)) {
291  n.m_estimate = n.m_cost;
292  return true;
293  }
294 
295  TileIndex tile = n.m_segment_last_tile;
296  DiagDirection exitdir = TrackdirToExitdir(n.m_segment_last_td);
297  int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
298  int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
299  int x2 = 2 * TileX(m_destTile);
300  int y2 = 2 * TileY(m_destTile);
301  int dx = abs(x1 - x2);
302  int dy = abs(y1 - y2);
303  int dmin = min(dx, dy);
304  int dxy = abs(dx - dy);
305  int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
306  n.m_estimate = n.m_cost + d;
307  assert(n.m_estimate >= n.m_parent->m_estimate);
308  return true;
309  }
310 };
311 
312 
313 
314 template <class Types>
316 {
317 public:
318  typedef typename Types::Tpf Tpf;
319  typedef typename Types::TrackFollower TrackFollower;
320  typedef typename Types::NodeList::Titem Node;
321  typedef typename Node::Key Key;
322 
323 protected:
325  inline Tpf& Yapf()
326  {
327  return *static_cast<Tpf *>(this);
328  }
329 
330 public:
331 
337  inline void PfFollowNode(Node &old_node)
338  {
339  TrackFollower F(Yapf().GetVehicle());
340  if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) {
341  Yapf().AddMultipleNodes(&old_node, F);
342  }
343  }
344 
346  inline char TransportTypeChar() const
347  {
348  return 'r';
349  }
350 
351  static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
352  {
353  Tpf pf;
354  return pf.ChooseRoadTrack(v, tile, enterdir, path_found);
355  }
356 
357  inline Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
358  {
359  /* Handle special case - when next tile is destination tile.
360  * However, when going to a station the (initial) destination
361  * tile might not be a station, but a junction, in which case
362  * this method forces the vehicle to jump in circles. */
363  if (tile == v->dest_tile && !v->current_order.IsType(OT_GOTO_STATION)) {
364  /* choose diagonal trackdir reachable from enterdir */
365  return DiagDirToDiagTrackdir(enterdir);
366  }
367  /* our source tile will be the next vehicle tile (should be the given one) */
368  TileIndex src_tile = tile;
369  /* get available trackdirs on the start tile */
370  TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes));
371  /* select reachable trackdirs only */
372  src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
373 
374  /* set origin and destination nodes */
375  Yapf().SetOrigin(src_tile, src_trackdirs);
376  Yapf().SetDestination(v);
377 
378  /* find the best path */
379  path_found = Yapf().FindPath(v);
380 
381  /* if path not found - return INVALID_TRACKDIR */
382  Trackdir next_trackdir = INVALID_TRACKDIR;
383  Node *pNode = Yapf().GetBestNode();
384  if (pNode != NULL) {
385  /* path was found or at least suggested
386  * walk through the path back to its origin */
387  while (pNode->m_parent != NULL) {
388  pNode = pNode->m_parent;
389  }
390  /* return trackdir from the best origin node (one of start nodes) */
391  Node &best_next_node = *pNode;
392  assert(best_next_node.GetTile() == tile);
393  next_trackdir = best_next_node.GetTrackdir();
394  }
395  return next_trackdir;
396  }
397 
398  static uint stDistanceToTile(const RoadVehicle *v, TileIndex tile)
399  {
400  Tpf pf;
401  return pf.DistanceToTile(v, tile);
402  }
403 
404  inline uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
405  {
406  /* handle special case - when current tile is the destination tile */
407  if (dst_tile == v->tile) {
408  /* distance is zero in this case */
409  return 0;
410  }
411 
412  if (!SetOriginFromVehiclePos(v)) return UINT_MAX;
413 
414  /* get available trackdirs on the destination tile */
415  Yapf().SetDestination(v);
416 
417  /* if path not found - return distance = UINT_MAX */
418  uint dist = UINT_MAX;
419 
420  /* find the best path */
421  if (!Yapf().FindPath(v)) return dist;
422 
423  Node *pNode = Yapf().GetBestNode();
424  if (pNode != NULL) {
425  /* path was found
426  * get the path cost estimate */
427  dist = pNode->GetCostEstimate();
428  }
429 
430  return dist;
431  }
432 
434  inline bool SetOriginFromVehiclePos(const RoadVehicle *v)
435  {
436  /* set origin (tile, trackdir) */
437  TileIndex src_tile = v->tile;
438  Trackdir src_td = v->GetVehicleTrackdir();
439  if (!HasTrackdir(TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)), src_td)) {
440  /* sometimes the roadveh is not on the road (it resides on non-existing track)
441  * how should we handle that situation? */
442  return false;
443  }
444  Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
445  return true;
446  }
447 
448  static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
449  {
450  Tpf pf;
451  return pf.FindNearestDepot(v, tile, td, max_distance);
452  }
453 
461  inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
462  {
463  /* Set origin. */
464  Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
465  Yapf().SetMaxCost(max_distance);
466 
467  /* Find the best path and return if no depot is found. */
468  if (!Yapf().FindPath(v)) return FindDepotData();
469 
470  /* Return the cost of the best path and its depot. */
471  Node *n = Yapf().GetBestNode();
472  return FindDepotData(n->m_segment_last_tile, n->m_cost);
473  }
474 };
475 
476 template <class Tpf_, class Tnode_list, template <class Types> class Tdestination>
478 {
480 
481  typedef Tpf_ Tpf;
483  typedef Tnode_list NodeList;
484  typedef RoadVehicle VehicleType;
485  typedef CYapfBaseT<Types> PfBase;
488  typedef Tdestination<Types> PfDestination;
491 };
492 
493 struct CYapfRoad1 : CYapfT<CYapfRoad_TypesT<CYapfRoad1 , CRoadNodeListTrackDir, CYapfDestinationTileRoadT > > {};
494 struct CYapfRoad2 : CYapfT<CYapfRoad_TypesT<CYapfRoad2 , CRoadNodeListExitDir , CYapfDestinationTileRoadT > > {};
495 
496 struct CYapfRoadAnyDepot1 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot1, CRoadNodeListTrackDir, CYapfDestinationAnyDepotRoadT> > {};
497 struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNodeListExitDir , CYapfDestinationAnyDepotRoadT> > {};
498 
499 
500 Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found)
501 {
502  /* default is YAPF type 2 */
503  typedef Trackdir (*PfnChooseRoadTrack)(const RoadVehicle*, TileIndex, DiagDirection, bool &path_found);
504  PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg
505 
506  /* check if non-default YAPF type should be used */
508  pfnChooseRoadTrack = &CYapfRoad1::stChooseRoadTrack; // Trackdir, allow 90-deg
509  }
510 
511  Trackdir td_ret = pfnChooseRoadTrack(v, tile, enterdir, path_found);
512  return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit2x64(trackdirs);
513 }
514 
516 {
517  TileIndex tile = v->tile;
518  Trackdir trackdir = v->GetVehicleTrackdir();
519  if (!HasTrackdir(TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)), trackdir)) {
520  return FindDepotData();
521  }
522 
523  /* default is YAPF type 2 */
524  typedef FindDepotData (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int);
525  PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
526 
527  /* check if non-default YAPF type should be used */
529  pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
530  }
531 
532  return pfnFindNearestDepot(v, tile, trackdir, max_distance);
533 }
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:98
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
bool SetOriginFromVehiclePos(const RoadVehicle *v)
Return true if the valid origin (tile/trackdir) was set from the current vehicle position.
Definition: yapf_road.cpp:434
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
Definition: yapf_common.hpp:17
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:231
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:193
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition: yapf_road.cpp:286
static RoadStopType GetRoadStopType(TileIndex t)
Get the road stop type of this tile.
Definition: station_map.h:57
int GetLength() const
Get the length of this drive through stop.
Definition: roadstop_base.h:49
int OneTileCost(TileIndex tile, Trackdir trackdir)
return one tile cost
Definition: yapf_road.cpp:60
Flag for an invalid trackdirbit value.
Definition: track_type.h:122
A tile with road (or tram tracks)
Definition: tile_type.h:45
int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: roadveh.h:113
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
Definition: roadstop_base.h:58
Tpf & Yapf()
to access inherited path finder
Definition: yapf_road.cpp:325
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:237
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
bool PfCalcCost(Node &n, const TrackFollower *tf)
Called by YAPF to calculate the cost from the origin to the given node.
Definition: yapf_road.cpp:114
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
PathfinderSettings pf
settings for all pathfinders
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:320
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:192
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
Definition: road_map.h:535
FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
Find the best depot for a road vehicle.
Definition: yapf_road.cpp:461
static TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction...
Definition: track_func.h:565
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:68
void PfFollowNode(Node &old_node)
Called by YAPF to move from the given node to the next tile.
Definition: yapf_road.cpp:337
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Definition: station_map.h:234
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:449
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:321
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance)
Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF...
Definition: yapf_road.cpp:515
Buses, trucks and trams belong to this class.
Definition: roadveh.h:88
char TransportTypeChar() const
return debug report character to identify the transportation type
Definition: yapf_road.cpp:346
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:343
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
CYapfBaseT - A-star type path finder base class.
Definition: yapf_base.hpp:51
bool disable_node_optimization
whether to use exit-dir instead of trackdir in node key
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_road.cpp:318
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
static bool IsTruckStop(TileIndex t)
Is the station at t a truck stop?
Definition: station_map.h:181
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition: track_func.h:121
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:63
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
static bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
Definition: track_func.h:350
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Types::Tpf Tpf
pathfinder (derived from THIS class)
Definition: yapf_road.cpp:24
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
Definition: road_map.h:99
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:74
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition: yapf_road.cpp:202
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:901
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:547
Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found)
Finds the best path for given road vehicle using YAPF.
Definition: yapf_road.cpp:500
bool IsFreeBay(uint nr) const
Checks whether the given bay is free in this road stop.
Definition: roadstop_base.h:95
DiagDirection
Enumeration for diagonal directions.
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_road.cpp:190
Track follower helper template class (can serve pathfinders and vehicle controllers).
static TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
Calculates the tile of given station that is closest to a given tile for this we assume the station i...
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:591
Container for each entry point of a drive through road stop.
Definition: roadstop_base.h:34
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:29
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_road.cpp:228
static T KillFirstBit(T value)
Clear the first bit in an integer.
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:81
Node tailored for road pathfinding.
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:230
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:96
Tpf & Yapf()
to access inherited path finder
Definition: yapf_road.cpp:258
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Helper container to find a depot.
Base includes/functions for YAPF.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition: yapf_road.cpp:265
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:83
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:641
A tile of a station.
Definition: tile_type.h:48
static uint8 FindFirstBit2x64(const int value)
Finds the position of the first non-zero bit in an integer.
Transport by road vehicle.
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:106
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:26
A Stop for a Road Vehicle.
Definition: roadstop_base.h:24
static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next)
Checks whether the &#39;next&#39; tile is still part of the road same drive through stop &#39;rs&#39; in the same dir...
Definition: roadstop.cpp:307
Tpf & Yapf()
to access inherited path finder
Definition: yapf_road.cpp:196
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition: map_type.h:68
No track build.
Definition: track_type.h:107
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:27
Flag for an invalid trackdir.
Definition: track_type.h:93
Tpf & Yapf()
to access inherited path finder
Definition: yapf_road.cpp:35
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
Types::TrackFollower TrackFollower
track follower helper
Definition: yapf_road.cpp:25
static bool IsBusStop(TileIndex t)
Is the station at t a bus stop?
Definition: station_map.h:192
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:362
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:318
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition: roadstop.cpp:268
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition: yapf_road.cpp:216