OpenTTD Source: src/rail.cpp File Reference

OpenTTD Source 15.3

Functions
rail.cpp File Reference

Implementation of rail specific functions. More...

`#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 "table/track_data.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.
bool | HasAnyRailTypesAvail (const CompanyID company)
| Test if any buildable railtype is available for a company.
bool | ValParamRailType (const RailType rail)
| Validate functions for rail building.
RailTypes | AddDateIntroducedRailTypes (RailTypes current, TimerGameCalendar::Date date)
| Add the rail types that are to be introduced at the given date.
RailTypes | GetCompanyRailTypes (CompanyID company, bool introduces)
| Get the rail types the given company can build.
RailTypes | GetRailTypes (bool introduces)
| Get list of rail types, regardless of company availability.
RailType | GetRailTypeByLabel (RailTypeLabel label, bool allow_alternate_labels)
| Get the rail type for a given label.

## 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 102 of file rail.cpp.

References AddDateIntroducedRailTypes(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::All(), GetRailTypeInfo(), RailTypeInfo::introduces_railtypes, RailTypeInfo::introduction_date, RailTypeInfo::introduction_required_railtypes, IsInsideMM(), RailTypeInfo::label, TimerGameConst< struct Calendar >::MAX_DATE, RAILTYPE_BEGIN, RAILTYPE_END, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().

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 135 of file rail.cpp.

References _settings_game, AddDateIntroducedRailTypes(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), EngineInfo::climates, TimerGameCalendar::date, TimerGameConst< struct Calendar >::DAYS_IN_YEAR, GameSettings::game_creation, GetAllIntroducesRailTypes(), Engine::IterateType(), GameCreationSettings::landscape, RailVehicleInfo::railtypes, RAILVEH_WAGON, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and VEH_TRAIN.

Referenced by AfterLoadGame(), DisableEngineForCompany(), DoStartupNewCompany(), EnableEngineForCompany(), GetRailTypeDropDownList(), and StartupEngines().

## ◆ 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 195 of file rail.cpp.

References RailTypeInfo::alternate_labels, FlatSet< Tkey, Tcompare >::contains(), INVALID_RAILTYPE, RailTypeInfo::label, and RAILTYPE_END.

Referenced by AfterLoadGRFs(), ConvertRailTypes(), GetRailTypeTranslation(), and RailTypeChangeInfo().

## ◆ 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 166 of file rail.cpp.

References _settings_game, AddDateIntroducedRailTypes(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), EngineInfo::climates, GameSettings::game_creation, GetAllIntroducesRailTypes(), Engine::IterateType(), GameCreationSettings::landscape, TimerGameConst< struct Calendar >::MAX_DATE, RailVehicleInfo::railtypes, RAILVEH_WAGON, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and VEH_TRAIN.

Referenced by GetRailTypeDropDownList().

## ◆ GetTileRailType()

RailType GetTileRailType | ( | Tile | tile | ) |

Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.

Definition at line 37 of file rail.cpp.

References GetRailType(), GetTileType(), GetTunnelBridgeTransportType(), HasStationRail(), INVALID_RAILTYPE, IsLevelCrossing(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, and TRANSPORT_RAIL.

Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CheckNextTrainTile(), ExtendTrainReservation(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetTrackTypes(), GetTrainForReservation(), IsSafeWaitingPosition(), IsWaitingPositionFree(), MaskWireBits(), Vehicle::ShowVisualEffect(), TrainCheckIfLineEnds(), TrainController(), and TryPathReserve().

## ◆ 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 78 of file rail.cpp.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset().

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 68 of file rail.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

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 90 of file rail.cpp.

References _current_company, HasRailTypeAvail(), and RAILTYPE_END.

Referenced by CmdBuildBridge(), CmdBuildRailStation(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdConvertRail(), CmdRailTrackHelper(), BuildRailToolbarWindow::OnInvalidateData(), and ShowBuildRailToolbar().