Hunter MAI [micro_ai] tag: add optional [filter] tag
This commit is contained in:
parent
08a722e248
commit
b340188038
2 changed files with 25 additions and 8 deletions
|
@ -39,9 +39,16 @@ local function hunter_attack_weakest_adj_enemy(ai, unit)
|
|||
end
|
||||
|
||||
function ca_hunter:evaluation(ai, cfg)
|
||||
local unit = wesnoth.get_units { side = wesnoth.current.side, id = cfg.id,
|
||||
formula = '$this_unit.moves > 0'
|
||||
}[1]
|
||||
local unit
|
||||
if cfg.filter then
|
||||
unit = wesnoth.get_units({
|
||||
side = wesnoth.current.side,
|
||||
{ "and", cfg.filter },
|
||||
formula = '$this_unit.moves > 0' }
|
||||
)[1]
|
||||
else
|
||||
unit = wesnoth.get_units({ id = cfg.id, formula = '$this_unit.moves > 0' })[1]
|
||||
end
|
||||
|
||||
if unit then return cfg.ca_score end
|
||||
return 0
|
||||
|
@ -53,9 +60,16 @@ function ca_hunter:execution(ai, cfg)
|
|||
-- hunting_ground, then retreats to
|
||||
-- position given by 'home_x,home_y' for 'rest_turns' turns, or until fully healed
|
||||
|
||||
local unit = wesnoth.get_units { side = wesnoth.current.side, id = cfg.id,
|
||||
formula = '$this_unit.moves > 0'
|
||||
}[1]
|
||||
local unit
|
||||
if cfg.filter then
|
||||
unit = wesnoth.get_units({
|
||||
side = wesnoth.current.side,
|
||||
{ "and", cfg.filter },
|
||||
formula = '$this_unit.moves > 0' }
|
||||
)[1]
|
||||
else
|
||||
unit = wesnoth.get_units({ id = cfg.id, formula = '$this_unit.moves > 0' })[1]
|
||||
end
|
||||
--print('Hunter: ', unit.id)
|
||||
|
||||
-- If hunting_status is not set for the unit -> default behavior -> hunting
|
||||
|
|
|
@ -416,8 +416,11 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
}
|
||||
|
||||
elseif (cfg.ai_type == 'hunter') then
|
||||
required_keys = { "id", "home_x", "home_y" }
|
||||
optional_keys = { "filter_location", "rest_turns", "show_messages" }
|
||||
if (not cfg.id) and (not H.get_child(cfg, "filter")) then
|
||||
H.wml_error("Hunter [micro_ai] tag requires either id= key or [filter] tag")
|
||||
end
|
||||
required_keys = { "home_x", "home_y" }
|
||||
optional_keys = { "id", "filter", "filter_location", "rest_turns", "show_messages" }
|
||||
CA_parms = { { ca_id = "mai_hunter", location = 'ai/micro_ais/cas/ca_hunter.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
--------- Patrol Micro AI ------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue