From 91630cd68792801c34eb7a1b542c5852c6927dce Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 25 Dec 2018 21:59:37 +0200 Subject: [PATCH] Victory condition logic moved to VictoryManager Victory screen now pops up when you fulfill the victory conditions =D Added "One more turn" mode, if people want to play after the victory conditions have been fulfilled --- core/src/com/unciv/UnCivGame.kt | 2 +- core/src/com/unciv/logic/GameInfo.kt | 1 + .../logic/civilization/CivilizationInfo.kt | 9 +++- .../logic/civilization/VictoryManager.kt | 37 ++++++++++++++++ .../com/unciv/models/gamebasics/Building.kt | 4 +- core/src/com/unciv/ui/NewGameScreen.kt | 1 + core/src/com/unciv/ui/VictoryScreen.kt | 42 ++++++++++--------- .../pickerscreens/ConstructionPickerScreen.kt | 1 - .../pickerscreens/ImprovementPickerScreen.kt | 1 + .../unciv/ui/pickerscreens/PickerScreen.kt | 11 +++-- .../ui/pickerscreens/PolicyPickerScreen.kt | 1 + .../ui/pickerscreens/PromotionPickerScreen.kt | 1 + .../ui/pickerscreens/TechPickerScreen.kt | 1 + core/src/com/unciv/ui/saves/LoadScreen.kt | 1 + core/src/com/unciv/ui/saves/SaveScreen.kt | 1 + .../com/unciv/ui/worldscreen/WorldScreen.kt | 4 +- 16 files changed, 88 insertions(+), 30 deletions(-) create mode 100644 core/src/com/unciv/logic/civilization/VictoryManager.kt diff --git a/core/src/com/unciv/UnCivGame.kt b/core/src/com/unciv/UnCivGame.kt index fb5df00b86..d42f058e89 100644 --- a/core/src/com/unciv/UnCivGame.kt +++ b/core/src/com/unciv/UnCivGame.kt @@ -21,7 +21,7 @@ class UnCivGame : Game() { val viewEntireMapForDebug = false // For when you need to test something in an advanced game and don't have time to faff around - val superchargedForDebug = false + val superchargedForDebug = true lateinit var worldScreen: WorldScreen diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 310bb90b4d..650a2abc5e 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -18,6 +18,7 @@ class GameInfo { var difficulty="Chieftain" // difficulty is game-wide, think what would happen if 2 human players could play on diffferent difficulties? var tileMap: TileMap = TileMap() var turns = 0 + var oneMoreTurnMode=false //region pure functions fun clone(): GameInfo { diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 0e03139a10..a99518d298 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -49,7 +49,8 @@ class CivilizationInfo { var policies = PolicyManager() var goldenAges = GoldenAgeManager() var greatPeople = GreatPersonManager() - var scienceVictory = ScienceVictoryManager() + @Deprecated("As of 2.11.3") var scienceVictory = ScienceVictoryManager() + var victoryManager=VictoryManager() var diplomacy = HashMap() var notifications = ArrayList() @@ -76,7 +77,7 @@ class CivilizationInfo { toReturn.policies = policies.clone() toReturn.goldenAges = goldenAges.clone() toReturn.greatPeople=greatPeople.clone() - toReturn.scienceVictory = scienceVictory.clone() + toReturn.victoryManager=victoryManager.clone() toReturn.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName }) toReturn.cities = cities.map { it.clone() } toReturn.exploredTiles.addAll(exploredTiles) @@ -306,6 +307,10 @@ class CivilizationInfo { tech.setTransients() diplomacy.values.forEach { it.civInfo=this} + victoryManager.civInfo=this + if(victoryManager.currentsSpaceshipParts.values.sum() == 0 + && scienceVictory.currentParts.values.sum()>0) + victoryManager.currentsSpaceshipParts = scienceVictory.currentParts for (cityInfo in cities) { cityInfo.civInfo = this // must be before the city's setTransients because it depends on the tilemap, that comes from the playerCivInfo diff --git a/core/src/com/unciv/logic/civilization/VictoryManager.kt b/core/src/com/unciv/logic/civilization/VictoryManager.kt new file mode 100644 index 0000000000..bb71b92071 --- /dev/null +++ b/core/src/com/unciv/logic/civilization/VictoryManager.kt @@ -0,0 +1,37 @@ +package com.unciv.logic.civilization + +import com.unciv.models.Counter + +class VictoryManager { + @Transient lateinit var civInfo: CivilizationInfo + + var requiredSpaceshipParts = Counter() + var currentsSpaceshipParts = Counter() + + init { + requiredSpaceshipParts.add("SS Booster", 3) + requiredSpaceshipParts.add("SS Cockpit", 1) + requiredSpaceshipParts.add("SS Engine", 1) + requiredSpaceshipParts.add("SS Stasis Chamber", 1) + } + + fun clone(): VictoryManager { + val toReturn = VictoryManager() + toReturn.currentsSpaceshipParts.putAll(currentsSpaceshipParts) + return toReturn + } + + fun unconstructedSpaceshipParts(): Counter { + val counter = requiredSpaceshipParts.clone() + counter.remove(currentsSpaceshipParts) + return counter + } + + fun hasWonScientificVictory() = requiredSpaceshipParts.equals(currentsSpaceshipParts) + + fun hasWonCulturalVictory() = civInfo.policies.adoptedPolicies.count{it.endsWith("Complete")} > 3 + + fun hasWonConquestVictory() = civInfo.gameInfo.civilizations.all { it.isPlayerCivilization() || it.isDefeated() } + + fun hasWon() = hasWonConquestVictory() || hasWonCulturalVictory() || hasWonScientificVictory() +} diff --git a/core/src/com/unciv/models/gamebasics/Building.kt b/core/src/com/unciv/models/gamebasics/Building.kt index e29f883d3a..d9b9ba2631 100644 --- a/core/src/com/unciv/models/gamebasics/Building.kt +++ b/core/src/com/unciv/models/gamebasics/Building.kt @@ -210,7 +210,7 @@ class Building : NamedStats(), IConstruction{ if ("Spaceship part" in uniques) { if (!civInfo.getBuildingUniques().contains("Enables construction of Spaceship parts")) return false - if (civInfo.scienceVictory.unconstructedParts()[name] == 0) return false // Don't need to build any more of these! + if (civInfo.victoryManager.unconstructedSpaceshipParts()[name] == 0) return false // Don't need to build any more of these! } return true } @@ -219,7 +219,7 @@ class Building : NamedStats(), IConstruction{ val civInfo = construction.cityInfo.civInfo if ("Spaceship part" in uniques) { - civInfo.scienceVictory.currentParts.add(name, 1) + civInfo.victoryManager.currentsSpaceshipParts.add(name, 1) return } construction.addBuilding(name) diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index 0b12922e76..9443cfc11e 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -99,6 +99,7 @@ class NewGameScreen: PickerScreen(){ val nationTables = ArrayList() init { + setDefaultCloseAction() val mainTable = Table() mainTable.add(getOptionsTable()) val civPickerTable = Table().apply { defaults().pad(5f) } diff --git a/core/src/com/unciv/ui/VictoryScreen.kt b/core/src/com/unciv/ui/VictoryScreen.kt index 9783ee412c..89ebd1455c 100644 --- a/core/src/com/unciv/ui/VictoryScreen.kt +++ b/core/src/com/unciv/ui/VictoryScreen.kt @@ -33,28 +33,32 @@ class VictoryScreen : PickerScreen() { rightSideButton.isVisible=false - if(playerCivInfo.scienceVictory.hasWon()){ - descriptionLabel.setText("You have won a scientific victory!") - won() + if(playerCivInfo.victoryManager.hasWonScientificVictory()){ + won("You have won a scientific victory!") + } + else if(playerCivInfo.victoryManager.hasWonCulturalVictory()){ + won("You have won a cultural victory!") + } + else if(playerCivInfo.victoryManager.hasWonConquestVictory()){ + won("You have won a conquest victory!") } - if(playerCivInfo.policies.adoptedPolicies.count{it.endsWith("Complete")} > 3){ - descriptionLabel.setText("You have won a cultural victory!") - won() - } - - if(playerCivInfo.gameInfo.civilizations.all { it.isPlayerCivilization() || it.isDefeated() }){ - descriptionLabel.setText("You have won a conquest victory!") - won() - } + else setDefaultCloseAction() } - fun won(){ + fun won(description: String) { + descriptionLabel.setText(description) + rightSideButton.setText("Start new game".tr()) - rightSideButton.isVisible=true - closeButton.isVisible=false + rightSideButton.isVisible = true rightSideButton.enable() rightSideButton.onClick { UnCivGame.Current.startNewGame() } + + closeButton.setText("One more turn...!") + closeButton.onClick { + playerCivInfo.gameInfo.oneMoreTurnMode = true + UnCivGame.Current.setWorldScreen() + } } fun scienceVictoryColumn():Table{ @@ -62,11 +66,11 @@ class VictoryScreen : PickerScreen() { t.defaults().pad(5f) t.add(getMilestone("Built Apollo Program",playerCivInfo.getBuildingUniques().contains("Enables construction of Spaceship parts"))).row() - val scienceVictory = playerCivInfo.scienceVictory + val victoryManager= playerCivInfo.victoryManager - for (key in scienceVictory.requiredParts.keys) - for (i in 0 until scienceVictory.requiredParts[key]!!) - t.add(getMilestone(key, scienceVictory.currentParts[key]!! > i)).row() //(key, builtSpaceshipParts) + for (key in victoryManager.requiredSpaceshipParts.keys) + for (i in 0 until victoryManager.requiredSpaceshipParts[key]!!) + t.add(getMilestone(key, victoryManager.currentsSpaceshipParts[key]!! > i)).row() //(key, builtSpaceshipParts) return t } diff --git a/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt index d7d1b9c989..c570ece46f 100644 --- a/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt @@ -33,7 +33,6 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() { init { val civInfo = game.gameInfo.getPlayerCivilization() - closeButton.clearListeners() // Don't go back to the world screen, unlike the other picker screens! closeButton.onClick { game.screen = CityScreen(this@ConstructionPickerScreen.city) dispose() diff --git a/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt index 350ec79a59..ce121e4d78 100644 --- a/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ImprovementPickerScreen.kt @@ -17,6 +17,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo) : PickerScreen() { init { val civInfo = game.gameInfo.getPlayerCivilization() + setDefaultCloseAction() rightSideButton.setText("Pick improvement") rightSideButton.onClick { diff --git a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt index 8ec10554c6..bcdfe9863c 100644 --- a/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PickerScreen.kt @@ -20,10 +20,6 @@ open class PickerScreen : CameraStageBaseScreen() { internal var splitPane: SplitPane init { - closeButton.onClick { - game.setWorldScreen() - dispose() - } bottomTable.add(closeButton).width(stage.width / 4) descriptionLabel = Label("", CameraStageBaseScreen.skin) @@ -50,6 +46,13 @@ open class PickerScreen : CameraStageBaseScreen() { stage.addActor(splitPane) } + fun setDefaultCloseAction() { + closeButton.onClick { + game.setWorldScreen() + dispose() + } + } + protected fun pick(rightButtonText: String) { rightSideButton.enable() rightSideButton.setText(rightButtonText) diff --git a/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt index f07414c592..3fe5fccbe0 100644 --- a/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt @@ -22,6 +22,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen( rightSideButton.setText("{Adopt policy}\r\n(".tr() + policies.storedCulture + "/" + policies.getCultureNeededForNextPolicy() + ")") + setDefaultCloseAction() if (policies.freePolicies > 0) { rightSideButton.setText("Adopt free policy".tr()) closeButton.disable() diff --git a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt index 7bf7a4118b..cea885d0a4 100644 --- a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt @@ -16,6 +16,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() { init { onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } + setDefaultCloseAction() rightSideButton.setText("Pick promotion") rightSideButton.onClick("promote") { mapUnit.promotions.addPromotion(selectedPromotion!!.name) diff --git a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt index 947e01094c..3db4b0e11d 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt @@ -37,6 +37,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen() } init { + setDefaultCloseAction() onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() } tempTechsToResearch = ArrayList(civTech.techsToResearch) diff --git a/core/src/com/unciv/ui/saves/LoadScreen.kt b/core/src/com/unciv/ui/saves/LoadScreen.kt index 468017025e..2f5dcee3b0 100644 --- a/core/src/com/unciv/ui/saves/LoadScreen.kt +++ b/core/src/com/unciv/ui/saves/LoadScreen.kt @@ -19,6 +19,7 @@ class LoadScreen : PickerScreen() { lateinit var selectedSave:String init { + setDefaultCloseAction() val saveTable = Table() val deleteSaveButton = TextButton("Delete save".tr(), CameraStageBaseScreen.skin) diff --git a/core/src/com/unciv/ui/saves/SaveScreen.kt b/core/src/com/unciv/ui/saves/SaveScreen.kt index 909ba64a5c..656ac314b3 100644 --- a/core/src/com/unciv/ui/saves/SaveScreen.kt +++ b/core/src/com/unciv/ui/saves/SaveScreen.kt @@ -19,6 +19,7 @@ class SaveScreen : PickerScreen() { val textField = TextField("", skin) init { + setDefaultCloseAction() val currentSaves = Table() currentSaves.add(Label("Current saves".tr(),skin)).row() diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 0cf74ef0d2..31072a0581 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -14,6 +14,7 @@ import com.unciv.logic.civilization.DiplomaticStatus import com.unciv.models.gamebasics.tile.ResourceType import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.unit.UnitType +import com.unciv.ui.VictoryScreen import com.unciv.ui.pickerscreens.GreatPersonPickerScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.pickerscreens.TechButton @@ -153,7 +154,8 @@ class WorldScreen : CameraStageBaseScreen() { notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f, nextTurnButton.y - notificationsScroll.height - 5f) - if(civInfo.policies.freePolicies>0) game.screen = PolicyPickerScreen(civInfo) + if(!gameInfo.oneMoreTurnMode && civInfo.victoryManager.hasWon()) game.screen = VictoryScreen() + else if(civInfo.policies.freePolicies>0) game.screen = PolicyPickerScreen(civInfo) else if(civInfo.greatPeople.freeGreatPeople>0) game.screen = GreatPersonPickerScreen() }