| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "jacl.h" |
| 7 |
#include "language.h" |
| 8 |
#include "types.h" |
| 9 |
#include "prototypes.h" |
| 10 |
#include "parser.h" |
| 11 |
#include "encapsulate.h" |
| 12 |
#include <string.h> |
| 13 |
|
| 14 |
#define FIRST_LIST noun_number-2 |
| 15 |
#define SECOND_LIST noun_number |
| 16 |
|
| 17 |
int object_list[4][MAX_OBJECTS]; |
| 18 |
static int multiple_resolved[MAX_OBJECTS]; |
| 19 |
|
| 20 |
|
| 21 |
int list_size[4]; |
| 22 |
|
| 23 |
|
| 24 |
int max_size[4]; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
static int selection; |
| 34 |
|
| 35 |
static int matches = 0; |
| 36 |
static int highest_confidence = 0; |
| 37 |
static int prime_suspect = 0; |
| 38 |
static int done = 0; |
| 39 |
static int backup_pointer = 0; |
| 40 |
static int everything = 0; |
| 41 |
|
| 42 |
static int confidence[MAX_OBJECTS]; |
| 43 |
static int possible_objects[MAX_OBJECTS]; |
| 44 |
|
| 45 |
int it; |
| 46 |
int them[MAX_OBJECTS]; |
| 47 |
int her; |
| 48 |
int him; |
| 49 |
static int parent; |
| 50 |
|
| 51 |
int custom_error; |
| 52 |
|
| 53 |
int oops_word; |
| 54 |
int last_exact; |
| 55 |
|
| 56 |
static char *expected_scope[3]; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
static int from_objects[MAX_OBJECTS]; |
| 61 |
|
| 62 |
int after_from; |
| 63 |
static const char *from_word; |
| 64 |
|
| 65 |
static int object_expected = FALSE; |
| 66 |
|
| 67 |
char default_function[84]; |
| 68 |
static char object_name[84]; |
| 69 |
|
| 70 |
static char base_function[84]; |
| 71 |
static char before_function[84]; |
| 72 |
static char after_function[84]; |
| 73 |
static char local_after_function[84]; |
| 74 |
|
| 75 |
|
| 76 |
static int find_parent(int index); |
| 77 |
static int build_object_list(struct word_type *scope_word, int noun_number); |
| 78 |
static void call_functions(const char *base_name); |
| 79 |
static void add_to_list(int noun_number, int resolved_object); |
| 80 |
static int noun_resolve(struct word_type *scope_word, int finding_from, int noun_number); |
| 81 |
static int get_from_object(struct word_type *scope_word, int noun_number); |
| 82 |
static int is_direct_child_of_from(int child); |
| 83 |
static int is_child_of_from(int child); |
| 84 |
static int verify_from_object(int from_object); |
| 85 |
static void add_all(struct word_type *scope_word, int noun_number); |
| 86 |
static struct word_type *exact_match(struct word_type *pointer); |
| 87 |
static struct word_type *object_match(struct word_type *iterator, int noun_number); |
| 88 |
static void set_them(int noun_number); |
| 89 |
static void diagnose(void); |
| 90 |
|
| 91 |
void |
| 92 |
parser() |
| 93 |
{ |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
struct word_type *pointer; |
| 98 |
struct word_type *matched_word = NULL; |
| 99 |
|
| 100 |
int index; |
| 101 |
int current_noun = 0; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
last_exact = -1; |
| 109 |
after_from = -1; |
| 110 |
from_objects[0] = 0; |
| 111 |
|
| 112 |
noun[0] = FALSE; |
| 113 |
noun[1] = FALSE; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
for (index = 0; index < 4; index++) { |
| 118 |
list_size[index] = 0; |
| 119 |
max_size[index] = 0; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
clear_cinteger("$integer"); |
| 124 |
|
| 125 |
clear_cstring("$string"); |
| 126 |
|
| 127 |
clear_cstring("action"); |
| 128 |
|
| 129 |
if (grammar_table == NULL) { |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
INTERRUPTED->value = TRUE; |
| 134 |
diagnose(); |
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
pointer = grammar_table; |
| 141 |
|
| 142 |
while (word[wp] != NULL && pointer != NULL) { |
| 143 |
|
| 144 |
|
| 145 |
object_expected = FALSE; |
| 146 |
|
| 147 |
if (!strcmp(cstring_resolve("THEN_WORD")->value, word[wp])) { |
| 148 |
|
| 149 |
|
| 150 |
break; |
| 151 |
} else if ((matched_word = exact_match(pointer)) != NULL) { |
| 152 |
|
| 153 |
|
| 154 |
pointer = matched_word; |
| 155 |
pointer = pointer->first_child; |
| 156 |
} else if ((matched_word = object_match(pointer, current_noun)) != NULL) { |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
if (list_size[current_noun] > 1) { |
| 162 |
|
| 163 |
if (matched_word->word[1] != '*') { |
| 164 |
if (last_exact == -1) { |
| 165 |
write_text (cstring_resolve("NO_MULTI_START")->value); |
| 166 |
} else { |
| 167 |
sprintf(error_buffer, cstring_resolve("NO_MULTI_VERB")->value, word[last_exact]); |
| 168 |
write_text(error_buffer); |
| 169 |
} |
| 170 |
|
| 171 |
INTERRUPTED->value = TRUE; |
| 172 |
return; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
expected_scope[current_noun] = (char *) &matched_word->word; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
current_noun++; |
| 183 |
|
| 184 |
|
| 185 |
pointer = matched_word; |
| 186 |
pointer = pointer->first_child; |
| 187 |
} else { |
| 188 |
|
| 189 |
if (oops_word == -1 && word[wp] != NULL) { |
| 190 |
oops_word = wp; |
| 191 |
} |
| 192 |
|
| 193 |
if (custom_error == TRUE) { |
| 194 |
|
| 195 |
|
| 196 |
TIME->value = FALSE; |
| 197 |
INTERRUPTED->value = TRUE; |
| 198 |
return; |
| 199 |
} else { |
| 200 |
|
| 201 |
|
| 202 |
INTERRUPTED->value = TRUE; |
| 203 |
diagnose(); |
| 204 |
return; |
| 205 |
} |
| 206 |
} |
| 207 |
}; |
| 208 |
|
| 209 |
if (pointer == NULL) { |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
log_error(INCOMPLETE_GRAMMAR, PLUS_STDOUT); |
| 214 |
INTERRUPTED->value = TRUE; |
| 215 |
return; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
do { |
| 232 |
if (pointer->word[0] == '>') { |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
add_cstring("action", &pointer->word[1]); |
| 237 |
|
| 238 |
if (list_size[0] > 1) { |
| 239 |
|
| 240 |
|
| 241 |
noun[1] = first_available(1); |
| 242 |
|
| 243 |
for (index = 0; index < max_size[0]; index++) { |
| 244 |
|
| 245 |
if (object_list[0][index] != 0) { |
| 246 |
noun[0] = object_list[0][index]; |
| 247 |
|
| 248 |
if (MULTI_PREFIX->value) { |
| 249 |
|
| 250 |
plain_output(noun[0], FALSE); |
| 251 |
write_text(temp_buffer); |
| 252 |
write_text(": "); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
call_functions(pointer->word); |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
if (INTERRUPTED->value) { |
| 261 |
break; |
| 262 |
} |
| 263 |
} |
| 264 |
} |
| 265 |
} else { |
| 266 |
|
| 267 |
|
| 268 |
if (list_size[1] > 1) { |
| 269 |
|
| 270 |
|
| 271 |
noun[0] = first_available(0); |
| 272 |
|
| 273 |
for (index = 0; index < max_size[1]; index++) { |
| 274 |
|
| 275 |
if (object_list[1][index] != 0) { |
| 276 |
noun[1] = object_list[1][index]; |
| 277 |
|
| 278 |
if (MULTI_PREFIX->value) { |
| 279 |
|
| 280 |
plain_output(noun[0], FALSE); |
| 281 |
write_text(temp_buffer); |
| 282 |
write_text(": "); |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
call_functions(pointer->word); |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
if (INTERRUPTED->value) { |
| 291 |
break; |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
} else { |
| 296 |
|
| 297 |
|
| 298 |
if (list_size[0] == 0) { |
| 299 |
noun[0] = 0; |
| 300 |
noun[1] = 0; |
| 301 |
|
| 302 |
|
| 303 |
call_functions(pointer->word); |
| 304 |
} else { |
| 305 |
noun[0] = first_available(0); |
| 306 |
noun[1] = first_available(1); |
| 307 |
|
| 308 |
|
| 309 |
call_functions(pointer->word); |
| 310 |
} |
| 311 |
} |
| 312 |
} |
| 313 |
if (TIME->value == FALSE) { |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
} |
| 318 |
return; |
| 319 |
} else { |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
if (pointer->next_sibling == NULL) { |
| 324 |
break; |
| 325 |
} else { |
| 326 |
pointer = pointer->next_sibling; |
| 327 |
} |
| 328 |
} |
| 329 |
} while (TRUE); |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
INTERRUPTED->value = TRUE; |
| 335 |
diagnose(); |
| 336 |
return; |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
int |
| 343 |
first_available(int list_number) |
| 344 |
{ |
| 345 |
int index; |
| 346 |
|
| 347 |
if (list_size[list_number] == 0) return (0); |
| 348 |
|
| 349 |
|
| 350 |
for (index = 0; index < max_size[list_number]; index++) { |
| 351 |
if (object_list[list_number][index] != 0) { |
| 352 |
|
| 353 |
return (object_list[list_number][index]); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
return (0); |
| 360 |
} |
| 361 |
|
| 362 |
void |
| 363 |
call_functions(const char *base_name) |
| 364 |
{ |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
TIME->value = TRUE; |
| 372 |
|
| 373 |
strncpy(base_function, base_name + 1, 80); |
| 374 |
strcat(base_function, "_"); |
| 375 |
|
| 376 |
strncpy(override, base_function, 80); |
| 377 |
|
| 378 |
strcpy(before_function, "+before_"); |
| 379 |
strcat(before_function, base_name + 1); |
| 380 |
|
| 381 |
strcpy(after_function, "+after_"); |
| 382 |
strcat(after_function, base_name + 1); |
| 383 |
|
| 384 |
strcpy(local_after_function, "after_"); |
| 385 |
strcat(local_after_function, base_name + 1); |
| 386 |
if (noun[1] != FALSE) { |
| 387 |
strcat(local_after_function, "_"); |
| 388 |
strcat(local_after_function, object[noun[1]]->label); |
| 389 |
} |
| 390 |
if (noun[0] != FALSE) { |
| 391 |
strcat(local_after_function, "_"); |
| 392 |
strcat(local_after_function, object[noun[0]]->label); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
strcpy(default_function, "+default_"); |
| 399 |
strcat(default_function, base_name + 1); |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
if (execute("+before") != FALSE) |
| 404 |
return; |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
if (execute(before_function) != FALSE) |
| 409 |
return; |
| 410 |
|
| 411 |
if (noun[0] == FALSE) { |
| 412 |
strcat(base_function, object[HERE]->label); |
| 413 |
|
| 414 |
if (execute(base_function) == FALSE) { |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
strcat(override, "override_"); |
| 427 |
strcat(override, object[HERE]->label); |
| 428 |
|
| 429 |
|
| 430 |
strcpy(base_function, "+"); |
| 431 |
strcat(base_function, base_name + 1); |
| 432 |
|
| 433 |
|
| 434 |
if (execute(base_function) == FALSE) |
| 435 |
unkfunrun(base_function); |
| 436 |
} |
| 437 |
} else if (noun[1] == FALSE) { |
| 438 |
strcat(base_function, object[noun[0]]->label); |
| 439 |
|
| 440 |
if (execute(base_function) == FALSE) { |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
strcat(override, "override_"); |
| 453 |
strcat(override, object[noun[0]]->label); |
| 454 |
|
| 455 |
|
| 456 |
strcpy(base_function, "+"); |
| 457 |
strcat(base_function, base_name + 1); |
| 458 |
|
| 459 |
|
| 460 |
if (execute(base_function) == FALSE) |
| 461 |
unkfunrun(base_function); |
| 462 |
} |
| 463 |
} else { |
| 464 |
strcat(base_function, object[noun[1]]->label); |
| 465 |
strcat(base_function, "_"); |
| 466 |
strcat(base_function, object[noun[0]]->label); |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
if (execute(base_function) == FALSE) { |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
strcat(override, object[noun[1]]->label); |
| 483 |
strcat(override, "_override_"); |
| 484 |
strcat(override, object[noun[0]]->label); |
| 485 |
|
| 486 |
|
| 487 |
strcpy(base_function, "+"); |
| 488 |
strcat(base_function, base_name + 1); |
| 489 |
|
| 490 |
|
| 491 |
if (execute(base_function) == FALSE) |
| 492 |
unkfunrun(base_function); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
if (execute(local_after_function) != FALSE) |
| 499 |
return; |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
if (execute(after_function) != FALSE) |
| 504 |
return; |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
if (execute("+after") != FALSE) |
| 509 |
return; |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
if (TIME->value) { |
| 516 |
|
| 517 |
eachturn(); |
| 518 |
} |
| 519 |
|
| 520 |
return; |
| 521 |
} |
| 522 |
|
| 523 |
struct word_type * |
| 524 |
object_match(struct word_type *iterator, int noun_number) |
| 525 |
{ |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
int object_was_option = FALSE; |
| 532 |
|
| 533 |
do { |
| 534 |
|
| 535 |
|
| 536 |
if (iterator->word[0] == '*') { |
| 537 |
object_was_option = TRUE; |
| 538 |
if (build_object_list(iterator, noun_number)) { |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
return (iterator); |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
if (custom_error == TRUE) { |
| 547 |
|
| 548 |
|
| 549 |
return (NULL); |
| 550 |
} |
| 551 |
} |
| 552 |
while ((iterator = iterator->next_sibling) != NULL); |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
if (object_was_option) { |
| 559 |
|
| 560 |
|
| 561 |
diagnose(); |
| 562 |
custom_error = TRUE; |
| 563 |
} |
| 564 |
|
| 565 |
return (NULL); |
| 566 |
} |
| 567 |
|
| 568 |
struct word_type * |
| 569 |
exact_match(struct word_type *pointer) |
| 570 |
{ |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
struct word_type *iterator = pointer; |
| 576 |
|
| 577 |
do { |
| 578 |
if (iterator->word[0] == '*') { |
| 579 |
|
| 580 |
|
| 581 |
} else if (!strcmp(iterator->word, "$string")) { |
| 582 |
add_cstring("$string", word[wp]); |
| 583 |
last_exact = wp; |
| 584 |
wp++; |
| 585 |
return (iterator); |
| 586 |
} else if (!strcmp(iterator->word, "$integer") && |
| 587 |
validate(word[wp])) { |
| 588 |
add_cinteger("$integer", atoi(word[wp])); |
| 589 |
last_exact = wp; |
| 590 |
wp++; |
| 591 |
return (iterator); |
| 592 |
} else if (!strcmp(word[wp], iterator->word)) { |
| 593 |
last_exact = wp; |
| 594 |
wp++; |
| 595 |
return (iterator); |
| 596 |
} |
| 597 |
} |
| 598 |
while ((iterator = iterator->next_sibling) != NULL); |
| 599 |
|
| 600 |
|
| 601 |
return (NULL); |
| 602 |
} |
| 603 |
|
| 604 |
static int |
| 605 |
is_terminator(struct word_type *scope_word) |
| 606 |
{ |
| 607 |
struct word_type *terminator = scope_word->first_child; |
| 608 |
|
| 609 |
if (terminator != NULL) { |
| 610 |
|
| 611 |
|
| 612 |
do { |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
if (!strcmp(word[wp], terminator->word) |
| 617 |
|| (!strcmp(terminator->word, "$integer") |
| 618 |
&& validate(word[wp]))) { |
| 619 |
return (TRUE); |
| 620 |
} |
| 621 |
} |
| 622 |
while ((terminator = terminator->next_sibling) != NULL); |
| 623 |
} |
| 624 |
|
| 625 |
return (FALSE); |
| 626 |
} |
| 627 |
|
| 628 |
int |
| 629 |
build_object_list(struct word_type *scope_word, int noun_number) |
| 630 |
{ |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
int index, counter; |
| 635 |
int resolved_object; |
| 636 |
const char *except_word; |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
if (get_from_object(scope_word, noun_number) == FALSE) { |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
return (FALSE); |
| 645 |
} |
| 646 |
|
| 647 |
while (word[wp] != NULL) { |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
if (!strcmp(word[wp], cstring_resolve("BUT_WORD")->value) || |
| 654 |
!strcmp(word[wp], cstring_resolve("EXCEPT_WORD")->value)) { |
| 655 |
|
| 656 |
|
| 657 |
except_word = word[wp]; |
| 658 |
|
| 659 |
wp++; |
| 660 |
|
| 661 |
if (word[wp] != NULL && !strcmp(word[wp], cstring_resolve("FOR_WORD")->value)) { |
| 662 |
|
| 663 |
wp++; |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
if (get_from_object(scope_word, noun_number) == FALSE) { |
| 668 |
|
| 669 |
|
| 670 |
return (FALSE); |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
if (noun_number < 2) { |
| 676 |
|
| 677 |
|
| 678 |
set_them(noun_number); |
| 679 |
|
| 680 |
|
| 681 |
noun_number = noun_number + 2; |
| 682 |
} else { |
| 683 |
sprintf (error_buffer, cstring_resolve("DOUBLE_EXCEPT")->value, except_word); |
| 684 |
write_text (error_buffer); |
| 685 |
custom_error = TRUE; |
| 686 |
return (FALSE); |
| 687 |
} |
| 688 |
} else if (after_from != -1 && !strcmp(word[wp], cstring_resolve("FROM_WORD")->value)) { |
| 689 |
|
| 690 |
|
| 691 |
wp = after_from; |
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
if (list_size[noun_number] == 0) { |
| 697 |
|
| 698 |
add_all(scope_word, noun_number); |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
if (get_from_object(scope_word, noun_number) == FALSE) { |
| 703 |
|
| 704 |
|
| 705 |
return (FALSE); |
| 706 |
} |
| 707 |
} else if (!strcmp("then", word[wp])) { |
| 708 |
break; |
| 709 |
} else if (is_terminator(scope_word)) { |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
break; |
| 714 |
} else if ( !strcmp(word[wp], "comma") || |
| 715 |
!strcmp(word[wp], cstring_resolve("AND_WORD")->value)) { |
| 716 |
|
| 717 |
wp++; |
| 718 |
} else { |
| 719 |
|
| 720 |
|
| 721 |
resolved_object = noun_resolve(scope_word, FALSE, noun_number); |
| 722 |
|
| 723 |
if (resolved_object == -1) { |
| 724 |
|
| 725 |
|
| 726 |
index = 0; |
| 727 |
|
| 728 |
while (multiple_resolved[index] != 0) { |
| 729 |
|
| 730 |
add_to_list (noun_number, multiple_resolved[index]); |
| 731 |
index++; |
| 732 |
} |
| 733 |
} else if (resolved_object) { |
| 734 |
|
| 735 |
add_to_list (noun_number, resolved_object); |
| 736 |
} else { |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
return (FALSE); |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
if (noun_number > 1 && list_size[noun_number] != 0) { |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
for (index = 0; index < max_size[SECOND_LIST]; index++) { |
| 752 |
if (object_list[SECOND_LIST][index] != 0) { |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
for (counter = 0; counter < max_size[FIRST_LIST]; counter++) { |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
if (object_list[FIRST_LIST][counter] == |
| 762 |
object_list[SECOND_LIST][index]) { |
| 763 |
|
| 764 |
|
| 765 |
object_list[FIRST_LIST][counter] = 0; |
| 766 |
list_size[FIRST_LIST]--; |
| 767 |
} |
| 768 |
} |
| 769 |
} |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
if (noun_number > 1) { |
| 774 |
|
| 775 |
noun_number = FIRST_LIST; |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
if (list_size[noun_number] != 0) { |
| 780 |
|
| 781 |
set_them(noun_number); |
| 782 |
|
| 783 |
return (TRUE); |
| 784 |
} else { |
| 785 |
|
| 786 |
|
| 787 |
if (!strcmp(scope_word->word, "*held") || |
| 788 |
!strcmp(scope_word->word, "**held")) { |
| 789 |
write_text(cstring_resolve("NONE_HELD")->value); |
| 790 |
} else { |
| 791 |
write_text(cstring_resolve("NO_OBJECTS")->value); |
| 792 |
} |
| 793 |
|
| 794 |
custom_error = TRUE; |
| 795 |
return (FALSE); |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
void |
| 800 |
set_them(int noun_number) |
| 801 |
{ |
| 802 |
int index, counter; |
| 803 |
|
| 804 |
if (list_size[noun_number] == 1) { |
| 805 |
|
| 806 |
|
| 807 |
for (index = 0; index < max_size[noun_number]; index++) { |
| 808 |
if (object_list[noun_number][index] != 0) { |
| 809 |
if (object[object_list[noun_number][index]]->attributes & PLURAL) { |
| 810 |
them[0] = object_list[noun_number][index]; |
| 811 |
them[1] = 0; |
| 812 |
break; |
| 813 |
} |
| 814 |
} |
| 815 |
} |
| 816 |
} else { |
| 817 |
|
| 818 |
|
| 819 |
counter = 0; |
| 820 |
|
| 821 |
for (index = 0; index < max_size[noun_number]; index++) { |
| 822 |
if (object_list[noun_number][index] != 0) { |
| 823 |
them[counter] = object_list[noun_number][index]; |
| 824 |
|
| 825 |
counter++; |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
them[counter] = 0; |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
void |
| 835 |
add_all(struct word_type *scope_word, int noun_number) |
| 836 |
{ |
| 837 |
int index; |
| 838 |
|
| 839 |
for (index = 1; index <= objects; index++) { |
| 840 |
if ((object[index]->MASS < HEAVY) && |
| 841 |
!(object[index]->attributes & LOCATION)) { |
| 842 |
if (is_direct_child_of_from(index) && |
| 843 |
scope(index, scope_word->word, RESTRICT)) { |
| 844 |
|
| 845 |
add_to_list (noun_number, index); |
| 846 |
} |
| 847 |
} |
| 848 |
} |
| 849 |
} |
| 850 |
|
| 851 |
int |
| 852 |
is_child_of_from(int child) |
| 853 |
{ |
| 854 |
|
| 855 |
|
| 856 |
int index = 0; |
| 857 |
|
| 858 |
if (from_objects[0] == 0) { |
| 859 |
|
| 860 |
return (TRUE); |
| 861 |
} |
| 862 |
|
| 863 |
while (from_objects[index] != 0) { |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
if (object[child]->PARENT == from_objects[index]) { |
| 875 |
|
| 876 |
return (TRUE); |
| 877 |
} |
| 878 |
index++; |
| 879 |
} |
| 880 |
|
| 881 |
return (FALSE); |
| 882 |
} |
| 883 |
|
| 884 |
int |
| 885 |
is_direct_child_of_from(int child) |
| 886 |
{ |
| 887 |
|
| 888 |
|
| 889 |
int index = 0; |
| 890 |
|
| 891 |
if (from_objects[0] == 0) { |
| 892 |
|
| 893 |
return (TRUE); |
| 894 |
} |
| 895 |
|
| 896 |
while (from_objects[index] != 0) { |
| 897 |
|
| 898 |
if (object[child]->PARENT == from_objects[index]) { |
| 899 |
|
| 900 |
return (TRUE); |
| 901 |
} |
| 902 |
index++; |
| 903 |
} |
| 904 |
|
| 905 |
return (FALSE); |
| 906 |
} |
| 907 |
|
| 908 |
int |
| 909 |
get_from_object(struct word_type *scope_word, int noun_number) |
| 910 |
{ |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
int index, counter, from_object; |
| 917 |
|
| 918 |
|
| 919 |
int backup = wp; |
| 920 |
|
| 921 |
|
| 922 |
struct word_type *terminator = scope_word->first_child; |
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
if (terminator != NULL) { |
| 927 |
|
| 928 |
if (!strcmp(cstring_resolve("FROM_WORD")->value, terminator->word)) { |
| 929 |
|
| 930 |
return (TRUE); |
| 931 |
} |
| 932 |
while ((terminator = terminator->next_sibling) != NULL); |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
while (word[wp] != NULL) { |
| 938 |
|
| 939 |
if (!strcmp(word[wp], cstring_resolve("FROM_WORD")->value)) { |
| 940 |
from_word = word[wp]; |
| 941 |
wp++; |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
from_object = noun_resolve(scope_word, TRUE, noun_number); |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
after_from = wp; |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
if (from_object == -1) { |
| 958 |
|
| 959 |
|
| 960 |
index = 0; |
| 961 |
counter = 0; |
| 962 |
|
| 963 |
|
| 964 |
while (multiple_resolved[index] != 0) { |
| 965 |
if (verify_from_object(multiple_resolved[index]) == FALSE) { |
| 966 |
|
| 967 |
return (FALSE); |
| 968 |
} else { |
| 969 |
from_objects[counter] = multiple_resolved[index]; |
| 970 |
counter++; |
| 971 |
} |
| 972 |
index++; |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
from_objects[counter] = 0; |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
wp = backup; |
| 981 |
return (TRUE); |
| 982 |
} else if (from_object) { |
| 983 |
if (verify_from_object(from_object) == FALSE) { |
| 984 |
return (FALSE); |
| 985 |
} else { |
| 986 |
|
| 987 |
from_objects[0] = from_object; |
| 988 |
from_objects[1] = 0; |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
wp = backup; |
| 993 |
return (TRUE); |
| 994 |
} |
| 995 |
} else { |
| 996 |
|
| 997 |
diagnose(); |
| 998 |
custom_error = TRUE; |
| 999 |
return (FALSE); |
| 1000 |
} |
| 1001 |
|
| 1002 |
} else if ( !strcmp(cstring_resolve("EXCEPT_WORD")->value, word[wp]) || |
| 1003 |
!strcmp(cstring_resolve("BUT_WORD")->value, word[wp])) { |
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
wp = backup; |
| 1008 |
return (TRUE); |
| 1009 |
} else if (is_terminator(scope_word) || !strcmp("then", word[wp])) { |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
wp = backup; |
| 1014 |
return (TRUE); |
| 1015 |
} |
| 1016 |
wp++; |
| 1017 |
} |
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
wp = backup; |
| 1022 |
return (TRUE); |
| 1023 |
} |
| 1024 |
|
| 1025 |
int |
| 1026 |
verify_from_object(int from_object) |
| 1027 |
{ |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
if (object[from_object]->attributes & CONTAINER && object[from_object]->attributes & CLOSED) { |
| 1038 |
|
| 1039 |
if (object[from_object]->attributes & FEMALE) { |
| 1040 |
sprintf (error_buffer, cstring_resolve("CONTAINER_CLOSED_FEM")->value, sentence_output(from_object, TRUE)); |
| 1041 |
} else { |
| 1042 |
sprintf (error_buffer, cstring_resolve("CONTAINER_CLOSED")->value, sentence_output(from_object, TRUE)); |
| 1043 |
} |
| 1044 |
write_text(error_buffer); |
| 1045 |
custom_error = TRUE; |
| 1046 |
return (FALSE); |
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
} |
| 1062 |
|
| 1063 |
|
| 1064 |
return (TRUE); |
| 1065 |
} |
| 1066 |
|
| 1067 |
void |
| 1068 |
add_to_list(int noun_number, int resolved_object) |
| 1069 |
{ |
| 1070 |
|
| 1071 |
|
| 1072 |
if (!(object[resolved_object]->attributes & ANIMATE)) |
| 1073 |
it = resolved_object; |
| 1074 |
if (object[resolved_object]->attributes & ANIMATE |
| 1075 |
&& object[resolved_object]->attributes & FEMALE) |
| 1076 |
her = resolved_object; |
| 1077 |
if (object[resolved_object]->attributes & ANIMATE |
| 1078 |
&& !(object[resolved_object]->attributes & FEMALE)) |
| 1079 |
him = resolved_object; |
| 1080 |
|
| 1081 |
|
| 1082 |
object_list[noun_number][max_size[noun_number]] = resolved_object; |
| 1083 |
list_size[noun_number]++; |
| 1084 |
max_size[noun_number]++; |
| 1085 |
} |
| 1086 |
|
| 1087 |
int |
| 1088 |
noun_resolve(struct word_type *scope_word, int finding_from, int noun_number) |
| 1089 |
{ |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
int object_matched; |
| 1096 |
|
| 1097 |
|
| 1098 |
int return_limit = 0; |
| 1099 |
|
| 1100 |
int index; |
| 1101 |
int counter; |
| 1102 |
int first_word = TRUE; |
| 1103 |
|
| 1104 |
struct word_type *terminator = scope_word->first_child; |
| 1105 |
struct name_type *current_name; |
| 1106 |
|
| 1107 |
matches = 0; |
| 1108 |
highest_confidence = 0; |
| 1109 |
prime_suspect = 0; |
| 1110 |
done = FALSE; |
| 1111 |
backup_pointer = wp; |
| 1112 |
everything = FALSE; |
| 1113 |
|
| 1114 |
if (word[wp] == NULL) { |
| 1115 |
|
| 1116 |
return (FALSE); |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
for (index = 1; index <= objects; index++) |
| 1122 |
confidence[index] = 1; |
| 1123 |
|
| 1124 |
|
| 1125 |
object_name[0] = 0; |
| 1126 |
|
| 1127 |
|
| 1128 |
if (validate(word[wp])) { |
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
if (word[wp +1] != NULL && !strcmp(word[wp + 1], cstring_resolve("OF_WORD")->value)) { |
| 1133 |
return_limit = atoi (word[wp]); |
| 1134 |
|
| 1135 |
|
| 1136 |
if (return_limit < 1) { |
| 1137 |
return_limit = 1; |
| 1138 |
} |
| 1139 |
|
| 1140 |
object_expected = TRUE; |
| 1141 |
strcpy(object_name, word[wp]); |
| 1142 |
strcat(object_name, " "); |
| 1143 |
strcat(object_name, cstring_resolve("OF_WORD")->value); |
| 1144 |
|
| 1145 |
|
| 1146 |
wp = wp + 2; |
| 1147 |
} |
| 1148 |
|
| 1149 |
|
| 1150 |
} |
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
error_buffer[0] = 0; |
| 1155 |
|
| 1156 |
while (word[wp] != NULL) { |
| 1157 |
|
| 1158 |
|
| 1159 |
if (first_word == FALSE) { |
| 1160 |
strcat(error_buffer, " "); |
| 1161 |
} |
| 1162 |
strcat(error_buffer, word[wp]); |
| 1163 |
first_word = FALSE; |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
terminator = scope_word->first_child; |
| 1169 |
|
| 1170 |
if (terminator != NULL) { |
| 1171 |
|
| 1172 |
|
| 1173 |
do { |
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
if (!strcmp(word[wp], terminator->word) |
| 1179 |
|| (!strcmp(word[wp], cstring_resolve("FROM_WORD")->value)) |
| 1180 |
|| (!strcmp(word[wp], cstring_resolve("AND_WORD")->value)) |
| 1181 |
|| (!strcmp(word[wp], "comma")) |
| 1182 |
|| (!strcmp(word[wp], cstring_resolve("BUT_WORD")->value)) |
| 1183 |
|| (!strcmp(word[wp], cstring_resolve("THEN_WORD")->value)) |
| 1184 |
|| (!strcmp(word[wp], cstring_resolve("EXCEPT_WORD")->value)) |
| 1185 |
|| (!strcmp(terminator->word, "$integer") |
| 1186 |
&& validate(word[wp]))) { |
| 1187 |
if (!matches) { |
| 1188 |
|
| 1189 |
|
| 1190 |
return (FALSE); |
| 1191 |
} else { |
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
done = TRUE; |
| 1196 |
break; |
| 1197 |
} |
| 1198 |
} |
| 1199 |
} |
| 1200 |
while ((terminator = terminator->next_sibling) != NULL); |
| 1201 |
} |
| 1202 |
|
| 1203 |
if (done == TRUE) { |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
break; |
| 1209 |
} |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
if (object_name[0] != 0) |
| 1217 |
strcat(object_name, " "); |
| 1218 |
|
| 1219 |
strcat(object_name, word[wp]); |
| 1220 |
|
| 1221 |
if (!strcmp("everything", word[wp])) { |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
if (return_limit == FALSE) { |
| 1227 |
return_limit = MAX_OBJECTS; |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
everything = TRUE; |
| 1232 |
|
| 1233 |
matches = 0; |
| 1234 |
|
| 1235 |
|
| 1236 |
for (index = 1; index <= objects; index++) { |
| 1237 |
if (confidence[index] != FALSE) { |
| 1238 |
matches++; |
| 1239 |
} |
| 1240 |
} |
| 1241 |
|
| 1242 |
|
| 1243 |
if (word[wp + 1] != NULL && !strcmp(cstring_resolve("OF_WORD")->value, word[wp + 1])) { |
| 1244 |
|
| 1245 |
wp++; |
| 1246 |
} |
| 1247 |
|
| 1248 |
} else { |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
for (index = 1; index <= objects; index++) { |
| 1253 |
if (!confidence[index]) { |
| 1254 |
|
| 1255 |
|
| 1256 |
continue; |
| 1257 |
} |
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
object_matched = FALSE; |
| 1262 |
|
| 1263 |
if (!strcmp(cstring_resolve("IT_WORD")->value, word[wp]) || |
| 1264 |
!strcmp(cstring_resolve("ITSELF_WORD")->value, word[wp])) { |
| 1265 |
if (it == FALSE) { |
| 1266 |
no_it(); |
| 1267 |
return (FALSE); |
| 1268 |
} else { |
| 1269 |
if (index == it) { |
| 1270 |
object_matched = TRUE; |
| 1271 |
} |
| 1272 |
} |
| 1273 |
} else if (!strcmp(cstring_resolve("HER_WORD")->value, word[wp]) || |
| 1274 |
!strcmp(cstring_resolve("HERSELF_WORD")->value, word[wp])) { |
| 1275 |
if (her == FALSE) { |
| 1276 |
no_it(); |
| 1277 |
return (FALSE); |
| 1278 |
} else { |
| 1279 |
if (index == her) { |
| 1280 |
object_matched = TRUE; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
} else if (!strcmp(cstring_resolve("HIM_WORD")->value, word[wp]) || |
| 1284 |
!strcmp(cstring_resolve("HIMSELF_WORD")->value, word[wp])) { |
| 1285 |
if (him == FALSE) { |
| 1286 |
no_it(); |
| 1287 |
return (FALSE); |
| 1288 |
} else { |
| 1289 |
if (index == him) { |
| 1290 |
object_matched = TRUE; |
| 1291 |
} |
| 1292 |
} |
| 1293 |
} else if (!strcmp(cstring_resolve("THEM_WORD")->value, word[wp]) || |
| 1294 |
!strcmp(cstring_resolve("THEMSELVES_WORD")->value, word[wp]) || |
| 1295 |
!strcmp(cstring_resolve("ONES_WORD")->value, word[wp])) { |
| 1296 |
|
| 1297 |
|
| 1298 |
if (return_limit == FALSE) { |
| 1299 |
return_limit = MAX_OBJECTS; |
| 1300 |
} |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
counter = 0; |
| 1305 |
|
| 1306 |
while (them[counter] != 0) { |
| 1307 |
if (them[counter] == index) { |
| 1308 |
|
| 1309 |
object_matched = TRUE; |
| 1310 |
break; |
| 1311 |
} |
| 1312 |
counter++; |
| 1313 |
} |
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
} else { |
| 1330 |
current_name = object[index]->first_name; |
| 1331 |
|
| 1332 |
while (current_name != NULL) { |
| 1333 |
|
| 1334 |
if (!strcmp(word[wp], current_name->name)) { |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
object_matched = TRUE; |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
break; |
| 1343 |
} |
| 1344 |
current_name = current_name->next_name; |
| 1345 |
} |
| 1346 |
|
| 1347 |
|
| 1348 |
current_name = object[index]->first_plural; |
| 1349 |
|
| 1350 |
while (current_name != NULL) { |
| 1351 |
|
| 1352 |
if (!strcmp(word[wp], current_name->name)) { |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
object_matched = TRUE; |
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
if (return_limit == FALSE) { |
| 1364 |
return_limit = MAX_OBJECTS; |
| 1365 |
} |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
break; |
| 1370 |
} |
| 1371 |
current_name = current_name->next_name; |
| 1372 |
} |
| 1373 |
} |
| 1374 |
|
| 1375 |
if (object_matched) { |
| 1376 |
|
| 1377 |
|
| 1378 |
if (confidence[index] == 1) { |
| 1379 |
|
| 1380 |
|
| 1381 |
matches++; |
| 1382 |
} |
| 1383 |
if (confidence[index] != FALSE) { |
| 1384 |
|
| 1385 |
|
| 1386 |
confidence[index]++; |
| 1387 |
} |
| 1388 |
} else { |
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
if (confidence[index] > 1) |
| 1394 |
matches--; |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
confidence[index] = FALSE; |
| 1399 |
} |
| 1400 |
} |
| 1401 |
} |
| 1402 |
|
| 1403 |
if (!matches) { |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
if (oops_word == -1 && word[wp] != NULL) { |
| 1411 |
oops_word = wp; |
| 1412 |
} |
| 1413 |
|
| 1414 |
break; |
| 1415 |
} |
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
wp++; |
| 1420 |
} |
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
if (return_limit == FALSE) { |
| 1431 |
|
| 1432 |
return_limit = 1; |
| 1433 |
} |
| 1434 |
|
| 1435 |
if (matches == 0) { |
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
object_expected = TRUE; |
| 1446 |
|
| 1447 |
wp = backup_pointer; |
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
return (FALSE); |
| 1453 |
|
| 1454 |
} |
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
for (index = 1; index <= objects; index++) { |
| 1462 |
if (confidence[index] != FALSE && strcmp(scope_word->word, "*anywhere") && strcmp(scope_word->word, "**anywhere") && strcmp(scope_word->word, "*location")) { |
| 1463 |
if (scope(index, "*present", UNRESTRICT) == FALSE) { |
| 1464 |
matches--; |
| 1465 |
confidence[index] = FALSE; |
| 1466 |
|
| 1467 |
} |
| 1468 |
} |
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
if (confidence[index] == 1 && return_limit > 1) { |
| 1473 |
if ((object[index]->MASS >= HEAVY) || |
| 1474 |
(object[index]->attributes & LOCATION)) { |
| 1475 |
matches--; |
| 1476 |
confidence[index] = 0; |
| 1477 |
|
| 1478 |
} |
| 1479 |
} |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
if (confidence[index] != FALSE && return_limit == 1) { |
| 1484 |
current_name = object[index]->first_name; |
| 1485 |
counter = 0; |
| 1486 |
while (current_name != NULL) { |
| 1487 |
counter++; |
| 1488 |
current_name = current_name->next_name; |
| 1489 |
} |
| 1490 |
confidence[index] = ((confidence[index] - 1) * 100) / counter; |
| 1491 |
} |
| 1492 |
} |
| 1493 |
|
| 1494 |
|
| 1495 |
highest_confidence = 0; |
| 1496 |
|
| 1497 |
for (index = 1; index <= objects; index++) { |
| 1498 |
if (confidence[index] > highest_confidence) { |
| 1499 |
highest_confidence = confidence[index]; |
| 1500 |
} |
| 1501 |
} |
| 1502 |
|
| 1503 |
|
| 1504 |
for (index = 1; index <= objects; index++) { |
| 1505 |
if (confidence[index] != FALSE) { |
| 1506 |
if (scope(index, "*present", UNRESTRICT) != FALSE) { |
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
if (confidence[index] == highest_confidence) { |
| 1512 |
prime_suspect = index; |
| 1513 |
} |
| 1514 |
|
| 1515 |
} |
| 1516 |
|
| 1517 |
if (finding_from) { |
| 1518 |
if (strcmp(scope_word->word, "*anywhere") && strcmp(scope_word->word, "**anywhere")) { |
| 1519 |
if (scope(index, "*present", TRUE) == FALSE) { |
| 1520 |
matches--; |
| 1521 |
confidence[index] = FALSE; |
| 1522 |
continue; |
| 1523 |
} |
| 1524 |
} |
| 1525 |
} else if (scope(index, scope_word->word, (everything && !from_objects[0])) == FALSE) { |
| 1526 |
|
| 1527 |
|
| 1528 |
matches--; |
| 1529 |
confidence[index] = FALSE; |
| 1530 |
continue; |
| 1531 |
} |
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
if (is_child_of_from(index) == FALSE) { |
| 1536 |
matches--; |
| 1537 |
confidence[index] = FALSE; |
| 1538 |
|
| 1539 |
} |
| 1540 |
} |
| 1541 |
} |
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
if (matches > 1 && return_limit == 1) { |
| 1549 |
|
| 1550 |
|
| 1551 |
highest_confidence = 0; |
| 1552 |
|
| 1553 |
for (index = 1; index <= objects; index++) { |
| 1554 |
if (confidence[index] > highest_confidence) { |
| 1555 |
highest_confidence = confidence[index]; |
| 1556 |
} |
| 1557 |
} |
| 1558 |
|
| 1559 |
|
| 1560 |
for (index = 1; index <= objects; index++) { |
| 1561 |
|
| 1562 |
|
| 1563 |
if (confidence[index] != FALSE) { |
| 1564 |
if (confidence[index] < highest_confidence) { |
| 1565 |
|
| 1566 |
confidence[index] = FALSE; |
| 1567 |
matches--; |
| 1568 |
} |
| 1569 |
} |
| 1570 |
} |
| 1571 |
} |
| 1572 |
|
| 1573 |
if (matches == 0) { |
| 1574 |
|
| 1575 |
|
| 1576 |
if (prime_suspect != FALSE) { |
| 1577 |
return (prime_suspect); |
| 1578 |
} else { |
| 1579 |
object_expected = TRUE; |
| 1580 |
wp = backup_pointer; |
| 1581 |
return (FALSE); |
| 1582 |
} |
| 1583 |
} |
| 1584 |
|
| 1585 |
if (matches == 1) { |
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
for (index = 1; index <= objects; index++) { |
| 1590 |
if (confidence[index] != FALSE) { |
| 1591 |
return (index); |
| 1592 |
} |
| 1593 |
} |
| 1594 |
} |
| 1595 |
|
| 1596 |
if (return_limit > 1) { |
| 1597 |
|
| 1598 |
|
| 1599 |
counter = 0; |
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
for (index = 1; index <= objects; index++) { |
| 1604 |
if (confidence[index] != FALSE) { |
| 1605 |
|
| 1606 |
|
| 1607 |
multiple_resolved[counter] = index; |
| 1608 |
return_limit--; |
| 1609 |
|
| 1610 |
counter++; |
| 1611 |
|
| 1612 |
if (return_limit == 0) { |
| 1613 |
break; |
| 1614 |
} |
| 1615 |
} |
| 1616 |
} |
| 1617 |
|
| 1618 |
|
| 1619 |
multiple_resolved[counter] = 0; |
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
return (-1); |
| 1624 |
} |
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
int situation = noun_number; |
| 1630 |
|
| 1631 |
if (finding_from) { |
| 1632 |
situation += 4; |
| 1633 |
} |
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
if (matches == 0) { |
| 1663 |
return (prime_suspect); |
| 1664 |
} |
| 1665 |
|
| 1666 |
|
| 1667 |
if (matches == 1) { |
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
for (index = 1; index <= objects; index++) { |
| 1672 |
if (confidence[index] != FALSE) { |
| 1673 |
return (index); |
| 1674 |
} |
| 1675 |
} |
| 1676 |
} |
| 1677 |
|
| 1678 |
#if defined GLK || defined __NDS__ |
| 1679 |
|
| 1680 |
|
| 1681 |
counter = 1; |
| 1682 |
write_text(cstring_resolve("BY")->value); |
| 1683 |
write_text(error_buffer); |
| 1684 |
write_text(cstring_resolve("REFERRING_TO")->value); |
| 1685 |
for (index = 1; index <= objects; index++) { |
| 1686 |
if (confidence[index] != FALSE) { |
| 1687 |
possible_objects[counter] = index; |
| 1688 |
sprintf(text_buffer, " [%d] ", counter); |
| 1689 |
write_text(text_buffer); |
| 1690 |
sentence_output(index, 0); |
| 1691 |
write_text(temp_buffer); |
| 1692 |
matches--; |
| 1693 |
if (counter < 9) |
| 1694 |
counter++; |
| 1695 |
write_text("^"); |
| 1696 |
} |
| 1697 |
} |
| 1698 |
|
| 1699 |
|
| 1700 |
selection = get_number(FALSE, 1, counter - 1); |
| 1701 |
|
| 1702 |
if (selection == -1) { |
| 1703 |
write_text (cstring_resolve("INVALID_SELECTION")->value); |
| 1704 |
custom_error = TRUE; |
| 1705 |
return (FALSE); |
| 1706 |
} else { |
| 1707 |
write_text("^"); |
| 1708 |
return (possible_objects[selection]); |
| 1709 |
} |
| 1710 |
#else |
| 1711 |
|
| 1712 |
|
| 1713 |
write_text(cstring_resolve("WHEN_YOU_SAY")->value); |
| 1714 |
write_text(error_buffer); |
| 1715 |
write_text(cstring_resolve("MUST_SPECIFY")->value); |
| 1716 |
for (index = 1; index <= objects; index++) { |
| 1717 |
if (confidence[index] != FALSE) { |
| 1718 |
sentence_output(index, 0); |
| 1719 |
write_text(temp_buffer); |
| 1720 |
matches--; |
| 1721 |
if (matches == 0) { |
| 1722 |
write_text("."); |
| 1723 |
break; |
| 1724 |
} else if (matches == 1) { |
| 1725 |
write_text(cstring_resolve("OR_WORD")->value); |
| 1726 |
} else |
| 1727 |
write_text(", "); |
| 1728 |
} |
| 1729 |
} |
| 1730 |
write_text("^"); |
| 1731 |
|
| 1732 |
custom_error = TRUE; |
| 1733 |
return (FALSE); |
| 1734 |
#endif |
| 1735 |
} |
| 1736 |
|
| 1737 |
void |
| 1738 |
diagnose() |
| 1739 |
{ |
| 1740 |
if (custom_error) { |
| 1741 |
TIME->value = FALSE; |
| 1742 |
return; |
| 1743 |
} |
| 1744 |
if (word[wp] == NULL) |
| 1745 |
write_text(cstring_resolve("INCOMPLETE_SENTENCE")->value); |
| 1746 |
else if (object_expected && wp != 0) { |
| 1747 |
write_text(cstring_resolve("UNKNOWN_OBJECT")->value); |
| 1748 |
write_text(object_name); |
| 1749 |
write_text(cstring_resolve("UNKNOWN_OBJECT_END")->value); |
| 1750 |
} else { |
| 1751 |
write_text(cstring_resolve("CANT_USE_WORD")->value); |
| 1752 |
write_text(word[wp]); |
| 1753 |
write_text(cstring_resolve("IN_CONTEXT")->value); |
| 1754 |
} |
| 1755 |
TIME->value = FALSE; |
| 1756 |
} |
| 1757 |
|
| 1758 |
int |
| 1759 |
scope(int index, const char *expected, int restricted) |
| 1760 |
{ |
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
int temp = 0; |
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
if (!strcmp(expected, "*held") || !strcmp(expected, "**held")) { |
| 1770 |
if (object[index]->PARENT == HELD) { |
| 1771 |
return (TRUE); |
| 1772 |
} else if (object[index]->MASS >= HEAVY) { |
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
temp = object[index]->PARENT; |
| 1778 |
if (temp > 0 && temp < objects) { |
| 1779 |
if (object[temp]->PARENT == HELD) { |
| 1780 |
return (TRUE); |
| 1781 |
} |
| 1782 |
} |
| 1783 |
return (FALSE); |
| 1784 |
} else { |
| 1785 |
return (FALSE); |
| 1786 |
} |
| 1787 |
} else if (!strcmp(expected, "*location")) { |
| 1788 |
if (object[index]->attributes & LOCATION) { |
| 1789 |
return (TRUE); |
| 1790 |
} else { |
| 1791 |
return (FALSE); |
| 1792 |
} |
| 1793 |
} else if (!strcmp(expected, "*here") || !strcmp(expected, "**here")) { |
| 1794 |
if (object[index]->PARENT == HERE || index == HERE) { |
| 1795 |
|
| 1796 |
|
| 1797 |
return (TRUE); |
| 1798 |
} else if (object[index]->PARENT == HELD) { |
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
return (FALSE); |
| 1803 |
} else { |
| 1804 |
|
| 1805 |
return (parent_of(HERE, index, restricted)); |
| 1806 |
} |
| 1807 |
} else if (!strcmp(expected, "*anywhere") || !strcmp(expected, "**anywhere")) { |
| 1808 |
return (TRUE); |
| 1809 |
} else if (!strcmp(expected, "*inside") || !strcmp(expected, "**inside")) { |
| 1810 |
if (object_list[0][0] >0 && object_list[0][0] < objects) { |
| 1811 |
return (parent_of(object_list[0][0], index, restricted)); |
| 1812 |
} else { |
| 1813 |
|
| 1814 |
return (parent_of(HERE, index, restricted)); |
| 1815 |
} |
| 1816 |
} else if (!strcmp(expected, "*present") || !strcmp(expected, "**present")) { |
| 1817 |
if (index == HERE) { |
| 1818 |
return (TRUE); |
| 1819 |
} else { |
| 1820 |
if (find_parent(index)) { |
| 1821 |
return (TRUE); |
| 1822 |
} else { |
| 1823 |
return (FALSE); |
| 1824 |
} |
| 1825 |
} |
| 1826 |
} else { |
| 1827 |
unkscorun(expected); |
| 1828 |
return (FALSE); |
| 1829 |
} |
| 1830 |
} |
| 1831 |
|
| 1832 |
int |
| 1833 |
find_parent(int index) |
| 1834 |
{ |
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
if (!(object[index]->attributes & LOCATION) && |
| 1842 |
object[index]->PARENT != NOWHERE) { |
| 1843 |
|
| 1844 |
parent = object[index]->PARENT; |
| 1845 |
|
| 1846 |
|
| 1847 |
if (index == parent) { |
| 1848 |
|
| 1849 |
sprintf(error_buffer, SELF_REFERENCE, executing_function->name, object[index]->label); |
| 1850 |
log_error(error_buffer, PLUS_STDOUT); |
| 1851 |
return (FALSE); |
| 1852 |
} else if (!(object[parent]->attributes & LOCATION) |
| 1853 |
&& ((object[parent]->attributes & CLOSED && object[parent]->attributes & CONTAINER) |
| 1854 |
|| object[parent]->attributes & CONCEALING)) { |
| 1855 |
|
| 1856 |
return (FALSE); |
| 1857 |
} else if (parent == HERE || parent == HELD) { |
| 1858 |
|
| 1859 |
return (TRUE); |
| 1860 |
} else { |
| 1861 |
if (object[parent]->attributes & LOCATION) { |
| 1862 |
|
| 1863 |
return (FALSE); |
| 1864 |
} else { |
| 1865 |
|
| 1866 |
return (find_parent(parent)); |
| 1867 |
} |
| 1868 |
} |
| 1869 |
} else { |
| 1870 |
if (index == HERE) |
| 1871 |
|
| 1872 |
return (TRUE); |
| 1873 |
else |
| 1874 |
return (FALSE); |
| 1875 |
} |
| 1876 |
} |
| 1877 |
|
| 1878 |
int |
| 1879 |
parent_of(int parent, int child, int restricted) |
| 1880 |
{ |
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
int index; |
| 1890 |
|
| 1891 |
|
| 1892 |
if (child == parent) { |
| 1893 |
return (TRUE); |
| 1894 |
} else if (!(object[child]->attributes & LOCATION) && |
| 1895 |
object[child]->PARENT != NOWHERE) { |
| 1896 |
|
| 1897 |
index = object[child]->PARENT; |
| 1898 |
|
| 1899 |
|
| 1900 |
if (index == child) { |
| 1901 |
|
| 1902 |
sprintf(error_buffer, SELF_REFERENCE, executing_function->name, object[index]->label); |
| 1903 |
log_error(error_buffer, PLUS_STDOUT); |
| 1904 |
|
| 1905 |
return (FALSE); |
| 1906 |
} else if (!(object[index]->attributes & LOCATION) |
| 1907 |
&& ((object[index]->attributes & CLOSED && object[index]->attributes & CONTAINER) |
| 1908 |
|| object[index]->attributes & CONCEALING)) { |
| 1909 |
|
| 1910 |
|
| 1911 |
return (FALSE); |
| 1912 |
} else if (restricted && object[index]->MASS < HEAVY && index != parent) { |
| 1913 |
|
| 1914 |
return (FALSE); |
| 1915 |
} else { |
| 1916 |
|
| 1917 |
if (index == parent) { |
| 1918 |
|
| 1919 |
return (TRUE); |
| 1920 |
} else if (object[index]->attributes & LOCATION) { |
| 1921 |
return (FALSE); |
| 1922 |
} else { |
| 1923 |
|
| 1924 |
|
| 1925 |
return (parent_of(parent, index, restricted)); |
| 1926 |
} |
| 1927 |
} |
| 1928 |
} else { |
| 1929 |
|
| 1930 |
return (FALSE); |
| 1931 |
} |
| 1932 |
} |