Fandom

Wikihack

Source:NetHack 3.1.0/vault.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Below is the full text to vault.c from the source code of NetHack 3.1.0. To link to a particular line, write [[NetHack 3.1.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.
1.    /*	SCCS Id: @(#)vault.c	3.1	93/01/15	*/
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_background(fcx,fcy, 1);
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.  	clear_nhwindow(WIN_MESSAGE);
257.  	verbalize("I don't know you.");
258.  	if (!u.ugold && !hidden_gold())
259.  	    verbalize("Please follow me.");
260.  	else {
261.  	    if (!u.ugold)
262.  		verbalize("You have hidden gold.");
263.  	    verbalize("Most likely all your gold was stolen from this vault.");
264.  	    verbalize("Please drop that gold and follow me.");
265.  	}
266.  	EGD(guard)->gdx = gx;
267.  	EGD(guard)->gdy = gy;
268.  	EGD(guard)->fcbeg = 0;
269.  	EGD(guard)->fakecorr[0].fx = x;
270.  	EGD(guard)->fakecorr[0].fy = y;
271.  	if(IS_WALL(levl[x][y].typ))
272.  	    EGD(guard)->fakecorr[0].ftyp = levl[x][y].typ;
273.  	else { /* the initial guard location is a dug door */
274.  	    int vlt = EGD(guard)->vroom;
275.  	    xchar lowx = rooms[vlt].lx, hix = rooms[vlt].hx;
276.  	    xchar lowy = rooms[vlt].ly, hiy = rooms[vlt].hy;
277.  
278.  	    if(x == lowx-1 && y == lowy-1)
279.  		EGD(guard)->fakecorr[0].ftyp = TLCORNER;
280.  	    else if(x == hix+1 && y == lowy-1)
281.  		EGD(guard)->fakecorr[0].ftyp = TRCORNER;
282.  	    else if(x == lowx-1 && y == hiy+1)
283.  		EGD(guard)->fakecorr[0].ftyp = BLCORNER;
284.  	    else if(x == hix+1 && y == hiy+1)
285.  		EGD(guard)->fakecorr[0].ftyp = BRCORNER;
286.  	    else if(y == lowy-1 || y == hiy+1)
287.  		EGD(guard)->fakecorr[0].ftyp = HWALL;
288.  	    else if(x == lowx-1 || x == hix+1)
289.  		EGD(guard)->fakecorr[0].ftyp = VWALL;
290.  	}
291.  	levl[x][y].typ = DOOR;
292.  	levl[x][y].doormask = D_NODOOR;
293.  	EGD(guard)->fcend = 1;
294.  	EGD(guard)->warncnt = 1;
295.      }
296.  }
297.  
298.  #endif /* OVL0 */
299.  #ifdef OVLB
300.  
301.  static void
302.  move_gold(gold, vroom)
303.  struct obj *gold;
304.  int vroom;
305.  {
306.  	xchar nx, ny;
307.  
308.  	remove_object(gold);
309.  	newsym(gold->ox, gold->oy);
310.  	nx = rooms[vroom].lx + rn2(2);
311.  	ny = rooms[vroom].ly + rn2(2);
312.  	place_object(gold, nx, ny);
313.  	stackobj(gold);
314.  	newsym(nx,ny);
315.  }
316.  
317.  static void
318.  wallify_vault(grd)
319.  struct monst *grd;
320.  {
321.  	int x, y;
322.  	int vlt = EGD(grd)->vroom;
323.  	char tmp_viz;
324.  	xchar lowx = rooms[vlt].lx, hix = rooms[vlt].hx;
325.  	xchar lowy = rooms[vlt].ly, hiy = rooms[vlt].hy;
326.  	register struct obj *gold;
327.  	register boolean fixed = FALSE;
328.  	register boolean movedgold = FALSE;
329.  
330.  	for(x = lowx-1; x <= hix+1; x++)
331.  	    for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) {
332.  		if(!IS_WALL(levl[x][y].typ) && !in_fcorridor(grd, x, y)) {
333.  		    struct monst *mon;
334.  
335.  		    if((mon = m_at(x, y)) && grd->mx != x && grd->my != y) {
336.  			if (mon->data->msound != MS_SILENT)
337.  			    You("hear a scream.");
338.  			rloc(m_at(x,y));
339.  		    }
340.  		    if ((gold = g_at(x, y)) != 0) {
341.  			move_gold(gold, EGD(grd)->vroom);
342.  			movedgold = TRUE;
343.  		    }
344.  		    if(x == lowx-1 && y == lowy-1)
345.  			levl[x][y].typ = TLCORNER;
346.  		    else if(x == hix+1 && y == lowy-1)
347.  			levl[x][y].typ = TRCORNER;
348.  		    else if(x == lowx-1 && y == hiy+1)
349.  			levl[x][y].typ = BLCORNER;
350.  		    else if(x == hix+1 && y == hiy+1)
351.  			levl[x][y].typ = BRCORNER;
352.  		    else levl[x][y].typ = HWALL;
353.  
354.  		    levl[x][y].doormask = 0;
355.  		    /*
356.  		     * hack: player knows walls are restored because of the
357.  		     * message, below, so show this on the screen.
358.  		     */
359.  		    tmp_viz = viz_array[y][x];
360.  		    viz_array[y][x] = IN_SIGHT|COULD_SEE;
361.  		    newsym(x,y);
362.  		    viz_array[y][x] = tmp_viz;
363.  		    block_point(x,y);
364.  		    fixed = TRUE;
365.  		}
366.  	    }
367.  	for(x = lowx-1; x <= hix+1; x += (hix-lowx+2))
368.  	    for(y = lowy; y <= hiy; y++) {
369.  		if(!IS_WALL(levl[x][y].typ) && !in_fcorridor(grd, x, y)) {
370.  		    if(MON_AT(x, y) && grd->mx != x && grd->my != y) {
371.  			You("hear a scream.");
372.  			rloc(m_at(x,y));
373.  		    }
374.  		    if ((gold = g_at(x, y)) != 0) {
375.  			move_gold(gold, EGD(grd)->vroom);
376.  			movedgold = TRUE;
377.  		    }
378.  		    levl[x][y].typ = VWALL;
379.  		    levl[x][y].doormask = 0;
380.  		    tmp_viz = viz_array[y][x];
381.  		    viz_array[y][x] = IN_SIGHT|COULD_SEE;
382.  		    newsym(x,y);
383.  		    viz_array[y][x] = tmp_viz;
384.  		    block_point(x,y);
385.  		    fixed = TRUE;
386.  		}
387.  	    }
388.  
389.  	if(movedgold || fixed) {
390.  	    if(in_fcorridor(grd, grd->mx, grd->my) || cansee(grd->mx, grd->my))
391.  		pline("The guard whispers an incantation.");
392.  	    else You("hear a distant chant.");
393.  	    if(movedgold)
394.  		pline("A mysterious force moves the gold into the vault.");
395.  	    if(fixed)
396.  		pline("The damaged vault's walls are magically restored!");
397.  	}
398.  }
399.  
400.  /*
401.   * return  1: guard moved,  0: guard didn't,  -1: let m_move do it,  -2: died
402.   */
403.  int
404.  gd_move(grd)
405.  register struct monst *grd;
406.  {
407.  	int x, y, nx, ny, m, n;
408.  	int dx, dy, gx, gy, fci;
409.  	uchar typ;
410.  	struct fakecorridor *fcp;
411.  	register struct egd *egrd = EGD(grd);
412.  	register struct rm *crm;
413.  	register boolean goldincorridor = FALSE,
414.  			 u_in_vault = vault_occupied(u.urooms)? TRUE : FALSE,
415.  			 grd_in_vault = *in_rooms(grd->mx, grd->my, VAULT)?
416.  					TRUE : FALSE;
417.  	boolean disappear_msg_seen = FALSE, semi_dead = (grd->mhp <= 0);
418.  	register boolean u_carry_gold = ((u.ugold + hidden_gold()) > 0L);
419.  
420.  	if(!on_level(&(egrd->gdlevel), &u.uz)) return(-1);
421.  	nx = ny = m = n = 0;
422.  	if(!u_in_vault && !grd_in_vault)
423.  	    wallify_vault(grd);
424.  	if(!grd->mpeaceful) {
425.  	    if(semi_dead) {
426.  		egrd->gddone =1;
427.  		goto newpos;
428.  	    }
429.  	    if(!u_in_vault &&
430.  	       (grd_in_vault ||
431.  		(in_fcorridor(grd, grd->mx, grd->my) &&
432.  		 !in_fcorridor(grd, u.ux, u.uy)))) {
433.  		rloc(grd);
434.  		wallify_vault(grd);
435.  		(void) clear_fcorr(grd, TRUE);
436.  		goto letknow;
437.  	    }
438.  	    if(!in_fcorridor(grd, grd->mx, grd->my))
439.  		(void) clear_fcorr(grd, TRUE);
440.  	    return(-1);
441.  	}
442.  	if(abs(egrd->ogx - grd->mx) > 1 ||
443.  			abs(egrd->ogy - grd->my) > 1)
444.  		return(-1);	/* teleported guard - treat as monster */
445.  	if(egrd->fcend == 1) {
446.  	    if(u_in_vault &&
447.  			(u_carry_gold || um_dist(grd->mx, grd->my, 1))) {
448.  		if(egrd->warncnt == 3)
449.  			verbalize("I repeat, %sfollow me!",
450.  				u_carry_gold ? (!u.ugold ?
451.  					  "drop that hidden gold and " :
452.  					  "drop that gold and ") : "");
453.  		if(egrd->warncnt == 7) {
454.  			m = grd->mx;
455.  			n = grd->my;
456.  			verbalize("You've been warned, knave!");
457.  			mnexto(grd);
458.  			levl[m][n].typ = egrd->fakecorr[0].ftyp;
459.  			newsym(m,n);
460.  			grd->mpeaceful = 0;
461.  			return(-1);
462.  		}
463.  		/* not fair to get mad when (s)he's fainted or paralyzed */
464.  		if(!is_fainted() && multi >= 0) egrd->warncnt++;
465.  		return(0);
466.  	    }
467.  
468.  	    if (!u_in_vault)
469.  		if (u_carry_gold) {	/* player teleported */
470.  		    m = grd->mx;
471.  		    n = grd->my;
472.  		    rloc(grd);
473.  		    levl[m][n].typ = egrd->fakecorr[0].ftyp;
474.  		    newsym(m,n);
475.  		    grd->mpeaceful = 0;
476.  letknow:
477.  		    if(!cansee(grd->mx, grd->my))
478.  			You("hear the shrill sound of a guard's whistle.");
479.  		    else
480.  			You(um_dist(grd->mx, grd->my, 2) ?
481.  			    "see an angry %s approaching." :
482.  			    "are confronted by an angry %s.",
483.  			    l_monnam(grd));
484.  		    return(-1);
485.  		} else {
486.  		    verbalize("Well, be gone your way.");
487.  		    wallify_vault(grd);
488.  		    egrd->gddone = 1;
489.  		    goto cleanup;
490.  		}
491.  	}
492.  
493.  	if(egrd->fcend > 1) {
494.  	    if(egrd->fcend > 2 && in_fcorridor(grd, grd->mx, grd->my) &&
495.  		  !egrd->gddone && !in_fcorridor(grd, u.ux, u.uy) &&
496.  		  levl[egrd->fakecorr[0].fx][egrd->fakecorr[0].fy].typ
497.  				 == egrd->fakecorr[0].ftyp) {
498.  		pline("The guard, confused, disappears.");
499.  		disappear_msg_seen = TRUE;
500.  		goto cleanup;
501.  	    }
502.  	    if(u_carry_gold &&
503.  		    (in_fcorridor(grd, u.ux, u.uy) ||
504.  		    /* cover a 'blind' spot */
505.  		    (egrd->fcend > 1 && u_in_vault))) {
506.  		if(!grd->mx) {
507.  			restfakecorr(grd);
508.  			return(-2);
509.  		}
510.  		if(egrd->warncnt < 6) {
511.  			egrd->warncnt = 6;
512.  			verbalize("Drop all your gold, scoundrel!");
513.  			return(0);
514.  		} else {
515.  			verbalize("So be it, rogue!");
516.  			grd->mpeaceful = 0;
517.  			return(-1);
518.  		}
519.  	    }
520.  	}
521.  	for(fci = egrd->fcbeg; fci < egrd->fcend; fci++)
522.  	    if(g_at(egrd->fakecorr[fci].fx, egrd->fakecorr[fci].fy)){
523.  		m = egrd->fakecorr[fci].fx;
524.  		n = egrd->fakecorr[fci].fy;
525.  		goldincorridor = TRUE;
526.  	    }
527.  	if(goldincorridor && !egrd->gddone) {
528.  		x = grd->mx;
529.  		y = grd->my;
530.  		if (m == u.ux && n == u.uy) {
531.  		    struct obj *gold = g_at(m,n);
532.  		    /* Grab the gold from between the hero's feet.  */
533.  		    grd->mgold += gold->quan;
534.  		    delobj(gold);
535.  		    newsym(m,n);
536.  		} else if (m == x && n == y) {
537.  		    mpickgold(grd);	/* does a newsym */
538.  		} else {
539.  		    /* just for insurance... */
540.  		    if (MON_AT(m, n) && m != grd->mx && n != grd->my) {
541.  			verbalize("Out of my way, scum!");
542.  			rloc(m_at(m, n));
543.  		    }
544.  		    remove_monster(grd->mx, grd->my);
545.  		    place_monster(grd, m, n);
546.  		    mpickgold(grd);	/* does a newsym */
547.  		}
548.  		if(cansee(m,n))
549.  		    pline("%s%s picks up the gold.", Monnam(grd),
550.  				grd->mpeaceful ? " calms down and" : "");
551.  		if(x != grd->mx || y != grd->my) {
552.  		    remove_monster(grd->mx, grd->my);
553.  		    place_monster(grd, x, y);
554.  		    newsym(grd->mx,grd->my);
555.  		}
556.  		if(!grd->mpeaceful) return(-1);
557.  		else {
558.  		    egrd->warncnt = 5;
559.  		    return(0);
560.  		}
561.  	}
562.  	if(um_dist(grd->mx, grd->my, 1) || egrd->gddone) {
563.  		if(!egrd->gddone && !rn2(10)) verbalize("Move along!");
564.  		restfakecorr(grd);
565.  		return(0);	/* didn't move */
566.  	}
567.  	x = grd->mx;
568.  	y = grd->my;
569.  
570.  	if(u_in_vault) goto nextpos;
571.  
572.  	/* look around (hor & vert only) for accessible places */
573.  	for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) {
574.  	  if((nx == x || ny == y) && (nx != x || ny != y) && isok(nx, ny)) {
575.  
576.  	    typ = (crm = &levl[nx][ny])->typ;
577.  	    if(!IS_STWALL(typ) && !IS_POOL(typ)) {
578.  
579.  		if(in_fcorridor(grd, nx, ny))
580.  			goto nextnxy;
581.  
582.  		if(*in_rooms(nx,ny,VAULT))
583.  			continue;
584.  
585.  		/* seems we found a good place to leave him alone */
586.  		egrd->gddone = 1;
587.  		if(ACCESSIBLE(typ)) goto newpos;
588.  #ifdef STUPID
589.  		if (typ == SCORR)
590.  		    crm->typ = CORR;
591.  		else
592.  		    crm->typ = DOOR;
593.  #else
594.  		crm->typ = (typ == SCORR) ? CORR : DOOR;
595.  #endif
596.  		if(crm->typ == DOOR) crm->doormask = D_NODOOR;
597.  		goto proceed;
598.  	    }
599.  	  }
600.  nextnxy:	;
601.  	}
602.  nextpos:
603.  	nx = x;
604.  	ny = y;
605.  	gx = egrd->gdx;
606.  	gy = egrd->gdy;
607.  	dx = (gx > x) ? 1 : (gx < x) ? -1 : 0;
608.  	dy = (gy > y) ? 1 : (gy < y) ? -1 : 0;
609.  	if(abs(gx-x) >= abs(gy-y)) nx += dx; else ny += dy;
610.  
611.  	while((typ = (crm = &levl[nx][ny])->typ) != 0) {
612.  	/* in view of the above we must have IS_WALL(typ) or typ == POOL */
613.  	/* must be a wall here */
614.  		if(isok(nx+nx-x,ny+ny-y) && !IS_POOL(typ) &&
615.  		    IS_ROOM(levl[nx+nx-x][ny+ny-y].typ)){
616.  			crm->typ = DOOR;
617.  			crm->doormask = D_NODOOR;
618.  			goto proceed;
619.  		}
620.  		if(dy && nx != x) {
621.  			nx = x; ny = y+dy;
622.  			continue;
623.  		}
624.  		if(dx && ny != y) {
625.  			ny = y; nx = x+dx; dy = 0;
626.  			continue;
627.  		}
628.  		/* I don't like this, but ... */
629.  		if(IS_ROOM(typ)) {
630.  			crm->typ = DOOR;
631.  			crm->doormask = D_NODOOR;
632.  			goto proceed;
633.  		}
634.  		break;
635.  	}
636.  	crm->typ = CORR;
637.  proceed:
638.  	if (cansee(nx,ny))
639.  	    newsym(nx,ny);
640.  
641.  	fcp = &(egrd->fakecorr[egrd->fcend]);
642.  	if(egrd->fcend++ == FCSIZ) panic("fakecorr overflow");
643.  	fcp->fx = nx;
644.  	fcp->fy = ny;
645.  	fcp->ftyp = typ;
646.  newpos:
647.  	if(egrd->gddone) {
648.  		/* The following is a kluge.  We need to keep     */
649.  		/* the guard around in order to be able to make   */
650.  		/* the fake corridor disappear as the player      */
651.  		/* moves out of it, but we also need the guard    */
652.  		/* out of the way.  We send the guard to never-   */
653.  		/* never land.  We set ogx ogy to mx my in order  */
654.  		/* to avoid a check at the top of this function.  */
655.  		/* At the end of the process, the guard is killed */
656.  		/* in restfakecorr().				  */
657.  cleanup:
658.  		x = grd->mx; y = grd->my;
659.  
660.  		wallify_vault(grd);
661.  		remove_monster(grd->mx, grd->my);
662.  		newsym(grd->mx,grd->my);
663.  		place_monster(grd, 0, 0);
664.  		egrd->ogx = grd->mx;
665.  		egrd->ogy = grd->my;
666.  		restfakecorr(grd);
667.  		if(!semi_dead && (in_fcorridor(grd, u.ux, u.uy) ||
668.  				     cansee(x, y))) {
669.  		    if (!disappear_msg_seen)
670.  			pline("Suddenly, the guard disappears.");
671.  		    return(1);
672.  		}
673.  		return(-2);
674.  	}
675.  	egrd->ogx = grd->mx;	/* update old positions */
676.  	egrd->ogy = grd->my;
677.  	remove_monster(grd->mx, grd->my);
678.  	place_monster(grd, nx, ny);
679.  	newsym(grd->mx,grd->my);
680.  	restfakecorr(grd);
681.  	return(1);
682.  }
683.  
684.  /* Routine when dying or quitting with a vault guard around */
685.  void
686.  paygd()
687.  {
688.  
689.  	register struct monst *grd = findgd();
690.  	struct obj *gold;
691.  	int gx,gy;
692.  	char buf[BUFSZ];
693.  
694.  	if (!u.ugold || !grd) return;
695.  
696.  	if (u.uinvault) {
697.  	    Your("%ld zorkmid%s goes into the Magic Memory Vault.",
698.  		u.ugold, plur(u.ugold));
699.  	    gx = u.ux;
700.  	    gy = u.uy;
701.  	} else {
702.  	    if(grd->mpeaceful) { /* guard has no "right" to your gold */
703.  		mongone(grd);
704.  		return;
705.  	    }
706.  	    mnexto(grd);
707.  	    pline("%s remits your gold to the vault.", Monnam(grd));
708.  	    gx = rooms[EGD(grd)->vroom].lx + rn2(2);
709.  	    gy = rooms[EGD(grd)->vroom].ly + rn2(2);
710.  	    Sprintf(buf,
711.  		"To Croesus: here's the gold recovered from the %s %s...",
712.  		player_mon()->mname, plname);
713.  	    make_engr_at(gx, gy, buf, 0L, ENGRAVE);
714.  	}
715.  	place_object(gold = mkgoldobj(u.ugold), gx, gy);
716.  	stackobj(gold);
717.  	mongone(grd);
718.  }
719.  
720.  long
721.  hidden_gold()
722.  {
723.  	register long value = 0L;
724.  	register struct obj *obj;
725.  
726.  	for (obj = invent; obj; obj = obj->nobj)
727.  	    if (Is_container(obj))
728.  		value += contained_gold(obj);
729.  
730.  	return(value);
731.  }
732.  
733.  #ifdef SOUNDS
734.  boolean
735.  gd_sound()  /* prevent "You hear footsteps.." when inappropriate */
736.  {
737.  	register struct monst *grd = findgd();
738.  
739.  	return(grd == (struct monst *)0);
740.  }
741.  #endif
742.  
743.  #endif /* OVLB */
744.  
745.  /*vault.c*/

Also on Fandom

Random Wiki