OpenTTD Source 20260721-master-g25ec12c62d
slope_type.h File Reference

Definitions of a slope. More...

#include "core/enum_type.hpp"

Go to the source code of this file.

Macros

#define M(x)
 Helper for creating a bitset of slopes.

Typedefs

template<typename T>
using CornerIndexArray = EnumIndexArray<T, Corner, CORNER_END>
 Array with Corner as index.
template<typename T>
using SlopeIndexArray = EnumClassIndexContainer<std::array<T, SLOPE_STEEP | SLOPE_ELEVATED>, Slope>
 Array with Slope as index.
template<typename T>
using NonSteepSlopeIndexArray = EnumClassIndexContainer<std::array<T, SLOPE_ELEVATED>, Slope>
 Array with non steep Slope as index.

Enumerations

enum  Corner : uint8_t {
  CORNER_W = 0 , CORNER_S = 1 , CORNER_E = 2 , CORNER_N = 3 ,
  CORNER_END , CORNER_INVALID = 0xFF
}
 Enumeration of tile corners. More...
enum  Slope : uint8_t {
  SLOPE_FLAT = 0x00 , SLOPE_W = 0x01 , SLOPE_S = 0x02 , SLOPE_E = 0x04 ,
  SLOPE_N = 0x08 , SLOPE_STEEP = 0x10 , SLOPE_NW = SLOPE_N | SLOPE_W , SLOPE_SW = SLOPE_S | SLOPE_W ,
  SLOPE_SE = SLOPE_S | SLOPE_E , SLOPE_NE = SLOPE_N | SLOPE_E , SLOPE_EW = SLOPE_E | SLOPE_W , SLOPE_NS = SLOPE_N | SLOPE_S ,
  SLOPE_ELEVATED = SLOPE_N | SLOPE_E | SLOPE_S | SLOPE_W , SLOPE_NWS = SLOPE_N | SLOPE_W | SLOPE_S , SLOPE_WSE = SLOPE_W | SLOPE_S | SLOPE_E , SLOPE_SEN = SLOPE_S | SLOPE_E | SLOPE_N ,
  SLOPE_ENW = SLOPE_E | SLOPE_N | SLOPE_W , SLOPE_STEEP_W = SLOPE_STEEP | SLOPE_NWS , SLOPE_STEEP_S = SLOPE_STEEP | SLOPE_WSE , SLOPE_STEEP_E = SLOPE_STEEP | SLOPE_SEN ,
  SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW , SLOPE_HALFTILE = 0x20 , SLOPE_HALFTILE_MASK = 0xE0 , SLOPE_HALFTILE_W = SLOPE_HALFTILE | (CORNER_W << 6) ,
  SLOPE_HALFTILE_S = SLOPE_HALFTILE | (CORNER_S << 6) , SLOPE_HALFTILE_E = SLOPE_HALFTILE | (CORNER_E << 6) , SLOPE_HALFTILE_N = SLOPE_HALFTILE | (CORNER_N << 6)
}
 Enumeration for the slope-type. More...
enum class  Foundation : uint8_t {
  None , Leveled , InclinedX , InclinedY ,
  SteepLower , SteepBoth , HalfTileW , HalfTileS ,
  HalfTileE , HalfTileN , HalfTileEnd , RailW = Foundation::HalfTileEnd ,
  RailS , RailE , RailN , End ,
  Invalid = 0xFF
}
 Enumeration for Foundations. More...

Variables

static constexpr uint8_t NUM_SLOPES = 19
 The total number of possible slope types.
static const uint32_t VALID_LEVEL_CROSSING_SLOPES = M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT)
 Constant bitset with safe slopes for building a level crossing.

Detailed Description

Definitions of a slope.

This file defines the enumeration and helper functions for handling the slope info of a tile.

Definition in file slope_type.h.

Macro Definition Documentation

◆ M

#define M ( x)
Value:
(1U << (x))

Helper for creating a bitset of slopes.

Parameters
xThe slope to convert into a bitset.

Definition at line 110 of file slope_type.h.

Typedef Documentation

◆ CornerIndexArray

template<typename T>
using CornerIndexArray = EnumIndexArray<T, Corner, CORNER_END>

Array with Corner as index.

Template Parameters
Tthe type contained within the array.

Definition at line 35 of file slope_type.h.

◆ NonSteepSlopeIndexArray

template<typename T>
using NonSteepSlopeIndexArray = EnumClassIndexContainer<std::array<T, SLOPE_ELEVATED>, Slope>

Array with non steep Slope as index.

Note
Remove halftile form the slope before accessing an element.
SLOPE_ELEVATED is just SLOPE_FLAT with height increased by one, therefore it is not a valid index.
Template Parameters
Tthe type contained within the array.

Definition at line 104 of file slope_type.h.

◆ SlopeIndexArray

template<typename T>
using SlopeIndexArray = EnumClassIndexContainer<std::array<T, SLOPE_STEEP | SLOPE_ELEVATED>, Slope>

Array with Slope as index.

Note
Remove halftile form the slope before accessing an element.
Elevated steep slope (e.g. value 31) is an invalid slope because it does not define which corner is steep.
Template Parameters
Tthe type contained within the array.

Definition at line 95 of file slope_type.h.

Enumeration Type Documentation

◆ Corner

enum Corner : uint8_t

Enumeration of tile corners.

Definition at line 21 of file slope_type.h.

◆ Foundation

enum class Foundation : uint8_t
strong

Enumeration for Foundations.

Enumerator
None 

The tile has no foundation, the slope remains unchanged.

Leveled 

The tile is leveled up to a flat slope.

InclinedX 

The tile has an along X-axis inclined foundation.

InclinedY 

The tile has an along Y-axis inclined foundation.

SteepLower 

The tile has a steep slope. The lowest corner is raised by a foundation to allow building railroad on the lower halftile.

SteepBoth 

The tile has a steep slope. The lowest corner is raised by a foundation and the upper halftile is leveled.

HalfTileW 

Level west halftile non-continuously.

HalfTileS 

Level south halftile non-continuously.

HalfTileE 

Level east halftile non-continuously.

HalfTileN 

Level north halftile non-continuously.

HalfTileEnd 

End marker for halftile foundations.

RailW 

Foundation for TRACK_BIT_LEFT, but not a leveled foundation.

RailS 

Foundation for TRACK_BIT_LOWER, but not a leveled foundation.

RailE 

Foundation for TRACK_BIT_RIGHT, but not a leveled foundation.

RailN 

Foundation for TRACK_BIT_UPPER, but not a leveled foundation.

End 

End marker.

Invalid 

Used inside "rail_cmd.cpp" to indicate invalid slope/track combination.

Definition at line 119 of file slope_type.h.

◆ Slope

enum Slope : uint8_t

Enumeration for the slope-type.

This enumeration use the chars N,E,S,W corresponding the direction north, east, south and west. The top corner of a tile is the north-part of the tile. The whole slope is encoded with 5 bits, 4 bits for each corner and 1 bit for a steep-flag.

For halftile slopes an extra 3 bits are used to represent this properly; 1 bit for a halftile-flag and 2 bits to encode which extra side (corner) is leveled when the slope of the first 5 bits is applied. This means that there can only be one leveled slope for steep slopes, which is logical because two leveled slopes would mean that it is not a steep slope as halftile slopes only span one height level.

Enumerator
SLOPE_FLAT 

a flat tile

SLOPE_W 

the west corner of the tile is raised

SLOPE_S 

the south corner of the tile is raised

SLOPE_E 

the east corner of the tile is raised

SLOPE_N 

the north corner of the tile is raised

SLOPE_STEEP 

indicates the slope is steep

SLOPE_NW 

north and west corner are raised

SLOPE_SW 

south and west corner are raised

SLOPE_SE 

south and east corner are raised

SLOPE_NE 

north and east corner are raised

SLOPE_EW 

east and west corner are raised

SLOPE_NS 

north and south corner are raised

SLOPE_ELEVATED 

bit mask containing all 'simple' slopes

SLOPE_NWS 

north, west and south corner are raised

SLOPE_WSE 

west, south and east corner are raised

SLOPE_SEN 

south, east and north corner are raised

SLOPE_ENW 

east, north and west corner are raised

SLOPE_STEEP_W 

a steep slope falling to east (from west)

SLOPE_STEEP_S 

a steep slope falling to north (from south)

SLOPE_STEEP_E 

a steep slope falling to west (from east)

SLOPE_STEEP_N 

a steep slope falling to south (from north)

SLOPE_HALFTILE 

one halftile is leveled (non continuous slope)

SLOPE_HALFTILE_MASK 

three bits used for halftile slopes

SLOPE_HALFTILE_W 

the west halftile is leveled (non continuous slope)

SLOPE_HALFTILE_S 

the south halftile is leveled (non continuous slope)

SLOPE_HALFTILE_E 

the east halftile is leveled (non continuous slope)

SLOPE_HALFTILE_N 

the north halftile is leveled (non continuous slope)

Definition at line 53 of file slope_type.h.

Variable Documentation

◆ NUM_SLOPES

uint8_t NUM_SLOPES = 19
staticconstexpr

The total number of possible slope types.

Definition at line 86 of file slope_type.h.

Referenced by DrawTile_Road(), DrawTile_TunnelBridge(), and GetRoadGroundSprite().

◆ VALID_LEVEL_CROSSING_SLOPES

const uint32_t VALID_LEVEL_CROSSING_SLOPES = M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT)
static

Constant bitset with safe slopes for building a level crossing.

Definition at line 112 of file slope_type.h.

Referenced by CmdBuildRoad(), CmdBuildSingleRail(), and TerraformTile_Road().