OpenTTD
Functions
direction_func.h File Reference

Different functions related to conversions between directions. More...

#include "direction_type.h"

Go to the source code of this file.

Functions

static bool IsValidDiagDirection (DiagDirection d)
 Checks if an integer value is a valid DiagDirection. More...
 
static bool IsValidDirection (Direction d)
 Checks if an integer value is a valid Direction. More...
 
static bool IsValidAxis (Axis d)
 Checks if an integer value is a valid Axis. More...
 
static Direction ReverseDir (Direction d)
 Return the reverse of a direction. More...
 
static DirDiff DirDifference (Direction d0, Direction d1)
 Calculate the difference between two directions. More...
 
static DirDiff ChangeDirDiff (DirDiff d, DirDiff delta)
 Applies two differences together. More...
 
static Direction ChangeDir (Direction d, DirDiff delta)
 Change a direction by a given difference. More...
 
static DiagDirection ReverseDiagDir (DiagDirection d)
 Returns the reverse direction of the given DiagDirection. More...
 
static DiagDirDiff DiagDirDifference (DiagDirection d0, DiagDirection d1)
 Calculate the difference between two DiagDirection values. More...
 
static DiagDirection ChangeDiagDir (DiagDirection d, DiagDirDiff delta)
 Applies a difference on a DiagDirection. More...
 
static DiagDirection DirToDiagDir (Direction dir)
 Convert a Direction to a DiagDirection. More...
 
static Direction DiagDirToDir (DiagDirection dir)
 Convert a DiagDirection to a Direction. More...
 
static Axis OtherAxis (Axis a)
 Select the other axis as provided. More...
 
static Axis DiagDirToAxis (DiagDirection d)
 Convert a DiagDirection to the axis. More...
 
static DiagDirection AxisToDiagDir (Axis a)
 Converts an Axis to a DiagDirection. More...
 
static Direction AxisToDirection (Axis a)
 Converts an Axis to a Direction. More...
 
static DiagDirection XYNSToDiagDir (Axis xy, uint ns)
 Convert an axis and a flag for north/south into a DiagDirection. More...
 
static bool IsDiagonalDirection (Direction dir)
 Checks if a given Direction is diagonal. More...
 

Detailed Description

Different functions related to conversions between directions.

Definition in file direction_func.h.

Function Documentation

◆ AxisToDiagDir()

static DiagDirection AxisToDiagDir ( Axis  a)
inlinestatic

Converts an Axis to a DiagDirection.

This function returns the DiagDirection which belongs to the axis. As 2 directions are mapped to an axis this function returns the one which points to south, either south-west (on X axis) or south-east (on Y axis)

Parameters
aThe axis
Returns
The direction pointed to south

Definition at line 234 of file direction_func.h.

Referenced by CmdBuildLongRoad(), GetNorthernBridgeEnd(), and GetSouthernBridgeEnd().

◆ AxisToDirection()

static Direction AxisToDirection ( Axis  a)
inlinestatic

Converts an Axis to a Direction.

This function returns the Direction which belongs to the axis. As 2 directions are mapped to an axis this function returns the one which points to south, either south-west (on X axis) or south-east (on Y axis)

Parameters
aThe axis
Returns
The direction pointed to south

Definition at line 251 of file direction_func.h.

◆ ChangeDiagDir()

static DiagDirection ChangeDiagDir ( DiagDirection  d,
DiagDirDiff  delta 
)
inlinestatic

Applies a difference on a DiagDirection.

This function applies a difference on a DiagDirection and returns the new DiagDirection.

Parameters
dThe DiagDirection
deltaThe difference to apply on
Returns
The new direction which was calculated

Definition at line 151 of file direction_func.h.

Referenced by IsNeighborRoadTile(), and TrainExitDir().

◆ ChangeDir()

static Direction ChangeDir ( Direction  d,
DirDiff  delta 
)
inlinestatic

Change a direction by a given difference.

This functions returns a new direction of the given direction which is rotated by the given difference.

Parameters
dThe direction to get a new direction from
deltaThe offset/drift applied to the direction
Returns
The new direction

Definition at line 106 of file direction_func.h.

Referenced by ChangeTrainDirRandomly(), DisasterTick_Submarine(), Airport::GetHangarExitDirection(), and RotateAirportMovingData().

◆ ChangeDirDiff()

static DirDiff ChangeDirDiff ( DirDiff  d,
DirDiff  delta 
)
inlinestatic

Applies two differences together.

This function adds two differences together and returns the resulting difference. So adding two DIRDIFF_REVERSE together results in the DIRDIFF_SAME difference.

Parameters
dThe first difference
deltaThe second difference to add on
Returns
The resulting difference

Definition at line 90 of file direction_func.h.

◆ DiagDirDifference()

static DiagDirDiff DiagDirDifference ( DiagDirection  d0,
DiagDirection  d1 
)
inlinestatic

Calculate the difference between two DiagDirection values.

Parameters
d0The first direction as the base
d1The second direction as the offset from the base
Returns
The difference how the second direction drifts of the first one.

Definition at line 133 of file direction_func.h.

◆ DiagDirToAxis()

static Axis DiagDirToAxis ( DiagDirection  d)
inlinestatic

Convert a DiagDirection to the axis.

This function returns the axis which belongs to the given DiagDirection. The axis X belongs to the DiagDirection north-east and south-west.

Parameters
dThe DiagDirection
Returns
The axis which belongs to the direction

Definition at line 216 of file direction_func.h.

Referenced by CanEnterTileOwnerCheck(), CheckFlatLandRoadStop(), CleanUpRoadBits(), GetAnyRoadBits(), GetBridgeHeight(), IsRoadAllowedHere(), MaskWireBits(), RemoveRoad(), SetupFarmFieldFence(), and CYapfCostBase::stSlopeCost().

◆ DiagDirToDir()

static Direction DiagDirToDir ( DiagDirection  dir)
inlinestatic

Convert a DiagDirection to a Direction.

This function can be used to convert the 4-way DiagDirection to the 8-way Direction. As 4-way are less than 8-way not all possible directions can be calculated.

Parameters
dirThe direction to convert
Returns
The resulting Direction

Definition at line 184 of file direction_func.h.

Referenced by CmdBuildRailWagon(), CmdBuildRoadVehicle(), and TrainCanLeaveTile().

◆ DirDifference()

static DirDiff DirDifference ( Direction  d0,
Direction  d1 
)
inlinestatic

Calculate the difference between two directions.

Parameters
d0The first direction as the base
d1The second direction as the offset from the base
Returns
The difference how the second direction drifts of the first one.

Definition at line 70 of file direction_func.h.

Referenced by Airport::GetHangarExitDirection().

◆ DirToDiagDir()

static DiagDirection DirToDiagDir ( Direction  dir)
inlinestatic

Convert a Direction to a DiagDirection.

This function can be used to convert the 8-way Direction to the 4-way DiagDirection. If the direction cannot be mapped its "rounded clockwise". So DIR_N becomes DIAGDIR_NE.

Parameters
dirThe direction to convert
Returns
The resulting DiagDirection, maybe "rounded clockwise".

Definition at line 168 of file direction_func.h.

Referenced by DisasterTick_Submarine(), RoadStop::Enter(), FindVehiclesInRoadStop(), GetTrainStopLocation(), Ship::GetVehicleTrackdir(), RoadVehicle::GetVehicleTrackdir(), Train::GetVehicleTrackdir(), RoadStop::Leave(), and TrainExitDir().

◆ IsDiagonalDirection()

static bool IsDiagonalDirection ( Direction  dir)
inlinestatic

Checks if a given Direction is diagonal.

Parameters
dirThe given direction.
Returns
True if the direction is diagonal.

Definition at line 275 of file direction_func.h.

Referenced by RoadVehicle::UpdateDeltaXY(), and Train::UpdateDeltaXY().

◆ IsValidAxis()

static bool IsValidAxis ( Axis  d)
inlinestatic

Checks if an integer value is a valid Axis.

Parameters
dThe value to check
Returns
True if the value belongs to an Axis, else false

Definition at line 45 of file direction_func.h.

References AXIS_END.

Referenced by PlaceRail_Waypoint().

◆ IsValidDiagDirection()

static bool IsValidDiagDirection ( DiagDirection  d)
inlinestatic

Checks if an integer value is a valid DiagDirection.

Parameters
dThe value to check
Returns
True if the value belongs to a DiagDirection, else false

Definition at line 23 of file direction_func.h.

References DIAGDIR_END.

Referenced by GetOtherAqueductEnd(), and BuildDocksToolbarWindow::OnPlacePresize().

◆ IsValidDirection()

static bool IsValidDirection ( Direction  d)
inlinestatic

Checks if an integer value is a valid Direction.

Parameters
dThe value to check
Returns
True if the value belongs to a Direction, else false

Definition at line 34 of file direction_func.h.

References DIR_END.

◆ OtherAxis()

static Axis OtherAxis ( Axis  a)
inlinestatic

Select the other axis as provided.

This is basically the not-operator for the axis.

Parameters
aThe given axis
Returns
The other axis

Definition at line 199 of file direction_func.h.

◆ ReverseDiagDir()

static DiagDirection ReverseDiagDir ( DiagDirection  d)
inlinestatic

◆ ReverseDir()

static Direction ReverseDir ( Direction  d)
inlinestatic

Return the reverse of a direction.

Parameters
dThe direction to get the reverse from
Returns
The reverse Direction

Definition at line 56 of file direction_func.h.

Referenced by Train::GetImage(), TileLoop_Water(), and UpdateStatusAfterSwap().

◆ XYNSToDiagDir()

static DiagDirection XYNSToDiagDir ( Axis  xy,
uint  ns 
)
inlinestatic

Convert an axis and a flag for north/south into a DiagDirection.

Parameters
xyaxis to convert
nsnorth -> 0, south -> 1
Returns
the desired DiagDirection

Definition at line 263 of file direction_func.h.

Referenced by GetShipDepotDirection().