mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 06:51:30 -04:00
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
This commit is contained in:
parent
f66e54a127
commit
91630cd687
@ -21,7 +21,7 @@ class UnCivGame : Game() {
|
|||||||
val viewEntireMapForDebug = false
|
val viewEntireMapForDebug = false
|
||||||
|
|
||||||
// For when you need to test something in an advanced game and don't have time to faff around
|
// 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
|
lateinit var worldScreen: WorldScreen
|
||||||
|
|
||||||
|
@ -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 difficulty="Chieftain" // difficulty is game-wide, think what would happen if 2 human players could play on diffferent difficulties?
|
||||||
var tileMap: TileMap = TileMap()
|
var tileMap: TileMap = TileMap()
|
||||||
var turns = 0
|
var turns = 0
|
||||||
|
var oneMoreTurnMode=false
|
||||||
|
|
||||||
//region pure functions
|
//region pure functions
|
||||||
fun clone(): GameInfo {
|
fun clone(): GameInfo {
|
||||||
|
@ -49,7 +49,8 @@ class CivilizationInfo {
|
|||||||
var policies = PolicyManager()
|
var policies = PolicyManager()
|
||||||
var goldenAges = GoldenAgeManager()
|
var goldenAges = GoldenAgeManager()
|
||||||
var greatPeople = GreatPersonManager()
|
var greatPeople = GreatPersonManager()
|
||||||
var scienceVictory = ScienceVictoryManager()
|
@Deprecated("As of 2.11.3") var scienceVictory = ScienceVictoryManager()
|
||||||
|
var victoryManager=VictoryManager()
|
||||||
var diplomacy = HashMap<String,DiplomacyManager>()
|
var diplomacy = HashMap<String,DiplomacyManager>()
|
||||||
var notifications = ArrayList<Notification>()
|
var notifications = ArrayList<Notification>()
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ class CivilizationInfo {
|
|||||||
toReturn.policies = policies.clone()
|
toReturn.policies = policies.clone()
|
||||||
toReturn.goldenAges = goldenAges.clone()
|
toReturn.goldenAges = goldenAges.clone()
|
||||||
toReturn.greatPeople=greatPeople.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.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName })
|
||||||
toReturn.cities = cities.map { it.clone() }
|
toReturn.cities = cities.map { it.clone() }
|
||||||
toReturn.exploredTiles.addAll(exploredTiles)
|
toReturn.exploredTiles.addAll(exploredTiles)
|
||||||
@ -306,6 +307,10 @@ class CivilizationInfo {
|
|||||||
tech.setTransients()
|
tech.setTransients()
|
||||||
diplomacy.values.forEach { it.civInfo=this}
|
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) {
|
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
|
cityInfo.civInfo = this // must be before the city's setTransients because it depends on the tilemap, that comes from the playerCivInfo
|
||||||
|
37
core/src/com/unciv/logic/civilization/VictoryManager.kt
Normal file
37
core/src/com/unciv/logic/civilization/VictoryManager.kt
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package com.unciv.logic.civilization
|
||||||
|
|
||||||
|
import com.unciv.models.Counter
|
||||||
|
|
||||||
|
class VictoryManager {
|
||||||
|
@Transient lateinit var civInfo: CivilizationInfo
|
||||||
|
|
||||||
|
var requiredSpaceshipParts = Counter<String>()
|
||||||
|
var currentsSpaceshipParts = Counter<String>()
|
||||||
|
|
||||||
|
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<String> {
|
||||||
|
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()
|
||||||
|
}
|
@ -210,7 +210,7 @@ class Building : NamedStats(), IConstruction{
|
|||||||
|
|
||||||
if ("Spaceship part" in uniques) {
|
if ("Spaceship part" in uniques) {
|
||||||
if (!civInfo.getBuildingUniques().contains("Enables construction of Spaceship parts")) return false
|
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
|
return true
|
||||||
}
|
}
|
||||||
@ -219,7 +219,7 @@ class Building : NamedStats(), IConstruction{
|
|||||||
val civInfo = construction.cityInfo.civInfo
|
val civInfo = construction.cityInfo.civInfo
|
||||||
|
|
||||||
if ("Spaceship part" in uniques) {
|
if ("Spaceship part" in uniques) {
|
||||||
civInfo.scienceVictory.currentParts.add(name, 1)
|
civInfo.victoryManager.currentsSpaceshipParts.add(name, 1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
construction.addBuilding(name)
|
construction.addBuilding(name)
|
||||||
|
@ -99,6 +99,7 @@ class NewGameScreen: PickerScreen(){
|
|||||||
val nationTables = ArrayList<NationTable>()
|
val nationTables = ArrayList<NationTable>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
setDefaultCloseAction()
|
||||||
val mainTable = Table()
|
val mainTable = Table()
|
||||||
mainTable.add(getOptionsTable())
|
mainTable.add(getOptionsTable())
|
||||||
val civPickerTable = Table().apply { defaults().pad(5f) }
|
val civPickerTable = Table().apply { defaults().pad(5f) }
|
||||||
|
@ -33,28 +33,32 @@ class VictoryScreen : PickerScreen() {
|
|||||||
|
|
||||||
rightSideButton.isVisible=false
|
rightSideButton.isVisible=false
|
||||||
|
|
||||||
if(playerCivInfo.scienceVictory.hasWon()){
|
if(playerCivInfo.victoryManager.hasWonScientificVictory()){
|
||||||
descriptionLabel.setText("You have won a scientific victory!")
|
won("You have won a scientific victory!")
|
||||||
won()
|
}
|
||||||
|
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){
|
else setDefaultCloseAction()
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun won(){
|
fun won(description: String) {
|
||||||
|
descriptionLabel.setText(description)
|
||||||
|
|
||||||
rightSideButton.setText("Start new game".tr())
|
rightSideButton.setText("Start new game".tr())
|
||||||
rightSideButton.isVisible=true
|
rightSideButton.isVisible = true
|
||||||
closeButton.isVisible=false
|
|
||||||
rightSideButton.enable()
|
rightSideButton.enable()
|
||||||
rightSideButton.onClick { UnCivGame.Current.startNewGame() }
|
rightSideButton.onClick { UnCivGame.Current.startNewGame() }
|
||||||
|
|
||||||
|
closeButton.setText("One more turn...!")
|
||||||
|
closeButton.onClick {
|
||||||
|
playerCivInfo.gameInfo.oneMoreTurnMode = true
|
||||||
|
UnCivGame.Current.setWorldScreen()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scienceVictoryColumn():Table{
|
fun scienceVictoryColumn():Table{
|
||||||
@ -62,11 +66,11 @@ class VictoryScreen : PickerScreen() {
|
|||||||
t.defaults().pad(5f)
|
t.defaults().pad(5f)
|
||||||
t.add(getMilestone("Built Apollo Program",playerCivInfo.getBuildingUniques().contains("Enables construction of Spaceship parts"))).row()
|
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 (key in victoryManager.requiredSpaceshipParts.keys)
|
||||||
for (i in 0 until scienceVictory.requiredParts[key]!!)
|
for (i in 0 until victoryManager.requiredSpaceshipParts[key]!!)
|
||||||
t.add(getMilestone(key, scienceVictory.currentParts[key]!! > i)).row() //(key, builtSpaceshipParts)
|
t.add(getMilestone(key, victoryManager.currentsSpaceshipParts[key]!! > i)).row() //(key, builtSpaceshipParts)
|
||||||
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
|
|||||||
init {
|
init {
|
||||||
val civInfo = game.gameInfo.getPlayerCivilization()
|
val civInfo = game.gameInfo.getPlayerCivilization()
|
||||||
|
|
||||||
closeButton.clearListeners() // Don't go back to the world screen, unlike the other picker screens!
|
|
||||||
closeButton.onClick {
|
closeButton.onClick {
|
||||||
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
game.screen = CityScreen(this@ConstructionPickerScreen.city)
|
||||||
dispose()
|
dispose()
|
||||||
|
@ -17,6 +17,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo) : PickerScreen() {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
val civInfo = game.gameInfo.getPlayerCivilization()
|
val civInfo = game.gameInfo.getPlayerCivilization()
|
||||||
|
setDefaultCloseAction()
|
||||||
|
|
||||||
rightSideButton.setText("Pick improvement")
|
rightSideButton.setText("Pick improvement")
|
||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
|
@ -20,10 +20,6 @@ open class PickerScreen : CameraStageBaseScreen() {
|
|||||||
internal var splitPane: SplitPane
|
internal var splitPane: SplitPane
|
||||||
|
|
||||||
init {
|
init {
|
||||||
closeButton.onClick {
|
|
||||||
game.setWorldScreen()
|
|
||||||
dispose()
|
|
||||||
}
|
|
||||||
bottomTable.add(closeButton).width(stage.width / 4)
|
bottomTable.add(closeButton).width(stage.width / 4)
|
||||||
|
|
||||||
descriptionLabel = Label("", CameraStageBaseScreen.skin)
|
descriptionLabel = Label("", CameraStageBaseScreen.skin)
|
||||||
@ -50,6 +46,13 @@ open class PickerScreen : CameraStageBaseScreen() {
|
|||||||
stage.addActor(splitPane)
|
stage.addActor(splitPane)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setDefaultCloseAction() {
|
||||||
|
closeButton.onClick {
|
||||||
|
game.setWorldScreen()
|
||||||
|
dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected fun pick(rightButtonText: String) {
|
protected fun pick(rightButtonText: String) {
|
||||||
rightSideButton.enable()
|
rightSideButton.enable()
|
||||||
rightSideButton.setText(rightButtonText)
|
rightSideButton.setText(rightButtonText)
|
||||||
|
@ -22,6 +22,7 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen(
|
|||||||
|
|
||||||
rightSideButton.setText("{Adopt policy}\r\n(".tr() + policies.storedCulture + "/" + policies.getCultureNeededForNextPolicy() + ")")
|
rightSideButton.setText("{Adopt policy}\r\n(".tr() + policies.storedCulture + "/" + policies.getCultureNeededForNextPolicy() + ")")
|
||||||
|
|
||||||
|
setDefaultCloseAction()
|
||||||
if (policies.freePolicies > 0) {
|
if (policies.freePolicies > 0) {
|
||||||
rightSideButton.setText("Adopt free policy".tr())
|
rightSideButton.setText("Adopt free policy".tr())
|
||||||
closeButton.disable()
|
closeButton.disable()
|
||||||
|
@ -16,6 +16,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
|
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
|
||||||
|
setDefaultCloseAction()
|
||||||
rightSideButton.setText("Pick promotion")
|
rightSideButton.setText("Pick promotion")
|
||||||
rightSideButton.onClick("promote") {
|
rightSideButton.onClick("promote") {
|
||||||
mapUnit.promotions.addPromotion(selectedPromotion!!.name)
|
mapUnit.promotions.addPromotion(selectedPromotion!!.name)
|
||||||
|
@ -37,6 +37,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
setDefaultCloseAction()
|
||||||
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
|
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
|
||||||
|
|
||||||
tempTechsToResearch = ArrayList(civTech.techsToResearch)
|
tempTechsToResearch = ArrayList(civTech.techsToResearch)
|
||||||
|
@ -19,6 +19,7 @@ class LoadScreen : PickerScreen() {
|
|||||||
lateinit var selectedSave:String
|
lateinit var selectedSave:String
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
setDefaultCloseAction()
|
||||||
val saveTable = Table()
|
val saveTable = Table()
|
||||||
|
|
||||||
val deleteSaveButton = TextButton("Delete save".tr(), CameraStageBaseScreen.skin)
|
val deleteSaveButton = TextButton("Delete save".tr(), CameraStageBaseScreen.skin)
|
||||||
|
@ -19,6 +19,7 @@ class SaveScreen : PickerScreen() {
|
|||||||
val textField = TextField("", skin)
|
val textField = TextField("", skin)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
setDefaultCloseAction()
|
||||||
val currentSaves = Table()
|
val currentSaves = Table()
|
||||||
|
|
||||||
currentSaves.add(Label("Current saves".tr(),skin)).row()
|
currentSaves.add(Label("Current saves".tr(),skin)).row()
|
||||||
|
@ -14,6 +14,7 @@ import com.unciv.logic.civilization.DiplomaticStatus
|
|||||||
import com.unciv.models.gamebasics.tile.ResourceType
|
import com.unciv.models.gamebasics.tile.ResourceType
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
import com.unciv.models.gamebasics.unit.UnitType
|
import com.unciv.models.gamebasics.unit.UnitType
|
||||||
|
import com.unciv.ui.VictoryScreen
|
||||||
import com.unciv.ui.pickerscreens.GreatPersonPickerScreen
|
import com.unciv.ui.pickerscreens.GreatPersonPickerScreen
|
||||||
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
||||||
import com.unciv.ui.pickerscreens.TechButton
|
import com.unciv.ui.pickerscreens.TechButton
|
||||||
@ -153,7 +154,8 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f,
|
notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f,
|
||||||
nextTurnButton.y - notificationsScroll.height - 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()
|
else if(civInfo.greatPeople.freeGreatPeople>0) game.screen = GreatPersonPickerScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user