Home | History | Annotate | Line # | Download | only in hack
hack.fight.c revision 1.8
      1  1.8  dholland /*	$NetBSD: hack.fight.c,v 1.8 2008/01/28 06:55:41 dholland Exp $	*/
      2  1.4  christos 
      3  1.2   mycroft /*
      4  1.6       jsm  * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
      5  1.6       jsm  * Amsterdam
      6  1.6       jsm  * All rights reserved.
      7  1.6       jsm  *
      8  1.6       jsm  * Redistribution and use in source and binary forms, with or without
      9  1.6       jsm  * modification, are permitted provided that the following conditions are
     10  1.6       jsm  * met:
     11  1.6       jsm  *
     12  1.6       jsm  * - Redistributions of source code must retain the above copyright notice,
     13  1.6       jsm  * this list of conditions and the following disclaimer.
     14  1.6       jsm  *
     15  1.6       jsm  * - Redistributions in binary form must reproduce the above copyright
     16  1.6       jsm  * notice, this list of conditions and the following disclaimer in the
     17  1.6       jsm  * documentation and/or other materials provided with the distribution.
     18  1.6       jsm  *
     19  1.6       jsm  * - Neither the name of the Stichting Centrum voor Wiskunde en
     20  1.6       jsm  * Informatica, nor the names of its contributors may be used to endorse or
     21  1.6       jsm  * promote products derived from this software without specific prior
     22  1.6       jsm  * written permission.
     23  1.6       jsm  *
     24  1.6       jsm  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     25  1.6       jsm  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  1.6       jsm  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     27  1.6       jsm  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     28  1.6       jsm  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     29  1.6       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     30  1.6       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     31  1.6       jsm  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     32  1.6       jsm  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     33  1.6       jsm  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     34  1.6       jsm  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35  1.6       jsm  */
     36  1.6       jsm 
     37  1.6       jsm /*
     38  1.6       jsm  * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org>
     39  1.6       jsm  * All rights reserved.
     40  1.6       jsm  *
     41  1.6       jsm  * Redistribution and use in source and binary forms, with or without
     42  1.6       jsm  * modification, are permitted provided that the following conditions
     43  1.6       jsm  * are met:
     44  1.6       jsm  * 1. Redistributions of source code must retain the above copyright
     45  1.6       jsm  *    notice, this list of conditions and the following disclaimer.
     46  1.6       jsm  * 2. Redistributions in binary form must reproduce the above copyright
     47  1.6       jsm  *    notice, this list of conditions and the following disclaimer in the
     48  1.6       jsm  *    documentation and/or other materials provided with the distribution.
     49  1.6       jsm  * 3. The name of the author may not be used to endorse or promote products
     50  1.6       jsm  *    derived from this software without specific prior written permission.
     51  1.6       jsm  *
     52  1.6       jsm  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     53  1.6       jsm  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     54  1.6       jsm  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
     55  1.6       jsm  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     56  1.6       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     57  1.6       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     58  1.6       jsm  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     59  1.6       jsm  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     60  1.6       jsm  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     61  1.6       jsm  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     62  1.2   mycroft  */
     63  1.2   mycroft 
     64  1.4  christos #include <sys/cdefs.h>
     65  1.2   mycroft #ifndef lint
     66  1.8  dholland __RCSID("$NetBSD: hack.fight.c,v 1.8 2008/01/28 06:55:41 dholland Exp $");
     67  1.4  christos #endif				/* not lint */
     68  1.1       cgd 
     69  1.4  christos #include "hack.h"
     70  1.4  christos #include "extern.h"
     71  1.1       cgd 
     72  1.4  christos static boolean  far_noise;
     73  1.4  christos static long     noisetime;
     74  1.1       cgd 
     75  1.1       cgd /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
     76  1.4  christos int
     77  1.4  christos hitmm(magr, mdef)
     78  1.4  christos 	struct monst   *magr, *mdef;
     79  1.4  christos {
     80  1.5       jsm 	const struct permonst *pa = magr->data, *pd = mdef->data;
     81  1.8  dholland 	int             didhit;
     82  1.4  christos 	schar           tmp;
     83  1.4  christos 	boolean         vis;
     84  1.8  dholland 
     85  1.4  christos 	if (strchr("Eauy", pa->mlet))
     86  1.4  christos 		return (0);
     87  1.4  christos 	if (magr->mfroz)
     88  1.4  christos 		return (0);	/* riv05!a3 */
     89  1.1       cgd 	tmp = pd->ac + pa->mlevel;
     90  1.4  christos 	if (mdef->mconf || mdef->mfroz || mdef->msleep) {
     91  1.1       cgd 		tmp += 4;
     92  1.4  christos 		if (mdef->msleep)
     93  1.4  christos 			mdef->msleep = 0;
     94  1.1       cgd 	}
     95  1.8  dholland 	didhit = (tmp > rnd(20));
     96  1.8  dholland 	if (didhit)
     97  1.4  christos 		mdef->msleep = 0;
     98  1.4  christos 	vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my));
     99  1.4  christos 	if (vis) {
    100  1.4  christos 		char            buf[BUFSZ];
    101  1.4  christos 		if (mdef->mimic)
    102  1.4  christos 			seemimic(mdef);
    103  1.4  christos 		if (magr->mimic)
    104  1.4  christos 			seemimic(magr);
    105  1.4  christos 		(void) sprintf(buf, "%s %s", Monnam(magr),
    106  1.8  dholland 			       didhit ? "hits" : "misses");
    107  1.1       cgd 		pline("%s %s.", buf, monnam(mdef));
    108  1.1       cgd 	} else {
    109  1.4  christos 		boolean         far = (dist(magr->mx, magr->my) > 15);
    110  1.4  christos 		if (far != far_noise || moves - noisetime > 10) {
    111  1.1       cgd 			far_noise = far;
    112  1.1       cgd 			noisetime = moves;
    113  1.1       cgd 			pline("You hear some noises%s.",
    114  1.4  christos 			      far ? " in the distance" : "");
    115  1.1       cgd 		}
    116  1.1       cgd 	}
    117  1.8  dholland 	if (didhit) {
    118  1.4  christos 		if (magr->data->mlet == 'c' && !magr->cham) {
    119  1.1       cgd 			magr->mhpmax += 3;
    120  1.4  christos 			if (vis)
    121  1.4  christos 				pline("%s is turned to stone!", Monnam(mdef));
    122  1.4  christos 			else if (mdef->mtame)
    123  1.4  christos 				pline("You have a peculiarly sad feeling for a moment, then it passes.");
    124  1.1       cgd 			monstone(mdef);
    125  1.8  dholland 			didhit = 2;
    126  1.4  christos 		} else if ((mdef->mhp -= d(pa->damn, pa->damd)) < 1) {
    127  1.4  christos 			magr->mhpmax += 1 + rn2(pd->mlevel + 1);
    128  1.4  christos 			if (magr->mtame && magr->mhpmax > 8 * pa->mlevel) {
    129  1.4  christos 				if (pa == &li_dog)
    130  1.4  christos 					magr->data = pa = &dog;
    131  1.4  christos 				else if (pa == &dog)
    132  1.4  christos 					magr->data = pa = &la_dog;
    133  1.1       cgd 			}
    134  1.4  christos 			if (vis)
    135  1.4  christos 				pline("%s is killed!", Monnam(mdef));
    136  1.4  christos 			else if (mdef->mtame)
    137  1.4  christos 				pline("You have a sad feeling for a moment, then it passes.");
    138  1.1       cgd 			mondied(mdef);
    139  1.8  dholland 			didhit = 2;
    140  1.1       cgd 		}
    141  1.1       cgd 	}
    142  1.8  dholland 	return (didhit);
    143  1.1       cgd }
    144  1.1       cgd 
    145  1.1       cgd /* drop (perhaps) a cadaver and remove monster */
    146  1.4  christos void
    147  1.4  christos mondied(mdef)
    148  1.4  christos 	struct monst   *mdef;
    149  1.4  christos {
    150  1.5       jsm 	const struct permonst *pd = mdef->data;
    151  1.4  christos 	if (letter(pd->mlet) && rn2(3)) {
    152  1.4  christos 		(void) mkobj_at(pd->mlet, mdef->mx, mdef->my);
    153  1.4  christos 		if (cansee(mdef->mx, mdef->my)) {
    154  1.4  christos 			unpmon(mdef);
    155  1.4  christos 			atl(mdef->mx, mdef->my, fobj->olet);
    156  1.1       cgd 		}
    157  1.4  christos 		stackobj(fobj);
    158  1.4  christos 	}
    159  1.4  christos 	mondead(mdef);
    160  1.1       cgd }
    161  1.1       cgd 
    162  1.1       cgd /* drop a rock and remove monster */
    163  1.4  christos void
    164  1.4  christos monstone(mdef)
    165  1.4  christos 	struct monst   *mdef;
    166  1.4  christos {
    167  1.4  christos 	if (strchr(mlarge, mdef->data->mlet))
    168  1.1       cgd 		mksobj_at(ENORMOUS_ROCK, mdef->mx, mdef->my);
    169  1.1       cgd 	else
    170  1.1       cgd 		mksobj_at(ROCK, mdef->mx, mdef->my);
    171  1.4  christos 	if (cansee(mdef->mx, mdef->my)) {
    172  1.1       cgd 		unpmon(mdef);
    173  1.4  christos 		atl(mdef->mx, mdef->my, fobj->olet);
    174  1.1       cgd 	}
    175  1.1       cgd 	mondead(mdef);
    176  1.1       cgd }
    177  1.1       cgd 
    178  1.4  christos 
    179  1.4  christos int
    180  1.4  christos fightm(mtmp)
    181  1.4  christos 	struct monst   *mtmp;
    182  1.4  christos {
    183  1.4  christos 	struct monst   *mon;
    184  1.4  christos 	for (mon = fmon; mon; mon = mon->nmon)
    185  1.4  christos 		if (mon != mtmp) {
    186  1.4  christos 			if (DIST(mon->mx, mon->my, mtmp->mx, mtmp->my) < 3)
    187  1.4  christos 				if (rn2(4))
    188  1.4  christos 					return (hitmm(mtmp, mon));
    189  1.4  christos 		}
    190  1.4  christos 	return (-1);
    191  1.1       cgd }
    192  1.1       cgd 
    193  1.1       cgd /* u is hit by sth, but not a monster */
    194  1.4  christos int
    195  1.4  christos thitu(tlev, dam, name)
    196  1.4  christos 	int tlev, dam;
    197  1.5       jsm 	const char           *name;
    198  1.1       cgd {
    199  1.4  christos 	char            buf[BUFSZ];
    200  1.4  christos 	setan(name, buf);
    201  1.4  christos 	if (u.uac + tlev <= rnd(20)) {
    202  1.4  christos 		if (Blind)
    203  1.4  christos 			pline("It misses.");
    204  1.4  christos 		else
    205  1.4  christos 			pline("You are almost hit by %s!", buf);
    206  1.4  christos 		return (0);
    207  1.1       cgd 	} else {
    208  1.4  christos 		if (Blind)
    209  1.4  christos 			pline("You are hit!");
    210  1.4  christos 		else
    211  1.4  christos 			pline("You are hit by %s!", buf);
    212  1.4  christos 		losehp(dam, name);
    213  1.4  christos 		return (1);
    214  1.1       cgd 	}
    215  1.1       cgd }
    216  1.1       cgd 
    217  1.4  christos char            mlarge[] = "bCDdegIlmnoPSsTUwY',&";
    218  1.1       cgd 
    219  1.1       cgd boolean
    220  1.4  christos hmon(mon, obj, thrown)		/* return TRUE if mon still alive */
    221  1.4  christos 	struct monst   *mon;
    222  1.4  christos 	struct obj     *obj;
    223  1.4  christos 	int thrown;
    224  1.1       cgd {
    225  1.4  christos 	int tmp;
    226  1.4  christos 	boolean         hittxt = FALSE;
    227  1.1       cgd 
    228  1.4  christos 	if (!obj) {
    229  1.1       cgd 		tmp = rnd(2);	/* attack with bare hands */
    230  1.4  christos 		if (mon->data->mlet == 'c' && !uarmg) {
    231  1.1       cgd 			pline("You hit the cockatrice with your bare hands.");
    232  1.1       cgd 			pline("You turn to stone ...");
    233  1.1       cgd 			done_in_by(mon);
    234  1.1       cgd 		}
    235  1.4  christos 	} else if (obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) {
    236  1.4  christos 		if (obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG))
    237  1.4  christos 			tmp = rnd(2);
    238  1.4  christos 		else {
    239  1.4  christos 			if (strchr(mlarge, mon->data->mlet)) {
    240  1.4  christos 				tmp = rnd(objects[obj->otyp].wldam);
    241  1.4  christos 				if (obj->otyp == TWO_HANDED_SWORD)
    242  1.4  christos 					tmp += d(2, 6);
    243  1.4  christos 				else if (obj->otyp == FLAIL)
    244  1.4  christos 					tmp += rnd(4);
    245  1.4  christos 			} else {
    246  1.4  christos 				tmp = rnd(objects[obj->otyp].wsdam);
    247  1.4  christos 			}
    248  1.4  christos 			tmp += obj->spe;
    249  1.4  christos 			if (!thrown && obj == uwep && obj->otyp == BOOMERANG
    250  1.4  christos 			    && !rn2(3)) {
    251  1.4  christos 				pline("As you hit %s, the boomerang breaks into splinters.",
    252  1.4  christos 				      monnam(mon));
    253  1.4  christos 				freeinv(obj);
    254  1.4  christos 				setworn((struct obj *) 0, obj->owornmask);
    255  1.4  christos 				obfree(obj, (struct obj *) 0);
    256  1.7   jnemeth 				obj = NULL;
    257  1.4  christos 				tmp++;
    258  1.4  christos 			}
    259  1.1       cgd 		}
    260  1.7   jnemeth 		if (mon->data->mlet == 'O' && obj != NULL &&
    261  1.7   jnemeth 		    obj->otyp == TWO_HANDED_SWORD &&
    262  1.4  christos 		    !strcmp(ONAME(obj), "Orcrist"))
    263  1.4  christos 			tmp += rnd(10);
    264  1.4  christos 	} else
    265  1.4  christos 		switch (obj->otyp) {
    266  1.1       cgd 		case HEAVY_IRON_BALL:
    267  1.4  christos 			tmp = rnd(25);
    268  1.4  christos 			break;
    269  1.1       cgd 		case EXPENSIVE_CAMERA:
    270  1.4  christos 			pline("You succeed in destroying your camera. Congratulations!");
    271  1.1       cgd 			freeinv(obj);
    272  1.4  christos 			if (obj->owornmask)
    273  1.1       cgd 				setworn((struct obj *) 0, obj->owornmask);
    274  1.1       cgd 			obfree(obj, (struct obj *) 0);
    275  1.4  christos 			return (TRUE);
    276  1.1       cgd 		case DEAD_COCKATRICE:
    277  1.1       cgd 			pline("You hit %s with the cockatrice corpse.",
    278  1.4  christos 			      monnam(mon));
    279  1.4  christos 			if (mon->data->mlet == 'c') {
    280  1.1       cgd 				tmp = 1;
    281  1.1       cgd 				hittxt = TRUE;
    282  1.1       cgd 				break;
    283  1.1       cgd 			}
    284  1.1       cgd 			pline("%s is turned to stone!", Monnam(mon));
    285  1.1       cgd 			killed(mon);
    286  1.4  christos 			return (FALSE);
    287  1.4  christos 		case CLOVE_OF_GARLIC:	/* no effect against demons */
    288  1.4  christos 			if (strchr(UNDEAD, mon->data->mlet))
    289  1.1       cgd 				mon->mflee = 1;
    290  1.1       cgd 			tmp = 1;
    291  1.1       cgd 			break;
    292  1.1       cgd 		default:
    293  1.1       cgd 			/* non-weapons can damage because of their weight */
    294  1.1       cgd 			/* (but not too much) */
    295  1.4  christos 			tmp = obj->owt / 10;
    296  1.4  christos 			if (tmp < 1)
    297  1.4  christos 				tmp = 1;
    298  1.4  christos 			else
    299  1.4  christos 				tmp = rnd(tmp);
    300  1.4  christos 			if (tmp > 6)
    301  1.4  christos 				tmp = 6;
    302  1.1       cgd 		}
    303  1.1       cgd 
    304  1.1       cgd 	/****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
    305  1.1       cgd 
    306  1.1       cgd 	tmp += u.udaminc + dbon();
    307  1.4  christos 	if (u.uswallow) {
    308  1.4  christos 		if ((tmp -= u.uswldtim) <= 0) {
    309  1.1       cgd 			pline("Your arms are no longer able to hit.");
    310  1.4  christos 			return (TRUE);
    311  1.1       cgd 		}
    312  1.1       cgd 	}
    313  1.4  christos 	if (tmp < 1)
    314  1.4  christos 		tmp = 1;
    315  1.1       cgd 	mon->mhp -= tmp;
    316  1.4  christos 	if (mon->mhp < 1) {
    317  1.1       cgd 		killed(mon);
    318  1.4  christos 		return (FALSE);
    319  1.1       cgd 	}
    320  1.4  christos 	if (mon->mtame && (!mon->mflee || mon->mfleetim)) {
    321  1.4  christos 		mon->mflee = 1;	/* Rick Richardson */
    322  1.4  christos 		mon->mfleetim += 10 * rnd(tmp);
    323  1.1       cgd 	}
    324  1.4  christos 	if (!hittxt) {
    325  1.7   jnemeth 		if (thrown) {
    326  1.1       cgd 			/* this assumes that we cannot throw plural things */
    327  1.7   jnemeth 			if (obj == NULL)
    328  1.7   jnemeth 				panic("thrown non-object");
    329  1.4  christos 			hit(xname(obj) /* or: objects[obj->otyp].oc_name */ ,
    330  1.4  christos 			    mon, exclam(tmp));
    331  1.7   jnemeth 		} else if (Blind)
    332  1.1       cgd 			pline("You hit it.");
    333  1.1       cgd 		else
    334  1.1       cgd 			pline("You hit %s%s", monnam(mon), exclam(tmp));
    335  1.1       cgd 	}
    336  1.4  christos 	if (u.umconf && !thrown) {
    337  1.4  christos 		if (!Blind) {
    338  1.1       cgd 			pline("Your hands stop glowing blue.");
    339  1.4  christos 			if (!mon->mfroz && !mon->msleep)
    340  1.4  christos 				pline("%s appears confused.", Monnam(mon));
    341  1.1       cgd 		}
    342  1.1       cgd 		mon->mconf = 1;
    343  1.1       cgd 		u.umconf = 0;
    344  1.1       cgd 	}
    345  1.4  christos 	return (TRUE);		/* mon still alive */
    346  1.1       cgd }
    347  1.1       cgd 
    348  1.1       cgd /* try to attack; return FALSE if monster evaded */
    349  1.1       cgd /* u.dx and u.dy must be set */
    350  1.4  christos int
    351  1.1       cgd attack(mtmp)
    352  1.4  christos 	struct monst   *mtmp;
    353  1.1       cgd {
    354  1.4  christos 	schar           tmp;
    355  1.4  christos 	boolean         malive = TRUE;
    356  1.5       jsm 	const struct permonst *mdat;
    357  1.1       cgd 	mdat = mtmp->data;
    358  1.1       cgd 
    359  1.4  christos 	u_wipe_engr(3);		/* andrew@orca: prevent unlimited pick-axe
    360  1.4  christos 				 * attacks */
    361  1.1       cgd 
    362  1.4  christos 	if (mdat->mlet == 'L' && !mtmp->mfroz && !mtmp->msleep &&
    363  1.4  christos 	    !mtmp->mconf && mtmp->mcansee && !rn2(7) &&
    364  1.4  christos 	    (m_move(mtmp, 0) == 2 /* he died */ ||	/* he moved: */
    365  1.4  christos 	     mtmp->mx != u.ux + u.dx || mtmp->my != u.uy + u.dy))
    366  1.4  christos 		return (FALSE);
    367  1.4  christos 
    368  1.4  christos 	if (mtmp->mimic) {
    369  1.4  christos 		if (!u.ustuck && !mtmp->mflee)
    370  1.4  christos 			u.ustuck = mtmp;
    371  1.4  christos 		switch (levl[u.ux + u.dx][u.uy + u.dy].scrsym) {
    372  1.1       cgd 		case '+':
    373  1.1       cgd 			pline("The door actually was a Mimic.");
    374  1.1       cgd 			break;
    375  1.1       cgd 		case '$':
    376  1.1       cgd 			pline("The chest was a Mimic!");
    377  1.1       cgd 			break;
    378  1.1       cgd 		default:
    379  1.1       cgd 			pline("Wait! That's a Mimic!");
    380  1.1       cgd 		}
    381  1.1       cgd 		wakeup(mtmp);	/* clears mtmp->mimic */
    382  1.4  christos 		return (TRUE);
    383  1.1       cgd 	}
    384  1.1       cgd 	wakeup(mtmp);
    385  1.1       cgd 
    386  1.4  christos 	if (mtmp->mhide && mtmp->mundetected) {
    387  1.4  christos 		struct obj     *obj;
    388  1.1       cgd 
    389  1.1       cgd 		mtmp->mundetected = 0;
    390  1.4  christos 		if ((obj = o_at(mtmp->mx, mtmp->my)) && !Blind)
    391  1.1       cgd 			pline("Wait! There's a %s hiding under %s!",
    392  1.4  christos 			      mdat->mname, doname(obj));
    393  1.4  christos 		return (TRUE);
    394  1.1       cgd 	}
    395  1.1       cgd 	tmp = u.uluck + u.ulevel + mdat->ac + abon();
    396  1.4  christos 	if (uwep) {
    397  1.4  christos 		if (uwep->olet == WEAPON_SYM || uwep->otyp == PICK_AXE)
    398  1.1       cgd 			tmp += uwep->spe;
    399  1.4  christos 		if (uwep->otyp == TWO_HANDED_SWORD)
    400  1.4  christos 			tmp -= 1;
    401  1.4  christos 		else if (uwep->otyp == DAGGER)
    402  1.4  christos 			tmp += 2;
    403  1.4  christos 		else if (uwep->otyp == CRYSKNIFE)
    404  1.4  christos 			tmp += 3;
    405  1.4  christos 		else if (uwep->otyp == SPEAR &&
    406  1.4  christos 			 strchr("XDne", mdat->mlet))
    407  1.4  christos 			tmp += 2;
    408  1.1       cgd 	}
    409  1.4  christos 	if (mtmp->msleep) {
    410  1.1       cgd 		mtmp->msleep = 0;
    411  1.1       cgd 		tmp += 2;
    412  1.1       cgd 	}
    413  1.4  christos 	if (mtmp->mfroz) {
    414  1.1       cgd 		tmp += 4;
    415  1.4  christos 		if (!rn2(10))
    416  1.4  christos 			mtmp->mfroz = 0;
    417  1.1       cgd 	}
    418  1.4  christos 	if (mtmp->mflee)
    419  1.4  christos 		tmp += 2;
    420  1.4  christos 	if (u.utrap)
    421  1.4  christos 		tmp -= 3;
    422  1.1       cgd 
    423  1.1       cgd 	/* with a lot of luggage, your agility diminishes */
    424  1.4  christos 	tmp -= (inv_weight() + 40) / 20;
    425  1.1       cgd 
    426  1.4  christos 	if (tmp <= rnd(20) && !u.uswallow) {
    427  1.4  christos 		if (Blind)
    428  1.4  christos 			pline("You miss it.");
    429  1.4  christos 		else
    430  1.4  christos 			pline("You miss %s.", monnam(mtmp));
    431  1.1       cgd 	} else {
    432  1.1       cgd 		/* we hit the monster; be careful: it might die! */
    433  1.1       cgd 
    434  1.4  christos 		if ((malive = hmon(mtmp, uwep, 0)) == TRUE) {
    435  1.4  christos 			/* monster still alive */
    436  1.4  christos 			if (!rn2(25) && mtmp->mhp < mtmp->mhpmax / 2) {
    437  1.1       cgd 				mtmp->mflee = 1;
    438  1.4  christos 				if (!rn2(3))
    439  1.4  christos 					mtmp->mfleetim = rnd(100);
    440  1.4  christos 				if (u.ustuck == mtmp && !u.uswallow)
    441  1.1       cgd 					u.ustuck = 0;
    442  1.1       cgd 			}
    443  1.1       cgd #ifndef NOWORM
    444  1.4  christos 			if (mtmp->wormno)
    445  1.4  christos 				cutworm(mtmp, u.ux + u.dx, u.uy + u.dy,
    446  1.1       cgd 					uwep ? uwep->otyp : 0);
    447  1.4  christos #endif	/* NOWORM */
    448  1.1       cgd 		}
    449  1.4  christos 		if (mdat->mlet == 'a') {
    450  1.4  christos 			if (rn2(2)) {
    451  1.1       cgd 				pline("You are splashed by the blob's acid!");
    452  1.1       cgd 				losehp_m(rnd(6), mtmp);
    453  1.4  christos 				if (!rn2(30))
    454  1.4  christos 					corrode_armor();
    455  1.1       cgd 			}
    456  1.4  christos 			if (!rn2(6))
    457  1.4  christos 				corrode_weapon();
    458  1.1       cgd 		}
    459  1.1       cgd 	}
    460  1.4  christos 	if (malive && mdat->mlet == 'E' && canseemon(mtmp)
    461  1.4  christos 	    && !mtmp->mcan && rn2(3)) {
    462  1.4  christos 		if (mtmp->mcansee) {
    463  1.4  christos 			pline("You are frozen by the floating eye's gaze!");
    464  1.4  christos 			nomul((u.ulevel > 6 || rn2(4)) ? rn1(20, -21) : -200);
    465  1.4  christos 		} else {
    466  1.4  christos 			pline("The blinded floating eye cannot defend itself.");
    467  1.4  christos 			if (!rn2(500))
    468  1.4  christos 				if ((int) u.uluck > LUCKMIN)
    469  1.4  christos 					u.uluck--;
    470  1.4  christos 		}
    471  1.1       cgd 	}
    472  1.4  christos 	return (TRUE);
    473  1.1       cgd }
    474