Civilization rankings (Richest, Strongest, Most Fertile, Largest, etc.) (#2036)

* Initial preparations

* Moving to the separate package

* Calculation and visualization

* Translations

* Using a local function instead of additional class

* Using a local function instead of additional class (part 2)

* Rankings French.properties

* Fixup of the leftover

Co-authored-by: RobertGine <61517798+RobertGine@users.noreply.github.com>
This commit is contained in:
JackRainy
2020-02-29 20:48:55 +02:00
committed by GitHub
parent b9682b0c80
commit 24e4d77453
9 changed files with 84 additions and 17 deletions

View File

@ -834,6 +834,9 @@ Happiness = Bonheur
Production = Production Production = Production
Culture = Culture Culture = Culture
Food = Nourriture Food = Nourriture
Crop Yield = Récolte
Land = Territoire
Force = Puissance
GOLDEN AGE = ÂGE D'OR GOLDEN AGE = ÂGE D'OR
Golden Age = Age d'or Golden Age = Age d'or
[year] BC = [year] avant J.C. [year] BC = [year] avant J.C.
@ -986,6 +989,7 @@ Built Apollo Program = Construit le programme Apollo
Destroy [civName] = Détruire [civName] Destroy [civName] = Détruire [civName]
Our status = Notre situation Our status = Notre situation
Global status = Situation globale Global status = Situation globale
Rankings = Classements
Spaceship parts remaining = Parties de Vaisseau spatial manquantes Spaceship parts remaining = Parties de Vaisseau spatial manquantes
Branches completed = Branches complêtées Branches completed = Branches complêtées
Undefeated civs = Civilization invaincues Undefeated civs = Civilization invaincues

View File

@ -834,6 +834,9 @@ Happiness = Счастье
Production = Производство Production = Производство
Culture = Культура Culture = Культура
Food = Еда Food = Еда
Crop Yield = Урожай
Land = Земля
Force = Сила
GOLDEN AGE = ЗОЛОТОЙ ВЕК GOLDEN AGE = ЗОЛОТОЙ ВЕК
Golden Age = Золотой век Golden Age = Золотой век
[year] BC = [year] до н.э. [year] BC = [year] до н.э.
@ -987,6 +990,7 @@ Built Apollo Program = Построена Программа Аполлон
Destroy [civName] = Уничтожить [civName] Destroy [civName] = Уничтожить [civName]
Our status = Наш статус Our status = Наш статус
Global status = Глобальный статус Global status = Глобальный статус
Rankings = Рейтинги
Spaceship parts remaining = Осталось частей КК Spaceship parts remaining = Осталось частей КК
Branches completed = Ветвей завершено Branches completed = Ветвей завершено
Undefeated civs = Непобеждённые цивилизации Undefeated civs = Непобеждённые цивилизации

View File

@ -838,6 +838,9 @@ Happiness = Щастя
Production = Виробництво Production = Виробництво
Culture = Культура Culture = Культура
Food = Їжа Food = Їжа
Crop Yield = Врожай
Land = Земля
Force = Сила
GOLDEN AGE = ЗОЛОТА ДОБА GOLDEN AGE = ЗОЛОТА ДОБА
Golden Age = Золота доба Golden Age = Золота доба
[year] BC = [year] до н.е. [year] BC = [year] до н.е.
@ -991,6 +994,7 @@ Built Apollo Program = Здійснити Програму Аполлон
Destroy [civName] = Знищити [civName] Destroy [civName] = Знищити [civName]
Our status = Наш стан Our status = Наш стан
Global status = Глобальний стан Global status = Глобальний стан
Rankings = Рейтинги
Spaceship parts remaining = Залишилось частин космічного корабля Spaceship parts remaining = Залишилось частин космічного корабля
Branches completed = Галузей завершено Branches completed = Галузей завершено
Undefeated civs = Непереможені цивілізації Undefeated civs = Непереможені цивілізації

View File

@ -834,6 +834,9 @@ Happiness =
Production = Production =
Culture = Culture =
Food = Food =
Crop Yield =
Land =
Force =
GOLDEN AGE = GOLDEN AGE =
Golden Age = Golden Age =
[year] BC = [year] BC =
@ -987,6 +990,7 @@ Built Apollo Program =
Destroy [civName] = Destroy [civName] =
Our status = Our status =
Global status = Global status =
Rankings =
Spaceship parts remaining = Spaceship parts remaining =
Branches completed = Branches completed =
Undefeated civs = Undefeated civs =

View File

@ -25,6 +25,7 @@ import com.unciv.models.ruleset.tile.ResourceSupplyList
import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.victoryscreen.RankingType
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.collections.HashMap import kotlin.collections.HashMap
@ -41,7 +42,7 @@ class CivilizationInfo {
* Instead, we create a copy list with the change, and replace this list. * Instead, we create a copy list with the change, and replace this list.
* The other solution, casting toList() every "get", has a performance cost * The other solution, casting toList() every "get", has a performance cost
*/ */
@Transient private var units=listOf<MapUnit>() @Transient private var units = listOf<MapUnit>()
@Transient var viewableTiles = setOf<TileInfo>() @Transient var viewableTiles = setOf<TileInfo>()
@Transient var viewableInvisibleUnitsTiles = setOf<TileInfo>() @Transient var viewableInvisibleUnitsTiles = setOf<TileInfo>()
@ -165,8 +166,6 @@ class CivilizationInfo {
statsForNextTurn = stats().getStatMapForNextTurn().values.toList().reduce{a,b->a+b} statsForNextTurn = stats().getStatMapForNextTurn().values.toList().reduce{a,b->a+b}
} }
fun getHappiness() = stats().getHappinessBreakdown().values.sum().roundToInt() fun getHappiness() = stats().getHappinessBreakdown().values.sum().roundToInt()
@ -329,6 +328,21 @@ class CivilizationInfo {
&& !diplomacyManager.otherCivDiplomacy().hasFlag(DiplomacyFlags.ResearchAgreement) && !diplomacyManager.otherCivDiplomacy().hasFlag(DiplomacyFlags.ResearchAgreement)
&& gold >= cost && otherCiv.gold >= cost && gold >= cost && otherCiv.gold >= cost
} }
fun getStatForRanking(category: RankingType) : Int {
return when(category) {
RankingType.Population -> cities.sumBy { it.population.population }
RankingType.CropYield -> statsForNextTurn.food.roundToInt()
RankingType.Production -> statsForNextTurn.production.roundToInt()
RankingType.Gold -> gold
RankingType.Land -> cities.sumBy { it.tiles.size }
RankingType.Force -> units.sumBy { it.baseUnit.strength }
RankingType.Happiness -> getHappiness()
RankingType.Technologies -> tech.researchedTechnologies.size
RankingType.Culture -> policies.storedCulture
}
}
//endregion //endregion
//region state-changing functions //region state-changing functions

View File

@ -0,0 +1,13 @@
package com.unciv.ui.victoryscreen
enum class RankingType (val value: String) {
Population("Population"),
CropYield("Crop Yield"),
Production("Production"),
Gold("Gold"),
Land("Land"),
Force("Force"),
Happiness("Happiness"),
Technologies("Technologies"),
Culture("Culture")
}

View File

@ -1,4 +1,4 @@
package com.unciv.ui package com.unciv.ui.victoryscreen
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
@ -7,6 +7,7 @@ import com.unciv.UncivGame
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.ruleset.VictoryType import com.unciv.models.ruleset.VictoryType
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.EmpireOverviewScreen
import com.unciv.ui.newgamescreen.NewGameScreen import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.addSeparator import com.unciv.ui.utils.addSeparator
@ -16,14 +17,14 @@ import com.unciv.ui.utils.toLabel
class VictoryScreen : PickerScreen() { class VictoryScreen : PickerScreen() {
val playerCivInfo = UncivGame.Current.gameInfo.getPlayerToViewAs() private val playerCivInfo = UncivGame.Current.gameInfo.getPlayerToViewAs()
val victoryTypes = playerCivInfo.gameInfo.gameParameters.victoryTypes val victoryTypes = playerCivInfo.gameInfo.gameParameters.victoryTypes
val scientificVictoryEnabled = victoryTypes.contains(VictoryType.Scientific) private val scientificVictoryEnabled = victoryTypes.contains(VictoryType.Scientific)
val culturalVictoryEnabled = victoryTypes.contains(VictoryType.Cultural) private val culturalVictoryEnabled = victoryTypes.contains(VictoryType.Cultural)
val dominationVictoryEnabled = victoryTypes.contains(VictoryType.Domination) private val dominationVictoryEnabled = victoryTypes.contains(VictoryType.Domination)
val contentsTable = Table() private val contentsTable = Table()
init { init {
val tabsTable = Table().apply { defaults().pad(10f) } val tabsTable = Table().apply { defaults().pad(10f) }
@ -33,6 +34,9 @@ class VictoryScreen : PickerScreen() {
val setGlobalVictoryButton = TextButton("Global status".tr(),skin) val setGlobalVictoryButton = TextButton("Global status".tr(),skin)
setGlobalVictoryButton .onClick { setGlobalVictoryTable() } setGlobalVictoryButton .onClick { setGlobalVictoryTable() }
tabsTable.add(setGlobalVictoryButton) tabsTable.add(setGlobalVictoryButton)
val setCivRankingsButton = TextButton("Rankings".tr(),skin)
setCivRankingsButton.onClick { setCivRankingsTable() }
tabsTable.add(setCivRankingsButton)
topTable.add(tabsTable) topTable.add(tabsTable)
topTable.addSeparator() topTable.addSeparator()
topTable.add(contentsTable) topTable.add(contentsTable)
@ -72,7 +76,7 @@ class VictoryScreen : PickerScreen() {
} }
fun wonOrLost(description: String) { private fun wonOrLost(description: String) {
val endGameMessage = when(description){ val endGameMessage = when(description){
"You have won a cultural victory!" -> "You have achieved victory through the awesome power of your Culture. Your civilization's greatness - the magnificence of its monuments and the power of its artists - have astounded the world! Poets will honor you as long as beauty brings gladness to a weary heart." "You have won a cultural victory!" -> "You have achieved victory through the awesome power of your Culture. Your civilization's greatness - the magnificence of its monuments and the power of its artists - have astounded the world! Poets will honor you as long as beauty brings gladness to a weary heart."
@ -98,7 +102,7 @@ class VictoryScreen : PickerScreen() {
} }
fun setMyVictoryTable(){ private fun setMyVictoryTable() {
val myVictoryStatusTable = Table() val myVictoryStatusTable = Table()
myVictoryStatusTable.defaults().pad(10f) myVictoryStatusTable.defaults().pad(10f)
if(scientificVictoryEnabled) myVictoryStatusTable.add("Science victory".toLabel()) if(scientificVictoryEnabled) myVictoryStatusTable.add("Science victory".toLabel())
@ -117,7 +121,7 @@ class VictoryScreen : PickerScreen() {
contentsTable.add(myVictoryStatusTable) contentsTable.add(myVictoryStatusTable)
} }
fun scienceVictoryColumn():Table{ private fun scienceVictoryColumn():Table {
val t = Table() val t = Table()
t.defaults().pad(5f) t.defaults().pad(5f)
t.add(getMilestone("Built Apollo Program",playerCivInfo.containsBuildingUnique("Enables construction of Spaceship parts"))).row() t.add(getMilestone("Built Apollo Program",playerCivInfo.containsBuildingUnique("Enables construction of Spaceship parts"))).row()
@ -131,7 +135,7 @@ class VictoryScreen : PickerScreen() {
return t return t
} }
fun culturalVictoryColumn():Table{ private fun culturalVictoryColumn():Table {
val t=Table() val t=Table()
t.defaults().pad(5f) t.defaults().pad(5f)
for(branch in playerCivInfo.gameInfo.ruleSet.policyBranches.values) { for(branch in playerCivInfo.gameInfo.ruleSet.policyBranches.values) {
@ -141,7 +145,7 @@ class VictoryScreen : PickerScreen() {
return t return t
} }
fun conquestVictoryColumn():Table{ private fun conquestVictoryColumn():Table {
val table=Table() val table=Table()
table.defaults().pad(5f) table.defaults().pad(5f)
for (civ in playerCivInfo.gameInfo.civilizations) { for (civ in playerCivInfo.gameInfo.civilizations) {
@ -201,7 +205,7 @@ class VictoryScreen : PickerScreen() {
.sortedByDescending { it.branchesCompleted } .sortedByDescending { it.branchesCompleted }
for (entry in civsToBranchesCompleted) { for (entry in civsToBranchesCompleted) {
val civToBranchesHaveCompleted=EmpireOverviewScreen.getCivGroup(entry.civ, " - " + entry.branchesCompleted, playerCivInfo) val civToBranchesHaveCompleted= EmpireOverviewScreen.getCivGroup(entry.civ, " - " + entry.branchesCompleted, playerCivInfo)
policyVictoryColumn.add(civToBranchesHaveCompleted).row() policyVictoryColumn.add(civToBranchesHaveCompleted).row()
} }
return policyVictoryColumn return policyVictoryColumn
@ -226,4 +230,24 @@ class VictoryScreen : PickerScreen() {
return scientificVictoryColumn return scientificVictoryColumn
} }
private fun setCivRankingsTable() {
val majorCivs = game.gameInfo.civilizations.filter { it.isMajorCiv() }
val civRankingsTable = Table().apply { defaults().pad(5f) }
for( category in RankingType.values()) {
val column = Table().apply { defaults().pad(5f) }
column.add(category.value.toLabel()).row()
column.addSeparator()
for (civ in majorCivs.sortedByDescending { it.getStatForRanking(category) }) {
column.add(EmpireOverviewScreen.getCivGroup(civ, " : " + civ.getStatForRanking(category).toString(), playerCivInfo)).row()
}
civRankingsTable.add(column)
}
contentsTable.clear()
contentsTable.add(civRankingsTable)
}
} }

View File

@ -20,7 +20,7 @@ import com.unciv.models.UncivSound
import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.ruleset.unit.UnitType import com.unciv.models.ruleset.unit.UnitType
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.VictoryScreen import com.unciv.ui.victoryscreen.VictoryScreen
import com.unciv.ui.cityscreen.CityScreen import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.pickerscreens.GreatPersonPickerScreen import com.unciv.ui.pickerscreens.GreatPersonPickerScreen
import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen

View File

@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.unciv.UncivGame import com.unciv.UncivGame
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.CivilopediaScreen import com.unciv.ui.CivilopediaScreen
import com.unciv.ui.VictoryScreen import com.unciv.ui.victoryscreen.VictoryScreen
import com.unciv.ui.MultiplayerScreen import com.unciv.ui.MultiplayerScreen
import com.unciv.ui.mapeditor.LoadMapScreen import com.unciv.ui.mapeditor.LoadMapScreen
import com.unciv.ui.mapeditor.NewMapScreen import com.unciv.ui.mapeditor.NewMapScreen