Source:NetHack 3.2.0/vault.c

From NetHackWiki
(Redirected from NetHack 3.2.0/vault.c)
Jump to navigation Jump to search

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

Warning! This is the source code from an old release. For the latest release, see Source code

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