|
OpenTTD Source 20251117-master-g7398d2e290
|
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/geometry_type.hpp"#include "core/random_func.hpp"#include "newgrf_generic.h"#include "timer/timer_game_tick.h"#include "tree_cmd.h"#include "landscape_cmd.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 | BlobHarmonic |
| struct | TreeListEnt |
Enumerations | |
| enum | TreePlacer : uint8_t { TP_NONE , TP_ORIGINAL , TP_IMPROVED } |
| List of tree placer algorithm. More... | |
| enum | ExtraTreePlacement : uint8_t { ETP_NO_SPREAD , ETP_SPREAD_RAINFOREST , ETP_SPREAD_ALL , ETP_NO_GROWTH_NO_SPREAD } |
| 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. | |
| static void | PlantTreesOnTile (TileIndex tile, TreeType treetype, uint count, TreeGrowthStage growth) |
| Creates a tree tile Ground type and density is preserved. | |
| static TreeType | GetRandomTreeType (TileIndex tile, uint seed) |
| Get a random TreeType for the given tile based on a given seed. | |
| static void | PlaceTree (TileIndex tile, uint32_t r) |
| Make a random tree tile of the given tile. | |
| static void | CreateStarShapedPolygon (int radius, std::span< const BlobHarmonic > harmonics, std::span< Point > shape) |
| Creates a star-shaped polygon originating from (0, 0) as defined by the given harmonics. | |
| static void | CreateRandomStarShapedPolygon (int radius, std::span< Point > shape) |
| Creates a random star-shaped polygon originating from (0, 0). | |
| static bool | IsPointInTriangle (int x, int y, const Point &v1, const Point &v2, const Point &v3) |
| Returns true if the given coordinates lie within a triangle. | |
| static bool | IsPointInStarShapedPolygon (int x, int y, std::span< Point > shape) |
| Returns true if the given coordinates lie within a star shaped polygon. | |
| static void | PlaceTreeGroups (uint num_groups) |
| Creates a number of tree groups. | |
| static void | PlaceTreeAtSameHeight (TileIndex tile, int height) |
| Place a tree at the same height as an existing tree. | |
| void | PlaceTreesRandomly () |
| Place some trees randomly. | |
| uint | PlaceTreeGroupAroundTile (TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone) |
| Place some trees in a radius around a tile. | |
| void | GenerateTrees () |
| Place new trees. | |
| CommandCost | CmdPlantTree (DoCommandFlags flags, TileIndex tile, TileIndex start_tile, uint8_t tree_to_plant, bool diagonal) |
| Plant a tree. | |
| static void | DrawTile_Trees (TileInfo *ti) |
| static int | GetSlopePixelZ_Trees (TileIndex tile, uint x, uint y, bool) |
| static Foundation | GetFoundation_Trees (TileIndex, Slope) |
| static CommandCost | ClearTile_Trees (TileIndex tile, DoCommandFlags flags) |
| static void | GetTileDesc_Trees (TileIndex tile, TileDesc &td) |
| static void | TileLoopTreesDesert (TileIndex tile) |
| static void | TileLoopTreesAlps (TileIndex tile) |
| static bool | CanPlantExtraTrees (TileIndex tile) |
| static void | TileLoop_Trees (TileIndex tile) |
| bool | DecrementTreeCounter () |
| Decrement the tree tick counter. | |
| static void | PlantRandomTree (bool rainforest) |
| Place a random tree on a random tile. | |
| void | OnTick_Trees () |
| static TrackStatus | GetTileTrackStatus_Trees (TileIndex, TransportType, uint, DiagDirection) |
| static void | ChangeTileOwner_Trees (TileIndex, Owner, Owner) |
| void | InitializeTrees () |
| static CommandCost | TerraformTile_Trees (TileIndex tile, DoCommandFlags flags, int, Slope) |
Variables | |
| uint8_t | _trees_tick_ctr |
| Determines when to consider building more trees. | |
| static const uint16_t | DEFAULT_TREE_STEPS = 1000 |
| Default number of attempts for placing trees. | |
| static const uint16_t | DEFAULT_RAINFOREST_TREE_STEPS = 15000 |
| Default number of attempts for placing extra trees at rainforest in tropic. | |
| static const uint16_t | EDITOR_TREE_DIV = 5 |
| Game editor tree generation divisor factor. | |
| const TileTypeProcs | _tile_type_trees_procs |
Handling of tree tiles.
Definition in file tree_cmd.cpp.
| enum ExtraTreePlacement : uint8_t |
Where to place trees while in-game?
Definition at line 48 of file tree_cmd.cpp.
| enum TreePlacer : uint8_t |
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 41 of file tree_cmd.cpp.
|
static |
Definition at line 813 of file tree_cmd.cpp.
|
static |
Tests if a tile can be converted to MP_TREES This is true for clear ground without farms or rocks.
| tile | the tile of interest |
| allow_desert | Allow planting trees on CLEAR_DESERT? |
Definition at line 70 of file tree_cmd.cpp.
References CLEAR_DESERT, CLEAR_FIELDS, CLEAR_ROCKS, GetTileSlope(), GetTileType(), IsBridgeAbove(), IsClearGround(), IsCoast(), IsSlopeWithOneCornerRaised(), MP_CLEAR, and MP_WATER.
Referenced by PlaceTreeAtSameHeight(), PlaceTreeGroupAroundTile(), PlaceTreeGroups(), PlaceTreesRandomly(), PlantRandomTree(), and PlantTreesOnTile().
Definition at line 1003 of file tree_cmd.cpp.
|
static |
Definition at line 725 of file tree_cmd.cpp.
| CommandCost CmdPlantTree | ( | DoCommandFlags | flags, |
| TileIndex | tile, | ||
| TileIndex | start_tile, | ||
| uint8_t | tree_to_plant, | ||
| bool | diagonal | ||
| ) |
Plant a tree.
| flags | type of operation |
| tile | end tile of area-drag |
| start_tile | start tile of area-drag of tree plantation |
| tree_to_plant | tree type, TREE_INVALID means random. |
| diagonal | Whether to use the Orthogonal (false) or Diagonal (true) iterator. |
Definition at line 511 of file tree_cmd.cpp.
References _current_company, _settings_game, CommandCost::AddCost(), AddTreeCount(), ChangeTownRating(), CLEAR_FIELDS, CLEAR_ROCKS, ClosestTownFromTile(), CMD_ERROR, TileIterator::Create(), EconomySettings::dist_local_authority, GameSettings::economy, Execute, EXPENSES_OTHER, CommandCost::Failed(), GameSettings::game_creation, GB(), GetClearGround(), CommandCost::GetCost(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), GetRandomTreeType(), GetTileSlope(), GetTileType(), GetTreeCount(), GetTropicZone(), Growing1, Grown, INVALID_STRING_ID, INVALID_TILE, IsBridgeAbove(), IsCoast(), IsInsideBS(), IsInsideMM(), IsSlopeWithOneCornerRaised(), IsTileType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), GameCreationSettings::landscape, MarkTileDirtyByTile(), MP_CLEAR, MP_TREES, MP_WATER, PlantTreesOnTile(), Random, SetTropicZone(), Map::Size(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), to_underlying(), TREE_CACTUS, TREE_INVALID, CompanyProperties::tree_limit, TREE_RAINFOREST, TREE_SUB_TROPICAL, TREE_TOYLAND, TROPICZONE_DESERT, TROPICZONE_NORMAL, and TROPICZONE_RAINFOREST.
|
static |
Creates a random star-shaped polygon originating from (0, 0).
The shape is placed into a pre-allocated span so the caller controls allocation.
| radius | The maximum radius of the blob. May be smaller, but will not be larger. | |
| [out] | shape | Shape to fill with polygon points. |
Definition at line 231 of file tree_cmd.cpp.
References CreateStarShapedPolygon(), and Random.
Referenced by PlaceTreeGroups().
|
static |
Creates a star-shaped polygon originating from (0, 0) as defined by the given harmonics.
The shape is placed into a pre-allocated span so the caller controls allocation.
| radius | The maximum radius of the polygon. May be smaller, but will not be larger. | |
| harmonics | Harmonics data for the polygon. | |
| [out] | shape | Shape to fill with points. |
Definition at line 200 of file tree_cmd.cpp.
Referenced by CreateRandomStarShapedPolygon().
| bool DecrementTreeCounter | ( | ) |
Decrement the tree tick counter.
The interval is scaled by map size to allow for the same density regardless of size. Adjustment for map sizes below the standard 256 * 256 are handled earlier.
Definition at line 945 of file tree_cmd.cpp.
References _trees_tick_ctr, MAX_MAP_SIZE_BITS, MIN_MAP_SIZE_BITS, and Map::ScaleBySize().
|
static |
Definition at line 641 of file tree_cmd.cpp.
| 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 476 of file tree_cmd.cpp.
References _settings_game, DEFAULT_RAINFOREST_TREE_STEPS, DEFAULT_TREE_STEPS, GameSettings::game_creation, GB(), GWP_TREE, GameCreationSettings::landscape, PlaceTreeGroups(), PlaceTreesRandomly(), Random, Map::ScaleBySize(), SetGeneratingWorldProgress(), TP_IMPROVED, TP_NONE, TP_ORIGINAL, and GameCreationSettings::tree_placer.
Referenced by _GenerateWorld().
|
static |
Definition at line 720 of file tree_cmd.cpp.
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.
| tile | The tile to get a random TreeType from |
| seed | The seed for randomness, must be less or equal 256 |
Definition at line 141 of file tree_cmd.cpp.
References _settings_game, GameSettings::game_creation, GetTropicZone(), GameCreationSettings::landscape, TREE_CACTUS, TREE_COUNT_RAINFOREST, TREE_COUNT_SUB_ARCTIC, TREE_COUNT_SUB_TROPICAL, TREE_COUNT_TEMPERATE, TREE_COUNT_TOYLAND, TREE_INVALID, TREE_RAINFOREST, TREE_SUB_ARCTIC, TREE_SUB_TROPICAL, TREE_TEMPERATE, TREE_TOYLAND, TROPICZONE_DESERT, and TROPICZONE_NORMAL.
Referenced by CmdPlantTree(), PlaceTree(), and PlantRandomTree().
|
static |
Definition at line 713 of file tree_cmd.cpp.
Definition at line 742 of file tree_cmd.cpp.
|
static |
Definition at line 998 of file tree_cmd.cpp.
| void InitializeTrees | ( | ) |
Definition at line 1008 of file tree_cmd.cpp.
|
static |
Returns true if the given coordinates lie within a star shaped polygon.
Breaks the polygon into a series of triangles around the centre point (0, 0) and then tests the coordinates against each triangle until a match is found (or not).
| x | X coordinate relative to centre of shape. |
| y | Y coordinate relative to centre of shape. |
| shape | The shape to check against. |
Definition at line 278 of file tree_cmd.cpp.
References IsPointInTriangle().
Referenced by PlaceTreeGroups().
|
static |
Returns true if the given coordinates lie within a triangle.
| x | X coordinate relative to centre of shape. |
| y | Y coordinate relative to centre of shape. |
| v1 | First vertex of triangle. |
| v2 | Second vertex of triangle. |
| v3 | Third vertex of triangle. |
Definition at line 259 of file tree_cmd.cpp.
References Coord2D< T >::x, and Coord2D< T >::y.
Referenced by IsPointInStarShapedPolygon().
| void OnTick_Trees | ( | ) |
Definition at line 974 of file tree_cmd.cpp.
|
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.
| tile | The tile to make a tree-tile from |
| r | The randomness value from a Random() value |
Definition at line 171 of file tree_cmd.cpp.
References GB(), GetRandomTreeType(), GetTreeGround(), MarkTileDirtyByTile(), PlantTreesOnTile(), SetTreeGroundDensity(), TREE_GROUND_ROUGH_SNOW, TREE_GROUND_SHORE, TREE_GROUND_SNOW_DESERT, and TREE_INVALID.
Referenced by PlaceTreeAtSameHeight(), PlaceTreeGroups(), and PlaceTreesRandomly().
|
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.
| tile | The base tile to add a new tree somewhere around |
| height | The height (like the one from the tile) |
Definition at line 337 of file tree_cmd.cpp.
References abs(), CanPlantTreesOnTile(), DEFAULT_TREE_STEPS, Delta(), GB(), GetTileZ(), INVALID_TILE, PlaceTree(), Random, and TileAddWrap().
Referenced by PlaceTreesRandomly().
| uint PlaceTreeGroupAroundTile | ( | TileIndex | tile, |
| TreeType | treetype, | ||
| uint | radius, | ||
| uint | count, | ||
| bool | set_zone | ||
| ) |
Place some trees in a radius around a tile.
The trees are placed in an quasi-normal distribution around the indicated tile, meaning that while the radius does define a square, the distribution inside the square will be roughly circular.
| tile | Tile to place trees around. |
| treetype | Type of trees to place. Must be a valid tree type for the climate. |
| radius | Maximum distance (on each axis) from tile to place trees. |
| count | Maximum number of trees to place. |
| set_zone | Whether to create a rainforest zone when placing rainforest trees. |
Definition at line 429 of file tree_cmd.cpp.
References AddTreeCount(), CanPlantTreesOnTile(), DistanceSquare(), OrthogonalTileArea::Expand(), GetTileType(), GetTreeCount(), Growing1, Grown, INVALID_TILE, IsInsideMM(), IsTileType(), MarkTileDirtyByTile(), MP_TREES, MP_VOID, PlantTreesOnTile(), SetTreeGrowth(), SetTropicZone(), TileAddWrap(), TREE_CACTUS, TREE_COUNT_TOYLAND, TREE_RAINFOREST, TREE_TOYLAND, and TROPICZONE_RAINFOREST.
|
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.
| num_groups | Number of tree groups to place. |
< How many segments make up the tree group.
< Maximum radius of tree groups.
Definition at line 297 of file tree_cmd.cpp.
References CanPlantTreesOnTile(), CreateRandomStarShapedPolygon(), DEFAULT_TREE_STEPS, GB(), GWP_TREE, IncreaseGeneratingWorldProgress(), INVALID_TILE, IsPointInStarShapedPolygon(), PlaceTree(), Random, RandomTile, and TileAddWrap().
Referenced by GenerateTrees().
| void PlaceTreesRandomly | ( | ) |
Place some trees randomly.
This function just place some trees randomly on the map.
Definition at line 366 of file tree_cmd.cpp.
References _settings_game, CanPlantTreesOnTile(), GameSettings::construction, DEFAULT_RAINFOREST_TREE_STEPS, DEFAULT_TREE_STEPS, EDITOR_TREE_DIV, GameSettings::game_creation, GetSnowLine(), GetTileZ(), GetTropicZone(), GWP_TREE, IncreaseGeneratingWorldProgress(), GameCreationSettings::landscape, ConstructionSettings::map_height_limit, MAP_HEIGHT_LIMIT_ORIGINAL, PlaceTree(), PlaceTreeAtSameHeight(), Random, RandomTileSeed(), Map::ScaleBySize(), TP_IMPROVED, GameCreationSettings::tree_placer, and TROPICZONE_RAINFOREST.
Referenced by GenerateTrees(), and BuildTreesWindow::OnClick().
|
static |
Place a random tree on a random tile.
| rainforest | If set the random tile must be in a rainforest zone. |
Definition at line 960 of file tree_cmd.cpp.
References CanPlantTreesOnTile(), GB(), GetRandomTreeType(), GetTropicZone(), Growing1, PlantTreesOnTile(), Random, RandomTileSeed(), TREE_INVALID, and TROPICZONE_RAINFOREST.
|
static |
Creates a tree tile Ground type and density is preserved.
| tile | where to plant the trees. |
| treetype | The type of the tree |
| count | the number of trees (minus 1) |
| growth | the growth status |
Definition at line 95 of file tree_cmd.cpp.
References CanPlantTreesOnTile(), CLEAR_GRASS, CLEAR_ROUGH, ClearNeighbourNonFloodingStates(), GetClearDensity(), GetClearGround(), GetTileType(), IsSnowTile(), MakeTree(), MP_CLEAR, MP_WATER, TREE_GROUND_GRASS, TREE_GROUND_ROUGH, TREE_GROUND_ROUGH_SNOW, TREE_GROUND_SHORE, TREE_GROUND_SNOW_DESERT, and TREE_INVALID.
Referenced by CmdPlantTree(), PlaceTree(), PlaceTreeGroupAroundTile(), and PlantRandomTree().
|
static |
Definition at line 1013 of file tree_cmd.cpp.
|
static |
Definition at line 820 of file tree_cmd.cpp.
|
static |
Definition at line 782 of file tree_cmd.cpp.
|
static |
Definition at line 755 of file tree_cmd.cpp.
|
extern |
Definition at line 54 of file landscape.cpp.
| uint8_t _trees_tick_ctr |
Determines when to consider building more trees.
Definition at line 56 of file tree_cmd.cpp.
Referenced by DecrementTreeCounter().
|
static |
Default number of attempts for placing extra trees at rainforest in tropic.
Definition at line 59 of file tree_cmd.cpp.
Referenced by GenerateTrees(), and PlaceTreesRandomly().
|
static |
Default number of attempts for placing trees.
Definition at line 58 of file tree_cmd.cpp.
Referenced by GenerateTrees(), PlaceTreeAtSameHeight(), PlaceTreeGroups(), and PlaceTreesRandomly().
|
static |
Game editor tree generation divisor factor.
Definition at line 60 of file tree_cmd.cpp.
Referenced by PlaceTreesRandomly().