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

Detailed Description

Functions related to slopes.

Definition in file slope_func.h.

Function Documentation

◆ ComplementSlope()

Slope ComplementSlope ( Slope s)
inline

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 86 of file slope_func.h.

References IsHalftileSlope(), IsSteepSlope(), and SLOPE_ELEVATED.

Referenced by CmdBuildTunnel(), DrawTrackBits(), DrawTrackDetails(), FlowRiver(), IsRoadAllowedHere(), IsSlopeWithThreeCornersRaised(), RiverMakeWider(), and SlopeWithThreeCornersRaised().

◆ FlatteningFoundation()

Foundation FlatteningFoundation ( Slope s)
inline

Returns the foundation needed to flatten a slope.

Parameters
sThe current Slope.
Returns
Either Foundation::None if the tile was already flat, or Foundation::Leveled.

Definition at line 377 of file slope_func.h.

References Leveled, None, and SLOPE_FLAT.

Referenced by GetBridgeFoundation(), GetFoundation_Industry(), GetFoundation_Object(), GetFoundation_Rail(), GetFoundation_Road(), and GetFoundation_Town().

◆ GetHalftileFoundationCorner()

Corner GetHalftileFoundationCorner ( Foundation f)
inline

Returns the halftile corner of a halftile-foundation.

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

Definition at line 343 of file slope_func.h.

References HalfTileEnd, HalfTileW, IsInsideMM(), and to_underlying().

Referenced by ApplyFoundationToSlope(), DrawFoundation(), and DrawTrackBits().

◆ GetHalftileSlopeCorner()

constexpr Corner GetHalftileSlopeCorner ( Slope s)
inlinestaticconstexpr

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 158 of file slope_func.h.

References IsHalftileSlope().

Referenced by DrawAutorailSelection(), DrawRailCatenaryRailway(), DrawTileSelection(), DrawTileSelectionRect(), DrawTrackDetails(), GetPartialPixelZ(), and GetSlopePixelZOnEdge().

◆ GetHighestSlopeCorner()

Corner GetHighestSlopeCorner ( Slope s)
inline

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 136 of file slope_func.h.

References RemoveHalftileSlope(), SLOPE_E, SLOPE_N, SLOPE_S, SLOPE_STEEP_E, SLOPE_STEEP_N, SLOPE_STEEP_S, SLOPE_STEEP_W, and SLOPE_W.

Referenced by ApplyFoundationToSlope(), CheckRoadSlope(), DrawFoundation(), DrawTrackBits(), DrawTrackDetails(), FloodHalftile(), GetRailFoundation(), GetRoadFoundation(), and RemoveRoad().

◆ GetInclinedSlopeDirection()

DiagDirection GetInclinedSlopeDirection ( Slope s)
inline

Returns the direction of an inclined slope.

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

Definition at line 249 of file slope_func.h.

References Invalid, NE, NW, SE, SLOPE_NE, SLOPE_NW, SLOPE_SE, SLOPE_SW, and SW.

Referenced by AfterLoadGame(), CmdBuildDock(), CmdBuildLock(), CmdBuildTunnel(), GetOtherAqueductEnd(), BuildDocksToolbarWindow::OnPlaceObject(), BuildDocksToolbarWindow::OnPlacePresize(), RiverMakeWider(), and ShipTestUpDownOnLock().

◆ GetRailFoundationCorner()

Corner GetRailFoundationCorner ( Foundation f)
inline

Returns the track corner of a special rail foundation.

Parameters
fThe Foundation.
Returns
The Corner with track.

Definition at line 366 of file slope_func.h.

References IsSpecialRailFoundation(), RailW, and to_underlying().

Referenced by ApplyFoundationToSlope(), and DrawFoundation().

◆ GetSlopeMaxPixelZ()

constexpr int GetSlopeMaxPixelZ ( Slope s)
inlinestaticconstexpr

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 183 of file slope_func.h.

References GetSlopeMaxZ(), and TILE_HEIGHT.

Referenced by DrawClearLandFence(), DrawTile_Trees(), and GetPartialPixelZ().

◆ GetSlopeMaxZ()

constexpr int GetSlopeMaxZ ( Slope s)
inlinestaticconstexpr

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 170 of file slope_func.h.

References IsSteepSlope(), and SLOPE_FLAT.

Referenced by AutoslopeCheckForEntranceEdge(), CheckBuildableTile(), GetSlopeMaxPixelZ(), TerraformTile_Industry(), TerraformTile_Object(), TerraformTile_Road(), TerraformTile_Station(), and TerraformTile_Town().

◆ HalftileFoundation()

Foundation HalftileFoundation ( Corner corner)
inline

Returns the halftile foundation for single horizontal/vertical track.

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

Definition at line 399 of file slope_func.h.

References HalfTileW, and IsValidCorner().

Referenced by DrawTrackBits(), and GetRailFoundation().

◆ HalftileSlope()

constexpr Slope HalftileSlope ( Slope s,
Corner corner )
inlinestaticconstexpr

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 284 of file slope_func.h.

References IsValidCorner(), and SLOPE_HALFTILE.

Referenced by ApplyFoundationToSlope().

◆ HasSlopeHighestCorner()

bool HasSlopeHighestCorner ( Slope s)
inline

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 123 of file slope_func.h.

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

Referenced by GetBridgeFoundation().

◆ InclinedFoundation()

Foundation InclinedFoundation ( Axis axis)
inline

Returns the along a specific axis inclined foundation.

Parameters
axisThe Axis.
Returns
The needed Foundation.

Definition at line 388 of file slope_func.h.

References InclinedX, InclinedY, and X.

Referenced by GetBridgeFoundation().

◆ InclinedSlope()

Slope InclinedSlope ( DiagDirection dir)
inline

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 266 of file slope_func.h.

References NE, NW, SE, SLOPE_NE, SLOPE_NW, SLOPE_SE, SLOPE_SW, and SW.

Referenced by AdjustTileh(), CanBuildDepotByTileh(), DrawRailCatenaryRailway(), GrowTownWithBridge(), and GrowTownWithTunnel().

◆ IsFoundation()

bool IsFoundation ( Foundation f)
inline

Tests whether the given foundation is a foundation.

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

Definition at line 297 of file slope_func.h.

References None.

Referenced by ApplyFoundationToSlope(), and DrawFoundation().

◆ IsHalftileSlope()

constexpr bool IsHalftileSlope ( Slope s)
inlinestaticconstexpr

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 57 of file slope_func.h.

References SLOPE_HALFTILE.

Referenced by ComplementSlope(), DrawAutorailSelection(), DrawRailCatenaryRailway(), DrawTileSelection(), DrawTileSelectionRect(), DrawTrackDetails(), GetHalftileSlopeCorner(), GetPartialPixelZ(), GetSlopePixelZOnEdge(), GetSlopeZInCorner(), and IsSlopeWithThreeCornersRaised().

◆ IsInclinedFoundation()

bool IsInclinedFoundation ( Foundation f)
inline

Tests if the foundation is an inclined foundation.

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

Definition at line 319 of file slope_func.h.

References InclinedX, and InclinedY.

Referenced by DrawFoundation().

◆ IsInclinedSlope()

bool IsInclinedSlope ( Slope s)
inline

Tests if a specific slope is an inclined slope.

Parameters
sThe Slope
Returns
true iff the slope is inclined.

Definition at line 238 of file slope_func.h.

References SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

Referenced by CmdBuildCanal(), RiverFlowsDown(), and RiverMakeWider().

◆ IsLeveledFoundation()

bool IsLeveledFoundation ( Foundation f)
inline

Tests if the foundation is a leveled foundation.

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

Definition at line 308 of file slope_func.h.

References Leveled.

Referenced by ApplyFoundationToSlope(), and DrawFoundation().

◆ IsNonContinuousFoundation()

bool IsNonContinuousFoundation ( Foundation f)
inline

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

halftile-foundation or Foundation::SteepBoth.

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

Definition at line 330 of file slope_func.h.

References HalfTileEnd, IsInsideMM(), and SteepBoth.

Referenced by ApplyFoundationToSlope(), DrawFoundation(), DrawTrackBits(), FloodHalftile(), and TileLoop_Rail().

◆ IsSlopeWithOneCornerRaised()

◆ IsSlopeWithThreeCornersRaised()

bool IsSlopeWithThreeCornersRaised ( Slope s)
inline

Tests if a specific slope has exactly three corners raised.

Parameters
sThe Slope
Returns
true iff exactly three corners are raised

Definition at line 205 of file slope_func.h.

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

Referenced by FloodHalftile(), GetRailFoundation(), RiverMakeWider(), and TileLoop_Rail().

◆ IsSpecialRailFoundation()

bool IsSpecialRailFoundation ( Foundation f)
inline

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 355 of file slope_func.h.

References End, IsInsideMM(), and RailW.

Referenced by ApplyFoundationToSlope(), DrawFoundation(), GetRailFoundationCorner(), and TerraformTile_Rail().

◆ IsSteepSlope()

◆ IsValidCorner()

constexpr bool IsValidCorner ( Corner corner)
inlinestaticconstexpr

Rangecheck for Corner enumeration.

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

Definition at line 24 of file slope_func.h.

References IsInsideMM().

Referenced by CornerToTrackBits(), DrawRailCatenaryRailway(), DrawTrackBits(), DrawTrackFence(), HalftileFoundation(), HalftileSlope(), SlopeWithOneCornerRaised(), and SpecialRailFoundation().

◆ OppositeCorner()

Corner OppositeCorner ( Corner corner)
inline

Returns the opposite corner.

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

Definition at line 194 of file slope_func.h.

Referenced by ApplyFoundationToSlope(), DrawAutorailSelection(), DrawTileSelectionRect(), DrawTrackBits(), DrawTrackDetails(), FloodHalftile(), GetRailFoundation(), and SteepSlope().

◆ RemoveHalftileSlope()

constexpr Slope RemoveHalftileSlope ( Slope s)
inlinestaticconstexpr

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 70 of file slope_func.h.

References SLOPE_HALFTILE_MASK.

Referenced by DrawAutorailSelection(), DrawTileSelection(), DrawTrackFence(), GetHighestSlopeCorner(), GetPartialPixelZ(), GetSlopePixelZOnEdge(), HasSlopeHighestCorner(), IsRoadAllowedHere(), IsUphillTrackdir(), TestAutoslopeOnRailTile(), and TileLoop_Water().

◆ RemoveSteepSlope()

constexpr Slope RemoveSteepSlope ( Slope s)
staticconstexpr

Removes a steep flag from a slope.

Parameters
sA Slope to get modified version of.
Returns
The slope s without the steep flag.

Definition at line 46 of file slope_func.h.

References SLOPE_STEEP.

Referenced by DrawFoundation(), IsRoadAllowedHere(), and TileLoop_Water().

◆ SlopeToSpriteOffset()

uint SlopeToSpriteOffset ( Slope s)
inline

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 423 of file slope_func.h.

References _slope_to_sprite_offset.

Referenced by DrawClearLandTile(), DrawRoughLandTile(), DrawTile_Clear(), DrawTile_Trees(), DrawTile_TunnelBridge(), DrawTile_Void(), DrawTileSelectionRect(), DrawTrackBits(), and GetRoadGroundSprite().

◆ SlopeWithOneCornerRaised()

Slope SlopeWithOneCornerRaised ( Corner corner)
inline

Returns the slope with a specific corner raised.

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

Definition at line 109 of file slope_func.h.

References IsValidCorner().

Referenced by ApplyFoundationToSlope(), CheckRoadSlope(), DrawFoundation(), DrawTileSelectionRect(), GetRailFoundation(), GetRoadFoundation(), GetSlopePixelZOnEdge(), GetSlopeZInCorner(), RemoveRoad(), and SlopeWithThreeCornersRaised().

◆ SlopeWithThreeCornersRaised()

Slope SlopeWithThreeCornersRaised ( Corner corner)
inline

Returns the slope with all except one corner raised.

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

Definition at line 216 of file slope_func.h.

References ComplementSlope(), and SlopeWithOneCornerRaised().

Referenced by ApplyFoundationToSlope(), DrawAutorailSelection(), DrawFoundation(), DrawTrackBits(), GetRailFoundation(), and SteepSlope().

◆ SpecialRailFoundation()

Foundation SpecialRailFoundation ( Corner corner)
inline

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

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

Definition at line 411 of file slope_func.h.

References IsValidCorner(), and RailW.

Referenced by GetRailFoundation().

◆ SteepSlope()

Slope SteepSlope ( Corner corner)
inline

Returns a specific steep slope.

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

Definition at line 227 of file slope_func.h.

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

Referenced by GetSlopeZInCorner().