##############################################################################
# Trap: Grate
##############################################################################

{{
function callback.grate_trap_stepped(data, triggerable, triggerer, marker, ev)
  local x, y = marker:pos()
  local p = dgn.find_marker_positions_by_prop("grate", 1)[1]
  if (p == nil) then
    crawl.mpr("Error: no grate to close!")
    dgn.grid(x, y, "floor")
    return -- uh oh
  end
  -- It might be better to shove them away instead.  Since followers won't
  -- have a chance to get there yet, this means the monster came another way:
  -- most likely you displaced it, and that suggests the surroundings are
  -- likely to be full.
  if (dgn.mons_at(p.x, p.y) ~= nil or p == you.pos()) then
    if (you.see_cell(x, y)) then
      crawl.mpr("A part of the floor depresses, but nothing seems to happen.")
      return
    end
  end
  dgn.grid(p.x, p.y, "iron_grate")
  -- remove the trap
  dgn.grid(x, y, "floor")
  if (you.see_cell(p.x, p.y)) then
    crawl.mpr("An iron grate slams shut!")
  end
end
}}

#############################################
# falling grate cutting your retreat off
#
NAME:   grate_trap
DEPTH:  D:9-27, Vault:2-7, Crypt:2-5, Elf:2-5, Snake:2-5, Zot:2-5
ORIENT: float
TAGS:   allow_dup extra luniq_grate_trap layout_rooms layout_caves
KFEAT:  ^ = pressure plate trap
{{
local tm = TriggerableFunction:new{func="callback.grate_trap_stepped",
                                   repeated=true}
tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
lua_marker('^', tm)
lua_marker(',', props_marker { grate=1 })
}}
MAP
xxxx
x(,^@
xxxx
ENDMAP
