MCPcopy Index your code
hub / github.com/NetHack/NetHack / knows_class

Function knows_class

src/u_init.c:585–629  ·  view source on GitHub ↗

Know ordinary (non-magical) objects of a certain class, like all gems except the loadstone and luckstone. */

Source from the content-addressed store, hash-verified

583/* Know ordinary (non-magical) objects of a certain class,
584 like all gems except the loadstone and luckstone. */
585staticfn void
586knows_class(char sym)
587{
588 struct obj odummy, *o;
589 int ct;
590
591 if (u.uroleplay.pauper)
592 return;
593
594 odummy = cg.zeroobj;
595 odummy.oclass = sym;
596 o = &odummy; /* for use in various obj.h macros */
597
598 /*
599 * Note: the exceptions here can be bypassed if necessary by
600 * calling knows_object() directly. So an elven ranger,
601 * for example, knows all elven weapons despite the bow,
602 * arrow, and spear limitation below.
603 */
604
605 for (ct = svb.bases[(uchar) sym]; ct < svb.bases[(uchar) sym + 1]; ct++) {
606 /* not flagged as magic but shouldn't be pre-discovered
607 (small shields look the same as two types of magical shield;
608 cornuthaum / dunce cap look the same as each other) */
609 if (ct == CORNUTHAUM || ct == DUNCE_CAP || ct == SMALL_SHIELD)
610 continue;
611 if (sym == WEAPON_CLASS) {
612 odummy.otyp = ct; /* update 'o' */
613 /* arbitrary: only knights and samurai recognize polearms */
614 if ((!Role_if(PM_KNIGHT) && !Role_if(PM_SAMURAI)) && is_pole(o))
615 continue;
616 /* rangers know all launchers (bows, &c), ammo (arrows, &c),
617 and spears regardless of race/species, but not other weapons */
618 if (Role_if(PM_RANGER)
619 && (!is_launcher(o) && !is_ammo(o) && !is_spear(o)))
620 continue;
621 /* rogues know daggers, regardless of racial variations */
622 if (Role_if(PM_ROGUE) && (objects[o->otyp].oc_skill != P_DAGGER))
623 continue;
624 }
625
626 if (objects[ct].oc_class == sym && !objects[ct].oc_magic)
627 knows_object(ct, FALSE);
628 }
629}
630
631/* role-specific initializations, mostly inventory
632

Callers 1

u_init_roleFunction · 0.85

Calls 1

knows_objectFunction · 0.85

Tested by

no test coverage detected