Update Micro AIs to use new Lua API functions for altering AI
This commit is contained in:
parent
55481c9949
commit
0f01f97b30
7 changed files with 49 additions and 142 deletions
|
@ -12,25 +12,18 @@ function ca_healer_initialize:evaluation()
|
|||
end
|
||||
|
||||
function ca_healer_initialize:execution(cfg, data)
|
||||
W.modify_ai {
|
||||
side = wesnoth.current.side,
|
||||
action = "try_delete",
|
||||
path = "aspect[attacks].facet[no_healers_attack]"
|
||||
}
|
||||
W.delete_ai_component(wesnoth.current.side, "aspect[attacks].facet[no_healers_attack]")
|
||||
|
||||
W.modify_ai {
|
||||
side = wesnoth.current.side,
|
||||
action = "add",
|
||||
path = "aspect[attacks].facet",
|
||||
{ "facet", {
|
||||
W.add_ai_component(wesnoth.current.side, "aspect[attacks].facet",
|
||||
{
|
||||
name = "ai_default_rca::aspect_attacks",
|
||||
id = "no_healers_attack",
|
||||
invalidate_on_gamestate_change = "yes",
|
||||
{ "filter_own", {
|
||||
{ "not", { ability = "healing", { "and", H.get_child(cfg, "filter") } } }
|
||||
} }
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
-- We also need to set the score of healer moves to happen after
|
||||
-- combat (of other units) at beginning of turn
|
||||
|
|
|
@ -12,11 +12,7 @@ function ca_healer_may_attack:evaluation()
|
|||
end
|
||||
|
||||
function ca_healer_may_attack:execution(cfg, data)
|
||||
W.modify_ai {
|
||||
side = wesnoth.current.side,
|
||||
action = "try_delete",
|
||||
path = "aspect[attacks].facet[no_healers_attack]"
|
||||
}
|
||||
W.delete_ai_component(wesnoth.current.side, "aspect[attacks].facet[no_healers_attack]")
|
||||
|
||||
-- Once combat (by other units) is done, set the healer move score so that it
|
||||
-- now happens before combat (of the healers which were so far excluded from combat)
|
||||
|
|
|
@ -39,44 +39,26 @@ return {
|
|||
end
|
||||
|
||||
-- Always delete the attacks aspect first, so that we do not end up with 100 copies of the facet
|
||||
W.modify_ai {
|
||||
side = wesnoth.current.side,
|
||||
action = "try_delete",
|
||||
path = "aspect[attacks].facet[limited_attack]"
|
||||
}
|
||||
W.delete_ai_component(wesnoth.current.side, "aspect[attacks].facet[limited_attack]")
|
||||
|
||||
-- Also delete aggression, caution - for the same reason
|
||||
W.modify_ai {
|
||||
side = wesnoth.current.side,
|
||||
action = "try_delete",
|
||||
path = "aspect[aggression].facet[*]"
|
||||
}
|
||||
W.modify_ai {
|
||||
side = wesnoth.current.side,
|
||||
action = "try_delete",
|
||||
path = "aspect[caution].facet[*]"
|
||||
}
|
||||
W.delete_ai_component(wesnoth.current.side, "aspect[aggression].facet[*]")
|
||||
W.delete_ai_component(wesnoth.current.side, "aspect[caution].facet[*]")
|
||||
|
||||
-- If the target can be attacked, set the attacks aspect accordingly
|
||||
if attack_locs[1] then
|
||||
W.modify_ai {
|
||||
side = wesnoth.current.side,
|
||||
action = "add",
|
||||
path = "aspect[attacks].facet",
|
||||
{ "facet", {
|
||||
W.add_ai_component(wesnoth.current.side, "aspect[attacks].facet",
|
||||
{
|
||||
name = "ai_default_rca::aspect_attacks",
|
||||
id = "limited_attack",
|
||||
invalidate_on_gamestate_change = "yes",
|
||||
{ "filter_enemy", { id = target_id } }
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
-- We also want to set aggression=1 and caution=0,
|
||||
-- otherwise there could be turns on which nothing happens
|
||||
W.modify_side {
|
||||
side = wesnoth.current.side,
|
||||
{ "ai", { aggression = 1, caution = 0 } }
|
||||
}
|
||||
W.append_ai{ aggression = 1, caution = 0 }
|
||||
end
|
||||
|
||||
return 0
|
||||
|
|
|
@ -18,69 +18,49 @@ function wesnoth.micro_ais.fast_ai(cfg)
|
|||
-- Also need to delete/add some default CAs
|
||||
if (cfg.action == 'delete') then
|
||||
-- This can be done independently of whether these were removed earlier
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "add",
|
||||
path = "stage[main_loop].candidate_action",
|
||||
{ "candidate_action", {
|
||||
W.add_ai_component(cfg.side, "stage[main_loop].candidate_action",
|
||||
{
|
||||
id="combat",
|
||||
engine="cpp",
|
||||
name="ai_default_rca::combat_phase",
|
||||
max_score=100000,
|
||||
score=100000
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "add",
|
||||
path = "stage[main_loop].candidate_action",
|
||||
{ "candidate_action", {
|
||||
W.add_ai_component(cfg.side, "stage[main_loop].candidate_action",
|
||||
{
|
||||
id="villages",
|
||||
engine="cpp",
|
||||
name="ai_default_rca::get_villages_phase",
|
||||
max_score=60000,
|
||||
score=60000
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "add",
|
||||
path = "stage[main_loop].candidate_action",
|
||||
{ "candidate_action", {
|
||||
W.add_ai_component(cfg.side, "stage[main_loop].candidate_action",
|
||||
{
|
||||
id="retreat",
|
||||
engine="cpp",
|
||||
name="ai_default_rca::retreat_phase",
|
||||
max_score=40000,
|
||||
score=40000
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "add",
|
||||
path = "stage[main_loop].candidate_action",
|
||||
{ "candidate_action", {
|
||||
W.add_ai_component(cfg.side, "stage[main_loop].candidate_action",
|
||||
{
|
||||
id="move_to_targets",
|
||||
engine="cpp",
|
||||
name="ai_default_rca::move_to_targets_phase",
|
||||
max_score=20000,
|
||||
score=20000
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
else
|
||||
if (not cfg.skip_combat_ca) then
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "try_delete",
|
||||
path = "stage[main_loop].candidate_action[high_xp_attack]"
|
||||
}
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "try_delete",
|
||||
path = "stage[main_loop].candidate_action[combat]"
|
||||
}
|
||||
W.delete_ai_component(cfg.side, "stage[main_loop].candidate_action[high_xp_attack]")
|
||||
W.delete_ai_component(cfg.side, "stage[main_loop].candidate_action[combat]")
|
||||
else
|
||||
for i,parm in ipairs(CA_parms) do
|
||||
if (parm.ca_id == 'combat') or (parm.ca_id == 'combat_leader') then
|
||||
|
@ -90,23 +70,11 @@ function wesnoth.micro_ais.fast_ai(cfg)
|
|||
end
|
||||
|
||||
if (not cfg.skip_move_ca) then
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "try_delete",
|
||||
path = "stage[main_loop].candidate_action[villages]"
|
||||
}
|
||||
W.delete_ai_component(cfg.side, "stage[main_loop].candidate_action[villages]")
|
||||
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "try_delete",
|
||||
path = "stage[main_loop].candidate_action[retreat]"
|
||||
}
|
||||
W.delete_ai_component(cfg.side, "stage[main_loop].candidate_action[retreat]")
|
||||
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "try_delete",
|
||||
path = "stage[main_loop].candidate_action[move_to_targets]"
|
||||
}
|
||||
W.delete_ai_component(cfg.side, "stage[main_loop].candidate_action[move_to_targets]")
|
||||
else
|
||||
for i,parm in ipairs(CA_parms) do
|
||||
if (parm.ca_id == 'move') then
|
||||
|
|
|
@ -28,11 +28,7 @@ function wesnoth.micro_ais.protect_unit(cfg)
|
|||
-- Optional key disable_move_leader_to_keep: needs to be dealt with
|
||||
-- separately as it affects a default CA
|
||||
if cfg.disable_move_leader_to_keep then
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "try_delete",
|
||||
path = "stage[main_loop].candidate_action[move_leader_to_keep]"
|
||||
}
|
||||
W.delete_ai_component(cfg.side, "stage[main_loop].candidate_action[move_leader_to_keep]")
|
||||
end
|
||||
|
||||
-- attacks aspects also needs to be set separately
|
||||
|
@ -56,18 +52,15 @@ function wesnoth.micro_ais.protect_unit(cfg)
|
|||
MAIH.delete_aspects(cfg.side, aspect_parms)
|
||||
-- We also need to add the move_leader_to_keep CA back in
|
||||
-- This works even if it was not removed, it simply overwrites the existing CA
|
||||
W.modify_ai {
|
||||
side = side,
|
||||
action = "add",
|
||||
path = "stage[main_loop].candidate_action",
|
||||
{ "candidate_action", {
|
||||
W.add_ai_component(side, "stage[main_loop].candidate_action",
|
||||
{
|
||||
id="move_leader_to_keep",
|
||||
engine="cpp",
|
||||
name="ai_default_rca::move_leader_to_keep_phase",
|
||||
max_score=160000,
|
||||
score=160000
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
else
|
||||
MAIH.add_aspects(cfg.side, aspect_parms)
|
||||
end
|
||||
|
|
|
@ -4,26 +4,19 @@ local W = H.set_wml_action_metatable {}
|
|||
local function handle_default_recruitment(cfg)
|
||||
-- Also need to delete/add the default recruitment CA
|
||||
if cfg.action == 'add' then
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "try_delete",
|
||||
path = "stage[main_loop].candidate_action[recruitment]"
|
||||
}
|
||||
W.delete_ai_component(cfg.side, "stage[main_loop].candidate_action[recruitment]")
|
||||
elseif cfg.action == 'delete' then
|
||||
-- We need to add the recruitment CA back in
|
||||
-- This works even if it was not removed, it simply overwrites the existing CA
|
||||
W.modify_ai {
|
||||
side = cfg.side,
|
||||
action = "add",
|
||||
path = "stage[main_loop].candidate_action",
|
||||
{ "candidate_action", {
|
||||
W.add_ai_component(cfg.side, "stage[main_loop].candidate_action",
|
||||
{
|
||||
id="recruitment",
|
||||
engine="cpp",
|
||||
name="ai_default_rca::aspect_recruitment_phase",
|
||||
max_score=180000,
|
||||
score=180000
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -93,12 +93,7 @@ function micro_ai_helper.add_CAs(side, ca_id_core, CA_parms, CA_cfg)
|
|||
CA.location = parms.location
|
||||
table.insert(CA, T.args(CA_cfg))
|
||||
|
||||
W.modify_ai {
|
||||
side = side,
|
||||
action = "add",
|
||||
path = "stage[main_loop].candidate_action",
|
||||
T.candidate_action(CA)
|
||||
}
|
||||
W.add_ai_component(side, "stage[main_loop].candidate_action", CA)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,11 +110,7 @@ function micro_ai_helper.delete_CAs(side, ca_id_core, CA_parms)
|
|||
for _,parms in ipairs(CA_parms) do
|
||||
local ca_id = ca_id_core .. '_' .. parms.ca_id
|
||||
|
||||
W.modify_ai {
|
||||
side = side,
|
||||
action = "try_delete",
|
||||
path = "stage[main_loop].candidate_action[" .. ca_id .. "]"
|
||||
}
|
||||
W.delete_ai_component(side, "stage[main_loop].candidate_action[" .. ca_id .. "]")
|
||||
|
||||
-- Also need to delete variable stored in all units of the side, so that later MAIs can use these units
|
||||
local units = wesnoth.get_units { side = side }
|
||||
|
@ -151,12 +142,7 @@ function micro_ai_helper.add_aspects(side, aspect_parms)
|
|||
-- }
|
||||
|
||||
for _,parms in ipairs(aspect_parms) do
|
||||
W.modify_ai {
|
||||
side = side,
|
||||
action = "add",
|
||||
path = "aspect[" .. parms.aspect .. "].facet",
|
||||
T.facet(parms.facet)
|
||||
}
|
||||
W.add_ai_component(side, "aspect[" .. parms.aspect .. "].facet", parms.facet)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -167,11 +153,7 @@ function micro_ai_helper.delete_aspects(side, aspect_parms)
|
|||
-- aspect_parms.aspect_id field is needed
|
||||
|
||||
for _,parms in ipairs(aspect_parms) do
|
||||
W.modify_ai {
|
||||
side = side,
|
||||
action = "try_delete",
|
||||
path = "aspect[attacks].facet[" .. parms.facet.id .. "]"
|
||||
}
|
||||
W.delete_ai_component(side, "aspect[attacks].facet[" .. parms.facet.id .. "]")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue