Source:NetHack 3.4.3/src/extralev.c

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

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

Top of file

  1. /*	SCCS Id: @(#)extralev.c	3.4	2001/09/06	*/
  2. /*	Copyright 1988, 1989 by Ken Arromdee				*/
  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. /*
  2. * Support code for "rogue"-style level.
  3. */
  4.  
  5. #include "hack.h"
  6.  
  7. #ifdef REINCARNATION
  8.  
  9. struct rogueroom {
  10. 	xchar rlx, rly;
  11. 	xchar dx, dy;
  12. 	boolean real;
  13. 	uchar doortable;
  14. 	int nroom; /* Only meaningful for "real" rooms */
  15. };
  16. #define UP 1
  17. #define DOWN 2
  18. #define LEFT 4
  19. #define RIGHT 8
  20.  
  21. static NEARDATA struct rogueroom r[3][3];
  22. STATIC_DCL void FDECL(roguejoin,(int,int,int,int,int));
  23. STATIC_DCL void FDECL(roguecorr,(int,int,int));
  24. STATIC_DCL void FDECL(miniwalk,(int,int));

roguejoin

  1. STATIC_OVL
  2. void
  3. roguejoin(x1,y1,x2,y2, horiz)
  4. int x1,y1,x2,y2;
  5. int horiz;
  6. {
  7. 	register int x,y,middle;
  8. #ifndef MAX
  9. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  10. #endif
  11. #ifndef MIN
  12. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  13. #endif
  14. 	if (horiz) {
  15. 		middle = x1 + rn2(x2-x1+1);
  16. 		for(x=MIN(x1,middle); x<=MAX(x1,middle); x++)
  17. 			corr(x, y1);
  18. 		for(y=MIN(y1,y2); y<=MAX(y1,y2); y++)
  19. 			corr(middle,y);
  20. 		for(x=MIN(middle,x2); x<=MAX(middle,x2); x++)
  21. 			corr(x, y2);
  22. 	} else {
  23. 		middle = y1 + rn2(y2-y1+1);
  24. 		for(y=MIN(y1,middle); y<=MAX(y1,middle); y++)
  25. 			corr(x1, y);
  26. 		for(x=MIN(x1,x2); x<=MAX(x1,x2); x++)
  27. 			corr(x, middle);
  28. 		for(y=MIN(middle,y2); y<=MAX(middle,y2); y++)
  29. 			corr(x2,y);
  30. 	}
  31. }

roguecorr

  1. STATIC_OVL
  2. void
  3. roguecorr(x, y, dir)
  4. int x,y,dir;
  5. {
  6. 	register int fromx, fromy, tox, toy;
  7.  
  8. 	if (dir==DOWN) {
  9. 		r[x][y].doortable &= ~DOWN;
  10. 		if (!r[x][y].real) {
  11. 			fromx = r[x][y].rlx; fromy = r[x][y].rly;
  12. 			fromx += 1 + 26*x; fromy += 7*y;
  13. 		} else {
  14. 			fromx = r[x][y].rlx + rn2(r[x][y].dx);
  15. 			fromy = r[x][y].rly + r[x][y].dy;
  16. 			fromx += 1 + 26*x; fromy += 7*y;
  17. 			if (!IS_WALL(levl[fromx][fromy].typ))
  18. 				impossible("down: no wall at %d,%d?",fromx,
  19. 									fromy);
  20. 			dodoor(fromx, fromy, &rooms[r[x][y].nroom]);
  21. 			levl[fromx][fromy].doormask = D_NODOOR;
  22. 			fromy++;
  23. 		}
  24. 		if(y >= 2) {
  25. 			impossible("down door from %d,%d going nowhere?",x,y);
  26. 			return;
  27. 		}
  28. 		y++;
  29. 		r[x][y].doortable &= ~UP;
  30. 		if (!r[x][y].real) {
  31. 			tox = r[x][y].rlx; toy = r[x][y].rly;
  32. 			tox += 1 + 26*x; toy += 7*y;
  33. 		} else {
  34. 			tox = r[x][y].rlx + rn2(r[x][y].dx);
  35. 			toy = r[x][y].rly - 1;
  36. 			tox += 1 + 26*x; toy += 7*y;
  37. 			if (!IS_WALL(levl[tox][toy].typ))
  38. 				impossible("up: no wall at %d,%d?",tox,toy);
  39. 			dodoor(tox, toy, &rooms[r[x][y].nroom]);
  40. 			levl[tox][toy].doormask = D_NODOOR;
  41. 			toy--;
  42. 		}
  43. 		roguejoin(fromx, fromy, tox, toy, FALSE);
  44. 		return;
  45. 	} else if (dir == RIGHT) {
  46. 		r[x][y].doortable &= ~RIGHT;
  47. 		if (!r[x][y].real) {
  48. 			fromx = r[x][y].rlx; fromy = r[x][y].rly;
  49. 			fromx += 1 + 26*x; fromy += 7*y;
  50. 		} else {
  51. 			fromx = r[x][y].rlx + r[x][y].dx;
  52. 			fromy = r[x][y].rly + rn2(r[x][y].dy);
  53. 			fromx += 1 + 26*x; fromy += 7*y;
  54. 			if (!IS_WALL(levl[fromx][fromy].typ))
  55. 				impossible("down: no wall at %d,%d?",fromx,
  56. 									fromy);
  57. 			dodoor(fromx, fromy, &rooms[r[x][y].nroom]);
  58. 			levl[fromx][fromy].doormask = D_NODOOR;
  59. 			fromx++;
  60. 		}
  61. 		if(x >= 2) {
  62. 			impossible("right door from %d,%d going nowhere?",x,y);
  63. 			return;
  64. 		}
  65. 		x++;
  66. 		r[x][y].doortable &= ~LEFT;
  67. 		if (!r[x][y].real) {
  68. 			tox = r[x][y].rlx; toy = r[x][y].rly;
  69. 			tox += 1 + 26*x; toy += 7*y;
  70. 		} else {
  71. 			tox = r[x][y].rlx - 1;
  72. 			toy = r[x][y].rly + rn2(r[x][y].dy);
  73. 			tox += 1 + 26*x; toy += 7*y;
  74. 			if (!IS_WALL(levl[tox][toy].typ))
  75. 				impossible("left: no wall at %d,%d?",tox,toy);
  76. 			dodoor(tox, toy, &rooms[r[x][y].nroom]);
  77. 			levl[tox][toy].doormask = D_NODOOR;
  78. 			tox--;
  79. 		}
  80. 		roguejoin(fromx, fromy, tox, toy, TRUE);
  81. 		return;
  82. 	} else impossible("corridor in direction %d?",dir);
  83. }

miniwalk

  1. /* Modified walkfrom() from mkmaze.c */
  2. STATIC_OVL
  3. void
  4. miniwalk(x, y)
  5. int x,y;
  6. {
  7. 	register int q, dir;
  8. 	int dirs[4];
  9.  
  10. 	while(1) {
  11. 		q = 0;
  12. #define doorhere (r[x][y].doortable)
  13. 		if (x>0 && (!(doorhere & LEFT)) &&
  14. 					(!r[x-1][y].doortable || !rn2(10)))
  15. 			dirs[q++] = 0;
  16. 		if (x<2 && (!(doorhere & RIGHT)) &&
  17. 					(!r[x+1][y].doortable || !rn2(10)))
  18. 			dirs[q++] = 1;
  19. 		if (y>0 && (!(doorhere & UP)) &&
  20. 					(!r[x][y-1].doortable || !rn2(10)))
  21. 			dirs[q++] = 2;
  22. 		if (y<2 && (!(doorhere & DOWN)) &&
  23. 					(!r[x][y+1].doortable || !rn2(10)))
  24. 			dirs[q++] = 3;
  25. 	/* Rogue levels aren't just 3 by 3 mazes; they have some extra
  26. 	 * connections, thus that 1/10 chance
  27. 	 */
  28. 		if (!q) return;
  29. 		dir = dirs[rn2(q)];
  30. 		switch(dir) { /* Move in direction */
  31. 			case 0: doorhere |= LEFT;
  32. 				x--;
  33. 				doorhere |= RIGHT;
  34. 				break;
  35. 			case 1: doorhere |= RIGHT;
  36. 				x++;
  37. 				doorhere |= LEFT;
  38. 				break;
  39. 			case 2: doorhere |= UP;
  40. 				y--;
  41. 				doorhere |= DOWN;
  42. 				break;
  43. 			case 3: doorhere |= DOWN;
  44. 				y++;
  45. 				doorhere |= UP;
  46. 				break;
  47. 		}
  48. 		miniwalk(x,y);
  49. 	}
  50. }

makeroguerooms

  1. void
  2. makeroguerooms() {
  3. 	register int x,y;
  4. 	/* Rogue levels are structured 3 by 3, with each section containing
  5. 	 * a room or an intersection.  The minimum width is 2 each way.
  6. 	 * One difference between these and "real" Rogue levels: real Rogue
  7. 	 * uses 24 rows and NetHack only 23.  So we cheat a bit by making the
  8. 	 * second row of rooms not as deep.
  9. 	 *
  10. 	 * Each normal space has 6/7 rows and 25 columns in which a room may
  11. 	 * actually be placed.  Walls go from rows 0-5/6 and columns 0-24.
  12. 	 * Not counting walls, the room may go in
  13. 	 * rows 1-5 and columns 1-23 (numbering starting at 0).  A room
  14. 	 * coordinate of this type may be converted to a level coordinate
  15. 	 * by adding 1+28*x to the column, and 7*y to the row.  (The 1
  16. 	 * is because column 0 isn't used [we only use 1-78]).
  17. 	 * Room height may be 2-4 (2-5 on last row), length 2-23 (not
  18. 	 * counting walls)
  19. 	 */
  20. #define here r[x][y]
  21.  
  22. 	nroom = 0;
  23. 	for(y=0; y<3; y++) for(x=0; x<3; x++) {
  24. 		/* Note: we want to insure at least 1 room.  So, if the
  25. 		 * first 8 are all dummies, force the last to be a room.
  26. 		 */
  27. 		if (!rn2(5) && (nroom || (x<2 && y<2))) {
  28. 			/* Arbitrary: dummy rooms may only go where real
  29. 			 * ones do.
  30. 			 */
  31. 			here.real = FALSE;
  32. 			here.rlx = rn1(22, 2);
  33. 			here.rly = rn1((y==2)?4:3, 2);
  34. 		} else {
  35. 			here.real = TRUE;
  36. 			here.dx = rn1(22, 2); /* 2-23 long, plus walls */
  37. 			here.dy = rn1((y==2)?4:3, 2); /* 2-5 high, plus walls */
  38.  
  39. 			/* boundaries of room floor */
  40. 			here.rlx = rnd(23 - here.dx + 1);
  41. 			here.rly = rnd(((y==2) ? 5 : 4)- here.dy + 1);
  42. 			nroom++;
  43. 		}
  44. 		here.doortable = 0;
  45. 	}
  46. 	miniwalk(rn2(3), rn2(3));
  47. 	nroom = 0;
  48. 	for(y=0; y<3; y++) for(x=0; x<3; x++) {
  49. 		if (here.real) { /* Make a room */
  50. 			int lowx, lowy, hix, hiy;
  51.  
  52. 			r[x][y].nroom = nroom;
  53. 			smeq[nroom] = nroom;
  54.  
  55. 			lowx = 1 + 26*x + here.rlx;
  56. 			lowy = 7*y + here.rly;
  57. 			hix = 1 + 26*x + here.rlx + here.dx - 1;
  58. 			hiy = 7*y + here.rly + here.dy - 1;
  59. 			/* Strictly speaking, it should be lit only if above
  60. 			 * level 10, but since Rogue rooms are only
  61. 			 * encountered below level 10, use !rn2(7).
  62. 			 */
  63. 			add_room(lowx, lowy, hix, hiy,
  64. 				 (boolean) !rn2(7), OROOM, FALSE);
  65. 		}
  66. 	}
  67.  
  68. 	/* Now, add connecting corridors. */
  69. 	for(y=0; y<3; y++) for(x=0; x<3; x++) {
  70. 		if (here.doortable & DOWN)
  71. 			roguecorr(x, y, DOWN);
  72. 		if (here.doortable & RIGHT)
  73. 			roguecorr(x, y, RIGHT);
  74. 		if (here.doortable & LEFT)
  75. 			impossible ("left end of %d, %d never connected?",x,y);
  76. 		if (here.doortable & UP)
  77. 			impossible ("up end of %d, %d never connected?",x,y);
  78. 	}
  79. }

corr

  1. void
  2. corr(x,y)
  3. int x, y;
  4. {
  5. 	if (rn2(50)) {
  6. 		levl[x][y].typ = CORR;
  7. 	} else {
  8. 		levl[x][y].typ = SCORR;
  9. 	}
  10. }

makerogueghost

  1. void
  2. makerogueghost()
  3. {
  4. 	register struct monst *ghost;
  5. 	struct obj *ghostobj;
  6. 	struct mkroom *croom;
  7. 	int x,y;
  8.  
  9. 	if (!nroom) return; /* Should never happen */
  10. 	croom = &rooms[rn2(nroom)];
  11. 	x = somex(croom); y = somey(croom);
  12. 	if (!(ghost = makemon(&mons[PM_GHOST], x, y, NO_MM_FLAGS)))
  13. 		return;
  14. 	ghost->msleeping = 1;
  15. 	ghost = christen_monst(ghost, roguename());
  16.  
  17. 	if (rn2(4)) {
  18. 		ghostobj = mksobj_at(FOOD_RATION, x, y, FALSE, FALSE);
  19. 		ghostobj->quan = (long) rnd(7);
  20. 		ghostobj->owt = weight(ghostobj);
  21. 	}
  22. 	if (rn2(2)) {
  23. 		ghostobj = mksobj_at(MACE, x, y, FALSE, FALSE);
  24. 		ghostobj->spe = rnd(3);
  25. 		if (rn2(4)) curse(ghostobj);
  26. 	} else {
  27. 		ghostobj = mksobj_at(TWO_HANDED_SWORD, x, y, FALSE, FALSE);
  28. 		ghostobj->spe = rnd(5) - 2;
  29. 		if (rn2(4)) curse(ghostobj);
  30. 	}
  31. 	ghostobj = mksobj_at(BOW, x, y, FALSE, FALSE);
  32. 	ghostobj->spe = 1;
  33. 	if (rn2(4)) curse(ghostobj);
  34.  
  35. 	ghostobj = mksobj_at(ARROW, x, y, FALSE, FALSE);
  36. 	ghostobj->spe = 0;
  37. 	ghostobj->quan = (long) rn1(10,25);
  38. 	ghostobj->owt = weight(ghostobj);
  39. 	if (rn2(4)) curse(ghostobj);
  40.  
  41. 	if (rn2(2)) {
  42. 		ghostobj = mksobj_at(RING_MAIL, x, y, FALSE, FALSE);
  43. 		ghostobj->spe = rn2(3);
  44. 		if (!rn2(3)) ghostobj->oerodeproof = TRUE;
  45. 		if (rn2(4)) curse(ghostobj);
  46. 	} else {
  47. 		ghostobj = mksobj_at(PLATE_MAIL, x, y, FALSE, FALSE);
  48. 		ghostobj->spe = rnd(5) - 2;
  49. 		if (!rn2(3)) ghostobj->oerodeproof = TRUE;
  50. 		if (rn2(4)) curse(ghostobj);
  51. 	}
  52. 	if (rn2(2)) {
  53. 		ghostobj = mksobj_at(FAKE_AMULET_OF_YENDOR, x, y, TRUE, FALSE);
  54. 		ghostobj->known = TRUE;
  55. 	}
  56. }
  57. #endif /* REINCARNATION */
  58.  
  59. /*extralev.c*/