OpenTTD Source 20241224-master-gf74b0cf984
tree_map.h File Reference

Map accessors for tree tiles. More...

#include "tile_map.h"
#include "water_map.h"

Go to the source code of this file.

Enumerations

enum  TreeType {
  TREE_TEMPERATE = 0x00 , TREE_SUB_ARCTIC = 0x0C , TREE_RAINFOREST = 0x14 , TREE_CACTUS = 0x1B ,
  TREE_SUB_TROPICAL = 0x1C , TREE_TOYLAND = 0x20 , TREE_INVALID = 0xFF
}
 List of tree types along all landscape types. More...
 
enum  TreeGround {
  TREE_GROUND_GRASS = 0 , TREE_GROUND_ROUGH = 1 , TREE_GROUND_SNOW_DESERT = 2 , TREE_GROUND_SHORE = 3 ,
  TREE_GROUND_ROUGH_SNOW = 4
}
 Enumeration for ground types of tiles with trees. More...
 
enum class  TreeGrowthStage : uint {
  Growing1 = 0 , Growing2 = 1 , Growing3 = 2 , Grown = 3 ,
  Dying1 = 4 , Dying2 = 5 , Dead = 6
}
 Enumeration for tree growth stages. More...
 

Functions

TreeType GetTreeType (Tile t)
 Returns the treetype of a tile.
 
TreeGround GetTreeGround (Tile t)
 Returns the groundtype for tree tiles.
 
uint GetTreeDensity (Tile t)
 Returns the 'density' of a tile with trees.
 
void SetTreeGroundDensity (Tile t, TreeGround g, uint d)
 Set the density and ground type of a tile with trees.
 
uint GetTreeCount (Tile t)
 Returns the number of trees on a tile.
 
void AddTreeCount (Tile t, int c)
 Add a amount to the tree-count value of a tile with trees.
 
TreeGrowthStage GetTreeGrowth (Tile t)
 Returns the tree growth stage.
 
void AddTreeGrowth (Tile t, int a)
 Add a value to the tree growth stage.
 
void SetTreeGrowth (Tile t, TreeGrowthStage g)
 Sets the tree growth stage of a tile.
 
void MakeTree (Tile t, TreeType type, uint count, TreeGrowthStage growth, TreeGround ground, uint density)
 Make a tree-tile.
 

Variables

static const uint TREE_COUNT_TEMPERATE = TREE_SUB_ARCTIC - TREE_TEMPERATE
 number of tree types on a temperate map.
 
static const uint TREE_COUNT_SUB_ARCTIC = TREE_RAINFOREST - TREE_SUB_ARCTIC
 number of tree types on a sub arctic map.
 
static const uint TREE_COUNT_RAINFOREST = TREE_CACTUS - TREE_RAINFOREST
 number of tree types for the 'rainforest part' of a sub-tropic map.
 
static const uint TREE_COUNT_SUB_TROPICAL = TREE_TOYLAND - TREE_SUB_TROPICAL
 number of tree types for the 'sub-tropic part' of a sub-tropic map.
 
static const uint TREE_COUNT_TOYLAND = 9
 number of tree types on a toyland map.
 

Detailed Description

Map accessors for tree tiles.

Definition in file tree_map.h.

Enumeration Type Documentation

◆ TreeGround

enum TreeGround

Enumeration for ground types of tiles with trees.

This enumeration defines the ground types for tiles with trees on it.

Enumerator
TREE_GROUND_GRASS 

normal grass

TREE_GROUND_ROUGH 

some rough tile

TREE_GROUND_SNOW_DESERT 

a desert or snow tile, depend on landscape

TREE_GROUND_SHORE 

shore

TREE_GROUND_ROUGH_SNOW 

A snow tile that is rough underneath.

Definition at line 52 of file tree_map.h.

◆ TreeGrowthStage

enum class TreeGrowthStage : uint
strong

Enumeration for tree growth stages.

This enumeration defines the stages of tree growth for tiles with trees on it.

Enumerator
Growing1 

First stage of growth.

Growing2 

Second stage of growth.

Growing3 

Third stage of growth.

Grown 

Fully grown tree.

Dying1 

First stage of dying.

Dying2 

Second stage of dying.

Dead 

Dead tree.

Definition at line 65 of file tree_map.h.

◆ TreeType

enum TreeType

List of tree types along all landscape types.

This enumeration contains a list of the different tree types along all landscape types. The values for the enumerations may be used for offsets from the grfs files. These points to the start of the tree list for a landscape. See the TREE_COUNT_* enumerations for the amount of different trees for a specific landscape.

Enumerator
TREE_TEMPERATE 

temperate tree

TREE_SUB_ARCTIC 

tree on a sub_arctic landscape

TREE_RAINFOREST 

tree on the 'green part' on a sub-tropical map

TREE_CACTUS 

a cactus for the 'desert part' on a sub-tropical map

TREE_SUB_TROPICAL 

tree on a sub-tropical map, non-rainforest, non-desert

TREE_TOYLAND 

tree on a toyland map

TREE_INVALID 

An invalid tree.

Definition at line 25 of file tree_map.h.

Function Documentation

◆ AddTreeCount()

void AddTreeCount ( Tile  t,
int  c 
)
inline

Add a amount to the tree-count value of a tile with trees.

This function add a value to the tree-count value of a tile. This value may be negative to reduce the tree-counter. If the resulting value reach 0 it doesn't get converted to a "normal" tile.

Parameters
tThe tile to change the tree amount
cThe value to add (or reduce) on the tree-count value
Precondition
Tile must be of type MP_TREES

Definition at line 180 of file tree_map.h.

References IsTileType(), Tile::m5(), and MP_TREES.

Referenced by CmdPlantTree(), and PlaceTreeGroupAroundTile().

◆ AddTreeGrowth()

void AddTreeGrowth ( Tile  t,
int  a 
)
inline

Add a value to the tree growth stage.

This function adds a value to the tree grow stage of a tile.

Parameters
tThe tile to add the value on
aThe value to add on the tree growth stage
Precondition
Tile must be of type MP_TREES

Definition at line 210 of file tree_map.h.

References IsTileType(), Tile::m5(), and MP_TREES.

◆ GetTreeCount()

uint GetTreeCount ( Tile  t)
inline

Returns the number of trees on a tile.

This function returns the number of trees of a tile (1-4). The tile must be contains at least one tree or be more specific: it must be of type MP_TREES.

Parameters
tThe index to get the number of trees
Returns
The number of trees (1-4)
Precondition
Tile must be of type MP_TREES

Definition at line 163 of file tree_map.h.

References GB(), IsTileType(), Tile::m5(), and MP_TREES.

Referenced by CmdPlantTree(), and PlaceTreeGroupAroundTile().

◆ GetTreeDensity()

uint GetTreeDensity ( Tile  t)
inline

Returns the 'density' of a tile with trees.

This function returns the density of a tile which got trees. Note that this value doesn't count the number of trees on a tile, use GetTreeCount instead. This function instead returns some kind of groundtype of the tile. As the map-array is finite in size and the information about the trees must be saved somehow other information about a tile must be saved somewhere encoded in the tile. So this function returns the density of a tile for sub arctic and sub tropical games. This means for sub arctic the type of snowline (0 to 3 for all 4 types of snowtiles) and for sub tropical the value 3 for a desert (and 0 for non-desert). The function name is not read as "get the tree density of a tile" but "get the density of a tile which got trees".

Parameters
tThe tile to get the 'density'
Precondition
Tile must be of type MP_TREES
See also
GetTreeCount

Definition at line 127 of file tree_map.h.

References GB(), IsTileType(), Tile::m2(), and MP_TREES.

Referenced by GetTerrainType().

◆ GetTreeGround()

TreeGround GetTreeGround ( Tile  t)
inline

Returns the groundtype for tree tiles.

This function returns the groundtype of a tile with trees.

Parameters
tThe tile to get the groundtype from
Returns
The groundtype of the tile
Precondition
Tile must be of type MP_TREES

Definition at line 102 of file tree_map.h.

References GB(), IsTileType(), Tile::m2(), and MP_TREES.

Referenced by AfterLoadGame(), GenerateRockyArea(), GetFloodingBehaviour(), GetNearbyTileInformation(), GetSmallMapVegetationPixels(), GetTerrainType(), IsSuitableForFarmField(), PlaceTree(), and TileLoop_Water().

◆ GetTreeGrowth()

TreeGrowthStage GetTreeGrowth ( Tile  t)
inline

Returns the tree growth stage.

This function returns the tree growth stage of a tile with trees.

Parameters
tThe tile to get the tree growth stage
Returns
The tree growth stage
Precondition
Tile must be of type MP_TREES

Definition at line 195 of file tree_map.h.

References GB(), IsTileType(), Tile::m5(), and MP_TREES.

Referenced by SearchLumberMillTrees().

◆ GetTreeType()

TreeType GetTreeType ( Tile  t)
inline

Returns the treetype of a tile.

This function returns the treetype of a given tile. As there are more possible treetypes for a tile in a game as the enumeration TreeType defines this function may be return a value which isn't catch by an entry of the enumeration TreeType. But there is no problem known about it.

Parameters
tThe tile to get the treetype from
Returns
The treetype of the given tile with trees
Precondition
Tile t must be of type MP_TREES

Definition at line 87 of file tree_map.h.

References IsTileType(), Tile::m3(), and MP_TREES.

◆ MakeTree()

void MakeTree ( Tile  t,
TreeType  type,
uint  count,
TreeGrowthStage  growth,
TreeGround  ground,
uint  density 
)
inline

Make a tree-tile.

This functions change the tile to a tile with trees and all information which belongs to it.

Parameters
tThe tile to make a tree-tile from
typeThe type of the tree
countthe number of trees
growththe growth stage
groundthe ground type
densitythe density (not the number of trees)

Definition at line 244 of file tree_map.h.

References Tile::m2(), Tile::m3(), Tile::m4(), Tile::m5(), Tile::m6(), Tile::m7(), MP_TREES, OWNER_NONE, SB(), SetTileOwner(), SetTileType(), SetWaterClass(), TREE_GROUND_SHORE, WATER_CLASS_INVALID, and WATER_CLASS_SEA.

Referenced by PlantTreesOnTile().

◆ SetTreeGroundDensity()

void SetTreeGroundDensity ( Tile  t,
TreeGround  g,
uint  d 
)
inline

Set the density and ground type of a tile with trees.

This functions saves the ground type and the density which belongs to it for a given tile.

Parameters
tThe tile to set the density and ground type
gThe ground type to save
dThe density to save with
Precondition
Tile must be of type MP_TREES

Definition at line 144 of file tree_map.h.

References IsTileType(), Tile::m2(), MP_TREES, SB(), SetWaterClass(), TREE_GROUND_SHORE, WATER_CLASS_INVALID, and WATER_CLASS_SEA.

Referenced by DoDryUp(), DoFloodTile(), and PlaceTree().

◆ SetTreeGrowth()

void SetTreeGrowth ( Tile  t,
TreeGrowthStage  g 
)
inline

Sets the tree growth stage of a tile.

This function sets the tree growth stage of a tile directly with the given value.

Parameters
tThe tile to change the tree growth stage
gThe new value
Precondition
Tile must be of type MP_TREES

Definition at line 226 of file tree_map.h.

References IsTileType(), Tile::m5(), MP_TREES, and SB().

Referenced by PlaceTreeGroupAroundTile().

Variable Documentation

◆ TREE_COUNT_RAINFOREST

const uint TREE_COUNT_RAINFOREST = TREE_CACTUS - TREE_RAINFOREST
static

number of tree types for the 'rainforest part' of a sub-tropic map.

Definition at line 43 of file tree_map.h.

Referenced by GetRandomTreeType().

◆ TREE_COUNT_SUB_ARCTIC

const uint TREE_COUNT_SUB_ARCTIC = TREE_RAINFOREST - TREE_SUB_ARCTIC
static

number of tree types on a sub arctic map.

Definition at line 42 of file tree_map.h.

Referenced by GetRandomTreeType().

◆ TREE_COUNT_SUB_TROPICAL

const uint TREE_COUNT_SUB_TROPICAL = TREE_TOYLAND - TREE_SUB_TROPICAL
static

number of tree types for the 'sub-tropic part' of a sub-tropic map.

Definition at line 44 of file tree_map.h.

Referenced by GetRandomTreeType().

◆ TREE_COUNT_TEMPERATE

const uint TREE_COUNT_TEMPERATE = TREE_SUB_ARCTIC - TREE_TEMPERATE
static

number of tree types on a temperate map.

Definition at line 41 of file tree_map.h.

Referenced by GetRandomTreeType().

◆ TREE_COUNT_TOYLAND

const uint TREE_COUNT_TOYLAND = 9
static

number of tree types on a toyland map.

Definition at line 45 of file tree_map.h.

Referenced by GetRandomTreeType(), and PlaceTreeGroupAroundTile().