From 1285133884fef75fc6f70e349744be0a36b76004 Mon Sep 17 00:00:00 2001 From: SeventhM <127357473+SeventhM@users.noreply.github.com> Date: Sat, 24 Jun 2023 23:36:33 -0700 Subject: [PATCH] Adding field for great person type (#9614) * Adding Field for great person types * Switching from unit field to unique * Simplification and adding back in the old field for backward compatibility * Deprecate old field for checking great person * Fix error * Fixes part 2. I probably should've waited --- .../com/unciv/logic/BackwardCompatibility.kt | 11 +++++++ core/src/com/unciv/logic/GameInfo.kt | 3 ++ .../managers/GreatPersonManager.kt | 30 ++++++++++++++----- .../unciv/models/ruleset/unique/UniqueType.kt | 1 + .../ui/screens/cityscreen/CityStatsTable.kt | 2 +- .../overviewscreen/StatsOverviewTab.kt | 2 +- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/core/src/com/unciv/logic/BackwardCompatibility.kt b/core/src/com/unciv/logic/BackwardCompatibility.kt index 63de26282c..ea00ff351f 100644 --- a/core/src/com/unciv/logic/BackwardCompatibility.kt +++ b/core/src/com/unciv/logic/BackwardCompatibility.kt @@ -202,4 +202,15 @@ object BackwardCompatibility { } historyStartTurn = turns } + + fun GameInfo.migrateGreatPersonPools() { + for (civ in civilizations) civ.greatPeople.run { + if (pointsForNextGreatPerson >= pointsForNextGreatPersonCounter[""]) { + pointsForNextGreatPersonCounter[""] = pointsForNextGreatPerson + } + else { + pointsForNextGreatPerson = pointsForNextGreatPersonCounter[""] + } + } + } } diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 7f321c0ed4..d57649e1ce 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -8,6 +8,7 @@ import com.unciv.logic.BackwardCompatibility.convertEncampmentData import com.unciv.logic.BackwardCompatibility.convertFortify import com.unciv.logic.BackwardCompatibility.guaranteeUnitPromotions import com.unciv.logic.BackwardCompatibility.migrateToTileHistory +import com.unciv.logic.BackwardCompatibility.migrateGreatPersonPools import com.unciv.logic.BackwardCompatibility.removeMissingModReferences import com.unciv.logic.GameInfo.Companion.CURRENT_COMPATIBILITY_NUMBER import com.unciv.logic.GameInfo.Companion.FIRST_WITHOUT @@ -602,6 +603,8 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion guaranteeUnitPromotions() migrateToTileHistory() + + migrateGreatPersonPools() } private fun updateCivilizationState() { diff --git a/core/src/com/unciv/logic/civilization/managers/GreatPersonManager.kt b/core/src/com/unciv/logic/civilization/managers/GreatPersonManager.kt index ec273df528..f1791161f6 100644 --- a/core/src/com/unciv/logic/civilization/managers/GreatPersonManager.kt +++ b/core/src/com/unciv/logic/civilization/managers/GreatPersonManager.kt @@ -6,6 +6,7 @@ import com.unciv.models.Counter import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unit.BaseUnit + // todo: Great Admiral? // todo: Free GP from policies and wonders should increase threshold according to the wiki // todo: GP from Maya long count should increase threshold as well - implement together @@ -16,7 +17,9 @@ class GreatPersonManager : IsPartOfGameInfoSerialization { lateinit var civInfo: Civilization /** Base points, without speed modifier */ - private var pointsForNextGreatPerson = 100 + @Deprecated("Values are now maintaned in pointsForNextGreatPersonCounter", ReplaceWith("pointsForNextGreatPersonCounter[\"\"]")) + var pointsForNextGreatPerson = 100 + var pointsForNextGreatPersonCounter = Counter() // Initial values assigned in getPointsRequiredForGreatPerson as needed var pointsForNextGreatGeneral = 200 var greatPersonPointsCounter = Counter() @@ -31,7 +34,7 @@ class GreatPersonManager : IsPartOfGameInfoSerialization { val toReturn = GreatPersonManager() toReturn.freeGreatPeople = freeGreatPeople toReturn.greatPersonPointsCounter = greatPersonPointsCounter.clone() - toReturn.pointsForNextGreatPerson = pointsForNextGreatPerson + toReturn.pointsForNextGreatPersonCounter = pointsForNextGreatPersonCounter.clone() toReturn.pointsForNextGreatGeneral = pointsForNextGreatGeneral toReturn.greatGeneralPoints = greatGeneralPoints toReturn.mayaLimitedFreeGP = mayaLimitedFreeGP @@ -39,7 +42,18 @@ class GreatPersonManager : IsPartOfGameInfoSerialization { return toReturn } - fun getPointsRequiredForGreatPerson() = (pointsForNextGreatPerson * civInfo.gameInfo.speed.modifier).toInt() + private fun getPoolKey(greatPerson: String) = civInfo.getEquivalentUnit(greatPerson) + .getMatchingUniques(UniqueType.GPPointPool) + // An empty string is used to indicate the Unique wasn't found + .firstOrNull()?.params?.get(0) ?: "" + + fun getPointsRequiredForGreatPerson(greatPerson: String): Int { + val key = getPoolKey(greatPerson) + if (pointsForNextGreatPersonCounter[key] == 0) { + pointsForNextGreatPersonCounter[key] = 100 + } + return (pointsForNextGreatPersonCounter[key] * civInfo.gameInfo.speed.modifier).toInt() + } fun getNewGreatPerson(): String? { if (greatGeneralPoints > pointsForNextGreatGeneral) { @@ -48,12 +62,12 @@ class GreatPersonManager : IsPartOfGameInfoSerialization { return "Great General" } - for ((key, value) in greatPersonPointsCounter) { - val requiredPoints = getPointsRequiredForGreatPerson() + for ((greatPerson, value) in greatPersonPointsCounter) { + val requiredPoints = getPointsRequiredForGreatPerson(greatPerson) if (value >= requiredPoints) { - greatPersonPointsCounter.add(key, -requiredPoints) - pointsForNextGreatPerson *= 2 - return key + greatPersonPointsCounter.add(greatPerson, -requiredPoints) + pointsForNextGreatPersonCounter[getPoolKey(greatPerson)] *= 2 + return greatPerson } } return null diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 45f7f50755..81ac08b4bd 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -532,6 +532,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: // Hurried means: sped up using great engineer/scientist ability, so this is in some sense a unit unique that should be here CannotBeHurried("Cannot be hurried", UniqueTarget.Building, UniqueTarget.Tech), GreatPerson("Great Person - [comment]", UniqueTarget.Unit), + GPPointPool("Is part of Great Person group [comment]", UniqueTarget.Unit), //endregion diff --git a/core/src/com/unciv/ui/screens/cityscreen/CityStatsTable.kt b/core/src/com/unciv/ui/screens/cityscreen/CityStatsTable.kt index f50b31d064..9f0b078f26 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/CityStatsTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/CityStatsTable.kt @@ -354,7 +354,7 @@ class CityStatsTable(private val cityScreen: CityScreen): Table() { info.add("{$greatPersonName} (+$gppPerTurn)".toLabel(hideIcons = true)).left().padBottom(4f).expandX().row() val gppCurrent = city.civ.greatPeople.greatPersonPointsCounter[greatPersonName] - val gppNeeded = city.civ.greatPeople.getPointsRequiredForGreatPerson() + val gppNeeded = city.civ.greatPeople.getPointsRequiredForGreatPerson(greatPersonName) val percent = gppCurrent / gppNeeded.toFloat() diff --git a/core/src/com/unciv/ui/screens/overviewscreen/StatsOverviewTab.kt b/core/src/com/unciv/ui/screens/overviewscreen/StatsOverviewTab.kt index f62101d51f..18e51d009a 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/StatsOverviewTab.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/StatsOverviewTab.kt @@ -204,8 +204,8 @@ class StatsOverviewTab( val greatPersonPoints = viewingPlayer.greatPeople.greatPersonPointsCounter val greatPersonPointsPerTurn = viewingPlayer.greatPeople.getGreatPersonPointsForNextTurn() - val pointsToGreatPerson = viewingPlayer.greatPeople.getPointsRequiredForGreatPerson() for ((greatPerson, points) in greatPersonPoints) { + val pointsToGreatPerson = viewingPlayer.greatPeople.getPointsRequiredForGreatPerson(greatPerson) add(greatPerson.toLabel()).left() add("$points/$pointsToGreatPerson".toLabel()) add(greatPersonPointsPerTurn[greatPerson].toLabel()).right().row()