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

Function wield_tool

src/wield.c:682–758  ·  view source on GitHub ↗

used for #rub and for applying pick-axe, whip, grappling hook or polearm */

Source from the content-addressed store, hash-verified

680
681/* used for #rub and for applying pick-axe, whip, grappling hook or polearm */
682boolean
683wield_tool(struct obj *obj,
684 const char *verb) /* "rub",&c */
685{
686 const char *what;
687 boolean more_than_1;
688
689 if (uwep && obj == uwep)
690 return TRUE; /* nothing to do if already wielding it */
691
692 if (!verb)
693 verb = "wield";
694 what = xname(obj);
695 more_than_1 = (obj->quan > 1L || strstri(what, "pair of ") != 0
696 || strstri(what, "s of ") != 0);
697
698 if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) {
699 You_cant("%s %s while wearing %s.", verb, yname(obj),
700 more_than_1 ? "them" : "it");
701 return FALSE;
702 }
703 if (uwep && welded(uwep)) {
704 if (flags.verbose) {
705 const char *hand = body_part(HAND);
706
707 if (bimanual(uwep))
708 hand = makeplural(hand);
709 if (strstri(what, "pair of ") != 0)
710 more_than_1 = FALSE;
711 pline(
712 "Since your weapon is welded to your %s, you cannot %s %s %s.",
713 hand, verb, more_than_1 ? "those" : "that", xname(obj));
714 } else {
715 You_cant("do that.");
716 }
717 return FALSE;
718 }
719 if (cantwield(gy.youmonst.data)) {
720 You_cant("hold %s strongly enough.", more_than_1 ? "them" : "it");
721 return FALSE;
722 }
723 /* check shield */
724 if (uarms && bimanual(obj)) {
725 You("cannot %s a two-handed %s while wearing a shield.", verb,
726 (obj->oclass == WEAPON_CLASS) ? "weapon" : "tool");
727 return FALSE;
728 }
729
730 if (uquiver == obj)
731 setuqwep((struct obj *) 0);
732 if (uswapwep == obj) {
733 (void) doswapweapon();
734 /* doswapweapon might fail */
735 if (uswapwep == obj)
736 return FALSE;
737 } else {
738 struct obj *oldwep = uwep;
739

Callers 6

use_pick_axeFunction · 0.85
use_tin_openerFunction · 0.85
dorubFunction · 0.85
use_whipFunction · 0.85
use_poleFunction · 0.85
use_grappleFunction · 0.85

Calls 15

xnameFunction · 0.85
strstriFunction · 0.85
You_cantFunction · 0.85
ynameFunction · 0.85
weldedFunction · 0.85
body_partFunction · 0.85
makepluralFunction · 0.85
YouFunction · 0.85
setuqwepFunction · 0.85
doswapweaponFunction · 0.85
ready_weaponFunction · 0.85
donameFunction · 0.85

Tested by

no test coverage detected