OpenTTD
Macros | Functions
road_func.h File Reference

Functions related to roads. More...

#include "core/bitmath_func.hpp"
#include "road_type.h"
#include "economy_func.h"

Go to the source code of this file.

Macros

#define FOR_EACH_SET_ROADTYPE(var, road_types)   FOR_EACH_SET_BIT_EX(RoadType, var, RoadTypes, road_types)
 Iterate through each set RoadType in a RoadTypes value. More...
 

Functions

static bool IsValidRoadType (RoadType rt)
 Whether the given roadtype is valid. More...
 
static bool IsValidRoadBits (RoadBits r)
 Whether the given roadtype is valid. More...
 
static RoadTypes RoadTypeToRoadTypes (RoadType rt)
 Maps a RoadType to the corresponding RoadTypes value. More...
 
static RoadTypes ComplementRoadTypes (RoadTypes r)
 Returns the RoadTypes which are not present in the given RoadTypes. 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)
 Calculates the maintenance cost of a number of road bits. More...
 
bool HasRoadTypesAvail (const CompanyID company, const RoadTypes rts)
 Finds out, whether given company has all given RoadTypes available. More...
 
bool ValParamRoadType (const RoadType rt)
 Validate functions for rail building. More...
 
RoadTypes GetCompanyRoadtypes (const CompanyID company)
 Get the road types the given company can build. More...
 
void UpdateLevelCrossing (TileIndex tile, bool sound=true)
 Sets correct crossing state. More...
 

Detailed Description

Functions related to roads.

Definition in file road_func.h.

Macro Definition Documentation

◆ FOR_EACH_SET_ROADTYPE

#define FOR_EACH_SET_ROADTYPE (   var,
  road_types 
)    FOR_EACH_SET_BIT_EX(RoadType, var, RoadTypes, road_types)

Iterate through each set RoadType in a RoadTypes value.

For more informations see FOR_EACH_SET_BIT_EX.

Parameters
varLoop index variable that stores fallowing set road type. Must be of type RoadType.
road_typesThe value to iterate through (any expression).
See also
FOR_EACH_SET_BIT_EX

Definition at line 28 of file road_func.h.

Function Documentation

◆ 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
aThe Axis
Returns
The result RoadBits which the selected road-part set

Definition at line 159 of file road_func.h.

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

◆ 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
rThe given RoadBits value
Returns
the complement

Definition at line 85 of file road_func.h.

◆ ComplementRoadTypes()

static RoadTypes ComplementRoadTypes ( RoadTypes  r)
inlinestatic

Returns the RoadTypes which are not present in the given RoadTypes.

This function returns the complement of a given RoadTypes.

Parameters
rThe given RoadTypes
Returns
The complement of the given RoadTypes

Definition at line 70 of file road_func.h.

References ROADTYPES_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
dThe DiagDirection
Returns
The result RoadBits which the selected road-part set

Definition at line 144 of file road_func.h.

Referenced by CanConnectToRoad(), CanFollowRoad(), CleanUpRoadBits(), CmdBuildLongRoad(), GetAnyRoadBits(), and IsNeighborRoadTile().

◆ GetCompanyRoadtypes()

RoadTypes GetCompanyRoadtypes ( CompanyID  company)

Get the road types the given company can build.

Parameters
companythe company to get the roadtypes for.
Returns
the road types.

Definition at line 139 of file road.cpp.

References ROADTYPES_NONE.

◆ HasRoadTypesAvail()

bool HasRoadTypesAvail ( const CompanyID  company,
const RoadTypes  rts 
)

Finds out, whether given company has all given RoadTypes available.

Parameters
companyID of company
rtsRoadTypes to test
Returns
true if company has all requested RoadTypes available

Definition at line 110 of file road.cpp.

References OWNER_DEITY, and OWNER_TOWN.

Referenced by CmdBuildBridge(), CmdBuildTunnel(), and ValParamRoadType().

◆ IsStraightRoad()

static bool IsStraightRoad ( RoadBits  r)
inlinestatic

Check if we've got a straight road.

Parameters
rThe given RoadBits
Returns
true if we've got a straight road

Definition at line 129 of file road_func.h.

◆ IsValidRoadBits()

static bool IsValidRoadBits ( RoadBits  r)
inlinestatic

Whether the given roadtype is valid.

Parameters
rtthe roadtype to check for validness
Returns
true if and only if valid

Definition at line 45 of file road_func.h.

References ROAD_END.

◆ IsValidRoadType()

static bool IsValidRoadType ( RoadType  rt)
inlinestatic

Whether the given roadtype is valid.

Parameters
rtthe roadtype to check for validness
Returns
true if and only if valid

Definition at line 35 of file road_func.h.

References ROADTYPE_ROAD, and ROADTYPE_TRAM.

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

◆ MirrorRoadBits()

static RoadBits MirrorRoadBits ( RoadBits  r)
inlinestatic

Calculate the mirrored RoadBits.

Simply move the bits to their new position.

Parameters
rThe given RoadBits value
Returns
the mirrored

Definition at line 99 of file road_func.h.

Referenced by CleanUpRoadBits().

◆ RoadMaintenanceCost()

static Money RoadMaintenanceCost ( RoadType  roadtype,
uint32  num 
)
inlinestatic

Calculates the maintenance cost of a number of road bits.

Parameters
roadtypeRoad type to get the cost for.
numNumber of road bits.
Returns
Total cost.

Definition at line 172 of file road_func.h.

Referenced by CompanyInfrastructureWindow::GetTotalMaintenanceCost().

◆ RoadTypeToRoadTypes()

static RoadTypes RoadTypeToRoadTypes ( RoadType  rt)
inlinestatic

Maps a RoadType to the corresponding RoadTypes value.

Parameters
rtthe roadtype to get the roadtypes from
Returns
the roadtypes with the given roadtype

Definition at line 56 of file road_func.h.

Referenced by MakeRoadDepot(), BuildRoadToolbarWindow::OnPlacePresize(), RemoveRoad(), and ValParamRoadType().

◆ RotateRoadBits()

static RoadBits RotateRoadBits ( RoadBits  r,
DiagDirDiff  rot 
)
inlinestatic

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 114 of file road_func.h.

◆ UpdateLevelCrossing()

void UpdateLevelCrossing ( TileIndex  tile,
bool  sound 
)

Sets correct crossing state.

Parameters
tiletile to update
soundshould we play sound?
Precondition
tile is a rail-road crossing

Definition at line 1699 of file train_cmd.cpp.

Referenced by Train::Crash().

◆ ValParamRoadType()

bool ValParamRoadType ( const RoadType  rt)

Validate functions for rail building.

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

Definition at line 129 of file road.cpp.

References _current_company, HasRoadTypesAvail(), and RoadTypeToRoadTypes().

Referenced by CmdBuildLongRoad(), and CmdBuildRoadDepot().