From bfaf049b6a5d6e2f660e165e6c785c229ef9a1df Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:51:52 +0100 Subject: [PATCH] Allow map editor to generate smaller than "tiny" Pangaea maps (#10894) * Allow map editor to generate tiny Pangaea maps (instead of entering an infinite loop) * rename variable & reword comment --- .../logic/map/mapgenerator/MapLandmassGenerator.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/map/mapgenerator/MapLandmassGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/MapLandmassGenerator.kt index 93b0f9bff7..4115e60692 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/MapLandmassGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/MapLandmassGenerator.kt @@ -152,7 +152,10 @@ class MapLandmassGenerator(val ruleset: Ruleset, val randomness: MapGenerationRa } private fun createPangaea(tileMap: TileMap) { - do { + val largeContinentThreshold = (tileMap.values.size / 4).coerceAtMost(25) + var retryCount = 200 // A bit much but when relevant (tiny map) an iteration is relatively cheap + + while(--retryCount >= 0) { val elevationSeed = randomness.RNG.nextInt().toDouble() for (tile in tileMap.values) { var elevation = randomness.getPerlinNoise(tile, elevationSeed) @@ -162,9 +165,11 @@ class MapLandmassGenerator(val ruleset: Ruleset, val randomness: MapGenerationRa } tileMap.assignContinents(TileMap.AssignContinentsMode.Reassign) + if ( tileMap.continentSizes.values.count { it > largeContinentThreshold } == 1 // Only one large continent + && tileMap.values.count { it.baseTerrain == waterTerrainName } <= tileMap.values.size * 0.7f // And at most 70% water + ) break waterThreshold -= 0.01 - } while (tileMap.continentSizes.values.count { it > 25 } != 1 // Multiple large continents - || tileMap.values.count { it.baseTerrain == waterTerrainName } > tileMap.values.size * 0.7f) // Over 70% water + } tileMap.assignContinents(TileMap.AssignContinentsMode.Clear) }