| 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 |
#include <assert.h> |
| 30 |
#include <stdio.h> |
| 31 |
|
| 32 |
#include "agility.h" |
| 33 |
#include "interp.h" |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
word input_back[MAXINPUT]; |
| 40 |
words in_text_back[MAXINPUT]; |
| 41 |
int ip_back, parse_ip; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
static int vnum; |
| 46 |
|
| 47 |
|
| 48 |
static parse_rec *lactor=NULL, *lobj=NULL, *lnoun=NULL; |
| 49 |
|
| 50 |
static int ambig_flag=0; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
int all_err_msg[]={73,83,113,103, |
| 58 |
239,239,239,239, |
| 59 |
123,125}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
static void freeall(void) |
| 69 |
{ |
| 70 |
rfree(lnoun);rfree(lobj); |
| 71 |
lnoun=lobj=NULL; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
static int parseerr(int msgid,char *s,int n) |
| 77 |
{ |
| 78 |
if (n>=0) |
| 79 |
gen_sysmsg(msgid,s,MSG_PARSE,in_text[n]); |
| 80 |
else |
| 81 |
gen_sysmsg(msgid,s,MSG_PARSE,""); |
| 82 |
freeall(); |
| 83 |
ep=n; |
| 84 |
ip=-1; |
| 85 |
return -1; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
static void print_nlist(parse_rec *n) |
| 91 |
{ |
| 92 |
char *s; |
| 93 |
int c; |
| 94 |
char buff[100]; |
| 95 |
|
| 96 |
if (n->info==D_END) |
| 97 |
writestr("----"); |
| 98 |
if (n->info==D_ALL) { |
| 99 |
writestr("ALL ");n++;} |
| 100 |
for(c=0;n->info!=D_END && c<20;n++,c++) |
| 101 |
if (n->info==D_AND) writestr(" AND "); |
| 102 |
else if (n->info==D_NUM) { |
| 103 |
sprintf(buff,"#%ld(%d); ",n->num,n->obj); |
| 104 |
writestr(buff); |
| 105 |
} else if (n->obj<0) { |
| 106 |
writestr(dict[-(n->obj)]); |
| 107 |
sprintf(buff,"(%d); ",n->obj); |
| 108 |
writestr(buff); |
| 109 |
} else { |
| 110 |
s=objname(n->obj);writestr(s);rfree(s); |
| 111 |
sprintf(buff,"(%d) ['%s %s']; ",n->obj,dict[n->adj],dict[n->noun]); |
| 112 |
writestr(buff); |
| 113 |
} |
| 114 |
if (n->info!=D_END) writestr("///"); |
| 115 |
writeln(""); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
static int parse_out(parse_rec *lactor,int vb,parse_rec *lnoun,int prep, |
| 121 |
parse_rec *lobj) |
| 122 |
{ |
| 123 |
writeln("ANALYSIS:"); |
| 124 |
writestr("Actor: ");print_nlist(lactor); |
| 125 |
writestr("Verb:");writeln(dict[ syntbl[auxsyn[vb]] ]); |
| 126 |
writestr("DObj: ");print_nlist(lnoun); |
| 127 |
writestr("Prep: "); |
| 128 |
if (prep!=0) writeln(dict[prep]); else writeln("---"); |
| 129 |
writestr("IObj: ");print_nlist(lobj); |
| 130 |
return 0; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
static void save_input(void) |
| 135 |
{ |
| 136 |
int i; |
| 137 |
|
| 138 |
for(i=0;input[i]!=-1 && i<MAXINPUT;i++) { |
| 139 |
input_back[i]=input[i]; |
| 140 |
strncpy(in_text_back[i],in_text[i],24); |
| 141 |
} |
| 142 |
input_back[i]=-1; |
| 143 |
ip_back=ip; |
| 144 |
} |
| 145 |
|
| 146 |
static void restore_input(void) |
| 147 |
{ |
| 148 |
int i; |
| 149 |
|
| 150 |
for(i=0;input_back[i]!=-1 && i<MAXINPUT;i++) { |
| 151 |
input[i]=input_back[i]; |
| 152 |
strncpy(in_text[i],in_text_back[i],24); |
| 153 |
} |
| 154 |
input[i]=-1; |
| 155 |
ip=ip_back; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
#define w_and(w) (w==ext_code[wand] || w==ext_code[wc]) |
| 165 |
#define w_but(w) (w==ext_code[wbut] || w==ext_code[wexcept]) |
| 166 |
#define w_isterm(w) (w==ext_code[wp] || w==ext_code[wthen] || \ |
| 167 |
w==ext_code[wsc] || w_and(w) || w==-1) |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
static word check_comb(int combptr) |
| 172 |
{ |
| 173 |
int k; |
| 174 |
word w; |
| 175 |
|
| 176 |
if (combptr==0) return 0; |
| 177 |
w=syntbl[combptr]; |
| 178 |
for(combptr+=1, k=ip;syntbl[combptr]!=0;combptr++,k++) |
| 179 |
if (syntbl[combptr]!=input[k]) break; |
| 180 |
if (syntbl[combptr]==0) { |
| 181 |
ip=k-1; |
| 182 |
return w; |
| 183 |
} |
| 184 |
return 0; |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
static int comb_verb(void) |
| 189 |
|
| 190 |
{ |
| 191 |
int i; |
| 192 |
word w; |
| 193 |
|
| 194 |
for(i=0;i<num_comb;i++) { |
| 195 |
w=check_comb(comblist[i]); |
| 196 |
if (w!=0) return w; |
| 197 |
} |
| 198 |
|
| 199 |
if (input[ip]==ext_code[wgo] && verb_authorsyn(ext_code[wgo])==0) { |
| 200 |
|
| 201 |
w=input[ip+1]; |
| 202 |
if (w!=0) i=verb_builtin(w); |
| 203 |
else i=0; |
| 204 |
if (i!=0) { |
| 205 |
ip++; |
| 206 |
return w; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
for(i=0;i<num_auxcomb;i++) { |
| 211 |
w=check_comb(auxcomb[i]); |
| 212 |
if (w!=0) return w; |
| 213 |
} |
| 214 |
|
| 215 |
return input[ip]; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
static rbool orig_agt_verb(word w) |
| 227 |
{ |
| 228 |
int i; |
| 229 |
if (aver<=AGT10 && w==ext_code[wg]) return 0; |
| 230 |
|
| 231 |
if (aver<=AGTCOS && w==ext_code[wscream]) return 0; |
| 232 |
for(i=0;old_agt_verb[i]!=-1 && old_agt_verb[i]!=w;i++); |
| 233 |
return(old_agt_verb[i]==w); |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
static int id_verb(void) |
| 249 |
|
| 250 |
{ |
| 251 |
word w; |
| 252 |
int j, canon_word, tmp; |
| 253 |
|
| 254 |
w=comb_verb(); |
| 255 |
if (w==0) return 0; |
| 256 |
|
| 257 |
|
| 258 |
canon_word=verb_builtin(w); |
| 259 |
if (canon_word!=0) { |
| 260 |
if (aver<AGX00 && orig_agt_verb(w)) |
| 261 |
|
| 262 |
tmp=0; |
| 263 |
else |
| 264 |
tmp=verb_authorsyn(w); |
| 265 |
if (tmp==0 || tmp==canon_word) |
| 266 |
w=syntbl[auxsyn[canon_word]]; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
for(j=room[loc].replacing_word;syntbl[j]!=0;j++) |
| 272 |
if (w==syntbl[j]) |
| 273 |
w=room[loc].replace_word; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
canon_word=verb_code(w); |
| 278 |
if (!PURE_DUMMY && canon_word==57) canon_word=0; |
| 279 |
return canon_word; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
#define compr_prep(w1,w2,r) {if (w1==input[ip] && w2==input[ip+1]) \ |
| 284 |
{ip+=2;return r;}} |
| 285 |
#define cprep(c1,c2,r) compr_prep(ext_code[c1],ext_code[c2],ext_code[r]) |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
static int parse_prep(void) |
| 290 |
{ |
| 291 |
wtype i; |
| 292 |
int j,k; |
| 293 |
|
| 294 |
for(j=0;j<num_prep;j++) { |
| 295 |
|
| 296 |
|
| 297 |
for(k=0;syntbl[userprep[j]+k+1]!=0;k++) |
| 298 |
if (syntbl[userprep[j]+k+1]!=input[ip+k]) break; |
| 299 |
if (syntbl[userprep[j]+k+1]==0) { |
| 300 |
ip+=k; |
| 301 |
return syntbl[userprep[j]]; |
| 302 |
} |
| 303 |
} |
| 304 |
cprep(win,wto,winto); |
| 305 |
cprep(wout,wof,wfrom); |
| 306 |
for(i=win;i<=wabout;i++) |
| 307 |
if (ext_code[i]==input[ip]) return input[ip++]; |
| 308 |
return 0; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
static int noun_syn(word w,int obj) |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
{ |
| 319 |
int i; |
| 320 |
|
| 321 |
if (w<=0) return 0; |
| 322 |
|
| 323 |
if (obj>=first_noun && obj<=maxnoun) |
| 324 |
{ |
| 325 |
obj=obj-first_noun; |
| 326 |
if (w==noun[obj].name) return 3; |
| 327 |
if (noun[obj].has_syns) |
| 328 |
for(i=noun[obj].syns;syntbl[i]!=0;i++) |
| 329 |
if (w==syntbl[i]) return (PURE_SYN ? 3 : 2); |
| 330 |
if (w==noun[obj].adj) return 1; |
| 331 |
return 0; |
| 332 |
} |
| 333 |
if (obj>=first_creat && obj<=maxcreat) |
| 334 |
{ |
| 335 |
obj=obj-first_creat; |
| 336 |
if (w==creature[obj].name) return 3; |
| 337 |
if (creature[obj].has_syns) |
| 338 |
for(i=creature[obj].syns;syntbl[i]!=0;i++) |
| 339 |
if (w==syntbl[i]) return (PURE_SYN ? 3: 2); |
| 340 |
if (w==creature[obj].adj) return 1; |
| 341 |
return 0; |
| 342 |
} |
| 343 |
return 0; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
static parse_rec *new_list(void) |
| 353 |
{ |
| 354 |
parse_rec *list; |
| 355 |
|
| 356 |
list=rmalloc(sizeof(parse_rec)); |
| 357 |
list[0].obj=0; |
| 358 |
list[0].num=0; |
| 359 |
list[0].adj=list[0].noun=0; |
| 360 |
list[0].info=D_END; |
| 361 |
return list; |
| 362 |
} |
| 363 |
|
| 364 |
static parse_rec *add_w_rec(parse_rec *pold,int obj0,long num0,int info0, |
| 365 |
word adj0, word noun0) |
| 366 |
{ |
| 367 |
parse_rec *pnew; |
| 368 |
int n; |
| 369 |
|
| 370 |
for(n=0;pold[n].info!=D_END;n++); |
| 371 |
pnew=rrealloc(pold,(n+2)*sizeof(parse_rec)); |
| 372 |
pnew[n].obj=obj0; |
| 373 |
pnew[n].num=num0; |
| 374 |
pnew[n].info=info0; |
| 375 |
pnew[n].adj=adj0; |
| 376 |
pnew[n].noun=noun0; |
| 377 |
pnew[n+1].obj=0; |
| 378 |
pnew[n+1].info=D_END; |
| 379 |
return pnew; |
| 380 |
} |
| 381 |
|
| 382 |
static parse_rec *add_rec(parse_rec *old,int obj0,long num0,int info0) |
| 383 |
{ |
| 384 |
word w; |
| 385 |
|
| 386 |
if (obj0<0) w=-obj0; |
| 387 |
|
| 388 |
else w=0; |
| 389 |
return add_w_rec(old,obj0,num0,info0,0,w); |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
static parse_rec *kill_rec(parse_rec *old,int index) |
| 394 |
|
| 395 |
{ |
| 396 |
parse_rec *pnew; |
| 397 |
int i; |
| 398 |
|
| 399 |
for(i=index;old[i].info!=D_END;i++) { |
| 400 |
old[i].obj=old[i+1].obj; |
| 401 |
old[i].num=old[i+1].num; |
| 402 |
old[i].noun=old[i+1].noun; |
| 403 |
old[i].adj=old[i+1].adj; |
| 404 |
old[i].info=old[i+1].info; |
| 405 |
old[i].score=old[i+1].score; |
| 406 |
} |
| 407 |
pnew=rrealloc(old,i*sizeof(parse_rec)); |
| 408 |
return pnew; |
| 409 |
} |
| 410 |
|
| 411 |
static parse_rec *concat_list(parse_rec *dest,parse_rec *src) |
| 412 |
{ |
| 413 |
int i,j; |
| 414 |
|
| 415 |
for(i=0;dest[i].info!=D_END;i++); |
| 416 |
for(j=0;src[j].info!=D_END;j++); |
| 417 |
dest=rrealloc(dest,sizeof(parse_rec)*(i+j+1)); |
| 418 |
memcpy(dest+i,src,(j+1)*sizeof(parse_rec)); |
| 419 |
return dest; |
| 420 |
} |
| 421 |
|
| 422 |
static parse_rec *purge_list(parse_rec *list) |
| 423 |
|
| 424 |
{ |
| 425 |
int i; |
| 426 |
|
| 427 |
for(i=0;list[i].info!=D_END;) |
| 428 |
if ( (list[i].info & D_MARK) != 0) |
| 429 |
list=kill_rec(list,i); |
| 430 |
else i++; |
| 431 |
return list; |
| 432 |
} |
| 433 |
|
| 434 |
static void clean_list(parse_rec *list) |
| 435 |
{ |
| 436 |
for(;list->info!=D_END;list++) |
| 437 |
list->info&=~D_MARK; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
static parse_rec *copy_list(parse_rec *list) |
| 442 |
{ |
| 443 |
parse_rec *cpy; |
| 444 |
int i; |
| 445 |
|
| 446 |
cpy=new_list(); |
| 447 |
for(i=0;list[i].info!=D_END;i++); |
| 448 |
cpy=rmalloc(sizeof(parse_rec)*(i+1)); |
| 449 |
memcpy(cpy,list,(i+1)*sizeof(parse_rec)); |
| 450 |
return cpy; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
static int scan_rec(int item,int num,parse_rec *list) |
| 457 |
{ |
| 458 |
int i; |
| 459 |
|
| 460 |
for(i=0;list[i].info!=D_END && list[i].info!=D_AND;i++) |
| 461 |
if (list[i].obj==item && list[i].num==num) |
| 462 |
return i; |
| 463 |
return -1; |
| 464 |
} |
| 465 |
|
| 466 |
static rbool scan_andrec(int item,parse_rec *list) |
| 467 |
{ |
| 468 |
for(;list->info!=D_END;list++) |
| 469 |
if (list->obj==item && list->info!=D_AND |
| 470 |
&& list->info!=D_ALL) return 1; |
| 471 |
return 0; |
| 472 |
} |
| 473 |
|
| 474 |
static rbool multinoun(parse_rec *list) |
| 475 |
|
| 476 |
{ |
| 477 |
if (list->info==D_ALL) return 1; |
| 478 |
for(;list->info!=D_END;list++) |
| 479 |
if (list->info==D_AND) return 1; |
| 480 |
return 0; |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
static void add_words_to_rec(parse_rec *nrec, word w, int tmp) |
| 488 |
{ |
| 489 |
word w2; |
| 490 |
|
| 491 |
if (tmp==2 || tmp==3) { |
| 492 |
w2=nrec->noun; |
| 493 |
nrec->noun=w; |
| 494 |
w=w2; |
| 495 |
} |
| 496 |
if (nrec->adj==0) |
| 497 |
nrec->adj=w; |
| 498 |
if (tmp==2) nrec->info=D_SYN; |
| 499 |
else if (tmp==3) nrec->info=D_NOUN; |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
void update_rec_words(parse_rec *nrec, parse_rec *newobj) |
| 506 |
{ |
| 507 |
int tmp; |
| 508 |
|
| 509 |
if (nrec->adj==0) nrec->adj=newobj->adj; |
| 510 |
if (newobj->info==D_ADJ) tmp=1; |
| 511 |
else if (newobj->info==D_SYN) tmp=2; |
| 512 |
else if (newobj->info==D_NOUN) tmp=3; |
| 513 |
else return; |
| 514 |
add_words_to_rec(nrec,newobj->noun,tmp); |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
static rbool ident_objrec(parse_rec *p1, parse_rec *p2) |
| 519 |
{ |
| 520 |
word noun1,adj1, noun2, adj2; |
| 521 |
|
| 522 |
if (p1->obj==p2->obj) return 1; |
| 523 |
if (p1->obj<=0 || p2->obj<=0) return 0; |
| 524 |
if (tnoun(p1->obj)) { |
| 525 |
noun1=noun[p1->obj-first_noun].name; |
| 526 |
adj1=noun[p1->obj-first_noun].adj; |
| 527 |
} else if (tcreat(p1->obj)) { |
| 528 |
noun1=creature[p1->obj-first_creat].name; |
| 529 |
adj1=creature[p1->obj-first_creat].adj; |
| 530 |
} else return 0; |
| 531 |
if (tnoun(p2->obj)) { |
| 532 |
noun2=noun[p2->obj-first_noun].name; |
| 533 |
adj2=noun[p2->obj-first_noun].adj; |
| 534 |
} else if (tcreat(p2->obj)) { |
| 535 |
noun2=creature[p2->obj-first_creat].name; |
| 536 |
adj2=creature[p2->obj-first_creat].adj; |
| 537 |
} else return 0; |
| 538 |
return (noun1==noun2 && adj1==adj2); |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
static parse_rec *fix_actor(parse_rec *alist) |
| 548 |
{ |
| 549 |
int i, cnt; |
| 550 |
|
| 551 |
assert(alist!=NULL); |
| 552 |
if (alist[0].info==D_ALL) { |
| 553 |
rfree(alist); |
| 554 |
return new_list();} |
| 555 |
|
| 556 |
|
| 557 |
cnt=0; |
| 558 |
for(i=0;alist[i].info!=D_END;i++) |
| 559 |
if ( (alist[i].obj<first_creat || alist[i].obj>maxcreat) |
| 560 |
&& alist[i].obj!=-ext_code[weverybody]) { |
| 561 |
if (alist[i].info!=D_AND) |
| 562 |
alist[i].info|=D_MARK; |
| 563 |
} else cnt++; |
| 564 |
alist=purge_list(alist); |
| 565 |
if (cnt<=1) return alist; |
| 566 |
|
| 567 |
|
| 568 |
cnt=0; |
| 569 |
for(i=0;alist[i].info!=D_END;i++) |
| 570 |
if (!genvisible(&alist[i])) { |
| 571 |
if (alist[i].info!=D_AND) |
| 572 |
alist[i].info|=D_MARK; |
| 573 |
} else cnt++; |
| 574 |
|
| 575 |
if (cnt==0) alist[0].info&=~D_MARK; |
| 576 |
|
| 577 |
return purge_list(alist); |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
static parse_rec *convert_to_all(parse_rec *list, int *ofsref) |
| 583 |
{ |
| 584 |
int i; |
| 585 |
int cnt; |
| 586 |
|
| 587 |
for(i=*ofsref;list[i].info!=D_AND && list[i].info!=D_END;i++); |
| 588 |
cnt=i-*ofsref; |
| 589 |
|
| 590 |
while(list[i].info!=D_END) i++; |
| 591 |
list=rrealloc(list,(i+cnt)*sizeof(parse_rec)); |
| 592 |
memmove(list+*ofsref+2*cnt-1,list+*ofsref+cnt, |
| 593 |
(i+1-cnt-*ofsref)*sizeof(parse_rec)); |
| 594 |
for(i=cnt-1;i>=0;i--) { |
| 595 |
int k; |
| 596 |
list[*ofsref+2*i]=list[*ofsref+i]; |
| 597 |
if (i==0) break; |
| 598 |
k=*ofsref+2*i-1; |
| 599 |
list[k].obj=0; |
| 600 |
list[k].num=0; |
| 601 |
list[k].adj=list[k].noun=0; |
| 602 |
list[k].info=D_AND; |
| 603 |
} |
| 604 |
|
| 605 |
return list; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
static parse_rec *add_disambig_info(parse_rec *ilist, int ofs, |
| 611 |
parse_rec *truenoun) |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
{ |
| 617 |
int i, n; |
| 618 |
|
| 619 |
for(i=ofs;ilist[i].info!=D_AND && ilist[i].info!=D_END;i++) { |
| 620 |
if (truenoun[0].info==D_EITHER) { |
| 621 |
|
| 622 |
if (i>ofs) ilist[i].info|=D_MARK; |
| 623 |
} else { |
| 624 |
n=scan_rec(ilist[i].obj,ilist[i].num,truenoun); |
| 625 |
if (n==-1) |
| 626 |
ilist[i].info|=D_MARK; |
| 627 |
else |
| 628 |
update_rec_words(&ilist[i],&truenoun[n]); |
| 629 |
} |
| 630 |
} |
| 631 |
ilist=purge_list(ilist); |
| 632 |
truenoun[0].obj=0; |
| 633 |
truenoun[0].num=0; |
| 634 |
truenoun[0].info=D_END; |
| 635 |
return ilist; |
| 636 |
} |
| 637 |
|
| 638 |
static int max_disambig_score; |
| 639 |
|
| 640 |
static int score_disambig(parse_rec *rec, int ambig_type) |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
{ |
| 646 |
if (ambig_type==1) |
| 647 |
return DISAMBIG_SUCC; |
| 648 |
else if (ambig_type==2) |
| 649 |
return check_obj(lactor,vnum,rec,prep,NULL); |
| 650 |
else if (ambig_type==3) |
| 651 |
return check_obj(lactor,vnum,lnoun,prep,rec); |
| 652 |
else fatal("Invalid ambig_type!"); |
| 653 |
return 0; |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
static parse_rec *expand_all(parse_rec *lnoun) |
| 662 |
{ |
| 663 |
parse_rec *list; |
| 664 |
int i, j; |
| 665 |
rbool prev_obj; |
| 666 |
rbool kill_obj; |
| 667 |
parse_rec temp_obj; |
| 668 |
|
| 669 |
if (debug_parse) { |
| 670 |
writestr("ALL BUT:"); |
| 671 |
print_nlist(lnoun); |
| 672 |
} |
| 673 |
tmpobj(&temp_obj); |
| 674 |
nounloop(i) |
| 675 |
noun[i].scratch=0; |
| 676 |
creatloop(i) |
| 677 |
creature[i].scratch=0; |
| 678 |
objloop(i) |
| 679 |
if ( ( (verbflag[vnum]&VERB_GLOBAL)!=0 || visible(i) ) |
| 680 |
&& (lnoun==NULL || !scan_andrec(i,lnoun))) { |
| 681 |
temp_obj.obj=i; |
| 682 |
if (score_disambig(&temp_obj,2)>=500) { |
| 683 |
if (tnoun(i)) noun[i-first_noun].scratch=1; |
| 684 |
else if (tcreat(i)) creature[i-first_creat].scratch=1; |
| 685 |
else writeln("INTERNAL ERROR: Invalid object type in expand_all()."); |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
list=new_list(); |
| 693 |
prev_obj=0; |
| 694 |
objloop(i) |
| 695 |
if (it_scratch(i)) { |
| 696 |
kill_obj=0; |
| 697 |
for(j=it_loc(i);tnoun(j)||tcreat(j);j=it_loc(j)) |
| 698 |
if (it_scratch(j)) {kill_obj=1;break;} |
| 699 |
if (kill_obj) continue; |
| 700 |
|
| 701 |
if (prev_obj) list=add_rec(list,0,0,D_AND); |
| 702 |
list=add_rec(list,i,0,D_SYN); |
| 703 |
prev_obj=1; |
| 704 |
} |
| 705 |
|
| 706 |
if (debug_parse) { |
| 707 |
writestr("ALL==>"); |
| 708 |
print_nlist(list); |
| 709 |
} |
| 710 |
rfree(lnoun); |
| 711 |
return list; |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
#define MAX_DSCHEME 3 |
| 735 |
#define MAX_DLEV 2 |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
static rbool disambig_check(parse_rec *rec, int dsch, int dlev, |
| 744 |
int ambig_type, rbool pick_one) |
| 745 |
{ |
| 746 |
switch(dsch) { |
| 747 |
case 0: |
| 748 |
switch(dlev) { |
| 749 |
case 0:return (!PURE_ADJ || rec->info!=D_ADJ); |
| 750 |
case 1:return (rec->info!=D_INTERN); |
| 751 |
case 2: return (rec->info!=D_NUM || rec->obj!=0); |
| 752 |
|
| 753 |
default:return 0; |
| 754 |
} |
| 755 |
case 1: |
| 756 |
switch(dlev) { |
| 757 |
case 0: |
| 758 |
|
| 759 |
|
| 760 |
if (PURE_DISAMBIG || rec->info==D_NUM) |
| 761 |
rec->score=DISAMBIG_SUCC; |
| 762 |
else rec->score=score_disambig(rec,ambig_type); |
| 763 |
if (rec->score>=max_disambig_score) |
| 764 |
max_disambig_score=rec->score; |
| 765 |
return 1; |
| 766 |
case 1: return (rec->score==max_disambig_score); |
| 767 |
case 2: |
| 768 |
return (rec->info==D_NUM |
| 769 |
|| ( (verbflag[vnum]&VERB_GLOBAL)!=0 && rec->score>=500 ) |
| 770 |
|| ( tnoun(rec->obj) && noun[rec->obj-first_noun].scope ) |
| 771 |
|| ( tcreat(rec->obj) && creature[rec->obj-first_creat].scope )); |
| 772 |
default:return 1; |
| 773 |
} |
| 774 |
case 2: |
| 775 |
switch(dlev) { |
| 776 |
case 0: |
| 777 |
return 1; |
| 778 |
|
| 779 |
case 1:return (rec->info!=D_PRO && rec->info!=D_ALL && |
| 780 |
rec->info!=D_INTERN && rec->info!=D_NUM); |
| 781 |
default: return 0; |
| 782 |
} |
| 783 |
case 3: return pick_one; |
| 784 |
default: return 0; |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
static parse_rec *disambig_a_noun(parse_rec *list, int ofs, int ambig_type) |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
{ |
| 799 |
int i,cnt; |
| 800 |
int dsch; |
| 801 |
|
| 802 |
int dlev; |
| 803 |
|
| 804 |
|
| 805 |
rbool one_in_scope; |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
cnt=2; |
| 811 |
one_in_scope=0; |
| 812 |
max_disambig_score=-1000; |
| 813 |
|
| 814 |
|
| 815 |
for(dsch=0;dsch<=MAX_DSCHEME;dsch++) |
| 816 |
for(dlev=0;dlev<=MAX_DLEV;dlev++) { |
| 817 |
if (DEBUG_DISAMBIG) |
| 818 |
rprintf("\nDISAMBIG%c%d:%d: ",(dsch==1?'*':' '),dsch,dlev); |
| 819 |
cnt=0; |
| 820 |
for(i=ofs;list[i].info!=D_END && list[i].info!=D_AND;i++) |
| 821 |
if ( disambig_check( &list[i], dsch, dlev, ambig_type, |
| 822 |
one_in_scope || (i==ofs)) |
| 823 |
) |
| 824 |
{ |
| 825 |
cnt++; |
| 826 |
if (DEBUG_DISAMBIG) |
| 827 |
rprintf("+%d ",list[i].obj); |
| 828 |
} else { |
| 829 |
if (DEBUG_DISAMBIG) |
| 830 |
rprintf("-%d ",list[i].obj); |
| 831 |
list[i].info|=D_MARK; |
| 832 |
} |
| 833 |
if (cnt!=0) { |
| 834 |
list=purge_list(list); |
| 835 |
if (cnt==1) return list; |
| 836 |
if (dsch==1 && dlev==MAX_DLEV) |
| 837 |
one_in_scope=1; |
| 838 |
} else { |
| 839 |
clean_list(list); |
| 840 |
break; |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
for(i=ofs;list[i].info!=D_END && list[i].info!=D_AND;i++) { |
| 845 |
if (!ident_objrec(&list[i],&list[ofs])) break; |
| 846 |
list[i].info|=D_MARK; |
| 847 |
} |
| 848 |
if (list[i].info==D_END || list[i].info==D_AND) { |
| 849 |
|
| 850 |
if (one_in_scope) writeln("(Picking one at random)"); |
| 851 |
list[0].info&=~D_MARK; |
| 852 |
list=purge_list(list); |
| 853 |
} else clean_list(list); |
| 854 |
if (DEBUG_DISAMBIG) rprintf("\n"); |
| 855 |
return list; |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
#define list (*ilist) |
| 868 |
|
| 869 |
|
| 870 |
static int disambig_phrase(parse_rec **ilist,parse_rec *truenoun,int tn_ofs, |
| 871 |
int ambig_type) |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
{ |
| 876 |
int ofs, i; |
| 877 |
char *s; |
| 878 |
|
| 879 |
ofs=0; |
| 880 |
if (list[0].info==D_END) return -1; |
| 881 |
if (list[0].info==D_ALL) ofs=1; |
| 882 |
#ifdef OMEGA |
| 883 |
return -1; |
| 884 |
|
| 885 |
#endif |
| 886 |
|
| 887 |
while(list[ofs].info!=D_END) { |
| 888 |
if (ofs==tn_ofs) { |
| 889 |
if (truenoun[0].info==D_ALL) |
| 890 |
list=convert_to_all(list,&ofs); |
| 891 |
else { |
| 892 |
list=add_disambig_info(list,ofs,truenoun); |
| 893 |
if ( list[ofs].info==D_END) { |
| 894 |
gen_sysmsg(240,"In that case, I don't know what you mean.", |
| 895 |
MSG_PARSE,""); |
| 896 |
return -2; |
| 897 |
} |
| 898 |
} |
| 899 |
} |
| 900 |
list=disambig_a_noun(list,ofs,ambig_type); |
| 901 |
assert(list[ofs].info!=D_END && list[ofs].info!=D_AND); |
| 902 |
if (list[ofs+1].info!=D_END && list[ofs+1].info!=D_AND) |
| 903 |
|
| 904 |
{ writestr("Do you mean"); |
| 905 |
for(i=ofs;list[i].info!=D_END && list[i].info!=D_AND;i++) { |
| 906 |
if (list[i+1].info==D_END || list[i+1].info==D_AND) |
| 907 |
if (i>ofs+1) writestr(", or"); |
| 908 |
else writestr(" or"); |
| 909 |
else if (i>ofs) writestr(","); |
| 910 |
writestr(" the "); |
| 911 |
if (list[i].info!=D_NUM || list[i].obj!=0) |
| 912 |
s=objname(list[i].obj); |
| 913 |
else { s=rmalloc(30*sizeof(char)); |
| 914 |
sprintf(s,"%ld",list[i].num);} |
| 915 |
writestr(s); |
| 916 |
rfree(s); |
| 917 |
} |
| 918 |
writeln("?"); |
| 919 |
return ofs;} |
| 920 |
|
| 921 |
while((*ilist)[ofs].info!=D_END && (*ilist)[ofs].info!=D_AND) |
| 922 |
ofs++; |
| 923 |
if ((*ilist)[ofs].info==D_AND) ofs++; |
| 924 |
} |
| 925 |
return -1; |
| 926 |
} |
| 927 |
|
| 928 |
#undef list |
| 929 |
|
| 930 |
static int disambig_ofs; |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
static parse_rec *disambig(int ambig_set, parse_rec *list, parse_rec *truenoun) |
| 938 |
|
| 939 |
{ |
| 940 |
if (ambig_flag==ambig_set || ambig_flag==0) |
| 941 |
{ |
| 942 |
if (truenoun==NULL || truenoun[0].info==D_END) disambig_ofs=-1; |
| 943 |
disambig_ofs=disambig_phrase(&list,truenoun,disambig_ofs,ambig_set); |
| 944 |
if (disambig_ofs==-1) ambig_flag=0; |
| 945 |
else if (disambig_ofs==-2) ambig_flag=-1; |
| 946 |
else ambig_flag=ambig_set; |
| 947 |
} |
| 948 |
return list; |
| 949 |
} |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
static parse_rec *parse_a_noun(void) |
| 972 |
|
| 973 |
|
| 974 |
{ |
| 975 |
parse_rec *nlist; |
| 976 |
char *errptr; |
| 977 |
int i, tmp, numval, num, oip; |
| 978 |
|
| 979 |
nlist=new_list(); |
| 980 |
oip=ip; |
| 981 |
|
| 982 |
if (input[ip]==-1) |
| 983 |
return nlist; |
| 984 |
if (input[ip]==0) { |
| 985 |
numval=strtol(in_text[ip],&errptr,10); |
| 986 |
if (errptr==in_text[ip]) |
| 987 |
return nlist; |
| 988 |
if (*errptr!=0) return nlist; |
| 989 |
nlist=add_rec(nlist,0,numval,D_NUM); |
| 990 |
ip++; |
| 991 |
return nlist; |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
num=0; |
| 997 |
objloop(i) |
| 998 |
if ((tmp=noun_syn(input[ip],i))!=0) { |
| 999 |
numval=strtol(in_text[ip],&errptr,10); |
| 1000 |
if (*errptr!=0) numval=0; |
| 1001 |
nlist=add_w_rec(nlist,i,numval, |
| 1002 |
(tmp==1) ? D_ADJ : (tmp==2 ? D_SYN : D_NOUN), |
| 1003 |
(tmp==1) ? input[ip] : 0, |
| 1004 |
(tmp==1) ? 0 : input[ip]); |
| 1005 |
num++; |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
while(num>0 && input[ip]!=-1 && ip<MAXINPUT) { |
| 1019 |
ip++; |
| 1020 |
if (input[ip]==-1) break; |
| 1021 |
num=0; |
| 1022 |
for(i=0;nlist[i].info!=D_END;i++) |
| 1023 |
if (nlist[i].info==D_NOUN) |
| 1024 |
nlist[i].info|=D_MARK; |
| 1025 |
else if ( (tmp=noun_syn(input[ip],nlist[i].obj))==0) |
| 1026 |
nlist[i].info|=D_MARK; |
| 1027 |
else { |
| 1028 |
num++; |
| 1029 |
add_words_to_rec(&nlist[i], input[ip], tmp); |
| 1030 |
} |
| 1031 |
|
| 1032 |
if (num!=0) { |
| 1033 |
nlist=purge_list(nlist); |
| 1034 |
for(i=0;nlist[i].info!=D_END;i++) |
| 1035 |
nlist[i].num=0; |
| 1036 |
} |
| 1037 |
else |
| 1038 |
clean_list(nlist); |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
if (ip==oip || ip==oip+1) { |
| 1049 |
|
| 1050 |
|
| 1051 |
if ( (input[oip]==ext_code[wdoor] && aver<=AGX00) |
| 1052 |
|| input[oip]==ext_code[wscene]) |
| 1053 |
nlist=add_rec(nlist,-input[oip],0,D_INTERN); |
| 1054 |
else if (input[oip]==ext_code[wall] || |
| 1055 |
input[oip]==ext_code[weverything]) |
| 1056 |
nlist=add_rec(nlist,ALL_MARK,0,D_ALL); |
| 1057 |
else if (input[oip]==ext_code[whe] || input[oip]==ext_code[whim]) |
| 1058 |
nlist=add_rec(nlist,last_he,0,D_PRO); |
| 1059 |
else if (input[oip]==ext_code[wshe] || input[oip]==ext_code[wher]) |
| 1060 |
nlist=add_rec(nlist,last_she,0,D_PRO); |
| 1061 |
else if (input[oip]==ext_code[wit]) |
| 1062 |
nlist=add_rec(nlist,last_it,0,D_PRO); |
| 1063 |
else if (input[oip]==ext_code[wthey] || input[oip]==ext_code[wthem]) |
| 1064 |
nlist=add_rec(nlist,last_they,0,D_PRO); |
| 1065 |
else for (i=0;i<10;i++) |
| 1066 |
if (input[oip]==syntbl[auxsyn[i]]) |
| 1067 |
nlist=add_rec(nlist,-syntbl[auxsyn[i]],0,D_INTERN); |
| 1068 |
else if (input[oip]==ext_code[weveryone] || |
| 1069 |
input[oip]==ext_code[weverybody]) |
| 1070 |
nlist=add_rec(nlist,-ext_code[weverybody],0,D_INTERN); |
| 1071 |
|
| 1072 |
|
| 1073 |
numval=strtol(in_text[oip],&errptr,10); |
| 1074 |
if (*errptr==0) |
| 1075 |
nlist=add_rec(nlist,-input[oip],numval,D_NUM); |
| 1076 |
|
| 1077 |
|
| 1078 |
if (globalnoun!=NULL) |
| 1079 |
for(i=0;i<numglobal;i++) |
| 1080 |
if (input[oip]==globalnoun[i]) |
| 1081 |
nlist=add_rec(nlist,-input[oip],0,D_GLOBAL); |
| 1082 |
for(i=0;i<MAX_FLAG_NOUN;i++) |
| 1083 |
if (flag_noun[i]!=0 && input[oip]==flag_noun[i] |
| 1084 |
#if 0 |
| 1085 |
&& (room[loc].flag_noun_bits & (1L<<i))!=0 |
| 1086 |
#endif |
| 1087 |
) |
| 1088 |
nlist=add_rec(nlist,-input[oip],0,D_FLAG); |
| 1089 |
|
| 1090 |
|
| 1091 |
for(i=0;i<MAX_PIX;i++) |
| 1092 |
if (pix_name[i]!=0 && input[oip]==pix_name[i] && |
| 1093 |
(room[loc].PIX_bits & (1L<<i))!=0) |
| 1094 |
nlist=add_rec(nlist,-input[oip],0,D_PIX); |
| 1095 |
|
| 1096 |
if (nlist[0].info!=D_END) ip=oip+1; |
| 1097 |
} |
| 1098 |
return nlist; |
| 1099 |
} |
| 1100 |
|
| 1101 |
static parse_rec *parse_noun(int and_ok,int is_actor) |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
{ |
| 1107 |
parse_rec *next, *lnoun; |
| 1108 |
int saveinfo; |
| 1109 |
rbool all_except; |
| 1110 |
|
| 1111 |
all_except=0; |
| 1112 |
next=lnoun=parse_a_noun(); |
| 1113 |
saveinfo=next[0].info; |
| 1114 |
|
| 1115 |
#if 0 |
| 1116 |
if (!and_ok) return lnoun; |
| 1117 |
#endif |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
if (is_actor) return lnoun; |
| 1122 |
|
| 1123 |
if (lnoun[0].info==D_ALL && w_but(input[ip])) |
| 1124 |
all_except=1; |
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
while ( (all_except || w_and(input[ip])) && |
| 1129 |
saveinfo!=D_END) |
| 1130 |
{ |
| 1131 |
ip++; |
| 1132 |
next=parse_a_noun(); saveinfo=next[0].info; |
| 1133 |
if (next[0].info!=D_END) { |
| 1134 |
if (!all_except) lnoun=add_rec(lnoun,AND_MARK,0,D_AND); |
| 1135 |
lnoun=concat_list(lnoun,next); |
| 1136 |
} else ip--; |
| 1137 |
all_except=0; |
| 1138 |
rfree(next); |
| 1139 |
} |
| 1140 |
return lnoun; |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
parse_rec *parse_disambig_answer(void) |
| 1145 |
{ |
| 1146 |
parse_rec *temp; |
| 1147 |
|
| 1148 |
if (input[ip+1]==-1) { |
| 1149 |
if (input[ip]==ext_code[wall] || input[ip]==ext_code[weverything] |
| 1150 |
|| input[ip]==ext_code[wboth]) { |
| 1151 |
temp=new_list(); |
| 1152 |
ip++; |
| 1153 |
return add_rec(temp,ALL_MARK,0,D_ALL); |
| 1154 |
} |
| 1155 |
if (input[ip]==ext_code[weither] || input[ip]==ext_code[w_any]) { |
| 1156 |
temp=new_list(); |
| 1157 |
ip++; |
| 1158 |
return add_rec(temp,0,0,D_EITHER); |
| 1159 |
} |
| 1160 |
} |
| 1161 |
return parse_noun(0,0); |
| 1162 |
} |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
static int parse_cmd(void) |
| 1172 |
|
| 1173 |
|
| 1174 |
{ |
| 1175 |
rbool new_actor; |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
parse_rec *tmp; |
| 1180 |
int tp; |
| 1181 |
|
| 1182 |
|
| 1183 |
ap=ip; |
| 1184 |
new_actor=0; |
| 1185 |
if (lactor==NULL) { |
| 1186 |
new_actor=1; |
| 1187 |
lactor=parse_noun(0,1); |
| 1188 |
|
| 1189 |
if (lactor[0].info!=D_END) { |
| 1190 |
lactor=fix_actor(lactor); |
| 1191 |
if (lactor[0].info==D_END) { |
| 1192 |
|
| 1193 |
if (input[ip]==ext_code[wc]) |
| 1194 |
return parseerr(229,"Who is this '$word$' you are addressing?",ap); |
| 1195 |
else ip=ap; |
| 1196 |
|
| 1197 |
}} |
| 1198 |
if (lactor[0].info!=D_END && input[ip]==ext_code[wc]) |
| 1199 |
ip++; |
| 1200 |
} |
| 1201 |
|
| 1202 |
vp=ip; |
| 1203 |
vnum=id_verb(); |
| 1204 |
if (vnum==0 && new_actor && lactor[0].info!=D_END) |
| 1205 |
{ |
| 1206 |
ip=ap; |
| 1207 |
vnum=id_verb(); |
| 1208 |
if (vnum==0) |
| 1209 |
ip=vp; |
| 1210 |
else { |
| 1211 |
lactor[0].obj=0; |
| 1212 |
lactor[0].info=D_END; |
| 1213 |
vp=ap; |
| 1214 |
} |
| 1215 |
} |
| 1216 |
|
| 1217 |
TELLHack: |
| 1218 |
|
| 1219 |
|
| 1220 |
if (vnum==0) |
| 1221 |
return parseerr(230,"I don't understand '$word$' as a verb.",ip); |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
prep=0; |
| 1226 |
np=++ip; |
| 1227 |
lnoun=parse_noun( (verbflag[vnum]&VERB_MULTI)!=0, 0); |
| 1228 |
|
| 1229 |
|
| 1230 |
if (prep==0) { |
| 1231 |
pp=ip;prep=parse_prep(); |
| 1232 |
op=ip;lobj=parse_noun(prep==0,0); |
| 1233 |
} |
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
if (lactor[0].info==D_END && lnoun[0].info!=D_END && |
| 1238 |
vnum==31 && prep==ext_code[wto] && !multinoun(lnoun)) |
| 1239 |
{ |
| 1240 |
ip=op; |
| 1241 |
rfree(lactor);rfree(lobj); |
| 1242 |
lactor=lnoun;lnoun=NULL; |
| 1243 |
vp=ip; |
| 1244 |
vnum=id_verb(); |
| 1245 |
goto TELLHack; |
| 1246 |
|
| 1247 |
} |
| 1248 |
|
| 1249 |
|
| 1250 |
if ( vnum==35 && (prep==ext_code[won] || prep==ext_code[woff]) |
| 1251 |
&& lobj[0].info==D_END ) |
| 1252 |
{ |
| 1253 |
tmp=lobj; lobj=lnoun; lnoun=tmp; |
| 1254 |
tp=op; np=op; op=tp; |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
if (aver<AGX00 && lnoun[0].info==D_END && lobj[0].info!=D_END) |
| 1261 |
{ |
| 1262 |
rfree(lnoun); |
| 1263 |
lnoun=copy_list(lobj); |
| 1264 |
np=op; |
| 1265 |
} |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
if (vnum==49 && prep==ext_code[wat] && !multinoun(lnoun)) { |
| 1270 |
tmp=lobj; lobj=lnoun; lnoun=tmp; |
| 1271 |
tp=np;np=op;op=tp; |
| 1272 |
prep=ext_code[wwith]; |
| 1273 |
} |
| 1274 |
|
| 1275 |
|
| 1276 |
if (vnum==40 && prep==0 && lnoun[0].info==D_END && lobj[0].info==D_END) |
| 1277 |
vnum=42; |
| 1278 |
|
| 1279 |
|
| 1280 |
if (smart_look && vnum==19 && lnoun[0].info!=D_END) vnum=20; |
| 1281 |
|
| 1282 |
|
| 1283 |
if ( (verbflag[vnum]&VERB_MULTI)==0 && multinoun(lnoun) ) { |
| 1284 |
|
| 1285 |
int msgnum; |
| 1286 |
if (vnum==31) msgnum=155; |
| 1287 |
else if (vnum==34) msgnum=160; |
| 1288 |
else msgnum=231; |
| 1289 |
return parseerr(msgnum, |
| 1290 |
"The verb '$word$' doesn't take multiple objects.",vp); |
| 1291 |
} else if ( multinoun(lobj) ) |
| 1292 |
return parseerr(232,"You can't use multiple indirect objects.",op); |
| 1293 |
else if (lnoun[0].info==D_END && !w_isterm(input[np]) && np!=pp) |
| 1294 |
|
| 1295 |
return parseerr(233,"I don't understand the word '$word$' as a noun.",np); |
| 1296 |
else if (lnoun[0].obj==0 && lnoun[0].info==D_PRO) |
| 1297 |
return parseerr(234,"I don't know to what '$word$' refers.",np); |
| 1298 |
else if (lobj[0].info==D_END && !w_isterm(input[op])) |
| 1299 |
|
| 1300 |
return parseerr(235,"I don't understand the word '$word$' as a noun.",op); |
| 1301 |
else if (lobj[0].obj==0 && lobj[0].info==D_PRO) |
| 1302 |
return parseerr(236,"I don't know to what '$word$' refers.",op); |
| 1303 |
else if (!w_isterm(input[ip])) |
| 1304 |
return parseerr(238,"Extra input found: \"$word$...\"",ip); |
| 1305 |
|
| 1306 |
return 0; |
| 1307 |
} |
| 1308 |
|
| 1309 |
|
| 1310 |
static void v_undo(void) |
| 1311 |
{ |
| 1312 |
if (undo_state==NULL) { |
| 1313 |
writeln("There is insufficiant memory to support UNDO"); |
| 1314 |
ip=-1; |
| 1315 |
return; |
| 1316 |
} |
| 1317 |
if (can_undo==0) { |
| 1318 |
if (newlife_flag) |
| 1319 |
writeln("You can't UNDO on the first turn."); |
| 1320 |
else writeln("You can only UNDO one turn."); |
| 1321 |
ip=-1; |
| 1322 |
return; |
| 1323 |
} |
| 1324 |
writeln(""); |
| 1325 |
writeln("UNDOing a turn..."); |
| 1326 |
can_undo=0; |
| 1327 |
putstate(undo_state); |
| 1328 |
ip=1; |
| 1329 |
set_statline(); |
| 1330 |
return; |
| 1331 |
} |
| 1332 |
|
| 1333 |
rbool parse(void) |
| 1334 |
|
| 1335 |
|
| 1336 |
{ |
| 1337 |
parse_rec *currnoun; |
| 1338 |
int fixword; |
| 1339 |
int start_ip; |
| 1340 |
|
| 1341 |
currnoun=NULL;start_ip=ip; |
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
if (ip==0 && input[0]==ext_code[woops] && input[1]>0 && |
| 1347 |
input[2]==-1 && ep>-1) { |
| 1348 |
fixword=input[ip+1]; |
| 1349 |
restore_input(); |
| 1350 |
input[ep]=fixword; |
| 1351 |
ambig_flag=0; |
| 1352 |
} |
| 1353 |
ep=-1; |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
if (ip!=0) ambig_flag=0; |
| 1362 |
if (ambig_flag) { |
| 1363 |
currnoun=parse_disambig_answer(); |
| 1364 |
if (input[ip]==-1 && currnoun[0].info!=D_END) |
| 1365 |
{restore_input();ip=parse_ip;} |
| 1366 |
else { |
| 1367 |
ip=0; |
| 1368 |
ambig_flag=0; |
| 1369 |
rfree(currnoun); |
| 1370 |
freeall(); |
| 1371 |
currnoun=NULL; |
| 1372 |
} |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
if (ip==0 && input[0]==ext_code[wundo] && input[1]==-1) |
| 1378 |
{ |
| 1379 |
v_undo(); |
| 1380 |
return 1; |
| 1381 |
} |
| 1382 |
|
| 1383 |
save_input(); |
| 1384 |
|
| 1385 |
|
| 1386 |
if (ip==0) { |
| 1387 |
actor_in_scope=0; |
| 1388 |
rfree(lactor); |
| 1389 |
} |
| 1390 |
|
| 1391 |
if (!ambig_flag) |
| 1392 |
if (parse_cmd()==-1) |
| 1393 |
return 1; |
| 1394 |
|
| 1395 |
parse_ip=ip; |
| 1396 |
|
| 1397 |
if (debug_parse) |
| 1398 |
parse_out(lactor,vnum,lnoun,prep,lobj); |
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
compute_scope(); |
| 1405 |
lactor=disambig(1,lactor,currnoun); |
| 1406 |
lnoun=disambig(2,lnoun,currnoun); |
| 1407 |
lobj=disambig(3,lobj,currnoun); |
| 1408 |
if (ambig_flag>0) return 0; |
| 1409 |
if (ambig_flag==-1) {ambig_flag=0;return 1;} |
| 1410 |
|
| 1411 |
rfree(currnoun); |
| 1412 |
|
| 1413 |
|
| 1414 |
if (!PURE_ALL && lnoun[0].info==D_ALL) { |
| 1415 |
lnoun=expand_all(lnoun); |
| 1416 |
if (lnoun[0].info==D_END) { |
| 1417 |
int msgnum; |
| 1418 |
if (vnum>=15 && vnum<=24) |
| 1419 |
msgnum=all_err_msg[vnum-15]; |
| 1420 |
else |
| 1421 |
msgnum=239; |
| 1422 |
parseerr(msgnum,"I don't know what you are referring to.",np); |
| 1423 |
return 1; |
| 1424 |
} |
| 1425 |
} |
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
if (start_ip==0 && undo_state!=NULL) { |
| 1432 |
undo_state=getstate(undo_state); |
| 1433 |
can_undo=1; |
| 1434 |
} |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
exec(&lactor[0],vnum,lnoun,prep,&lobj[0]); |
| 1440 |
rfree(lobj); |
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
lnoun=lobj=NULL; |
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
if (ip!=-1 && w_and(input[ip]) && input[ip+1]==ext_code[wthen]) |
| 1451 |
ip++; |
| 1452 |
if (ip!=-1 && input[ip]!=-1) ip++; |
| 1453 |
return 1; |
| 1454 |
} |
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
void menu_cmd(void) |
| 1460 |
{ |
| 1461 |
int i,j; |
| 1462 |
int choice; |
| 1463 |
char *curr_cmd, *tmp1, *tmp2; |
| 1464 |
int objcnt; |
| 1465 |
int verbword; |
| 1466 |
parse_rec actrec; |
| 1467 |
|
| 1468 |
parse_rec mobj; |
| 1469 |
int vnum; |
| 1470 |
word prep; |
| 1471 |
|
| 1472 |
menuentry *nounmenu; |
| 1473 |
int *nounval; |
| 1474 |
int nm_size, nm_width; |
| 1475 |
|
| 1476 |
|
| 1477 |
nounval=NULL; |
| 1478 |
nounmenu=NULL; |
| 1479 |
|
| 1480 |
choice=agt_menu("",vm_size,vm_width,verbmenu); |
| 1481 |
if (choice==-1 || doing_restore) return; |
| 1482 |
|
| 1483 |
verbword=verbinfo[choice].verb; |
| 1484 |
prep=verbinfo[choice].prep; |
| 1485 |
objcnt=verbinfo[choice].objnum; |
| 1486 |
|
| 1487 |
|
| 1488 |
ip=0; |
| 1489 |
input[0]=verbword;input[1]=input[2]=-1; |
| 1490 |
if (objcnt<=1 && prep!=0) input[1]=prep; |
| 1491 |
vnum=id_verb(); |
| 1492 |
|
| 1493 |
lnoun=rmalloc(sizeof(parse_rec)*2); |
| 1494 |
lnoun[0].obj=0;lnoun[0].num=0;lnoun[0].info=D_END; |
| 1495 |
|
| 1496 |
nm_size=nm_width=0; |
| 1497 |
|
| 1498 |
if (objcnt>=1) { |
| 1499 |
|
| 1500 |
nounval=get_nouns(); |
| 1501 |
for(nm_size=0;nounval[nm_size]!=0;nm_size++); |
| 1502 |
nounmenu=rmalloc(nm_size*sizeof(menuentry)); |
| 1503 |
nm_width=0; |
| 1504 |
for(i=0;i<nm_size;i++) { |
| 1505 |
tmp1=objname(nounval[i]); |
| 1506 |
strncpy(nounmenu[i],tmp1,MENU_WIDTH); |
| 1507 |
j=strlen(tmp1); |
| 1508 |
if (j>nm_width) nm_width=j; |
| 1509 |
} |
| 1510 |
if (nm_width>MENU_WIDTH) nm_width=MENU_WIDTH; |
| 1511 |
|
| 1512 |
if (objcnt>=2 || prep==0) |
| 1513 |
curr_cmd=rstrdup(dict[verbword]); |
| 1514 |
else |
| 1515 |
curr_cmd=concdup(dict[verbword],dict[prep]); |
| 1516 |
|
| 1517 |
choice=agt_menu(curr_cmd,nm_size,nm_width,nounmenu); |
| 1518 |
rfree(curr_cmd); |
| 1519 |
if (choice==-1 || doing_restore) |
| 1520 |
{rfree(nounmenu);rfree(nounval);rfree(lnoun);return;} |
| 1521 |
|
| 1522 |
if (objcnt==1 && prep!=0) { |
| 1523 |
mobj.obj=nounval[choice]; |
| 1524 |
mobj.num=0; |
| 1525 |
mobj.info=D_NOUN; |
| 1526 |
} else { |
| 1527 |
lnoun[0].obj=nounval[choice]; |
| 1528 |
lnoun[0].num=0; |
| 1529 |
lnoun[0].info=D_NOUN; |
| 1530 |
lnoun[1].obj=0;lnoun[1].num=0;lnoun[1].info=D_END; |
| 1531 |
} |
| 1532 |
} |
| 1533 |
|
| 1534 |
if (objcnt>=2) { |
| 1535 |
tmp1=objname(lnoun[0].obj); |
| 1536 |
tmp2=concdup(dict[verbword],tmp1); |
| 1537 |
rfree(tmp1); |
| 1538 |
curr_cmd=concdup(tmp2,dict[prep]); |
| 1539 |
rfree(tmp2); |
| 1540 |
|
| 1541 |
choice=agt_menu(curr_cmd,nm_size,nm_width,nounmenu); |
| 1542 |
rfree(curr_cmd); |
| 1543 |
if (choice==-1 || doing_restore) |
| 1544 |
{rfree(lnoun);rfree(nounmenu);rfree(nounval);return;} |
| 1545 |
|
| 1546 |
mobj.obj=nounval[choice]; |
| 1547 |
mobj.num=0; |
| 1548 |
mobj.info=D_NOUN; |
| 1549 |
} |
| 1550 |
|
| 1551 |
rfree(nounmenu);rfree(nounval); |
| 1552 |
|
| 1553 |
if (vnum==OLD_VERB+3) { |
| 1554 |
v_undo(); |
| 1555 |
return; |
| 1556 |
} |
| 1557 |
|
| 1558 |
if (undo_state!=NULL) { |
| 1559 |
undo_state=getstate(undo_state); |
| 1560 |
can_undo=1; |
| 1561 |
} |
| 1562 |
|
| 1563 |
|
| 1564 |
tmpobj(&actrec); |
| 1565 |
actrec.obj=0; |
| 1566 |
exec(&actrec,vnum,lnoun,prep,&mobj); |
| 1567 |
lnoun=NULL; |
| 1568 |
} |
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|