mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-25 22:59:12 +07:00
Part 1 of "generic Great Person points" - changed data type serialized in save to be stat-agnostic
This commit is contained in:
parent
6791dd3340
commit
cbfd658480
@ -316,6 +316,13 @@ class GameInfo {
|
||||
|
||||
cityInfo.cityStats.update()
|
||||
}
|
||||
|
||||
if(!civInfo.greatPeople.greatPersonPoints.isEmpty()) {
|
||||
civInfo.greatPeople.greatPersonPointsCounter.add(
|
||||
GreatPersonManager.statsToGreatPersonCounter(civInfo.greatPeople.greatPersonPoints)
|
||||
)
|
||||
civInfo.greatPeople.greatPersonPoints.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,16 @@
|
||||
package com.unciv.logic.civilization
|
||||
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
|
||||
class GreatPersonManager {
|
||||
var pointsForNextGreatPerson = 100
|
||||
var pointsForNextGreatGeneral = 30
|
||||
|
||||
@Deprecated("As of 3.15.15 - Should be converted to greatPersonPointsCounter")
|
||||
var greatPersonPoints = Stats()
|
||||
var greatPersonPointsCounter = Counter<String>()
|
||||
var greatGeneralPoints = 0
|
||||
var freeGreatPeople = 0
|
||||
|
||||
@ -17,12 +21,29 @@ class GreatPersonManager {
|
||||
Stat.Gold to "Great Merchant",
|
||||
Stat.Culture to "Great Artist",
|
||||
)
|
||||
|
||||
fun statsToGreatPersonCounter(stats: Stats): Counter<String> {
|
||||
val counter = Counter<String>()
|
||||
for ((key, value) in stats.toHashMap())
|
||||
if (statToGreatPersonMapping.containsKey(key))
|
||||
counter.add(statToGreatPersonMapping[key]!!, value.toInt())
|
||||
return counter
|
||||
}
|
||||
|
||||
fun greatPersonCounterToStats(counter: Counter<String>): Stats {
|
||||
val stats = Stats()
|
||||
for ((key, value) in counter) {
|
||||
val stat = statToGreatPersonMapping.entries.firstOrNull { it.value == key }?.key
|
||||
if (stat != null) stats.add(stat, value.toFloat())
|
||||
}
|
||||
return stats
|
||||
}
|
||||
}
|
||||
|
||||
fun clone(): GreatPersonManager {
|
||||
val toReturn = GreatPersonManager()
|
||||
toReturn.freeGreatPeople = freeGreatPeople
|
||||
toReturn.greatPersonPoints = greatPersonPoints.clone()
|
||||
toReturn.greatPersonPointsCounter = greatPersonPointsCounter.clone()
|
||||
toReturn.pointsForNextGreatPerson = pointsForNextGreatPerson
|
||||
toReturn.pointsForNextGreatGeneral = pointsForNextGreatGeneral
|
||||
toReturn.greatGeneralPoints = greatGeneralPoints
|
||||
@ -38,19 +59,19 @@ class GreatPersonManager {
|
||||
return "Great General"
|
||||
}
|
||||
|
||||
val greatPersonPointsHashmap = greatPersonPoints.toHashMap()
|
||||
for (entry in statToGreatPersonMapping) {
|
||||
if (greatPersonPointsHashmap[entry.key]!! > pointsForNextGreatPerson) {
|
||||
greatPersonPoints.add(entry.key, -pointsForNextGreatPerson.toFloat())
|
||||
for ((key, value) in greatPersonPointsCounter) {
|
||||
if (value > pointsForNextGreatPerson) {
|
||||
greatPersonPointsCounter.add(key, -pointsForNextGreatPerson)
|
||||
pointsForNextGreatPerson *= 2
|
||||
return entry.value
|
||||
return key
|
||||
}
|
||||
}
|
||||
return greatPerson
|
||||
}
|
||||
|
||||
fun addGreatPersonPoints(greatPersonPointsForTurn: Stats) {
|
||||
greatPersonPoints.add(greatPersonPointsForTurn)
|
||||
greatPersonPointsCounter.add(statsToGreatPersonCounter(greatPersonPointsForTurn))
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -19,15 +19,17 @@ open class Counter<K> : LinkedHashMap<K, Int>() {
|
||||
}
|
||||
|
||||
fun add(other: Counter<K>) {
|
||||
for (key in other.keys) {
|
||||
add(key, other[key]!!)
|
||||
}
|
||||
for (key in other.keys) add(key, other[key]!!)
|
||||
}
|
||||
|
||||
fun remove(other: Counter<K>) {
|
||||
for (key in other.keys) {
|
||||
add(key, -other[key]!!)
|
||||
}
|
||||
for (key in other.keys) add(key, -other[key]!!)
|
||||
}
|
||||
|
||||
fun times(amount:Int): Counter<K> {
|
||||
val newCounter = Counter<K>()
|
||||
for (key in keys) newCounter[key] = this[key]!! * amount
|
||||
return newCounter
|
||||
}
|
||||
|
||||
override fun clone(): Counter<K> {
|
||||
|
@ -105,7 +105,9 @@ class StatsOverviewTable (
|
||||
private fun getGreatPeopleTable(): Table {
|
||||
val greatPeopleTable = Table(CameraStageBaseScreen.skin)
|
||||
|
||||
val greatPersonPoints = viewingPlayer.greatPeople.greatPersonPoints.toHashMap()
|
||||
val greatPersonPoints = GreatPersonManager
|
||||
.greatPersonCounterToStats(viewingPlayer.greatPeople.greatPersonPointsCounter)
|
||||
.toHashMap()
|
||||
val greatPersonPointsPerTurn = viewingPlayer.getGreatPersonPointsForNextTurn().toHashMap()
|
||||
val pointsToGreatPerson = viewingPlayer.greatPeople.pointsForNextGreatPerson
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user