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
This commit is contained in:
SeventhM 2023-06-24 23:36:33 -07:00 committed by GitHub
parent aa0fb9ed8b
commit 1285133884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 10 deletions

View File

@ -202,4 +202,15 @@ object BackwardCompatibility {
} }
historyStartTurn = turns historyStartTurn = turns
} }
fun GameInfo.migrateGreatPersonPools() {
for (civ in civilizations) civ.greatPeople.run {
if (pointsForNextGreatPerson >= pointsForNextGreatPersonCounter[""]) {
pointsForNextGreatPersonCounter[""] = pointsForNextGreatPerson
}
else {
pointsForNextGreatPerson = pointsForNextGreatPersonCounter[""]
}
}
}
} }

View File

@ -8,6 +8,7 @@ import com.unciv.logic.BackwardCompatibility.convertEncampmentData
import com.unciv.logic.BackwardCompatibility.convertFortify import com.unciv.logic.BackwardCompatibility.convertFortify
import com.unciv.logic.BackwardCompatibility.guaranteeUnitPromotions import com.unciv.logic.BackwardCompatibility.guaranteeUnitPromotions
import com.unciv.logic.BackwardCompatibility.migrateToTileHistory import com.unciv.logic.BackwardCompatibility.migrateToTileHistory
import com.unciv.logic.BackwardCompatibility.migrateGreatPersonPools
import com.unciv.logic.BackwardCompatibility.removeMissingModReferences import com.unciv.logic.BackwardCompatibility.removeMissingModReferences
import com.unciv.logic.GameInfo.Companion.CURRENT_COMPATIBILITY_NUMBER import com.unciv.logic.GameInfo.Companion.CURRENT_COMPATIBILITY_NUMBER
import com.unciv.logic.GameInfo.Companion.FIRST_WITHOUT import com.unciv.logic.GameInfo.Companion.FIRST_WITHOUT
@ -602,6 +603,8 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
guaranteeUnitPromotions() guaranteeUnitPromotions()
migrateToTileHistory() migrateToTileHistory()
migrateGreatPersonPools()
} }
private fun updateCivilizationState() { private fun updateCivilizationState() {

View File

@ -6,6 +6,7 @@ import com.unciv.models.Counter
import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.ruleset.unit.BaseUnit
// todo: Great Admiral? // todo: Great Admiral?
// todo: Free GP from policies and wonders should increase threshold according to the wiki // 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 // todo: GP from Maya long count should increase threshold as well - implement together
@ -16,7 +17,9 @@ class GreatPersonManager : IsPartOfGameInfoSerialization {
lateinit var civInfo: Civilization lateinit var civInfo: Civilization
/** Base points, without speed modifier */ /** Base points, without speed modifier */
private var pointsForNextGreatPerson = 100 @Deprecated("Values are now maintaned in pointsForNextGreatPersonCounter", ReplaceWith("pointsForNextGreatPersonCounter[\"\"]"))
var pointsForNextGreatPerson = 100
var pointsForNextGreatPersonCounter = Counter<String>() // Initial values assigned in getPointsRequiredForGreatPerson as needed
var pointsForNextGreatGeneral = 200 var pointsForNextGreatGeneral = 200
var greatPersonPointsCounter = Counter<String>() var greatPersonPointsCounter = Counter<String>()
@ -31,7 +34,7 @@ class GreatPersonManager : IsPartOfGameInfoSerialization {
val toReturn = GreatPersonManager() val toReturn = GreatPersonManager()
toReturn.freeGreatPeople = freeGreatPeople toReturn.freeGreatPeople = freeGreatPeople
toReturn.greatPersonPointsCounter = greatPersonPointsCounter.clone() toReturn.greatPersonPointsCounter = greatPersonPointsCounter.clone()
toReturn.pointsForNextGreatPerson = pointsForNextGreatPerson toReturn.pointsForNextGreatPersonCounter = pointsForNextGreatPersonCounter.clone()
toReturn.pointsForNextGreatGeneral = pointsForNextGreatGeneral toReturn.pointsForNextGreatGeneral = pointsForNextGreatGeneral
toReturn.greatGeneralPoints = greatGeneralPoints toReturn.greatGeneralPoints = greatGeneralPoints
toReturn.mayaLimitedFreeGP = mayaLimitedFreeGP toReturn.mayaLimitedFreeGP = mayaLimitedFreeGP
@ -39,7 +42,18 @@ class GreatPersonManager : IsPartOfGameInfoSerialization {
return toReturn 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? { fun getNewGreatPerson(): String? {
if (greatGeneralPoints > pointsForNextGreatGeneral) { if (greatGeneralPoints > pointsForNextGreatGeneral) {
@ -48,12 +62,12 @@ class GreatPersonManager : IsPartOfGameInfoSerialization {
return "Great General" return "Great General"
} }
for ((key, value) in greatPersonPointsCounter) { for ((greatPerson, value) in greatPersonPointsCounter) {
val requiredPoints = getPointsRequiredForGreatPerson() val requiredPoints = getPointsRequiredForGreatPerson(greatPerson)
if (value >= requiredPoints) { if (value >= requiredPoints) {
greatPersonPointsCounter.add(key, -requiredPoints) greatPersonPointsCounter.add(greatPerson, -requiredPoints)
pointsForNextGreatPerson *= 2 pointsForNextGreatPersonCounter[getPoolKey(greatPerson)] *= 2
return key return greatPerson
} }
} }
return null return null

View File

@ -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 // 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), CannotBeHurried("Cannot be hurried", UniqueTarget.Building, UniqueTarget.Tech),
GreatPerson("Great Person - [comment]", UniqueTarget.Unit), GreatPerson("Great Person - [comment]", UniqueTarget.Unit),
GPPointPool("Is part of Great Person group [comment]", UniqueTarget.Unit),
//endregion //endregion

View File

@ -354,7 +354,7 @@ class CityStatsTable(private val cityScreen: CityScreen): Table() {
info.add("{$greatPersonName} (+$gppPerTurn)".toLabel(hideIcons = true)).left().padBottom(4f).expandX().row() info.add("{$greatPersonName} (+$gppPerTurn)".toLabel(hideIcons = true)).left().padBottom(4f).expandX().row()
val gppCurrent = city.civ.greatPeople.greatPersonPointsCounter[greatPersonName] 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() val percent = gppCurrent / gppNeeded.toFloat()

View File

@ -204,8 +204,8 @@ class StatsOverviewTab(
val greatPersonPoints = viewingPlayer.greatPeople.greatPersonPointsCounter val greatPersonPoints = viewingPlayer.greatPeople.greatPersonPointsCounter
val greatPersonPointsPerTurn = viewingPlayer.greatPeople.getGreatPersonPointsForNextTurn() val greatPersonPointsPerTurn = viewingPlayer.greatPeople.getGreatPersonPointsForNextTurn()
val pointsToGreatPerson = viewingPlayer.greatPeople.getPointsRequiredForGreatPerson()
for ((greatPerson, points) in greatPersonPoints) { for ((greatPerson, points) in greatPersonPoints) {
val pointsToGreatPerson = viewingPlayer.greatPeople.getPointsRequiredForGreatPerson(greatPerson)
add(greatPerson.toLabel()).left() add(greatPerson.toLabel()).left()
add("$points/$pointsToGreatPerson".toLabel()) add("$points/$pointsToGreatPerson".toLabel())
add(greatPersonPointsPerTurn[greatPerson].toLabel()).right().row() add(greatPersonPointsPerTurn[greatPerson].toLabel()).right().row()