How does damage calculation work?

General feedback and discussion of the game.

Moderator: Forum Moderators

Post Reply
User avatar
ADmiral-N
Posts: 62
Joined: March 24th, 2008, 1:14 am
Contact:

How does damage calculation work?

Post by ADmiral-N »

Damage calculation in Wesnoth is easy enough at first. A Wose at dawn will do 13-2 against an archer.
Then there are the daytime influences. At day, the Wose will deal 16 damage points to that archer.

But if there is more than one influence, how do these bonuses add up?

In a recent game, I observed a few damage values:
1) Wose (13-2) with leadership (+25%) at dawn (+0%) against Griffin Rider (-20% impact) does 19-2 damage.
2) Wose (13-2) with leadership (+25%) in the morning (+25%) against Griffin Rider (-20% impact) does 23-2 damage.
3) Strong Elvish Shaman (4-2) with leadership (+25%) against Griffin Rider (-20% impact) does 6-2 damage.

I tried to find the formula. Let's define a few variables:
B ... Base Damage for one strike
L ... Leadership influence. 1.0 = no leadership, 1.25 = 1 level diff. leadership
D ... Time of Day influence. One of { 0.75, 1.0, 1.25 }.
R ... Resistance influence. e.g. 1.20 for impact against a Griffin Rider.

Now what's the formula? If I had to guess, I'd probably say something like this:
Attack Damage = B * L * D * R

Let's check this with our observed values:
1) 13 * 1.25 * 1.0 * 1.2 = 19.5
2) 13 * 1.25 * 1.25 * 1.2 = 24.375
3) 4 * 1.25 * 1.0 * 1.2 = 6

The second value doesn't seem to work out. Let's try some other very intuitive formula:
Attack Damage = B * (L + D + R - 2)

1) 13 * (1.25 + 1.0 + 1.2 - 2) = 13 * 1.45 = 18.85
2) 13 * (1.25 + 1.25 + 1.2 - 2) = 13 * 1.7 = 22.1
3) 4 * (1.25 + 1.0 + 1.2 - 2) = 4 * 1.45 = 5.8

WTH!! How does it work? Is it documented anywhere (except the source code)? Could you add this to the help section? A search for "damage formula" on the forums turned up nothing.
I finally found a formula that seems halfway reasonable:
Attack Damage = B * (L + D - 1) * R

1) 13 * (1.25 + 1.0 - 1) * 1.2 = 13 * 1.25 * 1.2 = 19.5
2) 13 * (1.25 + 1.25 - 1) * 1.2 = 13 * 1.5 * 1.2 = 23.4
3) 4 * (1.25 + 1.0 - 1) * 1.2 = 4 * 1.25 * 1.2 = 6

Now the damage gets rounded down and it will fit.
I think the formula should be documented more clearly and it should be one of the obvious ones.

What about charge? How does it enter the equation?

Could a kind dev please sacrifice a few minutes of their valuable time and explain this? It would hopefully give some insight not just to me, but to any curious newcomers on this forum. :)
Subspace! Subspace is freeware and is the longest-running massively multiplayer internet space combat game in the world.
Jozrael
Posts: 1034
Joined: June 2nd, 2006, 1:39 pm
Location: NJ, USA.

Re: How does damage calculation work?

Post by Jozrael »

AFAIK:

Base Damage * Resistance, then modify with the sum of leadership/daytime/other factors.

If theres charge, multiply end result by 2.
User avatar
Lizard
Posts: 355
Joined: January 19th, 2008, 8:20 am
Location: Hiding in a swamp (gtm +1; DST)

Re: How does damage calculation work?

Post by Lizard »

AFAIK:
round it down after each multiplication.
in you case 13 * 1.25 * 1.2 * 1.25 works for the second one.
Have a look at the Damage calculation to see the order. Here it looks like ToD, Resi, Leader.
~ I'll heal you by 4 hp if you post next to me ~
Have a look at the Era of Strife, featuring Eltireans, Eventide, Minotaurs, Saurians and Triththa
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: How does damage calculation work?

Post by Max »

according to source code:

get base_damage (e.g 12)
add backstab bonus

damage_multiplier = 100
- add time of day bonus (e.g. +25, 0, -25)
- add leaderhip bonus (e.g. +25)
- multiply with resistance modifier (e.g. x200 if -50%, x90 if 10%)

damage = base_damage x damage_multiplier / 10000 (20000 if unit is slowed)

damage is rounded to nearest integer, damage can't be less than 1
User avatar
Wintermute
Inactive Developer
Posts: 840
Joined: March 23rd, 2006, 10:28 pm
Location: On IRC as "happygrue" at: #wesnoth-mp

Re: How does damage calculation work?

Post by Wintermute »

ADmiral-N wrote:I finally found a formula that seems halfway reasonable:
Attack Damage = B * (L + D - 1) * R

1) 13 * (1.25 + 1.0 - 1) * 1.2 = 13 * 1.25 * 1.2 = 19.5
2) 13 * (1.25 + 1.25 - 1) * 1.2 = 13 * 1.5 * 1.2 = 23.4
3) 4 * (1.25 + 1.0 - 1) * 1.2 = 4 * 1.25 * 1.2 = 6

Now the damage gets rounded down and it will fit.
I think the formula should be documented more clearly and it should be one of the obvious ones.
That is how it works, you have figured out and as Max2008 explains. This is the "intuitive" formula, if you have the right idea about how resistance works. From the in game help:
Resistances work very simply: if a unit has 40% resistance against a damage type, then it will suffer 40% less damage when hit with that damage type. It is also possible for a unit to be vulnerable against some damage types. If a unit has -100% resistance against a damage type, it will suffer 100% more damage when hit by that type.
Translation: Resistance has to be calculated after leadership and time of day. Resistance applies to the damage that WOULD BE taken, but for the resistance. If all modifiers were just multiplied together, then resistance would be treated as a 'bonus' (or penalty) rather than a reduction of final damage taken, which is it's stated purpose. I am not sure that this distinction is obvious, but if you think about it some more, I hope it makes sense.

That said, it is not highly public (other than being in the source code :wink: ) that this is how it works. Perhaps that will change.
"I just started playing this game a few days ago, and I already see some balance issues."
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: How does damage calculation work?

Post by Max »

and i think charge doubles the base damage (forgot to check that in the source).

damage calculation dialog adds to confusion because it lists resistance before tod-bonus (leadership bonus isn't listed at all).
User avatar
Wintermute
Inactive Developer
Posts: 840
Joined: March 23rd, 2006, 10:28 pm
Location: On IRC as "happygrue" at: #wesnoth-mp

Re: How does damage calculation work?

Post by Wintermute »

Max2008 wrote:damage calculation dialog adds to confusion because it lists resistance before tod-bonus (leadership bonus isn't listed at all).
Good point, I will look into that. I am still so happy to have such nice attack dialogues in the first place! I remember the days when there was much less info in them. Still they can always get better.
"I just started playing this game a few days ago, and I already see some balance issues."
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: How does damage calculation work?

Post by Max »

Wintermute wrote:Good point, I will look into that. I am still so happy to have such nice attack dialogues in the first place! I remember the days when there was much less info in them. Still they can always get better.
do you think this dialog could be changed so it would make damage calculation really obvious? maybe it get's too big and that's the reason not everything has been included there?
User avatar
ADmiral-N
Posts: 62
Joined: March 24th, 2008, 1:14 am
Contact:

Re: How does damage calculation work?

Post by ADmiral-N »

Thank you all for posting here!
Especially Wintermute, who explained it to me in-game already :)

Personally, I think it would make more sense to multiply everything instead of multiplying some factors and compose some influences into one of these factors by addition (and not others).
The way it is now, 25% bonus for time of day is not worth as much as -25% resistance on the enemy IF and only if you also apply one or more levels of leadership at the same time. (yeah I know resistances are round numbers, that's beside the point). On the other hand, if you gain either leadership or ToD bonus but not the other, the gain from resistances and that bonus is proportioned properly.

However, any changes in that system might lead to requiring rebalances (for example, leadership races would get slightly stronger if everything was multiplied), so I guess it should stay as it is. Just document it somewhere :)

As for the resistances: Of course I did not mean to reverse that bonus... ^^ The whole point of this is how all these factors stick together, which has been answered to my satisfaction.
Subspace! Subspace is freeware and is the longest-running massively multiplayer internet space combat game in the world.
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: How does damage calculation work?

Post by Max »

ADmiral-N wrote:Personally, I think it would make more sense to multiply everything instead of multiplying some factors and compose some influences into one of these factors by addition (and not others).
the difference is about 10%:
25% tod, 25% leadership: 150% damage. if it would be multiplied: 156% damage.
25% tod, 75% leadership: 200% damage. multiplied: 219% damage.
-25% tod, 50% leadership: 125% damage compared to 113%
-25% tod, 25% leadership: 100% damage compared to 94%
User avatar
Wintermute
Inactive Developer
Posts: 840
Joined: March 23rd, 2006, 10:28 pm
Location: On IRC as "happygrue" at: #wesnoth-mp

Re: How does damage calculation work?

Post by Wintermute »

ADmiral-N wrote:The way it is now, 25% bonus for time of day is not worth as much as -25% resistance on the enemy IF and only if you also apply one or more levels of leadership at the same time. (yeah I know resistances are round numbers, that's beside the point). On the other hand, if you gain either leadership or ToD bonus but not the other, the gain from resistances and that bonus is proportioned properly.
This is, AFAIK, by design, and not something that has just been overlooked. Resistance is indended to be applied *just* before damage is inflicted, and as such, is different thant the other modifiers. I think what could be improved is how the player is informed of this. Perhaps adding to the attack screen, or perhaps a more obvious walkthrough of the differences between leadership and ToD, and resistance.
"I just started playing this game a few days ago, and I already see some balance issues."
Sangel
Moderator Emeritus
Posts: 2232
Joined: March 26th, 2004, 10:58 pm
Location: New York, New York

Re: How does damage calculation work?

Post by Sangel »

ADmiral-N wrote:Personally, I think it would make more sense to multiply everything instead of multiplying some factors and compose some influences into one of these factors by addition (and not others)... However, any changes in that system might lead to requiring rebalances (for example, leadership races would get slightly stronger if everything was multiplied), so I guess it should stay as it is. Just document it somewhere :)
Yes, your proposal would indeed be simpler - and I there was a time when all modifiers were just multiplied together. Unfortunately, this had some extreme results, particularly when you started involving Charge and Backstab. After some serious discussion involving all segments of the community, the current formula was proposed, and Wesnoth has been balanced around it ever since.

As you correctly concluded, changing the formula would affect the balance of gameplay, and probably isn't desirable at this point. That said, it would be a good idea to document the damage calculation system somewhere in the help files, as Wesnoth tends to attract the kind of person who's interested in the nuts-and-bolts of the program as well as just the gameplay.
"Pure logic is the ruin of the spirit." - Antoine de Saint-Exupéry
Post Reply