mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 05:14:32 -04:00
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:
parent
aa0fb9ed8b
commit
1285133884
@ -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[""]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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<String>() // Initial values assigned in getPointsRequiredForGreatPerson as needed
|
||||
var pointsForNextGreatGeneral = 200
|
||||
|
||||
var greatPersonPointsCounter = Counter<String>()
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user