* Used for scrolls, potions, spells, and crystal balls. Returns: * * 1 - nothing was detected * 0 - something was detected */
| 600 | * 0 - something was detected |
| 601 | */ |
| 602 | int |
| 603 | object_detect(struct obj *detector, /* object doing the detecting */ |
| 604 | int class) /* an object class, 0 for all */ |
| 605 | { |
| 606 | coordxy x, y; |
| 607 | char stuff[BUFSZ]; |
| 608 | int is_cursed = (detector && detector->cursed); |
| 609 | int do_dknown = (detector && (detector->oclass == POTION_CLASS |
| 610 | || detector->oclass == SPBOOK_CLASS) |
| 611 | && detector->blessed); |
| 612 | int ct = 0, ctu = 0; |
| 613 | struct obj *obj, *otmp = (struct obj *) 0; |
| 614 | struct monst *mtmp; |
| 615 | int sym, boulder = 0, ter_typ = TER_DETECT | TER_OBJ; |
| 616 | |
| 617 | if (class < 0 || class >= MAXOCLASSES) { |
| 618 | impossible("object_detect: illegal class %d", class); |
| 619 | class = 0; |
| 620 | } |
| 621 | |
| 622 | /* Special boulder symbol check - does the class symbol happen |
| 623 | * to match showsyms[SYM_BOULDER + SYM_OFF_X] which is user-defined. |
| 624 | * If so, that means we aren't sure what they really wanted to |
| 625 | * detect. Rather than trump anything, show both possibilities. |
| 626 | * We can exclude checking the buried obj chain for boulders below. |
| 627 | */ |
| 628 | sym = class ? def_oc_syms[class].sym : 0; |
| 629 | if (sym && sym == gs.showsyms[SYM_BOULDER + SYM_OFF_X]) |
| 630 | boulder = ROCK_CLASS; |
| 631 | |
| 632 | if (Hallucination || (Confusion && class == SCROLL_CLASS)) |
| 633 | Strcpy(stuff, something); |
| 634 | else |
| 635 | Strcpy(stuff, class ? def_oc_syms[class].name : "objects"); |
| 636 | if (boulder && class != ROCK_CLASS) |
| 637 | Strcat(stuff, " and/or large stones"); |
| 638 | |
| 639 | if (do_dknown) |
| 640 | for (obj = gi.invent; obj; obj = obj->nobj) |
| 641 | observe_recursively(obj); |
| 642 | |
| 643 | for (obj = fobj; obj; obj = obj->nobj) { |
| 644 | if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) { |
| 645 | if (u_at(obj->ox, obj->oy)) |
| 646 | ctu++; |
| 647 | else |
| 648 | ct++; |
| 649 | } |
| 650 | if (do_dknown) |
| 651 | observe_recursively(obj); |
| 652 | } |
| 653 | |
| 654 | for (obj = svl.level.buriedobjlist; obj; obj = obj->nobj) { |
| 655 | if (!class || o_in(obj, class)) { |
| 656 | if (u_at(obj->ox, obj->oy)) |
| 657 | ctu++; |
| 658 | else |
| 659 | ct++; |
no test coverage detected