Difference between revisions of "Damage formula (OXCE)"

From UFOpaedia
Jump to navigation Jump to search
Line 3: Line 3:
 
== Lethal ranged single target ==
 
== Lethal ranged single target ==
  
The power of an attack is the sum of the base power [[https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Power_and_Damage_types|power]] of the weapon, and the bonus power ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Power_and_Damage_types|''damageBonus'']) which depends on the weapon and usually the user too. This sum is then randomized depending on the weapon ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''RandomType'']) but is usually in the range 0%-200%.
+
The power of an attack is the sum of the base power ([[Ruleset_Reference_Nightly_(OpenXcom)#Power_and_Damage_types|''power'']]) of the weapon, and the bonus power ([[Ruleset_Reference_Nightly_(OpenXcom)#Power_and_Damage_types|''damageBonus'']]) which depends on the weapon and usually the user too. This sum is then randomized depending on the weapon ([[Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''RandomType'']]) but is usually in the range 0%-200%.
  
 
  '' GROSS POWER = (power + damageBonus) x RNG(0%, 200%) ''
 
  '' GROSS POWER = (power + damageBonus) x RNG(0%, 200%) ''
  
  
A shot can get weaker past a certain distance ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Waypoints.2C_Shotguns.2C_Range_Limits_and_Accuracy.2FPower_Dropoff|''powerRangeThreshold'']) in which case damage is reduced by an amount ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Waypoints.2C_Shotguns.2C_Range_Limits_and_Accuracy.2FPower_Dropoff|''powerRangeReduction'']) for every tile beyond that distance. The reduced can't be negative and won't heal the target. '''TBD: can there be negative range reduction, i.e. power increases with distance? Is range damage reduction applied before or after randomType? '''
+
A shot can get weaker past a certain distance ([[Ruleset_Reference_Nightly_(OpenXcom)#Waypoints.2C_Shotguns.2C_Range_Limits_and_Accuracy.2FPower_Dropoff|''powerRangeThreshold'']]) in which case damage is reduced by an amount ([[Ruleset_Reference_Nightly_(OpenXcom)#Waypoints.2C_Shotguns.2C_Range_Limits_and_Accuracy.2FPower_Dropoff|''powerRangeReduction'']]) for every tile beyond that distance. The reduced can't be negative and won't heal the target. '''TBD: can there be negative range reduction, i.e. power increases with distance? Is range damage reduction applied before or after randomType? '''
  
 
  '' RANGE REDUCED POWER = GROSS POWER - LIMIT_LOWER(0, RANGE - powerRangeThreshold) x powerRangeReduction ''
 
  '' RANGE REDUCED POWER = GROSS POWER - LIMIT_LOWER(0, RANGE - powerRangeThreshold) x powerRangeReduction ''
Line 24: Line 24:
  
  
Then armor pre-damage is applied to the side of the armor that was hit. Power is multiplied by a factor ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''ToArmorPre'']) and then randomized from 0-100% depending on a flag ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''RandomArmorPre'']). '''TBD: check if armor pre-damage comes before or after shields.'''
+
Then armor pre-damage is applied to the side of the armor that was hit. Power is multiplied by a factor ([[Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''ToArmorPre'']]) and then randomized from 0-100% depending on a flag ([[Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''RandomArmorPre'']]). '''TBD: check if armor pre-damage comes before or after shields.'''
  
 
  '' ARMOR PRE-DAMAGE = POWER THROUGH P-SHIELDS x ToArmorPre x IF(RandomArmorPre, RNG(0%, 100%)) ''
 
  '' ARMOR PRE-DAMAGE = POWER THROUGH P-SHIELDS x ToArmorPre x IF(RandomArmorPre, RNG(0%, 100%)) ''
  
  
Armor provides a final layer of protection. The remaining power is multiplied by a resistance factor depending on damage type ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Armor|''damageModifier'']) and then reduced by the current armor value of the side that was hit ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Armor|''frontArmor'', ''sideArmor'', ''sideArmor + leftArmorDiff'', ''rearArmor'', ''underArmor'']) modified by the weapons armor effectiveness ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''ArmorEffectiveness'']).
+
Armor provides a final layer of protection. The remaining power is multiplied by a resistance factor depending on damage type ([[Ruleset_Reference_Nightly_(OpenXcom)#Armor|''damageModifier'']]) and then reduced by the current armor value of the side that was hit ([[Ruleset_Reference_Nightly_(OpenXcom)#Armor|''frontArmor'', ''sideArmor'', ''sideArmor + leftArmorDiff'', ''rearArmor'', ''underArmor'']]) modified by the weapons armor effectiveness ([[Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''ArmorEffectiveness'']]).
  
 
  '' NET POWER = POWER THROUGH P-SHIELDS x damageModifier - facingArmor x ArmorEffectiveness ''
 
  '' NET POWER = POWER THROUGH P-SHIELDS x damageModifier - facingArmor x ArmorEffectiveness ''
  
  
Finally damage is applied independently to each of the target unit stats. Power is multiplied by a factor ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''ToArmor, ToHealth, ToStun, ToTime, ToEnergy, ToMorale'']) and then randomized from 0-100% depending on a flag ([https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''RandomArmor, RandomHealth, RandomStun, RandomTime, RandomEnergy, RandomMorale'']).
+
Finally damage is applied independently to each of the target unit stats. Power is multiplied by a factor ([[Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''ToArmor, ToHealth, ToStun, ToTime, ToEnergy, ToMorale'']]) and then randomized from 0-100% depending on a flag ([[Ruleset_Reference_Nightly_(OpenXcom)#Item_Damage_Types|''RandomArmor, RandomHealth, RandomStun, RandomTime, RandomEnergy, RandomMorale'']]).
  
 
  '' ARMOR DAMAGE = NET POWER x ToArmor x IF(RandomArmor, RNG(0%, 100%)) ''
 
  '' ARMOR DAMAGE = NET POWER x ToArmor x IF(RandomArmor, RNG(0%, 100%)) ''

Revision as of 19:59, 27 April 2019

OXCE and mod scripts have greatly expanded the capabilities of weapons, items and armor. So here is a detailed breakdown of what happens when a weapon hits an enemy. Variable names are taken from the Ruleset or applicable Script or otherwise are ALL-CAPS.

Lethal ranged single target

The power of an attack is the sum of the base power (power) of the weapon, and the bonus power (damageBonus) which depends on the weapon and usually the user too. This sum is then randomized depending on the weapon (RandomType) but is usually in the range 0%-200%.

 GROSS POWER = (power + damageBonus) x RNG(0%, 200%) 


A shot can get weaker past a certain distance (powerRangeThreshold) in which case damage is reduced by an amount (powerRangeReduction) for every tile beyond that distance. The reduced can't be negative and won't heal the target. TBD: can there be negative range reduction, i.e. power increases with distance? Is range damage reduction applied before or after randomType?

 RANGE REDUCED POWER = GROSS POWER - LIMIT_LOWER(0, RANGE - powerRangeThreshold) x powerRangeReduction 


[Yankes Scripts] For each projectile that hits, energy shields are taken into account in the following sequence regardless of hit direction: left-hand energy shield item, right-hand energy shield item, armor energy shield. Each shield has a separate pool of hit points (shieldHp) that is reduced by the power they absorb modified by a resistance factor depending on damage type (shieldResistCoeff). Once all shields are depleted any power remaining keeps going. As usual a lower resistance coefficient is more effective, but a value of zero means the shield is bypassed undamaged.

 POWER THROUGH E-SHIELDS = RANGE REDUCED POWER - shieldHp * 100 / shieldResistCoeff 
 E-SHIELD DAMAGE = RANGE REDUCED POWER x shieldResistCoeff / 100 


[Yankes Scripts] Physical shield items come after energy shields, but only one shield will have any effect and the left-hand takes priority over the right-hand. Physical shields do not take damage and cannot be destroyed, but have 50% effectiveness from the sides, 25% from below, and 0% from the rear. They reduce power by their armor value (shieldArmor) modified by a resistance factor depending on damage type (shieldResistCoeff). Once again a resistance of zero means the shield is bypassed.

 POWER THROUGH P-SHIELDS = POWER THROUGH E-SHIELDS - shieldArmor * 100 / shieldResistCoeff x SIDE COEFFICIENT 


Then armor pre-damage is applied to the side of the armor that was hit. Power is multiplied by a factor (ToArmorPre) and then randomized from 0-100% depending on a flag (RandomArmorPre). TBD: check if armor pre-damage comes before or after shields.

 ARMOR PRE-DAMAGE = POWER THROUGH P-SHIELDS x ToArmorPre x IF(RandomArmorPre, RNG(0%, 100%)) 


Armor provides a final layer of protection. The remaining power is multiplied by a resistance factor depending on damage type (damageModifier) and then reduced by the current armor value of the side that was hit (frontArmor, sideArmor, sideArmor + leftArmorDiff, rearArmor, underArmor) modified by the weapons armor effectiveness (ArmorEffectiveness).

 NET POWER = POWER THROUGH P-SHIELDS x damageModifier - facingArmor x ArmorEffectiveness 


Finally damage is applied independently to each of the target unit stats. Power is multiplied by a factor (ToArmor, ToHealth, ToStun, ToTime, ToEnergy, ToMorale) and then randomized from 0-100% depending on a flag (RandomArmor, RandomHealth, RandomStun, RandomTime, RandomEnergy, RandomMorale).

 ARMOR DAMAGE = NET POWER x ToArmor x IF(RandomArmor, RNG(0%, 100%)) 

Area of effect

Melee