1*9b92b189Sdholland /* $NetBSD: hack.fight.c,v 1.12 2009/08/12 07:28:40 dholland Exp $ */
23ea4a95cSchristos
302ded532Smycroft /*
41c7f94e5Sjsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
51c7f94e5Sjsm * Amsterdam
61c7f94e5Sjsm * All rights reserved.
71c7f94e5Sjsm *
81c7f94e5Sjsm * Redistribution and use in source and binary forms, with or without
91c7f94e5Sjsm * modification, are permitted provided that the following conditions are
101c7f94e5Sjsm * met:
111c7f94e5Sjsm *
121c7f94e5Sjsm * - Redistributions of source code must retain the above copyright notice,
131c7f94e5Sjsm * this list of conditions and the following disclaimer.
141c7f94e5Sjsm *
151c7f94e5Sjsm * - Redistributions in binary form must reproduce the above copyright
161c7f94e5Sjsm * notice, this list of conditions and the following disclaimer in the
171c7f94e5Sjsm * documentation and/or other materials provided with the distribution.
181c7f94e5Sjsm *
191c7f94e5Sjsm * - Neither the name of the Stichting Centrum voor Wiskunde en
201c7f94e5Sjsm * Informatica, nor the names of its contributors may be used to endorse or
211c7f94e5Sjsm * promote products derived from this software without specific prior
221c7f94e5Sjsm * written permission.
231c7f94e5Sjsm *
241c7f94e5Sjsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
251c7f94e5Sjsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
261c7f94e5Sjsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
271c7f94e5Sjsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
281c7f94e5Sjsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
291c7f94e5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
301c7f94e5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
311c7f94e5Sjsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
321c7f94e5Sjsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
331c7f94e5Sjsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
341c7f94e5Sjsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
351c7f94e5Sjsm */
361c7f94e5Sjsm
371c7f94e5Sjsm /*
381c7f94e5Sjsm * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
391c7f94e5Sjsm * All rights reserved.
401c7f94e5Sjsm *
411c7f94e5Sjsm * Redistribution and use in source and binary forms, with or without
421c7f94e5Sjsm * modification, are permitted provided that the following conditions
431c7f94e5Sjsm * are met:
441c7f94e5Sjsm * 1. Redistributions of source code must retain the above copyright
451c7f94e5Sjsm * notice, this list of conditions and the following disclaimer.
461c7f94e5Sjsm * 2. Redistributions in binary form must reproduce the above copyright
471c7f94e5Sjsm * notice, this list of conditions and the following disclaimer in the
481c7f94e5Sjsm * documentation and/or other materials provided with the distribution.
491c7f94e5Sjsm * 3. The name of the author may not be used to endorse or promote products
501c7f94e5Sjsm * derived from this software without specific prior written permission.
511c7f94e5Sjsm *
521c7f94e5Sjsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
531c7f94e5Sjsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
541c7f94e5Sjsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
551c7f94e5Sjsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
561c7f94e5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
571c7f94e5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
581c7f94e5Sjsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
591c7f94e5Sjsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
601c7f94e5Sjsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
611c7f94e5Sjsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6202ded532Smycroft */
6302ded532Smycroft
643ea4a95cSchristos #include <sys/cdefs.h>
6502ded532Smycroft #ifndef lint
66*9b92b189Sdholland __RCSID("$NetBSD: hack.fight.c,v 1.12 2009/08/12 07:28:40 dholland Exp $");
6702ded532Smycroft #endif /* not lint */
6861f28255Scgd
6961f28255Scgd #include "hack.h"
703ea4a95cSchristos #include "extern.h"
7161f28255Scgd
7261f28255Scgd static boolean far_noise;
7361f28255Scgd static long noisetime;
7461f28255Scgd
75*9b92b189Sdholland static void monstone(struct monst *);
76*9b92b189Sdholland
7761f28255Scgd /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
783ea4a95cSchristos int
hitmm(struct monst * magr,struct monst * mdef)791fa8a9a6Sdholland hitmm(struct monst *magr, struct monst *mdef)
803ea4a95cSchristos {
81ab8b6343Sjsm const struct permonst *pa = magr->data, *pd = mdef->data;
823c439f43Sdholland int didhit;
8361f28255Scgd schar tmp;
8461f28255Scgd boolean vis;
853c439f43Sdholland
863ea4a95cSchristos if (strchr("Eauy", pa->mlet))
873ea4a95cSchristos return (0);
883ea4a95cSchristos if (magr->mfroz)
893ea4a95cSchristos return (0); /* riv05!a3 */
9061f28255Scgd tmp = pd->ac + pa->mlevel;
9161f28255Scgd if (mdef->mconf || mdef->mfroz || mdef->msleep) {
9261f28255Scgd tmp += 4;
933ea4a95cSchristos if (mdef->msleep)
943ea4a95cSchristos mdef->msleep = 0;
9561f28255Scgd }
963c439f43Sdholland didhit = (tmp > rnd(20));
973c439f43Sdholland if (didhit)
983ea4a95cSchristos mdef->msleep = 0;
9961f28255Scgd vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my));
10061f28255Scgd if (vis) {
10161f28255Scgd char buf[BUFSZ];
1023ea4a95cSchristos if (mdef->mimic)
1033ea4a95cSchristos seemimic(mdef);
1043ea4a95cSchristos if (magr->mimic)
1053ea4a95cSchristos seemimic(magr);
106907fca1bSdholland (void) snprintf(buf, sizeof(buf), "%s %s", Monnam(magr),
1073c439f43Sdholland didhit ? "hits" : "misses");
10861f28255Scgd pline("%s %s.", buf, monnam(mdef));
10961f28255Scgd } else {
11061f28255Scgd boolean far = (dist(magr->mx, magr->my) > 15);
11161f28255Scgd if (far != far_noise || moves - noisetime > 10) {
11261f28255Scgd far_noise = far;
11361f28255Scgd noisetime = moves;
11461f28255Scgd pline("You hear some noises%s.",
11561f28255Scgd far ? " in the distance" : "");
11661f28255Scgd }
11761f28255Scgd }
1183c439f43Sdholland if (didhit) {
11961f28255Scgd if (magr->data->mlet == 'c' && !magr->cham) {
12061f28255Scgd magr->mhpmax += 3;
1213ea4a95cSchristos if (vis)
1223ea4a95cSchristos pline("%s is turned to stone!", Monnam(mdef));
12361f28255Scgd else if (mdef->mtame)
12461f28255Scgd pline("You have a peculiarly sad feeling for a moment, then it passes.");
12561f28255Scgd monstone(mdef);
1263c439f43Sdholland didhit = 2;
1273ea4a95cSchristos } else if ((mdef->mhp -= d(pa->damn, pa->damd)) < 1) {
12861f28255Scgd magr->mhpmax += 1 + rn2(pd->mlevel + 1);
12961f28255Scgd if (magr->mtame && magr->mhpmax > 8 * pa->mlevel) {
1303ea4a95cSchristos if (pa == &li_dog)
1313ea4a95cSchristos magr->data = pa = &dog;
1323ea4a95cSchristos else if (pa == &dog)
1333ea4a95cSchristos magr->data = pa = &la_dog;
13461f28255Scgd }
1353ea4a95cSchristos if (vis)
1363ea4a95cSchristos pline("%s is killed!", Monnam(mdef));
13761f28255Scgd else if (mdef->mtame)
13861f28255Scgd pline("You have a sad feeling for a moment, then it passes.");
13961f28255Scgd mondied(mdef);
1403c439f43Sdholland didhit = 2;
14161f28255Scgd }
14261f28255Scgd }
1433c439f43Sdholland return (didhit);
14461f28255Scgd }
14561f28255Scgd
14661f28255Scgd /* drop (perhaps) a cadaver and remove monster */
1473ea4a95cSchristos void
mondied(struct monst * mdef)1481fa8a9a6Sdholland mondied(struct monst *mdef)
1493ea4a95cSchristos {
150ab8b6343Sjsm const struct permonst *pd = mdef->data;
15161f28255Scgd if (letter(pd->mlet) && rn2(3)) {
15261f28255Scgd (void) mkobj_at(pd->mlet, mdef->mx, mdef->my);
15361f28255Scgd if (cansee(mdef->mx, mdef->my)) {
15461f28255Scgd unpmon(mdef);
15561f28255Scgd atl(mdef->mx, mdef->my, fobj->olet);
15661f28255Scgd }
15761f28255Scgd stackobj(fobj);
15861f28255Scgd }
15961f28255Scgd mondead(mdef);
16061f28255Scgd }
16161f28255Scgd
16261f28255Scgd /* drop a rock and remove monster */
163*9b92b189Sdholland static void
monstone(struct monst * mdef)1641fa8a9a6Sdholland monstone(struct monst *mdef)
1653ea4a95cSchristos {
1663ea4a95cSchristos if (strchr(mlarge, mdef->data->mlet))
16761f28255Scgd mksobj_at(ENORMOUS_ROCK, mdef->mx, mdef->my);
16861f28255Scgd else
16961f28255Scgd mksobj_at(ROCK, mdef->mx, mdef->my);
17061f28255Scgd if (cansee(mdef->mx, mdef->my)) {
17161f28255Scgd unpmon(mdef);
17261f28255Scgd atl(mdef->mx, mdef->my, fobj->olet);
17361f28255Scgd }
17461f28255Scgd mondead(mdef);
17561f28255Scgd }
17661f28255Scgd
17761f28255Scgd
1783ea4a95cSchristos int
fightm(struct monst * mtmp)1791fa8a9a6Sdholland fightm(struct monst *mtmp)
1803ea4a95cSchristos {
1813ea4a95cSchristos struct monst *mon;
1823ea4a95cSchristos for (mon = fmon; mon; mon = mon->nmon)
1833ea4a95cSchristos if (mon != mtmp) {
18461f28255Scgd if (DIST(mon->mx, mon->my, mtmp->mx, mtmp->my) < 3)
18561f28255Scgd if (rn2(4))
18661f28255Scgd return (hitmm(mtmp, mon));
18761f28255Scgd }
18861f28255Scgd return (-1);
18961f28255Scgd }
19061f28255Scgd
19161f28255Scgd /* u is hit by sth, but not a monster */
1923ea4a95cSchristos int
thitu(int tlev,int dam,const char * name)1931fa8a9a6Sdholland thitu(int tlev, int dam, const char *name)
19461f28255Scgd {
19561f28255Scgd char buf[BUFSZ];
196907fca1bSdholland
197907fca1bSdholland setan(name, buf, sizeof(buf));
19861f28255Scgd if (u.uac + tlev <= rnd(20)) {
1993ea4a95cSchristos if (Blind)
2003ea4a95cSchristos pline("It misses.");
2013ea4a95cSchristos else
2023ea4a95cSchristos pline("You are almost hit by %s!", buf);
20361f28255Scgd return (0);
20461f28255Scgd } else {
2053ea4a95cSchristos if (Blind)
2063ea4a95cSchristos pline("You are hit!");
2073ea4a95cSchristos else
2083ea4a95cSchristos pline("You are hit by %s!", buf);
20961f28255Scgd losehp(dam, name);
21061f28255Scgd return (1);
21161f28255Scgd }
21261f28255Scgd }
21361f28255Scgd
214a7a3b831Sdholland const char mlarge[] = "bCDdegIlmnoPSsTUwY',&";
21561f28255Scgd
2161fa8a9a6Sdholland /* return TRUE if mon still alive */
21761f28255Scgd boolean
hmon(struct monst * mon,struct obj * obj,int thrown)2181fa8a9a6Sdholland hmon(struct monst *mon, struct obj *obj, int thrown)
21961f28255Scgd {
2203ea4a95cSchristos int tmp;
22161f28255Scgd boolean hittxt = FALSE;
22261f28255Scgd
22361f28255Scgd if (!obj) {
22461f28255Scgd tmp = rnd(2); /* attack with bare hands */
22561f28255Scgd if (mon->data->mlet == 'c' && !uarmg) {
22661f28255Scgd pline("You hit the cockatrice with your bare hands.");
22761f28255Scgd pline("You turn to stone ...");
22861f28255Scgd done_in_by(mon);
22961f28255Scgd }
23061f28255Scgd } else if (obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) {
23161f28255Scgd if (obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG))
23261f28255Scgd tmp = rnd(2);
23361f28255Scgd else {
2343ea4a95cSchristos if (strchr(mlarge, mon->data->mlet)) {
23561f28255Scgd tmp = rnd(objects[obj->otyp].wldam);
2363ea4a95cSchristos if (obj->otyp == TWO_HANDED_SWORD)
2373ea4a95cSchristos tmp += d(2, 6);
2383ea4a95cSchristos else if (obj->otyp == FLAIL)
2393ea4a95cSchristos tmp += rnd(4);
24061f28255Scgd } else {
24161f28255Scgd tmp = rnd(objects[obj->otyp].wsdam);
24261f28255Scgd }
24361f28255Scgd tmp += obj->spe;
24461f28255Scgd if (!thrown && obj == uwep && obj->otyp == BOOMERANG
24561f28255Scgd && !rn2(3)) {
24661f28255Scgd pline("As you hit %s, the boomerang breaks into splinters.",
24761f28255Scgd monnam(mon));
24861f28255Scgd freeinv(obj);
24961f28255Scgd setworn((struct obj *) 0, obj->owornmask);
25061f28255Scgd obfree(obj, (struct obj *) 0);
2512ad8d2c6Sjnemeth obj = NULL;
25261f28255Scgd tmp++;
25361f28255Scgd }
25461f28255Scgd }
2552ad8d2c6Sjnemeth if (mon->data->mlet == 'O' && obj != NULL &&
2562ad8d2c6Sjnemeth obj->otyp == TWO_HANDED_SWORD &&
25761f28255Scgd !strcmp(ONAME(obj), "Orcrist"))
25861f28255Scgd tmp += rnd(10);
2593ea4a95cSchristos } else
2603ea4a95cSchristos switch (obj->otyp) {
26161f28255Scgd case HEAVY_IRON_BALL:
2623ea4a95cSchristos tmp = rnd(25);
2633ea4a95cSchristos break;
26461f28255Scgd case EXPENSIVE_CAMERA:
26561f28255Scgd pline("You succeed in destroying your camera. Congratulations!");
26661f28255Scgd freeinv(obj);
26761f28255Scgd if (obj->owornmask)
26861f28255Scgd setworn((struct obj *) 0, obj->owornmask);
26961f28255Scgd obfree(obj, (struct obj *) 0);
27061f28255Scgd return (TRUE);
27161f28255Scgd case DEAD_COCKATRICE:
27261f28255Scgd pline("You hit %s with the cockatrice corpse.",
27361f28255Scgd monnam(mon));
27461f28255Scgd if (mon->data->mlet == 'c') {
27561f28255Scgd tmp = 1;
27661f28255Scgd hittxt = TRUE;
27761f28255Scgd break;
27861f28255Scgd }
27961f28255Scgd pline("%s is turned to stone!", Monnam(mon));
28061f28255Scgd killed(mon);
28161f28255Scgd return (FALSE);
28261f28255Scgd case CLOVE_OF_GARLIC: /* no effect against demons */
2833ea4a95cSchristos if (strchr(UNDEAD, mon->data->mlet))
28461f28255Scgd mon->mflee = 1;
28561f28255Scgd tmp = 1;
28661f28255Scgd break;
28761f28255Scgd default:
28861f28255Scgd /* non-weapons can damage because of their weight */
28961f28255Scgd /* (but not too much) */
29061f28255Scgd tmp = obj->owt / 10;
2913ea4a95cSchristos if (tmp < 1)
2923ea4a95cSchristos tmp = 1;
2933ea4a95cSchristos else
2943ea4a95cSchristos tmp = rnd(tmp);
2953ea4a95cSchristos if (tmp > 6)
2963ea4a95cSchristos tmp = 6;
29761f28255Scgd }
29861f28255Scgd
29961f28255Scgd /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
30061f28255Scgd
30161f28255Scgd tmp += u.udaminc + dbon();
30261f28255Scgd if (u.uswallow) {
30361f28255Scgd if ((tmp -= u.uswldtim) <= 0) {
30461f28255Scgd pline("Your arms are no longer able to hit.");
30561f28255Scgd return (TRUE);
30661f28255Scgd }
30761f28255Scgd }
3083ea4a95cSchristos if (tmp < 1)
3093ea4a95cSchristos tmp = 1;
31061f28255Scgd mon->mhp -= tmp;
31161f28255Scgd if (mon->mhp < 1) {
31261f28255Scgd killed(mon);
31361f28255Scgd return (FALSE);
31461f28255Scgd }
31561f28255Scgd if (mon->mtame && (!mon->mflee || mon->mfleetim)) {
31661f28255Scgd mon->mflee = 1; /* Rick Richardson */
31761f28255Scgd mon->mfleetim += 10 * rnd(tmp);
31861f28255Scgd }
31961f28255Scgd if (!hittxt) {
3202ad8d2c6Sjnemeth if (thrown) {
32161f28255Scgd /* this assumes that we cannot throw plural things */
3222ad8d2c6Sjnemeth if (obj == NULL)
3232ad8d2c6Sjnemeth panic("thrown non-object");
32461f28255Scgd hit(xname(obj) /* or: objects[obj->otyp].oc_name */ ,
32561f28255Scgd mon, exclam(tmp));
3262ad8d2c6Sjnemeth } else if (Blind)
32761f28255Scgd pline("You hit it.");
32861f28255Scgd else
32961f28255Scgd pline("You hit %s%s", monnam(mon), exclam(tmp));
33061f28255Scgd }
33161f28255Scgd if (u.umconf && !thrown) {
33261f28255Scgd if (!Blind) {
33361f28255Scgd pline("Your hands stop glowing blue.");
33461f28255Scgd if (!mon->mfroz && !mon->msleep)
33561f28255Scgd pline("%s appears confused.", Monnam(mon));
33661f28255Scgd }
33761f28255Scgd mon->mconf = 1;
33861f28255Scgd u.umconf = 0;
33961f28255Scgd }
34061f28255Scgd return (TRUE); /* mon still alive */
34161f28255Scgd }
34261f28255Scgd
34361f28255Scgd /* try to attack; return FALSE if monster evaded */
34461f28255Scgd /* u.dx and u.dy must be set */
3453ea4a95cSchristos int
attack(struct monst * mtmp)3461fa8a9a6Sdholland attack(struct monst *mtmp)
34761f28255Scgd {
34861f28255Scgd schar tmp;
34961f28255Scgd boolean malive = TRUE;
350ab8b6343Sjsm const struct permonst *mdat;
35161f28255Scgd mdat = mtmp->data;
35261f28255Scgd
3533ea4a95cSchristos u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe
3543ea4a95cSchristos * attacks */
35561f28255Scgd
35661f28255Scgd if (mdat->mlet == 'L' && !mtmp->mfroz && !mtmp->msleep &&
35761f28255Scgd !mtmp->mconf && mtmp->mcansee && !rn2(7) &&
35861f28255Scgd (m_move(mtmp, 0) == 2 /* he died */ || /* he moved: */
35961f28255Scgd mtmp->mx != u.ux + u.dx || mtmp->my != u.uy + u.dy))
36061f28255Scgd return (FALSE);
36161f28255Scgd
36261f28255Scgd if (mtmp->mimic) {
3633ea4a95cSchristos if (!u.ustuck && !mtmp->mflee)
3643ea4a95cSchristos u.ustuck = mtmp;
36561f28255Scgd switch (levl[u.ux + u.dx][u.uy + u.dy].scrsym) {
36661f28255Scgd case '+':
36761f28255Scgd pline("The door actually was a Mimic.");
36861f28255Scgd break;
36961f28255Scgd case '$':
37061f28255Scgd pline("The chest was a Mimic!");
37161f28255Scgd break;
37261f28255Scgd default:
37361f28255Scgd pline("Wait! That's a Mimic!");
37461f28255Scgd }
37561f28255Scgd wakeup(mtmp); /* clears mtmp->mimic */
37661f28255Scgd return (TRUE);
37761f28255Scgd }
37861f28255Scgd wakeup(mtmp);
37961f28255Scgd
38061f28255Scgd if (mtmp->mhide && mtmp->mundetected) {
3813ea4a95cSchristos struct obj *obj;
38261f28255Scgd
38361f28255Scgd mtmp->mundetected = 0;
38461f28255Scgd if ((obj = o_at(mtmp->mx, mtmp->my)) && !Blind)
38561f28255Scgd pline("Wait! There's a %s hiding under %s!",
38661f28255Scgd mdat->mname, doname(obj));
38761f28255Scgd return (TRUE);
38861f28255Scgd }
38961f28255Scgd tmp = u.uluck + u.ulevel + mdat->ac + abon();
39061f28255Scgd if (uwep) {
39161f28255Scgd if (uwep->olet == WEAPON_SYM || uwep->otyp == PICK_AXE)
39261f28255Scgd tmp += uwep->spe;
3933ea4a95cSchristos if (uwep->otyp == TWO_HANDED_SWORD)
3943ea4a95cSchristos tmp -= 1;
3953ea4a95cSchristos else if (uwep->otyp == DAGGER)
3963ea4a95cSchristos tmp += 2;
3973ea4a95cSchristos else if (uwep->otyp == CRYSKNIFE)
3983ea4a95cSchristos tmp += 3;
39961f28255Scgd else if (uwep->otyp == SPEAR &&
4003ea4a95cSchristos strchr("XDne", mdat->mlet))
4013ea4a95cSchristos tmp += 2;
40261f28255Scgd }
40361f28255Scgd if (mtmp->msleep) {
40461f28255Scgd mtmp->msleep = 0;
40561f28255Scgd tmp += 2;
40661f28255Scgd }
40761f28255Scgd if (mtmp->mfroz) {
40861f28255Scgd tmp += 4;
4093ea4a95cSchristos if (!rn2(10))
4103ea4a95cSchristos mtmp->mfroz = 0;
41161f28255Scgd }
4123ea4a95cSchristos if (mtmp->mflee)
4133ea4a95cSchristos tmp += 2;
4143ea4a95cSchristos if (u.utrap)
4153ea4a95cSchristos tmp -= 3;
41661f28255Scgd
41761f28255Scgd /* with a lot of luggage, your agility diminishes */
41861f28255Scgd tmp -= (inv_weight() + 40) / 20;
41961f28255Scgd
42061f28255Scgd if (tmp <= rnd(20) && !u.uswallow) {
4213ea4a95cSchristos if (Blind)
4223ea4a95cSchristos pline("You miss it.");
4233ea4a95cSchristos else
4243ea4a95cSchristos pline("You miss %s.", monnam(mtmp));
42561f28255Scgd } else {
42661f28255Scgd /* we hit the monster; be careful: it might die! */
42761f28255Scgd
42861f28255Scgd if ((malive = hmon(mtmp, uwep, 0)) == TRUE) {
42961f28255Scgd /* monster still alive */
43061f28255Scgd if (!rn2(25) && mtmp->mhp < mtmp->mhpmax / 2) {
43161f28255Scgd mtmp->mflee = 1;
4323ea4a95cSchristos if (!rn2(3))
4333ea4a95cSchristos mtmp->mfleetim = rnd(100);
43461f28255Scgd if (u.ustuck == mtmp && !u.uswallow)
43561f28255Scgd u.ustuck = 0;
43661f28255Scgd }
43761f28255Scgd #ifndef NOWORM
43861f28255Scgd if (mtmp->wormno)
43961f28255Scgd cutworm(mtmp, u.ux + u.dx, u.uy + u.dy,
44061f28255Scgd uwep ? uwep->otyp : 0);
4413ea4a95cSchristos #endif /* NOWORM */
44261f28255Scgd }
44361f28255Scgd if (mdat->mlet == 'a') {
44461f28255Scgd if (rn2(2)) {
44561f28255Scgd pline("You are splashed by the blob's acid!");
44661f28255Scgd losehp_m(rnd(6), mtmp);
4473ea4a95cSchristos if (!rn2(30))
4483ea4a95cSchristos corrode_armor();
44961f28255Scgd }
4503ea4a95cSchristos if (!rn2(6))
4513ea4a95cSchristos corrode_weapon();
45261f28255Scgd }
45361f28255Scgd }
45461f28255Scgd if (malive && mdat->mlet == 'E' && canseemon(mtmp)
45561f28255Scgd && !mtmp->mcan && rn2(3)) {
45661f28255Scgd if (mtmp->mcansee) {
45761f28255Scgd pline("You are frozen by the floating eye's gaze!");
45861f28255Scgd nomul((u.ulevel > 6 || rn2(4)) ? rn1(20, -21) : -200);
45961f28255Scgd } else {
46061f28255Scgd pline("The blinded floating eye cannot defend itself.");
4613ea4a95cSchristos if (!rn2(500))
4623ea4a95cSchristos if ((int) u.uluck > LUCKMIN)
4633ea4a95cSchristos u.uluck--;
46461f28255Scgd }
46561f28255Scgd }
46661f28255Scgd return (TRUE);
46761f28255Scgd }
468