# landscape.cpp File Reference

Functions related to the landscape (slopes etc. More...

`#include "stdafx.h"`
`#include "heightmap.h"`
`#include "clear_map.h"`
`#include "spritecache.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "landscape.h"`
`#include "variables.h"`
`#include "void_map.h"`
`#include "tgp.h"`
`#include "genworld.h"`
`#include "fios.h"`
`#include "functions.h"`
`#include "date_func.h"`
`#include "water.h"`
`#include "effectvehicle_func.h"`
`#include "landscape_type.h"`
`#include "settings_type.h"`
`#include "table/sprites.h"`
`#include "table/genland.h"`

Go to the source code of this file.

## Defines
#define | TILELOOP_BITS 4
#define | TILELOOP_SIZE (1 << TILELOOP_BITS)
#define | TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
#define | TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS)
## Functions
uint | ApplyFoundationToSlope (Foundation f, Slope *s)
| Applies a foundation to a slope.
uint | GetPartialZ (int x, int y, Slope corners)
| Determines height at given coordinate of a slope.
uint | GetSlopeZ (int x, int y)
int | GetSlopeZInCorner (Slope tileh, Corner corner)
| Determine the Z height of a corner relative to TileZ.
void | GetSlopeZOnEdge (Slope tileh, DiagDirection edge, int *z1, int *z2)
| Determine the Z height of the corners of a specific tile edge.
Slope | GetFoundationSlope (TileIndex tile, uint *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.
static bool | HasFoundationNW (TileIndex tile, Slope slope_here, uint z_here)
static bool | HasFoundationNE (TileIndex tile, Slope slope_here, uint z_here)
void | DrawFoundation (TileInfo *ti, Foundation f)
| Draw foundation f at tile ti.
void | DoClearSquare (TileIndex tile)
TrackStatus | GetTileTrackStatus (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
| Returns information about trackdirs and signal states.
void | ChangeTileOwner (TileIndex tile, Owner old_owner, Owner new_owner)
| Change the owner of a tile.
void | GetAcceptedCargo (TileIndex tile, AcceptedCargo ac)
void | AnimateTile (TileIndex tile)
bool | ClickTile (TileIndex tile)
void | GetTileDesc (TileIndex tile, TileDesc *td)
bool | IsSnowLineSet (void)
| 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 (void)
| Get the current snow line, either variable or static.
byte | HighestSnowLine (void)
| Get the highest possible snow line height, either variable or static.
byte | LowestSnowLine (void)
| Get the lowest possible snow line height, either variable or static.
void | ClearSnowLine (void)
| Clear the variable snow line table and free the memory.
CommandCost | CmdLandscapeClear (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Clear a piece of landscape.
CommandCost | CmdClearArea (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Clear a big piece of landscape.
void | RunTileLoop ()
void | InitializeLandscape ()
static void | GenerateTerrain (int type, uint flag)
static void | CreateDesertOrRainForest ()
void | GenerateLandscape (byte mode)
void | OnTick_Town ()
void | OnTick_Trees ()
void | OnTick_Station ()
void | OnTick_Industry ()
void | OnTick_Companies ()
void | OnTick_Train ()
void | CallLandscapeTick ()
## Variables
const TileTypeProcs | _tile_type_clear_procs
const TileTypeProcs | _tile_type_rail_procs
const TileTypeProcs | _tile_type_road_procs
const TileTypeProcs | _tile_type_town_procs
const TileTypeProcs | _tile_type_trees_procs
const TileTypeProcs | _tile_type_station_procs
const TileTypeProcs | _tile_type_water_procs
const TileTypeProcs | _tile_type_dummy_procs
const TileTypeProcs | _tile_type_industry_procs
const TileTypeProcs | _tile_type_tunnelbridge_procs
const TileTypeProcs | _tile_type_unmovable_procs
const TileTypeProcs *const | _tile_type_procs [16]
| Tile callback functions for each type of tile.
const byte | _tileh_to_sprite [32]
SnowLine * | _snow_line = NULL
| Description of the snow line throughout the year.
TileIndex | _cur_tileloop_tile
static const byte | _genterrain_tbl_1 [5] = { 10, 22, 33, 37, 4 }
static const byte | _genterrain_tbl_2 [5] = { 0, 0, 0, 0, 33 }

## Detailed Description

Functions related to the landscape (slopes etc.

).

Definition in file landscape.cpp.

## 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 81 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(), SlopeWithThreeCornersRaised(), and TILE_HEIGHT.

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

void ChangeTileOwner | ( | TileIndex | tile,
|  | Owner | old_owner,
|  | Owner | new_owner |
| ) |  |  |

Change the owner of a tile.

Parameters:

  | tile | Tile to change
  | old_owner | Current owner of the tile
  | new_owner | New owner of the tile

Definition at line 498 of file landscape.cpp.

References TileTypeProcs::change_tile_owner_proc, and GetTileType().

CommandCost CmdClearArea | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Clear a big piece of landscape.

Parameters:

  | tile | end tile of area dragging
  | p1 | start tile of area dragging
  | flags | of operation to conduct
  | p2 | unused

Definition at line 614 of file landscape.cpp.

References CommandCost::AddCost(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, CmdFailed(), DC_EXEC, DoCommand(), GetAvailableMoneyForCommand(), CommandCost::GetCost(), MapSize(), Swap(), TILE_SIZE, TileX(), TileXY(), and TileY().

CommandCost CmdLandscapeClear | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Clear a piece of landscape.

Parameters:

  | tile | tile to clear
  | flags | of operation to conduct
  | p1 | unused
  | p2 | unused

Definition at line 603 of file landscape.cpp.

References TileTypeProcs::clear_tile_proc, and GetTileType().

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

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

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

Slope GetFoundationSlope | ( | TileIndex | tile,
|  | uint * | 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 324 of file landscape.cpp.

References ApplyFoundationToSlope(), TileTypeProcs::get_foundation_proc, GetTileSlope(), and GetTileType().

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

uint GetPartialZ | ( | 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 134 of file landscape.cpp.

References GetHalftileSlopeCorner(), GetSlopeMaxZ(), 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.

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

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

Referenced by DrawTrackFence_NS_1(), DrawTrackFence_NS_2(), DrawTrackFence_WE_1(), DrawTrackFence_WE_2(), AITile::GetCornerHeight(), and TestAutoslopeOnRailTile().

void GetSlopeZOnEdge | ( | 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. it's 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 295 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().

TrackStatus GetTileTrackStatus | ( | TileIndex | tile,
|  | TransportType | mode,
|  | uint | sub_mode,
|  | DiagDirection | side |
| ) |  |  |

Returns information about trackdirs and signal states.

If there is any trackbit at 'side', return all trackdirbits. For TRANSPORT_ROAD, return no trackbits if there is no roadbit (of given subtype) at given side.

Parameters:

  | tile | tile to get info about
  | mode | transport type
  | sub_mode | for TRANSPORT_ROAD, roadtypes to check
  | side | side we are entering from, INVALID_DIAGDIR to return all trackbits

Returns:
  trackdirbits and other info depending on 'mode'

Definition at line 487 of file landscape.cpp.

References TileTypeProcs::get_tile_track_status_proc, and GetTileType().

Referenced by AIMarine::AreWaterTilesConnected(), CheckRoadBlockedForOvertaking(), DisasterTick_Submarine(), FixOwnerOfRailTrack(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GenericPlaceSignals(), GetAnyRoadTrackBits(), GetDriveableTrackdirBits(), AITile::HasTransportType(), MaskWireBits(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::QueryNewTileTrackStatus(), RoadFindPathToDest(), TrainCheckIfLineEnds(), TryPathReserve(), TryReserveRailTrack(), UnreserveRailTrack(), UpdateSignalsInBuffer(), and YapfFindNearestRoadDepot().

## Variable Documentation

const TileTypeProcs* const _tile_type_procs[16]

Initial value:

     {
      &_tile_type_clear_procs,
      &_tile_type_rail_procs,
      &_tile_type_road_procs,
      &_tile_type_town_procs,
      &_tile_type_trees_procs,
      &_tile_type_station_procs,
      &_tile_type_water_procs,
      &_tile_type_dummy_procs,
      &_tile_type_industry_procs,
      &_tile_type_tunnelbridge_procs,
      &_tile_type_unmovable_procs,
    }

Tile callback functions for each type of tile.

See also:
  TileType

Definition at line 44 of file landscape.cpp.

Referenced by CmdTerraformLand(), GetProductionAroundTiles(), and VehicleEnterTile().

const byte _tileh_to_sprite[32]

Initial value:

     {
      0, 1, 2, 3, 4, 5, 6,  7, 8, 9, 10, 11, 12, 13, 14, 0,
      0, 0, 0, 0, 0, 0, 0, 16, 0, 0,  0, 17,  0, 15, 18, 0,
    }

Definition at line 59 of file landscape.cpp.