Source:NetHack 3.2.0/zap.c

From NetHackWiki
Revision as of 10:04, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 3.2.0/zap.c moved to Source:NetHack 3.2.0/zap.c: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to zap.c from the source code of NetHack 3.2.0. To link to a particular line, write [[NetHack 3.2.0/zap.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1.    /*	SCCS Id: @(#)zap.c	3.2	96/03/11	*/
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include "hack.h"
6.    
7.    /* Disintegration rays have special treatment; corpses are never left.
8.     * But the routine which calculates the damage is separate from the routine
9.     * which kills the monster.  The damage routine returns this cookie to
10.    * indicate that the monster should be disintegrated.
11.    */
12.   #define MAGIC_COOKIE 1000
13.   
14.   #ifdef OVLB
15.   static NEARDATA boolean obj_zapped;
16.   static NEARDATA int poly_zapped;
17.   #endif
18.   
19.   
20.   /* kludge to use mondied instead of killed */
21.   extern boolean m_using;
22.   
23.   STATIC_DCL void FDECL(polyuse, (struct obj*, int, int));
24.   STATIC_DCL void FDECL(create_polymon, (struct obj *));
25.   STATIC_DCL void FDECL(costly_cancel, (struct obj *));
26.   STATIC_DCL int FDECL(zhit, (struct monst *,int,int));
27.   
28.   #ifdef OVLB
29.   static int FDECL(zap_hit, (int));
30.   #endif
31.   #ifdef OVL0
32.   static void FDECL(backfire, (struct obj *));
33.   #endif
34.   
35.   #define ZT_MAGIC_MISSILE	(AD_MAGM-1)
36.   #define ZT_FIRE			(AD_FIRE-1)
37.   #define ZT_COLD			(AD_COLD-1)
38.   #define ZT_SLEEP		(AD_SLEE-1)
39.   #define ZT_DEATH		(AD_DISN-1)	/* or disintegration */
40.   #define ZT_LIGHTNING		(AD_ELEC-1)
41.   #define ZT_POISON_GAS		(AD_DRST-1)
42.   #define ZT_ACID			(AD_ACID-1)
43.   /* 8 and 9 are currently unassigned */
44.   
45.   #define ZT_WAND(x)		(x)
46.   #define ZT_SPELL(x)		(10+(x))
47.   #define ZT_BREATH(x)	(20+(x))
48.   
49.   #ifndef OVLB
50.   extern const char *flash_types[];
51.   #else
52.   
53.   const char *flash_types[] = {		/* also used in buzzmu(mcastu.c) */
54.   	"magic missile",	/* Wands must be 0-9 */
55.   	"bolt of fire",
56.   	"bolt of cold",
57.   	"sleep ray",
58.   	"death ray",
59.   	"bolt of lightning",
60.   	"",
61.   	"",
62.   	"",
63.   	"",
64.   
65.   	"magic missile",	/* Spell equivalents must be 10-19 */
66.   	"fireball",
67.   	"cone of cold",
68.   	"sleep ray",
69.   	"finger of death",
70.   	"bolt of lightning",	/* There is no spell, used for retribution */
71.   	"",
72.   	"",
73.   	"",
74.   	"",
75.   
76.   	"blast of missiles",	/* Dragon breath equivalents 20-29*/
77.   	"blast of fire",
78.   	"blast of frost",
79.   	"blast of sleep gas",
80.   	"blast of disintegration",
81.   	"blast of lightning",
82.   	"blast of poison gas",
83.   	"blast of acid",
84.   	"",
85.   	""
86.   };
87.   
88.   /* Routines for IMMEDIATE wands and spells. */
89.   /* bhitm: monster mtmp was hit by the effect of wand or spell otmp */
90.   int
91.   bhitm(mtmp, otmp)
92.   register struct monst *mtmp;
93.   register struct obj *otmp;
94.   {
95.   	register boolean wake = TRUE;	/* Most 'zaps' should wake monster */
96.   	register int otyp = otmp->otyp;
97.   	boolean dbldam = Role_is('K') && u.uhave.questart;
98.   	register int dmg;
99.   
100.  	switch(otyp) {
101.  	case WAN_STRIKING:
102.  	case SPE_FORCE_BOLT:
103.  		if (resists_magm(mtmp)) {	/* match effect on player */
104.  			shieldeff(mtmp->mx, mtmp->my);
105.  			break;	/* skip makeknown */
106.  		} else if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) {
107.  			dmg = d(2,12);
108.  			if(dbldam) dmg *= 2;
109.  			hit((otyp == WAN_STRIKING) ? "wand" : "spell",
110.  			    mtmp, exclam(dmg));
111.  			(void) resist(mtmp, otmp->oclass, dmg, TELL);
112.  		} else miss((otyp == WAN_STRIKING) ? "wand" : "spell", mtmp);
113.  		makeknown(otyp);
114.  		break;
115.  	case WAN_SLOW_MONSTER:
116.  	case SPE_SLOW_MONSTER:
117.  		if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
118.  			if (mtmp->mspeed == MFAST) mtmp->mspeed = 0;
119.  			else mtmp->mspeed = MSLOW;
120.  			if (u.uswallow && (mtmp == u.ustuck) &&
121.  			    is_whirly(mtmp->data)) {
122.  				You("disrupt %s!", mon_nam(mtmp));
123.  				pline("A huge hole opens up...");
124.  				expels(mtmp, mtmp->data, TRUE);
125.  			}
126.  		}
127.  		break;
128.  	case WAN_SPEED_MONSTER:
129.  		if (!resist(mtmp, otmp->oclass, 0, NOTELL))
130.  			if (mtmp->mspeed == MSLOW) mtmp->mspeed = 0;
131.  			else mtmp->mspeed = MFAST;
132.  		break;
133.  	case WAN_UNDEAD_TURNING:
134.  	case SPE_TURN_UNDEAD:
135.  		wake = FALSE;
136.  		if (unturn_dead(mtmp)) wake = TRUE;
137.  		if (is_undead(mtmp->data)) {
138.  			wake = TRUE;
139.  			dmg = rnd(8);
140.  			if(dbldam) dmg *= 2;
141.  			if(!resist(mtmp, otmp->oclass, dmg, NOTELL))
142.  				mtmp->mflee = TRUE;
143.  		}
144.  		break;
145.  	case WAN_POLYMORPH:
146.  	case SPE_POLYMORPH:
147.  		if (resists_magm(mtmp)) {
148.  		    /* magic resistance protects from polymorph traps, so make
149.  		       it guard against involuntary polymorph attacks too... */
150.  		    shieldeff(mtmp->mx, mtmp->my);
151.  		} else if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
152.  		    if (!rn2(25)) {
153.  			if (canseemon(mtmp)) {
154.  			    pline("%s shudders!", Monnam(mtmp));
155.  			    makeknown(otyp);
156.  			}
157.  			/* no corpse after system shock */
158.  			xkilled(mtmp, 3);
159.  		    }
160.  		    else if (newcham(mtmp, (struct permonst *)0) )
161.  			if (!Hallucination && canspotmon(mtmp))
162.  			    makeknown(otyp);
163.  		}
164.  		break;
165.  	case WAN_CANCELLATION:
166.  	case SPE_CANCELLATION:
167.  		cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE);
168.  		break;
169.  	case WAN_TELEPORTATION:
170.  	case SPE_TELEPORT_AWAY:
171.  		if(mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) {
172.  		    pline("%s resists your magic!", Monnam(mtmp));
173.  		    break;
174.  		}
175.  		rloc(mtmp);
176.  		break;
177.  	case WAN_MAKE_INVISIBLE:
178.  		mon_set_minvis(mtmp);
179.  		break;
180.  	case WAN_NOTHING:
181.  		wake = FALSE;
182.  		break;
183.  	case WAN_PROBING:
184.  		wake = FALSE;
185.  		probe_monster(mtmp);
186.  		makeknown(otyp);
187.  		break;
188.  	case WAN_OPENING:
189.  	case SPE_KNOCK:
190.  		wake = FALSE;	/* don't want immediate counterattack */
191.  		if(u.uswallow && mtmp == u.ustuck) {
192.  			if (is_animal(mtmp->data)) {
193.  				if (Blind) You_feel("a sudden rush of air!");
194.  				else pline("%s opens its mouth!", Monnam(mtmp));
195.  			}
196.  			expels(mtmp, mtmp->data, TRUE);
197.  		}
198.  			break;
199.  	case SPE_HEALING:
200.  	case SPE_EXTRA_HEALING:
201.  		mtmp->mhp += d(6, otyp == SPE_EXTRA_HEALING ? 8 : 4);
202.  		if (mtmp->mhp > mtmp->mhpmax)
203.  		    mtmp->mhp = mtmp->mhpmax;
204.  		if (canseemon(mtmp))
205.  		    pline("%s looks%s better.", Monnam(mtmp),
206.  			  otyp == SPE_EXTRA_HEALING ? " much" : "" );
207.  		if (mtmp->mtame || mtmp->mpeaceful) {
208.  		    adjalign(Role_is('H') ? 1 : sgn(u.ualign.type));
209.  		}
210.  		break;
211.  	case WAN_LOCKING:
212.  	case SPE_WIZARD_LOCK:
213.  		wake = FALSE;
214.  		break;
215.  	case WAN_LIGHT:	/* (broken wand) */
216.  		if (flash_hits_mon(mtmp, otmp))
217.  		    makeknown(WAN_LIGHT);
218.  		break;
219.  	case WAN_SLEEP:	/* (broken wand) */
220.  		if (sleep_monst(mtmp, d(1 + otmp->spe, 12), WAND_CLASS))
221.  		    slept_monst(mtmp);
222.  		if (!Blind) makeknown(WAN_SLEEP);
223.  		break;
224.  	default:
225.  		impossible("What an interesting effect (%d)", otyp);
226.  		break;
227.  	}
228.  	if(wake) {
229.  	    if(mtmp->mhp > 0) {
230.  		wakeup(mtmp);
231.  		m_respond(mtmp);
232.  		if(mtmp->isshk && !*u.ushops) hot_pursuit(mtmp);
233.  	    } else if(mtmp->m_ap_type)
234.  		seemimic(mtmp); /* might unblock if mimicing a boulder/door */
235.  	}
236.  	return 0;
237.  }
238.  
239.  void
240.  probe_monster(mtmp)
241.  struct monst *mtmp;
242.  {
243.  	struct obj *otmp;
244.  
245.  	mstatusline(mtmp);
246.  	if (mtmp->minvent || mtmp->mgold) {
247.  	    for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
248.  		otmp->dknown = 1;	/* treat as "seen" */
249.  	    (void) display_minventory(mtmp, MINV_ALL);
250.  	} else {
251.  	    pline("%s is not carrying anything.", Monnam(mtmp));
252.  	}
253.  }
254.  
255.  #endif /*OVLB*/
256.  #ifdef OVL1
257.  
258.  /*
259.   * Return the object's physical location.  This only makes sense for
260.   * objects that are currently on the level (i.e. migrating objects
261.   * are nowhere).  By default, only things that can be seen (in hero's
262.   * inventory, monster's inventory, or on the ground) are reported.
263.   * By adding BURIED_TOO and/or CONTAINED_TOO flags, you can also get
264.   * the location of buried and contained objects.  Note that if an
265.   * object is carried by a monster, its reported position may change
266.   * from turn to turn.  This function returns FALSE if the position
267.   * is not available or subject to the constraints above.
268.   */
269.  boolean
270.  get_obj_location(obj, xp, yp, locflags)
271.  struct obj *obj;
272.  xchar *xp, *yp;
273.  int locflags;
274.  {
275.  	switch (obj->where) {
276.  	    case OBJ_INVENT:
277.  		*xp = u.ux;
278.  		*yp = u.uy;
279.  		return TRUE;
280.  	    case OBJ_FLOOR:
281.  		*xp = obj->ox;
282.  		*yp = obj->oy;
283.  		return TRUE;
284.  	    case OBJ_MINVENT:
285.  		*xp = obj->ocarry->mx;
286.  		*yp = obj->ocarry->my;
287.  		return TRUE;
288.  	    case OBJ_BURIED:
289.  		if (locflags & BURIED_TOO) {
290.  		    *xp = obj->ox;
291.  		    *yp = obj->oy;
292.  		    return TRUE;
293.  		}
294.  		break;
295.  	    case OBJ_CONTAINED:
296.  		if (locflags & CONTAINED_TOO)
297.  		    return get_obj_location(obj->ocontainer, xp, yp, locflags);
298.  		break;
299.  	}
300.  	*xp = *yp = 0;
301.  	return FALSE;
302.  }
303.  
304.  boolean
305.  get_mon_location(mon, xp, yp, locflags)
306.  struct monst *mon;
307.  xchar *xp, *yp;
308.  int locflags;	/* non-zero means get location even if monster is buried */
309.  {
310.  	if (mon == &youmonst) {
311.  	    *xp = u.ux;
312.  	    *yp = u.uy;
313.  	    return TRUE;
314.  	} else if (mon->mx > 0 && (!mon->mburied || locflags)) {
315.  	    *xp = mon->mx;
316.  	    *yp = mon->my;
317.  	    return TRUE;
318.  	} else {	/* migrating or buried */
319.  	    *xp = *yp = 0;
320.  	    return FALSE;
321.  	}
322.  }
323.  
324.  /*
325.   * Attempt to revive the given corpse, return the revived monster if
326.   * successful.  Note: this does NOT use up the corpse if it fails.
327.   */
328.  struct monst *
329.  revive(obj)
330.  register struct obj *obj;
331.  {
332.  	register struct monst *mtmp = (struct monst *)0;
333.  
334.  	if(obj->otyp == CORPSE) {
335.  		int montype = obj->corpsenm;
336.  		xchar x, y;
337.  
338.  		/* only for invent, minvent, or floor */
339.  		if (!get_obj_location(obj, &x, &y, 0))
340.  		    return (struct monst *) 0;
341.  
342.  		if (MON_AT(x,y)) {
343.  		    coord new_xy;
344.  
345.  		    if (enexto(&new_xy, x, y, &mons[montype]))
346.  			x = new_xy.x,  y = new_xy.y;
347.  		}
348.  
349.  		if(cant_create(&montype)) {
350.  			/* make a zombie or worm instead */
351.  			mtmp = makemon(&mons[montype], x, y);
352.  			if (mtmp) {
353.  				mtmp->mhp = mtmp->mhpmax = 100;
354.  				mtmp->mspeed = MFAST;
355.  			}
356.  		} else {
357.  			mtmp = makemon(&mons[montype], x, y);
358.  			if (mtmp) {
359.  				/* Monster retains its name */
360.  				if (obj->onamelth)
361.  					mtmp = christen_monst(mtmp, ONAME(obj));
362.  				/* No inventory for newly revived monsters */
363.  				discard_minvent(mtmp);
364.  			}
365.  		}
366.  		if (mtmp) {
367.  			if (obj->oeaten)
368.  				mtmp->mhp = eaten_stat(mtmp->mhp, obj);
369.  
370.  			switch (obj->where) {
371.  			    case OBJ_INVENT:
372.  				useup(obj);
373.  				break;
374.  			    case OBJ_FLOOR:
375.  				/* in case MON_AT+enexto for invisible mon */
376.  				x = obj->ox,  y = obj->oy;
377.  				/* not useupf(), which charges */
378.  				if (obj->quan > 1L)
379.  				    (void) splitobj(obj, 1L);
380.  				delobj(obj);
381.  				newsym(x, y);
382.  				break;
383.  			    case OBJ_MINVENT:
384.  				m_useup(obj->ocarry, obj);
385.  				break;
386.  			    default:
387.  				panic("revive");
388.  			}
389.  		}
390.  	}
391.  	return mtmp;
392.  }
393.  
394.  /* try to revive all corpses carried by `mon' */
395.  int
396.  unturn_dead(mon)
397.  struct monst *mon;
398.  {
399.  	struct obj *otmp, *otmp2;
400.  	struct monst *mtmp2;
401.  	char owner[BUFSIZ], corpse[BUFSIZ];
402.  	boolean youseeit;
403.  	int once = 0, res = 0;
404.  
405.  	youseeit = (mon == &youmonst) ? TRUE : canseemon(mon);
406.  	otmp2 = (mon == &youmonst) ? invent : mon->minvent;
407.  
408.  	while ((otmp = otmp2) != 0) {
409.  	    otmp2 = otmp->nobj;
410.  	    if (otmp->otyp != CORPSE) continue;
411.  	    /* save the name; the object is liable to go away */
412.  	    if (youseeit) Strcpy(corpse, corpse_xname(otmp, TRUE));
413.  
414.  	    /* for a merged group, only one is revived; should this be fixed? */
415.  	    if ((mtmp2 = revive(otmp)) != 0) {
416.  		++res;
417.  		if (youseeit) {
418.  		    if (!once++) Strcpy(owner,
419.  					(mon == &youmonst) ? "Your" :
420.  					s_suffix(Monnam(mon)));
421.  		    pline("%s %s suddenly comes alive!", owner, corpse);
422.  		} else if (canseemon(mtmp2))
423.  		    pline("%s suddenly appears!", Amonnam(mtmp2));
424.  	    }
425.  	}
426.  	return res;
427.  }
428.  #endif /*OVL1*/
429.  
430.  #ifdef OVLB
431.  static const char charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS, 0 };
432.  
433.  STATIC_OVL void
434.  costly_cancel(obj)
435.  register struct obj *obj;
436.  {
437.  	char objroom;
438.  	struct monst *shkp = (struct monst *)0;
439.  
440.  	if (obj->no_charge) return;
441.  
442.  	switch (obj->where) {
443.  	case OBJ_INVENT:
444.  		if (obj->unpaid) {
445.  		    shkp = shop_keeper(*u.ushops);
446.  		    if (!shkp) return;
447.  		    Norep("You cancel an unpaid object, you pay for it!");
448.  		    bill_dummy_object(obj);
449.  		}
450.  		break;
451.  	case OBJ_FLOOR:
452.  		objroom = *in_rooms(obj->ox, obj->oy, SHOPBASE);
453.  		shkp = shop_keeper(objroom);
454.  		if (!shkp || !inhishop(shkp)) return;
455.  		if (costly_spot(u.ux, u.uy) && objroom == *u.ushops) {
456.  		    Norep("You cancel it, you pay for it!");
457.  		    bill_dummy_object(obj);
458.  		} else
459.  		    (void) stolen_value(obj, obj->ox, obj->oy, FALSE, FALSE);
460.  		break;
461.  	}
462.  }
463.  
464.  /* cancel obj, possibly carried by you or a monster */
465.  void
466.  cancel_item(obj)
467.  register struct obj *obj;
468.  {
469.  	boolean	u_ring = (obj == uleft) || (obj == uright);
470.  	register boolean unpaid = (carried(obj) && obj->unpaid);
471.  	register boolean holy = (obj->otyp == POT_WATER && obj->blessed);
472.  
473.  	switch(obj->otyp) {
474.  		case RIN_GAIN_STRENGTH:
475.  			if ((obj->owornmask & W_RING) && u_ring) {
476.  				ABON(A_STR) -= obj->spe;
477.  				flags.botl = 1;
478.  			}
479.  			break;
480.  		case RIN_ADORNMENT:
481.  			if ((obj->owornmask & W_RING) && u_ring) {
482.  				ABON(A_CHA) -= obj->spe;
483.  				flags.botl = 1;
484.  			}
485.  			break;
486.  		case RIN_INCREASE_DAMAGE:
487.  			if ((obj->owornmask & W_RING) && u_ring)
488.  				u.udaminc -= obj->spe;
489.  			break;
490.  		case GAUNTLETS_OF_DEXTERITY:
491.  			if ((obj->owornmask & W_ARMG) && (obj == uarmg)) {
492.  				ABON(A_DEX) -= obj->spe;
493.  				flags.botl = 1;
494.  			}
495.  			break;
496.  		case HELM_OF_BRILLIANCE:
497.  			if ((obj->owornmask & W_ARMH) && (obj == uarmh)) {
498.  				ABON(A_INT) -= obj->spe;
499.  				ABON(A_WIS) -= obj->spe;
500.  				flags.botl = 1;
501.  			}
502.  			break;
503.  		/* case RIN_PROTECTION: /* not needed */
504.  	}
505.  	if (objects[obj->otyp].oc_magic
506.  	    || (obj->spe && (obj->oclass == ARMOR_CLASS ||
507.  			     obj->oclass == WEAPON_CLASS || is_weptool(obj)))
508.  	    || obj->otyp == POT_SICKNESS) {
509.  	    if (obj->spe != ((obj->oclass == WAND_CLASS) ? -1 : 0) &&
510.  	       obj->otyp != WAN_CANCELLATION &&
511.  		 /* can't cancel cancellation */
512.  		 obj->otyp != MAGIC_LAMP &&
513.  		 obj->otyp != CANDELABRUM_OF_INVOCATION) {
514.  		costly_cancel(obj);
515.  		obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0;
516.  		if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
517.  	    }
518.  	    switch (obj->oclass) {
519.  	      case SCROLL_CLASS:
520.  		costly_cancel(obj);
521.  		obj->otyp = SCR_BLANK_PAPER;
522.  		obj->spe = 0;
523.  		if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
524.  		break;
525.  	      case SPBOOK_CLASS:
526.  		if (obj->otyp != SPE_CANCELLATION &&
527.  			obj->otyp != SPE_BOOK_OF_THE_DEAD) {
528.  		    costly_cancel(obj);
529.  		    obj->otyp = SPE_BLANK_PAPER;
530.  		    if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
531.  		}
532.  		break;
533.  	      case POTION_CLASS:
534.  		costly_cancel(obj);
535.  		if (obj->otyp == POT_SICKNESS ||
536.  		    obj->otyp == POT_SEE_INVISIBLE) {
537.  	    /* sickness is "biologically contaminated" fruit juice; cancel it
538.  	     * and it just becomes fruit juice... whereas see invisible
539.  	     * tastes like "enchanted" fruit juice, it similarly cancels.
540.  	     */
541.  		    obj->otyp = POT_FRUIT_JUICE;
542.  		} else {
543.  	            obj->otyp = POT_WATER;
544.  		    obj->odiluted = 0; /* same as any other water */
545.  		}
546.  		if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
547.  		break;
548.  	    }
549.  	}
550.  	if (holy) costly_cancel(obj);
551.  	unbless(obj);
552.  	if (unpaid && holy) addtobill(obj, TRUE, FALSE, TRUE);
553.  	uncurse(obj);
554.  }
555.  #endif /*OVLB*/
556.  #ifdef OVL0
557.  
558.  boolean
559.  obj_resists(obj, ochance, achance)
560.  struct obj *obj;
561.  int ochance, achance;	/* percent chance for ordinary objects, artifacts */
562.  {
563.  	if (obj->otyp == AMULET_OF_YENDOR ||
564.  	    obj->otyp == SPE_BOOK_OF_THE_DEAD ||
565.  	    obj->otyp == CANDELABRUM_OF_INVOCATION ||
566.  	    obj->otyp == BELL_OF_OPENING ||
567.  	    (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) {
568.  		return TRUE;
569.  	} else {
570.  		int chance = rn2(100);
571.  
572.  		return((boolean)(chance < (obj->oartifact ? achance : ochance)));
573.  	}
574.  }
575.  
576.  boolean
577.  obj_shudders(obj)
578.  struct obj *obj;
579.  {
580.  	int	zap_odds;
581.  
582.  	if (obj->oclass == WAND_CLASS)
583.  		zap_odds = 3;	/* half-life = 2 zaps */
584.  	else if (obj->cursed)
585.  		zap_odds = 3;	/* half-life = 2 zaps */
586.  	else if (obj->blessed)
587.  		zap_odds = 12;	/* half-life = 8 zaps */
588.  	else
589.  		zap_odds = 8;	/* half-life = 6 zaps */
590.  
591.  	/* adjust for "large" quantities of identical things */
592.  	if(obj->quan > 4L) zap_odds /= 2;
593.  
594.  	return((boolean)(! rn2(zap_odds)));
595.  }
596.  #endif /*OVL0*/
597.  #ifdef OVLB
598.  
599.  /* Use up at least minwt number of things made of material mat.
600.   * There's also a chance that other stuff will be used up.  Finally,
601.   * there's a random factor here to keep from always using the stuff
602.   * at the top of the pile.
603.   */
604.  STATIC_OVL void
605.  polyuse(objhdr, mat, minwt)
606.      struct obj *objhdr;
607.      int mat, minwt;
608.  {
609.      register struct obj *otmp, *otmp2;
610.  
611.      for(otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) {
612.  	otmp2 = otmp->nexthere;
613.  	if((objects[otmp->otyp].oc_material == mat) == (rn2(minwt+1) != 0)) {
614.  	    /* appropriately add damage to bill */
615.  	    if (costly_spot(otmp->ox, otmp->oy))
616.  		if (*u.ushops)
617.  			addtobill(otmp, FALSE, FALSE, FALSE);
618.  		else
619.  			(void)stolen_value(otmp,
620.  					   otmp->ox, otmp->oy, FALSE, FALSE);
621.  	    minwt -= (int)otmp->quan;
622.  	    delobj(otmp);
623.  	}
624.      }
625.  }
626.  
627.  /*
628.   * Polymorph some of the stuff in this pile into a monster, preferably
629.   * a golem of some sort.
630.   */
631.  STATIC_OVL void
632.  create_polymon(obj)
633.      struct obj *obj;
634.  {
635.  	struct permonst *mdat = (struct permonst *)0;
636.  	struct monst *mtmp;
637.  	const char *material;
638.  	int pm_index;
639.  
640.  	/* no golems if you zap only one object -- not enough stuff */
641.  	if(!obj || (!obj->nexthere && obj->quan == 1L)) return;
642.  
643.  	/* some of these choices are arbitrary */
644.  	switch(poly_zapped) {
645.  	case IRON:
646.  	case METAL:
647.  	case MITHRIL:
648.  	    pm_index = PM_IRON_GOLEM;
649.  	    material = "metal ";
650.  	    break;
651.  	case COPPER:
652.  	case SILVER:
653.  	case GOLD:
654.  	case PLATINUM:
655.  	case GEMSTONE:
656.  	case GLASS:
657.  	case MINERAL:
658.  	    pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM;
659.  	    material = "lithic ";
660.  	    break;
661.  	case 0:
662.  	    /* there is no flesh type, but all food is type 0, so we use it */
663.  	    pm_index = PM_FLESH_GOLEM;
664.  	    material = "organic ";
665.  	    break;
666.  	case WOOD:
667.  	    pm_index = PM_WOOD_GOLEM;
668.  	    material = "wood ";
669.  	    break;
670.  	case LEATHER:
671.  	    pm_index = PM_LEATHER_GOLEM;
672.  	    material = "leather ";
673.  	    break;
674.  	case CLOTH:
675.  	    pm_index = PM_ROPE_GOLEM;
676.  	    material = "cloth ";
677.  	    break;
678.  	default:
679.  	    /* if all else fails... */
680.  	    pm_index = PM_STRAW_GOLEM;
681.  	    material = "";
682.  	    break;
683.  	}
684.  
685.  	if (!(mvitals[pm_index].mvflags & G_GENOD))
686.  		mdat = &mons[pm_index];
687.  
688.  	mtmp = makemon(mdat, obj->ox, obj->oy);
689.  	polyuse(obj, poly_zapped, (int)mons[pm_index].cwt);
690.  
691.  	if(!Blind && mtmp) {
692.  	    pline("Some %sobjects meld, and %s arises from the pile!",
693.  		  material, a_monnam(mtmp));
694.  	}
695.  }
696.  
697.  /* Assumes obj is on the floor. */
698.  void
699.  do_osshock(obj)
700.  struct obj *obj;
701.  {
702.  	long i;
703.  	obj_zapped = TRUE;
704.  
705.  	if(poly_zapped < 0) {
706.  	    /* some may metamorphosize */
707.  	    for(i=obj->quan; i; i--)
708.  		if (! rn2(Luck + 45)) {
709.  		    poly_zapped = objects[obj->otyp].oc_material;
710.  		    break;
711.  		}
712.  	}
713.  
714.  	/* if quan > 1 then some will survive intact */
715.  	if (obj->quan > 1L)
716.  		(void) splitobj(obj, (long)rnd((int)obj->quan - 1));
717.  
718.  	/* appropriately add damage to bill */
719.  	if (costly_spot(obj->ox, obj->oy))
720.  		if (*u.ushops)
721.  			addtobill(obj, FALSE, FALSE, FALSE);
722.  		else
723.  			(void)stolen_value(obj,
724.  					   obj->ox, obj->oy, FALSE, FALSE);
725.  
726.  	/* zap the object */
727.  	delobj(obj);
728.  }
729.  
730.  void
731.  poly_obj(obj)
732.  	register struct obj *obj;
733.  {
734.  	register struct obj *otmp;
735.  
736.  	/* preserve symbol and quantity */
737.  	otmp = mkobj_at(obj->oclass, obj->ox, obj->oy, FALSE);
738.  	otmp->quan = obj->quan;
739.  	/* preserve the shopkeepers (lack of) interest */
740.  	otmp->no_charge = obj->no_charge;
741.  #ifdef MAIL
742.  	/* You can't send yourself 100 mail messages and then
743.  	 * polymorph them into useful scrolls
744.  	 */
745.  	if (obj->otyp == SCR_MAIL) {
746.  		otmp->otyp = SCR_MAIL;
747.  		otmp->spe = 1;
748.  	}
749.  #endif
750.  
751.  	/* avoid abusing eggs laid by you */
752.  	if (obj->otyp == EGG && obj->spe) {
753.  		int mnum, tryct = 100;
754.  
755.  		/* first, turn into a generic egg */
756.  		if (otmp->otyp == EGG)
757.  		    kill_egg(otmp);
758.  		else {
759.  		    otmp->otyp = EGG;
760.  		    otmp->owt = weight(otmp);
761.  		}
762.  		otmp->corpsenm = NON_PM;
763.  		otmp->spe = 0;
764.  
765.  		/* now change it into something layed by the hero */
766.  		while (tryct--) {
767.  		    mnum = can_be_hatched(random_monster());
768.  		    if (mnum != NON_PM && !dead_species(mnum, TRUE)) {
769.  			otmp->spe = 1;	/* layed by hero */
770.  			otmp->corpsenm = mnum;
771.  			attach_egg_hatch_timeout(otmp);
772.  			break;
773.  		    }
774.  		}
775.  	}
776.  
777.  	/* keep special fields (including charges on wands) */
778.  	if (index(charged_objs, otmp->oclass)) otmp->spe = obj->spe;
779.  
780.  	otmp->cursed = obj->cursed;
781.  	otmp->blessed = obj->blessed;
782.  	otmp->oeroded = obj->oeroded;
783.  	otmp->oerodeproof = obj->oerodeproof;
784.  
785.  	/* reduce spellbook abuse */
786.  	if (obj->oclass == SPBOOK_CLASS)
787.  	    otmp->spestudied = obj->spestudied + 1;
788.  
789.  	/* Keep chest/box traps and poisoned ammo if we may */
790.  	if (obj->otrapped && Is_box(otmp)) otmp->otrapped = TRUE;
791.  
792.  	if (obj->opoisoned &&
793.  	    (otmp->oclass == WEAPON_CLASS && otmp->otyp <= SHURIKEN))
794.  		otmp->opoisoned = TRUE;
795.  
796.  	if (obj->otyp == CORPSE) {
797.  	/* turn crocodile corpses into shoes */
798.  	    if (obj->corpsenm == PM_CROCODILE) {
799.  		otmp->otyp = LOW_BOOTS;
800.  		otmp->oclass = ARMOR_CLASS;
801.  		otmp->spe = 0;
802.  		otmp->oeroded = 0;
803.  		otmp->oerodeproof = TRUE;
804.  		otmp->quan = 1L;
805.  		otmp->cursed = FALSE;
806.  	    }
807.  	}
808.  
809.  	/* no box contents --KAA */
810.  	if (Has_contents(otmp)) delete_contents(otmp);
811.  
812.  	/* 'n' merged objects may be fused into 1 object */
813.  	if (otmp->quan > 1L && (!objects[otmp->otyp].oc_merge ||
814.  				otmp->quan > (long)rn2(1000)))
815.  		otmp->quan = 1L;
816.  
817.  	if(otmp->otyp == MAGIC_LAMP) {
818.  		otmp->otyp = OIL_LAMP;
819.  		otmp->age = (long) rn1(500,1000);
820.  	}
821.  
822.  	while(otmp->otyp == WAN_WISHING || otmp->otyp == WAN_POLYMORPH)
823.  		otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING);
824.  
825.  	if (otmp->oclass == GEM_CLASS) {
826.  	    if (otmp->quan > (long) rnd(4) &&
827.  		    objects[obj->otyp].oc_material == MINERAL &&
828.  		    objects[otmp->otyp].oc_material != MINERAL) {
829.  		otmp->otyp = ROCK;	/* transmutation backfired */
830.  		otmp->quan /= 2L;	/* some material has been lost */
831.  	    }
832.  	}
833.  
834.  	/* update the weight */
835.  	otmp->owt = weight(otmp);
836.  
837.  	if(costly_spot(obj->ox, obj->oy)) {
838.  	    register struct monst *shkp =
839.  		  shop_keeper(*in_rooms(obj->ox, obj->oy, SHOPBASE));
840.  
841.  	    if ((!obj->no_charge ||
842.  		 (Has_contents(obj) &&
843.  		    (contained_cost(obj, shkp, 0L, FALSE) != 0L)))
844.  	       && inhishop(shkp)) {
845.  		if(shkp->mpeaceful) {
846.  		    if(*u.ushops && *in_rooms(u.ux, u.uy, 0) ==
847.  			    *in_rooms(shkp->mx, shkp->my, 0) &&
848.  			    !costly_spot(u.ux, u.uy))
849.  			make_angry_shk(shkp, obj->ox, obj->oy);
850.  		    else {
851.  			pline("%s gets angry!", Monnam(shkp));
852.  			hot_pursuit(shkp);
853.  		    }
854.  		} else Norep("%s is furious!", Monnam(shkp));
855.  	    }
856.  	}
857.  	delobj(obj);
858.  	return;
859.  }
860.  
861.  int
862.  bhito(obj, otmp)	/* object obj was hit by the effect of wand otmp */
863.  register struct obj *obj, *otmp;	/* returns TRUE if sth was done */
864.  {
865.  	register int res = 1;
866.  
867.  	/* bhito expects obj->{ox,oy} to be valid */
868.  	if (obj->where != OBJ_FLOOR)
869.  	    impossible("bhito: obj is at %d, not floor", obj->where);
870.  
871.  	if (obj == uball) {
872.  		res = 0;
873.  	} else if (obj == uchain) {
874.  		if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) {
875.  		    unpunish();
876.  		    res = 1;
877.  		    makeknown(otmp->otyp);
878.  		} else
879.  		    res = 0;
880.  	} else
881.  	switch(otmp->otyp) {
882.  	case WAN_POLYMORPH:
883.  	case SPE_POLYMORPH:
884.  		if (obj_resists(obj, 5, 95)) {
885.  		    res = 0;
886.  		    break;
887.  		}
888.  		/* any saved lock context will be dangerously obsolete */
889.  		if (Is_box(obj)) (void) boxlock(obj, otmp);
890.  
891.  		if (obj_shudders(obj)) {
892.  		    if (cansee(obj->ox, obj->oy))
893.  			makeknown(otmp->otyp);
894.  		    do_osshock(obj);
895.  		    break;
896.  		}
897.  		poly_obj(obj);
898.  		break;
899.  	case WAN_PROBING:
900.  		res = !obj->dknown;
901.  		/* target object has now been "seen (up close)" */
902.  		obj->dknown = 1;
903.  		/* petrified monster's inventory */
904.  		if (obj->otyp == STATUE) {
905.  		    if (!obj->cobj) {
906.  			struct trap *t = t_at(obj->ox, obj->oy);
907.  			/*
908.  			 * This is a work-around for statue traps.
909.  			 * Inventories of statue traps are always empty, but
910.  			 * often the monsters that result have items in their
911.  			 * inventory.  This might be perceived as a bug.
912.  			 * Ideally, the contents of a living statue, should
913.  			 * already be there, and the monster should inherit
914.  			 * its inventory from that.
915.  			 *
916.  			 * But until then, this makes the message about
917.  			 * the living statue being empty, much less definite.
918.  			 */
919.  			pline("%s %s empty.", The(xname(obj)),
920.  			      (t && t->ttyp == STATUE_TRAP) ? "seems" : "is");
921.  		    } else {
922.  			struct obj *o;
923.  			/* view contents (not recursively) */
924.  			for (o = obj->cobj; o; o = o->nobj)
925.  			    o->dknown = 1;	/* "seen", even if blind */
926.  			(void) display_cinventory(obj);
927.  		    }
928.  		    res = 1;
929.  		}
930.  		if (res) makeknown(WAN_PROBING);
931.  		break;
932.  	case WAN_STRIKING:
933.  	case SPE_FORCE_BOLT:
934.  		if (obj->otyp == BOULDER)
935.  			fracture_rock(obj);
936.  		else if (obj->otyp == STATUE)
937.  			(void) break_statue(obj);
938.  		else {
939.  			(void)breaks(obj, obj->ox, obj->oy, FALSE);
940.  			res = 0;
941.  		}
942.  		makeknown(otmp->otyp);
943.  		break;
944.  	case WAN_DIGGING:
945.  	case SPE_DIG:
946.  		/* vaporize boulders */
947.  		if (obj->otyp == BOULDER) {
948.  			delobj(obj);
949.  			res = 0;
950.  		}
951.  		break;
952.  	case WAN_CANCELLATION:
953.  	case SPE_CANCELLATION:
954.  		cancel_item(obj);
955.  #ifdef TEXTCOLOR
956.  		newsym(obj->ox,obj->oy);	/* might change color */
957.  #endif
958.  		break;
959.  	case WAN_TELEPORTATION:
960.  	case SPE_TELEPORT_AWAY:
961.  		rloco(obj);
962.  		break;
963.  	case WAN_MAKE_INVISIBLE:
964.  		obj->oinvis = TRUE;
965.  		newsym(obj->ox,obj->oy);	/* make object disappear */
966.  		break;
967.  	case WAN_UNDEAD_TURNING:
968.  	case SPE_TURN_UNDEAD:
969.  		res = !!revive(obj);
970.  		break;
971.  	case WAN_OPENING:
972.  	case SPE_KNOCK:
973.  	case WAN_LOCKING:
974.  	case SPE_WIZARD_LOCK:
975.  		if(Is_box(obj))
976.  			res = boxlock(obj, otmp);
977.  		else
978.  			res = 0;
979.  		if (res /* && otmp->oclass == WAND_CLASS */)
980.  			makeknown(otmp->otyp);
981.  		break;
982.  	case WAN_SLOW_MONSTER:		/* no effect on objects */
983.  	case SPE_SLOW_MONSTER:
984.  	case WAN_SPEED_MONSTER:
985.  	case WAN_NOTHING:
986.  	case SPE_HEALING:
987.  	case SPE_EXTRA_HEALING:
988.  		res = 0;
989.  		break;
990.  	default:
991.  		impossible("What an interesting effect (%d)", otmp->otyp);
992.  		break;
993.  	}
994.  	return(res);
995.  }
996.  
997.  /* returns nonzero if something was hit */
998.  int
999.  bhitpile(obj,fhito,tx,ty)
1000.     struct obj *obj;
1001.     int FDECL((*fhito), (OBJ_P,OBJ_P));
1002.     int tx, ty;
1003. {
1004.     int hitanything = 0;
1005.     register struct obj *otmp, *next_obj = (struct obj *)0;
1006. 
1007.     /* modified by GAN to hit all objects */
1008.     /* pre-reverse the polymorph pile,  -dave- 3/90 */
1009.     poly_zapped = -1;
1010.     if(obj->otyp == SPE_POLYMORPH || obj->otyp == WAN_POLYMORPH) {
1011. 	otmp = level.objects[tx][ty];
1012. 	level.objects[tx][ty] = next_obj;
1013. 	while(otmp) {
1014. 	    next_obj = otmp->nexthere;
1015. 	    otmp->nexthere = level.objects[tx][ty];
1016. 	    level.objects[tx][ty] = otmp;
1017. 	    otmp = next_obj;
1018. 	}
1019.     }
1020.     for(otmp = level.objects[tx][ty]; otmp; otmp = next_obj) {
1021. 	/* Fix for polymorph bug, Tim Wright */
1022. 	next_obj = otmp->nexthere;
1023. 	hitanything += (*fhito)(otmp, obj);
1024.     }
1025.     if(poly_zapped >= 0)
1026. 	create_polymon(level.objects[tx][ty]);
1027. 
1028.     return hitanything;
1029. }
1030. #endif /*OVLB*/
1031. #ifdef OVL1
1032. 
1033. /*
1034.  * zappable - returns 1 if zap is available, 0 otherwise.
1035.  *	      it removes a charge from the wand if zappable.
1036.  * added by GAN 11/03/86
1037.  */
1038. int
1039. zappable(wand)
1040. register struct obj *wand;
1041. {
1042. 	if(wand->spe < 0 || (wand->spe == 0 && rn2(121)))
1043. 		return 0;
1044. 	if(wand->spe == 0)
1045. 		You("wrest one last charge from the worn-out wand.");
1046. 	wand->spe--;
1047. 	return 1;
1048. }
1049. 
1050. /*
1051.  * zapnodir - zaps a NODIR wand/spell.
1052.  * added by GAN 11/03/86
1053.  */
1054. void
1055. zapnodir(obj)
1056. register struct obj *obj;
1057. {
1058. 	boolean known = FALSE;
1059. 
1060. 	switch(obj->otyp) {
1061. 		case WAN_LIGHT:
1062. 		case SPE_LIGHT:
1063. 			litroom(TRUE,obj);
1064. 			if (!Blind) known = TRUE;
1065. 			break;
1066. 		case WAN_SECRET_DOOR_DETECTION:
1067. 		case SPE_DETECT_UNSEEN:
1068. 			if(!findit()) return;
1069. 			if (!Blind) known = TRUE;
1070. 			break;
1071. 		case WAN_CREATE_MONSTER:
1072. 			known = create_critters(rn2(23) ? 1 : rn1(7,2),
1073. 					(struct permonst *)0);
1074. 			break;
1075. 		case WAN_WISHING:
1076. 			known = TRUE;
1077. 			if(Luck + rn2(5) < 0) {
1078. 				pline("Unfortunately, nothing happens.");
1079. 				break;
1080. 			}
1081. 			makewish();
1082. 			break;
1083. 	}
1084. 	if (known && !objects[obj->otyp].oc_name_known) {
1085. 		makeknown(obj->otyp);
1086. 		more_experienced(0,10);
1087. 	}
1088. }
1089. #endif /*OVL1*/
1090. #ifdef OVL0
1091. 
1092. static void
1093. backfire(otmp)
1094. 
1095. 	register struct obj * otmp;
1096. {
1097. 	pline("%s suddenly explodes!", The(xname(otmp)));
1098. 	losehp(d(otmp->spe+2,6), "exploding wand", KILLED_BY_AN);
1099. 	useup(otmp);
1100. }
1101. 
1102. static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 };
1103. 
1104. int
1105. dozap()
1106. {
1107. 	register struct obj *obj;
1108. 	int	damage;
1109. 
1110. 	if(check_capacity((char *)0)) return(0);
1111. 	obj = getobj(zap_syms, "zap");
1112. 	if(!obj) return(0);
1113. 
1114. 	check_unpaid(obj);
1115. 
1116. 	/* zappable addition done by GAN 11/03/86 */
1117. 	if(!zappable(obj)) pline(nothing_happens);
1118. 	else if(obj->cursed && !rn2(100)) {
1119. 		backfire(obj);	/* the wand blows up in your face! */
1120. 		exercise(A_STR, FALSE);
1121. 		return(1);
1122. 	} else if(!(objects[obj->otyp].oc_dir == NODIR) && !getdir((char *)0)) {
1123. 		if (!Blind)
1124. 		    pline("%s glows and fades.", The(xname(obj)));
1125. 		/* make him pay for knowing !NODIR */
1126. 	} else if(!u.dx && !u.dy && !u.dz && !(objects[obj->otyp].oc_dir == NODIR)) {
1127. 	    if ((damage = zapyourself(obj, TRUE)) != 0)
1128. 		losehp(damage, self_pronoun("zapped %sself with a wand", "him"),
1129. 			NO_KILLER_PREFIX);
1130. 	} else {
1131. 
1132. 		/*	Are we having fun yet?
1133. 		 * weffects -> buzz(obj->otyp) -> zhit (temple priest) ->
1134. 		 * attack -> hitum -> known_hitum -> ghod_hitsu ->
1135. 		 * buzz(AD_ELEC) -> destroy_item(WAND_CLASS) ->
1136. 		 * useup -> obfree -> dealloc_obj -> free(obj)
1137. 		 */
1138. 		current_wand = obj;
1139. 		weffects(obj);
1140. 		obj = current_wand;
1141. 		current_wand = 0;
1142. 	}
1143. 	if (obj && obj->spe < 0) {
1144. 	    pline("%s turns to dust.", The(xname(obj)));
1145. 	    useup(obj);
1146. 	}
1147. 	update_inventory();	/* maybe used a charge */
1148. 	return(1);
1149. }
1150. 
1151. int
1152. zapyourself(obj, ordinary)
1153. struct obj *obj;
1154. boolean ordinary;
1155. {
1156. 	int	damage = 0;
1157. 
1158. 	switch(obj->otyp) {
1159. 		case WAN_STRIKING:
1160. 		    makeknown(WAN_STRIKING);
1161. 		case SPE_FORCE_BOLT:
1162. 		    if(Antimagic) {
1163. 			shieldeff(u.ux, u.uy);
1164. 			pline("Boing!");
1165. 		    } else {
1166. 			if (ordinary) {
1167. 			    You("bash yourself!");
1168. 			    damage = d(2,12);
1169. 			} else
1170. 			    damage = d(1 + obj->spe,6);
1171. 			exercise(A_STR, FALSE);
1172. 		    }
1173. 		    break;
1174. 		case WAN_LIGHTNING:
1175. 		    makeknown(WAN_LIGHTNING);
1176. 		    if (!Shock_resistance) {
1177. 			You("shock yourself!");
1178. 			damage = d(12,6);
1179. 			exercise(A_CON, FALSE);
1180. 		    } else {
1181. 			shieldeff(u.ux, u.uy);
1182. 			You("zap yourself, but seem unharmed.");
1183. 			ugolemeffects(AD_ELEC, d(12,6));
1184. 		    }
1185. 		    destroy_item(WAND_CLASS, AD_ELEC);
1186. 		    destroy_item(RING_CLASS, AD_ELEC);
1187. 		    if(!Blind) {
1188. 			    You("are blinded by the flash!");
1189. 			    make_blinded((long)rnd(100),FALSE);
1190. 		    }
1191. 		    break;
1192. 		case SPE_FIREBALL:
1193. 		    You("explode a fireball on top of yourself!");
1194. 		    explode(u.ux, u.uy, 11, d(6,6), WAND_CLASS);
1195. 		    break;
1196. 		case WAN_FIRE:
1197. 		    makeknown(WAN_FIRE);
1198. 		case FIRE_HORN:
1199. 		    if (Fire_resistance) {
1200. 			shieldeff(u.ux, u.uy);
1201. 			You_feel("rather warm.");
1202. 			ugolemeffects(AD_FIRE, d(12,6));
1203. 		    } else {
1204. 			pline("You've set yourself afire!");
1205. 			damage = d(12,6);
1206. 		    }
1207. 		    (void) burnarmor();
1208. 		    destroy_item(SCROLL_CLASS, AD_FIRE);
1209. 		    destroy_item(POTION_CLASS, AD_FIRE);
1210. 		    destroy_item(SPBOOK_CLASS, AD_FIRE);
1211. 		    break;
1212. 		case WAN_COLD:
1213. 		    makeknown(WAN_COLD);
1214. 		case SPE_CONE_OF_COLD:
1215. 		case FROST_HORN:
1216. 		    if (Cold_resistance) {
1217. 			shieldeff(u.ux, u.uy);
1218. 			You_feel("a little chill.");
1219. 			ugolemeffects(AD_COLD, d(12,6));
1220. 		    } else {
1221. 			You("imitate a popsicle!");
1222. 			damage = d(12,6);
1223. 		    }
1224. 		    destroy_item(POTION_CLASS, AD_COLD);
1225. 		    break;
1226. 		case WAN_MAGIC_MISSILE:
1227. 		    makeknown(WAN_MAGIC_MISSILE);
1228. 		case SPE_MAGIC_MISSILE:
1229. 		    if(Antimagic) {
1230. 			shieldeff(u.ux, u.uy);
1231. 			pline_The("missiles bounce!");
1232. 		    } else {
1233. 			damage = d(4,6);
1234. 			pline("Idiot!  You've shot yourself!");
1235. 		    }
1236. 		    break;
1237. 		case WAN_POLYMORPH:
1238. 		    makeknown(WAN_POLYMORPH);
1239. 		case SPE_POLYMORPH:
1240. 		    polyself();
1241. 		    break;
1242. 		case WAN_CANCELLATION:
1243. 		case SPE_CANCELLATION:
1244. 		    cancel_monst(&youmonst, obj, TRUE, FALSE, TRUE);
1245. 		    break;
1246. 		case WAN_MAKE_INVISIBLE: {
1247. 		    /* have to test before changing HInvis but must change
1248. 		     * HInvis before doing newsym().
1249. 		     */
1250. 		    int msg = (!Invis && !See_invisible);
1251. 
1252. 		    if (ordinary || !rn2(10)) {	/* permanent */
1253. 			HInvis |= FROMOUTSIDE;
1254. 		    } else {			/* temporary */
1255. 			long amt = d(obj->spe, 250) + (HInvis & TIMEOUT);
1256. 
1257. 			HInvis &= ~TIMEOUT;
1258. 			HInvis |= min(amt, TIMEOUT);
1259. 		    }
1260. 		    if (msg && (Blind || !Invis)) {
1261. 			You_feel("rather airy.");
1262. 		    } else if (msg) {
1263. 			makeknown(WAN_MAKE_INVISIBLE);
1264. 			newsym(u.ux, u.uy);
1265. 			pline(Hallucination ?
1266. 			 "Far out, man!  You can see right through yourself!" :
1267. 			 "Gee!  All of a sudden, you can't see yourself.");
1268. 		    }
1269. 		    break;
1270. 		}
1271. 		case WAN_SPEED_MONSTER:
1272. 		    if (!(Fast & INTRINSIC)) {
1273. 			if (!Fast)
1274. 			    You("speed up.");
1275. 			else
1276. 			    Your("quickness feels more natural.");
1277. 			makeknown(WAN_SPEED_MONSTER);
1278. 			exercise(A_DEX, TRUE);
1279. 		    }
1280. 		    Fast |= FROMOUTSIDE;
1281. 		    break;
1282. 		case WAN_SLEEP:
1283. 		    makeknown(WAN_SLEEP);
1284. 		case SPE_SLEEP:
1285. 		    if(Sleep_resistance) {
1286. 			shieldeff(u.ux, u.uy);
1287. 			You("don't feel sleepy!");
1288. 		    } else {
1289. 			pline_The("sleep ray hits you!");
1290. 			fall_asleep(-rnd(50), TRUE);
1291. 		    }
1292. 		    break;
1293. 		case WAN_SLOW_MONSTER:
1294. 		case SPE_SLOW_MONSTER:
1295. 		    if(Fast & (TIMEOUT | INTRINSIC)) {
1296. 			u_slow_down();
1297. 			makeknown(obj->otyp);
1298. 		    }
1299. 		    break;
1300. 		case WAN_TELEPORTATION:
1301. 		case SPE_TELEPORT_AWAY:
1302. 		    tele();
1303. 		    break;
1304. 		case WAN_DEATH:
1305. 		case SPE_FINGER_OF_DEATH:
1306. 		    if (nonliving(uasmon) || is_demon(uasmon)) {
1307. 			pline((obj->otyp == WAN_DEATH) ?
1308. 			  "The wand shoots an apparently harmless beam at you."
1309. 			  : "You seem no deader than before.");
1310. 			break;
1311. 		    }
1312. 		    killer_format = NO_KILLER_PREFIX;
1313. 		    killer = self_pronoun("shot %sself with a death ray","him");
1314. 		    You("irradiate yourself with pure energy!");
1315. 		    You("die.");
1316. 		    makeknown(obj->otyp);
1317. 			/* They might survive with an amulet of life saving */
1318. 		    done(DIED);
1319. 		    break;
1320. 		case WAN_UNDEAD_TURNING:
1321. 		    makeknown(WAN_UNDEAD_TURNING);
1322. 		case SPE_TURN_UNDEAD:
1323. 		    (void) unturn_dead(&youmonst);
1324. 		    if (is_undead(uasmon)) {
1325. 			You_feel("frightened and %sstunned.",
1326. 			     Stunned ? "even more " : "");
1327. 			make_stunned(HStun + rnd(30), FALSE);
1328. 		    } else
1329. 			You("shudder in dread.");
1330. 		    break;
1331. 		case SPE_HEALING:
1332. 		case SPE_EXTRA_HEALING:
1333. 		    healup(d(6, obj->otyp == SPE_EXTRA_HEALING ? 8 : 4),
1334. 			   0, FALSE, (obj->otyp == SPE_EXTRA_HEALING));
1335. 		    You("feel%s better.",
1336. 			obj->otyp == SPE_EXTRA_HEALING ? " much" : "");
1337. 		    break;
1338. 		case WAN_LIGHT:	/* (broken wand) */
1339. 		 /* assert( !ordinary ); */
1340. 		    damage = d(obj->spe, 25);
1341. #ifdef TOURIST
1342. 		case EXPENSIVE_CAMERA:
1343. #endif
1344. 		    damage += rnd(25);
1345. 		    if (!Blind) {
1346. 			You("are blinded by the flash!");
1347. 			make_blinded((long)damage, FALSE);
1348. 			makeknown(obj->otyp);
1349. 		    }
1350. 		    damage = 0;	/* reset */
1351. 		    break;
1352. 		case WAN_OPENING:
1353. 		    if (Punished) makeknown(WAN_OPENING);
1354. 		case SPE_KNOCK:
1355. 		    if (Punished) Your("chain quivers for a moment.");
1356. 		    break;
1357. 		case WAN_DIGGING:
1358. 		case SPE_DIG:
1359. 		case SPE_DETECT_UNSEEN:
1360. 		case WAN_NOTHING:
1361. 		case WAN_LOCKING:
1362. 		case SPE_WIZARD_LOCK:
1363. 		    break;
1364. 		case WAN_PROBING:
1365. 		    for (obj = invent; obj; obj = obj->nobj)
1366. 			obj->dknown = 1;
1367. 		    /* note: `obj' reused; doesn't point at wand anymore */
1368. 		    makeknown(WAN_PROBING);
1369. 		    ustatusline();
1370. 		    break;
1371. 		default: impossible("object %d used?",obj->otyp);
1372. 		    break;
1373. 	}
1374. 	return(damage);
1375. }
1376. 
1377. #endif /*OVL0*/
1378. #ifdef OVL3
1379. 
1380. /*
1381.  * cancel a monster (possibly the hero).  inventory is cancelled only
1382.  * if the monster is zapping itself directly, since otherwise the
1383.  * effect is too strong.  currently non-hero monsters do not zap
1384.  * themselves with cancellation.
1385.  */
1386. void
1387. cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel)
1388. register struct monst	*mdef;
1389. register struct obj	*obj;
1390. boolean			youattack, allow_cancel_kill, self_cancel;
1391. {
1392. 	boolean	youdefend = (mdef == &youmonst);
1393. 	static const char writing_vanishes[] =
1394. 				"Some writing vanishes from %s head!";
1395. 	static const char your[] = "your";	/* should be extern */
1396. 
1397. 	if (youdefend ? (!youattack && Antimagic)
1398. 		      : resist(mdef, obj->oclass, 0, NOTELL))
1399. 		return;		/* resisted cancellation */
1400. 
1401. 	if (self_cancel) {	/* 1st cancel inventory */
1402. 	    struct obj *otmp;
1403. 
1404. 	    for (otmp = (youdefend ? invent : mdef->minvent);
1405. 			    otmp; otmp = otmp->nobj)
1406. 		cancel_item(otmp);
1407. 	    if (youdefend) {
1408. 		flags.botl = 1;	/* potential AC change */
1409. 		find_ac();
1410. 	    }
1411. 	}
1412. 
1413. 	/* now handle special cases */
1414. 	if (youdefend) {
1415. 	    if (u.mtimedone) {
1416. 		if ((u.umonnum == PM_CLAY_GOLEM) && !Blind)
1417. 		    pline(writing_vanishes, your);
1418. 		rehumanize();
1419. 	    }
1420. 	} else {
1421. 	    mdef->mcan = TRUE;
1422. 
1423. 	    if (is_were(mdef->data) && mdef->data->mlet != S_HUMAN)
1424. 		were_change(mdef);
1425. 
1426. 	    if (mdef->data == &mons[PM_CLAY_GOLEM]) {
1427. 		if (canseemon(mdef))
1428. 		    pline(writing_vanishes, s_suffix(mon_nam(mdef)));
1429. 
1430. 		if (allow_cancel_kill) {
1431. 		    if (youattack)
1432. 			killed(mdef);
1433. 		    else
1434. 			monkilled(mdef, "", AD_SPEL);
1435. 		}
1436. 	    }
1437. 	}
1438. }
1439. #endif /*OVL3*/
1440. 
1441. #ifdef OVLB
1442. /* called for various wand and spell effects - M. Stephenson */
1443. void
1444. weffects(obj)
1445. register struct	obj	*obj;
1446. {
1447. 	int ptmp, otyp = obj->otyp;
1448. 	boolean disclose = FALSE, was_unkn = !objects[otyp].oc_name_known;
1449. 
1450. 	exercise(A_WIS, TRUE);
1451. 	if (objects[otyp].oc_dir == IMMEDIATE) {
1452. 	    obj_zapped = FALSE;
1453. 	    if (u.uswallow) {
1454. 		(void) bhitm(u.ustuck, obj);
1455. 	    } else if (u.dz) {
1456. 		int x = u.ux, y = u.uy;
1457. 
1458. 		if (otyp == WAN_PROBING) {
1459. 		    if (u.dz < 0) {
1460. 			You("probe towards the %s.", ceiling(x,y));
1461. 			ptmp = 0;
1462. 		    } else {
1463. 			You("probe beneath the %s.", surface(x,y));
1464. 			ptmp = display_binventory(x, y, TRUE);
1465. 			ptmp += bhitpile(obj, bhito, x, y);
1466. 		    }
1467. 		    if (!ptmp) Your("probe reveals nothing.");
1468. 		    disclose = TRUE;
1469. 		} else if ((otyp == WAN_OPENING || otyp == SPE_KNOCK) &&
1470. 			/* up/down at closed portcullis only */
1471. 			is_db_wall(x,y) && find_drawbridge(&x, &y)) {
1472. 		    open_drawbridge(x, y);
1473. 		    disclose = TRUE;
1474. 		} else if ((otyp == WAN_LOCKING || otyp == SPE_WIZARD_LOCK) &&
1475. 			/* down at open bridge or up/down at open portcullis */
1476. 			((levl[x][y].typ == DRAWBRIDGE_DOWN) ? u.dz > 0 :
1477. 			    (is_drawbridge_wall(x,y) && !is_db_wall(x,y))) &&
1478. 			find_drawbridge(&x, &y)) {
1479. 		    close_drawbridge(x, y);
1480. 		    disclose = TRUE;
1481. 		} else if (u.dz > 0) {
1482. 		    /* zapping downward */
1483. 		    (void) bhitpile(obj, bhito, x, y);
1484. 		}
1485. 	    } else {
1486. 		(void) bhit(u.dx,u.dy, rn1(8,6),ZAPPED_WAND, bhitm,bhito, obj);
1487. 	    }
1488. 	    /* give a clue if obj_zapped */
1489. 	    if (obj_zapped)
1490. 		You_feel("shuddering vibrations.");
1491. 
1492. 	} else if (objects[otyp].oc_dir == NODIR) {
1493. 	    zapnodir(obj);
1494. 
1495. 	} else {
1496. 	    /* neither immediate nor directionless */
1497. 
1498. 	    if (otyp == WAN_DIGGING || otyp == SPE_DIG)
1499. 		zap_dig();
1500. 	    else if (otyp >= SPE_MAGIC_MISSILE && otyp <= SPE_FINGER_OF_DEATH)
1501. 		buzz(otyp - SPE_MAGIC_MISSILE + 10,
1502. 		     u.ulevel / 2 + 1,
1503. 		     u.ux, u.uy, u.dx, u.dy);
1504. 	    else if (otyp >= WAN_MAGIC_MISSILE && otyp <= WAN_LIGHTNING)
1505. 		buzz(otyp - WAN_MAGIC_MISSILE,
1506. 		     (otyp == WAN_MAGIC_MISSILE) ? 2 : 6,
1507. 		     u.ux, u.uy, u.dx, u.dy);
1508. 	    else
1509. 		impossible("weffects: unexpected spell or wand");
1510. 	    disclose = TRUE;
1511. 	}
1512. 
1513. 	if (disclose && was_unkn) {
1514. 	    makeknown(otyp);
1515. 	    more_experienced(0,10);
1516. 	}
1517. 	return;
1518. }
1519. #endif /*OVLB*/
1520. #ifdef OVL0
1521. 
1522. const char *
1523. exclam(force)
1524. register int force;
1525. {
1526. 	/* force == 0 occurs e.g. with sleep ray */
1527. 	/* note that large force is usual with wands so that !! would
1528. 		require information about hand/weapon/wand */
1529. 	return (const char *)((force < 0) ? "?" : (force <= 4) ? "." : "!");
1530. }
1531. 
1532. void
1533. hit(str,mtmp,force)
1534. register const char *str;
1535. register struct monst *mtmp;
1536. register const char *force;		/* usually either "." or "!" */
1537. {
1538. 	if(!cansee(bhitpos.x,bhitpos.y) || !flags.verbose)
1539. 	    pline("%s hits it.", The(str));
1540. 	else pline("%s hits %s%s", The(str), mon_nam(mtmp), force);
1541. }
1542. 
1543. void
1544. miss(str,mtmp)
1545. register const char *str;
1546. register struct monst *mtmp;
1547. {
1548. 	pline("%s misses %s.", The(str),
1549. 	      (cansee(bhitpos.x,bhitpos.y) && flags.verbose) ?
1550. 	      mon_nam(mtmp) : "it");
1551. }
1552. #endif /*OVL0*/
1553. #ifdef OVL1
1554. 
1555. /*
1556.  *  Called for the following distance effects:
1557.  *	when a weapon is thrown (weapon == THROWN_WEAPON)
1558.  *	when an object is kicked (KICKED_WEAPON)
1559.  *	when an IMMEDIATE wand is zapped (ZAPPED_WAND)
1560.  *	when a light beam is flashed (FLASHED_LIGHT)
1561.  *	for some invisible effect on a monster (INVIS_BEAM)
1562.  *  A thrown/kicked object falls down at the end of its range or when a monster
1563.  *  is hit.  The variable 'bhitpos' is set to the final position of the weapon
1564.  *  thrown/zapped.  The ray of a wand may affect (by calling a provided
1565.  *  function) several objects and monsters on its path.  The return value
1566.  *  is the monster hit (weapon != ZAPPED_WAND), or a null monster pointer.
1567.  *
1568.  *  Check !u.uswallow before calling bhit().
1569.  */
1570. struct monst *
1571. bhit(ddx,ddy,range,weapon,fhitm,fhito,obj)
1572. register int ddx,ddy,range;		/* direction and range */
1573. int weapon;				/* see values in hack.h */
1574. int FDECL((*fhitm), (MONST_P, OBJ_P)),	/* fns called when mon/obj hit */
1575.     FDECL((*fhito), (OBJ_P, OBJ_P));
1576. struct obj *obj;			/* object tossed/used */
1577. {
1578. 	register struct monst *mtmp;
1579. 	register uchar typ;
1580. 	register boolean shopdoor = FALSE;
1581. 
1582. 	if (weapon == KICKED_WEAPON) {
1583. 	    /* object starts one square in front of player */
1584. 	    bhitpos.x = u.ux + ddx;
1585. 	    bhitpos.y = u.uy + ddy;
1586. 	    range--;
1587. 	} else {
1588. 	    bhitpos.x = u.ux;
1589. 	    bhitpos.y = u.uy;
1590. 	}
1591. 
1592. 	if (weapon == FLASHED_LIGHT) {
1593. 	    tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam));
1594. 	} else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM)
1595. 	    tmp_at(DISP_FLASH, obj_to_glyph(obj));
1596. 	while(range-- > 0) {
1597. 		int x,y;
1598. 
1599. 		bhitpos.x += ddx;
1600. 		bhitpos.y += ddy;
1601. 		x = bhitpos.x; y = bhitpos.y;
1602. 
1603. 		if(!isok(x, y)) {
1604. 		    bhitpos.x -= ddx;
1605. 		    bhitpos.y -= ddy;
1606. 		    break;
1607. 		}
1608. 		if(obj->otyp == PICK_AXE && inside_shop(x, y) &&
1609. 					       shkcatch(obj, x, y)) {
1610. 		    tmp_at(DISP_END, 0);
1611. 		    return(m_at(x, y));
1612. 		}
1613. 
1614. 		typ = levl[bhitpos.x][bhitpos.y].typ;
1615. 
1616. 		if (weapon == ZAPPED_WAND && find_drawbridge(&x,&y))
1617. 		    switch (obj->otyp) {
1618. 			case WAN_OPENING:
1619. 			case SPE_KNOCK:
1620. 			    if (is_db_wall(bhitpos.x, bhitpos.y)) {
1621. 				if (cansee(x,y) || cansee(bhitpos.x,bhitpos.y))
1622. 				    makeknown(obj->otyp);
1623. 				open_drawbridge(x,y);
1624. 			    }
1625. 			    break;
1626. 			case WAN_LOCKING:
1627. 			case SPE_WIZARD_LOCK:
1628. 			    if ((cansee(x,y) || cansee(bhitpos.x, bhitpos.y))
1629. 				&& levl[x][y].typ == DRAWBRIDGE_DOWN)
1630. 				makeknown(obj->otyp);
1631. 			    close_drawbridge(x,y);
1632. 			    break;
1633. 			case WAN_STRIKING:
1634. 			case SPE_FORCE_BOLT:
1635. 			    if (typ != DRAWBRIDGE_UP)
1636. 				destroy_drawbridge(x,y);
1637. 			    makeknown(obj->otyp);
1638. 			    break;
1639. 		    }
1640. 
1641. 		if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
1642. 			if(weapon != ZAPPED_WAND) {
1643. 				if(weapon != INVIS_BEAM) tmp_at(DISP_END, 0);
1644. 				return(mtmp);
1645. 			}
1646. 			(*fhitm)(mtmp, obj);
1647. 			range -= 3;
1648. 		}
1649. 		if(fhito) {
1650. 		    if(bhitpile(obj,fhito,bhitpos.x,bhitpos.y))
1651. 			range--;
1652. 		} else {
1653.     boolean costly = shop_keeper(*in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) &&
1654. 				    costly_spot(bhitpos.x, bhitpos.y);
1655. 
1656. 			if(weapon == KICKED_WEAPON &&
1657. 			      ((obj->oclass == GOLD_CLASS &&
1658. 			         OBJ_AT(bhitpos.x, bhitpos.y)) ||
1659. 			    ship_object(obj, bhitpos.x, bhitpos.y, costly))) {
1660. 				tmp_at(DISP_END, 0);
1661. 				return (struct monst *)0;
1662. 			}
1663. 		}
1664. 		if(weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) {
1665. 		    switch (obj->otyp) {
1666. 		    case WAN_OPENING:
1667. 		    case WAN_LOCKING:
1668. 		    case WAN_STRIKING:
1669. 		    case SPE_KNOCK:
1670. 		    case SPE_WIZARD_LOCK:
1671. 		    case SPE_FORCE_BOLT:
1672. 			if (doorlock(obj, bhitpos.x, bhitpos.y)) {
1673. 			    if (cansee(bhitpos.x, bhitpos.y) ||
1674. 				(obj->otyp == WAN_STRIKING))
1675. 				makeknown(obj->otyp);
1676. 			    if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
1677. 				&& *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) {
1678. 				shopdoor = TRUE;
1679. 				add_damage(bhitpos.x, bhitpos.y, 400L);
1680. 			    }
1681. 			}
1682. 			break;
1683. 		    }
1684. 		}
1685. 		if(!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) {
1686. 			bhitpos.x -= ddx;
1687. 			bhitpos.y -= ddy;
1688. 			break;
1689. 		}
1690. 		if(weapon != ZAPPED_WAND && weapon != INVIS_BEAM) {
1691. 			tmp_at(bhitpos.x, bhitpos.y);
1692. 			delay_output();
1693. 			/* kicked objects fall in pools */
1694. 			if((weapon == KICKED_WEAPON) &&
1695. 			   is_pool(bhitpos.x, bhitpos.y))
1696. 			    break;
1697. #ifdef SINKS
1698. 			if(IS_SINK(typ) && weapon != FLASHED_LIGHT)
1699. 			    break;	/* physical objects fall onto sink */
1700. #endif
1701. 		}
1702. 	}
1703. 
1704. 	if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) tmp_at(DISP_END, 0);
1705. 
1706. 	if(shopdoor)
1707. 	    pay_for_damage("destroy");
1708. 
1709. 	return (struct monst *)0;
1710. }
1711. 
1712. struct monst *
1713. boomhit(dx, dy)
1714. int dx, dy;
1715. {
1716. 	register int i, ct;
1717. 	int boom = S_boomleft;	/* showsym[] index  */
1718. 	struct monst *mtmp;
1719. 
1720. 	bhitpos.x = u.ux;
1721. 	bhitpos.y = u.uy;
1722. 
1723. 	for(i=0; i<8; i++) if(xdir[i] == dx && ydir[i] == dy) break;
1724. 	tmp_at(DISP_FLASH, cmap_to_glyph(boom));
1725. 	for(ct=0; ct<10; ct++) {
1726. 		if(i == 8) i = 0;
1727. 		boom = (boom == S_boomleft) ? S_boomright : S_boomleft;
1728. 		tmp_at(DISP_CHANGE, cmap_to_glyph(boom));/* change glyph */
1729. 		dx = xdir[i];
1730. 		dy = ydir[i];
1731. 		bhitpos.x += dx;
1732. 		bhitpos.y += dy;
1733. 		if(MON_AT(bhitpos.x, bhitpos.y)) {
1734. 			mtmp = m_at(bhitpos.x,bhitpos.y);
1735. 			m_respond(mtmp);
1736. 			tmp_at(DISP_END, 0);
1737. 			return(mtmp);
1738. 		}
1739. 		if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ) ||
1740. 		   closed_door(bhitpos.x, bhitpos.y)) {
1741. 			bhitpos.x -= dx;
1742. 			bhitpos.y -= dy;
1743. 			break;
1744. 		}
1745. 		if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
1746. 			if(Fumbling || rn2(20) >= ACURR(A_DEX)) {
1747. 				/* we hit ourselves */
1748. 				(void) thitu(10, rnd(10), (struct obj *)0,
1749. 					"boomerang");
1750. 				break;
1751. 			} else {	/* we catch it */
1752. 				tmp_at(DISP_END, 0);
1753. 				You("skillfully catch the boomerang.");
1754. 				return(&youmonst);
1755. 			}
1756. 		}
1757. 		tmp_at(bhitpos.x, bhitpos.y);
1758. 		delay_output();
1759. 		if(ct % 5 != 0) i++;
1760. #ifdef SINKS
1761. 		if(IS_SINK(levl[bhitpos.x][bhitpos.y].typ))
1762. 			break;	/* boomerang falls on sink */
1763. #endif
1764. 	}
1765. 	tmp_at(DISP_END, 0);	/* do not leave last symbol */
1766. 	return (struct monst *)0;
1767. }
1768. 
1769. STATIC_OVL int
1770. zhit(mon, type, nd)			/* returns damage to mon */
1771. register struct monst *mon;
1772. register int type, nd;
1773. {
1774. 	register int tmp = 0;
1775. 	register int abstype = abs(type) % 10;
1776. 	boolean sho_shieldeff = FALSE;
1777. 
1778. 	switch(abstype) {
1779. 	case ZT_MAGIC_MISSILE:
1780. 		if (resists_magm(mon)) {
1781. 		    sho_shieldeff = TRUE;
1782. 		    break;
1783. 		}
1784. 		tmp = d(nd,6);
1785. 		break;
1786. 	case ZT_FIRE:
1787. 		if (resists_fire(mon)) {
1788. 		    sho_shieldeff = TRUE;
1789. 		    break;
1790. 		}
1791. 		tmp = d(nd,6);
1792. 		if (resists_cold(mon)) tmp += 7;
1793. 		break;
1794. 	case ZT_COLD:
1795. 		if (resists_cold(mon)) {
1796. 		    sho_shieldeff = TRUE;
1797. 		    break;
1798. 		}
1799. 		tmp = d(nd,6);
1800. 		if (resists_fire(mon)) tmp += d(nd, 3);
1801. 		break;
1802. 	case ZT_SLEEP:
1803. 		tmp = 0;
1804. 		(void)sleep_monst(mon, d(nd, 25),
1805. 				type == ZT_WAND(ZT_SLEEP) ? WAND_CLASS : '\0');
1806. 		break;
1807. 	case ZT_DEATH:		/* death/disintegration */
1808. 		if(abs(type) != ZT_BREATH(ZT_DEATH)) {	/* death */
1809. 		    if(mon->data == &mons[PM_DEATH]) {
1810. 			mon->mhpmax += mon->mhpmax/2;
1811. 			mon->mhp = mon->mhpmax;
1812. 			tmp = 0;
1813. 			break;
1814. 		    }
1815. 		    if (nonliving(mon->data) || is_demon(mon->data) ||
1816. 			    resists_magm(mon)) {	/* similar to player */
1817. 			sho_shieldeff = TRUE;
1818. 			break;
1819. 		    }
1820. 		    type = -1; /* so they don't get saving throws */
1821. 		} else {
1822. 		    if (resists_disint(mon)) {
1823. 			sho_shieldeff = TRUE;
1824. 			break;
1825. 		    } else {
1826. 			tmp = MAGIC_COOKIE;
1827. 			break;
1828. 		    }
1829. 		}
1830. 		tmp = mon->mhp+1;
1831. 		break;
1832. 	case ZT_LIGHTNING:
1833. 		if (resists_elec(mon)) {
1834. 		    sho_shieldeff = TRUE;
1835. 		    tmp = 0;
1836. 		    /* can still blind the monster */
1837. 		} else
1838. 		    tmp = d(nd,6);
1839. 		if (haseyes(mon->data) &&
1840. 				!(type > 0 && u.uswallow && mon == u.ustuck)) {
1841. 			register unsigned rnd_tmp = rnd(50);
1842. 			mon->mcansee = 0;
1843. 			if((mon->mblinded + rnd_tmp) > 127)
1844. 				mon->mblinded = 127;
1845. 			else mon->mblinded += rnd_tmp;
1846. 		}
1847. 		break;
1848. 	case ZT_POISON_GAS:
1849. 		if (resists_poison(mon)) {
1850. 		    sho_shieldeff = TRUE;
1851. 		    break;
1852. 		}
1853. 		tmp = d(nd,6);
1854. 		break;
1855. 	case ZT_ACID:
1856. 		if (resists_acid(mon)) {
1857. 		    sho_shieldeff = TRUE;
1858. 		    break;
1859. 		}
1860. 		tmp = d(nd,6);
1861. 		break;
1862. 	}
1863. 	if (sho_shieldeff) shieldeff(mon->mx, mon->my);
1864. 	if ((type >= 10 && type <= 19) && (Role_is('K') && u.uhave.questart))
1865. 	    tmp *= 2;
1866. 	if (type >= 0)
1867. 	    if (resist(mon, (type < ZT_SPELL(0)) ? WAND_CLASS : '\0',
1868. 		       0, NOTELL)) tmp /= 2;
1869. 	mon->mhp -= tmp;
1870. 	return(tmp);
1871. }
1872. #endif /*OVL1*/
1873. #ifdef OVLB
1874. 
1875. /*
1876.  * burn scrolls and spell books on floor at position x,y
1877.  * return the number of scrolls and spell books burned
1878.  */
1879. int
1880. burn_floor_paper(x, y, give_feedback)
1881. int x, y;
1882. boolean give_feedback;	/* caller needs to decide about visibility checks */
1883. {
1884. 	struct obj *obj, *obj2;
1885. 	long i, scrquan, delquan;
1886. 	const char *what;
1887. 	int cnt = 0;
1888. 
1889. 	for (obj = level.objects[x][y]; obj; obj = obj2) {
1890. 	    obj2 = obj->nexthere;
1891. 	    if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) {
1892. 		if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL ||
1893. 			obj_resists(obj, 2, 100))
1894. 		    continue;
1895. 		scrquan = obj->quan;	/* number present */
1896. 		delquan = 0;		/* number to destroy */
1897. 		for (i = scrquan; i > 0; i--)
1898. 		    if (!rn2(3)) delquan++;
1899. 		if (delquan) {
1900. 		    /* save name before potential delobj() */
1901. 		    what = !give_feedback ? 0 : (x == u.ux && y == u.uy) ?
1902. 				xname(obj) : distant_name(obj, xname);
1903. 		    /* not useupf(), which charges */
1904. 		    if (delquan < scrquan) obj->quan -= delquan;
1905. 		    else delobj(obj);
1906. 		    cnt += delquan;
1907. 		    if (give_feedback) {
1908. 			if (delquan > 1)
1909. 			    pline("%ld %s burn.", delquan, what);
1910. 			else
1911. 			    pline("%s burns.", An(what));
1912. 		    }
1913. 		}
1914. 	    }
1915. 	}
1916. 	return cnt;
1917. }
1918. 
1919. /* will zap/spell/breath attack score a hit against armor class `ac'? */
1920. static int
1921. zap_hit(ac)
1922. int ac;
1923. {
1924.     int chance = rn2(20);
1925. 
1926.     /* small chance for naked target to avoid being hit */
1927.     if (!chance) return rnd(10) < ac;
1928. 
1929.     /* very high armor protection does not achieve invulnerability */
1930.     ac = AC_VALUE(ac);
1931. 
1932.     return (3 - chance) < ac;
1933. }
1934. 
1935. /* type ==   0 to   9 : you shooting a wand */
1936. /* type ==  10 to  19 : you casting a spell */
1937. /* type ==  20 to  29 : you breathing as a monster */
1938. /* type == -10 to -19 : monster casting spell */
1939. /* type == -20 to -29 : monster breathing at you */
1940. /* type == -30 to -39 : monster shooting a wand */
1941. /* called with dx = dy = 0 with vertical bolts */
1942. void
1943. buzz(type,nd,sx,sy,dx,dy)
1944. register int type, nd;
1945. register xchar sx,sy;
1946. register int dx,dy;
1947. {
1948.     int range, abstype = abs(type) % 10;
1949.     struct rm *lev;
1950.     register xchar lsx, lsy;
1951.     struct monst *mon;
1952.     coord save_bhitpos;
1953.     boolean shopdamage = FALSE;
1954.     register const char *fltxt;
1955. 
1956.     fltxt = flash_types[(type <= -30) ? abstype : abs(type)];
1957.     if(u.uswallow) {
1958. 	register int tmp;
1959. 
1960. 	if(type < 0) return;
1961. 	tmp = zhit(u.ustuck, type, nd);
1962. 	if(!u.ustuck)	u.uswallow = 0;
1963. 	else	pline("%s rips into %s%s",
1964. 		      The(fltxt), mon_nam(u.ustuck), exclam(tmp));
1965. 	/* Using disintegration from the inside only makes a hole... */
1966. 	if (tmp == MAGIC_COOKIE)
1967. 	    u.ustuck->mhp = 0;
1968. 	if (u.ustuck->mhp < 1)
1969. 	    killed(u.ustuck);
1970. 	return;
1971.     }
1972.     if(type < 0) newsym(u.ux,u.uy);
1973.     range = rn1(7,7);
1974.     if(dx == 0 && dy == 0) range = 1;
1975.     save_bhitpos = bhitpos;
1976. 
1977.     tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype));
1978.     while(range-- > 0) {
1979. 	lsx = sx; sx += dx;
1980. 	lsy = sy; sy += dy;
1981. 	if(isok(sx,sy) && (lev = &levl[sx][sy])->typ) {
1982. 	    if(cansee(sx,sy)) {
1983. 		if(ZAP_POS(lev->typ) || cansee(lsx,lsy))
1984. 		    tmp_at(sx,sy);
1985. 		delay_output(); /* wait a little */
1986. 	    }
1987. 	} else
1988. 	    goto make_bounce;
1989. 
1990. 	/* hit() and miss() need bhitpos to match the target */
1991. 	bhitpos.x = sx,  bhitpos.y = sy;
1992. 	/* Fireballs only damage when they explode */
1993. 	if (type != ZT_SPELL(ZT_FIRE))
1994. 	    range += zap_over_floor(sx, sy, type, &shopdamage);
1995. 
1996. 	if ((mon = m_at(sx, sy)) != 0) {
1997. 	    if (type == ZT_SPELL(ZT_FIRE)) break;
1998. 	    if (type >= 0) mon->mstrategy &= ~STRAT_WAITMASK;
1999. 	    if (zap_hit(find_mac(mon))) {
2000. 		if (mon_reflects(mon, (char *)0)) {
2001. 		    if(cansee(mon->mx,mon->my)) {
2002. 			hit(fltxt, mon, exclam(0));
2003. 			shieldeff(mon->mx, mon->my);
2004. 			(void) mon_reflects(mon, "But it reflects from %s %s!");
2005. 		    }
2006. 		    dx = -dx;
2007. 		    dy = -dy;
2008. 		} else {
2009. 		    boolean mon_could_move = mon->mcanmove;
2010. 		    int tmp = zhit(mon, type, nd);
2011. 
2012. 		    if (is_rider(mon->data) && type == ZT_BREATH(ZT_DEATH)) {
2013. 			if (canseemon(mon)) {
2014. 			    hit(fltxt, mon, exclam(tmp));
2015. 			    pline("%s disintegrates.", Monnam(mon));
2016. 			    pline("%s body reintegrates before your %s!",
2017. 			         s_suffix(Monnam(mon)),
2018. 			         makeplural(body_part(EYE)));
2019. 		            pline("%s resurrects!", Monnam(mon));
2020. 			}
2021. 		        mon->mhp = mon->mhpmax;
2022. 			break; /* Out of while loop */
2023. 		    }
2024. 		    if(mon->data == &mons[PM_DEATH] && abstype == ZT_DEATH) {
2025. 		        if(cansee(mon->mx,mon->my)) {
2026. 			    hit(fltxt, mon, exclam(tmp));
2027. 		            pline("Death absorbs the deadly %s!",
2028. 				        type == ZT_BREATH(ZT_DEATH) ?
2029. 				        "blast" : "ray");
2030. 		            pline("It seems even stronger than before.");
2031. 		        }
2032. 		        break; /* Out of while loop */
2033. 		    }
2034. 
2035. 		    if (tmp == MAGIC_COOKIE) { /* disintegration */
2036. 			struct obj *otmp, *otmp2;
2037. 			pline("%s is disintegrated!", Monnam(mon));
2038. 			mon->mgold = 0L;
2039. 
2040. #define oresist_disintegration(obj) \
2041. 		(objects[obj->otyp].oc_oprop == DISINT_RES || \
2042. 		 obj_resists(obj, 5, 50) || is_quest_artifact(obj))
2043. 
2044. 			for (otmp = mon->minvent; otmp; otmp = otmp2) {
2045. 			    otmp2 = otmp->nobj;
2046. 			    if (!oresist_disintegration(otmp)) {
2047. 				obj_extract_self(otmp);
2048. 				obfree(otmp, (struct obj *)0);
2049. 			    }
2050. 			}
2051. 
2052. 			if (type < 0)
2053. 			    monkilled(mon, (char *)0, -AD_RBRE);
2054. 			else
2055. 			    xkilled(mon, 2);
2056. 		    } else if(mon->mhp < 1) {
2057. 			if(type < 0)
2058. 			    monkilled(mon, fltxt, AD_RBRE);
2059. 			else
2060. 			    killed(mon);
2061. 		    } else {
2062. 			hit(fltxt, mon, exclam(tmp));
2063. 
2064. 			if (mon_could_move && !mon->mcanmove)	/* ZT_SLEEP */
2065. 			    slept_monst(mon);
2066. 		    }
2067. 		}
2068. 		range -= 2;
2069. 	    } else {
2070. 		miss(fltxt,mon);
2071. 	    }
2072. 	} else if (sx == u.ux && sy == u.uy && range >= 0) {
2073. 	    nomul(0);
2074. 	    if (zap_hit((int) u.uac)) {
2075. 		register int dam = 0;
2076. 		range -= 2;
2077. 		pline("%s hits you!", The(fltxt));
2078. 		if (Reflecting) {
2079. 		    if (!Blind) {
2080. 			if(Reflecting & WORN_AMUL)
2081. 			    makeknown(AMULET_OF_REFLECTION);
2082. 			else
2083. 			    makeknown(SHIELD_OF_REFLECTION);
2084. 			pline("But it reflects from your %s!",
2085. 			      (Reflecting & W_AMUL) ? "amulet" : "shield");
2086. 		    } else
2087. 			pline("For some reason you are not affected.");
2088. 		    dx = -dx;
2089. 		    dy = -dy;
2090. 		    shieldeff(sx, sy);
2091. 		}
2092. 		else switch(abstype) {
2093. 		case ZT_MAGIC_MISSILE:
2094. 		    if(Antimagic) {
2095. 			shieldeff(sx, sy);
2096. 			pline_The("missiles bounce off!");
2097. 		    } else {
2098. 		        dam = d(nd,6);
2099. 			exercise(A_STR, FALSE);
2100. 		    }
2101. 		    break;
2102. 		case ZT_FIRE:
2103. 		    if(Fire_resistance) {
2104. 			shieldeff(sx, sy);
2105. 			You("don't feel hot!");
2106. 			ugolemeffects(AD_FIRE, d(nd, 6));
2107. 		    } else dam = d(nd, 6);
2108. 		    if (burnarmor()) {	/* "body hit" */
2109. 			if (!rn2(3)) destroy_item(POTION_CLASS, AD_FIRE);
2110. 			if (!rn2(3)) destroy_item(SCROLL_CLASS, AD_FIRE);
2111. 			if (!rn2(5)) destroy_item(SPBOOK_CLASS, AD_FIRE);
2112. 		    }
2113. 		    break;
2114. 		case ZT_COLD:
2115. 		    if(Cold_resistance) {
2116. 			shieldeff(sx, sy);
2117. 			You("don't feel cold.");
2118. 			ugolemeffects(AD_COLD, d(nd, 6));
2119. 		    } else
2120. 			dam = d(nd, 6);
2121. 		    if(!rn2(3))
2122. 			destroy_item(POTION_CLASS, AD_COLD);
2123. 		    break;
2124. 		case ZT_SLEEP:
2125. 		    if(Sleep_resistance) {
2126. 			shieldeff(u.ux, u.uy);
2127. 			You("don't feel sleepy.");
2128. 		    } else {
2129. 			/* have to do this _before_ we reset multi */
2130. 			stop_occupation();
2131. 			fall_asleep(-d(nd,25), TRUE); /* sleep ray */
2132. 		    }
2133. 		    break;
2134. 		case ZT_DEATH:
2135. 		    if(abs(type) == ZT_BREATH(ZT_DEATH)) {
2136. 			if (Disint_resistance) {
2137. 			    You("are not disintegrated.");
2138. 			    break;
2139. 			} else if (uarms) {
2140. 			    /* destroy shield; other possessions are safe */
2141. 			    (void) destroy_arm(uarms);
2142. 			    break;
2143. 			} else if (uarm) {
2144. 			    /* destroy suit; if present, cloak goes too */
2145. 			    if (uarmc) (void) destroy_arm(uarmc);
2146. 			    (void) destroy_arm(uarm);
2147. 			    break;
2148. 			}
2149. 			/* no shield or suit, you're dead; wipe out cloak
2150. 			   and/or shirt in case of life-saving or bones */
2151. 			if (uarmc) (void) destroy_arm(uarmc);
2152. #ifdef TOURIST
2153. 			if (uarmu) (void) destroy_arm(uarmu);
2154. #endif
2155. 		    } else if (nonliving(uasmon) || is_demon(uasmon)) {
2156. 			shieldeff(sx, sy);
2157. 			You("seem unaffected.");
2158. 			break;
2159. 		    } else if (Antimagic) {
2160. 			shieldeff(sx, sy);
2161. 			You("aren't affected.");
2162. 			break;
2163. 		    }
2164. 		    u.uhp = -1;
2165. 		    break;
2166. 		case ZT_LIGHTNING:
2167. 		    if (Shock_resistance) {
2168. 			shieldeff(sx, sy);
2169. 			You("aren't affected.");
2170. 			ugolemeffects(AD_ELEC, d(nd, 6));
2171. 		    } else {
2172. 			dam = d(nd, 6);
2173. 			exercise(A_CON, FALSE);
2174. 		    }
2175. 		    if(!rn2(3))
2176. 			destroy_item(WAND_CLASS, AD_ELEC);
2177. 		    if(!rn2(3))
2178. 			destroy_item(RING_CLASS, AD_ELEC);
2179. 		    break;
2180. 		case ZT_POISON_GAS:
2181. 		    poisoned("blast", A_DEX, "poisoned blast", 15);
2182. 		    break;
2183. 		case ZT_ACID:
2184. 		    if (resists_acid(&youmonst))
2185. 			dam = 0;
2186. 		    else {
2187. 			pline_The("acid burns!");
2188. 			dam = d(nd,6);
2189. 			exercise(A_STR, FALSE);
2190. 		    }
2191. 		    if(!rn2(6)) erode_weapon(TRUE);
2192. 		    if(!rn2(6)) erode_armor(TRUE);
2193. 		    break;
2194. 		}
2195. 		if(Half_spell_damage && dam &&
2196. 		   type < 0 && (type > -20 || type < -29)) /* !Breath */
2197. 		    dam = (dam+1) / 2;
2198. 		/* when killed by disintegration breath, don't leave corpse */
2199. 		u.ugrave_arise = (type == -ZT_BREATH(ZT_DEATH)) ? -3 : -1;
2200. 		losehp(dam, fltxt, KILLED_BY_AN);
2201. 	    } else pline("%s whizzes by you!", The(fltxt));
2202. 	    if (abstype == ZT_LIGHTNING && !Blind) {
2203. 		You("are blinded by the flash!");
2204. 		make_blinded((long)d(nd,50),FALSE);
2205. 	    }
2206. 	    stop_occupation();
2207. 	    nomul(0);
2208. 	}
2209. 
2210. 	if(!ZAP_POS(lev->typ) || (closed_door(sx, sy) && (range >= 0))) {
2211. 	    int bounce;
2212. 	    uchar rmn;
2213. 
2214.  make_bounce:
2215. 	    if (type == ZT_SPELL(ZT_FIRE)) {
2216. 		sx = lsx;
2217. 		sy = lsy;
2218. 		break; /* fireballs explode before the wall */
2219. 	    }
2220. 	    bounce = 0;
2221. 	    range--;
2222. 	    if(range && isok(lsx, lsy) && cansee(lsx,lsy))
2223. 		pline("%s bounces!", The(fltxt));
2224. 	    if(!dx || !dy || !rn2(20)) {
2225. 		dx = -dx;
2226. 		dy = -dy;
2227. 	    } else {
2228. 		if(isok(sx,lsy) && ZAP_POS(rmn = levl[sx][lsy].typ) &&
2229. 		   (IS_ROOM(rmn) || (isok(sx+dx,lsy) &&
2230. 				     ZAP_POS(levl[sx+dx][lsy].typ))))
2231. 		    bounce = 1;
2232. 		if(isok(lsx,sy) && ZAP_POS(rmn = levl[lsx][sy].typ) &&
2233. 		   (IS_ROOM(rmn) || (isok(lsx,sy+dy) &&
2234. 				     ZAP_POS(levl[lsx][sy+dy].typ))))
2235. 		    if(!bounce || rn2(2))
2236. 			bounce = 2;
2237. 
2238. 		switch(bounce) {
2239. 		case 0: dx = -dx; /* fall into... */
2240. 		case 1: dy = -dy; break;
2241. 		case 2: dx = -dx; break;
2242. 		}
2243. 		tmp_at(DISP_CHANGE, zapdir_to_glyph(dx,dy,abstype));
2244. 	    }
2245. 	}
2246.     }
2247.     tmp_at(DISP_END,0);
2248.     if (type == ZT_SPELL(ZT_FIRE))
2249. 	explode(sx, sy, type, d(12,6), 0);
2250.     if (shopdamage)
2251. 	pay_for_damage(abstype == ZT_FIRE ?  "burn away" :
2252. 		       abstype == ZT_COLD ?  "shatter" :
2253. 		       abstype == ZT_DEATH ? "disintegrate" : "destroy");
2254.     bhitpos = save_bhitpos;
2255. }
2256. #endif /*OVLB*/
2257. #ifdef OVL0
2258. 
2259. void
2260. melt_ice(x, y)
2261. xchar x, y;
2262. {
2263. 	struct rm *lev = &levl[x][y];
2264. 	struct obj *otmp;
2265. 
2266. 	if (lev->typ == DRAWBRIDGE_UP)
2267. 	    lev->drawbridgemask &= ~DB_ICE;	/* revert to DB_MOAT */
2268. 	else {	/* lev->typ == ICE */
2269. #ifdef STUPID
2270. 	    if (lev->icedpool == ICED_POOL) lev->typ = POOL;
2271. 	    else lev->typ = MOAT;
2272. #else
2273. 	    lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT);
2274. #endif
2275. 	    lev->icedpool = 0;
2276. 	}
2277. 	obj_ice_effects(x, y, FALSE);
2278. 	unearth_objs(x, y);
2279. 	if (Underwater) vision_recalc(1);
2280. 	newsym(x,y);
2281. 	if (cansee(x,y)) Norep("The ice crackles and melts.");
2282. 	if ((otmp = sobj_at(BOULDER, x, y)) != 0) {
2283. 	    if (cansee(x,y)) pline("%s settles...", An(xname(otmp)));
2284. 	    do {
2285. 		obj_extract_self(otmp);	/* boulder isn't being pushed */
2286. 		if (!boulder_hits_pool(otmp, x, y, FALSE))
2287. 		    impossible("melt_ice: no pool?");
2288. 		/* try again if there's another boulder and pool didn't fill */
2289. 	    } while (is_pool(x,y) && (otmp = sobj_at(BOULDER, x, y)) != 0);
2290. 	    newsym(x,y);
2291. 	}
2292. 	if (x == u.ux && y == u.uy)
2293. 		spoteffects();	/* possibly drown, notice objects */
2294. }
2295. 
2296. /* Burn floor scrolls, evaporate pools, etc...  in a single square.  Used
2297.  * both for normal bolts of fire, cold, etc... and for fireballs.
2298.  * Sets shopdamage to TRUE if a shop door is destroyed, and returns the
2299.  * amount by which range is reduced (the latter is just ignored by fireballs)
2300.  */
2301. int
2302. zap_over_floor(x, y, type, shopdamage)
2303. xchar x, y;
2304. int type;
2305. boolean *shopdamage;
2306. {
2307. 	struct monst *mon;
2308. 	int abstype = abs(type) % 10;
2309. 	struct rm *lev = &levl[x][y];
2310. 	int rangemod = 0;
2311. 
2312. 	if(abstype == ZT_FIRE) {
2313. 	    if(is_ice(x, y)) {
2314. 		melt_ice(x, y);
2315. 	    } else if(is_pool(x,y)) {
2316. 		const char *msgtxt = "You hear hissing gas.";
2317. 		if(lev->typ != POOL) {	/* MOAT or DRAWBRIDGE_UP */
2318. 		    if (cansee(x,y)) msgtxt = "Some water evaporates.";
2319. 		} else {
2320. 		    register struct trap *ttmp;
2321. 
2322. 		    rangemod -= 3;
2323. 		    lev->typ = ROOM;
2324. 		    ttmp = maketrap(x, y, PIT);
2325. 		    if (ttmp) ttmp->tseen = 1;
2326. 		    if (cansee(x,y)) msgtxt = "The water evaporates.";
2327. 		}
2328. 		Norep(msgtxt);
2329. 		if (lev->typ == ROOM) newsym(x,y);
2330. 	    } else if(IS_FOUNTAIN(lev->typ)) {
2331. 		    if (cansee(x,y))
2332. 			pline("Steam billows from the fountain.");
2333. 		    rangemod -= 1;
2334. 		    dryup(x,y);
2335. 	    }
2336. 	}
2337. 	else if(abstype == ZT_COLD && (is_pool(x,y) || is_lava(x,y))) {
2338. 		boolean lava = is_lava(x,y);
2339. 		boolean moat = (!lava && (lev->typ != POOL) &&
2340. 				(lev->typ != WATER) &&
2341. 				!Is_medusa_level(&u.uz) &&
2342. 				!Is_waterlevel(&u.uz));
2343. 
2344. 		if (lev->typ == WATER) {
2345. 		    /* For now, don't let WATER freeze. */
2346. 		    if (cansee(x,y))
2347. 			pline_The("water freezes for a moment.");
2348. 		    else
2349. 			You_hear("a soft crackling.");
2350. 		    rangemod -= 1000;	/* stop */
2351. 		} else {
2352. 		    rangemod -= 3;
2353. 		    if (lev->typ == DRAWBRIDGE_UP) {
2354. 			lev->drawbridgemask &= ~DB_UNDER;  /* clear lava */
2355. 			lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE);
2356. 		    } else {
2357. 			if (!lava)
2358. 			    lev->icedpool =
2359. 				    (lev->typ == POOL ? ICED_POOL : ICED_MOAT);
2360. 			lev->typ = (lava ? ROOM : ICE);
2361. 		    }
2362. 		    bury_objs(x,y);
2363. 		    if(cansee(x,y)) {
2364. 			if(moat)
2365. 				Norep("The moat is bridged with ice!");
2366. 			else if(lava)
2367. 				Norep("The lava cools and solidifies.");
2368. 			else
2369. 				Norep("The water freezes.");
2370. 			newsym(x,y);
2371. 		    } else if(flags.soundok && !lava)
2372. 			You_hear("a crackling sound.");
2373. 
2374. 		    if (x == u.ux && y == u.uy) {
2375. 			if (u.uinwater) {   /* not just `if (Underwater)' */
2376. 			    /* leave the no longer existent water */
2377. 			    u.uinwater = 0;
2378. 			    docrt();
2379. 			    vision_full_recalc = 1;
2380. 			} else if (u.utrap && u.utraptype == TT_LAVA) {
2381. 			    if (passes_walls(uasmon)) {
2382. 				You("pass through the now-solid rock.");
2383. 			    } else {
2384. 				u.utrap = rn1(50,20);
2385. 				u.utraptype = TT_INFLOOR;
2386. 				You("are firmly stuck in the cooling rock.");
2387. 			    }
2388. 			}
2389. 		    } else if ((mon = m_at(x,y)) != 0) {
2390. 			/* probably ought to do some hefty damage to any
2391. 			   non-ice creature caught in freezing water;
2392. 			   at a minimum, eels are forced out of hiding */
2393. 			if (is_swimmer(mon->data) && mon->mundetected) {
2394. 			    mon->mundetected = 0;
2395. 			    newsym(x,y);
2396. 			}
2397. 		    }
2398. 		}
2399. 		obj_ice_effects(x,y,TRUE);
2400. 	}
2401. 	if(closed_door(x, y)) {
2402. 		int new_doormask = -1;
2403. 		const char *see_txt = 0, *sense_txt = 0, *hear_txt = 0;
2404. 		rangemod = -1000;
2405. 		switch(abstype) {
2406. 		case ZT_FIRE:
2407. 		    new_doormask = D_NODOOR;
2408. 		    see_txt = "The door is consumed in flames!";
2409. 		    sense_txt = "smell smoke.";
2410. 		    break;
2411. 		case ZT_COLD:
2412. 		    new_doormask = D_NODOOR;
2413. 		    see_txt = "The door freezes and shatters!";
2414. 		    sense_txt = "feel cold.";
2415. 		    break;
2416. 		case ZT_DEATH:
2417. 		    /* death spells/wands don't disintegrate */
2418. 		    if(abs(type) != ZT_BREATH(ZT_DEATH))
2419. 			goto def_case;
2420. 		    new_doormask = D_NODOOR;
2421. 		    see_txt = "The door disintegrates!";
2422. 		    hear_txt = "crashing wood.";
2423. 		    break;
2424. 		case ZT_LIGHTNING:
2425. 		    new_doormask = D_BROKEN;
2426. 		    see_txt = "The door splinters!";
2427. 		    hear_txt = "crackling.";
2428. 		    break;
2429. 		default:
2430. 		def_case:
2431. 		    if(cansee(x,y)) {
2432. 			pline_The("door absorbs %s %s!",
2433. 			      (type < 0) ? "the" : "your",
2434. 			      abs(type) < ZT_SPELL(0) ? "bolt" :
2435. 			      abs(type) < ZT_BREATH(0) ? "spell" :
2436. 			      "blast");
2437. 		    } else You_feel("vibrations.");
2438. 		    break;
2439. 		}
2440. 		if (new_doormask >= 0) {	/* door gets broken */
2441. 		    if (*in_rooms(x, y, SHOPBASE)) {
2442. 			if (type >= 0) {
2443. 			    add_damage(x, y, 400L);
2444. 			    *shopdamage = TRUE;
2445. 			} else	/* caused by monster */
2446. 			    add_damage(x, y, 0L);
2447. 		    }
2448. 		    lev->doormask = new_doormask;
2449. 		    unblock_point(x, y);	/* vision */
2450. 		    if (cansee(x, y)) {
2451. 			pline(see_txt);
2452. 			newsym(x, y);
2453. 		    } else if (sense_txt) {
2454. 			You(sense_txt);
2455. 		    } else if (hear_txt) {
2456. 			if (flags.soundok) You_hear(hear_txt);
2457. 		    }
2458. 		    if (picking_at(x, y)) {
2459. 			stop_occupation();
2460. 			reset_pick();
2461. 		    }
2462. 		}
2463. 	}
2464. 
2465. 	if(OBJ_AT(x, y) && abstype == ZT_FIRE)
2466. 		if (burn_floor_paper(x, y, FALSE) && couldsee(x, y))  {
2467. 		    newsym(x,y);
2468. 		    You("%s of smoke.",
2469. 			!Blind ? "see a puff" : "smell a whiff");
2470. 		}
2471. 	if ((mon = m_at(x,y)) != 0) {
2472. 		/* Cannot use wakeup() which also angers the monster */
2473. 		mon->msleep = 0;
2474. 		if(mon->m_ap_type) seemimic(mon);
2475. 		if(type >= 0) {
2476. 		    setmangry(mon);
2477. 		    if(mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE))
2478. 			ghod_hitsu(mon);
2479. 		    if(mon->isshk && !*u.ushops)
2480. 			hot_pursuit(mon);
2481. 		}
2482. 	}
2483. 	return rangemod;
2484. }
2485. #endif /*OVL0*/
2486. #ifdef OVL3
2487. void
2488. fracture_rock(obj)	/* fractured by pick-axe or wand of striking */
2489. register struct obj *obj;		   /* no texts here! */
2490. {
2491. 	obj->otyp = ROCK;
2492. 	obj->quan = (long) rn1(60, 7);
2493. 	obj->owt = weight(obj);
2494. 	obj->oclass = GEM_CLASS;
2495. 	obj->known = FALSE;
2496. 	obj->onamelth = 0;		/* no names */
2497. 	if(!does_block(obj->ox,obj->oy,&levl[obj->ox][obj->oy]))
2498. 	    unblock_point(obj->ox,obj->oy);
2499. 	if(cansee(obj->ox,obj->oy))
2500. 	    newsym(obj->ox,obj->oy);
2501. }
2502. 
2503. boolean
2504. break_statue(obj)
2505. register struct obj *obj;
2506. {
2507. 	struct trap *trap;
2508. 	struct obj *item;
2509. 
2510. 	if((trap = t_at(obj->ox,obj->oy)) && trap->ttyp == STATUE_TRAP)
2511. 	    if(makemon(&mons[obj->corpsenm], obj->ox, obj->oy)) {
2512. 		pline("Instead of shattering, the statue suddenly comes alive!");
2513. 		delobj(obj);
2514. 		deltrap(trap);
2515. 		return FALSE;
2516. 	    }
2517. 	while ((item = obj->cobj) != 0) {
2518. 	    obj_extract_self(item);
2519. 	    place_object(item, obj->ox, obj->oy);
2520. 	}
2521. 	fracture_rock(obj);
2522. 	return TRUE;
2523. }
2524. 
2525. const char *destroy_strings[] = {
2526. 	"freezes and shatters", "freeze and shatter", "shattered potion",
2527. 	"boils and explodes", "boil and explode", "boiling potion",
2528. 	"catches fire and burns", "catch fire and burn", "burning scroll",
2529. 	"catches fire and burns", "catch fire and burn", "burning book",
2530. 	"turns to dust and vanishes", "turn to dust and vanish", "",
2531. 	"breaks apart and explodes", "break apart and explode", "exploding wand"
2532. };
2533. 
2534. void
2535. destroy_item(osym, dmgtyp)
2536. register int osym, dmgtyp;
2537. {
2538. 	register struct obj *obj, *obj2;
2539. 	register int dmg, xresist, skip;
2540. 	register long i, cnt, quan;
2541. 	register int dindx;
2542. 	const char *mult;
2543. 
2544. 	for(obj = invent; obj; obj = obj2) {
2545. 	    obj2 = obj->nobj;
2546. 	    if(obj->oclass != osym) continue; /* test only objs of type osym */
2547. 	    if(obj->oartifact) continue; /* don't destroy artifacts */
2548. 	    xresist = skip = 0;
2549. #ifdef GCC_WARN
2550. 	    dmg = dindx = 0;
2551. 	    quan = 0L;
2552. #endif
2553. 	    switch(dmgtyp) {
2554. 		case AD_COLD:
2555. 		    if(osym == POTION_CLASS && obj->otyp != POT_OIL) {
2556. 			quan = obj->quan;
2557. 			dindx = 0;
2558. 			dmg = rnd(4);
2559. 		    } else skip++;
2560. 		    break;
2561. 		case AD_FIRE:
2562. 		    xresist = (Fire_resistance && obj->oclass != POTION_CLASS);
2563. 
2564. 		    if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
2565. 			skip++;
2566. 		    if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
2567. 			skip++;
2568. 			if (!Blind)
2569. 			    pline("%s glows a strange %s, but remains intact.",
2570. 				The(xname(obj)), hcolor("dark red"));
2571. 		    }
2572. 		    quan = obj->quan;
2573. 		    switch(osym) {
2574. 			case POTION_CLASS:
2575. 			    dindx = 1;
2576. 			    dmg = rnd(6);
2577. 			    break;
2578. 			case SCROLL_CLASS:
2579. 			    dindx = 2;
2580. 			    dmg = 1;
2581. 			    break;
2582. 			case SPBOOK_CLASS:
2583. 			    dindx = 3;
2584. 			    dmg = 1;
2585. 			    break;
2586. 			default:
2587. 			    skip++;
2588. 			    break;
2589. 		    }
2590. 		    break;
2591. 		case AD_ELEC:
2592. 		    xresist = (Shock_resistance && obj->oclass != RING_CLASS);
2593. 		    quan = obj->quan;
2594. 		    switch(osym) {
2595. 			case RING_CLASS:
2596. 			    if(obj->otyp == RIN_SHOCK_RESISTANCE)
2597. 				    { skip++; break; }
2598. 			    dindx = 4;
2599. 			    dmg = 0;
2600. 			    break;
2601. 			case WAND_CLASS:
2602. 			    if(obj->otyp == WAN_LIGHTNING) { skip++; break; }
2603. #if 0
2604. 			    if (obj == current_wand) { skip++; break; }
2605. #endif
2606. 			    dindx = 5;
2607. 			    dmg = rnd(10);
2608. 			    break;
2609. 			default:
2610. 			    skip++;
2611. 			    break;
2612. 		    }
2613. 		    break;
2614. 		default:
2615. 		    skip++;
2616. 		    break;
2617. 	    }
2618. 	    if(!skip) {
2619. 		for(i = cnt = 0L; i < quan; i++)
2620. 		    if(!rn2(3)) cnt++;
2621. 
2622. 		if(!cnt) continue;
2623. 		if(cnt == quan)	mult = "Your";
2624. 		else	mult = (cnt == 1L) ? "One of your" : "Some of your";
2625. 		pline("%s %s %s!", mult, xname(obj),
2626. 			(cnt > 1L) ? destroy_strings[dindx*3 + 1]
2627. 				  : destroy_strings[dindx*3]);
2628. 		if(osym == POTION_CLASS && dmgtyp != AD_COLD)
2629. 		    potionbreathe(obj);
2630. 		if (obj->owornmask) {
2631. 		    if (obj->owornmask & W_RING) /* ring being worn */
2632. 			Ring_gone(obj);
2633. 		    else
2634. 			setnotworn(obj);
2635. 		}
2636. 		if (obj == current_wand) current_wand = 0;	/* destroyed */
2637. 		for (i = 0; i < cnt; i++)
2638. 		    useup(obj);
2639. 		if(dmg) {
2640. 		    if(xresist)	You("aren't hurt!");
2641. 		    else {
2642. 		        losehp(dmg, (cnt==1L) ? destroy_strings[dindx*3 + 2] :
2643. 			       (const char *)makeplural(destroy_strings[dindx*3 + 2]),
2644. 			       (cnt==1L) ? KILLED_BY_AN : KILLED_BY);
2645. 			exercise(A_STR, FALSE);
2646. 		   }
2647. 		}
2648. 	    }
2649. 	}
2650. 	return;
2651. }
2652. 
2653. int
2654. destroy_mitem(mtmp, osym, dmgtyp)
2655. register struct monst *mtmp;
2656. register int osym, dmgtyp;
2657. {
2658. 	register struct obj *obj, *obj2;
2659. 	register int skip, tmp = 0;
2660. 	register long i, cnt, quan;
2661. 	register int dindx;
2662. 	boolean vis=canseemon(mtmp);
2663. 
2664. 	for(obj = mtmp->minvent; obj; obj = obj2) {
2665. 	    obj2 = obj->nobj;
2666. 	    if(obj->oclass != osym) continue; /* test only objs of type osym */
2667. 	    skip = 0;
2668. 	    quan = 0L;
2669. 	    dindx = 0;
2670. 
2671. 	    switch(dmgtyp) {
2672. 		case AD_COLD:
2673. 		    if(osym == POTION_CLASS && obj->otyp != POT_OIL) {
2674. 			quan = obj->quan;
2675. 			dindx = 0;
2676. 			tmp++;
2677. 		    } else skip++;
2678. 		    break;
2679. 		case AD_FIRE:
2680. 		    if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
2681. 			skip++;
2682. 		    if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
2683. 			skip++;
2684. 			if (vis)
2685. 			    pline("%s glows a strange %s, but remains intact.",
2686. 				The(distant_name(obj, xname)),
2687. 				hcolor("dark red"));
2688. 		    }
2689. 		    quan = obj->quan;
2690. 		    switch(osym) {
2691. 			case POTION_CLASS:
2692. 			    dindx = 1;
2693. 			    tmp++;
2694. 			    break;
2695. 			case SCROLL_CLASS:
2696. 			    dindx = 2;
2697. 			    tmp++;
2698. 			    break;
2699. 			case SPBOOK_CLASS:
2700. 			    dindx = 3;
2701. 			    tmp++;
2702. 			    break;
2703. 			default:
2704. 			    skip++;
2705. 			    break;
2706. 		    }
2707. 		    break;
2708. 		case AD_ELEC:
2709. 		    quan = obj->quan;
2710. 		    switch(osym) {
2711. 			case RING_CLASS:
2712. 			    if(obj->otyp == RIN_SHOCK_RESISTANCE)
2713. 				    { skip++; break; }
2714. 			    dindx = 4;
2715. 			    break;
2716. 			case WAND_CLASS:
2717. 			    if(obj->otyp == WAN_LIGHTNING) { skip++; break; }
2718. 			    dindx = 5;
2719. 			    tmp++;
2720. 			    break;
2721. 			default:
2722. 			    skip++;
2723. 			    break;
2724. 		    }
2725. 		    break;
2726. 		default:
2727. 		    skip++;
2728. 		    break;
2729. 	    }
2730. 	    if(!skip) {
2731. 		for(i = cnt = 0L; i < quan; i++)
2732. 		    if(!rn2(3)) cnt++;
2733. 
2734. 		if(!cnt) continue;
2735. 		if (vis) pline("%s %s %s!",
2736. 			s_suffix(Monnam(mtmp)), xname(obj),
2737. 			(cnt > 1L) ? destroy_strings[dindx*3 + 1]
2738. 				  : destroy_strings[dindx*3]);
2739. 		for(i = 0; i < cnt; i++) m_useup(mtmp, obj);
2740. 	    }
2741. 	}
2742. 	return(tmp);
2743. }
2744. 
2745. #endif /*OVL3*/
2746. #ifdef OVL2
2747. 
2748. int
2749. resist(mtmp, oclass, damage, tell)
2750. struct monst *mtmp;
2751. char oclass;
2752. int damage, tell;
2753. {
2754. 	int resisted;
2755. 	int alev, dlev;
2756. 
2757. 	/* attack level */
2758. 	switch (oclass) {
2759. 	    case WAND_CLASS:	alev = 12;	 break;
2760. 	    case SCROLL_CLASS:	alev =  9;	 break;
2761. 	    case POTION_CLASS:	alev =  6;	 break;
2762. 	    default:		alev = u.ulevel; break;		/* spell */
2763. 	}
2764. 	/* defense level */
2765. 	dlev = (int)mtmp->m_lev;
2766. 	if (dlev > 50) dlev = 50;
2767. 	else if (dlev < 1) dlev = is_mplayer(mtmp->data) ? u.ulevel : 1;
2768. 
2769. 	resisted = rn2(100 + alev - dlev) < mtmp->data->mr;
2770. 	if(resisted) {
2771. 
2772. 		if(tell) {
2773. 		    shieldeff(mtmp->mx, mtmp->my);
2774. 		    pline("%s resists!", Monnam(mtmp));
2775. 		}
2776. 		mtmp->mhp -= damage/2;
2777. 	} else  mtmp->mhp -= damage;
2778. 
2779. 	if(mtmp->mhp < 1) {
2780. 		if(m_using) monkilled(mtmp, "", AD_RBRE);
2781. 		else killed(mtmp);
2782. 	}
2783. 	return(resisted);
2784. }
2785. 
2786. void
2787. makewish()
2788. {
2789. 	char buf[BUFSZ];
2790. 	register struct obj *otmp;
2791. 	int tries = 0;
2792. 
2793. 	if (flags.verbose) You("may wish for an object.");
2794. retry:
2795. 	getlin("For what do you wish?", buf);
2796. 	if(buf[0] == '\033') buf[0] = 0;
2797. 	/*
2798. 	 *  Note: if they wished for and got a non-object successfully,
2799. 	 *  otmp == &zeroobj
2800. 	 */
2801. 	otmp = readobjnam(buf);
2802. 	if (!otmp) {
2803. 	    pline("Nothing fitting that description exists in the game.");
2804. 	    if (++tries < 5) goto retry;
2805. 	    pline(thats_enough_tries);
2806. 	    if (!(otmp = readobjnam((char *)0)))
2807. 		return; /* for safety; should never happen */
2808. 	}
2809. 	if (otmp != &zeroobj) {
2810. 	    if(otmp->oartifact && !touch_artifact(otmp,&youmonst))
2811. 		dropy(otmp);
2812. 	    else
2813. 		/* The(aobjnam()) is safe since otmp is unidentified -dlc */
2814. 		(void) hold_another_object(otmp, u.uswallow ?
2815. 				       "Oops!  %s out of your reach!" :
2816. 				       Is_airlevel(&u.uz) || u.uinwater ?
2817. 				       "Oops!  %s away from you!" :
2818. 				       "Oops!  %s to the floor!",
2819. 				       The(aobjnam(otmp,
2820. 					     Is_airlevel(&u.uz) || u.uinwater ?
2821. 						   "slip" : "drop")),
2822. 				       (const char *)0);
2823. 	    u.ublesscnt += rn1(100,50);  /* the gods take notice */
2824. 	}
2825. }
2826. 
2827. #endif /*OVL2*/
2828. 
2829. /*zap.c*/