--Siegfried Fennig 18.12.2002
enigma.ConserveLevel=FALSE                  -- \dh\

levelw = 39
levelh = 25

create_world(levelw, levelh)
draw_border("st-greenbrown")
fill_floor("fl-marble", 0,0, level_width,level_height)

oxyd(35,1)
oxyd(35,21)

puzzle( 16,17,PUZ_0000)
puzzle( 17,19,PUZ_0000)
puzzle( 16,19,PUZ_0010)
puzzle( 17,20,PUZ_1010)
puzzle( 17,22,PUZ_1000)

draw_stones("st-greenbrown", {5,1}, {1,0}, 2)
draw_stones("st-greenbrown", {6,2}, {1,0}, 2)
draw_stones("st-greenbrown", {7,3}, {1,0}, 2)
draw_stones("st-greenbrown", {8,4}, {1,0}, 4)
draw_stones("st-greenbrown", {11,3}, {1,0}, 2)
draw_stones("st-greenbrown", {12,2}, {1,0}, 2)
draw_stones("st-greenbrown", {13,1}, {1,0}, 2)
draw_stones("st-greenbrown", {5,11}, {1,0}, 2)
draw_stones("st-greenbrown", {6,10}, {1,0}, 2)
draw_stones("st-greenbrown", {7,9}, {1,0}, 2)
draw_stones("st-greenbrown", {8,8}, {1,0}, 4)
draw_stones("st-greenbrown", {11,9}, {1,0}, 2)
draw_stones("st-greenbrown", {12,10}, {1,0}, 2)
draw_stones("st-greenbrown", {13,11}, {1,0}, 2)
draw_stones("st-greenbrown", {1,12}, {1,0}, 5)
draw_stones("st-greenbrown", {14,12}, {1,0}, 23)
draw_stones("st-greenbrown", {5,13}, {1,0}, 2)
draw_stones("st-greenbrown", {6,14}, {1,0}, 2)
draw_stones("st-greenbrown", {7,15}, {1,0}, 2)
draw_stones("st-greenbrown", {8,16}, {1,0}, 4)
draw_stones("st-greenbrown", {11,15}, {1,0}, 2)
draw_stones("st-greenbrown", {12,14}, {1,0}, 2)
draw_stones("st-greenbrown", {13,13}, {1,0}, 2)
draw_stones("st-greenbrown", {5,23}, {1,0}, 2)
draw_stones("st-greenbrown", {6,22}, {1,0}, 2)
draw_stones("st-greenbrown", {7,21}, {1,0}, 2)
draw_stones("st-greenbrown", {8,20}, {1,0}, 4)
draw_stones("st-greenbrown", {11,21}, {1,0}, 2)
draw_stones("st-greenbrown", {12,22}, {1,0}, 2)
draw_stones("st-greenbrown", {13,23}, {1,0}, 2)
draw_stones("st-invisible", {6,0}, {1,0}, 8)
draw_stones("st-invisible", {6,24}, {1,0}, 8)
draw_stones("st-greenbrown", {19,16}, {0,1}, 2)
draw_stones("st-greenbrown", {19,20}, {0,1}, 4)
draw_stones("st-greenbrown", {27,2}, {1,0}, 1)
draw_stones("st-greenbrown", {20,3}, {1,0}, 11)
draw_stones("st-greenbrown", {20,8}, {1,0}, 12)
draw_stones("st-greenbrown", {20,4}, {0,1}, 2)
draw_stones("st-greenbrown", {20,7}, {1,0}, 1)
draw_stones("st-greenbrown", {31,1}, {0,1}, 5)
draw_stones("st-greenbrown", {31,7}, {1,0}, 1)
draw_stones("st-greenbrown", {16,1}, {0,1}, 5)
draw_stones("st-greenbrown", {16,7}, {0,1}, 5)

fill_floor("fl-abyss", 6,0, 8,1)
fill_floor("fl-abyss", 7,1, 6,1)
fill_floor("fl-abyss", 8,2, 4,1)
fill_floor("fl-abyss", 9,3, 2,1)
fill_floor("fl-abyss", 9,9, 2,1)
fill_floor("fl-abyss", 8,10, 4,1)
fill_floor("fl-abyss", 7,11, 6,1)
fill_floor("fl-abyss", 6,12, 8,1)
fill_floor("fl-abyss", 7,13, 6,1)
fill_floor("fl-abyss", 8,14, 4,1)
fill_floor("fl-abyss", 9,15, 2,1)
fill_floor("fl-abyss", 9,21, 2,1)
fill_floor("fl-abyss", 8,22, 4,1)
fill_floor("fl-abyss", 7,23, 6,1)
fill_floor("fl-abyss", 6,24, 8,1)
fill_floor("fl-abyss", 7,18, 6,1)
fill_floor("fl-abyss", 32,1, 2,9)
fill_floor("fl-abyss", 20,1, 3,2)
fill_floor("fl-abyss", 21,4, 10,4)

set_stone( "st-timer", 24, 5, {action="callback", target="t_h1"})
set_stone( "st-timer", 25, 5, {action="callback", target="t_h2"})
set_stone( "st-timer", 26, 5, {action="callback", target="t_h3"})
set_stone( "st-timer", 27, 5, {action="callback", target="t_h4"})

timer = 0

function t_h1()
    bridgea=enigma.GetNamedObject("bridge1")
    bridgeb=enigma.GetNamedObject("bridge2")
    bridgec=enigma.GetNamedObject("bridge3")
    bridged=enigma.GetNamedObject("bridge4")

    if timer == 0 then
        enigma.SendMessage(bridgea, "close", nil)
     end
    if timer == 1 then
        enigma.SendMessage(bridgea, "open", nil)
    end
    if timer == 2 then
        enigma.SendMessage(bridgec, "close", nil)
    end
    if timer == 3 then
        enigma.SendMessage(bridgec, "open", nil)
    end
    if timer == 4 then
        enigma.SendMessage(bridgeb, "close", nil)
        enigma.SendMessage(bridged, "close", nil)
    end
    if timer == 5 then
        enigma.SendMessage(bridgeb, "open", nil)
    end
    if timer == 6 then
        enigma.SendMessage(bridged, "open", nil)
    end
    if timer == 7 then
        enigma.SendMessage(bridgec, "close", nil)
     end
    if timer == 8 then
        enigma.SendMessage(bridgea, "close", nil)
    end
    if timer == 9 then
        enigma.SendMessage(bridgec, "open", nil)
    end
    if timer == 10 then
        enigma.SendMessage(bridgea, "open", nil)
    end
    if timer == 11 then
        enigma.SendMessage(bridgeb, "close", nil)
        enigma.SendMessage(bridged, "close", nil)
    end
    if timer == 13 then
        enigma.SendMessage(bridgeb, "open", nil)
    end
    if timer == 14 then
        enigma.SendMessage(bridged, "open", nil)
    end
    if timer == 22 then
        enigma.SendMessage(bridgea, "close", nil)
     end
    if timer == 23 then
        enigma.SendMessage(bridgea, "open", nil)
    end
end

function t_h2()
    bridgea=enigma.GetNamedObject("bridge5")
    bridgeb=enigma.GetNamedObject("bridge6")
    bridgec=enigma.GetNamedObject("bridge7")
    bridged=enigma.GetNamedObject("bridge8")

    if timer == 7 then
        enigma.SendMessage(bridgea, "close", nil)
     end
    if timer == 8 then
        enigma.SendMessage(bridgea, "open", nil)
    end
    if timer == 9 then
        enigma.SendMessage(bridgec, "close", nil)
    end
    if timer == 10 then
        enigma.SendMessage(bridgec, "open", nil)
    end
    if timer == 11 then
        enigma.SendMessage(bridgeb, "close", nil)
        enigma.SendMessage(bridged, "close", nil)
    end
    if timer == 12 then
        enigma.SendMessage(bridgeb, "open", nil)
    end
    if timer == 13 then
        enigma.SendMessage(bridged, "open", nil)
    end
    if timer == 14 then
        enigma.SendMessage(bridgec, "close", nil)
     end
    if timer == 15 then
        enigma.SendMessage(bridgea, "close", nil)
    end
    if timer == 16 then
        enigma.SendMessage(bridgec, "open", nil)
    end
    if timer == 17 then
        enigma.SendMessage(bridgea, "open", nil)
    end
    if timer == 18 then
        enigma.SendMessage(bridgeb, "close", nil)
        enigma.SendMessage(bridged, "close", nil)
    end
    if timer == 19 then
        enigma.SendMessage(bridgeb, "open", nil)
    end
    if timer == 20 then
        enigma.SendMessage(bridged, "open", nil)
    end

    if timer == 30 then
        enigma.SendMessage(bridgea, "close", nil)
        enigma.SendMessage(bridgeb, "close", nil)
        enigma.SendMessage(bridgec, "close", nil)
        enigma.SendMessage(bridged, "close", nil)
    end
    if timer == 32 then
        enigma.SendMessage(bridgea, "open", nil)
        enigma.SendMessage(bridgeb, "open", nil)
        enigma.SendMessage(bridgec, "open", nil)
        enigma.SendMessage(bridged, "open", nil)
    end
end

function t_h3()
    bridgea=enigma.GetNamedObject("bridge9")
    bridgeb=enigma.GetNamedObject("bridge10")
    bridgec=enigma.GetNamedObject("bridge11")
    bridged=enigma.GetNamedObject("bridge12")

    if timer == 3 then
        enigma.SendMessage(bridgea, "close", nil)
     end
    if timer == 4 then
        enigma.SendMessage(bridgea, "open", nil)
    end
    if timer == 8 then
        enigma.SendMessage(bridgec, "close", nil)
    end
    if timer == 11 then
        enigma.SendMessage(bridgec, "open", nil)
    end
    if timer == 15 then
        enigma.SendMessage(bridgea, "close", nil)
     end
    if timer == 16 then
        enigma.SendMessage(bridgea, "open", nil)
    end
    if timer == 17 then
        enigma.SendMessage(bridgec, "close", nil)
    end
    if timer == 18 then
        enigma.SendMessage(bridgec, "open", nil)
    end
    if timer == 191 then
        enigma.SendMessage(bridgeb, "close", nil)
        enigma.SendMessage(bridged, "close", nil)
    end
    if timer == 20 then
        enigma.SendMessage(bridgeb, "open", nil)
    end
    if timer == 21 then
        enigma.SendMessage(bridged, "open", nil)
    end
    if timer == 22 then
        enigma.SendMessage(bridgec, "close", nil)
     end
    if timer == 23 then
        enigma.SendMessage(bridgea, "close", nil)
    end
    if timer == 24 then
        enigma.SendMessage(bridgec, "open", nil)
    end
    if timer == 25 then
        enigma.SendMessage(bridgea, "open", nil)
    end
    if timer == 26 then
        enigma.SendMessage(bridgeb, "close", nil)
        enigma.SendMessage(bridged, "close", nil)
    end
    if timer == 27 then
        enigma.SendMessage(bridgeb, "open", nil)
    end
    if timer == 28 then
        enigma.SendMessage(bridged, "open", nil)
    end
end

function t_h4()
    bridgea=enigma.GetNamedObject("bridge15")
    bridgeb=enigma.GetNamedObject("bridge16")

    if timer == 8 then
        enigma.SendMessage(bridgea, "close", nil)
    end
    if timer == 9 then
        enigma.SendMessage(bridgea, "open", nil)
    end
    if timer == 15 then
        enigma.SendMessage(bridgeb, "close", nil)
    end
    if timer == 16 then
        enigma.SendMessage(bridgeb, "open", nil)
    end
    timer = timer + 1
    if timer == 33 then
        timer = 0
    end
end

set_floor("fl-bridge", 8,5, {name="bridge1"})
set_floor("fl-bridge", 9,5, {name="bridge2"})
set_floor("fl-bridge", 10,5, {name="bridge3"})
set_floor("fl-bridge", 11,5, {name="bridge4"})
set_floor("fl-bridge", 8,6, {name="bridge5"})
set_floor("fl-bridge", 9,6, {name="bridge6"})
set_floor("fl-bridge", 10,6, {name="bridge7"})
set_floor("fl-bridge", 11,6, {name="bridge8"})
set_floor("fl-bridge", 8,7, {name="bridge9"})
set_floor("fl-bridge", 9,7, {name="bridge10"})
set_floor("fl-bridge", 10,7, {name="bridge11"})
set_floor("fl-bridge", 11,7, {name="bridge12"})
set_floor("fl-bridge", 10,17, {name="bridge15"})
set_floor("fl-bridge", 10,19, {name="bridge16"})

set_stone("st-bolder", 20,17, {direction=EAST})
set_stone("st-stoneimpulse", 23,17)
set_stone("st-stoneimpulse", 21,18)

oneway(22,18, enigma.NORTH)
oneway(27,1, enigma.EAST)

set_stones("st-glass", {{1,6},{1,12},{34,1},{34,2},{35,2},{36,1},{36,2}})
set_stones("st-glass", {{3,19},{3,12},{1,18},{2,18},{2,19},{1,20},{2,20}})

--draw_stones("st-greenbrown_hole", {23,18}, {1,0}, 1)
draw_stones("st-greenbrown", {23,18}, {1,0}, 15)
draw_stones("st-greenbrown", {21,19}, {0,1}, 4)
draw_stones("st-greenbrown", {23,20}, {1,0}, 13)
draw_stones("st-greenbrown", {22,22}, {1,0}, 14)
draw_stones("st-greenbrown", {36,20}, {0,1}, 3)
draw_stones("st-greenbrown", {19,15}, {1,0}, 19)
draw_stones("st-greenbrown", {19,18}, {1,0}, 2)
draw_stones("st-greenbrown", {4,18}, {1,0}, 2)
draw_stones("st-greenbrown", {14,18}, {1,0}, 2)
draw_stones("st-greenbrown", {15,20}, {1,0}, 2)
draw_stones("st-greenbrown", {20,10}, {1,0}, 18)
draw_stones("st-greenbrown", {15,16}, {1,0}, 2)
draw_stones("st-greenbrown_hole", {3,16}, {1,0}, 2)
draw_stones("st-greenbrown", {4,18}, {1,0}, 2)
draw_stones("st-greenbrown", {3,20}, {1,0}, 2)

set_item("it-spring1",4,2)
set_item("it-spring1",30,17)

doorv(19,19, {name="door1"})
set_item("it-trigger", 24,16, {invisible=1,action="open", target="door1"})
set_item("it-trigger", 37,16, {invisible=1,action="close", target="door1"})

set_attrib(laser(1,1, FALSE, SOUTH), "name", "laser")
set_stone("st-switch", 29,2, {action="onoff", target="laser"})

set_floor("fl-bridge", 9,17, {name="bridge13"})
set_item("it-trigger", 12,16, {target="bridge13", action="openclose"})
set_floor("fl-bridge", 9,19, {name="bridge14"})
set_item("it-trigger", 12,20, {target="bridge14", action="openclose"})
doorh(37,12, {name="door2"})
set_item("it-trigger", 12,18, {action="open", target="door2"})
set_item("it-trigger", 35,11, {invisible=1,target="door2", action="close"})

mirrorp(4,2,TRUE,FALSE, 1)
mirrorp(16,22,TRUE,FALSE, 3)
mirrorp(24,14,TRUE,FALSE, 1)
mirrorp(36,4,TRUE,FALSE, 1)
mirrorp(4,14,TRUE,FALSE, 3)
mirrorp(1,19,TRUE,FALSE, 2)

document(13,18, "Watch your step!")
document(35,17, "F3")
set_actor("ac-blackball", 32.5, 21.5, {player=0})
