]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.mon.c
1 /* $NetBSD: hack.mon.c,v 1.4 1997/10/19 16:58:34 christos Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.mon.c,v 1.4 1997/10/19 16:58:34 christos Exp $");
15 #include "hack.mfndpos.h"
18 #define NULL (char *) 0
21 int warnlevel
; /* used by movemon and dochugw */
25 "white", "pink", "red", "ruby", "purple", "black"
37 /* find a monster that we haven't treated yet */
39 * note that mtmp or mtmp->nmon might get killed while mtmp
40 * moves, so we cannot just walk down the chain (even new
41 * monsters might get created!)
43 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
44 if (mtmp
->mlstmv
< moves
)
46 /* treated all monsters */
52 /* most monsters drown in pools */
54 boolean inpool
, iseel
;
56 inpool
= (levl
[mtmp
->mx
][mtmp
->my
].typ
== POOL
);
57 iseel
= (mtmp
->data
->mlet
== ';');
58 if (inpool
&& !iseel
) {
59 if (cansee(mtmp
->mx
, mtmp
->my
))
60 pline("%s drowns.", Monnam(mtmp
));
64 /* but eels have a difficult time outside */
65 if (iseel
&& !inpool
) {
72 if (mtmp
->mblinded
&& !--mtmp
->mblinded
)
74 if (mtmp
->mfleetim
&& !--mtmp
->mfleetim
)
78 if (mtmp
->mspeed
!= MSLOW
|| !(moves
% 2)) {
79 /* continue if the monster died fighting */
81 if (Conflict
&& cansee(mtmp
->mx
, mtmp
->my
)
82 && (fr
= fightm(mtmp
)) == 2)
84 if (fr
< 0 && dochugw(mtmp
))
87 if (mtmp
->mspeed
== MFAST
&& dochugw(mtmp
))
91 warnlevel
-= u
.ulevel
;
92 if (warnlevel
>= SIZE(warnings
))
93 warnlevel
= SIZE(warnings
) - 1;
95 if (warnlevel
> lastwarnlev
|| moves
> lastwarntime
+ 5) {
97 switch (Warning
& (LEFT_RING
| RIGHT_RING
)) {
99 rr
= "Your left ring glows";
102 rr
= "Your right ring glows";
104 case LEFT_RING
| RIGHT_RING
:
105 rr
= "Both your rings glow";
108 rr
= "Your fingertips glow";
111 pline("%s %s!", rr
, warnings
[warnlevel
]);
112 lastwarntime
= moves
;
113 lastwarnlev
= warnlevel
;
115 dmonsfree(); /* remove all dead monsters */
128 kludge("%s swallows you!", name
);
137 youswld(mtmp
, dam
, die
, name
)
142 if (mtmp
!= u
.ustuck
)
144 kludge("%s digests you!", name
);
146 if (u
.uswldtim
++ >= die
) { /* a3 */
147 pline("It totally digests you!");
153 flags
.botlx
= 1; /* should we show status line ? */
163 int d
= dochug(mtmp
);
165 if (!d
) /* monster still alive */
167 if (!mtmp
->mpeaceful
)
168 if (mtmp
->data
->mlevel
> warnlevel
)
169 if ((dd
= dist(mtmp
->mx
, mtmp
->my
)) < dist(x
, y
))
171 if (!canseemon(mtmp
))
172 warnlevel
= mtmp
->data
->mlevel
;
176 /* returns 1 if monster died moving, 0 otherwise */
181 struct permonst
*mdat
;
182 int tmp
= 0, nearby
, scared
;
184 if (mtmp
->cham
&& !rn2(6))
185 (void) newcham(mtmp
, &mons
[dlevel
+ 14 + rn2(CMNUM
- 14 - dlevel
)]);
187 if (mdat
->mlevel
< 0)
188 panic("bad monster %c (%d)", mdat
->mlet
, mdat
->mlevel
);
190 /* regenerate monsters */
191 if ((!(moves
% 20) || strchr(MREGEN
, mdat
->mlet
)) &&
192 mtmp
->mhp
< mtmp
->mhpmax
)
196 return (0); /* frozen monsters don't do anything */
199 /* wake up, or get out of here. */
200 /* ettins are hard to surprise */
201 /* Nymphs and Leprechauns do not easily wake up */
202 if (cansee(mtmp
->mx
, mtmp
->my
) &&
203 (!Stealth
|| (mdat
->mlet
== 'e' && rn2(10))) &&
204 (!strchr("NL", mdat
->mlet
) || !rn2(50)) &&
205 (Aggravate_monster
|| strchr("d1", mdat
->mlet
)
206 || (!rn2(7) && !mtmp
->mimic
)))
211 /* not frozen or sleeping: wipe out texts written in the dust */
212 wipe_engr_at(mtmp
->mx
, mtmp
->my
, 1);
214 /* confused monsters get unconfused with small probability */
215 if (mtmp
->mconf
&& !rn2(50))
218 /* some monsters teleport */
219 if (mtmp
->mflee
&& strchr("tNL", mdat
->mlet
) && !rn2(40)) {
223 if (mdat
->mmove
< rnd(6))
226 /* fleeing monsters might regain courage */
227 if (mtmp
->mflee
&& !mtmp
->mfleetim
228 && mtmp
->mhp
== mtmp
->mhpmax
&& !rn2(25))
231 nearby
= (dist(mtmp
->mx
, mtmp
->my
) < 3);
232 scared
= (nearby
&& (sengr_at("Elbereth", u
.ux
, u
.uy
) ||
233 sobj_at(SCR_SCARE_MONSTER
, u
.ux
, u
.uy
)));
234 if (scared
&& !mtmp
->mflee
) {
236 mtmp
->mfleetim
= (rn2(7) ? rnd(10) : rnd(100));
241 (mtmp
->minvis
&& !rn2(3)) ||
242 (strchr("BIuy", mdat
->mlet
) && !rn2(4)) ||
243 (mdat
->mlet
== 'L' && !u
.ugold
&& (mtmp
->mgold
|| rn2(2))) ||
244 (!mtmp
->mcansee
&& !rn2(4)) ||
247 tmp
= m_move(mtmp
, 0); /* 2: monster died moving */
248 if (tmp
== 2 || (tmp
&& mdat
->mmove
<= 12))
251 if (!strchr("Ea", mdat
->mlet
) && nearby
&&
252 !mtmp
->mpeaceful
&& u
.uhp
> 0 && !scared
) {
254 return (1); /* monster died (e.g. 'y' or 'F') */
256 /* extra movement for fast monsters */
257 if (mdat
->mmove
- 12 > rnd(12))
258 tmp
= m_move(mtmp
, 1);
267 int nx
, ny
, omx
, omy
, appr
, nearer
, cnt
, i
, j
;
268 xchar gx
, gy
, nix
, niy
, chcnt
;
270 boolean likegold
= 0, likegems
= 0, likeobjs
= 0;
271 char msym
= mtmp
->data
->mlet
;
272 schar mmoved
= 0; /* not strictly nec.: chi >= 0 will
277 if (mtmp
->mfroz
|| mtmp
->msleep
)
279 if (mtmp
->mtrapped
) {
282 return (2); /* he died */
284 return (0); /* still in trap, so didnt move */
286 if (mtmp
->mhide
&& o_at(mtmp
->mx
, mtmp
->my
) && rn2(10))
287 return (0); /* do not leave hiding place */
294 /* my dog gets a special treatment */
296 return (dog_move(mtmp
, after
));
298 /* likewise for shopkeeper */
300 mmoved
= shk_move(mtmp
);
303 mmoved
= 0; /* follow player outside shop */
305 /* and for the guard */
311 * teleport if that lies in our nature ('t') or when badly wounded
314 if ((msym
== 't' && !rn2(5))
315 || (msym
== '1' && (mtmp
->mhp
< 7 || (!xdnstair
&& !rn2(5))
316 || levl
[u
.ux
][u
.uy
].typ
== STAIRS
))) {
317 if (mtmp
->mhp
< 7 || (msym
== 't' && rn2(2)))
324 /* spit fire ('D') or use a wand ('1') when appropriate */
325 if (strchr("D1", msym
))
328 if (msym
== 'U' && !mtmp
->mcan
&& canseemon(mtmp
) &&
329 mtmp
->mcansee
&& rn2(5)) {
331 pline("%s's gaze has confused you!", Monnam(mtmp
));
333 pline("You are getting more and more confused.");
336 Confusion
+= d(3, 4); /* timeout */
339 if (!mtmp
->mflee
&& u
.uswallow
&& u
.ustuck
!= mtmp
)
344 if (mtmp
->mconf
|| Invis
|| !mtmp
->mcansee
||
345 (strchr("BIy", msym
) && !rn2(3)))
351 if (msym
== 'L' && appr
== 1 && mtmp
->mgold
> u
.ugold
)
355 * random criterion for 'smell' or track finding ability should use
356 * mtmp->msmell or sth
359 ('a' <= msym
&& msym
<= 'z')) {
362 mroom
= inroom(omx
, omy
);
363 if (mroom
< 0 || mroom
!= inroom(u
.ux
, u
.uy
)) {
364 cp
= gettrack(omx
, omy
);
371 /* look for gold or jewels nearby */
372 likegold
= (strchr("LOD", msym
) != NULL
);
373 likegems
= (strchr("ODu", msym
) != NULL
);
374 likeobjs
= mtmp
->mhide
;
375 #define SRCHRADIUS 25
377 xchar mind
= SRCHRADIUS
; /* not too far away */
381 for (gold
= fgold
; gold
; gold
= gold
->ngold
)
382 if ((dd
= DIST(omx
, omy
, gold
->gx
, gold
->gy
)) < mind
) {
388 if (likegems
|| likeobjs
) {
390 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
391 if (likeobjs
|| otmp
->olet
== GEM_SYM
)
393 objects
[otmp
->otyp
].g_val
!= 0)
394 if ((dd
= DIST(omx
, omy
, otmp
->ox
, otmp
->oy
)) < mind
) {
400 if (mind
< SRCHRADIUS
&& appr
== -1) {
401 if (dist(omx
, omy
) < 10) {
410 cnt
= mfndpos(mtmp
, poss
, info
,
411 msym
== 'u' ? NOTONL
:
412 (msym
== '@' || msym
== '1') ? (ALLOW_SSM
| ALLOW_TRAPS
) :
413 strchr(UNDEAD
, msym
) ? NOGARLIC
: ALLOW_TRAPS
);
414 /* ALLOW_ROCK for some monsters ? */
417 for (i
= 0; i
< cnt
; i
++) {
420 for (j
= 0; j
< MTSZ
&& j
< cnt
- 1; j
++)
421 if (nx
== mtmp
->mtrack
[j
].x
&& ny
== mtmp
->mtrack
[j
].y
)
422 if (rn2(4 * (cnt
- j
)))
425 /* some stupid compilers think that this is too complicated */
427 int d1
= DIST(nx
, ny
, gx
, gy
);
428 int d2
= DIST(nix
, niy
, gx
, gy
);
432 nearer
= (DIST(nx
, ny
, gx
, gy
) < DIST(nix
, niy
, gx
, gy
));
434 if ((appr
== 1 && nearer
) || (appr
== -1 && !nearer
) ||
436 (!appr
&& !rn2(++chcnt
))) {
445 if (info
[chi
] & ALLOW_M
) {
446 mtmp2
= m_at(nix
, niy
);
447 if (hitmm(mtmp
, mtmp2
) == 1 && rn2(4) &&
448 hitmm(mtmp2
, mtmp
) == 2)
452 if (info
[chi
] & ALLOW_U
) {
453 (void) hitu(mtmp
, d(mtmp
->data
->damn
, mtmp
->data
->damd
) + 1);
458 for (j
= MTSZ
- 1; j
> 0; j
--)
459 mtmp
->mtrack
[j
] = mtmp
->mtrack
[j
- 1];
460 mtmp
->mtrack
[0].x
= omx
;
461 mtmp
->mtrack
[0].y
= omy
;
467 if (msym
== 'u' && rn2(2)) {
478 if (mintrap(mtmp
) == 2) /* he died */
485 mtmp
->mundetected
= 1;
496 while ((gold
= g_at(mtmp
->mx
, mtmp
->my
)) != NULL
) {
497 mtmp
->mgold
+= gold
->amount
;
499 if (levl
[mtmp
->mx
][mtmp
->my
].scrsym
== '$')
500 newsym(mtmp
->mx
, mtmp
->my
);
509 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
510 if (otmp
->olet
== GEM_SYM
)
511 if (otmp
->ox
== mtmp
->mx
&& otmp
->oy
== mtmp
->my
)
512 if (mtmp
->data
->mlet
!= 'u' || objects
[otmp
->otyp
].g_val
!= 0) {
514 mpickobj(mtmp
, otmp
);
515 if (levl
[mtmp
->mx
][mtmp
->my
].scrsym
== GEM_SYM
)
516 newsym(mtmp
->mx
, mtmp
->my
); /* %% */
517 return; /* pick only one object */
521 /* return number of acceptable neighbour positions */
523 mfndpos(mon
, poss
, info
, flag
)
528 int x
, y
, nx
, ny
, cnt
= 0, ntyp
;
535 nowtyp
= levl
[x
][y
].typ
;
537 pool
= (mon
->data
->mlet
== ';');
538 nexttry
: /* eels prefer the water, but if there is no
539 * water nearby, they will crawl over land */
544 for (nx
= x
- 1; nx
<= x
+ 1; nx
++)
545 for (ny
= y
- 1; ny
<= y
+ 1; ny
++)
546 if (nx
!= x
|| ny
!= y
)
548 if (!IS_ROCK(ntyp
= levl
[nx
][ny
].typ
))
549 if (!(nx
!= x
&& ny
!= y
&& (nowtyp
== DOOR
|| ntyp
== DOOR
)))
550 if ((ntyp
== POOL
) == pool
) {
552 if (nx
== u
.ux
&& ny
== u
.uy
) {
553 if (!(flag
& ALLOW_U
))
556 } else if ((mtmp
= m_at(nx
, ny
)) != NULL
) {
557 if (!(flag
& ALLOW_M
))
561 if (!(flag
& ALLOW_TM
))
563 info
[cnt
] |= ALLOW_TM
;
566 if (sobj_at(CLOVE_OF_GARLIC
, nx
, ny
)) {
569 info
[cnt
] |= NOGARLIC
;
571 if (sobj_at(SCR_SCARE_MONSTER
, nx
, ny
) ||
572 (!mon
->mpeaceful
&& sengr_at("Elbereth", nx
, ny
))) {
573 if (!(flag
& ALLOW_SSM
))
575 info
[cnt
] |= ALLOW_SSM
;
577 if (sobj_at(ENORMOUS_ROCK
, nx
, ny
)) {
578 if (!(flag
& ALLOW_ROCK
))
580 info
[cnt
] |= ALLOW_ROCK
;
582 if (!Invis
&& online(nx
, ny
)) {
595 struct trap
*ttmp
= t_at(nx
, ny
);
598 tt
= 1 << ttmp
->ttyp
;
599 if (mon
->mtrapseen
& tt
) {
610 if (!cnt
&& pool
&& nowtyp
!= POOL
) {
621 return ((x
- u
.ux
) * (x
- u
.ux
) + (y
- u
.uy
) * (y
- u
.uy
));
625 poisoned(string
, pname
)
626 char *string
, *pname
;
631 pline("It was poisoned.");
633 pline("The %s was poisoned!", string
);
634 if (Poison_resistance
) {
635 pline("The poison doesn't seem to affect you.");
641 pline("I am afraid the poison was deadly ...");
645 losehp(rn1(10, 6), pname
);
672 /* called when monster is moved to larger structure */
675 struct monst
*mtmp
, *mtmp2
;
681 if (u
.ustuck
== mtmp
)
684 replshk(mtmp
, mtmp2
);
698 for (mtmp
= fmon
; mtmp
->nmon
!= mon
; mtmp
= mtmp
->nmon
);
699 mtmp
->nmon
= mon
->nmon
;
704 * we do not free monsters immediately, in order to have their name available
705 * shortly after their demise
707 struct monst
*fdmon
; /* chain of dead monsters, need not to be
722 while ((mtmp
= fdmon
) != NULL
) {
732 if (u
.ustuck
== mtmp
) {
752 struct permonst
*mdat
;
755 mtmp
->data
= PM_CHAMELEON
;
758 pline("You destroy it!");
760 pline("You destroy %s!",
761 mtmp
->mtame
? amonnam(mtmp
, "poor") : monnam(mtmp
));
765 pline("Your hands stop glowing blue.");
768 /* count killed monsters */
770 nk
= 1; /* in case we cannot find it in mons */
771 tmp
= mdat
- mons
; /* strchr in mons array (if not 'd', '@', ...) */
772 if (tmp
>= 0 && tmp
< CMNUM
+ 2) {
774 if ((nk
= u
.nr_killed
[tmp
]) > MAXMONNO
&&
775 !strchr(fut_geno
, mdat
->mlet
))
776 charcat(fut_geno
, mdat
->mlet
);
778 /* punish bad behaviour */
779 if (mdat
->mlet
== '@')
780 Telepat
= 0, u
.uluck
-= 2;
781 if (mtmp
->mpeaceful
|| mtmp
->mtame
)
783 if (mdat
->mlet
== 'u')
785 if ((int) u
.uluck
< LUCKMIN
)
788 /* give experience points */
789 tmp
= 1 + mdat
->mlevel
* mdat
->mlevel
;
791 tmp
+= 2 * (7 - mdat
->ac
);
792 if (strchr("AcsSDXaeRTVWU&In:P", mdat
->mlet
))
793 tmp
+= 2 * mdat
->mlevel
;
794 if (strchr("DeV&P", mdat
->mlet
))
795 tmp
+= (7 * mdat
->mlevel
);
796 if (mdat
->mlevel
> 6)
798 if (mdat
->mlet
== ';')
803 * ------- recent addition: make nr of points decrease when this is
804 * not the first of this kind
808 int ml
= mdat
->mlevel
;
810 if (ul
< 14) /* points are given based on present and
812 for (tmp2
= 0; !tmp2
|| ul
+ tmp2
<= ml
; tmp2
++)
813 if (u
.uexp
+ 1 + (tmp
+ ((tmp2
<= 0) ? 0 : 4 << (tmp2
- 1))) / nk
814 >= 10 * pow((unsigned) (ul
- 1)))
819 tmp
= (tmp
+ ((tmp2
< 0) ? 0 : 4 << tmp2
)) / nk
;
823 /* note: ul is not necessarily the future value of u.ulevel */
824 /* ------- end of recent valuation change ------- */
825 #endif /* NEW_SCORING */
827 more_experienced(tmp
, 0);
829 while (u
.ulevel
< 14 && u
.uexp
>= newuexp()) {
830 pline("Welcome to experience level %u.", ++u
.ulevel
);
839 /* dispose of monster and make cadaver */
844 if (tmp
== 'm') { /* he killed a minotaur, give him a wand of
846 /* note: the dead minotaur will be on top of it! */
847 mksobj_at(WAN_DIGGING
, x
, y
);
848 /* if(cansee(x,y)) atl(x,y,fobj->olet); */
853 mksobj_at(WORM_TOOTH
, x
, y
);
857 if (!letter(tmp
) || (!strchr("mw", tmp
) && !rn2(3)))
860 if (ACCESSIBLE(levl
[x
][y
].typ
)) /* might be mimic in wall or dead eel */
861 if (x
!= u
.ux
|| y
!= u
.uy
) /* might be here after
863 if (strchr("NTVm&", mdat
->mlet
) || rn2(5)) {
864 struct obj
*obj2
= mkobj_at(tmp
, x
, y
);
866 atl(x
, y
, obj2
->olet
);
886 { /* force all chameleons to become normal */
889 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
892 (void) newcham(mtmp
, PM_CHAMELEON
);
897 newcham(mtmp
, mdat
) /* make a chameleon look like a new monster */
898 /* returns 1 if the monster actually changed */
900 struct permonst
*mdat
;
904 if (mdat
== mtmp
->data
)
905 return (0); /* still the same monster */
908 wormdead(mtmp
); /* throw tail away */
910 if (u
.ustuck
== mtmp
) {
921 hpd
= (mtmp
->data
->mlevel
) * 8;
925 mhp
= (mdat
->mlevel
) * 8;
926 /* new hp: same fraction of max as before */
927 mtmp
->mhp
= 2 + (hpn
* mhp
) / hpd
;
929 mtmp
->mhpmax
= 2 + (hpn
* mhp
) / hpd
;
930 mtmp
->minvis
= (mdat
->mlet
== 'I') ? 1 : 0;
932 if (mdat
->mlet
== 'w' && getwn(mtmp
))
934 /* perhaps we should clear mtmp->mtame here? */
936 unpmon(mtmp
); /* necessary for 'I' and to force pmon */
942 mnexto(mtmp
) /* Make monster mtmp next to you (if
947 mm
= enexto(u
.ux
, u
.uy
);
957 return (mtmp
->data
->mlet
== '@');
964 if (!mtmp
->mpeaceful
)
970 pline("%s gets angry!", Monnam(mtmp
));
974 * not one hundred procent correct: now a snake may hide under an invisible
981 return ((!mtmp
->minvis
|| See_invisible
)
982 && (!mtmp
->mhide
|| !o_at(mtmp
->mx
, mtmp
->my
))
983 && cansee(mtmp
->mx
, mtmp
->my
));