Better map-to-ruleset incompatibility checks

This commit is contained in:
yairm210
2021-12-28 23:42:06 +02:00
parent 2ea97edb92
commit af22ede437
2 changed files with 10 additions and 3 deletions

View File

@ -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
}

View File

@ -374,11 +374,17 @@ class TileMap {
* Is run before setTransients, so make do without startingLocationsByNation
*/
fun getRulesetIncompatibility(ruleset: Ruleset): HashSet<String> {
setTransients(ruleset)
setStartingLocationsTransients()
val rulesetIncompatibilities = HashSet<String>()
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!")