OpenTTD
Data Structures | Functions
pbs.h File Reference

PBS support routines. More...

#include "tile_type.h"
#include "direction_type.h"
#include "track_type.h"
#include "vehicle_type.h"

Go to the source code of this file.

Data Structures

struct  PBSTileInfo
 This struct contains information about the end of a reserved path. More...
 

Functions

TrackBits GetReservedTrackbits (TileIndex t)
 Get the reserved trackbits for any tile, regardless of type. More...
 
void SetRailStationPlatformReservation (TileIndex start, DiagDirection dir, bool b)
 Set the reservation for a complete station platform. More...
 
bool TryReserveRailTrack (TileIndex tile, Track t, bool trigger_stations=true)
 Try to reserve a specific track on a tile. More...
 
void UnreserveRailTrack (TileIndex tile, Track t)
 Lift the reservation of a specific track on a tile. More...
 
PBSTileInfo FollowTrainReservation (const Train *v, Vehicle **train_on_res=NULL)
 Follow a train reservation to the last tile. More...
 
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. More...
 
bool IsWaitingPositionFree (const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg=false)
 Check if a safe position is free. More...
 
TrainGetTrainForReservation (TileIndex tile, Track track)
 Find the train which has reserved a specific path. More...
 
static bool HasReservedTracks (TileIndex tile, TrackBits tracks)
 Check whether some of tracks is reserved on a tile. More...
 

Detailed Description

PBS support routines.

Definition in file pbs.h.

Function Documentation

◆ FollowTrainReservation()

PBSTileInfo FollowTrainReservation ( const Train v,
Vehicle **  train_on_res 
)

Follow a train reservation to the last tile.

Parameters
vthe vehicle
train_on_resIs set to a train we might encounter
Returns
The last tile of the reservation or the current train tile if no reservation present.

Definition at line 291 of file pbs.cpp.

Referenced by ExtendTrainReservation(), PBSTileInfo::PBSTileInfo(), and YapfTrainFindNearestDepot().

◆ GetReservedTrackbits()

TrackBits GetReservedTrackbits ( TileIndex  t)

◆ GetTrainForReservation()

Train* GetTrainForReservation ( TileIndex  tile,
Track  track 
)

Find the train which has reserved a specific path.

Parameters
tileA tile on the path.
trackA reserved track on the tile.
Returns
The vehicle holding the reservation or NULL if the path is stray.

Definition at line 333 of file pbs.cpp.

Referenced by CmdConvertRail(), and PBSTileInfo::PBSTileInfo().

◆ HasReservedTracks()

static bool HasReservedTracks ( TileIndex  tile,
TrackBits  tracks 
)
inlinestatic

Check whether some of tracks is reserved on a tile.

Parameters
tilethe tile
tracksthe tracks to test
Returns
true if at least on of tracks is reserved

Definition at line 60 of file pbs.h.

References GetReservedTrackbits(), and TRACK_BIT_NONE.

Referenced by DeleteLastWagon(), ExtendTrainReservation(), and FollowReservation().

◆ IsSafeWaitingPosition()

bool IsSafeWaitingPosition ( const Train v,
TileIndex  tile,
Trackdir  trackdir,
bool  include_line_end,
bool  forbid_90deg 
)

Determine whether a certain track on a tile is a safe position to end a path.

Parameters
vthe vehicle to test for
tileThe tile
trackdirThe trackdir to test
include_line_endShould end-of-line tiles be considered safe?
forbid_90degDon't allow trains to make 90 degree turns
Returns
True if it is a safe position

Definition at line 383 of file pbs.cpp.

References HasSignalOnTrackdir(), IsRailDepotTile(), IsTileType(), and MP_RAILWAY.

Referenced by ExtendTrainReservation(), FindSafePosition(), NPFFindSafeTile(), PBSTileInfo::PBSTileInfo(), and CYapfDestinationAnySafeTileRailT< Types >::PfDetectDestination().

◆ IsWaitingPositionFree()

bool IsWaitingPositionFree ( const Train v,
TileIndex  tile,
Trackdir  trackdir,
bool  forbid_90deg 
)

Check if a safe position is free.

Parameters
vthe vehicle to test for
tileThe tile
trackdirThe trackdir to test
forbid_90degDon't allow trains to make 90 degree turns
Returns
True if the position is free

Definition at line 429 of file pbs.cpp.

References GetReservedTrackbits(), HasSignalOnTrackdir(), IsRailDepotTile(), IsTileType(), MP_RAILWAY, TrackdirToTrack(), and TrackOverlapsTracks().

Referenced by ExtendTrainReservation(), NPFFindSafeTile(), NPFSaveTargetData(), PBSTileInfo::PBSTileInfo(), CYapfDestinationAnySafeTileRailT< Types >::PfDetectDestination(), and CYapfReserveTrack< Types >::TryReservePath().

◆ SetRailStationPlatformReservation()

void SetRailStationPlatformReservation ( TileIndex  start,
DiagDirection  dir,
bool  b 
)

Set the reservation for a complete station platform.

Precondition
IsRailStationTile(start)
Parameters
startstarting tile of the platform
dirthe direction in which to follow the platform
bthe state the reservation should be set to

Definition at line 59 of file pbs.cpp.

References TileOffsByDiagDir().

Referenced by ClearPathReservation(), FreeTrainReservation(), NPFSaveTargetData(), and RestoreTrainReservation().

◆ TryReserveRailTrack()

bool TryReserveRailTrack ( TileIndex  tile,
Track  t,
bool  trigger_stations 
)

Try to reserve a specific track on a tile.

Parameters
tilethe tile
tthe track
trigger_stationswhether to call station randomisation trigger
Returns
true if reservation was successful, i.e. the track was free and didn't cross any other reserved tracks.

Definition at line 82 of file pbs.cpp.

Referenced by ExtendTrainReservation(), NPFSaveTargetData(), CYapfReserveTrack< Types >::ReserveSingleTrack(), and Train::ReserveTrackUnderConsist().

◆ UnreserveRailTrack()

void UnreserveRailTrack ( TileIndex  tile,
Track  t 
)

Lift the reservation of a specific track on a tile.

Parameters
tilethe tile
tthe track

Definition at line 143 of file pbs.cpp.

Referenced by ClearPathReservation(), DeleteLastWagon(), and CYapfReserveTrack< Types >::UnreserveSingleTrack().