From dffd377510af79ffa26daf859c24e4c8801f0055 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 1 Apr 2020 16:09:13 +0300 Subject: [PATCH] Nuclear weapons setting moved to a per-game parameter --- .../com/unciv/logic/civilization/CivilizationInfo.kt | 8 ++++---- core/src/com/unciv/models/metadata/GameParameters.kt | 1 + core/src/com/unciv/models/ruleset/tech/Technology.kt | 7 +++---- core/src/com/unciv/models/ruleset/unit/BaseUnit.kt | 4 ++-- .../ui/newgamescreen/NewGameScreenOptionsTable.kt | 12 ++++++++---- .../worldscreen/mainmenu/WorldScreenOptionsPopup.kt | 7 ------- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index ce3dce1d..5901f939 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -166,7 +166,7 @@ class CivilizationInfo { /** * Returns a dictionary of ALL resource names, and the amount that the civ has of each */ - fun getCivResourcesByName():HashMap{ + fun getCivResourcesByName():HashMap { val hashMap = HashMap() for(resource in gameInfo.ruleSet.tileResources.keys) hashMap[resource]=0 for(entry in getCivResources()) @@ -353,9 +353,9 @@ class CivilizationInfo { tech.civInfo = this tech.setTransients() - diplomacy.values.forEach { - it.civInfo=this - it.updateHasOpenBorders() + for (diplomacyManager in diplomacy.values) { + diplomacyManager.civInfo=this + diplomacyManager.updateHasOpenBorders() } victoryManager.civInfo=this diff --git a/core/src/com/unciv/models/metadata/GameParameters.kt b/core/src/com/unciv/models/metadata/GameParameters.kt index f41f3268..33244f78 100644 --- a/core/src/com/unciv/models/metadata/GameParameters.kt +++ b/core/src/com/unciv/models/metadata/GameParameters.kt @@ -15,6 +15,7 @@ class GameParameters { // Default values are the default new game var noBarbarians = false var oneCityChallenge = false + var nuclearWeaponsEnabled = true var victoryTypes: ArrayList = VictoryType.values().toCollection(ArrayList()) // By default, all victory types var startingEra = TechEra.Ancient diff --git a/core/src/com/unciv/models/ruleset/tech/Technology.kt b/core/src/com/unciv/models/ruleset/tech/Technology.kt index 1afe2c89..596743cc 100644 --- a/core/src/com/unciv/models/ruleset/tech/Technology.kt +++ b/core/src/com/unciv/models/ruleset/tech/Technology.kt @@ -74,7 +74,7 @@ class Technology { val replacedBuildings = enabledBuildings.mapNotNull { it.replaces } enabledBuildings = enabledBuildings.filter { it.name !in replacedBuildings } - if (!UncivGame.Current.settings.nuclearWeaponEnabled) + if (civInfo.gameInfo.gameParameters.nuclearWeaponsEnabled) enabledBuildings=enabledBuildings.filterNot { it.name=="Manhattan Project" } return enabledBuildings @@ -88,9 +88,8 @@ class Technology { val replacedUnits = enabledUnits.mapNotNull { it.replaces } enabledUnits = enabledUnits.filter { it.name !in replacedUnits } - if (!UncivGame.Current.settings.nuclearWeaponEnabled) - enabledUnits=enabledUnits.filterNot { it.uniques.contains("Requires Manhattan Project") } - + if (!civInfo.gameInfo.gameParameters.nuclearWeaponsEnabled) + enabledUnits = enabledUnits.filterNot { it.uniques.contains("Requires Manhattan Project") } return enabledUnits } diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index cdfc2571..887b1980 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -137,8 +137,8 @@ class BaseUnit : INamed, IConstruction { if (obsoleteTech!=null && civInfo.tech.isResearched(obsoleteTech!!)) return "Obsolete by $obsoleteTech" if (uniqueTo!=null && uniqueTo!=civInfo.civName) return "Unique to $uniqueTo" if (civInfo.gameInfo.ruleSet.units.values.any { it.uniqueTo==civInfo.civName && it.replaces==name }) return "Our unique unit replaces this" - if (!UncivGame.Current.settings.nuclearWeaponEnabled - && (name == "Manhattan Project" || uniques.contains("Requires Manhattan Project"))) return "Disabled by setting" + if (!civInfo.gameInfo.gameParameters.nuclearWeaponsEnabled + && uniques.contains("Requires Manhattan Project")) return "Disabled by setting" if (uniques.contains("Requires Manhattan Project") && !civInfo.containsBuildingUnique("Enables nuclear weapon")) return "Requires Manhattan Project" if (requiredResource!=null && !civInfo.hasResource(requiredResource!!)) return "Consumes 1 [$requiredResource]" diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt index 2af9e575..ddd9cc37 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt @@ -41,6 +41,7 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay addVictoryTypeCheckboxes() addBarbariansCheckbox() addOneCityChallengeCheckbox() + addNuclearWeaponsCheckbox() addIsOnlineMultiplayerCheckbox() addModCheckboxes() @@ -101,15 +102,18 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay add(checkbox).colspan(2).row() } - private fun addBarbariansCheckbox() { + private fun addBarbariansCheckbox() = addCheckbox("No barbarians", newGameParameters.noBarbarians) { newGameParameters.noBarbarians = it } - } - private fun addOneCityChallengeCheckbox() { + private fun addOneCityChallengeCheckbox() = addCheckbox("One City Challenge", newGameParameters.oneCityChallenge) { newGameParameters.oneCityChallenge = it } - } + + private fun addNuclearWeaponsCheckbox() = + addCheckbox("Enable nuclear weapons", newGameParameters.nuclearWeaponsEnabled) + { newGameParameters.nuclearWeaponsEnabled = it } + private fun addIsOnlineMultiplayerCheckbox() { diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt index 46b34c21..fdfa20c6 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenOptionsPopup.kt @@ -122,13 +122,6 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen) update() } - - innerTable.add("Enable nuclear weapons".toLabel()) - addButton(innerTable, if (settings.nuclearWeaponEnabled) "Yes" else "No") { - settings.nuclearWeaponEnabled = !settings.nuclearWeaponEnabled - update() - } - addAutosaveTurnsSelectBox(innerTable) // at the moment the notification service only exists on Android