OpenTTD Source: src/landscape.h File Reference

OpenTTD Source 14.1

Data Structures | Functions | Variables
landscape.h File Reference
`#include "core/geometry_type.hpp"`
`#include "tile_cmd.h"`

Go to the source code of this file.

## Data Structures
struct | SnowLine
| Structure describing the height of the snow line each day of the year. More...

## Functions
bool | IsSnowLineSet ()
| Has a snow line table already been loaded. More...
void | SetSnowLine (byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
| Set a variable snow line, as loaded from a newgrf file. More...
byte | GetSnowLine ()
| Get the current snow line, either variable or static. More...
byte | HighestSnowLine ()
| Get the highest possible snow line height, either variable or static. More...
byte | LowestSnowLine ()
| Get the lowest possible snow line height, either variable or static. More...
void | ClearSnowLine ()
| Clear the variable snow line table and free the memory.
int | GetSlopeZInCorner (Slope tileh, Corner corner)
| Determine the Z height of a corner relative to TileZ. More...
Slope | GetFoundationSlope (TileIndex tile, int *z=nullptr)
| Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation, the function returns the same as GetTileSlope. More...
uint | GetPartialPixelZ (int x, int y, Slope corners)
| Determines height at given coordinate of a slope. More...
int | GetSlopePixelZ (int x, int y, bool ground_vehicle=false)
| Return world `Z` coordinate of a given point of a tile. More...
int | GetSlopePixelZOutsideMap (int x, int y)
| Return world `z` coordinate of a given point of a tile, also for tiles outside the map (virtual "black" tiles). More...
void | GetSlopePixelZOnEdge (Slope tileh, DiagDirection edge, int *z1, int *z2)
| Determine the Z height of the corners of a specific tile edge. More...
int | GetSlopePixelZInCorner (Slope tileh, Corner corner)
| Determine the Z height of a corner relative to TileZ. More...
Slope | GetFoundationPixelSlope (TileIndex tile, int *z)
| Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation, the function returns the same as GetTilePixelSlope. More...
Point | RemapCoords (int x, int y, int z)
| Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap. More...
Point | RemapCoords2 (int x, int y)
| Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap. More...
Point | InverseRemapCoords (int x, int y)
| Map 2D viewport or smallmap coordinate to 3D world or tile coordinate. More...
Point | InverseRemapCoords2 (int x, int y, bool clamp_to_map=false, bool *clamped=nullptr)
| Map 2D viewport or smallmap coordinate to 3D world or tile coordinate. More...
uint | ApplyFoundationToSlope (Foundation f, Slope *s)
| Applies a foundation to a slope. More...
uint | ApplyPixelFoundationToSlope (Foundation f, Slope *s)
| Applies a foundation to a slope. More...
void | DrawFoundation (TileInfo *ti, Foundation f)
| Draw foundation f at tile ti. More...
bool | HasFoundationNW (TileIndex tile, Slope slope_here, uint z_here)
bool | HasFoundationNE (TileIndex tile, Slope slope_here, uint z_here)
void | DoClearSquare (TileIndex tile)
void | RunTileLoop ()
| Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
void | InitializeLandscape ()
bool | GenerateLandscape (byte mode)

## Variables
static const uint | SNOW_LINE_MONTHS = 12
| Number of months in the snow line table.
static const uint | SNOW_LINE_DAYS = 32
| Number of days in each month in the snow line table.

## Detailed Description

Functions related to OTTD's landscape.

Definition in file landscape.h.

## Function Documentation

## ◆ ApplyFoundationToSlope()

uint ApplyFoundationToSlope | ( | Foundation | f,
|  | Slope * | s
| ) |  |

Applies a foundation to a slope.

Precondition
  Foundation and slope must be valid combined.

Parameters

  f | The Foundation.
  s | The Slope to modify.

Returns
  Increment to the tile Z coordinate.

Definition at line 166 of file landscape.cpp.

References FOUNDATION_INCLINED_X, FOUNDATION_STEEP_BOTH, GetHalftileFoundationCorner(), GetHighestSlopeCorner(), GetRailFoundationCorner(), HalftileSlope(), IsFoundation(), IsLeveledFoundation(), IsNonContinuousFoundation(), IsSpecialRailFoundation(), IsSteepSlope(), OppositeCorner(), SLOPE_FLAT, and SlopeWithThreeCornersRaised().

Referenced by ApplyPixelFoundationToSlope(), GetBridgeHeight(), GetFoundationSlope(), HasBridgeFlatRamp(), and TestAutoslopeOnRailTile().

## ◆ ApplyPixelFoundationToSlope()

uint ApplyPixelFoundationToSlope | ( | Foundation | f,
|  | Slope * | s
| ) |  |
| inline

Applies a foundation to a slope.

Precondition
  Foundation and slope must be valid combined.

Parameters

  f | The Foundation.
  s | The Slope to modify.

Returns
  Increment to the tile Z coordinate.

Definition at line 129 of file landscape.h.

References ApplyFoundationToSlope(), and TILE_HEIGHT.

## ◆ DrawFoundation()

void DrawFoundation | ( | TileInfo * | ti,
|  | Foundation | f
| ) |  |

Draw foundation f at tile ti.

Updates ti.

Parameters

  ti | Tile to draw foundation on
  f | Foundation to draw

Definition at line 427 of file landscape.cpp.

References FOUNDATION_STEEP_BOTH, GetFoundationPixelSlope(), IsFoundation(), and TileInfo::tile.

Referenced by DrawTile_Road().

## ◆ GenerateLandscape()

bool GenerateLandscape | ( | byte | mode | ) |

Number of steps of landscape generation

< Loading a heightmap

< Terragenesis generator

< Original generator

< Extra steps needed for tropic landscape

< Extra steps for other landscapes

Definition at line 1562 of file landscape.cpp.

References _settings_game, GameSettings::game_creation, and GameCreationSettings::landscape.

## ◆ GetFoundationPixelSlope()

Slope GetFoundationPixelSlope | ( | TileIndex | tile,
|  | int * | z
| ) |  |
| inline

Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation, the function returns the same as GetTilePixelSlope.

Parameters

  tile | The tile of interest.
  z | returns the z of the foundation slope. (Can be nullptr, if not needed)

Returns
  The slope on top of the foundation.

Definition at line 66 of file landscape.h.

References GetFoundationSlope(), and TILE_HEIGHT.

Referenced by DrawFoundation().

## ◆ GetFoundationSlope()

Slope GetFoundationSlope | ( | TileIndex | tile,
|  | int * | z
| ) |  |

Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation, the function returns the same as GetTileSlope.

Parameters

  tile | The tile of interest.
  z | returns the z of the foundation slope. (Can be nullptr, if not needed)

Returns
  The slope on top of the foundation.

Definition at line 379 of file landscape.cpp.

References _tile_type_procs, ApplyFoundationToSlope(), GetTileSlope(), and GetTileType().

Referenced by GetFoundationPixelSlope(), IsPossibleCrossing(), IsRoadAllowedHere(), and TileLoop_Water().

## ◆ GetPartialPixelZ()

uint GetPartialPixelZ | ( | int | x,
|  | int | y,
|  | Slope | corners
| ) |  |

Determines height at given coordinate of a slope.

At the northern corner (0, 0) the result is always a multiple of TILE_HEIGHT. When the height is a fractional Z, then the height is rounded down. For example, when at the height is 0 at x = 0 and the height is 8 at x = 16 (actually x = 0 of the next tile), then height is 0 at x = 1, 1 at x = 2, and 7 at x = 15.

Parameters

  x | x coordinate (value from 0 to 15)
  y | y coordinate (value from 0 to 15)
  corners | slope to examine

Returns
  height of given point of given slope

Definition at line 224 of file landscape.cpp.

Referenced by CheckPartialPixelZ().

## ◆ GetSlopePixelZ()

int GetSlopePixelZ | ( | int | x,
|  | int | y,
|  | bool | ground_vehicle
| ) |  |

Return world `Z` coordinate of a given point of a tile.

Normally this is the Z of the ground/foundation at the given location, but in some cases the ground/foundation can differ from the Z coordinate that the (ground) vehicle passing over it would take. For example when entering a tunnel or bridge.

Parameters

  x | World X coordinate in tile "units".
  y | World Y coordinate in tile "units".
  ground_vehicle | Whether to get the Z coordinate of the ground vehicle, or the ground.

Returns
  World Z coordinate at tile ground (vehicle) level, including slopes and foundations.

Definition at line 299 of file landscape.cpp.

Referenced by CheckGroundVehiclesAtCorrectZ(), GetPCPElevation(), HandleCrashedAircraft(), GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPosition(), and GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPositionAndInclination().

## ◆ GetSlopePixelZInCorner()

int GetSlopePixelZInCorner | ( | Slope | tileh,
|  | Corner | corner
| ) |  |
| inline

Determine the Z height of a corner relative to TileZ.

Precondition
  The slope must not be a halftile slope.

Parameters

  tileh | The slope.
  corner | The corner.

Returns
  Z position of corner relative to TileZ.

Definition at line 53 of file landscape.h.

References GetSlopeZInCorner(), and TILE_HEIGHT.

## ◆ GetSlopePixelZOnEdge()

void GetSlopePixelZOnEdge | ( | Slope | tileh,
|  | DiagDirection | edge,
|  | int * | z1,
|  | int * | z2
| ) |  |

Determine the Z height of the corners of a specific tile edge.

Note
  If a tile has a non-continuous halftile foundation, a corner can have different heights wrt. its edges.

Precondition
  z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added.

Parameters

  tileh | The slope of the tile.
  edge | The edge of interest.
  z1 | Gets incremented by the height of the first corner of the edge. (near corner wrt. the camera)
  z2 | Gets incremented by the height of the second corner of the edge. (far corner wrt. the camera)

Definition at line 350 of file landscape.cpp.

References GetHalftileSlopeCorner(), IsHalftileSlope(), RemoveHalftileSlope(), SLOPE_E, SLOPE_N, SLOPE_S, SLOPE_STEEP_E, SLOPE_STEEP_N, SLOPE_STEEP_S, SLOPE_STEEP_W, SLOPE_W, SlopeWithOneCornerRaised(), and TILE_HEIGHT.

## ◆ GetSlopePixelZOutsideMap()

int GetSlopePixelZOutsideMap | ( | int | x,
|  | int | y
| ) |  |

Return world `z` coordinate of a given point of a tile, also for tiles outside the map (virtual "black" tiles).

Parameters

  x | World X coordinate in tile "units", may be outside the map.
  y | World Y coordinate in tile "units", may be outside the map.

Returns
  World Z coordinate at tile ground level, including slopes and foundations.

Definition at line 314 of file landscape.cpp.

## ◆ GetSlopeZInCorner()

int GetSlopeZInCorner | ( | Slope | tileh,
|  | Corner | corner
| ) |  |

Determine the Z height of a corner relative to TileZ.

Precondition
  The slope must not be a halftile slope.

Parameters

  tileh | The slope.
  corner | The corner.

Returns
  Z position of corner relative to TileZ.

Definition at line 332 of file landscape.cpp.

References IsHalftileSlope(), SlopeWithOneCornerRaised(), and SteepSlope().

Referenced by GetSlopePixelZInCorner().

## ◆ InverseRemapCoords()

Point InverseRemapCoords | ( | int | x,
|  | int | y
| ) |  |
| inline

Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.

Function assumes `z == 0`. For other values of `z`, add `z` to y before the call.

Parameters

  x | X coordinate of the 2D coordinate.
  y | Y coordinate of the 2D coordinate.

Returns
  X and Y components of equivalent world or tile coordinate.

Note
  Inverse of RemapCoords function. Smaller values may get rounded.

See also
  InverseRemapCoords2

Definition at line 112 of file landscape.h.

Referenced by SmallMapWindow::SetNewScroll().

## ◆ InverseRemapCoords2()

Point InverseRemapCoords2 | ( | int | x,
|  | int | y,
|  | bool | clamp_to_map,
|  | bool * | clamped
| ) |  |

Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.

Function takes into account height of tiles and foundations.

Parameters

  | x | X viewport 2D coordinate.
  | y | Y viewport 2D coordinate.
  | clamp_to_map | Clamp the coordinate outside of the map to the closest, non-void tile within the map.
  [out] | clamped | Whether coordinates were clamped.

Returns
  3D world coordinate of point visible at the given screen coordinate (3D perspective).

Note
  Inverse of RemapCoords2 function. Smaller values may get rounded.

See also
  InverseRemapCoords

Definition at line 107 of file landscape.cpp.

Referenced by ClampViewportToMap(), SmallMapWindow::DrawMapIndicators(), and SmallMapWindow::SmallMapCenterOnCurrentPos().

## ◆ RemapCoords()

Point RemapCoords | ( | int | x,
|  | int | y,
|  | int | z
| ) |  |
| inline

Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.

Parameters

  x | X world or tile coordinate (runs in SW direction in the 2D view).
  y | Y world or tile coordinate (runs in SE direction in the 2D view).
  z | Z world or tile coordinate (runs in N direction in the 2D view).

Returns
  Equivalent coordinate in the 2D view.

See also
  RemapCoords2

Definition at line 82 of file landscape.h.

Referenced by MarkTileDirtyByTile(), IntroGameViewportCommand::PositionForViewport(), SelectGameWindow::ReadIntroGameViewportCommands(), Vehicle::UpdateBoundingBoxCoordinates(), Sign::UpdateVirtCoord(), and ViewportDrawBoundingBoxes().

## ◆ RemapCoords2()

Point RemapCoords2 | ( | int | x,
|  | int | y
| ) |  |
| inline

Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.

Same as RemapCoords, except the Z coordinate is read from the map.

Parameters

  x | X world or tile coordinate (runs in SW direction in the 2D view).
  y | Y world or tile coordinate (runs in SE direction in the 2D view).

Returns
  Equivalent coordinate in the 2D view.

See also
  RemapCoords

Definition at line 98 of file landscape.h.

Referenced by ClampViewportToMap(), Waypoint::UpdateVirtCoord(), Town::UpdateVirtCoord(), and Station::UpdateVirtCoord().