Source:NetHack 3.6.0/src/vault.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to vault.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/vault.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	vault.c	$NHDT-Date: 1446078792 2015/10/29 00:33:12 $  $NHDT-Branch: master $:$NHDT-Revision: 1.39 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  STATIC_DCL struct monst *NDECL(findgd);
  8.  
  9.  STATIC_DCL boolean FDECL(clear_fcorr, (struct monst *, BOOLEAN_P));
  10.  STATIC_DCL void FDECL(blackout, (int, int));
  11.  STATIC_DCL void FDECL(restfakecorr, (struct monst *));
  12.  STATIC_DCL boolean FDECL(in_fcorridor, (struct monst *, int, int));
  13.  STATIC_DCL void FDECL(move_gold, (struct obj *, int));
  14.  STATIC_DCL void FDECL(wallify_vault, (struct monst *));
  15.  

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

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

playgd

  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*/