#####################################
# Cloud traps, by mumra
#
# Currently, each type uses CHANCE: 10%
#
# From clouds.cc, available cloud types:
#    "flame", "noxious fumes", "freezing vapour", "poison gas",
#    "black smoke", "grey smoke", "blue smoke",
#    "purple smoke", "translocational energy", "fire",
#    "steam", "gloom", "ink", "blessed fire", "foul pestilence", "thin mist",
#    "seething chaos", "rain", "mutagenic fog", "magical condensation",
#    "raging winds", "calcifying dust",

{{

function callback.cloud_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

    -- TODO: Randomize "coloured"
  local cloud_message = data.cloud_message or "A coloured vial drops from a hatch in the ceiling!"
  local cloud_type = data.cloud_type or "thin mist"
  local walk_dist = 0
  local pow_min = 1
  local pow_max = 10
  local pow_rolls = 2
  local pow_mod = data.cloud_pow_mod or 1
  local kill_cat = "other"
  local size = 1
  local size_mod = data.cloud_size_mod or 1
  local spread_rate = -1
  local colour = ""
  local name = ""
  local tile = ""
  local excl_rad = -1

  -- Size based on depth (max. between 10-20 clouds at Zot:5)
  -- Size is at least 2, so that players note the effect on screen.
  -- TODO: Need to see how absdepth() works in Pan, Abyss?
  local depth = you.absdepth()
  size = (depth/3 + crawl.random2(depth/3))*size_mod
  if (size<2) then
    size = 2
  end

  -- Adjust power for depth
  pow_min = pow_mod * depth/6
  pow_max = pow_mod * depth/2
  if (pow_min<1) then
    pow_min = 1
  end
  if (pow_max<2) then
    pow_max = 2
  end
  crawl.mpr(cloud_message)
  dgn.apply_area_cloud(x, y, pow_min, pow_max, pow_rolls, size,
                       cloud_type, kill_cat, spread_rate, colour, name, tile,
                       excl_rad)

  data.triggered = true
  -- remove the trap
  dgn.grid(x, y, "floor")
end

}}

NAME:   cloud_trap_poisonous
DEPTH:  D:6-15, Lair:4-8, Orc:4, Elf, Snake, Swamp
TAGS:   allow_dup extra no_dump
CHANCE: 10%
KFEAT:  ^ = gas trap
{{
  local tm = TriggerableFunction:new{func="callback.cloud_trap_stepped",
              repeated=true,
              data={triggered=false, cloud_type="poison gas"} }
  tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
  lua_marker('^', tm)
}}
MAP
^
ENDMAP

NAME:   cloud_trap_fire
DEPTH:  D:10-27, Zot, Elf:4-5, Geh
TAGS:   allow_dup extra no_dump
CHANCE: 10%
KFEAT:  ^ = gas trap
{{
  local tm = TriggerableFunction:new{func="callback.cloud_trap_stepped",
              repeated=true,
              data={triggered=false, cloud_type="flame", cloud_pow_mod=0.3, cloud_size_mod=0.6,
                cloud_message="Fire belches from an orifice in the ground!" } }
  tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
  lua_marker('^', tm)
}}
MAP
^
ENDMAP

NAME:   cloud_trap_ice
DEPTH:  D:10-27, Zot, Elf:4-5, Coc
TAGS:   allow_dup extra no_dump
CHANCE: 10%
KFEAT:  ^ = gas trap
{{
  local tm = TriggerableFunction:new{func="callback.cloud_trap_stepped",
              repeated=true,
              data={triggered=false, cloud_type="freezing vapour", cloud_pow_mod=0.3, cloud_size_mod=0.6,
                cloud_message="A freezing wind blows from a nearby grate!" } }
  tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
  lua_marker('^', tm)
}}
MAP
^
ENDMAP

NAME:   cloud_trap_chaos
DEPTH:  D:20-27, Zot:2-4, Abyss
CHANCE: 10%
TAGS:   allow_dup extra abyss no_dump
KFEAT:  ^ = gas trap
{{
  local tm = TriggerableFunction:new{func="callback.cloud_trap_stepped",
              repeated=true,
              data={triggered=false, cloud_type="seething chaos", cloud_size_mod=0.8,
                cloud_message="Space ruptures around you!" } }
  tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
  lua_marker('^', tm)
}}
MAP
^
ENDMAP

NAME:   cloud_trap_miasma
DEPTH:  D:20-27, Zot, Abyss, Crypt, Tomb, Tar
CHANCE: 10%
TAGS:   allow_dup extra abyss no_dump
KFEAT:  ^ = gas trap
{{
  local tm = TriggerableFunction:new{func="callback.cloud_trap_stepped",
              repeated=true,
              data={triggered=false, cloud_type="foul pestilence",
                cloud_message="The stench of death fills the air!"} }
  tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
  lua_marker('^', tm)
}}
MAP
^
ENDMAP

# These next two are problematic. Petrify rarely does anything interesting, and
# the confusion one is even more harmless. They might be worth using in vaults,
# but for now they're disabled.

NAME:   cloud_trap_petrify
DEPTH:  D:8-17, Lair:5-8, Elf, Snake:3-5, Swamp:3-5
WEIGHT: 0
TAGS:   allow_dup extra no_dump
KFEAT:  ^ = gas trap
{{
  local tm = TriggerableFunction:new{func="callback.cloud_trap_stepped",
              repeated=true,
              data={triggered=false, cloud_type="calcifying dust",
                cloud_message="The ceiling rumbles... a layer of pale dust is dislodged!"} }
  tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
  lua_marker('^', tm)
}}
MAP
^
ENDMAP

NAME:   cloud_trap_noxious
DEPTH:  D:2-10, Lair, Orc, Elf, Swamp, Snake
WEIGHT: 0
TAGS:   allow_dup extra no_dump
KFEAT:  ^ = gas trap
{{
  local tm = TriggerableFunction:new{func="callback.cloud_trap_stepped",
              repeated=true,
              data={triggered=false, cloud_type="noxious fumes"} }
  tm:add_triggerer(DgnTriggerer:new{type="pressure_plate"})
  lua_marker('^', tm)
}}
MAP
^
ENDMAP
