]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.mkshop.c
1 /* $NetBSD: hack.mkshop.c,v 1.8 2003/04/02 18:36:38 jsm 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.8 2003/04/02 18:36:38 jsm Exp $");
73 #include "def.mkroom.h"
75 #define ESHK ((struct eshk *)(&(shk->mextra[0])))
76 const schar shprobs
[] = {3, 3, 5, 5, 10, 10, 14, 50}; /* their probabilities */
82 int sh
, sx
, sy
, i
= -1;
87 /* first determine shoptype */
89 char *ep
= getenv("SHOPTYPE");
91 if (*ep
== 'z' || *ep
== 'Z') {
95 if (*ep
== 'm' || *ep
== 'M') {
99 if (*ep
== 'b' || *ep
== 'B') {
103 if (*ep
== 's' || *ep
== 'S') {
107 for (i
= 0; shtypes
[i
]; i
++)
108 if (*ep
== shtypes
[i
])
115 for (sroom
= &rooms
[0], roomno
= 0;; sroom
++, roomno
++) {
118 if (sroom
- rooms
>= nroom
) {
119 pline("rooms not closed by -1?");
124 if (!sroom
->rlit
|| has_dnstairs(sroom
) || has_upstairs(sroom
))
128 (wizard
&& getenv("SHOPTYPE") && sroom
->doorct
!= 0) ||
134 if (i
< 0) { /* shoptype not yet determined */
137 for (j
= rn2(100), i
= 0; (j
-= shprobs
[i
]) >= 0; i
++)
139 break; /* superfluous */
140 if (isbig(sroom
) && i
+ SHOPBASE
== WANDSHOP
)
141 i
= GENERAL
- SHOPBASE
;
143 sroom
->rtype
= i
+ SHOPBASE
;
148 if (sx
== sroom
->lx
- 1)
150 else if (sx
== sroom
->hx
+ 1)
152 else if (sy
== sroom
->ly
- 1)
154 else if (sy
== sroom
->hy
+ 1)
158 /* This is said to happen sometimes, but I've never seen it. */
160 int j
= sroom
->doorct
;
162 pline("Where is shopdoor?");
163 pline("Room at (%d,%d),(%d,%d).", sroom
->lx
, sroom
->ly
,
164 sroom
->hx
, sroom
->hy
);
165 pline("doormax=%d doorct=%d fdoor=%d",
166 doorindex
, sroom
->doorct
, sh
);
168 pline("door [%d,%d]", doors
[sh
].x
, doors
[sh
].y
);
176 if (!(shk
= makemon(PM_SHK
, sx
, sy
)))
178 shk
->isshk
= shk
->mpeaceful
= 1;
180 shk
->mtrapseen
= ~0; /* we know all the traps already */
181 ESHK
->shoproom
= roomno
;
182 ESHK
->shoplevel
= dlevel
;
183 ESHK
->shd
= doors
[sh
];
189 shk
->mgold
= 1000 + 30 * rnd(100); /* initial capital */
191 findname(ESHK
->shknam
, let
);
192 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
193 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++) {
195 if ((sx
== sroom
->lx
&& doors
[sh
].x
== sx
- 1) ||
196 (sx
== sroom
->hx
&& doors
[sh
].x
== sx
+ 1) ||
197 (sy
== sroom
->ly
&& doors
[sh
].y
== sy
- 1) ||
198 (sy
== sroom
->hy
&& doors
[sh
].y
== sy
+ 1))
200 if (rn2(100) < dlevel
&& !m_at(sx
, sy
) &&
201 (mtmp
= makemon(PM_MIMIC
, sx
, sy
))) {
204 (let
&& rn2(10) < dlevel
) ? let
: ']';
207 (void) mkobj_at(let
, sx
, sy
);
215 struct mkroom
*sroom
;
218 int goldlim
= 500 * dlevel
;
222 for (sroom
= &rooms
[rn2(nroom
)];; sroom
++) {
223 if (sroom
== &rooms
[nroom
])
225 if (!i
-- || sroom
->hx
< 0)
229 if (type
== MORGUE
&& sroom
->rlit
)
231 if (has_upstairs(sroom
) || (has_dnstairs(sroom
) && rn2(3)))
233 if (sroom
->doorct
== 1 || !rn2(5))
238 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
239 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++) {
240 if ((sx
== sroom
->lx
&& doors
[sh
].x
== sx
- 1) ||
241 (sx
== sroom
->hx
&& doors
[sh
].x
== sx
+ 1) ||
242 (sy
== sroom
->ly
&& doors
[sh
].y
== sy
- 1) ||
243 (sy
== sroom
->hy
&& doors
[sh
].y
== sy
+ 1))
246 (type
== MORGUE
) ? morguemon() :
247 (type
== BEEHIVE
) ? PM_KILLER_BEE
: (struct permonst
*) 0,
253 i
= sq(dist2(sx
, sy
, doors
[sh
].x
, doors
[sh
].y
));
257 mkgold((long) (10 + rn2(i
)), sx
, sy
);
261 * Usually there is one dead body in the
264 if (!moct
&& rn2(3)) {
265 mksobj_at(CORPSE
, sx
, sy
);
271 mksobj_at(LUMP_OF_ROYAL_JELLY
, sx
, sy
);
277 const struct permonst
*
280 int i
= rn2(100), hd
= rn2(dlevel
);
282 if (hd
> 10 && i
< 10)
284 if (hd
> 8 && i
> 85)
286 return ((i
< 40) ? PM_GHOST
: (i
< 60) ? PM_WRAITH
: PM_ZOMBIE
);
291 { /* Michiel Huisjes & Fred de Wilde */
292 struct mkroom
*sroom
;
293 int sx
, sy
, i
, eelct
= 0;
295 for (i
= 0; i
< 5; i
++) { /* 5 tries */
296 sroom
= &rooms
[rn2(nroom
)];
297 if (sroom
->hx
< 0 || sroom
->rtype
||
298 has_upstairs(sroom
) || has_dnstairs(sroom
))
301 /* satisfied; make a swamp */
302 sroom
->rtype
= SWAMP
;
303 for (sx
= sroom
->lx
; sx
<= sroom
->hx
; sx
++)
304 for (sy
= sroom
->ly
; sy
<= sroom
->hy
; sy
++)
305 if ((sx
+ sy
) % 2 && !o_at(sx
, sy
) && !t_at(sx
, sy
)
306 && !m_at(sx
, sy
) && !nexttodoor(sx
, sy
)) {
307 levl
[sx
][sy
].typ
= POOL
;
308 levl
[sx
][sy
].scrsym
= POOL_SYM
;
309 if (!eelct
|| !rn2(4)) {
310 (void) makemon(PM_EEL
, sx
, sy
);
323 for (dx
= -1; dx
<= 1; dx
++)
324 for (dy
= -1; dy
<= 1; dy
++)
325 if ((lev
= &levl
[sx
+ dx
][sy
+ dy
])->typ
== DOOR
||
326 lev
->typ
== SDOOR
|| lev
->typ
== LDOOR
)
333 struct mkroom
*sroom
;
335 return (sroom
->lx
<= xdnstair
&& xdnstair
<= sroom
->hx
&&
336 sroom
->ly
<= ydnstair
&& ydnstair
<= sroom
->hy
);
341 struct mkroom
*sroom
;
343 return (sroom
->lx
<= xupstair
&& xupstair
<= sroom
->hx
&&
344 sroom
->ly
<= yupstair
&& yupstair
<= sroom
->hy
);
349 struct mkroom
*sroom
;
351 int area
= (sroom
->hx
- sroom
->lx
) * (sroom
->hy
- sroom
->ly
);
356 dist2(x0
, y0
, x1
, y1
)
359 return ((x0
- x1
) * (x0
- x1
) + (y0
- y1
) * (y0
- y1
));