OpenTTD Source: src/pbs.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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
20void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b);
21
22bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations = true);
23void 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);
46bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg = false);
47bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg = false);
48
49 Train *GetTrainForReservation(TileIndex tile, Track track);
50
58 inline bool HasReservedTracks(TileIndex tile, TrackBits tracks)
59{
60 return (GetReservedTrackbits(tile) & tracks) != TRACK_BIT_NONE;
61}
62
63#endif /* PBS_H */
direction_type.h
Different types to 'show' directions.
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
GetTrainForReservation
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
Definition pbs.cpp:331
TryReserveRailTrack
bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations=true)
Try to reserve a specific track on a tile.
Definition pbs.cpp:80
SetRailStationPlatformReservation
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
Definition pbs.cpp:57
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:381
HasReservedTracks
bool HasReservedTracks(TileIndex tile, TrackBits tracks)
Check whether some of tracks is reserved on a tile.
Definition pbs.h:58
IsWaitingPositionFree
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg=false)
Check if a safe position is free.
Definition pbs.cpp:427
GetReservedTrackbits
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
Definition pbs.cpp:24
UnreserveRailTrack
void UnreserveRailTrack(TileIndex tile, Track t)
Lift the reservation of a specific track on a tile.
Definition pbs.cpp:144
FollowTrainReservation
PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res=nullptr)
Follow a train reservation to the last tile.
Definition pbs.cpp:289
PBSTileInfo
This struct contains information about the end of a reserved path.
Definition pbs.h:26
PBSTileInfo::trackdir
Trackdir trackdir
The reserved trackdir on the tile.
Definition pbs.h:28
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
PBSTileInfo::PBSTileInfo
PBSTileInfo()
Create an empty PBSTileInfo.
Definition pbs.h:34
PBSTileInfo::tile
TileIndex tile
Tile the path ends, INVALID_TILE if no valid path was found.
Definition pbs.h:27
PBSTileInfo::okay
bool okay
True if tile is a safe waiting position, false otherwise.
Definition pbs.h:29
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Train
'Train' is either a loco or a wagon.
Definition train.h:91
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
tile_type.h
Types related to tiles.
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
track_type.h
All types related to tracks.
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition track_type.h:36
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:66
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:85
Track
Track
These are used to specify a single track.
Definition track_type.h:19
vehicle_type.h
Types related to vehicles.