Micro AIs: use ai_helper.get_avoid_map()
There are no functionality changes in this commit, it's simply switching over to the new ai_helper function. Changes to the MAI functionalities will be added separately.
This commit is contained in:
parent
ae22b2e08f
commit
10b0631143
6 changed files with 7 additions and 44 deletions
|
@ -1,5 +1,4 @@
|
|||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local T = wml.tag
|
||||
local M = wesnoth.map
|
||||
|
||||
|
@ -16,20 +15,6 @@ local M = wesnoth.map
|
|||
|
||||
local ca_fast_attack_utils = {}
|
||||
|
||||
function ca_fast_attack_utils.get_avoid_map(cfg)
|
||||
-- Get map of locations to be avoided.
|
||||
-- Use [micro_ai][avoid] tag with priority over [ai][avoid].
|
||||
-- If neither is given, return an empty location set.
|
||||
|
||||
local avoid_tag = wml.get_child(cfg, "avoid")
|
||||
|
||||
if not avoid_tag then
|
||||
return LS.of_pairs(ai.aspects.avoid)
|
||||
end
|
||||
|
||||
return LS.of_pairs(wesnoth.get_locations(avoid_tag))
|
||||
end
|
||||
|
||||
local function attack_filter(which, filter, is_leader)
|
||||
if (is_leader == nil) then is_leader = false end
|
||||
if (which == 'leader') then
|
||||
|
|
|
@ -76,7 +76,7 @@ function ca_fast_combat:evaluation(cfg, data)
|
|||
if (aggression > 1) then aggression = 1 end
|
||||
|
||||
-- Get the locations to be avoided
|
||||
local avoid_map = FAU.get_avoid_map(cfg)
|
||||
local avoid_map = AH.get_avoid_map(ai, wml.get_child(cfg, "avoid"), true)
|
||||
|
||||
for i = #fast_combat_units,1,-1 do
|
||||
local unit = fast_combat_units[i]
|
||||
|
|
|
@ -69,7 +69,7 @@ function ca_fast_combat_leader:evaluation(cfg, data)
|
|||
if (aggression > 1) then aggression = 1 end
|
||||
|
||||
-- Get the locations to be avoided
|
||||
local avoid_map = FAU.get_avoid_map(cfg)
|
||||
local avoid_map = AH.get_avoid_map(ai, wml.get_child(cfg, "avoid"), true)
|
||||
|
||||
-- Enemy power and number maps
|
||||
-- Currently, the power is simply the summed hitpoints of all enemies that
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local FAU = wesnoth.require "ai/micro_ais/cas/ca_fast_attack_utils.lua"
|
||||
local M = wesnoth.map
|
||||
|
||||
local ca_fast_move = {}
|
||||
|
@ -16,7 +15,7 @@ function ca_fast_move:execution(cfg)
|
|||
if (move_cost_factor < 1.1) then move_cost_factor = 1.1 end
|
||||
|
||||
-- Get the locations to be avoided
|
||||
local avoid_map = FAU.get_avoid_map(cfg)
|
||||
local avoid_map = AH.get_avoid_map(ai, wml.get_child(cfg, "avoid"), true)
|
||||
|
||||
local all_units_MP = AH.get_units_with_moves { side = wesnoth.current.side, canrecruit = 'no' }
|
||||
local units = {}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
local MAISD = wesnoth.require "ai/micro_ais/micro_ai_self_data.lua"
|
||||
local M = wesnoth.map
|
||||
|
@ -55,28 +54,8 @@ function ca_hang_out:execution(cfg)
|
|||
-- Use [micro_ai][avoid] tag with priority over [ai][avoid].
|
||||
-- If neither is given, default to all castle terrain.
|
||||
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 = wml.get_child(wesnoth.sides[wesnoth.current.side].__cfg, 'ai')
|
||||
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
|
||||
-- If there's a [facet] child, it's set as a composite aspect,
|
||||
-- with at least one facet.
|
||||
-- But it might not be a composite aspect; it could be
|
||||
-- a Lua aspect or a standard aspect.
|
||||
avoid_map = LS.of_pairs(ai.aspects.avoid)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if not avoid_map then
|
||||
avoid_map = LS.of_pairs(wesnoth.get_locations { terrain = 'C*,C*^*,*^C*' })
|
||||
end
|
||||
local default_avoid_tag = { terrain = 'C*,C*^*,*^C*' }
|
||||
local avoid_map = AH.get_avoid_map(ai, avoid_tag, true, default_avoid_tag)
|
||||
|
||||
local max_rating, best_hex, best_unit = - math.huge
|
||||
for _,unit in ipairs(units) do
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
local LS = wesnoth.require "location_set"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local M = wesnoth.map
|
||||
|
@ -61,7 +60,8 @@ function ca_healer_move:evaluation(cfg, data)
|
|||
local enemy_attack_map = BC.get_attack_map(enemies)
|
||||
for _,healee in ipairs(healees_MP) do healee:to_map() end
|
||||
|
||||
local avoid_map = LS.of_pairs(ai.aspects.avoid)
|
||||
-- Other options of adding avoid zones may be added later
|
||||
local avoid_map = AH.get_avoid_map(ai, nil, true)
|
||||
|
||||
local max_rating = - math.huge
|
||||
for _,healer in ipairs(healers) do
|
||||
|
|
Loading…
Add table
Reference in a new issue