Skip to content

Commit

Permalink
add a error message
Browse files Browse the repository at this point in the history
  • Loading branch information
newfrenchy83 committed Dec 8, 2023
1 parent 153fefe commit 89c9746
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,90 +53,14 @@
id=bob
[/filter]
[/object]
[object]
silent=yes
[effect]
apply_to = new_ability
[abilities]
[resistance]
id=steadfast1
multiply=2
affect_self=yes
[/resistance]
[/abilities]
[/effect]
[effect]
apply_to=attack
[set_specials]
mode=append
[attacks]
value=1
[/attacks]
[damage]
value=12
[/damage]
[chance_to_hit]
value=100
[/chance_to_hit]
[/set_specials]
[/effect]
[filter]
id=alice
[/filter]
[/object]

[store_unit]
[filter]
id=alice
[/filter]
variable=a
kill=yes
[/store_unit]
[store_unit]
[filter]
id=bob
[/filter]
variable=b
[/store_unit]
[unstore_unit]
variable=a
find_vacant=yes
x,y=$b.x,$b.y
[/unstore_unit]
[store_unit]
[filter]
id=alice
[/filter]
variable=a
[/store_unit]

[do_command]
[attack]
weapon=0
defender_weapon=0
[source]
x,y=$a.x,$a.y
[/source]
[destination]
x,y=$b.x,$b.y
[/destination]
[/attack]
[/do_command]
[store_unit]
[filter]
id=alice
[/filter]
variable=a
[/store_unit]
[store_unit]
[filter]
id=bob
[/filter]
variable=b
[/store_unit]
#damage are 12, if test fail hitpoints !=88
{ASSERT ({VARIABLE_CONDITIONAL a.hitpoints equals 88})}
{ASSERT ({VARIABLE_CONDITIONAL b.hitpoints equals 88})}
{SUCCEED}
{RETURN (
[not]
[have_unit]
id=bob
ability_id_active=steadfast1
[/have_unit]
[/not]
)}
[/event]
)}

8 changes: 8 additions & 0 deletions src/units/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "game_events/manager.hpp" // for add_events
#include "game_version.hpp"
#include "gettext.hpp" // for N_
#include "gui/dialogs/message.hpp"
#include "lexical_cast.hpp"
#include "log.hpp" // for LOG_STREAM, logger, etc
#include "map/map.hpp" // for gamemap
Expand Down Expand Up @@ -1791,9 +1792,16 @@ int unit::resistance_against(const std::string& damage_name,bool attacker,const
int res = opp_weapon ? movement_type_.resistance_against(*opp_weapon) : movement_type_.resistance_against(damage_name);

unit_ability_list resistance_abilities = get_abilities_weapons("resistance",loc, weapon, opp_weapon);
bool error_message = false;
utils::erase_if(resistance_abilities, [&](const unit_ability& i) {
if(!error_message && (*i.ability_cfg)["max_value"].empty()){
error_message = true;
}
return ((*i.ability_cfg)["max_value"].empty() || !resistance_filter_matches(*i.ability_cfg, attacker, damage_name, 100-res));
});
if(error_message){
gui2::show_error_message(_("One of [resistance] abilities don't have max_value attribute and is not valid."));
}

if(!resistance_abilities.empty()) {
unit_abilities::effect resist_effect(resistance_abilities, 100-res);
Expand Down
2 changes: 1 addition & 1 deletion wml_test_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
0 damage_secondary_type_test
0 swarms_filter_student_by_type
0 swarms_effects_not_checkable
0 resistance_without_value_test
1 resistance_without_value_test
0 filter_special_id_active
0 filter_ability_special_id_active
0 filter_special_id_not_exists
Expand Down

0 comments on commit 89c9746

Please sign in to comment.