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.
This commit is contained in:
gfgtdf 2019-01-01 20:47:26 +01:00
parent 0f1d70dbdc
commit daf054752a
3 changed files with 14 additions and 2 deletions

View file

@ -233,6 +233,7 @@ We crossed the high plateaus, and forded the Arkan-thoria. Then we headed up int
x={X} x={X}
y={Y} y={Y}
image=items/holy-water.png image=items/holy-water.png
name=holy_water
[/item] [/item]
#enddef #enddef
@ -246,6 +247,7 @@ We crossed the high plateaus, and forded the Arkan-thoria. Then we headed up int
[store_items] [store_items]
variable=holy_waters variable=holy_waters
item_name=holy_water
[/store_items] [/store_items]
[message] [message]
@ -307,9 +309,11 @@ We crossed the high plateaus, and forded the Arkan-thoria. Then we headed up int
[/if] [/if]
[remove_item] [remove_item]
x,y=$x1,$y1 x,y=$x1,$y1
image=holy_water
[/remove_item] [/remove_item]
[store_items] [store_items]
variable=holy_waters variable=holy_waters
item_name=holy_water
[/store_items] [/store_items]
[/event] [/event]

View file

@ -90,6 +90,7 @@ end
function wml_actions.store_items(cfg) function wml_actions.store_items(cfg)
local variable = cfg.variable or "items" local variable = cfg.variable or "items"
local item_name = cfg.item_name
variable = tostring(variable or helper.wml_error("invalid variable= in [store_items]")) variable = tostring(variable or helper.wml_error("invalid variable= in [store_items]"))
wml.variables[variable] = nil wml.variables[variable] = nil
local index = 0 local index = 0
@ -97,8 +98,14 @@ function wml_actions.store_items(cfg)
local items = scenario_items[loc[1] * 10000 + loc[2]] local items = scenario_items[loc[1] * 10000 + loc[2]]
if items then if items then
for j, item in ipairs(items) do for j, item in ipairs(items) do
wml.variables[string.format("%s[%u]", variable, index)] = item -- note: item_name can not be part of standard location filter because
index = index + 1 -- 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 end
end end

View file

@ -1119,6 +1119,7 @@
name="store_items" name="store_items"
max=infinite max=infinite
super="$action_wml/store_locations" super="$action_wml/store_locations"
{SIMPLE_KEY item_name string}
[/tag] [/tag]
[tag] [tag]
name="store_relative_direction" name="store_relative_direction"