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. */
| 798 | * Returns 1 if the monster took time to do it, 0 if it did not. |
| 799 | */ |
| 800 | int |
| 801 | mon_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 |
no test coverage detected