Source:NetHack 3.6.0/src/sounds.c

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

Below is the full text to sounds.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/sounds.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	sounds.c	$NHDT-Date: 1446713641 2015/11/05 08:54:01 $  $NHDT-Branch: master $:$NHDT-Revision: 1.74 $ */
  2.  /*      Copyright (c) 1989 Janet Walz, Mike Threepoint */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  STATIC_DCL boolean FDECL(mon_is_gecko, (struct monst *));
  8.  STATIC_DCL int FDECL(domonnoise, (struct monst *));
  9.  STATIC_DCL int NDECL(dochat);
  10.  STATIC_DCL int FDECL(mon_in_room, (struct monst *, int));
  11.  

mon_in_room

  1.  /* this easily could be a macro, but it might overtax dumb compilers */
  2.  STATIC_OVL int
  3.  mon_in_room(mon, rmtyp)
  4.  struct monst *mon;
  5.  int rmtyp;
  6.  {
  7.      int rno = levl[mon->mx][mon->my].roomno;
  8.      if (rno >= ROOMOFFSET)
  9.          return rooms[rno - ROOMOFFSET].rtype == rmtyp;
  10.      return FALSE;
  11.  }
  12.  

dosounds

  1.  void
  2.  dosounds()
  3.  {
  4.      register struct mkroom *sroom;
  5.      register int hallu, vx, vy;
  6.  #if defined(AMIGA) && defined(AZTEC_C_WORKAROUND)
  7.      int xx;
  8.  #endif
  9.      struct monst *mtmp;
  10.  
  11.      if (Deaf || !flags.acoustics || u.uswallow || Underwater)
  12.          return;
  13.  
  14.      hallu = Hallucination ? 1 : 0;
  15.  
  16.      if (level.flags.nfountains && !rn2(400)) {
  17.          static const char *const fountain_msg[4] = {
  18.              "bubbling water.", "water falling on coins.",
  19.              "the splashing of a naiad.", "a soda fountain!",
  20.          };
  21.          You_hear1(fountain_msg[rn2(3) + hallu]);
  22.      }
  23.      if (level.flags.nsinks && !rn2(300)) {
  24.          static const char *const sink_msg[3] = {
  25.              "a slow drip.", "a gurgling noise.", "dishes being washed!",
  26.          };
  27.          You_hear1(sink_msg[rn2(2) + hallu]);
  28.      }
  29.      if (level.flags.has_court && !rn2(200)) {
  30.          static const char *const throne_msg[4] = {
  31.              "the tones of courtly conversation.",
  32.              "a sceptre pounded in judgment.",
  33.              "Someone shouts \"Off with %s head!\"", "Queen Beruthiel's cats!",
  34.          };
  35.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  36.              if (DEADMONSTER(mtmp))
  37.                  continue;
  38.              if ((mtmp->msleeping || is_lord(mtmp->data)
  39.                   || is_prince(mtmp->data)) && !is_animal(mtmp->data)
  40.                  && mon_in_room(mtmp, COURT)) {
  41.                  /* finding one is enough, at least for now */
  42.                  int which = rn2(3) + hallu;
  43.  
  44.                  if (which != 2)
  45.                      You_hear1(throne_msg[which]);
  46.                  else
  47.                      pline(throne_msg[2], uhis());
  48.                  return;
  49.              }
  50.          }
  51.      }
  52.      if (level.flags.has_swamp && !rn2(200)) {
  53.          static const char *const swamp_msg[3] = {
  54.              "hear mosquitoes!", "smell marsh gas!", /* so it's a smell...*/
  55.              "hear Donald Duck!",
  56.          };
  57.          You1(swamp_msg[rn2(2) + hallu]);
  58.          return;
  59.      }
  60.      if (level.flags.has_vault && !rn2(200)) {
  61.          if (!(sroom = search_special(VAULT))) {
  62.              /* strange ... */
  63.              level.flags.has_vault = 0;
  64.              return;
  65.          }
  66.          if (gd_sound())
  67.              switch (rn2(2) + hallu) {
  68.              case 1: {
  69.                  boolean gold_in_vault = FALSE;
  70.  
  71.                  for (vx = sroom->lx; vx <= sroom->hx; vx++)
  72.                      for (vy = sroom->ly; vy <= sroom->hy; vy++)
  73.                          if (g_at(vx, vy))
  74.                              gold_in_vault = TRUE;
  75.  #if defined(AMIGA) && defined(AZTEC_C_WORKAROUND)
  76.                  /* Bug in aztec assembler here. Workaround below */
  77.                  xx = ROOM_INDEX(sroom) + ROOMOFFSET;
  78.                  xx = (xx != vault_occupied(u.urooms));
  79.                  if (xx)
  80.  #else
  81.                  if (vault_occupied(u.urooms)
  82.                      != (ROOM_INDEX(sroom) + ROOMOFFSET))
  83.  #endif /* AZTEC_C_WORKAROUND */
  84.                  {
  85.                      if (gold_in_vault)
  86.                          You_hear(!hallu
  87.                                       ? "someone counting money."
  88.                                       : "the quarterback calling the play.");
  89.                      else
  90.                          You_hear("someone searching.");
  91.                      break;
  92.                  }
  93.                  /* fall into... (yes, even for hallucination) */
  94.              }
  95.              case 0:
  96.                  You_hear("the footsteps of a guard on patrol.");
  97.                  break;
  98.              case 2:
  99.                  You_hear("Ebenezer Scrooge!");
  100.                  break;
  101.              }
  102.          return;
  103.      }
  104.      if (level.flags.has_beehive && !rn2(200)) {
  105.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  106.              if (DEADMONSTER(mtmp))
  107.                  continue;
  108.              if ((mtmp->data->mlet == S_ANT && is_flyer(mtmp->data))
  109.                  && mon_in_room(mtmp, BEEHIVE)) {
  110.                  switch (rn2(2) + hallu) {
  111.                  case 0:
  112.                      You_hear("a low buzzing.");
  113.                      break;
  114.                  case 1:
  115.                      You_hear("an angry drone.");
  116.                      break;
  117.                  case 2:
  118.                      You_hear("bees in your %sbonnet!",
  119.                               uarmh ? "" : "(nonexistent) ");
  120.                      break;
  121.                  }
  122.                  return;
  123.              }
  124.          }
  125.      }
  126.      if (level.flags.has_morgue && !rn2(200)) {
  127.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  128.              if (DEADMONSTER(mtmp))
  129.                  continue;
  130.              if ((is_undead(mtmp->data) || is_vampshifter(mtmp))
  131.                  && mon_in_room(mtmp, MORGUE)) {
  132.                  const char *hair = body_part(HAIR); /* hair/fur/scales */
  133.  
  134.                  switch (rn2(2) + hallu) {
  135.                  case 0:
  136.                      You("suddenly realize it is unnaturally quiet.");
  137.                      break;
  138.                  case 1:
  139.                      pline_The("%s on the back of your %s %s up.", hair,
  140.                                body_part(NECK), vtense(hair, "stand"));
  141.                      break;
  142.                  case 2:
  143.                      pline_The("%s on your %s %s to stand up.", hair,
  144.                                body_part(HEAD), vtense(hair, "seem"));
  145.                      break;
  146.                  }
  147.                  return;
  148.              }
  149.          }
  150.      }
  151.      if (level.flags.has_barracks && !rn2(200)) {
  152.          static const char *const barracks_msg[4] = {
  153.              "blades being honed.", "loud snoring.", "dice being thrown.",
  154.              "General MacArthur!",
  155.          };
  156.          int count = 0;
  157.  
  158.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  159.              if (DEADMONSTER(mtmp))
  160.                  continue;
  161.              if (is_mercenary(mtmp->data)
  162.  #if 0 /* don't bother excluding these */
  163.                  && !strstri(mtmp->data->mname, "watch")
  164.                  && !strstri(mtmp->data->mname, "guard")
  165.  #endif
  166.                  && mon_in_room(mtmp, BARRACKS)
  167.                  /* sleeping implies not-yet-disturbed (usually) */
  168.                  && (mtmp->msleeping || ++count > 5)) {
  169.                  You_hear1(barracks_msg[rn2(3) + hallu]);
  170.                  return;
  171.              }
  172.          }
  173.      }
  174.      if (level.flags.has_zoo && !rn2(200)) {
  175.          static const char *const zoo_msg[3] = {
  176.              "a sound reminiscent of an elephant stepping on a peanut.",
  177.              "a sound reminiscent of a seal barking.", "Doctor Dolittle!",
  178.          };
  179.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  180.              if (DEADMONSTER(mtmp))
  181.                  continue;
  182.              if ((mtmp->msleeping || is_animal(mtmp->data))
  183.                  && mon_in_room(mtmp, ZOO)) {
  184.                  You_hear1(zoo_msg[rn2(2) + hallu]);
  185.                  return;
  186.              }
  187.          }
  188.      }
  189.      if (level.flags.has_shop && !rn2(200)) {
  190.          if (!(sroom = search_special(ANY_SHOP))) {
  191.              /* strange... */
  192.              level.flags.has_shop = 0;
  193.              return;
  194.          }
  195.          if (tended_shop(sroom)
  196.              && !index(u.ushops, (int) (ROOM_INDEX(sroom) + ROOMOFFSET))) {
  197.              static const char *const shop_msg[3] = {
  198.                  "someone cursing shoplifters.",
  199.                  "the chime of a cash register.", "Neiman and Marcus arguing!",
  200.              };
  201.              You_hear1(shop_msg[rn2(2) + hallu]);
  202.          }
  203.          return;
  204.      }
  205.      if (level.flags.has_temple && !rn2(200)
  206.          && !(Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) {
  207.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  208.              if (DEADMONSTER(mtmp))
  209.                  continue;
  210.              if (mtmp->ispriest && inhistemple(mtmp)
  211.                  /* priest must be active */
  212.                  && mtmp->mcanmove && !mtmp->msleeping
  213.                  /* hero must be outside this temple */
  214.                  && temple_occupied(u.urooms) != EPRI(mtmp)->shroom)
  215.                  break;
  216.          }
  217.          if (mtmp) {
  218.              /* Generic temple messages; no attempt to match topic or tone
  219.                 to the pantheon involved, let alone to the specific deity.
  220.                 These are assumed to be coming from the attending priest;
  221.                 asterisk means that the priest must be capable of speech;
  222.                 pound sign (octathorpe,&c--don't go there) means that the
  223.                 priest and the altar must not be directly visible (we don't
  224.                 care if telepathy or extended detection reveals that the
  225.                 priest is not currently standing on the altar; he's mobile). */
  226.              static const char *const temple_msg[] = {
  227.                  "*someone praising %s.", "*someone beseeching %s.",
  228.                  "#an animal carcass being offered in sacrifice.",
  229.                  "*a strident plea for donations.",
  230.              };
  231.              const char *msg;
  232.              int trycount = 0, ax = EPRI(mtmp)->shrpos.x,
  233.                  ay = EPRI(mtmp)->shrpos.y;
  234.              boolean speechless = (mtmp->data->msound <= MS_ANIMAL),
  235.                      in_sight = canseemon(mtmp) || cansee(ax, ay);
  236.  
  237.              do {
  238.                  msg = temple_msg[rn2(SIZE(temple_msg) - 1 + hallu)];
  239.                  if (index(msg, '*') && speechless)
  240.                      continue;
  241.                  if (index(msg, '#') && in_sight)
  242.                      continue;
  243.                  break; /* msg is acceptable */
  244.              } while (++trycount < 50);
  245.              while (!letter(*msg))
  246.                  ++msg; /* skip control flags */
  247.              if (index(msg, '%'))
  248.                  You_hear(msg, halu_gname(EPRI(mtmp)->shralign));
  249.              else
  250.                  You_hear1(msg);
  251.              return;
  252.          }
  253.      }
  254.      if (Is_oracle_level(&u.uz) && !rn2(400)) {
  255.          /* make sure the Oracle is still here */
  256.          for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  257.              if (DEADMONSTER(mtmp))
  258.                  continue;
  259.              if (mtmp->data == &mons[PM_ORACLE])
  260.                  break;
  261.          }
  262.          /* and don't produce silly effects when she's clearly visible */
  263.          if (mtmp && (hallu || !canseemon(mtmp))) {
  264.              static const char *const ora_msg[5] = {
  265.                  "a strange wind.",     /* Jupiter at Dodona */
  266.                  "convulsive ravings.", /* Apollo at Delphi */
  267.                  "snoring snakes.",     /* AEsculapius at Epidaurus */
  268.                  "someone say \"No more woodchucks!\"",
  269.                  "a loud ZOT!" /* both rec.humor.oracle */
  270.              };
  271.              You_hear1(ora_msg[rn2(3) + hallu * 2]);
  272.          }
  273.          return;
  274.      }
  275.  }
  276.  

growl_sound

  1.  static const char *const h_sounds[] = {
  2.      "beep",   "boing",   "sing",   "belche", "creak",   "cough",
  3.      "rattle", "ululate", "pop",    "jingle", "sniffle", "tinkle",
  4.      "eep",    "clatter", "hum",    "sizzle", "twitter", "wheeze",
  5.      "rustle", "honk",    "lisp",   "yodel",  "coo",     "burp",
  6.      "moo",    "boom",    "murmur", "oink",   "quack",   "rumble",
  7.      "twang",  "bellow",  "toot",   "gargle", "hoot",    "warble"
  8.  };
  9.  
  10.  const char *
  11.  growl_sound(mtmp)
  12.  register struct monst *mtmp;
  13.  {
  14.      const char *ret;
  15.  
  16.      switch (mtmp->data->msound) {
  17.      case MS_MEW:
  18.      case MS_HISS:
  19.          ret = "hiss";
  20.          break;
  21.      case MS_BARK:
  22.      case MS_GROWL:
  23.          ret = "growl";
  24.          break;
  25.      case MS_ROAR:
  26.          ret = "roar";
  27.          break;
  28.      case MS_BUZZ:
  29.          ret = "buzz";
  30.          break;
  31.      case MS_SQEEK:
  32.          ret = "squeal";
  33.          break;
  34.      case MS_SQAWK:
  35.          ret = "screech";
  36.          break;
  37.      case MS_NEIGH:
  38.          ret = "neigh";
  39.          break;
  40.      case MS_WAIL:
  41.          ret = "wail";
  42.          break;
  43.      case MS_SILENT:
  44.          ret = "commotion";
  45.          break;
  46.      default:
  47.          ret = "scream";
  48.      }
  49.      return ret;
  50.  }
  51.  

growl

  1.  /* the sounds of a seriously abused pet, including player attacking it */
  2.  void
  3.  growl(mtmp)
  4.  register struct monst *mtmp;
  5.  {
  6.      register const char *growl_verb = 0;
  7.  
  8.      if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound)
  9.          return;
  10.  
  11.      /* presumably nearness and soundok checks have already been made */
  12.      if (Hallucination)
  13.          growl_verb = h_sounds[rn2(SIZE(h_sounds))];
  14.      else
  15.          growl_verb = growl_sound(mtmp);
  16.      if (growl_verb) {
  17.          pline("%s %s!", Monnam(mtmp), vtense((char *) 0, growl_verb));
  18.          if (context.run)
  19.              nomul(0);
  20.          wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 18);
  21.      }
  22.  }
  23.  

yelp

  1.  /* the sounds of mistreated pets */
  2.  void
  3.  yelp(mtmp)
  4.  register struct monst *mtmp;
  5.  {
  6.      register const char *yelp_verb = 0;
  7.  
  8.      if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound)
  9.          return;
  10.  
  11.      /* presumably nearness and soundok checks have already been made */
  12.      if (Hallucination)
  13.          yelp_verb = h_sounds[rn2(SIZE(h_sounds))];
  14.      else
  15.          switch (mtmp->data->msound) {
  16.          case MS_MEW:
  17.              yelp_verb = "yowl";
  18.              break;
  19.          case MS_BARK:
  20.          case MS_GROWL:
  21.              yelp_verb = "yelp";
  22.              break;
  23.          case MS_ROAR:
  24.              yelp_verb = "snarl";
  25.              break;
  26.          case MS_SQEEK:
  27.              yelp_verb = "squeal";
  28.              break;
  29.          case MS_SQAWK:
  30.              yelp_verb = "screak";
  31.              break;
  32.          case MS_WAIL:
  33.              yelp_verb = "wail";
  34.              break;
  35.          }
  36.      if (yelp_verb) {
  37.          pline("%s %s!", Monnam(mtmp), vtense((char *) 0, yelp_verb));
  38.          if (context.run)
  39.              nomul(0);
  40.          wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 12);
  41.      }
  42.  }
  43.  

whimper

  1.  /* the sounds of distressed pets */
  2.  void
  3.  whimper(mtmp)
  4.  register struct monst *mtmp;
  5.  {
  6.      register const char *whimper_verb = 0;
  7.  
  8.      if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound)
  9.          return;
  10.  
  11.      /* presumably nearness and soundok checks have already been made */
  12.      if (Hallucination)
  13.          whimper_verb = h_sounds[rn2(SIZE(h_sounds))];
  14.      else
  15.          switch (mtmp->data->msound) {
  16.          case MS_MEW:
  17.          case MS_GROWL:
  18.              whimper_verb = "whimper";
  19.              break;
  20.          case MS_BARK:
  21.              whimper_verb = "whine";
  22.              break;
  23.          case MS_SQEEK:
  24.              whimper_verb = "squeal";
  25.              break;
  26.          }
  27.      if (whimper_verb) {
  28.          pline("%s %s.", Monnam(mtmp), vtense((char *) 0, whimper_verb));
  29.          if (context.run)
  30.              nomul(0);
  31.          wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 6);
  32.      }
  33.  }
  34.  

beg

  1.  /* pet makes "I'm hungry" noises */
  2.  void
  3.  beg(mtmp)
  4.  register struct monst *mtmp;
  5.  {
  6.      if (mtmp->msleeping || !mtmp->mcanmove
  7.          || !(carnivorous(mtmp->data) || herbivorous(mtmp->data)))
  8.          return;
  9.  
  10.      /* presumably nearness and soundok checks have already been made */
  11.      if (!is_silent(mtmp->data) && mtmp->data->msound <= MS_ANIMAL)
  12.          (void) domonnoise(mtmp);
  13.      else if (mtmp->data->msound >= MS_HUMANOID) {
  14.          if (!canspotmon(mtmp))
  15.              map_invisible(mtmp->mx, mtmp->my);
  16.          verbalize("I'm hungry.");
  17.      }
  18.  }
  19.  

mon_is_gecko

  1.  /* return True if mon is a gecko or seems to look like one (hallucination) */
  2.  STATIC_OVL boolean
  3.  mon_is_gecko(mon)
  4.  struct monst *mon;
  5.  {
  6.      int glyph;
  7.  
  8.      /* return True if it is actually a gecko */
  9.      if (mon->data == &mons[PM_GECKO])
  10.          return TRUE;
  11.      /* return False if it is a long worm; we might be chatting to its tail
  12.         (not strictly needed; long worms are MS_SILENT so won't get here) */
  13.      if (mon->data == &mons[PM_LONG_WORM])
  14.          return FALSE;
  15.      /* result depends upon whether map spot shows a gecko, which will
  16.         be due to hallucination or to mimickery since mon isn't one */
  17.      glyph = glyph_at(mon->mx, mon->my);
  18.      return (boolean) (glyph_to_mon(glyph) == PM_GECKO);
  19.  }
  20.  

domonnoise

  1.  STATIC_OVL int
  2.  domonnoise(mtmp)
  3.  register struct monst *mtmp;
  4.  {
  5.      char verbuf[BUFSZ];
  6.      register const char *pline_msg = 0, /* Monnam(mtmp) will be prepended */
  7.          *verbl_msg = 0,                 /* verbalize() */
  8.              *verbl_msg_mcan = 0;        /* verbalize() if cancelled */
  9.      struct permonst *ptr = mtmp->data;
  10.      int msound = ptr->msound;
  11.  
  12.      /* presumably nearness and sleep checks have already been made */
  13.      if (Deaf)
  14.          return 0;
  15.      if (is_silent(ptr))
  16.          return 0;
  17.  
  18.      /* leader might be poly'd; if he can still speak, give leader speech */
  19.      if (mtmp->m_id == quest_status.leader_m_id && msound > MS_ANIMAL)
  20.          msound = MS_LEADER;
  21.      /* make sure it's your role's quest guardian; adjust if not */
  22.      else if (msound == MS_GUARDIAN && ptr != &mons[urole.guardnum])
  23.          msound = mons[genus(monsndx(ptr), 1)].msound;
  24.      /* some normally non-speaking types can/will speak if hero is similar */
  25.      else if (msound == MS_ORC         /* note: MS_ORC is same as MS_GRUNT */
  26.               && (same_race(ptr, youmonst.data)           /* current form, */
  27.                   || same_race(ptr, &mons[Race_switch]))) /* unpoly'd form */
  28.          msound = MS_HUMANOID;
  29.      /* silliness, with slight chance to interfere with shopping */
  30.      else if (Hallucination && mon_is_gecko(mtmp))
  31.          msound = MS_SELL;
  32.  
  33.      /* be sure to do this before talking; the monster might teleport away, in
  34.       * which case we want to check its pre-teleport position
  35.       */
  36.      if (!canspotmon(mtmp))
  37.          map_invisible(mtmp->mx, mtmp->my);
  38.  
  39.      switch (msound) {
  40.      case MS_ORACLE:
  41.          return doconsult(mtmp);
  42.      case MS_PRIEST:
  43.          priest_talk(mtmp);
  44.          break;
  45.      case MS_LEADER:
  46.      case MS_NEMESIS:
  47.      case MS_GUARDIAN:
  48.          quest_chat(mtmp);
  49.          break;
  50.      case MS_SELL: /* pitch, pay, total */
  51.          if (!Hallucination || (mtmp->isshk && !rn2(2))) {
  52.              shk_chat(mtmp);
  53.          } else {
  54.              /* approximation of GEICO's advertising slogan (it actually
  55.                 concludes with "save you 15% or more on car insurance.") */
  56.              Sprintf(verbuf, "15 minutes could save you 15 %s.",
  57.                      currency(15L)); /* "zorkmids" */
  58.              verbl_msg = verbuf;
  59.          }
  60.          break;
  61.      case MS_VAMPIRE: {
  62.          /* vampire messages are varied by tameness, peacefulness, and time of
  63.           * night */
  64.          boolean isnight = night();
  65.          boolean kindred = (Upolyd && (u.umonnum == PM_VAMPIRE
  66.                                        || u.umonnum == PM_VAMPIRE_LORD));
  67.          boolean nightchild =
  68.              (Upolyd && (u.umonnum == PM_WOLF || u.umonnum == PM_WINTER_WOLF
  69.                          || u.umonnum == PM_WINTER_WOLF_CUB));
  70.          const char *racenoun =
  71.              (flags.female && urace.individual.f)
  72.                  ? urace.individual.f
  73.                  : (urace.individual.m) ? urace.individual.m : urace.noun;
  74.  
  75.          if (mtmp->mtame) {
  76.              if (kindred) {
  77.                  Sprintf(verbuf, "Good %s to you Master%s",
  78.                          isnight ? "evening" : "day",
  79.                          isnight ? "!" : ".  Why do we not rest?");
  80.                  verbl_msg = verbuf;
  81.              } else {
  82.                  Sprintf(verbuf, "%s%s",
  83.                          nightchild ? "Child of the night, " : "",
  84.                          midnight()
  85.                           ? "I can stand this craving no longer!"
  86.                           : isnight
  87.                            ? "I beg you, help me satisfy this growing craving!"
  88.                            : "I find myself growing a little weary.");
  89.                  verbl_msg = verbuf;
  90.              }
  91.          } else if (mtmp->mpeaceful) {
  92.              if (kindred && isnight) {
  93.                  Sprintf(verbuf, "Good feeding %s!",
  94.                          flags.female ? "sister" : "brother");
  95.                  verbl_msg = verbuf;
  96.              } else if (nightchild && isnight) {
  97.                  Sprintf(verbuf, "How nice to hear you, child of the night!");
  98.                  verbl_msg = verbuf;
  99.              } else
  100.                  verbl_msg = "I only drink... potions.";
  101.          } else {
  102.              int vampindex;
  103.              static const char *const vampmsg[] = {
  104.                  /* These first two (0 and 1) are specially handled below */
  105.                  "I vant to suck your %s!",
  106.                  "I vill come after %s without regret!",
  107.                  /* other famous vampire quotes can follow here if desired */
  108.              };
  109.              if (kindred)
  110.                  verbl_msg =
  111.                      "This is my hunting ground that you dare to prowl!";
  112.              else if (youmonst.data == &mons[PM_SILVER_DRAGON]
  113.                       || youmonst.data == &mons[PM_BABY_SILVER_DRAGON]) {
  114.                  /* Silver dragons are silver in color, not made of silver */
  115.                  Sprintf(verbuf, "%s! Your silver sheen does not frighten me!",
  116.                          youmonst.data == &mons[PM_SILVER_DRAGON]
  117.                              ? "Fool"
  118.                              : "Young Fool");
  119.                  verbl_msg = verbuf;
  120.              } else {
  121.                  vampindex = rn2(SIZE(vampmsg));
  122.                  if (vampindex == 0) {
  123.                      Sprintf(verbuf, vampmsg[vampindex], body_part(BLOOD));
  124.                      verbl_msg = verbuf;
  125.                  } else if (vampindex == 1) {
  126.                      Sprintf(verbuf, vampmsg[vampindex],
  127.                              Upolyd ? an(mons[u.umonnum].mname)
  128.                                     : an(racenoun));
  129.                      verbl_msg = verbuf;
  130.                  } else
  131.                      verbl_msg = vampmsg[vampindex];
  132.              }
  133.          }
  134.      } break;
  135.      case MS_WERE:
  136.          if (flags.moonphase == FULL_MOON && (night() ^ !rn2(13))) {
  137.              pline("%s throws back %s head and lets out a blood curdling %s!",
  138.                    Monnam(mtmp), mhis(mtmp),
  139.                    ptr == &mons[PM_HUMAN_WERERAT] ? "shriek" : "howl");
  140.              wake_nearto(mtmp->mx, mtmp->my, 11 * 11);
  141.          } else
  142.              pline_msg =
  143.                  "whispers inaudibly.  All you can make out is \"moon\".";
  144.          break;
  145.      case MS_BARK:
  146.          if (flags.moonphase == FULL_MOON && night()) {
  147.              pline_msg = "howls.";
  148.          } else if (mtmp->mpeaceful) {
  149.              if (mtmp->mtame
  150.                  && (mtmp->mconf || mtmp->mflee || mtmp->mtrapped
  151.                      || moves > EDOG(mtmp)->hungrytime || mtmp->mtame < 5))
  152.                  pline_msg = "whines.";
  153.              else if (mtmp->mtame && EDOG(mtmp)->hungrytime > moves + 1000)
  154.                  pline_msg = "yips.";
  155.              else {
  156.                  if (mtmp->data
  157.                      != &mons[PM_DINGO]) /* dingos do not actually bark */
  158.                      pline_msg = "barks.";
  159.              }
  160.          } else {
  161.              pline_msg = "growls.";
  162.          }
  163.          break;
  164.      case MS_MEW:
  165.          if (mtmp->mtame) {
  166.              if (mtmp->mconf || mtmp->mflee || mtmp->mtrapped
  167.                  || mtmp->mtame < 5)
  168.                  pline_msg = "yowls.";
  169.              else if (moves > EDOG(mtmp)->hungrytime)
  170.                  pline_msg = "meows.";
  171.              else if (EDOG(mtmp)->hungrytime > moves + 1000)
  172.                  pline_msg = "purrs.";
  173.              else
  174.                  pline_msg = "mews.";
  175.              break;
  176.          } /* else FALLTHRU */
  177.      case MS_GROWL:
  178.          pline_msg = mtmp->mpeaceful ? "snarls." : "growls!";
  179.          break;
  180.      case MS_ROAR:
  181.          pline_msg = mtmp->mpeaceful ? "snarls." : "roars!";
  182.          break;
  183.      case MS_SQEEK:
  184.          pline_msg = "squeaks.";
  185.          break;
  186.      case MS_SQAWK:
  187.          if (ptr == &mons[PM_RAVEN] && !mtmp->mpeaceful)
  188.              verbl_msg = "Nevermore!";
  189.          else
  190.              pline_msg = "squawks.";
  191.          break;
  192.      case MS_HISS:
  193.          if (!mtmp->mpeaceful)
  194.              pline_msg = "hisses!";
  195.          else
  196.              return 0; /* no sound */
  197.          break;
  198.      case MS_BUZZ:
  199.          pline_msg = mtmp->mpeaceful ? "drones." : "buzzes angrily.";
  200.          break;
  201.      case MS_GRUNT:
  202.          pline_msg = "grunts.";
  203.          break;
  204.      case MS_NEIGH:
  205.          if (mtmp->mtame < 5)
  206.              pline_msg = "neighs.";
  207.          else if (moves > EDOG(mtmp)->hungrytime)
  208.              pline_msg = "whinnies.";
  209.          else
  210.              pline_msg = "whickers.";
  211.          break;
  212.      case MS_WAIL:
  213.          pline_msg = "wails mournfully.";
  214.          break;
  215.      case MS_GURGLE:
  216.          pline_msg = "gurgles.";
  217.          break;
  218.      case MS_BURBLE:
  219.          pline_msg = "burbles.";
  220.          break;
  221.      case MS_SHRIEK:
  222.          pline_msg = "shrieks.";
  223.          aggravate();
  224.          break;
  225.      case MS_IMITATE:
  226.          pline_msg = "imitates you.";
  227.          break;
  228.      case MS_BONES:
  229.          pline("%s rattles noisily.", Monnam(mtmp));
  230.          You("freeze for a moment.");
  231.          nomul(-2);
  232.          multi_reason = "scared by rattling";
  233.          nomovemsg = 0;
  234.          break;
  235.      case MS_LAUGH: {
  236.          static const char *const laugh_msg[4] = {
  237.              "giggles.", "chuckles.", "snickers.", "laughs.",
  238.          };
  239.          pline_msg = laugh_msg[rn2(4)];
  240.      } break;
  241.      case MS_MUMBLE:
  242.          pline_msg = "mumbles incomprehensibly.";
  243.          break;
  244.      case MS_DJINNI:
  245.          if (mtmp->mtame) {
  246.              verbl_msg = "Sorry, I'm all out of wishes.";
  247.          } else if (mtmp->mpeaceful) {
  248.              if (ptr == &mons[PM_WATER_DEMON])
  249.                  pline_msg = "gurgles.";
  250.              else
  251.                  verbl_msg = "I'm free!";
  252.          } else {
  253.              if (ptr != &mons[PM_PRISONER])
  254.                  verbl_msg = "This will teach you not to disturb me!";
  255.  #if 0
  256.              else
  257.                  verbl_msg = "??????????";
  258.  #endif
  259.          }
  260.          break;
  261.      case MS_BOAST: /* giants */
  262.          if (!mtmp->mpeaceful) {
  263.              switch (rn2(4)) {
  264.              case 0:
  265.                  pline("%s boasts about %s gem collection.", Monnam(mtmp),
  266.                        mhis(mtmp));
  267.                  break;
  268.              case 1:
  269.                  pline_msg = "complains about a diet of mutton.";
  270.                  break;
  271.              default:
  272.                  pline_msg = "shouts \"Fee Fie Foe Foo!\" and guffaws.";
  273.                  wake_nearto(mtmp->mx, mtmp->my, 7 * 7);
  274.                  break;
  275.              }
  276.              break;
  277.          }
  278.      /* else FALLTHRU */
  279.      case MS_HUMANOID:
  280.          if (!mtmp->mpeaceful) {
  281.              if (In_endgame(&u.uz) && is_mplayer(ptr))
  282.                  mplayer_talk(mtmp);
  283.              else
  284.                  pline_msg = "threatens you.";
  285.              break;
  286.          }
  287.          /* Generic peaceful humanoid behaviour. */
  288.          if (mtmp->mflee)
  289.              pline_msg = "wants nothing to do with you.";
  290.          else if (mtmp->mhp < mtmp->mhpmax / 4)
  291.              pline_msg = "moans.";
  292.          else if (mtmp->mconf || mtmp->mstun)
  293.              verbl_msg = !rn2(3) ? "Huh?" : rn2(2) ? "What?" : "Eh?";
  294.          else if (!mtmp->mcansee)
  295.              verbl_msg = "I can't see!";
  296.          else if (mtmp->mtrapped) {
  297.              struct trap *t = t_at(mtmp->mx, mtmp->my);
  298.  
  299.              if (t)
  300.                  t->tseen = 1;
  301.              verbl_msg = "I'm trapped!";
  302.          } else if (mtmp->mhp < mtmp->mhpmax / 2)
  303.              pline_msg = "asks for a potion of healing.";
  304.          else if (mtmp->mtame && !mtmp->isminion
  305.                   && moves > EDOG(mtmp)->hungrytime)
  306.              verbl_msg = "I'm hungry.";
  307.          /* Specific monsters' interests */
  308.          else if (is_elf(ptr))
  309.              pline_msg = "curses orcs.";
  310.          else if (is_dwarf(ptr))
  311.              pline_msg = "talks about mining.";
  312.          else if (likes_magic(ptr))
  313.              pline_msg = "talks about spellcraft.";
  314.          else if (ptr->mlet == S_CENTAUR)
  315.              pline_msg = "discusses hunting.";
  316.          else
  317.              switch (monsndx(ptr)) {
  318.              case PM_HOBBIT:
  319.                  pline_msg =
  320.                      (mtmp->mhpmax - mtmp->mhp >= 10)
  321.                          ? "complains about unpleasant dungeon conditions."
  322.                          : "asks you about the One Ring.";
  323.                  break;
  324.              case PM_ARCHEOLOGIST:
  325.                  pline_msg =
  326.                  "describes a recent article in \"Spelunker Today\" magazine.";
  327.                  break;
  328.              case PM_TOURIST:
  329.                  verbl_msg = "Aloha.";
  330.                  break;
  331.              default:
  332.                  pline_msg = "discusses dungeon exploration.";
  333.                  break;
  334.              }
  335.          break;
  336.      case MS_SEDUCE: {
  337.          int swval;
  338.          if (SYSOPT_SEDUCE) {
  339.              if (ptr->mlet != S_NYMPH
  340.                  && could_seduce(mtmp, &youmonst, (struct attack *) 0) == 1) {
  341.                  (void) doseduce(mtmp);
  342.                  break;
  343.              }
  344.              swval = ((poly_gender() != (int) mtmp->female) ? rn2(3) : 0);
  345.          } else
  346.              swval = ((poly_gender() == 0) ? rn2(3) : 0);
  347.          switch (swval) {
  348.          case 2:
  349.              verbl_msg = "Hello, sailor.";
  350.              break;
  351.          case 1:
  352.              pline_msg = "comes on to you.";
  353.              break;
  354.          default:
  355.              pline_msg = "cajoles you.";
  356.          }
  357.      } break;
  358.      case MS_ARREST:
  359.          if (mtmp->mpeaceful)
  360.              verbalize("Just the facts, %s.", flags.female ? "Ma'am" : "Sir");
  361.          else {
  362.              static const char *const arrest_msg[3] = {
  363.                  "Anything you say can be used against you.",
  364.                  "You're under arrest!", "Stop in the name of the Law!",
  365.              };
  366.              verbl_msg = arrest_msg[rn2(3)];
  367.          }
  368.          break;
  369.      case MS_BRIBE:
  370.          if (mtmp->mpeaceful && !mtmp->mtame) {
  371.              (void) demon_talk(mtmp);
  372.              break;
  373.          }
  374.      /* fall through */
  375.      case MS_CUSS:
  376.          if (!mtmp->mpeaceful)
  377.              cuss(mtmp);
  378.          else if (is_lminion(mtmp))
  379.              verbl_msg = "It's not too late.";
  380.          else
  381.              verbl_msg = "We're all doomed.";
  382.          break;
  383.      case MS_SPELL:
  384.          /* deliberately vague, since it's not actually casting any spell */
  385.          pline_msg = "seems to mutter a cantrip.";
  386.          break;
  387.      case MS_NURSE:
  388.          verbl_msg_mcan = "I hate this job!";
  389.          if (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))
  390.              verbl_msg = "Put that weapon away before you hurt someone!";
  391.          else if (uarmc || uarm || uarmh || uarms || uarmg || uarmf)
  392.              verbl_msg = Role_if(PM_HEALER)
  393.                              ? "Doc, I can't help you unless you cooperate."
  394.                              : "Please undress so I can examine you.";
  395.          else if (uarmu)
  396.              verbl_msg = "Take off your shirt, please.";
  397.          else
  398.              verbl_msg = "Relax, this won't hurt a bit.";
  399.          break;
  400.      case MS_GUARD:
  401.          if (money_cnt(invent))
  402.              verbl_msg = "Please drop that gold and follow me.";
  403.          else
  404.              verbl_msg = "Please follow me.";
  405.          break;
  406.      case MS_SOLDIER: {
  407.          static const char
  408.              *const soldier_foe_msg[3] =
  409.                  {
  410.                    "Resistance is useless!", "You're dog meat!", "Surrender!",
  411.                  },
  412.                     *const soldier_pax_msg[3] = {
  413.                         "What lousy pay we're getting here!",
  414.                         "The food's not fit for Orcs!",
  415.                         "My feet hurt, I've been on them all day!",
  416.                     };
  417.          verbl_msg = mtmp->mpeaceful ? soldier_pax_msg[rn2(3)]
  418.                                      : soldier_foe_msg[rn2(3)];
  419.          break;
  420.      }
  421.      case MS_RIDER:
  422.          /* 3.6.0 tribute */
  423.          if (ptr == &mons[PM_DEATH]
  424.              && !context.tribute.Deathnotice && u_have_novel()) {
  425.              struct obj *book = u_have_novel();
  426.              const char *tribtitle = (char *)0;
  427.  
  428.              if (book) {
  429.                  int novelidx = book->novelidx;
  430.  
  431.                  tribtitle = noveltitle(&novelidx);
  432.              }
  433.              if (tribtitle) {
  434.                  Sprintf(verbuf, "Ah, so you have a copy of /%s/.", tribtitle);
  435.                  /* no Death featured in these two, so exclude them */
  436.                  if (!(strcmpi(tribtitle, "Snuff") == 0
  437.                        || strcmpi(tribtitle, "The Wee Free Men") == 0))
  438.                      Strcat(verbuf, " I may have been misquoted there.");
  439.                  verbl_msg = verbuf;
  440.                  context.tribute.Deathnotice = 1;
  441.              }
  442.          } else if (ptr == &mons[PM_DEATH]
  443.                     && !rn2(2) && Death_quote(verbuf, BUFSZ)) {
  444.                  verbl_msg = verbuf;
  445.          }
  446.          /* end of tribute addition */
  447.          else if (ptr == &mons[PM_DEATH] && !rn2(10))
  448.              pline_msg = "is busy reading a copy of Sandman #8.";
  449.          else
  450.              verbl_msg = "Who do you think you are, War?";
  451.          break;
  452.      }
  453.  
  454.      if (pline_msg)
  455.          pline("%s %s", Monnam(mtmp), pline_msg);
  456.      else if (mtmp->mcan && verbl_msg_mcan)
  457.          verbalize1(verbl_msg_mcan);
  458.      else if (verbl_msg) {
  459.          if (ptr == &mons[PM_DEATH]) {
  460.              /* Death talks in CAPITAL LETTERS
  461.                 and without quotation marks */
  462.              char tmpbuf[BUFSZ];
  463.              Sprintf(tmpbuf, "%s", verbl_msg);
  464.              pline1(ucase(tmpbuf));
  465.          } else {
  466.              verbalize1(verbl_msg);
  467.          }
  468.      }
  469.      return 1;
  470.  }
  471.  

dotalk

  1.  /* #chat command */
  2.  int
  3.  dotalk()
  4.  {
  5.      int result;
  6.  
  7.      result = dochat();
  8.      return result;
  9.  }
  10.  

dochat

  1.  STATIC_OVL int
  2.  dochat()
  3.  {
  4.      struct monst *mtmp;
  5.      int tx, ty;
  6.      struct obj *otmp;
  7.  
  8.      if (is_silent(youmonst.data)) {
  9.          pline("As %s, you cannot speak.", an(youmonst.data->mname));
  10.          return 0;
  11.      }
  12.      if (Strangled) {
  13.          You_cant("speak.  You're choking!");
  14.          return 0;
  15.      }
  16.      if (u.uswallow) {
  17.          pline("They won't hear you out there.");
  18.          return 0;
  19.      }
  20.      if (Underwater) {
  21.          Your("speech is unintelligible underwater.");
  22.          return 0;
  23.      }
  24.      if (Deaf) {
  25.          pline("How can you hold a conversation when you cannot hear?");
  26.          return 0;
  27.      }
  28.  
  29.      if (!Blind && (otmp = shop_object(u.ux, u.uy)) != (struct obj *) 0) {
  30.          /* standing on something in a shop and chatting causes the shopkeeper
  31.             to describe the price(s).  This can inhibit other chatting inside
  32.             a shop, but that shouldn't matter much.  shop_object() returns an
  33.             object iff inside a shop and the shopkeeper is present and willing
  34.             (not angry) and able (not asleep) to speak and the position
  35.             contains any objects other than just gold.
  36.          */
  37.          price_quote(otmp);
  38.          return 1;
  39.      }
  40.  
  41.      if (!getdir("Talk to whom? (in what direction)")) {
  42.          /* decided not to chat */
  43.          return 0;
  44.      }
  45.  
  46.      if (u.usteed && u.dz > 0) {
  47.          if (!u.usteed->mcanmove || u.usteed->msleeping) {
  48.              pline("%s seems not to notice you.", Monnam(u.usteed));
  49.              return 1;
  50.          } else
  51.              return domonnoise(u.usteed);
  52.      }
  53.  
  54.      if (u.dz) {
  55.          pline("They won't hear you %s there.", u.dz < 0 ? "up" : "down");
  56.          return 0;
  57.      }
  58.  
  59.      if (u.dx == 0 && u.dy == 0) {
  60.          /*
  61.           * Let's not include this.
  62.           * It raises all sorts of questions: can you wear
  63.           * 2 helmets, 2 amulets, 3 pairs of gloves or 6 rings as a marilith,
  64.           * etc...  --KAA
  65.          if (u.umonnum == PM_ETTIN) {
  66.              You("discover that your other head makes boring conversation.");
  67.              return 1;
  68.          }
  69.           */
  70.          pline("Talking to yourself is a bad habit for a dungeoneer.");
  71.          return 0;
  72.      }
  73.  
  74.      tx = u.ux + u.dx;
  75.      ty = u.uy + u.dy;
  76.  
  77.      if (!isok(tx, ty))
  78.          return 0;
  79.  
  80.      mtmp = m_at(tx, ty);
  81.  
  82.      if ((!mtmp || mtmp->mundetected)
  83.          && (otmp = vobj_at(tx, ty)) != 0 && otmp->otyp == STATUE) {
  84.          /* Talking to a statue */
  85.          if (!Blind) {
  86.              pline_The("%s seems not to notice you.",
  87.                        /* if hallucinating, you can't tell it's a statue */
  88.                        Hallucination ? rndmonnam((char *) 0) : "statue");
  89.          }
  90.          return 0;
  91.      }
  92.  
  93.      if (!mtmp || mtmp->mundetected || mtmp->m_ap_type == M_AP_FURNITURE
  94.          || mtmp->m_ap_type == M_AP_OBJECT)
  95.          return 0;
  96.  
  97.      /* sleeping monsters won't talk, except priests (who wake up) */
  98.      if ((!mtmp->mcanmove || mtmp->msleeping) && !mtmp->ispriest) {
  99.          /* If it is unseen, the player can't tell the difference between
  100.             not noticing him and just not existing, so skip the message. */
  101.          if (canspotmon(mtmp))
  102.              pline("%s seems not to notice you.", Monnam(mtmp));
  103.          return 0;
  104.      }
  105.  
  106.      /* if this monster is waiting for something, prod it into action */
  107.      mtmp->mstrategy &= ~STRAT_WAITMASK;
  108.  
  109.      if (mtmp->mtame && mtmp->meating) {
  110.          if (!canspotmon(mtmp))
  111.              map_invisible(mtmp->mx, mtmp->my);
  112.          pline("%s is eating noisily.", Monnam(mtmp));
  113.          return 0;
  114.      }
  115.  
  116.      return domonnoise(mtmp);
  117.  }
  118.  

add_sound_mapping

  1.  #ifdef USER_SOUNDS
  2.  
  3.  extern void FDECL(play_usersound, (const char *, int));
  4.  
  5.  typedef struct audio_mapping_rec {
  6.      struct nhregex *regex;
  7.      char *filename;
  8.      int volume;
  9.      struct audio_mapping_rec *next;
  10.  } audio_mapping;
  11.  
  12.  static audio_mapping *soundmap = 0;
  13.  
  14.  char *sounddir = ".";
  15.  
  16.  /* adds a sound file mapping, returns 0 on failure, 1 on success */
  17.  int
  18.  add_sound_mapping(mapping)
  19.  const char *mapping;
  20.  {
  21.      char text[256];
  22.      char filename[256];
  23.      char filespec[256];
  24.      int volume;
  25.  
  26.      if (sscanf(mapping, "MESG \"%255[^\"]\"%*[\t ]\"%255[^\"]\" %d", text,
  27.                 filename, &volume) == 3) {
  28.          audio_mapping *new_map;
  29.  
  30.          if (strlen(sounddir) + strlen(filename) > 254) {
  31.              raw_print("sound file name too long");
  32.              return 0;
  33.          }
  34.          Sprintf(filespec, "%s/%s", sounddir, filename);
  35.  
  36.          if (can_read_file(filespec)) {
  37.              new_map = (audio_mapping *) alloc(sizeof(audio_mapping));
  38.              new_map->regex = regex_init();
  39.              new_map->filename = dupstr(filespec);
  40.              new_map->volume = volume;
  41.              new_map->next = soundmap;
  42.  
  43.              if (!regex_compile(text, new_map->regex)) {
  44.                  raw_print(regex_error_desc(new_map->regex));
  45.                  regex_free(new_map->regex);
  46.                  free(new_map->filename);
  47.                  free(new_map);
  48.                  return 0;
  49.              } else {
  50.                  soundmap = new_map;
  51.              }
  52.          } else {
  53.              Sprintf(text, "cannot read %.243s", filespec);
  54.              raw_print(text);
  55.              return 0;
  56.          }
  57.      } else {
  58.          raw_print("syntax error in SOUND");
  59.          return 0;
  60.      }
  61.  
  62.      return 1;
  63.  }
  64.  

play_sound_for_message

  1.  void
  2.  play_sound_for_message(msg)
  3.  const char *msg;
  4.  {
  5.      audio_mapping *cursor = soundmap;
  6.  
  7.      while (cursor) {
  8.          if (regex_match(msg, cursor->regex)) {
  9.              play_usersound(cursor->filename, cursor->volume);
  10.          }
  11.          cursor = cursor->next;
  12.      }
  13.  }
  14.  
  15.  #endif /* USER_SOUNDS */
  16.  
  17.  /*sounds.c*/