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:
Yair Morgenstern 2018-12-25 21:59:37 +02:00
parent f66e54a127
commit 91630cd687
16 changed files with 88 additions and 30 deletions

View file

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

View file

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

View file

@ -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<String,DiplomacyManager>()
var notifications = ArrayList<Notification>()
@ -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

View 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()
}

View file

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

View file

@ -99,6 +99,7 @@ class NewGameScreen: PickerScreen(){
val nationTables = ArrayList<NationTable>()
init {
setDefaultCloseAction()
val mainTable = Table()
mainTable.add(getOptionsTable())
val civPickerTable = Table().apply { defaults().pad(5f) }

View file

@ -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()
else setDefaultCloseAction()
}
if(playerCivInfo.gameInfo.civilizations.all { it.isPlayerCivilization() || it.isDefeated() }){
descriptionLabel.setText("You have won a conquest victory!")
won()
}
}
fun won(description: String) {
descriptionLabel.setText(description)
fun won(){
rightSideButton.setText("Start new game".tr())
rightSideButton.isVisible = true
closeButton.isVisible=false
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
}

View file

@ -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()

View file

@ -17,6 +17,7 @@ class ImprovementPickerScreen(tileInfo: TileInfo) : PickerScreen() {
init {
val civInfo = game.gameInfo.getPlayerCivilization()
setDefaultCloseAction()
rightSideButton.setText("Pick improvement")
rightSideButton.onClick {

View file

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

View file

@ -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()

View file

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

View file

@ -37,6 +37,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen()
}
init {
setDefaultCloseAction()
onBackButtonClicked { UnCivGame.Current.setWorldScreen(); dispose() }
tempTechsToResearch = ArrayList(civTech.techsToResearch)

View file

@ -19,6 +19,7 @@ class LoadScreen : PickerScreen() {
lateinit var selectedSave:String
init {
setDefaultCloseAction()
val saveTable = Table()
val deleteSaveButton = TextButton("Delete save".tr(), CameraStageBaseScreen.skin)

View file

@ -19,6 +19,7 @@ class SaveScreen : PickerScreen() {
val textField = TextField("", skin)
init {
setDefaultCloseAction()
val currentSaves = Table()
currentSaves.add(Label("Current saves".tr(),skin)).row()

View file

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