! ============================================================================ !
!   Cloak of Darkness - a simple demonstration of Interactive Fiction
!       This version for IAGE written by R.Rawson-Tetley on 15 Nov 01
!       Built from Roger Firth's Inform source
! ============================================================================ !

#import "lib.ih"

GameCode {

       Name "Cloak of Darkness"
       SinglePlayerGame yes
       StartingLocation foyer
       ShowAvailableExits no
       AllowPersist no

       Start: Override [

               currentplayer.print "<br><br><i>Hurrying through the rainswept November night, you're glad to see the bright lights of the Opera House. It's surprising that there aren't more people about but, hey, what do you expect in a cheap demo game...?</i><br><br>"

               game.displayversion
               call StandardLib.DisplayLibraryVersion
               game.displaycurrentlocation

               cloak.currentlocation = currentplayer.containerlocation
               cloak.isworn = true

               ' Reset flags that could have been used in last game
               cloak.removeuserboolean(general)
               scrawledmessage.setvalue(number) = 0
               bar.isdark = true
       ]

       Initialise: CodeExtend [

               ' Add hang as synonymous with put
               addverb 7 hang

       ]
}

LibraryMessage 133 "<b>** You have lost **</b>" ! Override normal death message
LibraryMessage 27 "(out of a possible 2) in"    ! Override max score
LibraryMessage 1 "<b>Cloak Of Darkness</b><br>An IF Demonstration. Written by R.Rawson-Tetley from Roger Firth's specification."

! ============================================================================ !

Location foyer "Foyer of the Opera House" {
               Description "You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west."
               S_to bar
               W_to cloakroom

       OnInput: [
               ;go
                       #north
                               currentplayer.print "You've only just arrived, and besides, the weather outside seems to be getting worse."
                               end
                       endif
               endif
       ]
}

Location cloakroom "Cloakroom" {
               Description "The walls of this small room were clearly once lined with hooks, though now only one remains. The exit is a door to the east."
               E_to foyer
}

Item hook "a small brass hook" {
               StartsIn cloakroom
               Size 2
               Nouns "small" "brass" "hook" "peg"
               has scenery supporter

               OnAction: [
                       ;examine
                               if ( cloak.currentlocation = this.surfacelocation ) then
                                       currentplayer.print |"There is a velvet cloak hung on the " & hook.thename|
                                       end
                               endif
                       endif
               ]
}

Location bar "Foyer bar" {
               Description "The bar, much rougher than you'd have guessed after the opulence of the foyer to the north, is completely empty. There seems to be some sort of message scrawled in the sawdust on the floor."
               N_to foyer
               has darkness

       OnInput: [

               if ( this.isdark = true ) then

                       ;go
                               #n
                                       end
                               else
                                       scrawledmessage.setvalue(number) = |scrawledmessage.getvalue(number) + 2|
                                       currentplayer.print "Blundering around in the dark isn't a good idea!"
                                       end
                               endif
                       endif

                       scrawledmessage.setvalue(number) = |scrawledmessage.getvalue(number) + 1|
                       currentplayer.print "In the dark? You could easily disturb something!"
               endif
       ]
}

Item cloak "a velvet cloak" {
               Nouns "handsome" "dark" "black" "velvet" "satin" "cloak"
               Description "A handsome cloak, of velvet trimmed with satin, and slightly spattered with raindrops. Its blackness is so deep that it almost seems to suck light from the room."
               has wearable

       OnAction: [

               end

               proc before_drop
                       if ( currentplayer.currentlocation = cloakroom.id ) then
                               bar.isdark = false
                               end
                       else
                               returnvalue = "This isn't the best place to leave a smart cloak lying around."
                               cancelevent
                               end
                       endif
               end

               proc before_insert
                       #on
                               if ( input.noun2 = hook.nounid ) and ( this.getuserboolean(general) = false ) then
                                       bar.isdark = false
                                       call StandardLib.AddScore 1
                                       this.adduserboolean(general)
                                       returnvalue = |"You hang the velvet cloak on the " & hook.thename|
                                       end
                               endif
                       endif
               end

               proc after_get
                       bar.isdark = true
                       end
               end

       ]
 }

Item scrawledmessage "a scrawled message"
               StartsIn bar
               Nouns "message" "sawdust" "floor"
               has scenery

       OnAction: [

               ;read
                       if ( this.getvalue(number) < 2 ) then
                               call StandardLib.AddScore 1
                               currentplayer.print "The message, neatly marked in the sawdust, reads..."
                               call StandardLib.Won
                               end
                       else
                               currentplayer.print "The message has been carelessly trampled, making it difficult to read. You can just distinguish the words..."
                               call StandardLib.Dead
                               end
                       endif
               endif
       ]
}