mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-09 20:29:50 +07:00
Resolved #8200 - get correct civ-wide stats from City-States with the correct unique
This commit is contained in:
parent
9f6aa4b90f
commit
8d98062a76
@ -256,7 +256,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
return statMap
|
||||
}
|
||||
|
||||
fun getGlobalStatsFromUniques():StatMap{
|
||||
fun getGlobalStatsFromUniques():StatMap {
|
||||
val statMap = StatMap()
|
||||
if (civInfo.religionManager.religion != null) {
|
||||
for (unique in civInfo.religionManager.religion!!.getFounderUniques()) {
|
||||
@ -269,13 +269,16 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
if (unique.isOfType(UniqueType.StatsFromGlobalFollowers))
|
||||
statMap.add(
|
||||
"Religion",
|
||||
unique.stats * civInfo.religionManager.numberOfFollowersFollowingThisReligion(unique.params[2]).toFloat() / unique.params[1].toFloat()
|
||||
unique.stats * civInfo.religionManager.numberOfFollowersFollowingThisReligion(
|
||||
unique.params[2]
|
||||
).toFloat() / unique.params[1].toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
for (unique in civInfo.getMatchingUniques(UniqueType.StatsPerPolicies)) {
|
||||
val amount = civInfo.policies.getAdoptedPolicies().count { !Policy.isBranchCompleteByName(it) } / unique.params[1].toInt()
|
||||
val amount = civInfo.policies.getAdoptedPolicies()
|
||||
.count { !Policy.isBranchCompleteByName(it) } / unique.params[1].toInt()
|
||||
statMap.add("Policies", unique.stats.times(amount))
|
||||
}
|
||||
|
||||
@ -292,6 +295,14 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
|
||||
statMap.add("Natural Wonders", statsPerNaturalWonder.times(civInfo.naturalWonders.size))
|
||||
|
||||
if (statMap.contains(UniqueTarget.CityState.name)) {
|
||||
for (unique in civInfo.getMatchingUniques(UniqueType.BonusStatsFromCityStates)) {
|
||||
val bonusPercent = unique.params[0].toPercent()
|
||||
val bonusStat = Stat.valueOf(unique.params[1])
|
||||
statMap[UniqueTarget.CityState.name]!![bonusStat] *= bonusPercent
|
||||
}
|
||||
}
|
||||
|
||||
return statMap
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ open class Stats(
|
||||
}
|
||||
|
||||
/** Adds each value of another [Stats] instance to this one in place */
|
||||
fun add(other: Stats) {
|
||||
fun add(other: Stats): Stats {
|
||||
production += other.production
|
||||
food += other.food
|
||||
gold += other.gold
|
||||
@ -89,6 +89,7 @@ open class Stats(
|
||||
culture += other.culture
|
||||
happiness += other.happiness
|
||||
faith += other.faith
|
||||
return this
|
||||
}
|
||||
|
||||
/** @return a new [Stats] instance containing the sum of its operands value by value */
|
||||
@ -239,9 +240,8 @@ open class Stats(
|
||||
|
||||
class StatMap:LinkedHashMap<String,Stats>() {
|
||||
fun add(source: String, stats: Stats) {
|
||||
if (!containsKey(source)) put(source, stats)
|
||||
else put(source, get(source)!! + stats)
|
||||
// This CAN'T be get(source)!!.add() because the initial stats we get are sometimes from other places -
|
||||
// for instance the Cities is from the currentCityStats and if we add to that we change the value in the cities themselves!
|
||||
// We always clone to avoid touching the mutable stats of uniques
|
||||
if (!containsKey(source)) put(source, stats.clone())
|
||||
else get(source)!!.add(stats)
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ import com.unciv.models.ruleset.Quest
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.translations.fillPlaceholders
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.audio.MusicMood
|
||||
@ -48,7 +47,6 @@ import com.unciv.ui.utils.extensions.onClick
|
||||
import com.unciv.ui.utils.extensions.setFontSize
|
||||
import com.unciv.ui.utils.extensions.surroundWithCircle
|
||||
import com.unciv.ui.utils.extensions.toLabel
|
||||
import com.unciv.ui.utils.extensions.toPercent
|
||||
import com.unciv.ui.utils.extensions.toTextButton
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.roundToInt
|
||||
@ -246,15 +244,13 @@ class DiplomacyScreen(
|
||||
}
|
||||
diplomacyTable.row().padTop(15f)
|
||||
|
||||
var friendBonusText = "{When Friends:}\n".tr()
|
||||
var friendBonusText = "When Friends:".tr()+"\n"
|
||||
val friendBonusObjects = viewingCiv.cityStateFunctions.getCityStateBonuses(otherCiv.cityStateType, RelationshipLevel.Friend)
|
||||
val friendBonusStrings = getAdjustedBonuses(friendBonusObjects)
|
||||
friendBonusText += friendBonusStrings.joinToString(separator = "\n") { it.tr() }
|
||||
friendBonusText += friendBonusObjects.joinToString(separator = "\n") { it.text.tr() }
|
||||
|
||||
var allyBonusText = "{When Allies:}\n".tr()
|
||||
var allyBonusText = "When Allies:".tr()+"\n"
|
||||
val allyBonusObjects = viewingCiv.cityStateFunctions.getCityStateBonuses(otherCiv.cityStateType, RelationshipLevel.Ally)
|
||||
val allyBonusStrings = getAdjustedBonuses(allyBonusObjects)
|
||||
allyBonusText += allyBonusStrings.joinToString(separator = "\n") { it.tr() }
|
||||
allyBonusText += allyBonusObjects.joinToString(separator = "\n") { it.text.tr() }
|
||||
|
||||
val relationLevel = otherCivDiplomacyManager.relationshipLevel()
|
||||
if (relationLevel >= RelationshipLevel.Friend) {
|
||||
@ -284,40 +280,9 @@ class DiplomacyScreen(
|
||||
return diplomacyTable
|
||||
}
|
||||
|
||||
/** Given a list of [bonuses], returns a list of pretty strings with updated values for Siam-like uniques
|
||||
* Assumes that each bonus contains only one stat type */
|
||||
private fun getAdjustedBonuses(bonuses: Sequence<Unique>): List<String> {
|
||||
val bonusStrings = ArrayList<String>()
|
||||
for (bonus in bonuses) {
|
||||
var improved = false
|
||||
for (unique in viewingCiv.getMatchingUniques(UniqueType.StatBonusPercentFromCityStates)) {
|
||||
val boostAmount = unique.params[0].toPercent()
|
||||
val boostedStat = Stat.valueOf(unique.params[1])
|
||||
when (bonus.type) {
|
||||
UniqueType.Stats -> { // "[+3 Faith]"
|
||||
if (bonus.stats[boostedStat] > 0) {
|
||||
bonusStrings.add(
|
||||
bonus.text.fillPlaceholders(
|
||||
(bonus.stats * boostAmount).toStringWithDecimals()))
|
||||
improved = true
|
||||
}
|
||||
}
|
||||
UniqueType.StatsPerCity -> { // "[+1 Food] [in every city]"
|
||||
if (bonus.stats[boostedStat] > 0) {
|
||||
bonusStrings.add(
|
||||
bonus.text.fillPlaceholders(
|
||||
(bonus.stats * boostAmount).toStringWithDecimals(), bonus.params[1]))
|
||||
improved = true
|
||||
}
|
||||
}
|
||||
else -> Unit // To silence "exhaustive when" warning
|
||||
}
|
||||
}
|
||||
// No matching unique, add it unmodified
|
||||
if (!improved)
|
||||
bonusStrings.add(bonus.text)
|
||||
}
|
||||
return bonusStrings
|
||||
fun fillUniquePlaceholders(unique:Unique, vararg strings: String):String {
|
||||
return unique.placeholderText.fillPlaceholders(*strings) + unique.conditionals.map { " <${it.text}>" }
|
||||
.joinToString("")
|
||||
}
|
||||
|
||||
private fun getCityStateDiplomacyTable(otherCiv: CivilizationInfo): Table {
|
||||
|
Loading…
Reference in New Issue
Block a user