From e464ba53289a1de05b53be3942d40234f91bb598 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 24 Feb 2021 20:34:01 +0200 Subject: [PATCH] Map generation parameters are moddable, allowing players to create custom terrains for map generation! --- .../jsons/Civ V - Vanilla/Terrains.json | 16 ++++++---- .../logic/map/mapgenerator/MapGenerator.kt | 30 ++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Terrains.json b/android/assets/jsons/Civ V - Vanilla/Terrains.json index f3f8f2547f..1b179fc039 100644 --- a/android/assets/jsons/Civ V - Vanilla/Terrains.json +++ b/android/assets/jsons/Civ V - Vanilla/Terrains.json @@ -21,7 +21,8 @@ "food": 2, "movementCost": 1, "defenceBonus": -0.1, - "RGB": [97,171,58] + "RGB": [97,171,58], + "uniques": ["Occurs at temperature between [-0.4] and [0.8] and humidity between [0.5] and [1]"] }, { "name": "Plains", @@ -30,7 +31,9 @@ "production": 1, "movementCost": 1, "defenceBonus": -0.1, - "RGB": [168,185,102] + "RGB": [168,185,102], + "uniques": ["Occurs at temperature between [-0.4] and [0.8] and humidity between [0] and [0.5]", + "Occurs at temperature between [0.8] and [1] and humidity between [0.7] and [1]"] }, { "name": "Tundra", @@ -38,14 +41,16 @@ "food": 1, "movementCost": 1, "defenceBonus": -0.1, - "RGB": [189,204,191] + "RGB": [189,204,191], + "uniques": ["Occurs at temperature between [-1] and [-0.4] and humidity between [0.5] and [1]"] }, { "name": "Desert", "type": "Land", "movementCost": 1, "defenceBonus": -0.1, - "RGB": [ 230, 230, 113] + "RGB": [ 230, 230, 113], + "uniques": ["Occurs at temperature between [0.8] and [1] and humidity between [0] and [0.7]"] }, { "name": "Lakes", @@ -75,7 +80,8 @@ "type": "Land", "movementCost": 1, "defenceBonus": -0.1, - "RGB": [231, 242, 249] + "RGB": [231, 242, 249], + "uniques": ["Occurs at temperature between [-1] and [-0.4] and humidity between [0] and [0.5]"] }, // Terrain features diff --git a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt index c4c343836e..7a4cd0e2ba 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt @@ -6,8 +6,10 @@ import com.unciv.logic.HexMath import com.unciv.logic.map.* import com.unciv.models.Counter import com.unciv.models.ruleset.Ruleset +import com.unciv.models.ruleset.Unique import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.TerrainType +import com.unciv.models.translations.equalsPlaceholderText import kotlin.math.abs import kotlin.math.max import kotlin.math.pow @@ -213,27 +215,21 @@ class MapGenerator(val ruleset: Ruleset) { val randomTemperature = randomness.getPerlinNoise(tile, temperatureSeed, scale = scale, nOctaves = 1) val latitudeTemperature = 1.0 - 2.0 * abs(tile.latitude) / tileMap.maxLatitude - var temperature = ((5.0 * latitudeTemperature + randomTemperature) / 6.0) + var temperature = (5.0 * latitudeTemperature + randomTemperature) / 6.0 temperature = abs(temperature).pow(1.0 - tileMap.mapParameters.temperatureExtremeness) * temperature.sign - tile.baseTerrain = when { - temperature < -0.4 -> { - if (humidity < 0.5) Constants.snow - else Constants.tundra - } - temperature < 0.8 -> { - if (humidity < 0.5) Constants.plains - else Constants.grassland - } - temperature <= 1.0 -> { - if (humidity < 0.7) Constants.desert - else Constants.plains - } - else -> { - println(temperature) - Constants.lakes + val matchingTerrain = ruleset.terrains.values.firstOrNull { + it.uniques.map { Unique(it) }.any { + it.placeholderText == "Occurs at temperature between [] and [] and humidity between [] and []" + && it.params[0].toFloat() < temperature && temperature < it.params[1].toFloat() + && it.params[2].toFloat() < humidity && humidity < it.params[3].toFloat() } + } + if (matchingTerrain != null) tile.baseTerrain = matchingTerrain.name + else { + tile.baseTerrain = ruleset.terrains.keys.first() + println("Temperature: $temperature, humidity: $humidity") } } }