How is the damage determined?

General feedback and discussion of the game.

Moderator: Forum Moderators

User avatar
powershot
Posts: 1193
Joined: May 7th, 2011, 3:03 am
Location: Central America
Contact:

Re: How is the damage determined?

Post by powershot »

Dunno wrote:Mmm... math... yummy... :geek:
So is Pi.
My new account is: Power_Pixel_Wannabe. Yea. Yea.... Why are you still reading this? What the heck m8? You have some kind of problem? Yea. I draw. NO I'M NOT 5 ANYMORE!!! Little brats.
The heck m8? I thought you left... No seriously... go... serious...
ok bye m8. I'm serious.
Caphriel
Posts: 994
Joined: April 21st, 2008, 4:10 pm

Re: How is the damage determined?

Post by Caphriel »

From actions.cpp:

Code: Select all

01062         // Compute base damage done with the weapon.
01063         int base_damage = weapon->damage();
01064         unit_ability_list dmg_specials = weapon->get_specials("damage");
01065         unit_abilities::effect dmg_effect(dmg_specials, base_damage, backstab_pos);
01066         base_damage = dmg_effect.get_composite_value();
01067 
01068         // Get the damage multiplier applied to the base damage of the weapon.
01069         int damage_multiplier = 100;
01070 
01071         // Time of day bonus.
01072         damage_multiplier += combat_modifier(u_loc, u.alignment(), u.is_fearless());
01073 
01074         // Leadership bonus.
01075         int leader_bonus = 0;
01076         if (under_leadership(units, u_loc, &leader_bonus).valid())
01077             damage_multiplier += leader_bonus;
01078 
01079         // Resistance modifier.
01080         damage_multiplier *= opp.damage_from(*weapon, !attacking, opp_loc);
01081 
01082         // Compute both the normal and slowed damage. For the record,
01083         // drain = normal damage / 2 and slow_drain = slow_damage / 2.
01084         damage = round_damage(base_damage, damage_multiplier, 10000);
So the damage multiplier starts at 100 (percent), is modified additively by time of day and leadership, and then multiplicatively by resistance. Just to confirm Dunno's test conclusively :eng:

And then here's the round_damage function, from util.hpp, with a handy comment explaining how rounding works:

Code: Select all

00044 /**
00045  *  round (base_damage * bonus / divisor) to the closest integer,
00046  *  but up or down towards base_damage
00047  */
00048 inline int round_damage(int base_damage, int bonus, int divisor) {
00049     if (base_damage==0) return 0;
00050     const int rounding = divisor / 2 - (bonus < divisor || divisor==1 ? 0 : 1);
00051     return std::max<int>(1, (base_damage * bonus + rounding) / divisor);
00052 }
Hope that clears things up!
User avatar
Colouredbox
Posts: 158
Joined: April 13th, 2011, 1:43 pm
Location: Finland

Re: How is the damage determined?

Post by Colouredbox »

This has been bothering me quite some time and this seems like a nice topic to ask it.

Are backstab and charge calculated as -100% resistance, or just doubling the damage when it has been rounded?
Waiting for cheesedwarfs to be added to ageless.
User avatar
Kymille
Posts: 107
Joined: October 25th, 2009, 4:55 am

Re: How is the damage determined?

Post by Kymille »

Colouredbox wrote: Are backstab and charge calculated as -100% resistance, or just doubling the damage when it has been rounded?
The code snippet above suggests the answer is neither. Backstab and charge are applied first, before resistances or time-of-day. Since you start with an integer, doubling it means that there is no rounding involved.

Of course, I could be reading it wrong.
User avatar
Colouredbox
Posts: 158
Joined: April 13th, 2011, 1:43 pm
Location: Finland

Re: How is the damage determined?

Post by Colouredbox »

Kymille wrote:
Colouredbox wrote: Are backstab and charge calculated as -100% resistance, or just doubling the damage when it has been rounded?
The code snippet above suggests the answer is neither. Backstab and charge are applied first, before resistances or time-of-day. Since you start with an integer, doubling it means that there is no rounding involved.

Of course, I could be reading it wrong.
Okay
Waiting for cheesedwarfs to be added to ageless.
Post Reply