Source:NetHack 3.6.1/src/objnam.c

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

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

Top of file

  1.  /* NetHack 3.6	objnam.c	$NHDT-Date: 1521507553 2018/03/20 00:59:13 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.199 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Robert Patrick Rankin, 2011. */
  4.  /* NetHack may be freely redistributed.  See license for details. */

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

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

  1.  
  2.  #include "hack.h"
  3.  
  4.  /* "an uncursed greased partly eaten guardian naga hatchling [corpse]" */
  5.  #define PREFIX 80 /* (56) */
  6.  #define SCHAR_LIM 127
  7.  #define NUMOBUF 12
  8.  
  9.  STATIC_DCL char *FDECL(strprepend, (char *, const char *));
  10.  STATIC_DCL short FDECL(rnd_otyp_by_wpnskill, (SCHAR_P));
  11.  STATIC_DCL short FDECL(rnd_otyp_by_namedesc, (char *, CHAR_P));
  12.  STATIC_DCL boolean FDECL(wishymatch, (const char *, const char *, BOOLEAN_P));
  13.  STATIC_DCL char *NDECL(nextobuf);
  14.  STATIC_DCL void FDECL(releaseobuf, (char *));
  15.  STATIC_DCL char *FDECL(minimal_xname, (struct obj *));
  16.  STATIC_DCL void FDECL(add_erosion_words, (struct obj *, char *));
  17.  STATIC_DCL char *FDECL(doname_base, (struct obj *obj, unsigned));
  18.  STATIC_DCL boolean FDECL(singplur_lookup, (char *, char *, BOOLEAN_P,
  19.                                             const char *const *));
  20.  STATIC_DCL char *FDECL(singplur_compound, (char *));
  21.  STATIC_DCL char *FDECL(xname_flags, (struct obj *, unsigned));
  22.  STATIC_DCL boolean FDECL(badman, (const char *, BOOLEAN_P));
  23.  
  24.  struct Jitem {
  25.      int item;
  26.      const char *name;
  27.  };
  28.  
  29.  #define BSTRCMPI(base, ptr, str) ((ptr) < base || strcmpi((ptr), str))
  30.  #define BSTRNCMPI(base, ptr, str, num) \
  31.      ((ptr) < base || strncmpi((ptr), str, num))
  32.  #define Strcasecpy(dst, src) (void) strcasecpy(dst, src)
  33.  
  34.  /* true for gems/rocks that should have " stone" appended to their names */
  35.  #define GemStone(typ)                                                  \
  36.      (typ == FLINT                                                      \
  37.       || (objects[typ].oc_material == GEMSTONE                          \
  38.           && (typ != DILITHIUM_CRYSTAL && typ != RUBY && typ != DIAMOND \
  39.               && typ != SAPPHIRE && typ != BLACK_OPAL && typ != EMERALD \
  40.               && typ != OPAL)))
  41.  
  42.  STATIC_OVL struct Jitem Japanese_items[] = { { SHORT_SWORD, "wakizashi" },
  43.                                               { BROADSWORD, "ninja-to" },
  44.                                               { FLAIL, "nunchaku" },
  45.                                               { GLAIVE, "naginata" },
  46.                                               { LOCK_PICK, "osaku" },
  47.                                               { WOODEN_HARP, "koto" },
  48.                                               { KNIFE, "shito" },
  49.                                               { PLATE_MAIL, "tanko" },
  50.                                               { HELMET, "kabuto" },
  51.                                               { LEATHER_GLOVES, "yugake" },
  52.                                               { FOOD_RATION, "gunyoki" },
  53.                                               { POT_BOOZE, "sake" },
  54.                                               { 0, "" } };
  55.  
  56.  STATIC_DCL const char *FDECL(Japanese_item_name, (int i));
  57.  

strprepend

  1.  STATIC_OVL char *
  2.  strprepend(s, pref)
  3.  register char *s;
  4.  register const char *pref;
  5.  {
  6.      register int i = (int) strlen(pref);
  7.  
  8.      if (i > PREFIX) {
  9.          impossible("PREFIX too short (for %d).", i);
  10.          return s;
  11.      }
  12.      s -= i;
  13.      (void) strncpy(s, pref, i); /* do not copy trailing 0 */
  14.      return s;
  15.  }
  16.  

nextobuf

  1.  /* manage a pool of BUFSZ buffers, so callers don't have to */
  2.  static char NEARDATA obufs[NUMOBUF][BUFSZ];
  3.  static int obufidx = 0;
  4.  
  5.  STATIC_OVL char *
  6.  nextobuf()
  7.  {
  8.      obufidx = (obufidx + 1) % NUMOBUF;
  9.      return obufs[obufidx];
  10.  }
  11.  

releaseobuf

  1.  /* put the most recently allocated buffer back if possible */
  2.  STATIC_OVL void
  3.  releaseobuf(bufp)
  4.  char *bufp;
  5.  {
  6.      /* caller may not know whether bufp is the most recently allocated
  7.         buffer; if it isn't, do nothing; note that because of the somewhat
  8.         obscure PREFIX handling for object name formatting by xname(),
  9.         the pointer our caller has and is passing to us might be into the
  10.         middle of an obuf rather than the address returned by nextobuf() */
  11.      if (bufp >= obufs[obufidx]
  12.          && bufp < obufs[obufidx] + sizeof obufs[obufidx]) /* obufs[][BUFSZ] */
  13.          obufidx = (obufidx - 1 + NUMOBUF) % NUMOBUF;
  14.  }
  15.  

obj_typename

  1.  char *
  2.  obj_typename(otyp)
  3.  register int otyp;
  4.  {
  5.      char *buf = nextobuf();
  6.      struct objclass *ocl = &objects[otyp];
  7.      const char *actualn = OBJ_NAME(*ocl);
  8.      const char *dn = OBJ_DESCR(*ocl);
  9.      const char *un = ocl->oc_uname;
  10.      int nn = ocl->oc_name_known;
  11.  
  12.      if (Role_if(PM_SAMURAI) && Japanese_item_name(otyp))
  13.          actualn = Japanese_item_name(otyp);
  14.      switch (ocl->oc_class) {
  15.      case COIN_CLASS:
  16.          Strcpy(buf, "coin");
  17.          break;
  18.      case POTION_CLASS:
  19.          Strcpy(buf, "potion");
  20.          break;
  21.      case SCROLL_CLASS:
  22.          Strcpy(buf, "scroll");
  23.          break;
  24.      case WAND_CLASS:
  25.          Strcpy(buf, "wand");
  26.          break;
  27.      case SPBOOK_CLASS:
  28.          if (otyp != SPE_NOVEL) {
  29.              Strcpy(buf, "spellbook");
  30.          } else {
  31.              Strcpy(buf, !nn ? "book" : "novel");
  32.              nn = 0;
  33.          }
  34.          break;
  35.      case RING_CLASS:
  36.          Strcpy(buf, "ring");
  37.          break;
  38.      case AMULET_CLASS:
  39.          if (nn)
  40.              Strcpy(buf, actualn);
  41.          else
  42.              Strcpy(buf, "amulet");
  43.          if (un)
  44.              Sprintf(eos(buf), " called %s", un);
  45.          if (dn)
  46.              Sprintf(eos(buf), " (%s)", dn);
  47.          return buf;
  48.      default:
  49.          if (nn) {
  50.              Strcpy(buf, actualn);
  51.              if (GemStone(otyp))
  52.                  Strcat(buf, " stone");
  53.              if (un)
  54.                  Sprintf(eos(buf), " called %s", un);
  55.              if (dn)
  56.                  Sprintf(eos(buf), " (%s)", dn);
  57.          } else {
  58.              Strcpy(buf, dn ? dn : actualn);
  59.              if (ocl->oc_class == GEM_CLASS)
  60.                  Strcat(buf,
  61.                         (ocl->oc_material == MINERAL) ? " stone" : " gem");
  62.              if (un)
  63.                  Sprintf(eos(buf), " called %s", un);
  64.          }
  65.          return buf;
  66.      }
  67.      /* here for ring/scroll/potion/wand */
  68.      if (nn) {
  69.          if (ocl->oc_unique)
  70.              Strcpy(buf, actualn); /* avoid spellbook of Book of the Dead */
  71.          else
  72.              Sprintf(eos(buf), " of %s", actualn);
  73.      }
  74.      if (un)
  75.          Sprintf(eos(buf), " called %s", un);
  76.      if (dn)
  77.          Sprintf(eos(buf), " (%s)", dn);
  78.      return buf;
  79.  }
  80.  

simple_typename

  1.  /* less verbose result than obj_typename(); either the actual name
  2.     or the description (but not both); user-assigned name is ignored */
  3.  char *
  4.  simple_typename(otyp)
  5.  int otyp;
  6.  {
  7.      char *bufp, *pp, *save_uname = objects[otyp].oc_uname;
  8.  
  9.      objects[otyp].oc_uname = 0; /* suppress any name given by user */
  10.      bufp = obj_typename(otyp);
  11.      objects[otyp].oc_uname = save_uname;
  12.      if ((pp = strstri(bufp, " (")) != 0)
  13.          *pp = '\0'; /* strip the appended description */
  14.      return bufp;
  15.  }
  16.  

obj_is_pname

  1.  boolean
  2.  obj_is_pname(obj)
  3.  struct obj *obj;
  4.  {
  5.      if (!obj->oartifact || !has_oname(obj))
  6.          return FALSE;
  7.      if (!program_state.gameover && !iflags.override_ID) {
  8.          if (not_fully_identified(obj))
  9.              return FALSE;
  10.      }
  11.      return TRUE;
  12.  }
  13.  
  14.  /* used by distant_name() to pass extra information to xname_flags();
  15.     it would be much cleaner if this were a parameter, but that would
  16.     require all of the xname() and doname() calls to be modified */
  17.  static int distantname = 0;
  18.  

distant_name

  1.  /* Give the name of an object seen at a distance.  Unlike xname/doname,
  2.   * we don't want to set dknown if it's not set already.
  3.   */
  4.  char *
  5.  distant_name(obj, func)
  6.  struct obj *obj;
  7.  char *FDECL((*func), (OBJ_P));
  8.  {
  9.      char *str;
  10.  
  11.      /* 3.6.1: this used to save Blind, set it, make the call, then restore
  12.       * the saved value; but the Eyes of the Overworld override blindness
  13.       * and let characters wearing them get dknown set for distant items.
  14.       *
  15.       * TODO? if the hero is wearing those Eyes, figure out whether the
  16.       * object is within X-ray radius and only treat it as distant when
  17.       * beyond that radius.  Logic is iffy but result might be interesting.
  18.       */
  19.      ++distantname;
  20.      str = (*func)(obj);
  21.      --distantname;
  22.      return str;
  23.  }
  24.  

fruitname

  1.  /* convert player specified fruit name into corresponding fruit juice name
  2.     ("slice of pizza" -> "pizza juice" rather than "slice of pizza juice") */
  3.  char *
  4.  fruitname(juice)
  5.  boolean juice; /* whether or not to append " juice" to the name */
  6.  {
  7.      char *buf = nextobuf();
  8.      const char *fruit_nam = strstri(pl_fruit, " of ");
  9.  
  10.      if (fruit_nam)
  11.          fruit_nam += 4; /* skip past " of " */
  12.      else
  13.          fruit_nam = pl_fruit; /* use it as is */
  14.  
  15.      Sprintf(buf, "%s%s", makesingular(fruit_nam), juice ? " juice" : "");
  16.      return buf;
  17.  }
  18.  

fruit_from_indx

  1.  /* look up a named fruit by index (1..127) */
  2.  struct fruit *
  3.  fruit_from_indx(indx)
  4.  int indx;
  5.  {
  6.      struct fruit *f;
  7.  
  8.      for (f = ffruit; f; f = f->nextf)
  9.          if (f->fid == indx)
  10.              break;
  11.      return f;
  12.  }
  13.  

fruit_from_name

  1.  /* look up a named fruit by name */
  2.  struct fruit *
  3.  fruit_from_name(fname, exact, highest_fid)
  4.  const char *fname;
  5.  boolean exact; /* False => prefix or exact match, True = exact match only */
  6.  int *highest_fid; /* optional output; only valid if 'fname' isn't found */
  7.  {
  8.      struct fruit *f, *tentativef;
  9.      char *altfname;
  10.      unsigned k;
  11.      /*
  12.       * note: named fruits are case-senstive...
  13.       */
  14.  
  15.      if (highest_fid)
  16.          *highest_fid = 0;
  17.      /* first try for an exact match */
  18.      for (f = ffruit; f; f = f->nextf)
  19.          if (!strcmp(f->fname, fname))
  20.              return f;
  21.          else if (highest_fid && f->fid > *highest_fid)
  22.              *highest_fid = f->fid;
  23.  
  24.      /* didn't match as-is; if caller is willing to accept a prefix
  25.         match, try to find one; we want to find the longest prefix that
  26.         matches, not the first */
  27.      if (!exact) {
  28.          tentativef = 0;
  29.          for (f = ffruit; f; f = f->nextf) {
  30.              k = strlen(f->fname);
  31.              if (!strncmp(f->fname, fname, k)
  32.                  && (!fname[k] || fname[k] == ' ')
  33.                  && (!tentativef || k > strlen(tentativef->fname)))
  34.                  tentativef = f;
  35.          }
  36.          f = tentativef;
  37.      }
  38.      /* if we still don't have a match, try singularizing the target;
  39.         for exact match, that's trivial, but for prefix, it's hard */
  40.      if (!f) {
  41.          altfname = makesingular(fname);
  42.          for (f = ffruit; f; f = f->nextf) {
  43.              if (!strcmp(f->fname, altfname))
  44.                  break;
  45.          }
  46.          releaseobuf(altfname);
  47.      }
  48.      if (!f && !exact) {
  49.          char fnamebuf[BUFSZ], *p;
  50.          unsigned fname_k = strlen(fname); /* length of assumed plural fname */
  51.  
  52.          tentativef = 0;
  53.          for (f = ffruit; f; f = f->nextf) {
  54.              k = strlen(f->fname);
  55.              /* reload fnamebuf[] each iteration in case it gets modified;
  56.                 there's no need to recalculate fname_k */
  57.              Strcpy(fnamebuf, fname);
  58.              /* bug? if singular of fname is longer than plural,
  59.                 failing the 'fname_k > k' test could skip a viable
  60.                 candidate; unfortunately, we can't singularize until
  61.                 after stripping off trailing stuff and we can't get
  62.                 accurate fname_k until fname has been singularized;
  63.                 compromise and use 'fname_k >= k' instead of '>',
  64.                 accepting 1 char length discrepancy without risking
  65.                 false match (I hope...) */
  66.              if (fname_k >= k && (p = index(&fnamebuf[k], ' ')) != 0) {
  67.                  *p = '\0'; /* truncate at 1st space past length of f->fname */
  68.                  altfname = makesingular(fnamebuf);
  69.                  k = strlen(altfname); /* actually revised 'fname_k' */
  70.                  if (!strcmp(f->fname, altfname)
  71.                      && (!tentativef || k > strlen(tentativef->fname)))
  72.                      tentativef = f;
  73.                  releaseobuf(altfname); /* avoid churning through all obufs */
  74.              }
  75.          }
  76.          f = tentativef;
  77.      }
  78.      return f;
  79.  }
  80.  

reorder_fruit

  1.  /* sort the named-fruit linked list by fruit index number */
  2.  void
  3.  reorder_fruit(forward)
  4.  boolean forward;
  5.  {
  6.      struct fruit *f, *allfr[1 + 127];
  7.      int i, j, k = SIZE(allfr);
  8.  
  9.      for (i = 0; i < k; ++i)
  10.          allfr[i] = (struct fruit *) 0;
  11.      for (f = ffruit; f; f = f->nextf) {
  12.          /* without sanity checking, this would reduce to 'allfr[f->fid]=f' */
  13.          j = f->fid;
  14.          if (j < 1 || j >= k) {
  15.              impossible("reorder_fruit: fruit index (%d) out of range", j);
  16.              return; /* don't sort after all; should never happen... */
  17.          } else if (allfr[j]) {
  18.              impossible("reorder_fruit: duplicate fruit index (%d)", j);
  19.              return;
  20.          }
  21.          allfr[j] = f;
  22.      }
  23.      ffruit = 0; /* reset linked list; we're rebuilding it from scratch */
  24.      /* slot [0] will always be empty; must start 'i' at 1 to avoid
  25.         [k - i] being out of bounds during first iteration */
  26.      for (i = 1; i < k; ++i) {
  27.          /* for forward ordering, go through indices from high to low;
  28.             for backward ordering, go from low to high */
  29.          j = forward ? (k - i) : i;
  30.          if (allfr[j]) {
  31.              allfr[j]->nextf = ffruit;
  32.              ffruit = allfr[j];
  33.          }
  34.      }
  35.  }
  36.  

xname

  1.  char *
  2.  xname(obj)
  3.  struct obj *obj;
  4.  {
  5.      return xname_flags(obj, CXN_NORMAL);
  6.  }
  7.  

xname_flags

  1.  char *
  2.  xname_flags(obj, cxn_flags)
  3.  register struct obj *obj;
  4.  unsigned cxn_flags; /* bitmask of CXN_xxx values */
  5.  {
  6.      register char *buf;
  7.      register int typ = obj->otyp;
  8.      register struct objclass *ocl = &objects[typ];
  9.      int nn = ocl->oc_name_known, omndx = obj->corpsenm;
  10.      const char *actualn = OBJ_NAME(*ocl);
  11.      const char *dn = OBJ_DESCR(*ocl) ? OBJ_DESCR(*ocl) : actualn;
  12.      const char *un = ocl->oc_uname;
  13.      boolean pluralize = (obj->quan != 1L) && !(cxn_flags & CXN_SINGULAR);
  14.      boolean known, dknown, bknown;
  15.  
  16.      buf = nextobuf() + PREFIX; /* leave room for "17 -3 " */
  17.      if (Role_if(PM_SAMURAI) && Japanese_item_name(typ))
  18.          actualn = Japanese_item_name(typ);
  19.  
  20.      buf[0] = '\0';
  21.      /*
  22.       * clean up known when it's tied to oc_name_known, eg after AD_DRIN
  23.       * This is only required for unique objects since the article
  24.       * printed for the object is tied to the combination of the two
  25.       * and printing the wrong article gives away information.
  26.       */
  27.      if (!nn && ocl->oc_uses_known && ocl->oc_unique)
  28.          obj->known = 0;
  29.      if (!Blind && !distantname)
  30.          obj->dknown = TRUE;
  31.      if (Role_if(PM_PRIEST))
  32.          obj->bknown = TRUE;
  33.  
  34.      if (iflags.override_ID) {
  35.          known = dknown = bknown = TRUE;
  36.          nn = 1;
  37.      } else {
  38.          known = obj->known;
  39.          dknown = obj->dknown;
  40.          bknown = obj->bknown;
  41.      }
  42.  
  43.      if (obj_is_pname(obj))
  44.          goto nameit;
  45.      switch (obj->oclass) {
  46.      case AMULET_CLASS:
  47.          if (!dknown)
  48.              Strcpy(buf, "amulet");
  49.          else if (typ == AMULET_OF_YENDOR || typ == FAKE_AMULET_OF_YENDOR)
  50.              /* each must be identified individually */
  51.              Strcpy(buf, known ? actualn : dn);
  52.          else if (nn)
  53.              Strcpy(buf, actualn);
  54.          else if (un)
  55.              Sprintf(buf, "amulet called %s", un);
  56.          else
  57.              Sprintf(buf, "%s amulet", dn);
  58.          break;
  59.      case WEAPON_CLASS:
  60.          if (is_poisonable(obj) && obj->opoisoned)
  61.              Strcpy(buf, "poisoned ");
  62.          /*FALLTHRU*/
  63.      case VENOM_CLASS:
  64.      case TOOL_CLASS:
  65.          if (typ == LENSES)
  66.              Strcpy(buf, "pair of ");
  67.          else if (is_wet_towel(obj))
  68.              Strcpy(buf, (obj->spe < 3) ? "moist " : "wet ");
  69.  
  70.          if (!dknown)
  71.              Strcat(buf, dn);
  72.          else if (nn)
  73.              Strcat(buf, actualn);
  74.          else if (un) {
  75.              Strcat(buf, dn);
  76.              Strcat(buf, " called ");
  77.              Strcat(buf, un);
  78.          } else
  79.              Strcat(buf, dn);
  80.          /* If we use an() here we'd have to remember never to use */
  81.          /* it whenever calling doname() or xname(). */
  82.          if (typ == FIGURINE && omndx != NON_PM) {
  83.              Sprintf(eos(buf), " of a%s %s",
  84.                      index(vowels, *mons[omndx].mname) ? "n" : "",
  85.                      mons[omndx].mname);
  86.          } else if (is_wet_towel(obj)) {
  87.              if (wizard)
  88.                  Sprintf(eos(buf), " (%d)", obj->spe);
  89.          }
  90.          break;
  91.      case ARMOR_CLASS:
  92.          /* depends on order of the dragon scales objects */
  93.          if (typ >= GRAY_DRAGON_SCALES && typ <= YELLOW_DRAGON_SCALES) {
  94.              Sprintf(buf, "set of %s", actualn);
  95.              break;
  96.          }
  97.          if (is_boots(obj) || is_gloves(obj))
  98.              Strcpy(buf, "pair of ");
  99.  
  100.          if (obj->otyp >= ELVEN_SHIELD && obj->otyp <= ORCISH_SHIELD
  101.              && !dknown) {
  102.              Strcpy(buf, "shield");
  103.              break;
  104.          }
  105.          if (obj->otyp == SHIELD_OF_REFLECTION && !dknown) {
  106.              Strcpy(buf, "smooth shield");
  107.              break;
  108.          }
  109.  
  110.          if (nn)
  111.              Strcat(buf, actualn);
  112.          else if (un) {
  113.              if (is_boots(obj))
  114.                  Strcat(buf, "boots");
  115.              else if (is_gloves(obj))
  116.                  Strcat(buf, "gloves");
  117.              else if (is_cloak(obj))
  118.                  Strcpy(buf, "cloak");
  119.              else if (is_helmet(obj))
  120.                  Strcpy(buf, "helmet");
  121.              else if (is_shield(obj))
  122.                  Strcpy(buf, "shield");
  123.              else
  124.                  Strcpy(buf, "armor");
  125.              Strcat(buf, " called ");
  126.              Strcat(buf, un);
  127.          } else
  128.              Strcat(buf, dn);
  129.          break;
  130.      case FOOD_CLASS:
  131.          if (typ == SLIME_MOLD) {
  132.              struct fruit *f = fruit_from_indx(obj->spe);
  133.  
  134.              if (!f) {
  135.                  impossible("Bad fruit #%d?", obj->spe);
  136.                  Strcpy(buf, "fruit");
  137.              } else {
  138.                  Strcpy(buf, f->fname);
  139.                  if (pluralize) {
  140.                      /* ick; already pluralized fruit names
  141.                         are allowed--we want to try to avoid
  142.                         adding a redundant plural suffix */
  143.                      Strcpy(buf, makeplural(makesingular(buf)));
  144.                      pluralize = FALSE;
  145.                  }
  146.              }
  147.              break;
  148.          }
  149.          if (obj->globby) {
  150.              Sprintf(buf, "%s%s",
  151.                      (obj->owt <= 100)
  152.                         ? "small "
  153.                         : (obj->owt > 500)
  154.                            ? "very large "
  155.                            : (obj->owt > 300)
  156.                               ? "large "
  157.                               : "",
  158.                      actualn);
  159.              break;
  160.          }
  161.  
  162.          Strcpy(buf, actualn);
  163.          if (typ == TIN && known)
  164.              tin_details(obj, omndx, buf);
  165.          break;
  166.      case COIN_CLASS:
  167.      case CHAIN_CLASS:
  168.          Strcpy(buf, actualn);
  169.          break;
  170.      case ROCK_CLASS:
  171.          if (typ == STATUE && omndx != NON_PM)
  172.              Sprintf(buf, "%s%s of %s%s",
  173.                      (Role_if(PM_ARCHEOLOGIST) && (obj->spe & STATUE_HISTORIC))
  174.                         ? "historic "
  175.                         : "",
  176.                      actualn,
  177.                      type_is_pname(&mons[omndx])
  178.                         ? ""
  179.                         : the_unique_pm(&mons[omndx])
  180.                            ? "the "
  181.                            : index(vowels, *mons[omndx].mname)
  182.                               ? "an "
  183.                               : "a ",
  184.                      mons[omndx].mname);
  185.          else
  186.              Strcpy(buf, actualn);
  187.          break;
  188.      case BALL_CLASS:
  189.          Sprintf(buf, "%sheavy iron ball",
  190.                  (obj->owt > ocl->oc_weight) ? "very " : "");
  191.          break;
  192.      case POTION_CLASS:
  193.          if (dknown && obj->odiluted)
  194.              Strcpy(buf, "diluted ");
  195.          if (nn || un || !dknown) {
  196.              Strcat(buf, "potion");
  197.              if (!dknown)
  198.                  break;
  199.              if (nn) {
  200.                  Strcat(buf, " of ");
  201.                  if (typ == POT_WATER && bknown
  202.                      && (obj->blessed || obj->cursed)) {
  203.                      Strcat(buf, obj->blessed ? "holy " : "unholy ");
  204.                  }
  205.                  Strcat(buf, actualn);
  206.              } else {
  207.                  Strcat(buf, " called ");
  208.                  Strcat(buf, un);
  209.              }
  210.          } else {
  211.              Strcat(buf, dn);
  212.              Strcat(buf, " potion");
  213.          }
  214.          break;
  215.      case SCROLL_CLASS:
  216.          Strcpy(buf, "scroll");
  217.          if (!dknown)
  218.              break;
  219.          if (nn) {
  220.              Strcat(buf, " of ");
  221.              Strcat(buf, actualn);
  222.          } else if (un) {
  223.              Strcat(buf, " called ");
  224.              Strcat(buf, un);
  225.          } else if (ocl->oc_magic) {
  226.              Strcat(buf, " labeled ");
  227.              Strcat(buf, dn);
  228.          } else {
  229.              Strcpy(buf, dn);
  230.              Strcat(buf, " scroll");
  231.          }
  232.          break;
  233.      case WAND_CLASS:
  234.          if (!dknown)
  235.              Strcpy(buf, "wand");
  236.          else if (nn)
  237.              Sprintf(buf, "wand of %s", actualn);
  238.          else if (un)
  239.              Sprintf(buf, "wand called %s", un);
  240.          else
  241.              Sprintf(buf, "%s wand", dn);
  242.          break;
  243.      case SPBOOK_CLASS:
  244.          if (typ == SPE_NOVEL) { /* 3.6 tribute */
  245.              if (!dknown)
  246.                  Strcpy(buf, "book");
  247.              else if (nn)
  248.                  Strcpy(buf, actualn);
  249.              else if (un)
  250.                  Sprintf(buf, "novel called %s", un);
  251.              else
  252.                  Sprintf(buf, "%s book", dn);
  253.              break;
  254.              /* end of tribute */
  255.          } else if (!dknown) {
  256.              Strcpy(buf, "spellbook");
  257.          } else if (nn) {
  258.              if (typ != SPE_BOOK_OF_THE_DEAD)
  259.                  Strcpy(buf, "spellbook of ");
  260.              Strcat(buf, actualn);
  261.          } else if (un) {
  262.              Sprintf(buf, "spellbook called %s", un);
  263.          } else
  264.              Sprintf(buf, "%s spellbook", dn);
  265.          break;
  266.      case RING_CLASS:
  267.          if (!dknown)
  268.              Strcpy(buf, "ring");
  269.          else if (nn)
  270.              Sprintf(buf, "ring of %s", actualn);
  271.          else if (un)
  272.              Sprintf(buf, "ring called %s", un);
  273.          else
  274.              Sprintf(buf, "%s ring", dn);
  275.          break;
  276.      case GEM_CLASS: {
  277.          const char *rock = (ocl->oc_material == MINERAL) ? "stone" : "gem";
  278.  
  279.          if (!dknown) {
  280.              Strcpy(buf, rock);
  281.          } else if (!nn) {
  282.              if (un)
  283.                  Sprintf(buf, "%s called %s", rock, un);
  284.              else
  285.                  Sprintf(buf, "%s %s", dn, rock);
  286.          } else {
  287.              Strcpy(buf, actualn);
  288.              if (GemStone(typ))
  289.                  Strcat(buf, " stone");
  290.          }
  291.          break;
  292.      }
  293.      default:
  294.          Sprintf(buf, "glorkum %d %d %d", obj->oclass, typ, obj->spe);
  295.      }
  296.      if (pluralize)
  297.          Strcpy(buf, makeplural(buf));
  298.  
  299.      if (obj->otyp == T_SHIRT && program_state.gameover) {
  300.          char tmpbuf[BUFSZ];
  301.  
  302.          Sprintf(eos(buf), " with text \"%s\"", tshirt_text(obj, tmpbuf));
  303.      }
  304.  
  305.      if (has_oname(obj) && dknown) {
  306.          Strcat(buf, " named ");
  307.      nameit:
  308.          Strcat(buf, ONAME(obj));
  309.      }
  310.  
  311.      if (!strncmpi(buf, "the ", 4))
  312.          buf += 4;
  313.      return buf;
  314.  }
  315.  

minimal_xname

  1.  /* similar to simple_typename but minimal_xname operates on a particular
  2.     object rather than its general type; it formats the most basic info:
  3.       potion                     -- if description not known
  4.       brown potion               -- if oc_name_known not set
  5.       potion of object detection -- if discovered
  6.   */
  7.  STATIC_OVL char *
  8.  minimal_xname(obj)
  9.  struct obj *obj;
  10.  {
  11.      char *bufp;
  12.      struct obj bareobj;
  13.      struct objclass saveobcls;
  14.      int otyp = obj->otyp;
  15.  
  16.      /* suppress user-supplied name */
  17.      saveobcls.oc_uname = objects[otyp].oc_uname;
  18.      objects[otyp].oc_uname = 0;
  19.      /* suppress actual name if object's description is unknown */
  20.      saveobcls.oc_name_known = objects[otyp].oc_name_known;
  21.      if (!obj->dknown)
  22.          objects[otyp].oc_name_known = 0;
  23.  
  24.      /* caveat: this makes a lot of assumptions about which fields
  25.         are required in order for xname() to yield a sensible result */
  26.      bareobj = zeroobj;
  27.      bareobj.otyp = otyp;
  28.      bareobj.oclass = obj->oclass;
  29.      bareobj.dknown = obj->dknown;
  30.      /* suppress known except for amulets (needed for fakes and real A-of-Y) */
  31.      bareobj.known = (obj->oclass == AMULET_CLASS)
  32.                          ? obj->known
  33.                          /* default is "on" for types which don't use it */
  34.                          : !objects[otyp].oc_uses_known;
  35.      bareobj.quan = 1L;         /* don't want plural */
  36.      bareobj.corpsenm = NON_PM; /* suppress statue and figurine details */
  37.      /* but suppressing fruit details leads to "bad fruit #0"
  38.         [perhaps we should force "slime mold" rather than use xname?] */
  39.      if (obj->otyp == SLIME_MOLD)
  40.          bareobj.spe = obj->spe;
  41.  
  42.      bufp = distant_name(&bareobj, xname); /* xname(&bareobj) */
  43.      if (!strncmp(bufp, "uncursed ", 9))
  44.          bufp += 9; /* Role_if(PM_PRIEST) */
  45.  
  46.      objects[otyp].oc_uname = saveobcls.oc_uname;
  47.      objects[otyp].oc_name_known = saveobcls.oc_name_known;
  48.      return bufp;
  49.  }
  50.  

mshot_xname

  1.  /* xname() output augmented for multishot missile feedback */
  2.  char *
  3.  mshot_xname(obj)
  4.  struct obj *obj;
  5.  {
  6.      char tmpbuf[BUFSZ];
  7.      char *onm = xname(obj);
  8.  
  9.      if (m_shot.n > 1 && m_shot.o == obj->otyp) {
  10.          /* "the Nth arrow"; value will eventually be passed to an() or
  11.             The(), both of which correctly handle this "the " prefix */
  12.          Sprintf(tmpbuf, "the %d%s ", m_shot.i, ordin(m_shot.i));
  13.          onm = strprepend(onm, tmpbuf);
  14.      }
  15.      return onm;
  16.  }
  17.  

the_unique_obj

  1.  /* used for naming "the unique_item" instead of "a unique_item" */
  2.  boolean
  3.  the_unique_obj(obj)
  4.  struct obj *obj;
  5.  {
  6.      boolean known = (obj->known || iflags.override_ID);
  7.  
  8.      if (!obj->dknown && !iflags.override_ID)
  9.          return FALSE;
  10.      else if (obj->otyp == FAKE_AMULET_OF_YENDOR && !known)
  11.          return TRUE; /* lie */
  12.      else
  13.          return (boolean) (objects[obj->otyp].oc_unique
  14.                            && (known || obj->otyp == AMULET_OF_YENDOR));
  15.  }
  16.  

the_unique_pm

  1.  /* should monster type be prefixed with "the"? (mostly used for corpses) */
  2.  boolean
  3.  the_unique_pm(ptr)
  4.  struct permonst *ptr;
  5.  {
  6.      boolean uniq;
  7.  
  8.      /* even though monsters with personal names are unique, we want to
  9.         describe them as "Name" rather than "the Name" */
  10.      if (type_is_pname(ptr))
  11.          return FALSE;
  12.  
  13.      uniq = (ptr->geno & G_UNIQ) ? TRUE : FALSE;
  14.      /* high priest is unique if it includes "of <deity>", otherwise not
  15.         (caller needs to handle the 1st possibility; we assume the 2nd);
  16.         worm tail should be irrelevant but is included for completeness */
  17.      if (ptr == &mons[PM_HIGH_PRIEST] || ptr == &mons[PM_LONG_WORM_TAIL])
  18.          uniq = FALSE;
  19.      /* Wizard no longer needs this; he's flagged as unique these days */
  20.      if (ptr == &mons[PM_WIZARD_OF_YENDOR])
  21.          uniq = TRUE;
  22.      return uniq;
  23.  }
  24.  

add_erosion_words

  1.  STATIC_OVL void
  2.  add_erosion_words(obj, prefix)
  3.  struct obj *obj;
  4.  char *prefix;
  5.  {
  6.      boolean iscrys = (obj->otyp == CRYSKNIFE);
  7.      boolean rknown;
  8.  
  9.      rknown = (iflags.override_ID == 0) ? obj->rknown : TRUE;
  10.  
  11.      if (!is_damageable(obj) && !iscrys)
  12.          return;
  13.  
  14.      /* The only cases where any of these bits do double duty are for
  15.       * rotted food and diluted potions, which are all not is_damageable().
  16.       */
  17.      if (obj->oeroded && !iscrys) {
  18.          switch (obj->oeroded) {
  19.          case 2:
  20.              Strcat(prefix, "very ");
  21.              break;
  22.          case 3:
  23.              Strcat(prefix, "thoroughly ");
  24.              break;
  25.          }
  26.          Strcat(prefix, is_rustprone(obj) ? "rusty " : "burnt ");
  27.      }
  28.      if (obj->oeroded2 && !iscrys) {
  29.          switch (obj->oeroded2) {
  30.          case 2:
  31.              Strcat(prefix, "very ");
  32.              break;
  33.          case 3:
  34.              Strcat(prefix, "thoroughly ");
  35.              break;
  36.          }
  37.          Strcat(prefix, is_corrodeable(obj) ? "corroded " : "rotted ");
  38.      }
  39.      if (rknown && obj->oerodeproof)
  40.          Strcat(prefix, iscrys
  41.                            ? "fixed "
  42.                            : is_rustprone(obj)
  43.                               ? "rustproof "
  44.                               : is_corrodeable(obj)
  45.                                  ? "corrodeproof " /* "stainless"? */
  46.                                  : is_flammable(obj)
  47.                                     ? "fireproof "
  48.                                     : "");
  49.  }
  50.  

erosion_matters

  1.  /* used to prevent rust on items where rust makes no difference */
  2.  boolean
  3.  erosion_matters(obj)
  4.  struct obj *obj;
  5.  {
  6.      switch (obj->oclass) {
  7.      case TOOL_CLASS:
  8.          /* it's possible for a rusty weptool to be polymorphed into some
  9.             non-weptool iron tool, in which case the rust implicitly goes
  10.             away, but it's also possible for it to be polymorphed into a
  11.             non-iron tool, in which case rust also implicitly goes away,
  12.             so there's no particular reason to try to handle the first
  13.             instance differently [this comment belongs in poly_obj()...] */
  14.          return is_weptool(obj) ? TRUE : FALSE;
  15.      case WEAPON_CLASS:
  16.      case ARMOR_CLASS:
  17.      case BALL_CLASS:
  18.      case CHAIN_CLASS:
  19.          return TRUE;
  20.      default:
  21.          break;
  22.      }
  23.      return FALSE;
  24.  }
  25.  
  26.  #define DONAME_WITH_PRICE 1
  27.  #define DONAME_VAGUE_QUAN 2
  28.  

doname_base

  1.  STATIC_OVL char *
  2.  doname_base(obj, doname_flags)
  3.  struct obj *obj;
  4.  unsigned doname_flags;
  5.  {
  6.      boolean ispoisoned = FALSE,
  7.              with_price = (doname_flags & DONAME_WITH_PRICE) != 0,
  8.              vague_quan = (doname_flags & DONAME_VAGUE_QUAN) != 0;
  9.      boolean known, dknown, cknown, bknown, lknown;
  10.      int omndx = obj->corpsenm;
  11.      char prefix[PREFIX];
  12.      char tmpbuf[PREFIX + 1]; /* for when we have to add something at
  13.                                  the start of prefix instead of the
  14.                                  end (Strcat is used on the end) */
  15.      register char *bp = xname(obj);
  16.  
  17.      if (iflags.override_ID) {
  18.          known = dknown = cknown = bknown = lknown = TRUE;
  19.      } else {
  20.          known = obj->known;
  21.          dknown = obj->dknown;
  22.          cknown = obj->cknown;
  23.          bknown = obj->bknown;
  24.          lknown = obj->lknown;
  25.      }
  26.  
  27.      /* When using xname, we want "poisoned arrow", and when using
  28.       * doname, we want "poisoned +0 arrow".  This kludge is about the only
  29.       * way to do it, at least until someone overhauls xname() and doname(),
  30.       * combining both into one function taking a parameter.
  31.       */
  32.      /* must check opoisoned--someone can have a weirdly-named fruit */
  33.      if (!strncmp(bp, "poisoned ", 9) && obj->opoisoned) {
  34.          bp += 9;
  35.          ispoisoned = TRUE;
  36.      }
  37.  
  38.      if (obj->quan != 1L) {
  39.          if (dknown || !vague_quan)
  40.              Sprintf(prefix, "%ld ", obj->quan);
  41.          else
  42.              Strcpy(prefix, "some ");
  43.      } else if (obj->otyp == CORPSE) {
  44.          /* skip article prefix for corpses [else corpse_xname()
  45.             would have to be taught how to strip it off again] */
  46.          *prefix = '\0';
  47.      } else if (obj_is_pname(obj) || the_unique_obj(obj)) {
  48.          if (!strncmpi(bp, "the ", 4))
  49.              bp += 4;
  50.          Strcpy(prefix, "the ");
  51.      } else {
  52.          Strcpy(prefix, "a ");
  53.      }
  54.  
  55.      /* "empty" goes at the beginning, but item count goes at the end */
  56.      if (cknown
  57.          /* bag of tricks: include "empty" prefix if it's known to
  58.             be empty but its precise number of charges isn't known
  59.             (when that is known, suffix of "(n:0)" will be appended,
  60.             making the prefix be redundant; note that 'known' flag
  61.             isn't set when emptiness gets discovered because then
  62.             charging magic would yield known number of new charges) */
  63.          && ((obj->otyp == BAG_OF_TRICKS)
  64.               ? (obj->spe == 0 && !obj->known)
  65.               /* not bag of tricks: empty if container which has no contents */
  66.               : ((Is_container(obj) || obj->otyp == STATUE)
  67.                  && !Has_contents(obj))))
  68.          Strcat(prefix, "empty ");
  69.  
  70.      if (bknown && obj->oclass != COIN_CLASS
  71.          && (obj->otyp != POT_WATER || !objects[POT_WATER].oc_name_known
  72.              || (!obj->cursed && !obj->blessed))) {
  73.          /* allow 'blessed clear potion' if we don't know it's holy water;
  74.           * always allow "uncursed potion of water"
  75.           */
  76.          if (obj->cursed)
  77.              Strcat(prefix, "cursed ");
  78.          else if (obj->blessed)
  79.              Strcat(prefix, "blessed ");
  80.          else if (!iflags.implicit_uncursed
  81.              /* For most items with charges or +/-, if you know how many
  82.               * charges are left or what the +/- is, then you must have
  83.               * totally identified the item, so "uncursed" is unnecessary,
  84.               * because an identified object not described as "blessed" or
  85.               * "cursed" must be uncursed.
  86.               *
  87.               * If the charges or +/- is not known, "uncursed" must be
  88.               * printed to avoid ambiguity between an item whose curse
  89.               * status is unknown, and an item known to be uncursed.
  90.               */
  91.                   || ((!known || !objects[obj->otyp].oc_charged
  92.                        || obj->oclass == ARMOR_CLASS
  93.                        || obj->oclass == RING_CLASS)
  94.  #ifdef MAIL
  95.                       && obj->otyp != SCR_MAIL
  96.  #endif
  97.                       && obj->otyp != FAKE_AMULET_OF_YENDOR
  98.                       && obj->otyp != AMULET_OF_YENDOR
  99.                       && !Role_if(PM_PRIEST)))
  100.              Strcat(prefix, "uncursed ");
  101.      }
  102.  
  103.      if (lknown && Is_box(obj)) {
  104.          if (obj->obroken)
  105.              /* 3.6.0 used "unlockable" here but that could be misunderstood
  106.                 to mean "capable of being unlocked" rather than the intended
  107.                 "not capable of being locked" */
  108.              Strcat(prefix, "broken ");
  109.          else if (obj->olocked)
  110.              Strcat(prefix, "locked ");
  111.          else
  112.              Strcat(prefix, "unlocked ");
  113.      }
  114.  
  115.      if (obj->greased)
  116.          Strcat(prefix, "greased ");
  117.  
  118.      if (cknown && Has_contents(obj)) {
  119.          /* we count the number of separate stacks, which corresponds
  120.             to the number of inventory slots needed to be able to take
  121.             everything out if no merges occur */
  122.          long itemcount = count_contents(obj, FALSE, FALSE, TRUE);
  123.  
  124.          Sprintf(eos(bp), " containing %ld item%s", itemcount,
  125.                  plur(itemcount));
  126.      }
  127.  
  128.      switch (is_weptool(obj) ? WEAPON_CLASS : obj->oclass) {
  129.      case AMULET_CLASS:
  130.          if (obj->owornmask & W_AMUL)
  131.              Strcat(bp, " (being worn)");
  132.          break;
  133.      case ARMOR_CLASS:
  134.          if (obj->owornmask & W_ARMOR)
  135.              Strcat(bp, (obj == uskin) ? " (embedded in your skin)"
  136.                                        : " (being worn)");
  137.          /*FALLTHRU*/
  138.      case WEAPON_CLASS:
  139.          if (ispoisoned)
  140.              Strcat(prefix, "poisoned ");
  141.          add_erosion_words(obj, prefix);
  142.          if (known) {
  143.              Strcat(prefix, sitoa(obj->spe));
  144.              Strcat(prefix, " ");
  145.          }
  146.          break;
  147.      case TOOL_CLASS:
  148.          if (obj->owornmask & (W_TOOL | W_SADDLE)) { /* blindfold */
  149.              Strcat(bp, " (being worn)");
  150.              break;
  151.          }
  152.          if (obj->otyp == LEASH && obj->leashmon != 0) {
  153.              struct monst *mlsh = find_mid(obj->leashmon, FM_FMON);
  154.  
  155.              if (!mlsh) {
  156.                  impossible("leashed monster not on this level");
  157.                  obj->leashmon = 0;
  158.              } else {
  159.                  Sprintf(eos(bp), " (attached to %s)",
  160.                          a_monnam(mlsh));
  161.              }
  162.              break;
  163.          }
  164.          if (obj->otyp == CANDELABRUM_OF_INVOCATION) {
  165.              if (!obj->spe)
  166.                  Strcpy(tmpbuf, "no");
  167.              else
  168.                  Sprintf(tmpbuf, "%d", obj->spe);
  169.              Sprintf(eos(bp), " (%s candle%s%s)", tmpbuf, plur(obj->spe),
  170.                      !obj->lamplit ? " attached" : ", lit");
  171.              break;
  172.          } else if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP
  173.                     || obj->otyp == BRASS_LANTERN || Is_candle(obj)) {
  174.              if (Is_candle(obj)
  175.                  && obj->age < 20L * (long) objects[obj->otyp].oc_cost)
  176.                  Strcat(prefix, "partly used ");
  177.              if (obj->lamplit)
  178.                  Strcat(bp, " (lit)");
  179.              break;
  180.          }
  181.          if (objects[obj->otyp].oc_charged)
  182.              goto charges;
  183.          break;
  184.      case WAND_CLASS:
  185.      charges:
  186.          if (known)
  187.              Sprintf(eos(bp), " (%d:%d)", (int) obj->recharged, obj->spe);
  188.          break;
  189.      case POTION_CLASS:
  190.          if (obj->otyp == POT_OIL && obj->lamplit)
  191.              Strcat(bp, " (lit)");
  192.          break;
  193.      case RING_CLASS:
  194.      ring:
  195.          if (obj->owornmask & W_RINGR)
  196.              Strcat(bp, " (on right ");
  197.          if (obj->owornmask & W_RINGL)
  198.              Strcat(bp, " (on left ");
  199.          if (obj->owornmask & W_RING) {
  200.              Strcat(bp, body_part(HAND));
  201.              Strcat(bp, ")");
  202.          }
  203.          if (known && objects[obj->otyp].oc_charged) {
  204.              Strcat(prefix, sitoa(obj->spe));
  205.              Strcat(prefix, " ");
  206.          }
  207.          break;
  208.      case FOOD_CLASS:
  209.          if (obj->oeaten)
  210.              Strcat(prefix, "partly eaten ");
  211.          if (obj->otyp == CORPSE) {
  212.              /* (quan == 1) => want corpse_xname() to supply article,
  213.                 (quan != 1) => already have count or "some" as prefix;
  214.                 "corpse" is already in the buffer returned by xname() */
  215.              unsigned cxarg = (((obj->quan != 1L) ? 0 : CXN_ARTICLE)
  216.                                | CXN_NOCORPSE);
  217.              char *cxstr = corpse_xname(obj, prefix, cxarg);
  218.  
  219.              Sprintf(prefix, "%s ", cxstr);
  220.              /* avoid having doname(corpse) consume an extra obuf */
  221.              releaseobuf(cxstr);
  222.          } else if (obj->otyp == EGG) {
  223.  #if 0 /* corpses don't tell if they're stale either */
  224.              if (known && stale_egg(obj))
  225.                  Strcat(prefix, "stale ");
  226.  #endif
  227.              if (omndx >= LOW_PM
  228.                  && (known || (mvitals[omndx].mvflags & MV_KNOWS_EGG))) {
  229.                  Strcat(prefix, mons[omndx].mname);
  230.                  Strcat(prefix, " ");
  231.                  if (obj->spe)
  232.                      Strcat(bp, " (laid by you)");
  233.              }
  234.          }
  235.          if (obj->otyp == MEAT_RING)
  236.              goto ring;
  237.          break;
  238.      case BALL_CLASS:
  239.      case CHAIN_CLASS:
  240.          add_erosion_words(obj, prefix);
  241.          if (obj->owornmask & W_BALL)
  242.              Strcat(bp, " (chained to you)");
  243.          break;
  244.      }
  245.  
  246.      if ((obj->owornmask & W_WEP) && !mrg_to_wielded) {
  247.          if (obj->quan != 1L) {
  248.              Strcat(bp, " (wielded)");
  249.          } else {
  250.              const char *hand_s = body_part(HAND);
  251.  
  252.              if (bimanual(obj))
  253.                  hand_s = makeplural(hand_s);
  254.              Sprintf(eos(bp), " (weapon in %s)", hand_s);
  255.  
  256.              if (warn_obj_cnt && obj == uwep && (EWarn_of_mon & W_WEP) != 0L) {
  257.                  /* presumably can be felt when blind */
  258.                  Strcat(bp, " (glowing");
  259.                  if (!Blind)
  260.                      Sprintf(eos(bp), " %s", glow_color(obj->oartifact));
  261.                  Strcat(bp, ")");
  262.              }
  263.          }
  264.      }
  265.      if (obj->owornmask & W_SWAPWEP) {
  266.          if (u.twoweap)
  267.              Sprintf(eos(bp), " (wielded in other %s)", body_part(HAND));
  268.          else
  269.              Strcat(bp, " (alternate weapon; not wielded)");
  270.      }
  271.      if (obj->owornmask & W_QUIVER) {
  272.          switch (obj->oclass) {
  273.          case WEAPON_CLASS:
  274.              if (is_ammo(obj)) {
  275.                  if (objects[obj->otyp].oc_skill == -P_BOW) {
  276.                      /* Ammo for a bow */
  277.                      Strcat(bp, " (in quiver)");
  278.                      break;
  279.                  } else {
  280.                      /* Ammo not for a bow */
  281.                      Strcat(bp, " (in quiver pouch)");
  282.                      break;
  283.                  }
  284.              } else {
  285.                  /* Weapons not considered ammo */
  286.                  Strcat(bp, " (at the ready)");
  287.                  break;
  288.              }
  289.          /* Small things and ammo not for a bow */
  290.          case RING_CLASS:
  291.          case AMULET_CLASS:
  292.          case WAND_CLASS:
  293.          case COIN_CLASS:
  294.          case GEM_CLASS:
  295.              Strcat(bp, " (in quiver pouch)");
  296.              break;
  297.          default: /* odd things */
  298.              Strcat(bp, " (at the ready)");
  299.          }
  300.      }
  301.      if (!iflags.suppress_price && is_unpaid(obj)) {
  302.          long quotedprice = unpaid_cost(obj, TRUE);
  303.  
  304.          Sprintf(eos(bp), " (%s, %ld %s)",
  305.                  obj->unpaid ? "unpaid" : "contents",
  306.                  quotedprice, currency(quotedprice));
  307.      } else if (with_price) {
  308.          long price = get_cost_of_shop_item(obj);
  309.  
  310.          if (price > 0)
  311.              Sprintf(eos(bp), " (%ld %s)", price, currency(price));
  312.      }
  313.      if (!strncmp(prefix, "a ", 2)
  314.          && index(vowels, *(prefix + 2) ? *(prefix + 2) : *bp)
  315.          && (*(prefix + 2)
  316.              || (strncmp(bp, "uranium", 7) && strncmp(bp, "unicorn", 7)
  317.                  && strncmp(bp, "eucalyptus", 10)))) {
  318.          Strcpy(tmpbuf, prefix);
  319.          Strcpy(prefix, "an ");
  320.          Strcpy(prefix + 3, tmpbuf + 2);
  321.      }
  322.  
  323.      /* show weight for items (debug tourist info)
  324.       * aum is stolen from Crawl's "Arbitrary Unit of Measure" */
  325.      if (wizard && iflags.wizweight) {
  326.          Sprintf(eos(bp), " (%d aum)", obj->owt);
  327.      }
  328.      bp = strprepend(bp, prefix);
  329.      return bp;
  330.  }
  331.  

doname

  1.  char *
  2.  doname(obj)
  3.  struct obj *obj;
  4.  {
  5.      return doname_base(obj, (unsigned) 0);
  6.  }
  7.  

doname_with_price

  1.  /* Name of object including price. */
  2.  char *
  3.  doname_with_price(obj)
  4.  struct obj *obj;
  5.  {
  6.      return doname_base(obj, DONAME_WITH_PRICE);
  7.  }
  8.  

doname_vague_quan

  1.  /* "some" instead of precise quantity if obj->dknown not set */
  2.  char *
  3.  doname_vague_quan(obj)
  4.  struct obj *obj;
  5.  {
  6.      /* Used by farlook.
  7.       * If it hasn't been seen up close and quantity is more than one,
  8.       * use "some" instead of the quantity: "some gold pieces" rather
  9.       * than "25 gold pieces".  This is suboptimal, to put it mildly,
  10.       * because lookhere and pickup report the precise amount.
  11.       * Picking the item up while blind also shows the precise amount
  12.       * for inventory display, then dropping it while still blind leaves
  13.       * obj->dknown unset so the count reverts to "some" for farlook.
  14.       *
  15.       * TODO: add obj->qknown flag for 'quantity known' on stackable
  16.       * items; it could overlay obj->cknown since no containers stack.
  17.       */
  18.      return doname_base(obj, DONAME_VAGUE_QUAN);
  19.  }
  20.  

not_fully_identified

  1.  /* used from invent.c */
  2.  boolean
  3.  not_fully_identified(otmp)
  4.  struct obj *otmp;
  5.  {
  6.      /* gold doesn't have any interesting attributes [yet?] */
  7.      if (otmp->oclass == COIN_CLASS)
  8.          return FALSE; /* always fully ID'd */
  9.      /* check fundamental ID hallmarks first */
  10.      if (!otmp->known || !otmp->dknown
  11.  #ifdef MAIL
  12.          || (!otmp->bknown && otmp->otyp != SCR_MAIL)
  13.  #else
  14.          || !otmp->bknown
  15.  #endif
  16.          || !objects[otmp->otyp].oc_name_known)
  17.          return TRUE;
  18.      if ((!otmp->cknown && (Is_container(otmp) || otmp->otyp == STATUE))
  19.          || (!otmp->lknown && Is_box(otmp)))
  20.          return TRUE;
  21.      if (otmp->oartifact && undiscovered_artifact(otmp->oartifact))
  22.          return TRUE;
  23.      /* otmp->rknown is the only item of interest if we reach here */
  24.      /*
  25.       *  Note:  if a revision ever allows scrolls to become fireproof or
  26.       *  rings to become shockproof, this checking will need to be revised.
  27.       *  `rknown' ID only matters if xname() will provide the info about it.
  28.       */
  29.      if (otmp->rknown
  30.          || (otmp->oclass != ARMOR_CLASS && otmp->oclass != WEAPON_CLASS
  31.              && !is_weptool(otmp)            /* (redundant) */
  32.              && otmp->oclass != BALL_CLASS)) /* (useless) */
  33.          return FALSE;
  34.      else /* lack of `rknown' only matters for vulnerable objects */
  35.          return (boolean) (is_rustprone(otmp) || is_corrodeable(otmp)
  36.                            || is_flammable(otmp));
  37.  }
  38.  

corpse_xname

  1.  /* format a corpse name (xname() omits monster type; doname() calls us);
  2.     eatcorpse() also uses us for death reason when eating tainted glob */
  3.  char *
  4.  corpse_xname(otmp, adjective, cxn_flags)
  5.  struct obj *otmp;
  6.  const char *adjective;
  7.  unsigned cxn_flags; /* bitmask of CXN_xxx values */
  8.  {
  9.      char *nambuf = nextobuf();
  10.      int omndx = otmp->corpsenm;
  11.      boolean ignore_quan = (cxn_flags & CXN_SINGULAR) != 0,
  12.              /* suppress "the" from "the unique monster corpse" */
  13.          no_prefix = (cxn_flags & CXN_NO_PFX) != 0,
  14.              /* include "the" for "the woodchuck corpse */
  15.          the_prefix = (cxn_flags & CXN_PFX_THE) != 0,
  16.              /* include "an" for "an ogre corpse */
  17.          any_prefix = (cxn_flags & CXN_ARTICLE) != 0,
  18.              /* leave off suffix (do_name() appends "corpse" itself) */
  19.          omit_corpse = (cxn_flags & CXN_NOCORPSE) != 0,
  20.          possessive = FALSE,
  21.          glob = (otmp->otyp != CORPSE && otmp->globby);
  22.      const char *mname;
  23.  
  24.      if (glob) {
  25.          mname = OBJ_NAME(objects[otmp->otyp]); /* "glob of <monster>" */
  26.      } else if (omndx == NON_PM) { /* paranoia */
  27.          mname = "thing";
  28.          /* [Possible enhancement:  check whether corpse has monster traits
  29.              attached in order to use priestname() for priests and minions.] */
  30.      } else if (omndx == PM_ALIGNED_PRIEST) {
  31.          /* avoid "aligned priest"; it just exposes internal details */
  32.          mname = "priest";
  33.      } else {
  34.          mname = mons[omndx].mname;
  35.          if (the_unique_pm(&mons[omndx]) || type_is_pname(&mons[omndx])) {
  36.              mname = s_suffix(mname);
  37.              possessive = TRUE;
  38.              /* don't precede personal name like "Medusa" with an article */
  39.              if (type_is_pname(&mons[omndx]))
  40.                  no_prefix = TRUE;
  41.              /* always precede non-personal unique monster name like
  42.                 "Oracle" with "the" unless explicitly overridden */
  43.              else if (the_unique_pm(&mons[omndx]) && !no_prefix)
  44.                  the_prefix = TRUE;
  45.          }
  46.      }
  47.      if (no_prefix)
  48.          the_prefix = any_prefix = FALSE;
  49.      else if (the_prefix)
  50.          any_prefix = FALSE; /* mutually exclusive */
  51.  
  52.      *nambuf = '\0';
  53.      /* can't use the() the way we use an() below because any capitalized
  54.         Name causes it to assume a personal name and return Name as-is;
  55.         that's usually the behavior wanted, but here we need to force "the"
  56.         to precede capitalized unique monsters (pnames are handled above) */
  57.      if (the_prefix)
  58.          Strcat(nambuf, "the ");
  59.  
  60.      if (!adjective || !*adjective) {
  61.          /* normal case:  newt corpse */
  62.          Strcat(nambuf, mname);
  63.      } else {
  64.          /* adjective positioning depends upon format of monster name */
  65.          if (possessive) /* Medusa's cursed partly eaten corpse */
  66.              Sprintf(eos(nambuf), "%s %s", mname, adjective);
  67.          else /* cursed partly eaten troll corpse */
  68.              Sprintf(eos(nambuf), "%s %s", adjective, mname);
  69.          /* in case adjective has a trailing space, squeeze it out */
  70.          mungspaces(nambuf);
  71.          /* doname() might include a count in the adjective argument;
  72.             if so, don't prepend an article */
  73.          if (digit(*adjective))
  74.              any_prefix = FALSE;
  75.      }
  76.  
  77.      if (glob) {
  78.          ; /* omit_corpse doesn't apply; quantity is always 1 */
  79.      } else if (!omit_corpse) {
  80.          Strcat(nambuf, " corpse");
  81.          /* makeplural(nambuf) => append "s" to "corpse" */
  82.          if (otmp->quan > 1L && !ignore_quan) {
  83.              Strcat(nambuf, "s");
  84.              any_prefix = FALSE; /* avoid "a newt corpses" */
  85.          }
  86.      }
  87.  
  88.      /* it's safe to overwrite our nambuf after an() has copied
  89.         its old value into another buffer */
  90.      if (any_prefix)
  91.          Strcpy(nambuf, an(nambuf));
  92.  
  93.      return nambuf;
  94.  }
  95.  

cxname

  1.  /* xname doesn't include monster type for "corpse"; cxname does */
  2.  char *
  3.  cxname(obj)
  4.  struct obj *obj;
  5.  {
  6.      if (obj->otyp == CORPSE)
  7.          return corpse_xname(obj, (const char *) 0, CXN_NORMAL);
  8.      return xname(obj);
  9.  }
  10.  

cxname_singular

  1.  /* like cxname, but ignores quantity */
  2.  char *
  3.  cxname_singular(obj)
  4.  struct obj *obj;
  5.  {
  6.      if (obj->otyp == CORPSE)
  7.          return corpse_xname(obj, (const char *) 0, CXN_SINGULAR);
  8.      return xname_flags(obj, CXN_SINGULAR);
  9.  }
  10.  

killer_xname

  1.  /* treat an object as fully ID'd when it might be used as reason for death */
  2.  char *
  3.  killer_xname(obj)
  4.  struct obj *obj;
  5.  {
  6.      struct obj save_obj;
  7.      unsigned save_ocknown;
  8.      char *buf, *save_ocuname, *save_oname = (char *) 0;
  9.  
  10.      /* bypass object twiddling for artifacts */
  11.      if (obj->oartifact)
  12.          return bare_artifactname(obj);
  13.  
  14.      /* remember original settings for core of the object;
  15.         oextra structs other than oname don't matter here--since they
  16.         aren't modified they don't need to be saved and restored */
  17.      save_obj = *obj;
  18.      if (has_oname(obj))
  19.          save_oname = ONAME(obj);
  20.  
  21.      /* killer name should be more specific than general xname; however, exact
  22.         info like blessed/cursed and rustproof makes things be too verbose */
  23.      obj->known = obj->dknown = 1;
  24.      obj->bknown = obj->rknown = obj->greased = 0;
  25.      /* if character is a priest[ess], bknown will get toggled back on */
  26.      if (obj->otyp != POT_WATER)
  27.          obj->blessed = obj->cursed = 0;
  28.      else
  29.          obj->bknown = 1; /* describe holy/unholy water as such */
  30.      /* "killed by poisoned <obj>" would be misleading when poison is
  31.         not the cause of death and "poisoned by poisoned <obj>" would
  32.         be redundant when it is, so suppress "poisoned" prefix */
  33.      obj->opoisoned = 0;
  34.      /* strip user-supplied name; artifacts keep theirs */
  35.      if (!obj->oartifact && save_oname)
  36.          ONAME(obj) = (char *) 0;
  37.      /* temporarily identify the type of object */
  38.      save_ocknown = objects[obj->otyp].oc_name_known;
  39.      objects[obj->otyp].oc_name_known = 1;
  40.      save_ocuname = objects[obj->otyp].oc_uname;
  41.      objects[obj->otyp].oc_uname = 0; /* avoid "foo called bar" */
  42.  
  43.      /* format the object */
  44.      if (obj->otyp == CORPSE) {
  45.          buf = nextobuf();
  46.          Strcpy(buf, corpse_xname(obj, (const char *) 0, CXN_NORMAL));
  47.      } else if (obj->otyp == SLIME_MOLD) {
  48.          /* concession to "most unique deaths competition" in the annual
  49.             devnull tournament, suppress player supplied fruit names because
  50.             those can be used to fake other objects and dungeon features */
  51.          buf = nextobuf();
  52.          Sprintf(buf, "deadly slime mold%s", plur(obj->quan));
  53.      } else {
  54.          buf = xname(obj);
  55.      }
  56.      /* apply an article if appropriate; caller should always use KILLED_BY */
  57.      if (obj->quan == 1L && !strstri(buf, "'s ") && !strstri(buf, "s' "))
  58.          buf = (obj_is_pname(obj) || the_unique_obj(obj)) ? the(buf) : an(buf);
  59.  
  60.      objects[obj->otyp].oc_name_known = save_ocknown;
  61.      objects[obj->otyp].oc_uname = save_ocuname;
  62.      *obj = save_obj; /* restore object's core settings */
  63.      if (!obj->oartifact && save_oname)
  64.          ONAME(obj) = save_oname;
  65.  
  66.      return buf;
  67.  }
  68.  

short_oname

  1.  /* xname,doname,&c with long results reformatted to omit some stuff */
  2.  char *
  3.  short_oname(obj, func, altfunc, lenlimit)
  4.  struct obj *obj;
  5.  char *FDECL((*func), (OBJ_P)),    /* main formatting routine */
  6.       *FDECL((*altfunc), (OBJ_P)); /* alternate for shortest result */
  7.  unsigned lenlimit;
  8.  {
  9.      struct obj save_obj;
  10.      char unamebuf[12], onamebuf[12], *save_oname, *save_uname, *outbuf;
  11.  
  12.      outbuf = (*func)(obj);
  13.      if ((unsigned) strlen(outbuf) <= lenlimit)
  14.          return outbuf;
  15.  
  16.      /* shorten called string to fairly small amount */
  17.      save_uname = objects[obj->otyp].oc_uname;
  18.      if (save_uname && strlen(save_uname) >= sizeof unamebuf) {
  19.          (void) strncpy(unamebuf, save_uname, sizeof unamebuf - 4);
  20.          Strcpy(unamebuf + sizeof unamebuf - 4, "...");
  21.          objects[obj->otyp].oc_uname = unamebuf;
  22.          releaseobuf(outbuf);
  23.          outbuf = (*func)(obj);
  24.          objects[obj->otyp].oc_uname = save_uname; /* restore called string */
  25.          if ((unsigned) strlen(outbuf) <= lenlimit)
  26.              return outbuf;
  27.      }
  28.  
  29.      /* shorten named string to fairly small amount */
  30.      save_oname = has_oname(obj) ? ONAME(obj) : 0;
  31.      if (save_oname && strlen(save_oname) >= sizeof onamebuf) {
  32.          (void) strncpy(onamebuf, save_oname, sizeof onamebuf - 4);
  33.          Strcpy(onamebuf + sizeof onamebuf - 4, "...");
  34.          ONAME(obj) = onamebuf;
  35.          releaseobuf(outbuf);
  36.          outbuf = (*func)(obj);
  37.          ONAME(obj) = save_oname; /* restore named string */
  38.          if ((unsigned) strlen(outbuf) <= lenlimit)
  39.              return outbuf;
  40.      }
  41.  
  42.      /* shorten both called and named strings;
  43.         unamebuf and onamebuf have both already been populated */
  44.      if (save_uname && strlen(save_uname) >= sizeof unamebuf && save_oname
  45.          && strlen(save_oname) >= sizeof onamebuf) {
  46.          objects[obj->otyp].oc_uname = unamebuf;
  47.          ONAME(obj) = onamebuf;
  48.          releaseobuf(outbuf);
  49.          outbuf = (*func)(obj);
  50.          if ((unsigned) strlen(outbuf) <= lenlimit) {
  51.              objects[obj->otyp].oc_uname = save_uname;
  52.              ONAME(obj) = save_oname;
  53.              return outbuf;
  54.          }
  55.      }
  56.  
  57.      /* still long; strip several name-lengthening attributes;
  58.         called and named strings are still in truncated form */
  59.      save_obj = *obj;
  60.      obj->bknown = obj->rknown = obj->greased = 0;
  61.      obj->oeroded = obj->oeroded2 = 0;
  62.      releaseobuf(outbuf);
  63.      outbuf = (*func)(obj);
  64.      if (altfunc && (unsigned) strlen(outbuf) > lenlimit) {
  65.          /* still long; use the alternate function (usually one of
  66.             the jackets around minimal_xname()) */
  67.          releaseobuf(outbuf);
  68.          outbuf = (*altfunc)(obj);
  69.      }
  70.      /* restore the object */
  71.      *obj = save_obj;
  72.      if (save_oname)
  73.          ONAME(obj) = save_oname;
  74.      if (save_uname)
  75.          objects[obj->otyp].oc_uname = save_uname;
  76.  
  77.      /* use whatever we've got, whether it's too long or not */
  78.      return outbuf;
  79.  }
  80.  

singular

  1.  /*
  2.   * Used if only one of a collection of objects is named (e.g. in eat.c).
  3.   */
  4.  const char *
  5.  singular(otmp, func)
  6.  register struct obj *otmp;
  7.  char *FDECL((*func), (OBJ_P));
  8.  {
  9.      long savequan;
  10.      char *nam;
  11.  
  12.      /* using xname for corpses does not give the monster type */
  13.      if (otmp->otyp == CORPSE && func == xname)
  14.          func = cxname;
  15.  
  16.      savequan = otmp->quan;
  17.      otmp->quan = 1L;
  18.      nam = (*func)(otmp);
  19.      otmp->quan = savequan;
  20.      return nam;
  21.  }
  22.  

an

  1.  char *
  2.  an(str)
  3.  register const char *str;
  4.  {
  5.      char *buf = nextobuf();
  6.  
  7.      buf[0] = '\0';
  8.  
  9.      if (strncmpi(str, "the ", 4) && strcmp(str, "molten lava")
  10.          && strcmp(str, "iron bars") && strcmp(str, "ice")) {
  11.          if (index(vowels, *str) && strncmp(str, "one-", 4)
  12.              && strncmp(str, "useful", 6) && strncmp(str, "unicorn", 7)
  13.              && strncmp(str, "uranium", 7) && strncmp(str, "eucalyptus", 10))
  14.              Strcpy(buf, "an ");
  15.          else
  16.              Strcpy(buf, "a ");
  17.      }
  18.  
  19.      Strcat(buf, str);
  20.      return buf;
  21.  }
  22.  

An

  1.  char *
  2.  An(str)
  3.  const char *str;
  4.  {
  5.      char *tmp = an(str);
  6.  
  7.      *tmp = highc(*tmp);
  8.      return tmp;
  9.  }
  10.  

the

  1.  /*
  2.   * Prepend "the" if necessary; assumes str is a subject derived from xname.
  3.   * Use type_is_pname() for monster names, not the().  the() is idempotent.
  4.   */
  5.  char *
  6.  the(str)
  7.  const char *str;
  8.  {
  9.      char *buf = nextobuf();
  10.      boolean insert_the = FALSE;
  11.  
  12.      if (!strncmpi(str, "the ", 4)) {
  13.          buf[0] = lowc(*str);
  14.          Strcpy(&buf[1], str + 1);
  15.          return buf;
  16.      } else if (*str < 'A' || *str > 'Z'
  17.                 /* treat named fruit as not a proper name, even if player
  18.                    has assigned a capitalized proper name as his/her fruit */
  19.                 || fruit_from_name(str, TRUE, (int *) 0)) {
  20.          /* not a proper name, needs an article */
  21.          insert_the = TRUE;
  22.      } else {
  23.          /* Probably a proper name, might not need an article */
  24.          register char *tmp, *named, *called;
  25.          int l;
  26.  
  27.          /* some objects have capitalized adjectives in their names */
  28.          if (((tmp = rindex(str, ' ')) != 0 || (tmp = rindex(str, '-')) != 0)
  29.              && (tmp[1] < 'A' || tmp[1] > 'Z')) {
  30.              insert_the = TRUE;
  31.          } else if (tmp && index(str, ' ') < tmp) { /* has spaces */
  32.              /* it needs an article if the name contains "of" */
  33.              tmp = strstri(str, " of ");
  34.              named = strstri(str, " named ");
  35.              called = strstri(str, " called ");
  36.              if (called && (!named || called < named))
  37.                  named = called;
  38.  
  39.              if (tmp && (!named || tmp < named)) /* found an "of" */
  40.                  insert_the = TRUE;
  41.              /* stupid special case: lacks "of" but needs "the" */
  42.              else if (!named && (l = strlen(str)) >= 31
  43.                       && !strcmp(&str[l - 31],
  44.                                  "Platinum Yendorian Express Card"))
  45.                  insert_the = TRUE;
  46.          }
  47.      }
  48.      if (insert_the)
  49.          Strcpy(buf, "the ");
  50.      else
  51.          buf[0] = '\0';
  52.      Strcat(buf, str);
  53.  
  54.      return buf;
  55.  }
  56.  

The

  1.  char *
  2.  The(str)
  3.  const char *str;
  4.  {
  5.      char *tmp = the(str);
  6.  
  7.      *tmp = highc(*tmp);
  8.      return tmp;
  9.  }
  10.  

aobjnam

  1.  /* returns "count cxname(otmp)" or just cxname(otmp) if count == 1 */
  2.  char *
  3.  aobjnam(otmp, verb)
  4.  struct obj *otmp;
  5.  const char *verb;
  6.  {
  7.      char prefix[PREFIX];
  8.      char *bp = cxname(otmp);
  9.  
  10.      if (otmp->quan != 1L) {
  11.          Sprintf(prefix, "%ld ", otmp->quan);
  12.          bp = strprepend(bp, prefix);
  13.      }
  14.      if (verb) {
  15.          Strcat(bp, " ");
  16.          Strcat(bp, otense(otmp, verb));
  17.      }
  18.      return bp;
  19.  }
  20.  

yobjnam

  1.  /* combine yname and aobjnam eg "your count cxname(otmp)" */
  2.  char *
  3.  yobjnam(obj, verb)
  4.  struct obj *obj;
  5.  const char *verb;
  6.  {
  7.      char *s = aobjnam(obj, verb);
  8.  
  9.      /* leave off "your" for most of your artifacts, but prepend
  10.       * "your" for unique objects and "foo of bar" quest artifacts */
  11.      if (!carried(obj) || !obj_is_pname(obj)
  12.          || obj->oartifact >= ART_ORB_OF_DETECTION) {
  13.          char *outbuf = shk_your(nextobuf(), obj);
  14.          int space_left = BUFSZ - 1 - strlen(outbuf);
  15.  
  16.          s = strncat(outbuf, s, space_left);
  17.      }
  18.      return s;
  19.  }
  20.  

Yobjnam2

  1.  /* combine Yname2 and aobjnam eg "Your count cxname(otmp)" */
  2.  char *
  3.  Yobjnam2(obj, verb)
  4.  struct obj *obj;
  5.  const char *verb;
  6.  {
  7.      register char *s = yobjnam(obj, verb);
  8.  
  9.      *s = highc(*s);
  10.      return s;
  11.  }
  12.  

Tobjnam

  1.  /* like aobjnam, but prepend "The", not count, and use xname */
  2.  char *
  3.  Tobjnam(otmp, verb)
  4.  struct obj *otmp;
  5.  const char *verb;
  6.  {
  7.      char *bp = The(xname(otmp));
  8.  
  9.      if (verb) {
  10.          Strcat(bp, " ");
  11.          Strcat(bp, otense(otmp, verb));
  12.      }
  13.      return bp;
  14.  }
  15.  

Doname2

  1.  /* capitalized variant of doname() */
  2.  char *
  3.  Doname2(obj)
  4.  struct obj *obj;
  5.  {
  6.      char *s = doname(obj);
  7.  
  8.      *s = highc(*s);
  9.      return s;
  10.  }
  11.  

yname

  1.  /* returns "[your ]xname(obj)" or "Foobar's xname(obj)" or "the xname(obj)" */
  2.  char *
  3.  yname(obj)
  4.  struct obj *obj;
  5.  {
  6.      char *s = cxname(obj);
  7.  
  8.      /* leave off "your" for most of your artifacts, but prepend
  9.       * "your" for unique objects and "foo of bar" quest artifacts */
  10.      if (!carried(obj) || !obj_is_pname(obj)
  11.          || obj->oartifact >= ART_ORB_OF_DETECTION) {
  12.          char *outbuf = shk_your(nextobuf(), obj);
  13.          int space_left = BUFSZ - 1 - strlen(outbuf);
  14.  
  15.          s = strncat(outbuf, s, space_left);
  16.      }
  17.  
  18.      return s;
  19.  }
  20.  

Yname2

  1.  /* capitalized variant of yname() */
  2.  char *
  3.  Yname2(obj)
  4.  struct obj *obj;
  5.  {
  6.      char *s = yname(obj);
  7.  
  8.      *s = highc(*s);
  9.      return s;
  10.  }
  11.  

ysimple_name

  1.  /* returns "your minimal_xname(obj)"
  2.   * or "Foobar's minimal_xname(obj)"
  3.   * or "the minimal_xname(obj)"
  4.   */
  5.  char *
  6.  ysimple_name(obj)
  7.  struct obj *obj;
  8.  {
  9.      char *outbuf = nextobuf();
  10.      char *s = shk_your(outbuf, obj); /* assert( s == outbuf ); */
  11.      int space_left = BUFSZ - 1 - strlen(s);
  12.  
  13.      return strncat(s, minimal_xname(obj), space_left);
  14.  }
  15.  

Ysimple_name2

  1.  /* capitalized variant of ysimple_name() */
  2.  char *
  3.  Ysimple_name2(obj)
  4.  struct obj *obj;
  5.  {
  6.      char *s = ysimple_name(obj);
  7.  
  8.      *s = highc(*s);
  9.      return s;
  10.  }
  11.  

simpleonames

  1.  /* "scroll" or "scrolls" */
  2.  char *
  3.  simpleonames(obj)
  4.  struct obj *obj;
  5.  {
  6.      char *simpleoname = minimal_xname(obj);
  7.  
  8.      if (obj->quan != 1L)
  9.          simpleoname = makeplural(simpleoname);
  10.      return simpleoname;
  11.  }
  12.  

ansimpleoname

  1.  /* "a scroll" or "scrolls"; "a silver bell" or "the Bell of Opening" */
  2.  char *
  3.  ansimpleoname(obj)
  4.  struct obj *obj;
  5.  {
  6.      char *simpleoname = simpleonames(obj);
  7.      int otyp = obj->otyp;
  8.  
  9.      /* prefix with "the" if a unique item, or a fake one imitating same,
  10.         has been formatted with its actual name (we let typename() handle
  11.         any `known' and `dknown' checking necessary) */
  12.      if (otyp == FAKE_AMULET_OF_YENDOR)
  13.          otyp = AMULET_OF_YENDOR;
  14.      if (objects[otyp].oc_unique
  15.          && !strcmp(simpleoname, OBJ_NAME(objects[otyp])))
  16.          return the(simpleoname);
  17.  
  18.      /* simpleoname is singular if quan==1, plural otherwise */
  19.      if (obj->quan == 1L)
  20.          simpleoname = an(simpleoname);
  21.      return simpleoname;
  22.  }
  23.  

thesimpleoname

  1.  /* "the scroll" or "the scrolls" */
  2.  char *
  3.  thesimpleoname(obj)
  4.  struct obj *obj;
  5.  {
  6.      char *simpleoname = simpleonames(obj);
  7.  
  8.      return the(simpleoname);
  9.  }
  10.  

bare_artifactname

  1.  /* artifact's name without any object type or known/dknown/&c feedback */
  2.  char *
  3.  bare_artifactname(obj)
  4.  struct obj *obj;
  5.  {
  6.      char *outbuf;
  7.  
  8.      if (obj->oartifact) {
  9.          outbuf = nextobuf();
  10.          Strcpy(outbuf, artiname(obj->oartifact));
  11.          if (!strncmp(outbuf, "The ", 4))
  12.              outbuf[0] = lowc(outbuf[0]);
  13.      } else {
  14.          outbuf = xname(obj);
  15.      }
  16.      return outbuf;
  17.  }
  18.  
  19.  static const char *wrp[] = {
  20.      "wand",   "ring",      "potion",     "scroll", "gem",
  21.      "amulet", "spellbook", "spell book",
  22.      /* for non-specific wishes */
  23.      "weapon", "armor",     "tool",       "food",   "comestible",
  24.  };
  25.  static const char wrpsym[] = { WAND_CLASS,   RING_CLASS,   POTION_CLASS,
  26.                                 SCROLL_CLASS, GEM_CLASS,    AMULET_CLASS,
  27.                                 SPBOOK_CLASS, SPBOOK_CLASS, WEAPON_CLASS,
  28.                                 ARMOR_CLASS,  TOOL_CLASS,   FOOD_CLASS,
  29.                                 FOOD_CLASS };
  30.  

otense

  1.  /* return form of the verb (input plural) if xname(otmp) were the subject */
  2.  char *
  3.  otense(otmp, verb)
  4.  struct obj *otmp;
  5.  const char *verb;
  6.  {
  7.      char *buf;
  8.  
  9.      /*
  10.       * verb is given in plural (without trailing s).  Return as input
  11.       * if the result of xname(otmp) would be plural.  Don't bother
  12.       * recomputing xname(otmp) at this time.
  13.       */
  14.      if (!is_plural(otmp))
  15.          return vtense((char *) 0, verb);
  16.  
  17.      buf = nextobuf();
  18.      Strcpy(buf, verb);
  19.      return buf;
  20.  }
  21.  
  22.  /* various singular words that vtense would otherwise categorize as plural;
  23.     also used by makesingular() to catch some special cases */
  24.  static const char *const special_subjs[] = {
  25.      "erinys",  "manes", /* this one is ambiguous */
  26.      "Cyclops", "Hippocrates",     "Pelias",    "aklys",
  27.      "amnesia", "detect monsters", "paralysis", "shape changers",
  28.      "nemesis", 0
  29.      /* note: "detect monsters" and "shape changers" are normally
  30.         caught via "<something>(s) of <whatever>", but they can be
  31.         wished for using the shorter form, so we include them here
  32.         to accommodate usage by makesingular during wishing */
  33.  };
  34.  

vtense

  1.  /* return form of the verb (input plural) for present tense 3rd person subj */
  2.  char *
  3.  vtense(subj, verb)
  4.  register const char *subj;
  5.  register const char *verb;
  6.  {
  7.      char *buf = nextobuf(), *bspot;
  8.      int len, ltmp;
  9.      const char *sp, *spot;
  10.      const char *const *spec;
  11.  
  12.      /*
  13.       * verb is given in plural (without trailing s).  Return as input
  14.       * if subj appears to be plural.  Add special cases as necessary.
  15.       * Many hard cases can already be handled by using otense() instead.
  16.       * If this gets much bigger, consider decomposing makeplural.
  17.       * Note: monster names are not expected here (except before corpse).
  18.       *
  19.       * Special case: allow null sobj to get the singular 3rd person
  20.       * present tense form so we don't duplicate this code elsewhere.
  21.       */
  22.      if (subj) {
  23.          if (!strncmpi(subj, "a ", 2) || !strncmpi(subj, "an ", 3))
  24.              goto sing;
  25.          spot = (const char *) 0;
  26.          for (sp = subj; (sp = index(sp, ' ')) != 0; ++sp) {
  27.              if (!strncmpi(sp, " of ", 4) || !strncmpi(sp, " from ", 6)
  28.                  || !strncmpi(sp, " called ", 8) || !strncmpi(sp, " named ", 7)
  29.                  || !strncmpi(sp, " labeled ", 9)) {
  30.                  if (sp != subj)
  31.                      spot = sp - 1;
  32.                  break;
  33.              }
  34.          }
  35.          len = (int) strlen(subj);
  36.          if (!spot)
  37.              spot = subj + len - 1;
  38.  
  39.          /*
  40.           * plural: anything that ends in 's', but not '*us' or '*ss'.
  41.           * Guess at a few other special cases that makeplural creates.
  42.           */
  43.          if ((lowc(*spot) == 's' && spot != subj
  44.               && !index("us", lowc(*(spot - 1))))
  45.              || !BSTRNCMPI(subj, spot - 3, "eeth", 4)
  46.              || !BSTRNCMPI(subj, spot - 3, "feet", 4)
  47.              || !BSTRNCMPI(subj, spot - 1, "ia", 2)
  48.              || !BSTRNCMPI(subj, spot - 1, "ae", 2)) {
  49.              /* check for special cases to avoid false matches */
  50.              len = (int) (spot - subj) + 1;
  51.              for (spec = special_subjs; *spec; spec++) {
  52.                  ltmp = strlen(*spec);
  53.                  if (len == ltmp && !strncmpi(*spec, subj, len))
  54.                      goto sing;
  55.                  /* also check for <prefix><space><special_subj>
  56.                     to catch things like "the invisible erinys" */
  57.                  if (len > ltmp && *(spot - ltmp) == ' '
  58.                      && !strncmpi(*spec, spot - ltmp + 1, ltmp))
  59.                      goto sing;
  60.              }
  61.  
  62.              return strcpy(buf, verb);
  63.          }
  64.          /*
  65.           * 3rd person plural doesn't end in telltale 's';
  66.           * 2nd person singular behaves as if plural.
  67.           */
  68.          if (!strcmpi(subj, "they") || !strcmpi(subj, "you"))
  69.              return strcpy(buf, verb);
  70.      }
  71.  
  72.  sing:
  73.      Strcpy(buf, verb);
  74.      len = (int) strlen(buf);
  75.      bspot = buf + len - 1;
  76.  
  77.      if (!strcmpi(buf, "are")) {
  78.          Strcasecpy(buf, "is");
  79.      } else if (!strcmpi(buf, "have")) {
  80.          Strcasecpy(bspot - 1, "s");
  81.      } else if (index("zxs", lowc(*bspot))
  82.                 || (len >= 2 && lowc(*bspot) == 'h'
  83.                     && index("cs", lowc(*(bspot - 1))))
  84.                 || (len == 2 && lowc(*bspot) == 'o')) {
  85.          /* Ends in z, x, s, ch, sh; add an "es" */
  86.          Strcasecpy(bspot + 1, "es");
  87.      } else if (lowc(*bspot) == 'y' && !index(vowels, lowc(*(bspot - 1)))) {
  88.          /* like "y" case in makeplural */
  89.          Strcasecpy(bspot, "ies");
  90.      } else {
  91.          Strcasecpy(bspot + 1, "s");
  92.      }
  93.  
  94.      return buf;
  95.  }
  96.  
  97.  struct sing_plur {
  98.      const char *sing, *plur;
  99.  };
  100.  
  101.  /* word pairs that don't fit into formula-based transformations;
  102.     also some suffices which have very few--often one--matches or
  103.     which aren't systematically reversible (knives, staves) */
  104.  static struct sing_plur one_off[] = {
  105.      { "child",
  106.        "children" },      /* (for wise guys who give their food funny names) */
  107.      { "cubus", "cubi" }, /* in-/suc-cubus */
  108.      { "culus", "culi" }, /* homunculus */
  109.      { "djinni", "djinn" },
  110.      { "erinys", "erinyes" },
  111.      { "foot", "feet" },
  112.      { "fungus", "fungi" },
  113.      { "goose", "geese" },
  114.      { "knife", "knives" },
  115.      { "labrum", "labra" }, /* candelabrum */
  116.      { "louse", "lice" },
  117.      { "mouse", "mice" },
  118.      { "mumak", "mumakil" },
  119.      { "nemesis", "nemeses" },
  120.      { "ovum", "ova" },
  121.      { "ox", "oxen" },
  122.      { "passerby", "passersby" },
  123.      { "rtex", "rtices" }, /* vortex */
  124.      { "serum", "sera" },
  125.      { "staff", "staves" },
  126.      { "tooth", "teeth" },
  127.      { 0, 0 }
  128.  };
  129.  
  130.  static const char *const as_is[] = {
  131.      /* makesingular() leaves these plural due to how they're used */
  132.      "boots",   "shoes",     "gloves",    "lenses",   "scales",
  133.      "eyes",    "gauntlets", "iron bars",
  134.      /* both singular and plural are spelled the same */
  135.      "bison",   "deer",      "elk",       "fish",      "fowl",
  136.      "tuna",    "yaki",      "-hai",      "krill",     "manes",
  137.      "moose",   "ninja",     "sheep",     "ronin",     "roshi",
  138.      "shito",   "tengu",     "ki-rin",    "Nazgul",    "gunyoki",
  139.      "piranha", "samurai",   "shuriken", 0,
  140.      /* Note:  "fish" and "piranha" are collective plurals, suitable
  141.         for "wiped out all <foo>".  For "3 <foo>", they should be
  142.         "fishes" and "piranhas" instead.  We settle for collective
  143.         variant instead of attempting to support both. */
  144.  };
  145.  

singplur_lookup

  1.  /* singularize/pluralize decisions common to both makesingular & makeplural */
  2.  STATIC_OVL boolean
  3.  singplur_lookup(basestr, endstring, to_plural, alt_as_is)
  4.  char *basestr, *endstring;    /* base string, pointer to eos(string) */
  5.  boolean to_plural;            /* true => makeplural, false => makesingular */
  6.  const char *const *alt_as_is; /* another set like as_is[] */
  7.  {
  8.      const struct sing_plur *sp;
  9.      const char *same, *other, *const *as;
  10.      int al;
  11.  
  12.      for (as = as_is; *as; ++as) {
  13.          al = (int) strlen(*as);
  14.          if (!BSTRCMPI(basestr, endstring - al, *as))
  15.              return TRUE;
  16.      }
  17.      if (alt_as_is) {
  18.          for (as = alt_as_is; *as; ++as) {
  19.              al = (int) strlen(*as);
  20.              if (!BSTRCMPI(basestr, endstring - al, *as))
  21.                  return TRUE;
  22.          }
  23.      }
  24.  
  25.      /* avoid false hit on one_off[].plur == "lice" or .sing == "goose";
  26.         if more of these turn up, one_off[] entries will need to flagged
  27.         as to which are whole words and which are matchable as suffices
  28.         then matching in the loop below will end up becoming more complex */
  29.      if (!strcmpi(basestr, "slice")
  30.          || !strcmpi(basestr, "mongoose")) {
  31.          if (to_plural)
  32.              Strcasecpy(endstring, "s");
  33.          return TRUE;
  34.      }
  35.      /* skip "ox" -> "oxen" entry when pluralizing "<something>ox"
  36.         unless it is muskox */
  37.      if (to_plural && strlen(basestr) > 2 && !strcmpi(endstring - 2, "ox")
  38.          && strcmpi(endstring - 6, "muskox")) {
  39.          /* "fox" -> "foxes" */
  40.          Strcasecpy(endstring, "es");
  41.          return TRUE;
  42.      }
  43.      if (to_plural) {
  44.          if (!strcmpi(endstring - 3, "man")
  45.              && badman(basestr, to_plural)) {
  46.              Strcasecpy(endstring, "s");
  47.              return TRUE;
  48.          }
  49.      } else {
  50.          if (!strcmpi(endstring - 3, "men")
  51.              && badman(basestr, to_plural))
  52.              return TRUE;
  53.      }
  54.      for (sp = one_off; sp->sing; sp++) {
  55.          /* check whether endstring already matches */
  56.          same = to_plural ? sp->plur : sp->sing;
  57.          al = (int) strlen(same);
  58.          if (!BSTRCMPI(basestr, endstring - al, same))
  59.              return TRUE; /* use as-is */
  60.          /* check whether it matches the inverse; if so, transform it */
  61.          other = to_plural ? sp->sing : sp->plur;
  62.          al = (int) strlen(other);
  63.          if (!BSTRCMPI(basestr, endstring - al, other)) {
  64.              Strcasecpy(endstring - al, same);
  65.              return TRUE; /* one_off[] transformation */
  66.          }
  67.      }
  68.      return FALSE;
  69.  }
  70.  

singplur_compound

  1.  /* searches for common compounds, ex. lump of royal jelly */
  2.  STATIC_OVL char *
  3.  singplur_compound(str)
  4.  char *str;
  5.  {
  6.      /* if new entries are added, be sure to keep compound_start[] in sync */
  7.      static const char *const compounds[] =
  8.          {
  9.            " of ",     " labeled ", " called ",
  10.            " named ",  " above", /* lurkers above */
  11.            " versus ", " from ",    " in ",
  12.            " on ",     " a la ",    " with", /* " with "? */
  13.            " de ",     " d'",       " du ",
  14.            "-in-",     "-at-",      0
  15.          }, /* list of first characters for all compounds[] entries */
  16.          compound_start[] = " -";
  17.  
  18.      const char *const *cmpd;
  19.      char *p;
  20.  
  21.      for (p = str; *p; ++p) {
  22.          /* substring starting at p can only match if *p is found
  23.             within compound_start[] */
  24.          if (!index(compound_start, *p))
  25.              continue;
  26.  
  27.          /* check current substring against all words in the compound[] list */
  28.          for (cmpd = compounds; *cmpd; ++cmpd)
  29.              if (!strncmpi(p, *cmpd, (int) strlen(*cmpd)))
  30.                  return p;
  31.      }
  32.      /* wasn't recognized as a compound phrase */
  33.      return 0;
  34.  }
  35.  

makeplural

  1.  /* Plural routine; once upon a time it may have been chiefly used for
  2.   * user-defined fruits, but it is now used extensively throughout the
  3.   * program.
  4.   *
  5.   * For fruit, we have to try to account for everything reasonable the
  6.   * player has; something unreasonable can still break the code.
  7.   * However, it's still a lot more accurate than "just add an 's' at the
  8.   * end", which Rogue uses...
  9.   *
  10.   * Also used for plural monster names ("Wiped out all homunculi." or the
  11.   * vanquished monsters list) and body parts.  A lot of unique monsters have
  12.   * names which get mangled by makeplural and/or makesingular.  They're not
  13.   * genocidable, and vanquished-mon handling does its own special casing
  14.   * (for uniques who've been revived and re-killed), so we don't bother
  15.   * trying to get those right here.
  16.   *
  17.   * Also misused by muse.c to convert 1st person present verbs to 2nd person.
  18.   * 3.6.0: made case-insensitive.
  19.   */
  20.  char *
  21.  makeplural(oldstr)
  22.  const char *oldstr;
  23.  {
  24.      register char *spot;
  25.      char lo_c, *str = nextobuf();
  26.      const char *excess = (char *) 0;
  27.      int len;
  28.  
  29.      if (oldstr)
  30.          while (*oldstr == ' ')
  31.              oldstr++;
  32.      if (!oldstr || !*oldstr) {
  33.          impossible("plural of null?");
  34.          Strcpy(str, "s");
  35.          return str;
  36.      }
  37.      Strcpy(str, oldstr);
  38.  
  39.      /*
  40.       * Skip changing "pair of" to "pairs of".  According to Webster, usual
  41.       * English usage is use pairs for humans, e.g. 3 pairs of dancers,
  42.       * and pair for objects and non-humans, e.g. 3 pair of boots.  We don't
  43.       * refer to pairs of humans in this game so just skip to the bottom.
  44.       */
  45.      if (!strncmpi(str, "pair of ", 8))
  46.          goto bottom;
  47.  
  48.      /* look for "foo of bar" so that we can focus on "foo" */
  49.      if ((spot = singplur_compound(str)) != 0) {
  50.          excess = oldstr + (int) (spot - str);
  51.          *spot = '\0';
  52.      } else
  53.          spot = eos(str);
  54.  
  55.      spot--;
  56.      while (spot > str && *spot == ' ')
  57.          spot--; /* Strip blanks from end */
  58.      *(spot + 1) = '\0';
  59.      /* Now spot is the last character of the string */
  60.  
  61.      len = strlen(str);
  62.  
  63.      /* Single letters */
  64.      if (len == 1 || !letter(*spot)) {
  65.          Strcpy(spot + 1, "'s");
  66.          goto bottom;
  67.      }
  68.  
  69.      /* dispense with some words which don't need pluralization */
  70.      {
  71.          static const char *const already_plural[] = {
  72.              "ae",  /* algae, larvae, &c */
  73.              "matzot", 0,
  74.          };
  75.  
  76.          /* spot+1: synch up with makesingular's usage */
  77.          if (singplur_lookup(str, spot + 1, TRUE, already_plural))
  78.              goto bottom;
  79.  
  80.          /* more of same, but not suitable for blanket loop checking */
  81.          if ((len == 2 && !strcmpi(str, "ya"))
  82.              || (len >= 3 && !strcmpi(spot - 2, " ya")))
  83.              goto bottom;
  84.      }
  85.  
  86.      /* man/men ("Wiped out all cavemen.") */
  87.      if (len >= 3 && !strcmpi(spot - 2, "man")
  88.          /* exclude shamans and humans etc */
  89.          && !badman(str, TRUE)) {
  90.          Strcasecpy(spot - 1, "en");
  91.          goto bottom;
  92.      }
  93.      if (lowc(*spot) == 'f') { /* (staff handled via one_off[]) */
  94.          lo_c = lowc(*(spot - 1));
  95.          if (len >= 3 && !strcmpi(spot - 2, "erf")) {
  96.              /* avoid "nerf" -> "nerves", "serf" -> "serves" */
  97.              ; /* fall through to default (append 's') */
  98.          } else if (index("lr", lo_c) || index(vowels, lo_c)) {
  99.              /* [aeioulr]f to [aeioulr]ves */
  100.              Strcasecpy(spot, "ves");
  101.              goto bottom;
  102.          }
  103.      }
  104.      /* ium/ia (mycelia, baluchitheria) */
  105.      if (len >= 3 && !strcmpi(spot - 2, "ium")) {
  106.          Strcasecpy(spot - 2, "ia");
  107.          goto bottom;
  108.      }
  109.      /* algae, larvae, hyphae (another fungus part) */
  110.      if ((len >= 4 && !strcmpi(spot - 3, "alga"))
  111.          || (len >= 5
  112.              && (!strcmpi(spot - 4, "hypha") || !strcmpi(spot - 4, "larva")))
  113.          || (len >= 6 && !strcmpi(spot - 5, "amoeba"))
  114.          || (len >= 8 && (!strcmpi(spot - 7, "vertebra")))) {
  115.          /* a to ae */
  116.          Strcasecpy(spot + 1, "e");
  117.          goto bottom;
  118.      }
  119.      /* fungus/fungi, homunculus/homunculi, but buses, lotuses, wumpuses */
  120.      if (len > 3 && !strcmpi(spot - 1, "us")
  121.          && !((len >= 5 && !strcmpi(spot - 4, "lotus"))
  122.               || (len >= 6 && !strcmpi(spot - 5, "wumpus")))) {
  123.          Strcasecpy(spot - 1, "i");
  124.          goto bottom;
  125.      }
  126.      /* sis/ses (nemesis) */
  127.      if (len >= 3 && !strcmpi(spot - 2, "sis")) {
  128.          Strcasecpy(spot - 1, "es");
  129.          goto bottom;
  130.      }
  131.      /* matzoh/matzot, possible food name */
  132.      if (len >= 6
  133.          && (!strcmpi(spot - 5, "matzoh") || !strcmpi(spot - 5, "matzah"))) {
  134.          Strcasecpy(spot - 1, "ot"); /* oh/ah -> ot */
  135.          goto bottom;
  136.      }
  137.      if (len >= 5
  138.          && (!strcmpi(spot - 4, "matzo") || !strcmpi(spot - 4, "matza"))) {
  139.          Strcasecpy(spot, "ot"); /* o/a -> ot */
  140.          goto bottom;
  141.      }
  142.  
  143.      /* note: -eau/-eaux (gateau, bordeau...) */
  144.      /* note: ox/oxen, VAX/VAXen, goose/geese */
  145.  
  146.      lo_c = lowc(*spot);
  147.  
  148.      /* Ends in z, x, s, ch, sh; add an "es" */
  149.      if (index("zxs", lo_c)
  150.          || (len >= 2 && lo_c == 'h' && index("cs", lowc(*(spot - 1))))
  151.          /* Kludge to get "tomatoes" and "potatoes" right */
  152.          || (len >= 4 && !strcmpi(spot - 2, "ato"))
  153.          || (len >= 5 && !strcmpi(spot - 4, "dingo"))) {
  154.          Strcasecpy(spot + 1, "es"); /* append es */
  155.          goto bottom;
  156.      }
  157.      /* Ends in y preceded by consonant (note: also "qu") change to "ies" */
  158.      if (lo_c == 'y' && !index(vowels, lowc(*(spot - 1)))) {
  159.          Strcasecpy(spot, "ies"); /* y -> ies */
  160.          goto bottom;
  161.      }
  162.      /* Default: append an 's' */
  163.      Strcasecpy(spot + 1, "s");
  164.  
  165.  bottom:
  166.      if (excess)
  167.          Strcat(str, excess);
  168.      return str;
  169.  }
  170.  

makesingular

  1.  /*
  2.   * Singularize a string the user typed in; this helps reduce the complexity
  3.   * of readobjnam, and is also used in pager.c to singularize the string
  4.   * for which help is sought.
  5.   *
  6.   * "Manes" is ambiguous: monster type (keep s), or horse body part (drop s)?
  7.   * Its inclusion in as_is[]/special_subj[] makes it get treated as the former.
  8.   *
  9.   * A lot of unique monsters have names ending in s; plural, or singular
  10.   * from plural, doesn't make much sense for them so we don't bother trying.
  11.   * 3.6.0: made case-insensitive.
  12.   */
  13.  char *
  14.  makesingular(oldstr)
  15.  const char *oldstr;
  16.  {
  17.      register char *p, *bp;
  18.      const char *excess = 0;
  19.      char *str = nextobuf();
  20.  
  21.      if (oldstr)
  22.          while (*oldstr == ' ')
  23.              oldstr++;
  24.      if (!oldstr || !*oldstr) {
  25.          impossible("singular of null?");
  26.          str[0] = '\0';
  27.          return str;
  28.      }
  29.  
  30.      bp = strcpy(str, oldstr);
  31.  
  32.      /* check for "foo of bar" so that we can focus on "foo" */
  33.      if ((p = singplur_compound(bp)) != 0) {
  34.          excess = oldstr + (int) (p - bp);
  35.          *p = '\0';
  36.      } else
  37.          p = eos(bp);
  38.  
  39.      /* dispense with some words which don't need singularization */
  40.      if (singplur_lookup(bp, p, FALSE, special_subjs))
  41.          goto bottom;
  42.  
  43.      /* remove -s or -es (boxes) or -ies (rubies) */
  44.      if (p >= bp + 1 && lowc(p[-1]) == 's') {
  45.          if (p >= bp + 2 && lowc(p[-2]) == 'e') {
  46.              if (p >= bp + 3 && lowc(p[-3]) == 'i') { /* "ies" */
  47.                  if (!BSTRCMPI(bp, p - 7, "cookies")
  48.                      || !BSTRCMPI(bp, p - 4, "pies")
  49.                      || !BSTRCMPI(bp, p - 5, "mbies") /* zombie */
  50.                      || !BSTRCMPI(bp, p - 5, "yries")) /* valkyrie */
  51.                      goto mins;
  52.                  Strcasecpy(p - 3, "y"); /* ies -> y */
  53.                  goto bottom;
  54.              }
  55.              /* wolves, but f to ves isn't fully reversible */
  56.              if (p - 4 >= bp && (index("lr", lowc(*(p - 4)))
  57.                                  || index(vowels, lowc(*(p - 4))))
  58.                  && !BSTRCMPI(bp, p - 3, "ves")) {
  59.                  if (!BSTRCMPI(bp, p - 6, "cloves")
  60.                      || !BSTRCMPI(bp, p - 6, "nerves"))
  61.                      goto mins;
  62.                  Strcasecpy(p - 3, "f"); /* ves -> f */
  63.                  goto bottom;
  64.              }
  65.              /* note: nurses, axes but boxes, wumpuses */
  66.              if (!BSTRCMPI(bp, p - 4, "eses")
  67.                  || !BSTRCMPI(bp, p - 4, "oxes") /* boxes, foxes */
  68.                  || !BSTRCMPI(bp, p - 4, "nxes") /* lynxes */
  69.                  || !BSTRCMPI(bp, p - 4, "ches")
  70.                  || !BSTRCMPI(bp, p - 4, "uses") /* lotuses */
  71.                  || !BSTRCMPI(bp, p - 4, "sses") /* priestesses */
  72.                  || !BSTRCMPI(bp, p - 5, "atoes") /* tomatoes */
  73.                  || !BSTRCMPI(bp, p - 7, "dingoes")
  74.                  || !BSTRCMPI(bp, p - 7, "Aleaxes")) {
  75.                  *(p - 2) = '\0'; /* drop es */
  76.                  goto bottom;
  77.              } /* else fall through to mins */
  78.  
  79.              /* ends in 's' but not 'es' */
  80.          } else if (!BSTRCMPI(bp, p - 2, "us")) { /* lotus, fungus... */
  81.              if (BSTRCMPI(bp, p - 6, "tengus") /* but not these... */
  82.                  && BSTRCMPI(bp, p - 7, "hezrous"))
  83.                  goto bottom;
  84.          } else if (!BSTRCMPI(bp, p - 2, "ss")
  85.                     || !BSTRCMPI(bp, p - 5, " lens")
  86.                     || (p - 4 == bp && !strcmpi(p - 4, "lens"))) {
  87.              goto bottom;
  88.          }
  89.      mins:
  90.          *(p - 1) = '\0'; /* drop s */
  91.  
  92.      } else { /* input doesn't end in 's' */
  93.  
  94.          if (!BSTRCMPI(bp, p - 3, "men")
  95.              && !badman(bp, FALSE)) {
  96.              Strcasecpy(p - 2, "an");
  97.              goto bottom;
  98.          }
  99.          /* matzot -> matzo, algae -> alga */
  100.          if (!BSTRCMPI(bp, p - 6, "matzot") || !BSTRCMPI(bp, p - 2, "ae")) {
  101.              *(p - 1) = '\0'; /* drop t/e */
  102.              goto bottom;
  103.          }
  104.          /* balactheria -> balactherium */
  105.          if (p - 4 >= bp && !strcmpi(p - 2, "ia")
  106.              && index("lr", lowc(*(p - 3))) && lowc(*(p - 4)) == 'e') {
  107.              Strcasecpy(p - 1, "um"); /* a -> um */
  108.          }
  109.  
  110.          /* here we cannot find the plural suffix */
  111.      }
  112.  
  113.  bottom:
  114.      /* if we stripped off a suffix (" of bar" from "foo of bar"),
  115.         put it back now [strcat() isn't actually 100% safe here...] */
  116.      if (excess)
  117.          Strcat(bp, excess);
  118.  
  119.      return bp;
  120.  }
  121.  

badman

  1.  boolean
  2.  badman(basestr, to_plural)
  3.  const char *basestr;
  4.  boolean to_plural;            /* true => makeplural, false => makesingular */
  5.  {
  6.      int i, al;
  7.      char *endstr, *spot;
  8.      /* these are all the prefixes for *man that don't have a *men plural */
  9.      const char *no_men[] = {
  10.          "albu", "antihu", "anti", "ata", "auto", "bildungsro", "cai", "cay",
  11.          "ceru", "corner", "decu", "des", "dura", "fir", "hanu", "het",
  12.          "infrahu", "inhu", "nonhu", "otto", "out", "prehu", "protohu",
  13.          "subhu", "superhu", "talis", "unhu", "sha",
  14.          "hu", "un", "le", "re", "so", "to", "at", "a",
  15.      };
  16.      /* these are all the prefixes for *men that don't have a *man singular */
  17.      const char *no_man[] = {
  18.          "abdo", "acu", "agno", "ceru", "cogno", "cycla", "fleh", "grava",
  19.          "hegu", "preno", "sonar", "speci", "dai", "exa", "fla", "sta", "teg",
  20.          "tegu", "vela", "da", "hy", "lu", "no", "nu", "ra", "ru", "se", "vi", "ya",
  21.          "o", "a",
  22.      };
  23.  
  24.      if (!basestr || strlen(basestr) < 4)
  25.          return FALSE;
  26.  
  27.      endstr = eos((char *)basestr);
  28.  
  29.      if (to_plural) {
  30.          for (i = 0; i < SIZE(no_men); i++) {
  31.              al = (int) strlen(no_men[i]);
  32.              spot = endstr - (al + 3);
  33.              if (!BSTRNCMPI(basestr, spot, no_men[i], al)
  34.                  && (spot == basestr || *(spot - 1) == ' '))
  35.                  return TRUE;
  36.          }
  37.      } else {
  38.          for (i = 0; i < SIZE(no_man); i++) {
  39.              al = (int) strlen(no_man[i]);
  40.              spot = endstr - (al + 3);
  41.              if (!BSTRNCMPI(basestr, spot, no_man[i], al)
  42.                  && (spot == basestr || *(spot - 1) == ' '))
  43.                  return TRUE;
  44.          }
  45.      }
  46.      return FALSE;
  47.  }
  48.  

wishymatch

  1.  /* compare user string against object name string using fuzzy matching */
  2.  STATIC_OVL boolean
  3.  wishymatch(u_str, o_str, retry_inverted)
  4.  const char *u_str;      /* from user, so might be variant spelling */
  5.  const char *o_str;      /* from objects[], so is in canonical form */
  6.  boolean retry_inverted; /* optional extra "of" handling */
  7.  {
  8.      static NEARDATA const char detect_SP[] = "detect ",
  9.                                 SP_detection[] = " detection";
  10.      char *p, buf[BUFSZ];
  11.  
  12.      /* ignore spaces & hyphens and upper/lower case when comparing */
  13.      if (fuzzymatch(u_str, o_str, " -", TRUE))
  14.          return TRUE;
  15.  
  16.      if (retry_inverted) {
  17.          const char *u_of, *o_of;
  18.  
  19.          /* when just one of the strings is in the form "foo of bar",
  20.             convert it into "bar foo" and perform another comparison */
  21.          u_of = strstri(u_str, " of ");
  22.          o_of = strstri(o_str, " of ");
  23.          if (u_of && !o_of) {
  24.              Strcpy(buf, u_of + 4);
  25.              p = eos(strcat(buf, " "));
  26.              while (u_str < u_of)
  27.                  *p++ = *u_str++;
  28.              *p = '\0';
  29.              return fuzzymatch(buf, o_str, " -", TRUE);
  30.          } else if (o_of && !u_of) {
  31.              Strcpy(buf, o_of + 4);
  32.              p = eos(strcat(buf, " "));
  33.              while (o_str < o_of)
  34.                  *p++ = *o_str++;
  35.              *p = '\0';
  36.              return fuzzymatch(u_str, buf, " -", TRUE);
  37.          }
  38.      }
  39.  
  40.      /* [note: if something like "elven speed boots" ever gets added, these
  41.         special cases should be changed to call wishymatch() recursively in
  42.         order to get the "of" inversion handling] */
  43.      if (!strncmp(o_str, "dwarvish ", 9)) {
  44.          if (!strncmpi(u_str, "dwarven ", 8))
  45.              return fuzzymatch(u_str + 8, o_str + 9, " -", TRUE);
  46.      } else if (!strncmp(o_str, "elven ", 6)) {
  47.          if (!strncmpi(u_str, "elvish ", 7))
  48.              return fuzzymatch(u_str + 7, o_str + 6, " -", TRUE);
  49.          else if (!strncmpi(u_str, "elfin ", 6))
  50.              return fuzzymatch(u_str + 6, o_str + 6, " -", TRUE);
  51.      } else if (!strncmp(o_str, detect_SP, sizeof detect_SP - 1)) {
  52.          /* check for "detect <foo>" vs "<foo> detection" */
  53.          if ((p = strstri(u_str, SP_detection)) != 0
  54.              && !*(p + sizeof SP_detection - 1)) {
  55.              /* convert "<foo> detection" into "detect <foo>" */
  56.              *p = '\0';
  57.              Strcat(strcpy(buf, detect_SP), u_str);
  58.              /* "detect monster" -> "detect monsters" */
  59.              if (!strcmpi(u_str, "monster"))
  60.                  Strcat(buf, "s");
  61.              *p = ' ';
  62.              return fuzzymatch(buf, o_str, " -", TRUE);
  63.          }
  64.      } else if (strstri(o_str, SP_detection)) {
  65.          /* and the inverse, "<foo> detection" vs "detect <foo>" */
  66.          if (!strncmpi(u_str, detect_SP, sizeof detect_SP - 1)) {
  67.              /* convert "detect <foo>s" into "<foo> detection" */
  68.              p = makesingular(u_str + sizeof detect_SP - 1);
  69.              Strcat(strcpy(buf, p), SP_detection);
  70.              /* caller may be looping through objects[], so avoid
  71.                 churning through all the obufs */
  72.              releaseobuf(p);
  73.              return fuzzymatch(buf, o_str, " -", TRUE);
  74.          }
  75.      } else if (strstri(o_str, "ability")) {
  76.          /* when presented with "foo of bar", makesingular() used to
  77.             singularize both foo & bar, but now only does so for foo */
  78.          /* catch "{potion(s),ring} of {gain,restore,sustain} abilities" */
  79.          if ((p = strstri(u_str, "abilities")) != 0
  80.              && !*(p + sizeof "abilities" - 1)) {
  81.              (void) strncpy(buf, u_str, (unsigned) (p - u_str));
  82.              Strcpy(buf + (p - u_str), "ability");
  83.              return fuzzymatch(buf, o_str, " -", TRUE);
  84.          }
  85.      } else if (!strcmp(o_str, "aluminum")) {
  86.          /* this special case doesn't really fit anywhere else... */
  87.          /* (note that " wand" will have been stripped off by now) */
  88.          if (!strcmpi(u_str, "aluminium"))
  89.              return fuzzymatch(u_str + 9, o_str + 8, " -", TRUE);
  90.      }
  91.  
  92.      return FALSE;
  93.  }
  94.  
  95.  struct o_range {
  96.      const char *name, oclass;
  97.      int f_o_range, l_o_range;
  98.  };
  99.  
  100.  /* wishable subranges of objects */
  101.  STATIC_OVL NEARDATA const struct o_range o_ranges[] = {
  102.      { "bag", TOOL_CLASS, SACK, BAG_OF_TRICKS },
  103.      { "lamp", TOOL_CLASS, OIL_LAMP, MAGIC_LAMP },
  104.      { "candle", TOOL_CLASS, TALLOW_CANDLE, WAX_CANDLE },
  105.      { "horn", TOOL_CLASS, TOOLED_HORN, HORN_OF_PLENTY },
  106.      { "shield", ARMOR_CLASS, SMALL_SHIELD, SHIELD_OF_REFLECTION },
  107.      { "hat", ARMOR_CLASS, FEDORA, DUNCE_CAP },
  108.      { "helm", ARMOR_CLASS, ELVEN_LEATHER_HELM, HELM_OF_TELEPATHY },
  109.      { "gloves", ARMOR_CLASS, LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY },
  110.      { "gauntlets", ARMOR_CLASS, LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY },
  111.      { "boots", ARMOR_CLASS, LOW_BOOTS, LEVITATION_BOOTS },
  112.      { "shoes", ARMOR_CLASS, LOW_BOOTS, IRON_SHOES },
  113.      { "cloak", ARMOR_CLASS, MUMMY_WRAPPING, CLOAK_OF_DISPLACEMENT },
  114.      { "shirt", ARMOR_CLASS, HAWAIIAN_SHIRT, T_SHIRT },
  115.      { "dragon scales", ARMOR_CLASS, GRAY_DRAGON_SCALES,
  116.        YELLOW_DRAGON_SCALES },
  117.      { "dragon scale mail", ARMOR_CLASS, GRAY_DRAGON_SCALE_MAIL,
  118.        YELLOW_DRAGON_SCALE_MAIL },
  119.      { "sword", WEAPON_CLASS, SHORT_SWORD, KATANA },
  120.      { "venom", VENOM_CLASS, BLINDING_VENOM, ACID_VENOM },
  121.      { "gray stone", GEM_CLASS, LUCKSTONE, FLINT },
  122.      { "grey stone", GEM_CLASS, LUCKSTONE, FLINT },
  123.  };
  124.  
  125.  /* alternate spellings; if the difference is only the presence or
  126.     absence of spaces and/or hyphens (such as "pickaxe" vs "pick axe"
  127.     vs "pick-axe") then there is no need for inclusion in this list;
  128.     likewise for ``"of" inversions'' ("boots of speed" vs "speed boots") */
  129.  struct alt_spellings {
  130.      const char *sp;
  131.      int ob;
  132.  } spellings[] = {
  133.      { "pickax", PICK_AXE },
  134.      { "whip", BULLWHIP },
  135.      { "saber", SILVER_SABER },
  136.      { "silver sabre", SILVER_SABER },
  137.      { "smooth shield", SHIELD_OF_REFLECTION },
  138.      { "grey dragon scale mail", GRAY_DRAGON_SCALE_MAIL },
  139.      { "grey dragon scales", GRAY_DRAGON_SCALES },
  140.      { "iron ball", HEAVY_IRON_BALL },
  141.      { "lantern", BRASS_LANTERN },
  142.      { "mattock", DWARVISH_MATTOCK },
  143.      { "amulet of poison resistance", AMULET_VERSUS_POISON },
  144.      { "potion of sleep", POT_SLEEPING },
  145.      { "stone", ROCK },
  146.      { "camera", EXPENSIVE_CAMERA },
  147.      { "tee shirt", T_SHIRT },
  148.      { "can", TIN },
  149.      { "can opener", TIN_OPENER },
  150.      { "kelp", KELP_FROND },
  151.      { "eucalyptus", EUCALYPTUS_LEAF },
  152.      { "royal jelly", LUMP_OF_ROYAL_JELLY },
  153.      { "lembas", LEMBAS_WAFER },
  154.      { "marker", MAGIC_MARKER },
  155.      { "hook", GRAPPLING_HOOK },
  156.      { "grappling iron", GRAPPLING_HOOK },
  157.      { "grapnel", GRAPPLING_HOOK },
  158.      { "grapple", GRAPPLING_HOOK },
  159.      { "protection from shape shifters", RIN_PROTECTION_FROM_SHAPE_CHAN },
  160.      /* if we ever add other sizes, move this to o_ranges[] with "bag" */
  161.      { "box", LARGE_BOX },
  162.      /* normally we wouldn't have to worry about unnecessary <space>, but
  163.         " stone" will get stripped off, preventing a wishymatch; that actually
  164.         lets "flint stone" be a match, so we also accept bogus "flintstone" */
  165.      { "luck stone", LUCKSTONE },
  166.      { "load stone", LOADSTONE },
  167.      { "touch stone", TOUCHSTONE },
  168.      { "flintstone", FLINT },
  169.      { (const char *) 0, 0 },
  170.  };
  171.  

rnd_otyp_by_wpnskill

  1.  STATIC_OVL short
  2.  rnd_otyp_by_wpnskill(skill)
  3.  schar skill;
  4.  {
  5.      int i, n = 0;
  6.      short otyp = STRANGE_OBJECT;
  7.      for (i = bases[WEAPON_CLASS];
  8.           i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++)
  9.          if (objects[i].oc_skill == skill) {
  10.              n++;
  11.              otyp = i;
  12.          }
  13.      if (n > 0) {
  14.          n = rn2(n);
  15.          for (i = bases[WEAPON_CLASS];
  16.               i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++)
  17.              if (objects[i].oc_skill == skill)
  18.                  if (--n < 0)
  19.                      return i;
  20.      }
  21.      return otyp;
  22.  }
  23.  

rnd_otyp_by_namedesc

  1.  STATIC_OVL short
  2.  rnd_otyp_by_namedesc(name, oclass)
  3.  char *name;
  4.  char oclass;
  5.  {
  6.      int i, n = 0;
  7.      short validobjs[NUM_OBJECTS];
  8.      register const char *zn;
  9.      long maxprob = 0;
  10.  
  11.      if (!name)
  12.          return STRANGE_OBJECT;
  13.  
  14.      memset((genericptr_t) validobjs, 0, sizeof(validobjs));
  15.  
  16.      for (i = oclass ? bases[(int)oclass] : STRANGE_OBJECT + 1;
  17.           i < NUM_OBJECTS && (!oclass || objects[i].oc_class == oclass);
  18.           ++i) {
  19.          /* don't match extra descriptions (w/o real name) */
  20.          if ((zn = OBJ_NAME(objects[i])) == 0)
  21.              continue;
  22.          if (wishymatch(name, zn, TRUE)
  23.              || ((zn = OBJ_DESCR(objects[i])) != 0
  24.                  && wishymatch(name, zn, FALSE))
  25.              || ((zn = objects[i].oc_uname) != 0
  26.                  && wishymatch(name, zn, FALSE))) {
  27.              validobjs[n++] = (short) i;
  28.              maxprob += (objects[i].oc_prob + 1);
  29.          }
  30.      }
  31.  
  32.      if (n > 0 && maxprob) {
  33.          long prob = rn2(maxprob);
  34.  
  35.          i = 0;
  36.          while (i < n - 1
  37.                 && (prob -= (objects[validobjs[i]].oc_prob + 1)) >= 0)
  38.              i++;
  39.          return validobjs[i];
  40.      }
  41.      return STRANGE_OBJECT;
  42.  }
  43.  

readobjnam

  1.  /*
  2.   * Return something wished for.  Specifying a null pointer for
  3.   * the user request string results in a random object.  Otherwise,
  4.   * if asking explicitly for "nothing" (or "nil") return no_wish;
  5.   * if not an object return &zeroobj; if an error (no matching object),
  6.   * return null.
  7.   */
  8.  struct obj *
  9.  readobjnam(bp, no_wish)
  10.  register char *bp;
  11.  struct obj *no_wish;
  12.  {
  13.      register char *p;
  14.      register int i;
  15.      register struct obj *otmp;
  16.      int cnt, spe, spesgn, typ, very, rechrg;
  17.      int blessed, uncursed, iscursed, ispoisoned, isgreased;
  18.      int eroded, eroded2, erodeproof, locked, unlocked, broken;
  19.      int halfeaten, mntmp, contents;
  20.      int islit, unlabeled, ishistoric, isdiluted, trapped;
  21.      int tmp, tinv, tvariety;
  22.      int wetness, gsize = 0;
  23.      struct fruit *f;
  24.      int ftype = context.current_fruit;
  25.      char fruitbuf[BUFSZ];
  26.      /* Fruits may not mess up the ability to wish for real objects (since
  27.       * you can leave a fruit in a bones file and it will be added to
  28.       * another person's game), so they must be checked for last, after
  29.       * stripping all the possible prefixes and seeing if there's a real
  30.       * name in there.  So we have to save the full original name.  However,
  31.       * it's still possible to do things like "uncursed burnt Alaska",
  32.       * or worse yet, "2 burned 5 course meals", so we need to loop to
  33.       * strip off the prefixes again, this time stripping only the ones
  34.       * possible on food.
  35.       * We could get even more detailed so as to allow food names with
  36.       * prefixes that _are_ possible on food, so you could wish for
  37.       * "2 3 alarm chilis".  Currently this isn't allowed; options.c
  38.       * automatically sticks 'candied' in front of such names.
  39.       */
  40.      char oclass;
  41.      char *un, *dn, *actualn, *origbp = bp;
  42.      const char *name = 0;
  43.  
  44.      cnt = spe = spesgn = typ = 0;
  45.      very = rechrg = blessed = uncursed = iscursed = ispoisoned =
  46.          isgreased = eroded = eroded2 = erodeproof = halfeaten =
  47.          islit = unlabeled = ishistoric = isdiluted = trapped =
  48.          locked = unlocked = broken = 0;
  49.      tvariety = RANDOM_TIN;
  50.      mntmp = NON_PM;
  51.  #define UNDEFINED 0
  52.  #define EMPTY 1
  53.  #define SPINACH 2
  54.      contents = UNDEFINED;
  55.      oclass = 0;
  56.      actualn = dn = un = 0;
  57.      wetness = 0;
  58.  
  59.      if (!bp)
  60.          goto any;
  61.      /* first, remove extra whitespace they may have typed */
  62.      (void) mungspaces(bp);
  63.      /* allow wishing for "nothing" to preserve wishless conduct...
  64.         [now requires "wand of nothing" if that's what was really wanted] */
  65.      if (!strcmpi(bp, "nothing") || !strcmpi(bp, "nil")
  66.          || !strcmpi(bp, "none"))
  67.          return no_wish;
  68.      /* save the [nearly] unmodified choice string */
  69.      Strcpy(fruitbuf, bp);
  70.  
  71.      for (;;) {
  72.          register int l;
  73.  
  74.          if (!bp || !*bp)
  75.              goto any;
  76.          if (!strncmpi(bp, "an ", l = 3) || !strncmpi(bp, "a ", l = 2)) {
  77.              cnt = 1;
  78.          } else if (!strncmpi(bp, "the ", l = 4)) {
  79.              ; /* just increment `bp' by `l' below */
  80.          } else if (!cnt && digit(*bp) && strcmp(bp, "0")) {
  81.              cnt = atoi(bp);
  82.              while (digit(*bp))
  83.                  bp++;
  84.              while (*bp == ' ')
  85.                  bp++;
  86.              l = 0;
  87.          } else if (*bp == '+' || *bp == '-') {
  88.              spesgn = (*bp++ == '+') ? 1 : -1;
  89.              spe = atoi(bp);
  90.              while (digit(*bp))
  91.                  bp++;
  92.              while (*bp == ' ')
  93.                  bp++;
  94.              l = 0;
  95.          } else if (!strncmpi(bp, "blessed ", l = 8)
  96.                     || !strncmpi(bp, "holy ", l = 5)) {
  97.              blessed = 1;
  98.          } else if (!strncmpi(bp, "moist ", l = 6)
  99.                     || !strncmpi(bp, "wet ", l = 4)) {
  100.              if (!strncmpi(bp, "wet ", 4))
  101.                  wetness = rn2(3) + 3;
  102.              else
  103.                  wetness = rnd(2);
  104.          } else if (!strncmpi(bp, "cursed ", l = 7)
  105.                     || !strncmpi(bp, "unholy ", l = 7)) {
  106.              iscursed = 1;
  107.          } else if (!strncmpi(bp, "uncursed ", l = 9)) {
  108.              uncursed = 1;
  109.          } else if (!strncmpi(bp, "rustproof ", l = 10)
  110.                     || !strncmpi(bp, "erodeproof ", l = 11)
  111.                     || !strncmpi(bp, "corrodeproof ", l = 13)
  112.                     || !strncmpi(bp, "fixed ", l = 6)
  113.                     || !strncmpi(bp, "fireproof ", l = 10)
  114.                     || !strncmpi(bp, "rotproof ", l = 9)) {
  115.              erodeproof = 1;
  116.          } else if (!strncmpi(bp, "lit ", l = 4)
  117.                     || !strncmpi(bp, "burning ", l = 8)) {
  118.              islit = 1;
  119.          } else if (!strncmpi(bp, "unlit ", l = 6)
  120.                     || !strncmpi(bp, "extinguished ", l = 13)) {
  121.              islit = 0;
  122.              /* "unlabeled" and "blank" are synonymous */
  123.          } else if (!strncmpi(bp, "unlabeled ", l = 10)
  124.                     || !strncmpi(bp, "unlabelled ", l = 11)
  125.                     || !strncmpi(bp, "blank ", l = 6)) {
  126.              unlabeled = 1;
  127.          } else if (!strncmpi(bp, "poisoned ", l = 9)) {
  128.              ispoisoned = 1;
  129.              /* "trapped" recognized but not honored outside wizard mode */
  130.          } else if (!strncmpi(bp, "trapped ", l = 8)) {
  131.              trapped = 0; /* undo any previous "untrapped" */
  132.              if (wizard)
  133.                  trapped = 1;
  134.          } else if (!strncmpi(bp, "untrapped ", l = 10)) {
  135.              trapped = 2; /* not trapped */
  136.          /* locked, unlocked, broken: box/chest lock states */
  137.          } else if (!strncmpi(bp, "locked ", l = 7)) {
  138.              locked = 1, unlocked = broken = 0;
  139.          } else if (!strncmpi(bp, "unlocked ", l = 9)) {
  140.              unlocked = 1, locked = broken = 0;
  141.          } else if (!strncmpi(bp, "broken ", l = 7)) {
  142.              broken = 1, locked = unlocked = 0;
  143.          } else if (!strncmpi(bp, "greased ", l = 8)) {
  144.              isgreased = 1;
  145.          } else if (!strncmpi(bp, "very ", l = 5)) {
  146.              /* very rusted very heavy iron ball */
  147.              very = 1;
  148.          } else if (!strncmpi(bp, "thoroughly ", l = 11)) {
  149.              very = 2;
  150.          } else if (!strncmpi(bp, "rusty ", l = 6)
  151.                     || !strncmpi(bp, "rusted ", l = 7)
  152.                     || !strncmpi(bp, "burnt ", l = 6)
  153.                     || !strncmpi(bp, "burned ", l = 7)) {
  154.              eroded = 1 + very;
  155.              very = 0;
  156.          } else if (!strncmpi(bp, "corroded ", l = 9)
  157.                     || !strncmpi(bp, "rotted ", l = 7)) {
  158.              eroded2 = 1 + very;
  159.              very = 0;
  160.          } else if (!strncmpi(bp, "partly eaten ", l = 13)
  161.                     || !strncmpi(bp, "partially eaten ", l = 16)) {
  162.              halfeaten = 1;
  163.          } else if (!strncmpi(bp, "historic ", l = 9)) {
  164.              ishistoric = 1;
  165.          } else if (!strncmpi(bp, "diluted ", l = 8)) {
  166.              isdiluted = 1;
  167.          } else if (!strncmpi(bp, "empty ", l = 6)) {
  168.              contents = EMPTY;
  169.          } else if (!strncmpi(bp, "small ", l = 6)) { /* glob sizes */
  170.              gsize = 1;
  171.          } else if (!strncmpi(bp, "medium ", l = 7)) {
  172.              /* xname() doesn't display "medium" but without this
  173.                 there'd be no way to ask for the intermediate size */
  174.              gsize = 2;
  175.          } else if (!strncmpi(bp, "large ", l = 6)) {
  176.              /* "very large " had "very " peeled off on previous iteration */
  177.              gsize = (very != 1) ? 3 : 4;
  178.          } else
  179.              break;
  180.          bp += l;
  181.      }
  182.      if (!cnt)
  183.          cnt = 1; /* %% what with "gems" etc. ? */
  184.      if (strlen(bp) > 1 && (p = rindex(bp, '(')) != 0) {
  185.          boolean keeptrailingchars = TRUE;
  186.  
  187.          p[(p > bp && p[-1] == ' ') ? -1 : 0] = '\0'; /*terminate bp */
  188.          ++p; /* advance past '(' */
  189.          if (!strncmpi(p, "lit)", 4)) {
  190.              islit = 1;
  191.              p += 4 - 1; /* point at ')' */
  192.          } else {
  193.              spe = atoi(p);
  194.              while (digit(*p))
  195.                  p++;
  196.              if (*p == ':') {
  197.                  p++;
  198.                  rechrg = spe;
  199.                  spe = atoi(p);
  200.                  while (digit(*p))
  201.                      p++;
  202.              }
  203.              if (*p != ')') {
  204.                  spe = rechrg = 0;
  205.                  /* mis-matched parentheses; rest of string will be ignored
  206.                   * [probably we should restore everything back to '('
  207.                   * instead since it might be part of "named ..."]
  208.                   */
  209.                  keeptrailingchars = FALSE;
  210.              } else {
  211.                  spesgn = 1;
  212.              }
  213.          }
  214.          if (keeptrailingchars) {
  215.              char *pp = eos(bp);
  216.  
  217.              /* 'pp' points at 'pb's terminating '\0',
  218.                 'p' points at ')' and will be incremented past it */
  219.              do {
  220.                  *pp++ = *++p;
  221.              } while (*p);
  222.          }
  223.      }
  224.      /*
  225.       * otmp->spe is type schar, so we don't want spe to be any bigger or
  226.       * smaller.  Also, spe should always be positive --some cheaters may
  227.       * try to confuse atoi().
  228.       */
  229.      if (spe < 0) {
  230.          spesgn = -1; /* cheaters get what they deserve */
  231.          spe = abs(spe);
  232.      }
  233.      if (spe > SCHAR_LIM)
  234.          spe = SCHAR_LIM;
  235.      if (rechrg < 0 || rechrg > 7)
  236.          rechrg = 7; /* recharge_limit */
  237.  
  238.      /* now we have the actual name, as delivered by xname, say
  239.       *  green potions called whisky
  240.       *  scrolls labeled "QWERTY"
  241.       *  egg
  242.       *  fortune cookies
  243.       *  very heavy iron ball named hoei
  244.       *  wand of wishing
  245.       *  elven cloak
  246.       */
  247.      if ((p = strstri(bp, " named ")) != 0) {
  248.          *p = 0;
  249.          name = p + 7;
  250.      }
  251.      if ((p = strstri(bp, " called ")) != 0) {
  252.          *p = 0;
  253.          un = p + 8;
  254.          /* "helmet called telepathy" is not "helmet" (a specific type)
  255.           * "shield called reflection" is not "shield" (a general type)
  256.           */
  257.          for (i = 0; i < SIZE(o_ranges); i++)
  258.              if (!strcmpi(bp, o_ranges[i].name)) {
  259.                  oclass = o_ranges[i].oclass;
  260.                  goto srch;
  261.              }
  262.      }
  263.      if ((p = strstri(bp, " labeled ")) != 0) {
  264.          *p = 0;
  265.          dn = p + 9;
  266.      } else if ((p = strstri(bp, " labelled ")) != 0) {
  267.          *p = 0;
  268.          dn = p + 10;
  269.      }
  270.      if ((p = strstri(bp, " of spinach")) != 0) {
  271.          *p = 0;
  272.          contents = SPINACH;
  273.      }
  274.  
  275.      /*
  276.       * Skip over "pair of ", "pairs of", "set of" and "sets of".
  277.       *
  278.       * Accept "3 pair of boots" as well as "3 pairs of boots".  It is
  279.       * valid English either way.  See makeplural() for more on pair/pairs.
  280.       *
  281.       * We should only double count if the object in question is not
  282.       * referred to as a "pair of".  E.g. We should double if the player
  283.       * types "pair of spears", but not if the player types "pair of
  284.       * lenses".  Luckily (?) all objects that are referred to as pairs
  285.       * -- boots, gloves, and lenses -- are also not mergable, so cnt is
  286.       * ignored anyway.
  287.       */
  288.      if (!strncmpi(bp, "pair of ", 8)) {
  289.          bp += 8;
  290.          cnt *= 2;
  291.      } else if (!strncmpi(bp, "pairs of ", 9)) {
  292.          bp += 9;
  293.          if (cnt > 1)
  294.              cnt *= 2;
  295.      } else if (!strncmpi(bp, "set of ", 7)) {
  296.          bp += 7;
  297.      } else if (!strncmpi(bp, "sets of ", 8)) {
  298.          bp += 8;
  299.      }
  300.  
  301.      /* intercept pudding globs here; they're a valid wish target,
  302.       * but we need them to not get treated like a corpse.
  303.       *
  304.       * also don't let player wish for multiple globs.
  305.       */
  306.      if ((p = strstri(bp, "glob of ")) != 0
  307.          || (p = strstri(bp, "globs of ")) != 0) {
  308.          int globoffset = (*(p + 4) == 's') ? 9 : 8;
  309.  
  310.          if ((mntmp = name_to_mon(p + globoffset)) >= PM_GRAY_OOZE
  311.              && mntmp <= PM_BLACK_PUDDING) {
  312.              mntmp = NON_PM; /* lie to ourselves */
  313.              cnt = 0;        /* force only one */
  314.          }
  315.      } else {
  316.          /*
  317.           * Find corpse type using "of" (figurine of an orc, tin of orc meat)
  318.           * Don't check if it's a wand or spellbook.
  319.           * (avoid "wand/finger of death" confusion).
  320.           */
  321.          if (!strstri(bp, "wand ") && !strstri(bp, "spellbook ")
  322.              && !strstri(bp, "finger ")) {
  323.              if ((p = strstri(bp, "tin of ")) != 0) {
  324.                  if (!strcmpi(p + 7, "spinach")) {
  325.                      contents = SPINACH;
  326.                      mntmp = NON_PM;
  327.                  } else {
  328.                      tmp = tin_variety_txt(p + 7, &tinv);
  329.                      tvariety = tinv;
  330.                      mntmp = name_to_mon(p + 7 + tmp);
  331.                  }
  332.                  typ = TIN;
  333.                  goto typfnd;
  334.              } else if ((p = strstri(bp, " of ")) != 0
  335.                         && (mntmp = name_to_mon(p + 4)) >= LOW_PM)
  336.                  *p = 0;
  337.          }
  338.      }
  339.      /* Find corpse type w/o "of" (red dragon scale mail, yeti corpse) */
  340.      if (strncmpi(bp, "samurai sword", 13)  /* not the "samurai" monster! */
  341.          && strncmpi(bp, "wizard lock", 11) /* not the "wizard" monster! */
  342.          && strncmpi(bp, "ninja-to", 8)     /* not the "ninja" rank */
  343.          && strncmpi(bp, "master key", 10)  /* not the "master" rank */
  344.          && strncmpi(bp, "magenta", 7)) {   /* not the "mage" rank */
  345.          if (mntmp < LOW_PM && strlen(bp) > 2
  346.              && (mntmp = name_to_mon(bp)) >= LOW_PM) {
  347.              int mntmptoo, mntmplen; /* double check for rank title */
  348.              char *obp = bp;
  349.  
  350.              mntmptoo = title_to_mon(bp, (int *) 0, &mntmplen);
  351.              bp += (mntmp != mntmptoo) ? (int) strlen(mons[mntmp].mname)
  352.                                        : mntmplen;
  353.              if (*bp == ' ') {
  354.                  bp++;
  355.              } else if (!strncmpi(bp, "s ", 2)) {
  356.                  bp += 2;
  357.              } else if (!strncmpi(bp, "es ", 3)) {
  358.                  bp += 3;
  359.              } else if (!*bp && !actualn && !dn && !un && !oclass) {
  360.                  /* no referent; they don't really mean a monster type */
  361.                  bp = obp;
  362.                  mntmp = NON_PM;
  363.              }
  364.          }
  365.      }
  366.  
  367.      /* first change to singular if necessary */
  368.      if (*bp) {
  369.          char *sng = makesingular(bp);
  370.          if (strcmp(bp, sng)) {
  371.              if (cnt == 1)
  372.                  cnt = 2;
  373.              Strcpy(bp, sng);
  374.          }
  375.      }
  376.  
  377.      /* Alternate spellings (pick-ax, silver sabre, &c) */
  378.      {
  379.          struct alt_spellings *as = spellings;
  380.  
  381.          while (as->sp) {
  382.              if (fuzzymatch(bp, as->sp, " -", TRUE)) {
  383.                  typ = as->ob;
  384.                  goto typfnd;
  385.              }
  386.              as++;
  387.          }
  388.          /* can't use spellings list for this one due to shuffling */
  389.          if (!strncmpi(bp, "grey spell", 10))
  390.              *(bp + 2) = 'a';
  391.  
  392.          if ((p = strstri(bp, "armour")) != 0) {
  393.              /* skip past "armo", then copy remainder beyond "u" */
  394.              p += 4;
  395.              while ((*p = *(p + 1)) != '\0')
  396.                  ++p; /* self terminating */
  397.          }
  398.      }
  399.  
  400.      /* dragon scales - assumes order of dragons */
  401.      if (!strcmpi(bp, "scales") && mntmp >= PM_GRAY_DRAGON
  402.          && mntmp <= PM_YELLOW_DRAGON) {
  403.          typ = GRAY_DRAGON_SCALES + mntmp - PM_GRAY_DRAGON;
  404.          mntmp = NON_PM; /* no monster */
  405.          goto typfnd;
  406.      }
  407.  
  408.      p = eos(bp);
  409.      if (!BSTRCMPI(bp, p - 10, "holy water")) {
  410.          typ = POT_WATER;
  411.          if ((p - bp) >= 12 && *(p - 12) == 'u')
  412.              iscursed = 1; /* unholy water */
  413.          else
  414.              blessed = 1;
  415.          goto typfnd;
  416.      }
  417.      if (unlabeled && !BSTRCMPI(bp, p - 6, "scroll")) {
  418.          typ = SCR_BLANK_PAPER;
  419.          goto typfnd;
  420.      }
  421.      if (unlabeled && !BSTRCMPI(bp, p - 9, "spellbook")) {
  422.          typ = SPE_BLANK_PAPER;
  423.          goto typfnd;
  424.      }
  425.      /*
  426.       * NOTE: Gold pieces are handled as objects nowadays, and therefore
  427.       * this section should probably be reconsidered as well as the entire
  428.       * gold/money concept.  Maybe we want to add other monetary units as
  429.       * well in the future. (TH)
  430.       */
  431.      if (!BSTRCMPI(bp, p - 10, "gold piece")
  432.          || !BSTRCMPI(bp, p - 7, "zorkmid")
  433.          || !strcmpi(bp, "gold") || !strcmpi(bp, "money")
  434.          || !strcmpi(bp, "coin") || *bp == GOLD_SYM) {
  435.          if (cnt > 5000 && !wizard)
  436.              cnt = 5000;
  437.          else if (cnt < 1)
  438.              cnt = 1;
  439.          otmp = mksobj(GOLD_PIECE, FALSE, FALSE);
  440.          otmp->quan = (long) cnt;
  441.          otmp->owt = weight(otmp);
  442.          context.botl = 1;
  443.          return otmp;
  444.      }
  445.  
  446.      /* check for single character object class code ("/" for wand, &c) */
  447.      if (strlen(bp) == 1 && (i = def_char_to_objclass(*bp)) < MAXOCLASSES
  448.          && i > ILLOBJ_CLASS && (i != VENOM_CLASS || wizard)) {
  449.          oclass = i;
  450.          goto any;
  451.      }
  452.  
  453.      /* Search for class names: XXXXX potion, scroll of XXXXX.  Avoid */
  454.      /* false hits on, e.g., rings for "ring mail". */
  455.      if (strncmpi(bp, "enchant ", 8)
  456.          && strncmpi(bp, "destroy ", 8)
  457.          && strncmpi(bp, "detect food", 11)
  458.          && strncmpi(bp, "food detection", 14)
  459.          && strncmpi(bp, "ring mail", 9)
  460.          && strncmpi(bp, "studded leather armor", 21)
  461.          && strncmpi(bp, "leather armor", 13)
  462.          && strncmpi(bp, "tooled horn", 11)
  463.          && strncmpi(bp, "food ration", 11)
  464.          && strncmpi(bp, "meat ring", 9))
  465.          for (i = 0; i < (int) (sizeof wrpsym); i++) {
  466.              register int j = strlen(wrp[i]);
  467.  
  468.              if (!strncmpi(bp, wrp[i], j)) {
  469.                  oclass = wrpsym[i];
  470.                  if (oclass != AMULET_CLASS) {
  471.                      bp += j;
  472.                      if (!strncmpi(bp, " of ", 4))
  473.                          actualn = bp + 4;
  474.                      /* else if(*bp) ?? */
  475.                  } else
  476.                      actualn = bp;
  477.                  goto srch;
  478.              }
  479.              if (!BSTRCMPI(bp, p - j, wrp[i])) {
  480.                  oclass = wrpsym[i];
  481.                  p -= j;
  482.                  *p = 0;
  483.                  if (p > bp && p[-1] == ' ')
  484.                      p[-1] = 0;
  485.                  actualn = dn = bp;
  486.                  goto srch;
  487.              }
  488.          }
  489.  
  490.      /* Wishing in wizard mode can create traps and furniture.
  491.       * Part I:  distinguish between trap and object for the two
  492.       * types of traps which have corresponding objects:  bear trap
  493.       * and land mine.  "beartrap" (object) and "bear trap" (trap)
  494.       * have a difference in spelling which we used to exploit by
  495.       * adding a special case in wishymatch(), but "land mine" is
  496.       * spelled the same either way so needs different handing.
  497.       * Since we need something else for land mine, we've dropped
  498.       * the bear trap hack so that both are handled exactly the
  499.       * same.  To get an armed trap instead of a disarmed object,
  500.       * the player can prefix either the object name or the trap
  501.       * name with "trapped " (which ordinarily applies to chests
  502.       * and tins), or append something--anything at all except for
  503.       * " object", but " trap" is suggested--to either the trap
  504.       * name or the object name.
  505.       */
  506.      if (wizard && (!strncmpi(bp, "bear", 4) || !strncmpi(bp, "land", 4))) {
  507.          boolean beartrap = (lowc(*bp) == 'b');
  508.          char *zp = bp + 4; /* skip "bear"/"land" */
  509.  
  510.          if (*zp == ' ')
  511.              ++zp; /* embedded space is optional */
  512.          if (!strncmpi(zp, beartrap ? "trap" : "mine", 4)) {
  513.              zp += 4;
  514.              if (trapped == 2 || !strcmpi(zp, " object")) {
  515.                  /* "untrapped <foo>" or "<foo> object" */
  516.                  typ = beartrap ? BEARTRAP : LAND_MINE;
  517.                  goto typfnd;
  518.              } else if (trapped == 1 || *zp != '\0') {
  519.                  /* "trapped <foo>" or "<foo> trap" (actually "<foo>*") */
  520.                  int idx = trap_to_defsym(beartrap ? BEAR_TRAP : LANDMINE);
  521.  
  522.                  /* use canonical trap spelling, skip object matching */
  523.                  Strcpy(bp, defsyms[idx].explanation);
  524.                  goto wiztrap;
  525.              }
  526.              /* [no prefix or suffix; we're going to end up matching
  527.                 the object name and getting a disarmed trap object] */
  528.          }
  529.      }
  530.  
  531.  retry:
  532.      /* "grey stone" check must be before general "stone" */
  533.      for (i = 0; i < SIZE(o_ranges); i++)
  534.          if (!strcmpi(bp, o_ranges[i].name)) {
  535.              typ = rnd_class(o_ranges[i].f_o_range, o_ranges[i].l_o_range);
  536.              goto typfnd;
  537.          }
  538.  
  539.      if (!BSTRCMPI(bp, p - 6, " stone") || !BSTRCMPI(bp, p - 4, " gem")) {
  540.          p[!strcmpi(p - 4, " gem") ? -4 : -6] = '\0';
  541.          oclass = GEM_CLASS;
  542.          dn = actualn = bp;
  543.          goto srch;
  544.      } else if (!strcmpi(bp, "looking glass")) {
  545.          ; /* avoid false hit on "* glass" */
  546.      } else if (!BSTRCMPI(bp, p - 6, " glass") || !strcmpi(bp, "glass")) {
  547.          register char *g = bp;
  548.  
  549.          /* treat "broken glass" as a non-existent item; since "broken" is
  550.             also a chest/box prefix it might have been stripped off above */
  551.          if (broken || strstri(g, "broken"))
  552.              return (struct obj *) 0;
  553.          if (!strncmpi(g, "worthless ", 10))
  554.              g += 10;
  555.          if (!strncmpi(g, "piece of ", 9))
  556.              g += 9;
  557.          if (!strncmpi(g, "colored ", 8))
  558.              g += 8;
  559.          else if (!strncmpi(g, "coloured ", 9))
  560.              g += 9;
  561.          if (!strcmpi(g, "glass")) { /* choose random color */
  562.              /* 9 different kinds */
  563.              typ = LAST_GEM + rnd(9);
  564.              if (objects[typ].oc_class == GEM_CLASS)
  565.                  goto typfnd;
  566.              else
  567.                  typ = 0; /* somebody changed objects[]? punt */
  568.          } else { /* try to construct canonical form */
  569.              char tbuf[BUFSZ];
  570.  
  571.              Strcpy(tbuf, "worthless piece of ");
  572.              Strcat(tbuf, g); /* assume it starts with the color */
  573.              Strcpy(bp, tbuf);
  574.          }
  575.      }
  576.  
  577.      actualn = bp;
  578.      if (!dn)
  579.          dn = actualn; /* ex. "skull cap" */
  580.  srch:
  581.      /* check real names of gems first */
  582.      if (!oclass && actualn) {
  583.          for (i = bases[GEM_CLASS]; i <= LAST_GEM; i++) {
  584.              register const char *zn;
  585.  
  586.              if ((zn = OBJ_NAME(objects[i])) != 0 && !strcmpi(actualn, zn)) {
  587.                  typ = i;
  588.                  goto typfnd;
  589.              }
  590.          }
  591.          /* "tin of foo" would be caught above, but plain "tin" has
  592.             a random chance of yielding "tin wand" unless we do this */
  593.          if (!strcmpi(actualn, "tin")) {
  594.              typ = TIN;
  595.              goto typfnd;
  596.          }
  597.      }
  598.  
  599.      if (((typ = rnd_otyp_by_namedesc(actualn, oclass)) != STRANGE_OBJECT)
  600.          || ((typ = rnd_otyp_by_namedesc(dn, oclass)) != STRANGE_OBJECT)
  601.          || ((typ = rnd_otyp_by_namedesc(un, oclass)) != STRANGE_OBJECT)
  602.          || ((typ = rnd_otyp_by_namedesc(origbp, oclass)) != STRANGE_OBJECT))
  603.          goto typfnd;
  604.      typ = 0;
  605.  
  606.      if (actualn) {
  607.          struct Jitem *j = Japanese_items;
  608.  
  609.          while (j->item) {
  610.              if (actualn && !strcmpi(actualn, j->name)) {
  611.                  typ = j->item;
  612.                  goto typfnd;
  613.              }
  614.              j++;
  615.          }
  616.      }
  617.      /* if we've stripped off "armor" and failed to match anything
  618.         in objects[], append "mail" and try again to catch misnamed
  619.         requests like "plate armor" and "yellow dragon scale armor" */
  620.      if (oclass == ARMOR_CLASS && !strstri(bp, "mail")) {
  621.          /* modifying bp's string is ok; we're about to resort
  622.             to random armor if this also fails to match anything */
  623.          Strcat(bp, " mail");
  624.          goto retry;
  625.      }
  626.      if (!strcmpi(bp, "spinach")) {
  627.          contents = SPINACH;
  628.          typ = TIN;
  629.          goto typfnd;
  630.      }
  631.      /* Note: not strcmpi.  2 fruits, one capital, one not, are possible.
  632.         Also not strncmp.  We used to ignore trailing text with it, but
  633.         that resulted in "grapefruit" matching "grape" if the latter came
  634.         earlier than the former in the fruit list. */
  635.      {
  636.          char *fp;
  637.          int l, cntf;
  638.          int blessedf, iscursedf, uncursedf, halfeatenf;
  639.  
  640.          blessedf = iscursedf = uncursedf = halfeatenf = 0;
  641.          cntf = 0;
  642.  
  643.          fp = fruitbuf;
  644.          for (;;) {
  645.              if (!fp || !*fp)
  646.                  break;
  647.              if (!strncmpi(fp, "an ", l = 3) || !strncmpi(fp, "a ", l = 2)) {
  648.                  cntf = 1;
  649.              } else if (!cntf && digit(*fp)) {
  650.                  cntf = atoi(fp);
  651.                  while (digit(*fp))
  652.                      fp++;
  653.                  while (*fp == ' ')
  654.                      fp++;
  655.                  l = 0;
  656.              } else if (!strncmpi(fp, "blessed ", l = 8)) {
  657.                  blessedf = 1;
  658.              } else if (!strncmpi(fp, "cursed ", l = 7)) {
  659.                  iscursedf = 1;
  660.              } else if (!strncmpi(fp, "uncursed ", l = 9)) {
  661.                  uncursedf = 1;
  662.              } else if (!strncmpi(fp, "partly eaten ", l = 13)
  663.                         || !strncmpi(fp, "partially eaten ", l = 16)) {
  664.                  halfeatenf = 1;
  665.              } else
  666.                  break;
  667.              fp += l;
  668.          }
  669.  
  670.          for (f = ffruit; f; f = f->nextf) {
  671.              /* match type: 0=none, 1=exact, 2=singular, 3=plural */
  672.              int ftyp = 0;
  673.  
  674.              if (!strcmp(fp, f->fname))
  675.                  ftyp = 1;
  676.              else if (!strcmp(fp, makesingular(f->fname)))
  677.                  ftyp = 2;
  678.              else if (!strcmp(fp, makeplural(f->fname)))
  679.                  ftyp = 3;
  680.              if (ftyp) {
  681.                  typ = SLIME_MOLD;
  682.                  blessed = blessedf;
  683.                  iscursed = iscursedf;
  684.                  uncursed = uncursedf;
  685.                  halfeaten = halfeatenf;
  686.                  /* adjust count if user explicitly asked for
  687.                     singular amount (can't happen unless fruit
  688.                     has been given an already pluralized name)
  689.                     or for plural amount */
  690.                  if (ftyp == 2 && !cntf)
  691.                      cntf = 1;
  692.                  else if (ftyp == 3 && !cntf)
  693.                      cntf = 2;
  694.                  cnt = cntf;
  695.                  ftype = f->fid;
  696.                  goto typfnd;
  697.              }
  698.          }
  699.      }
  700.  
  701.      if (!oclass && actualn) {
  702.          short objtyp;
  703.  
  704.          /* Perhaps it's an artifact specified by name, not type */
  705.          name = artifact_name(actualn, &objtyp);
  706.          if (name) {
  707.              typ = objtyp;
  708.              goto typfnd;
  709.          }
  710.      }
  711.  /* Let wizards wish for traps and furniture.
  712.   * Must come after objects check so wizards can still wish for
  713.   * trap objects like beartraps.
  714.   * Disallow such topology tweaks for WIZKIT startup wishes.
  715.   */
  716.  wiztrap:
  717.      if (wizard && !program_state.wizkit_wishing) {
  718.          struct rm *lev;
  719.          int trap, x = u.ux, y = u.uy;
  720.  
  721.          for (trap = NO_TRAP + 1; trap < TRAPNUM; trap++) {
  722.              struct trap *t;
  723.              const char *tname;
  724.  
  725.              tname = defsyms[trap_to_defsym(trap)].explanation;
  726.              if (strncmpi(tname, bp, strlen(tname)))
  727.                  continue;
  728.              /* found it; avoid stupid mistakes */
  729.              if ((trap == TRAPDOOR || trap == HOLE) && !Can_fall_thru(&u.uz))
  730.                  trap = ROCKTRAP;
  731.              if ((t = maketrap(x, y, trap)) != 0) {
  732.                  trap = t->ttyp;
  733.                  tname = defsyms[trap_to_defsym(trap)].explanation;
  734.                  pline("%s%s.", An(tname),
  735.                        (trap != MAGIC_PORTAL) ? "" : " to nowhere");
  736.              } else
  737.                  pline("Creation of %s failed.", an(tname));
  738.              return &zeroobj;
  739.          }
  740.  
  741.          /* furniture and terrain */
  742.          lev = &levl[x][y];
  743.          p = eos(bp);
  744.          if (!BSTRCMPI(bp, p - 8, "fountain")) {
  745.              lev->typ = FOUNTAIN;
  746.              level.flags.nfountains++;
  747.              if (!strncmpi(bp, "magic ", 6))
  748.                  lev->blessedftn = 1;
  749.              pline("A %sfountain.", lev->blessedftn ? "magic " : "");
  750.              newsym(x, y);
  751.              return &zeroobj;
  752.          }
  753.          if (!BSTRCMPI(bp, p - 6, "throne")) {
  754.              lev->typ = THRONE;
  755.              pline("A throne.");
  756.              newsym(x, y);
  757.              return &zeroobj;
  758.          }
  759.          if (!BSTRCMPI(bp, p - 4, "sink")) {
  760.              lev->typ = SINK;
  761.              level.flags.nsinks++;
  762.              pline("A sink.");
  763.              newsym(x, y);
  764.              return &zeroobj;
  765.          }
  766.          /* ("water" matches "potion of water" rather than terrain) */
  767.          if (!BSTRCMPI(bp, p - 4, "pool") || !BSTRCMPI(bp, p - 4, "moat")) {
  768.              lev->typ = !BSTRCMPI(bp, p - 4, "pool") ? POOL : MOAT;
  769.              del_engr_at(x, y);
  770.              pline("A %s.", (lev->typ == POOL) ? "pool" : "moat");
  771.              /* Must manually make kelp! */
  772.              water_damage_chain(level.objects[x][y], TRUE);
  773.              newsym(x, y);
  774.              return &zeroobj;
  775.          }
  776.          if (!BSTRCMPI(bp, p - 4, "lava")) { /* also matches "molten lava" */
  777.              lev->typ = LAVAPOOL;
  778.              del_engr_at(x, y);
  779.              pline("A pool of molten lava.");
  780.              if (!(Levitation || Flying))
  781.                  (void) lava_effects();
  782.              newsym(x, y);
  783.              return &zeroobj;
  784.          }
  785.  
  786.          if (!BSTRCMPI(bp, p - 5, "altar")) {
  787.              aligntyp al;
  788.  
  789.              lev->typ = ALTAR;
  790.              if (!strncmpi(bp, "chaotic ", 8))
  791.                  al = A_CHAOTIC;
  792.              else if (!strncmpi(bp, "neutral ", 8))
  793.                  al = A_NEUTRAL;
  794.              else if (!strncmpi(bp, "lawful ", 7))
  795.                  al = A_LAWFUL;
  796.              else if (!strncmpi(bp, "unaligned ", 10))
  797.                  al = A_NONE;
  798.              else /* -1 - A_CHAOTIC, 0 - A_NEUTRAL, 1 - A_LAWFUL */
  799.                  al = (!rn2(6)) ? A_NONE : rn2((int) A_LAWFUL + 2) - 1;
  800.              lev->altarmask = Align2amask(al);
  801.              pline("%s altar.", An(align_str(al)));
  802.              newsym(x, y);
  803.              return &zeroobj;
  804.          }
  805.  
  806.          if (!BSTRCMPI(bp, p - 5, "grave")
  807.              || !BSTRCMPI(bp, p - 9, "headstone")) {
  808.              make_grave(x, y, (char *) 0);
  809.              pline("%s.", IS_GRAVE(lev->typ) ? "A grave"
  810.                                              : "Can't place a grave here");
  811.              newsym(x, y);
  812.              return &zeroobj;
  813.          }
  814.  
  815.          if (!BSTRCMPI(bp, p - 4, "tree")) {
  816.              lev->typ = TREE;
  817.              pline("A tree.");
  818.              newsym(x, y);
  819.              block_point(x, y);
  820.              return &zeroobj;
  821.          }
  822.  
  823.          if (!BSTRCMPI(bp, p - 4, "bars")) {
  824.              lev->typ = IRONBARS;
  825.              pline("Iron bars.");
  826.              newsym(x, y);
  827.              return &zeroobj;
  828.          }
  829.      }
  830.  
  831.      if (!oclass && !typ) {
  832.          if (!strncmpi(bp, "polearm", 7)) {
  833.              typ = rnd_otyp_by_wpnskill(P_POLEARMS);
  834.              goto typfnd;
  835.          } else if (!strncmpi(bp, "hammer", 6)) {
  836.              typ = rnd_otyp_by_wpnskill(P_HAMMER);
  837.              goto typfnd;
  838.          }
  839.      }
  840.  
  841.      if (!oclass)
  842.          return ((struct obj *) 0);
  843.  any:
  844.      if (!oclass)
  845.          oclass = wrpsym[rn2((int) sizeof(wrpsym))];
  846.  typfnd:
  847.      if (typ)
  848.          oclass = objects[typ].oc_class;
  849.  
  850.      /* handle some objects that are only allowed in wizard mode */
  851.      if (typ && !wizard) {
  852.          switch (typ) {
  853.          case AMULET_OF_YENDOR:
  854.              typ = FAKE_AMULET_OF_YENDOR;
  855.              break;
  856.          case CANDELABRUM_OF_INVOCATION:
  857.              typ = rnd_class(TALLOW_CANDLE, WAX_CANDLE);
  858.              break;
  859.          case BELL_OF_OPENING:
  860.              typ = BELL;
  861.              break;
  862.          case SPE_BOOK_OF_THE_DEAD:
  863.              typ = SPE_BLANK_PAPER;
  864.              break;
  865.          case MAGIC_LAMP:
  866.              typ = OIL_LAMP;
  867.              break;
  868.          default:
  869.              /* catch any other non-wishable objects (venom) */
  870.              if (objects[typ].oc_nowish)
  871.                  return (struct obj *) 0;
  872.              break;
  873.          }
  874.      }
  875.  
  876.      /*
  877.       * Create the object, then fine-tune it.
  878.       */
  879.      otmp = typ ? mksobj(typ, TRUE, FALSE) : mkobj(oclass, FALSE);
  880.      typ = otmp->otyp, oclass = otmp->oclass; /* what we actually got */
  881.  
  882.      if (islit && (typ == OIL_LAMP || typ == MAGIC_LAMP || typ == BRASS_LANTERN
  883.                    || Is_candle(otmp) || typ == POT_OIL)) {
  884.          place_object(otmp, u.ux, u.uy); /* make it viable light source */
  885.          begin_burn(otmp, FALSE);
  886.          obj_extract_self(otmp); /* now release it for caller's use */
  887.      }
  888.  
  889.      /* if player specified a reasonable count, maybe honor it */
  890.      if (cnt > 0 && objects[typ].oc_merge
  891.          && (wizard || cnt < rnd(6) || (cnt <= 7 && Is_candle(otmp))
  892.              || (cnt <= 20 && ((oclass == WEAPON_CLASS && is_ammo(otmp))
  893.                                || typ == ROCK || is_missile(otmp)))))
  894.          otmp->quan = (long) cnt;
  895.  
  896.      if (oclass == VENOM_CLASS)
  897.          otmp->spe = 1;
  898.  
  899.      if (spesgn == 0) {
  900.          spe = otmp->spe;
  901.      } else if (wizard) {
  902.          ; /* no alteration to spe */
  903.      } else if (oclass == ARMOR_CLASS || oclass == WEAPON_CLASS
  904.                 || is_weptool(otmp)
  905.                 || (oclass == RING_CLASS && objects[typ].oc_charged)) {
  906.          if (spe > rnd(5) && spe > otmp->spe)
  907.              spe = 0;
  908.          if (spe > 2 && Luck < 0)
  909.              spesgn = -1;
  910.      } else {
  911.          if (oclass == WAND_CLASS) {
  912.              if (spe > 1 && spesgn == -1)
  913.                  spe = 1;
  914.          } else {
  915.              if (spe > 0 && spesgn == -1)
  916.                  spe = 0;
  917.          }
  918.          if (spe > otmp->spe)
  919.              spe = otmp->spe;
  920.      }
  921.  
  922.      if (spesgn == -1)
  923.          spe = -spe;
  924.  
  925.      /* set otmp->spe.  This may, or may not, use spe... */
  926.      switch (typ) {
  927.      case TIN:
  928.          if (contents == EMPTY) {
  929.              otmp->corpsenm = NON_PM;
  930.              otmp->spe = 0;
  931.          } else if (contents == SPINACH) {
  932.              otmp->corpsenm = NON_PM;
  933.              otmp->spe = 1;
  934.          }
  935.          break;
  936.      case TOWEL:
  937.          if (wetness)
  938.              otmp->spe = wetness;
  939.          break;
  940.      case SLIME_MOLD:
  941.          otmp->spe = ftype;
  942.      /* Fall through */
  943.      case SKELETON_KEY:
  944.      case CHEST:
  945.      case LARGE_BOX:
  946.      case HEAVY_IRON_BALL:
  947.      case IRON_CHAIN:
  948.      case STATUE:
  949.          /* otmp->cobj already done in mksobj() */
  950.          break;
  951.  #ifdef MAIL
  952.      case SCR_MAIL:
  953.          /* 0: delivered in-game via external event (or randomly for fake mail);
  954.             1: from bones or wishing; 2: written with marker */
  955.          otmp->spe = 1;
  956.          break;
  957.  #endif
  958.      case WAN_WISHING:
  959.          if (!wizard) {
  960.              otmp->spe = (rn2(10) ? -1 : 0);
  961.              break;
  962.          }
  963.          /*FALLTHRU*/
  964.      default:
  965.          otmp->spe = spe;
  966.      }
  967.  
  968.      /* set otmp->corpsenm or dragon scale [mail] */
  969.      if (mntmp >= LOW_PM) {
  970.          if (mntmp == PM_LONG_WORM_TAIL)
  971.              mntmp = PM_LONG_WORM;
  972.  
  973.          switch (typ) {
  974.          case TIN:
  975.              otmp->spe = 0; /* No spinach */
  976.              if (dead_species(mntmp, FALSE)) {
  977.                  otmp->corpsenm = NON_PM; /* it's empty */
  978.              } else if ((!(mons[mntmp].geno & G_UNIQ) || wizard)
  979.                         && !(mvitals[mntmp].mvflags & G_NOCORPSE)
  980.                         && mons[mntmp].cnutrit != 0) {
  981.                  otmp->corpsenm = mntmp;
  982.              }
  983.              break;
  984.          case CORPSE:
  985.              if ((!(mons[mntmp].geno & G_UNIQ) || wizard)
  986.                  && !(mvitals[mntmp].mvflags & G_NOCORPSE)) {
  987.                  if (mons[mntmp].msound == MS_GUARDIAN)
  988.                      mntmp = genus(mntmp, 1);
  989.                  set_corpsenm(otmp, mntmp);
  990.              }
  991.              break;
  992.          case EGG:
  993.              mntmp = can_be_hatched(mntmp);
  994.              /* this also sets hatch timer if appropriate */
  995.              set_corpsenm(otmp, mntmp);
  996.              break;
  997.          case FIGURINE:
  998.              if (!(mons[mntmp].geno & G_UNIQ) && !is_human(&mons[mntmp])
  999.  #ifdef MAIL
  1000.                  && mntmp != PM_MAIL_DAEMON
  1001.  #endif
  1002.                  )
  1003.                  otmp->corpsenm = mntmp;
  1004.              break;
  1005.          case STATUE:
  1006.              otmp->corpsenm = mntmp;
  1007.              if (Has_contents(otmp) && verysmall(&mons[mntmp]))
  1008.                  delete_contents(otmp); /* no spellbook */
  1009.              otmp->spe = ishistoric ? STATUE_HISTORIC : 0;
  1010.              break;
  1011.          case SCALE_MAIL:
  1012.              /* Dragon mail - depends on the order of objects & dragons. */
  1013.              if (mntmp >= PM_GRAY_DRAGON && mntmp <= PM_YELLOW_DRAGON)
  1014.                  otmp->otyp = GRAY_DRAGON_SCALE_MAIL + mntmp - PM_GRAY_DRAGON;
  1015.              break;
  1016.          }
  1017.      }
  1018.  
  1019.      /* set blessed/cursed -- setting the fields directly is safe
  1020.       * since weight() is called below and addinv() will take care
  1021.       * of luck */
  1022.      if (iscursed) {
  1023.          curse(otmp);
  1024.      } else if (uncursed) {
  1025.          otmp->blessed = 0;
  1026.          otmp->cursed = (Luck < 0 && !wizard);
  1027.      } else if (blessed) {
  1028.          otmp->blessed = (Luck >= 0 || wizard);
  1029.          otmp->cursed = (Luck < 0 && !wizard);
  1030.      } else if (spesgn < 0) {
  1031.          curse(otmp);
  1032.      }
  1033.  
  1034.      /* set eroded and erodeproof */
  1035.      if (erosion_matters(otmp)) {
  1036.          if (eroded && (is_flammable(otmp) || is_rustprone(otmp)))
  1037.              otmp->oeroded = eroded;
  1038.          if (eroded2 && (is_corrodeable(otmp) || is_rottable(otmp)))
  1039.              otmp->oeroded2 = eroded2;
  1040.          /*
  1041.           * 3.6.1: earlier versions included `&& !eroded && !eroded2' here,
  1042.           * but damageproof combined with damaged is feasible (eroded
  1043.           * armor modified by confused reading of cursed destroy armor)
  1044.           * so don't prevent player from wishing for such a combination.
  1045.           */
  1046.          if (erodeproof && (is_damageable(otmp) || otmp->otyp == CRYSKNIFE))
  1047.              otmp->oerodeproof = (Luck >= 0 || wizard);
  1048.      }
  1049.  
  1050.      /* set otmp->recharged */
  1051.      if (oclass == WAND_CLASS) {
  1052.          /* prevent wishing abuse */
  1053.          if (otmp->otyp == WAN_WISHING && !wizard)
  1054.              rechrg = 1;
  1055.          otmp->recharged = (unsigned) rechrg;
  1056.      }
  1057.  
  1058.      /* set poisoned */
  1059.      if (ispoisoned) {
  1060.          if (is_poisonable(otmp))
  1061.              otmp->opoisoned = (Luck >= 0);
  1062.          else if (oclass == FOOD_CLASS)
  1063.              /* try to taint by making it as old as possible */
  1064.              otmp->age = 1L;
  1065.      }
  1066.      /* and [un]trapped */
  1067.      if (trapped) {
  1068.          if (Is_box(otmp) || typ == TIN)
  1069.              otmp->otrapped = (trapped == 1);
  1070.      }
  1071.      /* empty for containers rather than for tins */
  1072.      if (contents == EMPTY) {
  1073.          if (otmp->otyp == BAG_OF_TRICKS || otmp->otyp == HORN_OF_PLENTY) {
  1074.              if (otmp->spe > 0)
  1075.                  otmp->spe = 0;
  1076.          } else if (Has_contents(otmp)) {
  1077.              /* this assumes that artifacts can't be randomly generated
  1078.                 inside containers */
  1079.              delete_contents(otmp);
  1080.              otmp->owt = weight(otmp);
  1081.          }
  1082.      }
  1083.      /* set locked/unlocked/broken */
  1084.      if (Is_box(otmp)) {
  1085.          if (locked) {
  1086.              otmp->olocked = 1, otmp->obroken = 0;
  1087.          } else if (unlocked) {
  1088.              otmp->olocked = 0, otmp->obroken = 0;
  1089.          } else if (broken) {
  1090.              otmp->olocked = 0, otmp->obroken = 1;
  1091.          }
  1092.      }
  1093.  
  1094.      if (isgreased)
  1095.          otmp->greased = 1;
  1096.  
  1097.      if (isdiluted && otmp->oclass == POTION_CLASS && otmp->otyp != POT_WATER)
  1098.          otmp->odiluted = 1;
  1099.  
  1100.      /* set tin variety */
  1101.      if (otmp->otyp == TIN && tvariety >= 0 && (rn2(4) || wizard))
  1102.          set_tin_variety(otmp, tvariety);
  1103.  
  1104.      if (name) {
  1105.          const char *aname;
  1106.          short objtyp;
  1107.  
  1108.          /* an artifact name might need capitalization fixing */
  1109.          aname = artifact_name(name, &objtyp);
  1110.          if (aname && objtyp == otmp->otyp)
  1111.              name = aname;
  1112.  
  1113.          /* 3.6 tribute - fix up novel */
  1114.          if (otmp->otyp == SPE_NOVEL) {
  1115.              const char *novelname;
  1116.  
  1117.              novelname = lookup_novel(name, &otmp->novelidx);
  1118.              if (novelname)
  1119.                  name = novelname;
  1120.          }
  1121.  
  1122.          otmp = oname(otmp, name);
  1123.          /* name==aname => wished for artifact (otmp->oartifact => got it) */
  1124.          if (otmp->oartifact || name == aname) {
  1125.              otmp->quan = 1L;
  1126.              u.uconduct.wisharti++; /* KMH, conduct */
  1127.          }
  1128.      }
  1129.  
  1130.      /* more wishing abuse: don't allow wishing for certain artifacts */
  1131.      /* and make them pay; charge them for the wish anyway! */
  1132.      if ((is_quest_artifact(otmp)
  1133.           || (otmp->oartifact && rn2(nartifact_exist()) > 1)) && !wizard) {
  1134.          artifact_exists(otmp, safe_oname(otmp), FALSE);
  1135.          obfree(otmp, (struct obj *) 0);
  1136.          otmp = &zeroobj;
  1137.          pline("For a moment, you feel %s in your %s, but it disappears!",
  1138.                something, makeplural(body_part(HAND)));
  1139.      }
  1140.  
  1141.      if (halfeaten && otmp->oclass == FOOD_CLASS) {
  1142.          if (otmp->otyp == CORPSE)
  1143.              otmp->oeaten = mons[otmp->corpsenm].cnutrit;
  1144.          else
  1145.              otmp->oeaten = objects[otmp->otyp].oc_nutrition;
  1146.          /* (do this adjustment before setting up object's weight) */
  1147.          consume_oeaten(otmp, 1);
  1148.      }
  1149.      otmp->owt = weight(otmp);
  1150.      if (very && otmp->otyp == HEAVY_IRON_BALL)
  1151.          otmp->owt += IRON_BALL_W_INCR;
  1152.      else if (gsize > 1 && otmp->globby)
  1153.          /* 0: unspecified => small; 1: small => keep default owt of 20;
  1154.             2: medium => 120; 3: large => 320; 4: very large => 520 */
  1155.          otmp->owt += 100 + (gsize - 2) * 200;
  1156.  
  1157.      return otmp;
  1158.  }
  1159.  

rnd_class

  1.  int
  2.  rnd_class(first, last)
  3.  int first, last;
  4.  {
  5.      int i, x, sum = 0;
  6.  
  7.      if (first == last)
  8.          return first;
  9.      for (i = first; i <= last; i++)
  10.          sum += objects[i].oc_prob;
  11.      if (!sum) /* all zero */
  12.          return first + rn2(last - first + 1);
  13.      x = rnd(sum);
  14.      for (i = first; i <= last; i++)
  15.          if (objects[i].oc_prob && (x -= objects[i].oc_prob) <= 0)
  16.              return i;
  17.      return 0;
  18.  }
  19.  

Japanese_item_name

  1.  STATIC_OVL const char *
  2.  Japanese_item_name(i)
  3.  int i;
  4.  {
  5.      struct Jitem *j = Japanese_items;
  6.  
  7.      while (j->item) {
  8.          if (i == j->item)
  9.              return j->name;
  10.          j++;
  11.      }
  12.      return (const char *) 0;
  13.  }
  14.  

suit_simple_name

  1.  const char *
  2.  suit_simple_name(suit)
  3.  struct obj *suit;
  4.  {
  5.      const char *suitnm, *esuitp;
  6.  
  7.      if (Is_dragon_mail(suit))
  8.          return "dragon mail"; /* <color> dragon scale mail */
  9.      else if (Is_dragon_scales(suit))
  10.          return "dragon scales";
  11.      suitnm = OBJ_NAME(objects[suit->otyp]);
  12.      esuitp = eos((char *) suitnm);
  13.      if (strlen(suitnm) > 5 && !strcmp(esuitp - 5, " mail"))
  14.          return "mail"; /* most suits fall into this category */
  15.      else if (strlen(suitnm) > 7 && !strcmp(esuitp - 7, " jacket"))
  16.          return "jacket"; /* leather jacket */
  17.      /* suit is lame but armor is ambiguous and body armor is absurd */
  18.      return "suit";
  19.  }
  20.  

cloak_simple_name

  1.  const char *
  2.  cloak_simple_name(cloak)
  3.  struct obj *cloak;
  4.  {
  5.      if (cloak) {
  6.          switch (cloak->otyp) {
  7.          case ROBE:
  8.              return "robe";
  9.          case MUMMY_WRAPPING:
  10.              return "wrapping";
  11.          case ALCHEMY_SMOCK:
  12.              return (objects[cloak->otyp].oc_name_known && cloak->dknown)
  13.                         ? "smock"
  14.                         : "apron";
  15.          default:
  16.              break;
  17.          }
  18.      }
  19.      return "cloak";
  20.  }
  21.  

helm_simple_name

  1.  /* helm vs hat for messages */
  2.  const char *
  3.  helm_simple_name(helmet)
  4.  struct obj *helmet;
  5.  {
  6.      /*
  7.       *  There is some wiggle room here; the result has been chosen
  8.       *  for consistency with the "protected by hard helmet" messages
  9.       *  given for various bonks on the head:  headgear that provides
  10.       *  such protection is a "helm", that which doesn't is a "hat".
  11.       *
  12.       *      elven leather helm / leather hat    -> hat
  13.       *      dwarvish iron helm / hard hat       -> helm
  14.       *  The rest are completely straightforward:
  15.       *      fedora, cornuthaum, dunce cap       -> hat
  16.       *      all other types of helmets          -> helm
  17.       */
  18.      return (helmet && !is_metallic(helmet)) ? "hat" : "helm";
  19.  }
  20.  

mimic_obj_name

  1.  const char *
  2.  mimic_obj_name(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (mtmp->m_ap_type == M_AP_OBJECT) {
  6.          if (mtmp->mappearance == GOLD_PIECE)
  7.              return "gold";
  8.          if (mtmp->mappearance != STRANGE_OBJECT)
  9.              return simple_typename(mtmp->mappearance);
  10.      }
  11.      return "whatcha-may-callit";
  12.  }
  13.  

safe_qbuf

  1.  /*
  2.   * Construct a query prompt string, based around an object name, which is
  3.   * guaranteed to fit within [QBUFSZ].  Takes an optional prefix, three
  4.   * choices for filling in the middle (two object formatting functions and a
  5.   * last resort literal which should be very short), and an optional suffix.
  6.   */
  7.  char *
  8.  safe_qbuf(qbuf, qprefix, qsuffix, obj, func, altfunc, lastR)
  9.  char *qbuf; /* output buffer */
  10.  const char *qprefix, *qsuffix;
  11.  struct obj *obj;
  12.  char *FDECL((*func), (OBJ_P)), *FDECL((*altfunc), (OBJ_P));
  13.  const char *lastR;
  14.  {
  15.      char *bufp, *endp;
  16.      /* convert size_t (or int for ancient systems) to ordinary unsigned */
  17.      unsigned len, lenlimit,
  18.          len_qpfx = (unsigned) (qprefix ? strlen(qprefix) : 0),
  19.          len_qsfx = (unsigned) (qsuffix ? strlen(qsuffix) : 0),
  20.          len_lastR = (unsigned) strlen(lastR);
  21.  
  22.      lenlimit = QBUFSZ - 1;
  23.      endp = qbuf + lenlimit;
  24.      /* sanity check, aimed mainly at paniclog (it's conceivable for
  25.         the result of short_oname() to be shorter than the length of
  26.         the last resort string, but we ignore that possibility here) */
  27.      if (len_qpfx > lenlimit)
  28.          impossible("safe_qbuf: prefix too long (%u characters).", len_qpfx);
  29.      else if (len_qpfx + len_qsfx > lenlimit)
  30.          impossible("safe_qbuf: suffix too long (%u + %u characters).",
  31.                     len_qpfx, len_qsfx);
  32.      else if (len_qpfx + len_lastR + len_qsfx > lenlimit)
  33.          impossible("safe_qbuf: filler too long (%u + %u + %u characters).",
  34.                     len_qpfx, len_lastR, len_qsfx);
  35.  
  36.      /* the output buffer might be the same as the prefix if caller
  37.         has already partially filled it */
  38.      if (qbuf == qprefix) {
  39.          /* prefix is already in the buffer */
  40.          *endp = '\0';
  41.      } else if (qprefix) {
  42.          /* put prefix into the buffer */
  43.          (void) strncpy(qbuf, qprefix, lenlimit);
  44.          *endp = '\0';
  45.      } else {
  46.          /* no prefix; output buffer starts out empty */
  47.          qbuf[0] = '\0';
  48.      }
  49.      len = (unsigned) strlen(qbuf);
  50.  
  51.      if (len + len_lastR + len_qsfx > lenlimit) {
  52.          /* too long; skip formatting, last resort output is truncated */
  53.          if (len < lenlimit) {
  54.              (void) strncpy(&qbuf[len], lastR, lenlimit - len);
  55.              *endp = '\0';
  56.              len = (unsigned) strlen(qbuf);
  57.              if (qsuffix && len < lenlimit) {
  58.                  (void) strncpy(&qbuf[len], qsuffix, lenlimit - len);
  59.                  *endp = '\0';
  60.                  /* len = (unsigned) strlen(qbuf); */
  61.              }
  62.          }
  63.      } else {
  64.          /* suffix and last resort are guaranteed to fit */
  65.          len += len_qsfx; /* include the pending suffix */
  66.          /* format the object */
  67.          bufp = short_oname(obj, func, altfunc, lenlimit - len);
  68.          if (len + strlen(bufp) <= lenlimit)
  69.              Strcat(qbuf, bufp); /* formatted name fits */
  70.          else
  71.              Strcat(qbuf, lastR); /* use last resort */
  72.          releaseobuf(bufp);
  73.  
  74.          if (qsuffix)
  75.              Strcat(qbuf, qsuffix);
  76.      }
  77.      /* assert( strlen(qbuf) < QBUFSZ ); */
  78.      return qbuf;
  79.  }
  80.  
  81.  /*objnam.c*/