1 /* $NetBSD: hack.makemon.c,v 1.8 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.makemon.c,v 1.8 2009/06/07 18:30:39 dholland Exp $");
72 static const struct monst zeromonst
;
75 * called with [x,y] = coordinates;
76 * [0,0] means anyplace
77 * [u.ux,u.uy] means: call mnexto (if !in_mklev)
79 * In case we make an Orc or killer bee, we make an entire horde (swarm);
80 * note that in this case we return only one of them (the one at [x,y]).
83 makemon(const struct permonst
*ptr
, int x
, int y
)
88 boolean anything
= (!ptr
);
92 return ((struct monst
*) 0);
94 if (strchr(fut_geno
, ptr
->mlet
))
95 return ((struct monst
*) 0);
97 ct
= CMNUM
- strlen(fut_geno
);
98 if (strchr(fut_geno
, 'm'))
99 ct
++; /* make only 1 minotaur */
100 if (strchr(fut_geno
, '@'))
103 return (0); /* no more monsters! */
104 tmp
= rn2(ct
* dlevel
/ 24 + 7);
105 if (tmp
< dlevel
- 4)
106 tmp
= rn2(ct
* dlevel
/ 24 + 12);
108 tmp
= rn1(ct
- ct
/ 2, ct
/ 2);
109 for (ct
= 0; ct
< CMNUM
; ct
++) {
111 if (strchr(fut_geno
, ptr
->mlet
))
119 mtmp
= newmonst(ptr
->pxlth
);
120 *mtmp
= zeromonst
; /* clear all entries in structure */
121 for (i
= 0; i
< ptr
->pxlth
; i
++)
122 ((char *) &(mtmp
->mextra
[0]))[i
] = 0;
125 mtmp
->m_id
= flags
.ident
++;
127 mtmp
->mxlth
= ptr
->pxlth
;
128 if (ptr
->mlet
== 'D')
129 mtmp
->mhpmax
= mtmp
->mhp
= 80;
130 else if (!ptr
->mlevel
)
131 mtmp
->mhpmax
= mtmp
->mhp
= rnd(4);
133 mtmp
->mhpmax
= mtmp
->mhp
= d(ptr
->mlevel
, 8);
137 if (ptr
->mlet
== 'M') {
139 mtmp
->mappearance
= ']';
142 if (x
== u
.ux
&& y
== u
.uy
&& ptr
->mlet
!= ' ')
144 if (x
== 0 && y
== 0)
147 if (ptr
->mlet
== 's' || ptr
->mlet
== 'S') {
148 mtmp
->mhide
= mtmp
->mundetected
= 1;
150 if (mtmp
->mx
&& mtmp
->my
)
151 (void) mkobj_at(0, mtmp
->mx
, mtmp
->my
);
153 if (ptr
->mlet
== ':') {
155 (void) newcham(mtmp
, &mons
[dlevel
+ 14 + rn2(CMNUM
- 14 - dlevel
)]);
157 if (ptr
->mlet
== 'I' || ptr
->mlet
== ';')
159 if (ptr
->mlet
== 'L' || ptr
->mlet
== 'N'
160 || (in_mklev
&& strchr("&w;", ptr
->mlet
) && rn2(5))
165 if (ptr
->mlet
== 'w' && getwn(mtmp
))
170 if (ptr
->mlet
== 'O' || ptr
->mlet
== 'k') {
176 mm
= enexto(mm
.x
, mm
.y
);
177 (void) makemon(ptr
, mm
.x
, mm
.y
);
184 enexto(xchar xx
, xchar yy
)
187 coord foo
[15], *tfoo
;
192 do { /* full kludge action. */
193 for (x
= xx
- range
; x
<= xx
+ range
; x
++)
194 if (goodpos(x
, yy
- range
)) {
196 tfoo
++->y
= yy
- range
;
197 if (tfoo
== &foo
[15])
200 for (x
= xx
- range
; x
<= xx
+ range
; x
++)
201 if (goodpos(x
, yy
+ range
)) {
203 tfoo
++->y
= yy
+ range
;
204 if (tfoo
== &foo
[15])
207 for (y
= yy
+ 1 - range
; y
< yy
+ range
; y
++)
208 if (goodpos(xx
- range
, y
)) {
209 tfoo
->x
= xx
- range
;
211 if (tfoo
== &foo
[15])
214 for (y
= yy
+ 1 - range
; y
< yy
+ range
; y
++)
215 if (goodpos(xx
+ range
, y
)) {
216 tfoo
->x
= xx
+ range
;
218 if (tfoo
== &foo
[15])
222 } while (tfoo
== foo
);
224 return (foo
[rn2(tfoo
- foo
)]);
228 goodpos(int x
, int y
)
229 { /* used only in mnexto and rloc */
231 !(x
< 1 || x
> COLNO
- 2 || y
< 1 || y
> ROWNO
- 2 ||
232 m_at(x
, y
) || !ACCESSIBLE(levl
[x
][y
].typ
)
233 || (x
== u
.ux
&& y
== u
.uy
)
234 || sobj_at(ENORMOUS_ROCK
, x
, y
)
239 rloc(struct monst
*mtmp
)
242 char ch
= mtmp
->data
->mlet
;
245 if (ch
== 'w' && mtmp
->mx
)
246 return; /* do not relocate worms */
249 tx
= rn1(COLNO
- 3, 2);
251 } while (!goodpos(tx
, ty
));
254 if (u
.ustuck
== mtmp
) {
266 mkmon_at(int let
, int x
, int y
)
269 const struct permonst
*ptr
;
271 for (ct
= 0; ct
< CMNUM
; ct
++) {
273 if (ptr
->mlet
== let
)
274 return (makemon(ptr
, x
, y
));