diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 0aa14016cf..b2dd4cf43f 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -834,10 +834,6 @@ void OnTick_Trees() /* Don't spread trees if that's not allowed */ if (_settings_game.construction.extra_tree_placement == ETP_NO_SPREAD || _settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return; - uint32_t r; - TileIndex tile; - TreeType tree; - /* Skip some tree ticks for map sizes below 256 * 256. 64 * 64 is 16 times smaller, so * this is the maximum number of ticks that are skipped. Number of ticks to skip is * inversely proportional to map size, so that is handled to create a mask. */ @@ -847,21 +843,28 @@ void OnTick_Trees() /* place a tree at a random rainforest spot */ if (_settings_game.game_creation.landscape == LT_TROPIC) { for (uint c = Map::ScaleBySize(1); c > 0; c--) { - if ((r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) && - CanPlantTreesOnTile(tile, false) && - (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { - PlantTreesOnTile(tile, tree, 0, TreeGrowthStage::Growing1); - } + uint32_t r = Random(); + TileIndex tile = RandomTileSeed(r); + if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) continue; + if (!CanPlantTreesOnTile(tile, false)) continue; + + TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8)); + if (tree == TREE_INVALID) continue; + + PlantTreesOnTile(tile, tree, 0, TreeGrowthStage::Growing1); } } if (!DecrementTreeCounter() || _settings_game.construction.extra_tree_placement == ETP_SPREAD_RAINFOREST) return; /* place a tree at a random spot */ - r = Random(); - tile = RandomTileSeed(r); - if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { - PlantTreesOnTile(tile, tree, 0, TreeGrowthStage::Growing1); + uint32_t r = Random(); + TileIndex tile = RandomTileSeed(r); + if (CanPlantTreesOnTile(tile, false)) { + TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8)); + if (tree != TREE_INVALID) { + PlantTreesOnTile(tile, tree, 0, TreeGrowthStage::Growing1); + } } }