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/>.
10 /** @file pbs.h PBS support routines */
15 #include "tile_type.h"
16 #include "direction_type.h"
17 #include "track_type.h"
18 #include "vehicle_type.h"
20 TrackBits
GetReservedTrackbits(TileIndex t
);
22 void SetRailStationPlatformReservation(TileIndex start
, DiagDirection dir
, bool b
);
24 bool TryReserveRailTrack(TileIndex tile
, Track t
, bool trigger_stations
= true);
25 bool TryReserveRailTrackdir(TileIndex tile
, Trackdir td
, bool trigger_stations
= true);
26 void UnreserveRailTrack(TileIndex tile
, Track t
);
27 void UnreserveRailTrackdir(TileIndex tile
, Trackdir td
);
29 /** This struct contains information about the end of a reserved path. */
31 TileIndex tile
; ///< Tile the path ends, INVALID_TILE if no valid path was found.
32 Trackdir trackdir
; ///< The reserved trackdir on the tile.
33 bool okay
; ///< True if tile is a safe waiting position, false otherwise.
36 * Create an empty PBSTileInfo.
38 PBSTileInfo() : tile(INVALID_TILE
), trackdir(INVALID_TRACKDIR
), okay(false) {}
41 * Create a PBSTileInfo with given tile, track direction and safe waiting position information.
42 * @param _t The tile where the path ends.
43 * @param _td The reserved track dir on the tile.
44 * @param _okay Whether the tile is a safe waiting point or not.
46 PBSTileInfo(TileIndex _t
, Trackdir _td
, bool _okay
) : tile(_t
), trackdir(_td
), okay(_okay
) {}
49 PBSTileInfo
FollowTrainReservation(const Train
*v
, Vehicle
**train_on_res
= NULL
);
50 bool IsSafeWaitingPosition(const Train
*v
, TileIndex tile
, Trackdir trackdir
, bool include_line_end
, bool forbid_90deg
= false);
51 bool IsWaitingPositionFree(const Train
*v
, TileIndex tile
, Trackdir trackdir
, bool forbid_90deg
= false);
53 Train
*GetTrainForReservation(TileIndex tile
, Track track
);
56 * Check whether some of tracks is reserved on a tile.
58 * @param tile the tile
59 * @param tracks the tracks to test
60 * @return true if at least on of tracks is reserved
62 static inline bool HasReservedTracks(TileIndex tile
, TrackBits tracks
)
64 return (GetReservedTrackbits(tile
) & tracks
) != TRACK_BIT_NONE
;