From 053f5b944208506ea4119b9bc30825c06b811b3e Mon Sep 17 00:00:00 2001 From: yairm210 Date: Thu, 1 Aug 2024 18:59:22 +0300 Subject: [PATCH] chore: retire deprecated uniques --- .../civilization/ReligionAutomation.kt | 6 ++--- .../city/managers/CityReligionManager.kt | 7 ++--- .../com/unciv/logic/map/mapunit/MapUnit.kt | 27 ------------------- .../models/ruleset/unique/Conditionals.kt | 9 ------- .../unciv/models/ruleset/unique/UniqueType.kt | 27 +++++++++---------- .../ruleset/validation/UniqueValidator.kt | 10 ++++--- .../com/unciv/uniques/GlobalUniquesTests.kt | 2 +- 7 files changed, 24 insertions(+), 64 deletions(-) diff --git a/core/src/com/unciv/logic/automation/civilization/ReligionAutomation.kt b/core/src/com/unciv/logic/automation/civilization/ReligionAutomation.kt index 61a81d11ba0d1..7c3ec0be1657f 100644 --- a/core/src/com/unciv/logic/automation/civilization/ReligionAutomation.kt +++ b/core/src/com/unciv/logic/automation/civilization/ReligionAutomation.kt @@ -355,7 +355,7 @@ object ReligionAutomation { 15f * if (civInfo.wantsToFocusOn(Victory.Focus.Military)) 2f else 1f UniqueType.StatsWhenSpreading -> unique.params[0].toFloat() / 5f - UniqueType.StatsWhenAdoptingReligion, UniqueType.StatsWhenAdoptingReligionSpeed -> + UniqueType.StatsWhenAdoptingReligion -> unique.stats.values.sum() / 50f UniqueType.RestingPointOfCityStatesFollowingReligionChange -> if (civInfo.wantsToFocusOn(Victory.Focus.CityStates)) @@ -366,8 +366,6 @@ object ReligionAutomation { unique.stats.values.sum() UniqueType.StatsFromGlobalFollowers -> 4f * (unique.stats.values.sum() / unique.params[1].toFloat()) - UniqueType.ProvidesStatsWheneverGreatPersonExpended -> - unique.stats.values.sum() / 2f UniqueType.Strength -> unique.params[0].toFloat() / 4f UniqueType.ReligionSpreadDistance -> @@ -451,7 +449,7 @@ object ReligionAutomation { // belief less than make the game crash. The `continue`s should only be reached whenever // there are not enough beliefs to choose, but there should be, as otherwise we could // not have used a great prophet to found/enhance our religion. - for (belief in BeliefType.values()) { + for (belief in BeliefType.entries) { if (belief == BeliefType.None) continue repeat(beliefsToChoose[belief]) { chosenBeliefs.add( diff --git a/core/src/com/unciv/logic/city/managers/CityReligionManager.kt b/core/src/com/unciv/logic/city/managers/CityReligionManager.kt index c9f71ea8d1980..99a42bdc5f208 100644 --- a/core/src/com/unciv/logic/city/managers/CityReligionManager.kt +++ b/core/src/com/unciv/logic/city/managers/CityReligionManager.kt @@ -112,12 +112,9 @@ class CityReligionManager : IsPartOfGameInfoSerialization { if (newMajorityReligion in religionsAtSomePointAdopted) return val religionOwningCiv = newMajorityReligionObject.getFounder() - if (religionOwningCiv.hasUnique(UniqueType.StatsWhenAdoptingReligionSpeed) || religionOwningCiv.hasUnique(UniqueType.StatsWhenAdoptingReligion)) { + if (religionOwningCiv.hasUnique(UniqueType.StatsWhenAdoptingReligion)) { val statsGranted = - ( - religionOwningCiv.getMatchingUniques(UniqueType.StatsWhenAdoptingReligionSpeed) - + religionOwningCiv.getMatchingUniques(UniqueType.StatsWhenAdoptingReligion) - ).map { it.stats.times(if (!it.isModifiedByGameSpeed()) 1f else city.civ.gameInfo.speed.modifier) } + religionOwningCiv.getMatchingUniques(UniqueType.StatsWhenAdoptingReligion).map { it.stats.times(if (!it.isModifiedByGameSpeed()) 1f else city.civ.gameInfo.speed.modifier) } .reduce { acc, stats -> acc + stats } for ((key, value) in statsGranted) diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index 686d5a5663545..a16edc7d4ecef 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -24,7 +24,6 @@ import com.unciv.models.ruleset.unique.UniqueTriggerActivation import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.ruleset.unit.UnitType -import com.unciv.models.stats.Stats import com.unciv.models.translations.tr import com.unciv.ui.components.UnitMovementMemoryType import java.text.DecimalFormat @@ -815,7 +814,6 @@ class MapUnit : IsPartOfGameInfoSerialization { /** Destroys the unit and gives stats if its a great person */ fun consume() { - addStatsPerGreatPersonUsage() for (unique in civ.getTriggeredUniques(UniqueType.TriggerUponExpendingUnit)) if (unique.conditionals.any { it.type == UniqueType.TriggerUponExpendingUnit && matchesFilter(it.params[0]) }) UniqueTriggerActivation.triggerUnique(unique, this, @@ -823,31 +821,6 @@ class MapUnit : IsPartOfGameInfoSerialization { destroy() } - private fun addStatsPerGreatPersonUsage() { - if (!isGreatPerson()) return - - val gainedStats = Stats() - for (unique in civ.getMatchingUniques(UniqueType.ProvidesGoldWheneverGreatPersonExpended)) { - gainedStats.gold += (100 * civ.gameInfo.speed.goldCostModifier).toInt() - } - val speedModifiers = civ.gameInfo.speed.statCostModifiers - for (unique in civ.getMatchingUniques(UniqueType.ProvidesStatsWheneverGreatPersonExpended)) { - val uniqueStats = unique.stats.clone() - for ((stat, value) in uniqueStats) { - uniqueStats[stat] = value * speedModifiers[stat]!! - } - gainedStats.add(uniqueStats) - } - - if (gainedStats.isEmpty()) return - - for (stat in gainedStats) - civ.addStat(stat.key, stat.value.toInt()) - - civ.addNotification("By expending your [$name] you gained [${gainedStats.toStringForNotifications()}]!", - getTile().position, NotificationCategory.Units, name) - } - fun removeFromTile() = currentTile.removeUnit(this) diff --git a/core/src/com/unciv/models/ruleset/unique/Conditionals.kt b/core/src/com/unciv/models/ruleset/unique/Conditionals.kt index e14072608ab7d..96f93df2b95a8 100644 --- a/core/src/com/unciv/models/ruleset/unique/Conditionals.kt +++ b/core/src/com/unciv/models/ruleset/unique/Conditionals.kt @@ -127,15 +127,6 @@ object Conditionals { UniqueType.ConditionalWhenBetweenStatResource -> checkResourceOrStatAmount(conditional.params[2], conditional.params[0].toFloat(), conditional.params[1].toFloat(), unique?.isModifiedByGameSpeed() == true) { current, lowerLimit, upperLimit -> current >= lowerLimit && current <= upperLimit } - UniqueType.ConditionalWhenAboveAmountStatResourceSpeed -> - checkResourceOrStatAmount(conditional.params[1], conditional.params[0].toFloat(), Float.MAX_VALUE, true) - { current, lowerLimit, _ -> current > lowerLimit } - UniqueType.ConditionalWhenBelowAmountStatResourceSpeed -> - checkResourceOrStatAmount(conditional.params[1], Float.MIN_VALUE, conditional.params[0].toFloat(), true) - { current, _, upperLimit -> current < upperLimit } - UniqueType.ConditionalWhenBetweenStatResourceSpeed -> - checkResourceOrStatAmount(conditional.params[2], conditional.params[0].toFloat(), conditional.params[1].toFloat(), true) - { current, lowerLimit, upperLimit -> current >= lowerLimit && current <= upperLimit } UniqueType.ConditionalHappy -> checkOnCiv { stats.happiness >= 0 } UniqueType.ConditionalBetweenHappiness -> diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 0a59ab92639e9..acb29b973559d 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -154,10 +154,6 @@ enum class UniqueType( /// Great Persons GreatPersonPointPercentage("[relativeAmount]% Great Person generation [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief), - @Deprecated("As of 4.11.19", ReplaceWith("Gain [100] [Gold] <(modified by game speed)>")) - ProvidesGoldWheneverGreatPersonExpended("Provides a sum of gold each time you spend a Great Person", UniqueTarget.Global), - @Deprecated("As of 4.11.19", ReplaceWith("Gain [amount] [stat] <(modified by game speed)>")) - ProvidesStatsWheneverGreatPersonExpended("[stats] whenever a Great Person is expended", UniqueTarget.Global), PercentGoldFromTradeMissions("[relativeAmount]% Gold from Great Merchant trade missions", UniqueTarget.Global), GreatGeneralProvidesDoubleCombatBonus("Great General provides double combat bonus", UniqueTarget.Unit, UniqueTarget.Global), // This should probably support conditionals, e.g. @@ -224,8 +220,6 @@ enum class UniqueType( FreeExtraBeliefs("May choose [amount] additional [beliefType] beliefs when [foundingOrEnhancing] a religion", UniqueTarget.Global), FreeExtraAnyBeliefs("May choose [amount] additional belief(s) of any type when [foundingOrEnhancing] a religion", UniqueTarget.Global), StatsWhenAdoptingReligion("[stats] when a city adopts this religion for the first time", UniqueTarget.Global, flags = setOf(UniqueFlag.AcceptsSpeedModifier)), - @Deprecated("As of 4.11.18", ReplaceWith("[stats] when a city adopts this religion for the first time <(modified by game speed)>")) - StatsWhenAdoptingReligionSpeed("[stats] when a city adopts this religion for the first time (modified by game speed)", UniqueTarget.Global), NaturalReligionSpreadStrength("[relativeAmount]% Natural religion spread [cityFilter]", UniqueTarget.FollowerBelief, UniqueTarget.Global), ReligionSpreadDistance("Religion naturally spreads to cities [amount] tiles away", UniqueTarget.Global, UniqueTarget.FollowerBelief), MayNotGenerateGreatProphet("May not generate great prophet equivalents naturally", UniqueTarget.Global), @@ -722,15 +716,6 @@ enum class UniqueType( ConditionalWhenBetweenStatResource("when between [amount] and [amount] [stat/resource]", UniqueTarget.Conditional, flags = setOf(UniqueFlag.AcceptsSpeedModifier), docDescription = "Stats refers to the accumulated stat, not stat-per-turn"), - // The game speed-adjusted versions of above - - @Deprecated("As of 4.11.18", ReplaceWith("when above [amount] [stat/resource] <(modified by game speed)>")) - ConditionalWhenAboveAmountStatResourceSpeed("when above [amount] [stat/resource] (modified by game speed)", UniqueTarget.Conditional), - @Deprecated("As of 4.11.18", ReplaceWith("when below [amount] [stat/resource] <(modified by game speed)>")) - ConditionalWhenBelowAmountStatResourceSpeed("when below [amount] [stat/resource] (modified by game speed)", UniqueTarget.Conditional), - @Deprecated("As of 4.11.18", ReplaceWith("when between [amount] and [amount] [stat/resource] <(modified by game speed)>")) - ConditionalWhenBetweenStatResourceSpeed("when between [amount] and [amount] [stat/resource] (modified by game speed)", UniqueTarget.Conditional), - /////// city conditionals ConditionalInThisCity("in this city", UniqueTarget.Conditional), ConditionalCityFilter("in [cityFilter] cities", UniqueTarget.Conditional), @@ -953,6 +938,18 @@ enum class UniqueType( ///////////////////////////////////////////// region 99 DEPRECATED AND REMOVED ///////////////////////////////////////////// + @Deprecated("As of 4.11.19", ReplaceWith("Gain [100] [Gold] <(modified by game speed)>"), DeprecationLevel.ERROR) + ProvidesGoldWheneverGreatPersonExpended("Provides a sum of gold each time you spend a Great Person", UniqueTarget.Global), + @Deprecated("As of 4.11.19", ReplaceWith("Gain [amount] [stat] <(modified by game speed)>"), DeprecationLevel.ERROR) + ProvidesStatsWheneverGreatPersonExpended("[stats] whenever a Great Person is expended", UniqueTarget.Global), + @Deprecated("As of 4.11.18", ReplaceWith("when above [amount] [stat/resource] <(modified by game speed)>"), DeprecationLevel.ERROR) + ConditionalWhenAboveAmountStatResourceSpeed("when above [amount] [stat/resource] (modified by game speed)", UniqueTarget.Conditional), + @Deprecated("As of 4.11.18", ReplaceWith("when below [amount] [stat/resource] <(modified by game speed)>"), DeprecationLevel.ERROR) + ConditionalWhenBelowAmountStatResourceSpeed("when below [amount] [stat/resource] (modified by game speed)", UniqueTarget.Conditional), + @Deprecated("As of 4.11.18", ReplaceWith("when between [amount] and [amount] [stat/resource] <(modified by game speed)>"), DeprecationLevel.ERROR) + ConditionalWhenBetweenStatResourceSpeed("when between [amount] and [amount] [stat/resource] (modified by game speed)", UniqueTarget.Conditional), + @Deprecated("As of 4.11.18", ReplaceWith("[stats] when a city adopts this religion for the first time <(modified by game speed)>"), DeprecationLevel.ERROR) + StatsWhenAdoptingReligionSpeed("[stats] when a city adopts this religion for the first time (modified by game speed)", UniqueTarget.Global), @Deprecated("As of 4.10.17", ReplaceWith("Grants [+500 Gold] to the first civilization to discover it"), DeprecationLevel.ERROR) GrantsGoldToFirstToDiscover("Grants 500 Gold to the first civilization to discover it", UniqueTarget.Terrain), @Deprecated("as of 4.10.17", ReplaceWith("[+100 Gold] for discovering a Natural Wonder (bonus enhanced to [+500 Gold] if first to discover it)"), DeprecationLevel.ERROR) diff --git a/core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt b/core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt index 579a975dc6c3d..eae3f36609653 100644 --- a/core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt +++ b/core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt @@ -112,9 +112,13 @@ class UniqueValidator(val ruleset: Ruleset) { val resourceUniques = setOf(UniqueType.ProvidesResources, UniqueType.ConsumesResources, UniqueType.DoubleResourceProduced, UniqueType.StrategicResourcesIncrease) - val resourceConditionals = setOf(UniqueType.ConditionalWithResource, UniqueType.ConditionalWithoutResource, - UniqueType.ConditionalWhenBetweenStatResource, UniqueType.ConditionalWhenAboveAmountStatResource, UniqueType.ConditionalWhenBelowAmountStatResource, - UniqueType.ConditionalWhenAboveAmountStatResourceSpeed, UniqueType.ConditionalWhenBelowAmountStatResourceSpeed, UniqueType.ConditionalWhenBetweenStatResourceSpeed) + val resourceConditionals = setOf( + UniqueType.ConditionalWithResource, + UniqueType.ConditionalWithoutResource, + UniqueType.ConditionalWhenBetweenStatResource, + UniqueType.ConditionalWhenAboveAmountStatResource, + UniqueType.ConditionalWhenBelowAmountStatResource, + ) private fun addConditionalErrors( conditional: Unique, diff --git a/tests/src/com/unciv/uniques/GlobalUniquesTests.kt b/tests/src/com/unciv/uniques/GlobalUniquesTests.kt index 3a3ab64a72a30..c8fdb7a0ee10d 100644 --- a/tests/src/com/unciv/uniques/GlobalUniquesTests.kt +++ b/tests/src/com/unciv/uniques/GlobalUniquesTests.kt @@ -608,7 +608,7 @@ class GlobalUniquesTests { val tile = game.getTile(Vector2.Zero) val city = game.addCity(civInfo, tile, true) val unit = game.addUnit("Great Engineer", civInfo, tile) - val building = game.createBuilding("[+250 Gold] whenever a Great Person is expended") + val building = game.createBuilding("Gain [250] [Gold] ") city.cityConstructions.addBuilding(building) civInfo.addGold(-civInfo.gold) // reset gold just to be sure