home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GAMES / informosk.lha / manual.txt < prev    next >
Text File  |  1993-11-27  |  148KB  |  3,602 lines

  1.  
  2. ---------------------------------------------------------------------------
  3.                Inform: A Compiler of Infocom-Format Games
  4.  
  5.                             (third edition)
  6. ---------------------------------------------------------------------------
  7.  
  8.  
  9.             "I will build myself a copper tower
  10.              With four ways out and no way in
  11.              But mine the glory, mine the power..."
  12.  
  13.                  (Louis MacNeice, "Flight of the Heart")
  14.  
  15.  
  16.   Hello, Informer!
  17.  
  18.   This manual contains four elements.  Firstly, it documents Inform, a
  19. program to manufacture Infocom version-3 format story files, which can then
  20. be played on any of the interpreters now widely available on most machines. 
  21. Inform has now been fairly heavily re-written, and is quite dependable (at
  22. least on my machine) even on very large game files.
  23.  
  24.   Secondly, it attempts to fully specify the version-3 "Z-machine".  Some of
  25. this information is already circulating in other files, but uncollated.  The
  26. rest seems only to be available in as much as it is implicit in the
  27. interpreter sources.  There seems to be some demand for this, if only among
  28. those tinkering with the interpreters.
  29.  
  30.   Thirdly, it contains articles on how to design games in general, which is
  31. not specific to this format at all.  Admittedly I do not always follow my
  32. own dictats, but I think that game implementation bears about the same
  33. relation to design as typing does to writing poetry, and I didn't want
  34. only to talk about the typing.
  35.  
  36.   Fourthly, it documents a suite of standard game routines provided with
  37. Inform to allow designers to begin coding at once.  In effect, this means
  38. that an Inform source file need not contain any of the parser code, or the
  39. running of the "game universe" - the library consists roughly of a full
  40. implementation of Zork without any actual puzzles.  It manages rooms,
  41. objects, containers, things on top of other things, light, scoring,
  42. switching things on and off, opening, closing and locking things, entering
  43. things, travelling about in them and so forth: it implements about 80 verbs. 
  44. The parser it uses (which can be entirely invisible to the designer, or can
  45. be altered if necessary) is about as good as anything Infocom ever had. 
  46. (And its source is very heavily commented, so the algorithm may be of
  47. interest even to non-Informers.)
  48.  
  49.   To get a quick look at the language, read parts (1) to (12) and Appendix
  50. C.
  51.  
  52.  
  53. ---------------------------------------------------------------------------
  54. Prefaces to editions of this manual
  55. ---------------------------------------------------------------------------
  56.  
  57.  
  58.   Historically, Inform was not a wonderfully well-written program: it must
  59. be admitted that I treated it more as an easel than a painting.
  60.  
  61.   But it works, and it runs in only two passes.  (This may sound easy but is
  62. not, because the story file format requires all manner of tricky operations
  63. to be done: for example, the dictionary must be alphabetically sorted, and
  64. the code must know absolute addresses of its entries... and the address of
  65. the start of the dictionary depends on many other things not known during
  66. pass 1... and so on.)
  67.  
  68.   It seems also, for what it's worth, to be more efficient than Infocom's
  69. own compiler - perhaps because it compiles from a low C-like rather than
  70. high LISP-like source.
  71.  
  72.   Inform is not public domain in the proper legal sense of the term.  The
  73. copyright is retained by the author, Graham Nelson.  I am perfectly happy
  74. for Inform to be used by anybody for any recreational purpose.  It may be
  75. freely distributed provided no profit is involved, and provided the
  76. copyright message is retained.  Please do not circulate heavily modified
  77. versions, and please comment any private changes of your own at the top of
  78. the source code. Story files produced by Inform belong to whoever wrote the
  79. source for them; I think, however, it is fair to ask that game-writers put
  80. some message into their credits saying that Inform was used, and giving the
  81. version number used to compile it.
  82.  
  83.  
  84. Notes on the second release:
  85.  
  86.   Since the first release, much improvement has been made in Inform's memory
  87. management which is now quite efficient: it allocates between 50 and 75K of
  88. memory, as opposed to 800K in the first edition.  The code is in ANSI C, is
  89. contained in a single file (without needing non-standard headers) and some
  90. effort has been made to improve its portability.  Hopefully it doesn't
  91. assume an ASCII character set, or 32-bit integers, or any particular
  92. byte-orientation within integers.  PC versions now ought to be feasible.
  93.  
  94.   The code has been annotated to some extent, and contains notes which
  95. should be useful to anyone trying to port the code to a new machine.
  96.  
  97.   This documentation has changed only in the new "objectloop" construction,
  98. and in Appendix C (sample output for the given programs).  The language
  99. which Inform compiles has not changed (except that two defunct features,
  100. which had not in any case been documented, have been withdrawn).  Details of
  101. changes to the source code of Inform may be found in detailed comments at
  102. its head.
  103.                                                                         GAN
  104.                                                                   June 1993
  105.  
  106. And the third:
  107.  
  108.   The third edition of this manual contains a fair amount of new material.
  109. Most of the changes in Inform are improvements which do not affect the
  110. language (better error reporting, bug fixes, speed improvements, new
  111. compile options, much greater portability across different C compilers).
  112.  
  113.   However, various new features have been added, mainly to provide for needs
  114. which cropped up for the author:
  115.  
  116.   new command line switches;                             see (1)
  117.   new directives "statusline", "release", "include",
  118.     "default", "stub";                                   (2), (18)
  119.   string indirection via the synonyms table;             (5), (16)
  120.   multiple object names;                                 (11), (16)
  121.   new constant forms #n$word and #r$routine;             (5)
  122.   new object alteration commands "write" and "give";     (8)
  123.   new command "string";                                  (8), (16)
  124.   new command "font";                                    (8), (18)
  125.   abbreviations, properly using the synonyms table.      (17)
  126.  
  127.   Making use of abbreviations slows compilation down, but (when switched on)
  128. can make reasonable memory savings (about 8%).
  129.  
  130.   Inform also now correctly works out the checksum and length fields for the
  131. story file header, which (a) makes a "verify" command easy to implement, and
  132. (b) may make story files work on older interpreters.
  133.  
  134.   One change has been made which is incompatible with earlier editions:
  135. the names of some of the more esoteric debugging directives have been
  136. homogenised.
  137.  
  138.   The text has been revised and clarified in several other places.
  139.  
  140.                                                                         GAN
  141.                                                               November 1993
  142.  
  143.   The author's email address may be found at the bottom of this file. 
  144. Comments and bug reports (by email) are welcomed with whatever degree of
  145. enthusiasm he can muster.
  146.  
  147.  
  148. ---------------------------------------------------------------------------
  149.                              Contents
  150. ---------------------------------------------------------------------------
  151.  
  152.       Inform
  153.            1.   Command lines and errors
  154.            2.   Source file format
  155.            3.   Compiler directives
  156.            4.   Variables
  157.            5.   Constants
  158.            6.   Routines
  159.            7.   Expressions
  160.            8.   Commands
  161.            9.   Conditions
  162.            10.  Built-in functions
  163.            11.  Objects
  164.            12.  Verbs and grammar
  165.            13.  Exactly what Inform does with words
  166.            14.  Indirect function calls
  167.            15.  Text spacing
  168.            16.  Drastic alteration of objects
  169.            17.  Abbreviations
  170.            18.  The status line
  171.            
  172.       The Z-machine
  173.            A1.  The Z-machine
  174.            A2.  How text is encoded
  175.            A3.  How Z-code is encoded
  176.            A4.  Using Inform as an assembler
  177.  
  178.       Designing games
  179.            B1.  A Bill of Player's Rights
  180.            B2.  What makes a good game?
  181.            B3.  Writing a Parser
  182.  
  183.       Example Inform programs
  184.            C1.  A Hello Cruel World program
  185.            C2.  "Deja Vu": a toy game
  186.            C3.  The library routines
  187.            C4.  A shell game to build on
  188.  
  189.  
  190. ---------------------------------------------------------------------------
  191. 1. Command lines and errors
  192. ---------------------------------------------------------------------------
  193.  
  194.  
  195. If Inform is run without any parameters given, it prints out something like
  196. the following information:
  197.  
  198.   Archimedes Inform 1.0 (v794/at)
  199.   Release 3 (November 6th 1993)
  200.   (allocating memory for arrays) (temporary files) 
  201.   
  202.   This program is a compiler to version-3 Infocom format story files.
  203.   It is copyright (C) Graham Nelson, 1993.
  204.   
  205.   Its syntax is "inform [-list] <file1> [<file2>]"
  206.   
  207.   <file1> is the name of the Inform source file; Inform translates this into
  208.      "Zcode.<file1>"
  209.   (unless <file1> contains a '.' or '/', in which case it is left alone).
  210.   <file2> may optionally be given as the name of the story file to make.
  211.   If it isn't given, Inform writes to
  212.      "Zgames.<file1>"
  213.   but if it is, then Inform takes <file2> as the full filename.
  214.   
  215.   -list is an optional list of switch letters following the initial hyphen:
  216.     a   list assembly-level instructions compiled
  217.     b   give statistics after both passes
  218.     c   more concise error messages
  219.     d   contract double spaces after full stops in text
  220.     e   economy mode (slower): make use of declared abbreviations
  221.     f   frequencies mode: show how useful abbreviations are
  222.     h   print this information
  223.     i   ignore default switches set within the file
  224.     l   list all assembly lines
  225.     m   say how much memory has been allocated
  226.     o   print offset addresses
  227.     p   give percentage breakdown of story file
  228.     s   give statistics
  229.     t   trace Z-code assembly
  230.     w   disable warning messages
  231.     x   print # for every 100 lines compiled (in both passes)
  232.   
  233.   For example: "inform -dex curses ram:curses".
  234.   
  235. (Don't worry if the version numbers differ slightly on your copy.)
  236.  
  237. Samples of -s and -p output can be found in Appendix C.  For -d, see
  238. section (15).  For -e and -f, see (17).  -x is useful if running Inform on a
  239. slow machine, since it offers some signs of life.  -a, -p and -l are largely
  240. useful to assembly-language programmers and the poor unfortunate obliged to
  241. maintain Inform.
  242.  
  243. -i overrides any "SWITCHES" directive in the body of the code, so that the
  244. only switches applying are those in the command line.
  245.  
  246. -m reveals how many bytes were malloc'ed.  The program can be compiled in
  247. several different versions, with varying memory needs, and porters might
  248. need to use this.
  249.  
  250. The filenames Inform uses for input and output will obviously depend on what
  251. machine it runs on.  The Archimedes conventions are those above, but, for
  252. example, the Unix version compiles files like "dejavu.inf" with headers
  253. like "parser.h" to "dejavu.z3".
  254.  
  255. As Inform runs, it may come up with warnings, errors or fatal errors.
  256. Here is a typical sample:
  257.  
  258.   Archimedes Inform 1.0 (v794/at)
  259.   line 10: Error: Symbol name expected
  260.   >   global
  261.   line 12: Error: The "Main" routine is not allowed to have local variables
  262.   >   [ Main i
  263.   line 12: Warning: Local variable unused: "i"
  264.   line 23: Warning: Local variable unused: "j"
  265.   Compiled with 2 errors and 2 warnings (no output)
  266.  
  267. (Infocom interpreters can crash horribly when given incorrect files, so
  268. Inform never writes a file which caused an error, though it will allow
  269. files causing warnings only.)
  270.  
  271. -c (concise) mode doesn't quote from the source files; -w turns warnings
  272. off.
  273.  
  274. The exchange rate is 100 errors to the fatal error: i.e., after 100 errors,
  275. Inform gives up altogether.
  276.  
  277.  
  278. ---------------------------------------------------------------------------
  279. 2. Source file format
  280. ---------------------------------------------------------------------------
  281.  
  282.  
  283. Lines in an Inform file are terminated by semicolons.  Exclamation marks
  284. ! thus...
  285. denote that the rest of that physical line is a comment.  Backslashes "fold"
  286. strings up, so that for example
  287.  
  288. initpos "A hinged trapdoor in the floor stands open, and light streams in \
  289.          from below."
  290.          
  291. is treated as if the "f" in "from below." follows directly from where the
  292. backslash \ is; i.e., the carriage return and leading spaces are removed.
  293.  
  294. Inform command names are not case sensitive, and nor are variable names.
  295. However, reserved words after the initial command (such as the "to" in a
  296. "for" construction) must be in lower case.
  297.  
  298. There are seven kinds of line:
  299.  
  300.                                Examples
  301.  
  302.   labels                       .Label;
  303.   routines start and stop      [ NewRoutine i j;
  304.   directives                   #Release 4;
  305.   assignments                  fred = parent(lamp);
  306.   function calls               Verify();
  307.   compiled commands            for i 1 to 10 { Step(i); }
  308.   assembly language            @prop_len_addr lamp lv;
  309.  
  310. In practice, you don't need to know assembly language, but it's there.
  311.  
  312.  
  313. ---------------------------------------------------------------------------
  314. 3. Compiler directives
  315. ---------------------------------------------------------------------------
  316.  
  317.  
  318. Directives are instructions to Inform which do not themselves make code.
  319. They can be prefaced by a # character, as in C, but need not be.
  320.  
  321. ABBREVIATE <string>                  Declare abbreviation (see (17))
  322. ATTRIBUTE <name>                     Make new attribute flag
  323. CONSTANT <name> <value>              Declare a constant
  324. DICTIONARY <name> <text>             Enter <text> in dictionary, and make
  325.                                      a new constant for its address
  326. END                                  End compilation here (this is optional)
  327.  
  328. GLOBAL <name> [ = <a> ]              Make a new global variable;
  329.                                        [give it the initial value a]
  330.               [ string <a> ]           [make it point to an (a+1)-byte array,
  331.                                          which has <a> as first byte, and is
  332.                                          otherwise zeros]
  333.               [ data <a> ]             [make it point to an a-byte array,
  334.                                          which is all zeros]
  335.               [ initial <i1> ... ]     [make it point to an array, the bytes
  336.                                          of which are as given]
  337.               [ initstr "text" ]       [make it point to an array, the bytes
  338.                                          of which are the ASCII values of the
  339.                                          characters in the string]
  340.  
  341. INCLUDE <filename>                   Include a file in the source
  342.  
  343. OBJECT ...                           Make an object (see below)
  344. PROPERTY ...                         Make a new property (see below)
  345.  
  346. RELEASE <a>                          Set the release number to <a>
  347.  
  348. SERIAL <string>                      Set the serial number to <string>
  349.                                         (it must be a six-digit number, and
  350.                                          defaults to the date in the form
  351.                                          YYMMDD if Inform has access to
  352.                                          today's date, or to 930000 if it
  353.                                          hasn't)
  354.  
  355. STATUSLINE score                     Make the status line show score/turns
  356.            time                      ...show hours/minutes
  357.  
  358. SWITCHES <switches>                  Declare default switch settings
  359.                                      (eg:  SWITCHES dexs
  360.                                      causes "inform filename" to be read as
  361.                                      "inform -dexs filename")
  362.  
  363. VERB ...                             Enter a line of grammar (see below)
  364.  
  365. The following are mainly for debugging the compiler (should anyone ever
  366. get around to doing this) but might sometimes be amusing or helpful:
  367.  
  368. LISTSYMBOLS                          List the symbol table
  369. LISTDICT                             List the dictionary
  370. LISTOBJECTS                          List the object tree
  371. LISTVERBS                            List the verb table
  372.  
  373. (the names of which have changed from earlier releases),
  374.  
  375. TRACE                                Trace assembler
  376. LTRACE                               List the lines of input
  377. ETRACE                               Trace expression evaluator
  378. BTRACE                               Trace assembler on both passes
  379. NOTRACE, NOLTRACE, etc               Turn off appropriate tracing
  380.  
  381. And there are two more rather technical directives:
  382.  
  383. DEFAULT <cname> <value>              If the constant has not yet been
  384.                                      defined, define it with this value
  385. STUB <rname> <n>                     If the routine has not yet been
  386.                                      defined, define one which has n local
  387.                                      variables and always returns false
  388.  
  389.  
  390. ---------------------------------------------------------------------------
  391. 4. Variables
  392. ---------------------------------------------------------------------------
  393.  
  394.  
  395. There are two kinds of variable, global and local (plus one special one).
  396.  
  397. Variables are all two-byte integers, which are treated as signed when it
  398. makes sense to do so (eg in asking whether one is positive or not) but
  399. not when it isn't (eg when it is used as an address).
  400.  
  401. There can be up to 240 global variables; as indicated in (3), these can be
  402. initialised to point to dynamic workspace, so as to achieve the effect of
  403. strings and arrays.  They have to be declared before use.  For instance:
  404.  
  405.   Global turns = 1;
  406.   Global buffer string 120;   ! Buffer holding 120 characters
  407.   Global task_scores initial 4 5 9 1 2 3 0;
  408.  
  409. In any routine, there can be up to 15 local variables.  These are declared
  410. when the routine begins.  (There is one exception: the special Main routine
  411. may not have local variables.)
  412.  
  413. There is also a stack, but it should be tampered with only with care.  Never
  414. call a variable "sp", as this is the stack pointer variable which you might
  415. occasionally need to use.
  416.  
  417. The observant reader will have noticed that 240+15+1 = 256.  This is of
  418. course no coincidence.
  419.  
  420.  
  421. ---------------------------------------------------------------------------
  422. 5. Constants
  423. ---------------------------------------------------------------------------
  424.  
  425.  
  426. Constants may be prefixed with a # character if desired.  This can be useful
  427. if they are alphabetical and might otherwise be confused with something else.
  428.  
  429. A constant in "double quotes" assembles the given text at a suitable (even)
  430. address, and gives half this address as the integer value.  Inside this text
  431. the character ^ is replaced by a newline character, and the character ~ by
  432. a double-quote mark.  In practice you seldom need to worry where the text
  433. is stored, or how.
  434.  
  435. (New in Release 3)  Inside a string, @dd (an @ sign followed by two decimal
  436. digits) is compiled to the synonym of that number.  When the Z-machine
  437. finds this, it prints the string pointed to by that entry in the synonym
  438. table.  (This is useful in altering object short names - see section (16).)
  439.  
  440. A character in single quotes, such as 'e', means the ASCII value of that
  441. character.  (This is true even on machines not using ASCII, of course.)
  442.  
  443. A dollar $ indicates that a hexadecimal constant follows; $$ indicates that
  444. binary follows.
  445.  
  446. Any constant declared in a directive can be quoted, and so can the special
  447. constants
  448.  
  449.   adjectives_table
  450.   preactions_table
  451.   actions_table
  452.  
  453. (set up by Inform) which give the code address of these tables.
  454.  
  455. A constant beginning a$, followed by the name of a routine which is an
  456. action routine, will have as value the number of the action.
  457.  
  458. A constant beginning w$, followed by a word of text, has as value the
  459. address of the given word in the dictionary (Inform will give an error
  460. at compile time if no such word is there).
  461.  
  462. (New in Release 3)  A constant beginning n$, followed by a word of text,
  463. has as value the address of the given word in the dictionary (Inform
  464. adds it to the dictionary as a new word if it is not already there).
  465.  
  466. (New in Release 3)  A constant beginning r$, followed by a routine name,
  467. gives (half) the address of the given routine.  (This is very helpful
  468. when altering properties of objects which are routine addresses.)
  469.  
  470. Thus, for instance, the following are legal constants:
  471.  
  472.   31415
  473.   $ff
  474.   $$1001001
  475.   #adjectives_table
  476.   #a$LookSub
  477.   #w$invent
  478.   'X'
  479.   "an emerald the size of a plover's egg"
  480.   "~Hello,~ said Peter.^~Hello, Peter,~ said Jane.^"
  481.   #r$FireRodRoutine
  482.   #n$amazon
  483.  
  484. Unfortunately, at present negative constants are not allowed, and Inform
  485. will reject, say, #-50.  In practice they are only very occasionally
  486. needed, and can of course always be got by, say, 0-50.
  487.  
  488.  
  489. ---------------------------------------------------------------------------
  490. 6. Routines
  491. ---------------------------------------------------------------------------
  492.  
  493.  
  494. The syntax to begin a routine is
  495.  
  496.   [ RoutineName <l1> ... <ln>;
  497.  
  498. and to end it, is
  499.  
  500.   ];
  501.  
  502. l1 to ln are the names of local variables, which are also the call
  503. parameters.  For example, if you have a routine
  504.  
  505.   [ Look i j k;
  506.     ...some code...
  507.   ];
  508.  
  509. and it is called by
  510.  
  511.   Look(attic);
  512.  
  513. then i will initially have the value "attic" when this is executed.
  514. Any local variables not specified (in this case, j and k) are initially
  515. zero.  It should be emphasized that it is legal to call Look with 0, 1,
  516. 2 or 3 arguments.  (Three is the maximum number of arguments any routine
  517. can have.)
  518.  
  519. Every routine returns a value to the caller; if no such value is
  520. explicitly given, this value is the integer 1 ("true").  In a line like
  521.  
  522.   Banner();
  523.  
  524. the return value is thrown away.
  525.  
  526. Inside a routine, labels may be declared with a line of their own:
  527.  
  528.   .labelname;
  529.  
  530. but note that whereas local variables have names which only mean anything
  531. locally, labels have names which are global.  In other words, you can't
  532. have a label called "loop" more than once in the file.  (It is legal to
  533. jump from one routine to a label inside another one, but extremely
  534. dangerous.)
  535.  
  536. There is one special routine, which you must define, called Main.  This is
  537. where execution of the game will begin, and it _must_ be the first one
  538. defined.  Returning from Main will cause the interpreter to crash: you
  539. should explicitly use the "QUIT" instruction instead.  Also, uniquely and
  540. for peculiar reasons, Main is _not_ permitted to have any local variables
  541. of its own.  This means it is usually only used as an outer shell.
  542.  
  543. (Inform issues a warning if the earliest defined routine is not called
  544. "Main".)
  545.  
  546.  
  547. ---------------------------------------------------------------------------
  548. 7. Expressions
  549. ---------------------------------------------------------------------------
  550.  
  551.  
  552. The usual arithmetic expressions are allowed, including the operators:
  553.  
  554.     =             set variable (only) on left equal to value on right
  555.     + -           plus, minus
  556.     * / % & |     times, divide, remainder, bitwise and, bitwise or
  557.     -> -->        byte, word array entry
  558.                   (eg: buffer->4 gives contents of the byte with address
  559.                   buffer+4, while table-->3 gives the word at table+6)
  560.                   
  561. In addition one may call a function, either a built-in function or a
  562. routine.
  563.  
  564. For example:
  565.  
  566.   4*(x+3/y)
  567.   i=j-->1
  568.   Fish(x)+Fowl(y)
  569.  
  570.  
  571. [Note: in earlier releases, Inform used to be unable to cope with
  572. many complicated expressions used in the same command, such as
  573.  
  574.   put buffer+6 byte i+j+1 56*prime(4);
  575.  
  576. ...but now it can.]
  577.  
  578.  
  579. ---------------------------------------------------------------------------
  580. 8. Commands
  581. ---------------------------------------------------------------------------
  582.  
  583.  
  584. The "high level" commands in Inform are as follows:
  585.  
  586. NEW_LINE                     Print a carriage return
  587. SHOW_SCORE                   Redisplay the score bar immediately, without
  588.                              waiting for the next keyboard input
  589. PRINT "text"                 Print text
  590. PRINT_RET "text"             Print text, print a newline and return true (1)
  591. PRINT_NUM <a>                Print a as a (signed) decimal number
  592. PRINT_CHAR <a>               Print the character whose ASCII value is a
  593. PRINT_ADDR <a>               Print the string whose address is a
  594. PRINT_PADDR <a>              Print the string whose address is 2*a
  595. PRINT_OBJ <a>                Print the short name of object a
  596.  
  597. REMOVE <a>                   Remove object a from the tree of objects
  598.                              (it may certainly be later put back)
  599. MOVE <a> TO <b>              Add object a to the things possessed by b
  600.  
  601. WRITE <object> <p1> <v1> [<p2> <v2>...]   Set properties of the given
  602.                              object to the given values.  (This is intended
  603.                              to replace the more primitive PUT_PROP: it can
  604.                              accept more complicated expressions, and handle
  605.                              more than one property at a time.)
  606.  
  607. GIVE <object> <a1> [<a2>...]   Give the object the quotes attributes.  An
  608.                              attribute beginning with ~ is cleared instead.
  609.                              (This is intended to replace SET_ATTR and
  610.                              CLEAR_ATTR.)  Thus, for instance,
  611.  
  612.                        give lamp light ~open container scored;
  613.  
  614.  
  615. PUT <addr> BYTE <index> <v>  Write byte value v into index'th byte after addr
  616. PUT <addr> WORD <index> <v>  ...and similarly for words
  617.  
  618. INC <var>                    Increment variable
  619. DEC <var>                    Decrement 
  620.  
  621. RETURN                       Return (actually, return true, i.e. 1)
  622. RETURN <a>                   Return the value a
  623. RTRUE                        Return true, i.e. the value 1
  624. RFALSE                       Return false, i.e. the value 0
  625.                              (These used to, and still can, be called
  626.                              "ret#true" and "ret#false".)
  627.  
  628. INVERSION                    Prints (in the game, not at compile time)
  629.                              the version number of Inform used to
  630.                              compile the story file
  631.  
  632. IF <condition>               If the condition is true, execute the code
  633.   {  ... code ... }          (braces are _compulsory_) [else execute the
  634. [ ELSE { ... other ...} ]    other code instead]
  635.  
  636. WHILE <condition>            While loop
  637.   {  ... code ... }
  638.  
  639. FOR <var> <init> TO <final>  For loop: the final value must be a constant
  640.   {  ... code ... }          or another variable.  If the range is empty, it
  641.                              does not execute even once.
  642.  
  643. DO                           Until loop
  644.   {  ... code ... }
  645. UNTIL <condition>
  646.  
  647. OBJECTLOOP <var> FROM/IN <obj>  A form of while loop.  The var first holds
  648.                              either the obj value (if it is FROM) or its
  649.                              child (if IN), and runs through the sibling
  650.                              objects.  So, for instance,
  651.  
  652.                        objectloop x in lamp { print_obj x; new_line; }
  653.  
  654.                              is equivalent to
  655.  
  656.                        x=child(lamp); while x~=0 { print_obj x; new_line;
  657.                        x=sibling(x); }
  658.  
  659. BREAK                        Break out of current loop (not block)
  660.  
  661. JUMP <label>                 Jump to label (warning: exercise caution in
  662.                              jumping out of one routine into another)
  663.  
  664. STRING <n> <text>            Set the nth indirect string to text (see (16))
  665.  
  666. FONT on                      Turn proportional fonts on/off (see (18))
  667.      off
  668.  
  669. The remaining commands need not be used if the library is being included:
  670.  
  671. QUIT                         Quit the game (at once, with no confirmatory
  672.                              question to the user)
  673. RESTART                      Restart the game from its initial state (ditto)
  674. SAVE <label>                 Try to save the game (asking the user for a file
  675.                              to put it in): if successful, jump to the label,
  676.                              otherwise carry on
  677. RESTORE <label>              Ditto, but restore
  678. VERIFY <label>               Ditto, but verify that the game is intact
  679.  
  680. READ <a> <b>                 Reads keyboard into buffer a and decomposes it
  681.                              to the buffer b:
  682.                              on entry, a[0] = buffer size, b[0] similarly
  683.                              on exit a[1] = no chars typed,
  684.                                        2 to a[1]+1 are the chars (unterminated)
  685.                              From byte 2, b contains 4-byte chunks, one for
  686.                              each word of input:
  687.                                  address of dictionary entry if recognised,
  688.                                    0000 otherwise
  689.                                  number of letters in word
  690.                                  first char of word in a
  691.                              This command automatically redisplays the status
  692.                              (score) line.
  693.  
  694.  
  695. If a command matches none of these, or if it began with an @ character, the
  696. line is sent to the assembler instead.  Some of the assembler opcodes are
  697. fairly usable, but the essential features of the Z-machine can be got at
  698. with just the high-level commands and functions.
  699.  
  700.  
  701. ---------------------------------------------------------------------------
  702. 9. Conditions
  703. ---------------------------------------------------------------------------
  704.  
  705.  
  706. These take the form
  707.  
  708.   <a>  <relation>  <b>
  709.  
  710. where the relation is one of
  711.  
  712.   ==            a equals b
  713.   ~=            a doesn't equal b
  714.   < > >= <=     comparisons
  715.   has           object a has attribute b at the moment
  716.   hasnt         ...hasnt...
  717.   near          objects a and b have the same parent
  718.   far           ...haven't...
  719.  
  720. These may _not_ be used in expressions (as if the language were C) and
  721. there is no AND/OR construction.  There is a reason for this, but not a
  722. very good one (unless you count laziness).  However, one concession
  723. towards such a feature is provided, viz. the useful construction
  724.  
  725.   <something> == <v1> [or <v2> [or <v3>]]
  726.  
  727. which is true if the first something is any of the values given.
  728.  
  729.  
  730. ---------------------------------------------------------------------------
  731. 10. Built-in functions
  732. ---------------------------------------------------------------------------
  733.  
  734.  
  735. The built in functions are
  736.  
  737.   PARENT(obj)  SIBLING(obj)  CHILD(obj)
  738.  
  739. for reading the object tree (see (11) below), together with
  740.  
  741.   RANDOM(x)
  742.  
  743. which returns a uniformly random number between 1 and x, and
  744.  
  745.   PROP_LEN(addr)  PROP_ADDR(o,p)  PROP(o,p)
  746.  
  747. for which see (11) below.
  748.  
  749. Warning: some interpreters set up their random number generator with poor
  750. choices of seed value, which means that the first few random numbers may be
  751. rather peculiarly distributed.  After a time, it settles down.  To get
  752. around this, "Curses" (for example) takes and throws away 100 random numbers
  753. when it begins.
  754.  
  755.  
  756. ---------------------------------------------------------------------------
  757. 11. Objects
  758. ---------------------------------------------------------------------------
  759.  
  760.  
  761. The object hierarchy is a tree of up to 255 "objects", which you might use
  762. for many different game elements: rooms, compass points, scenery, things
  763. which can be picked up, and so on.
  764.  
  765. They are numbered from 1 to 255, and the number 0 by convention means
  766. "nothing".  Attempting to print_obj object 0 will produce a string full of
  767. peculiar letters and (if you are very unlucky indeed) even random ASCII
  768. values followed by an interpreter crash.
  769.  
  770. In the tree, each object has a parent, a sibling, and a child.  Thus, for
  771. instance, a portion may resemble
  772.  
  773.             Meadow
  774.                |
  775.             Mailbox -> Player
  776.                |          |
  777.              Note      Sceptre -> Cucumber -> Torch -> Magic Rod
  778.                                                 |
  779.                                               Battery
  780.  
  781. in which -> shows siblings, and | parents and children.  In this case, the
  782. Meadow has nothing as its parent.  Anything with no possessions, such as the
  783. note, has nothing as its child, and so on.
  784.  
  785. When an object is moved, its possessions move with it, of course.
  786.  
  787. In practice an object needs rather more data than just a position in a tree. 
  788. It also has a collection of variables attached to it.
  789.  
  790. Firstly, there are 32 flags, called "attributes", which can be either set or
  791. clear.  These might be such conditions as "giving light", "currently worn"
  792. or "is one of the featureless white cubes".  All 32 are free for the
  793. programmer to use (though the Library routines, if in use, consume many of
  794. them).  They must be declared before use, by directives like
  795.  
  796.   ATTRIBUTE locked;
  797.  
  798. which will allocate a new attribute and make a constant "locked" to have the
  799. value of its number.  You never then need to know about these numbers,
  800. because you can use commands like
  801.  
  802.   IF obj has locked { print_ret "But it's locked!"; }
  803.  
  804.   GIVE obj locked;
  805.  
  806. Warning: 32 sounds like plenty, but the limit can quite easily be hit.  The
  807. author has found it useful to declare one as "general", to be used for
  808. different things for different objects.  (And this is done for you in the
  809. library.)
  810.  
  811. Secondly, there are 30 "properties".  These are far more elaborate.  For one
  812. thing, not every object has every property.  The following all declare new
  813. properties:
  814.  
  815.   PROPERTY door_to;
  816.   PROPERTY article "a";
  817.   PROPERTY blorpleroutine $ffff;
  818.  
  819. The value given, in the case of article and blorpleroutine, is the default
  820. value: that is, the value of the property which an object will have if it
  821. doesn't explicitly have some other value.  If you don't define a default
  822. value, it will by default be 0.
  823.  
  824. So, for instance,
  825.  
  826.   PROP(frog,timeleft);
  827.  
  828. will return 0 if "frog" has no timeleft entry.
  829.  
  830. The data for a given property can be a number, or up to four numbers in a
  831. row, or up to eight bytes of data.  The simplest way to get at the current
  832. value is something like
  833.  
  834.   i=PROP(location,door_to);
  835.  
  836. which will get the first number in the property door_to of object location.
  837. Similarly, it can be written to with
  838.  
  839.   WRITE location door_to hall_of_mists;
  840.  
  841. A subtle point is that numbers smaller than 256 are stored differently from
  842. larger ones.  In order to decide whether the property is one byte's worth or
  843. two, the Z-machine looks at the number of bytes which the property has in
  844. all, and sees whether it is odd or even; if even, it presumes the number is
  845. a 2-byte word; if odd, it presumes it is just one byte.
  846.  
  847. This is seldom something you need to know about, but occasionally you will
  848. want a property which will, later in the game, need to hold a value of, say,
  849. 1000, but which initially will be zero.  This is particularly the case with
  850. timing mechanisms, for instance.  The command
  851.  
  852.   PROPERTY LONG timeleft;
  853.  
  854. declares the property "timeleft" and requires Inform to make sure that all
  855. "timeleft" fields are 2 bytes wide, even if they have small initial values.
  856.  
  857. More elaborate manipulation has to be done by hand.
  858.  
  859.   k=PROP_ADDR(o,weird);
  860.  
  861. sets k to the address of the "weird" data of object o.  To find out how many
  862. bytes there are, apply PROP_LEN to this address.
  863.  
  864.   l=PROP_LEN(k);
  865.     
  866. Once you have the address you can read and write to it directly.  Be careful
  867. not to overrun the length, which may not be changed.
  868.  
  869. Warning: the Z-machine crashes if you attempt to write to a property field
  870. which an object hasn't got.  So although you can read an undeclared property
  871. (you just get the default values), you can't write to one.
  872.  
  873.  
  874. An object is declared (before the body of the code) by something like:
  875.  
  876. OBJECT trapdoor "hinged trapdoor" attic
  877.   with name "hinged" "trap" "door" "trapdoor",
  878.        initpos "A hinged trapdoor in the floor stands open, and light \
  879.                 streams in from below.",
  880.        closedpos "There is a closed trapdoor in the middle of the floor.",
  881.        portalto house,
  882.        postroutine TrapdoorPost,
  883.        dirprop d_to
  884.   has  portal static open light openable;
  885.  
  886. trapdoor is a constant which is set to its object number; "hinged trapdoor"
  887. is its attached short name; attic is the object which initially possesses
  888. it.  If it was to be initially unowned, this would be "nothing" instead of
  889. "attic".
  890.  
  891. After "with" is a list of property definitions, in the form
  892.  
  893.    <property> <data1> ...
  894.    [[, <property> <data1> ...]]
  895.  
  896. Warning: an excellent source of mysterious errors is missing off the commas
  897. between these, since property names are themselves legal constants.
  898.  
  899. There is one special property, called "name".  Its data must be (up to four
  900. at most) words, as above, and these are entered into the dictionary as nouns
  901. (if they aren't already present): the data actually stored is the dictionary
  902. addresses.
  903.  
  904. Note that the dictionary itself does _not_ know that "door" refers to this
  905. object: there might be any number of objects which could be called "door".
  906.  
  907. After "has" is a list of attributes which the object initially has.
  908.  
  909.  
  910. (New feature in Release 3)  You may give an object more than one internal
  911. name, thus:
  912.  
  913. OBJECT frog tree brick "frog" attic
  914.   with ...;
  915.  
  916. after which the same object can be called frog, tree or brick within the
  917. source code: in other words, several constants are created with the same
  918. value.  Why on earth should you want this?  - See section (16).
  919.  
  920.  
  921. ---------------------------------------------------------------------------
  922. 12. Verbs and grammar
  923. ---------------------------------------------------------------------------
  924.  
  925.  
  926. Whereas objects should be declared at the start of the file, the grammar
  927. to be allowed by the game should be declared at the end.  This is done with
  928. the VERB command.  VERB does something very complicated, but probably not
  929. what you think.  A typical VERB command would be:
  930.  
  931. VERB "take" "get" "pick" "lift"  * "out"                    -> ExitSub
  932.                                  * multi                    -> TakeSub
  933.                                  * multiinside "from" noun  -> RemoveSub
  934.                                  * "in" noun                -> EnterSub
  935.                                  * "off" held               -> DisrobeSub;
  936.  
  937. This declares a verb, for which "take", "get" etc are synonyms, and which
  938. can take five different courses.  In the first, it must be followed by the
  939. word "out".  In the last, it must be followed by "off" and then an item
  940. which is currently held by the player.  In the second, it can be followed by
  941. one object, or a list, perhaps specified as "everything", for instance.
  942. There can be no grammar at all, for example
  943.  
  944. VERB "invent" "i"                *                          -> InvSub;
  945.  
  946. After the "->" is the name of a routine which is to be called when this is
  947. matched.
  948.  
  949. For traditional reasons unclear to the author, previous Infocom hackers have
  950. called words such as "out" and "off", adjectives.  This is monstrously
  951. illiterate since they are of course prepositions.  We shall wearily follow
  952. convention anyway.
  953.  
  954. Remember that the Z-machine does _not_ contain the bulk of a game parser,
  955. only the computationally expensive and low-level part which works out what
  956. the words are.  So this command only sets up a table with some numbers in. 
  957. If you want a parser, you have to write code to deal with the table again.
  958. If you're using the library routines, the parser is all done for you and
  959. the possible tokens are:
  960.  
  961.    Word                What the library parser uses it for
  962.    ====                ===================================
  963.    noun                any visible object
  964.    held                object held
  965.    multi               one or more visible objects
  966.    multiheld           one or more held objects
  967.    multiexcept         one or more objects, except the other object 
  968.    multiinside         one or more objects, inside the other object
  969.    creature            an animate creature
  970.    special             any single word or number
  971.  
  972. Look through the library's grammar table for examples.
  973.  
  974. (New in Release 3)  If a verb is declared as a meta-verb, e.g. via
  975.  
  976.    VERB meta "score"
  977.                 *                                -> ScoreSub;
  978.  
  979. then the parser will treat it as outside the game - taking no time up, and
  980. possible at any moment.
  981.  
  982.  
  983. ---------------------------------------------------------------------------
  984. 13. Exactly what Inform does with words
  985. ---------------------------------------------------------------------------
  986.  
  987.  
  988. This is a very technical section about exactly how Inform deals with the
  989. grammar table and the dictionary.  It can safely be ignored by anyone
  990. using the library routines supplied, and in fact since the remaining
  991. sections of the manual proper are quite specialised, the next part to
  992. read is probably Appendix C.
  993.  
  994.  
  995.  
  996. By convention, adjectives are numbered downwards from $ff.  Thus, if
  997. the above were the opening lines of grammar, "from" would be $fe, and so on. 
  998. As they are created, they are entered into the dictionary, and also into the
  999. adjective table, which has four-byte entries
  1000.  
  1001.   <dictionary address of word>  00  <adjective number>
  1002.   ----2 bytes-----------------  ----2 bytes----------- 
  1003.  
  1004. In order to make life more interesting, these entries are stored in reverse
  1005. order (i.e., lowest adjective number first).  The address of this table is
  1006. rather difficult to deduce from the file header information, so the constant
  1007. #adjectives_table is set up by Inform to refer to it.  In any event, the
  1008. table isn't very useful and is created only for the sake of conforming to
  1009. Infocom internal conventions.
  1010.  
  1011. The important tables are the grammar and action tables.
  1012.  
  1013. The grammar table address is stored in word 7 (ie bytes 14 and 15) of the
  1014. header.  The table consists of a list of two-byte addresses to the entries
  1015. for each word.  This list is immediately followed by these entries, one
  1016. after another.
  1017.  
  1018. An entry consists of one byte giving the number of lines (eg, 5 for the
  1019. "take" definition above) and then that many 8-byte lines.  These lines
  1020. have the form
  1021.  
  1022.   <objects>  <sequence of words>  <action number>
  1023.   --1 byte-  ----6 bytes--------  --1 byte-------
  1024.  
  1025. <objects> is the number of objects which need to be supplied: eg, 0 for
  1026. "inventory", 1 for "take frog", 2 for "tie rope to dog".  The sequence
  1027. of words gives up to 6 blocks of syntax to follow the verb, which must
  1028. be matched in order.  Large numbers such as $ff mean that the appropriate
  1029. adjective must appear; small numbers are inserted by special words such as 
  1030. "held" or "noun" in the VERB command:
  1031.  
  1032.    Word         Byte
  1033.    ====         ====
  1034.    noun          0  
  1035.    held          1  
  1036.    multi         2  
  1037.    multiheld     3  
  1038.    multiexcept   4  
  1039.    multiinside   5  
  1040.    creature      6  
  1041.    special       7  
  1042.  
  1043. The sequence is padded out to 6 bytes with zeros.
  1044.  
  1045. The action numbers begin at 0.  The first routine mentioned as an action (in
  1046. the above example, ExitSub) is assigned action number 0; the next (TakeSub)
  1047. is given 1, and so on.  The appropriate number is stored in the last byte of
  1048. the line.
  1049.  
  1050. Thus, a little later on in the grammar, the line
  1051.  
  1052. VERB "exit" "leave"              *                          -> ExitSub;
  1053.  
  1054. might well appear, and ExitSub will mean "action 0" as before.
  1055.  
  1056. So this table does not store the address of the action routine, as one might
  1057. expect.  Instead the addresses corresponding to the action numbers are
  1058. stored in the actions table.  Once again, Inform puts this table in its
  1059. conventional place, but this address being difficult to work out, the
  1060. constant #actions_table is set up to hold it.  The actions table is simply
  1061. a list of 2-byte entries giving the routine addresses (divided by 2).
  1062.  
  1063. There is also a preactions table, with another constant #preactions_table,
  1064. created only to conform to Infocom conventions; it is set up containing 0000
  1065. for each action.  ("Curses", for instance, makes no use of this.)
  1066.  
  1067. In the mean time, what has happened to the actual words, "take", "get",
  1068. "pick" and "lift"?  Note that these do not appear in the grammar table at
  1069. all.  Instead they are entered into the dictionary, along with the verb
  1070. number.  As a final baroque twist, these numbers also count down from $ff.
  1071. Any number of words can be given, all referring to the same verb number;
  1072. "Curses" has 11 synonyms for "attack", for instance.
  1073.  
  1074. Of course, Inform does not know or care what is done with any of these
  1075. tables.   For instance, the "take" verb has the entry
  1076.  
  1077. 005
  1078. 000 255 000 000 000 000 000 000
  1079. 001 002 000 000 000 000 000 001
  1080. 002 005 254 000 000 000 000 002
  1081. 001 253 000 000 000 000 000 003
  1082. 001 252 001 000 000 000 000 004
  1083.  
  1084. but it is up to the code you write to deal with this.  (The VERBS command
  1085. will print out the full verb table in a similar format.)
  1086.  
  1087.  
  1088.  
  1089. This section describes what Inform does with the dictionary.  Again, if
  1090. you use the parser supplied, you needn't know this.
  1091.  
  1092. The fourth word of the file header (bytes 8 and 9) contain the dictionary
  1093. table's address.
  1094.  
  1095. The table begins with a 7-byte header:
  1096.  
  1097.   03 '.' ',' '"'
  1098.  
  1099. meaning there are three characters used to separate words in typed input,
  1100. full stops, commas and quotation marks.  (The Z-machine will allow any list
  1101. to be given here but Inform decides on this for you.)
  1102.  
  1103.   07  <number_of_entries>
  1104.       ----2 bytes--------
  1105.  
  1106. meaning there are that many entries in the dictionary, all 7 bytes long. 
  1107. (This could again be in principle varied, but allows for six significant
  1108. letters in words, while still enabling the text of the word to occupy a
  1109. 4-byte integer - which is convenient and fast when the compiler is
  1110. alphabetically sorting.)
  1111.  
  1112. The seven-byte entries are in alphabetical order, and look like:
  1113.  
  1114.   <the text of the word>  <flags>  <verb number>  <adjective number>
  1115.   ----4 bytes-----------  --1 b--  ----1 byte---  ----1 byte--------
  1116.  
  1117. The text is stored in the usual text format, thus allowing up to 6
  1118. characters.  The flags (chosen once again to conform loosely to Infocom
  1119. conventions, not for any sensible reason) have the eight bits
  1120.  
  1121.   7      6  5  4  3     2      1  0
  1122.   <noun> .. .. .. <adj> <spec> .. <verb>
  1123.  
  1124. <verb>, <noun> and <adj> mean the word can be a verb, noun or adjective; the
  1125. <spec> bit means the word was inserted by a DICTIONARY command in the
  1126. program, except that <verb> words also have the <spec> bit set (ours not to
  1127. wonder why).
  1128.  
  1129. (Release 3 of Inform also makes use of bit 1 above to indicate which verbs
  1130. were declared as "meta": the parser can use this to see how to treat a
  1131. verb.)
  1132.  
  1133. Note that a word can be any combination of these at once.  It can even be
  1134. simultaneously a verb, adjective and noun.
  1135.  
  1136. Typically a full game contains about 600 dictionary entries - about ten
  1137. times the number of portable objects.  Even so it only consumes about 4K, or
  1138. 1/64th of the available memory.  It's never worth economising on dictionary
  1139. entries; nothing else a designer can do with 4K will be as goodáto the user.
  1140.  
  1141.  
  1142. ---------------------------------------------------------------------------
  1143. 14. Indirect function calls
  1144. ---------------------------------------------------------------------------
  1145.  
  1146.  
  1147. Occasionally one needs to call a function whose address is in a variable:
  1148. for example, if the routine address has been looked up from a table, or an
  1149. object's property list.
  1150.  
  1151. For this, the function "indirect" is provided:
  1152.  
  1153.   a=indirect(b);
  1154.  
  1155. sets a to the return value of calling the function whose address is in b.
  1156.  
  1157. If you want to pass arguments as well, you should use the assembler-level
  1158. @icall.  But do so with care: it is dangerously easy to leave values lying
  1159. about on the stack, which will overflow causing a mysterious crash
  1160. hundreds of turns later.
  1161.  
  1162.  
  1163. ---------------------------------------------------------------------------
  1164. 15.  Text spacing
  1165. ---------------------------------------------------------------------------
  1166.  
  1167.  
  1168. Typewritten English, like this file, normally puts a double space after a
  1169. full stop.  This is much easier to read.  Unfortunately Infocom-standard
  1170. interpreters do not usually understand that.  When they fold text across
  1171. lines, they can easily turn
  1172.  
  1173.   ...and a pomegranate.  After all, you always hated fruit.
  1174.  
  1175. into something which looks like
  1176.  
  1177.    |You decline the offer of a banana, an apple and a pomegranate.   |
  1178.    | After all, you always hated fruit.                              |
  1179.    |                                                                 |
  1180.    |>                                                                |
  1181.  
  1182. which looks awful.  It would be easy to fix the interpreter not to do this;
  1183. but nobody does.  In case (like the author's) your typing is habitually
  1184. double-spaced, Inform provides a command line option -d to change it back
  1185. again.  It does this only by replacing the string ".  " by ". " in text
  1186. conversion.
  1187.  
  1188.  
  1189. ---------------------------------------------------------------------------
  1190. 16.  Drastic object alteration
  1191. ---------------------------------------------------------------------------
  1192.  
  1193.  
  1194. In earlier versions of Inform, there were some aspects of an object
  1195. difficult to change, once set.  Firstly, the "short name".  If you
  1196. declared an object as, say,
  1197.  
  1198.   OBJECT frog "little green frog" attic
  1199.     WITH ...
  1200.  
  1201. then the game would always refer to it as "little green frog": this would
  1202. be impossible to alter if, for instance, it should in some magical way
  1203. become an enormous green frog.
  1204.  
  1205. A sneaky way around this is to use string indirection.  Declare it as
  1206.  
  1207.   OBJECT frog "@00" attic
  1208.     WITH ...
  1209.  
  1210. so that, when the Z-machine does a print_obj on it, it prints out the
  1211. string entered 0th in the synonyms table.  In your initialisation code,
  1212. write your own string here, by:
  1213.  
  1214.   STRING 0 "little green frog";
  1215.  
  1216. (which actually compiles simply to:
  1217.  
  1218.   PUT $0042 WORD 0 "little green frog";
  1219.  
  1220. $0042 is the address of the synonyms table; setting word n changes the
  1221. string printed in place of @n.)
  1222.  
  1223. Then at any time you can amend the name by
  1224.  
  1225.   STRING 0 "enormous, slavering green frog";
  1226.  
  1227. @00 to @25 are available.  (Counting in decimal, not hex.)
  1228.  
  1229. (This system also provides an elegant way of dealing with bottles and
  1230. containers of water in general, say: "full beer bottle" can become
  1231. "half-empty beer bottle" and then "empty beer bottle".  (But if so,
  1232. remember also to change its indefinite article from "a" to "an".))
  1233.  
  1234. Secondly, properties which pointed to game routines were tricky to
  1235. set for very complicated reasons to do with how constants are translated.
  1236. Suffice to say that one can now do this by, e.g.
  1237.  
  1238.   WRITE frog preroutine #r$EnormousFrogPre;
  1239.  
  1240. or
  1241.  
  1242.   WRITE frog preroutine #r$LittleFrogPre;
  1243.  
  1244. Thirdly, it was difficult to change the dictionary entries recognised
  1245. as referring to an object.  Well, it still is, but here's how it's done:
  1246.  
  1247. Create your object with the name field containing dummy entries, e.g.
  1248.  
  1249.   OBJECT frog "@00" attic
  1250.     WITH name "zzzzzz" "zzzzzz" "zzzzzz",
  1251.          ...;  
  1252.  
  1253. and then initially set these by
  1254.  
  1255.   x=prop_addr(frog, name);
  1256.   put x word 0 #n$little;
  1257.   put x word 1 #n$green;
  1258.   put x word 2 #n$frog;
  1259.  
  1260. then alter them by
  1261.  
  1262.   x=prop_addr(frog, name);
  1263.   put x word 0 #n$enormo;
  1264.  
  1265. (Warning: if there are only three entries in the name property list, as
  1266. here, then the Z-machine will crash if you try to write to the fourth: so
  1267. make sure there are enough dummy entries when you create the object.)
  1268.  
  1269.  
  1270. It is thus possible to change absolutely every aspect of an object.  The
  1271. virtue of this is that, as Richard Tucker pointed out to the author, the
  1272. limit of 256 objects ceases to be a limitation if you can recycle them.
  1273. It takes careful coding, but these methods allow that recycling to take
  1274. place.
  1275.  
  1276. This is why multiple internal names are now allowed for an object:
  1277.  
  1278.   OBJECT frog brick herring "@00" attic
  1279.     WITH name "zzzzzz" "zzzzzz" "zzzzzz",
  1280.          ...;
  1281.  
  1282. will allow the same object number to be called frog, brick or herring by
  1283. different routines which deal with different incarnations of the same
  1284. object.
  1285.  
  1286.  
  1287. ---------------------------------------------------------------------------
  1288. 17.  Abbreviations
  1289. ---------------------------------------------------------------------------
  1290.  
  1291.  
  1292. When the game becomes full, about 10K out of the 128K length can be saved by
  1293. making use of text abbreviations: a method under which up to 64 commonly
  1294. occurring phrases can be abbreviated whenever they occur.
  1295.  
  1296. This makes no difference to the text as seen by the player.
  1297.  
  1298. Because checking for these causes a speed overhead, and isn't worthwhile
  1299. until the game is about 95% full, Inform does not do so except in economy
  1300. mode (compiling with the switch -e on).
  1301.  
  1302. An abbreviation must be declared explicitly, before any other text appears,
  1303. by a directive such as:
  1304.  
  1305.   ABBREVIATE "the ";
  1306.  
  1307. Only 64 may be declared (note for experts: the remaining 32 slots in the
  1308. synonyms table are allocated for variable strings, see (16)).
  1309.  
  1310. (This causes "the " to be stored internally as only 2 text chunks, rather
  1311. than 4, whenever it occurs: which is very often.)
  1312.  
  1313. Obviously, to get maximum gain one must make sensible choices.  A reasonable
  1314. start is:
  1315.  
  1316. "they "   "the "    "The "     "You "   "you "   "you're "  "and "   "but "
  1317. "is "     "There "  "can't "   "of "    "to "    "with "    "are "   "that "
  1318. "have "   "which "  "hrough "  "in "    "here "  "into "    "It "    "east"
  1319. "west"    "north"   "south"    "not "   "an "    ", "       "thing"  "door"
  1320. "she "    "he "     "above "   "below " ".~"     ",~ "      "***"    "if "
  1321. "If "     "it "     "might "   "could " "up "    "down "    "back "  "out"
  1322. "What "   "Why "
  1323.  
  1324. plus a few specific to the game.  To see how good these abbreviations are,
  1325. try compiling with the -f (frequencies) option set, which will count the
  1326. number of times each abbreviation is used, and work out how many bytes it
  1327. saved.  For instance, "the " occurs some 1200 times in "Curses".  One soon
  1328. sees that parts of speech and words like "there" make big savings, but that
  1329. almost any proper noun makes hardly any difference.
  1330.  
  1331.  
  1332. ---------------------------------------------------------------------------
  1333. 18.  The Status Line
  1334. ---------------------------------------------------------------------------
  1335.  
  1336.  
  1337. One of the most distinctive features of Infocom games in play is the status
  1338. line, the (usually highlighted) bar across the top of the screen.  The
  1339. interpreter automatically prints the current game location, and either the
  1340. time or the score and number of turns taken.
  1341.  
  1342. The status line is redisplayed at least (a) on a SHOW_SCORE command and
  1343. (b) each time the game asks the player to type something.  It may be
  1344. displayed even more often, at the whim of the interpreter.
  1345.  
  1346. The place name is the short name of the object whose number is held in
  1347. global 0 - the earliest global declared in the file.  If ever this global
  1348. holds the value 0, the name displayed will become corrupted and the game
  1349. may crash.
  1350.  
  1351. The next two globals are also used.
  1352.  
  1353. By default, these show the score and number of turns taken so far, usually
  1354. in the form "4/87".  (Interpreters vary in how they print these.)
  1355.  
  1356. However, if the file contains the directive
  1357.  
  1358.   Statusline time;
  1359.  
  1360. then they are treated as the time in hours and minutes.  For instance,
  1361. 1 and 32 would come out as "1:32 am".
  1362.  
  1363. It is up to the program to adjust these variables as time passes, score
  1364. is gathered, location changes, etc.  (Though as usual, the library will
  1365. take care of some of this work.)
  1366.  
  1367.  
  1368. Another miscellaneous point: on some machines, text will by default
  1369. be displayed in a proportional font (i.e. one in which the width of a
  1370. letter depends on what it is, so for example an i will be narrower than
  1371. an m).  If you want to display a diagram made up of letters, you will have
  1372. to turn this off, for which the "font" command is provided:
  1373.  
  1374.    font off;
  1375.    print "   +---+^   | A |^   +---+^";
  1376.    font on;
  1377.  
  1378. for example.  (Remember to turn the font back on afterwards!)
  1379.  
  1380. On a machine not using proportional fonts, these have no effect.   
  1381.  
  1382.  
  1383. ---------------------------------------------------------------------------
  1384. A1. The Z-machine
  1385. ---------------------------------------------------------------------------
  1386.  
  1387.  
  1388. The so-called Z-machine (the imaginary machine for which story files are
  1389. programs) is quite well-adapted to its task.  It maintains a hierarchy of
  1390. objects and possessions, and does the computationally-intensive part of
  1391. parsing input itself.  That said, it does not contain the bulk of the
  1392. parser.  The parsing tables which some investigators think are part of the
  1393. Z-machine format, are in fact the same across different Infocom games only
  1394. because they all contain essentially the same parser code.  Thus, Inform is
  1395. in principle free not to compile such tables, but it does so in order to
  1396. placate other people's programs (such as INFODUMP).  Some tables are put to
  1397. subtly different uses, however.
  1398.  
  1399. The following description is fairly complete, but only covers version 3.
  1400. It would be helpful if someone public-spirited would write an account of the
  1401. differences in later versions.
  1402.  
  1403. The version 3 Z-machine is 128K long at most.  Addresses within it are
  1404. nonetheless held in 2-byte words, which is why some addresses are stored as
  1405. half their actual values, and why some items (routines and static strings)
  1406. are always stored at even addresses.
  1407.  
  1408.  
  1409. The first 64 bytes contain a header.  The first 4 bytes are:
  1410.  
  1411. 03  <Flags>  <Release Number>
  1412.              ----2 bytes-----
  1413.  
  1414. 3 indicates version 3; the release number is as set in the program; the
  1415. flags byte contains bits:
  1416.  
  1417.   1   Status line type (clear for Score/Turns, set for Hours:Mins)
  1418.   3   Censorship bit (used by some games, but not by the Z-machine)
  1419.   4   Alternative prompts - sometimes used by primitive interpreters
  1420.   5   Status window support - used only by "Seastalker"
  1421.  
  1422. Next come seven word addresses, at words 2 to 8:
  1423.  
  1424. 2     <Start of Routines>    Where routines begin, in bytes
  1425. 3     <Main Routine>         Address of main routine, in bytes, +1
  1426.  
  1427. (This +1 is why Main cannot have local variables - it is a peculiarity
  1428. of the standard.  Note also that this is uniquely a routine address in
  1429. bytes and not words: Main must occur in the lower 64K of the file.  Inform
  1430. always sets word 3 to be word 2, plus 1.)
  1431.  
  1432. 4     <Dictionary>           The dictionary table address, in bytes
  1433. 5     <Object tree>          Object table address, in bytes
  1434. 6     <Variables>            Global variables address, in bytes
  1435. 7     <Save area size>       The total number of bytes in a saved game
  1436.  
  1437. (Saving the game is done by saving this many bytes from the beginning of
  1438. the machine.  (Saved games also contain the current state of the Z-machine
  1439. stack; the stack is _not_ stored anywhere in the Z-machine's memory.))
  1440.  
  1441. 8     <More flags>
  1442.  
  1443. This word of flags has bits:
  1444.  
  1445.   0   Scripting on: send output to printer
  1446.   1   Disable proportional fonts while this is set
  1447.   4   Something mysterious to do with sound effects in The Lurking Horror
  1448.  
  1449. This is followed by the six bytes from byte 18 to 23, which are the version
  1450. number string.  (Inform sets these to the current date, in the form YYMMDD.)
  1451. Then more words:
  1452.  
  1453. 12    <Synonyms table>       Synonym table address in bytes
  1454. 13    <Length>               Length of file, in words
  1455. 14    <Checksum>             Sum of bytes from 64 upwards, mod $10000
  1456.  
  1457. (The length and checksum are not actually used at all by many interpreters,
  1458. but are set by Inform anyway.  Inform also pads out the file to an exact
  1459. number of 512-byte blocks with zeros, since some interpreters still make
  1460. use of swapping blocks in and out, virtual-memory style.)
  1461.  
  1462. The remaining bytes in the header are used by the interpreter and should be
  1463. left alone by the game code.
  1464.  
  1465.  
  1466. We are now at $0040 and by convention we reach the synonyms.  Usually, the
  1467. actual strings (the expansions of the synonyms) are stored here, one after
  1468. another, making up 96 strings.  When that is out of the way, the actual
  1469. table begins (and this is what the synonyms address points to).  The table
  1470. contains 96 two-byte entries, giving the word addresses of the strings
  1471. before it.
  1472.  
  1473. (Since Inform only uses synonyms in an unorthodox way, it actually puts
  1474. a single dull string "   " (three spaces) at $0040, and then makes a table
  1475. of 96 pointers to it, starting at $0042: finally it fills in those
  1476. abbreviations declared explicitly by the user, into the latter 64 slots,
  1477. reserving the first 32 for variable usage.  Note that Inform does not
  1478. write the synonym expansions declared by the user at $0040: but then there
  1479. is no requirement to.)
  1480.  
  1481.  
  1482. Next is the object table.  In fact it begins with what is sometimes called
  1483. the "global properties table", though it is actually a table of default
  1484. values of properties.  This is a list of 31 2-byte words.  There is no
  1485. property 0, so the first word is always 0000.
  1486.  
  1487. (Inform also sets the default for property 1 - the special "name" property -
  1488. to 0000; the remainder are set in property definitions.)
  1489.  
  1490. After these 62 bytes, the objects begin, beginning from object 1.  An object
  1491. entry consists of 9 bytes, looking like:
  1492.  
  1493.    <the 32 attribute flags>   <parent>  <sibling>  <child>  <properties>
  1494.    ---32 bits in 4 bytes---   ---3 bytes------------------  ---2 bytes--
  1495.  
  1496. The last three bytes are 00 when the object pointed to is "nothing".  The
  1497. <properties> is an address (in bytes) of the properties attached to the
  1498. given object.
  1499.  
  1500. When all these 9-byte entries are out of the way, the properties tables
  1501. begin.  (Inform keeps these in the same order as the objects they are
  1502. attached to.)  An individual property table has the brief header
  1503.  
  1504.   03  <text of short name of object>
  1505.       --some even number of bytes---
  1506.  
  1507. and then lists the properties held, in descending numerical order.  (This
  1508. order is essential.)  A property is stored as
  1509.  
  1510.   <size byte>   <the actual property data>
  1511.                 ---between 1 and 8 bytes--
  1512.  
  1513. The size byte is arranged as 32*the number of data bytes, plus the property
  1514. number.
  1515.  
  1516. Each list of properties is ended by a 00 size byte.  This is why there is no
  1517. property 0.
  1518.  
  1519.  
  1520. When all the property tables are done, we come to the global variable table.
  1521. Global variables are numbered from 0 to 239, and this table begins with 240
  1522. initial 2-byte values for them.  After this is conventially left space for
  1523. all the arrays, dynamic strings and so on which they point to.
  1524.  
  1525.  
  1526. We have now reached the top of the save area.  Everything above here is
  1527. never altered.
  1528.  
  1529.  
  1530. Next is the table of grammar, which is described as above.  It is
  1531. immediately followed by the actions table, the preactions table and then the
  1532. adjectives table, also described above.
  1533.  
  1534.  
  1535. And next the dictionary table, described above.
  1536.  
  1537.  
  1538. Next is the code area.  Not all Infocom games begin with Main, but all
  1539. Informed ones do.  The code area simply contains a list of routines.
  1540.  
  1541. All routines (and static strings) must occur at even addresses, so as to
  1542. enable them to have word addresses instead.  (Inform occasionally inserts
  1543. 00 bytes between routines to ensure this.)
  1544.  
  1545. A routine begins with one byte indicating the number of local variables the
  1546. routine has (from 0 to 15), and then with that many 2-byte words giving
  1547. their initial values, if not supplied by the call to the routine.  (Inform
  1548. never makes use of this initialisation, and simply stores 0000's here.) 
  1549. Unlike global variables, these bytes are _not_ used for the current values
  1550. of the variables: they are kept on the stack.
  1551.  
  1552. Executable code follows this header.  There is no special marker for the end
  1553. of a routine; it is simply expected that in every case a legal return
  1554. instruction will be hit.
  1555.  
  1556. Finally, from the end of the code to the top of memory are the static
  1557. strings.  These are put up here to be out of the way, where they won't clog
  1558. up the bottom 64K of memory.  There's no table of their addresses, or pointer
  1559. to where they begin; each is referred to by an address in the code or data
  1560. given earlier.
  1561.  
  1562.  
  1563. ---------------------------------------------------------------------------
  1564. A2. How text is encoded
  1565. ---------------------------------------------------------------------------
  1566.  
  1567.  
  1568. Text is stored as a sequence of 2-byte words.  Each of these is divided into
  1569. three 5-bit pieces, plus 1 bit left over, arranged as
  1570.  
  1571.    --first byte-------   --second byte---
  1572.    7    6 5 4 3 2  1 0   7 6 5  4 3 2 1 0 
  1573.    bit  --first--  --second---  --third--
  1574.  
  1575. The bit is set only on the last 2-byte word of the text, and so marks the
  1576. end.
  1577.  
  1578. The pieces are then characters, with values in the range 0 to 31.
  1579.  
  1580. There are three alphabets, in which the numbers 6 to 31 mean:
  1581.  
  1582.   A0     abcdefghijklmnopqrstuvwxyz
  1583.   A1     ABCDEFGHIJKLMNOPQRSTUVWXYZ
  1584.   A2      ^0123456789.,!?_#'~/\-:()
  1585.  
  1586. ('^' being actually the new-line character.)
  1587.  
  1588. Character 0 is a space in all alphabets.  Characters 1, 2 and 3 are used for
  1589. abbreviations: thus, 1 followed by 14 means "print entry 14 in the synonym
  1590. table"; 2 followed by 5 means "print entry 32+5=37..."; 3 followed by 20
  1591. means "print entry 64+20=84..." etc.
  1592.  
  1593. The Z-machine provides these for commonly occurring strings to be printed
  1594. out as if they were characters, thus saving memory.  Being plainly
  1595. abbreviations, these are for some reason called "synonyms".  (In practice
  1596. this can save about 10K in a 128K file.)
  1597.  
  1598. (Inform makes use of these only when instructed to (e.g. @12 is compiled to
  1599. 1, 12, meaning print the 12th entry in the synonym table), or when
  1600. abbreviations have been declared (see section (17)).)
  1601.  
  1602. By default, a character is presumed to be in A0, i.e. to be a lower-case
  1603. English letter.  However, the character 4 means that the next one (only) is
  1604. in A1; and 5 means the next is in A2.
  1605.  
  1606. Notice that character 6 in A2 is blank.  It isn't a space: it simply isn't
  1607. there.  The sequence 5 followed by 6 indicates that the next two characters
  1608. define an ASCII value.  This is the way to get at the characters not in any
  1609. of the three alphabets.  For example, the familiar message
  1610.  
  1611.   *** You are dead ***
  1612.  
  1613. takes four "characters" to produce each of the *'s.
  1614.  
  1615. Finally, note that the end-bit only comes up once every three characters,
  1616. so that a way is needed to safely use up any spare characters in the last
  1617. 2-byte block.  This is done by padding out with 5's.  (5 followed by 5 does
  1618. nothing.)
  1619.  
  1620. This is especially the case with dictionary entries.  Some dictionary
  1621. entries, like "i", ought only to take one 2-byte block, but in order to make
  1622. all entries two 2-byte blocks and alphabetically sortable by number, they
  1623. are padded out by up to five 5's in a row.
  1624.  
  1625. (Note that care must be taken to avoid dictionary entries ever containing
  1626. use of synonyms.)
  1627.  
  1628. In practice the text compression factor is not really very good: "Curses"
  1629. contains about 155000 characters of text, stored in 99000 bytes.  (Text
  1630. usually accounts for about 75% of a story file.)  But the encoding does at
  1631. least encrypt the text so that casual browsers can't read it.
  1632.  
  1633.  
  1634. ---------------------------------------------------------------------------
  1635. A3. How Z-code is encoded
  1636. ---------------------------------------------------------------------------
  1637.  
  1638.  
  1639. The encoding of version 3 Z-code is to say the least complicated.  The
  1640. reader is warned that it is also different to that in all other versions. 
  1641. There are all kinds of exceptions intended either to make small economies of
  1642. code size (these are very seldom worth the effort, in fact) or to provide
  1643. new features tacked on at the last minute.
  1644.  
  1645. Experimenting with Inform as an assembler, while tracing is turned on, may
  1646. be helpful.
  1647.  
  1648. Z-code understands four kinds of operand, and describes these in 2-bit
  1649. fields:
  1650.  
  1651.   $$00    Large constant (>=256)         2 bytes
  1652.   $$01    Small constant (0 to 255)      1 byte
  1653.   $$10    Variable                       1 byte
  1654.   $$11    Omitted altogether             0 bytes
  1655.  
  1656. Variables are described in one byte.  00 means the top of the stack, 01 to
  1657. $0f are the local variables of the current routine and $10 to $ff are the
  1658. global variables, 0 to 239.  Writing to 00 pushes something onto the stack
  1659. and reading from it pulls it off.  The stack can also be manipulated (with
  1660. care) using the PUSH, PULL and POP instructions.  The stack is guaranteed to
  1661. be at least 512 bytes long, and some interpreters are more generous.  There
  1662. isn't any way to check stack overflowing, so be careful with recursion.
  1663.  
  1664. (One of the trickiest problems in compiling Z-code is throwing away unwanted
  1665. return values of routines which are left on the stack... it can take
  1666. hundreds of turns before a game crashes if this is got wrong.)
  1667.  
  1668. Z-code opcodes are 1 byte only.  To begin with, look at the top two bits.
  1669. If these are $$11, we shall call it "variable"; if $$10, "short"; and
  1670. otherwise "long".
  1671.  
  1672. In this description, we shall adopt the opcode names used by the existing
  1673. Infocom disassembler "TXD".
  1674.  
  1675. For short opcodes, look at the next two bits (4 and 5).  These give the kind
  1676. of operand which the code has.  If this is $11, there isn't an operand and
  1677. the opcode has no argument at all.  In this event, the remaining part of the
  1678. opcode gives what it is:
  1679.  
  1680.     $00   RET#TRUE                       (1) The opcode is followed by text
  1681.     $01   RET#FALSE                          in 2-byte chunks as usual
  1682.     $02   PRINT             (1)
  1683.     $03   PRINT_RET         (1)          (2) Opcode followed by a branch
  1684.     $05   SAVE              (2)
  1685.     $06   RESTORE           (2)          (3) This is an abbreviation for
  1686.     $07   RESTARE                            RET SP, to save one byte
  1687.     $08   RET(SP)+          (3)
  1688.     $09   POP
  1689.     $0A   QUIT
  1690.     $0B   NEW_LINE
  1691.     $0C   SHOW_SCORE
  1692.     $0D   VERIFY            (2)
  1693.  
  1694. If the type wasn't $11, then an operand follows, and moreover the "code"
  1695. part of the opcode means something different:
  1696.  
  1697.     $00   JZ                (2)          (4) Followed by a store opcode
  1698.     $01   GET_SIBLING       (2) (4)          (before the branch, if there
  1699.     $02   GET_CHILD         (2) (4)          is also a branch)
  1700.     $03   GET_PARENT        (4)
  1701.     $04   GET_PROP_LEN      (4)          (5) Refers indirectly to variables
  1702.     $05   INC               (5)              by their number (Inform
  1703.     $06   DEC               (5)              suppresses this feature, so
  1704.     $07   PRINT_ADDR                         "@inc sp" produces the constant
  1705.                                              0 instead of variable no. 0 as
  1706.     $09   REMOVE_OBJ                         operand)
  1707.     $0A   PRINT_OBJ
  1708.     $0B   RET
  1709.     $0C   JUMP
  1710.     $0D   PRINT_PADDR
  1711.     $0E   LOAD              (4) (5)
  1712.     $0F   NOT               (4)
  1713.  
  1714. "Long" opcodes have two operands.  The bottom 5 bits of the opcode say what
  1715. it is:
  1716.  
  1717.     $01   JE                (2) (6)      (6) If this is encoded as
  1718.     $02   JLE               (2)              "variable", then operands 3 and
  1719.     $03   JGE               (2)              4 (if present) are used as a
  1720.     $04   DEC_CHK           (2) (5)          kind of OR command: eg,
  1721.     $05   INC_CHK           (2) (5)          branch if o1 = o2, o3 or o4
  1722.     $06   COMPARE_POBJ      (2)   
  1723.     $07   TEST              (2)   
  1724.     $08   OR                (4)   
  1725.     $09   AND               (4)   
  1726.     $0A   TEST_ATTR         (2)   
  1727.     $0B   SET_ATTR
  1728.     $0C   CLEAR_ATTR
  1729.     $0D   STORE             (5)
  1730.     $0E   INSERT_OBJ
  1731.     $0F   LOADW             (4)   
  1732.     $10   LOADB             (4)   
  1733.     $11   GET_PROP          (4)   
  1734.     $12   GET_PROP_ADDR     (4)   
  1735.     $13   GET_NEXT_PROP     (4)   
  1736.     $14   ADD               (4)   
  1737.     $15   SUB               (4)   
  1738.     $16   MUL               (4)   
  1739.     $17   DIV               (4)   
  1740.     $18   MOD               (4)
  1741.  
  1742. The alert reader will notice that bits 5 and 6 are left spare to be used. 
  1743. Now there are two operands to specify, which ought to take up 4 bits, which
  1744. obviously won't fit.  So a more economical form is used instead.  Bit 6
  1745. refers to the first operand, and bit 5 to the second.  A value of 0 means a
  1746. small constant and 1 means a variable.  Now, type $11 (not really there)
  1747. operands can't happen, so that's no problem, but there might well be type
  1748. $00 (large constant) operands, for example in "@mul x #666 sp".  In this
  1749. event, the opcode is instead programmed as a "variable" opcode.
  1750.  
  1751. So we must now describe the "variable" opcode form.  In addition to the
  1752. possible opcodes which can arise from overflowing "long" opcodes, there are
  1753. others which can only be "variable".  Here all of the bottom 6 bits are
  1754. available to describe the opcode, and this either holds the above numbers
  1755. $00 to $18 or else:
  1756.  
  1757.     $20   CALL              (4)          (7) These codes are somewhat
  1758.     $21   STOREW                             conjectural and only apply
  1759.     $22   STOREB                             to a few Infocom games; Inform
  1760.     $23   PUT_PROP                           never uses them unless told to
  1761.     $24   READ                               explicitly
  1762.     $25   PRINT_CHAR
  1763.     $26   PRINT_NUM               
  1764.     $27   RANDOM            (4)
  1765.     $28   PUSH                    
  1766.     $29   PULL              (5)
  1767.     $2A   STATUS_SIZE       (7)      
  1768.     $2B   SET_WINDOW        (7)      
  1769.  
  1770.     $33   SET_PRINT         (7)      
  1771.     $34   #RECORD_MODE      (7)      
  1772.     $35   SOUND             (7)      
  1773.  
  1774. Some of these are only of "variable" type because the available codes for
  1775. the other types had run out - PRINT_CHAR, for instance.  Others, especially
  1776. CALL, need the flexibility to have between 1 and 4 operands.
  1777.  
  1778. In the "variable" type opcode, all eight bits of the opcode have been used
  1779. up, so we have to add another byte describing the operands.  This is divided
  1780. into four 2-bit fields.  For example, $$00101111 means large constant
  1781. followed by variable (and no third or fourth opcode).
  1782.  
  1783. Once the opcode is out of the way, the operands are simply stored in one or
  1784. two-byte form as appropriate.
  1785.  
  1786. PRINT and PRINT_RET are followed by text: this is assembled in the usual way
  1787. immediately after the opcode (which may well be at an odd address, but this
  1788. doesn't matter) and execution resumes after the last 2-byte chunk of text
  1789. (the one with top bit set).
  1790.  
  1791. Opcodes marked as "store" in the above tables, return a value: for example,
  1792. MUL multiplies its two arguments together, and CALL calls a routine which
  1793. must return a value.  Such instructions are followed by a single byte giving
  1794. the variable (stack pointer, local or global as usual) to put it in.  This
  1795. may look like an extra operand but is not: there is no need to tell the
  1796. Z-machine what type it has, since it must be a variable.
  1797.  
  1798. Finally, there are instructions which test a condition.  Apart from the
  1799. obvious branch instructions (JE and so on), SAVE does this, for example, the
  1800. test in question being whether or not the save was successful.  Branches are
  1801. stored in two different ways for economy reasons: nearby ones in a single
  1802. byte at the end of the instruction, farther ones in two bytes.
  1803.  
  1804. The top bit of the first byte of a branch is the "flag".  If this is clear,
  1805. then a branch occurs when the condition came out false.  If it is set, then
  1806. the branch occurs when it was true.
  1807.  
  1808. If the next bit (bit 6) is set, then the branch is in abbreviated 1-byte
  1809. format and the offset is in the bottom 6 bits (0 to 5).  If not, the offset
  1810. is in the bottom 15 bits (0 to 6 of the first byte, and all of the second).
  1811. This offset can be positive or negative.  (Eg., all 1's means -1 in the
  1812. usual way.)
  1813.  
  1814. In the abbreviated form, an offset of 1 in fact means "return true from the
  1815. current routine" and an offset of $20 (i.e., -31) means "return false".  An
  1816. offset of 1 is never useful but -31 might arise, and so it is essential to
  1817. use the long form for such branches.
  1818.  
  1819. Working out what the offset ought to be is more complicated than it appears
  1820. because the PC has already moved on from the start of the instruction when
  1821. it reaches the branch.  The bizarre formula in question is
  1822.  
  1823.   Offset = Destination address - Address of this instruction - Length + B
  1824.  
  1825. where
  1826.  
  1827.   Length = number of bytes in instruction (not counting the branch)
  1828.  
  1829. and B is 1 for short branches, 0 for long ones.
  1830.  
  1831. In practice Inform compiles branches in the long form, considering the
  1832. economy to be not worth the nightmarish computation needed to make the
  1833. long/short decision.  (One problem is that the number of bytes in each
  1834. instruction _must_ be the same in both passes, so that the decision needs to
  1835. be made before the value of the offset is known... in a 2-pass compiler this
  1836. is insoluble.  Another is that the offsets are affected by the size of the
  1837. branch, confusing things considerably on forward branches.)  However, its
  1838. assembler mode allows you to make an explicit choice.
  1839.  
  1840. JUMP instructions similarly encode their address operand as an offset, but
  1841. always as a two-byte (signed) constant.  In this respect they differ from
  1842. CALL instructions.  In a CALL, the address is half the absolute routine
  1843. address.
  1844.  
  1845.  
  1846. ---------------------------------------------------------------------------
  1847. A4. Using Inform as an assembler
  1848. ---------------------------------------------------------------------------
  1849.  
  1850.  
  1851. Inform can also act as an assembler.  A line beginning with an @ character
  1852. is sent straight to the assembly routines.  Constants and variable names
  1853. can be given as operands but not compound expressions.  The following are
  1854. supported:
  1855.  
  1856. jump <label>                               go to (local) label
  1857.  
  1858. jz <a> [~]<label>                          If a==0 go to label
  1859.                                            (or return if "rtrue" or "rfalse")
  1860. je <a> <b> [~]<label>                      a=b
  1861. jge <a> <b> [~]<label>                     a>b    (note: not >=)
  1862. jle <a> <b> [~]<label>                     a<b
  1863. test_attr <a> <b> [~]<label>               object a has attribute b
  1864. test <a> <b> [~]<label>                    a&b != 0
  1865. compare_pobj <a> <b> [~]<label>            objects a, b have same parent
  1866.                                            In the above, if the ~ is set,
  1867.                                            the condition is negated
  1868.  
  1869. ret#true                                   return true
  1870. ret#false                                  return false
  1871. ret
  1872. retsp                                      return sp
  1873. ret <a>                                    return a
  1874.  
  1875. save [~]<label>                            save; go to label if successful
  1876. restore [~]<label>                         restore; ...
  1877. verify [~]<label>                          verify file integrity; ...
  1878. restart                                    reset Z-machine
  1879. quit                                       exit Z-machine
  1880. show_score                                 redisplay status line immediately
  1881.  
  1882. store <v> <a>                              v=a
  1883. loadw <a> <b> <v>                          v=word at (word address) a+b
  1884. loadb <a> <b> <v>                          v=byte at (byte address) a+b
  1885. storew <a> <b> <c>                         word at (word address) a+b=c
  1886. storeb <a> <b> <c>                         byte at (byte address) a+b=c
  1887. get_prop <a> <b> <v>                       v=property b of object a
  1888. get_prop_addr <a> <b> <v>                  v=address of...
  1889. get_next_prop <a> <b> <v>                  ? - seldom used
  1890. put_prop <a> <b> <c>                       property b of obj a is c
  1891. get_parent <a> <v>                         v=parent of a
  1892. get_prop_len <a> <v>                       v=property length of a
  1893. get_sibling <a> <v> [~]<label>             v=sibling of a, branch if this =0
  1894. get_child <a> <v> [~]<label>               ...child
  1895. inc_chk <v> <a> [~]<label>                 if v++=a then label
  1896. dec_chk <v> <a> [~]<label>                 if v--=a then label
  1897.  
  1898. load <v1> <v2>                             ?
  1899.  
  1900. random <a> <v>                             v=random number up to a
  1901.  
  1902. inc <v>                                    v=v+1
  1903. dec <v>                                    v=v-1
  1904.  
  1905. or <a> <b> <v>                             v=a | b
  1906. and <a> <b> <v>                            v=a & b
  1907. add <a> <b> <v>                            v=a + b
  1908. sub <a> <b> <v>                            v=a - b
  1909. div <a> <b> <v>                            v=a / b
  1910. mod <a> <b> <v>                            v=a % b
  1911.  
  1912. set_attr <a> <b>                           set attribute bit b on object a
  1913. clear_attr <a> <b>                         clear...
  1914.  
  1915. push <a1> [... <a4>]                       push a1 to a4 onto the stack
  1916. pull <a1> [... <a4>]                       pull a1 to a4 from it
  1917. pop                                        throw away top of stack
  1918.  
  1919. insert_obj <a> <b>                         give object a to b
  1920. remove_obj <a>                             remove a from hierarchy
  1921.  
  1922. call <rname> [ <a1>... ] <v>               v=rname(a1,...)
  1923.  
  1924. icall                                      indirect call: sp=(sp)()
  1925.  
  1926. read <a> <b>                               see above
  1927. print_num <v>                              print v in decimal
  1928. print "<text>"                             print text
  1929. print_ret "<text>"                         print text, newline and return 1
  1930. new_line                                   print newline
  1931. print_addr <a>                             print string at address a
  1932. print_paddr <a>                            print string at address 2*a
  1933. print_obj <a>                              print name of object a
  1934. print_char <a>                             print ASCII char <a>
  1935.  
  1936. Branch statements use the long form of the branch code if the label (or
  1937. tilde) is prefaced with a question mark '?', and otherwise use the short
  1938. form.
  1939.  
  1940.  
  1941. ---------------------------------------------------------------------------
  1942. B1. A Bill of Player's Rights
  1943. ---------------------------------------------------------------------------
  1944.  
  1945.  
  1946.   W. H. Auden once observed that poetry makes nothing happen.  Adventure
  1947. games are much the same, except that they make the player annoyed most of
  1948. the time.  There's a fine line between a challenge and a nuisance: and
  1949. perhaps the most important point about designing a game is to think like a
  1950. player, not a programmer or even an author.
  1951.  
  1952.   With that in mind, I hold the following rights to be self-evident:
  1953.  
  1954.  
  1955.     1.  Not to be killed without warning
  1956.  
  1957.   At its most basic level, this means that a room with three exits, two of
  1958. which lead to instant death and the third to treasure, is unreasonable
  1959. without some hint.  Mention of which brings us to:
  1960.  
  1961.     2.  Not to be given horribly unclear hints
  1962.  
  1963.   Many years ago, I played a game in which going north from a cave led to a
  1964. lethal pit.  The hint was: there was a pride of lions carved above the
  1965. doorway.  Good hints can be skilfully hidden, or very brief (I think, for
  1966. example, the hint in the moving-rocks plain problem in "Spellbreaker" is a
  1967. masterpiece) but should not need explaining even after the event.
  1968.  
  1969.   A more sophisticated version of (1) leads us to:
  1970.  
  1971.     3.  To be able to win without experience of past lives
  1972.  
  1973.   Suppose, for instance, there is a nuclear bomb buried under some anonymous
  1974. floor somewhere, which must be disarmed.  It is unreasonable to expect a
  1975. player to dig up this floor purely because in previous games, the bomb blew
  1976. up there.  To take a more concrete example, in "The Lurking Horror" there is
  1977. something which needs cooking for the right length of time.  As far as I can
  1978. tell, the only way to find out the right time is by trial and error.  But
  1979. you only get one trial per game.  In principle a good player should be able
  1980. to play the entire game out without doing anything illogical.  In similar
  1981. vein:
  1982.  
  1983.     4.  To be able to win without knowledge of future events
  1984.  
  1985.   For example, the game opens near a shop.  You have one coin and can buy a
  1986. lamp, a magic carpet or a periscope.  Five minutes later you are transported
  1987. away without warning to a submarine, whereupon you need a periscope.  If you
  1988. bought the carpet, bad luck.
  1989.  
  1990.     5.  Not to have the game closed off without warning
  1991.  
  1992.   Closed off meaning that it would become impossible to proceed at some
  1993. later date.  If there is a papier-mache wall which you can walk through at
  1994. the very beginning of the game, it is extremely annoying to find that a
  1995. puzzle at the very end requires it to still be intact, because every one of
  1996. your saved games will be useless.  Similarly it is quite common to have a
  1997. room which can only be visited once per game.  If there are two different
  1998. things to be accomplished there, this should be hinted at.
  1999.  
  2000.     6.  Not to need to do unlikely things
  2001.  
  2002.   For example, a game which depends on asking a policeman about something he
  2003. could not reasonably know about.  (Less extremely, the problem of the
  2004. hacker's keys in "The Lurking Horror".)  Another unlikely thing is waiting
  2005. in uninteresting places.  If you have a junction such that after five turns
  2006. an elf turns up and gives you a magic ring, a player may well never spend
  2007. five turns there and never solve what you intended to be straightforward. 
  2008. On the other hand, if you were to put something which demanded investigation
  2009. in the junction, it might be fair enough.  ("Zork III" is especially poor in
  2010. this respect.)
  2011.  
  2012.     7.  Not to need to do boring things for the sake of it
  2013.  
  2014.   In the bad old days many games would make life difficult by putting
  2015. objects needed to solve a problem miles away from where the problem was,
  2016. despite all logic - say, putting a boat in the middle of a desert.  Or, for
  2017. example, it might be fun to have a four-discs tower of Hanoi puzzle in a
  2018. game.  But not an eight-discs one.
  2019.  
  2020.     8.  Not to have to type exactly the right verb
  2021.  
  2022.   For instance, looking inside a box finds nothing, but searching it does. 
  2023. Or consider the following dialogue (amazingly, from "Sorcerer"):
  2024.  
  2025.     >unlock journal
  2026.     (with the small key)
  2027.     No spell would help with that!
  2028.  
  2029.     >open journal
  2030.     (with the small key)
  2031.     The journal springs open.
  2032.  
  2033. This is so misleading as to constitute a bug.  But it's an easy design fault
  2034. to fall into.  (Similarly, the wording needed to use the brick in Zork II
  2035. strikes me as quite unfair.  Or perhaps I missed something obvious.)
  2036.  
  2037.     9.  To be allowed reasonable synonyms
  2038.  
  2039.   In the same room in "Sorcerer" is a "woven wall hanging" which can instead
  2040. be called "tapestry" (though not "curtain").  This is not a luxury, it's an
  2041. essential.
  2042.  
  2043.     10.  To have a decent parser
  2044.  
  2045.   This goes without saying.  At the very least it should provide for taking
  2046. and dropping multiple objects.  Some suggestions for a decent specification
  2047. are given in Appendix B3.
  2048.  
  2049.   The last few are more a matter of taste, but I believe in them:
  2050.  
  2051.     11.  To have reasonable freedom of action
  2052.  
  2053.   Being locked up in a long sequence of prisons, with only brief escapes
  2054. between them, is not all that entertaining.  After a while the player begins
  2055. to feel that the designer has tied him to a chair in order to shout the plot
  2056. at him.
  2057.  
  2058.     12.  Not to depend much on luck
  2059.  
  2060.   Small chance variations add to the fun, but only small ones.  The thief in
  2061. "Zork I" seems to me to be just about right in this respect, and similarly
  2062. the spinning room in "Zork II".  But a ten-ton weight which fell down and
  2063. killed you at a certain point in half of all games is just annoying.
  2064.  
  2065.     13.  To be able to understand a problem once it is solved
  2066.  
  2067.   This may sound odd, but many problems are solved by accident or trial and
  2068. error.  A guard-post which can be passed only if you are carrying a spear,
  2069. for instance, ought to have some indication that this is why you're allowed
  2070. past.  (The most extreme example must be the notorious Bank of Zork.)
  2071.  
  2072.     14.  Not to be given too many red herrings
  2073.  
  2074.   A few red herrings make a game more interesting.  A very nice feature of
  2075. "Zork I", "II" and "III" is that they each contain red herrings explained in
  2076. the others (in one case, explained in "Sorcerer").  But difficult puzzles
  2077. tend to be solved last, and the main technique players use is to look at
  2078. their maps and see what's left that they don't understand.  This is
  2079. frustrated when there are many insoluble puzzles and useless objects.  So
  2080. you can expect players to lose interest if you aren't careful.  My personal
  2081. view is that red herrings ought to have some clue provided (even only much
  2082. later): for instance, if there is a useless coconut near the beginning, then
  2083. perhaps much later an absent-minded botanist could be found who wandered
  2084. about dropping them.  The coconut should at least have some rationale.
  2085.  
  2086.   The very worst game I've played for red herrings is "Sorcerer", which by
  2087. my reckoning has 10.
  2088.  
  2089.     15.  To have a good reason why something is impossible
  2090.  
  2091.   Unless it's also funny, a very contrived reason why something is
  2092. impossible just irritates.  (The reason one can't walk on the grass in
  2093. "Trinity" is only just funny enough, I think.)
  2094.  
  2095.     16.  Not to need to be American to understand hints    (*)
  2096.  
  2097.   The diamond maze in "Zork II" being a case in point.  Similarly, it's
  2098. polite to allow the player to type English or American spellings or idiom. 
  2099. For instance "Trinity" endears itself to English players in that the soccer
  2100. ball can be called "football" - soccer is a word almost never used in
  2101. England.
  2102.  
  2103.     17.  To know how the game is getting on
  2104.  
  2105.   In other words, when the end is approaching, or how the plot is
  2106. developing.  Once upon a time, score was the only measure of this, but
  2107. hopefully not any more.
  2108.  
  2109.  
  2110. (*) Several people have politely pointed out to me that my own game
  2111.     "Curses" is, shall we say, slightly English.  But then, like any
  2112.     good dictator, I'm better at drafting constitutions than abiding
  2113.     by them.
  2114.  
  2115.  
  2116. ---------------------------------------------------------------------------
  2117. B2. What makes a good game?
  2118. ---------------------------------------------------------------------------
  2119.  
  2120.  
  2121.  
  2122. 1.  The Plot
  2123.  
  2124. The days of games which consisted of wandering around doing unrelated things
  2125. to get treasures, are long passed: the original Adventure was fun, and so
  2126. was Zork, but two such games are enough.  There should be some overall task
  2127. to be achieved, and it ought to be apparent to the player in advance.
  2128.  
  2129. This isn't to say that it should be apparent at once.  Instead, one can
  2130. begin with just an atmosphere or mood.  But if so, there must be a
  2131. consistent style throughout and this isn't easy to keep up.  "The Lurking
  2132. Horror" is an excellent example of a successful genre style; so is "Leather
  2133. Goddesses of Phobos".
  2134.  
  2135. At its most basic, this means there should be no electric drills lying about
  2136. in a medieval-style fantasy.  The original Adventure was very clean in this
  2137. respect, whereas Zork was less so: I think this is why Adventure remains the
  2138. better game even though virtually everything in Zork was individually
  2139. better.
  2140.  
  2141. If the chosen genre isn't fresh and relatively new, then the game had better
  2142. be very good.
  2143.  
  2144. Plot begins with the opening message, rather the way an episode of Star Trek
  2145. begins before the credits come up.  It ought to be striking and concise (not
  2146. an effort to sit through, like the title page of "Beyond Zork").  By and
  2147. large Infocom were good at this.  A fine example is the overture to
  2148. "Trinity" (by Brian Moriarty):
  2149.  
  2150.   Sharp words between the superpowers. Tanks in East Berlin. And now,
  2151.   reports the BBC, rumors of a satellite blackout. It's enough to spoil your
  2152.   continental breakfast.
  2153.  
  2154.   But the world will have to wait. This is the last day of your $599 London
  2155.   Getaway Package, and you're determined to soak up as much of that
  2156.   authentic English ambience as you can. So you've left the tour bus behind,
  2157.   ditched the camera and escaped to Hyde Park for a contemplative stroll
  2158.   through the Kensington Gardens.
  2159.  
  2160. Already you know: who you are (an unadventurous American tourist, of no
  2161. significance in the world); exactly where you are (Kensington Gardens, Hyde
  2162. Park, London, England); and what is going on (World War III is about to
  2163. break out).  Notice the careful details: mention of the BBC, of continental
  2164. breakfasts, of the camera and the tour bus.  More subtly, "Trinity" is a
  2165. game which starts as a kind of escapism from a disastrous world out of
  2166. control: notice the way the first paragraph is in tense, blunt,
  2167. headline-like sentences, whereas the second is much more relaxed.  So a lot
  2168. has been achieved by these two opening paragraphs.
  2169.  
  2170. The most common plots boil down to saving the world, by exploring until
  2171. eventually you vanquish something ("Lurking Horror" again, for instance) or
  2172. collecting some number of objects hidden in awkward places ("Leather
  2173. Goddesses" again, say).  The latter can get very hackneyed (got to find the
  2174. nine magic spoons of Zenda to reunite the Kingdom...), so much so that it
  2175. becomes a bit of a joke ("Hollywood Hijinx") but still it isn't a bad idea,
  2176. because it enables many different problems to be open at once.
  2177.  
  2178. Most games have a prologue, a middle game and an end game, which are usually
  2179. quite closed off from each other.  Usually once one of these phases has been
  2180. left, it cannot be returned to.
  2181.  
  2182. 2.  The Prologue
  2183.  
  2184. In establishing an atmosphere, the prologue gives a good head start.  In the
  2185. original mainframe Adventure, this was the above-ground landscape; the fact
  2186. that it was there gave a much greater sense of claustrophobia and depth to
  2187. the underground bulk of the game.
  2188.  
  2189. Sometimes a dream-sequence is used (for instance, in "Lurking Horror"), or
  2190. sometimes simply a more mundane region of game (for instance, the
  2191. guild-house in "Sorcerer").  It should not be too large or too hard.
  2192.  
  2193. As well as establishing the mood of the game, and giving out some background
  2194. information, the prologue has to attract a player enough to make him carry
  2195. on playing.  It's worth imagining that the player is only toying with the
  2196. game at this stage, and isn't drawing a map or being at all careful.  If the
  2197. prologue is big, the player will quickly get lost and give up.  If it is too
  2198. hard, then many players simply won't reach the middle game.
  2199.  
  2200. Perhaps eight to ten rooms is the largest a prologue ought to be, and even
  2201. then it should have a simple (easily remembered) map layout.
  2202.  
  2203. 3.  The Middle Game
  2204.  
  2205. A useful exercise is to draw out a tree (or more accurately a lattice) of
  2206. all the puzzles in a game.  At the top is a node representing the start of
  2207. the game, and then lower nodes represent solved puzzles.  An arrow is drawn
  2208. between two puzzles if one has to be solved before the other can be.  For
  2209. instance, a simple portion might look like:
  2210.  
  2211.                                Start
  2212.                               /     \
  2213.                              /       \
  2214.                       Find key     Find car
  2215.                              \        |
  2216.                               \       |
  2217.                                Start car
  2218.                                    |
  2219.                                    |
  2220.                              Reach motorway
  2221.  
  2222. This is useful because it checks that the game is soluble (for example, if
  2223. the ignition key had been kept in a phone box on the motorway, it wouldn't
  2224. have been) but also because it shows the overall structure of the game.
  2225. The questions to ask are:
  2226.  
  2227.   How much is visible at once?
  2228.   Do large parts of the game depend on one difficult puzzle?
  2229.   How many steps does a typical problem need?
  2230.  
  2231. Some games, such as the original Adventure, are very wide: there are thirty or
  2232. so puzzles, all easily available, none leading to each other.  Others, such as
  2233. "Spellbreaker", are very narrow: a long sequence of puzzles, each of which
  2234. leads only to a chance to solve the next.
  2235.  
  2236. A compromise is probably best.  Wide games are not very interesting, while
  2237. narrow ones can in a way be easy: if only one puzzle is available at a time,
  2238. the player will just concentrate on it, and will not be held up by trying to
  2239. use objects which are provided for different puzzles.
  2240.  
  2241. Bottlenecks should be avoided unless they are reasonably guessable:
  2242. otherwise many players will simply get no further.
  2243.  
  2244. Puzzles ought not to be simply a matter of typing in one well-chosen line. 
  2245. One hallmark of a good game is not to get any points for picking up an
  2246. easily-available key and unlocking a door with it.  This sort of low-level
  2247. achievement - like wearing an overcoat found lying around, for instance -
  2248. should not be enough.  A memorable puzzle will need several different ideas 
  2249. to solve (the Babel fish dispenser in "Hitch-hikers", for instance).
  2250.  
  2251. 4.  Size and Density
  2252.  
  2253. Once upon a time, the sole measure of quality in advertisements for
  2254. adventure games was the number of rooms.  Even quite small programs would
  2255. have 200 rooms, which meant only minimal room descriptions and simple
  2256. puzzles which were scattered thinly over the map.
  2257.  
  2258. Nowadays a healthier principle has been adopted: that (barring a few
  2259. junctions and corridors) there should be something out of the ordinary about
  2260. every room.
  2261.  
  2262. One reason for the quality of the "Infocom" games is that the version 3
  2263. system has an absolute maximum of 255 objects, which needs to cover rooms,
  2264. objects and many other things (eg, compass directions, or the spells in
  2265. "Enchanter" et al).  Many "objects" are not portable anyway: walls,
  2266. tapestries, thrones, control panels, coal-grinding machines and so on.
  2267.  
  2268. As a rule of thumb, four objects to one room is about right: this means
  2269. there will be, say, 50-60 rooms.  Of the remaining 200 objects, one can
  2270. expect 15-20 to be used up by the game's administration (eg, a "darkness"
  2271. room, 10 compass directions, a player and so on).  Another 50-75 or so
  2272. objects will be portable but the largest number, at least 100, will be
  2273. furniture.
  2274.  
  2275. So an object limit can be a blessing as well as a curse: it forces the
  2276. designer to make the game dense.  Rooms are too precious to be wasted.
  2277.  
  2278. In the Infocom format, there's room for 150K of text at the most. This is
  2279. the equivalent of about a quarter of a modern novel, or perhaps the analogy
  2280. is that there are enough bytes to store a very substantial book of poetry.
  2281. Roughly, then, one can afford to spend 2K of text in each room - about ten
  2282. times the level of detail of the original mainframe Adventure.
  2283.  
  2284. 5.  Rewards
  2285.  
  2286. There are two kinds of reward which need to be given to a player in return
  2287. for solving a puzzle.  One is obvious: that the game should advance a
  2288. little.  But the player at the keyboard needs a reward as well, that the
  2289. game should offer something new to look at.  In the old days, when a puzzle
  2290. was solved, the player simply got a bar of gold and had one less puzzle to
  2291. solve.
  2292.  
  2293. Much better is to offer the player some new rooms and objects to play
  2294. with, as this is a real incentive.  If no new rooms are on offer, at least
  2295. the "treasure" objects can be made interesting, like the spells in the
  2296. "Enchanter" trilogy or the cubes in "Spellbreaker".
  2297.  
  2298. 6.  Mazes
  2299.  
  2300. Almost every game contains a maze.  Nothing nowadays will ever equal the
  2301. immortal
  2302.  
  2303.   You are in a maze of twisty little passages, all alike.
  2304.  
  2305. But now we are all jaded.  A maze should offer some twist which hasn't been
  2306. done before (the ones in "Enchanter" and "Sorcerer" being fine examples).
  2307.  
  2308. The point is not to make it hard and boring.  The standard maze solution is
  2309. to litter the rooms with objects in order to make the rooms distinguishable.
  2310. It's easy enough to obstruct this, the thief in "Zork I" being about the
  2311. wittiest way of doing so.  But that only makes a maze tediously difficult.
  2312.  
  2313. Instead there should be an elegant quick solution: for instance a guide who
  2314. needs to be bribed, or fluorescent arrows painted on the floor which can
  2315. only be seen in darkness (plus a hint about darkness, of course).
  2316.  
  2317. Above all, don't design a maze which appears to be a standard impossibly
  2318. hard one: even if it isn't, a player may lose heart and give up rather than
  2319. go to the trouble of mapping it.
  2320.  
  2321. 7.  Wrong guesses
  2322.  
  2323. For some puzzles, a perfectly good alternative solution will occur to
  2324. players.  It's good style to code two or more solutions to the same puzzle,
  2325. if that doesn't upset the rest of the game.  But even if it does, at least
  2326. a game should say something when a good guess is made.  (Trying to cross the
  2327. volcano on the magic carpet in "Spellbreaker" is a case in point.)
  2328.  
  2329. One reason why "Zork" held the player's attention so firmly (and why it took
  2330. about ten times the code size, despite being slightly smaller than the
  2331. original mainframe Adventure) was that it had a huge stock of usually funny
  2332. responses to reasonable things which might be tried.
  2333.  
  2334. My favourite funny response, which I can't resist reprinting here, is:
  2335.  
  2336.    You are falling towards the ground, wind whipping around you.
  2337.    >east
  2338.    Down seems more likely.                                  ["Spellbreaker"]
  2339.  
  2340. (Though I also recommend trying to take the sea serpent in "Zork II".)  This
  2341. is a good example because it's exactly the sort of boring rule (can't move
  2342. from the midair position) which most designers usually want to code as fast
  2343. as possible, and don't write with any imagination.
  2344.  
  2345. Just as some puzzles should have more than one solution, some objects should
  2346. have more than one purpose.  In bad old games, players automatically threw
  2347. away everything as soon as they'd used them.  In better designed games,
  2348. obviously useful things (like the crowbar and the gloves in "Lurking
  2349. Horror") should be hung on to by the player throughout.
  2350.  
  2351. 8.  The Map
  2352.  
  2353. To maintain an atmosphere throughout it's vital that the map should be
  2354. continuous.  Adventure games used to have maps like
  2355.  
  2356.                             Glacier
  2357.                                |
  2358.                           Oriental Room  --  Fire Station
  2359.                            (megaphone)        (pot plant)
  2360.                                |
  2361.                            Cheese Room
  2362.  
  2363. in which the rooms bore no relation to each other, so that the game had no
  2364. overall geography at all, and objects were unrelated to the rooms they were
  2365. in.  Much more believable is something like
  2366.  
  2367.                    Snowy Mountainside
  2368.                             \  
  2369.                          Carved Tunnel
  2370.                                |
  2371.                          Oriental Room  -- Jade Passage -- Fire Dragon
  2372.                             (buddha)       (bonsai tree)      Room
  2373.                                |
  2374.                          Blossom Room
  2375.  
  2376. Try to have some large-scale geography too: the mountainside should extend
  2377. across the map in both directions.  If there is a stream passing through a
  2378. given location, what happens to it?  And so on.
  2379.  
  2380. In designing a map, it adds to the interest to make a few connections in the
  2381. rarer compass directions (NE, NW, SE, SW) to prevent the player from a
  2382. feeling that the game has a square grid.  Also, it's nice to have a few
  2383. (possibly long) loops which can be walked around, to prevent endless
  2384. retracing of steps.
  2385.  
  2386. If the map is very large, or if a good deal of to-and-froing is called for,
  2387. there should be some rapid means of moving across it, such as the magic
  2388. words in Adventure, or the cubes in "Spellbreaker".
  2389.  
  2390. 9.  The End Game
  2391.  
  2392. Some end games are small ("Lurking Horror", or "Sorcerer" for instance),
  2393. others large (the master game of the mainframe Adventure).  Nonetheless
  2394. almost all games have one.
  2395.  
  2396. End games serve two purposes.  Firstly they give the player a sense of being
  2397. near to success, and can be used to culminate the plot, to reveal the game's
  2398. secrets.  This is obvious enough.  But secondly they also serve to stop the
  2399. final stage of the game from being too hard.
  2400.  
  2401. As a designer, you don't usually want the last step to be too difficult; you
  2402. want to give the player the satisfaction of finishing, as a reward for
  2403. having got through the game.  (But of course you want to make him work for
  2404. it.)  An end game helps, because it narrows the game, so that only a few
  2405. rooms and objects are accessible.
  2406.  
  2407. The most annoying thing is requiring the player to have brought a few
  2408. otherwise useless objects with him.  The player should not be thinking that
  2409. the reason for being stuck on the master game is that something very obscure
  2410. should have been done 500 turns before.
  2411.  
  2412. 10.  And Finally...
  2413.  
  2414. Finally, the winner gets some last message (which, like the opening message,
  2415. should have something amusing in it and should not be too long).  That
  2416. needn't quite be all, though.  In its final incarnations (alas, not the one
  2417. included in Lost Treasures), "Zork I" offered winners access to the hints
  2418. system at the RESTART, RESTORE or QUIT prompt.
  2419.  
  2420. 11.  It's Never Finished
  2421.  
  2422. Games are never finished.  There's always one more bug, or one more message
  2423. which could be improved, or one more little cute reply to put in.  Debugging
  2424. is a creative process and adds to the life of the game.  My game "Curses"
  2425. was finished after about 80K of coding, but it's now 128K long.  In other
  2426. words, over a third of Curses is devoted to "irrelevant" features, blind
  2427. alleys and the like.
  2428.  
  2429. A first stage in debugging is to produce what you think is a perfectly
  2430. working game and hand it over to some players (preferably several) for a
  2431. week or two.  Expect this to produce a hundred or so awesomely trivial
  2432. bugs and one or two hugely obvious ones.  But don't expect that that's the
  2433. only hundred.  I think altogether 200 bugs in "Curses" have been spotted
  2434. since my original declared-finished version - about 50 of those in the
  2435. seven months since its public release.  I also think that the many people
  2436. who wrote to me to suggest little extensions and repairs have greatly
  2437. contributed to the game, and that's why there are so many names in the
  2438. credits.
  2439.  
  2440. 12.  Last Word
  2441.  
  2442. Inform makes it easy to knock up games which look a little bit like the
  2443. classics, until you play them.  Infocom, Inc, acquired a certain mystique in
  2444. their time, but a game is not good merely because it runs under one of their
  2445. interpreters.  Still, I hope a few people may put in the effort to turn out
  2446. a finished game or two, and add to the canon.
  2447.  
  2448.  
  2449. --------------------------------------------------------------------------
  2450. B3. Writing a Parser
  2451. ---------------------------------------------------------------------------
  2452.  
  2453.  
  2454. This lengthy dialogue is to meant to demonstrate what a player can expect
  2455. from a parser, and some of the pitfalls in designing one.
  2456.  
  2457. At each stage, lines 2a, 2b, ... etc are alternative inputs. Comments are in
  2458. square brackets.  It is taken as read that the parser can cope with words
  2459. (such as "plant") being nouns, verbs or prepositions depending on context.
  2460.  
  2461.  
  2462.       Parser Demo
  2463.       Welcome to the demonstration cave.
  2464.  
  2465.       You can see an Elvish-made sword and a Dutch-made sword.
  2466.  
  2467. [To begin with, an easy ambiguity.  There may be many other swords
  2468. elsewhere, but these should not obstruct the parser.]
  2469.  
  2470.       You can see an Elvish-made sword and a Dutch-made sword.
  2471.  
  2472. 1a.   > take the dutch sword
  2473.       Taken.
  2474. 1b.   > remove a sword
  2475.       (the Elvish-made sword)
  2476.       Taken.
  2477. 1c.   > get sword
  2478.       Which do you mean, the Elvish-made sword or the Dutch-made sword?
  2479.  
  2480. [Suppose you tried 1b.  There are four possible responses: you
  2481. don't care which, you want both, you say exactly which, or you give
  2482. a command again in full.]
  2483.  
  2484. 2a.   > either
  2485.       (the Elvish-made sword)
  2486.       Taken.
  2487. 2b.   > both
  2488.       Elvish-made sword: Taken.
  2489.       Dutch-made sword: Taken.
  2490. 2c.   > elvish
  2491.       Taken.
  2492. 2d.   > pick up the dutch sword
  2493.       Taken.
  2494.  
  2495. [2a may seem unnecessary - but what if the two objects were
  2496. absolutely indistinguishable from each other?  At least this would
  2497. allow the player to pick up one of them.]
  2498.  
  2499. [Now the player holds the Dutch sword, say, but the Elvish one is on
  2500. the floor.  The parser should therefore be able to decide which you
  2501. mean when you want to take or drop.]
  2502.  
  2503. 3a.   > drop sword
  2504.       (the Dutch-made sword)
  2505.       Dropped.
  2506.       > drop the dutch sword
  2507.       It is already on the ground.
  2508. 3b.   > take sword
  2509.       (the Elvish-made sword)
  2510.       Taken.
  2511.  
  2512. [Note that the parser accepts "drop the dutch sword", even when the
  2513. Dutch sword is already on the ground, exactly so as to allow the
  2514. production of the helpful message.  This shows that requests can be
  2515. contextually allowable, even when the parser knows they are illegal.]
  2516.  
  2517.       A dwarf comes in and deposits a Roman sword on the floor.
  2518.  
  2519. [Next, plurals.  The three swords are now on the floor, suppose, and
  2520. so are a Jersey cow, a red herring and a postage stamp.]
  2521.  
  2522. 4a.   > take all the swords
  2523.       Roman sword: Taken.
  2524.       Dutch-made sword: Taken.
  2525.       Elvish-made sword: Taken.
  2526. 4b.   > take every sword except the dutch
  2527.       Roman sword: Taken.
  2528.       Elvish-made sword: Taken.
  2529. 4c.   > take the roman and dutch swords
  2530.       Roman sword: Taken.
  2531.       Dutch-made sword: Taken.
  2532. 4d.   > take all swords but roman, elvish and dutch
  2533.       Nothing to do!
  2534. 4e.   > get everything except the swords and the fish
  2535.       Jersey cow: Too large.
  2536.       postage stamp: Taken.
  2537.  
  2538. [Some verbs ought not to allow multiple objects.]
  2539.  
  2540. 5a.   > examine everything
  2541.       That verb can't take multiple objects.
  2542.  
  2543. [Others can be abbreviated.  Common abbreviations are "x" for "examine",
  2544. "i" for "inventory", "l" for "look", "z" for "wait", "g" for "again".]
  2545.  
  2546. 6a.   > x roman sword
  2547.       A gladius, or one-handed short sword.
  2548.  
  2549. [Words like "it" or "them" ought to refer to the last-mentioned item.]
  2550.  
  2551. 7a.   > take it
  2552.       Taken.
  2553.  
  2554. [But beware: this is dangerous if the object is no longer in context.]
  2555.  
  2556. 8a.   > drop it into chasm
  2557.       The Roman sword vanishes into darkness.
  2558.       > x it
  2559.       The Roman sword is no longer available.
  2560.  
  2561. [Also, to some extent "it" should follow the game.  It would be usual to
  2562. code the following by removing the sword object and replacing it with an
  2563. Eagle one - but what happens to "it"?]
  2564.  
  2565. 9a.   > wave magic wand at it
  2566.       The Roman sword transmogrifies into the Eagle of the Ninth Legion.
  2567.       > x it
  2568.       The Eagle is the standard of the legion...
  2569.  
  2570. [Vagueness: and more on resolving ambiguity.  To begin with, you should
  2571. have the opportunity to specify what you want more fully - but only if
  2572. it is not obvious:]
  2573.  
  2574. 10a.  > take
  2575.       What do you want to take?
  2576.       > the postage stamp
  2577.       Taken.
  2578. 10b.  > drop
  2579.       (the Eagle of the Ninth)
  2580.       Dropped.
  2581.  
  2582. [One can take this dangerously far.  Should the parser be allowed to
  2583. implicitly solve a problem for the player?  Suppose you dropped
  2584. a sandwich by mistake a while back, and now intend to eat it...]
  2585.  
  2586. 11a.  > eat
  2587.       (the plant root)
  2588.       Mmm, the plant root isn't bad, but what strange things are
  2589.       happening to your vision...
  2590.  
  2591. [The parser should be aware, when resolving ambiguities and handling
  2592. plurals, of the distinction between objects being worn and merely being
  2593. carried.]
  2594.  
  2595. 12a.  > inventory
  2596.       You're wearing a taffeta dress and carrying a cotton blouse.
  2597.       > drop all
  2598.       cotton blouse: Dropped.
  2599. 12b.  > drop
  2600.       (the cotton blouse)
  2601.       Dropped.
  2602. 12c.  > drop taffeta
  2603.       It's suddenly rather cold in here.
  2604.  
  2605. [Similarly, there is a distinction between living and dead objects:]
  2606.  
  2607. 13a.  > say hello
  2608.       (to the dwarf)
  2609.       The dwarf grunts with irritation.
  2610.       > look
  2611.       A dwarf guards a cotton blouse and a postage stamp.
  2612.       > take all
  2613.       cotton blouse: The dwarf bars you.
  2614.       postage stamp: The dwarf bars you.
  2615.  
  2616. [Which brings us to conversation.  By convention, the standard format
  2617. is:]
  2618.  
  2619. 14a.  > dwarf, hello
  2620.       The dwarf grunts with irritation.
  2621. 14b.  > dwarf, go east
  2622.       The dwarf trundles off east.
  2623. 14c.  > dwarf, take
  2624.       What do you want the dwarf to take?
  2625.       > postage stamp
  2626.       The dwarf angrily refuses.
  2627. 14d.  > dwarf, drop everything
  2628.       dwarvish shield: The dwarf drops the shield.
  2629.       mithril armour: The dwarf refuses.
  2630.  
  2631. [Note that in the latter case, context for the dwarf is not the same as
  2632. context for the player, and "everything" must be read differently.]
  2633.  
  2634. [A particularly nasty, if unlikely case to resolve is:]
  2635.  
  2636. 15a.  > dwarf, examine
  2637.       What do you want the dwarf to examine?
  2638.       > dwarf, stamp
  2639.  
  2640. [Is the correct idea that the dwarf should look at himself and the
  2641. postage stamp?  Or that he should stamp his feet?]
  2642.  
  2643. [Another problem with conversation is that the parser should accept
  2644. it even when it doesn't make sense in game terms.  After all, you might
  2645. really mean this...]
  2646.  
  2647. 16a.  > dwarf, get your lousy beard out of here
  2648.       The dwarf spits.
  2649.  
  2650. [A parser may well have to accept arbitrary numbers or words at some
  2651. point.  For instance:]
  2652.  
  2653. 17a.  > write earth on cube
  2654.       You write "earth" on the featureless white cube.
  2655. 17b.  > enter 132
  2656.       You type "132" at the keyboard, and the safe opens.
  2657.  
  2658. [But care is sometimes needed, unless the parser insists on the player
  2659. using double-quotes:]
  2660.  
  2661. 18a.  > enter safe
  2662.       You type "safe" at the keyboard.
  2663. 18b.  > enter the safe
  2664.       You enter the walk-in safe.
  2665.  
  2666. [In a complicated command, information should gradually accumulate:]
  2667.  
  2668. 19a.  > transfer sword
  2669.       Which do you mean, the Roman sword or the Dutch-made sword?
  2670.       > roman
  2671.       What do you want to transfer the Roman sword to?
  2672.       > filing
  2673.       Which do you mean, the green filing cabinet or the blue filing
  2674.       cabinet?
  2675.       > blue
  2676.       Transferred.
  2677.  
  2678. [However if, say, "transfer" is a verb which always takes the
  2679. preposition "to" - ie, which must have the form "transfer x to y" - the
  2680. parser ought to be able to manage if there's only one container handy:]
  2681.  
  2682. 20a.  > transfer a sword
  2683.       (the Roman sword to the green filing cabinet)
  2684.       Transferred.
  2685.  
  2686. [The fact that a single verb may have many possible forms (as many as
  2687. a dozen, for instance) means that a parser may have to make many
  2688. different guesses to resolve ambiguities.  These may clash.  At the
  2689. very least, the parser shouldn't ask the player for a ruling more than
  2690. once: and if it changes its mind, it should only print up
  2691.  
  2692.       (what it inferred you meant)
  2693.  
  2694. once, for the pattern which got nearest to acceptance.  Another pitfall
  2695. is:]
  2696.  
  2697. 21a.  The dwarf takes everything away, then returns with the Sword of
  2698.       Damocles and the Sword of Alexander.
  2699.       > take sword of damocels
  2700.       You can't see any such thing.
  2701.  
  2702. [This appears obvious.  The trap is that the parser may have recognised
  2703. that "sword of" might refer to one of two things, and ask the player which
  2704. is intended, and only afterwards reach the inevitable conclusion that the
  2705. command doesn't make sense, because "damocels" isn't a preposition which
  2706. "take" can have.]
  2707.  
  2708. [Containers complicate the issue of context a little.  Consider these
  2709. alternative lines:]
  2710.  
  2711. 22a.  > look
  2712.       There are a red apple and two boxes here, a glass box and a steel box:
  2713.       both open.
  2714.       > i
  2715.       You carry a rucksack (which is empty), a torch, a banana and an
  2716.       apple.  You are wearing a patterned dress.
  2717.       > put everything in the rucksack
  2718.       torch: Transferred.
  2719.       banana: Transferred.
  2720.       green apple: Transferred.
  2721.       > empty rucksack into glass
  2722.       torch: Transferred.
  2723.       banana: Transferred.
  2724.       green apple: Transferred.
  2725.       > get apple from glass box                (*)
  2726.       Taken.
  2727.       > drop it in glass box
  2728.       Done.
  2729.       > close glass
  2730.       You close the glass box.
  2731.       > x apple
  2732.       Which apple do you mean, the red apple or the green apple?
  2733.       > green
  2734.       The apple is not yet ripe.
  2735.       > take it
  2736.       But the glass box is closed.
  2737. 22b.  > drop all except torch into the steel box
  2738.       rucksack: Dropped.
  2739.       banana: Dropped.
  2740.       green apple: Dropped.
  2741.       > put dress in steel box
  2742.       (taking it off first)
  2743.       Done.
  2744.       > x dress
  2745.       It has pictures of tulips on.
  2746.       > close steel box
  2747.       You close the steel box.
  2748.       > x dress
  2749.       You can't see any such thing.
  2750.  
  2751. [Note the way no attempt is made to put the rucksack inside itself.
  2752. Also, note that in the former line, objects can still be seen (if not
  2753. manipulated) because the glass box has transparent walls.  In the
  2754. latter, they become invisible when the box closes.
  2755.  
  2756. At (*), "get apple" would have been ambiguous.  In most games, so
  2757. would "get apple from box", though a really astute parser could deduce
  2758. that the box must be the glass one, because the other does not contain
  2759. an apple, and that the apple must be the green one, because the red one
  2760. isn't in anything.]
  2761.  
  2762. [Containment complicates the rules governing darkness considerably -
  2763. what happens after...]
  2764.  
  2765. 22c.  > put torch in steel box
  2766.       Done.
  2767.       > close steel box
  2768.       It is now pitch dark!
  2769.       > open steel box
  2770.  
  2771. [Is the steel box now in context?  Most parsers would insist that objects
  2772. on the floor of a dark room are not in context.  But that punishes the
  2773. player rather severely for her mistake, and not very realistically.  On
  2774. the other hand...]
  2775.  
  2776. 23a.  > east
  2777.       It's pitch dark in here.
  2778.       > get gelignite
  2779.       Taken.
  2780.  
  2781. [...in circumstances where the gelignite has never been seen before, is
  2782. regrettable.]
  2783.  
  2784. [To what extent should a parser issue implicit commands on behalf of the
  2785. player?  In some cases, this is clearly good practice.  In others, it is
  2786. not so clear.  For instance:]
  2787.  
  2788. 24a.  > drop dress
  2789.       (taking off the patterned dress first)
  2790.       Dropped.
  2791. 24b.  > read newspaper
  2792.       (taking the copy of the Daily Telegraph)
  2793.       "The Prime Minister today proved his brilliant grasp of..."
  2794. 24c.  > drop newspaper
  2795.       (taking the copy of the Daily Telegraph)
  2796.       Dropped.
  2797. 24d.  > examine delicate bomb label
  2798.       (taking the delicate bomb)
  2799.       The bomb explodes at your first touch!
  2800.  
  2801. [The first pair are clearly right, the second pair wrong.  This illustrates
  2802. also that the parser cannot handle "implicit taking" and the like in a
  2803. naive way: it must use the same game code as if the player had asked
  2804. explicitly.  Otherwise, the player could sneakily use, say, "drop chains"
  2805. to get the parser to remove her chains, even though the game itself would
  2806. not have allowed this.  Similarly, which of these will a player be more
  2807. impressed by?]
  2808.  
  2809. 25a.  > drop all
  2810.       newspaper: Dropped.
  2811.       delicate bomb: You don't really mean that!
  2812. 25b.  > drop all
  2813.       newspaper: Dropped.
  2814.       delicate bomb: The bomb explodes cataclysmically, killing you!
  2815.  
  2816. [A degree of customisation also makes for a happier player.  For instance,
  2817. in the author's game "Curses", the tedious rule is maintained that a player
  2818. can't hold more than five things at once, to which there is the tedious
  2819. solution of carrying a rucksack around to hold miscellaneous plunder.  It
  2820. becomes very boring to type all the "put x in rucksack" commands by hand, so
  2821. the parser infers these:]
  2822.  
  2823. 25a.  > get red herring
  2824.       (putting the cypher into the rucksack to make room)
  2825.       Taken.
  2826.  
  2827. [But a parser has to know a certain amount to do this sensibly: not to try
  2828. putting the rucksack into itself, not to put the light source into the
  2829. rucksack, and to try disposing of the item longest ignored.]
  2830.  
  2831. ["Again" is surprisingly hard to code in a context-sensitive way, but
  2832. players want it:]
  2833.  
  2834. 26a.  > throw herring into chasm
  2835.       It disappears into the darkness.
  2836.       > again
  2837.       I can't see what you're referring to.
  2838.  
  2839. [And another is-it-fair? darkness problem...]
  2840.  
  2841. 27a.  > press switch
  2842.       It is now pitch dark in here!
  2843.       > again
  2844.       I can't see what you're referring to.
  2845.  
  2846. [These are at least correct behaviour.  The disaster would be to continue
  2847. to allow the player to refer to the herring after it had fallen into the
  2848. chasm.  So the obvious solution is simply to parse the player's original
  2849. words all over again in the situation as it now is.  But then...]
  2850.  
  2851. 28a.  > press button
  2852.       Which button do you mean, the red button or the blue button?
  2853.       > blue
  2854.       Click!
  2855.       > again
  2856.       Click!
  2857.  
  2858. [...would not have worked - the question would have been asked all over
  2859. again.  So the player's clarifications have to be kept as well.]
  2860.  
  2861. [Another tricky bit of coding is for corrections, i.e. "oops".]
  2862.  
  2863. 29a.  > throw swrod at the dwarf
  2864.       You can't see any such thing.
  2865.       > oops sword
  2866.       The dwarf expires untidily.
  2867.  
  2868. [In practice it probably isn't worth coding this in an unduly clever way -
  2869. it only needs to work in most easy cases.  Even so it can be difficult to
  2870. point to the "obvious" wrong word, when the user's input as failed to
  2871. match against many different patterns.]
  2872.  
  2873.  
  2874. The conclusion of all this is that:
  2875.  
  2876. (i)  a parser is a major part of the game, and implicitly contains many
  2877.      of its rules and assumptions;
  2878. (ii) while it's obviously desirable to separate it as much as possible
  2879.      from the game proper, it must be customised to some degree and so
  2880.      cannot be separated altogether.
  2881.  
  2882. Thus, although it means very much more work, there is something to be said
  2883. for a game-design system which obliges the designer to provide a parser
  2884. himself.  Inform adopts the compromise of providing one which is as general
  2885. as possible, and held at arm's length, but which can be modified when
  2886. needed.
  2887.  
  2888.  
  2889. ---------------------------------------------------------------------------
  2890. C1. A Hello Cruel World program
  2891. ---------------------------------------------------------------------------
  2892.  
  2893.  
  2894. >   !
  2895. >   ! A great step backward in interactive fiction...
  2896. >   !
  2897. >
  2898. >   Object hillside "Bare hillside" nothing;
  2899. >   global place = hillside;
  2900. >   global score = 0;
  2901. >   global turns = 1;
  2902. >   
  2903. >   [ Main;
  2904. >   
  2905. >     print "^^^^^^^^^^^You wake up, shivering to see that Morgoth \
  2906. >            the Flatulent Devil is towering over you...^^";
  2907. >     Message();
  2908. >     print "^^\
  2909. >       ...and he squashes you effortlessly.^^   *** You have died ***^^^^^";
  2910. >   
  2911. >     quit;
  2912. >   ];
  2913. >   
  2914. >   [ Message i;
  2915. >     print "HELLO CRUEL WORLD^";
  2916. >     print "A Non-Interactive Demonstration^\
  2917. >            Copyright (c) 1993 by Graham Nelson. All rights reserved.^";
  2918. >     print "Release ";
  2919. >     print_num 0-->1;
  2920. >     print " / Serial number ";
  2921. >   
  2922. >     for i 18 to 23 { print_char 0->i; } new_line;
  2923. >   ];
  2924. >   
  2925.  
  2926. Note that the familiar banner has to be produced by your code.  By
  2927. convention, the first word (at bytes 2 and 3) of the file is the release
  2928. number, and this is what is set by the RELEASE command.  In this file there
  2929. isn't a RELEASE command, so it comes out as 1.  Bytes 18 to 23 contain the
  2930. serial number, or in fact the serial string of ASCII characters.  By custom
  2931. and tradition, these are the date of compilation arranged YYMMDD, and Inform
  2932. sets these automatically.
  2933.  
  2934. Note also that Message had to be a separate routine since we needed a local
  2935. variable, and Main is not permitted to have local variables of its own.
  2936.  
  2937. (The above source has changed a little since the first release: if the
  2938. object is not included, then some interpreters (not the InfoTaskForce one)
  2939. which voluntarily display the status line (when not asked to do so), get in
  2940. a quandary printing a location, time and score.  So for their benefit, here
  2941. are all three.)
  2942.  
  2943. On my machine (an Acorn Archimedes A5000), compiling with statistics
  2944. produces something like:
  2945.  
  2946.   *inform -s hellow
  2947.   Archimedes Inform 1.0 (v794/at)
  2948.   Input 31 lines (41 statements, 690 chars)
  2949.      1 objects (maximum 255)        0 dictionary entries (maximum 750)
  2950.      0 attributes (maximum 32)      2 properties (maximum 30)
  2951.      0 adjectives (maximum 240)     0 verbs (maximum 110)
  2952.      0 actions (maximum 125)        0 abbreviations (maximum 64)
  2953.      3 globals (maximum 240)      480 variable space (maximum 1500)
  2954.    141 symbols (maximum 3500)       2 routines (maximum 400)
  2955.    314 characters of text (compressed to 276 bytes, rate 0.878)
  2956.   Output story file is   1.5K long (maximum 128K)
  2957.   Essential size 1152 bytes: 129920 remaining
  2958.   Completed in 1 seconds.
  2959.  
  2960. (The second being mostly consumed in printing out the statistics.  In
  2961. practice the compilation time is roughly proportional to the output length,
  2962. and typically takes 0.5 seconds per K of story file on my machine.)
  2963.  
  2964. The "essential size" is the number of bytes actually used: the story file
  2965. is rounded up in size to an exact number of 512-byte blocks. The number
  2966. remaining is the actual number of bytes free in the Z-machine.
  2967.  
  2968. Note: if you try compiling the example games, and get different
  2969. statistics outputs, do not worry; it probably means you're using a later
  2970. version of Inform than the one that printed the above.  Similarly,
  2971. do not worry if your compiled story file shows differences with the
  2972. object code in the archive.
  2973.  
  2974. If the "Deja Vu" example (see below) compiles without Inform errors and
  2975. plays properly, then Inform is probably working OK.
  2976.  
  2977. As an extreme example, statistics for "Curses" look something like:
  2978.  
  2979.   *inform -sdep curses
  2980.   Archimedes Inform 1.0 (v794/at)
  2981.   Input 8532 lines (20095 statements, 348700 chars)
  2982.    255 objects (maximum 255)      732 dictionary entries (maximum 750)
  2983.     32 attributes (maximum 32)     29 properties (maximum 30)
  2984.     19 adjectives (maximum 240)   103 verbs (maximum 110)
  2985.    115 actions (maximum 125)       64 abbreviations (maximum 64)
  2986.     84 globals (maximum 240)     1340 variable space (maximum 1500)
  2987.   3496 symbols (maximum 3500)     307 routines (maximum 400)
  2988.   144284 characters of text (compressed to 91814 bytes, rate 0.636)
  2989.   Output story file is 128K long (maximum 128K)
  2990.   Approximate percentage breakdown of story file:
  2991.      Z-code               62.2%
  2992.      Static strings       24.1%
  2993.      Dictionary            3.9%
  2994.      Objects               6.7%
  2995.      Globals               1.0%
  2996.      Parsing tables        1.7%
  2997.      Header and synonyms   0.1%
  2998.      Total of save area    7.9%
  2999.      Total of text        70.2%
  3000.   Essential size 130780 bytes: 292 remaining
  3001.   Completed in 59 seconds.
  3002.   
  3003.  
  3004. ---------------------------------------------------------------------------
  3005. C2. "Deja Vu": a toy game
  3006. ---------------------------------------------------------------------------
  3007.  
  3008.  
  3009. The "Hello World" program above is enticingly short and easy, but only
  3010. because it doesn't contain a parser.  A fully functioning parser is hard
  3011. work to write, and occupies a good deal of "Inform" code.  Besides this, the
  3012. everyday mechanics of an adventure game involve more coding than most
  3013. designers want to go into, at least at the outset.
  3014.  
  3015. "Deja Vu" is a toy game in terms of how large it is to play, but
  3016. demonstrates the use of a large supplied library of Inform code.
  3017.  
  3018. Compiling "Deja Vu" with statistics should produce something like:
  3019.  
  3020.   *inform -s dejavu
  3021.   Archimedes Inform 1.0 (v794/at)
  3022.   Input 3837 lines (7529 statements, 126447 chars) from 4 files
  3023.     48 objects (maximum 255)      282 dictionary entries (maximum 750)
  3024.     30 attributes (maximum 32)     25 properties (maximum 30)
  3025.     19 adjectives (maximum 240)    77 verbs (maximum 110)
  3026.     86 actions (maximum 125)        0 abbreviations (maximum 64)
  3027.     77 globals (maximum 240)     1125 variable space (maximum 1500)
  3028.   1508 symbols (maximum 3500)     162 routines (maximum 400)
  3029.   16143 characters of text (compressed to 12078 bytes, rate 0.748)
  3030.   Output story file is  27K long (maximum 128K)
  3031.   Essential size 27430 bytes: 103642 remaining
  3032.   Completed in 19 seconds.
  3033.  
  3034. Again, don't worry if the details are slightly different.
  3035.   
  3036.  
  3037. ---------------------------------------------------------------------------
  3038. C3.  The library routines
  3039. ---------------------------------------------------------------------------
  3040.  
  3041.  
  3042. There are three header files provided to make up the kernel of a game,
  3043. which need to be #include'd at different points.  Together they amount
  3044. to a kind of operating system for the Z-machine.
  3045.  
  3046. Since they are themselves written in Inform, they can be altered if
  3047. necessary, but the idea is that they shouldn't need to be.  The shell game
  3048. in (C4) shows the minimum code needed to use the library, and DejaVu is a
  3049. more substantial example.
  3050.  
  3051. Your file _must_ provide one routine:
  3052.  
  3053.   Initialise() is called before the banner is printed up, and one thing it
  3054.   _must_ do is to set "location" to the initial game location.
  3055.  
  3056. It must also define two string constants, Story and Headline, e.g.:
  3057.  
  3058. >   Constant Story "ZORK II";
  3059. >   Constant Headline "^An Interactive Plagiarism^\
  3060. >                Copyright (c) 1993 by Ivan O. Ideas.^";
  3061.  
  3062.  
  3063. In addition, it may (but need not) provide the following routines:
  3064.  
  3065.   TimePasses() is called after every turn (but not, for instance, after a
  3066.   command like "score" or "save").
  3067.  
  3068.   PrintRank() completes the printing of the score.  (You might want to change
  3069.   this, so as to make the ranks something like "junior astronaut" or
  3070.   "master catburglar" or whatever suits your game.)
  3071.  
  3072.   DarkToDark() is called when a player goes from one dark room into another
  3073.   one.  If you want, you can take the opportunity to kill the player off
  3074.   for doing this.
  3075.  
  3076.   DeathMessage() is to print up "You have died" style messages.  To kill a
  3077.   player, set "deadflag" to 1.  To make a player win, set "deadflag" to 2.
  3078.   If you set "deadflag" to any other value (3, 4, ...) this routine is
  3079.   called to say what happened, e.g. "You have changed".
  3080.  
  3081.   LookRoutine() is called at the end of every location description.
  3082.  
  3083.   NewRoom() is called when the room changes, before any description of it
  3084.   is printed.  (This happens no matter how the change of room occurred.)
  3085.  
  3086.   PrintTaskName() prints the name of a game task (such as "driving the
  3087.   car").
  3088.  
  3089.   Amusing() is called to print some amusing afterword when the game is won
  3090.   (for instance, it might advertise some features which a successful
  3091.   player might never have noticed).
  3092.  
  3093.   GamePreRoutine() and GamePostRoutine() - see below.
  3094.  
  3095. Apart from these, the only routines of yours which are ever called are those
  3096. attached to your objects.
  3097.  
  3098.  
  3099. Three of the properties objects can have are:
  3100.  
  3101.   preroutine       whose values are routine names
  3102.   postroutine
  3103.   liferoutine
  3104.  
  3105. Suppose the player is in the Bedquilt Room, and types "drop oyster".  Once
  3106. it has checked that this is a reasonable command, the parser does the
  3107. following:
  3108.  
  3109.    1.  Call GamePreRoutine (if there is one).
  3110.        If this returns true, stop here.
  3111.  
  3112.    2.  Call the preroutine of Bedquilt Room.
  3113.        If this returns true, stop here.
  3114.  
  3115.    3.  Then the preroutine of the oyster.
  3116.        If this returns true, stop here.
  3117.  
  3118.    4.  Actually drop the object.
  3119.  
  3120.    5.  Call the postroutine of Bedquilt.
  3121.        If this returns true, stop here.
  3122.  
  3123.    6.  Then the postroutine of the oyster.
  3124.        If this returns true, stop here.
  3125.  
  3126.    7.  Call GamePostRoutine (if there is one).
  3127.        If this returns true, stop here.
  3128.  
  3129.    8.  Print "Dropped."
  3130.  
  3131. The point is that the preroutines can change the rules (e.g., to implement
  3132. "you can't drop things in the Bedquilt room", or "the toffee apple sticks
  3133. to your fingers") and postroutines can change what is printed (e.g., one
  3134. might print "Sinks into the bedquilt without trace" and remove whatever
  3135. was dropped).
  3136.  
  3137. Anything not mentioned in a preroutine or postroutine is dealt with in
  3138. the standard way.  In a postroutine the following variables are set up:
  3139.  
  3140.    action    The action, in the form #a$DropSub
  3141.    inp1      First parameter   | if given
  3142.    inp2      Second            |
  3143.  
  3144. (A complicated exception handles objects you can travel inside or push
  3145. from place to place - see the DejaVu code for the red car.)
  3146.  
  3147. To get your code to run whenever the room description is printed for a
  3148. particular place, put it under #a$LookSub in the room's postroutine.
  3149.  
  3150. Similarly, #a$GoSub in a room's postroutine applies when it has just been
  3151. walked into, whereas in a preroutine it refers to an intention to leave.
  3152.  
  3153. Here is a typical example:
  3154.  
  3155. >   [ CloverPost;
  3156. >     if action~=#a$TakeSub { rfalse; }
  3157. >     if player~=parent(sword) { rfalse; }
  3158. >     print_ret "As you take the clover, your sword shines \
  3159. >         a sudden burst of light!";
  3160. >   ];
  3161.  
  3162. Thus, when the clover is picked up, it makes the sword shine - as a hint,
  3163. say, that it's lucky.  Note that print_ret returns the value true (as well
  3164. as printing a new-line automatically), indicating intervention.  (And
  3165. "Taken.", which would be the usual response, is not printed.)
  3166.  
  3167. Warning: remember that in a postroutine, the action in question has already
  3168. taken place.  One might want the message to only appear the first time the
  3169. clover is taken, and naively code this as:
  3170.  
  3171. >     if clover has moved { rfalse; }
  3172.  
  3173. ...but that wouldn't work, because when the postroutine is called, the
  3174. "moved" attribute has already been set by TakeSub.
  3175.  
  3176. There is nothing to stop more than one object having the same pre- or
  3177. postroutine, and nothing to stop you changing them half-way through the
  3178. game after something happens.  (But be warned: the right command would be
  3179. something like
  3180.  
  3181. >     write clover postroutine #r$NewCloverPostroutine;
  3182.  
  3183. and remember to use the #r$ construction.)
  3184.  
  3185. GamePreRoutine and GamePostRoutine are extreme measures, changing the
  3186. rules across the entire game.  Remember that they're run every turn:
  3187. don't put anything too slow in them.
  3188.  
  3189.  
  3190. The actions implemented by the library are in three groups:
  3191.  
  3192.  1. Quit, Restart, Restore, Verify, Save, ScriptOn, ScriptOff,
  3193.     Brief, Normal, Verbose;
  3194.   
  3195.  2. Inv, Take, Drop, Remove, PutOn, Insert, Transfer, Empty,
  3196.     Enter, Exit, Go, Look, Examine, Give,
  3197.     Unlock, Lock, SwitchOn, SwitchOff, Open, Close, Disrobe, Wear, Eat;
  3198.  
  3199.  3. Rhet [rhetorical answer], Burn, Pray, Wake, WakeOther [person],
  3200.     Kiss, Think, Smell, Listen, Taste, Touch, TouchThing, Dig,
  3201.     Cut, Jump [jump on the spot], JumpOver, Tie, Drink,
  3202.     Fill, Sorry, Strong [swear word], Mild [swear word], Attack, Swim,
  3203.     Swing [something], Blow, Rub, Set, WaveHands [ie, just "wave"],
  3204.     Wave [something], Pull, Push, PushDir [push something in a direction],
  3205.     Turn, Squeeze, LookUnder [look underneath something], Search,
  3206.     ThrowAt, Answer, Buy, Ask, Sing, Climb, Wait, Sleep
  3207.  
  3208. Note that the player can type all manner of things to get these.  For
  3209. instance, "take off shirt" and "remove shirt" both cause the Disrobe
  3210. action.  Your code can ignore this complication.
  3211.  
  3212. Group 1 actions are "meta" - they are outside the game proper, and your
  3213. code is unable to stop them.  (If you want a room where the game can't be
  3214. saved, you'll have to tamper with SaveSub directly.)
  3215.  
  3216. Group 2 actions, by default, actually do something; group 3 actions,
  3217. by default, just reply with a message.
  3218.  
  3219. The routine names are these with "Sub" on the end, such as "SleepSub".
  3220. The action numbers corresponding to them are #a$SleepSub, and so on.
  3221.  
  3222.  
  3223. Although all actions go through a preroutine, not all of them bother
  3224. to check postroutines.  For instance, since the built-in "smell" routine
  3225. just says "You smell nothing out of the ordinary", there would be no
  3226. point calling a postroutine - nothing, after all, has been done.  (These
  3227. are the group 3 actions above.)
  3228.  
  3229. The ones which actually do something, and use postroutines, are:
  3230.  
  3231.   Inv, Take, Drop, Remove, PutOn, Insert, Exit, Go, Look, Examine, Unlock,
  3232.   Lock, SwitchOn, SwitchOff, Open, Close, Disrobe, Wear, Eat, Search.
  3233.  
  3234. (Some other group 2 actions use these postroutines indirectly - if the
  3235. player empties a sack out onto the floor, this is deemed to be dropping
  3236. the objects within, for instance, and if a sack is emptied into a packing
  3237. case this is considered a multiple insertion.)
  3238.  
  3239.  
  3240. Animate objects (such as sea monsters, mad aunts or nasty little dwarves)
  3241. have a "liferoutine".  When this is called, the variable "reason_code"
  3242. holds the reason it was.  This happens for the following reasons:
  3243.  
  3244.    0             The player has asked the creature to do something,
  3245.                  e.g., by "troll, go south".  action, inp1 and inp2 are
  3246.                  set up as usual: e.g. action=#a$GoSub and inp1=s_obj.
  3247.  
  3248.    #a$AttackSub  Player tried to attack creature
  3249.  
  3250.    #a$KissSub    Tried to kiss
  3251.  
  3252.    #a$AnswerSub  The player tried either "answer <word> to troll", or else
  3253.                  "troll, <something not understood>".  In either case
  3254.                  special_word is set to the dictionary entry of the first
  3255.                  word, or 0 if it isn't in the dictionary, and
  3256.                  special_number is set to an attempt to read it as a
  3257.                  number.  (For instance, "computer, 143" will cause
  3258.                  special_number to be set to 143.)
  3259.  
  3260.    #a$AskSub     "ask troll about ..." - similarly special_word and
  3261.                  special_number are set up
  3262.  
  3263.    #a$GiveSub    inp1 holds the object number of what the player has tried
  3264.                  to give (or feed) the creature.  (Unless code is written
  3265.                  the creature will "seem uninterested" and nothing will
  3266.                  happen.)
  3267.  
  3268.    #a$ThrowAtSub inp1 holds whatever the player tried to throw.
  3269.  
  3270. If the routine doesn't exist, or returns false, events will take their
  3271. usual course.
  3272.  
  3273.  
  3274. Quite often you want to simulate the effect of a player typing something.
  3275. For instance, in the Pepper Room the air is full of pepper and every turn
  3276. you sneeze and drop something at random.  If the code to do this simply
  3277. removes an object and puts it on the floor, then it might accidentally
  3278. provide a solution to the problem "the toffee apple sticks to the hands".
  3279.  
  3280. So a routine Process is provided, as in:
  3281.  
  3282.   print "You sneeze convulsively, and lose your grip on ";
  3283.   DefArt(obj); print "...^"; Process(obj, 0, #a$DropSub);
  3284.  
  3285. Formally, Process executes the third-named action, with arguments
  3286. (inp1 and inp2) being the first and second.  0 is given for inp2 here
  3287. because Drop doesn't have a second argument.
  3288.  
  3289.  
  3290. DefArt(obj) is a useful little routine which prints the name of the
  3291. object, with its definite article attached.  This causes, for example,
  3292.  
  3293.   the platinum bar
  3294.   Aunt Jemima
  3295.   Elbereth
  3296.  
  3297. (notice that proper names do not have "the" printed in front of them).
  3298. Similarly, CDefArt(obj) prints the same but with a capital letter at
  3299. the front, e.g.
  3300.  
  3301.   The platinum bar
  3302.   The marbles
  3303.  
  3304. and IndefArt(obj) with the indefinite article:
  3305.  
  3306.   a platinum bar
  3307.   an orange balloon
  3308.   your Aunt Jemima
  3309.   some bundles of reeds
  3310.   far too many marbles
  3311.  
  3312. Another useful routine is DescribeObj(obj), which produces a more complete
  3313. description:
  3314.  
  3315.   an electric torch (providing light)
  3316.   a rucksack (which is open and contains a scarlet fish)
  3317.  
  3318.  
  3319. Time now to detail how to make objects and places in this universe.  The
  3320. library sets up (and uses) the following attributes:
  3321.  
  3322.       light            gives off light
  3323.       concealed        invisible, but touchable
  3324.       worn             currently worn clothing
  3325.       clothing         can be clothing
  3326.       animate          is a creature of some kind
  3327.       female           gender female (otherwise male) - used for eg "her"
  3328.       proper           short name is proper noun
  3329.       moved            has been picked up at some time
  3330.       portal           is a doorway of some kind
  3331.       container        can contain things (eg, a bottle)
  3332.       supporter        can support things (eg, a table)
  3333.       interior         container with interior invisible when closed
  3334.       open             container or doorway which is open
  3335.       openable         container or doorway open/closeable to player
  3336.       workflag         (flag used by parser)
  3337.       enterable        can be entered (eg, car or fireplace)
  3338.       scenery          not described by looks, or moveable (eg, rock face)
  3339.       static           immovably fixed in place (eg, Y2 rock)
  3340.       direction        (is one of the compass directions)
  3341.       lockable         can be locked or unlocked (with suitable key)
  3342.       locked           is presently locked
  3343.       switchable       can be switched on and off
  3344.       on               is presently switched on
  3345.       edible           can be eaten
  3346.       autosearch       examining this object causes it also to be searched
  3347.       scored           award points for first taking
  3348.       talkable         is not an animate creature, but can nevertheless
  3349.                        be talked to (eg, a microphone)
  3350.       general          general-purpose flag
  3351.  
  3352. "general" is free for the user (as are the remaining spare attributes) and
  3353. usually means "the puzzle associated with this object has been solved".
  3354.  
  3355. Most of the above attributes make no sense for locations.  The attributes
  3356. applying to them are:
  3357.  
  3358.       light            there's ambient light
  3359.       visited          place has been visited at some time
  3360.       scored           award points for first visit
  3361.  
  3362. (If you simply never want to have darkness, a sneaky way of doing it is to
  3363. give the player object the light attribute, by tampering with its definition
  3364. in the Parser header file.)
  3365.  
  3366. Here are the properties defined and used by the library:
  3367.  
  3368.                   Default value    Use
  3369.                     if not 0
  3370.       name (*)                     dictionary words referring to an
  3371.                                    object, or dictionary words which
  3372.                                    refer to "irrelevant" things in a room
  3373.  
  3374.       longdesc                     long description of a room, or the
  3375.                                    examine description of an object
  3376.       article       "a"            indefinite article for object
  3377.  
  3378.       initpos                      initial description of an object not yet
  3379.                                    picked up (eg, "A flower grows here.")
  3380.  
  3381.       preroutine    $ffff          see above
  3382.       postroutine   $ffff
  3383.       liferoutine   $ffff          (only relevant for animate objects)
  3384.  
  3385.       n_to   s_to  (**)            map connections from one room to another
  3386.       e_to   w_to
  3387.       ne_to  se_to
  3388.       nw_to  sw_to
  3389.       u_to   d_to
  3390.  
  3391.       portalto                     place that a "portal" connects to
  3392.       dirprop                      direction which goes through it
  3393.  
  3394.       closedpos                    description of a portal which is closed
  3395.                                    (the initpos is used when it is open),
  3396.                                    or description of something switchable
  3397.                                    which is off (initpos used when it's on)
  3398.  
  3399.       timeleft                     useful for timed events
  3400.  
  3401.       with_key                     key object which must be held for a
  3402.                                    lockable object to be locked or unlocked
  3403.  
  3404.       cantgo        "You can't go that way."
  3405.                                    printed when player tries to go an
  3406.                                    impossible way from a location
  3407.  
  3408.       capacity      100            maximum number of things a container
  3409.                                    or supporter can contain or support
  3410.  
  3411. (*) name is a property actually defined in the syntax of Inform itself.
  3412. But this is the use to which it is put by the library routines.
  3413.  
  3414. (**) warning: do not confuse these with the direction objects n_obj,
  3415. s_obj... which are what inp1, inp2 etc would be set to in a command
  3416. mentioning a direction (such as "push the car north").
  3417.  
  3418. You cannot be both a container and a supporter.
  3419.  
  3420. For example, let us look at the object definitions needed to make a
  3421. locked door, which needs a key.
  3422.  
  3423. >   Object broken "Broken Passage" nothing
  3424. >     with longdesc "You are in a dirty broken passage...",
  3425. >     e_to cave, n_to door, s_to yriver, u_to view;
  3426.  
  3427. >   Object door "iron door" broken
  3428. >     with name "iron" "door",
  3429. >          initpos "In the north wall is an open iron door.",
  3430. >          closedpos "In the north wall is a shut iron door.",
  3431. >          portalto  ledge,
  3432. >          dirprop   n_to,
  3433. >          with_key  key
  3434. >     has  portal static openable lockable locked;
  3435.  
  3436. >   Object ledge "Canyon Ledge" nothing
  3437. >     with longdesc "The door opened out onto a tiny ledge...",
  3438. >          s_to broken
  3439. >     has  light scored;
  3440.  
  3441. Note that the map connection north from the broken passage is to the door,
  3442. not to a location.  The door has two different descriptions according to
  3443. whether it is opened or closed.  It is a portal to the ledge, and the
  3444. direction which it goes in is north.  (This is set so that "enter door"
  3445. can be translated into "go north".)  It needs the key to be unlocked,
  3446. but can then freely be opened.  Finally, it's static - you can't walk off
  3447. with it.
  3448.  
  3449. You get 5 points for getting through.  Once there, the ledge goes south
  3450. straight back to the broken passage.  (Doors which can be locked, opened
  3451. etc. on both sides have to be implemented with two objects, one each side.)
  3452.  
  3453. With these definitions, no actual code is needed at all.
  3454.  
  3455. Another brief example:
  3456.  
  3457. >   Object searchlight "Gotham City searchlight" cave
  3458. >     with name "search" "light" "template", article "the",
  3459. >          longdesc "It has some kind of template on it.",
  3460. >          initpos "The old city searchlight shines out a bat against \
  3461. >              the feather-clouds of the darkening sky.",
  3462. >          closedpos "The old city searchlight, neglected but still \
  3463. >              functional, sits here."
  3464. >     has  switchable static;
  3465.  
  3466.  
  3467. The library won't allow the player to carry an indefinite number of
  3468. objects: the limit allowed is the constant MAX_CARRIED, which you
  3469. may define if you wish.  (If you don't define it, it's 100, which
  3470. roughly removes the rule.)
  3471.  
  3472. If you define SACK_OBJECT to be some container, then the player will
  3473. automatically put old, least-used objects away in it as the game
  3474. progresses.  (If not, nothing happens.)
  3475.  
  3476.  
  3477. The other constants you are allowed to define help the score routines
  3478. along.  These are:
  3479.  
  3480.    MAX_SCORE     The maximum game score (default 0)
  3481.    NUMBER_TASKS  Number of individual "tasks" to perform (0)
  3482.    OBJECT_SCORE  Bonus for picking up a "scored" object (4)
  3483.    ROOM_SCORE    Bonus for entering a "scored" room (5)
  3484.  
  3485. and then the individual tasks have scores, as follows:
  3486.  
  3487.    Global task_scores initial t1 t2 ... tn;
  3488.  
  3489. Within your code, when a player achieves something, call Achieved(task)
  3490. to mark that the task has been completed.  It will only award points if
  3491. this task has not been completed before.
  3492.  
  3493.  
  3494. The library maintains light by itself.  It will cope, for instance, with
  3495. what happens if a dwarf picks up the light source and walks away, or if
  3496. the light source is shut up in an opaque box.  The program can give
  3497. or take away the light attribute to anything, or move anything anywhere,
  3498. without having to think about whether or not this makes the room dark.
  3499.  
  3500.  
  3501. If you're writing a game with time instead of score/turns on the
  3502. status line, you can set the time by
  3503.  
  3504.    SetTime( hours*60+minutes, rate);
  3505.  
  3506. where rate=0 means the time is left alone, and if rate>0 that many
  3507. minutes pass every action, whereas if rate<0 that many actions pass
  3508. for every minute.
  3509.  
  3510. Setting the_time tells the library that the game is a "time" rather than
  3511. "score" game.  Remember to call this in Initialise().
  3512.  
  3513.  
  3514. Finally, you might want the parser to know about plural nouns.  Many
  3515. games involve collecting a number of similar items, say a set of nine
  3516. crowns in different colours.  Then you'd want the parser to recognise
  3517. things like
  3518.  
  3519.    > drop all of the crowns except green
  3520.  
  3521. for instance.  It can do this, provided it's told that "crowns" is the
  3522. plural of crown, and provided it's told how to recognise a crown when
  3523. it sees one.
  3524.  
  3525. You need not declare any, but are allowed up to three such plurals, declared
  3526. in your Initialise() routine by lines like:
  3527.  
  3528. >   plural_word1 = #n$crowns; plural_filter1 = is_crown;
  3529.  
  3530. (and so on, for 2 and 3).  You must already have declared is_crown as
  3531. an Attribute, and flagged all the crowns with this attribute.  (#n$crowns
  3532. is a construction which puts the word "crowns" into the dictionary.)
  3533.  
  3534.  
  3535. Eventually, you will want to tamper with the library routines.  But they're
  3536. more flexible than they look, and you can put the evil day off for a very
  3537. long time.
  3538.  
  3539.  
  3540. ---------------------------------------------------------------------------
  3541. C4.  A shell game to build on
  3542. ---------------------------------------------------------------------------
  3543.  
  3544.  
  3545. The shell below is the minimum you need to write to use the library
  3546. routines.  Note that the order in which things occur is quite important.
  3547. Nothing should appear above the #include "Parser" line except possibly
  3548. more defined constants and any abbreviations.  Task_scores must be defined
  3549. in between the two inclusions; nothing else should be.  The grammar table
  3550. should be last.
  3551.  
  3552. It's good form to put the objects all together, before the code, and then
  3553. to define all your own global variables, and then to reach the routines.
  3554.  
  3555. >   !
  3556. >   ! Shell of a game
  3557. >   !
  3558. >   
  3559. >   Constant Story "SHELL";
  3560. >   Constant Headline "^An Interactive Skeleton^\
  3561. >                Copyright (c) 1993 by (your name here).^";
  3562. >   
  3563. >   Release 1;
  3564. >   Statusline score;
  3565. >   
  3566. >   #include "Parser";
  3567. >
  3568. >   Global task_scores initial 0;
  3569. >
  3570. >   #include "VerbLib";
  3571. >   
  3572. >   Object room "Blank Room" nothing
  3573. >     with longdesc "An empty room."
  3574. >     has  light;
  3575. >   
  3576. >   [ Initialise;
  3577. >     location=room;
  3578. >     print "^^^^^Welcome to the shell...^^";
  3579. >   ];
  3580. >   
  3581. >   [ PrintRank;
  3582. >     print ", earning you the rank of ";
  3583. >     print_ret "vacancy.";
  3584. >   ];
  3585. >   
  3586. >   #include "Grammar";
  3587. >   end;
  3588.  
  3589. (Actually, the Release and Statusline directives were redundant (1 and
  3590. score being the default settings anyway) but it's good form to include
  3591. them.)
  3592.  
  3593.  
  3594. ---------------------------------------------------------------------------
  3595.     Graham Nelson,            gan10@uk.ac.cam.phx  or  phx.cam.ac.uk
  3596.     Magdalen College,         nelson@uk.ac.ox.vax  or  vax.ox.ac.uk
  3597.     Oxford OX1 4AU,
  3598.     UK.                       18th April 1993
  3599.                               and 16th May 1993
  3600.                               and 14th November 1993
  3601. ---------------------------------------------------------------------------
  3602.