From 89c9746e56f6fd10cfd4107c310eea51ec015af3 Mon Sep 17 00:00:00 2001 From: newfrenchy83 Date: Fri, 8 Dec 2023 20:02:39 +0100 Subject: [PATCH] add a error message --- .../AbilitiesWML/resistance_value.cfg | 94 ++----------------- src/units/unit.cpp | 8 ++ wml_test_schedule | 2 +- 3 files changed, 18 insertions(+), 86 deletions(-) diff --git a/data/test/scenarios/wml_tests/UnitsWML/AbilitiesWML/resistance_value.cfg b/data/test/scenarios/wml_tests/UnitsWML/AbilitiesWML/resistance_value.cfg index 99aa3d1e1cdeb..094f5f698ce94 100644 --- a/data/test/scenarios/wml_tests/UnitsWML/AbilitiesWML/resistance_value.cfg +++ b/data/test/scenarios/wml_tests/UnitsWML/AbilitiesWML/resistance_value.cfg @@ -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] )} + diff --git a/src/units/unit.cpp b/src/units/unit.cpp index 9903045fc367e..f637c6e4ea65a 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -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 @@ -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); diff --git a/wml_test_schedule b/wml_test_schedule index 6b352b80a4046..5d53b6a1a927b 100644 --- a/wml_test_schedule +++ b/wml_test_schedule @@ -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