OpenTTD Source: src/road.h File Reference

OpenTTD Source 15.3

Data Structures | Typedefs | Enumerations | Functions | Variables
road.h File Reference

Road specific functions. More...

`#include "road_type.h"`
`#include "gfx_type.h"`
`#include "core/flatset_type.hpp"`
`#include "strings_type.h"`
`#include "timer/timer_game_calendar.h"`
`#include "core/enum_type.hpp"`
`#include "newgrf.h"`
`#include "newgrf_badge_type.h"`
`#include "economy_func.h"`

Go to the source code of this file.

## Data Structures
class | RoadTypeInfo

## Typedefs
using | RoadTypeFlags = EnumBitSet< RoadTypeFlag, uint8_t >

## Enumerations
enum class | RoadTypeFlag : uint8_t { Catenary = 0 , NoLevelCrossing = 1 , NoHouses = 2 , Hidden = 3 , TownBuild = 4 }
| Roadtype flag bit numbers. More...
enum | RoadTypeSpriteGroup : uint8_t { ROTSG_CURSORS , ROTSG_OVERLAY , ROTSG_GROUND , ROTSG_TUNNEL , ROTSG_CATENARY_FRONT , ROTSG_CATENARY_BACK , ROTSG_BRIDGE , ROTSG_reserved2 , ROTSG_DEPOT , ROTSG_reserved3 , ROTSG_ROADSTOP , ROTSG_ONEWAY , ROTSG_END }
| Sprite groups for a roadtype. More...

## Functions
RoadTypes | GetMaskForRoadTramType (RoadTramType rtt)
| Get the mask for road types of the given RoadTramType.
bool | RoadTypeIsRoad (RoadType roadtype)
bool | RoadTypeIsTram (RoadType roadtype)
RoadTramType | GetRoadTramType (RoadType roadtype)
RoadTramType | OtherRoadTramType (RoadTramType rtt)
const RoadTypeInfo * | GetRoadTypeInfo (RoadType roadtype)
| Returns a pointer to the Roadtype information for a given roadtype.
bool | HasPowerOnRoad (RoadType enginetype, RoadType tiletype)
| Checks if an engine of the given RoadType got power on a tile with a given RoadType.
Money | RoadBuildCost (RoadType roadtype)
| Returns the cost of building the specified roadtype.
Money | RoadClearCost (RoadType roadtype)
| Returns the cost of clearing the specified roadtype.
Money | RoadConvertCost (RoadType from, RoadType to)
| Calculates the cost of road conversion.
bool | RoadNoLevelCrossing (RoadType roadtype)
| Test if road disallows level crossings.
RoadType | GetRoadTypeByLabel (RoadTypeLabel label, bool allow_alternate_labels=true)
| Get the road type for a given label.
void | ResetRoadTypes ()
| Reset all road type information to its default values.
void | InitRoadTypes ()
| Resolve sprites of custom road types.
RoadType | AllocateRoadType (RoadTypeLabel label, RoadTramType rtt)
| Allocate a new road type label.
bool | HasAnyRoadTypesAvail (CompanyID company, RoadTramType rtt)
| Test if any buildable RoadType is available for a company.

## Variables
std::vector< RoadType > | _sorted_roadtypes
| Sorted list of road types.
RoadTypes | _roadtypes_hidden_mask
| Bitset of hidden roadtypes.

## Detailed Description

Road specific functions.

Definition in file road.h.

## Typedef Documentation

## ◆ RoadTypeFlags

using RoadTypeFlags = EnumBitSet<RoadTypeFlag, uint8_t>

Definition at line 31 of file road.h.

## Enumeration Type Documentation

## ◆ RoadTypeFlag

enum class RoadTypeFlag : uint8_t
| strong

Roadtype flag bit numbers.

Enumerator
Catenary | Bit number for adding catenary.
NoLevelCrossing | Bit number for disabling level crossing.
NoHouses | Bit number for setting this roadtype as not house friendly.
Hidden | Bit number for hidden from construction.
TownBuild | Bit number for allowing towns to build this roadtype.

Definition at line 24 of file road.h.

## ◆ RoadTypeSpriteGroup

enum RoadTypeSpriteGroup : uint8_t

Sprite groups for a roadtype.

Enumerator
ROTSG_CURSORS | Optional: Cursor and toolbar icon images.
ROTSG_OVERLAY | Optional: Images for overlaying track.
ROTSG_GROUND | Required: Main group of ground images.
ROTSG_TUNNEL | Optional: Ground images for tunnels.
ROTSG_CATENARY_FRONT | Optional: Catenary front.
ROTSG_CATENARY_BACK | Optional: Catenary back.
ROTSG_BRIDGE | Required: Bridge surface images.
ROTSG_reserved2 | Placeholder, if we need specific level crossing sprites.
ROTSG_DEPOT | Optional: Depot images.
ROTSG_reserved3 | Placeholder, if we add road fences (for highways).
ROTSG_ROADSTOP | Required: Bay stop surface.
ROTSG_ONEWAY | Optional: One-way indicator images.

Definition at line 36 of file road.h.

## Function Documentation

## ◆ AllocateRoadType()

RoadType AllocateRoadType | ( | RoadTypeLabel | label,
|  | RoadTramType | rtt
| ) |  |

Allocate a new road type label.

Definition at line 129 of file road_cmd.cpp.

References _original_roadtypes, _roadtypes_road, _roadtypes_tram, RoadTypeInfo::alternate_labels, RoadTypeInfo::flags, RoadTypeInfo::Index(), RoadTypeInfo::introduces_roadtypes, RoadTypeInfo::introduction_date, TimerGameConst< struct Calendar >::INVALID_DATE, INVALID_ROADTYPE, RoadTypeInfo::label, RoadTypeInfo::powered_roadtypes, ROADTYPE_ROAD, ROADTYPE_TRAM, RTT_ROAD, RTT_TRAM, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and RoadTypeInfo::sorting_order.

## ◆ GetMaskForRoadTramType()

RoadTypes GetMaskForRoadTramType | ( | RoadTramType | rtt | ) |
| inline

Get the mask for road types of the given RoadTramType.

Parameters

  rtt | RoadTramType.

Returns
  Mask of road types for RoadTramType.

Definition at line 183 of file road.h.

References _roadtypes_road, _roadtypes_tram, and RTT_ROAD.

Referenced by CompanyInfrastructure::GetRoadTramTotal(), GetTownRoadType(), GetTownRoadTypeFirstIntroductionDate(), HasAnyRoadTypesAvail(), ScenarioEditorToolbarWindow::OnPaint(), and BuildRoadToolbarWindow::RoadTramToolbarGlobalHotkeys().

## ◆ GetRoadTramType()

RoadTramType GetRoadTramType | ( | RoadType | roadtype | ) |
| inline

Definition at line 200 of file road.h.

## ◆ GetRoadTypeByLabel()

RoadType GetRoadTypeByLabel | ( | RoadTypeLabel | label,
|  | bool | allow_alternate_labels
| ) |  |

Get the road type for a given label.

Parameters

  label | the roadtype label.
  allow_alternate_labels | Search in the alternate label lists as well.

Returns
  the roadtype.

Definition at line 265 of file road.cpp.

References RoadTypeInfo::alternate_labels, FlatSet< Tkey, Tcompare >::contains(), INVALID_ROADTYPE, RoadTypeInfo::label, and ROADTYPE_END.

Referenced by AfterLoadGRFs(), ConvertRoadTypes(), RoadTypeResolverObject::GetFeature(), GetRoadTypeTranslation(), and RoadTypeChangeInfo().

## ◆ GetRoadTypeInfo()

const RoadTypeInfo * GetRoadTypeInfo | ( | RoadType | roadtype | ) |
| inline

Returns a pointer to the Roadtype information for a given roadtype.

Parameters

  roadtype | the road type which the information is requested for

Returns
  The pointer to the RoadTypeInfo

Definition at line 215 of file road.h.

References ROADTYPE_END.

Referenced by AddDateIntroducedRoadTypes(), AfterLoadVehiclesPhase2(), CheckAutoreplaceValidity(), CmdBuildRoadVehicle(), CompareRoadTypes(), DrawBridgeRoadBits(), DrawRoadBits(), DrawRoadDepotSprite(), DrawRoadStopTile(), DrawRoadTypeCatenary(), DrawTile_Road(), DrawTile_TunnelBridge(), FinaliseEngineArray(), NIHRoadType< TRoadTramType >::GetBadges(), GetCompanyRoadTypes(), GetEngineCategoryName(), RoadVehicle::GetMaxTrackSpeed(), GetReverseRoadTypeTranslation(), GetRoadTypes(), GetSmallMapRoutesPixels(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::GetSpeedLimit(), GetTownRoadType(), GetTownRoadTypeFirstIntroductionDate(), ReplaceVehicleWindow::GetWidgetString(), BuildVehicleWindow::GetWidgetString(), BuildRoadToolbarWindow::GetWidgetString(), HasPowerOnRoad(), HasRoadCatenary(), HasRoadTypeAvail(), IsEngineBuildable(), NewVehicleAvailable(), BuildRoadToolbarWindow::OnClick(), BuildRoadToolbarWindow::OnInit(), BuildRoadToolbarWindow::OnPlaceMouseUp(), BuildRoadToolbarWindow::OnPlaceObject(), RoadBuildCost(), RoadMaintenanceCost(), RoadNoLevelCrossing(), RoadTypesAllowHouseHere(), ROTTChunkHandler::Save(), SetCurrentRoadTypeLabelList(), TownCanGrowRoad(), ReplaceVehicleWindow::UpdateWidgetSize(), and CompanyInfrastructureWindow::UpdateWidgetSize().

## ◆ HasAnyRoadTypesAvail()

bool HasAnyRoadTypesAvail | ( | CompanyID | company,
|  | RoadTramType | rtt
| ) |  |

Test if any buildable RoadType is available for a company.

Parameters

  company | the company in question

Returns
  true if company has any RoadTypes available

Definition at line 152 of file road.cpp.

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

Referenced by CanBuildVehicleInfrastructure().

## ◆ HasPowerOnRoad()

bool HasPowerOnRoad | ( | RoadType | enginetype,
|  | RoadType | tiletype
| ) |  |
| inline

Checks if an engine of the given RoadType got power on a tile with a given RoadType.

This would normally just be an equality check, but for electrified roads (which also support non-electric vehicles).

Parameters

  enginetype | The RoadType of the engine we are considering.
  tiletype | The RoadType of the tile we are considering.

Returns
  Whether the engine got power on this tile.

Definition at line 230 of file road.h.

References GetRoadTypeInfo(), RoadTypeInfo::powered_roadtypes, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CanConnectToRoad(), CheckFlatLandRoadStop(), CmdBuildRoad(), and CmdConvertRoad().

## ◆ InitRoadTypes()

void InitRoadTypes | ( |  | ) |

Resolve sprites of custom road types.

Definition at line 111 of file road_cmd.cpp.

References _roadtypes_hidden_mask, _sorted_roadtypes, CompareRoadTypes(), RoadTypeInfo::flags, Hidden, RoadTypeInfo::Index(), RoadTypeInfo::label, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by AfterLoadGRFs().

## ◆ OtherRoadTramType()

RoadTramType OtherRoadTramType | ( | RoadTramType | rtt | ) |
| inline

Definition at line 205 of file road.h.

## ◆ ResetRoadTypes()

void ResetRoadTypes | ( |  | ) |

Reset all road type information to its default values.

Definition at line 63 of file road_cmd.cpp.

References _original_roadtypes, _roadtypes_hidden_mask, _roadtypes_road, _roadtypes_tram, ROADTYPE_ROAD, and ROADTYPE_TRAM.

Referenced by ResetNewGRFData().

## ◆ RoadBuildCost()

Money RoadBuildCost | ( | RoadType | roadtype | ) |
| inline

Returns the cost of building the specified roadtype.

Parameters

  roadtype | The roadtype being built.

Returns
  The cost multiplier.

Definition at line 240 of file road.h.

References GetRoadTypeInfo(), and ROADTYPE_END.

Referenced by CheckFlatLandRoadStop(), CmdBuildBridge(), CmdBuildRoad(), CmdBuildSingleRail(), CmdBuildTunnel(), RoadClearCost(), RoadConvertCost(), and ShowBuildBridgeWindow().

## ◆ RoadClearCost()

Money RoadClearCost | ( | RoadType | roadtype | ) |
| inline

Returns the cost of clearing the specified roadtype.

Parameters

  roadtype | The roadtype being removed.

Returns
  The cost.

Definition at line 251 of file road.h.

References RoadBuildCost(), and ROADTYPE_END.

Referenced by RemoveRoad(), RoadConvertCost(), and TunnelBridgeClearCost().

## ◆ RoadConvertCost()

Money RoadConvertCost | ( | RoadType | from,
|  | RoadType | to
| ) |  |
| inline

Calculates the cost of road conversion.

Parameters

  from | The roadtype we are converting from
  to | The roadtype we are converting to

Returns
  Cost per RoadBit

Definition at line 269 of file road.h.

References RoadBuildCost(), and RoadClearCost().

Referenced by CmdConvertRoad().

## ◆ RoadNoLevelCrossing()

bool RoadNoLevelCrossing | ( | RoadType | roadtype | ) |
| inline

Test if road disallows level crossings.

Parameters

  roadtype | The roadtype we are testing

Returns
  True iff the roadtype disallows level crossings

Definition at line 283 of file road.h.

References RoadTypeInfo::flags, GetRoadTypeInfo(), NoLevelCrossing, ROADTYPE_END, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CmdBuildRoad(), CmdBuildSingleRail(), and CmdConvertRoad().

## ◆ RoadTypeIsRoad()

bool RoadTypeIsRoad | ( | RoadType | roadtype | ) |
| inline

Definition at line 190 of file road.h.

## ◆ RoadTypeIsTram()

bool RoadTypeIsTram | ( | RoadType | roadtype | ) |
| inline

Definition at line 195 of file road.h.

## Variable Documentation

## ◆ _roadtypes_hidden_mask

RoadTypes _roadtypes_hidden_mask
| extern

Bitset of hidden roadtypes.

Definition at line 56 of file road_cmd.cpp.

Referenced by HasAnyRoadTypesAvail(), HasRoadTypeAvail(), InitRoadTypes(), and ResetRoadTypes().

## ◆ _sorted_roadtypes

std::vector<RoadType> _sorted_roadtypes
| extern

Sorted list of road types.

Definition at line 55 of file road_cmd.cpp.

Referenced by InitRoadTypes(), ReplaceVehicleWindow::UpdateWidgetSize(), and CompanyInfrastructureWindow::UpdateWidgetSize().