Skip to content

Commit

Permalink
Fix [resistance] without max_value bug
Browse files Browse the repository at this point in the history
Fix wesnoth#8092 issue.

If none [resistance] ability of the list contain max_avlue, on default value of 100 is used instead.
  • Loading branch information
newfrenchy83 committed Dec 8, 2023
1 parent a320377 commit 5fd3157
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/units/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,9 +1798,17 @@ int unit::resistance_against(const std::string& damage_name,bool attacker,const
if(!resistance_abilities.empty()) {
unit_abilities::effect resist_effect(resistance_abilities, 100-res);

bool has_max_value = false;
for(auto& i : resistance_abilities) {
if((*i.ability_cfg).has_attribute("max_value")){
has_max_value = true;
break;
}
}
int max_value = has_max_value ? resistance_abilities.highest("max_value").first : 100;

This comment has been minimized.

Copy link
@ProditorMagnus

ProditorMagnus Dec 8, 2023

Assuming highest works as max, wouldnt it give wrong result? When one ability has max_value 10 and other max_value 20, I expect resistances limited to 10.

res = 100 - std::min<int>(
resist_effect.get_composite_value(),
resistance_abilities.highest("max_value").first
max_value
);
}

Expand Down

2 comments on commit 5fd3157

@newfrenchy83
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But when none abilites has max_value?

@ProditorMagnus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of them will have max value. If user does not specify it is default for all of them.

Please sign in to comment.