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:
parent
caabb57161
commit
1c5a044078
1 changed files with 13 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue