Skip to content

Commit

Permalink
Forest Animals Micro AI: exclude rabbit holes on map border
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattsc committed Jan 22, 2020
1 parent fce99f1 commit 465ba7c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions data/ai/micro_ais/cas/ca_forest_animals_new_rabbit.lua
Expand Up @@ -22,22 +22,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
Expand Down

0 comments on commit 465ba7c

Please sign in to comment.