How does damage calculation works in relation to weapon effects?

Here you may find answers to your questions.
Post Reply
User avatar
b2198
Posts: 798
Joined: Mon Aug 30, 2021 5:48 pm
Location: Brazil

How does damage calculation works in relation to weapon effects?

Post by b2198 »

(Not sure if this should go into FAQ or Reporting Issues, since it might be both, or might only be a question)

I was doing some mental calculations in a match and it seems that I took a little more damage than what I was expecting, so I went into Map Editor to test this out, and I'm now not sure how damage calculation works.

Case in question:
Vanguard Shield Knight attacks a Gendarme
Gendarme takes 9 damage, which makes sense, because it's 12 - 3
Vanguard Shield Knight takes 8 damage back, not 7, which makes me confused, because I thought it would work like:

floor(max(1(minimum damage), 11*0.5(counter)*1(since no bonus on counter) - 5(armor)) + 6(weapon effect damage)*1.01(weapon effect bonus))
floor(max(1, 5.5 - 5) + 6.06)
floor(1 + 6.06)
7

but it seems it work something like:

floor(max(1(minimum damage), 11*0.5(counter)*1(since no bonus on counter) - 5(armor))) + ceil(6(weapon effect damage)*1.01(weapon effect bonus))
floor(max(1, 5.5 - 5)) + ceil(6.06)
1 + 7
8

If that's the case, then the display should show it as such, which is not the case right now, as seen here:
Image
If it's rounded up, it should show:
+-2
+1
+2
+5
+9
Green is the correct color, other colors are "less correct".
User avatar
Endru1241
Posts: 2717
Joined: Fri Sep 11, 2015 8:43 am
Location: Poland

Re: How does damage calculation works in relation to weapon effects?

Post by Endru1241 »

I checked and it seems to round up damage from effect now.
This is the case for heavy cavalry (10.8 rounded up to 11), heavy slow, like you mentioned (6.06 to 7), chariots qnd medium cavalry (7.2 to 8) and other mounted, like horse archers (3.6 to 4).

But I am pretty sure I have tested damage and it was like in calculations (floored).
Maybe something in the engine changed.
Age of Strategy design leader
User avatar
b2198
Posts: 798
Joined: Mon Aug 30, 2021 5:48 pm
Location: Brazil

Re: How does damage calculation works in relation to weapon effects?

Post by b2198 »

Not sure if it's related to weapon effects, but for some reason a +3 damage Gendarme (which I'll call A) attacking a +3 armor Gendarme (which I'll call B) takes 4 damage back, instead of 2. I thought it would go like this:

1) Gendarme A attacks Gendarme B: floor(14*2.05 - 6) = 22 damage, not enough to kill, Gendarme B is at 8hp

2) Gendarme B counter-attacks: floor(11*0.5*1 - 3) = 2 damage, Gendarme A is at 28hp

3) Gendarme A applies its weapon effect on Gendarme B: ceil(6*1.2) = 8 damage, Gendarme B dies

4) Since Gendarme B is already dead, its weapon effect is not applied on Gendarme A

I sincerely have no clue how that resulted in a 4 damage taken back. Did I miss anything in these steps?

Edit: after incrementally increasing Gendarme A's attack one by one, it got to the point where Gendarme B died before it could counterattack on step 2, which was on +7, because floor(18*2.05 - 6) = 30, so Gendarme B died right at that point. But before that, it was 4 damage taken back every time.

Also maybe I understood step 2 wrong and it's actually
floor((11*1 - 3)*0.5) = 4? So that the final damage was halved, not the raw damage the defender had?

Just checked that with an Armored Spearman with +2 armor attacking a War Elephant

1) Armored Spearman attacks War Elephant: floor(9*1.8 - 2) = 14 damage, not enough to kill, War Elephant is at 106hp

2) War Elephant counter-attacks: floor(15*1.5*0.5 - 3) = 8 damage, which is not right, but floor((15*1.5 - 3)*0.5) = ...9 damage? The Armored Spearman actually took 10 damage, how... hm... ceil(floor(15*1.25 - 1)*0.5) = 10 damage, maybe that's it? ceil(floor(11*1 - 3)*0.5) also gives 4 for the Gendarme case. (round instead of ceil also does the job for these cases, but I'm currently too lazy to test which one is right, so I'm stopping here for now)
Green is the correct color, other colors are "less correct".
User avatar
Endru1241
Posts: 2717
Joined: Fri Sep 11, 2015 8:43 am
Location: Poland

Re: How does damage calculation works in relation to weapon effects?

Post by Endru1241 »

Round up = ceil.

What I stated is that currently damage is ceiled.

As for weapon effects around death - they are applied even if unit dies in counter.

The sequence normally should be like:
1. Attacker deals damage
2. If attacker has "Can not be countered" skip 3. and 5. or if defender dies exit
3. Defender deals damage
4. Attacker applies weapon effect
5. Defender applies weapon effect

Also if defender has "First strike" 1. and 3. are replaced by each other. As well as 4. and 5.
2. then checks if attacker dies to exit.

And the damage would be:
Math.Floor(dealingUnit.attackPower/counterDivider * (1 + dealingUnit.bonusAgainst(damagedUnit)) - damagedUnit.armorAgainst(dealingUnit))
So for attacking Gendarme with Gendarme:
Math.Floor(11/1 * (1+1.05) - 3) = Math.Floor(11 * 2.05 - 3) = Math.Floor(22.55 - 3) = Math.Floor(19.55) = 19
And counter:
Math.Floor(11/2 * (1+0) - 3) = Math.Floor(5.5 * 1 - 3) = Math.Floor(5.5 - 3) = Math.Floor(2.5) = 2

Weapon effects are calculated like:
Math.Ceil(weaponEffect.finalPower() * (1 + weaponEffect.effectAffectUnit.bonusAgainst(damagedUnit)) - damagedUnit.armorAgainst(weaponEffect))

So for the same battle:
Math.Ceil(6 * (1+0.2) - 0) = Math.Ceil(6 * 1.2 - 0) = Math.Ceil(7.2) = 8

So total damage on defender = 27, on attacker = 10.
But displayed by two floating texts each (so e.g. over attacker there should appear 2 and 8 almost on the same time, and 19 and 8 over defender).

And all my tests confirm my calculations.

I have no idea how did it change for 4.
Is it possible Gendarme is some old unit with lower abilityPower ?

As for armored spearman vs elephant.
It should take 10 damage, because Math.Floor(15/2*1.5 - 1) = 10.
Armored spearman has 1 normal armor.
Master armored spearman takes 9 damage. With both blacksmith armors = 7.
Age of Strategy design leader
User avatar
b2198
Posts: 798
Joined: Mon Aug 30, 2021 5:48 pm
Location: Brazil

Re: How does damage calculation works in relation to weapon effects?

Post by b2198 »

Endru1241 wrote: Mon Jan 03, 2022 5:36 pm Round up = ceil.

What I stated is that currently damage is ceiled.

As for weapon effects around death - they are applied even if unit dies in counter.

The sequence normally should be like:
1. Attacker deals damage
2. If attacker has "Can not be countered" skip 3. and 5. or if defender dies exit
3. Defender deals damage
4. Attacker applies weapon effect
5. Defender applies weapon effect

Also if defender has "First strike" 1. and 3. are replaced by each other. As well as 4. and 5.
2. then checks if attacker dies to exit.
Yeah, those make sense
Endru1241 wrote: Mon Jan 03, 2022 5:36 pm And the damage would be:
Math.Floor(dealingUnit.attackPower/counterDivider * (1 + dealingUnit.bonusAgainst(damagedUnit)) - damagedUnit.armorAgainst(dealingUnit))
So for attacking Gendarme with Gendarme:
Math.Floor(11/1 * (1+1.05) - 3) = Math.Floor(11 * 2.05 - 3) = Math.Floor(22.55 - 3) = Math.Floor(19.55) = 19
And counter:
Math.Floor(11/2 * (1+0) - 3) = Math.Floor(5.5 * 1 - 3) = Math.Floor(5.5 - 3) = Math.Floor(2.5) = 2

Weapon effects are calculated like:
Math.Ceil(weaponEffect.finalPower() * (1 + weaponEffect.effectAffectUnit.bonusAgainst(damagedUnit)) - damagedUnit.armorAgainst(weaponEffect))

So for the same battle:
Math.Ceil(6 * (1+0.2) - 0) = Math.Ceil(6 * 1.2 - 0) = Math.Ceil(7.2) = 8

So total damage on defender = 27, on attacker = 10.
But displayed by two floating texts each (so e.g. over attacker there should appear 2 and 8 almost on the same time, and 19 and 8 over defender).

And all my tests confirm my calculations.

I have no idea how did it change for 4.
Is it possible Gendarme is some old unit with lower abilityPower ?
In my case the attacking Gendarme had +3 damage given by triggers, and the defending one had +3 armor, so the defender died before applying the weapon effect back.
Endru1241 wrote: Mon Jan 03, 2022 5:36 pm As for armored spearman vs elephant.
It should take 10 damage, because Math.Floor(15/2*1.5 - 1) = 10.
Armored spearman has 1 normal armor.
Master armored spearman takes 9 damage. With both blacksmith armors = 7.
In my case the armored spearman had +2 armor, also from triggers, so the damage should have been 8 because floor(15/2*1.5 - 3) = 8, but it was 10, so also 2 more than expected here.
Green is the correct color, other colors are "less correct".
User avatar
Endru1241
Posts: 2717
Joined: Fri Sep 11, 2015 8:43 am
Location: Poland

Re: How does damage calculation works in relation to weapon effects?

Post by Endru1241 »

I tested exact situation with elephant
b2198 wrote: Tue Jan 04, 2022 2:09 am In my case the armored spearman had +2 armor, also from triggers, so the damage should have been 8 because floor(15/2*1.5 - 3) = 8, but it was 10, so also 2 more than expected here.
And it's dealt 8 damage.
b2198 wrote: Tue Jan 04, 2022 2:09 am In my case the attacking Gendarme had +3 damage given by triggers, and the defending one had +3 armor, so the defender died before applying the weapon effect back.
Except according to sequence from my tests - there is no such a thing as dying before applying weapon effect.
If defender was alive to counterattack- it will also apply it's weapon effect.
The question is why weapon effect is only dealing 2, instead of 8.

I checked few things and came upon conclusion, that lowered damage must be because at the moment of damage calculation from defender weapon effect abilityPower must be checked as 0 (because there is no longer a unit), so it's
Math.ceil(1*1.01)=2
Age of Strategy design leader
User avatar
b2198
Posts: 798
Joined: Mon Aug 30, 2021 5:48 pm
Location: Brazil

Re: How does damage calculation works in relation to weapon effects?

Post by b2198 »

Endru1241 wrote: Tue Jan 04, 2022 5:38 am I tested exact situation with elephant
And it's dealt 8 damage.
Just went back to redo the test... and it dealt 8 damage, I probably messed up something in my previous test, my bad.
Endru1241 wrote: Tue Jan 04, 2022 5:38 am Except according to sequence from my tests - there is no such a thing as dying before applying weapon effect.
If defender was alive to counterattack- it will also apply it's weapon effect.
The question is why weapon effect is only dealing 2, instead of 8.

I checked few things and came upon conclusion, that lowered damage must be because at the moment of damage calculation from defender weapon effect abilityPower must be checked as 0 (because there is no longer a unit), so it's
Math.ceil(1*1.01)=2
Ooh, that makes sense. Wait, when the abilityPower is 0 then the default damage of the effect (in this case 1) is considered instead of Math.ceil(0*1.01) = 0?
Green is the correct color, other colors are "less correct".
User avatar
Endru1241
Posts: 2717
Joined: Fri Sep 11, 2015 8:43 am
Location: Poland

Re: How does damage calculation works in relation to weapon effects?

Post by Endru1241 »

b2198 wrote: Tue Jan 04, 2022 6:54 am Ooh, that makes sense. Wait, when the abilityPower is 0 then the default damage of the effect (in this case 1) is considered instead of Math.ceil(0*1.01) = 0?
Seems like it.
I guess it's something to prevent crashes, like:
if(unit != null)
MultiplyByAbilityPower();
Age of Strategy design leader
Post Reply

Return to “FAQ”