Debian Codegraph @

terps/tads/tads3/lib/adv3/adv3.h

raw symbols SCIP
1 #charset "us-ascii"
2
3 /*
4 * Copyright (c) 2000, 2006 Michael J. Roberts. All Rights Reserved.
5 *
6 * TADS 3 Library - main header
7 *
8 * This file provides definitions of macros, properties, and other
9 * identifiers used throughout the library and in game source.
10 *
11 * Each source code file in the library and in a game should generally
12 * #include this header near the top of the source file.
13 */
14
15 #ifndef ADV3_H
16 #define ADV3_H
17
18 /* ------------------------------------------------------------------------ */
19 /*
20 * Include the system headers that we depend upon. We include these here
21 * so that each game source file will pick up the same set of system
22 * headers in the same order, which is important for intrinsic function
23 * set definitions.
24 */
25 #include <tads.h>
26 #include <tok.h>
27 #include <t3.h>
28 #include <vector.h>
29 #include <strbuf.h>
30 #include <file.h>
31 #include <dict.h>
32
33
34 /* ------------------------------------------------------------------------ */
35 /*
36 * Establish the default dictionary for the game's player command parser
37 * vocabulary.
38 */
39 dictionary cmdDict;
40
41 /* ------------------------------------------------------------------------ */
42 /*
43 * canInherit - determine if there's anything to inherit from the current
44 * method. Returns true if there's a method to inherit, nil if
45 * 'inherited' in the current context would not invoke any code.
46 */
47 #define canInherit() \
48 propInherited(targetprop, targetobj, definingobj, PropDefAny)
49
50
51 /* ------------------------------------------------------------------------ */
52 /*
53 * Generic part of speech for "miscellaneous word." We use this to
54 * classify words in unstructured phrases; it can apply to any token.
55 * Note that dictionary entries are never made with this word type, so
56 * it's not specific to any language; this is merely for flagging words in
57 * unstructured phrases in grammar matches.
58 */
59 dictionary property miscWord;
60
61 /*
62 * Generic part of speech for SpecialTopic words. We enter special topic
63 * keywords into the parser dictionary so that they're not flagged as
64 * unknown words if they're used out of context.
65 */
66 dictionary property specialTopicWord;
67
68
69 /* ------------------------------------------------------------------------ */
70 /*
71 * If we're compiling for debugging, automatically include the parser
72 * debug code, which allows certain information on the parsing process
73 * (such as grammar match trees) to be displayed each time a command is
74 * typed.
75 *
76 * Note that you can turn on parser debugging independently of full
77 * compiler debug information simply by explicitly defining PARSER_DEBUG
78 * (with the t3make -D option, for example).
79 */
80 #ifdef __DEBUG
81 #define PARSER_DEBUG
82 #endif
83
84 /*
85 * Define some convenience macros for parser debug operations. When
86 * PARSER_DEBUG isn't defined, these macros expand out to nothing.
87 */
88 #ifdef PARSER_DEBUG
89
90 #define dbgShowGrammarList(lst) showGrammarList(lst)
91 #define dbgShowGrammarWithCaption(headline, match) \
92 showGrammarWithCaption(headline, match)
93
94 #else /* PARSER_DEBUG */
95
96 #define dbgShowGrammarList(lst)
97 #define dbgShowGrammarWithCaption(headline, match)
98
99 #endif /* PARSER_DEBUG */
100
101
102 /* ------------------------------------------------------------------------ */
103 /*
104 * Parser global variables giving information on the command currently
105 * being performed. These are valid through doAction processing. These
106 * should never be changed except by the parser.
107 */
108
109 /* the actor performing the current command */
110 #define gActor (libGlobal.curActor)
111
112 /*
113 * For convenience, define some macros that return the current direct and
114 * indirect objects from the current action. The library only uses direct
115 * and indirect objects, so games that define additional command objects
116 * will have to add their own similar macros for those.
117 */
118 #define gDobj (gAction.getDobj())
119 #define gIobj (gAction.getIobj())
120
121 /*
122 * Get the current ResolvedTopic, and the literal text of the topic phrase
123 * as the user typed it (but converted to lower case). These are
124 * applicable when the current action has a topic phrase.
125 */
126 #define gTopic (gAction.getTopic())
127 #define gTopicText (gTopic.getTopicText.toLower())
128
129 /* get the current literal phrase text, when the command has one */
130 #define gLiteral (gAction.getLiteral())
131
132 /*
133 * The tentative pre-resolution lists for the direct and indirect objects.
134 * When we're resolving an object of a multi-object command, these
135 * pre-resolution lists are available for the later-resolved objects.
136 *
137 * Note that these values are list of ResolveInfo objects. The obj_
138 * property of a list entry gives the entry's game-world object.
139 *
140 * These lists do not provide the final resolution lists for the objects;
141 * rather, they provide a tentative set of possibilities based on the
142 * information that's available without knowing the results of resolving
143 * the earlier-resolved objects yet.
144 *
145 * These are not meaningful when resolving single-object actions.
146 */
147 #define gTentativeDobj (gAction.getTentativeDobj())
148 #define gTentativeIobj (gAction.getTentativeIobj())
149
150 /*
151 * the actor who *issued* the current command (this is usually the player
152 * character, because most commands are initiated by the player on the
153 * command line, but it is also possible for one actor to send a command
154 * to another programmatically)
155 */
156 #define gIssuingActor (libGlobal.curIssuingActor)
157
158 /* the Action object of the command being executed */
159 #define gAction (libGlobal.curAction)
160
161 /*
162 * Determine if the current global action is the specified action. Only
163 * the action prefix is needed - so use "Take" rather than "TakeAction"
164 * here.
165 *
166 * This tests to see if the current global action is an instance of the
167 * given action class - we test that it's an instance rather than the
168 * action class itself because the parser creates an instance of the
169 * action when it matches the action's syntax.
170 */
171 #define gActionIs(action) \
172 (gAction != nil && gAction.actionOfKind(action##Action))
173
174 /* is the current global action ANY of the specified actions? */
175 #define gActionIn(action...) \
176 (gAction != nil \
177 && (action#foreach/gAction.actionOfKind(action##Action)/||/))
178
179 /* the verification results object - this is valid during verification */
180 #define gVerifyResults (libGlobal.curVerifyResults)
181
182 /* the command transcript object - this is valid during command execution */
183 #define gTranscript (mainOutputStream.curTranscript)
184
185 /*
186 * Some message processors add their own special parameters to messages,
187 * because they want to use expansion parameters (in the "{the dobj/him}"
188 * format) outside of the set of objects directly involved in the command.
189 *
190 * The Action method setMessageParam() lets you define such a parameter,
191 * but for convenience, we define this macro for setting one or more
192 * parameters whose names exactly match their local variable names. In
193 * other words, if you call this macro like this:
194 *
195 * gMessageParams(obj, cont)
196 *
197 * then you'll get one parameter with the text name 'obj' whose expansion
198 * will be the value of the local variable obj, and another with text name
199 * 'cont' whose expansion is the value of the local variable cont.
200 */
201 #define gMessageParams(var...) \
202 (gAction.setMessageParams(var#foreach/#@var, var/,/))
203
204 /*
205 * Synthesize a global message parameter name for the given object and
206 * return the synthesized name. This is useful in cases where there might
207 * be repeated instances of global message parameters in the same action,
208 * so it's not safe to use a fixed name string for the object. We'll
209 * create a unique global message parameter name, associate the object with
210 * the name, and return the name string.
211 */
212 #define gSynthMessageParam(var) (gAction.synthMessageParam(var))
213
214
215 /* ------------------------------------------------------------------------ */
216 /*
217 * Miscellaneous macros
218 */
219
220 /* get the current player character Actor object */
221 #define gPlayerChar (libGlobal.playerChar)
222
223 /*
224 * the exit lister object - if the exits module isn't included in the
225 * game, this will be nil
226 */
227 #define gExitLister (libGlobal.exitListerObj)
228
229 /*
230 * the hint manager object - if the hints module isn't included in the
231 * game, this will be nil
232 */
233 #define gHintManager (libGlobal.hintManagerObj)
234
235
236 /* ------------------------------------------------------------------------ */
237 /*
238 * The current library messages object. This is the source object for
239 * messages that don't logically relate to the actor carrying out the
240 * comamand. It's mostly used for meta-command replies, and for text
241 * fragments that are used to construct descriptions.
242 *
243 * This message object isn't generally used for parser messages or action
244 * replies - most of those come from the objects given by the current
245 * actor's getParserMessageObj() or getActionMessageObj(), respectively.
246 *
247 * By default, this is set to libMessages. The library never changes this
248 * itself, but a game can change this if it wants to switch to a new set of
249 * messages during a game. (If you don't need to change messages during a
250 * game, but simply want to customize some of the default messages, you
251 * don't need to set this variable - you can simply use 'modify
252 * libMessages' instead. This variable is designed for cases where you
253 * want to *dynamically* change the standard messages during the game.)
254 */
255 #define gLibMessages (libGlobal.libMessageObj)
256
257
258 /* ------------------------------------------------------------------------ */
259 /*
260 * readMainCommandTokens() phase identifiers. We define a separate code
261 * for each kind of call to readMainCommandTokens() so that we can do any
262 * special token processing that depends on the type of command we're
263 * reading.
264 *
265 * The library doesn't use the phase information itself for anything.
266 * These phase codes are purely for the author's use in writing
267 * pre-parsing functions and for differentiating prompts for the different
268 * types of input, as needed.
269 *
270 * Games that read additional response types of their own are free to add
271 * their own enums to identify the additional phases. Since the library
272 * doesn't need the phase information for anything internally, it won't
273 * confuse the library at all to add new game-specific phase codes.
274 */
275
276 /* reading a normal command line */
277 enum rmcCommand;
278
279 /* reading an unknown word response, to check for an "oops" command */
280 enum rmcOops;
281
282 /* reading a response to a prompt for a missing object phrase */
283 enum rmcAskObject;
284
285 /* reading a response to a prompt for a missing literal phrase */
286 enum rmcAskLiteral;
287
288 /* reading a response to an interactive disambiguation prompt */
289 enum rmcDisambig;
290
291
292 /* ------------------------------------------------------------------------ */
293 /*
294 * Property set definitions
295 */
296
297 /* in debug mode, flag objFor definitions for non-existent actions */
298 #ifdef __DEBUG
299 # define objForCheck(which, action) \
300 sentinel##which##action = __objref(action##Action, warn)
301 #else
302 # define objForCheck(which, action)
303 #endif
304
305 #define objFor(which, action) \
306 objForCheck(which, action) \
307 propertyset '*' ## #@which ## #@action
308
309 #define dobjFor(action) objFor(Dobj, action)
310 #define iobjFor(action) objFor(Iobj, action)
311
312 /*
313 * Treat an object definition as equivalent to another object definition.
314 * These can be used immediately after a dobjFor() or iobjFor() to treat
315 * the first action as though it were the second. So, if the player types
316 * "search box", and we want to treat the direct object the same as for
317 * "look in box", we could make this definition for the box:
318 *
319 * dobjFor(Search) asDobjFor(LookIn)
320 *
321 * Note that no semicolon is needed after this definition, and that this
322 * definition is completely in lieu of a regular property set for the
323 * object action.
324 *
325 * In general, a mapping should NOT change the role of an object:
326 * dobjFor(X) should not usually be mapped using asIobjFor(Y), and
327 * iobjFor(X) shouldn't be mapped using asDobjFor(Y). The problem with
328 * changing the role is that the handler routines often assume that the
329 * object is actually in the role for which the handler was written; a
330 * verify handler might refer to '{dobj}' in generating a message, for
331 * example, so reversing the roles would give the wrong object in the role.
332 *
333 * Role reversals should always be avoided, but can be used if necessary
334 * under conditions where all of the code involved in the TARGET of the
335 * mapping can be carefully controlled to ensure that it doesn't make
336 * assumptions about object roles, but only references 'self'. Reversing
337 * roles in a mapping should never be attempted in general-purpose library
338 * code, because code based on the library could override the target of the
339 * role-reversing mapping, and the override could fail to observe the
340 * restrictions on object role references.
341 *
342 * Note that role reversals can almost always be handled with other
343 * mechanisms that handle reversals cleanly. Always consider remapTo()
344 * first when confronted with a situation that seems to call for a
345 * role-reversing asObjFor() mapping, as remapTo() specifically allows for
346 * object role changes.
347 */
348 #define asObjFor(obj, Action) \
349 { \
350 preCond { return preCond##obj##Action; } \
351 verify() { verify##obj##Action; } \
352 remap() { return remap##obj##Action; } \
353 check() { check##obj##Action; } \
354 action() { action##obj##Action; } \
355 }
356
357 #define asDobjFor(action) asObjFor(Dobj, action)
358 #define asIobjFor(action) asObjFor(Iobj, action)
359
360 /*
361 * Define mappings of everything except the action. This can be used in
362 * cases where we want to pick up the verification, preconditions, and
363 * check routines from another handler, but not the action. This is often
364 * useful for two-object verbs where the action processing is entirely
365 * provided by one or the other object, so applying it to both would be
366 * redundant.
367 */
368 #define asObjWithoutActionFor(obj, Action) \
369 { \
370 preCond { return preCond##obj##Action; } \
371 verify() { verify##obj##Action; } \
372 remap() { return remap##obj##Action(); } \
373 check() { check##obj##Action; } \
374 action() { } \
375 }
376
377 #define asDobjWithoutActionFor(action) asObjWithoutActionFor(Dobj, action)
378 #define asIobjWithoutActionFor(action) asObjWithoutActionFor(Iobj, action)
379
380 /*
381 * "Remap" an action. This effectively rewrites the action in the given
382 * form. Each of the object slots can be filled either with a specific
383 * object, or with a noun phrase role name (DirectObject, IndirectObject);
384 * in the latter case, the object or objects from the named noun phrase
385 * role in the *current* action (i.e., before the rewrite) will be used.
386 *
387 * If the new action has two or more objects (for example, if it's a
388 * TIAction), then EXACTLY ONE of the slots must be filled with a specific
389 * object, and all of the other slots must be filled with role names. The
390 * specific object is the one that corresponds to the original object
391 * that's doing the remapping in the first place - this can simply be
392 * 'self' if the new action will operate on the same object, or it can be
393 * a different object. The important thing is that the 'verify' method
394 * for the defining object will be forwarded to the corresponding 'verify'
395 * method on the corresponding object for the new action.
396 *
397 * This macro must be used as the ENTIRE definition block for a dobjFor()
398 * or iobjFor(). For example, to remap a "put in" command directed to a
399 * desk so that the command is instead applied to a drawer in the desk, we
400 * could define the following on the desk object:
401 *
402 * iobjFor(PutIn) remapTo(PutIn, DirectObject, deskDrawer)
403 */
404 #define remapTo(action, objs...) { remap = [action##Action, ##objs] }
405
406 /*
407 * Conditionally remap an action. If 'cond' (a conditional expression)
408 * evaluated to true, we'll remap the action as directed; otherwise, we'll
409 * inherit the default handling
410 */
411 #define maybeRemapTo(cond, action, objs...) \
412 { remap = ((cond) ? [action##Action, ##objs] : inherited()) }
413
414
415 /*
416 * For two-object push-travel actions, such as "push sled into cave",
417 * define a special mapping for both the direct and indirect objects:
418 *
419 * - Map the direct object (the object being pushed) to a simple
420 * PushTravel action. So, for "push sled into cave," map the direct
421 * object handling to PushTravel for the sled. This makes the handling of
422 * the command equivalent to "push sled north" and the like.
423 *
424 * - Map the indirect object (the travel connector) to use the PushTravel
425 * action's verify remapper. This is handled specially by the PushTravel
426 * action object to handle the verification as though it were verifying
427 * the corresponding ordinary (non-push) travel action on the indirect
428 * object. Beyond verification, we do nothing, since the direct object of
429 * a pushable object will handle the whole action using a nested travel
430 * action.
431 *
432 * This effectively decomposes the two-object action into two coupled
433 * single-object actions: a regular PushTravel action on the object being
434 * pushed, and a regular whatever-kind-of-travel on the connector being
435 * traversed. This handling has the appeal that it means that we don't
436 * need a separate PUSH version of every kind of allowed travel on a
437 * connector, and we don't need a special handler version for each kind of
438 * travel on a pushable object; instead, we just use the basic PushTravel
439 * and kind-of-travel handlers to form the combined form. Note that this
440 * still allows separate treatment of the combined form wherever desired,
441 * just by overriding these default handlers for the two-object action.
442 */
443 #define mapPushTravelHandlers(pushAction, travelAction) \
444 dobjFor(pushAction) asDobjFor(PushTravel) \
445 mapPushTravelIobj(pushAction, travelAction)
446
447 #define mapPushTravelIobj(pushAction, travelAction) \
448 iobjFor(pushAction) \
449 { \
450 verify() \
451 { gAction.verifyPushTravelIobj(self, travelAction##Action); } \
452 }
453
454
455 /* ------------------------------------------------------------------------ */
456 /*
457 * For an Actor, delegate an action handler to the ActorState object for
458 * processing. You can use this any time you want to write the handlers
459 * for a particular action in the ActorState rather than in the Actor
460 * itself. This would be desirable if the actor's response for a
461 * particular action varies considerably according to the actor's state.
462 * For example, if you want an actor's response to being attacked to be
463 * handled in the actor's current ActorState object, you could put this
464 * code in the Actor object:
465 *
466 * dobjFor(AttackWith) actorStateDobjFor(AttackWith)
467 *
468 * Once you've done this, you'd just write a normal dobjFor(AttackWith)
469 * handler in each of the ActorState objects associated with the actor.
470 */
471 #define actorStateObjFor(obj, Action) \
472 { \
473 preCond { return curState.preCond##obj##Action; } \
474 verify() { curState.verify##obj##Action; } \
475 remap() { return curState.remap##obj##Action; } \
476 check() { curState.check##obj##Action; } \
477 action() { curState.action##obj##Action; } \
478 }
479
480 #define actorStateDobjFor(action) actorStateObjFor(Dobj, action)
481 #define actorStateIobjFor(action) actorStateObjFor(Iobj, action)
482
483
484 /* ------------------------------------------------------------------------ */
485 /*
486 * Object role identifiers. These are used to identify the role of a noun
487 * phrase in a command.
488 *
489 * The library provides base classes for actions of zero, one, and two noun
490 * phrases in their grammars: "look", "take book", "put book on shelf". We
491 * thus define role identifiers for direct and indirect objects. Note that
492 * even though we stop there, this doesn't preclude games or library
493 * extensions from adding actions that take more than two noun phrases
494 * ("put coin in slot with tongs"); any such extensions must simply define
495 * their own additional role identifiers for the third or fourth (etc) noun
496 * phrase.
497 */
498 enum ActorObject, DirectObject, IndirectObject;
499
500 /*
501 * A special role for the "other" object of a two-object command. This
502 * can be used in certain contexts (such as remapTo) where a particular
503 * object role is implied by the context, and where the action involved
504 * has exactly two objects; OtherObject in such contexts means
505 * DirectObject when the implied role is IndirectObject, and vice versa.
506 */
507 enum OtherObject;
508
509
510 /* ------------------------------------------------------------------------ */
511 /*
512 * Pronoun types. These are used to identify pronoun antecedents when
513 * resolving noun phrases involving pronouns.
514 *
515 * We define a basic set of pronouns here that are common to most
516 * languages. Language-specific modules are free to add their own pronoun
517 * types as needed.
518 *
519 * Our basic set is:
520 *
521 * 'it' - the neuter singular
522 *. 'him' - the masculine singular
523 *. 'her' - the feminine singular
524 *. 'them' - the ungendered plural
525 *. 'you' - second person singular
526 *. 'me' - first person singular
527 *
528 * Note that the first-person and second-person pronouns are assigned
529 * meanings that can vary by context. When a command is issued by the
530 * player character to the player character (i.e., the command comes from
531 * the player and no target actor is specified), these refer to the player
532 * character when the PC is in the appropriate referral person - if the
533 * game calls the PC "you", then the player calls the PC "me", and vice
534 * versa. When a command is targeted to or issued by an actor other than
535 * the PC, then "you" refers to the command's target and "me" refers to
536 * the command's issuer.
537 */
538 enum PronounIt, PronounThem, PronounHim, PronounHer, PronounYou, PronounMe;
539
540
541 /* ------------------------------------------------------------------------ */
542 /*
543 * set the location property
544 */
545 + property location;
546
547
548 /* ------------------------------------------------------------------------ */
549 /*
550 * Alternative exit definition. This can be used to define a secondary
551 * direction that links to the same destination, via the same connector, as
552 * another direction. It's frequently desirable to link multiple
553 * directions to the same exit; for example, a door leading north might
554 * also lead out, or a stairway to the north could lead up as well.
555 *
556 * Use this as follows in a room's property list:
557 *
558 *. out asExit(north)
559 *
560 * (Note that there's no '=' sign.)
561 *
562 * It's not necessary to use this macro to declare an alternative exit,
563 * since the alternatives can all point directly to the same connector as
564 * the original. The only thing this macro does is to make the alternative
565 * exit unlisted - it won't be shown in the list of exits in the status
566 * line, and it won't be shown in "you can't go that way" messages.
567 *
568 * Note that there's one common case where you should be careful with
569 * asExit(): if you have a room that has an exit in some compass direction,
570 * you might be tempted to make OUT the primary "direction" for the exit,
571 * and treat the equivalent compass as a synonym, with a line such as
572 * "south asExit(out)". You should avoid doing this - do it the other way
573 * instead, with the compass direction as the primary direction and OUT as
574 * the synonym: "out asExit(south)". The reason this is important is that
575 * if there's a nested room inside the location (such as a chair), OUT
576 * while in the nested room will mean to get out of the nested room. If
577 * you make the compass direction primary and make OUT the synonym, the
578 * compass direction will be listed as an available exit both in the
579 * location and in any nested rooms within it.
580 */
581 #define asExit(dir) = static ((dir).createUnlistedProxy())
582
583
584 /* ------------------------------------------------------------------------ */
585 /*
586 * "Person" indices. We define these as numbers rather than enums so that
587 * we can easily use these as list indices.
588 */
589 #define FirstPerson 1
590 #define SecondPerson 2
591 #define ThirdPerson 3
592
593
594 /* ------------------------------------------------------------------------ */
595 /*
596 * Transparency levels
597 */
598
599 /* the sense is passed without loss of detail */
600 enum transparent;
601
602 /* the sense is passed, but with a loss of detail associated with distance */
603 enum distant;
604
605 /*
606 * The sense is passed, but with attenuation of energy level. No other
607 * obscuration of detail occurs; this is something like tinted glass that
608 * doesn't distort the transmitted sense but reduces the amount of energy.
609 */
610 enum attenuated;
611
612 /*
613 * The sense is passed, but with a loss of detail due to an obscuring
614 * layer of material. The energy level is also attenuated. This is
615 * something like dirty or wavy glass that distorts an image transmitted
616 * through it but doesn't completely block out light.
617 */
618 enum obscured;
619
620 /* the sense is not passed at all */
621 enum opaque;
622
623
624 /* ------------------------------------------------------------------------ */
625 /*
626 * Size classes. An object is large, medium, or small with respect to
627 * each sense; the size is used to determine how well the object can be
628 * sensed at a distance or when obscured.
629 *
630 * What "size" means depends on the sense. For sight, the size
631 * indicates the visual size of the object. For hearing, the size
632 * indicates the loudness of the object.
633 */
634
635 /*
636 * Large - the object is large enough that its details can be sensed
637 * from a distance or through an obscuring medium.
638 */
639 enum large;
640
641 /*
642 * Medium - the object can be sensed at a distance or when obscured, but
643 * not in any detail. Most objects fall into this category. Note that
644 * things that are parts of large objects should normally be medium.
645 */
646 enum medium;
647
648 /*
649 * Small - the object cannot be sensed at a distance at all. This is
650 * appropriate for detailed parts of medium-class objects.
651 */
652 enum small;
653
654
655 /* ------------------------------------------------------------------------ */
656 /*
657 * Path traversal operations.
658 */
659
660 /* traverse from the starting point of the path */
661 enum PathFrom;
662
663 /* traverse into the contents */
664 enum PathIn;
665
666 /* traverse out to the container */
667 enum PathOut;
668
669 /* traverse from an object to a peer at the same containment level */
670 enum PathPeer;
671
672 /*
673 * traverse through an object with no common container on either side of
674 * the traversal - this is used when we are traversing an object, such as a
675 * SenseConnector, that connects unrelated locations
676 */
677 enum PathThrough;
678
679 /* traverse to the ending point of the path */
680 enum PathTo;
681
682
683 /* ------------------------------------------------------------------------ */
684 /*
685 * Listing Options
686 */
687
688 /*
689 * use "tall" notation, which lists objects in a single column, one item
690 * per line (the default is "wide" notation, which creates a sentence
691 * with the object listing)
692 */
693 #define ListTall 0x0001
694
695 /*
696 * Recursively list the contents of each item we list.
697 *
698 * For a 'tall' list, this indicates that we'll show the listed contents
699 * of each item that we list, and the listed contents of those items, and
700 * so on, indenting each level to indicate the containment relationship.
701 *
702 * For a 'wide' list, this indicates that we'll show the listed contents
703 * of each item in-line in the listing, as a parenthetic note.
704 *
705 * For both types of listings, when this flag is set and the indent level
706 * is zero (indicating a top-level listing), after the main list, we'll
707 * show a separate list for the contents of each item in our list that
708 * isn't itself listable but has listed contents, or has contents with
709 * listed contents, and so on to any level. For example, if we're showing
710 * a room description, and the room contains a desk that isn't listed
711 * because it's a fixed part of the room, we'll show a separate list of
712 * the desk's listed contents.
713 */
714 #define ListRecurse 0x0002
715
716 /*
717 * use "long list" notation - separates items that contain sublists with
718 * special punctuation, to set off the individual items in the longer
719 * listing from the items in the sublists (for example, separates items
720 * with semicolons rather than commas)
721 */
722 #define ListLong 0x0004
723
724 /*
725 * This is a recursive listing of the contents of an item. This is set by
726 * showList() in calls it makes to recursive listing levels.
727 */
728 #define ListContents 0x0008
729
730 /*
731 * Custom option bits. Flag bits with this value and higher are reserved
732 * for use by individual lister subclasses.
733 *
734 * To ensure compatibility with any future changes that involve adding
735 * more base lister flags, subclasses are encouraged to use the following
736 * mechanism. DO NOT use #define to define your own custom subclass
737 * flags. Instead, define a property of your lister subclass for each
738 * flag you need as follows:
739 *
740 * myCustomFlag1 = ListerCustomFlag(1) // use 1 for the first flag
741 *. myCustomFlag2 = ListerCustomFlag(2) // etc
742 *. nextCustomFlag = ListerCustomFlag(3)
743 *
744 * You DO NOT have to use the name 'myCustomFlag1' - use whatever name you
745 * like that describes the nature of the flag. However, the last item
746 * MUST be called 'nextCustomFlag' - this ensures that any subclasses of
747 * your class will allocate their own flags with new values that don't
748 * conflict with any of yours.
749 *
750 * Then, when a client of your Lister subclass needs to pass one of your
751 * flag to the Lister, it should simply evaluate your 'myCustomFlagN'
752 * property of your lister. If you'd like, you can even #define a ListXxx
753 * macro that retrieves the value, for the convenience of your callers:
754 *
755 * #define ListMyclassMyCustomFlag1 (Myclass.myCustomFlag1)
756 */
757 #define ListCustomFlag 0x0100
758
759 #define ListerCustomFlag(n) static ((inherited.nextCustomFlag) << ((n) - 1))
760
761
762 /* ------------------------------------------------------------------------ */
763 /*
764 * Spelled-out number options, for spellInt() and related functions.
765 *
766 * Note that the interfaces to the number-spelling functions can vary by
767 * language, and that variation can include these flags. Some language
768 * modules might ignore some of these generic flags or define additional
769 * language-specific flags.
770 */
771
772 /*
773 * Use tens of hundreds rather than thousands if possible - 1950 is
774 * 'nineteen hundred fifty' rather than 'one thousand nine hundred
775 * fifty'. This only works if the number (not including the millions
776 * and billions) is in the range 1,100 to 9,999, because we don't want
777 * to say something like 'one hundred twenty hundred' for 12,000.
778 */
779 #define SpellIntTeenHundreds 0x0001
780
781 /*
782 * use 'and' before the tens - 125 is 'one hundred and twenty-five'
783 * rather than 'one hundred twenty-five'
784 */
785 #define SpellIntAndTens 0x0002
786
787 /*
788 * put a comma after each power group - 123456 is 'one hundred
789 * twenty-three thousand, four hundred fifty-six'
790 */
791 #define SpellIntCommas 0x0004
792
793
794 /* ------------------------------------------------------------------------ */
795 /*
796 * Decimal number format options. These are used with the number
797 * formatting functions to control the formatting of numbers displayed in
798 * decimal digit format.
799 */
800
801 /*
802 * Use a group separator character between digit groups, using the
803 * default setting in languageGlobals.
804 */
805 #define DigitFormatGroupSep 0x0001
806
807 /*
808 * Explicitly use a comma/period to separate digit groups, overriding
809 * the current languageGlobals setting.
810 */
811 #define DigitFormatGroupComma 0x0002
812 #define DigitFormatGroupPeriod 0x0004
813
814
815 /* ------------------------------------------------------------------------ */
816 /*
817 * aHref() flags
818 */
819 #define AHREF_Plain 0x0001 /* plain text hyperlink (no underline/color) */
820
821
822 /* ------------------------------------------------------------------------ */
823 /*
824 * ResolveInfo flags
825 */
826
827 /* the noun phrase ends with an adjective */
828 #define EndsWithAdj 0x0001
829
830 /*
831 * one of the words in the noun phrase was truncated from its full
832 * dictionary spelling
833 */
834 #define VocabTruncated 0x0002
835
836 /*
837 * One or more plurals was truncated from its full dictionary spelling.
838 * (We specially distinguish plurals that are truncated, because in
839 * English a plural is usually formed by adding "s" or "es" to the end of
840 * the singular form of a noun, meaning that a given singular form is
841 * usually a leading substring of its plural. When a singular noun is
842 * longer than the truncation limit, which is conventionally six
843 * characters, the singular will always match as a truncated version of
844 * the plural, so every time someone types in a singular it'll be treated
845 * as ambiguous between the singular and plural form. So, in the English
846 * parser, we have a preference to ignore a truncated plural any time the
847 * word could also be interpreted as an untruncated singular, hence we
848 * note when we have a truncated plural.)
849 */
850 #define PluralTruncated 0x0004
851
852 /*
853 * The object came from an 'all' phrase. Normally, the only time this
854 * makes any difference is when deciding whether or not to mention which
855 * object we're acting upon; an 'all' object should normally be mentioned
856 * explicitly, as though the command had involved multiple objects,
857 * because otherwise it might not be clear to the user what object had
858 * actually matched 'all'.
859 */
860 #define MatchedAll 0x0008
861
862 /*
863 * Always announce the object before executing the command on it. This
864 * flag can be set for objects that match phrases whose meaning isn't
865 * necessarily known to the player, such as "all" (which selects objects
866 * based on the simulation state, which might not exactly match what the
867 * player had in mind) or "any book" (which might select arbitrarily from
868 * several possibilities, so the player can't know which we'll choose).
869 */
870 #define AlwaysAnnounce 0x0010
871
872 /*
873 * The noun phrase describing this object was ambiguous, and the object
874 * was selected by automatic disambiguation in a context where it was
875 * clear which object was indicated. This is used in cases where the
876 * objects not selected were all illogical for the action context.
877 */
878 #define ClearDisambig 0x0020
879
880 /*
881 * The noun phase describing this object was ambiguous, and the object was
882 * selected by automatic disambiguation in a context where it was not
883 * perfectly clear which object was indicated. This is used for cases
884 * where the objects selected were more logical than the objects not
885 * selected, but some of the unselected objects were still logical.
886 *
887 * This flag doesn't mean that we chose arbitrarily, but rather that we
888 * chose the best object or objects from a field that included additional
889 * objects that, though not quite as good, were still valid. We flag this
890 * case because the user *could* have meant to use one of the other valid
891 * objects, even though we consider it most likely that the user meant to
892 * use the one(s) we selected; so, we want to flag this so we can call the
893 * user's attention to our choice, to make it more likely that the user
894 * will immediately notice if we made the wrong choice.
895 *
896 * Note that we can't have both ClearDisambig and UnclearDisambig at the
897 * same time, but we *can* have neither of these. If neither flag is set
898 * for an object, it simply means that the object wasn't ambiguous to
899 * start with. When the user explicitly picks an object interactively,
900 * the selected object is effectively unambiguous, so it won't have either
901 * flag set; even though it started off ambiguous, the user did all of the
902 * work of selecting the appropriate object, leaving things unambiguous in
903 * the end.
904 */
905 #define UnclearDisambig 0x0040
906
907 /*
908 * The noun phrase was missing from the command and this object was
909 * supplied as an implicit default.
910 */
911 #define DefaultObject 0x0080
912
913 /*
914 * We've announced this as a defaulted object. We use this to ensure that
915 * we only make this type of announcement once, even if the opportunity to
916 * make the announcement comes up more than once; this can happen when
917 * we're asking for missing objects interactively in a multi-object
918 * command, since we might want to announce a default before prompting as
919 * well as before execution.
920 */
921 #define AnnouncedDefaultObject 0x0100
922
923
924 /* ------------------------------------------------------------------------ */
925 /*
926 * Announcement styles for disambiguated objects. These are used in the
927 * gameMain object (see GameMainDef) to select which type of announcement
928 * is used when the parser disambiguates a noun phrase using the
929 * logicalness rules.
930 */
931
932 /*
933 * Announce unclear disambiguation results only. When this setting is
934 * selected, the parser makes a parenthetical announcement (e.g., "(the red
935 * door)") when it selects an object based on likelihood rankings from
936 * among more than one logical match. The parser makes no announcement
937 * when exactly one logical object is in scope, even if other objects match
938 * the noun phrase by name.
939 */
940 enum AnnounceUnclear;
941
942 /*
943 * Announce clear and unclear disambiguation results, both using
944 * parenthetical announcement ("(the red door)"). When this setting is
945 * selected, the parser makes these announcements every time it applies the
946 * logicalness rules or likelihood rankings to disambiguate a noun phrase.
947 * There's no announcement when no disambiguation is needed (because the
948 * noun phrase matches only one in-scope object).
949 */
950 enum AnnounceClear;
951
952 /*
953 * Describe clear disambiguation results, rather than announcing them. The
954 * parser makes the parenthetical announcement, as usual, for unclear
955 * disambiguation picks, but not for clear picks (a clear pick is one where
956 * there's only one logical object, even though the noun phrase matches
957 * more than one object). For clear picks, however, the parser uses a
958 * verbose version of the action reply in lieu of one of the terse default
959 * messages. For example, rather than saying just "Taken", the parser
960 * would reply "You take the red book." The longer messages mention the
961 * object by name, to make it clear exactly which one was chosen.
962 */
963 enum DescribeClear;
964
965
966 /* ------------------------------------------------------------------------ */
967 /*
968 * Inventory modes. "Wide" mode displays the inventory in paragraph form;
969 * "tall" mode displays as a list, with one item per line, indenting items
970 * to reflect containment.
971 */
972 enum InventoryWide, InventoryTall;
973
974
975 /* ------------------------------------------------------------------------ */
976 /*
977 * Define an action with the given base class. This adds the *Action
978 * suffix to the given root name, and defines a class with the given base
979 * class. We also define the baseActionClass property to refer to myself;
980 * this is the canonical class representing the action for all subclasses.
981 * This information is useful because a language module might define
982 * several grammar rule subclasses for the given class; this lets us
983 * relate any instances of those various subclasses back to this same
984 * canonical class for the action if necessary.
985 */
986 #define DefineAction(name, baseClass...) \
987 class name##Action: ##baseClass \
988 baseActionClass = name##Action
989
990 /*
991 * Define a "system" action. System actions are meta-game commands, such
992 * as SAVE and QUIT, that generally operate the user interface and are not
993 * part of the game world.
994 */
995 #define DefineSystemAction(name) \
996 DefineAction(name, SystemAction)
997
998 /*
999 * Define a concrete IAction, given the root name for the action. We'll
1000 * automatically generate a class with name XxxAction.
1001 */
1002 #define DefineIAction(name) \
1003 DefineAction(name, IAction)
1004
1005 /* define a conversational IAction, such as Hello, Goodbye, Yes, No */
1006 #define DefineConvIAction(name) \
1007 DefineAction(name, ConvIAction)
1008
1009 /*
1010 * Define a concrete TAction, given the root name for the action. We'll
1011 * automatically generate a class with name XxxAction, a verProp with name
1012 * verXxx, a checkProp with name checkXxx, and an actionProp with name
1013 * actionDobjXxx.
1014 */
1015 #define DefineTAction(name) \
1016 DefineTActionSub(name, TAction)
1017
1018 /*
1019 * Define a concrete TAction with a specific base class.
1020 */
1021 #define DefineTActionSub(name, cls) \
1022 DefineAction(name, cls) \
1023 verDobjProp = &verifyDobj##name \
1024 remapDobjProp = &remapDobj##name \
1025 preCondDobjProp = &preCondDobj##name \
1026 checkDobjProp = &checkDobj##name \
1027 actionDobjProp = &actionDobj##name \
1028
1029 /*
1030 * Define a concrete TIAction, given the root name for the action. We'll
1031 * automatically generate a class with name XxxAction, a verDobjProp with
1032 * name verDobjXxx, a verIobjProp with name verIobjxxx, a checkDobjProp
1033 * with name checkDobjXxx, a checkIobjProp with name checkIobjXxx, an
1034 * actionDobjProp with name actionDobjXxx, and an actionIobjProp with name
1035 * actionIobjXxx.
1036 */
1037 #define DefineTIAction(name) \
1038 DefineTIActionSub(name, TIAction)
1039
1040 /*
1041 * Define a concrete TIAction with a specific base class.
1042 */
1043 #define DefineTIActionSub(name, cls) \
1044 DefineAction(name, cls) \
1045 verDobjProp = &verifyDobj##name \
1046 verIobjProp = &verifyIobj##name \
1047 remapDobjProp = &remapDobj##name \
1048 remapIobjProp = &remapIobj##name \
1049 preCondDobjProp = &preCondDobj##name \
1050 preCondIobjProp = &preCondIobj##name \
1051 checkDobjProp = &checkDobj##name \
1052 checkIobjProp = &checkIobj##name \
1053 actionDobjProp = &actionDobj##name \
1054 actionIobjProp = &actionIobj##name
1055
1056 /*
1057 * Define a concrete TopicAction, given the root name for the action.
1058 */
1059 #define DefineTopicAction(name) \
1060 DefineAction(name, TopicAction)
1061
1062 /*
1063 * Define a concrete TopicTAction, given the root name for the action.
1064 * 'which' gives the role the topic serves, for message generation purposes
1065 * - this should be one of the object role enums (DirectObject,
1066 * IndirectObject, etc) indicating which role the topic plays in the
1067 * action's grammar.
1068 */
1069 #define BaseDefineTopicTAction(name, which, cls) \
1070 DefineAction(name, cls) \
1071 verDobjProp = &verifyDobj##name \
1072 remapDobjProp = &remapDobj##name \
1073 preCondDobjProp = &preCondDobj##name \
1074 checkDobjProp = &checkDobj##name \
1075 actionDobjProp = &actionDobj##name \
1076 whichMessageTopic = which
1077
1078 #define DefineTopicTAction(name, which) \
1079 BaseDefineTopicTAction(name, which, TopicTAction)
1080
1081 /*
1082 * Define a concrete ConvTopicTAction. This is just like defining a
1083 * TopicTAction, but defines the action using the ConvTopicTAction
1084 * subclass.
1085 */
1086 #define DefineConvTopicTAction(name, which) \
1087 BaseDefineTopicTAction(name, which, ConvTopicTAction)
1088
1089 /*
1090 * Define a concrete LiteralAction, given the root name for the action.
1091 */
1092 #define DefineLiteralAction(name) \
1093 DefineAction(name, LiteralAction)
1094
1095 /*
1096 * Define a concrete LiteralTAction, given the root name for the action.
1097 * 'which' gives the role the literal phrase serves, for message generation
1098 * purposes - this should be one of the object role enums (DirectObject,
1099 * IndirectObject, etc) indicating which role the topic plays in the
1100 * action's grammar.
1101 */
1102 #define DefineLiteralTAction(name, which) \
1103 DefineAction(name, LiteralTAction) \
1104 verDobjProp = &verifyDobj##name \
1105 remapDobjProp = &remapDobj##name \
1106 preCondDobjProp = &preCondDobj##name \
1107 checkDobjProp = &checkDobj##name \
1108 actionDobjProp = &actionDobj##name \
1109 whichMessageLiteral = which
1110
1111 /* ------------------------------------------------------------------------ */
1112 /*
1113 * Convenience macros for setting verify results.
1114 *
1115 * A verify routine can use these macros to set any number of verify
1116 * results. The VerifyResultList will keep only the result that gives the
1117 * strongest disapproval of the action, since the verification process is
1118 * by its nature only interested in the most negative result.
1119 *
1120 * These macros take advantage of the fact that we have a global
1121 * VerifyResultList object, which gathers the results of the verification,
1122 * so they can be used only in verify routines. The global verification
1123 * results object is valid during each verification invocation.
1124 */
1125
1126 /*
1127 * Command is logical. There's generally no need to add a logical result
1128 * explicitly, since a command is logical unless disapproved, but we
1129 * include this for completeness.
1130 *
1131 * We use 100 as the default likelihood, to leave plenty of room for
1132 * specific likelihood rankings both above and below the default level.
1133 */
1134 #define logical \
1135 (gVerifyResults.addResult(new LogicalVerifyResult(100, '', 100)))
1136
1137 /*
1138 * Command is logical, and is ranked as indicated among logical results.
1139 * The 'rank' value is the likelihood rank; the higher the rank, the more
1140 * logical the command is. The rank is only used to establish an ordering
1141 * of the logical results; if a command also has illogical results, all of
1142 * the illogical results rank as less logical than the logical result with
1143 * the lowest likelihood.
1144 *
1145 * The 'key' value is an arbitrary string value associated with the
1146 * ranking. When two result lists both have a logical result object, and
1147 * both logical result objects have the same likelihood level, we'll check
1148 * the keys; if the keys match, we'll treat the two results as equivalent
1149 * and thus not distinguishing for disambiguation. This is useful because
1150 * it creates a crude multivariate space for ranking items for
1151 * disambiguation.
1152 *
1153 * For example, suppose we have a "put in" command, and we have two
1154 * possibilities for the target container. Neither is being held by the
1155 * actor, so they both have a result with a logical rank of 70 with a key
1156 * value of 'not held'. In addition, both are openable, and one is open
1157 * and the other is closed; the closed one has an additional result with a
1158 * logical rank of 80 and a key of 'not open'. Which do we choose? If we
1159 * looked only at the logical rankings, both would be equivalent, since
1160 * both have 70's as their most disapproving results. However, we see
1161 * that the two 70's were applied for the same reason - because they share
1162 * a common key - so we know this information isn't helpful for
1163 * disambiguation and can be ignored. So, we find that the closed one has
1164 * an 80, and the other has no other results (hence is by default logical
1165 * with rank 100), thus we take the '80' as the better one.
1166 *
1167 * Throughout the library, we use the following conventions:
1168 *
1169 * 150 = especially good fit: a good candidate for the action that is
1170 * especially likely to be used with the command. For example, a book is
1171 * especially suitable for a "read" command.
1172 *
1173 * 140 = similar to 150, but slightly less ideal a fit. We use this for
1174 * objects that are excellent fits, but for which we know certain other
1175 * objects might be better fits.
1176 *
1177 * 100 = default: a perfectly good candidate for the action, with nothing
1178 * that would make it illogical, but nothing that makes it especially
1179 * likely, either
1180 *
1181 * 80 = slightly less than perfect: a good candidate, but with some
1182 * temporary and correctable attribute that may make it less likely than
1183 * others. This is used for attributes that can be corrected: a container
1184 * needs to be opened for the action to succeed, but isn't currently open,
1185 * or an article of clothing cannot be worn for the action to proceeds,
1186 * but is currently being worn.
1187 *
1188 * 60/70 = slightly less than perfect, but with some attributes that can't
1189 * be readily corrected and which make the candidate potentially less
1190 * likely. These are used to make guesses about which might object might
1191 * be intended when several are logical but some might be more readily
1192 * used than others; for example, if putting an object into a container, a
1193 * container being held might rank higher than one not being held, so the
1194 * one not being held might be ranked a "70" likelihood.
1195 *
1196 * 50 = logical but not especially likely: an acceptable candidate for the
1197 * action, but probably not the best choice for the action. This is used
1198 * when an object can be used for the action, but would not be expected to
1199 * do anything special with the action.
1200 */
1201 #define logicalRank(rank, key) \
1202 (gVerifyResults.addResult(new LogicalVerifyResult(rank, key, 100)))
1203
1204 /*
1205 * Logical ranking with specific list ordering. This is the same as a
1206 * regular logicalRank, but uses the given list ordering rather than the
1207 * default list ordering (100).
1208 */
1209 #define logicalRankOrd(rank, key, ord) \
1210 (gVerifyResults.addResult(new LogicalVerifyResult(rank, key, ord)))
1211
1212 /* command is logical but dangerous */
1213 #define dangerous \
1214 (gVerifyResults.addResult(new DangerousVerifyResult('')))
1215
1216 /*
1217 * command is logical but non-obvious: the object should never be taken as
1218 * a default
1219 */
1220 #define nonObvious \
1221 (gVerifyResults.addResult(new NonObviousVerifyResult('')))
1222
1223 /* command is currently (but not always) illogical, for the given reason */
1224 #define illogicalNow(msg, params...) \
1225 (gVerifyResults.addResult(new IllogicalNowVerifyResult(msg, ##params)))
1226
1227 /* illogical because things are already as the command would make them */
1228 #define illogicalAlready(msg, params...) \
1229 (gVerifyResults.addResult( \
1230 new IllogicalAlreadyVerifyResult(msg, ##params)))
1231
1232 /* command is always illogical */
1233 #define illogical(msg, params...) \
1234 (gVerifyResults.addResult(new IllogicalVerifyResult(msg, ##params)))
1235
1236 /* illogical since we're trying to use something on itself (eg, PUT X IN X) */
1237 #define illogicalSelf(msg, params...) \
1238 (gVerifyResults.addResult(new IllogicalSelfVerifyResult(msg, ##params)))
1239
1240 /* command is being performed on an inaccessible object */
1241 #define inaccessible(msg, params...) \
1242 (gVerifyResults.addResult(new InaccessibleVerifyResult(msg, ##params)))
1243
1244
1245 /* ------------------------------------------------------------------------ */
1246 /*
1247 * Convenience macros for setting command results.
1248 */
1249
1250 /*
1251 * Set a default report for the current command. This report will be
1252 * shown unless a non-default report is issued, or if the default report
1253 * is to be suppressed (for example, because the command is being
1254 * performed implicitly as part of another command).
1255 *
1256 * Default reports should be used only for simple acknowledgments of the
1257 * command's successful completion - things like "Taken" or "Dropped" or
1258 * "Done."
1259 *
1260 * Default responses are suppressed for implicit commands because they are
1261 * redundant. When a command is performed implicitly, it is conventional
1262 * to mention the command being performed with a parenthetical: "(First
1263 * taking the book)". In such cases, a simple acknowledgment that the
1264 * command was successfully performed would add nothing of use but would
1265 * merely make the output more verbose, so we omit it.
1266 */
1267 #define defaultReport(msg, params...) \
1268 (gTranscript.addReport(new DefaultCommandReport(msg, ##params)))
1269
1270 /*
1271 * Set a default descriptive report for the current command. This report
1272 * will be shown unless any other report is shown for the same command.
1273 * This differs from defaultReport in that we don't suppress a default
1274 * description for an implied command: we only suppress a default
1275 * description when there are other reports for the same command.
1276 *
1277 * The purpose of the default descriptive report is to generate reports
1278 * that say things along the lines that there's nothing special to
1279 * describe. For example:
1280 *
1281 * >x desk
1282 *. You see nothing special about it.
1283 *
1284 * >look in alcove
1285 *. There's nothing in the alcove.
1286 *
1287 * When there's nothing else to report, these default descriptions are
1288 * suitable as the full response to the command. However, they become
1289 * undesirable when we have other "status" information or related special
1290 * descriptions to display; consider:
1291 *
1292 * >x desk
1293 *. You see nothing special about it.
1294 *. Someone has jabbed a dagger into the top of the desk.
1295 *
1296 * >look in alcove
1297 *. There's nothing in the alcove.
1298 *. A vase is displayed in the alcove.
1299 *
1300 * >x bag
1301 *. You see nothing special about it. It's open, and it contains
1302 *. a red book, an iron key, and a brass key.
1303 *
1304 * In the first two examples above, we have special descriptions for
1305 * objects contained in the objects being described. The special
1306 * descriptions essentially contradict the default descriptions' claims
1307 * that there's nothing special to mention, and also render the default
1308 * descriptions unnecessary, in that it would be enough to show just the
1309 * special descriptions. The third example above is similar, but the
1310 * extra information is status information for the object being described
1311 * rather than a special description of a contained item; as with the
1312 * other examples, the generic default description is both contradictory
1313 * and unnecessary.
1314 *
1315 * Default description reports should ONLY be used for messages that have
1316 * the character of the examples above: generic descriptions that indicate
1317 * explicitly that there's nothing special to report. Messages that offer
1318 * any sort of descriptive detail should NOT be generated as default
1319 * description reports, because it is suitable and desirable to retain an
1320 * actual descriptive message even when other status information or
1321 * related special descriptions are also shown.
1322 */
1323 #define defaultDescReport(msg, params...) \
1324 (gTranscript.addReport(new DefaultDescCommandReport(msg, ##params)))
1325
1326 /*
1327 * Add an cosmetic internal spacing report. This type of report is used
1328 * to show spacing (usually a paragraph break) within command output.
1329 *
1330 * The important thing about this report is that it doesn't trigger
1331 * suppression of any default reports. This is useful when internal
1332 * separation is added on speculation that there might be some reports to
1333 * separate, but without certainty that there will actually be any reports
1334 * shown; for example, when preparing to show a list of special
1335 * descriptions, we might add some spacing just in case some special
1336 * descriptions will be shown, saving the trouble of checking to see if
1337 * anything actually needs to be shown.
1338 */
1339 #define cosmeticSpacingReport(msg, params...) \
1340 (gTranscript.addReport(new CosmeticSpacingCommandReport(msg, ##params)))
1341
1342 /*
1343 * Add an "extra" report. This is an incidental message that doesn't
1344 * affect the display of a default report.
1345 */
1346 #define extraReport(msg, params...) \
1347 (gTranscript.addReport(new ExtraCommandReport(msg, ##params)))
1348
1349 /*
1350 * Set a main report for the current command. This report will be shown
1351 * as the main report from the command, overriding any default report for
1352 * the command.
1353 */
1354 #define mainReport(msg, params...) \
1355 (gTranscript.addReport(new MainCommandReport(msg, ##params)))
1356
1357 /*
1358 * Set a "before" report for the current command. This report will be
1359 * shown before any main report, but will override any default report for
1360 * the command.
1361 */
1362 #define reportBefore(msg, params...) \
1363 (gTranscript.addReport(new BeforeCommandReport(msg, ##params)))
1364
1365 /*
1366 * Set an "after" report for the current command. This report will be
1367 * shown after any main report, but will override any default report for
1368 * the command.
1369 */
1370 #define reportAfter(msg, params...) \
1371 (gTranscript.addReport(new AfterCommandReport(msg, ##params)))
1372
1373 /*
1374 * Report failure. This overrides any default report, and marks the
1375 * command as having failed.
1376 *
1377 * A failure report should NOT indicate any state change - this is
1378 * important because failure reports are suppressed under some conditions
1379 * (for example, when an NPC is performing an implied command, and the
1380 * implied command fails, we don't show the failure report). If a failure
1381 * is accompanied by a state change, then a mainReport() should be made in
1382 * addition to the failure report - the main report should indicate the
1383 * state change.
1384 */
1385 #define reportFailure(msg, params...) \
1386 (gTranscript.addReport(new FailCommandReport(msg, ##params)))
1387
1388 /*
1389 * Report a question. This shows a report that's really an interactive
1390 * prompt for more information, such as a prompt for a missing object.
1391 */
1392 #define reportQuestion(msg, params...) \
1393 (gTranscript.addReport(new QuestionCommandReport(msg, ##params)))
1394
1395
1396 /* ------------------------------------------------------------------------ */
1397 /*
1398 * Thing message property overrides sometimes need to be selective about
1399 * the role of the object. These macros let you specify that a Thing
1400 * message override is only in effect when the Thing is the direct or
1401 * indirect object. When the object isn't in the specified role, the
1402 * message override will be ignored.
1403 *
1404 * For example, suppose you want to override an object's response to PUT
1405 * IN, but *only* when it's the indirect object of PUT IN - *not* when the
1406 * object is itself being put somewhere. To do this, you could give the
1407 * object a property like this:
1408 *
1409 *. notAContainerMsg = iobjMsg('The vase\'s opening is too small. ')
1410 *
1411 * This specifies that when the object is involved in a PUT IN command that
1412 * fails with the 'notAContainerMsg' message, the given message should be
1413 * used - but *only* when the object is the indirect object.
1414 */
1415 #define dobjMsg(msg) (gDobj == self ? msg : nil)
1416 #define iobjMsg(msg) (gIobj == self ? msg : nil)
1417
1418
1419 /* ------------------------------------------------------------------------ */
1420 /*
1421 * Try performing a command implicitly. The action is the root name of
1422 * the action, without the 'Action' suffix - we'll automatically add the
1423 * suffix. 'objs' is a varying-length list of the resolved objects in the
1424 * new action - the direct object, indirect object, and any others needed
1425 * for the action.
1426 */
1427 #define tryImplicitAction(action, objs...) \
1428 _tryImplicitAction(gIssuingActor, gActor, &announceImplicitAction, \
1429 action##Action, ##objs)
1430
1431 /*
1432 * Try performing a command implicitly, with a special descriptive
1433 * message. 'msgProp' gives the libMessages method to invoke the announce
1434 * the action, if the action is performed. If 'msgProp' is nil, no
1435 * message is displayed at all.
1436 *
1437 * 'action' is the root name of the action, without the 'Action' suffix
1438 * (we'll automatically add the suffix). 'objs' is a varying-length list
1439 * of the resolved objects - direct object, indirect object, and any
1440 * others needed.
1441 */
1442 #define tryImplicitActionMsg(msgProp, action, objs...) \
1443 _tryImplicitAction(gIssuingActor, gActor, msgProp, \
1444 action##Action, ##objs)
1445
1446 /*
1447 * Replace the current action with a new action. The new action will be
1448 * performed, and the original action will be terminated with 'exit'.
1449 *
1450 * 'action' is the root name of the action, without the 'Action' suffix
1451 * (we'll add the suffix automatically). 'objs' is a varying-length list
1452 * of the resolved objects - direct object, indirect object, etc.
1453 */
1454 #define replaceAction(action, objs...) \
1455 _replaceAction(gActor, action##Action, ##objs)
1456
1457 /*
1458 * Replace the current action with a new action directed to a different
1459 * actor (but from the same issuing actor).
1460 */
1461 #define replaceActorAction(actor, action, objs...) \
1462 _replaceAction(actor, action##Action, ##objs)
1463
1464 /*
1465 * Run a nested action.
1466 */
1467 #define nestedAction(action, objs...) \
1468 _nestedAction(nil, gActor, action##Action, ##objs)
1469
1470 /*
1471 * Run a nested action targeted to a given actor.
1472 */
1473 #define nestedActorAction(actor, action, objs...) \
1474 _nestedAction(nil, actor, action##Action, ##objs)
1475
1476 /*
1477 * Run a new action. This is a brand new action run as a separate turn,
1478 * not as a nested action. This doesn't replace any current action, but is
1479 * simply a separate action.
1480 *
1481 * This is normally used only for internal actions that are run between
1482 * other actions. This should not normally be used while another action is
1483 * being processed - use nestedAction for that instead. This should also
1484 * not normally be used to replace the current action with another - use
1485 * replaceAction for that.
1486 *
1487 * Returns a CommandTranscript object, which provides information on the
1488 * results of the action.
1489 */
1490 #define newAction(action, objs...) \
1491 _newAction(CommandTranscript, nil, gActor, action##Action, ##objs)
1492
1493 /* run a new action with a specific actor */
1494 #define newActorAction(actor, action, objs...) \
1495 _newAction(CommandTranscript, nil, actor, action##Action, ##objs)
1496
1497 /*
1498 * Ask for a direct object and retry the command using the single-object
1499 * phrasing. This can be used in the action() routine for a no-object
1500 * command to ask for the missing direct object.
1501 *
1502 * In many cases, there is simply no grammar rule for a zero-object form
1503 * of a verb; in such cases, this macro is not needed, since the missing
1504 * object is handled via the grammar. However, for some actions, it is
1505 * desirable to allow the zero-object phrasing some of the time, but
1506 * require the direct-object phrasing other times. This macro exists for
1507 * these cases, because it allows the intransitive version of the action
1508 * to decide, on a case-by-case basis, whether to process the no-object
1509 * form of the command or to prompt for a direct object.
1510 *
1511 * newAction is the root name (without the Action suffix) of the
1512 * transitive action to execute. For example, if we're processing a plain
1513 * "in" command, we could use askForDobj(Enter) to ask for a direct object
1514 * for the transitive "enter" phrasing.
1515 */
1516 #define askForDobj(newAction) \
1517 (newAction##Action.retryWithMissingDobj(gAction, ResolveAsker))
1518
1519 /*
1520 * Ask for an indirect object and retry the command using the two-object
1521 * phrasing. This can be used in the action() routine of a single-object
1522 * command to ask for the missing indirect object.
1523 *
1524 * In many cases, there is simply no grammar rule for a single-object form
1525 * of a verb; in such cases, this macro is not needed, since the missing
1526 * object is handled via the grammar. However, for some actions, it is
1527 * desirable to allow the single-object phrasing some of the time, but
1528 * require the two-object phrasing other times. This macro exists for
1529 * these cases, because it allows the action() routine to decide, on a
1530 * case-by-case basis, whether to process the single-object form of the
1531 * command or to prompt for an indirect object.
1532 *
1533 * newAction is the root name (without the Action suffix) of the
1534 * two-object form of the action. For example, if we're processing a
1535 * single-object "unlock" command, we would use askForIobj(UnlockWith) to
1536 * ask for an indirect object for the "unlock with" two-object phrasing.
1537 */
1538 #define askForIobj(newAction) \
1539 (newAction##Action.retryWithMissingIobj(gAction, ResolveAsker))
1540
1541 /*
1542 * Ask for a literal phrase and retry the command using the two-object
1543 * phrasing. This is analogous to askForDobj() and askForIobj(), but for
1544 * literal phrases; we effectively convert a TAction into a
1545 * LiteralTAction.
1546 */
1547 #define askForLiteral(newAction) \
1548 (newAction##Action.retryWithMissingLiteral(gAction))
1549
1550 /*
1551 * Ask for a topic phrase and retry the command using the two-object
1552 * phrasing.
1553 */
1554 #define askForTopic(newAction) \
1555 (newAction##Action.retryWithMissingTopic(gAction))
1556
1557 /* ------------------------------------------------------------------------ */
1558 /*
1559 * Command interruption signal macros.
1560 */
1561
1562 /* a concise macro to throw an ExitSignal */
1563 #define exit throw new ExitSignal()
1564
1565 /* a concise macro to throw an ExitActionSignal */
1566 #define exitAction throw new ExitActionSignal()
1567
1568 /* a concise macro to throw an AbortImplicitSignal */
1569 #define abortImplicit throw new AbortImplicitSignal()
1570
1571
1572 /* ------------------------------------------------------------------------ */
1573 /*
1574 * Flags for LOOK AROUND styles
1575 */
1576
1577 /* show the room name as part of the description */
1578 #define LookRoomName 0x0001
1579
1580 /* show the room's long desription (the roomDesc) */
1581 #define LookRoomDesc 0x0002
1582
1583 /* show the non-portable items (the specialDesc's) */
1584 #define LookListSpecials 0x0004
1585
1586 /* show the portable items */
1587 #define LookListPortables 0x0008
1588
1589
1590 /* ------------------------------------------------------------------------ */
1591 /*
1592 * Template for multi-location objects. To put a MultiLoc object in
1593 * several initial locations, simply use a template giving the list of
1594 * locations.
1595 */
1596 MultiLoc template [locationList];
1597
1598
1599 /* ------------------------------------------------------------------------ */
1600 /*
1601 * Templates for style tags
1602 */
1603 StyleTag template 'tagName' 'openText'? 'closeText'?;
1604
1605
1606 /* ------------------------------------------------------------------------ */
1607 /*
1608 * A template for footnotes - all we usually need to define in a footnote
1609 * is its descriptive text, so this makes it easy to define one.
1610 */
1611 Footnote template "desc";
1612
1613 /* footnote status levels */
1614 enum FootnotesOff, FootnotesMedium, FootnotesFull;
1615
1616
1617 /* ------------------------------------------------------------------------ */
1618 /*
1619 * An achievement defines its descriptive text. It can also optionally
1620 * define the number of points it awards.
1621 */
1622 Achievement template +points? "desc";
1623
1624
1625 /* ------------------------------------------------------------------------ */
1626 /*
1627 * An event list takes a list of strings, objects, and/or functions.
1628 */
1629 EventList template [eventList];
1630
1631 /*
1632 * A shuffled event list with two lists - the first list is the sequential
1633 * initial list, fired in the exact order specified; and the second is the
1634 * random list, with the events that occur in shuffled order after we
1635 * exhaust the initial list.
1636 */
1637 ShuffledEventList template [firstEvents] [eventList];
1638
1639 /* a synchronized event list takes its state from another list */
1640 SyncEventList template ->masterObject inherited;
1641
1642 /* low-level shuffled list */
1643 ShuffledList template [valueList];
1644
1645
1646 /* ------------------------------------------------------------------------ */
1647 /*
1648 * Define a template for the Tip class.
1649 */
1650 Tip template "desc";
1651
1652
1653 /* ------------------------------------------------------------------------ */
1654 /*
1655 * Definitions for the menu system
1656 */
1657
1658 /*
1659 * The indices for the key values used to navigate menus, which are held
1660 * in the keyList array of MenuItems.
1661 */
1662 #define M_QUIT 1
1663 #define M_PREV 2
1664 #define M_UP 3
1665 #define M_DOWN 4
1666 #define M_SEL 5
1667
1668 /* some templates for defining menu items */
1669 MenuItem template 'title' 'heading'?;
1670 MenuTopicItem template 'title' 'heading'? [menuContents];
1671 MenuLongTopicItem template 'title' 'heading'? 'menuContents';
1672
1673 /* templates for hint system objects */
1674 Goal template ->closeWhenAchieved? 'title' 'heading'? [menuContents];
1675 Hint template 'hintText' [referencedGoals]?;
1676
1677 /* ------------------------------------------------------------------------ */
1678 /*
1679 * Templates for topic database entries.
1680 */
1681
1682 /*
1683 * A TopicEntry can be defined with an optional score, followed by the
1684 * match criteria (which can be either a single matching object, a list of
1685 * matching objects, or a regular expression pattern string), followed by
1686 * the optional response text (which can be given either as a double-quoted
1687 * string or as a list of single-quoted strings to use as an EventList).
1688 */
1689 TopicEntry template
1690 +matchScore?
1691 @matchObj | [matchObj] | 'matchPattern'
1692 "topicResponse" | [eventList] ?;
1693
1694 /* a ShuffledEventList version of the above */
1695 TopicEntry template
1696 +matchScore?
1697 @matchObj | [matchObj] | 'matchPattern'
1698 [firstEvents] [eventList];
1699
1700 /* we can also include *both* the match object/list *and* pattern */
1701 TopicEntry template
1702 +matchScore?
1703 @matchObj | [matchObj]
1704 'matchPattern'
1705 "topicResponse" | [eventList] ?;
1706
1707 /* a ShuffledEventList version of the above */
1708 TopicEntry template
1709 +matchScore?
1710 @matchObj | [matchObj]
1711 'matchPattern'
1712 [firstEvents] [eventList];
1713
1714 /* miscellanous topics just specify the response text or list */
1715 MiscTopic template "topicResponse" | [eventList];
1716 MiscTopic template [firstEvents] [eventList];
1717
1718 /*
1719 * A SpecialTopic takes a keyword list or a regular expression instead of
1720 * the regular match criteria. It also takes a suggestion name string and
1721 * the normal response text. There's no need for a score in a special
1722 * topic, since these are unique.
1723 */
1724 SpecialTopic template
1725 'name'
1726 [keywordList] | 'matchPat'
1727 "topicResponse" | [eventList] ?;
1728
1729 /* a ShuffledEventList version of the above */
1730 SpecialTopic template
1731 'name'
1732 [keywordList] | 'matchPat'
1733 [firstEvents] [eventList];
1734
1735 /* default topics just specify the response text */
1736 DefaultTopic template "topicResponse" | [eventList];
1737 DefaultTopic template [firstEvents] [eventList];
1738
1739 /* alternative topics just specify the response string or strings */
1740 AltTopic template "topicResponse" | [eventList];
1741 AltTopic template [firstEvents] [eventList];
1742
1743 /* a TopicGroup can specify its score adjustment */
1744 TopicGroup template +matchScoreAdjustment;
1745
1746 /* a conversation node need a name */
1747 ConvNode template 'name';
1748
1749 /*
1750 * End-of-conversation reason codes
1751 */
1752 enum endConvBye; /* player typed GOODBYE */
1753 enum endConvTravel; /* the other character is trying to travel away */
1754 enum endConvBoredom; /* our attentionSpan has been exhausted */
1755 enum endConvActor; /* the NPC itself (not the player) is saying GOODBYE */
1756
1757 /*
1758 * Special result code for Actor.canEndConversation() - this indicates that
1759 * the other actor said something to force the conversation to keep going.
1760 */
1761 enum blockEndConv;
1762
1763 /* ------------------------------------------------------------------------ */
1764 /*
1765 * Conversation manager macros
1766 */
1767
1768 /* has a topic key been revealed through <.reveal>? */
1769 #define gRevealed(key) (conversationManager.revealedNameTab[key] != nil)
1770
1771 /* reveal a topic key, as though through <.reveal> */
1772 #define gReveal(key) (conversationManager.setRevealed(key))
1773
1774 /* mark a Topic/Thing as known/seen by the player character */
1775 #define gSetKnown(obj) (gPlayerChar.setKnowsAbout(obj))
1776 #define gSetSeen(obj) (gPlayerChar.setHasSeen(obj))
1777
1778
1779 /* ------------------------------------------------------------------------ */
1780 /*
1781 * For compatibility with versions before 3.1.1, define
1782 * openableContentsLister as a synonym for openableDescContentsLister. The
1783 * former was renamed to the latter in 3.1.1 because the original name was
1784 * inconsistent with the corresponding listers for other classes. In
1785 * principle, openableContentsLister is meant to be the 'contentsLister'
1786 * (for displaying the openable's contents in room descriptions, etc) for
1787 * an Openable, while openableDescContentsLister is its
1788 * 'descContentsLister' (for displaying the openable's contents in its own
1789 * EXAMINE description). Fortunately we don't have a need for a special
1790 * contentsLister for Openable, so we can avoid breaking existing code by
1791 * mapping the old name to the new name.
1792 */
1793 #define openableContentsLister openableDescContentsLister
1794
1795
1796 #endif /* ADV3_H */