Map generation parameters are moddable, allowing players to create custom terrains for map generation!

This commit is contained in:
Yair Morgenstern 2021-02-24 20:34:01 +02:00
parent 53c919eef9
commit e464ba5328
2 changed files with 24 additions and 22 deletions

View File

@ -21,7 +21,8 @@
"food": 2, "food": 2,
"movementCost": 1, "movementCost": 1,
"defenceBonus": -0.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", "name": "Plains",
@ -30,7 +31,9 @@
"production": 1, "production": 1,
"movementCost": 1, "movementCost": 1,
"defenceBonus": -0.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", "name": "Tundra",
@ -38,14 +41,16 @@
"food": 1, "food": 1,
"movementCost": 1, "movementCost": 1,
"defenceBonus": -0.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", "name": "Desert",
"type": "Land", "type": "Land",
"movementCost": 1, "movementCost": 1,
"defenceBonus": -0.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", "name": "Lakes",
@ -75,7 +80,8 @@
"type": "Land", "type": "Land",
"movementCost": 1, "movementCost": 1,
"defenceBonus": -0.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 // Terrain features

View File

@ -6,8 +6,10 @@ import com.unciv.logic.HexMath
import com.unciv.logic.map.* import com.unciv.logic.map.*
import com.unciv.models.Counter import com.unciv.models.Counter
import com.unciv.models.ruleset.Ruleset 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.ResourceType
import com.unciv.models.ruleset.tile.TerrainType import com.unciv.models.ruleset.tile.TerrainType
import com.unciv.models.translations.equalsPlaceholderText
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.max import kotlin.math.max
import kotlin.math.pow import kotlin.math.pow
@ -213,27 +215,21 @@ class MapGenerator(val ruleset: Ruleset) {
val randomTemperature = randomness.getPerlinNoise(tile, temperatureSeed, scale = scale, nOctaves = 1) val randomTemperature = randomness.getPerlinNoise(tile, temperatureSeed, scale = scale, nOctaves = 1)
val latitudeTemperature = 1.0 - 2.0 * abs(tile.latitude) / tileMap.maxLatitude 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 temperature = abs(temperature).pow(1.0 - tileMap.mapParameters.temperatureExtremeness) * temperature.sign
tile.baseTerrain = when { val matchingTerrain = ruleset.terrains.values.firstOrNull {
temperature < -0.4 -> { it.uniques.map { Unique(it) }.any {
if (humidity < 0.5) Constants.snow it.placeholderText == "Occurs at temperature between [] and [] and humidity between [] and []"
else Constants.tundra && it.params[0].toFloat() < temperature && temperature < it.params[1].toFloat()
} && it.params[2].toFloat() < humidity && humidity < it.params[3].toFloat()
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
} }
}
if (matchingTerrain != null) tile.baseTerrain = matchingTerrain.name
else {
tile.baseTerrain = ruleset.terrains.keys.first()
println("Temperature: $temperature, humidity: $humidity")
} }
} }
} }