From 3f3dd0193e18e311c1ec32a0ae8c15a63e42ea78 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 16 Jun 2019 19:51:12 +0300 Subject: [PATCH] Resolved #251 - Choose specific victory conditions on new game Victory screen no longer 'reveals' civs you haven't met --- .../com/unciv/logic/automation/Automation.kt | 2 +- .../logic/automation/NextTurnAutomation.kt | 10 ++-- .../logic/civilization/CivilizationInfo.kt | 5 ++ .../unciv/logic/civilization/PolicyManager.kt | 2 +- .../logic/civilization/VictoryManager.kt | 9 ++- core/src/com/unciv/ui/NewGameScreen.kt | 56 +++++++++---------- core/src/com/unciv/ui/VictoryScreen.kt | 49 +++++++++------- .../unciv/ui/utils/CameraStageBaseScreen.kt | 1 + 8 files changed, 76 insertions(+), 58 deletions(-) diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index a15c7a1c7f..fa56c0b584 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -100,7 +100,7 @@ class Automation { && cityInfo.getTiles().any { it.isWater && it.hasViewableResource(cityInfo.civInfo) && it.improvement == null } val isAtWar = cityInfo.civInfo.isAtWar() - val preferredVictoryType = cityInfo.civInfo.getNation().preferredVictoryType + val preferredVictoryType = cityInfo.civInfo.victoryType() data class ConstructionChoice(val choice:String, var choiceModifier:Float){ val remainingWork:Int = getRemainingWork(choice) diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index c914aee75f..36563a2984 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -146,7 +146,7 @@ class NextTurnAutomation{ val adoptablePolicies = GameBasics.PolicyBranches.values.flatMap { it.policies.union(listOf(it)) } .filter { civInfo.policies.isAdoptable(it) } - val preferredVictoryType = civInfo.getNation().preferredVictoryType + val preferredVictoryType = civInfo.victoryType() val policyBranchPriority = when(preferredVictoryType) { VictoryType.Cultural -> listOf("Piety", "Freedom", "Tradition", "Rationalism") @@ -243,7 +243,7 @@ class NextTurnAutomation{ for (enemy in enemiesCiv) { val enemiesStrength = Automation().evaluteCombatStrength(enemy) - if (civInfo.getNation().preferredVictoryType!=VictoryType.Cultural + if (civInfo.victoryType()!=VictoryType.Cultural && enemiesStrength < ourCombatStrength*2 ) { continue //We're losing, but can still fight. Refuse peace. } @@ -265,7 +265,7 @@ class NextTurnAutomation{ if (enemy.isPlayerCivilization()) enemy.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse())) else { - if (enemy.getNation().preferredVictoryType!=VictoryType.Cultural + if (enemy.victoryType()!=VictoryType.Cultural && enemy.getCivUnits().filter { !it.type.isCivilian() }.size > enemy.cities.size && enemy.happiness > 0) { continue //enemy AI has too large army and happiness. It continues to fight for profit. @@ -296,7 +296,7 @@ class NextTurnAutomation{ private fun declareWar(civInfo: CivilizationInfo) { if (civInfo.isCityState()) return - if(civInfo.getNation().preferredVictoryType==VictoryType.Cultural) + if (civInfo.victoryType()==VictoryType.Cultural) return if (civInfo.cities.isNotEmpty() && civInfo.diplomacy.isNotEmpty()) { @@ -369,7 +369,7 @@ class NextTurnAutomation{ private fun trainSettler(civInfo: CivilizationInfo) { if(civInfo.isCityState()) return if(civInfo.isAtWar()) return // don't train settlers when you could be training troops. - if(civInfo.getNation().preferredVictoryType==VictoryType.Cultural && civInfo.cities.size >3) return + if(civInfo.victoryType()==VictoryType.Cultural && civInfo.cities.size >3) return if (civInfo.cities.any() && civInfo.happiness > civInfo.cities.size + 5 && civInfo.getCivUnits().none { it.name == Constants.settler } diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 3263293588..5bbb9e8cc5 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -138,6 +138,11 @@ class CivilizationInfo { fun getCityStateType(): CityStateType = getNation().cityStateType!! fun isMajorCiv() = !isBarbarianCivilization() && !isCityState() + fun victoryType(): VictoryType { + val victoryType = getNation().preferredVictoryType + if(gameInfo.gameParameters.victoryTypes.contains(victoryType)) return victoryType + else return VictoryType.Neutral + } fun getStatsForNextTurn():Stats = getStatMapForNextTurn().values.toList().reduce{a,b->a+b} diff --git a/core/src/com/unciv/logic/civilization/PolicyManager.kt b/core/src/com/unciv/logic/civilization/PolicyManager.kt index 1ad274d06b..76188d9f58 100644 --- a/core/src/com/unciv/logic/civilization/PolicyManager.kt +++ b/core/src/com/unciv/logic/civilization/PolicyManager.kt @@ -79,7 +79,7 @@ class PolicyManager { "Liberty Complete" -> { if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++ else { - val preferredVictoryType = civInfo.getNation().preferredVictoryType + val preferredVictoryType = civInfo.victoryType() val greatPerson = when(preferredVictoryType) { VictoryType.Cultural -> "Great Artist" VictoryType.Scientific -> "Great Scientist" diff --git a/core/src/com/unciv/logic/civilization/VictoryManager.kt b/core/src/com/unciv/logic/civilization/VictoryManager.kt index c7970fa911..44e00f3213 100644 --- a/core/src/com/unciv/logic/civilization/VictoryManager.kt +++ b/core/src/com/unciv/logic/civilization/VictoryManager.kt @@ -30,11 +30,14 @@ class VictoryManager { fun spaceshipPartsRemaining() = requiredSpaceshipParts.values.sum() - currentsSpaceshipParts.values.sum() - fun hasWonScientificVictory() = spaceshipPartsRemaining()==0 + fun hasWonScientificVictory() = civInfo.gameInfo.gameParameters.victoryTypes.contains(VictoryType.Scientific) + && spaceshipPartsRemaining()==0 - fun hasWonCulturalVictory() = civInfo.policies.adoptedPolicies.count{it.endsWith("Complete")} > 3 + fun hasWonCulturalVictory() = civInfo.gameInfo.gameParameters.victoryTypes.contains(VictoryType.Cultural) + && civInfo.policies.adoptedPolicies.count{it.endsWith("Complete")} > 3 - fun hasWonDominationVictory() = civInfo.gameInfo.civilizations.all { it==civInfo || it.isDefeated() || it.isCityState() } + fun hasWonDominationVictory() = civInfo.gameInfo.gameParameters.victoryTypes.contains(VictoryType.Domination) + && civInfo.gameInfo.civilizations.all { it==civInfo || it.isDefeated() || it.isCityState() } fun hasWonVictoryType(): VictoryType? { if(!civInfo.isMajorCiv()) return null diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index 763f8ae30b..62cc880aa4 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -77,15 +77,7 @@ class NewGameScreen: PickerScreen(){ addNumberOfHumansAndEnemies(newGameOptionsTable) addDifficultySelectBox(newGameOptionsTable) addVictoryTypeCheckboxes(newGameOptionsTable) - - val noBarbariansCheckbox = CheckBox("No barbarians".tr(),skin) - noBarbariansCheckbox.isChecked=newGameParameters.noBarbarians - noBarbariansCheckbox.addListener(object : ChangeListener() { - override fun changed(event: ChangeEvent?, actor: Actor?) { - newGameParameters.noBarbarians = noBarbariansCheckbox.isChecked - } - }) - newGameOptionsTable.add(noBarbariansCheckbox).colspan(2).row() + addBarbariansCheckbox(newGameOptionsTable) rightSideButton.enable() @@ -112,6 +104,17 @@ class NewGameScreen: PickerScreen(){ return newGameOptionsTable } + private fun addBarbariansCheckbox(newGameOptionsTable: Table) { + val noBarbariansCheckbox = CheckBox("No barbarians".tr(), skin) + noBarbariansCheckbox.isChecked = newGameParameters.noBarbarians + noBarbariansCheckbox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + newGameParameters.noBarbarians = noBarbariansCheckbox.isChecked + } + }) + newGameOptionsTable.add(noBarbariansCheckbox).colspan(2).row() + } + private fun addMapTypeSizeAndFile(newGameOptionsTable: Table) { newGameOptionsTable.add("{Map type}:".tr()) val mapTypes = LinkedHashMap() @@ -171,14 +174,14 @@ class NewGameScreen: PickerScreen(){ newGameOptionsTable.add("{Number of enemies}:".tr()) val enemiesSelectBox = SelectBox(skin) val enemiesArray = Array() - (0..GameBasics.Nations.filter{ !it.value.isCityState() }.size - 1).forEach { enemiesArray.add(it) } + for (enemyNumber in 0 until GameBasics.Nations.filter{ !it.value.isCityState() }.size) { + enemiesArray.add(enemyNumber) + } enemiesSelectBox.items = enemiesArray enemiesSelectBox.selected = newGameParameters.numberOfEnemies newGameOptionsTable.add(enemiesSelectBox).pad(10f).row() - // Todo - re-enable this when city states are fit for players addCityStatesSelectBox(newGameOptionsTable) -// newGameParameters.numberOfCityStates = 0 humanPlayers.addListener(object : ChangeListener() { override fun changed(event: ChangeEvent?, actor: Actor?) { @@ -232,31 +235,26 @@ class NewGameScreen: PickerScreen(){ // Create a checkbox for each VictoryType existing var i=0 - VictoryType.values().forEach{ - val victoryCheckbox = CheckBox(it.name.tr(),skin) - victoryCheckbox.name=it.name - victoryCheckbox.isChecked=newGameParameters.victoryTypes.contains(it) + val victoryConditionsTable = Table().apply { defaults().pad(10f) } + for (victoryType in VictoryType.values()) { + if(victoryType==VictoryType.Neutral) continue + val victoryCheckbox = CheckBox(victoryType.name.tr(),skin) + victoryCheckbox.name=victoryType.name + victoryCheckbox.isChecked=newGameParameters.victoryTypes.contains(victoryType) victoryCheckbox.addListener(object : ChangeListener() { override fun changed(event: ChangeEvent?, actor: Actor?) { - // If the checkbox is checked, adds the victoryType else remove it + // If the checkbox is checked, adds the victoryTypes else remove it if(victoryCheckbox.isChecked){ - newGameParameters.victoryTypes.add(it) + newGameParameters.victoryTypes.add(victoryType) } else { - newGameParameters.victoryTypes.remove(it) + newGameParameters.victoryTypes.remove(victoryType) } } }) - if(++i%2==0) { - // New row only each two checkboxes - newGameOptionsTable.add(victoryCheckbox) - .left() // Left alignment - .pad(10f).row() - } else { - newGameOptionsTable.add(victoryCheckbox) - .left() // Left alignment - } + victoryConditionsTable.add(victoryCheckbox) + if(++i%2==0) victoryConditionsTable.row() } - + newGameOptionsTable.add(victoryConditionsTable).colspan(2).row() } private fun getMapFileSelectBox(): SelectBox { diff --git a/core/src/com/unciv/ui/VictoryScreen.kt b/core/src/com/unciv/ui/VictoryScreen.kt index 5929c9ed9c..3f11bf0573 100644 --- a/core/src/com/unciv/ui/VictoryScreen.kt +++ b/core/src/com/unciv/ui/VictoryScreen.kt @@ -17,6 +17,11 @@ import com.unciv.ui.utils.toLabel class VictoryScreen : PickerScreen() { val playerCivInfo = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() + val victoryTypes = playerCivInfo.gameInfo.gameParameters.victoryTypes + val scientificVictoryEnabled = victoryTypes.contains(VictoryType.Scientific) + val culturalVictoryEnabled = victoryTypes.contains(VictoryType.Cultural) + val dominationVictoryEnabled = victoryTypes.contains(VictoryType.Domination) + val contentsTable = Table() @@ -83,17 +88,17 @@ class VictoryScreen : PickerScreen() { fun setMyVictoryTable(){ val myVictoryStatusTable = Table() myVictoryStatusTable.defaults().pad(10f) - myVictoryStatusTable.add("Science victory".toLabel()) - myVictoryStatusTable.add("Cultural victory".toLabel()) - myVictoryStatusTable.add("Conquest victory".toLabel()) + if(scientificVictoryEnabled) myVictoryStatusTable.add("Science victory".toLabel()) + if(culturalVictoryEnabled) myVictoryStatusTable.add("Cultural victory".toLabel()) + if(dominationVictoryEnabled) myVictoryStatusTable.add("Conquest victory".toLabel()) myVictoryStatusTable.row() - myVictoryStatusTable.add(scienceVictoryColumn()) - myVictoryStatusTable.add(culturalVictoryColumn()) - myVictoryStatusTable.add(conquestVictoryColumn()) + if(scientificVictoryEnabled) myVictoryStatusTable.add(scienceVictoryColumn()) + if(culturalVictoryEnabled) myVictoryStatusTable.add(culturalVictoryColumn()) + if(dominationVictoryEnabled) myVictoryStatusTable.add(conquestVictoryColumn()) myVictoryStatusTable.row() - myVictoryStatusTable.add("Complete all the spaceship parts\n to win!".toLabel()) - myVictoryStatusTable.add("Complete 4 policy branches\n to win!".toLabel()) - myVictoryStatusTable.add("Destroy all enemies\n to win!".toLabel()) + if(scientificVictoryEnabled) myVictoryStatusTable.add("Complete all the spaceship parts\n to win!".toLabel()) + if(culturalVictoryEnabled) myVictoryStatusTable.add("Complete 4 policy branches\n to win!".toLabel()) + if(dominationVictoryEnabled) myVictoryStatusTable.add("Destroy all enemies\n to win!".toLabel()) contentsTable.clear() contentsTable.add(myVictoryStatusTable) @@ -148,9 +153,9 @@ class VictoryScreen : PickerScreen() { val majorCivs = game.gameInfo.civilizations.filter { it.isMajorCiv() } val globalVictoryTable = Table().apply { defaults().pad(10f) } - globalVictoryTable.add(getGlobalScientificVictoryColumn(majorCivs)) - globalVictoryTable.add(getGlobalPolicyVictoryColumn(majorCivs)) - globalVictoryTable.add(getGlobalDominationVictoryColumn(majorCivs)) + if(scientificVictoryEnabled) globalVictoryTable.add(getGlobalScientificVictoryColumn(majorCivs)) + if(culturalVictoryEnabled) globalVictoryTable.add(getGlobalCulturalVictoryColumn(majorCivs)) + if(dominationVictoryEnabled) globalVictoryTable.add(getGlobalDominationVictoryColumn(majorCivs)) contentsTable.clear() contentsTable.add(globalVictoryTable) @@ -162,15 +167,17 @@ class VictoryScreen : PickerScreen() { dominationVictoryColumn.add("Undefeated civs".toLabel()).row() dominationVictoryColumn.addSeparator() - for (civ in majorCivs.filter { !it.isDefeated() }) - dominationVictoryColumn.add(TextButton(civ.civName.tr(), skin).apply { color = Color.GREEN }).row() + for (civ in majorCivs.filter { !it.isDefeated() }) { + val civName = if(playerCivInfo.knows(civ) || playerCivInfo==civ) civ.civName.tr() else "???" + dominationVictoryColumn.add(TextButton(civName, skin).apply { color = Color.GREEN }).row() + } for (civ in majorCivs.filter { it.isDefeated() }) dominationVictoryColumn.add(TextButton(civ.civName.tr(), skin).apply { color = Color.GRAY }).row() return dominationVictoryColumn } - private fun getGlobalPolicyVictoryColumn(majorCivs: List): Table { + private fun getGlobalCulturalVictoryColumn(majorCivs: List): Table { val policyVictoryColumn = Table().apply { defaults().pad(10f) } policyVictoryColumn.add("Branches completed".toLabel()).row() policyVictoryColumn.addSeparator() @@ -181,8 +188,10 @@ class VictoryScreen : PickerScreen() { majorCivs.map { civToBranchesCompleted(it, it.policies.adoptedPolicies.count { pol -> pol.endsWith("Complete") }) } .sortedByDescending { it.branchesCompleted } - for (entry in civsToBranchesCompleted) - policyVictoryColumn.add(TextButton(entry.civ.civName.tr() + " - " + entry.branchesCompleted, skin)).row() + for (entry in civsToBranchesCompleted) { + val civName = if(playerCivInfo.knows(entry.civ) || playerCivInfo==entry.civ) entry.civ.civName.tr() else "???" + policyVictoryColumn.add(TextButton(civName + " - " + entry.branchesCompleted, skin)).row() + } return policyVictoryColumn } @@ -198,8 +207,10 @@ class VictoryScreen : PickerScreen() { it.victoryManager.spaceshipPartsRemaining()) } - for (entry in civsToPartsRemaining) - scientificVictoryColumn.add(TextButton(entry.civ.civName.tr() + " - " + entry.partsRemaining, skin)).row() + for (entry in civsToPartsRemaining) { + val civName = if(playerCivInfo.knows(entry.civ) || playerCivInfo==entry.civ) entry.civ.civName.tr() else "???" + scientificVictoryColumn.add(TextButton(civName + " - " + entry.partsRemaining, skin)).row() + } return scientificVictoryColumn } diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 56e20f6579..dc327aff7c 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -71,6 +71,7 @@ open class CameraStageBaseScreen : Screen { skin.get(TextField.TextFieldStyle::class.java).font = Fonts().getFont(18) skin.get(SelectBox.SelectBoxStyle::class.java).font = Fonts().getFont(20) skin.get(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts().getFont(20) + skin.get(CheckBox.CheckBoxStyle::class.java).fontColor= Color.WHITE } internal var batch: Batch = SpriteBatch() }