OpenTTD Source: src/pbs.h Source File

OpenTTD Source 13.1

pbs.h
Go to the documentation of this file.
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
10 #ifndef PBS_H
11 #define PBS_H
12
13 #include "tile_type.h"
14 #include "direction_type.h"
15 #include "track_type.h"
16 #include "vehicle_type.h"
17
18 TrackBits GetReservedTrackbits(TileIndex t);
19
20 void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b);
21
22 bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations = true);
23 void UnreserveRailTrack(TileIndex tile, Track t);
24
26 struct PBSTileInfo {
27 TileIndex tile;
28 Trackdir trackdir;
29 bool okay;
30
34 PBSTileInfo() : tile(INVALID_TILE), trackdir(INVALID_TRACKDIR), okay(false) {}
35
42 PBSTileInfo(TileIndex _t, Trackdir _td, bool _okay) : tile(_t), trackdir(_td), okay(_okay) {}
43 };
44
45 PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res = nullptr);
46 bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg = false);
47 bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg = false);
48
49 Train *GetTrainForReservation(TileIndex tile, Track track);
50
58 static inline bool HasReservedTracks(TileIndex tile, TrackBits tracks)
59 {
60 return (GetReservedTrackbits(tile) & tracks) != TRACK_BIT_NONE;
61 }
62
63 #endif /* PBS_H */
PBSTileInfo::okay
bool okay
True if tile is a safe waiting position, false otherwise.
Definition: pbs.h:29
HasReservedTracks
static bool HasReservedTracks(TileIndex tile, TrackBits tracks)
Check whether some of tracks is reserved on a tile.
Definition: pbs.h:58
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:39
direction_type.h
GetTrainForReservation
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
Definition: pbs.cpp:330
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
PBSTileInfo::PBSTileInfo
PBSTileInfo()
Create an empty PBSTileInfo.
Definition: pbs.h:34
FollowTrainReservation
PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res=nullptr)
Follow a train reservation to the last tile.
Definition: pbs.cpp:288
PBSTileInfo
This struct contains information about the end of a reserved path.
Definition: pbs.h:26
TryReserveRailTrack
bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations=true)
Try to reserve a specific track on a tile.
Definition: pbs.cpp:80
PBSTileInfo::trackdir
Trackdir trackdir
The reserved trackdir on the tile.
Definition: pbs.h:28
IsSafeWaitingPosition
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg=false)
Determine whether a certain track on a tile is a safe position to end a path.
Definition: pbs.cpp:380
Train
'Train' is either a loco or a wagon.
Definition: train.h:88
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:89
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
IsWaitingPositionFree
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg=false)
Check if a safe position is free.
Definition: pbs.cpp:426
PBSTileInfo::tile
TileIndex tile
Tile the path ends, INVALID_TILE if no valid path was found.
Definition: pbs.h:27
SetRailStationPlatformReservation
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
Definition: pbs.cpp:57
vehicle_type.h
tile_type.h
PBSTileInfo::PBSTileInfo
PBSTileInfo(TileIndex _t, Trackdir _td, bool _okay)
Create a PBSTileInfo with given tile, track direction and safe waiting position information.
Definition: pbs.h:42
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
UnreserveRailTrack
void UnreserveRailTrack(TileIndex tile, Track t)
Lift the reservation of a specific track on a tile.
Definition: pbs.cpp:140
GetReservedTrackbits
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
Definition: pbs.cpp:24
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
track_type.h