Source:NetHack 3.6.0/src/end.c

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

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

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

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

Top of file[edit]

  1.  /* NetHack 3.6	end.c	$NHDT-Date: 1448241780 2015/11/23 01:23:00 $  $NHDT-Branch: master $:$NHDT-Revision: 1.108 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #define NEED_VARARGS /* comment line for pre-compiled headers */
  6.  
  7.  #include "hack.h"
  8.  #include "lev.h"
  9.  #ifndef NO_SIGNAL
  10.  #include <signal.h>
  11.  #endif
  12.  #include <ctype.h>
  13.  #include <limits.h>
  14.  #include "dlb.h"
  15.  
  16.  /* add b to long a, convert wraparound to max value */
  17.  #define nowrap_add(a, b) (a = ((a + b) < 0 ? LONG_MAX : (a + b)))
  18.  
  19.  /* these probably ought to be generated by makedefs, like LAST_GEM */
  20.  #define FIRST_GEM DILITHIUM_CRYSTAL
  21.  #define FIRST_AMULET AMULET_OF_ESP
  22.  #define LAST_AMULET AMULET_OF_YENDOR
  23.  
  24.  struct valuable_data {
  25.      long count;
  26.      int typ;
  27.  };
  28.  
  29.  static struct valuable_data
  30.      gems[LAST_GEM + 1 - FIRST_GEM + 1], /* 1 extra for glass */
  31.      amulets[LAST_AMULET + 1 - FIRST_AMULET];
  32.  
  33.  static struct val_list {
  34.      struct valuable_data *list;
  35.      int size;
  36.  } valuables[] = { { gems, sizeof gems / sizeof *gems },
  37.                    { amulets, sizeof amulets / sizeof *amulets },
  38.                    { 0, 0 } };
  39.  
  40.  #ifndef NO_SIGNAL
  41.  STATIC_PTR void FDECL(done_intr, (int));
  42.  #if defined(UNIX) || defined(VMS) || defined(__EMX__)
  43.  static void FDECL(done_hangup, (int));
  44.  #endif
  45.  #endif
  46.  STATIC_DCL void FDECL(disclose, (int, BOOLEAN_P));
  47.  STATIC_DCL void FDECL(get_valuables, (struct obj *));
  48.  STATIC_DCL void FDECL(sort_valuables, (struct valuable_data *, int));
  49.  STATIC_DCL void FDECL(artifact_score, (struct obj *, BOOLEAN_P, winid));
  50.  STATIC_DCL void FDECL(really_done, (int)) NORETURN;
  51.  STATIC_DCL boolean FDECL(odds_and_ends, (struct obj *, int));
  52.  STATIC_DCL void FDECL(savelife, (int));
  53.  STATIC_DCL void FDECL(list_vanquished, (CHAR_P, BOOLEAN_P));
  54.  STATIC_DCL void FDECL(list_genocided, (CHAR_P, BOOLEAN_P));
  55.  STATIC_DCL boolean FDECL(should_query_disclose_option, (int, char *));
  56.  STATIC_DCL int NDECL(num_extinct);
  57.  
  58.  #if defined(__BEOS__) || defined(MICRO) || defined(WIN32) || defined(OS2)
  59.  extern void FDECL(nethack_exit, (int));
  60.  #else
  61.  #define nethack_exit exit
  62.  #endif
  63.  
  64.  #define done_stopprint program_state.stopprint
  65.  
  66.  #ifndef PANICTRACE
  67.  #define NH_abort NH_abort_
  68.  #endif
  69.  
  70.  #ifdef AMIGA
  71.  #define NH_abort_() Abort(0)
  72.  #else
  73.  #ifdef SYSV
  74.  #define NH_abort_() (void) abort()
  75.  #else
  76.  #ifdef WIN32
  77.  #define NH_abort_() win32_abort()
  78.  #else
  79.  #define NH_abort_() abort()
  80.  #endif
  81.  #endif /* !SYSV */
  82.  #endif /* !AMIGA */
  83.  
  84.  #ifdef PANICTRACE
  85.  #include <errno.h>
  86.  #ifdef PANICTRACE_LIBC
  87.  #include <execinfo.h>
  88.  #endif
  89.  
  90.  /* What do we try and in what order?  Tradeoffs:
  91.   * libc: +no external programs required
  92.   *        -requires newish libc/glibc
  93.   *        -requires -rdynamic
  94.   * gdb:   +gives more detailed information
  95.   *        +works on more OS versions
  96.   *        -requires -g, which may preclude -O on some compilers
  97.   */
  98.  #ifdef SYSCF
  99.  #define SYSOPT_PANICTRACE_GDB sysopt.panictrace_gdb
  100.  #ifdef PANICTRACE_LIBC
  101.  #define SYSOPT_PANICTRACE_LIBC sysopt.panictrace_libc
  102.  #else
  103.  #define SYSOPT_PANICTRACE_LIBC 0
  104.  #endif
  105.  #else
  106.  #define SYSOPT_PANICTRACE_GDB (nh_getenv("NETHACK_USE_GDB") == 0 ? 0 : 2)
  107.  #ifdef PANICTRACE_LIBC
  108.  #define SYSOPT_PANICTRACE_LIBC 1
  109.  #else
  110.  #define SYSOPT_PANICTRACE_LIBC 0
  111.  #endif
  112.  #endif
  113.  
  114.  static void NDECL(NH_abort);
  115.  #ifndef NO_SIGNAL
  116.  static void FDECL(panictrace_handler, (int));
  117.  #endif
  118.  static boolean NDECL(NH_panictrace_libc);
  119.  static boolean NDECL(NH_panictrace_gdb);
  120.  

panictrace_handler[edit]

  1.  #ifndef NO_SIGNAL
  2.  /*ARGSUSED*/
  3.  void panictrace_handler(
  4.      sig_unused) /* called as signal() handler, so sent at least one arg */
  5.  int sig_unused UNUSED;
  6.  {
  7.  #define SIG_MSG "\nSignal received.\n"
  8.      (void) write(2, SIG_MSG, sizeof(SIG_MSG) - 1);
  9.      NH_abort();
  10.  }
  11.  

panictrace_setsignals[edit]

  1.  void
  2.  panictrace_setsignals(set)
  3.  boolean set;
  4.  {
  5.  #define SETSIGNAL(sig) \
  6.      (void) signal(sig, set ? (SIG_RET_TYPE) panictrace_handler : SIG_DFL);
  7.  #ifdef SIGILL
  8.      SETSIGNAL(SIGILL);
  9.  #endif
  10.  #ifdef SIGTRAP
  11.      SETSIGNAL(SIGTRAP);
  12.  #endif
  13.  #ifdef SIGIOT
  14.      SETSIGNAL(SIGIOT);
  15.  #endif
  16.  #ifdef SIGBUS
  17.      SETSIGNAL(SIGBUS);
  18.  #endif
  19.  #ifdef SIGFPE
  20.      SETSIGNAL(SIGFPE);
  21.  #endif
  22.  #ifdef SIGSEGV
  23.      SETSIGNAL(SIGSEGV);
  24.  #endif
  25.  #ifdef SIGSTKFLT
  26.      SETSIGNAL(SIGSTKFLT);
  27.  #endif
  28.  #ifdef SIGSYS
  29.      SETSIGNAL(SIGSYS);
  30.  #endif
  31.  #ifdef SIGEMT
  32.      SETSIGNAL(SIGEMT);
  33.  #endif
  34.  #undef SETSIGNAL
  35.  }
  36.  #endif /* NO_SIGNAL */
  37.  

NH_abort[edit]

  1.  static void
  2.  NH_abort()
  3.  {
  4.      int gdb_prio = SYSOPT_PANICTRACE_GDB;
  5.      int libc_prio = SYSOPT_PANICTRACE_LIBC;
  6.      static boolean aborting = FALSE;
  7.  
  8.      if (aborting)
  9.          return;
  10.      aborting = TRUE;
  11.  
  12.  #ifndef VMS
  13.      if (gdb_prio == libc_prio && gdb_prio > 0)
  14.          gdb_prio++;
  15.  
  16.      if (gdb_prio > libc_prio) {
  17.          NH_panictrace_gdb() || (libc_prio && NH_panictrace_libc());
  18.      } else {
  19.          NH_panictrace_libc() || (gdb_prio && NH_panictrace_gdb());
  20.      }
  21.  
  22.  #else /* VMS */
  23.      /* overload otherwise unused priority for debug mode: 1 = show
  24.         traceback and exit; 2 = show traceback and stay in debugger */
  25.      /* if (wizard && gdb_prio == 1) gdb_prio = 2; */
  26.      vms_traceback(gdb_prio);
  27.      (void) libc_prio; /* half-hearted attempt at lint suppression */
  28.  
  29.  #endif /* ?VMS */
  30.  
  31.  #ifndef NO_SIGNAL
  32.      panictrace_setsignals(FALSE);
  33.  #endif
  34.      NH_abort_();
  35.  }
  36.  

NH_panictrace_libc[edit]

  1.  static boolean
  2.  NH_panictrace_libc()
  3.  {
  4.  #ifdef PANICTRACE_LIBC
  5.      void *bt[20];
  6.      size_t count, x;
  7.      char **info;
  8.  
  9.      raw_print("Generating more information you may report:\n");
  10.      count = backtrace(bt, SIZE(bt));
  11.      info = backtrace_symbols(bt, count);
  12.      for (x = 0; x < count; x++) {
  13.          raw_printf("[%lu] %s", (unsigned long) x, info[x]);
  14.      }
  15.      /* free(info);   -- Don't risk it. */
  16.      return TRUE;
  17.  #else
  18.      return FALSE;
  19.  #endif /* !PANICTRACE_LIBC */
  20.  }
  21.  

NH_panictrace_gdb[edit]

  1.  /*
  2.   *   fooPATH  file system path for foo
  3.   *   fooVAR   (possibly const) variable containing fooPATH
  4.   */
  5.  #ifdef PANICTRACE_GDB
  6.  #ifdef SYSCF
  7.  #define GDBVAR sysopt.gdbpath
  8.  #define GREPVAR sysopt.greppath
  9.  #else /* SYSCF */
  10.  #define GDBVAR GDBPATH
  11.  #define GREPVAR GREPPATH
  12.  #endif /* SYSCF */
  13.  #endif /* PANICTRACE_GDB */
  14.  
  15.  static boolean
  16.  NH_panictrace_gdb()
  17.  {
  18.  #ifdef PANICTRACE_GDB
  19.      /* A (more) generic method to get a stack trace - invoke
  20.       * gdb on ourself. */
  21.      char *gdbpath = GDBVAR;
  22.      char *greppath = GREPVAR;
  23.      char buf[BUFSZ];
  24.      FILE *gdb;
  25.  
  26.      if (gdbpath == NULL || gdbpath[0] == 0)
  27.          return FALSE;
  28.      if (greppath == NULL || greppath[0] == 0)
  29.          return FALSE;
  30.  
  31.      sprintf(buf, "%s -n -q %s %d 2>&1 | %s '^#'", gdbpath, ARGV0, getpid(),
  32.              greppath);
  33.      gdb = popen(buf, "w");
  34.      if (gdb) {
  35.          raw_print("Generating more information you may report:\n");
  36.          fprintf(gdb, "bt\nquit\ny");
  37.          fflush(gdb);
  38.          sleep(4); /* ugly */
  39.          pclose(gdb);
  40.          return TRUE;
  41.      } else {
  42.          return FALSE;
  43.      }
  44.  #else
  45.      return FALSE;
  46.  #endif /* !PANICTRACE_GDB */
  47.  }
  48.  #endif /* PANICTRACE */
  49.  

Death/end strings[edit]

  1.  /*
  2.   * The order of these needs to match the macros in hack.h.
  3.   */
  4.  static NEARDATA const char *deaths[] = {
  5.      /* the array of death */
  6.      "died", "choked", "poisoned", "starvation", "drowning", "burning",
  7.      "dissolving under the heat and pressure", "crushed", "turned to stone",
  8.      "turned into slime", "genocided", "panic", "trickery", "quit",
  9.      "escaped", "ascended"
  10.  };
  11.  
  12.  static NEARDATA const char *ends[] = {
  13.      /* "when you %s" */
  14.      "died", "choked", "were poisoned",
  15.      "starved", "drowned", "burned",
  16.      "dissolved in the lava",
  17.      "were crushed", "turned to stone",
  18.      "turned into slime", "were genocided",
  19.      "panicked", "were tricked", "quit",
  20.      "escaped", "ascended"
  21.  };
  22.  
  23.  static boolean Schroedingers_cat = FALSE;
  24.  

done1[edit]

  1.  /*ARGSUSED*/
  2.  void
  3.  done1(sig_unused) /* called as signal() handler, so sent at least one arg */
  4.  int sig_unused UNUSED;
  5.  {
  6.  #ifndef NO_SIGNAL
  7.      (void) signal(SIGINT, SIG_IGN);
  8.  #endif
  9.      if (flags.ignintr) {
  10.  #ifndef NO_SIGNAL
  11.          (void) signal(SIGINT, (SIG_RET_TYPE) done1);
  12.  #endif
  13.          clear_nhwindow(WIN_MESSAGE);
  14.          curs_on_u();
  15.          wait_synch();
  16.          if (multi > 0)
  17.              nomul(0);
  18.      } else {
  19.          (void) done2();
  20.      }
  21.  }
  22.  

done2[edit]

  1.  /* "#quit" command or keyboard interrupt */
  2.  int
  3.  done2()
  4.  {
  5.      if (!paranoid_query(ParanoidQuit, "Really quit?")) {
  6.  #ifndef NO_SIGNAL
  7.          (void) signal(SIGINT, (SIG_RET_TYPE) done1);
  8.  #endif
  9.          clear_nhwindow(WIN_MESSAGE);
  10.          curs_on_u();
  11.          wait_synch();
  12.          if (multi > 0)
  13.              nomul(0);
  14.          if (multi == 0) {
  15.              u.uinvulnerable = FALSE; /* avoid ctrl-C bug -dlc */
  16.              u.usleep = 0;
  17.          }
  18.          return 0;
  19.      }
  20.  #if (defined(UNIX) || defined(VMS) || defined(LATTICE))
  21.      if (wizard) {
  22.          int c;
  23.  #ifdef VMS
  24.          extern int debuggable; /* sys/vms/vmsmisc.c, vmsunix.c */
  25.  
  26.          c = !debuggable ? 'n' : ynq("Enter debugger?");
  27.  #else
  28.  #ifdef LATTICE
  29.          c = ynq("Create SnapShot?");
  30.  #else
  31.          c = ynq("Dump core?");
  32.  #endif
  33.  #endif
  34.          if (c == 'y') {
  35.  #ifndef NO_SIGNAL
  36.              (void) signal(SIGINT, (SIG_RET_TYPE) done1);
  37.  #endif
  38.              exit_nhwindows((char *) 0);
  39.              NH_abort();
  40.          } else if (c == 'q')
  41.              done_stopprint++;
  42.      }
  43.  #endif
  44.  #ifndef LINT
  45.      done(QUIT);
  46.  #endif
  47.      return 0;
  48.  }
  49.  

done_intr[edit]

  1.  #ifndef NO_SIGNAL
  2.  /*ARGSUSED*/
  3.  STATIC_PTR void
  4.  done_intr(sig_unused) /* called as signal() handler, so sent at least 1 arg */
  5.  int sig_unused UNUSED;
  6.  {
  7.      done_stopprint++;
  8.      (void) signal(SIGINT, SIG_IGN);
  9.  #if defined(UNIX) || defined(VMS)
  10.      (void) signal(SIGQUIT, SIG_IGN);
  11.  #endif
  12.      return;
  13.  }
  14.  

done_hangup[edit]

  1.  #if defined(UNIX) || defined(VMS) || defined(__EMX__)
  2.  /* signal() handler */
  3.  static void
  4.  done_hangup(sig)
  5.  int sig;
  6.  {
  7.      program_state.done_hup++;
  8.      sethanguphandler((void FDECL((*), (int) )) SIG_IGN);
  9.      done_intr(sig);
  10.      return;
  11.  }
  12.  #endif
  13.  #endif /* NO_SIGNAL */
  14.  

done_in_by[edit]

  1.  void
  2.  done_in_by(mtmp, how)
  3.  struct monst *mtmp;
  4.  int how;
  5.  {
  6.      char buf[BUFSZ];
  7.      struct permonst *mptr = mtmp->data,
  8.                      *champtr = ((mtmp->cham >= LOW_PM)
  9.                                     ? &mons[mtmp->cham]
  10.                                     : mptr);
  11.      boolean distorted = (boolean) (Hallucination && canspotmon(mtmp)),
  12.              mimicker = (mtmp->m_ap_type == M_AP_MONSTER),
  13.              imitator = (mptr != champtr || mimicker);
  14.  
  15.      You((how == STONING) ? "turn to stone..." : "die...");
  16.      mark_synch(); /* flush buffered screen output */
  17.      buf[0] = '\0';
  18.      killer.format = KILLED_BY_AN;
  19.      /* "killed by the high priest of Crom" is okay,
  20.         "killed by the high priest" alone isn't */
  21.      if ((mptr->geno & G_UNIQ) != 0 && !(imitator && !mimicker)
  22.          && !(mptr == &mons[PM_HIGH_PRIEST] && !mtmp->ispriest)) {
  23.          if (!type_is_pname(mptr))
  24.              Strcat(buf, "the ");
  25.          killer.format = KILLED_BY;
  26.      }
  27.      /* _the_ <invisible> <distorted> ghost of Dudley */
  28.      if (mptr == &mons[PM_GHOST] && has_mname(mtmp)) {
  29.          Strcat(buf, "the ");
  30.          killer.format = KILLED_BY;
  31.      }
  32.      if (mtmp->minvis)
  33.          Strcat(buf, "invisible ");
  34.      if (distorted)
  35.          Strcat(buf, "hallucinogen-distorted ");
  36.  
  37.      if (imitator) {
  38.          char shape[BUFSZ];
  39.          const char *realnm = champtr->mname, *fakenm = mptr->mname;
  40.          boolean alt = is_vampshifter(mtmp);
  41.  
  42.          if (mimicker) {
  43.              /* realnm is already correct because champtr==mptr;
  44.                 set up fake mptr for type_is_pname/the_unique_pm */
  45.              mptr = &mons[mtmp->mappearance];
  46.              fakenm = mptr->mname;
  47.          } else if (alt && strstri(realnm, "vampire")
  48.                     && !strcmp(fakenm, "vampire bat")) {
  49.              /* special case: use "vampire in bat form" in preference
  50.                 to redundant looking "vampire in vampire bat form" */
  51.              fakenm = "bat";
  52.          }
  53.          /* for the alternate format, always suppress any article;
  54.             pname and the_unique should also have s_suffix() applied,
  55.             but vampires don't take on any shapes which warrant that */
  56.          if (alt || type_is_pname(mptr)) /* no article */
  57.              Strcpy(shape, fakenm);
  58.          else if (the_unique_pm(mptr)) /* "the"; don't use the() here */
  59.              Sprintf(shape, "the %s", fakenm);
  60.          else /* "a"/"an" */
  61.              Strcpy(shape, an(fakenm));
  62.          /* omit "called" to avoid excessive verbosity */
  63.          Sprintf(eos(buf),
  64.                  alt ? "%s in %s form"
  65.                      : mimicker ? "%s disguised as %s"
  66.                                 : "%s imitating %s",
  67.                  realnm, shape);
  68.          mptr = mtmp->data; /* reset for mimicker case */
  69.      } else if (mptr == &mons[PM_GHOST]) {
  70.          Strcat(buf, "ghost");
  71.          if (has_mname(mtmp))
  72.              Sprintf(eos(buf), " of %s", MNAME(mtmp));
  73.      } else if (mtmp->isshk) {
  74.          const char *shknm = shkname(mtmp),
  75.                     *honorific = shkname_is_pname(mtmp) ? ""
  76.                                     : mtmp->female ? "Ms. " : "Mr. ";
  77.  
  78.          Sprintf(eos(buf), "%s%s, the shopkeeper", honorific, shknm);
  79.          killer.format = KILLED_BY;
  80.      } else if (mtmp->ispriest || mtmp->isminion) {
  81.          /* m_monnam() suppresses "the" prefix plus "invisible", and
  82.             it overrides the effect of Hallucination on priestname() */
  83.          Strcat(buf, m_monnam(mtmp));
  84.      } else {
  85.          Strcat(buf, mptr->mname);
  86.          if (has_mname(mtmp))
  87.              Sprintf(eos(buf), " called %s", MNAME(mtmp));
  88.      }
  89.  
  90.      Strcpy(killer.name, buf);
  91.      if (mptr->mlet == S_WRAITH)
  92.          u.ugrave_arise = PM_WRAITH;
  93.      else if (mptr->mlet == S_MUMMY && urace.mummynum != NON_PM)
  94.          u.ugrave_arise = urace.mummynum;
  95.      else if (mptr->mlet == S_VAMPIRE && Race_if(PM_HUMAN))
  96.          u.ugrave_arise = PM_VAMPIRE;
  97.      else if (mptr == &mons[PM_GHOUL])
  98.          u.ugrave_arise = PM_GHOUL;
  99.      /* this could happen if a high-end vampire kills the hero
  100.         when ordinary vampires are genocided; ditto for wraiths */
  101.      if (u.ugrave_arise >= LOW_PM
  102.          && (mvitals[u.ugrave_arise].mvflags & G_GENOD))
  103.          u.ugrave_arise = NON_PM;
  104.  
  105.      done(how);
  106.      return;
  107.  }
  108.  

panic[edit]

  1.  #if defined(WIN32) && !defined(SYSCF)
  2.  #define NOTIFY_NETHACK_BUGS
  3.  #endif
  4.  
  5.  /*VARARGS1*/
  6.  void panic
  7.  VA_DECL(const char *, str)
  8.  {
  9.      VA_START(str);
  10.      VA_INIT(str, char *);
  11.  
  12.      if (program_state.panicking++)
  13.          NH_abort(); /* avoid loops - this should never happen*/
  14.  
  15.      if (iflags.window_inited) {
  16.          raw_print("\r\nOops...");
  17.          wait_synch(); /* make sure all pending output gets flushed */
  18.          exit_nhwindows((char *) 0);
  19.          iflags.window_inited = 0; /* they're gone; force raw_print()ing */
  20.      }
  21.  
  22.      raw_print(program_state.gameover
  23.                    ? "Postgame wrapup disrupted."
  24.                    : !program_state.something_worth_saving
  25.                          ? "Program initialization has failed."
  26.                          : "Suddenly, the dungeon collapses.");
  27.  #ifndef MICRO
  28.  #if defined(NOTIFY_NETHACK_BUGS)
  29.      if (!wizard)
  30.          raw_printf("Report the following error to \"%s\" or at \"%s\".",
  31.                     DEVTEAM_EMAIL, DEVTEAM_URL);
  32.      else if (program_state.something_worth_saving)
  33.          raw_print("\nError save file being written.\n");
  34.  #else
  35.      if (!wizard) {
  36.          const char *maybe_rebuild = !program_state.something_worth_saving
  37.                                       ? "."
  38.                                       : "\nand it may be possible to rebuild.";
  39.  
  40.          if (sysopt.support)
  41.              raw_printf("To report this error, %s%s", sysopt.support,
  42.                         maybe_rebuild);
  43.          else if (sysopt.fmtd_wizard_list) /* formatted SYSCF WIZARDS */
  44.              raw_printf("To report this error, contact %s%s",
  45.                         sysopt.fmtd_wizard_list, maybe_rebuild);
  46.          else
  47.              raw_printf("Report error to \"%s\"%s", WIZARD_NAME,
  48.                         maybe_rebuild);
  49.      }
  50.  #endif
  51.      /* XXX can we move this above the prints?  Then we'd be able to
  52.       * suppress "it may be possible to rebuild" based on dosave0()
  53.       * or say it's NOT possible to rebuild. */
  54.      if (program_state.something_worth_saving) {
  55.          set_error_savefile();
  56.          if (dosave0()) {
  57.              /* os/win port specific recover instructions */
  58.              if (sysopt.recover)
  59.                  raw_printf("%s", sysopt.recover);
  60.          }
  61.      }
  62.  #endif
  63.      {
  64.          char buf[BUFSZ];
  65.  
  66.          Vsprintf(buf, str, VA_ARGS);
  67.          raw_print(buf);
  68.          paniclog("panic", buf);
  69.      }
  70.  #ifdef WIN32
  71.      interject(INTERJECT_PANIC);
  72.  #endif
  73.  #if defined(UNIX) || defined(VMS) || defined(LATTICE) || defined(WIN32)
  74.      if (wizard)
  75.          NH_abort(); /* generate core dump */
  76.  #endif
  77.      VA_END();
  78.      really_done(PANICKED);
  79.  }
  80.  

should_query_diclose_option[edit]

  1.  STATIC_OVL boolean
  2.  should_query_disclose_option(category, defquery)
  3.  int category;
  4.  char *defquery;
  5.  {
  6.      int idx;
  7.      char *dop;
  8.  
  9.      *defquery = 'n';
  10.      if ((dop = index(disclosure_options, category)) != 0) {
  11.          idx = (int) (dop - disclosure_options);
  12.          if (idx < 0 || idx >= NUM_DISCLOSURE_OPTIONS) {
  13.              impossible(
  14.                     "should_query_disclose_option: bad disclosure index %d %c",
  15.                         idx, category);
  16.              *defquery = DISCLOSE_PROMPT_DEFAULT_YES;
  17.              return TRUE;
  18.          }
  19.          if (flags.end_disclose[idx] == DISCLOSE_YES_WITHOUT_PROMPT) {
  20.              *defquery = 'y';
  21.              return FALSE;
  22.          } else if (flags.end_disclose[idx] == DISCLOSE_NO_WITHOUT_PROMPT) {
  23.              *defquery = 'n';
  24.              return FALSE;
  25.          } else if (flags.end_disclose[idx] == DISCLOSE_PROMPT_DEFAULT_YES) {
  26.              *defquery = 'y';
  27.              return TRUE;
  28.          } else {
  29.              *defquery = 'n';
  30.              return TRUE;
  31.          }
  32.      }
  33.      impossible("should_query_disclose_option: bad category %c", category);
  34.      return TRUE;
  35.  }
  36.  

diclose[edit]

  1.  STATIC_OVL void
  2.  disclose(how, taken)
  3.  int how;
  4.  boolean taken;
  5.  {
  6.      char c = '\0', defquery;
  7.      char qbuf[QBUFSZ];
  8.      boolean ask = FALSE;
  9.  
  10.      if (invent && !done_stopprint) {
  11.          if (taken)
  12.              Sprintf(qbuf, "Do you want to see what you had when you %s?",
  13.                      (how == QUIT) ? "quit" : "died");
  14.          else
  15.              Strcpy(qbuf, "Do you want your possessions identified?");
  16.  
  17.          ask = should_query_disclose_option('i', &defquery);
  18.          c = ask ? yn_function(qbuf, ynqchars, defquery) : defquery;
  19.          if (c == 'y') {
  20.              struct obj *obj;
  21.  
  22.              for (obj = invent; obj; obj = obj->nobj) {
  23.                  makeknown(obj->otyp);
  24.                  obj->known = obj->bknown = obj->dknown = obj->rknown = 1;
  25.                  if (Is_container(obj) || obj->otyp == STATUE)
  26.                      obj->cknown = obj->lknown = 1;
  27.              }
  28.              (void) display_inventory((char *) 0, TRUE);
  29.              container_contents(invent, TRUE, TRUE, FALSE);
  30.          }
  31.          if (c == 'q')
  32.              done_stopprint++;
  33.      }
  34.  
  35.      if (!done_stopprint) {
  36.          ask = should_query_disclose_option('a', &defquery);
  37.          c = ask ? yn_function("Do you want to see your attributes?", ynqchars,
  38.                                defquery)
  39.                  : defquery;
  40.          if (c == 'y')
  41.              enlightenment((BASICENLIGHTENMENT | MAGICENLIGHTENMENT),
  42.                            (how >= PANICKED) ? ENL_GAMEOVERALIVE
  43.                                              : ENL_GAMEOVERDEAD);
  44.          if (c == 'q')
  45.              done_stopprint++;
  46.      }
  47.  
  48.      if (!done_stopprint) {
  49.          ask = should_query_disclose_option('v', &defquery);
  50.          list_vanquished(defquery, ask);
  51.      }
  52.  
  53.      if (!done_stopprint) {
  54.          ask = should_query_disclose_option('g', &defquery);
  55.          list_genocided(defquery, ask);
  56.      }
  57.  
  58.      if (!done_stopprint) {
  59.          ask = should_query_disclose_option('c', &defquery);
  60.          c = ask ? yn_function("Do you want to see your conduct?", ynqchars,
  61.                                defquery)
  62.                  : defquery;
  63.          if (c == 'y')
  64.              show_conduct((how >= PANICKED) ? 1 : 2);
  65.          if (c == 'q')
  66.              done_stopprint++;
  67.      }
  68.  
  69.      if (!done_stopprint) {
  70.          ask = should_query_disclose_option('o', &defquery);
  71.          c = ask ? yn_function("Do you want to see the dungeon overview?",
  72.                                ynqchars, defquery)
  73.                  : defquery;
  74.          if (c == 'y')
  75.              show_overview((how >= PANICKED) ? 1 : 2, how);
  76.          if (c == 'q')
  77.              done_stopprint++;
  78.      }
  79.  }
  80.  

savelife[edit]

  1.  /* try to get the player back in a viable state after being killed */
  2.  STATIC_OVL void
  3.  savelife(how)
  4.  int how;
  5.  {
  6.      int uhpmin = max(2 * u.ulevel, 10);
  7.  
  8.      if (u.uhpmax < uhpmin)
  9.          u.uhpmax = uhpmin;
  10.      u.uhp = u.uhpmax;
  11.      u.uswldtim = 0;
  12.      if (u.uhunger < 500) {
  13.          u.uhunger = 500;
  14.          newuhs(FALSE);
  15.      }
  16.      /* cure impending doom of sickness hero won't have time to fix */
  17.      if ((Sick & TIMEOUT) == 1L) {
  18.          u.usick_type = 0;
  19.          set_itimeout(&Sick, 0L);
  20.      }
  21.      if (how == CHOKING)
  22.          init_uhunger();
  23.      nomovemsg = "You survived that attempt on your life.";
  24.      context.move = 0;
  25.      if (multi > 0)
  26.          multi = 0;
  27.      else
  28.          multi = -1;
  29.      if (u.utrap && u.utraptype == TT_LAVA)
  30.          u.utrap = 0;
  31.      context.botl = 1;
  32.      u.ugrave_arise = NON_PM;
  33.      HUnchanging = 0L;
  34.      curs_on_u();
  35.  }
  36.  

get_valuables[edit]

  1.  /*
  2.   * Get valuables from the given list.  Revised code: the list always remains
  3.   * intact.
  4.   */
  5.  STATIC_OVL void
  6.  get_valuables(list)
  7.  struct obj *list; /* inventory or container contents */
  8.  {
  9.      register struct obj *obj;
  10.      register int i;
  11.  
  12.      /* find amulets and gems, ignoring all artifacts */
  13.      for (obj = list; obj; obj = obj->nobj)
  14.          if (Has_contents(obj)) {
  15.              get_valuables(obj->cobj);
  16.          } else if (obj->oartifact) {
  17.              continue;
  18.          } else if (obj->oclass == AMULET_CLASS) {
  19.              i = obj->otyp - FIRST_AMULET;
  20.              if (!amulets[i].count) {
  21.                  amulets[i].count = obj->quan;
  22.                  amulets[i].typ = obj->otyp;
  23.              } else
  24.                  amulets[i].count += obj->quan; /* always adds one */
  25.          } else if (obj->oclass == GEM_CLASS && obj->otyp < LUCKSTONE) {
  26.              i = min(obj->otyp, LAST_GEM + 1) - FIRST_GEM;
  27.              if (!gems[i].count) {
  28.                  gems[i].count = obj->quan;
  29.                  gems[i].typ = obj->otyp;
  30.              } else
  31.                  gems[i].count += obj->quan;
  32.          }
  33.      return;
  34.  }
  35.  

sort_valuables[edit]

  1.  /*
  2.   *  Sort collected valuables, most frequent to least.  We could just
  3.   *  as easily use qsort, but we don't care about efficiency here.
  4.   */
  5.  STATIC_OVL void
  6.  sort_valuables(list, size)
  7.  struct valuable_data list[];
  8.  int size; /* max value is less than 20 */
  9.  {
  10.      register int i, j;
  11.      struct valuable_data ltmp;
  12.  
  13.      /* move greater quantities to the front of the list */
  14.      for (i = 1; i < size; i++) {
  15.          if (list[i].count == 0)
  16.              continue;   /* empty slot */
  17.          ltmp = list[i]; /* structure copy */
  18.          for (j = i; j > 0; --j)
  19.              if (list[j - 1].count >= ltmp.count)
  20.                  break;
  21.              else {
  22.                  list[j] = list[j - 1];
  23.              }
  24.          list[j] = ltmp;
  25.      }
  26.      return;
  27.  }
  28.  

odds_and_ends[edit]

  1.  #define CAT_CHECK 2
  2.  
  3.  STATIC_OVL boolean
  4.  odds_and_ends(list, what)
  5.  struct obj *list;
  6.  int what;
  7.  {
  8.      struct obj *otmp;
  9.      for (otmp = list; otmp; otmp = otmp->nobj) {
  10.          switch (what) {
  11.          case CAT_CHECK: /* Schroedinger's Cat */
  12.              /* Ascending is deterministic */
  13.              if (SchroedingersBox(otmp))
  14.                  return rn2(2);
  15.              break;
  16.          }
  17.          if (Has_contents(otmp))
  18.              return odds_and_ends(otmp->cobj, what);
  19.      }
  20.      return FALSE;
  21.  }
  22.  

artifact_score[edit]

  1.  /* called twice; first to calculate total, then to list relevant items */
  2.  STATIC_OVL void
  3.  artifact_score(list, counting, endwin)
  4.  struct obj *list;
  5.  boolean counting; /* true => add up points; false => display them */
  6.  winid endwin;
  7.  {
  8.      char pbuf[BUFSZ];
  9.      struct obj *otmp;
  10.      long value, points;
  11.      short dummy; /* object type returned by artifact_name() */
  12.  
  13.      for (otmp = list; otmp; otmp = otmp->nobj) {
  14.          if (otmp->oartifact || otmp->otyp == BELL_OF_OPENING
  15.              || otmp->otyp == SPE_BOOK_OF_THE_DEAD
  16.              || otmp->otyp == CANDELABRUM_OF_INVOCATION) {
  17.              value = arti_cost(otmp); /* zorkmid value */
  18.              points = value * 5 / 2;  /* score value */
  19.              if (counting) {
  20.                  nowrap_add(u.urexp, points);
  21.              } else {
  22.                  makeknown(otmp->otyp);
  23.                  otmp->known = otmp->dknown = otmp->bknown = otmp->rknown = 1;
  24.                  /* assumes artifacts don't have quan > 1 */
  25.                  Sprintf(pbuf, "%s%s (worth %ld %s and %ld points)",
  26.                          the_unique_obj(otmp) ? "The " : "",
  27.                          otmp->oartifact ? artifact_name(xname(otmp), &dummy)
  28.                                          : OBJ_NAME(objects[otmp->otyp]),
  29.                          value, currency(value), points);
  30.                  putstr(endwin, 0, pbuf);
  31.              }
  32.          }
  33.          if (Has_contents(otmp))
  34.              artifact_score(otmp->cobj, counting, endwin);
  35.      }
  36.  }
  37.  

done[edit]

  1.  /* Be careful not to call panic from here! */
  2.  void
  3.  done(how)
  4.  int how;
  5.  {
  6.      if (how == TRICKED) {
  7.          if (killer.name[0]) {
  8.              paniclog("trickery", killer.name);
  9.              killer.name[0] = 0;
  10.          }
  11.          if (wizard) {
  12.              You("are a very tricky wizard, it seems.");
  13.              return;
  14.          }
  15.      }
  16.  
  17.      if (how == ASCENDED || (!killer.name[0] && how == GENOCIDED))
  18.          killer.format = NO_KILLER_PREFIX;
  19.      /* Avoid killed by "a" burning or "a" starvation */
  20.      if (!killer.name[0] && (how == STARVING || how == BURNING))
  21.          killer.format = KILLED_BY;
  22.      if (!killer.name[0] || how >= PANICKED)
  23.          Strcpy(killer.name, deaths[how]);
  24.  
  25.      if (how < PANICKED)
  26.          u.umortality++;
  27.      if (Lifesaved && (how <= GENOCIDED)) {
  28.          pline("But wait...");
  29.          makeknown(AMULET_OF_LIFE_SAVING);
  30.          Your("medallion %s!", !Blind ? "begins to glow" : "feels warm");
  31.          if (how == CHOKING)
  32.              You("vomit ...");
  33.          You_feel("much better!");
  34.          pline_The("medallion crumbles to dust!");
  35.          if (uamul)
  36.              useup(uamul);
  37.  
  38.          (void) adjattrib(A_CON, -1, TRUE);
  39.          savelife(how);
  40.          if (how == GENOCIDED) {
  41.              pline("Unfortunately you are still genocided...");
  42.          } else {
  43.              killer.name[0] = 0;
  44.              killer.format = 0;
  45.              return;
  46.          }
  47.      }
  48.      if ((wizard || discover) && (how <= GENOCIDED) &&
  49.          !paranoid_query(ParanoidDie, "Die?")) {
  50.          pline("OK, so you don't %s.", (how == CHOKING) ? "choke" : "die");
  51.          savelife(how);
  52.          killer.name[0] = 0;
  53.          killer.format = 0;
  54.          return;
  55.      }
  56.      really_done(how);
  57.  }
  58.  

really_done[edit]

  1.  /* separated from done() in order to specify the __noreturn__ attribute */
  2.  STATIC_OVL void
  3.  really_done(how)
  4.  int how;
  5.  {
  6.      boolean taken;
  7.      char pbuf[BUFSZ];
  8.      winid endwin = WIN_ERR;
  9.      boolean bones_ok, have_windows = iflags.window_inited;
  10.      struct obj *corpse = (struct obj *) 0;
  11.      time_t endtime;
  12.      long umoney;
  13.      long tmp;
  14.  
  15.      /*
  16.       *  The game is now over...
  17.       */
  18.      program_state.gameover = 1;
  19.      /* in case of a subsequent panic(), there's no point trying to save */
  20.      program_state.something_worth_saving = 0;
  21.      /* render vision subsystem inoperative */
  22.      iflags.vision_inited = 0;
  23.  
  24.      /* might have been killed while using a disposable item, so make sure
  25.         it's gone prior to inventory disclosure and creation of bones data */
  26.      inven_inuse(TRUE);
  27.      /* maybe not on object lists; if an active light source, would cause
  28.         big trouble (`obj_is_local' panic) for savebones() -> savelev() */
  29.      if (thrownobj && thrownobj->where == OBJ_FREE)
  30.          dealloc_obj(thrownobj);
  31.      if (kickedobj && kickedobj->where == OBJ_FREE)
  32.          dealloc_obj(kickedobj);
  33.  
  34.      /* remember time of death here instead of having bones, rip, and
  35.         topten figure it out separately and possibly getting different
  36.         time or even day if player is slow responding to --More-- */
  37.      endtime = getnow();
  38.      urealtime.realtime += (long) (endtime - urealtime.restored);
  39.  
  40.      /* Sometimes you die on the first move.  Life's not fair.
  41.       * On those rare occasions you get hosed immediately, go out
  42.       * smiling... :-)  -3.
  43.       */
  44.      if (moves <= 1 && how < PANICKED) /* You die... --More-- */
  45.          pline("Do not pass go.  Do not collect 200 %s.", currency(200L));
  46.  
  47.      if (have_windows)
  48.          wait_synch(); /* flush screen output */
  49.  #ifndef NO_SIGNAL
  50.      (void) signal(SIGINT, (SIG_RET_TYPE) done_intr);
  51.  #if defined(UNIX) || defined(VMS) || defined(__EMX__)
  52.      (void) signal(SIGQUIT, (SIG_RET_TYPE) done_intr);
  53.      sethanguphandler(done_hangup);
  54.  #endif
  55.  #endif /* NO_SIGNAL */
  56.  
  57.      bones_ok = (how < GENOCIDED) && can_make_bones();
  58.  
  59.      if (bones_ok && launch_in_progress())
  60.          force_launch_placement();
  61.  
  62.      /* maintain ugrave_arise even for !bones_ok */
  63.      if (how == PANICKED)
  64.          u.ugrave_arise = (NON_PM - 3); /* no corpse, no grave */
  65.      else if (how == BURNING || how == DISSOLVED) /* corpse burns up too */
  66.          u.ugrave_arise = (NON_PM - 2); /* leave no corpse */
  67.      else if (how == STONING)
  68.          u.ugrave_arise = (NON_PM - 1); /* statue instead of corpse */
  69.      else if (how == TURNED_SLIME)
  70.          u.ugrave_arise = PM_GREEN_SLIME;
  71.  
  72.      /* if pets will contribute to score, populate mydogs list now
  73.         (bones creation isn't a factor, but pline() messaging is) */
  74.      if (how == ESCAPED || how == ASCENDED)
  75.          keepdogs(TRUE);
  76.  
  77.      if (how == QUIT) {
  78.          killer.format = NO_KILLER_PREFIX;
  79.          if (u.uhp < 1) {
  80.              how = DIED;
  81.              u.umortality++; /* skipped above when how==QUIT */
  82.              Strcpy(killer.name, "quit while already on Charon's boat");
  83.          }
  84.      }
  85.      if (how == ESCAPED || how == PANICKED)
  86.          killer.format = NO_KILLER_PREFIX;
  87.  
  88.      if (how != PANICKED) {
  89.          /* these affect score and/or bones, but avoid them during panic */
  90.          taken = paybill((how == ESCAPED) ? -1 : (how != QUIT));
  91.          paygd();
  92.          clearpriests();
  93.      } else
  94.          taken = FALSE; /* lint; assert( !bones_ok ); */
  95.  
  96.      clearlocks();
  97.  
  98.      if (have_windows)
  99.          display_nhwindow(WIN_MESSAGE, FALSE);
  100.  
  101.      if (strcmp(flags.end_disclose, "none") && how != PANICKED)
  102.          disclose(how, taken);
  103.  
  104.      /* finish_paybill should be called after disclosure but before bones */
  105.      if (bones_ok && taken)
  106.          finish_paybill();
  107.  
  108.      /* grave creation should be after disclosure so it doesn't have
  109.         this grave in the current level's features for #overview */
  110.      if (bones_ok && u.ugrave_arise == NON_PM
  111.          && !(mvitals[u.umonnum].mvflags & G_NOCORPSE)) {
  112.          int mnum = u.umonnum;
  113.  
  114.          if (!Upolyd) {
  115.              /* Base corpse on race when not poly'd since original
  116.               * u.umonnum is based on role, and all role monsters
  117.               * are human.
  118.               */
  119.              mnum = (flags.female && urace.femalenum != NON_PM)
  120.                         ? urace.femalenum
  121.                         : urace.malenum;
  122.          }
  123.          corpse = mk_named_object(CORPSE, &mons[mnum], u.ux, u.uy, plname);
  124.          Sprintf(pbuf, "%s, ", plname);
  125.          formatkiller(eos(pbuf), sizeof pbuf - strlen(pbuf), how);
  126.          make_grave(u.ux, u.uy, pbuf);
  127.      }
  128.      pbuf[0] = '\0'; /* clear grave text; also lint suppression */
  129.  
  130.      /* calculate score, before creating bones [container gold] */
  131.      {
  132.          int deepest = deepest_lev_reached(FALSE);
  133.  
  134.          umoney = money_cnt(invent);
  135.          tmp = u.umoney0;
  136.          umoney += hidden_gold(); /* accumulate gold from containers */
  137.          tmp = umoney - tmp;      /* net gain */
  138.  
  139.          if (tmp < 0L)
  140.              tmp = 0L;
  141.          if (how < PANICKED)
  142.              tmp -= tmp / 10L;
  143.          tmp += 50L * (long) (deepest - 1);
  144.          if (deepest > 20)
  145.              tmp += 1000L * (long) ((deepest > 30) ? 10 : deepest - 20);
  146.          nowrap_add(u.urexp, tmp);
  147.  
  148.          /* ascension gives a score bonus iff offering to original deity */
  149.          if (how == ASCENDED && u.ualign.type == u.ualignbase[A_ORIGINAL]) {
  150.              /* retaining original alignment: score *= 2;
  151.                 converting, then using helm-of-OA to switch back: *= 1.5 */
  152.              tmp = (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL])
  153.                        ? u.urexp
  154.                        : (u.urexp / 2L);
  155.              nowrap_add(u.urexp, tmp);
  156.          }
  157.      }
  158.  
  159.      if (u.ugrave_arise >= LOW_PM && u.ugrave_arise != PM_GREEN_SLIME) {
  160.          /* give this feedback even if bones aren't going to be created,
  161.             so that its presence or absence doesn't tip off the player to
  162.             new bones or their lack; it might be a lie if makemon fails */
  163.          Your("body rises from the dead as %s...",
  164.               an(mons[u.ugrave_arise].mname));
  165.          display_nhwindow(WIN_MESSAGE, FALSE);
  166.      }
  167.  
  168.      if (bones_ok) {
  169.          if (!wizard || paranoid_query(ParanoidBones, "Save bones?"))
  170.              savebones(how, endtime, corpse);
  171.          /* corpse may be invalid pointer now so
  172.              ensure that it isn't used again */
  173.          corpse = (struct obj *) 0;
  174.      }
  175.  
  176.      /* update gold for the rip output, which can't use hidden_gold()
  177.         (containers will be gone by then if bones just got saved...) */
  178.      done_money = umoney;
  179.  
  180.      /* clean up unneeded windows */
  181.      if (have_windows) {
  182.          wait_synch();
  183.          free_pickinv_cache(); /* extra persistent window if perm_invent */
  184.          if (WIN_INVEN != WIN_ERR)
  185.              destroy_nhwindow(WIN_INVEN),  WIN_INVEN = WIN_ERR;
  186.          display_nhwindow(WIN_MESSAGE, TRUE);
  187.          destroy_nhwindow(WIN_MAP),  WIN_MAP = WIN_ERR;
  188.  #ifndef STATUS_VIA_WINDOWPORT
  189.          destroy_nhwindow(WIN_STATUS),  WIN_STATUS = WIN_ERR;
  190.  #endif
  191.          destroy_nhwindow(WIN_MESSAGE),  WIN_MESSAGE = WIN_ERR;
  192.  
  193.          if (!done_stopprint || flags.tombstone)
  194.              endwin = create_nhwindow(NHW_TEXT);
  195.  
  196.          if (how < GENOCIDED && flags.tombstone && endwin != WIN_ERR)
  197.              outrip(endwin, how, endtime);
  198.      } else
  199.          done_stopprint = 1; /* just avoid any more output */
  200.  
  201.      if (u.uhave.amulet) {
  202.          Strcat(killer.name, " (with the Amulet)");
  203.      } else if (how == ESCAPED) {
  204.          if (Is_astralevel(&u.uz)) /* offered Amulet to wrong deity */
  205.              Strcat(killer.name, " (in celestial disgrace)");
  206.          else if (carrying(FAKE_AMULET_OF_YENDOR))
  207.              Strcat(killer.name, " (with a fake Amulet)");
  208.          /* don't bother counting to see whether it should be plural */
  209.      }
  210.  
  211.      if (!done_stopprint) {
  212.          Sprintf(pbuf, "%s %s the %s...", Goodbye(), plname,
  213.                  (how != ASCENDED)
  214.                   ? (const char *) ((flags.female && urole.name.f)
  215.                                        ? urole.name.f
  216.                                        : urole.name.m)
  217.                   : (const char *) (flags.female ? "Demigoddess" : "Demigod"));
  218.          putstr(endwin, 0, pbuf);
  219.          putstr(endwin, 0, "");
  220.      }
  221.  
  222.      if (how == ESCAPED || how == ASCENDED) {
  223.          struct monst *mtmp;
  224.          struct obj *otmp;
  225.          register struct val_list *val;
  226.          register int i;
  227.  
  228.          for (val = valuables; val->list; val++)
  229.              for (i = 0; i < val->size; i++) {
  230.                  val->list[i].count = 0L;
  231.              }
  232.          get_valuables(invent);
  233.  
  234.          /* add points for collected valuables */
  235.          for (val = valuables; val->list; val++)
  236.              for (i = 0; i < val->size; i++)
  237.                  if (val->list[i].count != 0L) {
  238.                      tmp = val->list[i].count
  239.                            * (long) objects[val->list[i].typ].oc_cost;
  240.                      nowrap_add(u.urexp, tmp);
  241.                  }
  242.  
  243.          /* count the points for artifacts */
  244.          artifact_score(invent, TRUE, endwin);
  245.  
  246.          viz_array[0][0] |= IN_SIGHT; /* need visibility for naming */
  247.          mtmp = mydogs;
  248.          if (!done_stopprint)
  249.              Strcpy(pbuf, "You");
  250.          if (!Schroedingers_cat) /* check here in case disclosure was off */
  251.              Schroedingers_cat = odds_and_ends(invent, CAT_CHECK);
  252.          if (Schroedingers_cat) {
  253.              int mhp, m_lev = adj_lev(&mons[PM_HOUSECAT]);
  254.              mhp = d(m_lev, 8);
  255.              nowrap_add(u.urexp, mhp);
  256.              if (!done_stopprint)
  257.                  Strcat(eos(pbuf), " and Schroedinger's cat");
  258.          }
  259.          if (mtmp) {
  260.              while (mtmp) {
  261.                  if (!done_stopprint)
  262.                      Sprintf(eos(pbuf), " and %s", mon_nam(mtmp));
  263.                  if (mtmp->mtame)
  264.                      nowrap_add(u.urexp, mtmp->mhp);
  265.                  mtmp = mtmp->nmon;
  266.              }
  267.              if (!done_stopprint)
  268.                  putstr(endwin, 0, pbuf);
  269.              pbuf[0] = '\0';
  270.          } else {
  271.              if (!done_stopprint)
  272.                  Strcat(pbuf, " ");
  273.          }
  274.          if (!done_stopprint) {
  275.              Sprintf(eos(pbuf), "%s with %ld point%s,",
  276.                      how == ASCENDED ? "went to your reward"
  277.                                      : "escaped from the dungeon",
  278.                      u.urexp, plur(u.urexp));
  279.              putstr(endwin, 0, pbuf);
  280.          }
  281.  
  282.          if (!done_stopprint)
  283.              artifact_score(invent, FALSE, endwin); /* list artifacts */
  284.  
  285.          /* list valuables here */
  286.          for (val = valuables; val->list; val++) {
  287.              sort_valuables(val->list, val->size);
  288.              for (i = 0; i < val->size && !done_stopprint; i++) {
  289.                  int typ = val->list[i].typ;
  290.                  long count = val->list[i].count;
  291.  
  292.                  if (count == 0L)
  293.                      continue;
  294.                  if (objects[typ].oc_class != GEM_CLASS || typ <= LAST_GEM) {
  295.                      otmp = mksobj(typ, FALSE, FALSE);
  296.                      makeknown(otmp->otyp);
  297.                      otmp->known = 1;  /* for fake amulets */
  298.                      otmp->dknown = 1; /* seen it (blindness fix) */
  299.                      if (has_oname(otmp))
  300.                          free_oname(otmp);
  301.                      otmp->quan = count;
  302.                      Sprintf(pbuf, "%8ld %s (worth %ld %s),", count,
  303.                              xname(otmp), count * (long) objects[typ].oc_cost,
  304.                              currency(2L));
  305.                      obfree(otmp, (struct obj *) 0);
  306.                  } else {
  307.                      Sprintf(pbuf, "%8ld worthless piece%s of colored glass,",
  308.                              count, plur(count));
  309.                  }
  310.                  putstr(endwin, 0, pbuf);
  311.              }
  312.          }
  313.  
  314.      } else if (!done_stopprint) {
  315.          /* did not escape or ascend */
  316.          if (u.uz.dnum == 0 && u.uz.dlevel <= 0) {
  317.              /* level teleported out of the dungeon; `how' is DIED,
  318.                 due to falling or to "arriving at heaven prematurely" */
  319.              Sprintf(pbuf, "You %s beyond the confines of the dungeon",
  320.                      (u.uz.dlevel < 0) ? "passed away" : ends[how]);
  321.          } else {
  322.              /* more conventional demise */
  323.              const char *where = dungeons[u.uz.dnum].dname;
  324.  
  325.              if (Is_astralevel(&u.uz))
  326.                  where = "The Astral Plane";
  327.              Sprintf(pbuf, "You %s in %s", ends[how], where);
  328.              if (!In_endgame(&u.uz) && !Is_knox(&u.uz))
  329.                  Sprintf(eos(pbuf), " on dungeon level %d",
  330.                          In_quest(&u.uz) ? dunlev(&u.uz) : depth(&u.uz));
  331.          }
  332.  
  333.          Sprintf(eos(pbuf), " with %ld point%s,", u.urexp, plur(u.urexp));
  334.          putstr(endwin, 0, pbuf);
  335.      }
  336.  
  337.      if (!done_stopprint) {
  338.          Sprintf(pbuf, "and %ld piece%s of gold, after %ld move%s.", umoney,
  339.                  plur(umoney), moves, plur(moves));
  340.          putstr(endwin, 0, pbuf);
  341.      }
  342.      if (!done_stopprint) {
  343.          Sprintf(pbuf,
  344.              "You were level %d with a maximum of %d hit point%s when you %s.",
  345.                  u.ulevel, u.uhpmax, plur(u.uhpmax), ends[how]);
  346.          putstr(endwin, 0, pbuf);
  347.          putstr(endwin, 0, "");
  348.      }
  349.      if (!done_stopprint)
  350.          display_nhwindow(endwin, TRUE);
  351.      if (endwin != WIN_ERR)
  352.          destroy_nhwindow(endwin);
  353.  
  354.      /* "So when I die, the first thing I will see in Heaven is a
  355.       * score list?" */
  356.      if (have_windows && !iflags.toptenwin)
  357.          exit_nhwindows((char *) 0), have_windows = FALSE;
  358.      topten(how, endtime);
  359.      if (have_windows)
  360.          exit_nhwindows((char *) 0);
  361.  
  362.      if (done_stopprint) {
  363.          raw_print("");
  364.          raw_print("");
  365.      }
  366.      terminate(EXIT_SUCCESS);
  367.  }
  368.  

container_contents[edit]

  1.  void
  2.  container_contents(list, identified, all_containers, reportempty)
  3.  struct obj *list;
  4.  boolean identified, all_containers, reportempty;
  5.  {
  6.      register struct obj *box, *obj;
  7.      struct obj **oarray;
  8.      int i, n;
  9.      char *invlet;
  10.      char buf[BUFSZ];
  11.      boolean cat, deadcat;
  12.  
  13.      for (box = list; box; box = box->nobj) {
  14.          if (Is_container(box) || box->otyp == STATUE) {
  15.              box->cknown = 1; /* we're looking at the contents now */
  16.              if (identified)
  17.                  box->lknown = 1;
  18.              cat = deadcat = FALSE;
  19.              if (SchroedingersBox(box) && !Schroedingers_cat) {
  20.                  /* Schroedinger's Cat? */
  21.                  cat = odds_and_ends(box, CAT_CHECK);
  22.                  if (cat)
  23.                      Schroedingers_cat = TRUE;
  24.                  else
  25.                      deadcat = TRUE;
  26.                  box->spe = 0;
  27.              }
  28.              if (box->otyp == BAG_OF_TRICKS) {
  29.                  continue; /* wrong type of container */
  30.              } else if (box->cobj) {
  31.                  winid tmpwin = create_nhwindow(NHW_MENU);
  32.  
  33.                  /* count the number of items */
  34.                  for (n = 0, obj = box->cobj; obj; obj = obj->nobj)
  35.                      n++;
  36.                  /* Make a temporary array to store the objects sorted */
  37.                  oarray = objarr_init(n);
  38.  
  39.                  /* Add objects to the array */
  40.                  i = 0;
  41.                  invlet = flags.inv_order;
  42.              nextclass:
  43.                  for (obj = box->cobj; obj; obj = obj->nobj) {
  44.                      if (!flags.sortpack || obj->oclass == *invlet) {
  45.                          objarr_set(
  46.                              obj, i++, oarray,
  47.                              (flags.sortloot == 'f' || flags.sortloot == 'l'));
  48.                      }
  49.                  } /* for loop */
  50.                  if (flags.sortpack) {
  51.                      if (*++invlet)
  52.                          goto nextclass;
  53.                  }
  54.  
  55.                  Sprintf(buf, "Contents of %s:", the(xname(box)));
  56.                  putstr(tmpwin, 0, buf);
  57.                  putstr(tmpwin, 0, "");
  58.                  for (i = 0; i < n; i++) {
  59.                      obj = oarray[i];
  60.                      if (identified) {
  61.                          makeknown(obj->otyp);
  62.                          obj->known = obj->bknown = obj->dknown = obj->rknown =
  63.                              1;
  64.                          if (Is_container(obj) || obj->otyp == STATUE)
  65.                              obj->cknown = obj->lknown = 1;
  66.                      }
  67.                      putstr(tmpwin, 0, doname(obj));
  68.                  }
  69.                  free(oarray);
  70.                  if (cat)
  71.                      putstr(tmpwin, 0, "Schroedinger's cat");
  72.                  else if (deadcat)
  73.                      putstr(tmpwin, 0, "Schroedinger's dead cat");
  74.                  display_nhwindow(tmpwin, TRUE);
  75.                  destroy_nhwindow(tmpwin);
  76.                  if (all_containers)
  77.                      container_contents(box->cobj, identified, TRUE,
  78.                                         reportempty);
  79.              } else if (cat || deadcat) {
  80.                  pline("%s Schroedinger's %scat!", Tobjnam(box, "contain"),
  81.                        deadcat ? "dead " : "");
  82.                  display_nhwindow(WIN_MESSAGE, FALSE);
  83.              } else if (reportempty) {
  84.                  pline("%s is empty.", upstart(thesimpleoname(box)));
  85.                  display_nhwindow(WIN_MESSAGE, FALSE);
  86.              }
  87.          }
  88.          if (!all_containers)
  89.              break;
  90.      }
  91.  }
  92.  

terminate[edit]

  1.  /* should be called with either EXIT_SUCCESS or EXIT_FAILURE */
  2.  void
  3.  terminate(status)
  4.  int status;
  5.  {
  6.      program_state.in_moveloop = 0; /* won't be returning to normal play */
  7.  #ifdef MAC
  8.      getreturn("to exit");
  9.  #endif
  10.      /* don't bother to try to release memory if we're in panic mode, to
  11.         avoid trouble in case that happens to be due to memory problems */
  12.      if (!program_state.panicking) {
  13.          freedynamicdata();
  14.          dlb_cleanup();
  15.      }
  16.  
  17.  #ifdef VMS
  18.      /*
  19.       *  This is liable to draw a warning if compiled with gcc, but it's
  20.       *  more important to flag panic() -> really_done() -> terminate()
  21.       *  as __noreturn__ then to avoid the warning.
  22.       */
  23.      /* don't call exit() if already executing within an exit handler;
  24.         that would cancel any other pending user-mode handlers */
  25.      if (program_state.exiting)
  26.          return;
  27.  #endif
  28.      program_state.exiting = 1;
  29.      nethack_exit(status);
  30.  }
  31.  

dovanquished[edit]

  1.  /* #vanquished command */
  2.  int
  3.  dovanquished()
  4.  {
  5.      list_vanquished('a', FALSE);
  6.      return 0;
  7.  }
  8.  

list_vanquished[edit]

  1.  STATIC_OVL void
  2.  list_vanquished(defquery, ask)
  3.  char defquery;
  4.  boolean ask;
  5.  {
  6.      register int i, lev;
  7.      int ntypes = 0, max_lev = 0, nkilled;
  8.      long total_killed = 0L;
  9.      char c;
  10.      winid klwin;
  11.      char buf[BUFSZ];
  12.  
  13.      /* get totals first */
  14.      for (i = LOW_PM; i < NUMMONS; i++) {
  15.          if (mvitals[i].died)
  16.              ntypes++;
  17.          total_killed += (long) mvitals[i].died;
  18.          if (mons[i].mlevel > max_lev)
  19.              max_lev = mons[i].mlevel;
  20.      }
  21.  
  22.      /* vanquished creatures list;
  23.       * includes all dead monsters, not just those killed by the player
  24.       */
  25.      if (ntypes != 0) {
  26.          c = ask ? yn_function(
  27.                              "Do you want an account of creatures vanquished?",
  28.                                ynqchars, defquery)
  29.                  : defquery;
  30.          if (c == 'q')
  31.              done_stopprint++;
  32.          if (c == 'y' || c == 'a') {
  33.              klwin = create_nhwindow(NHW_MENU);
  34.              putstr(klwin, 0, "Vanquished creatures:");
  35.              putstr(klwin, 0, "");
  36.  
  37.              /* countdown by monster "toughness" */
  38.              for (lev = max_lev; lev >= 0; lev--)
  39.                  for (i = LOW_PM; i < NUMMONS; i++)
  40.                      if (mons[i].mlevel == lev
  41.                          && (nkilled = mvitals[i].died) > 0) {
  42.                          if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST) {
  43.                              Sprintf(buf, "%s%s",
  44.                                      !type_is_pname(&mons[i]) ? "The " : "",
  45.                                      mons[i].mname);
  46.                              if (nkilled > 1) {
  47.                                  switch (nkilled) {
  48.                                  case 2:
  49.                                      Sprintf(eos(buf), " (twice)");
  50.                                      break;
  51.                                  case 3:
  52.                                      Sprintf(eos(buf), " (thrice)");
  53.                                      break;
  54.                                  default:
  55.                                      Sprintf(eos(buf), " (%d times)", nkilled);
  56.                                      break;
  57.                                  }
  58.                              }
  59.                          } else {
  60.                              /* trolls or undead might have come back,
  61.                                 but we don't keep track of that */
  62.                              if (nkilled == 1)
  63.                                  Strcpy(buf, an(mons[i].mname));
  64.                              else
  65.                                  Sprintf(buf, "%d %s", nkilled,
  66.                                          makeplural(mons[i].mname));
  67.                          }
  68.                          putstr(klwin, 0, buf);
  69.                      }
  70.              /*
  71.               * if (Hallucination)
  72.               *     putstr(klwin, 0, "and a partridge in a pear tree");
  73.               */
  74.              if (ntypes > 1) {
  75.                  putstr(klwin, 0, "");
  76.                  Sprintf(buf, "%ld creatures vanquished.", total_killed);
  77.                  putstr(klwin, 0, buf);
  78.              }
  79.              display_nhwindow(klwin, TRUE);
  80.              destroy_nhwindow(klwin);
  81.          }
  82.      } else if (defquery == 'a') {
  83.          /* #dovanquished rather than final disclosure, so pline() is ok */
  84.          pline("No monsters have been vanquished.");
  85.      }
  86.  }
  87.  

num_genocides[edit]

  1.  /* number of monster species which have been genocided */
  2.  int
  3.  num_genocides()
  4.  {
  5.      int i, n = 0;
  6.  
  7.      for (i = LOW_PM; i < NUMMONS; ++i)
  8.          if (mvitals[i].mvflags & G_GENOD)
  9.              ++n;
  10.  
  11.      return n;
  12.  }
  13.  

num_extinct[edit]

  1.  int
  2.  num_extinct()
  3.  {
  4.      int i, n = 0;
  5.  
  6.      for (i = LOW_PM; i < NUMMONS; ++i)
  7.          if (!(mvitals[i].mvflags & G_GENOD) && (mvitals[i].mvflags & G_GONE)
  8.              && !(mons[i].geno & G_UNIQ))
  9.              ++n;
  10.  
  11.      return n;
  12.  }
  13.  

list_genocided[edit]

  1.  STATIC_OVL void
  2.  list_genocided(defquery, ask)
  3.  char defquery;
  4.  boolean ask;
  5.  {
  6.      register int i;
  7.      int ngenocided, nextinct;
  8.      char c;
  9.      winid klwin;
  10.      char buf[BUFSZ];
  11.  
  12.      ngenocided = num_genocides();
  13.      nextinct = num_extinct();
  14.  
  15.      /* genocided or extinct species list */
  16.      if (ngenocided != 0 || nextinct != 0) {
  17.          Sprintf(buf, "Do you want a list of %sspecies%s%s?",
  18.                  (nextinct && !ngenocided) ? "extinct " : "",
  19.                  (ngenocided) ? " genocided" : "",
  20.                  (nextinct && ngenocided) ? " and extinct" : "");
  21.          c = ask ? yn_function(buf, ynqchars, defquery) : defquery;
  22.          if (c == 'q')
  23.              done_stopprint++;
  24.          if (c == 'y') {
  25.              klwin = create_nhwindow(NHW_MENU);
  26.              Sprintf(buf, "%s%s species:",
  27.                      (ngenocided) ? "Genocided" : "Extinct",
  28.                      (nextinct && ngenocided) ? " or extinct" : "");
  29.              putstr(klwin, 0, buf);
  30.              putstr(klwin, 0, "");
  31.  
  32.              for (i = LOW_PM; i < NUMMONS; i++)
  33.                  if (mvitals[i].mvflags & G_GONE && !(mons[i].geno & G_UNIQ)) {
  34.                      if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST)
  35.                          Sprintf(buf, "%s%s",
  36.                                  !type_is_pname(&mons[i]) ? "" : "the ",
  37.                                  mons[i].mname);
  38.                      else
  39.                          Strcpy(buf, makeplural(mons[i].mname));
  40.                      if (!(mvitals[i].mvflags & G_GENOD))
  41.                          Strcat(buf, " (extinct)");
  42.                      putstr(klwin, 0, buf);
  43.                  }
  44.  
  45.              putstr(klwin, 0, "");
  46.              if (ngenocided > 0) {
  47.                  Sprintf(buf, "%d species genocided.", ngenocided);
  48.                  putstr(klwin, 0, buf);
  49.              }
  50.              if (nextinct > 0) {
  51.                  Sprintf(buf, "%d species extinct.", nextinct);
  52.                  putstr(klwin, 0, buf);
  53.              }
  54.  
  55.              display_nhwindow(klwin, TRUE);
  56.              destroy_nhwindow(klwin);
  57.          }
  58.      }
  59.  }
  60.  

delayed_killer[edit]

  1.  /* set a delayed killer, ensure non-delayed killer is cleared out */
  2.  void
  3.  delayed_killer(id, format, killername)
  4.  int id;
  5.  int format;
  6.  const char *killername;
  7.  {
  8.      struct kinfo *k = find_delayed_killer(id);
  9.  
  10.      if (k == (struct kinfo *) 0) {
  11.          /* no match, add a new delayed killer to the list */
  12.          k = (struct kinfo *) alloc(sizeof(struct kinfo));
  13.          k->id = id;
  14.          k->next = killer.next;
  15.          killer.next = k;
  16.      }
  17.  
  18.      k->format = format;
  19.      Strcpy(k->name, killername ? killername : "");
  20.      killer.name[0] = 0;
  21.  }
  22.  

find_delayed_killer[edit]

  1.  struct kinfo *
  2.  find_delayed_killer(id)
  3.  int id;
  4.  {
  5.      struct kinfo *k;
  6.  
  7.      for (k = killer.next; k != (struct kinfo *) 0; k = k->next) {
  8.          if (k->id == id)
  9.              break;
  10.      }
  11.      return k;
  12.  }
  13.  

dealloc_killer[edit]

  1.  void
  2.  dealloc_killer(kptr)
  3.  struct kinfo *kptr;
  4.  {
  5.      struct kinfo *prev = &killer, *k;
  6.  
  7.      if (kptr == (struct kinfo *) 0)
  8.          return;
  9.      for (k = killer.next; k != (struct kinfo *) 0; k = k->next) {
  10.          if (k == kptr)
  11.              break;
  12.          prev = k;
  13.      }
  14.  
  15.      if (k == (struct kinfo *) 0) {
  16.          impossible("dealloc_killer not on list");
  17.      } else {
  18.          prev->next = k->next;
  19.          free((genericptr_t) k);
  20.      }
  21.  }
  22.  

save_killers[edit]

  1.  void
  2.  save_killers(fd, mode)
  3.  int fd;
  4.  int mode;
  5.  {
  6.      struct kinfo *kptr;
  7.  
  8.      if (perform_bwrite(mode)) {
  9.          for (kptr = &killer; kptr != (struct kinfo *) 0; kptr = kptr->next) {
  10.              bwrite(fd, (genericptr_t) kptr, sizeof(struct kinfo));
  11.          }
  12.      }
  13.      if (release_data(mode)) {
  14.          while (killer.next) {
  15.              kptr = killer.next->next;
  16.              free((genericptr_t) killer.next);
  17.              killer.next = kptr;
  18.          }
  19.      }
  20.  }
  21.  

restore_killers[edit]

  1.  void
  2.  restore_killers(fd)
  3.  int fd;
  4.  {
  5.      struct kinfo *kptr;
  6.  
  7.      for (kptr = &killer; kptr != (struct kinfo *) 0; kptr = kptr->next) {
  8.          mread(fd, (genericptr_t) kptr, sizeof(struct kinfo));
  9.          if (kptr->next) {
  10.              kptr->next = (struct kinfo *) alloc(sizeof(struct kinfo));
  11.          }
  12.      }
  13.  }
  14.  

wordcount[edit]

  1.  static int
  2.  wordcount(p)
  3.  char *p;
  4.  {
  5.      int words = 0;
  6.  
  7.      while (*p) {
  8.          while (*p && isspace((uchar) *p))
  9.              p++;
  10.          if (*p)
  11.              words++;
  12.          while (*p && !isspace((uchar) *p))
  13.              p++;
  14.      }
  15.      return words;
  16.  }
  17.  

bel_copy1[edit]

  1.  static void
  2.  bel_copy1(inp, out)
  3.  char **inp, *out;
  4.  {
  5.      char *in = *inp;
  6.  
  7.      out += strlen(out); /* eos() */
  8.      while (*in && isspace((uchar) *in))
  9.          in++;
  10.      while (*in && !isspace((uchar) *in))
  11.          *out++ = *in++;
  12.      *out = '\0';
  13.      *inp = in;
  14.  }
  15.  

build_english_list[edit]

  1.  char *
  2.  build_english_list(in)
  3.  char *in;
  4.  {
  5.      char *out, *p = in;
  6.      int len = (int) strlen(p), words = wordcount(p);
  7.  
  8.      /* +3: " or " - " "; +(words - 1): (N-1)*(", " - " ") */
  9.      if (words > 1)
  10.          len += 3 + (words - 1);
  11.      out = (char *) alloc(len + 1);
  12.      *out = '\0'; /* bel_copy1() appends */
  13.  
  14.      switch (words) {
  15.      case 0:
  16.          impossible("no words in list");
  17.          break;
  18.      case 1:
  19.          /* "single" */
  20.          bel_copy1(&p, out);
  21.          break;
  22.      default:
  23.          if (words == 2) {
  24.              /* "first or second" */
  25.              bel_copy1(&p, out);
  26.              Strcat(out, " ");
  27.          } else {
  28.              /* "first, second, or third */
  29.              do {
  30.                  bel_copy1(&p, out);
  31.                  Strcat(out, ", ");
  32.              } while (--words > 1);
  33.          }
  34.          Strcat(out, "or ");
  35.          bel_copy1(&p, out);
  36.          break;
  37.      }
  38.      return out;
  39.  }
  40.  
  41.  /*end.c*/