Skip to content

Commit

Permalink
MicroAIs: Update all to use the new [args] syntax
Browse files Browse the repository at this point in the history
Except for Protect Unit, all of them seem to still work correctly.
  • Loading branch information
CelticMinstrel committed Mar 27, 2016
1 parent 037a526 commit c798740
Show file tree
Hide file tree
Showing 55 changed files with 367 additions and 397 deletions.
4 changes: 1 addition & 3 deletions data/ai/lua/generic_recruit_engine.lua
Expand Up @@ -440,9 +440,7 @@ return {
return score
end

function ai_cas:recruit_rushers_exec(ai_local)
if ai_local then ai = ai_local end

function ai_cas:recruit_rushers_exec()
if AH.show_messages() then W.message { speaker = 'narrator', message = 'Recruiting' } end

local enemy_counts = recruit_data.recruit.enemy_counts
Expand Down
15 changes: 8 additions & 7 deletions data/ai/micro_ais/cas/ca_big_animals.lua
Expand Up @@ -6,27 +6,28 @@ 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" , cfg.filter }
{ "and" , H.get_child(cfg, "filter") }
}
return big_animals
end

local ca_big_animals = {}

function ca_big_animals:evaluation(ai, cfg)
function ca_big_animals:evaluation(cfg)
if get_big_animals(cfg)[1] then return cfg.ca_score end
return 0
end

function ca_big_animals:execution(ai, cfg)
function ca_big_animals:execution(cfg)
-- Big animals just move toward a goal that gets (re)set occasionally
-- and attack whatever is in their range (except for some units that they avoid)

local big_animals = get_big_animals(cfg)
local avoid_tag = H.get_child(cfg, "avoid_unit")
local avoid_map = LS.create()
if cfg.avoid_unit then
if avoid_tag then
avoid_map = LS.of_pairs(wesnoth.get_locations { radius = 1,
{ "filter", { { "and", cfg.avoid_unit },
{ "filter", { { "and", avoid_tag },
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } }
} }
})
Expand All @@ -38,15 +39,15 @@ function ca_big_animals:execution(ai, 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(cfg.filter_location or {})
local locs = AH.get_passable_locations(H.get_child(cfg, "filter_location") or {})
local rand = math.random(#locs)

goal.goal_x, goal.goal_y = locs[rand][1], locs[rand][2]
MAIUV.set_mai_unit_variables(unit, cfg.ai_id, goal)
end

local reach_map = AH.get_reachable_unocc(unit)
local wander_terrain = cfg.filter_location_wander or {}
local wander_terrain = H.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
Expand Down
22 changes: 11 additions & 11 deletions data/ai/micro_ais/cas/ca_bottleneck_attack.lua
Expand Up @@ -3,7 +3,7 @@ local H = wesnoth.require "lua/helper.lua"

local ca_bottleneck_attack = {}

function ca_bottleneck_attack:evaluation(ai, cfg, self)
function ca_bottleneck_attack:evaluation(cfg, data)
local attackers = AH.get_units_with_attacks {
side = wesnoth.current.side,
{ "filter_adjacent", {
Expand Down Expand Up @@ -55,29 +55,29 @@ function ca_bottleneck_attack:evaluation(ai, cfg, self)

if (not best_attacker) then
-- In this case we take attacks away from all units
self.data.BD_bottleneck_attacks_done = true
data.BD_bottleneck_attacks_done = true
else
self.data.BD_bottleneck_attacks_done = false
self.data.BD_attacker = best_attacker
self.data.BD_target = best_target
self.data.BD_weapon = best_weapon
data.BD_bottleneck_attacks_done = false
data.BD_attacker = best_attacker
data.BD_target = best_target
data.BD_weapon = best_weapon
end

return cfg.ca_score
end

function ca_bottleneck_attack:execution(ai, cfg, self)
if self.data.BD_bottleneck_attacks_done then
function ca_bottleneck_attack:execution(cfg, data)
if data.BD_bottleneck_attacks_done then
local units = AH.get_units_with_attacks { side = wesnoth.current.side }
for _,unit in ipairs(units) do
AH.checked_stopunit_attacks(ai, unit)
end
else
AH.checked_attack(ai, self.data.BD_attacker, self.data.BD_target, self.data.BD_weapon)
AH.checked_attack(ai, data.BD_attacker, data.BD_target, data.BD_weapon)
end

self.data.BD_attacker, self.data.BD_target, self.data.BD_weapon = nil, nil, nil
self.data.BD_bottleneck_attacks_done = nil
data.BD_attacker, data.BD_target, data.BD_weapon = nil, nil, nil
data.BD_bottleneck_attacks_done = nil
end

return ca_bottleneck_attack

0 comments on commit c798740

Please sign in to comment.