Source:NetHack 3.6.0/src/wield.c

From NetHackWiki
(Redirected from Source:Wield.c)
Jump to: navigation, search

Below is the full text to wield.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/wield.c#line123]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

Top of file

  1.  /* NetHack 3.6	wield.c	$NHDT-Date: 1446887539 2015/11/07 09:12:19 $  $NHDT-Branch: master $:$NHDT-Revision: 1.47 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  /* KMH -- Differences between the three weapon slots.
  8.   *
  9.   * The main weapon (uwep):
  10.   * 1.  Is filled by the (w)ield command.
  11.   * 2.  Can be filled with any type of item.
  12.   * 3.  May be carried in one or both hands.
  13.   * 4.  Is used as the melee weapon and as the launcher for
  14.   *     ammunition.
  15.   * 5.  Only conveys intrinsics when it is a weapon, weapon-tool,
  16.   *     or artifact.
  17.   * 6.  Certain cursed items will weld to the hand and cannot be
  18.   *     unwielded or dropped.  See erodeable_wep() and will_weld()
  19.   *     below for the list of which items apply.
  20.   *
  21.   * The secondary weapon (uswapwep):
  22.   * 1.  Is filled by the e(x)change command, which swaps this slot
  23.   *     with the main weapon.  If the "pushweapon" option is set,
  24.   *     the (w)ield command will also store the old weapon in the
  25.   *     secondary slot.
  26.   * 2.  Can be filled with anything that will fit in the main weapon
  27.   *     slot; that is, any type of item.
  28.   * 3.  Is usually NOT considered to be carried in the hands.
  29.   *     That would force too many checks among the main weapon,
  30.   *     second weapon, shield, gloves, and rings; and it would
  31.   *     further be complicated by bimanual weapons.  A special
  32.   *     exception is made for two-weapon combat.
  33.   * 4.  Is used as the second weapon for two-weapon combat, and as
  34.   *     a convenience to swap with the main weapon.
  35.   * 5.  Never conveys intrinsics.
  36.   * 6.  Cursed items never weld (see #3 for reasons), but they also
  37.   *     prevent two-weapon combat.
  38.   *
  39.   * The quiver (uquiver):
  40.   * 1.  Is filled by the (Q)uiver command.
  41.   * 2.  Can be filled with any type of item.
  42.   * 3.  Is considered to be carried in a special part of the pack.
  43.   * 4.  Is used as the item to throw with the (f)ire command.
  44.   *     This is a convenience over the normal (t)hrow command.
  45.   * 5.  Never conveys intrinsics.
  46.   * 6.  Cursed items never weld; their effect is handled by the normal
  47.   *     throwing code.
  48.   * 7.  The autoquiver option will fill it with something deemed
  49.   *     suitable if (f)ire is used when it's empty.
  50.   *
  51.   * No item may be in more than one of these slots.
  52.   */
  53.  
  54.  STATIC_DCL boolean FDECL(cant_wield_corpse, (struct obj *));
  55.  STATIC_DCL int FDECL(ready_weapon, (struct obj *));
  56.  
  57.  /* used by will_weld() */
  58.  /* probably should be renamed */
  59.  #define erodeable_wep(optr)                             \
  60.      ((optr)->oclass == WEAPON_CLASS || is_weptool(optr) \
  61.       || (optr)->otyp == HEAVY_IRON_BALL || (optr)->otyp == IRON_CHAIN)
  62.  
  63.  /* used by welded(), and also while wielding */
  64.  #define will_weld(optr) \
  65.      ((optr)->cursed && (erodeable_wep(optr) || (optr)->otyp == TIN_OPENER))
  66.  

Functions that place a given item in a slot

  1.  /*** Functions that place a given item in a slot ***/
  2.  /* Proper usage includes:
  3.   * 1.  Initializing the slot during character generation or a
  4.   *     restore.
  5.   * 2.  Setting the slot due to a player's actions.
  6.   * 3.  If one of the objects in the slot are split off, these
  7.   *     functions can be used to put the remainder back in the slot.
  8.   * 4.  Putting an item that was thrown and returned back into the slot.
  9.   * 5.  Emptying the slot, by passing a null object.  NEVER pass
  10.   *     zeroobj!
  11.   *
  12.   * If the item is being moved from another slot, it is the caller's
  13.   * responsibility to handle that.  It's also the caller's responsibility
  14.   * to print the appropriate messages.
  15.   */

setuwep

  1.  void
  2.  setuwep(obj)
  3.  register struct obj *obj;
  4.  {
  5.      struct obj *olduwep = uwep;
  6.  
  7.      if (obj == uwep)
  8.          return; /* necessary to not set unweapon */
  9.      /* This message isn't printed in the caller because it happens
  10.       * *whenever* Sunsword is unwielded, from whatever cause.
  11.       */
  12.      setworn(obj, W_WEP);
  13.      if (uwep == obj && artifact_light(olduwep) && olduwep->lamplit) {
  14.          end_burn(olduwep, FALSE);
  15.          if (!Blind)
  16.              pline("%s shining.", Tobjnam(olduwep, "stop"));
  17.      }
  18.      /* Note: Explicitly wielding a pick-axe will not give a "bashing"
  19.       * message.  Wielding one via 'a'pplying it will.
  20.       * 3.2.2:  Wielding arbitrary objects will give bashing message too.
  21.       */
  22.      if (obj) {
  23.          unweapon = (obj->oclass == WEAPON_CLASS)
  24.                         ? is_launcher(obj) || is_ammo(obj) || is_missile(obj)
  25.                               || (is_pole(obj) && !u.usteed)
  26.                         : !is_weptool(obj) && !is_wet_towel(obj);
  27.      } else
  28.          unweapon = TRUE; /* for "bare hands" message */
  29.      update_inventory();
  30.  }
  31.  

cant_wield_corpse

  1.  STATIC_OVL boolean
  2.  cant_wield_corpse(obj)
  3.  struct obj *obj;
  4.  {
  5.      char kbuf[BUFSZ];
  6.  
  7.      if (uarmg || obj->otyp != CORPSE || !touch_petrifies(&mons[obj->corpsenm])
  8.          || Stone_resistance)
  9.          return FALSE;
  10.  
  11.      /* Prevent wielding cockatrice when not wearing gloves --KAA */
  12.      You("wield %s in your bare %s.",
  13.          corpse_xname(obj, (const char *) 0, CXN_PFX_THE),
  14.          makeplural(body_part(HAND)));
  15.      Sprintf(kbuf, "wielding %s bare-handed", killer_xname(obj));
  16.      instapetrify(kbuf);
  17.      return TRUE;
  18.  }
  19.  

ready_weapon

  1.  STATIC_OVL int
  2.  ready_weapon(wep)
  3.  struct obj *wep;
  4.  {
  5.      /* Separated function so swapping works easily */
  6.      int res = 0;
  7.  
  8.      if (!wep) {
  9.          /* No weapon */
  10.          if (uwep) {
  11.              You("are empty %s.", body_part(HANDED));
  12.              setuwep((struct obj *) 0);
  13.              res++;
  14.          } else
  15.              You("are already empty %s.", body_part(HANDED));
  16.      } else if (wep->otyp == CORPSE && cant_wield_corpse(wep)) {
  17.          /* hero must have been life-saved to get here; use a turn */
  18.          res++; /* corpse won't be wielded */
  19.      } else if (uarms && bimanual(wep)) {
  20.          You("cannot wield a two-handed %s while wearing a shield.",
  21.              is_sword(wep) ? "sword" : wep->otyp == BATTLE_AXE ? "axe"
  22.                                                                : "weapon");
  23.      } else if (!retouch_object(&wep, FALSE)) {
  24.          res++; /* takes a turn even though it doesn't get wielded */
  25.      } else {
  26.          /* Weapon WILL be wielded after this point */
  27.          res++;
  28.          if (will_weld(wep)) {
  29.              const char *tmp = xname(wep), *thestr = "The ";
  30.  
  31.              if (strncmp(tmp, thestr, 4) && !strncmp(The(tmp), thestr, 4))
  32.                  tmp = thestr;
  33.              else
  34.                  tmp = "";
  35.              pline("%s%s %s to your %s!", tmp, aobjnam(wep, "weld"),
  36.                    (wep->quan == 1L) ? "itself" : "themselves", /* a3 */
  37.                    bimanual(wep) ? (const char *) makeplural(body_part(HAND))
  38.                                  : body_part(HAND));
  39.              wep->bknown = TRUE;
  40.          } else {
  41.              /* The message must be printed before setuwep (since
  42.               * you might die and be revived from changing weapons),
  43.               * and the message must be before the death message and
  44.               * Lifesaved rewielding.  Yet we want the message to
  45.               * say "weapon in hand", thus this kludge.
  46.               */
  47.              long dummy = wep->owornmask;
  48.  
  49.              wep->owornmask |= W_WEP;
  50.              prinv((char *) 0, wep, 0L);
  51.              wep->owornmask = dummy;
  52.          }
  53.          setuwep(wep);
  54.  
  55.          /* KMH -- Talking artifacts are finally implemented */
  56.          arti_speak(wep);
  57.  
  58.          if (artifact_light(wep) && !wep->lamplit) {
  59.              begin_burn(wep, FALSE);
  60.              if (!Blind)
  61.                  pline("%s to shine %s!", Tobjnam(wep, "begin"),
  62.                        arti_light_description(wep));
  63.          }
  64.  #if 0
  65.          /* we'll get back to this someday, but it's not balanced yet */
  66.          if (Race_if(PM_ELF) && !wep->oartifact
  67.              && objects[wep->otyp].oc_material == IRON) {
  68.              /* Elves are averse to wielding cold iron */
  69.              You("have an uneasy feeling about wielding cold iron.");
  70.              change_luck(-1);
  71.          }
  72.  #endif
  73.          if (wep->unpaid) {
  74.              struct monst *this_shkp;
  75.  
  76.              if ((this_shkp = shop_keeper(inside_shop(u.ux, u.uy)))
  77.                  != (struct monst *) 0) {
  78.                  pline("%s says \"You be careful with my %s!\"",
  79.                        shkname(this_shkp), xname(wep));
  80.              }
  81.          }
  82.      }
  83.      return res;
  84.  }
  85.  

setuqwep

  1.  void
  2.  setuqwep(obj)
  3.  register struct obj *obj;
  4.  {
  5.      setworn(obj, W_QUIVER);
  6.      update_inventory();
  7.  }
  8.  
  9.  void
  10.  setuswapwep(obj)
  11.  register struct obj *obj;
  12.  {
  13.      setworn(obj, W_SWAPWEP);
  14.      update_inventory();
  15.  }
  16.  

Commands to change particular slot(s)

  1.  /*** Commands to change particular slot(s) ***/
  2.  
  3.  static NEARDATA const char wield_objs[] = { ALL_CLASSES, ALLOW_NONE,
  4.                                              WEAPON_CLASS, TOOL_CLASS, 0 };
  5.  static NEARDATA const char ready_objs[] = { COIN_CLASS, ALL_CLASSES,
  6.                                              ALLOW_NONE, WEAPON_CLASS, 0 };
  7.  static NEARDATA const char bullets[] = /* (note: different from dothrow.c) */
  8.      { COIN_CLASS, ALL_CLASSES, ALLOW_NONE, GEM_CLASS, WEAPON_CLASS, 0 };
  9.  

dowield

  1.  int
  2.  dowield()
  3.  {
  4.      register struct obj *wep, *oldwep;
  5.      int result;
  6.  
  7.      /* May we attempt this? */
  8.      multi = 0;
  9.      if (cantwield(youmonst.data)) {
  10.          pline("Don't be ridiculous!");
  11.          return 0;
  12.      }
  13.  
  14.      /* Prompt for a new weapon */
  15.      if (!(wep = getobj(wield_objs, "wield")))
  16.          /* Cancelled */
  17.          return 0;
  18.      else if (wep == uwep) {
  19.          You("are already wielding that!");
  20.          if (is_weptool(wep) || is_wet_towel(wep))
  21.              unweapon = FALSE; /* [see setuwep()] */
  22.          return 0;
  23.      } else if (welded(uwep)) {
  24.          weldmsg(uwep);
  25.          /* previously interrupted armor removal mustn't be resumed */
  26.          reset_remarm();
  27.          return 0;
  28.      }
  29.  
  30.      /* Handle no object, or object in other slot */
  31.      if (wep == &zeroobj)
  32.          wep = (struct obj *) 0;
  33.      else if (wep == uswapwep)
  34.          return doswapweapon();
  35.      else if (wep == uquiver)
  36.          setuqwep((struct obj *) 0);
  37.      else if (wep->owornmask & (W_ARMOR | W_ACCESSORY | W_SADDLE)) {
  38.          You("cannot wield that!");
  39.          return 0;
  40.      }
  41.  
  42.      /* Set your new primary weapon */
  43.      oldwep = uwep;
  44.      result = ready_weapon(wep);
  45.      if (flags.pushweapon && oldwep && uwep != oldwep)
  46.          setuswapwep(oldwep);
  47.      untwoweapon();
  48.  
  49.      return result;
  50.  }
  51.  

doswapweapon

  1.  int
  2.  doswapweapon()
  3.  {
  4.      register struct obj *oldwep, *oldswap;
  5.      int result = 0;
  6.  
  7.      /* May we attempt this? */
  8.      multi = 0;
  9.      if (cantwield(youmonst.data)) {
  10.          pline("Don't be ridiculous!");
  11.          return 0;
  12.      }
  13.      if (welded(uwep)) {
  14.          weldmsg(uwep);
  15.          return 0;
  16.      }
  17.  
  18.      /* Unwield your current secondary weapon */
  19.      oldwep = uwep;
  20.      oldswap = uswapwep;
  21.      setuswapwep((struct obj *) 0);
  22.  
  23.      /* Set your new primary weapon */
  24.      result = ready_weapon(oldswap);
  25.  
  26.      /* Set your new secondary weapon */
  27.      if (uwep == oldwep)
  28.          /* Wield failed for some reason */
  29.          setuswapwep(oldswap);
  30.      else {
  31.          setuswapwep(oldwep);
  32.          if (uswapwep)
  33.              prinv((char *) 0, uswapwep, 0L);
  34.          else
  35.              You("have no secondary weapon readied.");
  36.      }
  37.  
  38.      if (u.twoweap && !can_twoweapon())
  39.          untwoweapon();
  40.  
  41.      return result;
  42.  }
  43.  

dowieldquiver

  1.  int
  2.  dowieldquiver()
  3.  {
  4.      register struct obj *newquiver;
  5.      const char *quivee_types =
  6.          (uslinging()
  7.           || (uswapwep && objects[uswapwep->otyp].oc_skill == P_SLING))
  8.              ? bullets
  9.              : ready_objs;
  10.  
  11.      /* Since the quiver isn't in your hands, don't check cantwield(), */
  12.      /* will_weld(), touch_petrifies(), etc. */
  13.      multi = 0;
  14.  
  15.      /* Prompt for a new quiver */
  16.      if (!(newquiver = getobj(quivee_types, "ready")))
  17.          /* Cancelled */
  18.          return 0;
  19.  
  20.      /* Handle no object, or object in other slot */
  21.      /* Any type is okay, since we give no intrinsics anyways */
  22.      if (newquiver == &zeroobj) {
  23.          /* Explicitly nothing */
  24.          if (uquiver) {
  25.              You("now have no ammunition readied.");
  26.              setuqwep(newquiver = (struct obj *) 0);
  27.          } else {
  28.              You("already have no ammunition readied!");
  29.              return 0;
  30.          }
  31.      } else if (newquiver == uquiver) {
  32.          pline("That ammunition is already readied!");
  33.          return 0;
  34.      } else if (newquiver == uwep) {
  35.          /* Prevent accidentally readying the main weapon */
  36.          pline("%s already being used as a weapon!",
  37.                !is_plural(uwep) ? "That is" : "They are");
  38.          return 0;
  39.      } else if (newquiver->owornmask & (W_ARMOR | W_ACCESSORY | W_SADDLE)) {
  40.          You("cannot ready that!");
  41.          return 0;
  42.      } else {
  43.          long dummy;
  44.  
  45.          /* Check if it's the secondary weapon */
  46.          if (newquiver == uswapwep) {
  47.              setuswapwep((struct obj *) 0);
  48.              untwoweapon();
  49.          }
  50.  
  51.          /* Okay to put in quiver; print it */
  52.          dummy = newquiver->owornmask;
  53.          newquiver->owornmask |= W_QUIVER;
  54.          prinv((char *) 0, newquiver, 0L);
  55.          newquiver->owornmask = dummy;
  56.      }
  57.  
  58.      /* Finally, place it in the quiver */
  59.      setuqwep(newquiver);
  60.      /* Take no time since this is a convenience slot */
  61.      return 0;
  62.  }
  63.  

wield_tool

  1.  /* used for #rub and for applying pick-axe, whip, grappling hook or polearm */
  2.  boolean
  3.  wield_tool(obj, verb)
  4.  struct obj *obj;
  5.  const char *verb; /* "rub",&c */
  6.  {
  7.      const char *what;
  8.      boolean more_than_1;
  9.  
  10.      if (obj == uwep)
  11.          return TRUE; /* nothing to do if already wielding it */
  12.  
  13.      if (!verb)
  14.          verb = "wield";
  15.      what = xname(obj);
  16.      more_than_1 = (obj->quan > 1L || strstri(what, "pair of ") != 0
  17.                     || strstri(what, "s of ") != 0);
  18.  
  19.      if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) {
  20.          You_cant("%s %s while wearing %s.", verb, yname(obj),
  21.                   more_than_1 ? "them" : "it");
  22.          return FALSE;
  23.      }
  24.      if (welded(uwep)) {
  25.          if (flags.verbose) {
  26.              const char *hand = body_part(HAND);
  27.  
  28.              if (bimanual(uwep))
  29.                  hand = makeplural(hand);
  30.              if (strstri(what, "pair of ") != 0)
  31.                  more_than_1 = FALSE;
  32.              pline(
  33.                 "Since your weapon is welded to your %s, you cannot %s %s %s.",
  34.                    hand, verb, more_than_1 ? "those" : "that", xname(obj));
  35.          } else {
  36.              You_cant("do that.");
  37.          }
  38.          return FALSE;
  39.      }
  40.      if (cantwield(youmonst.data)) {
  41.          You_cant("hold %s strongly enough.", more_than_1 ? "them" : "it");
  42.          return FALSE;
  43.      }
  44.      /* check shield */
  45.      if (uarms && bimanual(obj)) {
  46.          You("cannot %s a two-handed %s while wearing a shield.", verb,
  47.              (obj->oclass == WEAPON_CLASS) ? "weapon" : "tool");
  48.          return FALSE;
  49.      }
  50.  
  51.      if (uquiver == obj)
  52.          setuqwep((struct obj *) 0);
  53.      if (uswapwep == obj) {
  54.          (void) doswapweapon();
  55.          /* doswapweapon might fail */
  56.          if (uswapwep == obj)
  57.              return FALSE;
  58.      } else {
  59.          struct obj *oldwep = uwep;
  60.  
  61.          You("now wield %s.", doname(obj));
  62.          setuwep(obj);
  63.          if (flags.pushweapon && oldwep && uwep != oldwep)
  64.              setuswapwep(oldwep);
  65.      }
  66.      if (uwep != obj)
  67.          return FALSE; /* rewielded old object after dying */
  68.      /* applying weapon or tool that gets wielded ends two-weapon combat */
  69.      if (u.twoweap)
  70.          untwoweapon();
  71.      if (obj->oclass != WEAPON_CLASS)
  72.          unweapon = TRUE;
  73.      return TRUE;
  74.  }
  75.  

can_twoweapon

  1.  int
  2.  can_twoweapon()
  3.  {
  4.      struct obj *otmp;
  5.  
  6.  #define NOT_WEAPON(obj) (!is_weptool(obj) && obj->oclass != WEAPON_CLASS)
  7.      if (!could_twoweap(youmonst.data)) {
  8.          if (Upolyd)
  9.              You_cant("use two weapons in your current form.");
  10.          else
  11.              pline("%s aren't able to use two weapons at once.",
  12.                    makeplural((flags.female && urole.name.f) ? urole.name.f
  13.                                                              : urole.name.m));
  14.      } else if (!uwep || !uswapwep)
  15.          Your("%s%s%s empty.", uwep ? "left " : uswapwep ? "right " : "",
  16.               body_part(HAND), (!uwep && !uswapwep) ? "s are" : " is");
  17.      else if (NOT_WEAPON(uwep) || NOT_WEAPON(uswapwep)) {
  18.          otmp = NOT_WEAPON(uwep) ? uwep : uswapwep;
  19.          pline("%s %s.", Yname2(otmp),
  20.                is_plural(otmp) ? "aren't weapons" : "isn't a weapon");
  21.      } else if (bimanual(uwep) || bimanual(uswapwep)) {
  22.          otmp = bimanual(uwep) ? uwep : uswapwep;
  23.          pline("%s isn't one-handed.", Yname2(otmp));
  24.      } else if (uarms)
  25.          You_cant("use two weapons while wearing a shield.");
  26.      else if (uswapwep->oartifact)
  27.          pline("%s being held second to another weapon!",
  28.                Yobjnam2(uswapwep, "resist"));
  29.      else if (uswapwep->otyp == CORPSE && cant_wield_corpse(uswapwep)) {
  30.          /* [Note: NOT_WEAPON() check prevents ever getting here...] */
  31.          ; /* must be life-saved to reach here; return FALSE */
  32.      } else if (Glib || uswapwep->cursed) {
  33.          if (!Glib)
  34.              uswapwep->bknown = TRUE;
  35.          drop_uswapwep();
  36.      } else
  37.          return TRUE;
  38.      return FALSE;
  39.  }
  40.  

drop_uswapwep

  1.  void
  2.  drop_uswapwep()
  3.  {
  4.      char str[BUFSZ];
  5.      struct obj *obj = uswapwep;
  6.  
  7.      /* Avoid trashing makeplural's static buffer */
  8.      Strcpy(str, makeplural(body_part(HAND)));
  9.      pline("%s from your %s!", Yobjnam2(obj, "slip"), str);
  10.      dropx(obj);
  11.  }
  12.  

dotwoweapon

  1.  int
  2.  dotwoweapon()
  3.  {
  4.      /* You can always toggle it off */
  5.      if (u.twoweap) {
  6.          You("switch to your primary weapon.");
  7.          u.twoweap = 0;
  8.          update_inventory();
  9.          return 0;
  10.      }
  11.  
  12.      /* May we use two weapons? */
  13.      if (can_twoweapon()) {
  14.          /* Success! */
  15.          You("begin two-weapon combat.");
  16.          u.twoweap = 1;
  17.          update_inventory();
  18.          return (rnd(20) > ACURR(A_DEX));
  19.      }
  20.      return 0;
  21.  }
  22.  

Functions to empty a given slot

  1.  /*** Functions to empty a given slot ***/
  2.  /* These should be used only when the item can't be put back in
  3.   * the slot by life saving.  Proper usage includes:
  4.   * 1.  The item has been eaten, stolen, burned away, or rotted away.
  5.   * 2.  Making an item disappear for a bones pile.
  6.   */

uwepgone

  1.  void
  2.  uwepgone()
  3.  {
  4.      if (uwep) {
  5.          if (artifact_light(uwep) && uwep->lamplit) {
  6.              end_burn(uwep, FALSE);
  7.              if (!Blind)
  8.                  pline("%s shining.", Tobjnam(uwep, "stop"));
  9.          }
  10.          setworn((struct obj *) 0, W_WEP);
  11.          unweapon = TRUE;
  12.          update_inventory();
  13.      }
  14.  }
  15.  

uswapwepgone

  1.  void
  2.  uswapwepgone()
  3.  {
  4.      if (uswapwep) {
  5.          setworn((struct obj *) 0, W_SWAPWEP);
  6.          update_inventory();
  7.      }
  8.  }
  9.  

uqwepgone

  1.  void
  2.  uqwepgone()
  3.  {
  4.      if (uquiver) {
  5.          setworn((struct obj *) 0, W_QUIVER);
  6.          update_inventory();
  7.      }
  8.  }
  9.  

untwoweapon

  1.  void
  2.  untwoweapon()
  3.  {
  4.      if (u.twoweap) {
  5.          You("can no longer use two weapons at once.");
  6.          u.twoweap = FALSE;
  7.          update_inventory();
  8.      }
  9.      return;
  10.  }
  11.  

chwepon

  1.  int
  2.  chwepon(otmp, amount)
  3.  register struct obj *otmp;
  4.  register int amount;
  5.  {
  6.      const char *color = hcolor((amount < 0) ? NH_BLACK : NH_BLUE);
  7.      const char *xtime, *wepname = "";
  8.      boolean multiple;
  9.      int otyp = STRANGE_OBJECT;
  10.  
  11.      if (!uwep || (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep))) {
  12.          char buf[BUFSZ];
  13.  
  14.          Sprintf(buf, "Your %s %s.", makeplural(body_part(HAND)),
  15.                  (amount >= 0) ? "twitch" : "itch");
  16.          strange_feeling(otmp, buf);
  17.          exercise(A_DEX, (boolean) (amount >= 0));
  18.          return 0;
  19.      }
  20.  
  21.      if (otmp && otmp->oclass == SCROLL_CLASS)
  22.          otyp = otmp->otyp;
  23.  
  24.      if (uwep->otyp == WORM_TOOTH && amount >= 0) {
  25.          multiple = (uwep->quan > 1L);
  26.          /* order: message, transformation, shop handling */
  27.          Your("%s %s much sharper now.", simpleonames(uwep),
  28.               multiple ? "fuse, and become" : "is");
  29.          uwep->otyp = CRYSKNIFE;
  30.          uwep->oerodeproof = 0;
  31.          if (multiple) {
  32.              uwep->quan = 1L;
  33.              uwep->owt = weight(uwep);
  34.          }
  35.          if (uwep->cursed)
  36.              uncurse(uwep);
  37.          /* update shop bill to reflect new higher value */
  38.          if (uwep->unpaid)
  39.              alter_cost(uwep, 0L);
  40.          if (otyp != STRANGE_OBJECT)
  41.              makeknown(otyp);
  42.          if (multiple)
  43.              encumber_msg();
  44.          return 1;
  45.      } else if (uwep->otyp == CRYSKNIFE && amount < 0) {
  46.          multiple = (uwep->quan > 1L);
  47.          /* order matters: message, shop handling, transformation */
  48.          Your("%s %s much duller now.", simpleonames(uwep),
  49.               multiple ? "fuse, and become" : "is");
  50.          costly_alteration(uwep, COST_DEGRD); /* DECHNT? other? */
  51.          uwep->otyp = WORM_TOOTH;
  52.          uwep->oerodeproof = 0;
  53.          if (multiple) {
  54.              uwep->quan = 1L;
  55.              uwep->owt = weight(uwep);
  56.          }
  57.          if (otyp != STRANGE_OBJECT && otmp->bknown)
  58.              makeknown(otyp);
  59.          if (multiple)
  60.              encumber_msg();
  61.          return 1;
  62.      }
  63.  
  64.      if (has_oname(uwep))
  65.          wepname = ONAME(uwep);
  66.      if (amount < 0 && uwep->oartifact && restrict_name(uwep, wepname)) {
  67.          if (!Blind)
  68.              pline("%s %s.", Yobjnam2(uwep, "faintly glow"), color);
  69.          return 1;
  70.      }
  71.      /* there is a (soft) upper and lower limit to uwep->spe */
  72.      if (((uwep->spe > 5 && amount >= 0) || (uwep->spe < -5 && amount < 0))
  73.          && rn2(3)) {
  74.          if (!Blind)
  75.              pline("%s %s for a while and then %s.",
  76.                    Yobjnam2(uwep, "violently glow"), color,
  77.                    otense(uwep, "evaporate"));
  78.          else
  79.              pline("%s.", Yobjnam2(uwep, "evaporate"));
  80.  
  81.          useupall(uwep); /* let all of them disappear */
  82.          return 1;
  83.      }
  84.      if (!Blind) {
  85.          xtime = (amount * amount == 1) ? "moment" : "while";
  86.          pline("%s %s for a %s.",
  87.                Yobjnam2(uwep, amount == 0 ? "violently glow" : "glow"), color,
  88.                xtime);
  89.          if (otyp != STRANGE_OBJECT && uwep->known
  90.              && (amount > 0 || (amount < 0 && otmp->bknown)))
  91.              makeknown(otyp);
  92.      }
  93.      if (amount < 0)
  94.          costly_alteration(uwep, COST_DECHNT);
  95.      uwep->spe += amount;
  96.      if (amount > 0) {
  97.          if (uwep->cursed)
  98.              uncurse(uwep);
  99.          /* update shop bill to reflect new higher price */
  100.          if (uwep->unpaid)
  101.              alter_cost(uwep, 0L);
  102.      }
  103.  
  104.      /*
  105.       * Enchantment, which normally improves a weapon, has an
  106.       * addition adverse reaction on Magicbane whose effects are
  107.       * spe dependent.  Give an obscure clue here.
  108.       */
  109.      if (uwep->oartifact == ART_MAGICBANE && uwep->spe >= 0) {
  110.          Your("right %s %sches!", body_part(HAND),
  111.               (((amount > 1) && (uwep->spe > 1)) ? "flin" : "it"));
  112.      }
  113.  
  114.      /* an elven magic clue, cookie@keebler */
  115.      /* elven weapons vibrate warningly when enchanted beyond a limit */
  116.      if ((uwep->spe > 5)
  117.          && (is_elven_weapon(uwep) || uwep->oartifact || !rn2(7)))
  118.          pline("%s unexpectedly.", Yobjnam2(uwep, "suddenly vibrate"));
  119.  
  120.      return 1;
  121.  }
  122.  

welded

  1.  int
  2.  welded(obj)
  3.  register struct obj *obj;
  4.  {
  5.      if (obj && obj == uwep && will_weld(obj)) {
  6.          obj->bknown = TRUE;
  7.          return 1;
  8.      }
  9.      return 0;
  10.  }
  11.  

weldmsg

  1.  void
  2.  weldmsg(obj)
  3.  register struct obj *obj;
  4.  {
  5.      long savewornmask;
  6.  
  7.      savewornmask = obj->owornmask;
  8.      pline("%s welded to your %s!", Yobjnam2(obj, "are"),
  9.            bimanual(obj) ? (const char *) makeplural(body_part(HAND))
  10.                          : body_part(HAND));
  11.      obj->owornmask = savewornmask;
  12.  }
  13.  

mwelded

  1.  /* test whether monster's wielded weapon is stuck to hand/paw/whatever */
  2.  boolean
  3.  mwelded(obj)
  4.  struct obj *obj;
  5.  {
  6.      /* caller is responsible for making sure this is a monster's item */
  7.      if (obj && (obj->owornmask & W_WEP) && will_weld(obj))
  8.          return TRUE;
  9.      return FALSE;
  10.  }
  11.  
  12.  /*wield.c*/