# road_func.h File Reference

Functions related to roads. More...

`#include "core/bitmath_func.hpp"`
`#include "road_type.h"`
`#include "direction_func.h"`
`#include "player_type.h"`

Go to the source code of this file.

## Functions
static bool | IsValidRoadType (RoadType rt)
| Whether the given roadtype is valid.
static bool | AreValidRoadTypes (RoadTypes rts)
| Are the given bits pointing to valid roadtypes?
static RoadTypes | RoadTypeToRoadTypes (RoadType rt)
| Maps a RoadType to the corresponding RoadTypes value.
static RoadTypes | ComplementRoadTypes (RoadTypes r)
| Returns the RoadTypes which are not present in the given RoadTypes.
static RoadBits | ComplementRoadBits (RoadBits r)
| Calculate the complement of a RoadBits value.
static RoadBits | MirrorRoadBits (RoadBits r)
| Calculate the mirrored RoadBits.
static RoadBits | RotateRoadBits (RoadBits r, DiagDirDiff rot)
| Calculate rotated RoadBits.
static RoadBits | DiagDirToRoadBits (DiagDirection d)
| Create the road-part which belongs to the given DiagDirection.
static RoadBits | AxisToRoadBits (Axis a)
| Create the road-part which belongs to the given Axis.
bool | HasRoadTypesAvail (const PlayerID p, const RoadTypes rts)
| Finds out, whether given player has all given RoadTypes available.
bool | ValParamRoadType (const RoadType rt)
| Validate functions for rail building.
RoadTypes | GetPlayerRoadtypes (const PlayerID p)
| Get the road types the given player can build.
void | UpdateLevelCrossing (TileIndex tile, bool sound=true)
| Sets correct crossing state.

## Detailed Description

Functions related to roads.

Definition in file road_func.h.

## Function Documentation

static bool AreValidRoadTypes | ( | RoadTypes | rts | ) | `[inline, static]`

Are the given bits pointing to valid roadtypes?

Parameters:

  | rts | the roadtypes to check for validness

Returns:
  true if and only if valid

Definition at line 28 of file road_func.h.

References HasBit(), ROADTYPE_ROAD, and ROADTYPE_TRAM.

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

static RoadBits AxisToRoadBits | ( | Axis | a | ) | `[inline, static]`

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

References AXIS_X, ROAD_X, and ROAD_Y.

Referenced by CmdBuildRoad(), and GetAnyRoadBits().

static RoadBits ComplementRoadBits | ( | RoadBits | r | ) | `[inline, static]`

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

References ROAD_ALL.

Referenced by CmdBuildRoad(), and RemoveRoad().

static RoadTypes ComplementRoadTypes | ( | RoadTypes | r | ) | `[inline, static]`

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

This function returns the complement of a given RoadTypes.

Parameters:

  | r | The given RoadTypes

Returns:
  The complement of the given RoadTypes

Note:
  The unused value ROADTYPES_HWAY will be used, too.

Definition at line 53 of file road_func.h.

References ROADTYPES_ALL.

Referenced by RemoveRoad().

static RoadBits DiagDirToRoadBits | ( | DiagDirection | d | ) | `[inline, static]`

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

References ROAD_NW.

Referenced by CleanUpRoadBits(), CmdRemoveRoadStop(), GetAnyRoadBits(), GetTownRoadGridElement(), GrowTownAtRoad(), GrowTownInTile(), GrowTownWithBridge(), and IsNeighborRoadTile().

RoadTypes GetPlayerRoadtypes | ( | const PlayerID | p | ) |

Get the road types the given player can build.

Parameters:

  | p | the player to get the roadtypes for.

Returns:
  the road types.

Definition at line 95 of file road.cpp.

References EngineInfo::climates, EF_ROAD_TRAM, HasBit(), EngineInfo::misc_flags, ROADTYPE_ROAD, ROADTYPE_TRAM, ROADTYPES_NONE, and SetBit().

bool HasRoadTypesAvail | ( | const PlayerID | p,
|  | const RoadTypes | rts |
| ) |  |  |

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

Parameters:

  | PlayerID | ID of player
  | rts | RoadTypes to test

Returns:
  true if player has all requested RoadTypes available

Definition at line 77 of file road.cpp.

References IsGeneratingWorld(), OWNER_TOWN, and ROADTYPES_ROAD.

static bool IsValidRoadType | ( | RoadType | rt | ) | `[inline, static]`

Whether the given roadtype is valid.

Parameters:

  | rt | the roadtype to check for validness

Returns:
  true if and only if valid

Definition at line 18 of file road_func.h.

References ROADTYPE_ROAD, and ROADTYPE_TRAM.

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

static RoadBits MirrorRoadBits | ( | RoadBits | r | ) | `[inline, static]`

Calculate the mirrored RoadBits.

Simply move the bits to their new position.

Parameters:

  | r | The given RoadBits value

Returns:
  the mirrored

Definition at line 81 of file road_func.h.

References GB().

Referenced by CheckRoadSlope(), and CleanUpRoadBits().

static RoadTypes RoadTypeToRoadTypes | ( | RoadType | rt | ) | `[inline, static]`

Maps a RoadType to the corresponding RoadTypes value.

Parameters:

  | rt | the roadtype to get the roadtypes from

Returns:
  the roadtypes with the given roadtype

Definition at line 39 of file road_func.h.

Referenced by AfterLoadVehicles(), CmdBuildRoad(), CmdBuildRoadVeh(), GetAnyRoadTrackBits(), RemoveRoad(), and ValParamRoadType().

static RoadBits RotateRoadBits | ( | RoadBits | r,
|  | DiagDirDiff | rot |
| ) |  |  | `[inline, static]`

Calculate rotated RoadBits.

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

Parameters:

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

Returns:
  the rotated

Definition at line 95 of file road_func.h.

References GB().

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 1766 of file train_cmd.cpp.

References HasVehicleOnPos(), MarkTileDirtyByTile(), TrainApproachingCrossing(), and TrainOnTileEnum().

Referenced by CmdBuildRoad(), CmdBuildSingleRail(), DeleteLastWagon(), and ReverseTrainDirection().

bool ValParamRoadType | ( | const RoadType | rt | ) |

Validate functions for rail building.

Parameters:

  | rt | road type to check.

Returns:
  true if the current player may build the road.

Definition at line 90 of file road.cpp.

References RoadTypeToRoadTypes().