From 150e15eae3dcf4b3937adad502e991f6726da180 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 3 Feb 2025 12:26:55 +0000 Subject: [PATCH] Feature: Place rocks on "too steep" tiles when fixing slopes. When generating maps or loading heightmaps, the terrain height is altered to prevent slopes that can't be represented. During this, there is now a chance of these tiles being turned into a rocky tile. Chance of placing rocks is based on the height. This gives a rocky mountain appearance without affecting all peaks. --- src/clear_cmd.cpp | 2 +- src/heightmap.cpp | 39 ++++++++++++++++++++++++++------------- src/landscape.cpp | 2 +- src/tgp.cpp | 4 ---- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp index ee4b9f6d27..be488f8a3e 100644 --- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -165,7 +165,7 @@ static void TileLoopClearAlps(TileIndex tile) /* Below the snow line, do nothing if no snow. */ /* At or above the snow line, make snow tile if needed. */ if (k >= 0) { - MakeSnow(tile); + MakeSnow(tile, IsClearGround(tile, CLEAR_ROCKS) ? GetClearDensity(tile) : 0); MarkTileDirtyByTile(tile); } return; diff --git a/src/heightmap.cpp b/src/heightmap.cpp index aae4e4865c..e80179e336 100644 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -400,7 +400,8 @@ void FixSlopes() { uint width, height; int row, col; - uint8_t current_tile; + uint8_t current_height; + uint8_t max_height = _settings_game.construction.map_height_limit; /* Adjust height difference to maximum one horizontal/vertical change. */ width = Map::SizeX(); @@ -409,21 +410,27 @@ void FixSlopes() /* Top and left edge */ for (row = 0; (uint)row < height; row++) { for (col = 0; (uint)col < width; col++) { - current_tile = MAX_TILE_HEIGHT; + current_height = MAX_TILE_HEIGHT; if (col != 0) { /* Find lowest tile; either the top or left one */ - current_tile = TileHeight(TileXY(col - 1, row)); // top edge + current_height = TileHeight(TileXY(col - 1, row)); // top edge } if (row != 0) { - if (TileHeight(TileXY(col, row - 1)) < current_tile) { - current_tile = TileHeight(TileXY(col, row - 1)); // left edge + if (TileHeight(TileXY(col, row - 1)) < current_height) { + current_height = TileHeight(TileXY(col, row - 1)); // left edge } } /* Does the height differ more than one? */ - if (TileHeight(TileXY(col, row)) >= (uint)current_tile + 2) { + TileIndex tile = TileXY(col, row); + if (TileHeight(tile) >= (uint)current_height + 2) { /* Then change the height to be no more than one */ - SetTileHeight(TileXY(col, row), current_tile + 1); + SetTileHeight(tile, current_height + 1); + /* Height was changed so now there's a chance, more likely at higher altitude, of the + * tile turning into rock. */ + if (IsInnerTile(tile) && RandomRange(max_height) <= current_height) { + MakeClear(tile, CLEAR_ROCKS, 3); + } } } } @@ -431,22 +438,28 @@ void FixSlopes() /* Bottom and right edge */ for (row = height - 1; row >= 0; row--) { for (col = width - 1; col >= 0; col--) { - current_tile = MAX_TILE_HEIGHT; + current_height = MAX_TILE_HEIGHT; if ((uint)col != width - 1) { /* Find lowest tile; either the bottom and right one */ - current_tile = TileHeight(TileXY(col + 1, row)); // bottom edge + current_height = TileHeight(TileXY(col + 1, row)); // bottom edge } if ((uint)row != height - 1) { - if (TileHeight(TileXY(col, row + 1)) < current_tile) { - current_tile = TileHeight(TileXY(col, row + 1)); // right edge + if (TileHeight(TileXY(col, row + 1)) < current_height) { + current_height = TileHeight(TileXY(col, row + 1)); // right edge } } /* Does the height differ more than one? */ - if (TileHeight(TileXY(col, row)) >= (uint)current_tile + 2) { + TileIndex tile = TileXY(col, row); + if (TileHeight(tile) >= (uint)current_height + 2) { /* Then change the height to be no more than one */ - SetTileHeight(TileXY(col, row), current_tile + 1); + SetTileHeight(tile, current_height + 1); + /* Height was changed so now there's a chance, more likely at higher altitude, of the + * tile turning into rock. */ + if (IsInnerTile(tile) && RandomRange(max_height) <= current_height) { + MakeClear(tile, CLEAR_ROCKS, 3); + } } } } diff --git a/src/landscape.cpp b/src/landscape.cpp index d14c5142b8..147ab12e1c 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1535,7 +1535,7 @@ bool GenerateLandscape(uint8_t mode) { /* Number of steps of landscape generation */ static constexpr uint GLS_HEIGHTMAP = 3; ///< Loading a heightmap - static constexpr uint GLS_TERRAGENESIS = 5; ///< Terragenesis generator + static constexpr uint GLS_TERRAGENESIS = 4; ///< Terragenesis generator static constexpr uint GLS_ORIGINAL = 2; ///< Original generator static constexpr uint GLS_TROPIC = 12; ///< Extra steps needed for tropic landscape static constexpr uint GLS_OTHER = 0; ///< Extra steps for other landscapes diff --git a/src/tgp.cpp b/src/tgp.cpp index b0f3351541..74ee70b031 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -884,8 +884,6 @@ static void HeightMapNormalize() if (_settings_game.game_creation.variety > 0) { HeightMapCurves(_settings_game.game_creation.variety); } - - HeightMapSmoothSlopes(I2H(1)); } /** @@ -1006,8 +1004,6 @@ void GenerateTerrainPerlin() } } - IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); - FreeHeightMap(); GenerateWorldSetAbortCallback(nullptr); }