###############################################################################
# bazaar.des - Bazaar entry vaults and bazaar layouts.
#
# Bazaars should in general not contain dangers. Players expect that bazaars
# are peaceful. In general, plain and small maps are weighted to be
# generic (i.e. common), with the weirder or larger ones providing surprises.
###############################################################################

: crawl_require('dlua/vault.lua')

###############################################################################
# Bazaar entries

# Utility functions

lua {{

function place_bazaar_portal(e)
  e.tags("bzr_entry")
  e.kfeat("O = enter_bazaar")
  e.lua_marker('O', bazaar_portal)
end

function bazaar_portal()
  local messager =
    timed_msg {
      initmsg = { "You hear coins being counted.",
                  "An interdimensional caravan has stopped on this level "
                  .. "and set up a bazaar. Hurry and find its entrance before "
                  .. "they move on!" },
      finalmsg = "You hear the last, dying notes of the bell.",
      verb = 'tolling',
      noisemaker = 'bell'
    }
  local blow = 200 + 30*(40 - you.absdepth()) + crawl.random2(200)
  local bhigh = blow + crawl.random2(blow) + 100

  return timed_marker {
               low=blow, high=bhigh, msg=messager, single_timed=true,
               disappear='The gate to the bazaar disappears!',
               desc = "flickering gateway to a bazaar",
               floor = 'stone_arch', feat_tile = 'dngn_portal_bazaar_gone'
  }
end

local tilesets = {
  blue      = { rock = "wall_brick_gray", floor = "floor_grass",
                halo = "halo_grass", colour = "blue" },
  red       = { rock = "wall_pebble_red", floor = "floor_vault",
                halo = "halo_vault", colour = "red" },
  lightblue = { rock = "wall_pebble_lightblue", floor = "floor_grass",
                halo = "halo_grass2", colour = "lightblue" },
  magenta   = { rock = "wall_stone_gray", floor = "floor_dirt",
                halo = "halo_dirt", colour = "magenta" },
  green     = { rock = "wall_stone_gray", floor = "floor_grass",
                halo = "halo_grass", colour = "green" },
}

-- Chooses a bazaar tileset from a list of predefined ones.
function random_bazaar_tileset()
  local keys = util.keys(tilesets)
  return tilesets[keys[crawl.random2(#keys) + 1]]
end

-- This should be called for every bazaar vault, as it sets some standard map
-- headers for bazaar vaults. The arguments give some control over how the
-- bazaar is modified automatically.
--
-- * randomise_tileset: Controls whether to choose the layout from a coupld of
--                      predefined tilesets.
-- * shop_halo:         Controls whether floor "halos" should be placed around
--                      the shops. Has no effect if randomise_tiles == false.
--
-- Both arguments default to true.
function bazaar_setup(e, randomise_tileset, shop_halo, from_xom)
  if randomise_tileset == nil then
    randomise_tileset = true
  end
  if shop_halo == nil then
    shop_halo = true
  end
  if from_xom == nil then
    from_xom = false
  end

  if from_xom == false then
    e.tags("normal_bazaar")
  end

  -- No hostile monsters, but one to six weak friendly monsters
  -- that won't follow you out of the portal. They're also customers!
  e.tags("no_monster_gen")
  local a = "att:good_neutral ; nothing"
  local b = "att:good_neutral"
  local cust = "kobold " .. a .. " / orc " .. a .. " / spriggan " .. a ..
               " / naga " .. a .. " / merfolk " .. a .. " / human " .. a
  if you.god() ~= "Elyvilon" and you.god() ~= "Zin" and you.god() ~= "the Shining One" then
      cust = cust .. " / lesser demon w:2 " .. b .. " / mummy w:2 " .. b
  end

  local xomCust = "boggart " .. a .. " / common demon " .. b ..
                  " / laughing skull band w:5 " .. b .. " / ugly thing " .. b ..
                  " / worldbinder " .. b .. " / glowing shapeshifter " .. b ..
                  " / demonspawn w:2 " .. b .. " / zykzyl " .. b ..
                  " / sin beast " .. b .. " / tentacled monstrosity " .. b

  if you.god() == "Xom" then
      e.kmons("K = " .. xomCust)
  else
      e.kmons("K = " .. cust)
  end

  e.kfeat("< = stone_arch")
  e.kfeat("> = exit_bazaar")

  -- Don't place any other customers if you'd hate them, or if they'd hate you.
  if you.get_base_mutation_level("hated by all") == 1 then
      crawl.mpr("Upon your arrival, your hatred by all makes the other customers disperse.")
  elseif you.god() == "Okawaru" then
      crawl.mpr("Upon your arrival, your lonesome duelist's vow makes the other customers flee.")
  else
      -- Xom sees a flavour opportunity and takes it.
      if you.god() == "Xom" then
          if from_xom == false then
              crawl.mpr("Xom shifts dimensions to make the bazaar a little more interesting.")
          end
          if you.silenced() == false then
              crawl.mpr("You hear the bustle and chatter of other... customers...?")
          end
          e.nsubst(". = 2:K / 4 = K. / 6 : K .:260 / *:.")
      else
          if you.silenced() == false then
              crawl.mpr("You hear the chatter and bustle of other customers!")
          end
          e.nsubst(". = 1:K / 2 = K. / 3 : K .:260 / *:.")
      end
  end

  -- Note: (false, true) makes no sense because of how the floor halos work.
  -- In most cases, they would look out of place.
  if randomise_tileset and shop_halo then
    randomise_bazaar_tiles()
    dgn.set_branch_epilogue("Bazaar", "create_shop_halos")
  elseif randomise_tileset and not shop_halo then
    randomise_bazaar_tiles()
    dgn.set_branch_epilogue("Bazaar", nil)
  else
    dgn.set_branch_epilogue("Bazaar", nil)
  end
end

function randomise_bazaar_tiles()
  local tileset = random_bazaar_tileset()
  dgn.change_floor_colour(tileset.colour)
  dgn.change_floor_tile(tileset.floor)
  dgn.change_rock_tile(tileset.rock)
end

function create_shop_halos()
  local tileset = tilesets[dgn.get_floor_colour()]
  dgn.floor_halo("enter_shop", "yellow", tileset.halo)
end

}}

default-depth: D:11-, Depths, Orc:$, Elf, Snake, Shoals, Vaults:1-4

###############################################################################
# Entries.
# The chance for a bazaar entry is branch and absdepth dependent,
# and resides in des/builder/shops.des.

NAME:   bzr_entry_dummy
TAGS:   transparent allow_dup
veto {{ return you.is_level_on_stack("Bazaar") }}
: place_bazaar_portal(_G)
MAP
O
ENDMAP

# A simple water entry.
NAME:    bzr_entry_water
TAGS:    no_pool_fixup
SHUFFLE: wwl
: place_bazaar_portal(_G)
MAP
 www
w.w.w
wwOww
w.w.w
 www
ENDMAP

# Some coins to shop with.
NAME:   bzr_entry_gold
SUBST:  $=$.
: place_bazaar_portal(_G)
MAP
xx.xx
x$$$x
.$O$.
x$$$x
xx.xx
ENDMAP

# Many customers
NAME:    bzr_entry_customers
MONS:    human, orc, goblin, kobold
SUBST:   . = .:150 1
SHUFFLE: 1234
: place_bazaar_portal(_G)
MAP
 .....
.......
...O...
.......
 .....
ENDMAP

# Safe
NAME:   bzr_entry_safe
: place_bazaar_portal(_G)
MAP
 xxxxx
xx...xx
+..O..x
xx...xx
 xxxxx
ENDMAP

# Safe 2
NAME:    bzr_entry_islet
TAGS:    no_descent
SHUFFLE: wwlW
: place_bazaar_portal(_G)
MAP
 wwwww
wwwwwww
ww<O>ww
wwwwwww
 wwwww
ENDMAP

# Portal along the road
NAME:    bzr_entry_road
SHUFFLE: XU, TUV
SUBST:   X=.
: place_bazaar_portal(_G)
MAP
   xxx
  xxOxx
xxx.X.xxx
@U.....U@
xxxxxxxxx
ENDMAP

# Portal by the lakeside (jpeg)
NAME:    bzr_entry_lakeside
TAGS:    no_rotate
MONS:    plant
SHUFFLE: XY
SUBST:   a = W .
SUBST:   X : T 1
SUBST:   Y = .
: place_bazaar_portal(_G)
MAP
     waWa.
   wwwWa.X.Y.
  wwwWO..Y.X.
wwwwwwaaaX.Y.
   wwwwwWa.
ENDMAP

# Bazaar entry with statue (Lemuel)
NAME:   statue_bzr
MONS:   orange crystal statue / obsidian statue / ice statue
: place_bazaar_portal(_G)
MAP
 @
c1c
cOc
ccc
ENDMAP

# Freezing bazaar (Lemuel)
NAME:   freezing_bzr
TAGS:   no_pool_fixup
MARKER: w = lua:fog_machine { cloud_type = "freezing vapour", \
             pow_min = 3, pow_max = 4, delay_min = 50, delay_max = 60, \
             size = 1, excl_rad = 0 }
: place_bazaar_portal(_G)
MAP
  w
 wWw
wWOWw
 wWw
  w
ENDMAP

# Bazaar in the mist (Lemuel)
NAME:   bzr_in_the_mist
MARKER: O = lua:fog_machine { cloud_type= "thin mist", \
            pow_min = 6, pow_max = 12, delay_min = 15, delay_max = 35, \
            size = 2, walk_dist = 2, spread_rate= 35 }
: place_bazaar_portal(_G)
MAP
O
ENDMAP

# Firewalk (Lemuel)
NAME:    bzr_firewalk
TAGS:    uniq_firewalk no_item_gen
SUBST:   $ : $ .
MARKER:  * = lua:fog_machine { cloud_type = "flame", \
             pow_min = 2, pow_max = 4, delay_min = 5, delay_max = 10, \
             size = 2, walk_dist = 0, spread_rate= 0 }
SUBST:   * = .
: place_bazaar_portal(_G)
MAP
c.@.$.@.c
c.*...*.c
c...$...c
c.......c
c.*.$.*.c
c.......c
c...$...c
c.*...*.c
c...O...c
ccccccccc
ENDMAP

#########################################
# Crystal gate, Pan only
# No allow_dup to prevent scumming.
NAME:    bzr_crystal_pan
TAGS:    extra
DEPTH:   Pan
COLOUR:  b = lightmagenta
COLOUR:  . = magenta
FTILE:   b.O = floor_crystal_squares
RTILE:   b = dngn_crystal_lightmagenta
: place_bazaar_portal(_G)
: set_feature_name("crystal_wall", "wall of crystal")
MAP
bb@bb
b...b
@.O.@
b...b
bb@bb
ENDMAP

###############################################################################
# Bazaar layouts.
#
# "encompass" levels are recommended, and can be as small or large as you like.
# No monsters are pre-placed in bazaars, and monsters do not spawn in bazaars,
# but you can place monsters in your maps if you know what you're doing.
#
# Every encompass bazaar level must have at least one downstair, which will be
# replaced with an exit from the bazaar. It's a good idea to also provide an
# upstair, which will be converted into a stone arch (and on which the player
# will be placed when entering the bazaar). If there's no upstair, the player
# will arrive on a random square.
#
# The bazaar_setup function should be called unless you know what you're doing.
#
# Maps are sorted by WEIGHTs: common (20), rare (5), very rare (1).

default-depth: Bazaar

###############################################################################
# Bazaar wrapper (to allow for Xom's bazaars)
###############################################################################

NAME:   bazaar_wrapper
TAGS:   allow_dup
PLACE:  Bazaar
ORIENT: encompass
{{
  local xom = dgn.persist.xom_bazaar
  if crawl.game_started() and xom == true then
    local map = dgn.map_by_tag("xom_bazaar")
    assert(map, "Couldn't find a map for Xom bazaar")
    dgn.place_map(map, false, false)
  elseif crawl.game_started() then
    local map = dgn.map_by_tag("normal_bazaar")
    assert(map, "Couldn't find a map for normal bazaar")
    dgn.place_map(map, false, false)
  end
  dgn.persist.xom_bazaar = false
}}
MAP
ENDMAP

##########################################################################
# Common maps (weight 200)
##########################################################################

##########################################
# bazaar lakeside (jpeg)
# 5 shops
NAME:    bazaar_lake
TAGS:    no_rotate
ORIENT:  encompass
WEIGHT:  20
KMONS:   ? = patrolling rock fish att:good_neutral
# high quality shops, pity they don't stay :p
KFEAT:   B = general shop
KFEAT:   C = book shop / jewellery shop
KFEAT:   D = antique weapon shop
KFEAT:   E = antique armour shop
KFEAT:   F = scroll shop / distillery shop
KFEAT:   ? = m
SHUFFLE: ABCDEF
SUBST:   A = Y
SHUFFLE: XY
SUBST:   X = <, Y = >
: bazaar_setup(_G)
: if you.get_base_mutation_level("hated by all") ~= 1 and
:   you.god() ~= "Okawaru" and crawl.one_chance_in(10) then
TAGS:    no_pool_fixup
NSUBST:  ? = 2:? / 1:?m / *:m
SUBST:   w = m, W = w, a = m.
FTILE:   ?m = floor_pebble_lightblue
KPROP:   w = no_tele_into
: else
SUBST:   a = W., ? = w
: end
: local colour = dgn.get_floor_colour()
: if colour == "blue" then
SUBST:   w = W
: end
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxx.....X.....xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx.................xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxx.......................xxxxxxxxxxxxxx
xxxxxxxxxxx......T......F......T......xxxxxxxxxxxx
xxxxxxxxxx.............................xxxxxxxxxxx
xxxxxxxxx...............................xxxxxxxxxx
xxxxxxxx..............aaaaa..............xxxxxxxxx
xxxxxxxx.....E.......awwwwwaa......A.....xxxxxxxxx
xxxxxxx............aawww?wwwww............xxxxxxxx
xxxxxxx...........awwww?W?wwwa............xxxxxxxx
xxxxxxx..........awwww?WWW?wwa............xxxxxxxx
xxxxxxxY.T........awwww??WWwwwa........T.Yxxxxxxxx
xxxxxxx............awwwwwwwwaX............xxxxxxxx
xxxxxxx.............aawwwwwwwwa...........xxxxxxxx
xxxxxxx...............aaaaaaaa............xxxxxxxx
xxxxxxxx.....D.....................B.....xxxxxxxxx
xxxxxxxx.................................xxxxxxxxx
xxxxxxxxx...............................xxxxxxxxxx
xxxxxxxxxx.............................xxxxxxxxxxx
xxxxxxxxxxx......T......C......T......xxxxxxxxxxxx
xxxxxxxxxxxxx.......................xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx.................xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxx.....X.....xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

########################################
# bazaars in a row
# ~4 shops
NAME:    bazaar_short_row
TAGS:    no_rotate no_pool_fixup
ORIENT:  encompass
WEIGHT:  20
SHUFFLE: Aa/Bb/Cc/Dd/Ee/Ff
SHUFFLE: Aa/Zz, Bb/Yy, Cc/Rr, Dd/Ss
# two guaranteed shops, expected four shops
KFEAT:   A = any shop / antique weapon shop
KFEAT:   B = any shop / antique armour shop
KFEAT:   C = any shop / antiques shop
KFEAT:   D = any shop / jewellery shop
KFEAT:   E = any shop / weapon shop / armour shop
KFEAT:   F = any shop / book shop / scroll shop
SUBST:   b=a, c=a, d=a, e=a, f=a, a=T
SUBST:   y=z, r=z, s=z, z=V, Y=Z, R=Z, S=Z
KFEAT:   Z = abandoned_shop
SHUFFLE: lw
SUBST:   w:wWx, l:lx
: bazaar_setup(_G)
: local colour = dgn.get_floor_colour()
: if colour == "red" then
SUBST: l = w
: elseif colour == "blue" then
SUBST: w = l
: end
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxAxxxxxxxxxxxCxxxxxxxxxxxExxxxxxxxxxxxxxxx
xxx.....xxxxxxx...xxxxxxxxx...xxxxxxxxx...xxxxxxx.....xxx
xx..www..xxxxxx.a.xxxxxxxxx.c.xxxxxxxxx.e.xxxxxx..lll..xx
x<.wwwww..+...........+...........+...........+..lllll.>x
xx..www..xxxxxx.b.xxxxxxxxx.d.xxxxxxxxx.f.xxxxxx..lll..xx
xxx.....xxxxxxx...xxxxxxxxx...xxxxxxxxx...xxxxxxx.....xxx
xxxxxxxxxxxxxxxxBxxxxxxxxxxxDxxxxxxxxxxxFxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

########################################
# bazaars in a row v2
# ~4.5 shops
# ~4.5 shops
NAME:    bazaar_long_row
TAGS:    no_rotate
ORIENT:  encompass
WEIGHT:  20
KFEAT:   A = any shop
KFEAT:   Z = abandoned_shop
SHUFFLE: Aa/Bb/Cc/Dd/Ee/Ff/Gg/Hh
SHUFFLE: Aa/Zz, Bb/Yy, Cc/Rr, Dd/Ss, Ee/Jj, Ff/Nn
# two guaranteed shops, expected five shops
SUBST:   BCDEFGH = A, bcdefgh = a
SUBST:   ZYRSJN = Z, zyrsjn = z
SUBST:   a = T, z = V
SHUFFLE: lw
SUBST:   w : wWx, l : lx
: bazaar_setup(_G)
: local colour = dgn.get_floor_colour()
: if colour == "red" then
SUBST: l = w
: elseif colour == "blue" then
SUBST: w = l
: end
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxAxxxxxxxxxxxCxxxxxxxxxxxExxxxxxxxxxxGxxxxxxxxxxxxxxxx
xxx.....xxxxxxx...xxxxxxxxx...xxxxxxxxx...xxxxxxxxx...xxxxxxx.....xxx
xx..www..xxxxxx.a.xxxxxxxxx.c.xxxxxxxxx.e.xxxxxxxxx.g.xxxxxx..lll..xx
x<.wwwww..+...........+...........+...........+...........+..lllll.>x
xx..www..xxxxxx.b.xxxxxxxxx.d.xxxxxxxxx.f.xxxxxxxxx.h.xxxxxx..lll..xx
xx......xxxxxxx...xxxxxxxxx...xxxxxxxxx...xxxxxxxxx...xxxxxxx.....xxx
xxxxxxxxxxxxxxxxBxxxxxxxxxxxDxxxxxxxxxxxFxxxxxxxxxxxHxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_circle_common
WEIGHT:  20
TAGS:    no_rotate
ORIENT:  encompass
KFEAT:   A = any shop / antique armour shop
KFEAT:   B = any shop / antique weapon shop
KFEAT:   C = any shop / jewellery shop
KFEAT:   D = any shop / book shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx...xxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx.....xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx..D..xxxxxxxxxxxxxxx
xxxxxxxxxx....+.....+....xxxxxxxxxx
xxxxxxx....xxxxx...xxxxx....xxxxxxx
xxxxxx..xxxxxxxxxxxxxxxxxxx..xxxxxx
xxxxx..xxxxxxxxxx>xxxxxxxxxx..xxxxx
xxxxx+xxxxxxxxxx...xxxxxxxxxx+xxxxx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xx.....xxxxxx.........xxxxxx.....xx
xx..A..xxxxxT....<....Txxxxx..B..xx
xx.....xxxxxx.........xxxxxx.....xx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xxxxx+xxxxxxxxxx...xxxxxxxxxx+xxxxx
xxxxx..xxxxxxxxxx+xxxxxxxxxx..xxxxx
xxxxxx..xxxxxxxxx+xxxxxxxxx..xxxxxx
xxxxxxx....xxxxx...xxxxx....xxxxxxx
xxxxxxxxxx....+.....+....xxxxxxxxxx
xxxxxxxxxxxxxxx..C..xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx.....xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx...xxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

# 2 good shops or 3 shops
NAME:    bazaar_jpeg_cross
TAGS:    no_rotate
WEIGHT:  20
ORIENT:  encompass
SHUFFLE: ABCD
: if crawl.coinflip() then
SUBST:   A = <, B = >
KFEAT:   C = jewellery shop / book shop
KFEAT:   D = antique armour shop / book shop
: else
SUBST:   T = <, A = >
KFEAT:   B = antique weapon shop
KFEAT:   C = antique armour shop
KFEAT:   D = general shop / distillery shop
:end
: if crawl.coinflip() then
SUBST:   ' = .
SUBST:   G : G.
: else
SUBST:   ' = x
SUBST:   G = .
:end
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxx...xxxxxxxxxxxxxx
xxxxxxxxxxxx.......xxxxxxxxxxxx
xxxxxxxxxxx....A....xxxxxxxxxxx
xxxxxxxxxxxx.......xxxxxxxxxxxx
xxxxxxxxxxxxxx...xxxxxxxxxxxxxx
xxxxxxxxxxxxxx...xxxxxxxxxxxxxx
xxxx...xxxxxxx...xxxxxxx...xxxx
xx......xxxx''.G.''xxxx......xx
x....B.......G.T.G.......D....x
xx......xxxx''.G.''xxxx......xx
xxxx...xxxxxxx...xxxxxxx...xxxx
xxxxxxxxxxxxxx...xxxxxxxxxxxxxx
xxxxxxxxxxxxxx...xxxxxxxxxxxxxx
xxxxxxxxxxxx.......xxxxxxxxxxxx
xxxxxxxxxxx....C....xxxxxxxxxxx
xxxxxxxxxxxx.......xxxxxxxxxxxx
xxxxxxxxxxxxxx...xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:      bazaar_minmay_generic_island
TAGS:      no_rotate
ORIENT:    encompass
WEIGHT:    20
KITEM:     $ = $ no_pickup
KFEAT:     ! = any shop
SUBST:     w : wl
SHUFFLE:   Aa/Bb/Cc/Dd, Cc/Ee, Dd/Ff
COLOUR:    EeFf = yellow
SUBST:     ab = !, AB = ., cd = !, CD = ., EeFf = $
KPROP:     wl = no_tele_into
:          bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxx
xxxxxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxx
xxxxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxx
xxxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxx
xxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxx
xxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxx
xxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxx
xxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxx
xxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxx
xxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxx
xxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxx
xxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxx
xxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxx
xwwwwwwwwwwwwwwwwwwnnnnnnnnnwwwwwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwwwwnn.......nnwwwwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwwwnn....!....nnwwwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwwnn...........nnwwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwnn..AAA...BBB..nnwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwn...AaA...BbB...nwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwn...AAA...BBB...nwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwn.............<.nwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwn.>.............nwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwn...CCC...DDD...nwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwn...CcC...DdD...nwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwnn..CCC...DDD..nnwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwwnn...........nnwwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwwwnn....!....nnwwwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwwwwnn.......nnwwwwwwwwwwwwwwwwwx
xwwwwwwwwwwwwwwwwwwnnnnnnnnnwwwwwwwwwwwwwwwwwwx
xxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxx
xxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxx
xxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxx
xxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxx
xxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxx
xxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxx
xxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxx
xxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxx
xxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxx
xxxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxx
xxxxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxx
xxxxxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxx
xxxxxxxxxxxxxxwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_minmay_row
TAGS:    no_rotate
ORIENT:  encompass
WEIGHT:  20
SHUFFLE: T? / AB
SUBST:   A = !, B = T
KFEAT:   ! = any shop
KFEAT:   ? = any shop / T
SUBST:   T : Tc
:        bazaar_setup(_G)
MAP
       xxxxx
       x...x
       x.<.x
    xxxx...xxxx
  xxx.........xxx
 xx......c......xx
 x...............x
xx..c.........c..xx
x.................x
x.T.?.!.?.?.!.?.T.x
x.................x
xx..c.........c..xx
 x...............x
 xx......c......xx
  xxx.........xxx
    xxxx...xxxx
       x.>.x
       x...x
       xxxxx
ENDMAP

NAME:   bazaar_minmay_cross
TAGS:   no_rotate
ORIENT: encompass
WEIGHT: 20
KFEAT:  ! = any shop
SUBST:  T = TU
:       bazaar_setup(_G)
MAP
        xxxxx
        x...x
        x.!.x
        x...x
xxxxxxxxx...xxxxxxxxx
x...x...........x...x
x.>.+.!...T...!.+.<.x
x...x...........x...x
xxxxxxxxx...xxxxxxxxx
        x...x
        x.!.x
        x...x
        xxxxx
ENDMAP

##########################################################################
# Rare maps (weights 0-10)
##########################################################################

# 4 random shops
NAME:   bazaar_general_marketplace
TAGS:   no_rotate
WEIGHT: 5
ORIENT: encompass
KFEAT:  A = any shop
:       bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxx
xxxxxxx>xxxxxxx
xxxxxx...xxxxxx
xxxxx.....xxxxx
xxxx...A...xxxx
xxx.........xxx
xx...........xx
x<..A.....A..>x
xx...........xx
xxx.........xxx
xxxx...A...xxxx
xxxxx.....xxxxx
xxxxxx...xxxxxx
xxxxxxx>xxxxxxx
xxxxxxxxxxxxxxx
ENDMAP

# 3 weapon/armour shops, potentially antique
NAME:    bazaar_outfitter
ORIENT:  encompass
WEIGHT:  5
KFEAT:   A = any shop
SHUFFLE: ABC, de
KFEAT:   A = weapon shop / armour shop
KFEAT:   B = antique weapon shop / weapon shop
KFEAT:   C = antique armour shop / armour shop
ITEM:    any weapon no_pickup / any weapon good_item no_pickup w:2
ITEM:    any armour no_pickup / any armour good_item no_pickup w:2
:        bazaar_setup(_G)
MAP
xxxxxxxxx
xxxx>xxxx
xx.....xx
x.......x
x.AdBeC.x
x.......x
xx.....xx
xxxx<xxxx
xxxxxxxxx
ENDMAP

# 4 random shops
NAME:    bazaar_jpeg_oval
TAGS:    no_rotate
WEIGHT:  5
ORIENT:  encompass
SUBST:   A = TVBG
KFEAT:   B = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxx
xxxB.....Bxxx
xx.........xx
x<....A....>x
xx.........xx
xxxB.....Bxxx
xxxxxxxxxxxxx
ENDMAP

# 2 shops, some items.
NAME:    bazaar_mystics
TAGS:    no_pool_fixup
WEIGHT:  5
ORIENT:  encompass
SUBST:   w : wlx
SHUFFLE: AB, def
ITEM:    any jewellery no_pickup / any jewellery good_item no_pickup
ITEM:    any book / any book good_item, any magical staff no_pickup
KFEAT:   A = scroll shop / book shop / book shop
KFEAT:   B = jewellery shop
SUBST:   d=.d, e=.e, f=.f
: bazaar_setup(_G)
: local colour = dgn.get_floor_colour()
: if colour == "red" then
SUBST: l = w
: elseif colour == "blue" then
SUBST: w = l
: end
MAP
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxwwwwwxxxxxx
xxxxxxxxxxwwww...wwwxxxx
xwwwwwwwwww....A...wwxxx
xw<......d+....e....+f>x
xwwwwwwwwww....B...wwxxx
xxxxxxxxxxwwww...wwwxxxx
xxxxxxxxxxxxxwwwwwxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

# 2 scroll shops, 2 potion shops
NAME:    dpeg_bazaar_wands
TAGS:    no_rotate no_pool_fixup
WEIGHT:  5
ORIENT:  encompass
KFEAT:   A = scroll shop
KFEAT:   B = distillery shop
ITEM:    ring of flight pre_id no_pickup
SHUFFLE: lAB/wBA
: bazaar_setup(_G)
: local colour = dgn.get_floor_colour()
: if colour == "red" then
SUBST: l = w
: elseif colour == "blue" then
SUBST: w = l
: end
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxx......>......xxxxxxxxxx
xxxx.........................xxxx
xx.....l.................l.....xx
xx......l...............l.......x
xl....A.ll.............ll.A....lx
xl......l...............l......lx
xll...........................llx
xllll.......................llllx
xlllllll.................lllllllx
xllllllllllll.......llllllllllllx
xlllllllllllllllllllllllllllllllx
x...lllllllllllllllllllllllll...x
x........lllllllllllllll........x
x............lllllll............x
x..............lll..............x
xxxxx.......................xxxxx
x...x.......................x...x
x.B.+.......................+.B.x
x...x..........<d>..........x...x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

# 5 shops, total weight of jpeg's rare circle vaults is 5
NAME:    bazaar_jpeg_circle_rare_1
WEIGHT:  1
TAGS:    no_rotate
ORIENT:  encompass
SHUFFLE: ABCD, EFGH
SUBST:   H=>, A=T, B=T
KFEAT:   CDEFG = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
x.....xxxxxxxxxx...xxxxxxxxxx.....x
x..E..+.......+.....+.......+..H..x
x.....xxxxxxxxx..D..xxxxxxxxx.....x
xx...xxxxx....+.....+....xxxxx...xx
xxx+xxx....xxxxx...xxxxx....xxx+xxx
xxx.xx..xxxxxxxxx+xxxxxxxxx..xx.xxx
xxx.x..xxxxxxxxxx+xxxxxxxxxx..x.xxx
xxx+x+xxxxxxxxxx...xxxxxxxxxx+x+xxx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xx.....xxxxxx.........xxxxxx.....xx
xx..A..xxxxxT....<....Txxxxx..B..xx
xx.....xxxxxx.........xxxxxx.....xx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xxx+x+xxxxxxxxxx...xxxxxxxxxx+x+xxx
xxx.x..xxxxxxxxxx+xxxxxxxxxx..x.xxx
xxx.xx..xxxxxxxxx+xxxxxxxxx..xx.xxx
xxx+xxx....xxxxx...xxxxx....xxx+xxx
xx...xxxxx....+.....+....xxxxx...xx
x.....xxxxxxxxx..C..xxxxxxxxx.....x
x..G..+.......+.....+.......+..F..x
x.....xxxxxxxxxx...xxxxxxxxxx.....x
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_circle_rare_2
WEIGHT:  1
TAGS:    no_rotate
ORIENT:  encompass
SHUFFLE: EFGH
SUBST:   H=>, D=T, C=T
KFEAT:   ABEFG = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
x.....xxxxxxxxxx...xxxxxxxxxx.....x
x..H..xxxxxxxxx.....xxxxxxxxx..E..x
x.....xxxxxxxxx..D..xxxxxxxxx.....x
xx...xxxxx....+.....+....xxxxx...xx
xxx+xxx....xxxxx...xxxxx....xxx+xxx
xxx.xx..xxxxxxxxx+xxxxxxxxx..xx.xxx
xxx.x..xxxxxxxxxx+xxxxxxxxxx..x.xxx
xxx+x+xxxxxxxxxx...xxxxxxxxxx+x+xxx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xx.....xxxxxx.........xxxxxx.....xx
xx..A..xxxxxT....<....Txxxxx..B..xx
xx.....xxxxxx.........xxxxxx.....xx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xxx+x+xxxxxxxxxx...xxxxxxxxxx+x+xxx
xxx.x..xxxxxxxxxx+xxxxxxxxxx..x.xxx
xxx.xx..xxxxxxxxx+xxxxxxxxx..xx.xxx
xxx+xxx....xxxxx...xxxxx....xxx+xxx
xx...xxxxx....+.....+....xxxxx...xx
x.....xxxxxxxxx..C..xxxxxxxxx.....x
x..G..xxxxxxxxx.....xxxxxxxxx..F..x
x.....xxxxxxxxxx...xxxxxxxxxx.....x
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_circle_rare_3
WEIGHT:  1
TAGS:    no_rotate
ORIENT:  encompass
SHUFFLE: EFGH
SUBST:   A=>, D=T, C=T
KFEAT:   BHEFG = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
x.....xxxxxxxxxx...xxxxxxxxxx.....x
x..H..+.......+.....+.......+..E..x
x.....xxxxxxxxx..D..xxxxxxxxx.....x
xx...xxxxxxxxxx.....xxxxxxxxxx...xx
xxx+xxxxxxxxxxxx...xxxxxxxxxxxx+xxx
xxx.xxxxxxxxxxxxx+xxxxxxxxxxxxx.xxx
xxx.xxxxxxxxxxxxx+xxxxxxxxxxxxx.xxx
xxx+xxxxxxxxxxxx...xxxxxxxxxxxx+xxx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xx.....xxxxxx.........xxxxxx.....xx
xx..A..xxxxxT....<....Txxxxx..B..xx
xx.....xxxxxx.........xxxxxx.....xx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xxx+xxxxxxxxxxxx...xxxxxxxxxxxx+xxx
xxx.xxxxxxxxxxxxx+xxxxxxxxxxxxx.xxx
xxx.xxxxxxxxxxxxx+xxxxxxxxxxxxx.xxx
xxx+xxxxxxxxxxxx...xxxxxxxxxxxx+xxx
xx...xxxxxxxxxx.....xxxxxxxxxx...xx
x.....xxxxxxxxx..C..xxxxxxxxx.....x
x..G..+.......+.....+.......+..F..x
x.....xxxxxxxxxx...xxxxxxxxxx.....x
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_circle_rare_4
WEIGHT:  1
TAGS:    no_rotate
ORIENT:  encompass
SHUFFLE: ABCDEF
KFEAT:   ABCDE = any shop
SUBST:   F = T
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
x.....xxxxxxxxxx...xxxxxxxxxx.....x
x..C..+.......+.....xxxxxxxxx..T..x
x.....xxxxxxxxx..D..xxxxxxxxx.....x
xx...xxxxxxxxxx.....xxxxxxxxxx...xx
xxx+xxxxxx.xxxxx...xxxxxxxxxxxx+xxx
xxx.xxxxxxxxxxxxx+xxxxxxxxxxxxx.xxx
xxx.xxxxxxxxxxxxx+xxxxxxxxxxxxx.xxx
xxx+xxxxxxxxxxxx...xxxxxxxxxxxx+xxx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xx.....xxxxxx.........xxxxxx.....xx
xx..A..xxxxxT....<....Txxxxx..>..xx
xx.....xxxxxx.........xxxxxx.....xx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xxx+xxxxxxxxxxxx...xxxxxxxxxxxx+xxx
xxx.xxxxxxxxxxxxxTxxxxxxxxxxxxx.xxx
xxx.xxxxxxxxxxxxxxxxxxxxxxxxxxx.xxx
xxx+xxxxxx.xxxxx...xxxxxxxxxxxx+xxx
xx...xxxxxxxxxx.....xxxxxxxxxx...xx
x.....xxxxxxxxx..E..xxxxxxxxx.....x
x..T..+.......+.....+.......+..B..x
x.....xxxxxxxxxx...xxxxxxxxxx.....x
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_circle_rare_5
WEIGHT:  1
TAGS:    no_rotate
ORIENT:  encompass
KFEAT:   CDEFG = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
x.....xxxxxxxxxx...xxxxxxxxxx.....x
x..>..+.......+.....+.......+..E..x
x.....xxxxxxxxx..D..xxxxxxxxx.....x
xx...xxxxx....+.....+....xxxxx...xx
xxxxxxx....xxxxx...xxxxx....xxxxxxx
xxxxxx..xxxxxxxxxxxxxxxxxxx..xxxxxx
xxxxx..xxxxxxxxxxTxxxxxxxxxx..xxxxx
xxxxx+xxxxxxxxxx...xxxxxxxxxx+xxxxx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xx.....xxxxxx.........xxxxxx.....xx
xx..T..+....+....<....+....+..T..xx
xx.....xxxxxx.........xxxxxx.....xx
xxx...xxxxxxxx.......xxxxxxxx...xxx
xxx+x+xxxxxxxxxx...xxxxxxxxxx+x+xxx
xxx.x..xxxxxxxxxxTxxxxxxxxxx..x.xxx
xxx.xx..xxxxxxxxxxxxxxxxxxx..xx.xxx
xxx+xxx....xxxxx...xxxxx....xxx+xxx
xx...xxxxx....+.....+....xxxxx...xx
x.....xxxxxxxxx..C..xxxxxxxxx.....x
x..G..xxxxxxxxx.....xxxxxxxxx..F..x
x.....xxxxxxxxxx...xxxxxxxxxx.....x
xx...xxxxxxxxxxxxxxxxxxxxxxxxx...xx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

# 4 shops
NAME:    bazaar_jpeg_honeycomb
WEIGHT:  10
TAGS:    no_rotate
ORIENT:  encompass
MONS:    plant
KITEM:   $ = $ no_pickup
SHUFFLE: ABCDEF
SUBST:   A = >, B = >
SUBST:   . = .:1000 $
SUBST:   K = T:20 1 .:5
KFEAT:   C = any shop / distillery shop
KFEAT:   D = any shop / antiques shop
KFEAT:   E = any shop / weapon shop / armour shop
KFEAT:   F = any shop / book shop / scroll shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxK.....Kxxxxxxxxxxxxxx
xxxxxxxxxxxxx.........xxxxxxxxxxxxx
xxxxxxxxxxxx.....B.....xxxxxxxxxxxx
xxxxxx....Kxx.........xxK....xxxxxx
xxxx........xx.......xx........xxxx
xxxK....A....xxxx+xxxx....C....Kxxx
xxxx........xxK.....Kxx........xxxx
xxxxx.....Kxx.........xxK....xxxxxx
xxxxxxx....+.....<.....+....xxxxxxx
xxxxx.....Kxx.........xxK....xxxxxx
xxxx........xxK.....Kxx........xxxx
xxxK....F....xxxx+xxxx....D....Kxxx
xxxx........xx.......xx........xxxx
xxxxxx....Kxx.........xxK....xxxxxx
xxxxxxxxxxxx.....E.....xxxxxxxxxxxx
xxxxxxxxxxxxx.........xxxxxxxxxxxxx
xxxxxxxxxxxxxxK.....Kxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

# 4 shops
NAME:    bazaar_jpeg_ribbon
TAGS:    no_rotate no_pool_fixup
WEIGHT:  10
ORIENT:  encompass
SHUFFLE: zZ
SUBST:   z = ., Z = w
SHUFFLE: wl, ABCD
SHUFFLE: AX
SUBST:   X = <, A = >
SUBST:   B : T G
KFEAT:   C = any shop
KFEAT:   D = weapon shop / book shop / jewellery shop
: bazaar_setup(_G)
: local colour = dgn.get_floor_colour()
: if colour == "red" then
SUBST: l = w
: elseif colour == "blue" then
SUBST: w = l
: end
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x.xxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxx.x
x....xxxxxxxxxxxxxx...xxxxxxxxxxxxxx....x
x..A..xxxxxxxxxxx.......xxxxxxxxxxx..A..x
x......xxxxxxxxx....B....xxxxxxxxx......x
xx......xxxxxx.............xxxxxx......xx
xxx......xxxx.....wwZww.....xxxx......xxx
xxxx.............ww...ww.............xxxx
xxxxx......D.....w..X..z.....D......xxxxx
xxxx.............ww...ww.............xxxx
xxx......xxxx.....wwwww.....xxxx......xxx
xx......xxxxxx.............xxxxxx......xx
x......xxxxxxxxx....B....xxxxxxxxx......x
x..C..xxxxxxxxxxx.......xxxxxxxxxxx..C..x
x....xxxxxxxxxxxxxx...xxxxxxxxxxxxxx....x
x.xxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxx.x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

# 5 shops, total weight of jpeg's nineroom vaults is 5
NAME:    bazaar_jpeg_ninerooms_1
TAGS:    no_rotate
WEIGHT:  1
ORIENT:  encompass
SUBST:   k : . x
NSUBST:  A = 2=T:30 V / *:C
NSUBST:  B = 1:< / >
KFEAT:   C = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........xxxxxxxxx....A....xxxxxxxxx.........x
x....A....+.........................+....A....x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxx+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........xxxxxxxxx.........xxxxxxxxx.........x
x....A............+....B....xxxxxxxxx....A....x
x.........xxxxxxxxx.........xxxxxxxxx.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x....B....+.........................+....A....x
x.........xxxxxxxxx....A....xxxxxxxxx.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_ninerooms_2
TAGS:    no_rotate
WEIGHT:  1
ORIENT:  encompass
SUBST:   k : . x
NSUBST:  A = 2=T:30 V / *:C
NSUBST:  B = 1:< / >
KFEAT:   C = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x....B....xxxxxxxxx.........xxxxxxxxx....A....x
x.........xxxxxxxxx....A............+.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxx+xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx+xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxxx.xxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........xxxxxxxxx.........xxxxxxxxx.........x
x....A....xxxxxxxxx....B....xxxxxxxxx....A....x
x.........xxxxxxxxx.........xxxxxxxxx.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........+............A............+.........x
x....A....xxxxxxxxx.........xxxxxxxxx....A....x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_ninerooms_3
TAGS:    no_rotate
WEIGHT:  1
ORIENT:  encompass
SUBST:   z = .:50 +
SUBST:   k : . x
NSUBST:  A = 1:< / 1=<TC / 2=T:30 V / *:C
NSUBST:  B = 1:> / 1=C>
KFEAT:   C = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........xxxxxxxxx.........xxxxxxxxx.........x
x....A....z.......z....A....xxxxxxxxx....B....x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxzxxxxxxxxxxxxxxxxxzxxxxxxxxxxxxxxxxxzxxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxxzxxxxxxxxxxxxxxxxxzxxxxxxxxxxxxxxxxxzxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........xxxxxxxxx.........xxxxxxxxx.........x
x....A....z.......z....A....z.......z....A....x
x.........xxxxxxxxx.........xxxxxxxxx.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxxxxxxxxxxxxxxxxxxxzxxxxxxxxxxxxxxxxxzxxxxx
xxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxxxxxxxxxxxxxxxxxxxxzxxxxxxxxxxxxxxxxxzxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x....B....z.......z....A....z.......z....A....x
x.........xxxxxxxxx.........xxxxxxxxx.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_ninerooms_4
TAGS:    no_rotate
WEIGHT:  1
ORIENT:  encompass
SUBST:   z = .:50 +
SUBST:   k : . x
NSUBST:  A = 1:< / 1=<TC / 2=T:30 V / *:C
NSUBST:  B = 1:> / 1=C>
KFEAT:   C = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........xxxxxxxxx.........xxxxxxxxx.........x
x....A....z.......z....A....xxxxxxxxx....B....x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxzxxxxxxxxxxxxxxxxxzxxxxxxxxxxxxxxxxxzxxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxxzxxxxxxxxxxxxxxxxxzxxxxxxxxxxxxxxxxxzxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........xxxxxxxxx.........xxxxxxxxx.........x
x....A....z.......z....A....z.......z....A....x
x.........xxxxxxxxx.........xxxxxxxxx.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxzxxxxxxxxxxxxxxxxxzxxxxxxxxxxxxxxxxxzxxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxxzxxxxxxxxxxxxxxxxxzxxxxxxxxxxxxxxxxxzxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x....B....xxxxxxxxx....A....z.......z....A....x
x.........xxxxxxxxx.........xxxxxxxxx.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_ninerooms_5
TAGS:    no_rotate
WEIGHT:  1
ORIENT:  encompass
SUBST:   k : . x
NSUBST:  A = 1:< / 1:> / 1:T C / 3=T:30 V / *:C
SUBST:   B = > C:20
KFEAT:   C = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x....A....xxxxxxxxx.........xxxxxxxxx....A....x
x......................A............+.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxx+xxxxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxxx+xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxxx.xxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........xxxxxxxxx.........xxxxxxxxx.........x
x....A....+.......+....B....xxxxxxxxx....A....x
x.........xxxxxxxxx.........xxxxxxxxx.........x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxx
xxxxx+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxx
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
x.........+............A............+.........x
x....A....xxxxxxxxx.........xxxxxxxxx....A....x
xk.......kxxxxxxxxxk.......kxxxxxxxxxk.......kx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:   bazaar_minmay_generic_box
TAGS:   no_rotate
WEIGHT: 5
ORIENT: encompass
KFEAT:  ! = any shop
KFEAT:  ? = any shop / T
:       bazaar_setup(_G)
MAP
xxxxxxxxx
x.......x
x.?.!.?.x
x.......x
x.<...>.x
x.......x
x.?.!.?.x
x.......x
xxxxxxxxx
ENDMAP

# This one's vertical edges look odd because
# it almost exceeds the maximum level size.
# Can't find a way to fix this without
# ruining the look of the vault.
NAME:       bazaar_minmay_generic_d
TAGS:       no_rotate
WEIGHT:     5
ORIENT:     encompass
: if crawl.coinflip() then
SUBST:      "=l , '=. , A=l , B=!
: else
SUBST:      "=. , '=l , A=! , B=l
: end
KFEAT:      ! = jewellery shop / jewellery shop / antiques shop / scroll shop / \
               book shop
LFLOORCOL:  darkgrey
: set_border_fill_type("endless_lava")
: bazaar_setup(_G, false, false)
MAP
lllllllllllllllllllllllllllllllllllll
ll...lllllllllllllllll'''llllllllllll
l.....lllllllllllllll'''''lllllllllll
l..<...lllllllllllll'''B''lllllllllll
l.......lllllllllll'''''''lllllllllll
ll.......lllllllll'''''''llllllllllll
lll.......lllllll'''''''lllllllllllll
llll.......lllll'''''''llllllllllllll
lllll.......lll'''''''lllllllllllllll
llllll.......''''''''llllllllllllllll
lllllll.......''''''lllllllllllllllll
llllllll.......''''lllllllllllll"""ll
lllllllll.......''lllllllllllll"""""l
lllllllll".......'llllllllllll"""A""l
lllllllll"".......lllllllllll"""""""l
llllllll"""".......lllllllll"""""""ll
lllllll"""""".......lllllll"""""""lll
llllll"""""""".......lllll"""""""llll
lllll"""""""lll.......lll"""""""lllll
llll"""""""lllll.......""""""""llllll
lll"""""""lllllll.......""""""lllllll
ll"""""""lllllllll.......""""llllllll
l"""""""lllllllllll.......""lllllllll
l""A"""llllllllllll'......."lllllllll
l"""""lllllllllllll''.......lllllllll
ll"""lllllllllllll''''.......llllllll
lllllllllllllllll''''''.......lllllll
llllllllllllllll''''''''.......llllll
lllllllllllllll'''''''lll.......lllll
llllllllllllll'''''''lllll.......llll
lllllllllllll...''''lllllll.......lll
llllllllllll.....''lllllllll.......ll
lllllllllll.......lllllllllll.......l
lllllllllll...!...lllllllllll.......l
lllllllllll.......lllllllllll.......l
llllllllllll.....""lllllllll.......ll
lllllllllllll...""""lllllll.......lll
llllllllllllll"""""""lllll.......llll
lllllllllllllll"""""""lll.......lllll
llllllllllllllll"""""""".......llllll
lllllllllllllllll"""""".......lllllll
ll'''lllllllllllll"""".......llllllll
l'''''lllllllllllll"".......lllllllll
l''B'''llllllllllll".......'lllllllll
l'''''''lllllllllll.......''lllllllll
ll'''''''lllllllll.......''''llllllll
lll'''''''lllllll.......''''''lllllll
llll'''''''lllll.......''''''''llllll
lllll'''''''lll.......lll'''''''lllll
llllll''''''''.......lllll'''''''llll
lllllll''''''.......lllllll'''''''lll
llllllll''''.......lllllllll'''''''ll
lllllllll''.......lllllllllll'''''''l
lllllllll'......."llllllllllll'''B''l
lllllllll.......""lllllllllllll'''''l
llllllll.......""""lllllllllllll'''ll
lllllll.......""""""lllllllllllllllll
llllll.......""""""""llllllllllllllll
lllll.......lll"""""""lllllllllllllll
llll.......lllll"""""""llllllllllllll
lll.......lllllll"""""""lllllllllllll
ll.......lllllllll"""""""llllllllllll
l.......lllllllllll"""""""lllllllllll
l..>...lllllllllllll"""A""lllllllllll
l.....lllllllllllllll"""""lllllllllll
ll...lllllllllllllllll"""llllllllllll
lllllllllllllllllllllllllllllllllllll
ENDMAP

NAME:       bazaar_minmay_trees
TAGS:       no_rotate
WEIGHT:     5
ORIENT:     encompass
MONS:       bush
KFEAT:      ! = any shop
KFEAT:      ? = any shop / .
LFLOORTILE: floor_grass
LFLOORCOL:  green
: bazaar_setup(_G, false, false)
MAP
ttttttttttttttt
ttttttttttttttt
tttttt.>.tttttt
tttt.......tttt
ttt.........ttt
ttt..11.11..ttt
tt...1!.!1...tt
tt.?.1...1.?.tt
tt...1!.!1...tt
ttt..11111..ttt
ttt.........ttt
tttt.......tttt
tttttt.<.tttttt
ttttttttttttttt
ttttttttttttttt
ENDMAP

NAME:   bazaar_minmay_armour_weapon
TAGS:   no_rotate no_species_fe
WEIGHT: 5
ORIENT: encompass
KFEAT:  A = antique weapon shop
KFEAT:  B = antique armour shop
:       bazaar_setup(_G)
MAP
      xxxxx
     xx...xx
     x.....x
     x..<..x
     x.....x
     xx...xx
      x...x
 xxxxxx...xxxxxx
xx...xx...xx...xx
x.....x...x.....x
x..A..+...+..A..x
x.....x...x.....x
xx...xx...xx...xx
 xxxxx.....xxxxx
     x.....x
 xxxxx.....xxxxx
xx...xx...xx...xx
x.....x...x.....x
x..B..+...+..B..x
x.....x...x.....x
xx...xx...xx...xx
 xxxxxx...xxxxxx
      x...x
     xx...xx
     x.....x
     x..>..x
     x.....x
     xx...xx
      xxxxx
ENDMAP

NAME:   bazaar_minmay_snake
TAGS:   no_rotate
WEIGHT: 5
ORIENT: encompass
SHUFFLE: !?
KFEAT:  ! = any shop
KFEAT:  ? = any shop / T
:       bazaar_setup(_G)
MAP
 xxxxx         xxxxx         xxxxx
xx...xxxxxxxxxxx...xxxxxxxxxxx...xx
x.................................x
x..<.............!.............?..x
x.................................x
xx...xxxxxxxxxxx...xxxxxxxxxxx...xx
 xxxxx         xxxxx         x...x
                             x...x
                             x...x
                             x...x
                             x...x
                             x...x
                             x...x
                             x...x
 xxxxx         xxxxx         x...x
xx...xxxxxxxxxxx...xxxxxxxxxxx...xx
x.................................x
x..?.............!.............?..x
x.................................x
xx...xxxxxxxxxxx...xxxxxxxxxxx...xx
 x...x         xxxxx         xxxxx
 x...x
 x...x
 x...x
 x...x
 x...x
 x...x
 x...x
 x...x         xxxxx         xxxxx
xx...xxxxxxxxxxx...xxxxxxxxxxx...xx
x.................................x
x..?.............!.............>..x
x.................................x
xx...xxxxxxxxxxx...xxxxxxxxxxx...xx
 xxxxx         xxxxx         xxxxx
ENDMAP

NAME:       bazaar_minmay_plants
TAGS:       no_rotate
WEIGHT:     5
ORIENT:     encompass
MONS:       plant / bush w:6, yak tile:mons_yak_bow att:neutral
KFEAT:      ! = any shop
SUBST:      " = """"111t
KPROP:      -"12t = no_tele_into
LFLOORTILE: floor_grass
LFLOORCOL:  green
: bazaar_setup(_G, false, false)
: decorative_floor(_G, '-', "garden patch")
MAP
""""""""""""""""""""""""""""""""">
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
"""""""""mmmmm""""""mmmmm"""""""""
"""""""""m...mm""""mm...m"""""""""
"""""""""m.!..mm-2mm..!.m"""""""""
"""""""""m.....mmmm.....m"""""""""
"""""""""mm............mm"""""""""
""""""""""mm..........mm""""""""""
"""""""""""mm...-cc..mm"""""""""""
""""""""""""m..cc>c..m-"""""""""""
"""""""""""-m..c<c-..m""""""""""""
"""""""""""mm..ccc...mm"""""""""""
""""""""""mm..........mm""""""""""
"""""""""mm............mm"""""""""
"""""""""m.....mmmm.....m"""""""""
"""""""""m.!..mm2-mm..!.m"""""""""
"""""""""m...mm""""mm...m"""""""""
"""""""""mmmmm""""""mmmmm"""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""
ENDMAP

# 4 random shops
NAME:   grunt_bazaar_doublecross
DEPTH:  Bazaar
ORIENT: encompass
KFEAT:  A = any shop
SUBST:  T = G:20 T V U:1
:       bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxx
xT.xxxxxxxxxxx.Tx
x.A.xxxxxxxxx.A.x
xxx...xxxxx...xxx
xxxxx.......xxxxx
xxxxxxx.T.xxxxxxx
xxxxx.......xxxxx
xxx...xxxxx...xxx
x...xx+.<.+xx...x
xT.xxxx.T.xxxx.Tx
x...xx+.>.+xx...x
xxx...xxxxx...xxx
xxxxx.......xxxxx
xxxxxxx.T.xxxxxxx
xxxxx.......xxxxx
xxx...xxxxx...xxx
x.A.xxxxxxxxx.A.x
xT.xxxxxxxxxxx.Tx
xxxxxxxxxxxxxxxxx
ENDMAP

# 3 to 4 shops, with an average of 3.5
NAME:       bazaar_kenran_forest_clearing
ORIENT:     encompass
WEIGHT:     5
KITEM:      h = human skeleton
KITEM:      c = black bear skeleton
KFEAT:      $ = any shop
KFEAT:      # = antique weapon shop / antique armour shop / \
                antiques shop / book shop
KFEAT:      A = abandoned_shop
NSUBST:     $ = 1=$A
NSUBST:     H = 1=h / *=.
SUBST:      $ = #:20 $
SUBST:      R = t:20 .
: if crawl.one_chance_in(4) then
KFEAT:      F = V
TILE:       t = dngn_tree_dead w:10 / dngn_tree_red w:3 / \
                dngn_tree_lightred w:2
COLOUR:     . = brown, t = brown w:10 / red w:3 / lightred w:2
: else
TILE:       t = dngn_tree w:3 / dngn_tree_yellow w:2 / \
                dngn_tree_lightred w:2 / dngn_tree_red w:3
KFEAT:      F = T
COLOUR:     . = green, t = green w:3 / lightgreen w:2 / \
                lightred w:3 / red w:2 / brown w:1
: end
:           bazaar_setup(_G)
MAP
ttttttttttttttttttttttttt
tttttttttttttttttttttt>tt
ttttttttttttttttttttt.ttt
ttttttttttttttttttttt.ttt
ttttttttttttttcttt.t..Rtt
ttttttttttttttt.ttt..tttt
tttt$.ttttttttt.....ttttt
tt.t...ttttttt..t.ttRtttt
tt...tRttttt..ttRtttt..tt
tttt....ttt...tt..tt....t
ttttRt.t.t....t..t...t.$t
ttttt..t..t.F..ttttRttttt
tttttt........tH.Attttttt
tttttttt.tt..tHt..ttttttt
tttttR....t..t.HHtR.$tttt
tttttt.t...t..t.tt...tttt
ttt......t.....t....ttttt
ttG.t..tt....tt...ttttttt
t......tttt..tRtttttttttt
t$..t.tttttt....ttttttttt
ttt....ttt...ttGttttttttt
ttttttttt...ttttttttttttt
ttttttttt..tttttttttttttt
tttttttttt...tttttttttttt
ttttttttttt..tttttttttttt
ttttttttttt.t.ttttttttttt
tttttttttt..ttttttttttttt
ttttt.tt...tttttttttttttt
ttt<.....tttttttttttttttt
ttttttt.ttttttttttttttttt
ttttttttttttttttttttttttt
ENDMAP

##########################################################################
# Very rare maps, including dangerous maps (weight 1)
##########################################################################

# 4.4 shops
NAME:    bazaar_jpeg_triangles
TAGS:    no_rotate
ORIENT:  encompass
WEIGHT:  1
SHUFFLE: ACD
SUBST:   A = <
KFEAT:   B = any shop / antique armour shop / jewellery shop
SUBST:   C = >
SUBST:   D = T
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxAxxxC............+...xxxxxxxxx
xxxxxxxx...xxx...........xxx...xxxxxxxx
xxxxxxx.....xxx....B....xxx.....xxxxxxx
xxxxxx.......xxx.......xxx.......xxxxxx
xxxxx....B....xxx.....xxx....B....xxxxx
xxxx...........xxx...xxx...........xxxx
xxxA............+...xxxD...........Dxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_hexagon
TAGS:    no_rotate
ORIENT:  encompass
WEIGHT:  1
SHUFFLE: AC, BD
KFEAT:   A = armour shop / weapon shop / jewellery shop
KFEAT:   B = general shop
KFEAT:   C = scroll shop / book shop / distillery shop
SUBST:   D = >
SUBST:   = : +x
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxx.................===.xxxxxxxxx
xxxxxxxx.............A...xxx...xxxxxxxx
xxxxxxx.................xxx.....xxxxxxx
xxxxxx........<........xxx.......xxxxxx
xxxxx.................xxx....B....xxxxx
xxxx...A.............xxx...........xxxx
xxx.................xxx.............xxx
xxx+xxxxxxxxxxxxxxx+xxxxxxxxxxxxxxx+xxx
xxx+xxxxxxxxxxxxxxxx+xxxxxxxxxxxxxx+xxx
xxx.............===.................xxx
xxxx...........xxx.............C...xxxx
xxxxx....D....xxx.................xxxxx
xxxxxx.......xxx........>........xxxxxx
xxxxxxx.....xxx.................xxxxxxx
xxxxxxxx...xxx...C.............xxxxxxxx
xxxxxxxxx.xxx.................xxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_jpeg_triangle_bulge
TAGS:    no_rotate
ORIENT:  encompass
WEIGHT:  1
SHUFFLE: AB
SUBST:   A = <, B = >
KFEAT:   C = any shop
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxCxxxxxxxxxxxxxx
xxxxxxxxxxxx.....xxxxxxxxxxxx
xxxxxxxxxx.........xxxxxxxxxx
xxxxxxxx....B...B....xxxxxxxx
xxxxxx.................xxxxxx
xxxx....C.....B.....C....xxxx
xxA.......................Axx
xxxxxxxxxxxxx...xxxxxxxxxxxxx
xxxxxxxxxxxxx...xxxxxxxxxxxxx
xxxxxxxxxxxx.....xxxxxxxxxxxx
xxxxxxxxxxx...C...xxxxxxxxxxx
xxxxxxxxxxxx.....xxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

# ~3.75 shops
NAME:     due_bazaar_butterfly
TAGS:     no_rotate
ORIENT:   encompass
WEIGHT:   1
SHUFFLE:  AEST
NSUBST:   A = 1:A / 1:B / 1:C / 1:D
SUBST:    E=>, S=T, T:TUV, D=ABC.
KFEAT:    A = armour shop / weapon shop / jewellery shop
KFEAT:    B = general shop
KFEAT:    C = scroll shop / book shop / distillery shop
: if crawl.coinflip() then
SUBST:    '=+, "=x, :=x
: else
SUBST:    '=x, "=., :=.
: end
:         bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xE..xxxxxxx...xx.......xx...xxxxxxx..Ex
xxx...xxxxx.T.''...A...''.T.xxxxx...xxx
xxxxx.+...+...xx.......xx...+...+.xxxxx
xxxxxxx...xxxxxxxxx+xxxxxxxxx...xxxxxxx
xxxxxxxxx.":xxxxxxx.xxxxxxx:".xxxxxxxxx
xxxxxxxxxxx::::xxxx.xxxxx:::xxxxxxxxxxx
x...xx.S.xxxxx::"xx+xx":::xxx.S.xx...xx
x...xx...xxxxxxxx.....xxxxxxx...xx...xx
x...xxx+xxxxxxxxx.....xxxxxxxx+xxx...xx
x.A.+...........+..<..+..........+.A.xx
x...xxx+xxxxxxxxx.....xxxxxxxx+xxx...xx
x...xx...xxxxxxxx.....xxxxxxx...xx...xx
x...xx.S.xxxx:::"xx+xx":::xxx.S.xx...xx
xxxxxxxxxxx:::xxxxx.xxxxx:::xxxxxxxxxxx
xxxxxxxxx:::xxxxxxx.xxxxxxx:::xxxxxxxxx
xxxxxxx.":xxxxxxxxx+xxxxxxxxx:".xxxxxxx
xxxxx...xxx...xx.......xx...xxx...xxxxx
xxx.+.....+.T.''...A...''.T.+.....+.xxx
xE..xxxxxxx...xx.......xx...xxxxxxx..Ex
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:    bazaar_minmay_challenge
TAGS:    no_rotate
WEIGHT:  1
ORIENT:  encompass
SUBST:   B = ., N = ., n = T, t = ., ' = ., " = .
KITEM:   ? = wand of digging pre_id no_pickup
KFEAT:   ? = antiques shop
KFEAT:   ! = any shop
SUBST:   T = V T U:1
SHUFFLE: XY
SUBST:   X = T
NSUBST:  Y = 1:< / *:>
:        bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxx'''...'''xxxxxxxx
xxxxxxx''''.X.''''xxxxxxx
xxxxxx'''''...'''''xxxxxx
xxxxx"""""".Y.""""""xxxxx
xxxx.................xxxx
xxx".BBBBBBNnNBBBBBB."xxx
xx'".B.............B."'xx
x''".B..bbbmmmbbb..B."''x
x''".B..b.......b..B."''x
x''".B..b.!...!.b..B."''x
x....N..m.......m..N....x
x..!.NTtm...>...mtTN.?..x
x....N..m.......m..N....x
x''".B..b.!...!.b..B."''x
x''".B..b.......b..B."''x
x''".B..bbbmmmbbb..B."''x
xx'".B.............B."'xx
xxx".BBBBBBNnNBBBBBB."xxx
xxxx.................xxxx
xxxxx"""""".Y.""""""xxxxx
xxxxxx'''''...'''''xxxxxx
xxxxxxx''''.X.''''xxxxxxx
xxxxxxxx'''...'''xxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:   bazaar_minmay_noklob
TAGS:   no_rotate
WEIGHT: 1
ORIENT: encompass
KFEAT:  ! = any shop
SUBST:  . = 1 .:200, ' = ., 2 = 1.
MONS:   plant
:       bazaar_setup(_G)
MAP
xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx.!..'..!.xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxx'''xxx....'....xxx'''xxx
xxx'<''+.....'.....+''>'xxx
xxx'''xxx....'....xxx'''xxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxx'''xxx....'....xxx'''xxx
xxx'!''+2....'....2+''!'xxx
xxx'''xxx....'....xxx'''xxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxx.!..>..!.xxxxxxxxx
xxxxxxxxx....'....xxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx
ENDMAP

NAME:   bazaar_minmay_mutagenic_fog
TAGS:   no_rotate
ORIENT: encompass
WEIGHT: 1
KFEAT:  ! = general shop
MARKER: F = lua:fog_machine { cloud_type = "mutagenic fog", \
             pow_min = 1, pow_max = 3, delay_min = 5, delay_max = 10, \
             size = 1, walk_dist = 0, spread_rate= 0 }
NSUBST: < = 1:< / *:.
:       bazaar_setup(_G)
MAP
xxxxxxxxx     xxxxxxxxx
x.......x     x.......x
x.>...!.x     x.!...>.x
x.......x     x.......x
x...<...x     x...<...x
x.......x     x.......x
x.!.....xxx xxx.....!.x
x.......x.xxx.x.......x
xxxxxxxx.x.x.x.xxxxxxxx
      x.xx...xx.x
      xx.......xx
       xx..F..xx
      xx.......xx
      x.xx...xx.x
xxxxxxxx.x.x.x.xxxxxxxx
x.......x.xxx.x.......x
x.!.....xxx xxx.....!.x
x.......x     x.......x
x...<...x     x...<...x
x.......x     x.......x
x.>...!.x     x.!...>.x
x.......x     x.......x
xxxxxxxxx     xxxxxxxxx
ENDMAP

NAME:   bazaar_kenran_lighthouse
TAGS:   no_pool_fixup
ORIENT: encompass
WEIGHT: 1
KMONS:  1 = ophan generate_awake
SUBST:  p = ppw, q = wwW, r = ....W
KFEAT:  p = open_sea
KFEAT:  A = any shop
FTILE:  -A>1+ = floor_pebble
FTILE:  ' = floor_rough
FTILE:  .< = floor_sand
TILE:   c = wall_brick_lightgray
# XXX For some reason, setting color on these alone doesn't change the tile.
TILE:   n = dngn_transparent_stone_yellow
COLOUR: . = brown
COLOUR: -' = white
COLOUR: n = yellow
: set_border_fill_type("open_sea")
: bazaar_setup(_G, false, false)
MAP
              pppppppppppp
           ppppwwwwwwwwwwppp
         pppwwwwwwwwwwwwwwwpppp
       pppwwwwwwwqqqqqqwwwwwwwpppp
      ppwwwwwwqqqqqWWWqqqwwwwwwwwp
      pwwwwwqqqWWWWWWWWWqqqqwwwwwpp
     ppwwwqqqWWWWWrrrrWWWWWqqqqwwwp
   pppwwwqqWWWWWrr'...rWWWWWWWqwwwpp
  ppwwwwwqWWWWrr..''...rrWWrWWqqwwwp
  pwwwwwqqWWWr..''''''....rWWWWqwwwpp
  pwwwqqqWWrr.''cnnnc'''...rrWWqqwwwp
  pwwqqWWWr.''ccc---ccc''..rWWWWqwwwppp
  pwwqWWWWr''nn-------nn''..rWWWqqwwwwpp
 ppwwqWrrr.'cn---------nc'..rrWWWqwwwwwp
ppwwwqWWr.''c--A-----A--c''..rWWWqqqwwwpp
pwwwwqWWr.'cc-----------cc'...rWWWWqqwwwp
pwwwqqWr.''n-----nnn-----n''...rWWWWqwwpp
pwwqqWrr.''n->---n1n-----+---...rrWWqqwwp
pwwwqWWWr''n-----nnn-----n'.---<rWWWqqwwp
ppwwqqWWr.'cc-----------cc'.....rWWqqwwpp
pwwwqqWr..''c--A-----A--c''...rrWWWWqwwwp
pwwqqWWr..''cn---------nc'...rWrrWWWqwwpp
pwwwqqWr...''nn-------nn'''.rrWWWWWqqwwp
pwwwqqWWrr..''ccc---ccc'''.rWWWWWWqqwwpp
ppwwwqWWWWr...''cnnnc'''r...rWWWWWWqqwwp
 pwwwqWWWrr...''''''''.rWr.r.rWWWWWqwwwp
 ppwwqqWWWWr...''.rr..rWWrrWr.rWWWWqqwwp
  pwwwqWWWWrr....rWWr.rWWWWWWrWWWWWqwwpp
  pwwwqqWWWWWrrrrWWWrrWWWWWWWWWWWWqqwwwp
  ppwwwqqqqWWWWWWWWWWWWWWWWWWqWWWWqwwwpp
   pwwwwwwqqWWWWWqqqWWWWqqqqqqqqWqqwwwp
   ppwwwwwwqqqWWqqqqqqqqqwwwwwwqqqwwwpp
    ppppwwwwwqqqqwwwwwwwwwwwwwwwwwwwwp
       ppwwwwwwwwwwwwwwwwwpppwpwwwwwpp
        pppwwwwwwwwpppppppp ppppppppp
          pppppppppp
ENDMAP

##########################################################################
# Generated maps
##########################################################################

# With Nemelex's bazaars gone, the number of bazaars in a game is sharply
# limited.  This one keeps allow_dup, just in case.
NAME:   bazaar_kb_twisted_cavern
TAGS:   allow_dup
ORIENT: encompass
WEIGHT: 50
{{
    -- Restricting the map to a smaller box might be good (more forks) but
    -- by allowing the whole level we mostly avoid straight borders.
    local gxm, gym = dgn.max_bounds()
    extend_map{width = gxm, height = gym}
    fill_area{fill = 'x', border = 'X'}

    -- 4th argument is the size of the cavern to be delved.
    delve(3, 3, 0, 150, 1)

    -- place one marker (shop / entrance / exit) at random
    nsubst('. = 1:C / *:.')
    -- then add five or six more (for 4-5 shops), using a greedy algorithm
    for i = 1, 5 + crawl.random2(2) do
      local x, y = farthest_from('C')
      mapgrd[x][y] = 'C'
    end
    nsubst('C = 1:< / 1:> / *:C')
    subst('X = x')
    kfeat('C = any shop')
    bazaar_setup(_G, true, false, false)
}}

##########################################################################
# Xom's unique bazaar maps
#
# Only seen when Xom directly pulls you into a bazaar.
# Heavily customized in flavour and power to emphasize Xom's love of risks.
##########################################################################

NAME:    regret_index_bazaar_xom_original
TAGS:    allow_dup xom_bazaar
ORIENT:  encompass
KMONS:   p = pile of debris
KMONS:   E = demonic plant
KMONS:   f = butterfly perm_ench:paralysis
KITEM:   d = potion of moonshine pre_id
KITEM:   r = large rock
KITEM:   s = human skeleton / kobold skeleton / orc skeleton / \
             naga skeleton / merfolk skeleton / spriggan skeleton
KITEM:   $ = $ no_pickup
KFEAT:   g = metal_statue
KFEAT:   h = stone_wall
KFEAT:   t = demonic_tree
KFEAT:   ^ = permanent teleport trap
KFEAT:   y = x
KFEAT:   D = abandoned_shop
KFEAT:   X = altar_xom
KFEAT:   + = closed_clear_door
KFEAT:   u = fountain_eyes
NSUBST:  A = 1:A / 1:B / 1:C / *:D
NSUBST:  ? = 1:E+ / 2 = E+n / * = xy
NSUBST:  X = 2:X / 2:g / 2:G / 2:D / 2 = UUu / 2 = YYu / 2:> / * = XgGDUuY
# Each of the eight passages towards possible shops
# has different randomized decor configurations.
SHUFFLE: HIJKLMNOPQRS
NSUBST:  H = 6:t / 2 = t. / 1:s / 2 = s. / 10:' / *:.
NSUBST:  I = 8:^ / 4 = ^. / 8 = +. / 10:' / *:.
NSUBST:  J = 3:c / 2 = y / 1 = cy.. / 15 = p. / 10:' / *:.
NSUBST:  K = 6:f / 3:E / 5 = fE... / 10:' / *:.
NSUBST:  L = 11:W / 2 = W. / 4 = E. / 4 = x... / 10:' / *:.
NSUBST:  M = 24:+ / 2 = +. / 2:c / 2 = cxy / 10:' / *:.
NSUBST:  N = 4:$ / 2:s / 2 = s. / 2 = EEg.. / 10:' / *:.
NSUBST:  O = 4:F / 2 = bn / 4 = s. / 10:' / *:.
NSUBST:  P = 2:d / 2:d. / 4 = t. / 8 = +. / 2 = n. / 10:' / *:.
NSUBST:  Q = 1:c / 2 = xy / 2:fpp / 2:r / 10:' / *:.
NSUBST:  R = 4:$ / 15:' / *:.
NSUBST:  S = 2:t / 2:^ / 2:F / 4 = +W / 2 = xy / *:.
SUBST:   b = bbbn, - = ccxy
SUBST:   " = bbbnnnnxycct^+g ":300
KPROP:   "`^ = no_tele_into
COLOUR:  W = lightgreen
FTILE:   t = floor_nerves_magenta
TILE:    v = wall_crypt_metal
MARKER:  F = lua:fog_machine { cloud_type = "magical condensation", \
             pow_min = 6, pow_max = 7, delay_min = 60, delay_max = 80, size = 8 }
MARKER:  + = lua: props_marker { connected_exclude="true" }
: vault_granite_statue_setup(_G, "G", "scintillating statue")
: vault_metal_statue_setup(_G, "g", "misfortune conduit")
: bazaar_setup(_G, false, false, true)
{{
local magi_name = util.random_from({"type:Ever-Affordable suffix:Forbidden_Knowledge",
                                    "type:Easily-Learnt suffix:Chaos_Theory",
                                    "type:Trivially-Accessible suffix:Secrets",
                                    "type:Fathomable suffix:Mysteries"})
local equip_name = util.random_from({ "type:Avant-Garde suffix:Galleria",
                                      "type:Bespoke suffix:Boutique",
                                      "type:Haute_Couture suffix:Collection",
                                      "type:Ready-to-Wear suffix:Runway" })

-- Spells that Xom effects can specifically invoke, which resemble other effects
-- Xom can do, or which come inherently with some sort of risk, in schools
-- less focused on direct destruction (besides Alchemy).
-- TODO: Properly crunch down all this boilerplate.
local hexspells = util.random_subset({ "jinxbite", "confusing_touch", "tukima's_dance",
                                       "yara's_violent_unravelling", "discord" }, 2)
local alchspells = util.random_subset({ "mephitic_cloud", "olgreb's_toxic_radiance",
                                        "alistair's_intoxication", "irradiate",
                                        "fulsome_fusillade" }, 2)
local necrospells = util.random_subset({ "kiss_of_death", "sublimation_of_blood",
                                         "fugue_of_the_fallen", "cigotuvi's_putrefaction",
                                         "death's_door" }, 2)
local tlocspells = util.random_subset({ "maxwell's_portable_piledriver",
                                        "volatile_blastmotes", "gell's_gavotte",
                                        "dispersal", "malign_gateway" }, 2)
local summspells = util.random_subset({ "call_imp", "martyr's_knell",
                                        "summon_forest", "summon_cactus_giant",
                                        "summon_horrible_things" }, 2)
local forgespells = util.random_subset({ "iskenderun's_battlesphere", "awaken_armour",
                                         "forge_blazeheart_golem", "alistair's_walking_alembic",
                                         "diamond_sawblades" }, 2)

local hexbook = "randbook owner:Xom title:Mystic_Anarchy disc:hexes " ..
                "numspells:2 spells:" .. table.concat(hexspells, '&&' )
local alchbook = "randbook owner:Xom title:Mad_Science disc:alchemy " ..
                 "numspells:2 spells:" .. table.concat(alchspells, '&&' )
local necrobook = "randbook owner:Xom title:Vocational_Suffering disc:necromancy " ..
                  "numspells:2 spells:" .. table.concat(necrospells, '&&' )
local tlocbook = "randbook owner:Xom title:Spontaneous_Journeys disc:translocation " ..
                 "numspells:2 spells:" .. table.concat(tlocspells, '&&' )
local summbook = "randbook owner:Xom title:Meeting_Friends disc:summoning " ..
                 "numspells:2 spells:" .. table.concat(summspells, '&&' )
local forgebook = "randbook owner:Xom title:Making_Friends disc:forgecraft " ..
                  "numspells:2 spells:" .. table.concat(forgespells, '&&' )

local use_books = table.concat(util.random_subset({hexbook, alchbook,
                  necrobook, tlocbook, summbook, forgebook}, 3), ' | ')

-- Manual options: above spell schools, other magical items offered in the same
-- shop, and a joke dud of Stealth since Xom will break it constantly.
local manuals = {"hexes", "alchemy", "necromancy", "translocations",
                 "summonings", "forgecraft", "evocations", "shapeshifting",
                 "stealth", "stealth", "stealth", "stealth"}
local manual = "manual of " .. util.random_from(manuals)

local wand = table.concat(util.random_subset({
             "any blast wand charges:" .. crawl.random_range(12, 18),
             "any hex wand charges:" .. crawl.random_range(12, 18),
             "wand of polymorph charges:" .. crawl.random_range(12, 18)}, 2), " | ")

-- Only chaos weapons: two randarts and one good_item.
-- Unrands are chosen for chaotic / demonic flavour, inherent risks,
-- or very niche build support.
local equip_count = 7
local weaps = { "demon blade", "double sword", "triple sword",
                "demon trident", "partisan", "bardiche", "demon whip",
                "eveningstar", "great mace", "broad axe", "battleaxe",
                "executioner's axe", "lajatang", "hand cannon", "longbow",
                "triple crossbow", "rapier", "quick blade"}
weaps = util.random_subset(weaps, 3)

local equips = {}

equips[1] = weaps[1] .. ' ego:chaos randart plus:' .. crawl.roll_dice(3, 4)
equips[2] = weaps[2] .. ' ego:chaos randart plus:' .. crawl.roll_dice(2, 5)
equips[3] = weaps[3] .. ' ego:chaos good_item plus:' .. crawl.roll_dice(3, 2)

if crawl.x_chance_in_y(3, 4) then
  equip_count = equip_count + 1

  local baseunlist = { "plutonium_sword", "singing_sword", "obsidian_axe",
                       "glaive_of_prune", "mace_of_variability", "firestarter",
                       "majin-bo", "robe_of_folly", "robe_of_misfortune",
                       "maxwell's_patent_armour", "orange_crystal_plate_armour",
                       "shield_of_the_gong", "tower_shield_of_ignorance",
                       "hat_of_the_bear_spirit", "mad_mage's_maulers",
                       "ratskin_cloak", "slick_slippers", "seven-league_boots",
                       "skull_of_zonguldrok", "fungal_fisticloak", "crown_of_vainglory"}

  local chaoticlist = { "spriggan's_knife", "captain's_cutlass", "gyre",
                        "maxwell's_thermic_engine",
                        "autumn_katana", "elemental_staff", "wrath_of_trog",
                        "frostbite", "consecrated_labrys", "wyrmbane",
                        "rift", "glaive_of_the_guard", "lochaber_axe",
                        "eos", "spellbinder", "sceptre_of_torment",
                        "punk", "storm_bow", "mule" }

  if crawl.coinflip() then
    table.insert(equips, util.random_from(baseunlist))
  else
    table.insert(equips, "chaotic " .. util.random_from(chaoticlist))
  end
end

equips = table.concat(equips, ' | ')

-- To make it more obvious the rings are deliberately pairing their upsides
-- with both an unequip punishment and a negative resist, use the same
-- unequip punishment and negative resist for both rings.
local unequip = { "^Contam", "^Drain"}
local resist = {"rF:-1", "rC:-1", "Will:-1"}
local jewellery = {"any ring randart artprops:", "any ring randart artprops:",
                   "any ring randart artprops:",
                   "amulet of faith randart artprops:Regen:1&"}
local jewel1 = util.random_from(jewellery) .. util.random_from(unequip) .. "&" ..
               util.random_from(resist)
local jewel2 = util.random_from(jewellery) .. util.random_from(unequip) .. "&" ..
               util.random_from(resist)

-- Niche or double-edged aux armour given extra artprop juice or mixed benefits.
local aux = table.concat(util.random_subset({
            "orb ego:mayhem randart artprops:Int:" .. crawl.random_range(4, 8),
            "orb ego:guile randart artprops:Dex:" .. crawl.random_range(4, 8),
            "orb ego:glass randart artprops:Harm",
            "orb ego:pyromania randart artprops:rF:1&&rC:-1",
            "orb ego:stardust randart artprops:Conj&&MP:" .. crawl.random_range(-2, -5),
            "orb ego:mesmerism randart artprops:Will:-1&&Rampage",
            "orb ego:attunement randart artprops:Str:" .. crawl.random_range(4, 8),
            "scarf ego:harm randart artprops:Slay:" .. crawl.random_range(3, 5)}, 2), " | ")

-- Double-sided consumables and niche darts. Since only Xom worshippers see
-- this bazaar, the potions of mutation are fine to hand out.
-- Only give out one each of the most potentially useful options.
local darts = { "dart ego:atropa w:3", "dart ego:datura w:3",
                "dart ego:disjunction w:3" }
local interest = util.random_from({"potion of berserk rage w:12",
                                   "potion of ambrosia w:12",
                                   "scroll of silence w:12"})

darts = table.concat(darts, ' q:' .. crawl.random_range(5, 8) .. ' | ' ) ..
        ' q:' .. crawl.random_range(5, 8)

local cons = {};
local consum = { "potion of attraction", "potion of lignification",
                 "potion of mutation", "scroll of poison",
                 "scroll of vulnerability", "scroll of immolation" }

for _, consumables in ipairs(consum) do
    table.insert(cons, consumables .. " q:" .. crawl.random_range(1, 4))
end

table.insert(cons, interest .. " q:" .. crawl.random_range(2, 3))

-- Only Xom gets to get away with this particular lack of niceness.
if you.race() ~= "Mummy" and you.race() ~= "Revenant"
     and you.race() ~= "Poltergeist" then
    table.insert(cons, "scroll of torment w:5 q:" .. crawl.random_range(1, 4))
end

cons = table.concat(cons, " | ")

-- Finally, assemble the shops.
-- TODO: implement chaotic talismans that also grant a free chaos brand, then
-- add back a third talisman drop to the spells + talisman shop.
kfeat('A = book shop no_mimic ' .. magi_name .. ' greed:8 count:8 use_all ; ' ..
           use_books .. ' | ' .. manual .. ' | ' ..  ' any talisman | ' ..
           ' any talisman randart | ' .. wand)
kfeat('B = weapon shop no_mimic ' .. equip_name .. ' greed:11 ' ..
           ' count:' .. equip_count .. ' use_all ; ' .. equips .. ' | ' ..
           jewel1 .. ' | ' .. jewel2 .. ' | ' .. aux)
kfeat('C = general shop no_mimic type:Party suffix:Supplies greed:6 count:' ..
           crawl.random_range(7, 11) .. ' ; ' .. darts .. ' | ' .. cons)

-- Xom bazaars should look quite garishly variable.
if crawl.x_chance_in_y(4, 7) then
  local feature = util.random_from({'tree', 'petrified_tree', 'demonic_tree',
                                    'open_sea', 'endless_lava'})
  kfeat('Z = ' .. feature)
  set_border_fill_type(feature)
else
  kfeat('Z : iron_grate')
  subst('Z : vhZ+')
  set_border_fill_type(util.random_from({'rock_wall', 'stone_wall', 'metal_wall'}))
end

local cols = util.random_subset( { "magenta", "blue", "red",
                                   "green", "cyan" }, 3)
tile('x = wall_zot_' .. cols[1] .. ' / wall_zot_light' .. cols[1] ..
          ' / wall_abyss_' .. cols[1] .. ' / wall_abyss_light' .. cols[1])
tile('y = wall_bars_' .. cols[2] .. ' / wall_bars_light' .. cols[2] ..
          ' / wall_undead_' .. cols[2] .. ' / wall_undead_light' .. cols[2])
tile('c = ' .. util.random_from({"wall_stone_mossy", "stone_wall_snake",
                                 "stone_wall_spider", "stone_wall_shoals",
                                 "stone_wall_vault", "wall_crypt"}))
tile('b = dngn_crystal_' .. cols[3] .. ' / dngn_crystal_light' .. cols[3])
tile('n = dngn_transparent_stone_' .. cols[3])
ftile("ABC' = " .. util.random_from({"floor_vines", "floor_marble",
                                     "floor_crystal_squares"}))
ftile("Z = " .. util.random_from({"floor_nerves", "floor_rough_brown",
                                  "floor_grass", "floor_pebble_red"}))
tile('h : wall_flesh / wall_stone_black_marked')
tile('v : dngn_metal_iron / dngn_metal_wall_darkgray')
lfloortile(util.random_from({"floor_slime", "floor_sandstone",
                             "floor_cobble_blood", "floor_cage"}))
}}
MAP
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZ""""""""""""""""""""""""""""""""""""""""""""ZZZZZZZZ
ZZZZZZZ""""""""""""""""""""""""""""""""""""""""""""""ZZZZZZZ
ZZZZZZ"""""""`````````````""""""""`````````````"""""""ZZZZZZ
ZZZZZ""""""""``cbbbbbbc```""""""""```cbbbbbbc``""""""""ZZZZZ
ZZZZ"""""""""``bHH..HHb```""""""""```bII..IIb``"""""""""ZZZZ
ZZZZ"""""""""``bH'''.Hbb```""""""```bbI.'''Ib``"""""""""ZZZZ
ZZZZ"""""""""``b.'A'..bbb```""""```bbb..'A'.b``"""""""""ZZZZ
ZZZZ"""""""""``b.'''..Hbbb```""```bbbI..'''.b``"""""""""ZZZZ
ZZZZ"""""""""``bH...XHH'bbb``````bbb'IIX...Ib``"""""""""ZZZZ
ZZZZ"""````````bHH..HHHHHbbb````bbbIIIII..IIb````````"""ZZZZ
ZZZZ""````````bcbbbHHHHHH'bbb``bbb'IIIIIIbbbcb````````""ZZZZ
ZZZZ""`cbbbbbbcxxxbb'HHHHHHbbbbbbIIIIII'bbxxxcbbbbbbc`""ZZZZ
ZZZZ""`bOO..OObxxxxbbHHHHHH'bbbb'IIIIIIbbxxxxbJJ..JJb`""ZZZZ
ZZZZ""`bO'''.Obxxxxxbb'HHHHHHccIIIIII'bbxxxxxbJ.'''Jb`""ZZZZ
ZZZZ""`b.'A'..bbxxxxxbbHHHHH....IIIIIbbxxxxxbb..'A'.b`""ZZZZ
ZZZZ""`b.'''..Obbxxxxxbb'HH......II'bbxxxxxbbJ..'''.b`""ZZZZ
ZZZZ""`bO...XOO'bbxxxxxbbH..X--X..Ibbxxxxxbb'JJX...Jb`""ZZZZ
ZZZZ""`bOO..OOOOObbxxxxxbb..--....bbxxxxxbbJJJJJ..JJb`""ZZZZ
ZZZZ""`cbbbOOOOOO'bbxxxxbb..-.-...bbxxxxbb'JJJJJJbbbc`""ZZZZ
ZZZZ""````bb'OO.OOObbxxbb...-..-...bbxxbbJJJJJJ'bb````""ZZZZ
ZZZZ"""""``bbOOOxOO'bbbb............bbbb'JJJJJJbb``"""""ZZZZ
ZZZZ""""""``bb'OO.OOObb..............bbJJJJJJ'bb``""""""ZZZZ
ZZZZ"""""""``bbOOOOO.........xx.........JJJJJbb``"""""""ZZZZ
ZZZZ""""""""``bb'OO.........y??x.........JJ'bb``""""""""ZZZZ
ZZZZ"""""""""``bbO..X..-...x?..?y..---X...Jbb``"""""""""ZZZZ
ZZZZ""""""""""``bc..-.-...x?.<..?x...--...cb``""""""""""ZZZZ
ZZZZ""""""""""``bc..--....x?..>.?x..-.-...cbb``"""""""""ZZZZ
ZZZZ"""""""""``bbN..X---...y?..?x..-..X...Kbbb``""""""""ZZZZ
ZZZZ""""""""``bb'NN.........x??y.........KK'bbb``"""""""ZZZZ
ZZZZ"""""""``bbNNNNN.........xx.........KKKKKbbb``""""""ZZZZ
ZZZZ""""""``bb'NNNNNNbb..............bbKKKKKK'bbb``"""""ZZZZ
ZZZZ"""""``bbNNNNNN'bbbb............bbbb'KKKKKKbbb````""ZZZZ
ZZZZ""````bb'NNNNNNbbxxbb...-..-...bbxxbbKKKKKK'bbbbc`""ZZZZ
ZZZZ""`cbbbNNNNNN'bbxxxxbb...-.-..bbxxxxbb'KKKKKKbbbb`""ZZZZ
ZZZZ""`bNN..NNNNNbbxxxxxbb....--..bbxxxxxbbKKKKK..KKb`""ZZZZ
ZZZZ""`bN...XNN'bbxxxxxbbM..X--X..Lbbxxxxxbb'KKX...Kb`""ZZZZ
ZZZZ""`b.'''..Nbbxxxxxbb'MM......LL'bbxxxxxbbK..'''.b`""ZZZZ
ZZZZ""`b.'A'..bbxxxxxbbMMMMM....LLLLLbbxxxxxbb..'A'.b`""ZZZZ
ZZZZ""`bN'''.Nbxxxxxbb'MMMMMMccLLLLLL'bbxxxxxbK.'''Kb`""ZZZZ
ZZZZ""`bNN..NNbxxxxbbMMMMMM'bbbb'LLLLLLbbxxxxbKK..KKb`""ZZZZ
ZZZZ""`cbbbbbbcxxxbb'MMMMMMbb``bbLLLLLL'bbxxxcbbbbbbc`""ZZZZ
ZZZZ""`````````cbbbMMMMMM'bb`""`bb'LLLLLLbbbc`````````""ZZZZ
ZZZZ""""""""""`bMM..MMMMMbb`""""`bbLLLLL..LLb`""""""""""ZZZZ
ZZZZ""""""""""`bM...XMM'bb`""""""`bb'LLX...Lb`""""""""""ZZZZ
ZZZZ""""""""""`b.'''..Mbb`""""""""`bbL..'''.b`""""""""""ZZZZ
ZZZZ""""""""""`b.'A'..bb`""""""""""`bb..'A'.b`""""""""""ZZZZ
ZZZZ""""""""""`bM'''.Mb`""""""""""""`bL.'''Lb`""""""""""ZZZZ
ZZZZ""""""""""`bMM..MMb`""""""""""""`bLL..LLb`""""""""""ZZZZ
ZZZZZ"""""""""`cbbbbbbc`""""""""""""`cbbbbbbc`"""""""""ZZZZZ
ZZZZZZ""""""""``````````""""""""""""``````````""""""""ZZZZZZ
ZZZZZZZ""""""""""""""""""""""""""""""""""""""""""""""ZZZZZZZ
ZZZZZZZZ""""""""""""""""""""""""""""""""""""""""""""ZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ENDMAP
