OpenTTD Source
20241108-master-g80f628063a
|
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. More... | |
bool | IsValidDirection (Direction d) |
Checks if an integer value is a valid Direction. More... | |
bool | IsValidAxis (Axis d) |
Checks if an integer value is a valid Axis. More... | |
Direction | ReverseDir (Direction d) |
Return the reverse of a direction. More... | |
DirDiff | DirDifference (Direction d0, Direction d1) |
Calculate the difference between two directions. More... | |
DirDiff | ChangeDirDiff (DirDiff d, DirDiff delta) |
Applies two differences together. More... | |
Direction | ChangeDir (Direction d, DirDiff delta) |
Change a direction by a given difference. More... | |
DiagDirection | ReverseDiagDir (DiagDirection d) |
Returns the reverse direction of the given DiagDirection. More... | |
DiagDirDiff | DiagDirDifference (DiagDirection d0, DiagDirection d1) |
Calculate the difference between two DiagDirection values. More... | |
DiagDirection | ChangeDiagDir (DiagDirection d, DiagDirDiff delta) |
Applies a difference on a DiagDirection. More... | |
DiagDirection | DirToDiagDir (Direction dir) |
Convert a Direction to a DiagDirection. More... | |
Direction | DiagDirToDir (DiagDirection dir) |
Convert a DiagDirection to a Direction. More... | |
Axis | OtherAxis (Axis a) |
Select the other axis as provided. More... | |
Axis | DiagDirToAxis (DiagDirection d) |
Convert a DiagDirection to the axis. More... | |
DiagDirection | AxisToDiagDir (Axis a) |
Converts an Axis to a DiagDirection. More... | |
Direction | AxisToDirection (Axis a) |
Converts an Axis to a Direction. More... | |
DiagDirection | XYNSToDiagDir (Axis xy, uint ns) |
Convert an axis and a flag for north/south into a DiagDirection. More... | |
bool | IsDiagonalDirection (Direction dir) |
Checks if a given Direction is diagonal. More... | |
Different functions related to conversions between directions.
Definition in file direction_func.h.
|
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)
a | The axis |
Definition at line 232 of file direction_func.h.
References IsValidAxis().
Referenced by AutoslopeCheckForAxis(), CalculateRoadStopCost(), CmdBuildLongRoad(), GetNorthernBridgeEnd(), GetSouthernBridgeEnd(), MarkDirtyAdjacentLevelCrossingTiles(), TrainApproachingCrossing(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), and UpdateLevelCrossing().
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)
a | The axis |
Definition at line 249 of file direction_func.h.
References IsValidAxis().
|
inline |
Applies a difference on a DiagDirection.
This function applies a difference on a DiagDirection and returns the new DiagDirection.
d | The DiagDirection |
delta | The difference to apply on |
Definition at line 149 of file direction_func.h.
References IsValidDiagDirection().
Referenced by AircraftGetEntryPoint(), IsNeighborRoadTile(), RiverMakeWider(), and VehicleExitDir().
Change a direction by a given difference.
This functions returns a new direction of the given direction which is rotated by the given difference.
d | The direction to get a new direction from |
delta | The offset/drift applied to the direction |
Definition at line 104 of file direction_func.h.
References IsValidDirection().
Referenced by ChangeTrainDirRandomly(), DisasterTick_Submarine(), Airport::GetHangarExitDirection(), HandleCrashedAircraft(), and RotateAirportMovingData().
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.
d | The first difference |
delta | The second difference to add on |
Definition at line 88 of file direction_func.h.
|
inline |
Calculate the difference between two DiagDirection values.
d0 | The first direction as the base |
d1 | The second direction as the offset from the base |
Definition at line 131 of file direction_func.h.
References IsValidDiagDirection().
Referenced by AircraftGetEntryPoint().
|
inline |
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.
d | The DiagDirection |
Definition at line 214 of file direction_func.h.
References IsValidDiagDirection().
Referenced by CanRoadContinueIntoNextTile(), GetAnyRoadBits(), GetBridgeHeight(), IsRoadAllowedHere(), MaskWireBits(), SetRailStationPlatformReservation(), SetupFarmFieldFence(), CYapfCostBase::stSlopeCost(), TrainApproachingCrossingTile(), and GroundVehicle< T, Type >::UpdateZPosition().
|
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.
dir | The direction to convert |
Definition at line 182 of file direction_func.h.
References IsValidDiagDirection().
Referenced by CmdBuildRailWagon(), CmdBuildRoadVehicle(), and TrainCanLeaveTile().
Calculate the difference between two directions.
d0 | The first direction as the base |
d1 | The second direction as the offset from the base |
Definition at line 68 of file direction_func.h.
References IsValidDirection().
Referenced by Airport::GetHangarExitDirection().
|
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.
dir | The direction to convert |
Definition at line 166 of file direction_func.h.
References IsValidDirection().
Referenced by AircraftGetEntryPoint(), DisasterTick_Submarine(), RoadStop::Enter(), FindVehiclesInRoadStop(), GetTrainStopLocation(), RoadVehicle::GetVehicleTrackdir(), Ship::GetVehicleTrackdir(), Train::GetVehicleTrackdir(), RoadStop::Leave(), ShipTestUpDownOnLock(), GroundVehicle< T, Type >::UpdateZPosition(), and VehicleExitDir().
|
inline |
Checks if a given Direction is diagonal.
dir | The given direction. |
Definition at line 273 of file direction_func.h.
References IsValidDirection().
Referenced by RoadVehicle::UpdateDeltaXY().
|
inline |
Checks if an integer value is a valid Axis.
d | The value to check |
Definition at line 43 of file direction_func.h.
References AXIS_END.
Referenced by AxisToDiagDir(), AxisToDirection(), AxisToRoadBits(), AxisToTrack(), CmdBuildLongRoad(), CmdBuildShipDepot(), CmdRemoveLongRoad(), OtherAxis(), PlaceRail_Waypoint(), PlaceRoad_Waypoint(), TileOffsByAxis(), and XYNSToDiagDir().
|
inline |
Checks if an integer value is a valid DiagDirection.
d | The value to check |
Definition at line 21 of file direction_func.h.
References DIAGDIR_END.
Referenced by ChangeDiagDir(), CmdBuildRoadDepot(), CmdBuildTrainDepot(), DiagDirDifference(), DiagdirReachesTrackdirs(), DiagDirToAxis(), DiagDirToDiagTrack(), DiagDirToDiagTrackBits(), DiagDirToDiagTrackdir(), DiagDirToDir(), DiagDirToRoadBits(), GetOtherAqueductEnd(), ReverseDiagDir(), ShipTestUpDownOnLock(), TileIndexDiffCByDiagDir(), TileOffsByDiagDir(), TrackEnterdirToTrackdir(), TrackExitdirToTrackdir(), and TrainController().
|
inline |
Checks if an integer value is a valid Direction.
d | The value to check |
Definition at line 32 of file direction_func.h.
References DIR_END.
Referenced by ChangeDir(), DirDifference(), DirToDiagDir(), IsDiagonalDirection(), ReverseDir(), TileIndexDiffCByDir(), TileOffsByDir(), and TrackDirectionToTrackdir().
Select the other axis as provided.
This is basically the not-operator for the axis.
a | The given axis |
Definition at line 197 of file direction_func.h.
References IsValidAxis().
Referenced by GetCrossingRailAxis(), and SetupFarmFieldFence().
|
inline |
Returns the reverse direction of the given DiagDirection.
d | The DiagDirection to get the reverse from |
Definition at line 118 of file direction_func.h.
References IsValidDiagDirection().
Referenced by AutoslopeCheckForAxis(), CalculateRoadStopCost(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CanFollowRoad(), CanRoadContinueIntoNextTile(), CYapfFollowShipT< Types >::CheckShipReverse(), CheckTownBuild2House(), CheckTownBuild2x2House(), ClearPathReservation(), CmdBuildLongRoad(), 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(), GrowTownWithBridge(), GrowTownWithTunnel(), IsNeighborRoadTile(), MarkDirtyAdjacentLevelCrossingTiles(), MaskWireBits(), CYapfCostRoadT< Types >::PfCalcCost(), RedundantBridgeExistsNearby(), RiverMakeWider(), SetupFarmFieldFence(), TestTownOwnsBridge(), TrainApproachingCrossing(), TrainCanLeaveTile(), TrainController(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::TryReverse(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), UpdateLevelCrossing(), and UpdateSignalsInBuffer().
Return the reverse of a direction.
d | The direction to get the reverse from |
Definition at line 54 of file direction_func.h.
References IsValidDirection().
Referenced by TileLoop_Water(), and UpdateStatusAfterSwap().
|
inline |
Convert an axis and a flag for north/south into a DiagDirection.
xy | axis to convert |
ns | north -> 0, south -> 1 |
Definition at line 261 of file direction_func.h.
References IsValidAxis().
Referenced by GetShipDepotDirection().