<?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="Stay There!" el:subtitle="" el:id="ralf05"/>
      <el:version el:score="2" el:release="2" el:revision="0" el:status="released"/>
      <el:author  el:name="Ralf Westram" el:email="amgine@reallysoft.de" el:homepage=""/>
      <el:copyright>Copyright © 2003 Ralf Westram</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/ralf" el:id="lib/ralf" 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[
--debug_mode()

level={
   "!!#######y#!!!!!!!!!",
   "!!y       #!!0!!!0!!",
   "!!# #y### #!! !!! !!",
   "!!# #     y!#_#!#_#!",
   "!!# # #y##y## ### ##",
   "!!#ay   #          y",
   "#yy y## #  ## ##   #",
   "#     y #  #...#   #",
   "y xxx y     ...    #",
   "# xxx #%#  #...#   #",
   "y xxx y%%  ## ##   #",
   "y     #,#          #",
   "##y#yy############y#",
}

triggers = 0
doors = 0
doorsopen = 0

state = {0,0,0,0,0,0,0,0,0}

function trigger(num)
   state[num] = 1-state[num]
   all=1
   for x=0,triggers-1 do
      if (state[x]==0) then
         all = 0
      end
   end

   if (doorsopen==0 and all==1) then
       SendMessage("door1","open")
       SendMessage("door2","open")
       doorsopen = 1
   elseif (doorsopen==1 and all==0) then
       SendMessage("door1","close")
       SendMessage("door2","close")
       doorsopen = 0
   end
end

function set_trigger(x,y)
   triggers = triggers + 1
   state[triggers] = 0
   local funcn = "trig_"..triggers
   dostring(funcn.." = function() trigger("..triggers..") end")
   set_item("it-trigger",x,y,{action="callback",target=funcn});
end

function set_door(x,y)
   doors = doors + 1
   set_stone("st-door",x,y,{name="door"..doors,type="h"})
end

cells={}

cells[" "] = cell{floor="fl-tigris"}
cells["!"] = cell{floor="fl-space"}

cells["."] = cell{parent={cells[" "],set_trigger}}

cells["#"] = cell{parent=cells[" "],stone="st-rock1"}
cells["y"] = cell{parent=cells[" "],stone="st-stoneimpulse"}

cells["%"] = cell{parent=cells[" "],stone="st-grate1"}
cells[","] = cell{parent=cells["%"],item="it-seed"}

cells["x"] = cell{parent=cells[" "],stone="st-stoneimpulse_movable"}
cells["a"] = cell{parent=cells[" "],actor={"ac-blackball", {player=0}}}
cells["_"] = cell{parent={cells[" "],set_door}}

-- debug
--cells["."] = cell{parent={cells["x"],set_trigger}}

rs_create_world(level,cells)
    ]]></el:luamain>
    <el:i18n>
      <el:string el:key="title">
        <el:english el:translate="false"/>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
