allow comma-separated list for side= in [disallow_recruit]...

...and [set_recruit] (FR bug #17266) (the three should behave
analogically...)
This commit is contained in:
Anonymissimus 2010-12-17 19:42:07 +00:00
parent 2697d4588f
commit e1828a43f0

View file

@ -37,8 +37,8 @@ function wml_actions.message(cfg)
end end
end end
local function get_team(cfg, tag) local function get_team(side, tag)
local side = tonumber(cfg.side or 1) or side = tonumber(side or 1) or
helper.wml_error(tag .. " given a noninteger side= attribute.") helper.wml_error(tag .. " given a noninteger side= attribute.")
local team = wesnoth.sides[side] or local team = wesnoth.sides[side] or
helper.wml_error(tag .. " given an invalid side= attribute.") helper.wml_error(tag .. " given an invalid side= attribute.")
@ -73,14 +73,14 @@ function wml_actions.chat(cfg)
end end
function wml_actions.gold(cfg) function wml_actions.gold(cfg)
local team = get_team(cfg, "[gold]") local team = get_team(cfg.side, "[gold]")
local amount = tonumber(cfg.amount) or local amount = tonumber(cfg.amount) or
helper.wml_error "[gold] missing required amount= attribute." helper.wml_error "[gold] missing required amount= attribute."
team.gold = team.gold + amount team.gold = team.gold + amount
end end
function wml_actions.store_gold(cfg) function wml_actions.store_gold(cfg)
local team = get_team(cfg, "[store_gold]") local team = get_team(cfg.side, "[store_gold]")
wesnoth.set_variable(cfg.variable or "gold", team.gold) wesnoth.set_variable(cfg.variable or "gold", team.gold)
end end
@ -135,7 +135,8 @@ function wml_actions.fire_event(cfg)
end end
function wml_actions.disallow_recruit(cfg) function wml_actions.disallow_recruit(cfg)
local team = get_team(cfg, "[disallow_recruit]") for side in string.gmatch(cfg.side or 1, "[^%s,][^,]*") do
local team = get_team(side, "[disallow_recruit]")
local v = team.recruit local v = team.recruit
for w in string.gmatch(cfg.type, "[^%s,][^,]*") do for w in string.gmatch(cfg.type, "[^%s,][^,]*") do
for i, r in ipairs(v) do for i, r in ipairs(v) do
@ -146,15 +147,19 @@ function wml_actions.disallow_recruit(cfg)
end end
end end
team.recruit = v team.recruit = v
end
end end
function wml_actions.set_recruit(cfg) function wml_actions.set_recruit(cfg)
local team = get_team(cfg, "[set_recruit]") for side in string.gmatch(cfg.side or 1, "[^%s,][^,]*") do
local team = get_team(side, "[set_recruit]")
local v = {} local v = {}
for w in string.gmatch(cfg.recruit, "[^%s,][^,]*") do local recruit = cfg.recruit or helper.wml_error("[set_recruit] missing required recruit= attribute")
for w in string.gmatch(recruit, "[^%s,][^,]*") do
table.insert(v, w) table.insert(v, w)
end end
team.recruit = v team.recruit = v
end
end end
function wml_actions.store_map_dimensions(cfg) function wml_actions.store_map_dimensions(cfg)