Source:NetHack 3.6.0/src/do wear.c

From NetHackWiki
(Redirected from Do wear.c)
Jump to: navigation, search

Below is the full text to do_wear.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/do_wear.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	do_wear.c	$NHDT-Date: 1446975698 2015/11/08 09:41:38 $  $NHDT-Branch: master $:$NHDT-Revision: 1.87 $ */
  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.  static NEARDATA const char see_yourself[] = "see yourself";
  8.  static NEARDATA const char unknown_type[] = "Unknown type of %s (%d)";
  9.  static NEARDATA const char c_armor[] = "armor", c_suit[] = "suit",
  10.                             c_shirt[] = "shirt", c_cloak[] = "cloak",
  11.                             c_gloves[] = "gloves", c_boots[] = "boots",
  12.                             c_helmet[] = "helmet", c_shield[] = "shield",
  13.                             c_weapon[] = "weapon", c_sword[] = "sword",
  14.                             c_axe[] = "axe", c_that_[] = "that";
  15.  
  16.  static NEARDATA const long takeoff_order[] = {
  17.      WORN_BLINDF, W_WEP,      WORN_SHIELD, WORN_GLOVES, LEFT_RING,
  18.      RIGHT_RING,  WORN_CLOAK, WORN_HELMET, WORN_AMUL,   WORN_ARMOR,
  19.      WORN_SHIRT,  WORN_BOOTS, W_SWAPWEP,   W_QUIVER,    0L
  20.  };
  21.  
  22.  STATIC_DCL void FDECL(on_msg, (struct obj *));
  23.  STATIC_DCL void FDECL(toggle_stealth, (struct obj *, long, BOOLEAN_P));
  24.  STATIC_DCL void FDECL(toggle_displacement, (struct obj *, long, BOOLEAN_P));
  25.  STATIC_PTR int NDECL(Armor_on);
  26.  STATIC_PTR int NDECL(Boots_on);
  27.  STATIC_PTR int NDECL(Cloak_on);
  28.  STATIC_PTR int NDECL(Helmet_on);
  29.  STATIC_PTR int NDECL(Gloves_on);
  30.  STATIC_DCL void FDECL(wielding_corpse, (struct obj *, BOOLEAN_P));
  31.  STATIC_PTR int NDECL(Shield_on);
  32.  STATIC_PTR int NDECL(Shirt_on);
  33.  STATIC_DCL void NDECL(Amulet_on);
  34.  STATIC_DCL void FDECL(learnring, (struct obj *, BOOLEAN_P));
  35.  STATIC_DCL void FDECL(Ring_off_or_gone, (struct obj *, BOOLEAN_P));
  36.  STATIC_PTR int FDECL(select_off, (struct obj *));
  37.  STATIC_DCL struct obj *NDECL(do_takeoff);
  38.  STATIC_PTR int NDECL(take_off);
  39.  STATIC_DCL int FDECL(menu_remarm, (int));
  40.  STATIC_DCL void FDECL(count_worn_stuff, (struct obj **, BOOLEAN_P));
  41.  STATIC_PTR int FDECL(armor_or_accessory_off, (struct obj *));
  42.  STATIC_PTR int FDECL(accessory_or_armor_on, (struct obj *));
  43.  STATIC_DCL void FDECL(already_wearing, (const char *));
  44.  STATIC_DCL void FDECL(already_wearing2, (const char *, const char *));
  45.  

off_msg

  1.  void
  2.  off_msg(otmp)
  3.  struct obj *otmp;
  4.  {
  5.      if (flags.verbose)
  6.          You("were wearing %s.", doname(otmp));
  7.  }
  8.  

on_msg

  1.  /* for items that involve no delay */
  2.  STATIC_OVL void
  3.  on_msg(otmp)
  4.  struct obj *otmp;
  5.  {
  6.      if (flags.verbose) {
  7.          char how[BUFSZ];
  8.          /* call xname() before obj_is_pname(); formatting obj's name
  9.             might set obj->dknown and that affects the pname test */
  10.          const char *otmp_name = xname(otmp);
  11.  
  12.          how[0] = '\0';
  13.          if (otmp->otyp == TOWEL)
  14.              Sprintf(how, " around your %s", body_part(HEAD));
  15.          You("are now wearing %s%s.",
  16.              obj_is_pname(otmp) ? the(otmp_name) : an(otmp_name), how);
  17.      }
  18.  }
  19.  

toggle_stealth

  1.  /* starting equipment gets auto-worn at beginning of new game,
  2.     and we don't want stealth or displacement feedback then */
  3.  static boolean initial_don = FALSE; /* manipulated in set_wear() */
  4.  
  5.  /* putting on or taking off an item which confers stealth;
  6.     give feedback and discover it iff stealth state is changing */
  7.  STATIC_OVL
  8.  void
  9.  toggle_stealth(obj, oldprop, on)
  10.  struct obj *obj;
  11.  long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */
  12.  boolean on;
  13.  {
  14.      if (on ? initial_don : context.takeoff.cancelled_don)
  15.          return;
  16.  
  17.      if (!oldprop /* extrinsic stealth from something else */
  18.          && !HStealth /* intrinsic stealth */
  19.          && !BStealth) { /* stealth blocked by something */
  20.          if (obj->otyp == RIN_STEALTH)
  21.              learnring(obj, TRUE);
  22.          else
  23.              makeknown(obj->otyp);
  24.  
  25.          if (on) {
  26.              if (!is_boots(obj))
  27.                  You("move very quietly.");
  28.              else if (Levitation || Flying)
  29.                  You("float imperceptibly.");
  30.              else
  31.                  You("walk very quietly.");
  32.          } else {
  33.              You("sure are noisy.");
  34.          }
  35.      }
  36.  }
  37.  

toggle_displacement

  1.  /* putting on or taking off an item which confers displacement;
  2.     give feedback and discover it iff displacement state is changing *and*
  3.     hero is able to see self (or sense monsters) */
  4.  STATIC_OVL
  5.  void
  6.  toggle_displacement(obj, oldprop, on)
  7.  struct obj *obj;
  8.  long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */
  9.  boolean on;
  10.  {
  11.      if (on ? initial_don : context.takeoff.cancelled_don)
  12.          return;
  13.  
  14.      if (!oldprop /* extrinsic displacement from something else */
  15.          && !(u.uprops[DISPLACED].intrinsic) /* (theoretical) */
  16.          && !(u.uprops[DISPLACED].blocked) /* (also theoretical) */
  17.          /* we don't use canseeself() here because it augments vision
  18.             with touch, which isn't appropriate for deciding whether
  19.             we'll notice that monsters have trouble spotting the hero */
  20.          && ((!Blind         /* see anything */
  21.               && !u.uswallow /* see surroundings */
  22.               && !Invisible) /* see self */
  23.              /* actively sensing nearby monsters via telepathy or extended
  24.                 monster detection overrides vision considerations because
  25.                 hero also senses self in this situation */
  26.              || (Unblind_telepat
  27.                  || (Blind_telepat && Blind)
  28.                  || Detect_monsters))) {
  29.          makeknown(obj->otyp);
  30.  
  31.          You_feel("that monsters%s have difficulty pinpointing your location.",
  32.                   on ? "" : " no longer");
  33.      }
  34.  }
  35.  

Boots_on

  1.  /*
  2.   * The Type_on() functions should be called *after* setworn().
  3.   * The Type_off() functions call setworn() themselves.
  4.   * [Blindf_on() is an exception and calls setworn() itself.]
  5.   */
  6.  
  7.  STATIC_PTR
  8.  int
  9.  Boots_on(VOID_ARGS)
  10.  {
  11.      long oldprop =
  12.          u.uprops[objects[uarmf->otyp].oc_oprop].extrinsic & ~WORN_BOOTS;
  13.  
  14.      switch (uarmf->otyp) {
  15.      case LOW_BOOTS:
  16.      case IRON_SHOES:
  17.      case HIGH_BOOTS:
  18.      case JUMPING_BOOTS:
  19.      case KICKING_BOOTS:
  20.          break;
  21.      case WATER_WALKING_BOOTS:
  22.          if (u.uinwater)
  23.              spoteffects(TRUE);
  24.          /* (we don't need a lava check here since boots can't be
  25.             put on while feet are stuck) */
  26.          break;
  27.      case SPEED_BOOTS:
  28.          /* Speed boots are still better than intrinsic speed, */
  29.          /* though not better than potion speed */
  30.          if (!oldprop && !(HFast & TIMEOUT)) {
  31.              makeknown(uarmf->otyp);
  32.              You_feel("yourself speed up%s.",
  33.                       (oldprop || HFast) ? " a bit more" : "");
  34.          }
  35.          break;
  36.      case ELVEN_BOOTS:
  37.          toggle_stealth(uarmf, oldprop, TRUE);
  38.          break;
  39.      case FUMBLE_BOOTS:
  40.          if (!oldprop && !(HFumbling & ~TIMEOUT))
  41.              incr_itimeout(&HFumbling, rnd(20));
  42.          break;
  43.      case LEVITATION_BOOTS:
  44.          if (!oldprop && !HLevitation && !BLevitation) {
  45.              makeknown(uarmf->otyp);
  46.              float_up();
  47.              spoteffects(FALSE);
  48.          } else {
  49.              float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
  50.          }
  51.          break;
  52.      default:
  53.          impossible(unknown_type, c_boots, uarmf->otyp);
  54.      }
  55.      return 0;
  56.  }
  57.  

Boots_off

  1.  int
  2.  Boots_off(VOID_ARGS)
  3.  {
  4.      struct obj *otmp = uarmf;
  5.      int otyp = otmp->otyp;
  6.      long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_BOOTS;
  7.  
  8.      context.takeoff.mask &= ~W_ARMF;
  9.      /* For levitation, float_down() returns if Levitation, so we
  10.       * must do a setworn() _before_ the levitation case.
  11.       */
  12.      setworn((struct obj *) 0, W_ARMF);
  13.      switch (otyp) {
  14.      case SPEED_BOOTS:
  15.          if (!Very_fast && !context.takeoff.cancelled_don) {
  16.              makeknown(otyp);
  17.              You_feel("yourself slow down%s.", Fast ? " a bit" : "");
  18.          }
  19.          break;
  20.      case WATER_WALKING_BOOTS:
  21.          /* check for lava since fireproofed boots make it viable */
  22.          if ((is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy))
  23.              && !Levitation && !Flying && !is_clinger(youmonst.data)
  24.              && !context.takeoff.cancelled_don
  25.              /* avoid recursive call to lava_effects() */
  26.              && !iflags.in_lava_effects) {
  27.              /* make boots known in case you survive the drowning */
  28.              makeknown(otyp);
  29.              spoteffects(TRUE);
  30.          }
  31.          break;
  32.      case ELVEN_BOOTS:
  33.          toggle_stealth(otmp, oldprop, FALSE);
  34.          break;
  35.      case FUMBLE_BOOTS:
  36.          if (!oldprop && !(HFumbling & ~TIMEOUT))
  37.              HFumbling = EFumbling = 0;
  38.          break;
  39.      case LEVITATION_BOOTS:
  40.          if (!oldprop && !HLevitation && !BLevitation
  41.              && !context.takeoff.cancelled_don) {
  42.              (void) float_down(0L, 0L);
  43.              makeknown(otyp);
  44.          } else {
  45.              float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
  46.          }
  47.          break;
  48.      case LOW_BOOTS:
  49.      case IRON_SHOES:
  50.      case HIGH_BOOTS:
  51.      case JUMPING_BOOTS:
  52.      case KICKING_BOOTS:
  53.          break;
  54.      default:
  55.          impossible(unknown_type, c_boots, otyp);
  56.      }
  57.      context.takeoff.cancelled_don = FALSE;
  58.      return 0;
  59.  }
  60.  

Cloak_on

  1.  STATIC_PTR int
  2.  Cloak_on(VOID_ARGS)
  3.  {
  4.      long oldprop =
  5.          u.uprops[objects[uarmc->otyp].oc_oprop].extrinsic & ~WORN_CLOAK;
  6.  
  7.      switch (uarmc->otyp) {
  8.      case ORCISH_CLOAK:
  9.      case DWARVISH_CLOAK:
  10.      case CLOAK_OF_MAGIC_RESISTANCE:
  11.      case ROBE:
  12.      case LEATHER_CLOAK:
  13.          break;
  14.      case CLOAK_OF_PROTECTION:
  15.          makeknown(uarmc->otyp);
  16.          break;
  17.      case ELVEN_CLOAK:
  18.          toggle_stealth(uarmc, oldprop, TRUE);
  19.          break;
  20.      case CLOAK_OF_DISPLACEMENT:
  21.          toggle_displacement(uarmc, oldprop, TRUE);
  22.          break;
  23.      case MUMMY_WRAPPING:
  24.          /* Note: it's already being worn, so we have to cheat here. */
  25.          if ((HInvis || EInvis) && !Blind) {
  26.              newsym(u.ux, u.uy);
  27.              You("can %s!", See_invisible ? "no longer see through yourself"
  28.                                           : see_yourself);
  29.          }
  30.          break;
  31.      case CLOAK_OF_INVISIBILITY:
  32.          /* since cloak of invisibility was worn, we know mummy wrapping
  33.             wasn't, so no need to check `oldprop' against blocked */
  34.          if (!oldprop && !HInvis && !Blind) {
  35.              makeknown(uarmc->otyp);
  36.              newsym(u.ux, u.uy);
  37.              pline("Suddenly you can%s yourself.",
  38.                    See_invisible ? " see through" : "not see");
  39.          }
  40.          break;
  41.      case OILSKIN_CLOAK:
  42.          pline("%s very tightly.", Tobjnam(uarmc, "fit"));
  43.          break;
  44.      /* Alchemy smock gives poison _and_ acid resistance */
  45.      case ALCHEMY_SMOCK:
  46.          EAcid_resistance |= WORN_CLOAK;
  47.          break;
  48.      default:
  49.          impossible(unknown_type, c_cloak, uarmc->otyp);
  50.      }
  51.      return 0;
  52.  }
  53.  

Cloak_off

  1.  int
  2.  Cloak_off(VOID_ARGS)
  3.  {
  4.      struct obj *otmp = uarmc;
  5.      int otyp = otmp->otyp;
  6.      long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_CLOAK;
  7.  
  8.      context.takeoff.mask &= ~W_ARMC;
  9.      /* For mummy wrapping, taking it off first resets `Invisible'. */
  10.      setworn((struct obj *) 0, W_ARMC);
  11.      switch (otyp) {
  12.      case ORCISH_CLOAK:
  13.      case DWARVISH_CLOAK:
  14.      case CLOAK_OF_PROTECTION:
  15.      case CLOAK_OF_MAGIC_RESISTANCE:
  16.      case OILSKIN_CLOAK:
  17.      case ROBE:
  18.      case LEATHER_CLOAK:
  19.          break;
  20.      case ELVEN_CLOAK:
  21.          toggle_stealth(otmp, oldprop, FALSE);
  22.          break;
  23.      case CLOAK_OF_DISPLACEMENT:
  24.          toggle_displacement(otmp, oldprop, FALSE);
  25.          break;
  26.      case MUMMY_WRAPPING:
  27.          if (Invis && !Blind) {
  28.              newsym(u.ux, u.uy);
  29.              You("can %s.", See_invisible ? "see through yourself"
  30.                                           : "no longer see yourself");
  31.          }
  32.          break;
  33.      case CLOAK_OF_INVISIBILITY:
  34.          if (!oldprop && !HInvis && !Blind) {
  35.              makeknown(CLOAK_OF_INVISIBILITY);
  36.              newsym(u.ux, u.uy);
  37.              pline("Suddenly you can %s.",
  38.                    See_invisible ? "no longer see through yourself"
  39.                                  : see_yourself);
  40.          }
  41.          break;
  42.      /* Alchemy smock gives poison _and_ acid resistance */
  43.      case ALCHEMY_SMOCK:
  44.          EAcid_resistance &= ~WORN_CLOAK;
  45.          break;
  46.      default:
  47.          impossible(unknown_type, c_cloak, otyp);
  48.      }
  49.      return 0;
  50.  }
  51.  

Helmet_on

  1.  STATIC_PTR
  2.  int
  3.  Helmet_on(VOID_ARGS)
  4.  {
  5.      switch (uarmh->otyp) {
  6.      case FEDORA:
  7.      case HELMET:
  8.      case DENTED_POT:
  9.      case ELVEN_LEATHER_HELM:
  10.      case DWARVISH_IRON_HELM:
  11.      case ORCISH_HELM:
  12.      case HELM_OF_TELEPATHY:
  13.          break;
  14.      case HELM_OF_BRILLIANCE:
  15.          adj_abon(uarmh, uarmh->spe);
  16.          break;
  17.      case CORNUTHAUM:
  18.          /* people think marked wizards know what they're talking
  19.           * about, but it takes trained arrogance to pull it off,
  20.           * and the actual enchantment of the hat is irrelevant.
  21.           */
  22.          ABON(A_CHA) += (Role_if(PM_WIZARD) ? 1 : -1);
  23.          context.botl = 1;
  24.          makeknown(uarmh->otyp);
  25.          break;
  26.      case HELM_OF_OPPOSITE_ALIGNMENT:
  27.          /* changing alignment can toggle off active artifact
  28.             properties, including levitation; uarmh could get
  29.             dropped or destroyed here */
  30.          uchangealign((u.ualign.type != A_NEUTRAL)
  31.                           ? -u.ualign.type
  32.                           : (uarmh->o_id % 2) ? A_CHAOTIC : A_LAWFUL,
  33.                       1);
  34.      /* makeknown(uarmh->otyp);   -- moved below, after xname() */
  35.      /*FALLTHRU*/
  36.      case DUNCE_CAP:
  37.          if (uarmh && !uarmh->cursed) {
  38.              if (Blind)
  39.                  pline("%s for a moment.", Tobjnam(uarmh, "vibrate"));
  40.              else
  41.                  pline("%s %s for a moment.", Tobjnam(uarmh, "glow"),
  42.                        hcolor(NH_BLACK));
  43.              curse(uarmh);
  44.          }
  45.          context.botl = 1; /* reveal new alignment or INT & WIS */
  46.          if (Hallucination) {
  47.              pline("My brain hurts!"); /* Monty Python's Flying Circus */
  48.          } else if (uarmh && uarmh->otyp == DUNCE_CAP) {
  49.              You_feel("%s.", /* track INT change; ignore WIS */
  50.                       ACURR(A_INT)
  51.                               <= (ABASE(A_INT) + ABON(A_INT) + ATEMP(A_INT))
  52.                           ? "like sitting in a corner"
  53.                           : "giddy");
  54.          } else {
  55.              /* [message moved to uchangealign()] */
  56.              makeknown(HELM_OF_OPPOSITE_ALIGNMENT);
  57.          }
  58.          break;
  59.      default:
  60.          impossible(unknown_type, c_helmet, uarmh->otyp);
  61.      }
  62.      return 0;
  63.  }
  64.  

Helmet_off

  1.  int
  2.  Helmet_off(VOID_ARGS)
  3.  {
  4.      context.takeoff.mask &= ~W_ARMH;
  5.  
  6.      switch (uarmh->otyp) {
  7.      case FEDORA:
  8.      case HELMET:
  9.      case DENTED_POT:
  10.      case ELVEN_LEATHER_HELM:
  11.      case DWARVISH_IRON_HELM:
  12.      case ORCISH_HELM:
  13.          break;
  14.      case DUNCE_CAP:
  15.          context.botl = 1;
  16.          break;
  17.      case CORNUTHAUM:
  18.          if (!context.takeoff.cancelled_don) {
  19.              ABON(A_CHA) += (Role_if(PM_WIZARD) ? -1 : 1);
  20.              context.botl = 1;
  21.          }
  22.          break;
  23.      case HELM_OF_TELEPATHY:
  24.          /* need to update ability before calling see_monsters() */
  25.          setworn((struct obj *) 0, W_ARMH);
  26.          see_monsters();
  27.          return 0;
  28.      case HELM_OF_BRILLIANCE:
  29.          if (!context.takeoff.cancelled_don)
  30.              adj_abon(uarmh, -uarmh->spe);
  31.          break;
  32.      case HELM_OF_OPPOSITE_ALIGNMENT:
  33.          /* changing alignment can toggle off active artifact
  34.             properties, including levitation; uarmh could get
  35.             dropped or destroyed here */
  36.          uchangealign(u.ualignbase[A_CURRENT], 2);
  37.          break;
  38.      default:
  39.          impossible(unknown_type, c_helmet, uarmh->otyp);
  40.      }
  41.      setworn((struct obj *) 0, W_ARMH);
  42.      context.takeoff.cancelled_don = FALSE;
  43.      return 0;
  44.  }
  45.  

Gloves_on

  1.  STATIC_PTR
  2.  int
  3.  Gloves_on(VOID_ARGS)
  4.  {
  5.      long oldprop =
  6.          u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES;
  7.  
  8.      switch (uarmg->otyp) {
  9.      case LEATHER_GLOVES:
  10.          break;
  11.      case GAUNTLETS_OF_FUMBLING:
  12.          if (!oldprop && !(HFumbling & ~TIMEOUT))
  13.              incr_itimeout(&HFumbling, rnd(20));
  14.          break;
  15.      case GAUNTLETS_OF_POWER:
  16.          makeknown(uarmg->otyp);
  17.          context.botl = 1; /* taken care of in attrib.c */
  18.          break;
  19.      case GAUNTLETS_OF_DEXTERITY:
  20.          adj_abon(uarmg, uarmg->spe);
  21.          break;
  22.      default:
  23.          impossible(unknown_type, c_gloves, uarmg->otyp);
  24.      }
  25.      return 0;
  26.  }
  27.  

wielding_corpse

  1.  STATIC_OVL void
  2.  wielding_corpse(obj, voluntary)
  3.  struct obj *obj;
  4.  boolean voluntary; /* taking gloves off on purpose? */
  5.  {
  6.      char kbuf[BUFSZ];
  7.  
  8.      if (!obj || obj->otyp != CORPSE)
  9.          return;
  10.      if (obj != uwep && (obj != uswapwep || !u.twoweap))
  11.          return;
  12.  
  13.      if (touch_petrifies(&mons[obj->corpsenm]) && !Stone_resistance) {
  14.          You("now wield %s in your bare %s.",
  15.              corpse_xname(obj, (const char *) 0, CXN_ARTICLE),
  16.              makeplural(body_part(HAND)));
  17.          Sprintf(kbuf, "%s gloves while wielding %s",
  18.                  voluntary ? "removing" : "losing", killer_xname(obj));
  19.          instapetrify(kbuf);
  20.          /* life-saved; can't continue wielding cockatrice corpse though */
  21.          remove_worn_item(obj, FALSE);
  22.      }
  23.  }
  24.  

Gloves_off

  1.  int
  2.  Gloves_off(VOID_ARGS)
  3.  {
  4.      long oldprop =
  5.          u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES;
  6.      boolean on_purpose = !context.mon_moving && !uarmg->in_use;
  7.  
  8.      context.takeoff.mask &= ~W_ARMG;
  9.  
  10.      switch (uarmg->otyp) {
  11.      case LEATHER_GLOVES:
  12.          break;
  13.      case GAUNTLETS_OF_FUMBLING:
  14.          if (!oldprop && !(HFumbling & ~TIMEOUT))
  15.              HFumbling = EFumbling = 0;
  16.          break;
  17.      case GAUNTLETS_OF_POWER:
  18.          makeknown(uarmg->otyp);
  19.          context.botl = 1; /* taken care of in attrib.c */
  20.          break;
  21.      case GAUNTLETS_OF_DEXTERITY:
  22.          if (!context.takeoff.cancelled_don)
  23.              adj_abon(uarmg, -uarmg->spe);
  24.          break;
  25.      default:
  26.          impossible(unknown_type, c_gloves, uarmg->otyp);
  27.      }
  28.      setworn((struct obj *) 0, W_ARMG);
  29.      context.takeoff.cancelled_don = FALSE;
  30.      (void) encumber_msg(); /* immediate feedback for GoP */
  31.  
  32.      /* prevent wielding cockatrice when not wearing gloves */
  33.      if (uwep && uwep->otyp == CORPSE)
  34.          wielding_corpse(uwep, on_purpose);
  35.  
  36.      /* KMH -- ...or your secondary weapon when you're wielding it
  37.         [This case can't actually happen; twoweapon mode won't
  38.         engage if a corpse has been set up as the alternate weapon.] */
  39.      if (u.twoweap && uswapwep && uswapwep->otyp == CORPSE)
  40.          wielding_corpse(uswapwep, on_purpose);
  41.  
  42.      return 0;
  43.  }
  44.  

Shield_on

  1.  STATIC_PTR int
  2.  Shield_on(VOID_ARGS)
  3.  {
  4.      /* no shield currently requires special handling when put on, but we
  5.         keep this uncommented in case somebody adds a new one which does */
  6.      switch (uarms->otyp) {
  7.      case SMALL_SHIELD:
  8.      case ELVEN_SHIELD:
  9.      case URUK_HAI_SHIELD:
  10.      case ORCISH_SHIELD:
  11.      case DWARVISH_ROUNDSHIELD:
  12.      case LARGE_SHIELD:
  13.      case SHIELD_OF_REFLECTION:
  14.          break;
  15.      default:
  16.          impossible(unknown_type, c_shield, uarms->otyp);
  17.      }
  18.  
  19.      return 0;
  20.  }
  21.  

Shield_off

  1.  int
  2.  Shield_off(VOID_ARGS)
  3.  {
  4.      context.takeoff.mask &= ~W_ARMS;
  5.  
  6.      /* no shield currently requires special handling when taken off, but we
  7.         keep this uncommented in case somebody adds a new one which does */
  8.      switch (uarms->otyp) {
  9.      case SMALL_SHIELD:
  10.      case ELVEN_SHIELD:
  11.      case URUK_HAI_SHIELD:
  12.      case ORCISH_SHIELD:
  13.      case DWARVISH_ROUNDSHIELD:
  14.      case LARGE_SHIELD:
  15.      case SHIELD_OF_REFLECTION:
  16.          break;
  17.      default:
  18.          impossible(unknown_type, c_shield, uarms->otyp);
  19.      }
  20.  
  21.      setworn((struct obj *) 0, W_ARMS);
  22.      return 0;
  23.  }
  24.  

Shirt_on

  1.  STATIC_PTR int
  2.  Shirt_on(VOID_ARGS)
  3.  {
  4.      /* no shirt currently requires special handling when put on, but we
  5.         keep this uncommented in case somebody adds a new one which does */
  6.      switch (uarmu->otyp) {
  7.      case HAWAIIAN_SHIRT:
  8.      case T_SHIRT:
  9.          break;
  10.      default:
  11.          impossible(unknown_type, c_shirt, uarmu->otyp);
  12.      }
  13.  
  14.      return 0;
  15.  }
  16.  

Shirt_off

  1.  int
  2.  Shirt_off(VOID_ARGS)
  3.  {
  4.      context.takeoff.mask &= ~W_ARMU;
  5.  
  6.      /* no shirt currently requires special handling when taken off, but we
  7.         keep this uncommented in case somebody adds a new one which does */
  8.      switch (uarmu->otyp) {
  9.      case HAWAIIAN_SHIRT:
  10.      case T_SHIRT:
  11.          break;
  12.      default:
  13.          impossible(unknown_type, c_shirt, uarmu->otyp);
  14.      }
  15.  
  16.      setworn((struct obj *) 0, W_ARMU);
  17.      return 0;
  18.  }
  19.  

Armor_on

  1.  /* This must be done in worn.c, because one of the possible intrinsics
  2.   * conferred is fire resistance, and we have to immediately set
  3.   * HFire_resistance in worn.c since worn.c will check it before returning.
  4.   */
  5.  STATIC_PTR
  6.  int
  7.  Armor_on(VOID_ARGS)
  8.  {
  9.      return 0;
  10.  }
  11.  

Armor_off

  1.  int
  2.  Armor_off(VOID_ARGS)
  3.  {
  4.      context.takeoff.mask &= ~W_ARM;
  5.      setworn((struct obj *) 0, W_ARM);
  6.      context.takeoff.cancelled_don = FALSE;
  7.      return 0;
  8.  }
  9.  

Armor_gone

  1.  /* The gone functions differ from the off functions in that if you die from
  2.   * taking it off and have life saving, you still die.
  3.   */
  4.  int
  5.  Armor_gone()
  6.  {
  7.      context.takeoff.mask &= ~W_ARM;
  8.      setnotworn(uarm);
  9.      context.takeoff.cancelled_don = FALSE;
  10.      return 0;
  11.  }
  12.  

Amulet_on

  1.  STATIC_OVL void
  2.  Amulet_on()
  3.  {
  4.      /* make sure amulet isn't wielded; can't use remove_worn_item()
  5.         here because it has already been set worn in amulet slot */
  6.      if (uamul == uwep)
  7.          setuwep((struct obj *) 0);
  8.      else if (uamul == uswapwep)
  9.          setuswapwep((struct obj *) 0);
  10.      else if (uamul == uquiver)
  11.          setuqwep((struct obj *) 0);
  12.  
  13.      switch (uamul->otyp) {
  14.      case AMULET_OF_ESP:
  15.      case AMULET_OF_LIFE_SAVING:
  16.      case AMULET_VERSUS_POISON:
  17.      case AMULET_OF_REFLECTION:
  18.      case AMULET_OF_MAGICAL_BREATHING:
  19.      case FAKE_AMULET_OF_YENDOR:
  20.          break;
  21.      case AMULET_OF_UNCHANGING:
  22.          if (Slimed)
  23.              make_slimed(0L, (char *) 0);
  24.          break;
  25.      case AMULET_OF_CHANGE: {
  26.          int orig_sex = poly_gender();
  27.  
  28.          if (Unchanging)
  29.              break;
  30.          change_sex();
  31.          /* Don't use same message as polymorph */
  32.          if (orig_sex != poly_gender()) {
  33.              makeknown(AMULET_OF_CHANGE);
  34.              You("are suddenly very %s!",
  35.                  flags.female ? "feminine" : "masculine");
  36.              context.botl = 1;
  37.          } else
  38.              /* already polymorphed into single-gender monster; only
  39.                 changed the character's base sex */
  40.              You("don't feel like yourself.");
  41.          pline_The("amulet disintegrates!");
  42.          if (orig_sex == poly_gender() && uamul->dknown
  43.              && !objects[AMULET_OF_CHANGE].oc_name_known
  44.              && !objects[AMULET_OF_CHANGE].oc_uname)
  45.              docall(uamul);
  46.          useup(uamul);
  47.          break;
  48.      }
  49.      case AMULET_OF_STRANGULATION:
  50.          if (can_be_strangled(&youmonst)) {
  51.              makeknown(AMULET_OF_STRANGULATION);
  52.              pline("It constricts your throat!");
  53.              Strangled = 6L;
  54.          }
  55.          break;
  56.      case AMULET_OF_RESTFUL_SLEEP: {
  57.          long newnap = (long) rnd(100), oldnap = (HSleepy & TIMEOUT);
  58.  
  59.          /* avoid clobbering FROMOUTSIDE bit, which might have
  60.             gotten set by previously eating one of these amulets */
  61.          if (newnap < oldnap || oldnap == 0L)
  62.              HSleepy = (HSleepy & ~TIMEOUT) | newnap;
  63.      } break;
  64.      case AMULET_OF_YENDOR:
  65.          break;
  66.      }
  67.  }
  68.  

Amulet_off

  1.  void
  2.  Amulet_off()
  3.  {
  4.      context.takeoff.mask &= ~W_AMUL;
  5.  
  6.      switch (uamul->otyp) {
  7.      case AMULET_OF_ESP:
  8.          /* need to update ability before calling see_monsters() */
  9.          setworn((struct obj *) 0, W_AMUL);
  10.          see_monsters();
  11.          return;
  12.      case AMULET_OF_LIFE_SAVING:
  13.      case AMULET_VERSUS_POISON:
  14.      case AMULET_OF_REFLECTION:
  15.      case AMULET_OF_CHANGE:
  16.      case AMULET_OF_UNCHANGING:
  17.      case FAKE_AMULET_OF_YENDOR:
  18.          break;
  19.      case AMULET_OF_MAGICAL_BREATHING:
  20.          if (Underwater) {
  21.              /* HMagical_breathing must be set off
  22.                  before calling drown() */
  23.              setworn((struct obj *) 0, W_AMUL);
  24.              if (!breathless(youmonst.data) && !amphibious(youmonst.data)
  25.                  && !Swimming) {
  26.                  You("suddenly inhale an unhealthy amount of water!");
  27.                  (void) drown();
  28.              }
  29.              return;
  30.          }
  31.          break;
  32.      case AMULET_OF_STRANGULATION:
  33.          if (Strangled) {
  34.              if (Breathless)
  35.                  Your("%s is no longer constricted!", body_part(NECK));
  36.              else
  37.                  You("can breathe more easily!");
  38.              Strangled = 0L;
  39.          }
  40.          break;
  41.      case AMULET_OF_RESTFUL_SLEEP:
  42.          setworn((struct obj *) 0, W_AMUL);
  43.          /* HSleepy = 0L; -- avoid clobbering FROMOUTSIDE bit */
  44.          if (!ESleepy && !(HSleepy & ~TIMEOUT))
  45.              HSleepy &= ~TIMEOUT; /* clear timeout bits */
  46.          return;
  47.      case AMULET_OF_YENDOR:
  48.          break;
  49.      }
  50.      setworn((struct obj *) 0, W_AMUL);
  51.      return;
  52.  }
  53.  

learnring

  1.  /* handle ring discovery; comparable to learnwand() */
  2.  STATIC_OVL void
  3.  learnring(ring, observed)
  4.  struct obj *ring;
  5.  boolean observed;
  6.  {
  7.      int ringtype = ring->otyp;
  8.  
  9.      /* if effect was observeable then we usually discover the type */
  10.      if (observed) {
  11.          /* if we already know the ring type which accomplishes this
  12.             effect (assumes there is at most one type for each effect),
  13.             mark this ring as having been seen (no need for makeknown);
  14.             otherwise if we have seen this ring, discover its type */
  15.          if (objects[ringtype].oc_name_known)
  16.              ring->dknown = 1;
  17.          else if (ring->dknown)
  18.              makeknown(ringtype);
  19.  #if 0 /* see learnwand() */
  20.          else
  21.              ring->eknown = 1;
  22.  #endif
  23.      }
  24.  
  25.      /* make enchantment of charged ring known (might be +0) and update
  26.         perm invent window if we've seen this ring and know its type */
  27.      if (ring->dknown && objects[ringtype].oc_name_known) {
  28.          if (objects[ringtype].oc_charged)
  29.              ring->known = 1;
  30.          update_inventory();
  31.      }
  32.  }
  33.  

Ring_on

  1.  void
  2.  Ring_on(obj)
  3.  register struct obj *obj;
  4.  {
  5.      long oldprop = u.uprops[objects[obj->otyp].oc_oprop].extrinsic;
  6.      int old_attrib, which;
  7.      boolean observable;
  8.  
  9.      /* make sure ring isn't wielded; can't use remove_worn_item()
  10.         here because it has already been set worn in a ring slot */
  11.      if (obj == uwep)
  12.          setuwep((struct obj *) 0);
  13.      else if (obj == uswapwep)
  14.          setuswapwep((struct obj *) 0);
  15.      else if (obj == uquiver)
  16.          setuqwep((struct obj *) 0);
  17.  
  18.      /* only mask out W_RING when we don't have both
  19.         left and right rings of the same type */
  20.      if ((oldprop & W_RING) != W_RING)
  21.          oldprop &= ~W_RING;
  22.  
  23.      switch (obj->otyp) {
  24.      case RIN_TELEPORTATION:
  25.      case RIN_REGENERATION:
  26.      case RIN_SEARCHING:
  27.      case RIN_HUNGER:
  28.      case RIN_AGGRAVATE_MONSTER:
  29.      case RIN_POISON_RESISTANCE:
  30.      case RIN_FIRE_RESISTANCE:
  31.      case RIN_COLD_RESISTANCE:
  32.      case RIN_SHOCK_RESISTANCE:
  33.      case RIN_CONFLICT:
  34.      case RIN_TELEPORT_CONTROL:
  35.      case RIN_POLYMORPH:
  36.      case RIN_POLYMORPH_CONTROL:
  37.      case RIN_FREE_ACTION:
  38.      case RIN_SLOW_DIGESTION:
  39.      case RIN_SUSTAIN_ABILITY:
  40.      case MEAT_RING:
  41.          break;
  42.      case RIN_STEALTH:
  43.          toggle_stealth(obj, oldprop, TRUE);
  44.          break;
  45.      case RIN_WARNING:
  46.          see_monsters();
  47.          break;
  48.      case RIN_SEE_INVISIBLE:
  49.          /* can now see invisible monsters */
  50.          set_mimic_blocking(); /* do special mimic handling */
  51.          see_monsters();
  52.  
  53.          if (Invis && !oldprop && !HSee_invisible && !Blind) {
  54.              newsym(u.ux, u.uy);
  55.              pline("Suddenly you are transparent, but there!");
  56.              learnring(obj, TRUE);
  57.          }
  58.          break;
  59.      case RIN_INVISIBILITY:
  60.          if (!oldprop && !HInvis && !BInvis && !Blind) {
  61.              learnring(obj, TRUE);
  62.              newsym(u.ux, u.uy);
  63.              self_invis_message();
  64.          }
  65.          break;
  66.      case RIN_LEVITATION:
  67.          if (!oldprop && !HLevitation && !BLevitation) {
  68.              float_up();
  69.              learnring(obj, TRUE);
  70.              spoteffects(FALSE); /* for sinks */
  71.          } else {
  72.              float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
  73.          }
  74.          break;
  75.      case RIN_GAIN_STRENGTH:
  76.          which = A_STR;
  77.          goto adjust_attrib;
  78.      case RIN_GAIN_CONSTITUTION:
  79.          which = A_CON;
  80.          goto adjust_attrib;
  81.      case RIN_ADORNMENT:
  82.          which = A_CHA;
  83.      adjust_attrib:
  84.          old_attrib = ACURR(which);
  85.          ABON(which) += obj->spe;
  86.          observable = (old_attrib != ACURR(which));
  87.          /* if didn't change, usually means ring is +0 but might
  88.             be because nonzero couldn't go below min or above max;
  89.             learn +0 enchantment if attribute value is not stuck
  90.             at a limit [and ring has been seen and its type is
  91.             already discovered, both handled by learnring()] */
  92.          if (observable || !extremeattr(which))
  93.              learnring(obj, observable);
  94.          context.botl = 1;
  95.          break;
  96.      case RIN_INCREASE_ACCURACY: /* KMH */
  97.          u.uhitinc += obj->spe;
  98.          break;
  99.      case RIN_INCREASE_DAMAGE:
  100.          u.udaminc += obj->spe;
  101.          break;
  102.      case RIN_PROTECTION_FROM_SHAPE_CHAN:
  103.          rescham();
  104.          break;
  105.      case RIN_PROTECTION:
  106.          /* usually learn enchantment and discover type;
  107.             won't happen if ring is unseen or if it's +0
  108.             and the type hasn't been discovered yet */
  109.          observable = (obj->spe != 0);
  110.          learnring(obj, observable);
  111.          if (obj->spe)
  112.              find_ac(); /* updates botl */
  113.          break;
  114.      }
  115.  }
  116.  

Ring_off_or_gone

  1.  STATIC_OVL void
  2.  Ring_off_or_gone(obj, gone)
  3.  register struct obj *obj;
  4.  boolean gone;
  5.  {
  6.      long mask = (obj->owornmask & W_RING);
  7.      int old_attrib, which;
  8.      boolean observable;
  9.  
  10.      context.takeoff.mask &= ~mask;
  11.      if (!(u.uprops[objects[obj->otyp].oc_oprop].extrinsic & mask))
  12.          impossible("Strange... I didn't know you had that ring.");
  13.      if (gone)
  14.          setnotworn(obj);
  15.      else
  16.          setworn((struct obj *) 0, obj->owornmask);
  17.  
  18.      switch (obj->otyp) {
  19.      case RIN_TELEPORTATION:
  20.      case RIN_REGENERATION:
  21.      case RIN_SEARCHING:
  22.      case RIN_HUNGER:
  23.      case RIN_AGGRAVATE_MONSTER:
  24.      case RIN_POISON_RESISTANCE:
  25.      case RIN_FIRE_RESISTANCE:
  26.      case RIN_COLD_RESISTANCE:
  27.      case RIN_SHOCK_RESISTANCE:
  28.      case RIN_CONFLICT:
  29.      case RIN_TELEPORT_CONTROL:
  30.      case RIN_POLYMORPH:
  31.      case RIN_POLYMORPH_CONTROL:
  32.      case RIN_FREE_ACTION:
  33.      case RIN_SLOW_DIGESTION:
  34.      case RIN_SUSTAIN_ABILITY:
  35.      case MEAT_RING:
  36.          break;
  37.      case RIN_STEALTH:
  38.          toggle_stealth(obj, (EStealth & ~mask), FALSE);
  39.          break;
  40.      case RIN_WARNING:
  41.          see_monsters();
  42.          break;
  43.      case RIN_SEE_INVISIBLE:
  44.          /* Make invisible monsters go away */
  45.          if (!See_invisible) {
  46.              set_mimic_blocking(); /* do special mimic handling */
  47.              see_monsters();
  48.          }
  49.  
  50.          if (Invisible && !Blind) {
  51.              newsym(u.ux, u.uy);
  52.              pline("Suddenly you cannot see yourself.");
  53.              learnring(obj, TRUE);
  54.          }
  55.          break;
  56.      case RIN_INVISIBILITY:
  57.          if (!Invis && !BInvis && !Blind) {
  58.              newsym(u.ux, u.uy);
  59.              Your("body seems to unfade%s.",
  60.                   See_invisible ? " completely" : "..");
  61.              learnring(obj, TRUE);
  62.          }
  63.          break;
  64.      case RIN_LEVITATION:
  65.          if (!BLevitation) {
  66.              (void) float_down(0L, 0L);
  67.              if (!Levitation)
  68.                  learnring(obj, TRUE);
  69.          } else {
  70.              float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
  71.          }
  72.          break;
  73.      case RIN_GAIN_STRENGTH:
  74.          which = A_STR;
  75.          goto adjust_attrib;
  76.      case RIN_GAIN_CONSTITUTION:
  77.          which = A_CON;
  78.          goto adjust_attrib;
  79.      case RIN_ADORNMENT:
  80.          which = A_CHA;
  81.      adjust_attrib:
  82.          old_attrib = ACURR(which);
  83.          ABON(which) -= obj->spe;
  84.          observable = (old_attrib != ACURR(which));
  85.          /* same criteria as Ring_on() */
  86.          if (observable || !extremeattr(which))
  87.              learnring(obj, observable);
  88.          context.botl = 1;
  89.          break;
  90.      case RIN_INCREASE_ACCURACY: /* KMH */
  91.          u.uhitinc -= obj->spe;
  92.          break;
  93.      case RIN_INCREASE_DAMAGE:
  94.          u.udaminc -= obj->spe;
  95.          break;
  96.      case RIN_PROTECTION:
  97.          /* might have been put on while blind and we can now see
  98.             or perhaps been forgotten due to amnesia */
  99.          observable = (obj->spe != 0);
  100.          learnring(obj, observable);
  101.          if (obj->spe)
  102.              find_ac(); /* updates botl */
  103.          break;
  104.      case RIN_PROTECTION_FROM_SHAPE_CHAN:
  105.          /* If you're no longer protected, let the chameleons
  106.           * change shape again -dgk
  107.           */
  108.          restartcham();
  109.          break;
  110.      }
  111.  }
  112.  

Ring_off

  1.  void
  2.  Ring_off(obj)
  3.  struct obj *obj;
  4.  {
  5.      Ring_off_or_gone(obj, FALSE);
  6.  }
  7.  

Ring_gone

  1.  void
  2.  Ring_gone(obj)
  3.  struct obj *obj;
  4.  {
  5.      Ring_off_or_gone(obj, TRUE);
  6.  }
  7.  

Blindf_on

  1.  void
  2.  Blindf_on(otmp)
  3.  register struct obj *otmp;
  4.  {
  5.      boolean already_blind = Blind, changed = FALSE;
  6.  
  7.      /* blindfold might be wielded; release it for wearing */
  8.      if (otmp->owornmask & W_WEAPON)
  9.          remove_worn_item(otmp, FALSE);
  10.      setworn(otmp, W_TOOL);
  11.      on_msg(otmp);
  12.  
  13.      if (Blind && !already_blind) {
  14.          changed = TRUE;
  15.          if (flags.verbose)
  16.              You_cant("see any more.");
  17.          /* set ball&chain variables before the hero goes blind */
  18.          if (Punished)
  19.              set_bc(0);
  20.      } else if (already_blind && !Blind) {
  21.          changed = TRUE;
  22.          /* "You are now wearing the Eyes of the Overworld." */
  23.          if (u.uroleplay.blind) {
  24.              /* this can only happen by putting on the Eyes of the Overworld;
  25.                 that shouldn't actually produce a permanent cure, but we
  26.                 can't let the "blind from birth" conduct remain intact */
  27.              pline("For the first time in your life, you can see!");
  28.              u.uroleplay.blind = FALSE;
  29.          } else
  30.              You("can see!");
  31.      }
  32.      if (changed) {
  33.          /* blindness has just been toggled */
  34.          if (Blind_telepat || Infravision)
  35.              see_monsters();
  36.          vision_full_recalc = 1; /* recalc vision limits */
  37.          if (!Blind)
  38.              learn_unseen_invent();
  39.          context.botl = 1;
  40.      }
  41.  }
  42.  

Blindf_off

  1.  void
  2.  Blindf_off(otmp)
  3.  register struct obj *otmp;
  4.  {
  5.      boolean was_blind = Blind, changed = FALSE;
  6.  
  7.      if (!otmp) {
  8.          impossible("Blindf_off without otmp");
  9.          return;
  10.      }
  11.      context.takeoff.mask &= ~W_TOOL;
  12.      setworn((struct obj *) 0, otmp->owornmask);
  13.      off_msg(otmp);
  14.  
  15.      if (Blind) {
  16.          if (was_blind) {
  17.              /* "still cannot see" makes no sense when removing lenses
  18.                 since they can't have been the cause of your blindness */
  19.              if (otmp->otyp != LENSES)
  20.                  You("still cannot see.");
  21.          } else {
  22.              changed = TRUE; /* !was_blind */
  23.              /* "You were wearing the Eyes of the Overworld." */
  24.              You_cant("see anything now!");
  25.              /* set ball&chain variables before the hero goes blind */
  26.              if (Punished)
  27.                  set_bc(0);
  28.          }
  29.      } else if (was_blind) {
  30.          if (!gulp_blnd_check()) {
  31.              changed = TRUE; /* !Blind */
  32.              You("can see again.");
  33.          }
  34.      }
  35.      if (changed) {
  36.          /* blindness has just been toggled */
  37.          if (Blind_telepat || Infravision)
  38.              see_monsters();
  39.          vision_full_recalc = 1; /* recalc vision limits */
  40.          if (!Blind)
  41.              learn_unseen_invent();
  42.          context.botl = 1;
  43.      }
  44.  }
  45.  

set_wear

  1.  /* called in moveloop()'s prologue to set side-effects of worn start-up items;
  2.     also used by poly_obj() when a worn item gets transformed */
  3.  void
  4.  set_wear(obj)
  5.  struct obj *obj; /* if null, do all worn items; otherwise just obj itself */
  6.  {
  7.      initial_don = !obj;
  8.  
  9.      if (!obj ? ublindf != 0 : (obj == ublindf))
  10.          (void) Blindf_on(ublindf);
  11.      if (!obj ? uright != 0 : (obj == uright))
  12.          (void) Ring_on(uright);
  13.      if (!obj ? uleft != 0 : (obj == uleft))
  14.          (void) Ring_on(uleft);
  15.      if (!obj ? uamul != 0 : (obj == uamul))
  16.          (void) Amulet_on();
  17.  
  18.      if (!obj ? uarmu != 0 : (obj == uarmu))
  19.          (void) Shirt_on();
  20.      if (!obj ? uarm != 0 : (obj == uarm))
  21.          (void) Armor_on();
  22.      if (!obj ? uarmc != 0 : (obj == uarmc))
  23.          (void) Cloak_on();
  24.      if (!obj ? uarmf != 0 : (obj == uarmf))
  25.          (void) Boots_on();
  26.      if (!obj ? uarmg != 0 : (obj == uarmg))
  27.          (void) Gloves_on();
  28.      if (!obj ? uarmh != 0 : (obj == uarmh))
  29.          (void) Helmet_on();
  30.      if (!obj ? uarms != 0 : (obj == uarms))
  31.          (void) Shield_on();
  32.  
  33.      initial_don = FALSE;
  34.  }
  35.  

donning

  1.  /* check whether the target object is currently being put on (or taken off--
  2.     also checks for doffing) */
  3.  boolean
  4.  donning(otmp)
  5.  struct obj *otmp;
  6.  {
  7.      /* long what = (occupation == take_off) ? context.takeoff.what : 0L; */
  8.      long what = context.takeoff.what; /* if nonzero, occupation is implied */
  9.      boolean result = FALSE;
  10.  
  11.      /* 'W' and 'T' set afternmv, 'A' sets context.takeoff.what */
  12.      if (otmp == uarm)
  13.          result = (afternmv == Armor_on || afternmv == Armor_off
  14.                    || what == WORN_ARMOR);
  15.      else if (otmp == uarmu)
  16.          result = (afternmv == Shirt_on || afternmv == Shirt_off
  17.                    || what == WORN_SHIRT);
  18.      else if (otmp == uarmc)
  19.          result = (afternmv == Cloak_on || afternmv == Cloak_off
  20.                    || what == WORN_CLOAK);
  21.      else if (otmp == uarmf)
  22.          result = (afternmv == Boots_on || afternmv == Boots_off
  23.                    || what == WORN_BOOTS);
  24.      else if (otmp == uarmh)
  25.          result = (afternmv == Helmet_on || afternmv == Helmet_off
  26.                    || what == WORN_HELMET);
  27.      else if (otmp == uarmg)
  28.          result = (afternmv == Gloves_on || afternmv == Gloves_off
  29.                    || what == WORN_GLOVES);
  30.      else if (otmp == uarms)
  31.          result = (afternmv == Shield_on || afternmv == Shield_off
  32.                    || what == WORN_SHIELD);
  33.  
  34.      return result;
  35.  }
  36.  

doffing

  1.  /* check whether the target object is currently being taken off,
  2.     so that stop_donning() and steal() can vary messages */
  3.  boolean
  4.  doffing(otmp)
  5.  struct obj *otmp;
  6.  {
  7.      long what = context.takeoff.what;
  8.      boolean result = FALSE;
  9.  
  10.      /* 'T' (also 'W') sets afternmv, 'A' sets context.takeoff.what */
  11.      if (otmp == uarm)
  12.          result = (afternmv == Armor_off || what == WORN_ARMOR);
  13.      else if (otmp == uarmu)
  14.          result = (afternmv == Shirt_off || what == WORN_SHIRT);
  15.      else if (otmp == uarmc)
  16.          result = (afternmv == Cloak_off || what == WORN_CLOAK);
  17.      else if (otmp == uarmf)
  18.          result = (afternmv == Boots_off || what == WORN_BOOTS);
  19.      else if (otmp == uarmh)
  20.          result = (afternmv == Helmet_off || what == WORN_HELMET);
  21.      else if (otmp == uarmg)
  22.          result = (afternmv == Gloves_off || what == WORN_GLOVES);
  23.      else if (otmp == uarms)
  24.          result = (afternmv == Shield_off || what == WORN_SHIELD);
  25.  
  26.      return result;
  27.  }
  28.  

cancel_don

  1.  void
  2.  cancel_don()
  3.  {
  4.      /* the piece of armor we were donning/doffing has vanished, so stop
  5.       * wasting time on it (and don't dereference it when donning would
  6.       * otherwise finish)
  7.       */
  8.      context.takeoff.cancelled_don =
  9.          (afternmv == Boots_on || afternmv == Helmet_on
  10.           || afternmv == Gloves_on || afternmv == Armor_on);
  11.      afternmv = 0;
  12.      nomovemsg = (char *) 0;
  13.      multi = 0;
  14.      context.takeoff.delay = 0;
  15.      context.takeoff.what = 0L;
  16.  }
  17.  

stop_donning

  1.  /* called by steal() during theft from hero; interrupt donning/doffing */
  2.  int
  3.  stop_donning(stolenobj)
  4.  struct obj *stolenobj; /* no message if stolenobj is already being doffing */
  5.  {
  6.      char buf[BUFSZ];
  7.      struct obj *otmp;
  8.      boolean putting_on;
  9.      int result = 0;
  10.  
  11.      for (otmp = invent; otmp; otmp = otmp->nobj)
  12.          if ((otmp->owornmask & W_ARMOR) && donning(otmp))
  13.              break;
  14.      /* at most one item will pass donning() test at any given time */
  15.      if (!otmp)
  16.          return 0;
  17.  
  18.      /* donning() returns True when doffing too; doffing() is more specific */
  19.      putting_on = !doffing(otmp);
  20.      /* cancel_don() looks at afternmv; it also serves as cancel_doff() */
  21.      cancel_don();
  22.      /* don't want <armor>_on() or <armor>_off() being called
  23.         by unmul() since the on or off action isn't completing */
  24.      afternmv = 0;
  25.      if (putting_on || otmp != stolenobj) {
  26.          Sprintf(buf, "You stop %s %s.",
  27.                  putting_on ? "putting on" : "taking off",
  28.                  thesimpleoname(otmp));
  29.      } else {
  30.          buf[0] = '\0';   /* silently stop doffing stolenobj */
  31.          result = -multi; /* remember this before calling unmul() */
  32.      }
  33.      unmul(buf);
  34.      /* while putting on, item becomes worn immediately but side-effects are
  35.         deferred until the delay expires; when interrupted, make it unworn
  36.         (while taking off, item stays worn until the delay expires; when
  37.         interrupted, leave it worn) */
  38.      if (putting_on)
  39.          remove_worn_item(otmp, FALSE);
  40.  
  41.      return result;
  42.  }
  43.  

count_worn_stuff

  1.  /* both 'clothes' and 'accessories' now include both armor and accessories;
  2.     TOOL_CLASS is for eyewear, FOOD_CLASS is for MEAT_RING */
  3.  static NEARDATA const char clothes[] = {
  4.      ARMOR_CLASS, RING_CLASS, AMULET_CLASS, TOOL_CLASS, FOOD_CLASS, 0
  5.  };
  6.  static NEARDATA const char accessories[] = {
  7.      RING_CLASS, AMULET_CLASS, TOOL_CLASS, FOOD_CLASS, ARMOR_CLASS, 0
  8.  };
  9.  STATIC_VAR NEARDATA int Narmorpieces, Naccessories;
  10.  
  11.  /* assign values to Narmorpieces and Naccessories */
  12.  STATIC_OVL void
  13.  count_worn_stuff(which, accessorizing)
  14.  struct obj **which; /* caller wants this when count is 1 */
  15.  boolean accessorizing;
  16.  {
  17.      struct obj *otmp;
  18.  
  19.      Narmorpieces = Naccessories = 0;
  20.  
  21.  #define MOREWORN(x,wtyp) do { if (x) { wtyp++; otmp = x; } } while (0)
  22.      otmp = 0;
  23.      MOREWORN(uarmh, Narmorpieces);
  24.      MOREWORN(uarms, Narmorpieces);
  25.      MOREWORN(uarmg, Narmorpieces);
  26.      MOREWORN(uarmf, Narmorpieces);
  27.      /* for cloak/suit/shirt, we only count the outermost item so that it
  28.         can be taken off without confirmation if final count ends up as 1 */
  29.      if (uarmc)
  30.          MOREWORN(uarmc, Narmorpieces);
  31.      else if (uarm)
  32.          MOREWORN(uarm, Narmorpieces);
  33.      else if (uarmu)
  34.          MOREWORN(uarmu, Narmorpieces);
  35.      if (!accessorizing)
  36.          *which = otmp; /* default item iff Narmorpieces is 1 */
  37.  
  38.      otmp = 0;
  39.      MOREWORN(uleft, Naccessories);
  40.      MOREWORN(uright, Naccessories);
  41.      MOREWORN(uamul, Naccessories);
  42.      MOREWORN(ublindf, Naccessories);
  43.      if (accessorizing)
  44.          *which = otmp; /* default item iff Naccessories is 1 */
  45.  #undef MOREWORN
  46.  }
  47.  

armor_or_accessory_off

  1.  /* take off one piece or armor or one accessory;
  2.     shared by dotakeoff('T') and doremring('R') */
  3.  STATIC_OVL int
  4.  armor_or_accessory_off(obj)
  5.  struct obj *obj;
  6.  {
  7.      if (!(obj->owornmask & (W_ARMOR | W_ACCESSORY))) {
  8.          You("are not wearing that.");
  9.          return 0;
  10.      }
  11.  
  12.      reset_remarm(); /* clear context.takeoff.mask and context.takeoff.what */
  13.      (void) select_off(obj);
  14.      if (!context.takeoff.mask)
  15.          return 0;
  16.      /* none of armoroff()/Ring_/Amulet/Blindf_off() use context.takeoff.mask */
  17.      reset_remarm();
  18.  
  19.      if (obj->owornmask & W_ARMOR) {
  20.          (void) armoroff(obj);
  21.      } else if (obj == uright || obj == uleft) {
  22.          /* Sometimes we want to give the off_msg before removing and
  23.           * sometimes after; for instance, "you were wearing a moonstone
  24.           * ring (on right hand)" is desired but "you were wearing a
  25.           * square amulet (being worn)" is not because of the redundant
  26.           * "being worn".
  27.           */
  28.          off_msg(obj);
  29.          Ring_off(obj);
  30.      } else if (obj == uamul) {
  31.          Amulet_off();
  32.          off_msg(obj);
  33.      } else if (obj == ublindf) {
  34.          Blindf_off(obj); /* does its own off_msg */
  35.      } else {
  36.          impossible("removing strange accessory?");
  37.          if (obj->owornmask)
  38.              remove_worn_item(obj, FALSE);
  39.      }
  40.      return 1;
  41.  }
  42.  

dotakeoff

  1.  /* the 'T' command */
  2.  int
  3.  dotakeoff()
  4.  {
  5.      struct obj *otmp = (struct obj *) 0;
  6.  
  7.      count_worn_stuff(&otmp, FALSE);
  8.      if (!Narmorpieces && !Naccessories) {
  9.          /* assert( GRAY_DRAGON_SCALES > YELLOW_DRAGON_SCALE_MAIL ); */
  10.          if (uskin)
  11.              pline_The("%s merged with your skin!",
  12.                        uskin->otyp >= GRAY_DRAGON_SCALES
  13.                            ? "dragon scales are"
  14.                            : "dragon scale mail is");
  15.          else
  16.              pline("Not wearing any armor or accessories.");
  17.          return 0;
  18.      }
  19.      if (Narmorpieces != 1 || ParanoidRemove)
  20.          otmp = getobj(clothes, "take off");
  21.      if (!otmp)
  22.          return 0;
  23.      if (otmp == uskin
  24.          || ((otmp == uarm) && uarmc)
  25.          || ((otmp == uarmu) && (uarmc || uarm))) {
  26.          char why[BUFSZ], what[BUFSZ];
  27.  
  28.          why[0] = what[0] = '\0';
  29.          if (otmp != uskin) {
  30.              if (uarmc)
  31.                  Strcat(what, cloak_simple_name(uarmc));
  32.              if ((otmp == uarmu) && uarm) {
  33.                  if (uarmc)
  34.                      Strcat(what, " and ");
  35.                  Strcat(what, suit_simple_name(uarm));
  36.              }
  37.              Sprintf(why, " without taking off your %s first", what);
  38.          }
  39.          You_cant("take that off%s.", why);
  40.          return 0;
  41.      }
  42.  
  43.      return armor_or_accessory_off(otmp);
  44.  }
  45.  

doremring

  1.  /* the 'R' command */
  2.  int
  3.  doremring()
  4.  {
  5.      struct obj *otmp = 0;
  6.  
  7.      count_worn_stuff(&otmp, TRUE);
  8.      if (!Naccessories && !Narmorpieces) {
  9.          pline("Not wearing any accessories or armor.");
  10.          return 0;
  11.      }
  12.      if (Naccessories != 1 || ParanoidRemove)
  13.          otmp = getobj(accessories, "remove");
  14.      if (!otmp)
  15.          return 0;
  16.  
  17.      return armor_or_accessory_off(otmp);
  18.  }
  19.  

cursed

  1.  /* Check if something worn is cursed _and_ unremovable. */
  2.  int
  3.  cursed(otmp)
  4.  register struct obj *otmp;
  5.  {
  6.      /* Curses, like chickens, come home to roost. */
  7.      if ((otmp == uwep) ? welded(otmp) : (int) otmp->cursed) {
  8.          boolean use_plural = (is_boots(otmp) || is_gloves(otmp)
  9.                                || otmp->otyp == LENSES || otmp->quan > 1L);
  10.  
  11.          You("can't.  %s cursed.", use_plural ? "They are" : "It is");
  12.          otmp->bknown = TRUE;
  13.          return 1;
  14.      }
  15.      return 0;
  16.  }
  17.  

armoroff

  1.  int
  2.  armoroff(otmp)
  3.  register struct obj *otmp;
  4.  {
  5.      register int delay = -objects[otmp->otyp].oc_delay;
  6.  
  7.      if (cursed(otmp))
  8.          return 0;
  9.      if (delay) {
  10.          nomul(delay);
  11.          multi_reason = "disrobing";
  12.          if (is_helmet(otmp)) {
  13.              /* ick... */
  14.              nomovemsg = !strcmp(helm_simple_name(otmp), "hat")
  15.                              ? "You finish taking off your hat."
  16.                              : "You finish taking off your helmet.";
  17.              afternmv = Helmet_off;
  18.          } else if (is_gloves(otmp)) {
  19.              nomovemsg = "You finish taking off your gloves.";
  20.              afternmv = Gloves_off;
  21.          } else if (is_boots(otmp)) {
  22.              nomovemsg = "You finish taking off your boots.";
  23.              afternmv = Boots_off;
  24.          } else {
  25.              nomovemsg = "You finish taking off your suit.";
  26.              afternmv = Armor_off;
  27.          }
  28.      } else {
  29.          /* Be warned!  We want off_msg after removing the item to
  30.           * avoid "You were wearing ____ (being worn)."  However, an
  31.           * item which grants fire resistance might cause some trouble
  32.           * if removed in Hell and lifesaving puts it back on; in this
  33.           * case the message will be printed at the wrong time (after
  34.           * the messages saying you died and were lifesaved).  Luckily,
  35.           * no cloak, shield, or fast-removable armor grants fire
  36.           * resistance, so we can safely do the off_msg afterwards.
  37.           * Rings do grant fire resistance, but for rings we want the
  38.           * off_msg before removal anyway so there's no problem.  Take
  39.           * care in adding armors granting fire resistance; this code
  40.           * might need modification.
  41.           * 3.2 (actually 3.1 even): that comment is obsolete since
  42.           * fire resistance is not required for Gehennom so setworn()
  43.           * doesn't force the resistance granting item to be re-worn
  44.           * after being lifesaved anymore.
  45.           */
  46.          if (is_cloak(otmp))
  47.              (void) Cloak_off();
  48.          else if (is_shield(otmp))
  49.              (void) Shield_off();
  50.          else
  51.              setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
  52.          off_msg(otmp);
  53.      }
  54.      context.takeoff.mask = context.takeoff.what = 0L;
  55.      return 1;
  56.  }
  57.  

already_wearing

  1.  STATIC_OVL void
  2.  already_wearing(cc)
  3.  const char *cc;
  4.  {
  5.      You("are already wearing %s%c", cc, (cc == c_that_) ? '!' : '.');
  6.  }
  7.  

already_wearing2

  1.  STATIC_OVL void
  2.  already_wearing2(cc1, cc2)
  3.  const char *cc1, *cc2;
  4.  {
  5.      You_cant("wear %s because you're wearing %s there already.", cc1, cc2);
  6.  }
  7.  

canwearobj

  1.  /*
  2.   * canwearobj checks to see whether the player can wear a piece of armor
  3.   *
  4.   * inputs: otmp (the piece of armor)
  5.   *         noisy (if TRUE give error messages, otherwise be quiet about it)
  6.   * output: mask (otmp's armor type)
  7.   */
  8.  int
  9.  canwearobj(otmp, mask, noisy)
  10.  struct obj *otmp;
  11.  long *mask;
  12.  boolean noisy;
  13.  {
  14.      int err = 0;
  15.      const char *which;
  16.  
  17.      which = is_cloak(otmp)
  18.                  ? c_cloak
  19.                  : is_shirt(otmp)
  20.                      ? c_shirt
  21.                      : is_suit(otmp)
  22.                          ? c_suit
  23.                          : 0;
  24.      if (which && cantweararm(youmonst.data)
  25.          /* same exception for cloaks as used in m_dowear() */
  26.          && (which != c_cloak || youmonst.data->msize != MZ_SMALL)
  27.          && (racial_exception(&youmonst, otmp) < 1)) {
  28.          if (noisy)
  29.              pline_The("%s will not fit on your body.", which);
  30.          return 0;
  31.      } else if (otmp->owornmask & W_ARMOR) {
  32.          if (noisy)
  33.              already_wearing(c_that_);
  34.          return 0;
  35.      }
  36.  
  37.      if (welded(uwep) && bimanual(uwep) && (is_suit(otmp) || is_shirt(otmp))) {
  38.          if (noisy)
  39.              You("cannot do that while holding your %s.",
  40.                  is_sword(uwep) ? c_sword : c_weapon);
  41.          return 0;
  42.      }
  43.  
  44.      if (is_helmet(otmp)) {
  45.          if (uarmh) {
  46.              if (noisy)
  47.                  already_wearing(an(helm_simple_name(uarmh)));
  48.              err++;
  49.          } else if (Upolyd && has_horns(youmonst.data) && !is_flimsy(otmp)) {
  50.              /* (flimsy exception matches polyself handling) */
  51.              if (noisy)
  52.                  pline_The("%s won't fit over your horn%s.",
  53.                            helm_simple_name(otmp),
  54.                            plur(num_horns(youmonst.data)));
  55.              err++;
  56.          } else
  57.              *mask = W_ARMH;
  58.      } else if (is_shield(otmp)) {
  59.          if (uarms) {
  60.              if (noisy)
  61.                  already_wearing(an(c_shield));
  62.              err++;
  63.          } else if (uwep && bimanual(uwep)) {
  64.              if (noisy)
  65.                  You("cannot wear a shield while wielding a two-handed %s.",
  66.                      is_sword(uwep) ? c_sword : (uwep->otyp == BATTLE_AXE)
  67.                                                     ? c_axe
  68.                                                     : c_weapon);
  69.              err++;
  70.          } else if (u.twoweap) {
  71.              if (noisy)
  72.                  You("cannot wear a shield while wielding two weapons.");
  73.              err++;
  74.          } else
  75.              *mask = W_ARMS;
  76.      } else if (is_boots(otmp)) {
  77.          if (uarmf) {
  78.              if (noisy)
  79.                  already_wearing(c_boots);
  80.              err++;
  81.          } else if (Upolyd && slithy(youmonst.data)) {
  82.              if (noisy)
  83.                  You("have no feet..."); /* not body_part(FOOT) */
  84.              err++;
  85.          } else if (Upolyd && youmonst.data->mlet == S_CENTAUR) {
  86.              /* break_armor() pushes boots off for centaurs,
  87.                 so don't let dowear() put them back on... */
  88.              if (noisy)
  89.                  pline("You have too many hooves to wear %s.",
  90.                        c_boots); /* makeplural(body_part(FOOT)) yields
  91.                                     "rear hooves" which sounds odd */
  92.              err++;
  93.          } else if (u.utrap
  94.                     && (u.utraptype == TT_BEARTRAP || u.utraptype == TT_INFLOOR
  95.                         || u.utraptype == TT_LAVA
  96.                         || u.utraptype == TT_BURIEDBALL)) {
  97.              if (u.utraptype == TT_BEARTRAP) {
  98.                  if (noisy)
  99.                      Your("%s is trapped!", body_part(FOOT));
  100.              } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) {
  101.                  if (noisy)
  102.                      Your("%s are stuck in the %s!",
  103.                           makeplural(body_part(FOOT)), surface(u.ux, u.uy));
  104.              } else { /*TT_BURIEDBALL*/
  105.                  if (noisy)
  106.                      Your("%s is attached to the buried ball!",
  107.                           body_part(LEG));
  108.              }
  109.              err++;
  110.          } else
  111.              *mask = W_ARMF;
  112.      } else if (is_gloves(otmp)) {
  113.          if (uarmg) {
  114.              if (noisy)
  115.                  already_wearing(c_gloves);
  116.              err++;
  117.          } else if (welded(uwep)) {
  118.              if (noisy)
  119.                  You("cannot wear gloves over your %s.",
  120.                      is_sword(uwep) ? c_sword : c_weapon);
  121.              err++;
  122.          } else
  123.              *mask = W_ARMG;
  124.      } else if (is_shirt(otmp)) {
  125.          if (uarm || uarmc || uarmu) {
  126.              if (uarmu) {
  127.                  if (noisy)
  128.                      already_wearing(an(c_shirt));
  129.              } else {
  130.                  if (noisy)
  131.                      You_cant("wear that over your %s.",
  132.                               (uarm && !uarmc) ? c_armor
  133.                                                : cloak_simple_name(uarmc));
  134.              }
  135.              err++;
  136.          } else
  137.              *mask = W_ARMU;
  138.      } else if (is_cloak(otmp)) {
  139.          if (uarmc) {
  140.              if (noisy)
  141.                  already_wearing(an(cloak_simple_name(uarmc)));
  142.              err++;
  143.          } else
  144.              *mask = W_ARMC;
  145.      } else if (is_suit(otmp)) {
  146.          if (uarmc) {
  147.              if (noisy)
  148.                  You("cannot wear armor over a %s.", cloak_simple_name(uarmc));
  149.              err++;
  150.          } else if (uarm) {
  151.              if (noisy)
  152.                  already_wearing("some armor");
  153.              err++;
  154.          } else
  155.              *mask = W_ARM;
  156.      } else {
  157.          /* getobj can't do this after setting its allow_all flag; that
  158.             happens if you have armor for slots that are covered up or
  159.             extra armor for slots that are filled */
  160.          if (noisy)
  161.              silly_thing("wear", otmp);
  162.          err++;
  163.      }
  164.      /* Unnecessary since now only weapons and special items like pick-axes get
  165.       * welded to your hand, not armor
  166.          if (welded(otmp)) {
  167.              if (!err++) {
  168.                  if (noisy) weldmsg(otmp);
  169.              }
  170.          }
  171.       */
  172.      return !err;
  173.  }
  174.  

accessory_or_armor_on

  1.  STATIC_OVL int
  2.  accessory_or_armor_on(obj)
  3.  struct obj *obj;
  4.  {
  5.      long mask = 0L;
  6.      boolean armor, ring, eyewear;
  7.  
  8.      if (obj->owornmask & (W_ACCESSORY | W_ARMOR)) {
  9.          already_wearing(c_that_);
  10.          return 0;
  11.      }
  12.      armor = (obj->oclass == ARMOR_CLASS);
  13.      ring = (obj->oclass == RING_CLASS || obj->otyp == MEAT_RING);
  14.      eyewear = (obj->otyp == BLINDFOLD || obj->otyp == TOWEL
  15.                 || obj->otyp == LENSES);
  16.      /* checks which are performed prior to actually touching the item */
  17.      if (armor) {
  18.          if (!canwearobj(obj, &mask, TRUE))
  19.              return 0;
  20.  
  21.          if (obj->otyp == HELM_OF_OPPOSITE_ALIGNMENT
  22.              && qstart_level.dnum == u.uz.dnum) { /* in quest */
  23.              if (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL])
  24.                  You("narrowly avoid losing all chance at your goal.");
  25.              else /* converted */
  26.                  You("are suddenly overcome with shame and change your mind.");
  27.              u.ublessed = 0; /* lose your god's protection */
  28.              makeknown(obj->otyp);
  29.              context.botl = 1; /*for AC after zeroing u.ublessed */
  30.              return 1;
  31.          }
  32.      } else {
  33.          /* accessory */
  34.          if (ring) {
  35.              char answer, qbuf[QBUFSZ];
  36.              int res = 0;
  37.  
  38.              if (nolimbs(youmonst.data)) {
  39.                  You("cannot make the ring stick to your body.");
  40.                  return 0;
  41.              }
  42.              if (uleft && uright) {
  43.                  There("are no more %s%s to fill.",
  44.                        humanoid(youmonst.data) ? "ring-" : "",
  45.                        makeplural(body_part(FINGER)));
  46.                  return 0;
  47.              }
  48.              if (uleft) {
  49.                  mask = RIGHT_RING;
  50.              } else if (uright) {
  51.                  mask = LEFT_RING;
  52.              } else {
  53.                  do {
  54.                      Sprintf(qbuf, "Which %s%s, Right or Left?",
  55.                              humanoid(youmonst.data) ? "ring-" : "",
  56.                              body_part(FINGER));
  57.                      answer = yn_function(qbuf, "rl", '\0');
  58.                      switch (answer) {
  59.                      case '\0':
  60.                          return 0;
  61.                      case 'l':
  62.                      case 'L':
  63.                          mask = LEFT_RING;
  64.                          break;
  65.                      case 'r':
  66.                      case 'R':
  67.                          mask = RIGHT_RING;
  68.                          break;
  69.                      }
  70.                  } while (!mask);
  71.              }
  72.              if (uarmg && uarmg->cursed) {
  73.                  res = !uarmg->bknown;
  74.                  uarmg->bknown = 1;
  75.                  You("cannot remove your gloves to put on the ring.");
  76.                  return res; /* uses move iff we learned gloves are cursed */
  77.              }
  78.              if (uwep) {
  79.                  res = !uwep->bknown; /* check this before calling welded() */
  80.                  if ((mask == RIGHT_RING || bimanual(uwep)) && welded(uwep)) {
  81.                      const char *hand = body_part(HAND);
  82.  
  83.                      /* welded will set bknown */
  84.                      if (bimanual(uwep))
  85.                          hand = makeplural(hand);
  86.                      You("cannot free your weapon %s to put on the ring.",
  87.                          hand);
  88.                      return res; /* uses move iff we learned weapon is cursed */
  89.                  }
  90.              }
  91.          } else if (obj->oclass == AMULET_CLASS) {
  92.              if (uamul) {
  93.                  already_wearing("an amulet");
  94.                  return 0;
  95.              }
  96.          } else if (eyewear) {
  97.              if (ublindf) {
  98.                  if (ublindf->otyp == TOWEL)
  99.                      Your("%s is already covered by a towel.",
  100.                           body_part(FACE));
  101.                  else if (ublindf->otyp == BLINDFOLD) {
  102.                      if (obj->otyp == LENSES)
  103.                          already_wearing2("lenses", "a blindfold");
  104.                      else
  105.                          already_wearing("a blindfold");
  106.                  } else if (ublindf->otyp == LENSES) {
  107.                      if (obj->otyp == BLINDFOLD)
  108.                          already_wearing2("a blindfold", "some lenses");
  109.                      else
  110.                          already_wearing("some lenses");
  111.                  } else {
  112.                      already_wearing(something); /* ??? */
  113.                  }
  114.                  return 0;
  115.              }
  116.          } else {
  117.              /* neither armor nor accessory */
  118.              You_cant("wear that!");
  119.              return 0;
  120.          }
  121.      }
  122.  
  123.      if (!retouch_object(&obj, FALSE))
  124.          return 1; /* costs a turn even though it didn't get worn */
  125.  
  126.      if (armor) {
  127.          int delay;
  128.  
  129.          obj->known = 1; /* since AC is shown on the status line */
  130.          /* if the armor is wielded, release it for wearing */
  131.          if (obj->owornmask & W_WEAPON)
  132.              remove_worn_item(obj, FALSE);
  133.          setworn(obj, mask);
  134.          delay = -objects[obj->otyp].oc_delay;
  135.          if (delay) {
  136.              nomul(delay);
  137.              multi_reason = "dressing up";
  138.              if (is_boots(obj))
  139.                  afternmv = Boots_on;
  140.              if (is_helmet(obj))
  141.                  afternmv = Helmet_on;
  142.              if (is_gloves(obj))
  143.                  afternmv = Gloves_on;
  144.              if (obj == uarm)
  145.                  afternmv = Armor_on;
  146.              nomovemsg = "You finish your dressing maneuver.";
  147.          } else {
  148.              if (is_cloak(obj))
  149.                  (void) Cloak_on();
  150.              if (is_shield(obj))
  151.                  (void) Shield_on();
  152.              if (is_shirt(obj))
  153.                  (void) Shirt_on();
  154.              on_msg(obj);
  155.          }
  156.          context.takeoff.mask = context.takeoff.what = 0L;
  157.      } else { /* not armor */
  158.          boolean give_feedback = FALSE;
  159.  
  160.          /* [releasing wielded accessory handled in Xxx_on()] */
  161.          if (ring) {
  162.              setworn(obj, mask);
  163.              Ring_on(obj);
  164.              give_feedback = TRUE;
  165.          } else if (obj->oclass == AMULET_CLASS) {
  166.              setworn(obj, W_AMUL);
  167.              Amulet_on();
  168.              /* no feedback here if amulet of change got used up */
  169.              give_feedback = (uamul != 0);
  170.          } else if (eyewear) {
  171.              /* setworn() handled by Blindf_on() */
  172.              Blindf_on(obj);
  173.              /* message handled by Blindf_on(); leave give_feedback False */
  174.          }
  175.          /* feedback for ring or for amulet other than 'change' */
  176.          if (give_feedback && is_worn(obj))
  177.              prinv((char *) 0, obj, 0L);
  178.      }
  179.      return 1;
  180.  }
  181.  

dowear

  1.  /* the 'W' command */
  2.  int
  3.  dowear()
  4.  {
  5.      struct obj *otmp;
  6.  
  7.      /* cantweararm() checks for suits of armor, not what we want here;
  8.         verysmall() or nohands() checks for shields, gloves, etc... */
  9.      if ((verysmall(youmonst.data) || nohands(youmonst.data))) {
  10.          pline("Don't even bother.");
  11.          return 0;
  12.      }
  13.      if (uarm && uarmu && uarmc && uarmh && uarms && uarmg && uarmf
  14.          && uleft && uright && uamul && ublindf) {
  15.          /* 'W' message doesn't mention accessories */
  16.          You("are already wearing a full complement of armor.");
  17.          return 0;
  18.      }
  19.      otmp = getobj(clothes, "wear");
  20.      return otmp ? accessory_or_armor_on(otmp) : 0;
  21.  }
  22.  

doputon

  1.  /* the 'P' command */
  2.  int
  3.  doputon()
  4.  {
  5.      struct obj *otmp;
  6.  
  7.      if (uleft && uright && uamul && ublindf
  8.          && uarm && uarmu && uarmc && uarmh && uarms && uarmg && uarmf) {
  9.          /* 'P' message doesn't mention armor */
  10.          Your("%s%s are full, and you're already wearing an amulet and %s.",
  11.               humanoid(youmonst.data) ? "ring-" : "",
  12.               makeplural(body_part(FINGER)),
  13.               (ublindf->otyp == LENSES) ? "some lenses" : "a blindfold");
  14.          return 0;
  15.      }
  16.      otmp = getobj(accessories, "put on");
  17.      return otmp ? accessory_or_armor_on(otmp) : 0;
  18.  }
  19.  

find_ac

  1.  /* calculate current armor class */
  2.  void
  3.  find_ac()
  4.  {
  5.      int uac = mons[u.umonnum].ac; /* base armor class for current form */
  6.  
  7.      /* armor class from worn gear */
  8.      if (uarm)
  9.          uac -= ARM_BONUS(uarm);
  10.      if (uarmc)
  11.          uac -= ARM_BONUS(uarmc);
  12.      if (uarmh)
  13.          uac -= ARM_BONUS(uarmh);
  14.      if (uarmf)
  15.          uac -= ARM_BONUS(uarmf);
  16.      if (uarms)
  17.          uac -= ARM_BONUS(uarms);
  18.      if (uarmg)
  19.          uac -= ARM_BONUS(uarmg);
  20.      if (uarmu)
  21.          uac -= ARM_BONUS(uarmu);
  22.      if (uleft && uleft->otyp == RIN_PROTECTION)
  23.          uac -= uleft->spe;
  24.      if (uright && uright->otyp == RIN_PROTECTION)
  25.          uac -= uright->spe;
  26.  
  27.      /* armor class from other sources */
  28.      if (HProtection & INTRINSIC)
  29.          uac -= u.ublessed;
  30.      uac -= u.uspellprot;
  31.  
  32.      /* [The magic binary numbers 127 and -128 should be replaced with the
  33.       * mystic decimal numbers 99 and -99 which require no explanation to
  34.       * the uninitiated and would cap the width of a status line value at
  35.       * one less character.]
  36.       */
  37.      if (uac < -128)
  38.          uac = -128; /* u.uac is an schar */
  39.      else if (uac > 127)
  40.          uac = 127; /* for completeness */
  41.  
  42.      if (uac != u.uac) {
  43.          u.uac = uac;
  44.          context.botl = 1;
  45.      }
  46.  }
  47.  

glibr

  1.  void
  2.  glibr()
  3.  {
  4.      register struct obj *otmp;
  5.      int xfl = 0;
  6.      boolean leftfall, rightfall, wastwoweap = FALSE;
  7.      const char *otherwep = 0, *thiswep, *which, *hand;
  8.  
  9.      leftfall = (uleft && !uleft->cursed
  10.                  && (!uwep || !welded(uwep) || !bimanual(uwep)));
  11.      rightfall = (uright && !uright->cursed && (!welded(uwep)));
  12.      if (!uarmg && (leftfall || rightfall) && !nolimbs(youmonst.data)) {
  13.          /* changed so cursed rings don't fall off, GAN 10/30/86 */
  14.          Your("%s off your %s.",
  15.               (leftfall && rightfall) ? "rings slip" : "ring slips",
  16.               (leftfall && rightfall) ? makeplural(body_part(FINGER))
  17.                                       : body_part(FINGER));
  18.          xfl++;
  19.          if (leftfall) {
  20.              otmp = uleft;
  21.              Ring_off(uleft);
  22.              dropx(otmp);
  23.          }
  24.          if (rightfall) {
  25.              otmp = uright;
  26.              Ring_off(uright);
  27.              dropx(otmp);
  28.          }
  29.      }
  30.  
  31.      otmp = uswapwep;
  32.      if (u.twoweap && otmp) {
  33.          /* secondary weapon doesn't need nearly as much handling as
  34.             primary; when in two-weapon mode, we know it's one-handed
  35.             with something else in the other hand and also that it's
  36.             a weapon or weptool rather than something unusual, plus
  37.             we don't need to compare its type with the primary */
  38.          otherwep = is_sword(otmp) ? c_sword : weapon_descr(otmp);
  39.          if (otmp->quan > 1L)
  40.              otherwep = makeplural(otherwep);
  41.          hand = body_part(HAND);
  42.          which = "left ";
  43.          Your("%s %s%s from your %s%s.", otherwep, xfl ? "also " : "",
  44.               otense(otmp, "slip"), which, hand);
  45.          xfl++;
  46.          wastwoweap = TRUE;
  47.          setuswapwep((struct obj *) 0); /* clears u.twoweap */
  48.          if (canletgo(otmp, ""))
  49.              dropx(otmp);
  50.      }
  51.      otmp = uwep;
  52.      if (otmp && !welded(otmp)) {
  53.          long savequan = otmp->quan;
  54.  
  55.          /* nice wording if both weapons are the same type */
  56.          thiswep = is_sword(otmp) ? c_sword : weapon_descr(otmp);
  57.          if (otherwep && strcmp(thiswep, makesingular(otherwep)))
  58.              otherwep = 0;
  59.          if (otmp->quan > 1L) {
  60.              /* most class names for unconventional wielded items
  61.                 are ok, but if wielding multiple apples or rations
  62.                 we don't want "your foods slip", so force non-corpse
  63.                 food to be singular; skipping makeplural() isn't
  64.                 enough--we need to fool otense() too */
  65.              if (!strcmp(thiswep, "food"))
  66.                  otmp->quan = 1L;
  67.              else
  68.                  thiswep = makeplural(thiswep);
  69.          }
  70.          hand = body_part(HAND);
  71.          which = "";
  72.          if (bimanual(otmp))
  73.              hand = makeplural(hand);
  74.          else if (wastwoweap)
  75.              which = "right "; /* preceding msg was about left */
  76.          pline("%s %s%s %s%s from your %s%s.",
  77.                !strncmp(thiswep, "corpse", 6) ? "The" : "Your",
  78.                otherwep ? "other " : "", thiswep, xfl ? "also " : "",
  79.                otense(otmp, "slip"), which, hand);
  80.          /* xfl++; */
  81.          otmp->quan = savequan;
  82.          setuwep((struct obj *) 0);
  83.          if (canletgo(otmp, ""))
  84.              dropx(otmp);
  85.      }
  86.  }
  87.  

some_armor

  1.  struct obj *
  2.  some_armor(victim)
  3.  struct monst *victim;
  4.  {
  5.      register struct obj *otmph, *otmp;
  6.  
  7.      otmph = (victim == &youmonst) ? uarmc : which_armor(victim, W_ARMC);
  8.      if (!otmph)
  9.          otmph = (victim == &youmonst) ? uarm : which_armor(victim, W_ARM);
  10.      if (!otmph)
  11.          otmph = (victim == &youmonst) ? uarmu : which_armor(victim, W_ARMU);
  12.  
  13.      otmp = (victim == &youmonst) ? uarmh : which_armor(victim, W_ARMH);
  14.      if (otmp && (!otmph || !rn2(4)))
  15.          otmph = otmp;
  16.      otmp = (victim == &youmonst) ? uarmg : which_armor(victim, W_ARMG);
  17.      if (otmp && (!otmph || !rn2(4)))
  18.          otmph = otmp;
  19.      otmp = (victim == &youmonst) ? uarmf : which_armor(victim, W_ARMF);
  20.      if (otmp && (!otmph || !rn2(4)))
  21.          otmph = otmp;
  22.      otmp = (victim == &youmonst) ? uarms : which_armor(victim, W_ARMS);
  23.      if (otmp && (!otmph || !rn2(4)))
  24.          otmph = otmp;
  25.      return otmph;
  26.  }
  27.  

stuck_ring

  1.  /* used for praying to check and fix levitation trouble */
  2.  struct obj *
  3.  stuck_ring(ring, otyp)
  4.  struct obj *ring;
  5.  int otyp;
  6.  {
  7.      if (ring != uleft && ring != uright) {
  8.          impossible("stuck_ring: neither left nor right?");
  9.          return (struct obj *) 0;
  10.      }
  11.  
  12.      if (ring && ring->otyp == otyp) {
  13.          /* reasons ring can't be removed match those checked by select_off();
  14.             limbless case has extra checks because ordinarily it's temporary */
  15.          if (nolimbs(youmonst.data) && uamul
  16.              && uamul->otyp == AMULET_OF_UNCHANGING && uamul->cursed)
  17.              return uamul;
  18.          if (welded(uwep) && (ring == uright || bimanual(uwep)))
  19.              return uwep;
  20.          if (uarmg && uarmg->cursed)
  21.              return uarmg;
  22.          if (ring->cursed)
  23.              return ring;
  24.      }
  25.      /* either no ring or not right type or nothing prevents its removal */
  26.      return (struct obj *) 0;
  27.  }
  28.  

unchanger

  1.  /* also for praying; find worn item that confers "Unchanging" attribute */
  2.  struct obj *
  3.  unchanger()
  4.  {
  5.      if (uamul && uamul->otyp == AMULET_OF_UNCHANGING)
  6.          return uamul;
  7.      return 0;
  8.  }
  9.  

select_off

  1.  STATIC_PTR
  2.  int
  3.  select_off(otmp)
  4.  register struct obj *otmp;
  5.  {
  6.      struct obj *why;
  7.      char buf[BUFSZ];
  8.  
  9.      if (!otmp)
  10.          return 0;
  11.      *buf = '\0'; /* lint suppression */
  12.  
  13.      /* special ring checks */
  14.      if (otmp == uright || otmp == uleft) {
  15.          if (nolimbs(youmonst.data)) {
  16.              pline_The("ring is stuck.");
  17.              return 0;
  18.          }
  19.          why = 0; /* the item which prevents ring removal */
  20.          if (welded(uwep) && (otmp == uright || bimanual(uwep))) {
  21.              Sprintf(buf, "free a weapon %s", body_part(HAND));
  22.              why = uwep;
  23.          } else if (uarmg && uarmg->cursed) {
  24.              Sprintf(buf, "take off your %s", c_gloves);
  25.              why = uarmg;
  26.          }
  27.          if (why) {
  28.              You("cannot %s to remove the ring.", buf);
  29.              why->bknown = TRUE;
  30.              return 0;
  31.          }
  32.      }
  33.      /* special glove checks */
  34.      if (otmp == uarmg) {
  35.          if (welded(uwep)) {
  36.              You("are unable to take off your %s while wielding that %s.",
  37.                  c_gloves, is_sword(uwep) ? c_sword : c_weapon);
  38.              uwep->bknown = TRUE;
  39.              return 0;
  40.          } else if (Glib) {
  41.              You_cant("take off the slippery %s with your slippery %s.",
  42.                       c_gloves, makeplural(body_part(FINGER)));
  43.              return 0;
  44.          }
  45.      }
  46.      /* special boot checks */
  47.      if (otmp == uarmf) {
  48.          if (u.utrap && u.utraptype == TT_BEARTRAP) {
  49.              pline_The("bear trap prevents you from pulling your %s out.",
  50.                        body_part(FOOT));
  51.              return 0;
  52.          } else if (u.utrap && u.utraptype == TT_INFLOOR) {
  53.              You("are stuck in the %s, and cannot pull your %s out.",
  54.                  surface(u.ux, u.uy), makeplural(body_part(FOOT)));
  55.              return 0;
  56.          }
  57.      }
  58.      /* special suit and shirt checks */
  59.      if (otmp == uarm || otmp == uarmu) {
  60.          why = 0; /* the item which prevents disrobing */
  61.          if (uarmc && uarmc->cursed) {
  62.              Sprintf(buf, "remove your %s", cloak_simple_name(uarmc));
  63.              why = uarmc;
  64.          } else if (otmp == uarmu && uarm && uarm->cursed) {
  65.              Sprintf(buf, "remove your %s", c_suit);
  66.              why = uarm;
  67.          } else if (welded(uwep) && bimanual(uwep)) {
  68.              Sprintf(buf, "release your %s",
  69.                      is_sword(uwep) ? c_sword : (uwep->otyp == BATTLE_AXE)
  70.                                                     ? c_axe
  71.                                                     : c_weapon);
  72.              why = uwep;
  73.          }
  74.          if (why) {
  75.              You("cannot %s to take off %s.", buf, the(xname(otmp)));
  76.              why->bknown = TRUE;
  77.              return 0;
  78.          }
  79.      }
  80.      /* basic curse check */
  81.      if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) {
  82.          ; /* some items can be removed even when cursed */
  83.      } else {
  84.          /* otherwise, this is fundamental */
  85.          if (cursed(otmp))
  86.              return 0;
  87.      }
  88.  
  89.      if (otmp == uarm)
  90.          context.takeoff.mask |= WORN_ARMOR;
  91.      else if (otmp == uarmc)
  92.          context.takeoff.mask |= WORN_CLOAK;
  93.      else if (otmp == uarmf)
  94.          context.takeoff.mask |= WORN_BOOTS;
  95.      else if (otmp == uarmg)
  96.          context.takeoff.mask |= WORN_GLOVES;
  97.      else if (otmp == uarmh)
  98.          context.takeoff.mask |= WORN_HELMET;
  99.      else if (otmp == uarms)
  100.          context.takeoff.mask |= WORN_SHIELD;
  101.      else if (otmp == uarmu)
  102.          context.takeoff.mask |= WORN_SHIRT;
  103.      else if (otmp == uleft)
  104.          context.takeoff.mask |= LEFT_RING;
  105.      else if (otmp == uright)
  106.          context.takeoff.mask |= RIGHT_RING;
  107.      else if (otmp == uamul)
  108.          context.takeoff.mask |= WORN_AMUL;
  109.      else if (otmp == ublindf)
  110.          context.takeoff.mask |= WORN_BLINDF;
  111.      else if (otmp == uwep)
  112.          context.takeoff.mask |= W_WEP;
  113.      else if (otmp == uswapwep)
  114.          context.takeoff.mask |= W_SWAPWEP;
  115.      else if (otmp == uquiver)
  116.          context.takeoff.mask |= W_QUIVER;
  117.  
  118.      else
  119.          impossible("select_off: %s???", doname(otmp));
  120.  
  121.      return 0;
  122.  }
  123.  

do_takeoff

  1.  STATIC_OVL struct obj *
  2.  do_takeoff()
  3.  {
  4.      struct obj *otmp = (struct obj *) 0;
  5.      struct takeoff_info *doff = &context.takeoff;
  6.  
  7.      if (doff->what == W_WEP) {
  8.          if (!cursed(uwep)) {
  9.              setuwep((struct obj *) 0);
  10.              You("are empty %s.", body_part(HANDED));
  11.              u.twoweap = FALSE;
  12.          }
  13.      } else if (doff->what == W_SWAPWEP) {
  14.          setuswapwep((struct obj *) 0);
  15.          You("no longer have a second weapon readied.");
  16.          u.twoweap = FALSE;
  17.      } else if (doff->what == W_QUIVER) {
  18.          setuqwep((struct obj *) 0);
  19.          You("no longer have ammunition readied.");
  20.      } else if (doff->what == WORN_ARMOR) {
  21.          otmp = uarm;
  22.          if (!cursed(otmp))
  23.              (void) Armor_off();
  24.      } else if (doff->what == WORN_CLOAK) {
  25.          otmp = uarmc;
  26.          if (!cursed(otmp))
  27.              (void) Cloak_off();
  28.      } else if (doff->what == WORN_BOOTS) {
  29.          otmp = uarmf;
  30.          if (!cursed(otmp))
  31.              (void) Boots_off();
  32.      } else if (doff->what == WORN_GLOVES) {
  33.          otmp = uarmg;
  34.          if (!cursed(otmp))
  35.              (void) Gloves_off();
  36.      } else if (doff->what == WORN_HELMET) {
  37.          otmp = uarmh;
  38.          if (!cursed(otmp))
  39.              (void) Helmet_off();
  40.      } else if (doff->what == WORN_SHIELD) {
  41.          otmp = uarms;
  42.          if (!cursed(otmp))
  43.              (void) Shield_off();
  44.      } else if (doff->what == WORN_SHIRT) {
  45.          otmp = uarmu;
  46.          if (!cursed(otmp))
  47.              (void) Shirt_off();
  48.      } else if (doff->what == WORN_AMUL) {
  49.          otmp = uamul;
  50.          if (!cursed(otmp))
  51.              Amulet_off();
  52.      } else if (doff->what == LEFT_RING) {
  53.          otmp = uleft;
  54.          if (!cursed(otmp))
  55.              Ring_off(uleft);
  56.      } else if (doff->what == RIGHT_RING) {
  57.          otmp = uright;
  58.          if (!cursed(otmp))
  59.              Ring_off(uright);
  60.      } else if (doff->what == WORN_BLINDF) {
  61.          if (!cursed(ublindf))
  62.              Blindf_off(ublindf);
  63.      } else {
  64.          impossible("do_takeoff: taking off %lx", doff->what);
  65.      }
  66.  
  67.      return otmp;
  68.  }
  69.  

take_off

  1.  /* occupation callback for 'A' */
  2.  STATIC_PTR
  3.  int
  4.  take_off(VOID_ARGS)
  5.  {
  6.      register int i;
  7.      register struct obj *otmp;
  8.      struct takeoff_info *doff = &context.takeoff;
  9.  
  10.      if (doff->what) {
  11.          if (doff->delay > 0) {
  12.              doff->delay--;
  13.              return 1; /* still busy */
  14.          } else {
  15.              if ((otmp = do_takeoff()))
  16.                  off_msg(otmp);
  17.          }
  18.          doff->mask &= ~doff->what;
  19.          doff->what = 0L;
  20.      }
  21.  
  22.      for (i = 0; takeoff_order[i]; i++)
  23.          if (doff->mask & takeoff_order[i]) {
  24.              doff->what = takeoff_order[i];
  25.              break;
  26.          }
  27.  
  28.      otmp = (struct obj *) 0;
  29.      doff->delay = 0;
  30.  
  31.      if (doff->what == 0L) {
  32.          You("finish %s.", doff->disrobing);
  33.          return 0;
  34.      } else if (doff->what == W_WEP) {
  35.          doff->delay = 1;
  36.      } else if (doff->what == W_SWAPWEP) {
  37.          doff->delay = 1;
  38.      } else if (doff->what == W_QUIVER) {
  39.          doff->delay = 1;
  40.      } else if (doff->what == WORN_ARMOR) {
  41.          otmp = uarm;
  42.          /* If a cloak is being worn, add the time to take it off and put
  43.           * it back on again.  Kludge alert! since that time is 0 for all
  44.           * known cloaks, add 1 so that it actually matters...
  45.           */
  46.          if (uarmc)
  47.              doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1;
  48.      } else if (doff->what == WORN_CLOAK) {
  49.          otmp = uarmc;
  50.      } else if (doff->what == WORN_BOOTS) {
  51.          otmp = uarmf;
  52.      } else if (doff->what == WORN_GLOVES) {
  53.          otmp = uarmg;
  54.      } else if (doff->what == WORN_HELMET) {
  55.          otmp = uarmh;
  56.      } else if (doff->what == WORN_SHIELD) {
  57.          otmp = uarms;
  58.      } else if (doff->what == WORN_SHIRT) {
  59.          otmp = uarmu;
  60.          /* add the time to take off and put back on armor and/or cloak */
  61.          if (uarm)
  62.              doff->delay += 2 * objects[uarm->otyp].oc_delay;
  63.          if (uarmc)
  64.              doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1;
  65.      } else if (doff->what == WORN_AMUL) {
  66.          doff->delay = 1;
  67.      } else if (doff->what == LEFT_RING) {
  68.          doff->delay = 1;
  69.      } else if (doff->what == RIGHT_RING) {
  70.          doff->delay = 1;
  71.      } else if (doff->what == WORN_BLINDF) {
  72.          doff->delay = 2;
  73.      } else {
  74.          impossible("take_off: taking off %lx", doff->what);
  75.          return 0; /* force done */
  76.      }
  77.  
  78.      if (otmp)
  79.          doff->delay += objects[otmp->otyp].oc_delay;
  80.  
  81.      /* Since setting the occupation now starts the counter next move, that
  82.       * would always produce a delay 1 too big per item unless we subtract
  83.       * 1 here to account for it.
  84.       */
  85.      if (doff->delay > 0)
  86.          doff->delay--;
  87.  
  88.      set_occupation(take_off, doff->disrobing, 0);
  89.      return 1; /* get busy */
  90.  }
  91.  

reset_remarm

  1.  /* clear saved context to avoid inappropriate resumption of interrupted 'A' */
  2.  void
  3.  reset_remarm()
  4.  {
  5.      context.takeoff.what = context.takeoff.mask = 0L;
  6.      context.takeoff.disrobing[0] = '\0';
  7.  }
  8.  

doddoremarm

  1.  /* the 'A' command -- remove multiple worn items */
  2.  int
  3.  doddoremarm()
  4.  {
  5.      int result = 0;
  6.  
  7.      if (context.takeoff.what || context.takeoff.mask) {
  8.          You("continue %s.", context.takeoff.disrobing);
  9.          set_occupation(take_off, context.takeoff.disrobing, 0);
  10.          return 0;
  11.      } else if (!uwep && !uswapwep && !uquiver && !uamul && !ublindf && !uleft
  12.                 && !uright && !wearing_armor()) {
  13.          You("are not wearing anything.");
  14.          return 0;
  15.      }
  16.  
  17.      add_valid_menu_class(0); /* reset */
  18.      if (flags.menu_style != MENU_TRADITIONAL
  19.          || (result = ggetobj("take off", select_off, 0, FALSE,
  20.                               (unsigned *) 0)) < -1)
  21.          result = menu_remarm(result);
  22.  
  23.      if (context.takeoff.mask) {
  24.          /* default activity for armor and/or accessories,
  25.             possibly combined with weapons */
  26.          (void) strncpy(context.takeoff.disrobing, "disrobing", CONTEXTVERBSZ);
  27.          /* specific activity when handling weapons only */
  28.          if (!(context.takeoff.mask & ~W_WEAPON))
  29.              (void) strncpy(context.takeoff.disrobing, "disarming",
  30.                             CONTEXTVERBSZ);
  31.          (void) take_off();
  32.      }
  33.      /* The time to perform the command is already completely accounted for
  34.       * in take_off(); if we return 1, that would add an extra turn to each
  35.       * disrobe.
  36.       */
  37.      return 0;
  38.  }
  39.  

menu_remarm

  1.  STATIC_OVL int
  2.  menu_remarm(retry)
  3.  int retry;
  4.  {
  5.      int n, i = 0;
  6.      menu_item *pick_list;
  7.      boolean all_worn_categories = TRUE;
  8.  
  9.      if (retry) {
  10.          all_worn_categories = (retry == -2);
  11.      } else if (flags.menu_style == MENU_FULL) {
  12.          all_worn_categories = FALSE;
  13.          n = query_category("What type of things do you want to take off?",
  14.                             invent, WORN_TYPES | ALL_TYPES, &pick_list,
  15.                             PICK_ANY);
  16.          if (!n)
  17.              return 0;
  18.          for (i = 0; i < n; i++) {
  19.              if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
  20.                  all_worn_categories = TRUE;
  21.              else
  22.                  add_valid_menu_class(pick_list[i].item.a_int);
  23.          }
  24.          free((genericptr_t) pick_list);
  25.      } else if (flags.menu_style == MENU_COMBINATION) {
  26.          all_worn_categories = FALSE;
  27.          if (ggetobj("take off", select_off, 0, TRUE, (unsigned *) 0) == -2)
  28.              all_worn_categories = TRUE;
  29.      }
  30.  
  31.      n = query_objlist("What do you want to take off?", invent,
  32.                        SIGNAL_NOMENU | USE_INVLET | INVORDER_SORT, &pick_list,
  33.                        PICK_ANY,
  34.                        all_worn_categories ? is_worn : is_worn_by_type);
  35.      if (n > 0) {
  36.          for (i = 0; i < n; i++)
  37.              (void) select_off(pick_list[i].item.a_obj);
  38.          free((genericptr_t) pick_list);
  39.      } else if (n < 0 && flags.menu_style != MENU_COMBINATION) {
  40.          There("is nothing else you can remove or unwield.");
  41.      }
  42.      return 0;
  43.  }
  44.  

destroy_arm

  1.  /* hit by destroy armor scroll/black dragon breath/monster spell */
  2.  int
  3.  destroy_arm(atmp)
  4.  register struct obj *atmp;
  5.  {
  6.      register struct obj *otmp;
  7.  #define DESTROY_ARM(o)                            \
  8.      ((otmp = (o)) != 0 && (!atmp || atmp == otmp) \
  9.               && (!obj_resists(otmp, 0, 90))       \
  10.           ? (otmp->in_use = TRUE)                  \
  11.           : FALSE)
  12.  
  13.      if (DESTROY_ARM(uarmc)) {
  14.          if (donning(otmp))
  15.              cancel_don();
  16.          Your("%s crumbles and turns to dust!", cloak_simple_name(uarmc));
  17.          (void) Cloak_off();
  18.          useup(otmp);
  19.      } else if (DESTROY_ARM(uarm)) {
  20.          if (donning(otmp))
  21.              cancel_don();
  22.          Your("armor turns to dust and falls to the %s!", surface(u.ux, u.uy));
  23.          (void) Armor_gone();
  24.          useup(otmp);
  25.      } else if (DESTROY_ARM(uarmu)) {
  26.          if (donning(otmp))
  27.              cancel_don();
  28.          Your("shirt crumbles into tiny threads and falls apart!");
  29.          (void) Shirt_off();
  30.          useup(otmp);
  31.      } else if (DESTROY_ARM(uarmh)) {
  32.          if (donning(otmp))
  33.              cancel_don();
  34.          Your("%s turns to dust and is blown away!", helm_simple_name(uarmh));
  35.          (void) Helmet_off();
  36.          useup(otmp);
  37.      } else if (DESTROY_ARM(uarmg)) {
  38.          if (donning(otmp))
  39.              cancel_don();
  40.          Your("gloves vanish!");
  41.          (void) Gloves_off();
  42.          useup(otmp);
  43.          selftouch("You");
  44.      } else if (DESTROY_ARM(uarmf)) {
  45.          if (donning(otmp))
  46.              cancel_don();
  47.          Your("boots disintegrate!");
  48.          (void) Boots_off();
  49.          useup(otmp);
  50.      } else if (DESTROY_ARM(uarms)) {
  51.          if (donning(otmp))
  52.              cancel_don();
  53.          Your("shield crumbles away!");
  54.          (void) Shield_off();
  55.          useup(otmp);
  56.      } else {
  57.          return 0; /* could not destroy anything */
  58.      }
  59.  
  60.  #undef DESTROY_ARM
  61.      stop_occupation();
  62.      return 1;
  63.  }
  64.  

adj_abon

  1.  void
  2.  adj_abon(otmp, delta)
  3.  register struct obj *otmp;
  4.  register schar delta;
  5.  {
  6.      if (uarmg && uarmg == otmp && otmp->otyp == GAUNTLETS_OF_DEXTERITY) {
  7.          if (delta) {
  8.              makeknown(uarmg->otyp);
  9.              ABON(A_DEX) += (delta);
  10.          }
  11.          context.botl = 1;
  12.      }
  13.      if (uarmh && uarmh == otmp && otmp->otyp == HELM_OF_BRILLIANCE) {
  14.          if (delta) {
  15.              makeknown(uarmh->otyp);
  16.              ABON(A_INT) += (delta);
  17.              ABON(A_WIS) += (delta);
  18.          }
  19.          context.botl = 1;
  20.      }
  21.  }
  22.  

inaccessible_equipment

  1.  /* decide whether a worn item is covered up by some other worn item,
  2.     used for dipping into liquid and applying grease;
  3.     some criteria are different than select_off()'s */
  4.  boolean
  5.  inaccessible_equipment(obj, verb, only_if_known_cursed)
  6.  struct obj *obj;
  7.  const char *verb; /* "dip" or "grease", or null to avoid messages */
  8.  boolean only_if_known_cursed; /* ignore covering unless known to be cursed */
  9.  {
  10.      static NEARDATA const char need_to_take_off_outer_armor[] =
  11.          "need to take off %s to %s %s.";
  12.      char buf[BUFSZ];
  13.      boolean anycovering = !only_if_known_cursed; /* more comprehensible... */
  14.  #define BLOCKSACCESS(x) (anycovering || ((x)->cursed && (x)->bknown))
  15.  
  16.      if (!obj || !obj->owornmask)
  17.          return FALSE; /* not inaccessible */
  18.  
  19.      /* check for suit covered by cloak */
  20.      if (obj == uarm && uarmc && BLOCKSACCESS(uarmc)) {
  21.          if (verb) {
  22.              Strcpy(buf, yname(uarmc));
  23.              You(need_to_take_off_outer_armor, buf, verb, yname(obj));
  24.          }
  25.          return TRUE;
  26.      }
  27.      /* check for shirt covered by suit and/or cloak */
  28.      if (obj == uarmu
  29.          && ((uarm && BLOCKSACCESS(uarm)) || (uarmc && BLOCKSACCESS(uarmc)))) {
  30.          if (verb) {
  31.              char cloaktmp[QBUFSZ], suittmp[QBUFSZ];
  32.              /* if sameprefix, use yname and xname to get "your cloak and suit"
  33.                 or "Manlobbi's cloak and suit"; otherwise, use yname and yname
  34.                 to get "your cloak and Manlobbi's suit" or vice versa */
  35.              boolean sameprefix = (uarm && uarmc
  36.                                    && !strcmp(shk_your(cloaktmp, uarmc),
  37.                                               shk_your(suittmp, uarm)));
  38.  
  39.              *buf = '\0';
  40.              if (uarmc)
  41.                  Strcat(buf, yname(uarmc));
  42.              if (uarm && uarmc)
  43.                  Strcat(buf, " and ");
  44.              if (uarm)
  45.                  Strcat(buf, sameprefix ? xname(uarm) : yname(uarm));
  46.              You(need_to_take_off_outer_armor, buf, verb, yname(obj));
  47.          }
  48.          return TRUE;
  49.      }
  50.      /* check for ring covered by gloves */
  51.      if ((obj == uleft || obj == uright) && uarmg && BLOCKSACCESS(uarmg)) {
  52.          if (verb) {
  53.              Strcpy(buf, yname(uarmg));
  54.              You(need_to_take_off_outer_armor, buf, verb, yname(obj));
  55.          }
  56.          return TRUE;
  57.      }
  58.      /* item is not inaccessible */
  59.      return FALSE;
  60.  }
  61.  
  62.  /*do_wear.c*/