goto.h
(c) 1999 by Toni Arnold, Zürich
Date of last modification: 21.7.99
Source:
http://www.copyriot.com/tarnold/goto.html
mk_room_name.perl
goto.h
gotog.h (german translation)
This is an inform library extension which implements the verb "go
to <a location>". It uses a standard breath first search strategy
to find the shortest way between two rooms. Together with the library extension
dirs_2.h
from Gunther Schmidl it becomes possible to play inform games with the
feeling of the old Magnetic Scrolls classics (with the exception of not
providing these magic graphics, of course ;-).
No warranty is provided for nothing, especially not for damage on your
source files by applying the perl script! (See below)
Usage
After you have done the "Application" and recompiled your game you can
just use the verb "go to location" to get to that room just like
in any Magnetic Scrolls game. If your target room name is ambiguous, the
normal inform parser disambiguation question ("which do you mean...") takes
place. Only the rooms which have already been visited become available
to the "go to"-verb.
Including the Library extension
Because goto.h contains a commom property and a global variable,
it has to be included at the beginning of the main source file.
The grammar extension of "go" on the other hand has to be declared at the
end
of
your main source file, so it's best to copy it out of the library extension,
uncomment it and paste it after the grammar.
Example game
Adventure (.z5-Executable compiled with "go
to") (here Java-online with ZPlet)
Adventure source (after application
of the perl script)
Adventure room name dictionary
( " " )
Application
My goto-distribution consists of two parts: a perl script mk_room_name.perl
which is intended for converting a game source into one with goto and the
goto.h library itself.
The script
The script mk_room_name.perl is derived from informap.perland
goes through all source files and tries to find room object definitions.
It is necessary because in inform normally rooms don't have name-properties
and - of course - no special property goto_steps. The script adds
all words of the room name (which has to be given in the object header
and not as a separate short_name property to be recognized)
as individual name words. For more details see the description in the script
itself.
Call
perl mk_room_name.pl advent.go.inf c=on d=on
^ ^
^
^ ^
^ can be omitted on WinNt and Unix
^ name of the
script
^ name of the inform source file
^ flag copy -> a target file *.goto is created
^ a dictionary file is created
It copies the source files to source files with the suffix .goto,
so the original files are not overwritten. Include statements in the copyed
files are adjusted, so you just have to compile main_source.inf.goto
instead of main_source.inf.
A room looks like that after the perl script has looked at it:
Object In_Hall_Of_Mists "In Hall of Mists"
with goto_steps 0,
! ----> room <---- # this is added
name "hall" "in" "mists" "of",
# this is added
...
description
"You are at one end of a vast hall stretching,
....
Rough stone steps lead up the dome.",
s_to In_Nugget_Of_Gold_Room,
w_to On_East_Bank_Of_Fissure,
d_to In_Hall_Of_Mt_King,
n_to In_Hall_Of_Mt_King,
u_to
[; if (not_in_goto)
{ ! # manually addet in the source to omit side effects
during goto search
if (large_gold_nugget in player)
"The dome is unclimbable.";
}
return
At_Top_Of_Small_Pit;
];
! Caution !:
Never ever edit directly the target file *.inf.goto!
The next time you produce it automatically your changes will get overwritten
without notice! You can easily distinguish target files from source files
by looking at the title comments because they get omitted.
Problems
-
The perl script recignizes rooms by looking for a n_to, e_to, d_to
etc. - propery. If no such property is provided because all reactions to
the "go"-Verb happen in before-Routines, you have to add at least
one direction. This is necessary for the "dirs"-Verb to work, too.
-
If directions are provided as routines (as in the example above) you have
to take care that side effects (normally printing something out or opening
a door) never happen while goto.h searches the map for the shortest way.
But you also have to make sure that the target room is returned if not_in_goto
is false - otherwise goto.h never finds the way in that direction.
-
Because all (visited) room names get into scope by trying "go to"
in a game they have to be unique. If there are more than one room with
the same name, the script doesn't add a name property and marks instead
all the synonym rooms with:
AboveGround In_Forest_1 "Im Wald"
with goto_steps 0,
! ----> room <----
!
##### name "im" "wald" not unique #####
If you want to define a room out of several rooms with the same name,
you can do this by adding a comment
! # goto
at the end of the room object header. The result looks like that afterwards:
Object Nadel_Faul_e1 "Aussen in der Tanne" ! # goto
has light,
with goto_steps 0,
! ----> room <----
name "aussen" "der" "in" "tanne",
! >#>#> goto <#<#<
description tanne_aussen,
w_to Nadel_Faul_b1;
-
If your game assigns target rooms to given directions randomly, "go
to" will find the way randomly, too. (Or, in other words, it will
normally not find the way).
This is virulent e.g. in the "Adventure"-example: if you loose yourself
in the forest and try to use "go to inside Building" afterwards,
then it will not find the way no more.
That's it. Comments to tarnold@copyriot.com