Swarm Micro AI: add [avoid] tag functionality

This includes both adding an [avoid] tag to the MAI itself, and taking the default AI [avoid] tag into account. If both are given, the former takes precedence over the latter.
This commit is contained in:
mattsc 2018-11-01 18:05:17 -07:00
parent 7579d181c0
commit abaa2dcc84
3 changed files with 8 additions and 5 deletions

View file

@ -29,6 +29,8 @@ function ca_swarm_move:execution(cfg)
local enemies = AH.get_attackable_enemies()
local avoid_map = AH.get_avoid_map(ai, wml.get_child(cfg, "avoid"), true)
-- Pick one unit at random, swarm does not move systematically
local unit = units[math.random(#units)]
@ -62,9 +64,9 @@ function ca_swarm_move:execution(cfg)
end
return rating
end)
end, { avoid_map = avoid_map })
AH.movefull_stopunit(ai, unit, best_hex)
AH.movefull_stopunit(ai, unit, best_hex or { unit.x, unit.y })
end
return ca_swarm_move

View file

@ -27,6 +27,7 @@ function ca_swarm_scatter:execution(cfg)
local enemies = get_enemies(cfg)
local units = get_swarm_units(cfg)
local vision_distance = cfg.vision_distance or 12
local avoid_map = AH.get_avoid_map(ai, wml.get_child(cfg, "avoid"), true)
-- In this case we simply maximize the distance from all these close enemies
-- but only for units that are within 'vision_distance' of one of those enemies
@ -45,9 +46,9 @@ function ca_swarm_scatter:execution(cfg)
rating = rating + M.distance_between(x, y, enemy.x, enemy.y)
end
return rating
end)
end, { avoid_map = avoid_map })
AH.movefull_stopunit(ai, unit, best_hex)
AH.movefull_stopunit(ai, unit, best_hex or { unit.x, unit.y })
-- Reconsider, as situation on the map might have changed
return

View file

@ -143,7 +143,7 @@ function wesnoth.micro_ais.forest_animals(cfg)
end
function wesnoth.micro_ais.swarm(cfg)
local optional_keys = { "scatter_distance", "vision_distance", "enemy_distance" }
local optional_keys = { "[avoid]", "scatter_distance", "vision_distance", "enemy_distance" }
local score = cfg.ca_score or 300000
local CA_parms = {
ai_id = 'mai_swarm',