OpenTTD Source: src/road_func.h File Reference

OpenTTD Source 12.0-beta1

Functions
road_func.h File Reference
`#include "core/bitmath_func.hpp"`
`#include "road.h"`
`#include "economy_func.h"`
`#include "transparency.h"`

Go to the source code of this file.

## Functions
static bool | IsValidRoadBits (RoadBits r)
| Whether the given roadtype is valid. More...
static RoadBits | ComplementRoadBits (RoadBits r)
| Calculate the complement of a RoadBits value. More...
static RoadBits | MirrorRoadBits (RoadBits r)
| Calculate the mirrored RoadBits. More...
static RoadBits | RotateRoadBits (RoadBits r, DiagDirDiff rot)
| Calculate rotated RoadBits. More...
static bool | IsStraightRoad (RoadBits r)
| Check if we've got a straight road. More...
static RoadBits | DiagDirToRoadBits (DiagDirection d)
| Create the road-part which belongs to the given DiagDirection. More...
static RoadBits | AxisToRoadBits (Axis a)
| Create the road-part which belongs to the given Axis. More...
static Money | RoadMaintenanceCost (RoadType roadtype, uint32 num, uint32 total_num)
| Calculates the maintenance cost of a number of road bits. More...
static bool | HasRoadCatenary (RoadType roadtype)
| Test if a road type has catenary. More...
static bool | HasRoadCatenaryDrawn (RoadType roadtype)
| Test if we should draw road catenary. More...
bool | HasRoadTypeAvail (CompanyID company, RoadType roadtype)
| Finds out, whether given company has a given RoadType available for construction. More...
bool | ValParamRoadType (RoadType roadtype)
| Validate functions for rail building. More...
RoadTypes | GetCompanyRoadTypes (CompanyID company, bool introduces=true)
| Get the road types the given company can build. More...
RoadTypes | GetRoadTypes (bool introduces)
| Get list of road types, regardless of company availability. More...
RoadTypes | AddDateIntroducedRoadTypes (RoadTypes current, Date date)
| Add the road types that are to be introduced at the given date. More...
void | UpdateLevelCrossing (TileIndex tile, bool sound=true)
| Sets correct crossing state. More...
void | UpdateCompanyRoadInfrastructure (RoadType rt, Owner o, int count)
| Update road infrastructure counts for a company. More...
void | DrawRoadOverlays (const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset)
| Draw road underlay and overlay sprites. More...

## Detailed Description

Functions related to roads.

Definition in file road_func.h.

## Function Documentation

## ◆ AddDateIntroducedRoadTypes()

RoadTypes AddDateIntroducedRoadTypes | ( | RoadTypes | current,
|  | Date | date
| ) |  |

Add the road types that are to be introduced at the given date.

Parameters

  rt | Roadtype
  current | The currently available roadtypes.
  date | The date for the introduction comparisons.

Returns
  The road types that should be available when date introduced road types are taken into account as well.

Definition at line 155 of file road.cpp.

References AddDateIntroducedRoadTypes(), GetRoadTypeInfo(), RoadTypeInfo::introduces_roadtypes, RoadTypeInfo::introduction_date, RoadTypeInfo::introduction_required_roadtypes, IsInsideMM(), RoadTypeInfo::label, MAX_DAY, ROADTYPE_BEGIN, and ROADTYPE_END.

Referenced by AddDateIntroducedRoadTypes(), EnginesDailyLoop(), ExistingRoadTypes(), GetCompanyRoadTypes(), and GetRoadTypes().

## ◆ AxisToRoadBits()

static RoadBits AxisToRoadBits | ( | Axis | a | ) |
| inlinestatic

Create the road-part which belongs to the given Axis.

This function returns a RoadBits value which belongs to the given Axis.

Parameters

  a | The Axis

Returns
  The result RoadBits which the selected road-part set

Definition at line 111 of file road_func.h.

References AXIS_X, IsValidAxis(), ROAD_X, and ROAD_Y.

Referenced by CmdBuildLongRoad(), CmdRemoveLongRoad(), and GetAnyRoadBits().

## ◆ ComplementRoadBits()

static RoadBits ComplementRoadBits | ( | RoadBits | r | ) |
| inlinestatic

Calculate the complement of a RoadBits value.

Simply flips all bits in the RoadBits value to get the complement of the RoadBits.

Parameters

  r | The given RoadBits value

Returns
  the complement

Definition at line 37 of file road_func.h.

References IsValidRoadBits(), and ROAD_ALL.

## ◆ DiagDirToRoadBits()

static RoadBits DiagDirToRoadBits | ( | DiagDirection | d | ) |
| inlinestatic

Create the road-part which belongs to the given DiagDirection.

This function returns a RoadBits value which belongs to the given DiagDirection.

Parameters

  d | The DiagDirection

Returns
  The result RoadBits which the selected road-part set

Definition at line 96 of file road_func.h.

References IsValidDiagDirection(), and ROAD_NW.

Referenced by CanFollowRoad(), CanRoadContinueIntoNextTile(), CleanUpRoadBits(), CmdBuildLongRoad(), DrawRoadTypeCatenary(), GetAnyRoadBits(), GrowTownWithBridge(), GrowTownWithTunnel(), and IsNeighborRoadTile().

## ◆ DrawRoadOverlays()

void DrawRoadOverlays | ( | const TileInfo * | ti,
|  | PaletteID | pal,
|  | const RoadTypeInfo * | road_rti,
|  | const RoadTypeInfo * | tram_rti,
|  | uint | road_offset,
|  | uint | tram_offset
| ) |  |

Draw road underlay and overlay sprites.

Parameters

  ti | TileInfo
  road_rti | Road road type information
  tram_rti | Tram road type information
  road_offset | Road sprite offset (based on road bits)
  tram_offset | Tram sprite offset (based on road bits)

Definition at line 1512 of file road_cmd.cpp.

References DrawGroundSprite(), GetCustomRoadSprite(), ROTSG_GROUND, and TileInfo::tile.

## ◆ GetCompanyRoadTypes()

RoadTypes GetCompanyRoadTypes | ( | CompanyID | company,
|  | bool | introduces
| ) |  |

Get the road types the given company can build.

Parameters

  company | the company to get the road types for.
  introduces | If true, include road types introduced by other road types

Returns
  the road types.

Definition at line 188 of file road.cpp.

References _date, _settings_game, AddDateIntroducedRoadTypes(), EngineInfo::climates, DAYS_IN_YEAR, GameSettings::game_creation, GetRoadTypeInfo(), HasBit(), RoadTypeInfo::introduces_roadtypes, Engine::IterateType(), GameCreationSettings::landscape, RoadVehicleInfo::roadtype, ROADTYPE_END, ROADTYPES_NONE, SetBit(), and VEH_ROAD.

Referenced by DisableEngineForCompany(), EnableEngineForCompany(), and StartupEngines().

## ◆ GetRoadTypes()

RoadTypes GetRoadTypes | ( | bool | introduces | ) |

Get list of road types, regardless of company availability.

Parameters

  introduces | If true, include road types introduced by other road types

Returns
  the road types.

Definition at line 216 of file road.cpp.

References _settings_game, AddDateIntroducedRoadTypes(), EngineInfo::climates, GameSettings::game_creation, GetRoadTypeInfo(), HasBit(), RoadTypeInfo::introduces_roadtypes, Engine::IterateType(), GameCreationSettings::landscape, MAX_DAY, RoadVehicleInfo::roadtype, ROADTYPE_END, ROADTYPES_NONE, SetBit(), and VEH_ROAD.

Referenced by ScenarioEditorToolbarWindow::OnPaint().

## ◆ HasRoadCatenary()

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

Test if a road type has catenary.

Parameters

  roadtype | Road type to test

Definition at line 135 of file road_func.h.

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

Referenced by HasRoadCatenaryDrawn().

## ◆ HasRoadCatenaryDrawn()

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

Test if we should draw road catenary.

Parameters

  roadtype | Road type to test

Definition at line 145 of file road_func.h.

References HasRoadCatenary(), IsInvisibilitySet(), and TO_CATENARY.

## ◆ HasRoadTypeAvail()

bool HasRoadTypeAvail | ( | const CompanyID | company,
|  | RoadType | roadtype
| ) |  |

Finds out, whether given company has a given RoadType available for construction.

Parameters

  company | ID of company
  roadtypet | RoadType to test

Returns
  true if company has the requested RoadType available

Definition at line 111 of file road.cpp.

References OWNER_DEITY, and OWNER_TOWN.

Referenced by ValParamRoadType().

## ◆ IsStraightRoad()

static bool IsStraightRoad | ( | RoadBits | r | ) |
| inlinestatic

Check if we've got a straight road.

Parameters

  r | The given RoadBits

Returns
  true if we've got a straight road

Definition at line 81 of file road_func.h.

References IsValidRoadBits(), ROAD_X, and ROAD_Y.

## ◆ IsValidRoadBits()

static bool IsValidRoadBits | ( | RoadBits | r | ) |
| inlinestatic

Whether the given roadtype is valid.

Parameters

  r | the roadtype to check for validness

Returns
  true if and only if valid

Definition at line 23 of file road_func.h.

References ROAD_END.

Referenced by ComplementRoadBits(), IsStraightRoad(), MirrorRoadBits(), and RotateRoadBits().

## ◆ MirrorRoadBits()

static RoadBits MirrorRoadBits | ( | RoadBits | r | ) |
| inlinestatic

Calculate the mirrored RoadBits.

Simply move the bits to their new position.

Parameters

  r | The given RoadBits value

Returns
  the mirrored

Definition at line 51 of file road_func.h.

References GB(), and IsValidRoadBits().

Referenced by CleanUpRoadBits().

## ◆ RoadMaintenanceCost()

static Money RoadMaintenanceCost | ( | RoadType | roadtype,
|  | uint32 | num,
|  | uint32 | total_num
| ) |  |
| inlinestatic

Calculates the maintenance cost of a number of road bits.

Parameters

  roadtype | Road type to get the cost for.
  num | Number of road bits.
  total_num | Total number of road bits of all road/tram-types.

Returns
  Total cost.

Definition at line 125 of file road_func.h.

References ROADTYPE_END.

Referenced by CompanyInfrastructureWindow::GetTotalMaintenanceCost().

## ◆ RotateRoadBits()

static RoadBits RotateRoadBits | ( | RoadBits | r,
|  | DiagDirDiff | rot
| ) |  |
| inlinestatic

Calculate rotated RoadBits.

Move the Roadbits clockwise until they are in their final position.

Parameters

  r | The given RoadBits value
  rot | The given Rotation angle

Returns
  the rotated

Definition at line 66 of file road_func.h.

References GB(), and IsValidRoadBits().

## ◆ UpdateCompanyRoadInfrastructure()

void UpdateCompanyRoadInfrastructure | ( | RoadType | rt,
|  | Owner | o,
|  | int | count
| ) |  |

Update road infrastructure counts for a company.

Parameters

  rt | Road type to update count of.
  o | Owner of road piece.
  count | Number of road pieces to adjust.

Definition at line 194 of file road_cmd.cpp.

References DirtyCompanyInfrastructureWindows(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Company::infrastructure, INVALID_ROADTYPE, and CompanyInfrastructure::road.

## ◆ UpdateLevelCrossing()

void UpdateLevelCrossing | ( | TileIndex | tile,
|  | bool | sound
| ) |  |

Sets correct crossing state.

Parameters

  tile | tile to update
  sound | should we play sound?

Precondition
  tile is a rail-road crossing

Definition at line 1694 of file train_cmd.cpp.

References _settings_client, SoundSettings::ambient, HasCrossingReservation(), HasVehicleOnPos(), IsCrossingBarred(), IsLevelCrossingTile(), ClientSettings::sound, Vehicle::tile, TrainApproachingCrossing(), and TrainOnTileEnum().

Referenced by Train::Crash(), and UnreserveRailTrack().

## ◆ ValParamRoadType()

bool ValParamRoadType | ( | RoadType | roadtype | ) |

Validate functions for rail building.

Parameters

  roadtype | road type to check.

Returns
  true if the current company may build the road.

Definition at line 142 of file road.cpp.

References _current_company, HasRoadTypeAvail(), and INVALID_ROADTYPE.

Referenced by CmdBuildBridge(), CmdBuildLongRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildTunnel(), CmdConvertRoad(), CmdRemoveLongRoad(), and ShowBuildRoadToolbar().