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

OpenTTD Source 15.0-beta1

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>
19 class CYapfCostRoadT
20{
21public:
22 typedef typename Types::Tpf Tpf;
23 typedef typename Types::TrackFollower TrackFollower;
24 typedef typename Types::NodeList::Item Node;
25 typedef typename Node::Key Key;
26
27protected:
28 int max_cost;
29
30 CYapfCostRoadT() : max_cost(0) {};
31
33 Tpf &Yapf()
34 {
35 return *static_cast<Tpf *>(this);
36 }
37
38 int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir)
39 {
40 /* height of the center of the current tile */
41 int x1 = TileX(tile) * TILE_SIZE;
42 int y1 = TileY(tile) * TILE_SIZE;
43 int z1 = GetSlopePixelZ(x1 + TILE_SIZE / 2, y1 + TILE_SIZE / 2, true);
44
45 /* height of the center of the next tile */
46 int x2 = TileX(next_tile) * TILE_SIZE;
47 int y2 = TileY(next_tile) * TILE_SIZE;
48 int z2 = GetSlopePixelZ(x2 + TILE_SIZE / 2, y2 + TILE_SIZE / 2, true);
49
50 if (z2 - z1 > 1) {
51 /* Slope up */
52 return Yapf().PfGetSettings().road_slope_penalty;
53 }
54 return 0;
55 }
56
58 inline int OneTileCost(TileIndex tile, Trackdir trackdir)
59 {
60 int cost = 0;
61 /* set base cost */
62 if (IsDiagonalTrackdir(trackdir)) {
63 cost += YAPF_TILE_LENGTH;
64 switch (GetTileType(tile)) {
65 case MP_ROAD:
66 /* Increase the cost for level crossings */
67 if (IsLevelCrossing(tile)) {
68 cost += Yapf().PfGetSettings().road_crossing_penalty;
69 }
70 break;
71
72 case MP_STATION: {
73 if (IsRoadWaypoint(tile)) break;
74
75 const RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
76 if (IsDriveThroughStopTile(tile)) {
77 /* Increase the cost for drive-through road stops */
78 cost += Yapf().PfGetSettings().road_stop_penalty;
79 DiagDirection dir = TrackdirToExitdir(trackdir);
80 if (!RoadStop::IsDriveThroughRoadStopContinuation(tile, tile - TileOffsByDiagDir(dir))) {
81 /* When we're the first road stop in a 'queue' of them we increase
82 * cost based on the fill percentage of the whole queue. */
83 const RoadStop::Entry *entry = rs->GetEntry(dir);
84 cost += entry->GetOccupied() * Yapf().PfGetSettings().road_stop_occupied_penalty / entry->GetLength();
85 }
86 } else {
87 /* Increase cost for filled road stops */
88 cost += Yapf().PfGetSettings().road_stop_bay_occupied_penalty * (!rs->IsFreeBay(0) + !rs->IsFreeBay(1)) / 2;
89 }
90 break;
91 }
92
93 default:
94 break;
95 }
96 } else {
97 /* non-diagonal trackdir */
98 cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
99 }
100 return cost;
101 }
102
103public:
104 inline void SetMaxCost(int max_cost)
105 {
106 this->max_cost = max_cost;
107 }
108
114 inline bool PfCalcCost(Node &n, const TrackFollower *)
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 */
138 if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
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>
187 class CYapfDestinationAnyDepotRoadT
188{
189public:
190 typedef typename Types::Tpf Tpf;
191 typedef typename Types::TrackFollower TrackFollower;
192 typedef typename Types::NodeList::Item Node;
193 typedef typename Node::Key Key;
194
196 Tpf &Yapf()
197 {
198 return *static_cast<Tpf *>(this);
199 }
200
202 inline bool PfDetectDestination(Node &n)
203 {
204 return IsRoadDepotTile(n.segment_last_tile);
205 }
206
207 inline bool PfDetectDestinationTile(TileIndex tile, Trackdir)
208 {
209 return IsRoadDepotTile(tile);
210 }
211
216 inline bool PfCalcEstimate(Node &n)
217 {
218 n.estimate = n.cost;
219 return true;
220 }
221};
222
223
224template <class Types>
225 class CYapfDestinationTileRoadT
226{
227public:
228 typedef typename Types::Tpf Tpf;
229 typedef typename Types::TrackFollower TrackFollower;
230 typedef typename Types::NodeList::Item Node;
231 typedef typename Node::Key Key;
232
233protected:
234 TileIndex dest_tile;
235 TrackdirBits dest_trackdirs;
236 StationID dest_station;
237 StationType station_type;
238 bool non_artic;
239
240public:
241 void SetDestination(const RoadVehicle *v)
242 {
243 if (v->current_order.IsType(OT_GOTO_STATION)) {
244 this->dest_station = v->current_order.GetDestination();
245 this->station_type = v->IsBus() ? STATION_BUS : STATION_TRUCK;
246 this->dest_tile = CalcClosestStationTile(this->dest_station, v->tile, this->station_type);
247 this->non_artic = !v->HasArticulatedPart();
248 this->dest_trackdirs = INVALID_TRACKDIR_BIT;
249 } else if (v->current_order.IsType(OT_GOTO_WAYPOINT)) {
250 this->dest_station = v->current_order.GetDestination();
251 this->station_type = STATION_ROADWAYPOINT;
252 this->dest_tile = CalcClosestStationTile(this->dest_station, v->tile, this->station_type);
253 this->non_artic = !v->HasArticulatedPart();
254 this->dest_trackdirs = INVALID_TRACKDIR_BIT;
255 } else {
256 this->dest_station = INVALID_STATION;
257 this->dest_tile = v->dest_tile;
258 this->dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, GetRoadTramType(v->roadtype)));
259 }
260 }
261
262 const Station *GetDestinationStation() const
263 {
264 return this->dest_station != INVALID_STATION ? Station::GetIfValid(this->dest_station) : nullptr;
265 }
266
267protected:
269 Tpf &Yapf()
270 {
271 return *static_cast<Tpf *>(this);
272 }
273
274public:
276 inline bool PfDetectDestination(Node &n)
277 {
278 return this->PfDetectDestinationTile(n.segment_last_tile, n.segment_last_td);
279 }
280
281 inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
282 {
283 if (this->dest_station != INVALID_STATION) {
284 return IsTileType(tile, MP_STATION) &&
285 GetStationIndex(tile) == this->dest_station &&
286 (this->station_type == GetStationType(tile)) &&
287 (this->non_artic || IsDriveThroughStopTile(tile));
288 }
289
290 return tile == this->dest_tile && HasTrackdir(this->dest_trackdirs, trackdir);
291 }
292
297 inline bool PfCalcEstimate(Node &n)
298 {
299 static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
300 static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
301 if (this->PfDetectDestination(n)) {
302 n.estimate = n.cost;
303 return true;
304 }
305
306 TileIndex tile = n.segment_last_tile;
307 DiagDirection exitdir = TrackdirToExitdir(n.segment_last_td);
308 int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
309 int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
310 int x2 = 2 * TileX(this->dest_tile);
311 int y2 = 2 * TileY(this->dest_tile);
312 int dx = abs(x1 - x2);
313 int dy = abs(y1 - y2);
314 int dmin = std::min(dx, dy);
315 int dxy = abs(dx - dy);
316 int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
317 n.estimate = n.cost + d;
318 assert(n.estimate >= n.parent->estimate);
319 return true;
320 }
321};
322
323
324
325template <class Types>
326 class CYapfFollowRoadT
327{
328public:
329 typedef typename Types::Tpf Tpf;
330 typedef typename Types::TrackFollower TrackFollower;
331 typedef typename Types::NodeList::Item Node;
332 typedef typename Node::Key Key;
333
334protected:
336 inline Tpf &Yapf()
337 {
338 return *static_cast<Tpf *>(this);
339 }
340
341public:
342
348 inline void PfFollowNode(Node &old_node)
349 {
350 TrackFollower F(Yapf().GetVehicle());
351 if (F.Follow(old_node.segment_last_tile, old_node.segment_last_td)) {
352 Yapf().AddMultipleNodes(&old_node, F);
353 }
354 }
355
357 inline char TransportTypeChar() const
358 {
359 return 'r';
360 }
361
362 static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found, RoadVehPathCache &path_cache)
363 {
364 Tpf pf;
365 return pf.ChooseRoadTrack(v, tile, enterdir, path_found, path_cache);
366 }
367
368 inline Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found, RoadVehPathCache &path_cache)
369 {
370 /* Handle special case - when next tile is destination tile.
371 * However, when going to a station the (initial) destination
372 * tile might not be a station, but a junction, in which case
373 * this method forces the vehicle to jump in circles. */
374 if (tile == v->dest_tile && !v->current_order.IsType(OT_GOTO_STATION)) {
375 /* choose diagonal trackdir reachable from enterdir */
376 return DiagDirToDiagTrackdir(enterdir);
377 }
378 /* our source tile will be the next vehicle tile (should be the given one) */
379 TileIndex src_tile = tile;
380 /* get available trackdirs on the start tile */
381 TrackdirBits src_trackdirs = GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype));
382 /* select reachable trackdirs only */
383 src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
384
385 /* set origin and destination nodes */
386 Yapf().SetOrigin(src_tile, src_trackdirs);
387 Yapf().SetDestination(v);
388
389 /* find the best path */
390 path_found = Yapf().FindPath(v);
391
392 /* if path not found - return INVALID_TRACKDIR */
393 Trackdir next_trackdir = INVALID_TRACKDIR;
394 Node *pNode = Yapf().GetBestNode();
395 if (pNode != nullptr) {
396 uint steps = 0;
397 for (Node *n = pNode; n->parent != nullptr; n = n->parent) steps++;
398
399 /* path was found or at least suggested
400 * walk through the path back to its origin */
401 while (pNode->parent != nullptr) {
402 steps--;
403 if (pNode->GetIsChoice() && steps < YAPF_ROADVEH_PATH_CACHE_SEGMENTS) {
404 path_cache.emplace_back(pNode->GetTrackdir(), pNode->GetTile());
405 }
406 pNode = pNode->parent;
407 }
408 /* return trackdir from the best origin node (one of start nodes) */
409 Node &best_next_node = *pNode;
410 assert(best_next_node.GetTile() == tile);
411 next_trackdir = best_next_node.GetTrackdir();
412
413 /* Check if target is a station, and cached path leads to within YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT
414 * tiles of the dest tile */
415 const Station *st = Yapf().GetDestinationStation();
416 if (st) {
417 const RoadStop *stop = st->GetPrimaryRoadStop(v);
418 if (stop != nullptr && (IsDriveThroughStopTile(stop->xy) || stop->GetNextRoadStop(v) != nullptr)) {
419 /* Destination station has at least 2 usable road stops, or first is a drive-through stop,
420 * trim end of path cache within a number of tiles of road stop tile area */
421 TileArea non_cached_area = v->IsBus() ? st->bus_station : st->truck_station;
422 non_cached_area.Expand(YAPF_ROADVEH_PATH_CACHE_DESTINATION_LIMIT);
423
424 /* Find the first tile not contained by the non-cachable area, and remove from the cache. */
425 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); });
426 path_cache.erase(std::begin(path_cache), it);
427 }
428 }
429 }
430 return next_trackdir;
431 }
432
433 inline uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
434 {
435 /* handle special case - when current tile is the destination tile */
436 if (dst_tile == v->tile) {
437 /* distance is zero in this case */
438 return 0;
439 }
440
441 if (!this->SetOriginFromVehiclePos(v)) return UINT_MAX;
442
443 /* get available trackdirs on the destination tile */
444 Yapf().SetDestination(v);
445
446 /* if path not found - return distance = UINT_MAX */
447 uint dist = UINT_MAX;
448
449 /* find the best path */
450 if (!Yapf().FindPath(v)) return dist;
451
452 Node *pNode = Yapf().GetBestNode();
453 if (pNode != nullptr) {
454 /* path was found
455 * get the path cost estimate */
456 dist = pNode->GetCostEstimate();
457 }
458
459 return dist;
460 }
461
463 inline bool SetOriginFromVehiclePos(const RoadVehicle *v)
464 {
465 /* set origin (tile, trackdir) */
466 TileIndex src_tile = v->tile;
467 Trackdir src_td = v->GetVehicleTrackdir();
468 if (!HasTrackdir(GetTrackdirBitsForRoad(src_tile, Yapf().IsTram() ? RTT_TRAM : RTT_ROAD), src_td)) {
469 /* sometimes the roadveh is not on the road (it resides on non-existing track)
470 * how should we handle that situation? */
471 return false;
472 }
473 Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
474 return true;
475 }
476
477 static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
478 {
479 Tpf pf;
480 return pf.FindNearestDepot(v, tile, td, max_distance);
481 }
482
490 inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
491 {
492 /* Set origin. */
493 Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
494 Yapf().SetMaxCost(max_distance);
495
496 /* Find the best path and return if no depot is found. */
497 if (!Yapf().FindPath(v)) return FindDepotData();
498
499 /* Return the cost of the best path and its depot. */
500 Node *n = Yapf().GetBestNode();
501 return FindDepotData(n->segment_last_tile, n->cost);
502 }
503};
504
505template <class Tpf_, class Tnode_list, template <class Types> class Tdestination>
506 struct CYapfRoad_TypesT
507{
508 typedef CYapfRoad_TypesT<Tpf_, Tnode_list, Tdestination> Types;
509
510 typedef Tpf_ Tpf;
511 typedef CFollowTrackRoad TrackFollower;
512 typedef Tnode_list NodeList;
513 typedef RoadVehicle VehicleType;
514 typedef CYapfBaseT<Types> PfBase;
515 typedef CYapfFollowRoadT<Types> PfFollow;
516 typedef CYapfOriginTileT<Types> PfOrigin;
517 typedef Tdestination<Types> PfDestination;
518 typedef CYapfSegmentCostCacheNoneT<Types> PfCache;
519 typedef CYapfCostRoadT<Types> PfCost;
520};
521
522 struct CYapfRoad1 : CYapfT<CYapfRoad_TypesT<CYapfRoad1 , CRoadNodeListTrackDir, CYapfDestinationTileRoadT > > {};
523 struct CYapfRoad2 : CYapfT<CYapfRoad_TypesT<CYapfRoad2 , CRoadNodeListExitDir , CYapfDestinationTileRoadT > > {};
524
525 struct CYapfRoadAnyDepot1 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot1, CRoadNodeListTrackDir, CYapfDestinationAnyDepotRoadT> > {};
526 struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNodeListExitDir , CYapfDestinationAnyDepotRoadT> > {};
527
528
529 Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
530{
531 Trackdir td_ret = _settings_game.pf.yapf.disable_node_optimization
532 ? CYapfRoad1::stChooseRoadTrack(v, tile, enterdir, path_found, path_cache) // Trackdir
533 : CYapfRoad2::stChooseRoadTrack(v, tile, enterdir, path_found, path_cache); // ExitDir, allow 90-deg
534
535 return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit(trackdirs);
536}
537
538 FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance)
539{
540 TileIndex tile = v->tile;
541 Trackdir trackdir = v->GetVehicleTrackdir();
542
543 if (!HasTrackdir(GetTrackdirBitsForRoad(tile, GetRoadTramType(v->roadtype)), trackdir)) {
544 return FindDepotData();
545 }
546
547 return _settings_game.pf.yapf.disable_node_optimization
548 ? CYapfRoadAnyDepot1::stFindNearestDepot(v, tile, trackdir, max_distance) // Trackdir
549 : CYapfRoadAnyDepot2::stFindNearestDepot(v, tile, trackdir, max_distance); // ExitDir
550}
FindFirstBit
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
Definition bitmath_func.hpp:213
KillFirstBit
constexpr T KillFirstBit(T value)
Clear the first bit in an integer.
Definition bitmath_func.hpp:250
CYapfBaseT
CYapfBaseT - A-star type path finder base class.
Definition yapf_base.hpp:49
CYapfCostRoadT
Definition yapf_road.cpp:20
CYapfCostRoadT::TrackFollower
Types::TrackFollower TrackFollower
track follower helper
Definition yapf_road.cpp:23
CYapfCostRoadT::Node
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:24
CYapfCostRoadT::Key
Node::Key Key
key to hash tables
Definition yapf_road.cpp:25
CYapfCostRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:33
CYapfCostRoadT::OneTileCost
int OneTileCost(TileIndex tile, Trackdir trackdir)
return one tile cost
Definition yapf_road.cpp:58
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:114
CYapfCostRoadT::Tpf
Types::Tpf Tpf
pathfinder (derived from THIS class)
Definition yapf_road.cpp:22
CYapfDestinationAnyDepotRoadT
Definition yapf_road.cpp:188
CYapfDestinationAnyDepotRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:196
CYapfDestinationAnyDepotRoadT::Node
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:192
CYapfDestinationAnyDepotRoadT::PfCalcEstimate
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition yapf_road.cpp:216
CYapfDestinationAnyDepotRoadT::PfDetectDestination
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition yapf_road.cpp:202
CYapfDestinationAnyDepotRoadT::Key
Node::Key Key
key to hash tables
Definition yapf_road.cpp:193
CYapfDestinationAnyDepotRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition yapf_road.cpp:190
CYapfDestinationTileRoadT
Definition yapf_road.cpp:226
CYapfDestinationTileRoadT::PfCalcEstimate
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition yapf_road.cpp:297
CYapfDestinationTileRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition yapf_road.cpp:228
CYapfDestinationTileRoadT::Key
Node::Key Key
key to hash tables
Definition yapf_road.cpp:231
CYapfDestinationTileRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:269
CYapfDestinationTileRoadT::Node
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:230
CYapfDestinationTileRoadT::PfDetectDestination
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition yapf_road.cpp:276
CYapfFollowRoadT
Definition yapf_road.cpp:327
CYapfFollowRoadT::Node
Types::NodeList::Item Node
this will be our node type
Definition yapf_road.cpp:331
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:490
CYapfFollowRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition yapf_road.cpp:336
CYapfFollowRoadT::PfFollowNode
void PfFollowNode(Node &old_node)
Called by YAPF to move from the given node to the next tile.
Definition yapf_road.cpp:348
CYapfFollowRoadT::Key
Node::Key Key
key to hash tables
Definition yapf_road.cpp:332
CYapfFollowRoadT::TransportTypeChar
char TransportTypeChar() const
return debug report character to identify the transportation type
Definition yapf_road.cpp:357
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:463
CYapfFollowRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition yapf_road.cpp:329
CYapfOriginTileT
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
Definition yapf_common.hpp:20
CYapfSegmentCostCacheNoneT
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
Definition yapf_costcache.hpp:24
CYapfT
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
Definition yapf_common.hpp:121
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:73
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition landscape.cpp:554
GetSlopePixelZ
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Definition landscape.cpp:303
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:425
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:415
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:567
MAX_MAP_SIZE
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition map_type.h:40
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition math_func.hpp:23
GetTrackdirBitsForRoad
TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
Wrapper around GetTileTrackStatus() and TrackStatusToTrackdirBits(), as for single tram bits GetTileT...
Definition pathfinder_func.h:60
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
GetRoadDepotDirection
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
Definition road_map.h:565
IsRoadDepotTile
static debug_inline bool IsRoadDepotTile(Tile t)
Return whether a tile is a road depot tile.
Definition road_map.h:116
IsLevelCrossing
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:85
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:57
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:31
CFollowTrackT
Track follower helper template class (can serve pathfinders and vehicle controllers).
Definition follow_track.hpp:29
CYapfRoad1
Definition yapf_road.cpp:522
CYapfRoad2
Definition yapf_road.cpp:523
CYapfRoadAnyDepot1
Definition yapf_road.cpp:525
CYapfRoadAnyDepot2
Definition yapf_road.cpp:526
CYapfRoad_TypesT
Definition yapf_road.cpp:507
FindDepotData
Helper container to find a depot.
Definition pathfinder_type.h:38
GameSettings::pf
PathfinderSettings pf
settings for all pathfinders
Definition settings_type.h:599
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:201
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition order_base.h:103
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition order_base.h:70
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
PathfinderSettings::yapf
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Definition settings_type.h:476
RoadStop::Entry
Container for each entry point of a drive through road stop.
Definition roadstop_base.h:33
RoadStop::Entry::GetOccupied
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
Definition roadstop_base.h:57
RoadStop::Entry::GetLength
int GetLength() const
Get the length of this drive through stop.
Definition roadstop_base.h:48
RoadStop
A Stop for a Road Vehicle.
Definition roadstop_base.h:22
RoadStop::IsFreeBay
bool IsFreeBay(uint nr) const
Checks whether the given bay is free in this road stop.
Definition roadstop_base.h:94
RoadStop::GetNextRoadStop
RoadStop * GetNextRoadStop(const struct RoadVehicle *v) const
Get the next road stop accessible by this vehicle.
Definition roadstop.cpp:42
RoadStop::xy
TileIndex xy
Position on the map.
Definition roadstop_base.h:69
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:303
RoadStop::GetByTile
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition roadstop.cpp:264
RoadStop::GetEntry
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
Definition roadstop_base.h:123
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 SetDParam 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:1735
RoadVehicle::roadtype
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
Definition roadveh.h:108
SpecializedStation< Station, false >::GetIfValid
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
Definition base_station_base.h:263
Station
Station data structure.
Definition station_base.h:439
Station::bus_station
TileArea bus_station
Tile area the bus 'station' part covers.
Definition station_base.h:449
Station::truck_station
TileArea truck_station
Tile area the truck 'station' part covers.
Definition station_base.h:451
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:963
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition vehicle_base.h:356
Vehicle::tile
TileIndex tile
Current tile index.
Definition vehicle_base.h:264
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition vehicle_base.h:271
YAPFSettings::disable_node_optimization
bool disable_node_optimization
whether to use exit-dir instead of trackdir in node key
Definition settings_type.h:426
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
TILE_SIZE
static const 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:67
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:86
TrackdirBits
TrackdirBits
Allow incrementing of Trackdir variables.
Definition track_type.h:98
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition track_type.h:99
INVALID_TRACKDIR_BIT
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
Definition track_type.h:114
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition transport_type.h:28
yapf.hpp
Base includes/functions for YAPF.
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:538
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:529