Patrol MAI [micro_ai] tag: add optional [filter] tag
This commit is contained in:
parent
f66e2b1763
commit
0670630ff9
2 changed files with 27 additions and 5 deletions
|
@ -4,15 +4,34 @@ local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
|||
local ca_patrol = {}
|
||||
|
||||
function ca_patrol:evaluation(ai, cfg)
|
||||
local patrol = wesnoth.get_units({ id = cfg.id })[1]
|
||||
local patrol
|
||||
if cfg.filter then
|
||||
patrol = wesnoth.get_units({
|
||||
side = wesnoth.current.side,
|
||||
{ "and", cfg.filter },
|
||||
formula = '$this_unit.moves > 0' }
|
||||
)[1]
|
||||
else
|
||||
patrol = wesnoth.get_units({ id = cfg.id, formula = '$this_unit.moves > 0' })[1]
|
||||
end
|
||||
|
||||
-- Check if unit exists as sticky BCAs are not always removed successfully
|
||||
if patrol and (patrol.moves > 0) then return cfg.ca_score end
|
||||
if patrol then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
function ca_patrol:execution(ai, cfg, self)
|
||||
local patrol = wesnoth.get_units( { id = cfg.id } )[1]
|
||||
local patrol
|
||||
if cfg.filter then
|
||||
patrol = wesnoth.get_units({
|
||||
side = wesnoth.current.side,
|
||||
{ "and", cfg.filter },
|
||||
formula = '$this_unit.moves > 0' }
|
||||
)[1]
|
||||
else
|
||||
patrol = wesnoth.get_units({ id = cfg.id, formula = '$this_unit.moves > 0' })[1]
|
||||
end
|
||||
|
||||
cfg.waypoint_x = AH.split(cfg.waypoint_x, ",")
|
||||
cfg.waypoint_y = AH.split(cfg.waypoint_y, ",")
|
||||
|
||||
|
|
|
@ -408,8 +408,11 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
|
||||
--------- Patrol Micro AI ------------------------------------
|
||||
elseif (cfg.ai_type == 'patrol') then
|
||||
required_keys = { "id", "waypoint_x", "waypoint_y" }
|
||||
optional_keys = { "attack", "one_time_only", "out_and_back" }
|
||||
if (not cfg.id) and (not H.get_child(cfg, "filter")) then
|
||||
H.wml_error("Patrol [micro_ai] tag requires either id= key or [filter] tag")
|
||||
end
|
||||
required_keys = { "waypoint_x", "waypoint_y" }
|
||||
optional_keys = { "id", "filter", "attack", "one_time_only", "out_and_back" }
|
||||
CA_parms = { { ca_id = "mai_patrol", location = 'ai/micro_ais/cas/ca_patrol.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
--------- Recruiting Micro AI ------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue