# rail.h File Reference

`#include "rail_type.h"`
`#include "track_type.h"`
`#include "vehicle_type.h"`
`#include "gfx_type.h"`
`#include "core/bitmath_func.hpp"`
`#include "economy_func.h"`
`#include "tile_cmd.h"`

Go to the source code of this file.

## Data Structures

struct | RailtypeInfo
| This struct contains all the info that is needed to draw and construct tracks. More...

## Functions

static const RailtypeInfo * | GetRailTypeInfo (RailType railtype)
| Returns a pointer to the Railtype information for a given railtype.
static bool | IsCompatibleRail (RailType enginetype, RailType tiletype)
| Checks if an engine of the given RailType can drive on a tile with a given RailType.
static bool | HasPowerOnRail (RailType enginetype, RailType tiletype)
| Checks if an engine of the given RailType got power on a tile with a given RailType.
static Money | RailBuildCost (RailType railtype)
| Returns the cost of building the specified railtype.
static Money | RailConvertCost (RailType from, RailType to)
| Calculates the cost of rail conversion.
void * | UpdateTrainPowerProc (Vehicle *v, void *data)
| Update power of train under which is the railtype being converted.
void | DrawTrainDepotSprite (int x, int y, int image, RailType railtype)
void | DrawDefaultWaypointSprite (int x, int y, RailType railtype)
void * | EnsureNoTrainOnTrackProc (Vehicle *v, void *data)
int | TicksToLeaveDepot (const Vehicle *v)
| Compute number of ticks when next wagon will leave a depot.
void | DrawCatenary (const TileInfo *ti)
| Draws overhead wires and pylons for electric railways.
void | DrawCatenaryOnTunnel (const TileInfo *ti)
| Draws wires on a tunnel tile.
Foundation | GetRailFoundation (Slope tileh, TrackBits bits)
| Checks if a track combination is valid on a specific slope and returns the needed foundation.
int32 | SettingsDisableElrail (int32 p1)
| _patches.disable_elrail callback
bool | HasRailtypeAvail (const PlayerID p, const RailType railtype)
| Finds out if a Player has a certain railtype available.
bool | ValParamRailtype (const RailType rail)
| Validate functions for rail building.
RailType | GetBestRailtype (const PlayerID p)
| Returns the "best" railtype a player can build.
RailTypes | GetPlayerRailtypes (const PlayerID p)
| Get the rail types the given player can build.

## Variables

int | _railtype_cost_multiplier [RAILTYPE_END]
const int | _default_railtype_cost_multiplier [RAILTYPE_END]

## Detailed Description

Definition in file rail.h.

## Function Documentation

void DrawCatenary | ( | const TileInfo * | ti | ) |

Draws overhead wires and pylons for electric railways.

Parameters:

  | ti | The TileInfo struct of the tile being drawn

See also:
  DrawCatenaryRailway

Definition at line 432 of file elrail.cpp.

References AddSortableSpriteToDraw(), DrawCatenaryRailway(), GetNorthernBridgeEnd(), GetRailDepotDirection(), GetRailType(), GetTileType(), GetTunnelBridgeTransportType(), IsBridgeAbove(), IsRailDepot(), IsTransparencySet(), MayHaveBridgeAbove(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, RAILTYPE_ELECTRIC, and TO_CATENARY.

Referenced by DrawTile_TunnelBridge().

void DrawCatenaryOnTunnel | ( | const TileInfo * | ti | ) |

Draws wires on a tunnel tile.

DrawTile_TunnelBridge() calls this function to draw the wires as SpriteCombine with the tunnel roof.

Parameters:

  | ti | The Tileinfo to draw the tile for

Definition at line 172 of file elrail.cpp.

References AddSortableSpriteToDraw(), BB_Z_SEPARATOR, GetRailType(), GetTunnelBridgeDirection(), IsTransparencySet(), RAILTYPE_ELECTRIC, and TO_CATENARY.

Referenced by DrawTile_TunnelBridge().

RailType GetBestRailtype | ( | const PlayerID | p | ) |

Returns the "best" railtype a player can build.

As the AI doesn't know what the BEST one is, we have our own priority list here. When adding new railtypes, modify this function

Parameters:

  | p | the player "in action"

Returns:
  The "best" railtype a player has available

Definition at line 192 of file rail.cpp.

References HasRailtypeAvail(), RAILTYPE_ELECTRIC, RAILTYPE_MAGLEV, RAILTYPE_MONO, and RAILTYPE_RAIL.

RailTypes GetPlayerRailtypes | ( | const PlayerID | p | ) |

Get the rail types the given player can build.

Parameters:

  | p | the player to get the rail types for.

Returns:
  the rail types.

Definition at line 200 of file rail.cpp.

References EngineInfo::climates, HasBit(), RAILTYPE_END, RAILTYPES_NONE, RAILVEH_WAGON, and SetBit().

Referenced by DoStartupNewPlayer(), and SettingsDisableElrail().

Foundation GetRailFoundation | ( | Slope | tileh,
|  | TrackBits | bits |
| ) |  |  |

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

Parameters:

  | tileh | Tile slope.
  | bits | Trackbits.

Returns:
  Needed foundation or FOUNDATION_INVALID if track/slope combination is not allowed.

Definition at line 198 of file rail_cmd.cpp.

References CornerToTrackBits(), FOUNDATION_INCLINED_X, FOUNDATION_INCLINED_Y, FOUNDATION_INVALID, FOUNDATION_LEVELED, FOUNDATION_NONE, FOUNDATION_STEEP_BOTH, FOUNDATION_STEEP_LOWER, GetHighestSlopeCorner(), HalftileFoundation(), IsSlopeWithOneCornerRaised(), IsSlopeWithThreeCornersRaised(), IsSteepSlope(), OppositeCorner(), SLOPE_E, SLOPE_N, SLOPE_S, SLOPE_W, SlopeWithOneCornerRaised(), SlopeWithThreeCornersRaised(), SpecialRailFoundation(), TRACK_BIT_HORZ, TRACK_BIT_LEFT, TRACK_BIT_LOWER, TRACK_BIT_NONE, TRACK_BIT_RIGHT, TRACK_BIT_UPPER, TRACK_BIT_VERT, TRACK_BIT_X, TRACK_BIT_Y, and TracksOverlap().

Referenced by CheckRailSlope(), DrawCatenaryRailway(), DrawTrackBits(), FloodHalftile(), and TestAutoslopeOnRailTile().

static const RailtypeInfo* GetRailTypeInfo | ( | RailType | railtype | ) | `[inline, static]`

Returns a pointer to the Railtype information for a given railtype.

Parameters:

  | railtype | the rail type which the information is requested for

Returns:
  The pointer to the RailtypeInfo

Definition at line 104 of file rail.h.

References _railtypes, and RAILTYPE_END.

Referenced by DrawStationTile(), DrawTile_TunnelBridge(), DrawTrackBits(), GetTrainAcceleration(), HasPowerOnRail(), IsCompatibleRail(), SetupRailToolbar(), and TrainConsistChanged().

static bool HasPowerOnRail | ( | RailType | enginetype,
|  | RailType | tiletype |
| ) |  |  | `[inline, static]`

Checks if an engine of the given RailType got power on a tile with a given RailType.

This would normally just be an equality check, but for electric rails (which also support non-electric engines).

Returns:
  Whether the engine got power on this tile.

Parameters:

  | enginetype | The RailType of the engine we are considering.
  | tiletype | The RailType of the tile we are considering.

Definition at line 132 of file rail.h.

References GetRailTypeInfo(), and HasBit().

Referenced by CmdBuildRailVehicle(), CmdBuildSingleRail(), RailConvertCost(), and TrainPowerChanged().

bool HasRailtypeAvail | ( | const PlayerID | p,
|  | const RailType | railtype |
| ) |  |  |

Finds out if a Player has a certain railtype available.

Parameters:

  | p | Player in question
  | railtype | requested RailType

Returns:
  true if player has requested RailType available

Definition at line 182 of file rail.cpp.

References HasBit().

Referenced by GetBestRailtype(), and ValParamRailtype().

static bool IsCompatibleRail | ( | RailType | enginetype,
|  | RailType | tiletype |
| ) |  |  | `[inline, static]`

Checks if an engine of the given RailType can drive on a tile with a given RailType.

This would normally just be an equality check, but for electric rails (which also support non-electric engines).

Returns:
  Whether the engine can drive on this tile.

Parameters:

  | enginetype | The RailType of the engine we are considering.
  | tiletype | The RailType of the tile we are considering.

Definition at line 119 of file rail.h.

References GetRailTypeInfo(), and HasBit().

Referenced by CmdBuildSingleRail(), CmdConvertRail(), and GenerateReplaceRailList().

static Money RailBuildCost | ( | RailType | railtype | ) | `[inline, static]`

Returns the cost of building the specified railtype.

Parameters:

  | railtype | The railtype being built.

Returns:
  The cost multiplier.

Definition at line 146 of file rail.h.

References RAILTYPE_END.

Referenced by CmdBuildSingleRail(), and RailConvertCost().

static Money RailConvertCost | ( | RailType | from,
|  | RailType | to |
| ) |  |  | `[inline, static]`

Calculates the cost of rail conversion.

Parameters:

  | from | The railtype we are converting from
  | to | The railtype we are converting to

Returns:
  Cost per TrackBit

Definition at line 158 of file rail.h.

References HasPowerOnRail(), and RailBuildCost().

Referenced by CmdConvertRail().

int TicksToLeaveDepot | ( | const Vehicle * | v | ) |

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

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

Parameters:

  | v | vehicle outside (leaving) the depot

Returns:
  number of ticks when the next wagon will leave

Definition at line 2252 of file rail_cmd.cpp.

References DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, and GetRailDepotDirection().

Referenced by AdvanceWagonsAfterSwap(), and CheckTrainsLengths().

bool ValParamRailtype | ( | const RailType | rail | ) |

Validate functions for rail building.

Parameters:

  | rail | the railtype to check.

Returns:
  true if the current player may build the rail.

Definition at line 187 of file rail.cpp.

References HasRailtypeAvail().

Referenced by CmdBuildBridge(), CmdBuildRailroadStation(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdConvertRail(), and CmdRailTrackHelper().