All Animal MAIs: add optional ca_score parameter
This commit is contained in:
parent
2cd8dea7d9
commit
9b8be208ed
2 changed files with 46 additions and 54 deletions
|
@ -48,7 +48,7 @@ return {
|
|||
formula = '$this_unit.moves > 0'
|
||||
}[1]
|
||||
|
||||
if unit then return 300000 end
|
||||
if unit then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -202,11 +202,8 @@ return {
|
|||
{ "and", cfg.filter_second }
|
||||
}
|
||||
|
||||
if wolves[1] and prey[1] then
|
||||
return 95000
|
||||
else
|
||||
return 0
|
||||
end
|
||||
if wolves[1] and prey[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
function engine:mai_animals_wolves_exec(cfg)
|
||||
|
@ -298,11 +295,8 @@ return {
|
|||
formula = '$this_unit.moves > 0', { "and", cfg.filter }
|
||||
}
|
||||
|
||||
if wolves[1] then
|
||||
return 90000
|
||||
else
|
||||
return 0
|
||||
end
|
||||
if wolves[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
function engine:mai_animals_wolves_wander_exec(cfg)
|
||||
|
@ -494,7 +488,7 @@ return {
|
|||
-- having to do the full attack evaluation for every single move
|
||||
local wolves = wesnoth.get_units { side = wesnoth.current.side, type = unit_type, formula = '$this_unit.attacks_left > 0' }
|
||||
|
||||
if wolves[1] then return 300000 end
|
||||
if wolves[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -679,8 +673,7 @@ return {
|
|||
-- When there's nothing to attack, the wolves wander and regroup into their packs
|
||||
local wolves = wesnoth.get_units { side = wesnoth.current.side, type = unit_type, formula = '$this_unit.moves > 0' }
|
||||
|
||||
if wolves[1] then return 290000 end
|
||||
|
||||
if wolves[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -815,7 +808,7 @@ return {
|
|||
formula = '$this_unit.moves > 0'
|
||||
}
|
||||
|
||||
if units[1] then return 300000 end
|
||||
if units[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -931,7 +924,7 @@ return {
|
|||
if enemies[1] then -- don't use 'formula=' for moves, it's slow
|
||||
local units = wesnoth.get_units { side = wesnoth.current.side }
|
||||
for i,u in ipairs(units) do
|
||||
if (u.moves > 0) then return 300000 end
|
||||
if (u.moves > 0) then return cfg.ca_score end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -982,7 +975,7 @@ return {
|
|||
function engine:mai_animals_move_swarm_eval(cfg)
|
||||
local units = wesnoth.get_units { side = wesnoth.current.side }
|
||||
for i,u in ipairs(units) do
|
||||
if (u.moves > 0) then return 290000 end
|
||||
if (u.moves > 0) then return cfg.ca_score end
|
||||
end
|
||||
|
||||
return 0
|
||||
|
@ -1085,7 +1078,7 @@ return {
|
|||
}
|
||||
local sheep = wesnoth.get_units { side = wesnoth.current.side, {"and", cfg.filter_second} }
|
||||
|
||||
if enemies[1] and dogs[1] and sheep[1] then return 300000 end
|
||||
if enemies[1] and dogs[1] and sheep[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -1205,7 +1198,7 @@ return {
|
|||
}
|
||||
}
|
||||
|
||||
if sheep[1] then return 295000 end
|
||||
if sheep[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -1247,7 +1240,7 @@ return {
|
|||
{ "filter_adjacent", { side = wesnoth.current.side, {"and", cfg.filter} } }
|
||||
}
|
||||
|
||||
if sheep[1] then return 290000 end
|
||||
if sheep[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -1288,7 +1281,7 @@ return {
|
|||
local herding_area = self:mai_animals_herding_area(cfg)
|
||||
for i,s in ipairs(sheep) do
|
||||
-- If a sheep is found outside the herding area, we want to chase it back
|
||||
if (not herding_area:get(s.x, s.y)) then return 280000 end
|
||||
if (not herding_area:get(s.x, s.y)) then return cfg.ca_score end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1363,7 +1356,7 @@ return {
|
|||
function engine:mai_animals_sheep_move_eval(cfg)
|
||||
-- If nothing else is to be done, the sheep do a random move
|
||||
local sheep = wesnoth.get_units { side = wesnoth.current.side, {"and", cfg.filter_second}, formula = '$this_unit.moves > 0' }
|
||||
if sheep[1] then return 270000 end
|
||||
if sheep[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -1407,7 +1400,7 @@ return {
|
|||
formula = '$this_unit.moves > 0',
|
||||
{ "not", { { "filter_adjacent", { side = wesnoth.current.side, {"and", cfg.filter_second} } } } }
|
||||
}
|
||||
if dogs[1] then return 260000 end
|
||||
if dogs[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -1455,7 +1448,7 @@ return {
|
|||
-- If this gets executed, we'll let the CA black-list itself
|
||||
|
||||
if (not cfg.rabbit_type) then return 0 end
|
||||
return 310000
|
||||
return cfg.ca_score
|
||||
end
|
||||
|
||||
function engine:mai_animals_new_rabbit_exec(cfg)
|
||||
|
@ -1526,11 +1519,8 @@ return {
|
|||
}
|
||||
--print('#tuskers, #adj_enemies', #tuskers, #adj_enemies)
|
||||
|
||||
if tuskers[1] and adj_enemies[1] then
|
||||
return 300000
|
||||
else
|
||||
return 0
|
||||
end
|
||||
if tuskers[1] and adj_enemies[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
function engine:mai_animals_tusker_attack_exec(cfg)
|
||||
|
@ -1590,9 +1580,9 @@ return {
|
|||
local all_tuskers = wesnoth.get_units { side = wesnoth.current.side, type = tusker_type }
|
||||
|
||||
-- If there are deer, rabbits or tuskers with moves left -> good
|
||||
if units[1] then return 290000 end
|
||||
if units[1] then return cfg.ca_score end
|
||||
-- Or, we move tusklets with this CA, if no tuskers are left (counting those without moves also)
|
||||
if (not all_tuskers[1]) and tusklets[1] then return 290000 end
|
||||
if (not all_tuskers[1]) and tusklets[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -1749,11 +1739,8 @@ return {
|
|||
local tusklets = wesnoth.get_units { side = wesnoth.current.side, type = cfg.tusklet_type, formula = '$this_unit.moves > 0' }
|
||||
local tuskers = wesnoth.get_units { side = wesnoth.current.side, type = cfg.tusker_type }
|
||||
|
||||
if tusklets[1] and tuskers[1] then
|
||||
return 280000
|
||||
else
|
||||
return 0
|
||||
end
|
||||
if tusklets[1] and tuskers[1] then return cfg.ca_score end
|
||||
return 0
|
||||
end
|
||||
|
||||
function engine:mai_animals_tusklet_exec(cfg)
|
||||
|
|
|
@ -304,14 +304,15 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
if (cfg.animal_type == 'big_animals') then
|
||||
required_keys = { "filter"}
|
||||
optional_keys = { "avoid_unit", "filter_location", "filter_location_wander" }
|
||||
CA_parms = { { ca_id = "mai_animals_big", score = 300000 } }
|
||||
CA_parms = { { ca_id = "mai_animals_big", score = cfg.ca_score or 300000 } }
|
||||
|
||||
elseif (cfg.animal_type == 'wolves') then
|
||||
required_keys = { "filter", "filter_second" }
|
||||
optional_keys = { "avoid_type" }
|
||||
local score = cfg.ca_score or 90000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_animals_wolves", score = 95000 },
|
||||
{ ca_id = "mai_animals_wolves_wander", score = 90000 }
|
||||
{ ca_id = "mai_animals_wolves", score = score },
|
||||
{ ca_id = "mai_animals_wolves_wander", score = score - 1 }
|
||||
}
|
||||
|
||||
local wolves_aspects = {
|
||||
|
@ -338,38 +339,42 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
elseif (cfg.animal_type == 'herding') then
|
||||
required_keys = { "filter_location", "filter", "filter_second", "herd_x", "herd_y" }
|
||||
optional_keys = { "attention_distance", "attack_distance" }
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_animals_herding_attack_close_enemy", score = 300000 },
|
||||
{ ca_id = "mai_animals_sheep_runs_enemy", score = 295000 },
|
||||
{ ca_id = "mai_animals_sheep_runs_dog", score = 290000 },
|
||||
{ ca_id = "mai_animals_herd_sheep", score = 280000 },
|
||||
{ ca_id = "mai_animals_sheep_move", score = 270000 },
|
||||
{ ca_id = "mai_animals_dog_move", score = 260000 }
|
||||
{ ca_id = "mai_animals_herding_attack_close_enemy", score = score },
|
||||
{ ca_id = "mai_animals_sheep_runs_enemy", score = score - 1 },
|
||||
{ ca_id = "mai_animals_sheep_runs_dog", score = score - 2 },
|
||||
{ ca_id = "mai_animals_herd_sheep", score = score - 3 },
|
||||
{ ca_id = "mai_animals_sheep_move", score = score - 4 },
|
||||
{ ca_id = "mai_animals_dog_move", score = score - 5 }
|
||||
}
|
||||
|
||||
elseif (cfg.animal_type == 'forest_animals') then
|
||||
optional_keys = { "rabbit_type", "rabbit_number", "rabbit_enemy_distance", "rabbit_hole_img",
|
||||
"tusker_type", "tusklet_type", "deer_type", "filter_location"
|
||||
}
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_animals_new_rabbit", score = 310000 },
|
||||
{ ca_id = "mai_animals_tusker_attack", score = 300000 },
|
||||
{ ca_id = "mai_animals_forest_move", score = 290000 },
|
||||
{ ca_id = "mai_animals_tusklet", score = 280000 }
|
||||
{ ca_id = "mai_animals_new_rabbit", score = score },
|
||||
{ ca_id = "mai_animals_tusker_attack", score = score - 1 },
|
||||
{ ca_id = "mai_animals_forest_move", score = score - 2 },
|
||||
{ ca_id = "mai_animals_tusklet", score = score - 3 }
|
||||
}
|
||||
|
||||
elseif (cfg.animal_type == 'swarm') then
|
||||
optional_keys = { "scatter_distance", "vision_distance", "enemy_distance" }
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_animals_scatter_swarm", score = 300000 },
|
||||
{ ca_id = "mai_animals_move_swarm", score = 290000 }
|
||||
{ ca_id = "mai_animals_scatter_swarm", score = score },
|
||||
{ ca_id = "mai_animals_move_swarm", score = score - 1 }
|
||||
}
|
||||
|
||||
elseif (cfg.animal_type == 'wolves_multipacks') then
|
||||
optional_keys = { "type", "pack_size", "show_pack_number" }
|
||||
local score = cfg.ca_score or 300000
|
||||
CA_parms = {
|
||||
{ ca_id = "mai_animals_wolves_multipacks_attack", score = 300000 },
|
||||
{ ca_id = "mai_animals_wolves_multipacks_wander", score = 290000 }
|
||||
{ ca_id = "mai_animals_wolves_multipacks_attack", score = score },
|
||||
{ ca_id = "mai_animals_wolves_multipacks_wander", score = score - 1 }
|
||||
}
|
||||
|
||||
elseif (cfg.animal_type == 'hunter_unit') then
|
||||
|
@ -380,7 +385,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
if (not cfg.id) then
|
||||
H.wml_error("[micro_ai] tag (hunter_unit) is missing required parameter: id")
|
||||
end
|
||||
CA_parms = { { ca_id = "mai_animals_hunter_unit", score = 300000, sticky = true } }
|
||||
CA_parms = { { ca_id = "mai_animals_hunter_unit", score = cfg.ca_score or 300000, sticky = true } }
|
||||
|
||||
else
|
||||
H.wml_error("[micro_ai] tag (animals) animal_type= key is missing or has unknown value")
|
||||
|
|
Loading…
Add table
Reference in a new issue