##############################################################################
# Trap: basket of spiders
###############################################################################

{{
function callback.spider_trap_stepped(data, triggerable, triggerer, marker, ev)
  if data.triggered == true then
    return
  end
  local x, y = marker:pos()
  if not you.see_cell(x, y) then
    -- pretend the monster avoided it
    return
  end
  data.triggered = true
  -- remove the trap
  dgn.grid(x, y, "floor")
  local spiders = 0
  for p in iter.rect_iterator(dgn.point(x-1, y-1), dgn.point(x+1, y+1)) do
    if (dgn.mons_at(p.x, p.y) == nil and p ~= you.pos() and dgn.is_passable(p.x, p.y)) then
      if (dgn.create_monster(p.x, p.y, "generate_awake spider")) then
        spiders = spiders + 1
      end
    end
  end
 if (spiders > 0) then
   crawl.mpr("A basket of spiders falls from above!")
 end
end
}}

#############################################
# a basket of spiders
#
NAME:   spider_trap
DEPTH:  D:9-27, Vaults, Elf, Spider, Snake
TAGS:   allow_dup extra luniq_spider_trap
WEIGHT: 100
KFEAT:  ^ = pressure plate trap
{{
 local tm = TriggerableFunction:new{func="callback.spider_trap_stepped",
              repeated=true,
              data={triggered=false} }
 tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
 lua_marker('^', tm)
}}
MAP
...
.^.
...
ENDMAP
