Source:NetHack 3.6.1/src/cmd.c

From NetHackWiki
(Redirected from Source:Ref/mon invent chain)
Jump to: navigation, search

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

Contents

Top of file

  1.  /* NetHack 3.6	cmd.c	$NHDT-Date: 1523306904 2018/04/09 20:48:24 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.281 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Robert Patrick Rankin, 2013. */
  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.  #include "lev.h"
  4.  #include "func_tab.h"
  5.  
  6.  #ifdef ALTMETA
  7.  STATIC_VAR boolean alt_esc = FALSE;
  8.  #endif
  9.  
  10.  struct cmd Cmd = { 0 }; /* flag.h */
  11.  
  12.  extern const char *hu_stat[];  /* hunger status from eat.c */
  13.  extern const char *enc_stat[]; /* encumbrance status from botl.c */
  14.  
  15.  #ifdef UNIX
  16.  /*
  17.   * Some systems may have getchar() return EOF for various reasons, and
  18.   * we should not quit before seeing at least NR_OF_EOFS consecutive EOFs.
  19.   */
  20.  #if defined(SYSV) || defined(DGUX) || defined(HPUX)
  21.  #define NR_OF_EOFS 20
  22.  #endif
  23.  #endif
  24.  
  25.  #define CMD_TRAVEL (char) 0x90
  26.  #define CMD_CLICKLOOK (char) 0x8F
  27.  
  28.  #ifdef DEBUG
  29.  extern int NDECL(wiz_debug_cmd_bury);
  30.  extern int NDECL(wiz_debug_cmd_traveldisplay);
  31.  #endif
  32.  
  33.  #ifdef DUMB /* stuff commented out in extern.h, but needed here */
  34.  extern int NDECL(doapply);            /**/
  35.  extern int NDECL(dorub);              /**/
  36.  extern int NDECL(dojump);             /**/
  37.  extern int NDECL(doextlist);          /**/
  38.  extern int NDECL(enter_explore_mode); /**/
  39.  extern int NDECL(dodrop);             /**/
  40.  extern int NDECL(doddrop);            /**/
  41.  extern int NDECL(dodown);             /**/
  42.  extern int NDECL(doup);               /**/
  43.  extern int NDECL(donull);             /**/
  44.  extern int NDECL(dowipe);             /**/
  45.  extern int NDECL(docallcnd);          /**/
  46.  extern int NDECL(dotakeoff);          /**/
  47.  extern int NDECL(doremring);          /**/
  48.  extern int NDECL(dowear);             /**/
  49.  extern int NDECL(doputon);            /**/
  50.  extern int NDECL(doddoremarm);        /**/
  51.  extern int NDECL(dokick);             /**/
  52.  extern int NDECL(dofire);             /**/
  53.  extern int NDECL(dothrow);            /**/
  54.  extern int NDECL(doeat);              /**/
  55.  extern int NDECL(done2);              /**/
  56.  extern int NDECL(vanquished);         /**/
  57.  extern int NDECL(doengrave);          /**/
  58.  extern int NDECL(dopickup);           /**/
  59.  extern int NDECL(ddoinv);             /**/
  60.  extern int NDECL(dotypeinv);          /**/
  61.  extern int NDECL(dolook);             /**/
  62.  extern int NDECL(doprgold);           /**/
  63.  extern int NDECL(doprwep);            /**/
  64.  extern int NDECL(doprarm);            /**/
  65.  extern int NDECL(doprring);           /**/
  66.  extern int NDECL(dopramulet);         /**/
  67.  extern int NDECL(doprtool);           /**/
  68.  extern int NDECL(dosuspend);          /**/
  69.  extern int NDECL(doforce);            /**/
  70.  extern int NDECL(doopen);             /**/
  71.  extern int NDECL(doclose);            /**/
  72.  extern int NDECL(dosh);               /**/
  73.  extern int NDECL(dodiscovered);       /**/
  74.  extern int NDECL(doclassdisco);       /**/
  75.  extern int NDECL(doset);              /**/
  76.  extern int NDECL(dotogglepickup);     /**/
  77.  extern int NDECL(dowhatis);           /**/
  78.  extern int NDECL(doquickwhatis);      /**/
  79.  extern int NDECL(dowhatdoes);         /**/
  80.  extern int NDECL(dohelp);             /**/
  81.  extern int NDECL(dohistory);          /**/
  82.  extern int NDECL(doloot);             /**/
  83.  extern int NDECL(dodrink);            /**/
  84.  extern int NDECL(dodip);              /**/
  85.  extern int NDECL(dosacrifice);        /**/
  86.  extern int NDECL(dopray);             /**/
  87.  extern int NDECL(dotip);              /**/
  88.  extern int NDECL(doturn);             /**/
  89.  extern int NDECL(doredraw);           /**/
  90.  extern int NDECL(doread);             /**/
  91.  extern int NDECL(dosave);             /**/
  92.  extern int NDECL(dosearch);           /**/
  93.  extern int NDECL(doidtrap);           /**/
  94.  extern int NDECL(dopay);              /**/
  95.  extern int NDECL(dosit);              /**/
  96.  extern int NDECL(dotalk);             /**/
  97.  extern int NDECL(docast);             /**/
  98.  extern int NDECL(dovspell);           /**/
  99.  extern int NDECL(dotele);             /**/
  100.  extern int NDECL(dountrap);           /**/
  101.  extern int NDECL(doversion);          /**/
  102.  extern int NDECL(doextversion);       /**/
  103.  extern int NDECL(doswapweapon);       /**/
  104.  extern int NDECL(dowield);            /**/
  105.  extern int NDECL(dowieldquiver);      /**/
  106.  extern int NDECL(dozap);              /**/
  107.  extern int NDECL(doorganize);         /**/
  108.  #endif /* DUMB */
  109.  
  110.  static int NDECL(dosuspend_core); /**/
  111.  
  112.  static int NDECL((*timed_occ_fn));
  113.  
  114.  STATIC_PTR int NDECL(doherecmdmenu);
  115.  STATIC_PTR int NDECL(dotherecmdmenu);
  116.  STATIC_PTR int NDECL(doprev_message);
  117.  STATIC_PTR int NDECL(timed_occupation);
  118.  STATIC_PTR int NDECL(doextcmd);
  119.  STATIC_PTR int NDECL(dotravel);
  120.  STATIC_PTR int NDECL(doterrain);
  121.  STATIC_PTR int NDECL(wiz_wish);
  122.  STATIC_PTR int NDECL(wiz_identify);
  123.  STATIC_PTR int NDECL(wiz_intrinsic);
  124.  STATIC_PTR int NDECL(wiz_map);
  125.  STATIC_PTR int NDECL(wiz_makemap);
  126.  STATIC_PTR int NDECL(wiz_genesis);
  127.  STATIC_PTR int NDECL(wiz_where);
  128.  STATIC_PTR int NDECL(wiz_detect);
  129.  STATIC_PTR int NDECL(wiz_panic);
  130.  STATIC_PTR int NDECL(wiz_polyself);
  131.  STATIC_PTR int NDECL(wiz_level_tele);
  132.  STATIC_PTR int NDECL(wiz_level_change);
  133.  STATIC_PTR int NDECL(wiz_show_seenv);
  134.  STATIC_PTR int NDECL(wiz_show_vision);
  135.  STATIC_PTR int NDECL(wiz_smell);
  136.  STATIC_PTR int NDECL(wiz_intrinsic);
  137.  STATIC_PTR int NDECL(wiz_mon_polycontrol);
  138.  STATIC_PTR int NDECL(wiz_show_wmodes);
  139.  STATIC_DCL void NDECL(wiz_map_levltyp);
  140.  STATIC_DCL void NDECL(wiz_levltyp_legend);
  141.  #if defined(__BORLANDC__) && !defined(_WIN32)
  142.  extern void FDECL(show_borlandc_stats, (winid));
  143.  #endif
  144.  #ifdef DEBUG_MIGRATING_MONS
  145.  STATIC_PTR int NDECL(wiz_migrate_mons);
  146.  #endif
  147.  STATIC_DCL int FDECL(size_monst, (struct monst *, BOOLEAN_P));
  148.  STATIC_DCL int FDECL(size_obj, (struct obj *));
  149.  STATIC_DCL void FDECL(count_obj, (struct obj *, long *, long *,
  150.                                    BOOLEAN_P, BOOLEAN_P));
  151.  STATIC_DCL void FDECL(obj_chain, (winid, const char *, struct obj *,
  152.                                    BOOLEAN_P, long *, long *));
  153.  STATIC_DCL void FDECL(mon_invent_chain, (winid, const char *, struct monst *,
  154.                                           long *, long *));
  155.  STATIC_DCL void FDECL(mon_chain, (winid, const char *, struct monst *,
  156.                                    BOOLEAN_P, long *, long *));
  157.  STATIC_DCL void FDECL(contained_stats, (winid, const char *, long *, long *));
  158.  STATIC_DCL void FDECL(misc_stats, (winid, long *, long *));
  159.  STATIC_PTR int NDECL(wiz_show_stats);
  160.  STATIC_DCL boolean FDECL(accept_menu_prefix, (int NDECL((*))));
  161.  #ifdef PORT_DEBUG
  162.  STATIC_DCL int NDECL(wiz_port_debug);
  163.  #endif
  164.  STATIC_PTR int NDECL(wiz_rumor_check);
  165.  STATIC_PTR int NDECL(doattributes);
  166.  
  167.  STATIC_DCL void FDECL(enlght_line, (const char *, const char *, const char *,
  168.                                      const char *));
  169.  STATIC_DCL char *FDECL(enlght_combatinc, (const char *, int, int, char *));
  170.  STATIC_DCL void FDECL(enlght_halfdmg, (int, int));
  171.  STATIC_DCL boolean NDECL(walking_on_water);
  172.  STATIC_DCL boolean FDECL(cause_known, (int));
  173.  STATIC_DCL char *FDECL(attrval, (int, int, char *));
  174.  STATIC_DCL void FDECL(background_enlightenment, (int, int));
  175.  STATIC_DCL void FDECL(characteristics_enlightenment, (int, int));
  176.  STATIC_DCL void FDECL(one_characteristic, (int, int, int));
  177.  STATIC_DCL void FDECL(status_enlightenment, (int, int));
  178.  STATIC_DCL void FDECL(attributes_enlightenment, (int, int));
  179.  
  180.  static const char *readchar_queue = "";
  181.  static coord clicklook_cc;
  182.  
  183.  STATIC_DCL void FDECL(add_herecmd_menuitem, (winid, int NDECL((*)),
  184.                                               const char *));
  185.  STATIC_DCL char FDECL(here_cmd_menu, (BOOLEAN_P));
  186.  STATIC_DCL char FDECL(there_cmd_menu, (BOOLEAN_P, int, int));
  187.  STATIC_DCL char *NDECL(parse);
  188.  STATIC_DCL void FDECL(show_direction_keys, (winid, CHAR_P, BOOLEAN_P));
  189.  STATIC_DCL boolean FDECL(help_dir, (CHAR_P, int, const char *));
  190.  

doprev_message

  1.  STATIC_PTR int
  2.  doprev_message(VOID_ARGS)
  3.  {
  4.      return nh_doprev_message();
  5.  }
  6.  

timed_occupation

  1.  /* Count down by decrementing multi */
  2.  STATIC_PTR int
  3.  timed_occupation(VOID_ARGS)
  4.  {
  5.      (*timed_occ_fn)();
  6.      if (multi > 0)
  7.          multi--;
  8.      return multi > 0;
  9.  }
  10.  

reset_occupations

  1.  /* If you have moved since initially setting some occupations, they
  2.   * now shouldn't be able to restart.
  3.   *
  4.   * The basic rule is that if you are carrying it, you can continue
  5.   * since it is with you.  If you are acting on something at a distance,
  6.   * your orientation to it must have changed when you moved.
  7.   *
  8.   * The exception to this is taking off items, since they can be taken
  9.   * off in a number of ways in the intervening time, screwing up ordering.
  10.   *
  11.   *      Currently:      Take off all armor.
  12.   *                      Picking Locks / Forcing Chests.
  13.   *                      Setting traps.
  14.   */
  15.  void
  16.  reset_occupations()
  17.  {
  18.      reset_remarm();
  19.      reset_pick();
  20.      reset_trapset();
  21.  }
  22.  

set_occupation

  1.  /* If a time is given, use it to timeout this function, otherwise the
  2.   * function times out by its own means.
  3.   */
  4.  void
  5.  set_occupation(fn, txt, xtime)
  6.  int NDECL((*fn));
  7.  const char *txt;
  8.  int xtime;
  9.  {
  10.      if (xtime) {
  11.          occupation = timed_occupation;
  12.          timed_occ_fn = fn;
  13.      } else
  14.          occupation = fn;
  15.      occtxt = txt;
  16.      occtime = 0;
  17.      return;
  18.  }
  19.  

popch

  1.  STATIC_DCL char NDECL(popch);
  2.  
  3.  /* Provide a means to redo the last command.  The flag `in_doagain' is set
  4.   * to true while redoing the command.  This flag is tested in commands that
  5.   * require additional input (like `throw' which requires a thing and a
  6.   * direction), and the input prompt is not shown.  Also, while in_doagain is
  7.   * TRUE, no keystrokes can be saved into the saveq.
  8.   */
  9.  #define BSIZE 20
  10.  static char pushq[BSIZE], saveq[BSIZE];
  11.  static NEARDATA int phead, ptail, shead, stail;
  12.  
  13.  STATIC_OVL char
  14.  popch()
  15.  {
  16.      /* If occupied, return '\0', letting tgetch know a character should
  17.       * be read from the keyboard.  If the character read is not the
  18.       * ABORT character (as checked in pcmain.c), that character will be
  19.       * pushed back on the pushq.
  20.       */
  21.      if (occupation)
  22.          return '\0';
  23.      if (in_doagain)
  24.          return (char) ((shead != stail) ? saveq[stail++] : '\0');
  25.      else
  26.          return (char) ((phead != ptail) ? pushq[ptail++] : '\0');
  27.  }
  28.  

pgetchar

  1.  char
  2.  pgetchar() /* courtesy of aeb@cwi.nl */
  3.  {
  4.      register int ch;
  5.  
  6.      if (!(ch = popch()))
  7.          ch = nhgetch();
  8.      return (char) ch;
  9.  }
  10.  

pushch

  1.  /* A ch == 0 resets the pushq */
  2.  void
  3.  pushch(ch)
  4.  char ch;
  5.  {
  6.      if (!ch)
  7.          phead = ptail = 0;
  8.      if (phead < BSIZE)
  9.          pushq[phead++] = ch;
  10.      return;
  11.  }
  12.  

savech

  1.  /* A ch == 0 resets the saveq.  Only save keystrokes when not
  2.   * replaying a previous command.
  3.   */
  4.  void
  5.  savech(ch)
  6.  char ch;
  7.  {
  8.      if (!in_doagain) {
  9.          if (!ch)
  10.              phead = ptail = shead = stail = 0;
  11.          else if (shead < BSIZE)
  12.              saveq[shead++] = ch;
  13.      }
  14.      return;
  15.  }
  16.  

doextcmd

  1.  /* here after # - now read a full-word command */
  2.  STATIC_PTR int
  3.  doextcmd(VOID_ARGS)
  4.  {
  5.      int idx, retval;
  6.      int NDECL((*func));
  7.  
  8.      /* keep repeating until we don't run help or quit */
  9.      do {
  10.          idx = get_ext_cmd();
  11.          if (idx < 0)
  12.              return 0; /* quit */
  13.  
  14.          func = extcmdlist[idx].ef_funct;
  15.          if (!wizard && (extcmdlist[idx].flags & WIZMODECMD)) {
  16.              You("can't do that.");
  17.              return 0;
  18.          }
  19.          if (iflags.menu_requested && !accept_menu_prefix(func)) {
  20.              pline("'%s' prefix has no effect for the %s command.",
  21.                    visctrl(Cmd.spkeys[NHKF_REQMENU]),
  22.                    extcmdlist[idx].ef_txt);
  23.              iflags.menu_requested = FALSE;
  24.          }
  25.          retval = (*func)();
  26.      } while (func == doextlist);
  27.  
  28.      return retval;
  29.  }
  30.  

doextlist

  1.  /* here after #? - now list all full-word commands */
  2.  int
  3.  doextlist(VOID_ARGS)
  4.  {
  5.      register const struct ext_func_tab *efp;
  6.      char buf[BUFSZ];
  7.      winid datawin;
  8.      char ch = cmd_from_func(doextcmd);
  9.  
  10.      datawin = create_nhwindow(NHW_TEXT);
  11.      putstr(datawin, 0, "");
  12.      putstr(datawin, 0, "            Extended Commands List");
  13.      putstr(datawin, 0, "");
  14.      if (ch) {
  15.          Sprintf(buf, "    Press '%s', then type:",
  16.                  visctrl(ch));
  17.          putstr(datawin, 0, buf);
  18.          putstr(datawin, 0, "");
  19.      }
  20.  
  21.      for (efp = extcmdlist; efp->ef_txt; efp++) {
  22.          if (!wizard && (efp->flags & WIZMODECMD))
  23.              continue;
  24.          Sprintf(buf, "   %-15s %c %s.",
  25.                  efp->ef_txt,
  26.                  (efp->flags & AUTOCOMPLETE) ? '*' : ' ',
  27.                  efp->ef_desc);
  28.          putstr(datawin, 0, buf);
  29.      }
  30.      putstr(datawin, 0, "");
  31.      putstr(datawin, 0, "    Commands marked with a * will be autocompleted.");
  32.      display_nhwindow(datawin, FALSE);
  33.      destroy_nhwindow(datawin);
  34.      return 0;
  35.  }
  36.  
  37.  #ifdef TTY_GRAPHICS
  38.  #define MAX_EXT_CMD 200 /* Change if we ever have more ext cmds */
  39.  

extcmd_via_menu

  1.  /*
  2.   * This is currently used only by the tty interface and is
  3.   * controlled via runtime option 'extmenu'.  (Most other interfaces
  4.   * already use a menu all the time for extended commands.)
  5.   *
  6.   * ``# ?'' is counted towards the limit of the number of commands,
  7.   * so we actually support MAX_EXT_CMD-1 "real" extended commands.
  8.   *
  9.   * Here after # - now show pick-list of possible commands.
  10.   */
  11.  int
  12.  extcmd_via_menu()
  13.  {
  14.      const struct ext_func_tab *efp;
  15.      menu_item *pick_list = (menu_item *) 0;
  16.      winid win;
  17.      anything any;
  18.      const struct ext_func_tab *choices[MAX_EXT_CMD + 1];
  19.      char buf[BUFSZ];
  20.      char cbuf[QBUFSZ], prompt[QBUFSZ], fmtstr[20];
  21.      int i, n, nchoices, acount;
  22.      int ret, len, biggest;
  23.      int accelerator, prevaccelerator;
  24.      int matchlevel = 0;
  25.      boolean wastoolong, one_per_line;
  26.  
  27.      ret = 0;
  28.      cbuf[0] = '\0';
  29.      biggest = 0;
  30.      while (!ret) {
  31.          i = n = 0;
  32.          any = zeroany;
  33.          /* populate choices */
  34.          for (efp = extcmdlist; efp->ef_txt; efp++) {
  35.              if (!(efp->flags & AUTOCOMPLETE)
  36.                  || (!wizard && (efp->flags & WIZMODECMD)))
  37.                  continue;
  38.              if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) {
  39.                  choices[i] = efp;
  40.                  if ((len = (int) strlen(efp->ef_desc)) > biggest)
  41.                      biggest = len;
  42.                  if (++i > MAX_EXT_CMD) {
  43.  #if defined(BETA)
  44.                      impossible(
  45.        "Exceeded %d extended commands in doextcmd() menu; 'extmenu' disabled.",
  46.                                 MAX_EXT_CMD);
  47.  #endif /* BETA */
  48.                      iflags.extmenu = 0;
  49.                      return -1;
  50.                  }
  51.              }
  52.          }
  53.          choices[i] = (struct ext_func_tab *) 0;
  54.          nchoices = i;
  55.          /* if we're down to one, we have our selection so get out of here */
  56.          if (nchoices  <= 1) {
  57.              ret = (nchoices == 1) ? (int) (choices[0] - extcmdlist) : -1;
  58.              break;
  59.          }
  60.  
  61.          /* otherwise... */
  62.          win = create_nhwindow(NHW_MENU);
  63.          start_menu(win);
  64.          Sprintf(fmtstr, "%%-%ds", biggest + 15);
  65.          prompt[0] = '\0';
  66.          wastoolong = FALSE; /* True => had to wrap due to line width
  67.                               * ('w' in wizard mode) */
  68.          /* -3: two line menu header, 1 line menu footer (for prompt) */
  69.          one_per_line = (nchoices < ROWNO - 3);
  70.          accelerator = prevaccelerator = 0;
  71.          acount = 0;
  72.          for (i = 0; choices[i]; ++i) {
  73.              accelerator = choices[i]->ef_txt[matchlevel];
  74.              if (accelerator != prevaccelerator || one_per_line)
  75.                  wastoolong = FALSE;
  76.              if (accelerator != prevaccelerator || one_per_line
  77.                  || (acount >= 2
  78.                      /* +4: + sizeof " or " - sizeof "" */
  79.                      && (strlen(prompt) + 4 + strlen(choices[i]->ef_txt)
  80.                          /* -6: enough room for 1 space left margin
  81.                           *   + "%c - " menu selector + 1 space right margin */
  82.                          >= min(sizeof prompt, COLNO - 6)))) {
  83.                  if (acount) {
  84.                      /* flush extended cmds for that letter already in buf */
  85.                      Sprintf(buf, fmtstr, prompt);
  86.                      any.a_char = prevaccelerator;
  87.                      add_menu(win, NO_GLYPH, &any, any.a_char, 0, ATR_NONE,
  88.                               buf, FALSE);
  89.                      acount = 0;
  90.                      if (!(accelerator != prevaccelerator || one_per_line))
  91.                          wastoolong = TRUE;
  92.                  }
  93.              }
  94.              prevaccelerator = accelerator;
  95.              if (!acount || one_per_line) {
  96.                  Sprintf(prompt, "%s%s [%s]", wastoolong ? "or " : "",
  97.                          choices[i]->ef_txt, choices[i]->ef_desc);
  98.              } else if (acount == 1) {
  99.                  Sprintf(prompt, "%s%s or %s", wastoolong ? "or " : "",
  100.                          choices[i - 1]->ef_txt, choices[i]->ef_txt);
  101.              } else {
  102.                  Strcat(prompt, " or ");
  103.                  Strcat(prompt, choices[i]->ef_txt);
  104.              }
  105.              ++acount;
  106.          }
  107.          if (acount) {
  108.              /* flush buf */
  109.              Sprintf(buf, fmtstr, prompt);
  110.              any.a_char = prevaccelerator;
  111.              add_menu(win, NO_GLYPH, &any, any.a_char, 0, ATR_NONE, buf,
  112.                       FALSE);
  113.          }
  114.          Sprintf(prompt, "Extended Command: %s", cbuf);
  115.          end_menu(win, prompt);
  116.          n = select_menu(win, PICK_ONE, &pick_list);
  117.          destroy_nhwindow(win);
  118.          if (n == 1) {
  119.              if (matchlevel > (QBUFSZ - 2)) {
  120.                  free((genericptr_t) pick_list);
  121.  #if defined(BETA)
  122.                  impossible("Too many chars (%d) entered in extcmd_via_menu()",
  123.                             matchlevel);
  124.  #endif
  125.                  ret = -1;
  126.              } else {
  127.                  cbuf[matchlevel++] = pick_list[0].item.a_char;
  128.                  cbuf[matchlevel] = '\0';
  129.                  free((genericptr_t) pick_list);
  130.              }
  131.          } else {
  132.              if (matchlevel) {
  133.                  ret = 0;
  134.                  matchlevel = 0;
  135.              } else
  136.                  ret = -1;
  137.          }
  138.      }
  139.      return ret;
  140.  }
  141.  #endif /* TTY_GRAPHICS */
  142.  

domonability

  1.  /* #monster command - use special monster ability while polymorphed */
  2.  int
  3.  domonability(VOID_ARGS)
  4.  {
  5.      if (can_breathe(youmonst.data))
  6.          return dobreathe();
  7.      else if (attacktype(youmonst.data, AT_SPIT))
  8.          return dospit();
  9.      else if (youmonst.data->mlet == S_NYMPH)
  10.          return doremove();
  11.      else if (attacktype(youmonst.data, AT_GAZE))
  12.          return dogaze();
  13.      else if (is_were(youmonst.data))
  14.          return dosummon();
  15.      else if (webmaker(youmonst.data))
  16.          return dospinweb();
  17.      else if (is_hider(youmonst.data))
  18.          return dohide();
  19.      else if (is_mind_flayer(youmonst.data))
  20.          return domindblast();
  21.      else if (u.umonnum == PM_GREMLIN) {
  22.          if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)) {
  23.              if (split_mon(&youmonst, (struct monst *) 0))
  24.                  dryup(u.ux, u.uy, TRUE);
  25.          } else
  26.              There("is no fountain here.");
  27.      } else if (is_unicorn(youmonst.data)) {
  28.          use_unicorn_horn((struct obj *) 0);
  29.          return 1;
  30.      } else if (youmonst.data->msound == MS_SHRIEK) {
  31.          You("shriek.");
  32.          if (u.uburied)
  33.              pline("Unfortunately sound does not carry well through rock.");
  34.          else
  35.              aggravate();
  36.      } else if (youmonst.data->mlet == S_VAMPIRE)
  37.          return dopoly();
  38.      else if (Upolyd)
  39.          pline("Any special ability you may have is purely reflexive.");
  40.      else
  41.          You("don't have a special ability in your normal form!");
  42.      return 0;
  43.  }
  44.  

enter_explore_mode

  1.  int
  2.  enter_explore_mode(VOID_ARGS)
  3.  {
  4.      if (wizard) {
  5.          You("are in debug mode.");
  6.      } else if (discover) {
  7.          You("are already in explore mode.");
  8.      } else {
  9.  #ifdef SYSCF
  10.  #if defined(UNIX)
  11.          if (!sysopt.explorers || !sysopt.explorers[0]
  12.              || !check_user_string(sysopt.explorers)) {
  13.              You("cannot access explore mode.");
  14.              return 0;
  15.          }
  16.  #endif
  17.  #endif
  18.          pline(
  19.          "Beware!  From explore mode there will be no return to normal game.");
  20.          if (paranoid_query(ParanoidQuit,
  21.                             "Do you want to enter explore mode?")) {
  22.              clear_nhwindow(WIN_MESSAGE);
  23.              You("are now in non-scoring explore mode.");
  24.              discover = TRUE;
  25.          } else {
  26.              clear_nhwindow(WIN_MESSAGE);
  27.              pline("Resuming normal game.");
  28.          }
  29.      }
  30.      return 0;
  31.  }
  32.  

wiz_wish

  1.  /* ^W command - wish for something */
  2.  STATIC_PTR int
  3.  wiz_wish(VOID_ARGS) /* Unlimited wishes for debug mode by Paul Polderman */
  4.  {
  5.      if (wizard) {
  6.          boolean save_verbose = flags.verbose;
  7.  
  8.          flags.verbose = FALSE;
  9.          makewish();
  10.          flags.verbose = save_verbose;
  11.          (void) encumber_msg();
  12.      } else
  13.          pline("Unavailable command '%s'.",
  14.                visctrl((int) cmd_from_func(wiz_wish)));
  15.      return 0;
  16.  }
  17.  

wiz_identify

  1.  /* ^I command - reveal and optionally identify hero's inventory */
  2.  STATIC_PTR int
  3.  wiz_identify(VOID_ARGS)
  4.  {
  5.      if (wizard) {
  6.          iflags.override_ID = (int) cmd_from_func(wiz_identify);
  7.          if (display_inventory((char *) 0, TRUE) == -1)
  8.              identify_pack(0, FALSE);
  9.          iflags.override_ID = 0;
  10.      } else
  11.          pline("Unavailable command '%s'.",
  12.                visctrl((int) cmd_from_func(wiz_identify)));
  13.      return 0;
  14.  }
  15.  

wiz_makemap

  1.  STATIC_PTR int
  2.  wiz_makemap(VOID_ARGS)
  3.  {
  4.      /* FIXME: doesn't handle riding */
  5.      if (wizard) {
  6.          struct monst *mtmp;
  7.  
  8.          rm_mapseen(ledger_no(&u.uz));
  9.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  10.              if (mtmp->isshk)
  11.                  setpaid(mtmp);
  12.          if (Punished) {
  13.              ballrelease(FALSE);
  14.              unplacebc();
  15.          }
  16.          check_special_room(TRUE);
  17.          dmonsfree();
  18.          savelev(-1, ledger_no(&u.uz), FREE_SAVE);
  19.          mklev();
  20.          vision_reset();
  21.          vision_full_recalc = 1;
  22.          cls();
  23.          (void) safe_teleds(TRUE);
  24.          if (Punished) {
  25.              unplacebc();
  26.              placebc();
  27.          }
  28.          docrt();
  29.          flush_screen(1);
  30.      }
  31.      return 0;
  32.  }
  33.  

wiz_map

  1.  /* ^F command - reveal the level map and any traps on it */
  2.  STATIC_PTR int
  3.  wiz_map(VOID_ARGS)
  4.  {
  5.      if (wizard) {
  6.          struct trap *t;
  7.          long save_Hconf = HConfusion, save_Hhallu = HHallucination;
  8.  
  9.          HConfusion = HHallucination = 0L;
  10.          for (t = ftrap; t != 0; t = t->ntrap) {
  11.              t->tseen = 1;
  12.              map_trap(t, TRUE);
  13.          }
  14.          do_mapping();
  15.          HConfusion = save_Hconf;
  16.          HHallucination = save_Hhallu;
  17.      } else
  18.          pline("Unavailable command '%s'.",
  19.                visctrl((int) cmd_from_func(wiz_map)));
  20.      return 0;
  21.  }
  22.  

wiz_genesis

  1.  /* ^G command - generate monster(s); a count prefix will be honored */
  2.  STATIC_PTR int
  3.  wiz_genesis(VOID_ARGS)
  4.  {
  5.      if (wizard)
  6.          (void) create_particular();
  7.      else
  8.          pline("Unavailable command '%s'.",
  9.                visctrl((int) cmd_from_func(wiz_genesis)));
  10.      return 0;
  11.  }
  12.  

wiz_where

  1.  /* ^O command - display dungeon layout */
  2.  STATIC_PTR int
  3.  wiz_where(VOID_ARGS)
  4.  {
  5.      if (wizard)
  6.          (void) print_dungeon(FALSE, (schar *) 0, (xchar *) 0);
  7.      else
  8.          pline("Unavailable command '%s'.",
  9.                visctrl((int) cmd_from_func(wiz_where)));
  10.      return 0;
  11.  }
  12.  

wiz_detect

  1.  /* ^E command - detect unseen (secret doors, traps, hidden monsters) */
  2.  STATIC_PTR int
  3.  wiz_detect(VOID_ARGS)
  4.  {
  5.      if (wizard)
  6.          (void) findit();
  7.      else
  8.          pline("Unavailable command '%s'.",
  9.                visctrl((int) cmd_from_func(wiz_detect)));
  10.      return 0;
  11.  }
  12.  

wiz_level_tele

  1.  /* ^V command - level teleport */
  2.  STATIC_PTR int
  3.  wiz_level_tele(VOID_ARGS)
  4.  {
  5.      if (wizard)
  6.          level_tele();
  7.      else
  8.          pline("Unavailable command '%s'.",
  9.                visctrl((int) cmd_from_func(wiz_level_tele)));
  10.      return 0;
  11.  }
  12.  

wiz_mon_polycontrol

  1.  /* #monpolycontrol command - choose new form for shapechangers, polymorphees */
  2.  STATIC_PTR int
  3.  wiz_mon_polycontrol(VOID_ARGS)
  4.  {
  5.      iflags.mon_polycontrol = !iflags.mon_polycontrol;
  6.      pline("Monster polymorph control is %s.",
  7.            iflags.mon_polycontrol ? "on" : "off");
  8.      return 0;
  9.  }
  10.  

wiz_level_change

  1.  /* #levelchange command - adjust hero's experience level */
  2.  STATIC_PTR int
  3.  wiz_level_change(VOID_ARGS)
  4.  {
  5.      char buf[BUFSZ] = DUMMY;
  6.      int newlevel;
  7.      int ret;
  8.  
  9.      getlin("To what experience level do you want to be set?", buf);
  10.      (void) mungspaces(buf);
  11.      if (buf[0] == '\033' || buf[0] == '\0')
  12.          ret = 0;
  13.      else
  14.          ret = sscanf(buf, "%d", &newlevel);
  15.  
  16.      if (ret != 1) {
  17.          pline1(Never_mind);
  18.          return 0;
  19.      }
  20.      if (newlevel == u.ulevel) {
  21.          You("are already that experienced.");
  22.      } else if (newlevel < u.ulevel) {
  23.          if (u.ulevel == 1) {
  24.              You("are already as inexperienced as you can get.");
  25.              return 0;
  26.          }
  27.          if (newlevel < 1)
  28.              newlevel = 1;
  29.          while (u.ulevel > newlevel)
  30.              losexp("#levelchange");
  31.      } else {
  32.          if (u.ulevel >= MAXULEV) {
  33.              You("are already as experienced as you can get.");
  34.              return 0;
  35.          }
  36.          if (newlevel > MAXULEV)
  37.              newlevel = MAXULEV;
  38.          while (u.ulevel < newlevel)
  39.              pluslvl(FALSE);
  40.      }
  41.      u.ulevelmax = u.ulevel;
  42.      return 0;
  43.  }
  44.  

wiz_panic

  1.  /* #panic command - test program's panic handling */
  2.  STATIC_PTR int
  3.  wiz_panic(VOID_ARGS)
  4.  {
  5.      if (yn("Do you want to call panic() and end your game?") == 'y')
  6.          panic("Crash test.");
  7.      return 0;
  8.  }
  9.  

wiz_polyself

  1.  /* #polyself command - change hero's form */
  2.  STATIC_PTR int
  3.  wiz_polyself(VOID_ARGS)
  4.  {
  5.      polyself(1);
  6.      return 0;
  7.  }
  8.  

wiz_show_seenv

  1.  /* #seenv command */
  2.  STATIC_PTR int
  3.  wiz_show_seenv(VOID_ARGS)
  4.  {
  5.      winid win;
  6.      int x, y, v, startx, stopx, curx;
  7.      char row[COLNO + 1];
  8.  
  9.      win = create_nhwindow(NHW_TEXT);
  10.      /*
  11.       * Each seenv description takes up 2 characters, so center
  12.       * the seenv display around the hero.
  13.       */
  14.      startx = max(1, u.ux - (COLNO / 4));
  15.      stopx = min(startx + (COLNO / 2), COLNO);
  16.      /* can't have a line exactly 80 chars long */
  17.      if (stopx - startx == COLNO / 2)
  18.          startx++;
  19.  
  20.      for (y = 0; y < ROWNO; y++) {
  21.          for (x = startx, curx = 0; x < stopx; x++, curx += 2) {
  22.              if (x == u.ux && y == u.uy) {
  23.                  row[curx] = row[curx + 1] = '@';
  24.              } else {
  25.                  v = levl[x][y].seenv & 0xff;
  26.                  if (v == 0)
  27.                      row[curx] = row[curx + 1] = ' ';
  28.                  else
  29.                      Sprintf(&row[curx], "%02x", v);
  30.              }
  31.          }
  32.          /* remove trailing spaces */
  33.          for (x = curx - 1; x >= 0; x--)
  34.              if (row[x] != ' ')
  35.                  break;
  36.          row[x + 1] = '\0';
  37.  
  38.          putstr(win, 0, row);
  39.      }
  40.      display_nhwindow(win, TRUE);
  41.      destroy_nhwindow(win);
  42.      return 0;
  43.  }
  44.  

wiz_show_vision

  1.  /* #vision command */
  2.  STATIC_PTR int
  3.  wiz_show_vision(VOID_ARGS)
  4.  {
  5.      winid win;
  6.      int x, y, v;
  7.      char row[COLNO + 1];
  8.  
  9.      win = create_nhwindow(NHW_TEXT);
  10.      Sprintf(row, "Flags: 0x%x could see, 0x%x in sight, 0x%x temp lit",
  11.              COULD_SEE, IN_SIGHT, TEMP_LIT);
  12.      putstr(win, 0, row);
  13.      putstr(win, 0, "");
  14.      for (y = 0; y < ROWNO; y++) {
  15.          for (x = 1; x < COLNO; x++) {
  16.              if (x == u.ux && y == u.uy)
  17.                  row[x] = '@';
  18.              else {
  19.                  v = viz_array[y][x]; /* data access should be hidden */
  20.                  if (v == 0)
  21.                      row[x] = ' ';
  22.                  else
  23.                      row[x] = '0' + viz_array[y][x];
  24.              }
  25.          }
  26.          /* remove trailing spaces */
  27.          for (x = COLNO - 1; x >= 1; x--)
  28.              if (row[x] != ' ')
  29.                  break;
  30.          row[x + 1] = '\0';
  31.  
  32.          putstr(win, 0, &row[1]);
  33.      }
  34.      display_nhwindow(win, TRUE);
  35.      destroy_nhwindow(win);
  36.      return 0;
  37.  }
  38.  

wiz_show_wmodes

  1.  /* #wmode command */
  2.  STATIC_PTR int
  3.  wiz_show_wmodes(VOID_ARGS)
  4.  {
  5.      winid win;
  6.      int x, y;
  7.      char row[COLNO + 1];
  8.      struct rm *lev;
  9.      boolean istty = !strcmp(windowprocs.name, "tty");
  10.  
  11.      win = create_nhwindow(NHW_TEXT);
  12.      if (istty)
  13.          putstr(win, 0, ""); /* tty only: blank top line */
  14.      for (y = 0; y < ROWNO; y++) {
  15.          for (x = 0; x < COLNO; x++) {
  16.              lev = &levl[x][y];
  17.              if (x == u.ux && y == u.uy)
  18.                  row[x] = '@';
  19.              else if (IS_WALL(lev->typ) || lev->typ == SDOOR)
  20.                  row[x] = '0' + (lev->wall_info & WM_MASK);
  21.              else if (lev->typ == CORR)
  22.                  row[x] = '#';
  23.              else if (IS_ROOM(lev->typ) || IS_DOOR(lev->typ))
  24.                  row[x] = '.';
  25.              else
  26.                  row[x] = 'x';
  27.          }
  28.          row[COLNO] = '\0';
  29.          /* map column 0, levl[0][], is off the left edge of the screen */
  30.          putstr(win, 0, &row[1]);
  31.      }
  32.      display_nhwindow(win, TRUE);
  33.      destroy_nhwindow(win);
  34.      return 0;
  35.  }
  36.  

wiz_map_levltyp

  1.  /* wizard mode variant of #terrain; internal levl[][].typ values in base-36 */
  2.  STATIC_OVL void
  3.  wiz_map_levltyp(VOID_ARGS)
  4.  {
  5.      winid win;
  6.      int x, y, terrain;
  7.      char row[COLNO + 1];
  8.      boolean istty = !strcmp(windowprocs.name, "tty");
  9.  
  10.      win = create_nhwindow(NHW_TEXT);
  11.      /* map row 0, levl[][0], is drawn on the second line of tty screen */
  12.      if (istty)
  13.          putstr(win, 0, ""); /* tty only: blank top line */
  14.      for (y = 0; y < ROWNO; y++) {
  15.          /* map column 0, levl[0][], is off the left edge of the screen;
  16.             it should always have terrain type "undiggable stone" */
  17.          for (x = 1; x < COLNO; x++) {
  18.              terrain = levl[x][y].typ;
  19.              /* assumes there aren't more than 10+26+26 terrain types */
  20.              row[x - 1] = (char) ((terrain == STONE && !may_dig(x, y))
  21.                                      ? '*'
  22.                                      : (terrain < 10)
  23.                                         ? '0' + terrain
  24.                                         : (terrain < 36)
  25.                                            ? 'a' + terrain - 10
  26.                                            : 'A' + terrain - 36);
  27.          }
  28.          x--;
  29.          if (levl[0][y].typ != STONE || may_dig(0, y))
  30.              row[x++] = '!';
  31.          row[x] = '\0';
  32.          putstr(win, 0, row);
  33.      }
  34.  
  35.      {
  36.          char dsc[BUFSZ];
  37.          s_level *slev = Is_special(&u.uz);
  38.  
  39.          Sprintf(dsc, "D:%d,L:%d", u.uz.dnum, u.uz.dlevel);
  40.          /* [dungeon branch features currently omitted] */
  41.          /* special level features */
  42.          if (slev) {
  43.              Sprintf(eos(dsc), " \"%s\"", slev->proto);
  44.              /* special level flags (note: dungeon.def doesn't set `maze'
  45.                 or `hell' for any specific levels so those never show up) */
  46.              if (slev->flags.maze_like)
  47.                  Strcat(dsc, " mazelike");
  48.              if (slev->flags.hellish)
  49.                  Strcat(dsc, " hellish");
  50.              if (slev->flags.town)
  51.                  Strcat(dsc, " town");
  52.              if (slev->flags.rogue_like)
  53.                  Strcat(dsc, " roguelike");
  54.              /* alignment currently omitted to save space */
  55.          }
  56.          /* level features */
  57.          if (level.flags.nfountains)
  58.              Sprintf(eos(dsc), " %c:%d", defsyms[S_fountain].sym,
  59.                      (int) level.flags.nfountains);
  60.          if (level.flags.nsinks)
  61.              Sprintf(eos(dsc), " %c:%d", defsyms[S_sink].sym,
  62.                      (int) level.flags.nsinks);
  63.          if (level.flags.has_vault)
  64.              Strcat(dsc, " vault");
  65.          if (level.flags.has_shop)
  66.              Strcat(dsc, " shop");
  67.          if (level.flags.has_temple)
  68.              Strcat(dsc, " temple");
  69.          if (level.flags.has_court)
  70.              Strcat(dsc, " throne");
  71.          if (level.flags.has_zoo)
  72.              Strcat(dsc, " zoo");
  73.          if (level.flags.has_morgue)
  74.              Strcat(dsc, " morgue");
  75.          if (level.flags.has_barracks)
  76.              Strcat(dsc, " barracks");
  77.          if (level.flags.has_beehive)
  78.              Strcat(dsc, " hive");
  79.          if (level.flags.has_swamp)
  80.              Strcat(dsc, " swamp");
  81.          /* level flags */
  82.          if (level.flags.noteleport)
  83.              Strcat(dsc, " noTport");
  84.          if (level.flags.hardfloor)
  85.              Strcat(dsc, " noDig");
  86.          if (level.flags.nommap)
  87.              Strcat(dsc, " noMMap");
  88.          if (!level.flags.hero_memory)
  89.              Strcat(dsc, " noMem");
  90.          if (level.flags.shortsighted)
  91.              Strcat(dsc, " shortsight");
  92.          if (level.flags.graveyard)
  93.              Strcat(dsc, " graveyard");
  94.          if (level.flags.is_maze_lev)
  95.              Strcat(dsc, " maze");
  96.          if (level.flags.is_cavernous_lev)
  97.              Strcat(dsc, " cave");
  98.          if (level.flags.arboreal)
  99.              Strcat(dsc, " tree");
  100.          if (Sokoban)
  101.              Strcat(dsc, " sokoban-rules");
  102.          /* non-flag info; probably should include dungeon branching
  103.             checks (extra stairs and magic portals) here */
  104.          if (Invocation_lev(&u.uz))
  105.              Strcat(dsc, " invoke");
  106.          if (On_W_tower_level(&u.uz))
  107.              Strcat(dsc, " tower");
  108.          /* append a branch identifier for completeness' sake */
  109.          if (u.uz.dnum == 0)
  110.              Strcat(dsc, " dungeon");
  111.          else if (u.uz.dnum == mines_dnum)
  112.              Strcat(dsc, " mines");
  113.          else if (In_sokoban(&u.uz))
  114.              Strcat(dsc, " sokoban");
  115.          else if (u.uz.dnum == quest_dnum)
  116.              Strcat(dsc, " quest");
  117.          else if (Is_knox(&u.uz))
  118.              Strcat(dsc, " ludios");
  119.          else if (u.uz.dnum == 1)
  120.              Strcat(dsc, " gehennom");
  121.          else if (u.uz.dnum == tower_dnum)
  122.              Strcat(dsc, " vlad");
  123.          else if (In_endgame(&u.uz))
  124.              Strcat(dsc, " endgame");
  125.          else {
  126.              /* somebody's added a dungeon branch we're not expecting */
  127.              const char *brname = dungeons[u.uz.dnum].dname;
  128.  
  129.              if (!brname || !*brname)
  130.                  brname = "unknown";
  131.              if (!strncmpi(brname, "the ", 4))
  132.                  brname += 4;
  133.              Sprintf(eos(dsc), " %s", brname);
  134.          }
  135.          /* limit the line length to map width */
  136.          if (strlen(dsc) >= COLNO)
  137.              dsc[COLNO - 1] = '\0'; /* truncate */
  138.          putstr(win, 0, dsc);
  139.      }
  140.  
  141.      display_nhwindow(win, TRUE);
  142.      destroy_nhwindow(win);
  143.      return;
  144.  }
  145.  
  146.  /* temporary? hack, since level type codes aren't the same as screen
  147.     symbols and only the latter have easily accessible descriptions */
  148.  static const char *levltyp[] = {
  149.      "stone", "vertical wall", "horizontal wall", "top-left corner wall",
  150.      "top-right corner wall", "bottom-left corner wall",
  151.      "bottom-right corner wall", "cross wall", "tee-up wall", "tee-down wall",
  152.      "tee-left wall", "tee-right wall", "drawbridge wall", "tree",
  153.      "secret door", "secret corridor", "pool", "moat", "water",
  154.      "drawbridge up", "lava pool", "iron bars", "door", "corridor", "room",
  155.      "stairs", "ladder", "fountain", "throne", "sink", "grave", "altar", "ice",
  156.      "drawbridge down", "air", "cloud",
  157.      /* not a real terrain type, but used for undiggable stone
  158.         by wiz_map_levltyp() */
  159.      "unreachable/undiggable",
  160.      /* padding in case the number of entries above is odd */
  161.      ""
  162.  };
  163.  

wiz_levltyp_legend

  1.  /* explanation of base-36 output from wiz_map_levltyp() */
  2.  STATIC_OVL void
  3.  wiz_levltyp_legend(VOID_ARGS)
  4.  {
  5.      winid win;
  6.      int i, j, last, c;
  7.      const char *dsc, *fmt;
  8.      char buf[BUFSZ];
  9.  
  10.      win = create_nhwindow(NHW_TEXT);
  11.      putstr(win, 0, "#terrain encodings:");
  12.      putstr(win, 0, "");
  13.      fmt = " %c - %-28s"; /* TODO: include tab-separated variant for win32 */
  14.      *buf = '\0';
  15.      /* output in pairs, left hand column holds [0],[1],...,[N/2-1]
  16.         and right hand column holds [N/2],[N/2+1],...,[N-1];
  17.         N ('last') will always be even, and may or may not include
  18.         the empty string entry to pad out the final pair, depending
  19.         upon how many other entries are present in levltyp[] */
  20.      last = SIZE(levltyp) & ~1;
  21.      for (i = 0; i < last / 2; ++i)
  22.          for (j = i; j < last; j += last / 2) {
  23.              dsc = levltyp[j];
  24.              c = !*dsc ? ' '
  25.                     : !strncmp(dsc, "unreachable", 11) ? '*'
  26.                        /* same int-to-char conversion as wiz_map_levltyp() */
  27.                        : (j < 10) ? '0' + j
  28.                           : (j < 36) ? 'a' + j - 10
  29.                              : 'A' + j - 36;
  30.              Sprintf(eos(buf), fmt, c, dsc);
  31.              if (j > i) {
  32.                  putstr(win, 0, buf);
  33.                  *buf = '\0';
  34.              }
  35.          }
  36.      display_nhwindow(win, TRUE);
  37.      destroy_nhwindow(win);
  38.      return;
  39.  }
  40.  

wiz_smell

  1.  /* #wizsmell command - test usmellmon(). */
  2.  STATIC_PTR int
  3.  wiz_smell(VOID_ARGS)
  4.  {
  5.      int ans = 0;
  6.      int mndx;  /* monster index */
  7.      coord cc;  /* screen pos of unknown glyph */
  8.      int glyph; /* glyph at selected position */
  9.  
  10.      cc.x = u.ux;
  11.      cc.y = u.uy;
  12.      mndx = 0; /* gcc -Wall lint */
  13.      if (!olfaction(youmonst.data)) {
  14.          You("are incapable of detecting odors in your present form.");
  15.          return 0;
  16.      }
  17.  
  18.      pline("You can move the cursor to a monster that you want to smell.");
  19.      do {
  20.          pline("Pick a monster to smell.");
  21.          ans = getpos(&cc, TRUE, "a monster");
  22.          if (ans < 0 || cc.x < 0) {
  23.              return 0; /* done */
  24.          }
  25.          /* Convert the glyph at the selected position to a mndxbol. */
  26.          glyph = glyph_at(cc.x, cc.y);
  27.          if (glyph_is_monster(glyph))
  28.              mndx = glyph_to_mon(glyph);
  29.          else
  30.              mndx = 0;
  31.          /* Is it a monster? */
  32.          if (mndx) {
  33.              if (!usmellmon(&mons[mndx]))
  34.                  pline("That monster seems to give off no smell.");
  35.          } else
  36.              pline("That is not a monster.");
  37.      } while (TRUE);
  38.      return 0;
  39.  }
  40.  

wiz_intrinsic

  1.  /* #wizinstrinsic command to set some intrinsics for testing */
  2.  STATIC_PTR int
  3.  wiz_intrinsic(VOID_ARGS)
  4.  {
  5.      if (wizard) {
  6.          extern const struct propname {
  7.              int prop_num;
  8.              const char *prop_name;
  9.          } propertynames[]; /* timeout.c */
  10.          static const char wizintrinsic[] = "#wizintrinsic";
  11.          static const char fmt[] = "You are%s %s.";
  12.          winid win;
  13.          anything any;
  14.          char buf[BUFSZ];
  15.          int i, j, n, p, amt, typ;
  16.          long oldtimeout, newtimeout;
  17.          const char *propname;
  18.          menu_item *pick_list = (menu_item *) 0;
  19.  
  20.          any = zeroany;
  21.          win = create_nhwindow(NHW_MENU);
  22.          start_menu(win);
  23.          for (i = 0; (propname = propertynames[i].prop_name) != 0; ++i) {
  24.              p = propertynames[i].prop_num;
  25.              if (p == HALLUC_RES) {
  26.                  /* Grayswandir vs hallucination; ought to be redone to
  27.                     use u.uprops[HALLUC].blocked instead of being treated
  28.                     as a separate property; letting in be manually toggled
  29.                     even only in wizard mode would be asking for trouble... */
  30.                  continue;
  31.              }
  32.              if (p == FIRE_RES) {
  33.                  any.a_int = 0;
  34.                  add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "--", FALSE);
  35.              }
  36.              any.a_int = i + 1; /* +1: avoid 0 */
  37.              oldtimeout = u.uprops[p].intrinsic & TIMEOUT;
  38.              if (oldtimeout)
  39.                  Sprintf(buf, "%-27s [%li]", propname, oldtimeout);
  40.              else
  41.                  Sprintf(buf, "%s", propname);
  42.              add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  43.          }
  44.          end_menu(win, "Which intrinsics?");
  45.          n = select_menu(win, PICK_ANY, &pick_list);
  46.          destroy_nhwindow(win);
  47.  
  48.          amt = 30; /* TODO: prompt for duration */
  49.          for (j = 0; j < n; ++j) {
  50.              i = pick_list[j].item.a_int - 1; /* -1: reverse +1 above */
  51.              p = propertynames[i].prop_num;
  52.              oldtimeout = u.uprops[p].intrinsic & TIMEOUT;
  53.              newtimeout = oldtimeout + (long) amt;
  54.              switch (p) {
  55.              case SICK:
  56.              case SLIMED:
  57.              case STONED:
  58.                  if (oldtimeout > 0L && newtimeout > oldtimeout)
  59.                      newtimeout = oldtimeout;
  60.                  break;
  61.              }
  62.  
  63.              switch (p) {
  64.              case BLINDED:
  65.                  make_blinded(newtimeout, TRUE);
  66.                  break;
  67.  #if 0       /* make_confused() only gives feedback when confusion is
  68.               * ending so use the 'default' case for it instead */
  69.              case CONFUSION:
  70.                  make_confused(newtimeout, TRUE);
  71.                  break;
  72.  #endif /*0*/
  73.              case DEAF:
  74.                  make_deaf(newtimeout, TRUE);
  75.                  break;
  76.              case HALLUC:
  77.                  make_hallucinated(newtimeout, TRUE, 0L);
  78.                  break;
  79.              case SICK:
  80.                  typ = !rn2(2) ? SICK_VOMITABLE : SICK_NONVOMITABLE;
  81.                  make_sick(newtimeout, wizintrinsic, TRUE, typ);
  82.                  break;
  83.              case SLIMED:
  84.                  Sprintf(buf, fmt,
  85.                          !Slimed ? "" : " still", "turning into slime");
  86.                  make_slimed(newtimeout, buf);
  87.                  break;
  88.              case STONED:
  89.                  Sprintf(buf, fmt,
  90.                          !Stoned ? "" : " still", "turning into stone");
  91.                  make_stoned(newtimeout, buf, KILLED_BY, wizintrinsic);
  92.                  break;
  93.              case STUNNED:
  94.                  make_stunned(newtimeout, TRUE);
  95.                  break;
  96.              case VOMITING:
  97.                  Sprintf(buf, fmt, !Vomiting ? "" : " still", "vomiting");
  98.                  make_vomiting(newtimeout, FALSE);
  99.                  pline1(buf);
  100.                  break;
  101.              default:
  102.                  pline("Timeout for %s %s %d.", propertynames[i].prop_name,
  103.                        oldtimeout ? "increased by" : "set to", amt);
  104.                  incr_itimeout(&u.uprops[p].intrinsic, amt);
  105.                  break;
  106.              }
  107.              context.botl = 1; /* probably not necessary... */
  108.          }
  109.          if (n >= 1)
  110.              free((genericptr_t) pick_list);
  111.          doredraw();
  112.      } else
  113.          pline("Unavailable command '%s'.",
  114.                visctrl((int) cmd_from_func(wiz_intrinsic)));
  115.      return 0;
  116.  }
  117.  

wiz_rumor_check

  1.  /* #wizrumorcheck command - verify each rumor access */
  2.  STATIC_PTR int
  3.  wiz_rumor_check(VOID_ARGS)
  4.  {
  5.      rumor_check();
  6.      return 0;
  7.  }
  8.  

doterrain

  1.  /* #terrain command -- show known map, inspired by crawl's '|' command */
  2.  STATIC_PTR int
  3.  doterrain(VOID_ARGS)
  4.  {
  5.      winid men;
  6.      menu_item *sel;
  7.      anything any;
  8.      int n;
  9.      int which;
  10.  
  11.      /*
  12.       * normal play: choose between known map without mons, obj, and traps
  13.       *  (to see underlying terrain only), or
  14.       *  known map without mons and objs (to see traps under mons and objs), or
  15.       *  known map without mons (to see objects under monsters);
  16.       * explore mode: normal choices plus full map (w/o mons, objs, traps);
  17.       * wizard mode: normal and explore choices plus
  18.       *  a dump of the internal levl[][].typ codes w/ level flags, or
  19.       *  a legend for the levl[][].typ codes dump
  20.       */
  21.      men = create_nhwindow(NHW_MENU);
  22.      start_menu(men);
  23.      any = zeroany;
  24.      any.a_int = 1;
  25.      add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE,
  26.               "known map without monsters, objects, and traps",
  27.               MENU_SELECTED);
  28.      any.a_int = 2;
  29.      add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE,
  30.               "known map without monsters and objects",
  31.               MENU_UNSELECTED);
  32.      any.a_int = 3;
  33.      add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE,
  34.               "known map without monsters",
  35.               MENU_UNSELECTED);
  36.      if (discover || wizard) {
  37.          any.a_int = 4;
  38.          add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE,
  39.                   "full map without monsters, objects, and traps",
  40.                   MENU_UNSELECTED);
  41.          if (wizard) {
  42.              any.a_int = 5;
  43.              add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE,
  44.                       "internal levl[][].typ codes in base-36",
  45.                       MENU_UNSELECTED);
  46.              any.a_int = 6;
  47.              add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE,
  48.                       "legend of base-36 levl[][].typ codes",
  49.                       MENU_UNSELECTED);
  50.          }
  51.      }
  52.      end_menu(men, "View which?");
  53.  
  54.      n = select_menu(men, PICK_ONE, &sel);
  55.      destroy_nhwindow(men);
  56.      /*
  57.       * n <  0: player used ESC to cancel;
  58.       * n == 0: preselected entry was explicitly chosen and got toggled off;
  59.       * n == 1: preselected entry was implicitly chosen via <space>|<enter>;
  60.       * n == 2: another entry was explicitly chosen, so skip preselected one.
  61.       */
  62.      which = (n < 0) ? -1 : (n == 0) ? 1 : sel[0].item.a_int;
  63.      if (n > 1 && which == 1)
  64.          which = sel[1].item.a_int;
  65.      if (n > 0)
  66.          free((genericptr_t) sel);
  67.  
  68.      switch (which) {
  69.      case 1: /* known map */
  70.          reveal_terrain(0, TER_MAP);
  71.          break;
  72.      case 2: /* known map with known traps */
  73.          reveal_terrain(0, TER_MAP | TER_TRP);
  74.          break;
  75.      case 3: /* known map with known traps and objects */
  76.          reveal_terrain(0, TER_MAP | TER_TRP | TER_OBJ);
  77.          break;
  78.      case 4: /* full map */
  79.          reveal_terrain(1, TER_MAP);
  80.          break;
  81.      case 5: /* map internals */
  82.          wiz_map_levltyp();
  83.          break;
  84.      case 6: /* internal details */
  85.          wiz_levltyp_legend();
  86.          break;
  87.      default:
  88.          break;
  89.      }
  90.      return 0; /* no time elapses */
  91.  }
  92.  
  93.  /* -enlightenment and conduct- */
  94.  static winid en_win = WIN_ERR;
  95.  static const char You_[] = "You ", are[] = "are ", were[] = "were ",
  96.                    have[] = "have ", had[] = "had ", can[] = "can ",
  97.                    could[] = "could ";
  98.  static const char have_been[] = "have been ", have_never[] = "have never ",
  99.                    never[] = "never ";
  100.  
  101.  #define enl_msg(prefix, present, past, suffix, ps) \
  102.      enlght_line(prefix, final ? past : present, suffix, ps)
  103.  #define you_are(attr, ps) enl_msg(You_, are, were, attr, ps)
  104.  #define you_have(attr, ps) enl_msg(You_, have, had, attr, ps)
  105.  #define you_can(attr, ps) enl_msg(You_, can, could, attr, ps)
  106.  #define you_have_been(goodthing) enl_msg(You_, have_been, were, goodthing, "")
  107.  #define you_have_never(badthing) \
  108.      enl_msg(You_, have_never, never, badthing, "")
  109.  #define you_have_X(something) \
  110.      enl_msg(You_, have, (const char *) "", something, "")
  111.  

enlght_line

  1.  static void
  2.  enlght_line(start, middle, end, ps)
  3.  const char *start, *middle, *end, *ps;
  4.  {
  5.      char buf[BUFSZ];
  6.  
  7.      Sprintf(buf, " %s%s%s%s.", start, middle, end, ps);
  8.      putstr(en_win, 0, buf);
  9.  }
  10.  

enlght_combatinc

  1.  /* format increased chance to hit or damage or defense (Protection) */
  2.  static char *
  3.  enlght_combatinc(inctyp, incamt, final, outbuf)
  4.  const char *inctyp;
  5.  int incamt, final;
  6.  char *outbuf;
  7.  {
  8.      const char *modif, *bonus;
  9.      boolean invrt;
  10.      int absamt;
  11.  
  12.      absamt = abs(incamt);
  13.      /* Protection amount is typically larger than damage or to-hit;
  14.         reduce magnitude by a third in order to stretch modifier ranges
  15.         (small:1..5, moderate:6..10, large:11..19, huge:20+) */
  16.      if (!strcmp(inctyp, "defense"))
  17.          absamt = (absamt * 2) / 3;
  18.  
  19.      if (absamt <= 3)
  20.          modif = "small";
  21.      else if (absamt <= 6)
  22.          modif = "moderate";
  23.      else if (absamt <= 12)
  24.          modif = "large";
  25.      else
  26.          modif = "huge";
  27.  
  28.      modif = !incamt ? "no" : an(modif); /* ("no" case shouldn't happen) */
  29.      bonus = (incamt >= 0) ? "bonus" : "penalty";
  30.      /* "bonus <foo>" (to hit) vs "<bar> bonus" (damage, defense) */
  31.      invrt = strcmp(inctyp, "to hit") ? TRUE : FALSE;
  32.  
  33.      Sprintf(outbuf, "%s %s %s", modif, invrt ? inctyp : bonus,
  34.              invrt ? bonus : inctyp);
  35.      if (final || wizard)
  36.          Sprintf(eos(outbuf), " (%s%d)", (incamt > 0) ? "+" : "", incamt);
  37.  
  38.      return outbuf;
  39.  }
  40.  

enlght_halfdmg

  1.  /* report half physical or half spell damage */
  2.  STATIC_OVL void
  3.  enlght_halfdmg(category, final)
  4.  int category;
  5.  int final;
  6.  {
  7.      const char *category_name;
  8.      char buf[BUFSZ];
  9.  
  10.      switch (category) {
  11.      case HALF_PHDAM:
  12.          category_name = "physical";
  13.          break;
  14.      case HALF_SPDAM:
  15.          category_name = "spell";
  16.          break;
  17.      default:
  18.          category_name = "unknown";
  19.          break;
  20.      }
  21.      Sprintf(buf, " %s %s damage", (final || wizard) ? "half" : "reduced",
  22.              category_name);
  23.      enl_msg(You_, "take", "took", buf, from_what(category));
  24.  }
  25.  

walking_on_water

  1.  /* is hero actively using water walking capability on water (or lava)? */
  2.  STATIC_OVL boolean
  3.  walking_on_water()
  4.  {
  5.      if (u.uinwater || Levitation || Flying)
  6.          return FALSE;
  7.      return (boolean) (Wwalking
  8.                        && (is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)));
  9.  }
  10.  

cause_known

  1.  /* check whether hero is wearing something that player definitely knows
  2.     confers the target property; item must have been seen and its type
  3.     discovered but it doesn't necessarily have to be fully identified */
  4.  STATIC_OVL boolean
  5.  cause_known(propindx)
  6.  int propindx; /* index of a property which can be conveyed by worn item */
  7.  {
  8.      register struct obj *o;
  9.      long mask = W_ARMOR | W_AMUL | W_RING | W_TOOL;
  10.  
  11.      /* simpler than from_what()/what_gives(); we don't attempt to
  12.         handle artifacts and we deliberately ignore wielded items */
  13.      for (o = invent; o; o = o->nobj) {
  14.          if (!(o->owornmask & mask))
  15.              continue;
  16.          if ((int) objects[o->otyp].oc_oprop == propindx
  17.              && objects[o->otyp].oc_name_known && o->dknown)
  18.              return TRUE;
  19.      }
  20.      return FALSE;
  21.  }
  22.  

attrval

  1.  /* format a characteristic value, accommodating Strength's strangeness */
  2.  STATIC_OVL char *
  3.  attrval(attrindx, attrvalue, resultbuf)
  4.  int attrindx, attrvalue;
  5.  char resultbuf[]; /* should be at least [7] to hold "18/100\0" */
  6.  {
  7.      if (attrindx != A_STR || attrvalue <= 18)
  8.          Sprintf(resultbuf, "%d", attrvalue);
  9.      else if (attrvalue > STR18(100)) /* 19 to 25 */
  10.          Sprintf(resultbuf, "%d", attrvalue - 100);
  11.      else /* simplify "18/ **" to be "18/100" */
  12.          Sprintf(resultbuf, "18/%02d", attrvalue - 18);
  13.      return resultbuf;
  14.  }
  15.  

enlightenment

  1.  void
  2.  enlightenment(mode, final)
  3.  int mode;  /* BASICENLIGHTENMENT | MAGICENLIGHTENMENT (| both) */
  4.  int final; /* ENL_GAMEINPROGRESS:0, ENL_GAMEOVERALIVE, ENL_GAMEOVERDEAD */
  5.  {
  6.      char buf[BUFSZ], tmpbuf[BUFSZ];
  7.  
  8.      Strcpy(tmpbuf, plname);
  9.      *tmpbuf = highc(*tmpbuf); /* same adjustment as bottom line */
  10.      /* as in background_enlightenment, when poly'd we need to use the saved
  11.         gender in u.mfemale rather than the current you-as-monster gender */
  12.      Sprintf(buf, "%s the %s's attributes:", tmpbuf,
  13.              ((Upolyd ? u.mfemale : flags.female) && urole.name.f)
  14.                  ? urole.name.f
  15.                  : urole.name.m);
  16.  
  17.      en_win = create_nhwindow(NHW_MENU);
  18.      /* title */
  19.      putstr(en_win, 0, buf); /* "Conan the Archeologist's attributes:" */
  20.      /* background and characteristics; ^X or end-of-game disclosure */
  21.      if (mode & BASICENLIGHTENMENT) {
  22.          /* role, race, alignment, deities */
  23.          background_enlightenment(mode, final);
  24.          /* strength, dexterity, &c */
  25.          characteristics_enlightenment(mode, final);
  26.      }
  27.      /* expanded status line information, including things which aren't
  28.         included there due to space considerations--such as obvious
  29.         alternative movement indicators (riding, levitation, &c), and
  30.         various troubles (turning to stone, trapped, confusion, &c);
  31.         shown for both basic and magic enlightenment */
  32.      status_enlightenment(mode, final);
  33.      /* remaining attributes; shown for potion,&c or wizard mode and
  34.         explore mode ^X or end of game disclosure */
  35.      if (mode & MAGICENLIGHTENMENT) {
  36.          /* intrinsics and other traditional enlightenment feedback */
  37.          attributes_enlightenment(mode, final);
  38.      }
  39.      display_nhwindow(en_win, TRUE);
  40.      destroy_nhwindow(en_win);
  41.      en_win = WIN_ERR;
  42.  }
  43.  
  44.  /*ARGSUSED*/

background_enlightenment

  1.  /* display role, race, alignment and such to en_win */
  2.  STATIC_OVL void
  3.  background_enlightenment(unused_mode, final)
  4.  int unused_mode UNUSED;
  5.  int final;
  6.  {
  7.      const char *role_titl, *rank_titl;
  8.      int innategend, difgend, difalgn;
  9.      char buf[BUFSZ], tmpbuf[BUFSZ];
  10.  
  11.      /* note that if poly'd, we need to use u.mfemale instead of flags.female
  12.         to access hero's saved gender-as-human/elf/&c rather than current one */
  13.      innategend = (Upolyd ? u.mfemale : flags.female) ? 1 : 0;
  14.      role_titl = (innategend && urole.name.f) ? urole.name.f : urole.name.m;
  15.      rank_titl = rank_of(u.ulevel, Role_switch, innategend);
  16.  
  17.      putstr(en_win, 0, ""); /* separator after title */
  18.      putstr(en_win, 0, "Background:");
  19.  
  20.      /* if polymorphed, report current shape before underlying role;
  21.         will be repeated as first status: "you are transformed" and also
  22.         among various attributes: "you are in beast form" (after being
  23.         told about lycanthropy) or "you are polymorphed into <a foo>"
  24.         (with countdown timer appended for wizard mode); we really want
  25.         the player to know he's not a samurai at the moment... */
  26.      if (Upolyd) {
  27.          struct permonst *uasmon = youmonst.data;
  28.  
  29.          tmpbuf[0] = '\0';
  30.          /* here we always use current gender, not saved role gender */
  31.          if (!is_male(uasmon) && !is_female(uasmon) && !is_neuter(uasmon))
  32.              Sprintf(tmpbuf, "%s ", genders[flags.female ? 1 : 0].adj);
  33.          Sprintf(buf, "%sin %s%s form", !final ? "currently " : "", tmpbuf,
  34.                  uasmon->mname);
  35.          you_are(buf, "");
  36.      }
  37.  
  38.      /* report role; omit gender if it's redundant (eg, "female priestess") */
  39.      tmpbuf[0] = '\0';
  40.      if (!urole.name.f
  41.          && ((urole.allow & ROLE_GENDMASK) == (ROLE_MALE | ROLE_FEMALE)
  42.              || innategend != flags.initgend))
  43.          Sprintf(tmpbuf, "%s ", genders[innategend].adj);
  44.      buf[0] = '\0';
  45.      if (Upolyd)
  46.          Strcpy(buf, "actually "); /* "You are actually a ..." */
  47.      if (!strcmpi(rank_titl, role_titl)) {
  48.          /* omit role when rank title matches it */
  49.          Sprintf(eos(buf), "%s, level %d %s%s", an(rank_titl), u.ulevel,
  50.                  tmpbuf, urace.noun);
  51.      } else {
  52.          Sprintf(eos(buf), "%s, a level %d %s%s %s", an(rank_titl), u.ulevel,
  53.                  tmpbuf, urace.adj, role_titl);
  54.      }
  55.      you_are(buf, "");
  56.  
  57.      /* report alignment (bypass you_are() in order to omit ending period);
  58.         adverb is used to distinguish between temporary change (helm of opp.
  59.         alignment), permanent change (one-time conversion), and original */
  60.      Sprintf(buf, " %s%s%s, %son a mission for %s",
  61.              You_, !final ? are : were,
  62.              align_str(u.ualign.type),
  63.              /* helm of opposite alignment (might hide conversion) */
  64.              (u.ualign.type != u.ualignbase[A_CURRENT])
  65.                 /* what's the past tense of "currently"? if we used "formerly"
  66.                    it would sound like a reference to the original alignment */
  67.                 ? (!final ? "currently " : "temporarily ")
  68.                 /* permanent conversion */
  69.                 : (u.ualign.type != u.ualignbase[A_ORIGINAL])
  70.                    /* and what's the past tense of "now"? certainly not "then"
  71.                       in a context like this...; "belatedly" == weren't that
  72.                       way sooner (in other words, didn't start that way) */
  73.                    ? (!final ? "now " : "belatedly ")
  74.                    /* atheist (ignored in very early game) */
  75.                    : (!u.uconduct.gnostic && moves > 1000L)
  76.                       ? "nominally "
  77.                       /* lastly, normal case */
  78.                       : "",
  79.              u_gname());
  80.      putstr(en_win, 0, buf);
  81.      /* show the rest of this game's pantheon (finishes previous sentence)
  82.         [appending "also Moloch" at the end would allow for straightforward
  83.         trailing "and" on all three aligned entries but looks too verbose] */
  84.      Sprintf(buf, " who %s opposed by", !final ? "is" : "was");
  85.      if (u.ualign.type != A_LAWFUL)
  86.          Sprintf(eos(buf), " %s (%s) and", align_gname(A_LAWFUL),
  87.                  align_str(A_LAWFUL));
  88.      if (u.ualign.type != A_NEUTRAL)
  89.          Sprintf(eos(buf), " %s (%s)%s", align_gname(A_NEUTRAL),
  90.                  align_str(A_NEUTRAL),
  91.                  (u.ualign.type != A_CHAOTIC) ? " and" : "");
  92.      if (u.ualign.type != A_CHAOTIC)
  93.          Sprintf(eos(buf), " %s (%s)", align_gname(A_CHAOTIC),
  94.                  align_str(A_CHAOTIC));
  95.      Strcat(buf, "."); /* terminate sentence */
  96.      putstr(en_win, 0, buf);
  97.  
  98.      /* show original alignment,gender,race,role if any have been changed;
  99.         giving separate message for temporary alignment change bypasses need
  100.         for tricky phrasing otherwise necessitated by possibility of having
  101.         helm of opposite alignment mask a permanent alignment conversion */
  102.      difgend = (innategend != flags.initgend);
  103.      difalgn = (((u.ualign.type != u.ualignbase[A_CURRENT]) ? 1 : 0)
  104.                 + ((u.ualignbase[A_CURRENT] != u.ualignbase[A_ORIGINAL])
  105.                    ? 2 : 0));
  106.      if (difalgn & 1) { /* have temporary alignment so report permanent one */
  107.          Sprintf(buf, "actually %s", align_str(u.ualignbase[A_CURRENT]));
  108.          you_are(buf, "");
  109.          difalgn &= ~1; /* suppress helm from "started out <foo>" message */
  110.      }
  111.      if (difgend || difalgn) { /* sex change or perm align change or both */
  112.          Sprintf(buf, " You started out %s%s%s.",
  113.                  difgend ? genders[flags.initgend].adj : "",
  114.                  (difgend && difalgn) ? " and " : "",
  115.                  difalgn ? align_str(u.ualignbase[A_ORIGINAL]) : "");
  116.          putstr(en_win, 0, buf);
  117.      }
  118.  }
  119.  

characteristics_enlightenment

  1.  /* characteristics: expanded version of bottom line strength, dexterity, &c;
  2.     [3.6.1: now includes all status info (except things already shown in the
  3.     'background' section), primarily so that blind players can suppress the
  4.     status line(s) altogether and use ^X feedback on demand to view HP, &c] */
  5.  STATIC_OVL void
  6.  characteristics_enlightenment(mode, final)
  7.  int mode;
  8.  int final;
  9.  {
  10.      char buf[BUFSZ];
  11.      int hp = Upolyd ? u.mh : u.uhp;
  12.      int hpmax = Upolyd ? u.mhmax : u.uhpmax;
  13.  
  14.      putstr(en_win, 0, ""); /* separator after background */
  15.      putstr(en_win, 0,
  16.             final ? "Final Characteristics:" : "Current Characteristics:");
  17.  
  18.      if (hp < 0)
  19.          hp = 0;
  20.      Sprintf(buf, "%d hit points (max:%d)", hp, hpmax);
  21.      you_have(buf, "");
  22.  
  23.      Sprintf(buf, "%d magic power (max:%d)", u.uen, u.uenmax);
  24.      you_have(buf, "");
  25.  
  26.      Sprintf(buf, "%d", u.uac);
  27.      enl_msg("Your armor class ", "is ", "was ", buf, "");
  28.  
  29.      if (Upolyd) {
  30.          switch (mons[u.umonnum].mlevel) {
  31.          case 0:
  32.              /* status line currently being explained shows "HD:0" */
  33.              Strcpy(buf, "0 hit dice (actually 1/2)");
  34.              break;
  35.          case 1:
  36.              Strcpy(buf, "1 hit die");
  37.              break;
  38.          default:
  39.              Sprintf(buf, "%d hit dice", mons[u.umonnum].mlevel);
  40.              break;
  41.          }
  42.      } else {
  43.          /* flags.showexp does not matter */
  44.          /* experience level is already shown in the Background section */
  45.          Sprintf(buf, "%-1ld experience point%s",
  46.                  u.uexp, plur(u.uexp));
  47.      }
  48.      you_have(buf, "");
  49.  
  50.      /* this is shown even if the 'time' option is off */
  51.      Sprintf(buf, "the dungeon %ld turn%s ago", moves, plur(moves));
  52.      /* same phrasing at end of game:  "entered" is unconditional */
  53.      enlght_line(You_, "entered ", buf, "");
  54.  
  55.  #ifdef SCORE_ON_BOTL
  56.      if (flags.showscore) {
  57.          /* describes what's shown on status line, which is an approximation;
  58.             only show it here if player has the 'showscore' option enabled */
  59.          Sprintf(buf, "%ld%s", botl_score(),
  60.                  !final ? "" : " before end-of-game adjustments");
  61.          enl_msg("Your score ", "is ", "was ", buf, "");
  62.      }
  63.  #endif
  64.  
  65.      /* bottom line order */
  66.      one_characteristic(mode, final, A_STR); /* strength */
  67.      one_characteristic(mode, final, A_DEX); /* dexterity */
  68.      one_characteristic(mode, final, A_CON); /* constitution */
  69.      one_characteristic(mode, final, A_INT); /* intelligence */
  70.      one_characteristic(mode, final, A_WIS); /* wisdom */
  71.      one_characteristic(mode, final, A_CHA); /* charisma */
  72.  }
  73.  

one_characteristic

  1.  /* display one attribute value for characteristics_enlightenment() */
  2.  STATIC_OVL void
  3.  one_characteristic(mode, final, attrindx)
  4.  int mode, final, attrindx;
  5.  {
  6.      extern const char *const attrname[]; /* attrib.c */
  7.      boolean hide_innate_value = FALSE, interesting_alimit;
  8.      int acurrent, abase, apeak, alimit;
  9.      const char *paren_pfx;
  10.      char subjbuf[BUFSZ], valubuf[BUFSZ], valstring[32];
  11.  
  12.      /* being polymorphed or wearing certain cursed items prevents
  13.         hero from reliably tracking changes to characteristics so
  14.         we don't show base & peak values then; when the items aren't
  15.         cursed, hero could take them off to check underlying values
  16.         and we show those in such case so that player doesn't need
  17.         to actually resort to doing that */
  18.      if (Upolyd) {
  19.          hide_innate_value = TRUE;
  20.      } else if (Fixed_abil) {
  21.          if (stuck_ring(uleft, RIN_SUSTAIN_ABILITY)
  22.              || stuck_ring(uright, RIN_SUSTAIN_ABILITY))
  23.              hide_innate_value = TRUE;
  24.      }
  25.      switch (attrindx) {
  26.      case A_STR:
  27.          if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER && uarmg->cursed)
  28.              hide_innate_value = TRUE;
  29.          break;
  30.      case A_DEX:
  31.          break;
  32.      case A_CON:
  33.          if (uwep && uwep->oartifact == ART_OGRESMASHER && uwep->cursed)
  34.              hide_innate_value = TRUE;
  35.          break;
  36.      case A_INT:
  37.          if (uarmh && uarmh->otyp == DUNCE_CAP && uarmh->cursed)
  38.              hide_innate_value = TRUE;
  39.          break;
  40.      case A_WIS:
  41.          if (uarmh && uarmh->otyp == DUNCE_CAP && uarmh->cursed)
  42.              hide_innate_value = TRUE;
  43.          break;
  44.      case A_CHA:
  45.          break;
  46.      default:
  47.          return; /* impossible */
  48.      };
  49.      /* note: final disclosure includes MAGICENLIGHTENTMENT */
  50.      if ((mode & MAGICENLIGHTENMENT) && !Upolyd)
  51.          hide_innate_value = FALSE;
  52.  
  53.      acurrent = ACURR(attrindx);
  54.      (void) attrval(attrindx, acurrent, valubuf); /* Sprintf(valubuf,"%d",) */
  55.      Sprintf(subjbuf, "Your %s ", attrname[attrindx]);
  56.  
  57.      if (!hide_innate_value) {
  58.          /* show abase, amax, and/or attrmax if acurr doesn't match abase
  59.             (a magic bonus or penalty is in effect) or abase doesn't match
  60.             amax (some points have been lost to poison or exercise abuse
  61.             and are restorable) or attrmax is different from normal human
  62.             (while game is in progress; trying to reduce dependency on
  63.             spoilers to keep track of such stuff) or attrmax was different
  64.             from abase (at end of game; this attribute wasn't maxed out) */
  65.          abase = ABASE(attrindx);
  66.          apeak = AMAX(attrindx);
  67.          alimit = ATTRMAX(attrindx);
  68.          /* criterium for whether the limit is interesting varies */
  69.          interesting_alimit =
  70.              final ? TRUE /* was originally `(abase != alimit)' */
  71.                    : (alimit != (attrindx != A_STR ? 18 : STR18(100)));
  72.          paren_pfx = final ? " (" : " (current; ";
  73.          if (acurrent != abase) {
  74.              Sprintf(eos(valubuf), "%sbase:%s", paren_pfx,
  75.                      attrval(attrindx, abase, valstring));
  76.              paren_pfx = ", ";
  77.          }
  78.          if (abase != apeak) {
  79.              Sprintf(eos(valubuf), "%speak:%s", paren_pfx,
  80.                      attrval(attrindx, apeak, valstring));
  81.              paren_pfx = ", ";
  82.          }
  83.          if (interesting_alimit) {
  84.              Sprintf(eos(valubuf), "%s%slimit:%s", paren_pfx,
  85.                      /* more verbose if exceeding 'limit' due to magic bonus */
  86.                      (acurrent > alimit) ? "innate " : "",
  87.                      attrval(attrindx, alimit, valstring));
  88.              /* paren_pfx = ", "; */
  89.          }
  90.          if (acurrent != abase || abase != apeak || interesting_alimit)
  91.              Strcat(valubuf, ")");
  92.      }
  93.      enl_msg(subjbuf, "is ", "was ", valubuf, "");
  94.  }
  95.  

status_enlightenment

  1.  /* status: selected obvious capabilities, assorted troubles */
  2.  STATIC_OVL void
  3.  status_enlightenment(mode, final)
  4.  int mode;
  5.  int final;
  6.  {
  7.      boolean magic = (mode & MAGICENLIGHTENMENT) ? TRUE : FALSE;
  8.      int cap;
  9.      char buf[BUFSZ], youtoo[BUFSZ];
  10.      boolean Riding = (u.usteed
  11.                        /* if hero dies while dismounting, u.usteed will still
  12.                           be set; we want to ignore steed in that situation */
  13.                        && !(final == ENL_GAMEOVERDEAD
  14.                             && !strcmp(killer.name, "riding accident")));
  15.      const char *steedname = (!Riding ? (char *) 0
  16.                        : x_monnam(u.usteed,
  17.                                   u.usteed->mtame ? ARTICLE_YOUR : ARTICLE_THE,
  18.                                   (char *) 0,
  19.                                   (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION),
  20.                                   FALSE));
  21.  
  22.      /*\
  23.       * Status (many are abbreviated on bottom line; others are or
  24.       *     should be discernible to the hero hence to the player)
  25.      \*/
  26.      putstr(en_win, 0, ""); /* separator after title or characteristics */
  27.      putstr(en_win, 0, final ? "Final Status:" : "Current Status:");
  28.  
  29.      Strcpy(youtoo, You_);
  30.      /* not a traditional status but inherently obvious to player; more
  31.         detail given below (attributes section) for magic enlightenment */
  32.      if (Upolyd) {
  33.          Strcpy(buf, "transformed");
  34.          if (ugenocided())
  35.              Sprintf(eos(buf), " and %s %s inside",
  36.                      final ? "felt" : "feel", udeadinside());
  37.          you_are(buf, "");
  38.      }
  39.      /* not a trouble, but we want to display riding status before maybe
  40.         reporting steed as trapped or hero stuck to cursed saddle */
  41.      if (Riding) {
  42.          Sprintf(buf, "riding %s", steedname);
  43.          you_are(buf, "");
  44.          Sprintf(eos(youtoo), "and %s ", steedname);
  45.      }
  46.      /* other movement situations that hero should always know */
  47.      if (Levitation) {
  48.          if (Lev_at_will && magic)
  49.              you_are("levitating, at will", "");
  50.          else
  51.              enl_msg(youtoo, are, were, "levitating", from_what(LEVITATION));
  52.      } else if (Flying) { /* can only fly when not levitating */
  53.          enl_msg(youtoo, are, were, "flying", from_what(FLYING));
  54.      }
  55.      if (Underwater) {
  56.          you_are("underwater", "");
  57.      } else if (u.uinwater) {
  58.          you_are(Swimming ? "swimming" : "in water", from_what(SWIMMING));
  59.      } else if (walking_on_water()) {
  60.          /* show active Wwalking here, potential Wwalking elsewhere */
  61.          Sprintf(buf, "walking on %s",
  62.                  is_pool(u.ux, u.uy) ? "water"
  63.                  : is_lava(u.ux, u.uy) ? "lava"
  64.                    : surface(u.ux, u.uy)); /* catchall; shouldn't happen */
  65.          you_are(buf, from_what(WWALKING));
  66.      }
  67.      if (Upolyd && (u.uundetected || youmonst.m_ap_type != M_AP_NOTHING))
  68.          youhiding(TRUE, final);
  69.  
  70.      /* internal troubles, mostly in the order that prayer ranks them */
  71.      if (Stoned)
  72.          you_are("turning to stone", "");
  73.      if (Slimed)
  74.          you_are("turning into slime", "");
  75.      if (Strangled) {
  76.          if (u.uburied) {
  77.              you_are("buried", "");
  78.          } else {
  79.              Strcpy(buf, "being strangled");
  80.              if (wizard)
  81.                  Sprintf(eos(buf), " (%ld)", (Strangled & TIMEOUT));
  82.              you_are(buf, from_what(STRANGLED));
  83.          }
  84.      }
  85.      if (Sick) {
  86.          /* prayer lumps these together; botl puts Ill before FoodPois */
  87.          if (u.usick_type & SICK_NONVOMITABLE)
  88.              you_are("terminally sick from illness", "");
  89.          if (u.usick_type & SICK_VOMITABLE)
  90.              you_are("terminally sick from food poisoning", "");
  91.      }
  92.      if (Vomiting)
  93.          you_are("nauseated", "");
  94.      if (Stunned)
  95.          you_are("stunned", "");
  96.      if (Confusion)
  97.          you_are("confused", "");
  98.      if (Hallucination)
  99.          you_are("hallucinating", "");
  100.      if (Blind) {
  101.          /* from_what() (currently wizard-mode only) checks !haseyes()
  102.             before u.uroleplay.blind, so we should too */
  103.          Sprintf(buf, "%s blind",
  104.                  !haseyes(youmonst.data) ? "innately"
  105.                  : u.uroleplay.blind ? "permanently"
  106.                    /* better phrasing desperately wanted... */
  107.                    : Blindfolded_only ? "deliberately"
  108.                      : "temporarily");
  109.          if (wizard && (Blinded & TIMEOUT) != 0L
  110.              && !u.uroleplay.blind && haseyes(youmonst.data))
  111.              Sprintf(eos(buf), " (%ld)", (Blinded & TIMEOUT));
  112.          /* !haseyes: avoid "you are innately blind innately" */
  113.          you_are(buf, !haseyes(youmonst.data) ? "" : from_what(BLINDED));
  114.      }
  115.      if (Deaf)
  116.          you_are("deaf", from_what(DEAF));
  117.  
  118.      /* external troubles, more or less */
  119.      if (Punished) {
  120.          if (uball) {
  121.              Sprintf(buf, "chained to %s", ansimpleoname(uball));
  122.          } else {
  123.              impossible("Punished without uball?");
  124.              Strcpy(buf, "punished");
  125.          }
  126.          you_are(buf, "");
  127.      }
  128.      if (u.utrap) {
  129.          char predicament[BUFSZ];
  130.          struct trap *t;
  131.          boolean anchored = (u.utraptype == TT_BURIEDBALL);
  132.  
  133.          if (anchored) {
  134.              Strcpy(predicament, "tethered to something buried");
  135.          } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) {
  136.              Sprintf(predicament, "stuck in %s", the(surface(u.ux, u.uy)));
  137.          } else {
  138.              Strcpy(predicament, "trapped");
  139.              if ((t = t_at(u.ux, u.uy)) != 0)
  140.                  Sprintf(eos(predicament), " in %s",
  141.                          an(defsyms[trap_to_defsym(t->ttyp)].explanation));
  142.          }
  143.          if (u.usteed) { /* not `Riding' here */
  144.              Sprintf(buf, "%s%s ", anchored ? "you and " : "", steedname);
  145.              *buf = highc(*buf);
  146.              enl_msg(buf, (anchored ? "are " : "is "),
  147.                      (anchored ? "were " : "was "), predicament, "");
  148.          } else
  149.              you_are(predicament, "");
  150.      } /* (u.utrap) */
  151.      if (u.uswallow) {
  152.          Sprintf(buf, "swallowed by %s", a_monnam(u.ustuck));
  153.          if (wizard)
  154.              Sprintf(eos(buf), " (%u)", u.uswldtim);
  155.          you_are(buf, "");
  156.      } else if (u.ustuck) {
  157.          Sprintf(buf, "%s %s",
  158.                  (Upolyd && sticks(youmonst.data)) ? "holding" : "held by",
  159.                  a_monnam(u.ustuck));
  160.          you_are(buf, "");
  161.      }
  162.      if (Riding) {
  163.          struct obj *saddle = which_armor(u.usteed, W_SADDLE);
  164.  
  165.          if (saddle && saddle->cursed) {
  166.              Sprintf(buf, "stuck to %s %s", s_suffix(steedname),
  167.                      simpleonames(saddle));
  168.              you_are(buf, "");
  169.          }
  170.      }
  171.      if (Wounded_legs) {
  172.          /* when mounted, Wounded_legs applies to steed rather than to
  173.             hero; we only report steed's wounded legs in wizard mode */
  174.          if (u.usteed) { /* not `Riding' here */
  175.              if (wizard && steedname) {
  176.                  Strcpy(buf, steedname);
  177.                  *buf = highc(*buf);
  178.                  enl_msg(buf, " has", " had", " wounded legs", "");
  179.              }
  180.          } else {
  181.              Sprintf(buf, "wounded %s", makeplural(body_part(LEG)));
  182.              you_have(buf, "");
  183.          }
  184.      }
  185.      if (Glib) {
  186.          Sprintf(buf, "slippery %s", makeplural(body_part(FINGER)));
  187.          you_have(buf, "");
  188.      }
  189.      if (Fumbling) {
  190.          if (magic || cause_known(FUMBLING))
  191.              enl_msg(You_, "fumble", "fumbled", "", from_what(FUMBLING));
  192.      }
  193.      if (Sleepy) {
  194.          if (magic || cause_known(SLEEPY)) {
  195.              Strcpy(buf, from_what(SLEEPY));
  196.              if (wizard)
  197.                  Sprintf(eos(buf), " (%ld)", (HSleepy & TIMEOUT));
  198.              enl_msg("You ", "fall", "fell", " asleep uncontrollably", buf);
  199.          }
  200.      }
  201.      /* hunger/nutrition */
  202.      if (Hunger) {
  203.          if (magic || cause_known(HUNGER))
  204.              enl_msg(You_, "hunger", "hungered", " rapidly",
  205.                      from_what(HUNGER));
  206.      }
  207.      Strcpy(buf, hu_stat[u.uhs]); /* hunger status; omitted if "normal" */
  208.      mungspaces(buf);             /* strip trailing spaces */
  209.      if (*buf) {
  210.          *buf = lowc(*buf); /* override capitalization */
  211.          if (!strcmp(buf, "weak"))
  212.              Strcat(buf, " from severe hunger");
  213.          else if (!strncmp(buf, "faint", 5)) /* fainting, fainted */
  214.              Strcat(buf, " due to starvation");
  215.          you_are(buf, "");
  216.      }
  217.      /* encumbrance */
  218.      if ((cap = near_capacity()) > UNENCUMBERED) {
  219.          const char *adj = "?_?"; /* (should always get overridden) */
  220.  
  221.          Strcpy(buf, enc_stat[cap]);
  222.          *buf = lowc(*buf);
  223.          switch (cap) {
  224.          case SLT_ENCUMBER:
  225.              adj = "slightly";
  226.              break; /* burdened */
  227.          case MOD_ENCUMBER:
  228.              adj = "moderately";
  229.              break; /* stressed */
  230.          case HVY_ENCUMBER:
  231.              adj = "very";
  232.              break; /* strained */
  233.          case EXT_ENCUMBER:
  234.              adj = "extremely";
  235.              break; /* overtaxed */
  236.          case OVERLOADED:
  237.              adj = "not possible";
  238.              break;
  239.          }
  240.          Sprintf(eos(buf), "; movement %s %s%s", !final ? "is" : "was", adj,
  241.                  (cap < OVERLOADED) ? " slowed" : "");
  242.          you_are(buf, "");
  243.      } else {
  244.          /* last resort entry, guarantees Status section is non-empty
  245.             (no longer needed for that purpose since weapon status added;
  246.             still useful though) */
  247.          you_are("unencumbered", "");
  248.      }
  249.      /* report being weaponless; distinguish whether gloves are worn */
  250.      if (!uwep) {
  251.          you_are(uarmg ? "empty handed" /* gloves imply hands */
  252.                        : humanoid(youmonst.data)
  253.                           /* hands but no weapon and no gloves */
  254.                           ? "bare handed"
  255.                           /* alternate phrasing for paws or lack of hands */
  256.                           : "not wielding anything",
  257.                  "");
  258.      /* two-weaponing implies a weapon (not other odd stuff) in each hand */
  259.      } else if (u.twoweap) {
  260.          you_are("wielding two weapons at once", "");
  261.      /* report most weapons by their skill class (so a katana will be
  262.         described as a long sword, for instance; mattock and hook are
  263.         exceptions), or wielded non-weapon item by its object class */
  264.      } else {
  265.          const char *what = weapon_descr(uwep);
  266.  
  267.          if (!strcmpi(what, "armor") || !strcmpi(what, "food")
  268.              || !strcmpi(what, "venom"))
  269.              Sprintf(buf, "wielding some %s", what);
  270.          else
  271.              Sprintf(buf, "wielding %s",
  272.                      (uwep->quan == 1L) ? an(what) : makeplural(what));
  273.          you_are(buf, "");
  274.      }
  275.      /* report 'nudity' */
  276.      if (!uarm && !uarmu && !uarmc && !uarmg && !uarmf && !uarmh) {
  277.          if (u.uroleplay.nudist)
  278.              enl_msg(You_, "do", "did", " not wear any armor", "");
  279.          else
  280.              you_are("not wearing any armor", "");
  281.      }
  282.  }
  283.  

attributes_enlightenment

  1.  /* attributes: intrinsics and the like, other non-obvious capabilities */
  2.  void
  3.  attributes_enlightenment(unused_mode, final)
  4.  int unused_mode UNUSED;
  5.  int final;
  6.  {
  7.      static NEARDATA const char if_surroundings_permitted[] =
  8.          " if surroundings permitted";
  9.      int ltmp, armpro;
  10.      char buf[BUFSZ];
  11.  
  12.      /*\
  13.       *  Attributes
  14.      \*/
  15.      putstr(en_win, 0, "");
  16.      putstr(en_win, 0, final ? "Final Attributes:" : "Current Attributes:");
  17.  
  18.      if (u.uevent.uhand_of_elbereth) {
  19.          static const char *const hofe_titles[3] = { "the Hand of Elbereth",
  20.                                                      "the Envoy of Balance",
  21.                                                      "the Glory of Arioch" };
  22.          you_are(hofe_titles[u.uevent.uhand_of_elbereth - 1], "");
  23.      }
  24.  
  25.      Sprintf(buf, "%s", piousness(TRUE, "aligned"));
  26.      if (u.ualign.record >= 0)
  27.          you_are(buf, "");
  28.      else
  29.          you_have(buf, "");
  30.  
  31.      if (wizard) {
  32.          Sprintf(buf, " %d", u.ualign.record);
  33.          enl_msg("Your alignment ", "is", "was", buf, "");
  34.      }
  35.  
  36.      /*** Resistances to troubles ***/
  37.      if (Invulnerable)
  38.          you_are("invulnerable", from_what(INVULNERABLE));
  39.      if (Antimagic)
  40.          you_are("magic-protected", from_what(ANTIMAGIC));
  41.      if (Fire_resistance)
  42.          you_are("fire resistant", from_what(FIRE_RES));
  43.      if (Cold_resistance)
  44.          you_are("cold resistant", from_what(COLD_RES));
  45.      if (Sleep_resistance)
  46.          you_are("sleep resistant", from_what(SLEEP_RES));
  47.      if (Disint_resistance)
  48.          you_are("disintegration-resistant", from_what(DISINT_RES));
  49.      if (Shock_resistance)
  50.          you_are("shock resistant", from_what(SHOCK_RES));
  51.      if (Poison_resistance)
  52.          you_are("poison resistant", from_what(POISON_RES));
  53.      if (Acid_resistance)
  54.          you_are("acid resistant", from_what(ACID_RES));
  55.      if (Drain_resistance)
  56.          you_are("level-drain resistant", from_what(DRAIN_RES));
  57.      if (Sick_resistance)
  58.          you_are("immune to sickness", from_what(SICK_RES));
  59.      if (Stone_resistance)
  60.          you_are("petrification resistant", from_what(STONE_RES));
  61.      if (Halluc_resistance)
  62.          enl_msg(You_, "resist", "resisted", " hallucinations",
  63.                  from_what(HALLUC_RES));
  64.      if (u.uedibility)
  65.          you_can("recognize detrimental food", "");
  66.  
  67.      /*** Vision and senses ***/
  68.      if (!Blind && (Blinded || !haseyes(youmonst.data)))
  69.          you_can("see", from_what(-BLINDED)); /* Eyes of the Overworld */
  70.      if (See_invisible) {
  71.          if (!Blind)
  72.              enl_msg(You_, "see", "saw", " invisible", from_what(SEE_INVIS));
  73.          else
  74.              enl_msg(You_, "will see", "would have seen",
  75.                      " invisible when not blind", from_what(SEE_INVIS));
  76.      }
  77.      if (Blind_telepat)
  78.          you_are("telepathic", from_what(TELEPAT));
  79.      if (Warning)
  80.          you_are("warned", from_what(WARNING));
  81.      if (Warn_of_mon && context.warntype.obj) {
  82.          Sprintf(buf, "aware of the presence of %s",
  83.                  (context.warntype.obj & M2_ORC) ? "orcs"
  84.                  : (context.warntype.obj & M2_ELF) ? "elves"
  85.                  : (context.warntype.obj & M2_DEMON) ? "demons" : something);
  86.          you_are(buf, from_what(WARN_OF_MON));
  87.      }
  88.      if (Warn_of_mon && context.warntype.polyd) {
  89.          Sprintf(buf, "aware of the presence of %s",
  90.                  ((context.warntype.polyd & (M2_HUMAN | M2_ELF))
  91.                   == (M2_HUMAN | M2_ELF))
  92.                      ? "humans and elves"
  93.                      : (context.warntype.polyd & M2_HUMAN)
  94.                            ? "humans"
  95.                            : (context.warntype.polyd & M2_ELF)
  96.                                  ? "elves"
  97.                                  : (context.warntype.polyd & M2_ORC)
  98.                                        ? "orcs"
  99.                                        : (context.warntype.polyd & M2_DEMON)
  100.                                              ? "demons"
  101.                                              : "certain monsters");
  102.          you_are(buf, "");
  103.      }
  104.      if (Warn_of_mon && context.warntype.speciesidx >= LOW_PM) {
  105.          Sprintf(buf, "aware of the presence of %s",
  106.                  makeplural(mons[context.warntype.speciesidx].mname));
  107.          you_are(buf, from_what(WARN_OF_MON));
  108.      }
  109.      if (Undead_warning)
  110.          you_are("warned of undead", from_what(WARN_UNDEAD));
  111.      if (Searching)
  112.          you_have("automatic searching", from_what(SEARCHING));
  113.      if (Clairvoyant)
  114.          you_are("clairvoyant", from_what(CLAIRVOYANT));
  115.      else if ((HClairvoyant || EClairvoyant) && BClairvoyant) {
  116.          Strcpy(buf, from_what(-CLAIRVOYANT));
  117.          if (!strncmp(buf, " because of ", 12))
  118.              /* overwrite substring; strncpy doesn't add terminator */
  119.              (void) strncpy(buf, " if not for ", 12);
  120.          enl_msg(You_, "could be", "could have been", " clairvoyant", buf);
  121.      }
  122.      if (Infravision)
  123.          you_have("infravision", from_what(INFRAVISION));
  124.      if (Detect_monsters)
  125.          you_are("sensing the presence of monsters", "");
  126.      if (u.umconf)
  127.          you_are("going to confuse monsters", "");
  128.  
  129.      /*** Appearance and behavior ***/
  130.      if (Adornment) {
  131.          int adorn = 0;
  132.  
  133.          if (uleft && uleft->otyp == RIN_ADORNMENT)
  134.              adorn += uleft->spe;
  135.          if (uright && uright->otyp == RIN_ADORNMENT)
  136.              adorn += uright->spe;
  137.          /* the sum might be 0 (+0 ring or two which negate each other);
  138.             that yields "you are charismatic" (which isn't pointless
  139.             because it potentially impacts seduction attacks) */
  140.          Sprintf(buf, "%scharismatic",
  141.                  (adorn > 0) ? "more " : (adorn < 0) ? "less " : "");
  142.          you_are(buf, from_what(ADORNED));
  143.      }
  144.      if (Invisible)
  145.          you_are("invisible", from_what(INVIS));
  146.      else if (Invis)
  147.          you_are("invisible to others", from_what(INVIS));
  148.      /* ordinarily "visible" is redundant; this is a special case for
  149.         the situation when invisibility would be an expected attribute */
  150.      else if ((HInvis || EInvis) && BInvis)
  151.          you_are("visible", from_what(-INVIS));
  152.      if (Displaced)
  153.          you_are("displaced", from_what(DISPLACED));
  154.      if (Stealth)
  155.          you_are("stealthy", from_what(STEALTH));
  156.      if (Aggravate_monster)
  157.          enl_msg("You aggravate", "", "d", " monsters",
  158.                  from_what(AGGRAVATE_MONSTER));
  159.      if (Conflict)
  160.          enl_msg("You cause", "", "d", " conflict", from_what(CONFLICT));
  161.  
  162.      /*** Transportation ***/
  163.      if (Jumping)
  164.          you_can("jump", from_what(JUMPING));
  165.      if (Teleportation)
  166.          you_can("teleport", from_what(TELEPORT));
  167.      if (Teleport_control)
  168.          you_have("teleport control", from_what(TELEPORT_CONTROL));
  169.      /* actively levitating handled earlier as a status condition */
  170.      if (BLevitation) { /* levitation is blocked */
  171.          long save_BLev = BLevitation;
  172.  
  173.          BLevitation = 0L;
  174.          if (Levitation)
  175.              enl_msg(You_, "would levitate", "would have levitated",
  176.                      if_surroundings_permitted, "");
  177.          BLevitation = save_BLev;
  178.      }
  179.      /* actively flying handled earlier as a status condition */
  180.      if (BFlying) { /* flight is blocked */
  181.          long save_BFly = BFlying;
  182.  
  183.          BFlying = 0L;
  184.          if (Flying)
  185.              enl_msg(You_, "would fly", "would have flown",
  186.                      Levitation
  187.                         ? "if you weren't levitating"
  188.                         : (save_BFly == FROMOUTSIDE)
  189.                            ? if_surroundings_permitted
  190.                            /* both surroundings and [latent] levitation */
  191.                            : " if circumstances permitted",
  192.                      "");
  193.          BFlying = save_BFly;
  194.      }
  195.      /* actively walking on water handled earlier as a status condition */
  196.      if (Wwalking && !walking_on_water())
  197.          you_can("walk on water", from_what(WWALKING));
  198.      /* actively swimming (in water but not under it) handled earlier */
  199.      if (Swimming && (Underwater || !u.uinwater))
  200.          you_can("swim", from_what(SWIMMING));
  201.      if (Breathless)
  202.          you_can("survive without air", from_what(MAGICAL_BREATHING));
  203.      else if (Amphibious)
  204.          you_can("breathe water", from_what(MAGICAL_BREATHING));
  205.      if (Passes_walls)
  206.          you_can("walk through walls", from_what(PASSES_WALLS));
  207.  
  208.      /*** Physical attributes ***/
  209.      if (Regeneration)
  210.          enl_msg("You regenerate", "", "d", "", from_what(REGENERATION));
  211.      if (Slow_digestion)
  212.          you_have("slower digestion", from_what(SLOW_DIGESTION));
  213.      if (u.uhitinc)
  214.          you_have(enlght_combatinc("to hit", u.uhitinc, final, buf), "");
  215.      if (u.udaminc)
  216.          you_have(enlght_combatinc("damage", u.udaminc, final, buf), "");
  217.      if (u.uspellprot || Protection) {
  218.          int prot = 0;
  219.  
  220.          if (uleft && uleft->otyp == RIN_PROTECTION)
  221.              prot += uleft->spe;
  222.          if (uright && uright->otyp == RIN_PROTECTION)
  223.              prot += uright->spe;
  224.          if (HProtection & INTRINSIC)
  225.              prot += u.ublessed;
  226.          prot += u.uspellprot;
  227.          if (prot)
  228.              you_have(enlght_combatinc("defense", prot, final, buf), "");
  229.      }
  230.      if ((armpro = magic_negation(&youmonst)) > 0) {
  231.          /* magic cancellation factor, conferred by worn armor */
  232.          static const char *const mc_types[] = {
  233.              "" /*ordinary*/, "warded", "guarded", "protected",
  234.          };
  235.          /* sanity check */
  236.          if (armpro >= SIZE(mc_types))
  237.              armpro = SIZE(mc_types) - 1;
  238.          you_are(mc_types[armpro], "");
  239.      }
  240.      if (Half_physical_damage)
  241.          enlght_halfdmg(HALF_PHDAM, final);
  242.      if (Half_spell_damage)
  243.          enlght_halfdmg(HALF_SPDAM, final);
  244.      /* polymorph and other shape change */
  245.      if (Protection_from_shape_changers)
  246.          you_are("protected from shape changers",
  247.                  from_what(PROT_FROM_SHAPE_CHANGERS));
  248.      if (Unchanging) {
  249.          const char *what = 0;
  250.  
  251.          if (!Upolyd) /* Upolyd handled below after current form */
  252.              you_can("not change from your current form",
  253.                      from_what(UNCHANGING));
  254.          /* blocked shape changes */
  255.          if (Polymorph)
  256.              what = !final ? "polymorph" : "have polymorphed";
  257.          else if (u.ulycn >= LOW_PM)
  258.              what = !final ? "change shape" : "have changed shape";
  259.          if (what) {
  260.              Sprintf(buf, "would %s periodically", what);
  261.              /* omit from_what(UNCHANGING); too verbose */
  262.              enl_msg(You_, buf, buf, " if not locked into your current form",
  263.                      "");
  264.          }
  265.      } else if (Polymorph) {
  266.          you_are("polymorphing periodically", from_what(POLYMORPH));
  267.      }
  268.      if (Polymorph_control)
  269.          you_have("polymorph control", from_what(POLYMORPH_CONTROL));
  270.      if (Upolyd && u.umonnum != u.ulycn) {
  271.          /* foreign shape (except were-form which is handled below) */
  272.          Sprintf(buf, "polymorphed into %s", an(youmonst.data->mname));
  273.          if (wizard)
  274.              Sprintf(eos(buf), " (%d)", u.mtimedone);
  275.          you_are(buf, "");
  276.      }
  277.      if (lays_eggs(youmonst.data) && flags.female) /* Upolyd */
  278.          you_can("lay eggs", "");
  279.      if (u.ulycn >= LOW_PM) {
  280.          /* "you are a werecreature [in beast form]" */
  281.          Strcpy(buf, an(mons[u.ulycn].mname));
  282.          if (u.umonnum == u.ulycn) {
  283.              Strcat(buf, " in beast form");
  284.              if (wizard)
  285.                  Sprintf(eos(buf), " (%d)", u.mtimedone);
  286.          }
  287.          you_are(buf, "");
  288.      }
  289.      if (Unchanging && Upolyd) /* !Upolyd handled above */
  290.          you_can("not change from your current form", from_what(UNCHANGING));
  291.      if (Hate_silver)
  292.          you_are("harmed by silver", "");
  293.      /* movement and non-armor-based protection */
  294.      if (Fast)
  295.          you_are(Very_fast ? "very fast" : "fast", from_what(FAST));
  296.      if (Reflecting)
  297.          you_have("reflection", from_what(REFLECTING));
  298.      if (Free_action)
  299.          you_have("free action", from_what(FREE_ACTION));
  300.      if (Fixed_abil)
  301.          you_have("fixed abilities", from_what(FIXED_ABIL));
  302.      if (Lifesaved)
  303.          enl_msg("Your life ", "will be", "would have been", " saved", "");
  304.  
  305.      /*** Miscellany ***/
  306.      if (Luck) {
  307.          ltmp = abs((int) Luck);
  308.          Sprintf(buf, "%s%slucky",
  309.                  ltmp >= 10 ? "extremely " : ltmp >= 5 ? "very " : "",
  310.                  Luck < 0 ? "un" : "");
  311.          if (wizard)
  312.              Sprintf(eos(buf), " (%d)", Luck);
  313.          you_are(buf, "");
  314.      } else if (wizard)
  315.          enl_msg("Your luck ", "is", "was", " zero", "");
  316.      if (u.moreluck > 0)
  317.          you_have("extra luck", "");
  318.      else if (u.moreluck < 0)
  319.          you_have("reduced luck", "");
  320.      if (carrying(LUCKSTONE) || stone_luck(TRUE)) {
  321.          ltmp = stone_luck(0);
  322.          if (ltmp <= 0)
  323.              enl_msg("Bad luck ", "does", "did", " not time out for you", "");
  324.          if (ltmp >= 0)
  325.              enl_msg("Good luck ", "does", "did", " not time out for you", "");
  326.      }
  327.  
  328.      if (u.ugangr) {
  329.          Sprintf(buf, " %sangry with you",
  330.                  u.ugangr > 6 ? "extremely " : u.ugangr > 3 ? "very " : "");
  331.          if (wizard)
  332.              Sprintf(eos(buf), " (%d)", u.ugangr);
  333.          enl_msg(u_gname(), " is", " was", buf, "");
  334.      } else {
  335.          /*
  336.           * We need to suppress this when the game is over, because death
  337.           * can change the value calculated by can_pray(), potentially
  338.           * resulting in a false claim that you could have prayed safely.
  339.           */
  340.          if (!final) {
  341.  #if 0
  342.              /* "can [not] safely pray" vs "could [not] have safely prayed" */
  343.              Sprintf(buf, "%s%ssafely pray%s", can_pray(FALSE) ? "" : "not ",
  344.                      final ? "have " : "", final ? "ed" : "");
  345.  #else
  346.              Sprintf(buf, "%ssafely pray", can_pray(FALSE) ? "" : "not ");
  347.  #endif
  348.              if (wizard)
  349.                  Sprintf(eos(buf), " (%d)", u.ublesscnt);
  350.              you_can(buf, "");
  351.          }
  352.      }
  353.  
  354.  #ifdef DEBUG
  355.      /* named fruit debugging (doesn't really belong here...); to enable,
  356.         include 'fruit' in DEBUGFILES list (even though it isn't a file...) */
  357.      if (wizard && explicitdebug("fruit")) {
  358.          struct fruit *f;
  359.  
  360.          reorder_fruit(TRUE); /* sort by fruit index, from low to high;
  361.                                * this modifies the ffruit chain, so could
  362.                                * possibly mask or even introduce a problem,
  363.                                * but it does useful sanity checking */
  364.          for (f = ffruit; f; f = f->nextf) {
  365.              Sprintf(buf, "Fruit #%d ", f->fid);
  366.              enl_msg(buf, "is ", "was ", f->fname, "");
  367.          }
  368.          enl_msg("The current fruit ", "is ", "was ", pl_fruit, "");
  369.          Sprintf(buf, "%d", flags.made_fruit);
  370.          enl_msg("The made fruit flag ", "is ", "was ", buf, "");
  371.      }
  372.  #endif
  373.  
  374.      {
  375.          const char *p;
  376.  
  377.          buf[0] = '\0';
  378.          if (final < 2) { /* still in progress, or quit/escaped/ascended */
  379.              p = "survived after being killed ";
  380.              switch (u.umortality) {
  381.              case 0:
  382.                  p = !final ? (char *) 0 : "survived";
  383.                  break;
  384.              case 1:
  385.                  Strcpy(buf, "once");
  386.                  break;
  387.              case 2:
  388.                  Strcpy(buf, "twice");
  389.                  break;
  390.              case 3:
  391.                  Strcpy(buf, "thrice");
  392.                  break;
  393.              default:
  394.                  Sprintf(buf, "%d times", u.umortality);
  395.                  break;
  396.              }
  397.          } else { /* game ended in character's death */
  398.              p = "are dead";
  399.              switch (u.umortality) {
  400.              case 0:
  401.                  impossible("dead without dying?");
  402.              case 1:
  403.                  break; /* just "are dead" */
  404.              default:
  405.                  Sprintf(buf, " (%d%s time!)", u.umortality,
  406.                          ordin(u.umortality));
  407.                  break;
  408.              }
  409.          }
  410.          if (p)
  411.              enl_msg(You_, "have been killed ", p, buf, "");
  412.      }
  413.  }
  414.  

minimal_enlightenment

  1.  #if 0  /* no longer used */
  2.  STATIC_DCL boolean NDECL(minimal_enlightenment);
  3.  
  4.  /*
  5.   * Courtesy function for non-debug, non-explorer mode players
  6.   * to help refresh them about who/what they are.
  7.   * Returns FALSE if menu cancelled (dismissed with ESC), TRUE otherwise.
  8.   */
  9.  STATIC_OVL boolean
  10.  minimal_enlightenment()
  11.  {
  12.      winid tmpwin;
  13.      menu_item *selected;
  14.      anything any;
  15.      int genidx, n;
  16.      char buf[BUFSZ], buf2[BUFSZ];
  17.      static const char untabbed_fmtstr[] = "%-15s: %-12s";
  18.      static const char untabbed_deity_fmtstr[] = "%-17s%s";
  19.      static const char tabbed_fmtstr[] = "%s:\t%-12s";
  20.      static const char tabbed_deity_fmtstr[] = "%s\t%s";
  21.      static const char *fmtstr;
  22.      static const char *deity_fmtstr;
  23.  
  24.      fmtstr = iflags.menu_tab_sep ? tabbed_fmtstr : untabbed_fmtstr;
  25.      deity_fmtstr = iflags.menu_tab_sep ? tabbed_deity_fmtstr
  26.                                         : untabbed_deity_fmtstr;
  27.      any = zeroany;
  28.      buf[0] = buf2[0] = '\0';
  29.      tmpwin = create_nhwindow(NHW_MENU);
  30.      start_menu(tmpwin);
  31.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
  32.               "Starting", FALSE);
  33.  
  34.      /* Starting name, race, role, gender */
  35.      Sprintf(buf, fmtstr, "name", plname);
  36.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  37.      Sprintf(buf, fmtstr, "race", urace.noun);
  38.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  39.      Sprintf(buf, fmtstr, "role",
  40.              (flags.initgend && urole.name.f) ? urole.name.f : urole.name.m);
  41.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  42.      Sprintf(buf, fmtstr, "gender", genders[flags.initgend].adj);
  43.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  44.  
  45.      /* Starting alignment */
  46.      Sprintf(buf, fmtstr, "alignment", align_str(u.ualignbase[A_ORIGINAL]));
  47.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  48.  
  49.      /* Current name, race, role, gender */
  50.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", FALSE);
  51.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
  52.               "Current", FALSE);
  53.      Sprintf(buf, fmtstr, "race", Upolyd ? youmonst.data->mname : urace.noun);
  54.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  55.      if (Upolyd) {
  56.          Sprintf(buf, fmtstr, "role (base)",
  57.                  (u.mfemale && urole.name.f) ? urole.name.f
  58.                                              : urole.name.m);
  59.          add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  60.      } else {
  61.          Sprintf(buf, fmtstr, "role",
  62.                  (flags.female && urole.name.f) ? urole.name.f
  63.                                                 : urole.name.m);
  64.          add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  65.      }
  66.      /* don't want poly_gender() here; it forces `2' for non-humanoids */
  67.      genidx = is_neuter(youmonst.data) ? 2 : flags.female;
  68.      Sprintf(buf, fmtstr, "gender", genders[genidx].adj);
  69.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  70.      if (Upolyd && (int) u.mfemale != genidx) {
  71.          Sprintf(buf, fmtstr, "gender (base)", genders[u.mfemale].adj);
  72.          add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  73.      }
  74.  
  75.      /* Current alignment */
  76.      Sprintf(buf, fmtstr, "alignment", align_str(u.ualign.type));
  77.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  78.  
  79.      /* Deity list */
  80.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", FALSE);
  81.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
  82.               "Deities", FALSE);
  83.      Sprintf(buf2, deity_fmtstr, align_gname(A_CHAOTIC),
  84.              (u.ualignbase[A_ORIGINAL] == u.ualign.type
  85.               && u.ualign.type == A_CHAOTIC)               ? " (s,c)"
  86.                  : (u.ualignbase[A_ORIGINAL] == A_CHAOTIC) ? " (s)"
  87.                  : (u.ualign.type   == A_CHAOTIC)          ? " (c)" : "");
  88.      Sprintf(buf, fmtstr, "Chaotic", buf2);
  89.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  90.  
  91.      Sprintf(buf2, deity_fmtstr, align_gname(A_NEUTRAL),
  92.              (u.ualignbase[A_ORIGINAL] == u.ualign.type
  93.               && u.ualign.type == A_NEUTRAL)               ? " (s,c)"
  94.                  : (u.ualignbase[A_ORIGINAL] == A_NEUTRAL) ? " (s)"
  95.                  : (u.ualign.type   == A_NEUTRAL)          ? " (c)" : "");
  96.      Sprintf(buf, fmtstr, "Neutral", buf2);
  97.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  98.  
  99.      Sprintf(buf2, deity_fmtstr, align_gname(A_LAWFUL),
  100.              (u.ualignbase[A_ORIGINAL] == u.ualign.type
  101.               && u.ualign.type == A_LAWFUL)                ? " (s,c)"
  102.                  : (u.ualignbase[A_ORIGINAL] == A_LAWFUL)  ? " (s)"
  103.                  : (u.ualign.type   == A_LAWFUL)           ? " (c)" : "");
  104.      Sprintf(buf, fmtstr, "Lawful", buf2);
  105.      add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE);
  106.  
  107.      end_menu(tmpwin, "Base Attributes");
  108.      n = select_menu(tmpwin, PICK_NONE, &selected);
  109.      destroy_nhwindow(tmpwin);
  110.      return (boolean) (n != -1);
  111.  }
  112.  #endif /*0*/
  113.  

doattributes

  1.  /* ^X command */
  2.  STATIC_PTR int
  3.  doattributes(VOID_ARGS)
  4.  {
  5.      int mode = BASICENLIGHTENMENT;
  6.  
  7.      /* show more--as if final disclosure--for wizard and explore modes */
  8.      if (wizard || discover)
  9.          mode |= MAGICENLIGHTENMENT;
  10.  
  11.      enlightenment(mode, ENL_GAMEINPROGRESS);
  12.      return 0;
  13.  }
  14.  

youhiding

  1.  void
  2.  youhiding(via_enlghtmt, msgflag)
  3.  boolean via_enlghtmt; /* englightment line vs topl message */
  4.  int msgflag;          /* for variant message phrasing */
  5.  {
  6.      char *bp, buf[BUFSZ];
  7.  
  8.      Strcpy(buf, "hiding");
  9.      if (youmonst.m_ap_type != M_AP_NOTHING) {
  10.          /* mimic; hero is only able to mimic a strange object or gold
  11.             or hallucinatory alternative to gold, so we skip the details
  12.             for the hypothetical furniture and monster cases */
  13.          bp = eos(strcpy(buf, "mimicking"));
  14.          if (youmonst.m_ap_type == M_AP_OBJECT) {
  15.              Sprintf(bp, " %s", an(simple_typename(youmonst.mappearance)));
  16.          } else if (youmonst.m_ap_type == M_AP_FURNITURE) {
  17.              Strcpy(bp, " something");
  18.          } else if (youmonst.m_ap_type == M_AP_MONSTER) {
  19.              Strcpy(bp, " someone");
  20.          } else {
  21.              ; /* something unexpected; leave 'buf' as-is */
  22.          }
  23.      } else if (u.uundetected) {
  24.          bp = eos(buf); /* points past "hiding" */
  25.          if (youmonst.data->mlet == S_EEL) {
  26.              if (is_pool(u.ux, u.uy))
  27.                  Sprintf(bp, " in the %s", waterbody_name(u.ux, u.uy));
  28.          } else if (hides_under(youmonst.data)) {
  29.              struct obj *o = level.objects[u.ux][u.uy];
  30.  
  31.              if (o)
  32.                  Sprintf(bp, " underneath %s", ansimpleoname(o));
  33.          } else if (is_clinger(youmonst.data) || Flying) {
  34.              /* Flying: 'lurker above' hides on ceiling but doesn't cling */
  35.              Sprintf(bp, " on the %s", ceiling(u.ux, u.uy));
  36.          } else {
  37.              /* on floor; is_hider() but otherwise not special: 'trapper' */
  38.              if (u.utrap && u.utraptype == TT_PIT) {
  39.                  struct trap *t = t_at(u.ux, u.uy);
  40.  
  41.                  Sprintf(bp, " in a %spit",
  42.                          (t && t->ttyp == SPIKED_PIT) ? "spiked " : "");
  43.              } else
  44.                  Sprintf(bp, " on the %s", surface(u.ux, u.uy));
  45.          }
  46.      } else {
  47.          ; /* shouldn't happen; will result in generic "you are hiding" */
  48.      }
  49.  
  50.      if (via_enlghtmt) {
  51.          int final = msgflag; /* 'final' is used by you_are() macro */
  52.  
  53.          you_are(buf, "");
  54.      } else {
  55.          /* for dohide(), when player uses '#monster' command */
  56.          You("are %s %s.", msgflag ? "already" : "now", buf);
  57.      }
  58.  }
  59.  

doconduct

  1.  /* KMH, #conduct
  2.   * (shares enlightenment's tense handling)
  3.   */
  4.  int
  5.  doconduct(VOID_ARGS)
  6.  {
  7.      show_conduct(0);
  8.      return 0;
  9.  }
  10.  

show_conduct

  1.  void
  2.  show_conduct(final)
  3.  int final;
  4.  {
  5.      char buf[BUFSZ];
  6.      int ngenocided;
  7.  
  8.      /* Create the conduct window */
  9.      en_win = create_nhwindow(NHW_MENU);
  10.      putstr(en_win, 0, "Voluntary challenges:");
  11.  
  12.      if (u.uroleplay.blind)
  13.          you_have_been("blind from birth");
  14.      if (u.uroleplay.nudist)
  15.          you_have_been("faithfully nudist");
  16.  
  17.      if (!u.uconduct.food)
  18.          enl_msg(You_, "have gone", "went", " without food", "");
  19.          /* but beverages are okay */
  20.      else if (!u.uconduct.unvegan)
  21.          you_have_X("followed a strict vegan diet");
  22.      else if (!u.uconduct.unvegetarian)
  23.          you_have_been("vegetarian");
  24.  
  25.      if (!u.uconduct.gnostic)
  26.          you_have_been("an atheist");
  27.  
  28.      if (!u.uconduct.weaphit) {
  29.          you_have_never("hit with a wielded weapon");
  30.      } else if (wizard) {
  31.          Sprintf(buf, "used a wielded weapon %ld time%s", u.uconduct.weaphit,
  32.                  plur(u.uconduct.weaphit));
  33.          you_have_X(buf);
  34.      }
  35.      if (!u.uconduct.killer)
  36.          you_have_been("a pacifist");
  37.  
  38.      if (!u.uconduct.literate) {
  39.          you_have_been("illiterate");
  40.      } else if (wizard) {
  41.          Sprintf(buf, "read items or engraved %ld time%s", u.uconduct.literate,
  42.                  plur(u.uconduct.literate));
  43.          you_have_X(buf);
  44.      }
  45.  
  46.      ngenocided = num_genocides();
  47.      if (ngenocided == 0) {
  48.          you_have_never("genocided any monsters");
  49.      } else {
  50.          Sprintf(buf, "genocided %d type%s of monster%s", ngenocided,
  51.                  plur(ngenocided), plur(ngenocided));
  52.          you_have_X(buf);
  53.      }
  54.  
  55.      if (!u.uconduct.polypiles) {
  56.          you_have_never("polymorphed an object");
  57.      } else if (wizard) {
  58.          Sprintf(buf, "polymorphed %ld item%s", u.uconduct.polypiles,
  59.                  plur(u.uconduct.polypiles));
  60.          you_have_X(buf);
  61.      }
  62.  
  63.      if (!u.uconduct.polyselfs) {
  64.          you_have_never("changed form");
  65.      } else if (wizard) {
  66.          Sprintf(buf, "changed form %ld time%s", u.uconduct.polyselfs,
  67.                  plur(u.uconduct.polyselfs));
  68.          you_have_X(buf);
  69.      }
  70.  
  71.      if (!u.uconduct.wishes) {
  72.          you_have_X("used no wishes");
  73.      } else {
  74.          Sprintf(buf, "used %ld wish%s", u.uconduct.wishes,
  75.                  (u.uconduct.wishes > 1L) ? "es" : "");
  76.          if (u.uconduct.wisharti) {
  77.              /* if wisharti == wishes
  78.               *  1 wish (for an artifact)
  79.               *  2 wishes (both for artifacts)
  80.               *  N wishes (all for artifacts)
  81.               * else (N is at least 2 in order to get here; M < N)
  82.               *  N wishes (1 for an artifact)
  83.               *  N wishes (M for artifacts)
  84.               */
  85.              if (u.uconduct.wisharti == u.uconduct.wishes)
  86.                  Sprintf(eos(buf), " (%s",
  87.                          (u.uconduct.wisharti > 2L) ? "all "
  88.                            : (u.uconduct.wisharti == 2L) ? "both " : "");
  89.              else
  90.                  Sprintf(eos(buf), " (%ld ", u.uconduct.wisharti);
  91.  
  92.              Sprintf(eos(buf), "for %s)",
  93.                      (u.uconduct.wisharti == 1L) ? "an artifact"
  94.                                                  : "artifacts");
  95.          }
  96.          you_have_X(buf);
  97.  
  98.          if (!u.uconduct.wisharti)
  99.              enl_msg(You_, "have not wished", "did not wish",
  100.                      " for any artifacts", "");
  101.      }
  102.  
  103.      /* Pop up the window and wait for a key */
  104.      display_nhwindow(en_win, TRUE);
  105.      destroy_nhwindow(en_win);
  106.      en_win = WIN_ERR;
  107.  }
  108.  
  109.  /* Macros for meta and ctrl modifiers:
  110.   *   M and C return the meta/ctrl code for the given character;
  111.   *     e.g., (C('c') is ctrl-c
  112.   */
  113.  #ifndef M
  114.  #ifndef NHSTDC
  115.  #define M(c) (0x80 | (c))
  116.  #else
  117.  #define M(c) ((c) - 128)
  118.  #endif /* NHSTDC */
  119.  #endif
  120.  
  121.  #ifndef C
  122.  #define C(c) (0x1f & (c))
  123.  #endif
  124.  
  125.  /* ordered by command name */
  126.  struct ext_func_tab extcmdlist[] = {
  127.      { '#', "#", "perform an extended command",
  128.              doextcmd, IFBURIED | GENERALCMD },
  129.      { M('?'), "?", "list all extended commands",
  130.              doextlist, IFBURIED | AUTOCOMPLETE | GENERALCMD },
  131.      { M('a'), "adjust", "adjust inventory letters",
  132.              doorganize, IFBURIED | AUTOCOMPLETE },
  133.      { M('A'), "annotate", "name current level",
  134.              donamelevel, IFBURIED | AUTOCOMPLETE },
  135.      { 'a', "apply", "apply (use) a tool (pick-axe, key, lamp...)",
  136.              doapply },
  137.      { C('x'), "attributes", "show your attributes",
  138.              doattributes, IFBURIED },
  139.      { '@', "autopickup", "toggle the pickup option on/off",
  140.              dotogglepickup, IFBURIED },
  141.      { 'C', "call", "call (name) something", docallcmd, IFBURIED },
  142.      { 'Z', "cast", "zap (cast) a spell", docast, IFBURIED },
  143.      { M('c'), "chat", "talk to someone", dotalk, IFBURIED | AUTOCOMPLETE },
  144.      { 'c', "close", "close a door", doclose },
  145.      { M('C'), "conduct", "list voluntary challenges you have maintained",
  146.              doconduct, IFBURIED | AUTOCOMPLETE },
  147.      { M('d'), "dip", "dip an object into something", dodip, AUTOCOMPLETE },
  148.      { '>', "down", "go down a staircase", dodown },
  149.      { 'd', "drop", "drop an item", dodrop },
  150.      { 'D', "droptype", "drop specific item types", doddrop },
  151.      { 'e', "eat", "eat something", doeat },
  152.      { 'E', "engrave", "engrave writing on the floor", doengrave },
  153.      { M('e'), "enhance", "advance or check weapon and spell skills",
  154.              enhance_weapon_skill, IFBURIED | AUTOCOMPLETE },
  155.      { '\0', "exploremode", "enter explore (discovery) mode",
  156.              enter_explore_mode, IFBURIED },
  157.      { 'f', "fire", "fire ammunition from quiver", dofire },
  158.      { M('f'), "force", "force a lock", doforce, AUTOCOMPLETE },
  159.      { ';', "glance", "show what type of thing a map symbol corresponds to",
  160.              doquickwhatis, IFBURIED | GENERALCMD },
  161.      { '?', "help", "give a help message", dohelp, IFBURIED | GENERALCMD },
  162.      { '\0', "herecmdmenu", "show menu of commands you can do here",
  163.              doherecmdmenu, IFBURIED },
  164.      { 'V', "history", "show long version and game history",
  165.              dohistory, IFBURIED | GENERALCMD },
  166.      { 'i', "inventory", "show your inventory", ddoinv, IFBURIED },
  167.      { 'I', "inventtype", "inventory specific item types",
  168.              dotypeinv, IFBURIED },
  169.      { M('i'), "invoke", "invoke an object's special powers",
  170.              doinvoke, IFBURIED | AUTOCOMPLETE },
  171.      { M('j'), "jump", "jump to another location", dojump, AUTOCOMPLETE },
  172.      { C('d'), "kick", "kick something", dokick },
  173.      { '\\', "known", "show what object types have been discovered",
  174.              dodiscovered, IFBURIED | GENERALCMD },
  175.      { '`', "knownclass", "show discovered types for one class of objects",
  176.              doclassdisco, IFBURIED | GENERALCMD },
  177.      { '\0', "levelchange", "change experience level",
  178.              wiz_level_change, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  179.      { '\0', "lightsources", "show mobile light sources",
  180.              wiz_light_sources, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  181.      { ':', "look", "look at what is here", dolook, IFBURIED },
  182.      { M('l'), "loot", "loot a box on the floor", doloot, AUTOCOMPLETE },
  183.  #ifdef DEBUG_MIGRATING_MONS
  184.      { '\0', "migratemons", "migrate N random monsters",
  185.              wiz_migrate_mons, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  186.  #endif
  187.      { '\0', "monpolycontrol", "control monster polymorphs",
  188.              wiz_mon_polycontrol, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  189.      { M('m'), "monster", "use monster's special ability",
  190.              domonability, IFBURIED | AUTOCOMPLETE },
  191.      { 'N', "name", "name a monster or an object",
  192.              docallcmd, IFBURIED | AUTOCOMPLETE },
  193.      { M('o'), "offer", "offer a sacrifice to the gods",
  194.              dosacrifice, AUTOCOMPLETE },
  195.      { 'o', "open", "open a door", doopen },
  196.      { 'O', "options", "show option settings, possibly change them",
  197.              doset, IFBURIED | GENERALCMD },
  198.      { C('o'), "overview", "show a summary of the explored dungeon",
  199.              dooverview, IFBURIED | AUTOCOMPLETE },
  200.      { '\0', "panic", "test panic routine (fatal to game)",
  201.              wiz_panic, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  202.      { 'p', "pay", "pay your shopping bill", dopay },
  203.      { ',', "pickup", "pick up things at the current location", dopickup },
  204.      { '\0', "polyself", "polymorph self",
  205.              wiz_polyself, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  206.  #ifdef PORT_DEBUG
  207.      { '\0', "portdebug", "wizard port debug command",
  208.              wiz_port_debug, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  209.  #endif
  210.      { M('p'), "pray", "pray to the gods for help",
  211.              dopray, IFBURIED | AUTOCOMPLETE },
  212.      { C('p'), "prevmsg", "view recent game messages",
  213.              doprev_message, IFBURIED | GENERALCMD },
  214.      { 'P', "puton", "put on an accessory (ring, amulet, etc)", doputon },
  215.      { 'q', "quaff", "quaff (drink) something", dodrink },
  216.      { M('q'), "quit", "exit without saving current game",
  217.              done2, IFBURIED | AUTOCOMPLETE | GENERALCMD },
  218.      { 'Q', "quiver", "select ammunition for quiver", dowieldquiver },
  219.      { 'r', "read", "read a scroll or spellbook", doread },
  220.      { C('r'), "redraw", "redraw screen", doredraw, IFBURIED | GENERALCMD },
  221.      { 'R', "remove", "remove an accessory (ring, amulet, etc)", doremring },
  222.      { M('R'), "ride", "mount or dismount a saddled steed",
  223.              doride, AUTOCOMPLETE },
  224.      { M('r'), "rub", "rub a lamp or a stone", dorub, AUTOCOMPLETE },
  225.      { 'S', "save", "save the game and exit", dosave, IFBURIED | GENERALCMD },
  226.      { 's', "search", "search for traps and secret doors",
  227.              dosearch, IFBURIED, "searching" },
  228.      { '*', "seeall", "show all equipment in use", doprinuse, IFBURIED },
  229.      { AMULET_SYM, "seeamulet", "show the amulet currently worn",
  230.              dopramulet, IFBURIED },
  231.      { ARMOR_SYM, "seearmor", "show the armor currently worn",
  232.              doprarm, IFBURIED },
  233.      { GOLD_SYM, "seegold", "count your gold", doprgold, IFBURIED },
  234.      { '\0', "seenv", "show seen vectors",
  235.              wiz_show_seenv, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  236.      { RING_SYM, "seerings", "show the ring(s) currently worn",
  237.              doprring, IFBURIED },
  238.      { SPBOOK_SYM, "seespells", "list and reorder known spells",
  239.              dovspell, IFBURIED },
  240.      { TOOL_SYM, "seetools", "show the tools currently in use",
  241.              doprtool, IFBURIED },
  242.      { '^', "seetrap", "show the type of adjacent trap", doidtrap, IFBURIED },
  243.      { WEAPON_SYM, "seeweapon", "show the weapon currently wielded",
  244.              doprwep, IFBURIED },
  245.  #ifdef SHELL
  246.      { '!', "shell", "do a shell escape", dosh, IFBURIED | GENERALCMD },
  247.  #endif /* SHELL */
  248.      { M('s'), "sit", "sit down", dosit, AUTOCOMPLETE },
  249.      { '\0', "stats", "show memory statistics",
  250.              wiz_show_stats, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  251.  #ifdef SUSPEND
  252.      { C('z'), "suspend", "suspend the game",
  253.              dosuspend_core, IFBURIED | GENERALCMD },
  254.  #endif /* SUSPEND */
  255.      { 'x', "swap", "swap wielded and secondary weapons", doswapweapon },
  256.      { 'T', "takeoff", "take off one piece of armor", dotakeoff },
  257.      { 'A', "takeoffall", "remove all armor", doddoremarm },
  258.      { C('t'), "teleport", "teleport around the level", dotele, IFBURIED },
  259.      { '\0', "terrain", "show map without obstructions",
  260.              doterrain, IFBURIED | AUTOCOMPLETE },
  261.      { '\0', "therecmdmenu",
  262.              "menu of commands you can do from here to adjacent spot",
  263.              dotherecmdmenu },
  264.      { 't', "throw", "throw something", dothrow },
  265.      { '\0', "timeout", "look at timeout queue and hero's timed intrinsics",
  266.              wiz_timeout_queue, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  267.      { M('T'), "tip", "empty a container", dotip, AUTOCOMPLETE },
  268.      { '_', "travel", "travel to a specific location on the map", dotravel },
  269.      { M('t'), "turn", "turn undead away", doturn, IFBURIED | AUTOCOMPLETE },
  270.      { 'X', "twoweapon", "toggle two-weapon combat",
  271.              dotwoweapon, AUTOCOMPLETE },
  272.      { M('u'), "untrap", "untrap something", dountrap, AUTOCOMPLETE },
  273.      { '<', "up", "go up a staircase", doup },
  274.      { '\0', "vanquished", "list vanquished monsters",
  275.              dovanquished, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  276.      { M('v'), "version",
  277.              "list compile time options for this version of NetHack",
  278.              doextversion, IFBURIED | AUTOCOMPLETE | GENERALCMD },
  279.      { 'v', "versionshort", "show version", doversion, IFBURIED | GENERALCMD },
  280.      { '\0', "vision", "show vision array",
  281.              wiz_show_vision, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  282.      { '.', "wait", "rest one move while doing nothing",
  283.              donull, IFBURIED, "waiting" },
  284.      { 'W', "wear", "wear a piece of armor", dowear },
  285.      { '&', "whatdoes", "tell what a command does", dowhatdoes, IFBURIED },
  286.      { '/', "whatis", "show what type of thing a symbol corresponds to",
  287.              dowhatis, IFBURIED | GENERALCMD },
  288.      { 'w', "wield", "wield (put in use) a weapon", dowield },
  289.      { M('w'), "wipe", "wipe off your face", dowipe, AUTOCOMPLETE },
  290.  #ifdef DEBUG
  291.      { '\0', "wizdebug_bury", "wizard debug: bury objs under and around you",
  292.              wiz_debug_cmd_bury, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  293.      { '\0', "wizdebug_traveldisplay", "wizard debug: toggle travel display",
  294.            wiz_debug_cmd_traveldisplay, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  295.  #endif
  296.      { C('e'), "wizdetect", "reveal hidden things within a small radius",
  297.              wiz_detect, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  298.      { C('g'), "wizgenesis", "create a monster",
  299.              wiz_genesis, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  300.      { C('i'), "wizidentify", "identify all items in inventory",
  301.              wiz_identify, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  302.      { '\0', "wizintrinsic", "set an intrinsic",
  303.              wiz_intrinsic, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  304.      { C('v'), "wizlevelport", "teleport to another level",
  305.              wiz_level_tele, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  306.      { '\0', "wizmakemap", "recreate the current level",
  307.              wiz_makemap, IFBURIED | WIZMODECMD },
  308.      { C('f'), "wizmap", "map the level",
  309.              wiz_map, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  310.      { '\0', "wizrumorcheck", "verify rumor boundaries",
  311.              wiz_rumor_check, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  312.      { '\0', "wizsmell", "smell monster",
  313.              wiz_smell, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  314.      { '\0', "wizwhere", "show locations of special levels",
  315.              wiz_where, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  316.      { C('w'), "wizwish", "wish for something",
  317.              wiz_wish, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  318.      { '\0', "wmode", "show wall modes",
  319.              wiz_show_wmodes, IFBURIED | AUTOCOMPLETE | WIZMODECMD },
  320.      { 'z', "zap", "zap a wand", dozap },
  321.      { '\0', (char *) 0, (char *) 0, donull, 0, (char *) 0 } /* sentinel */
  322.  };
  323.  
  324.  const char *
  325.  key2extcmddesc(key)
  326.  uchar key;
  327.  {
  328.      if (Cmd.commands[key] && Cmd.commands[key]->ef_txt)
  329.          return Cmd.commands[key]->ef_desc;
  330.      return (char *) 0;
  331.  }
  332.  

bind_key

  1.  boolean
  2.  bind_key(key, command)
  3.  uchar key;
  4.  const char *command;
  5.  {
  6.      struct ext_func_tab *extcmd;
  7.  
  8.      /* special case: "nothing" is reserved for unbinding */
  9.      if (!strcmp(command, "nothing")) {
  10.          Cmd.commands[key] = (struct ext_func_tab *) 0;
  11.          return TRUE;
  12.      }
  13.  
  14.      for (extcmd = extcmdlist; extcmd->ef_txt; extcmd++) {
  15.          if (strcmp(command, extcmd->ef_txt))
  16.              continue;
  17.          Cmd.commands[key] = extcmd;
  18.          return TRUE;
  19.      }
  20.  
  21.      return FALSE;
  22.  }
  23.  

commands_init

  1.  /* initialize all keyboard commands */
  2.  void
  3.  commands_init()
  4.  {
  5.      struct ext_func_tab *extcmd;
  6.  
  7.      for (extcmd = extcmdlist; extcmd->ef_txt; extcmd++)
  8.          if (extcmd->key)
  9.              Cmd.commands[extcmd->key] = extcmd;
  10.  
  11.      (void) bind_key(C('l'), "redraw"); /* if number_pad is set */
  12.      /*       'b', 'B' : go sw */
  13.      /*       'F' : fight (one time) */
  14.      /*       'g', 'G' : multiple go */
  15.      /*       'h', 'H' : go west */
  16.      (void) bind_key('h',    "help"); /* if number_pad is set */
  17.      (void) bind_key('j',    "jump"); /* if number_pad is on */
  18.      /*       'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' move commands */
  19.      (void) bind_key('k',    "kick"); /* if number_pad is on */
  20.      (void) bind_key('l',    "loot"); /* if number_pad is on */
  21.      (void) bind_key(C('n'), "annotate"); /* if number_pad is on */
  22.      (void) bind_key(M('n'), "name");
  23.      (void) bind_key(M('N'), "name");
  24.      (void) bind_key('u',    "untrap"); /* if number_pad is on */
  25.  
  26.      /* alt keys: */
  27.      (void) bind_key(M('O'), "overview");
  28.      (void) bind_key(M('2'), "twoweapon");
  29.  
  30.      /* wait_on_space */
  31.      (void) bind_key(' ',    "wait");
  32.  }
  33.  

dokeylist_putcmds

  1.  int
  2.  dokeylist_putcmds(datawin, docount, cmdflags, exflags, keys_used)
  3.  winid datawin;
  4.  boolean docount;
  5.  int cmdflags, exflags;
  6.  boolean *keys_used; /* boolean keys_used[256] */
  7.  {
  8.      int i;
  9.      char buf[BUFSZ];
  10.      char buf2[QBUFSZ];
  11.      int count = 0;
  12.  
  13.      for (i = 0; i < 256; i++) {
  14.          const struct ext_func_tab *extcmd;
  15.          uchar key = (uchar) i;
  16.  
  17.          if (keys_used[i])
  18.              continue;
  19.          if (key == ' ' && !flags.rest_on_space)
  20.              continue;
  21.          if ((extcmd = Cmd.commands[i]) != (struct ext_func_tab *) 0) {
  22.              if ((cmdflags && !(extcmd->flags & cmdflags))
  23.                  || (exflags && (extcmd->flags & exflags)))
  24.                  continue;
  25.              if (docount) {
  26.                  count++;
  27.                  continue;
  28.              }
  29.              Sprintf(buf, "%-8s %-12s %s", key2txt(key, buf2),
  30.                      extcmd->ef_txt,
  31.                      extcmd->ef_desc);
  32.              putstr(datawin, 0, buf);
  33.              keys_used[i] = TRUE;
  34.          }
  35.      }
  36.      return count;
  37.  }
  38.  

dokeylist

  1.  /* list all keys and their bindings, like dat/hh but dynamic */
  2.  void
  3.  dokeylist(VOID_ARGS)
  4.  {
  5.      char buf[BUFSZ], buf2[BUFSZ];
  6.      uchar key;
  7.      boolean keys_used[256] = {0};
  8.      winid datawin;
  9.      int i;
  10.      static const char
  11.          run_desc[] = "Prefix: run until something very interesting is seen",
  12.          forcefight_desc[] =
  13.                       "Prefix: force fight even if you don't see a monster";
  14.      static const struct {
  15.          int nhkf;
  16.          const char *desc;
  17.          boolean numpad;
  18.      } misc_keys[] = {
  19.          { NHKF_ESC, "escape from the current query/action", FALSE },
  20.          { NHKF_RUSH,
  21.            "Prefix: rush until something interesting is seen", FALSE },
  22.          { NHKF_RUN, run_desc, FALSE },
  23.          { NHKF_RUN2, run_desc, TRUE },
  24.          { NHKF_FIGHT, forcefight_desc, FALSE },
  25.          { NHKF_FIGHT2, forcefight_desc, TRUE } ,
  26.          { NHKF_NOPICKUP,
  27.            "Prefix: move without picking up objects/fighting", FALSE },
  28.          { NHKF_RUN_NOPICKUP,
  29.            "Prefix: run without picking up objects/fighting", FALSE },
  30.          { NHKF_DOINV, "view inventory", TRUE },
  31.          { NHKF_REQMENU, "Prefix: request a menu", FALSE },
  32.  #ifdef REDO
  33.          { NHKF_DOAGAIN , "re-do: perform the previous command again", FALSE },
  34.  #endif
  35.          { 0, (const char *) 0, FALSE }
  36.      };
  37.  
  38.      datawin = create_nhwindow(NHW_TEXT);
  39.      putstr(datawin, 0, "");
  40.      putstr(datawin, 0, "            Full Current Key Bindings List");
  41.  
  42.      /* directional keys */
  43.      putstr(datawin, 0, "");
  44.      putstr(datawin, 0, "Directional keys:");
  45.      show_direction_keys(datawin, '.', FALSE); /* '.'==self in direction grid */
  46.  
  47.      keys_used[(uchar) Cmd.move_NW] = keys_used[(uchar) Cmd.move_N]
  48.          = keys_used[(uchar) Cmd.move_NE] = keys_used[(uchar) Cmd.move_W]
  49.          = keys_used[(uchar) Cmd.move_E] = keys_used[(uchar) Cmd.move_SW]
  50.          = keys_used[(uchar) Cmd.move_S] = keys_used[(uchar) Cmd.move_SE]
  51.          = TRUE;
  52.  
  53.      if (!iflags.num_pad) {
  54.          keys_used[(uchar) highc(Cmd.move_NW)]
  55.              = keys_used[(uchar) highc(Cmd.move_N)]
  56.              = keys_used[(uchar) highc(Cmd.move_NE)]
  57.              = keys_used[(uchar) highc(Cmd.move_W)]
  58.              = keys_used[(uchar) highc(Cmd.move_E)]
  59.              = keys_used[(uchar) highc(Cmd.move_SW)]
  60.              = keys_used[(uchar) highc(Cmd.move_S)]
  61.              = keys_used[(uchar) highc(Cmd.move_SE)] = TRUE;
  62.          keys_used[(uchar) C(Cmd.move_NW)]
  63.              = keys_used[(uchar) C(Cmd.move_N)]
  64.              = keys_used[(uchar) C(Cmd.move_NE)]
  65.              = keys_used[(uchar) C(Cmd.move_W)]
  66.              = keys_used[(uchar) C(Cmd.move_E)]
  67.              = keys_used[(uchar) C(Cmd.move_SW)]
  68.              = keys_used[(uchar) C(Cmd.move_S)]
  69.              = keys_used[(uchar) C(Cmd.move_SE)] = TRUE;
  70.          putstr(datawin, 0, "");
  71.          putstr(datawin, 0,
  72.            "Shift-<direction> will move in specified direction until you hit");
  73.          putstr(datawin, 0, "        a wall or run into something.");
  74.          putstr(datawin, 0,
  75.            "Ctrl-<direction> will run in specified direction until something");
  76.          putstr(datawin, 0, "        very interesting is seen.");
  77.      }
  78.  
  79.      putstr(datawin, 0, "");
  80.      putstr(datawin, 0, "Miscellaneous keys:");
  81.      for (i = 0; misc_keys[i].desc; i++) {
  82.          key = Cmd.spkeys[misc_keys[i].nhkf];
  83.          if (key && ((misc_keys[i].numpad && iflags.num_pad)
  84.                      || !misc_keys[i].numpad)) {
  85.              keys_used[(uchar) key] = TRUE;
  86.              Sprintf(buf, "%-8s %s", key2txt(key, buf2), misc_keys[i].desc);
  87.              putstr(datawin, 0, buf);
  88.          }
  89.      }
  90.  #ifndef NO_SIGNAL
  91.      putstr(datawin, 0, "^c       break out of NetHack (SIGINT)");
  92.      keys_used[(uchar) C('c')] = TRUE;
  93.  #endif
  94.  
  95.      putstr(datawin, 0, "");
  96.      show_menu_controls(datawin, TRUE);
  97.  
  98.      if (dokeylist_putcmds(datawin, TRUE, GENERALCMD, WIZMODECMD, keys_used)) {
  99.          putstr(datawin, 0, "");
  100.          putstr(datawin, 0, "General commands:");
  101.          (void) dokeylist_putcmds(datawin, FALSE, GENERALCMD, WIZMODECMD,
  102.                                   keys_used);
  103.      }
  104.  
  105.      if (dokeylist_putcmds(datawin, TRUE, 0, WIZMODECMD, keys_used)) {
  106.          putstr(datawin, 0, "");
  107.          putstr(datawin, 0, "Game commands:");
  108.          (void) dokeylist_putcmds(datawin, FALSE, 0, WIZMODECMD, keys_used);
  109.      }
  110.  
  111.      if (wizard
  112.          && dokeylist_putcmds(datawin, TRUE, WIZMODECMD, 0, keys_used)) {
  113.          putstr(datawin, 0, "");
  114.          putstr(datawin, 0, "Wizard-mode commands:");
  115.          (void) dokeylist_putcmds(datawin, FALSE, WIZMODECMD, 0, keys_used);
  116.      }
  117.  
  118.      display_nhwindow(datawin, FALSE);
  119.      destroy_nhwindow(datawin);
  120.  }
  121.  

cmd_from_func

  1.  char
  2.  cmd_from_func(fn)
  3.  int NDECL((*fn));
  4.  {
  5.      int i;
  6.  
  7.      for (i = 0; i < 256; ++i)
  8.          if (Cmd.commands[i] && Cmd.commands[i]->ef_funct == fn)
  9.              return (char) i;
  10.      return '\0';
  11.  }
  12.  
  13.  /*
  14.   * wizard mode sanity_check code
  15.   */
  16.  
  17.  static const char template[] = "%-27s  %4ld  %6ld";
  18.  static const char stats_hdr[] = "                             count  bytes";
  19.  static const char stats_sep[] = "---------------------------  ----- -------";
  20.  

size_obj

  1.  STATIC_OVL int
  2.  size_obj(otmp)
  3.  struct obj *otmp;
  4.  {
  5.      int sz = (int) sizeof(struct obj);
  6.  
  7.      if (otmp->oextra) {
  8.          sz += (int) sizeof(struct oextra);
  9.          if (ONAME(otmp))
  10.              sz += (int) strlen(ONAME(otmp)) + 1;
  11.          if (OMONST(otmp))
  12.              sz += (int) sizeof(struct monst);
  13.          if (OMID(otmp))
  14.              sz += (int) sizeof(unsigned);
  15.          if (OLONG(otmp))
  16.              sz += (int) sizeof(long);
  17.          if (OMAILCMD(otmp))
  18.              sz += (int) strlen(OMAILCMD(otmp)) + 1;
  19.      }
  20.      return sz;
  21.  }
  22.  

count_obj

  1.  STATIC_OVL void
  2.  count_obj(chain, total_count, total_size, top, recurse)
  3.  struct obj *chain;
  4.  long *total_count;
  5.  long *total_size;
  6.  boolean top;
  7.  boolean recurse;
  8.  {
  9.      long count, size;
  10.      struct obj *obj;
  11.  
  12.      for (count = size = 0, obj = chain; obj; obj = obj->nobj) {
  13.          if (top) {
  14.              count++;
  15.              size += size_obj(obj);
  16.          }
  17.          if (recurse && obj->cobj)
  18.              count_obj(obj->cobj, total_count, total_size, TRUE, TRUE);
  19.      }
  20.      *total_count += count;
  21.      *total_size += size;
  22.  }
  23.  

obj_chain

  1.  STATIC_OVL void
  2.  obj_chain(win, src, chain, force, total_count, total_size)
  3.  winid win;
  4.  const char *src;
  5.  struct obj *chain;
  6.  boolean force;
  7.  long *total_count;
  8.  long *total_size;
  9.  {
  10.      char buf[BUFSZ];
  11.      long count = 0L, size = 0L;
  12.  
  13.      count_obj(chain, &count, &size, TRUE, FALSE);
  14.  
  15.      if (count || size || force) {
  16.          *total_count += count;
  17.          *total_size += size;
  18.          Sprintf(buf, template, src, count, size);
  19.          putstr(win, 0, buf);
  20.      }
  21.  }
  22.  

mon_invent_chain

  1.  STATIC_OVL void
  2.  mon_invent_chain(win, src, chain, total_count, total_size)
  3.  winid win;
  4.  const char *src;
  5.  struct monst *chain;
  6.  long *total_count;
  7.  long *total_size;
  8.  {
  9.      char buf[BUFSZ];
  10.      long count = 0, size = 0;
  11.      struct monst *mon;
  12.  
  13.      for (mon = chain; mon; mon = mon->nmon)
  14.          count_obj(mon->minvent, &count, &size, TRUE, FALSE);
  15.  
  16.      if (count || size) {
  17.          *total_count += count;
  18.          *total_size += size;
  19.          Sprintf(buf, template, src, count, size);
  20.          putstr(win, 0, buf);
  21.      }
  22.  }
  23.  

contained_stats

  1.  STATIC_OVL void
  2.  contained_stats(win, src, total_count, total_size)
  3.  winid win;
  4.  const char *src;
  5.  long *total_count;
  6.  long *total_size;
  7.  {
  8.      char buf[BUFSZ];
  9.      long count = 0, size = 0;
  10.      struct monst *mon;
  11.  
  12.      count_obj(invent, &count, &size, FALSE, TRUE);
  13.      count_obj(fobj, &count, &size, FALSE, TRUE);
  14.      count_obj(level.buriedobjlist, &count, &size, FALSE, TRUE);
  15.      count_obj(migrating_objs, &count, &size, FALSE, TRUE);
  16.      /* DEADMONSTER check not required in this loop since they have no
  17.       * inventory */
  18.      for (mon = fmon; mon; mon = mon->nmon)
  19.          count_obj(mon->minvent, &count, &size, FALSE, TRUE);
  20.      for (mon = migrating_mons; mon; mon = mon->nmon)
  21.          count_obj(mon->minvent, &count, &size, FALSE, TRUE);
  22.  
  23.      if (count || size) {
  24.          *total_count += count;
  25.          *total_size += size;
  26.          Sprintf(buf, template, src, count, size);
  27.          putstr(win, 0, buf);
  28.      }
  29.  }
  30.  

size_monst

  1.  STATIC_OVL int
  2.  size_monst(mtmp, incl_wsegs)
  3.  struct monst *mtmp;
  4.  boolean incl_wsegs;
  5.  {
  6.      int sz = (int) sizeof (struct monst);
  7.  
  8.      if (mtmp->wormno && incl_wsegs)
  9.          sz += size_wseg(mtmp);
  10.  
  11.      if (mtmp->mextra) {
  12.          sz += (int) sizeof (struct mextra);
  13.          if (MNAME(mtmp))
  14.              sz += (int) strlen(MNAME(mtmp)) + 1;
  15.          if (EGD(mtmp))
  16.              sz += (int) sizeof (struct egd);
  17.          if (EPRI(mtmp))
  18.              sz += (int) sizeof (struct epri);
  19.          if (ESHK(mtmp))
  20.              sz += (int) sizeof (struct eshk);
  21.          if (EMIN(mtmp))
  22.              sz += (int) sizeof (struct emin);
  23.          if (EDOG(mtmp))
  24.              sz += (int) sizeof (struct edog);
  25.          /* mextra->mcorpsenm doesn't point to more memory */
  26.      }
  27.      return sz;
  28.  }
  29.  

mon_chain

  1.  STATIC_OVL void
  2.  mon_chain(win, src, chain, force, total_count, total_size)
  3.  winid win;
  4.  const char *src;
  5.  struct monst *chain;
  6.  boolean force;
  7.  long *total_count;
  8.  long *total_size;
  9.  {
  10.      char buf[BUFSZ];
  11.      long count, size;
  12.      struct monst *mon;
  13.      /* mon->wormno means something different for migrating_mons and mydogs */
  14.      boolean incl_wsegs = !strcmpi(src, "fmon");
  15.  
  16.      count = size = 0L;
  17.      for (mon = chain; mon; mon = mon->nmon) {
  18.          count++;
  19.          size += size_monst(mon, incl_wsegs);
  20.      }
  21.      if (count || size || force) {
  22.          *total_count += count;
  23.          *total_size += size;
  24.          Sprintf(buf, template, src, count, size);
  25.          putstr(win, 0, buf);
  26.      }
  27.  }
  28.  

misc_stats

  1.  STATIC_OVL void
  2.  misc_stats(win, total_count, total_size)
  3.  winid win;
  4.  long *total_count;
  5.  long *total_size;
  6.  {
  7.      char buf[BUFSZ], hdrbuf[QBUFSZ];
  8.      long count, size;
  9.      int idx;
  10.      struct trap *tt;
  11.      struct damage *sd; /* shop damage */
  12.      struct cemetery *bi; /* bones info */
  13.  
  14.      /* traps and engravings are output unconditionally;
  15.       * others only if nonzero
  16.       */
  17.      count = size = 0L;
  18.      for (tt = ftrap; tt; tt = tt->ntrap) {
  19.          ++count;
  20.          size += (long) sizeof *tt;
  21.      }
  22.      *total_count += count;
  23.      *total_size += size;
  24.      Sprintf(hdrbuf, "traps, size %ld", (long) sizeof (struct trap));
  25.      Sprintf(buf, template, hdrbuf, count, size);
  26.      putstr(win, 0, buf);
  27.  
  28.      count = size = 0L;
  29.      engr_stats("engravings, size %ld+text", hdrbuf, &count, &size);
  30.      *total_count += count;
  31.      *total_size += size;
  32.      Sprintf(buf, template, hdrbuf, count, size);
  33.      putstr(win, 0, buf);
  34.  
  35.      count = size = 0L;
  36.      light_stats("light sources, size %ld", hdrbuf, &count, &size);
  37.      if (count || size) {
  38.          *total_count += count;
  39.          *total_size += size;
  40.          Sprintf(buf, template, hdrbuf, count, size);
  41.          putstr(win, 0, buf);
  42.      }
  43.  
  44.      count = size = 0L;
  45.      timer_stats("timers, size %ld", hdrbuf, &count, &size);
  46.      if (count || size) {
  47.          *total_count += count;
  48.          *total_size += size;
  49.          Sprintf(buf, template, hdrbuf, count, size);
  50.          putstr(win, 0, buf);
  51.      }
  52.  
  53.      count = size = 0L;
  54.      for (sd = level.damagelist; sd; sd = sd->next) {
  55.          ++count;
  56.          size += (long) sizeof *sd;
  57.      }
  58.      if (count || size) {
  59.          *total_count += count;
  60.          *total_size += size;
  61.          Sprintf(hdrbuf, "shop damage, size %ld",
  62.                  (long) sizeof (struct damage));
  63.          Sprintf(buf, template, hdrbuf, count, size);
  64.          putstr(win, 0, buf);
  65.      }
  66.  
  67.      count = size = 0L;
  68.      region_stats("regions, size %ld+%ld*rect+N", hdrbuf, &count, &size);
  69.      if (count || size) {
  70.          *total_count += count;
  71.          *total_size += size;
  72.          Sprintf(buf, template, hdrbuf, count, size);
  73.          putstr(win, 0, buf);
  74.      }
  75.  
  76.      count = size = 0L;
  77.      for (bi = level.bonesinfo; bi; bi = bi->next) {
  78.          ++count;
  79.          size += (long) sizeof *bi;
  80.      }
  81.      if (count || size) {
  82.          *total_count += count;
  83.          *total_size += size;
  84.          Sprintf(hdrbuf, "bones history, size %ld",
  85.                  (long) sizeof (struct cemetery));
  86.          Sprintf(buf, template, hdrbuf, count, size);
  87.          putstr(win, 0, buf);
  88.      }
  89.  
  90.      count = size = 0L;
  91.      for (idx = 0; idx < NUM_OBJECTS; ++idx)
  92.          if (objects[idx].oc_uname) {
  93.              ++count;
  94.              size += (long) (strlen(objects[idx].oc_uname) + 1);
  95.          }
  96.      if (count || size) {
  97.          *total_count += count;
  98.          *total_size += size;
  99.          Strcpy(hdrbuf, "object type names, text");
  100.          Sprintf(buf, template, hdrbuf, count, size);
  101.          putstr(win, 0, buf);
  102.      }
  103.  }
  104.  

wiz_show_stats

  1.  /*
  2.   * Display memory usage of all monsters and objects on the level.
  3.   */
  4.  static int
  5.  wiz_show_stats()
  6.  {
  7.      char buf[BUFSZ];
  8.      winid win;
  9.      long total_obj_size, total_obj_count,
  10.           total_mon_size, total_mon_count,
  11.           total_ovr_size, total_ovr_count,
  12.           total_misc_size, total_misc_count;
  13.  
  14.      win = create_nhwindow(NHW_TEXT);
  15.      putstr(win, 0, "Current memory statistics:");
  16.  
  17.      total_obj_count = total_obj_size = 0L;
  18.      putstr(win, 0, stats_hdr);
  19.      Sprintf(buf, "  Objects, base size %ld", (long) sizeof (struct obj));
  20.      putstr(win, 0, buf);
  21.      obj_chain(win, "invent", invent, TRUE, &total_obj_count, &total_obj_size);
  22.      obj_chain(win, "fobj", fobj, TRUE, &total_obj_count, &total_obj_size);
  23.      obj_chain(win, "buried", level.buriedobjlist, FALSE,
  24.                &total_obj_count, &total_obj_size);
  25.      obj_chain(win, "migrating obj", migrating_objs, FALSE,
  26.                &total_obj_count, &total_obj_size);
  27.      obj_chain(win, "billobjs", billobjs, FALSE,
  28.                &total_obj_count, &total_obj_size);
  29.      mon_invent_chain(win, "minvent", fmon, &total_obj_count, &total_obj_size);
  30.      mon_invent_chain(win, "migrating minvent", migrating_mons,
  31.                       &total_obj_count, &total_obj_size);
  32.      contained_stats(win, "contained", &total_obj_count, &total_obj_size);
  33.      putstr(win, 0, stats_sep);
  34.      Sprintf(buf, template, "  Obj total", total_obj_count, total_obj_size);
  35.      putstr(win, 0, buf);
  36.  
  37.      total_mon_count = total_mon_size = 0L;
  38.      putstr(win, 0, "");
  39.      Sprintf(buf, "  Monsters, base size %ld", (long) sizeof (struct monst));
  40.      putstr(win, 0, buf);
  41.      mon_chain(win, "fmon", fmon, TRUE, &total_mon_count, &total_mon_size);
  42.      mon_chain(win, "migrating", migrating_mons, FALSE,
  43.                &total_mon_count, &total_mon_size);
  44.      /* 'mydogs' is only valid during level change or end of game disclosure,
  45.         but conceivably we've been called from within debugger at such time */
  46.      if (mydogs) /* monsters accompanying hero */
  47.          mon_chain(win, "mydogs", mydogs, FALSE,
  48.                    &total_mon_count, &total_mon_size);
  49.      putstr(win, 0, stats_sep);
  50.      Sprintf(buf, template, "  Mon total", total_mon_count, total_mon_size);
  51.      putstr(win, 0, buf);
  52.  
  53.      total_ovr_count = total_ovr_size = 0L;
  54.      putstr(win, 0, "");
  55.      putstr(win, 0, "  Overview");
  56.      overview_stats(win, template, &total_ovr_count, &total_ovr_size);
  57.      putstr(win, 0, stats_sep);
  58.      Sprintf(buf, template, "  Over total", total_ovr_count, total_ovr_size);
  59.      putstr(win, 0, buf);
  60.  
  61.      total_misc_count = total_misc_size = 0L;
  62.      putstr(win, 0, "");
  63.      putstr(win, 0, "  Miscellaneous");
  64.      misc_stats(win, &total_misc_count, &total_misc_size);
  65.      putstr(win, 0, stats_sep);
  66.      Sprintf(buf, template, "  Misc total", total_misc_count, total_misc_size);
  67.      putstr(win, 0, buf);
  68.  
  69.      putstr(win, 0, "");
  70.      putstr(win, 0, stats_sep);
  71.      Sprintf(buf, template, "  Grand total",
  72.              (total_obj_count + total_mon_count
  73.               + total_ovr_count + total_misc_count),
  74.              (total_obj_size + total_mon_size
  75.               + total_ovr_size + total_misc_size));
  76.      putstr(win, 0, buf);
  77.  
  78.  #if defined(__BORLANDC__) && !defined(_WIN32)
  79.      show_borlandc_stats(win);
  80.  #endif
  81.  
  82.      display_nhwindow(win, FALSE);
  83.      destroy_nhwindow(win);
  84.      return 0;
  85.  }
  86.  

sanity_check

wiz_migrate_mons

  1.  #ifdef DEBUG_MIGRATING_MONS
  2.  static int
  3.  wiz_migrate_mons()
  4.  {
  5.      int mcount = 0;
  6.      char inbuf[BUFSZ] = DUMMY;
  7.      struct permonst *ptr;
  8.      struct monst *mtmp;
  9.      d_level tolevel;
  10.  
  11.      getlin("How many random monsters to migrate? [0]", inbuf);
  12.      if (*inbuf == '\033')
  13.          return 0;
  14.      mcount = atoi(inbuf);
  15.      if (mcount < 0 || mcount > (COLNO * ROWNO) || Is_botlevel(&u.uz))
  16.          return 0;
  17.      while (mcount > 0) {
  18.          if (Is_stronghold(&u.uz))
  19.              assign_level(&tolevel, &valley_level);
  20.          else
  21.              get_level(&tolevel, depth(&u.uz) + 1);
  22.          ptr = rndmonst();
  23.          mtmp = makemon(ptr, 0, 0, NO_MM_FLAGS);
  24.          if (mtmp)
  25.              migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM,
  26.                               (coord *) 0);
  27.          mcount--;
  28.      }
  29.      return 0;
  30.  }
  31.  #endif
  32.  
  33.  #define unctrl(c) ((c) <= C('z') ? (0x60 | (c)) : (c))
  34.  #define unmeta(c) (0x7f & (c))
  35.  
  36.  struct {
  37.      int nhkf;
  38.      char key;
  39.      const char *name;
  40.  } const spkeys_binds[] = {
  41.      { NHKF_ESC,              '\033', (char *) 0 }, /* no binding */
  42.      { NHKF_DOAGAIN,          DOAGAIN, "repeat" },
  43.      { NHKF_REQMENU,          'm', "reqmenu" },
  44.      { NHKF_RUN,              'G', "run" },
  45.      { NHKF_RUN2,             '5', "run.numpad" },
  46.      { NHKF_RUSH,             'g', "rush" },
  47.      { NHKF_FIGHT,            'F', "fight" },
  48.      { NHKF_FIGHT2,           '-', "fight.numpad" },
  49.      { NHKF_NOPICKUP,         'm', "nopickup" },
  50.      { NHKF_RUN_NOPICKUP,     'M', "run.nopickup" },
  51.      { NHKF_DOINV,            '0', "doinv" },
  52.      { NHKF_TRAVEL,           CMD_TRAVEL, (char *) 0 }, /* no binding */
  53.      { NHKF_CLICKLOOK,        CMD_CLICKLOOK, (char *) 0 }, /* no binding */
  54.      { NHKF_REDRAW,           C('r'), "redraw" },
  55.      { NHKF_REDRAW2,          C('l'), "redraw.numpad" },
  56.      { NHKF_GETDIR_SELF,      '.', "getdir.self" },
  57.      { NHKF_GETDIR_SELF2,     's', "getdir.self2" },
  58.      { NHKF_GETDIR_HELP,      '?', "getdir.help" },
  59.      { NHKF_COUNT,            'n', "count" },
  60.      { NHKF_GETPOS_SELF,      '@', "getpos.self" },
  61.      { NHKF_GETPOS_PICK,      '.', "getpos.pick" },
  62.      { NHKF_GETPOS_PICK_Q,    ',', "getpos.pick.quick" },
  63.      { NHKF_GETPOS_PICK_O,    ';', "getpos.pick.once" },
  64.      { NHKF_GETPOS_PICK_V,    ':', "getpos.pick.verbose" },
  65.      { NHKF_GETPOS_SHOWVALID, '$', "getpos.valid" },
  66.      { NHKF_GETPOS_AUTODESC,  '#', "getpos.autodescribe" },
  67.      { NHKF_GETPOS_MON_NEXT,  'm', "getpos.mon.next" },
  68.      { NHKF_GETPOS_MON_PREV,  'M', "getpos.mon.prev" },
  69.      { NHKF_GETPOS_OBJ_NEXT,  'o', "getpos.obj.next" },
  70.      { NHKF_GETPOS_OBJ_PREV,  'O', "getpos.obj.prev" },
  71.      { NHKF_GETPOS_DOOR_NEXT, 'd', "getpos.door.next" },
  72.      { NHKF_GETPOS_DOOR_PREV, 'D', "getpos.door.prev" },
  73.      { NHKF_GETPOS_UNEX_NEXT, 'x', "getpos.unexplored.next" },
  74.      { NHKF_GETPOS_UNEX_PREV, 'X', "getpos.unexplored.prev" },
  75.      { NHKF_GETPOS_VALID_NEXT, 'z', "getpos.valid.next" },
  76.      { NHKF_GETPOS_VALID_PREV, 'Z', "getpos.valid.prev" },
  77.      { NHKF_GETPOS_INTERESTING_NEXT, 'a', "getpos.all.next" },
  78.      { NHKF_GETPOS_INTERESTING_PREV, 'A', "getpos.all.prev" },
  79.      { NHKF_GETPOS_HELP,      '?', "getpos.help" },
  80.      { NHKF_GETPOS_LIMITVIEW, '"', "getpos.filter" },
  81.      { NHKF_GETPOS_MOVESKIP,  '*', "getpos.moveskip" },
  82.      { NHKF_GETPOS_MENU,      '!', "getpos.menu" }
  83.  };
  84.  

bind_specialkey

  1.  boolean
  2.  bind_specialkey(key, command)
  3.  uchar key;
  4.  const char *command;
  5.  {
  6.      int i;
  7.      for (i = 0; i < SIZE(spkeys_binds); i++) {
  8.          if (!spkeys_binds[i].name || strcmp(command, spkeys_binds[i].name))
  9.              continue;
  10.          Cmd.spkeys[spkeys_binds[i].nhkf] = key;
  11.          return TRUE;
  12.      }
  13.      return FALSE;
  14.  }
  15.  

txt2key

  1.  /* returns a one-byte character from the text (it may massacre the txt
  2.   * buffer) */
  3.  char
  4.  txt2key(txt)
  5.  char *txt;
  6.  {
  7.      txt = trimspaces(txt);
  8.      if (!*txt)
  9.          return '\0';
  10.  
  11.      /* simple character */
  12.      if (!txt[1])
  13.          return txt[0];
  14.  
  15.      /* a few special entries */
  16.      if (!strcmp(txt, "<enter>"))
  17.          return '\n';
  18.      if (!strcmp(txt, "<space>"))
  19.          return ' ';
  20.      if (!strcmp(txt, "<esc>"))
  21.          return '\033';
  22.  
  23.      /* control and meta keys */
  24.      switch (*txt) {
  25.      case 'm': /* can be mx, Mx, m-x, M-x */
  26.      case 'M':
  27.          txt++;
  28.          if (*txt == '-' && txt[1])
  29.              txt++;
  30.          if (txt[1])
  31.              return '\0';
  32.          return M(*txt);
  33.      case 'c': /* can be cx, Cx, ^x, c-x, C-x, ^-x */
  34.      case 'C':
  35.      case '^':
  36.          txt++;
  37.          if (*txt == '-' && txt[1])
  38.              txt++;
  39.          if (txt[1])
  40.              return '\0';
  41.          return C(*txt);
  42.      }
  43.  
  44.      /* ascii codes: must be three-digit decimal */
  45.      if (*txt >= '0' && *txt <= '9') {
  46.          uchar key = 0;
  47.          int i;
  48.  
  49.          for (i = 0; i < 3; i++) {
  50.              if (txt[i] < '0' || txt[i] > '9')
  51.                  return '\0';
  52.              key = 10 * key + txt[i] - '0';
  53.          }
  54.          return key;
  55.      }
  56.  
  57.      return '\0';
  58.  }
  59.  

key2txt

  1.  /* returns the text for a one-byte encoding;
  2.   * must be shorter than a tab for proper formatting */
  3.  char *
  4.  key2txt(c, txt)
  5.  uchar c;
  6.  char *txt; /* sufficiently long buffer */
  7.  {
  8.      /* should probably switch to "SPC", "ESC", "RET"
  9.         since nethack's documentation uses ESC for <escape> */
  10.      if (c == ' ')
  11.          Sprintf(txt, "<space>");
  12.      else if (c == '\033')
  13.          Sprintf(txt, "<esc>");
  14.      else if (c == '\n')
  15.          Sprintf(txt, "<enter>");
  16.      else if (c == '\177')
  17.          Sprintf(txt, "<del>"); /* "<delete>" won't fit */
  18.      else
  19.          Strcpy(txt, visctrl((char) c));
  20.      return txt;
  21.  }
  22.  
  23.  

parseautocomplete

  1.  void
  2.  parseautocomplete(autocomplete, condition)
  3.  char *autocomplete;
  4.  boolean condition;
  5.  {
  6.      struct ext_func_tab *efp;
  7.      register char *autoc;
  8.  
  9.      /* break off first autocomplete from the rest; parse the rest */
  10.      if ((autoc = index(autocomplete, ',')) != 0
  11.          || (autoc = index(autocomplete, ':')) != 0) {
  12.          *autoc++ = '\0';
  13.          parseautocomplete(autoc, condition);
  14.      }
  15.  
  16.      /* strip leading and trailing white space */
  17.      autocomplete = trimspaces(autocomplete);
  18.  
  19.      if (!*autocomplete)
  20.          return;
  21.  
  22.      /* take off negation */
  23.      if (*autocomplete == '!') {
  24.          /* unlike most options, a leading "no" might actually be a part of
  25.           * the extended command.  Thus you have to use ! */
  26.          autocomplete++;
  27.          autocomplete = trimspaces(autocomplete);
  28.          condition = !condition;
  29.      }
  30.  
  31.      /* find and modify the extended command */
  32.      for (efp = extcmdlist; efp->ef_txt; efp++) {
  33.          if (!strcmp(autocomplete, efp->ef_txt)) {
  34.              if (condition)
  35.                  efp->flags |= AUTOCOMPLETE;
  36.              else
  37.                  efp->flags &= ~AUTOCOMPLETE;
  38.              return;
  39.          }
  40.      }
  41.  
  42.      /* not a real extended command */
  43.      raw_printf("Bad autocomplete: invalid extended command '%s'.",
  44.                 autocomplete);
  45.      wait_synch();
  46.  }
  47.  

reset_commands

  1.  /* called at startup and after number_pad is twiddled */
  2.  void
  3.  reset_commands(initial)
  4.  boolean initial;
  5.  {
  6.      static const char sdir[] = "hykulnjb><",
  7.                        sdir_swap_yz[] = "hzkulnjb><",
  8.                        ndir[] = "47896321><",
  9.                        ndir_phone_layout[] = "41236987><";
  10.      static const int ylist[] = {
  11.          'y', 'Y', C('y'), M('y'), M('Y'), M(C('y'))
  12.      };
  13.      static struct ext_func_tab *back_dir_cmd[8];
  14.      const struct ext_func_tab *cmdtmp;
  15.      boolean flagtemp;
  16.      int c, i, updated = 0;
  17.      static boolean backed_dir_cmd = FALSE;
  18.  
  19.      if (initial) {
  20.          updated = 1;
  21.          Cmd.num_pad = FALSE;
  22.          Cmd.pcHack_compat = Cmd.phone_layout = Cmd.swap_yz = FALSE;
  23.          for (i = 0; i < SIZE(spkeys_binds); i++)
  24.              Cmd.spkeys[spkeys_binds[i].nhkf] = spkeys_binds[i].key;
  25.          commands_init();
  26.      } else {
  27.  
  28.          if (backed_dir_cmd) {
  29.              for (i = 0; i < 8; i++) {
  30.                  Cmd.commands[(uchar) Cmd.dirchars[i]] = back_dir_cmd[i];
  31.              }
  32.          }
  33.  
  34.          /* basic num_pad */
  35.          flagtemp = iflags.num_pad;
  36.          if (flagtemp != Cmd.num_pad) {
  37.              Cmd.num_pad = flagtemp;
  38.              ++updated;
  39.          }
  40.          /* swap_yz mode (only applicable for !num_pad); intended for
  41.             QWERTZ keyboard used in Central Europe, particularly Germany */
  42.          flagtemp = (iflags.num_pad_mode & 1) ? !Cmd.num_pad : FALSE;
  43.          if (flagtemp != Cmd.swap_yz) {
  44.              Cmd.swap_yz = flagtemp;
  45.              ++updated;
  46.              /* Cmd.swap_yz has been toggled;
  47.                 perform the swap (or reverse previous one) */
  48.              for (i = 0; i < SIZE(ylist); i++) {
  49.                  c = ylist[i] & 0xff;
  50.                  cmdtmp = Cmd.commands[c];              /* tmp = [y] */
  51.                  Cmd.commands[c] = Cmd.commands[c + 1]; /* [y] = [z] */
  52.                  Cmd.commands[c + 1] = cmdtmp;          /* [z] = tmp */
  53.              }
  54.          }
  55.          /* MSDOS compatibility mode (only applicable for num_pad) */
  56.          flagtemp = (iflags.num_pad_mode & 1) ? Cmd.num_pad : FALSE;
  57.          if (flagtemp != Cmd.pcHack_compat) {
  58.              Cmd.pcHack_compat = flagtemp;
  59.              ++updated;
  60.              /* pcHack_compat has been toggled */
  61.              c = M('5') & 0xff;
  62.              cmdtmp = Cmd.commands['5'];
  63.              Cmd.commands['5'] = Cmd.commands[c];
  64.              Cmd.commands[c] = cmdtmp;
  65.              c = M('0') & 0xff;
  66.              Cmd.commands[c] = Cmd.pcHack_compat ? Cmd.commands['I'] : 0;
  67.          }
  68.          /* phone keypad layout (only applicable for num_pad) */
  69.          flagtemp = (iflags.num_pad_mode & 2) ? Cmd.num_pad : FALSE;
  70.          if (flagtemp != Cmd.phone_layout) {
  71.              Cmd.phone_layout = flagtemp;
  72.              ++updated;
  73.              /* phone_layout has been toggled */
  74.              for (i = 0; i < 3; i++) {
  75.                  c = '1' + i;             /* 1,2,3 <-> 7,8,9 */
  76.                  cmdtmp = Cmd.commands[c];              /* tmp = [1] */
  77.                  Cmd.commands[c] = Cmd.commands[c + 6]; /* [1] = [7] */
  78.                  Cmd.commands[c + 6] = cmdtmp;          /* [7] = tmp */
  79.                  c = (M('1') & 0xff) + i; /* M-1,M-2,M-3 <-> M-7,M-8,M-9 */
  80.                  cmdtmp = Cmd.commands[c];              /* tmp = [M-1] */
  81.                  Cmd.commands[c] = Cmd.commands[c + 6]; /* [M-1] = [M-7] */
  82.                  Cmd.commands[c + 6] = cmdtmp;          /* [M-7] = tmp */
  83.              }
  84.          }
  85.      } /*?initial*/
  86.  
  87.      if (updated)
  88.          Cmd.serialno++;
  89.      Cmd.dirchars = !Cmd.num_pad
  90.                         ? (!Cmd.swap_yz ? sdir : sdir_swap_yz)
  91.                         : (!Cmd.phone_layout ? ndir : ndir_phone_layout);
  92.      Cmd.alphadirchars = !Cmd.num_pad ? Cmd.dirchars : sdir;
  93.  
  94.      Cmd.move_W = Cmd.dirchars[0];
  95.      Cmd.move_NW = Cmd.dirchars[1];
  96.      Cmd.move_N = Cmd.dirchars[2];
  97.      Cmd.move_NE = Cmd.dirchars[3];
  98.      Cmd.move_E = Cmd.dirchars[4];
  99.      Cmd.move_SE = Cmd.dirchars[5];
  100.      Cmd.move_S = Cmd.dirchars[6];
  101.      Cmd.move_SW = Cmd.dirchars[7];
  102.  
  103.      if (!initial) {
  104.          for (i = 0; i < 8; i++) {
  105.              back_dir_cmd[i] =
  106.                  (struct ext_func_tab *) Cmd.commands[(uchar) Cmd.dirchars[i]];
  107.              Cmd.commands[(uchar) Cmd.dirchars[i]] = (struct ext_func_tab *) 0;
  108.          }
  109.          backed_dir_cmd = TRUE;
  110.          for (i = 0; i < 8; i++)
  111.              (void) bind_key(Cmd.dirchars[i], "nothing");
  112.      }
  113.  }
  114.  

accept_menu_prefix

  1.  /* non-movement commands which accept 'm' prefix to request menu operation */
  2.  STATIC_OVL boolean
  3.  accept_menu_prefix(cmd_func)
  4.  int NDECL((*cmd_func));
  5.  {
  6.      if (cmd_func == dopickup || cmd_func == dotip
  7.          /* eat, #offer, and apply tinning-kit all use floorfood() to pick
  8.             an item on floor or in invent; 'm' skips picking from floor
  9.             (ie, inventory only) rather than request use of menu operation */
  10.          || cmd_func == doeat || cmd_func == dosacrifice || cmd_func == doapply
  11.          /* 'm' for removing saddle from adjacent monster without checking
  12.             for containers at <u.ux,u.uy> */
  13.          || cmd_func == doloot
  14.          /* travel: pop up a menu of interesting targets in view */
  15.          || cmd_func == dotravel
  16.          /* wizard mode ^V */
  17.          || cmd_func == wiz_level_tele
  18.          /* 'm' prefix allowed for some extended commands */
  19.          || cmd_func == doextcmd || cmd_func == doextlist)
  20.          return TRUE;
  21.      return FALSE;
  22.  }
  23.  

ch2spkeys

  1.  int
  2.  ch2spkeys(c, start, end)
  3.  char c;
  4.  int start,end;
  5.  {
  6.      int i;
  7.  
  8.      for (i = start; i <= end; i++)
  9.          if (Cmd.spkeys[i] == c)
  10.              return i;
  11.      return NHKF_ESC;
  12.  }
  13.  

rhack

  1.  void
  2.  rhack(cmd)
  3.  register char *cmd;
  4.  {
  5.      int spkey;
  6.      boolean do_walk, do_rush, prefix_seen, bad_command,
  7.          firsttime = (cmd == 0);
  8.  
  9.      iflags.menu_requested = FALSE;
  10.  #ifdef SAFERHANGUP
  11.      if (program_state.done_hup)
  12.          end_of_input();
  13.  #endif
  14.      if (firsttime) {
  15.          context.nopick = 0;
  16.          cmd = parse();
  17.      }
  18.      if (*cmd == Cmd.spkeys[NHKF_ESC]) {
  19.          context.move = FALSE;
  20.          return;
  21.      }
  22.      if (*cmd == DOAGAIN && !in_doagain && saveq[0]) {
  23.          in_doagain = TRUE;
  24.          stail = 0;
  25.          rhack((char *) 0); /* read and execute command */
  26.          in_doagain = FALSE;
  27.          return;
  28.      }
  29.      /* Special case of *cmd == ' ' handled better below */
  30.      if (!*cmd || *cmd == (char) 0377) {
  31.          nhbell();
  32.          context.move = FALSE;
  33.          return; /* probably we just had an interrupt */
  34.      }
  35.  
  36.      /* handle most movement commands */
  37.      do_walk = do_rush = prefix_seen = FALSE;
  38.      context.travel = context.travel1 = 0;
  39.      spkey = ch2spkeys(*cmd, NHKF_RUN, NHKF_CLICKLOOK);
  40.  
  41.      switch (spkey) {
  42.      case NHKF_RUSH:
  43.          if (movecmd(cmd[1])) {
  44.              context.run = 2;
  45.              do_rush = TRUE;
  46.          } else
  47.              prefix_seen = TRUE;
  48.          break;
  49.      case NHKF_RUN2:
  50.          if (!Cmd.num_pad)
  51.              break;
  52.          /*FALLTHRU*/
  53.      case NHKF_RUN:
  54.          if (movecmd(lowc(cmd[1]))) {
  55.              context.run = 3;
  56.              do_rush = TRUE;
  57.          } else
  58.              prefix_seen = TRUE;
  59.          break;
  60.      case NHKF_FIGHT2:
  61.          if (!Cmd.num_pad)
  62.              break;
  63.          /*FALLTHRU*/
  64.      /* Effects of movement commands and invisible monsters:
  65.       * m: always move onto space (even if 'I' remembered)
  66.       * F: always attack space (even if 'I' not remembered)
  67.       * normal movement: attack if 'I', move otherwise.
  68.       */
  69.      case NHKF_FIGHT:
  70.          if (movecmd(cmd[1])) {
  71.              context.forcefight = 1;
  72.              do_walk = TRUE;
  73.          } else
  74.              prefix_seen = TRUE;
  75.          break;
  76.      case NHKF_NOPICKUP:
  77.          if (movecmd(cmd[1]) || u.dz) {
  78.              context.run = 0;
  79.              context.nopick = 1;
  80.              if (!u.dz)
  81.                  do_walk = TRUE;
  82.              else
  83.                  cmd[0] = cmd[1]; /* "m<" or "m>" */
  84.          } else
  85.              prefix_seen = TRUE;
  86.          break;
  87.      case NHKF_RUN_NOPICKUP:
  88.          if (movecmd(lowc(cmd[1]))) {
  89.              context.run = 1;
  90.              context.nopick = 1;
  91.              do_rush = TRUE;
  92.          } else
  93.              prefix_seen = TRUE;
  94.          break;
  95.      case NHKF_DOINV:
  96.          if (!Cmd.num_pad)
  97.              break;
  98.          (void) ddoinv(); /* a convenience borrowed from the PC */
  99.          context.move = FALSE;
  100.          multi = 0;
  101.          return;
  102.      case NHKF_CLICKLOOK:
  103.          if (iflags.clicklook) {
  104.              context.move = FALSE;
  105.              do_look(2, &clicklook_cc);
  106.          }
  107.          return;
  108.      case NHKF_TRAVEL:
  109.          if (flags.travelcmd) {
  110.              context.travel = 1;
  111.              context.travel1 = 1;
  112.              context.run = 8;
  113.              context.nopick = 1;
  114.              do_rush = TRUE;
  115.              break;
  116.          }
  117.          /*FALLTHRU*/
  118.      default:
  119.          if (movecmd(*cmd)) { /* ordinary movement */
  120.              context.run = 0; /* only matters here if it was 8 */
  121.              do_walk = TRUE;
  122.          } else if (movecmd(Cmd.num_pad ? unmeta(*cmd) : lowc(*cmd))) {
  123.              context.run = 1;
  124.              do_rush = TRUE;
  125.          } else if (movecmd(unctrl(*cmd))) {
  126.              context.run = 3;
  127.              do_rush = TRUE;
  128.          }
  129.          break;
  130.      }
  131.  
  132.      /* some special prefix handling */
  133.      /* overload 'm' prefix to mean "request a menu" */
  134.      if (prefix_seen && cmd[0] == Cmd.spkeys[NHKF_REQMENU]) {
  135.          /* (for func_tab cast, see below) */
  136.          const struct ext_func_tab *ft = Cmd.commands[cmd[1] & 0xff];
  137.          int NDECL((*func)) = ft ? ((struct ext_func_tab *) ft)->ef_funct : 0;
  138.  
  139.          if (func && accept_menu_prefix(func)) {
  140.              iflags.menu_requested = TRUE;
  141.              ++cmd;
  142.          }
  143.      }
  144.  
  145.      if ((do_walk || do_rush) && !context.travel && !dxdy_moveok()) {
  146.          /* trying to move diagonally as a grid bug;
  147.             this used to be treated by movecmd() as not being
  148.             a movement attempt, but that didn't provide for any
  149.             feedback and led to strangeness if the key pressed
  150.             ('u' in particular) was overloaded for num_pad use */
  151.          You_cant("get there from here...");
  152.          context.run = 0;
  153.          context.nopick = context.forcefight = FALSE;
  154.          context.move = context.mv = FALSE;
  155.          multi = 0;
  156.          return;
  157.      }
  158.  
  159.      if (do_walk) {
  160.          if (multi)
  161.              context.mv = TRUE;
  162.          domove();
  163.          context.forcefight = 0;
  164.          return;
  165.      } else if (do_rush) {
  166.          if (firsttime) {
  167.              if (!multi)
  168.                  multi = max(COLNO, ROWNO);
  169.              u.last_str_turn = 0;
  170.          }
  171.          context.mv = TRUE;
  172.          domove();
  173.          return;
  174.      } else if (prefix_seen && cmd[1] == Cmd.spkeys[NHKF_ESC]) {
  175.          /* <prefix><escape> */
  176.          /* don't report "unknown command" for change of heart... */
  177.          bad_command = FALSE;
  178.      } else if (*cmd == ' ' && !flags.rest_on_space) {
  179.          bad_command = TRUE; /* skip cmdlist[] loop */
  180.  
  181.      /* handle all other commands */
  182.      } else {
  183.          register const struct ext_func_tab *tlist;
  184.          int res, NDECL((*func));
  185.  
  186.          /* current - use *cmd to directly index cmdlist array */
  187.          if ((tlist = Cmd.commands[*cmd & 0xff]) != 0) {
  188.              if (!wizard && (tlist->flags & WIZMODECMD)) {
  189.                  You_cant("do that!");
  190.                  res = 0;
  191.              } else if (u.uburied && !(tlist->flags & IFBURIED)) {
  192.                  You_cant("do that while you are buried!");
  193.                  res = 0;
  194.              } else {
  195.                  /* we discard 'const' because some compilers seem to have
  196.                     trouble with the pointer passed to set_occupation() */
  197.                  func = ((struct ext_func_tab *) tlist)->ef_funct;
  198.                  if (tlist->f_text && !occupation && multi)
  199.                      set_occupation(func, tlist->f_text, multi);
  200.                  res = (*func)(); /* perform the command */
  201.              }
  202.              if (!res) {
  203.                  context.move = FALSE;
  204.                  multi = 0;
  205.              }
  206.              return;
  207.          }
  208.          /* if we reach here, cmd wasn't found in cmdlist[] */
  209.          bad_command = TRUE;
  210.      }
  211.  
  212.      if (bad_command) {
  213.          char expcmd[20]; /* we expect 'cmd' to point to 1 or 2 chars */
  214.          char c, c1 = cmd[1];
  215.  
  216.          expcmd[0] = '\0';
  217.          while ((c = *cmd++) != '\0')
  218.              Strcat(expcmd, visctrl(c)); /* add 1..4 chars plus terminator */
  219.  
  220.          if (!prefix_seen || !help_dir(c1, spkey, "Invalid direction key!"))
  221.              Norep("Unknown command '%s'.", expcmd);
  222.      }
  223.      /* didn't move */
  224.      context.move = FALSE;
  225.      multi = 0;
  226.      return;
  227.  }
  228.  

xytod

  1.  /* convert an x,y pair into a direction code */
  2.  int
  3.  xytod(x, y)
  4.  schar x, y;
  5.  {
  6.      register int dd;
  7.  
  8.      for (dd = 0; dd < 8; dd++)
  9.          if (x == xdir[dd] && y == ydir[dd])
  10.              return dd;
  11.      return -1;
  12.  }
  13.  

dtoxy

  1.  /* convert a direction code into an x,y pair */
  2.  void
  3.  dtoxy(cc, dd)
  4.  coord *cc;
  5.  register int dd;
  6.  {
  7.      cc->x = xdir[dd];
  8.      cc->y = ydir[dd];
  9.      return;
  10.  }
  11.  

movecmd

  1.  /* also sets u.dz, but returns false for <> */
  2.  int
  3.  movecmd(sym)
  4.  char sym;
  5.  {
  6.      register const char *dp = index(Cmd.dirchars, sym);
  7.  
  8.      u.dz = 0;
  9.      if (!dp || !*dp)
  10.          return 0;
  11.      u.dx = xdir[dp - Cmd.dirchars];
  12.      u.dy = ydir[dp - Cmd.dirchars];
  13.      u.dz = zdir[dp - Cmd.dirchars];
  14.  #if 0 /* now handled elsewhere */
  15.      if (u.dx && u.dy && NODIAG(u.umonnum)) {
  16.          u.dx = u.dy = 0;
  17.          return 0;
  18.      }
  19.  #endif
  20.      return !u.dz;
  21.  }
  22.  

dxdy_moveok

  1.  /* grid bug handling which used to be in movecmd() */
  2.  int
  3.  dxdy_moveok()
  4.  {
  5.      if (u.dx && u.dy && NODIAG(u.umonnum))
  6.          u.dx = u.dy = 0;
  7.      return u.dx || u.dy;
  8.  }
  9.  

redraw_cmd

  1.  /* decide whether a character (user input keystroke) requests screen repaint */
  2.  boolean
  3.  redraw_cmd(c)
  4.  char c;
  5.  {
  6.      return (boolean) (c == Cmd.spkeys[NHKF_REDRAW]
  7.                        || (Cmd.num_pad && c == Cmd.spkeys[NHKF_REDRAW2]));
  8.  }
  9.  

prefix_cmd

  1.  boolean
  2.  prefix_cmd(c)
  3.  char c;
  4.  {
  5.      return (c == Cmd.spkeys[NHKF_RUSH]
  6.              || c == Cmd.spkeys[NHKF_RUN]
  7.              || c == Cmd.spkeys[NHKF_NOPICKUP]
  8.              || c == Cmd.spkeys[NHKF_RUN_NOPICKUP]
  9.              || c == Cmd.spkeys[NHKF_FIGHT]
  10.              || (Cmd.num_pad && (c == Cmd.spkeys[NHKF_RUN2]
  11.                                  || c == Cmd.spkeys[NHKF_FIGHT2])));
  12.  }
  13.  

get_adjacent_loc

  1.  /*
  2.   * uses getdir() but unlike getdir() it specifically
  3.   * produces coordinates using the direction from getdir()
  4.   * and verifies that those coordinates are ok.
  5.   *
  6.   * If the call to getdir() returns 0, Never_mind is displayed.
  7.   * If the resulting coordinates are not okay, emsg is displayed.
  8.   *
  9.   * Returns non-zero if coordinates in cc are valid.
  10.   */
  11.  int
  12.  get_adjacent_loc(prompt, emsg, x, y, cc)
  13.  const char *prompt, *emsg;
  14.  xchar x, y;
  15.  coord *cc;
  16.  {
  17.      xchar new_x, new_y;
  18.      if (!getdir(prompt)) {
  19.          pline1(Never_mind);
  20.          return 0;
  21.      }
  22.      new_x = x + u.dx;
  23.      new_y = y + u.dy;
  24.      if (cc && isok(new_x, new_y)) {
  25.          cc->x = new_x;
  26.          cc->y = new_y;
  27.      } else {
  28.          if (emsg)
  29.              pline1(emsg);
  30.          return 0;
  31.      }
  32.      return 1;
  33.  }
  34.  

getdir

  1.  int
  2.  getdir(s)
  3.  const char *s;
  4.  {
  5.      char dirsym;
  6.      int is_mov;
  7.  
  8.  retry:
  9.      if (in_doagain || *readchar_queue)
  10.          dirsym = readchar();
  11.      else
  12.          dirsym = yn_function((s && *s != '^') ? s : "In what direction?",
  13.                               (char *) 0, '\0');
  14.      /* remove the prompt string so caller won't have to */
  15.      clear_nhwindow(WIN_MESSAGE);
  16.  
  17.      if (redraw_cmd(dirsym)) { /* ^R */
  18.          docrt();              /* redraw */
  19.          goto retry;
  20.      }
  21.      savech(dirsym);
  22.  
  23.      if (dirsym == Cmd.spkeys[NHKF_GETDIR_SELF]
  24.          || dirsym == Cmd.spkeys[NHKF_GETDIR_SELF2]) {
  25.          u.dx = u.dy = u.dz = 0;
  26.      } else if (!(is_mov = movecmd(dirsym)) && !u.dz) {
  27.          boolean did_help = FALSE, help_requested;
  28.  
  29.          if (!index(quitchars, dirsym)) {
  30.              help_requested = (dirsym == Cmd.spkeys[NHKF_GETDIR_HELP]);
  31.              if (help_requested || iflags.cmdassist) {
  32.                  did_help = help_dir((s && *s == '^') ? dirsym : '\0',
  33.                                      NHKF_ESC,
  34.                                      help_requested ? (const char *) 0
  35.                                                    : "Invalid direction key!");
  36.                  if (help_requested)
  37.                      goto retry;
  38.              }
  39.              if (!did_help)
  40.                  pline("What a strange direction!");
  41.          }
  42.          return 0;
  43.      } else if (is_mov && !dxdy_moveok()) {
  44.          You_cant("orient yourself that direction.");
  45.          return 0;
  46.      }
  47.      if (!u.dz && (Stunned || (Confusion && !rn2(5))))
  48.          confdir();
  49.      return 1;
  50.  }
  51.  

show_direction_keys

  1.  STATIC_OVL void
  2.  show_direction_keys(win, centerchar, nodiag)
  3.  winid win; /* should specify a window which is using a fixed-width font... */
  4.  char centerchar; /* '.' or '@' or ' ' */
  5.  boolean nodiag;
  6.  {
  7.      char buf[BUFSZ];
  8.  
  9.      if (!centerchar)
  10.          centerchar = ' ';
  11.  
  12.      if (nodiag) {
  13.          Sprintf(buf, "             %c   ", Cmd.move_N);
  14.          putstr(win, 0, buf);
  15.          putstr(win, 0, "             |   ");
  16.          Sprintf(buf, "          %c- %c -%c",
  17.                  Cmd.move_W, centerchar, Cmd.move_E);
  18.          putstr(win, 0, buf);
  19.          putstr(win, 0, "             |   ");
  20.          Sprintf(buf, "             %c   ", Cmd.move_S);
  21.          putstr(win, 0, buf);
  22.      } else {
  23.          Sprintf(buf, "          %c  %c  %c",
  24.                  Cmd.move_NW, Cmd.move_N, Cmd.move_NE);
  25.          putstr(win, 0, buf);
  26.          putstr(win, 0, "           \\ | / ");
  27.          Sprintf(buf, "          %c- %c -%c",
  28.                  Cmd.move_W, centerchar, Cmd.move_E);
  29.          putstr(win, 0, buf);
  30.          putstr(win, 0, "           / | \\ ");
  31.          Sprintf(buf, "          %c  %c  %c",
  32.                  Cmd.move_SW, Cmd.move_S, Cmd.move_SE);
  33.          putstr(win, 0, buf);
  34.      };
  35.  }
  36.  

help_dir

  1.  /* explain choices if player has asked for getdir() help or has given
  2.     an invalid direction after a prefix key ('F', 'g', 'm', &c), which
  3.     might be bogus but could be up, down, or self when not applicable */
  4.  STATIC_OVL boolean