<?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="Island of Safety" el:subtitle="Keypad Corners" el:id="duffy27"/>
      <el:version el:score="1" el:release="2" el:revision="2" el:status="released"/>
      <el:author  el:name="Jacob Scott" el:email="" el:homepage=""/>
      <el:copyright>Copyright © 2003 Jacob Scott</el:copyright>
      <el:license el:type="GPL v2.0 or above" el:open="true"/>
      <el:compatibility el:enigma="1.10"/>
      <el:modes el:easy="false" el:single="true" el:network="false"/>
      <el:comments><el:code>New API converted by R. Bourquin</el:code></el:comments>
      <el:score el:easy="-" el:difficult="-"/>
    </el:info>
    <el:luamain><![CDATA[
ti[" "] = {"fl_hay"}
ti["-"] = {"fl_abyss"}
ti["."] = {"fl_hay", name="area#"}
ti["#"] = {"st_greenbrown"}
ti[","] = ti({"st_rawglass", name="display#"}) .. {"fl_ice"}
ti["1"] = {"st_greenbrown", name="corner#", _code="1"}
ti["3"] = {"st_greenbrown", name="corner#", _code="3"}
ti["7"] = {"st_greenbrown", name="corner#", _code="7"}
ti["9"] = {"st_greenbrown", name="corner#", _code="9"}
ti["D"] = {"st_door", flavor="a", name="doors#"}
ti["O"] = {"st_oxyd"}
ti["@"] = ti["."] .. {"#ac_marble_black"}

wo(ti, " ", {
    "-,,,,,,,,,,,,-",
    "-7##########9-",
    "OD..........DO",
    "-#..........#-",
    "-#..........#-",
    "OD..........DO",
    "-#..........#-",
    "-#.....@....#-",
    "OD..........DO",
    "-#..........#-",
    "-#..........#-",
    "OD..........DO",
    "-1##########3-"})

wo:add({"ot_timer", target="timer", interval=1.0, _state=0})
wo:shuffleOxyd()

local corners = no["corner#*"]
local doors = no["doors#*"]:sort("circular")
local door = 0
local startpos = po(1, 0)
local curpos = startpos

function timer(value, sender)
    if sender["_state"] == 0 then
        area = no["area#*"]:shuffle()
        stile = area[1]
        stile["name"] = "safetile"

        corner = corners:shuffle()[1]
        dist = po(corner) - po(stile)
        wo[area:shuffle()[1]] = {"it_document", text=corner["_code"]..string.sub(tostring(math.abs(dist.x)),-1)..string.sub(tostring(math.abs(dist.y)),-1)}

        wo[curpos] = {"fl_wood"}
        curpos = curpos + E
    elseif sender["_state"] == 12 then
        wo[no["area#*"]] = {"fl_abyss", name="abyss#"}
    elseif sender["_state"] == 13 then
        wo[no["abyss#*"]] = ti["."]
        wo[no["safetile"]] = ti["."]

        doors:close()
        doors[door+1]:open()
        door = (door +1) % #doors

        wo[no["display#*"]] = {"fl_ice"}
        curpos = startpos
    else
        wo[curpos] = {"fl_wood"}
        curpos = curpos + E
    end
    sender["_state"] = (sender["_state"] +1) % 14
end
 ]]></el:luamain>
    <el:i18n>
      <el:string el:key="title">
        <el:english el:translate="false"/>
      </el:string>
      <el:string el:key="subtitle">
        <el:english el:translate="true"/>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
