OpenTTD Source 20250818-master-g1850ad1aa2
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 static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
297 static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
298 if (this->PfDetectDestination(n)) {
299 n.estimate = n.cost;
300 return true;
301 }
302
303 TileIndex tile = n.segment_last_tile;
304 DiagDirection exitdir = TrackdirToExitdir(n.segment_last_td);
305 int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
306 int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
307 int x2 = 2 * TileX(this->dest_tile);
308 int y2 = 2 * TileY(this->dest_tile);
309 int dx = abs(x1 - x2);
310 int dy = abs(y1 - y2);
311 int dmin = std::min(dx, dy);
312 int dxy = abs(dx - dy);
313 int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
314 n.estimate = n.cost + d;
315 assert(n.estimate >= n.parent->estimate);
316 return true;
317 }
318};
319
320
321
322template <class Types>
324public:
325 typedef typename Types::Tpf Tpf;
326 typedef typename Types::TrackFollower TrackFollower;
327 typedef typename Types::NodeList::Item Node;
328 typedef typename Node::Key Key;
329
330protected:
332 inline Tpf &Yapf()
333 {
334 return *static_cast<Tpf *>(this);
335 }
336
337public:
338
344 inline void PfFollowNode(Node &old_node)
345 {
346 TrackFollower F(Yapf().GetVehicle());
347 if (F.Follow(old_node.segment_last_tile, old_node.segment_last_td)) {
348 Yapf().AddMultipleNodes(&old_node, F);
349 }
350 }
351
353 inline char TransportTypeChar() const
354 {
355 return 'r';
356 }
357
358 static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found, RoadVehPathCache &path_cache)
359 {
360 Tpf pf;
361 return pf.ChooseRoadTrack(v, tile, enterdir, path_found, path_cache);
362 }
363
364 inline Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found, RoadVehPathCache &path_cache)
365 {
366 /* Handle special case - when next tile is destination tile.
367 * However, when going to a station the (initial) destination
368 * tile might not be a station, but a junction, in which case
369 * this method forces the vehicle to jump in circles. */
370 if (tile == v->dest_tile && !v->current_order.IsType(OT_GOTO_STATION)) {
371 /* choose diagonal trackdir reachable from enterdir */
372 return DiagDirToDiagTrackdir(enterdir);
373 }
374 /* our source tile will be the next vehicle tile (should be the given one) */
375 TileIndex src_tile = tile;
376 /* get available trackdirs on the start tile */
377 TrackdirBits src_trackdirs = GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype));
378 /* select reachable trackdirs only */
379 src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
380
381 /* set origin and destination nodes */
382 Yapf().SetOrigin(src_tile, src_trackdirs);
383 Yapf().SetDestination(v);
384
385 /* find the best path */
386 path_found = Yapf().FindPath(v);
387
388 /* if path not found - return INVALID_TRACKDIR */
389 Trackdir next_trackdir = INVALID_TRACKDIR;
390 Node *node = Yapf().GetBestNode();
391 if (node != nullptr) {
392 uint steps = 0;
393 for (Node *n = node; n->parent != nullptr; n = n->parent) steps++;
394
395 /* path was found or at least suggested
396 * walk through the path back to its origin */
397 while (node->parent != nullptr) {
398 steps--;
399 if (node->GetIsChoice() && steps < YAPF_ROADVEH_PATH_CACHE_SEGMENTS) {
400 path_cache.emplace_back(node->GetTrackdir(), node->GetTile());
401 }
402 node = node->parent;
403 }
404 /* return trackdir from the best origin node (one of start nodes) */
405 Node &best_next_node = *node;
406 assert(best_next_node.GetTile() == tile);
407 next_trackdir = best_next_node.GetTrackdir();
408
409 /* Check if target is a station, and cached path leads to within YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT
410 * tiles of the dest tile */
411 const Station *st = Yapf().GetDestinationStation();
412 if (st) {
413 const RoadStop *stop = st->GetPrimaryRoadStop(v);
414 if (stop != nullptr && (IsDriveThroughStopTile(stop->xy) || stop->GetNextRoadStop(v) != nullptr)) {
415 /* Destination station has at least 2 usable road stops, or first is a drive-through stop,
416 * trim end of path cache within a number of tiles of road stop tile area */
417 TileArea non_cached_area = v->IsBus() ? st->bus_station : st->truck_station;
419
420 /* Find the first tile not contained by the non-cachable area, and remove from the cache. */
421 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); });
422 path_cache.erase(std::begin(path_cache), it);
423 }
424 }
425 }
426 return next_trackdir;
427 }
428
429 inline uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
430 {
431 /* handle special case - when current tile is the destination tile */
432 if (dst_tile == v->tile) {
433 /* distance is zero in this case */
434 return 0;
435 }
436
437 if (!this->SetOriginFromVehiclePos(v)) return UINT_MAX;
438
439 /* get available trackdirs on the destination tile */
440 Yapf().SetDestination(v);
441
442 /* if path not found - return distance = UINT_MAX */
443 uint dist = UINT_MAX;
444
445 /* find the best path */
446 if (!Yapf().FindPath(v)) return dist;
447
448 Node *node = Yapf().GetBestNode();
449 if (node != nullptr) {
450 /* path was found
451 * get the path cost estimate */
452 dist = node->GetCostEstimate();
453 }
454
455 return dist;
456 }
457
460 {
461 /* set origin (tile, trackdir) */
462 TileIndex src_tile = v->tile;
463 Trackdir src_td = v->GetVehicleTrackdir();
464 if (!HasTrackdir(GetTrackdirBitsForRoad(src_tile, Yapf().IsTram() ? RTT_TRAM : RTT_ROAD), src_td)) {
465 /* sometimes the roadveh is not on the road (it resides on non-existing track)
466 * how should we handle that situation? */
467 return false;
468 }
469 Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
470 return true;
471 }
472
473 static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
474 {
475 Tpf pf;
476 return pf.FindNearestDepot(v, tile, td, max_distance);
477 }
478
486 inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
487 {
488 /* Set origin. */
489 Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
490 Yapf().SetMaxCost(max_distance);
491
492 /* Find the best path and return if no depot is found. */
493 if (!Yapf().FindPath(v)) return FindDepotData();
494
495 /* Return the cost of the best path and its depot. */
496 Node *n = Yapf().GetBestNode();
497 return FindDepotData(n->segment_last_tile, n->cost);
498 }
499};
500
501template <class Tpf_, class Tnode_list, template <class Types> class Tdestination>
504
505 typedef Tpf_ Tpf;
507 typedef Tnode_list NodeList;
508 typedef RoadVehicle VehicleType;
512 typedef Tdestination<Types> PfDestination;
515};
516
517struct CYapfRoad1 : CYapfT<CYapfRoad_TypesT<CYapfRoad1 , CRoadNodeListTrackDir, CYapfDestinationTileRoadT>> {};
518struct CYapfRoad2 : CYapfT<CYapfRoad_TypesT<CYapfRoad2 , CRoadNodeListExitDir , CYapfDestinationTileRoadT>> {};
519
520struct CYapfRoadAnyDepot1 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot1, CRoadNodeListTrackDir, CYapfDestinationAnyDepotRoadT>> {};
521struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNodeListExitDir , CYapfDestinationAnyDepotRoadT>> {};
522
523
524Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
525{
527 ? CYapfRoad1::stChooseRoadTrack(v, tile, enterdir, path_found, path_cache) // Trackdir
528 : CYapfRoad2::stChooseRoadTrack(v, tile, enterdir, path_found, path_cache); // ExitDir, allow 90-deg
529
530 return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit(trackdirs);
531}
532
534{
535 TileIndex tile = v->tile;
536 Trackdir trackdir = v->GetVehicleTrackdir();
537
538 if (!HasTrackdir(GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype)), trackdir)) {
539 return FindDepotData();
540 }
541
543 ? CYapfRoadAnyDepot1::stFindNearestDepot(v, tile, trackdir, max_distance) // Trackdir
544 : CYapfRoadAnyDepot2::stFindNearestDepot(v, tile, trackdir, max_distance); // ExitDir
545}
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
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition math_func.hpp:23
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.
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.