#=====================================================================
action throw
  local dd, obj.ptr
  ifeq status, 1
    call bailout
  fin
  ifflag arg2, object
  else
    quip hah!
  fin
  ifhave arg2
  else
    quip you.arent.carrying
  fin
  ifhere troll, wants.treasure
    ifkey axe
      quip el.cheapo
    fin
    ifflag arg2, valued
      set troll, bought.off
      apport arg2, ylem
      quip bought.him.off
    fin
  fin
  ifkey axe
    drop axe
    ifnear dwarf
      chance 33
        quip dwarf.dodges
      fin
      random dd, dwarf
      iterate obj.ptr, dwarf0, dwarf4
        ifnear obj.ptr
          ifeq dd, 0
            apport obj.ptr, ylem
            sub dwarf, 1
            quip killed.dwarf
          fin
          sub dd, 1
        fin
      fin
      quit    # Shouldn't really need it
    otherwise
    ifhere dragon, on.rug
      quip no.kill.dragon
    otherwise
    ifhere bear, ferocious
      quip axe.now.by.bear
    fin
  fin
  call drop
# 
#=====================================================================
#
action quit
  ifkey score
    set want.to.quit?, 1
  else
    set want.to.quit?, 0
  fin
  ifne context, q.quit
    call cgiquery, want.to.quit?, q.quit, 1
  fin
  set context, none
  ifne qreply 0
    set score.text, 1   # Quitting, not just scoring
    call finis
  fin
  quip ok
# 
#=====================================================================
#
action kill
  local obj.ptr
  default mortal
  ifeq status, 1
    quip pacifist
  fin
  ifkey mirror
     and
  ifeq stage, in.repository
    say mirror.breaks
    say dwarves.wake
    call coroner
  fin
  ifhere arg2
  else
    quip i.dont.see, arg2
  fin
  ifkey dragon
    ifeq dragon, dead.body
      quip it.is.dead
    fin
    ifeq context, 0
      call cgiquery, with.what?, q.kill.dragon, 1
    fin
    set context, 0
    ifeq qreply, 1
      set dragon, dead.body
      set rug, 1
      unflag dragon, mortal
      quip dragon.vanquished
    fin
    quip dragon.blocks.way
  fin
  ifkey bird
    ifeq stage, in.repository
      quip leave.bird
    fin
    call zap.bird, bird.is.dead
  fin
  respond clam, oyster, no.kill.bivalve
  respond bear, no.kill.bear, bear
  respond snake, cant.kill.snake
  respond troll, troll.too.tough
  respond dwarf, with.what?
# 
#=====================================================================
#
action rub
  respond lamp, you.rub.lamp
  ifeq status, 2
    and
  ifnear arg2
    quip peculiar
  fin
# 
#=====================================================================
#
action inventory
  local got.some, single, obj.ptr
  itobj obj.ptr, inhand
    ifeq got.some, 0
      say "You are currently holding the following:"
    fin
    add got.some, 1
    set single, obj.ptr
    say obj.ptr
  fin
  ifhave bear
    say bear.tags.along
  fin
  ifeq got.some, 0
    say "You're not carrying anything."
  fin
  ifeq got.some, 1
    set it, single
  fin
  quit
# 
#=====================================================================
#
action save
  local fudge
  ifeq status, 1
    set fudge, 1
    call fudge.default.save.name, save
  fin
  save file, result
  ifeq result, 0
    quip ok
  fin
  iflt result, 0
    quip "Sorry, failed to create the ['{ARG2}'/default] dump.", fudge
  fin
  quit
#
#=====================================================================
#
action load
  local fudge
  ifeq status, 1
    set fudge, 1
    call fudge.default.save.name, load
  fin
  restore file, result
  ifeq result, 0
    quip ok
  fin
  ifgt result, 0
    quip no.such.dump, fudge
  fin
  quip its.gone.wrong, result
# 
#=====================================================================
#
action delete
  local fudge
  ifeq status, 1
    set fudge, 1
    call fudge.default.save.name, delete
  fin
  delete file, result
  ifeq result, 0
    quip ok
  fin
  quip no.such.dump, fudge

# 
#=====================================================================
#
action list
  set result, 0
  exec 34, result   # Find out how many
  ifeq result, 0
    quip "You have no saved games."
  fin
  ifeq result, 1
    say "f:You have one saved game: "
  else
    say "f:You have $ saved games: ", result
  fin
  exec 34, result # List them! (NB: result is 1 on more, so listing requested)
  quit
# 
#=====================================================================
#
action blast
  ifne stage, in.repository
    quip need.dynamite
  fin
  ifnear dynamite
    set blew.it, 3
  otherwise
  ifat ne.repository
    set blew.it, 2
  else
    set blew.it, 1
    set score.text, 1
    set stage, victory!
    say blew.it
    call finis
  fin
  say blew.it
  call coroner

# 
#=====================================================================
#
action brief
  set abnum, 0
  set detail, 3
  quip brief.ok
# 
#=====================================================================
#
action wave
  ifkey rod
    ifhave rod
      ifat east.of.fissure, west.of.fissure
        ifeq fissure, 1
          set fissure, 2
          say fissure
          set fissure, 0
          quit
        else
          set fissure, 1
          quip fissure
        fin
      else
        quip nothing.happens
      fin
    else
      quip you.dont.have, 0
    fin
  fin
  call bailout
# 
#=====================================================================
#
action read
  default readable
  ifeq status, 1
    call bailout
  fin
  ifflag arg2, readable
  else
    quip nocomprende
  fin
  ifnear arg2
    and
  ifflag status, light.here
    respond magazines, mag.in.dwarvish
    respond tablet, dark.room
    respond message, it.says.chest.elsewhere
    ifkey oyster
      ifhave oyster
        ifflag hints, q.oyster
          quip same.as.before
        fin
        call offer.hint?
        quit
      fin
      quip be.serious!
    fin
  fin
  quip i.dont.see, arg2
# 
#=====================================================================
#
action break
  ifeq status, 1
    call bailout
  fin
  ifkey vase
    and 
  ifnear vase
    drop vase     # We may be carrying it
    set vase, in.bits
    quip throw.vase
  fin
  ifkey mirror
    and
  ifhere mirror
    ifeq stage, in.repository
      say mirror.breaks
      say dwarves.wake
      call coroner
    fin
    quip too.far.up
  fin
  ifnear arg2
    quip no.can.fix
  fin
  quip i.dont.see, arg2
# 
#=====================================================================
#
action fill
  ifeq status 1
    ifnear bottle
      lda arg2, bottle
    else
      call bailout
    fin
  fin
  ifkey bottle
    ifnear bottle
      ifeq bottle, empty
        ifflag here, h2o.here
          set bottle, full.of.water
          quip bottle.full.of, water
        fin
        ifflag here, oil.here
          set bottle, full.of.oil
          quip bottle.full.of, oil
        fin
        quip nothing.to.fill
      fin
      quip bottle.already.full
    fin
    ifkey vase
      and
    ifnear vase
      ifflag here, h2o.here
        or
      ifflag here, oil.here
        set vase, in.bits
        unflag vase, valued
        quip vase.shatters
      fin
      quip no.vase.filler
    fin
    quip you.dont.have, 0
  fin
  quip cant.fill.that
# 
#=====================================================================
#
action empty
  ifeq status, 1
    ifnear bottle
      lda arg2, bottle
      set status, 2
    else
      quip "There's nothing here to empty!"
    fin
  fin
  ifis arg2, bottle
  else
   quip cant.do.that, empty
   fin
  ifeq bottle, full.of.water
    fakecom bottle, water
  else
    fakecom bottle, oil
  fin
  fakecom empty, pour
  call pour
# 
#=====================================================================
#
action pour
  default inhand, liquid
  ifeq status, 1
    call bailout
  fin
  ifany water, oil
    ifhave arg2
    else
      quip you.arent.carrying
    fin
  else
    ifnear arg2
      quip no.can.do, arg1
    fin
    quip nocomprende
  fin
  set bottle, full.of.air
  ifkey oil
    ifhere door
      call oil.door
    fin
    ifhere plant
      quip you.oil.the.plant
    fin
  fin
  ifkey water
    ifhere plant
      call water.plant
    fin
    ifhere door
      call water.door
    fin  
  fin
  quip pour.liquid      
# 
#=====================================================================
#
action say
  ifeq status, 2
    quip "Ok \"{arg2}\""
  fin
# 
#=====================================================================
#
action eat
  ifeq status, 1
    or
  ifkey food
    and
  ifnear food
    apport food, ylem
    quip urrp
  fin
  ifany bird, snake, clam, oyster, dwarf, dragon, troll, bear
    and
  ifnear arg2
    quip bleah
  fin
# 
#=====================================================================
#
action nothing
  quip ok
# 
#=====================================================================
#
action drink
  ifnear bottle, full.of.water
    set bottle, full.of.air
    quip bottle.now.empty
  fin
  ifflag here, h2o.here
    quip slurp
  fin
# 
#=====================================================================
#
action fee
  call foo.stuff, 0
# 
#=====================================================================
#
action fie
  call foo.stuff, 1
# 
#=====================================================================
#
action foe
  call foo.stuff, 2
# 
#=====================================================================
#
action foo
  call foo.stuff, 3
# 
#=====================================================================
#
action fum
  call foo.stuff, -1
# 
#=====================================================================
#
action lock
  default openable
  ifeq status, 1
    quip no.locks.here
  fin
  ifnear arg2
  else
    quip i.dont.see, arg2
  fin
  ifany grate, chain
    ifeq arg2, locked
      quip already.locked
    fin
    ifhave keys
    else
      quip need.keys
    fin
    ifkey chain
      ifat bear.room
        drop chain  # In case we are carrying it!
      else
        quip no.lock.chain
      fin
    fin
    ifkey clam
      quip what?
    fin
    deposit arg2, locked
    quip now.locked, arg2
  fin
  ifkey door
    quip no.lock
  fin
# 
#=====================================================================
#
action unlock
  default openable
  ifeq status, 1
    quip no.locks.here
  fin
  ifnear arg2
    respond keys, no.unlock.keys
    ifany grate, chain
      ifeq arg2, unlocked
        quip already.unlocked
      fin
      ifhave keys
      else
        quip need.keys
      fin
      ifkey grate
        and
      ifne stage, adventuring
        ifeq panic, 0
          set panic, 1
          set clock, 15
        fin
        quip exit.closed
      fin
      ifkey chain
        ifeq bear, ferocious
          quip cant.get.past.bear
        fin
        set locked.chain, 1  # Change chain's locked description
        set bear.chained, 1  # Change bear's chained description
        set bear, unchained
      fin
      deposit arg2, unlocked
      quip now.unlocked, arg2
    fin
    ifany oyster, clam
      ifhave arg2
        ifkey clam
          quip drop.the.clam
        else
          quip drop.the.oyster
        fin
      fin
      ifhave trident
        respond oyster, oyster.opened
        apport pearl, culdesac
        apport clam, ylem
        apport oyster, shell
        quip clam.opened
      fin      
      quip no.open.bivalve, arg2
    fin
    ifkey door
      quip no.lock
    fin
  fin
# 
#=====================================================================
#
action hours
  quip "Open all hours."
# 
#=====================================================================
#
action find
  ifeq status, 2
    ifhave arg2
      quip you.have.it
    fin
    ifhere arg2
      quip it.is.here.now
    fin
    ifeq stage, in.repository
      quip here.somewhere
    fin
  fin
# 
#=====================================================================
#
action feed
  default mortal
  ifeq status, 1
    call bailout
  fin
  ifnear arg2
    ifkey dwarf
      add daggro, 1
      quip fed.up.dwarf
    fin
    respond bird, bird.not.hungry
    respond troll, no.feed.troll
    ifkey dragon
      and
    ifeq dragon, dead.body
      quip hah!
    fin
    ifkey snake
      and
    ifnear bird
      and
    ifne stage, in.repository
      call zap.bird, snake.eats.bird
    fin
    ifkey bear
      and
    ifnear food
      apport food, ylem
      set bear, placid
      quip bear.eats
    fin
    respond snake, dragon, bear, it.wont.eat
    ifkey dwarf
      and
    ifnear food
      add daggro, 1
      quip fed.up.dwarf
    fin
    quip hah!
  else
    quip i.dont.see, arg2
  fin
# 
#=====================================================================
#
action get, water
  ifflag here, h2o.here
    proceed
  fin
  quip i.dont.see, water
# 
#---------------------------------------------------------------------
#
action get, oil
  ifflag here, oil.here
    proceed
  fin
  quip i.dont.see, oil
# 
#---------------------------------------------------------------------
#
action get
  local invct, tmp, obj.ptr
  ifkey inventory
    call inventory
  fin
  ifany water, oil    # We have already checked their presence!
    ifnear bottle
    else
      quip no.way.to.carry
    fin
    lda arg2, bottle
    call fill
  fin
  ifkey all
    doall here, portable
    set tmp, 1
  fin
  ifkey treasure
    doall here, valued
    set tmp, 2
  fin
  default portable
  ifeq status, 2
    ifhave arg2
      quip you.have.it
    fin
    ifeq stage, in.repository
      and
      not
    ifnear arg2
      and
    ifflag arg2, seen
      quip be.serious!
    fin
    ifany water, oil
      apport arg2, here
      set status, 1
      call fill
    fin
    ifhere arg2
      itobj obj.ptr, inhand
        ifflag obj.ptr, freebie
        else
          add invct, 1
        fin
      fin
      ifge invct, 7
        quip arms.are.full
        flush
      fin
      ifflag arg2, portable
        ifkey cage
           and
        ifhere bird, caged
           get bird
        fin
        ifkey bird
          ifeq bird, caged
            get cage
          else
            ifhave rod
              quip bird.is.scared
            fin
            ifhave cage
              set bird, caged
            else
              quip need.cage            
            fin
          fin
        fin
        ifkey rug
          and
        ifeq rug, 0
          quip be.serious!
        fin
        ifkey chain
          ifeq chain, locked
            quip chain.locked
          fin
        fin
        ifkey bear
          ifeq bear, ferocious
            quip be.serious!
          fin
          ifeq bear, placid
            quip bear.is.chained
          fin
        fin
        ifkey axe
          and
        ifhere bear, ferocious
          quip be.serious!
        fin
        get arg2
        say ok
        ifkey oyster
          and
        ifeq stage, in.repository
          and
          not
        ifflag status, oyster.noted
          say oyster.writing
          flag status, oyster.noted
        fin
        quit
      fin  
#
# Trying to get a non-portable object.
#
      respond plant, roots.too.deep        
      quip no.can.do, arg1
    fin
    ifgt tmp,0
      sub tmp, 1
      quip no.all.here, tmp
    fin
    quip i.dont.see, arg2
  fin
  call bailout
# 
#=====================================================================
#
action drop
  local tmp
  ifeq status, 2
    ifkey all
      doall inhand
      set tmp, 1
    fin
    ifkey treasure
      doall inhand, valued
      set tmp, 2
    fin
    ifany water, oil
      call pour
    fin
    ifhave arg2
      drop arg2
      ifkey bird
        set bird, freed
        ifhere snake
          apport snake, ylem
          quip bird.v.snake
        fin
        ifat sw.repository
          say bird.v.snake
          say dwarves.wake
          call coroner
        fin
        ifhere dragon
          call zap.bird, bird.v.dragon
        fin
      otherwise
      ifkey cage
        and
      ifhave bird, caged
        drop bird
      fin
      ifkey vase
        ifhere pillow
          set vase, on.pillow
          quip vase.on.pillow
        else
          set vase, in.bits
          quip vase.breaks
        fin
      otherwise
      ifkey bear
        ifnear troll, wants.treasure
          set troll, gone.for.good
          quip bear.chases.troll
        fin
      fin
      quip ok
    fin
    quip you.dont.have, tmp
  fin
  call bailout
# 
#=====================================================================
#
action light
  ifnear lamp
    set lamp, switched.on
    ifle lamplife, 0
      quip lamp.is.dead
    fin
    say lamp.now.on
    ifflag, status, light.here
    else
      flag status, light.here
      call describe.here
    fin
    quit
  else
    quip no.light.here
  fin    
# 
#=====================================================================
#
action extinguish
  ifnear lamp
    say lamp.now.off
    set lamp, switched.off
    call is.it.dark?
    ifflag status, light.here
    else
      say it.is.now.dark
    fin
    quit
  else
    quip no.light.here
  fin    
# 
#=====================================================================
#
action score
  call get.score
  say score.text, scorex
  call quit
# 
#=====================================================================
#
action back
  ifeq there, 0
     or
  ifflag here, no.back
     or
  ifflag there, no.back
    quip cant.go.back
  fin
  move there
# 
#=====================================================================
#
action oil
  ifhave oil
  else
    ifflag here, oil.here
      apport oil, here
    else
      quip i.dont.see, oil
    fin
  fin
  ifkey door
    and
  ifnear door
    call oil.door
  fin
  ifkey plant
    and
  ifnear plant
    quip you.oil.the.plant
  fin
# 
#=====================================================================
#
action water
  ifhave water
  else
    ifflag, here, h2o.here
      apport water, here
    else
      quip i.dont.see, water
    fin
  fin
  ifkey plant
    and
  ifnear plant
    call water.plant
  fin
  ifkey door
    and
  ifnear door
    call water.door
  fin
# 
#=====================================================================
#
action wake
  quip hah!     # Repository 'wake' handeld by location code
# 
#=====================================================================
#
action look
   unflag here, been.here
   iflt detail, 3
     add detail, 1
     say no.detail
   fin
   call describe.here
   quit
# 
######################################################################
