Skip to content

Commit

Permalink
Fix [damage] weapon special produces unexpected damage values
Browse files Browse the repository at this point in the history
  • Loading branch information
newfrenchy83 committed Oct 17, 2024
1 parent 491c236 commit e4517d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@
# API(s) being tested: [attacks]divide=
##
# Expected end state:
# Bob's attack has 4 strikes after rounding down.
# Bob's attack has 5 strikes after rounding up.
#####
{ONE_CALCULATION_UNIT_TEST divide_float_2dp 10 (divide=2.02) 4}
{ONE_CALCULATION_UNIT_TEST divide_float_2dp 10 (divide=2.02) 5}
#####
# API(s) being tested: [attacks]divide=
##
Expand All @@ -192,16 +192,16 @@
# API(s) being tested: [attacks]
##
# Expected end state:
# Bob's attack is the expected answer: 10 strikes * 2 / 3 = 6 strikes after rounding down.
# Bob's attack is the expected answer: 10 strikes * 2 / 3 = 7 strikes after rounding up.
#####
{ONE_CALCULATION_UNIT_TEST divide_multiply_combined 10 (divide,multiply=3,2) 6}
{ONE_CALCULATION_UNIT_TEST divide_multiply_combined 10 (divide,multiply=3,2) 7}
#####
# API(s) being tested: [attacks]divide=,[attacks]multiply=
##
# Expected end state:
# Bob's attack is the expected answer: 10 strikes * 2 / 3 = 6 strikes after rounding down.
# Bob's attack is the expected answer: 10 strikes * 2 / 3 = 7 strikes after rounding up.
#####
{TWO_CALCULATION_UNIT_TEST divide_multiply_separated 10 (divide=3) (multiply=2) 6}
{TWO_CALCULATION_UNIT_TEST divide_multiply_separated 10 (divide=3) (multiply=2) 7}
#####
# API(s) being tested: [attacks]multiply=
##
Expand All @@ -213,9 +213,9 @@
# API(s) being tested: [attacks]multiply=
##
# Expected end state:
# Bob's attack has 9 strikes, because 3 * 3.334 first rounds 3.334 to 3.33, and then 3 * 3.33 floors to 9.
# Bob's attack has 10 strikes, because 3 * 3.334 first rounds 3.334 to 3.33, and then 3 * 3.33 floors to 10.
#####
{ONE_CALCULATION_UNIT_TEST multiply_float_3dp 3 (multiply=3.334) 9}
{ONE_CALCULATION_UNIT_TEST multiply_float_3dp 3 (multiply=3.334) 10}

#undef ONE_CALCULATION_UNIT_TEST
#undef TWO_CALCULATION_UNIT_TEST
6 changes: 5 additions & 1 deletion src/units/abilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,11 @@ effect::effect(const unit_ability_list& list, int def, const_attack_ptr att, EFF
effect_list_.push_back(val.second);
}

composite_value_ = static_cast<int>((value_set + addition + substraction) * multiplier / divisor);
double temp_value = (value_set + addition + substraction) * multiplier / divisor;
composite_value_ = static_cast<int>(temp_value);
if((temp_value - composite_value_) >= 0.5){
composite_value_ = std::round(temp_value);
}
//clamp what if min_value < max_value or one attribute only used.
if(max_value && min_value && *min_value < *max_value) {
composite_value_ = std::clamp(*min_value, *max_value, composite_value_);
Expand Down

0 comments on commit e4517d1

Please sign in to comment.