OpenTTD
yapf_road.cpp
Go to the documentation of this file.
1 /* $Id: yapf_road.cpp 27586 2016-05-29 14:14:52Z frosch $ */
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:
31  Tpf& Yapf()
32  {
33  return *static_cast<Tpf *>(this);
34  }
35 
36  int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
37  {
38  /* height of the center of the current tile */
39  int x1 = TileX(tile) * TILE_SIZE;
40  int y1 = TileY(tile) * TILE_SIZE;
41  int z1 = GetSlopePixelZ(x1 + TILE_SIZE / 2, y1 + TILE_SIZE / 2);
42 
43  /* height of the center of the next tile */
44  int x2 = TileX(next_tile) * TILE_SIZE;
45  int y2 = TileY(next_tile) * TILE_SIZE;
46  int z2 = GetSlopePixelZ(x2 + TILE_SIZE / 2, y2 + TILE_SIZE / 2);
47 
48  if (z2 - z1 > 1) {
49  /* Slope up */
50  return Yapf().PfGetSettings().road_slope_penalty;
51  }
52  return 0;
53  }
54 
56  inline int OneTileCost(TileIndex tile, Trackdir trackdir)
57  {
58  int cost = 0;
59  /* set base cost */
60  if (IsDiagonalTrackdir(trackdir)) {
61  cost += YAPF_TILE_LENGTH;
62  switch (GetTileType(tile)) {
63  case MP_ROAD:
64  /* Increase the cost for level crossings */
65  if (IsLevelCrossing(tile)) {
66  cost += Yapf().PfGetSettings().road_crossing_penalty;
67  }
68  break;
69 
70  case MP_STATION: {
71  const RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
72  if (IsDriveThroughStopTile(tile)) {
73  /* Increase the cost for drive-through road stops */
74  cost += Yapf().PfGetSettings().road_stop_penalty;
75  DiagDirection dir = TrackdirToExitdir(trackdir);
77  /* When we're the first road stop in a 'queue' of them we increase
78  * cost based on the fill percentage of the whole queue. */
79  const RoadStop::Entry *entry = rs->GetEntry(dir);
80  cost += entry->GetOccupied() * Yapf().PfGetSettings().road_stop_occupied_penalty / entry->GetLength();
81  }
82  } else {
83  /* Increase cost for filled road stops */
84  cost += Yapf().PfGetSettings().road_stop_bay_occupied_penalty * (!rs->IsFreeBay(0) + !rs->IsFreeBay(1)) / 2;
85  }
86  break;
87  }
88 
89  default:
90  break;
91  }
92  } else {
93  /* non-diagonal trackdir */
94  cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
95  }
96  return cost;
97  }
98 
99 public:
105  inline bool PfCalcCost(Node &n, const TrackFollower *tf)
106  {
107  int segment_cost = 0;
108  uint tiles = 0;
109  /* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
110  TileIndex tile = n.m_key.m_tile;
111  Trackdir trackdir = n.m_key.m_td;
112  for (;;) {
113  /* base tile cost depending on distance between edges */
114  segment_cost += Yapf().OneTileCost(tile, trackdir);
115 
116  const RoadVehicle *v = Yapf().GetVehicle();
117  /* we have reached the vehicle's destination - segment should end here to avoid target skipping */
118  if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
119 
120  /* stop if we have just entered the depot */
122  /* next time we will reverse and leave the depot */
123  break;
124  }
125 
126  /* if there are no reachable trackdirs on new tile, we have end of road */
127  TrackFollower F(Yapf().GetVehicle());
128  if (!F.Follow(tile, trackdir)) break;
129 
130  /* if there are more trackdirs available & reachable, we are at the end of segment */
131  if (KillFirstBit(F.m_new_td_bits) != TRACKDIR_BIT_NONE) break;
132 
133  Trackdir new_td = (Trackdir)FindFirstBit2x64(F.m_new_td_bits);
134 
135  /* stop if RV is on simple loop with no junctions */
136  if (F.m_new_tile == n.m_key.m_tile && new_td == n.m_key.m_td) return false;
137 
138  /* if we skipped some tunnel tiles, add their cost */
139  segment_cost += F.m_tiles_skipped * YAPF_TILE_LENGTH;
140  tiles += F.m_tiles_skipped + 1;
141 
142  /* add hilly terrain penalty */
143  segment_cost += Yapf().SlopeCost(tile, F.m_new_tile, trackdir);
144 
145  /* add min/max speed penalties */
146  int min_speed = 0;
147  int max_veh_speed = v->GetDisplayMaxSpeed();
148  int max_speed = F.GetSpeedLimit(&min_speed);
149  if (max_speed < max_veh_speed) segment_cost += 1 * (max_veh_speed - max_speed);
150  if (min_speed > max_veh_speed) segment_cost += 10 * (min_speed - max_veh_speed);
151 
152  /* move to the next tile */
153  tile = F.m_new_tile;
154  trackdir = new_td;
155  if (tiles > MAX_MAP_SIZE) break;
156  }
157 
158  /* save end of segment back to the node */
159  n.m_segment_last_tile = tile;
160  n.m_segment_last_td = trackdir;
161 
162  /* save also tile cost */
163  int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
164  n.m_cost = parent_cost + segment_cost;
165  return true;
166  }
167 };
168 
169 
170 template <class Types>
172 {
173 public:
174  typedef typename Types::Tpf Tpf;
175  typedef typename Types::TrackFollower TrackFollower;
176  typedef typename Types::NodeList::Titem Node;
177  typedef typename Node::Key Key;
178 
180  Tpf& Yapf()
181  {
182  return *static_cast<Tpf *>(this);
183  }
184 
186  inline bool PfDetectDestination(Node &n)
187  {
188  bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
189  return bDest;
190  }
191 
192  inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
193  {
194  return IsRoadDepotTile(tile);
195  }
196 
201  inline bool PfCalcEstimate(Node &n)
202  {
203  n.m_estimate = n.m_cost;
204  return true;
205  }
206 };
207 
208 
209 template <class Types>
211 {
212 public:
213  typedef typename Types::Tpf Tpf;
214  typedef typename Types::TrackFollower TrackFollower;
215  typedef typename Types::NodeList::Titem Node;
216  typedef typename Node::Key Key;
217 
218 protected:
219  TileIndex m_destTile;
220  TrackdirBits m_destTrackdirs;
221  StationID m_dest_station;
222  bool m_bus;
223  bool m_non_artic;
224 
225 public:
226  void SetDestination(const RoadVehicle *v)
227  {
228  if (v->current_order.IsType(OT_GOTO_STATION)) {
229  m_dest_station = v->current_order.GetDestination();
230  m_bus = v->IsBus();
231  m_destTile = CalcClosestStationTile(m_dest_station, v->tile, m_bus ? STATION_BUS : STATION_TRUCK);
232  m_non_artic = !v->HasArticulatedPart();
233  m_destTrackdirs = INVALID_TRACKDIR_BIT;
234  } else {
235  m_dest_station = INVALID_STATION;
236  m_destTile = v->dest_tile;
237  m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, v->compatible_roadtypes));
238  }
239  }
240 
241 protected:
243  Tpf& Yapf()
244  {
245  return *static_cast<Tpf *>(this);
246  }
247 
248 public:
250  inline bool PfDetectDestination(Node &n)
251  {
252  return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
253  }
254 
255  inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
256  {
257  if (m_dest_station != INVALID_STATION) {
258  return IsTileType(tile, MP_STATION) &&
259  GetStationIndex(tile) == m_dest_station &&
260  (m_bus ? IsBusStop(tile) : IsTruckStop(tile)) &&
261  (m_non_artic || IsDriveThroughStopTile(tile));
262  }
263 
264  return tile == m_destTile && ((m_destTrackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE);
265  }
266 
271  inline bool PfCalcEstimate(Node &n)
272  {
273  static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
274  static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
275  if (PfDetectDestination(n)) {
276  n.m_estimate = n.m_cost;
277  return true;
278  }
279 
280  TileIndex tile = n.m_segment_last_tile;
281  DiagDirection exitdir = TrackdirToExitdir(n.m_segment_last_td);
282  int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
283  int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
284  int x2 = 2 * TileX(m_destTile);
285  int y2 = 2 * TileY(m_destTile);
286  int dx = abs(x1 - x2);
287  int dy = abs(y1 - y2);
288  int dmin = min(dx, dy);
289  int dxy = abs(dx - dy);
290  int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
291  n.m_estimate = n.m_cost + d;
292  assert(n.m_estimate >= n.m_parent->m_estimate);
293  return true;
294  }
295 };
296 
297 
298 
299 template <class Types>
301 {
302 public:
303  typedef typename Types::Tpf Tpf;
304  typedef typename Types::TrackFollower TrackFollower;
305  typedef typename Types::NodeList::Titem Node;
306  typedef typename Node::Key Key;
307 
308 protected:
310  inline Tpf& Yapf()
311  {
312  return *static_cast<Tpf *>(this);
313  }
314 
315 public:
316 
322  inline void PfFollowNode(Node &old_node)
323  {
324  TrackFollower F(Yapf().GetVehicle());
325  if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) {
326  Yapf().AddMultipleNodes(&old_node, F);
327  }
328  }
329 
331  inline char TransportTypeChar() const
332  {
333  return 'r';
334  }
335 
336  static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
337  {
338  Tpf pf;
339  return pf.ChooseRoadTrack(v, tile, enterdir, path_found);
340  }
341 
342  inline Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
343  {
344  /* Handle special case - when next tile is destination tile.
345  * However, when going to a station the (initial) destination
346  * tile might not be a station, but a junction, in which case
347  * this method forces the vehicle to jump in circles. */
348  if (tile == v->dest_tile && !v->current_order.IsType(OT_GOTO_STATION)) {
349  /* choose diagonal trackdir reachable from enterdir */
350  return DiagDirToDiagTrackdir(enterdir);
351  }
352  /* our source tile will be the next vehicle tile (should be the given one) */
353  TileIndex src_tile = tile;
354  /* get available trackdirs on the start tile */
355  TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes));
356  /* select reachable trackdirs only */
357  src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
358 
359  /* set origin and destination nodes */
360  Yapf().SetOrigin(src_tile, src_trackdirs);
361  Yapf().SetDestination(v);
362 
363  /* find the best path */
364  path_found = Yapf().FindPath(v);
365 
366  /* if path not found - return INVALID_TRACKDIR */
367  Trackdir next_trackdir = INVALID_TRACKDIR;
368  Node *pNode = Yapf().GetBestNode();
369  if (pNode != NULL) {
370  /* path was found or at least suggested
371  * walk through the path back to its origin */
372  while (pNode->m_parent != NULL) {
373  pNode = pNode->m_parent;
374  }
375  /* return trackdir from the best origin node (one of start nodes) */
376  Node &best_next_node = *pNode;
377  assert(best_next_node.GetTile() == tile);
378  next_trackdir = best_next_node.GetTrackdir();
379  }
380  return next_trackdir;
381  }
382 
383  static uint stDistanceToTile(const RoadVehicle *v, TileIndex tile)
384  {
385  Tpf pf;
386  return pf.DistanceToTile(v, tile);
387  }
388 
389  inline uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
390  {
391  /* handle special case - when current tile is the destination tile */
392  if (dst_tile == v->tile) {
393  /* distance is zero in this case */
394  return 0;
395  }
396 
397  if (!SetOriginFromVehiclePos(v)) return UINT_MAX;
398 
399  /* get available trackdirs on the destination tile */
400  Yapf().SetDestination(v);
401 
402  /* if path not found - return distance = UINT_MAX */
403  uint dist = UINT_MAX;
404 
405  /* find the best path */
406  if (!Yapf().FindPath(v)) return dist;
407 
408  Node *pNode = Yapf().GetBestNode();
409  if (pNode != NULL) {
410  /* path was found
411  * get the path cost estimate */
412  dist = pNode->GetCostEstimate();
413  }
414 
415  return dist;
416  }
417 
419  inline bool SetOriginFromVehiclePos(const RoadVehicle *v)
420  {
421  /* set origin (tile, trackdir) */
422  TileIndex src_tile = v->tile;
423  Trackdir src_td = v->GetVehicleTrackdir();
424  if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
425  /* sometimes the roadveh is not on the road (it resides on non-existing track)
426  * how should we handle that situation? */
427  return false;
428  }
429  Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
430  return true;
431  }
432 
433  static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
434  {
435  Tpf pf;
436  return pf.FindNearestDepot(v, tile, td, max_distance);
437  }
438 
450  inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
451  {
452  /* Set origin. */
453  Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
454 
455  /* Find the best path and return if no depot is found. */
456  if (!Yapf().FindPath(v)) return FindDepotData();
457 
458  /* Return the cost of the best path and its depot. */
459  Node *n = Yapf().GetBestNode();
460  return FindDepotData(n->m_segment_last_tile, n->m_cost);
461  }
462 };
463 
464 template <class Tpf_, class Tnode_list, template <class Types> class Tdestination>
466 {
468 
469  typedef Tpf_ Tpf;
471  typedef Tnode_list NodeList;
472  typedef RoadVehicle VehicleType;
473  typedef CYapfBaseT<Types> PfBase;
476  typedef Tdestination<Types> PfDestination;
479 };
480 
481 struct CYapfRoad1 : CYapfT<CYapfRoad_TypesT<CYapfRoad1 , CRoadNodeListTrackDir, CYapfDestinationTileRoadT > > {};
482 struct CYapfRoad2 : CYapfT<CYapfRoad_TypesT<CYapfRoad2 , CRoadNodeListExitDir , CYapfDestinationTileRoadT > > {};
483 
484 struct CYapfRoadAnyDepot1 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot1, CRoadNodeListTrackDir, CYapfDestinationAnyDepotRoadT> > {};
485 struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNodeListExitDir , CYapfDestinationAnyDepotRoadT> > {};
486 
487 
488 Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found)
489 {
490  /* default is YAPF type 2 */
491  typedef Trackdir (*PfnChooseRoadTrack)(const RoadVehicle*, TileIndex, DiagDirection, bool &path_found);
492  PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg
493 
494  /* check if non-default YAPF type should be used */
496  pfnChooseRoadTrack = &CYapfRoad1::stChooseRoadTrack; // Trackdir, allow 90-deg
497  }
498 
499  Trackdir td_ret = pfnChooseRoadTrack(v, tile, enterdir, path_found);
500  return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit2x64(trackdirs);
501 }
502 
504 {
505  TileIndex tile = v->tile;
506  Trackdir trackdir = v->GetVehicleTrackdir();
507  if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
508  return FindDepotData();
509  }
510 
511  /* default is YAPF type 2 */
512  typedef FindDepotData (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int);
513  PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
514 
515  /* check if non-default YAPF type should be used */
517  pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
518  }
519 
520  return pfnFindNearestDepot(v, tile, trackdir, max_distance);
521 }
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:89
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:419
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:216
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:177
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition: yapf_road.cpp:271
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:56
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:310
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:105
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:305
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:176
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
Definition: road_map.h:534
FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
Find the best depot for a road vehicle.
Definition: yapf_road.cpp:450
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:543
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:322
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:427
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:306
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:503
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:331
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 give tiletype.
Definition: tile_map.h:143
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:303
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
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.
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:186
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:900
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:525
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:488
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:174
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:509
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:213
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:80
Node tailored for road pathfinding.
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:215
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:243
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:250
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:619
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:180
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition: map_type.h:67
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:31
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:340
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:201