hack.mkmaze.c revision 1.4 1 1.4 christos /* $NetBSD: hack.mkmaze.c,v 1.4 1997/10/19 16:58:27 christos Exp $ */
2 1.4 christos
3 1.2 mycroft /*
4 1.2 mycroft * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
5 1.2 mycroft */
6 1.2 mycroft
7 1.4 christos #include <sys/cdefs.h>
8 1.2 mycroft #ifndef lint
9 1.4 christos __RCSID("$NetBSD: hack.mkmaze.c,v 1.4 1997/10/19 16:58:27 christos Exp $");
10 1.4 christos #endif /* not lint */
11 1.1 cgd
12 1.1 cgd #include "hack.h"
13 1.4 christos #include "extern.h"
14 1.1 cgd #include "def.mkroom.h" /* not really used */
15 1.1 cgd struct permonst hell_hound =
16 1.4 christos {"hell hound", 'd', 12, 14, 2, 3, 6, 0};
17 1.1 cgd
18 1.4 christos void
19 1.1 cgd makemaz()
20 1.1 cgd {
21 1.4 christos int x, y;
22 1.4 christos int zx, zy;
23 1.4 christos coord mm;
24 1.4 christos boolean al = (dlevel >= 30 && !flags.made_amulet);
25 1.4 christos
26 1.4 christos for (x = 2; x < COLNO - 1; x++)
27 1.4 christos for (y = 2; y < ROWNO - 1; y++)
28 1.4 christos levl[x][y].typ = (x % 2 && y % 2) ? 0 : HWALL;
29 1.4 christos if (al) {
30 1.4 christos struct monst *mtmp;
31 1.4 christos
32 1.4 christos zx = 2 * (COLNO / 4) - 1;
33 1.4 christos zy = 2 * (ROWNO / 4) - 1;
34 1.4 christos for (x = zx - 2; x < zx + 4; x++)
35 1.4 christos for (y = zy - 2; y <= zy + 2; y++) {
36 1.4 christos levl[x][y].typ =
37 1.4 christos (y == zy - 2 || y == zy + 2 || x == zx - 2 || x == zx + 3) ? POOL :
38 1.4 christos (y == zy - 1 || y == zy + 1 || x == zx - 1 || x == zx + 2) ? HWALL :
39 1.4 christos ROOM;
40 1.4 christos }
41 1.4 christos (void) mkobj_at(AMULET_SYM, zx, zy);
42 1.4 christos flags.made_amulet = 1;
43 1.4 christos walkfrom(zx + 4, zy);
44 1.4 christos if ((mtmp = makemon(&hell_hound, zx, zy)) != NULL)
45 1.4 christos mtmp->msleep = 1;
46 1.4 christos if ((mtmp = makemon(PM_WIZARD, zx + 1, zy)) != NULL) {
47 1.4 christos mtmp->msleep = 1;
48 1.4 christos flags.no_of_wizards = 1;
49 1.4 christos }
50 1.1 cgd } else {
51 1.4 christos mm = mazexy();
52 1.4 christos zx = mm.x;
53 1.4 christos zy = mm.y;
54 1.4 christos walkfrom(zx, zy);
55 1.4 christos (void) mksobj_at(WAN_WISHING, zx, zy);
56 1.4 christos (void) mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of
57 1.4 christos * it */
58 1.1 cgd }
59 1.1 cgd
60 1.4 christos for (x = 2; x < COLNO - 1; x++)
61 1.4 christos for (y = 2; y < ROWNO - 1; y++) {
62 1.4 christos switch (levl[x][y].typ) {
63 1.1 cgd case HWALL:
64 1.1 cgd levl[x][y].scrsym = '-';
65 1.1 cgd break;
66 1.1 cgd case ROOM:
67 1.1 cgd levl[x][y].scrsym = '.';
68 1.1 cgd break;
69 1.1 cgd }
70 1.1 cgd }
71 1.4 christos for (x = rn1(8, 11); x; x--) {
72 1.1 cgd mm = mazexy();
73 1.1 cgd (void) mkobj_at(rn2(2) ? GEM_SYM : 0, mm.x, mm.y);
74 1.1 cgd }
75 1.4 christos for (x = rn1(10, 2); x; x--) {
76 1.1 cgd mm = mazexy();
77 1.1 cgd (void) mkobj_at(ROCK_SYM, mm.x, mm.y);
78 1.1 cgd }
79 1.1 cgd mm = mazexy();
80 1.1 cgd (void) makemon(PM_MINOTAUR, mm.x, mm.y);
81 1.4 christos for (x = rn1(5, 7); x; x--) {
82 1.1 cgd mm = mazexy();
83 1.1 cgd (void) makemon((struct permonst *) 0, mm.x, mm.y);
84 1.1 cgd }
85 1.4 christos for (x = rn1(6, 7); x; x--) {
86 1.1 cgd mm = mazexy();
87 1.4 christos mkgold(0L, mm.x, mm.y);
88 1.1 cgd }
89 1.4 christos for (x = rn1(6, 7); x; x--)
90 1.4 christos mktrap(0, 1, (struct mkroom *) 0);
91 1.1 cgd mm = mazexy();
92 1.1 cgd levl[(xupstair = mm.x)][(yupstair = mm.y)].scrsym = '<';
93 1.1 cgd levl[xupstair][yupstair].typ = STAIRS;
94 1.1 cgd xdnstair = ydnstair = 0;
95 1.1 cgd }
96 1.1 cgd
97 1.4 christos void
98 1.4 christos walkfrom(x, y)
99 1.4 christos int x, y;
100 1.4 christos {
101 1.4 christos int q, a, dir;
102 1.4 christos int dirs[4];
103 1.1 cgd levl[x][y].typ = ROOM;
104 1.4 christos while (1) {
105 1.1 cgd q = 0;
106 1.4 christos for (a = 0; a < 4; a++)
107 1.4 christos if (okay(x, y, a))
108 1.4 christos dirs[q++] = a;
109 1.4 christos if (!q)
110 1.4 christos return;
111 1.1 cgd dir = dirs[rn2(q)];
112 1.4 christos move(&x, &y, dir);
113 1.1 cgd levl[x][y].typ = ROOM;
114 1.4 christos move(&x, &y, dir);
115 1.4 christos walkfrom(x, y);
116 1.1 cgd }
117 1.1 cgd }
118 1.1 cgd
119 1.4 christos void
120 1.4 christos move(x, y, dir)
121 1.4 christos int *x, *y;
122 1.4 christos int dir;
123 1.1 cgd {
124 1.4 christos switch (dir) {
125 1.4 christos case 0:
126 1.4 christos --(*y);
127 1.4 christos break;
128 1.4 christos case 1:
129 1.4 christos (*x)++;
130 1.4 christos break;
131 1.4 christos case 2:
132 1.4 christos (*y)++;
133 1.4 christos break;
134 1.4 christos case 3:
135 1.4 christos --(*x);
136 1.4 christos break;
137 1.1 cgd }
138 1.1 cgd }
139 1.1 cgd
140 1.4 christos int
141 1.4 christos okay(x, y, dir)
142 1.4 christos int x, y;
143 1.4 christos int dir;
144 1.1 cgd {
145 1.4 christos move(&x, &y, dir);
146 1.4 christos move(&x, &y, dir);
147 1.4 christos if (x < 3 || y < 3 || x > COLNO - 3 || y > ROWNO - 3 || levl[x][y].typ != 0)
148 1.4 christos return (0);
149 1.1 cgd else
150 1.4 christos return (1);
151 1.1 cgd }
152 1.1 cgd
153 1.1 cgd coord
154 1.4 christos mazexy()
155 1.4 christos {
156 1.4 christos coord mm;
157 1.4 christos mm.x = 3 + 2 * rn2(COLNO / 2 - 2);
158 1.4 christos mm.y = 3 + 2 * rn2(ROWNO / 2 - 2);
159 1.1 cgd return mm;
160 1.1 cgd }
161