Replace all references to deprecated functions in the helper module

(and remove the require if this meant it was no longer used)
This commit is contained in:
Celtic Minstrel 2019-12-02 01:10:34 -05:00
parent 74e004c265
commit 732b7942bb
33 changed files with 119 additions and 142 deletions

View file

@ -656,7 +656,7 @@ function ai_helper.get_named_loc_xy(param_core, cfg, required_for)
if loc then
return loc
else
H.wml_error("Named location does not exist: " .. loc_id)
wml.error("Named location does not exist: " .. loc_id)
end
end
@ -666,14 +666,14 @@ function ai_helper.get_named_loc_xy(param_core, cfg, required_for)
if x and y then
local width, height = wesnoth.get_map_size()
if (x < 1) or (x > width) or (y < 1) or (y > height) then
H.wml_error("Location is not on map: " .. param_x .. ',' .. param_y .. ' = ' .. x .. ',' .. y)
wml.error("Location is not on map: " .. param_x .. ',' .. param_y .. ' = ' .. x .. ',' .. y)
end
return { x, y }
end
if required_for then
H.wml_error(required_for .. " requires either " .. param_loc .. "= or " .. param_x .. "/" .. param_y .. "= keys")
wml.error(required_for .. " requires either " .. param_loc .. "= or " .. param_x .. "/" .. param_y .. "= keys")
end
end
@ -705,7 +705,7 @@ function ai_helper.get_multi_named_locs_xy(param_core, cfg, required_for)
local xs = ai_helper.split(cfg_x, ",")
local ys = ai_helper.split(cfg_y, ",")
if (#xs ~= #ys) then
H.wml_error("Coordinate lists need to have same number of elements: " .. param_x .. ' and ' .. param_y)
wml.error("Coordinate lists need to have same number of elements: " .. param_x .. ' and ' .. param_y)
end
for i,x in ipairs(xs) do
@ -719,7 +719,7 @@ function ai_helper.get_multi_named_locs_xy(param_core, cfg, required_for)
end
if required_for then
H.wml_error(required_for .. " requires either " .. param_loc .. "= or " .. param_x .. "/" .. param_y .. "= keys")
wml.error(required_for .. " requires either " .. param_loc .. "= or " .. param_x .. "/" .. param_y .. "= keys")
end
return locs

View file

@ -101,9 +101,9 @@ function ca_goto:execution(cfg, data)
local enemy_map, enemy_attack_map
if cfg.avoid_enemies then
if (type(cfg.avoid_enemies) ~= 'number') then
H.wml_error("Goto AI avoid_enemies= requires a number as argument")
wml.error("Goto AI avoid_enemies= requires a number as argument")
elseif (cfg.avoid_enemies <= 0) then
H.wml_error("Goto AI avoid_enemies= argument must be >0")
wml.error("Goto AI avoid_enemies= argument must be >0")
end
local enemies = AH.get_visible_units(wesnoth.current.side, {

View file

@ -1,5 +1,4 @@
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local H = wesnoth.require "helper"
local MAIH = wesnoth.require("ai/micro_ais/micro_ai_helper.lua")
function wesnoth.micro_ais.big_animals(cfg)
@ -171,7 +170,7 @@ end
function wesnoth.micro_ais.hunter(cfg)
if (cfg.action ~= 'delete') then
if (not cfg.id) and (not wml.get_child(cfg, "filter")) then
H.wml_error("Hunter [micro_ai] tag requires either id= key or [filter] tag")
wml.error("Hunter [micro_ai] tag requires either id= key or [filter] tag")
end
AH.get_named_loc_xy('home', cfg, 'Hunter [micro_ai] tag')
end

View file

@ -1,10 +1,9 @@
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local H = wesnoth.require "helper"
function wesnoth.micro_ais.messenger_escort(cfg)
if (cfg.action ~= 'delete') then
if (not cfg.id) and (not wml.get_child(cfg, "filter")) then
H.wml_error("Messenger [micro_ai] tag requires either id= key or [filter] tag")
wml.error("Messenger [micro_ai] tag requires either id= key or [filter] tag")
end
AH.get_multi_named_locs_xy('waypoint', cfg, 'Messenger [micro_ai] tag')
end

View file

@ -1,10 +1,9 @@
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local H = wesnoth.require "helper"
function wesnoth.micro_ais.stationed_guardian(cfg)
if (cfg.action ~= 'delete') then
if (not cfg.id) and (not wml.get_child(cfg, "filter")) then
H.wml_error("Stationed Guardian [micro_ai] tag requires either id= key or [filter] tag")
wml.error("Stationed Guardian [micro_ai] tag requires either id= key or [filter] tag")
end
AH.get_named_loc_xy('station', cfg, 'Stationed guardian [micro_ai] tag')
end
@ -19,7 +18,7 @@ end
function wesnoth.micro_ais.zone_guardian(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not wml.get_child(cfg, "filter")) then
H.wml_error("Zone Guardian [micro_ai] tag requires either id= key or [filter] tag")
wml.error("Zone Guardian [micro_ai] tag requires either id= key or [filter] tag")
end
local required_keys = { "[filter_location]" }
local optional_keys = { "id", "[filter]", "[filter_location_enemy]", "station_loc", "station_x", "station_y" }
@ -33,7 +32,7 @@ end
function wesnoth.micro_ais.return_guardian(cfg)
if (cfg.action ~= 'delete') then
if (not cfg.id) and (not wml.get_child(cfg, "filter")) then
H.wml_error("Return Guardian [micro_ai] tag requires either id= key or [filter] tag")
wml.error("Return Guardian [micro_ai] tag requires either id= key or [filter] tag")
end
AH.get_named_loc_xy('return', cfg, 'Return guardian [micro_ai] tag')
end
@ -48,7 +47,7 @@ end
function wesnoth.micro_ais.coward(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not wml.get_child(cfg, "filter")) then
H.wml_error("Coward [micro_ai] tag requires either id= key or [filter] tag")
wml.error("Coward [micro_ai] tag requires either id= key or [filter] tag")
end
local required_keys = { "distance" }
local optional_keys = { "attack_if_trapped", "id", "[filter]", "[filter_second]", "seek_loc", "seek_x", "seek_y", "avoid_loc", "avoid_x", "avoid_y" }

View file

@ -1,10 +1,9 @@
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local H = wesnoth.require "helper"
function wesnoth.micro_ais.patrol(cfg)
if (cfg.action ~= 'delete') then
if (not cfg.id) and (not wml.get_child(cfg, "filter")) then
H.wml_error("Patrol [micro_ai] tag requires either id= key or [filter] tag")
wml.error("Patrol [micro_ai] tag requires either id= key or [filter] tag")
end
AH.get_multi_named_locs_xy('waypoint', cfg, 'Patrol [micro_ai] tag')
end

View file

@ -1,5 +1,4 @@
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local H = wesnoth.require "helper"
local MAIH = wesnoth.require("ai/micro_ais/micro_ai_helper.lua")
function wesnoth.micro_ais.protect_unit(cfg)
@ -14,7 +13,7 @@ function wesnoth.micro_ais.protect_unit(cfg)
local unit_ids = {}
for u in wml.child_range(cfg, "unit") do
if not u.id then
H.wml_error("Protect Unit Micro AI missing id key in [unit] tag")
wml.error("Protect Unit Micro AI missing id key in [unit] tag")
end
AH.get_multi_named_locs_xy('goal', u, 'Protect Unit Micro AI [unit] tag')
table.insert(unit_ids, u.id)

View file

@ -1,4 +1,3 @@
local H = wesnoth.require "helper"
local T = wml.tag
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
@ -169,14 +168,14 @@ function micro_ai_helper.micro_ai_setup(cfg, CA_parms, required_keys, optional_k
if v:match('%[[a-zA-Z0-9_]+%]') then
v = v:sub(2,-2)
if not wml.get_child(cfg, v) then
H.wml_error("[micro_ai] tag (" .. cfg.ai_type .. ") is missing required parameter: [" .. v .. "]")
wml.error("[micro_ai] tag (" .. cfg.ai_type .. ") is missing required parameter: [" .. v .. "]")
end
for child in wml.child_range(cfg, v) do
table.insert(CA_cfg, T[v](child))
end
else
if not cfg[v] then
H.wml_error("[micro_ai] tag (" .. cfg.ai_type .. ") is missing required parameter: " .. v .."=")
wml.error("[micro_ai] tag (" .. cfg.ai_type .. ") is missing required parameter: " .. v .."=")
end
CA_cfg[v] = cfg[v]
end

View file

@ -8,10 +8,10 @@ local T = wml.tag
local vars = wml.variables
function wml_actions.spread_bandit_villages(cfg)
local x = cfg.x or helper.wml_error("[spread_bandit_villages] missing required x= attribute.")
local y = cfg.y or helper.wml_error("[spread_bandit_villages] missing required y= attribute.")
local count = cfg.count or helper.wml_error("[spread_bandit_villages] missing required count= attribute.")
local types = cfg.types or helper.wml_error("[spread_bandit_villages] missing required types= attribute.")
local x = cfg.x or wml.error("[spread_bandit_villages] missing required x= attribute.")
local y = cfg.y or wml.error("[spread_bandit_villages] missing required y= attribute.")
local count = cfg.count or wml.error("[spread_bandit_villages] missing required count= attribute.")
local types = cfg.types or wml.error("[spread_bandit_villages] missing required types= attribute.")
vars.villages_visited = 0
vars.boss_found = false
@ -70,8 +70,8 @@ end
function wml_actions.bandit_village_capture(cfg)
local bandit_villages = wml.array_access.get_proxy("bandit_villages")
local x = cfg.x or helper.wml_error("[bandit_village_capture] missing required x= attribute.")
local y = cfg.y or helper.wml_error("[bandit_village_capture] missing required y= attribute.")
local x = cfg.x or wml.error("[bandit_village_capture] missing required x= attribute.")
local y = cfg.y or wml.error("[bandit_village_capture] missing required y= attribute.")
for i=1,#bandit_villages do
if bandit_villages[i].x == x and bandit_villages[i].y == y then

View file

@ -7,8 +7,6 @@ local wml_actions = wesnoth.wml_actions
local T = wml.tag
local vars = wml.variables
helper = wesnoth.require "lua/helper.lua"
function wesnoth.wml_actions.shift_labels(cfg)
for k, v in ipairs(labels) do
wml_label { x = v.x, y = v.y }
@ -60,7 +58,7 @@ end
function wesnoth.wml_actions.unstore_left_behind_units(cfg)
if wml.variables["l3_store_kalenz"] ~= nil then
l3_store_kalenz = helper.get_variable_array("l3_store_kalenz")
l3_store_kalenz = wml.array_variables["l3_store_kalenz"]
for i,_ in ipairs(l3_store_kalenz) do
var_name = "l3_store_kalenz[" .. tostring(i-1) .. "]"
wml_actions.unstore_unit {
@ -72,7 +70,7 @@ function wesnoth.wml_actions.unstore_left_behind_units(cfg)
wml.variables["l3_store_kalenz"] = nil
end
if wml.variables["l3_store_landar"] ~= nil then
l3_store_landar = helper.get_variable_array("l3_store_landar")
l3_store_landar = wml.array_variables["l3_store_landar"]
for i,_ in ipairs(l3_store_landar) do
var_name = "l3_store_landar[" .. tostring(i-1) .. "]"
wml_actions.unstore_unit {

View file

@ -1,9 +1,8 @@
local helper = wesnoth.require "helper"
local T = wml.tag
local vars = wml.variables
function wesnoth.wml_actions.find_respawn_point(cfg)
local respawn_near = cfg.respawn_near or helper.wml_error "[find_respawn_point] missing required respawn_near= key"
local respawn_near = cfg.respawn_near or wml.error "[find_respawn_point] missing required respawn_near= key"
local variable = cfg.variable or "nearest_hex"
local respawn_point
local radius = 1

View file

@ -493,8 +493,8 @@
[lua]
code = <<
H = wesnoth.require "helper"
T = H.set_wml_tag_metatable {}
V = H.set_wml_var_metatable {}
T = wml.tag
V = wml.variables
W = H.set_wml_action_metatable {}
_ = wesnoth.textdomain "wesnoth-sota"
>>

View file

@ -6,11 +6,11 @@ local wml_actions = wesnoth.wml_actions
local T = wml.tag
function wml_actions.spawn_units(cfg)
local x = cfg.x or helper.wml_error("[spawn_units] missing required x= attribute.")
local y = cfg.y or helper.wml_error("[spawn_units] missing required y= attribute.")
local types = cfg.types or helper.wml_error("[spawn_units] missing required types= attribute.")
local count = cfg.count or helper.wml_error("[spawn_units] missing required count= attribute.")
local side = cfg.side or helper.wml_error("[spawn_units] missing required side= attribute.")
local x = cfg.x or wml.error("[spawn_units] missing required x= attribute.")
local y = cfg.y or wml.error("[spawn_units] missing required y= attribute.")
local types = cfg.types or wml.error("[spawn_units] missing required types= attribute.")
local count = cfg.count or wml.error("[spawn_units] missing required count= attribute.")
local side = cfg.side or wml.error("[spawn_units] missing required side= attribute.")
local done = 0
for i=1,count do

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local MG = wesnoth.require "mapgen_helper"
local LS = wesnoth.require "location_set"
local random = wesnoth.random
@ -153,7 +152,7 @@ function callbacks.generate_map(params)
if MG.is_valid_transform(t) then
table.insert(transforms, t)
else
helper.wml_error("Unknown transformation '" .. t .. "'")
wml.error("Unknown transformation '" .. t .. "'")
end
end
map[transforms[random(#transforms)]](map)

View file

@ -645,7 +645,7 @@ end
--! from table @options.
--! @return the index of the selected option.
--! @code
--! local result = helper.get_user_choice({ speaker = "narrator" },
--! local result = gui.get_user_choice({ speaker = "narrator" },
--! { "Choice 1", "Choice 2" })
--! @endcode
function gui.get_user_choice(attr, options)

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
local wml_actions = wesnoth.wml_actions
@ -12,7 +11,7 @@ end
wml_actions["if"] = function(cfg)
if not (wml.get_child(cfg, 'then') or wml.get_child(cfg, 'elseif') or wml.get_child(cfg, 'else')) then
helper.wml_error("[if] didn't find any [then], [elseif], or [else] children.")
wml.error("[if] didn't find any [then], [elseif], or [else] children.")
end
if wesnoth.eval_conditional(cfg) then -- evaluate [if] tag
@ -42,7 +41,7 @@ end
wml_actions["while"] = function( cfg )
if wml.child_count(cfg, "do") == 0 then
helper.wml_error "[while] does not contain any [do] tags"
wml.error "[while] does not contain any [do] tags"
end
-- execute [do] up to 65536 times
@ -78,7 +77,7 @@ end
wesnoth.wml_actions["for"] = function(cfg)
if wml.child_count(cfg, "do") == 0 then
helper.wml_error "[for] does not contain any [do] tags"
wml.error "[for] does not contain any [do] tags"
end
local loop_lim = {}
@ -103,7 +102,7 @@ wesnoth.wml_actions["for"] = function(cfg)
end
loop_lim = wml.tovconfig(loop_lim)
if loop_lim.step == 0 then -- Sanity check
helper.wml_error("[for] has a step of 0!")
wml.error("[for] has a step of 0!")
end
if (first < loop_lim.last and loop_lim.step <= 0)
or (first > loop_lim.last and loop_lim.step >= 0) then
@ -152,7 +151,7 @@ end
wml_actions["repeat"] = function(cfg)
if wml.child_count(cfg, "do") == 0 then
helper.wml_error "[repeat] does not contain any [do] tags"
wml.error "[repeat] does not contain any [do] tags"
end
local times = cfg.times or 1
@ -174,10 +173,10 @@ end
function wml_actions.foreach(cfg)
if wml.child_count(cfg, "do") == 0 then
helper.wml_error "[foreach] does not contain any [do] tags"
wml.error "[foreach] does not contain any [do] tags"
end
local array_name = cfg.array or helper.wml_error "[foreach] missing required array= attribute"
local array_name = cfg.array or wml.error "[foreach] missing required array= attribute"
local array = wml.array_variables[array_name]
if #array == 0 then return end -- empty and scalars unwanted
local item_name = cfg.variable or "this_item"
@ -190,7 +189,7 @@ function wml_actions.foreach(cfg)
-- Some protection against external modification
-- It's not perfect, though - it'd be nice if *any* change could be detected
if array_length ~= wml.variables[array_name .. ".length"] then
helper.wml_error("WML array length changed during [foreach] iteration")
wml.error("WML array length changed during [foreach] iteration")
end
wml.variables[item_name] = value
-- set index variable

View file

@ -20,7 +20,7 @@ That means before loading the WML tags via wesnoth.require "wml".
]]
function wml_actions.sync_variable(cfg)
local names = cfg.name or helper.wml_error "[sync_variable] missing required name= attribute."
local names = cfg.name or wml.error "[sync_variable] missing required name= attribute."
local result = wesnoth.synchronize_choice(
function()
local res = {}
@ -61,7 +61,7 @@ function wml_actions.chat(cfg)
local side_list = wesnoth.sides.find(cfg)
local speaker = tostring(cfg.speaker or "WML")
local message = tostring(cfg.message or
helper.wml_error "[chat] missing required message= attribute."
wml.error "[chat] missing required message= attribute."
)
for index, side in ipairs(side_list) do
@ -91,7 +91,7 @@ end
function wml_actions.gold(cfg)
local amount = tonumber(cfg.amount) or
helper.wml_error "[gold] missing required amount= attribute."
wml.error "[gold] missing required amount= attribute."
local sides = wesnoth.sides.find(cfg)
for index, team in ipairs(sides) do
team.gold = team.gold + amount
@ -107,7 +107,7 @@ end
function wml_actions.clear_variable(cfg, variables)
local names = cfg.name or
helper.wml_error "[clear_variable] missing required name= attribute."
wml.error "[clear_variable] missing required name= attribute."
if variables == nil then variables = wml.variables end
for w in utils.split(names) do
variables[utils.trim(w)] = nil
@ -126,11 +126,11 @@ end
function wml_actions.store_unit_type(cfg)
local types = cfg.type or
helper.wml_error "[store_unit_type] missing required type= attribute."
wml.error "[store_unit_type] missing required type= attribute."
local writer = utils.vwriter.init(cfg, "unit_type")
for w in utils.split(types) do
local unit_type = wesnoth.unit_types[w] or
helper.wml_error(string.format("Attempt to store nonexistent unit type '%s'.", w))
wml.error(string.format("Attempt to store nonexistent unit type '%s'.", w))
utils.vwriter.write(writer, unit_type.__cfg)
end
end
@ -156,7 +156,7 @@ function wml_actions.fire_event(cfg)
end
function wml_actions.allow_recruit(cfg)
local unit_types = cfg.type or helper.wml_error("[allow_recruit] missing required type= attribute")
local unit_types = cfg.type or wml.error("[allow_recruit] missing required type= attribute")
for index, team in ipairs(wesnoth.sides.find(cfg)) do
local v = team.recruit
for type in utils.split(unit_types) do
@ -168,7 +168,7 @@ function wml_actions.allow_recruit(cfg)
end
function wml_actions.allow_extra_recruit(cfg)
local recruits = cfg.extra_recruit or helper.wml_error("[allow_extra_recruit] missing required extra_recruit= attribute")
local recruits = cfg.extra_recruit or wml.error("[allow_extra_recruit] missing required extra_recruit= attribute")
for index, unit in ipairs(wesnoth.units.find_on_map(cfg)) do
local v = unit.extra_recruit
for recruit in utils.split(recruits) do
@ -200,7 +200,7 @@ function wml_actions.disallow_recruit(cfg)
end
function wml_actions.disallow_extra_recruit(cfg)
local recruits = cfg.extra_recruit or helper.wml_error("[disallow_extra_recruit] missing required extra_recruit= attribute")
local recruits = cfg.extra_recruit or wml.error("[disallow_extra_recruit] missing required extra_recruit= attribute")
for index, unit in ipairs(wesnoth.units.find_on_map(cfg)) do
local v = unit.extra_recruit
for w in utils.split(recruits) do
@ -216,7 +216,7 @@ function wml_actions.disallow_extra_recruit(cfg)
end
function wml_actions.set_recruit(cfg)
local recruit = cfg.recruit or helper.wml_error("[set_recruit] missing required recruit= attribute")
local recruit = cfg.recruit or wml.error("[set_recruit] missing required recruit= attribute")
for index, team in ipairs(wesnoth.sides.find(cfg)) do
local v = {}
for w in utils.split(recruit) do
@ -227,7 +227,7 @@ function wml_actions.set_recruit(cfg)
end
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 recruits = cfg.extra_recruit or wml.error("[set_extra_recruit] missing required extra_recruit= attribute")
local v = {}
for w in utils.split(recruits) do
@ -249,7 +249,7 @@ end
function wml_actions.unit_worth(cfg)
local u = wesnoth.units.find_on_map(cfg)[1] or
helper.wml_error "[unit_worth]'s filter didn't match any unit"
wml.error "[unit_worth]'s filter didn't match any unit"
local ut = wesnoth.unit_types[u.type]
local hp = u.hitpoints / u.max_hitpoints
local xp = u.experience / u.max_experience
@ -353,7 +353,7 @@ local function get_overlay_object_id(overlay)
end
function wml_actions.unit_overlay(cfg)
local img = cfg.image or helper.wml_error( "[unit_overlay] missing required image= attribute" )
local img = cfg.image or wml.error( "[unit_overlay] missing required image= attribute" )
for i,u in ipairs(wesnoth.units.find_on_map(cfg)) do
local has_already = false
for i, w in ipairs(u.overlays) do
@ -373,7 +373,7 @@ function wml_actions.unit_overlay(cfg)
end
function wml_actions.remove_unit_overlay(cfg)
local img = cfg.image or helper.wml_error( "[remove_unit_overlay] missing required image= attribute" )
local img = cfg.image or wml.error( "[remove_unit_overlay] missing required image= attribute" )
for i,u in ipairs(wesnoth.units.find_on_map(cfg)) do
local has_already = false
for i, w in ipairs(u.overlays) do
@ -398,7 +398,7 @@ end
function wml_actions.store_unit(cfg)
local filter = wml.get_child(cfg, "filter") or
helper.wml_error "[store_unit] missing required [filter] tag"
wml.error "[store_unit] missing required [filter] tag"
local kill_units = cfg.kill
--cache the needed units here, since the filter might reference the to-be-cleared variable(s)
@ -418,7 +418,7 @@ function wml_actions.store_unit(cfg)
end
function wml_actions.sound(cfg)
local name = cfg.name or helper.wml_error("[sound] missing required name= attribute")
local name = cfg.name or wml.error("[sound] missing required name= attribute")
wesnoth.play_sound(name, cfg["repeat"])
end
@ -440,11 +440,11 @@ end
function wml_actions.store_reachable_locations(cfg)
local unit_filter = wml.get_child(cfg, "filter") or
helper.wml_error "[store_reachable_locations] missing required [filter] tag"
wml.error "[store_reachable_locations] missing required [filter] tag"
local location_filter = wml.get_child(cfg, "filter_location")
local range = cfg.range or "movement"
local moves = cfg.moves or "current"
local variable = cfg.variable or helper.wml_error "[store_reachable_locations] missing required variable= key"
local variable = cfg.variable or wml.error "[store_reachable_locations] missing required variable= key"
local reach_param = { viewing_side = cfg.viewing_side or 0 }
if range == "vision" then
moves = "max"
@ -502,9 +502,9 @@ function wml_actions.capture_village(cfg)
local side = cfg.side
local filter_side = wml.get_child(cfg, "filter_side")
local fire_event = cfg.fire_event
if side then side = tonumber(side) or helper.wml_error("invalid side in [capture_village]") end
if side then side = tonumber(side) or wml.error("invalid side in [capture_village]") end
if filter_side then
if side then helper.wml_error("duplicate side information in [capture_village]") end
if side then wml.error("duplicate side information in [capture_village]") end
side = wesnoth.sides.find(filter_side)[1]
if side then side = side.side end
end
@ -516,7 +516,7 @@ function wml_actions.capture_village(cfg)
end
function wml_actions.terrain(cfg)
local terrain = cfg.terrain or helper.wml_error("[terrain] missing required terrain= attribute")
local terrain = cfg.terrain or wml.error("[terrain] missing required terrain= attribute")
cfg = wml.shallow_parsed(cfg)
cfg.terrain = nil
for i, loc in ipairs(wesnoth.get_locations(cfg)) do
@ -526,14 +526,14 @@ end
function wml_actions.delay(cfg)
local delay = tonumber(cfg.time) or
helper.wml_error "[delay] missing required time= attribute."
wml.error "[delay] missing required time= attribute."
local accelerate = cfg.accelerate or false
wesnoth.interface.delay(delay, accelerate)
end
function wml_actions.floating_text(cfg)
local locs = wesnoth.get_locations(cfg)
local text = cfg.text or helper.wml_error("[floating_text] missing required text= attribute")
local text = cfg.text or wml.error("[floating_text] missing required text= attribute")
for i, loc in ipairs(locs) do
wesnoth.interface.float_label(loc[1], loc[2], text, cfg.color)
@ -613,10 +613,10 @@ end
function wml_actions.add_ai_behavior(cfg)
local unit = wesnoth.units.find_on_map(wml.get_child(cfg, "filter"))[1] or
helper.wml_error("[add_ai_behavior]: no unit specified")
wml.error("[add_ai_behavior]: no unit specified")
local side = cfg.side or
helper.wml_error("[add_ai_behavior]: no side attribute given")
wml.error("[add_ai_behavior]: no side attribute given")
local sticky = cfg.sticky or false
local loop_id = cfg.loop_id or "main_loop"
@ -628,7 +628,7 @@ function wml_actions.add_ai_behavior(cfg)
local uy = unit.y
if not (eval and exec) then
helper.wml_error("[add_ai_behavior]: invalid execution/evaluation handler(s)")
wml.error("[add_ai_behavior]: invalid execution/evaluation handler(s)")
end
local path = "stage[" .. loop_id .. "].candidate_action[" .. id .. "]" -- bca: behavior candidate action
@ -740,7 +740,7 @@ function wml_actions.time_area(cfg)
end
function wml_actions.remove_time_area(cfg)
local id = cfg.id or helper.wml_error("[remove_time_area] missing required id= key")
local id = cfg.id or wml.error("[remove_time_area] missing required id= key")
for w in utils.split(id) do
wesnoth.remove_time_area(w)
@ -781,7 +781,7 @@ function wml_actions.event(cfg)
end
function wml_actions.remove_event(cfg)
local id = cfg.id or helper.wml_error("[remove_event] missing required id= key")
local id = cfg.id or wml.error("[remove_event] missing required id= key")
for w in utils.split(id) do
wesnoth.remove_event_handler(w)
@ -834,10 +834,10 @@ local function on_board(x, y)
end
wml_actions.unstore_unit = function(cfg)
local variable = cfg.variable or helper.wml_error("[unstore_unit] missing required 'variable' attribute")
local unit_cfg = wml.variables[variable] or helper.wml_error("[unstore_unit]: variable '" .. variable .. "' doesn't exist")
local variable = cfg.variable or wml.error("[unstore_unit] missing required 'variable' attribute")
local unit_cfg = wml.variables[variable] or wml.error("[unstore_unit]: variable '" .. variable .. "' doesn't exist")
if type(unit_cfg) ~= "table" or unit_cfg.type == nil then
helper.wml_error("[unstore_unit]: variable '" .. variable .. "' doesn't contain unit data")
wml.error("[unstore_unit]: variable '" .. variable .. "' doesn't contain unit data")
end
local unit = wesnoth.units.create(unit_cfg)
local advance = cfg.advance ~= false
@ -891,7 +891,7 @@ wml_actions.teleport = function(cfg)
end
function wml_actions.remove_sound_source(cfg)
local ids = cfg.id or helper.wml_error("[remove_sound_source] missing required id= attribute")
local ids = cfg.id or wml.error("[remove_sound_source] missing required id= attribute")
for id in utils.split(ids) do
wesnoth.remove_sound_source(id)
end
@ -904,7 +904,7 @@ end
function wml_actions.deprecated_message(cfg)
if type(cfg.level) ~= "number" or cfg.level < 1 or cfg.level > 4 then
local _ = wesnoth.textdomain "wesnoth"
helper.wml_error(_"Invalid deprecation level (should be 1-4)")
wml.error(_"Invalid deprecation level (should be 1-4)")
end
wesnoth.deprecated_message(cfg.what, cfg.level, cfg.version, cfg.message or '')
end
@ -951,7 +951,7 @@ function wesnoth.wml_actions.zoom(cfg)
end
function wesnoth.wml_actions.story(cfg)
local title = cfg.title or helper.wml_error "Missing title key in [story] ActionWML"
local title = cfg.title or wml.error "Missing title key in [story] ActionWML"
gui.show_story(cfg, title)
end
@ -960,7 +960,7 @@ function wesnoth.wml_actions.cancel_action(cfg)
end
function wesnoth.wml_actions.store_unit_defense(cfg)
local unit = wesnoth.units.find_on_map(cfg)[1] or helper.wml_error "[store_unit_defense]'s filter didn't match any unit"
local unit = wesnoth.units.find_on_map(cfg)[1] or wml.error "[store_unit_defense]'s filter didn't match any unit"
local terrain = cfg.terrain
local defense
@ -975,14 +975,14 @@ function wesnoth.wml_actions.store_unit_defense(cfg)
end
function wml_actions.terrain_mask(cfg)
cfg = helper.parsed(cfg)
cfg = wml.parsed(cfg)
local alignment = cfg.alignment
local is_odd = false
local border = cfg.border
local mask = cfg.mask
local x = cfg.x or helper.wml_error("[terrain_mask] missing x attribute")
local y = cfg.y or helper.wml_error("[terrain_mask] missing y attribute")
local x = cfg.x or wml.error("[terrain_mask] missing x attribute")
local y = cfg.y or wml.error("[terrain_mask] missing y attribute")
if alignment == "even" then
is_odd = false
elseif alignment == "odd" then

View file

@ -1,5 +1,4 @@
local helper = wesnoth.require "helper"
local utils = {vwriter = {}}
function utils.trim(s)
@ -17,7 +16,7 @@ function utils.check_key(val, key, tag, convert_spaces)
val = tostring(val):gsub(' ', '_')
end
if not val:match('^[a-zA-Z0-9_]+$') then
helper.wml_error("Invalid " .. key .. "= in [" .. tag .. "]")
wml.error("Invalid " .. key .. "= in [" .. tag .. "]")
end
return val
end
@ -117,7 +116,7 @@ function utils.handle_event_commands(cfg, scope_type)
if cmd == "insert_tag" then
cmd = arg.name
local from = arg.variable or
helper.wml_error("[insert_tag] found with no variable= field")
wml.error("[insert_tag] found with no variable= field")
arg = wml.variables[from]
if type(arg) ~= "table" then
@ -131,7 +130,7 @@ function utils.handle_event_commands(cfg, scope_type)
end
if not string.find(cmd, "^filter") then
cmd = wesnoth.wml_actions[cmd] or
helper.wml_error(string.format("[%s] not supported", cmd))
wml.error(string.format("[%s] not supported", cmd))
if insert_from then
local j = 0
repeat
@ -150,7 +149,7 @@ function utils.handle_event_commands(cfg, scope_type)
scope_stack:pop()
if #scope_stack == 0 then
if current_exit == "continue" and scope_type ~= "loop" then
helper.wml_error("[continue] found outside a loop scope!")
wml.error("[continue] found outside a loop scope!")
end
current_exit = "none"
end

View file

@ -3,7 +3,7 @@ local T = wml.tag
local function add_animation(anim, cfg)
cfg = wml.shallow_parsed(cfg)
local flag = cfg.flag or helper.wml_error("[animate_unit] is missing flag")
local flag = cfg.flag or wml.error("[animate_unit] is missing flag")
local filter = wml.get_child(cfg, "filter")
local unit
if filter then

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
local already_ended = false
@ -28,7 +27,7 @@ function wesnoth.wml_actions.endlevel(cfg)
local side_results = {}
for result in wml.child_range(parsed, "result") do
local side = result.side or helper.wml_error("[result] in [endlevel] missing required side= key")
local side = result.side or wml.error("[result] in [endlevel] missing required side= key")
side_results[side] = result
end
local there_is_a_human_victory = false
@ -49,7 +48,7 @@ function wesnoth.wml_actions.endlevel(cfg)
local victory_or_defeat = side_result.result or cfg.result or "victory"
local victory = victory_or_defeat == "victory"
if victory_or_defeat ~= "victory" and victory_or_defeat ~= "defeat" then
return helper.wml_error("invalid result= key in [endlevel] '" .. victory_or_defeat .."'")
return wml.error("invalid result= key in [endlevel] '" .. victory_or_defeat .."'")
end
if v.controller == "human" then
if victory then

View file

@ -1,11 +1,10 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
function wesnoth.wml_actions.find_path(cfg)
local filter_unit = wml.get_child(cfg, "traveler") or helper.wml_error("[find_path] missing required [traveler] tag")
local filter_unit = wml.get_child(cfg, "traveler") or wml.error("[find_path] missing required [traveler] tag")
-- only the first unit matching
local unit = wesnoth.units.find_on_map(filter_unit)[1] or helper.wml_error("[find_path]'s filter didn't match any unit")
local filter_location = wml.get_child(cfg, "destination") or helper.wml_error( "[find_path] missing required [destination] tag" )
local unit = wesnoth.units.find_on_map(filter_unit)[1] or wml.error("[find_path]'s filter didn't match any unit")
local filter_location = wml.get_child(cfg, "destination") or wml.error( "[find_path] missing required [destination] tag" )
-- support for $this_unit
local this_unit = utils.start_var_scope("this_unit")

View file

@ -4,9 +4,9 @@ local wml_actions = wesnoth.wml_actions
local T = wml.tag
function wml_actions.harm_unit(cfg)
local filter = wml.get_child(cfg, "filter") or helper.wml_error("[harm_unit] missing required [filter] tag")
local filter = wml.get_child(cfg, "filter") or wml.error("[harm_unit] missing required [filter] tag")
-- we need to use shallow_literal field, to avoid raising an error if $this_unit (not yet assigned) is used
if not wml.shallow_literal(cfg).amount then helper.wml_error("[harm_unit] has missing required amount= attribute") end
if not wml.shallow_literal(cfg).amount then wml.error("[harm_unit] has missing required amount= attribute") end
local variable = cfg.variable -- kept out of the way to avoid problems
local _ = wesnoth.textdomain "wesnoth"
-- #textdomain wesnoth

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local wml_actions = wesnoth.wml_actions
local scenario_items = (wesnoth.require "location_set").create()
@ -69,7 +68,7 @@ function wml_actions.item(cfg)
next_item_name = next_item_name + 1
end
if not cfg.image and not cfg.halo then
helper.wml_error "[item] missing required image= and halo= attributes."
wml.error "[item] missing required image= and halo= attributes."
end
for i, loc in ipairs(locs) do
add_overlay(loc[1], loc[2], cfg)
@ -91,7 +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]"))
variable = tostring(variable or wml.error("invalid variable= in [store_items]"))
wml.variables[variable] = nil
local index = 0
for i, loc in ipairs(wesnoth.get_locations(cfg)) do

View file

@ -1,5 +1,4 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
local _ = wesnoth.textdomain "wesnoth"
@ -32,7 +31,7 @@ local function get_image(cfg, speaker)
elseif cfg.image_pos == 'right' then
left_side = false
elseif cfg.image_pos ~= nil then
helper.wml_error('Invalid [message]image_pos - should be left or right')
wml.error('Invalid [message]image_pos - should be left or right')
end
return image, left_side

View file

@ -1,4 +1,3 @@
local H = wesnoth.require "helper"
local MAIH = wesnoth.require("ai/micro_ais/micro_ai_helper.lua")
wesnoth.micro_ais = {}
@ -12,21 +11,21 @@ function wesnoth.wml_actions.micro_ai(cfg)
cfg = cfg.__shallow_parsed
-- Check that the required common keys are all present and set correctly
if (not cfg.ai_type) then H.wml_error("[micro_ai] is missing required ai_type= key") end
if (not cfg.side) then H.wml_error("[micro_ai] is missing required side= key") end
if (not cfg.ai_type) then wml.error("[micro_ai] is missing required ai_type= key") end
if (not cfg.side) then wml.error("[micro_ai] is missing required side= key") end
if (not wesnoth.sides[cfg.side]) then
wesnoth.message("Warning", "[micro_ai] uses side=" .. cfg.side .. ": side does not exist")
return
end
if (not cfg.action) then H.wml_error("[micro_ai] is missing required action= key") end
if (not cfg.action) then wml.error("[micro_ai] is missing required action= key") end
if (cfg.action ~= 'add') and (cfg.action ~= 'delete') and (cfg.action ~= 'change') then
H.wml_error("[micro_ai] unknown value for action=. Allowed values: add, delete or change")
wml.error("[micro_ai] unknown value for action=. Allowed values: add, delete or change")
end
-- Set up the configuration tables for the different Micro AIs
if wesnoth.micro_ais[cfg.ai_type] == nil then
H.wml_error("unknown value for ai_type= in [micro_ai]")
wml.error("unknown value for ai_type= in [micro_ai]")
end
local required_keys, optional_keys, CA_parms = wesnoth.micro_ais[cfg.ai_type](cfg)

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
function wesnoth.wml_actions.modify_ai(cfg)
@ -11,7 +10,7 @@ function wesnoth.wml_actions.modify_ai(cfg)
local comp_type = string.sub(cfg.path, start, final)
component = wml.get_child(cfg, comp_type)
if component == nil then
helper.wml_error("Missing component definition in [modify_ai]")
wml.error("Missing component definition in [modify_ai]")
end
component = wml.parsed(component)
end
@ -25,7 +24,7 @@ function wesnoth.wml_actions.modify_ai(cfg)
local id_final = string.len(cfg.path) - 1
local id = string.sub(cfg.path, id_start, id_final)
if id == "*" then
helper.wml_error("[modify_ai] can only change one component at a time")
wml.error("[modify_ai] can only change one component at a time")
elseif not component.id and not id:match("[0-9]+") then
component.id = id
end

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
local wml_actions = wesnoth.wml_actions
@ -90,7 +89,7 @@ local function is_simple(cfg)
end
local function simple_modify_unit(cfg)
local filter = wml.get_child(cfg, "filter") or helper.wml_error "[modify_unit] missing required [filter] tag"
local filter = wml.get_child(cfg, "filter") or wml.error "[modify_unit] missing required [filter] tag"
-- todo: investigate the following attrtibutes:
-- id, alpha, flying, overlays
local simple_attributes = {
@ -160,7 +159,7 @@ local function simple_modify_unit(cfg)
if wesnoth.effects[apply_to] then
wesnoth.effects[apply_to](u, tagcontent)
else
helper.wml_error("[modify_unit] had invalid [effect]apply_to value")
wml.error("[modify_unit] had invalid [effect]apply_to value")
end
elseif tagname == "status" then
for i, v in pairs(tagcontent) do
@ -234,7 +233,7 @@ function wml_actions.modify_unit(cfg)
end
end
local filter = wml.get_child(cfg, "filter") or helper.wml_error "[modify_unit] missing required [filter] tag"
local filter = wml.get_child(cfg, "filter") or wml.error "[modify_unit] missing required [filter] tag"
local function handle_unit(unit_num)
local children_handled = {}
local unit_path = string.format("%s[%u]", unit_variable, unit_num)
@ -268,7 +267,7 @@ function wml_actions.modify_unit(cfg)
unit = unit.__cfg;
wml.variables[unit_path] = unit
else
helper.wml_error("[modify_unit] had invalid [effect]apply_to value")
wml.error("[modify_unit] had invalid [effect]apply_to value")
end
elseif current_tag == "set_variable" then
local unit = wesnoth.units.create(wml.variables[unit_path])

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
local function path_locs(path)
@ -50,7 +49,7 @@ function wesnoth.wml_actions.move_unit(cfg)
path = {to_x = cfg.to_x, to_y = cfg.to_y}
end
if not path then
helper.wml_error(coordinate_error)
wml.error(coordinate_error)
end
local fire_event = cfg.fire_event
local unshroud = cfg.clear_shroud
@ -72,10 +71,10 @@ function wesnoth.wml_actions.move_unit(cfg)
local x, y = xs(current_unit), ys(current_unit)
local prevX, prevY = tonumber(current_unit.x), tonumber(current_unit.y)
while true do
x = tonumber(x) or helper.wml_error(coordinate_error)
y = tonumber(y) or helper.wml_error(coordinate_error)
x = tonumber(x) or wml.error(coordinate_error)
y = tonumber(y) or wml.error(coordinate_error)
if not (x == prevX and y == prevY) then x, y = wesnoth.find_vacant_tile(x, y, pass_check) end
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
if not x or not y then 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", move_string_x, x)
move_string_y = string.format("%s,%u", move_string_y, y)
local next_x, next_y = xs(current_unit), ys(current_unit)

View file

@ -1,14 +1,13 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
wesnoth.wml_actions.random_placement = function(cfg)
local parsed = wml.shallow_parsed(cfg)
-- TODO: In most cases this tag is used to place units, so maybe make include_borders=no the default for [filter_location]?
local filter = wml.get_child(parsed, "filter_location") or {}
local command = wml.get_child(parsed, "command") or helper.wml_error("[random_placement] missing required [command] subtag")
local command = wml.get_child(parsed, "command") or wml.error("[random_placement] missing required [command] subtag")
local distance = cfg.min_distance or 0
local num_items = cfg.num_items or helper.wml_error("[random_placement] missing required 'num_items' attribute")
local variable = cfg.variable or helper.wml_error("[random_placement] missing required 'variable' attribute")
local num_items = cfg.num_items or wml.error("[random_placement] missing required 'num_items' attribute")
local variable = cfg.variable or wml.error("[random_placement] missing required 'variable' attribute")
local allow_less = cfg.allow_less == true
local variable_previous = utils.start_var_scope(variable)
local math_abs = math.abs
@ -33,7 +32,7 @@ wesnoth.wml_actions.random_placement = function(cfg)
print("placed only " .. i .. " items")
return
else
helper.wml_error("[random_placement] failed to place items. only " .. i .. " items were placed")
wml.error("[random_placement] failed to place items. only " .. i .. " items were placed")
end
end
local index = wesnoth.random(size)

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
function wesnoth.wml_actions.role(cfg)
@ -8,7 +7,7 @@ function wesnoth.wml_actions.role(cfg)
local filter = wml.shallow_literal(cfg)
if role == nil then
helper.wml_error("missing role= in [role]")
wml.error("missing role= in [role]")
end
local types = {}

View file

@ -424,7 +424,7 @@ function set_terrain_impl(data)
end
function set_terrain_simul(cfg)
cfg = helper.parsed(cfg)
cfg = wml.parsed(cfg)
local data = {}
for i, r in ipairs(cfg) do
r_new = {

View file

@ -2358,8 +2358,7 @@ Also, 0..9 = $below_ten, one,two,three = $ascii and the bonus answer is $mixed."
code = <<
local ec = wesnoth.current.event_context
wesnoth.message(string.format("Unit moved from %d,%d to %d,%d", ec.x2, ec.y2, ec.x1, ec.y1))
local helper = wesnoth.require "helper"
local result = helper.get_user_choice(
local result = gui.get_user_choice(
{ speaker = "unit", message = "Pick your poison" },
{ "&items/potion-red.png=Something red=Take a sip and enjoy",
"*&items/potion-blue.png=Nice blue=Surely youll like that one",

View file

@ -2,7 +2,7 @@
[event]
name = prestart
[lua]
code = << H = wesnoth.require("lua/helper.lua")
code = << H = wesnoth.require("helper")
A = wesnoth.require("ai/lua/extCAexample.lua")
result = H and A and true
wml.variables["result"] = result and "true" or "false" >>