### debug.acd ########################################################
#
# This optional adv350 module can be included in the adv350.acd file
# anywhere between procs.acd and actions.acd -- placing it anywhere
# else may cause problems. The resulting executable will be marginally
# larger and will include wiz (or debug) mode commands. These can
# be listed using the standard VOCABULARY command. Use WIZARD ON
# and WIZARD OFF to activate or deactivate the wiz mode. As a safety
# precaution, the default state is OFF.
#
# WARNING: if built with the debug.acd module, the game will be able
# to load save files generated by executables built without the module,
# but not the other way around.
#
#=====================================================================
#
# Commands exclusive to the wiz mode
#
verb decrement
verb next
verb numbers
verb increment
verb previous
verb !runout
verb first
verb npcs
verb notbeen
verb fetch
verb fly
verb glow
verb found
verb vocabulary
verb show
verb wizard
verb aggro
#
#=====================================================================
#
var entname
var magick
array odloc, 6
flags variable
  nowiz
  glowing
  show.numbers
  show.npcs
#
#=====================================================================
#
text YOU.GLOW
   [Your body is surrounded by a magical glow./The glow surrounding
   your body fades out.]

#
fragment cycle YOUR.MAGNIFICENCE
   Your [Mightiness/Wizardness/Magnificence/Puissance/Splendiferousness]
#
text STATE.IS.NOW
  The state of the object '{arg2}' is now $. The description now reads:
#
text LOCATION.NUMBER

   I beg to report that this be '{ENTNAME}', location number $.

#
text NO.CAN.SET
   But, {YOUR.MAGNIFICENCE}! The state of the object '{arg2}'
   would become negative: $!
#
text VOCAB.WIZ
   Wizard (i.e. debug) commands:

  /  close cave                - triggers the next cave closure stage
  /  decrement \<entity\>        - decrement state value of object or location 
  /  dump                      - dump values and bits
  /  fetch \<object\> (obtain)   - fetch the object from wherever
  /  find \<object\>             - go where the object is
  /  first                     - forces first dwarf, if axe not seen
  /  fly \<location\> (teleport) - go to the named location
  /  glow                      - toggle magical illumination
  /  increment \<entity\>        - increment state value of object or location 
  /  next                      - go to the next higher location
  /  notbeen                   - show locations not yet visited
  /  previous                  - go to the next lower location
  /  runout                    - sets event clock to zero
  /  \[show\] \{numbers|npcs}     - toggles loc number/npcs repeated display
  /  show \<entity\>             - Displays entity's current value
  /  where                     - shows where one is (and came from)
  /  where treasure            - shows valued objects (sorted on seen flag)
  /  where water               - shows water-holes
  /  where \<object\>            - shows object's location
  /  wizard \{on|off}           - switches wizard mode on or off
#
fragment random YOUR.WISH
  [To hear is to obey/Your wish is my command/As you desire/
  It shall be so/Of course. Immediately]
#
text random TO.HEAR.IS.TO.OBEY
  {YOUR.WISH},[/ Oh/=] [{YOUR.MAGNIFICENCE}/Great Wizard/Mighty One/
  the Greatest of Wizards]!

#
text increment NO.DESTINATION
  Assuredly {YOUR.MAGNIFICENCE} can {ARG1}, but alas, a destination is
  required.
#
text WIZ.NO.CHANGE
  But, {YOUR.MAGNIFICENCE}!.. The wizard mode is *already* {ARG2}!
#
text WIZ.NOT.OBJECT
  Alas, {YOUR.MAGNIFICENCE}, {ARG2} is not actually 
  a[n/ portable] object.
#
text cycle BAD.WIZ.COM
  I am [mortified/ashamed/disturbed/perplexed] to find myself 
  not understanding.
#
text YOU.ARE.THERE
  That's where you are right now!
#
text ONLY.WIZARDS
  Only wizards can [do that./{ARG1}!]
#
text .NAMED.VALUE
  The value of # is $.
#
text .VALUE.IS
  Value $.
#
text COULD.YOU.CLARIFY?
  I humbly beg to be informed as to what it is {YOUR.MAGNIFICENCE}
  wishes to {ARG1}.
#
#=====================================================================
#
proc is.it.dark?
  ifflag magick, nowiz
    proceed
  fin
  ifflag magick, glowing
    flag status, light.here
  fin
#
#---------------------------------------------------------------------
#
proc change.state, delta
  local state
#
  ifflag magick, nowiz
    proceed
  fin
  ifeq status, 1
    quip could.you.clarify?
  fin
  ifflag arg2, object
    or
  ifflag arg2, place
    eval state, arg2
    add state, delta
    ifge state, 0
      deposit arg2, state
      say state.is.now, state
      quip arg2
    fin
    quip no.can.set, state
  fin
  quip hah!
#
#---------------------------------------------------------------------
#
proc place.chain, step
  local place.ptr
  ifflag magick, nowiz
    proceed
  fin
  ifeq step 1
    and
  ifat ylem
    move road
  otherwise
  ifeq step, -1
    and
  ifat road
    move ylem
  else
    set place.ptr, here
    add place.ptr, step
    move place.ptr
  fin
  quit
#
#---------------------------------------------------------------------
#
proc show.locs
  local dn, dt, df, dc, obj.ptr
  set entname, here
  say blank
  say "f:This be room '{entname}', dwarves present: $, ", dwarf
  say "daggro: $.", daggro
  say blank
  iflt, daggro, 2
    proceed
  fin
  lda dt, odloc
  iterate obj.ptr, dwarf0, pirate
    eval df, dt         # Workout NPC's former location
    locate dc, obj.ptr  # And the current one
    ifeq df, 0
      next
    fin
    ifis obj.ptr, pirate
      ifflag chest, seen
        next
      fin
      say "f:PIRATE "
    else
      say "f:DWARF$ ", dn
    fin
    ifgt df, 0
      and
    ifne df, dc
      set entname, df
      say "f:'{ENTNAME}' => "
    fin
    set entname, dc
    say "'{ENTNAME}'"
    deposit dt, dc
    add dt, 1
    add dn, 1
  fin
  say blank
#
#---------------------------------------------------------------------
#
proc show.where, msg, entity, end
  say msg
  set entname, entity
  say "f: '{ENTNAME}' (refno $)", entname
  ifeq end, 1
    say "."
  otherwise
  ifeq end, 2
    say blank
  fin
#
#---------------------------------------------------------------------
#
proc wiz.reports
  ifflag magick, nowiz
    proceed
  fin
  ifflag magick, show.numbers
    and
  ifflag status, moved
    call show.where "f:I beg to report that this be_", here, 1
  fin
  ifflag magick, show.npcs
    and
  ifgt daggro, 0
    call show.locs
  fin
#
#======================================================================
#
action close cave
  local stg
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  ifeq stage, in.repository
    quip nothing.happens
  fin
  say "Entering next closure stage, {YOUR.MAGNIFICENCE}..."
  ifeq stage, adventuring
    ifeq clock, 0
      set clock, 30
    else
      ifinrange here, road, cobbles
        goto y2
        flag status, moved
      fin
      set daggro, 2            # Prevent axe throwing
      set clock, 1
    fin
    quit
  fin
  ifeq stage, exits.barred
    call cave.closure
  fin
  quit
#
#---------------------------------------------------------------------
#
action find
  local place.ptr
  ifflag magick, nowiz
    proceed
  fin
  ifflag arg2, place
    call fly
  fin
  ifflag arg2, object
    ifhave arg2
      quip you.have.it
    fin
    ifat arg2
      quip you.are.there
    fin
    locate place.ptr, arg2
    ifgt place.ptr, 0
      move place.ptr
    else
      quip, "Oddly, {ARG2} is nowhere to be found!"
    fin
  else
    quip wiz.not.object, 0
  fin
#
#---------------------------------------------------------------------
#
action aggro
  iflt daggro, 2
    call meet.first.dwarf
  else
    add daggro, 1
    say "Dwarf's provoked to aggression level of $, {your.magnificence}.", daggro
  fin
  quit
#
#---------------------------------------------------------------------
#
action runout
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  set clock, 0
  say to.hear.is.to.obey
  smove here, ok
#
#---------------------------------------------------------------------
#
action glow
  ifflag magick, nowiz
    quip only.wizards, 1
  fin
  ifflag magick, glowing
    unflag magick, glowing
    say you.glow, 1
    call is.it.dark?
    ifflag status, light.here
    else
      quip it.is.now.dark
    fin
  else   
    flag magick, glowing
    say you.glow, 0
    ifflag status, light.here
    else
      flag status, light.here
      call describe.here
    fin
  fin
  quit
#
#---------------------------------------------------------------------
#
action fetch
  ifflag magick, nowiz
    call get
  fin
  ifeq status, 1
    quip could.you.clarify?
  fin
  ifeq status, 2
    ifflag arg2, object
      and
    ifflag arg2, portable
      get arg2
      flag arg2, seen
      quip "You {ARG1} the #.", arg2
    fin
  fin  
  quip wiz.not.object, 1
#
#---------------------------------------------------------------------
#
action numbers
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  ifflag magick, show.numbers
    unflag magick, show.numbers
  else
    flag magick, show.numbers
  fin
  flag status, moved
  quip to.hear.is.to.obey
#
#---------------------------------------------------------------------
#
action dump
  iftyped dump
    ifflag magick, nowiz
      quip only.wizards, 0
    fin
    dump
    quit
  fin
#
#---------------------------------------------------------------------
#
action increment
  ifflag magick, nowiz
   quip only.wizards, 0
  fin
  call change.state, 1
#
#---------------------------------------------------------------------
#
action decrement
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  call change.state, -1
#
#---------------------------------------------------------------------
#
action vocabulary
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  quip vocab.wiz
#
#---------------------------------------------------------------------
#
action fly
  ifflag magick, nowiz
    quip only.wizards, 1
  fin
  ifeq status, 1
    quip no.destination
  fin
  ifflag arg2, place
    smove arg2, "Foof..."
  else
    quip bad.wiz.com
  fin
#
#---------------------------------------------------------------------
#
action next
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  call place.chain, 1
#
#---------------------------------------------------------------------
#
action previous
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  call place.chain, -1
#
#---------------------------------------------------------------------
#
action wizard
  ifkey off
    ifflag magick, nowiz
     quip wiz.no.change
    fin
    flag magick, nowiz
    quip to.hear.is.to.obey
  fin
  ifkey on
    ifflag magick, nowiz
     unflag magick, nowiz
     quip to.hear.is.to.obey
   fin
   quip wiz.no.change
  fin
#
#---------------------------------------------------------------------
#
action where
  local tmp
  local temp.ptr, obj.ptr, place.ptr
  iftyped find    # In this game WHERE is a synonym of FIND
    proceed
  fin
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  ifeq status, 1
    ifeq there, 0
      or
    ifeq there, here
      set tmp, 1
    fin
    call show.where, "f:{YOUR.MAGNIFICENCE} is at ", here, tmp
    ifeq tmp, 0
      call show.where, "f:, having arrived here from ", there, 1
    fin
  else
    ifkey treasure
      say "I beg to report that the following items are currently of value:
        /Not yet seen:"
      itobj obj.ptr, valued
        ifflag, obj.ptr, seen
          add tmp, 1
        else
          locate temp.ptr, obj.ptr
          set entname, obj.ptr
          call show.where, "f:___{ENTNAME} at ", temp.ptr, 2
        fin
      fin
      say "Already seen:[ none/]", tmp
      itobj obj.ptr, valued
        ifflag, obj.ptr, seen
          locate temp.ptr, obj.ptr
          set entname, obj.ptr
          call show.where, "f:___{ENTNAME} at ", temp.ptr, 2
        fin
      fin
    otherwise
    ifflag arg2, object
      locate temp.ptr, arg2
      call show.where, "f:Be advised that the object '{ARG2}' is at ", temp.ptr, 1
      ifkey water
        say "Personal supply of water can be replenished at:"
        itplace place.ptr
          ifflag place.ptr, h2o.here
            call show.where, "f:___", place.ptr, 2
          fin
        fin
      fin
    else
      quip wiz.not.object, 0
    fin
  fin
  quit
#
#---------------------------------------------------------------------
#
action first
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  ifflag axe, seen
    or
  ifinrange here, road, pit
    quip "Alas, this is not the time or place, {YOUR.MAGNIFICENCE}."
  else
    set daggro,1
  fin
  quit
#
#---------------------------------------------------------------------
#
action notbeen
  local place.ptr
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  itplace place.ptr
    ifflag place.ptr, been.here
    else
      set entname, place.ptr
      say "{ENTNAME} not yet visited"
    fin
  fin
  quit
#
#---------------------------------------------------------------------
#
action npcs
  local dcur, dloc, place.ptr
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  ifflag magick, show.npcs
    unflag magick, show.npcs
  else
    flag magick, show.npcs
    lda place.ptr, odloc
    iterate dcur, dwarf0, pirate
      locate dloc, dcur
      deposit place.ptr, dloc
      add place.ptr, 1 
    fin
    iflt daggro, 2
      quip "Once NPCs start moving, I shall endeavour to report
           on every turn, until requested otherwise, {YOUR.MAGNIFICENCE}."
    fin
  fin
  quip "As you command, {YOUR.MAGNIFICENCE}."
#
#---------------------------------------------------------------------
#
action found
  local obj.ptr
  ifflag magick, nowiz
    quip only.wizards, 0
  fin
  itobj obj.ptr, seen
    set entname, obj.ptr
    say "{entname}"
  fin  
#
#---------------------------------------------------------------------
#
action show
  local tmp
  ifany numbers, npcs
    call arg2
  fin
  eval tmp, arg2
  quip "Entity {ARG2} has the value $.", tmp
#
#=====================================================================
#
init
  local tmp,   randomise your.magnificence, 0
  flag magick, nowiz
  set tmp, 52
  exec 22, tmp   # I have a big screen! :-)
#
#=====================================================================
#
repeat
  local dcur, dloc, place.ptr
  ifflag magick, glowing
    flag status, light.here
  fin
  ifflag magick, show.npcs
    lda place.ptr, odloc
    iterate dcur, dwarf0, pirate
      locate dloc, dcur
      deposit place.ptr, dloc
      add place.ptr, 1 
    fin
  fin

#
#####################################################################
