Debian Codegraph @

terps/agility/interp.h

raw symbols SCIP
1 /* interp.h-- Header file for interpreter data structures */
2 /* Copyright (C) 1996-1999,2001 Robert Masenten */
3 /* This program may be redistributed under the terms of the
4 GNU General Public License, version 2; see agility.h for details. */
5 /* */
6 /* This is part of the source for AGiliTy: the (Mostly) Universal */
7 /* AGT Interpreter */
8
9 /* This file contains variables and data structures used
10 by the interpreter but not read in from the gamefile.
11 For the rest of the data structures, see agility.h and
12 agtdata.c */
13
14 #ifndef global
15 #define uagt_defined_global
16 #define global extern
17 #endif
18
19 /* -------------------------------------------------------------------- */
20 /* The following are debugging and diagnostic flags. */
21 /* They are mainly intended for debugging the interpreter, but */
22 /* they could concievable be used for debugging games under the */
23 /* interpreter */
24 /* -------------------------------------------------------------------- */
25
26 global rbool stable_random;
27 /* --Force random numbers to be repeatable. */
28
29
30 global rbool DEBUG_MEM; /* prints out information on memory allocation */
31
32 global rbool debug_parse; /* Prints out long parse diagnostic information
33 after the sentence has been parse but before
34 disambiguation */
35 global rbool DEBUG_EXEC_VERB; /* This prints out a line indicating each command
36 that exec_verb() is asked to run */
37 global rbool DEBUG_DISAMBIG; /* Print out dismabiguation debugging info */
38 global rbool DEBUG_SMSG; /* Print out STANDARD message info */
39
40 #define DEBUG_AGT_CMD flag[0] /* This sends metacommand execution information
41 to either the screen or debugfile, depending on
42 whether DEBUG_OUT is true or false. */
43
44 global rbool debug_disambig, debug_any;
45 /* These determine if metacommands are traced during disambiguation
46 or during the scanning of ANY commands */
47
48 global rbool DEBUG_OUT; /* True if debugging output is redirected somewhere
49 other than the screen */
50 global FILE *debugfile; /* Where debugging output should be sent */
51
52 #define def_DEBUG_MEM 1 /* parser.c */
53
54
55 /* -------------------------------------------------------------------- */
56 /* The following are AGT 'purity' flags; they turn off features of */
57 /* my interpreter that are not fully consistent with the original AGT.*/
58 /* More are defined in agility.h, and you should look there for general */
59 /* notes */
60 /* -------------------------------------------------------------------- */
61
62 /* The following are defined (and described) in agil.c */
63 extern rbool PURE_INPUT, PURE_TONE;
64
65 #define PURE_WEAR 1 /* If this is cleared, then things taken off
66 still stay in the player's inventory.
67 The support for this isn't quite complete yet
68 (there are one or two checks that need to be done
69 but aren't) and so right now this should be 1. */
70
71 global rbool PURE_DOT; /* Treats period as a letter-character and not
72 as punctuation. This should be set automatically
73 during initialization based on whether any words
74 in the dictionary have dots. */
75
76 #define FORCE_PURE_DOT 0 /* This forces the period to be treated as a letter
77 even if there are no words in the dictionary
78 containing periods. The only reason to set
79 this was if you were concerned that knowledge
80 about the presence or absence of periods in the
81 dictionary would give puzzles away. */
82
83
84
85
86 #define MEM_MARGIN (16*1024) /* 16K should be enough (SOGGY, the largest AGT
87 game, uses around 12K) */
88 #define PICT_SUPPORT 0 /* Graphics not supported */
89 #define TAB_SIZE 3 /* Number of spaces in a tab */
90
91
92
93
94 /* -------------------------------------------------------------------- */
95 /* Variables and Flags related to Metaverbs */
96 /* -------------------------------------------------------------------- */
97
98 global rbool notify_flag, listexit_flag, menu_mode;
99
100 global rbool cmd_saveable; /* set indicates that this command can be repeated
101 with AGAIN. */
102 global rbool can_undo; /* Can we UNDO the last turn? */
103
104 global uchar *restart_state, *undo_state; /* Store old game states for
105 RESTART and UNDO */
106 global char doing_restore; /* Have we been asked to RESTORE? */
107
108 global rbool do_look; /* True if we should print a room description */
109 global rbool do_autoverb; /* True if we should run the autoexec verb
110 for the current room */
111
112 /* The following are used for scripting and logging */
113 global rbool script_on;
114 global genfile scriptfile;
115 global signed char logflag; /* 1=logging, 2=replaying, 0=neither, 3=both */
116 global int logdelay; /* -1=wait for keypress, >=0 is numerical delay */
117 global genfile log_in, log_out;
118
119 global rbool fast_replay; /* If true, don't print MORE prompts. */
120
121 global rbool sound_on; /* Manipulated by music_cmd; can be used by interface
122 to determine if a tone should be made */
123
124 global integer *pictable; /* Used to decode picture numbers */
125 global fc_type hold_fc; /* Needed to print instructions on demand */
126
127 global unsigned short compass_rose; /* Used to pass compass info to
128 the os layer */
129
130
131 /* -------------------------------------------------------------------- */
132 /* Game State */
133 /* -------------------------------------------------------------------- */
134
135 global rbool quitflag, deadflag, winflag, endflag;
136 global rbool first_visit_flag, newlife_flag, room_firstdesc;
137
138 global rbool start_of_turn; /* True if running the command on the first
139 noun in the list */
140 global rbool end_of_turn; /* True if running command on last noun in
141 the list. */
142
143 global rbool actor_in_scope; /* Used to determine if the actor was in
144 scope when the command was originally
145 given */
146
147 global integer loc; /* Player's location */
148 global integer player_contents, player_worn; /* Worn and carried objects*/
149
150 global long totwt, totsize; /* Size and wt player is carrying around */
151
152 global integer curr_lives; /* Number of lives left. */
153
154 global long tscore, old_score; /* Total score */
155 global long objscore; /* Portion of tscore that comes from the POINTS
156 field of nouns and creatures. */
157
158 global integer turncnt; /* Number of turns that have passed */
159 global integer curr_time; /* The time in the game; in the format
160 1243==12:43 */
161
162 global rbool *flag; /* AGT Flags */
163 global short *agt_counter; /* AGT counters */
164 #ifdef AGT_16BIT
165 global short *agt_var; /*AGT variables */
166 #else
167 global long *agt_var;
168 #endif
169
170 global long agt_number; /* The number entered by the player */
171 global rbool agt_answer; /* Did the player get the answer to the last question
172 right? */
173
174 global tline l_stat, r_stat; /* Left and right parts of status line */
175 /* If r_stat is the empty string, l_stat should be
176 centered to create a Trinity-like status line */
177
178 global rbool nomatch_aware; /* Does the game use the nomatch extension
179 to the metacommand format?
180 (which allow <none> and ANY to be
181 distingused) */
182
183 global rbool smart_look; /* If true, then LOOK <object> will be converted
184 to EXAMINE. This is set automatically in agil.c,
185 based on whether the game file uses
186 LOOK <object> in any of the metacommands; if it
187 does, then smart_look is set to 0. */
188
189 /* -------------------------------------------------------------------- */
190 /* Menu data structures */
191 /* -------------------------------------------------------------------- */
192
193 #define MENU_WIDTH 50
194 typedef char menuentry[MENU_WIDTH];
195
196 global int vm_width; /* Width of widest element */
197 global menuentry *verbmenu;
198
199
200
201 /* -------------------------------------------------------------------- */
202 /* Parser Data Structures */
203 /* This also includes "parser-related" variables like dobj and iobj */
204 /* -------------------------------------------------------------------- */
205
206 /* This extracts the object number from a parse rec */
207 #define p_obj(objrec) ((objrec) ? (objrec)->obj : 0)
208
209 /* The following data structures are used for disambiguation of nouns */
210 typedef struct {
211 long num; /* Numeric value of object; 0 if object doesn't have one */
212 int obj; /* Object number; negative values point into the dictionary */
213 int info; /* Disambiguation info */
214 /* -1=last record; ignore obj field. */
215 word noun, adj; /* Used for printing out error messages */
216 short score; /* Disambiguation score */
217 } parse_rec; /* Stores objects that have been found during parse */
218
219
220 /* In an ideal world, the following would all be local variables. */
221 /* Unfortunately, they're used in too many different places for this
222 to be practical */
223
224 global int vb;
225 global integer actor, dobj, iobj;
226 global parse_rec *actor_rec, *dobj_rec, *iobj_rec;
227 global word prep;
228 global parse_rec *curr_creat_rec;
229 /* Creature currently behaving in a hostile way:
230 used to fill in $c_name$ messages */
231
232 global int disambig_score; /* Used to rank objects during disambiguation */
233
234 #define DISAMBIG_SUCC 1000 /* Score given to an object that triggers a
235 built-in verb or an action token */
236
237
238 #define MAXINPUT 200 /* Max number of words input */
239
240 global word input[MAXINPUT]; /* 200 words of input should be enough */
241 global words in_text[MAXINPUT];
242 /* The corrospoinding strings, for error reporting purposes */
243
244 global short ip,ep; /* input pointer and error pointer */
245 global short ap,vp,np,pp,op; /* Points to first word in actor, verb, noun,
246 and object resp. */
247
248
249
250 /* The following needs to be kept consistant with ext_voc[] in
251 agil.c */
252 typedef enum{wthe,wmy,wa,wan,wthen,wp,wsc,wand,wc,wits,wall,wundo,wlook,wg,
253 wpick,wgo,wexits,wtalk,wtake,wdoor,wagain,wbut,wexcept,
254 wscene,weverything,wlistexit,wlistexits,wclose,
255 wdverb,wdnoun,wdadjective,wdprep,wdobject,wdname,
256 wstep,w_any,weither,wboth,weveryone,weverybody,
257 whe,wshe,wit,wthey,whim,wher,wthem,wis,ware,woops,
258 wwas,wwere,wscream,
259 win,wout,winto,wat,wto,wacross,winside,wwith,wnear,wfor,
260 wof,wbehind,wbeside,won,woff,wunder,wfrom, wthrough,
261 wtoward, wtowards, wbetween, waround, wupon, wthru,
262 wby, wover, wup, wdown,
263 wabout} wtype;
264 global word ext_code[wabout+1]; /* Codes for the above */
265 global short last_he, last_she, last_it, last_they;
266 /* Used for pronoun support */
267
268
269
270 /* -------------------------------------------------------------------- */
271 /* Noun List Data structures and constants */
272 /* -------------------------------------------------------------------- */
273
274
275 /* The following are used in noun lists */
276 #define AND_MARK (-ext_code[wand])
277 #define ALL_MARK (-ext_code[wall])
278
279 #define D_END 50 /* Marks end of disambiguation list */
280 #define D_AND 51 /* Used to seperate multiple objects during disambig */
281 #define D_NOUN 0 /* Noun match */
282 #define D_SYN 1 /* Adjective/synonym only match */
283 #define D_ADJ 2 /* Adj only match */
284 #define D_FLAG 3 /* Flag noun */
285 #define D_GLOBAL 4 /* Global noun */
286 #define D_PIX 5 /* PIX name */
287 #define D_PRO 6 /* Pronoun */
288 #define D_ALL 7 /* ALL, or a header to an ALL EXCEPT _ AND _ ... list */
289 #define D_INTERN 8 /* Internal nouns: DOOR, SCENE */
290 #define D_NUM 9 /* A number, value is in obj */
291 #define D_EITHER 10 /* EITHER or ANY, used only to resolve disambiguation */
292
293 #define D_MARK 0x80 /* Used as a temporary marker, usually to indicate
294 this noun is being considered for elimination */
295
296
297
298 /* -------------------------------------------------------------------- */
299 /* These are used for text boxes (quotes and the title) */
300 /* -------------------------------------------------------------------- */
301 #define TB_TTL 1 /* We're printing the title */
302 #define TB_BOLD 2 /* Print it bold */
303 #define TB_BORDER 4 /* Give it a border */
304 #define TB_CENTER 8 /* Center the text inside */
305 #define TB_NOCENT 16 /* Don't center the whole box */
306
307
308 /* -------------------------------------------------------------------- */
309 /* In AGIL.C */
310 /* -------------------------------------------------------------------- */
311 void print_instructions(fc_type fc);
312 void run_game(fc_type fc);
313
314 /* -------------------------------------------------------------------- */
315 /* In PARSER.C */
316 /* -------------------------------------------------------------------- */
317 rbool parse(void); /* Returns true unless there is ambiguity */
318 void menu_cmd(void);
319
320
321 /* -------------------------------------------------------------------- */
322 /* In EXEC.C */
323 /* -------------------------------------------------------------------- */
324
325 /* Legal values for gen_sysmsg context; they indicate who is calling it */
326 #define MSG_PARSE 0 /* The parser */
327 #define MSG_MAIN 1 /* The main execution loop */
328 #define MSG_RUN 2 /* The routines that execute the player's commands */
329 #define MSG_DESC 3 /* Printing out description. */
330
331 void gen_sysmsg(int msgid,char *s,int context,const char *pword);
332 /* Prints either STANDARD message <msgid> or default msg <s>;
333 <context> determines what $$ substitutions are meaningful
334 <parseword> gives the $pword$ substitution for MSG_PARSE messages */
335
336 void exec(parse_rec *actor,int vnum, parse_rec *lnoun,
337 word prep, parse_rec *iobj);
338 void set_statline(void);
339 void newroom(void);
340 void print_descr(descr_ptr dp,rbool nl);
341 void quote(int msgnum);
342 void print_score(void);
343 long read_number(void);
344
345
346 /* -------------------------------------------------------------------- */
347 /* In TOKEN.C */
348 /* -------------------------------------------------------------------- */
349 void init_stack(void); /* Set up expression stack */
350 void clear_stack(void); /* Set stack back to empty state */
351 void reset_random(void); /* Reset random number generator state */
352 int get_random(int a,int b); /* Return random number from a to b, inclusive */
353
354 /* -------------------------------------------------------------------- */
355 /* In OBJECT.C */
356 /* -------------------------------------------------------------------- */
357 rbool player_has(int item);
358 rbool visible(int item);
359 rbool genvisible(parse_rec *dobj);
360 int *get_nouns(void); /* Returns list of in scope nouns */
361 void add_object(int loc, int item); /* Adds item to loc's contents list */
362 void tmpobj(parse_rec *objrec);
363 void compute_scope(void); /* Sets scope flags for all of the objects */
364 void compute_seen(void); /* Determine HAS_SEEN flag for nouns and creatures */
365
366 void init_creat_fix(void);
367 void free_creat_fix(void);
368
369 /* ------------------------------------------------------------------- */
370 /* The following are intended as building blocks to construct macros */
371 /* to extract information about general objects, regardless of whether */
372 /* they are nouns, creatures, or virtual nouns with no associated */
373 /* data structure. */
374 /* ------------------------------------------------------------------- */
375 /* nounattr(item,attr) -- returns 0 if not noun.
376 creatattr(item,attr) -- returns 0 if not creature
377 objattr(item,attr) -- Returns attribute for noun or creature, 0 otherwise
378 anyattr(item,attr) -- Returns attribute for noun, creature, or room,
379 0 otherwise.
380 */
381
382 #define creatattr2(item,attr,op3) (tcreat(item)? \
383 creature[(item)-first_creat].attr:\
384 (op3))
385 #define creatattr(item,attr) creatattr2(item,attr,0)
386 #define nounattr2(item,attr,alt) (tnoun(item)? \
387 noun[(item)-first_noun].attr:(alt))
388 #define nounattr(item,attr) nounattr2(item,attr,0)
389 #define objattr(item,attr) nounattr2(item,attr,creatattr(item,attr))
390 #define objattr2(item,attr,op3) nounattr2(item,attr,creatattr2(item,attr,op3))
391 #define roomattr2(item,attr,op3) (troom(item)?\
392 room[(item)-first_room].attr:(op3))
393 #define anyattr(item,attr) roomattr2(item,attr,objattr(item,attr))
394
395 #define it_scratch(item) objattr(item,scratch)
396 #define it_loc(item) objattr2(item,location,\
397 (tdoor(item)) ? loc+first_room : 0)
398
399
400 /* -------------------------------------------------------------------- */
401 /* In RUNVERB.C */
402 /* -------------------------------------------------------------------- */
403 int check_obj(parse_rec *act, int verbid,
404 parse_rec *donum, word prep, parse_rec *ionum);
405
406
407 /* -------------------------------------------------------------------- */
408 /* In AGTDBG.C */
409 /* -------------------------------------------------------------------- */
410 void debug_cmd_out(int,int,int,int,int);
411 void debug_head(int);
412 void debug_newline(integer op, rbool first_nl);
413
414 /* -------------------------------------------------------------------- */
415 /* In SAVEGAME.C */
416 /* -------------------------------------------------------------------- */
417 void savegame(void);
418 rbool loadgame(void);
419 void init_state_sys(void); /* Must be called before either of the following */
420 uchar *getstate(uchar *gs);
421 /* Returns malloc'd block containing game state. */
422 void putstate(uchar *gs); /* Restores games state. */
423 void init_vals(void); /* Compute dependent variables
424 such as totwt, totsize, etc. */
425 void restart_game(void);
426
427
428 /* -------------------------------------------------------------------- */
429 /* In OS_<whatever>.C */
430 /* -------------------------------------------------------------------- */
431 global volatile int screen_width, status_width;
432 global int screen_height;
433 global volatile int curr_x;
434
435 void init_interface(int argc,char *argv[]);
436 void start_interface(fc_type fc);
437 void close_interface(void);
438 char *agt_input(int in_type); /* read line, return malloc'd string */
439 char agt_getkey(rbool echo_char);
440 void agt_clrscr(void);
441 void agt_textcolor(int c);
442 void agt_delay(int n); /* n in seconds */
443 int agt_rand(int a,int b); /* Return random number from a to b, inclusive */
444 void agt_newline(void);
445 void agt_puts(const char *s); /* Output string */
446 void agt_statline(const char *s); /* Prints s out on status line */
447 void agt_tone(int hz,int ms);
448 void agt_makebox(int width,int height,unsigned long flags);
449 void agt_qnewline(void);
450 void agt_endbox(void);
451 genfile agt_globalfile(int fid); /* When fid=0, return global config file */
452 rbool agt_option(int optnum,char *optstr[],rbool setflag);
453
454 /* These have stubs defined in interface.c that would ened to be
455 commented out if you actually wanted to support these */
456 void fontcmd(int cmd,int font); /* fontlist[font] */
457 void pictcmd(int cmd,int pict); /* pictlist[pict] or pixlist[pict] */
458 int musiccmd(int cmd,int song); /* songlist[song] */
459
460
461 /* -------------------------------------------------------------------- */
462 /* In INTERFACE.C */
463 /* -------------------------------------------------------------------- */
464 /* init_interface() (in os_?????.c) is responsible for initializing these */
465 global rbool par_fill_on, center_on;
466 global rbool textbold; /* Is the text currently bold? */
467
468 void wait_return(void);
469 void agt_waitkey(void);
470
471 void agt_center(rbool b); /* 1=turn on text centering, 0=turn off */
472 void agt_par(rbool b); /* 1=turn on "paragraph" mode, 0=turn off */
473 char *agt_readline(int in_type); /* Front end for agt_input */
474 char agt_getchar(void); /* Front end for some uses of agt_getkey */
475 void prompt_out(int); /* 1=standard prompt, 2=question prompt */
476 genfile get_user_file(int ft); /* 0=script, 1=save, 2=restore */
477 void set_default_filenames(fc_type fc);
478 void script(uchar); /* 0=turn off, 1=turn on */
479 void logon(void); /* Turn on logging */
480 int close_pfile(genfile f, int ft); /* ft is the same as for get_user_file */
481 void replay(int delay); /* REPLAY */
482 rbool yesno(const char*);
483 void textbox(char *(txt[]),int len,unsigned long flags);
484 void padout(int padleng); /* Outputs padleng spaces */
485 int agt_menu(char *header,int size,int width,menuentry *menu);
486 fc_type new_game(void);
487
488 void set_test_mode(fc_type fc);
489 /* This sets up scripting and replaying for testing mode */
490
491 /* These are intended to be called by the os layer */
492 void print_statline(void);
493
494 void agt_save(void);
495 void agt_restore(void);
496 void agt_restart(void);
497 void agt_quit(void);
498 void agt_newgame(fc_type fc);
499
500 /* -------------------------------------------------------------------- */
501 /* Object manipulation macros */
502 /* -------------------------------------------------------------------- */
503 #define objloop(i) for(i=first_noun; i<=maxnoun || i<=maxcreat; \
504 (i<=maxnoun || i>=first_creat) ? (i++) : (i=first_creat) )
505 #define nounloop(i) for(i=0;i<=maxnoun-first_noun;i++)
506 #define creatloop(i) for(i=0;i<=maxcreat-first_creat;i++)
507
508 #define tdoor(x) ((x)==-ext_code[wdoor])
509
510 #ifdef uagt_defined_global
511 #undef global
512 #undef uagt_define_global
513 #endif
514
515
516