diff --git a/src/actions/attack.cpp b/src/actions/attack.cpp index b56daa3ad37b4..39a8213a79f40 100644 --- a/src/actions/attack.cpp +++ b/src/actions/attack.cpp @@ -183,7 +183,7 @@ battle_context_unit_stats::battle_context_unit_stats(nonempty_unit_const_ptr up, chance_to_hit = std::clamp(cth, 0, 100); // Compute base damage done with the weapon. - double base_damage = weapon->modified_damage(); + int base_damage = weapon->modified_damage(); // Get the damage multiplier applied to the base damage of the weapon. int damage_multiplier = 100; @@ -317,7 +317,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type, chance_to_hit = std::clamp(cth, 0, 100); - double base_damage = weapon->modified_damage(); + int base_damage = weapon->modified_damage(); int damage_multiplier = 100; unit_alignments::type alignment = weapon->alignment().value_or(u_type->alignment()); damage_multiplier diff --git a/src/reports.cpp b/src/reports.cpp index 79a7a09bbd9a3..11a4f1768cf73 100644 --- a/src/reports.cpp +++ b/src/reports.cpp @@ -782,7 +782,7 @@ static int attack_info(const reports::context& rc, const attack_type &at, config { auto ctx = at.specials_context(u.shared_from_this(), hex, u.side() == rc.screen().playing_team().side()); int base_damage = at.damage(); - double specials_damage = at.modified_damage(); + int specials_damage = at.modified_damage(); int damage_multiplier = 100; const_attack_ptr weapon = at.shared_from_this(); unit_alignments::type attack_alignment = weapon->alignment().value_or(u.alignment()); diff --git a/src/units/abilities.cpp b/src/units/abilities.cpp index 5ab5912207913..559f70bfe6c40 100644 --- a/src/units/abilities.cpp +++ b/src/units/abilities.cpp @@ -1373,9 +1373,9 @@ std::set attack_type::alternative_damage_types() const /** * Returns the damage per attack of this weapon, considering specials. */ -double attack_type::modified_damage() const +int attack_type::modified_damage() const { - double damage_value = unit_abilities::effect(get_specials_and_abilities("damage"), damage(), shared_from_this()).get_composite_double_value(); + int damage_value = composite_value(get_specials_and_abilities("damage"), damage()); return damage_value; } @@ -2576,16 +2576,15 @@ effect::effect(const unit_ability_list& list, int def, const const_attack_ptr& a effect_list_.push_back(val.second); } - composite_double_value_ = (value_set + addition + substraction) * multiplier / divisor; + composite_value_ = std::round((value_set + addition + substraction) * multiplier / divisor); //clamp what if min_value < max_value or one attribute only used. if(max_value && min_value && *min_value < *max_value) { - composite_double_value_ = std::clamp(static_cast(*min_value), static_cast(*max_value), composite_double_value_); + composite_value_ = std::clamp(*min_value, *max_value, composite_value_); } else if(max_value && !min_value) { - composite_double_value_ = std::min(static_cast(*max_value), composite_double_value_); + composite_value_ = std::min(*max_value, composite_value_); } else if(min_value && !max_value) { - composite_double_value_ = std::max(static_cast(*min_value), composite_double_value_); + composite_value_ = std::max(*min_value, composite_value_); } - composite_value_ = std::round(composite_double_value_); } } // end namespace unit_abilities diff --git a/src/units/abilities.hpp b/src/units/abilities.hpp index 8620d21904a89..74ae67a65af65 100644 --- a/src/units/abilities.hpp +++ b/src/units/abilities.hpp @@ -48,8 +48,6 @@ class effect int get_composite_value() const { return composite_value_; } - double get_composite_double_value() const - { return composite_double_value_; } const_iterator begin() const { return effect_list_.begin(); } const_iterator end() const @@ -57,7 +55,6 @@ class effect private: std::vector effect_list_; int composite_value_; - double composite_double_value_; }; diff --git a/src/units/attack_type.hpp b/src/units/attack_type.hpp index a780eac173573..f2177b09cd677 100644 --- a/src/units/attack_type.hpp +++ b/src/units/attack_type.hpp @@ -112,7 +112,7 @@ class attack_type : public std::enable_shared_from_this std::set alternative_damage_types() const; /** Returns the damage per attack of this weapon, considering specials. */ - double modified_damage() const; + int modified_damage() const; /** Return the special weapon value, considering specials. * @param abil_list The list of special checked. diff --git a/src/utils/math.hpp b/src/utils/math.hpp index 66c5f4d340eeb..ccbee0fc8e68f 100644 --- a/src/utils/math.hpp +++ b/src/utils/math.hpp @@ -77,7 +77,7 @@ constexpr T modulo(T num, int mod, T min = 0) * round (base_damage * bonus / divisor) to the closest integer, * but up or down towards base_damage */ -constexpr int round_damage(double base_damage, int bonus, int divisor) { +constexpr int round_damage(int base_damage, int bonus, int divisor) { if (base_damage==0) return 0; return std::max(1, std::round((base_damage * bonus) / divisor)); }