Source:NetHack 3.4.3/src/vault.c

From NetHackWiki
(Redirected from Source:Ref/paygd)
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)vault.c	3.4	2003/01/15	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

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. #include "hack.h"
  2. #include "vault.h"
  3.  
  4. STATIC_DCL struct monst *NDECL(findgd);
  5.  
  6. #define g_monnam(mtmp) \
  7. 	x_monnam(mtmp, ARTICLE_NONE, (char *)0, SUPPRESS_IT, FALSE)
  8.  
  9. #ifdef OVLB
  10.  
  11. STATIC_DCL boolean FDECL(clear_fcorr, (struct monst *,BOOLEAN_P));
  12. STATIC_DCL void FDECL(restfakecorr,(struct monst *));
  13. STATIC_DCL boolean FDECL(in_fcorridor, (struct monst *,int,int));
  14. STATIC_DCL void FDECL(move_gold,(struct obj *,int));
  15. STATIC_DCL void FDECL(wallify_vault,(struct monst *));

clear_fcorr[edit]

  1. STATIC_OVL boolean
  2. clear_fcorr(grd, forceshow)
  3. register struct monst *grd;
  4. register boolean forceshow;
  5. {
  6. 	register int fcx, fcy, fcbeg;
  7. 	register struct monst *mtmp;
  8.  
  9. 	if (!on_level(&(EGD(grd)->gdlevel), &u.uz)) return TRUE;
  10.  
  11. 	while((fcbeg = EGD(grd)->fcbeg) < EGD(grd)->fcend) {
  12. 		fcx = EGD(grd)->fakecorr[fcbeg].fx;
  13. 		fcy = EGD(grd)->fakecorr[fcbeg].fy;
  14. 		if((grd->mhp <= 0 || !in_fcorridor(grd, u.ux, u.uy)) &&
  15. 				   EGD(grd)->gddone)
  16. 			forceshow = TRUE;
  17. 		if((u.ux == fcx && u.uy == fcy && grd->mhp > 0)
  18. 			|| (!forceshow && couldsee(fcx,fcy))
  19. 			|| (Punished && !carried(uball)
  20. 				&& uball->ox == fcx && uball->oy == fcy))
  21. 			return FALSE;
  22.  
  23. 		if ((mtmp = m_at(fcx,fcy)) != 0) {
  24. 			if(mtmp->isgd) return(FALSE);
  25. 			else if(!in_fcorridor(grd, u.ux, u.uy)) {
  26. 			    if(mtmp->mtame) yelp(mtmp);
  27. 			    (void) rloc(mtmp, FALSE);
  28. 			}
  29. 		}
  30. 		levl[fcx][fcy].typ = EGD(grd)->fakecorr[fcbeg].ftyp;
  31. 		map_location(fcx, fcy, 1);	/* bypass vision */
  32. 		if(!ACCESSIBLE(levl[fcx][fcy].typ)) block_point(fcx,fcy);
  33. 		EGD(grd)->fcbeg++;
  34. 	}
  35. 	if(grd->mhp <= 0) {
  36. 	    pline_The("corridor disappears.");
  37. 	    if(IS_ROCK(levl[u.ux][u.uy].typ)) You("are encased in rock.");
  38. 	}
  39. 	return(TRUE);
  40. }

restfakecorr[edit]

  1. STATIC_OVL void
  2. restfakecorr(grd)
  3. register struct monst *grd;
  4. {
  5. 	/* it seems you left the corridor - let the guard disappear */
  6. 	if(clear_fcorr(grd, FALSE)) mongone(grd);
  7. }

grddead[edit]

  1. boolean
  2. grddead(grd)				/* called in mon.c */
  3. register struct monst *grd;
  4. {
  5. 	register boolean dispose = clear_fcorr(grd, TRUE);
  6.  
  7. 	if(!dispose) {
  8. 		/* see comment by newpos in gd_move() */
  9. 		remove_monster(grd->mx, grd->my);
  10. 		newsym(grd->mx, grd->my);
  11. 		place_monster(grd, 0, 0);
  12. 		EGD(grd)->ogx = grd->mx;
  13. 		EGD(grd)->ogy = grd->my;
  14. 		dispose = clear_fcorr(grd, TRUE);
  15. 	}
  16. 	return(dispose);
  17. }

in_fcorridor[edit]

  1. STATIC_OVL boolean
  2. in_fcorridor(grd, x, y)
  3. register struct monst *grd;
  4. int x, y;
  5. {
  6. 	register int fci;
  7.  
  8. 	for(fci = EGD(grd)->fcbeg; fci < EGD(grd)->fcend; fci++)
  9. 		if(x == EGD(grd)->fakecorr[fci].fx &&
  10. 				y == EGD(grd)->fakecorr[fci].fy)
  11. 			return(TRUE);
  12. 	return(FALSE);
  13. }

findgd[edit]

  1. STATIC_OVL
  2. struct monst *
  3. findgd()
  4. {
  5. 	register struct monst *mtmp;
  6.  
  7. 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  8. 	    if(mtmp->isgd && !DEADMONSTER(mtmp) && on_level(&(EGD(mtmp)->gdlevel), &u.uz))
  9. 		return(mtmp);
  10. 	return((struct monst *)0);
  11. }
  12.  
  13. #endif /* OVLB */
  14. #ifdef OVL0

vault_occupied[edit]

  1. char
  2. vault_occupied(array)
  3. char *array;
  4. {
  5. 	register char *ptr;
  6.  
  7. 	for (ptr = array; *ptr; ptr++)
  8. 		if (rooms[*ptr - ROOMOFFSET].rtype == VAULT)
  9. 			return(*ptr);
  10. 	return('\0');
  11. }

invault[edit]

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

move_gold[edit]

  1. STATIC_OVL void
  2. move_gold(gold, vroom)
  3. struct obj *gold;
  4. int vroom;
  5. {
  6. 	xchar nx, ny;
  7.  
  8. 	remove_object(gold);
  9. 	newsym(gold->ox, gold->oy);
  10. 	nx = rooms[vroom].lx + rn2(2);
  11. 	ny = rooms[vroom].ly + rn2(2);
  12. 	place_object(gold, nx, ny);
  13. 	stackobj(gold);
  14. 	newsym(nx,ny);
  15. }

wallify_vault[edit]

  1. STATIC_OVL void
  2. wallify_vault(grd)
  3. struct monst *grd;
  4. {
  5. 	int x, y, typ;
  6. 	int vlt = EGD(grd)->vroom;
  7. 	char tmp_viz;
  8. 	xchar lox = rooms[vlt].lx - 1, hix = rooms[vlt].hx + 1,
  9. 	      loy = rooms[vlt].ly - 1, hiy = rooms[vlt].hy + 1;
  10. 	struct monst *mon;
  11. 	struct obj *gold;
  12. 	struct trap *trap;
  13. 	boolean fixed = FALSE;
  14. 	boolean movedgold = FALSE;
  15.  
  16. 	for (x = lox; x <= hix; x++)
  17. 	    for (y = loy; y <= hiy; y++) {
  18. 		/* if not on the room boundary, skip ahead */
  19. 		if (x != lox && x != hix && y != loy && y != hiy) continue;
  20.  
  21. 		if (!IS_WALL(levl[x][y].typ) && !in_fcorridor(grd, x, y)) {
  22. 		    if ((mon = m_at(x, y)) != 0 && mon != grd) {
  23. 			if (mon->mtame) yelp(mon);
  24. 			(void) rloc(mon, FALSE);
  25. 		    }
  26. 		    if ((gold = g_at(x, y)) != 0) {
  27. 			move_gold(gold, EGD(grd)->vroom);
  28. 			movedgold = TRUE;
  29. 		    }
  30. 		    if ((trap = t_at(x, y)) != 0)
  31. 			deltrap(trap);
  32. 		    if (x == lox)
  33. 			typ = (y == loy) ? TLCORNER :
  34. 			      (y == hiy) ? BLCORNER : VWALL;
  35. 		    else if (x == hix)
  36. 			typ = (y == loy) ? TRCORNER :
  37. 			      (y == hiy) ? BRCORNER : VWALL;
  38. 		    else  /* not left or right side, must be top or bottom */
  39. 			typ = HWALL;
  40. 		    levl[x][y].typ = typ;
  41. 		    levl[x][y].doormask = 0;
  42. 		    /*
  43. 		     * hack: player knows walls are restored because of the
  44. 		     * message, below, so show this on the screen.
  45. 		     */
  46. 		    tmp_viz = viz_array[y][x];
  47. 		    viz_array[y][x] = IN_SIGHT|COULD_SEE;
  48. 		    newsym(x,y);
  49. 		    viz_array[y][x] = tmp_viz;
  50. 		    block_point(x,y);
  51. 		    fixed = TRUE;
  52. 		}
  53. 	    }
  54.  
  55. 	if(movedgold || fixed) {
  56. 	    if(in_fcorridor(grd, grd->mx, grd->my) || cansee(grd->mx, grd->my))
  57. 		pline_The("%s whispers an incantation.", g_monnam(grd));
  58. 	    else You_hear("a distant chant.");
  59. 	    if(movedgold)
  60. 		pline("A mysterious force moves the gold into the vault.");
  61. 	    if(fixed)
  62. 		pline_The("damaged vault's walls are magically restored!");
  63. 	}
  64. }

gd_move[edit]

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

paygd[edit]

  1. /* Routine when dying or quitting with a vault guard around */
  2. void
  3. paygd()
  4. {
  5. 	register struct monst *grd = findgd();
  6. #ifndef GOLDOBJ
  7. 	struct obj *gold;
  8. #else
  9. long umoney = money_cnt(invent);
  10. 	struct obj *coins, *nextcoins;
  11. #endif
  12. 	int gx,gy;
  13. 	char buf[BUFSZ];
  14.  
  15. #ifndef GOLDOBJ
  16. 	if (!u.ugold || !grd) return;
  17. #else
  18. 	if (!umoney || !grd) return;
  19. #endif
  20.  
  21. 	if (u.uinvault) {
  22. 	    Your("%ld %s goes into the Magic Memory Vault.",
  23. #ifndef GOLDOBJ
  24. 		u.ugold,
  25. 		currency(u.ugold));
  26. #else
  27. 		umoney,
  28. 		currency(umoney));
  29. #endif
  30. 	    gx = u.ux;
  31. 	    gy = u.uy;
  32. 	} else {
  33. 	    if(grd->mpeaceful) { /* guard has no "right" to your gold */
  34. 		mongone(grd);
  35. 		return;
  36. 	    }
  37. 	    mnexto(grd);
  38. 	    pline("%s remits your gold to the vault.", Monnam(grd));
  39. 	    gx = rooms[EGD(grd)->vroom].lx + rn2(2);
  40. 	    gy = rooms[EGD(grd)->vroom].ly + rn2(2);
  41. 	    Sprintf(buf,
  42. 		"To Croesus: here's the gold recovered from %s the %s.",
  43. 		plname, mons[u.umonster].mname);
  44. 	    make_grave(gx, gy, buf);
  45. 	}
  46. #ifndef GOLDOBJ
  47. 	place_object(gold = mkgoldobj(u.ugold), gx, gy);
  48. 	stackobj(gold);
  49. #else
  50. for (coins = invent; coins; coins = nextcoins) {
  51. nextcoins = coins->nobj;
  52. 	    if (objects[coins->otyp].oc_class == COIN_CLASS) {
  53. 	        freeinv(coins);
  54. place_object(coins, gx, gy);
  55. 		stackobj(coins);
  56. 	    }
  57. }
  58. #endif
  59. 	mongone(grd);
  60. }

hidden_gold[edit]

  1. long
  2. hidden_gold()
  3. {
  4. 	register long value = 0L;
  5. 	register struct obj *obj;
  6.  
  7. 	for (obj = invent; obj; obj = obj->nobj)
  8. 	    if (Has_contents(obj))
  9. 		value += contained_gold(obj);
  10. 	/* unknown gold stuck inside statues may cause some consternation... */
  11.  
  12. 	return(value);
  13. }

gd_sound[edit]

  1. boolean
  2. gd_sound()  /* prevent "You hear footsteps.." when inappropriate */
  3. {
  4. 	register struct monst *grd = findgd();
  5.  
  6. 	if (vault_occupied(u.urooms)) return(FALSE);
  7. 	else return((boolean)(grd == (struct monst *)0));
  8. }
  9.  
  10. #endif /* OVLB */
  11.  
  12. /*vault.c*/