Resolved #251 - Choose specific victory conditions on new game

Victory screen no longer 'reveals' civs you haven't met
This commit is contained in:
Yair Morgenstern 2019-06-16 19:51:12 +03:00
parent be7baaa117
commit 3f3dd0193e
8 changed files with 76 additions and 58 deletions

View File

@ -100,7 +100,7 @@ class Automation {
&& cityInfo.getTiles().any { it.isWater && it.hasViewableResource(cityInfo.civInfo) && it.improvement == null } && cityInfo.getTiles().any { it.isWater && it.hasViewableResource(cityInfo.civInfo) && it.improvement == null }
val isAtWar = cityInfo.civInfo.isAtWar() 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){ data class ConstructionChoice(val choice:String, var choiceModifier:Float){
val remainingWork:Int = getRemainingWork(choice) val remainingWork:Int = getRemainingWork(choice)

View File

@ -146,7 +146,7 @@ class NextTurnAutomation{
val adoptablePolicies = GameBasics.PolicyBranches.values.flatMap { it.policies.union(listOf(it)) } val adoptablePolicies = GameBasics.PolicyBranches.values.flatMap { it.policies.union(listOf(it)) }
.filter { civInfo.policies.isAdoptable(it) } .filter { civInfo.policies.isAdoptable(it) }
val preferredVictoryType = civInfo.getNation().preferredVictoryType val preferredVictoryType = civInfo.victoryType()
val policyBranchPriority = val policyBranchPriority =
when(preferredVictoryType) { when(preferredVictoryType) {
VictoryType.Cultural -> listOf("Piety", "Freedom", "Tradition", "Rationalism") VictoryType.Cultural -> listOf("Piety", "Freedom", "Tradition", "Rationalism")
@ -243,7 +243,7 @@ class NextTurnAutomation{
for (enemy in enemiesCiv) { for (enemy in enemiesCiv) {
val enemiesStrength = Automation().evaluteCombatStrength(enemy) val enemiesStrength = Automation().evaluteCombatStrength(enemy)
if (civInfo.getNation().preferredVictoryType!=VictoryType.Cultural if (civInfo.victoryType()!=VictoryType.Cultural
&& enemiesStrength < ourCombatStrength*2 ) { && enemiesStrength < ourCombatStrength*2 ) {
continue //We're losing, but can still fight. Refuse peace. continue //We're losing, but can still fight. Refuse peace.
} }
@ -265,7 +265,7 @@ class NextTurnAutomation{
if (enemy.isPlayerCivilization()) if (enemy.isPlayerCivilization())
enemy.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse())) enemy.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
else { else {
if (enemy.getNation().preferredVictoryType!=VictoryType.Cultural if (enemy.victoryType()!=VictoryType.Cultural
&& enemy.getCivUnits().filter { !it.type.isCivilian() }.size > enemy.cities.size && enemy.getCivUnits().filter { !it.type.isCivilian() }.size > enemy.cities.size
&& enemy.happiness > 0) { && enemy.happiness > 0) {
continue //enemy AI has too large army and happiness. It continues to fight for profit. 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) { private fun declareWar(civInfo: CivilizationInfo) {
if (civInfo.isCityState()) return if (civInfo.isCityState()) return
if(civInfo.getNation().preferredVictoryType==VictoryType.Cultural) if (civInfo.victoryType()==VictoryType.Cultural)
return return
if (civInfo.cities.isNotEmpty() && civInfo.diplomacy.isNotEmpty()) { if (civInfo.cities.isNotEmpty() && civInfo.diplomacy.isNotEmpty()) {
@ -369,7 +369,7 @@ class NextTurnAutomation{
private fun trainSettler(civInfo: CivilizationInfo) { private fun trainSettler(civInfo: CivilizationInfo) {
if(civInfo.isCityState()) return if(civInfo.isCityState()) return
if(civInfo.isAtWar()) return // don't train settlers when you could be training troops. 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() if (civInfo.cities.any()
&& civInfo.happiness > civInfo.cities.size + 5 && civInfo.happiness > civInfo.cities.size + 5
&& civInfo.getCivUnits().none { it.name == Constants.settler } && civInfo.getCivUnits().none { it.name == Constants.settler }

View File

@ -138,6 +138,11 @@ class CivilizationInfo {
fun getCityStateType(): CityStateType = getNation().cityStateType!! fun getCityStateType(): CityStateType = getNation().cityStateType!!
fun isMajorCiv() = !isBarbarianCivilization() && !isCityState() 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} fun getStatsForNextTurn():Stats = getStatMapForNextTurn().values.toList().reduce{a,b->a+b}

View File

@ -79,7 +79,7 @@ class PolicyManager {
"Liberty Complete" -> { "Liberty Complete" -> {
if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++ if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++
else { else {
val preferredVictoryType = civInfo.getNation().preferredVictoryType val preferredVictoryType = civInfo.victoryType()
val greatPerson = when(preferredVictoryType) { val greatPerson = when(preferredVictoryType) {
VictoryType.Cultural -> "Great Artist" VictoryType.Cultural -> "Great Artist"
VictoryType.Scientific -> "Great Scientist" VictoryType.Scientific -> "Great Scientist"

View File

@ -30,11 +30,14 @@ class VictoryManager {
fun spaceshipPartsRemaining() = requiredSpaceshipParts.values.sum() - currentsSpaceshipParts.values.sum() 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? { fun hasWonVictoryType(): VictoryType? {
if(!civInfo.isMajorCiv()) return null if(!civInfo.isMajorCiv()) return null

View File

@ -77,15 +77,7 @@ class NewGameScreen: PickerScreen(){
addNumberOfHumansAndEnemies(newGameOptionsTable) addNumberOfHumansAndEnemies(newGameOptionsTable)
addDifficultySelectBox(newGameOptionsTable) addDifficultySelectBox(newGameOptionsTable)
addVictoryTypeCheckboxes(newGameOptionsTable) addVictoryTypeCheckboxes(newGameOptionsTable)
addBarbariansCheckbox(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()
rightSideButton.enable() rightSideButton.enable()
@ -112,6 +104,17 @@ class NewGameScreen: PickerScreen(){
return newGameOptionsTable 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) { private fun addMapTypeSizeAndFile(newGameOptionsTable: Table) {
newGameOptionsTable.add("{Map type}:".tr()) newGameOptionsTable.add("{Map type}:".tr())
val mapTypes = LinkedHashMap<String, MapType>() val mapTypes = LinkedHashMap<String, MapType>()
@ -171,14 +174,14 @@ class NewGameScreen: PickerScreen(){
newGameOptionsTable.add("{Number of enemies}:".tr()) newGameOptionsTable.add("{Number of enemies}:".tr())
val enemiesSelectBox = SelectBox<Int>(skin) val enemiesSelectBox = SelectBox<Int>(skin)
val enemiesArray = Array<Int>() val enemiesArray = Array<Int>()
(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.items = enemiesArray
enemiesSelectBox.selected = newGameParameters.numberOfEnemies enemiesSelectBox.selected = newGameParameters.numberOfEnemies
newGameOptionsTable.add(enemiesSelectBox).pad(10f).row() newGameOptionsTable.add(enemiesSelectBox).pad(10f).row()
// Todo - re-enable this when city states are fit for players
addCityStatesSelectBox(newGameOptionsTable) addCityStatesSelectBox(newGameOptionsTable)
// newGameParameters.numberOfCityStates = 0
humanPlayers.addListener(object : ChangeListener() { humanPlayers.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) { override fun changed(event: ChangeEvent?, actor: Actor?) {
@ -232,31 +235,26 @@ class NewGameScreen: PickerScreen(){
// Create a checkbox for each VictoryType existing // Create a checkbox for each VictoryType existing
var i=0 var i=0
VictoryType.values().forEach{ val victoryConditionsTable = Table().apply { defaults().pad(10f) }
val victoryCheckbox = CheckBox(it.name.tr(),skin) for (victoryType in VictoryType.values()) {
victoryCheckbox.name=it.name if(victoryType==VictoryType.Neutral) continue
victoryCheckbox.isChecked=newGameParameters.victoryTypes.contains(it) val victoryCheckbox = CheckBox(victoryType.name.tr(),skin)
victoryCheckbox.name=victoryType.name
victoryCheckbox.isChecked=newGameParameters.victoryTypes.contains(victoryType)
victoryCheckbox.addListener(object : ChangeListener() { victoryCheckbox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) { 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){ if(victoryCheckbox.isChecked){
newGameParameters.victoryTypes.add(it) newGameParameters.victoryTypes.add(victoryType)
} else { } else {
newGameParameters.victoryTypes.remove(it) newGameParameters.victoryTypes.remove(victoryType)
} }
} }
}) })
if(++i%2==0) { victoryConditionsTable.add(victoryCheckbox)
// New row only each two checkboxes if(++i%2==0) victoryConditionsTable.row()
newGameOptionsTable.add(victoryCheckbox)
.left() // Left alignment
.pad(10f).row()
} else {
newGameOptionsTable.add(victoryCheckbox)
.left() // Left alignment
} }
} newGameOptionsTable.add(victoryConditionsTable).colspan(2).row()
} }
private fun getMapFileSelectBox(): SelectBox<String> { private fun getMapFileSelectBox(): SelectBox<String> {

View File

@ -17,6 +17,11 @@ import com.unciv.ui.utils.toLabel
class VictoryScreen : PickerScreen() { class VictoryScreen : PickerScreen() {
val playerCivInfo = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() 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() val contentsTable = Table()
@ -83,17 +88,17 @@ class VictoryScreen : PickerScreen() {
fun setMyVictoryTable(){ fun setMyVictoryTable(){
val myVictoryStatusTable = Table() val myVictoryStatusTable = Table()
myVictoryStatusTable.defaults().pad(10f) myVictoryStatusTable.defaults().pad(10f)
myVictoryStatusTable.add("Science victory".toLabel()) if(scientificVictoryEnabled) myVictoryStatusTable.add("Science victory".toLabel())
myVictoryStatusTable.add("Cultural victory".toLabel()) if(culturalVictoryEnabled) myVictoryStatusTable.add("Cultural victory".toLabel())
myVictoryStatusTable.add("Conquest victory".toLabel()) if(dominationVictoryEnabled) myVictoryStatusTable.add("Conquest victory".toLabel())
myVictoryStatusTable.row() myVictoryStatusTable.row()
myVictoryStatusTable.add(scienceVictoryColumn()) if(scientificVictoryEnabled) myVictoryStatusTable.add(scienceVictoryColumn())
myVictoryStatusTable.add(culturalVictoryColumn()) if(culturalVictoryEnabled) myVictoryStatusTable.add(culturalVictoryColumn())
myVictoryStatusTable.add(conquestVictoryColumn()) if(dominationVictoryEnabled) myVictoryStatusTable.add(conquestVictoryColumn())
myVictoryStatusTable.row() myVictoryStatusTable.row()
myVictoryStatusTable.add("Complete all the spaceship parts\n to win!".toLabel()) if(scientificVictoryEnabled) myVictoryStatusTable.add("Complete all the spaceship parts\n to win!".toLabel())
myVictoryStatusTable.add("Complete 4 policy branches\n to win!".toLabel()) if(culturalVictoryEnabled) myVictoryStatusTable.add("Complete 4 policy branches\n to win!".toLabel())
myVictoryStatusTable.add("Destroy all enemies\n to win!".toLabel()) if(dominationVictoryEnabled) myVictoryStatusTable.add("Destroy all enemies\n to win!".toLabel())
contentsTable.clear() contentsTable.clear()
contentsTable.add(myVictoryStatusTable) contentsTable.add(myVictoryStatusTable)
@ -148,9 +153,9 @@ class VictoryScreen : PickerScreen() {
val majorCivs = game.gameInfo.civilizations.filter { it.isMajorCiv() } val majorCivs = game.gameInfo.civilizations.filter { it.isMajorCiv() }
val globalVictoryTable = Table().apply { defaults().pad(10f) } val globalVictoryTable = Table().apply { defaults().pad(10f) }
globalVictoryTable.add(getGlobalScientificVictoryColumn(majorCivs)) if(scientificVictoryEnabled) globalVictoryTable.add(getGlobalScientificVictoryColumn(majorCivs))
globalVictoryTable.add(getGlobalPolicyVictoryColumn(majorCivs)) if(culturalVictoryEnabled) globalVictoryTable.add(getGlobalCulturalVictoryColumn(majorCivs))
globalVictoryTable.add(getGlobalDominationVictoryColumn(majorCivs)) if(dominationVictoryEnabled) globalVictoryTable.add(getGlobalDominationVictoryColumn(majorCivs))
contentsTable.clear() contentsTable.clear()
contentsTable.add(globalVictoryTable) contentsTable.add(globalVictoryTable)
@ -162,15 +167,17 @@ class VictoryScreen : PickerScreen() {
dominationVictoryColumn.add("Undefeated civs".toLabel()).row() dominationVictoryColumn.add("Undefeated civs".toLabel()).row()
dominationVictoryColumn.addSeparator() dominationVictoryColumn.addSeparator()
for (civ in majorCivs.filter { !it.isDefeated() }) for (civ in majorCivs.filter { !it.isDefeated() }) {
dominationVictoryColumn.add(TextButton(civ.civName.tr(), skin).apply { color = Color.GREEN }).row() 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() }) for (civ in majorCivs.filter { it.isDefeated() })
dominationVictoryColumn.add(TextButton(civ.civName.tr(), skin).apply { color = Color.GRAY }).row() dominationVictoryColumn.add(TextButton(civ.civName.tr(), skin).apply { color = Color.GRAY }).row()
return dominationVictoryColumn return dominationVictoryColumn
} }
private fun getGlobalPolicyVictoryColumn(majorCivs: List<CivilizationInfo>): Table { private fun getGlobalCulturalVictoryColumn(majorCivs: List<CivilizationInfo>): Table {
val policyVictoryColumn = Table().apply { defaults().pad(10f) } val policyVictoryColumn = Table().apply { defaults().pad(10f) }
policyVictoryColumn.add("Branches completed".toLabel()).row() policyVictoryColumn.add("Branches completed".toLabel()).row()
policyVictoryColumn.addSeparator() policyVictoryColumn.addSeparator()
@ -181,8 +188,10 @@ class VictoryScreen : PickerScreen() {
majorCivs.map { civToBranchesCompleted(it, it.policies.adoptedPolicies.count { pol -> pol.endsWith("Complete") }) } majorCivs.map { civToBranchesCompleted(it, it.policies.adoptedPolicies.count { pol -> pol.endsWith("Complete") }) }
.sortedByDescending { it.branchesCompleted } .sortedByDescending { it.branchesCompleted }
for (entry in civsToBranchesCompleted) for (entry in civsToBranchesCompleted) {
policyVictoryColumn.add(TextButton(entry.civ.civName.tr() + " - " + entry.branchesCompleted, skin)).row() 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 return policyVictoryColumn
} }
@ -198,8 +207,10 @@ class VictoryScreen : PickerScreen() {
it.victoryManager.spaceshipPartsRemaining()) it.victoryManager.spaceshipPartsRemaining())
} }
for (entry in civsToPartsRemaining) for (entry in civsToPartsRemaining) {
scientificVictoryColumn.add(TextButton(entry.civ.civName.tr() + " - " + entry.partsRemaining, skin)).row() 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 return scientificVictoryColumn
} }

View File

@ -71,6 +71,7 @@ open class CameraStageBaseScreen : Screen {
skin.get<TextField.TextFieldStyle>(TextField.TextFieldStyle::class.java).font = Fonts().getFont(18) skin.get<TextField.TextFieldStyle>(TextField.TextFieldStyle::class.java).font = Fonts().getFont(18)
skin.get<SelectBox.SelectBoxStyle>(SelectBox.SelectBoxStyle::class.java).font = Fonts().getFont(20) skin.get<SelectBox.SelectBoxStyle>(SelectBox.SelectBoxStyle::class.java).font = Fonts().getFont(20)
skin.get<SelectBox.SelectBoxStyle>(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts().getFont(20) skin.get<SelectBox.SelectBoxStyle>(SelectBox.SelectBoxStyle::class.java).listStyle.font = Fonts().getFont(20)
skin.get<CheckBox.CheckBoxStyle>(CheckBox.CheckBoxStyle::class.java).fontColor= Color.WHITE
} }
internal var batch: Batch = SpriteBatch() internal var batch: Batch = SpriteBatch()
} }