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

## Detailed Description

Functions related to slopes.

Definition in file slope_func.h.

## Function Documentation

static Slope ComplementSlope | ( | Slope | s | ) | `[inline, static]`

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:

  | s | The Slope to get the complement.

Returns:
  a complement Slope of the given slope.

Definition at line 78 of file slope_func.h.

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

Referenced by CmdBuildTunnel(), DrawTrackBits(), AITile::GetComplementSlope(), IsRoadAllowedHere(), IsSlopeWithThreeCornersRaised(), and SlopeWithThreeCornersRaised().

static Foundation FlatteningFoundation | ( | Slope | s | ) | `[inline, static]`

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:

  | s | The current Slope.

Returns:
  The needed Foundation.

Definition at line 360 of file slope_func.h.

References FOUNDATION_LEVELED, FOUNDATION_NONE, and SLOPE_FLAT.

Referenced by GetFoundation_Town().

static Corner GetHalftileFoundationCorner | ( | Foundation | f | ) | `[inline, static]`

Returns the halftile corner of a halftile-foundation.

Precondition:
  f != FOUNDATION_STEEP_BOTH

Parameters:

  | f | The Foundation.

Returns:
  The Corner with track.

Definition at line 324 of file slope_func.h.

References FOUNDATION_HALFTILE_N, FOUNDATION_HALFTILE_W, and IsInsideMM().

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

static Corner GetHalftileSlopeCorner | ( | Slope | s | ) | `[inline, static]`

Returns the leveled halftile of a halftile slope.

Precondition:
  The slope must be a halftile slope.

Parameters:

  | s | The Slope.

Returns:
  The corner of the leveled halftile.

Definition at line 150 of file slope_func.h.

References IsHalftileSlope().

Referenced by DrawAutorailSelection(), DrawTileSelection(), DrawTileSelectionRect(), GetPartialZ(), and GetSlopeZOnEdge().

static Corner GetHighestSlopeCorner | ( | Slope | s | ) | `[inline, static]`

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:

  | s | The Slope.

Returns:
  Highest corner.

Definition at line 128 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(), DrawFoundation(), DrawTrackBits(), FloodHalftile(), and GetRailFoundation().

static DiagDirection GetInclinedSlopeDirection | ( | Slope | s | ) | `[inline, static]`

Returns the direction of an inclined slope.

Parameters:

  | s | A Slope

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

Definition at line 230 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 CmdBuildDock(), CmdBuildLock(), CmdBuildTunnel(), AITunnel::GetOtherTunnelEnd(), and BuildDocksToolbarWindow::OnPlacePresize().

static Corner GetRailFoundationCorner | ( | Foundation | f | ) | `[inline, static]`

Returns the track corner of a special rail foundation.

Parameters:

  | f | The Foundation.

Returns:
  The Corner with track.

Definition at line 347 of file slope_func.h.

References FOUNDATION_RAIL_W, and IsSpecialRailFoundation().

Referenced by ApplyFoundationToSlope(), and DrawFoundation().

static uint GetSlopeMaxZ | ( | Slope | s | ) | `[inline, static]`

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

Parameters:

  | s | The Slope.

Returns:
  Relative height of highest corner.

Definition at line 162 of file slope_func.h.

References IsSteepSlope(), SLOPE_FLAT, and TILE_HEIGHT.

Referenced by AutoslopeCheckForEntranceEdge(), and GetPartialZ().

static Foundation HalftileFoundation | ( | Corner | corner | ) | `[inline, static]`

Returns the halftile foundation for single horizontal/vertical track.

Parameters:

  | corner | The Corner with the track.

Returns:
  The wanted Foundation.

Definition at line 382 of file slope_func.h.

References FOUNDATION_HALFTILE_W, and IsValidCorner().

Referenced by DrawTrackBits(), and GetRailFoundation().

static Slope HalftileSlope | ( | Slope | s,
|  | Corner | corner |
| ) |  |  | `[inline, static]`

Adds a halftile slope to a slope.

Parameters:

  | s | Slope without a halftile slope.
  | corner | The Corner of the halftile.

Returns:
  The Slope s with the halftile slope added.

Definition at line 265 of file slope_func.h.

References IsValidCorner(), and SLOPE_HALFTILE.

Referenced by ApplyFoundationToSlope().

static bool HasSlopeHighestCorner | ( | Slope | s | ) | `[inline, static]`

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

one corner raised or a steep slope).

Note: A halftile slope is ignored.

Parameters:

  | s | The Slope.

Returns:
  true iff the slope has a highest corner.

Definition at line 115 of file slope_func.h.

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

static Foundation InclinedFoundation | ( | Axis | axis | ) | `[inline, static]`

Returns the along a specific axis inclined foundation.

Parameters:

  | axis | The Axis.

Returns:
  The needed Foundation.

Definition at line 371 of file slope_func.h.

References AXIS_X, FOUNDATION_INCLINED_X, and FOUNDATION_INCLINED_Y.

static Slope InclinedSlope | ( | DiagDirection | dir | ) | `[inline, static]`

Returns the slope, that is inclined in a specific direction.

Parameters:

  | dir | A DiagDirection

Returns:
  The Slope that goes up in direction dir.

Definition at line 247 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(), and GrowTownWithBridge().

static bool IsFoundation | ( | Foundation | f | ) | `[inline, static]`

Tests for FOUNDATION_NONE.

Parameters:

  | f | Maybe a Foundation.

Returns:
  true iff f is a foundation.

Definition at line 278 of file slope_func.h.

References FOUNDATION_NONE.

Referenced by ApplyFoundationToSlope(), and DrawFoundation().

static bool IsHalftileSlope | ( | Slope | s | ) | `[inline, static]`

Checks for non-continuous slope on halftile foundations.

Parameters:

  | s | The 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 ComplementSlope(), DrawAutorailSelection(), DrawCatenaryRailway(), DrawTileSelection(), DrawTileSelectionRect(), GetHalftileSlopeCorner(), GetPartialZ(), GetSlopeZInCorner(), GetSlopeZOnEdge(), and IsSlopeWithThreeCornersRaised().

static bool IsInclinedFoundation | ( | Foundation | f | ) | `[inline, static]`

Tests if the foundation is an inclined foundation.

Parameters:

  | f | The Foundation.

Returns:
  true iff f is an inclined foundation.

Definition at line 300 of file slope_func.h.

References FOUNDATION_INCLINED_X, and FOUNDATION_INCLINED_Y.

Referenced by DrawFoundation().

static bool IsInclinedSlope | ( | Slope | s | ) | `[inline, static]`

Tests if a specific slope is an inclined slope.

Parameters:

  | s | The Slope

Returns:
  true iff the slope is inclined.

Definition at line 219 of file slope_func.h.

References SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

Referenced by CmdBuildCanal().

static bool IsLeveledFoundation | ( | Foundation | f | ) | `[inline, static]`

Tests if the foundation is a leveled foundation.

Parameters:

  | f | The Foundation.

Returns:
  true iff f is a leveled foundation.

Definition at line 289 of file slope_func.h.

References FOUNDATION_LEVELED.

Referenced by ApplyFoundationToSlope(), and DrawFoundation().

static bool IsNonContinuousFoundation | ( | Foundation | f | ) | `[inline, static]`

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

halftile-foundation or FOUNDATION_STEEP_BOTH.

Parameters:

  | f | The Foundation.

Returns:
  true iff f is a non-continuous foundation

Definition at line 311 of file slope_func.h.

References FOUNDATION_HALFTILE_N, FOUNDATION_STEEP_BOTH, and IsInsideMM().

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

static bool IsSlopeWithOneCornerRaised | ( | Slope | s | ) | `[inline, static]`

Tests if a specific slope has exactly one corner raised.

Parameters:

  | s | The 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(), CheckRoadSlope(), CmdBuildSingleRail(), CmdPlantTree(), CmdRemoveSingleRail(), DoFloodTile(), FloodHalftile(), GetFloodingBehaviour(), GetRailFoundation(), GetRoadFoundation(), HasSlopeHighestCorner(), IsSlopeWithThreeCornersRaised(), and TestAutoslopeOnRailTile().

static bool IsSlopeWithThreeCornersRaised | ( | Slope | s | ) | `[inline, static]`

Tests if a specific slope has exactly three corners raised.

Parameters:

  | s | The Slope

Returns:
  true iff exactly three corners are raised

Definition at line 186 of file slope_func.h.

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

Referenced by FloodHalftile(), and GetRailFoundation().

static bool IsSpecialRailFoundation | ( | Foundation | f | ) | `[inline, static]`

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

Parameters:

  | f | The Foundation.

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

Definition at line 336 of file slope_func.h.

References FOUNDATION_RAIL_N, FOUNDATION_RAIL_W, and IsInsideMM().

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

static bool IsSteepSlope | ( | Slope | s | ) | `[inline, static]`

Checks if a slope is steep.

Parameters:

  | s | The 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(), AutoslopeCheckForEntranceEdge(), CanBuildHouseHere(), CheckFlatLandBelow(), CheckRailSlope(), CheckRoadSlope(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildTrainDepot(), ComplementSlope(), DrawCatenaryRailway(), DrawFoundation(), DrawTileSelection(), DrawTileSelectionRect(), DrawTrackBits(), FloodHalftile(), GetRailFoundation(), GetRoadFoundation(), GetSlopeMaxZ(), HasSlopeHighestCorner(), IsSlopeWithThreeCornersRaised(), IsValidTileForWaypoint(), LookupWithBuildOnSlopes(), and RemoveRoad().

static bool IsValidCorner | ( | Corner | corner | ) | `[inline, static]`

Rangecheck for Corner enumeration.

Parameters:

  | corner | A Corner.

Returns:
  true iff corner is in a valid range.

Definition at line 26 of file slope_func.h.

References IsInsideMM().

Referenced by CornerToTrackBits(), DrawTrackBits(), AITile::GetCornerHeight(), HalftileFoundation(), HalftileSlope(), SlopeWithOneCornerRaised(), and SpecialRailFoundation().

static Corner OppositeCorner | ( | Corner | corner | ) | `[inline, static]`

Returns the opposite corner.

Parameters:

  | corner | A Corner.

Returns:
  The opposite corner to "corner".

Definition at line 175 of file slope_func.h.

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

static Slope RemoveHalftileSlope | ( | Slope | s | ) | `[inline, static]`

Removes a halftile slope from a slope.

Non-halftile slopes remain unmodified.

Parameters:

  | s | A Slope.

Returns:
  The slope s without it's halftile slope.

Definition at line 62 of file slope_func.h.

References SLOPE_HALFTILE_MASK.

Referenced by DrawAutorailSelection(), DrawTileSelection(), DrawTrackFence_NS_1(), DrawTrackFence_NS_2(), DrawTrackFence_WE_1(), DrawTrackFence_WE_2(), GetHighestSlopeCorner(), GetPartialZ(), GetSlopeZOnEdge(), HasSlopeHighestCorner(), IsUphillTrackdir(), and TestAutoslopeOnRailTile().

static Slope SlopeWithOneCornerRaised | ( | Corner | corner | ) | `[inline, static]`

Returns the slope with a specific corner raised.

Parameters:

  | corner | The Corner.

Returns:
  The Slope with corner "corner" raised.

Definition at line 101 of file slope_func.h.

References IsValidCorner().

Referenced by ApplyFoundationToSlope(), DrawFoundation(), DrawTileSelectionRect(), GetRailFoundation(), GetSlopeZInCorner(), GetSlopeZOnEdge(), and SlopeWithThreeCornersRaised().

static Slope SlopeWithThreeCornersRaised | ( | Corner | corner | ) | `[inline, static]`

Returns the slope with all except one corner raised.

Parameters:

  | corner | The Corner.

Returns:
  The Slope with all corners but "corner" raised.

Definition at line 197 of file slope_func.h.

References ComplementSlope(), and SlopeWithOneCornerRaised().

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

static Foundation SpecialRailFoundation | ( | Corner | corner | ) | `[inline, static]`

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

Parameters:

  | corner | The Corner with the track.

Returns:
  The wanted Foundation.

Definition at line 394 of file slope_func.h.

References FOUNDATION_RAIL_W, and IsValidCorner().

Referenced by GetRailFoundation().

static Slope SteepSlope | ( | Corner | corner | ) | `[inline, static]`

Returns a specific steep slope.

Parameters:

  | corner | A Corner.

Returns:
  The steep Slope with "corner" as highest corner.

Definition at line 208 of file slope_func.h.

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

Referenced by GetSlopeZInCorner().