Source:NetHack 3.4.3/src/mklev.c

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

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

Top of file

  1. /*	SCCS Id: @(#)mklev.c	3.4	2001/11/29	*/
  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. /* #define DEBUG */	/* uncomment to enable code debugging */
  3.  
  4. #ifdef DEBUG
  5. # ifdef WIZARD
  6. #define debugpline	if (wizard) pline
  7. # else
  8. #define debugpline	pline
  9. # endif
  10. #endif
  11.  
  12. /* for UNIX, Rand #def'd to (long)lrand48() or (long)random() */
  13. /* croom->lx etc are schar (width <= int), so % arith ensures that */
  14. /* conversion of result to int is reasonable */
  15.  
  16.  
  17. STATIC_DCL void FDECL(mkfount,(int,struct mkroom *));
  18. #ifdef SINKS
  19. STATIC_DCL void FDECL(mksink,(struct mkroom *));
  20. #endif
  21. STATIC_DCL void FDECL(mkaltar,(struct mkroom *));
  22. STATIC_DCL void FDECL(mkgrave,(struct mkroom *));
  23. STATIC_DCL void NDECL(makevtele);
  24. STATIC_DCL void NDECL(clear_level_structures);
  25. STATIC_DCL void NDECL(makelevel);
  26. STATIC_DCL void NDECL(mineralize);
  27. STATIC_DCL boolean FDECL(bydoor,(XCHAR_P,XCHAR_P));
  28. STATIC_DCL struct mkroom *FDECL(find_branch_room, (coord *));
  29. STATIC_DCL struct mkroom *FDECL(pos_to_room, (XCHAR_P, XCHAR_P));
  30. STATIC_DCL boolean FDECL(place_niche,(struct mkroom *,int*,int*,int*));
  31. STATIC_DCL void FDECL(makeniche,(int));
  32. STATIC_DCL void NDECL(make_niches);
  33.  
  34. STATIC_PTR int FDECL( CFDECLSPEC do_comp,(const genericptr,const genericptr));
  35.  
  36. STATIC_DCL void FDECL(dosdoor,(XCHAR_P,XCHAR_P,struct mkroom *,int));
  37. STATIC_DCL void FDECL(join,(int,int,BOOLEAN_P));
  38. STATIC_DCL void FDECL(do_room_or_subroom, (struct mkroom *,int,int,int,int,
  39. 				       BOOLEAN_P,SCHAR_P,BOOLEAN_P,BOOLEAN_P));
  40. STATIC_DCL void NDECL(makerooms);
  41. STATIC_DCL void FDECL(finddpos,(coord *,XCHAR_P,XCHAR_P,XCHAR_P,XCHAR_P));
  42. STATIC_DCL void FDECL(mkinvpos, (XCHAR_P,XCHAR_P,int));
  43. STATIC_DCL void FDECL(mk_knox_portal, (XCHAR_P,XCHAR_P));
  44.  
  45. #define create_vault()	create_room(-1, -1, 2, 2, -1, -1, VAULT, TRUE)
  46. #define init_vault()	vault_x = -1
  47. #define do_vault()	(vault_x != -1)
  48. static xchar		vault_x, vault_y;
  49. boolean goldseen;
  50. static boolean made_branch;	/* used only during level creation */

do_comp

  1. /* Args must be (const genericptr) so that qsort will always be happy. */
  2.  
  3. STATIC_PTR int CFDECLSPEC
  4. do_comp(vx,vy)
  5. const genericptr vx;
  6. const genericptr vy;
  7. {
  8. #ifdef LINT
  9. /* lint complains about possible pointer alignment problems, but we know
  10. that vx and vy are always properly aligned. Hence, the following
  11. bogus definition:
  12. */
  13. 	return (vx == vy) ? 0 : -1;
  14. #else
  15. 	register const struct mkroom *x, *y;
  16.  
  17. 	x = (const struct mkroom *)vx;
  18. 	y = (const struct mkroom *)vy;
  19. 	if(x->lx < y->lx) return(-1);
  20. 	return(x->lx > y->lx);
  21. #endif /* LINT */
  22. }

finddpos

  1. STATIC_OVL void
  2. finddpos(cc, xl,yl,xh,yh)
  3. coord *cc;
  4. xchar xl,yl,xh,yh;
  5. {
  6. 	register xchar x, y;
  7.  
  8. 	x = (xl == xh) ? xl : (xl + rn2(xh-xl+1));
  9. 	y = (yl == yh) ? yl : (yl + rn2(yh-yl+1));
  10. 	if(okdoor(x, y))
  11. 		goto gotit;
  12.  
  13. 	for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++)
  14. 		if(okdoor(x, y))
  15. 			goto gotit;
  16.  
  17. 	for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++)
  18. 		if(IS_DOOR(levl[x][y].typ) || levl[x][y].typ == SDOOR)
  19. 			goto gotit;
  20. 	/* cannot find something reasonable -- strange */
  21. 	x = xl;
  22. 	y = yh;
  23. gotit:
  24. 	cc->x = x;
  25. 	cc->y = y;
  26. 	return;
  27. }

sort_rooms

  1. void
  2. sort_rooms()
  3. {
  4. #if defined(SYSV) || defined(DGUX)
  5. 	qsort((genericptr_t) rooms, (unsigned)nroom, sizeof(struct mkroom), do_comp);
  6. #else
  7. 	qsort((genericptr_t) rooms, nroom, sizeof(struct mkroom), do_comp);
  8. #endif
  9. }

do_room_or_subroom

  1. STATIC_OVL void
  2. do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, rtype, special, is_room)
  3. register struct mkroom *croom;
  4. int lowx, lowy;
  5. register int hix, hiy;
  6. boolean lit;
  7. schar rtype;
  8. boolean special;
  9. boolean is_room;
  10. {
  11. 	register int x, y;
  12. 	struct rm *lev;
  13.  
  14. 	/* locations might bump level edges in wall-less rooms */
  15. 	/* add/subtract 1 to allow for edge locations */
  16. 	if(!lowx) lowx++;
  17. 	if(!lowy) lowy++;
  18. 	if(hix >= COLNO-1) hix = COLNO-2;
  19. 	if(hiy >= ROWNO-1) hiy = ROWNO-2;
  20.  
  21. 	if(lit) {
  22. 		for(x = lowx-1; x <= hix+1; x++) {
  23. 			lev = &levl[x][max(lowy-1,0)];
  24. 			for(y = lowy-1; y <= hiy+1; y++)
  25. 				lev++->lit = 1;
  26. 		}
  27. 		croom->rlit = 1;
  28. 	} else
  29. 		croom->rlit = 0;
  30.  
  31. 	croom->lx = lowx;
  32. 	croom->hx = hix;
  33. 	croom->ly = lowy;
  34. 	croom->hy = hiy;
  35. 	croom->rtype = rtype;
  36. 	croom->doorct = 0;
  37. 	/* if we're not making a vault, doorindex will still be 0
  38. 	 * if we are, we'll have problems adding niches to the previous room
  39. 	 * unless fdoor is at least doorindex
  40. 	 */
  41. 	croom->fdoor = doorindex;
  42. 	croom->irregular = FALSE;
  43.  
  44. 	croom->nsubrooms = 0;
  45. 	croom->sbrooms[0] = (struct mkroom *) 0;
  46. 	if (!special) {
  47. 	    for(x = lowx-1; x <= hix+1; x++)
  48. 		for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) {
  49. 		    levl[x][y].typ = HWALL;
  50. 		    levl[x][y].horizontal = 1;	/* For open/secret doors. */
  51. 		}
  52. 	    for(x = lowx-1; x <= hix+1; x += (hix-lowx+2))
  53. 		for(y = lowy; y <= hiy; y++) {
  54. 		    levl[x][y].typ = VWALL;
  55. 		    levl[x][y].horizontal = 0;	/* For open/secret doors. */
  56. 		}
  57. 	    for(x = lowx; x <= hix; x++) {
  58. 		lev = &levl[x][lowy];
  59. 		for(y = lowy; y <= hiy; y++)
  60. 		    lev++->typ = ROOM;
  61. 	    }
  62. 	    if (is_room) {
  63. 		levl[lowx-1][lowy-1].typ = TLCORNER;
  64. 		levl[hix+1][lowy-1].typ = TRCORNER;
  65. 		levl[lowx-1][hiy+1].typ = BLCORNER;
  66. 		levl[hix+1][hiy+1].typ = BRCORNER;
  67. 	    } else {	/* a subroom */
  68. 		wallification(lowx-1, lowy-1, hix+1, hiy+1);
  69. 	    }
  70. 	}
  71. }

add_room

  1. void
  2. add_room(lowx, lowy, hix, hiy, lit, rtype, special)
  3. register int lowx, lowy, hix, hiy;
  4. boolean lit;
  5. schar rtype;
  6. boolean special;
  7. {
  8. 	register struct mkroom *croom;
  9.  
  10. 	croom = &rooms[nroom];
  11. 	do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit,
  12. 					    rtype, special, (boolean) TRUE);
  13. 	croom++;
  14. 	croom->hx = -1;
  15. 	nroom++;
  16. }

add_subroom

  1. void
  2. add_subroom(proom, lowx, lowy, hix, hiy, lit, rtype, special)
  3. struct mkroom *proom;
  4. register int lowx, lowy, hix, hiy;
  5. boolean lit;
  6. schar rtype;
  7. boolean special;
  8. {
  9. 	register struct mkroom *croom;
  10.  
  11. 	croom = &subrooms[nsubroom];
  12. 	do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit,
  13. 					    rtype, special, (boolean) FALSE);
  14. 	proom->sbrooms[proom->nsubrooms++] = croom;
  15. 	croom++;
  16. 	croom->hx = -1;
  17. 	nsubroom++;
  18. }

makerooms

  1. STATIC_OVL void
  2. makerooms()
  3. {
  4. 	boolean tried_vault = FALSE;
  5.  
  6. 	/* make rooms until satisfied */
  7. 	/* rnd_rect() will returns 0 if no more rects are available... */
  8. 	while(nroom < MAXNROFROOMS && rnd_rect()) {
  9. 		if(nroom >= (MAXNROFROOMS/6) && rn2(2) && !tried_vault) {
  10. 			tried_vault = TRUE;
  11. 			if (create_vault()) {
  12. 				vault_x = rooms[nroom].lx;
  13. 				vault_y = rooms[nroom].ly;
  14. 				rooms[nroom].hx = -1;
  15. 			}
  16. 		} else
  17. 		    if (!create_room(-1, -1, -1, -1, -1, -1, OROOM, -1))
  18. 			return;
  19. 	}
  20. 	return;
  21. }

join

  1. STATIC_OVL void
  2. join(a,b,nxcor)
  3. register int a, b;
  4. boolean nxcor;
  5. {
  6. 	coord cc,tt, org, dest;
  7. 	register xchar tx, ty, xx, yy;
  8. 	register struct mkroom *croom, *troom;
  9. 	register int dx, dy;
  10.  
  11. 	croom = &rooms[a];
  12. 	troom = &rooms[b];
  13.  
  14. 	/* find positions cc and tt for doors in croom and troom
  15. 	   and direction for a corridor between them */
  16.  
  17. 	if(troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) return;
  18. 	if(troom->lx > croom->hx) {
  19. 		dx = 1;
  20. 		dy = 0;
  21. 		xx = croom->hx+1;
  22. 		tx = troom->lx-1;
  23. 		finddpos(&cc, xx, croom->ly, xx, croom->hy);
  24. 		finddpos(&tt, tx, troom->ly, tx, troom->hy);
  25. 	} else if(troom->hy < croom->ly) {
  26. 		dy = -1;
  27. 		dx = 0;
  28. 		yy = croom->ly-1;
  29. 		finddpos(&cc, croom->lx, yy, croom->hx, yy);
  30. 		ty = troom->hy+1;
  31. 		finddpos(&tt, troom->lx, ty, troom->hx, ty);
  32. 	} else if(troom->hx < croom->lx) {
  33. 		dx = -1;
  34. 		dy = 0;
  35. 		xx = croom->lx-1;
  36. 		tx = troom->hx+1;
  37. 		finddpos(&cc, xx, croom->ly, xx, croom->hy);
  38. 		finddpos(&tt, tx, troom->ly, tx, troom->hy);
  39. 	} else {
  40. 		dy = 1;
  41. 		dx = 0;
  42. 		yy = croom->hy+1;
  43. 		ty = troom->ly-1;
  44. 		finddpos(&cc, croom->lx, yy, croom->hx, yy);
  45. 		finddpos(&tt, troom->lx, ty, troom->hx, ty);
  46. 	}
  47. 	xx = cc.x;
  48. 	yy = cc.y;
  49. 	tx = tt.x - dx;
  50. 	ty = tt.y - dy;
  51. 	if(nxcor && levl[xx+dx][yy+dy].typ)
  52. 		return;
  53. 	if (okdoor(xx,yy) || !nxcor)
  54. 	    dodoor(xx,yy,croom);
  55.  
  56. 	org.x  = xx+dx; org.y  = yy+dy;
  57. 	dest.x = tx; dest.y = ty;
  58.  
  59. 	if (!dig_corridor(&org, &dest, nxcor,
  60. 			level.flags.arboreal ? ROOM : CORR, STONE))
  61. 	    return;
  62.  
  63. 	/* we succeeded in digging the corridor */
  64. 	if (okdoor(tt.x, tt.y) || !nxcor)
  65. 	    dodoor(tt.x, tt.y, troom);
  66.  
  67. 	if(smeq[a] < smeq[b])
  68. 		smeq[b] = smeq[a];
  69. 	else
  70. 		smeq[a] = smeq[b];
  71. }

makecorridors

  1. void
  2. makecorridors()
  3. {
  4. 	int a, b, i;
  5. 	boolean any = TRUE;
  6.  
  7. 	for(a = 0; a < nroom-1; a++) {
  8. 		join(a, a+1, FALSE);
  9. 		if(!rn2(50)) break; /* allow some randomness */
  10. 	}
  11. 	for(a = 0; a < nroom-2; a++)
  12. 	    if(smeq[a] != smeq[a+2])
  13. 		join(a, a+2, FALSE);
  14. 	for(a = 0; any && a < nroom; a++) {
  15. 	    any = FALSE;
  16. 	    for(b = 0; b < nroom; b++)
  17. 		if(smeq[a] != smeq[b]) {
  18. 		    join(a, b, FALSE);
  19. 		    any = TRUE;
  20. 		}
  21. 	}
  22. 	if(nroom > 2)
  23. 	    for(i = rn2(nroom) + 4; i; i--) {
  24. 		a = rn2(nroom);
  25. 		b = rn2(nroom-2);
  26. 		if(b >= a) b += 2;
  27. 		join(a, b, TRUE);
  28. 	    }
  29. }

add_door

  1. void
  2. add_door(x,y,aroom)
  3. register int x, y;
  4. register struct mkroom *aroom;
  5. {
  6. 	register struct mkroom *broom;
  7. 	register int tmp;
  8.  
  9. 	aroom->doorct++;
  10. 	broom = aroom+1;
  11. 	if(broom->hx < 0)
  12. 		tmp = doorindex;
  13. 	else
  14. 		for(tmp = doorindex; tmp > broom->fdoor; tmp--)
  15. 			doors[tmp] = doors[tmp-1];
  16. 	doorindex++;
  17. 	doors[tmp].x = x;
  18. 	doors[tmp].y = y;
  19. 	for( ; broom->hx >= 0; broom++) broom->fdoor++;
  20. }

dosdoor

  1. STATIC_OVL void
  2. dosdoor(x,y,aroom,type)
  3. register xchar x, y;
  4. register struct mkroom *aroom;
  5. register int type;
  6. {
  7. 	boolean shdoor = ((*in_rooms(x, y, SHOPBASE))? TRUE : FALSE);
  8.  
  9. 	if(!IS_WALL(levl[x][y].typ)) /* avoid SDOORs on already made doors */
  10. 		type = DOOR;
  11. 	levl[x][y].typ = type;
  12. 	if(type == DOOR) {
  13. 	    if(!rn2(3)) {      /* is it a locked door, closed, or a doorway? */
  14. 		if(!rn2(5))
  15. 		    levl[x][y].doormask = D_ISOPEN;
  16. 		else if(!rn2(6))
  17. 		    levl[x][y].doormask = D_LOCKED;
  18. 		else
  19. 		    levl[x][y].doormask = D_CLOSED;
  20.  
  21. 		if (levl[x][y].doormask != D_ISOPEN && !shdoor &&
  22. 		    level_difficulty() >= 5 && !rn2(25))
  23. 		    levl[x][y].doormask |= D_TRAPPED;
  24. 	    } else
  25. #ifdef STUPID
  26. 		if (shdoor)
  27. 			levl[x][y].doormask = D_ISOPEN;
  28. 		else
  29. 			levl[x][y].doormask = D_NODOOR;
  30. #else
  31. 		levl[x][y].doormask = (shdoor ? D_ISOPEN : D_NODOOR);
  32. #endif
  33. 	    if(levl[x][y].doormask & D_TRAPPED) {
  34. 		struct monst *mtmp;
  35.  
  36. 		if (level_difficulty() >= 9 && !rn2(5) &&
  37. 		   !((mvitals[PM_SMALL_MIMIC].mvflags & G_GONE) &&
  38. 		     (mvitals[PM_LARGE_MIMIC].mvflags & G_GONE) &&
  39. 		     (mvitals[PM_GIANT_MIMIC].mvflags & G_GONE))) {
  40. 		    /* make a mimic instead */
  41. 		    levl[x][y].doormask = D_NODOOR;
  42. 		    mtmp = makemon(mkclass(S_MIMIC,0), x, y, NO_MM_FLAGS);
  43. 		    if (mtmp)
  44. 			set_mimic_sym(mtmp);
  45. 		}
  46. 	    }
  47. 	    /* newsym(x,y); */
  48. 	} else { /* SDOOR */
  49. 		if(shdoor || !rn2(5))	levl[x][y].doormask = D_LOCKED;
  50. 		else			levl[x][y].doormask = D_CLOSED;
  51.  
  52. 		if(!shdoor && level_difficulty() >= 4 && !rn2(20))
  53. 		    levl[x][y].doormask |= D_TRAPPED;
  54. 	}
  55.  
  56. 	add_door(x,y,aroom);
  57. }

place_niche

  1. STATIC_OVL boolean
  2. place_niche(aroom,dy,xx,yy)
  3. register struct mkroom *aroom;
  4. int *dy, *xx, *yy;
  5. {
  6. 	coord dd;
  7.  
  8. 	if(rn2(2)) {
  9. 	    *dy = 1;
  10. 	    finddpos(&dd, aroom->lx, aroom->hy+1, aroom->hx, aroom->hy+1);
  11. 	} else {
  12. 	    *dy = -1;
  13. 	    finddpos(&dd, aroom->lx, aroom->ly-1, aroom->hx, aroom->ly-1);
  14. 	}
  15. 	*xx = dd.x;
  16. 	*yy = dd.y;
  17. 	return((boolean)((isok(*xx,*yy+*dy) && levl[*xx][*yy+*dy].typ == STONE)
  18. 	    && (isok(*xx,*yy-*dy) && !IS_POOL(levl[*xx][*yy-*dy].typ)
  19. 				  && !IS_FURNITURE(levl[*xx][*yy-*dy].typ))));
  20. }
  21.  
  22. /* there should be one of these per trap, in the same order as trap.h */
  23. static NEARDATA const char *trap_engravings[TRAPNUM] = {
  24. 			(char *)0, (char *)0, (char *)0, (char *)0, (char *)0,
  25. 			(char *)0, (char *)0, (char *)0, (char *)0, (char *)0,
  26. 			(char *)0, (char *)0, (char *)0, (char *)0,
  27. 			/* 14..16: trap door, teleport, level-teleport */
  28. 			"Vlad was here", "ad aerarium", "ad aerarium",
  29. 			(char *)0, (char *)0, (char *)0, (char *)0, (char *)0,
  30. 			(char *)0,
  31. };

makeniche

  1. STATIC_OVL void
  2. makeniche(trap_type)
  3. int trap_type;
  4. {
  5. 	register struct mkroom *aroom;
  6. 	register struct rm *rm;
  7. 	register int vct = 8;
  8. 	int dy, xx, yy;
  9. 	register struct trap *ttmp;
  10.  
  11. 	if(doorindex < DOORMAX)
  12. 	  while(vct--) {
  13. 	    aroom = &rooms[rn2(nroom)];
  14. 	    if(aroom->rtype != OROOM) continue;	/* not an ordinary room */
  15. 	    if(aroom->doorct == 1 && rn2(5)) continue;
  16. 	    if(!place_niche(aroom,&dy,&xx,&yy)) continue;
  17.  
  18. 	    rm = &levl[xx][yy+dy];
  19. 	    if(trap_type || !rn2(4)) {
  20.  
  21. 		rm->typ = SCORR;
  22. 		if(trap_type) {
  23. 		    if((trap_type == HOLE || trap_type == TRAPDOOR)
  24. 			&& !Can_fall_thru(&u.uz))
  25. 			trap_type = ROCKTRAP;
  26. 		    ttmp = maketrap(xx, yy+dy, trap_type);
  27. 		    if (ttmp) {
  28. 			if (trap_type != ROCKTRAP) ttmp->once = 1;
  29. 			if (trap_engravings[trap_type]) {
  30. 			    make_engr_at(xx, yy-dy,
  31. 				     trap_engravings[trap_type], 0L, DUST);
  32. 			    wipe_engr_at(xx, yy-dy, 5); /* age it a little */
  33. 			}
  34. 		    }
  35. 		}
  36. 		dosdoor(xx, yy, aroom, SDOOR);
  37. 	    } else {
  38. 		rm->typ = CORR;
  39. 		if(rn2(7))
  40. 		    dosdoor(xx, yy, aroom, rn2(5) ? SDOOR : DOOR);
  41. 		else {
  42. 		    if (!level.flags.noteleport)
  43. 			(void) mksobj_at(SCR_TELEPORTATION,
  44. 					 xx, yy+dy, TRUE, FALSE);
  45. 		    if (!rn2(3)) (void) mkobj_at(0, xx, yy+dy, TRUE);
  46. 		}
  47. 	    }
  48. 	    return;
  49. 	}
  50. }

make_niches

  1. STATIC_OVL void
  2. make_niches()
  3. {
  4. 	register int ct = rnd((nroom>>1) + 1), dep = depth(&u.uz);
  5.  
  6. 	boolean	ltptr = (!level.flags.noteleport && dep > 15),
  7. 		vamp = (dep > 5 && dep < 25);
  8.  
  9. 	while(ct--) {
  10. 		if (ltptr && !rn2(6)) {
  11. 			ltptr = FALSE;
  12. 			makeniche(LEVEL_TELEP);
  13. 		} else if (vamp && !rn2(6)) {
  14. 			vamp = FALSE;
  15. 			makeniche(TRAPDOOR);
  16. 		} else	makeniche(NO_TRAP);
  17. 	}
  18. }

makevtele

  1. STATIC_OVL void
  2. makevtele()
  3. {
  4. 	makeniche(TELEP_TRAP);
  5. }

clear_level_structures

  1. /* clear out various globals that keep information on the current level.
  2. * some of this is only necessary for some types of levels (maze, normal,
  3. * special) but it's easier to put it all in one place than make sure
  4. * each type initializes what it needs to separately.
  5. */
  6. STATIC_OVL void
  7. clear_level_structures()
  8. {
  9. 	static struct rm zerorm = { cmap_to_glyph(S_stone),
  10. 						0, 0, 0, 0, 0, 0, 0, 0 };
  11. 	register int x,y;
  12. 	register struct rm *lev;
  13.  
  14. 	for(x=0; x<COLNO; x++) {
  15. 	    lev = &levl[x][0];
  16. 	    for(y=0; y<ROWNO; y++) {
  17. 		*lev++ = zerorm;
  18. #ifdef MICROPORT_BUG
  19. 		level.objects[x][y] = (struct obj *)0;
  20. 		level.monsters[x][y] = (struct monst *)0;
  21. #endif
  22. 	    }
  23. 	}
  24. #ifndef MICROPORT_BUG
  25. 	(void) memset((genericptr_t)level.objects, 0, sizeof(level.objects));
  26. 	(void) memset((genericptr_t)level.monsters, 0, sizeof(level.monsters));
  27. #endif
  28. 	level.objlist = (struct obj *)0;
  29. 	level.buriedobjlist = (struct obj *)0;
  30. 	level.monlist = (struct monst *)0;
  31. 	level.damagelist = (struct damage *)0;
  32.  
  33. 	level.flags.nfountains = 0;
  34. 	level.flags.nsinks = 0;
  35. 	level.flags.has_shop = 0;
  36. 	level.flags.has_vault = 0;
  37. 	level.flags.has_zoo = 0;
  38. 	level.flags.has_court = 0;
  39. 	level.flags.has_morgue = level.flags.graveyard = 0;
  40. 	level.flags.has_beehive = 0;
  41. 	level.flags.has_barracks = 0;
  42. 	level.flags.has_temple = 0;
  43. 	level.flags.has_swamp = 0;
  44. 	level.flags.noteleport = 0;
  45. 	level.flags.hardfloor = 0;
  46. 	level.flags.nommap = 0;
  47. 	level.flags.hero_memory = 1;
  48. 	level.flags.shortsighted = 0;
  49. 	level.flags.arboreal = 0;
  50. 	level.flags.is_maze_lev = 0;
  51. 	level.flags.is_cavernous_lev = 0;
  52.  
  53. 	nroom = 0;
  54. 	rooms[0].hx = -1;
  55. 	nsubroom = 0;
  56. 	subrooms[0].hx = -1;
  57. 	doorindex = 0;
  58. 	init_rect();
  59. 	init_vault();
  60. 	xdnstair = ydnstair = xupstair = yupstair = 0;
  61. 	sstairs.sx = sstairs.sy = 0;
  62. 	xdnladder = ydnladder = xupladder = yupladder = 0;
  63. 	made_branch = FALSE;
  64. 	clear_regions();
  65. }

makelevel

  1. STATIC_OVL void
  2. makelevel()
  3. {
  4. 	register struct mkroom *croom, *troom;
  5. 	register int tryct;
  6. 	register int x, y;
  7. 	struct monst *tmonst;	/* always put a web with a spider */
  8. 	branch *branchp;
  9. 	int room_threshold;
  10.  
  11. 	if(wiz1_level.dlevel == 0) init_dungeons();
  12. 	oinit();	/* assign level dependent obj probabilities */
  13. 	clear_level_structures();
  14.  
  15. 	{
  16. 	    register s_level *slev = Is_special(&u.uz);
  17.  
  18. 	    /* check for special levels */
  19. #ifdef REINCARNATION
  20. 	    if (slev && !Is_rogue_level(&u.uz))
  21. #else
  22. 	    if (slev)
  23. #endif
  24. 	    {
  25. 		    makemaz(slev->proto);
  26. 		    return;
  27. 	    } else if (dungeons[u.uz.dnum].proto[0]) {
  28. 		    makemaz("");
  29. 		    return;
  30. 	    } else if (In_mines(&u.uz)) {
  31. 		    makemaz("minefill");
  32. 		    return;
  33. 	    } else if (In_quest(&u.uz)) {
  34. 		    char	fillname[9];
  35. 		    s_level	*loc_lev;
  36.  
  37. 		    Sprintf(fillname, "%s-loca", urole.filecode);
  38. 		    loc_lev = find_level(fillname);
  39.  
  40. 		    Sprintf(fillname, "%s-fil", urole.filecode);
  41. 		    Strcat(fillname,
  42. 			   (u.uz.dlevel < loc_lev->dlevel.dlevel) ? "a" : "b");
  43. 		    makemaz(fillname);
  44. 		    return;
  45. 	    } else if(In_hell(&u.uz) ||
  46. 		  (rn2(5) && u.uz.dnum == medusa_level.dnum
  47. 			  && depth(&u.uz) > depth(&medusa_level))) {
  48. 		    makemaz("");
  49. 		    return;
  50. 	    }
  51. 	}
  52.  
  53. 	/* otherwise, fall through - it's a "regular" level. */
  54.  
  55. #ifdef REINCARNATION
  56. 	if (Is_rogue_level(&u.uz)) {
  57. 		makeroguerooms();
  58. 		makerogueghost();
  59. 	} else
  60. #endif
  61. 		makerooms();
  62. 	sort_rooms();
  63.  
  64. 	/* construct stairs (up and down in different rooms if possible) */
  65. 	croom = &rooms[rn2(nroom)];
  66. 	if (!Is_botlevel(&u.uz))
  67. 	     mkstairs(somex(croom), somey(croom), 0, croom);	/* down */
  68. 	if (nroom > 1) {
  69. 	    troom = croom;
  70. 	    croom = &rooms[rn2(nroom-1)];
  71. 	    if (croom == troom) croom++;
  72. 	}
  73.  
  74. 	if (u.uz.dlevel != 1) {
  75. 	    xchar sx, sy;
  76. 	    do {
  77. 		sx = somex(croom);
  78. 		sy = somey(croom);
  79. 	    } while(occupied(sx, sy));
  80. 	    mkstairs(sx, sy, 1, croom);	/* up */
  81. 	}
  82.  
  83. 	branchp = Is_branchlev(&u.uz);	/* possible dungeon branch */
  84. 	room_threshold = branchp ? 4 : 3; /* minimum number of rooms needed
  85. 					     to allow a random special room */
  86. #ifdef REINCARNATION
  87. 	if (Is_rogue_level(&u.uz)) goto skip0;
  88. #endif
  89. 	makecorridors();
  90. 	make_niches();
  91.  
  92. 	/* make a secret treasure vault, not connected to the rest */
  93. 	if(do_vault()) {
  94. 		xchar w,h;
  95. #ifdef DEBUG
  96. 		debugpline("trying to make a vault...");
  97. #endif
  98. 		w = 1;
  99. 		h = 1;
  100. 		if (check_room(&vault_x, &w, &vault_y, &h, TRUE)) {
  101. 		    fill_vault:
  102. 			add_room(vault_x, vault_y, vault_x+w,
  103. 				 vault_y+h, TRUE, VAULT, FALSE);
  104. 			level.flags.has_vault = 1;
  105. 			++room_threshold;
  106. 			fill_room(&rooms[nroom - 1], FALSE);
  107. 			mk_knox_portal(vault_x+w, vault_y+h);
  108. 			if(!level.flags.noteleport && !rn2(3)) makevtele();
  109. 		} else if(rnd_rect() && create_vault()) {
  110. 			vault_x = rooms[nroom].lx;
  111. 			vault_y = rooms[nroom].ly;
  112. 			if (check_room(&vault_x, &w, &vault_y, &h, TRUE))
  113. 				goto fill_vault;
  114. 			else
  115. 				rooms[nroom].hx = -1;
  116. 		}
  117. 	}
  118.  
  119. {
  120. 	register int u_depth = depth(&u.uz);
  121.  
  122. #ifdef WIZARD
  123. 	if(wizard && nh_getenv("SHOPTYPE")) mkroom(SHOPBASE); else
  124. #endif
  125. 	if (u_depth > 1 &&
  126. 	    u_depth < depth(&medusa_level) &&
  127. 	    nroom >= room_threshold &&
  128. 	    rn2(u_depth) < 3) mkroom(SHOPBASE);
  129. 	else if (u_depth > 4 && !rn2(6)) mkroom(COURT);
  130. 	else if (u_depth > 5 && !rn2(8) &&
  131. 	   !(mvitals[PM_LEPRECHAUN].mvflags & G_GONE)) mkroom(LEPREHALL);
  132. 	else if (u_depth > 6 && !rn2(7)) mkroom(ZOO);
  133. 	else if (u_depth > 8 && !rn2(5)) mkroom(TEMPLE);
  134. 	else if (u_depth > 9 && !rn2(5) &&
  135. 	   !(mvitals[PM_KILLER_BEE].mvflags & G_GONE)) mkroom(BEEHIVE);
  136. 	else if (u_depth > 11 && !rn2(6)) mkroom(MORGUE);
  137. 	else if (u_depth > 12 && !rn2(8)) mkroom(ANTHOLE);
  138. 	else if (u_depth > 14 && !rn2(4) &&
  139. 	   !(mvitals[PM_SOLDIER].mvflags & G_GONE)) mkroom(BARRACKS);
  140. 	else if (u_depth > 15 && !rn2(6)) mkroom(SWAMP);
  141. 	else if (u_depth > 16 && !rn2(8) &&
  142. 	   !(mvitals[PM_COCKATRICE].mvflags & G_GONE)) mkroom(COCKNEST);
  143. }
  144.  
  145. #ifdef REINCARNATION
  146. skip0:
  147. #endif
  148. 	/* Place multi-dungeon branch. */
  149. 	place_branch(branchp, 0, 0);
  150.  
  151. 	/* for each room: put things inside */
  152. 	for(croom = rooms; croom->hx > 0; croom++) {
  153. 		if(croom->rtype != OROOM) continue;
  154.  
  155. 		/* put a sleeping monster inside */
  156. 		/* Note: monster may be on the stairs. This cannot be
  157. 		   avoided: maybe the player fell through a trap door
  158. 		   while a monster was on the stairs. Conclusion:
  159. 		   we have to check for monsters on the stairs anyway. */
  160.  
  161. 		if(u.uhave.amulet || !rn2(3)) {
  162. 		    x = somex(croom); y = somey(croom);
  163. 		    tmonst = makemon((struct permonst *) 0, x,y,NO_MM_FLAGS);
  164. 		    if (tmonst && tmonst->data == &mons[PM_GIANT_SPIDER] &&
  165. 			    !occupied(x, y))
  166. 			(void) maketrap(x, y, WEB);
  167. 		}
  168. 		/* put traps and mimics inside */
  169. 		goldseen = FALSE;
  170. 		x = 8 - (level_difficulty()/6);
  171. 		if (x <= 1) x = 2;
  172. 		while (!rn2(x))
  173. 		    mktrap(0,0,croom,(coord*)0);
  174. 		if (!goldseen && !rn2(3))
  175. 		    (void) mkgold(0L, somex(croom), somey(croom));
  176. #ifdef REINCARNATION
  177. 		if(Is_rogue_level(&u.uz)) goto skip_nonrogue;
  178. #endif
  179. 		if(!rn2(10)) mkfount(0,croom);
  180. #ifdef SINKS
  181. 		if(!rn2(60)) mksink(croom);
  182. #endif
  183. 		if(!rn2(60)) mkaltar(croom);
  184. 		x = 80 - (depth(&u.uz) * 2);
  185. 		if (x < 2) x = 2;
  186. 		if(!rn2(x)) mkgrave(croom);
  187.  
  188. 		/* put statues inside */
  189. 		if(!rn2(20))
  190. 		    (void) mkcorpstat(STATUE, (struct monst *)0,
  191. 				      (struct permonst *)0,
  192. 				      somex(croom), somey(croom), TRUE);
  193. 		/* put box/chest inside;
  194. 		 *  40% chance for at least 1 box, regardless of number
  195. 		 *  of rooms; about 5 - 7.5% for 2 boxes, least likely
  196. 		 *  when few rooms; chance for 3 or more is neglible.
  197. 		 */
  198. 		if(!rn2(nroom * 5 / 2))
  199. 		    (void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST,
  200. 				     somex(croom), somey(croom), TRUE, FALSE);
  201.  
  202. 		/* maybe make some graffiti */
  203. 		if(!rn2(27 + 3 * abs(depth(&u.uz)))) {
  204. 		    char buf[BUFSZ];
  205. 		    const char *mesg = random_engraving(buf);
  206. 		    if (mesg) {
  207. 			do {
  208. 			    x = somex(croom);  y = somey(croom);
  209. 			} while(levl[x][y].typ != ROOM && !rn2(40));
  210. 			if (!(IS_POOL(levl[x][y].typ) ||
  211. 			      IS_FURNITURE(levl[x][y].typ)))
  212. 			    make_engr_at(x, y, mesg, 0L, MARK);
  213. 		    }
  214. 		}
  215.  
  216. #ifdef REINCARNATION
  217. 	skip_nonrogue:
  218. #endif
  219. 		if(!rn2(3)) {
  220. 		    (void) mkobj_at(0, somex(croom), somey(croom), TRUE);
  221. 		    tryct = 0;
  222. 		    while(!rn2(5)) {
  223. 			if(++tryct > 100) {
  224. 			    impossible("tryct overflow4");
  225. 			    break;
  226. 			}
  227. 			(void) mkobj_at(0, somex(croom), somey(croom), TRUE);
  228. 		    }
  229. 		}
  230. 	}
  231. }

Line 821 starts the script that generates items on the dungeon floor. The probability of making an item is 1 in 3, with a 1 in 5 chance of making each additional item.

mineralize

  1. /*
  2. *	Place deposits of minerals (gold and misc gems) in the stone
  3. *	surrounding the rooms on the map.
  4. *	Also place kelp in water.
  5. */
  6. STATIC_OVL void
  7. mineralize()
  8. {
  9. 	s_level *sp;
  10. 	struct obj *otmp;
  11. 	int goldprob, gemprob, x, y, cnt;
  12.  
  13.  
  14. 	/* Place kelp, except on the plane of water */
  15. 	if (In_endgame(&u.uz)) return;
  16. 	for (x = 2; x < (COLNO - 2); x++)
  17. 	    for (y = 1; y < (ROWNO - 1); y++)
  18. 		if ((levl[x][y].typ == POOL && !rn2(10)) ||
  19. 			(levl[x][y].typ == MOAT && !rn2(30)))
  20. 		    (void) mksobj_at(KELP_FROND, x, y, TRUE, FALSE);
  21.  
  22. 	/* determine if it is even allowed;
  23. 	   almost all special levels are excluded */
  24. 	if (In_hell(&u.uz) || In_V_tower(&u.uz) ||
  25. #ifdef REINCARNATION
  26. 		Is_rogue_level(&u.uz) ||
  27. #endif
  28. 		level.flags.arboreal ||
  29. 		((sp = Is_special(&u.uz)) != 0 && !Is_oracle_level(&u.uz)
  30. 					&& (!In_mines(&u.uz) || sp->flags.town)
  31. 	    )) return;
  32.  
  33. 	/* basic level-related probabilities */
  34. 	goldprob = 20 + depth(&u.uz) / 3;
  35. 	gemprob = goldprob / 4;
  36.  
  37. 	/* mines have ***MORE*** goodies - otherwise why mine? */
  38. 	if (In_mines(&u.uz)) {
  39. 	    goldprob *= 2;
  40. 	    gemprob *= 3;
  41. 	} else if (In_quest(&u.uz)) {
  42. 	    goldprob /= 4;
  43. 	    gemprob /= 6;
  44. 	}
  45.  
  46. 	/*
  47. 	 * Seed rock areas with gold and/or gems.
  48. 	 * We use fairly low level object handling to avoid unnecessary
  49. 	 * overhead from placing things in the floor chain prior to burial.
  50. 	 */
  51. 	for (x = 2; x < (COLNO - 2); x++)
  52. 	  for (y = 1; y < (ROWNO - 1); y++)
  53. 	    if (levl[x][y+1].typ != STONE) {	 /* <x,y> spot not eligible */
  54. 		y += 2;		/* next two spots aren't eligible either */
  55. 	    } else if (levl[x][y].typ != STONE) { /* this spot not eligible */
  56. 		y += 1;		/* next spot isn't eligible either */
  57. 	    } else if (!(levl[x][y].wall_info & W_NONDIGGABLE) &&
  58. 		  levl[x][y-1].typ   == STONE &&
  59. 		  levl[x+1][y-1].typ == STONE && levl[x-1][y-1].typ == STONE &&
  60. 		  levl[x+1][y].typ   == STONE && levl[x-1][y].typ   == STONE &&
  61. 		  levl[x+1][y+1].typ == STONE && levl[x-1][y+1].typ == STONE) {
  62. 		if (rn2(1000) < goldprob) {
  63. 		    if ((otmp = mksobj(GOLD_PIECE, FALSE, FALSE)) != 0) {
  64. 			otmp->ox = x,  otmp->oy = y;
  65. 			otmp->quan = 1L + rnd(goldprob * 3);
  66. 			otmp->owt = weight(otmp);
  67. 			if (!rn2(3)) add_to_buried(otmp);
  68. 			else place_object(otmp, x, y);
  69. 		    }
  70. 		}
  71. 		if (rn2(1000) < gemprob) {
  72. 		    for (cnt = rnd(2 + dunlev(&u.uz) / 3); cnt > 0; cnt--)
  73. 			if ((otmp = mkobj(GEM_CLASS, FALSE)) != 0) {
  74. 			    if (otmp->otyp == ROCK) {
  75. 				dealloc_obj(otmp);	/* discard it */
  76. 			    } else {
  77. 				otmp->ox = x,  otmp->oy = y;
  78. 				if (!rn2(3)) add_to_buried(otmp);
  79. 				else place_object(otmp, x, y);
  80. 			    }
  81. 		    }
  82. 		}
  83. 	    }
  84. }

mklev

  1. void
  2. mklev()
  3. {
  4. 	struct mkroom *croom;
  5.  
  6. 	if(getbones()) return;
  7. 	in_mklev = TRUE;
  8. 	makelevel();
  9. 	bound_digging();
  10. 	mineralize();
  11. 	in_mklev = FALSE;
  12. 	/* has_morgue gets cleared once morgue is entered; graveyard stays
  13. 	   set (graveyard might already be set even when has_morgue is clear
  14. 	   [see fixup_special()], so don't update it unconditionally) */
  15. 	if (level.flags.has_morgue)
  16. 	    level.flags.graveyard = 1;
  17. 	if (!level.flags.is_maze_lev) {
  18. 	    for (croom = &rooms[0]; croom != &rooms[nroom]; croom++)
  19. #ifdef SPECIALIZATION
  20. 		topologize(croom, FALSE);
  21. #else
  22. 		topologize(croom);
  23. #endif
  24. 	}
  25. 	set_wall_state();
  26. }

topologize

  1. void
  2. #ifdef SPECIALIZATION
  3. topologize(croom, do_ordinary)
  4. register struct mkroom *croom;
  5. boolean do_ordinary;
  6. #else
  7. topologize(croom)
  8. register struct mkroom *croom;
  9. #endif
  10. {
  11. 	register int x, y, roomno = (croom - rooms) + ROOMOFFSET;
  12. 	register int lowx = croom->lx, lowy = croom->ly;
  13. 	register int hix = croom->hx, hiy = croom->hy;
  14. #ifdef SPECIALIZATION
  15. 	register schar rtype = croom->rtype;
  16. #endif
  17. 	register int subindex, nsubrooms = croom->nsubrooms;
  18.  
  19. 	/* skip the room if already done; i.e. a shop handled out of order */
  20. 	/* also skip if this is non-rectangular (it _must_ be done already) */
  21. 	if ((int) levl[lowx][lowy].roomno == roomno || croom->irregular)
  22. 	    return;
  23. #ifdef SPECIALIZATION
  24. # ifdef REINCARNATION
  25. 	if (Is_rogue_level(&u.uz))
  26. 	    do_ordinary = TRUE;		/* vision routine helper */
  27. # endif
  28. 	if ((rtype != OROOM) || do_ordinary)
  29. #endif
  30. 	{
  31. 	    /* do innards first */
  32. 	    for(x = lowx; x <= hix; x++)
  33. 		for(y = lowy; y <= hiy; y++)
  34. #ifdef SPECIALIZATION
  35. 		    if (rtype == OROOM)
  36. 			levl[x][y].roomno = NO_ROOM;
  37. 		    else
  38. #endif
  39. 			levl[x][y].roomno = roomno;
  40. 	    /* top and bottom edges */
  41. 	    for(x = lowx-1; x <= hix+1; x++)
  42. 		for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) {
  43. 		    levl[x][y].edge = 1;
  44. 		    if (levl[x][y].roomno)
  45. 			levl[x][y].roomno = SHARED;
  46. 		    else
  47. 			levl[x][y].roomno = roomno;
  48. 		}
  49. 	    /* sides */
  50. 	    for(x = lowx-1; x <= hix+1; x += (hix-lowx+2))
  51. 		for(y = lowy; y <= hiy; y++) {
  52. 		    levl[x][y].edge = 1;
  53. 		    if (levl[x][y].roomno)
  54. 			levl[x][y].roomno = SHARED;
  55. 		    else
  56. 			levl[x][y].roomno = roomno;
  57. 		}
  58. 	}
  59. 	/* subrooms */
  60. 	for (subindex = 0; subindex < nsubrooms; subindex++)
  61. #ifdef SPECIALIZATION
  62. 		topologize(croom->sbrooms[subindex], (rtype != OROOM));
  63. #else
  64. 		topologize(croom->sbrooms[subindex]);
  65. #endif
  66. }

find_branch_room

  1. /* Find an unused room for a branch location. */
  2. STATIC_OVL struct mkroom *
  3. find_branch_room(mp)
  4. coord *mp;
  5. {
  6. struct mkroom *croom = 0;
  7.  
  8. if (nroom == 0) {
  9. 	mazexy(mp);		/* already verifies location */
  10. } else {
  11. 	/* not perfect - there may be only one stairway */
  12. 	if(nroom > 2) {
  13. 	    int tryct = 0;
  14.  
  15. 	    do
  16. 		croom = &rooms[rn2(nroom)];
  17. 	    while((croom == dnstairs_room || croom == upstairs_room ||
  18. 		  croom->rtype != OROOM) && (++tryct < 100));
  19. 	} else
  20. 	    croom = &rooms[rn2(nroom)];
  21.  
  22. 	do {
  23. 	    if (!somexy(croom, mp))
  24. 		impossible("Can't place branch!");
  25. 	} while(occupied(mp->x, mp->y) ||
  26. 	    (levl[mp->x][mp->y].typ != CORR && levl[mp->x][mp->y].typ != ROOM));
  27. }
  28. return croom;
  29. }

pos_to_room

  1. /* Find the room for (x,y).  Return null if not in a room. */
  2. STATIC_OVL struct mkroom *
  3. pos_to_room(x, y)
  4. xchar x, y;
  5. {
  6. int i;
  7. struct mkroom *curr;
  8.  
  9. for (curr = rooms, i = 0; i < nroom; curr++, i++)
  10. 	if (inside_room(curr, x, y)) return curr;;
  11. return (struct mkroom *) 0;
  12. }

place_branch

  1. /* If given a branch, randomly place a special stair or portal. */
  2. void
  3. place_branch(br, x, y)
  4. branch *br;	/* branch to place */
  5. xchar x, y;	/* location */
  6. {
  7. 	coord	      m;
  8. 	d_level	      *dest;
  9. 	boolean	      make_stairs;
  10. 	struct mkroom *br_room;
  11.  
  12. 	/*
  13. 	 * Return immediately if there is no branch to make or we have
  14. 	 * already made one.  This routine can be called twice when
  15. 	 * a special level is loaded that specifies an SSTAIR location
  16. 	 * as a favored spot for a branch.
  17. 	 */
  18. 	if (!br || made_branch) return;
  19.  
  20. 	if (!x) {	/* find random coordinates for branch */
  21. 	    br_room = find_branch_room(&m);
  22. 	    x = m.x;
  23. 	    y = m.y;
  24. 	} else {
  25. 	    br_room = pos_to_room(x, y);
  26. 	}
  27.  
  28. 	if (on_level(&br->end1, &u.uz)) {
  29. 	    /* we're on end1 */
  30. 	    make_stairs = br->type != BR_NO_END1;
  31. 	    dest = &br->end2;
  32. 	} else {
  33. 	    /* we're on end2 */
  34. 	    make_stairs = br->type != BR_NO_END2;
  35. 	    dest = &br->end1;
  36. 	}
  37.  
  38. 	if (br->type == BR_PORTAL) {
  39. 	    mkportal(x, y, dest->dnum, dest->dlevel);
  40. 	} else if (make_stairs) {
  41. 	    sstairs.sx = x;
  42. 	    sstairs.sy = y;
  43. 	    sstairs.up = (char) on_level(&br->end1, &u.uz) ?
  44. 					    br->end1_up : !br->end1_up;
  45. 	    assign_level(&sstairs.tolev, dest);
  46. 	    sstairs_room = br_room;
  47.  
  48. 	    levl[x][y].ladder = sstairs.up ? LA_UP : LA_DOWN;
  49. 	    levl[x][y].typ = STAIRS;
  50. 	}
  51. 	/*
  52. 	 * Set made_branch to TRUE even if we didn't make a stairwell (i.e.
  53. 	 * make_stairs is false) since there is currently only one branch
  54. 	 * per level, if we failed once, we're going to fail again on the
  55. 	 * next call.
  56. 	 */
  57. 	made_branch = TRUE;
  58. }

bydoor

  1. STATIC_OVL boolean
  2. bydoor(x, y)
  3. register xchar x, y;
  4. {
  5. 	register int typ;
  6.  
  7. 	if (isok(x+1, y)) {
  8. 		typ = levl[x+1][y].typ;
  9. 		if (IS_DOOR(typ) || typ == SDOOR) return TRUE;
  10. 	}
  11. 	if (isok(x-1, y)) {
  12. 		typ = levl[x-1][y].typ;
  13. 		if (IS_DOOR(typ) || typ == SDOOR) return TRUE;
  14. 	}
  15. 	if (isok(x, y+1)) {
  16. 		typ = levl[x][y+1].typ;
  17. 		if (IS_DOOR(typ) || typ == SDOOR) return TRUE;
  18. 	}
  19. 	if (isok(x, y-1)) {
  20. 		typ = levl[x][y-1].typ;
  21. 		if (IS_DOOR(typ) || typ == SDOOR) return TRUE;
  22. 	}
  23. 	return FALSE;
  24. }

okdoor

  1. /* see whether it is allowable to create a door at [x,y] */
  2. int
  3. okdoor(x,y)
  4. register xchar x, y;
  5. {
  6. 	register boolean near_door = bydoor(x, y);
  7.  
  8. 	return((levl[x][y].typ == HWALL || levl[x][y].typ == VWALL) &&
  9. 			doorindex < DOORMAX && !near_door);
  10. }

dodoor

  1. void
  2. dodoor(x,y,aroom)
  3. register int x, y;
  4. register struct mkroom *aroom;
  5. {
  6. 	if(doorindex >= DOORMAX) {
  7. 		impossible("DOORMAX exceeded?");
  8. 		return;
  9. 	}
  10.  
  11. 	dosdoor(x,y,aroom,rn2(8) ? DOOR : SDOOR);
  12. }

occupied

  1. boolean
  2. occupied(x, y)
  3. register xchar x, y;
  4. {
  5. 	return((boolean)(t_at(x, y)
  6. 		|| IS_FURNITURE(levl[x][y].typ)
  7. 		|| is_lava(x,y)
  8. 		|| is_pool(x,y)
  9. 		|| invocation_pos(x,y)
  10. 		));
  11. }

mktrap

  1. /* make a trap somewhere (in croom if mazeflag = 0 && !tm) */
  2. /* if tm != null, make trap at that location */
  3. void
  4. mktrap(num, mazeflag, croom, tm)
  5. register int num, mazeflag;
  6. register struct mkroom *croom;
  7. coord *tm;
  8. {
  9. 	register int kind;
  10. 	coord m;
  11.  
  12. 	/* no traps in pools */
  13. 	if (tm && is_pool(tm->x,tm->y)) return;
  14.  
  15. 	if (num > 0 && num < TRAPNUM) {
  16. 	    kind = num;
  17. #ifdef REINCARNATION
  18. 	} else if (Is_rogue_level(&u.uz)) {
  19. 	    switch (rn2(7)) {
  20. 		default: kind = BEAR_TRAP; break; /* 0 */
  21. 		case 1: kind = ARROW_TRAP; break;
  22. 		case 2: kind = DART_TRAP; break;
  23. 		case 3: kind = TRAPDOOR; break;
  24. 		case 4: kind = PIT; break;
  25. 		case 5: kind = SLP_GAS_TRAP; break;
  26. 		case 6: kind = RUST_TRAP; break;
  27. 	    }
  28. #endif
  29. 	} else if (Inhell && !rn2(5)) {
  30. 	    /* bias the frequency of fire traps in Gehennom */
  31. 	    kind = FIRE_TRAP;
  32. 	} else {
  33. 	    unsigned lvl = level_difficulty();
  34.  
  35. 	    do {
  36. 		kind = rnd(TRAPNUM-1);
  37. 		/* reject "too hard" traps */
  38. 		switch (kind) {
  39. 		    case MAGIC_PORTAL:
  40. 			kind = NO_TRAP; break;
  41. 		    case ROLLING_BOULDER_TRAP:
  42. 		    case SLP_GAS_TRAP:
  43. 			if (lvl < 2) kind = NO_TRAP; break;
  44. 		    case LEVEL_TELEP:
  45. 			if (lvl < 5 || level.flags.noteleport)
  46. 			    kind = NO_TRAP; break;
  47. 		    case SPIKED_PIT:
  48. 			if (lvl < 5) kind = NO_TRAP; break;
  49. 		    case LANDMINE:
  50. 			if (lvl < 6) kind = NO_TRAP; break;
  51. 		    case WEB:
  52. 			if (lvl < 7) kind = NO_TRAP; break;
  53. 		    case STATUE_TRAP:
  54. 		    case POLY_TRAP:
  55. 			if (lvl < 8) kind = NO_TRAP; break;
  56. 		    case FIRE_TRAP:
  57. 			if (!Inhell) kind = NO_TRAP; break;
  58. 		    case TELEP_TRAP:
  59. 			if (level.flags.noteleport) kind = NO_TRAP; break;
  60. 		    case HOLE:
  61. 			/* make these much less often than other traps */
  62. 			if (rn2(7)) kind = NO_TRAP; break;
  63. 		}
  64. 	    } while (kind == NO_TRAP);
  65. 	}
  66.  
  67. 	if ((kind == TRAPDOOR || kind == HOLE) && !Can_fall_thru(&u.uz))
  68. 		kind = ROCKTRAP;
  69.  
  70. 	if (tm)
  71. 	    m = *tm;
  72. 	else {
  73. 	    register int tryct = 0;
  74. 	    boolean avoid_boulder = (kind == PIT || kind == SPIKED_PIT ||
  75. 				     kind == TRAPDOOR || kind == HOLE);
  76.  
  77. 	    do {
  78. 		if (++tryct > 200)
  79. 		    return;
  80. 		if (mazeflag)
  81. 		    mazexy(&m);
  82. 		else if (!somexy(croom,&m))
  83. 		    return;
  84. 	    } while (occupied(m.x, m.y) ||
  85. 			(avoid_boulder && sobj_at(BOULDER, m.x, m.y)));
  86. 	}
  87.  
  88. 	(void) maketrap(m.x, m.y, kind);
  89. 	if (kind == WEB) (void) makemon(&mons[PM_GIANT_SPIDER],
  90. 						m.x, m.y, NO_MM_FLAGS);
  91. }

mkstairs

  1. void
  2. mkstairs(x, y, up, croom)
  3. xchar x, y;
  4. char  up;
  5. struct mkroom *croom;
  6. {
  7. 	if (!x) {
  8. 	    impossible("mkstairs:  bogus stair attempt at <%d,%d>", x, y);
  9. 	    return;
  10. 	}
  11.  
  12. 	/*
  13. 	 * We can't make a regular stair off an end of the dungeon.  This
  14. 	 * attempt can happen when a special level is placed at an end and
  15. 	 * has an up or down stair specified in its description file.
  16. 	 */
  17. 	if ((dunlev(&u.uz) == 1 && up) ||
  18. 			(dunlev(&u.uz) == dunlevs_in_dungeon(&u.uz) && !up))
  19. 	    return;
  20.  
  21. 	if(up) {
  22. 		xupstair = x;
  23. 		yupstair = y;
  24. 		upstairs_room = croom;
  25. 	} else {
  26. 		xdnstair = x;
  27. 		ydnstair = y;
  28. 		dnstairs_room = croom;
  29. 	}
  30.  
  31. 	levl[x][y].typ = STAIRS;
  32. 	levl[x][y].ladder = up ? LA_UP : LA_DOWN;
  33. }

mkfount

  1. STATIC_OVL
  2. void
  3. mkfount(mazeflag,croom)
  4. register int mazeflag;
  5. register struct mkroom *croom;
  6. {
  7. 	coord m;
  8. 	register int tryct = 0;
  9.  
  10. 	do {
  11. 	    if(++tryct > 200) return;
  12. 	    if(mazeflag)
  13. 		mazexy(&m);
  14. 	    else
  15. 		if (!somexy(croom, &m))
  16. 		    return;
  17. 	} while(occupied(m.x, m.y) || bydoor(m.x, m.y));
  18.  
  19. 	/* Put a fountain at m.x, m.y */
  20. 	levl[m.x][m.y].typ = FOUNTAIN;
  21. 	/* Is it a "blessed" fountain? (affects drinking from fountain) */
  22. 	if(!rn2(7)) levl[m.x][m.y].blessedftn = 1;
  23.  
  24. 	level.flags.nfountains++;
  25. }
  26.  
  27. #ifdef SINKS

The blessedftn flag marks magic fountains, those that act like a potion of gain ability. This function is called only for random fountains in ordinary rooms in the main dungeons. So fountains on levels with a fixed layout are never magical, and the quest doesn't have any at all.

mksink

  1. STATIC_OVL void
  2. mksink(croom)
  3. register struct mkroom *croom;
  4. {
  5. 	coord m;
  6. 	register int tryct = 0;
  7.  
  8. 	do {
  9. 	    if(++tryct > 200) return;
  10. 	    if (!somexy(croom, &m))
  11. 		return;
  12. 	} while(occupied(m.x, m.y) || bydoor(m.x, m.y));
  13.  
  14. 	/* Put a sink at m.x, m.y */
  15. 	levl[m.x][m.y].typ = SINK;
  16.  
  17. 	level.flags.nsinks++;
  18. }
  19. #endif /* SINKS */

mkaltar

  1. STATIC_OVL void
  2. mkaltar(croom)
  3. register struct mkroom *croom;
  4. {
  5. 	coord m;
  6. 	register int tryct = 0;
  7. 	aligntyp al;
  8.  
  9. 	if (croom->rtype != OROOM) return;
  10.  
  11. 	do {
  12. 	    if(++tryct > 200) return;
  13. 	    if (!somexy(croom, &m))
  14. 		return;
  15. 	} while (occupied(m.x, m.y) || bydoor(m.x, m.y));
  16.  
  17. 	/* Put an altar at m.x, m.y */
  18. 	levl[m.x][m.y].typ = ALTAR;
  19.  
  20. 	/* -1 - A_CHAOTIC, 0 - A_NEUTRAL, 1 - A_LAWFUL */
  21. 	al = rn2((int)A_LAWFUL+2) - 1;
  22. 	levl[m.x][m.y].altarmask = Align2amask( al );
  23. }

mkgrave

  1. static void
  2. mkgrave(croom)
  3. struct mkroom *croom;
  4. {
  5. 	coord m;
  6. 	register int tryct = 0;
  7. 	register struct obj *otmp;
  8. 	boolean dobell = !rn2(10);
  9.  
  10.  
  11. 	if(croom->rtype != OROOM) return;
  12.  
  13. 	do {
  14. 	    if(++tryct > 200) return;
  15. 	    if (!somexy(croom, &m))
  16. 		return;
  17. 	} while (occupied(m.x, m.y) || bydoor(m.x, m.y));
  18.  
  19. 	/* Put a grave at m.x, m.y */
  20. 	make_grave(m.x, m.y, dobell ? "Saved by the bell!" : (char *) 0);
  21.  
  22. 	/* Possibly fill it with objects */
  23. 	if (!rn2(3)) (void) mkgold(0L, m.x, m.y);
  24. 	for (tryct = rn2(5); tryct; tryct--) {
  25. 	    otmp = mkobj(RANDOM_CLASS, TRUE);
  26. 	    if (!otmp) return;
  27. 	    curse(otmp);
  28. 	    otmp->ox = m.x;
  29. 	    otmp->oy = m.y;
  30. 	    add_to_buried(otmp);
  31. 	}
  32.  
  33. 	/* Leave a bell, in case we accidentally buried someone alive */
  34. 	if (dobell) (void) mksobj_at(BELL, m.x, m.y, TRUE, FALSE);
  35. 	return;
  36. }
  37.  
  38.  
  39. /* maze levels have slightly different constraints from normal levels */
  40. #define x_maze_min 2
  41. #define y_maze_min 2

mkinvokearea

  1. /*
  2. * Major level transmutation: add a set of stairs (to the Sanctum) after
  3. * an earthquake that leaves behind a a new topology, centered at inv_pos.
  4. * Assumes there are no rooms within the invocation area and that inv_pos
  5. * is not too close to the edge of the map.  Also assume the hero can see,
  6. * which is guaranteed for normal play due to the fact that sight is needed
  7. * to read the Book of the Dead.
  8. */
  9. void
  10. mkinvokearea()
  11. {
  12. int dist;
  13. xchar xmin = inv_pos.x, xmax = inv_pos.x;
  14. xchar ymin = inv_pos.y, ymax = inv_pos.y;
  15. register xchar i;
  16.  
  17. pline_The("floor shakes violently under you!");
  18. pline_The("walls around you begin to bend and crumble!");
  19. display_nhwindow(WIN_MESSAGE, TRUE);
  20.  
  21. mkinvpos(xmin, ymin, 0);		/* middle, before placing stairs */
  22.  
  23. for(dist = 1; dist < 7; dist++) {
  24. 	xmin--; xmax++;
  25.  
  26. 	/* top and bottom */
  27. 	if(dist != 3) { /* the area is wider that it is high */
  28. 	    ymin--; ymax++;
  29. 	    for(i = xmin+1; i < xmax; i++) {
  30. 		mkinvpos(i, ymin, dist);
  31. 		mkinvpos(i, ymax, dist);
  32. 	    }
  33. 	}
  34.  
  35. 	/* left and right */
  36. 	for(i = ymin; i <= ymax; i++) {
  37. 	    mkinvpos(xmin, i, dist);
  38. 	    mkinvpos(xmax, i, dist);
  39. 	}
  40.  
  41. 	flush_screen(1);	/* make sure the new glyphs shows up */
  42. 	delay_output();
  43. }
  44.  
  45. You("are standing at the top of a stairwell leading down!");
  46. mkstairs(u.ux, u.uy, 0, (struct mkroom *)0); /* down */
  47. newsym(u.ux, u.uy);
  48. vision_full_recalc = 1;	/* everything changed */
  49. }

mkinvpos

  1. /* Change level topology.  Boulders in the vicinity are eliminated.
  2. * Temporarily overrides vision in the name of a nice effect.
  3. */
  4. STATIC_OVL void
  5. mkinvpos(x,y,dist)
  6. xchar x,y;
  7. int dist;
  8. {
  9. struct trap *ttmp;
  10. struct obj *otmp;
  11. boolean make_rocks;
  12. register struct rm *lev = &levl[x][y];
  13.  
  14. /* clip at existing map borders if necessary */
  15. if (!within_bounded_area(x, y, x_maze_min + 1, y_maze_min + 1,
  16. 				   x_maze_max - 1, y_maze_max - 1)) {
  17. 	/* only outermost 2 columns and/or rows may be truncated due to edge */
  18. 	if (dist < (7 - 2))
  19. 	    panic("mkinvpos: <%d,%d> (%d) off map edge!", x, y, dist);
  20. 	return;
  21. }
  22.  
  23. /* clear traps */
  24. if ((ttmp = t_at(x,y)) != 0) deltrap(ttmp);
  25.  
  26. /* clear boulders; leave some rocks for non-{moat|trap} locations */
  27. make_rocks = (dist != 1 && dist != 4 && dist != 5) ? TRUE : FALSE;
  28. while ((otmp = sobj_at(BOULDER, x, y)) != 0) {
  29. 	if (make_rocks) {
  30. 	    fracture_rock(otmp);
  31. 	    make_rocks = FALSE;		/* don't bother with more rocks */
  32. 	} else {
  33. 	    obj_extract_self(otmp);
  34. 	    obfree(otmp, (struct obj *)0);
  35. 	}
  36. }
  37. unblock_point(x,y);	/* make sure vision knows this location is open */
  38.  
  39. /* fake out saved state */
  40. lev->seenv = 0;
  41. lev->doormask = 0;
  42. if(dist < 6) lev->lit = TRUE;
  43. lev->waslit = TRUE;
  44. lev->horizontal = FALSE;
  45. viz_array[y][x] = (dist < 6 ) ?
  46. 	(IN_SIGHT|COULD_SEE) : /* short-circuit vision recalc */
  47. 	COULD_SEE;
  48.  
  49. switch(dist) {
  50. case 1: /* fire traps */
  51. 	if (is_pool(x,y)) break;
  52. 	lev->typ = ROOM;
  53. 	ttmp = maketrap(x, y, FIRE_TRAP);
  54. 	if (ttmp) ttmp->tseen = TRUE;
  55. 	break;
  56. case 0: /* lit room locations */
  57. case 2:
  58. case 3:
  59. case 6: /* unlit room locations */
  60. 	lev->typ = ROOM;
  61. 	break;
  62. case 4: /* pools (aka a wide moat) */
  63. case 5:
  64. 	lev->typ = MOAT;
  65. 	/* No kelp! */
  66. 	break;
  67. default:
  68. 	impossible("mkinvpos called with dist %d", dist);
  69. 	break;
  70. }
  71.  
  72. /* display new value of position; could have a monster/object on it */
  73. newsym(x,y);
  74. }

mk_knox_portal

  1. /*
  2. * The portal to Ludios is special.  The entrance can only occur within a
  3. * vault in the main dungeon at a depth greater than 10.  The Ludios branch
  4. * structure reflects this by having a bogus "source" dungeon:  the value
  5. * of n_dgns (thus, Is_branchlev() will never find it).
  6. *
  7. * Ludios will remain isolated until the branch is corrected by this function.
  8. */
  9. STATIC_OVL void
  10. mk_knox_portal(x, y)
  11. xchar x, y;
  12. {
  13. 	extern int n_dgns;		/* from dungeon.c */
  14. 	d_level *source;
  15. 	branch *br;
  16. 	schar u_depth;
  17.  
  18. 	br = dungeon_branch("Fort Ludios");
  19. 	if (on_level(&knox_level, &br->end1)) {
  20. 	    source = &br->end2;
  21. 	} else {
  22. 	    /* disallow Knox branch on a level with one branch already */
  23. 	    if(Is_branchlev(&u.uz))
  24. 		return;
  25. 	    source = &br->end1;
  26. 	}
  27.  
  28. 	/* Already set or 2/3 chance of deferring until a later level. */
  29. 	if (source->dnum < n_dgns || (rn2(3)
  30. #ifdef WIZARD
  31. 				      && !wizard
  32. #endif
  33. 				      )) return;
  34.  
  35. 	if (! (u.uz.dnum == oracle_level.dnum	    /* in main dungeon */
  36. 		&& !at_dgn_entrance("The Quest")    /* but not Quest's entry */
  37. 		&& (u_depth = depth(&u.uz)) > 10    /* beneath 10 */
  38. 		&& u_depth < depth(&medusa_level))) /* and above Medusa */
  39. 	    return;
  40.  
  41. 	/* Adjust source to be current level and re-insert branch. */
  42. 	*source = u.uz;
  43. 	insert_branch(br, TRUE);
  44.  
  45. #ifdef DEBUG
  46. 	pline("Made knox portal.");
  47. #endif
  48. 	place_branch(br, x, y);
  49. }
  50.  
  51. /*mklev.c*/