OpenTTD Source: src/rail.cpp File Reference

OpenTTD Source 14.0-beta1

Functions | Variables
rail.cpp File Reference
`#include "stdafx.h"`
`#include "station_map.h"`
`#include "tunnelbridge_map.h"`
`#include "timer/timer_game_calendar.h"`
`#include "company_func.h"`
`#include "company_base.h"`
`#include "engine_base.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
RailType | GetTileRailType (Tile tile)
| Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
bool | HasRailTypeAvail (const CompanyID company, const RailType railtype)
| Finds out if a company has a certain buildable railtype available. More...
bool | HasAnyRailTypesAvail (const CompanyID company)
| Test if any buildable railtype is available for a company. More...
bool | ValParamRailType (const RailType rail)
| Validate functions for rail building. More...
RailTypes | AddDateIntroducedRailTypes (RailTypes current, TimerGameCalendar::Date date)
| Add the rail types that are to be introduced at the given date. More...
RailTypes | GetCompanyRailTypes (CompanyID company, bool introduces)
| Get the rail types the given company can build. More...
RailTypes | GetRailTypes (bool introduces)
| Get list of rail types, regardless of company availability. More...
RailType | GetRailTypeByLabel (RailTypeLabel label, bool allow_alternate_labels)
| Get the rail type for a given label. More...

## Variables
const byte | _signal_along_trackdir [TRACKDIR_END]
const byte | _signal_against_trackdir [TRACKDIR_END]
const byte | _signal_on_track []
const TrackdirBits | _exitdir_reaches_trackdirs []
const Trackdir | _next_trackdir [TRACKDIR_END]
const TrackdirBits | _track_crosses_trackdirs [TRACK_END]
const TrackBits | _track_crosses_tracks []
const DiagDirection | _trackdir_to_exitdir [TRACKDIR_END]
const Trackdir | _track_exitdir_to_trackdir [][DIAGDIR_END]
const Trackdir | _track_enterdir_to_trackdir [][DIAGDIR_END]
const Trackdir | _track_direction_to_trackdir [][DIR_END]
const Trackdir | _dir_to_diag_trackdir []
const TrackBits | _corner_to_trackbits []
const TrackdirBits | _uphill_trackdirs []

## Detailed Description

Implementation of rail specific functions.

Definition in file rail.cpp.

## Function Documentation

## ◆ AddDateIntroducedRailTypes()

RailTypes AddDateIntroducedRailTypes | ( | RailTypes | current,
|  | TimerGameCalendar::Date | date
| ) |  |

Add the rail types that are to be introduced at the given date.

Parameters

  current | The currently available railtypes.
  date | The date for the introduction comparisons.

Returns
  The rail types that should be available when date introduced rail types are taken into account as well.

Definition at line 218 of file rail.cpp.

References AddDateIntroducedRailTypes(), GetRailTypeInfo(), RailTypeInfo::introduces_railtypes, RailTypeInfo::introduction_date, RailTypeInfo::introduction_required_railtypes, IsInsideMM(), RailTypeInfo::label, TimerGameConst< struct Calendar >::MAX_DATE, RAILTYPE_BEGIN, and RAILTYPE_END.

Referenced by AddDateIntroducedRailTypes(), GetCompanyRailTypes(), GetRailTypes(), and NewVehicleAvailable().

## ◆ GetCompanyRailTypes()

RailTypes GetCompanyRailTypes | ( | CompanyID | company,
|  | bool | introduces
| ) |  |

Get the rail types the given company can build.

Parameters

  company | the company to get the rail types for.
  introduces | If true, include rail types introduced by other rail types

Returns
  the rail types.

Definition at line 251 of file rail.cpp.

References _settings_game, AddDateIntroducedRailTypes(), EngineInfo::climates, TimerGameCalendar::date, TimerGameConst< struct Calendar >::DAYS_IN_YEAR, GameSettings::game_creation, GetRailTypeInfo(), HasBit(), RailTypeInfo::introduces_railtypes, Engine::IterateType(), GameCreationSettings::landscape, RailVehicleInfo::railtype, RAILTYPE_END, RAILTYPES_NONE, RAILVEH_WAGON, SetBit(), and VEH_TRAIN.

Referenced by DisableEngineForCompany(), EnableEngineForCompany(), GetRailTypeDropDownList(), and SettingsDisableElrail().

## ◆ GetRailTypeByLabel()

RailType GetRailTypeByLabel | ( | RailTypeLabel | label,
|  | bool | allow_alternate_labels
| ) |  |

Get the rail type for a given label.

Parameters

  label | the railtype label.
  allow_alternate_labels | Search in the alternate label lists as well.

Returns
  the railtype.

Definition at line 311 of file rail.cpp.

References RailTypeInfo::alternate_labels, GetRailTypeInfo(), INVALID_RAILTYPE, RailTypeInfo::label, RAILTYPE_BEGIN, and RAILTYPE_END.

Referenced by GetRailTypeTranslation().

## ◆ GetRailTypes()

RailTypes GetRailTypes | ( | bool | introduces | ) |

Get list of rail types, regardless of company availability.

Parameters

  introduces | If true, include rail types introduced by other rail types

Returns
  the rail types.

Definition at line 282 of file rail.cpp.

References _settings_game, AddDateIntroducedRailTypes(), EngineInfo::climates, GameSettings::game_creation, GetRailTypeInfo(), HasBit(), RailTypeInfo::introduces_railtypes, Engine::IterateType(), GameCreationSettings::landscape, TimerGameConst< struct Calendar >::MAX_DATE, RailVehicleInfo::railtype, RAILTYPE_END, RAILTYPES_NONE, RAILVEH_WAGON, SetBit(), and VEH_TRAIN.

Referenced by GetRailTypeDropDownList().

## ◆ HasAnyRailTypesAvail()

bool HasAnyRailTypesAvail | ( | const CompanyID | company | ) |

Test if any buildable railtype is available for a company.

Parameters

  company | the company in question

Returns
  true if company has any RailTypes available

Definition at line 196 of file rail.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get().

Referenced by CanBuildVehicleInfrastructure().

## ◆ HasRailTypeAvail()

bool HasRailTypeAvail | ( | const CompanyID | company,
|  | const RailType | railtype
| ) |  |

Finds out if a company has a certain buildable railtype available.

Parameters

  company | the company in question
  railtype | requested RailType

Returns
  true if company has requested RailType available

Definition at line 186 of file rail.cpp.

References HasBit().

Referenced by ValParamRailType().

## ◆ ValParamRailType()

bool ValParamRailType | ( | const RailType | rail | ) |

Validate functions for rail building.

Parameters

  rail | the railtype to check.

Returns
  true if the current company may build the rail.

Definition at line 206 of file rail.cpp.

References _current_company, HasRailTypeAvail(), and RAILTYPE_END.

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

## Variable Documentation

## ◆ _corner_to_trackbits

const TrackBits _corner_to_trackbits[]

Initial value:
= {
TRACK_BIT_LEFT, TRACK_BIT_LOWER, TRACK_BIT_RIGHT, TRACK_BIT_UPPER,
}

## ◆ _dir_to_diag_trackdir

const Trackdir _dir_to_diag_trackdir[]

Initial value:
= {
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW,
}

## ◆ _exitdir_reaches_trackdirs

const TrackdirBits _exitdir_reaches_trackdirs[]

Initial value:
= {
TRACKDIR_BIT_X_NE | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N,
TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E,
TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S,
TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W
}

## ◆ _next_trackdir

const Trackdir _next_trackdir[TRACKDIR_END]

Initial value:
= {
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_LOWER_E, TRACKDIR_UPPER_E, TRACKDIR_RIGHT_S, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR,
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_LOWER_W, TRACKDIR_UPPER_W, TRACKDIR_RIGHT_N, TRACKDIR_LEFT_N
}

## ◆ _signal_against_trackdir

const byte _signal_against_trackdir[TRACKDIR_END]

Initial value:
= {
0x4, 0x4, 0x4, 0x1, 0x8, 0x2, 0, 0,
0x8, 0x8, 0x8, 0x2, 0x4, 0x1
}

## ◆ _signal_along_trackdir

const byte _signal_along_trackdir[TRACKDIR_END]

Initial value:
= {
0x8, 0x8, 0x8, 0x2, 0x4, 0x1, 0, 0,
0x4, 0x4, 0x4, 0x1, 0x8, 0x2
}

## ◆ _signal_on_track

const byte _signal_on_track[]

Initial value:
= {
0xC, 0xC, 0xC, 0x3, 0xC, 0x3
}

## ◆ _track_crosses_trackdirs

const TrackdirBits _track_crosses_trackdirs[TRACK_END]

Initial value:
= {
TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW,
TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW,
TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S,
TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S,
TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E,
TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E
}

## ◆ _track_crosses_tracks

const TrackBits _track_crosses_tracks[]

Initial value:
= {
TRACK_BIT_Y,
TRACK_BIT_X,
TRACK_BIT_VERT,
TRACK_BIT_VERT,
TRACK_BIT_HORZ,
TRACK_BIT_HORZ
}

## ◆ _track_direction_to_trackdir

const Trackdir _track_direction_to_trackdir[][DIR_END]

Initial value:
= {
{INVALID_TRACKDIR, TRACKDIR_X_NE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR, INVALID_TRACKDIR},
{INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_NW},
{INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W, INVALID_TRACKDIR},
{INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W, INVALID_TRACKDIR},
{TRACKDIR_LEFT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR},
{TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR}
}

## ◆ _track_enterdir_to_trackdir

const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END]

Initial value:
= {
{TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR},
{INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW},
{INVALID_TRACKDIR, TRACKDIR_UPPER_E, TRACKDIR_UPPER_W, INVALID_TRACKDIR},
{TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W},
{TRACKDIR_LEFT_N, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR},
{INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, TRACKDIR_RIGHT_N}
}

## ◆ _track_exitdir_to_trackdir

const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END]

Initial value:
= {
{TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR},
{INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW},
{TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W},
{INVALID_TRACKDIR, TRACKDIR_LOWER_E, TRACKDIR_LOWER_W, INVALID_TRACKDIR},
{INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LEFT_S, TRACKDIR_LEFT_N},
{TRACKDIR_RIGHT_N, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR}
}

## ◆ _trackdir_to_exitdir

const DiagDirection _trackdir_to_exitdir[TRACKDIR_END]

Initial value:
= {
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_NE,
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE,
}
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:76
TRACKDIR_LOWER_E
@ TRACKDIR_LOWER_E
Lower track and direction to east.
Definition: track_type.h:72
TRACKDIR_RIGHT_S
@ TRACKDIR_RIGHT_S
Right track and direction to south.
Definition: track_type.h:74
TRACKDIR_LOWER_W
@ TRACKDIR_LOWER_W
Lower track and direction to west.
Definition: track_type.h:80
TRACKDIR_BIT_LEFT_N
@ TRACKDIR_BIT_LEFT_N
Track left, direction north.
Definition: track_type.h:111
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:78
TRACKDIR_BIT_Y_NW
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
Definition: track_type.h:108
TRACKDIR_UPPER_E
@ TRACKDIR_UPPER_E
Upper track and direction to east.
Definition: track_type.h:71
TRACKDIR_Y_SE
@ TRACKDIR_Y_SE
Y-axis and direction to south-east.
Definition: track_type.h:70
TRACK_BIT_UPPER
@ TRACK_BIT_UPPER
Upper track.
Definition: track_type.h:39
TRACK_BIT_RIGHT
@ TRACK_BIT_RIGHT
Right track.
Definition: track_type.h:42
TRACKDIR_LEFT_N
@ TRACKDIR_LEFT_N
Left track and direction to north.
Definition: track_type.h:81
TRACK_BIT_VERT
@ TRACK_BIT_VERT
Left and right track.
Definition: track_type.h:45
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:77
TRACKDIR_BIT_LOWER_W
@ TRACKDIR_BIT_LOWER_W
Track lower, direction west.
Definition: track_type.h:110
TRACKDIR_BIT_UPPER_E
@ TRACKDIR_BIT_UPPER_E
Track upper, direction east.
Definition: track_type.h:102
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition: track_type.h:37
TRACKDIR_BIT_LEFT_S
@ TRACKDIR_BIT_LEFT_S
Track left, direction south.
Definition: track_type.h:104
TRACKDIR_BIT_RIGHT_S
@ TRACKDIR_BIT_RIGHT_S
Track right, direction south.
Definition: track_type.h:105
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:86
TRACKDIR_X_NE
@ TRACKDIR_X_NE
X-axis and direction to north-east.
Definition: track_type.h:69
TRACKDIR_UPPER_W
@ TRACKDIR_UPPER_W
Upper track and direction to west.
Definition: track_type.h:79
TRACK_BIT_LOWER
@ TRACK_BIT_LOWER
Lower track.
Definition: track_type.h:40
TRACKDIR_BIT_X_NE
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
Definition: track_type.h:100
TRACK_BIT_HORZ
@ TRACK_BIT_HORZ
Upper and lower track.
Definition: track_type.h:44
TRACK_BIT_LEFT
@ TRACK_BIT_LEFT
Left track.
Definition: track_type.h:41
TRACKDIR_BIT_LOWER_E
@ TRACKDIR_BIT_LOWER_E
Track lower, direction east.
Definition: track_type.h:103
TRACKDIR_Y_NW
@ TRACKDIR_Y_NW
Y-axis and direction to north-west.
Definition: track_type.h:78
TRACKDIR_BIT_Y_SE
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
Definition: track_type.h:101
TRACKDIR_BIT_RIGHT_N
@ TRACKDIR_BIT_RIGHT_N
Track right, direction north.
Definition: track_type.h:112
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition: track_type.h:38
TRACKDIR_LEFT_S
@ TRACKDIR_LEFT_S
Left track and direction to south.
Definition: track_type.h:73
TRACKDIR_X_SW
@ TRACKDIR_X_SW
X-axis and direction to south-west.
Definition: track_type.h:77
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:75
TRACKDIR_RIGHT_N
@ TRACKDIR_RIGHT_N
Right track and direction to north.
Definition: track_type.h:82
TRACKDIR_BIT_UPPER_W
@ TRACKDIR_BIT_UPPER_W
Track upper, direction west.
Definition: track_type.h:109
TRACKDIR_BIT_X_SW
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Definition: track_type.h:107