OpenTTD Source  20241120-master-g6d3adc6169
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 
19 
21 
22 bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations = true);
23 void UnreserveRailTrack(TileIndex tile, Track t);
24 
26 struct PBSTileInfo {
29  bool okay;
30 
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 
50 
58 inline bool HasReservedTracks(TileIndex tile, TrackBits tracks)
59 {
60  return (GetReservedTrackbits(tile) & tracks) != TRACK_BIT_NONE;
61 }
62 
63 #endif /* PBS_H */
Different types to 'show' directions.
DiagDirection
Enumeration for diagonal directions.
bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations=true)
Try to reserve a specific track on a tile.
Definition: pbs.cpp:80
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
Definition: pbs.cpp:57
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
bool HasReservedTracks(TileIndex tile, TrackBits tracks)
Check whether some of tracks is reserved on a tile.
Definition: pbs.h:58
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg=false)
Check if a safe position is free.
Definition: pbs.cpp:426
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
Definition: pbs.cpp:24
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
Definition: pbs.cpp:330
void UnreserveRailTrack(TileIndex tile, Track t)
Lift the reservation of a specific track on a tile.
Definition: pbs.cpp:140
PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res=nullptr)
Follow a train reservation to the last tile.
Definition: pbs.cpp:288
This struct contains information about the end of a reserved path.
Definition: pbs.h:26
Trackdir trackdir
The reserved trackdir on the tile.
Definition: pbs.h:28
PBSTileInfo(TileIndex _t, Trackdir _td, bool _okay)
Create a PBSTileInfo with given tile, track direction and safe waiting position information.
Definition: pbs.h:42
PBSTileInfo()
Create an empty PBSTileInfo.
Definition: pbs.h:34
TileIndex tile
Tile the path ends, INVALID_TILE if no valid path was found.
Definition: pbs.h:27
bool okay
True if tile is a safe waiting position, false otherwise.
Definition: pbs.h:29
'Train' is either a loco or a wagon.
Definition: train.h:89
Vehicle data structure.
Definition: vehicle_base.h:244
Types related to tiles.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
All types related to tracks.
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:36
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:86
Track
These are used to specify a single track.
Definition: track_type.h:19
Types related to vehicles.