Debian Codegraph @

terps/agility/agil.c

raw symbols SCIP
1 /* agil.c-- initialization and the main execution loop */
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) */
7 /* Universal AGT Interpreter */
8
9 /* This file contains the initialization and clean-up code
10 as well as the interpreter's main loop. */
11
12 /* Overview of the source for AGiliTy:
13 agil.c
14 --initialization
15 --tokeniser
16
17 parser.c:
18 --parser
19 --disambiguation
20 --menuing system
21
22 exec.c
23 --verb execution wrapper
24 --standard utilities for running actions
25
26 runverb.c:
27 --standard verbs and the main routine for executing the player's action.
28
29 object.c
30 --Utility functions for manipulating game objects (nouns, creatures, etc.)
31 including scope routines.
32
33 metacommand.c
34 --metacommand execution: scan the metacommands and execute them
35 in the proper order. The actual execution of each individual command
36 is handled in token.c.
37
38 token.c
39 --this module contains the actual code to run each of the (several hundered)
40 different metacommands; called from metacommand.c.
41
42
43 debugcmd.c
44 --Routines to execute debugging verb
45
46 savegame.c
47 --save and restore
48 --undo and restart
49
50 util.c
51 --general utilities
52 --memory management
53 --buffered file i/o
54
55 interface.c
56 --high level input/output
57 --general utilities
58
59 disassemble.c
60 --Metacommand debugging output
61
62 os_<name>.c
63 --low level input/output
64 --other platform dependent code
65 */
66
67
68 #include <ctype.h>
69 #include "agility.h"
70 #include "interp.h"
71
72 /* The following are AGT 'purity' flags; they turn off features of */
73 /* my interpreter that are not fully consistent with the original AGT */
74 /* and so could break some games. Some of these are trivial improvements; */
75 /* some are more radical and should be used with caution. Several are */
76 /* only useful if a game was designed with them in mind. */
77 /* In all cases, setting the flag to 1 more closely follows the */
78 /* behavior of the original interpreters */
79 /* WARNING: Most of these haven't been tested in the non-default state. */
80 /* Most of these will eventually become variables settable by the user */
81 /* or from a (possibly game-specific) configuration file */
82
83 rbool PURE_INPUT=1; /* Is the input line bold? */
84
85 rbool PURE_TONE=0; /* Is low level sound enabled? */
86
87
88 /*-------------------------------------------------------------------*/
89 /* Misc. things to support the tokenizer and the dictionry. */
90 /*-------------------------------------------------------------------*/
91
92 /* The following should not be changed without also changing the
93 wtype enum statement in interp.h to match */
94 static const char* ext_voc[]=
95 {"the","my","a","an", /* These 4 are ignored in canonical AGT */
96 "then",".",";","and", "," , "its", "all","undo", "look","g",
97 "pick","go","exits","talk","take","door","again","but","except",
98 "scene","everything","listexit","listexits","close",
99 "verb","noun","adjective","prep","object","name","step",
100 " any","either","both","everyone","everybody",
101 "he","she","it","they","him","her","them","is","are","oops",
102 "was","were","scream",
103 /* Everything between 'in' and 'about' should be a preposition */
104 "in","out", "into","at","to","across","inside","with","near","for",
105 "of","behind", "beside", "on", "off", "under", "from","through",
106 "toward", "towards", "between", "around", "upon", "thru",
107 "by", "over", "up", "down",
108 "about"};
109 /* 'about' must be the last element of this list */
110
111
112 /*-------------------------------------------------------------------*/
113 /* Routines to read in and use various auxilary files. */
114 /* (.TTL, .INS, .VOC, .CFG) */
115 /*-------------------------------------------------------------------*/
116
117 static rbool emptyline(unsigned char *s)
118 /* Check if s consists only of white space and control characters */
119 {
120 unsigned char *p;
121
122 for(p=s;*p!=0;p++)
123 if (!rspace(*p) && *p>26) return 0;
124 return 1;
125 }
126
127 static void print_title(fc_type fc)
128 {
129 int height;
130 signed char center_mode; /* Center title? */
131 descr_line *buff;
132 char *s;
133 rbool skip_line; /* Skip first line: it has COLORS */
134
135 if (agx_file)
136 buff=read_descr(title_ptr.start,title_ptr.size);
137 else
138 buff=read_ttl(fc);
139
140 if (buff==NULL) {
141 char *s;
142
143 writeln("");writeln("");
144 s=formal_name(fc,fNONE);
145 if (s!=NULL) {
146 s[0]=toupper(s[0]);
147 agt_center(1);
148 agt_textcolor(-1);
149 writeln(s);
150 agt_textcolor(-2);
151 agt_center(0);
152 rfree(s);
153 }
154 writeln("");writeln("");
155
156 if (aver<AGX00)
157 writeln("This game was created with Malmberg and Welch's Adventure "
158 "Game Toolkit; it is being executed by");
159 else writeln("This game is being executed by ");
160 writeln("");
161 height=0;
162 } else {
163 if (buff[0]!=NULL && strncasecmp(buff[0],"COLORS",6)==0) {
164 /* Do screen colors */
165 skip_line=1;
166 } else skip_line=0;
167 /* Compute height and count the number of non-empty lines
168 starting with spaces. We use height as a loop variable
169 and center_mode to store the count temporarily. */
170 center_mode=0;
171 for(height=skip_line;buff[height]!=NULL;height++)
172 if (!emptyline((uchar*)buff[height])) {
173 if (rspace(buff[height][0])) center_mode++;
174 else center_mode--;
175 }
176
177 if (box_title || aver==AGTCOS) center_mode=TB_CENTER;
178 else /* includes aver==AGT135 */
179 if (center_mode<=0) center_mode=TB_CENTER;
180 else center_mode=TB_NOCENT;
181
182 if (!bold_mode) agt_textcolor(-1);
183 agt_clrscr();
184 textbox(buff+skip_line,height-skip_line,center_mode|
185 ( bold_mode ? 0: TB_BOLD) | TB_TTL |
186 ( box_title ? TB_BORDER : 0));
187 if (!bold_mode) agt_textcolor(-2); /* Bold off */
188 } /* End printing of title proper */
189
190 if (agx_file)
191 free_descr(buff);
192 else
193 free_ttl(buff);
194
195 agt_textcolor(7);
196 agt_center(1);
197 if (buff!=NULL) {
198 if (aver<AGX00 && height<=screen_height-6)
199 writeln("[Created with Malmberg and Welch's Adventure Game Toolkit]");
200 if (height<=screen_height-9) writeln("");
201 if (height<=screen_height-5) writeln("This game is being executed by");
202 }
203 agt_textcolor(-1);
204 s=rmalloc(80);
205 if (height<=screen_height-5)
206 sprintf(s,"AGiliTy: "
207 "The (Mostly) Universal AGT Interpreter %s",version_str);
208 else
209 sprintf(s,"Being run by AGiliTy %s, "
210 "Copyright (C) 1996-99,2001 Robert Masenten",
211 version_str);
212 writeln(s);
213 rfree(s);
214 agt_textcolor(-2);
215 if (height<=screen_height-5)
216 writeln("Copyright (C) 1996-99,2001 by Robert Masenten");
217 if (height<=screen_height-3) writeln(portstr);
218 if (height<=screen_height-10) writeln("");
219 agt_center(0);
220 }
221
222
223
224 /* .INS reading routines -------------------------------------- */
225
226 void print_instructions(fc_type fc)
227 {
228 char *buffer;
229 uchar *s;
230
231 writeln("INSTRUCTIONS:");
232 if (open_ins_file(fc,1)) { /* Instruction file exists */
233 while ( NULL!=(buffer=read_ins_line()) ) {
234 for(s=(uchar*)buffer;*s!=0;s++) *s=trans_ascii[*s];
235 writeln(buffer);
236 }
237 }
238 writeln("");
239 }
240
241 /* Routines to build the verb menu from the .VOC information */
242
243 static void build_verbmenu(void)
244 {
245 int i, n;
246 char *p,*d;
247
248 verbmenu=rmalloc(vm_size*sizeof(menuentry));
249 vm_width=0;
250 for(i=0;i<vm_size;i++) {
251 p=verbmenu[i]; d=dict[verbinfo[i].verb];
252 n=0;
253 for(;n<MENU_WIDTH && *d!=0;p++,d++,n++) *p=*d;
254 if (verbinfo[i].prep!=0 && n+1<MENU_WIDTH) {
255 *p++=' ';
256 d=dict[verbinfo[i].prep];
257 *p++=toupper(*d++);
258 for(;n<MENU_WIDTH && *d!=0;p++,d++,n++) *p=*d;
259 }
260 verbmenu[i][0]=toupper(verbmenu[i][0]);
261 *p=0;
262 if (n>vm_width) vm_width=n;
263 }
264 }
265
266 /* .CFG reading routines -------------------------------------------- */
267
268 #define opt(s) (strcasecmp(optstr[0],s)==0)
269
270 /* These are the interpreter specific options; this is called
271 from cfg_option in agtdata.c. */
272 void agil_option(int optnum,char *optstr[], rbool setflag, rbool lastpass)
273 {
274 if (opt("ibm_char")) fix_ascii_flag=!setflag;
275 else if (!lastpass) return; /* On the first pass through the game specific
276 file, we ignore all but the above options */
277 else if (opt("tone")) PURE_TONE=setflag;
278 else if (opt("input_bold")) PURE_INPUT=setflag;
279 else if (opt("force_load")) FORCE_VERSION=setflag;
280 else if (opt("stable_random")) stable_random=setflag;
281 else if (!agt_option(optnum,optstr,setflag)) /* Platform specific options */
282 rprintf("Invalid option %s\n",optstr[0]);
283 }
284
285 /*-------------------------------------------------------------------*/
286 /* Tokeniser: Split input into words and look them up in dictionary */
287 /*-------------------------------------------------------------------*/
288
289 static rbool noise_word(word w)
290 {
291 if (w==ext_code[wthe] || w==ext_code[wa] || w==ext_code[wan]) return 1;
292 if (w==ext_code[wmy]) return 1;
293 if (aver>=AGT18 && aver<=AGT18MAX && w==ext_code[wis]) return 1;
294 return 0;
295 }
296
297
298 static rbool check_dot(char *prevtext, int prevcnt, char *lookahead)
299 /* This routine is devoted to trying to figure out whether
300 we should treat '.' as punctuation or as a letter. */
301 /* It returns true if '.' should be treated as punctuation. */
302 /* prevtext=the current word, as far as it has been parsed.
303 prevcnt=the number of letters in prevtext
304 [which is *not* 0 terminated] */
305 /* lookahead=the rest of the current input line *after* the period. */
306 {
307 int i, endword, restcnt;
308
309 if (!PURE_DOT) return 1; /* No words with periods in them, so it must
310 be punctuation. */
311 /* We just start scanning the dictionary to see if any of them
312 are possible matches, looking ahead as neccessary. */
313
314 /* Find the next unambiguous word end. This ignores possible
315 word ends caused by periods. */
316 for(endword=0;lookahead[endword]!=0;endword++)
317 if (isspace(lookahead[endword]) ||
318 lookahead[endword]==',' || lookahead[endword]==';')
319 break;
320
321 for(i=0;i<dp;i++) {
322 if (i==ext_code[wp]) continue; /* Ignore matches with the word ".". */
323
324 /* If it doesn't contain a '.' at the right location, there is no
325 point in continuing. */
326 restcnt=strlen(dict[i]);
327 if (restcnt<=prevcnt || dict[i][prevcnt]!='.') continue;
328
329 /* Now make sure the previous characters are correct */
330 if (strncasecmp(prevtext,dict[i],prevcnt)!=0) continue;
331
332 /* Finally, compare the trailing text. This is complicated by
333 the fact that the trailing text could itself contain ambiguous '.'s */
334 restcnt-=prevcnt+1; /* Number of characters in dict entry after '.' */
335 if (restcnt>endword) continue; /* Dictionary entry is longer than
336 following text */
337
338 /* Check to see if the dictionary entry can be found in the lookahead
339 buffer */
340 if (strncasecmp(lookahead,dict[i]+prevcnt+1,restcnt)!=0) continue;
341
342 if (restcnt==endword) return 0; /* We have a match */
343 /* At this point, we know that restcnt<endword and the dictionary
344 entry matches as far as restcnt. */
345 /* endword ignores '.', though, so it could be we have a match
346 but are missing it because it is period-terminated. Check this. */
347 if (lookahead[restcnt]=='.') return 0;
348
349 /* Otherwise, no match... try again with the next word... */
350 }
351 return 1; /* No matches: treat it as punctuation. */
352 }
353
354
355
356
357
358
359 static void tokenise(char *buff)
360 /* Convert input string into vocabulary codes */
361 /* 0 here denotes an unrecognized word and -1 marks the end. */
362 {
363 int ip,j, k;
364 rbool punctuation;
365
366 j=0;ip=0;
367 k=0; /* k is the character pointer */
368 for(k=0;;k++) {
369 /* If PURE_DOT is set, then there are periods in some of the dictionary
370 words, so '.' could be a letter or punctuation-- we have to examine
371 context to figure out which. */
372 if (buff[k]=='.' && PURE_DOT)
373 /* Note: check_dot is in agtdata.c, since it needs to access
374 internal implementation details of the dictionary */
375 punctuation=check_dot(in_text[ip],j,buff+k+1);
376 else
377 punctuation=(buff[k]==',' || buff[k]==';' || buff[k]=='.');
378 if (buff[k]!=0 && !isspace(buff[k]) && !punctuation) {
379 if (j<WORD_LENG-1)
380 in_text[ip][j++]=buff[k];
381 } else if (j>0) /* End of word: add it to input */
382 {
383 in_text[ip][j]=0;
384 input[ip]=search_dict(in_text[ip]);
385 if (input[ip]==-1) input[ip]=0;
386 else if (input[ip]==0) input[ip]=ext_code[w_any]; /* _Real_ 'ANY' */
387 if (!noise_word(input[ip])) ip+=1;
388 /* i.e. if not one of the four ignored words, advance */
389 j=0;
390 } /* If j=0 and not punct, then no new word; just skip the whitespace */
391 if (punctuation) {
392 in_text[ip][0]=buff[k];in_text[ip][1]=0;
393 input[ip]=search_dict(in_text[ip]);
394 if (input[ip]==-1) input[ip]=0;
395 j=0;ip++;
396 }
397 if (ip>=MAXINPUT-1) {
398 writeln("Too many words in input; ignoring rest of line.");
399 break;
400 }
401 if (buff[k]==0) break;
402 }
403 input[ip]=-1;
404 in_text[ip][0]=0;
405 }
406
407
408
409 /*-------------------------------------------------------------------*/
410 /* Main game loop: Get player input and call the parser. */
411 /*-------------------------------------------------------------------*/
412
413 static void game_end(void)
414 {
415 rbool done_flag;
416 char *s;
417
418 if (winflag || deadflag) {
419 writeln("");writeln("");agt_center(1);
420 if (winflag)
421 gen_sysmsg(148,"***** $You$ have won! *****",MSG_MAIN,NULL);
422 if (deadflag)
423 gen_sysmsg(147,"***** $You$ have died! *****",MSG_MAIN,NULL);
424 writeln("");writeln("");agt_center(0);
425 }
426 if (deadflag && !endflag) {
427 if (curr_lives>1) { /* Resurrection code */
428 if (curr_lives==max_lives)
429 gen_sysmsg(151,"Hmmm.... so $you$'ve gotten $your$self killed. "
430 "Would you like me to try a resurrection?",MSG_MAIN,NULL);
431 else gen_sysmsg(152,"<Sigh> $You$'ve died *again*. "
432 "Would you like me to try another resurrection?",
433 MSG_MAIN,NULL);
434 if (yesno("? ")) { /* Now do resurrection */
435 curr_lives--;
436 quitflag=deadflag=0;
437 gen_sysmsg(154,
438 "$You$ emerge coughing from a cloud of dark green smoke.",
439 MSG_MAIN,NULL);
440 writeln("");
441 loc=resurrect_room-first_room;
442 newlife_flag=1;
443 set_statline();
444 do_look=do_autoverb=1;
445 newroom();
446 return;
447 } else writeln("As you wish...");
448 }
449 else if (max_lives>1)
450 gen_sysmsg(153,"$You$'ve used up all of $your$ lives.",MSG_MAIN,NULL);
451 }
452 writeln("");
453 print_score();
454 writeln("");
455 done_flag=quitflag; /* If player has QUIT, don't ask again */
456 while (!done_flag && !quitflag) {
457 writestr("Would you like to ");
458 if (restart_state!=NULL) writestr("restart, ");
459 writestr("restore");
460 if (undo_state!=NULL && can_undo)
461 writestr(", undo,");
462 else if (restart_state!=NULL) writestr(",");
463 writestr(" or quit? ");
464 s=agt_readline(5);
465 if (strncasecmp(s,"RESTART",7)==0)
466 if (restart_state!=NULL)
467 {restart_game();done_flag=1;}
468 else writeln("Sorry, I'm unable to do that because of limited memory.");
469 else if (strncasecmp(s,"RESTORE",7)==0)
470 if (loadgame()) {done_flag=1;}
471 else writeln("(RESTORE failed)");
472 else if (strncasecmp(s,"UNDO",4)==0)
473 if (can_undo && undo_state!=NULL)
474 {putstate(undo_state);done_flag=1;}
475 else writeln("Insufficiant memory to support UNDO");
476 else if (toupper(s[0])=='Q')
477 {quitflag=1;done_flag=1;}
478 }
479 set_statline();
480 }
481
482
483 static void parse_loop(void)
484 /* This exists to deal with THEN lists; parse() handles the indiviudual
485 commands */
486 {
487 for(ip=0;ip>=0 && ip<MAXINPUT && input[ip]!=-1; ) {
488 if (!parse() || quitflag || winflag || deadflag ||endflag) break;
489 if (doing_restore) break;
490 if (ip>=0 && ip<MAXINPUT && input[ip]!=-1)
491 writeln(""); /* Insert blank lines between commands when dealing
492 with THEN lists */
493 }
494 }
495
496
497 static long rm_start_size;
498 static char memstr[100];
499
500 static void mainloop(void)
501 {
502 char *s;
503
504 doing_restore=0;
505 while(!quitflag)
506 {
507 if (DEBUG_MEM) {
508 sprintf(memstr,
509 "A:%ld F:%ld Delta:%ld Size:%ld+%ld=%ld (%ld left)\n",
510 ralloc_cnt,rfree_cnt,ralloc_cnt-rfree_cnt,
511 rm_start_size,rm_size-rm_start_size,rm_size,
512 rm_freesize);
513 writeln(memstr);}
514 rm_size=0; /* Reset it to zero */
515 rm_freesize=get_rm_freesize();
516 if (!menu_mode) {
517 prompt_out(1);
518 s=agt_readline(0);
519 if (!doing_restore) tokenise(s); /* Tokenizes into input */
520 rfree(s);
521 if (!doing_restore) parse_loop();
522 }
523 else
524 menu_cmd();
525 if (doing_restore) {
526 if (doing_restore==1) loadgame();
527 else if (doing_restore==2) restart_game();
528 else if (doing_restore==3 || doing_restore==4)
529 return; /* Quit or New game requested */
530 doing_restore=0;
531 }
532 if (winflag || deadflag || endflag || quitflag)
533 game_end();
534 }
535 }
536
537
538 /*-------------------------------------------------------------------*/
539 /* Start up and shut down: Routines to initialise the game state and */
540 /* clean up after the game ends. */
541 /*-------------------------------------------------------------------*/
542
543 static int init(void)
544 {
545 int i, can_save;
546 uchar *tmp1, *tmp2;
547
548 init_vals();
549 init_creat_fix();
550 if (!agx_file) dict[0][0]=0; /* Turn "ANY" into "" */
551 l_stat[0]=r_stat[0]=0; /* Clear the status line */
552 /* lactor=lobj=lnoun=NULL;*/
553 tscore=old_score=objscore=0;
554 turncnt=0;
555 curr_time=start_time;
556 loc=start_room-first_room;
557 cmd_saveable=0;
558 first_visit_flag=newlife_flag=room_firstdesc=1;
559 curr_lives=max_lives;
560
561 /* Note: flag[0] is the debugging flag and is set elsewhere */
562 if (FLAG_NUM<0) FLAG_NUM=0;
563 dbgflagptr=flag=rrealloc(flag,sizeof(rbool)*(FLAG_NUM+1));
564 for(i=1;i<=FLAG_NUM;i++)
565 flag[i]=0;
566 dbgcntptr=agt_counter=rmalloc(sizeof(short)*(CNT_NUM+1));
567 for(i=0;i<=CNT_NUM;i++)
568 {agt_counter[i]=-1;}
569 dbgvarptr=agt_var=rmalloc(sizeof(*agt_var)*(VAR_NUM+1));
570 for(i=0;i<=VAR_NUM;i++)
571 agt_var[i]=0;
572
573 for(i=0;i<=maxnoun-first_noun;i++) {
574 if (noun[i].position==NULL || noun[i].position[0]=='\0')
575 noun[i].pos_prep=0;
576 else noun[i].pos_prep=-1;
577 noun[i].pos_name=0;
578 noun[i].initpos=noun[i].position;
579 }
580
581 nomatch_aware=0; /* By default, not aware. */
582 smart_look=1; /* By default, LOOK <x> --> EXAMINE */
583 for(i=0;i<last_cmd;i++) {
584 if (command[i].nouncmd==-1 || command[i].objcmd==-1
585 || command[i].noun_adj==-1 || command[i].obj_adj==-1
586 || command[i].prep==-1)
587 nomatch_aware=1;
588 if (command[i].verbcmd==ext_code[wlook] &&
589 (command[i].nouncmd>0 || command[i].noun_adj>0
590 || command[i].objcmd>0 || command[i].obj_adj>0
591 || command[i].prep>0) )
592 smart_look=0;
593 }
594
595 pictable=rmalloc(sizeof(int)*maxpict);
596 for(i=0;i<maxpict;i++) pictable[i]=i;
597 init_state_sys(); /* Initialize the system for saving and restoring
598 game states */
599 tmp1=rmalloc(MEM_MARGIN); /* Preserve some work space */
600
601 tmp2=getstate(NULL); /* Make sure we have space to save */
602 if (tmp2==NULL) can_save=0;
603 else can_save=1;
604
605 if (tmp2!=NULL)
606 undo_state=getstate(NULL);
607 else undo_state=NULL;
608
609 if (undo_state!=NULL)
610 restart_state=getstate(NULL);
611 else restart_state=NULL;
612
613 rfree(tmp1);
614 rfree(tmp2);
615 rm_start_size=get_rm_size();
616 rm_freesize=get_rm_freesize();
617 return can_save;
618 }
619
620
621 static void ext_dict(void)
622 /* Enter the vocabulary extensions into the dictionary */
623 {
624 wtype i;
625 for(i=wthe;i<=wabout;i++)
626 ext_code[i]=add_dict(ext_voc[i]);
627 }
628
629
630 static void fix_dummy(void)
631 {
632 int i;
633
634 /* At this point, all occurances in the game file of the dictionary
635 words have been converted to dictionary indices, and so as long as
636 we don't change the dictionary index values, we can change the contents
637 without interfering with the metacommand scanner (since it compares
638 dictionary indices, not actual strings) */
639
640 if (!PURE_DUMMY) {
641 for(i=0;i<DUMB_VERB;i++)
642 dict[ syntbl[auxsyn[i+BASE_VERB]] ][5]=' ';
643 /* Convert underscores into spaces:
644 i.e. 'dummy_verb5' -> 'dummy verb5' */
645 dict[ syntbl[auxsyn[21]] ][6]=' '; /* change_locations */
646 dict[ syntbl[auxsyn[55]] ][5]=' '; /* magic_word */
647 }
648
649 if (!PURE_SUBNAME) /* Replace the 'e' by a space */
650 for(i=0;i<MAX_SUB;i++)
651 sprintf(dict[sub_name[i]],"subroutin %d",i+1);
652 /* This must be no longer than 25 characters with the terminating null */
653
654 /* Now set PURE_DOT based on whether any dictionary word
655 contains a period. */
656 if (aver>=AGT18 && aver<=AGT18MAX) PURE_DOT=0;
657 else {
658 PURE_DOT=FORCE_PURE_DOT;
659 for(i=0;i<dp && !PURE_DOT;i++)
660 if (strchr(dict[i],'.')!=NULL && /* i.e. dict[i] contains period */
661 i!=ext_code[wp]) /* The period itself _is_ a dictionary word:
662 avoid this false match */
663 PURE_DOT=1;
664 }
665 }
666
667
668 /* char *v */
669
670 static void print_license(void)
671 {
672 writeln("AGiliTy");
673 writestr("The (Mostly) Universal AGT Interpreter, ");
674 writeln(version_str);
675 writeln(" Copyright (C) 1996-1999,2001 by Robert Masenten");
676 writestr("[");writestr(portstr);writeln("]");
677 writeln("-----------------------------------------------------------");
678 writeln("");
679 writeln(" This is an interpreter for game files created with Malmberg and "
680 "Welch's _Adventure Game Toolkit_. AGiliTy is universal in the "
681 "sense that it understands and interprets most of the many versions "
682 "of the AGT game file format.");
683 writeln(" It is *not* a port of the original interpreters but rather a "
684 "completely new interpreter built around the game file format; "
685 "while it follows the original interpreters on most things, there "
686 "are some differences which are described in the file "
687 "'readme.agility' which should have come with this program.");
688 writeln("");
689 writeln(" This software is copyright 1996-1999,2001 by Robert Masenten ");
690 writeln(" This program is free software; you can redistribute it and/or "
691 "modify it under the terms of version 2 of the GNU General "
692 "Public License as published by the Free Software Foundation.");
693 writeln(" This program is distributed in the hope that it will be useful, "
694 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
695 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
696 "GNU General Public License for more details.");
697 writeln(" You should have received a copy of the GNU General Public "
698 "License along with this program; if not, write to the Free "
699 "Software Foundation, Inc., 59 Temple Place, Suite 330, "
700 "Boston, MA 02111-1307 USA");
701 writeln("");
702 writeln(" Bugs can be reported at this project's GitHub page at "
703 "https://github.com/DavidKinder/Windows-AGiliTy/");
704 writeln("");
705 writeln("ACKNOWLEDGMENTS");
706 writeln("Thanks to Jay Goemmer, who has sent me pages and pages of "
707 "comments and bug reports; "
708 "David Kinder, responsible for the Amiga and Windows ports and a "
709 "source of much valuble feedback; "
710 "David Youd, who has uncovered many subtle and complex bugs in "
711 "both AGiliTy and Magx; "
712 "Mitch Mlinar, who has contributed several patches and other "
713 "suggestions; "
714 "all of those who have sent me suggestions and bug reports, "
715 "including "
716 "Audrey DeLisle (responsible for the red smoke), David Doherty,"
717 "Al Golden, "
718 "John Hartnup, Walter Isaac, Sami Kivela, Alexander Lehmann, "
719 "Grant E. Metcalf, "
720 "Paul Mikell, Adam Myrow, Olav Nielsen, "
721 "D.J. Picton, Kevin Soucy, Ben Straub, \"Grand Moff Tarkin\", "
722 "Adam Thornton, "
723 "Mark Tilford, David Turpin, and Gil Williamson; "
724 "Volker Blasius,"
725 " original maintainer of the Interactive Fiction Archive; "
726 "Robert Pelak, who suggested the name \"AGiliTy\"; "
727 "and to everyone on Rec.arts.int-fiction who suggested names for "
728 "my interpreter.");
729 writeln("");
730 writeln("SPECIAL VERBS RECOGNIZED");
731 writeln("These are all of the special verbs recognized by the interpreter:");
732 writeln(" SCORE Print out your score.");
733 writeln(" NOTIFY Turn score notification on and off.");
734 writeln(" INSTRUCTIONS or INS Display the instructions for the game.");
735 writeln(" INTRODUCTION or INTRO Repeat the introduction of the game.");
736 writeln(" VIEW <picture> Views an illustration. (Not supported on all "
737 "platforms.)");
738 writeln(" BRIEF Don't print room descriptions for rooms you've seen.");
739 writeln(" VERBOSE Print room descriptions even for rooms you've already "
740 "seen.");
741 writeln(" LIST EXITS List the exits from a room.");
742 writeln(" LISTEXIT ON/OFF Turn on/off automatic listing of exits.");
743 writeln(" SCRIPT Start sending a transcript to a file.");
744 writeln(" UNSCRIPT Stop creating a transcript.");
745 writeln(" SOUND ON, OFF Turn sound on/off.");
746 writeln(" LOG Start sending all of your commands to a file.");
747 writeln(" REPLAY <number> Replay your commands from a file, "
748 "executing one every <number> seconds.");
749 writeln(" REPLAY FAST Replay your commands from a file without waiting "
750 "for you to read the scrolling text.");
751 writeln(" REPLAY STEP Replay your commands from a file, "
752 "one for every keypress.");
753 writeln(" AGILDEBUG Access debugging commands.");
754 writeln(" MENU Toggle menu mode on or off.");
755 writeln(" OOPS Correct a word you just mistyped; must be the first "
756 "command on a line.");
757 writeln(" UNDO Undo your last move; must be the first command on a line.");
758 writeln(" SAVE Save the game.");
759 writeln(" RESTORE Restore the game.");
760 writeln(" RESTART Restart the game.");
761 writeln(" QUIT Quit.");
762 writeln("");
763 }
764
765
766 /* This is a hack to get rid of the "What Now?" prompt. */
767 static void fix_prompt(void)
768 {
769 descr_line *d;
770
771 if (err_ptr==NULL) return;
772 d=read_descr(err_ptr[0].start,err_ptr[0].size);
773 if (d==NULL) return;
774 if (strncasecmp(d[0],"What Now?",9)==0)
775 err_ptr[0].size=err_ptr[0].start=0;
776 free_descr(d);
777 }
778
779
780
781 void close_game(void); /* Called by setup_game, and so needs
782 to be defined here. */
783
784 static fc_type setup_game(fc_type fc)
785 /* game_name is the common filename of the AGT game files */
786 {
787 int can_save;
788 char choice;
789 rbool have_ins;
790
791 bold_mode=0;
792 rm_acct=1;rm_trap=1;
793 rm_size=ralloc_cnt=rfree_cnt=0;
794 mars_fix=0; no_auxsyn=0;
795 debug_disambig=0;debug_any=1;
796 dbg_nomsg=1; /* Supress output of MSG arguments to metacommands */
797 textbold=0;debug_mode=0;aver=0;
798 verboseflag=1;notify_flag=0;logflag=0;menu_mode=0;
799 fast_replay=0;
800 stable_random=BATCH_MODE || make_test;
801 if (make_test) BATCH_MODE=0;
802 hold_fc=fc;
803 set_default_filenames(fc);
804
805 init_stack();
806 read_config(agt_globalfile(0),1); /* Global configuration file */
807
808 /* Now that we *have* PATH information, go looking for the games */
809 /* At the very least, it creates an rmalloc'd copy of game_name */
810 read_config(openfile(fc,fCFG,NULL,0),0);
811 text_file=0;
812 /* First pass through game specific config file */
813 build_trans_ascii();
814 #ifdef PROFILE
815 resetwatch();
816 #endif
817 writeln("Loading game...");
818 if (!read_agx(fc,0) && !readagt(fc,0))
819 fatal("Unable to load game.");
820 #ifdef PROFILE
821 writeln(stopwatch());
822 agt_waitkey();
823 #endif
824 if (have_opt)
825 menu_mode=opt_data[5]; /* See agtread.c for discussion of OPT file
826 format */
827 text_file=1;
828 read_config(openfile(fc,fCFG,NULL,0),1);/*Game specific config file*/
829 text_file=0;
830 if (min_ver>AGIL_VERID) {
831 if (FORCE_VERSION)
832 agtwarn("This game requires a later version of AGiliTy.",0);
833 else
834 fatal("This game requires a later version of AGiliTy.");
835 }
836 sort_cmd();
837 ext_dict();
838 build_verbmenu();
839 fix_dummy(); /* Prevent player from calling dummy verbs or subroutines by
840 typing 'Subroutine n' on the command line */
841 can_save=init();
842 if (!agx_file) open_descr(fc);
843 fix_prompt(); /* Kill off 'What Now?' prompt. */
844 if (BATCH_MODE || make_test)
845 set_test_mode(fc);
846 start_interface(fc);
847 fontcmd(2,0); /* Set initial font */
848 if (intro_first && intro_ptr.size>0) {
849 agt_clrscr();
850 print_descr(intro_ptr,1);
851 wait_return();
852 }
853 if (aver>=AGTME10)
854 pictcmd(3,0); /* Show title image, if there is one */
855 print_title(fc);
856 have_ins=open_ins_file(fc,0);
857 do {
858 if (have_ins)
859 writestr("Choose <I>nstructions, <A>GiliTy Information, "
860 "or <other> to start the game");
861 else
862 writestr("Choose <A>GiliTy Information or <other> to start the game");
863 choice=tolower(agt_getchar()); /* Wait for keypress */
864 agt_clrscr();
865 if (have_ins && choice=='i') print_instructions(fc);
866 else if (choice=='a') print_license();
867 } while ( (choice=='i' && have_ins) || choice=='a');
868 close_ins_file();
869 if (!intro_first && intro_ptr.size>0) {
870 print_descr(intro_ptr,1);
871 wait_return();
872 agt_clrscr();
873 }
874 if (maxroom<first_room) {close_game();exit(EXIT_SUCCESS);}
875 set_statline();
876 if (can_save==0) {
877 writeln("[Insufficiant memory to support SAVE, RESTORE, or UNDO]");
878 }
879 else if (undo_state==NULL)
880 writeln("[Insufficiant memory to support UNDO]");
881 do_look=do_autoverb=1;
882 newroom();
883 rm_acct=1; /* Turn on memory allocation accounting */
884 return fc;
885 }
886
887
888 /* We need to import save_lnoun from exec.c so that we can free it. */
889 extern parse_rec *save_lnoun;
890
891 void close_game(void)
892 {
893 if (agx_file)
894 agx_close_descr();
895 else
896 close_descr();
897 fontcmd(1,-1); /* Restore original font */
898 musiccmd(7,-1); /* Clean up */
899 close_interface();
900
901 /* Now free everything in sight; this _shouldn't_ be necessary,
902 but why take chances? */
903 free_all_agtread();
904 rfree(restart_state);rfree(undo_state);
905 rfree(pictable);rfree(save_lnoun);
906 rfree(verbptr);rfree(verbend);
907 rfree(agt_counter);rfree(agt_var);
908 free_creat_fix();
909 flag=rrealloc(flag,sizeof(rbool)); /* Preserve the debugging flag */
910
911 if (DEBUG_MEM)
912 printf("\n\nAlloc:%ld Freed:%ld Difference:%ld\n",ralloc_cnt,
913 rfree_cnt,ralloc_cnt-rfree_cnt);
914 }
915
916
917 void run_game(fc_type fc)
918 {
919 doing_restore=0;
920 rm_acct=1;rm_trap=1;
921 rm_size=ralloc_cnt=rfree_cnt=0;
922 read_config(agt_globalfile(0),1); /* Global configuration file:
923 get PATH information*/
924 fix_file_context(fc,fDA1);
925 do {
926 if (doing_restore==3) {
927 release_file_context(&fc);
928 fc=setup_game(new_game());
929 }
930 else setup_game(fc);
931 doing_restore=0;
932 mainloop();
933 close_game();
934 } while (doing_restore==3);
935 release_file_context(&fc);
936 }
937
938