OpenTTD Game API
Public Types | Static Public Member Functions
GSRail Class Reference

Class that handles all rail related functions. More...

Inheritance diagram for GSRail:

Public Types

enum  ErrorMessages {
  ERR_RAIL_BASE,
  ERR_CROSSING_ON_ONEWAY_ROAD,
  ERR_UNSUITABLE_TRACK,
  ERR_RAILTYPE_DISALLOWS_CROSSING
}
 All rail related error messages. More...
 
enum  RailType { RAILTYPE_INVALID }
 Types of rail known to the game. More...
 
enum  RailTrack {
  RAILTRACK_NE_SW,
  RAILTRACK_NW_SE,
  RAILTRACK_NW_NE,
  RAILTRACK_SW_SE,
  RAILTRACK_NW_SW,
  RAILTRACK_NE_SE,
  RAILTRACK_INVALID
}
 A bitmap with all possible rail tracks on a tile. More...
 
enum  SignalType {
  SIGNALTYPE_NORMAL,
  SIGNALTYPE_ENTRY,
  SIGNALTYPE_EXIT,
  SIGNALTYPE_COMBO,
  SIGNALTYPE_PBS,
  SIGNALTYPE_PBS_ONEWAY,
  SIGNALTYPE_TWOWAY,
  SIGNALTYPE_NORMAL_TWOWAY,
  SIGNALTYPE_ENTRY_TWOWAY,
  SIGNALTYPE_EXIT_TWOWAY,
  SIGNALTYPE_COMBO_TWOWAY,
  SIGNALTYPE_NONE
}
 Types of signal known to the game. More...
 
enum  BuildType {
  BT_TRACK,
  BT_SIGNAL,
  BT_DEPOT,
  BT_STATION,
  BT_WAYPOINT
}
 Types of rail-related objects in the game. More...
 

Static Public Member Functions

static char * GetName (RailType rail_type)
 Get the name of a rail type. More...
 
static bool IsRailTile (TileIndex tile)
 Checks whether the given tile is actually a tile with rail that can be used to traverse a tile. More...
 
static bool IsLevelCrossingTile (TileIndex tile)
 Checks whether there is a road / rail crossing on a tile. More...
 
static bool IsRailDepotTile (TileIndex tile)
 Checks whether the given tile is actually a tile with a rail depot. More...
 
static bool IsRailStationTile (TileIndex tile)
 Checks whether the given tile is actually a tile with a rail station. More...
 
static bool IsRailWaypointTile (TileIndex tile)
 Checks whether the given tile is actually a tile with a rail waypoint. More...
 
static bool IsRailTypeAvailable (RailType rail_type)
 Check if a given RailType is available. More...
 
static RailType GetCurrentRailType ()
 Get the current RailType set for all GSRail functions. More...
 
static void SetCurrentRailType (RailType rail_type)
 Set the RailType for all further GSRail functions. More...
 
static bool TrainCanRunOnRail (GSRail::RailType engine_rail_type, GSRail::RailType track_rail_type)
 Check if a train build for a rail type can run on another rail type. More...
 
static bool TrainHasPowerOnRail (GSRail::RailType engine_rail_type, GSRail::RailType track_rail_type)
 Check if a train build for a rail type has power on another rail type. More...
 
static RailType GetRailType (TileIndex tile)
 Get the RailType that is used on a tile. More...
 
static bool ConvertRailType (TileIndex start_tile, TileIndex end_tile, GSRail::RailType convert_to)
 Convert the tracks on all tiles within a rectangle to another RailType. More...
 
static TileIndex GetRailDepotFrontTile (TileIndex depot)
 Gets the tile in front of a rail depot. More...
 
static RailTrack GetRailStationDirection (TileIndex tile)
 Gets the direction of a rail station tile. More...
 
static bool BuildRailDepot (TileIndex tile, TileIndex front)
 Builds a rail depot. More...
 
static bool BuildRailStation (TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id)
 Build a rail station. More...
 
static bool BuildNewGRFRailStation (TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station)
 Build a NewGRF rail station. More...
 
static bool BuildRailWaypoint (TileIndex tile)
 Build a rail waypoint. More...
 
static bool RemoveRailWaypointTileRectangle (TileIndex tile, TileIndex tile2, bool keep_rail)
 Remove all rail waypoint pieces within a rectangle on the map. More...
 
static bool RemoveRailStationTileRectangle (TileIndex tile, TileIndex tile2, bool keep_rail)
 Remove all rail station platform pieces within a rectangle on the map. More...
 
static uint GetRailTracks (TileIndex tile)
 Get all RailTracks on the given tile. More...
 
static bool BuildRailTrack (TileIndex tile, RailTrack rail_track)
 Build rail on the given tile. More...
 
static bool RemoveRailTrack (TileIndex tile, RailTrack rail_track)
 Remove rail on the given tile. More...
 
static bool AreTilesConnected (TileIndex from, TileIndex tile, TileIndex to)
 Check if a tile connects two adjacent tiles. More...
 
static bool BuildRail (TileIndex from, TileIndex tile, TileIndex to)
 Build a rail connection between two tiles. More...
 
static bool RemoveRail (TileIndex from, TileIndex tile, TileIndex to)
 Remove a rail connection between two tiles. More...
 
static SignalType GetSignalType (TileIndex tile, TileIndex front)
 Get the SignalType of the signal on a tile or SIGNALTYPE_NONE if there is no signal. More...
 
static bool BuildSignal (TileIndex tile, TileIndex front, SignalType signal)
 Build a signal on a tile. More...
 
static bool RemoveSignal (TileIndex tile, TileIndex front)
 Remove a signal. More...
 
static Money GetBuildCost (RailType railtype, BuildType build_type)
 Get the baseprice of building a rail-related object. More...
 
static int32 GetMaxSpeed (RailType railtype)
 Get the maximum speed of trains running on this railtype. More...
 
static uint16 GetMaintenanceCostFactor (RailType railtype)
 Get the maintenance cost factor of a railtype. More...
 

Detailed Description

Class that handles all rail related functions.

Member Enumeration Documentation

◆ BuildType

Types of rail-related objects in the game.

Enumerator
BT_TRACK 

Build a track.

BT_SIGNAL 

Build a signal.

BT_DEPOT 

Build a depot.

BT_STATION 

Build a station.

BT_WAYPOINT 

Build a rail waypoint.

◆ ErrorMessages

All rail related error messages.

Enumerator
ERR_RAIL_BASE 

Base for rail building / maintaining errors.

ERR_CROSSING_ON_ONEWAY_ROAD 

One-way roads cannot have crossings.

ERR_UNSUITABLE_TRACK 

No suitable track could be found.

ERR_RAILTYPE_DISALLOWS_CROSSING 

This railtype cannot have crossings.

◆ RailTrack

A bitmap with all possible rail tracks on a tile.

Enumerator
RAILTRACK_NE_SW 

Track along the x-axis (north-east to south-west).

RAILTRACK_NW_SE 

Track along the y-axis (north-west to south-east).

RAILTRACK_NW_NE 

Track in the upper corner of the tile (north).

RAILTRACK_SW_SE 

Track in the lower corner of the tile (south).

RAILTRACK_NW_SW 

Track in the left corner of the tile (west).

RAILTRACK_NE_SE 

Track in the right corner of the tile (east).

RAILTRACK_INVALID 

Flag for an invalid track.

◆ RailType

Types of rail known to the game.

Enumerator
RAILTYPE_INVALID 

Invalid RailType.

◆ SignalType

Types of signal known to the game.

Enumerator
SIGNALTYPE_NORMAL 

Normal signal.

SIGNALTYPE_ENTRY 

Entry presignal.

SIGNALTYPE_EXIT 

Exit signal.

SIGNALTYPE_COMBO 

Combo signal.

SIGNALTYPE_PBS 

Normal PBS signal.

SIGNALTYPE_PBS_ONEWAY 

No-entry PBS signal.

SIGNALTYPE_TWOWAY 

Bit mask for twoway signal.

SIGNALTYPE_NORMAL_TWOWAY 

Normal twoway signal.

SIGNALTYPE_ENTRY_TWOWAY 

Entry twoway signal.

SIGNALTYPE_EXIT_TWOWAY 

Exit twoway signal.

SIGNALTYPE_COMBO_TWOWAY 

Combo twoway signal.

SIGNALTYPE_NONE 

No signal.

Member Function Documentation

◆ AreTilesConnected()

static bool GSRail::AreTilesConnected ( TileIndex  from,
TileIndex  tile,
TileIndex  to 
)
static

Check if a tile connects two adjacent tiles.

Parameters
fromThe first tile to connect.
tileThe tile that is checked.
toThe second tile to connect.
Precondition
from != to.
GSMap::DistanceManhattan(from, tile) == 1.
GSMap::DistanceManhattan(to, tile) == 1.
Returns
True if 'tile' connects 'from' and 'to'.

◆ BuildNewGRFRailStation()

static bool GSRail::BuildNewGRFRailStation ( TileIndex  tile,
RailTrack  direction,
uint  num_platforms,
uint  platform_length,
StationID  station_id,
CargoID  cargo_id,
IndustryType  source_industry,
IndustryType  goal_industry,
int  distance,
bool  source_station 
)
static

Build a NewGRF rail station.

This calls callback 18 to let a NewGRF provide the station class / id to build, so we don't end up with only the default stations on the map. When no NewGRF provides a rail station, or an unbuildable rail station is returned by a NewGRF, this function will fall back to building a default non-NewGRF station as if GSRail::BuildRailStation was called.

Parameters
tilePlace to build the station.
directionThe direction to build the station.
num_platformsThe number of platforms to build.
platform_lengthThe length of each platform.
station_idThe station to join, GSStation::STATION_NEW or GSStation::STATION_JOIN_ADJACENT.
cargo_idThe CargoID of the cargo that will be transported from / to this station.
source_industryThe IndustryType of the industry you'll transport goods from, GSIndustryType::INDUSTRYTYPE_UNKNOWN or GSIndustryType::INDUSTRYTYPE_TOWN.
goal_industryThe IndustryType of the industry you'll transport goods to, GSIndustryType::INDUSTRYTYPE_UNKNOWN or GSIndustryType::INDUSTRYTYPE_TOWN.
distanceThe manhattan distance you'll transport the cargo over.
source_stationTrue if this is the source station, false otherwise.
Precondition
IsRailTypeAvailable(GetCurrentRailType()).
GSMap::IsValidTile(tile).
direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW.
num_platforms > 0 && num_platforms <= 255.
platform_length > 0 && platform_length <= 255.
station_id == GSStation::STATION_NEW || station_id == GSStation::STATION_JOIN_ADJACENT || GSStation::IsValidStation(station_id).
GSCargo::IsValidCargo(cargo_type)
source_industry == GSIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == GSIndustryType::INDUSTRYTYPE_TOWN || GSIndustryType::IsValidIndustryType(source_industry).
goal_industry == GSIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == GSIndustryType::INDUSTRYTYPE_TOWN || GSIndustryType::IsValidIndustryType(goal_industry).
Valid GSCompanyMode active in scope.
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
GSError::ERR_AREA_NOT_CLEAR
GSError::ERR_FLAT_LAND_REQUIRED
GSStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION
GSStation::ERR_STATION_TOO_MANY_STATIONS
GSStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN
Returns
Whether the station has been/can be build or not.

◆ BuildRail()

static bool GSRail::BuildRail ( TileIndex  from,
TileIndex  tile,
TileIndex  to 
)
static

Build a rail connection between two tiles.

Parameters
fromThe tile just before the tile to build on.
tileThe first tile to build on.
toThe tile just after the last tile to build on.
Precondition
from != to.
GSMap::DistanceManhattan(from, tile) == 1.
GSMap::DistanceManhattan(to, tile) >= 1.
(abs(abs(GSMap::GetTileX(to) - GSMap::GetTileX(tile)) - abs(GSMap::GetTileY(to) - GSMap::GetTileY(tile))) <= 1) || (GSMap::GetTileX(from) == GSMap::GetTileX(tile) && GSMap::GetTileX(tile) == GSMap::GetTileX(to)) || (GSMap::GetTileY(from) == GSMap::GetTileY(tile) && GSMap::GetTileY(tile) == GSMap::GetTileY(to)).
IsRailTypeAvailable(GetCurrentRailType()).
Valid GSCompanyMode active in scope.
Exceptions
GSError::ERR_AREA_NOT_CLEAR
GSError::ERR_LAND_SLOPED_WRONG
GSRail::ERR_CROSSING_ON_ONEWAY_ROAD
GSRoad::ERR_ROAD_WORKS_IN_PROGRESS
GSError::ERR_ALREADY_BUILT
Note
Construction will fail if an obstacle is found between the start and end tiles.
Returns
Whether the rail has been/can be build or not.

◆ BuildRailDepot()

static bool GSRail::BuildRailDepot ( TileIndex  tile,
TileIndex  front 
)
static

Builds a rail depot.

Parameters
tilePlace to build the depot.
frontThe tile exactly in front of the depot.
Precondition
GSMap::IsValidTile(tile).
GSMap::IsValidTile(front).
'tile' is not equal to 'front', but in a straight line of it.
IsRailTypeAvailable(GetCurrentRailType()).
Valid GSCompanyMode active in scope.
Exceptions
GSError::ERR_FLAT_LAND_REQUIRED
GSError::ERR_AREA_NOT_CLEAR
Returns
Whether the rail depot has been/can be build or not.

◆ BuildRailStation()

static bool GSRail::BuildRailStation ( TileIndex  tile,
RailTrack  direction,
uint  num_platforms,
uint  platform_length,
StationID  station_id 
)
static

Build a rail station.

Parameters
tilePlace to build the station.
directionThe direction to build the station.
num_platformsThe number of platforms to build.
platform_lengthThe length of each platform.
station_idThe station to join, GSStation::STATION_NEW or GSStation::STATION_JOIN_ADJACENT.
Precondition
IsRailTypeAvailable(GetCurrentRailType()).
GSMap::IsValidTile(tile).
direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW.
num_platforms > 0 && num_platforms <= 255.
platform_length > 0 && platform_length <= 255.
station_id == GSStation::STATION_NEW || station_id == GSStation::STATION_JOIN_ADJACENT || GSStation::IsValidStation(station_id).
Valid GSCompanyMode active in scope.
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
GSError::ERR_AREA_NOT_CLEAR
GSError::ERR_FLAT_LAND_REQUIRED
GSStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION
GSStation::ERR_STATION_TOO_MANY_STATIONS
GSStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN
Returns
Whether the station has been/can be build or not.

◆ BuildRailTrack()

static bool GSRail::BuildRailTrack ( TileIndex  tile,
RailTrack  rail_track 
)
static

Build rail on the given tile.

Parameters
tileThe tile to build on.
rail_trackThe RailTrack to build.
Precondition
GSMap::IsValidTile(tile).
IsRailTypeAvailable(GetCurrentRailType()).
Valid GSCompanyMode active in scope.
Exceptions
GSError::ERR_AREA_NOT_CLEAR
GSError::ERR_LAND_SLOPED_WRONG
GSRoad::ERR_ROAD_WORKS_IN_PROGRESS
GSRail::ERR_CROSSING_ON_ONEWAY_ROAD
GSError::ERR_ALREADY_BUILT
Returns
Whether the rail has been/can be build or not.
Note
You can only build a single track with this function so do not use the values from RailTrack as bitmask.

◆ BuildRailWaypoint()

static bool GSRail::BuildRailWaypoint ( TileIndex  tile)
static

Build a rail waypoint.

Parameters
tilePlace to build the waypoint.
Precondition
GSMap::IsValidTile(tile).
IsRailTile(tile).
GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE.
IsRailTypeAvailable(GetCurrentRailType()).
Valid GSCompanyMode active in scope.
Exceptions
GSError::ERR_FLAT_LAND_REQUIRED
Returns
Whether the rail waypoint has been/can be build or not.

◆ BuildSignal()

static bool GSRail::BuildSignal ( TileIndex  tile,
TileIndex  front,
SignalType  signal 
)
static

Build a signal on a tile.

Parameters
tileThe tile to build on.
frontThe tile in front of the signal.
signalThe SignalType to build.
Precondition
GSMap::DistanceManhattan(tile, front) == 1.
IsRailTile(tile) && !IsRailStationTile(tile) && !IsRailWaypointTile(tile).
Valid GSCompanyMode active in scope.
Exceptions
GSRail::ERR_UNSUITABLE_TRACK
Returns
Whether the signal has been/can be build or not.

◆ ConvertRailType()

static bool GSRail::ConvertRailType ( TileIndex  start_tile,
TileIndex  end_tile,
GSRail::RailType  convert_to 
)
static

Convert the tracks on all tiles within a rectangle to another RailType.

Parameters
start_tileOne corner of the rectangle.
end_tileThe opposite corner of the rectangle.
convert_toThe RailType you want to convert the rails to.
Precondition
GSMap::IsValidTile(start_tile).
GSMap::IsValidTile(end_tile).
IsRailTypeAvailable(convert_to).
Valid GSCompanyMode active in scope.
Exceptions
GSRail::ERR_UNSUITABLE_TRACK
Returns
Whether at least some rail has been converted successfully.

◆ GetBuildCost()

static Money GSRail::GetBuildCost ( RailType  railtype,
BuildType  build_type 
)
static

Get the baseprice of building a rail-related object.

Parameters
railtypethe railtype that is build (on)
build_typethe type of object to build
Precondition
IsRailTypeAvailable(railtype)
Returns
The baseprice of building the given object.

◆ GetCurrentRailType()

static RailType GSRail::GetCurrentRailType ( )
static

Get the current RailType set for all GSRail functions.

Returns
The RailType currently set.

◆ GetMaintenanceCostFactor()

static uint16 GSRail::GetMaintenanceCostFactor ( RailType  railtype)
static

Get the maintenance cost factor of a railtype.

Parameters
railtypeThe railtype to get the maintenance factor of.
Precondition
IsRailTypeAvailable(railtype)
Returns
Maintenance cost factor of the railtype.

◆ GetMaxSpeed()

static int32 GSRail::GetMaxSpeed ( RailType  railtype)
static

Get the maximum speed of trains running on this railtype.

Parameters
railtypeThe railtype to get the maximum speed of.
Precondition
IsRailTypeAvailable(railtype)
Returns
The maximum speed trains can run on this railtype or 0 if there is no limit.
Note
The speed is in OpenTTD's internal speed unit. This is mph / 1.6, which is roughly km/h. To get km/h multiply this number by 1.00584.

◆ GetName()

static char* GSRail::GetName ( RailType  rail_type)
static

Get the name of a rail type.

Parameters
rail_typeThe rail type to get the name of.
Precondition
IsRailTypeAvailable(rail_type).
Returns
The name the rail type has.
Note
Since there is no string with only the name of the track, the text which is shown in the dropdown where you can chose a track type is returned. This means that the name could be something like "Maglev construction" instead of just "Maglev".

◆ GetRailDepotFrontTile()

static TileIndex GSRail::GetRailDepotFrontTile ( TileIndex  depot)
static

Gets the tile in front of a rail depot.

Parameters
depotThe rail depot tile.
Precondition
IsRailDepotTile(depot).
Returns
The tile in front of the depot.

◆ GetRailStationDirection()

static RailTrack GSRail::GetRailStationDirection ( TileIndex  tile)
static

Gets the direction of a rail station tile.

Parameters
tileThe rail station tile.
Precondition
IsRailStationTile(tile).
Returns
The direction of the station (either RAILTRACK_NE_SW or RAILTRACK_NW_SE).

◆ GetRailTracks()

static uint GSRail::GetRailTracks ( TileIndex  tile)
static

Get all RailTracks on the given tile.

Note
A depot has no railtracks.
Parameters
tileThe tile to check.
Precondition
IsRailTile(tile).
Returns
A bitmask of RailTrack with all RailTracks on the tile.

◆ GetRailType()

static RailType GSRail::GetRailType ( TileIndex  tile)
static

Get the RailType that is used on a tile.

Parameters
tileThe tile to check.
Precondition
GSTile::HasTransportType(tile, GSTile.TRANSPORT_RAIL).
Returns
The RailType that is used on a tile.

◆ GetSignalType()

static SignalType GSRail::GetSignalType ( TileIndex  tile,
TileIndex  front 
)
static

Get the SignalType of the signal on a tile or SIGNALTYPE_NONE if there is no signal.

Precondition
GSMap::DistanceManhattan(tile, front) == 1.
Parameters
tileThe tile that might have a signal.
frontThe tile in front of 'tile'.
Returns
The SignalType of the signal on 'tile' facing to 'front'.

◆ IsLevelCrossingTile()

static bool GSRail::IsLevelCrossingTile ( TileIndex  tile)
static

Checks whether there is a road / rail crossing on a tile.

Parameters
tileThe tile to check.
Returns
True if and only if there is a road / rail crossing.

◆ IsRailDepotTile()

static bool GSRail::IsRailDepotTile ( TileIndex  tile)
static

Checks whether the given tile is actually a tile with a rail depot.

Parameters
tileThe tile to check.
Precondition
GSMap::IsValidTile(tile).
Returns
True if and only if the tile has a rail depot.

◆ IsRailStationTile()

static bool GSRail::IsRailStationTile ( TileIndex  tile)
static

Checks whether the given tile is actually a tile with a rail station.

Parameters
tileThe tile to check.
Precondition
GSMap::IsValidTile(tile).
Returns
True if and only if the tile has a rail station.

◆ IsRailTile()

static bool GSRail::IsRailTile ( TileIndex  tile)
static

Checks whether the given tile is actually a tile with rail that can be used to traverse a tile.

This excludes rail depots but includes stations and waypoints.

Parameters
tileThe tile to check.
Precondition
GSMap::IsValidTile(tile).
Returns
True if and only if the tile has rail.

◆ IsRailTypeAvailable()

static bool GSRail::IsRailTypeAvailable ( RailType  rail_type)
static

Check if a given RailType is available.

Parameters
rail_typeThe RailType to check for.
Returns
True if this RailType can be used.

◆ IsRailWaypointTile()

static bool GSRail::IsRailWaypointTile ( TileIndex  tile)
static

Checks whether the given tile is actually a tile with a rail waypoint.

Parameters
tileThe tile to check.
Precondition
GSMap::IsValidTile(tile).
Returns
True if and only if the tile has a rail waypoint.

◆ RemoveRail()

static bool GSRail::RemoveRail ( TileIndex  from,
TileIndex  tile,
TileIndex  to 
)
static

Remove a rail connection between two tiles.

Parameters
fromThe tile just before the tile to remove rail from.
tileThe first tile to remove rail from.
toThe tile just after the last tile to remove rail from.
Precondition
from != to.
GSMap::DistanceManhattan(from, tile) == 1.
GSMap::DistanceManhattan(to, tile) >= 1.
(abs(abs(GSMap::GetTileX(to) - GSMap::GetTileX(tile)) - abs(GSMap::GetTileY(to) - GSMap::GetTileY(tile))) <= 1) || (GSMap::GetTileX(from) == GSMap::GetTileX(tile) && GSMap::GetTileX(tile) == GSMap::GetTileX(to)) || (GSMap::GetTileY(from) == GSMap::GetTileY(tile) && GSMap::GetTileY(tile) == GSMap::GetTileY(to)).
Valid GSCompanyMode active in scope.
Exceptions
GSRail::ERR_UNSUITABLE_TRACK
Returns
Whether the rail has been/can be removed or not.

◆ RemoveRailStationTileRectangle()

static bool GSRail::RemoveRailStationTileRectangle ( TileIndex  tile,
TileIndex  tile2,
bool  keep_rail 
)
static

Remove all rail station platform pieces within a rectangle on the map.

Parameters
tileOne corner of the rectangle to clear.
tile2The opposite corner.
keep_railWhether to keep the rail after removal.
Precondition
IsValidTile(tile).
IsValidTile(tile2).
Valid GSCompanyMode active in scope.
Exceptions
GSRail::ERR_UNSUITABLE_TRACK
Returns
Whether at least one tile has been/can be cleared or not.

◆ RemoveRailTrack()

static bool GSRail::RemoveRailTrack ( TileIndex  tile,
RailTrack  rail_track 
)
static

Remove rail on the given tile.

Parameters
tileThe tile to remove rail from.
rail_trackThe RailTrack to remove.
Precondition
GSMap::IsValidTile(tile).
(GetRailTracks(tile) & rail_track) != 0.
Valid GSCompanyMode active in scope.
Exceptions
GSRail::ERR_UNSUITABLE_TRACK
Returns
Whether the rail has been/can be removed or not.
Note
You can only remove a single track with this function so do not use the values from RailTrack as bitmask.

◆ RemoveRailWaypointTileRectangle()

static bool GSRail::RemoveRailWaypointTileRectangle ( TileIndex  tile,
TileIndex  tile2,
bool  keep_rail 
)
static

Remove all rail waypoint pieces within a rectangle on the map.

Parameters
tileOne corner of the rectangle to clear.
tile2The opposite corner.
keep_railWhether to keep the rail after removal.
Precondition
IsValidTile(tile).
IsValidTile(tile2).
Valid GSCompanyMode active in scope.
Exceptions
GSRail::ERR_UNSUITABLE_TRACK
Returns
Whether at least one tile has been/can be cleared or not.

◆ RemoveSignal()

static bool GSRail::RemoveSignal ( TileIndex  tile,
TileIndex  front 
)
static

Remove a signal.

Parameters
tileThe tile to remove the signal from.
frontThe tile in front of the signal.
Precondition
GSMap::DistanceManhattan(tile, front) == 1.
GetSignalType(tile, front) != SIGNALTYPE_NONE.
Valid GSCompanyMode active in scope.
Exceptions
GSRail::ERR_UNSUITABLE_TRACK
Returns
Whether the signal has been/can be removed or not.

◆ SetCurrentRailType()

static void GSRail::SetCurrentRailType ( RailType  rail_type)
static

Set the RailType for all further GSRail functions.

Parameters
rail_typeThe RailType to set.

◆ TrainCanRunOnRail()

static bool GSRail::TrainCanRunOnRail ( GSRail::RailType  engine_rail_type,
GSRail::RailType  track_rail_type 
)
static

Check if a train build for a rail type can run on another rail type.

Parameters
engine_rail_typeThe rail type the train is build for.
track_rail_typeThe type you want to check.
Precondition
GSRail::IsRailTypeAvailable(engine_rail_type).
GSRail::IsRailTypeAvailable(track_rail_type).
Returns
Whether a train build for 'engine_rail_type' can run on 'track_rail_type'.
Note
Even if a train can run on a RailType that doesn't mean that it'll be able to power the train. Use TrainHasPowerOnRail for that.

◆ TrainHasPowerOnRail()

static bool GSRail::TrainHasPowerOnRail ( GSRail::RailType  engine_rail_type,
GSRail::RailType  track_rail_type 
)
static

Check if a train build for a rail type has power on another rail type.

Parameters
engine_rail_typeThe rail type the train is build for.
track_rail_typeThe type you want to check.
Precondition
GSRail::IsRailTypeAvailable(engine_rail_type).
GSRail::IsRailTypeAvailable(track_rail_type).
Returns
Whether a train build for 'engine_rail_type' has power on 'track_rail_type'.