OpenTTD: src/landscape.h File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Data Structures | Functions | Variables
landscape.h File Reference

Functions related to OTTD's landscape. More...

`#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.
void | SetSnowLine (byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
| Set a variable snow line, as loaded from a newgrf file.
byte | GetSnowLine ()
| Get the current snow line, either variable or static.
byte | HighestSnowLine ()
| Get the highest possible snow line height, either variable or static.
byte | LowestSnowLine ()
| Get the lowest possible snow line height, either variable or static.
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.
Slope | GetFoundationSlope (TileIndex tile, int *z=NULL)
| 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.
uint | GetPartialPixelZ (int x, int y, Slope corners)
| Determines height at given coordinate of a slope.
int | GetSlopePixelZ (int x, int y)
void | GetSlopePixelZOnEdge (Slope tileh, DiagDirection edge, int *z1, int *z2)
| Determine the Z height of the corners of a specific tile edge.
static int | GetSlopePixelZInCorner (Slope tileh, Corner corner)
| Determine the Z height of a corner relative to TileZ.
static 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.
static 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.
static Point | RemapCoords2 (int x, int y)
| Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
static Point | InverseRemapCoords (int x, int y)
| Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
uint | ApplyFoundationToSlope (Foundation f, Slope *s)
| Applies a foundation to a slope.
static uint | ApplyPixelFoundationToSlope (Foundation f, Slope *s)
| Applies a foundation to a slope.
void | DrawFoundation (TileInfo *ti, Foundation f)
| Draw foundation f at tile ti.
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 ()
void | 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

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 98 of file landscape.cpp.

References FOUNDATION_INCLINED_X, FOUNDATION_INCLINED_Y, FOUNDATION_STEEP_BOTH, FOUNDATION_STEEP_LOWER, GetHalftileFoundationCorner(), GetHighestSlopeCorner(), GetRailFoundationCorner(), HalftileSlope(), IsFoundation(), IsLeveledFoundation(), IsNonContinuousFoundation(), IsSpecialRailFoundation(), IsSteepSlope(), OppositeCorner(), SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, SLOPE_SW, SlopeWithOneCornerRaised(), and SlopeWithThreeCornersRaised().

Referenced by ApplyPixelFoundationToSlope(), CheckBridgeSlopeNorth(), CheckBridgeSlopeSouth(), DrawCatenaryRailway(), FloodHalftile(), GetBridgeHeight(), GetFoundationSlope(), HasBridgeFlatRamp(), and TestAutoslopeOnRailTile().

static uint ApplyPixelFoundationToSlope | ( | Foundation | f,
|  | Slope * | s
| ) |  |
| inlinestatic

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 127 of file landscape.h.

References ApplyFoundationToSlope(), and TILE_HEIGHT.

Referenced by 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 389 of file landscape.cpp.

References AddSortableSpriteToDraw(), ApplyPixelFoundationToSlope(), FOUNDATION_INCLINED_X, FOUNDATION_INCLINED_Y, FOUNDATION_STEEP_BOTH, FOUNDATION_STEEP_LOWER, GetFoundationPixelSlope(), GetHalftileFoundationCorner(), GetHighestSlopeCorner(), GetRailFoundationCorner(), IsFoundation(), IsInclinedFoundation(), IsLeveledFoundation(), IsNonContinuousFoundation(), IsSpecialRailFoundation(), IsSteepSlope(), OffsetGroundSprite(), SLOPE_EW, SLOPE_NE, SLOPE_NS, SLOPE_STEEP, SLOPE_SW, SlopeWithOneCornerRaised(), SlopeWithThreeCornersRaised(), SPR_HALFTILE_FOUNDATION_BASE, TileInfo::tile, TILE_HEIGHT, TileInfo::tileh, TileInfo::x, TileInfo::y, and TileInfo::z.

Referenced by DrawRoadBits(), DrawTile_Road(), DrawTile_Town(), DrawTile_TunnelBridge(), and DrawTrackBits().

void 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 1210 of file landscape.cpp.

References _settings_game, Clamp(), GameSettings::construction, CreateRivers(), CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY, GameSettings::difficulty, FixSlopes(), ConstructionSettings::freeform_edges, GameSettings::game_creation, GB(), GenerateTerrainPerlin(), GWM_HEIGHTMAP, GWP_LANDSCAPE, IncreaseGeneratingWorldProgress(), GameCreationSettings::land_generator, GameCreationSettings::landscape, LG_TERRAGENESIS, LoadHeightmap(), MakeVoid(), MapSizeX(), MapSizeY(), SmallFiosItem::name, DifficultySettings::quantity_sea_lakes, ScaleByMapSize(), SetGeneratingWorldProgress(), DifficultySettings::terrain_type, and TileXY().

Referenced by _GenerateWorld().

static Slope GetFoundationPixelSlope | ( | TileIndex | tile,
|  | int * | z
| ) |  |
| inlinestatic

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 NULL, if not needed)

Returns
  The slope on top of the foundation.

Definition at line 67 of file landscape.h.

References GetFoundationSlope(), and TILE_HEIGHT.

Referenced by DrawFoundation().

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 NULL, if not needed)

Returns
  The slope on top of the foundation.

Definition at line 341 of file landscape.cpp.

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

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

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

Determines height at given coordinate of a slope.

Parameters

  x | x coordinate
  y | y coordinate
  corners | slope to examine

Returns
  height of given point of given slope

Definition at line 151 of file landscape.cpp.

References GetHalftileSlopeCorner(), GetSlopeMaxPixelZ(), IsHalftileSlope(), RemoveHalftileSlope(), SLOPE_E, SLOPE_ELEVATED, SLOPE_ENW, SLOPE_EW, SLOPE_N, SLOPE_NE, SLOPE_NS, SLOPE_NW, SLOPE_NWS, SLOPE_S, SLOPE_SE, SLOPE_SEN, SLOPE_STEEP_E, SLOPE_STEEP_N, SLOPE_STEEP_S, SLOPE_STEEP_W, SLOPE_SW, SLOPE_W, and SLOPE_WSE.

Referenced by DrawRoadBits().

static int GetSlopePixelZInCorner | ( | Slope | tileh,
|  | Corner | corner
| ) |  |
| inlinestatic

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 54 of file landscape.h.

References GetSlopeZInCorner(), and TILE_HEIGHT.

Referenced by DrawTrackFence_NS_1(), DrawTrackFence_NS_2(), DrawTrackFence_WE_1(), and DrawTrackFence_WE_2().

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 312 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.

Referenced by DrawBridgePillars().

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 294 of file landscape.cpp.

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

Referenced by GetSlopePixelZInCorner(), and TestAutoslopeOnRailTile().

static Point InverseRemapCoords | ( | int | x,
|  | int | y
| ) |  |
| inlinestatic

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.

Definition at line 112 of file landscape.h.

Referenced by SmallMapWindow::GetSmallMapCoordIncludingHeight(), GetTileCoordFromScreenCoord(), and SmallMapWindow::SetNewScroll().

static Point RemapCoords | ( | int | x,
|  | int | y,
|  | int | z
| ) |  |
| inlinestatic

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 83 of file landscape.h.

Referenced by AddCombinedSprite(), AddSortableSpriteToDraw(), AddTileSpriteToDraw(), CcStartStopVehicle(), DrawCommonTileSeqInGUI(), DrawGroundSpriteAt(), MarkTileDirtyByTile(), MarkTileDirtyByTileOutsideMap(), SmallMapWindow::OnClick(), RemapCoords2(), SetSelectionTilesDirty(), SetupScreenshotViewport(), ShowCostOrIncomeAnimation(), ShowFeederIncomeAnimation(), ShowFillingPercent(), Vehicle::UpdateViewport(), Sign::UpdateVirtCoord(), and ViewportDrawBoundingBoxes().

static Point RemapCoords2 | ( | int | x,
|  | int | y
| ) |  |
| inlinestatic

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 99 of file landscape.h.

References RemapCoords().

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