|
OpenTTD Source 20260531-master-g0e951f3528
|
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. | |
| DirDiff | LimitDirDiff (DirDiff d) |
| Limit a direction difference to up to 45 degrees. | |
| 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. | |
| DiagDirections | AxisToDiagDirs (Axis a) |
| Converts an Axis to DiagDirections. | |
| 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. | |
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 242 of file direction_func.h.
References IsValidAxis(), and to_underlying().
Referenced by AutoslopeCheckForAxis(), CmdBuildBridge(), CmdBuildLongRoad(), CmdBuildRailStation(), CmdBuildRoadWaypoint(), DeleteLastWagon(), DrawBridgePillars(), GetNorthernBridgeEnd(), GetSouthernBridgeEnd(), GetTileTrackStatus_Road(), and TrainApproachingCrossing().
|
inline |
Converts an Axis to DiagDirections.
This function returns both DiagDirections which belong to the axis.
| a | The axis |
Definition at line 257 of file direction_func.h.
References IsValidAxis(), NE, NW, SE, SW, and X.
Referenced by CalculateRoadStopCost(), CheckFlatLandRailStation(), DrawTile_Road(), MarkDirtyAdjacentLevelCrossingTiles(), 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 276 of file direction_func.h.
References IsValidAxis(), and to_underlying().
Referenced by AfterLoadGame().
|
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 159 of file direction_func.h.
References IsValidDiagDirection(), and to_underlying().
Referenced by AircraftGetEntryPoint(), GrowTownInTile(), IsNeighbourRoadTile(), 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 114 of file direction_func.h.
References IsValidDirection(), and to_underlying().
Referenced by AircraftController(), ChangeTrainDirRandomly(), DisasterTick_Submarine(), Airport::GetHangarExitDirection(), HandleCrashedAircraft(), RotateAirportMovingData(), Vehicle::ShowVisualEffect(), and SpawnAdvancedVisualEffect().
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.
References to_underlying().
|
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 141 of file direction_func.h.
References IsValidDiagDirection(), and to_underlying().
Referenced by AircraftGetEntryPoint(), and YapfShipRegions::PfCalcCost().
|
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 224 of file direction_func.h.
References IsValidDiagDirection(), and to_underlying().
Referenced by AfterLoadGame(), CanRoadContinueIntoNextTile(), CheckBuildAbove_TunnelBridge(), CheckTrainStayInDepot(), CleanUpRoadBits(), CmdBuildDock(), CmdBuildRoadStop(), CmdBuildTunnel(), DrawRailCatenaryRailway(), DrawTile_TunnelBridge(), DrawTile_Water(), ExploreSegment(), WaterRegion::ForceUpdate(), GetAnyRoadBits(), GetBridgeHeight(), GetFoundation_TunnelBridge(), GetSlopePixelZ_TunnelBridge(), GetTileTrackStatus_Road(), GetTileTrackStatus_Station(), IsRoadAllowedHere(), IsWateredTile(), MakeDock(), MaskWireBits(), PlaceRoad_BusStation(), PlaceRoad_TruckStation(), RemoveRoad(), RoadFindPathToDest(), SetRailStationPlatformReservation(), SetupFarmFieldFence(), CYapfCostBase::stSlopeCost(), TerraformTile_TunnelBridge(), TrainApproachingCrossingTile(), TryBuildCoastLighthouse(), GroundVehicle< T, Type >::UpdateZPosition(), VehicleEnterTile_Rail(), VehicleEnterTile_Station(), and VehicleEnterTile_TunnelBridge().
|
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 192 of file direction_func.h.
References IsValidDiagDirection(), and to_underlying().
Referenced by AfterLoadGame(), CheckShipStayInDepot(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVehicle(), CmdBuildShip(), TrainCanLeaveTile(), and VehicleEnterTile_Rail().
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(), and to_underlying().
Referenced by AircraftController(), Train::GetCurveSpeedLimit(), Airport::GetHangarExitDirection(), and TrainController().
|
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 Direction::N becomes DiagDirection::NE.
| dir | The direction to convert |
Definition at line 176 of file direction_func.h.
References IsValidDirection(), and to_underlying().
Referenced by AfterLoadGame(), AircraftGetEntryPoint(), CheckTrainStayInDepot(), CmdTurnRoadVeh(), DisasterTick_Submarine(), RoadStop::Enter(), GetTrainStopLocation(), RoadVehicle::GetVehicleTrackdir(), Ship::GetVehicleTrackdir(), Train::GetVehicleTrackdir(), IsWateredTile(), RoadStop::Leave(), RoadStop::Entry::Rebuild(), ShipTestUpDownOnLock(), RoadVehicle::UpdateDeltaXY(), Train::UpdateDeltaXY(), GroundVehicle< T, Type >::UpdateZPosition(), VehicleEnterTile_Station(), VehicleEnterTile_TunnelBridge(), and VehicleExitDir().
|
inline |
Checks if a given Direction is diagonal.
| dir | The given direction. |
Definition at line 300 of file direction_func.h.
References IsValidDirection(), and to_underlying().
Referenced by CheckReverseTrain(), Vehicle::GetAdvanceDistance(), RoadVehicle::GetCurrentMaxSpeed(), Vehicle::GetOldAdvanceSpeed(), TrainApproachingLineEnd(), RoadVehicle::UpdateDeltaXY(), Train::UpdateDeltaXY(), and VehicleExitDir().
|
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 End.
Referenced by AxisToDiagDir(), AxisToDiagDirs(), AxisToDirection(), AxisToRoadBits(), AxisToTrack(), CmdBuildLongRoad(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadWaypoint(), 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 End.
Referenced by ChangeDiagDir(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildTrainDepot(), DiagDirDifference(), DiagdirReachesTrackdirs(), DiagDirToAxis(), DiagDirToDiagTrack(), DiagDirToDiagTrackBits(), DiagDirToDiagTrackdir(), DiagDirToDir(), DiagDirToRoadBits(), ExploreSegment(), GetOtherAqueductEnd(), GrowTownAtRoad(), BuildDocksToolbarWindow::OnPlacePresize(), 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 End.
Referenced by ChangeDir(), DirDifference(), DirToDiagDir(), IsDiagonalDirection(), ReverseDir(), TileIndexDiffCByDir(), TileOffsByDir(), and TrackDirectionToTrackdir().
Limit a direction difference to up to 45 degrees.
| d | direction difference to limit. |
Definition at line 99 of file direction_func.h.
References Left45, Reverse, and Right45.
Referenced by AircraftController().
Select the other axis as provided.
This is basically the not-operator for the axis.
| a | The given axis |
Definition at line 207 of file direction_func.h.
References IsValidAxis(), and to_underlying().
Referenced by AfterLoadGame(), CheckFlatLandRoadStop(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadWaypoint(), DrawBridgeMiddle(), DrawBridgePillars(), GetCrossingRailAxis(), IsPossibleCrossing(), and SetupFarmFieldFence().
|
inline |
Returns the reverse direction of the given DiagDirection.
| d | The DiagDirection to get the reverse from |
Definition at line 128 of file direction_func.h.
References IsValidDiagDirection(), and to_underlying().
Referenced by AfterLoadGame(), AutoslopeCheckForAxis(), CanConnectToRoad(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::CanEnterNewTile(), CanFollowRoad(), CanRoadContinueIntoNextTile(), CcBuildBridge(), CcBuildRoadTunnel(), CcRoadStop(), CYapfFollowShipT< Types >::CheckShipReverse(), CheckTownBuild2House(), CheckTownBuild2x2House(), ClearPathReservation(), CmdBuildBridge(), CmdBuildDock(), CmdBuildLock(), CmdBuildLongRoad(), CmdBuildTunnel(), ConnectRoadToStructure(), DeleteLastWagon(), DoClearBridge(), DoClearTunnel(), DrawBridgePillars(), DrawRailCatenaryRailway(), ExploreSegment(), FixOwnerOfRailTrack(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::FollowTileExit(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::ForcedReverse(), GetAnyRoadBits(), GetBridgeEnd(), GetNorthernBridgeEnd(), GetOtherAqueductEnd(), GetOtherTunnelEnd(), GetTileTrackStatus_Road(), GetTileTrackStatus_TunnelBridge(), GetTownRoadGridElement(), GrowTownAtRoad(), GrowTownInTile(), GrowTownWithBridge(), GrowTownWithTunnel(), IsNeighbourRoadTile(), IsWateredTile(), MaskWireBits(), BuildDocksToolbarWindow::OnPlaceObject(), BuildDocksToolbarWindow::OnPlacePresize(), CYapfCostRailT< Types >::PfCalcCost(), CYapfCostRoadT< Types >::PfCalcCost(), RiverMakeWider(), SetupFarmFieldFence(), TestTownOwnsBridge(), TrainApproachingCrossing(), TrainCanLeaveTile(), TrainCheckIfLineEnds(), TrainController(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::TryReverse(), UpdateSignalsInBuffer(), VehicleEnterTile_Rail(), VehicleEnterTile_TunnelBridge(), and VisitAdjacentWaterRegionPatchNeighbours().
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(), and to_underlying().
Referenced by AfterLoadGame(), CheckShipStayInDepot(), DrawRailCatenaryOnBridge(), RoadVehicle::GetImage(), Train::GetImage(), Vehicle::GetMovingDirection(), Vehicle::SetMovingDirection(), SpawnAdvancedVisualEffect(), TileLoop_Water(), Train::UpdateDeltaXY(), UpdateStatusAfterSwap(), VehicleEnterTile_Rail(), and VehicleEnterTile_Road().
|
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 288 of file direction_func.h.
References IsValidAxis(), and to_underlying().
Referenced by AfterLoadGame(), and GetShipDepotDirection().