Rail specific functions. More...
#include "rail_type.h"
#include "track_type.h"
#include "gfx_type.h"
#include "core/bitmath_func.hpp"
#include "economy_func.h"
#include "slope_type.h"
#include "strings_type.h"
#include "date_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... | |
Typedefs | |
typedef SmallVector < RailTypeLabel, 4 > | RailTypeLabelList |
List of rail type labels. | |
Enumerations | |
enum | RailTypeFlags { RTF_CATENARY = 0, RTF_NO_LEVEL_CROSSING = 1, RTFB_NONE = 0, RTFB_CATENARY = 1 << RTF_CATENARY, RTFB_NO_LEVEL_CROSSING = 1 << RTF_NO_LEVEL_CROSSING } |
Railtype flags. More... | |
enum | RailTypeSpriteGroup { RTSG_CURSORS, RTSG_OVERLAY, RTSG_GROUND, RTSG_TUNNEL, RTSG_WIRES, RTSG_PYLONS, RTSG_BRIDGE, RTSG_CROSSING, RTSG_DEPOT, RTSG_FENCES, RTSG_TUNNEL_PORTAL, RTSG_END } |
Sprite groups for a railtype. More... | |
enum | RailTrackOffset { RTO_X, RTO_Y, RTO_N, RTO_S, RTO_E, RTO_W, RTO_SLOPE_NE, RTO_SLOPE_SE, RTO_SLOPE_SW, RTO_SLOPE_NW, RTO_CROSSING_XY, RTO_JUNCTION_SW, RTO_JUNCTION_NE, RTO_JUNCTION_SE, RTO_JUNCTION_NW, RTO_JUNCTION_NSEW } |
Offsets for sprites within an overlay/underlay set. More... | |
enum | RailTrackBridgeOffset { RTBO_X, RTBO_Y, RTBO_SLOPE } |
Offsets for spries within a bridge surface overlay set. More... | |
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 | |
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 bool | RailNoLevelCrossings (RailType rt) |
Test if a RailType disallows build of level crossings. | |
static Money | RailBuildCost (RailType railtype) |
Returns the cost of building the specified railtype. | |
static Money | RailClearCost (RailType railtype) |
Returns the 'cost' of clearing the specified railtype. | |
static Money | RailConvertCost (RailType from, RailType to) |
Calculates the cost of rail conversion. | |
static Money | RailMaintenanceCost (RailType railtype, uint32 num, uint32 total_num) |
Calculates the maintenance cost of a number of track bits. | |
static Money | SignalMaintenanceCost (uint32 num) |
Calculates the maintenance cost of a number of signals. | |
void | DrawTrainDepotSprite (int x, int y, int image, RailType railtype) |
int | TicksToLeaveDepot (const Train *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. | |
RailTypes | AddDateIntroducedRailTypes (RailTypes current, Date date) |
Add the rail types that are to be introduced at the given date. | |
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, bool allow_alternate_labels=true) |
Get the rail type for a given label. | |
void | ResetRailTypes () |
Reset all rail type information to its default values. | |
void | InitRailTypes () |
Resolve sprites of custom rail types. | |
RailType | AllocateRailType (RailTypeLabel label) |
Allocate a new rail type label. |
Rail specific functions.
Definition in file rail.h.
typedef SmallVector<RailTypeLabel, 4> RailTypeLabelList |
enum RailFenceOffset |
enum RailTrackOffset |
Offsets for sprites within an overlay/underlay set.
These are the same for overlay and underlay sprites.
enum RailTypeFlags |
enum RailTypeSpriteGroup |
Sprite groups for a railtype.
RTSG_CURSORS |
Cursor and toolbar icon images. |
RTSG_OVERLAY |
Images for overlaying track. |
RTSG_GROUND |
Main group of ground images. |
RTSG_TUNNEL |
Main group of ground images for snow or desert. |
RTSG_WIRES |
Catenary wires. |
RTSG_PYLONS |
Catenary pylons. |
RTSG_BRIDGE |
Bridge surface images. |
RTSG_CROSSING |
Level crossing overlay images. |
RTSG_DEPOT |
Depot images. |
RTSG_FENCES |
Fence images. |
RTSG_TUNNEL_PORTAL |
Tunnel portal overlay. |
Add the rail types that are to be introduced at the given date.
current | The currently available railtypes. | |
date | The date for the introduction comparisions. |
Definition at line 223 of file rail.cpp.
References AddDateIntroducedRailTypes(), GetRailTypeInfo(), RailtypeInfo::introduces_railtypes, RailtypeInfo::introduction_date, RailtypeInfo::introduction_required_railtypes, IsInsideMM(), RailtypeInfo::label, MAX_DAY, and RAILTYPE_BEGIN.
Referenced by AcceptEnginePreview(), AddDateIntroducedRailTypes(), CheckRailIntroduction(), GetCompanyRailtypes(), GetRailTypeDropDownList(), and NewVehicleAvailable().
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
company | the company "in action" |
Definition at line 208 of file rail.cpp.
References HasRailtypeAvail(), RAILTYPE_ELECTRIC, RAILTYPE_MAGLEV, and RAILTYPE_MONO.
Referenced by SetDefaultRailGui().
Get the rail types the given company can build.
c | the company to get the rail types for. |
Definition at line 255 of file rail.cpp.
References _date, _settings_game, AddDateIntroducedRailTypes(), EngineInfo::climates, Engine::company_avail, DAYS_IN_YEAR, GameSettings::game_creation, GetRailTypeInfo(), HasBit(), Engine::intro_date, RailtypeInfo::introduces_railtypes, GameCreationSettings::landscape, RAILTYPE_END, RAILVEH_WAGON, and VEH_TRAIN.
Referenced by AfterLoadGame(), DoStartupNewCompany(), SettingsDisableElrail(), and StartupEngines().
Foundation GetRailFoundation | ( | Slope | tileh, | |
TrackBits | bits | |||
) |
Checks if a track combination is valid on a specific slope and returns the needed foundation.
tileh | Tile slope. | |
bits | Trackbits. |
Definition at line 266 of file rail_cmd.cpp.
References CornerToTrackBits(), FOUNDATION_INVALID, FOUNDATION_LEVELED, 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().
RailType GetRailTypeByLabel | ( | RailTypeLabel | label, | |
bool | allow_alternate_labels | |||
) |
Get the rail type for a given label.
label | the railtype label. | |
allow_alternate_labels | Search in the alternate label lists as well. |
Definition at line 283 of file rail.cpp.
References RailtypeInfo::alternate_labels, SmallVector< T, S >::Contains(), GetRailTypeInfo(), RailtypeInfo::label, and RAILTYPE_BEGIN.
Referenced by AfterLoadGRFs(), and RailTypeChangeInfo().
static const RailtypeInfo* GetRailTypeInfo | ( | RailType | railtype | ) | [inline, static] |
Returns a pointer to the Railtype information for a given railtype.
railtype | the rail type which the information is requested for |
Definition at line 284 of file rail.h.
References RAILTYPE_END.
Referenced by AcceptEnginePreview(), AddDateIntroducedRailTypes(), AffectSpeedByZChange(), CheckAutoreplaceValidity(), CompareRailTypes(), Train::ConsistChanged(), DrawBridgeMiddle(), DrawStationTile(), DrawTile_Road(), DrawTile_TunnelBridge(), DrawTrackBits(), VehicleDetailsWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), FollowTrainReservation(), FreeTrainTrackReservation(), Train::GetAccelerationType(), GetCompanyRailtypes(), Train::GetCurveSpeedLimit(), GetEngineCategoryName(), GetGlobalVariable(), Train::GetMaxTrackSpeed(), GetNewEngine(), GetPylonBase(), GetRailTypeByLabel(), GetRailTypeDropDownList(), GetReverseRailTypeTranslation(), GetSmallMapRoutesPixels(), GetTrainForReservation(), GetWireBase(), HasCatenary(), HasPowerOnRail(), IsCompatibleRail(), IsEngineBuildable(), IsSafeWaitingPosition(), IsWaitingPositionFree(), NeedRailTypeConversion(), NewVehicleAvailable(), NPFTrainFindNearestSafeTile(), BuildRailToolbarWindow::OnClick(), ReplaceVehicleWindow::OnPaint(), RailBuildCost(), RailMaintenanceCost(), RailNoLevelCrossings(), ResetNewGRFData(), BuildRailToolbarWindow::SetStringParameters(), BuildVehicleWindow::SetStringParameters(), BuildRailToolbarWindow::SetupRailToolbar(), StartupEngines(), TrainController(), CompanyInfrastructureWindow::UpdateWidgetSize(), and ReplaceVehicleWindow::UpdateWidgetSize().
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).
enginetype | The RailType of the engine we are considering. | |
tiletype | The RailType of the tile we are considering. |
Definition at line 312 of file rail.h.
References GetRailTypeInfo(), and HasBit().
Referenced by CheckFlatLandRailStation(), CmdBuildRailVehicle(), CmdBuildSingleRail(), CmdConvertRail(), Train::GetPower(), Train::GetPoweredPartPower(), RailConvertCost(), and Vehicle::ShowVisualEffect().
Finds out if a company has a certain railtype available.
company | the company in question | |
railtype | requested RailType |
Definition at line 186 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(), SetDefaultRailGui(), and ValParamRailtype().
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).
enginetype | The RailType of the engine we are considering. | |
tiletype | The RailType of the tile we are considering. |
Definition at line 299 of file rail.h.
References GetRailTypeInfo(), and HasBit().
Referenced by CmdBuildRailWagon(), CmdBuildSingleRail(), CmdConvertRail(), and IsCompatibleTrainStationTile().
Returns the cost of building the specified railtype.
railtype | The railtype being built. |
Definition at line 332 of file rail.h.
References GetRailTypeInfo(), and RAILTYPE_END.
Referenced by CmdBuildBridge(), CmdBuildRailStation(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), RailClearCost(), RailConvertCost(), and ShowBuildBridgeWindow().
Returns the 'cost' of clearing the specified railtype.
railtype | The railtype being removed. |
Definition at line 343 of file rail.h.
References max(), RailBuildCost(), and RAILTYPE_END.
Referenced by CmdRemoveSingleRail(), and RailConvertCost().
Calculates the cost of rail conversion.
from | The railtype we are converting from | |
to | The railtype we are converting to |
Definition at line 360 of file rail.h.
References HasPowerOnRail(), max(), min(), RailBuildCost(), and RailClearCost().
Referenced by CmdConvertRail().
static Money RailMaintenanceCost | ( | RailType | railtype, | |
uint32 | num, | |||
uint32 | total_num | |||
) | [inline, static] |
Calculates the maintenance cost of a number of track bits.
railtype | The railtype to get the cost of. | |
num | Number of track bits of this railtype. | |
total_num | Total number of track bits of all railtypes. |
Definition at line 387 of file rail.h.
References GetRailTypeInfo(), IntSqrt(), and RAILTYPE_END.
Referenced by CompaniesGenStatistics(), CompanyInfrastructureWindow::DrawWidget(), CompanyInfrastructureWindow::GetTotalMaintenanceCost(), and CompanyInfrastructureWindow::UpdateWidgetSize().
static bool RailNoLevelCrossings | ( | RailType | rt | ) | [inline, static] |
Test if a RailType disallows build of level crossings.
rt | The RailType to check. |
Definition at line 322 of file rail.h.
References GetRailTypeInfo(), HasBit(), and RTF_NO_LEVEL_CROSSING.
Referenced by CmdBuildRoad(), CmdBuildSingleRail(), and CmdConvertRail().
static Money SignalMaintenanceCost | ( | uint32 | num | ) | [inline, static] |
Calculates the maintenance cost of a number of signals.
num | Number of signals. |
Definition at line 398 of file rail.h.
References IntSqrt().
Referenced by CompaniesGenStatistics(), CompanyInfrastructureWindow::DrawWidget(), CompanyInfrastructureWindow::GetTotalMaintenanceCost(), and CompanyInfrastructureWindow::UpdateWidgetSize().
int TicksToLeaveDepot | ( | const Train * | v | ) |
Compute number of ticks when next wagon will leave a depot.
Negative means next wagon should have left depot n ticks before.
v | vehicle outside (leaving) the depot |
Definition at line 2803 of file rail_cmd.cpp.
References Train::CalcNextVehicleOffset(), DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, GetRailDepotDirection(), Vehicle::tile, Vehicle::x_pos, and Vehicle::y_pos.
Referenced by AdvanceWagonsAfterSwap(), CheckTrainsLengths(), and FixupTrainLengths().
bool ValParamRailtype | ( | const RailType | rail | ) |
Validate functions for rail building.
rail | the railtype to check. |
Definition at line 196 of file rail.cpp.
References _current_company, HasRailtypeAvail(), and RAILTYPE_END.
Referenced by CmdBuildBridge(), CmdBuildRailStation(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdConvertRail(), CmdRailTrackHelper(), and ShowBuildRailToolbar().