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

Function possibly_unwield

src/weapon.c:746–795  ·  view source on GitHub ↗

Called after polymorphing a monster, robbing it, etc.... Monsters * otherwise never unwield stuff on their own. Might print message. */

Source from the content-addressed store, hash-verified

744 * otherwise never unwield stuff on their own. Might print message.
745 */
746void
747possibly_unwield(struct monst *mon, boolean polyspot)
748{
749 struct obj *obj, *mw_tmp;
750
751 if (!(mw_tmp = MON_WEP(mon)))
752 return;
753 for (obj = mon->minvent; obj; obj = obj->nobj)
754 if (obj == mw_tmp)
755 break;
756 if (!obj) { /* The weapon was stolen or destroyed */
757 MON_NOWEP(mon);
758 mon->weapon_check = NEED_WEAPON;
759 return;
760 }
761 if (!attacktype(mon->data, AT_WEAP)) {
762 setmnotwielded(mon, mw_tmp);
763 mon->weapon_check = NO_WEAPON_WANTED;
764 /* if we're going to call distant_name(), do so before extract_self */
765 if (cansee(mon->mx, mon->my)) {
766 pline_mon(mon, "%s drops %s.", Monnam(mon), distant_name(obj, doname));
767 newsym(mon->mx, mon->my);
768 }
769 obj_extract_self(obj);
770 /* might be dropping object into water or lava */
771 if (!flooreffects(obj, mon->mx, mon->my, "drop")) {
772 if (polyspot)
773 bypass_obj(obj);
774 place_object(obj, mon->mx, mon->my);
775 stackobj(obj);
776 }
777 return;
778 }
779 /* The remaining case where there is a change is where a monster
780 * is polymorphed into a stronger/weaker monster with a different
781 * choice of weapons. This has no parallel for players. It can
782 * be handled by waiting until mon_wield_item is actually called.
783 * Though the monster still wields the wrong weapon until then,
784 * this is OK since the player can't see it. (FIXME: Not okay since
785 * probing can reveal it.)
786 * Note that if there is no change, setting the check to NEED_WEAPON
787 * is harmless.
788 * Possible problem: big monster with big cursed weapon gets
789 * polymorphed into little monster. But it's not quite clear how to
790 * handle this anyway....
791 */
792 if (!(mwelded(mw_tmp) && mon->weapon_check == NO_WEAPON_WANTED))
793 mon->weapon_check = NEED_WEAPON;
794 return;
795}
796
797/* Let a monster try to wield a weapon, based on mon->weapon_check.
798 * Returns 1 if the monster took time to do it, 0 if it did not.

Callers 6

steal_itFunction · 0.85
mhitm_ad_seduFunction · 0.85
new_wereFunction · 0.85
mattackmFunction · 0.85
newchamFunction · 0.85
use_whipFunction · 0.85

Calls 12

attacktypeFunction · 0.85
setmnotwieldedFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
distant_nameFunction · 0.85
newsymFunction · 0.85
obj_extract_selfFunction · 0.85
flooreffectsFunction · 0.85
bypass_objFunction · 0.85
place_objectFunction · 0.85
stackobjFunction · 0.85
mweldedFunction · 0.85

Tested by

no test coverage detected