##############################################################################
# Trap: Beogh Altar
##############################################################################

# By sevenhm.
# There are many monsters (Ogres / Trolls / etc) on the lava islands. There is
# a very good item sitting on the pressure plate trap.  When you stand on the
# trap, Beogh rages that you would steal the items that were left for him by
# worshippers, and creates lava bridges so that the monsters can leave the
# island and run towards you.
# If you are a worshipper of his, or if you are a godless Orc he asks you to
# approach the altar, and does not open the bridge.

{{
function callback.beogh_warn_stepped(data, triggerable, triggerer, marker, ev)
  local x, y = marker:pos()

-- This checks to see if you worship Beogh and are in good standing or are a godless
-- orc . If you do/are then you get a positive message but if you don't, Beogh warns
-- you that you should not continue towards his altar. (Monsters stepping on this
-- trap will also activate it.
  if you.god() == "Beogh" and you.piety() > 50 then
     crawl.god_speaks("Beogh" , "Your presence is welcomed at the altar to your God.")
     dgn.grid(x, y, "floor")
  elseif you.race() == "Hill Orc" and you.god() == "No God" then
     crawl.god_speaks("Beogh" , "Beogh will allow you to approach the altar.")
     dgn.grid(x, y, "floor")
  else
     if you.race() == "Demigod" then
        crawl.god_speaks("Beogh" , "The orc god booms: STAY AWAY, HOLY BEING!")
     elseif you.race() == "Demonspawn" then
        crawl.god_speaks("Beogh", "The orc god booms: STAY AWAY, FOUL BEING!")
     else
        crawl.god_speaks("Beogh" , "The orc god booms: STAY AWAY, MORTAL!")
     end
  end
end

function callback.beogh_trap_stepped(data, triggerable, triggerer, marker, ev)
  local x, y = marker:pos()
-- This enacts the changes.  First it checks to see if the player is a Beogh
-- worshipper in good standing or a godless orc (a potential worshipper).  If
-- the player is one of these things nothing happens.  Otherwise the trap is sprung.
  if monster_step == true then
    return
  elseif (you.god() == "Beogh" and you.piety() > 50) or
         (you.race() == "Hill Orc" and you.god() == "No God") then
    dgn.grid(x, y, "floor")
  else
    crawl.god_speaks("Beogh", "Beogh's wrath is called down upon you! The monsters attack!")
    for slave in iter.slave_iterator("bridge", 1) do
      dgn.terrain_changed(slave.x, slave.y, "floor", false, false, false)
    end
    dgn.grid(x, y, "floor")
  end
end
}}

NAME:   trap_god_beogh
TAGS:   no_monster_gen
DEPTH:  Orc:2-4
ORIENT: float

# t gives you a warning not to come closer
# ^ actually triggers the trap
KFEAT:  Z = altar_beogh
KPROP:  ^t.1* = no_rtele_into
{{
local tm = TriggerableFunction:new{func="callback.beogh_trap_stepped",
                                   repeated=false}
local tm2 = TriggerableFunction:new{func="callback.beogh_warn_stepped",
                                   repeated=false}
tm:add_triggerer(DgnTriggerer:new{type="player_move"})
tm2:add_triggerer(DgnTriggerer:new{type="player_move"})
lua_marker('^', tm)
lua_marker('t', tm2)
lua_marker('M', props_marker { bridge=1 })
}}
SHUFFLE: NM
SUBST:   NML:l, 1=1112 , 3=123 , ^t:. , *=*|
# Some orcs who can shoot are necessary, otherwise a caster can snipe
# all the ogres and trolls safely.
MONS:   w:7  generate_awake troll ; robe . nothing /\
        w:5  generate_awake ogre ;  giant club | robe /\
        w:5  generate_awake orc ; war axe | robe
MONS:   w:10 generate_awake rock troll ; robe . nothing /\
        w:5  generate_awake orc warrior ; broad axe | robe /\
        w:10 generate_awake two-headed ogre ; giant spiked club | robe
MONS:   w:10 generate_awake orc priest /\
        w:4  generate_awake orc high priest /\
        w:10 generate_awake orc warrior ; javelin ego:returning race:orcish /\
        w:4  generate_awake orc warlord ; bardiche ego:reaching race:orcish
MAP
     x@xx
     x.xx
     x.xx
   xxx..xxx
  xxlll.llxx
 xxlllltlllxxx
 x...........x
xx.llll*llll.xx
x..l13l^l31l..x
x..M13N.N31M..x
x..M13N.N31M..x
xx.MllNZNllM.xx
 x...xx=xx...x
 xxxxx***xxxxx
     xxxxx
ENDMAP
