1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.mkshop.c - version 1.0.3 */
7 #include "def.mkroom.h"
10 #define ESHK ((struct eshk *)(&(shk->mextra[0])))
11 extern struct monst *makemon();
12 extern struct obj *mkobj_at();
14 extern char shtypes[]; /* = "=/)%?!["; 8 types: 7 specialized, 1 mixed */
15 schar shprobs[] = { 3,3,5,5,10,10,14,50 }; /* their probabilities */
24 /* first determine shoptype */
26 char *ep = getenv("SHOPTYPE");
28 if(*ep == 'z' || *ep == 'Z'){
32 if(*ep == 'm' || *ep == 'M'){
36 if(*ep == 'b' || *ep == 'B'){
40 if(*ep == 's' || *ep == 'S'){
44 for(i=0; shtypes[i]; i++)
45 if(*ep == shtypes[i]) break;
51 for(sroom = &rooms[0], roomno = 0; ; sroom++, roomno++){
52 if(sroom->hx < 0) return;
53 if(sroom - rooms >= nroom) {
54 pline("rooms not closed by -1?");
57 if(sroom->rtype) continue;
58 if(!sroom->rlit || has_dnstairs(sroom) || has_upstairs(sroom))
62 (wizard && getenv("SHOPTYPE") && sroom->doorct != 0) ||
64 sroom->doorct <= 2 && sroom->doorct > 0) break;
67 if(i < 0) { /* shoptype not yet determined */
70 for(j = rn2(100), i = 0; (j -= shprobs[i])>= 0; i++)
71 if(!shtypes[i]) break; /* superfluous */
72 if(isbig(sroom) && i + SHOPBASE == WANDSHOP)
75 sroom->rtype = i + SHOPBASE;
80 if(sx == sroom->lx-1) sx++; else
81 if(sx == sroom->hx+1) sx--; else
82 if(sy == sroom->ly-1) sy++; else
83 if(sy == sroom->hy+1) sy--; else {
85 /* This is said to happen sometimes, but I've never seen it. */
87 int j = sroom->doorct;
90 pline("Where is shopdoor?");
91 pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly,
92 sroom->hx, sroom->hy);
93 pline("doormax=%d doorct=%d fdoor=%d",
94 doorindex, sroom->doorct, sh);
96 pline("door [%d,%d]", doors[sh].x, doors[sh].y);
104 if(!(shk = makemon(PM_SHK,sx,sy))) return;
105 shk->isshk = shk->mpeaceful = 1;
107 shk->mtrapseen = ~0; /* we know all the traps already */
108 ESHK->shoproom = roomno;
109 ESHK->shoplevel = dlevel;
110 ESHK->shd = doors[sh];
116 shk->mgold = 1000 + 30*rnd(100); /* initial capital */
118 findname(ESHK->shknam, let);
119 for(sx = sroom->lx; sx <= sroom->hx; sx++)
120 for(sy = sroom->ly; sy <= sroom->hy; sy++){
122 if((sx == sroom->lx && doors[sh].x == sx-1) ||
123 (sx == sroom->hx && doors[sh].x == sx+1) ||
124 (sy == sroom->ly && doors[sh].y == sy-1) ||
125 (sy == sroom->hy && doors[sh].y == sy+1)) continue;
126 if(rn2(100) < dlevel && !m_at(sx,sy) &&
127 (mtmp = makemon(PM_MIMIC, sx, sy))){
130 (let && rn2(10) < dlevel) ? let : ']';
133 (void) mkobj_at(let, sx, sy);
140 struct mkroom *sroom;
143 int goldlim = 500 * dlevel;
145 struct permonst *morguemon();
148 for(sroom = &rooms[rn2(nroom)]; ; sroom++) {
149 if(sroom == &rooms[nroom])
151 if(!i-- || sroom->hx < 0)
155 if(type == MORGUE && sroom->rlit)
157 if(has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3)))
159 if(sroom->doorct == 1 || !rn2(5))
164 for(sx = sroom->lx; sx <= sroom->hx; sx++)
165 for(sy = sroom->ly; sy <= sroom->hy; sy++){
166 if((sx == sroom->lx && doors[sh].x == sx-1) ||
167 (sx == sroom->hx && doors[sh].x == sx+1) ||
168 (sy == sroom->ly && doors[sh].y == sy-1) ||
169 (sy == sroom->hy && doors[sh].y == sy+1)) continue;
171 (type == MORGUE) ? morguemon() :
172 (type == BEEHIVE) ? PM_KILLER_BEE : (struct permonst *) 0,
174 if(mon) mon->msleep = 1;
177 i = sq(dist2(sx,sy,doors[sh].x,doors[sh].y));
178 if(i >= goldlim) i = 5*dlevel;
180 mkgold((long)(10 + rn2(i)), sx, sy);
183 /* Usually there is one dead body in the morgue */
184 if(!moct && rn2(3)) {
185 mksobj_at(CORPSE, sx, sy);
190 if(!rn2(3)) mksobj_at(LUMP_OF_ROYAL_JELLY, sx, sy);
199 extern struct permonst pm_ghost;
200 int i = rn2(100), hd = rn2(dlevel);
202 if(hd > 10 && i < 10) return(PM_DEMON);
203 if(hd > 8 && i > 85) return(PM_VAMPIRE);
204 return((i < 40) ? PM_GHOST : (i < 60) ? PM_WRAITH : PM_ZOMBIE);
207 mkswamp() /* Michiel Huisjes & Fred de Wilde */
209 struct mkroom *sroom;
210 int sx,sy,i,eelct = 0;
211 extern struct permonst pm_eel;
213 for(i=0; i<5; i++) { /* 5 tries */
214 sroom = &rooms[rn2(nroom)];
215 if(sroom->hx < 0 || sroom->rtype ||
216 has_upstairs(sroom) || has_dnstairs(sroom))
219 /* satisfied; make a swamp */
220 sroom->rtype = SWAMP;
221 for(sx = sroom->lx; sx <= sroom->hx; sx++)
222 for(sy = sroom->ly; sy <= sroom->hy; sy++)
223 if((sx+sy)%2 && !o_at(sx,sy) && !t_at(sx,sy)
224 && !m_at(sx,sy) && !nexttodoor(sx,sy)){
225 levl[sx][sy].typ = POOL;
226 levl[sx][sy].scrsym = POOL_SYM;
227 if(!eelct || !rn2(4)) {
228 (void) makemon(PM_EEL, sx, sy);
240 for(dx = -1; dx <= 1; dx++) for(dy = -1; dy <= 1; dy++)
241 if((lev = &levl[sx+dx][sy+dy])->typ == DOOR ||
242 lev->typ == SDOOR || lev->typ == LDOOR)
248 struct mkroom *sroom;
250 return(sroom->lx <= xdnstair && xdnstair <= sroom->hx &&
251 sroom->ly <= ydnstair && ydnstair <= sroom->hy);
255 struct mkroom *sroom;
257 return(sroom->lx <= xupstair && xupstair <= sroom->hx &&
258 sroom->ly <= yupstair && yupstair <= sroom->hy);
262 struct mkroom *sroom;
264 int area = (sroom->hx - sroom->lx) * (sroom->hy - sroom->ly);
269 return((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));