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