Converted building GPP from stats to counter

This commit is contained in:
Yair Morgenstern 2021-07-23 15:25:11 +03:00
parent 2c050283b0
commit 0ed47f10a8
3 changed files with 35 additions and 26 deletions

View File

@ -323,15 +323,16 @@ class CityInfo {
for ((specialistName, amount) in population.getNewSpecialists())
if (getRuleset().specialists.containsKey(specialistName)) { // To solve problems in total remake mods
val specialist = getRuleset().specialists[specialistName]!!
specialistsCounter.add(GreatPersonManager.statsToGreatPersonCounter(specialist.greatPersonPoints)
.times(amount))
specialistsCounter.add(
GreatPersonManager.statsToGreatPersonCounter(specialist.greatPersonPoints)
.times(amount)
)
}
sourceToGPP["Specialists"] = specialistsCounter
val buildingsCounter = Counter<String>()
for (building in cityConstructions.getBuiltBuildings())
if (building.greatPersonPoints != null)
buildingsCounter.add(GreatPersonManager.statsToGreatPersonCounter(building.greatPersonPoints!!))
buildingsCounter.add(building.greatPersonPoints)
sourceToGPP["Buildings"] = buildingsCounter
for ((source, gppCounter) in sourceToGPP) {
@ -349,11 +350,13 @@ class CityInfo {
// Sweden UP
for (otherciv in civInfo.getKnownCivs()) {
if (!civInfo.getDiplomacyManager(otherciv).hasFlag(DiplomacyFlags.DeclarationOfFriendship)) continue
if (!civInfo.getDiplomacyManager(otherciv)
.hasFlag(DiplomacyFlags.DeclarationOfFriendship)
) continue
for(ourunique in civInfo.getMatchingUniques("When declaring friendship, both parties gain a []% boost to great person generation"))
for (ourunique in civInfo.getMatchingUniques("When declaring friendship, both parties gain a []% boost to great person generation"))
allGppPercentageBonus += ourunique.params[0].toInt()
for(theirunique in otherciv.getMatchingUniques("When declaring friendship, both parties gain a []% boost to great person generation"))
for (theirunique in otherciv.getMatchingUniques("When declaring friendship, both parties gain a []% boost to great person generation"))
allGppPercentageBonus += theirunique.params[0].toInt()
}
@ -361,6 +364,20 @@ class CityInfo {
gppCounter.add(unitName, gppCounter[unitName]!! * allGppPercentageBonus / 100)
}
// Since existing buildings and specialists have *stat names* rather than Great Person names
// as the keys, convert every stat name to the appropriate Great Person name instead
for (counter in sourceToGPP.values)
for ((key, gppAmount) in counter.toMap()) { // since we're removing, copy to avoid concurrency problems
val relevantStatEntry = GreatPersonManager.statToGreatPersonMapping
.entries.firstOrNull { it.key.name.equals(key, true) }
if (relevantStatEntry == null) continue
counter.add(relevantStatEntry.value, gppAmount)
counter.remove(key)
}
return sourceToGPP
}

View File

@ -6,7 +6,8 @@ open class Counter<K> : LinkedHashMap<K, Int>() {
override operator fun get(key: K): Int? { // don't return null if empty
if (containsKey(key))
return super.get(key)
// .toInt(), because GDX deserializes Counter values as *floats* for some reason
return super.get(key)!!.toInt()
else return 0
}

View File

@ -4,7 +4,6 @@ import com.unciv.logic.city.CityConstructions
import com.unciv.logic.city.CityInfo
import com.unciv.logic.city.IConstruction
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.GreatPersonManager
import com.unciv.models.Counter
import com.unciv.models.ruleset.tile.TileImprovement
import com.unciv.models.stats.NamedStats
@ -42,7 +41,7 @@ class Building : NamedStats(), IConstruction, ICivilopediaText {
return counter
}
var greatPersonPoints: Stats? = null
var greatPersonPoints= Counter<String>()
/** Extra cost percentage when purchasing */
private var hurryCostModifier = 0
@ -136,13 +135,8 @@ class Building : NamedStats(), IConstruction, ICivilopediaText {
if (percentStats.food != 0f) stringBuilder.append("+" + percentStats.food.toInt() + "% {Food}\n".tr())
if (percentStats.culture != 0f) stringBuilder.append("+" + percentStats.culture.toInt() + "% {Culture}\r\n".tr())
if (this.greatPersonPoints != null) {
val gpp = this.greatPersonPoints!!
if (gpp.production != 0f) stringBuilder.appendLine("+" + gpp.production.toInt() + " " + "[Great Engineer] points".tr())
if (gpp.gold != 0f) stringBuilder.appendLine("+" + gpp.gold.toInt() + " " + "[Great Merchant] points".tr())
if (gpp.science != 0f) stringBuilder.appendLine("+" + gpp.science.toInt() + " " + "[Great Scientist] points".tr())
if (gpp.culture != 0f) stringBuilder.appendLine("+" + gpp.culture.toInt() + " " + "[Great Artist] points".tr())
}
for((greatPersonName, value) in greatPersonPoints)
stringBuilder.appendLine("+$value "+"[$greatPersonName] points".tr())
for ((specialistName, amount) in newSpecialists())
stringBuilder.appendLine("+$amount " + "[$specialistName] slots".tr())
@ -260,7 +254,7 @@ class Building : NamedStats(), IConstruction, ICivilopediaText {
val stats = this.clone()
val percentStats = getStatPercentageBonuses(null)
val specialists = newSpecialists()
if (uniques.isNotEmpty() || !stats.isEmpty() || !percentStats.isEmpty() || this.greatPersonPoints != null || specialists.isNotEmpty())
if (uniques.isNotEmpty() || !stats.isEmpty() || !percentStats.isEmpty() || this.greatPersonPoints.isNotEmpty() || specialists.isNotEmpty())
textList += FormattedLine()
if (uniques.isNotEmpty()) {
@ -282,14 +276,11 @@ class Building : NamedStats(), IConstruction, ICivilopediaText {
}
}
if (greatPersonPoints != null) {
for ( (key, value) in greatPersonPoints!!.toHashMap()) {
if (value == 0f) continue
val gppName = GreatPersonManager.statToGreatPersonMapping[key]
?: continue
textList += FormattedLine(value.formatSignedInt() + " " + "[$gppName] points".tr(),
link = "Unit/$gppName")
}
for((greatPersonName, value) in greatPersonPoints) {
textList += FormattedLine(
"+$value " + "[$greatPersonName] points".tr(),
link = "Unit/$greatPersonName"
)
}
if (specialists.isNotEmpty()) {