hack.mkmaze.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* $NetBSD: hack.mkmaze.c,v 1.6 2003/04/02 18:36:38 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
  4. * Amsterdam
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * - Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. *
  14. * - Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * - Neither the name of the Stichting Centrum voor Wiskunde en
  19. * Informatica, nor the names of its contributors may be used to endorse or
  20. * promote products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  25. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  26. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  27. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. /*
  36. * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
  37. * All rights reserved.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. * 1. Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * 2. Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in the
  46. * documentation and/or other materials provided with the distribution.
  47. * 3. The name of the author may not be used to endorse or promote products
  48. * derived from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  51. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  52. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  53. * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  54. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  55. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  56. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  57. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  58. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  59. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60. */
  61. #include <sys/cdefs.h>
  62. #ifndef lint
  63. __RCSID("$NetBSD: hack.mkmaze.c,v 1.6 2003/04/02 18:36:38 jsm Exp $");
  64. #endif /* not lint */
  65. #include "hack.h"
  66. #include "extern.h"
  67. #include "def.mkroom.h" /* not really used */
  68. const struct permonst hell_hound =
  69. {"hell hound", 'd', 12, 14, 2, 3, 6, 0};
  70. void
  71. makemaz()
  72. {
  73. int x, y;
  74. int zx, zy;
  75. coord mm;
  76. boolean al = (dlevel >= 30 && !flags.made_amulet);
  77. for (x = 2; x < COLNO - 1; x++)
  78. for (y = 2; y < ROWNO - 1; y++)
  79. levl[x][y].typ = (x % 2 && y % 2) ? 0 : HWALL;
  80. if (al) {
  81. struct monst *mtmp;
  82. zx = 2 * (COLNO / 4) - 1;
  83. zy = 2 * (ROWNO / 4) - 1;
  84. for (x = zx - 2; x < zx + 4; x++)
  85. for (y = zy - 2; y <= zy + 2; y++) {
  86. levl[x][y].typ =
  87. (y == zy - 2 || y == zy + 2 || x == zx - 2 || x == zx + 3) ? POOL :
  88. (y == zy - 1 || y == zy + 1 || x == zx - 1 || x == zx + 2) ? HWALL :
  89. ROOM;
  90. }
  91. (void) mkobj_at(AMULET_SYM, zx, zy);
  92. flags.made_amulet = 1;
  93. walkfrom(zx + 4, zy);
  94. if ((mtmp = makemon(&hell_hound, zx, zy)) != NULL)
  95. mtmp->msleep = 1;
  96. if ((mtmp = makemon(PM_WIZARD, zx + 1, zy)) != NULL) {
  97. mtmp->msleep = 1;
  98. flags.no_of_wizards = 1;
  99. }
  100. } else {
  101. mm = mazexy();
  102. zx = mm.x;
  103. zy = mm.y;
  104. walkfrom(zx, zy);
  105. (void) mksobj_at(WAN_WISHING, zx, zy);
  106. (void) mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of
  107. * it */
  108. }
  109. for (x = 2; x < COLNO - 1; x++)
  110. for (y = 2; y < ROWNO - 1; y++) {
  111. switch (levl[x][y].typ) {
  112. case HWALL:
  113. levl[x][y].scrsym = '-';
  114. break;
  115. case ROOM:
  116. levl[x][y].scrsym = '.';
  117. break;
  118. }
  119. }
  120. for (x = rn1(8, 11); x; x--) {
  121. mm = mazexy();
  122. (void) mkobj_at(rn2(2) ? GEM_SYM : 0, mm.x, mm.y);
  123. }
  124. for (x = rn1(10, 2); x; x--) {
  125. mm = mazexy();
  126. (void) mkobj_at(ROCK_SYM, mm.x, mm.y);
  127. }
  128. mm = mazexy();
  129. (void) makemon(PM_MINOTAUR, mm.x, mm.y);
  130. for (x = rn1(5, 7); x; x--) {
  131. mm = mazexy();
  132. (void) makemon((struct permonst *) 0, mm.x, mm.y);
  133. }
  134. for (x = rn1(6, 7); x; x--) {
  135. mm = mazexy();
  136. mkgold(0L, mm.x, mm.y);
  137. }
  138. for (x = rn1(6, 7); x; x--)
  139. mktrap(0, 1, (struct mkroom *) 0);
  140. mm = mazexy();
  141. levl[(xupstair = mm.x)][(yupstair = mm.y)].scrsym = '<';
  142. levl[xupstair][yupstair].typ = STAIRS;
  143. xdnstair = ydnstair = 0;
  144. }
  145. void
  146. walkfrom(x, y)
  147. int x, y;
  148. {
  149. int q, a, dir;
  150. int dirs[4];
  151. levl[x][y].typ = ROOM;
  152. while (1) {
  153. q = 0;
  154. for (a = 0; a < 4; a++)
  155. if (okay(x, y, a))
  156. dirs[q++] = a;
  157. if (!q)
  158. return;
  159. dir = dirs[rn2(q)];
  160. move(&x, &y, dir);
  161. levl[x][y].typ = ROOM;
  162. move(&x, &y, dir);
  163. walkfrom(x, y);
  164. }
  165. }
  166. void
  167. move(x, y, dir)
  168. int *x, *y;
  169. int dir;
  170. {
  171. switch (dir) {
  172. case 0:
  173. --(*y);
  174. break;
  175. case 1:
  176. (*x)++;
  177. break;
  178. case 2:
  179. (*y)++;
  180. break;
  181. case 3:
  182. --(*x);
  183. break;
  184. }
  185. }
  186. int
  187. okay(x, y, dir)
  188. int x, y;
  189. int dir;
  190. {
  191. move(&x, &y, dir);
  192. move(&x, &y, dir);
  193. if (x < 3 || y < 3 || x > COLNO - 3 || y > ROWNO - 3 || levl[x][y].typ != 0)
  194. return (0);
  195. else
  196. return (1);
  197. }
  198. coord
  199. mazexy()
  200. {
  201. coord mm;
  202. mm.x = 3 + 2 * rn2(COLNO / 2 - 2);
  203. mm.y = 3 + 2 * rn2(ROWNO / 2 - 2);
  204. return mm;
  205. }