Source:NetHack 3.6.0/src/pline.c

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

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

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

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

Top of file

  1.  /* NetHack 3.6	pline.c	$NHDT-Date: 1432512770 2015/05/25 00:12:50 $  $NHDT-Branch: master $:$NHDT-Revision: 1.42 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers \
  6.                                         */
  7.  #include "hack.h"
  8.  
  9.  static boolean no_repeat = FALSE;
  10.  static char prevmsg[BUFSZ];
  11.  
  12.  static char *FDECL(You_buf, (int));
  13.  

pline

  1.  /*VARARGS1*/
  2.  /* Note that these declarations rely on knowledge of the internals
  3.   * of the variable argument handling stuff in "tradstdc.h"
  4.   */
  5.  
  6.  #if defined(USE_STDARG) || defined(USE_VARARGS)
  7.  static void FDECL(vpline, (const char *, va_list));
  8.  
  9.  void pline
  10.  VA_DECL(const char *, line)
  11.  {
  12.      VA_START(line);
  13.      VA_INIT(line, char *);
  14.      vpline(line, VA_ARGS);
  15.      VA_END();
  16.  }
  17.  
  18.  # ifdef USE_STDARG
  19.  static void
  20.  vpline(const char *line, va_list the_args)
  21.  # else
  22.  static void
  23.  vpline(line, the_args)
  24.  const char *line;
  25.  va_list the_args;
  26.  # endif
  27.  
  28.  #else /* USE_STDARG | USE_VARARG */
  29.  
  30.  # define vpline pline
  31.  
  32.  void pline
  33.  VA_DECL(const char *, line)
  34.  #endif /* USE_STDARG | USE_VARARG */
  35.  {       /* start of vpline() or of nested block in USE_OLDARG's pline() */
  36.      char pbuf[3 * BUFSZ];
  37.      int ln;
  38.      xchar msgtyp;
  39.      /* Do NOT use VA_START and VA_END in here... see above */
  40.  
  41.      if (!line || !*line)
  42.          return;
  43.  #ifdef HANGUPHANDLING
  44.      if (program_state.done_hup)
  45.          return;
  46.  #endif
  47.      if (program_state.wizkit_wishing)
  48.          return;
  49.  
  50.      if (index(line, '%')) {
  51.          Vsprintf(pbuf, line, VA_ARGS);
  52.          line = pbuf;
  53.      }
  54.      if ((ln = (int) strlen(line)) > BUFSZ - 1) {
  55.          if (line != pbuf)                          /* no '%' was present */
  56.              (void) strncpy(pbuf, line, BUFSZ - 1); /* caveat: unterminated */
  57.          /* truncate, preserving the final 3 characters:
  58.             "___ extremely long text" -> "___ extremely l...ext"
  59.             (this may be suboptimal if overflow is less than 3) */
  60.          (void) strncpy(pbuf + BUFSZ - 1 - 6, "...", 3);
  61.          /* avoid strncpy; buffers could overlap if excess is small */
  62.          pbuf[BUFSZ - 1 - 3] = line[ln - 3];
  63.          pbuf[BUFSZ - 1 - 2] = line[ln - 2];
  64.          pbuf[BUFSZ - 1 - 1] = line[ln - 1];
  65.          pbuf[BUFSZ - 1] = '\0';
  66.          line = pbuf;
  67.      }
  68.      if (!iflags.window_inited) {
  69.          raw_print(line);
  70.          iflags.last_msg = PLNMSG_UNKNOWN;
  71.          return;
  72.      }
  73.  #ifndef MAC
  74.      if (no_repeat && !strcmp(line, toplines))
  75.          return;
  76.  #endif /* MAC */
  77.      if (vision_full_recalc)
  78.          vision_recalc(0);
  79.      if (u.ux)
  80.          flush_screen(1); /* %% */
  81.      msgtyp = msgtype_type(line);
  82.      if (msgtyp == MSGTYP_NOSHOW) return;
  83.      if (msgtyp == MSGTYP_NOREP && !strcmp(line, prevmsg)) return;
  84.      putstr(WIN_MESSAGE, 0, line);
  85.      /* this gets cleared after every pline message */
  86.      iflags.last_msg = PLNMSG_UNKNOWN;
  87.      strncpy(prevmsg, line, BUFSZ);
  88.      if (msgtyp == MSGTYP_STOP) display_nhwindow(WIN_MESSAGE, TRUE); /* --more-- */
  89.  
  90.  #if !(defined(USE_STDARG) || defined(USE_VARARGS))
  91.      /* provide closing brace for the nested block
  92.         which immediately follows USE_OLDARGS's VA_DECL() */
  93.      VA_END();
  94.  #endif
  95.  }
  96.  

Norep

  1.  /*VARARGS1*/
  2.  void Norep
  3.  VA_DECL(const char *, line)
  4.  {
  5.      VA_START(line);
  6.      VA_INIT(line, const char *);
  7.      no_repeat = TRUE;
  8.      vpline(line, VA_ARGS);
  9.      no_repeat = FALSE;
  10.      VA_END();
  11.      return;
  12.  }
  13.  

You_buf

  1.  /* work buffer for You(), &c and verbalize() */
  2.  static char *you_buf = 0;
  3.  static int you_buf_siz = 0;
  4.  
  5.  static char *
  6.  You_buf(siz)
  7.  int siz;
  8.  {
  9.      if (siz > you_buf_siz) {
  10.          if (you_buf)
  11.              free((genericptr_t) you_buf);
  12.          you_buf_siz = siz + 10;
  13.          you_buf = (char *) alloc((unsigned) you_buf_siz);
  14.      }
  15.      return you_buf;
  16.  }
  17.  

free_youbuf

  1.  void
  2.  free_youbuf()
  3.  {
  4.      if (you_buf)
  5.          free((genericptr_t) you_buf), you_buf = (char *) 0;
  6.      you_buf_siz = 0;
  7.  }
  8.  

You

  1.  /* `prefix' must be a string literal, not a pointer */
  2.  #define YouPrefix(pointer, prefix, text) \
  3.      Strcpy((pointer = You_buf((int) (strlen(text) + sizeof prefix))), prefix)
  4.  
  5.  #define YouMessage(pointer, prefix, text) \
  6.      strcat((YouPrefix(pointer, prefix, text), pointer), text)
  7.  
  8.  /*VARARGS1*/
  9.  void You
  10.  VA_DECL(const char *, line)
  11.  {
  12.      char *tmp;
  13.      VA_START(line);
  14.      VA_INIT(line, const char *);
  15.      vpline(YouMessage(tmp, "You ", line), VA_ARGS);
  16.      VA_END();
  17.  }
  18.  

Your

  1.  /*VARARGS1*/
  2.  void Your
  3.  VA_DECL(const char *, line)
  4.  {
  5.      char *tmp;
  6.      VA_START(line);
  7.      VA_INIT(line, const char *);
  8.      vpline(YouMessage(tmp, "Your ", line), VA_ARGS);
  9.      VA_END();
  10.  }
  11.  

You_feel

  1.  /*VARARGS1*/
  2.  void You_feel
  3.  VA_DECL(const char *, line)
  4.  {
  5.      char *tmp;
  6.      VA_START(line);
  7.      VA_INIT(line, const char *);
  8.      if (Unaware)
  9.          YouPrefix(tmp, "You dream that you feel ", line);
  10.      else
  11.          YouPrefix(tmp, "You feel ", line);
  12.      vpline(strcat(tmp, line), VA_ARGS);
  13.      VA_END();
  14.  }
  15.  

You_cant

  1.  /*VARARGS1*/
  2.  void You_cant
  3.  VA_DECL(const char *, line)
  4.  {
  5.      char *tmp;
  6.      VA_START(line);
  7.      VA_INIT(line, const char *);
  8.      vpline(YouMessage(tmp, "You can't ", line), VA_ARGS);
  9.      VA_END();
  10.  }
  11.  

pline_The

  1.  /*VARARGS1*/
  2.  void pline_The
  3.  VA_DECL(const char *, line)
  4.  {
  5.      char *tmp;
  6.      VA_START(line);
  7.      VA_INIT(line, const char *);
  8.      vpline(YouMessage(tmp, "The ", line), VA_ARGS);
  9.      VA_END();
  10.  }
  11.  

There

  1.  /*VARARGS1*/
  2.  void There
  3.  VA_DECL(const char *, line)
  4.  {
  5.      char *tmp;
  6.      VA_START(line);
  7.      VA_INIT(line, const char *);
  8.      vpline(YouMessage(tmp, "There ", line), VA_ARGS);
  9.      VA_END();
  10.  }
  11.  

You_hear

  1.  /*VARARGS1*/
  2.  void You_hear
  3.  VA_DECL(const char *, line)
  4.  {
  5.      char *tmp;
  6.  
  7.      if (Deaf || !flags.acoustics)
  8.          return;
  9.      VA_START(line);
  10.      VA_INIT(line, const char *);
  11.      if (Underwater)
  12.          YouPrefix(tmp, "You barely hear ", line);
  13.      else if (Unaware)
  14.          YouPrefix(tmp, "You dream that you hear ", line);
  15.      else
  16.          YouPrefix(tmp, "You hear ", line);
  17.      vpline(strcat(tmp, line), VA_ARGS);
  18.      VA_END();
  19.  }
  20.  

You_see

  1.  /*VARARGS1*/
  2.  void You_see
  3.  VA_DECL(const char *, line)
  4.  {
  5.      char *tmp;
  6.  
  7.      VA_START(line);
  8.      VA_INIT(line, const char *);
  9.      if (Unaware)
  10.          YouPrefix(tmp, "You dream that you see ", line);
  11.      else if (Blind) /* caller should have caught this... */
  12.          YouPrefix(tmp, "You sense ", line);
  13.      else
  14.          YouPrefix(tmp, "You see ", line);
  15.      vpline(strcat(tmp, line), VA_ARGS);
  16.      VA_END();
  17.  }
  18.  

verbalize

  1.  /* Print a message inside double-quotes.
  2.   * The caller is responsible for checking deafness.
  3.   * Gods can speak directly to you in spite of deafness.
  4.   */
  5.  /*VARARGS1*/
  6.  void verbalize
  7.  VA_DECL(const char *, line)
  8.  {
  9.      char *tmp;
  10.  
  11.      VA_START(line);
  12.      VA_INIT(line, const char *);
  13.      tmp = You_buf((int) strlen(line) + sizeof "\"\"");
  14.      Strcpy(tmp, "\"");
  15.      Strcat(tmp, line);
  16.      Strcat(tmp, "\"");
  17.      vpline(tmp, VA_ARGS);
  18.      VA_END();
  19.  }
  20.  

raw_printf

  1.  /*VARARGS1*/
  2.  /* Note that these declarations rely on knowledge of the internals
  3.   * of the variable argument handling stuff in "tradstdc.h"
  4.   */
  5.  
  6.  #if defined(USE_STDARG) || defined(USE_VARARGS)
  7.  static void FDECL(vraw_printf, (const char *, va_list));
  8.  
  9.  void raw_printf
  10.  VA_DECL(const char *, line)
  11.  {
  12.      VA_START(line);
  13.      VA_INIT(line, char *);
  14.      vraw_printf(line, VA_ARGS);
  15.      VA_END();
  16.  }
  17.  
  18.  # ifdef USE_STDARG
  19.  static void
  20.  vraw_printf(const char *line, va_list the_args)
  21.  # else
  22.  static void
  23.  vraw_printf(line, the_args)
  24.  const char *line;
  25.  va_list the_args;
  26.  # endif
  27.  
  28.  #else /* USE_STDARG | USE_VARARG */
  29.  
  30.  void raw_printf
  31.  VA_DECL(const char *, line)
  32.  #endif
  33.  {
  34.      char pbuf[3 * BUFSZ];
  35.      int ln;
  36.      /* Do NOT use VA_START and VA_END in here... see above */
  37.  
  38.      if (index(line, '%')) {
  39.          Vsprintf(pbuf, line, VA_ARGS);
  40.          line = pbuf;
  41.      }
  42.      if ((ln = (int) strlen(line)) > BUFSZ - 1) {
  43.          if (line != pbuf)
  44.              line = strncpy(pbuf, line, BUFSZ - 1);
  45.          /* unlike pline, we don't futz around to keep last few chars */
  46.          pbuf[BUFSZ - 1] = '\0'; /* terminate strncpy or truncate vsprintf */
  47.      }
  48.      raw_print(line);
  49.  #if !(defined(USE_STDARG) || defined(USE_VARARGS))
  50.      VA_END(); /* (see vpline) */
  51.  #endif
  52.  }
  53.  

impossible

  1.  /*VARARGS1*/
  2.  void impossible
  3.  VA_DECL(const char *, s)
  4.  {
  5.      char pbuf[2 * BUFSZ];
  6.      VA_START(s);
  7.      VA_INIT(s, const char *);
  8.      if (program_state.in_impossible)
  9.          panic("impossible called impossible");
  10.  
  11.      program_state.in_impossible = 1;
  12.      Vsprintf(pbuf, s, VA_ARGS);
  13.      pbuf[BUFSZ - 1] = '\0'; /* sanity */
  14.      paniclog("impossible", pbuf);
  15.      pline("%s", pbuf);
  16.      pline("Program in disorder - perhaps you'd better #quit.");
  17.      program_state.in_impossible = 0;
  18.      VA_END();
  19.  }
  20.  

align_str

  1.  const char *
  2.  align_str(alignment)
  3.  aligntyp alignment;
  4.  {
  5.      switch ((int) alignment) {
  6.      case A_CHAOTIC:
  7.          return "chaotic";
  8.      case A_NEUTRAL:
  9.          return "neutral";
  10.      case A_LAWFUL:
  11.          return "lawful";
  12.      case A_NONE:
  13.          return "unaligned";
  14.      }
  15.      return "unknown";
  16.  }
  17.  

mstatusline

  1.  void
  2.  mstatusline(mtmp)
  3.  register struct monst *mtmp;
  4.  {
  5.      aligntyp alignment = mon_aligntyp(mtmp);
  6.      char info[BUFSZ], monnambuf[BUFSZ];
  7.  
  8.      info[0] = 0;
  9.      if (mtmp->mtame) {
  10.          Strcat(info, ", tame");
  11.          if (wizard) {
  12.              Sprintf(eos(info), " (%d", mtmp->mtame);
  13.              if (!mtmp->isminion)
  14.                  Sprintf(eos(info), "; hungry %ld; apport %d",
  15.                          EDOG(mtmp)->hungrytime, EDOG(mtmp)->apport);
  16.              Strcat(info, ")");
  17.          }
  18.      } else if (mtmp->mpeaceful)
  19.          Strcat(info, ", peaceful");
  20.      if (mtmp->cham >= LOW_PM && mtmp->data != &mons[mtmp->cham])
  21.          /* don't reveal the innate form (chameleon, vampire, &c),
  22.             just expose the fact that this current form isn't it */
  23.          Strcat(info, ", shapechanger");
  24.      /* pets eating mimic corpses mimic while eating, so this comes first */
  25.      if (mtmp->meating)
  26.          Strcat(info, ", eating");
  27.      /* a stethoscope exposes mimic before getting here so this
  28.         won't be relevant for it, but wand of probing doesn't */
  29.      if (mtmp->m_ap_type)
  30.          Sprintf(eos(info), ", mimicking %s",
  31.                  (mtmp->m_ap_type == M_AP_FURNITURE)
  32.                      ? an(defsyms[mtmp->mappearance].explanation)
  33.                      : (mtmp->m_ap_type == M_AP_OBJECT)
  34.                            ? ((mtmp->mappearance == GOLD_PIECE)
  35.                                   ? "gold"
  36.                                   : an(simple_typename(mtmp->mappearance)))
  37.                            : (mtmp->m_ap_type == M_AP_MONSTER)
  38.                                  ? an(mons[mtmp->mappearance].mname)
  39.                                  : something); /* impossible... */
  40.      if (mtmp->mcan)
  41.          Strcat(info, ", cancelled");
  42.      if (mtmp->mconf)
  43.          Strcat(info, ", confused");
  44.      if (mtmp->mblinded || !mtmp->mcansee)
  45.          Strcat(info, ", blind");
  46.      if (mtmp->mstun)
  47.          Strcat(info, ", stunned");
  48.      if (mtmp->msleeping)
  49.          Strcat(info, ", asleep");
  50.  #if 0 /* unfortunately mfrozen covers temporary sleep and being busy \
  51.           (donning armor, for instance) as well as paralysis */
  52.  	else if (mtmp->mfrozen)	  Strcat(info, ", paralyzed");
  53.  #else
  54.      else if (mtmp->mfrozen || !mtmp->mcanmove)
  55.          Strcat(info, ", can't move");
  56.  #endif
  57.      /* [arbitrary reason why it isn't moving] */
  58.      else if (mtmp->mstrategy & STRAT_WAITMASK)
  59.          Strcat(info, ", meditating");
  60.      if (mtmp->mflee)
  61.          Strcat(info, ", scared");
  62.      if (mtmp->mtrapped)
  63.          Strcat(info, ", trapped");
  64.      if (mtmp->mspeed)
  65.          Strcat(info, mtmp->mspeed == MFAST ? ", fast" : mtmp->mspeed == MSLOW
  66.                                                              ? ", slow"
  67.                                                              : ", ???? speed");
  68.      if (mtmp->mundetected)
  69.          Strcat(info, ", concealed");
  70.      if (mtmp->minvis)
  71.          Strcat(info, ", invisible");
  72.      if (mtmp == u.ustuck)
  73.          Strcat(info, sticks(youmonst.data)
  74.                           ? ", held by you"
  75.                           : !u.uswallow ? ", holding you"
  76.                                         : attacktype_fordmg(u.ustuck->data,
  77.                                                             AT_ENGL, AD_DGST)
  78.                                               ? ", digesting you"
  79.                                               : is_animal(u.ustuck->data)
  80.                                                     ? ", swallowing you"
  81.                                                     : ", engulfing you");
  82.      if (mtmp == u.usteed)
  83.          Strcat(info, ", carrying you");
  84.  
  85.      /* avoid "Status of the invisible newt ..., invisible" */
  86.      /* and unlike a normal mon_nam, use "saddled" even if it has a name */
  87.      Strcpy(monnambuf, x_monnam(mtmp, ARTICLE_THE, (char *) 0,
  88.                                 (SUPPRESS_IT | SUPPRESS_INVISIBLE), FALSE));
  89.  
  90.      pline("Status of %s (%s):  Level %d  HP %d(%d)  AC %d%s.", monnambuf,
  91.            align_str(alignment), mtmp->m_lev, mtmp->mhp, mtmp->mhpmax,
  92.            find_mac(mtmp), info);
  93.  }
  94.  

ustatusline

  1.  void
  2.  ustatusline()
  3.  {
  4.      char info[BUFSZ];
  5.  
  6.      info[0] = '\0';
  7.      if (Sick) {
  8.          Strcat(info, ", dying from");
  9.          if (u.usick_type & SICK_VOMITABLE)
  10.              Strcat(info, " food poisoning");
  11.          if (u.usick_type & SICK_NONVOMITABLE) {
  12.              if (u.usick_type & SICK_VOMITABLE)
  13.                  Strcat(info, " and");
  14.              Strcat(info, " illness");
  15.          }
  16.      }
  17.      if (Stoned)
  18.          Strcat(info, ", solidifying");
  19.      if (Slimed)
  20.          Strcat(info, ", becoming slimy");
  21.      if (Strangled)
  22.          Strcat(info, ", being strangled");
  23.      if (Vomiting)
  24.          Strcat(info, ", nauseated"); /* !"nauseous" */
  25.      if (Confusion)
  26.          Strcat(info, ", confused");
  27.      if (Blind) {
  28.          Strcat(info, ", blind");
  29.          if (u.ucreamed) {
  30.              if ((long) u.ucreamed < Blinded || Blindfolded
  31.                  || !haseyes(youmonst.data))
  32.                  Strcat(info, ", cover");
  33.              Strcat(info, "ed by sticky goop");
  34.          } /* note: "goop" == "glop"; variation is intentional */
  35.      }
  36.      if (Stunned)
  37.          Strcat(info, ", stunned");
  38.      if (!u.usteed && Wounded_legs) {
  39.          const char *what = body_part(LEG);
  40.          if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
  41.              what = makeplural(what);
  42.          Sprintf(eos(info), ", injured %s", what);
  43.      }
  44.      if (Glib)
  45.          Sprintf(eos(info), ", slippery %s", makeplural(body_part(HAND)));
  46.      if (u.utrap)
  47.          Strcat(info, ", trapped");
  48.      if (Fast)
  49.          Strcat(info, Very_fast ? ", very fast" : ", fast");
  50.      if (u.uundetected)
  51.          Strcat(info, ", concealed");
  52.      if (Invis)
  53.          Strcat(info, ", invisible");
  54.      if (u.ustuck) {
  55.          if (sticks(youmonst.data))
  56.              Strcat(info, ", holding ");
  57.          else
  58.              Strcat(info, ", held by ");
  59.          Strcat(info, mon_nam(u.ustuck));
  60.      }
  61.  
  62.      pline("Status of %s (%s%s):  Level %d  HP %d(%d)  AC %d%s.", plname,
  63.            (u.ualign.record >= 20)
  64.                ? "piously "
  65.                : (u.ualign.record > 13)
  66.                      ? "devoutly "
  67.                      : (u.ualign.record > 8)
  68.                            ? "fervently "
  69.                            : (u.ualign.record > 3)
  70.                                  ? "stridently "
  71.                                  : (u.ualign.record == 3)
  72.                                        ? ""
  73.                                        : (u.ualign.record >= 1)
  74.                                              ? "haltingly "
  75.                                              : (u.ualign.record == 0)
  76.                                                    ? "nominally "
  77.                                                    : "insufficiently ",
  78.            align_str(u.ualign.type),
  79.            Upolyd ? mons[u.umonnum].mlevel : u.ulevel, Upolyd ? u.mh : u.uhp,
  80.            Upolyd ? u.mhmax : u.uhpmax, u.uac, info);
  81.  }
  82.  

self_invis_message

  1.  void
  2.  self_invis_message()
  3.  {
  4.      pline("%s %s.",
  5.            Hallucination ? "Far out, man!  You" : "Gee!  All of a sudden, you",
  6.            See_invisible ? "can see right through yourself"
  7.                          : "can't see yourself");
  8.  }
  9.  

pudding_merge_message

  1.  void
  2.  pudding_merge_message(otmp, otmp2)
  3.  struct obj *otmp;
  4.  struct obj *otmp2;
  5.  {
  6.      boolean visible =
  7.          cansee(otmp->ox, otmp->oy) || cansee(otmp2->ox, otmp2->oy);
  8.      boolean onfloor = otmp->where == OBJ_FLOOR || otmp2->where == OBJ_FLOOR;
  9.      boolean inpack = carried(otmp) || carried(otmp2);
  10.  
  11.      /* the player will know something happened inside his own inventory */
  12.      if ((!Blind && visible) || inpack) {
  13.          if (Hallucination) {
  14.              if (onfloor) {
  15.                  You_see("parts of the floor melting!");
  16.              } else if (inpack) {
  17.                  Your("pack reaches out and grabs something!");
  18.              }
  19.              /* even though we can see where they should be,
  20.               * they'll be out of our view (minvent or container)
  21.               * so don't actually show anything */
  22.          } else if (onfloor || inpack) {
  23.              pline("The %s coalesce%s.", makeplural(obj_typename(otmp->otyp)),
  24.                    inpack ? " inside your pack" : "");
  25.          }
  26.      } else {
  27.          You_hear("a faint sloshing sound.");
  28.      }
  29.  }
  30.  
  31.  /*pline.c*/