Messenger MAI: add optional [filter_second] tag
This allows selection of the escort units.
This commit is contained in:
parent
bfa48aa52b
commit
76bcdae73c
3 changed files with 18 additions and 7 deletions
|
@ -53,7 +53,7 @@ local function messenger_find_enemies_in_way(unit, goal_x, goal_y)
|
|||
return
|
||||
end
|
||||
|
||||
local function messenger_find_clearing_attack(unit, goal_x, goal_y)
|
||||
local function messenger_find_clearing_attack(unit, goal_x, goal_y, cfg)
|
||||
-- Check if an enemy is in the way of the messenger
|
||||
-- If so, find attack that would "clear" that enemy out of the way
|
||||
-- unit: proxy table for the messenger unit
|
||||
|
@ -68,8 +68,11 @@ local function messenger_find_clearing_attack(unit, goal_x, goal_y)
|
|||
--print('Finding attacks on',enemy_in_way.name,enemy_in_way.id)
|
||||
|
||||
-- Find all units that can attack this enemy
|
||||
local my_units = wesnoth.get_units{ side = wesnoth.current.side, formula = '$this_unit.attacks_left > 0',
|
||||
{ "not", { id = unit.id } }
|
||||
local my_units = wesnoth.get_units {
|
||||
side = wesnoth.current.side,
|
||||
formula = '$this_unit.attacks_left > 0',
|
||||
{ "not", { id = unit.id } },
|
||||
{ "and", cfg.filter_second }
|
||||
}
|
||||
|
||||
-- Eliminate units without attacks
|
||||
|
@ -141,7 +144,7 @@ function ca_messenger_attack:evaluation(ai, cfg, self)
|
|||
local x, y = messenger_next_waypoint(messenger, cfg, self)
|
||||
|
||||
-- See if there's an enemy in the way that should be attacked
|
||||
local attack = messenger_find_clearing_attack(messenger, x, y)
|
||||
local attack = messenger_find_clearing_attack(messenger, x, y, cfg)
|
||||
|
||||
if attack then
|
||||
self.data.best_attack = attack
|
||||
|
|
|
@ -10,7 +10,11 @@ function ca_messenger_escort_move:evaluation(ai, cfg)
|
|||
local messenger = wesnoth.get_units{ side = wesnoth.current.side, id = cfg.id }[1]
|
||||
if (not messenger) then return 0 end
|
||||
|
||||
local my_units = wesnoth.get_units{ side = wesnoth.current.side, formula = '$this_unit.moves > 0' }
|
||||
local my_units = wesnoth.get_units {
|
||||
side = wesnoth.current.side,
|
||||
formula = '$this_unit.moves > 0',
|
||||
{ "and", cfg.filter_second }
|
||||
}
|
||||
|
||||
if my_units[1] then
|
||||
return cfg.ca_score
|
||||
|
@ -20,7 +24,11 @@ end
|
|||
|
||||
function ca_messenger_escort_move:execution(ai, cfg)
|
||||
local messenger = wesnoth.get_units{ id = cfg.id }[1]
|
||||
local my_units = wesnoth.get_units{ side = wesnoth.current.side, formula = '$this_unit.moves > 0' }
|
||||
local my_units = wesnoth.get_units {
|
||||
side = wesnoth.current.side,
|
||||
formula = '$this_unit.moves > 0',
|
||||
{ "and", cfg.filter_second }
|
||||
}
|
||||
|
||||
-- Simply move units one at a time
|
||||
local next_unit = my_units[1]
|
||||
|
|
|
@ -207,7 +207,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
--------- Messenger Escort Micro AI ------------------------------------
|
||||
elseif (cfg.ai_type == 'messenger_escort') then
|
||||
required_keys = { "id", "waypoint_x", "waypoint_y" }
|
||||
optional_keys = { "enemy_death_chance", "messenger_death_chance" }
|
||||
optional_keys = { "enemy_death_chance", "filter_second", "messenger_death_chance" }
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = 'mai_messenger_attack', location = 'ai/micro_ais/cas/ca_messenger_attack.lua', score = score },
|
||||
|
|
Loading…
Add table
Reference in a new issue