<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<el:level xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://enigma-game.org/schema/level/1 level.xsd" xmlns:el="http://enigma-game.org/schema/level/1">
  <el:protected>
    <el:info el:type="level">
      <el:identity el:title="Everhungry" el:subtitle="" el:id="ant32"/>
      <el:version el:score="1" el:release="1" el:revision="0" el:status="released"/>
      <el:author  el:name="Petr Machata" el:email="" el:homepage=""/>
      <el:copyright>Copyright © 2003 Petr Machata</el:copyright>
      <el:license el:type="GPL v2.0 or above" el:open="true"/>
      <el:compatibility el:enigma="0.92">
       <el:dependency el:path="lib/ant" el:id="lib/ant" el:release="1" el:preload="true"/>
      </el:compatibility>
      <el:modes el:easy="false" el:single="true" el:network="false"/>
      <el:comments>
        <el:code>Lua 5.1 and XML converted by Leveladministrators</el:code>
      </el:comments>
      <el:score el:easy="-" el:difficult="-"/>
    </el:info>
    <el:luamain><![CDATA[
local shatter_map = {count=0, effct=1}
local intact_fields = {}

-- shatter given piece of floor
function bombit(x0, y0)
   bomb = set_item("it-blackbomb", x0, y0)
   SendMessage(bomb, "explode")
   shatter_map[getkey(x0,y0)] = {x=x0, y=y0}
   shatter_map.count = shatter_map.count+1
   shatter_map[shatter_map.count] = shatter_map[getkey(x0,y0)]
end

-- add given field to list of intact fields
function add_intact(x0, y0)
   intact_fields[getkey(x0,y0)] = 1
end

-- move the eater
function tick()
   if ((shatter_map.count or 0)==0) then bombit(10,7) return end
   if (shatter_map.effct > shatter_map.count) then return end

   local minx, maxx = 1, level_width-2
   local miny, maxy = 1, level_height-2 

   local count = 0,0
   local found = -1
   local x0,y0, x1,y1 = 0,0, 0,0

   repeat
      -- once the array is empty, there are no shatters left to satisfy conditions
      if (shatter_map.effct > shatter_map.count) then return end
      -- pick a field from shatter array and movement direction
      local m = shatter_map.count
      local d = random(1,4)
      -- setup coordinates
      x0, y0 = shatter_map[m].x, shatter_map[m].y
      x1, y1 = x0, y0
      -- setup flags
      found = 1
      count= 0

      repeat
     if     (d == 1) then x1=x0+0 y1=y0-1
     elseif (d == 2) then x1=x0+1 y1=y0+0
     elseif (d == 3) then x1=x0+0 y1=y0+1
     elseif (d == 4) then x1=x0-1 y1=y0+0
     end

     d = d+1
     if (d>4) then d=d-4 end

     count=count+1
     if (count>4) then found=0 break end

     cond = (not(shatter_map[getkey(x1,y1)] or intact_fields[getkey(x1,y1)]))
      until cond

      --if not found, this square is inner void
      if (found == 0) then
     -- swap
     local rem = shatter_map[shatter_map.effct]
     shatter_map[shatter_map.effct] = shatter_map[m]
     shatter_map[m] = rem
     -- move effective counter of shatter array
     shatter_map.effct = shatter_map.effct+1
      end
   until (found==1)

   bombit(x1,y1)
end

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
floor = cell{floor="fl-tigris"}
stone = cell{stone="st-rock5"}
spring= cell{item= "it-spring1"}
actor = cell{actor={"ac-blackball", {player=0}}, parent=spring}
timer = cell{stone={"st-timer", {action="callback", target="tick", interval=0.2}}}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

create_world(20, 13)
fill_world_func(floor)
draw_border_func({stone,add_intact})

timer(0,0)
set_funcs(oxyd, {{0,1},{0,6},{0,11},{19,1},{19,6},{19,11}})
set_funcs(add_intact, {{1,1},{1,6},{1,11},{18,1},{18,6},{18,11}})
oxyd_shuffle()

actor(1,1)

-- Added CreatingPreview-section to show some abyss in preview: Andreas, Oct 06
if enigma.CreatingPreview then
   set_floor("fl-abyss", 10, 7)
   set_floor("fl-abyss", 10, 6)
   set_floor("fl-abyss", 11, 6)
   set_floor("fl-abyss", 12, 6)
   set_item("it-crack3", 12, 5)
   set_item("it-explosion1", 11, 5)
   set_item("it-explosion1", 12, 4)
   set_item("it-explosion1", 13, 5)
end

    ]]></el:luamain>
    <el:i18n>
      <el:string el:key="title">
        <el:english el:translate="false"/>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
