OpenTTD

yapf_road.cpp
Go to the documentation of this file.
1 /* $Id: yapf_road.cpp 27586 2016-05-29 14:14:52Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #include "../../stdafx.h"
13 #include "yapf.hpp"
14 #include "yapf_node_road.hpp"
15 #include "../../roadstop_base.h"
16
17 #include "../../safeguards.h"
18
19
20 template <class Types>
21 class CYapfCostRoadT
22 {
23 public:
24 typedef typename Types::Tpf Tpf;
25 typedef typename Types::TrackFollower TrackFollower;
26 typedef typename Types::NodeList::Titem Node;
27 typedef typename Node::Key Key;
28
29 protected:
31 Tpf& Yapf()
32 {
33 return *static_cast<Tpf *>(this);
34 }
35
36 int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
37 {
38 /* height of the center of the current tile */
39 int x1 = TileX(tile) * TILE_SIZE;
40 int y1 = TileY(tile) * TILE_SIZE;
41 int z1 = GetSlopePixelZ(x1 + TILE_SIZE / 2, y1 + TILE_SIZE / 2);
42
43 /* height of the center of the next tile */
44 int x2 = TileX(next_tile) * TILE_SIZE;
45 int y2 = TileY(next_tile) * TILE_SIZE;
46 int z2 = GetSlopePixelZ(x2 + TILE_SIZE / 2, y2 + TILE_SIZE / 2);
47
48 if (z2 - z1 > 1) {
49 /* Slope up */
50 return Yapf().PfGetSettings().road_slope_penalty;
51 }
52 return 0;
53 }
54
56 inline int OneTileCost(TileIndex tile, Trackdir trackdir)
57 {
58 int cost = 0;
59 /* set base cost */
60 if (IsDiagonalTrackdir(trackdir)) {
61 cost += YAPF_TILE_LENGTH;
62 switch (GetTileType(tile)) {
63 case MP_ROAD:
64 /* Increase the cost for level crossings */
65 if (IsLevelCrossing(tile)) {
66 cost += Yapf().PfGetSettings().road_crossing_penalty;
67 }
68 break;
69
70 case MP_STATION: {
71 const RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
72 if (IsDriveThroughStopTile(tile)) {
73 /* Increase the cost for drive-through road stops */
74 cost += Yapf().PfGetSettings().road_stop_penalty;
75 DiagDirection dir = TrackdirToExitdir(trackdir);
76 if (!RoadStop::IsDriveThroughRoadStopContinuation(tile, tile - TileOffsByDiagDir(dir))) {
77 /* When we're the first road stop in a 'queue' of them we increase
78 * cost based on the fill percentage of the whole queue. */
79 const RoadStop::Entry *entry = rs->GetEntry(dir);
80 cost += entry->GetOccupied() * Yapf().PfGetSettings().road_stop_occupied_penalty / entry->GetLength();
81 }
82 } else {
83 /* Increase cost for filled road stops */
84 cost += Yapf().PfGetSettings().road_stop_bay_occupied_penalty * (!rs->IsFreeBay(0) + !rs->IsFreeBay(1)) / 2;
85 }
86 break;
87 }
88
89 default:
90 break;
91 }
92 } else {
93 /* non-diagonal trackdir */
94 cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
95 }
96 return cost;
97 }
98
99 public:
105 inline bool PfCalcCost(Node &n, const TrackFollower *tf)
106 {
107 int segment_cost = 0;
108 uint tiles = 0;
109 /* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
110 TileIndex tile = n.m_key.m_tile;
111 Trackdir trackdir = n.m_key.m_td;
112 for (;;) {
113 /* base tile cost depending on distance between edges */
114 segment_cost += Yapf().OneTileCost(tile, trackdir);
115
116 const RoadVehicle *v = Yapf().GetVehicle();
117 /* we have reached the vehicle's destination - segment should end here to avoid target skipping */
118 if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
119
120 /* stop if we have just entered the depot */
121 if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
122 /* next time we will reverse and leave the depot */
123 break;
124 }
125
126 /* if there are no reachable trackdirs on new tile, we have end of road */
127 TrackFollower F(Yapf().GetVehicle());
128 if (!F.Follow(tile, trackdir)) break;
129
130 /* if there are more trackdirs available & reachable, we are at the end of segment */
131 if (KillFirstBit(F.m_new_td_bits) != TRACKDIR_BIT_NONE) break;
132
133 Trackdir new_td = (Trackdir)FindFirstBit2x64(F.m_new_td_bits);
134
135 /* stop if RV is on simple loop with no junctions */
136 if (F.m_new_tile == n.m_key.m_tile && new_td == n.m_key.m_td) return false;
137
138 /* if we skipped some tunnel tiles, add their cost */
139 segment_cost += F.m_tiles_skipped * YAPF_TILE_LENGTH;
140 tiles += F.m_tiles_skipped + 1;
141
142 /* add hilly terrain penalty */
143 segment_cost += Yapf().SlopeCost(tile, F.m_new_tile, trackdir);
144
145 /* add min/max speed penalties */
146 int min_speed = 0;
147 int max_veh_speed = v->GetDisplayMaxSpeed();
148 int max_speed = F.GetSpeedLimit(&min_speed);
149 if (max_speed < max_veh_speed) segment_cost += 1 * (max_veh_speed - max_speed);
150 if (min_speed > max_veh_speed) segment_cost += 10 * (min_speed - max_veh_speed);
151
152 /* move to the next tile */
153 tile = F.m_new_tile;
154 trackdir = new_td;
155 if (tiles > MAX_MAP_SIZE) break;
156 }
157
158 /* save end of segment back to the node */
159 n.m_segment_last_tile = tile;
160 n.m_segment_last_td = trackdir;
161
162 /* save also tile cost */
163 int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0;
164 n.m_cost = parent_cost + segment_cost;
165 return true;
166 }
167 };
168
169
170 template <class Types>
171 class CYapfDestinationAnyDepotRoadT
172 {
173 public:
174 typedef typename Types::Tpf Tpf;
175 typedef typename Types::TrackFollower TrackFollower;
176 typedef typename Types::NodeList::Titem Node;
177 typedef typename Node::Key Key;
178
180 Tpf& Yapf()
181 {
182 return *static_cast<Tpf *>(this);
183 }
184
186 inline bool PfDetectDestination(Node &n)
187 {
188 bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
189 return bDest;
190 }
191
192 inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
193 {
194 return IsRoadDepotTile(tile);
195 }
196
201 inline bool PfCalcEstimate(Node &n)
202 {
203 n.m_estimate = n.m_cost;
204 return true;
205 }
206 };
207
208
209 template <class Types>
210 class CYapfDestinationTileRoadT
211 {
212 public:
213 typedef typename Types::Tpf Tpf;
214 typedef typename Types::TrackFollower TrackFollower;
215 typedef typename Types::NodeList::Titem Node;
216 typedef typename Node::Key Key;
217
218 protected:
219 TileIndex m_destTile;
220 TrackdirBits m_destTrackdirs;
221 StationID m_dest_station;
222 bool m_bus;
223 bool m_non_artic;
224
225 public:
226 void SetDestination(const RoadVehicle *v)
227 {
228 if (v->current_order.IsType(OT_GOTO_STATION)) {
229 m_dest_station = v->current_order.GetDestination();
230 m_bus = v->IsBus();
231 m_destTile = CalcClosestStationTile(m_dest_station, v->tile, m_bus ? STATION_BUS : STATION_TRUCK);
232 m_non_artic = !v->HasArticulatedPart();
233 m_destTrackdirs = INVALID_TRACKDIR_BIT;
234 } else {
235 m_dest_station = INVALID_STATION;
236 m_destTile = v->dest_tile;
237 m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, v->compatible_roadtypes));
238 }
239 }
240
241 protected:
243 Tpf& Yapf()
244 {
245 return *static_cast<Tpf *>(this);
246 }
247
248 public:
250 inline bool PfDetectDestination(Node &n)
251 {
252 return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
253 }
254
255 inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
256 {
257 if (m_dest_station != INVALID_STATION) {
258 return IsTileType(tile, MP_STATION) &&
259 GetStationIndex(tile) == m_dest_station &&
260 (m_bus ? IsBusStop(tile) : IsTruckStop(tile)) &&
261 (m_non_artic || IsDriveThroughStopTile(tile));
262 }
263
264 return tile == m_destTile && ((m_destTrackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE);
265 }
266
271 inline bool PfCalcEstimate(Node &n)
272 {
273 static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
274 static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
275 if (PfDetectDestination(n)) {
276 n.m_estimate = n.m_cost;
277 return true;
278 }
279
280 TileIndex tile = n.m_segment_last_tile;
281 DiagDirection exitdir = TrackdirToExitdir(n.m_segment_last_td);
282 int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
283 int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
284 int x2 = 2 * TileX(m_destTile);
285 int y2 = 2 * TileY(m_destTile);
286 int dx = abs(x1 - x2);
287 int dy = abs(y1 - y2);
288 int dmin = min(dx, dy);
289 int dxy = abs(dx - dy);
290 int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
291 n.m_estimate = n.m_cost + d;
292 assert(n.m_estimate >= n.m_parent->m_estimate);
293 return true;
294 }
295 };
296
297
298
299 template <class Types>
300 class CYapfFollowRoadT
301 {
302 public:
303 typedef typename Types::Tpf Tpf;
304 typedef typename Types::TrackFollower TrackFollower;
305 typedef typename Types::NodeList::Titem Node;
306 typedef typename Node::Key Key;
307
308 protected:
310 inline Tpf& Yapf()
311 {
312 return *static_cast<Tpf *>(this);
313 }
314
315 public:
316
322 inline void PfFollowNode(Node &old_node)
323 {
324 TrackFollower F(Yapf().GetVehicle());
325 if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) {
326 Yapf().AddMultipleNodes(&old_node, F);
327 }
328 }
329
331 inline char TransportTypeChar() const
332 {
333 return 'r';
334 }
335
336 static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
337 {
338 Tpf pf;
339 return pf.ChooseRoadTrack(v, tile, enterdir, path_found);
340 }
341
342 inline Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
343 {
344 /* Handle special case - when next tile is destination tile.
345 * However, when going to a station the (initial) destination
346 * tile might not be a station, but a junction, in which case
347 * this method forces the vehicle to jump in circles. */
348 if (tile == v->dest_tile && !v->current_order.IsType(OT_GOTO_STATION)) {
349 /* choose diagonal trackdir reachable from enterdir */
350 return DiagDirToDiagTrackdir(enterdir);
351 }
352 /* our source tile will be the next vehicle tile (should be the given one) */
353 TileIndex src_tile = tile;
354 /* get available trackdirs on the start tile */
355 TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes));
356 /* select reachable trackdirs only */
357 src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
358
359 /* set origin and destination nodes */
360 Yapf().SetOrigin(src_tile, src_trackdirs);
361 Yapf().SetDestination(v);
362
363 /* find the best path */
364 path_found = Yapf().FindPath(v);
365
366 /* if path not found - return INVALID_TRACKDIR */
367 Trackdir next_trackdir = INVALID_TRACKDIR;
368 Node *pNode = Yapf().GetBestNode();
369 if (pNode != NULL) {
370 /* path was found or at least suggested
371 * walk through the path back to its origin */
372 while (pNode->m_parent != NULL) {
373 pNode = pNode->m_parent;
374 }
375 /* return trackdir from the best origin node (one of start nodes) */
376 Node &best_next_node = *pNode;
377 assert(best_next_node.GetTile() == tile);
378 next_trackdir = best_next_node.GetTrackdir();
379 }
380 return next_trackdir;
381 }
382
383 static uint stDistanceToTile(const RoadVehicle *v, TileIndex tile)
384 {
385 Tpf pf;
386 return pf.DistanceToTile(v, tile);
387 }
388
389 inline uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
390 {
391 /* handle special case - when current tile is the destination tile */
392 if (dst_tile == v->tile) {
393 /* distance is zero in this case */
394 return 0;
395 }
396
397 if (!SetOriginFromVehiclePos(v)) return UINT_MAX;
398
399 /* get available trackdirs on the destination tile */
400 Yapf().SetDestination(v);
401
402 /* if path not found - return distance = UINT_MAX */
403 uint dist = UINT_MAX;
404
405 /* find the best path */
406 if (!Yapf().FindPath(v)) return dist;
407
408 Node *pNode = Yapf().GetBestNode();
409 if (pNode != NULL) {
410 /* path was found
411 * get the path cost estimate */
412 dist = pNode->GetCostEstimate();
413 }
414
415 return dist;
416 }
417
419 inline bool SetOriginFromVehiclePos(const RoadVehicle *v)
420 {
421 /* set origin (tile, trackdir) */
422 TileIndex src_tile = v->tile;
423 Trackdir src_td = v->GetVehicleTrackdir();
424 if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
425 /* sometimes the roadveh is not on the road (it resides on non-existing track)
426 * how should we handle that situation? */
427 return false;
428 }
429 Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
430 return true;
431 }
432
433 static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
434 {
435 Tpf pf;
436 return pf.FindNearestDepot(v, tile, td, max_distance);
437 }
438
450 inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
451 {
452 /* Set origin. */
453 Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
454
455 /* Find the best path and return if no depot is found. */
456 if (!Yapf().FindPath(v)) return FindDepotData();
457
458 /* Return the cost of the best path and its depot. */
459 Node *n = Yapf().GetBestNode();
460 return FindDepotData(n->m_segment_last_tile, n->m_cost);
461 }
462 };
463
464 template <class Tpf_, class Tnode_list, template <class Types> class Tdestination>
465 struct CYapfRoad_TypesT
466 {
467 typedef CYapfRoad_TypesT<Tpf_, Tnode_list, Tdestination> Types;
468
469 typedef Tpf_ Tpf;
470 typedef CFollowTrackRoad TrackFollower;
471 typedef Tnode_list NodeList;
472 typedef RoadVehicle VehicleType;
473 typedef CYapfBaseT<Types> PfBase;
474 typedef CYapfFollowRoadT<Types> PfFollow;
475 typedef CYapfOriginTileT<Types> PfOrigin;
476 typedef Tdestination<Types> PfDestination;
477 typedef CYapfSegmentCostCacheNoneT<Types> PfCache;
478 typedef CYapfCostRoadT<Types> PfCost;
479 };
480
481 struct CYapfRoad1 : CYapfT<CYapfRoad_TypesT<CYapfRoad1 , CRoadNodeListTrackDir, CYapfDestinationTileRoadT > > {};
482 struct CYapfRoad2 : CYapfT<CYapfRoad_TypesT<CYapfRoad2 , CRoadNodeListExitDir , CYapfDestinationTileRoadT > > {};
483
484 struct CYapfRoadAnyDepot1 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot1, CRoadNodeListTrackDir, CYapfDestinationAnyDepotRoadT> > {};
485 struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNodeListExitDir , CYapfDestinationAnyDepotRoadT> > {};
486
487
488 Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found)
489 {
490 /* default is YAPF type 2 */
491 typedef Trackdir (*PfnChooseRoadTrack)(const RoadVehicle*, TileIndex, DiagDirection, bool &path_found);
492 PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg
493
494 /* check if non-default YAPF type should be used */
495 if (_settings_game.pf.yapf.disable_node_optimization) {
496 pfnChooseRoadTrack = &CYapfRoad1::stChooseRoadTrack; // Trackdir, allow 90-deg
497 }
498
499 Trackdir td_ret = pfnChooseRoadTrack(v, tile, enterdir, path_found);
500 return (td_ret != INVALID_TRACKDIR) ? td_ret : (Trackdir)FindFirstBit2x64(trackdirs);
501 }
502
503 FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_distance)
504 {
505 TileIndex tile = v->tile;
506 Trackdir trackdir = v->GetVehicleTrackdir();
507 if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
508 return FindDepotData();
509 }
510
511 /* default is YAPF type 2 */
512 typedef FindDepotData (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int);
513 PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
514
515 /* check if non-default YAPF type should be used */
516 if (_settings_game.pf.yapf.disable_node_optimization) {
517 pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
518 }
519
520 return pfnFindNearestDepot(v, tile, trackdir, max_distance);
521 }
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:89
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
CYapfCostRoadT
Definition: yapf_road.cpp:21
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:419
CYapfOriginTileT
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
Definition: yapf_common.hpp:17
CYapfDestinationTileRoadT::Key
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:216
CYapfDestinationAnyDepotRoadT::Key
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:177
CYapfDestinationTileRoadT::PfCalcEstimate
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition: yapf_road.cpp:271
GetRoadStopType
static RoadStopType GetRoadStopType(TileIndex t)
Get the road stop type of this tile.
Definition: station_map.h:57
RoadStop::Entry::GetLength
int GetLength() const
Get the length of this drive through stop.
Definition: roadstop_base.h:49
CYapfRoad1
Definition: yapf_road.cpp:481
CYapfCostRoadT::OneTileCost
int OneTileCost(TileIndex tile, Trackdir trackdir)
return one tile cost
Definition: yapf_road.cpp:56
INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
Definition: track_type.h:122
MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:45
RoadVehicle::GetDisplayMaxSpeed
int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: roadveh.h:113
RoadStop::Entry::GetOccupied
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
Definition: roadstop_base.h:58
CYapfFollowRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition: yapf_road.cpp:310
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:237
CYapfSegmentCostCacheNoneT
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
Definition: yapf_costcache.hpp:23
CYapfCostRoadT::PfCalcCost
bool PfCalcCost(Node &n, const TrackFollower *tf)
Called by YAPF to calculate the cost from the origin to the given node.
Definition: yapf_road.cpp:105
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
GameSettings::pf
PathfinderSettings pf
settings for all pathfinders
Definition: settings_type.h:550
CYapfFollowRoadT::Node
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:305
CYapfDestinationAnyDepotRoadT::Node
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:176
CYapfDestinationAnyDepotRoadT
Definition: yapf_road.cpp:171
GetRoadDepotDirection
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
Definition: road_map.h:534
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:450
DiagdirReachesTrackdirs
static TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction...
Definition: track_func.h:543
IsLevelCrossing
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:68
CYapfRoadAnyDepot1
Definition: yapf_road.cpp:484
CYapfFollowRoadT::PfFollowNode
void PfFollowNode(Node &old_node)
Called by YAPF to move from the given node to the next tile.
Definition: yapf_road.cpp:322
IsDriveThroughStopTile
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Definition: station_map.h:234
TrackdirToExitdir
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:427
CYapfFollowRoadT::Key
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:306
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
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:503
CYapfDestinationTileRoadT
Definition: yapf_road.cpp:210
CYapfRoad2
Definition: yapf_road.cpp:482
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:88
CYapfFollowRoadT::TransportTypeChar
char TransportTypeChar() const
return debug report character to identify the transportation type
Definition: yapf_road.cpp:331
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:343
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
CYapfBaseT
CYapfBaseT - A-star type path finder base class.
Definition: yapf_base.hpp:51
YAPFSettings::disable_node_optimization
bool disable_node_optimization
whether to use exit-dir instead of trackdir in node key
Definition: settings_type.h:375
PathfinderSettings::yapf
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Definition: settings_type.h:433
CYapfFollowRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_road.cpp:303
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
IsTruckStop
static bool IsTruckStop(TileIndex t)
Is the station at t a truck stop?
Definition: station_map.h:181
TrackdirToTrackdirBits
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition: track_func.h:121
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:63
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:120
RoadVehicle::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
Definition: roadveh_cmd.cpp:1669
CYapfCostRoadT::Tpf
Types::Tpf Tpf
pathfinder (derived from THIS class)
Definition: yapf_road.cpp:24
CYapfRoadAnyDepot2
Definition: yapf_road.cpp:485
YAPF_TILE_LENGTH
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
Definition: pathfinder_type.h:30
IsRoadDepotTile
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
Definition: road_map.h:99
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:74
CYapfT
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
Definition: yapf_common.hpp:186
CYapfDestinationAnyDepotRoadT::PfDetectDestination
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition: yapf_road.cpp:186
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:900
CYapfRoad_TypesT
Definition: yapf_road.cpp:465
DiagDirToDiagTrackdir
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:525
YapfRoadVehicleChooseTrack
Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found)
Finds the best path for given road vehicle using YAPF.
Definition: yapf_road.cpp:488
RoadStop::IsFreeBay
bool IsFreeBay(uint nr) const
Checks whether the given bay is free in this road stop.
Definition: roadstop_base.h:95
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:80
min
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
CYapfDestinationAnyDepotRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_road.cpp:174
CFollowTrackT
Track follower helper template class (can serve pathfinders and vehicle controllers).
Definition: follow_track.hpp:30
CalcClosestStationTile
static 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:26
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:509
RoadStop::Entry
Container for each entry point of a drive through road stop.
Definition: roadstop_base.h:34
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:29
CYapfDestinationTileRoadT::Tpf
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Definition: yapf_road.cpp:213
KillFirstBit
static T KillFirstBit(T value)
Clear the first bit in an integer.
Definition: bitmath_func.hpp:241
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:80
yapf_node_road.hpp
Node tailored for road pathfinding.
CYapfDestinationTileRoadT::Node
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:215
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:96
CYapfDestinationTileRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition: yapf_road.cpp:243
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
FindDepotData
Helper container to find a depot.
Definition: pathfinder_type.h:46
CYapfFollowRoadT
Definition: yapf_road.cpp:300
yapf.hpp
Base includes/functions for YAPF.
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
CYapfDestinationTileRoadT::PfDetectDestination
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
Definition: yapf_road.cpp:250
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:83
IsDiagonalTrackdir
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:619
MP_STATION
A tile of a station.
Definition: tile_type.h:48
FindFirstBit2x64
static uint8 FindFirstBit2x64(const int value)
Finds the position of the first non-zero bit in an integer.
Definition: bitmath_func.hpp:218
TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:30
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
TrackdirBits
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:106
CYapfCostRoadT::Node
Types::NodeList::Titem Node
this will be our node type
Definition: yapf_road.cpp:26
RoadStop
A Stop for a Road Vehicle.
Definition: roadstop_base.h:24
RoadStop::IsDriveThroughRoadStopContinuation
static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next)
Checks whether the &#39;next&#39; tile is still part of the road same drive through stop &#39;rs&#39; in the same dir...
Definition: roadstop.cpp:307
CYapfDestinationAnyDepotRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition: yapf_road.cpp:180
MAX_MAP_SIZE
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition: map_type.h:67
TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:107
CYapfCostRoadT::Key
Node::Key Key
key to hash tables
Definition: yapf_road.cpp:27
INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:93
CYapfCostRoadT::Yapf
Tpf & Yapf()
to access inherited path finder
Definition: yapf_road.cpp:31
YAPF_TILE_CORNER_LENGTH
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
Definition: pathfinder_type.h:33
CYapfCostRoadT::TrackFollower
Types::TrackFollower TrackFollower
track follower helper
Definition: yapf_road.cpp:25
IsBusStop
static bool IsBusStop(TileIndex t)
Is the station at t a bus stop?
Definition: station_map.h:192
TrackStatusToTrackdirBits
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:340
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:318
RoadStop::GetByTile
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition: roadstop.cpp:268
CYapfDestinationAnyDepotRoadT::PfCalcEstimate
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Definition: yapf_road.cpp:201