From f9aef243250989420f2c933a860edd63dff959ef Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:12:57 +0000 Subject: [PATCH] Fix: Remove unwanted river artifacts after generation This requires postponing ModifyDesertZoneAroundRiver to after river generation. --- src/landscape.cpp | 37 +++++++++++++++++++++++++++++++------ src/water.h | 1 + src/water_cmd.cpp | 14 ++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/landscape.cpp b/src/landscape.cpp index 7865895cab..3bcfcf92b7 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1023,7 +1023,8 @@ static void MakeLake(TileIndex tile, uint height_lake) for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) { TileIndex t = tile + TileOffsByDiagDir(d); if (IsWaterTile(t)) { - MakeRiverAndModifyDesertZoneAround(tile); + MakeRiver(tile, Random()); + MarkTileDirtyByTile(tile); return; } } @@ -1153,7 +1154,8 @@ static void RiverMakeWider(TileIndex tile, TileIndex origin_tile) /* If the tile upstream isn't flat, don't bother. */ if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return; - MakeRiverAndModifyDesertZoneAround(downstream_tile); + MakeRiver(downstream_tile, Random()); + MarkTileDirtyByTile(downstream_tile); } /* If upstream is dry and flat, try making it a river tile. */ @@ -1161,13 +1163,15 @@ static void RiverMakeWider(TileIndex tile, TileIndex origin_tile) /* If the tile upstream isn't flat, don't bother. */ if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return; - MakeRiverAndModifyDesertZoneAround(upstream_tile); + MakeRiver(upstream_tile, Random()); + MarkTileDirtyByTile(upstream_tile); } } /* If the tile slope matches the desired slope, add a river tile. */ if (cur_slope == desired_slope) { - MakeRiverAndModifyDesertZoneAround(tile); + MakeRiver(tile, Random()); + MarkTileDirtyByTile(tile); } } @@ -1237,7 +1241,8 @@ protected: for (PathNode *path = current.parent; path != nullptr; path = path->parent) { TileIndex tile = path->GetTile(); if (!IsWaterTile(tile)) { - MakeRiverAndModifyDesertZoneAround(tile); + MakeRiver(tile, Random()); + MarkTileDirtyByTile(tile); } } @@ -1355,7 +1360,8 @@ static std::tuple FlowRiver(TileIndex spring, TileIndex begin, uint /* We only want a lake if the river is long enough. */ DistanceManhattan(spring, lake_centre) > min_river_length) { end = lake_centre; - MakeRiverAndModifyDesertZoneAround(lake_centre); + MakeRiver(lake_centre, Random()); + MarkTileDirtyByTile(lake_centre); uint diameter = RandomRange(8) + 3; /* Run the loop twice, so artefacts from going circular in one direction get (mostly) hidden. */ @@ -1419,6 +1425,25 @@ static void CreateRivers() /* Widening rivers may have left some tiles requiring to be watered. */ ConvertGroundTilesIntoWaterTiles(); + /* Search for unwanted pockets of river artifacts to clear them of water. */ + for (const auto tile : Map::Iterate()) { + if (!IsTileType(tile, MP_WATER) || !IsRiver(tile)) continue; + + bool has_neighbour = false; + for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) { + TileIndex other_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(d)); + if (other_tile == INVALID_TILE || !IsWaterTile(other_tile)) continue; + + has_neighbour = true; + if (_settings_game.game_creation.landscape == LandscapeType::Tropic) ModifyDesertZoneAroundRiver(tile); + break; + } + + if (!has_neighbour) { + DoClearSquare(tile); + } + } + /* Run tile loop to update the ground density. */ for (uint i = 0; i != TILE_UPDATE_FREQUENCY; i++) { if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER); diff --git a/src/water.h b/src/water.h index 3bad4fba5a..4eeb1d0521 100644 --- a/src/water.h +++ b/src/water.h @@ -39,6 +39,7 @@ void MakeWaterKeepingClass(TileIndex tile, Owner o); void CheckForDockingTile(TileIndex t); void MakeRiverAndModifyDesertZoneAround(TileIndex tile); +void ModifyDesertZoneAroundRiver(TileIndex tile); static const uint RIVER_OFFSET_DESERT_DISTANCE = 5; ///< Circular tile search diameter to create non-desert around a river tile. bool IsWateredTile(TileIndex tile, Direction from); diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 45ef9d58ee..beaca87a10 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -454,6 +454,20 @@ void MakeRiverAndModifyDesertZoneAround(TileIndex tile) } } +/** + * Remove desert directly around a river tile. + * @param tile The tile to create non-desert around + */ +void ModifyDesertZoneAroundRiver(TileIndex tile) +{ + assert(IsTileType(tile, MP_WATER) && IsRiver(tile)); + + /* Remove desert directly around the river tile. */ + for (auto t : SpiralTileSequence(tile, RIVER_OFFSET_DESERT_DISTANCE)) { + if (GetTropicZone(t) == TROPICZONE_DESERT) SetTropicZone(t, TROPICZONE_NORMAL); + } +} + /** * Build a piece of canal. * @param flags type of operation