Prevent duplicate advancements from being added to unit type (#7743)

* Add myself to Miscellaneous Contributors

* types: Add unit tests over adding advancements
This commit is contained in:
Cody Burchell 2023-07-08 22:08:10 -05:00 committed by GitHub
parent b50a8012ea
commit 71e83f7b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 1 deletions

View File

@ -0,0 +1,2 @@
### Miscellaneous and Bug Fixes
* Prevent duplicate advancements from being added to unit type. (issue #7009)

View File

@ -1199,6 +1199,9 @@
name = "Chusslove Illich (caslav.ilic)"
comment = "wmlxgetext improvements"
[/entry]
[entry]
name = "Cody Burchell (nullmoose)"
[/entry]
[entry]
name = "David Slabý (blaf)"
[/entry]

View File

@ -0,0 +1,73 @@
#####
# API(s) being tested: [modify_unit_type][add_advancement]
##
# Actions:
# Modify the horseman unit type to add the lancer advancement.
# Spawn a horseman unit.
##
# Expected end state:
# The spawned horseman should only have the lancer advancement listed once in advances_to.
#####
{GENERIC_UNIT_TEST "no_duplicate_advancements" (
[modify_unit_type]
type="Horseman"
add_advancement="Lancer"
[/modify_unit_type]
[event]
name=start
[unit]
x = 1
y = 1
type = Horseman
side = 1
id = charlie
canrecruit = no
[/unit]
[store_unit]
variable=horseman
[filter]
id = charlie
[/filter]
[/store_unit]
{ASSERT ({VARIABLE_CONDITIONAL horseman.advances_to equals "Knight,Lancer"})}
{SUCCEED}
[/event]
)}
#####
# API(s) being tested: [modify_unit_type][add_advancement]
##
# Actions:
# Modify the horseman unit type to add the cavalier advancement.
# Spawn a horseman unit.
##
# Expected end state:
# The spawned horseman should have the cavalier advancement listed in advances_to.
#####
{GENERIC_UNIT_TEST "add_advancement" (
[modify_unit_type]
type="Horseman"
add_advancement="Cavalier"
[/modify_unit_type]
[event]
name=start
[unit]
x = 1
y = 1
type = Horseman
side = 1
id = charlie
canrecruit = no
[/unit]
[store_unit]
variable=horseman
[filter]
id = charlie
[/filter]
[/store_unit]
{ASSERT ({VARIABLE_CONDITIONAL horseman.advances_to equals "Knight,Lancer,Cavalier"})}
{SUCCEED}
[/event]
)}

View File

@ -1367,7 +1367,9 @@ void unit_type::apply_scenario_fix(const config& cfg)
}
if(auto attr = cfg.get("add_advancement")) {
for(const auto& str : utils::split(attr->str())) {
advances_to_.push_back(str);
if(!utils::contains(advances_to_, str)) {
advances_to_.push_back(str);
}
}
}
if(auto attr = cfg.get("remove_advancement")) {

View File

@ -214,6 +214,8 @@
0 has_achievement
0 test_movement_used
0 test_attacks_used
0 no_duplicate_advancements
0 add_advancement
# Terrain mask tests
0 test_terrain_mask_simple_nop
0 test_terrain_mask_simple_set