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