Skip to content

Commit

Permalink
canceled rounding of [damage] carried over to final calculation
Browse files Browse the repository at this point in the history
If a value of [damage] is rounded during the final calculation integrating [leadeship] and the Tod bonus, then the value shown in the unit bar will be colored the same way as if [leadership] or a Tod bonus/penalty was applied, even if this is not the case, rather than seeing this bug, I prefer to say no to @soliton- and round the intermediate value
  • Loading branch information
newfrenchy83 committed Dec 22, 2024
1 parent 6505e89 commit fde5dcf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/actions/attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/reports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
13 changes: 6 additions & 7 deletions src/units/abilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,9 @@ std::set<std::string> 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;
}

Expand Down Expand Up @@ -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<double>(*min_value), static_cast<double>(*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<double>(*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<double>(*min_value), composite_double_value_);
composite_value_ = std::max(*min_value, composite_value_);
}
composite_value_ = std::round(composite_double_value_);
}

} // end namespace unit_abilities
3 changes: 0 additions & 3 deletions src/units/abilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@ 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
{ return effect_list_.end(); }
private:
std::vector<individual_effect> effect_list_;
int composite_value_;
double composite_double_value_;
};


Expand Down
2 changes: 1 addition & 1 deletion src/units/attack_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class attack_type : public std::enable_shared_from_this<attack_type>
std::set<std::string> 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.
Expand Down

0 comments on commit fde5dcf

Please sign in to comment.