Author Topic: Melee weapon math  (Read 7503 times)

Offline Eddie

  • Commander
  • *****
  • Posts: 560
    • View Profile
Melee weapon math
« on: February 21, 2016, 03:23:59 pm »
Edit: I made a spreadsheet that you can use to calculate melee damage for your gals. Type in your gals stats and see what is the best weapon for her. If you think my formulas are not correct, please discuss here.


Melee weapon damage is complicated enough that you need a spreadsheet to do it quickly. But I got a bit confused what the actual damage formulas are. What gives me trouble is the "ToStun" and "ToHealth" modifiers. Is that damage added or is the existing damage split?

Example Handle:
It has a "ToHealth: 0.15" modifier and does stun damage. Is the damage
StunDamage + (HealthDamage=Stundamage*0.15)
or
StunDamage*(1-0.15) + (HealthDamage=Stundamage*0.15)?

In the second case, what happens when the ToHealth modifier is >1?

And what about resistances and armour in all this? Are resistances applied to damage types seperately? Is armour applied to each damage type or the total?
Bottom line, can someone give me the correct formula please?
« Last Edit: February 25, 2016, 04:00:52 am by Eddie »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Melee weapon math
« Reply #1 on: February 21, 2016, 03:58:54 pm »
Code ref: https://github.com/Yankes/OpenXcom/blob/OpenXcomExtended/src/Savegame/BattleUnit.cpp#L1131

Stun damage are are independent to health damage except that both are based on power of hit (something like `weapon_damage * random - armor`).
`ToHealth: 1.0` Mean whole power value will be applied to health (if 0 then nothing will change, if < 0 then unit will grain health).
Same for stun.

Examples:
Code: [Select]
ToHealth: 1.0
ToStun: 0.25
This behavior of normal weapon.

Code: [Select]
ToHealth: 0.0
ToStun: 1.0
This is behavior of stun rod.

if value is greater than 1.0 then simply unit will lose or grain more health/stun e.g. with weapon damage 1 and to health 100.0 then you can instant kill all unarmed units but unit with armor will not get any damage (because power after armor subtraction is less than zero).

btw I see I f*** up stun damage in stun rod a bit. In normal version it get always 100% of power but in extended it have random value from 0 to current power value (like normal weapons).
Sorry for all deaths that caused by stun not working as intended.
« Last Edit: February 21, 2016, 05:33:29 pm by Yankes »

Offline Cristao

  • Colonel
  • ****
  • Posts: 407
    • View Profile
Re: Melee weapon math
« Reply #2 on: February 21, 2016, 05:14:32 pm »
Yup, Yankes - Stun Rod is a bit messed up. Is there an error in the code you posted? Should it be

Code: [Select]
ToHealth
ToStun

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Melee weapon math
« Reply #3 on: February 21, 2016, 05:38:36 pm »
Yup, Yankes - Stun Rod is a bit messed up. Is there an error in the code you posted? Should it be

Code: [Select]
ToHealth
ToStun
Error I mention is in extended exe. Its handles bit different stun damage in stun road than nightly version.

And in my previous post I incorrectly repeated that names in examples as you pointed out. This is different thing to previous one.

Offline Dioxine

  • Commander
  • *****
  • Posts: 5455
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Melee weapon math
« Reply #4 on: February 21, 2016, 07:33:55 pm »

btw I see I f*** up stun damage in stun rod a bit. In normal version it get always 100% of power but in extended it have random value from 0 to current power value (like normal weapons).
Sorry for all deaths that caused by stun not working as intended.

Doesn't matter, my Cattle Prod has forced 0-200% damage rolls anyway.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Melee weapon math
« Reply #5 on: February 21, 2016, 08:39:00 pm »
and then rolled again. Whole point was normal weapons do random stun damage aside from damage range e.g. when you do 100 damage to unit it could do form 0 to 25 stun damage (aside from 100 damage to health). In normal OXC when you hit someone with 132 damage stun rod (item can do damage from 0 to 200) it will do 132 stun damage, but if you do with exactly same item in OXCE value will be in 0 to 132 range.

In 3.0 it will be fixed. While I doing that I decide to expand a bit handling of damage types. Each "ToSomething" property will have "RandomProperty" witch will how calculate final change of stat. Something like:
each psi-attack reduce morale by 20 and have random chance to reduce hp by 0 to 5.


Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9093
    • View Profile
Re: Melee weapon math
« Reply #6 on: February 21, 2016, 08:48:47 pm »

Offline Eddie

  • Commander
  • *****
  • Posts: 560
    • View Profile
Re: Melee weapon math
« Reply #7 on: February 21, 2016, 11:02:15 pm »
Ok, lets see if I read the code correctly...

Example 1: Ball Bat
Lets say it does 40 damage on a hit, type is stun. I hit a target with armour 20, so 20 actual stun damage is dealt. Now the Ball Bat has "ToHealth=0.75", so in addition to the 20 stun damage the bat does 20*0.75=15 damage to health.

Example 2: Plastersteel Pipe
Lets say it does 30 damage on a hit, type is concussion (type 3, HE in vanilla). I hit a target with armour 20, so 10 damage to health is dealt. Now the pipe has "ToStun=1.5", so in addition to the 10 damage to health the pipe should do 10*1.5=15 stun damage. But since "ToStun" is rolled, it does 0-15 stun damage, so an average of 7.5.

Edit: If I read the code correctly, "ToStun" ignores any stun resistances the target might have if it's not totally immune to stun damage. Also, no resistances in the "ToHealth" damage, and no bleeding.

« Last Edit: February 21, 2016, 11:22:34 pm by Eddie »

Offline Dioxine

  • Commander
  • *****
  • Posts: 5455
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Melee weapon math
« Reply #8 on: February 21, 2016, 11:34:32 pm »
Edit: If I read the code correctly, "ToStun" ignores any stun resistances the target might have if it's not totally immune to stun damage. Also, no resistances in the "ToHealth" damage, and no bleeding.

It is exactly as I want it. It allows to custom-tailor new damage types from the existing ones; like resistance to stub bomb being different than resistance to handle, and different from resistance to electricity etc.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Melee weapon math
« Reply #9 on: February 22, 2016, 01:52:02 am »
Exactly what Dioxine said, stun resistance is to stun damage type not to `ToStun` property.

Offline Eddie

  • Commander
  • *****
  • Posts: 560
    • View Profile
Re: Melee weapon math
« Reply #10 on: February 25, 2016, 03:58:45 am »
I made a spreadsheet with the formulas for melee weapons (early game) and added it to the first post. Please discuss here if you think my formulas are not correct.
« Last Edit: February 25, 2016, 04:02:13 am by Eddie »