From af22ede437cded1f738b92d31d7c1b64029cb4e0 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Tue, 28 Dec 2021 23:42:06 +0200 Subject: [PATCH] Better map-to-ruleset incompatibility checks --- core/src/com/unciv/logic/map/TileInfo.kt | 3 ++- core/src/com/unciv/logic/map/TileMap.kt | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index f56164ca99..e1f373e31e 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -750,7 +750,8 @@ open class TileInfo { out.add("Terrain feature [$terrainFeature] does not exist in ruleset!") if (resource != null && !ruleset.tileResources.containsKey(resource)) out.add("Resource [$resource] does not exist in ruleset!") - if (improvement != null && !ruleset.tileImprovements.containsKey(improvement)) + if (improvement != null && !improvement!!.startsWith(TileMap.startingLocationPrefix) + && !ruleset.tileImprovements.containsKey(improvement)) out.add("Improvement [$improvement] does not exist in ruleset!") return out } diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index a66142b788..ea9337f461 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -374,11 +374,17 @@ class TileMap { * Is run before setTransients, so make do without startingLocationsByNation */ fun getRulesetIncompatibility(ruleset: Ruleset): HashSet { - setTransients(ruleset) - setStartingLocationsTransients() val rulesetIncompatibilities = HashSet() for (set in values.map { it.getRulesetIncompatibility(ruleset) }) rulesetIncompatibilities.addAll(set) + + // All the rest is to find missing nations + try { // This can fail if the map contains a resource that isn't in the ruleset, in TileInfo.tileResource + setTransients(ruleset) + } catch (ex: Exception) { + return rulesetIncompatibilities + } + setStartingLocationsTransients() for ((_, nationName) in startingLocations) { if (nationName !in ruleset.nations) rulesetIncompatibilities.add("Nation [$nationName] does not exist in ruleset!")