Lua code: replace deprecated helper.get_child() calls

This commit is contained in:
mattsc 2018-05-11 07:44:30 -07:00
parent f153279e87
commit f0bb40590f
40 changed files with 88 additions and 88 deletions

View file

@ -1092,9 +1092,9 @@ end
function ai_helper.has_ability(unit, ability)
-- Returns true/false depending on whether unit has the given ability
local has_ability = false
local abilities = H.get_child(unit.__cfg, "abilities")
local abilities = wml.get_child(unit.__cfg, "abilities")
if abilities then
if H.get_child(abilities, ability) then has_ability = true end
if wml.get_child(abilities, ability) then has_ability = true end
end
return has_ability
end

View file

@ -60,7 +60,7 @@ return {
random_gender = false
}
-- Find the best regeneration ability and use it to estimate hp regained by regeneration
local abilities = H.get_child(unit.__cfg, "abilities")
local abilities = wml.get_child(unit.__cfg, "abilities")
local regen_amount = 0
if abilities then
for regen in H.child_range(abilities, "regenerate") do
@ -130,12 +130,12 @@ return {
for special in H.child_range(attack, 'specials') do
local mod
if H.get_child(special, 'poison') and can_poison then
if wml.get_child(special, 'poison') and can_poison then
poison = true
end
-- Handle marksman and magical
mod = H.get_child(special, 'chance_to_hit')
mod = wml.get_child(special, 'chance_to_hit')
if mod then
if mod.value then
if mod.cumulative then
@ -157,7 +157,7 @@ return {
end
-- Handle most damage specials (assumes all are cumulative)
mod = H.get_child(special, 'damage')
mod = wml.get_child(special, 'damage')
if mod and mod.active_on ~= "defense" then
local special_multiplier = 1
local special_bonus = 0
@ -198,7 +198,7 @@ return {
for defender_attack in H.child_range(defender.__cfg, 'attack') do
if (defender_attack.range == attack.range) then
for special in H.child_range(defender_attack, 'specials') do
if H.get_child(special, 'drains') and drainable(attacker) then
if wml.get_child(special, 'drains') and drainable(attacker) then
-- TODO: calculate chance to hit
-- currently assumes 50% chance to hit using supplied constant
local attacker_resistance = wesnoth.unit_resistance(attacker, defender_attack.type)
@ -295,7 +295,7 @@ return {
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
if H.get_child(special, 'slow') then
if wml.get_child(special, 'slow') then
return true
end
end
@ -936,7 +936,7 @@ return {
local test_units, num_recruits = {}, 0
local movetypes = {}
for x,id in ipairs(wesnoth.sides[wesnoth.current.side].recruit) do
local custom_movement = H.get_child(wesnoth.unit_types[id].__cfg, "movement_costs")
local custom_movement = wml.get_child(wesnoth.unit_types[id].__cfg, "movement_costs")
local movetype = wesnoth.unit_types[id].__cfg.movement_type
if custom_movement
or (not movetypes[movetype])

View file

@ -84,7 +84,7 @@ function retreat_functions.get_healing_locations()
if u.moves == 0 or u.side ~= wesnoth.current.side then
local heal_amount = 0
local cure = 0
local abilities = H.get_child(u.__cfg, "abilities") or {}
local abilities = wml.get_child(u.__cfg, "abilities") or {}
for ability in H.child_range(abilities, "heals") do
heal_amount = ability.value
if ability.poison == "slowed" then

View file

@ -5,12 +5,12 @@ local LS = wesnoth.require "location_set"
local function get_units_target(cfg)
local units = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
local target = wesnoth.get_units {
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
{ "and", H.get_child(cfg, "filter_second") }
{ "and", wml.get_child(cfg, "filter_second") }
}[1]
return units, target
@ -55,7 +55,7 @@ function ca_assassin_move:execution(cfg)
local enemies = AH.get_visible_units(wesnoth.current.side, {
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
{ "not", H.get_child(cfg, "filter_second") }
{ "not", wml.get_child(cfg, "filter_second") }
})
-- Maximum damage the enemies can theoretically do for all hexes they can attack
@ -128,7 +128,7 @@ function ca_assassin_move:execution(cfg)
-- Preferred hexes (do this here once for all hexes, so that it does not need
-- to get done for every step of the a* search.
-- We only need to know whether a hex is preferred or not, there's no additional rating.
local prefer_slf = H.get_child(cfg, "prefer")
local prefer_slf = wml.get_child(cfg, "prefer")
local prefer_map -- want this to be nil, not empty LS if [prefer] tag not given
if prefer_slf then
local preferred_hexes = wesnoth.get_locations(prefer_slf)

View file

@ -6,7 +6,7 @@ local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
local function get_big_animals(cfg)
local big_animals = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and" , H.get_child(cfg, "filter") }
{ "and" , wml.get_child(cfg, "filter") }
}
return big_animals
end
@ -24,7 +24,7 @@ function ca_big_animals:execution(cfg)
local unit = get_big_animals(cfg)[1]
local avoid_tag = H.get_child(cfg, "avoid_unit")
local avoid_tag = wml.get_child(cfg, "avoid_unit")
local avoid_map = LS.create()
if avoid_tag then
local enemies_to_be_avoided = AH.get_attackable_enemies(avoid_tag)
@ -41,7 +41,7 @@ function ca_big_animals:execution(cfg)
-- Unit gets a new goal if none is set or on any move with a 10% random chance
local r = math.random(10)
if (not goal.goal_x) or (r == 1) then
local locs = AH.get_passable_locations(H.get_child(cfg, "filter_location") or {})
local locs = AH.get_passable_locations(wml.get_child(cfg, "filter_location") or {})
local rand = math.random(#locs)
goal.goal_x, goal.goal_y = locs[rand][1], locs[rand][2]
@ -49,7 +49,7 @@ function ca_big_animals:execution(cfg)
end
local reach_map = AH.get_reachable_unocc(unit)
local wander_terrain = H.get_child(cfg, "filter_location_wander") or {}
local wander_terrain = wml.get_child(cfg, "filter_location_wander") or {}
reach_map:iter( function(x, y, v)
-- Remove tiles that do not comform to the wander terrain filter
if (not wesnoth.match_location(x, y, wander_terrain)) then

View file

@ -2,7 +2,7 @@ local H = wesnoth.require "helper"
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local function get_coward(cfg)
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
local filter = wml.get_child(cfg, "filter") or { id = cfg.id }
local coward = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", filter }
@ -23,7 +23,7 @@ function ca_coward:execution(cfg)
local reach = wesnoth.find_reach(coward)
local filter_second =
H.get_child(cfg, "filter_second")
wml.get_child(cfg, "filter_second")
or { { "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } } }
local enemies = AH.get_live_units {
{ "and", filter_second },

View file

@ -22,7 +22,7 @@ function ca_fast_attack_utils.get_avoid_map(cfg)
-- Use [micro_ai][avoid] tag with priority over [ai][avoid].
-- If neither is given, return an empty location set.
local avoid_tag = H.get_child(cfg, "avoid")
local avoid_tag = wml.get_child(cfg, "avoid")
if not avoid_tag then
return LS.of_pairs(ai.aspects.avoid)
@ -118,7 +118,7 @@ function ca_fast_attack_utils.single_unit_info(unit_proxy)
}
-- Include the ability type, such as: hides, heals, regenerate, skirmisher (set up as 'hides = true')
local abilities = H.get_child(unit_proxy.__cfg, "abilities")
local abilities = wml.get_child(unit_proxy.__cfg, "abilities")
if abilities then
for _,ability in ipairs(abilities) do
single_unit_info[ability[1]] = true

View file

@ -9,8 +9,8 @@ function ca_fast_combat:evaluation(cfg, data)
data.move_cache = { turn = wesnoth.current.turn }
data.gamedata = FAU.gamedata_setup()
local filter_own = H.get_child(cfg, "filter")
local filter_enemy = H.get_child(cfg, "filter_second")
local filter_own = wml.get_child(cfg, "filter")
local filter_enemy = wml.get_child(cfg, "filter_second")
local enemies
local units_sorted = true

View file

@ -18,8 +18,8 @@ function ca_fast_combat_leader:evaluation(cfg, data)
data.move_cache = { turn = wesnoth.current.turn }
data.gamedata = FAU.gamedata_setup()
local filter_own = H.get_child(cfg, "filter")
local filter_enemy = H.get_child(cfg, "filter_second")
local filter_own = wml.get_child(cfg, "filter")
local filter_enemy = wml.get_child(cfg, "filter_second")
local enemies, leader
if (not filter_own) and (not filter_enemy) then

View file

@ -73,7 +73,7 @@ function ca_forest_animals_move:execution(cfg)
end
-- If no close enemies, do a random move
local wander_terrain = H.get_child(cfg, "filter_location") or {}
local wander_terrain = wml.get_child(cfg, "filter_location") or {}
if (not close_enemies[1]) then
local reach = AH.get_reachable_unocc(unit)
local width, height = wesnoth.get_map_size()

View file

@ -31,7 +31,7 @@ function ca_goto:evaluation(cfg, data)
local all_locs = wesnoth.get_locations {
x = '1-' .. width,
y = '1-' .. height,
{ "and", H.get_child(cfg, "filter_location") }
{ "and", wml.get_child(cfg, "filter_location") }
}
if (#all_locs == 0) then return 0 end
@ -62,7 +62,7 @@ function ca_goto:evaluation(cfg, data)
local all_units = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
local units = {}

View file

@ -8,7 +8,7 @@ local M = wesnoth.map
local function get_hang_out_units(cfg)
local units = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
return units
end
@ -22,14 +22,14 @@ function ca_hang_out:evaluation(cfg, data)
end
-- Otherwise check if any of the mobilize conditions are now met
local mobilize_condition = H.get_child(cfg, "mobilize_condition")
local mobilize_condition = wml.get_child(cfg, "mobilize_condition")
if (mobilize_condition and wesnoth.eval_conditional(mobilize_condition))
or (cfg.mobilize_on_gold_less_than and (wesnoth.sides[wesnoth.current.side].gold < cfg.mobilize_on_gold_less_than))
then
MAISD.insert_mai_self_data(data, cfg.ai_id, { mobilize_units = true })
-- Need to unmark all units also (all units, with and without moves)
local units = wesnoth.get_units { side = wesnoth.current.side, { "and", H.get_child(cfg, "filter") } }
local units = wesnoth.get_units { side = wesnoth.current.side, { "and", wml.get_child(cfg, "filter") } }
for _,unit in ipairs(units) do
MAIUV.delete_mai_unit_variables(unit, cfg.ai_id)
end
@ -46,7 +46,7 @@ function ca_hang_out:execution(cfg)
-- Get the locations close to which the units should hang out
-- cfg.filter_location defaults to the location of the side leader(s)
local filter_location = H.get_child(cfg, "filter_location") or {
local filter_location = wml.get_child(cfg, "filter_location") or {
{ "filter", { side = wesnoth.current.side, canrecruit = "yes" } }
}
@ -60,15 +60,15 @@ function ca_hang_out:execution(cfg)
-- Get map of locations to be avoided.
-- Use [micro_ai][avoid] tag with priority over [ai][avoid].
-- If neither is given, default to all castle terrain.
local avoid_tag = H.get_child(cfg, "avoid")
local avoid_tag = wml.get_child(cfg, "avoid")
local avoid_map
if avoid_tag then
avoid_map = LS.of_pairs(wesnoth.get_locations(avoid_tag))
else
local ai_tag = H.get_child(wesnoth.sides[wesnoth.current.side].__cfg, 'ai')
local ai_tag = wml.get_child(wesnoth.sides[wesnoth.current.side].__cfg, 'ai')
for aspect in H.child_range(ai_tag, 'aspect') do
if (aspect.id == 'avoid') then
local facet = H.get_child(aspect, 'facet')
local facet = wml.get_child(aspect, 'facet')
if facet or aspect.name ~= "composite_aspect" then
-- If there's a [facet] child, it's set as a composite aspect,
-- with at least one facet.

View file

@ -19,7 +19,7 @@ function ca_healer_initialize:execution(cfg, data)
id = "no_healers_attack",
invalidate_on_gamestate_change = "yes",
{ "filter_own", {
{ "not", { ability = "healing", { "and", H.get_child(cfg, "filter") } } }
{ "not", { ability = "healing", { "and", wml.get_child(cfg, "filter") } } }
} }
}
)

View file

@ -16,7 +16,7 @@ function ca_healer_move:evaluation(cfg, data)
local all_healers = wesnoth.get_units {
side = wesnoth.current.side,
ability = "healing",
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
local healers, healers_noMP = {}, {}
@ -31,7 +31,7 @@ function ca_healer_move:evaluation(cfg, data)
local all_healees = wesnoth.get_units {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter_second") }
{ "and", wml.get_child(cfg, "filter_second") }
}
local healees, healees_MP = {}, {}

View file

@ -5,7 +5,7 @@ local M = wesnoth.map
local function get_sheep(cfg)
local sheep = wesnoth.get_units {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter_second") }
{ "and", wml.get_child(cfg, "filter_second") }
}
return sheep
end
@ -13,7 +13,7 @@ end
local function get_dogs(cfg)
local dogs = AH.get_units_with_attacks {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
return dogs
end
@ -22,7 +22,7 @@ local function get_enemies(cfg, radius)
local enemies = AH.get_attackable_enemies {
{ "filter_location",
{ radius = radius,
{ "filter", { side = wesnoth.current.side, { "and", H.get_child(cfg, "filter_second") } } } }
{ "filter", { side = wesnoth.current.side, { "and", wml.get_child(cfg, "filter_second") } } } }
}
}
return enemies

View file

@ -6,8 +6,8 @@ local M = wesnoth.map
local function get_dog(cfg)
local dogs = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") },
{ "not", { { "filter_adjacent", { side = wesnoth.current.side, { "and", H.get_child(cfg, "filter_second") } } } } }
{ "and", wml.get_child(cfg, "filter") },
{ "not", { { "filter_adjacent", { side = wesnoth.current.side, { "and", wml.get_child(cfg, "filter_second") } } } } }
}
return dogs[1]
end
@ -23,7 +23,7 @@ end
function ca_herding_dog_move:execution(cfg)
-- We simply move the first dog first, order does not matter
local dog = get_dog(cfg)
local herding_perimeter = LS.of_pairs(wesnoth.get_locations(H.get_child(cfg, "filter_location")))
local herding_perimeter = LS.of_pairs(wesnoth.get_locations(wml.get_child(cfg, "filter_location")))
-- Find average distance of herding_perimeter from center
local av_dist = 0

View file

@ -4,7 +4,7 @@ local AH = wesnoth.require "ai/lua/ai_helper.lua"
local function get_dog(cfg)
local dogs = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") },
{ "and", wml.get_child(cfg, "filter") },
}
return dogs[1]
end

View file

@ -4,7 +4,7 @@ local LS = wesnoth.require "location_set"
return function(cfg)
-- Find the area that the sheep can occupy
-- First, find all contiguous hexes around center hex that are inside herding_perimeter
local location_filter = H.get_child(cfg, "filter_location")
local location_filter = wml.get_child(cfg, "filter_location")
local herding_area = LS.of_pairs(wesnoth.get_locations {
x = cfg.herd_x,
y = cfg.herd_y,

View file

@ -7,7 +7,7 @@ local herding_area = wesnoth.require "ai/micro_ais/cas/ca_herding_f_herding_area
local function get_dogs(cfg)
local dogs = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
return dogs
end
@ -15,8 +15,8 @@ end
local function get_sheep_to_herd(cfg)
local all_sheep = wesnoth.get_units {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter_second") },
{ "not", { { "filter_adjacent", { side = wesnoth.current.side, { "and", H.get_child(cfg, "filter") } } } } }
{ "and", wml.get_child(cfg, "filter_second") },
{ "not", { { "filter_adjacent", { side = wesnoth.current.side, { "and", wml.get_child(cfg, "filter") } } } } }
}
local sheep_to_herd = {}
@ -63,7 +63,7 @@ function ca_herding_herd_sheep:execution(cfg)
-- And the closer dog goes first (so that it might be able to chase another sheep afterward)
rating = rating - M.distance_between(x, y, dog.x, dog.y) / 100.
-- Finally, prefer to stay on path, if possible
if (wesnoth.match_location(x, y, H.get_child(cfg, "filter_location")) ) then rating = rating + 0.001 end
if (wesnoth.match_location(x, y, wml.get_child(cfg, "filter_location")) ) then rating = rating + 0.001 end
reach_map:insert(x, y, rating)

View file

@ -6,7 +6,7 @@ local herding_area = wesnoth.require "ai/micro_ais/cas/ca_herding_f_herding_area
local function get_next_sheep(cfg)
local sheep = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter_second") }
{ "and", wml.get_child(cfg, "filter_second") }
}
return sheep[1]
end
@ -24,7 +24,7 @@ function ca_herding_sheep_move:execution(cfg)
local sheep = get_next_sheep(cfg)
local reach_map = AH.get_reachable_unocc(sheep)
local dogs_filter = H.get_child(cfg, "filter")
local dogs_filter = wml.get_child(cfg, "filter")
-- Exclude those that are next to a dog
reach_map:iter( function(x, y, v)
for xa, ya in H.adjacent_tiles(x, y) do

View file

@ -5,8 +5,8 @@ local M = wesnoth.map
local function get_next_sheep(cfg)
local sheep = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter_second") },
{ "filter_adjacent", { side = wesnoth.current.side, { "and", H.get_child(cfg, "filter") } } }
{ "and", wml.get_child(cfg, "filter_second") },
{ "filter_adjacent", { side = wesnoth.current.side, { "and", wml.get_child(cfg, "filter") } } }
}
return sheep[1]
end
@ -24,7 +24,7 @@ function ca_herding_sheep_runs_dog:execution(cfg)
local sheep = get_next_sheep(cfg)
-- Get the first dog that the sheep is adjacent to
local dog = wesnoth.get_units { side = wesnoth.current.side, { "and", H.get_child(cfg, "filter") },
local dog = wesnoth.get_units { side = wesnoth.current.side, { "and", wml.get_child(cfg, "filter") },
{ "filter_adjacent", { x = sheep.x, y = sheep.y } }
}[1]

View file

@ -5,7 +5,7 @@ local M = wesnoth.map
local function get_next_sheep_enemies(cfg)
local sheep = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter_second") }
{ "and", wml.get_child(cfg, "filter_second") }
}
if (not sheep[1]) then return end

View file

@ -36,7 +36,7 @@ local function hunter_attack_weakest_adj_enemy(ai, hunter)
end
local function get_hunter(cfg)
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
local filter = wml.get_child(cfg, "filter") or { id = cfg.id }
local hunter = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", filter }
@ -65,7 +65,7 @@ function ca_hunter:execution(cfg)
local rand = math.random(10)
if (not hunter_vars.goal_x) or (rand == 1) then
-- 'locs' includes border hexes, but that does not matter here
locs = AH.get_passable_locations((H.get_child(cfg, "filter_location") or {}), hunter)
locs = AH.get_passable_locations((wml.get_child(cfg, "filter_location") or {}), hunter)
local rand = math.random(#locs)
hunter_vars.goal_x, hunter_vars.goal_y = locs[rand][1], locs[rand][2]

View file

@ -6,7 +6,7 @@ local function get_lurker(cfg)
-- We simply pick the first of the lurkers, they have no strategy
local lurker = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}[1]
return lurker
end
@ -26,7 +26,7 @@ function ca_lurkers:execution(cfg)
table.sort(targets, function(a, b) return (a.hitpoints < b.hitpoints) end)
local reach = LS.of_pairs(wesnoth.find_reach(lurker.x, lurker.y))
local lurk_area = H.get_child(cfg, "filter_location")
local lurk_area = wml.get_child(cfg, "filter_location")
local reachable_attack_terrain =
LS.of_pairs(wesnoth.get_locations {
{ "and", { x = lurker.x, y = lurker.y, radius = lurker.moves } },
@ -66,7 +66,7 @@ function ca_lurkers:execution(cfg)
local reachable_wander_terrain =
LS.of_pairs( wesnoth.get_locations {
{ "and", { x = lurker.x, y = lurker.y, radius = lurker.moves } },
{ "and", H.get_child(cfg, "filter_location_wander") or lurk_area }
{ "and", wml.get_child(cfg, "filter_location_wander") or lurk_area }
})
reachable_wander_terrain:inter(reach)

View file

@ -45,11 +45,11 @@ local function messenger_find_clearing_attack(messenger, goal_x, goal_y, cfg)
local enemy_in_way = messenger_find_enemies_in_way(messenger, goal_x, goal_y)
if (not enemy_in_way) then return end
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
local filter = wml.get_child(cfg, "filter") or { id = cfg.id }
local units = AH.get_units_with_attacks {
side = wesnoth.current.side,
{ "not", filter },
{ "and", H.get_child(cfg, "filter_second") }
{ "and", wml.get_child(cfg, "filter_second") }
}
if (not units[1]) then return end

View file

@ -9,7 +9,7 @@ local messenger_next_waypoint = wesnoth.require "ai/micro_ais/cas/ca_messenger_f
local function get_escorts(cfg)
local escorts = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter_second") }
{ "and", wml.get_child(cfg, "filter_second") }
}
return escorts
end

View file

@ -10,7 +10,7 @@ return function(cfg)
-- Returns nil for first 3 arguments if no messenger has moves left
-- Returns nil for all arguments if there are no messengers on the map
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
local filter = wml.get_child(cfg, "filter") or { id = cfg.id }
local messengers = wesnoth.get_units { side = wesnoth.current.side, { "and", filter } }
if (not messengers[1]) then return end

View file

@ -3,7 +3,7 @@ local AH = wesnoth.require "ai/lua/ai_helper.lua"
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
local function get_patrol(cfg)
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
local filter = wml.get_child(cfg, "filter") or { id = cfg.id }
local patrol = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", filter }

View file

@ -2,7 +2,7 @@ local H = wesnoth.require "helper"
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local function get_guardian(cfg)
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
local filter = wml.get_child(cfg, "filter") or { id = cfg.id }
local guardian = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", filter }

View file

@ -8,13 +8,13 @@ local ca_simple_attack, best_attack = {}
function ca_simple_attack:evaluation(cfg)
local units = AH.get_units_with_attacks {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
if (not units[1]) then return 0 end
-- If cfg.filter_second is set, set up a map (location set)
-- of enemies that it is okay to attack
local enemy_filter = H.get_child(cfg, "filter_second")
local enemy_filter = wml.get_child(cfg, "filter_second")
local enemy_map
if enemy_filter then
local enemies = AH.get_attackable_enemies(enemy_filter)

View file

@ -3,7 +3,7 @@ local AH = wesnoth.require "ai/lua/ai_helper.lua"
local M = wesnoth.map
local function get_guardian(cfg)
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
local filter = wml.get_child(cfg, "filter") or { id = cfg.id }
local guardian = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", filter }

View file

@ -6,15 +6,15 @@ local M = wesnoth.map
local function get_wolves(cfg)
local wolves = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
return wolves
end
local function get_prey(cfg)
-- Note: we cannot pass H.get_child() directly to AH.get_attackable_enemies()
-- Note: we cannot pass wml.get_child() directly to AH.get_attackable_enemies()
-- as the former returns two values and the latter takes optional arguments
local filter_second = H.get_child(cfg, "filter_second")
local filter_second = wml.get_child(cfg, "filter_second")
local prey = AH.get_attackable_enemies(filter_second)
return prey
end

View file

@ -6,7 +6,7 @@ local LS = wesnoth.require "location_set"
local function get_wolves(cfg)
local wolves = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", H.get_child(cfg, "filter") }
{ "and", wml.get_child(cfg, "filter") }
}
return wolves
end

View file

@ -4,7 +4,7 @@ local LS = wesnoth.require "location_set"
local M = wesnoth.map
local function get_guardian(cfg)
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
local filter = wml.get_child(cfg, "filter") or { id = cfg.id }
local guardian = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", filter }
@ -23,8 +23,8 @@ function ca_zone_guardian:execution(cfg)
local guardian = get_guardian(cfg)
local reach = wesnoth.find_reach(guardian)
local zone = H.get_child(cfg, "filter_location")
local zone_enemy = H.get_child(cfg, "filter_location_enemy") or zone
local zone = wml.get_child(cfg, "filter_location")
local zone_enemy = wml.get_child(cfg, "filter_location_enemy") or zone
local enemies = AH.get_attackable_enemies { { "filter_location", zone_enemy } }
if enemies[1] then
local min_dist, target = 9e99

View file

@ -30,7 +30,7 @@ function wesnoth.micro_ais.wolves(cfg)
id = "mai_wolves_" .. (cfg.ca_id or "default") .. "_dont_attack",
invalidate_on_gamestate_change = "yes",
{ "filter_enemy", {
{ "and", H.get_child(cfg, "filter_second") }
{ "and", wml.get_child(cfg, "filter_second") }
} }
}
}
@ -165,7 +165,7 @@ function wesnoth.micro_ais.wolves_multipacks(cfg)
end
function wesnoth.micro_ais.hunter(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
if (cfg.action ~= 'delete') and (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")
end
local required_keys = { "home_x", "home_y" }

View file

@ -1,7 +1,7 @@
local H = wesnoth.require "helper"
function wesnoth.micro_ais.messenger_escort(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
if (cfg.action ~= 'delete') and (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")
end
local required_keys = { "waypoint_x", "waypoint_y" }

View file

@ -1,7 +1,7 @@
local H = wesnoth.require "helper"
function wesnoth.micro_ais.stationed_guardian(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
if (cfg.action ~= 'delete') and (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")
end
local required_keys = { "distance", "station_x", "station_y" }
@ -14,7 +14,7 @@ function wesnoth.micro_ais.stationed_guardian(cfg)
end
function wesnoth.micro_ais.zone_guardian(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
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")
end
local required_keys = { "[filter_location]" }
@ -27,7 +27,7 @@ function wesnoth.micro_ais.zone_guardian(cfg)
end
function wesnoth.micro_ais.return_guardian(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
if (cfg.action ~= 'delete') and (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")
end
local required_keys = { "return_x", "return_y" }
@ -40,7 +40,7 @@ function wesnoth.micro_ais.return_guardian(cfg)
end
function wesnoth.micro_ais.coward(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
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")
end
local required_keys = { "distance" }

View file

@ -1,7 +1,7 @@
local H = wesnoth.require "helper"
function wesnoth.micro_ais.patrol(cfg)
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
if (cfg.action ~= 'delete') and (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")
end
local required_keys = { "waypoint_x", "waypoint_y" }

View file

@ -169,7 +169,7 @@ function micro_ai_helper.micro_ai_setup(cfg, CA_parms, required_keys, optional_k
for _,v in pairs(required_keys) do
if v:match('%[[a-zA-Z0-9_]+%]') then
v = v:sub(2,-2)
if not H.get_child(cfg, v) then
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

View file

@ -16,7 +16,7 @@ local function plugin()
local function find_test_game(info)
local g = info.game_list()
if g then
local gamelist = helper.get_child(g, "gamelist")
local gamelist = wml.get_child(g, "gamelist")
if gamelist then
for i = 1, #gamelist do
local t = gamelist[i]