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

Function select_hwep

src/weapon.c:704–741  ·  view source on GitHub ↗

select a hand to hand weapon for the monster */

Source from the content-addressed store, hash-verified

702
703/* select a hand to hand weapon for the monster */
704struct obj *
705select_hwep(struct monst *mtmp)
706{
707 struct obj *otmp;
708 int i;
709 boolean strong = strongmonst(mtmp->data);
710 boolean wearing_shield = (mtmp->misc_worn_check & W_ARMS) != 0;
711
712 /* prefer artifacts to everything else */
713 for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) {
714 if (otmp->oclass == WEAPON_CLASS && otmp->oartifact
715 && touch_artifact(otmp, mtmp)
716 && ((strong && !wearing_shield)
717 || !objects[otmp->otyp].oc_bimanual))
718 return otmp;
719 }
720
721 if (is_giant(mtmp->data)) /* giants just love to use clubs */
722 Oselect(CLUB);
723 else if (mtmp->data == &mons[PM_BALROG] && uwep)
724 Oselect(BULLWHIP);
725
726 /* only strong monsters can wield big (esp. long) weapons */
727 /* big weapon is basically the same as bimanual */
728 /* all monsters can wield the remaining weapons */
729 for (i = 0; i < SIZE(hwep); i++) {
730 if (hwep[i] == CORPSE && !(mtmp->misc_worn_check & W_ARMG)
731 && !resists_ston(mtmp))
732 continue;
733 if (((strong && !wearing_shield) || !objects[hwep[i]].oc_bimanual)
734 && (objects[hwep[i]].oc_material != SILVER
735 || !mon_hates_silver(mtmp)))
736 Oselect(hwep[i]);
737 }
738
739 /* failure */
740 return (struct obj *) 0;
741}
742
743/* Called after polymorphing a monster, robbing it, etc.... Monsters
744 * otherwise never unwield stuff on their own. Might print message.

Callers 2

mon_wield_itemFunction · 0.85
gain_guardian_angelFunction · 0.85

Calls 2

touch_artifactFunction · 0.85
mon_hates_silverFunction · 0.85

Tested by

no test coverage detected