home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / vault.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  18.6 KB  |  749 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)vault.c    3.1    93/03/30    */
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6. #include "vault.h"
  7.  
  8. STATIC_DCL struct monst *NDECL(findgd);
  9.  
  10. #ifdef OVLB
  11.  
  12. static boolean FDECL(clear_fcorr, (struct monst *,BOOLEAN_P));
  13. static void FDECL(restfakecorr,(struct monst *));
  14. static boolean FDECL(in_fcorridor, (struct monst *,int,int));
  15. static void FDECL(move_gold,(struct obj *,int));
  16. static void FDECL(wallify_vault,(struct monst *));
  17.  
  18. static boolean
  19. clear_fcorr(grd, forceshow)
  20. register struct monst *grd;
  21. register boolean forceshow;
  22. {
  23.     register int fcx, fcy, fcbeg;
  24.     register struct monst *mtmp;
  25.  
  26.     while((fcbeg = EGD(grd)->fcbeg) < EGD(grd)->fcend) {
  27.         fcx = EGD(grd)->fakecorr[fcbeg].fx;
  28.         fcy = EGD(grd)->fakecorr[fcbeg].fy;
  29.         if((grd->mhp <= 0 || !in_fcorridor(grd, u.ux, u.uy)) &&
  30.                    EGD(grd)->gddone)
  31.             forceshow = TRUE;
  32.         if((u.ux == fcx && u.uy == fcy && grd->mhp > 0) ||
  33.            (!forceshow && cansee(fcx,fcy))) return(FALSE);
  34.         if ((mtmp = m_at(fcx,fcy)) != 0) {
  35.             if(mtmp->isgd) return(FALSE);
  36.             else if(!in_fcorridor(grd, u.ux, u.uy)) {
  37. #ifdef SOUNDS
  38.                 if(mtmp->mpeaceful) yelp(mtmp);
  39. #endif
  40.                 rloc(mtmp);
  41.             }
  42.         }
  43.         levl[fcx][fcy].typ = EGD(grd)->fakecorr[fcbeg].ftyp;
  44.         map_location(fcx, fcy, 1);    /* bypass vision */
  45.         if(!ACCESSIBLE(levl[fcx][fcy].typ)) block_point(fcx,fcy);
  46.         EGD(grd)->fcbeg++;
  47.     }
  48.     if(grd->mhp <= 0) {
  49.         pline("The corridor disappears.");
  50.         if(IS_ROCK(levl[u.ux][u.uy].typ)) You("are encased in rock.");
  51.     }
  52.     return(TRUE);
  53. }
  54.  
  55. static void
  56. restfakecorr(grd)
  57. register struct monst *grd;
  58. {
  59.     /* it seems you left the corridor - let the guard disappear */
  60.     if(clear_fcorr(grd, FALSE)) mongone(grd);
  61. }
  62.  
  63. boolean
  64. grddead(grd)                /* called in mon.c */
  65. register struct monst *grd;
  66. {
  67.     register boolean dispose = clear_fcorr(grd, TRUE);
  68.  
  69.     if(!dispose) {
  70.         /* see comment by newpos in gd_move() */
  71.         remove_monster(grd->mx, grd->my);
  72.         newsym(grd->mx, grd->my);
  73.         place_monster(grd, 0, 0);
  74.         EGD(grd)->ogx = grd->mx;
  75.         EGD(grd)->ogy = grd->my;
  76.         dispose = clear_fcorr(grd, TRUE);
  77.     }
  78.     return(dispose);
  79. }
  80.  
  81. static boolean
  82. in_fcorridor(grd, x, y)
  83. register struct monst *grd;
  84. int x, y;
  85. {
  86.     register int fci;
  87.  
  88.     for(fci = EGD(grd)->fcbeg; fci < EGD(grd)->fcend; fci++)
  89.         if(x == EGD(grd)->fakecorr[fci].fx &&
  90.                 y == EGD(grd)->fakecorr[fci].fy)
  91.             return(TRUE);
  92.     return(FALSE);
  93. }
  94.  
  95. STATIC_OVL
  96. struct monst *
  97. findgd() {
  98.  
  99.     register struct monst *mtmp;
  100.  
  101.     for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  102.         if(mtmp->isgd && on_level(&(EGD(mtmp)->gdlevel), &u.uz))
  103.         return(mtmp);
  104.     return((struct monst *)0);
  105. }
  106.  
  107. #endif /* OVLB */
  108. #ifdef OVL0
  109.  
  110. char
  111. vault_occupied(array)
  112. char *array;
  113. {
  114.     register char *ptr;
  115.  
  116.     for (ptr = array; *ptr; ptr++)
  117.         if (rooms[*ptr - ROOMOFFSET].rtype == VAULT)
  118.             return(*ptr);
  119.     return('\0');
  120. }
  121.  
  122. void
  123. invault()
  124. {
  125.  
  126. #ifdef BSD_43_BUG
  127.     int dummy;        /* hack to avoid schain botch */
  128. #endif
  129.     struct monst *guard;
  130.     int vaultroom = (int)vault_occupied(u.urooms);
  131.  
  132.     if(!vaultroom) {
  133.     u.uinvault = 0;
  134.     return;
  135.     }
  136.  
  137.     vaultroom -= ROOMOFFSET;
  138.  
  139.     guard = findgd();
  140.     if(++u.uinvault % 30 == 0 && !guard) { /* if time ok and no guard now. */
  141.     char buf[BUFSZ];
  142.     register int x, y, dd, gx, gy;
  143.     int lx = 0, ly = 0;
  144.  
  145.     /* first find the goal for the guard */
  146.     for(dd = 2; (dd < ROWNO || dd < COLNO); dd++) {
  147.       for(y = u.uy-dd; y <= u.uy+dd; ly = y, y++) {
  148.         if(y < 0 || y > ROWNO-1) continue;
  149.         for(x = u.ux-dd; x <= u.ux+dd; lx = x, x++) {
  150.           if(y != u.uy-dd && y != u.uy+dd && x != u.ux-dd)
  151.         x = u.ux+dd;
  152.           if(x < 1 || x > COLNO-1) continue;
  153.           if(levl[x][y].typ == CORR) {
  154.           if(x < u.ux) lx = x + 1;
  155.           else if(x > u.ux) lx = x - 1;
  156.           else x = lx;
  157.           if(y < u.uy) ly = y + 1;
  158.           else if(y > u.uy) ly = y - 1;
  159.           else y = ly;
  160.           if(levl[lx][ly].typ != STONE && levl[lx][ly].typ != CORR)
  161.               goto incr_radius;
  162.           goto fnd;
  163.           }
  164.         }
  165.       }
  166. incr_radius: ;
  167.     }
  168.     impossible("Not a single corridor on this level??");
  169.     tele();
  170.     return;
  171. fnd:
  172.     gx = x; gy = y;
  173.  
  174.     /* next find a good place for a door in the wall */
  175.     x = u.ux; y = u.uy;
  176.     if(levl[x][y].typ != ROOM) {  /* player dug a door and is in it */
  177.         if(levl[x+1][y].typ == ROOM)  x = x + 1;
  178.         else if(levl[x][y+1].typ == ROOM) y = y + 1;
  179.         else if(levl[x-1][y].typ == ROOM) x = x - 1;
  180.         else if(levl[x][y-1].typ == ROOM) y = y - 1;
  181.         else if(levl[x+1][y+1].typ == ROOM) {
  182.             x = x + 1;
  183.             y = y + 1;
  184.         } else if (levl[x-1][y-1].typ == ROOM) {
  185.             x = x - 1;
  186.             y = y - 1;
  187.         } else if (levl[x+1][y-1].typ == ROOM) {
  188.             x = x + 1;
  189.             y = y - 1;
  190.         } else if (levl[x-1][y+1].typ == ROOM) {
  191.             x = x - 1;
  192.             y = y + 1;
  193.         }
  194.     }
  195.     while(levl[x][y].typ == ROOM) {
  196.         register int dx,dy;
  197.  
  198.         dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
  199.         dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
  200.         if(abs(gx-x) >= abs(gy-y))
  201.             x += dx;
  202.         else
  203.             y += dy;
  204.     }
  205.     if(x == u.ux && y == u.uy) {
  206.         if(levl[x+1][y].typ == HWALL || levl[x+1][y].typ == DOOR)
  207.             x = x + 1;
  208.         else if(levl[x-1][y].typ == HWALL || levl[x-1][y].typ == DOOR)
  209.             x = x - 1;
  210.         else if(levl[x][y+1].typ == VWALL || levl[x][y+1].typ == DOOR)
  211.             y = y + 1;
  212.         else if(levl[x][y-1].typ == VWALL || levl[x][y-1].typ == DOOR)
  213.             y = y - 1;
  214.         else return;
  215.     }
  216.  
  217.     /* make something interesting happen */
  218.     if(!(guard = makemon(&mons[PM_GUARD], x, y))) return;
  219.     guard->isgd = 1;
  220.     guard->mpeaceful = 1;
  221.     set_malign(guard);
  222.     EGD(guard)->gddone = 0;
  223.     EGD(guard)->ogx = x;
  224.     EGD(guard)->ogy = y;
  225.     assign_level(&(EGD(guard)->gdlevel), &u.uz);
  226.     EGD(guard)->vroom = vaultroom;
  227.     EGD(guard)->warncnt = 0;
  228.  
  229.     if(!cansee(guard->mx, guard->my)) {
  230.         mongone(guard);
  231.         return;
  232.     }
  233.  
  234.     reset_faint();            /* if fainted - wake up */
  235.     pline("Suddenly one of the Vault's guards enters!");
  236.     newsym(guard->mx,guard->my);
  237.     if (Strangled
  238. #ifdef POLYSELF
  239.             || uasmon->msound == MS_SILENT
  240. #endif
  241.                             ) {
  242.         verbalize("I'll be back when you're ready to speak to me!");
  243.         mongone(guard);
  244.         return;
  245.     }
  246.     stop_occupation();        /* if occupied, stop it *now* */
  247.     do {
  248.         getlin("\"Hello stranger, who are you?\" -",buf);
  249.     } while (!letter(buf[0]));
  250.  
  251.     if(!strcmp(buf, "Croesus") || !strcmp(buf, "Kroisos")) {
  252.         verbalize("Oh, yes, of course.  Sorry to have disturbed you.");
  253.         mongone(guard);
  254.         return;
  255.     }
  256.     verbalize("I don't know you.");
  257.     if (!u.ugold && !hidden_gold())
  258.         verbalize("Please follow me.");
  259.     else {
  260.         if (!u.ugold)
  261.         verbalize("You have hidden gold.");
  262.         verbalize("Most likely all your gold was stolen from this vault.");
  263.         verbalize("Please drop that gold and follow me.");
  264.     }
  265.     EGD(guard)->gdx = gx;
  266.     EGD(guard)->gdy = gy;
  267.     EGD(guard)->fcbeg = 0;
  268.     EGD(guard)->fakecorr[0].fx = x;
  269.     EGD(guard)->fakecorr[0].fy = y;
  270.     if(IS_WALL(levl[x][y].typ))
  271.         EGD(guard)->fakecorr[0].ftyp = levl[x][y].typ;
  272.     else { /* the initial guard location is a dug door */
  273.         int vlt = EGD(guard)->vroom;
  274.         xchar lowx = rooms[vlt].lx, hix = rooms[vlt].hx;
  275.         xchar lowy = rooms[vlt].ly, hiy = rooms[vlt].hy;
  276.  
  277.         if(x == lowx-1 && y == lowy-1)
  278.         EGD(guard)->fakecorr[0].ftyp = TLCORNER;
  279.         else if(x == hix+1 && y == lowy-1)
  280.         EGD(guard)->fakecorr[0].ftyp = TRCORNER;
  281.         else if(x == lowx-1 && y == hiy+1)
  282.         EGD(guard)->fakecorr[0].ftyp = BLCORNER;
  283.         else if(x == hix+1 && y == hiy+1)
  284.         EGD(guard)->fakecorr[0].ftyp = BRCORNER;
  285.         else if(y == lowy-1 || y == hiy+1)
  286.         EGD(guard)->fakecorr[0].ftyp = HWALL;
  287.         else if(x == lowx-1 || x == hix+1)
  288.         EGD(guard)->fakecorr[0].ftyp = VWALL;
  289.     }
  290.     levl[x][y].typ = DOOR;
  291.     levl[x][y].doormask = D_NODOOR;
  292.     EGD(guard)->fcend = 1;
  293.     EGD(guard)->warncnt = 1;
  294.     }
  295. }
  296.  
  297. #endif /* OVL0 */
  298. #ifdef OVLB
  299.  
  300. static void
  301. move_gold(gold, vroom)
  302. struct obj *gold;
  303. int vroom;
  304. {
  305.     xchar nx, ny;
  306.  
  307.     remove_object(gold);
  308.     newsym(gold->ox, gold->oy);
  309.     nx = rooms[vroom].lx + rn2(2);
  310.     ny = rooms[vroom].ly + rn2(2);
  311.     place_object(gold, nx, ny);
  312.     stackobj(gold);
  313.     newsym(nx,ny);
  314. }
  315.  
  316. static void
  317. wallify_vault(grd)
  318. struct monst *grd;
  319. {
  320.     int x, y;
  321.     int vlt = EGD(grd)->vroom;
  322.     char tmp_viz;
  323.     xchar lowx = rooms[vlt].lx, hix = rooms[vlt].hx;
  324.     xchar lowy = rooms[vlt].ly, hiy = rooms[vlt].hy;
  325.     register struct obj *gold;
  326.     register boolean fixed = FALSE;
  327.     register boolean movedgold = FALSE;
  328.  
  329.     for(x = lowx-1; x <= hix+1; x++)
  330.         for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) {
  331.         if(!IS_WALL(levl[x][y].typ) && !in_fcorridor(grd, x, y)) {
  332.             if(MON_AT(x, y) && grd->mx != x && grd->my != y) {
  333.             struct monst *mon = m_at(x,y);
  334. #ifdef SOUNDS
  335.             yelp(mon);
  336. #endif
  337.             rloc(mon);
  338.             }
  339.             if ((gold = g_at(x, y)) != 0) {
  340.             move_gold(gold, EGD(grd)->vroom);
  341.             movedgold = TRUE;
  342.             }
  343.             if(x == lowx-1 && y == lowy-1)
  344.             levl[x][y].typ = TLCORNER;
  345.             else if(x == hix+1 && y == lowy-1)
  346.             levl[x][y].typ = TRCORNER;
  347.             else if(x == lowx-1 && y == hiy+1)
  348.             levl[x][y].typ = BLCORNER;
  349.             else if(x == hix+1 && y == hiy+1)
  350.             levl[x][y].typ = BRCORNER;
  351.             else levl[x][y].typ = HWALL;
  352.  
  353.             levl[x][y].doormask = 0;
  354.             /*
  355.              * hack: player knows walls are restored because of the
  356.              * message, below, so show this on the screen.
  357.              */
  358.             tmp_viz = viz_array[y][x];
  359.             viz_array[y][x] = IN_SIGHT|COULD_SEE;
  360.             newsym(x,y);
  361.             viz_array[y][x] = tmp_viz;
  362.             block_point(x,y);
  363.             fixed = TRUE;
  364.         }
  365.         }
  366.     for(x = lowx-1; x <= hix+1; x += (hix-lowx+2))
  367.         for(y = lowy; y <= hiy; y++) {
  368.         if(!IS_WALL(levl[x][y].typ) && !in_fcorridor(grd, x, y)) {
  369.             if(MON_AT(x, y) && grd->mx != x && grd->my != y) {
  370.             struct monst *mon = m_at(x,y);
  371. #ifdef SOUNDS
  372.             yelp(mon);
  373. #endif
  374.             rloc(mon);
  375.             }
  376.             if ((gold = g_at(x, y)) != 0) {
  377.             move_gold(gold, EGD(grd)->vroom);
  378.             movedgold = TRUE;
  379.             }
  380.             levl[x][y].typ = VWALL;
  381.             levl[x][y].doormask = 0;
  382.             tmp_viz = viz_array[y][x];
  383.             viz_array[y][x] = IN_SIGHT|COULD_SEE;
  384.             newsym(x,y);
  385.             viz_array[y][x] = tmp_viz;
  386.             block_point(x,y);
  387.             fixed = TRUE;
  388.         }
  389.         }
  390.  
  391.     if(movedgold || fixed) {
  392.         if(in_fcorridor(grd, grd->mx, grd->my) || cansee(grd->mx, grd->my))
  393.         pline("The guard whispers an incantation.");
  394.         else You("hear a distant chant.");
  395.         if(movedgold)
  396.         pline("A mysterious force moves the gold into the vault.");
  397.         if(fixed)
  398.         pline("The damaged vault's walls are magically restored!");
  399.     }
  400. }
  401.  
  402. /*
  403.  * return  1: guard moved,  0: guard didn't,  -1: let m_move do it,  -2: died
  404.  */
  405. int
  406. gd_move(grd)
  407. register struct monst *grd;
  408. {
  409.     int x, y, nx, ny, m, n;
  410.     int dx, dy, gx, gy, fci;
  411.     uchar typ;
  412.     struct fakecorridor *fcp;
  413.     register struct egd *egrd = EGD(grd);
  414.     register struct rm *crm;
  415.     register boolean goldincorridor = FALSE,
  416.              u_in_vault = vault_occupied(u.urooms)? TRUE : FALSE,
  417.              grd_in_vault = *in_rooms(grd->mx, grd->my, VAULT)?
  418.                     TRUE : FALSE;
  419.     boolean disappear_msg_seen = FALSE, semi_dead = (grd->mhp <= 0);
  420.     register boolean u_carry_gold = ((u.ugold + hidden_gold()) > 0L);
  421.  
  422.     if(!on_level(&(egrd->gdlevel), &u.uz)) return(-1);
  423.     nx = ny = m = n = 0;
  424.     if(!u_in_vault && !grd_in_vault)
  425.         wallify_vault(grd);
  426.     if(!grd->mpeaceful) {
  427.         if(semi_dead) {
  428.         egrd->gddone =1;
  429.         goto newpos;
  430.         }
  431.         if(!u_in_vault &&
  432.            (grd_in_vault ||
  433.         (in_fcorridor(grd, grd->mx, grd->my) &&
  434.          !in_fcorridor(grd, u.ux, u.uy)))) {
  435.         rloc(grd);
  436.         wallify_vault(grd);
  437.         (void) clear_fcorr(grd, TRUE);
  438.         goto letknow;
  439.         }
  440.         if(!in_fcorridor(grd, grd->mx, grd->my))
  441.         (void) clear_fcorr(grd, TRUE);
  442.         return(-1);
  443.     }
  444.     if(abs(egrd->ogx - grd->mx) > 1 ||
  445.             abs(egrd->ogy - grd->my) > 1)
  446.         return(-1);    /* teleported guard - treat as monster */
  447.     if(egrd->fcend == 1) {
  448.         if(u_in_vault &&
  449.             (u_carry_gold || um_dist(grd->mx, grd->my, 1))) {
  450.         if(egrd->warncnt == 3)
  451.             verbalize("I repeat, %sfollow me!",
  452.                 u_carry_gold ? (!u.ugold ?
  453.                       "drop that hidden gold and " :
  454.                       "drop that gold and ") : "");
  455.         if(egrd->warncnt == 7) {
  456.             m = grd->mx;
  457.             n = grd->my;
  458.             verbalize("You've been warned, knave!");
  459.             mnexto(grd);
  460.             levl[m][n].typ = egrd->fakecorr[0].ftyp;
  461.             newsym(m,n);
  462.             grd->mpeaceful = 0;
  463.             return(-1);
  464.         }
  465.         /* not fair to get mad when (s)he's fainted or paralyzed */
  466.         if(!is_fainted() && multi >= 0) egrd->warncnt++;
  467.         return(0);
  468.         }
  469.  
  470.         if (!u_in_vault)
  471.         if (u_carry_gold) {    /* player teleported */
  472.             m = grd->mx;
  473.             n = grd->my;
  474.             rloc(grd);
  475.             levl[m][n].typ = egrd->fakecorr[0].ftyp;
  476.             newsym(m,n);
  477.             grd->mpeaceful = 0;
  478. letknow:
  479.             if(!cansee(grd->mx, grd->my))
  480.             You("hear the shrill sound of a guard's whistle.");
  481.             else
  482.             You(um_dist(grd->mx, grd->my, 2) ?
  483.                 "see an angry %s approaching." :
  484.                 "are confronted by an angry %s.",
  485.                 l_monnam(grd));
  486.             return(-1);
  487.         } else {
  488.             verbalize("Well, begone.");
  489.             wallify_vault(grd);
  490.             egrd->gddone = 1;
  491.             goto cleanup;
  492.         }
  493.     }
  494.  
  495.     if(egrd->fcend > 1) {
  496.         if(egrd->fcend > 2 && in_fcorridor(grd, grd->mx, grd->my) &&
  497.           !egrd->gddone && !in_fcorridor(grd, u.ux, u.uy) &&
  498.           levl[egrd->fakecorr[0].fx][egrd->fakecorr[0].fy].typ
  499.                  == egrd->fakecorr[0].ftyp) {
  500.         pline("The guard, confused, disappears.");
  501.         disappear_msg_seen = TRUE;
  502.         goto cleanup;
  503.         }
  504.         if(u_carry_gold &&
  505.             (in_fcorridor(grd, u.ux, u.uy) ||
  506.             /* cover a 'blind' spot */
  507.             (egrd->fcend > 1 && u_in_vault))) {
  508.         if(!grd->mx) {
  509.             restfakecorr(grd);
  510.             return(-2);
  511.         }
  512.         if(egrd->warncnt < 6) {
  513.             egrd->warncnt = 6;
  514.             verbalize("Drop all your gold, scoundrel!");
  515.             return(0);
  516.         } else {
  517.             verbalize("So be it, rogue!");
  518.             grd->mpeaceful = 0;
  519.             return(-1);
  520.         }
  521.         }
  522.     }
  523.     for(fci = egrd->fcbeg; fci < egrd->fcend; fci++)
  524.         if(g_at(egrd->fakecorr[fci].fx, egrd->fakecorr[fci].fy)){
  525.         m = egrd->fakecorr[fci].fx;
  526.         n = egrd->fakecorr[fci].fy;
  527.         goldincorridor = TRUE;
  528.         }
  529.     if(goldincorridor && !egrd->gddone) {
  530.         x = grd->mx;
  531.         y = grd->my;
  532.         if (m == u.ux && n == u.uy) {
  533.             struct obj *gold = g_at(m,n);
  534.             /* Grab the gold from between the hero's feet.  */
  535.             grd->mgold += gold->quan;
  536.             delobj(gold);
  537.             newsym(m,n);
  538.         } else if (m == x && n == y) {
  539.             mpickgold(grd);    /* does a newsym */
  540.         } else {
  541.             /* just for insurance... */
  542.             if (MON_AT(m, n) && m != grd->mx && n != grd->my) {
  543.             verbalize("Out of my way, scum!");
  544.             rloc(m_at(m, n));
  545.             }
  546.             remove_monster(grd->mx, grd->my);
  547.             place_monster(grd, m, n);
  548.             mpickgold(grd);    /* does a newsym */
  549.         }
  550.         if(cansee(m,n))
  551.             pline("%s%s picks up the gold.", Monnam(grd),
  552.                 grd->mpeaceful ? " calms down and" : "");
  553.         if(x != grd->mx || y != grd->my) {
  554.             remove_monster(grd->mx, grd->my);
  555.             place_monster(grd, x, y);
  556.             newsym(grd->mx,grd->my);
  557.         }
  558.         if(!grd->mpeaceful) return(-1);
  559.         else {
  560.             egrd->warncnt = 5;
  561.             return(0);
  562.         }
  563.     }
  564.     if(um_dist(grd->mx, grd->my, 1) || egrd->gddone) {
  565.         if(!egrd->gddone && !rn2(10)) verbalize("Move along!");
  566.         restfakecorr(grd);
  567.         return(0);    /* didn't move */
  568.     }
  569.     x = grd->mx;
  570.     y = grd->my;
  571.  
  572.     if(u_in_vault) goto nextpos;
  573.  
  574.     /* look around (hor & vert only) for accessible places */
  575.     for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) {
  576.       if((nx == x || ny == y) && (nx != x || ny != y) && isok(nx, ny)) {
  577.  
  578.         typ = (crm = &levl[nx][ny])->typ;
  579.         if(!IS_STWALL(typ) && !IS_POOL(typ)) {
  580.  
  581.         if(in_fcorridor(grd, nx, ny))
  582.             goto nextnxy;
  583.  
  584.         if(*in_rooms(nx,ny,VAULT))
  585.             continue;
  586.  
  587.         /* seems we found a good place to leave him alone */
  588.         egrd->gddone = 1;
  589.         if(ACCESSIBLE(typ)) goto newpos;
  590. #ifdef STUPID
  591.         if (typ == SCORR)
  592.             crm->typ = CORR;
  593.         else
  594.             crm->typ = DOOR;
  595. #else
  596.         crm->typ = (typ == SCORR) ? CORR : DOOR;
  597. #endif
  598.         if(crm->typ == DOOR) crm->doormask = D_NODOOR;
  599.         goto proceed;
  600.         }
  601.       }
  602. nextnxy:    ;
  603.     }
  604. nextpos:
  605.     nx = x;
  606.     ny = y;
  607.     gx = egrd->gdx;
  608.     gy = egrd->gdy;
  609.     dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
  610.     dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
  611.     if(abs(gx-x) >= abs(gy-y)) nx += dx; else ny += dy;
  612.  
  613.     while((typ = (crm = &levl[nx][ny])->typ) != 0) {
  614.     /* in view of the above we must have IS_WALL(typ) or typ == POOL */
  615.     /* must be a wall here */
  616.         if(isok(nx+nx-x,ny+ny-y) && !IS_POOL(typ) &&
  617.             IS_ROOM(levl[nx+nx-x][ny+ny-y].typ)){
  618.             crm->typ = DOOR;
  619.             crm->doormask = D_NODOOR;
  620.             goto proceed;
  621.         }
  622.         if(dy && nx != x) {
  623.             nx = x; ny = y+dy;
  624.             continue;
  625.         }
  626.         if(dx && ny != y) {
  627.             ny = y; nx = x+dx; dy = 0;
  628.             continue;
  629.         }
  630.         /* I don't like this, but ... */
  631.         if(IS_ROOM(typ)) {
  632.             crm->typ = DOOR;
  633.             crm->doormask = D_NODOOR;
  634.             goto proceed;
  635.         }
  636.         break;
  637.     }
  638.     crm->typ = CORR;
  639. proceed:
  640.     if (cansee(nx,ny))
  641.         newsym(nx,ny);
  642.  
  643.     fcp = &(egrd->fakecorr[egrd->fcend]);
  644.     if(egrd->fcend++ == FCSIZ) panic("fakecorr overflow");
  645.     fcp->fx = nx;
  646.     fcp->fy = ny;
  647.     fcp->ftyp = typ;
  648. newpos:
  649.     if(egrd->gddone) {
  650.         /* The following is a kluge.  We need to keep     */
  651.         /* the guard around in order to be able to make   */
  652.         /* the fake corridor disappear as the player      */
  653.         /* moves out of it, but we also need the guard    */
  654.         /* out of the way.  We send the guard to never-   */
  655.         /* never land.  We set ogx ogy to mx my in order  */
  656.         /* to avoid a check at the top of this function.  */
  657.         /* At the end of the process, the guard is killed */
  658.         /* in restfakecorr().                  */
  659. cleanup:
  660.         x = grd->mx; y = grd->my;
  661.  
  662.         wallify_vault(grd);
  663.         remove_monster(grd->mx, grd->my);
  664.         newsym(grd->mx,grd->my);
  665.         place_monster(grd, 0, 0);
  666.         egrd->ogx = grd->mx;
  667.         egrd->ogy = grd->my;
  668.         restfakecorr(grd);
  669.         if(!semi_dead && (in_fcorridor(grd, u.ux, u.uy) ||
  670.                      cansee(x, y))) {
  671.             if (!disappear_msg_seen)
  672.             pline("Suddenly, the guard disappears.");
  673.             return(1);
  674.         }
  675.         return(-2);
  676.     }
  677.     egrd->ogx = grd->mx;    /* update old positions */
  678.     egrd->ogy = grd->my;
  679.     remove_monster(grd->mx, grd->my);
  680.     place_monster(grd, nx, ny);
  681.     newsym(grd->mx,grd->my);
  682.     restfakecorr(grd);
  683.     return(1);
  684. }
  685.  
  686. /* Routine when dying or quitting with a vault guard around */
  687. void
  688. paygd()
  689. {
  690.  
  691.     register struct monst *grd = findgd();
  692.     struct obj *gold;
  693.     int gx,gy;
  694.     char buf[BUFSZ];
  695.  
  696.     if (!u.ugold || !grd) return;
  697.  
  698.     if (u.uinvault) {
  699.         Your("%ld zorkmid%s goes into the Magic Memory Vault.",
  700.         u.ugold, plur(u.ugold));
  701.         gx = u.ux;
  702.         gy = u.uy;
  703.     } else {
  704.         if(grd->mpeaceful) { /* guard has no "right" to your gold */
  705.         mongone(grd);
  706.         return;
  707.         }
  708.         mnexto(grd);
  709.         pline("%s remits your gold to the vault.", Monnam(grd));
  710.         gx = rooms[EGD(grd)->vroom].lx + rn2(2);
  711.         gy = rooms[EGD(grd)->vroom].ly + rn2(2);
  712.         Sprintf(buf,
  713.         "To Croesus: here's the gold recovered from %s the %s.",
  714.         plname, player_mon()->mname);
  715.         make_engr_at(gx, gy, buf, 0L, ENGRAVE);
  716.     }
  717.     place_object(gold = mkgoldobj(u.ugold), gx, gy);
  718.     stackobj(gold);
  719.     mongone(grd);
  720. }
  721.  
  722. long
  723. hidden_gold()
  724. {
  725.     register long value = 0L;
  726.     register struct obj *obj;
  727.  
  728.     for (obj = invent; obj; obj = obj->nobj)
  729.         if (Has_contents(obj))
  730.         value += contained_gold(obj);
  731.     /* unknown gold stuck inside statues may cause some consternation... */
  732.  
  733.     return(value);
  734. }
  735.  
  736. #ifdef SOUNDS
  737. boolean
  738. gd_sound()  /* prevent "You hear footsteps.." when inappropriate */
  739. {
  740.     register struct monst *grd = findgd();
  741.  
  742.     return((boolean)(grd == (struct monst *)0));
  743. }
  744. #endif
  745.  
  746. #endif /* OVLB */
  747.  
  748. /*vault.c*/
  749.