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



That's it. Comments to tarnold@copyriot.com