1 1.8 dholland /* $NetBSD: hack.mkmaze.c,v 1.8 2009/08/12 07:28:41 dholland 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.8 dholland __RCSID("$NetBSD: hack.mkmaze.c,v 1.8 2009/08/12 07:28:41 dholland 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.8 dholland 73 1.8 dholland static const struct permonst hell_hound = 74 1.4 christos {"hell hound", 'd', 12, 14, 2, 3, 6, 0}; 75 1.1 cgd 76 1.8 dholland static void walkfrom(int, int); 77 1.8 dholland static void move(int *, int *, int); 78 1.8 dholland static int okay(int, int, int); 79 1.8 dholland 80 1.4 christos void 81 1.7 dholland makemaz(void) 82 1.1 cgd { 83 1.4 christos int x, y; 84 1.4 christos int zx, zy; 85 1.4 christos coord mm; 86 1.4 christos boolean al = (dlevel >= 30 && !flags.made_amulet); 87 1.4 christos 88 1.4 christos for (x = 2; x < COLNO - 1; x++) 89 1.4 christos for (y = 2; y < ROWNO - 1; y++) 90 1.4 christos levl[x][y].typ = (x % 2 && y % 2) ? 0 : HWALL; 91 1.4 christos if (al) { 92 1.4 christos struct monst *mtmp; 93 1.4 christos 94 1.4 christos zx = 2 * (COLNO / 4) - 1; 95 1.4 christos zy = 2 * (ROWNO / 4) - 1; 96 1.4 christos for (x = zx - 2; x < zx + 4; x++) 97 1.4 christos for (y = zy - 2; y <= zy + 2; y++) { 98 1.4 christos levl[x][y].typ = 99 1.4 christos (y == zy - 2 || y == zy + 2 || x == zx - 2 || x == zx + 3) ? POOL : 100 1.4 christos (y == zy - 1 || y == zy + 1 || x == zx - 1 || x == zx + 2) ? HWALL : 101 1.4 christos ROOM; 102 1.4 christos } 103 1.4 christos (void) mkobj_at(AMULET_SYM, zx, zy); 104 1.4 christos flags.made_amulet = 1; 105 1.4 christos walkfrom(zx + 4, zy); 106 1.4 christos if ((mtmp = makemon(&hell_hound, zx, zy)) != NULL) 107 1.4 christos mtmp->msleep = 1; 108 1.4 christos if ((mtmp = makemon(PM_WIZARD, zx + 1, zy)) != NULL) { 109 1.4 christos mtmp->msleep = 1; 110 1.4 christos flags.no_of_wizards = 1; 111 1.4 christos } 112 1.1 cgd } else { 113 1.4 christos mm = mazexy(); 114 1.4 christos zx = mm.x; 115 1.4 christos zy = mm.y; 116 1.4 christos walkfrom(zx, zy); 117 1.4 christos (void) mksobj_at(WAN_WISHING, zx, zy); 118 1.4 christos (void) mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of 119 1.4 christos * it */ 120 1.1 cgd } 121 1.1 cgd 122 1.4 christos for (x = 2; x < COLNO - 1; x++) 123 1.4 christos for (y = 2; y < ROWNO - 1; y++) { 124 1.4 christos switch (levl[x][y].typ) { 125 1.1 cgd case HWALL: 126 1.1 cgd levl[x][y].scrsym = '-'; 127 1.1 cgd break; 128 1.1 cgd case ROOM: 129 1.1 cgd levl[x][y].scrsym = '.'; 130 1.1 cgd break; 131 1.1 cgd } 132 1.1 cgd } 133 1.4 christos for (x = rn1(8, 11); x; x--) { 134 1.1 cgd mm = mazexy(); 135 1.1 cgd (void) mkobj_at(rn2(2) ? GEM_SYM : 0, mm.x, mm.y); 136 1.1 cgd } 137 1.4 christos for (x = rn1(10, 2); x; x--) { 138 1.1 cgd mm = mazexy(); 139 1.1 cgd (void) mkobj_at(ROCK_SYM, mm.x, mm.y); 140 1.1 cgd } 141 1.1 cgd mm = mazexy(); 142 1.1 cgd (void) makemon(PM_MINOTAUR, mm.x, mm.y); 143 1.4 christos for (x = rn1(5, 7); x; x--) { 144 1.1 cgd mm = mazexy(); 145 1.1 cgd (void) makemon((struct permonst *) 0, mm.x, mm.y); 146 1.1 cgd } 147 1.4 christos for (x = rn1(6, 7); x; x--) { 148 1.1 cgd mm = mazexy(); 149 1.4 christos mkgold(0L, mm.x, mm.y); 150 1.1 cgd } 151 1.4 christos for (x = rn1(6, 7); x; x--) 152 1.4 christos mktrap(0, 1, (struct mkroom *) 0); 153 1.1 cgd mm = mazexy(); 154 1.1 cgd levl[(xupstair = mm.x)][(yupstair = mm.y)].scrsym = '<'; 155 1.1 cgd levl[xupstair][yupstair].typ = STAIRS; 156 1.1 cgd xdnstair = ydnstair = 0; 157 1.1 cgd } 158 1.1 cgd 159 1.8 dholland static void 160 1.7 dholland walkfrom(int x, int y) 161 1.4 christos { 162 1.4 christos int q, a, dir; 163 1.4 christos int dirs[4]; 164 1.1 cgd levl[x][y].typ = ROOM; 165 1.4 christos while (1) { 166 1.1 cgd q = 0; 167 1.4 christos for (a = 0; a < 4; a++) 168 1.4 christos if (okay(x, y, a)) 169 1.4 christos dirs[q++] = a; 170 1.4 christos if (!q) 171 1.4 christos return; 172 1.1 cgd dir = dirs[rn2(q)]; 173 1.4 christos move(&x, &y, dir); 174 1.1 cgd levl[x][y].typ = ROOM; 175 1.4 christos move(&x, &y, dir); 176 1.4 christos walkfrom(x, y); 177 1.1 cgd } 178 1.1 cgd } 179 1.1 cgd 180 1.8 dholland static void 181 1.7 dholland move(int *x, int *y, int dir) 182 1.1 cgd { 183 1.4 christos switch (dir) { 184 1.4 christos case 0: 185 1.4 christos --(*y); 186 1.4 christos break; 187 1.4 christos case 1: 188 1.4 christos (*x)++; 189 1.4 christos break; 190 1.4 christos case 2: 191 1.4 christos (*y)++; 192 1.4 christos break; 193 1.4 christos case 3: 194 1.4 christos --(*x); 195 1.4 christos break; 196 1.1 cgd } 197 1.1 cgd } 198 1.1 cgd 199 1.8 dholland static int 200 1.7 dholland okay(int x, int y, 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.7 dholland mazexy(void) 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