Show victory screen when AI wins
This commit is contained in:
parent
45080744b7
commit
8974e02290
3 changed files with 40 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.unciv.logic.civilization
|
||||
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.gamebasics.VictoryType
|
||||
|
||||
class VictoryManager {
|
||||
@Transient lateinit var civInfo: CivilizationInfo
|
||||
|
@ -27,11 +28,21 @@ class VictoryManager {
|
|||
return counter
|
||||
}
|
||||
|
||||
fun hasWonScientificVictory() = requiredSpaceshipParts.equals(currentsSpaceshipParts)
|
||||
fun spaceshipPartsRemaining() = requiredSpaceshipParts.values.sum() - currentsSpaceshipParts.values.sum()
|
||||
|
||||
fun hasWonScientificVictory() = spaceshipPartsRemaining()==0
|
||||
|
||||
fun hasWonCulturalVictory() = civInfo.policies.adoptedPolicies.count{it.endsWith("Complete")} > 3
|
||||
|
||||
fun hasWonConquestVictory() = civInfo.gameInfo.civilizations.all { it==civInfo || it.isDefeated() || it.isCityState() }
|
||||
fun hasWonDominationVictory() = civInfo.gameInfo.civilizations.all { it==civInfo || it.isDefeated() || it.isCityState() }
|
||||
|
||||
fun hasWon() = hasWonConquestVictory() || hasWonCulturalVictory() || hasWonScientificVictory()
|
||||
fun hasWonVictoryType(): VictoryType? {
|
||||
if(!civInfo.isMajorCiv()) return null
|
||||
if(hasWonDominationVictory()) return VictoryType.Domination
|
||||
if(hasWonScientificVictory()) return VictoryType.Scientific
|
||||
if(hasWonCulturalVictory()) return VictoryType.Cultural
|
||||
return null
|
||||
}
|
||||
|
||||
fun hasWon() = hasWonVictoryType()!=null
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
|||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.VictoryType
|
||||
import com.unciv.models.gamebasics.tr
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.utils.addSeparator
|
||||
|
@ -35,21 +36,35 @@ class VictoryScreen : PickerScreen() {
|
|||
|
||||
rightSideButton.isVisible=false
|
||||
|
||||
if(playerCivInfo.victoryManager.hasWonScientificVictory()){
|
||||
won("You have won a scientific victory!")
|
||||
var someoneHasWon = false
|
||||
|
||||
val playerVictoryType = playerCivInfo.victoryManager.hasWonVictoryType()
|
||||
if(playerVictoryType!=null){
|
||||
someoneHasWon=true
|
||||
when(playerVictoryType){
|
||||
VictoryType.Cultural -> wonOrLost("You have won a cultural victory!")
|
||||
VictoryType.Domination -> wonOrLost("You have won a domination victory!") // todo change translation
|
||||
VictoryType.Scientific -> wonOrLost("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!")
|
||||
for(civ in game.gameInfo.civilizations.filter { it.isMajorCiv() && it!=playerCivInfo }){
|
||||
val civVictoryType = civ.victoryManager.hasWonVictoryType()
|
||||
if(civVictoryType!=null){
|
||||
someoneHasWon=true
|
||||
val winningCivName = civ.civName
|
||||
when(civVictoryType){
|
||||
VictoryType.Cultural -> wonOrLost("[$winningCivName] has won a cultural victory!")
|
||||
VictoryType.Domination -> wonOrLost("[$winningCivName] has won a domination victory!")
|
||||
VictoryType.Scientific -> wonOrLost("[$winningCivName] has won a scientific victory!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else setDefaultCloseAction()
|
||||
if(!someoneHasWon) setDefaultCloseAction()
|
||||
}
|
||||
|
||||
|
||||
fun won(description: String) {
|
||||
fun wonOrLost(description: String) {
|
||||
descriptionLabel.setText(description.tr())
|
||||
|
||||
rightSideButton.setText("Start new game".tr())
|
||||
|
@ -180,7 +195,7 @@ class VictoryScreen : PickerScreen() {
|
|||
|
||||
val civsToPartsRemaining = majorCivs.map {
|
||||
civToSpaceshipPartsRemaining(it,
|
||||
it.victoryManager.requiredSpaceshipParts.size - it.victoryManager.currentsSpaceshipParts.size)
|
||||
it.victoryManager.spaceshipPartsRemaining())
|
||||
}
|
||||
|
||||
for (entry in civsToPartsRemaining)
|
||||
|
|
|
@ -163,7 +163,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||
nextTurnButton.y - notificationsScroll.height - 5f)
|
||||
|
||||
when {
|
||||
!gameInfo.oneMoreTurnMode && currentPlayerCiv.victoryManager.hasWon() -> game.screen = VictoryScreen()
|
||||
!gameInfo.oneMoreTurnMode && gameInfo.civilizations.any { it.victoryManager.hasWon() } -> game.screen = VictoryScreen()
|
||||
currentPlayerCiv.policies.freePolicies>0 -> game.screen = PolicyPickerScreen(currentPlayerCiv)
|
||||
currentPlayerCiv.greatPeople.freeGreatPeople>0 -> game.screen = GreatPersonPickerScreen()
|
||||
currentPlayerCiv.tradeRequests.isNotEmpty() ->{
|
||||
|
|
Loading…
Reference in a new issue