##############################################################################
# Megacathedral, for the bats on the brink of extinction. Or beyond. (due)

{{
function callback.cathedral_bats (data, triggerable, triggerer, marker, ev)
  if triggerer.type ~= "turn" or triggerer.sub_type ~= "countdown" then
    return
  end

  if data.bat_count > 10 then
    return
  end

  local x, y = marker:pos()
  local you_x, you_y = you.pos()

  if (you_x == x and you_y == y) then return end
  if dgn.mons_at(x, y) then return end

  if (not dgn.create_monster(x, y,
          "generate_awake bat name:megabat n_rpl n_spe n_des n_noc tile:mons_megabat / " ..
          "generate_awake w:2 fire bat")) then
    return
  end

  data.bat_count = data.bat_count + 1

  if you.see_cell(x, y) then
    crawl.mpr("A bat flies out of a crevice!")
  end
end
}}

NAME:   due_megacathedral
ORIENT: float
DEPTH:  D:8-14
MONS:   wraith / shadow w:2
MONS:   flayed ghost
TAGS:   no_rotate no_vmirror no_hmirror
NSUBST: C = 5:C / *:.
SUBST:  X = C
SUBST:  D = V..
{{
local cathedral_bats = TriggerableFunction:new {
    func = "callback.cathedral_bats",
    repeated = true,
    data = {bat_count=0},
}

cathedral_bats:add_triggerer(DgnTriggerer:new {
    type="turn",
    delay_min=500,
    delay_max=800
})

lua_marker('C', cathedral_bats)
lua_marker('V', cathedral_bats)
}}
MAP
             cccc.cccc
          ccccccG.Gcccccc
         ccc...cc+cc1..ccc
      ccccc..C..c.c..D..ccccc
     ccc.ccc...cc.cc...ccc.ccc
     cc1..ccc+cc...cc+ccc...cc
  ccccc.D.ccc.........ccc.C.ccccc
 cccccc...+c..ccc+ccc..c+...cccccc
 cc...cc.cc..ccc...ccc..cc.cc..1cc
cc.....ccc..cc.......cc..ccc.....cc
cc..C...+....+...X...+....+...D..cc
cc.....ccc..cc.......cc..ccc.....cc
 cc...cc.cc..ccc...ccc..cc.cc...cc
 cccccc...+c..ccc+ccc..c+...cccccc
  ccccc.D.ccc.........ccc.C.ccccc
     cc1..ccc+ccG.Gcc+ccc...cc
     ccc.ccc...cc=cc...ccc.ccc
      ccccc..D..c.c..C..ccccc
         ccc..1cc2cc...ccc
          cccccc|||cccccc
             ccccccccc
ENDMAP
