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}
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]

View file

@ -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

View file

@ -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"