Swarm Micro AI: add optional parameter [filter]
This commit is contained in:
parent
c59e71b974
commit
8d03d3ef08
4 changed files with 44 additions and 7 deletions
|
@ -4,7 +4,10 @@ local M = wesnoth.map
|
|||
local ca_swarm_move = {}
|
||||
|
||||
function ca_swarm_move:evaluation(cfg)
|
||||
local units = wesnoth.units.find_on_map { side = wesnoth.current.side }
|
||||
local units = wesnoth.units.find_on_map {
|
||||
side = wesnoth.current.side,
|
||||
{ "and" , wml.get_child(cfg, "filter") }
|
||||
}
|
||||
for _,unit in ipairs(units) do
|
||||
if (unit.moves > 0) then return cfg.ca_score end
|
||||
end
|
||||
|
@ -17,7 +20,11 @@ function ca_swarm_move:execution(cfg)
|
|||
local vision_distance = cfg.vision_distance or 12
|
||||
|
||||
-- If no close enemies, swarm will move semi-randomly, staying close together, but away from enemies
|
||||
local all_units = wesnoth.units.find_on_map { side = wesnoth.current.side }
|
||||
local all_units = wesnoth.units.find_on_map {
|
||||
side = wesnoth.current.side,
|
||||
{ "and" , wml.get_child(cfg, "filter") }
|
||||
}
|
||||
|
||||
local units, units_no_moves = {}, {}
|
||||
for _,unit in ipairs(all_units) do
|
||||
if (unit.moves > 0) then
|
||||
|
|
|
@ -12,7 +12,10 @@ local function get_enemies(cfg)
|
|||
end
|
||||
|
||||
local function get_swarm_units(cfg)
|
||||
return AH.get_units_with_moves { side = wesnoth.current.side }
|
||||
return AH.get_units_with_moves {
|
||||
side = wesnoth.current.side,
|
||||
{ "and" , wml.get_child(cfg, "filter") }
|
||||
}
|
||||
end
|
||||
|
||||
local ca_swarm_scatter = {}
|
||||
|
|
|
@ -146,7 +146,7 @@ function wesnoth.micro_ais.forest_animals(cfg)
|
|||
end
|
||||
|
||||
function wesnoth.micro_ais.swarm(cfg)
|
||||
local optional_keys = { "[avoid]", "scatter_distance", "vision_distance", "enemy_distance" }
|
||||
local optional_keys = { "[avoid]", "[filter]", "scatter_distance", "vision_distance", "enemy_distance" }
|
||||
local score = cfg.ca_score or 300000
|
||||
local CA_parms = {
|
||||
ai_id = 'mai_swarm',
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
{VARIABLE scenario_name swarm}
|
||||
|
||||
{REPEAT 12 {GENERIC_UNIT 2 "Vampire Bat" 37 26}}
|
||||
{REPEAT 8 {GENERIC_UNIT 2 "Blood Bat" 37 20}}
|
||||
|
||||
# The right-click menu items
|
||||
[set_menu_item]
|
||||
|
@ -102,8 +103,8 @@
|
|||
[/command]
|
||||
[/set_menu_item]
|
||||
[set_menu_item]
|
||||
id=m03_new_bat
|
||||
description= _ "Place Side 2 Bat"
|
||||
id=m03_new_vampire_bat
|
||||
description= _ "Place Side 2 Vampire Bat"
|
||||
image=units/undead/bat-se-4.png~CROP(24,16,24,24)
|
||||
[show_if]
|
||||
{VARIABLE_CONDITIONAL scenario_name equals swarm}
|
||||
|
@ -112,6 +113,17 @@
|
|||
{GENERIC_UNIT 2 (Vampire Bat) $x1 $y1}
|
||||
[/command]
|
||||
[/set_menu_item]
|
||||
[set_menu_item]
|
||||
id=m04_new_blood_bat
|
||||
description= _ "Place Side 2 Blood Bat"
|
||||
image=units/undead/bloodbat-se-4.png~CROP(24,16,24,24)
|
||||
[show_if]
|
||||
{VARIABLE_CONDITIONAL scenario_name equals swarm}
|
||||
[/show_if]
|
||||
[command]
|
||||
{GENERIC_UNIT 2 (Blood Bat) $x1 $y1}
|
||||
[/command]
|
||||
[/set_menu_item]
|
||||
[set_menu_item]
|
||||
id=m05_kill_unit
|
||||
description= _ "Kill Unit under Cursor"
|
||||
|
@ -131,6 +143,21 @@
|
|||
side=2
|
||||
ai_type=swarm
|
||||
action=add
|
||||
|
||||
[filter]
|
||||
type=Vampire Bat
|
||||
[/filter]
|
||||
ca_score=300001
|
||||
[/micro_ai]
|
||||
[micro_ai]
|
||||
side=2
|
||||
ai_type=swarm
|
||||
action=add
|
||||
|
||||
[filter]
|
||||
type=Blood Bat
|
||||
[/filter]
|
||||
ca_score=300000
|
||||
[/micro_ai]
|
||||
[/event]
|
||||
|
||||
|
@ -141,7 +168,7 @@
|
|||
[message]
|
||||
speaker=narrator
|
||||
image=wesnoth-icon.png
|
||||
message= _ "This scenario features bats moving around in a swarm. Without adjacent enemies, they simply try to stay together and at a certain distance from enemies. However, if an enemy unit is close to any bat, the swarm scatters. This is particular fun to watch when one places an enemy unit in the middle of the swarm. After being scattered, the swarm members slowly rejoin, but not in a very organized way. Sub-swarms or individual bats might roam around for quite some time before they find their way back. It is also possible that individual bats (or small groups) split off from the larger swarm at times.
|
||||
message= _ "This scenario features bats moving around in two swarms. Without adjacent enemies, the bats in a swarm simply try to stay together and at a certain distance from enemies. However, if an enemy unit is close to any bat, the swarm scatters. This is particular fun to watch when one places an enemy unit in the middle of the swarm. After being scattered, the swarm members slowly rejoin, but not in a very organized way. Sub-swarms or individual bats might roam around for quite some time before they find their way back. It is also possible that individual bats (or small groups) split off from the larger swarm at times.
|
||||
|
||||
The player controls a side of gryphons, each of which is given 99 moves so that the reaction of the swarm to enemies can be tested easily. There are also several right-click options, for example for adding bats or gryphons or for taking units off the map.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue