mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-13 11:30:31 +07:00
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
This commit is contained in:
parent
4fa7c8d4c6
commit
da328c0408
@ -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
|
||||
},
|
||||
|
@ -860,6 +860,8 @@ WaterAircraftCarrier =
|
||||
Composite Bowman =
|
||||
Foreign Land =
|
||||
Friendly Land =
|
||||
Air =
|
||||
Wounded =
|
||||
Marine =
|
||||
Mobile SAM =
|
||||
Paratrooper =
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user