Forest Animals Micro AI: exclude rabbit holes on map border

Previously, a rabbit hole item on the map border could be selected for spawning a new rabbit, resulting in an error message on screen and abandoning the CA for the rest of the turn.
This commit is contained in:
mattsc 2020-01-21 16:30:26 -08:00
parent caabb57161
commit 1c5a044078

View file

@ -21,22 +21,25 @@ function ca_forest_animals_new_rabbit:execution(cfg)
-- Eliminate all holes that have an enemy within 'rabbit_enemy_distance' hexes
-- We also add a random number to the ones we keep, for selection of the holes later
local width, height = wesnoth.get_map_size()
local holes = {}
for _,item in ipairs(all_items) do
local enemies = AH.get_attackable_enemies {
{ "filter_location", { x = item.x, y = item.y, radius = rabbit_enemy_distance } }
}
if (item.x > 0) and (item.x <= width) and (item.y > 0) and (item.y <= height) then
local enemies = AH.get_attackable_enemies {
{ "filter_location", { x = item.x, y = item.y, radius = rabbit_enemy_distance } }
}
if (not enemies[1]) then
-- If cfg.rabbit_hole_img is set, only items with that image or halo count as holes
if cfg.rabbit_hole_img then
if (item.image == cfg.rabbit_hole_img) or (item.halo == cfg.rabbit_hole_img) then
if (not enemies[1]) then
-- If cfg.rabbit_hole_img is set, only items with that image or halo count as holes
if cfg.rabbit_hole_img then
if (item.image == cfg.rabbit_hole_img) or (item.halo == cfg.rabbit_hole_img) then
item.random = math.random(100)
table.insert(holes, item)
end
else
item.random = math.random(100)
table.insert(holes, item)
end
else
item.random = math.random(100)
table.insert(holes, item)
end
end
end