1 /* $NetBSD: hack.mon.c,v 1.9 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.mon.c,v 1.9 2009/06/07 18:30:39 dholland Exp $");
72 #include "hack.mfndpos.h"
75 #define NULL (char *) 0
78 static int warnlevel
; /* used by movemon and dochugw */
79 static long lastwarntime
;
80 static int lastwarnlev
;
82 static const char *const warnings
[] = {
83 "white", "pink", "red", "ruby", "purple", "black"
86 static int dochugw(struct monst
*);
87 static void mpickgold(struct monst
*);
88 static void mpickgems(struct monst
*);
89 static void dmonsfree(void);
90 static int ishuman(struct monst
*);
101 /* find a monster that we haven't treated yet */
103 * note that mtmp or mtmp->nmon might get killed while mtmp
104 * moves, so we cannot just walk down the chain (even new
105 * monsters might get created!)
107 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
108 if (mtmp
->mlstmv
< moves
)
110 /* treated all monsters */
114 mtmp
->mlstmv
= moves
;
116 /* most monsters drown in pools */
118 boolean inpool
, iseel
;
120 inpool
= (levl
[mtmp
->mx
][mtmp
->my
].typ
== POOL
);
121 iseel
= (mtmp
->data
->mlet
== ';');
122 if (inpool
&& !iseel
) {
123 if (cansee(mtmp
->mx
, mtmp
->my
))
124 pline("%s drowns.", Monnam(mtmp
));
128 /* but eels have a difficult time outside */
129 if (iseel
&& !inpool
) {
136 if (mtmp
->mblinded
&& !--mtmp
->mblinded
)
138 if (mtmp
->mfleetim
&& !--mtmp
->mfleetim
)
142 if (mtmp
->mspeed
!= MSLOW
|| !(moves
% 2)) {
143 /* continue if the monster died fighting */
145 if (Conflict
&& cansee(mtmp
->mx
, mtmp
->my
)
146 && (fr
= fightm(mtmp
)) == 2)
148 if (fr
< 0 && dochugw(mtmp
))
151 if (mtmp
->mspeed
== MFAST
&& dochugw(mtmp
))
155 warnlevel
-= u
.ulevel
;
156 if (warnlevel
>= SIZE(warnings
))
157 warnlevel
= SIZE(warnings
) - 1;
159 if (warnlevel
> lastwarnlev
|| moves
> lastwarntime
+ 5) {
161 switch (Warning
& (LEFT_RING
| RIGHT_RING
)) {
163 rr
= "Your left ring glows";
166 rr
= "Your right ring glows";
168 case LEFT_RING
| RIGHT_RING
:
169 rr
= "Both your rings glow";
172 rr
= "Your fingertips glow";
175 pline("%s %s!", rr
, warnings
[warnlevel
]);
176 lastwarntime
= moves
;
177 lastwarnlev
= warnlevel
;
179 dmonsfree(); /* remove all dead monsters */
183 justswld(struct monst
*mtmp
, const char *name
)
190 kludge("%s swallows you!", name
);
199 youswld(struct monst
*mtmp
, int dam
, int die
, const char *name
)
201 if (mtmp
!= u
.ustuck
)
203 kludge("%s digests you!", name
);
205 if (u
.uswldtim
++ >= die
) { /* a3 */
206 pline("It totally digests you!");
212 flags
.botlx
= 1; /* should we show status line ? */
217 dochugw(struct monst
*mtmp
)
221 int dead
= dochug(mtmp
);
224 if (!dead
) /* monster still alive */
226 if (!mtmp
->mpeaceful
)
227 if (mtmp
->data
->mlevel
> warnlevel
)
228 if ((dd
= dist(mtmp
->mx
, mtmp
->my
)) < dist(x
, y
))
230 if (!canseemon(mtmp
))
231 warnlevel
= mtmp
->data
->mlevel
;
235 /* returns 1 if monster died moving, 0 otherwise */
237 dochug(struct monst
*mtmp
)
239 const struct permonst
*mdat
;
240 int tmp
= 0, nearby
, scared
;
242 if (mtmp
->cham
&& !rn2(6))
243 (void) newcham(mtmp
, &mons
[dlevel
+ 14 + rn2(CMNUM
- 14 - dlevel
)]);
245 if (mdat
->mlevel
< 0)
246 panic("bad monster %c (%d)", mdat
->mlet
, mdat
->mlevel
);
248 /* regenerate monsters */
249 if ((!(moves
% 20) || strchr(MREGEN
, mdat
->mlet
)) &&
250 mtmp
->mhp
< mtmp
->mhpmax
)
254 return (0); /* frozen monsters don't do anything */
257 /* wake up, or get out of here. */
258 /* ettins are hard to surprise */
259 /* Nymphs and Leprechauns do not easily wake up */
260 if (cansee(mtmp
->mx
, mtmp
->my
) &&
261 (!Stealth
|| (mdat
->mlet
== 'e' && rn2(10))) &&
262 (!strchr("NL", mdat
->mlet
) || !rn2(50)) &&
263 (Aggravate_monster
|| strchr("d1", mdat
->mlet
)
264 || (!rn2(7) && !mtmp
->mimic
)))
269 /* not frozen or sleeping: wipe out texts written in the dust */
270 wipe_engr_at(mtmp
->mx
, mtmp
->my
, 1);
272 /* confused monsters get unconfused with small probability */
273 if (mtmp
->mconf
&& !rn2(50))
276 /* some monsters teleport */
277 if (mtmp
->mflee
&& strchr("tNL", mdat
->mlet
) && !rn2(40)) {
281 if (mdat
->mmove
< rnd(6))
284 /* fleeing monsters might regain courage */
285 if (mtmp
->mflee
&& !mtmp
->mfleetim
286 && mtmp
->mhp
== mtmp
->mhpmax
&& !rn2(25))
289 nearby
= (dist(mtmp
->mx
, mtmp
->my
) < 3);
290 scared
= (nearby
&& (sengr_at("Elbereth", u
.ux
, u
.uy
) ||
291 sobj_at(SCR_SCARE_MONSTER
, u
.ux
, u
.uy
)));
292 if (scared
&& !mtmp
->mflee
) {
294 mtmp
->mfleetim
= (rn2(7) ? rnd(10) : rnd(100));
299 (mtmp
->minvis
&& !rn2(3)) ||
300 (strchr("BIuy", mdat
->mlet
) && !rn2(4)) ||
301 (mdat
->mlet
== 'L' && !u
.ugold
&& (mtmp
->mgold
|| rn2(2))) ||
302 (!mtmp
->mcansee
&& !rn2(4)) ||
305 tmp
= m_move(mtmp
, 0); /* 2: monster died moving */
306 if (tmp
== 2 || (tmp
&& mdat
->mmove
<= 12))
309 if (!strchr("Ea", mdat
->mlet
) && nearby
&&
310 !mtmp
->mpeaceful
&& u
.uhp
> 0 && !scared
) {
312 return (1); /* monster died (e.g. 'y' or 'F') */
314 /* extra movement for fast monsters */
315 if (mdat
->mmove
- 12 > rnd(12))
316 tmp
= m_move(mtmp
, 1);
321 m_move(struct monst
*mtmp
, int after
)
324 int nx
, ny
, omx
, omy
, appr
, nearer
, cnt
, i
, j
;
325 xchar gx
, gy
, nix
, niy
, chcnt
;
327 boolean likegold
= 0, likegems
= 0, likeobjs
= 0;
328 char msym
= mtmp
->data
->mlet
;
329 schar mmoved
= 0; /* not strictly nec.: chi >= 0 will
334 if (mtmp
->mfroz
|| mtmp
->msleep
)
336 if (mtmp
->mtrapped
) {
339 return (2); /* he died */
341 return (0); /* still in trap, so didnt move */
343 if (mtmp
->mhide
&& o_at(mtmp
->mx
, mtmp
->my
) && rn2(10))
344 return (0); /* do not leave hiding place */
351 /* my dog gets a special treatment */
353 return (dog_move(mtmp
, after
));
355 /* likewise for shopkeeper */
357 mmoved
= shk_move(mtmp
);
360 mmoved
= 0; /* follow player outside shop */
362 /* and for the guard */
368 * teleport if that lies in our nature ('t') or when badly wounded
371 if ((msym
== 't' && !rn2(5))
372 || (msym
== '1' && (mtmp
->mhp
< 7 || (!xdnstair
&& !rn2(5))
373 || levl
[u
.ux
][u
.uy
].typ
== STAIRS
))) {
374 if (mtmp
->mhp
< 7 || (msym
== 't' && rn2(2)))
381 /* spit fire ('D') or use a wand ('1') when appropriate */
382 if (strchr("D1", msym
))
385 if (msym
== 'U' && !mtmp
->mcan
&& canseemon(mtmp
) &&
386 mtmp
->mcansee
&& rn2(5)) {
388 pline("%s's gaze has confused you!", Monnam(mtmp
));
390 pline("You are getting more and more confused.");
393 Confusion
+= d(3, 4); /* timeout */
396 if (!mtmp
->mflee
&& u
.uswallow
&& u
.ustuck
!= mtmp
)
401 if (mtmp
->mconf
|| Invis
|| !mtmp
->mcansee
||
402 (strchr("BIy", msym
) && !rn2(3)))
408 if (msym
== 'L' && appr
== 1 && mtmp
->mgold
> u
.ugold
)
412 * random criterion for 'smell' or track finding ability should use
413 * mtmp->msmell or sth
416 ('a' <= msym
&& msym
<= 'z')) {
419 mroom
= inroom(omx
, omy
);
420 if (mroom
< 0 || mroom
!= inroom(u
.ux
, u
.uy
)) {
421 cp
= gettrack(omx
, omy
);
428 /* look for gold or jewels nearby */
429 likegold
= (strchr("LOD", msym
) != NULL
);
430 likegems
= (strchr("ODu", msym
) != NULL
);
431 likeobjs
= mtmp
->mhide
;
432 #define SRCHRADIUS 25
434 xchar mind
= SRCHRADIUS
; /* not too far away */
438 for (gold
= fgold
; gold
; gold
= gold
->ngold
)
439 if ((dd
= DIST(omx
, omy
, gold
->gx
, gold
->gy
)) < mind
) {
445 if (likegems
|| likeobjs
) {
447 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
448 if (likeobjs
|| otmp
->olet
== GEM_SYM
)
450 objects
[otmp
->otyp
].g_val
!= 0)
451 if ((dd
= DIST(omx
, omy
, otmp
->ox
, otmp
->oy
)) < mind
) {
457 if (mind
< SRCHRADIUS
&& appr
== -1) {
458 if (dist(omx
, omy
) < 10) {
467 cnt
= mfndpos(mtmp
, poss
, info
,
468 msym
== 'u' ? NOTONL
:
469 (msym
== '@' || msym
== '1') ? (ALLOW_SSM
| ALLOW_TRAPS
) :
470 strchr(UNDEAD
, msym
) ? NOGARLIC
: ALLOW_TRAPS
);
471 /* ALLOW_ROCK for some monsters ? */
474 for (i
= 0; i
< cnt
; i
++) {
477 for (j
= 0; j
< MTSZ
&& j
< cnt
- 1; j
++)
478 if (nx
== mtmp
->mtrack
[j
].x
&& ny
== mtmp
->mtrack
[j
].y
)
479 if (rn2(4 * (cnt
- j
)))
482 /* some stupid compilers think that this is too complicated */
484 int d1
= DIST(nx
, ny
, gx
, gy
);
485 int d2
= DIST(nix
, niy
, gx
, gy
);
489 nearer
= (DIST(nx
, ny
, gx
, gy
) < DIST(nix
, niy
, gx
, gy
));
491 if ((appr
== 1 && nearer
) || (appr
== -1 && !nearer
) ||
493 (!appr
&& !rn2(++chcnt
))) {
502 if (info
[chi
] & ALLOW_M
) {
503 mtmp2
= m_at(nix
, niy
);
505 panic("error in m_move");
506 if (hitmm(mtmp
, mtmp2
) == 1 && rn2(4) &&
507 hitmm(mtmp2
, mtmp
) == 2)
511 if (info
[chi
] & ALLOW_U
) {
512 (void) hitu(mtmp
, d(mtmp
->data
->damn
, mtmp
->data
->damd
) + 1);
517 for (j
= MTSZ
- 1; j
> 0; j
--)
518 mtmp
->mtrack
[j
] = mtmp
->mtrack
[j
- 1];
519 mtmp
->mtrack
[0].x
= omx
;
520 mtmp
->mtrack
[0].y
= omy
;
526 if (msym
== 'u' && rn2(2)) {
537 if (mintrap(mtmp
) == 2) /* he died */
544 mtmp
->mundetected
= 1;
551 mpickgold(struct monst
*mtmp
)
554 while ((gold
= g_at(mtmp
->mx
, mtmp
->my
)) != NULL
) {
555 mtmp
->mgold
+= gold
->amount
;
557 if (levl
[mtmp
->mx
][mtmp
->my
].scrsym
== '$')
558 newsym(mtmp
->mx
, mtmp
->my
);
563 mpickgems(struct monst
*mtmp
)
566 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
567 if (otmp
->olet
== GEM_SYM
)
568 if (otmp
->ox
== mtmp
->mx
&& otmp
->oy
== mtmp
->my
)
569 if (mtmp
->data
->mlet
!= 'u' || objects
[otmp
->otyp
].g_val
!= 0) {
571 mpickobj(mtmp
, otmp
);
572 if (levl
[mtmp
->mx
][mtmp
->my
].scrsym
== GEM_SYM
)
573 newsym(mtmp
->mx
, mtmp
->my
); /* %% */
574 return; /* pick only one object */
578 /* return number of acceptable neighbour positions */
580 mfndpos(struct monst
*mon
, coord poss
[9], int info
[9], int flag
)
582 int x
, y
, nx
, ny
, cnt
= 0, ntyp
;
589 nowtyp
= levl
[x
][y
].typ
;
591 pool
= (mon
->data
->mlet
== ';');
592 nexttry
: /* eels prefer the water, but if there is no
593 * water nearby, they will crawl over land */
598 for (nx
= x
- 1; nx
<= x
+ 1; nx
++)
599 for (ny
= y
- 1; ny
<= y
+ 1; ny
++)
600 if (nx
!= x
|| ny
!= y
)
602 if (!IS_ROCK(ntyp
= levl
[nx
][ny
].typ
))
603 if (!(nx
!= x
&& ny
!= y
&& (nowtyp
== DOOR
|| ntyp
== DOOR
)))
604 if ((ntyp
== POOL
) == pool
) {
606 if (nx
== u
.ux
&& ny
== u
.uy
) {
607 if (!(flag
& ALLOW_U
))
610 } else if ((mtmp
= m_at(nx
, ny
)) != NULL
) {
611 if (!(flag
& ALLOW_M
))
615 if (!(flag
& ALLOW_TM
))
617 info
[cnt
] |= ALLOW_TM
;
620 if (sobj_at(CLOVE_OF_GARLIC
, nx
, ny
)) {
623 info
[cnt
] |= NOGARLIC
;
625 if (sobj_at(SCR_SCARE_MONSTER
, nx
, ny
) ||
626 (!mon
->mpeaceful
&& sengr_at("Elbereth", nx
, ny
))) {
627 if (!(flag
& ALLOW_SSM
))
629 info
[cnt
] |= ALLOW_SSM
;
631 if (sobj_at(ENORMOUS_ROCK
, nx
, ny
)) {
632 if (!(flag
& ALLOW_ROCK
))
634 info
[cnt
] |= ALLOW_ROCK
;
636 if (!Invis
&& online(nx
, ny
)) {
649 struct trap
*ttmp
= t_at(nx
, ny
);
652 tt
= 1 << ttmp
->ttyp
;
653 if (mon
->mtrapseen
& tt
) {
664 if (!cnt
&& pool
&& nowtyp
!= POOL
) {
674 return ((x
- u
.ux
) * (x
- u
.ux
) + (y
- u
.uy
) * (y
- u
.uy
));
678 poisoned(const char *string
, const char *pname
)
683 pline("It was poisoned.");
685 pline("The %s was poisoned!", string
);
686 if (Poison_resistance
) {
687 pline("The poison doesn't seem to affect you.");
693 pline("I am afraid the poison was deadly ...");
697 losehp(rn1(10, 6), pname
);
706 mondead(struct monst
*mtmp
)
723 /* called when monster is moved to larger structure */
725 replmon(struct monst
*mtmp
, struct monst
*mtmp2
)
731 if (u
.ustuck
== mtmp
)
734 replshk(mtmp
, mtmp2
);
740 relmon(struct monst
*mon
)
747 for (mtmp
= fmon
; mtmp
->nmon
!= mon
; mtmp
= mtmp
->nmon
);
748 mtmp
->nmon
= mon
->nmon
;
753 * we do not free monsters immediately, in order to have their name available
754 * shortly after their demise
756 static struct monst
*fdmon
; /* chain of dead monsters, need not to be
760 monfree(struct monst
*mtmp
)
770 while ((mtmp
= fdmon
) != NULL
) {
777 unstuck(struct monst
*mtmp
)
779 if (u
.ustuck
== mtmp
) {
792 killed(struct monst
*mtmp
)
798 const struct permonst
*mdat
;
801 mtmp
->data
= PM_CHAMELEON
;
804 pline("You destroy it!");
806 pline("You destroy %s!",
807 mtmp
->mtame
? amonnam(mtmp
, "poor") : monnam(mtmp
));
811 pline("Your hands stop glowing blue.");
814 /* count killed monsters */
816 nk
= 1; /* in case we cannot find it in mons */
817 tmp
= mdat
- mons
; /* strchr in mons array (if not 'd', '@', ...) */
818 if (tmp
>= 0 && tmp
< CMNUM
+ 2) {
820 if ((nk
= u
.nr_killed
[tmp
]) > MAXMONNO
&&
821 !strchr(fut_geno
, mdat
->mlet
))
822 charcat(fut_geno
, mdat
->mlet
);
824 /* punish bad behaviour */
825 if (mdat
->mlet
== '@')
826 Telepat
= 0, u
.uluck
-= 2;
827 if (mtmp
->mpeaceful
|| mtmp
->mtame
)
829 if (mdat
->mlet
== 'u')
831 if ((int) u
.uluck
< LUCKMIN
)
834 /* give experience points */
835 tmp
= 1 + mdat
->mlevel
* mdat
->mlevel
;
837 tmp
+= 2 * (7 - mdat
->ac
);
838 if (strchr("AcsSDXaeRTVWU&In:P", mdat
->mlet
))
839 tmp
+= 2 * mdat
->mlevel
;
840 if (strchr("DeV&P", mdat
->mlet
))
841 tmp
+= (7 * mdat
->mlevel
);
842 if (mdat
->mlevel
> 6)
844 if (mdat
->mlet
== ';')
849 * ------- recent addition: make nr of points decrease when this is
850 * not the first of this kind
854 int ml
= mdat
->mlevel
;
856 if (ul
< 14) /* points are given based on present and
858 for (tmp2
= 0; !tmp2
|| ul
+ tmp2
<= ml
; tmp2
++)
859 if (u
.uexp
+ 1 + (tmp
+ ((tmp2
<= 0) ? 0 : 4 << (tmp2
- 1))) / nk
860 >= 10 * pow((unsigned) (ul
- 1)))
865 tmp
= (tmp
+ ((tmp2
< 0) ? 0 : 4 << tmp2
)) / nk
;
869 /* note: ul is not necessarily the future value of u.ulevel */
870 /* ------- end of recent valuation change ------- */
871 #endif /* NEW_SCORING */
873 more_experienced(tmp
, 0);
875 while (u
.ulevel
< 14 && u
.uexp
>= newuexp()) {
876 pline("Welcome to experience level %u.", ++u
.ulevel
);
885 /* dispose of monster and make cadaver */
890 if (tmp
== 'm') { /* he killed a minotaur, give him a wand of
892 /* note: the dead minotaur will be on top of it! */
893 mksobj_at(WAN_DIGGING
, x
, y
);
894 /* if(cansee(x,y)) atl(x,y,fobj->olet); */
899 mksobj_at(WORM_TOOTH
, x
, y
);
903 if (!letter(tmp
) || (!strchr("mw", tmp
) && !rn2(3)))
906 if (ACCESSIBLE(levl
[x
][y
].typ
)) /* might be mimic in wall or dead eel */
907 if (x
!= u
.ux
|| y
!= u
.uy
) /* might be here after
909 if (strchr("NTVm&", mdat
->mlet
) || rn2(5)) {
910 struct obj
*obj2
= mkobj_at(tmp
, x
, y
);
912 atl(x
, y
, obj2
->olet
);
918 kludge(const char *str
, const char *arg
)
931 { /* force all chameleons to become normal */
934 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
937 (void) newcham(mtmp
, PM_CHAMELEON
);
941 /* make a chameleon look like a new monster */
942 /* returns 1 if the monster actually changed */
944 newcham(struct monst
*mtmp
, const struct permonst
*mdat
)
948 if (mdat
== mtmp
->data
)
949 return (0); /* still the same monster */
952 wormdead(mtmp
); /* throw tail away */
954 if (u
.ustuck
== mtmp
) {
965 hpd
= (mtmp
->data
->mlevel
) * 8;
969 mhp
= (mdat
->mlevel
) * 8;
970 /* new hp: same fraction of max as before */
971 mtmp
->mhp
= 2 + (hpn
* mhp
) / hpd
;
973 mtmp
->mhpmax
= 2 + (hpn
* mhp
) / hpd
;
974 mtmp
->minvis
= (mdat
->mlet
== 'I') ? 1 : 0;
976 if (mdat
->mlet
== 'w' && getwn(mtmp
))
978 /* perhaps we should clear mtmp->mtame here? */
980 unpmon(mtmp
); /* necessary for 'I' and to force pmon */
985 /* Make monster mtmp next to you (if possible) */
987 mnexto(struct monst
*mtmp
)
990 mm
= enexto(u
.ux
, u
.uy
);
997 ishuman(struct monst
*mtmp
)
999 return (mtmp
->data
->mlet
== '@');
1003 setmangry(struct monst
*mtmp
)
1005 if (!mtmp
->mpeaceful
)
1009 mtmp
->mpeaceful
= 0;
1011 pline("%s gets angry!", Monnam(mtmp
));
1015 * not one hundred procent correct: now a snake may hide under an invisible
1019 canseemon(struct monst
*mtmp
)
1021 return ((!mtmp
->minvis
|| See_invisible
)
1022 && (!mtmp
->mhide
|| !o_at(mtmp
->mx
, mtmp
->my
))
1023 && cansee(mtmp
->mx
, mtmp
->my
));