mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-14 06:50:11 +00:00
Reverted 2011-09-21T21:44:58Z!thonsew@yahoo.com and 2011-09-20T21:21:21Z!thonsew@yahoo.com.
thonsew: The lua interface is not your playground. This is not the way I want the lua files or its C++ interface to be modified. You are invited to talk with me on IRC. some of the main reasons: -Your revisions contain lots of unneccessary changes, some of which break existing lua or wml without a reason. Do you ever look at the diffs? -Your revisions pack a lot of unrelated stuff together into one. 2011-09-21T21:44:58Z!thonsew@yahoo.com makes sense in some parts and is what you should have done in the first place.
This commit is contained in:
parent
83e2b2b999
commit
febb9da2ca
@ -4,7 +4,7 @@
|
||||
-- from the engine between 1.8 and 1.10.
|
||||
|
||||
function wesnoth.get_side(i)
|
||||
return wesnoth.sides[tonumber(i)]
|
||||
return wesnoth.sides[i]
|
||||
end
|
||||
|
||||
function wesnoth.get_side_count()
|
||||
|
@ -1,21 +1,7 @@
|
||||
--! #textdomain wesnoth
|
||||
|
||||
--! Create the t_tokens that helper will use for fast access to vconfig objects
|
||||
--! Allows the use of cfg[tk] which is faster than cfg["tk"] which is semantically the same as cfg.tk
|
||||
--for example local id_token = wesnoth.create_t_token("id")
|
||||
|
||||
local helper = {}
|
||||
|
||||
--! Checks if a value equals another value or the string of the value equals the string og the other value
|
||||
function helper.check_equal(a, b)
|
||||
return (a == b) or (tostring(a) == tostring(b))
|
||||
end
|
||||
|
||||
--! Checks if a value equals another value or the string of the value equals the string og the other value
|
||||
function helper.check_not_equal(a, b)
|
||||
return not ((a == b) or (tostring(a) == tostring(b)))
|
||||
end
|
||||
|
||||
--! Returns an iterator over all the sides matching a given filter that can be used in a for-in loop.
|
||||
function helper.get_sides(cfg)
|
||||
local function f(s)
|
||||
@ -33,7 +19,7 @@ end
|
||||
|
||||
--! Interrupts the current execution and displays a chat message that looks like a WML error.
|
||||
function helper.wml_error(m)
|
||||
error("~wml:" .. tostring(m), 0)
|
||||
error("~wml:" .. m, 0)
|
||||
end
|
||||
|
||||
--! Returns an iterator over teams that can be used in a for-in loop.
|
||||
@ -54,9 +40,9 @@ function helper.get_child(cfg, name, id)
|
||||
-- ipairs cannot be used on a vconfig object
|
||||
for i = 1, #cfg do
|
||||
local v = cfg[i]
|
||||
if helper.check_equal( v[1], name) then
|
||||
if v[1] == name then
|
||||
local w = v[2]
|
||||
if not id or helper.check_equal( w.id, id) then return w, i end
|
||||
if not id or w.id == id then return w, i end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -70,7 +56,7 @@ function helper.child_range(cfg, tag)
|
||||
c = cfg[i]
|
||||
if not c then return end
|
||||
s.i = i + 1
|
||||
until helper.check_equal( c[1] , tag)
|
||||
until c[1] == tag
|
||||
return c[2]
|
||||
end
|
||||
return f, { i = 1 }
|
||||
@ -85,10 +71,10 @@ function helper.modify_unit(filter, vars)
|
||||
variable = "LUA_modify_unit",
|
||||
kill = true
|
||||
})
|
||||
for i = 0, tonumber(wesnoth.get_variable("LUA_modify_unit.length")) - 1 do
|
||||
for i = 0, wesnoth.get_variable("LUA_modify_unit.length") - 1 do
|
||||
local u = "LUA_modify_unit[" .. i .. "]"
|
||||
for k, v in pairs(vars) do
|
||||
wesnoth.set_variable(u .. '.' .. tostring(k), v)
|
||||
wesnoth.set_variable(u .. '.' .. k, v)
|
||||
end
|
||||
wesnoth.fire("unstore_unit", {
|
||||
variable = u,
|
||||
@ -131,8 +117,8 @@ function helper.move_unit_fake(filter, to_x, to_y)
|
||||
gender = "$LUA_move_unit.gender",
|
||||
variation = "$LUA_move_unit.variation",
|
||||
side = "$LUA_move_unit.side",
|
||||
x = tostring(from_x) .. ',' .. tostring(to_x),
|
||||
y = tostring(from_y) .. ',' .. tostring(to_y)
|
||||
x = from_x .. ',' .. to_x,
|
||||
y = from_y .. ',' .. to_y
|
||||
})
|
||||
|
||||
wesnoth.fire("unstore_unit", { variable="LUA_move_unit", find_vacant=true })
|
||||
@ -160,9 +146,9 @@ end
|
||||
function variable_mt.__index(t, k)
|
||||
local i = tonumber(k)
|
||||
if i then
|
||||
k = tostring(t.__varname) .. '[' .. i .. ']'
|
||||
k = t.__varname .. '[' .. i .. ']'
|
||||
else
|
||||
k = tostring(t.__varname) .. '.' .. tostring(k)
|
||||
k = t.__varname .. '.' .. k
|
||||
end
|
||||
return get_variable_proxy(k)
|
||||
end
|
||||
@ -170,9 +156,9 @@ end
|
||||
function variable_mt.__newindex(t, k, v)
|
||||
local i = tonumber(k)
|
||||
if i then
|
||||
k = tostring(t.__varname) .. '[' .. i .. ']'
|
||||
k = t.__varname .. '[' .. i .. ']'
|
||||
else
|
||||
k = tostring(t.__varname) .. '.' .. tostring(k)
|
||||
k = t.__varname .. '.' .. k
|
||||
end
|
||||
set_variable_proxy(k, v)
|
||||
end
|
||||
@ -236,8 +222,8 @@ end
|
||||
--! @returns a table containing all the variables (starting at index 1).
|
||||
function helper.get_variable_array(var)
|
||||
local result = {}
|
||||
for i = 1, wesnoth.get_variable(tostring(var) .. ".length") do
|
||||
result[i] = wesnoth.get_variable(string.format("%s[%d]", tostring(var), i - 1))
|
||||
for i = 1, wesnoth.get_variable(var .. ".length") do
|
||||
result[i] = wesnoth.get_variable(string.format("%s[%d]", var, i - 1))
|
||||
end
|
||||
return result
|
||||
end
|
||||
@ -246,7 +232,7 @@ end
|
||||
function helper.set_variable_array(var, t)
|
||||
wesnoth.set_variable(var)
|
||||
for i, v in ipairs(t) do
|
||||
wesnoth.set_variable(string.format("%s[%d]", tostring(var), i - 1), v)
|
||||
wesnoth.set_variable(string.format("%s[%d]", var, i - 1), v)
|
||||
end
|
||||
end
|
||||
|
||||
@ -256,8 +242,8 @@ end
|
||||
--! @returns a table containing all the variable proxies (starting at index 1).
|
||||
function helper.get_variable_proxy_array(var)
|
||||
local result = {}
|
||||
for i = 1, wesnoth.get_variable(tostring(var) .. ".length") do
|
||||
result[i] = get_variable_proxy(string.format("%s[%d]", tostring(var), i - 1))
|
||||
for i = 1, wesnoth.get_variable(var .. ".length") do
|
||||
result[i] = get_variable_proxy(string.format("%s[%d]", var, i - 1))
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
@ -113,8 +113,8 @@ end
|
||||
|
||||
function methods:of_wml_var(name)
|
||||
local values = self.values
|
||||
for i = 0, wesnoth.get_variable(tostring(name) .. ".length") - 1 do
|
||||
local t = wesnoth.get_variable(string.format("%s[%d]", tostring(name), i))
|
||||
for i = 0, wesnoth.get_variable(name .. ".length") - 1 do
|
||||
local t = wesnoth.get_variable(string.format("%s[%d]", name, i))
|
||||
local x, y = t.x, t.y
|
||||
t.x, t.y = nil, nil
|
||||
values[index(x, y)] = next(t) and t or true
|
||||
@ -138,10 +138,10 @@ function methods:to_wml_var(name)
|
||||
wesnoth.set_variable(name)
|
||||
self:stable_iter(function(x, y, v)
|
||||
if type(v) == 'table' then
|
||||
wesnoth.set_variable(string.format("%s[%d]", tostring(name), i), v)
|
||||
wesnoth.set_variable(string.format("%s[%d]", name, i), v)
|
||||
end
|
||||
wesnoth.set_variable(string.format("%s[%d].x", tostring(name), i), x)
|
||||
wesnoth.set_variable(string.format("%s[%d].y", tostring(name), i), y)
|
||||
wesnoth.set_variable(string.format("%s[%d].x", name, i), x)
|
||||
wesnoth.set_variable(string.format("%s[%d].y", name, i), y)
|
||||
i = i + 1
|
||||
end)
|
||||
end
|
||||
|
@ -8,9 +8,7 @@ if wesnoth.package["lua/helper.lua"] then return end
|
||||
function wesnoth.game_events.on_load(cfg)
|
||||
if #cfg == 0 then return end
|
||||
local t = {}
|
||||
for i = 1,#cfg do
|
||||
t[i] = string.format("[%s]", tostring(cfg[i][1]))
|
||||
end
|
||||
for i = 1,#cfg do t[i] = string.format("[%s]", cfg[i][1]) end
|
||||
error(string.format("~wml:%s not supported at scenario toplevel", table.concat(t, ', ')), 0)
|
||||
end
|
||||
|
||||
@ -41,7 +39,8 @@ end
|
||||
|
||||
function wml_actions.chat(cfg)
|
||||
local side_list = wesnoth.get_sides(cfg)
|
||||
local message = tostring(cfg.message or helper.wml_error "[chat] missing required message= attribute.")
|
||||
local message = tostring(cfg.message) or
|
||||
helper.wml_error "[chat] missing required message= attribute."
|
||||
|
||||
local speaker = cfg.speaker
|
||||
if speaker then
|
||||
@ -51,7 +50,7 @@ function wml_actions.chat(cfg)
|
||||
end
|
||||
|
||||
for index, side in ipairs(side_list) do
|
||||
if helper.check_equal( side.controller , "human") then
|
||||
if side.controller == "human" then
|
||||
wesnoth.message(speaker, message)
|
||||
break
|
||||
end
|
||||
@ -72,8 +71,9 @@ function wml_actions.store_gold(cfg)
|
||||
end
|
||||
|
||||
function wml_actions.clear_variable(cfg)
|
||||
local names = tostring(cfg.name or helper.wml_error "[clear_variable] missing required name= attribute.")
|
||||
for w in string.gmatch(tostring(names), "[^%s,][^,]*") do
|
||||
local names = cfg.name or
|
||||
helper.wml_error "[clear_variable] missing required name= attribute."
|
||||
for w in string.gmatch(names, "[^%s,][^,]*") do
|
||||
wesnoth.set_variable(trim(w))
|
||||
end
|
||||
end
|
||||
@ -94,10 +94,10 @@ function wml_actions.store_unit_type(cfg)
|
||||
helper.wml_error "[store_unit_type] missing required type= attribute."
|
||||
wesnoth.set_variable(var)
|
||||
local i = 0
|
||||
for w in string.gmatch(tostring(types), "[^%s,][^,]*") do
|
||||
for w in string.gmatch(types, "[^%s,][^,]*") do
|
||||
local unit_type = wesnoth.unit_types[w] or
|
||||
helper.wml_error(string.format("Attempt to store nonexistent unit type '%s'.", w))
|
||||
wesnoth.set_variable(string.format("%s[%d]", tostring(var), i), unit_type.__cfg)
|
||||
wesnoth.set_variable(string.format("%s[%d]", var, i), unit_type.__cfg)
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
@ -123,7 +123,7 @@ end
|
||||
function wml_actions.allow_recruit(cfg)
|
||||
for index, team in ipairs(wesnoth.get_sides(nil, cfg, true)) do
|
||||
local v = team.recruit
|
||||
for type in string.gmatch(tostring(cfg.type), "[^%s,][^,]*") do
|
||||
for type in string.gmatch(cfg.type, "[^%s,][^,]*") do
|
||||
table.insert(v, type)
|
||||
wesnoth.add_known_unit(type)
|
||||
end
|
||||
@ -135,7 +135,7 @@ function wml_actions.allow_extra_recruit(cfg)
|
||||
local recruits = cfg.extra_recruit or helper.wml_error("[allow_extra_recruit] missing required extra_recruit= attribute")
|
||||
for index, unit in ipairs(wesnoth.get_units(cfg)) do
|
||||
local v = unit.extra_recruit
|
||||
for recruit in string.gmatch(tostring(recruits), "[^%s,][^,]*") do
|
||||
for recruit in string.gmatch(recruits, "[^%s,][^,]*") do
|
||||
table.insert(v, recruit)
|
||||
wesnoth.add_known_unit(recruit)
|
||||
end
|
||||
@ -146,9 +146,9 @@ end
|
||||
function wml_actions.disallow_recruit(cfg)
|
||||
for index, team in ipairs(wesnoth.get_sides(nil, cfg, true)) do
|
||||
local v = team.recruit
|
||||
for w in string.gmatch(tostring(cfg.type), "[^%s,][^,]*") do
|
||||
for w in string.gmatch(cfg.type, "[^%s,][^,]*") do
|
||||
for i, r in ipairs(v) do
|
||||
if helper.check_equal( r , w) then
|
||||
if r == w then
|
||||
table.remove(v, i)
|
||||
break
|
||||
end
|
||||
@ -162,9 +162,9 @@ function wml_actions.disallow_extra_recruit(cfg)
|
||||
local recruits = cfg.extra_recruit or helper.wml_error("[disallow_extra_recruit] missing required extra_recruit= attribute")
|
||||
for index, unit in ipairs(wesnoth.get_units(cfg)) do
|
||||
local v = unit.extra_recruit
|
||||
for w in string.gmatch(tostring(recruits), "[^%s,][^,]*") do
|
||||
for w in string.gmatch(recruits, "[^%s,][^,]*") do
|
||||
for i, r in ipairs(v) do
|
||||
if helper.check_equal( r , w) then
|
||||
if r == w then
|
||||
table.remove(v, i)
|
||||
break
|
||||
end
|
||||
@ -178,7 +178,7 @@ function wml_actions.set_recruit(cfg)
|
||||
local recruit = cfg.recruit or helper.wml_error("[set_recruit] missing required recruit= attribute")
|
||||
for index, team in ipairs(wesnoth.get_sides(nil, cfg, true)) do
|
||||
local v = {}
|
||||
for w in string.gmatch(tostring(recruit), "[^%s,][^,]*") do
|
||||
for w in string.gmatch(recruit, "[^%s,][^,]*") do
|
||||
table.insert(v, w)
|
||||
end
|
||||
team.recruit = v
|
||||
@ -189,7 +189,7 @@ function wml_actions.set_extra_recruit(cfg)
|
||||
local recruits = cfg.extra_recruit or helper.wml_error("[set_extra_recruit] missing required extra_recruit= attribute")
|
||||
local v = {}
|
||||
|
||||
for w in string.gmatch(tostring(recruits), "[^%s,][^,]*") do
|
||||
for w in string.gmatch(recruits, "[^%s,][^,]*") do
|
||||
table.insert(v, w)
|
||||
end
|
||||
|
||||
@ -201,9 +201,9 @@ end
|
||||
function wml_actions.store_map_dimensions(cfg)
|
||||
local var = cfg.variable or "map_size"
|
||||
local w, h, b = wesnoth.get_map_size()
|
||||
wesnoth.set_variable(tostring(var) .. ".width", w)
|
||||
wesnoth.set_variable(tostring(var) .. ".height", h)
|
||||
wesnoth.set_variable(tostring(var) .. ".border_size", b)
|
||||
wesnoth.set_variable(var .. ".width", w)
|
||||
wesnoth.set_variable(var .. ".height", h)
|
||||
wesnoth.set_variable(var .. ".border_size", b)
|
||||
end
|
||||
|
||||
function wml_actions.unit_worth(cfg)
|
||||
@ -213,7 +213,7 @@ function wml_actions.unit_worth(cfg)
|
||||
local hp = u.hitpoints / u.max_hitpoints
|
||||
local xp = u.experience / u.max_experience
|
||||
local best_adv = ut.cost
|
||||
for w in string.gmatch(tostring(ut.__cfg.advances_to), "[^%s,][^,]*") do
|
||||
for w in string.gmatch(ut.__cfg.advances_to, "[^%s,][^,]*") do
|
||||
local uta = wesnoth.unit_types[w]
|
||||
if uta and uta.cost > best_adv then best_adv = uta.cost end
|
||||
end
|
||||
@ -228,26 +228,23 @@ function wml_actions.wml_action(cfg)
|
||||
-- The new tag's name
|
||||
local name = cfg.name or
|
||||
helper.wml_error "[wml_action] missing required name= attribute."
|
||||
local code = tostring(cfg.lua_function or helper.wml_error "[wml_action] missing required lua_function= attribute.")
|
||||
local code = cfg.lua_function or
|
||||
helper.wml_error "[wml_action] missing required lua_function= attribute."
|
||||
local bytecode, message = loadstring(code)
|
||||
if not bytecode then
|
||||
helper.wml_error("[wml_action] failed to compile Lua code: " .. tostring(message))
|
||||
helper.wml_error("[wml_action] failed to compile Lua code: " .. message)
|
||||
end
|
||||
-- The lua function that is executed when the tag is called
|
||||
local lua_function = bytecode() or
|
||||
helper.wml_error "[wml_action] expects a Lua code returning a function."
|
||||
-- Store it as a t_token and a string
|
||||
wml_actions[name] = lua_function
|
||||
wml_actions[tostring(name)] = lua_function
|
||||
end
|
||||
|
||||
function wml_actions.lua(cfg)
|
||||
local cfg = helper.shallow_literal(cfg)
|
||||
|
||||
local bytecode, message = loadstring(tostring(cfg.code or ""))
|
||||
if not bytecode then error("~lua:" .. tostring(message), 0) end
|
||||
local ww, ii = helper.get_child(cfg, "args")
|
||||
bytecode(ww)
|
||||
local bytecode, message = loadstring(cfg.code or "")
|
||||
if not bytecode then error("~lua:" .. message, 0) end
|
||||
bytecode(helper.get_child(cfg, "args"))
|
||||
end
|
||||
|
||||
function wml_actions.music(cfg)
|
||||
@ -265,33 +262,29 @@ local function handle_event_commands(cfg)
|
||||
local cmd = v[1]
|
||||
local arg = v[2]
|
||||
local insert_from
|
||||
|
||||
if helper.check_equal( cmd , "insert_tag") then
|
||||
if cmd == "insert_tag" then
|
||||
cmd = arg.name
|
||||
local from = arg.variable
|
||||
arg = wesnoth.get_variable(from)
|
||||
|
||||
if type(arg) ~= "table" then
|
||||
-- Corner case: A missing variable is replaced
|
||||
-- by an empty container rather than being ignored.
|
||||
arg = {}
|
||||
elseif string.sub(tostring(from), -1) ~= ']' then
|
||||
elseif string.sub(from, -1) ~= ']' then
|
||||
insert_from = from
|
||||
end
|
||||
arg = wesnoth.tovconfig(arg)
|
||||
end
|
||||
|
||||
if not string.find(tostring(cmd), "^filter") then
|
||||
scmd = tostring(cmd);
|
||||
cmd = wml_actions[cmd] or wml_actions[tostring(cmd)] or
|
||||
helper.wml_error(string.format("[%s] not supported", tostring(cmd)))
|
||||
if not string.find(cmd, "^filter") then
|
||||
cmd = wml_actions[cmd] or
|
||||
helper.wml_error(string.format("[%s] not supported", cmd))
|
||||
if insert_from then
|
||||
local j = 0
|
||||
repeat
|
||||
cmd(arg)
|
||||
j = j + 1
|
||||
if j >= wesnoth.get_variable(tostring(insert_from) .. ".length") then break end
|
||||
arg = wesnoth.tovconfig(wesnoth.get_variable(string.format("%s[%d]", tostring(insert_from), j)))
|
||||
if j >= wesnoth.get_variable(insert_from .. ".length") then break end
|
||||
arg = wesnoth.tovconfig(wesnoth.get_variable(string.format("%s[%d]", insert_from, j)))
|
||||
until false
|
||||
else
|
||||
cmd(arg)
|
||||
@ -331,8 +324,8 @@ function wml_actions.switch(cfg)
|
||||
-- Execute all the [case]s where the value matches.
|
||||
for v in helper.child_range(cfg, "case") do
|
||||
local match = false
|
||||
for w in string.gmatch(tostring(v.value), "[^%s,][^,]*") do
|
||||
if helper.check_equal( w , value) then match = true ; break end
|
||||
for w in string.gmatch(v.value, "[^%s,][^,]*") do
|
||||
if w == tostring(value) then match = true ; break end
|
||||
end
|
||||
if match then
|
||||
handle_event_commands(v)
|
||||
@ -378,11 +371,11 @@ function wml_actions.unit_overlay(cfg)
|
||||
local img = cfg.image
|
||||
for i,u in ipairs(wesnoth.get_units(cfg)) do
|
||||
local ucfg = u.__cfg
|
||||
for w in string.gmatch(tostring(ucfg.overlays), "[^%s,][^,]*") do
|
||||
if helper.check_equal( w , img) then ucfg = nil end
|
||||
for w in string.gmatch(ucfg.overlays, "[^%s,][^,]*") do
|
||||
if w == img then ucfg = nil end
|
||||
end
|
||||
if ucfg then
|
||||
ucfg.overlays = tostring(ucfg.overlays) .. ',' .. tostring(img)
|
||||
ucfg.overlays = ucfg.overlays .. ',' .. img
|
||||
wesnoth.put_unit(ucfg)
|
||||
end
|
||||
end
|
||||
@ -393,7 +386,7 @@ function wml_actions.remove_unit_overlay(cfg)
|
||||
for i,u in ipairs(wesnoth.get_units(cfg)) do
|
||||
local ucfg = u.__cfg
|
||||
local t = {}
|
||||
for w in string.gmatch(tostring(ucfg.overlays), "[^%s,][^,]*") do
|
||||
for w in string.gmatch(ucfg.overlays, "[^%s,][^,]*") do
|
||||
if w ~= img then table.insert(t, w) end
|
||||
end
|
||||
ucfg.overlays = table.concat(t, ',')
|
||||
@ -407,38 +400,35 @@ function wml_actions.store_turns(cfg)
|
||||
end
|
||||
|
||||
function wml_actions.store_unit(cfg)
|
||||
local filter = helper.get_child(cfg, "filter") or helper.wml_error "[store_unit] missing required [filter] tag"
|
||||
local filter = helper.get_child(cfg, "filter") or
|
||||
helper.wml_error "[store_unit] missing required [filter] tag"
|
||||
local kill_units = cfg.kill
|
||||
local mode = cfg.mode
|
||||
|
||||
local var = cfg.variable or "unit"
|
||||
local idx = 0
|
||||
if (helper.check_equal( mode , "append") )then
|
||||
idx = wesnoth.get_variable(tostring(var) .. ".length")
|
||||
elseif helper.check_not_equal( mode, "replace" ) then
|
||||
if mode == "append" then
|
||||
idx = wesnoth.get_variable(var .. ".length")
|
||||
elseif mode ~= "replace" then
|
||||
wesnoth.set_variable(var)
|
||||
end
|
||||
|
||||
for i,u in ipairs(wesnoth.get_units(filter)) do
|
||||
wesnoth.set_variable(string.format("%s[%d]", tostring(var), idx), u.__cfg)
|
||||
wesnoth.set_variable(string.format("%s[%d]", var, idx), u.__cfg)
|
||||
idx = idx + 1
|
||||
if kill_units then
|
||||
wesnoth.put_unit(u.x, u.y)
|
||||
end
|
||||
if kill_units then wesnoth.put_unit(u.x, u.y) end
|
||||
end
|
||||
|
||||
if (not filter.x or helper.check_equal( filter.x , "recall")) and (not filter.y or helper.check_equal( filter.y , "recall")) then
|
||||
if (not filter.x or filter.x == "recall") and (not filter.y or filter.y == "recall") then
|
||||
for i,u in ipairs(wesnoth.get_recall_units(filter)) do
|
||||
local ucfg = u.__cfg
|
||||
ucfg.x = "recall"
|
||||
ucfg.y = "recall"
|
||||
wesnoth.set_variable(string.format("%s[%d]", tostring(var), idx), ucfg)
|
||||
wesnoth.set_variable(string.format("%s[%d]", var, idx), ucfg)
|
||||
idx = idx + 1
|
||||
if kill_units then wesnoth.extract_unit(u) end
|
||||
end
|
||||
end
|
||||
|
||||
ssname = string.format("%s[%d]", tostring(var), idx-1)
|
||||
end
|
||||
|
||||
function wml_actions.sound(cfg)
|
||||
@ -459,7 +449,7 @@ function wml_actions.store_locations(cfg)
|
||||
if wesnoth.get_terrain_info(t).village then
|
||||
res.owner_side = wesnoth.get_village_owner(x, y) or 0
|
||||
end
|
||||
wesnoth.set_variable(string.format("%s[%d]", tostring(var), i - 1), res)
|
||||
wesnoth.set_variable(string.format("%s[%d]", var, i - 1), res)
|
||||
end
|
||||
end
|
||||
|
||||
@ -471,7 +461,7 @@ function wml_actions.store_reachable_locations(cfg)
|
||||
local moves = cfg.moves or "current"
|
||||
local variable = cfg.variable or helper.wml_error "[store_reachable_locations] missing required variable= key"
|
||||
local reach_param = { viewing_side = cfg.viewing_side or 0 }
|
||||
if helper.check_equal( range , "vision") then
|
||||
if range == "vision" then
|
||||
moves = "max"
|
||||
reach_param.ignore_units = true
|
||||
end
|
||||
@ -480,7 +470,7 @@ function wml_actions.store_reachable_locations(cfg)
|
||||
|
||||
for i,unit in ipairs(wesnoth.get_units(unit_filter)) do
|
||||
local unit_reach
|
||||
if helper.check_equal( moves, "max" ) then
|
||||
if moves == "max" then
|
||||
local saved_moves = unit.moves
|
||||
unit.moves = unit.max_moves
|
||||
unit_reach = location_set.of_pairs(wesnoth.find_reach(unit, reach_param))
|
||||
@ -489,7 +479,7 @@ function wml_actions.store_reachable_locations(cfg)
|
||||
unit_reach = location_set.of_pairs(wesnoth.find_reach(unit, reach_param))
|
||||
end
|
||||
|
||||
if helper.check_equal( range, "vision" ) or helper.check_equal( range, "attack" ) then
|
||||
if range == "vision" or range == "attack" then
|
||||
unit_reach:iter(function(x, y)
|
||||
reach:insert(x, y)
|
||||
for u,v in helper.adjacent_tiles(x, y) do
|
||||
@ -528,8 +518,8 @@ function wml_actions.modify_unit(cfg)
|
||||
|
||||
local function handle_attributes(cfg, unit_path, toplevel)
|
||||
for current_key, current_value in pairs(helper.shallow_parsed(cfg)) do
|
||||
if type(current_value) ~= "table" and (not toplevel or helper.check_not_equal( current_key, "type" )) then
|
||||
wesnoth.set_variable(string.format("%s.%s", tostring(unit_path), tostring(current_key)), current_value)
|
||||
if type(current_value) ~= "table" and (not toplevel or current_key ~= "type") then
|
||||
wesnoth.set_variable(string.format("%s.%s", unit_path, current_key), current_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -542,7 +532,8 @@ function wml_actions.modify_unit(cfg)
|
||||
for current_index, current_table in ipairs(cfg) do
|
||||
local current_tag = current_table[1]
|
||||
local tag_index = children_handled[current_tag] or 0
|
||||
handle_child(current_table[2], string.format("%s.%s[%u]", tostring(unit_path), tostring(current_tag), tostring(tag_index)))
|
||||
handle_child(current_table[2], string.format("%s.%s[%u]",
|
||||
unit_path, current_tag, tag_index))
|
||||
children_handled[current_tag] = tag_index + 1
|
||||
end
|
||||
end
|
||||
@ -550,15 +541,15 @@ function wml_actions.modify_unit(cfg)
|
||||
local filter = helper.get_child(cfg, "filter") or helper.wml_error "[modify_unit] missing required [filter] tag"
|
||||
local function handle_unit(unit_num)
|
||||
local children_handled = {}
|
||||
local unit_path = string.format("%s[%u]", tostring(unit_variable), unit_num)
|
||||
local unit_path = string.format("%s[%u]", unit_variable, unit_num)
|
||||
wesnoth.set_variable("this_unit", wesnoth.get_variable(unit_path))
|
||||
handle_attributes(cfg, unit_path, true)
|
||||
|
||||
for current_index, current_table in ipairs(helper.shallow_parsed(cfg)) do
|
||||
local current_tag = current_table[1]
|
||||
if helper.check_equal( current_tag, "filter" ) then
|
||||
if current_tag == "filter" then
|
||||
-- nothing
|
||||
elseif helper.check_equal( current_tag, "object" ) or helper.check_equal( current_tag, "trait" ) then
|
||||
elseif current_tag == "object" or current_tag == "trait" then
|
||||
local unit = wesnoth.get_variable(unit_path)
|
||||
unit = wesnoth.create_unit(unit)
|
||||
wesnoth.add_modification(unit, current_tag, current_table[2])
|
||||
@ -566,20 +557,21 @@ function wml_actions.modify_unit(cfg)
|
||||
wesnoth.set_variable(unit_path, unit)
|
||||
else
|
||||
local tag_index = children_handled[current_tag] or 0
|
||||
handle_child(current_table[2], string.format("%s.%s[%u]", tostring(unit_path), tostring(current_tag), tag_index))
|
||||
handle_child(current_table[2], string.format("%s.%s[%u]",
|
||||
unit_path, current_tag, tag_index))
|
||||
children_handled[current_tag] = tag_index + 1
|
||||
end
|
||||
end
|
||||
|
||||
if cfg.type then
|
||||
if helper.check_not_equal( cfg.type, "" ) then wesnoth.set_variable(tostring(unit_path) .. ".advances_to", cfg.type) end
|
||||
wesnoth.set_variable(tostring(unit_path) .. ".experience", wesnoth.get_variable(tostring(unit_path) .. ".max_experience"))
|
||||
if cfg.type ~= "" then wesnoth.set_variable(unit_path .. ".advances_to", cfg.type) end
|
||||
wesnoth.set_variable(unit_path .. ".experience", wesnoth.get_variable(unit_path .. ".max_experience"))
|
||||
end
|
||||
wml_actions.unstore_unit { variable = unit_path }
|
||||
end
|
||||
|
||||
wml_actions.store_unit { {"filter", filter}, variable = unit_variable, kill = true }
|
||||
local max_index = wesnoth.get_variable(tostring(unit_variable) .. ".length") - 1
|
||||
local max_index = wesnoth.get_variable(unit_variable .. ".length") - 1
|
||||
|
||||
for current_unit = 0, max_index do
|
||||
handle_unit(current_unit)
|
||||
@ -591,8 +583,8 @@ end
|
||||
|
||||
function wml_actions.move_unit(cfg)
|
||||
local coordinate_error = "invalid coordinate in [move_unit]"
|
||||
local to_x = tostring(cfg.to_x or helper.wml_error(coordinate_error))
|
||||
local to_y = tostring(cfg.to_y or helper.wml_error(coordinate_error))
|
||||
local to_x = tostring(cfg.to_x) or helper.wml_error(coordinate_error)
|
||||
local to_y = tostring(cfg.to_y) or helper.wml_error(coordinate_error)
|
||||
local fire_event = cfg.fire_event
|
||||
local check_passability = cfg.check_passability; if check_passability == nil then check_passability = true end
|
||||
cfg = helper.literal(cfg)
|
||||
@ -602,7 +594,7 @@ function wml_actions.move_unit(cfg)
|
||||
local pattern = "[^%s,]+"
|
||||
for current_unit_index, current_unit in ipairs(units) do
|
||||
if not fire_event or current_unit.valid then
|
||||
local xs, ys = string.gmatch(tostring(to_x), pattern), string.gmatch(tostring(to_y), pattern)
|
||||
local xs, ys = string.gmatch(to_x, pattern), string.gmatch(to_y, pattern)
|
||||
local move_string_x = current_unit.x
|
||||
local move_string_y = current_unit.y
|
||||
local pass_check = nil
|
||||
@ -614,8 +606,8 @@ function wml_actions.move_unit(cfg)
|
||||
y = tonumber(y) or helper.wml_error(coordinate_error)
|
||||
x, y = wesnoth.find_vacant_tile(x, y, pass_check)
|
||||
if not x or not y then helper.wml_error("Could not find a suitable hex near to one of the target hexes in [move_unit].") end
|
||||
move_string_x = string.format("%s,%u", tostring(move_string_x), x)
|
||||
move_string_y = string.format("%s,%u", tostring(move_string_y), y)
|
||||
move_string_x = string.format("%s,%u", move_string_x, x)
|
||||
move_string_y = string.format("%s,%u", move_string_y, y)
|
||||
local next_x, next_y = xs(), ys()
|
||||
if not next_x and not next_y then break end
|
||||
x, y = next_x, next_y
|
||||
@ -727,7 +719,7 @@ function wml_actions.harm_unit(cfg)
|
||||
for index, unit_to_harm in ipairs(wesnoth.get_units(filter)) do
|
||||
if not fire_event or unit_to_harm.valid then
|
||||
if animate then
|
||||
if helper.check_not_equal( animate, "defender" ) and harmer and harmer.valid then
|
||||
if animate ~= "defender" and harmer and harmer.valid then
|
||||
wesnoth.scroll_to_tile(harmer.x, harmer.y, true)
|
||||
wml_actions.animate_unit( { flag = "attack", hits = true, { "filter", { id = harmer.id } },
|
||||
{ "primary_attack", primary_attack },
|
||||
@ -753,7 +745,7 @@ function wml_actions.harm_unit(cfg)
|
||||
|
||||
local function set_status(name, male_string, female_string, sound)
|
||||
if not cfg[name] or unit_to_harm.status[name] then return end
|
||||
if helper.check_equal( gender, "female" ) then
|
||||
if gender == "female" then
|
||||
text = string.format("%s%s%s", text, tostring(female_string), "\n")
|
||||
else
|
||||
text = string.format("%s%s%s", text, tostring(male_string), "\n")
|
||||
@ -776,7 +768,7 @@ function wml_actions.harm_unit(cfg)
|
||||
text = string.format("%s%s", "\t", text)
|
||||
end
|
||||
|
||||
if animate and helper.check_not_equal( animate, "attacker" ) then
|
||||
if animate and animate ~= "attacker" then
|
||||
if harmer and harmer.valid then
|
||||
wml_actions.animate_unit( { flag = "defend", hits = true, { "filter", { id = unit_to_harm.id } },
|
||||
{ "primary_attack", primary_attack },
|
||||
@ -792,12 +784,12 @@ function wml_actions.harm_unit(cfg)
|
||||
wesnoth.float_label( unit_to_harm.x, unit_to_harm.y, string.format( "<span foreground='red'>%s</span>", text ) )
|
||||
|
||||
local function calc_xp( level ) -- to calculate the experience in case of kill
|
||||
if helper.check_equal( level, 0 ) then return 4
|
||||
if level == 0 then return 4
|
||||
else return level * 8 end
|
||||
end
|
||||
|
||||
if helper.check_not_equal( experience, false ) and harmer and harmer.valid and wesnoth.is_enemy( unit_to_harm.side, harmer.side ) then -- no XP earned for harming friendly units
|
||||
if helper.check_not_equal( kill, false ) and unit_to_harm.hitpoints <= 0 then
|
||||
if experience ~= false and harmer and harmer.valid and wesnoth.is_enemy( unit_to_harm.side, harmer.side ) then -- no XP earned for harming friendly units
|
||||
if kill ~= false and unit_to_harm.hitpoints <= 0 then
|
||||
harmer.experience = harmer.experience + calc_xp( unit_to_harm.__cfg.level )
|
||||
else
|
||||
unit_to_harm.experience = unit_to_harm.experience + harmer.__cfg.level
|
||||
@ -805,7 +797,7 @@ function wml_actions.harm_unit(cfg)
|
||||
end
|
||||
end
|
||||
|
||||
if helper.check_not_equal( kill, false ) and unit_to_harm.hitpoints <= 0 then
|
||||
if kill ~= false and unit_to_harm.hitpoints <= 0 then
|
||||
local function bool( value ) -- support function for kill tag below
|
||||
if value then return true
|
||||
else return false end
|
||||
@ -818,11 +810,11 @@ function wml_actions.harm_unit(cfg)
|
||||
end
|
||||
|
||||
if variable then
|
||||
wesnoth.set_variable(string.format("%s[%d]", tostring(variable), index - 1), { harm_amount = damage })
|
||||
wesnoth.set_variable(string.format("%s[%d]", variable, index - 1), { harm_amount = damage })
|
||||
end
|
||||
|
||||
-- both may no longer be alive at this point, so double check
|
||||
if helper.check_not_equal( experience, false ) and harmer and unit_to_harm.valid and unit_to_harm.experience >= unit_to_harm.max_experience then
|
||||
if experience ~= false and harmer and unit_to_harm.valid and unit_to_harm.experience >= unit_to_harm.max_experience then
|
||||
wml_actions.store_unit { { "filter", { id = unit_to_harm.id } }, variable = "Lua_store_unit", kill = true }
|
||||
wml_actions.unstore_unit { variable = "Lua_store_unit", find_vacant = false, advance = true }
|
||||
wesnoth.set_variable ( "Lua_store_unit", nil )
|
||||
@ -832,7 +824,7 @@ function wml_actions.harm_unit(cfg)
|
||||
end
|
||||
end
|
||||
|
||||
if helper.check_not_equal( experience, false ) and harmer and harmer.valid and harmer.experience >= harmer.max_experience then
|
||||
if experience ~= false and harmer and harmer.valid and harmer.experience >= harmer.max_experience then
|
||||
wml_actions.store_unit { { "filter", { id = harmer.id } }, variable = "Lua_store_unit", kill = true }
|
||||
wml_actions.unstore_unit { variable = "Lua_store_unit", find_vacant = false, advance = true }
|
||||
wesnoth.set_variable ( "Lua_store_unit", nil )
|
||||
@ -890,14 +882,14 @@ function wml_actions.store_side(cfg)
|
||||
gold = t.gold,
|
||||
side = side_number
|
||||
}
|
||||
wesnoth.set_variable(string.format("%s[%u]", tostring(variable), index), container)
|
||||
wesnoth.set_variable(string.format("%s[%u]", variable, index), container)
|
||||
index = index + 1
|
||||
end
|
||||
-- deprecated starting with 1.9.0
|
||||
-- added message starting with 1.9.7
|
||||
-- assuming that a wml author will usually be in debug mode and a player will not...
|
||||
if wesnoth.game_config.debug then
|
||||
wesnoth.message("warning", string.format("$%s.colour is deprecated, use $%s.color (if needed)", tostring(variable), tostring(variable)))
|
||||
wesnoth.message("warning", string.format("$%s.colour is deprecated, use $%s.color (if needed)", variable, variable))
|
||||
end
|
||||
end
|
||||
|
||||
@ -925,8 +917,8 @@ function wml_actions.add_ai_behavior(cfg)
|
||||
helper.wml_error("[add_ai_behavior]: invalid execution/evaluation handler(s)")
|
||||
end
|
||||
|
||||
local id = "bca-" .. tostring(ca_counter)
|
||||
local path = "stage[" .. tostring(loop_id) .. "].candidate_action[" .. tostring(id) .. "]" -- bca: behavior candidate action
|
||||
local id = "bca-" .. ca_counter
|
||||
local path = "stage[" .. loop_id .. "].candidate_action[" .. id .. "]" -- bca: behavior candidate action
|
||||
|
||||
ca_counter = ca_counter + 1
|
||||
|
||||
|
@ -21,7 +21,7 @@ local function remove_overlay(x, y, name)
|
||||
if name then
|
||||
for i = #items,1,-1 do
|
||||
local item = items[i]
|
||||
if helper.check_equal( item.image, name ) or helper.check_equal( item.halo, name ) then
|
||||
if item.image == name or item.halo == name then
|
||||
table.remove(items, i)
|
||||
end
|
||||
end
|
||||
@ -47,7 +47,7 @@ function game_events.on_load(cfg)
|
||||
local i = 1
|
||||
while i <= #cfg do
|
||||
local v = cfg[i]
|
||||
if helper.check_equal( v[1], "item" ) then
|
||||
if v[1] == "item" then
|
||||
local v2 = v[2]
|
||||
add_overlay(v2.x, v2.y, v2)
|
||||
table.remove(cfg, i)
|
||||
@ -90,7 +90,7 @@ function wml_actions.store_items(cfg)
|
||||
local items = scenario_items[loc[1] * 10000 + loc[2]]
|
||||
if not items then break end
|
||||
for j, item in ipairs(items) do
|
||||
wesnoth.set_variable(string.format("%s[%u]", tostring(variable), index), item)
|
||||
wesnoth.set_variable(string.format("%s[%u]", variable, index), item)
|
||||
index = index + 1
|
||||
end
|
||||
until true
|
||||
|
@ -7,7 +7,7 @@ local function color_prefix(r, g, b)
|
||||
end
|
||||
|
||||
local function insert_before_nl(s, t)
|
||||
return string.gsub(tostring(s), "[^\n]*", "%0" .. tostring(t), 1)
|
||||
return string.gsub(tostring(s), "[^\n]*", "%0" .. t, 1)
|
||||
end
|
||||
|
||||
local scenario_objectives = {}
|
||||
@ -26,7 +26,7 @@ local old_on_load = game_events.on_load
|
||||
function game_events.on_load(cfg)
|
||||
for i = #cfg,1,-1 do
|
||||
local v = cfg[i]
|
||||
if helper.check_equal( v[1], "objectives" ) then
|
||||
if v[1] == "objectives" then
|
||||
local v2 = v[2]
|
||||
scenario_objectives[v2.side or 0] = v2
|
||||
table.remove(cfg, i)
|
||||
@ -47,18 +47,18 @@ local function generate_objectives(cfg)
|
||||
local gold_carryover = ""
|
||||
local notes = ""
|
||||
|
||||
local win_string = tostring(cfg.victory_string or _ "Victory:")
|
||||
local lose_string = tostring(cfg.defeat_string or _ "Defeat:")
|
||||
local gold_carryover_string = tostring(cfg.gold_carryover_string or _ "Gold carryover:")
|
||||
local notes_string = tostring(cfg.notes_string or _ "Notes:")
|
||||
local win_string = cfg.victory_string or _ "Victory:"
|
||||
local lose_string = cfg.defeat_string or _ "Defeat:"
|
||||
local gold_carryover_string = cfg.gold_carryover_string or _ "Gold carryover:"
|
||||
local notes_string = cfg.notes_string or _ "Notes:"
|
||||
|
||||
local bullet = "• "
|
||||
|
||||
for obj in helper.child_range(cfg, "objective") do
|
||||
local show_if = helper.get_child(obj, "show_if")
|
||||
if not show_if or wesnoth.eval_conditional(show_if) then
|
||||
local condition = tostring(obj.condition)
|
||||
local description = tostring(obj.description or "")
|
||||
local condition = obj.condition
|
||||
local description = obj.description or ""
|
||||
local turn_counter = ""
|
||||
|
||||
if obj.show_turn_counter then
|
||||
@ -74,22 +74,22 @@ local function generate_objectives(cfg)
|
||||
end
|
||||
end
|
||||
|
||||
if helper.check_equal( condition, "win" ) then
|
||||
if condition == "win" then
|
||||
local caption = obj.caption
|
||||
|
||||
if caption then
|
||||
win_objectives = tostring(win_objectives) .. tostring(caption) .. "\n"
|
||||
win_objectives = win_objectives .. caption .. "\n"
|
||||
end
|
||||
|
||||
win_objectives = tostring(win_objectives) .. tostring(color_prefix(0, 255, 0)) .. tostring(bullet) .. tostring(description) .. tostring(turn_counter) .. "</span>" .. "\n"
|
||||
elseif helper.check_equal( condition, "lose" ) then
|
||||
win_objectives = win_objectives .. color_prefix(0, 255, 0) .. bullet .. description .. turn_counter .. "</span>" .. "\n"
|
||||
elseif condition == "lose" then
|
||||
local caption = obj.caption
|
||||
|
||||
if caption then
|
||||
lose_objectives = tostring(lose_objectives) .. tostring(caption) .. "\n"
|
||||
lose_objectives = lose_objectives .. caption .. "\n"
|
||||
end
|
||||
|
||||
lose_objectives = tostring(lose_objectives) .. tostring(color_prefix(255, 0, 0)) .. tostring(bullet) .. tostring(description) .. tostring(turn_counter) .. "</span>" .. "\n"
|
||||
lose_objectives = lose_objectives .. color_prefix(255, 0, 0) .. bullet .. description .. turn_counter .. "</span>" .. "\n"
|
||||
else
|
||||
wesnoth.message "Unknown condition, ignoring."
|
||||
end
|
||||
@ -99,28 +99,28 @@ local function generate_objectives(cfg)
|
||||
for obj in helper.child_range(cfg, "gold_carryover") do
|
||||
if obj.bonus ~= nil then
|
||||
if obj.bonus then
|
||||
gold_carryover = tostring(color_prefix(255, 255, 192)) .. tostring(bullet) .. "<small>" .. _"Early finish bonus." .. "</small></span>\n"
|
||||
gold_carryover = color_prefix(255, 255, 192) .. bullet .. "<small>" .. _"Early finish bonus." .. "</small></span>\n"
|
||||
else
|
||||
gold_carryover = tostring(color_prefix(255, 255, 192)) .. tostring(bullet) .. "<small>" .. _"No early finish bonus." .. "</small></span>\n"
|
||||
gold_carryover = color_prefix(255, 255, 192) .. bullet .. "<small>" .. _"No early finish bonus." .. "</small></span>\n"
|
||||
end
|
||||
end
|
||||
|
||||
if obj.carryover_percentage then
|
||||
local carryover_amount_string = ""
|
||||
|
||||
if tonumber(tostring(obj.carryover_percentage or 0)) == 0 then
|
||||
if obj.carryover_percentage == 0 then
|
||||
carryover_amount_string = _"No gold carried over to the next scenario."
|
||||
else
|
||||
carryover_amount_string = string.format(tostring(_ "%d%% of gold carried over to the next scenario."), tostring(obj.carryover_percentage))
|
||||
carryover_amount_string = string.format(tostring(_ "%d%% of gold carried over to the next scenario."), obj.carryover_percentage)
|
||||
end
|
||||
|
||||
gold_carryover = tostring(gold_carryover) .. tostring(color_prefix(255, 255, 192)) .. tostring(bullet) .. "<small>" .. tostring(carryover_amount_string) .. "</small></span>\n"
|
||||
gold_carryover = gold_carryover .. color_prefix(255, 255, 192) .. bullet .. "<small>" .. carryover_amount_string .. "</small></span>\n"
|
||||
end
|
||||
end
|
||||
|
||||
for note in helper.child_range(cfg, "note") do
|
||||
if note.description then
|
||||
notes = tostring(notes) .. tostring(color_prefix(255, 255, 255)) .. tostring(bullet) .. "<small>" .. tostring(note.description) .. "</small></span>\n"
|
||||
notes = notes .. color_prefix(255, 255, 255) .. bullet .. "<small>" .. note.description .. "</small></span>\n"
|
||||
end
|
||||
end
|
||||
|
||||
@ -128,21 +128,21 @@ local function generate_objectives(cfg)
|
||||
if summary then
|
||||
objectives = "<big>" .. insert_before_nl(summary, "</big>") .. "\n"
|
||||
end
|
||||
if helper.check_not_equal( win_objectives, "" ) then
|
||||
objectives = tostring(objectives) .. "<big>" .. tostring(win_string) .. "</big>\n" .. tostring(win_objectives)
|
||||
if win_objectives ~= "" then
|
||||
objectives = objectives .. "<big>" .. win_string .. "</big>\n" .. win_objectives
|
||||
end
|
||||
if helper.check_not_equal( lose_objectives, "" ) then
|
||||
objectives = tostring(objectives) .. "<big>" .. tostring(lose_string) .. "</big>\n" .. tostring(lose_objectives)
|
||||
if lose_objectives ~= "" then
|
||||
objectives = objectives .. "<big>" .. lose_string .. "</big>\n" .. lose_objectives
|
||||
end
|
||||
if helper.check_not_equal( gold_carryover, "" ) then
|
||||
objectives = tostring(objectives) .. tostring(gold_carryover_string) .. "\n" .. tostring(gold_carryover)
|
||||
if gold_carryover ~= "" then
|
||||
objectives = objectives .. gold_carryover_string .. "\n" .. gold_carryover
|
||||
end
|
||||
if helper.check_not_equal( notes, "" ) then
|
||||
objectives = tostring(objectives) .. tostring(notes_string) .. "\n" .. tostring(notes)
|
||||
if notes ~= "" then
|
||||
objectives = objectives .. notes_string .. "\n" .. notes
|
||||
end
|
||||
local note = cfg.note
|
||||
if note then
|
||||
objectives = tostring(objectives) .. tostring(note) .. "\n"
|
||||
objectives = objectives .. note .. "\n"
|
||||
end
|
||||
|
||||
return string.sub(tostring(objectives), 1, -2)
|
||||
@ -150,8 +150,8 @@ end
|
||||
|
||||
function wml_actions.objectives(cfg)
|
||||
cfg = helper.parsed(cfg)
|
||||
local side = tonumber(tostring(cfg.side or 0)) or 0
|
||||
local silent = tostring(cfg.silent)
|
||||
local side = cfg.side or 0
|
||||
local silent = cfg.silent
|
||||
|
||||
-- Save the objectives in a WML variable in case they have to be regenerated later.
|
||||
cfg.side = nil
|
||||
@ -173,7 +173,7 @@ function wml_actions.objectives(cfg)
|
||||
end
|
||||
|
||||
function wml_actions.show_objectives(cfg)
|
||||
local side = tonumber(tostring(cfg.side or 0)) or 0
|
||||
local side = cfg.side or 0
|
||||
local cfg0 = scenario_objectives[0]
|
||||
if side == 0 then
|
||||
local objectives0 = cfg0 and generate_objectives(cfg0)
|
||||
|
@ -90,7 +90,7 @@ void lua_ai_context::set_persistent_data(const config &cfg)
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
lua_rawgeti(L, -1, num_);
|
||||
|
||||
luaW_pushconfig(L, cfg, false);
|
||||
luaW_pushconfig(L, cfg);
|
||||
lua_setfield(L, -2, "data");
|
||||
|
||||
lua_settop(L, top);
|
||||
@ -388,7 +388,7 @@ static int cfun_ai_get_leader_aggression(lua_State *L)
|
||||
static int cfun_ai_get_leader_goal(lua_State *L)
|
||||
{
|
||||
config goal = get_readonly_context(L).get_leader_goal();
|
||||
luaW_pushconfig(L, goal, false);
|
||||
luaW_pushconfig(L, goal);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -696,7 +696,7 @@ void lua_ai_action_handler::handle(config &cfg, bool configOut, lua_object_ptr l
|
||||
|
||||
if (!configOut)
|
||||
{
|
||||
luaW_pushconfig(L, cfg, false);
|
||||
luaW_pushconfig(L, cfg);
|
||||
luaW_pcall(L, 2, 0, true);
|
||||
}
|
||||
else if (luaW_pcall(L, 1, 5, true)) // @note for Crab: how much nrets should we actually have here
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -40,8 +40,8 @@ public:
|
||||
void save_game(config &);
|
||||
void load_game();
|
||||
bool run_event(game_events::queued_event const &);
|
||||
void set_wml_action(config::t_token const &, game_events::action_handler);
|
||||
bool run_wml_action(config::t_token const &, vconfig const &,
|
||||
void set_wml_action(std::string const &, game_events::action_handler);
|
||||
bool run_wml_action(std::string const &, vconfig const &,
|
||||
game_events::queued_event const &);
|
||||
bool run_filter(char const *name, unit const &u);
|
||||
/** Runs a plain script. */
|
||||
|
@ -25,8 +25,8 @@ class unit;
|
||||
|
||||
bool luaW_pcall(lua_State *L , int nArgs, int nRets, bool allow_wml_error = false);
|
||||
unit *luaW_tounit(lua_State *L, int index, bool only_on_map = false);
|
||||
void luaW_pushconfig(lua_State *L, config const &cfg, bool return_tokens);
|
||||
bool luaW_toconfig(lua_State *L, int index, config &cfg, int tstring_meta = 0, int t_token_meta = 0);
|
||||
void luaW_pushconfig(lua_State *L, config const &cfg);
|
||||
bool luaW_toconfig(lua_State *L, int index, config &cfg, int tstring_meta = 0);
|
||||
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg);
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user