hack.mon.c revision 1.7.10.1 1 1.7.10.1 matt /* hack.mon.c,v 1.7 2006/03/30 01:28:46 jnemeth 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.7.10.1 matt __RCSID("hack.mon.c,v 1.7 2006/03/30 01:28:46 jnemeth Exp");
67 1.4 christos #endif /* not lint */
68 1.1 cgd
69 1.4 christos #include <stdlib.h>
70 1.1 cgd #include "hack.h"
71 1.4 christos #include "extern.h"
72 1.1 cgd #include "hack.mfndpos.h"
73 1.1 cgd
74 1.1 cgd #ifndef NULL
75 1.1 cgd #define NULL (char *) 0
76 1.1 cgd #endif
77 1.1 cgd
78 1.4 christos int warnlevel; /* used by movemon and dochugw */
79 1.4 christos long lastwarntime;
80 1.4 christos int lastwarnlev;
81 1.5 jsm const char *const warnings[] = {
82 1.1 cgd "white", "pink", "red", "ruby", "purple", "black"
83 1.1 cgd };
84 1.1 cgd
85 1.4 christos void
86 1.1 cgd movemon()
87 1.1 cgd {
88 1.4 christos struct monst *mtmp;
89 1.4 christos int fr;
90 1.1 cgd
91 1.1 cgd warnlevel = 0;
92 1.1 cgd
93 1.4 christos while (1) {
94 1.1 cgd /* find a monster that we haven't treated yet */
95 1.4 christos /*
96 1.4 christos * note that mtmp or mtmp->nmon might get killed while mtmp
97 1.4 christos * moves, so we cannot just walk down the chain (even new
98 1.4 christos * monsters might get created!)
99 1.4 christos */
100 1.4 christos for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
101 1.4 christos if (mtmp->mlstmv < moves)
102 1.4 christos goto next_mon;
103 1.1 cgd /* treated all monsters */
104 1.1 cgd break;
105 1.1 cgd
106 1.4 christos next_mon:
107 1.1 cgd mtmp->mlstmv = moves;
108 1.1 cgd
109 1.1 cgd /* most monsters drown in pools */
110 1.4 christos {
111 1.4 christos boolean inpool, iseel;
112 1.1 cgd
113 1.4 christos inpool = (levl[mtmp->mx][mtmp->my].typ == POOL);
114 1.4 christos iseel = (mtmp->data->mlet == ';');
115 1.4 christos if (inpool && !iseel) {
116 1.4 christos if (cansee(mtmp->mx, mtmp->my))
117 1.4 christos pline("%s drowns.", Monnam(mtmp));
118 1.4 christos mondead(mtmp);
119 1.4 christos continue;
120 1.4 christos }
121 1.4 christos /* but eels have a difficult time outside */
122 1.4 christos if (iseel && !inpool) {
123 1.4 christos if (mtmp->mhp > 1)
124 1.4 christos mtmp->mhp--;
125 1.4 christos mtmp->mflee = 1;
126 1.4 christos mtmp->mfleetim += 2;
127 1.4 christos }
128 1.1 cgd }
129 1.4 christos if (mtmp->mblinded && !--mtmp->mblinded)
130 1.1 cgd mtmp->mcansee = 1;
131 1.4 christos if (mtmp->mfleetim && !--mtmp->mfleetim)
132 1.1 cgd mtmp->mflee = 0;
133 1.4 christos if (mtmp->mimic)
134 1.4 christos continue;
135 1.4 christos if (mtmp->mspeed != MSLOW || !(moves % 2)) {
136 1.1 cgd /* continue if the monster died fighting */
137 1.1 cgd fr = -1;
138 1.4 christos if (Conflict && cansee(mtmp->mx, mtmp->my)
139 1.4 christos && (fr = fightm(mtmp)) == 2)
140 1.1 cgd continue;
141 1.4 christos if (fr < 0 && dochugw(mtmp))
142 1.1 cgd continue;
143 1.1 cgd }
144 1.4 christos if (mtmp->mspeed == MFAST && dochugw(mtmp))
145 1.1 cgd continue;
146 1.1 cgd }
147 1.1 cgd
148 1.1 cgd warnlevel -= u.ulevel;
149 1.4 christos if (warnlevel >= SIZE(warnings))
150 1.4 christos warnlevel = SIZE(warnings) - 1;
151 1.4 christos if (warnlevel >= 0)
152 1.4 christos if (warnlevel > lastwarnlev || moves > lastwarntime + 5) {
153 1.5 jsm const char *rr;
154 1.4 christos switch (Warning & (LEFT_RING | RIGHT_RING)) {
155 1.4 christos case LEFT_RING:
156 1.4 christos rr = "Your left ring glows";
157 1.4 christos break;
158 1.4 christos case RIGHT_RING:
159 1.4 christos rr = "Your right ring glows";
160 1.4 christos break;
161 1.4 christos case LEFT_RING | RIGHT_RING:
162 1.4 christos rr = "Both your rings glow";
163 1.4 christos break;
164 1.4 christos default:
165 1.4 christos rr = "Your fingertips glow";
166 1.4 christos break;
167 1.4 christos }
168 1.4 christos pline("%s %s!", rr, warnings[warnlevel]);
169 1.4 christos lastwarntime = moves;
170 1.4 christos lastwarnlev = warnlevel;
171 1.4 christos }
172 1.4 christos dmonsfree(); /* remove all dead monsters */
173 1.1 cgd }
174 1.1 cgd
175 1.4 christos void
176 1.4 christos justswld(mtmp, name)
177 1.4 christos struct monst *mtmp;
178 1.5 jsm const char *name;
179 1.1 cgd {
180 1.1 cgd
181 1.1 cgd mtmp->mx = u.ux;
182 1.1 cgd mtmp->my = u.uy;
183 1.1 cgd u.ustuck = mtmp;
184 1.1 cgd pmon(mtmp);
185 1.4 christos kludge("%s swallows you!", name);
186 1.1 cgd more();
187 1.1 cgd seeoff(1);
188 1.1 cgd u.uswallow = 1;
189 1.1 cgd u.uswldtim = 0;
190 1.1 cgd swallowed();
191 1.1 cgd }
192 1.1 cgd
193 1.4 christos void
194 1.4 christos youswld(mtmp, dam, die, name)
195 1.4 christos struct monst *mtmp;
196 1.4 christos int dam, die;
197 1.5 jsm const char *name;
198 1.1 cgd {
199 1.4 christos if (mtmp != u.ustuck)
200 1.4 christos return;
201 1.4 christos kludge("%s digests you!", name);
202 1.1 cgd u.uhp -= dam;
203 1.4 christos if (u.uswldtim++ >= die) { /* a3 */
204 1.1 cgd pline("It totally digests you!");
205 1.1 cgd u.uhp = -1;
206 1.1 cgd }
207 1.4 christos if (u.uhp < 1)
208 1.4 christos done_in_by(mtmp);
209 1.4 christos #if 0
210 1.4 christos flags.botlx = 1; /* should we show status line ? */
211 1.4 christos #endif
212 1.1 cgd }
213 1.1 cgd
214 1.4 christos int
215 1.4 christos dochugw(mtmp)
216 1.4 christos struct monst *mtmp;
217 1.4 christos {
218 1.4 christos int x = mtmp->mx;
219 1.4 christos int y = mtmp->my;
220 1.7.10.1 matt int dead = dochug(mtmp);
221 1.4 christos int dd;
222 1.7.10.1 matt
223 1.7.10.1 matt if (!dead) /* monster still alive */
224 1.4 christos if (Warning)
225 1.4 christos if (!mtmp->mpeaceful)
226 1.4 christos if (mtmp->data->mlevel > warnlevel)
227 1.4 christos if ((dd = dist(mtmp->mx, mtmp->my)) < dist(x, y))
228 1.4 christos if (dd < 100)
229 1.4 christos if (!canseemon(mtmp))
230 1.4 christos warnlevel = mtmp->data->mlevel;
231 1.7.10.1 matt return (dead);
232 1.1 cgd }
233 1.1 cgd
234 1.1 cgd /* returns 1 if monster died moving, 0 otherwise */
235 1.4 christos int
236 1.1 cgd dochug(mtmp)
237 1.4 christos struct monst *mtmp;
238 1.1 cgd {
239 1.5 jsm const struct permonst *mdat;
240 1.4 christos int tmp = 0, nearby, scared;
241 1.1 cgd
242 1.4 christos if (mtmp->cham && !rn2(6))
243 1.4 christos (void) newcham(mtmp, &mons[dlevel + 14 + rn2(CMNUM - 14 - dlevel)]);
244 1.1 cgd mdat = mtmp->data;
245 1.4 christos if (mdat->mlevel < 0)
246 1.4 christos panic("bad monster %c (%d)", mdat->mlet, mdat->mlevel);
247 1.1 cgd
248 1.1 cgd /* regenerate monsters */
249 1.4 christos if ((!(moves % 20) || strchr(MREGEN, mdat->mlet)) &&
250 1.1 cgd mtmp->mhp < mtmp->mhpmax)
251 1.1 cgd mtmp->mhp++;
252 1.1 cgd
253 1.4 christos if (mtmp->mfroz)
254 1.4 christos return (0); /* frozen monsters don't do anything */
255 1.1 cgd
256 1.4 christos if (mtmp->msleep) {
257 1.1 cgd /* wake up, or get out of here. */
258 1.1 cgd /* ettins are hard to surprise */
259 1.1 cgd /* Nymphs and Leprechauns do not easily wake up */
260 1.4 christos if (cansee(mtmp->mx, mtmp->my) &&
261 1.4 christos (!Stealth || (mdat->mlet == 'e' && rn2(10))) &&
262 1.4 christos (!strchr("NL", mdat->mlet) || !rn2(50)) &&
263 1.4 christos (Aggravate_monster || strchr("d1", mdat->mlet)
264 1.4 christos || (!rn2(7) && !mtmp->mimic)))
265 1.1 cgd mtmp->msleep = 0;
266 1.4 christos else
267 1.4 christos return (0);
268 1.1 cgd }
269 1.1 cgd /* not frozen or sleeping: wipe out texts written in the dust */
270 1.1 cgd wipe_engr_at(mtmp->mx, mtmp->my, 1);
271 1.1 cgd
272 1.1 cgd /* confused monsters get unconfused with small probability */
273 1.4 christos if (mtmp->mconf && !rn2(50))
274 1.4 christos mtmp->mconf = 0;
275 1.1 cgd
276 1.1 cgd /* some monsters teleport */
277 1.4 christos if (mtmp->mflee && strchr("tNL", mdat->mlet) && !rn2(40)) {
278 1.1 cgd rloc(mtmp);
279 1.4 christos return (0);
280 1.1 cgd }
281 1.4 christos if (mdat->mmove < rnd(6))
282 1.4 christos return (0);
283 1.1 cgd
284 1.1 cgd /* fleeing monsters might regain courage */
285 1.4 christos if (mtmp->mflee && !mtmp->mfleetim
286 1.1 cgd && mtmp->mhp == mtmp->mhpmax && !rn2(25))
287 1.1 cgd mtmp->mflee = 0;
288 1.1 cgd
289 1.1 cgd nearby = (dist(mtmp->mx, mtmp->my) < 3);
290 1.1 cgd scared = (nearby && (sengr_at("Elbereth", u.ux, u.uy) ||
291 1.4 christos sobj_at(SCR_SCARE_MONSTER, u.ux, u.uy)));
292 1.4 christos if (scared && !mtmp->mflee) {
293 1.1 cgd mtmp->mflee = 1;
294 1.1 cgd mtmp->mfleetim = (rn2(7) ? rnd(10) : rnd(100));
295 1.1 cgd }
296 1.4 christos if (!nearby ||
297 1.4 christos mtmp->mflee ||
298 1.4 christos mtmp->mconf ||
299 1.4 christos (mtmp->minvis && !rn2(3)) ||
300 1.4 christos (strchr("BIuy", mdat->mlet) && !rn2(4)) ||
301 1.4 christos (mdat->mlet == 'L' && !u.ugold && (mtmp->mgold || rn2(2))) ||
302 1.4 christos (!mtmp->mcansee && !rn2(4)) ||
303 1.4 christos mtmp->mpeaceful
304 1.4 christos ) {
305 1.4 christos tmp = m_move(mtmp, 0); /* 2: monster died moving */
306 1.4 christos if (tmp == 2 || (tmp && mdat->mmove <= 12))
307 1.4 christos return (tmp == 2);
308 1.4 christos }
309 1.4 christos if (!strchr("Ea", mdat->mlet) && nearby &&
310 1.4 christos !mtmp->mpeaceful && u.uhp > 0 && !scared) {
311 1.4 christos if (mhitu(mtmp))
312 1.4 christos return (1); /* monster died (e.g. 'y' or 'F') */
313 1.1 cgd }
314 1.1 cgd /* extra movement for fast monsters */
315 1.4 christos if (mdat->mmove - 12 > rnd(12))
316 1.4 christos tmp = m_move(mtmp, 1);
317 1.4 christos return (tmp == 2);
318 1.4 christos }
319 1.4 christos
320 1.4 christos int
321 1.5 jsm m_move(struct monst *mtmp, int after)
322 1.4 christos {
323 1.4 christos struct monst *mtmp2;
324 1.4 christos int nx, ny, omx, omy, appr, nearer, cnt, i, j;
325 1.4 christos xchar gx, gy, nix, niy, chcnt;
326 1.4 christos schar chi;
327 1.4 christos boolean likegold = 0, likegems = 0, likeobjs = 0;
328 1.4 christos char msym = mtmp->data->mlet;
329 1.4 christos schar mmoved = 0; /* not strictly nec.: chi >= 0 will
330 1.4 christos * do */
331 1.4 christos coord poss[9];
332 1.4 christos int info[9];
333 1.4 christos
334 1.4 christos if (mtmp->mfroz || mtmp->msleep)
335 1.4 christos return (0);
336 1.4 christos if (mtmp->mtrapped) {
337 1.1 cgd i = mintrap(mtmp);
338 1.4 christos if (i == 2)
339 1.4 christos return (2); /* he died */
340 1.4 christos if (i == 1)
341 1.4 christos return (0); /* still in trap, so didnt move */
342 1.1 cgd }
343 1.4 christos if (mtmp->mhide && o_at(mtmp->mx, mtmp->my) && rn2(10))
344 1.4 christos return (0); /* do not leave hiding place */
345 1.1 cgd
346 1.1 cgd #ifndef NOWORM
347 1.4 christos if (mtmp->wormno)
348 1.1 cgd goto not_special;
349 1.4 christos #endif /* NOWORM */
350 1.1 cgd
351 1.1 cgd /* my dog gets a special treatment */
352 1.4 christos if (mtmp->mtame) {
353 1.4 christos return (dog_move(mtmp, after));
354 1.1 cgd }
355 1.1 cgd /* likewise for shopkeeper */
356 1.4 christos if (mtmp->isshk) {
357 1.1 cgd mmoved = shk_move(mtmp);
358 1.4 christos if (mmoved >= 0)
359 1.1 cgd goto postmov;
360 1.4 christos mmoved = 0; /* follow player outside shop */
361 1.1 cgd }
362 1.1 cgd /* and for the guard */
363 1.4 christos if (mtmp->isgd) {
364 1.1 cgd mmoved = gd_move();
365 1.1 cgd goto postmov;
366 1.1 cgd }
367 1.4 christos /*
368 1.4 christos * teleport if that lies in our nature ('t') or when badly wounded
369 1.4 christos * ('1')
370 1.4 christos */
371 1.4 christos if ((msym == 't' && !rn2(5))
372 1.4 christos || (msym == '1' && (mtmp->mhp < 7 || (!xdnstair && !rn2(5))
373 1.4 christos || levl[u.ux][u.uy].typ == STAIRS))) {
374 1.4 christos if (mtmp->mhp < 7 || (msym == 't' && rn2(2)))
375 1.1 cgd rloc(mtmp);
376 1.1 cgd else
377 1.1 cgd mnexto(mtmp);
378 1.1 cgd mmoved = 1;
379 1.1 cgd goto postmov;
380 1.1 cgd }
381 1.1 cgd /* spit fire ('D') or use a wand ('1') when appropriate */
382 1.4 christos if (strchr("D1", msym))
383 1.1 cgd inrange(mtmp);
384 1.1 cgd
385 1.4 christos if (msym == 'U' && !mtmp->mcan && canseemon(mtmp) &&
386 1.1 cgd mtmp->mcansee && rn2(5)) {
387 1.4 christos if (!Confusion)
388 1.1 cgd pline("%s's gaze has confused you!", Monnam(mtmp));
389 1.1 cgd else
390 1.1 cgd pline("You are getting more and more confused.");
391 1.4 christos if (rn2(3))
392 1.4 christos mtmp->mcan = 1;
393 1.4 christos Confusion += d(3, 4); /* timeout */
394 1.1 cgd }
395 1.1 cgd not_special:
396 1.4 christos if (!mtmp->mflee && u.uswallow && u.ustuck != mtmp)
397 1.4 christos return (1);
398 1.1 cgd appr = 1;
399 1.4 christos if (mtmp->mflee)
400 1.4 christos appr = -1;
401 1.4 christos if (mtmp->mconf || Invis || !mtmp->mcansee ||
402 1.4 christos (strchr("BIy", msym) && !rn2(3)))
403 1.1 cgd appr = 0;
404 1.1 cgd omx = mtmp->mx;
405 1.1 cgd omy = mtmp->my;
406 1.1 cgd gx = u.ux;
407 1.1 cgd gy = u.uy;
408 1.4 christos if (msym == 'L' && appr == 1 && mtmp->mgold > u.ugold)
409 1.1 cgd appr = -1;
410 1.1 cgd
411 1.4 christos /*
412 1.4 christos * random criterion for 'smell' or track finding ability should use
413 1.4 christos * mtmp->msmell or sth
414 1.1 cgd */
415 1.4 christos if (msym == '@' ||
416 1.4 christos ('a' <= msym && msym <= 'z')) {
417 1.4 christos coord *cp;
418 1.4 christos schar mroom;
419 1.4 christos mroom = inroom(omx, omy);
420 1.4 christos if (mroom < 0 || mroom != inroom(u.ux, u.uy)) {
421 1.4 christos cp = gettrack(omx, omy);
422 1.4 christos if (cp) {
423 1.4 christos gx = cp->x;
424 1.4 christos gy = cp->y;
425 1.4 christos }
426 1.1 cgd }
427 1.1 cgd }
428 1.1 cgd /* look for gold or jewels nearby */
429 1.4 christos likegold = (strchr("LOD", msym) != NULL);
430 1.4 christos likegems = (strchr("ODu", msym) != NULL);
431 1.1 cgd likeobjs = mtmp->mhide;
432 1.1 cgd #define SRCHRADIUS 25
433 1.4 christos {
434 1.4 christos xchar mind = SRCHRADIUS; /* not too far away */
435 1.4 christos int dd;
436 1.4 christos if (likegold) {
437 1.4 christos struct gold *gold;
438 1.4 christos for (gold = fgold; gold; gold = gold->ngold)
439 1.4 christos if ((dd = DIST(omx, omy, gold->gx, gold->gy)) < mind) {
440 1.4 christos mind = dd;
441 1.4 christos gx = gold->gx;
442 1.4 christos gy = gold->gy;
443 1.4 christos }
444 1.4 christos }
445 1.4 christos if (likegems || likeobjs) {
446 1.4 christos struct obj *otmp;
447 1.4 christos for (otmp = fobj; otmp; otmp = otmp->nobj)
448 1.4 christos if (likeobjs || otmp->olet == GEM_SYM)
449 1.4 christos if (msym != 'u' ||
450 1.4 christos objects[otmp->otyp].g_val != 0)
451 1.4 christos if ((dd = DIST(omx, omy, otmp->ox, otmp->oy)) < mind) {
452 1.4 christos mind = dd;
453 1.4 christos gx = otmp->ox;
454 1.4 christos gy = otmp->oy;
455 1.4 christos }
456 1.4 christos }
457 1.4 christos if (mind < SRCHRADIUS && appr == -1) {
458 1.4 christos if (dist(omx, omy) < 10) {
459 1.4 christos gx = u.ux;
460 1.4 christos gy = u.uy;
461 1.4 christos } else
462 1.4 christos appr = 1;
463 1.4 christos }
464 1.1 cgd }
465 1.1 cgd nix = omx;
466 1.1 cgd niy = omy;
467 1.4 christos cnt = mfndpos(mtmp, poss, info,
468 1.4 christos msym == 'u' ? NOTONL :
469 1.4 christos (msym == '@' || msym == '1') ? (ALLOW_SSM | ALLOW_TRAPS) :
470 1.4 christos strchr(UNDEAD, msym) ? NOGARLIC : ALLOW_TRAPS);
471 1.4 christos /* ALLOW_ROCK for some monsters ? */
472 1.1 cgd chcnt = 0;
473 1.1 cgd chi = -1;
474 1.4 christos for (i = 0; i < cnt; i++) {
475 1.1 cgd nx = poss[i].x;
476 1.1 cgd ny = poss[i].y;
477 1.4 christos for (j = 0; j < MTSZ && j < cnt - 1; j++)
478 1.4 christos if (nx == mtmp->mtrack[j].x && ny == mtmp->mtrack[j].y)
479 1.4 christos if (rn2(4 * (cnt - j)))
480 1.4 christos goto nxti;
481 1.1 cgd #ifdef STUPID
482 1.1 cgd /* some stupid compilers think that this is too complicated */
483 1.4 christos {
484 1.4 christos int d1 = DIST(nx, ny, gx, gy);
485 1.4 christos int d2 = DIST(nix, niy, gx, gy);
486 1.4 christos nearer = (d1 < d2);
487 1.1 cgd }
488 1.1 cgd #else
489 1.4 christos nearer = (DIST(nx, ny, gx, gy) < DIST(nix, niy, gx, gy));
490 1.4 christos #endif /* STUPID */
491 1.4 christos if ((appr == 1 && nearer) || (appr == -1 && !nearer) ||
492 1.4 christos !mmoved ||
493 1.4 christos (!appr && !rn2(++chcnt))) {
494 1.1 cgd nix = nx;
495 1.1 cgd niy = ny;
496 1.1 cgd chi = i;
497 1.1 cgd mmoved = 1;
498 1.1 cgd }
499 1.4 christos nxti: ;
500 1.1 cgd }
501 1.4 christos if (mmoved) {
502 1.4 christos if (info[chi] & ALLOW_M) {
503 1.4 christos mtmp2 = m_at(nix, niy);
504 1.7 jnemeth if (mtmp2 == NULL)
505 1.7 jnemeth panic("error in m_move");
506 1.4 christos if (hitmm(mtmp, mtmp2) == 1 && rn2(4) &&
507 1.4 christos hitmm(mtmp2, mtmp) == 2)
508 1.4 christos return (2);
509 1.4 christos return (0);
510 1.4 christos }
511 1.4 christos if (info[chi] & ALLOW_U) {
512 1.4 christos (void) hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd) + 1);
513 1.4 christos return (0);
514 1.1 cgd }
515 1.1 cgd mtmp->mx = nix;
516 1.1 cgd mtmp->my = niy;
517 1.4 christos for (j = MTSZ - 1; j > 0; j--)
518 1.4 christos mtmp->mtrack[j] = mtmp->mtrack[j - 1];
519 1.1 cgd mtmp->mtrack[0].x = omx;
520 1.1 cgd mtmp->mtrack[0].y = omy;
521 1.1 cgd #ifndef NOWORM
522 1.4 christos if (mtmp->wormno)
523 1.4 christos worm_move(mtmp);
524 1.4 christos #endif /* NOWORM */
525 1.1 cgd } else {
526 1.4 christos if (msym == 'u' && rn2(2)) {
527 1.1 cgd rloc(mtmp);
528 1.4 christos return (0);
529 1.1 cgd }
530 1.1 cgd #ifndef NOWORM
531 1.4 christos if (mtmp->wormno)
532 1.4 christos worm_nomove(mtmp);
533 1.4 christos #endif /* NOWORM */
534 1.1 cgd }
535 1.1 cgd postmov:
536 1.4 christos if (mmoved == 1) {
537 1.4 christos if (mintrap(mtmp) == 2) /* he died */
538 1.4 christos return (2);
539 1.4 christos if (likegold)
540 1.4 christos mpickgold(mtmp);
541 1.4 christos if (likegems)
542 1.4 christos mpickgems(mtmp);
543 1.4 christos if (mtmp->mhide)
544 1.4 christos mtmp->mundetected = 1;
545 1.1 cgd }
546 1.1 cgd pmon(mtmp);
547 1.4 christos return (mmoved);
548 1.1 cgd }
549 1.1 cgd
550 1.4 christos void
551 1.4 christos mpickgold(mtmp)
552 1.4 christos struct monst *mtmp;
553 1.4 christos {
554 1.4 christos struct gold *gold;
555 1.4 christos while ((gold = g_at(mtmp->mx, mtmp->my)) != NULL) {
556 1.1 cgd mtmp->mgold += gold->amount;
557 1.1 cgd freegold(gold);
558 1.4 christos if (levl[mtmp->mx][mtmp->my].scrsym == '$')
559 1.1 cgd newsym(mtmp->mx, mtmp->my);
560 1.1 cgd }
561 1.1 cgd }
562 1.1 cgd
563 1.4 christos void
564 1.4 christos mpickgems(mtmp)
565 1.4 christos struct monst *mtmp;
566 1.4 christos {
567 1.4 christos struct obj *otmp;
568 1.4 christos for (otmp = fobj; otmp; otmp = otmp->nobj)
569 1.4 christos if (otmp->olet == GEM_SYM)
570 1.4 christos if (otmp->ox == mtmp->mx && otmp->oy == mtmp->my)
571 1.4 christos if (mtmp->data->mlet != 'u' || objects[otmp->otyp].g_val != 0) {
572 1.4 christos freeobj(otmp);
573 1.4 christos mpickobj(mtmp, otmp);
574 1.4 christos if (levl[mtmp->mx][mtmp->my].scrsym == GEM_SYM)
575 1.4 christos newsym(mtmp->mx, mtmp->my); /* %% */
576 1.4 christos return; /* pick only one object */
577 1.4 christos }
578 1.1 cgd }
579 1.1 cgd
580 1.1 cgd /* return number of acceptable neighbour positions */
581 1.4 christos int
582 1.4 christos mfndpos(mon, poss, info, flag)
583 1.4 christos struct monst *mon;
584 1.4 christos coord poss[9];
585 1.4 christos int info[9], flag;
586 1.4 christos {
587 1.4 christos int x, y, nx, ny, cnt = 0, ntyp;
588 1.4 christos struct monst *mtmp;
589 1.4 christos int nowtyp;
590 1.4 christos boolean pool;
591 1.1 cgd
592 1.1 cgd x = mon->mx;
593 1.1 cgd y = mon->my;
594 1.1 cgd nowtyp = levl[x][y].typ;
595 1.1 cgd
596 1.1 cgd pool = (mon->data->mlet == ';');
597 1.4 christos nexttry: /* eels prefer the water, but if there is no
598 1.4 christos * water nearby, they will crawl over land */
599 1.4 christos if (mon->mconf) {
600 1.1 cgd flag |= ALLOW_ALL;
601 1.1 cgd flag &= ~NOTONL;
602 1.1 cgd }
603 1.4 christos for (nx = x - 1; nx <= x + 1; nx++)
604 1.4 christos for (ny = y - 1; ny <= y + 1; ny++)
605 1.4 christos if (nx != x || ny != y)
606 1.4 christos if (isok(nx, ny))
607 1.4 christos if (!IS_ROCK(ntyp = levl[nx][ny].typ))
608 1.4 christos if (!(nx != x && ny != y && (nowtyp == DOOR || ntyp == DOOR)))
609 1.4 christos if ((ntyp == POOL) == pool) {
610 1.4 christos info[cnt] = 0;
611 1.4 christos if (nx == u.ux && ny == u.uy) {
612 1.4 christos if (!(flag & ALLOW_U))
613 1.4 christos continue;
614 1.4 christos info[cnt] = ALLOW_U;
615 1.4 christos } else if ((mtmp = m_at(nx, ny)) != NULL) {
616 1.4 christos if (!(flag & ALLOW_M))
617 1.4 christos continue;
618 1.4 christos info[cnt] = ALLOW_M;
619 1.4 christos if (mtmp->mtame) {
620 1.4 christos if (!(flag & ALLOW_TM))
621 1.4 christos continue;
622 1.4 christos info[cnt] |= ALLOW_TM;
623 1.4 christos }
624 1.4 christos }
625 1.4 christos if (sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
626 1.4 christos if (flag & NOGARLIC)
627 1.4 christos continue;
628 1.4 christos info[cnt] |= NOGARLIC;
629 1.4 christos }
630 1.4 christos if (sobj_at(SCR_SCARE_MONSTER, nx, ny) ||
631 1.4 christos (!mon->mpeaceful && sengr_at("Elbereth", nx, ny))) {
632 1.4 christos if (!(flag & ALLOW_SSM))
633 1.4 christos continue;
634 1.4 christos info[cnt] |= ALLOW_SSM;
635 1.4 christos }
636 1.4 christos if (sobj_at(ENORMOUS_ROCK, nx, ny)) {
637 1.4 christos if (!(flag & ALLOW_ROCK))
638 1.4 christos continue;
639 1.4 christos info[cnt] |= ALLOW_ROCK;
640 1.4 christos }
641 1.4 christos if (!Invis && online(nx, ny)) {
642 1.4 christos if (flag & NOTONL)
643 1.4 christos continue;
644 1.4 christos info[cnt] |= NOTONL;
645 1.4 christos }
646 1.4 christos /*
647 1.4 christos * we cannot
648 1.4 christos * avoid
649 1.4 christos * traps of
650 1.4 christos * an unknown
651 1.4 christos * kind
652 1.4 christos */
653 1.4 christos {
654 1.4 christos struct trap *ttmp = t_at(nx, ny);
655 1.4 christos int tt;
656 1.4 christos if (ttmp) {
657 1.4 christos tt = 1 << ttmp->ttyp;
658 1.4 christos if (mon->mtrapseen & tt) {
659 1.4 christos if (!(flag & tt))
660 1.4 christos continue;
661 1.4 christos info[cnt] |= tt;
662 1.4 christos }
663 1.4 christos }
664 1.4 christos }
665 1.4 christos poss[cnt].x = nx;
666 1.4 christos poss[cnt].y = ny;
667 1.4 christos cnt++;
668 1.4 christos }
669 1.4 christos if (!cnt && pool && nowtyp != POOL) {
670 1.1 cgd pool = FALSE;
671 1.1 cgd goto nexttry;
672 1.1 cgd }
673 1.4 christos return (cnt);
674 1.1 cgd }
675 1.1 cgd
676 1.4 christos int
677 1.4 christos dist(x, y)
678 1.4 christos int x, y;
679 1.4 christos {
680 1.4 christos return ((x - u.ux) * (x - u.ux) + (y - u.uy) * (y - u.uy));
681 1.1 cgd }
682 1.1 cgd
683 1.4 christos void
684 1.1 cgd poisoned(string, pname)
685 1.5 jsm const char *string, *pname;
686 1.1 cgd {
687 1.4 christos int i;
688 1.1 cgd
689 1.4 christos if (Blind)
690 1.4 christos pline("It was poisoned.");
691 1.4 christos else
692 1.4 christos pline("The %s was poisoned!", string);
693 1.4 christos if (Poison_resistance) {
694 1.1 cgd pline("The poison doesn't seem to affect you.");
695 1.1 cgd return;
696 1.1 cgd }
697 1.1 cgd i = rn2(10);
698 1.4 christos if (i == 0) {
699 1.1 cgd u.uhp = -1;
700 1.1 cgd pline("I am afraid the poison was deadly ...");
701 1.4 christos } else if (i <= 5) {
702 1.4 christos losestr(rn1(3, 3));
703 1.1 cgd } else {
704 1.4 christos losehp(rn1(10, 6), pname);
705 1.1 cgd }
706 1.4 christos if (u.uhp < 1) {
707 1.1 cgd killer = pname;
708 1.1 cgd done("died");
709 1.1 cgd }
710 1.1 cgd }
711 1.1 cgd
712 1.4 christos void
713 1.1 cgd mondead(mtmp)
714 1.4 christos struct monst *mtmp;
715 1.1 cgd {
716 1.4 christos relobj(mtmp, 1);
717 1.1 cgd unpmon(mtmp);
718 1.1 cgd relmon(mtmp);
719 1.1 cgd unstuck(mtmp);
720 1.4 christos if (mtmp->isshk)
721 1.4 christos shkdead(mtmp);
722 1.4 christos if (mtmp->isgd)
723 1.4 christos gddead();
724 1.1 cgd #ifndef NOWORM
725 1.4 christos if (mtmp->wormno)
726 1.4 christos wormdead(mtmp);
727 1.4 christos #endif /* NOWORM */
728 1.1 cgd monfree(mtmp);
729 1.1 cgd }
730 1.1 cgd
731 1.1 cgd /* called when monster is moved to larger structure */
732 1.4 christos void
733 1.4 christos replmon(mtmp, mtmp2)
734 1.4 christos struct monst *mtmp, *mtmp2;
735 1.1 cgd {
736 1.1 cgd relmon(mtmp);
737 1.1 cgd monfree(mtmp);
738 1.1 cgd mtmp2->nmon = fmon;
739 1.1 cgd fmon = mtmp2;
740 1.4 christos if (u.ustuck == mtmp)
741 1.4 christos u.ustuck = mtmp2;
742 1.4 christos if (mtmp2->isshk)
743 1.4 christos replshk(mtmp, mtmp2);
744 1.4 christos if (mtmp2->isgd)
745 1.4 christos replgd(mtmp, mtmp2);
746 1.1 cgd }
747 1.1 cgd
748 1.4 christos void
749 1.1 cgd relmon(mon)
750 1.4 christos struct monst *mon;
751 1.1 cgd {
752 1.4 christos struct monst *mtmp;
753 1.1 cgd
754 1.4 christos if (mon == fmon)
755 1.4 christos fmon = fmon->nmon;
756 1.1 cgd else {
757 1.4 christos for (mtmp = fmon; mtmp->nmon != mon; mtmp = mtmp->nmon);
758 1.1 cgd mtmp->nmon = mon->nmon;
759 1.1 cgd }
760 1.1 cgd }
761 1.1 cgd
762 1.4 christos /*
763 1.4 christos * we do not free monsters immediately, in order to have their name available
764 1.4 christos * shortly after their demise
765 1.4 christos */
766 1.4 christos struct monst *fdmon; /* chain of dead monsters, need not to be
767 1.4 christos * saved */
768 1.1 cgd
769 1.4 christos void
770 1.4 christos monfree(mtmp)
771 1.4 christos struct monst *mtmp;
772 1.4 christos {
773 1.1 cgd mtmp->nmon = fdmon;
774 1.1 cgd fdmon = mtmp;
775 1.1 cgd }
776 1.1 cgd
777 1.4 christos void
778 1.4 christos dmonsfree()
779 1.4 christos {
780 1.4 christos struct monst *mtmp;
781 1.4 christos while ((mtmp = fdmon) != NULL) {
782 1.1 cgd fdmon = mtmp->nmon;
783 1.1 cgd free((char *) mtmp);
784 1.1 cgd }
785 1.1 cgd }
786 1.1 cgd
787 1.4 christos void
788 1.1 cgd unstuck(mtmp)
789 1.4 christos struct monst *mtmp;
790 1.1 cgd {
791 1.4 christos if (u.ustuck == mtmp) {
792 1.4 christos if (u.uswallow) {
793 1.1 cgd u.ux = mtmp->mx;
794 1.1 cgd u.uy = mtmp->my;
795 1.1 cgd u.uswallow = 0;
796 1.1 cgd setsee();
797 1.1 cgd docrt();
798 1.1 cgd }
799 1.1 cgd u.ustuck = 0;
800 1.1 cgd }
801 1.1 cgd }
802 1.1 cgd
803 1.4 christos void
804 1.1 cgd killed(mtmp)
805 1.4 christos struct monst *mtmp;
806 1.1 cgd {
807 1.1 cgd #ifdef lint
808 1.1 cgd #define NEW_SCORING
809 1.4 christos #endif /* lint */
810 1.4 christos int tmp, nk, x, y;
811 1.5 jsm const struct permonst *mdat;
812 1.1 cgd
813 1.4 christos if (mtmp->cham)
814 1.4 christos mtmp->data = PM_CHAMELEON;
815 1.1 cgd mdat = mtmp->data;
816 1.4 christos if (Blind)
817 1.4 christos pline("You destroy it!");
818 1.1 cgd else {
819 1.1 cgd pline("You destroy %s!",
820 1.4 christos mtmp->mtame ? amonnam(mtmp, "poor") : monnam(mtmp));
821 1.1 cgd }
822 1.4 christos if (u.umconf) {
823 1.4 christos if (!Blind)
824 1.4 christos pline("Your hands stop glowing blue.");
825 1.1 cgd u.umconf = 0;
826 1.1 cgd }
827 1.1 cgd /* count killed monsters */
828 1.1 cgd #define MAXMONNO 100
829 1.4 christos nk = 1; /* in case we cannot find it in mons */
830 1.4 christos tmp = mdat - mons; /* strchr in mons array (if not 'd', '@', ...) */
831 1.4 christos if (tmp >= 0 && tmp < CMNUM + 2) {
832 1.4 christos u.nr_killed[tmp]++;
833 1.4 christos if ((nk = u.nr_killed[tmp]) > MAXMONNO &&
834 1.4 christos !strchr(fut_geno, mdat->mlet))
835 1.4 christos charcat(fut_geno, mdat->mlet);
836 1.1 cgd }
837 1.1 cgd /* punish bad behaviour */
838 1.4 christos if (mdat->mlet == '@')
839 1.4 christos Telepat = 0, u.uluck -= 2;
840 1.4 christos if (mtmp->mpeaceful || mtmp->mtame)
841 1.4 christos u.uluck--;
842 1.4 christos if (mdat->mlet == 'u')
843 1.4 christos u.uluck -= 5;
844 1.4 christos if ((int) u.uluck < LUCKMIN)
845 1.4 christos u.uluck = LUCKMIN;
846 1.1 cgd
847 1.1 cgd /* give experience points */
848 1.1 cgd tmp = 1 + mdat->mlevel * mdat->mlevel;
849 1.4 christos if (mdat->ac < 3)
850 1.4 christos tmp += 2 * (7 - mdat->ac);
851 1.4 christos if (strchr("AcsSDXaeRTVWU&In:P", mdat->mlet))
852 1.4 christos tmp += 2 * mdat->mlevel;
853 1.4 christos if (strchr("DeV&P", mdat->mlet))
854 1.4 christos tmp += (7 * mdat->mlevel);
855 1.4 christos if (mdat->mlevel > 6)
856 1.4 christos tmp += 50;
857 1.4 christos if (mdat->mlet == ';')
858 1.4 christos tmp += 1000;
859 1.1 cgd
860 1.1 cgd #ifdef NEW_SCORING
861 1.4 christos /*
862 1.4 christos * ------- recent addition: make nr of points decrease when this is
863 1.4 christos * not the first of this kind
864 1.4 christos */
865 1.4 christos {
866 1.4 christos int ul = u.ulevel;
867 1.4 christos int ml = mdat->mlevel;
868 1.4 christos
869 1.4 christos if (ul < 14) /* points are given based on present and
870 1.4 christos * future level */
871 1.4 christos for (tmp2 = 0; !tmp2 || ul + tmp2 <= ml; tmp2++)
872 1.4 christos if (u.uexp + 1 + (tmp + ((tmp2 <= 0) ? 0 : 4 << (tmp2 - 1))) / nk
873 1.4 christos >= 10 * pow((unsigned) (ul - 1)))
874 1.4 christos if (++ul == 14)
875 1.4 christos break;
876 1.4 christos
877 1.4 christos tmp2 = ml - ul - 1;
878 1.4 christos tmp = (tmp + ((tmp2 < 0) ? 0 : 4 << tmp2)) / nk;
879 1.4 christos if (!tmp)
880 1.4 christos tmp = 1;
881 1.1 cgd }
882 1.1 cgd /* note: ul is not necessarily the future value of u.ulevel */
883 1.1 cgd /* ------- end of recent valuation change ------- */
884 1.4 christos #endif /* NEW_SCORING */
885 1.1 cgd
886 1.4 christos more_experienced(tmp, 0);
887 1.1 cgd flags.botl = 1;
888 1.4 christos while (u.ulevel < 14 && u.uexp >= newuexp()) {
889 1.1 cgd pline("Welcome to experience level %u.", ++u.ulevel);
890 1.1 cgd tmp = rnd(10);
891 1.4 christos if (tmp < 3)
892 1.4 christos tmp = rnd(10);
893 1.1 cgd u.uhpmax += tmp;
894 1.1 cgd u.uhp += tmp;
895 1.1 cgd flags.botl = 1;
896 1.1 cgd }
897 1.1 cgd
898 1.1 cgd /* dispose of monster and make cadaver */
899 1.4 christos x = mtmp->mx;
900 1.4 christos y = mtmp->my;
901 1.1 cgd mondead(mtmp);
902 1.1 cgd tmp = mdat->mlet;
903 1.4 christos if (tmp == 'm') { /* he killed a minotaur, give him a wand of
904 1.4 christos * digging */
905 1.4 christos /* note: the dead minotaur will be on top of it! */
906 1.1 cgd mksobj_at(WAN_DIGGING, x, y);
907 1.1 cgd /* if(cansee(x,y)) atl(x,y,fobj->olet); */
908 1.1 cgd stackobj(fobj);
909 1.1 cgd } else
910 1.1 cgd #ifndef NOWORM
911 1.4 christos if (tmp == 'w') {
912 1.1 cgd mksobj_at(WORM_TOOTH, x, y);
913 1.1 cgd stackobj(fobj);
914 1.1 cgd } else
915 1.4 christos #endif /* NOWORM */
916 1.4 christos if (!letter(tmp) || (!strchr("mw", tmp) && !rn2(3)))
917 1.4 christos tmp = 0;
918 1.4 christos
919 1.4 christos if (ACCESSIBLE(levl[x][y].typ)) /* might be mimic in wall or dead eel */
920 1.4 christos if (x != u.ux || y != u.uy) /* might be here after
921 1.4 christos * swallowed */
922 1.4 christos if (strchr("NTVm&", mdat->mlet) || rn2(5)) {
923 1.4 christos struct obj *obj2 = mkobj_at(tmp, x, y);
924 1.4 christos if (cansee(x, y))
925 1.4 christos atl(x, y, obj2->olet);
926 1.4 christos stackobj(obj2);
927 1.4 christos }
928 1.1 cgd }
929 1.1 cgd
930 1.4 christos void
931 1.5 jsm kludge(const char *str, const char *arg)
932 1.4 christos {
933 1.4 christos if (Blind) {
934 1.4 christos if (*str == '%')
935 1.4 christos pline(str, "It");
936 1.4 christos else
937 1.4 christos pline(str, "it");
938 1.4 christos } else
939 1.4 christos pline(str, arg);
940 1.1 cgd }
941 1.1 cgd
942 1.4 christos void
943 1.4 christos rescham()
944 1.4 christos { /* force all chameleons to become normal */
945 1.4 christos struct monst *mtmp;
946 1.1 cgd
947 1.4 christos for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
948 1.4 christos if (mtmp->cham) {
949 1.1 cgd mtmp->cham = 0;
950 1.1 cgd (void) newcham(mtmp, PM_CHAMELEON);
951 1.1 cgd }
952 1.1 cgd }
953 1.1 cgd
954 1.4 christos int
955 1.4 christos newcham(mtmp, mdat) /* make a chameleon look like a new monster */
956 1.4 christos /* returns 1 if the monster actually changed */
957 1.4 christos struct monst *mtmp;
958 1.5 jsm const struct permonst *mdat;
959 1.1 cgd {
960 1.4 christos int mhp, hpn, hpd;
961 1.1 cgd
962 1.4 christos if (mdat == mtmp->data)
963 1.4 christos return (0); /* still the same monster */
964 1.1 cgd #ifndef NOWORM
965 1.4 christos if (mtmp->wormno)
966 1.4 christos wormdead(mtmp); /* throw tail away */
967 1.4 christos #endif /* NOWORM */
968 1.1 cgd if (u.ustuck == mtmp) {
969 1.1 cgd if (u.uswallow) {
970 1.1 cgd u.uswallow = 0;
971 1.1 cgd u.uswldtim = 0;
972 1.4 christos mnexto(mtmp);
973 1.4 christos docrt();
974 1.4 christos prme();
975 1.1 cgd }
976 1.1 cgd u.ustuck = 0;
977 1.1 cgd }
978 1.1 cgd hpn = mtmp->mhp;
979 1.4 christos hpd = (mtmp->data->mlevel) * 8;
980 1.4 christos if (!hpd)
981 1.4 christos hpd = 4;
982 1.1 cgd mtmp->data = mdat;
983 1.4 christos mhp = (mdat->mlevel) * 8;
984 1.1 cgd /* new hp: same fraction of max as before */
985 1.4 christos mtmp->mhp = 2 + (hpn * mhp) / hpd;
986 1.1 cgd hpn = mtmp->mhpmax;
987 1.4 christos mtmp->mhpmax = 2 + (hpn * mhp) / hpd;
988 1.1 cgd mtmp->minvis = (mdat->mlet == 'I') ? 1 : 0;
989 1.1 cgd #ifndef NOWORM
990 1.4 christos if (mdat->mlet == 'w' && getwn(mtmp))
991 1.4 christos initworm(mtmp);
992 1.4 christos /* perhaps we should clear mtmp->mtame here? */
993 1.4 christos #endif /* NOWORM */
994 1.4 christos unpmon(mtmp); /* necessary for 'I' and to force pmon */
995 1.1 cgd pmon(mtmp);
996 1.4 christos return (1);
997 1.1 cgd }
998 1.1 cgd
999 1.4 christos void
1000 1.4 christos mnexto(mtmp) /* Make monster mtmp next to you (if
1001 1.4 christos * possible) */
1002 1.4 christos struct monst *mtmp;
1003 1.1 cgd {
1004 1.4 christos coord mm;
1005 1.1 cgd mm = enexto(u.ux, u.uy);
1006 1.1 cgd mtmp->mx = mm.x;
1007 1.1 cgd mtmp->my = mm.y;
1008 1.1 cgd pmon(mtmp);
1009 1.1 cgd }
1010 1.1 cgd
1011 1.4 christos int
1012 1.4 christos ishuman(mtmp)
1013 1.4 christos struct monst *mtmp;
1014 1.4 christos {
1015 1.4 christos return (mtmp->data->mlet == '@');
1016 1.1 cgd }
1017 1.1 cgd
1018 1.4 christos void
1019 1.4 christos setmangry(mtmp)
1020 1.4 christos struct monst *mtmp;
1021 1.4 christos {
1022 1.4 christos if (!mtmp->mpeaceful)
1023 1.4 christos return;
1024 1.4 christos if (mtmp->mtame)
1025 1.4 christos return;
1026 1.1 cgd mtmp->mpeaceful = 0;
1027 1.4 christos if (ishuman(mtmp))
1028 1.4 christos pline("%s gets angry!", Monnam(mtmp));
1029 1.1 cgd }
1030 1.1 cgd
1031 1.4 christos /*
1032 1.4 christos * not one hundred procent correct: now a snake may hide under an invisible
1033 1.4 christos * object
1034 1.4 christos */
1035 1.4 christos int
1036 1.1 cgd canseemon(mtmp)
1037 1.4 christos struct monst *mtmp;
1038 1.1 cgd {
1039 1.4 christos return ((!mtmp->minvis || See_invisible)
1040 1.4 christos && (!mtmp->mhide || !o_at(mtmp->mx, mtmp->my))
1041 1.1 cgd && cansee(mtmp->mx, mtmp->my));
1042 1.1 cgd }
1043