1 /* $NetBSD: hack.mkshop.c,v 1.9 2009/06/07 18:30:39 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.mkshop.c,v 1.9 2009/06/07 18:30:39 dholland Exp $");
73 #include "def.mkroom.h"
76 #define ESHK ((struct eshk *)(&(shk->mextra[0])))
78 /* their probabilities */
79 static const schar shprobs
[] = {3, 3, 5, 5, 10, 10, 14, 50};
81 static const struct permonst
*morguemon(void);
82 static int nexttodoor(int, int);
83 static int has_dnstairs(struct mkroom
*);
84 static int has_upstairs(struct mkroom
*);
85 static int isbig(struct mkroom
*);
86 static int dist2(int, int, int, int);
93 int sh
, sx
, sy
, i
= -1;
98 /* first determine shoptype */
100 char *ep
= getenv("SHOPTYPE");
102 if (*ep
== 'z' || *ep
== 'Z') {
106 if (*ep
== 'm' || *ep
== 'M') {
110 if (*ep
== 'b' || *ep
== 'B') {
114 if (*ep
== 's' || *ep
== 'S') {
118 for (i
= 0; shtypes
[i
]; i
++)
119 if (*ep
== shtypes
[i
])
126 for (sroom
= &rooms
[0], roomno
= 0;; sroom
++, roomno
++) {
129 if (sroom
- rooms
>= nroom
) {
130 pline("rooms not closed by -1?");
135 if (!sroom
->rlit
|| has_dnstairs(sroom
) || has_upstairs(sroom
))
139 (wizard
&& getenv("SHOPTYPE") && sroom
->doorct
!= 0) ||
145 if (i
< 0) { /* shoptype not yet determined */
148 for (j
= rn2(100), i
= 0; (j
-= shprobs
[i
]) >= 0; i
++)
150 break; /* superfluous */
151 if (isbig(sroom
) && i
+ SHOPBASE
== WANDSHOP
)
152 i
= GENERAL
- SHOPBASE
;
154 sroom
->rtype
= i
+ SHOPBASE
;
159 if (sx
== sroom
->lx
- 1)
161 else if (sx
== sroom
->hx
+ 1)
163 else if (sy
== sroom
->ly
- 1)
165 else if (sy
== sroom
->hy
+ 1)
169 /* This is said to happen sometimes, but I've never seen it. */
171 int j
= sroom
->doorct
;
173 pline("Where is shopdoor?");
174 pline("Room at (%d,%d),(%d,%d).", sroom
->lx
, sroom
->ly
,
175 sroom
->hx
, sroom
->hy
);
176 pline("doormax=%d doorct=%d fdoor=%d",
177 doorindex
, sroom
->doorct
, sh
);
179 pline("door [%d,%d]", doors
[sh
].x
, doors
[sh
].y
);
187 if (!(shk
= makemon(PM_SHK
, sx
, sy
)))
189 shk
->isshk
= shk
->mpeaceful
= 1;
191 shk
->mtrapseen
= ~0; /* we know all the traps already */
192 ESHK
->shoproom
= roomno
;
193 ESHK
->shoplevel
= dlevel
;
194 ESHK
->shd
= doors
[sh
];
200 shk
->mgold
= 1000 + 30 * rnd(100); /* initial capital */
202 findname(ESHK
->shknam
, let
);
203 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
204 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++) {
206 if ((sx
== sroom
->lx
&& doors
[sh
].x
== sx
- 1) ||
207 (sx
== sroom
->hx
&& doors
[sh
].x
== sx
+ 1) ||
208 (sy
== sroom
->ly
&& doors
[sh
].y
== sy
- 1) ||
209 (sy
== sroom
->hy
&& doors
[sh
].y
== sy
+ 1))
211 if (rn2(100) < dlevel
&& !m_at(sx
, sy
) &&
212 (mtmp
= makemon(PM_MIMIC
, sx
, sy
))) {
215 (let
&& rn2(10) < dlevel
) ? let
: ']';
218 (void) mkobj_at(let
, sx
, sy
);
225 struct mkroom
*sroom
;
228 int goldlim
= 500 * dlevel
;
232 for (sroom
= &rooms
[rn2(nroom
)];; sroom
++) {
233 if (sroom
== &rooms
[nroom
])
235 if (!i
-- || sroom
->hx
< 0)
239 if (type
== MORGUE
&& sroom
->rlit
)
241 if (has_upstairs(sroom
) || (has_dnstairs(sroom
) && rn2(3)))
243 if (sroom
->doorct
== 1 || !rn2(5))
248 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
249 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++) {
250 if ((sx
== sroom
->lx
&& doors
[sh
].x
== sx
- 1) ||
251 (sx
== sroom
->hx
&& doors
[sh
].x
== sx
+ 1) ||
252 (sy
== sroom
->ly
&& doors
[sh
].y
== sy
- 1) ||
253 (sy
== sroom
->hy
&& doors
[sh
].y
== sy
+ 1))
256 (type
== MORGUE
) ? morguemon() :
257 (type
== BEEHIVE
) ? PM_KILLER_BEE
: (struct permonst
*) 0,
263 i
= sq(dist2(sx
, sy
, doors
[sh
].x
, doors
[sh
].y
));
267 mkgold((long) (10 + rn2(i
)), sx
, sy
);
271 * Usually there is one dead body in the
274 if (!moct
&& rn2(3)) {
275 mksobj_at(CORPSE
, sx
, sy
);
281 mksobj_at(LUMP_OF_ROYAL_JELLY
, sx
, sy
);
287 static const struct permonst
*
290 int i
= rn2(100), hd
= rn2(dlevel
);
292 if (hd
> 10 && i
< 10)
294 if (hd
> 8 && i
> 85)
296 return ((i
< 40) ? PM_GHOST
: (i
< 60) ? PM_WRAITH
: PM_ZOMBIE
);
301 { /* Michiel Huisjes & Fred de Wilde */
302 struct mkroom
*sroom
;
303 int sx
, sy
, i
, eelct
= 0;
305 for (i
= 0; i
< 5; i
++) { /* 5 tries */
306 sroom
= &rooms
[rn2(nroom
)];
307 if (sroom
->hx
< 0 || sroom
->rtype
||
308 has_upstairs(sroom
) || has_dnstairs(sroom
))
311 /* satisfied; make a swamp */
312 sroom
->rtype
= SWAMP
;
313 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
314 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++)
315 if ((sx
+ sy
) % 2 && !o_at(sx
, sy
) && !t_at(sx
, sy
)
316 && !m_at(sx
, sy
) && !nexttodoor(sx
, sy
)) {
317 levl
[sx
][sy
].typ
= POOL
;
318 levl
[sx
][sy
].scrsym
= POOL_SYM
;
319 if (!eelct
|| !rn2(4)) {
320 (void) makemon(PM_EEL
, sx
, sy
);
328 nexttodoor(int sx
, int sy
)
332 for (dx
= -1; dx
<= 1; dx
++)
333 for (dy
= -1; dy
<= 1; dy
++)
334 if ((lev
= &levl
[sx
+ dx
][sy
+ dy
])->typ
== DOOR
||
335 lev
->typ
== SDOOR
|| lev
->typ
== LDOOR
)
341 has_dnstairs(struct mkroom
*sroom
)
343 return (sroom
->lx
<= xdnstair
&& xdnstair
<= sroom
->hx
&&
344 sroom
->ly
<= ydnstair
&& ydnstair
<= sroom
->hy
);
348 has_upstairs(struct mkroom
*sroom
)
350 return (sroom
->lx
<= xupstair
&& xupstair
<= sroom
->hx
&&
351 sroom
->ly
<= yupstair
&& yupstair
<= sroom
->hy
);
355 isbig(struct mkroom
*sroom
)
357 int area
= (sroom
->hx
- sroom
->lx
) * (sroom
->hy
- sroom
->ly
);
362 dist2(int x0
, int y0
, int x1
, int y1
)
364 return ((x0
- x1
) * (x0
- x1
) + (y0
- y1
) * (y0
- y1
));