]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.mkshop.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.mkshop.c,v 1.4 1995/03/23 08:30:50 cgd Exp $";
12 #include "def.mkroom.h"
14 #define ESHK ((struct eshk *)(&(shk->mextra[0])))
15 extern struct monst
*makemon();
16 extern struct obj
*mkobj_at();
18 extern char shtypes
[]; /* = "=/)%?!["; 8 types: 7 specialized, 1 mixed */
19 schar shprobs
[] = { 3,3,5,5,10,10,14,50 }; /* their probabilities */
22 register struct mkroom
*sroom
;
23 register int sh
,sx
,sy
,i
= -1;
26 register struct monst
*shk
;
28 /* first determine shoptype */
30 register char *ep
= getenv("SHOPTYPE");
32 if(*ep
== 'z' || *ep
== 'Z'){
36 if(*ep
== 'm' || *ep
== 'M'){
40 if(*ep
== 'b' || *ep
== 'B'){
44 if(*ep
== 's' || *ep
== 'S'){
48 for(i
=0; shtypes
[i
]; i
++)
49 if(*ep
== shtypes
[i
]) break;
55 for(sroom
= &rooms
[0], roomno
= 0; ; sroom
++, roomno
++){
56 if(sroom
->hx
< 0) return;
57 if(sroom
- rooms
>= nroom
) {
58 pline("rooms not closed by -1?");
61 if(sroom
->rtype
) continue;
62 if(!sroom
->rlit
|| has_dnstairs(sroom
) || has_upstairs(sroom
))
66 (wizard
&& getenv("SHOPTYPE") && sroom
->doorct
!= 0) ||
68 sroom
->doorct
<= 2 && sroom
->doorct
> 0) break;
71 if(i
< 0) { /* shoptype not yet determined */
74 for(j
= rn2(100), i
= 0; (j
-= shprobs
[i
])>= 0; i
++)
75 if(!shtypes
[i
]) break; /* superfluous */
76 if(isbig(sroom
) && i
+ SHOPBASE
== WANDSHOP
)
79 sroom
->rtype
= i
+ SHOPBASE
;
84 if(sx
== sroom
->lx
-1) sx
++; else
85 if(sx
== sroom
->hx
+1) sx
--; else
86 if(sy
== sroom
->ly
-1) sy
++; else
87 if(sy
== sroom
->hy
+1) sy
--; else {
89 /* This is said to happen sometimes, but I've never seen it. */
91 register int j
= sroom
->doorct
;
94 pline("Where is shopdoor?");
95 pline("Room at (%d,%d),(%d,%d).", sroom
->lx
, sroom
->ly
,
96 sroom
->hx
, sroom
->hy
);
97 pline("doormax=%d doorct=%d fdoor=%d",
98 doorindex
, sroom
->doorct
, sh
);
100 pline("door [%d,%d]", doors
[sh
].x
, doors
[sh
].y
);
108 if(!(shk
= makemon(PM_SHK
,sx
,sy
))) return;
109 shk
->isshk
= shk
->mpeaceful
= 1;
111 shk
->mtrapseen
= ~0; /* we know all the traps already */
112 ESHK
->shoproom
= roomno
;
113 ESHK
->shoplevel
= dlevel
;
114 ESHK
->shd
= doors
[sh
];
120 shk
->mgold
= 1000 + 30*rnd(100); /* initial capital */
122 findname(ESHK
->shknam
, let
);
123 for(sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
124 for(sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++){
125 register struct monst
*mtmp
;
126 if((sx
== sroom
->lx
&& doors
[sh
].x
== sx
-1) ||
127 (sx
== sroom
->hx
&& doors
[sh
].x
== sx
+1) ||
128 (sy
== sroom
->ly
&& doors
[sh
].y
== sy
-1) ||
129 (sy
== sroom
->hy
&& doors
[sh
].y
== sy
+1)) continue;
130 if(rn2(100) < dlevel
&& !m_at(sx
,sy
) &&
131 (mtmp
= makemon(PM_MIMIC
, sx
, sy
))){
134 (let
&& rn2(10) < dlevel
) ? let
: ']';
137 (void) mkobj_at(let
, sx
, sy
);
144 register struct mkroom
*sroom
;
145 register struct monst
*mon
;
146 register int sh
,sx
,sy
,i
;
147 int goldlim
= 500 * dlevel
;
149 struct permonst
*morguemon();
152 for(sroom
= &rooms
[rn2(nroom
)]; ; sroom
++) {
153 if(sroom
== &rooms
[nroom
])
155 if(!i
-- || sroom
->hx
< 0)
159 if(type
== MORGUE
&& sroom
->rlit
)
161 if(has_upstairs(sroom
) || (has_dnstairs(sroom
) && rn2(3)))
163 if(sroom
->doorct
== 1 || !rn2(5))
168 for(sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
169 for(sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++){
170 if((sx
== sroom
->lx
&& doors
[sh
].x
== sx
-1) ||
171 (sx
== sroom
->hx
&& doors
[sh
].x
== sx
+1) ||
172 (sy
== sroom
->ly
&& doors
[sh
].y
== sy
-1) ||
173 (sy
== sroom
->hy
&& doors
[sh
].y
== sy
+1)) continue;
175 (type
== MORGUE
) ? morguemon() :
176 (type
== BEEHIVE
) ? PM_KILLER_BEE
: (struct permonst
*) 0,
178 if(mon
) mon
->msleep
= 1;
181 i
= sq(dist2(sx
,sy
,doors
[sh
].x
,doors
[sh
].y
));
182 if(i
>= goldlim
) i
= 5*dlevel
;
184 mkgold((long)(10 + rn2(i
)), sx
, sy
);
187 /* Usually there is one dead body in the morgue */
188 if(!moct
&& rn2(3)) {
189 mksobj_at(CORPSE
, sx
, sy
);
194 if(!rn2(3)) mksobj_at(LUMP_OF_ROYAL_JELLY
, sx
, sy
);
203 extern struct permonst pm_ghost
;
204 register int i
= rn2(100), hd
= rn2(dlevel
);
206 if(hd
> 10 && i
< 10) return(PM_DEMON
);
207 if(hd
> 8 && i
> 85) return(PM_VAMPIRE
);
208 return((i
< 40) ? PM_GHOST
: (i
< 60) ? PM_WRAITH
: PM_ZOMBIE
);
211 mkswamp() /* Michiel Huisjes & Fred de Wilde */
213 register struct mkroom
*sroom
;
214 register int sx
,sy
,i
,eelct
= 0;
215 extern struct permonst pm_eel
;
217 for(i
=0; i
<5; i
++) { /* 5 tries */
218 sroom
= &rooms
[rn2(nroom
)];
219 if(sroom
->hx
< 0 || sroom
->rtype
||
220 has_upstairs(sroom
) || has_dnstairs(sroom
))
223 /* satisfied; make a swamp */
224 sroom
->rtype
= SWAMP
;
225 for(sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
226 for(sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++)
227 if((sx
+sy
)%2
&& !o_at(sx
,sy
) && !t_at(sx
,sy
)
228 && !m_at(sx
,sy
) && !nexttodoor(sx
,sy
)){
229 levl
[sx
][sy
].typ
= POOL
;
230 levl
[sx
][sy
].scrsym
= POOL_SYM
;
231 if(!eelct
|| !rn2(4)) {
232 (void) makemon(PM_EEL
, sx
, sy
);
243 register struct rm
*lev
;
244 for(dx
= -1; dx
<= 1; dx
++) for(dy
= -1; dy
<= 1; dy
++)
245 if((lev
= &levl
[sx
+dx
][sy
+dy
])->typ
== DOOR
||
246 lev
->typ
== SDOOR
|| lev
->typ
== LDOOR
)
252 register struct mkroom
*sroom
;
254 return(sroom
->lx
<= xdnstair
&& xdnstair
<= sroom
->hx
&&
255 sroom
->ly
<= ydnstair
&& ydnstair
<= sroom
->hy
);
259 register struct mkroom
*sroom
;
261 return(sroom
->lx
<= xupstair
&& xupstair
<= sroom
->hx
&&
262 sroom
->ly
<= yupstair
&& yupstair
<= sroom
->hy
);
266 register struct mkroom
*sroom
;
268 register int area
= (sroom
->hx
- sroom
->lx
) * (sroom
->hy
- sroom
->ly
);
273 return((x0
-x1
)*(x0
-x1
) + (y0
-y1
)*(y0
-y1
));