OpenTTD
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
rail_cmd.cpp File Reference

Handling of rail tiles. More...

#include "stdafx.h"
#include "cmd_helper.h"
#include "viewport_func.h"
#include "command_func.h"
#include "depot_base.h"
#include "pathfinder/yapf/yapf_cache.h"
#include "newgrf_debug.h"
#include "newgrf_railtype.h"
#include "train.h"
#include "autoslope.h"
#include "water.h"
#include "tunnelbridge_map.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "tunnelbridge.h"
#include "elrail_func.h"
#include "town.h"
#include "pbs.h"
#include "company_base.h"
#include "core/backup_type.hpp"
#include "date_func.h"
#include "strings_func.h"
#include "company_gui.h"
#include "object_map.h"
#include "table/strings.h"
#include "table/railtypes.h"
#include "table/track_land.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  FenceOffset
 Offsets for drawing fences. More...
 

Macros

#define MAYBE_DRAW_SIGNAL(x, y, z, t)   if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, rti, t, GetSingleSignalState(tile, x), y, z)
 

Typedefs

typedef SmallVector< Train *, 16 > TrainList
 Helper type for lists/vectors of trains.
 

Enumerations

enum  SignalOffsets {
  SIGNAL_TO_SOUTHWEST, SIGNAL_TO_NORTHEAST, SIGNAL_TO_SOUTHEAST, SIGNAL_TO_NORTHWEST,
  SIGNAL_TO_EAST, SIGNAL_TO_WEST, SIGNAL_TO_SOUTH, SIGNAL_TO_NORTH
}
 Enum holding the signal offset in the sprite sheet according to the side it is representing. More...
 

Functions

void ResetRailTypes ()
 Reset all rail type information to its default values.
 
void ResolveRailTypeGUISprites (RailtypeInfo *rti)
 
static int CDECL CompareRailTypes (const RailType *first, const RailType *second)
 Compare railtypes based on their sorting order. More...
 
void InitRailTypes ()
 Resolve sprites of custom rail types.
 
RailType AllocateRailType (RailTypeLabel label)
 Allocate a new rail type label.
 
static CommandCost EnsureNoTrainOnTrack (TileIndex tile, Track track)
 Tests if a vehicle interacts with the specified track. More...
 
static CommandCost CheckTrackCombination (TileIndex tile, TrackBits to_build, uint flags)
 Check that the new track bits may be built. More...
 
Foundation GetRailFoundation (Slope tileh, TrackBits bits)
 Checks if a track combination is valid on a specific slope and returns the needed foundation. More...
 
static CommandCost CheckRailSlope (Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
 Tests if a track can be build on a tile. More...
 
static bool ValParamTrackOrientation (Track track)
 
CommandCost CmdBuildSingleRail (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a single piece of rail. More...
 
CommandCost CmdRemoveSingleRail (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Remove a single piece of track. More...
 
bool FloodHalftile (TileIndex t)
 Called from water_cmd if a non-flat rail-tile gets flooded and should be converted to shore. More...
 
static CommandCost ValidateAutoDrag (Trackdir *trackdir, TileIndex start, TileIndex end)
 
static CommandCost CmdRailTrackHelper (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build or remove a stretch of railroad tracks. More...
 
CommandCost CmdBuildRailroadTrack (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build rail on a stretch of track. More...
 
CommandCost CmdRemoveRailroadTrack (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build rail on a stretch of track. More...
 
CommandCost CmdBuildTrainDepot (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a train depot. More...
 
CommandCost CmdBuildSingleSignal (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build signals, alternate between double/single, signal/semaphore, pre/exit/combo-signals, and what-else not. More...
 
static bool CheckSignalAutoFill (TileIndex &tile, Trackdir &trackdir, int &signal_ctr, bool remove)
 
static CommandCost CmdSignalTrackHelper (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build many signals by dragging; AutoSignals. More...
 
CommandCost CmdBuildSignalTrack (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build signals on a stretch of track. More...
 
CommandCost CmdRemoveSingleSignal (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Remove signals. More...
 
CommandCost CmdRemoveSignalTrack (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Remove signals on a stretch of track. More...
 
static VehicleUpdateTrainPowerProc (Vehicle *v, void *data)
 Update power of train under which is the railtype being converted.
 
CommandCost CmdConvertRail (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Convert one rail type to the other. More...
 
static CommandCost RemoveTrainDepot (TileIndex tile, DoCommandFlag flags)
 
static CommandCost ClearTile_Track (TileIndex tile, DoCommandFlag flags)
 
static uint GetSaveSlopeZ (uint x, uint y, Track track)
 Get surface height in point (x,y) On tiles with halftile foundations move (x,y) to a safe point wrt. More...
 
static void DrawSingleSignal (TileIndex tile, const RailtypeInfo *rti, Track track, SignalState condition, SignalOffsets image, uint pos)
 
static void DrawTrackFence (const TileInfo *ti, SpriteID base_image, uint num_sprites, RailFenceOffset rfo)
 Draw a track fence. More...
 
static void DrawTrackFence_NW (const TileInfo *ti, SpriteID base_image, uint num_sprites)
 Draw fence at NW border matching the tile slope.
 
static void DrawTrackFence_SE (const TileInfo *ti, SpriteID base_image, uint num_sprites)
 Draw fence at SE border matching the tile slope.
 
static void DrawTrackFence_NE (const TileInfo *ti, SpriteID base_image, uint num_sprites)
 Draw fence at NE border matching the tile slope.
 
static void DrawTrackFence_SW (const TileInfo *ti, SpriteID base_image, uint num_sprites)
 Draw fence at SW border matching the tile slope.
 
static void DrawTrackDetails (const TileInfo *ti, const RailtypeInfo *rti)
 Draw track fences. More...
 
static void DrawTrackSprite (SpriteID sprite, PaletteID pal, const TileInfo *ti, Slope s)
 
static void DrawTrackBitsOverlay (TileInfo *ti, TrackBits track, const RailtypeInfo *rti)
 
static void DrawTrackBits (TileInfo *ti, TrackBits track)
 Draw ground sprite and track bits. More...
 
static void DrawSignals (TileIndex tile, TrackBits rails, const RailtypeInfo *rti)
 
static void DrawTile_Track (TileInfo *ti)
 
void DrawTrainDepotSprite (int x, int y, int dir, RailType railtype)
 
static int GetSlopePixelZ_Track (TileIndex tile, uint x, uint y)
 
static Foundation GetFoundation_Track (TileIndex tile, Slope tileh)
 
static void TileLoop_Track (TileIndex tile)
 
static TrackStatus GetTileTrackStatus_Track (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 
static bool ClickTile_Track (TileIndex tile)
 
static void GetTileDesc_Track (TileIndex tile, TileDesc *td)
 
static void ChangeTileOwner_Track (TileIndex tile, Owner old_owner, Owner new_owner)
 
int TicksToLeaveDepot (const Train *v)
 Compute number of ticks when next wagon will leave a depot. More...
 
static VehicleEnterTileStatus VehicleEnter_Track (Vehicle *u, TileIndex tile, int x, int y)
 Tile callback routine when vehicle enters tile. More...
 
static CommandCost TestAutoslopeOnRailTile (TileIndex tile, uint flags, int z_old, Slope tileh_old, int z_new, Slope tileh_new, TrackBits rail_bits)
 Tests if autoslope is allowed. More...
 
static VehicleEnsureNoShipProc (Vehicle *v, void *data)
 Test-procedure for HasVehicleOnPos to check for a ship.
 
static CommandCost TerraformTile_Track (TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 

Variables

RailtypeInfo _railtypes [RAILTYPE_END]
 
RailType _sorted_railtypes [RAILTYPE_END]
 
uint8 _sorted_railtypes_size
 
static const byte _track_sloped_sprites [14]
 
static const TrackBits _valid_tracks_without_foundation [15]
 Valid TrackBits on a specific (non-steep)-slope without foundation. More...
 
static const TrackBits _valid_tracks_on_leveled_foundation [15]
 Valid TrackBits on a specific (non-steep)-slope with leveled foundation. More...
 
static const TileIndexDiffC _trackdelta []
 
static uint32 _drawtile_track_palette
 
static FenceOffset _fence_offsets []
 Offsets for drawing fences. More...
 
static const int INF = 1000
 
static const SubSprite _halftile_sub_sprite [4]
 
static const byte _fractcoords_behind [4] = { 0x8F, 0x8, 0x80, 0xF8 }
 
static const byte _fractcoords_enter [4] = { 0x8A, 0x48, 0x84, 0xA8 }
 
static const int8 _deltacoord_leaveoffset [8]
 
const TileTypeProcs _tile_type_rail_procs
 

Detailed Description

Handling of rail tiles.

Definition in file rail_cmd.cpp.

Enumeration Type Documentation

◆ SignalOffsets

Enum holding the signal offset in the sprite sheet according to the side it is representing.

Definition at line 51 of file rail_cmd.cpp.

Function Documentation

◆ CheckRailSlope()

static CommandCost CheckRailSlope ( Slope  tileh,
TrackBits  rail_bits,
TrackBits  existing,
TileIndex  tile 
)
static

Tests if a track can be build on a tile.

Parameters
tilehTile slope.
rail_bitsTracks to build.
existingTracks already built.
tileTile (used for water test)
Returns
Error message or cost for foundation building.

Definition at line 408 of file rail_cmd.cpp.

References _settings_game, _valid_tracks_on_leveled_foundation, ConstructionSettings::build_on_slopes, GameSettings::construction, EXPENSES_CONSTRUCTION, FLOOD_NONE, FOUNDATION_INVALID, FOUNDATION_NONE, GetFloodingBehaviour(), GetRailFoundation(), IsSteepSlope(), and return_cmd_error.

Referenced by TestAutoslopeOnRailTile().

◆ CheckTrackCombination()

static CommandCost CheckTrackCombination ( TileIndex  tile,
TrackBits  to_build,
uint  flags 
)
static

Check that the new track bits may be built.

Parameters
tileTile to build on.
to_buildNew track bits.
flagsFlags of the operation.
Returns
Succeeded or failed command.

Definition at line 249 of file rail_cmd.cpp.

References DC_NO_RAIL_OVERLAP, GetTrackBits(), HasSignals(), IsPlainRail(), return_cmd_error, TRACK_BIT_HORZ, and TRACK_BIT_VERT.

◆ CmdBuildRailroadTrack()

CommandCost CmdBuildRailroadTrack ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build rail on a stretch of track.

Stub for the unified rail builder/remover

Parameters
tilestart tile of drag
flagsoperation to perform
p1end tile of drag
p2various bitstuffed elements
  • p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
  • p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
  • p2 = (bit 7) - 0 = build, 1 = remove tracks
textunused
Returns
the cost of this operation or an error
See also
CmdRailTrackHelper

Definition at line 924 of file rail_cmd.cpp.

References ClrBit(), and CmdRailTrackHelper().

◆ CmdBuildSignalTrack()

CommandCost CmdBuildSignalTrack ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build signals on a stretch of track.

Stub for the unified signal builder/remover

Parameters
tilestart tile of drag
flagsoperation to perform
p1end tile of drag
p2various bitstuffed elements
  • p2 = (bit 0- 2) - track-orientation, valid values: 0-5 (Track enum)
  • p2 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
  • p2 = (bit 4) - 0 = signals, 1 = semaphores
  • p2 = (bit 5) - 0 = build, 1 = remove signals
  • p2 = (bit 6) - 0 = selected stretch, 1 = auto fill
  • p2 = (bit 7- 9) - default signal type
  • p2 = (bit 24-31) - user defined signals_density
textunused
Returns
the cost of this operation or an error
See also
CmdSignalTrackHelper

Definition at line 1428 of file rail_cmd.cpp.

References CmdSignalTrackHelper().

◆ CmdBuildSingleRail()

CommandCost CmdBuildSingleRail ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build a single piece of rail.

Parameters
tiletile to build on
flagsoperation to perform
p1railtype of being built piece (normal, mono, maglev)
p2rail track to build
textunused
Returns
the cost of this operation or an error

Definition at line 442 of file rail_cmd.cpp.

References EXPENSES_CONSTRUCTION, and ValParamRailtype().

◆ CmdBuildSingleSignal()

CommandCost CmdBuildSingleSignal ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build signals, alternate between double/single, signal/semaphore, pre/exit/combo-signals, and what-else not.

If the rail piece does not have any signals, bit 4 (cycle signal-type) is ignored

Parameters
tiletile where to build the signals
flagsoperation to perform
p1various bitstuffed elements
  • p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
  • p1 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal or (for bit 7) toggle variant (CTRL-toggle)
  • p1 = (bit 4) - 0 = signals, 1 = semaphores
  • p1 = (bit 5-7) - type of the signal, for valid values see enum SignalType in rail_map.h
  • p1 = (bit 8) - convert the present signal type and variant
  • p1 = (bit 9-11)- start cycle from this signal type
  • p1 = (bit 12-14)-wrap around after this signal type
  • p1 = (bit 15-16)-cycle the signal direction this many times
  • p1 = (bit 17) - 1 = don't modify an existing signal but don't fail either, 0 = always set new signal type
p2used for CmdBuildManySignals() to copy direction of first signal
textunused
Returns
the cost of this operation or an error
Todo:
p2 should be replaced by two bits for "along" and "against" the track.

Definition at line 1032 of file rail_cmd.cpp.

References GB(), HasBit(), SIG_ELECTRIC, and SIG_SEMAPHORE.

◆ CmdBuildTrainDepot()

CommandCost CmdBuildTrainDepot ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build a train depot.

Parameters
tileposition of the train depot
flagsoperation to perform
p1rail type
p2bit 0..1 entrance direction (DiagDirection)
textunused
Returns
the cost of this operation or an error
Todo:
When checking for the tile slope, distinguish between "Flat land required" and "land sloped in wrong direction"

Definition at line 960 of file rail_cmd.cpp.

References _date, _settings_game, Depot::build_date, ConstructionSettings::build_on_slopes, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_depot_pool >::CanAllocateItem(), CanBuildDepotByTileh(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, GameSettings::construction, DC_EXEC, DoCommand(), CommandCost::Failed(), GetTileSlope(), IsBridgeAbove(), return_cmd_error, SLOPE_FLAT, and ValParamRailtype().

◆ CmdConvertRail()

CommandCost CmdConvertRail ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Convert one rail type to the other.

You can convert normal rail to monorail/maglev easily or vice-versa.

Parameters
tileend tile of rail conversion drag
flagsoperation to perform
p1start tile of drag
p2various bitstuffed elements:
  • p2 = (bit 0- 3) new railtype to convert to.
  • p2 = (bit 4) build diagonally or not.
textunused
Returns
the cost of this operation or an error

Definition at line 1548 of file rail_cmd.cpp.

References _settings_game, CommandCost::AddCost(), SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), CCF_TRACK, CheckTileOwnership(), CMD_ERROR, CountBits(), DC_EXEC, DiagDirToDiagTrack(), DirtyCompanyInfrastructureWindows(), VehicleSettings::disable_elrails, SmallVector< T, S >::End(), EnsureNoTrainOnTrackBits(), EnsureNoVehicleOnGround(), error(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), FindVehicleOnPos(), FreeTrainTrackReservation(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), CommandCost::GetCost(), GetCrossingRailTrack(), GetOtherTunnelBridgeEnd(), GetRailDepotTrack(), GetRailStationTrack(), GetRailTileType(), GetRailType(), GetReservedTrackbits(), GetTileOwner(), GetTileType(), GetTrackBits(), GetTrainForReservation(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasBit(), HasPowerOnRail(), HasStationRail(), HasTunnelBridgeReservation(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Company::infrastructure, INVALID_TILE, INVALID_TRACK, InvalidateWindowData(), IsBridge(), IsCompatibleRail(), IsLevelCrossing(), IsLevelCrossingTile(), IsPlainRailTile(), IsRailStationTile(), IsStationTileBlocked(), SmallVector< T, S >::Length(), LEVELCROSSING_TRACKBIT_FACTOR, CommandCost::MakeError(), MapSize(), MarkBridgeDirty(), MarkTileDirtyByTile(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, CompanyInfrastructure::rail, RAIL_TILE_DEPOT, RailConvertCost(), RailNoLevelCrossings(), RAILTYPE_ELECTRIC, RAILTYPE_RAIL, RemoveFirstTrack(), SetRailType(), TRACK_BIT_NONE, TracksOverlap(), TRANSPORT_RAIL, TryPathReserve(), TUNNELBRIDGE_TRACKBIT_FACTOR, TunnelBridgeIsFree(), UpdateTrainPowerProc(), ValParamRailtype(), GameSettings::vehicle, WC_BUILD_VEHICLE, WC_VEHICLE_DEPOT, and YapfNotifyTrackLayoutChange().

◆ CmdRailTrackHelper()

static CommandCost CmdRailTrackHelper ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)
static

Build or remove a stretch of railroad tracks.

Parameters
tilestart tile of drag
flagsoperation to perform
p1end tile of drag
p2various bitstuffed elements
  • p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building
  • p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
  • p2 = (bit 7) - 0 = build, 1 = remove tracks
  • p2 = (bit 8) - 0 = build up to an obstacle, 1 = fail if an obstacle is found (used for AIs).
textunused
Returns
the cost of this operation or an error

Definition at line 864 of file rail_cmd.cpp.

References EXPENSES_CONSTRUCTION, HasBit(), and ValParamRailtype().

Referenced by CmdBuildRailroadTrack(), and CmdRemoveRailroadTrack().

◆ CmdRemoveRailroadTrack()

CommandCost CmdRemoveRailroadTrack ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build rail on a stretch of track.

Stub for the unified rail builder/remover

Parameters
tilestart tile of drag
flagsoperation to perform
p1end tile of drag
p2various bitstuffed elements
  • p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building
  • p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
  • p2 = (bit 7) - 0 = build, 1 = remove tracks
textunused
Returns
the cost of this operation or an error
See also
CmdRailTrackHelper

Definition at line 943 of file rail_cmd.cpp.

References CmdRailTrackHelper(), and SetBit().

◆ CmdRemoveSignalTrack()

CommandCost CmdRemoveSignalTrack ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Remove signals on a stretch of track.

Stub for the unified signal builder/remover

Parameters
tilestart tile of drag
flagsoperation to perform
p1end tile of drag
p2various bitstuffed elements
  • p2 = (bit 0- 2) - track-orientation, valid values: 0-5 (Track enum)
  • p2 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
  • p2 = (bit 4) - 0 = signals, 1 = semaphores
  • p2 = (bit 5) - 0 = build, 1 = remove signals
  • p2 = (bit 6) - 0 = selected stretch, 1 = auto fill
  • p2 = (bit 7- 9) - default signal type
  • p2 = (bit 24-31) - user defined signals_density
textunused
Returns
the cost of this operation or an error
See also
CmdSignalTrackHelper

Definition at line 1520 of file rail_cmd.cpp.

References CmdSignalTrackHelper(), and SetBit().

◆ CmdRemoveSingleRail()

CommandCost CmdRemoveSingleRail ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Remove a single piece of track.

Parameters
tiletile to remove track from
flagsoperation to perform
p1unused
p2rail orientation
textunused
Returns
the cost of this operation or an error

Definition at line 606 of file rail_cmd.cpp.

References EXPENSES_CONSTRUCTION.

◆ CmdRemoveSingleSignal()

CommandCost CmdRemoveSingleSignal ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Remove signals.

Parameters
tilecoordinates where signal is being deleted from
flagsoperation to perform
p1various bitstuffed elements, only track information is used
  • (bit 0- 2) - track-orientation, valid values: 0-5 (Track enum)
  • (bit 3) - override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
  • (bit 4) - 0 = signals, 1 = semaphores
p2unused
textunused
Returns
the cost of this operation or an error

Definition at line 1445 of file rail_cmd.cpp.

◆ CmdSignalTrackHelper()

static CommandCost CmdSignalTrackHelper ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)
static

Build many signals by dragging; AutoSignals.

Parameters
tilestart tile of drag
flagsoperation to perform
p1end tile of drag
p2various bitstuffed elements
  • p2 = (bit 0- 2) - track-orientation, valid values: 0-5 (Track enum)
  • p2 = (bit 3) - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
  • p2 = (bit 4) - 0 = signals, 1 = semaphores
  • p2 = (bit 5) - 0 = build, 1 = remove signals
  • p2 = (bit 6) - 0 = selected stretch, 1 = auto fill
  • p2 = (bit 7- 9) - default signal type
  • p2 = (bit 10) - 0 = keep fixed distance, 1 = minimise gaps between signals
  • p2 = (bit 24-31) - user defined signals_density
textunused
Returns
the cost of this operation or an error

Definition at line 1258 of file rail_cmd.cpp.

References EXPENSES_CONSTRUCTION, GB(), HasBit(), and MapSize().

Referenced by CmdBuildSignalTrack(), and CmdRemoveSignalTrack().

◆ CompareRailTypes()

static int CDECL CompareRailTypes ( const RailType first,
const RailType second 
)
static

Compare railtypes based on their sorting order.

Parameters
firstThe railtype to compare to.
secondThe railtype to compare.
Returns
True iff the first should be sorted before the second.

Definition at line 130 of file rail_cmd.cpp.

References GetRailTypeInfo(), and RailtypeInfo::sorting_order.

◆ DrawTrackBits()

static void DrawTrackBits ( TileInfo ti,
TrackBits  track 
)
static

Draw ground sprite and track bits.

Parameters
tiTileInfo
trackTrackBits to draw

Definition at line 2216 of file rail_cmd.cpp.

References GetRailType(), GetRailTypeInfo(), and TileInfo::tile.

◆ DrawTrackDetails()

static void DrawTrackDetails ( const TileInfo ti,
const RailtypeInfo rti 
)
static

Draw track fences.

Parameters
tiTile drawing information.
rtiRail type information.

Definition at line 2002 of file rail_cmd.cpp.

References GetCustomRailSprite(), IsHalftileSlope(), RTSG_FENCES, TCX_NORMAL, TCX_UPPER_HALFTILE, TileInfo::tile, and TileInfo::tileh.

◆ DrawTrackFence()

static void DrawTrackFence ( const TileInfo ti,
SpriteID  base_image,
uint  num_sprites,
RailFenceOffset  rfo 
)
static

Draw a track fence.

Parameters
tiTile drawing information.
base_imageFirst fence sprite.
num_spritesNumber of fence sprites.
rfoFence to draw.

Definition at line 1943 of file rail_cmd.cpp.

References FenceOffset::height_ref, and TileInfo::z.

Referenced by DrawTrackFence_NE(), DrawTrackFence_NW(), DrawTrackFence_SE(), and DrawTrackFence_SW().

◆ EnsureNoTrainOnTrack()

static CommandCost EnsureNoTrainOnTrack ( TileIndex  tile,
Track  track 
)
static

Tests if a vehicle interacts with the specified track.

All track bits interact except parallel TRACK_BIT_HORZ or TRACK_BIT_VERT.

Parameters
tileThe tile.
trackThe track.
Returns
Succeeded command (no train found), or a failed command (a train was found).

Definition at line 236 of file rail_cmd.cpp.

References EnsureNoTrainOnTrackBits(), and TrackToTrackBits().

◆ FloodHalftile()

bool FloodHalftile ( TileIndex  t)

Called from water_cmd if a non-flat rail-tile gets flooded and should be converted to shore.

The function floods the lower halftile, if the tile has a halftile foundation.

Parameters
tThe tile to flood.
Returns
true if something was flooded.

Definition at line 749 of file rail_cmd.cpp.

◆ GetRailFoundation()

Foundation GetRailFoundation ( Slope  tileh,
TrackBits  bits 
)

Checks if a track combination is valid on a specific slope and returns the needed foundation.

Parameters
tilehTile slope.
bitsTrackbits.
Returns
Needed foundation or FOUNDATION_INVALID if track/slope combination is not allowed.

Definition at line 328 of file rail_cmd.cpp.

References _valid_tracks_on_leveled_foundation, _valid_tracks_without_foundation, CornerToTrackBits(), FOUNDATION_INCLINED_X, FOUNDATION_INCLINED_Y, FOUNDATION_INVALID, FOUNDATION_NONE, FOUNDATION_STEEP_BOTH, FOUNDATION_STEEP_LOWER, GetHighestSlopeCorner(), HalftileFoundation(), IsSteepSlope(), TRACK_BIT_LEFT, TRACK_BIT_NONE, TRACK_BIT_X, TRACK_BIT_Y, and TracksOverlap().

Referenced by CheckRailSlope(), and TestAutoslopeOnRailTile().

◆ GetSaveSlopeZ()

static uint GetSaveSlopeZ ( uint  x,
uint  y,
Track  track 
)
static

Get surface height in point (x,y) On tiles with halftile foundations move (x,y) to a safe point wrt.

track

Definition at line 1851 of file rail_cmd.cpp.

◆ TestAutoslopeOnRailTile()

static CommandCost TestAutoslopeOnRailTile ( TileIndex  tile,
uint  flags,
int  z_old,
Slope  tileh_old,
int  z_new,
Slope  tileh_new,
TrackBits  rail_bits 
)
static

Tests if autoslope is allowed.

Parameters
tileThe tile.
flagsTerraform command flags.
z_oldOld TileZ.
tileh_oldOld TileSlope.
z_newNew TileZ.
tileh_newNew TileSlope.
rail_bitsTrackbits.

Definition at line 2969 of file rail_cmd.cpp.

References _settings_game, ApplyFoundationToSlope(), AutoslopeEnabled(), ConstructionSettings::build_on_slopes, CheckRailSlope(), GameSettings::construction, GetRailFoundation(), return_cmd_error, TRACK_BIT_LEFT, and TRACK_BIT_NONE.

◆ TicksToLeaveDepot()

int TicksToLeaveDepot ( const Train v)

Compute number of ticks when next wagon will leave a depot.

Negative means next wagon should have left depot n ticks before.

Parameters
vvehicle outside (leaving) the depot
Returns
number of ticks when the next wagon will leave

Definition at line 2889 of file rail_cmd.cpp.

References Train::CalcNextVehicleOffset(), DIAGDIR_NE, GetRailDepotDirection(), Vehicle::tile, and Vehicle::x_pos.

Referenced by AdvanceWagonsAfterSwap().

◆ VehicleEnter_Track()

static VehicleEnterTileStatus VehicleEnter_Track ( Vehicle u,
TileIndex  tile,
int  x,
int  y 
)
static

Tile callback routine when vehicle enters tile.

See also
vehicle_enter_tile_proc

Definition at line 2909 of file rail_cmd.cpp.

Variable Documentation

◆ _deltacoord_leaveoffset

const int8 _deltacoord_leaveoffset[8]
static
Initial value:
= {
-1, 0, 1, 0,
0, 1, 0, -1
}

Definition at line 2877 of file rail_cmd.cpp.

◆ _fence_offsets

FenceOffset _fence_offsets[]
static
Initial value:
= {
{ CORNER_INVALID, 0, 1, 16, 1 },
{ CORNER_INVALID, 1, 0, 1, 16 },
{ CORNER_W, 8, 8, 1, 1 },
{ CORNER_N, 8, 8, 1, 1 },
{ CORNER_INVALID, 0, 1, 16, 1 },
{ CORNER_INVALID, 1, 0, 1, 16 },
{ CORNER_INVALID, 0, 1, 16, 1 },
{ CORNER_INVALID, 1, 0, 1, 16 },
{ CORNER_INVALID, 0, 15, 16, 1 },
{ CORNER_INVALID, 15, 0, 1, 16 },
{ CORNER_E, 8, 8, 1, 1 },
{ CORNER_S, 8, 8, 1, 1 },
{ CORNER_INVALID, 0, 15, 16, 1 },
{ CORNER_INVALID, 15, 0, 1, 16 },
{ CORNER_INVALID, 0, 15, 16, 1 },
{ CORNER_INVALID, 15, 0, 1, 16 },
}

Offsets for drawing fences.

Definition at line 1917 of file rail_cmd.cpp.

◆ _halftile_sub_sprite

const SubSprite _halftile_sub_sprite[4]
static
Initial value:
= {
{ -INF , -INF , 32 - 33, INF },
{ -INF , 0 + 7, INF , INF },
{ -31 + 33, -INF , INF , INF },
{ -INF , -INF , INF , 30 - 23 }
}

Definition at line 2052 of file rail_cmd.cpp.

◆ _tile_type_rail_procs

const TileTypeProcs _tile_type_rail_procs
Initial value:
= {
DrawTile_Track,
GetSlopePixelZ_Track,
ClearTile_Track,
NULL,
GetTileDesc_Track,
GetTileTrackStatus_Track,
ClickTile_Track,
NULL,
TileLoop_Track,
ChangeTileOwner_Track,
NULL,
GetFoundation_Track,
TerraformTile_Track,
}
static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int x, int y)
Tile callback routine when vehicle enters tile.
Definition: rail_cmd.cpp:2909

◆ _track_sloped_sprites

const byte _track_sloped_sprites[14]
static
Initial value:
= {
14, 15, 22, 13,
0, 21, 17, 12,
23, 0, 18, 20,
19, 16
}

Definition at line 189 of file rail_cmd.cpp.

◆ _trackdelta

const TileIndexDiffC _trackdelta[]
static
Initial value:
= {
{ -1, 0 }, { 0, 1 }, { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, 1 },
{ 0, 0 },
{ 0, 0 },
{ 1, 0 }, { 0, -1 }, { 0, -1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
{ 0, 0 },
{ 0, 0 }
}

Definition at line 794 of file rail_cmd.cpp.

◆ _valid_tracks_on_leveled_foundation

const TrackBits _valid_tracks_on_leveled_foundation[15]
static
Initial value:
= {
TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
TRACK_BIT_ALL
}
Right track.
Definition: track_type.h:48
All possible tracks.
Definition: track_type.h:56
X-axis track.
Definition: track_type.h:43
Lower track.
Definition: track_type.h:46
Upper track.
Definition: track_type.h:45
Left track.
Definition: track_type.h:47
No track.
Definition: track_type.h:42
Y-axis track.
Definition: track_type.h:44

Valid TrackBits on a specific (non-steep)-slope with leveled foundation.

Definition at line 300 of file rail_cmd.cpp.

Referenced by CheckRailSlope(), and GetRailFoundation().

◆ _valid_tracks_without_foundation

const TrackBits _valid_tracks_without_foundation[15]
static
Initial value:

Valid TrackBits on a specific (non-steep)-slope without foundation.

Definition at line 278 of file rail_cmd.cpp.

Referenced by GetRailFoundation().