Skip to content

Commit

Permalink
value, add, sub, multiply and divide are rounded instead to ever trun…
Browse files Browse the repository at this point in the history
…cated
  • Loading branch information
newfrenchy83 committed Nov 19, 2024
1 parent 8eb31d5 commit 269658e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
# API(s) being tested: [attacks]divide=
##
# Expected end state:
# Bob's attack has 5 strikes. Here 2.008 is truncated to 2.00, and then 10 / 2.00 is 5.
# Bob's attack has 5 strikes. Here 2.008 is rounded up to 2.10, and then 10 / 2.10 is rounded up to 5.
#####
{ONE_CALCULATION_UNIT_TEST divide_float_3dp 10 (divide=2.008) 5}
#####
Expand Down
24 changes: 12 additions & 12 deletions src/units/abilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2450,10 +2450,10 @@ effect::effect(const unit_ability_list& list, int def, const_attack_ptr att, EFF

if(wham != EFFECT_CUMULABLE){
if (const config::attribute_value *v = cfg.get("value")) {
int value = get_single_ability_value(*v, def, ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
callable.add("base_value", wfl::variant(def));
return formula.evaluate(callable).as_int();
});
int value = std::round(get_single_ability_value(*v, static_cast<double>(def), ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
callable.add("base_value", wfl::variant(def));
return formula.evaluate(callable).as_int() / 1.0 ;
}) * 1 );

int value_cum = cfg["cumulative"].to_bool() ? std::max(def, value) : value;
assert((set_effect_min.type != NOT_USED) == (set_effect_max.type != NOT_USED));
Expand Down Expand Up @@ -2482,27 +2482,27 @@ effect::effect(const unit_ability_list& list, int def, const_attack_ptr att, EFF
}

if (const config::attribute_value *v = cfg.get("add")) {
int add = get_single_ability_value(*v, def, ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
int add = std::round(get_single_ability_value(*v, static_cast<double>(def), ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
callable.add("base_value", wfl::variant(def));
return formula.evaluate(callable).as_int();
});
return formula.evaluate(callable).as_int() / 1.0;
}) * 1);
std::map<std::string,individual_effect>::iterator add_effect = values_add.find(effect_id);
if(add_effect == values_add.end() || add > add_effect->second.value) {
values_add[effect_id].set(ADD, add, ability.ability_cfg, ability.teacher_loc);
}
}
if (const config::attribute_value *v = cfg.get("sub")) {
int sub = - get_single_ability_value(*v, def, ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
int sub = - std::round(get_single_ability_value(*v, static_cast<double>(def), ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
callable.add("base_value", wfl::variant(def));
return formula.evaluate(callable).as_int();
});
return formula.evaluate(callable).as_int() / 1.0;
}) * 1);
std::map<std::string,individual_effect>::iterator sub_effect = values_sub.find(effect_id);
if(sub_effect == values_sub.end() || sub < sub_effect->second.value) {
values_sub[effect_id].set(ADD, sub, ability.ability_cfg, ability.teacher_loc);
}
}
if (const config::attribute_value *v = cfg.get("multiply")) {
int multiply = static_cast<int>(get_single_ability_value(*v, static_cast<double>(def), ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
int multiply = std::round(get_single_ability_value(*v, static_cast<double>(def), ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
callable.add("base_value", wfl::variant(def));
return formula.evaluate(callable).as_decimal() / 1000.0 ;
}) * 100);
Expand All @@ -2512,7 +2512,7 @@ effect::effect(const unit_ability_list& list, int def, const_attack_ptr att, EFF
}
}
if (const config::attribute_value *v = cfg.get("divide")) {
int divide = static_cast<int>(get_single_ability_value(*v, static_cast<double>(def), ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
int divide = std::round(get_single_ability_value(*v, static_cast<double>(def), ability, list.loc(), att, [&](const wfl::formula& formula, wfl::map_formula_callable& callable) {
callable.add("base_value", wfl::variant(def));
return formula.evaluate(callable).as_decimal() / 1000.0 ;
}) * 100);
Expand Down

0 comments on commit 269658e

Please sign in to comment.