Functions | Variables

# 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 "void_map.h"`
`#include "tgp.h"`
`#include "genworld.h"`
`#include "fios.h"`
`#include "date_func.h"`
`#include "water.h"`
`#include "effectvehicle_func.h"`
`#include "landscape_type.h"`
`#include "animated_tile_func.h"`
`#include "core/random_func.hpp"`
`#include "object_base.h"`
`#include "company_func.h"`
`#include "pathfinder/npf/aystar.h"`
`#include <list>`
`#include "table/strings.h"`
`#include "table/sprites.h"`
`#include "table/genland.h"`

Go to the source code of this file.

## Functions
uint | ApplyFoundationToSlope (Foundation f, Slope *s)
| Applies a foundation to a slope.
uint | GetPartialPixelZ (int x, int y, Slope corners)
| Determines height at given coordinate of a slope.
int | GetSlopePixelZ (int x, int y)
int | GetSlopeZInCorner (Slope tileh, Corner corner)
| Determine the Z height of a corner relative to TileZ.
void | GetSlopePixelZOnEdge (Slope tileh, DiagDirection edge, int *z1, int *z2)
| Determine the Z height of the corners of a specific tile edge.
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 GetTilePixelSlope.
bool | HasFoundationNW (TileIndex tile, Slope slope_here, uint z_here)
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 | GetTileDesc (TileIndex tile, TileDesc *td)
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.
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 ()
| Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
void | InitializeLandscape ()
static void | GenerateTerrain (int type, uint flag)
static void | CreateDesertOrRainForest ()
static bool | FindSpring (TileIndex tile, void *user_data)
| Find the spring of a river.
static bool | MakeLake (TileIndex tile, void *user_data)
| Make a connected lake; fill all tiles in the circular tile search that are connected.
static bool | FlowsDown (TileIndex begin, TileIndex end)
| Check whether a river at begin could (logically) flow down to end.
static int32 | River_EndNodeCheck (AyStar *aystar, OpenListNode *current)
static int32 | River_CalculateG (AyStar *aystar, AyStarNode *current, OpenListNode *parent)
static int32 | River_CalculateH (AyStar *aystar, AyStarNode *current, OpenListNode *parent)
static void | River_GetNeighbours (AyStar *aystar, OpenListNode *current)
static void | River_FoundEndNode (AyStar *aystar, OpenListNode *current)
static uint | River_Hash (uint tile, uint dir)
| Simple hash function for river tiles to be used by AyStar.
static void | BuildRiver (TileIndex begin, TileIndex end)
| Actually build the river between the begin and end tiles using AyStar.
static bool | FlowRiver (bool *marks, TileIndex spring, TileIndex begin)
| Try to flow the river down from a given begin.
static void | CreateRivers ()
| Actually (try to) create some rivers.
void | GenerateLandscape (byte mode)
void | OnTick_Town ()
void | OnTick_Trees ()
void | OnTick_Station ()
void | OnTick_Industry ()
void | OnTick_Companies ()
| Called every tick for updating some company info.
void | OnTick_LinkGraph ()
| Spawn or join a link graph component if any link graph is due to do so.
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_void_procs
const TileTypeProcs | _tile_type_industry_procs
const TileTypeProcs | _tile_type_tunnelbridge_procs
const TileTypeProcs | _tile_type_object_procs
const TileTypeProcs *const | _tile_type_procs [16]
| Tile callback functions for each type of tile.
const byte | _slope_to_sprite_offset [32]
| landscape slope => sprite
static 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 }
static const uint | RIVER_HASH_SIZE = 8
| The number of bits the hash for river finding should have.

## 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 95 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_NE, SLOPE_NW, SLOPE_SE, SLOPE_SW, SlopeWithOneCornerRaised(), and SlopeWithThreeCornersRaised().

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

static void BuildRiver | ( | TileIndex | begin,
|  | TileIndex | end |
| ) |  |  | `[static]`

Actually build the river between the begin and end tiles using AyStar.

Parameters:

  | begin | The begin of the river.
  | end | The end of the river.

Definition at line 1078 of file landscape.cpp.

References AyStar::AddStartNode(), AyStar::Free(), AyStar::Init(), AyStar::Main(), MemSetT(), and River_Hash().

Referenced by FlowRiver().

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

References GetTileType().

Referenced by AfterLoadGame(), and ChangeOwnershipOfCompanyItems().

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
  | flags | of operation to conduct
  | p1 | start tile of area dragging
  | p2 | various bitstuffed data. bit 0: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
  | text | unused

Returns:
  the cost of this operation or an error

Definition at line 658 of file landscape.cpp.

References _current_company, _pause_mode, CommandCost::AddCost(), CompanyProperties::clear_limit, CMD_ERROR, CMD_LANDSCAPE_CLEAR, CreateEffectVehicleAbove(), DC_AUTO, DC_EXEC, DoCommand(), EV_EXPLOSION_LARGE, EV_EXPLOSION_SMALL, EXPENSES_CONSTRUCTION, CommandCost::Failed(), GB(), GetAvailableMoneyForCommand(), CommandCost::GetCost(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), TileArea::h, HasBit(), INVALID_TILE, MapSize(), PM_UNPAUSED, TileArea::tile, TILE_SIZE, TileX(), TileY(), and TileArea::w.

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
  | text | unused

Returns:
  the cost of this operation or an error

Definition at line 608 of file landscape.cpp.

References _current_company, CommandCost::AddCost(), CompanyProperties::clear_limit, DC_AUTO, DC_EXEC, DC_FORCE_CLEAR_TILE, DC_NO_WATER, EXPENSES_CONSTRUCTION, FindClearedObject(), ClearedObjectArea::first_tile, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetTileType(), GetWaterClass(), HasTileWaterClass(), IsCoastTile(), IsTileOnWater(), IsWaterTile(), return_cmd_error, and WATER_CLASS_CANAL.

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 386 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_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().

static bool FindSpring | ( | TileIndex | tile,
|  | void * | user_data |
| ) |  |  | `[static]`

Find the spring of a river.

Parameters:

  | tile | The tile to consider for being the spring.
  | user_data | Ignored data.

Returns:
  True iff it is suitable as a spring.

Definition at line 937 of file landscape.cpp.

References _settings_game, GameSettings::game_creation, GetTileMaxZ(), GetTileSlope(), GetTropicZone(), INVALID_TILE, IsWaterTile(), GameCreationSettings::landscape, SLOPE_FLAT, TileAddWrap(), and TROPICZONE_RAINFOREST.

Referenced by CreateRivers().

static bool FlowRiver | ( | bool * | marks,
|  | TileIndex | spring,
|  | TileIndex | begin |
| ) |  |  | `[static]`

Try to flow the river down from a given begin.

Parameters:

  | marks | Array for temporary of iterated tiles.
  | spring | The springing point of the river.
  | begin | The begin point we are looking from; somewhere down hill from the spring.

Returns:
  True iff a river could/has been built, otherwise false.

Definition at line 1106 of file landscape.cpp.

References _settings_game, BuildRiver(), CircularTileSearch(), DIAGDIR_BEGIN, DistanceManhattan(), FlowsDown(), GameSettings::game_creation, GetTileSlope(), GetTropicZone(), IsValidTile(), IsWaterTile(), GameCreationSettings::landscape, MakeLake(), MakeRiver(), MapSize(), MemSetT(), GameCreationSettings::min_river_length, SLOPE_FLAT, TileHeight(), TileOffsByDiagDir(), and TROPICZONE_DESERT.

Referenced by CreateRivers().

static bool FlowsDown | ( | TileIndex | begin,
|  | TileIndex | end |
| ) |  |  | `[static]`

Check whether a river at begin could (logically) flow down to end.

Parameters:

  | begin | The origin of the flow.
  | end | The destination of the flow.

Returns:
  True iff the water can be flowing down.

Definition at line 997 of file landscape.cpp.

References DistanceManhattan(), GetTileSlope(), IsInclinedSlope(), and SLOPE_FLAT.

Referenced by FlowRiver().

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

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

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 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 338 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 148 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().

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

References GetHalftileSlopeCorner(), IsHalftileSlope(), RemoveHalftileSlope(), SLOPE_STEEP_E, SLOPE_STEEP_N, SLOPE_STEEP_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 291 of file landscape.cpp.

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

Referenced by GetSlopePixelZInCorner(), and TestAutoslopeOnRailTile().

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

References TileTypeProcs::get_tile_track_status_proc, and GetTileType().

Referenced by AfterLoadGame(), CheckRoadBlockedForOvertaking(), DisasterTick_Submarine(), FixOwnerOfRailTrack(), GenericPlaceSignals(), GetDriveableTrackdirBits(), MaskWireBits(), OPFShipChooseTrack(), RoadFindPathToDest(), CYapfFollowRoadT< Types >::SetOriginFromVehiclePos(), RoadVehicle::TileMayHaveSlopedTrack(), TrainCheckIfLineEnds(), TrainController(), TryPathReserve(), TryReserveRailTrack(), UnreserveRailTrack(), UpdateSignalsInBuffer(), and YapfRoadVehicleFindNearestDepot().

static bool MakeLake | ( | TileIndex | tile,
|  | void * | user_data |
| ) |  |  | `[static]`

Make a connected lake; fill all tiles in the circular tile search that are connected.

Parameters:

  | tile | The tile to consider for lake making.
  | user_data | The height of the lake.

Returns:
  Always false, so it continues searching.

Definition at line 974 of file landscape.cpp.

References _settings_game, DIAGDIR_BEGIN, GameSettings::game_creation, GetTileSlope(), GetTropicZone(), IsValidTile(), IsWaterTile(), GameCreationSettings::landscape, MakeRiver(), TileHeight(), and TileOffsByDiagDir().

Referenced by FlowRiver().

void OnTick_Companies | ( |  | ) |

Called every tick for updating some company info.

Definition at line 690 of file company_cmd.cpp.

References _cur_company_tick_index, _next_competitor_start, CompanyProperties::bankrupt_asked, AI::CanStartNew(), DAY_TICKS, GenerateCompanyName(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), AI::GetStartNextTime(), HandleBankruptcyTakeover(), MAX_COMPANIES, MaybeStartNewCompany(), and CompanyProperties::name_1.

void OnTick_LinkGraph | ( |  | ) |

Spawn or join a link graph component if any link graph is due to do so.

Spawning is done on COMPONENTS_SPAWN_TICK every day, joining on COMPONENT_JOIN_TICK. Each link graph is due every recalc_interval days.

Definition at line 182 of file linkgraph.cpp.

References _date, _date_fract, _settings_game, LinkGraph::COMPONENTS_JOIN_TICK, LinkGraph::COMPONENTS_SPAWN_TICK, LinkGraph::Join(), GameSettings::linkgraph, LinkGraph::NextComponent(), NUM_CARGO, and LinkGraphSettings::recalc_interval.

static uint River_Hash | ( | uint | tile,
|  | uint | dir |
| ) |  |  | `[static]`

Simple hash function for river tiles to be used by AyStar.

Parameters:

  | tile | The tile to hash.
  | dir | The unused direction.

Returns:
  The hash for the tile.

Definition at line 1068 of file landscape.cpp.

References GB(), TileHash(), TileX(), and TileY().

Referenced by BuildRiver().

## Variable Documentation

const byte _slope_to_sprite_offset[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,
    }

landscape slope => sprite

Referenced by SlopeToSpriteOffset().

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_void_procs,
      &_tile_type_industry_procs,
      &_tile_type_tunnelbridge_procs,
      &_tile_type_object_procs,
    }

Tile callback functions for each type of tile.

See also:
  TileType

Definition at line 57 of file landscape.cpp.

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