OpenTTD Source 20260421-master-gc2fbc6fdeb
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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>
19class CYapfCostRoadT {
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
62 inline int OneTileCost(TileIndex tile, Trackdir trackdir)
63 {
64 int cost = 0;
65 /* set base cost */
66 if (IsDiagonalTrackdir(trackdir)) {
67 cost += YAPF_TILE_LENGTH;
68 switch (GetTileType(tile)) {
69 case TileType::Road:
70 /* Increase the cost for level crossings */
71 if (IsLevelCrossing(tile)) {
72 cost += Yapf().PfGetSettings().road_crossing_penalty;
73 }
74 break;
75
76 case TileType::Station: {
77 if (IsRoadWaypoint(tile)) break;
78
79 const RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
80 if (IsDriveThroughStopTile(tile)) {
81 /* Increase the cost for drive-through road stops */
82 cost += Yapf().PfGetSettings().road_stop_penalty;
83 DiagDirection dir = TrackdirToExitdir(trackdir);
85 /* When we're the first road stop in a 'queue' of them we increase
86 * cost based on the fill percentage of the whole queue. */
87 const RoadStop::Entry &entry = rs->GetEntry(dir);
88 cost += entry.GetOccupied() * Yapf().PfGetSettings().road_stop_occupied_penalty / entry.GetLength();
89 }
90 } else {
91 /* Increase cost for filled road stops */
92 cost += Yapf().PfGetSettings().road_stop_bay_occupied_penalty * (!rs->IsFreeBay(0) + !rs->IsFreeBay(1)) / 2;
93 }
94 break;
95 }
96
97 default:
98 break;
99 }
100 } else {
101 /* non-diagonal trackdir */
102 cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
103 }
104 return cost;
105 }
106
107public:
108 inline void SetMaxCost(int max_cost)
109 {
110 this->max_cost = max_cost;
111 }
112
114 inline bool PfCalcCost(Node &n, [[maybe_unused]] const TrackFollower *follower)
115 {
116 int segment_cost = 0;
117 uint tiles = 0;
118 /* start at n.key.tile / n.key.td and walk to the end of segment */
119 TileIndex tile = n.key.tile;
120 Trackdir trackdir = n.key.td;
121 int parent_cost = (n.parent != nullptr) ? n.parent->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 (this->max_cost > 0 && (parent_cost + segment_cost) > this->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.new_td_bits) != TRACKDIR_BIT_NONE) break;
149
150 Trackdir new_td = (Trackdir)FindFirstBit(F.new_td_bits);
151
152 /* stop if RV is on simple loop with no junctions */
153 if (F.new_tile == n.key.tile && new_td == n.key.td) return false;
154
155 /* if we skipped some tunnel tiles, add their cost */
156 segment_cost += F.tiles_skipped * YAPF_TILE_LENGTH;
157 tiles += F.tiles_skipped + 1;
158
159 /* add hilly terrain penalty */
160 segment_cost += Yapf().SlopeCost(tile, F.new_tile, trackdir);
161
162 /* add min/max speed penalties */
163 int min_speed = 0;
164 int max_veh_speed = std::min<int>(v->GetDisplayMaxSpeed(), v->current_order.GetMaxSpeed() * 2);
165 int max_speed = F.GetSpeedLimit(&min_speed);
166 if (max_speed < max_veh_speed) segment_cost += YAPF_TILE_LENGTH * (max_veh_speed - max_speed) * (4 + F.tiles_skipped) / max_veh_speed;
167 if (min_speed > max_veh_speed) segment_cost += YAPF_TILE_LENGTH * (min_speed - max_veh_speed);
168
169 /* move to the next tile */
170 tile = F.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.segment_last_tile = tile;
177 n.segment_last_td = trackdir;
178
179 /* save also tile cost */
180 n.cost = parent_cost + segment_cost;
181 return true;
182 }
183};
184
185
186template <class Types>
188public:
189 typedef typename Types::Tpf Tpf;
190 typedef typename Types::TrackFollower TrackFollower;
191 typedef typename Types::NodeList::Item Node;
192 typedef typename Node::Key Key;
193
196 {
197 return *static_cast<Tpf *>(this);
198 }
199
201 inline bool PfDetectDestination(Node &n)
202 {
203 return IsRoadDepotTile(n.segment_last_tile);
204 }
205
207 inline bool PfDetectDestinationTile(TileIndex tile, [[maybe_unused]] Trackdir td)
208 {
209 return IsRoadDepotTile(tile);
210 }
211
213 inline bool PfCalcEstimate(Node &n)
214 {
215 n.estimate = n.cost;
216 return true;
217 }
218};
219
220
221template <class Types>
223public:
224 typedef typename Types::Tpf Tpf;
225 typedef typename Types::TrackFollower TrackFollower;
226 typedef typename Types::NodeList::Item Node;
227 typedef typename Node::Key Key;
228
229protected:
230 TileIndex dest_tile;
231 TrackdirBits dest_trackdirs;
232 StationID dest_station;
233 StationType station_type;
234 bool non_artic;
235
236public:
237 void SetDestination(const RoadVehicle *v)
238 {
239 if (v->current_order.IsType(OT_GOTO_STATION)) {
240 this->dest_station = v->current_order.GetDestination().ToStationID();
241 this->station_type = v->IsBus() ? StationType::Bus : StationType::Truck;
242 this->dest_tile = CalcClosestStationTile(this->dest_station, v->tile, this->station_type);
243 this->non_artic = !v->HasArticulatedPart();
244 this->dest_trackdirs = INVALID_TRACKDIR_BIT;
245 } else if (v->current_order.IsType(OT_GOTO_WAYPOINT)) {
246 this->dest_station = v->current_order.GetDestination().ToStationID();
247 this->station_type = StationType::RoadWaypoint;
248 this->dest_tile = CalcClosestStationTile(this->dest_station, v->tile, this->station_type);
249 this->non_artic = !v->HasArticulatedPart();
250 this->dest_trackdirs = INVALID_TRACKDIR_BIT;
251 } else {
252 this->dest_station = StationID::Invalid();
253 this->dest_tile = v->dest_tile == INVALID_TILE ? TileIndex{} : v->dest_tile;
254 this->dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(this->dest_tile, TRANSPORT_ROAD, GetRoadTramType(v->roadtype)));
255 }
256 }
257
258 const Station *GetDestinationStation() const
259 {
260 return this->dest_station != StationID::Invalid() ? Station::GetIfValid(this->dest_station) : nullptr;
261 }
262
263protected:
266 {
267 return *static_cast<Tpf *>(this);
268 }
269
270public:
272 inline bool PfDetectDestination(Node &n)
273 {
274 return this->PfDetectDestinationTile(n.segment_last_tile, n.segment_last_td);
275 }
276
279 {
280 if (this->dest_station != StationID::Invalid()) {
281 return IsTileType(tile, TileType::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, td);
288 }
289
291 inline bool PfCalcEstimate(Node &n)
292 {
293 if (this->PfDetectDestination(n)) {
294 n.estimate = n.cost;
295 return true;
296 }
297
298 n.estimate = n.cost + OctileDistanceCost(n.segment_last_tile, n.segment_last_td, this->dest_tile);
299 assert(n.estimate >= n.parent->estimate);
300 return true;
301 }
302};
303
304
305
306template <class Types>
308public:
309 typedef typename Types::Tpf Tpf;
310 typedef typename Types::TrackFollower TrackFollower;
311 typedef typename Types::NodeList::Item Node;
312 typedef typename Node::Key Key;
313
314protected:
316 inline Tpf &Yapf()
317 {
318 return *static_cast<Tpf *>(this);
319 }
320
321public:
322
324 inline void PfFollowNode(Node &old_node)
325 {
326 TrackFollower F(Yapf().GetVehicle());
327 if (F.Follow(old_node.segment_last_tile, old_node.segment_last_td)) {
328 Yapf().AddMultipleNodes(&old_node, F);
329 }
330 }
331
333 inline char TransportTypeChar() const
334 {
335 return 'r';
336 }
337
338 static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found, RoadVehPathCache &path_cache)
339 {
340 Tpf pf;
341 return pf.ChooseRoadTrack(v, tile, enterdir, path_found, path_cache);
342 }
343
344 inline Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found, RoadVehPathCache &path_cache)
345 {
346 /* Handle special case - when next tile is destination tile.
347 * However, when going to a station the (initial) destination
348 * tile might not be a station, but a junction, in which case
349 * this method forces the vehicle to jump in circles. */
350 if (tile == v->dest_tile && !v->current_order.IsType(OT_GOTO_STATION)) {
351 /* choose diagonal trackdir reachable from enterdir */
352 return DiagDirToDiagTrackdir(enterdir);
353 }
354 /* our source tile will be the next vehicle tile (should be the given one) */
355 TileIndex src_tile = tile;
356 /* get available trackdirs on the start tile */
357 TrackdirBits src_trackdirs = GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype));
358 /* select reachable trackdirs only */
359 src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
360
361 /* set origin and destination nodes */
362 Yapf().SetOrigin(src_tile, src_trackdirs);
363 Yapf().SetDestination(v);
364
365 /* find the best path */
366 path_found = Yapf().FindPath(v);
367
368 /* if path not found - return INVALID_TRACKDIR */
369 Trackdir next_trackdir = INVALID_TRACKDIR;
370 Node *node = Yapf().GetBestNode();
371 if (node != nullptr) {
372 uint steps = 0;
373 for (Node *n = node; n->parent != nullptr; n = n->parent) steps++;
374
375 /* path was found or at least suggested
376 * walk through the path back to its origin */
377 while (node->parent != nullptr) {
378 steps--;
379 if (node->GetIsChoice() && steps < YAPF_ROADVEH_PATH_CACHE_SEGMENTS) {
380 path_cache.emplace_back(node->GetTrackdir(), node->GetTile());
381 }
382 node = node->parent;
383 }
384 /* return trackdir from the best origin node (one of start nodes) */
385 Node &best_next_node = *node;
386 assert(best_next_node.GetTile() == tile);
387 next_trackdir = best_next_node.GetTrackdir();
388
389 /* Check if target is a station, and cached path leads to within YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT
390 * tiles of the dest tile */
391 const Station *st = Yapf().GetDestinationStation();
392 if (st) {
393 const RoadStop *stop = st->GetPrimaryRoadStop(v);
394 if (stop != nullptr && (IsDriveThroughStopTile(stop->xy) || stop->GetNextRoadStop(v) != nullptr)) {
395 /* Destination station has at least 2 usable road stops, or first is a drive-through stop,
396 * trim end of path cache within a number of tiles of road stop tile area */
397 TileArea non_cached_area = v->IsBus() ? st->bus_station : st->truck_station;
399
400 /* Find the first tile not contained by the non-cacheable area, and remove from the cache. */
401 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); });
402 path_cache.erase(std::begin(path_cache), it);
403 }
404 }
405 }
406 return next_trackdir;
407 }
408
409 inline uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
410 {
411 /* handle special case - when current tile is the destination tile */
412 if (dst_tile == v->tile) {
413 /* distance is zero in this case */
414 return 0;
415 }
416
417 if (!this->SetOriginFromVehiclePos(v)) return UINT_MAX;
418
419 /* get available trackdirs on the destination tile */
420 Yapf().SetDestination(v);
421
422 /* if path not found - return distance = UINT_MAX */
423 uint dist = UINT_MAX;
424
425 /* find the best path */
426 if (!Yapf().FindPath(v)) return dist;
427
428 Node *node = Yapf().GetBestNode();
429 if (node != nullptr) {
430 /* path was found
431 * get the path cost estimate */
432 dist = node->GetCostEstimate();
433 }
434
435 return dist;
436 }
437
444 {
445 /* set origin (tile, trackdir) */
446 TileIndex src_tile = v->tile;
447 Trackdir src_td = v->GetVehicleTrackdir();
448 if (!HasTrackdir(GetTrackdirBitsForRoad(src_tile, Yapf().IsTram() ? RoadTramType::Tram : RoadTramType::Road), src_td)) {
449 /* sometimes the roadveh is not on the road (it resides on non-existing track)
450 * how should we handle that situation? */
451 return false;
452 }
453 Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
454 return true;
455 }
456
457 static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
458 {
459 Tpf pf;
460 return pf.FindNearestDepot(v, tile, td, max_distance);
461 }
462
471 inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
472 {
473 /* Set origin. */
474 Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
475 Yapf().SetMaxCost(max_distance);
476
477 /* Find the best path and return if no depot is found. */
478 if (!Yapf().FindPath(v)) return FindDepotData();
479
480 /* Return the cost of the best path and its depot. */
481 Node *n = Yapf().GetBestNode();
482 return FindDepotData(n->segment_last_tile, n->cost);
483 }
484};
485
486template <class Tpf_, template <class Types> class Tdestination>
489
490 typedef Tpf_ Tpf;
491 typedef CFollowTrackRoad TrackFollower;
492 typedef CRoadNodeList NodeList;
493 typedef RoadVehicle VehicleType;
494 typedef CYapfBaseT<Types> PfBase;
495 typedef CYapfFollowRoadT<Types> PfFollow;
496 typedef CYapfOriginTileT<Types> PfOrigin;
497 typedef Tdestination<Types> PfDestination;
498 typedef CYapfSegmentCostCacheNoneT<Types> PfCache;
499 typedef CYapfCostRoadT<Types> PfCost;
500};
501
502struct CYapfRoad : CYapfT<CYapfRoad_TypesT<CYapfRoad, CYapfDestinationTileRoadT>> {};
503
504struct CYapfRoadAnyDepot : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot, CYapfDestinationAnyDepotRoadT>> {};
505
506Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
507{
508 Trackdir td_ret = CYapfRoad::stChooseRoadTrack(v, tile, enterdir, path_found, path_cache);
509
510 return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit(trackdirs);
511}
512
514{
515 TileIndex tile = v->tile;
516 Trackdir trackdir = v->GetVehicleTrackdir();
517
518 if (!HasTrackdir(GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype)), trackdir)) {
519 return FindDepotData();
520 }
521
522 return CYapfRoadAnyDepot::stFindNearestDepot(v, tile, trackdir, max_distance);
523}
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:48
bool PfCalcCost(Node &n, const TrackFollower *follower)
Called by YAPF to calculate the cost from the origin to the given node.
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()
Access the inherited path finder.
Definition yapf_road.cpp:32
int OneTileCost(TileIndex tile, Trackdir trackdir)
Return one tile cost.
Definition yapf_road.cpp:62
Types::Tpf Tpf
pathfinder (derived from THIS class)
Definition yapf_road.cpp:21
bool PfDetectDestinationTile(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
Tpf & Yapf()
Access the 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()
Access the inherited path finder.
Types::NodeList::Item Node
this will be our node type
bool PfDetectDestinationTile(TileIndex tile, Trackdir td)
Called by YAPF to detect if node ends in the desired destination.
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()
Access the 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...
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DiagDirection
Enumeration for diagonal directions.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, RoadTramType 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 uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:574
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.
static bool IsRoadDepotTile(Tile t)
Return whether a tile is a road depot tile.
Definition road_map.h:100
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
Definition road_map.h:576
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
@ Tram
Tram type.
Definition road_type.h:39
@ Road
Road type.
Definition road_type.h:38
Base class for roadstops.
A number of safeguards to prevent using unsafe methods.
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.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ RoadWaypoint
Waypoint for trucks and busses.
Definition of base types and functions in a cross-platform compatible way.
Helper container to find a depot.
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:307
DestinationID GetDestination() const
Gets the destination of this order.
Definition order_base.h:100
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition order_base.h:67
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
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:40
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:292
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition roadstop.cpp:253
Buses, trucks and trams belong to this class.
Definition roadveh.h:105
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:131
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
Definition roadveh.h:115
static Station * GetIfValid(auto index)
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.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
@ Station
A tile of a station or airport.
Definition tile_type.h:54
@ Road
A tile with road and/or tram tracks.
Definition tile_type.h:51
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition track_func.h:354
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
Definition track_func.h:560
bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition track_func.h:636
bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
Definition track_func.h:342
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition track_func.h:542
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:441
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.
@ Station
station encountered (could be a target next time)
Definition yapf_type.hpp:26
@ RoadVehicle
Default zoom level for the road vehicle view.
Definition zoom_type.h:41