From d090f91bcec3ffc5ef6c267376364b9226a52a0c Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 4 Oct 2019 23:49:05 -0400 Subject: [PATCH] Alter the special notes syntax in EffectWML so that the note macros can be reused in that context --- changelog.md | 2 +- data/core/macros/special-notes.cfg | 6 ++++++ data/schema/units/modifications.cfg | 8 ++------ src/units/unit.cpp | 19 ++++++++----------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index e3ba3a7c5dc2..4379301a66a7 100644 --- a/changelog.md +++ b/changelog.md @@ -49,7 +49,7 @@ * Special notes for units now use a new system, with a `[special_note]note=` tag. * This tag is supported both in `[unit]` and in `[unit_type]`. If used in `[unit]`, it will override the type's notes. * Standard special notes should now be added with `{NOTE_*}` instead of `{SPECIAL_NOTES_*}`. - * In `[effect]apply_to=profile`, `[add_special_note]` and `[remove_special_note]` are supported. + * In `[effect]apply_to=profile`, `[special_note]` is now supported to add/remove special notes. * Support for the deprecated "&image.png=text" syntax has been removed in all contexts - use the DescriptionWML attributes instead. * Fix infinite recursion in SUF with [hides] and [filter_vision]. (Issue#1389) ### Miscellaneous and bug fixes diff --git a/data/core/macros/special-notes.cfg b/data/core/macros/special-notes.cfg index 397879e373b3..fb43bd15515a 100644 --- a/data/core/macros/special-notes.cfg +++ b/data/core/macros/special-notes.cfg @@ -103,6 +103,12 @@ _"This unit has a defense cap on certain terrain types — it cannot achieve a h # New versions start here! +#define NOTE_REMOVE +[+special_note] + remove=yes +[/special_note] +#enddef + #define NOTE_SPIRIT [special_note] note={INTERNAL:SPECIAL_NOTES_SPIRIT} diff --git a/data/schema/units/modifications.cfg b/data/schema/units/modifications.cfg index db4adb83fb46..04f00eb41477 100644 --- a/data/schema/units/modifications.cfg +++ b/data/schema/units/modifications.cfg @@ -129,14 +129,10 @@ {SIMPLE_KEY small_portrait string} {SIMPLE_KEY description t_string} [tag] - name="add_special_note" - max="infinite" - {REQUIRED_KEY note t_string} - [/tag] - [tag] - name="remove_special_note" + name="special_note" max="infinite" {REQUIRED_KEY note t_string} + {SIMPLE_KEY remove bool} [/tag] [/case] [case] diff --git a/src/units/unit.cpp b/src/units/unit.cpp index e9b4370435f1..270fa2152af8 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -1939,18 +1939,15 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect) description_ = *v; } - if(config::const_child_itors cfg_range = effect.child_range("add_special_note")) { + if(config::const_child_itors cfg_range = effect.child_range("special_note")) { for(const config& c : cfg_range) { - special_notes_.emplace_back(c["note"].t_str()); - } - } - - if(config::const_child_itors cfg_range = effect.child_range("remove_special_note")) { - // TODO: Test that this works properly - for(const config& c : cfg_range) { - auto iter = std::find(special_notes_.begin(), special_notes_.end(), c["note"].t_str()); - if(iter != special_notes_.end()) { - special_notes_.erase(iter); + if(!c["remove"].to_bool()) { + special_notes_.emplace_back(c["note"].t_str()); + } else { + auto iter = std::find(special_notes_.begin(), special_notes_.end(), c["note"].t_str()); + if(iter != special_notes_.end()) { + special_notes_.erase(iter); + } } } }