OpenTTD Source: src/road.h File Reference

OpenTTD Source 1.11.0-RC1

Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
road.h File Reference
`#include "road_type.h"`
`#include "gfx_type.h"`
`#include "core/bitmath_func.hpp"`
`#include "strings_type.h"`
`#include "date_type.h"`
`#include "core/enum_type.hpp"`
`#include "newgrf.h"`
`#include "economy_func.h"`
`#include <vector>`

Go to the source code of this file.

## Data Structures
class | RoadTypeInfo

## Macros
#define | FOR_ALL_ROADTRAMTYPES(x) for (RoadTramType x : { RTT_ROAD, RTT_TRAM })
#define | FOR_ALL_SORTED_ROADTYPES(var) for (uint8 index = 0; index < _sorted_roadtypes.size() && (var = _sorted_roadtypes[index], true) ; index++)
| Loop header for iterating over roadtypes, sorted by sortorder. More...

## Typedefs
typedef std::vector< RoadTypeLabel > | RoadTypeLabelList
| List of road type labels.

## Enumerations
enum | RoadTramType : bool { RTT_ROAD, RTT_TRAM }
enum | RoadTramTypes : uint8 { RTTB_ROAD = 1 << RTT_ROAD, RTTB_TRAM = 1 << RTT_TRAM }
enum | RoadTypeFlags { ROTF_CATENARY = 0, ROTF_NO_LEVEL_CROSSING, ROTF_NO_HOUSES, ROTF_HIDDEN, ROTF_TOWN_BUILD, ROTFB_NONE = 0, ROTFB_CATENARY = 1 << ROTF_CATENARY, ROTFB_NO_LEVEL_CROSSING = 1 << ROTF_NO_LEVEL_CROSSING, ROTFB_NO_HOUSES = 1 << ROTF_NO_HOUSES, ROTFB_HIDDEN = 1 << ROTF_HIDDEN, ROTFB_TOWN_BUILD = 1 << ROTF_TOWN_BUILD }
| Roadtype flags. More...
enum | RoadTypeSpriteGroup { ROTSG_CURSORS, ROTSG_OVERLAY, ROTSG_GROUND, ROTSG_reserved1, ROTSG_CATENARY_FRONT, ROTSG_CATENARY_BACK, ROTSG_BRIDGE, ROTSG_reserved2, ROTSG_DEPOT, ROTSG_reserved3, ROTSG_ROADSTOP, ROTSG_END }
| Sprite groups for a roadtype. More...

## Functions
static bool | RoadTypeIsRoad (RoadType roadtype)
static bool | RoadTypeIsTram (RoadType roadtype)
static RoadTramType | GetRoadTramType (RoadType roadtype)
static RoadTramType | OtherRoadTramType (RoadTramType rtt)
static const RoadTypeInfo * | GetRoadTypeInfo (RoadType roadtype)
| Returns a pointer to the Roadtype information for a given roadtype. More...
static bool | HasPowerOnRoad (RoadType enginetype, RoadType tiletype)
| Checks if an engine of the given RoadType got power on a tile with a given RoadType. More...
static Money | RoadBuildCost (RoadType roadtype)
| Returns the cost of building the specified roadtype. More...
static Money | RoadClearCost (RoadType roadtype)
| Returns the cost of clearing the specified roadtype. More...
static Money | RoadConvertCost (RoadType from, RoadType to)
| Calculates the cost of road conversion. More...
static bool | RoadNoLevelCrossing (RoadType roadtype)
| Test if road disallows level crossings. More...
RoadType | GetRoadTypeByLabel (RoadTypeLabel label, bool allow_alternate_labels=true)
| Get the road type for a given label. More...
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. More...

## Variables
RoadTypes | _roadtypes_type
| Bitmap of road/tram types. More...
std::vector< RoadType > | _sorted_roadtypes
RoadTypes | _roadtypes_hidden_mask

## Detailed Description

Road specific functions.

Definition in file road.h.

## Macro Definition Documentation

## ◆ FOR_ALL_SORTED_ROADTYPES

#define FOR_ALL_SORTED_ROADTYPES | ( |  | var | ) | for (uint8 index = 0; index < _sorted_roadtypes.size() && (var = _sorted_roadtypes[index], true) ; index++)

Loop header for iterating over roadtypes, sorted by sortorder.

Parameters

  var | Roadtype.

Definition at line 312 of file road.h.

## Enumeration Type Documentation

## ◆ RoadTypeFlags

enum RoadTypeFlags

Roadtype flags.

Starts with RO instead of R because R is used for rails

Enumerator
ROTF_CATENARY | Bit number for adding catenary.
ROTF_NO_LEVEL_CROSSING | Bit number for disabling level crossing.
ROTF_NO_HOUSES | Bit number for setting this roadtype as not house friendly.
ROTF_HIDDEN | Bit number for hidden from construction.
ROTF_TOWN_BUILD | Bit number for allowing towns to build this roadtype.
ROTFB_NONE | All flags cleared.
ROTFB_CATENARY | Value for drawing a catenary.
ROTFB_NO_LEVEL_CROSSING | Value for disabling a level crossing.
ROTFB_NO_HOUSES | Value for for setting this roadtype as not house friendly.
ROTFB_HIDDEN | Value for hidden from construction.
ROTFB_TOWN_BUILD | Value for allowing towns to build this roadtype.

Definition at line 38 of file road.h.

## ◆ RoadTypeSpriteGroup

enum RoadTypeSpriteGroup

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_reserved1 | Placeholder, if we need specific tunnel sprites.
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: Drive-in stop surface.

Definition at line 57 of file road.h.

## Function Documentation

## ◆ 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 243 of file road.cpp.

References RoadTypeInfo::alternate_labels, GetRoadTypeInfo(), INVALID_ROADTYPE, RoadTypeInfo::label, ROADTYPE_BEGIN, and ROADTYPE_END.

Referenced by RoadTypeResolverObject::GetFeature().

## ◆ GetRoadTypeInfo()

static const RoadTypeInfo* GetRoadTypeInfo | ( | RoadType | roadtype | ) |
| inlinestatic

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 224 of file road.h.

Referenced by AddDateIntroducedRoadTypes(), CheckAutoreplaceValidity(), CmdBuildRoadVehicle(), EnableEngineForCompany(), ExistingRoadTypes(), GetCompanyRoadTypes(), RoadVehicle::GetMaxTrackSpeed(), GetRoadTypeByLabel(), GetRoadTypes(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::GetSpeedLimit(), HasPowerOnRoad(), HasRoadCatenary(), IsEngineBuildable(), ReplaceVehicleWindow::OnPaint(), RoadNoLevelCrossing(), BuildVehicleWindow::SetStringParameters(), and ReplaceVehicleWindow::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 132 of file road.cpp.

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

Referenced by CanBuildVehicleInfrastructure().

## ◆ HasPowerOnRoad()

static bool HasPowerOnRoad | ( | RoadType | enginetype,
|  | RoadType | tiletype
| ) |  |
| inlinestatic

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).

Returns
  Whether the engine got power on this tile.

Parameters

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

Definition at line 239 of file road.h.

References GetRoadTypeInfo(), and HasBit().

## ◆ RoadBuildCost()

static Money RoadBuildCost | ( | RoadType | roadtype | ) |
| inlinestatic

Returns the cost of building the specified roadtype.

Parameters

  roadtype | The roadtype being built.

Returns
  The cost multiplier.

Definition at line 249 of file road.h.

References ROADTYPE_END.

Referenced by RoadConvertCost().

## ◆ RoadClearCost()

static Money RoadClearCost | ( | RoadType | roadtype | ) |
| inlinestatic

Returns the cost of clearing the specified roadtype.

Parameters

  roadtype | The roadtype being removed.

Returns
  The cost.

Definition at line 260 of file road.h.

References ROADTYPE_END.

Referenced by RoadConvertCost().

## ◆ RoadConvertCost()

static Money RoadConvertCost | ( | RoadType | from,
|  | RoadType | to
| ) |  |
| inlinestatic

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 278 of file road.h.

References RoadBuildCost(), and RoadClearCost().

## ◆ RoadNoLevelCrossing()

static bool RoadNoLevelCrossing | ( | RoadType | roadtype | ) |
| inlinestatic

Test if road disallows level crossings.

Parameters

  roadtype | The roadtype we are testing

Returns
  True iff the roadtype disallows level crossings

Definition at line 292 of file road.h.

References GetRoadTypeInfo(), HasBit(), ROADTYPE_END, and ROTF_NO_LEVEL_CROSSING.

## Variable Documentation

## ◆ _roadtypes_type

RoadTypes _roadtypes_type

Bitmap of road/tram types.

Bit if set if a roadtype is tram.

Definition at line 57 of file road_cmd.cpp.

Referenced by ScenarioEditorToolbarWindow::OnPaint().