mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-19 12:39:11 +00:00
Compare commits
4 Commits
573b55cf9f
...
89182e4b15
Author | SHA1 | Date | |
---|---|---|---|
|
89182e4b15 | ||
|
a75532dd47 | ||
|
6d40780434 | ||
|
6335312b3c |
@@ -58,6 +58,7 @@ static const uint16_t DEFAULT_TREE_STEPS = 1000; ///< Default number
|
||||
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.
|
||||
static const uint16_t FOREST_THRESHOLD = 6; ///< Minimum amount of trees required to be considered a forest.
|
||||
static const uint16_t FOREST_SEARCH_RADIUS = 2; ///< Radius of area to examine when determining forest status.
|
||||
|
||||
/**
|
||||
* Tests if a tile can be converted to MP_TREES
|
||||
@@ -96,17 +97,13 @@ static bool IsNearbyForest(TileIndex tile)
|
||||
if (IsTileType(tile, MP_TREES)) return true;
|
||||
|
||||
/* Count the trees around the clear tile to determine if it's near a forest */
|
||||
for (int x = -2; x <= 2; x++) {
|
||||
for (int y = -2; y <= 2; y++) {
|
||||
TileIndex vincity = TileAddWrap(tile, x, y);
|
||||
if (vincity != INVALID_TILE &&
|
||||
IsTileType(vincity, MP_TREES)) {
|
||||
planted_tile_count++;
|
||||
}
|
||||
}
|
||||
for (TileIndex t : TileArea(tile).Expand(FOREST_SEARCH_RADIUS)) {
|
||||
if (!IsTileType(t, MP_TREES)) continue;
|
||||
++planted_tile_count;
|
||||
if (planted_tile_count >= FOREST_THRESHOLD) return true;
|
||||
}
|
||||
|
||||
return (planted_tile_count >= FOREST_THRESHOLD);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -802,7 +799,7 @@ static void TileLoop_Trees(TileIndex tile)
|
||||
break;
|
||||
|
||||
case 6: // final stage of tree destruction
|
||||
if (!CanPlantExtraTrees(tile)) {
|
||||
if (!CanPlantExtraTrees(tile) || (_settings_game.game_creation.tree_placer == TP_IMPROVED && !IsNearbyForest(tile))) {
|
||||
/* if trees can't spread just plant a new one to prevent deforestation */
|
||||
SetTreeGrowth(tile, 0);
|
||||
} else if (GetTreeCount(tile) > 1) {
|
||||
@@ -810,12 +807,6 @@ static void TileLoop_Trees(TileIndex tile)
|
||||
AddTreeCount(tile, -1);
|
||||
SetTreeGrowth(tile, 3);
|
||||
} else {
|
||||
/* Backups the type of tree if using improved trees */
|
||||
TreeType treetype;
|
||||
if (_settings_game.game_creation.tree_placer == TP_IMPROVED && IsTileType(tile, MP_TREES)) {
|
||||
treetype = GetTreeType(tile);
|
||||
}
|
||||
|
||||
/* just one tree, change type into MP_CLEAR */
|
||||
switch (GetTreeGround(tile)) {
|
||||
case TREE_GROUND_SHORE: MakeShore(tile); break;
|
||||
@@ -837,11 +828,6 @@ static void TileLoop_Trees(TileIndex tile)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* When using improved trees, when a "alone" tree is dead, a new one is planted immediately. */
|
||||
if (_settings_game.game_creation.tree_placer == TP_IMPROVED && !IsNearbyForest(tile)) {
|
||||
PlantTreesOnTile(tile, treetype, 0, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user