Home | History | Annotate | Line # | Download | only in hack
hack.zap.c revision 1.8
      1  1.8  dholland /*	$NetBSD: hack.zap.c,v 1.8 2009/06/07 18:30:39 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.zap.c,v 1.8 2009/06/07 18:30:39 dholland Exp $");
     67  1.4  christos #endif				/* not lint */
     68  1.1       cgd 
     69  1.1       cgd #include "hack.h"
     70  1.4  christos #include "extern.h"
     71  1.1       cgd 
     72  1.5       jsm const char           *const fl[] = {
     73  1.1       cgd 	"magic missile",
     74  1.1       cgd 	"bolt of fire",
     75  1.1       cgd 	"sleep ray",
     76  1.1       cgd 	"bolt of cold",
     77  1.1       cgd 	"death ray"
     78  1.1       cgd };
     79  1.1       cgd 
     80  1.1       cgd /* Routines for IMMEDIATE wands. */
     81  1.1       cgd /* bhitm: monster mtmp was hit by the effect of wand otmp */
     82  1.4  christos void
     83  1.8  dholland bhitm(struct monst *mtmp, struct obj *otmp)
     84  1.1       cgd {
     85  1.1       cgd 	wakeup(mtmp);
     86  1.4  christos 	switch (otmp->otyp) {
     87  1.1       cgd 	case WAN_STRIKING:
     88  1.4  christos 		if (u.uswallow || rnd(20) < 10 + mtmp->data->ac) {
     89  1.4  christos 			int             tmp = d(2, 12);
     90  1.1       cgd 			hit("wand", mtmp, exclam(tmp));
     91  1.1       cgd 			mtmp->mhp -= tmp;
     92  1.4  christos 			if (mtmp->mhp < 1)
     93  1.4  christos 				killed(mtmp);
     94  1.4  christos 		} else
     95  1.4  christos 			miss("wand", mtmp);
     96  1.1       cgd 		break;
     97  1.1       cgd 	case WAN_SLOW_MONSTER:
     98  1.1       cgd 		mtmp->mspeed = MSLOW;
     99  1.1       cgd 		break;
    100  1.1       cgd 	case WAN_SPEED_MONSTER:
    101  1.1       cgd 		mtmp->mspeed = MFAST;
    102  1.1       cgd 		break;
    103  1.1       cgd 	case WAN_UNDEAD_TURNING:
    104  1.4  christos 		if (strchr(UNDEAD, mtmp->data->mlet)) {
    105  1.1       cgd 			mtmp->mhp -= rnd(8);
    106  1.4  christos 			if (mtmp->mhp < 1)
    107  1.4  christos 				killed(mtmp);
    108  1.4  christos 			else
    109  1.4  christos 				mtmp->mflee = 1;
    110  1.1       cgd 		}
    111  1.1       cgd 		break;
    112  1.1       cgd 	case WAN_POLYMORPH:
    113  1.4  christos 		if (newcham(mtmp, &mons[rn2(CMNUM)]))
    114  1.1       cgd 			objects[otmp->otyp].oc_name_known = 1;
    115  1.1       cgd 		break;
    116  1.1       cgd 	case WAN_CANCELLATION:
    117  1.1       cgd 		mtmp->mcan = 1;
    118  1.1       cgd 		break;
    119  1.1       cgd 	case WAN_TELEPORTATION:
    120  1.1       cgd 		rloc(mtmp);
    121  1.1       cgd 		break;
    122  1.1       cgd 	case WAN_MAKE_INVISIBLE:
    123  1.1       cgd 		mtmp->minvis = 1;
    124  1.1       cgd 		break;
    125  1.1       cgd #ifdef WAN_PROBING
    126  1.1       cgd 	case WAN_PROBING:
    127  1.1       cgd 		mstatusline(mtmp);
    128  1.1       cgd 		break;
    129  1.4  christos #endif	/* WAN_PROBING */
    130  1.1       cgd 	default:
    131  1.1       cgd 		impossible("What an interesting wand (%u)", otmp->otyp);
    132  1.1       cgd 	}
    133  1.1       cgd }
    134  1.1       cgd 
    135  1.8  dholland /*
    136  1.8  dholland  * object obj was hit by the effect of wand otmp
    137  1.8  dholland  * returns TRUE if sth was done
    138  1.8  dholland  */
    139  1.4  christos int
    140  1.8  dholland bhito(struct obj *obj, struct obj *otmp)
    141  1.1       cgd {
    142  1.4  christos 	int             res = TRUE;
    143  1.1       cgd 
    144  1.4  christos 	if (obj == uball || obj == uchain)
    145  1.1       cgd 		res = FALSE;
    146  1.1       cgd 	else
    147  1.4  christos 		switch (otmp->otyp) {
    148  1.4  christos 		case WAN_POLYMORPH:
    149  1.4  christos 			/*
    150  1.4  christos 			 * preserve symbol and quantity, but turn rocks into
    151  1.4  christos 			 * gems
    152  1.4  christos 			 */
    153  1.4  christos 			mkobj_at((obj->otyp == ROCK || obj->otyp == ENORMOUS_ROCK)
    154  1.4  christos 				 ? GEM_SYM : obj->olet,
    155  1.4  christos 				 obj->ox, obj->oy)->quan = obj->quan;
    156  1.4  christos 			delobj(obj);
    157  1.4  christos 			break;
    158  1.4  christos 		case WAN_STRIKING:
    159  1.4  christos 			if (obj->otyp == ENORMOUS_ROCK)
    160  1.4  christos 				fracture_rock(obj);
    161  1.4  christos 			else
    162  1.4  christos 				res = FALSE;
    163  1.4  christos 			break;
    164  1.4  christos 		case WAN_CANCELLATION:
    165  1.4  christos 			if (obj->spe && obj->olet != AMULET_SYM) {
    166  1.4  christos 				obj->known = 0;
    167  1.4  christos 				obj->spe = 0;
    168  1.4  christos 			}
    169  1.4  christos 			break;
    170  1.4  christos 		case WAN_TELEPORTATION:
    171  1.4  christos 			rloco(obj);
    172  1.4  christos 			break;
    173  1.4  christos 		case WAN_MAKE_INVISIBLE:
    174  1.4  christos 			obj->oinvis = 1;
    175  1.4  christos 			break;
    176  1.4  christos 		case WAN_UNDEAD_TURNING:
    177  1.4  christos 			res = revive(obj);
    178  1.4  christos 			break;
    179  1.4  christos 		case WAN_SLOW_MONSTER:	/* no effect on objects */
    180  1.4  christos 		case WAN_SPEED_MONSTER:
    181  1.4  christos #ifdef WAN_PROBING
    182  1.4  christos 		case WAN_PROBING:
    183  1.4  christos #endif	/* WAN_PROBING */
    184  1.1       cgd 			res = FALSE;
    185  1.4  christos 			break;
    186  1.4  christos 		default:
    187  1.4  christos 			impossible("What an interesting wand (%u)", otmp->otyp);
    188  1.1       cgd 		}
    189  1.4  christos 	return (res);
    190  1.1       cgd }
    191  1.1       cgd 
    192  1.4  christos int
    193  1.8  dholland dozap(void)
    194  1.1       cgd {
    195  1.4  christos 	struct obj     *obj;
    196  1.4  christos 	xchar           zx, zy;
    197  1.1       cgd 
    198  1.1       cgd 	obj = getobj("/", "zap");
    199  1.4  christos 	if (!obj)
    200  1.4  christos 		return (0);
    201  1.4  christos 	if (obj->spe < 0 || (obj->spe == 0 && rn2(121))) {
    202  1.1       cgd 		pline("Nothing Happens.");
    203  1.4  christos 		return (1);
    204  1.1       cgd 	}
    205  1.4  christos 	if (obj->spe == 0)
    206  1.1       cgd 		pline("You wrest one more spell from the worn-out wand.");
    207  1.4  christos 	if (!(objects[obj->otyp].bits & NODIR) && !getdir(1))
    208  1.4  christos 		return (1);	/* make him pay for knowing !NODIR */
    209  1.1       cgd 	obj->spe--;
    210  1.4  christos 	if (objects[obj->otyp].bits & IMMEDIATE) {
    211  1.4  christos 		if (u.uswallow)
    212  1.1       cgd 			bhitm(u.ustuck, obj);
    213  1.4  christos 		else if (u.dz) {
    214  1.4  christos 			if (u.dz > 0) {
    215  1.4  christos 				struct obj     *otmp = o_at(u.ux, u.uy);
    216  1.4  christos 				if (otmp)
    217  1.1       cgd 					(void) bhito(otmp, obj);
    218  1.1       cgd 			}
    219  1.1       cgd 		} else
    220  1.4  christos 			(void) bhit(u.dx, u.dy, rn1(8, 6), 0, bhitm, bhito, obj);
    221  1.1       cgd 	} else {
    222  1.4  christos 		switch (obj->otyp) {
    223  1.1       cgd 		case WAN_LIGHT:
    224  1.1       cgd 			litroom(TRUE);
    225  1.1       cgd 			break;
    226  1.1       cgd 		case WAN_SECRET_DOOR_DETECTION:
    227  1.4  christos 			if (!findit())
    228  1.4  christos 				return (1);
    229  1.1       cgd 			break;
    230  1.1       cgd 		case WAN_CREATE_MONSTER:
    231  1.4  christos 			{
    232  1.4  christos 				int             cnt = 1;
    233  1.4  christos 				if (!rn2(23))
    234  1.4  christos 					cnt += rn2(7) + 1;
    235  1.4  christos 				while (cnt--)
    236  1.4  christos 					(void) makemon((struct permonst *) 0, u.ux, u.uy);
    237  1.1       cgd 			}
    238  1.1       cgd 			break;
    239  1.1       cgd 		case WAN_WISHING:
    240  1.4  christos 			{
    241  1.4  christos 				char            buf[BUFSZ];
    242  1.4  christos 				struct obj     *otmp;
    243  1.4  christos 				if (u.uluck + rn2(5) < 0) {
    244  1.4  christos 					pline("Unfortunately, nothing happens.");
    245  1.4  christos 					break;
    246  1.4  christos 				}
    247  1.4  christos 				pline("You may wish for an object. What do you want? ");
    248  1.4  christos 				getlin(buf);
    249  1.4  christos 				if (buf[0] == '\033')
    250  1.4  christos 					buf[0] = 0;
    251  1.4  christos 				otmp = readobjnam(buf);
    252  1.4  christos 				otmp = addinv(otmp);
    253  1.4  christos 				prinv(otmp);
    254  1.4  christos 				break;
    255  1.1       cgd 			}
    256  1.1       cgd 		case WAN_DIGGING:
    257  1.4  christos 			/*
    258  1.4  christos 			 * Original effect (approximately): from CORR: dig
    259  1.4  christos 			 * until we pierce a wall from ROOM: piece wall and
    260  1.4  christos 			 * dig until we reach an ACCESSIBLE place. Currently:
    261  1.4  christos 			 * dig for digdepth positions; also down on request
    262  1.4  christos 			 * of Lennart Augustsson.
    263  1.1       cgd 			 */
    264  1.4  christos 			{
    265  1.4  christos 				struct rm      *room;
    266  1.4  christos 				int             digdepth;
    267  1.4  christos 				if (u.uswallow) {
    268  1.4  christos 					struct monst   *mtmp = u.ustuck;
    269  1.4  christos 
    270  1.4  christos 					pline("You pierce %s's stomach wall!",
    271  1.4  christos 					      monnam(mtmp));
    272  1.4  christos 					mtmp->mhp = 1;	/* almost dead */
    273  1.4  christos 					unstuck(mtmp);
    274  1.4  christos 					mnexto(mtmp);
    275  1.4  christos 					break;
    276  1.4  christos 				}
    277  1.4  christos 				if (u.dz) {
    278  1.4  christos 					if (u.dz < 0) {
    279  1.4  christos 						pline("You loosen a rock from the ceiling.");
    280  1.4  christos 						pline("It falls on your head!");
    281  1.4  christos 						losehp(1, "falling rock");
    282  1.4  christos 						mksobj_at(ROCK, u.ux, u.uy);
    283  1.4  christos 						fobj->quan = 1;
    284  1.4  christos 						stackobj(fobj);
    285  1.4  christos 						if (Invisible)
    286  1.4  christos 							newsym(u.ux, u.uy);
    287  1.4  christos 					} else {
    288  1.4  christos 						dighole();
    289  1.4  christos 					}
    290  1.4  christos 					break;
    291  1.4  christos 				}
    292  1.4  christos 				zx = u.ux + u.dx;
    293  1.4  christos 				zy = u.uy + u.dy;
    294  1.4  christos 				digdepth = 8 + rn2(18);
    295  1.4  christos 				Tmp_at(-1, '*');	/* open call */
    296  1.4  christos 				while (--digdepth >= 0) {
    297  1.4  christos 					if (!isok(zx, zy))
    298  1.1       cgd 						break;
    299  1.4  christos 					room = &levl[zx][zy];
    300  1.4  christos 					Tmp_at(zx, zy);
    301  1.4  christos 					if (!xdnstair) {
    302  1.4  christos 						if (zx < 3 || zx > COLNO - 3 ||
    303  1.4  christos 						    zy < 3 || zy > ROWNO - 3)
    304  1.4  christos 							break;
    305  1.4  christos 						if (room->typ == HWALL ||
    306  1.4  christos 						    room->typ == VWALL) {
    307  1.4  christos 							room->typ = ROOM;
    308  1.4  christos 							break;
    309  1.4  christos 						}
    310  1.4  christos 					} else if (room->typ == HWALL || room->typ == VWALL ||
    311  1.4  christos 						   room->typ == SDOOR || room->typ == LDOOR) {
    312  1.4  christos 						room->typ = DOOR;
    313  1.4  christos 						digdepth -= 2;
    314  1.4  christos 					} else if (room->typ == SCORR || !room->typ) {
    315  1.4  christos 						room->typ = CORR;
    316  1.4  christos 						digdepth--;
    317  1.1       cgd 					}
    318  1.4  christos 					mnewsym(zx, zy);
    319  1.4  christos 					zx += u.dx;
    320  1.4  christos 					zy += u.dy;
    321  1.1       cgd 				}
    322  1.4  christos 				mnewsym(zx, zy);	/* not always necessary */
    323  1.4  christos 				Tmp_at(-1, -1);	/* closing call */
    324  1.4  christos 				break;
    325  1.1       cgd 			}
    326  1.1       cgd 		default:
    327  1.1       cgd 			buzz((int) obj->otyp - WAN_MAGIC_MISSILE,
    328  1.4  christos 			     u.ux, u.uy, u.dx, u.dy);
    329  1.1       cgd 			break;
    330  1.1       cgd 		}
    331  1.4  christos 		if (!objects[obj->otyp].oc_name_known) {
    332  1.1       cgd 			objects[obj->otyp].oc_name_known = 1;
    333  1.4  christos 			more_experienced(0, 10);
    334  1.1       cgd 		}
    335  1.1       cgd 	}
    336  1.4  christos 	return (1);
    337  1.1       cgd }
    338  1.1       cgd 
    339  1.5       jsm const char           *
    340  1.8  dholland exclam(int force)
    341  1.1       cgd {
    342  1.1       cgd 	/* force == 0 occurs e.g. with sleep ray */
    343  1.4  christos 	/*
    344  1.4  christos 	 * note that large force is usual with wands so that !! would require
    345  1.4  christos 	 * information about hand/weapon/wand
    346  1.4  christos 	 */
    347  1.4  christos 	return ((force < 0) ? "?" : (force <= 4) ? "." : "!");
    348  1.1       cgd }
    349  1.1       cgd 
    350  1.4  christos void
    351  1.8  dholland hit(const char *str, struct monst *mtmp, const char *force)
    352  1.1       cgd {
    353  1.8  dholland 	/* force is usually either "." or "!" */
    354  1.8  dholland 
    355  1.4  christos 	if (!cansee(mtmp->mx, mtmp->my))
    356  1.4  christos 		pline("The %s hits it.", str);
    357  1.4  christos 	else
    358  1.4  christos 		pline("The %s hits %s%s", str, monnam(mtmp), force);
    359  1.1       cgd }
    360  1.1       cgd 
    361  1.4  christos void
    362  1.8  dholland miss(const char *str, struct monst *mtmp)
    363  1.1       cgd {
    364  1.4  christos 	if (!cansee(mtmp->mx, mtmp->my))
    365  1.4  christos 		pline("The %s misses it.", str);
    366  1.4  christos 	else
    367  1.4  christos 		pline("The %s misses %s.", str, monnam(mtmp));
    368  1.1       cgd }
    369  1.1       cgd 
    370  1.4  christos /*
    371  1.4  christos  * bhit: called when a weapon is thrown (sym = obj->olet) or when an
    372  1.4  christos  * IMMEDIATE wand is zapped (sym = 0); the weapon falls down at end of range
    373  1.4  christos  * or when a monster is hit; the monster is returned, and bhitpos is set to
    374  1.4  christos  * the final position of the weapon thrown; the ray of a wand may affect
    375  1.4  christos  * several objects and monsters on its path - for each of these an argument
    376  1.4  christos  * function is called.
    377  1.4  christos  */
    378  1.1       cgd /* check !u.uswallow before calling bhit() */
    379  1.1       cgd 
    380  1.4  christos struct monst   *
    381  1.8  dholland bhit(int ddx, int ddy, int range,	/* direction and range */
    382  1.8  dholland      int sym,				/* symbol displayed on path */
    383  1.8  dholland      					/* fns called when mon/obj hit */
    384  1.8  dholland      void (*fhitm)(struct monst *, struct obj *),
    385  1.8  dholland      int (*fhito)(struct obj *, struct obj *),
    386  1.8  dholland      struct obj *obj)			/* 2nd arg to fhitm/fhito */
    387  1.4  christos {
    388  1.4  christos 	struct monst   *mtmp;
    389  1.4  christos 	struct obj     *otmp;
    390  1.4  christos 	int             typ;
    391  1.1       cgd 
    392  1.1       cgd 	bhitpos.x = u.ux;
    393  1.1       cgd 	bhitpos.y = u.uy;
    394  1.1       cgd 
    395  1.4  christos 	if (sym)
    396  1.4  christos 		tmp_at(-1, sym);/* open call */
    397  1.4  christos 	while (range-- > 0) {
    398  1.1       cgd 		bhitpos.x += ddx;
    399  1.1       cgd 		bhitpos.y += ddy;
    400  1.1       cgd 		typ = levl[bhitpos.x][bhitpos.y].typ;
    401  1.4  christos 		if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != NULL) {
    402  1.4  christos 			if (sym) {
    403  1.1       cgd 				tmp_at(-1, -1);	/* close call */
    404  1.4  christos 				return (mtmp);
    405  1.1       cgd 			}
    406  1.4  christos 			(*fhitm) (mtmp, obj);
    407  1.1       cgd 			range -= 3;
    408  1.1       cgd 		}
    409  1.4  christos 		if (fhito && (otmp = o_at(bhitpos.x, bhitpos.y))) {
    410  1.4  christos 			if ((*fhito) (otmp, obj))
    411  1.1       cgd 				range--;
    412  1.1       cgd 		}
    413  1.4  christos 		if (!ZAP_POS(typ)) {
    414  1.1       cgd 			bhitpos.x -= ddx;
    415  1.1       cgd 			bhitpos.y -= ddy;
    416  1.1       cgd 			break;
    417  1.1       cgd 		}
    418  1.4  christos 		if (sym)
    419  1.4  christos 			tmp_at(bhitpos.x, bhitpos.y);
    420  1.1       cgd 	}
    421  1.1       cgd 
    422  1.1       cgd 	/* leave last symbol unless in a pool */
    423  1.4  christos 	if (sym)
    424  1.4  christos 		tmp_at(-1, (levl[bhitpos.x][bhitpos.y].typ == POOL) ? -1 : 0);
    425  1.4  christos 	return (0);
    426  1.1       cgd }
    427  1.1       cgd 
    428  1.4  christos struct monst   *
    429  1.5       jsm boomhit(int dx, int dy)
    430  1.4  christos {
    431  1.4  christos 	int             i, ct;
    432  1.4  christos 	struct monst   *mtmp;
    433  1.4  christos 	char            sym = ')';
    434  1.1       cgd 
    435  1.1       cgd 	bhitpos.x = u.ux;
    436  1.1       cgd 	bhitpos.y = u.uy;
    437  1.1       cgd 
    438  1.4  christos 	for (i = 0; i < 8; i++)
    439  1.4  christos 		if (xdir[i] == dx && ydir[i] == dy)
    440  1.4  christos 			break;
    441  1.1       cgd 	tmp_at(-1, sym);	/* open call */
    442  1.4  christos 	for (ct = 0; ct < 10; ct++) {
    443  1.4  christos 		if (i == 8)
    444  1.4  christos 			i = 0;
    445  1.1       cgd 		sym = ')' + '(' - sym;
    446  1.4  christos 		tmp_at(-2, sym);/* change let call */
    447  1.1       cgd 		dx = xdir[i];
    448  1.1       cgd 		dy = ydir[i];
    449  1.1       cgd 		bhitpos.x += dx;
    450  1.1       cgd 		bhitpos.y += dy;
    451  1.4  christos 		if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != NULL) {
    452  1.4  christos 			tmp_at(-1, -1);
    453  1.4  christos 			return (mtmp);
    454  1.1       cgd 		}
    455  1.4  christos 		if (!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)) {
    456  1.1       cgd 			bhitpos.x -= dx;
    457  1.1       cgd 			bhitpos.y -= dy;
    458  1.1       cgd 			break;
    459  1.1       cgd 		}
    460  1.4  christos 		if (bhitpos.x == u.ux && bhitpos.y == u.uy) {	/* ct == 9 */
    461  1.4  christos 			if (rn2(20) >= 10 + u.ulevel) {	/* we hit ourselves */
    462  1.1       cgd 				(void) thitu(10, rnd(10), "boomerang");
    463  1.1       cgd 				break;
    464  1.4  christos 			} else {/* we catch it */
    465  1.4  christos 				tmp_at(-1, -1);
    466  1.1       cgd 				pline("Skillfully, you catch the boomerang.");
    467  1.4  christos 				return (&youmonst);
    468  1.1       cgd 			}
    469  1.1       cgd 		}
    470  1.1       cgd 		tmp_at(bhitpos.x, bhitpos.y);
    471  1.4  christos 		if (ct % 5 != 0)
    472  1.4  christos 			i++;
    473  1.1       cgd 	}
    474  1.4  christos 	tmp_at(-1, -1);		/* do not leave last symbol */
    475  1.4  christos 	return (0);
    476  1.1       cgd }
    477  1.1       cgd 
    478  1.1       cgd char
    479  1.8  dholland dirlet(int dx, int dy)
    480  1.4  christos {
    481  1.1       cgd 	return
    482  1.1       cgd 		(dx == dy) ? '\\' : (dx && dy) ? '/' : dx ? '-' : '|';
    483  1.1       cgd }
    484  1.1       cgd 
    485  1.1       cgd /* type == -1: monster spitting fire at you */
    486  1.1       cgd /* type == -1,-2,-3: bolts sent out by wizard */
    487  1.1       cgd /* called with dx = dy = 0 with vertical bolts */
    488  1.4  christos void
    489  1.8  dholland buzz(int type, xchar sx, xchar sy, int dx, int dy)
    490  1.4  christos {
    491  1.4  christos 	int             abstype = abs(type);
    492  1.5       jsm 	const char     *fltxt = (type == -1) ? "blaze of fire" : fl[abstype];
    493  1.4  christos 	struct rm      *lev;
    494  1.4  christos 	xchar           range;
    495  1.4  christos 	struct monst   *mon;
    496  1.1       cgd 
    497  1.4  christos 	if (u.uswallow) {
    498  1.4  christos 		int             tmp;
    499  1.1       cgd 
    500  1.4  christos 		if (type < 0)
    501  1.4  christos 			return;
    502  1.1       cgd 		tmp = zhit(u.ustuck, type);
    503  1.1       cgd 		pline("The %s rips into %s%s",
    504  1.4  christos 		      fltxt, monnam(u.ustuck), exclam(tmp));
    505  1.1       cgd 		return;
    506  1.1       cgd 	}
    507  1.4  christos 	if (type < 0)
    508  1.4  christos 		pru();
    509  1.4  christos 	range = rn1(7, 7);
    510  1.4  christos 	Tmp_at(-1, dirlet(dx, dy));	/* open call */
    511  1.4  christos 	while (range-- > 0) {
    512  1.1       cgd 		sx += dx;
    513  1.1       cgd 		sy += dy;
    514  1.4  christos 		if ((lev = &levl[sx][sy])->typ)
    515  1.4  christos 			Tmp_at(sx, sy);
    516  1.1       cgd 		else {
    517  1.4  christos 			int             bounce = 0;
    518  1.4  christos 			if (cansee(sx - dx, sy - dy))
    519  1.1       cgd 				pline("The %s bounces!", fltxt);
    520  1.4  christos 			if (ZAP_POS(levl[sx][sy - dy].typ))
    521  1.1       cgd 				bounce = 1;
    522  1.4  christos 			if (ZAP_POS(levl[sx - dx][sy].typ)) {
    523  1.4  christos 				if (!bounce || rn2(2))
    524  1.4  christos 					bounce = 2;
    525  1.1       cgd 			}
    526  1.4  christos 			switch (bounce) {
    527  1.1       cgd 			case 0:
    528  1.1       cgd 				dx = -dx;
    529  1.1       cgd 				dy = -dy;
    530  1.1       cgd 				continue;
    531  1.1       cgd 			case 1:
    532  1.1       cgd 				dy = -dy;
    533  1.1       cgd 				sx -= dx;
    534  1.1       cgd 				break;
    535  1.1       cgd 			case 2:
    536  1.1       cgd 				dx = -dx;
    537  1.1       cgd 				sy -= dy;
    538  1.1       cgd 				break;
    539  1.1       cgd 			}
    540  1.4  christos 			Tmp_at(-2, dirlet(dx, dy));
    541  1.1       cgd 			continue;
    542  1.1       cgd 		}
    543  1.4  christos 		if (lev->typ == POOL && abstype == 1 /* fire */ ) {
    544  1.1       cgd 			range -= 3;
    545  1.1       cgd 			lev->typ = ROOM;
    546  1.4  christos 			if (cansee(sx, sy)) {
    547  1.4  christos 				mnewsym(sx, sy);
    548  1.1       cgd 				pline("The water evaporates.");
    549  1.1       cgd 			} else
    550  1.1       cgd 				pline("You hear a hissing sound.");
    551  1.1       cgd 		}
    552  1.4  christos 		if ((mon = m_at(sx, sy)) &&
    553  1.4  christos 		    (type != -1 || mon->data->mlet != 'D')) {
    554  1.1       cgd 			wakeup(mon);
    555  1.4  christos 			if (rnd(20) < 18 + mon->data->ac) {
    556  1.4  christos 				int             tmp = zhit(mon, abstype);
    557  1.4  christos 				if (mon->mhp < 1) {
    558  1.4  christos 					if (type < 0) {
    559  1.4  christos 						if (cansee(mon->mx, mon->my))
    560  1.4  christos 							pline("%s is killed by the %s!",
    561  1.4  christos 							Monnam(mon), fltxt);
    562  1.4  christos 						mondied(mon);
    563  1.1       cgd 					} else
    564  1.4  christos 						killed(mon);
    565  1.1       cgd 				} else
    566  1.1       cgd 					hit(fltxt, mon, exclam(tmp));
    567  1.1       cgd 				range -= 2;
    568  1.1       cgd 			} else
    569  1.4  christos 				miss(fltxt, mon);
    570  1.4  christos 		} else if (sx == u.ux && sy == u.uy) {
    571  1.1       cgd 			nomul(0);
    572  1.4  christos 			if (rnd(20) < 18 + u.uac) {
    573  1.4  christos 				int             dam = 0;
    574  1.1       cgd 				range -= 2;
    575  1.4  christos 				pline("The %s hits you!", fltxt);
    576  1.4  christos 				switch (abstype) {
    577  1.1       cgd 				case 0:
    578  1.4  christos 					dam = d(2, 6);
    579  1.1       cgd 					break;
    580  1.1       cgd 				case 1:
    581  1.4  christos 					if (Fire_resistance)
    582  1.1       cgd 						pline("You don't feel hot!");
    583  1.4  christos 					else
    584  1.4  christos 						dam = d(6, 6);
    585  1.4  christos 					if (!rn2(3))
    586  1.1       cgd 						burn_scrolls();
    587  1.1       cgd 					break;
    588  1.1       cgd 				case 2:
    589  1.4  christos 					nomul(-rnd(25));	/* sleep ray */
    590  1.1       cgd 					break;
    591  1.1       cgd 				case 3:
    592  1.4  christos 					if (Cold_resistance)
    593  1.1       cgd 						pline("You don't feel cold!");
    594  1.4  christos 					else
    595  1.4  christos 						dam = d(6, 6);
    596  1.1       cgd 					break;
    597  1.1       cgd 				case 4:
    598  1.1       cgd 					u.uhp = -1;
    599  1.1       cgd 				}
    600  1.4  christos 				losehp(dam, fltxt);
    601  1.4  christos 			} else
    602  1.4  christos 				pline("The %s whizzes by you!", fltxt);
    603  1.1       cgd 			stop_occupation();
    604  1.1       cgd 		}
    605  1.4  christos 		if (!ZAP_POS(lev->typ)) {
    606  1.4  christos 			int             bounce = 0, rmn;
    607  1.4  christos 			if (cansee(sx, sy))
    608  1.4  christos 				pline("The %s bounces!", fltxt);
    609  1.1       cgd 			range--;
    610  1.4  christos 			if (!dx || !dy || !rn2(20)) {
    611  1.1       cgd 				dx = -dx;
    612  1.1       cgd 				dy = -dy;
    613  1.1       cgd 			} else {
    614  1.4  christos 				if (ZAP_POS(rmn = levl[sx][sy - dy].typ) &&
    615  1.4  christos 				    (IS_ROOM(rmn) || ZAP_POS(levl[sx + dx][sy - dy].typ)))
    616  1.4  christos 					bounce = 1;
    617  1.4  christos 				if (ZAP_POS(rmn = levl[sx - dx][sy].typ) &&
    618  1.4  christos 				    (IS_ROOM(rmn) || ZAP_POS(levl[sx - dx][sy + dy].typ)))
    619  1.4  christos 					if (!bounce || rn2(2))
    620  1.4  christos 						bounce = 2;
    621  1.1       cgd 
    622  1.4  christos 				switch (bounce) {
    623  1.4  christos 				case 0:
    624  1.4  christos 					dy = -dy;
    625  1.4  christos 					dx = -dx;
    626  1.4  christos 					break;
    627  1.4  christos 				case 1:
    628  1.4  christos 					dy = -dy;
    629  1.4  christos 					break;
    630  1.4  christos 				case 2:
    631  1.4  christos 					dx = -dx;
    632  1.4  christos 					break;
    633  1.4  christos 				}
    634  1.4  christos 				Tmp_at(-2, dirlet(dx, dy));
    635  1.1       cgd 			}
    636  1.1       cgd 		}
    637  1.1       cgd 	}
    638  1.4  christos 	Tmp_at(-1, -1);
    639  1.1       cgd }
    640  1.1       cgd 
    641  1.4  christos int
    642  1.8  dholland zhit(struct monst *mon, int type)		/* returns damage to mon */
    643  1.1       cgd {
    644  1.4  christos 	int             tmp = 0;
    645  1.1       cgd 
    646  1.4  christos 	switch (type) {
    647  1.4  christos 	case 0:		/* magic missile */
    648  1.4  christos 		tmp = d(2, 6);
    649  1.1       cgd 		break;
    650  1.1       cgd 	case -1:		/* Dragon blazing fire */
    651  1.4  christos 	case 1:		/* fire */
    652  1.4  christos 		if (strchr("Dg", mon->data->mlet))
    653  1.4  christos 			break;
    654  1.4  christos 		tmp = d(6, 6);
    655  1.4  christos 		if (strchr("YF", mon->data->mlet))
    656  1.4  christos 			tmp += 7;
    657  1.1       cgd 		break;
    658  1.4  christos 	case 2:		/* sleep */
    659  1.1       cgd 		mon->mfroz = 1;
    660  1.1       cgd 		break;
    661  1.4  christos 	case 3:		/* cold */
    662  1.4  christos 		if (strchr("YFgf", mon->data->mlet))
    663  1.4  christos 			break;
    664  1.4  christos 		tmp = d(6, 6);
    665  1.4  christos 		if (mon->data->mlet == 'D')
    666  1.4  christos 			tmp += 7;
    667  1.4  christos 		break;
    668  1.4  christos 	case 4:		/* death */
    669  1.4  christos 		if (strchr(UNDEAD, mon->data->mlet))
    670  1.4  christos 			break;
    671  1.4  christos 		tmp = mon->mhp + 1;
    672  1.1       cgd 		break;
    673  1.1       cgd 	}
    674  1.1       cgd 	mon->mhp -= tmp;
    675  1.4  christos 	return (tmp);
    676  1.1       cgd }
    677  1.1       cgd 
    678  1.1       cgd #define	CORPSE_I_TO_C(otyp)	(char) ((otyp >= DEAD_ACID_BLOB)\
    679  1.1       cgd 		     ?  'a' + (otyp - DEAD_ACID_BLOB)\
    680  1.1       cgd 		     :	'@' + (otyp - DEAD_HUMAN))
    681  1.4  christos int
    682  1.8  dholland revive(struct obj *obj)
    683  1.1       cgd {
    684  1.4  christos 	struct monst   *mtmp = NULL;
    685  1.1       cgd 
    686  1.4  christos 	if (obj->olet == FOOD_SYM && obj->otyp > CORPSE) {
    687  1.1       cgd 		/* do not (yet) revive shopkeepers */
    688  1.4  christos 		/*
    689  1.4  christos 		 * Note: this might conceivably produce two monsters at the
    690  1.4  christos 		 * same position - strange, but harmless
    691  1.4  christos 		 */
    692  1.4  christos 		mtmp = mkmon_at(CORPSE_I_TO_C(obj->otyp), obj->ox, obj->oy);
    693  1.1       cgd 		delobj(obj);
    694  1.1       cgd 	}
    695  1.4  christos 	return (!!mtmp);	/* TRUE if some monster created */
    696  1.1       cgd }
    697  1.1       cgd 
    698  1.4  christos void
    699  1.8  dholland rloco(struct obj *obj)
    700  1.1       cgd {
    701  1.4  christos 	int tx, ty, otx, oty;
    702  1.1       cgd 
    703  1.1       cgd 	otx = obj->ox;
    704  1.1       cgd 	oty = obj->oy;
    705  1.1       cgd 	do {
    706  1.4  christos 		tx = rn1(COLNO - 3, 2);
    707  1.1       cgd 		ty = rn2(ROWNO);
    708  1.4  christos 	} while (!goodpos(tx, ty));
    709  1.1       cgd 	obj->ox = tx;
    710  1.1       cgd 	obj->oy = ty;
    711  1.4  christos 	if (cansee(otx, oty))
    712  1.4  christos 		newsym(otx, oty);
    713  1.1       cgd }
    714  1.1       cgd 
    715  1.8  dholland /* fractured by pick-axe or wand of striking */
    716  1.8  dholland /* no texts here! */
    717  1.4  christos void
    718  1.8  dholland fracture_rock(struct obj *obj)
    719  1.1       cgd {
    720  1.1       cgd 	/* unpobj(obj); */
    721  1.1       cgd 	obj->otyp = ROCK;
    722  1.1       cgd 	obj->quan = 7 + rn2(60);
    723  1.1       cgd 	obj->owt = weight(obj);
    724  1.1       cgd 	obj->olet = WEAPON_SYM;
    725  1.4  christos 	if (cansee(obj->ox, obj->oy))
    726  1.4  christos 		prl(obj->ox, obj->oy);
    727  1.1       cgd }
    728  1.1       cgd 
    729  1.4  christos void
    730  1.8  dholland burn_scrolls(void)
    731  1.1       cgd {
    732  1.4  christos 	struct obj     *obj, *obj2;
    733  1.4  christos 	int             cnt = 0;
    734  1.1       cgd 
    735  1.4  christos 	for (obj = invent; obj; obj = obj2) {
    736  1.1       cgd 		obj2 = obj->nobj;
    737  1.4  christos 		if (obj->olet == SCROLL_SYM) {
    738  1.1       cgd 			cnt++;
    739  1.1       cgd 			useup(obj);
    740  1.1       cgd 		}
    741  1.1       cgd 	}
    742  1.4  christos 	if (cnt > 1) {
    743  1.1       cgd 		pline("Your scrolls catch fire!");
    744  1.1       cgd 		losehp(cnt, "burning scrolls");
    745  1.4  christos 	} else if (cnt) {
    746  1.1       cgd 		pline("Your scroll catches fire!");
    747  1.1       cgd 		losehp(1, "burning scroll");
    748  1.1       cgd 	}
    749  1.1       cgd }
    750