OpenTTD
Functions
slope_func.h File Reference

Functions related to slopes. More...

#include "core/math_func.hpp"
#include "slope_type.h"
#include "direction_type.h"
#include "tile_type.h"

Go to the source code of this file.

Functions

static bool IsValidCorner (Corner corner)
 Rangecheck for Corner enumeration. More...
 
static bool IsSteepSlope (Slope s)
 Checks if a slope is steep. More...
 
static bool IsHalftileSlope (Slope s)
 Checks for non-continuous slope on halftile foundations. More...
 
static Slope RemoveHalftileSlope (Slope s)
 Removes a halftile slope from a slope. More...
 
static Slope ComplementSlope (Slope s)
 Return the complement of a slope. More...
 
static bool IsSlopeWithOneCornerRaised (Slope s)
 Tests if a specific slope has exactly one corner raised. More...
 
static Slope SlopeWithOneCornerRaised (Corner corner)
 Returns the slope with a specific corner raised. More...
 
static bool HasSlopeHighestCorner (Slope s)
 Tests if a slope has a highest corner (i.e. More...
 
static Corner GetHighestSlopeCorner (Slope s)
 Returns the highest corner of a slope (one corner raised or a steep slope). More...
 
static Corner GetHalftileSlopeCorner (Slope s)
 Returns the leveled halftile of a halftile slope. More...
 
static int GetSlopeMaxZ (Slope s)
 Returns the height of the highest corner of a slope relative to TileZ (= minimal height) More...
 
static int GetSlopeMaxPixelZ (Slope s)
 Returns the height of the highest corner of a slope relative to TileZ (= minimal height) More...
 
static Corner OppositeCorner (Corner corner)
 Returns the opposite corner. More...
 
static bool IsSlopeWithThreeCornersRaised (Slope s)
 Tests if a specific slope has exactly three corners raised. More...
 
static Slope SlopeWithThreeCornersRaised (Corner corner)
 Returns the slope with all except one corner raised. More...
 
static Slope SteepSlope (Corner corner)
 Returns a specific steep slope. More...
 
static bool IsInclinedSlope (Slope s)
 Tests if a specific slope is an inclined slope. More...
 
static DiagDirection GetInclinedSlopeDirection (Slope s)
 Returns the direction of an inclined slope. More...
 
static Slope InclinedSlope (DiagDirection dir)
 Returns the slope that is inclined in a specific direction. More...
 
static Slope HalftileSlope (Slope s, Corner corner)
 Adds a halftile slope to a slope. More...
 
static bool IsFoundation (Foundation f)
 Tests for FOUNDATION_NONE. More...
 
static bool IsLeveledFoundation (Foundation f)
 Tests if the foundation is a leveled foundation. More...
 
static bool IsInclinedFoundation (Foundation f)
 Tests if the foundation is an inclined foundation. More...
 
static bool IsNonContinuousFoundation (Foundation f)
 Tests if a foundation is a non-continuous foundation, i.e. More...
 
static Corner GetHalftileFoundationCorner (Foundation f)
 Returns the halftile corner of a halftile-foundation. More...
 
static bool IsSpecialRailFoundation (Foundation f)
 Tests if a foundation is a special rail foundation for single horizontal/vertical track. More...
 
static Corner GetRailFoundationCorner (Foundation f)
 Returns the track corner of a special rail foundation. More...
 
static Foundation FlatteningFoundation (Slope s)
 Returns the foundation needed to flatten a slope. More...
 
static Foundation InclinedFoundation (Axis axis)
 Returns the along a specific axis inclined foundation. More...
 
static Foundation HalftileFoundation (Corner corner)
 Returns the halftile foundation for single horizontal/vertical track. More...
 
static Foundation SpecialRailFoundation (Corner corner)
 Returns the special rail foundation for single horizontal/vertical track. More...
 
static uint SlopeToSpriteOffset (Slope s)
 Returns the Sprite offset for a given Slope. More...
 

Detailed Description

Functions related to slopes.

Definition in file slope_func.h.

Function Documentation

◆ ComplementSlope()

static Slope ComplementSlope ( Slope  s)
inlinestatic

Return the complement of a slope.

This method returns the complement of a slope. The complement of a slope is a slope with raised corner which aren't raised in the given slope.

Precondition
The slope must neither be steep nor a halftile slope.
Parameters
sThe Slope to get the complement.
Returns
a complement Slope of the given slope.

Definition at line 78 of file slope_func.h.

Referenced by IsRoadAllowedHere(), IsSlopeWithThreeCornersRaised(), and SlopeWithThreeCornersRaised().

◆ FlatteningFoundation()

static Foundation FlatteningFoundation ( Slope  s)
inlinestatic

Returns the foundation needed to flatten a slope.

The returned foundation is either FOUNDATION_NONE if the tile was already flat, or FOUNDATION_LEVELED.

Parameters
sThe current Slope.
Returns
The needed Foundation.

Definition at line 371 of file slope_func.h.

References FOUNDATION_LEVELED, FOUNDATION_NONE, and SLOPE_FLAT.

Referenced by GetBridgeFoundation().

◆ GetHalftileFoundationCorner()

static Corner GetHalftileFoundationCorner ( Foundation  f)
inlinestatic

Returns the halftile corner of a halftile-foundation.

Precondition
f != FOUNDATION_STEEP_BOTH
Parameters
fThe Foundation.
Returns
The Corner with track.

Definition at line 335 of file slope_func.h.

Referenced by ApplyFoundationToSlope().

◆ GetHalftileSlopeCorner()

static Corner GetHalftileSlopeCorner ( Slope  s)
inlinestatic

Returns the leveled halftile of a halftile slope.

Precondition
The slope must be a halftile slope.
Parameters
sThe Slope.
Returns
The corner of the leveled halftile.

Definition at line 150 of file slope_func.h.

Referenced by DrawAutorailSelection(), DrawTileSelectionRect(), and GetSlopePixelZOnEdge().

◆ GetHighestSlopeCorner()

static Corner GetHighestSlopeCorner ( Slope  s)
inlinestatic

Returns the highest corner of a slope (one corner raised or a steep slope).

Precondition
The slope must be a slope with one corner raised or a steep slope. A halftile slope is ignored.
Parameters
sThe Slope.
Returns
Highest corner.

Definition at line 128 of file slope_func.h.

References RemoveHalftileSlope(), SLOPE_STEEP_W, and SLOPE_W.

Referenced by ApplyFoundationToSlope(), CheckRoadSlope(), GetRailFoundation(), and GetRoadFoundation().

◆ GetInclinedSlopeDirection()

static DiagDirection GetInclinedSlopeDirection ( Slope  s)
inlinestatic

Returns the direction of an inclined slope.

Parameters
sA Slope
Returns
The direction the slope goes up in. Or INVALID_DIAGDIR if the slope is not an inclined slope.

Definition at line 241 of file slope_func.h.

References DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, INVALID_DIAGDIR, SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

Referenced by CmdBuildLock(), GetOtherAqueductEnd(), and BuildDocksToolbarWindow::OnPlacePresize().

◆ GetRailFoundationCorner()

static Corner GetRailFoundationCorner ( Foundation  f)
inlinestatic

Returns the track corner of a special rail foundation.

Parameters
fThe Foundation.
Returns
The Corner with track.

Definition at line 358 of file slope_func.h.

Referenced by ApplyFoundationToSlope().

◆ GetSlopeMaxPixelZ()

static int GetSlopeMaxPixelZ ( Slope  s)
inlinestatic

Returns the height of the highest corner of a slope relative to TileZ (= minimal height)

Parameters
sThe Slope.
Returns
Relative height of highest corner.

Definition at line 175 of file slope_func.h.

References GetSlopeMaxZ(), and TILE_HEIGHT.

◆ GetSlopeMaxZ()

static int GetSlopeMaxZ ( Slope  s)
inlinestatic

Returns the height of the highest corner of a slope relative to TileZ (= minimal height)

Parameters
sThe Slope.
Returns
Relative height of highest corner.

Definition at line 162 of file slope_func.h.

References IsSteepSlope(), and SLOPE_FLAT.

Referenced by AutoslopeCheckForEntranceEdge(), CheckBuildableTile(), and GetSlopeMaxPixelZ().

◆ HalftileFoundation()

static Foundation HalftileFoundation ( Corner  corner)
inlinestatic

Returns the halftile foundation for single horizontal/vertical track.

Parameters
cornerThe Corner with the track.
Returns
The wanted Foundation.

Definition at line 393 of file slope_func.h.

Referenced by GetRailFoundation().

◆ HalftileSlope()

static Slope HalftileSlope ( Slope  s,
Corner  corner 
)
inlinestatic

Adds a halftile slope to a slope.

Parameters
sSlope without a halftile slope.
cornerThe Corner of the halftile.
Returns
The Slope s with the halftile slope added.

Definition at line 276 of file slope_func.h.

Referenced by ApplyFoundationToSlope().

◆ HasSlopeHighestCorner()

static bool HasSlopeHighestCorner ( Slope  s)
inlinestatic

Tests if a slope has a highest corner (i.e.

one corner raised or a steep slope).

Note: A halftile slope is ignored.

Parameters
sThe Slope.
Returns
true iff the slope has a highest corner.

Definition at line 115 of file slope_func.h.

References IsSlopeWithOneCornerRaised(), IsSteepSlope(), and RemoveHalftileSlope().

Referenced by GetBridgeFoundation().

◆ InclinedFoundation()

static Foundation InclinedFoundation ( Axis  axis)
inlinestatic

Returns the along a specific axis inclined foundation.

Parameters
axisThe Axis.
Returns
The needed Foundation.

Definition at line 382 of file slope_func.h.

References AXIS_X, FOUNDATION_INCLINED_X, and FOUNDATION_INCLINED_Y.

Referenced by GetBridgeFoundation().

◆ InclinedSlope()

static Slope InclinedSlope ( DiagDirection  dir)
inlinestatic

Returns the slope that is inclined in a specific direction.

Parameters
dirA DiagDirection
Returns
The Slope that goes up in direction dir.

Definition at line 258 of file slope_func.h.

References DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

Referenced by AdjustTileh().

◆ IsFoundation()

static bool IsFoundation ( Foundation  f)
inlinestatic

Tests for FOUNDATION_NONE.

Parameters
fMaybe a Foundation.
Returns
true iff f is a foundation.

Definition at line 289 of file slope_func.h.

References FOUNDATION_NONE.

Referenced by ApplyFoundationToSlope(), and DrawFoundation().

◆ IsHalftileSlope()

static bool IsHalftileSlope ( Slope  s)
inlinestatic

Checks for non-continuous slope on halftile foundations.

Parameters
sThe given Slope.
Returns
True if the slope is non-continuous, else false.

Definition at line 49 of file slope_func.h.

References SLOPE_HALFTILE.

Referenced by DrawAutorailSelection(), DrawTileSelectionRect(), DrawTrackDetails(), GetSlopePixelZOnEdge(), and IsSlopeWithThreeCornersRaised().

◆ IsInclinedFoundation()

static bool IsInclinedFoundation ( Foundation  f)
inlinestatic

Tests if the foundation is an inclined foundation.

Parameters
fThe Foundation.
Returns
true iff f is an inclined foundation.

Definition at line 311 of file slope_func.h.

References FOUNDATION_INCLINED_X, and FOUNDATION_INCLINED_Y.

◆ IsInclinedSlope()

static bool IsInclinedSlope ( Slope  s)
inlinestatic

Tests if a specific slope is an inclined slope.

Parameters
sThe Slope
Returns
true iff the slope is inclined.

Definition at line 230 of file slope_func.h.

References SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

◆ IsLeveledFoundation()

static bool IsLeveledFoundation ( Foundation  f)
inlinestatic

Tests if the foundation is a leveled foundation.

Parameters
fThe Foundation.
Returns
true iff f is a leveled foundation.

Definition at line 300 of file slope_func.h.

References FOUNDATION_LEVELED.

Referenced by ApplyFoundationToSlope().

◆ IsNonContinuousFoundation()

static bool IsNonContinuousFoundation ( Foundation  f)
inlinestatic

Tests if a foundation is a non-continuous foundation, i.e.

halftile-foundation or FOUNDATION_STEEP_BOTH.

Parameters
fThe Foundation.
Returns
true iff f is a non-continuous foundation

Definition at line 322 of file slope_func.h.

References FOUNDATION_HALFTILE_N, FOUNDATION_STEEP_BOTH, and IsInsideMM().

Referenced by ApplyFoundationToSlope().

◆ IsSlopeWithOneCornerRaised()

static bool IsSlopeWithOneCornerRaised ( Slope  s)
inlinestatic

Tests if a specific slope has exactly one corner raised.

Parameters
sThe Slope
Returns
true iff exactly one corner is raised

Definition at line 90 of file slope_func.h.

References SLOPE_E, SLOPE_N, SLOPE_S, and SLOPE_W.

Referenced by CanPlantTreesOnTile(), GetFloodingBehaviour(), GetRoadFoundation(), HasSlopeHighestCorner(), and IsSlopeWithThreeCornersRaised().

◆ IsSlopeWithThreeCornersRaised()

static bool IsSlopeWithThreeCornersRaised ( Slope  s)
inlinestatic

Tests if a specific slope has exactly three corners raised.

Parameters
sThe Slope
Returns
true iff exactly three corners are raised

Definition at line 197 of file slope_func.h.

References ComplementSlope(), IsHalftileSlope(), IsSlopeWithOneCornerRaised(), and IsSteepSlope().

◆ IsSpecialRailFoundation()

static bool IsSpecialRailFoundation ( Foundation  f)
inlinestatic

Tests if a foundation is a special rail foundation for single horizontal/vertical track.

Parameters
fThe Foundation.
Returns
true iff f is a special rail foundation for single horizontal/vertical track.

Definition at line 347 of file slope_func.h.

References FOUNDATION_RAIL_N, FOUNDATION_RAIL_W, and IsInsideMM().

Referenced by ApplyFoundationToSlope().

◆ IsSteepSlope()

static bool IsSteepSlope ( Slope  s)
inlinestatic

Checks if a slope is steep.

Parameters
sThe given Slope.
Returns
True if the slope is steep, else false.

Definition at line 38 of file slope_func.h.

References SLOPE_STEEP.

Referenced by ApplyFoundationToSlope(), CanBuildHouseHere(), CheckBuildableTile(), CheckRailSlope(), CheckRoadSlope(), GetRailFoundation(), GetRoadFoundation(), GetSlopeMaxZ(), HasSlopeHighestCorner(), IsSlopeWithThreeCornersRaised(), and SearchTileForStatue().

◆ IsValidCorner()

static bool IsValidCorner ( Corner  corner)
inlinestatic

Rangecheck for Corner enumeration.

Parameters
cornerA Corner.
Returns
true iff corner is in a valid range.

Definition at line 26 of file slope_func.h.

References IsInsideMM().

◆ OppositeCorner()

static Corner OppositeCorner ( Corner  corner)
inlinestatic

Returns the opposite corner.

Parameters
cornerA Corner.
Returns
The opposite corner to "corner".

Definition at line 186 of file slope_func.h.

Referenced by ApplyFoundationToSlope(), DrawAutorailSelection(), and SteepSlope().

◆ RemoveHalftileSlope()

static Slope RemoveHalftileSlope ( Slope  s)
inlinestatic

Removes a halftile slope from a slope.

Non-halftile slopes remain unmodified.

Parameters
sA Slope.
Returns
The slope s without its halftile slope.

Definition at line 62 of file slope_func.h.

References SLOPE_HALFTILE_MASK.

Referenced by DrawAutorailSelection(), GetHighestSlopeCorner(), GetSlopePixelZOnEdge(), and HasSlopeHighestCorner().

◆ SlopeToSpriteOffset()

static uint SlopeToSpriteOffset ( Slope  s)
inlinestatic

Returns the Sprite offset for a given Slope.

Parameters
sThe Slope to get the offset for.
Returns
The sprite offset for this Slope.

Definition at line 417 of file slope_func.h.

References _slope_to_sprite_offset.

◆ SlopeWithOneCornerRaised()

static Slope SlopeWithOneCornerRaised ( Corner  corner)
inlinestatic

Returns the slope with a specific corner raised.

Parameters
cornerThe Corner.
Returns
The Slope with corner "corner" raised.

Definition at line 101 of file slope_func.h.

Referenced by CheckRoadSlope(), GetRoadFoundation(), GetSlopePixelZOnEdge(), and SlopeWithThreeCornersRaised().

◆ SlopeWithThreeCornersRaised()

static Slope SlopeWithThreeCornersRaised ( Corner  corner)
inlinestatic

Returns the slope with all except one corner raised.

Parameters
cornerThe Corner.
Returns
The Slope with all corners but "corner" raised.

Definition at line 208 of file slope_func.h.

References ComplementSlope(), and SlopeWithOneCornerRaised().

Referenced by ApplyFoundationToSlope(), DrawAutorailSelection(), and SteepSlope().

◆ SpecialRailFoundation()

static Foundation SpecialRailFoundation ( Corner  corner)
inlinestatic

Returns the special rail foundation for single horizontal/vertical track.

Parameters
cornerThe Corner with the track.
Returns
The wanted Foundation.

Definition at line 405 of file slope_func.h.

◆ SteepSlope()

static Slope SteepSlope ( Corner  corner)
inlinestatic

Returns a specific steep slope.

Parameters
cornerA Corner.
Returns
The steep Slope with "corner" as highest corner.

Definition at line 219 of file slope_func.h.

References OppositeCorner(), SLOPE_STEEP, and SlopeWithThreeCornersRaised().