| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
#include <ctype.h> |
| 69 |
#include "agility.h" |
| 70 |
#include "interp.h" |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
rbool PURE_INPUT=1; |
| 84 |
|
| 85 |
rbool PURE_TONE=0; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
static const char* ext_voc[]= |
| 95 |
{"the","my","a","an", |
| 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 |
|
| 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 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
static rbool emptyline(unsigned char *s) |
| 118 |
|
| 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; |
| 131 |
descr_line *buff; |
| 132 |
char *s; |
| 133 |
rbool skip_line; |
| 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 |
|
| 165 |
skip_line=1; |
| 166 |
} else skip_line=0; |
| 167 |
|
| 168 |
|
| 169 |
|
| 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 |
| 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); |
| 188 |
} |
| 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 |
|
| 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)) { |
| 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 |
|
| 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 |
|
| 267 |
|
| 268 |
#define opt(s) (strcasecmp(optstr[0],s)==0) |
| 269 |
|
| 270 |
|
| 271 |
|
| 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; |
| 276 |
|
| 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)) |
| 282 |
rprintf("Invalid option %s\n",optstr[0]); |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 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 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
{ |
| 307 |
int i, endword, restcnt; |
| 308 |
|
| 309 |
if (!PURE_DOT) return 1; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 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; |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
restcnt=strlen(dict[i]); |
| 327 |
if (restcnt<=prevcnt || dict[i][prevcnt]!='.') continue; |
| 328 |
|
| 329 |
|
| 330 |
if (strncasecmp(prevtext,dict[i],prevcnt)!=0) continue; |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
restcnt-=prevcnt+1; |
| 335 |
if (restcnt>endword) continue; |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
if (strncasecmp(lookahead,dict[i]+prevcnt+1,restcnt)!=0) continue; |
| 341 |
|
| 342 |
if (restcnt==endword) return 0; |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
if (lookahead[restcnt]=='.') return 0; |
| 348 |
|
| 349 |
|
| 350 |
} |
| 351 |
return 1; |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
static void tokenise(char *buff) |
| 360 |
|
| 361 |
|
| 362 |
{ |
| 363 |
int ip,j, k; |
| 364 |
rbool punctuation; |
| 365 |
|
| 366 |
j=0;ip=0; |
| 367 |
k=0; |
| 368 |
for(k=0;;k++) { |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
if (buff[k]=='.' && PURE_DOT) |
| 373 |
|
| 374 |
|
| 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) |
| 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]; |
| 387 |
if (!noise_word(input[ip])) ip+=1; |
| 388 |
|
| 389 |
j=0; |
| 390 |
} |
| 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 |
|
| 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) { |
| 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("? ")) { |
| 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; |
| 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 |
|
| 485 |
|
| 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(""); |
| 492 |
|
| 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; |
| 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); |
| 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; |
| 530 |
doing_restore=0; |
| 531 |
} |
| 532 |
if (winflag || deadflag || endflag || quitflag) |
| 533 |
game_end(); |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 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; |
| 551 |
l_stat[0]=r_stat[0]=0; |
| 552 |
|
| 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 |
|
| 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; |
| 582 |
smart_look=1; |
| 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(); |
| 598 |
|
| 599 |
tmp1=rmalloc(MEM_MARGIN); |
| 600 |
|
| 601 |
tmp2=getstate(NULL); |
| 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 |
|
| 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 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
if (!PURE_DUMMY) { |
| 641 |
for(i=0;i<DUMB_VERB;i++) |
| 642 |
dict[ syntbl[auxsyn[i+BASE_VERB]] ][5]=' '; |
| 643 |
|
| 644 |
|
| 645 |
dict[ syntbl[auxsyn[21]] ][6]=' '; |
| 646 |
dict[ syntbl[auxsyn[55]] ][5]=' '; |
| 647 |
} |
| 648 |
|
| 649 |
if (!PURE_SUBNAME) |
| 650 |
for(i=0;i<MAX_SUB;i++) |
| 651 |
sprintf(dict[sub_name[i]],"subroutin %d",i+1); |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 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 && |
| 661 |
i!=ext_code[wp]) |
| 662 |
|
| 663 |
PURE_DOT=1; |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 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 |
|
| 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); |
| 782 |
|
| 783 |
|
| 784 |
static fc_type setup_game(fc_type fc) |
| 785 |
|
| 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; |
| 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); |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
read_config(openfile(fc,fCFG,NULL,0),0); |
| 811 |
text_file=0; |
| 812 |
|
| 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]; |
| 826 |
|
| 827 |
text_file=1; |
| 828 |
read_config(openfile(fc,fCFG,NULL,0),1); |
| 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(); |
| 840 |
|
| 841 |
can_save=init(); |
| 842 |
if (!agx_file) open_descr(fc); |
| 843 |
fix_prompt(); |
| 844 |
if (BATCH_MODE || make_test) |
| 845 |
set_test_mode(fc); |
| 846 |
start_interface(fc); |
| 847 |
fontcmd(2,0); |
| 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); |
| 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()); |
| 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; |
| 884 |
return fc; |
| 885 |
} |
| 886 |
|
| 887 |
|
| 888 |
|
| 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); |
| 898 |
musiccmd(7,-1); |
| 899 |
close_interface(); |
| 900 |
|
| 901 |
|
| 902 |
|
| 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)); |
| 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); |
| 923 |
|
| 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 |
|