From daf054752a35d8395c2171b5bb5e8eb0e6407f10 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Tue, 1 Jan 2019 20:47:26 +0100 Subject: [PATCH] support item_name= in [store_items] we use it in SotA16 to make the scenario more robust against [modification]s that might add [item]s for decoration. --- .../Secrets_of_the_Ancients/scenarios/16_The_Mage.cfg | 4 ++++ data/lua/wml/items.lua | 11 +++++++++-- data/schema/core/actionwml.cfg | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/data/campaigns/Secrets_of_the_Ancients/scenarios/16_The_Mage.cfg b/data/campaigns/Secrets_of_the_Ancients/scenarios/16_The_Mage.cfg index 03098907f01..93cfac10abd 100644 --- a/data/campaigns/Secrets_of_the_Ancients/scenarios/16_The_Mage.cfg +++ b/data/campaigns/Secrets_of_the_Ancients/scenarios/16_The_Mage.cfg @@ -233,6 +233,7 @@ We crossed the high plateaus, and forded the Arkan-thoria. Then we headed up int x={X} y={Y} image=items/holy-water.png + name=holy_water [/item] #enddef @@ -246,6 +247,7 @@ We crossed the high plateaus, and forded the Arkan-thoria. Then we headed up int [store_items] variable=holy_waters + item_name=holy_water [/store_items] [message] @@ -307,9 +309,11 @@ We crossed the high plateaus, and forded the Arkan-thoria. Then we headed up int [/if] [remove_item] x,y=$x1,$y1 + image=holy_water [/remove_item] [store_items] variable=holy_waters + item_name=holy_water [/store_items] [/event] diff --git a/data/lua/wml/items.lua b/data/lua/wml/items.lua index 1cc31c150d8..e8f45b17ea3 100644 --- a/data/lua/wml/items.lua +++ b/data/lua/wml/items.lua @@ -90,6 +90,7 @@ end function wml_actions.store_items(cfg) local variable = cfg.variable or "items" + local item_name = cfg.item_name variable = tostring(variable or helper.wml_error("invalid variable= in [store_items]")) wml.variables[variable] = nil local index = 0 @@ -97,8 +98,14 @@ function wml_actions.store_items(cfg) local items = scenario_items[loc[1] * 10000 + loc[2]] if items then for j, item in ipairs(items) do - wml.variables[string.format("%s[%u]", variable, index)] = item - index = index + 1 + -- note: item_name can not be part of standard location filter because + -- there might be multiple items on one locations and we don't + -- want to return them all if only one matches the name + -- todo: consider making cfg.item_name a comma list or a regex. + if item_name == nil or item.name == item_name then + wml.variables[string.format("%s[%u]", variable, index)] = item + index = index + 1 + end end end end diff --git a/data/schema/core/actionwml.cfg b/data/schema/core/actionwml.cfg index bb7a644ec1d..7e66ec7f2f8 100644 --- a/data/schema/core/actionwml.cfg +++ b/data/schema/core/actionwml.cfg @@ -1119,6 +1119,7 @@ name="store_items" max=infinite super="$action_wml/store_locations" + {SIMPLE_KEY item_name string} [/tag] [tag] name="store_relative_direction"