rail.h File Reference

Rail specific functions. More...

#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 "slope_type.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...

Enumerations

enum  RailTypeFlag { RTF_CATENARY = 0 }
enum  RailTypeFlags { RTFB_NONE = 0, RTFB_CATENARY = 1 << RTF_CATENARY }
enum  RailFenceOffset {
  RFO_FLAT_X, RFO_FLAT_Y, RFO_FLAT_VERT, RFO_FLAT_HORZ,
  RFO_SLOPE_SW, RFO_SLOPE_SE, RFO_SLOPE_NE, RFO_SLOPE_NW
}
 Offsets from base sprite for fence sprites. More...

Functions

 DECLARE_ENUM_AS_BIT_SET (RailTypeFlags)
static const RailtypeInfoGetRailTypeInfo (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.
Vehicle * 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)
Vehicle * EnsureNoTrainOnTrackProc (Vehicle *v, void *data)
int TicksToLeaveDepot (const Vehicle *v)
 Compute number of ticks when next wagon will leave a depot.
Foundation GetRailFoundation (Slope tileh, TrackBits bits)
 Checks if a track combination is valid on a specific slope and returns the needed foundation.
bool HasRailtypeAvail (const CompanyID company, const RailType railtype)
 Finds out if a company has a certain railtype available.
bool ValParamRailtype (const RailType rail)
 Validate functions for rail building.
RailType GetBestRailtype (const CompanyID company)
 Returns the "best" railtype a company can build.
RailTypes GetCompanyRailtypes (const CompanyID c)
 Get the rail types the given company can build.
RailType GetRailTypeByLabel (RailTypeLabel label)
 Get the rail type for a given label.
void ResetRailTypes ()
 Reset all rail type information to its default values.


Detailed Description

Rail specific functions.

Definition in file rail.h.


Enumeration Type Documentation

Offsets from base sprite for fence sprites.

These are in the order of the sprites in the original data files.

Definition at line 29 of file rail.h.

Enumerator:
RTF_CATENARY  Set if the rail type should have catenary drawn.

Definition at line 16 of file rail.h.


Function Documentation

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

Definition at line 181 of file rail.cpp.

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

Referenced by SetDefaultRailGui().

RailTypes GetCompanyRailtypes ( const CompanyID  c  ) 

Get the rail types the given company can build.

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

Definition at line 189 of file rail.cpp.

References _date, _settings_game, EngineInfo::climates, DAYS_IN_YEAR, GameSettings::game_creation, HasBit(), GameCreationSettings::landscape, RAILTYPE_END, RAILTYPES_NONE, RAILVEH_WAGON, and SetBit().

Referenced by DoStartupNewCompany(), and SettingsDisableElrail().

Foundation GetRailFoundation ( Slope  tileh,
TrackBits  bits 
)

RailType GetRailTypeByLabel ( RailTypeLabel  label  ) 

Get the rail type for a given label.

Parameters:
label the railtype label.
Returns:
the railtype.

Definition at line 211 of file rail.cpp.

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

Referenced by RailVehicleChangeInfo().

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

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 176 of file rail.h.

References GetRailTypeInfo(), and HasBit().

Referenced by CmdBuildRailVehicle(), CmdBuildSingleRail(), CmdConvertRail(), AIEngine::HasPowerOnRail(), RailConvertCost(), AIRail::TrainHasPowerOnRail(), and TrainPowerChanged().

bool HasRailtypeAvail ( const CompanyID  company,
const RailType  railtype 
)

Finds out if a company has a certain railtype available.

Parameters:
company the company in question
railtype requested RailType
Returns:
true if company has requested RailType available

Definition at line 171 of file rail.cpp.

References HasBit().

Referenced by GetBestRailtype(), AIRail::IsRailTypeAvailable(), SetDefaultRailGui(), 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 163 of file rail.h.

References GetRailTypeInfo(), and HasBit().

Referenced by AIEngine::CanRunOnRail(), CmdBuildRailWagon(), CmdBuildSingleRail(), CmdConvertRail(), and AIRail::TrainCanRunOnRail().

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 186 of file rail.h.

References GetRailTypeInfo(), and 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 198 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 2431 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 company may build the rail.

Definition at line 176 of file rail.cpp.

References HasRailtypeAvail().

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


Generated on Sun Nov 15 15:40:22 2009 for OpenTTD by  doxygen 1.5.6