From da328c0408c338e471eda06c98ccbc0e32f98cf9 Mon Sep 17 00:00:00 2001 From: givehub99 <71454921+givehub99@users.noreply.github.com> Date: Thu, 8 Oct 2020 03:09:05 -0700 Subject: [PATCH] Unified Unit Category Checking For Uniques (#3238) * Starting unified unit category checking. This will increase flexibility with uniques as well as cut down on uniques that have only a slightly different way of checking unit categories. Things currently checked by the category checking method are: Type of unit Name of unit Whether unit is wounded If the unit is land, water, or air "Bonus vs City y%" still works currently. Uniques that have been changed/added to use this category checking method so far are: "Bonus vs x y%" "[] units deal +[]% damage" (parameterization of "Wounded military units deal +25% damage") "[] units gain the [] promotion" If PR approved, using this method for more uniques would be a good idea. Commented as depecrated are these uniques "+[]% Strength vs []" (this has not been used in json files) "Wounded military units deal +25% damage" (policies json file was updated to use parameterized version) The following was added to template.properties for translating modifiers: Air Wounded * translation ending with a space * -Changed matchesCategory method for CityCombatant to what was suggested -Changed matchesCategory method for MapUnitCombatant to what was suggested -Use type.name instead of type.toString().toLowerCase() -Lowercasing is no longer allowed for type names and unit names. I kept the lower cased versions of wounded, land, water, and air for compatibility as several of the uniques are phrased like "Bonus vs land units 25%" and such and have entries in template.properties (ie. land units = ). * -Lowercasing is no longer allowed. For wounded, land, water or air, you have to either use the capitalized version (ie. "Wounded") or lower case with units (ie. "wounded units"). This lets preexisting uniques that use "wounded units" etc still work while also letting people use the singular capitalized word (ie. "Wounded") for other uniques. * fixed missing check for wounded units --- .../jsons/Civ V - Vanilla/Policies.json | 2 +- .../jsons/translations/template.properties | 2 ++ .../com/unciv/logic/battle/BattleDamage.kt | 19 ++++++++++--------- .../com/unciv/logic/battle/CityCombatant.kt | 1 + core/src/com/unciv/logic/battle/ICombatant.kt | 1 + .../unciv/logic/battle/MapUnitCombatant.kt | 3 +++ core/src/com/unciv/logic/map/MapUnit.kt | 18 ++++++++++++++++++ core/src/com/unciv/logic/map/TileMap.kt | 2 +- 8 files changed, 37 insertions(+), 11 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Policies.json b/android/assets/jsons/Civ V - Vanilla/Policies.json index 190dea8aac..89b1610718 100644 --- a/android/assets/jsons/Civ V - Vanilla/Policies.json +++ b/android/assets/jsons/Civ V - Vanilla/Policies.json @@ -452,7 +452,7 @@ { "name": "Populism", "effect": "Wounded military units deal +25% damage", - "uniques": ["Wounded military units deal +25% damage"], + "uniques": ["[Wounded] units deal +[25]% damage"], "row": 1, "column": 1 }, diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 09b6a8a861..2ba8b5ec91 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -860,6 +860,8 @@ WaterAircraftCarrier = Composite Bowman = Foreign Land = Friendly Land = +Air = +Wounded = Marine = Mobile SAM = Paratrooper = diff --git a/core/src/com/unciv/logic/battle/BattleDamage.kt b/core/src/com/unciv/logic/battle/BattleDamage.kt index b18a314a43..498d72f0c9 100644 --- a/core/src/com/unciv/logic/battle/BattleDamage.kt +++ b/core/src/com/unciv/logic/battle/BattleDamage.kt @@ -45,18 +45,13 @@ object BattleDamage { val civInfo = combatant.getCivInfo() if (combatant is MapUnitCombatant) { for (BDM in getBattleDamageModifiersOfUnit(combatant.unit)) { - if (BDM.vs == enemy.getUnitType().toString()) - addToModifiers(BDM) - if (BDM.vs == "wounded units" && enemy is MapUnitCombatant && enemy.getHealth() < 100) - addToModifiers(BDM) - if (BDM.vs == "land units" && enemy.getUnitType().isLandUnit()) - addToModifiers(BDM) - if (BDM.vs == "water units" && enemy.getUnitType().isWaterUnit()) - addToModifiers(BDM) - if (BDM.vs == "air units" && enemy.getUnitType().isAirUnit()) + if (enemy.matchesCategory(BDM.vs)) { addToModifiers(BDM) + } + } + // As of 3.11.1 This is to be deprecated and converted to "Bonus vs x y%" - keeping it here so that mods with this can still work for now for (unique in combatant.unit.getMatchingUniques("+[]% Strength vs []")) { if (unique.params[1] == enemy.getName()) modifiers.add("vs [${unique.params[1]}]", unique.params[0].toInt()) @@ -70,9 +65,15 @@ object BattleDamage { if (civHappiness < 0) modifiers["Unhappiness"] = max(2 * civHappiness, -90) // otherwise it could exceed -100% and start healing enemy units... + // As of 3.11.0 This is to be deprecated and converted to "[Wounded] units deal +[25]% damage" - keeping it here so that mods with this can still work for now if (civInfo.hasUnique("Wounded military units deal +25% damage") && combatant.getHealth() < 100) { modifiers["Wounded unit"] = 25 } + for (unique in civInfo.getMatchingUniques("[] units deal +[]% damage")) { + if (combatant.matchesCategory(unique.params[0])) { + modifiers.add(unique.params[0], unique.params[1].toInt()) + } + } if (civInfo.hasUnique("+15% combat strength for melee units which have another military unit in an adjacent tile") && combatant.isMelee() diff --git a/core/src/com/unciv/logic/battle/CityCombatant.kt b/core/src/com/unciv/logic/battle/CityCombatant.kt index 7783ffe146..5f124535d2 100644 --- a/core/src/com/unciv/logic/battle/CityCombatant.kt +++ b/core/src/com/unciv/logic/battle/CityCombatant.kt @@ -20,6 +20,7 @@ class CityCombatant(val city: CityInfo) : ICombatant { override fun isDefeated(): Boolean = city.health==1 override fun isInvisible(): Boolean = false override fun canAttack(): Boolean = (!city.attackedThisTurn) + override fun matchesCategory(category:String) = category == "City" override fun takeDamage(damage: Int) { city.health -= damage diff --git a/core/src/com/unciv/logic/battle/ICombatant.kt b/core/src/com/unciv/logic/battle/ICombatant.kt index 053ab0412e..7b2e07059a 100644 --- a/core/src/com/unciv/logic/battle/ICombatant.kt +++ b/core/src/com/unciv/logic/battle/ICombatant.kt @@ -17,6 +17,7 @@ interface ICombatant{ fun getTile(): TileInfo fun isInvisible(): Boolean fun canAttack(): Boolean + fun matchesCategory(category:String): Boolean fun isMelee(): Boolean { return this.getUnitType().isMelee() diff --git a/core/src/com/unciv/logic/battle/MapUnitCombatant.kt b/core/src/com/unciv/logic/battle/MapUnitCombatant.kt index 57e4be5d7e..09bb3c6bf5 100644 --- a/core/src/com/unciv/logic/battle/MapUnitCombatant.kt +++ b/core/src/com/unciv/logic/battle/MapUnitCombatant.kt @@ -14,6 +14,7 @@ class MapUnitCombatant(val unit: MapUnit) : ICombatant { override fun isDefeated(): Boolean = unit.health <= 0 override fun isInvisible(): Boolean = unit.isInvisible() override fun canAttack(): Boolean = unit.canAttack() + override fun matchesCategory(category:String) = unit.matchesCategory(category) override fun takeDamage(damage: Int) { unit.health -= damage @@ -38,4 +39,6 @@ class MapUnitCombatant(val unit: MapUnit) : ICombatant { override fun toString(): String { return unit.name+" of "+unit.civInfo.civName } + + } \ No newline at end of file diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 399a1c2c66..96392da9a0 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -696,5 +696,23 @@ class MapUnit { } } + fun matchesCategory(category:String): Boolean { + if (category == type.name) + return true + if (category == name) + return true + + if ((category == "Wounded" || category == "wounded units") && health < 100) + return true + if ((category == "Land" || category == "land units") && type.isLandUnit()) + return true + if ((category == "Water" || category == "water units") && type.isWaterUnit()) + return true + if ((category == "Air" || category == "air units") && type.isAirUnit()) + return true + + return false + } + //endregion } \ No newline at end of file diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 2398daf522..50fc7dca74 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -169,7 +169,7 @@ class TileMap { unit.promotions.addPromotion(promotion, true) for (unique in civInfo.getMatchingUniques("[] units gain the [] promotion")) { - if (unique.params[0] == unit.type.name) { + if (unit.matchesCategory(unique.params[0])) { unit.promotions.addPromotion(unique.params[1], true) } }