<?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="Meditation in Peace" el:subtitle="Funeral on Deep Sea" el:id="20070502ral466"/>
      <el:version el:score="1" el:release="1" el:revision="$Revision: 70 $" el:status="released"/>
      <el:author  el:name="Ronald Lamprecht" el:email="ral@users.berlios.de"/>
      <el:copyright>Copyright © 2006 Ronald Lamprecht</el:copyright>
      <el:license el:type="GPL v2.0 or above" el:open="true"/>
      <el:compatibility el:enigma="1.00">
      </el:compatibility>
      <el:modes el:easy="true" el:single="true" el:network="false"/>
      <el:comments>
        <el:credits el:showinfo="false" el:showstart="false">Thanks to Nat Pryce for his libs and code examples</el:credits>
        <el:code>Lua 5.1</el:code>
      </el:comments>
      <el:score el:easy="2:10" el:difficult="4:27"/>
    </el:info>
    <el:luamain><![CDATA[
enigma.ConserveLevel = TRUE
math_floor = floor

set_oxyd = oxyd

function oxyd( x, y, tiles )
    return set_oxyd( x, y )
end

function nothing(x, y, tiles)
    -- create nothing
end

function horizontal_bolder(x,y,tiles)
    if random() >= 0.5 then
        return set_stone( "st-bolder-w", x, y )
    else
        return set_stone( "st-bolder-e", x, y )
    end
end

function vertical_bolder(x,y,tiles)
    if random() >= 0.5 then
        return set_stone( "st-bolder-n", x, y )
    else
        return set_stone( "st-bolder-s", x, y )
    end
end

function checkerboard_floor( type1, type2, attribs1, attribs2 )
    return function( x, y, tiles )
        if mod(x,2) == mod(y,2) then
            return set_floor( type1, x, y, attribs1 or {} )
        else
            return set_floor( type2, x, y, attribs2 or {} )
        end
    end
end

function floor( floor_type, attribs )
    return function( x, y, tiles )
        return set_floor( floor_type, x, y, attribs or {} )
    end
end

function stone( stone_type, attribs )
    return function( x, y, tiles )
        return set_stone( stone_type, x, y, attribs or {} )
    end
end

function item( item_type, attribs )
    return function( x, y, tiles )
        return set_item( item_type, x, y, attribs or {} )
    end
end

function actor( actor_type, attribs )
    return function( x, y, tiles )
        if (actor_type == "ac-whiteball-small") then
            return set_actor( actor_type, x+0.5, y, attribs or {} )
        else
            return set_actor( actor_type, x+0.5, y+0.5, attribs or {} )
        end
    end
end

function gradient( gradient_type )
    return function( x, y, tiles )
        return set_floor( "fl-gradient", x, y, {type=gradient_type} )
    end
end

function inherit(tile_type)
    return function( x, y, tiles )
        return create_tile( tiles, x, y, tile_type )
    end
end

function group( array, constructor )
    return function( x, y, tiles )
        object = constructor( x, y, tiles )
        tinsert( array, object )
        return object
    end
end

function difficulty( d, constructor )
    if options.Difficulty == d then
        return constructor
    else
        return nothing
    end
end

function create_world_from_map( tiles, map )
    create_world( strlen(map[1]), getn(map) )

    for y = 1,getn(map) do
        local line = map[y]
        for x = 1,strlen(line) do
            local tile = strchar(strbyte(line,x))
            create_tile( tiles, x-1, y-1, tile )
        end
    end
end

function create_tile( tiles, x, y, tile_type )
    local constructors = tiles[tile_type]

    if constructors then
    for i = 1,getn(constructors) do
        constructors[i](x,y,tiles)
    end
    else
    error("invalid tile identifier " .. tile_type )
    end
end

tiles = {}
tiles[" "] = {floor("fl-wood")}
tiles["~"] = {floor("fl-water")}
tiles["T"] = {inherit("~"), stone("st-timer",{invisible=1, interval=0.1, action="callback", target="wave"})}
if (difficult) then
  tiles["#"] = {inherit("~"), stone("st-grate3")}
else
  tiles["#"] = {inherit(" "), stone("st-metal")}
end
tiles["M"] = {inherit(" "), stone("st-metal")}
tiles["dy"] = {inherit(" "), item("it-dynamite")}
tiles["d"] = {inherit("dy"), stone("st-block")}
tiles["wo1"] = {inherit(" "), item("it-wormhole", {targetx=7.5, targety=1.5, strength=5, range=1})}
tiles["wo2"] = {inherit(" "), item("it-wormhole", {targetx=13.5, targety=4.5, strength=5, range=1})}
tiles["wo3"] = {inherit(" "), item("it-wormhole", {targetx=5.5, targety=6.5, strength=5, range=1})}
tiles["wo4"] = {inherit(" "), item("it-wormhole", {targetx=10.5, targety=10.5, strength=5, range=1})}
tiles["A"] = {inherit("wo1"), stone("st-block")}
tiles["B"] = {inherit("wo2"), stone("st-block")}
tiles["C"] = {inherit("wo3"), stone("st-block")}
tiles["D"] = {inherit("wo4"), stone("st-block")}
tiles["h"] = {inherit(" "), item("it-hollow", {essential=1})}
tiles["S"] = {inherit(" "), item("it-spade")}
tiles["P"] = {inherit(" "), item("it-pin")}
tiles["t"] = {inherit(" "), item("it-document", {text="Health"})}

tiles["1"] = {inherit(" "), actor("ac-blackball", {name="black", essential=1, player=0, controllers=1})}
tiles["2"] = {inherit(" "), actor("ac-whiteball-small", {essential=1, player=0, controllers=0})}
tiles["3"] = {inherit("M"), actor("ac-whiteball", {essential=0, player=0, controllers=1, name="white"})}

postinit = 0
time = 5
dir = 1
function wave()
    -- ugly workaround to use spikes for the black marble without giving
    -- a chance to use a pin for the small white marbles
    -- the white marble is needed to avoid level restarts
    if (postinit == 1 and not difficult) then
        enigma.SetAttrib(enigma.GetNamedObject("black"), "player", 0)
        postinit = 2
    end
    if (postinit == 0 and not difficult) then
        enigma.SetAttrib(enigma.GetNamedObject("black"), "player", 1)
        set_item("it-pin", enigma.GetPos(enigma.GetNamedObject("black")))
        postinit = 1
    end

    -- the deep sea
    if (difficult) then
        enigma.AddConstantForce(dir * 40,0)
    else
        enigma.AddConstantForce(dir * 30,0)
    end
    time = time + 1;
    if (time == 10) then
        time = 0
        dir = -dir
    end
end

create_world_from_map( tiles, {
"T#                #~ ",
"~#   t  S   1     #~",
"~#              Cd#~",
"~#dD         h    #~",
"~#                #~",
"~#                #~",
"~#        h       #~",
"~#                #~",
"~#dA              #~",
"~#   h          Bd#~",
"~#                #~",
"~#                #~",
"~#      2222      #~3"
})

--set_actor("ac-whiteball-small", 5.5, 9.5, {essential=1, player=0, controllers=0})
oxyd_shuffle()

    ]]></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:translation el:lang="de">Bestattung auf hoher See</el:translation>
      </el:string>
      <el:string el:key="Health">
        <el:english el:translate="true" >Warning: Do not play this level for more than 10 minutes - you may suffer sea sickness yourself!</el:english>
        <el:translation el:lang="de">Warnung: Spielen Sie diesen Level nicht für mehr als 10 Minuten - Sie können selber an Seekrankheit leiden!</el:translation>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
