-
Notifications
You must be signed in to change notification settings - Fork 5
/
advsys.doc
1188 lines (532 loc) · 28.7 KB
/
advsys.doc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
ADVSYS - An Adventure Writing System
Version 1.2
by David Betz
18 Garrison Drive
Bedford, NH 03110
(603) 472-2389 (home)
July 14, 1986
Copyright (c) 1986, by David Betz
All Rights Reserved
Permission is hereby granted for unrestricted non-commercial use
ADVSYS An Adventure Writing System Page 2
INTRODUCTION
ADVSYS is a special purpose programming language that was
specifically designed to be used to write computer text
adventure games. It includes a facility for defining the kinds
of objects that are common in adventures. Some objects
represent locations on the game map, some objects represent
things that the player can find while exploring the adventure
world, and some objects represent other characters that the
adventurer can encounter during his or her journeys. The
adventure language also provides a facility to define actions.
Actions are short sections of code that determine what happens
in response to a command from the player. These two concepts,
"objects" and "actions" form the basis for the adventure
language.
ACKNOWLEDGEMENTS
Although I have written all of the code associated with this
adventure writing system, I must acknowledge the assistance of
one individual without whom this project would probably never
have reached completion. That person is Gary McGath. Gary was
interested in writing a commercial quality adventure game and I
convinced him to write it using my system (which was as yet
almost completely unspecified) instead of using a traditional
programming language. The input that Gary provided during the
development of his game contributed significantly to the overall
design of the system. I would like to thank Gary for that
contribution.
ADVSYS An Adventure Writing System Page 3
USING THE SYSTEM TO WRITE AN ADVENTURE
In order to write an adventure using this system, you need to
write an adventure description. This is an ordinary ASCII text
file containing definitions for all of the objects and actions
in your adventure game. This file is used as input to the
adventure compiler. The compiler takes the adventure
description and compiles it into a set of data structures.
In order to play an adventure written using this system, you
need the data structure file that was produced by the compiler
and the adventure interpreter program. The interpreter uses the
information produced by the adventure compiler to allow a player
to play the adventure game. Notice that it is not necessary for
the player to have access to the original adventure description
file. All of the information that is necessary to play the
adventure game is contained within the data structure file that
is produced by the compiler. This file is a binary file that
cannot be simply "listed" to reveal the internal workings of the
adventure.
The adventure compiler is called ADVCOM and the interpreter is
called ADVINT. These two programs in conjunction with this
documentation are all that is required to write and play
adventure games using this system.
ADVSYS An Adventure Writing System Page 4
RUNNING THE COMPILER
If you have created an adventure definition file called
"MYADV.ADV", you can compile it with the command:
A>advcom myadv
Typing this command will invoke the adventure compiler and cause
it to compile the file named "MYADV.ADV". The ".ADV" extension
is added to the file name by the compiler. During the process
of compiling the file, many messages will be printed telling
about the progress of the compiler. At the end of the
compilation process, the compiler prints a set of statistics
describing the resulting data structure file. This file will be
called "MYADV.DAT". It contains the data structures needed by
the adventure interpreter to allow a player to play the
adventure game.
Note: The "A>" in the line above is the MS-DOS prompt and should
not be typed as part of the command.
RUNNING THE INTERPRETER
Assuming that you have a compiled adventure data file called
"MYADV.DAT", you can play the adventure by typing the command:
A>advint myadv
This command will start the adventure. There will probably be
some text printed at this point describing the adventure and the
initial situation. You will then be prompted to type a command.
The prompt is the colon character. The format for commands is
described under the section about the parser. After typing a
command, you will be told what happened as a result of your
command, your new situation will be described and you will begin
the loop again.
ADVSYS An Adventure Writing System Page 5
ADVENTURE DESCRIPTION FILE FORMAT
All adventure description files contain a collection of
statements. These statements must be formed according to
the following rules:
The adventure definition statement:
All adventure definitions should have an ADVENTURE
statement. This statement gives the name of the adventure
and the version number of the definition file. Each
adventure should have a unique name. This name is used to
identify "saved position" files and insure that only files
that correspond to the current adventure are restored. The
version number allows the author to have many versions of
the same adventure during development and guarantee that
"save" files from one version aren't restored into another
version.
(ADVENTURE name version)
Example:
(ADVENTURE sample 1)
Vocabulary statements:
These statements add words to the adventure vocabulary.
(ADJECTIVE word*)
(PREPOSITION word*)
(CONJUNCTION word*)
(ARTICLE word*)
(SYNONYM word synonym*)
Examples:
(ADJECTIVE red blue)
(CONJUNCTION and)
(SYNONYM big large)
Note:
Words are also added to the vocabulary by the object
and action definitions using the NOUN, ADJECTIVE, VERB
and PREPOSITION statements.
ADVSYS An Adventure Writing System Page 6
Constant definition statement:
(DEFINE name value)
Examples:
(DEFINE what "I don't understand what you're saying!\n")
(DEFINE max-load 100)
Function definition statement:
(DEFINE (function-name [arg-name]* [&aux tmp-name*]) expr*)
Example:
(DEFINE (factorial n)
(IF (< n 2)
1
(* n (factorial (- n 1)))))
Variable definition statement:
(VARIABLE variable-name*)
Example:
(VARIABLE score i j)
Property name definition statement:
(PROPERTY property-name*)
Example:
(PROPERTY weight value)
ADVSYS An Adventure Writing System Page 7
Comments:
Comments begin with a semi-colon and end with the end of the
line.
Example:
; this is a comment
Include files:
Any line that begins with a "@" causes the inclusion of
another file. The file name immediately follows the at-sign
and extends to the end of the line. Only one level of
include is supported.
Example:
@basic.adv
ADVSYS An Adventure Writing System Page 8
Handler definition statements:
(INIT expr*)
(UPDATE expr*)
(BEFORE expr*)
(AFTER expr*)
(ERROR expr*)
Example:
(INIT
(print "Welcome to the sample adventure!\n"))
Handlers:
All activity within an adventure game is controlled by a
built-in handler loop. Each of the handlers in the loop
contains code that is provided by the adventure author. The
sequencing from handler to handler is provided by the
adventure system itself.
The first handler that is called in an adventure game is the
INIT handler. It prints some sort of introductory text and
initializes all global variables in order to start the
adventure game.
After the INIT handler has completed, the normal loop is
entered. It starts with the UPDATE handler. The UPDATE
handler prepares for the player's next turn. It should
describe the player's location if it has changed since the
last turn. After the UPDATE handler completes, the parser
is called. It prompts the player for a command, parses the
command, sets the built-in parser varaibles and exits. Then
the BEFORE handler is called. It is called before the
action associated with the command to allow the adventure
author to inspect the parser variables before proceeding to
the action itself. After the BEFORE handler completes, the
action itself is called (or whatever action is stored in the
built-in variable $ACTION when the BEFORE handler
completes). When the action completes, the AFTER handler is
called to give the author a chance to handle events that
happen only at the end of a successful turn. The ERROR
handler is called when the parser detects an error.
ADVSYS An Adventure Writing System Page 9
The handler loop:
INIT
|
v
UPDATE<----------+
| |
v |
parse--->ERROR---+
| |
v |
BEFORE |
| |
v |
action |
| |
v |
AFTER------------+
ADVSYS An Adventure Writing System Page 10
The parser:
The parser handles all commands from the player. It prompts
the player when it is ready for a new command. The prompt
is the colon character. When the player has typed a
command, the parser breaks the command into phrases. The
parser recognizes the following command forms:
[actor,] verb
[actor,] verb dobjects
[actor,] verb dobjects preposition iobject
[actor,] verb iobject dobjects
Where:
actor ==> a noun phrase
verb ==> the verb phrase (1 or 2 words)
dobjects ==> dobject [conjunction dobject]*
dobject ==> a noun phrase
preposition ==> a preposition
iobject ==> a noun phrase
noun phrase ==> [article] [adjective]* noun
Examples:
Look
Take the red magic sword
Take the red sword and the blue bottle
Give the troll the red sword
Give the red sword to the troll
Troll, give me the sword
Notes:
Square brackets enclose optional phrases. An asterisk
indicates zero or more of the preceeding element.
The fourth form above is treated as if the player had
typed:
[actor,] verb dobject "to" iobject
Once the parser has broken the command into phrases, it
assigns each noun phrase a number. It stores the number of
the actor noun phrase in the built-in variable $ACTOR. It
stores the first direct object noun phrase number in the
variable $DOBJECT. It stores the number of direct objects
in the variable $NDOBJECTS. It stores the indirect object
noun phrase number in the variable $IOBJECT. If any of the
noun phrases is missing from the command, the corresponding
variable is set to NIL. The parser saves the verb phrase
and preposition to use when determining which action to use
to handle the command.
ADVSYS An Adventure Writing System Page 11
Action definition statement:
Actions are used to handle player commands. Each time the
parser finishes parsing a new command, it uses the verb
phrase and the preposition to locate an action to handle the
command. Each action specifies a kind of template that must
match the command in order for the action to be called. The
template consists of the words used in the verb phrase and
preposition and the existance of the actor, direct object
and indirect object noun phrases. Once the parser finds an
action that matches the command, it stores the action in the
built-in variable $ACTION and exits.
(ACTION action-name astat*)
astat:
(ACTOR [flag])
(VERB verb*)
(DIRECT-OBJECT [flag])
(PREPOSITION word*)
(INDIRECT-OBJECT [flag])
flag:
REQUIRED must have the corresponding np
OPTIONAL may have the corresponding np
FORBIDDEN must not have the corresponding np
verb:
word
(word word)
Example:
(ACTION take
(VERB take (pick up))
(DIRECT-OBJECT)
(CODE
(print "You can't take the ")
(print-noun $dobject)
(print "!\n")))
If the ACTOR, DIRECT-OBJECT or INDIRECT-OBJECT statements
are left out entirely, the settings of the corresponding
flags are taken from the action default definitions. If
there is no action default definition, the value FORBIDDEN
is assumed. If any of these statements is present, but no
flag is specified, it is treated as if the flag REQUIRED was
specified.
ADVSYS An Adventure Writing System Page 12
Action default definition statement:
This statement defines default values for the ACTOR, DIRECT-
OBJECT and INDIRECT-OBJECT flags.
(DEFAULT dstat*)
dstat:
(ACTOR [flag])
(DIRECT-OBJECT [flag])
(INDIRECT-OBJECT [flag])
flag:
REQUIRED
OPTIONAL
FORBIDDEN
Example:
(DEFAULT
(ACTOR OPTIONAL))
ADVSYS An Adventure Writing System Page 13
Object definition statements:
The object definition statements are used to define
individual objects and classes of objects. The most basic
way of defining an object is using the (OBJECT ...)
statement. This defines an object which has no parent
class.
It is also possible to create a class of objects that share
information. A class is defined just like a normal object.
It is given nouns, adjectives and properties. In addition,
a class may have class properties. These are properties
that are shared amongst all instances of the class. In
order to create an instance of a class, the (class-name ...)
form is used. This creates an instance of the named class.
An instance will inherit all nouns and adjectives from its
parent class. It will also inherit all class properties
defined in the parent (and its parents). Any normal
properties defined in the parent class will be copied to the
new object. The copies will have the same values that the
parent has, but it is possible for the instance to have
property definitions that override these values. Instances
may also have additional nouns, adjectives and properties.
(OBJECT object-name ostat*)
(class-name object-name ostat*)
ostat:
(NOUN word*)
(ADJECTIVE word*)
(PROPERTY [property-name value]*)
(CLASS-PROPERTY [property-name value]*)
(METHOD (selector [arg-name]* [&aux tmp-name*])
expr*)
class-name:
the name of a previously defined object
Examples:
(OBJECT sword
(NOUN sword weapon)
(CLASS-PROPERTY
is-weapon T)
(PROPERTY
weight 10
value 5
damage 20))
(sword red-sword
(ADJECTIVE red)
(PROPERTY
damage 25))
ADVSYS An Adventure Writing System Page 14
Expressions:
(+ expr expr) add
(- expr expr) subtract
(* expr expr) multiply
(/ expr expr) divide
(% expr expr) remainder
(& expr expr) bit-wise and
(| expr expr) bit-wise or
(~ expr) bit-wise complement
These arithmetic functions operate on integers. As it turns
out, every data type in the system is represented by an
integer, so these functions will work with any type of
arguments. They are probably only useful with integers,
however.
(RANDOMIZE) reset the random number generator
(RAND expr) generate a random number
These functions enable the generation of pseudo-random
numbers. The (RAND n) function takes a single argument and
generates a random number between zero and n-1. (RANDOMIZE)
resets the seed used by the random number function so that
each invocation of a program results in a new sequence of
random numbers.
(AND expr*) logical and (short circuits)
(OR expr*) logical or (short circuits)
(NOT expr) logical not
These functions operate on logical values. In this system,
any value that is not equal to NIL (or zero) is considered
true. NIL and zero are considered false. AND and OR
evaluate their arguments from left to right and stop as soon
as the value of the entire expression can be determined. In
other words, AND stops when it encounters a false value, OR
stops when it encounters a true value.
(< expr expr) less than
(= expr expr) equal to
(> expr expr) greater than
These functions compare integers. They cannot be used to
compare strings.
ADVSYS An Adventure Writing System Page 15
(GETP obj property-name) get the value of a property
(SETP obj property-name value) set the value of a property
These functions manipulate object properties. They are used
to find the value of a property or to set the value of a
property. They will also find and set the values of
inherited properties. If GETP is used to find the value of
a property that doesn't exist for the specified object, NIL
is returned. If SETP is used to set the value of a property
that doesn't exist, the operation is ignored.
(CLASS obj)
This function returns the class of an object. If the object
was defined with an (OBJECT ...) statement, NIL will be
returned. If the object was defined with the (class-name
...) statement, the class object will be returned.
(MATCH obj noun-phrase-number)
This function matches an object with a noun phrase. An
object matches a noun phrase if it includes all of the
adjectives specified in the noun phrase and also includes
the noun mentioned. Both nouns and adjectives can be
inherited.
(YES-OR-NO) get a yes or no answer from the player
This function waits for the player to type a line. If the
line begins with a 'Y' or a 'y', the function returns T. If
the line begins with anything else, the function returns
NIL.
(PRINT expr) print a string
(PRINT-NUMBER expr) print a number
(PRINT-NOUN noun-phrase-number) print a noun phrase
(TERPRI) terminate the print line
These functions perform various sorts of output. PRINT
prints strings, PRINT-NUMBER prints numbers and PRINT-NOUN
prints a noun phrase.
(FINISH) exit and continue with the AFTER handler
(CHAIN) exit and continue with the next handler
(ABORT) exit and continue with the UPDATE handler
(RESTART) exit and restart the current game
(EXIT) exit to the operating system
These functions cause the immediate termination of the
current handler. FINISH causes execution to proceed with
the AFTER handler, CHAIN causes execution to proceed with
the next handler in the normal sequence, ABORT causes
execution to proceed with the UPDATE handler (effectively
aborting the current turn), RESTART restores the game to its
ADVSYS An Adventure Writing System Page 16
original state and starts over with the INIT handler and
EXIT causes an immediate exit back to the operating system.
(SAVE) save the current game position