]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.mon.c
8ee9b4706cd7f76e21785f1a1a14c453832ce79e
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 int warnlevel
; /* used by movemon and dochugw */
81 const char *const warnings
[] = {
82 "white", "pink", "red", "ruby", "purple", "black"
94 /* find a monster that we haven't treated yet */
96 * note that mtmp or mtmp->nmon might get killed while mtmp
97 * moves, so we cannot just walk down the chain (even new
98 * monsters might get created!)
100 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
101 if (mtmp
->mlstmv
< moves
)
103 /* treated all monsters */
107 mtmp
->mlstmv
= moves
;
109 /* most monsters drown in pools */
111 boolean inpool
, iseel
;
113 inpool
= (levl
[mtmp
->mx
][mtmp
->my
].typ
== POOL
);
114 iseel
= (mtmp
->data
->mlet
== ';');
115 if (inpool
&& !iseel
) {
116 if (cansee(mtmp
->mx
, mtmp
->my
))
117 pline("%s drowns.", Monnam(mtmp
));
121 /* but eels have a difficult time outside */
122 if (iseel
&& !inpool
) {
129 if (mtmp
->mblinded
&& !--mtmp
->mblinded
)
131 if (mtmp
->mfleetim
&& !--mtmp
->mfleetim
)
135 if (mtmp
->mspeed
!= MSLOW
|| !(moves
% 2)) {
136 /* continue if the monster died fighting */
138 if (Conflict
&& cansee(mtmp
->mx
, mtmp
->my
)
139 && (fr
= fightm(mtmp
)) == 2)
141 if (fr
< 0 && dochugw(mtmp
))
144 if (mtmp
->mspeed
== MFAST
&& dochugw(mtmp
))
148 warnlevel
-= u
.ulevel
;
149 if (warnlevel
>= SIZE(warnings
))
150 warnlevel
= SIZE(warnings
) - 1;
152 if (warnlevel
> lastwarnlev
|| moves
> lastwarntime
+ 5) {
154 switch (Warning
& (LEFT_RING
| RIGHT_RING
)) {
156 rr
= "Your left ring glows";
159 rr
= "Your right ring glows";
161 case LEFT_RING
| RIGHT_RING
:
162 rr
= "Both your rings glow";
165 rr
= "Your fingertips glow";
168 pline("%s %s!", rr
, warnings
[warnlevel
]);
169 lastwarntime
= moves
;
170 lastwarnlev
= warnlevel
;
172 dmonsfree(); /* remove all dead monsters */
176 justswld(struct monst
*mtmp
, const char *name
)
183 kludge("%s swallows you!", name
);
192 youswld(struct monst
*mtmp
, int dam
, int die
, const char *name
)
194 if (mtmp
!= u
.ustuck
)
196 kludge("%s digests you!", name
);
198 if (u
.uswldtim
++ >= die
) { /* a3 */
199 pline("It totally digests you!");
205 flags
.botlx
= 1; /* should we show status line ? */
210 dochugw(struct monst
*mtmp
)
214 int dead
= dochug(mtmp
);
217 if (!dead
) /* monster still alive */
219 if (!mtmp
->mpeaceful
)
220 if (mtmp
->data
->mlevel
> warnlevel
)
221 if ((dd
= dist(mtmp
->mx
, mtmp
->my
)) < dist(x
, y
))
223 if (!canseemon(mtmp
))
224 warnlevel
= mtmp
->data
->mlevel
;
228 /* returns 1 if monster died moving, 0 otherwise */
230 dochug(struct monst
*mtmp
)
232 const struct permonst
*mdat
;
233 int tmp
= 0, nearby
, scared
;
235 if (mtmp
->cham
&& !rn2(6))
236 (void) newcham(mtmp
, &mons
[dlevel
+ 14 + rn2(CMNUM
- 14 - dlevel
)]);
238 if (mdat
->mlevel
< 0)
239 panic("bad monster %c (%d)", mdat
->mlet
, mdat
->mlevel
);
241 /* regenerate monsters */
242 if ((!(moves
% 20) || strchr(MREGEN
, mdat
->mlet
)) &&
243 mtmp
->mhp
< mtmp
->mhpmax
)
247 return (0); /* frozen monsters don't do anything */
250 /* wake up, or get out of here. */
251 /* ettins are hard to surprise */
252 /* Nymphs and Leprechauns do not easily wake up */
253 if (cansee(mtmp
->mx
, mtmp
->my
) &&
254 (!Stealth
|| (mdat
->mlet
== 'e' && rn2(10))) &&
255 (!strchr("NL", mdat
->mlet
) || !rn2(50)) &&
256 (Aggravate_monster
|| strchr("d1", mdat
->mlet
)
257 || (!rn2(7) && !mtmp
->mimic
)))
262 /* not frozen or sleeping: wipe out texts written in the dust */
263 wipe_engr_at(mtmp
->mx
, mtmp
->my
, 1);
265 /* confused monsters get unconfused with small probability */
266 if (mtmp
->mconf
&& !rn2(50))
269 /* some monsters teleport */
270 if (mtmp
->mflee
&& strchr("tNL", mdat
->mlet
) && !rn2(40)) {
274 if (mdat
->mmove
< rnd(6))
277 /* fleeing monsters might regain courage */
278 if (mtmp
->mflee
&& !mtmp
->mfleetim
279 && mtmp
->mhp
== mtmp
->mhpmax
&& !rn2(25))
282 nearby
= (dist(mtmp
->mx
, mtmp
->my
) < 3);
283 scared
= (nearby
&& (sengr_at("Elbereth", u
.ux
, u
.uy
) ||
284 sobj_at(SCR_SCARE_MONSTER
, u
.ux
, u
.uy
)));
285 if (scared
&& !mtmp
->mflee
) {
287 mtmp
->mfleetim
= (rn2(7) ? rnd(10) : rnd(100));
292 (mtmp
->minvis
&& !rn2(3)) ||
293 (strchr("BIuy", mdat
->mlet
) && !rn2(4)) ||
294 (mdat
->mlet
== 'L' && !u
.ugold
&& (mtmp
->mgold
|| rn2(2))) ||
295 (!mtmp
->mcansee
&& !rn2(4)) ||
298 tmp
= m_move(mtmp
, 0); /* 2: monster died moving */
299 if (tmp
== 2 || (tmp
&& mdat
->mmove
<= 12))
302 if (!strchr("Ea", mdat
->mlet
) && nearby
&&
303 !mtmp
->mpeaceful
&& u
.uhp
> 0 && !scared
) {
305 return (1); /* monster died (e.g. 'y' or 'F') */
307 /* extra movement for fast monsters */
308 if (mdat
->mmove
- 12 > rnd(12))
309 tmp
= m_move(mtmp
, 1);
314 m_move(struct monst
*mtmp
, int after
)
317 int nx
, ny
, omx
, omy
, appr
, nearer
, cnt
, i
, j
;
318 xchar gx
, gy
, nix
, niy
, chcnt
;
320 boolean likegold
= 0, likegems
= 0, likeobjs
= 0;
321 char msym
= mtmp
->data
->mlet
;
322 schar mmoved
= 0; /* not strictly nec.: chi >= 0 will
327 if (mtmp
->mfroz
|| mtmp
->msleep
)
329 if (mtmp
->mtrapped
) {
332 return (2); /* he died */
334 return (0); /* still in trap, so didnt move */
336 if (mtmp
->mhide
&& o_at(mtmp
->mx
, mtmp
->my
) && rn2(10))
337 return (0); /* do not leave hiding place */
344 /* my dog gets a special treatment */
346 return (dog_move(mtmp
, after
));
348 /* likewise for shopkeeper */
350 mmoved
= shk_move(mtmp
);
353 mmoved
= 0; /* follow player outside shop */
355 /* and for the guard */
361 * teleport if that lies in our nature ('t') or when badly wounded
364 if ((msym
== 't' && !rn2(5))
365 || (msym
== '1' && (mtmp
->mhp
< 7 || (!xdnstair
&& !rn2(5))
366 || levl
[u
.ux
][u
.uy
].typ
== STAIRS
))) {
367 if (mtmp
->mhp
< 7 || (msym
== 't' && rn2(2)))
374 /* spit fire ('D') or use a wand ('1') when appropriate */
375 if (strchr("D1", msym
))
378 if (msym
== 'U' && !mtmp
->mcan
&& canseemon(mtmp
) &&
379 mtmp
->mcansee
&& rn2(5)) {
381 pline("%s's gaze has confused you!", Monnam(mtmp
));
383 pline("You are getting more and more confused.");
386 Confusion
+= d(3, 4); /* timeout */
389 if (!mtmp
->mflee
&& u
.uswallow
&& u
.ustuck
!= mtmp
)
394 if (mtmp
->mconf
|| Invis
|| !mtmp
->mcansee
||
395 (strchr("BIy", msym
) && !rn2(3)))
401 if (msym
== 'L' && appr
== 1 && mtmp
->mgold
> u
.ugold
)
405 * random criterion for 'smell' or track finding ability should use
406 * mtmp->msmell or sth
409 ('a' <= msym
&& msym
<= 'z')) {
412 mroom
= inroom(omx
, omy
);
413 if (mroom
< 0 || mroom
!= inroom(u
.ux
, u
.uy
)) {
414 cp
= gettrack(omx
, omy
);
421 /* look for gold or jewels nearby */
422 likegold
= (strchr("LOD", msym
) != NULL
);
423 likegems
= (strchr("ODu", msym
) != NULL
);
424 likeobjs
= mtmp
->mhide
;
425 #define SRCHRADIUS 25
427 xchar mind
= SRCHRADIUS
; /* not too far away */
431 for (gold
= fgold
; gold
; gold
= gold
->ngold
)
432 if ((dd
= DIST(omx
, omy
, gold
->gx
, gold
->gy
)) < mind
) {
438 if (likegems
|| likeobjs
) {
440 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
441 if (likeobjs
|| otmp
->olet
== GEM_SYM
)
443 objects
[otmp
->otyp
].g_val
!= 0)
444 if ((dd
= DIST(omx
, omy
, otmp
->ox
, otmp
->oy
)) < mind
) {
450 if (mind
< SRCHRADIUS
&& appr
== -1) {
451 if (dist(omx
, omy
) < 10) {
460 cnt
= mfndpos(mtmp
, poss
, info
,
461 msym
== 'u' ? NOTONL
:
462 (msym
== '@' || msym
== '1') ? (ALLOW_SSM
| ALLOW_TRAPS
) :
463 strchr(UNDEAD
, msym
) ? NOGARLIC
: ALLOW_TRAPS
);
464 /* ALLOW_ROCK for some monsters ? */
467 for (i
= 0; i
< cnt
; i
++) {
470 for (j
= 0; j
< MTSZ
&& j
< cnt
- 1; j
++)
471 if (nx
== mtmp
->mtrack
[j
].x
&& ny
== mtmp
->mtrack
[j
].y
)
472 if (rn2(4 * (cnt
- j
)))
475 /* some stupid compilers think that this is too complicated */
477 int d1
= DIST(nx
, ny
, gx
, gy
);
478 int d2
= DIST(nix
, niy
, gx
, gy
);
482 nearer
= (DIST(nx
, ny
, gx
, gy
) < DIST(nix
, niy
, gx
, gy
));
484 if ((appr
== 1 && nearer
) || (appr
== -1 && !nearer
) ||
486 (!appr
&& !rn2(++chcnt
))) {
495 if (info
[chi
] & ALLOW_M
) {
496 mtmp2
= m_at(nix
, niy
);
498 panic("error in m_move");
499 if (hitmm(mtmp
, mtmp2
) == 1 && rn2(4) &&
500 hitmm(mtmp2
, mtmp
) == 2)
504 if (info
[chi
] & ALLOW_U
) {
505 (void) hitu(mtmp
, d(mtmp
->data
->damn
, mtmp
->data
->damd
) + 1);
510 for (j
= MTSZ
- 1; j
> 0; j
--)
511 mtmp
->mtrack
[j
] = mtmp
->mtrack
[j
- 1];
512 mtmp
->mtrack
[0].x
= omx
;
513 mtmp
->mtrack
[0].y
= omy
;
519 if (msym
== 'u' && rn2(2)) {
530 if (mintrap(mtmp
) == 2) /* he died */
537 mtmp
->mundetected
= 1;
544 mpickgold(struct monst
*mtmp
)
547 while ((gold
= g_at(mtmp
->mx
, mtmp
->my
)) != NULL
) {
548 mtmp
->mgold
+= gold
->amount
;
550 if (levl
[mtmp
->mx
][mtmp
->my
].scrsym
== '$')
551 newsym(mtmp
->mx
, mtmp
->my
);
556 mpickgems(struct monst
*mtmp
)
559 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
560 if (otmp
->olet
== GEM_SYM
)
561 if (otmp
->ox
== mtmp
->mx
&& otmp
->oy
== mtmp
->my
)
562 if (mtmp
->data
->mlet
!= 'u' || objects
[otmp
->otyp
].g_val
!= 0) {
564 mpickobj(mtmp
, otmp
);
565 if (levl
[mtmp
->mx
][mtmp
->my
].scrsym
== GEM_SYM
)
566 newsym(mtmp
->mx
, mtmp
->my
); /* %% */
567 return; /* pick only one object */
571 /* return number of acceptable neighbour positions */
573 mfndpos(struct monst
*mon
, coord poss
[9], int info
[9], int flag
)
575 int x
, y
, nx
, ny
, cnt
= 0, ntyp
;
582 nowtyp
= levl
[x
][y
].typ
;
584 pool
= (mon
->data
->mlet
== ';');
585 nexttry
: /* eels prefer the water, but if there is no
586 * water nearby, they will crawl over land */
591 for (nx
= x
- 1; nx
<= x
+ 1; nx
++)
592 for (ny
= y
- 1; ny
<= y
+ 1; ny
++)
593 if (nx
!= x
|| ny
!= y
)
595 if (!IS_ROCK(ntyp
= levl
[nx
][ny
].typ
))
596 if (!(nx
!= x
&& ny
!= y
&& (nowtyp
== DOOR
|| ntyp
== DOOR
)))
597 if ((ntyp
== POOL
) == pool
) {
599 if (nx
== u
.ux
&& ny
== u
.uy
) {
600 if (!(flag
& ALLOW_U
))
603 } else if ((mtmp
= m_at(nx
, ny
)) != NULL
) {
604 if (!(flag
& ALLOW_M
))
608 if (!(flag
& ALLOW_TM
))
610 info
[cnt
] |= ALLOW_TM
;
613 if (sobj_at(CLOVE_OF_GARLIC
, nx
, ny
)) {
616 info
[cnt
] |= NOGARLIC
;
618 if (sobj_at(SCR_SCARE_MONSTER
, nx
, ny
) ||
619 (!mon
->mpeaceful
&& sengr_at("Elbereth", nx
, ny
))) {
620 if (!(flag
& ALLOW_SSM
))
622 info
[cnt
] |= ALLOW_SSM
;
624 if (sobj_at(ENORMOUS_ROCK
, nx
, ny
)) {
625 if (!(flag
& ALLOW_ROCK
))
627 info
[cnt
] |= ALLOW_ROCK
;
629 if (!Invis
&& online(nx
, ny
)) {
642 struct trap
*ttmp
= t_at(nx
, ny
);
645 tt
= 1 << ttmp
->ttyp
;
646 if (mon
->mtrapseen
& tt
) {
657 if (!cnt
&& pool
&& nowtyp
!= POOL
) {
667 return ((x
- u
.ux
) * (x
- u
.ux
) + (y
- u
.uy
) * (y
- u
.uy
));
671 poisoned(const char *string
, const char *pname
)
676 pline("It was poisoned.");
678 pline("The %s was poisoned!", string
);
679 if (Poison_resistance
) {
680 pline("The poison doesn't seem to affect you.");
686 pline("I am afraid the poison was deadly ...");
690 losehp(rn1(10, 6), pname
);
699 mondead(struct monst
*mtmp
)
716 /* called when monster is moved to larger structure */
718 replmon(struct monst
*mtmp
, struct monst
*mtmp2
)
724 if (u
.ustuck
== mtmp
)
727 replshk(mtmp
, mtmp2
);
733 relmon(struct monst
*mon
)
740 for (mtmp
= fmon
; mtmp
->nmon
!= mon
; mtmp
= mtmp
->nmon
);
741 mtmp
->nmon
= mon
->nmon
;
746 * we do not free monsters immediately, in order to have their name available
747 * shortly after their demise
749 struct monst
*fdmon
; /* chain of dead monsters, need not to be
753 monfree(struct monst
*mtmp
)
763 while ((mtmp
= fdmon
) != NULL
) {
770 unstuck(struct monst
*mtmp
)
772 if (u
.ustuck
== mtmp
) {
785 killed(struct monst
*mtmp
)
791 const struct permonst
*mdat
;
794 mtmp
->data
= PM_CHAMELEON
;
797 pline("You destroy it!");
799 pline("You destroy %s!",
800 mtmp
->mtame
? amonnam(mtmp
, "poor") : monnam(mtmp
));
804 pline("Your hands stop glowing blue.");
807 /* count killed monsters */
809 nk
= 1; /* in case we cannot find it in mons */
810 tmp
= mdat
- mons
; /* strchr in mons array (if not 'd', '@', ...) */
811 if (tmp
>= 0 && tmp
< CMNUM
+ 2) {
813 if ((nk
= u
.nr_killed
[tmp
]) > MAXMONNO
&&
814 !strchr(fut_geno
, mdat
->mlet
))
815 charcat(fut_geno
, mdat
->mlet
);
817 /* punish bad behaviour */
818 if (mdat
->mlet
== '@')
819 Telepat
= 0, u
.uluck
-= 2;
820 if (mtmp
->mpeaceful
|| mtmp
->mtame
)
822 if (mdat
->mlet
== 'u')
824 if ((int) u
.uluck
< LUCKMIN
)
827 /* give experience points */
828 tmp
= 1 + mdat
->mlevel
* mdat
->mlevel
;
830 tmp
+= 2 * (7 - mdat
->ac
);
831 if (strchr("AcsSDXaeRTVWU&In:P", mdat
->mlet
))
832 tmp
+= 2 * mdat
->mlevel
;
833 if (strchr("DeV&P", mdat
->mlet
))
834 tmp
+= (7 * mdat
->mlevel
);
835 if (mdat
->mlevel
> 6)
837 if (mdat
->mlet
== ';')
842 * ------- recent addition: make nr of points decrease when this is
843 * not the first of this kind
847 int ml
= mdat
->mlevel
;
849 if (ul
< 14) /* points are given based on present and
851 for (tmp2
= 0; !tmp2
|| ul
+ tmp2
<= ml
; tmp2
++)
852 if (u
.uexp
+ 1 + (tmp
+ ((tmp2
<= 0) ? 0 : 4 << (tmp2
- 1))) / nk
853 >= 10 * pow((unsigned) (ul
- 1)))
858 tmp
= (tmp
+ ((tmp2
< 0) ? 0 : 4 << tmp2
)) / nk
;
862 /* note: ul is not necessarily the future value of u.ulevel */
863 /* ------- end of recent valuation change ------- */
864 #endif /* NEW_SCORING */
866 more_experienced(tmp
, 0);
868 while (u
.ulevel
< 14 && u
.uexp
>= newuexp()) {
869 pline("Welcome to experience level %u.", ++u
.ulevel
);
878 /* dispose of monster and make cadaver */
883 if (tmp
== 'm') { /* he killed a minotaur, give him a wand of
885 /* note: the dead minotaur will be on top of it! */
886 mksobj_at(WAN_DIGGING
, x
, y
);
887 /* if(cansee(x,y)) atl(x,y,fobj->olet); */
892 mksobj_at(WORM_TOOTH
, x
, y
);
896 if (!letter(tmp
) || (!strchr("mw", tmp
) && !rn2(3)))
899 if (ACCESSIBLE(levl
[x
][y
].typ
)) /* might be mimic in wall or dead eel */
900 if (x
!= u
.ux
|| y
!= u
.uy
) /* might be here after
902 if (strchr("NTVm&", mdat
->mlet
) || rn2(5)) {
903 struct obj
*obj2
= mkobj_at(tmp
, x
, y
);
905 atl(x
, y
, obj2
->olet
);
911 kludge(const char *str
, const char *arg
)
924 { /* force all chameleons to become normal */
927 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
930 (void) newcham(mtmp
, PM_CHAMELEON
);
934 /* make a chameleon look like a new monster */
935 /* returns 1 if the monster actually changed */
937 newcham(struct monst
*mtmp
, const struct permonst
*mdat
)
941 if (mdat
== mtmp
->data
)
942 return (0); /* still the same monster */
945 wormdead(mtmp
); /* throw tail away */
947 if (u
.ustuck
== mtmp
) {
958 hpd
= (mtmp
->data
->mlevel
) * 8;
962 mhp
= (mdat
->mlevel
) * 8;
963 /* new hp: same fraction of max as before */
964 mtmp
->mhp
= 2 + (hpn
* mhp
) / hpd
;
966 mtmp
->mhpmax
= 2 + (hpn
* mhp
) / hpd
;
967 mtmp
->minvis
= (mdat
->mlet
== 'I') ? 1 : 0;
969 if (mdat
->mlet
== 'w' && getwn(mtmp
))
971 /* perhaps we should clear mtmp->mtame here? */
973 unpmon(mtmp
); /* necessary for 'I' and to force pmon */
978 /* Make monster mtmp next to you (if possible) */
980 mnexto(struct monst
*mtmp
)
983 mm
= enexto(u
.ux
, u
.uy
);
990 ishuman(struct monst
*mtmp
)
992 return (mtmp
->data
->mlet
== '@');
996 setmangry(struct monst
*mtmp
)
998 if (!mtmp
->mpeaceful
)
1002 mtmp
->mpeaceful
= 0;
1004 pline("%s gets angry!", Monnam(mtmp
));
1008 * not one hundred procent correct: now a snake may hide under an invisible
1012 canseemon(struct monst
*mtmp
)
1014 return ((!mtmp
->minvis
|| See_invisible
)
1015 && (!mtmp
->mhide
|| !o_at(mtmp
->mx
, mtmp
->my
))
1016 && cansee(mtmp
->mx
, mtmp
->my
));