Lua code: replace deprecated wesnoth.set_variable() calls
This commit is contained in:
parent
0f157bff27
commit
ce7faae4f4
26 changed files with 130 additions and 132 deletions
|
@ -286,7 +286,7 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
|
|||
if getmetatable(v) == "WML variable proxy" then
|
||||
v = wml.variables[v.__varname]
|
||||
end
|
||||
wesnoth.set_variable(k, v)
|
||||
wml.variables[k] = v
|
||||
end
|
||||
|
||||
function variable_mt.__index(t, k)
|
||||
|
|
|
@ -47,14 +47,14 @@ function helper.modify_unit(filter, vars)
|
|||
for i = 0, wml.variables["LUA_modify_unit.length"] - 1 do
|
||||
local u = string.format("LUA_modify_unit[%d]", i)
|
||||
for k, v in pairs(vars) do
|
||||
wesnoth.set_variable(u .. '.' .. k, v)
|
||||
wml.variables[u .. '.' .. k] = v
|
||||
end
|
||||
wml_actions.unstore_unit({
|
||||
variable = u,
|
||||
find_vacant = false
|
||||
})
|
||||
end
|
||||
wesnoth.set_variable("LUA_modify_unit")
|
||||
wml.variables["LUA_modify_unit"] = nil
|
||||
end
|
||||
|
||||
--! Fakes the move of a unit satisfying the given @a filter to position @a x, @a y.
|
||||
|
@ -71,12 +71,12 @@ function helper.move_unit_fake(filter, to_x, to_y)
|
|||
wml_actions.scroll_to({ x=from_x, y=from_y })
|
||||
|
||||
if to_x < from_x then
|
||||
wesnoth.set_variable("LUA_move_unit.facing", "sw")
|
||||
wml.variables["LUA_move_unit.facing"] = "sw"
|
||||
elseif to_x > from_x then
|
||||
wesnoth.set_variable("LUA_move_unit.facing", "se")
|
||||
wml.variables["LUA_move_unit.facing"] = "se"
|
||||
end
|
||||
wesnoth.set_variable("LUA_move_unit.x", to_x)
|
||||
wesnoth.set_variable("LUA_move_unit.y", to_y)
|
||||
wml.variables["LUA_move_unit.x"] = to_x
|
||||
wml.variables["LUA_move_unit.y"] = to_y
|
||||
|
||||
wml_actions.kill({
|
||||
x = from_x,
|
||||
|
@ -96,7 +96,7 @@ function helper.move_unit_fake(filter, to_x, to_y)
|
|||
|
||||
wml_actions.unstore_unit({ variable="LUA_move_unit", find_vacant=true })
|
||||
wml_actions.redraw({})
|
||||
wesnoth.set_variable("LUA_move_unit")
|
||||
wml.variables["LUA_move_unit"] = nil
|
||||
end
|
||||
|
||||
-- Metatable that redirects access to wml.variables_proxy
|
||||
|
|
|
@ -175,13 +175,13 @@ end
|
|||
|
||||
function methods:to_wml_var(name)
|
||||
local i = 0
|
||||
wesnoth.set_variable(name)
|
||||
wml.variables[name] = nil
|
||||
self:stable_iter(function(x, y, v)
|
||||
if type(v) == 'table' then
|
||||
wesnoth.set_variable(string.format("%s[%d]", name, i), v)
|
||||
wml.variables[string.format("%s[%d]", name, i)] = v
|
||||
end
|
||||
wesnoth.set_variable(string.format("%s[%d].x", name, i), x)
|
||||
wesnoth.set_variable(string.format("%s[%d].y", name, i), y)
|
||||
wml.variables[string.format("%s[%d].x", name, i)] = x
|
||||
wml.variables[string.format("%s[%d].y", name, i)] = y
|
||||
i = i + 1
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -113,7 +113,7 @@ wesnoth.wml_actions["for"] = function(cfg)
|
|||
end
|
||||
local i_var = cfg.variable or "i"
|
||||
local save_i = utils.start_var_scope(i_var)
|
||||
wesnoth.set_variable(i_var, first)
|
||||
wml.variables[i_var] = first
|
||||
local function loop_condition()
|
||||
local sentinel = loop_lim.last
|
||||
if loop_lim.step then
|
||||
|
@ -144,7 +144,7 @@ wesnoth.wml_actions["for"] = function(cfg)
|
|||
goto exit
|
||||
end
|
||||
end
|
||||
wesnoth.set_variable(i_var, wml.variables[i_var] + loop_lim.step)
|
||||
wml.variables[i_var] = wml.variables[i_var] + loop_lim.step
|
||||
end
|
||||
::exit::
|
||||
utils.end_var_scope(i_var, save_i)
|
||||
|
@ -192,9 +192,9 @@ function wml_actions.foreach(cfg)
|
|||
if array_length ~= wml.variables[array_name .. ".length"] then
|
||||
helper.wml_error("WML array length changed during [foreach] iteration")
|
||||
end
|
||||
wesnoth.set_variable(item_name, value)
|
||||
wml.variables[item_name] = value
|
||||
-- set index variable
|
||||
wesnoth.set_variable(i_name, index-1) -- here -1, because of WML array
|
||||
wml.variables[i_name] = index-1 -- here -1, because of WML array
|
||||
-- perform actions
|
||||
for do_child in wml.child_range(cfg, "do") do
|
||||
local action = utils.handle_event_commands(do_child, "loop")
|
||||
|
|
|
@ -46,13 +46,13 @@ function wml_actions.sync_variable(cfg)
|
|||
local name = variable.name
|
||||
|
||||
if variable.type == "indexed" then
|
||||
wesnoth.set_variable(name, variable[1][2])
|
||||
wml.variables[name] = variable[1][2]
|
||||
elseif variable.type == "array" then
|
||||
for index, cfg_pair in ipairs(variable) do
|
||||
wesnoth.set_variable( string.format("%s[%d]", name, index - 1), cfg_pair[2])
|
||||
wml.variables[string.format("%s[%d]", name, index - 1)] = cfg_pair[2]
|
||||
end
|
||||
else
|
||||
wesnoth.set_variable(name, variable.value)
|
||||
wml.variables[name] = variable.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -102,14 +102,14 @@ end
|
|||
--since the gold is stored in a scalar variable, not a container (there's no key).
|
||||
function wml_actions.store_gold(cfg)
|
||||
local team = wesnoth.get_sides(cfg)[1]
|
||||
if team then wesnoth.set_variable(cfg.variable or "gold", team.gold) end
|
||||
if team then wml.variables[cfg.variable or "gold"] = team.gold end
|
||||
end
|
||||
|
||||
function wml_actions.clear_variable(cfg)
|
||||
local names = cfg.name or
|
||||
helper.wml_error "[clear_variable] missing required name= attribute."
|
||||
for w in utils.split(names) do
|
||||
wesnoth.set_variable(utils.trim(w))
|
||||
wml.variables[utils.trim(w)] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,7 +120,7 @@ function wml_actions.store_unit_type_ids(cfg)
|
|||
end
|
||||
table.sort(types)
|
||||
types = table.concat(types, ',')
|
||||
wesnoth.set_variable(cfg.variable or "unit_type_ids", types)
|
||||
wml.variables[cfg.variable or "unit_type_ids"] = types
|
||||
end
|
||||
|
||||
function wml_actions.store_unit_type(cfg)
|
||||
|
@ -241,9 +241,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(var .. ".width", w)
|
||||
wesnoth.set_variable(var .. ".height", h)
|
||||
wesnoth.set_variable(var .. ".border_size", b)
|
||||
wml.variables[var .. ".width"] = w
|
||||
wml.variables[var .. ".height"] = h
|
||||
wml.variables[var .. ".border_size"] = b
|
||||
end
|
||||
|
||||
function wml_actions.unit_worth(cfg)
|
||||
|
@ -257,12 +257,12 @@ function wml_actions.unit_worth(cfg)
|
|||
local uta = wesnoth.unit_types[w]
|
||||
if uta and uta.cost > best_adv then best_adv = uta.cost end
|
||||
end
|
||||
wesnoth.set_variable("cost", ut.cost)
|
||||
wesnoth.set_variable("next_cost", best_adv)
|
||||
wesnoth.set_variable("health", math.floor(hp * 100))
|
||||
wesnoth.set_variable("experience", math.floor(xp * 100))
|
||||
wesnoth.set_variable("recall_cost", ut.recall_cost)
|
||||
wesnoth.set_variable("unit_worth", math.floor(math.max(ut.cost * hp, best_adv * xp)))
|
||||
wml.variables["cost"] = ut.cost
|
||||
wml.variables["next_cost"] = best_adv
|
||||
wml.variables["health"] = math.floor(hp * 100)
|
||||
wml.variables["experience"] = math.floor(xp * 100)
|
||||
wml.variables["recall_cost"] = ut.recall_cost
|
||||
wml.variables["unit_worth"] = math.floor(math.max(ut.cost * hp, best_adv * xp))
|
||||
end
|
||||
|
||||
function wml_actions.lua(cfg)
|
||||
|
@ -373,7 +373,7 @@ end
|
|||
|
||||
function wml_actions.store_turns(cfg)
|
||||
local var = cfg.variable or "turns"
|
||||
wesnoth.set_variable(var, wesnoth.game_config.last_turn)
|
||||
wml.variables[var] = wesnoth.game_config.last_turn
|
||||
end
|
||||
|
||||
function wml_actions.store_unit(cfg)
|
||||
|
@ -948,5 +948,5 @@ function wesnoth.wml_actions.store_unit_defense(cfg)
|
|||
else
|
||||
defense = wesnoth.unit_defense(unit, wesnoth.get_terrain(unit.x, unit.y))
|
||||
end
|
||||
wesnoth.set_variable(cfg.variable or "terrain_defense", defense)
|
||||
wml.variables[cfg.variable or "terrain_defense"] = defense
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ function utils.vwriter.init(cfg, default_variable)
|
|||
elseif mode == "append" then
|
||||
index = wml.variables[variable .. ".length"]
|
||||
elseif mode ~= "replace" then
|
||||
wesnoth.set_variable(variable)
|
||||
wml.variables[variable] = nil
|
||||
end
|
||||
return {
|
||||
variable = variable,
|
||||
|
@ -43,9 +43,9 @@ end
|
|||
|
||||
function utils.vwriter.write(self, container)
|
||||
if self.is_explicit_index then
|
||||
wesnoth.set_variable(self.variable, container)
|
||||
wml.variables[self.variable] = container
|
||||
else
|
||||
wesnoth.set_variable(string.format("%s[%u]", self.variable, self.index), container)
|
||||
wml.variables[string.format("%s[%u]", self.variable, self.index)] = container
|
||||
end
|
||||
self.index = self.index + 1
|
||||
end
|
||||
|
@ -194,16 +194,16 @@ end
|
|||
function utils.start_var_scope(name)
|
||||
local var = wml.array_access.get(name) --containers and arrays
|
||||
if #var == 0 then var = wml.variables[name] end --scalars (and nil/empty)
|
||||
wesnoth.set_variable(name)
|
||||
wml.variables[name] = nil
|
||||
return var
|
||||
end
|
||||
|
||||
function utils.end_var_scope(name, var)
|
||||
wesnoth.set_variable(name)
|
||||
wml.variables[name] = nil
|
||||
if type(var) == "table" then
|
||||
wml.array_access.set(name, var)
|
||||
else
|
||||
wesnoth.set_variable(name, var)
|
||||
wml.variables[name] = var
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ function wesnoth.wml_actions.find_path(cfg)
|
|||
-- support for $this_unit
|
||||
local this_unit = utils.start_var_scope("this_unit")
|
||||
|
||||
wesnoth.set_variable ( "this_unit" ) -- clearing this_unit
|
||||
wesnoth.set_variable("this_unit", unit.__cfg) -- cfg field needed
|
||||
wml.variables["this_unit"] = nil -- clearing this_unit
|
||||
wml.variables["this_unit"] = unit.__cfg -- cfg field needed
|
||||
|
||||
local variable = cfg.variable or "path"
|
||||
local ignore_units = false
|
||||
|
@ -78,28 +78,27 @@ function wesnoth.wml_actions.find_path(cfg)
|
|||
end
|
||||
|
||||
if cost >= 42424242 then -- it's the high value returned for unwalkable or busy terrains
|
||||
wesnoth.set_variable ( tostring(variable), { hexes = 0 } ) -- set only length, nil all other values
|
||||
wml.variables[tostring(variable)] = { hexes = 0 } -- set only length, nil all other values
|
||||
-- support for $this_unit
|
||||
wesnoth.set_variable ( "this_unit" ) -- clearing this_unit
|
||||
wml.variables["this_unit"] = nil -- clearing this_unit
|
||||
utils.end_var_scope("this_unit", this_unit)
|
||||
return end
|
||||
|
||||
if not allow_multiple_turns and turns > 1 then -- location cannot be reached in one turn
|
||||
wesnoth.set_variable ( tostring(variable), { hexes = 0 } )
|
||||
wml.variables[tostring(variable)] = { hexes = 0 }
|
||||
-- support for $this_unit
|
||||
wesnoth.set_variable ( "this_unit" ) -- clearing this_unit
|
||||
wml.variables["this_unit"] = nil -- clearing this_unit
|
||||
utils.end_var_scope("this_unit", this_unit)
|
||||
return end -- skip the cycles below
|
||||
|
||||
wesnoth.set_variable (
|
||||
tostring( variable ),
|
||||
wml.variables[tostring( variable )] =
|
||||
{
|
||||
hexes = current_distance,
|
||||
from_x = unit.x, from_y = unit.y,
|
||||
to_x = current_location[1], to_y = current_location[2],
|
||||
movement_cost = cost,
|
||||
required_turns = turns
|
||||
} )
|
||||
}
|
||||
|
||||
for index, path_loc in ipairs(path) do
|
||||
local sub_path, sub_cost = wesnoth.find_path(
|
||||
|
@ -120,18 +119,17 @@ function wesnoth.wml_actions.find_path(cfg)
|
|||
sub_turns = math.ceil( ( ( sub_cost - unit.moves ) / unit.max_moves ) + 1 )
|
||||
end
|
||||
|
||||
wesnoth.set_variable (
|
||||
string.format( "%s.step[%d]", variable, index - 1 ),
|
||||
wml.variables[string.format( "%s.step[%d]", variable, index - 1 )] =
|
||||
{ -- this structure takes less space in the inspection window
|
||||
x = path_loc[1], y = path_loc[2],
|
||||
terrain = wesnoth.get_terrain( path_loc[1], path_loc[2] ),
|
||||
movement_cost = sub_cost,
|
||||
required_turns = sub_turns
|
||||
} )
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
-- support for $this_unit
|
||||
wesnoth.set_variable ( "this_unit" ) -- clearing this_unit
|
||||
wml.variables["this_unit"] = nil -- clearing this_unit
|
||||
utils.end_var_scope("this_unit", this_unit)
|
||||
end
|
||||
|
|
|
@ -24,8 +24,8 @@ function wml_actions.harm_unit(cfg)
|
|||
for index, unit_to_harm in ipairs(wesnoth.get_units(filter)) do
|
||||
if unit_to_harm.valid then
|
||||
-- block to support $this_unit
|
||||
wesnoth.set_variable ( "this_unit" ) -- clearing this_unit
|
||||
wesnoth.set_variable("this_unit", unit_to_harm.__cfg) -- cfg field needed
|
||||
wml.variables["this_unit"] = nil -- clearing this_unit
|
||||
wml.variables["this_unit"] = unit_to_harm.__cfg -- cfg field needed
|
||||
local amount = tonumber(cfg.amount)
|
||||
local animate = cfg.animate -- attacker and defender are special values
|
||||
local delay = cfg.delay or 500
|
||||
|
@ -187,7 +187,7 @@ function wml_actions.harm_unit(cfg)
|
|||
end
|
||||
|
||||
if variable then
|
||||
wesnoth.set_variable(string.format("%s[%d]", variable, index - 1), { harm_amount = damage })
|
||||
wml.variables[string.format("%s[%d]", variable, index - 1)] = { harm_amount = damage }
|
||||
end
|
||||
|
||||
-- both units may no longer be alive at this point, so double check
|
||||
|
@ -203,6 +203,6 @@ function wml_actions.harm_unit(cfg)
|
|||
wml_actions.redraw {}
|
||||
end
|
||||
|
||||
wesnoth.set_variable ( "this_unit" ) -- clearing this_unit
|
||||
wml.variables["this_unit"] = nil -- clearing this_unit
|
||||
utils.end_var_scope("this_unit", this_unit)
|
||||
end
|
|
@ -67,7 +67,7 @@ function wesnoth.wml_actions.heal_unit(cfg)
|
|||
|
||||
if not heal_amount_set then
|
||||
heal_amount_set = true
|
||||
wesnoth.set_variable("heal_amount", heal_amount)
|
||||
wml.variables["heal_amount"] = heal_amount
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,7 +75,7 @@ function wml_actions.item(cfg)
|
|||
local redraw = cfg.redraw
|
||||
if redraw == nil then redraw = true end
|
||||
if redraw then wml_actions.redraw {} end
|
||||
if cfg.write_name then wesnoth.set_variable(cfg.write_name, cfg.name) end
|
||||
if cfg.write_name then wml.variables[cfg.write_name] = cfg.name end
|
||||
return cfg.name
|
||||
end
|
||||
|
||||
|
@ -89,13 +89,13 @@ end
|
|||
function wml_actions.store_items(cfg)
|
||||
local variable = cfg.variable or "items"
|
||||
variable = tostring(variable or helper.wml_error("invalid variable= in [store_items]"))
|
||||
wesnoth.set_variable(variable)
|
||||
wml.variables[variable] = nil
|
||||
local index = 0
|
||||
for i, loc in ipairs(wesnoth.get_locations(cfg)) do
|
||||
local items = scenario_items[loc[1] * 10000 + loc[2]]
|
||||
if items then
|
||||
for j, item in ipairs(items) do
|
||||
wesnoth.set_variable(string.format("%s[%u]", variable, index), item)
|
||||
wml.variables[string.format("%s[%u]", variable, index)] = item
|
||||
index = index + 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -441,7 +441,7 @@ function wesnoth.wml_actions.message(cfg)
|
|||
|
||||
if text_input ~= nil then
|
||||
-- Implement the consequences of the choice
|
||||
wesnoth.set_variable(text_input.variable or "input", choice.text)
|
||||
wml.variables[text_input.variable or "input"] = choice.text
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -459,9 +459,9 @@ function wesnoth.wml_actions.message(cfg)
|
|||
|
||||
if cfg.variable ~= nil then
|
||||
if options[option_chosen].value == nil then
|
||||
wesnoth.set_variable(cfg.variable, option_chosen)
|
||||
wml.variables[cfg.variable] = option_chosen
|
||||
else
|
||||
wesnoth.set_variable(cfg.variable, options[option_chosen].value)
|
||||
wml.variables[cfg.variable] = options[option_chosen].value
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ function wml_actions.modify_unit(cfg)
|
|||
local function handle_attributes(cfg, unit_path, toplevel)
|
||||
for current_key, current_value in pairs(wml.shallow_parsed(cfg)) do
|
||||
if type(current_value) ~= "table" and (not toplevel or (current_key ~= "type" and current_key ~= "mode")) then
|
||||
wesnoth.set_variable(string.format("%s.%s", unit_path, current_key), current_value)
|
||||
wml.variables[string.format("%s.%s", unit_path, current_key)] = current_value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ function wml_actions.modify_unit(cfg)
|
|||
local children_handled = {}
|
||||
local unit_path = string.format("%s[%u]", unit_variable, unit_num)
|
||||
local this_unit = wml.variables[unit_path]
|
||||
wesnoth.set_variable("this_unit", this_unit)
|
||||
wml.variables["this_unit"] = this_unit
|
||||
handle_attributes(cfg, unit_path, true)
|
||||
|
||||
for current_index, current_table in ipairs(wml.shallow_parsed(cfg)) do
|
||||
|
@ -52,7 +52,7 @@ function wml_actions.modify_unit(cfg)
|
|||
unit = wesnoth.create_unit(unit)
|
||||
wesnoth.add_modification(unit, current_tag, mod)
|
||||
unit = unit.__cfg;
|
||||
wesnoth.set_variable(unit_path, unit)
|
||||
wml.variables[unit_path] = unit
|
||||
elseif current_tag == "effect" then
|
||||
local mod = current_table[2]
|
||||
local apply_to = mod.apply_to
|
||||
|
@ -61,13 +61,13 @@ function wml_actions.modify_unit(cfg)
|
|||
unit = wesnoth.create_unit(unit)
|
||||
wesnoth.effects[apply_to](unit, mod)
|
||||
unit = unit.__cfg;
|
||||
wesnoth.set_variable(unit_path, unit)
|
||||
wml.variables[unit_path] = unit
|
||||
else
|
||||
helper.wml_error("[modify_unit] had invalid [effect]apply_to value")
|
||||
end
|
||||
else
|
||||
if replace_mode then
|
||||
wesnoth.set_variable(string.format("%s.%s", unit_path, current_tag), {})
|
||||
wml.variables[string.format("%s.%s", unit_path, current_tag)] = {}
|
||||
end
|
||||
local tag_index = children_handled[current_tag] or 0
|
||||
handle_child(current_table[2], string.format("%s.%s[%u]",
|
||||
|
@ -77,8 +77,8 @@ function wml_actions.modify_unit(cfg)
|
|||
end
|
||||
|
||||
if cfg.type then
|
||||
if cfg.type ~= "" then wesnoth.set_variable(unit_path .. ".advances_to", cfg.type) end
|
||||
wesnoth.set_variable(unit_path .. ".experience", wml.variables[unit_path .. ".max_experience"])
|
||||
if cfg.type ~= "" then wml.variables[unit_path .. ".advances_to"] = cfg.type end
|
||||
wml.variables[unit_path .. ".experience"] = wml.variables[unit_path .. ".max_experience"]
|
||||
end
|
||||
wml_actions.kill({ id = this_unit.id, animate = false })
|
||||
wml_actions.unstore_unit { variable = unit_path }
|
||||
|
@ -93,5 +93,5 @@ function wml_actions.modify_unit(cfg)
|
|||
end
|
||||
utils.end_var_scope("this_unit", this_unit)
|
||||
|
||||
wesnoth.set_variable(unit_variable)
|
||||
wml.variables[unit_variable] = nil
|
||||
end
|
|
@ -38,10 +38,10 @@ wesnoth.wml_actions.random_placement = function(cfg)
|
|||
end
|
||||
local index = wesnoth.random(size)
|
||||
local point = locs[index]
|
||||
wesnoth.set_variable(variable .. ".x", point[1])
|
||||
wesnoth.set_variable(variable .. ".y", point[2])
|
||||
wesnoth.set_variable(variable .. ".n", i)
|
||||
wesnoth.set_variable(variable .. ".terrain", wesnoth.get_terrain(point[1], point[2]))
|
||||
wml.variables[variable .. ".x"] = point[1]
|
||||
wml.variables[variable .. ".y"] = point[2]
|
||||
wml.variables[variable .. ".n"] = i
|
||||
wml.variables[variable .. ".terrain"] = wesnoth.get_terrain(point[1], point[2])
|
||||
if distance < 0 then
|
||||
-- optimisation: nothing to do for distance < 0
|
||||
elseif distance == 0 then
|
||||
|
|
|
@ -4,51 +4,51 @@ function wesnoth.wml_actions.set_variable(cfg)
|
|||
local name = cfg.name or helper.wml_error "trying to set a variable with an empty name"
|
||||
|
||||
if cfg.value ~= nil then -- check for nil because user may try to set a variable as false
|
||||
wesnoth.set_variable(name, cfg.value)
|
||||
wml.variables[name] = cfg.value
|
||||
end
|
||||
|
||||
if cfg.literal ~= nil then
|
||||
wesnoth.set_variable(name, wml.shallow_literal(cfg).literal)
|
||||
wml.variables[name] = wml.shallow_literal(cfg).literal
|
||||
end
|
||||
|
||||
if cfg.to_variable then
|
||||
wesnoth.set_variable(name, wml.variables[cfg.to_variable])
|
||||
wml.variables[name] = wml.variables[cfg.to_variable]
|
||||
end
|
||||
|
||||
if cfg.suffix then
|
||||
wesnoth.set_variable(name, (wml.variables[name] or '') .. (cfg.suffix or ''))
|
||||
wml.variables[name] = (wml.variables[name] or '') .. (cfg.suffix or '')
|
||||
end
|
||||
|
||||
if cfg.prefix then
|
||||
wesnoth.set_variable(name, (cfg.prefix or '') .. (wml.variables[name] or ''))
|
||||
wml.variables[name] = (cfg.prefix or '') .. (wml.variables[name] or '')
|
||||
end
|
||||
|
||||
if cfg.add then
|
||||
wesnoth.set_variable(name, (tonumber(wml.variables[name]) or 0) + (tonumber(cfg.add) or 0))
|
||||
wml.variables[name] = (tonumber(wml.variables[name]) or 0) + (tonumber(cfg.add) or 0)
|
||||
end
|
||||
|
||||
if cfg.sub then
|
||||
wesnoth.set_variable(name, (tonumber(wml.variables[name]) or 0) - (tonumber(cfg.sub) or 0))
|
||||
wml.variables[name] = (tonumber(wml.variables[name]) or 0) - (tonumber(cfg.sub) or 0)
|
||||
end
|
||||
|
||||
if cfg.multiply then
|
||||
wesnoth.set_variable(name, (tonumber(wml.variables[name]) or 0) * (tonumber(cfg.multiply) or 0))
|
||||
wml.variables[name] = (tonumber(wml.variables[name]) or 0) * (tonumber(cfg.multiply) or 0)
|
||||
end
|
||||
|
||||
if cfg.divide then
|
||||
local divide = tonumber(cfg.divide) or 0
|
||||
if divide == 0 then helper.wml_error("division by zero on variable " .. name) end
|
||||
wesnoth.set_variable(name, (tonumber(wml.variables[name]) or 0) / divide)
|
||||
wml.variables[name] = (tonumber(wml.variables[name]) or 0) / divide
|
||||
end
|
||||
|
||||
if cfg.modulo then
|
||||
local modulo = tonumber(cfg.modulo) or 0
|
||||
if modulo == 0 then helper.wml_error("division by zero on variable " .. name) end
|
||||
wesnoth.set_variable(name, (tonumber(wml.variables[name]) or 0) % modulo)
|
||||
wml.variables[name] = (tonumber(wml.variables[name]) or 0) % modulo
|
||||
end
|
||||
|
||||
if cfg.abs then
|
||||
wesnoth.set_variable(name, math.abs(tonumber(wml.variables[name]) or 0))
|
||||
wml.variables[name] = math.abs(tonumber(wml.variables[name]) or 0)
|
||||
end
|
||||
|
||||
if cfg.root then
|
||||
|
@ -73,31 +73,31 @@ function wesnoth.wml_actions.set_variable(cfg)
|
|||
end
|
||||
end
|
||||
|
||||
wesnoth.set_variable(name, root_fcn(radicand))
|
||||
wml.variables[name] = root_fcn(radicand)
|
||||
end
|
||||
|
||||
if cfg.power then
|
||||
wesnoth.set_variable(name, (tonumber(wml.variables[name]) or 0) ^ (tonumber(cfg.power) or 0))
|
||||
wml.variables[name] = (tonumber(wml.variables[name]) or 0) ^ (tonumber(cfg.power) or 0)
|
||||
end
|
||||
|
||||
if cfg.round then
|
||||
local var = tonumber(wml.variables[name] or 0)
|
||||
local round_val = cfg.round
|
||||
if round_val == "ceil" then
|
||||
wesnoth.set_variable(name, math.ceil(var))
|
||||
wml.variables[name] = math.ceil(var)
|
||||
elseif round_val == "floor" then
|
||||
wesnoth.set_variable(name, math.floor(var))
|
||||
wml.variables[name] = math.floor(var)
|
||||
elseif round_val == "trunc" then
|
||||
-- Storing to a variable first because modf returns two values,
|
||||
-- and I'm not sure if set_variable will complain about the extra parameter
|
||||
local new_val = math.modf(var)
|
||||
wesnoth.set_variable(name, new_val)
|
||||
wml.variables[name] = new_val
|
||||
else
|
||||
local decimals = math.modf(tonumber(round_val) or 0)
|
||||
local value = var * (10 ^ decimals)
|
||||
value = helper.round(value)
|
||||
value = value * (10 ^ -decimals)
|
||||
wesnoth.set_variable(name, value)
|
||||
wml.variables[name] = value
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -106,31 +106,31 @@ function wesnoth.wml_actions.set_variable(cfg)
|
|||
-- but on the value assigned to the respective key
|
||||
if cfg.ipart then
|
||||
local ivalue = math.modf(tonumber(cfg.ipart) or 0)
|
||||
wesnoth.set_variable(name, ivalue)
|
||||
wml.variables[name] = ivalue
|
||||
end
|
||||
|
||||
if cfg.fpart then
|
||||
local ivalue, fvalue = math.modf(tonumber(cfg.fpart) or 0)
|
||||
wesnoth.set_variable(name, fvalue)
|
||||
wml.variables[name] = fvalue
|
||||
end
|
||||
|
||||
if cfg.string_length ~= nil then
|
||||
wesnoth.set_variable(name, string.len(tostring(cfg.string_length)))
|
||||
wml.variables[name] = string.len(tostring(cfg.string_length))
|
||||
end
|
||||
|
||||
if cfg.time then
|
||||
if cfg.time == "stamp" then
|
||||
wesnoth.set_variable(name, wesnoth.get_time_stamp())
|
||||
wml.variables[name] = wesnoth.get_time_stamp()
|
||||
end
|
||||
end
|
||||
|
||||
if cfg.rand then
|
||||
wesnoth.set_variable(name, helper.rand(tostring(cfg.rand)))
|
||||
wml.variables[name] = helper.rand(tostring(cfg.rand))
|
||||
end
|
||||
|
||||
if cfg.formula then
|
||||
local fcn = wesnoth.compile_formula(cfg.formula)
|
||||
wesnoth.set_variable(name, fcn(wml.variables[name]))
|
||||
wml.variables[name] = fcn(wml.variables[name])
|
||||
end
|
||||
|
||||
local join_child = wml.get_child(cfg, "join")
|
||||
|
@ -151,6 +151,6 @@ function wesnoth.wml_actions.set_variable(cfg)
|
|||
end
|
||||
end
|
||||
|
||||
wesnoth.set_variable(name, string_to_join)
|
||||
wml.variables[name] = string_to_join
|
||||
end
|
||||
end
|
||||
|
|
|
@ -191,22 +191,22 @@ local function create_timed_spaws(interval, num_spawns, base_gold_amount, gold_i
|
|||
break
|
||||
end
|
||||
end
|
||||
wesnoth.set_variable(string.format("timed_spawn[%d]", spawn_number - 1), {
|
||||
wml.variables[string.format("timed_spawn[%d]", spawn_number - 1)] = {
|
||||
units = math.ceil(units),
|
||||
turn = turn,
|
||||
gold = helper.round(gold * configure_gold_factor),
|
||||
pool_num = random_spawn_numbers[spawn_number],
|
||||
})
|
||||
}
|
||||
else
|
||||
wesnoth.set_variable(string.format("timed_spawn[%d]", spawn_number - 1), {
|
||||
wml.variables[string.format("timed_spawn[%d]", spawn_number - 1)] = {
|
||||
units = units_amount + 1,
|
||||
turn = turn,
|
||||
gold = gold,
|
||||
pool_num = random_spawn_numbers[spawn_number],
|
||||
})
|
||||
}
|
||||
end
|
||||
end
|
||||
wesnoth.set_variable("final_turn", final_turn)
|
||||
wml.variables["final_turn"] = final_turn
|
||||
end
|
||||
|
||||
-- @a unittypes: a array of strings
|
||||
|
@ -249,7 +249,7 @@ local function final_spawn()
|
|||
end
|
||||
local spawn_index = wesnoth.random(spawns_left) - 1
|
||||
local spawn = wml.variables[string.format("fixed_spawn[%d]", spawn_index)]
|
||||
wesnoth.set_variable(string.format("fixed_spawn[%d]", spawn_index))
|
||||
wml.variables[string.format("fixed_spawn[%d]", spawn_index)] = nil
|
||||
local types = {}
|
||||
for tag in helper.child_range(spawn, "type") do
|
||||
table.insert(types, tag.type)
|
||||
|
@ -282,7 +282,7 @@ on_event("new turn", function()
|
|||
if wesnoth.current.turn ~= next_spawn.turn then
|
||||
return
|
||||
end
|
||||
wesnoth.set_variable("timed_spawn[0]")
|
||||
wml.variables["timed_spawn[0]"] = nil
|
||||
local unit_types = get_spawn_types(next_spawn.units, next_spawn.gold, random_spawns[next_spawn.pool_num])
|
||||
local spawn_areas = {{"3-14", "15"}, {"1", "4-13"}, {"2-13", "1"}, {"1", "2-15"}}
|
||||
local spawn_area = spawn_areas[wesnoth.random(#spawn_areas)]
|
||||
|
@ -317,7 +317,7 @@ on_event("new turn", function()
|
|||
return
|
||||
end
|
||||
final_spawn()
|
||||
wesnoth.set_variable("next_final_spawn", wesnoth.current.turn + wesnoth.random(1,2))
|
||||
wml.variables["next_final_spawn"] = wesnoth.current.turn + wesnoth.random(1,2)
|
||||
end)
|
||||
|
||||
-- The victory condition: win when there are no enemy unit after the first final spawn appeared.
|
||||
|
@ -392,29 +392,29 @@ on_event("prestart", function()
|
|||
if weather_to_dispense[index].turns_left <= 0 then
|
||||
table.remove(weather_to_dispense, index)
|
||||
end
|
||||
wesnoth.set_variable(string.format("weather_event[%d]", event_num), {
|
||||
wml.variables[string.format("weather_event[%d]", event_num)] = {
|
||||
turn = turn,
|
||||
weather_id = weather_id,
|
||||
})
|
||||
}
|
||||
event_num = event_num + 1
|
||||
turn = turn + num_turns
|
||||
-- Second snow happens half the time.
|
||||
if weather_id == "snowfall" and heavy_snowfall_turns_left >= 0 and wesnoth.random(2) == 2 then
|
||||
num_turns = get_weather_duration(heavy_snowfall_turns_left)
|
||||
wesnoth.set_variable(string.format("weather_event[%d]", event_num), {
|
||||
wml.variables[string.format("weather_event[%d]", event_num)] = {
|
||||
turn = turn,
|
||||
weather_id = "heavy snowfall",
|
||||
})
|
||||
}
|
||||
event_num = event_num + 1
|
||||
turn = turn + num_turns
|
||||
heavy_snowfall_turns_left = heavy_snowfall_turns_left - num_turns
|
||||
end
|
||||
-- Go back to clear weather.
|
||||
num_turns = get_weather_duration(clear_turns_left)
|
||||
wesnoth.set_variable(string.format("weather_event[%d]", event_num), {
|
||||
wml.variables[string.format("weather_event[%d]", event_num)] = {
|
||||
turn = turn,
|
||||
weather_id = "clear",
|
||||
})
|
||||
}
|
||||
event_num = event_num + 1
|
||||
turn = turn + num_turns
|
||||
clear_turns_left = clear_turns_left - num_turns
|
||||
|
@ -453,7 +453,7 @@ on_event("side 3 turn", function()
|
|||
return
|
||||
end
|
||||
-- remove the to-be-consumed weather event from the todo list.
|
||||
wesnoth.set_variable("weather_event[0]")
|
||||
wml.variables["weather_event[0]"] = nil
|
||||
if weather_event.weather_id == "clear" then
|
||||
weather_map("multiplayer/maps/Dark_Forecast_basic.map")
|
||||
wesnoth.wml_actions.sound {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
for i, side in ipairs(wesnoth.get_sides({})) do
|
||||
wesnoth.set_variable("p" .. tostring(i) .. "_faction", side.faction)
|
||||
wml.variables["p" .. tostring(i) .. "_faction"] = side.faction
|
||||
end
|
||||
|
|
|
@ -1150,7 +1150,7 @@ end
|
|||
x = t.x, y = t.y })
|
||||
end
|
||||
function wml_actions.check_substitution(t)
|
||||
wesnoth.set_variable("substitution_variable", 1)
|
||||
wml.variables["substitution_variable"] = 1
|
||||
if t.value ~= "Number 2" then
|
||||
wesnoth.message("Substitution is not delayed! " .. tostring(t.value))
|
||||
end
|
||||
|
@ -3673,7 +3673,7 @@ unplagueable: $wml_unit.status.unplagueable"
|
|||
for i, v in ipairs(helper.get_variable_proxy_array "temp_villages_area") do
|
||||
wesnoth.put_unit({ type = "Goblin Spearman", side = 2 }, v.x, v.y)
|
||||
end
|
||||
wesnoth.set_variable "temp_villages_area"
|
||||
wml.variables["temp_villages_area"] = nil
|
||||
>>
|
||||
[/lua]
|
||||
[/event]
|
||||
|
|
|
@ -16,7 +16,7 @@ local H = wesnoth.require('helper')
|
|||
local expected = H.get_variable_array('expected')
|
||||
local aspect = wml.variables['test_attribute']
|
||||
if ai.aspects[aspect] ~= expected[wesnoth.current.turn].value then
|
||||
wesnoth.set_variable('is_valid', false)
|
||||
wml.variables['is_valid'] = false
|
||||
local msg = 'Failed on turn ' .. tostring(wesnoth.current.turn)
|
||||
msg = msg .. ' (time: ' .. wesnoth.get_time_of_day().id .. ')'
|
||||
msg = msg .. '; ' .. aspect
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
{TEST_BREAK_REPLAY "break_replay_with_lua_random" (
|
||||
[lua]
|
||||
code =<<
|
||||
wesnoth.set_variable("rnd_num", math.random(200))
|
||||
wml.variables["rnd_num"] = math.random(200)
|
||||
>>
|
||||
[/lua]
|
||||
)}
|
||||
|
@ -82,7 +82,7 @@
|
|||
function()
|
||||
return { value = math.random(200) }
|
||||
end)
|
||||
wesnoth.set_variable("rnd_num", result.value)
|
||||
wml.variables["rnd_num"] = result.value
|
||||
>>
|
||||
[/lua]
|
||||
)}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
function()
|
||||
return { value = temp.facing }
|
||||
end)
|
||||
wesnoth.set_variable("synced_temp", result.value)
|
||||
wml.variables["synced_temp"] = result.value
|
||||
>>
|
||||
[/lua]
|
||||
{ASSERT ({VARIABLE_CONDITIONAL unit.facing equals $synced_temp})}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
c = true
|
||||
end
|
||||
end
|
||||
wesnoth.set_variable("result", (not a) and b and (not c)) >>
|
||||
wml.variables["result"] = (not a) and b and (not c) >>
|
||||
[/lua]
|
||||
|
||||
{RETURN {VARIABLE_CONDITIONAL result boolean_equals true}}
|
||||
|
@ -49,7 +49,7 @@
|
|||
c = true
|
||||
end
|
||||
end
|
||||
wesnoth.set_variable("result", (not a) and b and (not c)) >>
|
||||
wml.variables["result"] = (not a) and b and (not c) >>
|
||||
[/lua]
|
||||
|
||||
{RETURN {VARIABLE_CONDITIONAL result boolean_equals true}}
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
name = prestart
|
||||
[lua]
|
||||
code = << a,b,c,d = wesnoth.dofile("test/macros/test.lua")
|
||||
wesnoth.set_variable("a", a)
|
||||
wesnoth.set_variable("b", b)
|
||||
wesnoth.set_variable("c", c)
|
||||
wesnoth.set_variable("d", d) >>
|
||||
wml.variables["a"] = a
|
||||
wml.variables["b"] = b
|
||||
wml.variables["c"] = c
|
||||
wml.variables["d"] = d >>
|
||||
[/lua]
|
||||
|
||||
{ASSERT ({VARIABLE_CONDITIONAL a equals 1})}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
[lua]
|
||||
code = << local s = wesnoth.get_sides({})
|
||||
local result = (s[1].side == 1) and (s[2].side == 2)
|
||||
wesnoth.set_variable("result", result) >>
|
||||
wml.variables["result"] = result >>
|
||||
[/lua]
|
||||
|
||||
{RETURN ({VARIABLE_CONDITIONAL result boolean_equals true})}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
code = <<
|
||||
function wesnoth.wml_actions.foo(cfg)
|
||||
if cfg.bar then
|
||||
wesnoth.set_variable("result", cfg.bar)
|
||||
wml.variables["result"] = cfg.bar
|
||||
end
|
||||
end
|
||||
>>
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
r = r and not wesnoth.fire_wml_menu_item("test2", 3, 3)
|
||||
r = r and wesnoth.fire_wml_menu_item("test2", 4, 4)
|
||||
r = r and not wesnoth.fire_wml_menu_item("test2", 4, 4)
|
||||
wesnoth.set_variable("result", r) >>
|
||||
wml.variables["result"] = r >>
|
||||
[/lua]
|
||||
|
||||
{RETURN {VARIABLE_CONDITIONAL result boolean_equals true}}
|
||||
|
@ -115,7 +115,7 @@
|
|||
)}
|
||||
|
||||
[lua]
|
||||
code = << wesnoth.set_variable("result", r) >>
|
||||
code = << wml.variables["result"] = r >>
|
||||
[/lua]
|
||||
{RETURN {VARIABLE_CONDITIONAL result boolean_equals true}}
|
||||
[/event]
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
code = << H = wesnoth.require("lua/helper.lua")
|
||||
A = wesnoth.require("ai/lua/extCAexample.lua")
|
||||
result = H and A and true
|
||||
wesnoth.set_variable("result", result and "true" or "false") >>
|
||||
wml.variables["result"] = result and "true" or "false" >>
|
||||
[/lua]
|
||||
|
||||
{RETURN ({VARIABLE_CONDITIONAL result boolean_equals true})}
|
||||
|
|
Loading…
Add table
Reference in a new issue