Source:NetHack 3.6.0/src/do name.c

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

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

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

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

Top of file

  1.  /* NetHack 3.6	do_name.c	$NHDT-Date: 1446808440 2015/11/06 11:14:00 $  $NHDT-Branch: master $:$NHDT-Revision: 1.77 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  STATIC_DCL char *NDECL(nextmbuf);
  8.  STATIC_DCL void FDECL(getpos_help, (BOOLEAN_P, const char *));
  9.  STATIC_DCL void NDECL(do_mname);
  10.  STATIC_DCL void FDECL(do_oname, (struct obj *));
  11.  STATIC_DCL void NDECL(namefloorobj);
  12.  STATIC_DCL char *FDECL(bogusmon, (char *,char *));
  13.  
  14.  extern const char what_is_an_unknown_object[]; /* from pager.c */
  15.  
  16.  #define NUMMBUF 5
  17.  

nextmbuf

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

getpos_sethilite

  1.  /* function for getpos() to highlight desired map locations.
  2.   * parameter value 0 = initialize, 1 = highlight, 2 = done
  3.   */
  4.  void FDECL((*getpos_hilitefunc), (int)) = (void FDECL((*), (int))) 0;
  5.  
  6.  void
  7.  getpos_sethilite(f)
  8.  void FDECL((*f), (int));
  9.  {
  10.      getpos_hilitefunc = f;
  11.  }
  12.  

getpos_help

  1.  /* the response for '?' help request in getpos() */
  2.  STATIC_OVL void
  3.  getpos_help(force, goal)
  4.  boolean force;
  5.  const char *goal;
  6.  {
  7.      char sbuf[BUFSZ];
  8.      boolean doing_what_is;
  9.      winid tmpwin = create_nhwindow(NHW_MENU);
  10.  
  11.      Sprintf(sbuf, "Use [%c%c%c%c] to move the cursor to %s.", /* hjkl */
  12.              Cmd.move_W, Cmd.move_S, Cmd.move_N, Cmd.move_E, goal);
  13.      putstr(tmpwin, 0, sbuf);
  14.      putstr(tmpwin, 0, "Use [HJKL] to move the cursor 8 units at a time.");
  15.      putstr(tmpwin, 0, "Or enter a background symbol (ex. <).");
  16.      putstr(tmpwin, 0, "Use @ to move the cursor on yourself.");
  17.      if (getpos_hilitefunc != NULL)
  18.          putstr(tmpwin, 0, "Use $ to display valid locations.");
  19.      putstr(tmpwin, 0, "Use # to toggle automatic description.");
  20.      /* disgusting hack; the alternate selection characters work for any
  21.         getpos call, but they only matter for dowhatis (and doquickwhatis) */
  22.      doing_what_is = (goal == what_is_an_unknown_object);
  23.      Sprintf(sbuf, "Type a .%s when you are at the right place.",
  24.              doing_what_is ? " or , or ; or :" : "");
  25.      putstr(tmpwin, 0, sbuf);
  26.      if (!force)
  27.          putstr(tmpwin, 0, "Type Space or Escape when you're done.");
  28.      putstr(tmpwin, 0, "");
  29.      display_nhwindow(tmpwin, TRUE);
  30.      destroy_nhwindow(tmpwin);
  31.  }
  32.  

getpos

  1.  int
  2.  getpos(ccp, force, goal)
  3.  coord *ccp;
  4.  boolean force;
  5.  const char *goal;
  6.  {
  7.      int result = 0;
  8.      int cx, cy, i, c;
  9.      int sidx, tx, ty;
  10.      boolean msg_given = TRUE; /* clear message window by default */
  11.      boolean auto_msg = FALSE;
  12.      boolean show_goal_msg = FALSE;
  13.      static const char pick_chars[] = ".,;:";
  14.      const char *cp;
  15.      boolean hilite_state = FALSE;
  16.  
  17.      if (!goal)
  18.          goal = "desired location";
  19.      if (flags.verbose) {
  20.          pline("(For instructions type a ?)");
  21.          msg_given = TRUE;
  22.      }
  23.      cx = ccp->x;
  24.      cy = ccp->y;
  25.  #ifdef CLIPPING
  26.      cliparound(cx, cy);
  27.  #endif
  28.      curs(WIN_MAP, cx, cy);
  29.      flush_screen(0);
  30.  #ifdef MAC
  31.      lock_mouse_cursor(TRUE);
  32.  #endif
  33.      for (;;) {
  34.          if (show_goal_msg) {
  35.              pline("Move cursor to %s:", goal);
  36.              curs(WIN_MAP, cx, cy);
  37.              flush_screen(0);
  38.              show_goal_msg = FALSE;
  39.          } else if (auto_msg && !msg_given && !hilite_state) {
  40.              coord cc;
  41.              int sym = 0;
  42.              char tmpbuf[BUFSZ];
  43.              const char *firstmatch = NULL;
  44.  
  45.              cc.x = cx;
  46.              cc.y = cy;
  47.              if (do_screen_description(cc, TRUE, sym, tmpbuf, &firstmatch)) {
  48.                  pline1(firstmatch);
  49.                  curs(WIN_MAP, cx, cy);
  50.                  flush_screen(0);
  51.              }
  52.          }
  53.  
  54.          c = nh_poskey(&tx, &ty, &sidx);
  55.  
  56.          if (hilite_state) {
  57.              (*getpos_hilitefunc)(2);
  58.              hilite_state = FALSE;
  59.              curs(WIN_MAP, cx, cy);
  60.              flush_screen(0);
  61.          }
  62.  
  63.          if (auto_msg)
  64.              msg_given = FALSE;
  65.  
  66.          if (c == '\033') {
  67.              cx = cy = -10;
  68.              msg_given = TRUE; /* force clear */
  69.              result = -1;
  70.              break;
  71.          }
  72.          if (c == 0) {
  73.              if (!isok(tx, ty))
  74.                  continue;
  75.              /* a mouse click event, just assign and return */
  76.              cx = tx;
  77.              cy = ty;
  78.              break;
  79.          }
  80.          if ((cp = index(pick_chars, c)) != 0) {
  81.              /* '.' => 0, ',' => 1, ';' => 2, ':' => 3 */
  82.              result = (int) (cp - pick_chars);
  83.              break;
  84.          }
  85.          for (i = 0; i < 8; i++) {
  86.              int dx, dy;
  87.  
  88.              if (Cmd.dirchars[i] == c) {
  89.                  /* a normal movement letter or digit */
  90.                  dx = xdir[i];
  91.                  dy = ydir[i];
  92.              } else if (Cmd.alphadirchars[i] == lowc((char) c)
  93.                         || (Cmd.num_pad && Cmd.dirchars[i] == (c & 0177))) {
  94.                  /* a shifted movement letter or Meta-digit */
  95.                  dx = 8 * xdir[i];
  96.                  dy = 8 * ydir[i];
  97.              } else
  98.                  continue;
  99.  
  100.              /* truncate at map edge; diagonal moves complicate this... */
  101.              if (cx + dx < 1) {
  102.                  dy -= sgn(dy) * (1 - (cx + dx));
  103.                  dx = 1 - cx; /* so that (cx+dx == 1) */
  104.              } else if (cx + dx > COLNO - 1) {
  105.                  dy += sgn(dy) * ((COLNO - 1) - (cx + dx));
  106.                  dx = (COLNO - 1) - cx;
  107.              }
  108.              if (cy + dy < 0) {
  109.                  dx -= sgn(dx) * (0 - (cy + dy));
  110.                  dy = 0 - cy; /* so that (cy+dy == 0) */
  111.              } else if (cy + dy > ROWNO - 1) {
  112.                  dx += sgn(dx) * ((ROWNO - 1) - (cy + dy));
  113.                  dy = (ROWNO - 1) - cy;
  114.              }
  115.              cx += dx;
  116.              cy += dy;
  117.              goto nxtc;
  118.          }
  119.  
  120.          if (c == '?' || redraw_cmd(c)) {
  121.              if (c == '?')
  122.                  getpos_help(force, goal);
  123.              else         /* ^R */
  124.                  docrt(); /* redraw */
  125.              /* update message window to reflect that we're still targetting */
  126.              show_goal_msg = TRUE;
  127.              msg_given = TRUE;
  128.          } else if ((c == '$') && (getpos_hilitefunc != NULL)) {
  129.              if (!hilite_state) {
  130.                  (*getpos_hilitefunc)(0);
  131.                  (*getpos_hilitefunc)(1);
  132.                  hilite_state = TRUE;
  133.              }
  134.              goto nxtc;
  135.          } else if (c == '#') {
  136.              auto_msg = !auto_msg;
  137.              pline("Automatic description %sis %s.",
  138.                    flags.verbose ? "of features under cursor " : "",
  139.                    auto_msg ? "on" : "off");
  140.              if (!auto_msg)
  141.                  show_goal_msg = TRUE;
  142.              msg_given = TRUE;
  143.              goto nxtc;
  144.          } else if (c == '@') {
  145.              cx = u.ux;
  146.              cy = u.uy;
  147.              goto nxtc;
  148.          } else {
  149.              if (!index(quitchars, c)) {
  150.                  char matching[MAXPCHARS];
  151.                  int pass, lo_x, lo_y, hi_x, hi_y, k = 0;
  152.                  (void) memset((genericptr_t) matching, 0, sizeof matching);
  153.                  for (sidx = 1; sidx < MAXPCHARS; sidx++)
  154.                      if (c == defsyms[sidx].sym || c == (int) showsyms[sidx])
  155.                          matching[sidx] = (char) ++k;
  156.                  if (k) {
  157.                      for (pass = 0; pass <= 1; pass++) {
  158.                          /* pass 0: just past current pos to lower right;
  159.                             pass 1: upper left corner to current pos */
  160.                          lo_y = (pass == 0) ? cy : 0;
  161.                          hi_y = (pass == 0) ? ROWNO - 1 : cy;
  162.                          for (ty = lo_y; ty <= hi_y; ty++) {
  163.                              lo_x = (pass == 0 && ty == lo_y) ? cx + 1 : 1;
  164.                              hi_x = (pass == 1 && ty == hi_y) ? cx : COLNO - 1;
  165.                              for (tx = lo_x; tx <= hi_x; tx++) {
  166.                                  /* look at dungeon feature, not at
  167.                                   * user-visible glyph */
  168.                                  k = back_to_glyph(tx, ty);
  169.                                  /* uninteresting background glyph */
  170.                                  if (glyph_is_cmap(k)
  171.                                      && (IS_DOOR(levl[tx][ty].typ)
  172.                                          || glyph_to_cmap(k) == S_room
  173.                                          || glyph_to_cmap(k) == S_darkroom
  174.                                          || glyph_to_cmap(k) == S_corr
  175.                                          || glyph_to_cmap(k) == S_litcorr)) {
  176.                                      /* what hero remembers to be at tx,ty */
  177.                                      k = glyph_at(tx, ty);
  178.                                  }
  179.                                  if (glyph_is_cmap(k)
  180.                                      && matching[glyph_to_cmap(k)]
  181.                                      && levl[tx][ty].seenv
  182.                                      && (!IS_WALL(levl[tx][ty].typ))
  183.                                      && (levl[tx][ty].typ != SDOOR)
  184.                                      && glyph_to_cmap(k) != S_room
  185.                                      && glyph_to_cmap(k) != S_corr
  186.                                      && glyph_to_cmap(k) != S_litcorr) {
  187.                                      cx = tx, cy = ty;
  188.                                      if (msg_given) {
  189.                                          clear_nhwindow(WIN_MESSAGE);
  190.                                          msg_given = FALSE;
  191.                                      }
  192.                                      goto nxtc;
  193.                                  }
  194.                              } /* column */
  195.                          }     /* row */
  196.                      }         /* pass */
  197.                      pline("Can't find dungeon feature '%c'.", c);
  198.                      msg_given = TRUE;
  199.                      goto nxtc;
  200.                  } else {
  201.                      char note[QBUFSZ];
  202.  
  203.                      if (!force)
  204.                          Strcpy(note, "aborted");
  205.                      else
  206.                          Sprintf(note, "use %c%c%c%c or .", /* hjkl */
  207.                                  Cmd.move_W, Cmd.move_S, Cmd.move_N,
  208.                                  Cmd.move_E);
  209.                      pline("Unknown direction: '%s' (%s).", visctrl((char) c),
  210.                            note);
  211.                      msg_given = TRUE;
  212.                  } /* k => matching */
  213.              }     /* !quitchars */
  214.              if (force)
  215.                  goto nxtc;
  216.              pline("Done.");
  217.              msg_given = FALSE; /* suppress clear */
  218.              cx = -1;
  219.              cy = 0;
  220.              result = 0; /* not -1 */
  221.              break;
  222.          }
  223.      nxtc:
  224.          ;
  225.  #ifdef CLIPPING
  226.          cliparound(cx, cy);
  227.  #endif
  228.          curs(WIN_MAP, cx, cy);
  229.          flush_screen(0);
  230.      }
  231.  #ifdef MAC
  232.      lock_mouse_cursor(FALSE);
  233.  #endif
  234.      if (msg_given)
  235.          clear_nhwindow(WIN_MESSAGE);
  236.      ccp->x = cx;
  237.      ccp->y = cy;
  238.      getpos_hilitefunc = NULL;
  239.      return result;
  240.  }
  241.  

new_mname

  1.  /* allocate space for a monster's name; removes old name if there is one */
  2.  void
  3.  new_mname(mon, lth)
  4.  struct monst *mon;
  5.  int lth; /* desired length (caller handles adding 1 for terminator) */
  6.  {
  7.      if (lth) {
  8.          /* allocate mextra if necessary; otherwise get rid of old name */
  9.          if (!mon->mextra)
  10.              mon->mextra = newmextra();
  11.          else
  12.              free_mname(mon); /* already has mextra, might also have name */
  13.          MNAME(mon) = (char *) alloc((unsigned) lth);
  14.      } else {
  15.          /* zero length: the new name is empty; get rid of the old name */
  16.          if (has_mname(mon))
  17.              free_mname(mon);
  18.      }
  19.  }
  20.  

free_mname

  1.  /* release a monster's name; retains mextra even if all fields are now null */
  2.  void
  3.  free_mname(mon)
  4.  struct monst *mon;
  5.  {
  6.      if (has_mname(mon)) {
  7.          free((genericptr_t) MNAME(mon));
  8.          MNAME(mon) = (char *) 0;
  9.      }
  10.  }
  11.  

new_oname

  1.  /* allocate space for an object's name; removes old name if there is one */
  2.  void
  3.  new_oname(obj, lth)
  4.  struct obj *obj;
  5.  int lth; /* desired length (caller handles adding 1 for terminator) */
  6.  {
  7.      if (lth) {
  8.          /* allocate oextra if necessary; otherwise get rid of old name */
  9.          if (!obj->oextra)
  10.              obj->oextra = newoextra();
  11.          else
  12.              free_oname(obj); /* already has oextra, might also have name */
  13.          ONAME(obj) = (char *) alloc((unsigned) lth);
  14.      } else {
  15.          /* zero length: the new name is empty; get rid of the old name */
  16.          if (has_oname(obj))
  17.              free_oname(obj);
  18.      }
  19.  }
  20.  

free_oname

  1.  /* release an object's name; retains oextra even if all fields are now null */
  2.  void
  3.  free_oname(obj)
  4.  struct obj *obj;
  5.  {
  6.      if (has_oname(obj)) {
  7.          free((genericptr_t) ONAME(obj));
  8.          ONAME(obj) = (char *) 0;
  9.      }
  10.  }
  11.  

safe_oname

  1.  /*  safe_oname() always returns a valid pointer to
  2.   *  a string, either the pointer to an object's name
  3.   *  if it has one, or a pointer to an empty string
  4.   *  if it doesn't.
  5.   */
  6.  const char *
  7.  safe_oname(obj)
  8.  struct obj *obj;
  9.  {
  10.      if (has_oname(obj))
  11.          return ONAME(obj);
  12.      return "";
  13.  }
  14.  

christen_monst

  1.  /* historical note: this returns a monster pointer because it used to
  2.     allocate a new bigger block of memory to hold the monster and its name */
  3.  struct monst *
  4.  christen_monst(mtmp, name)
  5.  struct monst *mtmp;
  6.  const char *name;
  7.  {
  8.      int lth;
  9.      char buf[PL_PSIZ];
  10.  
  11.      /* dogname & catname are PL_PSIZ arrays; object names have same limit */
  12.      lth = (name && *name) ? ((int) strlen(name) + 1) : 0;
  13.      if (lth > PL_PSIZ) {
  14.          lth = PL_PSIZ;
  15.          name = strncpy(buf, name, PL_PSIZ - 1);
  16.          buf[PL_PSIZ - 1] = '\0';
  17.      }
  18.      new_mname(mtmp, lth); /* removes old name if one is present */
  19.      if (lth)
  20.          Strcpy(MNAME(mtmp), name);
  21.      return mtmp;
  22.  }
  23.  

do_mname

  1.  /* allow player to assign a name to some chosen monster */
  2.  STATIC_OVL void
  3.  do_mname()
  4.  {
  5.      char buf[BUFSZ], monnambuf[BUFSZ];
  6.      coord cc;
  7.      register int cx, cy;
  8.      register struct monst *mtmp;
  9.      char qbuf[QBUFSZ];
  10.  
  11.      if (Hallucination) {
  12.          You("would never recognize it anyway.");
  13.          return;
  14.      }
  15.      cc.x = u.ux;
  16.      cc.y = u.uy;
  17.      if (getpos(&cc, FALSE, "the monster you want to name") < 0
  18.          || (cx = cc.x) < 0)
  19.          return;
  20.      cy = cc.y;
  21.  
  22.      if (cx == u.ux && cy == u.uy) {
  23.          if (u.usteed && canspotmon(u.usteed))
  24.              mtmp = u.usteed;
  25.          else {
  26.              pline("This %s creature is called %s and cannot be renamed.",
  27.                    beautiful(), plname);
  28.              return;
  29.          }
  30.      } else
  31.          mtmp = m_at(cx, cy);
  32.  
  33.      if (!mtmp
  34.          || (!sensemon(mtmp)
  35.              && (!(cansee(cx, cy) || see_with_infrared(mtmp))
  36.                  || mtmp->mundetected || mtmp->m_ap_type == M_AP_FURNITURE
  37.                  || mtmp->m_ap_type == M_AP_OBJECT
  38.                  || (mtmp->minvis && !See_invisible)))) {
  39.          pline("I see no monster there.");
  40.          return;
  41.      }
  42.      /* special case similar to the one in lookat() */
  43.      Sprintf(qbuf, "What do you want to call %s?",
  44.              distant_monnam(mtmp, ARTICLE_THE, monnambuf));
  45.      getlin(qbuf, buf);
  46.      if (!*buf || *buf == '\033')
  47.          return;
  48.      /* strip leading and trailing spaces; unnames monster if all spaces */
  49.      (void) mungspaces(buf);
  50.  
  51.      /* unique monsters have their own specific names or titles;
  52.         shopkeepers, temple priests and other minions use alternate
  53.         name formatting routines which ignore any user-supplied name */
  54.      if (mtmp->data->geno & G_UNIQ)
  55.          pline("%s doesn't like being called names!", upstart(monnambuf));
  56.      else if (mtmp->isshk
  57.               && !(Deaf || mtmp->msleeping || !mtmp->mcanmove
  58.                    || mtmp->data->msound <= MS_ANIMAL))
  59.          verbalize("I'm %s, not %s.", shkname(mtmp), buf);
  60.      else if (mtmp->ispriest || mtmp->isminion || mtmp->isshk)
  61.          pline("%s will not accept the name %s.", upstart(monnambuf), buf);
  62.      else
  63.          (void) christen_monst(mtmp, buf);
  64.  }
  65.  

do_oname

  1.  /*
  2.   * This routine changes the address of obj. Be careful not to call it
  3.   * when there might be pointers around in unknown places. For now: only
  4.   * when obj is in the inventory.
  5.   */
  6.  STATIC_OVL
  7.  void
  8.  do_oname(obj)
  9.  register struct obj *obj;
  10.  {
  11.      char *bufp, buf[BUFSZ], bufcpy[BUFSZ], qbuf[QBUFSZ];
  12.      const char *aname;
  13.      short objtyp;
  14.  
  15.      /* Do this now because there's no point in even asking for a name */
  16.      if (obj->otyp == SPE_NOVEL) {
  17.          pline("%s already has a published name.", Ysimple_name2(obj));
  18.          return;
  19.      }
  20.  
  21.      Sprintf(qbuf, "What do you want to name %s ",
  22.              is_plural(obj) ? "these" : "this");
  23.      (void) safe_qbuf(qbuf, qbuf, "?", obj, xname, simpleonames, "item");
  24.      getlin(qbuf, buf);
  25.      if (!*buf || *buf == '\033')
  26.          return;
  27.      /* strip leading and trailing spaces; unnames item if all spaces */
  28.      (void) mungspaces(buf);
  29.  
  30.      /* relax restrictions over proper capitalization for artifacts */
  31.      if ((aname = artifact_name(buf, &objtyp)) != 0 && objtyp == obj->otyp)
  32.          Strcpy(buf, aname);
  33.  
  34.      if (obj->oartifact) {
  35.          pline_The("artifact seems to resist the attempt.");
  36.          return;
  37.      } else if (restrict_name(obj, buf) || exist_artifact(obj->otyp, buf)) {
  38.          /* this used to change one letter, substituting a value
  39.             of 'a' through 'y' (due to an off by one error, 'z'
  40.             would never be selected) and then force that to
  41.             upper case if such was the case of the input;
  42.             now, the hand slip scuffs one or two letters as if
  43.             the text had been trodden upon, sometimes picking
  44.             punctuation instead of an arbitrary letter;
  45.             unfortunately, we have to cover the possibility of
  46.             it targetting spaces so failing to make any change
  47.             (we know that it must eventually target a nonspace
  48.             because buf[] matches a valid artifact name) */
  49.          Strcpy(bufcpy, buf);
  50.          /* for "the Foo of Bar", only scuff "Foo of Bar" part */
  51.          bufp = !strncmpi(bufcpy, "the ", 4) ? (buf + 4) : buf;
  52.          do {
  53.              wipeout_text(bufp, rnd(2), (unsigned) 0);
  54.          } while (!strcmp(buf, bufcpy));
  55.          pline("While engraving, your %s slips.", body_part(HAND));
  56.          display_nhwindow(WIN_MESSAGE, FALSE);
  57.          You("engrave: \"%s\".", buf);
  58.      }
  59.      obj = oname(obj, buf);
  60.  }
  61.  

oname

  1.  struct obj *
  2.  oname(obj, name)
  3.  struct obj *obj;
  4.  const char *name;
  5.  {
  6.      int lth;
  7.      char buf[PL_PSIZ];
  8.  
  9.      lth = *name ? (int) (strlen(name) + 1) : 0;
  10.      if (lth > PL_PSIZ) {
  11.          lth = PL_PSIZ;
  12.          name = strncpy(buf, name, PL_PSIZ - 1);
  13.          buf[PL_PSIZ - 1] = '\0';
  14.      }
  15.      /* If named artifact exists in the game, do not create another.
  16.       * Also trying to create an artifact shouldn't de-artifact
  17.       * it (e.g. Excalibur from prayer). In this case the object
  18.       * will retain its current name. */
  19.      if (obj->oartifact || (lth && exist_artifact(obj->otyp, name)))
  20.          return obj;
  21.  
  22.      new_oname(obj, lth); /* removes old name if one is present */
  23.      if (lth)
  24.          Strcpy(ONAME(obj), name);
  25.  
  26.      if (lth)
  27.          artifact_exists(obj, name, TRUE);
  28.      if (obj->oartifact) {
  29.          /* can't dual-wield with artifact as secondary weapon */
  30.          if (obj == uswapwep)
  31.              untwoweapon();
  32.          /* activate warning if you've just named your weapon "Sting" */
  33.          if (obj == uwep)
  34.              set_artifact_intrinsic(obj, TRUE, W_WEP);
  35.          /* if obj is owned by a shop, increase your bill */
  36.          if (obj->unpaid)
  37.              alter_cost(obj, 0L);
  38.      }
  39.      if (carried(obj))
  40.          update_inventory();
  41.      return obj;
  42.  }
  43.  

objtyp_is_callable

  1.  static NEARDATA const char callable[] = {
  2.      SCROLL_CLASS, POTION_CLASS, WAND_CLASS,  RING_CLASS, AMULET_CLASS,
  3.      GEM_CLASS,    SPBOOK_CLASS, ARMOR_CLASS, TOOL_CLASS, 0
  4.  };
  5.  
  6.  boolean
  7.  objtyp_is_callable(i)
  8.  int i;
  9.  {
  10.      return (boolean) (objects[i].oc_uname
  11.                        || (OBJ_DESCR(objects[i])
  12.                            && index(callable, objects[i].oc_class)));
  13.  }
  14.  

docallcmd

  1.  /* C and #name commands - player can name monster or object or type of obj */
  2.  int
  3.  docallcmd()
  4.  {
  5.      struct obj *obj;
  6.      winid win;
  7.      anything any;
  8.      menu_item *pick_list = 0;
  9.      char ch, allowall[2];
  10.      /* if player wants a,b,c instead of i,o when looting, do that here too */
  11.      boolean abc = flags.lootabc;
  12.  
  13.      win = create_nhwindow(NHW_MENU);
  14.      start_menu(win);
  15.      any = zeroany;
  16.      any.a_char = 'm'; /* group accelerator 'C' */
  17.      add_menu(win, NO_GLYPH, &any, abc ? 0 : any.a_char, 'C', ATR_NONE,
  18.               "a monster", MENU_UNSELECTED);
  19.      if (invent) {
  20.          /* we use y and n as accelerators so that we can accept user's
  21.             response keyed to old "name an individual object?" prompt */
  22.          any.a_char = 'i'; /* group accelerator 'y' */
  23.          add_menu(win, NO_GLYPH, &any, abc ? 0 : any.a_char, 'y', ATR_NONE,
  24.                   "a particular object in inventory", MENU_UNSELECTED);
  25.          any.a_char = 'o'; /* group accelerator 'n' */
  26.          add_menu(win, NO_GLYPH, &any, abc ? 0 : any.a_char, 'n', ATR_NONE,
  27.                   "the type of an object in inventory", MENU_UNSELECTED);
  28.      }
  29.      any.a_char = 'f'; /* group accelerator ',' (or ':' instead?) */
  30.      add_menu(win, NO_GLYPH, &any, abc ? 0 : any.a_char, ',', ATR_NONE,
  31.               "the type of an object upon the floor", MENU_UNSELECTED);
  32.      any.a_char = 'd'; /* group accelerator '\' */
  33.      add_menu(win, NO_GLYPH, &any, abc ? 0 : any.a_char, '\\', ATR_NONE,
  34.               "the type of an object on discoveries list", MENU_UNSELECTED);
  35.      any.a_char = 'a'; /* group accelerator 'l' */
  36.      add_menu(win, NO_GLYPH, &any, abc ? 0 : any.a_char, 'l', ATR_NONE,
  37.               "record an annotation for the current level", MENU_UNSELECTED);
  38.      end_menu(win, "What do you want to name?");
  39.      if (select_menu(win, PICK_ONE, &pick_list) > 0) {
  40.          ch = pick_list[0].item.a_char;
  41.          free((genericptr_t) pick_list);
  42.      } else
  43.          ch = 'q';
  44.      destroy_nhwindow(win);
  45.  
  46.      switch (ch) {
  47.      default:
  48.      case 'q':
  49.          break;
  50.      case 'm': /* name a visible monster */
  51.          do_mname();
  52.          break;
  53.      case 'i': /* name an individual object in inventory */
  54.          allowall[0] = ALL_CLASSES;
  55.          allowall[1] = '\0';
  56.          obj = getobj(allowall, "name");
  57.          if (obj)
  58.              do_oname(obj);
  59.          break;
  60.      case 'o': /* name a type of object in inventory */
  61.          obj = getobj(callable, "call");
  62.          if (obj) {
  63.              /* behave as if examining it in inventory;
  64.                 this might set dknown if it was picked up
  65.                 while blind and the hero can now see */
  66.              (void) xname(obj);
  67.  
  68.              if (!obj->dknown) {
  69.                  You("would never recognize another one.");
  70.  #if 0
  71.              } else if (!objtyp_is_callable(obj->otyp)) {
  72.                  You("know those as well as you ever will.");
  73.  #endif
  74.              } else {
  75.                  docall(obj);
  76.              }
  77.          }
  78.          break;
  79.      case 'f': /* name a type of object visible on the floor */
  80.          namefloorobj();
  81.          break;
  82.      case 'd': /* name a type of object on the discoveries list */
  83.          rename_disco();
  84.          break;
  85.      case 'a': /* annotate level */
  86.          donamelevel();
  87.          break;
  88.      }
  89.      return 0;
  90.  }
  91.  

docall

  1.  void
  2.  docall(obj)
  3.  register struct obj *obj;
  4.  {
  5.      char buf[BUFSZ], qbuf[QBUFSZ];
  6.      struct obj otemp;
  7.      register char **str1;
  8.  
  9.      if (!obj->dknown)
  10.          return; /* probably blind */
  11.      otemp = *obj;
  12.      otemp.quan = 1L;
  13.      otemp.oextra = (struct oextra *) 0;
  14.  
  15.      if (objects[otemp.otyp].oc_class == POTION_CLASS && otemp.fromsink)
  16.          /* kludge, meaning it's sink water */
  17.          Sprintf(qbuf, "Call a stream of %s fluid:",
  18.                  OBJ_DESCR(objects[otemp.otyp]));
  19.      else
  20.          Sprintf(qbuf, "Call %s:", an(xname(&otemp)));
  21.      getlin(qbuf, buf);
  22.      if (!*buf || *buf == '\033')
  23.          return;
  24.  
  25.      /* clear old name */
  26.      str1 = &(objects[obj->otyp].oc_uname);
  27.      if (*str1)
  28.          free((genericptr_t) *str1);
  29.  
  30.      /* strip leading and trailing spaces; uncalls item if all spaces */
  31.      (void) mungspaces(buf);
  32.      if (!*buf) {
  33.          if (*str1) { /* had name, so possibly remove from disco[] */
  34.              /* strip name first, for the update_inventory() call
  35.                 from undiscover_object() */
  36.              *str1 = (char *) 0;
  37.              undiscover_object(obj->otyp);
  38.          }
  39.      } else {
  40.          *str1 = dupstr(buf);
  41.          discover_object(obj->otyp, FALSE, TRUE); /* possibly add to disco[] */
  42.      }
  43.  }
  44.  

namefloorobj

  1.  STATIC_OVL void
  2.  namefloorobj()
  3.  {
  4.      coord cc;
  5.      int glyph;
  6.      char buf[BUFSZ];
  7.      struct obj *obj = 0;
  8.      boolean fakeobj = FALSE, use_plural;
  9.  
  10.      cc.x = u.ux, cc.y = u.uy;
  11.      /* "dot for under/over you" only makes sense when the cursor hasn't
  12.         been moved off the hero's '@' yet, but there's no way to adjust
  13.         the help text once getpos() has started */
  14.      Sprintf(buf, "object on map (or '.' for one %s you)",
  15.              (u.uundetected && hides_under(youmonst.data)) ? "over" : "under");
  16.      if (getpos(&cc, FALSE, buf) < 0 || cc.x <= 0)
  17.          return;
  18.      if (cc.x == u.ux && cc.y == u.uy) {
  19.          obj = vobj_at(u.ux, u.uy);
  20.      } else {
  21.          glyph = glyph_at(cc.x, cc.y);
  22.          if (glyph_is_object(glyph))
  23.              fakeobj = object_from_map(glyph, cc.x, cc.y, &obj);
  24.          /* else 'obj' stays null */
  25.      }
  26.      if (!obj) {
  27.          /* "under you" is safe here since there's no object to hide under */
  28.          pline("There doesn't seem to be any object %s.",
  29.                (cc.x == u.ux && cc.y == u.uy) ? "under you" : "there");
  30.          return;
  31.      }
  32.      /* note well: 'obj' might be as instance of STRANGE_OBJECT if target
  33.         is a mimic; passing that to xname (directly or via simpleonames)
  34.         would yield "glorkum" so we need to handle it explicitly; it will
  35.         always fail the Hallucination test and pass the !callable test,
  36.         resulting in the "can't be assigned a type name" message */
  37.      Strcpy(buf, (obj->otyp != STRANGE_OBJECT)
  38.                   ? simpleonames(obj)
  39.                   : obj_descr[STRANGE_OBJECT].oc_name);
  40.      use_plural = (obj->quan > 1L);
  41.      if (Hallucination) {
  42.          const char *unames[6];
  43.          char tmpbuf[BUFSZ];
  44.  
  45.          /* straight role name */
  46.          unames[0] = ((Upolyd ? u.mfemale : flags.female) && urole.name.f)
  47.                       ? urole.name.f
  48.                       : urole.name.m;
  49.          /* random rank title for hero's role */
  50.          unames[1] = rank_of(rnd(30), Role_switch, flags.female);
  51.          /* random fake monster */
  52.          unames[2] = bogusmon(tmpbuf, (char *) 0);
  53.          /* increased chance for fake monster */
  54.          unames[3] = unames[2];
  55.          /* traditional */
  56.          unames[4] = roguename();
  57.          /* silly */
  58.          unames[5] = "Wibbly Wobbly";
  59.          pline("%s %s to call you \"%s.\"",
  60.                The(buf), use_plural ? "decide" : "decides",
  61.                unames[rn2(SIZE(unames))]);
  62.      } else if (!objtyp_is_callable(obj->otyp)) {
  63.          pline("%s %s can't be assigned a type name.",
  64.                use_plural ? "Those" : "That", buf);
  65.      } else if (!obj->dknown) {
  66.          You("don't know %s %s well enough to name %s.",
  67.              use_plural ? "those" : "that", buf, use_plural ? "them" : "it");
  68.      } else {
  69.          docall(obj);
  70.      }
  71.      if (fakeobj)
  72.          dealloc_obj(obj);
  73.  }
  74.  

rndghostname

  1.  static const char *const ghostnames[] = {
  2.      /* these names should have length < PL_NSIZ */
  3.      /* Capitalize the names for aesthetics -dgk */
  4.      "Adri",    "Andries",       "Andreas",     "Bert",    "David",  "Dirk",
  5.      "Emile",   "Frans",         "Fred",        "Greg",    "Hether", "Jay",
  6.      "John",    "Jon",           "Karnov",      "Kay",     "Kenny",  "Kevin",
  7.      "Maud",    "Michiel",       "Mike",        "Peter",   "Robert", "Ron",
  8.      "Tom",     "Wilmar",        "Nick Danger", "Phoenix", "Jiro",   "Mizue",
  9.      "Stephan", "Lance Braccus", "Shadowhawk"
  10.  };
  11.  
  12.  /* ghost names formerly set by x_monnam(), now by makemon() instead */
  13.  const char *
  14.  rndghostname()
  15.  {
  16.      return rn2(7) ? ghostnames[rn2(SIZE(ghostnames))] : (const char *) plname;
  17.  }
  18.  

x_monnam

  1.  /*
  2.   * Monster naming functions:
  3.   * x_monnam is the generic monster-naming function.
  4.   *                seen        unseen       detected               named
  5.   * mon_nam:     the newt        it      the invisible orc       Fido
  6.   * noit_mon_nam:the newt (as if detected) the invisible orc     Fido
  7.   * l_monnam:    newt            it      invisible orc           dog called Fido
  8.   * Monnam:      The newt        It      The invisible orc       Fido
  9.   * noit_Monnam: The newt (as if detected) The invisible orc     Fido
  10.   * Adjmonnam:   The poor newt   It      The poor invisible orc  The poor Fido
  11.   * Amonnam:     A newt          It      An invisible orc        Fido
  12.   * a_monnam:    a newt          it      an invisible orc        Fido
  13.   * m_monnam:    newt            xan     orc                     Fido
  14.   * y_monnam:    your newt     your xan  your invisible orc      Fido
  15.   */
  16.  
  17.  /* Bug: if the monster is a priest or shopkeeper, not every one of these
  18.   * options works, since those are special cases.
  19.   */
  20.  char *
  21.  x_monnam(mtmp, article, adjective, suppress, called)
  22.  register struct monst *mtmp;
  23.  int article;
  24.  /* ARTICLE_NONE, ARTICLE_THE, ARTICLE_A: obvious
  25.   * ARTICLE_YOUR: "your" on pets, "the" on everything else
  26.   *
  27.   * If the monster would be referred to as "it" or if the monster has a name
  28.   * _and_ there is no adjective, "invisible", "saddled", etc., override this
  29.   * and always use no article.
  30.   */
  31.  const char *adjective;
  32.  int suppress;
  33.  /* SUPPRESS_IT, SUPPRESS_INVISIBLE, SUPPRESS_HALLUCINATION, SUPPRESS_SADDLE.
  34.   * EXACT_NAME: combination of all the above
  35.   */
  36.  boolean called;
  37.  {
  38.      char *buf = nextmbuf();
  39.      struct permonst *mdat = mtmp->data;
  40.      const char *pm_name = mdat->mname;
  41.      boolean do_hallu, do_invis, do_it, do_saddle;
  42.      boolean name_at_start, has_adjectives;
  43.      char *bp;
  44.  
  45.      if (program_state.gameover)
  46.          suppress |= SUPPRESS_HALLUCINATION;
  47.      if (article == ARTICLE_YOUR && !mtmp->mtame)
  48.          article = ARTICLE_THE;
  49.  
  50.      do_hallu = Hallucination && !(suppress & SUPPRESS_HALLUCINATION);
  51.      do_invis = mtmp->minvis && !(suppress & SUPPRESS_INVISIBLE);
  52.      do_it = !canspotmon(mtmp) && article != ARTICLE_YOUR
  53.              && !program_state.gameover && mtmp != u.usteed
  54.              && !(u.uswallow && mtmp == u.ustuck) && !(suppress & SUPPRESS_IT);
  55.      do_saddle = !(suppress & SUPPRESS_SADDLE);
  56.  
  57.      buf[0] = '\0';
  58.  
  59.      /* unseen monsters, etc.  Use "it" */
  60.      if (do_it) {
  61.          Strcpy(buf, "it");
  62.          return buf;
  63.      }
  64.  
  65.      /* priests and minions: don't even use this function */
  66.      if (mtmp->ispriest || mtmp->isminion) {
  67.          char priestnambuf[BUFSZ];
  68.          char *name;
  69.          long save_prop = EHalluc_resistance;
  70.          unsigned save_invis = mtmp->minvis;
  71.  
  72.          /* when true name is wanted, explicitly block Hallucination */
  73.          if (!do_hallu)
  74.              EHalluc_resistance = 1L;
  75.          if (!do_invis)
  76.              mtmp->minvis = 0;
  77.          name = priestname(mtmp, priestnambuf);
  78.          EHalluc_resistance = save_prop;
  79.          mtmp->minvis = save_invis;
  80.          if (article == ARTICLE_NONE && !strncmp(name, "the ", 4))
  81.              name += 4;
  82.          return strcpy(buf, name);
  83.      }
  84.      /* an "aligned priest" not flagged as a priest or minion should be
  85.         "priest" or "priestess" (normally handled by priestname()) */
  86.      if (mdat == &mons[PM_ALIGNED_PRIEST])
  87.          pm_name = mtmp->female ? "priestess" : "priest";
  88.      else if (mdat == &mons[PM_HIGH_PRIEST] && mtmp->female)
  89.          pm_name = "high priestess";
  90.  
  91.      /* Shopkeepers: use shopkeeper name.  For normal shopkeepers, just
  92.       * "Asidonhopo"; for unusual ones, "Asidonhopo the invisible
  93.       * shopkeeper" or "Asidonhopo the blue dragon".  If hallucinating,
  94.       * none of this applies.
  95.       */
  96.      if (mtmp->isshk && !do_hallu) {
  97.          if (adjective && article == ARTICLE_THE) {
  98.              /* pathological case: "the angry Asidonhopo the blue dragon"
  99.                 sounds silly */
  100.              Strcpy(buf, "the ");
  101.              Strcat(strcat(buf, adjective), " ");
  102.              Strcat(buf, shkname(mtmp));
  103.              return buf;
  104.          }
  105.          Strcat(buf, shkname(mtmp));
  106.          if (mdat == &mons[PM_SHOPKEEPER] && !do_invis)
  107.              return buf;
  108.          Strcat(buf, " the ");
  109.          if (do_invis)
  110.              Strcat(buf, "invisible ");
  111.          Strcat(buf, pm_name);
  112.          return buf;
  113.      }
  114.  
  115.      /* Put the adjectives in the buffer */
  116.      if (adjective)
  117.          Strcat(strcat(buf, adjective), " ");
  118.      if (do_invis)
  119.          Strcat(buf, "invisible ");
  120.      if (do_saddle && (mtmp->misc_worn_check & W_SADDLE) && !Blind
  121.          && !Hallucination)
  122.          Strcat(buf, "saddled ");
  123.      if (buf[0] != 0)
  124.          has_adjectives = TRUE;
  125.      else
  126.          has_adjectives = FALSE;
  127.  
  128.      /* Put the actual monster name or type into the buffer now */
  129.      /* Be sure to remember whether the buffer starts with a name */
  130.      if (do_hallu) {
  131.          char rnamecode;
  132.          char *rname = rndmonnam(&rnamecode);
  133.  
  134.          Strcat(buf, rname);
  135.          name_at_start = bogon_is_pname(rnamecode);
  136.      } else if (has_mname(mtmp)) {
  137.          char *name = MNAME(mtmp);
  138.  
  139.          if (mdat == &mons[PM_GHOST]) {
  140.              Sprintf(eos(buf), "%s ghost", s_suffix(name));
  141.              name_at_start = TRUE;
  142.          } else if (called) {
  143.              Sprintf(eos(buf), "%s called %s", pm_name, name);
  144.              name_at_start = (boolean) type_is_pname(mdat);
  145.          } else if (is_mplayer(mdat) && (bp = strstri(name, " the ")) != 0) {
  146.              /* <name> the <adjective> <invisible> <saddled> <rank> */
  147.              char pbuf[BUFSZ];
  148.  
  149.              Strcpy(pbuf, name);
  150.              pbuf[bp - name + 5] = '\0'; /* adjectives right after " the " */
  151.              if (has_adjectives)
  152.                  Strcat(pbuf, buf);
  153.              Strcat(pbuf, bp + 5); /* append the rest of the name */
  154.              Strcpy(buf, pbuf);
  155.              article = ARTICLE_NONE;
  156.              name_at_start = TRUE;
  157.          } else {
  158.              Strcat(buf, name);
  159.              name_at_start = TRUE;
  160.          }
  161.      } else if (is_mplayer(mdat) && !In_endgame(&u.uz)) {
  162.          char pbuf[BUFSZ];
  163.  
  164.          Strcpy(pbuf, rank_of((int) mtmp->m_lev, monsndx(mdat),
  165.                               (boolean) mtmp->female));
  166.          Strcat(buf, lcase(pbuf));
  167.          name_at_start = FALSE;
  168.      } else {
  169.          Strcat(buf, pm_name);
  170.          name_at_start = (boolean) type_is_pname(mdat);
  171.      }
  172.  
  173.      if (name_at_start && (article == ARTICLE_YOUR || !has_adjectives)) {
  174.          if (mdat == &mons[PM_WIZARD_OF_YENDOR])
  175.              article = ARTICLE_THE;
  176.          else
  177.              article = ARTICLE_NONE;
  178.      } else if ((mdat->geno & G_UNIQ) && article == ARTICLE_A) {
  179.          article = ARTICLE_THE;
  180.      }
  181.  
  182.      {
  183.          char buf2[BUFSZ];
  184.  
  185.          switch (article) {
  186.          case ARTICLE_YOUR:
  187.              Strcpy(buf2, "your ");
  188.              Strcat(buf2, buf);
  189.              Strcpy(buf, buf2);
  190.              return buf;
  191.          case ARTICLE_THE:
  192.              Strcpy(buf2, "the ");
  193.              Strcat(buf2, buf);
  194.              Strcpy(buf, buf2);
  195.              return buf;
  196.          case ARTICLE_A:
  197.              return an(buf);
  198.          case ARTICLE_NONE:
  199.          default:
  200.              return buf;
  201.          }
  202.      }
  203.  }
  204.  

l_monnam

  1.  char *
  2.  l_monnam(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      return x_monnam(mtmp, ARTICLE_NONE, (char *) 0,
  6.                      (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, TRUE);
  7.  }
  8.  

mon_nam

  1.  char *
  2.  mon_nam(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      return x_monnam(mtmp, ARTICLE_THE, (char *) 0,
  6.                      (has_mname(mtmp)) ? SUPPRESS_SADDLE : 0, FALSE);
  7.  }
  8.  

noit_mon_nam

  1.  /* print the name as if mon_nam() was called, but assume that the player
  2.   * can always see the monster--used for probing and for monsters aggravating
  3.   * the player with a cursed potion of invisibility
  4.   */
  5.  char *
  6.  noit_mon_nam(mtmp)
  7.  struct monst *mtmp;
  8.  {
  9.      return x_monnam(mtmp, ARTICLE_THE, (char *) 0,
  10.                      (has_mname(mtmp)) ? (SUPPRESS_SADDLE | SUPPRESS_IT)
  11.                                         : SUPPRESS_IT,
  12.                      FALSE);
  13.  }
  14.  

Monnam

  1.  char *
  2.  Monnam(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      register char *bp = mon_nam(mtmp);
  6.  
  7.      *bp = highc(*bp);
  8.      return  bp;
  9.  }
  10.  

noit_Monnam

  1.  char *
  2.  noit_Monnam(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      register char *bp = noit_mon_nam(mtmp);
  6.  
  7.      *bp = highc(*bp);
  8.      return  bp;
  9.  }
  10.  

m_monnam

  1.  /* monster's own name */
  2.  char *
  3.  m_monnam(mtmp)
  4.  struct monst *mtmp;
  5.  {
  6.      return x_monnam(mtmp, ARTICLE_NONE, (char *) 0, EXACT_NAME, FALSE);
  7.  }
  8.  

y_monnam

  1.  /* pet name: "your little dog" */
  2.  char *
  3.  y_monnam(mtmp)
  4.  struct monst *mtmp;
  5.  {
  6.      int prefix, suppression_flag;
  7.  
  8.      prefix = mtmp->mtame ? ARTICLE_YOUR : ARTICLE_THE;
  9.      suppression_flag = (has_mname(mtmp)
  10.                          /* "saddled" is redundant when mounted */
  11.                          || mtmp == u.usteed)
  12.                             ? SUPPRESS_SADDLE
  13.                             : 0;
  14.  
  15.      return x_monnam(mtmp, prefix, (char *) 0, suppression_flag, FALSE);
  16.  }
  17.  

Adjmonnam

  1.  char *
  2.  Adjmonnam(mtmp, adj)
  3.  struct monst *mtmp;
  4.  const char *adj;
  5.  {
  6.      char *bp = x_monnam(mtmp, ARTICLE_THE, adj,
  7.                          has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE);
  8.  
  9.      *bp = highc(*bp);
  10.      return  bp;
  11.  }
  12.  

a_monnam

  1.  char *
  2.  a_monnam(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      return x_monnam(mtmp, ARTICLE_A, (char *) 0,
  6.                      has_mname(mtmp) ? SUPPRESS_SADDLE : 0, FALSE);
  7.  }
  8.  

Amonnam

  1.  char *
  2.  Amonnam(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      char *bp = a_monnam(mtmp);
  6.  
  7.      *bp = highc(*bp);
  8.      return  bp;
  9.  }
  10.  

distant_monnam

  1.  /* used for monster ID by the '/', ';', and 'C' commands to block remote
  2.     identification of the endgame altars via their attending priests */
  3.  char *
  4.  distant_monnam(mon, article, outbuf)
  5.  struct monst *mon;
  6.  int article; /* only ARTICLE_NONE and ARTICLE_THE are handled here */
  7.  char *outbuf;
  8.  {
  9.      /* high priest(ess)'s identity is concealed on the Astral Plane,
  10.         unless you're adjacent (overridden for hallucination which does
  11.         its own obfuscation) */
  12.      if (mon->data == &mons[PM_HIGH_PRIEST] && !Hallucination
  13.          && Is_astralevel(&u.uz) && distu(mon->mx, mon->my) > 2) {
  14.          Strcpy(outbuf, article == ARTICLE_THE ? "the " : "");
  15.          Strcat(outbuf, mon->female ? "high priestess" : "high priest");
  16.      } else {
  17.          Strcpy(outbuf, x_monnam(mon, article, (char *) 0, 0, TRUE));
  18.      }
  19.      return outbuf;
  20.  }
  21.  

bogusmon

  1.  /* fake monsters used to be in a hard-coded array, now in a data file */
  2.  STATIC_OVL char *
  3.  bogusmon(buf, code)
  4.  char *buf, *code;
  5.  {
  6.      char *mname = buf;
  7.  
  8.      get_rnd_text(BOGUSMONFILE, buf);
  9.      /* strip prefix if present */
  10.      if (!letter(*mname)) {
  11.          if (code)
  12.              *code = *mname;
  13.          ++mname;
  14.      } else {
  15.          if (code)
  16.              *code = '\0';
  17.      }
  18.      return mname;
  19.  }
  20.  

rndmonnam

  1.  /* return a random monster name, for hallucination */
  2.  char *
  3.  rndmonnam(code)
  4.  char *code;
  5.  {
  6.      static char buf[BUFSZ];
  7.      char *mname;
  8.      int name;
  9.  #define BOGUSMONSIZE 100 /* arbitrary */
  10.  
  11.      if (code)
  12.          *code = '\0';
  13.  
  14.      do {
  15.          name = rn1(SPECIAL_PM + BOGUSMONSIZE - LOW_PM, LOW_PM);
  16.      } while (name < SPECIAL_PM
  17.               && (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN)));
  18.  
  19.      if (name >= SPECIAL_PM) {
  20.          mname = bogusmon(buf, code);
  21.      } else {
  22.          mname = strcpy(buf, mons[name].mname);
  23.      }
  24.      return mname;
  25.  #undef BOGUSMONSIZE
  26.  }
  27.  

bogon_is_pname

  1.  /* check bogusmon prefix to decide whether it's a personal name */
  2.  boolean
  3.  bogon_is_pname(code)
  4.  char code;
  5.  {
  6.      if (!code)
  7.          return FALSE;
  8.      return index("-+=", code) ? TRUE : FALSE;
  9.  }
  10.  

roguename

  1.  /* name of a Rogue player */
  2.  const char *
  3.  roguename()
  4.  {
  5.      char *i, *opts;
  6.  
  7.      if ((opts = nh_getenv("ROGUEOPTS")) != 0) {
  8.          for (i = opts; *i; i++)
  9.              if (!strncmp("name=", i, 5)) {
  10.                  char *j;
  11.                  if ((j = index(i + 5, ',')) != 0)
  12.                      *j = (char) 0;
  13.                  return i + 5;
  14.              }
  15.      }
  16.      return rn2(3) ? (rn2(2) ? "Michael Toy" : "Kenneth Arnold")
  17.                    : "Glenn Wichman";
  18.  }
  19.  

Color functions

  1.  static NEARDATA const char *const hcolors[] = {
  2.      "ultraviolet", "infrared", "bluish-orange", "reddish-green", "dark white",
  3.      "light black", "sky blue-pink", "salty", "sweet", "sour", "bitter",
  4.      "striped", "spiral", "swirly", "plaid", "checkered", "argyle", "paisley",
  5.      "blotchy", "guernsey-spotted", "polka-dotted", "square", "round",
  6.      "triangular", "cabernet", "sangria", "fuchsia", "wisteria", "lemon-lime",
  7.      "strawberry-banana", "peppermint", "romantic", "incandescent",
  8.      "octarine", /* Discworld: the Colour of Magic */
  9.  };
  10.  

hcolor

  1.  const char *
  2.  hcolor(colorpref)
  3.  const char *colorpref;
  4.  {
  5.      return (Hallucination || !colorpref) ? hcolors[rn2(SIZE(hcolors))]
  6.                                           : colorpref;
  7.  }
  8.  

rndcolor

  1.  /* return a random real color unless hallucinating */
  2.  const char *
  3.  rndcolor()
  4.  {
  5.      int k = rn2(CLR_MAX);
  6.  
  7.      return Hallucination ? hcolor((char *) 0)
  8.                           : (k == NO_COLOR) ? "colorless"
  9.                                             : c_obj_colors[k];
  10.  }
  11.  

coyotename

  1.  /* Aliases for road-runner nemesis
  2.   */
  3.  static const char *const coynames[] = {
  4.      "Carnivorous Vulgaris", "Road-Runnerus Digestus", "Eatibus Anythingus",
  5.      "Famishus-Famishus", "Eatibus Almost Anythingus", "Eatius Birdius",
  6.      "Famishius Fantasticus", "Eternalii Famishiis", "Famishus Vulgarus",
  7.      "Famishius Vulgaris Ingeniusi", "Eatius-Slobbius", "Hardheadipus Oedipus",
  8.      "Carnivorous Slobbius", "Hard-Headipus Ravenus", "Evereadii Eatibus",
  9.      "Apetitius Giganticus", "Hungrii Flea-Bagius", "Overconfidentii Vulgaris",
  10.      "Caninus Nervous Rex", "Grotesques Appetitus", "Nemesis Ridiculii",
  11.      "Canis latrans"
  12.  };
  13.  
  14.  char *
  15.  coyotename(mtmp, buf)
  16.  struct monst *mtmp;
  17.  char *buf;
  18.  {
  19.      if (mtmp && buf) {
  20.          Sprintf(buf, "%s - %s",
  21.                  x_monnam(mtmp, ARTICLE_NONE, (char *) 0, 0, TRUE),
  22.                  mtmp->mcan ? coynames[SIZE(coynames) - 1]
  23.                             : coynames[rn2(SIZE(coynames) - 1)]);
  24.      }
  25.      return buf;
  26.  }
  27.  

Terry Pratchett novel functions

  1.  /* make sure "The Colour of Magic" remains the first entry in here */
  2.  static const char *const sir_Terry_novels[] = {
  3.      "The Colour of Magic", "The Light Fantastic", "Equal Rites", "Mort",
  4.      "Sourcery", "Wyrd Sisters", "Pyramids", "Guards! Guards!", "Eric",
  5.      "Moving Pictures", "Reaper Man", "Witches Abroad", "Small Gods",
  6.      "Lords and Ladies", "Men at Arms", "Soul Music", "Interesting Times",
  7.      "Maskerade", "Feet of Clay", "Hogfather", "Jingo", "The Last Continent",
  8.      "Carpe Jugulum", "The Fifth Elephant", "The Truth", "Thief of Time",
  9.      "The Last Hero", "The Amazing Maurice and his Educated Rodents",
  10.      "Night Watch", "The Wee Free Men", "Monstrous Regiment",
  11.      "A Hat Full of Sky", "Going Postal", "Thud!", "Wintersmith",
  12.      "Making Money", "Unseen Academicals", "I Shall Wear Midnight", "Snuff",
  13.      "Raising Steam", "The Shepherd's Crown"
  14.  };
  15.  
  16.  const char *
  17.  noveltitle(novidx)
  18.  int *novidx;
  19.  {
  20.      int j, k = SIZE(sir_Terry_novels);
  21.  
  22.      j = rn2(k);
  23.      if (novidx) {
  24.          if (*novidx == -1)
  25.              *novidx = j;
  26.          else if (*novidx >= 0 && *novidx < k)
  27.              j = *novidx;
  28.      }
  29.      return sir_Terry_novels[j];
  30.  }
  31.  
  32.  const char *
  33.  lookup_novel(lookname, idx)
  34.  const char *lookname;
  35.  int *idx;
  36.  {
  37.      int k;
  38.  
  39.      /* Take American or U.K. spelling of this one */
  40.      if (!strcmpi(The(lookname), "The Color of Magic"))
  41.          lookname = sir_Terry_novels[0];
  42.  
  43.      for (k = 0; k < SIZE(sir_Terry_novels); ++k) {
  44.          if (!strcmpi(lookname, sir_Terry_novels[k])
  45.              || !strcmpi(The(lookname), sir_Terry_novels[k])) {
  46.              if (idx)
  47.                  *idx = k;
  48.              return sir_Terry_novels[k];
  49.          }
  50.      }
  51.      /* name not found; if novelidx is already set, override the name */
  52.      if (idx && *idx >= 0 && *idx < SIZE(sir_Terry_novels))
  53.          return sir_Terry_novels[*idx];
  54.  
  55.      return (const char *) 0;
  56.  }
  57.  
  58.  /*do_name.c*/