-
Notifications
You must be signed in to change notification settings - Fork 1
/
adv.t
5936 lines (5607 loc) · 177 KB
/
adv.t
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
/* Copyright (c) 1988-2000 by Michael J. Roberts. All Rights Reserved. */
/*
adv.t - standard adventure definitions for TADS games
Version 2.5.17
This file is part of TADS: The Text Adventure Development System.
Please see the file LICENSE.TAD (which should be part of the TADS
distribution) for information on copying and using TADS.
You may modify and use this file in any way you want, provided that
if you redistribute modified copies of this file in source form, the
copies must include the original copyright notice (including this
paragraph), and must be clearly marked as modified from the original
version.
This file defines the basic classes and functions used by most TADS
adventure games. It is generally #include'd at the start of each game
source file.
*/
/* parse adv.t using normal TADS operators */
#pragma C-
/* ------------------------------------------------------------------------ */
/*
* Constants for parser status codes. These codes are passed to
* parseError and parseErrorParam to indicate which message these
* routines should display. In addition, these codes are returned by
* parserResolveObjects.
*/
#define PRS_SUCCESS 0 /* success */
#define PRSERR_BAD_PUNCT 1 /* I don't understand the punctuation */
#define PRSERR_UNK_WORD 2 /* I don't know the word */
#define PRSERR_TOO_MANY_OBJS 3 /* The word refers to too many objects */
#define PRSERR_ALL_OF 4 /* You left something out after "all of" */
#define PRSERR_BOTH_OF 5 /* You left something out after "both of" */
#define PRSERR_OF_NOUN 6 /* Expected a noun after "of" */
#define PRSERR_ART_NOUN 7 /* An article must be followed by a noun */
#define PRSERR_DONT_SEE_ANY 9 /* I don't see any %s here */
#define PRSERR_TOO_MANY_OBJS2 10 /* Referring to too many objects with %s */
#define PRSERR_TOO_MANY_OBJS3 11 /* Referring to too many objects */
#define PRSERR_ONE_ACTOR 12 /* You can only speak to one person */
#define PRSERR_DONT_KNOW_REF 13 /* Don't know what you're referring to */
#define PRSERR_DONT_KNOW_REF2 14 /* Don't know what you're referring to */
#define PRSERR_DONT_SEE_REF 15 /* Don't see what you're referring to */
#define PRSERR_DONT_SEE_ANY2 16 /* You don't see any %s here */
#define PRSERR_NO_MULTI_IO 25 /* can't use multiple indirect objects */
#define PRSERR_NO_AGAIN 26 /* There's no command to repeat */
#define PRSERR_BAD_AGAIN 27 /* You can't repeat that command */
#define PRSERR_NO_MULTI 28 /* can't use multiple objects w/this cmd */
#define PRSERR_ANY_OF 29 /* You left something out after "any of" */
#define PRSERR_ONLY_SEE 30 /* I only see %d of those */
#define PRSERR_CANT_TALK 31 /* You can't talk to that */
#define PRSERR_INT_PPC_INV 32 /* internal: invalid preparseCmd list */
#define PRSERR_INT_PPC_LONG 33 /* internal: preparseCmd command too long */
#define PRSERR_INT_PPC_LOOP 34 /* internal: preparseCmd loop */
#define PRSERR_DONT_SEE_ANY_MORE 38 /* You don't see that here any more */
#define PRSERR_DONT_SEE_THAT 39 /* You don't see that here */
#define PRSERR_NO_NEW_NUM 40 /* can't create new numbered object */
#define PRSERR_BAD_DIS_STAT 41 /* invalid status from disambigXobj */
#define PRSERR_EMPTY_DISAMBIG 42 /* empty response to disambig query */
#define PRSERR_DISAMBIG_RETRY 43 /* retry object disambig response as cmd */
#define PRSERR_AMBIGUOUS 44 /* objects still ambiguous */
#define PRSERR_OOPS_UPDATE 45 /* command corrected by "oops" */
#define PRSERR_TRY_AGAIN 100 /* Let's try it again... */
#define PRSERR_WHICH_PFX 101 /* Which %s do you mean... */
#define PRSERR_WHICH_COMMA 102 /* (comma) */
#define PRSERR_WHICH_OR 103 /* ...or... */
#define PRSERR_WHICH_QUESTION 104 /* (question mark) */
#define PRSERR_DONTKNOW_PFX 110 /* I don't know how to... */
#define PRSERR_DONTKNOW_SPC 111 /* (space) */
#define PRSERR_DONTKNOW_ANY 112 /* ...anything */
#define PRSERR_DONTKNOW_TO 113 /* ...to... */
#define PRSERR_DONTKNOW_SPC2 114 /* (space) */
#define PRSERR_DONTKNOW_END 115 /* (period) */
#define PRSERR_MULTI 120 /* (colon) for multiple-object prefix */
#define PRSERR_ASSUME_OPEN 130 /* (open paren) for defaulted objects */
#define PRSERR_ASSUME_CLOSE 131 /* (close paren) */
#define PRSERR_ASSUME_SPC 132 /* (space) */
#define PRSERR_WHAT_PFX 140 /* What do you want to... */
#define PRSERR_WHAT_IT 141 /* ...it... */
#define PRSERR_WHAT_TO 142 /* ...to... */
#define PRSERR_WHAT_END 143 /* (question mark) */
#define PRSERR_WHAT_THEM 144 /* ...them... */
#define PRSERR_WHAT_HIM 145 /* ...him... */
#define PRSERR_WHAT_HER 146 /* ...her... */
#define PRSERR_WHAT_THEM2 147 /* ...them... */
#define PRSERR_WHAT_PFX2 148 /* What do you want... */
#define PRSERR_WHAT_TOSPC 149 /* ...to... */
#define PRSERR_MORE_SPECIFIC 160 /* you'll have to be more specific */
#define PRSERR_NOREACH_MULTI 200 /* (colon) for prefixing unreachables */
/* ------------------------------------------------------------------------ */
/*
* constants for the event codes returned by the inputevent() intrinsic
* function
*/
#define INPUT_EVENT_KEY 1
#define INPUT_EVENT_TIMEOUT 2
#define INPUT_EVENT_HREF 3
#define INPUT_EVENT_NOTIMEOUT 4
#define INPUT_EVENT_EOF 5
/*
* constants for inputdialog()
*/
#define INDLG_OK 1
#define INDLG_OKCANCEL 2
#define INDLG_YESNO 3
#define INDLG_YESNOCANCEL 4
#define INDLG_ICON_NONE 0
#define INDLG_ICON_WARNING 1
#define INDLG_ICON_INFO 2
#define INDLG_ICON_QUESTION 3
#define INDLG_ICON_ERROR 4
#define INDLG_LBL_OK 1
#define INDLG_LBL_CANCEL 2
#define INDLG_LBL_YES 3
#define INDLG_LBL_NO 4
/*
* constants for gettime() type codes
*/
#define GETTIME_DATE_AND_TIME 1
#define GETTIME_TICKS 2
/*
* constants for askfile() prompt type codes
*/
#define ASKFILE_PROMPT_OPEN 1 /* open an existing file for reading */
#define ASKFILE_PROMPT_SAVE 2 /* save to the file */
/*
* constants for askfile() flags
*/
#define ASKFILE_EXT_RESULT 1 /* extended result codes */
/*
* askfile() return codes - these are returned in the first element of
* the list returned from askfile() when ASKFILE_EXT_RESULT is used in
* the 'flags' parameter
*/
#define ASKFILE_SUCCESS 0 /* success - 2nd list element is filename */
#define ASKFILE_FAILURE 1 /* an error occurred asking for a file */
#define ASKFILE_CANCEL 2 /* player canceled the file selector */
/*
* constants for askfile() file type codes
*/
#define FILE_TYPE_GAME 0 /* a game data file (.gam) */
#define FILE_TYPE_SAVE 1 /* a saved game (.sav) */
#define FILE_TYPE_LOG 2 /* a transcript (log) file */
#define FILE_TYPE_DATA 4 /* general data file (used for fopen()) */
#define FILE_TYPE_CMD 5 /* command input file */
#define FILE_TYPE_TEXT 7 /* text file */
#define FILE_TYPE_BIN 8 /* binary data file */
#define FILE_TYPE_UNKNOWN 11 /* unknown file type */
/*
* constants for execCommand() flags
*/
#define EC_HIDE_SUCCESS 1 /* hide success messages */
#define EC_HIDE_ERROR 2 /* hide error messages */
#define EC_SKIP_VALIDDO 4 /* skip direct object validation */
#define EC_SKIP_VALIDIO 8 /* skip indirect object validation */
/*
* constants for execCommand() return codes
*/
#define EC_SUCCESS 0 /* successful completion */
#define EC_EXIT 1013 /* "exit" executed */
#define EC_ABORT 1014 /* "abort" executed */
#define EC_ASKDO 1015 /* "askdo" executed */
#define EC_ASKIO 1016 /* "askio" executed */
#define EC_EXITOBJ 1019 /* "exitobj" executed */
#define EC_INVAL_SYNTAX 1200 /* invalid sentence structure */
#define EC_VERDO_FAILED 1201 /* verDoVerb failed */
#define EC_VERIO_FAILED 1202 /* verIoVerb failed */
#define EC_NO_VERDO 1203 /* no verDoVerb method defined */
#define EC_NO_VERIO 1204 /* no verIoVerb method defined */
#define EC_INVAL_DOBJ 1205 /* direct object validation failed */
#define EC_INVAL_IOBJ 1206 /* indirect object validation failed */
/*
* constants for parserGetObj object codes
*/
#define PO_ACTOR 1 /* actor */
#define PO_VERB 2 /* deepverb object */
#define PO_DOBJ 3 /* direct object */
#define PO_PREP 4 /* preposition object (introducing indirect object) */
#define PO_IOBJ 5 /* indirect object */
#define PO_IT 6 /* get the "it" object */
#define PO_HIM 7 /* get the "him" object */
#define PO_HER 8 /* get the "her" object */
#define PO_THEM 9 /* get the "them" object */
/*
* constants for parseNounPhrase return codes
*/
#define PNP_ERROR 1 /* noun phrase syntax error */
#define PNP_USE_DEFAULT 2 /* use default processing */
/*
* constants for disambigDobj and disambigIobj status codes
*/
#define DISAMBIG_CONTINUE 1 /* continue disambiguation for this list */
#define DISAMBIG_DONE 2 /* list is fully resolved */
#define DISAMBIG_ERROR 3 /* disambiguation failed; abort command */
#define DISAMBIG_PARSE_RESP 4 /* parse interactive response string */
#define DISAMBIG_PROMPTED 5 /* prompted for response, but didn't read it */
/*
* Parser word types. These values may be combined, since a given word
* may appear in the dictionary with multiple types. To test for a
* particular type, use the bitwise AND operator:
*
* ((typ & PRSTYP_NOUN) != 0).
*/
#define PRSTYP_ARTICLE 1 /* the, a, an */
#define PRSTYP_ADJ 2 /* adjective */
#define PRSTYP_NOUN 4 /* noun */
#define PRSTYP_PREP 8 /* preposition */
#define PRSTYP_VERB 16 /* verb */
#define PRSTYP_SPEC 32 /* special words - "of", ",", ".", etc. */
#define PRSTYP_PLURAL 64 /* plural */
#define PRSTYP_UNKNOWN 128 /* word is not in dictionary */
/*
* Parser noun-phrase flags. These values may be combined; to test for
* a single flag, use the bitwise AND operator:
*
* ((flag & PRSFLG_UNKNOWN) != 0)
*/
#define PRSFLG_ALL 1 /* "all" */
#define PRSFLG_EXCEPT 2 /* "except" or "but" (used in "all except ...") */
#define PRSFLG_IT 4 /* "it" */
#define PRSFLG_THEM 8 /* "them" */
#define PRSFLG_NUM 16 /* a number */
#define PRSFLG_COUNT 32 /* noun phrase uses a count - "3 coins" */
#define PRSFLG_PLURAL 64 /* noun phrase is a plural usage - "the coins" */
#define PRSFLG_ANY 128 /* noun phrase uses "any" - "any coin" */
#define PRSFLG_HIM 256 /* "him" */
#define PRSFLG_HER 512 /* "her" */
#define PRSFLG_STR 1024 /* a quoted string */
#define PRSFLG_UNKNOWN 2048 /* noun phrase contains an unknown word */
#define PRSFLG_ENDADJ 4096 /* noun phrase ends in an adjective */
#define PRSFLG_TRUNC 8192 /* noun phrase uses a truncated word */
/*
* Constants for parserResolveObjects usage codes
*/
#define PRO_RESOLVE_DOBJ 1 /* direct object */
#define PRO_RESOLVE_IOBJ 2 /* indirect object */
#define PRO_RESOLVE_ACTOR 3 /* actor */
/*
* Constants for result codes from restore()
*/
#define RESTORE_SUCCESS 0 /* success */
#define RESTORE_FILE_NOT_FOUND 1 /* file not found */
#define RESTORE_NOT_SAVE_FILE 2 /* not a saved game file */
#define RESTORE_BAD_FMT_VSN 3 /* incompatible file format version */
#define RESTORE_BAD_GAME_VSN 4 /* file saved by another game or version */
#define RESTORE_READ_ERROR 5 /* error reading from the file */
#define RESTORE_NO_PARAM_FILE 6 /* no parameter file for restore(nil) */
/*
* Constants for defined() function. When passed as the optional third
* argument to defined(), these flags specify what type of information
* is returned from defined().
*
* By default, defined(obj, &prop) returns true if the property is
* defined or inherited by the object, nil if not. The DEFINED_ANY flag
* has the same effect.
*
* When DEFINED_DIRECTLY is used, the function returns true only if the
* property is directly defined by the object, not merely inherited from
* a superclass.
*
* When DEFINED_INHERITS is used, the function returns true only if the
* property is inherited from a superclass, and returns nil if the
* property isn't defined at all or is defined directly by the object.
*
* When DEFINED_GET_CLASS is used, the function returns the object that
* actually defines the property; this will be the object itself if the
* object overrides the property, otherwise it will be the superclass
* from which the object inherits the property. The function returns
* nil if the property isn't defined or inherited at all for the object.
*/
#define DEFINED_ANY 1 /* default: property is defined or inherited */
#define DEFINED_DIRECTLY 2 /* defined directly by the object */
#define DEFINED_INHERITS 3 /* inherited, not defined directly */
#define DEFINED_GET_CLASS 4 /* get the defining class */
/*
* Constants for datatype() and proptype()
*/
#define DTY_NUMBER 1 /* number */
#define DTY_OBJECT 2 /* object */
#define DTY_SSTRING 3 /* single-quoted string value */
#define DTY_NIL 5 /* nil */
#define DTY_CODE 6 /* method code */
#define DTY_LIST 7 /* list */
#define DTY_TRUE 8 /* true */
#define DTY_DSTRING 9 /* double-quoted string */
#define DTY_FUNCPTR 10 /* function pointer */
#define DTY_PROP 13 /* property pointer */
/* ------------------------------------------------------------------------ */
/*
* Define compound prepositions. Since prepositions that appear in
* parsed sentences must be single words, we must define any logical
* prepositions that consist of two or more words here. Note that
* only two words can be pasted together at once; to paste more, use
* a second step. For example, 'out from under' must be defined in
* two steps:
*
* compoundWord 'out' 'from' 'outfrom';
* compoundWord 'outfrom' 'under' 'outfromunder';
*
* Listed below are the compound prepositions that were built in to
* version 1.0 of the TADS run-time.
*/
compoundWord 'on' 'to' 'onto'; /* on to --> onto */
compoundWord 'in' 'to' 'into'; /* in to --> into */
compoundWord 'in' 'between' 'inbetween'; /* and so forth */
compoundWord 'down' 'in' 'downin';
compoundWord 'down' 'on' 'downon';
compoundWord 'up' 'on' 'upon';
compoundWord 'out' 'of' 'outof';
compoundWord 'off' 'of' 'offof';
compoundWord 'i' 'wide' 'i_wide';
compoundWord 'invent' 'wide' 'i_wide';
compoundWord 'inventory' 'wide' 'i_wide';
compoundWord 'i' 'tall' 'i_tall';
compoundWord 'invent' 'tall' 'i_tall';
compoundWord 'inventory' 'tall' 'i_tall';
;
/*
* Format strings: these associate keywords with properties. When
* a keyword appears in output between percent signs (%), the matching
* property of the current command's actor is evaluated and substituted
* for the keyword (and the percent signs). For example, if you have:
*
* formatstring 'you' fmtYou;
*
* and the command being processed is:
*
* fred, pick up the paper
*
* and the "fred" actor has fmtYou = "he", and this string is output:
*
* "%You% can't see that here."
*
* Then the actual output is: "He can't see that here."
*
* The format strings are chosen to look like normal output (minus the
* percent signs, of course) when the actor is the player character (Me).
*/
formatstring 'you' fmtYou;
formatstring 'your' fmtYour;
formatstring 'you\'re' fmtYoure;
formatstring 'youm' fmtYoum;
formatstring 'you\'ve' fmtYouve;
formatstring 's' fmtS;
formatstring 'es' fmtEs;
formatstring 'have' fmtHave;
formatstring 'do' fmtDo;
formatstring 'are' fmtAre;
formatstring 'me' fmtMe;
;
/*
* Special Word List: This list defines the special words that the
* parser needs for input commands. If the list is not provided, the
* parser uses the old defaults. The list below is the same as the old
* defaults. Note - the words in this list must appear in the order
* shown below.
*/
specialWords
'of', /* used in phrases such as "piece of paper" */
'and', /* conjunction for noun lists or to separate commands */
'then', /* conjunction to separate commands */
'all' = 'everything', /* refers to every accessible object */
'both', /* used with plurals, or to answer disambiguation questions */
'but' = 'except', /* used to exclude items from ALL */
'one', /* used to answer questions: "the red one" */
'ones', /* likewise for plurals: "the blue ones" */
'it' = 'there', /* refers to last single direct object used */
'them', /* refers to last direct object list */
'him', /* refers to last masculine actor mentioned */
'her', /* refers to last feminine actor mentioned */
'any' = 'either' /* pick object arbitrarily from ambiguous list */
;
/*
* Forward-declare functions. This is not required in most cases,
* but it doesn't hurt. Providing these forward declarations ensures
* that the compiler knows that we want these symbols to refer to
* functions rather than objects.
*/
checkDoor: function;
checkReach: function;
itemcnt: function;
isIndistinguishable: function;
sayPrefixCount: function;
listcont: function;
nestlistcont: function;
listcontcont: function;
turncount: function;
addweight: function;
addbulk: function;
incscore: function;
darkTravel: function;
scoreRank: function;
terminate: function;
goToSleep: function;
initSearch: function;
reachableList: function;
initRestart: function;
contentsListable: function;
;
/*
* inputline: function
*
* This is a simple cover function for the built-in function input().
* This cover function switches to the 'TADS-Input' font when running in
* HTML mode, so that input explicitly read through this function appears
* in the same input font that is used for normal command-line input.
*/
inputline: function
{
local ret;
local html_mode;
/* note whether we're in HTML mode */
html_mode := (systemInfo(__SYSINFO_SYSINFO) = true
&& systemInfo(__SYSINFO_HTML_MODE));
/* if in HTML mode, switch to TADS-Input font */
if (html_mode)
"<font face='TADS-Input'>";
/* read the input */
ret := input();
/* exit TADS-Input font mode if appropriate */
if (html_mode)
"</font>";
/* return the line of text */
return ret;
}
/*
* _rand: function(x)
*
* This is a modified version of the built-in random number generator, which
* may improve upon the standard random number generator's statistical
* performance in many cases. To use this replacement, simply call _rand
* instead of rand in your code.
*/
_rand: function(x)
{
return (((rand(16*x)-1)/16)+1);
}
/*
* initRestart - flag when a restart has occurred by setting a flag
* in global.
*/
initRestart: function(parm)
{
global.restarting := true;
}
/*
* checkDoor: if the door d is open, this function silently returns
* the room r. Otherwise, print a message ("The door is closed.") and
* return nil.
*/
checkDoor: function(d, r)
{
if (d.isopen)
return r;
else
{
setit(d);
caps(); d.thedesc; " <<d.isdesc>> closed. ";
return nil;
}
}
/*
* checkReach: determines whether the object obj can be reached by
* actor in location loc, using the verb v. This routine returns true
* if obj is a special object (numObj or strObj), if obj is in actor's
* inventory or actor's location, or if it's in the 'reachable' list for
* loc.
*/
checkReach: function(loc, actor, v, obj)
{
if (obj = numObj or obj = strObj)
return;
if (not (actor.isCarrying(obj) or obj.isIn(actor.location)))
{
if (find(loc.reachable, obj) <> nil)
return;
"%You% can't reach "; obj.thedesc; " from "; loc.thedesc; ". ";
exit;
}
}
/*
* isIndistinguishable: function(obj1, obj2)
*
* Returns true if the two objects are indistinguishable for the purposes
* of listing. The two objects are equivalent if they both have the
* isEquivalent property set to true, they both have the same immediate
* superclass, and their other listing properties match (in particular,
* isworn and (islamp and islit) match for both objects).
*/
isIndistinguishable: function(obj1, obj2)
{
return (firstsc(obj1) = firstsc(obj2)
and obj1.isworn = obj2.isworn
and ((obj1.islamp and obj1.islit)
= (obj2.islamp and obj2.islit)));
}
/*
* itemcnt: function(list)
*
* Returns a count of the "listable" objects in list. An
* object is listable (that is, it shows up in a room's description)
* if its isListed property is true. This function is
* useful for determining how many objects (if any) will be listed
* in a room's description. Indistinguishable items are counted as
* a single item (two items are indistinguishable if they both have
* the same immediate superclass, and their isEquivalent properties
* are both true.
*/
itemcnt: function(list)
{
local cnt, tot, i, obj, j;
tot := length(list);
for (i := 1, cnt := 0 ; i <= tot ; ++i)
{
/* only consider this item if it's to be listed */
obj := list[i];
if (obj.isListed)
{
/*
* see if there are other equivalent items later in the
* list - if so, don't count it (this ensures that each such
* item is counted only once, since only the last such item
* in the list will be counted)
*/
if (obj.isEquivalent)
{
local sc;
sc := firstsc(obj);
for (j := i + 1 ; j <= tot ; ++j)
{
if (isIndistinguishable(obj, list[j]))
goto skip_this_item;
}
}
/* count this item */
++cnt;
skip_this_item: ;
}
}
return cnt;
}
/*
* sayPrefixCount: function(cnt)
*
* This function displays a count (suitable for use in listcont when
* showing the number of equivalent items. We display the count spelled out
* if it's a small number, otherwise we just display the digits of the
* number.
*/
sayPrefixCount: function(cnt)
{
if (cnt <= 20)
say(['one' 'two' 'three' 'four' 'five'
'six' 'seven' 'eight' 'nine' 'ten'
'eleven' 'twelve' 'thirteen' 'fourteen' 'fifteen'
'sixteen' 'seventeen' 'eighteen' 'nineteen' 'twenty'][cnt]);
else
say(cnt);
}
/*
* listcontgen: function(obj, flags, indent)
*
* This is a general-purpose object lister routine; the other object lister
* routines call this routine to do their work. This function can take an
* object, in which case it lists the contents of the object, or it can take
* a list, in which case it simply lists the items in the list. The flags
* parameter specifies what to do. LCG_TALL makes the function display a "tall"
* listing, with one object per line; if LCG_TALL isn't specified, the function
* displays a "wide" listing, showing the objects as a comma-separated list.
* When LCG_TALL is specified, the indent parameter indicates how many
* tab levels to indent the current level of listing, allowing recursive calls
* to display the contents of listed objects. LCG_CHECKVIS makes the function
* check the visibility of the top-level object before listing its contents.
* LCG_RECURSE indicates that we should recursively list the contents of the
* objects we list; we'll use the same flags on recursive calls, and use one
* higher indent level. LCG_CHECKLIST specifies that we should check
* the listability of any recursive contents before listing them, using
* the standard contentsListable() test. To specify multiple flags, combine
* them with the bitwise-or (|) operator.
*/
#define LCG_TALL 1
#define LCG_CHECKVIS 2
#define LCG_RECURSE 4
#define LCG_CHECKLIST 8
listcontgen: function(obj, flags, indent)
{
local i, count, tot, list, cur, disptot, prefix_count;
/*
* Get the list. If the "obj" parameter is already a list, use it
* directly; otherwise, list the contents of the object.
*/
switch(datatype(obj))
{
case 2:
/* it's an object - list its contents */
list := obj.contents;
/*
* if the CHECKVIS flag is specified, check to make sure the
* contents of the object are visible; if they're not, don't
* list anything
*/
if ((flags & LCG_CHECKVIS) != 0)
{
local contvis;
/* determine whether the contents are visible */
contvis := (!isclass(obj, openable)
|| (isclass(obj, openable) && obj.isopen)
|| obj.contentsVisible);
/* if they're not visible, don't list the contents */
if (!contvis)
return;
}
break;
case 7:
/* it's already a list */
list := obj;
break;
default:
/* ignore other types entirely */
return;
}
/* count the items in the list */
tot := length(list);
/* we haven't displayed anything yet */
count := 0;
/*
* Count how many items we're going to display -- this may be fewer
* than the number of items in the list, because some items might
* not be listed at all (isListed = nil), and we'll list each group
* of equivalent objects with a single display item (with a count of
* the number of equivalent objets)
*/
disptot := itemcnt(list);
/* iterate through the list */
for (i := 1 ; i <= tot ; ++i)
{
/* get the current object */
cur := list[i];
/* if this object is to be listed, figure out how to show it */
if (cur.isListed)
{
/* presume there is only one such object (i.e., no equivalents) */
prefix_count := 1;
/*
* if this is one of more than one equivalent items, list it
* only if it's the first one, and show the number of such
* items along with the first one
*/
if (cur.isEquivalent)
{
local before, after;
local j;
local sc;
/* get this object's superclass */
sc := firstsc(cur);
/* scan for other objects equivalent to this one */
for (before := after := 0, j := 1 ; j <= tot ; ++j)
{
if (isIndistinguishable(cur, list[j]))
{
if (j < i)
{
/*
* note that objects precede this one, and
* then look no further, since we're just
* going to skip this item anyway
*/
++before;
break;
}
else
++after;
}
}
/*
* if there are multiple such objects, and this is the
* first such object, list it with the count prefixed;
* if there are multiple and this isn't the first one,
* skip it; otherwise, go on as normal
*/
if (before = 0)
prefix_count := after;
else
continue;
}
/* display the appropriate separator before this item */
if ((flags & LCG_TALL) != 0)
{
local j;
/* tall listing - indent to the desired level */
"\n";
for (j := 1; j <= indent; ++j)
"\t";
}
else
{
/*
* "wide" (paragraph-style) listing - add a comma, and
* possibly "and", if this isn't the first item
*/
if (count > 0)
{
if (count+1 < disptot)
", ";
else if (count = 1)
" and ";
else
", and ";
}
}
/* list the object, along with the number of such items */
if (prefix_count = 1)
{
/* there's only one object - show the singular description */
cur.adesc;
}
else
{
/*
* there are multiple equivalents for this object -
* display the number of the items and the plural
* description
*/
sayPrefixCount(prefix_count); " ";
cur.pluraldesc;
}
/* show any additional information about the item */
if (cur.isworn)
" (being worn)";
if (cur.islamp and cur.islit)
" (providing light)";
/* increment the number of displayed items */
++count;
/*
* If this is a "tall" listing, and there's at least one item
* contained inside the current item, list the item's
* contents recursively, indented one level deeper.
*
* If the 'check visibility' flag is set, then only proceed
* with the sublisting if the contents are listable.
*/
if ((flags & LCG_RECURSE) != 0
&& itemcnt(cur.contents) != 0
&& ((flags & LCG_CHECKLIST) = 0 || contentsListable(cur)))
{
/*
* if this is a "wide" listing, show the contents in
* parentheses
*/
if ((flags & LCG_TALL) = 0)
{
if (cur.issurface)
" (upon which %you% see%s% ";
else
" (which contains ";
}
/* show the recursive listing, indented one level deeper */
listcontgen(cur, flags, indent + 1);
/* close the parenthetical, if we opened one */
if ((flags & LCG_TALL) = 0)
")";
}
}
}
}
/*
* listcont: function(obj)
*
* This function displays the contents of an object, separated by
* commas. The thedesc properties of the contents are used.
* It is up to the caller to provide the introduction to the list
* (usually something to the effect of "The box contains" is
* displayed before calling listcont) and finishing the
* sentence (usually by displaying a period). An object is listed
* only if its isListed property is true. If there are
* multiple indistinguishable items in the list, the items are
* listed only once (with the number of the items).
*/
listcont: function(obj)
{
/* use the general-purpose contents lister to show a "wide" listing */
listcontgen(obj, 0, 0);
}
/*
* nestlistcont: function(obj, depth)
*
* This function will produce a nested listing of the contents of obj.
* It will recurse down into the objects contents until the list is
* exhausted. An object's contents are listed only if they are
* considered visible by the normal visibility rules. The depth
* parameter is used to control the tabbing of the listing: an initial
* value of 1 will produce a listing with indented top-level contents,
* which is normally what you want, but 0 might also be desirable
* desirable in certain cases.
*/
nestlistcont: function(obj, depth)
{
/*
* use the general-purpose contents lister to show a "tall" listing,
* recursing into contents of the items in the list
*/
listcontgen(obj, LCG_TALL | LCG_RECURSE | LCG_CHECKLIST, depth);
}
/*
* contentsListable: are the contents of the given object listable in an
* inventory or description list? Returns true if the object's contents
* are visible and it's not a "quiet" container/surface.
*/
contentsListable: function(obj)
{
/* check to see if it's a surface or container */
if (obj.issurface)
{
/* surface - list the contents unless it's a "quiet" surface */
return (not obj.isqsurface);
}
else
{
/*
* container - list the contents if the container makes its
* contents visible and it's not a "quiet" container
*/
return (obj.contentsVisible and not obj.isqcontainer);
}
}
/*
* showcontcont: list the contents of the object, plus the contents of
* an fixeditem's contained by the object. A complete sentence is shown.
* This is an internal routine used by listcontcont and listfixedcontcont.
*/
showcontcont: function(obj)
{
/* show obj's direct contents, if it has any and they're listable */
if (itemcnt(obj.contents) != 0 && contentsListable(obj))
{
if (obj.issurface)
{
"Sitting on "; obj.thedesc;" is "; listcont(obj);
". ";
}
else
{
caps();
obj.thedesc; " seem";
if (!obj.isThem) "s";
" to contain ";
listcont(obj);
". ";
}
}
/*
* show the contents of the fixed contents if obj's contents are
* themselves listable
*/
if (contentsListable(obj))
listfixedcontcont(obj);
}
/*
* listfixedcontcont: function(obj)
*
* List the contents of the contents of any fixeditem objects
* in the contents list of the object obj. This routine
* makes sure that all objects that can be taken are listed somewhere
* in a room's description. This routine recurses down the contents
* tree, following each branch until either something has been listed
* or the branch ends without anything being listable. This routine
* displays a complete sentence, so no introductory or closing text
* is needed.
*/
listfixedcontcont: function(obj)
{
local list, i, tot, thisobj;
list := obj.contents;
tot := length(list);
i := 1;
while (i <= tot)
{
thisobj := list[i];
if (thisobj.isfixed and thisobj.contentsVisible and
not thisobj.isqcontainer)
showcontcont(thisobj);
i := i + 1;
}
}
/*
* listcontcont: function(obj)
*
* This function lists the contents of the contents of an object.
* It displays full sentences, so no introductory or closing text
* is required. Any item in the contents list of the object
* obj whose contentsVisible property is true has
* its contents listed. An Object whose isqcontainer or
* isqsurface property is true will not have its
* contents listed.
*/
listcontcont: function(obj)
{
local list, i, tot;
list := obj.contents;
tot := length(list);
i := 1;
while (i <= tot)
{
showcontcont(list[i]);
i := i + 1;