<?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="Weirdly Wired" el:subtitle="" el:id="andreas49"/>
      <el:version el:score="1" el:release="1" el:revision="11" el:status="released"/>
      <el:author el:name="Andreas Lochmann" el:email="" el:homepage=""/>
      <el:copyright>Copyright © 2008, 2009 Andreas Lochmann</el:copyright>
      <el:license el:type="GPL v2.0 or above" el:open="true"/>
      <el:compatibility el:enigma="1.10">
        <el:dependency el:path="lib/libmath" el:id="lib/libmath" el:release="1" el:preload="true"/>
      </el:compatibility>
      <el:modes el:easy="true" el:single="true" el:network="false"/>
      <el:score el:easy="0:37" el:difficult="8:49"/>
    </el:info>
    <el:luamain><![CDATA[

ti[" "] = {"fl_sahara", friction = 3.5, adhesion = 4.0}
ti["a"] = {"fl_ivory", friction = 3.5, adhesion = 4.0}
ti["b"] = {"fl_bright", friction = 3.5, adhesion = 4.0}
ti["c"] = {"fl_platinum", friction = 3.5, adhesion = 4.0}
ti["_"] = {"fl_water"}
ti["@"] = {"#ac_marble_black"}
ti["w"] = {"st_flat_movable", "wood#"}
ti["t"] = {"it_trigger", "trigger#"}
ti["d"] = {"st_blocker", "door#"}
ti["o"] = {"st_oxyd", oxydcolor = OXYD_YELLOW, flavor = "a"}
ti["O"] = {"st_oxyd", oxydcolor = OXYD_WHITE, flavor = "a"}
ti["1"] = {"st_panel", cluster = 1}
ti["2"] = {"st_panel", cluster = 2}
ti["S"] = {"st_switch", target = "easy_mode_call"}

floors  = {ti[" "], ti["a"], ti["b"], ti["c"]}
polynom = lib.math.random_vector(10, 4)

function myresolver(key, x, y)
  if key == " " then
    return floors[lib.math.cubic_polynomial(polynom, x, y) % (#floors) + 1]
  elseif    (key == "#")
         or ((key == "_") and (random(4) == 1))
         or ((key == "S") and wo["IsDifficult"]) then
    return ti[""..random(2)]
  else
    return ti[key]
  end
end

w, h = wo(myresolver, " ", {
 -- 01234567890123456789
   "####################___________________",
   "#                  #_____###o###_______",
   "#   w   w t   t    #_____#d   d#_______",
   "#     w   w t   t  #___### ### ###_____",
   "#  w     t         #___#d d#_#d d#_____",
   "#                  ##### ###_### ###___",
   "S    w   w t @ t        d#___#_#d d#___",
   "#                  #######_####### #___",
   "#  w     t         #_______O  d# # o___",
   "#     w   w t   t  #_______### ### #___",
   "#   w   w t   t    #_________#d   d#___",
   "#                  #_________###O###___",
   "####################___________________"
})

door_p = lib.math.permutation(12)
wire_p = lib.math.permutation(12)
woods = no["wood#*"]
triggers = no["trigger#*"]
doors = no["door#*"]

for j = 1, 12 do
  triggers[j].target = doors[door_p[j]]
end

for j = 1, 9 do
  wo:add({"ot_wire",
          anchor1 = woods[wire_p[j + 3]],
          anchor2 = woods[wire_p[j%3 + 1]]})
  wo:add({"ot_wire", name = "obsolete_wire#",
          anchor1 = woods[wire_p[j + 3]],
          anchor2 = woods[wire_p[j%9 + 4]]})
end

function easy_mode_call(is_on, sender)
  if is_on then
    no["obsolete_wire#*"]:kill()
  else
    for j = 1, 9 do
      wo:add({"ot_wire", name = "obsolete_wire#",
              anchor1 = woods[wire_p[j + 3]],
              anchor2 = woods[wire_p[j%9 + 4]]})
    end
  end
end
    ]]></el:luamain>
    <el:i18n>
      <el:string el:key="title">
        <el:english el:translate="false"/>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
