Jump to content
XCOMUFO & Xenocide

Damage Formula


bamb

Recommended Posts

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

Link to comment
Share on other sites

  • 3 months later...

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
Link to comment
Share on other sites

  • 2 months later...

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.

Link to comment
Share on other sites

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!)

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...