From 57f6c99d86224b236378d28452a1fe54c5c1ed5c Mon Sep 17 00:00:00 2001 From: GGGuenni Date: Sat, 13 Mar 2021 22:38:11 +0100 Subject: [PATCH] More terrainFeature refactors (#3694) --- core/src/com/unciv/logic/GameInfo.kt | 4 ++-- core/src/com/unciv/logic/battle/Battle.kt | 2 +- core/src/com/unciv/logic/city/CityInfo.kt | 4 ++-- core/src/com/unciv/logic/civilization/CivInfoStats.kt | 2 +- core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt | 4 ++-- core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt | 2 +- core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt | 5 ++--- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 3233982a42..daa902aa0f 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -332,8 +332,8 @@ class GameInfo { // So we remove them so the game doesn't crash when it tries to access them. private fun removeMissingModReferences() { for (tile in tileMap.values) { - if (tile.terrainFeature != null && !ruleSet.terrains.containsKey(tile.terrainFeature!!)) - tile.terrainFeature = null + for (terrainFeature in tile.terrainFeatures.filter{ !ruleSet.terrains.containsKey(it) }) + tile.terrainFeatures.remove(terrainFeature) if (tile.resource != null && !ruleSet.tileResources.containsKey(tile.resource!!)) tile.resource = null if (tile.improvement != null && !ruleSet.tileImprovements.containsKey(tile.improvement!!) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index fcee254464..5384788f4a 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -404,7 +404,7 @@ object Battle { tile.improvementInProgress = null tile.turnsToImprovement = 0 tile.roadStatus = RoadStatus.None - if (tile.isLand && !tile.isImpassible()) tile.terrainFeature = "Fallout" + if (tile.isLand && !tile.isImpassible()) tile.terrainFeatures.contains("Fallout") } for (civ in attacker.getCivInfo().getKnownCivs()) { diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 04ff34d961..fe9e2ce68d 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -116,8 +116,8 @@ class CityInfo { tryUpdateRoadStatus() val tile = getCenterTile() - if (getRuleset().tileImprovements.containsKey("Remove " + tile.terrainFeature)) - tile.terrainFeature = null + for (terrainFeature in tile.terrainFeatures.filter { getRuleset().tileImprovements.containsKey("Remove $it") }) + tile.terrainFeatures.remove(terrainFeature) tile.improvement = null tile.improvementInProgress = null diff --git a/core/src/com/unciv/logic/civilization/CivInfoStats.kt b/core/src/com/unciv/logic/civilization/CivInfoStats.kt index 8fe874b658..3080bd82d9 100644 --- a/core/src/com/unciv/logic/civilization/CivInfoStats.kt +++ b/core/src/com/unciv/logic/civilization/CivInfoStats.kt @@ -60,7 +60,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) { if (tile.isCityCenter()) continue if (ignoreHillTiles && tile.isHill()) continue - if (tile.terrainFeature in ignoredTileTypes || tile.baseTerrain in ignoredTileTypes) { + if (tile.terrainFeatures.any { it in ignoredTileTypes } || tile.baseTerrain in ignoredTileTypes) { continue } diff --git a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt index c14fbcc3c3..03158b5ecd 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt @@ -260,7 +260,7 @@ class MapGenerator(val ruleset: Ruleset) { val vegetation = (randomness.getPerlinNoise(tile, vegetationSeed, scale = 3.0, nOctaves = 1) + 1.0) / 2.0 if (vegetation <= tileMap.mapParameters.vegetationRichness) - tile.terrainFeature = Constants.vegetation.filter { ruleset.terrains[it]!!.occursOn.contains(tile.baseTerrain) }.random(randomness.RNG) + tile.terrainFeatures.add(Constants.vegetation.filter { ruleset.terrains[it]!!.occursOn.contains(tile.baseTerrain) }.random(randomness.RNG)) } } /** @@ -275,7 +275,7 @@ class MapGenerator(val ruleset: Ruleset) { val possibleFeatures = rareFeatures.filter { it.occursOn.contains(tile.baseTerrain) && (!tile.isHill() || it.occursOn.contains(Constants.hill)) } if (possibleFeatures.any()) - tile.terrainFeature = possibleFeatures.random(randomness.RNG).name + tile.terrainFeatures.add(possibleFeatures.random(randomness.RNG).name) } } } diff --git a/core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt index 5694aaea5f..9e03c925b5 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/RiverGenerator.kt @@ -22,7 +22,7 @@ class RiverGenerator(val randomness: MapGenerationRandomness){ for(tile in map.values){ if(tile.isAdjacentToRiver()){ - if(tile.baseTerrain== Constants.desert && !tile.isHill()) tile.terrainFeature= Constants.floodPlains + if(tile.baseTerrain== Constants.desert && !tile.isHill()) tile.terrainFeatures.add(Constants.floodPlains) else if(tile.baseTerrain== Constants.snow) tile.baseTerrain = Constants.tundra else if(tile.baseTerrain== Constants.tundra) tile.baseTerrain = Constants.plains tile.setTerrainTransients() diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index bd4f2edc01..0250a16374 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -367,9 +367,8 @@ object UnitActions { uncivSound = UncivSound.Chimes, action = { val unitTile = unit.getTile() - if (unitTile.terrainFeature != null && - unitTile.ruleset.tileImprovements.containsKey("Remove " + unitTile.terrainFeature)) - unitTile.terrainFeature = null // remove forest/jungle/marsh + for (terrainFeature in tile.terrainFeatures.filter{ unitTile.ruleset.tileImprovements.containsKey("Remove $it") }) + unitTile.terrainFeatures.remove(terrainFeature)// remove forest/jungle/marsh unitTile.improvement = improvementName unitTile.improvementInProgress = null unitTile.turnsToImprovement = 0