###############################################################################
# Grated Community (by Mu, cleaned up by regret-index.)
#
# A few creatures have built their own little community deep underground,
# complete with quaint little homes and a handful of local shops.
#
# Digging or teleportation is required to enter the vault.  A wand of digging
# and scroll of teleportation is guaranteed to ensure random teleporters can
# escape. If all else fails, there is an escape hatch in the mall's washroom.

: crawl_require('dlua/vault.lua')

{{
function grated_community_house_setup(e)
  e.tags("grated_community_mu_home")
  e.tags("unrand")
  e.tags("allow_dup")
  e.tags("luniq")
  e.kfeat("- = +")
  e.marker("- = lua:restrict_door()")
  single_cloud(e, "#", "flame", false)
  if you.in_branch("D") then
    e.ftile("' = floor_vault")
  else
    e.ftile("' = floor_metal_gold")
  end
end
}}

default-depth: D:12-, !D:$, Vaults, !Vaults:$

NAME:   index_mu_grated_community
TAGS:   no_rotate no_monster_gen no_item_gen no_descent
TAGS:   vaults_hard vaults_orient_s no_wall_fixup
ORIENT: float
WEIGHT: 30 (Vaults), 10
: if you.in_branch("D") then
MONS:   patrolling human, patrolling acid dragon, patrolling centaur
MONS:   patrolling tengu warrior, patrolling two-headed ogre
MONS:   patrolling deep elf pyromancer / patrolling deep elf archer w:6
MONS:   ettin / frost giant / stone giant / yaktaur captain w:2
KMONS:  8 = orc knight
KMONS:  90 = arcanist / occultist / necromancer / deep elf knight / \
             orc priest / gargoyle / centaur / yaktaur / vampire /  \
             troll / cyclops / manticore / basilisk / warg
SUBST:  9 = 9.., 0 = 0"", z = c
: else -- Vaults
MONS:   patrolling vault guard, patrolling dire elephant
MONS:   patrolling centaur warrior band
MONS:   patrolling great orb of eyes, patrolling ettin
MONS:   patrolling ironbound mechanist / patrolling ironbound frostheart
MONS:   vault warden / ironbound thunderhulk / \
        fire giant w:2 / frost giant w:2 / deep elf annihilator w:2
KMONS:  8 = orc warlord / war gargoyle w:2
KMONS:  90 = harpy / deep troll / yaktaur / entropy weaver / arcanist / \
             ogre mage / polterguardian / crawling flesh cage
SUBST:  9 = 9., 0 = 0", x = b
CLEAR:  z
: end
KMONS:  ! = generate_awake lemure
ITEM:   human skeleton / elf skeleton / kobold skeleton
: kitem("$ = q:" .. crawl.random_range(75, 450) .. " gold")
KFEAT:  g = iron_grate
KFEAT:  A = general shop
KFEAT:  B = scroll shop type:Wondrous suffix:Manuscripts count:10 \
            greed:35 ; scroll of torment | scroll of vulnerability | \
            scroll of noise | scroll of poison | scroll of immolation | \
            scroll of silence
KFEAT:  C = distillery shop type:Miraculous suffix:Elixirs count:10 \
            greed:35 ; potion of mutation | potion of attraction | \
            potion of berserk rage | potion of moonshine | \
            potion of lignification | potion of cancellation
# Moved back into the main vault. Nicolae's Legendary Smithy sells randarts, but
# with a guaranteed downside. It's still possible to find something usable, if
# you don't care about the downside or can make up for it with other things.
{{
local badprops = {"EV:-5", "Str:-6", "Int:-6", "Dex:-6", "Slay:-4", "rF:-1",
  "rC:-1", "Will:-1", "*Silence", "-Tele", "*Corrode", "*Slow", "MP:-9"}
local armours = {"plate armour", "chain mail", "kite shield", "tower shield",
                 "helmet"}
local inventory = {}
for i = 1,7 do
  local newthing = util.random_from(armours) .. " randart artprops:" ..
                   util.random_from(badprops)
  table.insert(inventory, newthing)
end
local inventorytext = table.concat(inventory, " | ")
local smithy = string.gsub(crawl.make_name(), " ", "_")
kfeat("D = armour shop name:The_Legendary_" .. smithy ..
      " type:Legendary suffix:Smithy count:7 greed:35 use_all ; " ..
      inventorytext)
}}
SHUFFLE:  KLMNOPQR
SUBVAULT: K : grated_community_mu_home_escape
SUBVAULT: L : grated_community_mu_home
SUBVAULT: M : grated_community_mu_home
SUBVAULT: N : grated_community_mu_home
SUBVAULT: O : grated_community_mu_home
SUBVAULT: P : grated_community_mu_home
SUBVAULT: Q : grated_community_mu_home
SUBVAULT: R : grated_community_mu_home
SUBST:    KLMNOPQR = .
KPROP:    ! = no_tele_into
TILE:     c = wall_stone_smooth
TILE:     x = wall_brick_vines
FTILE:    "?tG = floor_grass_dark
COLOUR:   "?t = green
: single_cloud(_G, "#", "flame", false)
: if you.in_branch("D") then
FTILE:    .d$ABCDTU123456780H+g = floor_vault
: else
FTILE:    .d$ABCDTU123456780H+g = floor_metal_gold
: end
MAP
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
zxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcccccccccccccccz
zx00""""""""00""""""""00"""""""""."""cccccccccccccccz
zx00""""""""00""""""""00""""""""...""Gc..........g!cz
zx""KKKKKKK"""LLLLLLL"""MMMMMMM"..."""n..........cccz
zx""KKKKKKK"""LLLLLLL"""MMMMMMM"......+..........g!cz
zx""KKKKKKK"""LLLLLLL"""MMMMMMM"......+.9.......9cccz
zx""KKKKKKK"""LLLLLLL"""MMMMMMM"...""cn.99.....99g!cz
zx""KKKKKKK"""LLLLLLL"""MMMMMMM"......+.9.......9cccz
zx""KKKKKKK"""LLLLLLL"""MMMMMMM"......+..........g!cz
zx""KKKKKKK"""LLLLLLL"""MMMMMMM"..."""n..........cccz
zx""......K.9.......L.9.......M....""Gcccc+c.9.c+cccz
zx""."t"t".9T9."t"t".7T9."t"t".....""ccWc..c.99c..4cz
zx""......N.9.......O.9.......P....""cc..5.c99.c4A.cz
zx""NNNNNNN...OOOOOOO"""PPPPPPP"...""cc....c.9.c..4$z
zx""NNNNNNN.".OOOOOOO"""PPPPPPP"...""cc#c..c...cccccz
zx""NNNNNNN.t.OOOOOOO"""PPPPPPP"...""ccccc.c...cWcWcz
zx""NNNNNNN.".OOOOOOO"""PPPPPPP"...""cc....c...+.>.cz
zx""NNNNNNN.t.OOOOOOO"""PPPPPPP"...""c$.D7.c...cWcWcz
zx""NNNNNNN.".OOOOOOO"""PPPPPPP"...""ccccccc.9.cccccz
zx""NNNNNNN...OOOOOOO"""PPPPPPP"...""c$....c999c.d.cz
zx""""""""".9.""""""""""""""""""...""cc.6.6c.9.nd.dcz
zx00"""""""9T9"""""""""""""""""""."."cc.U6.c...n.d.cz
zx00""""""".9."""""""""""""""""""".".cc....c...n...cz
zx""QQQQQQQQ.RRRRRRRR""xxxxxxxxxxxx."cc6C..c.7.cc+ccz
zx""QQQQQQQ.".RRRRRRR""xccccccccccx".cc....c...c...cz
zx""QQQQQQQ.t.RRRRRRR""xc1......3cx."cc.U..c.9.c5.5cz
zx""QQQQQQQ.".RRRRRRR""xc.c+cc+c.cx".cc....c...+.B.cz
zx""QQQQQQQ.t.RRRRRRR""xc.c1..1c.gg."cc....+...c..5$z
zx""QQQQQQQ.".RRRRRRR""xc.cnccnc.gg".cccccccccccccccz
zx""QQQQQQQ...RRRRRRR""xc........gg."cccccccccccccccz
zx00"""""""""""""""""00xc..2..2..cx"""""""""""""000xz
zx00"""""""""""""""""00xc........cx"""""""""""""000xz
zxxxxxxxxxxxxxxxxxxxxxxxc.2....2.cxxxxxxxxxxxxxxxxxxz
zzzzzzzzzzzzzzzzzzzzzzzzz........zzzzzzzzzzzzzzzzzzzz
ENDMAP

#### housing subvaults
# death knight, bound demons, bloody lounge, bricked up window, draugr
NAME:  grated_community_mu_yred_home
TAGS:  patrolling
KMONS: 1 : generate_awake warg draugr / generate_awake komodo dragon draugr
KMONS: 2 : generate_awake lindwurm draugr / generate_awake ice dragon draugr
KMONS: 3 = vampire / skeletal warrior w:2 / phantasmal warrior w:2
KMONS: 4 = death knight
KMONS: ? = generate_awake lemure
KITEM: 34 = any good_item
KFEAT: g = iron_grate
KFEAT: _ = altar_yredelemnul / fountain_blood
KPROP: . = bloody / w:4 nothing
KPROP: 1 = no_tele_into
TILE:  c = wall_stone_dark
TILE:  x = wall_brick_darkgray
FTILE: ._+1234?gcx = floor_crypt
: if you.in_branch("Vaults") then
SUBST: 1 = 2, 3 = 4
: end
: grated_community_house_setup(_G)
MAP
ccccccc
c?c3c?c
cgc+cgc
c.....c
c.1.1.c
c_....c
cccxc+c
      '
ENDMAP

# giant, hides, hearth, deep washroom, closet, lounge feature
NAME:    grated_community_mu_giant_home
TAGS:    no_pool_fixup patrolling
MONS:    ettin / cyclops / stone giant, fire giant / titan, frost giant
ITEM:    giant spiked club / giant club / nothing, animal skin
KFEAT:   M = cache_of_meat
KITEM:   f = human skeleton / yak skeleton / elf skeleton / kobold skeleton /\
             elephant skeleton / dream sheep skeleton / manticore skeleton,\
             animal skin
KFEAT:   ? = granite_statue / orcish_idol / altar_beogh w:5 / altar_makhleb w:1
SHUFFLE: 1# / 1# / 1# / 1# / 1# / 3!
####  The frost giant has an ice fireplace ok that's just how he cooks
: single_cloud(_G, "!", "freezing vapour", false)
: if you.in_branch("Vaults") then
SUBST:   1 = 2
: end
FTILE:   123456cw#+%M*.8$n~ = floor_pebble_darkgray
TILE:    c = wall_stone_scorched
: grated_community_house_setup(_G)
MAP
ccccccc
cwcc#cc
c-cdMfc
c...1.c
ccc.?.c
cd-...c
cccnc+c
      '
ENDMAP

# spellcaster, living room, workshop, closet
NAME:   grated_community_mu_spellcaster_home
MONS:   necromancer, arcanist / ogre mage, occultist / tengu conjurer w:5
MONS:   lich / ancient lich w:4, deep elf sorcerer / guardian sphinx
MONS:   deep elf annihilator / tengu reaver w:5
ITEM:   book of necromancy / book of death / book of unlife / book of decay
ITEM:   book of power / book of party tricks / book of transmutation / \
        book of the senses / book of chaos
ITEM:   book of fire / book of ice / book of lightning / book of the earth / \
        book of storms / the unrestrained analects
NSUBST: P = 1:P / *:G
: local q = crawl.random_range(1, 3)
: local s = "any scroll / nothing"
: local p = "any potion / nothing"
: local occupant = crawl.random2(3)
: if occupant == 0 then
KMONS:  P = withered plant
:   kitem("% = $, any wand / w:15 nothing, " .. s)
:   kitem("* = scroll of torment pre_id q:" .. q .. " / nothing, " .. s)
:   kitem("| = potion of magic pre_id q: " .. q .. " / nothing, " .. p)
KFEAT:  C = altar_kikubaaqudgha / altar_sif_muna w:4
SUBST:  & = ddddd., G = GGGGGY
: elseif occupant == 1 then
KMONS:  P = plant
:   kitem("% = $, " .. p .. ", " .. p .. ", " ..p)
:   kitem("% = scroll of vulnerability / nothing, " .. s)
:   kitem("* = potion of magic pre_id q: " .. q .. " / nothing, " .. p)
KFEAT:  C = altar_sif_muna / altar_ashenzari w:5
SUBST:  1 = 2, & = eeeee., G = GTU
: else
KITEM:  % = $, any beam wand / any blast wand, \
            potion of brilliance pre_id / nothing
:   kitem("* = scroll of immolation pre_id / nothing, " .. s)
:   kitem("| = scroll of immolation pre_id q: " .. q .. " / nothing, " .. s)
KFEAT:  C = altar_vehumet / altar_makhleb w:2
KFEAT:  P = cache_of_fruit
SUBST:  1 = 3, & = fffff.
: end
SUBST:  C = C%
: if you.in_branch("Vaults") then
SUBST:  1 = 4, 2 = 5, 3 = 6
: end
FTILE:  .def%*|PCG-+P123456nc = floor_crystal_squares
TILE:   c = dngn_stone_wall_brown
: grated_community_house_setup(_G)
MAP
ccccccc
cCc1.Pc
c.-...c
ccc-c.c
c&..c.c
cP*|c.c
cccnc+c
      '
ENDMAP

# orc, possible family, messy living room w/features, hearth, closet
NAME:   grated_community_mu_orcish_home
MONS:   orc knight, orc warrior, orc priest, warg
MONS:   orc warlord, orc high priest, peacekeeper
KITEM:  % = w:12 animal skin / club / hand axe
KITEM:  | = battleaxe / nothing, plate armour / nothing, gold, any, any
KFEAT:  F = cache_of_fruit / cache_of_meat
KFEAT:  ? = altar_beogh / orcish_idol
NSUBST: | = 1:| / *:W, F = 1:F. / *:?, . = 5:% / *:.
SUBST:  2 = 2224, 3 = 3334
FTILE:  .WF?%|#-+cn1234567 = floor_pebble_yellow
TILE:   c = stone_wall_orc
: if you.in_branch("Vaults") then
SUBST:  1 = 5, 2 = 1, 3 = 6, 4 = 7
: end
: grated_community_house_setup(_G)
MAP
ccccccc
c|-.1.c
ccc.F2c
c#.3..c
ccc.F.c
c|-...c
cccnc+c
      '
ENDMAP

# troll, cookfire, remains
NAME:   grated_community_mu_troll_home
MONS:   patrolling deep troll
ITEM:   animal skin
KITEM:  % = any skeleton, any / nothing
NSUBST: . = 2:d / 7:% / *:.
KPROP:  .d% = bloody
FTILE:  ."1+#d%x = floor_dirt
TILE:   x = wall_pebble_darkgray
: grated_community_house_setup(_G)
MAP
xxxxxxx
xx...xx
x.1...x
x..#..x
x.....x
xx"""xx
xxx+xxx
      '
ENDMAP

# taur, entrace w/feature, shooting range, closets
NAME:    grated_community_mu_taur_home
MONS:    patrolling centaur warrior, patrolling yaktaur captain, training dummy
KMONS:   P = plant
ITEM:    any potion, any good_item, stone q:1 no_pickup
KFEAT:   G = granite_statue / cache_of_fruit w:5
SUBST:   G = GP
NSUBST:  d = 1:dW / *:e
: if you.in_branch("Vaults") then
SUBST:   1 = 2
: end
FTILE:   .defWG+-12Pxn = floor_moss
TILE:    c = stone_wall_shoals
: grated_community_house_setup(_G)
MAP
ccccccc
c3fff.c
ccccc-c
cd-.1.c
ccc.G.c
cd-...c
cccnc+c
      '
ENDMAP

NAME:   grated_community_mu_unbuilt_plot
FTILE:  . = floor_pebble_red
COLOUR: . = green
: grated_community_house_setup(_G)
MAP
.......
.......
.......
.......
.......
.......
.......
      '
ENDMAP

# This was originally kept seperate of the other subvaults to push in and hide
# the escape items from those who teleported in, but that's not really needed.
NAME:  grated_community_mu_sprite_home
TAGS:  grated_community_mu_home_escape
MONS:  kobold brigand, boggart band
KMONS: P = plant
ITEM:  wand of digging pre_id, scroll of teleportation pre_id
ITEM:  animal skin, any good_item
: if you.in_branch("Vaults") then
SUBST: 1 = 2
: end
TILE:  x = wall_brick_darkgray
FTILE: .defg1P+- = floor_sandstone
: grated_community_house_setup(_G)
MAP
xxxxxxx
xW-.edx
xxx..xx
x#x..Px
x1....x
xfg...x
xxxnx+x
      '
ENDMAP
