diff --git a/core/src/com/unciv/models/ruleset/Ruleset.kt b/core/src/com/unciv/models/ruleset/Ruleset.kt index 0fffec2db9..3e93d2b069 100644 --- a/core/src/com/unciv/models/ruleset/Ruleset.kt +++ b/core/src/com/unciv/models/ruleset/Ruleset.kt @@ -228,7 +228,7 @@ class Ruleset { } } - for(building in buildings.values) { + for (building in buildings.values) { if (building.requiredTech == null && building.cost == 0) lines += "${building.name} must either have an explicit cost or reference an existing tech!" } @@ -346,7 +346,7 @@ object RulesetCache :HashMap() { for (mod in loadedMods.sortedByDescending { it.modOptions.isBaseRuleset }) { newRuleset.add(mod) newRuleset.mods += mod.name - if(mod.modOptions.isBaseRuleset){ + if (mod.modOptions.isBaseRuleset) { newRuleset.modOptions = mod.modOptions } } diff --git a/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt index 62d0fb1022..30aa0d77a3 100644 --- a/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt @@ -199,12 +199,35 @@ class GameOptionsTable(val previousScreen: IPreviousScreen, val updatePlayerPick return@onChange } + val previousMods = gameParameters.mods.toList() + if (mod.modOptions.isBaseRuleset) - for (oldBaseRuleset in gameParameters.mods.toList()) // so we don't get concurrent modification excpetions + for (oldBaseRuleset in previousMods) // so we don't get concurrent modification excpetions if (modRulesets.firstOrNull { it.name == oldBaseRuleset }?.modOptions?.isBaseRuleset == true) gameParameters.mods.remove(oldBaseRuleset) gameParameters.mods.add(mod.name) - reloadRuleset() // This can FAIL at updateBuildingCosts if the mod is incorrectly defined! So we need to popup! + + var isCompatibleWithCurrentRuleset = true + try { + val newRuleset = RulesetCache.getComplexRuleset(gameParameters) + newRuleset.modOptions.isBaseRuleset = true + val complexModLinkErrors = newRuleset.checkModLinks() + if (complexModLinkErrors != "") isCompatibleWithCurrentRuleset = false + } catch (x: Exception) { + // This happens if a building is dependent on a tech not in the base ruleset + // because newRuleset.updateBuildingCosts() in getComplexRulset() throws an error + isCompatibleWithCurrentRuleset = false + } + + if (!isCompatibleWithCurrentRuleset) { + ToastPopup("The mod you selected is incompatible with the defined ruleset!\n\n$modLinkErrors", previousScreen as CameraStageBaseScreen) + checkBox.isChecked = false + gameParameters.mods.clear() + gameParameters.mods.addAll(previousMods) + return@onChange + } + + reloadRuleset() } else { gameParameters.mods.remove(mod.name)