Fast Micro AI: fix behavior with attack_hidden_enemies=yes
ai_helper.get_attacks() now excludes hidden enemies by default -> they need to be specifically included if they are to be attacked, as opposed to having to be excluded when not.
This commit is contained in:
parent
cf731dd923
commit
d375321e64
2 changed files with 8 additions and 2 deletions
|
@ -56,6 +56,7 @@ function ca_fast_combat:evaluation(cfg, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Exclude hidden enemies, except if attack_hidden_enemies=yes is set in [micro_ai] tag
|
-- Exclude hidden enemies, except if attack_hidden_enemies=yes is set in [micro_ai] tag
|
||||||
|
local viewing_side = wesnoth.current.side
|
||||||
if (not cfg.attack_hidden_enemies) then
|
if (not cfg.attack_hidden_enemies) then
|
||||||
local hidden_enemies = AH.get_live_units {
|
local hidden_enemies = AH.get_live_units {
|
||||||
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
|
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
|
||||||
|
@ -65,6 +66,8 @@ function ca_fast_combat:evaluation(cfg, data)
|
||||||
for _,e in ipairs(hidden_enemies) do
|
for _,e in ipairs(hidden_enemies) do
|
||||||
enemy_map:remove(e.x, e.y)
|
enemy_map:remove(e.x, e.y)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
viewing_side = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local aggression = ai.aspects.aggression
|
local aggression = ai.aspects.aggression
|
||||||
|
@ -80,7 +83,7 @@ function ca_fast_combat:evaluation(cfg, data)
|
||||||
local unit_copy = FAU.get_unit_copy(unit.id, data.gamedata)
|
local unit_copy = FAU.get_unit_copy(unit.id, data.gamedata)
|
||||||
|
|
||||||
if (unit.attacks_left > 0) and (#unit.attacks > 0) then
|
if (unit.attacks_left > 0) and (#unit.attacks > 0) then
|
||||||
local attacks = AH.get_attacks({ unit }, { include_occupied = cfg.include_occupied_attack_hexes })
|
local attacks = AH.get_attacks({ unit }, { include_occupied = cfg.include_occupied_attack_hexes, viewing_side = viewing_side })
|
||||||
|
|
||||||
if (#attacks > 0) then
|
if (#attacks > 0) then
|
||||||
local max_rating, best_target, best_dst = -9e99
|
local max_rating, best_target, best_dst = -9e99
|
||||||
|
|
|
@ -48,6 +48,7 @@ function ca_fast_combat_leader:evaluation(cfg, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Exclude hidden enemies, except if attack_hidden_enemies=yes is set in [micro_ai] tag
|
-- Exclude hidden enemies, except if attack_hidden_enemies=yes is set in [micro_ai] tag
|
||||||
|
local viewing_side = wesnoth.current.side
|
||||||
if (not cfg.attack_hidden_enemies) then
|
if (not cfg.attack_hidden_enemies) then
|
||||||
local hidden_enemies = AH.get_live_units {
|
local hidden_enemies = AH.get_live_units {
|
||||||
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
|
{ "filter_side", { { "enemy_of", { side = wesnoth.current.side } } } },
|
||||||
|
@ -57,6 +58,8 @@ function ca_fast_combat_leader:evaluation(cfg, data)
|
||||||
for _,e in ipairs(hidden_enemies) do
|
for _,e in ipairs(hidden_enemies) do
|
||||||
enemy_map:remove(e.x, e.y)
|
enemy_map:remove(e.x, e.y)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
viewing_side = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local aggression = ai.aspects.aggression
|
local aggression = ai.aspects.aggression
|
||||||
|
@ -114,7 +117,7 @@ function ca_fast_combat_leader:evaluation(cfg, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local attacks = AH.get_attacks({ leader }, { include_occupied = cfg.include_occupied_attack_hexes })
|
local attacks = AH.get_attacks({ leader }, { include_occupied = cfg.include_occupied_attack_hexes, viewing_side = viewing_side })
|
||||||
|
|
||||||
if (#attacks > 0) then
|
if (#attacks > 0) then
|
||||||
local max_rating, best_target, best_dst = -9e99
|
local max_rating, best_target, best_dst = -9e99
|
||||||
|
|
Loading…
Add table
Reference in a new issue