(svn r27985) -Codechange: Convert VA2 switches into ones with non-overlapping ranges...
[openttd.git] / src / pbs.h
bloba02d4d06e12e13c291305d6680213521099636a7
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 pbs.h PBS support routines */
12 #ifndef PBS_H
13 #define PBS_H
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 void UnreserveRailTrack(TileIndex tile, Track t);
27 /** This struct contains information about the end of a reserved path. */
28 struct PBSTileInfo {
29 TileIndex tile; ///< Tile the path ends, INVALID_TILE if no valid path was found.
30 Trackdir trackdir; ///< The reserved trackdir on the tile.
31 bool okay; ///< True if tile is a safe waiting position, false otherwise.
33 /**
34 * Create an empty PBSTileInfo.
36 PBSTileInfo() : tile(INVALID_TILE), trackdir(INVALID_TRACKDIR), okay(false) {}
38 /**
39 * Create a PBSTileInfo with given tile, track direction and safe waiting position information.
40 * @param _t The tile where the path ends.
41 * @param _td The reserved track dir on the tile.
42 * @param _okay Whether the tile is a safe waiting point or not.
44 PBSTileInfo(TileIndex _t, Trackdir _td, bool _okay) : tile(_t), trackdir(_td), okay(_okay) {}
47 PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res = NULL);
48 bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg = false);
49 bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg = false);
51 Train *GetTrainForReservation(TileIndex tile, Track track);
53 /**
54 * Check whether some of tracks is reserved on a tile.
56 * @param tile the tile
57 * @param tracks the tracks to test
58 * @return true if at least on of tracks is reserved
60 static inline bool HasReservedTracks(TileIndex tile, TrackBits tracks)
62 return (GetReservedTrackbits(tile) & tracks) != TRACK_BIT_NONE;
65 #endif /* PBS_H */