How is the damage determined?
Moderator: Forum Moderators
Re: How is the damage determined?
So is Pi.Dunno wrote:Mmm... math... yummy...
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.
The heck m8? I thought you left... No seriously... go... serious...
ok bye m8. I'm serious.
Re: How is the damage determined?
From actions.cpp:
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
And then here's the round_damage function, from util.hpp, with a handy comment explaining how rounding works:
Hope that clears things up!
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);
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 }
- Colouredbox
- Posts: 158
- Joined: April 13th, 2011, 1:43 pm
- Location: Finland
Re: How is the damage determined?
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?
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.
Re: How is the damage determined?
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.Colouredbox wrote: Are backstab and charge calculated as -100% resistance, or just doubling the damage when it has been rounded?
Of course, I could be reading it wrong.
- Colouredbox
- Posts: 158
- Joined: April 13th, 2011, 1:43 pm
- Location: Finland
Re: How is the damage determined?
OkayKymille wrote: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.Colouredbox wrote: Are backstab and charge calculated as -100% resistance, or just doubling the damage when it has been rounded?
Of course, I could be reading it wrong.
Waiting for cheesedwarfs to be added to ageless.