MCPcopy Create free account
hub / github.com/NetHack/NetHack / mon_wield_item

Function mon_wield_item

src/weapon.c:800–934  ·  view source on GitHub ↗

Let a monster try to wield a weapon, based on mon->weapon_check. * Returns 1 if the monster took time to do it, 0 if it did not. */

Source from the content-addressed store, hash-verified

798 * Returns 1 if the monster took time to do it, 0 if it did not.
799 */
800int
801mon_wield_item(struct monst *mon)
802{
803 struct obj *obj;
804 boolean exclaim = TRUE; /* assume mon is planning to attack */
805
806 /* This case actually should never happen */
807 if (mon->weapon_check == NO_WEAPON_WANTED)
808 return 0;
809 switch (mon->weapon_check) {
810 case NEED_HTH_WEAPON:
811 obj = select_hwep(mon);
812 break;
813 case NEED_RANGED_WEAPON:
814 (void) select_rwep(mon);
815 obj = gp.propellor;
816 break;
817 case NEED_PICK_AXE:
818 obj = m_carrying(mon, PICK_AXE);
819 /* KMH -- allow other picks */
820 if (!obj && !which_armor(mon, W_ARMS))
821 obj = m_carrying(mon, DWARVISH_MATTOCK);
822 exclaim = FALSE; /* mon is just planning to dig */
823 break;
824 case NEED_AXE:
825 /* currently, only 2 types of axe */
826 obj = m_carrying(mon, BATTLE_AXE);
827 if (!obj || which_armor(mon, W_ARMS))
828 obj = m_carrying(mon, AXE);
829 exclaim = FALSE;
830 break;
831 case NEED_PICK_OR_AXE:
832 /* prefer pick for fewer switches on most levels */
833 obj = m_carrying(mon, DWARVISH_MATTOCK);
834 if (!obj)
835 obj = m_carrying(mon, BATTLE_AXE);
836 if (!obj || which_armor(mon, W_ARMS)) {
837 obj = m_carrying(mon, PICK_AXE);
838 if (!obj)
839 obj = m_carrying(mon, AXE);
840 }
841 exclaim = FALSE;
842 break;
843 default:
844 impossible("weapon_check %d for %s?", mon->weapon_check,
845 mon_nam(mon));
846 return 0;
847 }
848 if (obj && obj != &hands_obj) {
849 struct obj *mw_tmp = MON_WEP(mon);
850
851 if (mw_tmp && mw_tmp->otyp == obj->otyp) {
852 /* already wielding it */
853 mon->weapon_check = NEED_WEAPON;
854 return 0;
855 }
856 /* Actually, this isn't necessary--as soon as the monster
857 * wields the weapon, the weapon welds itself, so the monster

Callers 10

mattackmFunction · 0.85
invaultFunction · 0.85
dog_inventFunction · 0.85
make_familiarFunction · 0.85
tamedogFunction · 0.85
dochugFunction · 0.85
m_digweapon_checkFunction · 0.85
thrwmmFunction · 0.85
thrwmuFunction · 0.85
mattackuFunction · 0.85

Calls 15

select_hwepFunction · 0.85
select_rwepFunction · 0.85
m_carryingFunction · 0.85
which_armorFunction · 0.85
mon_namFunction · 0.85
mweldedFunction · 0.85
canseemonFunction · 0.85
mbodypartFunction · 0.85
makepluralFunction · 0.85
otenseFunction · 0.85
s_suffixFunction · 0.85
xnameFunction · 0.85

Tested by

no test coverage detected