<?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="Rhapsody on Cracks" el:subtitle="The real value of coffee" el:id="20060510ral008"/>
      <el:version el:score="1" el:release="1" el:revision="$Revision: 42 $" 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="0.92"/>
      <el:modes el:easy="true" el:single="true" el:network="false"/>
      <el:score el:easy="1:16" el:difficult="1:52"/>
    </el:info>
    <el:luamain><![CDATA[
enigma.ConserveLevel = FALSE
if difficult then
    enigma.Brittleness = 0.95
else
    enigma.Brittleness = 0.75
end

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 )
        return set_actor( actor_type, x+0.5, y+0.5, attribs or {} )
    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

oxyd_default_flavor = "a"

tiles = {}
tiles[" "] = {floor("fl-bluegray")}
tiles["."] = {floor("fl-abyss")}
tiles["c"] = {inherit(" "), item("it-crack1")}
tiles["s"] = {inherit(" "), item("it-spring2")}
tiles["p"] = {inherit(" "), item("it-coin1")}
tiles["n"] = {inherit(" "), item("it-coin2")}
tiles["d"] = {inherit(" "), item("it-coin4")}
tiles["k"] = {inherit(" "), item("it-coffee")}
tiles["w"] = {inherit(" "), item("it-seed")}
tiles["#"] = {inherit(" "), stone("st-glass")}
tiles["m"] = {inherit(" "), stone("st-mail-e")}
tiles["-"] = {inherit("#"), item("it-pipe-h")}
tiles["|"] = {inherit("#"), item("it-pipe-sw")}
tiles["W"] = {inherit(" "), item("it-wormhole",{strength=2,targetx="10.5",targety="2.5"})}
tiles["a"] = {inherit(" "), stone("st-door-h", {name="doorA"})}
tiles["A"] = {inherit(" "), stone("st-coinslot", {action="openclose", target="doorA"})}
tiles["b"] = {inherit(" "), stone("st-door-h", {name="doorB"})}
tiles["B"] = {inherit(" "), stone("st-switch", {action="openclose", target="doorB"})}
tiles["D"] = {inherit(" "), item("it-floppy")}
tiles["f"] = {inherit(" "), stone("st-door-v", {name="doorF"})}
tiles["F"] = {inherit(" "), stone("st-floppy", {action="openclose", target="doorF"})}
tiles["r"] = {inherit(" "), item("it-key_a")}
tiles["t"] = {inherit(" "), stone("st-door-v", {name="doorT"})}
tiles["T"] = {inherit(" "), stone("st-key_a", {action="openclose", target="doorT"})}
tiles["h"] = {inherit(" "), stone("st-door-v", {name="doorH"})}
tiles["H"] = {inherit(" "), stone("st-switch", {action="openclose", target="doorH"})}
tiles["g"] = {inherit(" "), stone("st-door-v", {name="doorG"})}
tiles["G"] = {inherit(" "), stone("st-floppy", {action="openclose", target="doorG"})}

if difficult then
    tiles["e"] = tiles[" "]
    tiles["y"] = tiles[" "]
    tiles["z"] = {inherit(" "), item("it-coin4")}
else
    tiles["e"] = {inherit(" "), item("it-spring2")}
    tiles["z"] = tiles[" "]
    tiles["y"] = {inherit(" "), item("it-coin4")}
end


tiles["x"] = {inherit(" "), oxyd}

tiles["1"] = {inherit(" "), actor("ac-blackball", {player=0})}

function nocompress()
    kill_stone(1, 6)
end

create_world_from_map( tiles, {
"####################",
"#    ...    ...   c#",
"# W  ... ep ...  1 #",
"#    ...    ... s  #",
"#   #####m-|########",
"#        cc        #",
"#        cc        #",
"#        cc        #",
"##b##############aA#",
"#p # y# dxx D#  #k #",
"#n t  g zxx  h  fk B",
"#D TwwG dxx  #r F  #",
"#####H#xx##xx#######"
})
oxyd_shuffle()
]]></el:luamain>
    <el:i18n>
    </el:i18n>
  </el:protected>
</el:level>

