abstract
| - Below is the full text to mkmaze.c from the source code of NetHack 1.4f. To link to a particular line, write [[NetHack 1.4f/mkmaze.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* SCCS Id: @(#)mkmaze.c 1.4 87/08/08 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* mkmaze.c - version 1.0.2 */ 4. 5. #include "hack.h" 6. #include "mkroom.h" /* not really used */ 7. extern struct monst *makemon(); 8. extern struct permonst pm_wizard; 9. extern struct obj *mkobj_at(); 10. struct permonst hell_hound = 11. { "hell hound", 'd', 12, 14, 2, 20, 3, 6, 0 }; 12. 13. makemaz() 14. { 15. int x,y; 16. register zx,zy; 17. coord mm; 18. boolean al = (dlevel >= 30 && !flags.made_amulet); 19. 20. for(x = 2; x < COLNO-1; x++) 21. for(y = 2; y < ROWNO-1; y++) 22. levl[x][y].typ = (x%2 && y%2) ? 0 : HWALL; 23. if(al) { 24. register struct monst *mtmp; 25. 26. zx = 2*(COLNO/4) - 1; 27. zy = 2*(ROWNO/4) - 1; 28. for(x = zx-2; x < zx+4; x++) for(y = zy-2; y <= zy+2; y++) { 29. levl[x][y].typ = 30. (y == zy-2 || y == zy+2 || x == zx-2 || x == zx+3) ? POOL : 31. (y == zy-1 || y == zy+1 || x == zx-1 || x == zx+2) ? HWALL: 32. ROOM; 33. } 34. (void) mkobj_at(AMULET_SYM, zx, zy); 35. flags.made_amulet = 1; 36. walkfrom(zx+4, zy); 37. if(mtmp = makemon(&hell_hound, zx, zy)) 38. mtmp->msleep = 1; 39. if(mtmp = makemon(PM_WIZARD, zx+1, zy)) { 40. mtmp->msleep = 1; 41. flags.no_of_wizards = 1; 42. } 43. } else { 44. mazexy(&mm); 45. zx = mm.x; 46. zy = mm.y; 47. walkfrom(zx,zy); 48. (void) mksobj_at(WAN_WISHING, zx, zy); 49. (void) mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of it */ 50. } 51. 52. for(x = 2; x < COLNO-1; x++) 53. for(y = 2; y < ROWNO-1; y++) { 54. switch(levl[x][y].typ) { 55. case HWALL: 56. levl[x][y].scrsym = HWALL_SYM; 57. break; 58. case ROOM: 59. levl[x][y].scrsym = ROOM_SYM; 60. break; 61. } 62. } 63. for(x = rn1(8,11); x; x--) { 64. mazexy(&mm); 65. (void) mkobj_at(rn2(2) ? GEM_SYM : 0, mm.x, mm.y); 66. } 67. for(x = rn1(10,2); x; x--) { 68. mazexy(&mm); 69. (void) mkobj_at(ROCK_SYM, mm.x, mm.y); 70. } 71. mazexy(&mm); 72. (void) makemon(PM_MINOTAUR, mm.x, mm.y); 73. for(x = rn1(5,7); x; x--) { 74. mazexy(&mm); 75. (void) makemon((struct permonst *) 0, mm.x, mm.y); 76. } 77. for(x = rn1(6,7); x; x--) { 78. mazexy(&mm); 79. mkgold(0L,mm.x,mm.y); 80. } 81. for(x = rn1(6,7); x; x--) 82. mktrap(0,1,(struct mkroom *) 0); 83. mazexy(&mm); 84. levl[(xupstair = mm.x)][(yupstair = mm.y)].scrsym = UP_SYM; 85. levl[xupstair][yupstair].typ = STAIRS; 86. xdnstair = ydnstair = 0; 87. } 88. 89. #ifdef DGK 90. /* Make the mazewalk iterative by faking a stack. This is needed to 91. * ensure the mazewalk is successful in the limited stack space of 92. * the program. This iterative version uses the mimumum amount of stack 93. * that is totally safe. 94. */ 95. walkfrom(x,y) 96. int x,y; 97. { 98. #define CELLS (ROWNO * COLNO) / 4 /* a maze cell is 4 squares */ 99. char mazex[CELLS + 1], mazey[CELLS + 1]; /* char's are OK */ 100. int q, a, dir, pos; 101. int dirs[4]; 102. 103. pos = 1; 104. mazex[pos] = (char) x; 105. mazey[pos] = (char) y; 106. while (pos) { 107. x = (int) mazex[pos]; 108. y = (int) mazey[pos]; 109. levl[x][y].typ = ROOM; 110. q = 0; 111. for (a = 0; a < 4; a++) 112. if(okay(x, y, a)) dirs[q++]= a; 113. if (!q) 114. pos--; 115. else { 116. dir = dirs[rn2(q)]; 117. move(&x, &y, dir); 118. levl[x][y].typ = ROOM; 119. move(&x, &y, dir); 120. pos++; 121. if (pos > CELLS) 122. panic("Overflow in walkfrom"); 123. mazex[pos] = (char) x; 124. mazey[pos] = (char) y; 125. } 126. } 127. } 128. #else 129. 130. walkfrom(x,y) int x,y; { 131. register int q,a,dir; 132. int dirs[4]; 133. levl[x][y].typ = ROOM; 134. while(1) { 135. q = 0; 136. for(a = 0; a < 4; a++) 137. if(okay(x,y,a)) dirs[q++]= a; 138. if(!q) return; 139. dir = dirs[rn2(q)]; 140. move(&x,&y,dir); 141. levl[x][y].typ = ROOM; 142. move(&x,&y,dir); 143. walkfrom(x,y); 144. } 145. } 146. #endif /* DGK /**/ 147. 148. move(x,y,dir) 149. register int *x, *y; 150. register int dir; 151. { 152. switch(dir){ 153. case 0: --(*y); break; 154. case 1: (*x)++; break; 155. case 2: (*y)++; break; 156. case 3: --(*x); break; 157. } 158. } 159. 160. okay(x,y,dir) 161. int x,y; 162. register int dir; 163. { 164. move(&x,&y,dir); 165. move(&x,&y,dir); 166. if(x<3 || y<3 || x>COLNO-3 || y>ROWNO-3 || levl[x][y].typ != 0) 167. return(0); 168. else 169. return(1); 170. } 171. 172. mazexy(cc) 173. coord *cc; 174. { 175. cc->x = 3 + 2*rn2(COLNO/2 - 2); 176. cc->y = 3 + 2*rn2(ROWNO/2 - 2); 177. return(0); 178. }
|