returns 1 if name is restricted for otmp->otyp */
| 572 | |
| 573 | /* returns 1 if name is restricted for otmp->otyp */ |
| 574 | boolean |
| 575 | restrict_name(struct obj *otmp, const char *name) |
| 576 | { |
| 577 | const struct artifact *a; |
| 578 | const char *aname, *odesc, *other; |
| 579 | boolean sametype[NUM_OBJECTS]; |
| 580 | int i, lo, hi, otyp = otmp->otyp, ocls = objects[otyp].oc_class; |
| 581 | |
| 582 | if (!*name) |
| 583 | return FALSE; |
| 584 | if (!strncmpi(name, "the ", 4)) |
| 585 | name += 4; |
| 586 | |
| 587 | /* decide what types of objects are the same as otyp; |
| 588 | if it's been discovered, then only itself matches; |
| 589 | otherwise, include all other undiscovered objects |
| 590 | of the same class which have the same description |
| 591 | or share the same pool of shuffled descriptions */ |
| 592 | (void) memset((genericptr_t) sametype, 0, sizeof sametype); /* FALSE */ |
| 593 | sametype[otyp] = TRUE; |
| 594 | if (!objects[otyp].oc_name_known |
| 595 | && (odesc = OBJ_DESCR(objects[otyp])) != 0) { |
| 596 | obj_shuffle_range(otyp, &lo, &hi); |
| 597 | for (i = svb.bases[ocls]; i < NUM_OBJECTS; i++) { |
| 598 | if (objects[i].oc_class != ocls) |
| 599 | break; |
| 600 | if (!objects[i].oc_name_known |
| 601 | && (other = OBJ_DESCR(objects[i])) != 0 |
| 602 | && (!strcmp(odesc, other) || (i >= lo && i <= hi))) |
| 603 | sametype[i] = TRUE; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | /* Since almost every artifact is SPFX_RESTR, it doesn't cost |
| 608 | us much to do the string comparison before the spfx check. |
| 609 | Bug fix: don't name multiple elven daggers "Sting". |
| 610 | */ |
| 611 | for (a = artilist + 1; a->otyp; a++) { |
| 612 | if (!sametype[a->otyp]) |
| 613 | continue; |
| 614 | aname = a->name; |
| 615 | if (!strncmpi(aname, "the ", 4)) |
| 616 | aname += 4; |
| 617 | if (!strcmp(aname, name)) |
| 618 | return (boolean) ((a->spfx & (SPFX_NOGEN | SPFX_RESTR)) != 0 |
| 619 | || otmp->quan > 1L); |
| 620 | } |
| 621 | |
| 622 | return FALSE; |
| 623 | } |
| 624 | |
| 625 | boolean |
| 626 | attacks(int adtyp, struct obj *otmp) |
no test coverage detected