Jump to content


Photo

Damage Formula


  • Please log in to reply
8 replies to this topic

#1 bamb

bamb

    Captain

  • Forum Members
  • PipPipPipPip
  • 155 posts

Posted 24 April 2007 - 03:44 PM

I was trying to look at if different weapons do different damage to armor.

This is what I found:
In soldier.cpp
There's a method

void Soldier::hit(int sniper, int pierce, int type, int hitdir, int dam_dev)

The pierce value is effectually the damage of the weapon (some randomness is added in hit()) . We can backtrack to see where pierce comes from:
In soldier.cpp, again, I've highlighted the parameter we are investigating.

void Soldier::apply_hit(int sniper, int _z, int _x, int _y, int _wtype, int _hitdir)
{
if (check_for_hit(_z, _x, _y)) {
hit(sniper, Item::obdata_damage(_wtype) , Item::obdata_damageType(_wtype), _hitdir, Item::obdata_dDeviation(_wtype))

}
}

And the obdata_damage in item.h:

static int obdata_damage(int index) { return obdata_get_int(index, "damage"); }

So the pierce value is the "damage" tag of the clip (or weapon if it's a laser). It's specified in the weapon set lua file by the modder guy.

Now let us go forward, to see what the pierce value actually does in the hit() method:

Some randomness is added, a constant distribution from damage-dev to damage+dev:
pierce = (int) cur_random->getUniform(pierce * (1.0 - (dam_dev / 100.0)), pierce * (1.0 + (dam_dev / 100.0)));



Armour penetration is checked:
if ((hitloc = do_armour_check(pierce, damagedir)) == -1) return; // Can't pierce the armour.
(NOTE THAT PIERCE IS PASSED BY REFERENCE)


In the method int Soldier::do_armour_check(int &pierce, int damdir):
if (*armor >= pierce) {
*armor -= pierce;
return -1;
}

pierce -= *armor;
*armor = 0;

Which means either we don't penetrate and just reduce the armor, or if we do penetrate,
the armor value is reduced from the damage value, and the armor is set to zero.


Again, back to hit(), finally (if we don't die), health is reduced:
ud.CurHealth -= pierce;


-

So, is this correct, the two values of the weapon are:
Damage
Damage deviation in percent
And they are precisely what they are named.
And hitting is done by randomized damage, hitting armor. If randdamage is bigger than the armor value, health is reduced and armor goes to zero. Otherwise armor is just reduced.

??

This should definitely be in the wiki as we have been wondering if the rifles have differing armour piercing capabilities and what the second number after the damage values means.

Feel free to use this post as source for the wiki entry. =b

#2 bamb

bamb

    Captain

  • Forum Members
  • PipPipPipPip
  • 155 posts

Posted 13 August 2007 - 06:49 AM

The melee weapon code is subject to a few exploits, all based on the reason that accuracy doesn't really affect melee weapons:

1) You can carry two handed melee weapons easily with a pistol in the other hand, as you hit the melee things from so near you won't miss anyway. And firing two handed weapons with one hand only affects accuracy.
2) Even if you're wounded or with very low morale, your melee weapon attacks are as good as before, for the same reason, these "handicaps" only affect accuracy.

My solution would be a different damage formula for melee weapons.:
The damage a melee weapon does is always multiplied by a term "melee accuracy" of the unit, which doesn't take into account the shooting accuracy of the soldier, but uses morale, health (as fraction of max health) and perhaps strength (but not too much that, a baseline should be added so that the multiplier is 0.5+strength/50 or something like that) too.

Edited by bamb, 13 August 2007 - 06:52 AM.


#3 feliciafan89

feliciafan89

    Sergeant

  • Forum Members
  • PipPipPip
  • 52 posts

Posted 29 October 2007 - 07:13 AM

I know this is kind of old, but... how exactly do laser and plasma damage types differ? Furthermore, how do they affect the damage formula(e)?
Posted Image

#4 bamb

bamb

    Captain

  • Forum Members
  • PipPipPipPip
  • 155 posts

Posted 29 October 2007 - 08:06 PM

I've posted the damage formulas somewhere else, but they don't differ. The damage is damage, and the percentage tells the variation of damage... So plasma weapons have little variation. With shotgun on the other hand you might do small or big damage, you never really know what happens when you fire.

I think. I didn't check that thoroughly. If the damagetype in the lua is the same (and not stun or fire etc...), the weapons behave the same in that regard.

#5 feliciafan89

feliciafan89

    Sergeant

  • Forum Members
  • PipPipPip
  • 52 posts

Posted 30 October 2007 - 07:36 AM

I think armor piercing should be set as a special type of ammo, not the standard type. Despite the name, it doesn't really pierce armor. The Auto and Heavy Cannons do this better. For the rifles and pistols, I think "Armor Piercing" should be replaced with "Ballistic."

(Drill Sergeant: And if you try telling me they're the same, you're going back to XCom Basic Training, wet nose!)
Posted Image

#6 bamb

bamb

    Captain

  • Forum Members
  • PipPipPipPip
  • 155 posts

Posted 30 October 2007 - 02:50 PM

Yeah I agree, some rounds and weapon types could be armor-piercing and some could be normal. Armor piercing ones would do more damage against armors. It would be relatively easy to do in the code.

#7 feliciafan89

feliciafan89

    Sergeant

  • Forum Members
  • PipPipPip
  • 52 posts

Posted 07 November 2007 - 08:42 AM

Something else that's screwed up; it says in the Chryssalid Live Specimen profile that Armor Piercing ammo isn't very effective against it. Then why is it called Armor Piercing ammo? Ballistic, I could understand, but not AP ammo!
Posted Image

#8 Guest_Azrael Strife_*

Guest_Azrael Strife_*
  • Guests

Posted 07 November 2007 - 08:59 AM

Where does it say it's AP ammo? Don't let the variable name "Pierce" fool you, it's just a name picked to confuse other programmers :P

#9 feliciafan89

feliciafan89

    Sergeant

  • Forum Members
  • PipPipPip
  • 52 posts

Posted 07 November 2007 - 10:24 AM

I'm not quite a programmer YET, but I got confused, alright! ^_^
Posted Image