Fix increase by percentage returns 1 if experience is equal to zero (#8425)

Using `[effect]app/y_to,increase=experience,"40%"` on a unit with 0 XP used
to give that unit 1 XP, because of a minimum in the C++.
This commit is contained in:
newfrenchy83 2024-02-19 13:49:09 +01:00 committed by GitHub
parent e14d7ddee9
commit b4abee7c38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 1 deletions

View file

@ -0,0 +1,44 @@
# wmllint: no translatables
#####
# API(s) being tested: [effect]apply_to=experience
##
# Actions:
# Try to set Alice's and Bob's experience to 0 and increase by 40%.
##
# Expected end state:
# Alice and Bob have 0 experience.
#####
{COMMON_KEEP_A_B_UNIT_TEST "increase_zero_experience_by_percentage" (
[event]
name=start
[modify_unit]
[filter]
id=alice,bob
[/filter]
[effect]
apply_to=experience
set=0
[/effect]
[effect]
apply_to=experience
increase=40%
[/effect]
[/modify_unit]
[store_unit]
[filter]
id=alice
[/filter]
variable=a
[/store_unit]
[store_unit]
[filter]
id=bob
[/filter]
variable=b
[/store_unit]
{ASSERT ({VARIABLE_CONDITIONAL a.experience numerical_equals 0})}
{ASSERT ({VARIABLE_CONDITIONAL b.experience numerical_equals 0})}
{SUCCEED}
[/event]
)}

View file

@ -2214,7 +2214,7 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
}
if(increase.empty() == false) {
experience_ = utils::apply_modifier(experience_, increase, 1);
experience_ = utils::apply_modifier(experience_, increase, 0);
}
} else if(apply_to == "max_experience") {
const std::string& increase = effect["increase"];

View file

@ -495,6 +495,7 @@
0 kill_fires_events
# Game mechanics
0 zero_experience
0 increase_zero_experience_by_percentage
0 unit_no_advancements
0 no_sides
# heal ability tests