Let HandleWindowDragging return a boolean status
[openttd/fttd.git] / src / pathfinder / yapf / yapf.h
blob58911f5448aa2940a2c9cf56ba21cd390e5a289e
1 /* $Id$ */
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 */
10 /** @file yapf.h Entry point for OpenTTD to YAPF. */
12 #ifndef YAPF_H
13 #define YAPF_H
15 #include "../../direction_type.h"
16 #include "../../track_type.h"
17 #include "../../vehicle_type.h"
18 #include "../types.h"
20 /** Length (penalty) of one tile with YAPF */
21 static const int YAPF_TILE_LENGTH = 100;
23 /** Length (penalty) of a corner with YAPF */
24 static const int YAPF_TILE_CORNER_LENGTH = 71;
26 /**
27 * This penalty is the equivalent of "infinite", which means that paths that
28 * get this penalty will be chosen, but only if there is no other route
29 * without it. Be careful with not applying this penalty to often, or the
30 * total path cost might overflow..
32 static const int YAPF_INFINITE_PENALTY = 1000 * YAPF_TILE_LENGTH;
34 /**
35 * Finds the best path for given ship using YAPF.
36 * @param v the ship that needs to find a path
37 * @param tile the tile to find the path from (should be next tile the ship is about to enter)
38 * @param enterdir diagonal direction which the ship will enter this new tile from
39 * @param trackdirs available trackdirs on the new tile (to choose from)
40 * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
41 * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
43 Trackdir YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found);
45 /**
46 * Returns true if it is better to reverse the ship before leaving depot using YAPF.
47 * @param v the ship leaving the depot
48 * @return true if reversing is better
50 bool YapfShipCheckReverse(const Ship *v);
52 /**
53 * Find the nearest depot to a ship
54 * @param v the ship looking for a depot
55 * @param max_distance maximum allowed distance, or 0 for any distance
56 * @return the tile of the nearest depot
58 TileIndex YapfShipFindNearestDepot (const Ship *v, uint max_distance);
60 /**
61 * Finds the best path for given road vehicle using YAPF.
62 * @param v the RV that needs to find a path
63 * @param tile the tile to find the path from (should be next tile the RV is about to enter)
64 * @param enterdir diagonal direction which the RV will enter this new tile from
65 * @param trackdirs available trackdirs on the new tile (to choose from)
66 * @param path_found [out] Whether a path has been found (true) or has been guessed (false)
67 * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
69 Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found);
71 /**
72 * Finds the best path for given train using YAPF.
73 * @param v the train that needs to find a path
74 * @param origin the end of the current reservation
75 * @param reserve_track indicates whether YAPF should try to reserve the found path
76 * @param target [out] the target tile of the reservation, free is set to true if path was reserved
77 * @return the best trackdir for next turn
79 Trackdir YapfTrainChooseTrack(const Train *v, const RailPathPos &origin, bool reserve_track, struct PFResult *target);
81 /**
82 * Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.
83 * @param v vehicle that needs to go to some depot
84 * @param max_penalty max distance (in pathfinder penalty) from the current vehicle position
85 * (used also as optimization - the pathfinder can stop path finding if max_penalty
86 * was reached and no depot was seen)
87 * @return depot tile found, or INVALID_TILE if no depot was found
89 TileIndex YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, uint max_penalty);
91 /**
92 * Used when user sends train to the nearest depot or if train needs servicing using YAPF.
93 * @param v train that needs to go to some depot
94 * @param origin the end of the current reservation
95 * @param max_distance max distance (int pathfinder penalty) from the current train position
96 * (used also as optimization - the pathfinder can stop path finding if max_penalty
97 * was reached and no depot was seen)
98 * @param res pointer to store the data about the depot
99 * @return whether a depot was found
101 bool YapfTrainFindNearestDepot (const Train *v, const RailPathPos &origin, uint max_distance, FindDepotData *res);
104 * Returns true if it is better to reverse the train before leaving station using YAPF.
105 * @param v the train leaving the station
106 * @return true if reversing is better
108 bool YapfTrainCheckReverse(const Train *v);
111 * Try to extend the reserved path of a train to the nearest safe tile using YAPF.
113 * @param v The train that needs to find a safe tile.
114 * @param pos Last position of the current reserved path.
115 * @param override_railtype Should all physically compatible railtypes be searched, even if the vehicle can't run on them on its own?
116 * @return True if the path could be extended to a safe tile.
118 bool YapfTrainFindNearestSafeTile(const Train *v, const RailPathPos &pos, bool override_railtype);
121 * Use this function to notify YAPF that track layout (or signal configuration) has change.
123 void YapfNotifyTrackLayoutChange (void);
125 #endif /* YAPF_H */