From 4586e04eca8e898724757c887c87ad6dc666b7b4 Mon Sep 17 00:00:00 2001 From: mattsc Date: Fri, 11 May 2018 07:52:19 -0700 Subject: [PATCH] Lua code: replace deprecated helper.child_range() calls (cherry-picked from commit 7c137e1a336559acdd6f797192a9516135480b2e) --- data/ai/lua/battle_calcs.lua | 4 ++-- data/ai/lua/generic_recruit_engine.lua | 14 +++++++------- data/ai/lua/retreat.lua | 2 +- data/ai/micro_ais/cas/ca_fast_attack_utils.lua | 4 ++-- data/ai/micro_ais/cas/ca_hang_out.lua | 2 +- .../micro_ais/cas/ca_protect_unit_attack.lua | 2 +- .../micro_ais/cas/ca_protect_unit_finish.lua | 2 +- data/ai/micro_ais/cas/ca_protect_unit_move.lua | 4 ++-- data/ai/micro_ais/cas/ca_recruit_random.lua | 2 +- data/ai/micro_ais/mai-defs/protect.lua | 2 +- data/ai/micro_ais/micro_ai_helper.lua | 18 +++++++++--------- data/ai/micro_ais/micro_ai_self_data.lua | 2 +- data/ai/micro_ais/micro_ai_unit_variables.lua | 2 +- .../multiplayer/scenarios/2p_Dark_Forecast.lua | 2 +- 14 files changed, 31 insertions(+), 31 deletions(-) diff --git a/data/ai/lua/battle_calcs.lua b/data/ai/lua/battle_calcs.lua index 13f22b91cd06..13def8eae435 100644 --- a/data/ai/lua/battle_calcs.lua +++ b/data/ai/lua/battle_calcs.lua @@ -38,11 +38,11 @@ function battle_calcs.unit_attack_info(unit, cache) resist_mod = {}, alignment = unit_cfg.alignment } - for attack in H.child_range(unit_cfg, 'attack') do + for attack in wml.child_range(unit_cfg, 'attack') do -- Extract information for specials; we do this first because some -- custom special might have the same name as one of the default scalar fields local a = {} - for special in H.child_range(attack, 'specials') do + for special in wml.child_range(attack, 'specials') do for _,sp in ipairs(special) do if (sp[1] == 'damage') then -- this is 'backstab' if (sp[2].id == 'backstab') then diff --git a/data/ai/lua/generic_recruit_engine.lua b/data/ai/lua/generic_recruit_engine.lua index 37f1a3e33d3d..6bb4cfdb1d32 100644 --- a/data/ai/lua/generic_recruit_engine.lua +++ b/data/ai/lua/generic_recruit_engine.lua @@ -63,7 +63,7 @@ return { local abilities = wml.get_child(unit.__cfg, "abilities") local regen_amount = 0 if abilities then - for regen in H.child_range(abilities, "regenerate") do + for regen in wml.child_range(abilities, "regenerate") do if regen.value > regen_amount then regen_amount = regen.value end @@ -121,14 +121,14 @@ return { -- This may be rectifiable by looking at retaliation damage as well. local steadfast = false - for attack in H.child_range(wesnoth.unit_types[attacker.type].__cfg, "attack") do + for attack in wml.child_range(wesnoth.unit_types[attacker.type].__cfg, "attack") do local defense = defender_defense local poison = false local damage_multiplier = 1 local damage_bonus = 0 local weapon_damage = attack.damage - for special in H.child_range(attack, 'specials') do + for special in wml.child_range(attack, 'specials') do local mod if wml.get_child(special, 'poison') and can_poison then poison = true @@ -195,9 +195,9 @@ return { -- Handle drain for defender local drain_recovery = 0 - for defender_attack in H.child_range(defender.__cfg, 'attack') do + for defender_attack in wml.child_range(defender.__cfg, 'attack') do if (defender_attack.range == attack.range) then - for special in H.child_range(defender_attack, 'specials') do + for special in wml.child_range(defender_attack, 'specials') do if wml.get_child(special, 'drains') and drainable(attacker) then -- TODO: calculate chance to hit -- currently assumes 50% chance to hit using supplied constant @@ -293,8 +293,8 @@ return { end function can_slow(unit) - for defender_attack in H.child_range(unit.__cfg, 'attack') do - for special in H.child_range(defender_attack, 'specials') do + for defender_attack in wml.child_range(unit.__cfg, 'attack') do + for special in wml.child_range(defender_attack, 'specials') do if wml.get_child(special, 'slow') then return true end diff --git a/data/ai/lua/retreat.lua b/data/ai/lua/retreat.lua index ad527bd05cbb..ea6c047fd033 100644 --- a/data/ai/lua/retreat.lua +++ b/data/ai/lua/retreat.lua @@ -85,7 +85,7 @@ function retreat_functions.get_healing_locations() local heal_amount = 0 local cure = 0 local abilities = wml.get_child(u.__cfg, "abilities") or {} - for ability in H.child_range(abilities, "heals") do + for ability in wml.child_range(abilities, "heals") do heal_amount = ability.value if ability.poison == "slowed" then cure = 1 diff --git a/data/ai/micro_ais/cas/ca_fast_attack_utils.lua b/data/ai/micro_ais/cas/ca_fast_attack_utils.lua index 3c95164549d2..9940a2c73eee 100644 --- a/data/ai/micro_ais/cas/ca_fast_attack_utils.lua +++ b/data/ai/micro_ais/cas/ca_fast_attack_utils.lua @@ -128,11 +128,11 @@ function ca_fast_attack_utils.single_unit_info(unit_proxy) -- Information about the attacks indexed by weapon number, -- including specials (e.g. 'poison = true') single_unit_info.attacks = {} - for attack in H.child_range(unit_cfg, 'attack') do + for attack in wml.child_range(unit_cfg, 'attack') do -- Extract information for specials; we do this first because some -- custom special might have the same name as one of the default scalar fields local a = {} - for special in H.child_range(attack, 'specials') do + for special in wml.child_range(attack, 'specials') do for _,sp in ipairs(special) do if (sp[1] == 'damage') then -- this is 'backstab' if (sp[2].id == 'backstab') then diff --git a/data/ai/micro_ais/cas/ca_hang_out.lua b/data/ai/micro_ais/cas/ca_hang_out.lua index 8eb410f80546..ae58239246d5 100644 --- a/data/ai/micro_ais/cas/ca_hang_out.lua +++ b/data/ai/micro_ais/cas/ca_hang_out.lua @@ -66,7 +66,7 @@ function ca_hang_out:execution(cfg) avoid_map = LS.of_pairs(wesnoth.get_locations(avoid_tag)) else local ai_tag = wml.get_child(wesnoth.sides[wesnoth.current.side].__cfg, 'ai') - for aspect in H.child_range(ai_tag, 'aspect') do + for aspect in wml.child_range(ai_tag, 'aspect') do if (aspect.id == 'avoid') then local facet = wml.get_child(aspect, 'facet') if facet or aspect.name ~= "composite_aspect" then diff --git a/data/ai/micro_ais/cas/ca_protect_unit_attack.lua b/data/ai/micro_ais/cas/ca_protect_unit_attack.lua index 0e1f1628fa3e..4ceb97bb832c 100644 --- a/data/ai/micro_ais/cas/ca_protect_unit_attack.lua +++ b/data/ai/micro_ais/cas/ca_protect_unit_attack.lua @@ -10,7 +10,7 @@ function ca_protect_unit_attack:evaluation(cfg) -- or the counter attack on the enemy turn, it does not attack, even if that's really unlikely local units = {} - for u in H.child_range(cfg, "unit") do + for u in wml.child_range(cfg, "unit") do table.insert(units, AH.get_units_with_attacks { id = u.id }[1]) end if (not units[1]) then return 0 end diff --git a/data/ai/micro_ais/cas/ca_protect_unit_finish.lua b/data/ai/micro_ais/cas/ca_protect_unit_finish.lua index 875f3fb55fab..4cd399f4844e 100644 --- a/data/ai/micro_ais/cas/ca_protect_unit_finish.lua +++ b/data/ai/micro_ais/cas/ca_protect_unit_finish.lua @@ -5,7 +5,7 @@ local ca_protect_unit_finish, PU_unit, PU_goal = {} function ca_protect_unit_finish:evaluation(cfg) -- If a unit can make it to the goal, this is the first thing that happens - for u in H.child_range(cfg, "unit") do + for u in wml.child_range(cfg, "unit") do local unit = AH.get_units_with_moves { id = u.id }[1] if unit then local path, cost = AH.find_path_with_shroud(unit, u.goal_x, u.goal_y) diff --git a/data/ai/micro_ais/cas/ca_protect_unit_move.lua b/data/ai/micro_ais/cas/ca_protect_unit_move.lua index bda9f92785c9..62806b417362 100644 --- a/data/ai/micro_ais/cas/ca_protect_unit_move.lua +++ b/data/ai/micro_ais/cas/ca_protect_unit_move.lua @@ -5,7 +5,7 @@ local BC = wesnoth.require "ai/lua/battle_calcs.lua" local function get_protected_units(cfg) local units = {} - for u in H.child_range(cfg, "unit") do + for u in wml.child_range(cfg, "unit") do table.insert(units, AH.get_units_with_moves { id = u.id }[1]) end return units @@ -38,7 +38,7 @@ function ca_protect_unit_move:execution(cfg, data) -- We move the weakest (fewest HP unit) first local unit = AH.choose(protected_units, function(u) return - u.hitpoints end) local goal = {} - for u in H.child_range(cfg, "unit") do + for u in wml.child_range(cfg, "unit") do if (unit.id == u.id) then goal = { u.goal_x, u.goal_y } end end diff --git a/data/ai/micro_ais/cas/ca_recruit_random.lua b/data/ai/micro_ais/cas/ca_recruit_random.lua index 88c07e3b35cf..156f33019251 100644 --- a/data/ai/micro_ais/cas/ca_recruit_random.lua +++ b/data/ai/micro_ais/cas/ca_recruit_random.lua @@ -59,7 +59,7 @@ function ca_recruit_random:evaluation(cfg) local probabilities, probability_sum = {}, 0 -- Go through all the types listed in [probability] tags (which can be comma-separated lists) - for prob in H.child_range(cfg, "probability") do + for prob in wml.child_range(cfg, "probability") do types = AH.split(prob.type, ",") for _,typ in ipairs(types) do -- 'type' is a reserved keyword in Lua -- If this type is in the recruit list, add it diff --git a/data/ai/micro_ais/mai-defs/protect.lua b/data/ai/micro_ais/mai-defs/protect.lua index 6744b0bcdee4..f903496677e6 100644 --- a/data/ai/micro_ais/mai-defs/protect.lua +++ b/data/ai/micro_ais/mai-defs/protect.lua @@ -11,7 +11,7 @@ function wesnoth.micro_ais.protect_unit(cfg) } local unit_ids = {} - for u in H.child_range(cfg, "unit") do + 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") end diff --git a/data/ai/micro_ais/micro_ai_helper.lua b/data/ai/micro_ais/micro_ai_helper.lua index d074665f71fc..f88755b5bd29 100644 --- a/data/ai/micro_ais/micro_ai_helper.lua +++ b/data/ai/micro_ais/micro_ai_helper.lua @@ -39,9 +39,9 @@ function micro_ai_helper.add_CAs(side, ca_id_core, CA_parms, CA_cfg) while id_found do -- This is really just a precaution id_found = false - for ai_tag in H.child_range(wesnoth.sides[side].__cfg, 'ai') do - for stage in H.child_range(ai_tag, 'stage') do - for ca in H.child_range(stage, 'candidate_action') do + for ai_tag in wml.child_range(wesnoth.sides[side].__cfg, 'ai') do + for stage in wml.child_range(ai_tag, 'stage') do + for ca in wml.child_range(stage, 'candidate_action') do if string.find(ca.name, ai_id .. '_') then id_found = true break @@ -54,10 +54,10 @@ function micro_ai_helper.add_CAs(side, ca_id_core, CA_parms, CA_cfg) -- AI's data variable. However, the MAI can be changed while it is not -- the AI's turn, when this is not possible. So instead, we check for the -- existence of such tags and make sure we are using a different ai_id. - for ai_tag in H.child_range(wesnoth.sides[side].__cfg, 'ai') do - for engine in H.child_range(ai_tag, 'engine') do - for data in H.child_range(engine, 'data') do - for mai in H.child_range(data, 'micro_ai') do + for ai_tag in wml.child_range(wesnoth.sides[side].__cfg, 'ai') do + for engine in wml.child_range(ai_tag, 'engine') do + for data in wml.child_range(engine, 'data') do + for mai in wml.child_range(data, 'micro_ai') do if (mai.ai_id == ai_id) then id_found = true break @@ -172,7 +172,7 @@ function micro_ai_helper.micro_ai_setup(cfg, CA_parms, required_keys, optional_k if not wml.get_child(cfg, v) then H.wml_error("[micro_ai] tag (" .. cfg.ai_type .. ") is missing required parameter: [" .. v .. "]") end - for child in H.child_range(cfg, v) do + for child in wml.child_range(cfg, v) do table.insert(CA_cfg, T[v](child)) end else @@ -187,7 +187,7 @@ function micro_ai_helper.micro_ai_setup(cfg, CA_parms, required_keys, optional_k for _,v in pairs(optional_keys) do if v:match('%[[a-zA-Z0-9_]+%]') then v = v:sub(2,-2) - for child in H.child_range(cfg, v) do + for child in wml.child_range(cfg, v) do table.insert(CA_cfg, T[v](child)) end else diff --git a/data/ai/micro_ais/micro_ai_self_data.lua b/data/ai/micro_ais/micro_ai_self_data.lua index 12f0f91c51c8..13c474075357 100644 --- a/data/ai/micro_ais/micro_ai_self_data.lua +++ b/data/ai/micro_ais/micro_ai_self_data.lua @@ -79,7 +79,7 @@ function micro_ai_self_data.get_mai_self_data(self_data, ai_id, key) -- table of key=value pairs (including the ai_id key) -- - If no such tag is found: nil (if @key is set), otherwise empty table - for mai in H.child_range(self_data, "micro_ai") do + for mai in wml.child_range(self_data, "micro_ai") do if (mai.ai_id == ai_id) then if key then return mai[key] diff --git a/data/ai/micro_ais/micro_ai_unit_variables.lua b/data/ai/micro_ais/micro_ai_unit_variables.lua index 0e448e4b6ee8..9f8b149e5fe6 100644 --- a/data/ai/micro_ais/micro_ai_unit_variables.lua +++ b/data/ai/micro_ais/micro_ai_unit_variables.lua @@ -70,7 +70,7 @@ function micro_ai_unit_variables.get_mai_unit_variables(unit, ai_id, key) -- table of key=value pairs (including the ai_id key) -- - If no such tag is found: nil (if @key is set), otherwise empty table - for mai in H.child_range(unit.variables.__cfg, "micro_ai") do + for mai in wml.child_range(unit.variables.__cfg, "micro_ai") do if (mai.ai_id == ai_id) then if key then return mai[key] diff --git a/data/multiplayer/scenarios/2p_Dark_Forecast.lua b/data/multiplayer/scenarios/2p_Dark_Forecast.lua index f54c02d5a014..8036e030a06d 100644 --- a/data/multiplayer/scenarios/2p_Dark_Forecast.lua +++ b/data/multiplayer/scenarios/2p_Dark_Forecast.lua @@ -251,7 +251,7 @@ local function final_spawn() local spawn = wml.variables[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 + for tag in wml.child_range(spawn, "type") do table.insert(types, tag.type) end place_units(types, spawn.x, spawn.y)