OpenTTD Source: src/rail_cmd.h File Reference

OpenTTD Source 15.0-RC2

Functions | Variables
rail_cmd.h File Reference

Command definitions for rail. More...

`#include "command_type.h"`
`#include "track_type.h"`
`#include "direction_type.h"`
`#include "rail_type.h"`
`#include "signal_type.h"`

Go to the source code of this file.

## Functions
CommandCost | CmdBuildRailroadTrack (DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, RailType railtype, Track track, bool auto_remove_signals, bool fail_on_obstacle)
| Build rail on a stretch of track.
CommandCost | CmdRemoveRailroadTrack (DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, Track track)
| Build rail on a stretch of track.
CommandCost | CmdBuildSingleRail (DoCommandFlags flags, TileIndex tile, RailType railtype, Track track, bool auto_remove_signals)
| Build a single piece of rail.
CommandCost | CmdRemoveSingleRail (DoCommandFlags flags, TileIndex tile, Track track)
| Remove a single piece of track.
CommandCost | CmdBuildTrainDepot (DoCommandFlags flags, TileIndex tile, RailType railtype, DiagDirection dir)
| Build a train depot.
CommandCost | CmdBuildSingleSignal (DoCommandFlags flags, TileIndex tile, Track track, SignalType sigtype, SignalVariant sigvar, bool convert_signal, bool skip_existing_signals, bool ctrl_pressed, SignalType cycle_start, SignalType cycle_stop, uint8_t num_dir_cycle, uint8_t signals_copy)
| Build signals, alternate between double/single, signal/semaphore, pre/exit/combo-signals, and what-else not.
CommandCost | CmdRemoveSingleSignal (DoCommandFlags flags, TileIndex tile, Track track)
| Remove signals.
CommandCost | CmdConvertRail (DoCommandFlags flags, TileIndex tile, TileIndex area_start, RailType totype, bool diagonal)
| Convert one rail type to the other.
CommandCost | CmdBuildSignalTrack (DoCommandFlags flags, TileIndex tile, TileIndex end_tile, Track track, SignalType sigtype, SignalVariant sigvar, bool mode, bool autofill, bool minimise_gaps, uint8_t signal_density)
| Build signals on a stretch of track.
CommandCost | CmdRemoveSignalTrack (DoCommandFlags flags, TileIndex tile, TileIndex end_tile, Track track, bool autofill)
| Remove signals on a stretch of track.
void | CcRailDepot (Commands cmd, const CommandCost &result, TileIndex tile, RailType rt, DiagDirection dir)

## Variables
CommandCallback | CcPlaySound_CONSTRUCTION_RAIL
CommandCallback | CcStation
CommandCallback | CcBuildRailTunnel

## Detailed Description

Command definitions for rail.

Definition in file rail_cmd.h.

## Function Documentation

## ◆ CcRailDepot()

void CcRailDepot | ( | Commands | cmd,
|  | const CommandCost & | result,
|  | TileIndex | tile,
|  | RailType | rt,
|  | DiagDirection | dir
| ) |  |

Definition at line 143 of file rail_gui.cpp.

## ◆ CmdBuildRailroadTrack()

CommandCost CmdBuildRailroadTrack | ( | DoCommandFlags | flags,
|  | TileIndex | end_tile,
|  | TileIndex | start_tile,
|  | RailType | railtype,
|  | Track | track,
|  | bool | auto_remove_signals,
|  | bool | fail_on_obstacle
| ) |  |

Build rail on a stretch of track.

Stub for the unified rail builder/remover

Parameters

  flags | operation to perform
  end_tile | end tile of drag
  start_tile | start tile of drag
  railtype | railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building
  track | track-orientation
  auto_remove_signals | false = build up to an obstacle, true = fail if an obstacle is found (used for AIs).
  fail_on_obstacle | false = error on signal in the way, true = auto remove signals when in the way

See also
  CmdRailTrackHelper

Definition at line 930 of file rail_cmd.cpp.

References CmdRailTrackHelper().

## ◆ CmdBuildSignalTrack()

CommandCost CmdBuildSignalTrack | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | TileIndex | end_tile,
|  | Track | track,
|  | SignalType | sigtype,
|  | SignalVariant | sigvar,
|  | bool | mode,
|  | bool | autofill,
|  | bool | minimise_gaps,
|  | uint8_t | signal_density
| ) |  |

Build signals on a stretch of track.

Stub for the unified signal builder/remover

Parameters

  flags | operation to perform
  tile | start tile of drag
  end_tile | end tile of drag
  track | track-orientation
  sigtype | default signal type
  sigvar | signal variant to build
  mode | true = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
  autofill | fill beyond selected stretch?
  minimise_gaps | false = keep fixed distance, true = minimise gaps between signals
  signal_density | user defined signals_density

Returns
  the cost of this operation or an error

See also
  CmdSignalTrackHelper

Definition at line 1446 of file rail_cmd.cpp.

References CmdSignalTrackHelper().

## ◆ CmdBuildSingleRail()

CommandCost CmdBuildSingleRail | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | RailType | railtype,
|  | Track | track,
|  | bool | auto_remove_signals
| ) |  |

Build a single piece of rail.

Parameters

  flags | operation to perform
  tile | tile to build on
  railtype | railtype of being built piece (normal, mono, maglev)
  track | track-orientation
  auto_remove_signals | false = error on signal in the way, true = auto remove signals when in the way

Returns
  the cost of this operation or an error

Definition at line 423 of file rail_cmd.cpp.

References _current_company, _settings_game, CommandCost::AddCost(), AddTrackToSignalBuffer(), AXIS_X, AXIS_Y, Barren, CheckForDockingTile(), CheckOwnership(), CheckRailSlope(), CheckTileOwnership(), CheckTrackCombination(), CMD_ERROR, GameSettings::construction, CountBits(), ConstructionSettings::crossing_with_competitor, DirtyCompanyInfrastructureWindows(), DRD_NONE, EnsureNoTrainOnTrack(), EnsureNoVehicleOnGround(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), CommandCost::GetCost(), GetCrossingRailBits(), GetCrossingRoadAxis(), GetDisallowedRoadDirections(), GetRailType(), GetRoadBits(), GetRoadOwner(), GetTileOwner(), GetTileSlope(), GetTileType(), GetTownIndex(), GetTrackBits(), HalfTileWater, HasBit(), HasExactlyOneBit(), HasPowerOnRail(), HasRoadWorks(), HasSignalOnTrack(), HasSignals(), HasTrack(), INVALID_ROADTYPE, IsCompatibleRail(), IsLevelCrossing(), IsNormalRoad(), IsPlainRail(), IsSlopeWithOneCornerRaised(), IsTileType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), LEVELCROSSING_TRACKBIT_FACTOR, MakeRoadCrossing(), MarkDirtyAdjacentLevelCrossingTiles(), MarkTileDirtyByTile(), MP_RAILWAY, MP_ROAD, MP_WATER, OWNER_DEITY, RailBuildCost(), RailNoLevelCrossings(), ROAD_NONE, ROAD_X, ROAD_Y, RoadBuildCost(), RoadNoLevelCrossing(), RTT_ROAD, RTT_TRAM, SetTrackBits(), CommandCost::Succeeded(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TRACK_BEGIN, TRACK_BIT_NONE, TRACK_END, TRACK_X, TRACK_Y, TracksOverlap(), TrackToTrackBits(), UpdateLevelCrossing(), VALID_LEVEL_CROSSING_SLOPES, ValParamRailType(), and YapfNotifyTrackLayoutChange().

## ◆ CmdBuildSingleSignal()

CommandCost CmdBuildSingleSignal | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | Track | track,
|  | SignalType | sigtype,
|  | SignalVariant | sigvar,
|  | bool | convert_signal,
|  | bool | skip_existing_signals,
|  | bool | ctrl_pressed,
|  | SignalType | cycle_start,
|  | SignalType | cycle_stop,
|  | uint8_t | num_dir_cycle,
|  | uint8_t | signals_copy
| ) |  |

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, signal cycling is ignored

Parameters

  flags | operation to perform
  tile | tile where to build the signals
  track | track-orientation
  sigtype | type of the signal
  sigvar | variant of signal type (normal/semaphore)
  ctrl_pressed | true = override signal/semaphore, or pre/exit/combo signal or toggle variant (CTRL-toggle)
  convert_signal | convert the present signal type and variant
  cycle_start | start cycle from this signal type
  cycle_stop | wrap around after this signal type
  num_dir_cycle | cycle the signal direction this many times
  skip_existing_signals | true = don't modify an existing signal but don't fail either, false = always set new signal type
  signals_copy | used for CmdBuildManySignals() to copy direction of first signal

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 1049 of file rail_cmd.cpp.

References _current_company, _settings_game, AddTrackToSignalBuffer(), CheckTileOwnership(), CMD_ERROR, CountBits(), Vehicle::cur_speed, Vehicle::current_order, DirtyCompanyInfrastructureWindows(), EnsureNoVehicleOnGround(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), PathfinderSettings::forbid_90_deg, FreeTrainTrackReservation(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetPresentSignals(), GetRailReservationTrackBits(), GetSignalStates(), GetTileOwner(), GetTrackBits(), GetTrainForReservation(), Train::GetVehicleTrackdir(), HasBit(), HasReservedTracks(), HasSignalOnTrack(), HasSignals(), HasTrack(), IsPlainRailTile(), IsSafeWaitingPosition(), Order::IsType(), KillFirstBit(), MarkTileDirtyByTile(), GameSettings::pf, SetHasSignals(), SetPresentSignals(), SetSignalStates(), SIG_ELECTRIC, SIG_SEMAPHORE, SignalOnTrack(), Stopped, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tile, TRACK_BIT_DEPOT, TracksOverlap(), TrackToTrackBits(), TryPathReserve(), Vehicle::vehstatus, and YapfNotifyTrackLayoutChange().

## ◆ CmdBuildTrainDepot()

CommandCost CmdBuildTrainDepot | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | RailType | railtype,
|  | DiagDirection | dir
| ) |  |

Build a train depot.

Parameters

  flags | operation to perform
  tile | position of the train depot
  railtype | rail type
  dir | entrance direction

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 961 of file rail_cmd.cpp.

References _current_company, _settings_game, CommandCost::AddCost(), AddSideToSignalBuffer(), ConstructionSettings::build_on_slopes, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_depot_pool >::CanAllocateItem(), CanBuildDepotByTileh(), CheckTileOwnership(), CMD_ERROR, GameSettings::construction, DiagDirToDiagTrack(), DirtyCompanyInfrastructureWindows(), EnsureNoVehicleOnGround(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetRailDepotDirection(), GetRailType(), GetTileSlope(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, INVALID_DIAGDIR, IsBridgeAbove(), IsRailDepotTile(), IsValidDiagDirection(), MakeDefaultName(), MakeRailDepot(), MarkTileDirtyByTile(), RailBuildCost(), SetRailDepotExitDirection(), SLOPE_FLAT, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), ValParamRailType(), and YapfNotifyTrackLayoutChange().

## ◆ CmdConvertRail()

CommandCost CmdConvertRail | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | TileIndex | area_start,
|  | RailType | totype,
|  | bool | diagonal
| ) |  |

Convert one rail type to the other.

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

Parameters

  flags | operation to perform
  tile | end tile of rail conversion drag
  area_start | start tile of drag
  totype | new railtype to convert to.
  diagonal | build diagonally or not.

Returns
  the cost of this operation or an error

Definition at line 1539 of file rail_cmd.cpp.

References _settings_game, CommandCost::AddCost(), CCF_TRACK, CheckTileOwnership(), CMD_ERROR, CountBits(), TileIterator::Create(), Depot, DiagDirToDiagTrack(), DirtyCompanyInfrastructureWindows(), VehicleSettings::disable_elrails, EnsureNoTrainOnTrackBits(), EnsureNoVehicleOnGround(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), FreeTrainTrackReservation(), SpecializedVehicle< T, Type >::From(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetCrossingRailTrack(), GetOtherTunnelBridgeEnd(), GetRailDepotTrack(), GetRailStationTrack(), GetRailTileType(), GetRailType(), GetReservedTrackbits(), GetTileOwner(), GetTileType(), GetTrackBits(), GetTrainForReservation(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasPowerOnRail(), HasStationRail(), HasTunnelBridgeReservation(), include(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Company::infrastructure, INVALID_TILE, INVALID_TRACK, InvalidateWindowData(), IsBridge(), IsCompatibleRail(), IsLevelCrossing(), IsLevelCrossingTile(), IsPlainRailTile(), IsRailStationTile(), IsStationTileBlocked(), LEVELCROSSING_TRACKBIT_FACTOR, CommandCost::MakeError(), MarkBridgeDirty(), MarkTileDirtyByTile(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, CompanyInfrastructure::rail, RailConvertCost(), RailNoLevelCrossings(), RAILTYPE_ELECTRIC, RAILTYPE_RAIL, RemoveFirstTrack(), SetRailType(), Map::Size(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TRACK_BIT_NONE, TracksOverlap(), TRANSPORT_RAIL, TryPathReserve(), TUNNELBRIDGE_TRACKBIT_FACTOR, TunnelBridgeIsFree(), ValParamRailType(), VEH_TRAIN, GameSettings::vehicle, WC_BUILD_VEHICLE, WC_VEHICLE_DEPOT, and YapfNotifyTrackLayoutChange().

## ◆ CmdRemoveRailroadTrack()

CommandCost CmdRemoveRailroadTrack | ( | DoCommandFlags | flags,
|  | TileIndex | end_tile,
|  | TileIndex | start_tile,
|  | Track | track
| ) |  |

Build rail on a stretch of track.

Stub for the unified rail builder/remover

Parameters

  flags | operation to perform
  end_tile | end tile of drag
  start_tile | start tile of drag
  track | track-orientation

Returns
  the cost of this operation or an error

See also
  CmdRailTrackHelper

Definition at line 945 of file rail_cmd.cpp.

References CmdRailTrackHelper(), and INVALID_RAILTYPE.

## ◆ CmdRemoveSignalTrack()

CommandCost CmdRemoveSignalTrack | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | TileIndex | end_tile,
|  | Track | track,
|  | bool | autofill
| ) |  |

Remove signals on a stretch of track.

Stub for the unified signal builder/remover

Parameters

  flags | operation to perform
  tile | start tile of drag
  end_tile | end tile of drag
  track | track-orientation
  autofill | fill beyond selected stretch?

Returns
  the cost of this operation or an error

See also
  CmdSignalTrackHelper

Definition at line 1524 of file rail_cmd.cpp.

References CmdSignalTrackHelper(), SIG_ELECTRIC, and SIGTYPE_BLOCK.

## ◆ CmdRemoveSingleRail()

CommandCost CmdRemoveSingleRail | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | Track | track
| ) |  |

Remove a single piece of track.

Parameters

  flags | operation to perform
  tile | tile to remove track from
  track | rail orientation

Returns
  the cost of this operation or an error

Definition at line 612 of file rail_cmd.cpp.

References _current_company, CommandCost::AddCost(), AddTrackToSignalBuffer(), Bankrupt, CheckTileOwnership(), CMD_ERROR, CountBits(), DeleteNewGRFInspectWindow(), DirtyCompanyInfrastructureWindows(), EnsureNoTrainOnTrack(), EnsureNoVehicleOnGround(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), FreeTrainTrackReservation(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetCrossingRailBits(), GetCrossingRoadAxis(), GetCrossingRoadBits(), GetRailReservationTrackBits(), GetRailType(), GetRoadOwner(), GetTileOwner(), GetTileSlope(), GetTileType(), GetTownIndex(), GetTrackBits(), GetTrainForReservation(), HalfTileWater, HasReservedTracks(), HasSignalOnTrack(), INVALID_OWNER, IsDockingTile(), IsLevelCrossing(), IsPlainRail(), IsSlopeWithOneCornerRaised(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), LEVELCROSSING_TRACKBIT_FACTOR, MakeRoadNormal(), MakeShore(), MarkTileDirtyByTile(), MP_RAILWAY, MP_ROAD, OWNER_WATER, RailClearCost(), RTT_ROAD, RTT_TRAM, SetDockingTile(), SetTrackBits(), SetTrackReservation(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TRACK_BIT_X, TRACK_BIT_Y, TRACK_X, TRACK_Y, TracksOverlap(), TrackToTrackBits(), TryPathReserve(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), and YapfNotifyTrackLayoutChange().

## ◆ CmdRemoveSingleSignal()

CommandCost CmdRemoveSingleSignal | ( | DoCommandFlags | flags,
|  | TileIndex | tile,
|  | Track | track
| ) |  |

Remove signals.

Parameters

  flags | operation to perform
  tile | coordinates where signal is being deleted from
  track | track-orientation

Returns
  the cost of this operation or an error

Definition at line 1458 of file rail_cmd.cpp.

References _current_company, AddTrackToSignalBuffer(), CheckTileOwnership(), CountBits(), DirtyCompanyInfrastructureWindows(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetPresentSignals(), GetReservedTrackbits(), GetTileOwner(), GetTrainForReservation(), HasReservedTracks(), HasSignalOnTrack(), HasSignalOnTrackdir(), HasTrack(), INVALID_TRACK, IsPlainRailTile(), MarkTileDirtyByTile(), OWNER_WATER, ReverseTrackdir(), SetHasSignals(), SetPresentSignals(), SetSignalStates(), SIG_ELECTRIC, SignalOnTrack(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileAddByDiagDir(), TrackBitsToTrack(), TrackdirBitsToTrackBits(), TrackdirReachesTrackdirs(), TrackdirToExitdir(), TrackToTrackBits(), TrackToTrackdir(), TryPathReserve(), and YapfNotifyTrackLayoutChange().

## Variable Documentation

## ◆ CcBuildRailTunnel

CommandCallback CcBuildRailTunnel

Definition at line 43 of file rail_cmd.h.

## ◆ CcPlaySound_CONSTRUCTION_RAIL

CommandCallback CcPlaySound_CONSTRUCTION_RAIL

Definition at line 41 of file rail_cmd.h.

## ◆ CcStation

CommandCallback CcStation

Definition at line 42 of file rail_cmd.h.