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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 17 deletions

View file

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

View file

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

View file

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

View file

@ -834,6 +834,9 @@ Happiness =
Production =
Culture =
Food =
Crop Yield =
Land =
Force =
GOLDEN AGE =
Golden Age =
[year] BC =
@ -987,6 +990,7 @@ Built Apollo Program =
Destroy [civName] =
Our status =
Global status =
Rankings =
Spaceship parts remaining =
Branches completed =
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.stats.Stats
import com.unciv.models.translations.tr
import com.unciv.ui.victoryscreen.RankingType
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
@ -41,7 +42,7 @@ class CivilizationInfo {
* Instead, we create a copy list with the change, and replace this list.
* 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 viewableInvisibleUnitsTiles = setOf<TileInfo>()
@ -165,8 +166,6 @@ class CivilizationInfo {
statsForNextTurn = stats().getStatMapForNextTurn().values.toList().reduce{a,b->a+b}
}
fun getHappiness() = stats().getHappinessBreakdown().values.sum().roundToInt()
@ -329,6 +328,21 @@ class CivilizationInfo {
&& !diplomacyManager.otherCivDiplomacy().hasFlag(DiplomacyFlags.ResearchAgreement)
&& 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
//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.scenes.scene2d.ui.Table
@ -7,6 +7,7 @@ import com.unciv.UncivGame
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.ruleset.VictoryType
import com.unciv.models.translations.tr
import com.unciv.ui.EmpireOverviewScreen
import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.addSeparator
@ -16,14 +17,14 @@ import com.unciv.ui.utils.toLabel
class VictoryScreen : PickerScreen() {
val playerCivInfo = UncivGame.Current.gameInfo.getPlayerToViewAs()
private val playerCivInfo = UncivGame.Current.gameInfo.getPlayerToViewAs()
val victoryTypes = playerCivInfo.gameInfo.gameParameters.victoryTypes
val scientificVictoryEnabled = victoryTypes.contains(VictoryType.Scientific)
val culturalVictoryEnabled = victoryTypes.contains(VictoryType.Cultural)
val dominationVictoryEnabled = victoryTypes.contains(VictoryType.Domination)
private val scientificVictoryEnabled = victoryTypes.contains(VictoryType.Scientific)
private val culturalVictoryEnabled = victoryTypes.contains(VictoryType.Cultural)
private val dominationVictoryEnabled = victoryTypes.contains(VictoryType.Domination)
val contentsTable = Table()
private val contentsTable = Table()
init {
val tabsTable = Table().apply { defaults().pad(10f) }
@ -33,6 +34,9 @@ class VictoryScreen : PickerScreen() {
val setGlobalVictoryButton = TextButton("Global status".tr(),skin)
setGlobalVictoryButton .onClick { setGlobalVictoryTable() }
tabsTable.add(setGlobalVictoryButton)
val setCivRankingsButton = TextButton("Rankings".tr(),skin)
setCivRankingsButton.onClick { setCivRankingsTable() }
tabsTable.add(setCivRankingsButton)
topTable.add(tabsTable)
topTable.addSeparator()
topTable.add(contentsTable)
@ -72,7 +76,7 @@ class VictoryScreen : PickerScreen() {
}
fun wonOrLost(description: String) {
private fun wonOrLost(description: String) {
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."
@ -98,7 +102,7 @@ class VictoryScreen : PickerScreen() {
}
fun setMyVictoryTable(){
private fun setMyVictoryTable() {
val myVictoryStatusTable = Table()
myVictoryStatusTable.defaults().pad(10f)
if(scientificVictoryEnabled) myVictoryStatusTable.add("Science victory".toLabel())
@ -117,7 +121,7 @@ class VictoryScreen : PickerScreen() {
contentsTable.add(myVictoryStatusTable)
}
fun scienceVictoryColumn():Table{
private fun scienceVictoryColumn():Table {
val t = Table()
t.defaults().pad(5f)
t.add(getMilestone("Built Apollo Program",playerCivInfo.containsBuildingUnique("Enables construction of Spaceship parts"))).row()
@ -131,7 +135,7 @@ class VictoryScreen : PickerScreen() {
return t
}
fun culturalVictoryColumn():Table{
private fun culturalVictoryColumn():Table {
val t=Table()
t.defaults().pad(5f)
for(branch in playerCivInfo.gameInfo.ruleSet.policyBranches.values) {
@ -141,7 +145,7 @@ class VictoryScreen : PickerScreen() {
return t
}
fun conquestVictoryColumn():Table{
private fun conquestVictoryColumn():Table {
val table=Table()
table.defaults().pad(5f)
for (civ in playerCivInfo.gameInfo.civilizations) {
@ -201,7 +205,7 @@ class VictoryScreen : PickerScreen() {
.sortedByDescending { it.branchesCompleted }
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()
}
return policyVictoryColumn
@ -226,4 +230,24 @@ class VictoryScreen : PickerScreen() {
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.unit.UnitType
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.pickerscreens.GreatPersonPickerScreen
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.models.translations.tr
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.mapeditor.LoadMapScreen
import com.unciv.ui.mapeditor.NewMapScreen