MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / PlaceTree

Function PlaceTree

src/tree_cmd.cpp:161–178  ·  view source on GitHub ↗

* 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. * * @param tile The tile to make a tree-tile from * @param r The randomness value from a Random() value * @param keep_density Whether to keep the existing ground density of the tile. */

Source from the content-addressed store, hash-verified

159 * @param keep_density Whether to keep the existing ground density of the tile.
160 */
161void PlaceTree(TileIndex tile, uint32_t r, bool keep_density)
162{
163 TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
164
165 if (tree != TREE_INVALID) {
166 PlantTreesOnTile(tile, tree, GB(r, 22, 2), static_cast<TreeGrowthStage>(std::min<uint8_t>(GB(r, 16, 3), 6)));
167 MarkTileDirtyByTile(tile);
168
169 /* Maybe keep the existing ground density.*/
170 if (keep_density) return;
171
172 /* Rerandomize ground, if neither snow nor shore */
173 TreeGround ground = GetTreeGround(tile);
174 if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_ROUGH_SNOW && ground != TREE_GROUND_SHORE) {
175 SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3);
176 }
177 }
178}
179
180struct BlobHarmonic {
181 int amplitude;

Callers 4

MakeWetlandsFunction · 0.85
PlaceTreeGroupsFunction · 0.85
PlaceTreeAtSameHeightFunction · 0.85
PlaceTreesRandomlyFunction · 0.85

Calls 6

GetRandomTreeTypeFunction · 0.85
GBFunction · 0.85
PlantTreesOnTileFunction · 0.85
GetTreeGroundFunction · 0.85
SetTreeGroundDensityFunction · 0.85
MarkTileDirtyByTileFunction · 0.70

Tested by

no test coverage detected