OpenTTD: src/direction_func.h File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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

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

  a | The axis

Returns
  The direction pointed to south

Definition at line 220 of file direction_func.h.

References IsValidAxis().

Referenced by CmdBuildBridge(), CmdBuildLongRoad(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadStop(), DrawBridgePillars(), GetNorthernBridgeEnd(), GetSouthernBridgeEnd(), and TrainApproachingCrossing().

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

  a | The axis

Returns
  The direction pointed to south

Definition at line 237 of file direction_func.h.

References IsValidAxis().

Referenced by AfterLoadGame().

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

  d | The DiagDirection
  delta | The difference to apply on

Returns
  The new direction which was calculated

Definition at line 137 of file direction_func.h.

References IsValidDiagDirection().

Referenced by AircraftGetEntryPoint(), GrowTownInTile(), IsNeighborRoadTile(), and TrainExitDir().

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

  d | The direction to get a new direction from
  delta | The offset/drift applied to the direction

Returns
  The new direction

Definition at line 106 of file direction_func.h.

References IsValidDirection().

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

static DirDiff ChangeDirDiff | ( | DirDiff | d,
|  | DirDiff | delta
| ) |  |
| inlinestatic

Applies two differences together.

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

Parameters

  d | The first difference
  delta | The second difference to add on

Returns
  The resulting difference

Definition at line 90 of file direction_func.h.

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

  d | The DiagDirection

Returns
  The axis which belongs to the direction

Definition at line 202 of file direction_func.h.

References IsValidDiagDirection().

Referenced by AfterLoadGame(), CanEnterTileOwnerCheck(), CheckFlatLandRoadStop(), CleanUpRoadBits(), CmdBuildBridge(), CmdBuildRoad(), CmdBuildRoadStop(), CmdBuildTunnel(), CmdRemoveRoadStop(), DrawCatenaryRailway(), DrawTile_TunnelBridge(), ExploreSegment(), GetAnyRoadBits(), GetBridgeHeight(), IsRoadAllowedHere(), IsWateredTile(), MakeDock(), MaskWireBits(), PlaceRoad_BusStation(), PlaceRoad_TruckStation(), RemoveRoad(), RoadFindPathToDest(), SetRailStationPlatformReservation(), SetupFarmFieldFence(), CYapfCostBase::stSlopeCost(), TrainApproachingCrossingTile(), TryBuildLightHouse(), GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPosition(), and VehicleEnter_Track().

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

  dir | The direction to convert

Returns
  The resulting Direction

Definition at line 170 of file direction_func.h.

References IsValidDiagDirection().

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

static DirDiff DirDifference | ( | Direction | d0,
|  | Direction | d1
| ) |  |
| inlinestatic

Calculate the difference between to directions.

Parameters

  d0 | The first direction as the base
  d1 | The second direction as the offset from the base

Returns
  The difference how the second directions drifts of the first one.

Definition at line 70 of file direction_func.h.

References IsValidDirection().

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

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

  dir | The direction to convert

Returns
  The resulting DiagDirection, maybe "rounded clockwise".

Definition at line 154 of file direction_func.h.

References IsValidDirection().

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

static bool IsDiagonalDirection | ( | Direction | dir | ) |
| inlinestatic

Checks if a given Direction is diagonal.

Parameters

  dir | The given direction.

Returns
  True if the direction is diagonal.

Definition at line 261 of file direction_func.h.

References IsValidDirection().

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

static bool IsValidAxis | ( | Axis | d | ) |
| inlinestatic

Checks if an integer value is a valid Axis.

Parameters

  d | The 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 AxisToDiagDir(), AxisToDirection(), AxisToRoadBits(), AxisToTrack(), OtherAxis(), PlaceRail_Waypoint(), and XYNSToDiagDir().

static bool IsValidDiagDirection | ( | DiagDirection | d | ) |
| inlinestatic

Checks if an integer value is a valid DiagDirection.

Parameters

  d | The 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 ChangeDiagDir(), ChooseShipTrack(), DiagdirReachesTrackdirs(), DiagDirToAxis(), DiagDirToDiagTrack(), DiagDirToDiagTrackBits(), DiagDirToDiagTrackdir(), DiagDirToDir(), DiagDirToRoadBits(), ExploreSegment(), GetOtherAqueductEnd(), GrowTownAtRoad(), BuildDocksToolbarWindow::OnPlacePresize(), OPFShipChooseTrack(), ReverseDiagDir(), TileIndexDiffCByDiagDir(), TileOffsByDiagDir(), TrackEnterdirToTrackdir(), TrackExitdirToTrackdir(), and TrainController().

static bool IsValidDirection | ( | Direction | d | ) |
| inlinestatic

Checks if an integer value is a valid Direction.

Parameters

  d | The 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.

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

static Axis OtherAxis | ( | Axis | a | ) |
| inlinestatic

Select the other axis as provided.

This is basically the not-operator for the axis.

Parameters

  a | The given axis

Returns
  The other axis

Definition at line 185 of file direction_func.h.

References IsValidAxis().

Referenced by CmdBuildRailWaypoint(), CmdBuildRoad(), DrawBridgePillars(), and GetCrossingRailAxis().

static DiagDirection ReverseDiagDir | ( | DiagDirection | d | ) |
| inlinestatic

Returns the reverse direction of the given DiagDirection.

Parameters

  d | The DiagDirection to get the reverse from

Returns
  The reverse direction

Definition at line 120 of file direction_func.h.

References IsValidDiagDirection().

Referenced by AfterLoadGame(), AircraftGetEntryPoint(), CanConnectToRoad(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CanEnterTile(), CanFollowRoad(), CcBuildBridge(), CcBuildRoadTunnel(), CcRoadStop(), CheckTownBuild2House(), CheckTownBuild2x2House(), ClearPathReservation(), CmdBuildBridge(), CmdBuildDock(), CmdBuildLongRoad(), CmdBuildTunnel(), ConnectRoadToStructure(), DoClearBridge(), DoClearTunnel(), DrawBridgePillars(), DrawCatenaryRailway(), 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(), IsNeighborRoadTile(), IsWateredTile(), MaskWireBits(), BuildDocksToolbarWindow::OnPlaceObject(), BuildDocksToolbarWindow::OnPlacePresize(), OPFShipChooseTrack(), CYapfCostRoadT< Types >::PfCalcCost(), CYapfCostRailT< Types >::PfCalcCost(), RoadStop::Entry::Rebuild(), TrainApproachingCrossing(), TrainCanLeaveTile(), TrainCheckIfLineEnds(), TrainController(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::TryReverse(), UpdateSignalsInBuffer(), and VehicleEnter_Track().

static Direction ReverseDir | ( | Direction | d | ) |
| inlinestatic

Return the reverse of a direction.

Parameters

  d | The direction to get the reverse from

Returns
  The reverse Direction

Definition at line 56 of file direction_func.h.

References IsValidDirection().

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

static DiagDirection XYNSToDiagDir | ( | Axis | xy,
|  | uint | ns
| ) |  |
| inlinestatic

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

Parameters

  xy | axis to convert
  ns | north -> 0, south -> 1

Returns
  the desired DiagDirection

Definition at line 249 of file direction_func.h.

References IsValidAxis().

Referenced by AfterLoadGame(), and GetShipDepotDirection().