Hard Light Productions Forums

Modding, Mission Design, and Coding => The Modding Workshop => Topic started by: pSimon on February 26, 2016, 04:28:17 am

Title: Damage Algorithm
Post by: pSimon on February 26, 2016, 04:28:17 am
Is there a good description of the damage algorithm anywhere?

I'm playing around with armor.tbl values. and some of my results feel a trifle odd.

I'm assuming it goes something like this, without armor tables:

- Weapon damage * SH fac applied to shield
- If shield>0 stop
- Weapon damage * Hull fac applied to hull
- Weapon damage * Subsys fac applied to subsystem

1] Is this correct?

2] _When_ do the calculations in armor.tbl get applied? (i.e to raw dmg, or to dmg*whatever_factor)

3] What do the "weapon piercing" parameters actually do?



Title: Re: Damage Algorithm
Post by: FrikgFeek on February 26, 2016, 04:31:03 am
- If shield>0 stop
This is definitely not true. Try outfitting a myrm with 2 banks or Prom S(total 6 gunpoints) and you'll be able to oneshot manticores. You will break a shield quadrant and instatlly do enough hull damage to kill them.

Same for the Trebuchet, or Torando, or Hornet, they all do enough damage to penetrate a quadrant and instantly do hull damage.

Calculation order is defined in armor.tbl AFAIK.
Title: Re: Damage Algorithm
Post by: The E on February 26, 2016, 04:55:37 am
The sequence goes like this:
1. Weapon hits ship.
2. Find out how much damage the weapon does (this can vary depending on whether or not it has attenuating damage, or is an unarmed missile)
3. Multiply the damage by the shield factor of the weapon.
4. If damage is positive, retrieve the weapons' damage type and the ship's shield armor type.
5. Scale the damage according to the formulas defined in armor.tbl (this includes difficulty scaling), or just difficulty scaling if no armor types are defined for both ship and weapon.
6. Apply damage to the shield quadrant being hit.
7. If there is damage left over, undo shield scaling.
8. If there is damage left over, retrieve the ship's hull armor type.
9. Apply armor type or difficulty scaling, as per step 5
10. Apply the weapons' armor factor
11. Subtract remaining damage from the ship hull.

- If shield>0 stop
This is definitely not true. Try outfitting a myrm with 2 banks or Prom S(total 6 gunpoints) and you'll be able to oneshot manticores. You will break a shield quadrant and instatlly do enough hull damage to kill them.

It is definitely true. Remember that the game treats every weapon as a separate object, if you hit something with a quad bank of PromS, there will be 4 separate impacts; In your example, the first one or two prom hits will kill the shield, the others will be applied to the hull. This usually happens fast enough that you won't notice the separate impacts.

As for weapon piercing, those parameters determine the point at which the game will add the penetration particle effects (Like the beam piercing effect).
Title: Re: Damage Algorithm
Post by: FrikgFeek on February 26, 2016, 05:18:57 am
Are you sure about that? What about a single Treb or Grimmler killing a fighter(not a doubleshot)? Is it because of the seperate damage from the shockwave?

If "shield>0 stop" was the case a single Trebuchet would do 0 damage to a Nahema as it has 900 shields and the trebuchet only does 175 shield damage, not enough to fully break a quadrant. You'd get its front quadrant down to 50 with the direct hit and the shockwave would end up stripping the shields completely and then doing 0 hull damage. Yet in game it will bring it down to ~52% hull. That means the trebuchet did ~144 hull damage with the shockwave. I don't know how and why it's that number as it doesn't seem to be related to any of the treb's stats but this is reproducible in-game.

By your calculations it should do 225 hull damage if it hits a quadrant with 50 shielding and no difficulty/armor trickery is involved.
Title: Re: Damage Algorithm
Post by: AdmiralRalwood on February 26, 2016, 10:53:09 am
If the weapon deals more damage than the shield quadrant has strength, it will deal the leftovers through the shield.

Additionally, modded weapons can always deal some percentage of their damage through shields.

EDIT: Shockwaves, by default, do as much damage as the weapon itself. That's why the trebuchet deals so much damage.
Title: Re: Damage Algorithm
Post by: FrikgFeek on February 26, 2016, 11:06:50 am
I know that, the problem is that it deals too LITTLE damage. Edited numbers after some testing.

Trebuchet stats:
Damage: 350
Hull Factor: 0.9
Shied factor: 0.5
Subsystem factor: 2.4

Normal calculations would suggest this in the Nahema scenario:

1.Direct trebuchet hit, 175 shield damage. Front quadrant taken from 225 to 50.
2.Shockwave hit, front quadrant taken from 50 to 0, leftover damage is 125
3.Shield factor un-applied, leftover damage is 250
4.Hull factor applied, hull damage equals 225.
5.Nahema left at 25% hull(75/300)

What actually happens.
1.Direct trebuchet hit, 175 shield damage.
2.Shockwave hit, front quadrant taken to 0.
3.????
4.Nahema is around 63% hull, taking ~111 damage.


This seems to be rather consistent, tested it on a zero-effort test mission where you shoot a play-dead Nahema with a treb.
Title: Re: Damage Algorithm
Post by: Meneldil on February 26, 2016, 11:38:02 am
How is the shockwave damage calculated?
If it scales with distance, then hull-to-shields distance could explain the discrepancy. Do you get the full double damage (350) when hitting the shields alone of eg. Seraphim? Or full 630 when hitting an unshielded ship?
Title: Re: Damage Algorithm
Post by: FrikgFeek on February 26, 2016, 11:49:00 am
It's not that. I think I got it.

This step:

7. If there is damage left over, undo shield scaling.


Doesn't happen. It makes sense now. 125 leftover damage from the shockwave after depleting a full quadrant multiplied by the armor factor comes out to 112.5, which would bring the Nahema to 63% hull.

So what ACTUALLY happens is that leftover shield damage is then multiplied by the hull factor without undoing the shield factor multiplication. That means a weapon that has a huge shield factor but a normal hull factor can actually wreck hulls if it manages to pierce the shields with a lot of leftover damage.

Or not, as I've been informed that there is code to specifically un-apply the shield factor if it's >1.
Title: Re: Damage Algorithm
Post by: pSimon on February 27, 2016, 06:56:25 am
Thanks for the info.

Plainly it's not the stupid question I feared it might be.

Would it be sensible to wiki this?
Title: Re: Damage Algorithm
Post by: FrikgFeek on February 27, 2016, 07:36:06 am
I just realised what I wrote.

If shield>0 stop is definitely true, I just somehow misread it, thinking it means that all damage stops if shields absorbed something. What you actually meant was that all damage stops if there are shield points left over after the damage is taken.

My bad.
Title: Re: Damage Algorithm
Post by: pSimon on February 27, 2016, 09:28:17 am
I could have put it better, TBH