Micro AIs: use [filter_location] and variants thereof for SLFs
Rename Standard Location Filters in order to be consistent with other WML.
This commit is contained in:
parent
f7aa38bca4
commit
5033ef7ebf
6 changed files with 42 additions and 42 deletions
|
@ -69,7 +69,7 @@ return {
|
|||
local r = AH.random(10)
|
||||
if (not unit.variables.goal_x) or (r <= 1) then
|
||||
-- 'locs' includes border hexes, but that does not matter here
|
||||
locs = AH.get_passable_locations((cfg.hunting_ground or {}), unit)
|
||||
locs = AH.get_passable_locations((cfg.filter_location or {}), unit)
|
||||
local rand = AH.random(#locs)
|
||||
--print('#locs', #locs, rand)
|
||||
unit.variables.goal_x, unit.variables.goal_y = locs[rand][1], locs[rand][2]
|
||||
|
@ -840,7 +840,7 @@ return {
|
|||
-- Unit gets a new goal if none exist or on any move with 10% random chance
|
||||
local r = AH.random(10)
|
||||
if (not unit.variables.goal_x) or (r == 1) then
|
||||
local locs = AH.get_passable_locations(cfg.goal_terrain or {})
|
||||
local locs = AH.get_passable_locations(cfg.filter_location or {})
|
||||
local rand = AH.random(#locs)
|
||||
--print(type, ': #locs', #locs, rand)
|
||||
unit.variables.goal_x, unit.variables.goal_y = locs[rand][1], locs[rand][2]
|
||||
|
@ -849,7 +849,7 @@ return {
|
|||
|
||||
-- hexes the unit can reach
|
||||
local reach_map = AH.get_reachable_unocc(unit)
|
||||
local wander_terrain = cfg.wander_terrain or {}
|
||||
local wander_terrain = cfg.filter_location_wander or {}
|
||||
reach_map:iter( function(x, y, v)
|
||||
-- Remove tiles that do not comform to the wander terrain filter
|
||||
if (not wesnoth.match_location(x, y, wander_terrain) ) then
|
||||
|
@ -1056,13 +1056,13 @@ return {
|
|||
-- First, find all contiguous hexes around center hex that are inside herding_perimeter
|
||||
local herding_area = LS.of_pairs(wesnoth.get_locations {
|
||||
x = cfg.herd_x, y = cfg.herd_y, radius = 999,
|
||||
{"filter_radius", { { "not", cfg.herding_perimeter } } }
|
||||
{"filter_radius", { { "not", cfg.filter_location } } }
|
||||
} )
|
||||
|
||||
-- Then, also exclude hexes next to herding_perimeter; some of the functions work better like that
|
||||
herding_area:iter( function(x, y, v)
|
||||
for xa, ya in H.adjacent_tiles(x, y) do
|
||||
if (wesnoth.match_location(xa, ya, cfg.herding_perimeter) ) then herding_area:remove(x, y) end
|
||||
if (wesnoth.match_location(xa, ya, cfg.filter_location) ) then herding_area:remove(x, y) end
|
||||
end
|
||||
end)
|
||||
--AH.put_labels(herding_area)
|
||||
|
@ -1334,7 +1334,7 @@ return {
|
|||
-- And the closer dog goes first (so that it might be able to chase another sheep afterward)
|
||||
rating = rating - H.distance_between(x, y, d.x, d.y) / 100.
|
||||
-- Finally, prefer to stay on path, if possible
|
||||
if (wesnoth.match_location(x, y, cfg.herding_perimeter) ) then rating = rating + 0.001 end
|
||||
if (wesnoth.match_location(x, y, cfg.filter_location) ) then rating = rating + 0.001 end
|
||||
|
||||
reach_map:insert(x, y, rating)
|
||||
|
||||
|
@ -1418,7 +1418,7 @@ return {
|
|||
{ "not", { { "filter_adjacent", { side = wesnoth.current.side, {"and", cfg.filter_second} } } } }
|
||||
}[1]
|
||||
|
||||
local herding_perimeter = LS.of_pairs(wesnoth.get_locations(cfg.herding_perimeter))
|
||||
local herding_perimeter = LS.of_pairs(wesnoth.get_locations(cfg.filter_location))
|
||||
--AH.put_labels(herding_perimeter)
|
||||
|
||||
-- Find average distance of herding_perimeter from center
|
||||
|
@ -1601,7 +1601,7 @@ return {
|
|||
local rabbit_type = cfg.rabbit_type or "no_unit_of_this_type"
|
||||
local tusker_type = cfg.tusker_type or "no_unit_of_this_type"
|
||||
local tusklet_type = cfg.tusklet_type or "no_unit_of_this_type"
|
||||
local wander_terrain = cfg.wander_terrain or {}
|
||||
local wander_terrain = cfg.filter_location or {}
|
||||
|
||||
-- We want the deer/rabbits to move first, tuskers later
|
||||
local units = wesnoth.get_units { side = wesnoth.current.side, type = deer_type .. ',' .. rabbit_type, formula = '$this_unit.moves > 0' }
|
||||
|
|
|
@ -40,7 +40,7 @@ return {
|
|||
local reachable_attack_terrain =
|
||||
LS.of_pairs( wesnoth.get_locations {
|
||||
{"and", {x = me.x, y = me.y, radius = me.moves} },
|
||||
{"and", cfg.attack_terrain}
|
||||
{"and", cfg.filter_location}
|
||||
} )
|
||||
reachable_attack_terrain:inter(reach)
|
||||
--print(" reach: " .. reach:size() .. " reach_attack: " .. reachable_attack_terrain:size())
|
||||
|
@ -82,7 +82,7 @@ return {
|
|||
local reachable_wander_terrain =
|
||||
LS.of_pairs( wesnoth.get_locations {
|
||||
{"and", {x = me.x, y = me.y, radius = me.moves} },
|
||||
{"and", (cfg.wander_terrain or cfg.attack_terrain)}
|
||||
{"and", (cfg.filter_location_wander or cfg.filter_location)}
|
||||
} )
|
||||
reachable_wander_terrain:inter(reach)
|
||||
|
||||
|
|
|
@ -278,8 +278,8 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
if (cfg.action ~= "delete") then
|
||||
-- Required keys
|
||||
cfg = cfg.__parsed
|
||||
local required_keys = {"filter", "attack_terrain"}
|
||||
local optional_keys = {"stationary", "wander_terrain"}
|
||||
local required_keys = {"filter", "filter_location"}
|
||||
local optional_keys = {"stationary", "filter_location_wander"}
|
||||
|
||||
for k, v in pairs(required_keys) do
|
||||
local child = H.get_child(cfg, v)
|
||||
|
@ -496,7 +496,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
|
||||
-- This list does not contain id because we check for that differently
|
||||
required_keys["hunter_unit"] = { "id", "home_x", "home_y" }
|
||||
optional_keys["hunter_unit"] = { "hunting_ground", "rest_turns", "show_messages" }
|
||||
optional_keys["hunter_unit"] = { "filter_location", "rest_turns", "show_messages" }
|
||||
|
||||
required_keys["wolves"] = { "filter", "filter_second" }
|
||||
optional_keys["wolves"] = { "avoid_type" }
|
||||
|
@ -505,17 +505,17 @@ function wesnoth.wml_actions.micro_ai(cfg)
|
|||
optional_keys["wolves_multipacks"] = { "type", "pack_size", "show_pack_number" }
|
||||
|
||||
required_keys["big_animals"] = { "filter"}
|
||||
optional_keys["big_animals"] = { "avoid_unit", "goal_terrain", "wander_terrain" }
|
||||
optional_keys["big_animals"] = { "avoid_unit", "filter_location", "filter_location_wander" }
|
||||
|
||||
required_keys["forest_animals"] = {}
|
||||
optional_keys["forest_animals"] = { "rabbit_type", "rabbit_number", "rabbit_enemy_distance", "rabbit_hole_img",
|
||||
"tusker_type", "tusklet_type", "deer_type", "wander_terrain"
|
||||
"tusker_type", "tusklet_type", "deer_type", "filter_location"
|
||||
}
|
||||
|
||||
required_keys["swarm"] = {}
|
||||
optional_keys["swarm"] = { "scatter_distance", "vision_distance", "enemy_distance" }
|
||||
|
||||
required_keys["herding"] = { "herding_perimeter", "filter", "filter_second", "herd_x", "herd_y" }
|
||||
required_keys["herding"] = { "filter_location", "filter", "filter_second", "herd_x", "herd_y" }
|
||||
optional_keys["herding"] = { "attention_distance", "attack_distance" }
|
||||
|
||||
if (cfg.action~='delete') then
|
||||
|
|
|
@ -245,9 +245,9 @@
|
|||
rabbit_type=Giant Rat
|
||||
tusker_type=Ogre
|
||||
tusklet_type=Young Ogre
|
||||
[wander_terrain]
|
||||
[filter_location]
|
||||
terrain=*^F*
|
||||
[/wander_terrain]
|
||||
[/filter_location]
|
||||
[/micro_ai]
|
||||
|
||||
# Set up the big_animals micro AI for the Ghasts
|
||||
|
@ -263,12 +263,12 @@
|
|||
[avoid_unit]
|
||||
type=Yeti,Giant Spider,Ghast,Footpad
|
||||
[/avoid_unit]
|
||||
[goal_terrain]
|
||||
[filter_location]
|
||||
x,y=1-40,1-18
|
||||
[/goal_terrain]
|
||||
[wander_terrain]
|
||||
[/filter_location]
|
||||
[filter_location_wander]
|
||||
terrain=*
|
||||
[/wander_terrain]
|
||||
[/filter_location_wander]
|
||||
[/micro_ai]
|
||||
|
||||
# Set up the big_animals micro AI for side 4 (the spiders)
|
||||
|
@ -284,12 +284,12 @@
|
|||
[avoid_unit]
|
||||
type=Yeti,Giant Spider,Ghast,Footpad
|
||||
[/avoid_unit]
|
||||
[goal_terrain]
|
||||
[filter_location]
|
||||
terrain=H*
|
||||
[/goal_terrain]
|
||||
[wander_terrain]
|
||||
[/filter_location]
|
||||
[filter_location_wander]
|
||||
terrain=*
|
||||
[/wander_terrain]
|
||||
[/filter_location_wander]
|
||||
[/micro_ai]
|
||||
|
||||
# Set up the big_animals micro AI for the Yeti
|
||||
|
@ -305,12 +305,12 @@
|
|||
[avoid_unit]
|
||||
type=Yeti,Giant Spider,Ghast,Footpad
|
||||
[/avoid_unit]
|
||||
[goal_terrain]
|
||||
[filter_location]
|
||||
terrain=M*
|
||||
[/goal_terrain]
|
||||
[wander_terrain]
|
||||
[/filter_location]
|
||||
[filter_location_wander]
|
||||
terrain=M*,M*^*,H*,H*^*
|
||||
[/wander_terrain]
|
||||
[/filter_location_wander]
|
||||
[/micro_ai]
|
||||
|
||||
# Set up the wolves micro AI
|
||||
|
@ -343,9 +343,9 @@
|
|||
type=Troll Whelp
|
||||
[/filter_second]
|
||||
herd_x,herd_y=32,28
|
||||
[herding_perimeter]
|
||||
[filter_location]
|
||||
terrain=Rb
|
||||
[/herding_perimeter]
|
||||
[/filter_location]
|
||||
[/micro_ai]
|
||||
[/event]
|
||||
|
||||
|
|
|
@ -67,9 +67,9 @@
|
|||
|
||||
animal_type=hunter_unit
|
||||
id=Rowck
|
||||
[hunting_ground]
|
||||
[filter_location]
|
||||
x,y=5-30,1-15
|
||||
[/hunting_ground]
|
||||
[/filter_location]
|
||||
home_x,home_y=3,15
|
||||
rest_turns=2
|
||||
|
||||
|
|
|
@ -326,9 +326,9 @@
|
|||
[filter]
|
||||
type=Saurian Skirmisher
|
||||
[/filter]
|
||||
[attack_terrain]
|
||||
[filter_location]
|
||||
terrain=S*
|
||||
[/attack_terrain]
|
||||
[/filter_location]
|
||||
stationary=yes
|
||||
[/micro_ai]
|
||||
|
||||
|
@ -340,9 +340,9 @@
|
|||
[filter]
|
||||
type=Saurian Skirmisher
|
||||
[/filter]
|
||||
[attack_terrain]
|
||||
[filter_location]
|
||||
terrain=S*
|
||||
[/attack_terrain]
|
||||
[/filter_location]
|
||||
[/micro_ai]
|
||||
|
||||
[micro_ai]
|
||||
|
@ -353,12 +353,12 @@
|
|||
[filter]
|
||||
type=Naga Fighter
|
||||
[/filter]
|
||||
[attack_terrain]
|
||||
[filter_location]
|
||||
terrain=W*,S*
|
||||
[/attack_terrain]
|
||||
[wander_terrain]
|
||||
[/filter_location]
|
||||
[filter_location_wander]
|
||||
terrain=W*
|
||||
[/wander_terrain]
|
||||
[/filter_location_wander]
|
||||
[/micro_ai]
|
||||
|
||||
# The WML lurkers
|
||||
|
|
Loading…
Add table
Reference in a new issue