]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.mkshop.c
8ec09f9c7d772a2ffed8922d90dcc50ba8bdccca
1 /* $NetBSD: hack.mkshop.c,v 1.6 2001/03/25 20:44:01 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.mkshop.c,v 1.6 2001/03/25 20:44:01 jsm Exp $");
16 #include "def.mkroom.h"
18 #define ESHK ((struct eshk *)(&(shk->mextra[0])))
19 const schar shprobs
[] = {3, 3, 5, 5, 10, 10, 14, 50}; /* their probabilities */
25 int sh
, sx
, sy
, i
= -1;
30 /* first determine shoptype */
32 char *ep
= getenv("SHOPTYPE");
34 if (*ep
== 'z' || *ep
== 'Z') {
38 if (*ep
== 'm' || *ep
== 'M') {
42 if (*ep
== 'b' || *ep
== 'B') {
46 if (*ep
== 's' || *ep
== 'S') {
50 for (i
= 0; shtypes
[i
]; i
++)
51 if (*ep
== shtypes
[i
])
58 for (sroom
= &rooms
[0], roomno
= 0;; sroom
++, roomno
++) {
61 if (sroom
- rooms
>= nroom
) {
62 pline("rooms not closed by -1?");
67 if (!sroom
->rlit
|| has_dnstairs(sroom
) || has_upstairs(sroom
))
71 (wizard
&& getenv("SHOPTYPE") && sroom
->doorct
!= 0) ||
73 (sroom
->doorct
<= 2 && sroom
->doorct
> 0))
77 if (i
< 0) { /* shoptype not yet determined */
80 for (j
= rn2(100), i
= 0; (j
-= shprobs
[i
]) >= 0; i
++)
82 break; /* superfluous */
83 if (isbig(sroom
) && i
+ SHOPBASE
== WANDSHOP
)
84 i
= GENERAL
- SHOPBASE
;
86 sroom
->rtype
= i
+ SHOPBASE
;
91 if (sx
== sroom
->lx
- 1)
93 else if (sx
== sroom
->hx
+ 1)
95 else if (sy
== sroom
->ly
- 1)
97 else if (sy
== sroom
->hy
+ 1)
101 /* This is said to happen sometimes, but I've never seen it. */
103 int j
= sroom
->doorct
;
105 pline("Where is shopdoor?");
106 pline("Room at (%d,%d),(%d,%d).", sroom
->lx
, sroom
->ly
,
107 sroom
->hx
, sroom
->hy
);
108 pline("doormax=%d doorct=%d fdoor=%d",
109 doorindex
, sroom
->doorct
, sh
);
111 pline("door [%d,%d]", doors
[sh
].x
, doors
[sh
].y
);
119 if (!(shk
= makemon(PM_SHK
, sx
, sy
)))
121 shk
->isshk
= shk
->mpeaceful
= 1;
123 shk
->mtrapseen
= ~0; /* we know all the traps already */
124 ESHK
->shoproom
= roomno
;
125 ESHK
->shoplevel
= dlevel
;
126 ESHK
->shd
= doors
[sh
];
132 shk
->mgold
= 1000 + 30 * rnd(100); /* initial capital */
134 findname(ESHK
->shknam
, let
);
135 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
136 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++) {
138 if ((sx
== sroom
->lx
&& doors
[sh
].x
== sx
- 1) ||
139 (sx
== sroom
->hx
&& doors
[sh
].x
== sx
+ 1) ||
140 (sy
== sroom
->ly
&& doors
[sh
].y
== sy
- 1) ||
141 (sy
== sroom
->hy
&& doors
[sh
].y
== sy
+ 1))
143 if (rn2(100) < dlevel
&& !m_at(sx
, sy
) &&
144 (mtmp
= makemon(PM_MIMIC
, sx
, sy
))) {
147 (let
&& rn2(10) < dlevel
) ? let
: ']';
150 (void) mkobj_at(let
, sx
, sy
);
158 struct mkroom
*sroom
;
161 int goldlim
= 500 * dlevel
;
165 for (sroom
= &rooms
[rn2(nroom
)];; sroom
++) {
166 if (sroom
== &rooms
[nroom
])
168 if (!i
-- || sroom
->hx
< 0)
172 if (type
== MORGUE
&& sroom
->rlit
)
174 if (has_upstairs(sroom
) || (has_dnstairs(sroom
) && rn2(3)))
176 if (sroom
->doorct
== 1 || !rn2(5))
181 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
182 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++) {
183 if ((sx
== sroom
->lx
&& doors
[sh
].x
== sx
- 1) ||
184 (sx
== sroom
->hx
&& doors
[sh
].x
== sx
+ 1) ||
185 (sy
== sroom
->ly
&& doors
[sh
].y
== sy
- 1) ||
186 (sy
== sroom
->hy
&& doors
[sh
].y
== sy
+ 1))
189 (type
== MORGUE
) ? morguemon() :
190 (type
== BEEHIVE
) ? PM_KILLER_BEE
: (struct permonst
*) 0,
196 i
= sq(dist2(sx
, sy
, doors
[sh
].x
, doors
[sh
].y
));
200 mkgold((long) (10 + rn2(i
)), sx
, sy
);
204 * Usually there is one dead body in the
207 if (!moct
&& rn2(3)) {
208 mksobj_at(CORPSE
, sx
, sy
);
214 mksobj_at(LUMP_OF_ROYAL_JELLY
, sx
, sy
);
220 const struct permonst
*
223 int i
= rn2(100), hd
= rn2(dlevel
);
225 if (hd
> 10 && i
< 10)
227 if (hd
> 8 && i
> 85)
229 return ((i
< 40) ? PM_GHOST
: (i
< 60) ? PM_WRAITH
: PM_ZOMBIE
);
234 { /* Michiel Huisjes & Fred de Wilde */
235 struct mkroom
*sroom
;
236 int sx
, sy
, i
, eelct
= 0;
238 for (i
= 0; i
< 5; i
++) { /* 5 tries */
239 sroom
= &rooms
[rn2(nroom
)];
240 if (sroom
->hx
< 0 || sroom
->rtype
||
241 has_upstairs(sroom
) || has_dnstairs(sroom
))
244 /* satisfied; make a swamp */
245 sroom
->rtype
= SWAMP
;
246 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
247 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++)
248 if ((sx
+ sy
) % 2 && !o_at(sx
, sy
) && !t_at(sx
, sy
)
249 && !m_at(sx
, sy
) && !nexttodoor(sx
, sy
)) {
250 levl
[sx
][sy
].typ
= POOL
;
251 levl
[sx
][sy
].scrsym
= POOL_SYM
;
252 if (!eelct
|| !rn2(4)) {
253 (void) makemon(PM_EEL
, sx
, sy
);
266 for (dx
= -1; dx
<= 1; dx
++)
267 for (dy
= -1; dy
<= 1; dy
++)
268 if ((lev
= &levl
[sx
+ dx
][sy
+ dy
])->typ
== DOOR
||
269 lev
->typ
== SDOOR
|| lev
->typ
== LDOOR
)
276 struct mkroom
*sroom
;
278 return (sroom
->lx
<= xdnstair
&& xdnstair
<= sroom
->hx
&&
279 sroom
->ly
<= ydnstair
&& ydnstair
<= sroom
->hy
);
284 struct mkroom
*sroom
;
286 return (sroom
->lx
<= xupstair
&& xupstair
<= sroom
->hx
&&
287 sroom
->ly
<= yupstair
&& yupstair
<= sroom
->hy
);
292 struct mkroom
*sroom
;
294 int area
= (sroom
->hx
- sroom
->lx
) * (sroom
->hy
- sroom
->ly
);
299 dist2(x0
, y0
, x1
, y1
)
302 return ((x0
- x1
) * (x0
- x1
) + (y0
- y1
) * (y0
- y1
));