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