From 92b71102e1e0af4d0fed816b3f35dc1fdb157a6b Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 21 Sep 2023 14:37:21 +0300 Subject: [PATCH] Fixed mod compatibility autochanges Tested by forcing a new Deciv game to load with a much older mod version --- core/src/com/unciv/logic/BackwardCompatibility.kt | 2 +- core/src/com/unciv/logic/automation/unit/UnitAutomation.kt | 4 ++-- core/src/com/unciv/logic/map/tile/Tile.kt | 2 +- core/src/com/unciv/ui/images/ImageGetter.kt | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/logic/BackwardCompatibility.kt b/core/src/com/unciv/logic/BackwardCompatibility.kt index 9558d86bc7..e2de48aacc 100644 --- a/core/src/com/unciv/logic/BackwardCompatibility.kt +++ b/core/src/com/unciv/logic/BackwardCompatibility.kt @@ -39,7 +39,7 @@ object BackwardCompatibility { private fun GameInfo.removeUnitsAndPromotions() { for (tile in tileMap.values) { - for (unit in tile.getUnits()) { + for (unit in tile.getUnits().toList()) { if (!ruleset.units.containsKey(unit.name)) tile.removeUnit(unit) for (promotion in unit.promotions.promotions.toList()) diff --git a/core/src/com/unciv/logic/automation/unit/UnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/UnitAutomation.kt index a438d1a3ee..319a5a8496 100644 --- a/core/src/com/unciv/logic/automation/unit/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/UnitAutomation.kt @@ -564,8 +564,8 @@ object UnitAutomation { // Our main attack target is the closest city, but we're fine with deviating from that a bit var enemyCitiesByPriority = closestEnemyCity.civ.cities .associateWith { it.getCenterTile().aerialDistanceTo(closestEnemyCity.getCenterTile()) } - .filterNot { it.value > 10 } // anything 10 tiles away from the target is irrelevant - .asSequence().sortedBy { it.value }.map { it.key } // sort the list by closeness to target - least is best! + .asSequence().filterNot { it.value > 10 } // anything 10 tiles away from the target is irrelevant + .sortedBy { it.value }.map { it.key } // sort the list by closeness to target - least is best! if (unit.baseUnit.isRanged()) // ranged units don't harm capturable cities, waste of a turn enemyCitiesByPriority = enemyCitiesByPriority.filterNot { it.health == 1 } diff --git a/core/src/com/unciv/logic/map/tile/Tile.kt b/core/src/com/unciv/logic/map/tile/Tile.kt index d0d65d0efc..3810955aec 100644 --- a/core/src/com/unciv/logic/map/tile/Tile.kt +++ b/core/src/com/unciv/logic/map/tile/Tile.kt @@ -883,7 +883,7 @@ open class Tile : IsPartOfGameInfoSerialization { if (resource != null && resource !in ruleset.tileResources) resource = null if (improvement != null && improvement !in ruleset.tileImprovements) - removeImprovement() + improvement = null } /** If the unit isn't in the ruleset we can't even know what type of unit this is! So check each place diff --git a/core/src/com/unciv/ui/images/ImageGetter.kt b/core/src/com/unciv/ui/images/ImageGetter.kt index 104121566e..8c0db9b72c 100644 --- a/core/src/com/unciv/ui/images/ImageGetter.kt +++ b/core/src/com/unciv/ui/images/ImageGetter.kt @@ -62,6 +62,8 @@ object ImageGetter { atlases["game"] = atlas } + + /** Required every time the ruleset changes, in order to load mod-specific images */ fun setNewRuleset(ruleset: Ruleset) { ImageGetter.ruleset = ruleset