OpenTTD
Data Structures | Enumerations | Functions | Variables
tree_cmd.cpp File Reference

Handling of tree tiles. More...

#include "stdafx.h"
#include "clear_map.h"
#include "landscape.h"
#include "tree_map.h"
#include "viewport_func.h"
#include "command_func.h"
#include "town.h"
#include "genworld.h"
#include "clear_func.h"
#include "company_func.h"
#include "sound_func.h"
#include "water.h"
#include "company_base.h"
#include "core/random_func.hpp"
#include "newgrf_generic.h"
#include "table/strings.h"
#include "table/tree_land.h"
#include "table/clear_land.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  TreeListEnt
 

Enumerations

enum  TreePlacer { TP_NONE, TP_ORIGINAL, TP_IMPROVED }
 List of tree placer algorithm. More...
 
enum  ExtraTreePlacement { ETP_NONE, ETP_RAINFOREST, ETP_ALL }
 Where to place trees while in-game? More...
 

Functions

static bool CanPlantTreesOnTile (TileIndex tile, bool allow_desert)
 Tests if a tile can be converted to MP_TREES This is true for clear ground without farms or rocks. More...
 
static void PlantTreesOnTile (TileIndex tile, TreeType treetype, uint count, uint growth)
 Creates a tree tile Ground type and density is preserved. More...
 
static TreeType GetRandomTreeType (TileIndex tile, uint seed)
 Get a random TreeType for the given tile based on a given seed. More...
 
static void PlaceTree (TileIndex tile, uint32 r)
 Make a random tree tile of the given tile. More...
 
static void PlaceTreeGroups (uint num_groups)
 Creates a number of tree groups. More...
 
static void PlaceTreeAtSameHeight (TileIndex tile, int height)
 Place a tree at the same height as an existing tree. More...
 
void PlaceTreesRandomly ()
 Place some trees randomly. More...
 
void GenerateTrees ()
 Place new trees. More...
 
CommandCost CmdPlantTree (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Plant a tree. More...
 
static void DrawTile_Trees (TileInfo *ti)
 
static int GetSlopePixelZ_Trees (TileIndex tile, uint x, uint y)
 
static Foundation GetFoundation_Trees (TileIndex tile, Slope tileh)
 
static CommandCost ClearTile_Trees (TileIndex tile, DoCommandFlag flags)
 
static void GetTileDesc_Trees (TileIndex tile, TileDesc *td)
 
static void TileLoopTreesDesert (TileIndex tile)
 
static void TileLoopTreesAlps (TileIndex tile)
 
static void TileLoop_Trees (TileIndex tile)
 
void OnTick_Trees ()
 
static TrackStatus GetTileTrackStatus_Trees (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 
static void ChangeTileOwner_Trees (TileIndex tile, Owner old_owner, Owner new_owner)
 
void InitializeTrees ()
 
static CommandCost TerraformTile_Trees (TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 

Variables

byte _trees_tick_ctr
 Determines when to consider building more trees. More...
 
static const uint16 DEFAULT_TREE_STEPS = 1000
 Default number of attempts for placing trees.
 
static const uint16 DEFAULT_RAINFOREST_TREE_STEPS = 15000
 Default number of attempts for placing extra trees at rainforest in tropic.
 
static const uint16 EDITOR_TREE_DIV = 5
 Game editor tree generation divisor factor.
 
const TileTypeProcs _tile_type_trees_procs
 

Detailed Description

Handling of tree tiles.

Definition in file tree_cmd.cpp.

Enumeration Type Documentation

◆ ExtraTreePlacement

Where to place trees while in-game?

Enumerator
ETP_NONE 

Place trees on no tiles.

ETP_RAINFOREST 

Place trees only on rainforest tiles.

ETP_ALL 

Place trees on all tiles.

Definition at line 46 of file tree_cmd.cpp.

◆ TreePlacer

enum TreePlacer

List of tree placer algorithm.

This enumeration defines all possible tree placer algorithm in the game.

Enumerator
TP_NONE 

No tree placer algorithm.

TP_ORIGINAL 

The original algorithm.

TP_IMPROVED 

A 'improved' algorithm.

Definition at line 39 of file tree_cmd.cpp.

Function Documentation

◆ CanPlantTreesOnTile()

static bool CanPlantTreesOnTile ( TileIndex  tile,
bool  allow_desert 
)
static

Tests if a tile can be converted to MP_TREES This is true for clear ground without farms or rocks.

Parameters
tilethe tile of interest
allow_desertAllow planting trees on CLEAR_DESERT?
Returns
true if trees can be built.

Definition at line 67 of file tree_cmd.cpp.

References CLEAR_DESERT, CLEAR_FIELDS, CLEAR_ROCKS, GetRawClearGround(), GetTileSlope(), GetTileType(), IsBridgeAbove(), IsClearGround(), IsCoast(), IsSlopeWithOneCornerRaised(), MP_CLEAR, and MP_WATER.

◆ CmdPlantTree()

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

Plant a tree.

Parameters
tileend tile of area-drag
flagstype of operation
p1tree type, TREE_INVALID means random.
p2start tile of area-drag of tree plantation
textunused
Returns
the cost of this operation or an error

Definition at line 335 of file tree_cmd.cpp.

References CMD_ERROR, EXPENSES_OTHER, GB(), INVALID_STRING_ID, IsInsideBS(), MapSize(), and TREE_INVALID.

◆ GenerateTrees()

void GenerateTrees ( )

Place new trees.

This function takes care of the selected tree placer algorithm and place randomly the trees for a new game.

Definition at line 300 of file tree_cmd.cpp.

References _settings_game, GameSettings::game_creation, GameCreationSettings::landscape, TP_NONE, TP_ORIGINAL, and GameCreationSettings::tree_placer.

◆ GetRandomTreeType()

static TreeType GetRandomTreeType ( TileIndex  tile,
uint  seed 
)
static

Get a random TreeType for the given tile based on a given seed.

This function returns a random TreeType which can be placed on the given tile. The seed for randomness must be less or equal 256, use GB on the value of Random() to get such a value.

Parameters
tileThe tile to get a random TreeType from
seedThe seed for randomness, must be less or equal 256
Returns
The random tree type

Definition at line 132 of file tree_cmd.cpp.

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

Referenced by PlaceTree().

◆ PlaceTree()

static void PlaceTree ( TileIndex  tile,
uint32  r 
)
static

Make a random tree tile of the given tile.

Create a new tree-tile for the given tile. The second parameter is used for randomness like type and number of trees.

Parameters
tileThe tile to make a tree-tile from
rThe randomness value from a Random() value

Definition at line 162 of file tree_cmd.cpp.

References GB(), GetRandomTreeType(), GetTreeGround(), min(), PlantTreesOnTile(), SetTreeCounter(), SetTreeGroundDensity(), TREE_GROUND_ROUGH_SNOW, TREE_GROUND_SHORE, TREE_GROUND_SNOW_DESERT, and TREE_INVALID.

◆ PlaceTreeAtSameHeight()

static void PlaceTreeAtSameHeight ( TileIndex  tile,
int  height 
)
static

Place a tree at the same height as an existing tree.

Add a new tree around the given tile which is at the same height or at some offset (2 units) of it.

Parameters
tileThe base tile to add a new tree somewhere around
heightThe height (like the one from the tile)

Definition at line 217 of file tree_cmd.cpp.

◆ PlaceTreeGroups()

static void PlaceTreeGroups ( uint  num_groups)
static

Creates a number of tree groups.

The number of trees in each group depends on how many trees are actually placed around the given tile.

Parameters
num_groupsNumber of tree groups to place.

Definition at line 186 of file tree_cmd.cpp.

References DEFAULT_TREE_STEPS, and RandomTile.

◆ PlaceTreesRandomly()

void PlaceTreesRandomly ( )

Place some trees randomly.

This function just place some trees randomly on the map.

Definition at line 246 of file tree_cmd.cpp.

References DEFAULT_TREE_STEPS, and ScaleByMapSize().

◆ PlantTreesOnTile()

static void PlantTreesOnTile ( TileIndex  tile,
TreeType  treetype,
uint  count,
uint  growth 
)
static

Creates a tree tile Ground type and density is preserved.

Precondition
the tile must be suitable for trees.
Parameters
tilewhere to plant the trees.
treetypeThe type of the tree
countthe number of trees (minus 1)
growththe growth status

Definition at line 92 of file tree_cmd.cpp.

Referenced by PlaceTree().

Variable Documentation

◆ _tile_type_trees_procs

const TileTypeProcs _tile_type_trees_procs
Initial value:
= {
DrawTile_Trees,
GetSlopePixelZ_Trees,
ClearTile_Trees,
NULL,
GetTileDesc_Trees,
GetTileTrackStatus_Trees,
NULL,
NULL,
TileLoop_Trees,
ChangeTileOwner_Trees,
NULL,
NULL,
GetFoundation_Trees,
TerraformTile_Trees,
}

◆ _trees_tick_ctr

byte _trees_tick_ctr

Determines when to consider building more trees.

Definition at line 53 of file tree_cmd.cpp.