OpenTTD
Enumerations | Functions
rail_map.h File Reference

Hides the direct accesses to the map array with map accessors. More...

#include "rail_type.h"
#include "depot_type.h"
#include "signal_func.h"
#include "track_func.h"
#include "tile_map.h"
#include "signal_type.h"

Go to the source code of this file.

Enumerations

enum  RailTileType { RAIL_TILE_NORMAL = 0, RAIL_TILE_SIGNALS = 1, RAIL_TILE_DEPOT = 3 }
 Different types of Rail-related tiles. More...
 
enum  RailGroundType {
  RAIL_GROUND_BARREN = 0, RAIL_GROUND_GRASS = 1, RAIL_GROUND_FENCE_NW = 2, RAIL_GROUND_FENCE_SE = 3,
  RAIL_GROUND_FENCE_SENW = 4, RAIL_GROUND_FENCE_NE = 5, RAIL_GROUND_FENCE_SW = 6, RAIL_GROUND_FENCE_NESW = 7,
  RAIL_GROUND_FENCE_VERT1 = 8, RAIL_GROUND_FENCE_VERT2 = 9, RAIL_GROUND_FENCE_HORIZ1 = 10, RAIL_GROUND_FENCE_HORIZ2 = 11,
  RAIL_GROUND_ICE_DESERT = 12, RAIL_GROUND_WATER = 13, RAIL_GROUND_HALF_SNOW = 14
}
 The ground 'under' the rail. More...
 

Functions

static RailTileType GetRailTileType (TileIndex t)
 Returns the RailTileType (normal with or without signals, waypoint or depot). More...
 
static bool IsPlainRail (TileIndex t)
 Returns whether this is plain rails, with or without signals. More...
 
static bool IsPlainRailTile (TileIndex t)
 Checks whether the tile is a rail tile or rail tile with signals. More...
 
static bool HasSignals (TileIndex t)
 Checks if a rail tile has signals. More...
 
static void SetHasSignals (TileIndex tile, bool signals)
 Add/remove the 'has signal' bit from the RailTileType. More...
 
static bool IsRailDepot (TileIndex t)
 Is this rail tile a rail depot? More...
 
static bool IsRailDepotTile (TileIndex t)
 Is this tile rail tile and a rail depot? More...
 
static RailType GetRailType (TileIndex t)
 Gets the rail type of the given tile. More...
 
static void SetRailType (TileIndex t, RailType r)
 Sets the rail type of the given tile. More...
 
static TrackBits GetTrackBits (TileIndex tile)
 Gets the track bits of the given tile. More...
 
static void SetTrackBits (TileIndex t, TrackBits b)
 Sets the track bits of the given tile. More...
 
static bool HasTrack (TileIndex tile, Track track)
 Returns whether the given track is present on the given tile. More...
 
static DiagDirection GetRailDepotDirection (TileIndex t)
 Returns the direction the depot is facing to. More...
 
static Track GetRailDepotTrack (TileIndex t)
 Returns the track of a depot, ignoring direction. More...
 
static TrackBits GetRailReservationTrackBits (TileIndex t)
 Returns the reserved track bits of the tile. More...
 
static void SetTrackReservation (TileIndex t, TrackBits b)
 Sets the reserved track bits of the tile. More...
 
static bool TryReserveTrack (TileIndex tile, Track t)
 Try to reserve a specific track on a tile. More...
 
static void UnreserveTrack (TileIndex tile, Track t)
 Lift the reservation of a specific track on a tile. More...
 
static bool HasDepotReservation (TileIndex t)
 Get the reservation state of the depot. More...
 
static void SetDepotReservation (TileIndex t, bool b)
 Set the reservation state of the depot. More...
 
static TrackBits GetDepotReservationTrackBits (TileIndex t)
 Get the reserved track bits for a depot. More...
 
static bool IsPbsSignal (SignalType s)
 
static SignalType GetSignalType (TileIndex t, Track track)
 
static void SetSignalType (TileIndex t, Track track, SignalType s)
 
static bool IsPresignalEntry (TileIndex t, Track track)
 
static bool IsPresignalExit (TileIndex t, Track track)
 
static bool IsOnewaySignal (TileIndex t, Track track)
 One-way signals can't be passed the 'wrong' way. More...
 
static void CycleSignalSide (TileIndex t, Track track)
 
static SignalVariant GetSignalVariant (TileIndex t, Track track)
 
static void SetSignalVariant (TileIndex t, Track track, SignalVariant v)
 
static void SetSignalStates (TileIndex tile, uint state)
 Set the states of the signals (Along/AgainstTrackDir) More...
 
static uint GetSignalStates (TileIndex tile)
 Set the states of the signals (Along/AgainstTrackDir) More...
 
static SignalState GetSingleSignalState (TileIndex t, byte signalbit)
 Get the state of a single signal. More...
 
static void SetPresentSignals (TileIndex tile, uint signals)
 Set whether the given signals are present (Along/AgainstTrackDir) More...
 
static uint GetPresentSignals (TileIndex tile)
 Get whether the given signals are present (Along/AgainstTrackDir) More...
 
static bool IsSignalPresent (TileIndex t, byte signalbit)
 Checks whether the given signals is present. More...
 
static bool HasSignalOnTrack (TileIndex tile, Track track)
 Checks for the presence of signals (either way) on the given track on the given rail tile.
 
static bool HasSignalOnTrackdir (TileIndex tile, Trackdir trackdir)
 Checks for the presence of signals along the given trackdir on the given rail tile. More...
 
static SignalState GetSignalStateByTrackdir (TileIndex tile, Trackdir trackdir)
 Gets the state of the signal along the given trackdir. More...
 
static void SetSignalStateByTrackdir (TileIndex tile, Trackdir trackdir, SignalState state)
 Sets the state of the signal along the given trackdir.
 
static bool HasPbsSignalOnTrackdir (TileIndex tile, Trackdir td)
 Is a pbs signal present along the trackdir? More...
 
static bool HasOnewaySignalBlockingTrackdir (TileIndex tile, Trackdir td)
 Is a one-way signal blocking the trackdir? A one-way signal on the trackdir against will block, but signals on both trackdirs won't. More...
 
RailType GetTileRailType (TileIndex tile)
 Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
 
static void SetRailGroundType (TileIndex t, RailGroundType rgt)
 
static RailGroundType GetRailGroundType (TileIndex t)
 
static bool IsSnowRailGround (TileIndex t)
 
static void MakeRailNormal (TileIndex t, Owner o, TrackBits b, RailType r)
 
static void MakeRailDepot (TileIndex t, Owner o, DepotID did, DiagDirection d, RailType r)
 

Detailed Description

Hides the direct accesses to the map array with map accessors.

Definition in file rail_map.h.

Enumeration Type Documentation

◆ RailGroundType

The ground 'under' the rail.

Enumerator
RAIL_GROUND_BARREN 

Nothing (dirt)

RAIL_GROUND_GRASS 

Grassy.

RAIL_GROUND_FENCE_NW 

Grass with a fence at the NW edge.

RAIL_GROUND_FENCE_SE 

Grass with a fence at the SE edge.

RAIL_GROUND_FENCE_SENW 

Grass with a fence at the NW and SE edges.

RAIL_GROUND_FENCE_NE 

Grass with a fence at the NE edge.

RAIL_GROUND_FENCE_SW 

Grass with a fence at the SW edge.

RAIL_GROUND_FENCE_NESW 

Grass with a fence at the NE and SW edges.

RAIL_GROUND_FENCE_VERT1 

Grass with a fence at the eastern side.

RAIL_GROUND_FENCE_VERT2 

Grass with a fence at the western side.

RAIL_GROUND_FENCE_HORIZ1 

Grass with a fence at the southern side.

RAIL_GROUND_FENCE_HORIZ2 

Grass with a fence at the northern side.

RAIL_GROUND_ICE_DESERT 

Icy or sandy.

RAIL_GROUND_WATER 

Grass with a fence and shore or water on the free halftile.

RAIL_GROUND_HALF_SNOW 

Snow only on higher part of slope (steep or one corner raised)

Definition at line 486 of file rail_map.h.

◆ RailTileType

Different types of Rail-related tiles.

Enumerator
RAIL_TILE_NORMAL 

Normal rail tile without signals.

RAIL_TILE_SIGNALS 

Normal rail tile with signals.

RAIL_TILE_DEPOT 

Depot (one entrance)

Definition at line 24 of file rail_map.h.

Function Documentation

◆ GetDepotReservationTrackBits()

static TrackBits GetDepotReservationTrackBits ( TileIndex  t)
inlinestatic

Get the reserved track bits for a depot.

Precondition
IsRailDepot(t)
Parameters
tthe tile
Returns
reserved track bits

Definition at line 283 of file rail_map.h.

References GetRailDepotTrack(), HasDepotReservation(), TRACK_BIT_NONE, and TrackToTrackBits().

Referenced by GetReservedTrackbits().

◆ GetPresentSignals()

static uint GetPresentSignals ( TileIndex  tile)
inlinestatic

Get whether the given signals are present (Along/AgainstTrackDir)

Parameters
tilethe tile to get the present signals for
Returns
the signals that are present

Definition at line 394 of file rail_map.h.

References _m, and GB().

Referenced by IsSignalPresent().

◆ GetRailDepotDirection()

static DiagDirection GetRailDepotDirection ( TileIndex  t)
inlinestatic

Returns the direction the depot is facing to.

Parameters
tthe tile to get the depot facing from
Precondition
IsRailDepotTile(t)
Returns
the direction the depot is facing

Definition at line 172 of file rail_map.h.

References _m, and GB().

Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse(), GetRailDepotTrack(), Train::GetVehicleTrackdir(), TicksToLeaveDepot(), and TrainCanLeaveTile().

◆ GetRailDepotTrack()

static Track GetRailDepotTrack ( TileIndex  t)
inlinestatic

Returns the track of a depot, ignoring direction.

Precondition
IsRailDepotTile(t)
Parameters
tthe tile to get the depot track from
Returns
the track of the depot

Definition at line 183 of file rail_map.h.

References DiagDirToDiagTrack(), and GetRailDepotDirection().

Referenced by AdvanceWagonsAfterSwap(), CmdConvertRail(), and GetDepotReservationTrackBits().

◆ GetRailReservationTrackBits()

static TrackBits GetRailReservationTrackBits ( TileIndex  t)
inlinestatic

Returns the reserved track bits of the tile.

Precondition
IsPlainRailTile(t)
Parameters
tthe tile to query
Returns
the track bits

Definition at line 195 of file rail_map.h.

Referenced by GetReservedTrackbits().

◆ GetRailTileType()

static RailTileType GetRailTileType ( TileIndex  t)
inlinestatic

Returns the RailTileType (normal with or without signals, waypoint or depot).

Parameters
tthe tile to get the information from
Precondition
IsTileType(t, MP_RAILWAY)
Returns
the RailTileType

Definition at line 37 of file rail_map.h.

Referenced by CmdConvertRail(), GetAxisForNewWaypoint(), GetRailTrackBitsUniversal(), HasSignals(), IsPlainRail(), IsPossibleCrossing(), IsRailDepot(), and PlaceExtraDepotRail().

◆ GetRailType()

static RailType GetRailType ( TileIndex  t)
inlinestatic

◆ GetSignalStateByTrackdir()

static SignalState GetSignalStateByTrackdir ( TileIndex  tile,
Trackdir  trackdir 
)
inlinestatic

Gets the state of the signal along the given trackdir.

Along meaning if you are currently driving on the given trackdir, this is the signal that is facing us (for which we stop when it's red).

Definition at line 439 of file rail_map.h.

◆ GetSignalStates()

static uint GetSignalStates ( TileIndex  tile)
inlinestatic

Set the states of the signals (Along/AgainstTrackDir)

Parameters
tilethe tile to set the states for
Returns
the state of the signals

Definition at line 363 of file rail_map.h.

References _m, and GB().

Referenced by GetSingleSignalState(), and SetSignalStateByTrackdir().

◆ GetSingleSignalState()

static SignalState GetSingleSignalState ( TileIndex  t,
byte  signalbit 
)
inlinestatic

Get the state of a single signal.

Parameters
tthe tile to get the signal state for
signalbitthe signal
Returns
the state of the signal

Definition at line 374 of file rail_map.h.

References GetSignalStates(), and HasBit().

◆ GetTrackBits()

static TrackBits GetTrackBits ( TileIndex  tile)
inlinestatic

Gets the track bits of the given tile.

Parameters
tilethe tile to get the track bits from
Returns
the track bits of the tile

Definition at line 137 of file rail_map.h.

Referenced by CheckTrackCombination(), CmdConvertRail(), GetAxisForNewWaypoint(), GetRailTrackBitsUniversal(), HasTrack(), IsPossibleCrossing(), PlaceExtraDepotRail(), and CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::QueryNewTileTrackStatus().

◆ HasDepotReservation()

static bool HasDepotReservation ( TileIndex  t)
inlinestatic

Get the reservation state of the depot.

Precondition
IsRailDepot(t)
Parameters
tthe depot tile
Returns
reservation state

Definition at line 259 of file rail_map.h.

Referenced by CheckTrainStayInDepot(), and GetDepotReservationTrackBits().

◆ HasOnewaySignalBlockingTrackdir()

static bool HasOnewaySignalBlockingTrackdir ( TileIndex  tile,
Trackdir  td 
)
inlinestatic

Is a one-way signal blocking the trackdir? A one-way signal on the trackdir against will block, but signals on both trackdirs won't.

Parameters
tilethe tile to check
tdthe trackdir to check

Definition at line 476 of file rail_map.h.

References GetTileRailType(), HasSignalOnTrackdir(), IsOnewaySignal(), IsTileType(), MP_RAILWAY, ReverseTrackdir(), and TrackdirToTrack().

Referenced by ExtendTrainReservation(), and FollowReservation().

◆ HasPbsSignalOnTrackdir()

static bool HasPbsSignalOnTrackdir ( TileIndex  tile,
Trackdir  td 
)
inlinestatic

Is a pbs signal present along the trackdir?

Parameters
tilethe tile to check
tdthe trackdir to check

Definition at line 464 of file rail_map.h.

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

◆ HasSignalOnTrackdir()

static bool HasSignalOnTrackdir ( TileIndex  tile,
Trackdir  trackdir 
)
inlinestatic

Checks for the presence of signals along the given trackdir on the given rail tile.

Along meaning if you are currently driving on the given trackdir, this is the signal that is facing us (for which we stop when it's red).

Definition at line 427 of file rail_map.h.

Referenced by FollowReservation(), HasOnewaySignalBlockingTrackdir(), HasPbsSignalOnTrackdir(), IsSafeWaitingPosition(), and IsWaitingPositionFree().

◆ HasSignals()

static bool HasSignals ( TileIndex  t)
inlinestatic

Checks if a rail tile has signals.

Parameters
tthe tile to get the information from
Precondition
IsTileType(t, MP_RAILWAY)
Returns
true if and only if the tile has signals

Definition at line 73 of file rail_map.h.

References GetRailTileType(), and RAIL_TILE_SIGNALS.

Referenced by CheckTrackCombination().

◆ HasTrack()

static bool HasTrack ( TileIndex  tile,
Track  track 
)
inlinestatic

Returns whether the given track is present on the given tile.

Parameters
tilethe tile to check the track presence of
trackthe track to search for on the tile
Precondition
IsPlainRailTile(tile)
Returns
true if and only if the given track exists on the tile

Definition at line 161 of file rail_map.h.

References GetTrackBits(), and HasBit().

◆ IsOnewaySignal()

static bool IsOnewaySignal ( TileIndex  t,
Track  track 
)
inlinestatic

One-way signals can't be passed the 'wrong' way.

Definition at line 320 of file rail_map.h.

Referenced by HasOnewaySignalBlockingTrackdir().

◆ IsPlainRail()

static bool IsPlainRail ( TileIndex  t)
inlinestatic

Returns whether this is plain rails, with or without signals.

Iow, if this tiles RailTileType is RAIL_TILE_NORMAL or RAIL_TILE_SIGNALS.

Parameters
tthe tile to get the information from
Precondition
IsTileType(t, MP_RAILWAY)
Returns
true if and only if the tile is normal rail (with or without signals)

Definition at line 50 of file rail_map.h.

References GetRailTileType(), RAIL_TILE_NORMAL, and RAIL_TILE_SIGNALS.

Referenced by CheckTrackCombination(), ExtendTrainReservation(), GetReservedTrackbits(), and IsPlainRailTile().

◆ IsPlainRailTile()

static bool IsPlainRailTile ( TileIndex  t)
inlinestatic

Checks whether the tile is a rail tile or rail tile with signals.

Parameters
tthe tile to get the information from
Returns
true if and only if the tile is normal rail (with or without signals)

Definition at line 61 of file rail_map.h.

References IsPlainRail(), IsTileType(), and MP_RAILWAY.

Referenced by CmdConvertRail(), MaskWireBits(), and CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::QueryNewTileTrackStatus().

◆ IsRailDepot()

static bool IsRailDepot ( TileIndex  t)
inlinestatic

Is this rail tile a rail depot?

Parameters
tthe tile to get the information from
Precondition
IsTileType(t, MP_RAILWAY)
Returns
true if and only if the tile is a rail depot

Definition at line 96 of file rail_map.h.

References GetRailTileType(), and RAIL_TILE_DEPOT.

Referenced by DrawRailCatenary(), GetReservedTrackbits(), and IsRailDepotTile().

◆ IsRailDepotTile()

static bool IsRailDepotTile ( TileIndex  t)
inlinestatic

Is this tile rail tile and a rail depot?

Parameters
tthe tile to get the information from
Returns
true if and only if the tile is a rail depot

Definition at line 106 of file rail_map.h.

References IsRailDepot(), IsTileType(), and MP_RAILWAY.

Referenced by FollowReservation(), IsDepotTile(), IsSafeWaitingPosition(), IsWaitingPositionFree(), CYapfDestinationAnyDepotRailT< Types >::PfDetectDestination(), ReverseTrainDirection(), and TrainCanLeaveTile().

◆ IsSignalPresent()

static bool IsSignalPresent ( TileIndex  t,
byte  signalbit 
)
inlinestatic

Checks whether the given signals is present.

Parameters
tthe tile to check on
signalbitthe signal
Returns
true if and only if the signal is present

Definition at line 405 of file rail_map.h.

References GetPresentSignals(), and HasBit().

◆ SetDepotReservation()

static void SetDepotReservation ( TileIndex  t,
bool  b 
)
inlinestatic

Set the reservation state of the depot.

Precondition
IsRailDepot(t)
Parameters
tthe depot tile
bthe reservation state

Definition at line 271 of file rail_map.h.

◆ SetHasSignals()

static void SetHasSignals ( TileIndex  tile,
bool  signals 
)
inlinestatic

Add/remove the 'has signal' bit from the RailTileType.

Parameters
tilethe tile to add/remove the signals to/from
signalswhether the rail tile should have signals or not
Precondition
IsPlainRailTile(tile)

Definition at line 84 of file rail_map.h.

◆ SetPresentSignals()

static void SetPresentSignals ( TileIndex  tile,
uint  signals 
)
inlinestatic

Set whether the given signals are present (Along/AgainstTrackDir)

Parameters
tilethe tile to set the present signals for
signalsthe signals that have to be present

Definition at line 384 of file rail_map.h.

References _m, and SB().

◆ SetRailType()

static void SetRailType ( TileIndex  t,
RailType  r 
)
inlinestatic

Sets the rail type of the given tile.

Parameters
tthe tile to set the rail type of
rthe new rail type for the tile

Definition at line 126 of file rail_map.h.

References _m, and SB().

Referenced by CmdConvertRail().

◆ SetSignalStates()

static void SetSignalStates ( TileIndex  tile,
uint  state 
)
inlinestatic

Set the states of the signals (Along/AgainstTrackDir)

Parameters
tilethe tile to set the states for
statethe new state

Definition at line 353 of file rail_map.h.

References _m, and SB().

Referenced by SetSignalStateByTrackdir().

◆ SetTrackBits()

static void SetTrackBits ( TileIndex  t,
TrackBits  b 
)
inlinestatic

Sets the track bits of the given tile.

Parameters
tthe tile to set the track bits of
bthe new track bits for the tile

Definition at line 148 of file rail_map.h.

◆ SetTrackReservation()

static void SetTrackReservation ( TileIndex  t,
TrackBits  b 
)
inlinestatic

Sets the reserved track bits of the tile.

Precondition
IsPlainRailTile(t) && !TracksOverlap(b)
Parameters
tthe tile to change
bthe track bits

Definition at line 210 of file rail_map.h.

◆ TryReserveTrack()

static bool TryReserveTrack ( TileIndex  tile,
Track  t 
)
inlinestatic

Try to reserve a specific track on a tile.

Precondition
IsPlainRailTile(t) && HasTrack(tile, t)
Parameters
tilethe tile
tthe rack to reserve
Returns
true if successful

Definition at line 227 of file rail_map.h.

◆ UnreserveTrack()

static void UnreserveTrack ( TileIndex  tile,
Track  t 
)
inlinestatic

Lift the reservation of a specific track on a tile.

Precondition
IsPlainRailTile(t) && HasTrack(tile, t)
Parameters
tilethe tile
tthe track to free

Definition at line 245 of file rail_map.h.