Source:NetHack 3.4.0/vault.c

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

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

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