Source:NetHack 3.6.1/src/wield.c

From NetHackWiki
(Redirected from Source:Ref/setuqwep)
Jump to: navigation, search

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

Top of file

  1.  /* NetHack 3.6	wield.c	$NHDT-Date: 1496959480 2017/06/08 22:04:40 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.54 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Robert Patrick Rankin, 2009. */
  4.  /* NetHack may be freely redistributed.  See license for details. */

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.

  1.  
  2.  #include "hack.h"
  3.  
  4.  /* KMH -- Differences between the three weapon slots.
  5.   *
  6.   * The main weapon (uwep):
  7.   * 1.  Is filled by the (w)ield command.
  8.   * 2.  Can be filled with any type of item.
  9.   * 3.  May be carried in one or both hands.
  10.   * 4.  Is used as the melee weapon and as the launcher for
  11.   *     ammunition.
  12.   * 5.  Only conveys intrinsics when it is a weapon, weapon-tool,
  13.   *     or artifact.
  14.   * 6.  Certain cursed items will weld to the hand and cannot be
  15.   *     unwielded or dropped.  See erodeable_wep() and will_weld()
  16.   *     below for the list of which items apply.
  17.   *
  18.   * The secondary weapon (uswapwep):
  19.   * 1.  Is filled by the e(x)change command, which swaps this slot
  20.   *     with the main weapon.  If the "pushweapon" option is set,
  21.   *     the (w)ield command will also store the old weapon in the
  22.   *     secondary slot.
  23.   * 2.  Can be filled with anything that will fit in the main weapon
  24.   *     slot; that is, any type of item.
  25.   * 3.  Is usually NOT considered to be carried in the hands.
  26.   *     That would force too many checks among the main weapon,
  27.   *     second weapon, shield, gloves, and rings; and it would
  28.   *     further be complicated by bimanual weapons.  A special
  29.   *     exception is made for two-weapon combat.
  30.   * 4.  Is used as the second weapon for two-weapon combat, and as
  31.   *     a convenience to swap with the main weapon.
  32.   * 5.  Never conveys intrinsics.
  33.   * 6.  Cursed items never weld (see #3 for reasons), but they also
  34.   *     prevent two-weapon combat.
  35.   *
  36.   * The quiver (uquiver):
  37.   * 1.  Is filled by the (Q)uiver command.
  38.   * 2.  Can be filled with any type of item.
  39.   * 3.  Is considered to be carried in a special part of the pack.
  40.   * 4.  Is used as the item to throw with the (f)ire command.
  41.   *     This is a convenience over the normal (t)hrow command.
  42.   * 5.  Never conveys intrinsics.
  43.   * 6.  Cursed items never weld; their effect is handled by the normal
  44.   *     throwing code.
  45.   * 7.  The autoquiver option will fill it with something deemed
  46.   *     suitable if (f)ire is used when it's empty.
  47.   *
  48.   * No item may be in more than one of these slots.
  49.   */
  50.  
  51.  STATIC_DCL boolean FDECL(cant_wield_corpse, (struct obj *));
  52.  STATIC_DCL int FDECL(ready_weapon, (struct obj *));
  53.  
  54.  /* used by will_weld() */
  55.  /* probably should be renamed */
  56.  #define erodeable_wep(optr)                             \
  57.      ((optr)->oclass == WEAPON_CLASS || is_weptool(optr) \
  58.       || (optr)->otyp == HEAVY_IRON_BALL || (optr)->otyp == IRON_CHAIN)
  59.  
  60.  /* used by welded(), and also while wielding */
  61.  #define will_weld(optr) \
  62.      ((optr)->cursed && (erodeable_wep(optr) || (optr)->otyp == TIN_OPENER))
  63.  
  64.  /*** Functions that place a given item in a slot ***/
  65.  /* Proper usage includes:
  66.   * 1.  Initializing the slot during character generation or a
  67.   *     restore.
  68.   * 2.  Setting the slot due to a player's actions.
  69.   * 3.  If one of the objects in the slot are split off, these
  70.   *     functions can be used to put the remainder back in the slot.
  71.   * 4.  Putting an item that was thrown and returned back into the slot.
  72.   * 5.  Emptying the slot, by passing a null object.  NEVER pass
  73.   *     zeroobj!
  74.   *
  75.   * If the item is being moved from another slot, it is the caller's
  76.   * responsibility to handle that.  It's also the caller's responsibility
  77.   * to print the appropriate messages.
  78.   */

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.      if (uwep == obj
  19.          && ((uwep && uwep->oartifact == ART_OGRESMASHER)
  20.              || (olduwep && olduwep->oartifact == ART_OGRESMASHER)))
  21.          context.botl = 1;
  22.      /* Note: Explicitly wielding a pick-axe will not give a "bashing"
  23.       * message.  Wielding one via 'a'pplying it will.
  24.       * 3.2.2:  Wielding arbitrary objects will give bashing message too.
  25.       */
  26.      if (obj) {
  27.          unweapon = (obj->oclass == WEAPON_CLASS)
  28.                         ? is_launcher(obj) || is_ammo(obj) || is_missile(obj)
  29.                               || (is_pole(obj) && !u.usteed)
  30.                         : !is_weptool(obj) && !is_wet_towel(obj);
  31.      } else
  32.          unweapon = TRUE; /* for "bare hands" message */
  33.      update_inventory();
  34.  }
  35.  

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.               * [That comment is obsolete.  It dates from the days (3.0)
  47.               * when unwielding Firebrand could cause hero to be burned
  48.               * to death in Hell due to loss of fire resistance.
  49.               * "Lifesaved re-wielding or re-wearing" is ancient history.]
  50.               */
  51.              long dummy = wep->owornmask;
  52.  
  53.              wep->owornmask |= W_WEP;
  54.              prinv((char *) 0, wep, 0L);
  55.              wep->owornmask = dummy;
  56.          }
  57.          setuwep(wep);
  58.  
  59.          /* KMH -- Talking artifacts are finally implemented */
  60.          arti_speak(wep);
  61.  
  62.          if (artifact_light(wep) && !wep->lamplit) {
  63.              begin_burn(wep, FALSE);
  64.              if (!Blind)
  65.                  pline("%s to shine %s!", Tobjnam(wep, "begin"),
  66.                        arti_light_description(wep));
  67.          }
  68.  #if 0
  69.          /* we'll get back to this someday, but it's not balanced yet */
  70.          if (Race_if(PM_ELF) && !wep->oartifact
  71.              && objects[wep->otyp].oc_material == IRON) {
  72.              /* Elves are averse to wielding cold iron */
  73.              You("have an uneasy feeling about wielding cold iron.");
  74.              change_luck(-1);
  75.          }
  76.  #endif
  77.          if (wep->unpaid) {
  78.              struct monst *this_shkp;
  79.  
  80.              if ((this_shkp = shop_keeper(inside_shop(u.ux, u.uy)))
  81.                  != (struct monst *) 0) {
  82.                  pline("%s says \"You be careful with my %s!\"",
  83.                        shkname(this_shkp), xname(wep));
  84.              }
  85.          }
  86.      }
  87.      return res;
  88.  }
  89.  

setuqwep

  1.  void
  2.  setuqwep(obj)
  3.  register struct obj *obj;
  4.  {
  5.      setworn(obj, W_QUIVER);
  6.      update_inventory();
  7.  }
  8.  

setuswapwep

  1.  void
  2.  setuswapwep(obj)
  3.  register struct obj *obj;
  4.  {
  5.      setworn(obj, W_SWAPWEP);
  6.      update_inventory();
  7.  }
  8.  
  9.  /*** Commands to change particular slot(s) ***/
  10.  
  11.  static NEARDATA const char wield_objs[] = {
  12.      ALL_CLASSES, ALLOW_NONE, WEAPON_CLASS, TOOL_CLASS, 0
  13.  };
  14.  static NEARDATA const char ready_objs[] = {
  15.      ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, ALLOW_NONE, WEAPON_CLASS, 0
  16.  };
  17.  static NEARDATA const char bullets[] = { /* (note: different from dothrow.c) */
  18.      ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, ALLOW_NONE,
  19.      GEM_CLASS, WEAPON_CLASS, 0
  20.  };
  21.  

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.      char qbuf[QBUFSZ];
  5.      struct obj *newquiver;
  6.      const char *quivee_types;
  7.      int res;
  8.      boolean finish_splitting = FALSE,
  9.              was_uwep = FALSE, was_twoweap = u.twoweap;
  10.  
  11.      /* Since the quiver isn't in your hands, don't check cantwield(), */
  12.      /* will_weld(), touch_petrifies(), etc. */
  13.      multi = 0;
  14.      /* forget last splitobj() before calling getobj() with ALLOW_COUNT */
  15.      context.objsplit.child_oid = context.objsplit.parent_oid = 0;
  16.  
  17.      /* Prompt for a new quiver: "What do you want to ready?"
  18.         (Include gems/stones as likely candidates if either primary
  19.         or secondary weapon is a sling.) */
  20.      quivee_types = (uslinging()
  21.                      || (uswapwep
  22.                          && objects[uswapwep->otyp].oc_skill == P_SLING))
  23.                     ? bullets
  24.                     : ready_objs;
  25.      newquiver = getobj(quivee_types, "ready");
  26.  
  27.      if (!newquiver) {
  28.          /* Cancelled */
  29.          return 0;
  30.      } else if (newquiver == &zeroobj) { /* no object */
  31.          /* Explicitly nothing */
  32.          if (uquiver) {
  33.              You("now have no ammunition readied.");
  34.              /* skip 'quivering: prinv()' */
  35.              setuqwep((struct obj *) 0);
  36.          } else {
  37.              You("already have no ammunition readied!");
  38.          }
  39.          return 0;
  40.      } else if (newquiver->o_id == context.objsplit.child_oid) {
  41.          /* if newquiver is the result of supplying a count to getobj()
  42.             we don't want to split something already in the quiver;
  43.             for any other item, we need to give it its own inventory slot */
  44.          if (uquiver && uquiver->o_id == context.objsplit.parent_oid) {
  45.              unsplitobj(newquiver);
  46.              goto already_quivered;
  47.          }
  48.          finish_splitting = TRUE;
  49.      } else if (newquiver == uquiver) {
  50.      already_quivered:
  51.          pline("That ammunition is already readied!");
  52.          return 0;
  53.      } else if (newquiver->owornmask & (W_ARMOR | W_ACCESSORY | W_SADDLE)) {
  54.          You("cannot ready that!");
  55.          return 0;
  56.      } else if (newquiver == uwep) {
  57.          int weld_res = !uwep->bknown;
  58.  
  59.          if (welded(uwep)) {
  60.              weldmsg(uwep);
  61.              reset_remarm(); /* same as dowield() */
  62.              return weld_res;
  63.          }
  64.          /* offer to split stack if wielding more than 1 */
  65.          if (uwep->quan > 1L && inv_cnt(FALSE) < 52 && splittable(uwep)) {
  66.              Sprintf(qbuf, "You are wielding %ld %s.  Ready %ld of them?",
  67.                      uwep->quan, simpleonames(uwep), uwep->quan - 1L);
  68.              switch (ynq(qbuf)) {
  69.              case 'q':
  70.                  return 0;
  71.              case 'y':
  72.                  /* leave 1 wielded, split rest off and put into quiver */
  73.                  newquiver = splitobj(uwep, uwep->quan - 1L);
  74.                  finish_splitting = TRUE;
  75.                  goto quivering;
  76.              default:
  77.                  break;
  78.              }
  79.              Strcpy(qbuf, "Ready all of them instead?");
  80.          } else {
  81.              boolean use_plural = (is_plural(uwep) || pair_of(uwep));
  82.  
  83.              Sprintf(qbuf, "You are wielding %s.  Ready %s instead?",
  84.                      !use_plural ? "that" : "those",
  85.                      !use_plural ? "it" : "them");
  86.          }
  87.          /* require confirmation to ready the main weapon */
  88.          if (ynq(qbuf) != 'y') {
  89.              (void) Shk_Your(qbuf, uwep); /* replace qbuf[] contents */
  90.              pline("%s%s %s wielded.", qbuf,
  91.                    simpleonames(uwep), otense(uwep, "remain"));
  92.              return 0;
  93.          }
  94.          /* quivering main weapon, so no longer wielding it */
  95.          setuwep((struct obj *) 0);
  96.          untwoweapon();
  97.          was_uwep = TRUE;
  98.      } else if (newquiver == uswapwep) {
  99.          if (uswapwep->quan > 1L && inv_cnt(FALSE) < 52
  100.              && splittable(uswapwep)) {
  101.              Sprintf(qbuf, "%s %ld %s.  Ready %ld of them?",
  102.                      u.twoweap ? "You are dual wielding"
  103.                                : "Your alternate weapon is",
  104.                      uswapwep->quan, simpleonames(uswapwep),
  105.                      uswapwep->quan - 1L);
  106.              switch (ynq(qbuf)) {
  107.              case 'q':
  108.                  return 0;
  109.              case 'y':
  110.                  /* leave 1 alt-wielded, split rest off and put into quiver */
  111.                  newquiver = splitobj(uswapwep, uswapwep->quan - 1L);
  112.                  finish_splitting = TRUE;
  113.                  goto quivering;
  114.              default:
  115.                  break;
  116.              }
  117.              Strcpy(qbuf, "Ready all of them instead?");
  118.          } else {
  119.              boolean use_plural = (is_plural(uswapwep) || pair_of(uswapwep));
  120.  
  121.              Sprintf(qbuf, "%s your %s weapon.  Ready %s instead?",
  122.                      !use_plural ? "That is" : "Those are",
  123.                      u.twoweap ? "second" : "alternate",
  124.                      !use_plural ? "it" : "them");
  125.          }
  126.          /* require confirmation to ready the alternate weapon */
  127.          if (ynq(qbuf) != 'y') {
  128.              (void) Shk_Your(qbuf, uswapwep); /* replace qbuf[] contents */
  129.              pline("%s%s %s %s.", qbuf,
  130.                    simpleonames(uswapwep), otense(uswapwep, "remain"),
  131.                    u.twoweap ? "wielded" : "as secondary weapon");
  132.              return 0;
  133.          }
  134.          /* quivering alternate weapon, so no more uswapwep */
  135.          setuswapwep((struct obj *) 0);
  136.          untwoweapon();
  137.      }
  138.  
  139.   quivering:
  140.      if (finish_splitting) {
  141.          freeinv(newquiver);
  142.          newquiver->nomerge = 1;
  143.          addinv(newquiver);
  144.          newquiver->nomerge = 0;
  145.      }
  146.      /* place item in quiver before printing so that inventory feedback
  147.         includes "(at the ready)" */
  148.      setuqwep(newquiver);
  149.      prinv((char *) 0, newquiver, 0L);
  150.  
  151.      /* quiver is a convenience slot and manipulating it ordinarily
  152.         consumes no time, but unwielding primary or secondary weapon
  153.         should take time (perhaps we're adjacent to a rust monster
  154.         or disenchanter and want to hit it immediately, but not with
  155.         something we're wielding that's vulnerable to its damage) */
  156.      res = 0;
  157.      if (was_uwep) {
  158.          You("are now empty %s.", body_part(HANDED));
  159.          res = 1;
  160.      } else if (was_twoweap && !u.twoweap) {
  161.          You("are no longer wielding two weapons at once.");
  162.          res = 1;
  163.      }
  164.      return res;
  165.  }
  166.  

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.  
  23.  /*** Functions to empty a given slot ***/
  24.  /* These should be used only when the item can't be put back in
  25.   * the slot by life saving.  Proper usage includes:
  26.   * 1.  The item has been eaten, stolen, burned away, or rotted away.
  27.   * 2.  Making an item disappear for a bones pile.
  28.   */

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

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*/