hack.makemon.c revision 1.6 1 1.6 jsm /* $NetBSD: hack.makemon.c,v 1.6 2003/04/02 18:36:37 jsm Exp $ */
2 1.4 christos
3 1.2 mycroft /*
4 1.6 jsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5 1.6 jsm * Amsterdam
6 1.6 jsm * All rights reserved.
7 1.6 jsm *
8 1.6 jsm * Redistribution and use in source and binary forms, with or without
9 1.6 jsm * modification, are permitted provided that the following conditions are
10 1.6 jsm * met:
11 1.6 jsm *
12 1.6 jsm * - Redistributions of source code must retain the above copyright notice,
13 1.6 jsm * this list of conditions and the following disclaimer.
14 1.6 jsm *
15 1.6 jsm * - Redistributions in binary form must reproduce the above copyright
16 1.6 jsm * notice, this list of conditions and the following disclaimer in the
17 1.6 jsm * documentation and/or other materials provided with the distribution.
18 1.6 jsm *
19 1.6 jsm * - Neither the name of the Stichting Centrum voor Wiskunde en
20 1.6 jsm * Informatica, nor the names of its contributors may be used to endorse or
21 1.6 jsm * promote products derived from this software without specific prior
22 1.6 jsm * written permission.
23 1.6 jsm *
24 1.6 jsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 1.6 jsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 1.6 jsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 1.6 jsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 1.6 jsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 1.6 jsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 1.6 jsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 1.6 jsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 1.6 jsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 1.6 jsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 1.6 jsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 1.6 jsm */
36 1.6 jsm
37 1.6 jsm /*
38 1.6 jsm * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org>
39 1.6 jsm * All rights reserved.
40 1.6 jsm *
41 1.6 jsm * Redistribution and use in source and binary forms, with or without
42 1.6 jsm * modification, are permitted provided that the following conditions
43 1.6 jsm * are met:
44 1.6 jsm * 1. Redistributions of source code must retain the above copyright
45 1.6 jsm * notice, this list of conditions and the following disclaimer.
46 1.6 jsm * 2. Redistributions in binary form must reproduce the above copyright
47 1.6 jsm * notice, this list of conditions and the following disclaimer in the
48 1.6 jsm * documentation and/or other materials provided with the distribution.
49 1.6 jsm * 3. The name of the author may not be used to endorse or promote products
50 1.6 jsm * derived from this software without specific prior written permission.
51 1.6 jsm *
52 1.6 jsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 1.6 jsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 1.6 jsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 1.6 jsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 1.6 jsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 1.6 jsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 1.6 jsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 1.6 jsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 1.6 jsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 1.6 jsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 1.2 mycroft */
63 1.2 mycroft
64 1.4 christos #include <sys/cdefs.h>
65 1.2 mycroft #ifndef lint
66 1.6 jsm __RCSID("$NetBSD: hack.makemon.c,v 1.6 2003/04/02 18:36:37 jsm Exp $");
67 1.4 christos #endif /* not lint */
68 1.1 cgd
69 1.1 cgd #include "hack.h"
70 1.4 christos #include "extern.h"
71 1.4 christos
72 1.1 cgd struct monst zeromonst;
73 1.1 cgd
74 1.1 cgd /*
75 1.1 cgd * called with [x,y] = coordinates;
76 1.1 cgd * [0,0] means anyplace
77 1.1 cgd * [u.ux,u.uy] means: call mnexto (if !in_mklev)
78 1.1 cgd *
79 1.1 cgd * In case we make an Orc or killer bee, we make an entire horde (swarm);
80 1.1 cgd * note that in this case we return only one of them (the one at [x,y]).
81 1.1 cgd */
82 1.4 christos struct monst *
83 1.5 jsm makemon(const struct permonst *ptr, int x, int y)
84 1.1 cgd {
85 1.4 christos struct monst *mtmp;
86 1.4 christos int tmp, ct;
87 1.4 christos boolean anything = (!ptr);
88 1.4 christos
89 1.4 christos if (x != 0 || y != 0)
90 1.4 christos if (m_at(x, y))
91 1.4 christos return ((struct monst *) 0);
92 1.4 christos if (ptr) {
93 1.4 christos if (strchr(fut_geno, ptr->mlet))
94 1.4 christos return ((struct monst *) 0);
95 1.1 cgd } else {
96 1.1 cgd ct = CMNUM - strlen(fut_geno);
97 1.4 christos if (strchr(fut_geno, 'm'))
98 1.4 christos ct++; /* make only 1 minotaur */
99 1.4 christos if (strchr(fut_geno, '@'))
100 1.4 christos ct++;
101 1.4 christos if (ct <= 0)
102 1.4 christos return (0); /* no more monsters! */
103 1.4 christos tmp = rn2(ct * dlevel / 24 + 7);
104 1.4 christos if (tmp < dlevel - 4)
105 1.4 christos tmp = rn2(ct * dlevel / 24 + 12);
106 1.4 christos if (tmp >= ct)
107 1.4 christos tmp = rn1(ct - ct / 2, ct / 2);
108 1.4 christos for (ct = 0; ct < CMNUM; ct++) {
109 1.1 cgd ptr = &mons[ct];
110 1.4 christos if (strchr(fut_geno, ptr->mlet))
111 1.1 cgd continue;
112 1.4 christos if (!tmp--)
113 1.4 christos goto gotmon;
114 1.1 cgd }
115 1.1 cgd panic("makemon?");
116 1.1 cgd }
117 1.1 cgd gotmon:
118 1.1 cgd mtmp = newmonst(ptr->pxlth);
119 1.1 cgd *mtmp = zeromonst; /* clear all entries in structure */
120 1.4 christos for (ct = 0; ct < ptr->pxlth; ct++)
121 1.1 cgd ((char *) &(mtmp->mextra[0]))[ct] = 0;
122 1.1 cgd mtmp->nmon = fmon;
123 1.1 cgd fmon = mtmp;
124 1.1 cgd mtmp->m_id = flags.ident++;
125 1.1 cgd mtmp->data = ptr;
126 1.1 cgd mtmp->mxlth = ptr->pxlth;
127 1.4 christos if (ptr->mlet == 'D')
128 1.4 christos mtmp->mhpmax = mtmp->mhp = 80;
129 1.4 christos else if (!ptr->mlevel)
130 1.4 christos mtmp->mhpmax = mtmp->mhp = rnd(4);
131 1.4 christos else
132 1.4 christos mtmp->mhpmax = mtmp->mhp = d(ptr->mlevel, 8);
133 1.1 cgd mtmp->mx = x;
134 1.1 cgd mtmp->my = y;
135 1.1 cgd mtmp->mcansee = 1;
136 1.4 christos if (ptr->mlet == 'M') {
137 1.1 cgd mtmp->mimic = 1;
138 1.1 cgd mtmp->mappearance = ']';
139 1.1 cgd }
140 1.4 christos if (!in_mklev) {
141 1.4 christos if (x == u.ux && y == u.uy && ptr->mlet != ' ')
142 1.1 cgd mnexto(mtmp);
143 1.4 christos if (x == 0 && y == 0)
144 1.1 cgd rloc(mtmp);
145 1.1 cgd }
146 1.4 christos if (ptr->mlet == 's' || ptr->mlet == 'S') {
147 1.1 cgd mtmp->mhide = mtmp->mundetected = 1;
148 1.4 christos if (in_mklev)
149 1.4 christos if (mtmp->mx && mtmp->my)
150 1.4 christos (void) mkobj_at(0, mtmp->mx, mtmp->my);
151 1.1 cgd }
152 1.4 christos if (ptr->mlet == ':') {
153 1.1 cgd mtmp->cham = 1;
154 1.4 christos (void) newcham(mtmp, &mons[dlevel + 14 + rn2(CMNUM - 14 - dlevel)]);
155 1.1 cgd }
156 1.4 christos if (ptr->mlet == 'I' || ptr->mlet == ';')
157 1.1 cgd mtmp->minvis = 1;
158 1.4 christos if (ptr->mlet == 'L' || ptr->mlet == 'N'
159 1.4 christos || (in_mklev && strchr("&w;", ptr->mlet) && rn2(5))
160 1.4 christos )
161 1.4 christos mtmp->msleep = 1;
162 1.1 cgd
163 1.1 cgd #ifndef NOWORM
164 1.4 christos if (ptr->mlet == 'w' && getwn(mtmp))
165 1.1 cgd initworm(mtmp);
166 1.4 christos #endif /* NOWORM */
167 1.1 cgd
168 1.4 christos if (anything)
169 1.4 christos if (ptr->mlet == 'O' || ptr->mlet == 'k') {
170 1.4 christos coord mm;
171 1.4 christos int cnt = rnd(10);
172 1.4 christos mm.x = x;
173 1.4 christos mm.y = y;
174 1.4 christos while (cnt--) {
175 1.4 christos mm = enexto(mm.x, mm.y);
176 1.4 christos (void) makemon(ptr, mm.x, mm.y);
177 1.4 christos }
178 1.1 cgd }
179 1.4 christos return (mtmp);
180 1.1 cgd }
181 1.1 cgd
182 1.1 cgd coord
183 1.4 christos enexto(xx, yy)
184 1.4 christos xchar xx, yy;
185 1.1 cgd {
186 1.4 christos xchar x, y;
187 1.4 christos coord foo[15], *tfoo;
188 1.4 christos int range;
189 1.1 cgd
190 1.1 cgd tfoo = foo;
191 1.1 cgd range = 1;
192 1.4 christos do { /* full kludge action. */
193 1.4 christos for (x = xx - range; x <= xx + range; x++)
194 1.4 christos if (goodpos(x, yy - range)) {
195 1.1 cgd tfoo->x = x;
196 1.4 christos tfoo++->y = yy - range;
197 1.4 christos if (tfoo == &foo[15])
198 1.4 christos goto foofull;
199 1.1 cgd }
200 1.4 christos for (x = xx - range; x <= xx + range; x++)
201 1.4 christos if (goodpos(x, yy + range)) {
202 1.1 cgd tfoo->x = x;
203 1.4 christos tfoo++->y = yy + range;
204 1.4 christos if (tfoo == &foo[15])
205 1.4 christos goto foofull;
206 1.1 cgd }
207 1.4 christos for (y = yy + 1 - range; y < yy + range; y++)
208 1.4 christos if (goodpos(xx - range, y)) {
209 1.4 christos tfoo->x = xx - range;
210 1.1 cgd tfoo++->y = y;
211 1.4 christos if (tfoo == &foo[15])
212 1.4 christos goto foofull;
213 1.1 cgd }
214 1.4 christos for (y = yy + 1 - range; y < yy + range; y++)
215 1.4 christos if (goodpos(xx + range, y)) {
216 1.4 christos tfoo->x = xx + range;
217 1.1 cgd tfoo++->y = y;
218 1.4 christos if (tfoo == &foo[15])
219 1.4 christos goto foofull;
220 1.1 cgd }
221 1.1 cgd range++;
222 1.4 christos } while (tfoo == foo);
223 1.1 cgd foofull:
224 1.4 christos return (foo[rn2(tfoo - foo)]);
225 1.1 cgd }
226 1.1 cgd
227 1.4 christos int
228 1.5 jsm goodpos(int x, int y)
229 1.4 christos { /* used only in mnexto and rloc */
230 1.4 christos return (
231 1.4 christos !(x < 1 || x > COLNO - 2 || y < 1 || y > ROWNO - 2 ||
232 1.4 christos m_at(x, y) || !ACCESSIBLE(levl[x][y].typ)
233 1.4 christos || (x == u.ux && y == u.uy)
234 1.4 christos || sobj_at(ENORMOUS_ROCK, x, y)
235 1.4 christos ));
236 1.1 cgd }
237 1.1 cgd
238 1.4 christos void
239 1.1 cgd rloc(mtmp)
240 1.4 christos struct monst *mtmp;
241 1.1 cgd {
242 1.4 christos int tx, ty;
243 1.4 christos char ch = mtmp->data->mlet;
244 1.1 cgd
245 1.1 cgd #ifndef NOWORM
246 1.4 christos if (ch == 'w' && mtmp->mx)
247 1.4 christos return; /* do not relocate worms */
248 1.4 christos #endif /* NOWORM */
249 1.1 cgd do {
250 1.4 christos tx = rn1(COLNO - 3, 2);
251 1.1 cgd ty = rn2(ROWNO);
252 1.4 christos } while (!goodpos(tx, ty));
253 1.1 cgd mtmp->mx = tx;
254 1.1 cgd mtmp->my = ty;
255 1.4 christos if (u.ustuck == mtmp) {
256 1.4 christos if (u.uswallow) {
257 1.1 cgd u.ux = tx;
258 1.1 cgd u.uy = ty;
259 1.1 cgd docrt();
260 1.4 christos } else
261 1.4 christos u.ustuck = 0;
262 1.1 cgd }
263 1.1 cgd pmon(mtmp);
264 1.1 cgd }
265 1.1 cgd
266 1.4 christos struct monst *
267 1.4 christos mkmon_at(let, x, y)
268 1.4 christos char let;
269 1.4 christos int x, y;
270 1.1 cgd {
271 1.4 christos int ct;
272 1.5 jsm const struct permonst *ptr;
273 1.1 cgd
274 1.4 christos for (ct = 0; ct < CMNUM; ct++) {
275 1.1 cgd ptr = &mons[ct];
276 1.4 christos if (ptr->mlet == let)
277 1.4 christos return (makemon(ptr, x, y));
278 1.1 cgd }
279 1.4 christos return (0);
280 1.1 cgd }
281