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