OpenTTD
Functions | Variables
rail.cpp File Reference

Implementation of rail specific functions. More...

#include "stdafx.h"
#include "station_map.h"
#include "tunnelbridge_map.h"
#include "date_func.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 (TileIndex 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 railtype available. More...
 
bool ValParamRailtype (const RailType rail)
 Validate functions for rail building. More...
 
RailType GetBestRailtype (const CompanyID company)
 Returns the "best" railtype a company can build. More...
 
RailTypes AddDateIntroducedRailTypes (RailTypes current, Date date)
 Add the rail types that are to be introduced at the given date. More...
 
RailTypes GetCompanyRailtypes (CompanyID company)
 Get the rail types the given company can build. 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,
Date  date 
)

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

Parameters
currentThe currently available railtypes.
dateThe 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 225 of file rail.cpp.

References AddDateIntroducedRailTypes(), GetRailTypeInfo(), RailtypeInfo::introduces_railtypes, RailtypeInfo::introduction_date, RailtypeInfo::introduction_required_railtypes, IsInsideMM(), RailtypeInfo::label, MAX_DAY, RAILTYPE_BEGIN, and RAILTYPE_END.

Referenced by AddDateIntroducedRailTypes().

◆ GetBestRailtype()

RailType GetBestRailtype ( const CompanyID  company)

Returns the "best" railtype a company 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
companythe company "in action"
Returns
The "best" railtype a company has available

Definition at line 210 of file rail.cpp.

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

◆ GetCompanyRailtypes()

RailTypes GetCompanyRailtypes ( CompanyID  company)

Get the rail types the given company can build.

Parameters
cthe company to get the rail types for.
Returns
the rail types.

Definition at line 257 of file rail.cpp.

References RAILTYPES_NONE.

◆ GetRailTypeByLabel()

RailType GetRailTypeByLabel ( RailTypeLabel  label,
bool  allow_alternate_labels 
)

Get the rail type for a given label.

Parameters
labelthe railtype label.
allow_alternate_labelsSearch in the alternate label lists as well.
Returns
the railtype.

Definition at line 285 of file rail.cpp.

References RailtypeInfo::alternate_labels, SmallVector< T, S >::Contains(), GetRailTypeInfo(), INVALID_RAILTYPE, RailtypeInfo::label, RAILTYPE_BEGIN, and RAILTYPE_END.

◆ HasRailtypeAvail()

bool HasRailtypeAvail ( const CompanyID  company,
const RailType  railtype 
)

Finds out if a company has a certain railtype available.

Parameters
companythe company in question
railtyperequested RailType
Returns
true if company has requested RailType available

Definition at line 188 of file rail.cpp.

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

Referenced by GetBestRailtype(), and ValParamRailtype().

◆ ValParamRailtype()

bool ValParamRailtype ( const RailType  rail)

Validate functions for rail building.

Parameters
railthe railtype to check.
Returns
true if the current company may build the rail.

Definition at line 198 of file rail.cpp.

References _current_company, HasRailtypeAvail(), and RAILTYPE_END.

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

Variable Documentation

◆ _corner_to_trackbits

const TrackBits _corner_to_trackbits[]
Initial value:

◆ _dir_to_diag_trackdir

const Trackdir _dir_to_diag_trackdir[]
Initial value:
= {
}
Y-axis and direction to north-west.
Definition: track_type.h:85
X-axis and direction to south-west.
Definition: track_type.h:84
Y-axis and direction to south-east.
Definition: track_type.h:77
X-axis and direction to north-east.
Definition: track_type.h:76

◆ _exitdir_reaches_trackdirs

const TrackdirBits _exitdir_reaches_trackdirs[]
Initial value:
= {
}
Track right, direction south.
Definition: track_type.h:113
Track upper, direction east.
Definition: track_type.h:110
Track right, direction north.
Definition: track_type.h:120
Track x-axis, direction north-east.
Definition: track_type.h:108
Track upper, direction west.
Definition: track_type.h:117
Track lower, direction west.
Definition: track_type.h:118
Track x-axis, direction south-west.
Definition: track_type.h:115
Track y-axis, direction north-west.
Definition: track_type.h:116
Track y-axis, direction south-east.
Definition: track_type.h:109
Track left, direction south.
Definition: track_type.h:112
Track left, direction north.
Definition: track_type.h:119
Track lower, direction east.
Definition: track_type.h:111

◆ _next_trackdir

const Trackdir _next_trackdir[TRACKDIR_END]
Initial value:
= {
}
Y-axis and direction to north-west.
Definition: track_type.h:85
Right track and direction to north.
Definition: track_type.h:89
X-axis and direction to south-west.
Definition: track_type.h:84
Left track and direction to north.
Definition: track_type.h:88
Upper track and direction to west.
Definition: track_type.h:86
Y-axis and direction to south-east.
Definition: track_type.h:77
Lower track and direction to east.
Definition: track_type.h:79
Left track and direction to south.
Definition: track_type.h:80
Right track and direction to south.
Definition: track_type.h:81
Lower track and direction to west.
Definition: track_type.h:87
Upper track and direction to east.
Definition: track_type.h:78
Flag for an invalid trackdir.
Definition: track_type.h:93
X-axis and direction to north-east.
Definition: track_type.h:76

◆ _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:
= {
}
Track right, direction south.
Definition: track_type.h:113
Track upper, direction east.
Definition: track_type.h:110
Track right, direction north.
Definition: track_type.h:120
Track x-axis, direction north-east.
Definition: track_type.h:108
Track upper, direction west.
Definition: track_type.h:117
Track lower, direction west.
Definition: track_type.h:118
Track x-axis, direction south-west.
Definition: track_type.h:115
Track y-axis, direction north-west.
Definition: track_type.h:116
Track y-axis, direction south-east.
Definition: track_type.h:109
Track left, direction south.
Definition: track_type.h:112
Track left, direction north.
Definition: track_type.h:119
Track lower, direction east.
Definition: track_type.h:111

◆ _track_crosses_tracks

const TrackBits _track_crosses_tracks[]
Initial value:
= {
TRACK_BIT_HORZ
}
Left and right track.
Definition: track_type.h:51
X-axis track.
Definition: track_type.h:43
Upper and lower track.
Definition: track_type.h:50
Y-axis track.
Definition: track_type.h:44

◆ _track_direction_to_trackdir

const Trackdir _track_direction_to_trackdir[][DIR_END]
Initial value:
= {
}
Y-axis and direction to north-west.
Definition: track_type.h:85
Right track and direction to north.
Definition: track_type.h:89
X-axis and direction to south-west.
Definition: track_type.h:84
Left track and direction to north.
Definition: track_type.h:88
Upper track and direction to west.
Definition: track_type.h:86
Y-axis and direction to south-east.
Definition: track_type.h:77
Lower track and direction to east.
Definition: track_type.h:79
Left track and direction to south.
Definition: track_type.h:80
Right track and direction to south.
Definition: track_type.h:81
Lower track and direction to west.
Definition: track_type.h:87
Upper track and direction to east.
Definition: track_type.h:78
Flag for an invalid trackdir.
Definition: track_type.h:93
X-axis and direction to north-east.
Definition: track_type.h:76

◆ _track_enterdir_to_trackdir

const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END]
Initial value:
= {
}
Y-axis and direction to north-west.
Definition: track_type.h:85
Right track and direction to north.
Definition: track_type.h:89
X-axis and direction to south-west.
Definition: track_type.h:84
Left track and direction to north.
Definition: track_type.h:88
Upper track and direction to west.
Definition: track_type.h:86
Y-axis and direction to south-east.
Definition: track_type.h:77
Lower track and direction to east.
Definition: track_type.h:79
Left track and direction to south.
Definition: track_type.h:80
Right track and direction to south.
Definition: track_type.h:81
Lower track and direction to west.
Definition: track_type.h:87
Upper track and direction to east.
Definition: track_type.h:78
Flag for an invalid trackdir.
Definition: track_type.h:93
X-axis and direction to north-east.
Definition: track_type.h:76

◆ _track_exitdir_to_trackdir

const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END]
Initial value:
= {
}
Y-axis and direction to north-west.
Definition: track_type.h:85
Right track and direction to north.
Definition: track_type.h:89
X-axis and direction to south-west.
Definition: track_type.h:84
Left track and direction to north.
Definition: track_type.h:88
Upper track and direction to west.
Definition: track_type.h:86
Y-axis and direction to south-east.
Definition: track_type.h:77
Lower track and direction to east.
Definition: track_type.h:79
Left track and direction to south.
Definition: track_type.h:80
Right track and direction to south.
Definition: track_type.h:81
Lower track and direction to west.
Definition: track_type.h:87
Upper track and direction to east.
Definition: track_type.h:78
Flag for an invalid trackdir.
Definition: track_type.h:93
X-axis and direction to north-east.
Definition: track_type.h:76

◆ _trackdir_to_exitdir

const DiagDirection _trackdir_to_exitdir[TRACKDIR_END]
Initial value: