' Cloak of Darkness - Quest 3.5 implementation
' v2.0; 05/OCT/2003
' this implementation by Alex Warren; original by Roger Firth

define game <Cloak of Darkness>
    asl-version <350>
    start <foyer>
    gametype singleplayer
    game version <2.0>
    game author <Roger Firth; Quest implementation by Alex Warren>

' The script below is executed when the game begins. It sets up a numeric
' variable "bar.darkmoves" which contains the number of moves made in the darkened
' bar.

    startscript set numeric <bar.darkmoves; 0>
end define

' The player starts the game wearing the cloak, so it is defined within the
' "inventory" room:

define room <inventory>
    define object <cloak>
        prefix <a velvet>
        alt <velvet cloak; my cloak; my velvet cloak>
        look <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.>
                property <not on_hook>
                drop {
                    if ( #quest.currentroom# = cloakroom ) then {
                        lose <cloak>
                property <bar; lit>
                msg <You drop the cloak on the floor.>
            else msg <This isn't the best place to leave a _
                smart cloak lying around.>
    end define
end define

define room <foyer>
    alias <Foyer of the Opera House>
    prefix <the>
    look <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.>
    south <bar>
    west <cloakroom>
    north msg <You've only just arrived, and besides, the weather outside _
              seems to be getting worse.>
end define

define room <cloakroom>
    prefix <the>
    look <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.>
    east <foyer>

' The cloak's property "on_flag" is used to specify if the cloak is on the hook:

    command <put #@object1# on #@object2#> {
        if ( #object1# = cloak ) and ( #object2# = hook ) then {
            if not property <cloak; on_hook> then {
                move <cloak; cloakroom>
                conceal <cloak>
                property <cloak; on_hook>
                property <bar; lit>
                msg <You place the cloak on the hook.>
            else msg <The cloak is already on the hook.>
        else msg <You can't do that.>

    define object <hook>
        alt <small brass hook; small hook; brass hook; peg>
        prefix <a small brass>
        look {
            if not property <cloak; on_hook> then msg <It's just a small brass hook.>
            else msg <It's just a small brass hook, with a cloak hanging on it.>
    end define
end define

define room <bar>
    alias <Foyer bar>

    properties <not lit>

' Add a "READ object" command so we can type READ MESSAGE. We'll just make it
' do the same thing as LOOK. We're defining this here, above the catch-all,
' otherwise Quest would use that code instead.

    command <read #@object#> exec <look at #object#>

' Here we override *all* commands that are typed in when the player is in the
' room. If the bar is in the dark, all the direction commands are allowed and
' are processed normally, but all other commands produce a message about being
' in the dark and quietly increment the move counter. If the bar is not in the
' dark, all commands are processed normally.

    command <#command_data#> {
        if not property <bar; lit> then {
            if ( #command_data# = north ) or ( #command_data# = n ) _
             or ( #command_data# = northwest ) or ( #command_data# = nw ) _
             or ( #command_data# = west ) or ( #command_data# = w ) _
             or ( #command_data# = souththwest ) or ( #command_data# = sw ) _
             or ( #command_data# = south ) or ( #command_data# = s ) _
             or ( #command_data# = southeast ) or ( #command_data# = se ) _
             or ( #command_data# = east ) or ( #command_data# = e ) _
             or ( #command_data# = northeast ) or ( #command_data# = ne ) _
            then exec <#command_data#; normal>
            else {
                inc <bar.darkmoves>
                msg <In the dark? You could easily disturb something!>
        else exec <#command_data#; normal>

' The description here overrides the default description, so Quest doesn't
' automatically list all the possible directions we can go in.

    description {
        msg <You are in the |crFoyer bar|cb.>
        if property <bar; lit> then _
            msg <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 |bmessage|xb scrawled in the sawdust on the floor.>
            else msg <It is dark in here.>

' All directions other than north execute the "blunder" procedure (below), which
' prints a message and increments the move counter.

    north <foyer>
    northeast do <blunder>
    east do <blunder>
    southeast do <blunder>
    south do <blunder>
    southwest do <blunder>
    west do <blunder>
    northwest do <blunder>

' The message object starts the game being hidden and inaccessible by the plaer.
' However, if the bar's "lit" property is set when this room is entered, the
' message is made accessible, i.e. it can then be viewed:

    script if property <bar; lit> then show <message>

    define object <message>
        prefix <a>
        suffix <scrawled on the floor>
        alt <floor; message on floor; sawdust>

' Looking at the message wins or loses the game, depending on the number of
' moves made by the player in this room when it was dark:

        look {
            if ( %bar.darkmoves% <= 1 ) then {
                msg <The message, neatly marked in the sawdust, reads...>
                msg <You have won.>
            else {
                msg <The message has been carelessly trampled, making _
                    it difficult to read. You can just distinguish the words...>
                msg <You have lost.>
    end define
end define

define procedure <blunder>
    msg <Blundering around in the dark isn't a good idea!>
    inc <bar.darkmoves; 2>
end define

define text <intro>
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...?
end define