-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathadvlite.h
1498 lines (1204 loc) · 51.7 KB
/
advlite.h
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
#charset "us-ascii"
/*
* Copyright (c) 2000, 2006 Michael J. Roberts. All Rights Reserved.
*
* TADS 3 Library - main header
*
* This file provides definitions of macros, properties, and other
* identifiers used throughout the library and in game source.
*
* Each source code file in the library and in a game should generally
* #include this header near the top of the source file.
*/
#ifndef ADV3LITE_H
#define ADV3LITE_H
/* ------------------------------------------------------------------------ */
/*
* Include the system headers that we depend upon. We include these here
* so that each game source file will pick up the same set of system
* headers in the same order, which is important for intrinsic function
* set definitions.
*/
#include <tads.h>
#include <tok.h>
#include <t3.h>
#include <vector.h>
#include <strbuf.h>
#include <file.h>
#include <dict.h>
#include <bignum.h>
#include <gramprod.h>
#include <strcomp.h>
/* ------------------------------------------------------------------------ */
/*
* Turn on sourceTextGroup property generation in the compiler. (This lets
* us determine which module defined an object, and the order of the module
* in the overall project build. We use this for determining the
* precedence of certain items based on their definition order in the
* source code.)
*/
#pragma sourceTextGroup(on)
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
/*
* The '+' property sets an object's location to the lexically preceding
* object.
*/
+ property location;
/*
* The VerbRule macro starts the definition of a verb grammar rule. The
* tag is just an identifying name for the rule, so that you can refer to
* it with 'replace' or 'modify'.
*/
#define VerbRule(tag) grammar predicate(tag):
/*
* Verb rule noun phrase macros. These are convenience macros for
* specifying the most common noun phrase slots in the grammar templates
* for verb rules.
*/
#define singleDobj singleNoun->dobjMatch
#define singleIobj singleNoun->iobjMatch
#define singleAcc singleNoun->accMatch
#define singleAobj singleNoun->accMatch
#define multiDobj nounList->dobjMatch
#define multiIobj nounList->iobjMatch
#define accList nounList->accMatch
#define aobjList nounList->accMatch
#define multiAcc nounList->accMatch
#define multiAobj nounList->accMatch
#define numberDobj numberPhrase->dobjMatch
#define topicDobj topicPhrase->dobjMatch
#define topicIobj topicPhrase->iobjMatch
#define topicAcc topicPhrase->accMatch
#define topicAobj topicPhrase->accMatch
#define literalDobj literalPhrase->dobjMatch
#define literalIobj literalPhrase->iobjMatch
#define literalAcc literalPhrase->accMatch
#define literalAobj literalPhrase->accMatch
#define singleDir directionName->dirMatch
#define numericDobj numberPhrase -> dobjMatch
#define numericIobj numberPhrase -> iobjMatch
#define numericAcc numberPhrase -> accMatch
#define numericAobj numberPhrase -> accMatch
/* Also add a couple of synonyms familiar froma adv3 */
#define dobjList nounList->dobjMatch
#define iobjList nounList->iobjMatch
/* ------------------------------------------------------------------------ */
/*
* Establish the default dictionary for the game's player command parser
* vocabulary.
*/
dictionary cmdDict;
/*
* The standard parts of speech for the dictionary.
*/
dictionary property noun, nounApostS;
/* ------------------------------------------------------------------------ */
/*
* Flags for matching noun phrases during parsing. These are bit flags, so
* they can be combined with '|' (bitwise OR).
*
* Note that the arithmetic values also matter: the values are in order of
* priority for noun phrase matches. That is, a higher arithmetic value is
* a better match. The best match is one with no truncation and no
* approximation, so that will have the highest arithmetic value when you
* combine those two bit flags. The next best is character approximation
* but no truncation - truncation is more important than approximation, so
* it has a higher arithmetic value.
*/
/* matched a preposition (the phrase contains at least one preposition) */
#define MatchPrep 0x0001
/*
* matched a weak token (which we'll treat as equivalent to matchimg a
* preposition).
*/
#define MatchWeak 0x0001
/* matched an adjective (the phrase contains at least one adjective) */
#define MatchAdj 0x0002
/* matched a noun (the phrase contains at least one noun word) */
#define MatchNoun 0x0004
/* matched a plural (the phrase contains at least one plural word) */
#define MatchPlural 0x0008
/* matched a phrase */
#define MatchPhrase 0x0010
/* mask to select only the part-of-speech flags */
#define MatchPartMask 0x0FFF
/*
* all words were matched WITHOUT character approximations (such as
* matching 'a' to 'a-umlaut')
*/
#define MatchNoApprox 0x1000
/* all words were matched WITHOUT truncation */
#define MatchNoTrunc 0x2000
/* mask to select only the match-strength flags */
#define MatchStrengthMask 0xF000
/* ------------------------------------------------------------------------ */
/*
* Flags for object selection during parsing. These flags reflect how well
* an object matched a noun phrase during the resolution process.
*/
/*
* The noun phrase required disambiguation, because more than one object
* was in scope that matched the noun phrase. We were able to figure out
* which one(s) the player meant from context, without having to ask the
* player for help.
*
* For example, there are two doors in the room, one open and one closed.
* The player types OPEN DOOR. It's fairly obvious that they must be
* talking about the closed door. So, we choose that object and set the
* Disambig flag.
*
* (Note that this flag specifically does NOT mean that we had to ask the
* user for help with the dreaded "Which do you mean..." question. It's
* kind of the opposite: it means that we had a noun phrase that was
* initially ambiguous, but that we managed to disambiguate it on our own.
* When we get the user involved, there's ambiguity *before* we ask the
* question, but the user's response removes the ambiguity by telling us
* exactly which alternative they intended. This flag indicates that we
* made an educated guess about what the user must have intended, without
* asking. The flag lets the parser tell the player about the guess, which
* is desirable because the guess is sometimes wrong.
*/
#define SelDisambig 0x0001
/*
* This object was chosen arbitrarily from a larger set, because the noun
* phrase construction says we should do so. This flag is set when the
* noun phrase is something TAKE A BOOK or TAKE ANY OF THE BOOKS.
*/
#define SelArbitrary 0x0002
/*
* The noun phrase that we matched was a manifestly plural construction,
* such as TAKE ALL or TAKE THE BOOKS.
*/
#define SelPlural 0x0004
/*
* We selected an object as a default. This is set when the player leaves
* out a noun phrase, but we can guess what was probably meant based on
* context: e.g., ASK ABOUT THE HOUSE is probably directed to Bob if Bob is
* the only person nearby.
*/
#define SelDefault 0x0008
/*
* This object was set internally by the program; it did not come from
* parsing any player input. This generally means that the whole command
* was constructed by the program, to handle an event or other internal
* processing, rather than by parsing player input.
*/
#define SelProg 0x1000
/* ------------------------------------------------------------------------ */
/*
* readMainCommandTokens() phase identifiers. We define a separate code
* for each kind of call to readMainCommandTokens() so that we can do any
* special token processing that depends on the type of command we're
* reading.
*
* The library doesn't use the phase information itself for anything.
* These phase codes are purely for the author's use in writing
* pre-parsing functions and for differentiating prompts for the different
* types of input, as needed.
*
* Games that read additional response types of their own are free to add
* their own enums to identify the additional phases. Since the library
* doesn't need the phase information for anything internally, it won't
* confuse the library at all to add new game-specific phase codes.
*/
/* reading a normal command line */
enum rmcCommand;
/* reading an unknown word response, to check for an "oops" command */
enum rmcOops;
/* reading a response to a prompt for a missing object phrase */
enum rmcAskObject;
/* reading a response to a prompt for a missing literal phrase */
enum rmcAskLiteral;
/* reading a response to an interactive disambiguation prompt */
enum rmcDisambig;
/* ------------------------------------------------------------------------ */
/*
* A couple of utility macros we use internally for turning macro values
* into strings. STRINGIZE(x) expands any macros in its argument and then
* turns the result into a single-quoted string, which can then be used in
* regular program text or in directives that evaluate constant
* expressions, such as #if. (STRINGIZE is the real macro; _STRINGIZE is
* needed to force expansion of any macros in the argument, which is
* required because of the weird ANSI C expansion-order rules, and which
* works because of same.)
*/
#define _STRINGIZE(x) #@x
#define STRINGIZE(x) _STRINGIZE(x)
/* ------------------------------------------------------------------------ */
/*
* Parser global variables giving information on the command currently
* being performed. These are valid through doAction processing. These
* should never be changed except by the parser.
*/
/* the actor performing the current command */
#define gActor (libGlobal.curActor)
/*
* For convenience, define some macros that return the current direct and
* indirect objects from the current action. The library only uses direct
* and indirect objects, so games that define additional command objects
* will have to add their own similar macros for those.
*/
#define gDobj (gAction.curDobj)
#define gIobj (gAction.curIobj)
#define gLiteral (gAction.literal)
#define gNumber (gAction.num)
/* the Action object of the command being executed */
#define gAction (libGlobal.curAction)
#define gCommand (libGlobal.curCommand)
#define gTentativeDobj (gCommand.dobjs.mapAll({x: x.obj}).toList)
#define gTentativeIobj (gCommand.iobjs.mapAll({x: x.obj}).toList)
/*
* the probable Action objects of the command being executed for use in verify routines when
* resolution of both objects may not be complete. If the gDobj or gIobj is non-nil, use that,
* otherwise use the first object in the tentative resolution list if the list has any items,
* otherwisse evaluate to failVerifyObj.
*/
#define gVerifyDobj (gDobj ?? (gTentativeDobj.length > 0 ? gTentativeDobj[1] : failVerifyObj))
#define gVerifyIobj (gIobj ?? (gTentativeIobj.length > 0 ? gTentativeIobj[1] : failVerifyObj))
/*
* An alternative way of dealing with the potential object not yet resolved problem, by testing
* whether any of the objects in lst are in the Tentative Object List.
*/
#define gTentativeDobjIn(lst) (gTentativeDobj.overlapsWith(lst))
#define gTentativeIobjIn(lst) (gTentativeIobj.overlapsWith(lst))
/* The previous action and command */
#define gLastAction (libGlobal.lastAction)
#define gLastCommand (libGlobal.lastCommand)
/*
* Determine if the current global action is the specified action. Only
* the action prefix is needed - so use "Take" rather than "TakeAction"
* here.
*
* This tests to see if the current global action is an instance of the
* given action class - we test that it's an instance rather than the
* action class itself because the parser creates an instance of the
* action when it matches the action's syntax.
*/
#define gActionIs(action) \
(gAction != nil && gAction.ofKind(action))
/* is the current global action ANY of the specified actions? */
#define gActionIn(action...) \
(gAction != nil \
&& (action#foreach/gAction.ofKind(action)/||/))
/* is the current action a Travel action going dirn */
#define gTravelActionIs(dirn) \
(gAction != nil && gAction.ofKind(Travel) && gAction.direction == dirn ## Dir)
/* the list of objects involved in the action just completed */
#define gActionList (nilToList(gCommand.action.actionList))
/* a displaying string version of the above */
#define gActionListStr makeListStr(gCommand.action.reportList, &theName)
/*
* an object that is singular or plural according to whether gActionList
* represents a single object of a plurality of objects, and which picks
* up the correct gender if there is only a single object.
*/
#define gActionListObj (object: Thing \
{ \
plural = (gAction.reportList.length > 1 || \
gAction.reportList[1].plural); \
isIt = (gAction.reportList.length == 1 ? \
gAction.reportList[1].isIt : nil);\
isHim = (gAction.reportList.length == 1 ? \
gAction.reportList[1].isHim : nil);\
isHer = (gAction.reportList.length == 1 ? \
gAction.reportList[1].isHer : nil);\
name = gActionListStr; \
qualified = true; \
} )
/* ------------------------------------------------------------------------ */
/*
* Miscellaneous macros
*/
/* get the current player character Actor object */
#define gPlayerChar (libGlobal.playerChar)
/* get the player character's location */
#define gLocation (getPlayerChar().location)
/* get the current turn count */
#define gTurns (libGlobal.totalTurns)
/*
* get the player character's current room (which may or may not be the same
* as his/her location)
*/
#define gRoom (getPlayerChar().getOutermostRoom)
/* Get the current actor's curren room (which may not be the same as its location) */
#define gActorRoom (gActor.getOutermostRoom)
#define objFor(which, action) propertyset '*' ## #@which ## #@action
#define dobjFor(action) objFor(Dobj, action)
#define iobjFor(action) objFor(Iobj, action)
#define gTopic (gAction.curTopic)
#define gTopicText (gTopic.getTopicText)
#define gTopicMatch (gTopic.getBestMatch)
#define reportAfter(msg) gCommand.afterReports += msg
#define reportPostImplicit(msg) gCommand.postImplicitReports += msg
/*
* Defined for the sake of adv3 users moving to adv3Lite, who may be more used to using
* mainReport() in a similar context.
*/
#define mainReport(msg) actionReport(msg)
#define sLoc(which) subLocation = &remap##which
/*
* Treat an object definition as equivalent to another object definition.
* These can be used immediately after a dobjFor() or iobjFor() to treat
* the first action as though it were the second. So, if the player types
* "search box", and we want to treat the direct object the same as for
* "look in box", we could make this definition for the box:
*
* dobjFor(Search) asDobjFor(LookIn)
*
* Note that no semicolon is needed after this definition, and that this
* definition is completely in lieu of a regular property set for the
* object action.
*
* In general, a mapping should NOT change the role of an object:
* dobjFor(X) should not usually be mapped using asIobjFor(Y), and
* iobjFor(X) shouldn't be mapped using asDobjFor(Y). The problem with
* changing the role is that the handler routines often assume that the
* object is actually in the role for which the handler was written; a
* verify handler might refer to '{dobj}' in generating a message, for
* example, so reversing the roles would give the wrong object in the role.
*
* Role reversals should always be avoided, but can be used if necessary
* under conditions where all of the code involved in the TARGET of the
* mapping can be carefully controlled to ensure that it doesn't make
* assumptions about object roles, but only references 'self'. Reversing
* roles in a mapping should never be attempted in general-purpose library
* code, because code based on the library could override the target of the
* role-reversing mapping, and the override could fail to observe the
* restrictions on object role references.
*
* Note that role reversals can almost always be handled with other
* mechanisms that handle reversals cleanly. Always consider Doer.doInstead()
* first when confronted with a situation that seems to call for a
* role-reversing asObjFor() mapping, as doInstead() specifically allows for
* object role changes.
*/
#define asObjFor(obj, Action) \
{ \
preCond { return preCond##obj##Action; } \
verify() { verify##obj##Action; } \
remap() { return remap##obj##Action; } \
check() { check##obj##Action; } \
action() { action##obj##Action; } \
report() { report##obj##Action; } \
}
#define asDobjFor(action) asObjFor(Dobj, action)
#define asIobjFor(action) asObjFor(Iobj, action)
/*
* Define mappings of everything except the action. This can be used in
* cases where we want to pick up the verification, preconditions, and
* check routines from another handler, but not the action. This is often
* useful for two-object verbs where the action processing is entirely
* provided by one or the other object, so applying it to both would be
* redundant.
*/
#define asObjWithoutActionFor(obj, Action) \
{ \
preCond { return preCond##obj##Action; } \
verify() { verify##obj##Action; } \
remap() { return remap##obj##Action(); } \
check() { check##obj##Action; } \
action() { } \
}
#define asDobjWithoutActionFor(action) asObjWithoutActionFor(Dobj, action)
#define asIobjWithoutActionFor(action) asObjWithoutActionFor(Iobj, action)
#define asObjWithoutVerifyFor(obj, Action) \
{ \
preCond { return preCond##obj##Action; } \
remap() { return remap##obj##Action(); } \
check() { check##obj##Action; } \
action() { action##obj##Action(); } \
report() { report##obj##Action(); } \
}
#define asDobjWithoutVerifyFor(action) asObjWithoutVerifyFor(Dobj, action)
#define asIobjWithoutVerifyFor(action) asObjWithoutVerifyFor(Iobj, action)
#define askForDobj(action) askMissingObject(action, DirectObject)
#define askForIobj(action) askMissingObject(action, IndirectObject)
#define askForAobj(action) askMissingObject(action, AccessoryObject)
#define askForAcc(action) askMissingObject(action, AccessoryObject)
/* Convenience macros for synthesizing travel in a given compass direction */
#define goInstead(dirn) doInstead(Go, dirn##Dir)
#define goNested(dirn) doNested(Go, dirn##Dir)
#define asExit(dir) : UnlistedProxyConnector { direction = dir##Dir }
#define asExitListed(dir) : UnlistedProxyConnector { direction = dir##Dir isConnectorListed = true}
/* ------------------------------------------------------------------------ */
/*
* Define an action with the given base class. This adds the *Action
* suffix to the given root name, and defines a class with the given base
* class. We also define the baseActionClass property to refer to myself;
* this is the canonical class representing the action for all subclasses.
* This information is useful because a language module might define
* several grammar rule subclasses for the given class; this lets us
* relate any instances of those various subclasses back to this same
* canonical class for the action if necessary.
*/
/*
* Define an action OBJECT with the given name inheriting from the given base
* class, for use with the Mercury parser.
*/
#define DefineAction(name, baseClass...) \
name: ##baseClass \
baseActionClass = name
/*
* Define a "system" action. System actions are meta-game commands, such
* as SAVE and QUIT, that generally operate the user interface and are not
* part of the game world.
*/
#define DefineSystemAction(name) \
DefineAction(name, SystemAction)
/*
* Define a concrete IAction, given the root name for the action. We'll
* automatically generate a class with name XxxAction.
*/
#define DefineIAction(name) \
DefineAction(name, IAction)
/*
* Define a concrete TAction, given the root name for the action. We'll
* automatically generate a class with name XxxAction, a verProp with name
* verXxx, a checkProp with name checkXxx, and an actionProp with name
* actionDobjXxx.
*/
#define DefineTAction(name) \
DefineTActionSub(name, TAction)
/*
* Define a concrete TAction with a specific base class.
*/
#define DefineTActionSub(name, cls) \
DefineAction(name, cls) \
verDobjProp = &verifyDobj##name \
remapDobjProp = &remapDobj##name \
preCondDobjProp = &preCondDobj##name \
checkDobjProp = &checkDobj##name \
actionDobjProp = &actionDobj##name \
reportDobjProp = &reportDobj##name \
#define DefineLiteralTAction(name)\
DefineTActionSub(name, LiteralTAction)
#define DefineLiteralAction(name)\
DefineAction(name, LiteralAction)
#define DefineTopicTAction(name)\
DefineTActionSub(name, TopicTAction)
#define DefineTopicAction(name)\
DefineAction(name, TopicAction)
#define DefineNumericTAction(name)\
DefineTActionSub(name, NumericTAction)
#define DefineNumericAction(name) \
DefineAction(name, NumericAction)
/*
* Define a concrete TIAction, given the root name for the action. We'll
* automatically generate a class with name XxxAction, a verDobjProp with
* name verDobjXxx, a verIobjProp with name verIobjxxx, a checkDobjProp
* with name checkDobjXxx, a checkIobjProp with name checkIobjXxx, an
* actionDobjProp with name actionDobjXxx, and an actionIobjProp with name
* actionIobjXxx.
*/
#define DefineTIAction(name) \
DefineTIActionSub(name, TIAction)
/*
* Define a concrete TIAction with a specific base class.
*/
#define DefineTIActionSub(name, cls) \
DefineAction(name, cls) \
verDobjProp = &verifyDobj##name \
verIobjProp = &verifyIobj##name \
remapDobjProp = &remapDobj##name \
remapIobjProp = &remapIobj##name \
preCondDobjProp = &preCondDobj##name \
preCondIobjProp = &preCondIobj##name \
checkDobjProp = &checkDobj##name \
checkIobjProp = &checkIobj##name \
actionDobjProp = &actionDobj##name \
actionIobjProp = &actionIobj##name \
reportDobjProp = &reportDobj##name \
reportIobjProp = &reportIobj##name \
/*
* The following macros relating to the TIAAction class are only relevant when
* the TIAAction extension is used. The macros are nevertheless included here
* for convenience when using the TIAAction extension.
*
* Define a concrete TIAAction, given the root name for the action. We'll
* automatically generate a class with name XxxAction, a verDobjProp with name
* verDobjXxx, a verIobjProp with name verIobjxxx, a checkDobjProp with name
* checkDobjXxx, a checkIobjProp with name checkIobjXxx, an actionDobjProp
* with name actionDobjXxx, and an actionIobjProp with name actionIobjXxx.
*/
#define DefineTIAAction(name) \
DefineTIAActionSub(name, TIAAction)
/*
* Define a concrete TIAction with a specific base class.
*/
#define DefineTIAActionSub(name, cls) \
DefineAction(name, cls) \
verDobjProp = &verifyDobj##name \
verIobjProp = &verifyIobj##name \
verAobjProp = &verifyAobj##name \
remapDobjProp = &remapDobj##name \
remapIobjProp = &remapIobj##name \
remapAobjProp = &remapAobj##name \
preCondDobjProp = &preCondDobj##name \
preCondIobjProp = &preCondIobj##name \
preCondAobjProp = &preCondAobj##name \
checkDobjProp = &checkDobj##name \
checkIobjProp = &checkIobj##name \
checkAobjProp = &checkAobj##name \
actionDobjProp = &actionDobj##name \
actionIobjProp = &actionIobj##name \
actionAobjProp = &actionAobj##name \
reportDobjProp = &reportDobj##name \
reportIobjProp = &reportIobj##name \
reportAobjProp = &reportAobj##name \
#define aobjFor(action) objFor(Aobj, action)
#define asAobjFor(action) asObjFor(Aobj, action)
#define accFor(action) objFor(Aobj, action)
#define asAccFor(action) asObjFor(Aobj, action)
#define gAobj gAction.curAobj
#define gAcc gAction.curAobj
/*
* Macros for use in verify routines, returning various kinds of verify
* results
*/
#define gVerifyList gAction.verifyList
#define logical gAction.addVerifyResult (new VerifyResult(100, '', true, self))
#define illogical(msg) \
gAction.addVerifyResult(new VerifyResult(30, msg, nil, self))
#define illogicalNow(msg) \
gAction.addVerifyResult(new VerifyResult(40, msg, nil, self))
/*
* IllogicalAlready doesn't do anything different from IllogicalNow in
* adv3Lite, but is supplied so that game authors familiar with adv3 can use
* it without getting a compilation error. It may also be slightly useful for
* documentary purposes to clarify why a verify routine in game code is ruling
* out an action.
*/
#define illogicalAlready(msg) \
gAction.addVerifyResult(new VerifyResult(40, msg, nil, self))
#define illogicalSelf(msg) \
gAction.addVerifyResult(new VerifyResult(20, msg, nil, self))
#define logicalRank(score) \
gAction.addVerifyResult(new VerifyResult(score, '', true, self))
#define inaccessible(msg) \
gAction.addVerifyResult(new VerifyResult(10, msg, nil, self))
#define implausible(msg) \
gAction.addVerifyResult(new VerifyResult(35, msg, nil, self))
#define nonObvious \
gAction.addVerifyResult(new VerifyResult(30, '', true, self, nil))
#define dangerous \
gAction.addVerifyResult(new VerifyResult(90, '', true, self, nil))
/* ------------------------------------------------------------------------ */
/*
* Command interruption signal macros.
*/
/* a concise macro to throw an ExitSignal */
#define exit throw new ExitSignal()
/* a concise macro to throw an ExitActionSignal */
#define exitAction throw new ExitActionSignal()
/* a concise macro to throw an AbortImplicitSignal */
#define abortImplicit throw new AbortImplicitSignal()
/* a concise macro to throw an Abort signal */
#define abort throw new AbortActionSignal()
/* ------------------------------------------------------------------------ */
/*
* aHref() flags
*/
#define AHREF_Plain 0x0001 /* plain text hyperlink (no underline/color) */
/* ------------------------------------------------------------------------ */
/*
* An achievement defines its descriptive text. It can also optionally
* define the number of points it awards.
*/
Achievement template +points? "desc";
/* ------------------------------------------------------------------------ */
/*
* Templates for style tags
*/
StyleTag template 'tagName' 'openText'? 'closeText'?;
/* ------------------------------------------------------------------------ */
/*
* Object definition templates
*/
Thing template 'vocab' @location? "desc"?;
Topic template 'vocab' @familiar?;
Room template 'roomTitle' 'vocab' "desc"?;
Room template 'roomTitle' "desc"?;
Region template [rooms];
Door template 'vocab' @location? "desc"? ->otherSide;
Door template ->otherSide 'vocab' @location? "desc"?;
TravelConnector template 'vocab'? @location? "desc"? ->destination;
TravelConnector template ->destination "travelDesc";
Enterable template inherited ->connector;
Enterable template ->connector inherited;
Unthing template 'vocab' @location? 'notHereMsg'?;
Unthing template @unObject @location? 'notHereMsg'?;
SensoryEmanation template inherited [eventList]?;
ActorState template "specialDesc" 'stateDesc' | "stateDesc" ?;
TopicGroup template +scoreBoost? 'convKeys' | [convKeys] ? ;
TopicEntry template
+matchScore?
@matchObj | [matchObj] | 'matchPattern'
"topicResponse" | [eventList] ?;
/* a ShuffledEventList version of the above */
TopicEntry template
+matchScore?
@matchObj | [matchObj] | 'matchPattern'
[firstEvents] [eventList];
/* we can also include *both* the match object/list *and* pattern */
TopicEntry template
+matchScore?
@matchObj | [matchObj]
'matchPattern'
"topicResponse" | [eventList] ?;
/* a ShuffledEventList version of the above */
TopicEntry template
+matchScore?
@matchObj | [matchObj]
'matchPattern'
[firstEvents] [eventList];
/* Version ActorTopicEntry template for use with Facts and kTag */
ActorTopicEntry template +matchScore? "topicResponse" | [eventList];
QueryTopic template
+matchScore? 'matchPattern'
"topicResponse" | [eventList] ?;
QueryTopic template
+matchScore? 'matchPattern'
[firstEvents] [eventList];
QueryTopic template
+matchScore? 'qtype'
@matchObj | [matchObj] | 'matchPattern'
"topicResponse" | [eventList] ?;
/* a ShuffledEventList version of the above */
QueryTopic template
+matchScore? 'qtype'
@matchObj | [matchObj] | 'matchPattern'
[firstEvents] [eventList];
/* we can also include *both* the match object/list *and* pattern */
QueryTopic template
+matchScore? 'qtype'
@matchObj | [matchObj]
'matchPattern'
"topicResponse" | [eventList] ?;
/* a ShuffledEventList version of the above */
QueryTopic template
+matchScore? 'qtype'
@matchObj | [matchObj]
'matchPattern'
[firstEvents] [eventList];
SayTopic template
+matchScore?
'tTag' 'extraVocab'
"topicResponse" | [eventList] ?;
CommandTopic template +matchScore?
@matchObj | [matchObj]
@matchDobj @matchIobj? "topicResponse" | [eventList]? ;
CommandTopic template +matchScore?
@matchObj | [matchObj] [matchDobj] @matchIobj "topicResponse" | [eventList]? ;
DefaultTopic template "topicResponse" | [eventList];
DefaultConsultTopic template "topicResponse" | [eventList];
DefaultThought template "topicResponse" | [eventList];
/* miscellanous topics just specify the response text or list */
MiscTopic template "topicResponse" | [eventList];
MiscTopic template [firstEvents] [eventList];
NodeContinuationTopic template "topicResponse" | [eventList];
NodeContinuationTopic template [firstEvents] [eventList];
/* AltTopics just specify the response text or list */
AltTopic template "topicResponse" | [eventList];
AltTopic template [firstEvents] [eventList];
/* The ProxyActor template just specifies the location (i.e. the base Actor) */
ProxyActor template @location;
Doer template 'cmd';
/* Templates for use with test sequences */
Test template 'testName' [testList] @location? [testHolding]?;
Test template 'testName' [testList] [testHolding]? @location?;
/* Define some convenient abbreviations for ConvNode related objects */
#define NEC NodeEndCheck
#define NCT NodeContinuationTopic
#define DCT DefaultConvstayTopic
/* Define convenient named constants for use with ConvAgendaItem */
#define InitiateConversationReason 1
#define ConversationLullReason 2
#define DefaultTopicReason 3
/* ------------------------------------------------------------------------ */
/*
* Command interruption signal macros.
*/
/*
* Terminate execution of the command line. This aborts the current
* command, including any remaining object iterations for the current
* action, and discards anything else on the command line.
*/
#define exitCommandLine throw new ExitCommandLineSignal()
/*----------------------------------------------------------------------------*/
/*
* enums for different types of lock:
*/
enum notLockable, lockableWithoutKey, lockableWithKey, indirectLockable;
enum masculine, feminine, neuter;
/* ------------------------------------------------------------------------ */
/*
* The current library messages object. This is the source object for
* messages that don't logically relate to the actor carrying out the
* comamand. It's mostly used for meta-command replies, and for text
* fragments that are used to construct descriptions.
*
* This message object isn't generally used for parser messages or action
* replies - most of those come from the objects given by the current
* actor's getParserMessageObj() or getActionMessageObj(), respectively.
*
* By default, this is set to libMessages. The library never changes this
* itself, but a game can change this if it wants to switch to a new set of
* messages during a game. (If you don't need to change messages during a
* game, but simply want to customize some of the default messages, you
* don't need to set this variable - you can simply use 'modify
* libMessages' instead. This variable is designed for cases where you
* want to *dynamically* change the standard messages during the game.)
*/
#define gLibMessages (libGlobal.libMessageObj)
/*
* the exit lister object - if the exits module isn't included in the
* game, this will be nil
*/
#define gExitLister (libGlobal.exitListerObj)
/*
* the hint manager object - if the hints module isn't included in the
* game, this will be nil
*/
#define gHintManager (libGlobal.hintManagerObj)
/*
* the extra hint manager object - if the hints module isn't included in the
* game, this will be nil
*/
#define gExtraHintManager (libGlobal.extraHintManagerObj)
/* ------------------------------------------------------------------------ */
/*
* Convenience macros for controlling the narrative tense.
*/
/*
* Set the current narrative tense. Use val = true for past and
* val = nil for present.
*/
#define setPastTense(val) (gameMain.usePastTense = (val))
/*
* Shorthand macro for selecting one of two values depending on the
* current narrative tense.
*/
#define tSel(presVal, pastVal) \
(gameMain.usePastTense ? (pastVal) : (presVal))
/*
* Temporarily override the current narrative tense and invoke a callback
* function.
*/
#define withPresent(callback) (withTense(nil, (callback)))
#define withPast(callback) (withTense(true, (callback)))
/* ------------------------------------------------------------------------ */
/*
* Object role identifiers. These are used to identify the role of a noun
* phrase in a command.
*
*
*/
/*
* A special role for the "other" object of a two-object command. This
* can be used in certain contexts (such as remapTo) where a particular
* object role is implied by the context, and where the action involved
* has exactly two objects; OtherObject in such contexts means
* DirectObject when the implied role is IndirectObject, and vice versa.
*/
enum OtherObject;
/* ------------------------------------------------------------------------ */
/*
* A couple of utility macros we use internally for turning macro values
* into strings. STRINGIZE(x) expands any macros in its argument and then
* turns the result into a single-quoted string, which can then be used in
* regular program text or in directives that evaluate constant