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 
8 /** @file yapf.h Entry point for OpenTTD to YAPF. */
9 
10 #ifndef YAPF_H
11 #define YAPF_H
12 
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"
19 
20 /**
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
28  */
29 Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, ShipPathCache &path_cache);
30 
31 /**
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  * @param trackdir [out] the best of all possible reversed trackdirs
35  * @return true if reversing is better
36  */
37 bool YapfShipCheckReverse(const Ship *v, Trackdir *trackdir);
38 
39 /**
40  * Finds the best path for given road vehicle using YAPF.
41  * @param v         the RV that needs to find a path
42  * @param tile      the tile to find the path from (should be next tile the RV is about to enter)
43  * @param enterdir  diagonal direction which the RV will enter this new tile from
44  * @param trackdirs available trackdirs on the new tile (to choose from)
45  * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
46  * @return          the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
47  */
48 Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache);
49 
50 /**
51  * Finds the best path for given train using YAPF.
52  * @param v        the train that needs to find a path
53  * @param tile     the tile to find the path from (should be next tile the train is about to enter)
54  * @param enterdir diagonal direction which the RV will enter this new tile from
55  * @param tracks   available trackdirs on the new tile (to choose from)
56  * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
57  * @param reserve_track indicates whether YAPF should try to reserve the found path
58  * @param target   [out] the target tile of the reservation, free is set to true if path was reserved
59  * @return         the best track for next turn
60  */
61 Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, struct PBSTileInfo *target);
62 
63 /**
64  * Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.
65  * @param v            vehicle that needs to go to some depot
66  * @param max_penalty  max distance (in pathfinder penalty) from the current vehicle position
67  *                     (used also as optimization - the pathfinder can stop path finding if max_penalty
68  *                     was reached and no depot was seen)
69  * @return             the data about the depot
70  */
71 FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty);
72 
73 /**
74  * Used when user sends train to the nearest depot or if train needs servicing using YAPF.
75  * @param v            train that needs to go to some depot
76  * @param max_distance max distance (int pathfinder penalty) from the current train position
77  *                     (used also as optimization - the pathfinder can stop path finding if max_penalty
78  *                     was reached and no depot was seen)
79  * @return             the data about the depot
80  */
81 FindDepotData YapfTrainFindNearestDepot(const Train *v, int max_distance);
82 
83 /**
84  * Returns true if it is better to reverse the train before leaving station using YAPF.
85  * @param v the train leaving the station
86  * @return true if reversing is better
87  */
88 bool YapfTrainCheckReverse(const Train *v);
89 
90 /**
91  * Try to extend the reserved path of a train to the nearest safe tile using YAPF.
92  *
93  * @param v    The train that needs to find a safe tile.
94  * @param tile Last tile of the current reserved path.
95  * @param td   Last trackdir of the current reserved path.
96  * @param override_railtype Should all physically compatible railtypes be searched, even if the vehicle can't run on them on its own?
97  * @return True if the path could be extended to a safe tile.
98  */
99 bool YapfTrainFindNearestSafeTile(const Train *v, TileIndex tile, Trackdir td, bool override_railtype);
100 
101 #endif /* YAPF_H */
102