Skip to content

Commit

Permalink
Fast Micro AI: add [filter] and [filter_second] tags
Browse files Browse the repository at this point in the history
These can be used to limit the attackers and attack targets in the same
way as the ‘attacks’ facet does with [filter_own] and [filter_enemy]
for the default AI combat candidate action.
This does not affect the move-to-targets candidate action of the Fast
Micro AI.
  • Loading branch information
mattsc authored and mattsc committed Sep 4, 2015
1 parent 656f288 commit 4b589ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 18 additions & 2 deletions data/ai/micro_ais/cas/ca_fast_combat.lua
Expand Up @@ -10,7 +10,10 @@ function ca_fast_combat:evaluation(ai, cfg, self)
self.data.gamedata = FAU.gamedata_setup()

if (not self.data.fast_combat_units) or (not self.data.fast_combat_units[1]) then
self.data.fast_combat_units = wesnoth.get_units { side = wesnoth.current.side }
self.data.fast_combat_units = wesnoth.get_units {
side = wesnoth.current.side,
{ "and", cfg.filter }
}
if (not self.data.fast_combat_units[1]) then return 0 end

-- For speed reasons, we'll go through the arrays from the end, so they are sorted backwards
Expand All @@ -21,8 +24,21 @@ function ca_fast_combat:evaluation(ai, cfg, self)
end
end

-- Exclude hidden enemies, except if attack_hidden_enemies=yes is set in [micro_ai] tag
local excluded_enemies_map = LS.create()

-- Exclude enemies not matching [filter_second]
if (cfg.filter_second) then
local excluded_enemies = wesnoth.get_units {
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
{ "not", cfg.filter_second }
}

for _,e in ipairs(excluded_enemies) do
excluded_enemies_map:insert(e.x, e.y)
end
end

-- Exclude hidden enemies, except if attack_hidden_enemies=yes is set in [micro_ai] tag
if (not cfg.attack_hidden_enemies) then
local hidden_enemies = wesnoth.get_units {
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
Expand Down
3 changes: 2 additions & 1 deletion data/ai/micro_ais/micro_ai_wml_tag.lua
Expand Up @@ -460,7 +460,8 @@ function wesnoth.wml_actions.micro_ai(cfg)

elseif (cfg.ai_type == 'fast_ai') then
optional_keys = {
"attack_hidden_enemies", "dungeon_mode", "include_occupied_attack_hexes", "move_cost_factor",
"attack_hidden_enemies", "dungeon_mode", "filter", "filter_second",
"include_occupied_attack_hexes", "move_cost_factor",
"weak_units_first", "skip_combat_ca", "skip_move_ca"
}
CA_parms = {
Expand Down

0 comments on commit 4b589ba

Please sign in to comment.