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/>.
8 /** @file yapf.h Entry point for OpenTTD to YAPF. */
13 #include "../../direction_type.h"
14 #include "../../track_type.h"
15 #include "../../vehicle_type.h"
16 #include "../../ship.h"
17 #include "../../roadveh.h"
18 #include "../pathfinder_type.h"
21 * Finds the best path for given ship using YAPF.
22 * @param v the ship that needs to find a path
23 * @param tile the tile to find the path from (should be next tile the ship is about to enter)
24 * @param enterdir diagonal direction which the ship will enter this new tile from
25 * @param tracks available tracks on the new tile (to choose from)
26 * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
27 * @return the best trackdir for next turn or INVALID_TRACK if the path could not be found
29 Track
YapfShipChooseTrack(const Ship
*v
, TileIndex tile
, DiagDirection enterdir
, TrackBits tracks
, bool &path_found
, ShipPathCache
&path_cache
);
32 * Returns true if it is better to reverse the ship before leaving depot using YAPF.
33 * @param v the ship leaving the depot
34 * @return true if reversing is better
36 bool YapfShipCheckReverse(const Ship
*v
);
39 * Finds the best path for given road vehicle using YAPF.
40 * @param v the RV that needs to find a path
41 * @param tile the tile to find the path from (should be next tile the RV is about to enter)
42 * @param enterdir diagonal direction which the RV will enter this new tile from
43 * @param trackdirs available trackdirs on the new tile (to choose from)
44 * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
45 * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
47 Trackdir
YapfRoadVehicleChooseTrack(const RoadVehicle
*v
, TileIndex tile
, DiagDirection enterdir
, TrackdirBits trackdirs
, bool &path_found
, RoadVehPathCache
&path_cache
);
50 * Finds the best path for given train using YAPF.
51 * @param v the train that needs to find a path
52 * @param tile the tile to find the path from (should be next tile the train is about to enter)
53 * @param enterdir diagonal direction which the RV will enter this new tile from
54 * @param tracks available trackdirs on the new tile (to choose from)
55 * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
56 * @param reserve_track indicates whether YAPF should try to reserve the found path
57 * @param target [out] the target tile of the reservation, free is set to true if path was reserved
58 * @return the best track for next turn
60 Track
YapfTrainChooseTrack(const Train
*v
, TileIndex tile
, DiagDirection enterdir
, TrackBits tracks
, bool &path_found
, bool reserve_track
, struct PBSTileInfo
*target
);
63 * Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.
64 * @param v vehicle that needs to go to some depot
65 * @param max_penalty max distance (in pathfinder penalty) from the current vehicle position
66 * (used also as optimization - the pathfinder can stop path finding if max_penalty
67 * was reached and no depot was seen)
68 * @return the data about the depot
70 FindDepotData
YapfRoadVehicleFindNearestDepot(const RoadVehicle
*v
, int max_penalty
);
73 * Used when user sends train to the nearest depot or if train needs servicing using YAPF.
74 * @param v train that needs to go to some depot
75 * @param max_distance max distance (int pathfinder penalty) from the current train position
76 * (used also as optimization - the pathfinder can stop path finding if max_penalty
77 * was reached and no depot was seen)
78 * @return the data about the depot
80 FindDepotData
YapfTrainFindNearestDepot(const Train
*v
, int max_distance
);
83 * Returns true if it is better to reverse the train before leaving station using YAPF.
84 * @param v the train leaving the station
85 * @return true if reversing is better
87 bool YapfTrainCheckReverse(const Train
*v
);
90 * Try to extend the reserved path of a train to the nearest safe tile using YAPF.
92 * @param v The train that needs to find a safe tile.
93 * @param tile Last tile of the current reserved path.
94 * @param td Last trackdir of the current reserved path.
95 * @param override_railtype Should all physically compatible railtypes be searched, even if the vehicle can't run on them on its own?
96 * @return True if the path could be extended to a safe tile.
98 bool YapfTrainFindNearestSafeTile(const Train
*v
, TileIndex tile
, Trackdir td
, bool override_railtype
);