##############################################################################
# Yredelemnul's ordeal

# Before allowed to worship Yredelemnul, he demands a sacrifice!
{{
crawl_require('dlua/vault.lua')

function callback.dk_yredelemnul_ordeal_los(data, triggerable, triggerer, marker, ev)
  if data.triggered == true then
    return
  end
  crawl.god_speaks("Yredelemnul", "You sense Yredelemnul urging you " ..
                                  "to kill the trapped human.")
  data.triggered = true
end

function callback.dk_yredelemnul_ordeal(data, triggerable, triggerer, marker, ev)
  crawl.god_speaks("Yredelemnul", "Yredelemnul welcomes your deed!")

  for replica in iter.replica_iterator("floor", 1) do
      if not dgn.is_passable(replica.x,replica.y) then
        dgn.terrain_changed(replica.x, replica.y, "floor", false)
        dgn.place_cloud(replica.x, replica.y, "foul pestilence", crawl.random2(15) + 5)
      else
        crawl.mpr("You feel a numb sensation.")
        return
      end
  end
  crawl.mpr("You hear a strange fizzling.")
end
}}

NAME:   dk_yredelemnul_ordeal
TAGS:   temple_overflow_yredelemnul temple_overflow_1 no_monster_gen
MONS:   goblin zombie / kobold zombie / human zombie / jackal zombie
MONS:   goblin draugr / kobold draugr / orc draugr / jackal draugr
# Uses a neutral human to make the player feel extra evil. Neutral also means
# good gods will get mad if you choose to obey Yred.
KMONS:  h = generate_awake human att:neutral
MARKER: h = lua:portal_desc {replica_name="victim"}
MARKER: h = lua:MonPropsMarker:new{yreplica="yreplica"}
KFEAT:  h = .
KFEAT:  _ = altar_yredelemnul
: kitem("d = " .. vault_species_skeletons(_G, "early"))
NSUBST: 1 = 1:12 / * = 1..
FTILE:  _-M = floor_tomb
SUBST:  G : G.
{{
local tlos = TriggerableFunction:new{
  func="callback.dk_yredelemnul_ordeal_los",
  repeated=true}
tlos:add_triggerer(DgnTriggerer:new{type="player_los"})

local tm = TriggerableFunction:new{
  func="callback.dk_yredelemnul_ordeal", repeated=false}
tm:add_triggerer(DgnTriggerer:new{type="monster_dies", target="yreplica"})

lua_marker('h', tlos)
lua_marker('_', tm)
lua_marker('M', props_marker { floor=1 })
}}
SUBST:  M = n
TILE:   n = dngn_transparent_stone_darkgray
TILE:   c = wall_undead
KPROP:  _- = no_tele_into
SUBST:  - = .
MAP
 xxxxxxx
 xcccccx
 xc---cx
 xc-_-cx
xxc---cxx
GdcMMMcdG
.1.....1.
...n=n...
...nhn...
.1.nnn.1.
.........
ENDMAP
