!***************************************************************************
!**
!** Test For Echo
!**
!** This short Inform "game" gives an example of using the BeforeParsing()
!** entry point to simulate a room where commands are echoed back to
!** the player, much like Zork I's Loud Room.
!**
!** Users are free to use this code anyway they like, and may modify it to
!** suit their needs.
!**
!** John Menichelli (
[email protected])
!**
!***************************************************************************
Constant Story "Test For Echo";
Constant Headline "^A sample game (with apologies to Rush)
by John Menichelli^^";
Release 1;
Include "Parser";
Include "Verblib";
!***************************************************************************
!**
!** The Loud Room has the attribute "general" when the echo effect has
!** been canceled.
!**
!***************************************************************************
Object LoudRoom "Loud Room"
with name "Loud Room",
description [;
print "This is a large room with a ceiling which cannot be
detected from the ground. A narrow passage leads east and west. ";
if (self has general)
"The room is eerie in its quietness.";
else
"The room is deafeningly loud with an undetermined
rushing sound. The sound seems to reverberate from
all of the walls, making it difficult even to think.";
],
e_to EastRoom,
w_to WestRoom,
has light;
!***************************************************************************
!**
!** The obligatory platinum bar which can't be picked up until the echo
!** effect has been canceled.
!**
!***************************************************************************
Object -> PlatBar "platinum bar"
with name "platinum" "bar",
;
Object EastRoom "East Room"
with name "East Room",
description "This is a room with an exit to the west.",
w_to LoudRoom,
has light;
Object WestRoom "West Room"
with name "West Room",
description "This is a room with an exit to the east.",
e_to LoudRoom,
has light;
[ BeforeParsing ;
if (player notin LoudRoom) rfalse;
if (player in LoudRoom && LoudRoom has general) rfalse;
! Allow certain system verbs
if (parse-->1 == 'restore' or 'restart' or 'save' or 'q//' or 'quit') rfalse;
! Test for east or west movement and allow it
if (parse-->1 == 'go' && (parse-->3 == 'e//' || parse-->3 == 'w//')) rfalse;
if (parse-->1 == 'go' && (parse-->3 == 'east' || parse-->3 == 'west')) rfalse;
if (parse-->1 == 'go' && parse->1 == 1) rfalse;
if (parse-->1 == 'e//' or 'w//') rfalse;
if (parse-->1 == 'east' or 'west') rfalse;
! "Bug" response
if (parse-->1 == 'bug') rfalse;
! Print the last word in the input stream twice
PrintRawInputWord(parse->1);
print " ";
PrintRawInputWord(parse->1);
print " ...^";
! Test for the word "echo" and cause it's effect
! Gives the Loud Room general and cancels the echo effect
if (parse-->1 == 'echo')
{
print "^The acoustics of the room change subtly.^^";
give LoudRoom general;
parse->1 = 1;
parse-->1 = 'cth';
<< Examine LoudRoom >>;
}
! Modify the parse table and continue execution. This prevents returning
! a response to the command the player types.
else
{
parse->1 = 1;
parse-->1 = 'cth';
}
];
!***************************************************************************
!**
!** Print word num from the raw input stream
!**
!***************************************************************************
[ PrintRawInputWord num i ;
! Print non-dictionary word
for (i = 0: i < WordLength(num): i++)
print (char) WordAddress(num)->i;
];
!***************************************************************************
!**
!** Initialise
!**
!***************************************************************************
[Initialise ;
location = EastRoom;
];
Include "Grammar";
[ EchoSub ;
"echo echo ...";
];
Verb 'echo'
* -> Echo;
!***************************************************************************
!**
!** Dummy action when no response is desired. "Cth" was chosen because
!** it's not a command most players would use. This is a crude hack; if
!** anyone knows a better way, please let me know.
!**
!***************************************************************************
[ CthSub ;
];
Verb 'cth'
* -> Cth;
[ BugSub ;
"That's only your opinion.";
];
Verb 'bug'
* -> Bug;