OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Data Structures | Functions
pbs.cpp File Reference

PBS support routines. More...

`#include "stdafx.h"`
`#include "viewport_func.h"`
`#include "vehicle_func.h"`
`#include "newgrf_station.h"`
`#include "pathfinder/follow_track.hpp"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | FindTrainOnTrackInfo
| Helper struct for finding the best matching vehicle on a specific track. More...

## Functions
TrackBits | GetReservedTrackbits (TileIndex t)
| Get the reserved trackbits for any tile, regardless of type.
void | SetRailStationPlatformReservation (TileIndex start, DiagDirection dir, bool b)
| Set the reservation for a complete station platform.
bool | TryReserveRailTrack (TileIndex tile, Track t, bool trigger_stations)
| Try to reserve a specific track on a tile.
void | UnreserveRailTrack (TileIndex tile, Track t)
| Lift the reservation of a specific track on a tile.
static PBSTileInfo | FollowReservation (Owner o, RailTypes rts, TileIndex tile, Trackdir trackdir, bool ignore_oneway=false)
| Follow a reservation starting from a specific tile to the end.
static Vehicle * | FindTrainOnTrackEnum (Vehicle *v, void *data)
| Callback for Has/FindVehicleOnPos to find a train on a specific track.
PBSTileInfo | FollowTrainReservation (const Train *v, Vehicle **train_on_res)
| Follow a train reservation to the last tile.
Train * | GetTrainForReservation (TileIndex tile, Track track)
| Find the train which has reserved a specific path.
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.
bool | IsWaitingPositionFree (const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
| Check if a safe position is free.

## Detailed Description

PBS support routines.

Definition in file pbs.cpp.

## Function Documentation

static Vehicle* FindTrainOnTrackEnum | ( | Vehicle * | v,
|  | void * | data
| ) |  |
| static

Callback for Has/FindVehicleOnPos to find a train on a specific track.

Definition at line 266 of file pbs.cpp.

References FindTrainOnTrackInfo::best, SpecializedVehicle< T, Type >::First(), SpecializedVehicle< Train, Type >::From(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, FindTrainOnTrackInfo::res, TRACK_BIT_WORMHOLE, PBSTileInfo::trackdir, TrackdirToTrack(), BaseVehicle::type, VEH_TRAIN, Vehicle::vehstatus, and VS_CRASHED.

Referenced by FollowTrainReservation(), and GetTrainForReservation().

static PBSTileInfo FollowReservation | ( | Owner | o,
|  | RailTypes | rts,
|  | TileIndex | tile,
|  | Trackdir | trackdir,
|  | bool | ignore_oneway = `false`
| ) |  |
| static

Follow a reservation starting from a specific tile to the end.

Definition at line 190 of file pbs.cpp.

References DiagDirToDiagTrackdir(), FindFirstTrackdir(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetReservedTrackbits(), HasOnewaySignalBlockingTrackdir(), HasReservedTracks(), HasSignalOnTrackdir(), HasStationReservation(), IsRailDepotTile(), IsTileType(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_exitdir, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_is_station, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_td_bits, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_tile, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_tiles_skipped, MP_RAILWAY, TileOffsByDiagDir(), TrackBitsToTrackdirBits(), TRACKDIR_BIT_NONE, TrackdirToTrack(), and TrackToTrackBits().

Referenced by FollowTrainReservation(), and GetTrainForReservation().

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

Follow a train reservation to the last tile.

Parameters

  v | the vehicle
  train_on_res | Is 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.

References _settings_game, FindTrainOnTrackInfo::best, RailtypeInfo::compatible_railtypes, FindTrainOnTrackEnum(), FindVehicleOnPos(), SpecializedVehicle< T, Type >::First(), FollowReservation(), PathfinderSettings::forbid_90_deg, GetDepotReservationTrackBits(), GetOtherTunnelBridgeEnd(), GetRailTypeInfo(), Train::GetVehicleTrackdir(), IsCompatibleTrainStationTile(), IsRailDepotTile(), IsRailStationTile(), IsSafeWaitingPosition(), IsTileType(), MP_TUNNELBRIDGE, PBSTileInfo::okay, Vehicle::owner, GameSettings::pf, FindTrainOnTrackInfo::res, ReverseTrackdir(), PBSTileInfo::tile, Vehicle::tile, TileOffsByDiagDir(), PBSTileInfo::trackdir, TrackdirToExitdir(), BaseVehicle::type, and VEH_TRAIN.

Referenced by ExtendTrainReservation(), FindClosestTrainDepot(), NPFTrainChooseTrack(), TryPathReserve(), and YapfTrainFindNearestDepot().

TrackBits GetReservedTrackbits | ( | TileIndex | t | ) |

Get the reserved trackbits for any tile, regardless of type.

Parameters

  t | the tile

Returns
  the reserved trackbits. TRACK_BIT_NONE on nothing reserved or a tile without rail.

Definition at line 26 of file pbs.cpp.

References GetCrossingReservationTrackBits(), GetDepotReservationTrackBits(), GetRailReservationTrackBits(), GetStationReservationTrackBits(), GetTileType(), GetTunnelBridgeReservationTrackBits(), GetTunnelBridgeTransportType(), HasStationRail(), IsLevelCrossing(), IsPlainRail(), IsRailDepot(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, TRACK_BIT_NONE, and TRANSPORT_RAIL.

Referenced by CmdConvertRail(), CmdRemoveSingleSignal(), FollowReservation(), FreeTrainTrackReservation(), HasReservedTracks(), IsWaitingPositionFree(), CYapfCostRailT< Types >::ReservationCost(), and TrainController().

Train* GetTrainForReservation | ( | TileIndex | tile,
|  | Track | track
| ) |  |

Find the train which has reserved a specific path.

Parameters

  tile | A tile on the path.
  track | A 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.

References FindTrainOnTrackInfo::best, RailtypeInfo::compatible_railtypes, FindTrainOnTrackEnum(), FindVehicleOnPos(), FollowReservation(), GetOtherTunnelBridgeEnd(), GetRailTypeInfo(), GetTileOwner(), GetTileRailType(), HasOnewaySignalBlockingTrackdir(), HasPbsSignalOnTrackdir(), HasReservedTracks(), IsCompatibleTrainStationTile(), IsRailStationTile(), IsTileType(), MP_TUNNELBRIDGE, FindTrainOnTrackInfo::res, ReverseTrackdir(), PBSTileInfo::tile, TileOffsByDiagDir(), PBSTileInfo::trackdir, TrackdirToExitdir(), TrackToTrackBits(), and TrackToTrackdir().

Referenced by CheckFlatLandRailStation(), CmdBuildRailStation(), CmdBuildSingleSignal(), CmdConvertRail(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), DoClearBridge(), DoClearTunnel(), and RemoveFromRailBaseStation().

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

  v | the vehicle to test for
  tile | The tile
  trackdir | The trackdir to test
  include_line_end | Should end-of-line tiles be considered safe?
  forbid_90deg | Don'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 RailtypeInfo::compatible_railtypes, DiagdirReachesTrackdirs(), FindFirstTrackdir(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetRailTypeInfo(), HasPbsSignalOnTrackdir(), HasSignalOnTrackdir(), IsRailDepotTile(), IsTileType(), KillFirstBit(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_exitdir, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_td_bits, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_tile, MP_RAILWAY, ReverseTrackdir(), SIGTYPE_PBS_ONEWAY, TRACKDIR_BIT_NONE, TrackdirCrossesTrackdirs(), and TrackdirToTrack().

Referenced by CmdBuildSingleSignal(), ExtendTrainReservation(), FindSafePosition(), FollowTrainReservation(), NPFFindSafeTile(), CYapfCostRailT< Types >::PfCalcCost(), and CYapfDestinationAnySafeTileRailT< Types >::PfDetectDestination().

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

Check if a safe position is free.

Parameters

  v | the vehicle to test for
  tile | The tile
  trackdir | The trackdir to test
  forbid_90deg | Don't allow trains to make 90 degree turns

Returns
  True if the position is free

Definition at line 429 of file pbs.cpp.

References RailtypeInfo::compatible_railtypes, DiagdirReachesTrackdirs(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetRailTypeInfo(), GetReservedTrackbits(), HasReservedTracks(), HasSignalOnTrackdir(), IsRailDepotTile(), IsTileType(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_exitdir, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_td_bits, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::m_new_tile, MP_RAILWAY, TrackdirBitsToTrackBits(), TrackdirCrossesTrackdirs(), TrackdirToTrack(), and TrackOverlapsTracks().

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

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

Set the reservation for a complete station platform.

Precondition
  IsRailStationTile(start)

Parameters

  start | starting tile of the platform
  dir | the direction in which to follow the platform
  b | the state the reservation should be set to

Definition at line 59 of file pbs.cpp.

References DiagDirToAxis(), GetRailStationAxis(), IsCompatibleTrainStationTile(), IsRailStationTile(), MarkTileDirtyByTile(), SetRailStationReservation(), TILE_ADD, and TileOffsByDiagDir().

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

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

Try to reserve a specific track on a tile.

Parameters

  tile | the tile
  t | the track
  trigger_stations | whether 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.

References _settings_client, BarCrossing(), GetTileTrackStatus(), GetTileType(), GetTunnelBridgeReservationTrackBits(), GetTunnelBridgeTransportType(), ClientSettings::gui, HasCrossingReservation(), HasDepotReservation(), HasStationRail(), HasStationReservation(), IsBridgeTile(), IsLevelCrossing(), IsPlainRail(), IsRailDepot(), IsRailStation(), MarkBridgeDirty(), MarkTileDirtyByTile(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, SetCrossingReservation(), SetDepotReservation(), SetRailStationReservation(), SetTunnelBridgeReservation(), GUISettings::show_track_reservation, SRT_PATH_RESERVATION, TrackToTrackBits(), TRANSPORT_RAIL, TriggerStationRandomisation(), and TryReserveTrack().

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

void UnreserveRailTrack | ( | TileIndex | tile,
|  | Track | t
| ) |  |

Lift the reservation of a specific track on a tile.

Parameters

  tile | the tile
  t | the track

Definition at line 143 of file pbs.cpp.

References _settings_client, GetTileTrackStatus(), GetTileType(), GetTunnelBridgeTransportType(), ClientSettings::gui, HasStationRail(), IsBridgeTile(), IsLevelCrossing(), IsPlainRail(), IsRailDepot(), MarkBridgeDirty(), MarkTileDirtyByTile(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, SetCrossingReservation(), SetDepotReservation(), SetRailStationReservation(), SetTunnelBridgeReservation(), GUISettings::show_track_reservation, TrackToTrackBits(), TRANSPORT_RAIL, UnreserveTrack(), and UpdateLevelCrossing().

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