Move path to Micro AI candidate actions files into variable
The purpose of this commit (and the previous) is to make it easier for UMC authors to add functionality to the Micro AIs.
This commit is contained in:
parent
5df117161a
commit
f417faa2d5
1 changed files with 41 additions and 40 deletions
|
@ -57,20 +57,21 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
|
||||
-- Set up the configuration tables for the different Micro AIs
|
||||
local required_keys, optional_keys, CA_parms = {}, {}, {}
|
||||
local CA_path = 'ai/micro_ais/cas/'
|
||||
|
||||
--------- Healer Support Micro AI ------------------------------------
|
||||
if (cfg.ai_type == 'healer_support') then
|
||||
optional_keys = { "aggression", "injured_units_only", "max_threats", "filter", "filter_second" }
|
||||
-- Scores for this AI need to be hard-coded, it does not work otherwise
|
||||
CA_parms = {
|
||||
{ ca_id = 'mai_healer_initialize', location = 'ai/micro_ais/cas/ca_healer_initialize.lua', score = 999990 },
|
||||
{ ca_id = 'mai_healer_move', location = 'ai/micro_ais/cas/ca_healer_move.lua', score = 105000 },
|
||||
{ ca_id = 'mai_healer_initialize', location = CA_path .. 'ca_healer_initialize.lua', score = 999990 },
|
||||
{ ca_id = 'mai_healer_move', location = CA_path .. 'ca_healer_move.lua', score = 105000 },
|
||||
}
|
||||
|
||||
-- The healers_can_attack CA is only added to the table if aggression ~= 0
|
||||
-- But: make sure we always try removal
|
||||
if (cfg.action == 'delete') or (tonumber(cfg.aggression) ~= 0) then
|
||||
table.insert(CA_parms, { ca_id = 'mai_healer_may_attack', location = 'ai/micro_ais/cas/ca_healer_may_attack.lua', score = 99990 })
|
||||
table.insert(CA_parms, { ca_id = 'mai_healer_may_attack', location = CA_path .. 'ca_healer_may_attack.lua', score = 99990 })
|
||||
end
|
||||
|
||||
--------- Bottleneck Defense Micro AI -----------------------------------
|
||||
|
@ -79,8 +80,8 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
optional_keys = { "healer_x", "healer_y", "leadership_x", "leadership_y", "active_side_leader" }
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = 'mai_bottleneck_move', location = 'ai/micro_ais/cas/ca_bottleneck_move.lua', score = score },
|
||||
{ ca_id = 'mai_bottleneck_attack', location = 'ai/micro_ais/cas/ca_bottleneck_attack.lua', score = score - 1 }
|
||||
{ ca_id = 'mai_bottleneck_move', location = CA_path .. 'ca_bottleneck_move.lua', score = score },
|
||||
{ ca_id = 'mai_bottleneck_attack', location = CA_path .. 'ca_bottleneck_attack.lua', score = score - 1 }
|
||||
}
|
||||
|
||||
--------- Messenger Escort Micro AI ------------------------------------
|
||||
|
@ -89,25 +90,25 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
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 },
|
||||
{ ca_id = 'mai_messenger_move', location = 'ai/micro_ais/cas/ca_messenger_move.lua', score = score - 1 },
|
||||
{ ca_id = 'mai_messenger_escort_move', location = 'ai/micro_ais/cas/ca_messenger_escort_move.lua', score = score - 2 }
|
||||
{ ca_id = 'mai_messenger_attack', location = CA_path .. 'ca_messenger_attack.lua', score = score },
|
||||
{ ca_id = 'mai_messenger_move', location = CA_path .. 'ca_messenger_move.lua', score = score - 1 },
|
||||
{ ca_id = 'mai_messenger_escort_move', location = CA_path .. 'ca_messenger_escort_move.lua', score = score - 2 }
|
||||
}
|
||||
|
||||
--------- Lurkers Micro AI ------------------------------------
|
||||
elseif (cfg.ai_type == 'lurkers') then
|
||||
required_keys = { "filter", "filter_location" }
|
||||
optional_keys = { "stationary", "filter_location_wander" }
|
||||
CA_parms = { { ca_id = 'mai_lurkers', location = 'ai/micro_ais/cas/ca_lurkers.lua', score = cfg.ca_score or 300000 } }
|
||||
CA_parms = { { ca_id = 'mai_lurkers', location = CA_path .. 'ca_lurkers.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
--------- Protect Unit Micro AI ------------------------------------
|
||||
elseif (cfg.ai_type == 'protect_unit') then
|
||||
required_keys = { "id", "goal_x", "goal_y" }
|
||||
-- Scores for this AI need to be hard-coded, it does not work otherwise
|
||||
CA_parms = {
|
||||
{ ca_id = 'mai_protect_unit_finish', location = 'ai/micro_ais/cas/ca_protect_unit_finish.lua', score = 300000 },
|
||||
{ ca_id = 'mai_protect_unit_attack', location = 'ai/micro_ais/cas/ca_protect_unit_attack.lua', score = 95000 },
|
||||
{ ca_id = 'mai_protect_unit_move', location = 'ai/micro_ais/cas/ca_protect_unit_move.lua', score = 94999 }
|
||||
{ ca_id = 'mai_protect_unit_finish', location = CA_path .. 'ca_protect_unit_finish.lua', score = 300000 },
|
||||
{ ca_id = 'mai_protect_unit_attack', location = CA_path .. 'ca_protect_unit_attack.lua', score = 95000 },
|
||||
{ ca_id = 'mai_protect_unit_move', location = CA_path .. 'ca_protect_unit_move.lua', score = 94999 }
|
||||
}
|
||||
|
||||
-- [unit] tags need to be dealt with separately
|
||||
|
@ -191,7 +192,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
end
|
||||
required_keys = { "distance", "station_x", "station_y", "guard_x", "guard_y" }
|
||||
optional_keys = { "id", "filter" }
|
||||
CA_parms = { { ca_id = 'mai_stationed_guardian', location = 'ai/micro_ais/cas/ca_stationed_guardian.lua', score = cfg.ca_score or 300000 } }
|
||||
CA_parms = { { ca_id = 'mai_stationed_guardian', location = CA_path .. 'ca_stationed_guardian.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
elseif (cfg.ai_type == 'zone_guardian') then
|
||||
if (not cfg.id) and (not H.get_child(cfg, "filter")) then
|
||||
|
@ -199,7 +200,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
end
|
||||
required_keys = { "filter_location" }
|
||||
optional_keys = { "id", "filter", "filter_location_enemy", "station_x", "station_y" }
|
||||
CA_parms = { { ca_id = 'mai_zone_guardian', location = 'ai/micro_ais/cas/ca_zone_guardian.lua', score = cfg.ca_score or 300000 } }
|
||||
CA_parms = { { ca_id = 'mai_zone_guardian', location = CA_path .. 'ca_zone_guardian.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
elseif (cfg.ai_type == 'return_guardian') then
|
||||
if (not cfg.id) and (not H.get_child(cfg, "filter")) then
|
||||
|
@ -207,7 +208,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
end
|
||||
required_keys = { "return_x", "return_y" }
|
||||
optional_keys = { "id", "filter" }
|
||||
CA_parms = { { ca_id = 'mai_return_guardian', location = 'ai/micro_ais/cas/ca_return_guardian.lua', score = cfg.ca_score or 100010 } }
|
||||
CA_parms = { { ca_id = 'mai_return_guardian', location = CA_path .. 'ca_return_guardian.lua', score = cfg.ca_score or 100010 } }
|
||||
|
||||
elseif (cfg.ai_type == 'coward') then
|
||||
if (not cfg.id) and (not H.get_child(cfg, "filter")) then
|
||||
|
@ -215,21 +216,21 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
end
|
||||
required_keys = { "distance" }
|
||||
optional_keys = { "id", "filter", "filter_second", "seek_x", "seek_y","avoid_x","avoid_y" }
|
||||
CA_parms = { { ca_id = 'mai_coward', location = 'ai/micro_ais/cas/ca_coward.lua', score = cfg.ca_score or 300000 } }
|
||||
CA_parms = { { ca_id = 'mai_coward', location = CA_path .. 'ca_coward.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
--------- Micro AI Animals ------------------------------------
|
||||
elseif (cfg.ai_type == 'big_animals') then
|
||||
required_keys = { "filter"}
|
||||
optional_keys = { "avoid_unit", "filter_location", "filter_location_wander" }
|
||||
CA_parms = { { ca_id = "mai_big_animals", location = 'ai/micro_ais/cas/ca_big_animals.lua', score = cfg.ca_score or 300000 } }
|
||||
CA_parms = { { ca_id = "mai_big_animals", location = CA_path .. 'ca_big_animals.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
elseif (cfg.ai_type == 'wolves') then
|
||||
required_keys = { "filter", "filter_second" }
|
||||
optional_keys = { "attack_only_prey", "avoid_type" }
|
||||
local score = cfg.ca_score or 90000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_wolves_move", location = 'ai/micro_ais/cas/ca_wolves_move.lua', score = score },
|
||||
{ ca_id = "mai_wolves_wander", location = 'ai/micro_ais/cas/ca_wolves_wander.lua', score = score - 1 }
|
||||
{ ca_id = "mai_wolves_move", location = CA_path .. 'ca_wolves_move.lua', score = score },
|
||||
{ ca_id = "mai_wolves_wander", location = CA_path .. 'ca_wolves_wander.lua', score = score - 1 }
|
||||
}
|
||||
|
||||
if cfg.attack_only_prey then
|
||||
|
@ -279,12 +280,12 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
optional_keys = { "attention_distance", "attack_distance" }
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_herding_attack_close_enemy", location = 'ai/micro_ais/cas/ca_herding_attack_close_enemy.lua', score = score },
|
||||
{ ca_id = "mai_herding_sheep_runs_enemy", location = 'ai/micro_ais/cas/ca_herding_sheep_runs_enemy.lua', score = score - 1 },
|
||||
{ ca_id = "mai_herding_sheep_runs_dog", location = 'ai/micro_ais/cas/ca_herding_sheep_runs_dog.lua', score = score - 2 },
|
||||
{ ca_id = "mai_herding_herd_sheep", location = 'ai/micro_ais/cas/ca_herding_herd_sheep.lua', score = score - 3 },
|
||||
{ ca_id = "mai_herding_sheep_move", location = 'ai/micro_ais/cas/ca_herding_sheep_move.lua', score = score - 4 },
|
||||
{ ca_id = "mai_herding_dog_move", location = 'ai/micro_ais/cas/ca_herding_dog_move.lua', score = score - 5 }
|
||||
{ ca_id = "mai_herding_attack_close_enemy", location = CA_path .. 'ca_herding_attack_close_enemy.lua', score = score },
|
||||
{ ca_id = "mai_herding_sheep_runs_enemy", location = CA_path .. 'ca_herding_sheep_runs_enemy.lua', score = score - 1 },
|
||||
{ ca_id = "mai_herding_sheep_runs_dog", location = CA_path .. 'ca_herding_sheep_runs_dog.lua', score = score - 2 },
|
||||
{ ca_id = "mai_herding_herd_sheep", location = CA_path .. 'ca_herding_herd_sheep.lua', score = score - 3 },
|
||||
{ ca_id = "mai_herding_sheep_move", location = CA_path .. 'ca_herding_sheep_move.lua', score = score - 4 },
|
||||
{ ca_id = "mai_herding_dog_move", location = CA_path .. 'ca_herding_dog_move.lua', score = score - 5 }
|
||||
}
|
||||
|
||||
elseif (cfg.ai_type == 'forest_animals') then
|
||||
|
@ -293,26 +294,26 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
}
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_forest_animals_new_rabbit", location = 'ai/micro_ais/cas/ca_forest_animals_new_rabbit.lua', score = score },
|
||||
{ ca_id = "mai_forest_animals_tusker_attack", location = 'ai/micro_ais/cas/ca_forest_animals_tusker_attack.lua', score = score - 1 },
|
||||
{ ca_id = "mai_forest_animals_move", location = 'ai/micro_ais/cas/ca_forest_animals_move.lua', score = score - 2 },
|
||||
{ ca_id = "mai_forest_animals_tusklet_move", location = 'ai/micro_ais/cas/ca_forest_animals_tusklet_move.lua', score = score - 3 }
|
||||
{ ca_id = "mai_forest_animals_new_rabbit", location = CA_path .. 'ca_forest_animals_new_rabbit.lua', score = score },
|
||||
{ ca_id = "mai_forest_animals_tusker_attack", location = CA_path .. 'ca_forest_animals_tusker_attack.lua', score = score - 1 },
|
||||
{ ca_id = "mai_forest_animals_move", location = CA_path .. 'ca_forest_animals_move.lua', score = score - 2 },
|
||||
{ ca_id = "mai_forest_animals_tusklet_move", location = CA_path .. 'ca_forest_animals_tusklet_move.lua', score = score - 3 }
|
||||
}
|
||||
|
||||
elseif (cfg.ai_type == 'swarm') then
|
||||
optional_keys = { "scatter_distance", "vision_distance", "enemy_distance" }
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_swarm_scatter", location = 'ai/micro_ais/cas/ca_swarm_scatter.lua', score = score },
|
||||
{ ca_id = "mai_swarm_move", location = 'ai/micro_ais/cas/ca_swarm_move.lua', score = score - 1 }
|
||||
{ ca_id = "mai_swarm_scatter", location = CA_path .. 'ca_swarm_scatter.lua', score = score },
|
||||
{ ca_id = "mai_swarm_move", location = CA_path .. 'ca_swarm_move.lua', score = score - 1 }
|
||||
}
|
||||
|
||||
elseif (cfg.ai_type == 'wolves_multipacks') then
|
||||
optional_keys = { "type", "pack_size", "show_pack_number" }
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_wolves_multipacks_attack", location = 'ai/micro_ais/cas/ca_wolves_multipacks_attack.lua', score = score },
|
||||
{ ca_id = "mai_wolves_multipacks_wander", location = 'ai/micro_ais/cas/ca_wolves_multipacks_wander.lua', score = score - 1 }
|
||||
{ ca_id = "mai_wolves_multipacks_attack", location = CA_path .. 'ca_wolves_multipacks_attack.lua', score = score },
|
||||
{ ca_id = "mai_wolves_multipacks_wander", location = CA_path .. 'ca_wolves_multipacks_wander.lua', score = score - 1 }
|
||||
}
|
||||
|
||||
elseif (cfg.ai_type == 'hunter') then
|
||||
|
@ -321,7 +322,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
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 } }
|
||||
CA_parms = { { ca_id = "mai_hunter", location = CA_path .. 'ca_hunter.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
--------- Patrol Micro AI ------------------------------------
|
||||
elseif (cfg.ai_type == 'patrol') then
|
||||
|
@ -330,17 +331,17 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
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 } }
|
||||
CA_parms = { { ca_id = "mai_patrol", location = CA_path .. 'ca_patrol.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
--------- Recruiting Micro AI ------------------------------------
|
||||
elseif (cfg.ai_type == 'recruit_rushers') or (cfg.ai_type == 'recruit_random')then
|
||||
if (cfg.ai_type == 'recruit_rushers') then
|
||||
optional_keys = { "randomness" }
|
||||
CA_parms = { { ca_id = "mai_rusher_recruit", location = 'ai/micro_ais/cas/ca_recruit_rushers.lua', score = cfg.ca_score or 180000 } }
|
||||
CA_parms = { { ca_id = "mai_rusher_recruit", location = CA_path .. 'ca_recruit_rushers.lua', score = cfg.ca_score or 180000 } }
|
||||
|
||||
else
|
||||
optional_keys = { "skip_low_gold_recruiting", "type", "prob" }
|
||||
CA_parms = { { ca_id = "mai_random_recruit", location = 'ai/micro_ais/cas/ca_recruit_random.lua', score = cfg.ca_score or 180000 } }
|
||||
CA_parms = { { ca_id = "mai_random_recruit", location = CA_path .. 'ca_recruit_random.lua', score = cfg.ca_score or 180000 } }
|
||||
|
||||
-- The 'probability' tags need to be handled separately here
|
||||
cfg.type, cfg.prob = {}, {}
|
||||
|
@ -387,17 +388,17 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
"avoid_enemies", "filter", "ignore_units", "ignore_enemy_at_goal",
|
||||
"release_all_units_at_goal", "release_unit_at_goal", "unique_goals", "use_straight_line"
|
||||
}
|
||||
CA_parms = { { ca_id = 'mai_goto', location = 'ai/micro_ais/cas/ca_goto.lua', score = cfg.ca_score or 300000 } }
|
||||
CA_parms = { { ca_id = 'mai_goto', location = CA_path .. 'ca_goto.lua', score = cfg.ca_score or 300000 } }
|
||||
|
||||
--------- Hang Out Micro AI ------------------------------------
|
||||
elseif (cfg.ai_type == 'hang_out') then
|
||||
optional_keys = { "filter", "filter_location", "avoid", "mobilize_condition", "mobilize_on_gold_less_than" }
|
||||
CA_parms = { { ca_id = 'mai_hang_out', location = 'ai/micro_ais/cas/ca_hang_out.lua', score = cfg.ca_score or 170000 } }
|
||||
CA_parms = { { ca_id = 'mai_hang_out', location = CA_path .. 'ca_hang_out.lua', score = cfg.ca_score or 170000 } }
|
||||
|
||||
--------- Simple Attack Micro AI ---------------------------
|
||||
elseif (cfg.ai_type == 'simple_attack') then
|
||||
optional_keys = { "filter", "filter_second", "weapon" }
|
||||
CA_parms = { { ca_id = 'mai_simple_attack', location = 'ai/micro_ais/cas/ca_simple_attack.lua', score = cfg.ca_score or 110000 } }
|
||||
CA_parms = { { ca_id = 'mai_simple_attack', location = CA_path .. 'ca_simple_attack.lua', score = cfg.ca_score or 110000 } }
|
||||
|
||||
-- If we got here, none of the valid ai_types was specified
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue