From 4113b810ffad325711b8c7dad74011274df176a6 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Mon, 22 Nov 2021 20:53:08 +0200 Subject: [PATCH] Simplified civ info stats happiness breakdown --- .../unciv/logic/civilization/CivInfoStats.kt | 63 ++++++++----------- .../com/unciv/models/ruleset/unit/BaseUnit.kt | 10 --- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/CivInfoStats.kt b/core/src/com/unciv/logic/civilization/CivInfoStats.kt index 46a539397e..528a63f1a8 100644 --- a/core/src/com/unciv/logic/civilization/CivInfoStats.kt +++ b/core/src/com/unciv/logic/civilization/CivInfoStats.kt @@ -290,67 +290,54 @@ class CivInfoStats(val civInfo: CivilizationInfo) { statMap["Natural Wonders"] = happinessPerNaturalWonder * civInfo.naturalWonders.size if (civInfo.religionManager.religion != null) { - statMap["Religion"] = 0f + var religionHappiness = 0f for (unique in civInfo.religionManager.religion!!.getBeliefs(BeliefType.Founder) .flatMap { it.uniqueObjects }) { if (unique.placeholderText == "[] for each global city following this religion") { - statMap["Religion"] = - statMap["Religion"]!! + - unique.stats.happiness * civInfo.religionManager.numberOfCitiesFollowingThisReligion() - .toFloat() + val followingCities = + civInfo.religionManager.numberOfCitiesFollowingThisReligion() + religionHappiness += unique.stats.happiness * followingCities } if (unique.placeholderText == "[] for every [] global followers []") { - statMap["Religion"] = - statMap["Religion"]!! + - unique.stats.happiness * - civInfo.religionManager.numberOfFollowersFollowingThisReligion( - unique.params[2] - ).toFloat() / - unique.params[1].toFloat() + val followers = + civInfo.religionManager.numberOfFollowersFollowingThisReligion(unique.params[2]) + religionHappiness += + unique.stats.happiness * (followers / unique.params[1].toInt()) } } - if (statMap["Religion"] == 0f) - statMap.remove("Religion") + if (religionHappiness > 0) statMap["Religion"] = religionHappiness } //From city-states + var cityStatesHappiness = 0f for (otherCiv in civInfo.getKnownCivs()) { val relationshipLevel = otherCiv.getDiplomacyManager(civInfo).relationshipLevel() - if (otherCiv.isCityState() && relationshipLevel >= RelationshipLevel.Friend) { - val eraInfo = civInfo.getEra() + if (!otherCiv.isCityState() || relationshipLevel < RelationshipLevel.Friend) continue - if (!eraInfo.undefinedCityStateBonuses()) { - for (bonus in eraInfo.getCityStateBonuses(otherCiv.cityStateType, relationshipLevel)) { - if (!bonus.conditionalsApply(otherCiv)) continue - if (bonus.isOfType(UniqueType.CityStateHappiness)) { - if (statMap.containsKey("City-States")) - statMap["City-States"] = - statMap["City-States"]!! + bonus.params[0].toFloat() - else - statMap["City-States"] = bonus.params[0].toFloat() - } - } - } else { - // Deprecated, assume Civ V values for compatibility - if (otherCiv.cityStateType == CityStateType.Mercantile) { - val happinessBonus = if (civInfo.getEraNumber() in 0..1) 2f else 3f - if (statMap.containsKey("City-States")) - statMap["City-States"] = statMap["City-States"]!! + happinessBonus - else - statMap["City-States"] = happinessBonus - } + val eraInfo = civInfo.getEra() + // Deprecated, assume Civ V values for compatibility + if (!eraInfo.undefinedCityStateBonuses()) { + for (bonus in eraInfo.getCityStateBonuses(otherCiv.cityStateType, relationshipLevel)) { + if (!bonus.conditionalsApply(otherCiv)) continue + if (bonus.isOfType(UniqueType.CityStateHappiness)) + cityStatesHappiness += bonus.params[0].toFloat() } + } else if (otherCiv.cityStateType == CityStateType.Mercantile) { + // compatibility mode for + cityStatesHappiness += if (civInfo.getEraNumber() in 0..1) 2f else 3f } } // Just in case - if (statMap.containsKey("City-States")) { + if (cityStatesHappiness > 0) { for (unique in civInfo.getMatchingUniques("[]% [] from City-States")) { if (unique.params[1] == Stat.Happiness.name) - statMap["City-States"] = statMap["City-States"]!! * unique.params[0].toPercent() + cityStatesHappiness *= unique.params[0].toPercent() } } + if (cityStatesHappiness > 0) statMap["City-States"] = cityStatesHappiness + return statMap } diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index a932510960..50ce34171e 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -665,22 +665,12 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction { unique.isOfType(UniqueType.StrengthNearCapital) && unique.params[0].toInt() > 0 -> power *= (unique.params[0].toInt() / 4f).toPercent() // Bonus decreasing with distance from capital - not worth much most of the map??? - // Deprecated since 3.17.4 - unique.isOfType(UniqueType.StrengthAttacking) // Attack - half the bonus - -> power += (power * unique.params[0].toInt()) / 200 - unique.isOfType(UniqueType.StrengthDefending) // Defense - half the bonus - -> power += (power * unique.params[0].toInt()) / 200 - // unique.placeholderText == "May Paradrop up to [] tiles from inside friendly territory" // Paradrop - 25% bonus -> power += power / 4 unique.isOfType(UniqueType.MustSetUp) // Must set up - 20 % penalty -> power -= power / 5 unique.placeholderText == "[] additional attacks per turn" // Extra attacks - 20% bonus per extra attack -> power += (power * unique.params[0].toInt()) / 5 - // Deprecated since 3.17.5 - unique.isOfType(UniqueType.StrengthIn) // Bonus in terrain or feature - half the bonus - -> power += (power * unique.params[0].toInt()) / 200 - // } }