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

Function PlaceTreeAtSameHeight

src/tree_cmd.cpp:330–352  ·  view source on GitHub ↗

* 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. * * @param tile The base tile to add a new tree somewhere around * @param height The height (like the one from the tile) */

Source from the content-addressed store, hash-verified

328 * @param height The height (like the one from the tile)
329 */
330static void PlaceTreeAtSameHeight(TileIndex tile, int height)
331{
332 for (uint i = 0; i < DEFAULT_TREE_STEPS; i++) {
333 uint32_t r = Random();
334 int x = GB(r, 0, 5) - 16;
335 int y = GB(r, 8, 5) - 16;
336 TileIndex cur_tile = TileAddWrap(tile, x, y);
337 if (cur_tile == INVALID_TILE) continue;
338
339 /* Keep in range of the existing tree */
340 if (abs(x) + abs(y) > 16) continue;
341
342 /* Clear tile, no farm-tiles or rocks */
343 if (!CanPlantTreesOnTile(cur_tile, true)) continue;
344
345 /* Not too much height difference */
346 if (Delta(GetTileZ(cur_tile), height) > 2) continue;
347
348 /* Place one tree and quit */
349 PlaceTree(cur_tile, r);
350 break;
351 }
352}
353
354/**
355 * Place some trees randomly

Callers 1

PlaceTreesRandomlyFunction · 0.85

Calls 8

GBFunction · 0.85
TileAddWrapFunction · 0.85
absFunction · 0.85
CanPlantTreesOnTileFunction · 0.85
DeltaFunction · 0.85
GetTileZFunction · 0.85
PlaceTreeFunction · 0.85
RandomFunction · 0.50

Tested by

no test coverage detected