Source:NetHack 3.6.1/src/vault.c

From NetHackWiki
(Redirected from Source:Ref/invault)
Jump to: navigation, search

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

Top of file

  1.  /* NetHack 3.6	vault.c	$NHDT-Date: 1452132199 2016/01/07 02:03:19 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.42 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Robert Patrick Rankin, 2011. */
  4.  /* NetHack may be freely redistributed.  See license for details. */

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

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

  1.  
  2.  #include "hack.h"
  3.  
  4.  STATIC_DCL struct monst *NDECL(findgd);
  5.  
  6.  STATIC_DCL boolean FDECL(clear_fcorr, (struct monst *, BOOLEAN_P));
  7.  STATIC_DCL void FDECL(blackout, (int, int));
  8.  STATIC_DCL void FDECL(restfakecorr, (struct monst *));
  9.  STATIC_DCL boolean FDECL(in_fcorridor, (struct monst *, int, int));
  10.  STATIC_DCL void FDECL(move_gold, (struct obj *, int));
  11.  STATIC_DCL void FDECL(wallify_vault, (struct monst *));
  12.  

newegd

  1.  void
  2.  newegd(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (!mtmp->mextra)
  6.          mtmp->mextra = newmextra();
  7.      if (!EGD(mtmp)) {
  8.          EGD(mtmp) = (struct egd *) alloc(sizeof(struct egd));
  9.          (void) memset((genericptr_t) EGD(mtmp), 0, sizeof(struct egd));
  10.      }
  11.  }
  12.  

free_egd

  1.  void
  2.  free_egd(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      if (mtmp->mextra && EGD(mtmp)) {
  6.          free((genericptr_t) EGD(mtmp));
  7.          EGD(mtmp) = (struct egd *) 0;
  8.      }
  9.      mtmp->isgd = 0;
  10.  }
  11.  

clear_fcorr

  1.  STATIC_OVL boolean
  2.  clear_fcorr(grd, forceshow)
  3.  struct monst *grd;
  4.  boolean forceshow;
  5.  {
  6.      register int fcx, fcy, fcbeg;
  7.      struct monst *mtmp;
  8.      boolean sawcorridor = FALSE;
  9.      struct egd *egrd = EGD(grd);
  10.      struct trap *trap;
  11.      struct rm *lev;
  12.  
  13.      if (!on_level(&egrd->gdlevel, &u.uz))
  14.          return TRUE;
  15.  
  16.      while ((fcbeg = egrd->fcbeg) < egrd->fcend) {
  17.          fcx = egrd->fakecorr[fcbeg].fx;
  18.          fcy = egrd->fakecorr[fcbeg].fy;
  19.          if ((grd->mhp <= 0 || !in_fcorridor(grd, u.ux, u.uy)) && egrd->gddone)
  20.              forceshow = TRUE;
  21.          if ((u.ux == fcx && u.uy == fcy && grd->mhp > 0)
  22.              || (!forceshow && couldsee(fcx, fcy))
  23.              || (Punished && !carried(uball) && uball->ox == fcx
  24.                  && uball->oy == fcy))
  25.              return FALSE;
  26.  
  27.          if ((mtmp = m_at(fcx, fcy)) != 0) {
  28.              if (mtmp->isgd) {
  29.                  return FALSE;
  30.              } else if (!in_fcorridor(grd, u.ux, u.uy)) {
  31.                  if (mtmp->mtame)
  32.                      yelp(mtmp);
  33.                  (void) rloc(mtmp, FALSE);
  34.              }
  35.          }
  36.          lev = &levl[fcx][fcy];
  37.          if (lev->typ == CORR && cansee(fcx, fcy))
  38.              sawcorridor = TRUE;
  39.          lev->typ = egrd->fakecorr[fcbeg].ftyp;
  40.          if (IS_STWALL(lev->typ)) {
  41.              /* destroy any trap here (pit dug by you, hole dug via
  42.                 wand while levitating or by monster, bear trap or land
  43.                 mine via object, spun web) when spot reverts to stone */
  44.              if ((trap = t_at(fcx, fcy)) != 0)
  45.                  deltrap(trap);
  46.              /* undo scroll/wand/spell of light affecting this spot */
  47.              if (lev->typ == STONE)
  48.                  blackout(fcx, fcy);
  49.          }
  50.          map_location(fcx, fcy, 1); /* bypass vision */
  51.          if (!ACCESSIBLE(lev->typ))
  52.              block_point(fcx, fcy);
  53.          vision_full_recalc = 1;
  54.          egrd->fcbeg++;
  55.      }
  56.      if (sawcorridor)
  57.          pline_The("corridor disappears.");
  58.      if (IS_ROCK(levl[u.ux][u.uy].typ))
  59.          You("are encased in rock.");
  60.      return TRUE;
  61.  }
  62.  

blackout

  1.  /* as a temporary corridor is removed, set stone locations and adjacent
  2.     spots to unlit; if player used scroll/wand/spell of light while inside
  3.     the corridor, we don't want the light to reappear if/when a new tunnel
  4.     goes through the same area */
  5.  STATIC_OVL void
  6.  blackout(x, y)
  7.  int x, y;
  8.  {
  9.      struct rm *lev;
  10.      int i, j;
  11.  
  12.      for (i = x - 1; i <= x + 1; ++i)
  13.          for (j = y - 1; j <= y + 1; ++j) {
  14.              if (!isok(i, j))
  15.                  continue;
  16.              lev = &levl[i][j];
  17.              /* [possible bug: when (i != x || j != y), perhaps we ought
  18.                 to check whether the spot on the far side is lit instead
  19.                 of doing a blanket blackout of adjacent locations] */
  20.              if (lev->typ == STONE)
  21.                  lev->lit = lev->waslit = 0;
  22.              /* mark <i,j> as not having been seen from <x,y> */
  23.              unset_seenv(lev, x, y, i, j);
  24.          }
  25.  }
  26.  

restfakecorr

  1.  STATIC_OVL void
  2.  restfakecorr(grd)
  3.  struct monst *grd;
  4.  {
  5.      /* it seems you left the corridor - let the guard disappear */
  6.      if (clear_fcorr(grd, FALSE)) {
  7.          grd->isgd = 0; /* dmonsfree() should delete this mon */
  8.          mongone(grd);
  9.      }
  10.  }
  11.  

grddead

  1.  /* called in mon.c */
  2.  boolean
  3.  grddead(grd)
  4.  struct monst *grd;
  5.  {
  6.      boolean dispose = clear_fcorr(grd, TRUE);
  7.  
  8.      if (!dispose) {
  9.          /* destroy guard's gold; drop any other inventory */
  10.          relobj(grd, 0, FALSE);
  11.          /* guard is dead; monster traversal loops should skip it */
  12.          grd->mhp = 0;
  13.          if (grd == context.polearm.hitmon)
  14.              context.polearm.hitmon = 0;
  15.          /* see comment by newpos in gd_move() */
  16.          remove_monster(grd->mx, grd->my);
  17.          newsym(grd->mx, grd->my);
  18.          place_monster(grd, 0, 0);
  19.          EGD(grd)->ogx = grd->mx;
  20.          EGD(grd)->ogy = grd->my;
  21.          dispose = clear_fcorr(grd, TRUE);
  22.      }
  23.      if (dispose)
  24.          grd->isgd = 0; /* for dmonsfree() */
  25.      return dispose;
  26.  }
  27.  

in_fcorridor

  1.  STATIC_OVL boolean
  2.  in_fcorridor(grd, x, y)
  3.  struct monst *grd;
  4.  int x, y;
  5.  {
  6.      register int fci;
  7.      struct egd *egrd = EGD(grd);
  8.  
  9.      for (fci = egrd->fcbeg; fci < egrd->fcend; fci++)
  10.          if (x == egrd->fakecorr[fci].fx && y == egrd->fakecorr[fci].fy)
  11.              return TRUE;
  12.      return FALSE;
  13.  }
  14.  

findgd

  1.  STATIC_OVL
  2.  struct monst *
  3.  findgd()
  4.  {
  5.      register struct monst *mtmp;
  6.  
  7.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  8.          if (DEADMONSTER(mtmp))
  9.              continue;
  10.          if (mtmp->isgd && on_level(&(EGD(mtmp)->gdlevel), &u.uz))
  11.              return mtmp;
  12.      }
  13.      return (struct monst *) 0;
  14.  }
  15.  

vault_summon_gd

  1.  void
  2.  vault_summon_gd()
  3.  {
  4.      if (vault_occupied(u.urooms) && !findgd())
  5.          u.uinvault = (VAULT_GUARD_TIME - 1);
  6.  }
  7.  

vault_occupied

  1.  char
  2.  vault_occupied(array)
  3.  char *array;
  4.  {
  5.      register char *ptr;
  6.  
  7.      for (ptr = array; *ptr; ptr++)
  8.          if (rooms[*ptr - ROOMOFFSET].rtype == VAULT)
  9.              return *ptr;
  10.      return '\0';
  11.  }
  12.  

invault

  1.  void
  2.  invault()
  3.  {
  4.  #ifdef BSD_43_BUG
  5.      int dummy; /* hack to avoid schain botch */
  6.  #endif
  7.      struct monst *guard;
  8.      boolean gsensed;
  9.      int trycount, vaultroom = (int) vault_occupied(u.urooms);
  10.  
  11.      if (!vaultroom) {
  12.          u.uinvault = 0;
  13.          return;
  14.      }
  15.  
  16.      vaultroom -= ROOMOFFSET;
  17.  
  18.      guard = findgd();
  19.      if (++u.uinvault % VAULT_GUARD_TIME == 0 && !guard) {
  20.          /* if time ok and no guard now. */
  21.          char buf[BUFSZ] = DUMMY;
  22.          register int x, y, dd, gx, gy;
  23.          int lx = 0, ly = 0;
  24.          long umoney;
  25.  
  26.          /* first find the goal for the guard */
  27.          for (dd = 2; (dd < ROWNO || dd < COLNO); dd++) {
  28.              for (y = u.uy - dd; y <= u.uy + dd; ly = y, y++) {
  29.                  if (y < 0 || y > ROWNO - 1)
  30.                      continue;
  31.                  for (x = u.ux - dd; x <= u.ux + dd; lx = x, x++) {
  32.                      if (y != u.uy - dd && y != u.uy + dd && x != u.ux - dd)
  33.                          x = u.ux + dd;
  34.                      if (x < 1 || x > COLNO - 1)
  35.                          continue;
  36.                      if (levl[x][y].typ == CORR) {
  37.                          if (x < u.ux)
  38.                              lx = x + 1;
  39.                          else if (x > u.ux)
  40.                              lx = x - 1;
  41.                          else
  42.                              lx = x;
  43.                          if (y < u.uy)
  44.                              ly = y + 1;
  45.                          else if (y > u.uy)
  46.                              ly = y - 1;
  47.                          else
  48.                              ly = y;
  49.                          if (levl[lx][ly].typ != STONE
  50.                              && levl[lx][ly].typ != CORR)
  51.                              goto incr_radius;
  52.                          goto fnd;
  53.                      }
  54.                  }
  55.              }
  56.          incr_radius:
  57.              ;
  58.          }
  59.          impossible("Not a single corridor on this level??");
  60.          tele();
  61.          return;
  62.      fnd:
  63.          gx = x;
  64.          gy = y;
  65.  
  66.          /* next find a good place for a door in the wall */
  67.          x = u.ux;
  68.          y = u.uy;
  69.          if (levl[x][y].typ != ROOM) { /* player dug a door and is in it */
  70.              if (levl[x + 1][y].typ == ROOM)
  71.                  x = x + 1;
  72.              else if (levl[x][y + 1].typ == ROOM)
  73.                  y = y + 1;
  74.              else if (levl[x - 1][y].typ == ROOM)
  75.                  x = x - 1;
  76.              else if (levl[x][y - 1].typ == ROOM)
  77.                  y = y - 1;
  78.              else if (levl[x + 1][y + 1].typ == ROOM) {
  79.                  x = x + 1;
  80.                  y = y + 1;
  81.              } else if (levl[x - 1][y - 1].typ == ROOM) {
  82.                  x = x - 1;
  83.                  y = y - 1;
  84.              } else if (levl[x + 1][y - 1].typ == ROOM) {
  85.                  x = x + 1;
  86.                  y = y - 1;
  87.              } else if (levl[x - 1][y + 1].typ == ROOM) {
  88.                  x = x - 1;
  89.                  y = y + 1;
  90.              }
  91.          }
  92.          while (levl[x][y].typ == ROOM) {
  93.              register int dx, dy;
  94.  
  95.              dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
  96.              dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
  97.              if (abs(gx - x) >= abs(gy - y))
  98.                  x += dx;
  99.              else
  100.                  y += dy;
  101.          }
  102.          if (x == u.ux && y == u.uy) {
  103.              if (levl[x + 1][y].typ == HWALL || levl[x + 1][y].typ == DOOR)
  104.                  x = x + 1;
  105.              else if (levl[x - 1][y].typ == HWALL
  106.                       || levl[x - 1][y].typ == DOOR)
  107.                  x = x - 1;
  108.              else if (levl[x][y + 1].typ == VWALL
  109.                       || levl[x][y + 1].typ == DOOR)
  110.                  y = y + 1;
  111.              else if (levl[x][y - 1].typ == VWALL
  112.                       || levl[x][y - 1].typ == DOOR)
  113.                  y = y - 1;
  114.              else
  115.                  return;
  116.          }
  117.  
  118.          /* make something interesting happen */
  119.          if (!(guard = makemon(&mons[PM_GUARD], x, y, MM_EGD)))
  120.              return;
  121.          guard->isgd = 1;
  122.          guard->mpeaceful = 1;
  123.          set_malign(guard);
  124.          EGD(guard)->gddone = 0;
  125.          EGD(guard)->ogx = x;
  126.          EGD(guard)->ogy = y;
  127.          assign_level(&(EGD(guard)->gdlevel), &u.uz);
  128.          EGD(guard)->vroom = vaultroom;
  129.          EGD(guard)->warncnt = 0;
  130.  
  131.          reset_faint(); /* if fainted - wake up */
  132.          gsensed = !canspotmon(guard);
  133.          if (!gsensed)
  134.              pline("Suddenly one of the Vault's %s enters!",
  135.                    makeplural(guard->data->mname));
  136.          else
  137.              pline("Someone else has entered the Vault.");
  138.          newsym(guard->mx, guard->my);
  139.          if (u.uswallow) {
  140.              /* can't interrogate hero, don't interrogate engulfer */
  141.              if (!Deaf) verbalize("What's going on here?");
  142.              if (gsensed)
  143.                  pline_The("other presence vanishes.");
  144.              mongone(guard);
  145.              return;
  146.          }
  147.          if (youmonst.m_ap_type == M_AP_OBJECT || u.uundetected) {
  148.              if (youmonst.m_ap_type == M_AP_OBJECT
  149.                  && youmonst.mappearance != GOLD_PIECE)
  150.                  if (!Deaf) verbalize("Hey! Who left that %s in here?",
  151.                                      mimic_obj_name(&youmonst));
  152.              /* You're mimicking some object or you're hidden. */
  153.              pline("Puzzled, %s turns around and leaves.", mhe(guard));
  154.              mongone(guard);
  155.              return;
  156.          }
  157.          if (Strangled || is_silent(youmonst.data) || multi < 0) {
  158.              /* [we ought to record whether this this message has already
  159.                 been given in order to vary it upon repeat visits, but
  160.                 discarding the monster and its egd data renders that hard] */
  161.              if (Deaf)
  162.                  pline("%s huffs and turns to leave.", noit_Monnam(guard));
  163.              else
  164.                  verbalize("I'll be back when you're ready to speak to me!");
  165.              mongone(guard);
  166.              return;
  167.          }
  168.  
  169.          stop_occupation(); /* if occupied, stop it *now* */
  170.          if (multi > 0) {
  171.              nomul(0);
  172.              unmul((char *) 0);
  173.          }
  174.          trycount = 5;
  175.          do {
  176.              getlin(Deaf ? "You are required to supply your name. -"
  177.                          : "\"Hello stranger, who are you?\" -", buf);
  178.              (void) mungspaces(buf);
  179.          } while (!buf[0] && --trycount > 0);
  180.  
  181.          if (u.ualign.type == A_LAWFUL
  182.              /* ignore trailing text, in case player includes rank */
  183.              && strncmpi(buf, plname, (int) strlen(plname)) != 0) {
  184.              adjalign(-1); /* Liar! */
  185.          }
  186.  
  187.          if (!strcmpi(buf, "Croesus") || !strcmpi(buf, "Kroisos")
  188.              || !strcmpi(buf, "Creosote")) {
  189.              if (!mvitals[PM_CROESUS].died) {
  190.                  if (Deaf) {
  191.                      if (!Blind)
  192.                          pline("%s waves goodbye.", noit_Monnam(guard));
  193.                  } else {
  194.                      verbalize(
  195.                           "Oh, yes, of course.  Sorry to have disturbed you.");
  196.                  }
  197.                  mongone(guard);
  198.              } else {
  199.                  setmangry(guard, FALSE);
  200.                  if (Deaf) {
  201.                     if (!Blind)
  202.                          pline("%s mouths something and looks very angry!",
  203.                                noit_Monnam(guard));
  204.                  } else {
  205.                     verbalize(
  206.                             "Back from the dead, are you?  I'll remedy that!");
  207.                  }
  208.                  /* don't want guard to waste next turn wielding a weapon */
  209.                  if (!MON_WEP(guard)) {
  210.                      guard->weapon_check = NEED_HTH_WEAPON;
  211.                      (void) mon_wield_item(guard);
  212.                  }
  213.              }
  214.              return;
  215.          }
  216.          if (Deaf)
  217.              pline("%s doesn't %srecognize you.", noit_Monnam(guard),
  218.                      (Blind) ? "" : "appear to ");
  219.          else
  220.              verbalize("I don't know you.");
  221.          umoney = money_cnt(invent);
  222.          if (!umoney && !hidden_gold()) {
  223.              if (Deaf)
  224.                  pline("%s stomps%s.", noit_Monnam(guard),
  225.                        (Blind) ? "" : " and beckons");
  226.              else
  227.                  verbalize("Please follow me.");
  228.          } else {
  229.              if (!umoney) {
  230.                  if (Deaf) {
  231.                      if (!Blind)
  232.                          pline("%s glares at you%s.", noit_Monnam(guard),
  233.                                invent ? "r stuff" : "");
  234.                  } else {
  235.                     verbalize("You have hidden gold.");
  236.                  }
  237.              }
  238.              if (Deaf) {
  239.                  if (!Blind)
  240.                      pline(
  241.                         "%s holds out %s palm and beckons with %s other hand.",
  242.                            noit_Monnam(guard), mhis(guard), mhis(guard));
  243.              } else {
  244.                  verbalize(
  245.                      "Most likely all your gold was stolen from this vault.");
  246.                  verbalize("Please drop that gold and follow me.");
  247.              }
  248.          }
  249.          EGD(guard)->gdx = gx;
  250.          EGD(guard)->gdy = gy;
  251.          EGD(guard)->fcbeg = 0;
  252.          EGD(guard)->fakecorr[0].fx = x;
  253.          EGD(guard)->fakecorr[0].fy = y;
  254.          if (IS_WALL(levl[x][y].typ))
  255.              EGD(guard)->fakecorr[0].ftyp = levl[x][y].typ;
  256.          else { /* the initial guard location is a dug door */
  257.              int vlt = EGD(guard)->vroom;
  258.              xchar lowx = rooms[vlt].lx, hix = rooms[vlt].hx;
  259.              xchar lowy = rooms[vlt].ly, hiy = rooms[vlt].hy;
  260.  
  261.              if (x == lowx - 1 && y == lowy - 1)
  262.                  EGD(guard)->fakecorr[0].ftyp = TLCORNER;
  263.              else if (x == hix + 1 && y == lowy - 1)
  264.                  EGD(guard)->fakecorr[0].ftyp = TRCORNER;
  265.              else if (x == lowx - 1 && y == hiy + 1)
  266.                  EGD(guard)->fakecorr[0].ftyp = BLCORNER;
  267.              else if (x == hix + 1 && y == hiy + 1)
  268.                  EGD(guard)->fakecorr[0].ftyp = BRCORNER;
  269.              else if (y == lowy - 1 || y == hiy + 1)
  270.                  EGD(guard)->fakecorr[0].ftyp = HWALL;
  271.              else if (x == lowx - 1 || x == hix + 1)
  272.                  EGD(guard)->fakecorr[0].ftyp = VWALL;
  273.          }
  274.          levl[x][y].typ = DOOR;
  275.          levl[x][y].doormask = D_NODOOR;
  276.          unblock_point(x, y); /* doesn't block light */
  277.          EGD(guard)->fcend = 1;
  278.          EGD(guard)->warncnt = 1;
  279.      }
  280.  }
  281.  

move_gold

  1.  STATIC_OVL void
  2.  move_gold(gold, vroom)
  3.  struct obj *gold;
  4.  int vroom;
  5.  {
  6.      xchar nx, ny;
  7.  
  8.      remove_object(gold);
  9.      newsym(gold->ox, gold->oy);
  10.      nx = rooms[vroom].lx + rn2(2);
  11.      ny = rooms[vroom].ly + rn2(2);
  12.      place_object(gold, nx, ny);
  13.      stackobj(gold);
  14.      newsym(nx, ny);
  15.  }
  16.  

wallify_vault

  1.  STATIC_OVL void
  2.  wallify_vault(grd)
  3.  struct monst *grd;
  4.  {
  5.      int x, y, typ;
  6.      int vlt = EGD(grd)->vroom;
  7.      char tmp_viz;
  8.      xchar lox = rooms[vlt].lx - 1, hix = rooms[vlt].hx + 1,
  9.            loy = rooms[vlt].ly - 1, hiy = rooms[vlt].hy + 1;
  10.      struct monst *mon;
  11.      struct obj *gold;
  12.      struct trap *trap;
  13.      boolean fixed = FALSE;
  14.      boolean movedgold = FALSE;
  15.  
  16.      for (x = lox; x <= hix; x++)
  17.          for (y = loy; y <= hiy; y++) {
  18.              /* if not on the room boundary, skip ahead */
  19.              if (x != lox && x != hix && y != loy && y != hiy)
  20.                  continue;
  21.  
  22.              if (!IS_WALL(levl[x][y].typ) && !in_fcorridor(grd, x, y)) {
  23.                  if ((mon = m_at(x, y)) != 0 && mon != grd) {
  24.                      if (mon->mtame)
  25.                          yelp(mon);
  26.                      (void) rloc(mon, FALSE);
  27.                  }
  28.                  if ((gold = g_at(x, y)) != 0) {
  29.                      move_gold(gold, EGD(grd)->vroom);
  30.                      movedgold = TRUE;
  31.                  }
  32.                  if ((trap = t_at(x, y)) != 0)
  33.                      deltrap(trap);
  34.                  if (x == lox)
  35.                      typ =
  36.                          (y == loy) ? TLCORNER : (y == hiy) ? BLCORNER : VWALL;
  37.                  else if (x == hix)
  38.                      typ =
  39.                          (y == loy) ? TRCORNER : (y == hiy) ? BRCORNER : VWALL;
  40.                  else /* not left or right side, must be top or bottom */
  41.                      typ = HWALL;
  42.                  levl[x][y].typ = typ;
  43.                  levl[x][y].doormask = 0;
  44.                  /*
  45.                   * hack: player knows walls are restored because of the
  46.                   * message, below, so show this on the screen.
  47.                   */
  48.                  tmp_viz = viz_array[y][x];
  49.                  viz_array[y][x] = IN_SIGHT | COULD_SEE;
  50.                  newsym(x, y);
  51.                  viz_array[y][x] = tmp_viz;
  52.                  block_point(x, y);
  53.                  fixed = TRUE;
  54.              }
  55.          }
  56.  
  57.      if (movedgold || fixed) {
  58.          if (in_fcorridor(grd, grd->mx, grd->my) || cansee(grd->mx, grd->my))
  59.              pline("%s whispers an incantation.", noit_Monnam(grd));
  60.          else
  61.              You_hear("a distant chant.");
  62.          if (movedgold)
  63.              pline("A mysterious force moves the gold into the vault.");
  64.          if (fixed)
  65.              pline_The("damaged vault's walls are magically restored!");
  66.      }
  67.  }
  68.  

gd_move

  1.  /*
  2.   * return  1: guard moved,  0: guard didn't,  -1: let m_move do it,  -2: died
  3.   */
  4.  int
  5.  gd_move(grd)
  6.  register struct monst *grd;
  7.  {
  8.      int x, y, nx, ny, m, n;
  9.      int dx, dy, gx, gy, fci;
  10.      uchar typ;
  11.      struct fakecorridor *fcp;
  12.      register struct egd *egrd = EGD(grd);
  13.      struct rm *crm;
  14.      boolean goldincorridor = FALSE,
  15.              u_in_vault = vault_occupied(u.urooms) ? TRUE : FALSE,
  16.              grd_in_vault = *in_rooms(grd->mx, grd->my, VAULT) ? TRUE : FALSE;
  17.      boolean disappear_msg_seen = FALSE, semi_dead = (grd->mhp <= 0);
  18.      long umoney = money_cnt(invent);
  19.      register boolean u_carry_gold = ((umoney + hidden_gold()) > 0L);
  20.      boolean see_guard, newspot = FALSE;
  21.  
  22.      if (!on_level(&(egrd->gdlevel), &u.uz))
  23.          return -1;
  24.      nx = ny = m = n = 0;
  25.      if (!u_in_vault && !grd_in_vault)
  26.          wallify_vault(grd);
  27.      if (!grd->mpeaceful) {
  28.          if (semi_dead) {
  29.              egrd->gddone = 1;
  30.              goto newpos;
  31.          }
  32.          if (!u_in_vault
  33.              && (grd_in_vault || (in_fcorridor(grd, grd->mx, grd->my)
  34.                                   && !in_fcorridor(grd, u.ux, u.uy)))) {
  35.              (void) rloc(grd, FALSE);
  36.              wallify_vault(grd);
  37.              (void) clear_fcorr(grd, TRUE);
  38.              goto letknow;
  39.          }
  40.          if (!in_fcorridor(grd, grd->mx, grd->my))
  41.              (void) clear_fcorr(grd, TRUE);
  42.          return -1;
  43.      }
  44.      if (abs(egrd->ogx - grd->mx) > 1 || abs(egrd->ogy - grd->my) > 1)
  45.          return -1; /* teleported guard - treat as monster */
  46.  
  47.      if (egrd->witness) {
  48.          if (!Deaf)
  49.              verbalize("How dare you %s that gold, scoundrel!",
  50.                        (egrd->witness & GD_EATGOLD) ? "consume" : "destroy");
  51.          egrd->witness = 0;
  52.          grd->mpeaceful = 0;
  53.          return -1;
  54.      }
  55.      if (egrd->fcend == 1) {
  56.          if (u_in_vault && (u_carry_gold || um_dist(grd->mx, grd->my, 1))) {
  57.              if (egrd->warncnt == 3 && !Deaf)
  58.                  verbalize("I repeat, %sfollow me!",
  59.                            u_carry_gold
  60.                                ? (!umoney ? "drop that hidden money and "
  61.                                           : "drop that money and ")
  62.                                : "");
  63.              if (egrd->warncnt == 7) {
  64.                  m = grd->mx;
  65.                  n = grd->my;
  66.                  if (!Deaf)
  67.                      verbalize("You've been warned, knave!");
  68.                  mnexto(grd);
  69.                  levl[m][n].typ = egrd->fakecorr[0].ftyp;
  70.                  newsym(m, n);
  71.                  grd->mpeaceful = 0;
  72.                  return -1;
  73.              }
  74.              /* not fair to get mad when (s)he's fainted or paralyzed */
  75.              if (!is_fainted() && multi >= 0)
  76.                  egrd->warncnt++;
  77.              return 0;
  78.          }
  79.  
  80.          if (!u_in_vault) {
  81.              if (u_carry_gold) { /* player teleported */
  82.                  m = grd->mx;
  83.                  n = grd->my;
  84.                  (void) rloc(grd, TRUE);
  85.                  levl[m][n].typ = egrd->fakecorr[0].ftyp;
  86.                  newsym(m, n);
  87.                  grd->mpeaceful = 0;
  88.              letknow:
  89.                  if (!cansee(grd->mx, grd->my) || !mon_visible(grd))
  90.                      You_hear("the shrill sound of a guard's whistle.");
  91.                  else
  92.                      You(um_dist(grd->mx, grd->my, 2)
  93.                              ? "see %s approaching."
  94.                              : "are confronted by %s.",
  95.                          /* "an angry guard" */
  96.                          x_monnam(grd, ARTICLE_A, "angry", 0, FALSE));
  97.                  return -1;
  98.              } else {
  99.                  if (!Deaf)
  100.                      verbalize("Well, begone.");
  101.                  wallify_vault(grd);
  102.                  egrd->gddone = 1;
  103.                  goto cleanup;
  104.              }
  105.          }
  106.      }
  107.  
  108.      if (egrd->fcend > 1) {
  109.          if (egrd->fcend > 2 && in_fcorridor(grd, grd->mx, grd->my)
  110.              && !egrd->gddone && !in_fcorridor(grd, u.ux, u.uy)
  111.              && levl[egrd->fakecorr[0].fx][egrd->fakecorr[0].fy].typ
  112.                     == egrd->fakecorr[0].ftyp) {
  113.              pline("%s, confused, disappears.", noit_Monnam(grd));
  114.              disappear_msg_seen = TRUE;
  115.              goto cleanup;
  116.          }
  117.          if (u_carry_gold && (in_fcorridor(grd, u.ux, u.uy)
  118.                               /* cover a 'blind' spot */
  119.                               || (egrd->fcend > 1 && u_in_vault))) {
  120.              if (!grd->mx) {
  121.                  restfakecorr(grd);
  122.                  return -2;
  123.              }
  124.              if (egrd->warncnt < 6) {
  125.                  egrd->warncnt = 6;
  126.                  if (Deaf) {
  127.                      if (!Blind)
  128.                          pline("%s holds out %s palm demandingly!",
  129.                                noit_Monnam(grd), mhis(grd));
  130.                  } else {
  131.                      verbalize("Drop all your gold, scoundrel!");
  132.                  }
  133.                  return 0;
  134.              } else {
  135.                  if (Deaf) {
  136.                      if (!Blind)
  137.                          pline("%s rubs %s hands with enraged delight!",
  138.                                noit_Monnam(grd), mhis(grd));
  139.                  } else {
  140.                      verbalize("So be it, rogue!");
  141.                  }
  142.                  grd->mpeaceful = 0;
  143.                  return -1;
  144.              }
  145.          }
  146.      }
  147.      for (fci = egrd->fcbeg; fci < egrd->fcend; fci++)
  148.          if (g_at(egrd->fakecorr[fci].fx, egrd->fakecorr[fci].fy)) {
  149.              m = egrd->fakecorr[fci].fx;
  150.              n = egrd->fakecorr[fci].fy;
  151.              goldincorridor = TRUE;
  152.          }
  153.      if (goldincorridor && !egrd->gddone) {
  154.          x = grd->mx;
  155.          y = grd->my;
  156.          if (m == u.ux && n == u.uy) {
  157.              struct obj *gold = g_at(m, n);
  158.              /* Grab the gold from between the hero's feet.  */
  159.              obj_extract_self(gold);
  160.              add_to_minv(grd, gold);
  161.              newsym(m, n);
  162.          } else if (m == x && n == y) {
  163.              mpickgold(grd); /* does a newsym */
  164.          } else {
  165.              /* just for insurance... */
  166.              if (MON_AT(m, n) && m != grd->mx && n != grd->my) {
  167.                  if (!Deaf)
  168.                      verbalize("Out of my way, scum!");
  169.                  (void) rloc(m_at(m, n), FALSE);
  170.              }
  171.              remove_monster(grd->mx, grd->my);
  172.              newsym(grd->mx, grd->my);
  173.              place_monster(grd, m, n);
  174.              mpickgold(grd); /* does a newsym */
  175.          }
  176.          if (cansee(m, n))
  177.              pline("%s%s picks up the gold.", Monnam(grd),
  178.                    grd->mpeaceful ? " calms down and" : "");
  179.          if (x != grd->mx || y != grd->my) {
  180.              remove_monster(grd->mx, grd->my);
  181.              newsym(grd->mx, grd->my);
  182.              place_monster(grd, x, y);
  183.              newsym(x, y);
  184.          }
  185.          if (!grd->mpeaceful)
  186.              return -1;
  187.          egrd->warncnt = 5;
  188.          return 0;
  189.      }
  190.      if (um_dist(grd->mx, grd->my, 1) || egrd->gddone) {
  191.          if (!egrd->gddone && !rn2(10) && !Deaf && !u.uswallow
  192.              && !(u.ustuck && !sticks(youmonst.data)))
  193.              verbalize("Move along!");
  194.          restfakecorr(grd);
  195.          return 0; /* didn't move */
  196.      }
  197.      x = grd->mx;
  198.      y = grd->my;
  199.  
  200.      if (u_in_vault)
  201.          goto nextpos;
  202.  
  203.      /* look around (hor & vert only) for accessible places */
  204.      for (nx = x - 1; nx <= x + 1; nx++)
  205.          for (ny = y - 1; ny <= y + 1; ny++) {
  206.              if ((nx == x || ny == y) && (nx != x || ny != y)
  207.                  && isok(nx, ny)) {
  208.                  typ = (crm = &levl[nx][ny])->typ;
  209.                  if (!IS_STWALL(typ) && !IS_POOL(typ)) {
  210.                      if (in_fcorridor(grd, nx, ny))
  211.                          goto nextnxy;
  212.  
  213.                      if (*in_rooms(nx, ny, VAULT))
  214.                          continue;
  215.  
  216.                      /* seems we found a good place to leave him alone */
  217.                      egrd->gddone = 1;
  218.                      if (ACCESSIBLE(typ))
  219.                          goto newpos;
  220.  #ifdef STUPID
  221.                      if (typ == SCORR)
  222.                          crm->typ = CORR;
  223.                      else
  224.                          crm->typ = DOOR;
  225.  #else
  226.                      crm->typ = (typ == SCORR) ? CORR : DOOR;
  227.  #endif
  228.                      if (crm->typ == DOOR)
  229.                          crm->doormask = D_NODOOR;
  230.                      goto proceed;
  231.                  }
  232.              }
  233.          nextnxy:
  234.              ;
  235.          }
  236.  nextpos:
  237.      nx = x;
  238.      ny = y;
  239.      gx = egrd->gdx;
  240.      gy = egrd->gdy;
  241.      dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
  242.      dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
  243.      if (abs(gx - x) >= abs(gy - y))
  244.          nx += dx;
  245.      else
  246.          ny += dy;
  247.  
  248.      while ((typ = (crm = &levl[nx][ny])->typ) != STONE) {
  249.          /* in view of the above we must have IS_WALL(typ) or typ == POOL */
  250.          /* must be a wall here */
  251.          if (isok(nx + nx - x, ny + ny - y) && !IS_POOL(typ)
  252.              && IS_ROOM(levl[nx + nx - x][ny + ny - y].typ)) {
  253.              crm->typ = DOOR;
  254.              crm->doormask = D_NODOOR;
  255.              goto proceed;
  256.          }
  257.          if (dy && nx != x) {
  258.              nx = x;
  259.              ny = y + dy;
  260.              continue;
  261.          }
  262.          if (dx && ny != y) {
  263.              ny = y;
  264.              nx = x + dx;
  265.              dy = 0;
  266.              continue;
  267.          }
  268.          /* I don't like this, but ... */
  269.          if (IS_ROOM(typ)) {
  270.              crm->typ = DOOR;
  271.              crm->doormask = D_NODOOR;
  272.              goto proceed;
  273.          }
  274.          break;
  275.      }
  276.      crm->typ = CORR;
  277.  proceed:
  278.      newspot = TRUE;
  279.      unblock_point(nx, ny); /* doesn't block light */
  280.      if (cansee(nx, ny))
  281.          newsym(nx, ny);
  282.  
  283.      fcp = &(egrd->fakecorr[egrd->fcend]);
  284.      if (egrd->fcend++ == FCSIZ)
  285.          panic("fakecorr overflow");
  286.      fcp->fx = nx;
  287.      fcp->fy = ny;
  288.      fcp->ftyp = typ;
  289.  newpos:
  290.      if (egrd->gddone) {
  291.          /* The following is a kludge.  We need to keep    */
  292.          /* the guard around in order to be able to make   */
  293.          /* the fake corridor disappear as the player      */
  294.          /* moves out of it, but we also need the guard    */
  295.          /* out of the way.  We send the guard to never-   */
  296.          /* never land.  We set ogx ogy to mx my in order  */
  297.          /* to avoid a check at the top of this function.  */
  298.          /* At the end of the process, the guard is killed */
  299.          /* in restfakecorr().                             */
  300.      cleanup:
  301.          x = grd->mx;
  302.          y = grd->my;
  303.  
  304.          see_guard = canspotmon(grd);
  305.          wallify_vault(grd);
  306.          remove_monster(grd->mx, grd->my);
  307.          newsym(grd->mx, grd->my);
  308.          place_monster(grd, 0, 0);
  309.          egrd->ogx = grd->mx;
  310.          egrd->ogy = grd->my;
  311.          restfakecorr(grd);
  312.          if (!semi_dead && (in_fcorridor(grd, u.ux, u.uy) || cansee(x, y))) {
  313.              if (!disappear_msg_seen && see_guard)
  314.                  pline("Suddenly, %s disappears.", noit_mon_nam(grd));
  315.              return 1;
  316.          }
  317.          return -2;
  318.      }
  319.      egrd->ogx = grd->mx; /* update old positions */
  320.      egrd->ogy = grd->my;
  321.      remove_monster(grd->mx, grd->my);
  322.      place_monster(grd, nx, ny);
  323.      if (newspot && g_at(nx, ny)) {
  324.          /* if there's gold already here (most likely from mineralize()),
  325.             pick it up now so that guard doesn't later think hero dropped
  326.             it and give an inappropriate message */
  327.          mpickgold(grd);
  328.          if (canspotmon(grd))
  329.              pline("%s picks up some gold.", Monnam(grd));
  330.      } else
  331.          newsym(grd->mx, grd->my);
  332.      restfakecorr(grd);
  333.      return 1;
  334.  }
  335.  

paygd

  1.  /* Routine when dying or quitting with a vault guard around */
  2.  void
  3.  paygd()
  4.  {
  5.      register struct monst *grd = findgd();
  6.      long umoney = money_cnt(invent);
  7.      struct obj *coins, *nextcoins;
  8.      int gx, gy;
  9.      char buf[BUFSZ];
  10.  
  11.      if (!umoney || !grd)
  12.          return;
  13.  
  14.      if (u.uinvault) {
  15.          Your("%ld %s goes into the Magic Memory Vault.", umoney,
  16.               currency(umoney));
  17.          gx = u.ux;
  18.          gy = u.uy;
  19.      } else {
  20.          if (grd->mpeaceful) { /* guard has no "right" to your gold */
  21.              mongone(grd);
  22.              return;
  23.          }
  24.          mnexto(grd);
  25.          pline("%s remits your gold to the vault.", Monnam(grd));
  26.          gx = rooms[EGD(grd)->vroom].lx + rn2(2);
  27.          gy = rooms[EGD(grd)->vroom].ly + rn2(2);
  28.          Sprintf(buf, "To Croesus: here's the gold recovered from %s the %s.",
  29.                  plname, mons[u.umonster].mname);
  30.          make_grave(gx, gy, buf);
  31.      }
  32.      for (coins = invent; coins; coins = nextcoins) {
  33.          nextcoins = coins->nobj;
  34.          if (objects[coins->otyp].oc_class == COIN_CLASS) {
  35.              freeinv(coins);
  36.              place_object(coins, gx, gy);
  37.              stackobj(coins);
  38.          }
  39.      }
  40.      mongone(grd);
  41.  }
  42.  

hidden_gold

  1.  long
  2.  hidden_gold()
  3.  {
  4.      long value = 0L;
  5.      struct obj *obj;
  6.  
  7.      for (obj = invent; obj; obj = obj->nobj)
  8.          if (Has_contents(obj))
  9.              value += contained_gold(obj);
  10.      /* unknown gold stuck inside statues may cause some consternation... */
  11.  
  12.      return value;
  13.  }
  14.  

gd_sound

  1.  /* prevent "You hear footsteps.." when inappropriate */
  2.  boolean
  3.  gd_sound()
  4.  {
  5.      struct monst *grd = findgd();
  6.  
  7.      if (vault_occupied(u.urooms))
  8.          return FALSE;
  9.      else
  10.          return (boolean) (grd == (struct monst *) 0);
  11.  }
  12.  

vault_gd_watching

  1.  void
  2.  vault_gd_watching(activity)
  3.  unsigned int activity;
  4.  {
  5.      struct monst *guard = findgd();
  6.  
  7.      if (guard && guard->mcansee && m_canseeu(guard)) {
  8.          if (activity == GD_EATGOLD || activity == GD_DESTROYGOLD)
  9.              EGD(guard)->witness = activity;
  10.      }
  11.  }
  12.  
  13.  /*vault.c*/