OpenTTD Source 20250908-master-g16cd420e4c
yapf_road.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10#include "../../stdafx.h"
11#include "yapf.hpp"
12#include "yapf_node_road.hpp"
13#include "../../roadstop_base.h"
14
15#include "../../safeguards.h"
16
17
18template <class Types>
20public:
21 typedef typename Types::Tpf Tpf;
22 typedef typename Types::TrackFollower TrackFollower;
23 typedef typename Types::NodeList::Item Node;
24 typedef typename Node::Key Key;
25
26protected:
27 int max_cost;
28
29 CYapfCostRoadT() : max_cost(0) {};
30
33 {
34 return *static_cast<Tpf *>(this);
35 }
36
37 int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir)
38 {
39 /* height of the center of the current tile */
40 int x1 = TileX(tile) * TILE_SIZE;
41 int y1 = TileY(tile) * TILE_SIZE;
42 int z1 = GetSlopePixelZ(x1 + TILE_SIZE / 2, y1 + TILE_SIZE / 2, true);
43
44 /* height of the center of the next tile */
45 int x2 = TileX(next_tile) * TILE_SIZE;
46 int y2 = TileY(next_tile) * TILE_SIZE;
47 int z2 = GetSlopePixelZ(x2 + TILE_SIZE / 2, y2 + TILE_SIZE / 2, true);
48
49 if (z2 - z1 > 1) {
50 /* Slope up */
51 return Yapf().PfGetSettings().road_slope_penalty;
52 }
53 return 0;
54 }
55
57 inline int OneTileCost(TileIndex tile, Trackdir trackdir)
58 {
59 int cost = 0;
60 /* set base cost */
61 if (IsDiagonalTrackdir(trackdir)) {
62 cost += YAPF_TILE_LENGTH;
63 switch (GetTileType(tile)) {
64 case MP_ROAD:
65 /* Increase the cost for level crossings */
66 if (IsLevelCrossing(tile)) {
67 cost += Yapf().PfGetSettings().road_crossing_penalty;
68 }
69 break;
70
71 case MP_STATION: {
72 if (IsRoadWaypoint(tile)) break;
73
74 const RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
75 if (IsDriveThroughStopTile(tile)) {
76 /* Increase the cost for drive-through road stops */
77 cost += Yapf().PfGetSettings().road_stop_penalty;
78 DiagDirection dir = TrackdirToExitdir(trackdir);
80 /* When we're the first road stop in a 'queue' of them we increase
81 * cost based on the fill percentage of the whole queue. */
82 const RoadStop::Entry &entry = rs->GetEntry(dir);
83 cost += entry.GetOccupied() * Yapf().PfGetSettings().road_stop_occupied_penalty / entry.GetLength();
84 }
85 } else {
86 /* Increase cost for filled road stops */
87 cost += Yapf().PfGetSettings().road_stop_bay_occupied_penalty * (!rs->IsFreeBay(0) + !rs->IsFreeBay(1)) / 2;
88 }
89 break;
90 }
91
92 default:
93 break;
94 }
95 } else {
96 /* non-diagonal trackdir */
97 cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
98 }
99 return cost;
100 }
101
102public:
103 inline void SetMaxCost(int max_cost)
104 {
105 this->max_cost = max_cost;
106 }
107
113 inline bool PfCalcCost(Node &n, const TrackFollower *)
114 {
115 int segment_cost = 0;
116 uint tiles = 0;
117 /* start at n.key.tile / n.key.td and walk to the end of segment */
118 TileIndex tile = n.key.tile;
119 Trackdir trackdir = n.key.td;
120 int parent_cost = (n.parent != nullptr) ? n.parent->cost : 0;
121
122 for (;;) {
123 /* base tile cost depending on distance between edges */
124 segment_cost += Yapf().OneTileCost(tile, trackdir);
125
126 const RoadVehicle *v = Yapf().GetVehicle();
127 /* we have reached the vehicle's destination - segment should end here to avoid target skipping */
128 if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
129
130 /* Finish if we already exceeded the maximum path cost (i.e. when
131 * searching for the nearest depot). */
132 if (this->max_cost > 0 && (parent_cost + segment_cost) > this->max_cost) {
133 return false;
134 }
135
136 /* stop if we have just entered the depot */
138 /* next time we will reverse and leave the depot */
139 break;
140 }
141
142 /* if there are no reachable trackdirs on new tile, we have end of road */
143 TrackFollower F(Yapf().GetVehicle());
144 if (!F.Follow(tile, trackdir)) break;
145
146 /* if there are more trackdirs available & reachable, we are at the end of segment */
147 if (KillFirstBit(F.new_td_bits) != TRACKDIR_BIT_NONE) break;
148
149 Trackdir new_td = (Trackdir)FindFirstBit(F.new_td_bits);
150
151 /* stop if RV is on simple loop with no junctions */
152 if (F.new_tile == n.key.tile && new_td == n.key.td) return false;
153
154 /* if we skipped some tunnel tiles, add their cost */
155 segment_cost += F.tiles_skipped * YAPF_TILE_LENGTH;
156 tiles += F.tiles_skipped + 1;
157
158 /* add hilly terrain penalty */
159 segment_cost += Yapf().SlopeCost(tile, F.new_tile, trackdir);
160
161 /* add min/max speed penalties */
162 int min_speed = 0;
163 int max_veh_speed = std::min<int>(v->GetDisplayMaxSpeed(), v->current_order.GetMaxSpeed() * 2);
164 int max_speed = F.GetSpeedLimit(&min_speed);
165 if (max_speed < max_veh_speed) segment_cost += YAPF_TILE_LENGTH * (max_veh_speed - max_speed) * (4 + F.tiles_skipped) / max_veh_speed;
166 if (min_speed > max_veh_speed) segment_cost += YAPF_TILE_LENGTH * (min_speed - max_veh_speed);
167
168 /* move to the next tile */
169 tile = F.new_tile;
170 trackdir = new_td;
171 if (tiles > MAX_MAP_SIZE) break;
172 }
173
174 /* save end of segment back to the node */
175 n.segment_last_tile = tile;
176 n.segment_last_td = trackdir;
177
178 /* save also tile cost */
179 n.cost = parent_cost + segment_cost;
180 return true;
181 }
182};
183
184
185template <class Types>
187public:
188 typedef typename Types::Tpf Tpf;
189 typedef typename Types::TrackFollower TrackFollower;
190 typedef typename Types::NodeList::Item Node;
191 typedef typename Node::Key Key;
192
195 {
196 return *static_cast<Tpf *>(this);
197 }
198
200 inline bool PfDetectDestination(Node &n)
201 {
202 return IsRoadDepotTile(n.segment_last_tile);
203 }
204
205 inline bool PfDetectDestinationTile(TileIndex tile, Trackdir)
206 {
207 return IsRoadDepotTile(tile);
208 }
209
214 inline bool PfCalcEstimate(Node &n)
215 {
216 n.estimate = n.cost;
217 return true;
218 }
219};
220
221
222template <class Types>
224public:
225 typedef typename Types::Tpf Tpf;
226 typedef typename Types::TrackFollower TrackFollower;
227 typedef typename Types::NodeList::Item Node;
228 typedef typename Node::Key Key;
229
230protected:
231 TileIndex dest_tile;
232 TrackdirBits dest_trackdirs;
233 StationID dest_station;
234 StationType station_type;
235 bool non_artic;
236
237public:
238 void SetDestination(const RoadVehicle *v)
239 {
240 if (v->current_order.IsType(OT_GOTO_STATION)) {
241 this->dest_station = v->current_order.GetDestination().ToStationID();
242 this->station_type = v->IsBus() ? StationType::Bus : StationType::Truck;
243 this->dest_tile = CalcClosestStationTile(this->dest_station, v->tile, this->station_type);
244 this->non_artic = !v->HasArticulatedPart();
245 this->dest_trackdirs = INVALID_TRACKDIR_BIT;
246 } else if (v->current_order.IsType(OT_GOTO_WAYPOINT)) {
247 this->dest_station = v->current_order.GetDestination().ToStationID();
248 this->station_type = StationType::RoadWaypoint;
249 this->dest_tile = CalcClosestStationTile(this->dest_station, v->tile, this->station_type);
250 this->non_artic = !v->HasArticulatedPart();
251 this->dest_trackdirs = INVALID_TRACKDIR_BIT;
252 } else {
253 this->dest_station = StationID::Invalid();
254 this->dest_tile = v->dest_tile;
255 this->dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, GetRoadTramType(v->roadtype)));
256 }
257 }
258
259 const Station *GetDestinationStation() const
260 {
261 return this->dest_station != StationID::Invalid() ? Station::GetIfValid(this->dest_station) : nullptr;
262 }
263
264protected:
267 {
268 return *static_cast<Tpf *>(this);
269 }
270
271public:
273 inline bool PfDetectDestination(Node &n)
274 {
275 return this->PfDetectDestinationTile(n.segment_last_tile, n.segment_last_td);
276 }
277
278 inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
279 {
280 if (this->dest_station != StationID::Invalid()) {
281 return IsTileType(tile, MP_STATION) &&
282 GetStationIndex(tile) == this->dest_station &&
283 (this->station_type == GetStationType(tile)) &&
284 (this->non_artic || IsDriveThroughStopTile(tile));
285 }
286
287 return tile == this->dest_tile && HasTrackdir(this->dest_trackdirs, trackdir);
288 }
289
294 inline bool PfCalcEstimate(Node &n)
295 {
296 if (this->PfDetectDestination(n)) {
297 n.estimate = n.cost;
298 return true;
299 }
300
301 n.estimate = n.cost + OctileDistanceCost(n.segment_last_tile, n.segment_last_td, this->dest_tile);
302 assert(n.estimate >= n.parent->estimate);
303 return true;
304 }
305};
306
307
308
309template <class Types>
311public:
312 typedef typename Types::Tpf Tpf;
313 typedef typename Types::TrackFollower TrackFollower;
314 typedef typename Types::NodeList::Item Node;
315 typedef typename Node::Key Key;
316
317protected:
319 inline Tpf &Yapf()
320 {
321 return *static_cast<Tpf *>(this);
322 }
323
324public:
325
331 inline void PfFollowNode(Node &old_node)
332 {
333 TrackFollower F(Yapf().GetVehicle());
334 if (F.Follow(old_node.segment_last_tile, old_node.segment_last_td)) {
335 Yapf().AddMultipleNodes(&old_node, F);
336 }
337 }
338
340 inline char TransportTypeChar() const
341 {
342 return 'r';
343 }
344
345 static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found, RoadVehPathCache &path_cache)
346 {
347 Tpf pf;
348 return pf.ChooseRoadTrack(v, tile, enterdir, path_found, path_cache);
349 }
350
351 inline Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found, RoadVehPathCache &path_cache)
352 {
353 /* Handle special case - when next tile is destination tile.
354 * However, when going to a station the (initial) destination
355 * tile might not be a station, but a junction, in which case
356 * this method forces the vehicle to jump in circles. */
357 if (tile == v->dest_tile && !v->current_order.IsType(OT_GOTO_STATION)) {
358 /* choose diagonal trackdir reachable from enterdir */
359 return DiagDirToDiagTrackdir(enterdir);
360 }
361 /* our source tile will be the next vehicle tile (should be the given one) */
362 TileIndex src_tile = tile;
363 /* get available trackdirs on the start tile */
364 TrackdirBits src_trackdirs = GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype));
365 /* select reachable trackdirs only */
366 src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
367
368 /* set origin and destination nodes */
369 Yapf().SetOrigin(src_tile, src_trackdirs);
370 Yapf().SetDestination(v);
371
372 /* find the best path */
373 path_found = Yapf().FindPath(v);
374
375 /* if path not found - return INVALID_TRACKDIR */
376 Trackdir next_trackdir = INVALID_TRACKDIR;
377 Node *node = Yapf().GetBestNode();
378 if (node != nullptr) {
379 uint steps = 0;
380 for (Node *n = node; n->parent != nullptr; n = n->parent) steps++;
381
382 /* path was found or at least suggested
383 * walk through the path back to its origin */
384 while (node->parent != nullptr) {
385 steps--;
386 if (node->GetIsChoice() && steps < YAPF_ROADVEH_PATH_CACHE_SEGMENTS) {
387 path_cache.emplace_back(node->GetTrackdir(), node->GetTile());
388 }
389 node = node->parent;
390 }
391 /* return trackdir from the best origin node (one of start nodes) */
392 Node &best_next_node = *node;
393 assert(best_next_node.GetTile() == tile);
394 next_trackdir = best_next_node.GetTrackdir();
395
396 /* Check if target is a station, and cached path leads to within YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT
397 * tiles of the dest tile */
398 const Station *st = Yapf().GetDestinationStation();
399 if (st) {
400 const RoadStop *stop = st->GetPrimaryRoadStop(v);
401 if (stop != nullptr && (IsDriveThroughStopTile(stop->xy) || stop->GetNextRoadStop(v) != nullptr)) {
402 /* Destination station has at least 2 usable road stops, or first is a drive-through stop,
403 * trim end of path cache within a number of tiles of road stop tile area */
404 TileArea non_cached_area = v->IsBus() ? st->bus_station : st->truck_station;
406
407 /* Find the first tile not contained by the non-cacheable area, and remove from the cache. */
408 auto it = std::find_if(std::begin(path_cache), std::end(path_cache), [&non_cached_area](const auto &pc) { return !non_cached_area.Contains(pc.tile); });
409 path_cache.erase(std::begin(path_cache), it);
410 }
411 }
412 }
413 return next_trackdir;
414 }
415
416 inline uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
417 {
418 /* handle special case - when current tile is the destination tile */
419 if (dst_tile == v->tile) {
420 /* distance is zero in this case */
421 return 0;
422 }
423
424 if (!this->SetOriginFromVehiclePos(v)) return UINT_MAX;
425
426 /* get available trackdirs on the destination tile */
427 Yapf().SetDestination(v);
428
429 /* if path not found - return distance = UINT_MAX */
430 uint dist = UINT_MAX;
431
432 /* find the best path */
433 if (!Yapf().FindPath(v)) return dist;
434
435 Node *node = Yapf().GetBestNode();
436 if (node != nullptr) {
437 /* path was found
438 * get the path cost estimate */
439 dist = node->GetCostEstimate();
440 }
441
442 return dist;
443 }
444
447 {
448 /* set origin (tile, trackdir) */
449 TileIndex src_tile = v->tile;
450 Trackdir src_td = v->GetVehicleTrackdir();
451 if (!HasTrackdir(GetTrackdirBitsForRoad(src_tile, Yapf().IsTram() ? RTT_TRAM : RTT_ROAD), src_td)) {
452 /* sometimes the roadveh is not on the road (it resides on non-existing track)
453 * how should we handle that situation? */
454 return false;
455 }
456 Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
457 return true;
458 }
459
460 static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
461 {
462 Tpf pf;
463 return pf.FindNearestDepot(v, tile, td, max_distance);
464 }
465
473 inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
474 {
475 /* Set origin. */
476 Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
477 Yapf().SetMaxCost(max_distance);
478
479 /* Find the best path and return if no depot is found. */
480 if (!Yapf().FindPath(v)) return FindDepotData();
481
482 /* Return the cost of the best path and its depot. */
483 Node *n = Yapf().GetBestNode();
484 return FindDepotData(n->segment_last_tile, n->cost);
485 }
486};
487
488template <class Tpf_, class Tnode_list, template <class Types> class Tdestination>
491
492 typedef Tpf_ Tpf;
494 typedef Tnode_list NodeList;
495 typedef RoadVehicle VehicleType;
499 typedef Tdestination<Types> PfDestination;
502};
503
504struct CYapfRoad1 : CYapfT<CYapfRoad_TypesT<CYapfRoad1 , CRoadNodeListTrackDir, CYapfDestinationTileRoadT>> {};
505struct CYapfRoad2 : CYapfT<CYapfRoad_TypesT<CYapfRoad2 , CRoadNodeListExitDir , CYapfDestinationTileRoadT>> {};
506
507struct CYapfRoadAnyDepot1 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot1, CRoadNodeListTrackDir, CYapfDestinationAnyDepotRoadT>> {};
508struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNodeListExitDir , CYapfDestinationAnyDepotRoadT>> {};
509
510
511Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
512{
514 ? CYapfRoad1::stChooseRoadTrack(v, tile, enterdir, path_found, path_cache) // Trackdir
515 : CYapfRoad2::stChooseRoadTrack(v, tile, enterdir, path_found, path_cache); // ExitDir, allow 90-deg
516
517 return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit(trackdirs);
518}
519
521{
522 TileIndex tile = v->tile;
523 Trackdir trackdir = v->GetVehicleTrackdir();
524
525 if (!HasTrackdir(GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype)), trackdir)) {
526 return FindDepotData();
527 }
528
530 ? CYapfRoadAnyDepot1::stFindNearestDepot(v, tile, trackdir, max_distance) // Trackdir
531 : CYapfRoadAnyDepot2::stFindNearestDepot(v, tile, trackdir, max_distance); // ExitDir
532}
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
constexpr T KillFirstBit(T value)
Clear the first bit in an integer.
CYapfBaseT - A-star type path finder base class.
Definition yapf_base.hpp:49
Types::TrackFollower TrackFollower
track follower helper
Definition yapf_road.cpp:22
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:23
Node::Key Key
key to hash tables
Definition yapf_road.cpp:24
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:32
int OneTileCost(TileIndex tile, Trackdir trackdir)
return one tile cost
Definition yapf_road.cpp:57
bool PfCalcCost(Node &n, const TrackFollower *)
Called by YAPF to calculate the cost from the origin to the given node.
Types::Tpf Tpf
pathfinder (derived from THIS class)
Definition yapf_road.cpp:21
Tpf & Yapf()
to access inherited path finder
Types::NodeList::Item Node
this will be our node type
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Node::Key Key
key to hash tables
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Node::Key Key
key to hash tables
Tpf & Yapf()
to access inherited path finder
Types::NodeList::Item Node
this will be our node type
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Types::NodeList::Item Node
this will be our node type
FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
Find the best depot for a road vehicle.
Tpf & Yapf()
to access inherited path finder
void PfFollowNode(Node &old_node)
Called by YAPF to move from the given node to the next tile.
Node::Key Key
key to hash tables
char TransportTypeChar() const
return debug report character to identify the transportation type
bool SetOriginFromVehiclePos(const RoadVehicle *v)
Return true if the valid origin (tile/trackdir) was set from the current vehicle position.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
Hash table based node list multi-container class.
Definition nodelist.hpp:21
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DiagDirection
Enumeration for diagonal directions.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:424
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:414
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:569
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition map_type.h:40
TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
Wrapper around GetTileTrackStatus() and TrackStatusToTrackdirBits(), as for single tram bits GetTileT...
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...
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
static const int YAPF_ROADVEH_PATH_CACHE_SEGMENTS
Maximum segments of road vehicle path cache.
static const int YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT
Distance from destination road stops to not cache any further.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
Definition road_map.h:545
static debug_inline bool IsRoadDepotTile(Tile t)
Return whether a tile is a road depot tile.
Definition road_map.h:100
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition station_map.h:44
bool IsRoadWaypoint(Tile t)
Is the station at t a road waypoint?
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station or waypoint?
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
RoadStopType GetRoadStopType(Tile t)
Get the road stop type of this tile.
Definition station_map.h:56
StationType
Station types.
Track follower helper template class (can serve pathfinders and vehicle controllers).
Helper container to find a depot.
PathfinderSettings pf
settings for all pathfinders
Node of the link graph.
Definition linkgraph.h:90
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
Definition order_base.h:197
DestinationID GetDestination() const
Gets the destination of this order.
Definition order_base.h:99
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition order_base.h:66
Represents the covered area of e.g.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
Definition tilearea.cpp:104
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Definition tilearea.cpp:123
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Container for each entry point of a drive through road stop.
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
int GetLength() const
Get the length of this drive through stop.
A Stop for a Road Vehicle.
bool IsFreeBay(uint nr) const
Checks whether the given bay is free in this road stop.
RoadStop * GetNextRoadStop(const struct RoadVehicle *v) const
Get the next road stop accessible by this vehicle.
Definition roadstop.cpp:42
TileIndex xy
Position on the map.
const Entry & GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next)
Checks whether the 'next' tile is still part of the road same drive through stop 'rs' in the same dir...
Definition roadstop.cpp:294
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition roadstop.cpp:255
Buses, trucks and trams belong to this class.
Definition roadveh.h:98
bool IsBus() const
Check whether a roadvehicle is a bus.
int GetDisplayMaxSpeed() const override
Gets the maximum speed in km-ish/h that can be sent into string parameters for string processing.
Definition roadveh.h:125
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
Definition roadveh.h:108
static Station * GetIfValid(auto index)
Returns station if the index is a valid index for this station type.
Station data structure.
TileArea bus_station
Tile area the bus 'station' part covers.
TileArea truck_station
Tile area the truck 'station' part covers.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Order current_order
The current order (+ status, like: loading)
TileIndex tile
Current tile index.
TileIndex dest_tile
Heading for this tile.
bool disable_node_optimization
whether to use exit-dir instead of trackdir in node key
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
@ MP_ROAD
A tile with road (or tram tracks)
Definition tile_type.h:50
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition track_func.h:352
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
Definition track_func.h:555
bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition track_func.h:631
bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
Definition track_func.h:340
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition track_func.h:537
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition track_func.h:111
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition track_func.h:439
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:66
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:85
TrackdirBits
Allow incrementing of Trackdir variables.
Definition track_type.h:97
@ TRACKDIR_BIT_NONE
No track build.
Definition track_type.h:98
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
Definition track_type.h:113
@ TRANSPORT_ROAD
Transport by road vehicle.
Base includes/functions for YAPF.
int OctileDistanceCost(TileIndex start_tile, Trackdir start_td, TileIndex destination_tile)
Calculates the octile distance cost between a starting tile / trackdir and a destination tile.
Node tailored for road pathfinding.
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.
Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
Finds the best path for given road vehicle using YAPF.