mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Map generation parameters are moddable, allowing players to create custom terrains for map generation!
This commit is contained in:
parent
53c919eef9
commit
e464ba5328
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user