|
OpenTTD Source 20251116-master-g21329071df
|
Rail specific functions. More...
#include "rail_type.h"#include "track_type.h"#include "gfx_type.h"#include "core/bitmath_func.hpp"#include "core/enum_type.hpp"#include "core/flatset_type.hpp"#include "economy_func.h"#include "slope_type.h"#include "strings_type.h"#include "timer/timer_game_calendar.h"#include "signal_type.h"#include "settings_type.h"#include "newgrf_badge_type.h"Go to the source code of this file.
Data Structures | |
| class | RailTypeInfo |
| This struct contains all the info that is needed to draw and construct tracks. More... | |
Typedefs | |
| using | RailTypeFlags = EnumBitSet< RailTypeFlag, uint8_t > |
Functions | |
| const RailTypeInfo * | GetRailTypeInfo (RailType railtype) |
| Returns a pointer to the Railtype information for a given railtype. | |
| RailTypes | GetAllCompatibleRailTypes (RailTypes railtypes) |
| Returns all compatible railtypes for a set of railtypes. | |
| RailTypes | GetAllPoweredRailTypes (RailTypes railtypes) |
| Returns all powered railtypes for a set of railtypes. | |
| RailTypes | GetAllIntroducesRailTypes (RailTypes railtypes) |
| Returns all introduced railtypes for a set of railtypes. | |
| bool | IsCompatibleRail (RailType enginetype, RailType tiletype) |
| Checks if an engine of the given RailType can drive on a tile with a given RailType. | |
| bool | IsCompatibleRail (RailTypes enginetype, RailType tiletype) |
| Checks if an engine of the given RailTypes can drive on a tile with a given RailType. | |
| bool | HasPowerOnRail (RailType enginetype, RailType tiletype) |
| Checks if an engine of the given RailType got power on a tile with a given RailType. | |
| bool | HasPowerOnRail (RailTypes enginetype, RailType tiletype) |
| Checks if an engine of the given RailTypes got power on a tile with a given RailType. | |
| bool | RailNoLevelCrossings (RailType rt) |
| Test if a RailType disallows build of level crossings. | |
| bool | Rail90DegTurnDisallowed (RailType rt1, RailType rt2, bool def=_settings_game.pf.forbid_90_deg) |
| Test if 90 degree turns are disallowed between two railtypes. | |
| Money | RailBuildCost (RailType railtype) |
| Returns the cost of building the specified railtype. | |
| Money | RailClearCost (RailType railtype) |
| Returns the 'cost' of clearing the specified railtype. | |
| Money | RailConvertCost (RailType from, RailType to) |
| Calculates the cost of rail conversion. | |
| Money | RailMaintenanceCost (RailType railtype, uint32_t num, uint32_t total_num) |
| Calculates the maintenance cost of a number of track bits. | |
| Money | SignalMaintenanceCost (uint32_t 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 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=true) |
| 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=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. | |
Variables | |
| std::vector< RailType > | _sorted_railtypes |
| Sorted list of rail types. | |
| RailTypes | _railtypes_hidden_mask |
Rail specific functions.
Definition in file rail.h.
| using RailTypeFlags = EnumBitSet<RailTypeFlag, uint8_t> |
| enum RailFenceOffset : uint8_t |
Offsets from base sprite for fence sprites.
These are in the order of the sprites in the original data files.
| enum RailTrackBridgeOffset : uint8_t |
| enum RailTrackOffset : uint8_t |
Offsets for sprites within an overlay/underlay set.
These are the same for overlay and underlay sprites.
|
strong |
Railtype flag bit numbers.
| enum RailTypeSpriteGroup : uint8_t |
Sprite groups for a railtype.
| Enumerator | |
|---|---|
| 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. |
| RTSG_SIGNALS | Signal images. |
| RTSG_GROUND_COMPLETE | Complete ground images. |
| RailTypes AddDateIntroducedRailTypes | ( | RailTypes | current, |
| TimerGameCalendar::Date | date | ||
| ) |
Add the rail types that are to be introduced at the given date.
| current | The currently available railtypes. |
| date | The date for the introduction comparisons. |
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().
| RailType AllocateRailType | ( | RailTypeLabel | label | ) |
Allocate a new rail type label.
Definition at line 148 of file rail_cmd.cpp.
References _original_railtypes, RailTypeInfo::alternate_labels, RailTypeInfo::compatible_railtypes, RailTypeInfo::Index(), RailTypeInfo::introduces_railtypes, INVALID_RAILTYPE, RailTypeInfo::label, RailTypeInfo::powered_railtypes, RAILTYPE_RAIL, and RailTypeInfo::sorting_order.
| void DrawTrainDepotSprite | ( | int | x, |
| int | y, | ||
| int | image, | ||
| RailType | railtype | ||
| ) |
Definition at line 2535 of file rail_cmd.cpp.
Returns all compatible railtypes for a set of railtypes.
| railtypes | Set of railtypes to get the compatible railtypes from. |
Definition at line 313 of file rail.h.
References RailTypeInfo::compatible_railtypes, GetRailTypeInfo(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().
Referenced by CheckAutoreplaceValidity(), FollowTrainReservation(), FreeTrainTrackReservation(), IsCompatibleRail(), IsEngineBuildable(), and IsSafeWaitingPosition().
Returns all introduced railtypes for a set of railtypes.
| railtypes | Set of railtypes to get the introduced railtypes from. |
Definition at line 337 of file rail.h.
References GetRailTypeInfo(), RailTypeInfo::introduces_railtypes, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().
Referenced by GetCompanyRailTypes(), GetRailTypes(), and NewVehicleAvailable().
Returns all powered railtypes for a set of railtypes.
| railtypes | Set of railtypes to get the powered railtypes from. |
Definition at line 325 of file rail.h.
References GetRailTypeInfo(), RailTypeInfo::powered_railtypes, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().
Referenced by Train::ConsistChanged(), and HasPowerOnRail().
Get the rail types the given company can build.
| company | the company to get the rail types for. |
| introduces | If true, include rail types introduced by other 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().
| 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 309 of file rail_cmd.cpp.
References _valid_tracks_without_foundation, CornerToTrackBits(), FOUNDATION_INCLINED_X, FOUNDATION_INCLINED_Y, FOUNDATION_INVALID, FOUNDATION_LEVELED, FOUNDATION_NONE, 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(), DrawRailCatenaryRailway(), 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 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().
|
inline |
Returns a pointer to the Railtype information for a given railtype.
| railtype | the rail type which the information is requested for |
Definition at line 301 of file rail.h.
References RAILTYPE_END.
Referenced by AddDateIntroducedRailTypes(), CompareRailTypes(), DrawBridgeMiddle(), DrawStationTile(), DrawTile_Road(), DrawTile_TunnelBridge(), DrawTrackBits(), BuildSignalWindow::DrawWidget(), FinaliseEngineArray(), Train::GetAccelerationType(), GetAllCompatibleRailTypes(), GetAllIntroducesRailTypes(), GetAllPoweredRailTypes(), NIHRailType::GetBadges(), GetBridgeSpriteTableBaseOffset(), Train::GetCurveSpeedLimit(), GetEngineCategoryName(), GetGlobalVariable(), Train::GetMaxTrackSpeed(), GetNewEngine(), GetPylonBase(), GetRailTypeDropDownList(), GetRailTypeTranslation(), GetReverseRailTypeTranslation(), GetSmallMapRoutesPixels(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::GetSpeedLimit(), GetTrainForReservation(), ReplaceVehicleWindow::GetWidgetString(), BuildVehicleWindow::GetWidgetString(), BuildRailToolbarWindow::GetWidgetString(), GetWireBase(), HasPowerOnRail(), HasRailCatenary(), IsCompatibleRail(), BuildRailToolbarWindow::OnClick(), BuildRailToolbarWindow::OnInit(), BuildSignalWindow::OnInit(), Rail90DegTurnDisallowed(), RailBuildCost(), RailMaintenanceCost(), RailNoLevelCrossings(), ResetNewGRFData(), RAILChunkHandler::Save(), SetCurrentRailTypeLabelList(), ReplaceVehicleWindow::UpdateWidgetSize(), and CompanyInfrastructureWindow::UpdateWidgetSize().
| RailTypes GetRailTypes | ( | bool | introduces | ) |
Get list of rail types, regardless of company availability.
| introduces | If true, include rail types introduced by other 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().
| bool HasAnyRailTypesAvail | ( | const CompanyID | company | ) |
Test if any buildable railtype is available for a company.
| company | the company in question |
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().
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 377 of file rail.h.
References GetRailTypeInfo(), RailTypeInfo::powered_railtypes, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Referenced by CheckFlatLandRailStation(), CmdBuildRailVehicle(), CmdBuildSingleRail(), CmdConvertRail(), Train::GetPower(), Train::GetPoweredPartPower(), RailConvertCost(), and Vehicle::ShowVisualEffect().
Checks if an engine of the given RailTypes got power on a tile with a given RailType.
| enginetype | The RailTypes of the engine we are considering. |
| tiletype | The RailType of the tile we are considering. |
Definition at line 389 of file rail.h.
References GetAllPoweredRailTypes(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Finds out if a company has a certain buildable railtype available.
| company | the company in question |
| railtype | requested RailType |
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().
| void InitRailTypes | ( | ) |
Resolve sprites of custom rail types.
Definition at line 130 of file rail_cmd.cpp.
References _sorted_railtypes, CompareRailTypes(), RailTypeInfo::flags, Hidden, RailTypeInfo::Index(), RailTypeInfo::label, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Referenced by AfterLoadGRFs().
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 352 of file rail.h.
References RailTypeInfo::compatible_railtypes, GetRailTypeInfo(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Referenced by CmdBuildRailWagon(), CmdBuildSingleRail(), CmdConvertRail(), and IsCompatibleTrainStationTile().
Checks if an engine of the given RailTypes can drive on a tile with a given RailType.
| enginetype | The RailTypes of the engine we are considering. |
| tiletype | The RailType of the tile we are considering. |
Definition at line 364 of file rail.h.
References GetAllCompatibleRailTypes(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
|
inline |
Test if 90 degree turns are disallowed between two railtypes.
| rt1 | First railtype to test for. |
| rt2 | Second railtype to test for. |
| def | Default value to use if the rail type doesn't specify anything. |
Definition at line 411 of file rail.h.
References Allow90Deg, Disallow90Deg, RailTypeInfo::flags, GetRailTypeInfo(), INVALID_RAILTYPE, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Referenced by CheckNextTrainTile(), ExtendTrainReservation(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), IsSafeWaitingPosition(), IsWaitingPositionFree(), TrainCheckIfLineEnds(), TrainController(), and TryPathReserve().
Returns the cost of building the specified railtype.
| railtype | The railtype being built. |
Definition at line 429 of file rail.h.
References GetRailTypeInfo(), and RAILTYPE_END.
Referenced by CalculateRailStationCost(), CmdBuildBridge(), CmdBuildSingleRail(), CmdBuildTrainDepot(), CmdBuildTunnel(), GetRailTypeDropDownList(), RailClearCost(), RailConvertCost(), and ShowBuildBridgeWindow().
Returns the 'cost' of clearing the specified railtype.
| railtype | The railtype being removed. |
Definition at line 440 of file rail.h.
References RailBuildCost(), and RAILTYPE_END.
Referenced by CmdRemoveSingleRail(), RailConvertCost(), and TunnelBridgeClearCost().
Calculates the cost of rail conversion.
| from | The railtype we are converting from |
| to | The railtype we are converting to |
Definition at line 457 of file rail.h.
References HasPowerOnRail(), RailBuildCost(), and RailClearCost().
Referenced by CmdConvertRail().
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 484 of file rail.h.
References GetRailTypeInfo(), IntSqrt(), and RAILTYPE_END.
Referenced by CompaniesGenStatistics().
|
inline |
Test if a RailType disallows build of level crossings.
| rt | The RailType to check. |
Definition at line 399 of file rail.h.
References RailTypeInfo::flags, GetRailTypeInfo(), NoLevelCrossing, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
Referenced by CmdBuildRoad(), CmdBuildSingleRail(), and CmdConvertRail().
| void ResetRailTypes | ( | ) |
Reset all rail type information to its default values.
Definition at line 65 of file rail_cmd.cpp.
References _original_railtypes.
Referenced by ResetNewGRFData().
|
inline |
Calculates the maintenance cost of a number of signals.
| num | Number of signals. |
Definition at line 495 of file rail.h.
References IntSqrt().
Referenced by CompaniesGenStatistics().
| 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 2911 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 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().
|
extern |
Definition at line 48 of file rail_cmd.cpp.
|
extern |
Sorted list of rail types.
Definition at line 47 of file rail_cmd.cpp.
Referenced by GetRailTypeDropDownList(), InitRailTypes(), SetDefaultRailGui(), ReplaceVehicleWindow::UpdateWidgetSize(), and CompanyInfrastructureWindow::UpdateWidgetSize().