/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* hack.mon.c - version 1.0.3 */
#include "hack.mfndpos.h"
extern struct monst
*makemon();
extern struct obj
*mkobj_at();
int warnlevel
; /* used by movemon and dochugw */
"white", "pink", "red", "ruby", "purple", "black"
register struct monst
*mtmp
;
/* find a monster that we haven't treated yet */
/* note that mtmp or mtmp->nmon might get killed
while mtmp moves, so we cannot just walk down the
chain (even new monsters might get created!) */
for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
if(mtmp
->mlstmv
< moves
) goto next_mon
;
/* treated all monsters */
/* most monsters drown in pools */
inpool
= (levl
[mtmp
->mx
][mtmp
->my
].typ
== POOL
);
iseel
= (mtmp
->data
->mlet
== ';');
if(cansee(mtmp
->mx
,mtmp
->my
))
pline("%s drowns.", Monnam(mtmp
));
/* but eels have a difficult time outside */
if(mtmp
->mhp
> 1) mtmp
->mhp
--;
if(mtmp
->mblinded
&& !--mtmp
->mblinded
)
if(mtmp
->mfleetim
&& !--mtmp
->mfleetim
)
if(mtmp
->mimic
) continue;
if(mtmp
->mspeed
!= MSLOW
|| !(moves
%2)){
/* continue if the monster died fighting */
if(Conflict
&& cansee(mtmp
->mx
,mtmp
->my
)
&& (fr
= fightm(mtmp
)) == 2)
if(fr
<0 && dochugw(mtmp
))
if(mtmp
->mspeed
== MFAST
&& dochugw(mtmp
))
if(warnlevel
>= SIZE(warnings
))
warnlevel
= SIZE(warnings
)-1;
if(warnlevel
> lastwarnlev
|| moves
> lastwarntime
+ 5){
switch(Warning
& (LEFT_RING
| RIGHT_RING
)){
rr
= "Your left ring glows";
rr
= "Your right ring glows";
case LEFT_RING
| RIGHT_RING
:
rr
= "Both your rings glow";
rr
= "Your fingertips glow";
pline("%s %s!", rr
, warnings
[warnlevel
]);
dmonsfree(); /* remove all dead monsters */
register struct monst
*mtmp
;
kludge("%s swallows you!",name
);
youswld(mtmp
,dam
,die
,name
)
register struct monst
*mtmp
;
if(mtmp
!= u
.ustuck
) return;
kludge("%s digests you!",name
);
if(u
.uswldtim
++ >= die
){ /* a3 */
pline("It totally digests you!");
if(u
.uhp
< 1) done_in_by(mtmp
);
/* flags.botlx = 1; /* should we show status line ? */
dochugw(mtmp
) register struct monst
*mtmp
; {
register d
= dochug(mtmp
);
if(!d
) /* monster still alive */
if(mtmp
->data
->mlevel
> warnlevel
)
if((dd
= dist(mtmp
->mx
,mtmp
->my
)) < dist(x
,y
))
warnlevel
= mtmp
->data
->mlevel
;
/* returns 1 if monster died moving, 0 otherwise */
register struct monst
*mtmp
;
register struct permonst
*mdat
;
register tmp
, nearby
, scared
;
if(mtmp
->cham
&& !rn2(6))
(void) newcham(mtmp
, &mons
[dlevel
+14+rn2(CMNUM
-14-dlevel
)]);
panic("bad monster %c (%d)",mdat
->mlet
,mdat
->mlevel
);
/* regenerate monsters */
if((!(moves
%20) || index(MREGEN
, mdat
->mlet
)) &&
mtmp
->mhp
< mtmp
->mhpmax
)
if(mtmp
->mfroz
) return(0); /* frozen monsters don't do anything */
/* wake up, or get out of here. */
/* ettins are hard to surprise */
/* Nymphs and Leprechauns do not easily wake up */
if(cansee(mtmp
->mx
,mtmp
->my
) &&
(!Stealth
|| (mdat
->mlet
== 'e' && rn2(10))) &&
(!index("NL",mdat
->mlet
) || !rn2(50)) &&
(Aggravate_monster
|| index("d1", mdat
->mlet
)
|| (!rn2(7) && !mtmp
->mimic
)))
/* not frozen or sleeping: wipe out texts written in the dust */
wipe_engr_at(mtmp
->mx
, mtmp
->my
, 1);
/* confused monsters get unconfused with small probability */
if(mtmp
->mconf
&& !rn2(50)) mtmp
->mconf
= 0;
/* some monsters teleport */
if(mtmp
->mflee
&& index("tNL", mdat
->mlet
) && !rn2(40)){
if(mdat
->mmove
< rnd(6)) return(0);
/* fleeing monsters might regain courage */
if(mtmp
->mflee
&& !mtmp
->mfleetim
&& mtmp
->mhp
== mtmp
->mhpmax
&& !rn2(25))
nearby
= (dist(mtmp
->mx
, mtmp
->my
) < 3);
scared
= (nearby
&& (sengr_at("Elbereth", u
.ux
, u
.uy
) ||
sobj_at(SCR_SCARE_MONSTER
, u
.ux
, u
.uy
)));
if(scared
&& !mtmp
->mflee
) {
mtmp
->mfleetim
= (rn2(7) ? rnd(10) : rnd(100));
(mtmp
->minvis
&& !rn2(3)) ||
(index("BIuy", mdat
->mlet
) && !rn2(4)) ||
(mdat
->mlet
== 'L' && !u
.ugold
&& (mtmp
->mgold
|| rn2(2))) ||
(!mtmp
->mcansee
&& !rn2(4)) ||
tmp
= m_move(mtmp
,0); /* 2: monster died moving */
if(tmp
== 2 || (tmp
&& mdat
->mmove
<= 12))
if(!index("Ea", mdat
->mlet
) && nearby
&&
!mtmp
->mpeaceful
&& u
.uhp
> 0 && !scared
) {
return(1); /* monster died (e.g. 'y' or 'F') */
/* extra movement for fast monsters */
if(mdat
->mmove
-12 > rnd(12)) tmp
= m_move(mtmp
,1);
register struct monst
*mtmp
;
register struct monst
*mtmp2
;
register nx
,ny
,omx
,omy
,appr
,nearer
,cnt
,i
,j
;
xchar gx
,gy
,nix
,niy
,chcnt
;
boolean likegold
, likegems
, likeobjs
;
char msym
= mtmp
->data
->mlet
;
schar mmoved
= 0; /* not strictly nec.: chi >= 0 will do */
if(mtmp
->mfroz
|| mtmp
->msleep
)
if(i
== 2) return(2); /* he died */
if(i
== 1) return(0); /* still in trap, so didnt move */
if(mtmp
->mhide
&& o_at(mtmp
->mx
,mtmp
->my
) && rn2(10))
return(0); /* do not leave hiding place */
/* my dog gets a special treatment */
return( dog_move(mtmp
, after
) );
/* likewise for shopkeeper */
mmoved
= 0; /* follow player outside shop */
/* teleport if that lies in our nature ('t') or when badly wounded ('1') */
if((msym
== 't' && !rn2(5))
|| (msym
== '1' && (mtmp
->mhp
< 7 || (!xdnstair
&& !rn2(5))
|| levl
[u
.ux
][u
.uy
].typ
== STAIRS
))) {
if(mtmp
->mhp
< 7 || (msym
== 't' && rn2(2)))
/* spit fire ('D') or use a wand ('1') when appropriate */
if(msym
== 'U' && !mtmp
->mcan
&& canseemon(mtmp
) &&
mtmp
->mcansee
&& rn2(5)) {
pline("%s's gaze has confused you!", Monnam(mtmp
));
pline("You are getting more and more confused.");
if(rn2(3)) mtmp
->mcan
= 1;
Confusion
+= d(3,4); /* timeout */
if(!mtmp
->mflee
&& u
.uswallow
&& u
.ustuck
!= mtmp
) return(1);
if(mtmp
->mflee
) appr
= -1;
if(mtmp
->mconf
|| Invis
|| !mtmp
->mcansee
||
(index("BIy", msym
) && !rn2(3)))
if(msym
== 'L' && appr
== 1 && mtmp
->mgold
> u
.ugold
)
/* random criterion for 'smell' or track finding ability
should use mtmp->msmell or sth
('a' <= msym
&& msym
<= 'z')) {
extern coord
*gettrack();
if(mroom
< 0 || mroom
!= inroom(u
.ux
,u
.uy
)){
/* look for gold or jewels nearby */
likegold
= (index("LOD", msym
) != NULL
);
likegems
= (index("ODu", msym
) != NULL
);
{ xchar mind
= SRCHRADIUS
; /* not too far away */
register struct gold
*gold
;
for(gold
= fgold
; gold
; gold
= gold
->ngold
)
if((dd
= DIST(omx
,omy
,gold
->gx
,gold
->gy
)) < mind
){
if(likegems
|| likeobjs
){
register struct obj
*otmp
;
for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
if(likeobjs
|| otmp
->olet
== GEM_SYM
)
objects
[otmp
->otyp
].g_val
!= 0)
if((dd
= DIST(omx
,omy
,otmp
->ox
,otmp
->oy
)) < mind
){
if(mind
< SRCHRADIUS
&& appr
== -1) {
cnt
= mfndpos(mtmp
,poss
,info
,
(msym
== '@' || msym
== '1') ? (ALLOW_SSM
| ALLOW_TRAPS
) :
index(UNDEAD
, msym
) ? NOGARLIC
: ALLOW_TRAPS
);
/* ALLOW_ROCK for some monsters ? */
for(j
=0; j
<MTSZ
&& j
<cnt
-1; j
++)
if(nx
== mtmp
->mtrack
[j
].x
&& ny
== mtmp
->mtrack
[j
].y
)
if(rn2(4*(cnt
-j
))) goto nxti
;
/* some stupid compilers think that this is too complicated */
{ int d1
= DIST(nx
,ny
,gx
,gy
);
int d2
= DIST(nix
,niy
,gx
,gy
);
nearer
= (DIST(nx
,ny
,gx
,gy
) < DIST(nix
,niy
,gx
,gy
));
if((appr
== 1 && nearer
) || (appr
== -1 && !nearer
) ||
(!appr
&& !rn2(++chcnt
))){
if(hitmm(mtmp
,mtmp2
) == 1 && rn2(4) &&
hitmm(mtmp2
,mtmp
) == 2) return(2);
(void) hitu(mtmp
, d(mtmp
->data
->damn
, mtmp
->data
->damd
)+1);
for(j
=MTSZ
-1; j
>0; j
--) mtmp
->mtrack
[j
] = mtmp
->mtrack
[j
-1];
if(mtmp
->wormno
) worm_move(mtmp
);
if(msym
== 'u' && rn2(2)){
if(mtmp
->wormno
) worm_nomove(mtmp
);
if(mintrap(mtmp
) == 2) /* he died */
if(likegold
) mpickgold(mtmp
);
if(likegems
) mpickgems(mtmp
);
if(mtmp
->mhide
) mtmp
->mundetected
= 1;
mpickgold(mtmp
) register struct monst
*mtmp
; {
register struct gold
*gold
;
while(gold
= g_at(mtmp
->mx
, mtmp
->my
)){
mtmp
->mgold
+= gold
->amount
;
if(levl
[mtmp
->mx
][mtmp
->my
].scrsym
== '$')
newsym(mtmp
->mx
, mtmp
->my
);
mpickgems(mtmp
) register struct monst
*mtmp
; {
register struct obj
*otmp
;
for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
if(otmp
->olet
== GEM_SYM
)
if(otmp
->ox
== mtmp
->mx
&& otmp
->oy
== mtmp
->my
)
if(mtmp
->data
->mlet
!= 'u' || objects
[otmp
->otyp
].g_val
!= 0){
if(levl
[mtmp
->mx
][mtmp
->my
].scrsym
== GEM_SYM
)
newsym(mtmp
->mx
, mtmp
->my
); /* %% */
return; /* pick only one object */
/* return number of acceptable neighbour positions */
mfndpos(mon
,poss
,info
,flag
)
register struct monst
*mon
;
register int x
,y
,nx
,ny
,cnt
= 0,ntyp
;
register struct monst
*mtmp
;
pool
= (mon
->data
->mlet
== ';');
nexttry
: /* eels prefer the water, but if there is no water nearby,
they will crawl over land */
for(nx
= x
-1; nx
<= x
+1; nx
++) for(ny
= y
-1; ny
<= y
+1; ny
++)
if(nx
!= x
|| ny
!= y
) if(isok(nx
,ny
))
if(!IS_ROCK(ntyp
= levl
[nx
][ny
].typ
))
if(!(nx
!= x
&& ny
!= y
&& (nowtyp
== DOOR
|| ntyp
== DOOR
)))
if((ntyp
== POOL
) == pool
) {
if(nx
== u
.ux
&& ny
== u
.uy
){
if(!(flag
& ALLOW_U
)) continue;
} else if(mtmp
= m_at(nx
,ny
)){
if(!(flag
& ALLOW_M
)) continue;
if(!(flag
& ALLOW_TM
)) continue;
if(sobj_at(CLOVE_OF_GARLIC
, nx
, ny
)) {
if(flag
& NOGARLIC
) continue;
if(sobj_at(SCR_SCARE_MONSTER
, nx
, ny
) ||
(!mon
->mpeaceful
&& sengr_at("Elbereth", nx
, ny
))) {
if(!(flag
& ALLOW_SSM
)) continue;
if(sobj_at(ENORMOUS_ROCK
, nx
, ny
)) {
if(!(flag
& ALLOW_ROCK
)) continue;
if(!Invis
&& online(nx
,ny
)){
if(flag
& NOTONL
) continue;
/* we cannot avoid traps of an unknown kind */
{ register struct trap
*ttmp
= t_at(nx
, ny
);
if(!(flag
& tt
)) continue;
if(!cnt
&& pool
&& nowtyp
!= POOL
) {
return((x
-u
.ux
)*(x
-u
.ux
) + (y
-u
.uy
)*(y
-u
.uy
));
register char *string
, *pname
;
if(Blind
) pline("It was poisoned.");
else pline("The %s was poisoned!",string
);
pline("The poison doesn't seem to affect you.");
pline("I am afraid the poison was deadly ...");
losehp(rn1(10,6), pname
);
register struct monst
*mtmp
;
if(mtmp
->isshk
) shkdead(mtmp
);
if(mtmp
->wormno
) wormdead(mtmp
);
/* called when monster is moved to larger structure */
register struct monst
*mtmp
, *mtmp2
;
if(u
.ustuck
== mtmp
) u
.ustuck
= mtmp2
;
if(mtmp2
->isshk
) replshk(mtmp
,mtmp2
);
if(mtmp2
->isgd
) replgd(mtmp
,mtmp2
);
register struct monst
*mon
;
register struct monst
*mtmp
;
if(mon
== fmon
) fmon
= fmon
->nmon
;
for(mtmp
= fmon
; mtmp
->nmon
!= mon
; mtmp
= mtmp
->nmon
) ;
/* we do not free monsters immediately, in order to have their name
available shortly after their demise */
struct monst
*fdmon
; /* chain of dead monsters, need not to be saved */
monfree(mtmp
) register struct monst
*mtmp
; {
register struct monst
*mtmp
;
register struct monst
*mtmp
;
register struct monst
*mtmp
;
register int tmp
,tmp2
,nk
,x
,y
;
register struct permonst
*mdat
;
if(mtmp
->cham
) mtmp
->data
= PM_CHAMELEON
;
if(Blind
) pline("You destroy it!");
mtmp
->mtame
? amonnam(mtmp
, "poor") : monnam(mtmp
));
if(!Blind
) pline("Your hands stop glowing blue.");
/* count killed monsters */
nk
= 1; /* in case we cannot find it in mons */
tmp
= mdat
- mons
; /* index in mons array (if not 'd', '@', ...) */
if(tmp
>= 0 && tmp
< CMNUM
+2) {
if((nk
= u
.nr_killed
[tmp
]) > MAXMONNO
&&
!index(fut_geno
, mdat
->mlet
))
charcat(fut_geno
, mdat
->mlet
);
/* punish bad behaviour */
if(mdat
->mlet
== '@') Telepat
= 0, u
.uluck
-= 2;
if(mtmp
->mpeaceful
|| mtmp
->mtame
) u
.uluck
--;
if(mdat
->mlet
== 'u') u
.uluck
-= 5;
if((int)u
.uluck
< LUCKMIN
) u
.uluck
= LUCKMIN
;
/* give experience points */
tmp
= 1 + mdat
->mlevel
* mdat
->mlevel
;
if(mdat
->ac
< 3) tmp
+= 2*(7 - mdat
->ac
);
if(index("AcsSDXaeRTVWU&In:P", mdat
->mlet
))
if(index("DeV&P",mdat
->mlet
)) tmp
+= (7*mdat
->mlevel
);
if(mdat
->mlevel
> 6) tmp
+= 50;
if(mdat
->mlet
== ';') tmp
+= 1000;
/* ------- recent addition: make nr of points decrease
when this is not the first of this kind */
if(ul
< 14) /* points are given based on present and future level */
for(tmp2
= 0; !tmp2
|| ul
+ tmp2
<= ml
; tmp2
++)
if(u
.uexp
+ 1 + (tmp
+ ((tmp2
<= 0) ? 0 : 4<<(tmp2
-1)))/nk
>= 10*pow((unsigned)(ul
-1)))
tmp
= (tmp
+ ((tmp2
< 0) ? 0 : 4<<tmp2
))/nk
;
/* note: ul is not necessarily the future value of u.ulevel */
/* ------- end of recent valuation change ------- */
while(u
.ulevel
< 14 && u
.uexp
>= newuexp()){
pline("Welcome to experience level %u.", ++u
.ulevel
);
if(tmp
< 3) tmp
= rnd(10);
/* dispose of monster and make cadaver */
x
= mtmp
->mx
; y
= mtmp
->my
;
if(tmp
== 'm') { /* he killed a minotaur, give him a wand of digging */
/* note: the dead minotaur will be on top of it! */
mksobj_at(WAN_DIGGING
, x
, y
);
/* if(cansee(x,y)) atl(x,y,fobj->olet); */
mksobj_at(WORM_TOOTH
, x
, y
);
if(!letter(tmp
) || (!index("mw", tmp
) && !rn2(3))) tmp
= 0;
if(ACCESSIBLE(levl
[x
][y
].typ
)) /* might be mimic in wall or dead eel*/
if(x
!= u
.ux
|| y
!= u
.uy
) /* might be here after swallowed */
if(index("NTVm&",mdat
->mlet
) || rn2(5)) {
register struct obj
*obj2
= mkobj_at(tmp
,x
,y
);
if(*str
== '%') pline(str
,"It");
rescham() /* force all chameleons to become normal */
register struct monst
*mtmp
;
for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
(void) newcham(mtmp
, PM_CHAMELEON
);
newcham(mtmp
,mdat
) /* make a chameleon look like a new monster */
/* returns 1 if the monster actually changed */
register struct monst
*mtmp
;
register struct permonst
*mdat
;
if(mdat
== mtmp
->data
) return(0); /* still the same monster */
if(mtmp
->wormno
) wormdead(mtmp
); /* throw tail away */
hpd
= (mtmp
->data
->mlevel
)*8;
/* new hp: same fraction of max as before */
mtmp
->mhp
= 2 + (hpn
*mhp
)/hpd
;
mtmp
->mhpmax
= 2 + (hpn
*mhp
)/hpd
;
mtmp
->minvis
= (mdat
->mlet
== 'I') ? 1 : 0;
if(mdat
->mlet
== 'w' && getwn(mtmp
)) initworm(mtmp
);
/* perhaps we should clear mtmp->mtame here? */
unpmon(mtmp
); /* necessary for 'I' and to force pmon */
mnexto(mtmp
) /* Make monster mtmp next to you (if possible) */
ishuman(mtmp
) register struct monst
*mtmp
; {
return(mtmp
->data
->mlet
== '@');
setmangry(mtmp
) register struct monst
*mtmp
; {
if(!mtmp
->mpeaceful
) return;
if(ishuman(mtmp
)) pline("%s gets angry!", Monnam(mtmp
));
/* not one hundred procent correct: now a snake may hide under an
register struct monst
*mtmp
;
return((!mtmp
->minvis
|| See_invisible
)
&& (!mtmp
->mhide
|| !o_at(mtmp
->mx
,mtmp
->my
))
&& cansee(mtmp
->mx
, mtmp
->my
));