################################################
#
# Dwarven Hall
#
# thematic branch based on Scandinavian folklore

## Lua
################################################

{{
dhfh = {}
dhfh.statues_idx = 0
dhfh.monster_from_statue = function(monster)
    dhfh.statues_idx = dhfh.statues_idx + 1
    local mod = MonsterOnTrigger:new {
        target="auto",
        new_monster="generate_awake " .. monster,
        message_seen="The granite statue comes to life!",
        message_unseen="You hear a distant wail.",
        master_name="statue" .. dhfh.statues_idx
    }
    return mod
end
dhfh.new_trigger = function(_type)
    return DgnTriggerer:new {
                        type   = _type,
                        target = "auto"
                      }
end

dhfh.hall_setup = function(e, glyph)
    local mod
    if (glyph == "|") then
        mod = dhfh.monster_from_statue("eidolon")
        mod:add_triggerer( dhfh.new_trigger("item_pickup") )
    else
        local new_monster
        if (crawl.x_chance_in_y(1, 3)) then
            new_monster="eidolon"
        else
            new_monster="freezing wraith"
        end

        mod = dhfh.monster_from_statue(new_monster)
        mod:add_triggerer( dhfh.new_trigger("item_pickup") )
    end
    e.lua_marker("G", portal_desc { desc="granite statue of a fallen hero",
            slaved_to="statue" .. dhfh.statues_idx})
    e.lua_marker(glyph, mod)
end
}}

## Branch entries
################################################

# Dummy entry
NAME:    enter_dwarf_dummy
TAGS:    dwarf_entry
KFEAT:   O = enter_dwarven_hall
MAP
O
ENDMAP

NAME:    enter_dwarf_1
TAGS:    dwarf_entry no_monster_gen
SUBST:   . = . ':7
COLOUR:  ' = yellow
FTILE:   ' = floor_sandstone
SUBST:   ' = .
KFEAT:   O = enter_dwarven_hall
MAP
.....
.'G'.
.'O'.
.'''.
.....
ENDMAP

NAME:    enter_dwarf_2
TAGS:    dwarf_entry no_monster_gen
SHUFFLE: CD / c+
COLOUR:  ' = yellow
COLOUR:  C = yellow
COLOUR:  D = yellow
SUBST:   D = =
SUBST:   C = c
FTILE:   =GO' = floor_sandstone
TILE:    c = wall_stone_dark
TILE:    D = wall_stone_black_marked
SUBST:   ' = .
KFEAT:   O = enter_dwarven_hall
MAP
.......
.ccDcc.
.c'G'c.
.C'O'C.
.c'''c.
.ccCcc.
.......
ENDMAP

NAME:    enter_dwarf_4
TAGS:    dwarf_entry no_monster_gen no_wall_fixup
WEIGHT:  10
CHANCE:  5%
COLOUR:  1 = yellow, ' = yellow, x = white
MONS:    dwarf w:30 / elf w:2 / war dog
FTILE:   1'xO = floor_sandstone
RTILE:   x = wall_tomb
KFEAT:   O = enter_dwarven_hall
MAP
.........
.xxxxxxx.
.x1'O'1x.
.x'''''x.
.x'x'x'x.
.xGx'xGx.
.xxx'xxx.
....'....
ENDMAP

NAME:    enter_dwarf_5
TAGS:    dwarf_entry no_monster_gen
COLOUR:  c = white, = = white, ' = yellow
RTILE:   c = wall_tomb, = = wall_tomb
FTILE:   ='GO = floor_sandstone
NSUBST:  = = 1:= / *:c
SUBST:   c : cx
KFEAT:   O = enter_dwarven_hall
MAP
   ...
  ..c..
 ..=c=..
..=cGc=..
.cc'O'cc.
..=c'c=..
 ..=c=..
  ..c..
   ...
ENDMAP

NAME:    enter_dwarf_6
TAGS:    dwarf_entry
MONS:    elf / w:5 deep dwarf / deep dwarf necromancer / \
         deep dwarf artificer
MONS:    shadow wraith / wraith / wight w:5 / troll / rock troll w:5 / \
         deep dwarf necromancer w:2 / deep dwarf artificer w:1
FTILE:   12O.A = floor_sandstone
# crawl will rotate for the rest of possibilities
NSUBST:  A = 1:= / *:c
FTILE:   =12O. = floor_limestone
FTILE:   @ = floor_sandstone
COLOUR:  12 = yellow
KFEAT:   O = enter_dwarven_hall
MAP
cccc@cccc
c1.....1c
c.ccccc.c
c.c.2.c.c
@.c.O.c.@
c.c...c.c
c.cAAcc.c
c1.....1c
cccc@cccc
ENDMAP

default-depth:

## Arrival maps
################################################

# Dummy arrival
NAME:   dhfh_arrival_dummy
TAGS:   extra dummy dhfh_arrival
MAP
{
ENDMAP

NAME:   dhfh_arrival_the_gate
TAGS:   extra patrolling no_wall_fixup dhfh_arrival
ORIENT: float
MONS:   nothing w:20 / deep dwarf / elf w:5
MONS:   wight / troll w:5 / deep dwarf necromancer w:2 / deep dwarf artificer w:1
MAP
x.........x
@.........@
x....2....x
x...1.1...x
x.G..1..G.x
x.........x
xxx+++++xxx
xxx.....xxx
xxx..[..xxx
xxx.....xxx
xxx..{..xxx
xxxx...xxxx
xxxxxxxxxxx
ENDMAP

NAME:   dhfh_arrival_statues
TAGS:   extra patrolling dhfh_arrival
ORIENT: float
KMONS:  1 = nothing w:30 / deep dwarf w:5 / wight w:2 / troll w:1
MAP
  ccccccc
  c.....c
  c..{..c
ccG.....Gcc
@1.......1@
ccG.....Gcc
@1.......1@
ccG.....Gcc
@1.......1@
ccG.....Gcc
  c.....c
  c@...@c
ENDMAP

NAME:   dhfh_arrival_fountains
TAGS:   no_rotate no_wall_fixup dhfh_arrival
ORIENT: float
SUBST:  f = T:40 V:40 U:20
KMONS:  1 = nothing w:50 / deep dwarf w:5 / wight w:2 / troll w:1
MAP
xxxx..@..xxxx
xf....G....fx
x...1.1.1...x
.............
@G..1.{.1..G@
.............
x...1.1.1...x
xf....G....fx
xxxx..@..xxxx
ENDMAP

NAME:   dhfh_arrival_gauntlet
TAGS:   no_rotate no_wall_fixup dhfh_arrival
ORIENT: float
SUBST:  f = T:40 V:40 U:20
KMONS:  1 = nothing / deep dwarf w:5 / wight w:2 / troll w:1
MAP
x@xxxxxxxxx@x
x...........x
x.xxxxxxxxx.x
x.x{......x.x
x.x.......x.x
x.x.......x.x
x.xxxG.Gxxx.x
x...........x
xx....1....xx
 xx.......xx
  xx1.f.1xx
   xx...xx
    xx.xx
     xxx
ENDMAP

NAME:   dhfh_arrival_vestibule
TAGS:   no_wall_fixup dhfh_arrival
ORIENT: float
WEIGHT: 5
SUBST:  f = T:40 V:40 U:20
KMONS:  1 = nothing / war dog / giant centipede / \
            deep dwarf w:5 / wight w:2 / troll w:1
KMONS:  2 = nothing / wight / troll w:5 / necrophage w:2
KMONS:  3 = nothing / orange rat / redback / wolf spider
FTILE:  . = floor_sandstone
SUBST:  ' = .
MAP
ccccccccccccccccccccccccccccccccc
 @'''''''''''''''''''''''''''''@
  c''vvvvvvvvvvvvvvvvvvvvvvv''c
   c''vv.................vv''c
    c''vv..1....{....1..vv''c
     c''vv.............vv''c
      c''vv..f..2..f..vv''c
       c''vv.........vv''c
        c''vv.......vv''c
         c''vvv+++vvv''c
          c''vv...vv''c
           c''..3..''c
            c''...''c
             c''.''c
              @...@
               @@@
ENDMAP

NAME:   dhfh_arrival_flooded
TAGS:   no_wall_fixup no_pool_fixup dhfh_arrival
WEIGHT: 5
ORIENT: float
SUBST:  W = W .:2
SUBST:  w = w W:2
MAP
xxxW@WWxx
xwWWWWWWx
xwwwwwwwx
xwwwwwwwx
xwwwwwwwx
xwwwwwwwx
xxwwwwwxx
 xxwwWxx
  xxWxx
xccc+cccx
xcG.W.Gcx
xc.....cx
xc..{..cx
xc.....cx
xcG...Gcx
xcccccccx
xxxxxxxxx
ENDMAP

## Treasure maps
################################################
NAME:    dhfh_treasure_sunken_tomb
TAGS:    dhfh_treasure no_item_gen no_monster_gen no_pool_fixup no_wall_fixup
WEIGHT:  40
ORIENT:  float
MONS:    deep dwarf w:30 / elf w:3
MONS:    deep dwarf w:20 / elf w:3
MONS:    generate_awake giant centipede / generate_awake redback / \
generate_awake wolf spider w:8 / generate_awake war dog w:8
MONS:    generate_awake wight w:20 / generate_awake troll / \
generate_awake orange rat
MONS:    deep dwarf w:20 / elf w:3 / wight w:2
MONS:    deep dwarf / elf w:3 / wight w:2 / troll w:5 / orc priest / deep elf priest w:5
MONS:    orc priest / deep elf priest w:3
SUBST:   p = T:40 V:40 U:20
SUBST:   . = .:92 ~:5 ^:1 %:1 *:1
SUBST:   q = q:66 ~:33 ^:1
KFEAT:   q = alarm trap
MARKER:  + = lua:restrict_door()
ITEM:    box of beasts / empty ebony casket
ITEM:    any weapon
ITEM:    amulet of faith / \
         any jewellery / any weapon ego:holy_wrath / any weapon / \
         potion of experience w:1 / potion of porridge / any potion / \
         scroll of holy word / scroll of torment / any scroll
ITEM:    potion of porridge
MAP
        xxxxxxxxxxxxxxxxxxxx
        xxxxxxxxxxxxgxxxxxxx
        xxxxxxxxxx1111xxxxxx
        xxxx.x.x111..111xxxx
        xx...+.........111xx
xxxxxxxxx....xxxxxxxxx...11x
xxxxxx.....xxx.......x...1xx
xxxx.....xxx...xxxx..+...xxx
x......xxxx....xqxx..x..xxxx
x..xxxxx55xxx..xe3...xx.xxxx
x...xx6666xxx+xxxxxxxxccccxx
xx..x55x+xxxx......q.cc||cxx
xxx+xxxx....xxxC7.xc+cG4$ccx
 xx..xx.......xx55xc4.C..dcx
 xx..3+........xffxcccG4.4cx
 xxx+xx........xxxx.xccccccx
 x....x.............+q3.xxxx
 xxxxxxxxxx.........xx..exxx
 x........+..........xxxxxxx
 x........x.....p....x
 x..xxxxxxxx.........x
 x..xxxxxxxxx........x
 x..xxxxxxxxxx......xx
 x222222xxxxxx.....xxx
 x22222gxxxxxxx.....xx
 xxxxxxxxxxxxxxx....xx
               xx.@..x
ENDMAP

NAME:   dhfh_treasure_vault
TAGS:   dhfh_treasure no_item_gen no_monster_gen no_wall_fixup no_rotate
ORIENT: float
WEIGHT: 15
MONS:   deep dwarf
MONS:   troll w:20, elf, wight
MONS:   wight
MONS:   patrolling deep dwarf
NSUBST: X = 2:= / *:x
MARKER: = = lua:restrict_door()
SUBST:  * = **d
ITEM:   staff of death / scroll of torment / necronomicon w:1
MAP
cccccccccccccccccccc@cccccccccccccccccccc
c$X...x............x.x............x...X$c
c*X1...........x.4.x.x.4.x...........2X.c
c.X*..x........x...G.G...x........x..1X.c
c.X1..x........x.G.....G.x........x..*X.c
c.X2........xxxxxx..4..xxxxxx........1X*c
c$X...x........$$x.....x$$........x...X$c
cccccccccccccccccccc@cccccccccccccccccccc
ENDMAP

NAME:   dhfh_treasure_sunken_vault
TAGS:   dhfh_treasure no_item_gen no_monster_gen no_wall_fixup no_rotate
ORIENT: float
WEIGHT: 5
MONS:   wight
MONS:   necrophage
MONS:   orange rat
MONS:   war dog
SUBST:  $ = $$d
ITEM:   any weapon ego:draining / any armour ego:positive_energy / \
        staff of death / scroll of torment / necronomicon w:1
MAP
..xxx@<xxxxx
............
.xxxxxxxx3x.
.3.....xx.x.
.xxxxxx4x.x.
.xx4x$$xx.x.
.x.x$22$x.x.
.x.x$12$x.x.
.x.xx$$x4xx.
.x.x4xxxxxx.
.x.xx.....3.
.x3xxxxxxxx.
............
ENDMAP

## guardhouses
################################################
NAME:   dhfh_guard_house_d2
TAGS:   dhfh_guard_house allow_dup
DEPTH:  Dwarf:1
NSUBST: C = 1:@ / *:c
NSUBST: S = 1:= / *:c
KITEM:  * = % w:20 / * / $
SUBST:  1 = 2 w:2 / 1 / .
KMONS:  1 = patrolling deep dwarf berserker w:5 / \
            patrolling deep dwarf scion / patrolling deep dwarf death knight w:5 / \
            patrolling deep dwarf artificer / patrolling deep dwarf necromancer w:5
KMONS:  2 = patrolling deep dwarf death knight / \
            patrolling unborn deep dwarf w:2
MAP
cccc  cccc
c*.c  c.*c
c.SccccS.c
ccc1..1ccc
  c.1..c
  c..1.c
ccc1..1ccc
c.ScCCcS.c
c*.c..c.*c
cccc@.cccc
ENDMAP

NAME:   dhfh_guard_house_d3
TAGS:   dhfh_guard_house allow_dup
DEPTH:  Dwarf:1
NSUBST: C = 1:@ / *:c
NSUBST: S = 1:= / *:c
KITEM:  * = % w:20 / * / $
SUBST:  1 = 2 w:2 / 1 / .
KMONS:  1 = patrolling deep dwarf berserker / \
            patrolling deep dwarf scion w:7 / patrolling deep dwarf death knight / \
            patrolling deep dwarf artificer w:5 / patrolling deep dwarf necromancer w:3
KMONS:  2 = patrolling deep dwarf death knight / patrolling unborn deep dwarf
MAP
cccc  cccc
c*.c  c.*c
c.SccccS.c
ccc1..1ccc
  c.1..c
  c..1.c
ccc1..1ccc
c.ScCCcS.c
c*.c..c.*c
cccc@.cccc
ENDMAP

NAME:   dhfh_guard_house_d4
TAGS:   dhfh_guard_house allow_dup
DEPTH:  Dwarf:1
NSUBST: C = 1:@ / *:c
NSUBST: S = 1:= / *:c
KITEM:  * = % w:20 / * / $
SUBST:  1 = 2 w:2 / 1 / .
KMONS:  1 = patrolling deep dwarf berserker / \
            patrolling deep dwarf scion w:1 / patrolling deep dwarf death knight / \
            patrolling deep dwarf artificer w:1 / patrolling deep dwarf necromancer w:1
KMONS:  2 = patrolling deep dwarf death knight w:3 / \
            patrolling unborn deep dwarf
MAP
cccc  cccc
c*.c  c.*c
c.SccccS.c
ccc1..1ccc
  c.1..c
  c..1.c
ccc1..1ccc
c.ScCCcS.c
c*.c..c.*c
cccc@.cccc
ENDMAP

## the main hall
################################################
NAME:  dhfh_hall_top
TAGS:  dhfh_hall_top allow_dup no_rotate no_hmirror no_vmirror
: dhfh.hall_setup(_G, "|")
MAP
G
|
ENDMAP

NAME:  dhfh_hall_left
TAGS:  dhfh_hall_left allow_dup no_rotate no_hmirror no_vmirror
KITEM: * = any scroll / any potion / any book w:2 / any rod w:1 / any jewellery w:3 / \
           w:2 any misc / any level:20 weapon / w:3 any level:20 armour
: dhfh.hall_setup(_G, "*")
MAP
G*
ENDMAP

NAME:  dhfh_hall_right
TAGS:  dhfh_hall_right allow_dup no_rotate no_hmirror no_vmirror
KITEM: * = any scroll / any potion / any food / any book w:2 / any jewellery w:3 / \
           w:2 any misc / any level:20 weapon / w:3 any level:20 armour
: dhfh.hall_setup(_G, "*")
MAP
*G
ENDMAP

NAME:     dhfh_hall
TAGS:     no_monster_gen no_item_gen no_wall_fixup
ORIENT:   northwest
PLACE:    Dwarf
NSUBST:   s = 1:= / *:c
MARKER:   = = lua:restrict_door()
SUBST:    ? = w * |:3
KITEM:    w : wand of heal wounds
SUBVAULT: O : dhfh_hall_top
SUBVAULT: Z : dhfh_hall_left
SUBVAULT: Y : dhfh_hall_left
SUBVAULT: X : dhfh_hall_left
SUBVAULT: W : dhfh_hall_left
SUBVAULT: A : dhfh_hall_right
SUBVAULT: B : dhfh_hall_right
SUBVAULT: C : dhfh_hall_right
SUBVAULT: D : dhfh_hall_right
KMONS:    1 = patrolling unborn deep dwarf w:5 / \
              patrolling deep dwarf death knight / patrolling deep dwarf necromancer
KMONS:    2 = shadow wraith / freezing wraith / troll / rock troll w:5 / \
              patrolling deep dwarf death knight w:3 / patrolling deep dwarf necromancer w:2 / \
              patrolling unborn deep dwarf w:1
{{
  hook("post_place", function()
    dgn.place_maps{tag="dhfh_arrival"}
    dgn.place_maps{tag="dhfh_treasure"}
  end)
}}
MAP
 ccccccccccc
 c....O....c
 c.2..O..2.c
 c....1....cccc
 c....1....s..c
cccccG.Gcccsc.c
cZZ.c...c.AAs.c
c.....1.....c.cccccccc
c...........c.s.s...Uc
cYY.c.1.c.BBs.ccc....c
c...........c...c.2..c
c.1...2...1.c..2+..2.c
c...........c..2c.2.?c
cXX.c.1.c.CCs.cccccccc
c...........c.c
c...........c.c
cWW.c.1.c.DDs.c
cccccc.ccccsc.c
   c.....s....c
   c..<..cccccc
   c.....c
   ccc@ccc
ENDMAP

NAME:   dhfh_barracks_1
TAGS:   extra uniq_dhfh_barracks chance_dhfh_barracks
ORIENT: float
CHANCE: 50%
DEPTH:  Dwarf:1
MONS:   elf w:5 / deep dwarf / deep dwarf necromancer / \
        deep dwarf berserker
MONS:   shadow wraith / wraith / wight w:5 / troll / rock troll w:5 / \
        deep dwarf necromancer w:2 / deep dwarf scion w:1
SUBST:   1 = d f:5 g:2 j:1
KMONS:   d = deep dwarf / deep dwarf scion
KMONS:   f = deep dwarf necromancer
KMONS:   g = deep dwarf berserker
KMONS:   h = deep dwarf ; potion of porridge
KMONS:   j = deep dwarf necromancer ; potion of porridge
SUBST:   2 = l m:5 p:2 r:1
KMONS:   l = patrolling deep dwarf necromancer
KMONS:   m = patrolling deep dwarf berserker
KMONS:   p = patrolling deep dwarf ; potion of porridge
KMONS:   r = patrolling deep dwarf necromancer ; potion of porridge
KMONS:   3 = generate_awake wight w:20 / generate_awake troll / \
             generate_awake orange rat
KMONS:   5 = mermaid
KFEAT:   5 = shallow_water
SUBST:   F = T:40 V:40 U:20
SUBST:   W = W .
SUBST:   P = %:25 $ *:2 P:3 R:1 D:1 M:1
KITEM:   P = potion of porridge
KITEM:   D = deck of changes / deck of war / deck of defence / \
             deck of destruction w:1 / deck of dungeons w:1 / deck of wonders w:5
KITEM:   R = any potion / potion of poison w:3 / \
             potion of strong poison w:1 / any scroll / scroll of acquirement w:1 / \
             scroll of random uselessness
KITEM:   M = manual of Fighting / manual of Dodging / manual of Armour / \
             manual of Unarmed Combat / manual of Spellcasting w:1 / \
             manual of Invocations w:1
KFEAT:   ? = any shop
SUBST:   & = .:15 G H I
KITEM:   G = griffon corpse
KITEM:   H = sheep corpse
KITEM:   I = deep troll corpse
MARKER:  + = lua:restrict_door()
: dgn.delayed_decay(_G, 'G', 'griffon corpse')
: dgn.delayed_decay(_G, 'H', 'hell hound corpse')
: dgn.delayed_decay(_G, 'I', 'deep troll corpse')
MAP
            cccccccccccccc
xxxxxxxxxxxxcFW....nFnFnFc
x...........cWW.....W5WWWc
x1P.P1P1P.P1ccccc..ccccccc
x.........................
x1P.P1P1P.P1.2..........3@
x.........................
x1P.P1P1P.P1cc.ccccc..cccc
x...........c.2.c...22...c
xxxxxxxxxxxxc.?.c........c
            c...c.xxxxxx.c
            ccccc..1..1..c
                c+nnnnnn+c
                c&&&&&&&&c
                cccccccccc
ENDMAP

NAME:   dhfh_barracks_2
TAGS:   extra uniq_dhfh_barracks chance_dhfh_barracks
ORIENT: float
CHANCE: 50%
DEPTH:  Dwarf:1
MONS:   elf w:5 / dwarf / deep dwarf necromancer / \
        deep dwarf berserker
MONS:   shadow wraith / wraith / wight w:5 / troll / rock troll w:5 / \
        deep dwarf necromancer w:2 / deep dwarf scion w:1
SUBST:   1 = d f:5 g:2 j:1
KMONS:   d = deep dwarf / deep dwarf scion
KMONS:   f = deep dwarf necromancer
KMONS:   g = deep dwarf berserker
KMONS:   h = deep dwarf ; potion of porridge
KMONS:   j = deep dwarf necromancer ; potion of porridge
SUBST:   2 = l m:5 p:2 r:1
KMONS:   l = patrolling deep dwarf necromancer
KMONS:   m = patrolling deep dwarf berserker
KMONS:   p = patrolling deep dwarf ; potion of porridge
KMONS:   r = patrolling deep dwarf necromancer ; potion of porridge
KMONS:   3 = generate_awake wight w:20 / generate_awake troll / \
             generate_awake orange rat
NSUBST:  s = 1:= / *:c
SUBST:   F = T:40 V:40 U:20
SUBST:   W = W .
SUBST:   P = %:25 $ *:2 P:3 R:1 D:1 M:1
KITEM:   P = potion of porridge
KITEM:   D = deck of changes / deck of war / deck of defence / \
             deck of destruction w:1 / deck of dungeons w:1 / deck of wonders w:5
KITEM:   R = any potion / potion of poison w:3 / \
             potion of strong poison w:1 / any scroll / scroll of acquirement w:1 / \
             scroll of random uselessness
KITEM:   M = manual of Fighting / manual of Dodging / manual of Armour / \
             manual of Unarmed Combat / manual of Spellcasting w:1 / \
             manual of Invocations w:1
KITEM:   Q = potion of water / potion of poison / potion of strong poison / \
             bottled efreet w:1
KFEAT:   ? = any shop
KFEAT:   & = food shop
MARKER:  = = lua:restrict_door()
KFEAT:   8 = granite_statue
MAP
cccccccccccc.@.ccccc
c1P1P1P1P1Pc...c...c
c..........c....2?.c  ccccc
c.1P1P1P1P.+2..c...c  c...c
c..........c...ccccc  c.!.c
c.F.8..8.F.c...sQc    c.2.c
ccccc22ccccc...csccccccc.cc
...........................
@3...........3............@
...........................
ccccccccccsc...cscccccccccc
         cQs...sQc
         ccc...ccc
           c...c
           c...c
           c.3.c
           c.@.c
ENDMAP
