Merge from vendor branch OPENSSL:
[games.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
c7106d58
PA
11static void walkfrom(int, int);
12static void move(int *, int *, int);
13static bool okay(int, int, int);
14
15void
16makemaz(void)
984263bc
MD
17{
18 int x,y;
19 int zx,zy;
20 coord mm;
21 boolean al = (dlevel >= 30 && !flags.made_amulet);
22
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;
28
29 zx = 2*(COLNO/4) - 1;
30 zy = 2*(ROWNO/4) - 1;
31 for(x = zx-2; x < zx+4; x++) for(y = zy-2; y <= zy+2; y++) {
32 levl[x][y].typ =
33 (y == zy-2 || y == zy+2 || x == zx-2 || x == zx+3) ? POOL :
34 (y == zy-1 || y == zy+1 || x == zx-1 || x == zx+2) ? HWALL:
35 ROOM;
36 }
c7106d58 37 mkobj_at(AMULET_SYM, zx, zy);
984263bc
MD
38 flags.made_amulet = 1;
39 walkfrom(zx+4, zy);
c7106d58 40 if((mtmp = makemon(&hell_hound, zx, zy)))
984263bc 41 mtmp->msleep = 1;
c7106d58 42 if((mtmp = makemon(PM_WIZARD, zx+1, zy))) {
984263bc
MD
43 mtmp->msleep = 1;
44 flags.no_of_wizards = 1;
45 }
46 } else {
47 mm = mazexy();
48 zx = mm.x;
49 zy = mm.y;
50 walkfrom(zx,zy);
c7106d58
PA
51 mksobj_at(WAN_WISHING, zx, zy);
52 mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of it */
984263bc
MD
53 }
54
55 for(x = 2; x < COLNO-1; x++)
56 for(y = 2; y < ROWNO-1; y++) {
57 switch(levl[x][y].typ) {
58 case HWALL:
59 levl[x][y].scrsym = '-';
60 break;
61 case ROOM:
62 levl[x][y].scrsym = '.';
63 break;
64 }
65 }
66 for(x = rn1(8,11); x; x--) {
67 mm = mazexy();
c7106d58 68 mkobj_at(rn2(2) ? GEM_SYM : 0, mm.x, mm.y);
984263bc
MD
69 }
70 for(x = rn1(10,2); x; x--) {
71 mm = mazexy();
c7106d58 72 mkobj_at(ROCK_SYM, mm.x, mm.y);
984263bc
MD
73 }
74 mm = mazexy();
c7106d58 75 makemon(PM_MINOTAUR, mm.x, mm.y);
984263bc
MD
76 for(x = rn1(5,7); x; x--) {
77 mm = mazexy();
c7106d58 78 makemon((struct permonst *) 0, mm.x, mm.y);
984263bc
MD
79 }
80 for(x = rn1(6,7); x; x--) {
81 mm = mazexy();
82 mkgold(0L,mm.x,mm.y);
83 }
84 for(x = rn1(6,7); x; x--)
85 mktrap(0,1,(struct mkroom *) 0);
86 mm = mazexy();
87 levl[(xupstair = mm.x)][(yupstair = mm.y)].scrsym = '<';
88 levl[xupstair][yupstair].typ = STAIRS;
89 xdnstair = ydnstair = 0;
90}
91
c7106d58
PA
92static void
93walkfrom(int x, int y)
94{
984263bc
MD
95int q,a,dir;
96int 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
c7106d58
PA
111static void
112move(int *x, int *y, int dir)
984263bc
MD
113{
114 switch(dir){
115 case 0: --(*y); break;
116 case 1: (*x)++; break;
117 case 2: (*y)++; break;
118 case 3: --(*x); break;
119 }
120}
121
c7106d58
PA
122static bool
123okay(int x, int y, int dir)
984263bc
MD
124{
125 move(&x,&y,dir);
126 move(&x,&y,dir);
127 if(x<3 || y<3 || x>COLNO-3 || y>ROWNO-3 || levl[x][y].typ != 0)
128 return(0);
129 else
130 return(1);
131}
132
133coord
c7106d58
PA
134mazexy(void)
135{
984263bc
MD
136 coord mm;
137 mm.x = 3 + 2*rn2(COLNO/2 - 2);
138 mm.y = 3 + 2*rn2(ROWNO/2 - 2);
139 return mm;
140}