OpenTTD Source 20241224-master-gf74b0cf984
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

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

Detailed Description

Different functions related to conversions between directions.

Definition in file direction_func.h.

Function Documentation

◆ AxisToDiagDir()

DiagDirection AxisToDiagDir ( Axis  a)
inline

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 232 of file direction_func.h.

References IsValidAxis().

Referenced by AutoslopeCheckForAxis(), CalculateRoadStopCost(), CmdBuildBridge(), CmdBuildLongRoad(), CmdBuildRailStation(), CmdBuildRoadWaypoint(), DeleteLastWagon(), DrawBridgePillars(), DrawTile_Road(), GetNorthernBridgeEnd(), GetSouthernBridgeEnd(), MarkDirtyAdjacentLevelCrossingTiles(), TrainApproachingCrossing(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), and UpdateLevelCrossing().

◆ AxisToDirection()

Direction AxisToDirection ( Axis  a)
inline

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 249 of file direction_func.h.

References IsValidAxis().

Referenced by AfterLoadGame().

◆ ChangeDiagDir()

DiagDirection ChangeDiagDir ( DiagDirection  d,
DiagDirDiff  delta 
)
inline

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 149 of file direction_func.h.

References IsValidDiagDirection().

Referenced by AircraftGetEntryPoint(), GrowTownInTile(), IsNeighborRoadTile(), RiverMakeWider(), and VehicleExitDir().

◆ ChangeDir()

Direction ChangeDir ( Direction  d,
DirDiff  delta 
)
inline

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 104 of file direction_func.h.

References IsValidDirection().

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

◆ ChangeDirDiff()

DirDiff ChangeDirDiff ( DirDiff  d,
DirDiff  delta 
)
inline

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 88 of file direction_func.h.

◆ DiagDirDifference()

DiagDirDiff DiagDirDifference ( DiagDirection  d0,
DiagDirection  d1 
)
inline

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 131 of file direction_func.h.

References IsValidDiagDirection().

Referenced by AircraftGetEntryPoint(), and CYapfCostRegionT< Types >::PfCalcCost().

◆ DiagDirToAxis()

◆ DiagDirToDir()

Direction DiagDirToDir ( DiagDirection  dir)
inline

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 182 of file direction_func.h.

References IsValidDiagDirection().

Referenced by AfterLoadGame(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVehicle(), TrainCanLeaveTile(), and VehicleEnter_Track().

◆ DirDifference()

DirDiff DirDifference ( Direction  d0,
Direction  d1 
)
inline

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

References IsValidDirection().

Referenced by AircraftController(), Train::GetCurveSpeedLimit(), Airport::GetHangarExitDirection(), and TrainController().

◆ DirToDiagDir()

DiagDirection DirToDiagDir ( Direction  dir)
inline

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 166 of file direction_func.h.

References IsValidDirection().

Referenced by AfterLoadGame(), AircraftGetEntryPoint(), CmdTurnRoadVeh(), DisasterTick_Submarine(), RoadStop::Enter(), FindVehiclesInRoadStop(), GetTrainStopLocation(), RoadVehicle::GetVehicleTrackdir(), Ship::GetVehicleTrackdir(), Train::GetVehicleTrackdir(), IsWateredTile(), RoadStop::Leave(), ShipTestUpDownOnLock(), GroundVehicle< T, Type >::UpdateZPosition(), and VehicleExitDir().

◆ IsDiagonalDirection()

bool IsDiagonalDirection ( Direction  dir)
inline

Checks if a given Direction is diagonal.

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

Definition at line 273 of file direction_func.h.

References IsValidDirection().

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

◆ IsValidAxis()

bool IsValidAxis ( Axis  d)
inline

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 43 of file direction_func.h.

References AXIS_END.

Referenced by AxisToDiagDir(), AxisToDirection(), AxisToRoadBits(), AxisToTrack(), CmdBuildLongRoad(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadWaypoint(), CmdBuildShipDepot(), CmdRemoveLongRoad(), OtherAxis(), PlaceRail_Waypoint(), PlaceRoad_Waypoint(), TileOffsByAxis(), and XYNSToDiagDir().

◆ IsValidDiagDirection()

◆ IsValidDirection()

bool IsValidDirection ( Direction  d)
inline

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 32 of file direction_func.h.

References DIR_END.

Referenced by ChangeDir(), DirDifference(), DirToDiagDir(), IsDiagonalDirection(), ReverseDir(), TileIndexDiffCByDir(), TileOffsByDir(), and TrackDirectionToTrackdir().

◆ OtherAxis()

Axis OtherAxis ( Axis  a)
inline

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 197 of file direction_func.h.

References IsValidAxis().

Referenced by CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadWaypoint(), DrawBridgePillars(), GetCrossingRailAxis(), and SetupFarmFieldFence().

◆ ReverseDiagDir()

DiagDirection ReverseDiagDir ( DiagDirection  d)
inline

Returns the reverse direction of the given DiagDirection.

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

Definition at line 118 of file direction_func.h.

References IsValidDiagDirection().

Referenced by AfterLoadGame(), AutoslopeCheckForAxis(), CalculateRoadStopCost(), CanConnectToRoad(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CanFollowRoad(), CanRoadContinueIntoNextTile(), CcBuildBridge(), CcBuildRoadTunnel(), CcRoadStop(), CYapfFollowShipT< Types >::CheckShipReverse(), CheckTownBuild2House(), CheckTownBuild2x2House(), ClearPathReservation(), CmdBuildBridge(), CmdBuildDock(), CmdBuildLongRoad(), CmdBuildTunnel(), ConnectRoadToStructure(), DeleteLastWagon(), DoClearBridge(), DoClearTunnel(), DrawBridgePillars(), DrawRailCatenaryRailway(), DrawTile_Road(), ExploreSegment(), FixOwnerOfRailTrack(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::FollowTileExit(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse(), GetAnyRoadBits(), GetBridgeEnd(), GetNorthernBridgeEnd(), GetOtherAqueductEnd(), GetOtherTunnelEnd(), GetTownRoadGridElement(), GrowTownAtRoad(), GrowTownInTile(), GrowTownWithBridge(), GrowTownWithTunnel(), IsNeighborRoadTile(), IsWateredTile(), MarkDirtyAdjacentLevelCrossingTiles(), MaskWireBits(), BuildDocksToolbarWindow::OnPlaceObject(), BuildDocksToolbarWindow::OnPlacePresize(), CYapfCostRoadT< Types >::PfCalcCost(), CYapfCostRailT< Types >::PfCalcCost(), RedundantBridgeExistsNearby(), RiverMakeWider(), SetupFarmFieldFence(), TestTownOwnsBridge(), TrainApproachingCrossing(), TrainCanLeaveTile(), TrainCheckIfLineEnds(), TrainController(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::TryReverse(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), UpdateLevelCrossing(), UpdateSignalsInBuffer(), VehicleEnter_Track(), and VisitAdjacentWaterRegionPatchNeighbors().

◆ ReverseDir()

Direction ReverseDir ( Direction  d)
inline

Return the reverse of a direction.

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

Definition at line 54 of file direction_func.h.

References IsValidDirection().

Referenced by AfterLoadGame(), DrawRailCatenaryOnBridge(), Train::GetImage(), SpawnAdvancedVisualEffect(), TileLoop_Water(), Train::UpdateDeltaXY(), UpdateStatusAfterSwap(), and VehicleEnter_Track().

◆ XYNSToDiagDir()

DiagDirection XYNSToDiagDir ( Axis  xy,
uint  ns 
)
inline

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 261 of file direction_func.h.

References IsValidAxis().

Referenced by AfterLoadGame(), and GetShipDepotDirection().