Skip to content

Commit

Permalink
Alter the special notes syntax in EffectWML so that the note macros c…
Browse files Browse the repository at this point in the history
…an be reused in that context
  • Loading branch information
CelticMinstrel committed Oct 5, 2019
1 parent f05f811 commit d090f91
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions data/core/macros/special-notes.cfg
Expand Up @@ -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}
Expand Down
8 changes: 2 additions & 6 deletions data/schema/units/modifications.cfg
Expand Up @@ -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]
Expand Down
19 changes: 8 additions & 11 deletions src/units/unit.cpp
Expand Up @@ -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);
}
}
}
}
Expand Down

1 comment on commit d090f91

@CelticMinstrel
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, I forgot to double-check that to_bool() returns false if the key is missing...

Please sign in to comment.