OpenTTD
Macros | 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 "saveload/saveload.h"
#include <list>
#include <set>
#include "table/strings.h"
#include "table/sprites.h"
#include "safeguards.h"
#include "table/genland.h"

Go to the source code of this file.

Macros

#define SET_MARK(x)   marks.insert(x)
 
#define IS_MARKED(x)   (marks.find(x) != marks.end())
 

Functions

uint ApplyFoundationToSlope (Foundation f, Slope *s)
 Applies a foundation to a slope. More...
 
uint GetPartialPixelZ (int x, int y, Slope corners)
 Determines height at given coordinate of a slope. More...
 
int GetSlopePixelZ (int x, int y)
 
int GetSlopeZInCorner (Slope tileh, Corner corner)
 Determine the Z height of a corner relative to TileZ. More...
 
void GetSlopePixelZOnEdge (Slope tileh, DiagDirection edge, int *z1, int *z2)
 Determine the Z height of the corners of a specific tile edge. More...
 
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. More...
 
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. More...
 
void DoClearSquare (TileIndex tile)
 
TrackStatus GetTileTrackStatus (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 Returns information about trackdirs and signal states. More...
 
void ChangeTileOwner (TileIndex tile, Owner old_owner, Owner new_owner)
 Change the owner of a tile. More...
 
void GetTileDesc (TileIndex tile, TileDesc *td)
 
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.
 
CommandCost CmdLandscapeClear (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Clear a piece of landscape. More...
 
CommandCost CmdClearArea (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Clear a big piece of landscape. More...
 
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. More...
 
static bool MakeLake (TileIndex tile, void *user_data)
 Make a connected lake; fill all tiles in the circular tile search that are connected. More...
 
static bool FlowsDown (TileIndex begin, TileIndex end)
 Check whether a river at begin could (logically) flow down to end. More...
 
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. More...
 
static void BuildRiver (TileIndex begin, TileIndex end)
 Actually build the river between the begin and end tiles using AyStar. More...
 
static bool FlowRiver (TileIndex spring, TileIndex begin)
 Try to flow the river down from a given begin. More...
 
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. More...
 
void OnTick_LinkGraph ()
 Spawn or join a link graph job or compress a link graph 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. More...
 
const byte _slope_to_sprite_offset [32]
 landscape slope => sprite More...
 
static SnowLine_snow_line = NULL
 Description of the snow line throughout the year. More...
 
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

◆ ApplyFoundationToSlope()

uint ApplyFoundationToSlope ( Foundation  f,
Slope s 
)

◆ BuildRiver()

static void BuildRiver ( TileIndex  begin,
TileIndex  end 
)
static

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

Parameters
beginThe begin of the river.
endThe end of the river.

Definition at line 1081 of file landscape.cpp.

References MemSetT().

◆ ChangeTileOwner()

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

Change the owner of a tile.

Parameters
tileTile to change
old_ownerCurrent owner of the tile
new_ownerNew owner of the tile

Definition at line 520 of file landscape.cpp.

References GetTileType().

◆ CmdClearArea()

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

Clear a big piece of landscape.

Parameters
tileend tile of area dragging
flagsof operation to conduct
p1start tile of area dragging
p2various bitstuffed data. bit 0: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
textunused
Returns
the cost of this operation or an error

Definition at line 662 of file landscape.cpp.

References _current_company, CMD_ERROR, DC_AUTO, DC_BANKRUPT, EXPENSES_CONSTRUCTION, GetAvailableMoneyForCommand(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), and MapSize().

◆ CmdLandscapeClear()

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

Clear a piece of landscape.

Parameters
tiletile to clear
flagsof operation to conduct
p1unused
p2unused
textunused
Returns
the cost of this operation or an error

Definition at line 612 of file landscape.cpp.

References CommandCost::AddCost(), DC_AUTO, DC_FORCE_CLEAR_TILE, EXPENSES_CONSTRUCTION, GetWaterClass(), HasTileWaterClass(), IsCoastTile(), IsTileOnWater(), IsWaterTile(), return_cmd_error, and WATER_CLASS_CANAL.

◆ DrawFoundation()

void DrawFoundation ( TileInfo ti,
Foundation  f 
)

Draw foundation f at tile ti.

Updates ti.

Parameters
tiTile to draw foundation on
fFoundation to draw

Definition at line 390 of file landscape.cpp.

References IsFoundation().

Referenced by ApplyPixelFoundationToSlope(), and DrawTile_Road().

◆ FindSpring()

static bool FindSpring ( TileIndex  tile,
void *  user_data 
)
static

Find the spring of a river.

Parameters
tileThe tile to consider for being the spring.
user_dataIgnored data.
Returns
True iff it is suitable as a spring.

Definition at line 941 of file landscape.cpp.

References _settings_game, GameSettings::game_creation, IsTileFlat(), IsWaterTile(), and GameCreationSettings::landscape.

Referenced by CreateRivers().

◆ FlowRiver()

static bool FlowRiver ( TileIndex  spring,
TileIndex  begin 
)
static

Try to flow the river down from a given begin.

Parameters
springThe springing point of the river.
beginThe 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 1108 of file landscape.cpp.

Referenced by CreateRivers().

◆ FlowsDown()

static bool FlowsDown ( TileIndex  begin,
TileIndex  end 
)
static

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

Parameters
beginThe origin of the flow.
endThe destination of the flow.
Returns
True iff the water can be flowing down.

Definition at line 1000 of file landscape.cpp.

◆ GenerateLandscape()

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

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

◆ 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
tileThe tile of interest.
zreturns the z of the foundation slope. (Can be NULL, if not needed)
Returns
The slope on top of the foundation.

Definition at line 342 of file landscape.cpp.

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

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

◆ GetPartialPixelZ()

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

Determines height at given coordinate of a slope.

Parameters
xx coordinate
yy coordinate
cornersslope to examine
Returns
height of given point of given slope

Definition at line 152 of file landscape.cpp.

◆ 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
tilehThe slope of the tile.
edgeThe edge of interest.
z1Gets incremented by the height of the first corner of the edge. (near corner wrt. the camera)
z2Gets incremented by the height of the second corner of the edge. (far corner wrt. the camera)

Definition at line 313 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.

◆ 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
tilehThe slope.
cornerThe corner.
Returns
Z position of corner relative to TileZ.

Definition at line 295 of file landscape.cpp.

Referenced by GetSlopePixelZInCorner().

◆ GetTileTrackStatus()

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
tiletile to get info about
modetransport type
sub_modefor TRANSPORT_ROAD, roadtypes to check
sideside we are entering from, INVALID_DIAGDIR to return all trackbits
Returns
trackdirbits and other info depending on 'mode'

Definition at line 509 of file landscape.cpp.

References TileTypeProcs::get_tile_track_status_proc, and GetTileType().

Referenced by CheckRoadBlockedForOvertaking(), CYapfFollowShipT< Types >::CheckShipReverse(), DisasterTick_Submarine(), GenericPlaceSignals(), GetDriveableTrackdirBits(), MaskWireBits(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::QueryNewTileTrackStatus(), RoadFindPathToDest(), CYapfFollowRoadT< Types >::SetOriginFromVehiclePos(), RoadVehicle::TileMayHaveSlopedTrack(), TrainCheckIfLineEnds(), and YapfRoadVehicleFindNearestDepot().

◆ MakeLake()

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
tileThe tile to consider for lake making.
user_dataThe height of the lake.
Returns
Always false, so it continues searching.

Definition at line 977 of file landscape.cpp.

◆ OnTick_Companies()

void OnTick_Companies ( )

Called every tick for updating some company info.

Definition at line 697 of file company_cmd.cpp.

◆ River_Hash()

static uint River_Hash ( uint  tile,
uint  dir 
)
static

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

Parameters
tileThe tile to hash.
dirThe unused direction.
Returns
The hash for the tile.

Definition at line 1071 of file landscape.cpp.

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

Variable Documentation

◆ _slope_to_sprite_offset

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

◆ _tile_type_procs

const TileTypeProcs* const _tile_type_procs[16]
Initial value:
= {
&_tile_type_clear_procs,
&_tile_type_rail_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,
}
const TileTypeProcs _tile_type_road_procs
Tile callback functions for road tiles.
const TileTypeProcs _tile_type_town_procs
Tile callback functions for a town.

Tile callback functions for each type of tile.

See also
TileType

Definition at line 61 of file landscape.cpp.