OpenTTD Source 20241224-master-gf74b0cf984
road_func.h File Reference

Functions related to roads. More...

#include "core/bitmath_func.hpp"
#include "road.h"
#include "economy_func.h"
#include "transparency.h"

Go to the source code of this file.

Functions

bool IsValidRoadBits (RoadBits r)
 Whether the given roadtype is valid.
 
RoadBits ComplementRoadBits (RoadBits r)
 Calculate the complement of a RoadBits value.
 
RoadBits MirrorRoadBits (RoadBits r)
 Calculate the mirrored RoadBits.
 
RoadBits RotateRoadBits (RoadBits r, DiagDirDiff rot)
 Calculate rotated RoadBits.
 
bool IsStraightRoad (RoadBits r)
 Check if we've got a straight road.
 
RoadBits DiagDirToRoadBits (DiagDirection d)
 Create the road-part which belongs to the given DiagDirection.
 
RoadBits AxisToRoadBits (Axis a)
 Create the road-part which belongs to the given Axis.
 
Money RoadMaintenanceCost (RoadType roadtype, uint32_t num, uint32_t total_num)
 Calculates the maintenance cost of a number of road bits.
 
bool HasRoadCatenary (RoadType roadtype)
 Test if a road type has catenary.
 
bool HasRoadCatenaryDrawn (RoadType roadtype)
 Test if we should draw road catenary.
 
bool HasRoadTypeAvail (CompanyID company, RoadType roadtype)
 Finds out, whether given company has a given RoadType available for construction.
 
bool ValParamRoadType (RoadType roadtype)
 Validate functions for rail building.
 
RoadTypes GetCompanyRoadTypes (CompanyID company, bool introduces=true)
 Get the road types the given company can build.
 
RoadTypes GetRoadTypes (bool introduces)
 Get list of road types, regardless of company availability.
 
RoadTypes AddDateIntroducedRoadTypes (RoadTypes current, TimerGameCalendar::Date date)
 Add the road types that are to be introduced at the given date.
 
void UpdateLevelCrossing (TileIndex tile, bool sound=true, bool force_bar=false)
 Update a level crossing to barred or open (crossing may include multiple adjacent tiles).
 
void MarkDirtyAdjacentLevelCrossingTiles (TileIndex tile, Axis road_axis)
 Find adjacent level crossing tiles in this multi-track crossing and mark them dirty.
 
void UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval (TileIndex tile, Axis road_axis)
 Update adjacent level crossing tiles in this multi-track crossing, due to removal of a level crossing tile.
 
void UpdateCompanyRoadInfrastructure (RoadType rt, Owner o, int count)
 Update road infrastructure counts for a company.
 
void DrawRoadOverlays (const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset, bool draw_underlay=true)
 Draw road underlay and overlay sprites.
 
void DrawRoadGroundSprites (const TileInfo *ti, RoadBits road, RoadBits tram, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, Roadside roadside, bool snow_or_desert)
 Draw road ground sprites.
 

Detailed Description

Functions related to roads.

Definition in file road_func.h.

Function Documentation

◆ AddDateIntroducedRoadTypes()

RoadTypes AddDateIntroducedRoadTypes ( RoadTypes  current,
TimerGameCalendar::Date  date 
)

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

Parameters
rtRoadtype
currentThe currently available roadtypes.
dateThe 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 166 of file road.cpp.

References AddDateIntroducedRoadTypes(), GetRoadTypeInfo(), RoadTypeInfo::introduces_roadtypes, RoadTypeInfo::introduction_date, RoadTypeInfo::introduction_required_roadtypes, IsInsideMM(), RoadTypeInfo::label, TimerGameConst< struct Calendar >::MAX_DATE, ROADTYPE_BEGIN, and ROADTYPE_END.

Referenced by AddDateIntroducedRoadTypes(), GetCompanyRoadTypes(), GetRoadTypes(), and NewVehicleAvailable().

◆ AxisToRoadBits()

RoadBits AxisToRoadBits ( Axis  a)
inline

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

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

Parameters
aThe 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(), CmdBuildRoad(), CmdRemoveLongRoad(), GetAnyRoadBits(), RemoveGenericRoadStop(), RemoveRoad(), and RoadFindPathToDest().

◆ ComplementRoadBits()

RoadBits ComplementRoadBits ( RoadBits  r)
inline

Calculate the complement of a RoadBits value.

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

Parameters
rThe given RoadBits value
Returns
the complement

Definition at line 37 of file road_func.h.

References IsValidRoadBits(), and ROAD_ALL.

Referenced by CmdBuildRoad(), and RemoveRoad().

◆ DiagDirToRoadBits()

RoadBits DiagDirToRoadBits ( DiagDirection  d)
inline

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

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

Parameters
dThe 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 CanConnectToRoad(), CanFollowRoad(), CanRoadContinueIntoNextTile(), CleanUpRoadBits(), CmdBuildLongRoad(), CmdBuildRoad(), ConnectRoadToStructure(), DrawRoadCatenary(), DrawRoadDepotSprite(), DrawRoadTypeCatenary(), DrawTile_Road(), GetAnyRoadBits(), GetTownRoadGridElement(), GrowTownAtRoad(), GrowTownInTile(), GrowTownWithBridge(), GrowTownWithTunnel(), IsNeighborRoadTile(), and RoadFindPathToDest().

◆ DrawRoadGroundSprites()

void DrawRoadGroundSprites ( const TileInfo ti,
RoadBits  road,
RoadBits  tram,
const RoadTypeInfo road_rti,
const RoadTypeInfo tram_rti,
Roadside  roadside,
bool  snow_or_desert 
)

Draw road ground sprites.

Parameters
tiTileInfo
roadRoad bits
tramTram bits
road_rtiRoad road type information
tram_rtiTram road type information
roadsideRoadside type
snow_or_desertWhether to draw snow/desert ground sprites

Definition at line 1605 of file road_cmd.cpp.

References DrawGroundSprite(), DrawRoadOverlays(), GetRoadGroundSprite(), GetRoadSpriteOffset(), ROAD_NONE, and TileInfo::tileh.

Referenced by DrawRoadBits().

◆ DrawRoadOverlays()

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

Draw road underlay and overlay sprites.

Parameters
tiTileInfo
road_rtiRoad road type information
tram_rtiTram road type information
road_offsetRoad sprite offset (based on road bits)
tram_offsetTram sprite offset (based on road bits)
draw_underlayWhether to draw underlays

Definition at line 1515 of file road_cmd.cpp.

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

Referenced by DrawRoadGroundSprites(), DrawTile_Road(), and DrawTile_TunnelBridge().

◆ GetCompanyRoadTypes()

RoadTypes GetCompanyRoadTypes ( CompanyID  company,
bool  introduces 
)

Get the road types the given company can build.

Parameters
companythe company to get the road types for.
introducesIf true, include road types introduced by other road types
Returns
the road types.

Definition at line 199 of file road.cpp.

References _settings_game, AddDateIntroducedRoadTypes(), EngineInfo::climates, TimerGameCalendar::date, TimerGameConst< struct Calendar >::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 AfterLoadGame(), DisableEngineForCompany(), DoStartupNewCompany(), EnableEngineForCompany(), and StartupEngines().

◆ GetRoadTypes()

RoadTypes GetRoadTypes ( bool  introduces)

◆ HasRoadCatenary()

bool HasRoadCatenary ( RoadType  roadtype)
inline

Test if a road type has catenary.

Parameters
roadtypeRoad type to test

Definition at line 135 of file road_func.h.

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

Referenced by DrawRoadTypeCatenary(), and HasRoadCatenaryDrawn().

◆ HasRoadCatenaryDrawn()

bool HasRoadCatenaryDrawn ( RoadType  roadtype)
inline

Test if we should draw road catenary.

Parameters
roadtypeRoad type to test

Definition at line 145 of file road_func.h.

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

Referenced by DrawBridgeRoadBits(), DrawRoadCatenary(), and DrawTile_TunnelBridge().

◆ HasRoadTypeAvail()

bool HasRoadTypeAvail ( const CompanyID  company,
RoadType  roadtype 
)

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

Parameters
companyID of company
roadtypetRoadType to test
Returns
true if company has the requested RoadType available

Definition at line 111 of file road.cpp.

References _generating_world, Company::avail_roadtypes, TimerGameCalendar::date, RoadTypeInfo::flags, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetRoadTypeInfo(), HasBit(), RoadTypeInfo::introduction_date, IsInsideMM(), RoadTypeInfo::label, TimerGameConst< struct Calendar >::MAX_DATE, OWNER_DEITY, OWNER_TOWN, ROTFB_HIDDEN, and ROTFB_TOWN_BUILD.

Referenced by ValParamRoadType().

◆ IsStraightRoad()

bool IsStraightRoad ( RoadBits  r)
inline

Check if we've got a straight road.

Parameters
rThe 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.

Referenced by CheckRoadSlope(), CmdBuildRoad(), and RemoveRoad().

◆ IsValidRoadBits()

bool IsValidRoadBits ( RoadBits  r)
inline

Whether the given roadtype is valid.

Parameters
rthe 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 CmdBuildRoad(), ComplementRoadBits(), IsStraightRoad(), MirrorRoadBits(), and RotateRoadBits().

◆ MarkDirtyAdjacentLevelCrossingTiles()

void MarkDirtyAdjacentLevelCrossingTiles ( TileIndex  tile,
Axis  road_axis 
)

Find adjacent level crossing tiles in this multi-track crossing and mark them dirty.

Parameters
tileThe tile which causes the update.
road_axisThe road axis.

Definition at line 1805 of file train_cmd.cpp.

References AxisToDiagDir(), GetCrossingRoadAxis(), IsLevelCrossingTile(), MarkTileDirtyByTile(), ReverseDiagDir(), Map::Size(), and TileAddByDiagDir().

Referenced by CmdBuildRoad(), and CmdBuildSingleRail().

◆ MirrorRoadBits()

RoadBits MirrorRoadBits ( RoadBits  r)
inline

Calculate the mirrored RoadBits.

Simply move the bits to their new position.

Parameters
rThe given RoadBits value
Returns
the mirrored

Definition at line 51 of file road_func.h.

References GB(), and IsValidRoadBits().

Referenced by CheckRoadSlope(), CleanUpRoadBits(), CmdBuildRoad(), and RemoveRoad().

◆ RoadMaintenanceCost()

Money RoadMaintenanceCost ( RoadType  roadtype,
uint32_t  num,
uint32_t  total_num 
)
inline

Calculates the maintenance cost of a number of road bits.

Parameters
roadtypeRoad type to get the cost for.
numNumber of road bits.
total_numTotal number of road bits of all road/tram-types.
Returns
Total cost.

Definition at line 125 of file road_func.h.

References GetRoadTypeInfo(), IntSqrt(), and ROADTYPE_END.

Referenced by CompaniesGenStatistics(), CompanyInfrastructureWindow::DrawWidget(), CompanyInfrastructureWindow::GetTotalMaintenanceCost(), and CompanyInfrastructureWindow::UpdateWidgetSize().

◆ RotateRoadBits()

RoadBits RotateRoadBits ( RoadBits  r,
DiagDirDiff  rot 
)
inline

Calculate rotated RoadBits.

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

Parameters
rThe given RoadBits value
rotThe given Rotation angle
Returns
the rotated

Definition at line 66 of file road_func.h.

References GB(), and IsValidRoadBits().

◆ UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval()

void UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval ( TileIndex  tile,
Axis  road_axis 
)

Update adjacent level crossing tiles in this multi-track crossing, due to removal of a level crossing tile.

Parameters
tileThe crossing tile which has been or is about to be removed, and which caused the update.
road_axisThe road axis.

Definition at line 1822 of file train_cmd.cpp.

References AxisToDiagDir(), CheckLevelCrossing(), GetCrossingRoadAxis(), IsCrossingBarred(), IsLevelCrossingTile(), MarkTileDirtyByTile(), ReverseDiagDir(), SetCrossingBarred(), Map::Size(), and TileOffsByDiagDir().

Referenced by CmdRemoveSingleRail(), and RemoveRoad().

◆ UpdateCompanyRoadInfrastructure()

◆ UpdateLevelCrossing()

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

Update a level crossing to barred or open (crossing may include multiple adjacent tiles).

Parameters
tileTile which causes the update.
soundShould we play sound?
force_barShould we force the crossing to be barred?

Definition at line 1773 of file train_cmd.cpp.

References AxisToDiagDir(), CheckLevelCrossing(), GetCrossingRoadAxis(), IsLevelCrossingTile(), ReverseDiagDir(), Map::Size(), TileAddByDiagDir(), and UpdateLevelCrossingTile().

Referenced by AfterLoadGame(), ChangeOwnershipOfCompanyItems(), CmdBuildRoad(), CmdBuildSingleRail(), Train::Crash(), DeleteLastWagon(), MaybeBarCrossingWithSound(), ReverseTrainDirection(), TrainController(), TryReserveRailTrack(), and UnreserveRailTrack().

◆ ValParamRoadType()

bool ValParamRoadType ( RoadType  roadtype)

Validate functions for rail building.

Parameters
roadtyperoad type to check.
Returns
true if the current company may build the road.

Definition at line 153 of file road.cpp.

References _current_company, HasRoadTypeAvail(), and ROADTYPE_END.

Referenced by CmdBuildBridge(), CmdBuildLongRoad(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildTunnel(), CmdConvertRoad(), CmdRemoveLongRoad(), BuildRoadToolbarWindow::OnInvalidateData(), and ShowBuildRoadToolbar().