1 /* $NetBSD: hack.makemon.c,v 1.9 2009/08/12 07:28:40 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.
67 static const struct monst zeromonst
;
70 * called with [x,y] = coordinates;
71 * [0,0] means anyplace
72 * [u.ux,u.uy] means: call mnexto (if !in_mklev)
74 * In case we make an Orc or killer bee, we make an entire horde (swarm);
75 * note that in this case we return only one of them (the one at [x,y]).
78 makemon(const struct permonst
*ptr
, int x
, int y
)
83 boolean anything
= (!ptr
);
87 return ((struct monst
*) 0);
89 if (strchr(fut_geno
, ptr
->mlet
))
90 return ((struct monst
*) 0);
92 ct
= CMNUM
- strlen(fut_geno
);
93 if (strchr(fut_geno
, 'm'))
94 ct
++; /* make only 1 minotaur */
95 if (strchr(fut_geno
, '@'))
98 return (0); /* no more monsters! */
99 tmp
= rn2(ct
* dlevel
/ 24 + 7);
100 if (tmp
< dlevel
- 4)
101 tmp
= rn2(ct
* dlevel
/ 24 + 12);
103 tmp
= rn1(ct
- ct
/ 2, ct
/ 2);
104 for (ct
= 0; ct
< CMNUM
; ct
++) {
106 if (strchr(fut_geno
, ptr
->mlet
))
114 mtmp
= newmonst(ptr
->pxlth
);
115 *mtmp
= zeromonst
; /* clear all entries in structure */
116 for (i
= 0; i
< ptr
->pxlth
; i
++)
117 ((char *) &(mtmp
->mextra
[0]))[i
] = 0;
120 mtmp
->m_id
= flags
.ident
++;
122 mtmp
->mxlth
= ptr
->pxlth
;
123 if (ptr
->mlet
== 'D')
124 mtmp
->mhpmax
= mtmp
->mhp
= 80;
125 else if (!ptr
->mlevel
)
126 mtmp
->mhpmax
= mtmp
->mhp
= rnd(4);
128 mtmp
->mhpmax
= mtmp
->mhp
= d(ptr
->mlevel
, 8);
132 if (ptr
->mlet
== 'M') {
134 mtmp
->mappearance
= ']';
137 if (x
== u
.ux
&& y
== u
.uy
&& ptr
->mlet
!= ' ')
139 if (x
== 0 && y
== 0)
142 if (ptr
->mlet
== 's' || ptr
->mlet
== 'S') {
143 mtmp
->mhide
= mtmp
->mundetected
= 1;
145 if (mtmp
->mx
&& mtmp
->my
)
146 (void) mkobj_at(0, mtmp
->mx
, mtmp
->my
);
148 if (ptr
->mlet
== ':') {
150 (void) newcham(mtmp
, &mons
[dlevel
+ 14 + rn2(CMNUM
- 14 - dlevel
)]);
152 if (ptr
->mlet
== 'I' || ptr
->mlet
== ';')
154 if (ptr
->mlet
== 'L' || ptr
->mlet
== 'N'
155 || (in_mklev
&& strchr("&w;", ptr
->mlet
) && rn2(5))
160 if (ptr
->mlet
== 'w' && getwn(mtmp
))
165 if (ptr
->mlet
== 'O' || ptr
->mlet
== 'k') {
171 mm
= enexto(mm
.x
, mm
.y
);
172 (void) makemon(ptr
, mm
.x
, mm
.y
);
179 enexto(xchar xx
, xchar yy
)
182 coord foo
[15], *tfoo
;
187 do { /* full kludge action. */
188 for (x
= xx
- range
; x
<= xx
+ range
; x
++)
189 if (goodpos(x
, yy
- range
)) {
191 tfoo
++->y
= yy
- range
;
192 if (tfoo
== &foo
[15])
195 for (x
= xx
- range
; x
<= xx
+ range
; x
++)
196 if (goodpos(x
, yy
+ range
)) {
198 tfoo
++->y
= yy
+ range
;
199 if (tfoo
== &foo
[15])
202 for (y
= yy
+ 1 - range
; y
< yy
+ range
; y
++)
203 if (goodpos(xx
- range
, y
)) {
204 tfoo
->x
= xx
- range
;
206 if (tfoo
== &foo
[15])
209 for (y
= yy
+ 1 - range
; y
< yy
+ range
; y
++)
210 if (goodpos(xx
+ range
, y
)) {
211 tfoo
->x
= xx
+ range
;
213 if (tfoo
== &foo
[15])
217 } while (tfoo
== foo
);
219 return (foo
[rn2(tfoo
- foo
)]);
223 goodpos(int x
, int y
)
224 { /* used only in mnexto and rloc */
226 !(x
< 1 || x
> COLNO
- 2 || y
< 1 || y
> ROWNO
- 2 ||
227 m_at(x
, y
) || !ACCESSIBLE(levl
[x
][y
].typ
)
228 || (x
== u
.ux
&& y
== u
.uy
)
229 || sobj_at(ENORMOUS_ROCK
, x
, y
)
234 rloc(struct monst
*mtmp
)
237 char ch
= mtmp
->data
->mlet
;
240 if (ch
== 'w' && mtmp
->mx
)
241 return; /* do not relocate worms */
244 tx
= rn1(COLNO
- 3, 2);
246 } while (!goodpos(tx
, ty
));
249 if (u
.ustuck
== mtmp
) {
261 mkmon_at(int let
, int x
, int y
)
264 const struct permonst
*ptr
;
266 for (ct
= 0; ct
< CMNUM
; ct
++) {
268 if (ptr
->mlet
== let
)
269 return (makemon(ptr
, x
, y
));