Skip to content

Commit

Permalink
chore: retire deprecated uniques
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Aug 1, 2024
1 parent e89d342 commit 053f5b9
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 ->
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 2 additions & 5 deletions core/src/com/unciv/logic/city/managers/CityReligionManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 0 additions & 27 deletions core/src/com/unciv/logic/map/mapunit/MapUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -815,39 +814,13 @@ 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,
triggerNotificationText = "due to expending our [${this.name}]")
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)


Expand Down
9 changes: 0 additions & 9 deletions core/src/com/unciv/models/ruleset/unique/Conditionals.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
27 changes: 12 additions & 15 deletions core/src/com/unciv/models/ruleset/unique/UniqueType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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] <upon expending a [Great Person] unit> <(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] <upon expending a [Great Person] unit> <(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. <after discovering [tech]>
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -953,6 +938,18 @@ enum class UniqueType(

///////////////////////////////////////////// region 99 DEPRECATED AND REMOVED /////////////////////////////////////////////

@Deprecated("As of 4.11.19", ReplaceWith("Gain [100] [Gold] <upon expending a [Great Person] unit> <(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] <upon expending a [Great Person] unit> <(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)
Expand Down
10 changes: 7 additions & 3 deletions core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/com/unciv/uniques/GlobalUniquesTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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] <upon expending a [Great Person] unit>")
city.cityConstructions.addBuilding(building)

civInfo.addGold(-civInfo.gold) // reset gold just to be sure
Expand Down

0 comments on commit 053f5b9

Please sign in to comment.