OpenTTD Source: src/pathfinder/yapf/yapf_road.cpp Source File

OpenTTD Source 15.0-RC2

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
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>
19 class 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
32 Tpf &Yapf()
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);
79 if (!RoadStop::IsDriveThroughRoadStopContinuation(tile, tile - TileOffsByDiagDir(dir))) {
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 */
137 if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
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>
186 class CYapfDestinationAnyDepotRoadT {
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
194 Tpf &Yapf()
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>
223 class CYapfDestinationTileRoadT {
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:
266 Tpf &Yapf()
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>
310 class CYapfFollowRoadT {
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;
405 non_cached_area.Expand(YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT);
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
446 inline bool SetOriginFromVehiclePos(const RoadVehicle *v)
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_, template <class Types> class Tdestination>
489 struct CYapfRoad_TypesT {
490 typedef CYapfRoad_TypesT<Tpf_, Tdestination> Types;
491
492 typedef Tpf_ Tpf;
493 typedef CFollowTrackRoad TrackFollower;
494 typedef CRoadNodeList NodeList;
495 typedef RoadVehicle VehicleType;
496 typedef CYapfBaseT<Types> PfBase;
497 typedef CYapfFollowRoadT<Types> PfFollow;
498 typedef CYapfOriginTileT<Types> PfOrigin;
499 typedef Tdestination<Types> PfDestination;
500 typedef CYapfSegmentCostCacheNoneT<Types> PfCache;
501 typedef CYapfCostRoadT<Types> PfCost;
502};
503
504 struct CYapfRoad : CYapfT<CYapfRoad_TypesT<CYapfRoad, CYapfDestinationTileRoadT>> {};
505
506 struct CYapfRoadAnyDepot : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot, CYapfDestinationAnyDepotRoadT>> {};
507
508 Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
509{
510 Trackdir td_ret = CYapfRoad::stChooseRoadTrack(v, tile, enterdir, path_found, path_cache);
511
512 return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit(trackdirs);
513}
514
515 FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance)
516{
517 TileIndex tile = v->tile;
518 Trackdir trackdir = v->GetVehicleTrackdir();
519
520 if (!HasTrackdir(GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype)), trackdir)) {
521 return FindDepotData();
522 }
523
524 return CYapfRoadAnyDepot::stFindNearestDepot(v, tile, trackdir, max_distance);
525}
FindFirstBit
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
Definition bitmath_func.hpp:189
KillFirstBit
constexpr T KillFirstBit(T value)
Clear the first bit in an integer.
Definition bitmath_func.hpp:226
CYapfBaseT
CYapfBaseT - A-star type path finder base class.
Definition yapf_base.hpp:48
CYapfCostRoadT
Definition yapf_road.cpp:19
CYapfCostRoadT::TrackFollower
Types::TrackFollower TrackFollower
track follower helper
Definition yapf_road.cpp:22
CYapfCostRoadT::Node
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:23
CYapfCostRoadT::Key
Node::Key Key
key to hash tables
Definition yapf_road.cpp:24
CYapfCostRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:32
CYapfCostRoadT::OneTileCost
int OneTileCost(TileIndex tile, Trackdir trackdir)
return one tile cost
Definition yapf_road.cpp:57
CYapfCostRoadT::PfCalcCost
bool PfCalcCost(Node &n, const TrackFollower *)
Called by YAPF to calculate the cost from the origin to the given node.
Definition yapf_road.cpp:113
CYapfCostRoadT::Tpf
Types::Tpf Tpf
pathfinder (derived from THIS class)
Definition yapf_road.cpp:21
CYapfDestinationAnyDepotRoadT
Definition yapf_road.cpp:186
CYapfDestinationAnyDepotRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:194
CYapfDestinationAnyDepotRoadT::Node
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:190
CYapfDestinationAnyDepotRoadT::PfCalcEstimate
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition yapf_road.cpp:214
CYapfDestinationAnyDepotRoadT::PfDetectDestination
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition yapf_road.cpp:200
CYapfDestinationAnyDepotRoadT::Key
Node::Key Key
key to hash tables
Definition yapf_road.cpp:191
CYapfDestinationAnyDepotRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition yapf_road.cpp:188
CYapfDestinationTileRoadT
Definition yapf_road.cpp:223
CYapfDestinationTileRoadT::PfCalcEstimate
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition yapf_road.cpp:294
CYapfDestinationTileRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition yapf_road.cpp:225
CYapfDestinationTileRoadT::Key
Node::Key Key
key to hash tables
Definition yapf_road.cpp:228
CYapfDestinationTileRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:266
CYapfDestinationTileRoadT::Node
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:227
CYapfDestinationTileRoadT::PfDetectDestination
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition yapf_road.cpp:273
CYapfFollowRoadT
Definition yapf_road.cpp:310
CYapfFollowRoadT::Node
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:314
CYapfFollowRoadT::FindNearestDepot
FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
Find the best depot for a road vehicle.
Definition yapf_road.cpp:473
CYapfFollowRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:319
CYapfFollowRoadT::PfFollowNode
void PfFollowNode(Node &old_node)
Called by YAPF to move from the given node to the next tile.
Definition yapf_road.cpp:331
CYapfFollowRoadT::Key
Node::Key Key
key to hash tables
Definition yapf_road.cpp:315
CYapfFollowRoadT::TransportTypeChar
char TransportTypeChar() const
return debug report character to identify the transportation type
Definition yapf_road.cpp:340
CYapfFollowRoadT::SetOriginFromVehiclePos
bool SetOriginFromVehiclePos(const RoadVehicle *v)
Return true if the valid origin (tile/trackdir) was set from the current vehicle position.
Definition yapf_road.cpp:446
CYapfFollowRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition yapf_road.cpp:312
CYapfOriginTileT
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
Definition yapf_common.hpp:19
CYapfSegmentCostCacheNoneT
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
Definition yapf_costcache.hpp:23
CYapfT
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
Definition yapf_common.hpp:94
NodeList
Hash table based node list multi-container class.
Definition nodelist.hpp:21
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition direction_func.h:118
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition landscape.cpp:559
GetSlopePixelZ
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Definition landscape.cpp:306
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:437
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:427
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:582
MAX_MAP_SIZE
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition map_type.h:40
GetTrackdirBitsForRoad
TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
Wrapper around GetTileTrackStatus() and TrackStatusToTrackdirBits(), as for single tram bits GetTileT...
Definition pathfinder_func.h:59
CalcClosestStationTile
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...
Definition pathfinder_func.h:25
YAPF_TILE_CORNER_LENGTH
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
Definition pathfinder_type.h:19
YAPF_ROADVEH_PATH_CACHE_SEGMENTS
static const int YAPF_ROADVEH_PATH_CACHE_SEGMENTS
Maximum segments of road vehicle path cache.
Definition pathfinder_type.h:30
YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT
static const int YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT
Distance from destination road stops to not cache any further.
Definition pathfinder_type.h:33
YAPF_TILE_LENGTH
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
Definition pathfinder_type.h:16
IsRoadDepotTile
static bool IsRoadDepotTile(Tile t)
Return whether a tile is a road depot tile.
Definition road_map.h:100
GetRoadDepotDirection
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
Definition road_map.h:550
IsLevelCrossing
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
RTT_ROAD
@ RTT_ROAD
Road road type.
Definition road_type.h:38
RTT_TRAM
@ RTT_TRAM
Tram road type.
Definition road_type.h:39
GetStationType
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition station_map.h:44
IsRoadWaypoint
bool IsRoadWaypoint(Tile t)
Is the station at t a road waypoint?
Definition station_map.h:202
IsDriveThroughStopTile
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station or waypoint?
Definition station_map.h:276
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
GetRoadStopType
RoadStopType GetRoadStopType(Tile t)
Get the road stop type of this tile.
Definition station_map.h:56
StationType
StationType
Station types.
Definition station_type.h:29
CFollowTrackT
Track follower helper template class (can serve pathfinders and vehicle controllers).
Definition follow_track.hpp:28
CYapfRoadAnyDepot
Definition yapf_road.cpp:506
CYapfRoad_TypesT
Definition yapf_road.cpp:489
CYapfRoad
Definition yapf_road.cpp:504
FindDepotData
Helper container to find a depot.
Definition pathfinder_type.h:38
LinkGraph::BaseNode
Node of the link graph.
Definition linkgraph.h:90
Order::GetMaxSpeed
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:207
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition order_base.h:99
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition order_base.h:66
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
OrthogonalTileArea::Contains
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
Definition tilearea.cpp:104
OrthogonalTileArea::Expand
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Definition tilearea.cpp:123
PoolID< uint16_t, struct StationIDTag, 64000, 0xFFFF >
RoadStop::Entry
Container for each entry point of a drive through road stop.
Definition roadstop_base.h:31
RoadStop::Entry::GetOccupied
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
Definition roadstop_base.h:52
RoadStop::Entry::GetLength
int GetLength() const
Get the length of this drive through stop.
Definition roadstop_base.h:43
RoadStop
A Stop for a Road Vehicle.
Definition roadstop_base.h:21
RoadStop::IsFreeBay
bool IsFreeBay(uint nr) const
Checks whether the given bay is free in this road stop.
Definition roadstop_base.h:92
RoadStop::GetNextRoadStop
RoadStop * GetNextRoadStop(const struct RoadVehicle *v) const
Get the next road stop accessible by this vehicle.
Definition roadstop.cpp:40
RoadStop::xy
TileIndex xy
Position on the map.
Definition roadstop_base.h:70
RoadStop::GetEntry
const Entry & GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
Definition roadstop_base.h:124
RoadStop::IsDriveThroughRoadStopContinuation
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
RoadStop::GetByTile
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition roadstop.cpp:253
RoadVehicle
Buses, trucks and trams belong to this class.
Definition roadveh.h:98
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition roadveh_cmd.cpp:82
RoadVehicle::GetDisplayMaxSpeed
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
RoadVehicle::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
Definition roadveh_cmd.cpp:1747
RoadVehicle::roadtype
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
Definition roadveh.h:108
SpecializedStation< Station, false >::GetIfValid
static Station * GetIfValid(auto index)
Returns station if the index is a valid index for this station type.
Definition base_station_base.h:257
Station
Station data structure.
Definition station_base.h:500
Station::bus_station
TileArea bus_station
Tile area the bus 'station' part covers.
Definition station_base.h:510
Station::truck_station
TileArea truck_station
Tile area the truck 'station' part covers.
Definition station_base.h:512
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition vehicle_base.h:931
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition vehicle_base.h:311
Vehicle::tile
TileIndex tile
Current tile index.
Definition vehicle_base.h:225
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition vehicle_base.h:232
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
GetTileType
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
TILE_SIZE
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition tile_type.h:50
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
TrackStatusToTrackdirBits
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition track_func.h:352
DiagdirReachesTrackdirs
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
IsDiagonalTrackdir
bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition track_func.h:631
HasTrackdir
bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
Definition track_func.h:340
DiagDirToDiagTrackdir
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition track_func.h:537
TrackdirToTrackdirBits
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition track_func.h:111
TrackdirToExitdir
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
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:66
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:85
TrackdirBits
TrackdirBits
Allow incrementing of Trackdir variables.
Definition track_type.h:97
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition track_type.h:98
INVALID_TRACKDIR_BIT
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
Definition track_type.h:113
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition transport_type.h:26
yapf.hpp
Base includes/functions for YAPF.
OctileDistanceCost
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.
Definition yapf_common.hpp:104
yapf_node_road.hpp
Node tailored for road pathfinding.
YapfRoadVehicleFindNearestDepot
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance)
Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.
Definition yapf_road.cpp:515
YapfRoadVehicleChooseTrack
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.
Definition yapf_road.cpp:508