* 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) */
| 328 | * @param height The height (like the one from the tile) |
| 329 | */ |
| 330 | static 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 |
no test coverage detected