OpenTTD Source 20260531-master-g0e951f3528
direction_type.h File Reference

Different types to 'show' directions. More...

#include "core/enum_type.hpp"

Go to the source code of this file.

Typedefs

using Directions = EnumBitSet<Direction, uint8_t>
 Allow incrementing of Direction variables.
template<typename T>
using DirectionIndexArray = EnumIndexArray<T, Direction, Direction::End>
 Array with Direction as index.
using DiagDirections = EnumBitSet<DiagDirection, uint8_t>
 Bitset of DiagDirection elements.
template<typename T>
using DiagDirectionIndexArray = EnumIndexArray<T, DiagDirection, DiagDirection::End>
 Array with DiagDirection as index.
template<typename T>
using AxisIndexArray = EnumIndexArray<T, Axis, Axis::End>
 Array with Axis as index.

Enumerations

enum class  Direction : uint8_t {
  Begin = 0 , N = 0 , NE = 1 , E = 2 ,
  SE = 3 , S = 4 , SW = 5 , W = 6 ,
  NW = 7 , End , Invalid = 0xFF
}
 Defines the 8 directions on the map. More...
enum class  DirDiff : uint8_t {
  Same = 0 , Right45 = 1 , Right90 = 2 , Reverse = 4 ,
  Left90 = 6 , Left45 = 7
}
 Enumeration for the difference between two directions. More...
enum class  DiagDirection : uint8_t {
  Begin = 0 , NE = 0 , SE = 1 , SW = 2 ,
  NW = 3 , End , Invalid = 0xFF
}
 Enumeration for diagonal directions. More...
enum class  DiagDirDiff : uint8_t { Same = 0 , Right90 = 1 , Reverse = 2 , Left90 = 3 }
 Enumeration for the difference between to DiagDirection. More...
enum class  Axis : uint8_t { X = 0 , Y = 1 , End , Invalid = 0xFF }
 Enumeration for the two axis X and Y. More...

Variables

static constexpr Directions DIRECTIONS_ALL {Direction::N, Direction::NE, Direction::E, Direction::SE, Direction::S, Direction::SW, Direction::W, Direction::NW}
 All possible directions.
static constexpr DiagDirections DIAGDIRECTIONS_ALL {DiagDirection::NE, DiagDirection::SE, DiagDirection::SW, DiagDirection::NW}
 All possible diagonal directions.

Detailed Description

Different types to 'show' directions.

Definition in file direction_type.h.

Typedef Documentation

◆ AxisIndexArray

template<typename T>
using AxisIndexArray = EnumIndexArray<T, Axis, Axis::End>

Array with Axis as index.

Template Parameters
Tthe type contained within the array.

Definition at line 148 of file direction_type.h.

◆ DiagDirectionIndexArray

Array with DiagDirection as index.

Template Parameters
Tthe type contained within the array.

Definition at line 108 of file direction_type.h.

◆ DiagDirections

Bitset of DiagDirection elements.

Definition at line 98 of file direction_type.h.

◆ DirectionIndexArray

Array with Direction as index.

Template Parameters
Tthe type contained within the array.

Definition at line 51 of file direction_type.h.

◆ Directions

using Directions = EnumBitSet<Direction, uint8_t>

Allow incrementing of Direction variables.

Definition at line 41 of file direction_type.h.

Enumeration Type Documentation

◆ Axis

enum class Axis : uint8_t
strong

Enumeration for the two axis X and Y.

This enumeration represents the two axis X and Y in the game. The X axis is the one which goes align the north-west edge (and south-east edge). The Y axis must be so the one which goes align the north-east edge (and south-west) edge.

Enumerator

The X axis.

The y axis.

End 

End marker.

Invalid 

Flag for an invalid Axis.

Definition at line 135 of file direction_type.h.

◆ DiagDirDiff

enum class DiagDirDiff : uint8_t
strong

Enumeration for the difference between to DiagDirection.

As the DiagDirection only contains 4 possible directions the difference between two of these directions can only be in 4 ways. As the DirDiff enumeration the values can be added together and you will get the resulting difference (use modulo DiagDirection::End).

See also
DirDiff
Enumerator
Same 

Same directions.

Right90 

90 degrees right

Reverse 

Reverse directions.

Left90 

90 degrees left

Definition at line 120 of file direction_type.h.

◆ DiagDirection

enum class DiagDirection : uint8_t
strong

Enumeration for diagonal directions.

This enumeration is used for the 4 direction of the tile-edges.

Enumerator
Begin 

Used for iterations.

NE 

Northeast, upper right on your monitor.

SE 

Southeast.

SW 

Southwest.

NW 

Northwest.

End 

Used for iterations.

Invalid 

Flag for an invalid DiagDirection.

Definition at line 85 of file direction_type.h.

◆ DirDiff

enum class DirDiff : uint8_t
strong

Enumeration for the difference between two directions.

This enumeration is used to mark differences between two directions. If you get one direction you can align a second direction in 8 different ways. This enumeration only contains 6 of these 8 differences, but the remaining two can be calculated by adding to differences together. This also means you can add two differences together and get the difference you really want to get. The difference of 45 degrees left + the difference of 45 degrees right results in the difference of 0 degrees.

Note
To get this mentioned addition of direction you must use modulo Direction::End or use the ChangeDirDiff(DirDiff, DirDiff) function.
See also
ChangeDirDiff(DirDiff, DirDiff)
Enumerator
Same 

Both directions faces to the same direction.

Right45 

Angle of 45 degrees right.

Right90 

Angle of 90 degrees right.

Reverse 

One direction is the opposite of the other one.

Left90 

Angle of 90 degrees left.

Left45 

Angle of 45 degrees left.

Definition at line 70 of file direction_type.h.

◆ Direction

enum class Direction : uint8_t
strong

Defines the 8 directions on the map.

This enum defines 8 possible directions which are used for the vehicles in the game. The directions are aligned straight to the viewport, not to the map. So north points to the top of your viewport and not rotated by 45 degrees left or right to get a "north" used in you games.

Enumerator
Begin 

Used to iterate.

North.

NE 

Northeast.

East.

SE 

Southeast.

South.

SW 

Southwest.

West.

NW 

Northwest.

End 

Used to iterate.

Invalid 

Flag for an invalid direction.

Definition at line 24 of file direction_type.h.

Variable Documentation

◆ DIAGDIRECTIONS_ALL

All possible diagonal directions.

Definition at line 101 of file direction_type.h.

Referenced by InvalidateWaterRegion(), and VisitWaterRegionPatchNeighbours().

◆ DIRECTIONS_ALL

All possible directions.

Definition at line 44 of file direction_type.h.

Referenced by DrawRailCatenaryRailway().