From 97d74a3aef5f47305a7e4be1f10bd11ccb0fcd0e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 15 Feb 2022 11:29:32 +0200 Subject: [PATCH] Enabled type check checking for uniques whose deprecation leads to multiple uniques! This also enables auto-deprecating the Embark+Ocean unique --- .../jsons/Civ V - Gods & Kings/Nations.json | 2 +- .../assets/jsons/Civ V - Vanilla/Nations.json | 2 +- .../unciv/models/ruleset/unique/UniqueType.kt | 19 ++++--- docs/uniques.md | 19 ++++--- tests/src/com/unciv/testing/BasicTests.kt | 52 +++++++++++-------- 5 files changed, 56 insertions(+), 38 deletions(-) diff --git a/android/assets/jsons/Civ V - Gods & Kings/Nations.json b/android/assets/jsons/Civ V - Gods & Kings/Nations.json index 7ea68005bc..c98f736967 100644 --- a/android/assets/jsons/Civ V - Gods & Kings/Nations.json +++ b/android/assets/jsons/Civ V - Gods & Kings/Nations.json @@ -488,7 +488,7 @@ "innerColor": [255,255,78], "favoredReligion": "Christianity", "uniqueName": "Wayfinding", - "uniques": ["Can embark and move over Coasts and Oceans immediately", "Normal vision when embarked ", "+[10]% Strength if within [2] tiles of a [Moai]"], + "uniques": ["Enables embarkation for land units ", "Enables embarked units to enter ocean tiles ", "Normal vision when embarked ", "+[10]% Strength if within [2] tiles of a [Moai]"], "cities": ["Honolulu","Samoa","Tonga","Nuku Hiva","Raiatea","Aotearoa","Tahiti","Hilo","Te Wai Pounamu","Rapa Nui", "Tuamotu","Rarotonga","Tuvalu","Tubuai","Mangareva","Oahu","Kiritimati","Ontong Java","Niue","Rekohu", "Rakahanga","Bora Bora","Kailua","Uvea","Futuna","Rotuma","Tokelau","Lahaina","Bellona","Mungava","Tikopia", diff --git a/android/assets/jsons/Civ V - Vanilla/Nations.json b/android/assets/jsons/Civ V - Vanilla/Nations.json index 33ca1d8a90..dc80ae012c 100644 --- a/android/assets/jsons/Civ V - Vanilla/Nations.json +++ b/android/assets/jsons/Civ V - Vanilla/Nations.json @@ -468,7 +468,7 @@ "outerColor": [225,105,0], "innerColor": [255,255,78], "uniqueName": "Wayfinding", - "uniques": ["Can embark and move over Coasts and Oceans immediately", "Normal vision when embarked ", "+[10]% Strength if within [2] tiles of a [Moai]"], + "uniques": ["Enables embarkation for land units ", "Enables embarked units to enter ocean tiles ", "Normal vision when embarked ", "+[10]% Strength if within [2] tiles of a [Moai]"], "cities": ["Honolulu","Samoa","Tonga","Nuku Hiva","Raiatea","Aotearoa","Tahiti","Hilo","Te Wai Pounamu","Rapa Nui", "Tuamotu","Rarotonga","Tuvalu","Tubuai","Mangareva","Oahu","Kiritimati","Ontong Java","Niue","Rekohu", "Rakahanga","Bora Bora","Kailua","Uvea","Futuna","Rotuma","Tokelau","Lahaina","Bellona","Mungava","Tikopia", diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index d5f657bb02..7a3a40eafa 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -284,7 +284,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: // ToDo: make per unit and use unit filters? LandUnitEmbarkation("Enables embarkation for land units", UniqueTarget.Global), EmbarkedUnitsMayEnterOcean("Enables embarked units to enter ocean tiles", UniqueTarget.Global), - // todo: Should this be deprecated and replaces with the two above uniques? + @Deprecated("as of 3.19.9", ReplaceWith("Enables embarkation for land units \", \"Enables embarked units to enter ocean tiles ")) EmbarkAndEnterOcean("Can embark and move over Coasts and Oceans immediately", UniqueTarget.Global), PopulationLossFromNukes("Population loss from nuclear attacks [amount]% [cityFilter]", UniqueTarget.Global), @@ -292,11 +292,14 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: PopulationLossFromNukesDeprecated("Population loss from nuclear attacks -[amount]%", UniqueTarget.Global), NaturalReligionSpreadStrength("[amount]% Natural religion spread [cityFilter]", UniqueTarget.FollowerBelief, UniqueTarget.Global), - @Deprecated("as of 3.19.3", ReplaceWith("[amount]% Natural religion spread [cityFilter] OR [amount]% natural religion spread [cityFilter] ")) + @Deprecated("as of 3.19.3", ReplaceWith("[amount]% Natural religion spread [cityFilter] \"" + + " OR \"[amount]% Natural religion spread [cityFilter] ")) NaturalReligionSpreadStrengthWith("[amount]% Natural religion spread [cityFilter] with [tech/policy]", UniqueTarget.Global, UniqueTarget.FollowerBelief), ReligionSpreadDistance("Religion naturally spreads to cities [amount] tiles away", UniqueTarget.Global, UniqueTarget.FollowerBelief), - @Deprecated("as of 3.19.8", ReplaceWith("Only available OR OR ")) + @Deprecated("as of 3.19.8", ReplaceWith("Only available " + + "\" OR \"Only available " + + "\" OR \"Only available ")) IncompatibleWith("Incompatible with [policy/tech/promotion]", UniqueTarget.Policy, UniqueTarget.Tech, UniqueTarget.Promotion), StartingTech("Starting tech", UniqueTarget.Tech), StartsWithTech("Starts with [tech]", UniqueTarget.Nation), @@ -325,7 +328,9 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: // Meant to be used together with conditionals, like "Only available " OnlyAvailableWhen("Only available", UniqueTarget.Unit, UniqueTarget.Building, UniqueTarget.Improvement, UniqueTarget.Policy, UniqueTarget.Tech, UniqueTarget.Promotion), - @Deprecated("as of 3.19.8", ReplaceWith("Only available OR OR ")) + @Deprecated("as of 3.19.8", ReplaceWith("Only available \"" + + " OR \"Only available \"" + + " OR \"Only available ")) NotDisplayedWithout("Not displayed as an available construction without [buildingName/tech/resource/policy]", UniqueTarget.Building, UniqueTarget.Unit), ConvertFoodToProductionWhenConstructed("Excess Food converted to Production when under construction", UniqueTarget.Building, UniqueTarget.Unit), RequiresPopulation("Requires at least [amount] population", UniqueTarget.Building, UniqueTarget.Unit), @@ -668,7 +673,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: // endregion // region DEPRECATED AND REMOVED - @Deprecated("as of 3.18.14", ReplaceWith("[stats] [in all cities] OR [stats] [in all cities] ")) + @Deprecated("as of 3.18.14", ReplaceWith("[stats] [in all cities] \" OR \"[stats] [in all cities] ")) StatsFromCitiesBefore("[stats] per turn from cities before [tech/policy]", UniqueTarget.Global, UniqueTarget.FollowerBelief), @Deprecated("as of 3.18.12", ReplaceWith("[amount]% XP gained from combat"), DeprecationLevel.WARNING) @@ -776,9 +781,9 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: StrengthPlus("+[amount]% Strength", UniqueTarget.Unit), @Deprecated("As of 3.17.3 - removed 3.17.13", ReplaceWith("[-amount]% Strength"), DeprecationLevel.ERROR) StrengthMin("-[amount]% Strength", UniqueTarget.Unit), - @Deprecated("As of 3.17.3 - removed 3.17.13", ReplaceWith("[+amount]% Strength OR "), DeprecationLevel.ERROR) + @Deprecated("As of 3.17.3 - removed 3.17.13", ReplaceWith("[+amount]% Strength \" OR \"[+amount]% Strength "), DeprecationLevel.ERROR) StrengthPlusVs("+[amount]% Strength vs [combatantFilter]", UniqueTarget.Unit), - @Deprecated("As of 3.17.3 - removed 3.17.13", ReplaceWith("[-amount]% Strength OR "), DeprecationLevel.ERROR) + @Deprecated("As of 3.17.3 - removed 3.17.13", ReplaceWith("[-amount]% Strength \" OR \"[+amount]% Strength "), DeprecationLevel.ERROR) StrengthMinVs("-[amount]% Strength vs [combatantFilter]", UniqueTarget.Unit), @Deprecated("As of 3.17.3 - removed 3.17.13", ReplaceWith("[+amount]% Strength"), DeprecationLevel.ERROR) CombatBonus("+[amount]% Combat Strength", UniqueTarget.Unit), diff --git a/docs/uniques.md b/docs/uniques.md index a22342ab1c..6af7f9bd37 100644 --- a/docs/uniques.md +++ b/docs/uniques.md @@ -381,6 +381,9 @@ Applicable to: Global #### Enables construction of Spaceship parts Applicable to: Global +#### Notified of new Barbarian encampments +Applicable to: Global + #### Enables Open Borders agreements Applicable to: Global @@ -503,6 +506,9 @@ Example: "[20]% to Flank Attack bonuses" Applicable to: Global, Unit +#### +30% Strength when fighting City-State units and cities +Applicable to: Global + #### [amount] Movement Example: "[20] Movement" @@ -1520,13 +1526,14 @@ Applicable to: Conditional - "+[amount]% Defensive Strength for cities" - Deprecated as of 3.18.17, replace with "[+amount]% Strength for cities " - "[amount]% Attacking Strength for cities" - Deprecated as of 3.18.17, replace with "[+amount]% Strength for cities " - "+[amount]% attacking strength for cities with garrisoned units" - Deprecated as of 3.19.1, replace with "[+amount]% Strength for cities " + - "Can embark and move over Coasts and Oceans immediately" - Deprecated as of 3.19.9, replace with "Enables embarkation for land units ", "Enables embarked units to enter ocean tiles " - "Population loss from nuclear attacks -[amount]%" - Deprecated as of 3.19.2, replace with "Population loss from nuclear attacks [-amount]% [in this city]" - - "[amount]% Natural religion spread [cityFilter] with [tech/policy]" - Deprecated as of 3.19.3, replace with "[amount]% Natural religion spread [cityFilter] OR [amount]% natural religion spread [cityFilter] " + - "[amount]% Natural religion spread [cityFilter] with [tech/policy]" - Deprecated as of 3.19.3, replace with "[amount]% Natural religion spread [cityFilter] " OR "[amount]% Natural religion spread [cityFilter] " - "[amount] HP when healing in [tileFilter] tiles" - Deprecated as of 3.19.4, replace with "[amount] HP when healing " - "Melee units pay no movement cost to pillage" - Deprecated as of 3.18.17, replace with "No movement cost to pillage " - "Heal adjacent units for an additional 15 HP per turn" - Deprecated as of 3.19.3, replace with "All adjacent units heal [+15] HP when healing" - "+[amount]% attack strength to all [mapUnitFilter] units for [amount2] turns" - Deprecated as of 3.19.8, replace with "[+amount]% Strength " - - "[stats] per turn from cities before [tech/policy]" - Deprecated as of 3.18.14, replace with "[stats] [in all cities] OR [stats] [in all cities] " + - "[stats] per turn from cities before [tech/policy]" - Deprecated as of 3.18.14, replace with "[stats] [in all cities] " OR "[stats] [in all cities] " - "[mapUnitFilter] units gain [amount]% more Experience from combat" - Deprecated as of 3.18.12, replace with "[amount]% XP gained from combat " - "[amount]% maintenance costs for [mapUnitFilter] units" - Deprecated as of 3.18.14, replace with "[amount]% maintenance costs " - "50% of excess happiness added to culture towards policies" - Deprecated as of 3.18.2, replace with "[50]% of excess happiness converted to [Culture]" @@ -1565,8 +1572,8 @@ Applicable to: Conditional - "-33% unit upkeep costs" - Deprecated Extremely old - used for auto-updates only, replace with "[-33]% maintenance costs " - "-50% food consumption by specialists" - Deprecated Extremely old - used for auto-updates only, replace with "[-50]% Food consumption by specialists [in all cities]" - "+50% attacking strength for cities with garrisoned units" - Deprecated Extremely old - used for auto-updates only, replace with "[+50]% Strength for cities " - - "Incompatible with [policy/tech/promotion]" - Deprecated as of 3.19.8, replace with "Only available OR OR " - - "Not displayed as an available construction without [buildingName/tech/resource/policy]" - Deprecated as of 3.19.8, replace with "Only available OR OR " + - "Incompatible with [policy/tech/promotion]" - Deprecated as of 3.19.8, replace with "Only available " OR "Only available " OR "Only available " + - "Not displayed as an available construction without [buildingName/tech/resource/policy]" - Deprecated as of 3.19.8, replace with "Only available " OR "Only available " OR "Only available " - "[stats] with [resource]" - Deprecated as of 3.19.7, replace with "[stats] " - "Not displayed as an available construction unless [buildingName] is built" - Deprecated as of 3.16.11, replace with "Not displayed as an available construction without [buildingName]" - "[stats] once [tech] is discovered" - Deprecated as of 3.17.10 - removed 3.18.19, replace with "[stats] " @@ -1585,8 +1592,8 @@ Applicable to: Conditional - "Double movement in Snow, Tundra and Hills" - Deprecated As of 3.17.1 - removed 3.17.13, replace with "Double movement in [terrainFilter]" - "+[amount]% Strength" - Deprecated As of 3.17.3 - removed 3.17.13, replace with "[+amount]% Strength" - "-[amount]% Strength" - Deprecated As of 3.17.3 - removed 3.17.13, replace with "[-amount]% Strength" - - "+[amount]% Strength vs [combatantFilter]" - Deprecated As of 3.17.3 - removed 3.17.13, replace with "[+amount]% Strength OR " - - "-[amount]% Strength vs [combatantFilter]" - Deprecated As of 3.17.3 - removed 3.17.13, replace with "[-amount]% Strength OR " + - "+[amount]% Strength vs [combatantFilter]" - Deprecated As of 3.17.3 - removed 3.17.13, replace with "[+amount]% Strength " OR "[+amount]% Strength " + - "-[amount]% Strength vs [combatantFilter]" - Deprecated As of 3.17.3 - removed 3.17.13, replace with "[-amount]% Strength " OR "[+amount]% Strength " - "+[amount]% Combat Strength" - Deprecated As of 3.17.3 - removed 3.17.13, replace with "[+amount]% Strength" - "+1 Visibility Range" - Deprecated Extremely old - used for auto-updates only, replace with "[+1] Sight" - "+[amount] Visibility Range" - Deprecated Extremely old - used for auto-updates only, replace with "[+amount] Sight" diff --git a/tests/src/com/unciv/testing/BasicTests.kt b/tests/src/com/unciv/testing/BasicTests.kt index 99b6b9b9f3..2027a3f408 100644 --- a/tests/src/com/unciv/testing/BasicTests.kt +++ b/tests/src/com/unciv/testing/BasicTests.kt @@ -129,34 +129,40 @@ class BasicTests { var allOK = true for (uniqueType in UniqueType.values()) { val deprecationAnnotation = uniqueType.getDeprecationAnnotation() ?: continue - val replacementTextUnique = Unique(deprecationAnnotation.replaceWith.expression) - if (replacementTextUnique.type == null && !replacementTextUnique.text.contains(" OR ")) { - println("${uniqueType.name}'s deprecation text does not match any existing type!'") - allOK = false - } - if (replacementTextUnique.type == uniqueType){ - println("${uniqueType.name}'s deprecation text references itself!'") - allOK = false - } - for (conditional in replacementTextUnique.conditionals){ - if (conditional.type==null){ - println("${uniqueType.name}'s deprecation text contains conditional \"${conditional.text}\" which does not match any existing type!'") + + val uniquesToCheck = deprecationAnnotation.replaceWith.expression.split("\", \"", "\" OR \"") + + for (uniqueText in uniquesToCheck) { + val replacementTextUnique = Unique(uniqueText) + + + if (replacementTextUnique.type == null) { + println("${uniqueType.name}'s deprecation text \"$uniqueText\" does not match any existing type!") allOK = false } - } - - var iteration = 1 - var replacementUnique = Unique(uniqueType.placeholderText) - while (replacementUnique.getDeprecationAnnotation() != null) { - if (iteration == 10) { + if (replacementTextUnique.type == uniqueType) { + println("${uniqueType.name}'s deprecation text references itself!") allOK = false - println("${uniqueType.name}'s deprecation text never references an undeprecated unique!") - break } - iteration++ - replacementUnique = Unique(replacementUnique.getReplacementText()) - } + for (conditional in replacementTextUnique.conditionals) { + if (conditional.type == null) { + println("${uniqueType.name}'s deprecation text contains conditional \"${conditional.text}\" which does not match any existing type!") + allOK = false + } + } + var iteration = 1 + var replacementUnique = Unique(uniqueType.placeholderText) + while (replacementUnique.getDeprecationAnnotation() != null) { + if (iteration == 10) { + allOK = false + println("${uniqueType.name}'s deprecation text never references an undeprecated unique!") + break + } + iteration++ + replacementUnique = Unique(replacementUnique.getReplacementText()) + } + } } Assert.assertTrue("This test succeeds only if all deprecated uniques have a replaceWith text that matches an existing type", allOK) }