1
0
Fork 0

Feature: Place rocks on "too steep" tiles when fixing slopes. (#13462)

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.
pull/13270/head
Peter Nelson 2025-02-09 18:37:25 +00:00 committed by GitHub
parent ba20ea5d18
commit 588597805d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 19 deletions

View File

@ -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;

View File

@ -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);
}
}
}
}

View File

@ -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

View File

@ -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);
}