Source:NetHack 3.4.0/zap.c

From NetHackWiki
(Redirected from NetHack 3.4.0/zap.c)
Jump to navigation Jump to search

Below is the full text to zap.c from the source code of NetHack 3.4.0. To link to a particular line, write [[NetHack 3.4.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.4	2002/02/07	*/
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.   extern boolean notonhead;	/* for long worms */
20.   
21.   /* kludge to use mondied instead of killed */
22.   extern boolean m_using;
23.   
24.   STATIC_DCL void FDECL(costly_cancel, (struct obj *));
25.   STATIC_DCL void FDECL(polyuse, (struct obj*, int, int));
26.   STATIC_DCL void FDECL(create_polymon, (struct obj *, int));
27.   STATIC_DCL boolean FDECL(zap_updown, (struct obj *));
28.   STATIC_DCL int FDECL(zhitm, (struct monst *,int,int,struct obj **));
29.   STATIC_DCL void FDECL(zhitu, (int,int,const char *,XCHAR_P,XCHAR_P));
30.   STATIC_DCL void FDECL(revive_egg, (struct obj *));
31.   STATIC_DCL boolean FDECL(hits_bars, (struct obj *));
32.   #ifdef STEED
33.   STATIC_DCL boolean FDECL(zap_steed, (struct obj *));
34.   #endif
35.   
36.   #ifdef OVLB
37.   STATIC_DCL int FDECL(zap_hit, (int,int));
38.   #endif
39.   #ifdef OVL0
40.   STATIC_DCL void FDECL(backfire, (struct obj *));
41.   STATIC_DCL int FDECL(spell_hit_bonus, (int));
42.   #endif
43.   
44.   #define ZT_MAGIC_MISSILE	(AD_MAGM-1)
45.   #define ZT_FIRE			(AD_FIRE-1)
46.   #define ZT_COLD			(AD_COLD-1)
47.   #define ZT_SLEEP		(AD_SLEE-1)
48.   #define ZT_DEATH		(AD_DISN-1)	/* or disintegration */
49.   #define ZT_LIGHTNING		(AD_ELEC-1)
50.   #define ZT_POISON_GAS		(AD_DRST-1)
51.   #define ZT_ACID			(AD_ACID-1)
52.   /* 8 and 9 are currently unassigned */
53.   
54.   #define ZT_WAND(x)		(x)
55.   #define ZT_SPELL(x)		(10+(x))
56.   #define ZT_BREATH(x)		(20+(x))
57.   
58.   #define is_hero_spell(type)	((type) >= 10 && (type) < 20)
59.   
60.   #ifndef OVLB
61.   STATIC_VAR const char are_blinded_by_the_flash[];
62.   extern const char *flash_types[];
63.   #else
64.   STATIC_VAR const char are_blinded_by_the_flash[] = "are blinded by the flash!";
65.   
66.   const char *flash_types[] = {		/* also used in buzzmu(mcastu.c) */
67.   	"magic missile",	/* Wands must be 0-9 */
68.   	"bolt of fire",
69.   	"bolt of cold",
70.   	"sleep ray",
71.   	"death ray",
72.   	"bolt of lightning",
73.   	"",
74.   	"",
75.   	"",
76.   	"",
77.   
78.   	"magic missile",	/* Spell equivalents must be 10-19 */
79.   	"fireball",
80.   	"cone of cold",
81.   	"sleep ray",
82.   	"finger of death",
83.   	"bolt of lightning",	/* There is no spell, used for retribution */
84.   	"",
85.   	"",
86.   	"",
87.   	"",
88.   
89.   	"blast of missiles",	/* Dragon breath equivalents 20-29*/
90.   	"blast of fire",
91.   	"blast of frost",
92.   	"blast of sleep gas",
93.   	"blast of disintegration",
94.   	"blast of lightning",
95.   	"blast of poison gas",
96.   	"blast of acid",
97.   	"",
98.   	""
99.   };
100.  
101.  /* Routines for IMMEDIATE wands and spells. */
102.  /* bhitm: monster mtmp was hit by the effect of wand or spell otmp */
103.  int
104.  bhitm(mtmp, otmp)
105.  struct monst *mtmp;
106.  struct obj *otmp;
107.  {
108.  	boolean wake = TRUE;	/* Most 'zaps' should wake monster */
109.  	boolean reveal_invis = FALSE;
110.  	boolean dbldam = Role_if(PM_KNIGHT) && u.uhave.questart;
111.  	int dmg, otyp = otmp->otyp;
112.  	const char *zap_type_text = "spell";
113.  #ifdef STEED
114.  	struct obj *obj;
115.  #endif
116.  
117.  	if (u.uswallow && mtmp == u.ustuck)
118.  	    reveal_invis = FALSE;
119.  
120.  	switch(otyp) {
121.  	case WAN_STRIKING:
122.  		zap_type_text = "wand";
123.  		/* fall through */
124.  	case SPE_FORCE_BOLT:
125.  		reveal_invis = TRUE;
126.  		if (resists_magm(mtmp)) {	/* match effect on player */
127.  			shieldeff(mtmp->mx, mtmp->my);
128.  			break;	/* skip makeknown */
129.  		} else if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) {
130.  			dmg = d(2,12);
131.  			if(dbldam) dmg *= 2;
132.  			if (otyp == SPE_FORCE_BOLT)
133.  			    dmg += spell_damage_bonus();
134.  			hit(zap_type_text, mtmp, exclam(dmg));
135.  			(void) resist(mtmp, otmp->oclass, dmg, TELL);
136.  		} else miss(zap_type_text, mtmp);
137.  		makeknown(otyp);
138.  		break;
139.  	case WAN_SLOW_MONSTER:
140.  	case SPE_SLOW_MONSTER:
141.  		if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
142.  			mon_adjust_speed(mtmp, -1, otmp);
143.  			m_dowear(mtmp, FALSE); /* might want speed boots */
144.  			if (u.uswallow && (mtmp == u.ustuck) &&
145.  			    is_whirly(mtmp->data)) {
146.  				You("disrupt %s!", mon_nam(mtmp));
147.  				pline("A huge hole opens up...");
148.  				expels(mtmp, mtmp->data, TRUE);
149.  			}
150.  		}
151.  		break;
152.  	case WAN_SPEED_MONSTER:
153.  		if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
154.  			mon_adjust_speed(mtmp, 1, otmp);
155.  			m_dowear(mtmp, FALSE); /* might want speed boots */
156.  		}
157.  		break;
158.  	case WAN_UNDEAD_TURNING:
159.  	case SPE_TURN_UNDEAD:
160.  		wake = FALSE;
161.  		if (unturn_dead(mtmp)) wake = TRUE;
162.  		if (is_undead(mtmp->data)) {
163.  			reveal_invis = TRUE;
164.  			wake = TRUE;
165.  			dmg = rnd(8);
166.  			if(dbldam) dmg *= 2;
167.  			if (otyp == SPE_TURN_UNDEAD)
168.  				dmg += spell_damage_bonus();
169.  			flags.bypasses = TRUE;	/* for make_corpse() */
170.  			if (!resist(mtmp, otmp->oclass, dmg, NOTELL)) {
171.  			    if (mtmp->mhp > 0) monflee(mtmp, 0, FALSE, TRUE);
172.  			}
173.  		}
174.  		break;
175.  	case WAN_POLYMORPH:
176.  	case SPE_POLYMORPH:
177.  	case POT_POLYMORPH:
178.  		if (resists_magm(mtmp)) {
179.  		    /* magic resistance protects from polymorph traps, so make
180.  		       it guard against involuntary polymorph attacks too... */
181.  		    shieldeff(mtmp->mx, mtmp->my);
182.  		} else if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
183.  		    /* natural shapechangers aren't affected by system shock
184.  		       (unless protection from shapechangers is interfering
185.  		       with their metabolism...) */
186.  		    if (mtmp->cham == CHAM_ORDINARY && !rn2(25)) {
187.  			if (canseemon(mtmp)) {
188.  			    pline("%s shudders!", Monnam(mtmp));
189.  			    makeknown(otyp);
190.  			}
191.  			/* flags.bypasses = TRUE; ## for make_corpse() */
192.  			/* no corpse after system shock */
193.  			xkilled(mtmp, 3);
194.  		    } else if (newcham(mtmp, (struct permonst *)0,
195.  				       (otyp != POT_POLYMORPH))) {
196.  			if (!Hallucination && canspotmon(mtmp))
197.  			    makeknown(otyp);
198.  		    }
199.  		}
200.  		break;
201.  	case WAN_CANCELLATION:
202.  	case SPE_CANCELLATION:
203.  		cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE);
204.  		break;
205.  	case WAN_TELEPORTATION:
206.  	case SPE_TELEPORT_AWAY:
207.  		reveal_invis = !u_teleport_mon(mtmp, TRUE);
208.  		break;
209.  	case WAN_MAKE_INVISIBLE:
210.  	    {
211.  		int oldinvis = mtmp->minvis;
212.  		char nambuf[BUFSZ];
213.  
214.  		/* format monster's name before altering its visibility */
215.  		Strcpy(nambuf, Monnam(mtmp));
216.  		mon_set_minvis(mtmp);
217.  		if (!oldinvis && knowninvisible(mtmp)) {
218.  		    pline("%s turns transparent!", nambuf);
219.  		    makeknown(otyp);
220.  		}
221.  		break;
222.  	    }
223.  	case WAN_NOTHING:
224.  	case WAN_LOCKING:
225.  	case SPE_WIZARD_LOCK:
226.  		wake = FALSE;
227.  		break;
228.  	case WAN_PROBING:
229.  		wake = FALSE;
230.  		reveal_invis = TRUE;
231.  		probe_monster(mtmp);
232.  		makeknown(otyp);
233.  		break;
234.  	case WAN_OPENING:
235.  	case SPE_KNOCK:
236.  		wake = FALSE;	/* don't want immediate counterattack */
237.  		if (u.uswallow && mtmp == u.ustuck) {
238.  			if (is_animal(mtmp->data)) {
239.  				if (Blind) You_feel("a sudden rush of air!");
240.  				else pline("%s opens its mouth!", Monnam(mtmp));
241.  			}
242.  			expels(mtmp, mtmp->data, TRUE);
243.  #ifdef STEED
244.  		} else if (!!(obj = which_armor(mtmp, W_SADDLE))) {
245.  			mtmp->misc_worn_check &= ~obj->owornmask;
246.  			obj->owornmask = 0L;
247.  			update_mon_intrinsics(mtmp, obj, FALSE);
248.  			obj_extract_self(obj);
249.  			place_object(obj, mtmp->mx, mtmp->my);
250.  			/* call stackobj() if we ever drop anything that can merge */
251.  			newsym(mtmp->mx, mtmp->my);
252.  #endif
253.  		}
254.  		break;
255.  	case SPE_HEALING:
256.  	case SPE_EXTRA_HEALING:
257.  		reveal_invis = TRUE;
258.  	    if (mtmp->data != &mons[PM_PESTILENCE]) {
259.  		wake = FALSE;		/* wakeup() makes the target angry */
260.  		mtmp->mhp += d(6, otyp == SPE_EXTRA_HEALING ? 8 : 4);
261.  		if (mtmp->mhp > mtmp->mhpmax)
262.  		    mtmp->mhp = mtmp->mhpmax;
263.  		if (mtmp->mblinded) {
264.  		    mtmp->mblinded = 0;
265.  		    mtmp->mcansee = 1;
266.  		}
267.  		if (canseemon(mtmp))
268.  		    pline("%s looks%s better.", Monnam(mtmp),
269.  			  otyp == SPE_EXTRA_HEALING ? " much" : "" );
270.  		if (mtmp->mtame || mtmp->mpeaceful) {
271.  		    adjalign(Role_if(PM_HEALER) ? 1 : sgn(u.ualign.type));
272.  		}
273.  	    } else {	/* Pestilence */
274.  		/* Pestilence will always resist; damage is half of 3d{4,8} */
275.  		(void) resist(mtmp, otmp->oclass,
276.  			      d(3, otyp == SPE_EXTRA_HEALING ? 8 : 4), TELL);
277.  	    }
278.  		break;
279.  	case WAN_LIGHT:	/* (broken wand) */
280.  		if (flash_hits_mon(mtmp, otmp)) {
281.  		    makeknown(WAN_LIGHT);
282.  		    reveal_invis = TRUE;
283.  		}
284.  		break;
285.  	case WAN_SLEEP:	/* (broken wand) */
286.  		/* [wakeup() doesn't rouse victims of temporary sleep,
287.  		    so it's okay to leave `wake' set to TRUE here] */
288.  		reveal_invis = TRUE;
289.  		if (sleep_monst(mtmp, d(1 + otmp->spe, 12), WAND_CLASS))
290.  		    slept_monst(mtmp);
291.  		if (!Blind) makeknown(WAN_SLEEP);
292.  		break;
293.  	case SPE_STONE_TO_FLESH:
294.  		if (monsndx(mtmp->data) == PM_STONE_GOLEM) {
295.  		    char *name = Monnam(mtmp);
296.  		    /* turn into flesh golem */
297.  		    if (newcham(mtmp, &mons[PM_FLESH_GOLEM], FALSE)) {
298.  			if (canseemon(mtmp))
299.  			    pline("%s turns to flesh!", name);
300.  		    } else {
301.  			if (canseemon(mtmp))
302.  			    pline("%s looks rather fleshy for a moment.",
303.  				  name);
304.  		    }
305.  		} else
306.  		    wake = FALSE;
307.  		break;
308.  	case SPE_DRAIN_LIFE:
309.  		dmg = rnd(8);
310.  		if(dbldam) dmg *= 2;
311.  		if (otyp == SPE_DRAIN_LIFE)
312.  			dmg += spell_damage_bonus();
313.  		if (resists_drli(mtmp))
314.  		    shieldeff(mtmp->mx, mtmp->my);
315.  		else if (!resist(mtmp, otmp->oclass, dmg, NOTELL) &&
316.  				mtmp->mhp > 0) {
317.  		    mtmp->mhp -= dmg;
318.  		    mtmp->mhpmax -= dmg;
319.  		    if (mtmp->mhp <= 0 || mtmp->mhpmax <= 0 || mtmp->m_lev < 1)
320.  			xkilled(mtmp, 1);
321.  		    else {
322.  			mtmp->m_lev--;
323.  			if (canseemon(mtmp))
324.  			    pline("%s suddenly seems weaker!", Monnam(mtmp));
325.  		    }
326.  		}
327.  		break;
328.  	default:
329.  		impossible("What an interesting effect (%d)", otyp);
330.  		break;
331.  	}
332.  	if(wake) {
333.  	    if(mtmp->mhp > 0) {
334.  		wakeup(mtmp);
335.  		m_respond(mtmp);
336.  		if(mtmp->isshk && !*u.ushops) hot_pursuit(mtmp);
337.  	    } else if(mtmp->m_ap_type)
338.  		seemimic(mtmp); /* might unblock if mimicing a boulder/door */
339.  	}
340.  	/* note: bhitpos won't be set if swallowed, but that's okay since
341.  	 * reveal_invis will be false.  We can't use mtmp->mx, my since it
342.  	 * might be an invisible worm hit on the tail.
343.  	 */
344.  	if (reveal_invis) {
345.  	    if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y) &&
346.  							!canspotmon(mtmp))
347.  		map_invisible(bhitpos.x, bhitpos.y);
348.  	}
349.  	return 0;
350.  }
351.  
352.  void
353.  probe_monster(mtmp)
354.  struct monst *mtmp;
355.  {
356.  	struct obj *otmp;
357.  
358.  	mstatusline(mtmp);
359.  	if (notonhead) return;	/* don't show minvent for long worm tail */
360.  
361.  #ifndef GOLDOBJ
362.  	if (mtmp->minvent || mtmp->mgold) {
363.  #else
364.  	if (mtmp->minvent) {
365.  #endif
366.  	    for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
367.  		otmp->dknown = 1;	/* treat as "seen" */
368.  	    (void) display_minventory(mtmp, MINV_ALL, (char *)0);
369.  	} else {
370.  	    pline("%s is not carrying anything.", noit_Monnam(mtmp));
371.  	}
372.  }
373.  
374.  #endif /*OVLB*/
375.  #ifdef OVL1
376.  
377.  /*
378.   * Return the object's physical location.  This only makes sense for
379.   * objects that are currently on the level (i.e. migrating objects
380.   * are nowhere).  By default, only things that can be seen (in hero's
381.   * inventory, monster's inventory, or on the ground) are reported.
382.   * By adding BURIED_TOO and/or CONTAINED_TOO flags, you can also get
383.   * the location of buried and contained objects.  Note that if an
384.   * object is carried by a monster, its reported position may change
385.   * from turn to turn.  This function returns FALSE if the position
386.   * is not available or subject to the constraints above.
387.   */
388.  boolean
389.  get_obj_location(obj, xp, yp, locflags)
390.  struct obj *obj;
391.  xchar *xp, *yp;
392.  int locflags;
393.  {
394.  	switch (obj->where) {
395.  	    case OBJ_INVENT:
396.  		*xp = u.ux;
397.  		*yp = u.uy;
398.  		return TRUE;
399.  	    case OBJ_FLOOR:
400.  		*xp = obj->ox;
401.  		*yp = obj->oy;
402.  		return TRUE;
403.  	    case OBJ_MINVENT:
404.  		if (obj->ocarry->mx) {
405.  		    *xp = obj->ocarry->mx;
406.  		    *yp = obj->ocarry->my;
407.  		    return TRUE;
408.  		}
409.  		break;	/* !mx => migrating monster */
410.  	    case OBJ_BURIED:
411.  		if (locflags & BURIED_TOO) {
412.  		    *xp = obj->ox;
413.  		    *yp = obj->oy;
414.  		    return TRUE;
415.  		}
416.  		break;
417.  	    case OBJ_CONTAINED:
418.  		if (locflags & CONTAINED_TOO)
419.  		    return get_obj_location(obj->ocontainer, xp, yp, locflags);
420.  		break;
421.  	}
422.  	*xp = *yp = 0;
423.  	return FALSE;
424.  }
425.  
426.  boolean
427.  get_mon_location(mon, xp, yp, locflags)
428.  struct monst *mon;
429.  xchar *xp, *yp;
430.  int locflags;	/* non-zero means get location even if monster is buried */
431.  {
432.  	if (mon == &youmonst) {
433.  	    *xp = u.ux;
434.  	    *yp = u.uy;
435.  	    return TRUE;
436.  	} else if (mon->mx > 0 && (!mon->mburied || locflags)) {
437.  	    *xp = mon->mx;
438.  	    *yp = mon->my;
439.  	    return TRUE;
440.  	} else {	/* migrating or buried */
441.  	    *xp = *yp = 0;
442.  	    return FALSE;
443.  	}
444.  }
445.  
446.  /* used by revive() and animate_statue() */
447.  struct monst *
448.  montraits(obj,cc)
449.  struct obj *obj;
450.  coord *cc;
451.  {
452.  	struct monst *mtmp = (struct monst *)0;
453.  	struct monst *mtmp2 = (struct monst *)0;
454.  
455.  	if (obj->oxlth && (obj->oattached == OATTACHED_MONST))
456.  		mtmp2 = get_mtraits(obj, TRUE);
457.  	if (mtmp2) {
458.  		/* save_mtraits() validated mtmp2->mnum */
459.  		mtmp2->data = &mons[mtmp2->mnum];
460.  		if (mtmp2->mhpmax <= 0 && !is_rider(mtmp2->data))
461.  			return (struct monst *)0;
462.  		mtmp = makemon(mtmp2->data,
463.  				cc->x, cc->y, NO_MINVENT|MM_NOWAIT|MM_NOCOUNTBIRTH);
464.  		if (!mtmp) return mtmp;
465.  
466.  		/* heal the monster */
467.  		if (mtmp->mhpmax > mtmp2->mhpmax && is_rider(mtmp2->data))
468.  			mtmp2->mhpmax = mtmp->mhpmax;
469.  		mtmp2->mhp = mtmp2->mhpmax;
470.  		/* Get these ones from mtmp */
471.  		mtmp2->minvent = mtmp->minvent; /*redundant*/
472.  		/* monster ID is available if the monster died in the current
473.  		   game, but should be zero if the corpse was in a bones level
474.  		   (we cleared it when loading bones) */
475.  		if (!mtmp2->m_id)
476.  		    mtmp2->m_id = mtmp->m_id;
477.  		mtmp2->mx   = mtmp->mx;
478.  		mtmp2->my   = mtmp->my;
479.  		mtmp2->mux  = mtmp->mux;
480.  		mtmp2->muy  = mtmp->muy;
481.  		mtmp2->mw   = mtmp->mw;
482.  		mtmp2->wormno = mtmp->wormno;
483.  		mtmp2->misc_worn_check = mtmp->misc_worn_check;
484.  		mtmp2->weapon_check = mtmp->weapon_check;
485.  		mtmp2->mtrapseen = mtmp->mtrapseen;
486.  		mtmp2->mflee = mtmp->mflee;
487.  		mtmp2->mburied = mtmp->mburied;
488.  		mtmp2->mundetected = mtmp->mundetected;
489.  		mtmp2->mfleetim = mtmp->mfleetim;
490.  		mtmp2->mlstmv = mtmp->mlstmv;
491.  		mtmp2->m_ap_type = mtmp->m_ap_type;
492.  		/* set these ones explicitly */
493.  		mtmp2->mavenge = 0;
494.  		mtmp2->meating = 0;
495.  		mtmp2->mleashed = 0;
496.  		mtmp2->mtrapped = 0;
497.  		mtmp2->msleeping = 0;
498.  		mtmp2->mfrozen = 0;
499.  		mtmp2->mcan = 0;
500.  		mtmp2->mcansee = 1;	/* set like in makemon */
501.  		mtmp2->mblinded = 0;
502.  		mtmp2->mcanmove = 1;	/* set like in makemon */
503.  		mtmp2->mstun = 0;
504.  		mtmp2->mconf = 0;
505.  		replmon(mtmp,mtmp2);
506.  	}
507.  	return mtmp2;
508.  }
509.  
510.  /*
511.   * get_container_location() returns the following information
512.   * about the outermost container:
513.   * loc argument gets set to: 
514.   *	OBJ_INVENT	if in hero's inventory; return 0.
515.   *	OBJ_FLOOR	if on the floor; return 0.
516.   *	OBJ_BURIED	if buried; return 0.
517.   *	OBJ_MINVENT	if in monster's inventory; return monster.
518.   * container_nesting is updated with the nesting depth of the containers
519.   * if applicable.
520.   */
521.  struct monst *
522.  get_container_location(obj, loc, container_nesting)
523.  struct obj *obj;
524.  int *loc;
525.  int *container_nesting;
526.  {
527.  	if (!obj || !loc)
528.  		return 0;
529.  
530.  	if (container_nesting) *container_nesting = 0;
531.  	while (obj && obj->where == OBJ_CONTAINED) {
532.  		if (container_nesting) *container_nesting += 1;
533.  		obj = obj->ocontainer;
534.  	}
535.  	if (obj) {
536.  	    *loc = obj->where;	/* outermost container's location */
537.  	    if (obj->where == OBJ_MINVENT) return obj->ocarry;
538.  	}
539.  	return (struct monst *)0;
540.  }
541.  
542.  /*
543.   * Attempt to revive the given corpse, return the revived monster if
544.   * successful.  Note: this does NOT use up the corpse if it fails.
545.   */
546.  struct monst *
547.  revive(obj)
548.  register struct obj *obj;
549.  {
550.  	register struct monst *mtmp = (struct monst *)0;
551.  	struct obj *container = (struct obj *)0;
552.  	int container_nesting = 0;
553.  	schar savetame = 0;
554.  	boolean recorporealization = FALSE;
555.  	boolean in_container = FALSE;
556.  	if(obj->otyp == CORPSE) {
557.  		int montype = obj->corpsenm;
558.  		xchar x, y;
559.  
560.  		if (obj->where == OBJ_CONTAINED) {
561.  			/* deal with corpses in [possibly nested] containers */
562.  			struct monst *carrier;
563.  			int holder = 0;
564.  
565.  			container = obj->ocontainer;
566.  			carrier = get_container_location(container, &holder,
567.  							&container_nesting);
568.  			switch(holder) {
569.  			    case OBJ_MINVENT:
570.  				x = carrier->mx; y = carrier->my;
571.  				in_container = TRUE;
572.  				break;
573.  			    case OBJ_INVENT:
574.  				x = u.ux; y = u.uy;
575.  				in_container = TRUE;
576.  				break;
577.  			    case OBJ_FLOOR:
578.  				if (!get_obj_location(obj, &x, &y, CONTAINED_TOO))
579.  					return (struct monst *) 0;
580.  				in_container = TRUE;
581.  				break;
582.  			    default:
583.  			    	return (struct monst *)0;
584.  			}
585.  		} else {
586.  			/* only for invent, minvent, or floor */
587.  			if (!get_obj_location(obj, &x, &y, 0))
588.  			    return (struct monst *) 0;
589.  		}
590.  		if (in_container) {
591.  			/* Rules for revival from containers:
592.  			   - the container cannot be locked
593.  			   - the container cannot be heavily nested (>2 is arbitrary)
594.  			   - the container cannot be a statue or bag of holding
595.  			     (except in very rare cases for the latter)
596.  			*/
597.  			if (!x || !y || container->olocked || container_nesting > 2 ||
598.  			    container->otyp == STATUE ||
599.  			    (container->otyp == BAG_OF_HOLDING && rn2(40)))
600.  				return (struct monst *)0;
601.  		}
602.  
603.  		if (MON_AT(x,y)) {
604.  		    coord new_xy;
605.  
606.  		    if (enexto(&new_xy, x, y, &mons[montype]))
607.  			x = new_xy.x,  y = new_xy.y;
608.  		}
609.  
610.  		if(cant_create(&montype, TRUE)) {
611.  			/* make a zombie or worm instead */
612.  			mtmp = makemon(&mons[montype], x, y,
613.  				       NO_MINVENT|MM_NOWAIT);
614.  			if (mtmp) {
615.  				mtmp->mhp = mtmp->mhpmax = 100;
616.  				mon_adjust_speed(mtmp, 2, (struct obj *)0); /* MFAST */
617.  			}
618.  		} else {
619.  		    if (obj->oxlth && (obj->oattached == OATTACHED_MONST)) {
620.  			    coord xy;
621.  			    xy.x = x; xy.y = y;
622.  		    	    mtmp = montraits(obj, &xy);
623.  		    	    if (mtmp && mtmp->mtame && !mtmp->isminion)
624.  				wary_dog(mtmp, TRUE);
625.  		    } else
626.   		            mtmp = makemon(&mons[montype], x, y,
627.  				       NO_MINVENT|MM_NOWAIT|MM_NOCOUNTBIRTH);
628.  		    if (mtmp) {
629.  			if (obj->oxlth && (obj->oattached == OATTACHED_M_ID)) {
630.  			    unsigned m_id;
631.  			    struct monst *ghost;
632.  			    (void) memcpy((genericptr_t)&m_id,
633.  				    (genericptr_t)obj->oextra, sizeof(m_id));
634.  			    ghost = find_mid(m_id, FM_FMON);
635.  		    	    if (ghost && ghost->data == &mons[PM_GHOST]) {
636.  		    		    int x2, y2;
637.  		    		    x2 = ghost->mx; y2 = ghost->my;
638.  		    		    if (ghost->mtame)
639.  		    		    	savetame = ghost->mtame;
640.  		    		    if (canseemon(ghost))
641.  		    		  	pline("%s is suddenly drawn into its former body!",
642.  						Monnam(ghost));
643.  				    mongone(ghost);
644.  				    recorporealization = TRUE;
645.  				    newsym(x2, y2);
646.  			    }
647.  			    /* don't mess with obj->oxlth here */
648.  			    obj->oattached = OATTACHED_NOTHING;
649.  			}
650.  			/* Monster retains its name */
651.  			if (obj->onamelth)
652.  			    mtmp = christen_monst(mtmp, ONAME(obj));
653.  			/* flag the quest leader as alive. */
654.  			if (mtmp->data->msound == MS_LEADER || mtmp->m_id ==
655.  				quest_status.leader_m_id)
656.  			    quest_status.leader_is_dead = FALSE;
657.  		    }
658.  		}
659.  		if (mtmp) {
660.  			if (obj->oeaten)
661.  				mtmp->mhp = eaten_stat(mtmp->mhp, obj);
662.  			/* track that this monster was revived at least once */
663.  			mtmp->mrevived = 1;
664.  
665.  			if (recorporealization) {
666.  				/* If mtmp is revivification of former tame ghost*/
667.  				if (savetame) {
668.  				    struct monst *mtmp2 = tamedog(mtmp, (struct obj *)0);
669.  				    if (mtmp2) {
670.  					mtmp2->mtame = savetame;
671.  					mtmp = mtmp2;
672.  				    }
673.  				}
674.  				/* was ghost, now alive, it's all very confusing */
675.  				mtmp->mconf = 1;
676.  			}
677.  
678.  			switch (obj->where) {
679.  			    case OBJ_INVENT:
680.  				useup(obj);
681.  				break;
682.  			    case OBJ_FLOOR:
683.  				/* in case MON_AT+enexto for invisible mon */
684.  				x = obj->ox,  y = obj->oy;
685.  				/* not useupf(), which charges */
686.  				if (obj->quan > 1L)
687.  				    obj = splitobj(obj, 1L);
688.  				delobj(obj);
689.  				newsym(x, y);
690.  				break;
691.  			    case OBJ_MINVENT:
692.  				m_useup(obj->ocarry, obj);
693.  				break;
694.  			    case OBJ_CONTAINED:
695.  				obj_extract_self(obj);
696.  				obfree(obj, (struct obj *) 0);
697.  				break;
698.  			    default:
699.  				panic("revive");
700.  			}
701.  		}
702.  	}
703.  	return mtmp;
704.  }
705.  
706.  STATIC_OVL void
707.  revive_egg(obj)
708.  struct obj *obj;
709.  {
710.  	/*
711.  	 * Note: generic eggs with corpsenm set to NON_PM will never hatch.
712.  	 */
713.  	if (obj->otyp != EGG) return;
714.  	if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE))
715.  	    attach_egg_hatch_timeout(obj);
716.  }
717.  
718.  /* try to revive all corpses and eggs carried by `mon' */
719.  int
720.  unturn_dead(mon)
721.  struct monst *mon;
722.  {
723.  	struct obj *otmp, *otmp2;
724.  	struct monst *mtmp2;
725.  	char owner[BUFSZ], corpse[BUFSZ];
726.  	boolean youseeit;
727.  	int once = 0, res = 0;
728.  
729.  	youseeit = (mon == &youmonst) ? TRUE : canseemon(mon);
730.  	otmp2 = (mon == &youmonst) ? invent : mon->minvent;
731.  
732.  	while ((otmp = otmp2) != 0) {
733.  	    otmp2 = otmp->nobj;
734.  	    if (otmp->otyp == EGG)
735.  		revive_egg(otmp);
736.  	    if (otmp->otyp != CORPSE) continue;
737.  	    /* save the name; the object is liable to go away */
738.  	    if (youseeit) Strcpy(corpse, corpse_xname(otmp, TRUE));
739.  
740.  	    /* for a merged group, only one is revived; should this be fixed? */
741.  	    if ((mtmp2 = revive(otmp)) != 0) {
742.  		++res;
743.  		if (youseeit) {
744.  		    if (!once++) Strcpy(owner,
745.  					(mon == &youmonst) ? "Your" :
746.  					s_suffix(Monnam(mon)));
747.  		    pline("%s %s suddenly comes alive!", owner, corpse);
748.  		} else if (canseemon(mtmp2))
749.  		    pline("%s suddenly appears!", Amonnam(mtmp2));
750.  	    }
751.  	}
752.  	return res;
753.  }
754.  #endif /*OVL1*/
755.  
756.  #ifdef OVLB
757.  static const char charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS, 0 };
758.  
759.  STATIC_OVL void
760.  costly_cancel(obj)
761.  register struct obj *obj;
762.  {
763.  	char objroom;
764.  	struct monst *shkp = (struct monst *)0;
765.  
766.  	if (obj->no_charge) return;
767.  
768.  	switch (obj->where) {
769.  	case OBJ_INVENT:
770.  		if (obj->unpaid) {
771.  		    shkp = shop_keeper(*u.ushops);
772.  		    if (!shkp) return;
773.  		    Norep("You cancel an unpaid object, you pay for it!");
774.  		    bill_dummy_object(obj);
775.  		}
776.  		break;
777.  	case OBJ_FLOOR:
778.  		objroom = *in_rooms(obj->ox, obj->oy, SHOPBASE);
779.  		shkp = shop_keeper(objroom);
780.  		if (!shkp || !inhishop(shkp)) return;
781.  		if (costly_spot(u.ux, u.uy) && objroom == *u.ushops) {
782.  		    Norep("You cancel it, you pay for it!");
783.  		    bill_dummy_object(obj);
784.  		} else
785.  		    (void) stolen_value(obj, obj->ox, obj->oy, FALSE, FALSE);
786.  		break;
787.  	}
788.  }
789.  
790.  /* cancel obj, possibly carried by you or a monster */
791.  void
792.  cancel_item(obj)
793.  register struct obj *obj;
794.  {
795.  	boolean	u_ring = (obj == uleft) || (obj == uright);
796.  	register boolean holy = (obj->otyp == POT_WATER && obj->blessed);
797.  
798.  	switch(obj->otyp) {
799.  		case RIN_GAIN_STRENGTH:
800.  			if ((obj->owornmask & W_RING) && u_ring) {
801.  				ABON(A_STR) -= obj->spe;
802.  				flags.botl = 1;
803.  			}
804.  			break;
805.  		case RIN_GAIN_CONSTITUTION:
806.  			if ((obj->owornmask & W_RING) && u_ring) {
807.  				ABON(A_CON) -= obj->spe;
808.  				flags.botl = 1;
809.  			}
810.  			break;
811.  		case RIN_ADORNMENT:
812.  			if ((obj->owornmask & W_RING) && u_ring) {
813.  				ABON(A_CHA) -= obj->spe;
814.  				flags.botl = 1;
815.  			}
816.  			break;
817.  		case RIN_INCREASE_ACCURACY:
818.  			if ((obj->owornmask & W_RING) && u_ring)
819.  				u.uhitinc -= obj->spe;
820.  			break;
821.  		case RIN_INCREASE_DAMAGE:
822.  			if ((obj->owornmask & W_RING) && u_ring)
823.  				u.udaminc -= obj->spe;
824.  			break;
825.  		case GAUNTLETS_OF_DEXTERITY:
826.  			if ((obj->owornmask & W_ARMG) && (obj == uarmg)) {
827.  				ABON(A_DEX) -= obj->spe;
828.  				flags.botl = 1;
829.  			}
830.  			break;
831.  		case HELM_OF_BRILLIANCE:
832.  			if ((obj->owornmask & W_ARMH) && (obj == uarmh)) {
833.  				ABON(A_INT) -= obj->spe;
834.  				ABON(A_WIS) -= obj->spe;
835.  				flags.botl = 1;
836.  			}
837.  			break;
838.  		/* case RIN_PROTECTION:  not needed */
839.  	}
840.  	if (objects[obj->otyp].oc_magic
841.  	    || (obj->spe && (obj->oclass == ARMOR_CLASS ||
842.  			     obj->oclass == WEAPON_CLASS || is_weptool(obj)))
843.  	    || obj->otyp == POT_ACID || obj->otyp == POT_SICKNESS) {
844.  	    if (obj->spe != ((obj->oclass == WAND_CLASS) ? -1 : 0) &&
845.  	       obj->otyp != WAN_CANCELLATION &&
846.  		 /* can't cancel cancellation */
847.  		 obj->otyp != MAGIC_LAMP &&
848.  		 obj->otyp != CANDELABRUM_OF_INVOCATION) {
849.  		costly_cancel(obj);
850.  		obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0;
851.  	    }
852.  	    switch (obj->oclass) {
853.  	      case SCROLL_CLASS:
854.  		costly_cancel(obj);
855.  		obj->otyp = SCR_BLANK_PAPER;
856.  		obj->spe = 0;
857.  		break;
858.  	      case SPBOOK_CLASS:
859.  		if (obj->otyp != SPE_CANCELLATION &&
860.  			obj->otyp != SPE_BOOK_OF_THE_DEAD) {
861.  		    costly_cancel(obj);
862.  		    obj->otyp = SPE_BLANK_PAPER;
863.  		}
864.  		break;
865.  	      case POTION_CLASS:
866.  		costly_cancel(obj);
867.  		if (obj->otyp == POT_SICKNESS ||
868.  		    obj->otyp == POT_SEE_INVISIBLE) {
869.  	    /* sickness is "biologically contaminated" fruit juice; cancel it
870.  	     * and it just becomes fruit juice... whereas see invisible
871.  	     * tastes like "enchanted" fruit juice, it similarly cancels.
872.  	     */
873.  		    obj->otyp = POT_FRUIT_JUICE;
874.  		} else {
875.  	            obj->otyp = POT_WATER;
876.  		    obj->odiluted = 0; /* same as any other water */
877.  		}
878.  		break;
879.  	    }
880.  	}
881.  	if (holy) costly_cancel(obj);
882.  	unbless(obj);
883.  	uncurse(obj);
884.  #ifdef INVISIBLE_OBJECTS
885.  	if (obj->oinvis) obj->oinvis = 0;
886.  #endif
887.  	return;
888.  }
889.  
890.  /* Remove a positive enchantment or charge from obj,
891.   * possibly carried by you or a monster
892.   */
893.  boolean
894.  drain_item(obj)
895.  register struct obj *obj;
896.  {
897.  	boolean u_ring;
898.  
899.  	/* Is this a charged/enchanted object? */
900.  	if (!obj || (!objects[obj->otyp].oc_charged &&
901.  			obj->oclass != WEAPON_CLASS &&
902.  			obj->oclass != ARMOR_CLASS && !is_weptool(obj)) ||
903.  			obj->spe <= 0)
904.  	    return (FALSE);
905.  	if (obj_resists(obj, 10, 90))
906.  	    return (FALSE);
907.  
908.  	/* Charge for the cost of the object */
909.  	costly_cancel(obj);	/* The term "cancel" is okay for now */
910.  
911.  	/* Drain the object and any implied effects */
912.  	obj->spe--;
913.  	u_ring = (obj == uleft) || (obj == uright);
914.  	switch(obj->otyp) {
915.  	case RIN_GAIN_STRENGTH:
916.  	    if ((obj->owornmask & W_RING) && u_ring) {
917.  	    	ABON(A_STR)--;
918.  	    	flags.botl = 1;
919.  	    }
920.  	    break;
921.  	case RIN_GAIN_CONSTITUTION:
922.  	    if ((obj->owornmask & W_RING) && u_ring) {
923.  	    	ABON(A_CON)--;
924.  	    	flags.botl = 1;
925.  	    }
926.  	    break;
927.  	case RIN_ADORNMENT:
928.  	    if ((obj->owornmask & W_RING) && u_ring) {
929.  	    	ABON(A_CHA)--;
930.  	    	flags.botl = 1;
931.  	    }
932.  	    break;
933.  	case RIN_INCREASE_ACCURACY:
934.  	    if ((obj->owornmask & W_RING) && u_ring)
935.  	    	u.uhitinc--;
936.  	    break;
937.  	case RIN_INCREASE_DAMAGE:
938.  	    if ((obj->owornmask & W_RING) && u_ring)
939.  	    	u.udaminc--;
940.  	    break;
941.  	case HELM_OF_BRILLIANCE:
942.  	    if ((obj->owornmask & W_ARMH) && (obj == uarmh)) {
943.  	    	ABON(A_INT)--;
944.  	    	ABON(A_WIS)--;
945.  	    	flags.botl = 1;
946.  	    }
947.  	    break;
948.  	case GAUNTLETS_OF_DEXTERITY:
949.  	    if ((obj->owornmask & W_ARMG) && (obj == uarmg)) {
950.  	    	ABON(A_DEX)--;
951.  	    	flags.botl = 1;
952.  	    }
953.  	    break;
954.  	case RIN_PROTECTION:
955.  	    flags.botl = 1;
956.  	    break;
957.  	}
958.  	if (carried(obj)) update_inventory();
959.  	return (TRUE);
960.  }
961.  
962.  #endif /*OVLB*/
963.  #ifdef OVL0
964.  
965.  boolean
966.  obj_resists(obj, ochance, achance)
967.  struct obj *obj;
968.  int ochance, achance;	/* percent chance for ordinary objects, artifacts */
969.  {
970.  	if (obj->otyp == AMULET_OF_YENDOR ||
971.  	    obj->otyp == SPE_BOOK_OF_THE_DEAD ||
972.  	    obj->otyp == CANDELABRUM_OF_INVOCATION ||
973.  	    obj->otyp == BELL_OF_OPENING ||
974.  	    (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) {
975.  		return TRUE;
976.  	} else {
977.  		int chance = rn2(100);
978.  
979.  		return((boolean)(chance < (obj->oartifact ? achance : ochance)));
980.  	}
981.  }
982.  
983.  boolean
984.  obj_shudders(obj)
985.  struct obj *obj;
986.  {
987.  	int	zap_odds;
988.  
989.  	if (obj->oclass == WAND_CLASS)
990.  		zap_odds = 3;	/* half-life = 2 zaps */
991.  	else if (obj->cursed)
992.  		zap_odds = 3;	/* half-life = 2 zaps */
993.  	else if (obj->blessed)
994.  		zap_odds = 12;	/* half-life = 8 zaps */
995.  	else
996.  		zap_odds = 8;	/* half-life = 6 zaps */
997.  
998.  	/* adjust for "large" quantities of identical things */
999.  	if(obj->quan > 4L) zap_odds /= 2;
1000. 
1001. 	return((boolean)(! rn2(zap_odds)));
1002. }
1003. #endif /*OVL0*/
1004. #ifdef OVLB
1005. 
1006. /* Use up at least minwt number of things made of material mat.
1007.  * There's also a chance that other stuff will be used up.  Finally,
1008.  * there's a random factor here to keep from always using the stuff
1009.  * at the top of the pile.
1010.  */
1011. STATIC_OVL void
1012. polyuse(objhdr, mat, minwt)
1013.     struct obj *objhdr;
1014.     int mat, minwt;
1015. {
1016.     register struct obj *otmp, *otmp2;
1017. 
1018.     for(otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) {
1019. 	otmp2 = otmp->nexthere;
1020. 	if (otmp == uball || otmp == uchain) continue;
1021. 	if (obj_resists(otmp, 0, 0)) continue;	/* preserve unique objects */
1022. #ifdef MAIL
1023. 	if (otmp->otyp == SCR_MAIL) continue;
1024. #endif
1025. 
1026. 	if (((int) objects[otmp->otyp].oc_material == mat) ==
1027. 		(rn2(minwt + 1) != 0)) {
1028. 	    /* appropriately add damage to bill */
1029. 	    if (costly_spot(otmp->ox, otmp->oy)) {
1030. 		if (*u.ushops)
1031. 			addtobill(otmp, FALSE, FALSE, FALSE);
1032. 		else
1033. 			(void)stolen_value(otmp,
1034. 					   otmp->ox, otmp->oy, FALSE, FALSE);
1035. 	    }
1036. 	    if (otmp->quan < LARGEST_INT)
1037. 		minwt -= (int)otmp->quan;
1038. 	    else
1039. 		minwt = 0;
1040. 	    delobj(otmp);
1041. 	}
1042.     }
1043. }
1044. 
1045. /*
1046.  * Polymorph some of the stuff in this pile into a monster, preferably
1047.  * a golem of the kind okind.
1048.  */
1049. STATIC_OVL void
1050. create_polymon(obj, okind)
1051.     struct obj *obj;
1052.     int okind;
1053. {
1054. 	struct permonst *mdat = (struct permonst *)0;
1055. 	struct monst *mtmp;
1056. 	const char *material;
1057. 	int pm_index;
1058. 
1059. 	/* no golems if you zap only one object -- not enough stuff */
1060. 	if(!obj || (!obj->nexthere && obj->quan == 1L)) return;
1061. 
1062. 	/* some of these choices are arbitrary */
1063. 	switch(okind) {
1064. 	case IRON:
1065. 	case METAL:
1066. 	case MITHRIL:
1067. 	    pm_index = PM_IRON_GOLEM;
1068. 	    material = "metal ";
1069. 	    break;
1070. 	case COPPER:
1071. 	case SILVER:
1072. 	case PLATINUM:
1073. 	case GEMSTONE:
1074. 	case MINERAL:
1075. 	    pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM;
1076. 	    material = "lithic ";
1077. 	    break;
1078. 	case 0:
1079. 	case FLESH:
1080. 	    /* there is no flesh type, but all food is type 0, so we use it */
1081. 	    pm_index = PM_FLESH_GOLEM;
1082. 	    material = "organic ";
1083. 	    break;
1084. 	case WOOD:
1085. 	    pm_index = PM_WOOD_GOLEM;
1086. 	    material = "wood ";
1087. 	    break;
1088. 	case LEATHER:
1089. 	    pm_index = PM_LEATHER_GOLEM;
1090. 	    material = "leather ";
1091. 	    break;
1092. 	case CLOTH:
1093. 	    pm_index = PM_ROPE_GOLEM;
1094. 	    material = "cloth ";
1095. 	    break;
1096. 	case BONE:
1097. 	    pm_index = PM_SKELETON;     /* nearest thing to "bone golem" */
1098. 	    material = "bony ";
1099. 	    break;
1100. 	case GOLD:
1101. 	    pm_index = PM_GOLD_GOLEM;
1102. 	    material = "gold ";
1103. 	    break;
1104. 	case GLASS:
1105. 	    pm_index = PM_GLASS_GOLEM;
1106. 	    material = "glassy ";
1107. 	    break;
1108. 	case PAPER:
1109. 	    pm_index = PM_PAPER_GOLEM;
1110. 	    material = "paper ";
1111. 	    break;
1112. 	default:
1113. 	    /* if all else fails... */
1114. 	    pm_index = PM_STRAW_GOLEM;
1115. 	    material = "";
1116. 	    break;
1117. 	}
1118. 
1119. 	if (!(mvitals[pm_index].mvflags & G_GENOD))
1120. 		mdat = &mons[pm_index];
1121. 
1122. 	mtmp = makemon(mdat, obj->ox, obj->oy, NO_MM_FLAGS);
1123. 	polyuse(obj, okind, (int)mons[pm_index].cwt);
1124. 
1125. 	if(mtmp && cansee(mtmp->mx, mtmp->my)) {
1126. 	    pline("Some %sobjects meld, and %s arises from the pile!",
1127. 		  material, a_monnam(mtmp));
1128. 	}
1129. }
1130. 
1131. /* Assumes obj is on the floor. */
1132. void
1133. do_osshock(obj)
1134. struct obj *obj;
1135. {
1136. 	long i;
1137. 
1138. #ifdef MAIL
1139. 	if (obj->otyp == SCR_MAIL) return;
1140. #endif
1141. 	obj_zapped = TRUE;
1142. 
1143. 	if(poly_zapped < 0) {
1144. 	    /* some may metamorphosize */
1145. 	    for (i = obj->quan; i; i--)
1146. 		if (! rn2(Luck + 45)) {
1147. 		    poly_zapped = objects[obj->otyp].oc_material;
1148. 		    break;
1149. 		}
1150. 	}
1151. 
1152. 	/* if quan > 1 then some will survive intact */
1153. 	if (obj->quan > 1L) {
1154. 	    if (obj->quan > LARGEST_INT)
1155. 		obj = splitobj(obj, (long)rnd(30000));
1156. 	    else
1157. 		obj = splitobj(obj, (long)rnd((int)obj->quan - 1));
1158. 	}
1159. 
1160. 	/* appropriately add damage to bill */
1161. 	if (costly_spot(obj->ox, obj->oy)) {
1162. 		if (*u.ushops)
1163. 			addtobill(obj, FALSE, FALSE, FALSE);
1164. 		else
1165. 			(void)stolen_value(obj,
1166. 					   obj->ox, obj->oy, FALSE, FALSE);
1167. 	}
1168. 
1169. 	/* zap the object */
1170. 	delobj(obj);
1171. }
1172. 
1173. /*
1174.  * Polymorph the object to the given object ID.  If the ID is STRANGE_OBJECT
1175.  * then pick random object from the source's class (this is the standard
1176.  * "polymorph" case).  If ID is set to a specific object, inhibit fusing
1177.  * n objects into 1.  This could have been added as a flag, but currently
1178.  * it is tied to not being the standard polymorph case. The new polymorphed
1179.  * object replaces obj in its link chains.  Return value is a pointer to
1180.  * the new object.
1181.  *
1182.  * This should be safe to call for an object anywhere.
1183.  */
1184. struct obj *
1185. poly_obj(obj, id)
1186. 	struct obj *obj;
1187. 	int id;
1188. {
1189. 	struct obj *otmp;
1190. 	xchar ox, oy;
1191. 	boolean can_merge = (id == STRANGE_OBJECT);
1192. 	int obj_location = obj->where;
1193. 
1194. 	if (id == STRANGE_OBJECT) { /* preserve symbol */
1195. 	    int try_limit = 3;
1196. 	    /* Try up to 3 times to make the magic-or-not status of
1197. 	       the new item be the same as it was for the old one. */
1198. 	    otmp = (struct obj *)0;
1199. 	    do {
1200. 		if (otmp) delobj(otmp);
1201. 		otmp = mkobj(obj->oclass, FALSE);
1202. 	    } while (--try_limit > 0 &&
1203. 		  objects[obj->otyp].oc_magic != objects[otmp->otyp].oc_magic);
1204. 	} else {
1205. 	    /* literally replace obj with this new thing */
1206. 	    otmp = mksobj(id, FALSE, FALSE);
1207. 	/* Actually more things use corpsenm but they polymorph differently */
1208. #define USES_CORPSENM(typ) ((typ)==CORPSE || (typ)==STATUE || (typ)==FIGURINE)
1209. 	    if (USES_CORPSENM(obj->otyp) && USES_CORPSENM(id))
1210. 		otmp->corpsenm = obj->corpsenm;
1211. #undef USES_CORPSENM
1212. 	}
1213. 
1214. 	/* preserve quantity */
1215. 	otmp->quan = obj->quan;
1216. 	/* preserve the shopkeepers (lack of) interest */
1217. 	otmp->no_charge = obj->no_charge;
1218. 	/* preserve inventory letter if in inventory */
1219. 	if (obj_location == OBJ_INVENT)
1220. 	    otmp->invlet = obj->invlet;
1221. #ifdef MAIL
1222. 	/* You can't send yourself 100 mail messages and then
1223. 	 * polymorph them into useful scrolls
1224. 	 */
1225. 	if (obj->otyp == SCR_MAIL) {
1226. 		otmp->otyp = SCR_MAIL;
1227. 		otmp->spe = 1;
1228. 	}
1229. #endif
1230. 
1231. 	/* avoid abusing eggs laid by you */
1232. 	if (obj->otyp == EGG && obj->spe) {
1233. 		int mnum, tryct = 100;
1234. 
1235. 		/* first, turn into a generic egg */
1236. 		if (otmp->otyp == EGG)
1237. 		    kill_egg(otmp);
1238. 		else {
1239. 		    otmp->otyp = EGG;
1240. 		    otmp->owt = weight(otmp);
1241. 		}
1242. 		otmp->corpsenm = NON_PM;
1243. 		otmp->spe = 0;
1244. 
1245. 		/* now change it into something layed by the hero */
1246. 		while (tryct--) {
1247. 		    mnum = can_be_hatched(random_monster());
1248. 		    if (mnum != NON_PM && !dead_species(mnum, TRUE)) {
1249. 			otmp->spe = 1;	/* layed by hero */
1250. 			otmp->corpsenm = mnum;
1251. 			attach_egg_hatch_timeout(otmp);
1252. 			break;
1253. 		    }
1254. 		}
1255. 	}
1256. 
1257. 	/* keep special fields (including charges on wands) */
1258. 	if (index(charged_objs, otmp->oclass)) otmp->spe = obj->spe;
1259. 	otmp->recharged = obj->recharged;
1260. 
1261. 	otmp->cursed = obj->cursed;
1262. 	otmp->blessed = obj->blessed;
1263. 	otmp->oeroded = obj->oeroded;
1264. 	otmp->oeroded2 = obj->oeroded2;
1265. 	if (!is_flammable(otmp) && !is_rustprone(otmp)) otmp->oeroded = 0;
1266. 	if (!is_corrodeable(otmp) && !is_rottable(otmp)) otmp->oeroded2 = 0;
1267. 	if (is_damageable(otmp))
1268. 	    otmp->oerodeproof = obj->oerodeproof;
1269. 
1270. 	/* Keep chest/box traps and poisoned ammo if we may */
1271. 	if (obj->otrapped && Is_box(otmp)) otmp->otrapped = TRUE;
1272. 
1273. 	if (obj->opoisoned && is_poisonable(otmp))
1274. 		otmp->opoisoned = TRUE;
1275. 
1276. 	if (id == STRANGE_OBJECT && obj->otyp == CORPSE) {
1277. 	/* turn crocodile corpses into shoes */
1278. 	    if (obj->corpsenm == PM_CROCODILE) {
1279. 		otmp->otyp = LOW_BOOTS;
1280. 		otmp->oclass = ARMOR_CLASS;
1281. 		otmp->spe = 0;
1282. 		otmp->oeroded = 0;
1283. 		otmp->oerodeproof = TRUE;
1284. 		otmp->quan = 1L;
1285. 		otmp->cursed = FALSE;
1286. 	    }
1287. 	}
1288. 
1289. 	/* no box contents --KAA */
1290. 	if (Has_contents(otmp)) delete_contents(otmp);
1291. 
1292. 	/* 'n' merged objects may be fused into 1 object */
1293. 	if (otmp->quan > 1L && (!objects[otmp->otyp].oc_merge ||
1294. 				(can_merge && otmp->quan > (long)rn2(1000))))
1295. 	    otmp->quan = 1L;
1296. 
1297. 	switch (otmp->oclass) {
1298. 
1299. 	case TOOL_CLASS:
1300. 	    if (otmp->otyp == MAGIC_LAMP) {
1301. 		otmp->otyp = OIL_LAMP;
1302. 		otmp->age = 1500L;	/* "best" oil lamp possible */
1303. 	    } else if (otmp->otyp == MAGIC_MARKER) {
1304. 		otmp->recharged = 1;	/* degraded quality */
1305. 	    }
1306. 	    /* don't care about the recharge count of other tools */
1307. 	    break;
1308. 
1309. 	case WAND_CLASS:
1310. 	    while (otmp->otyp == WAN_WISHING || otmp->otyp == WAN_POLYMORPH)
1311. 		otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING);
1312. 	    /* altering the object tends to degrade its quality
1313. 	       (analogous to spellbook `read count' handling) */
1314. 	    if ((int)otmp->recharged < rn2(7))	/* recharge_limit */
1315. 		otmp->recharged++;
1316. 	    break;
1317. 
1318. 	case POTION_CLASS:
1319. 	    while (otmp->otyp == POT_POLYMORPH)
1320. 		otmp->otyp = rnd_class(POT_GAIN_ABILITY, POT_WATER);
1321. 	    break;
1322. 
1323. 	case SPBOOK_CLASS:
1324. 	    while (otmp->otyp == SPE_POLYMORPH)
1325. 		otmp->otyp = rnd_class(SPE_DIG, SPE_BLANK_PAPER);
1326. 	    /* reduce spellbook abuse */
1327. 	    otmp->spestudied = obj->spestudied + 1;
1328. 	    break;
1329. 
1330. 	case GEM_CLASS:
1331. 	    if (otmp->quan > (long) rnd(4) &&
1332. 		    objects[obj->otyp].oc_material == MINERAL &&
1333. 		    objects[otmp->otyp].oc_material != MINERAL) {
1334. 		otmp->otyp = ROCK;	/* transmutation backfired */
1335. 		otmp->quan /= 2L;	/* some material has been lost */
1336. 	    }
1337. 	    break;
1338. 	}
1339. 
1340. 	/* update the weight */
1341. 	otmp->owt = weight(otmp);
1342. 
1343. 	/* for now, take off worn items being polymorphed */
1344. 	if (obj_location == OBJ_INVENT) {
1345. 	    if (id == STRANGE_OBJECT)
1346. 		remove_worn_item(obj);
1347. 	    else {
1348. 		/* This is called only for stone to flesh.  It's a lot simpler
1349. 		 * than it otherwise might be.  We don't need to check for
1350. 		 * special effects when putting them on (no meat objects have
1351. 		 * any) and only three worn masks are possible.
1352. 		 */
1353. 		otmp->owornmask = obj->owornmask;
1354. 		remove_worn_item(obj);
1355. 		setworn(otmp, otmp->owornmask);
1356. 		if (otmp->owornmask & LEFT_RING)
1357. 		    uleft = otmp;
1358. 		if (otmp->owornmask & RIGHT_RING)
1359. 		    uright = otmp;
1360. 		if (otmp->owornmask & W_WEP)
1361. 		    uwep = otmp;
1362. 		if (otmp->owornmask & W_SWAPWEP)
1363. 		    uswapwep = otmp;
1364. 		if (otmp->owornmask & W_QUIVER)
1365. 		    uquiver = otmp;
1366. 		goto no_unwear;
1367. 	    }
1368. 	}
1369. 
1370. 	/* preserve the mask in case being used by something else */
1371. 	otmp->owornmask = obj->owornmask;
1372. no_unwear:
1373. 
1374. 	if (obj_location == OBJ_FLOOR && obj->otyp == BOULDER &&
1375. 		otmp->otyp != BOULDER)
1376. 	    unblock_point(obj->ox, obj->oy);
1377. 
1378. 	/* ** we are now done adjusting the object ** */
1379. 
1380. 
1381. 	/* swap otmp for obj */
1382. 	replace_object(obj, otmp);
1383. 	if (obj_location == OBJ_INVENT) {
1384. 	    /*
1385. 	     * We may need to do extra adjustments for the hero if we're
1386. 	     * messing with the hero's inventory.  The following calls are
1387. 	     * equivalent to calling freeinv on obj and addinv on otmp,
1388. 	     * while doing an in-place swap of the actual objects.
1389. 	     */
1390. 	    freeinv_core(obj);
1391. 	    addinv_core1(otmp);
1392. 	    addinv_core2(otmp);
1393. 	}
1394. 
1395. 	if ((!carried(otmp) || obj->unpaid) &&
1396. 		get_obj_location(otmp, &ox, &oy, BURIED_TOO|CONTAINED_TOO) &&
1397. 		costly_spot(ox, oy)) {
1398. 	    register struct monst *shkp =
1399. 		shop_keeper(*in_rooms(ox, oy, SHOPBASE));
1400. 
1401. 	    if ((!obj->no_charge ||
1402. 		 (Has_contents(obj) &&
1403. 		    (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 0L)))
1404. 	       && inhishop(shkp)) {
1405. 		if(shkp->mpeaceful) {
1406. 		    if(*u.ushops && *in_rooms(u.ux, u.uy, 0) ==
1407. 			    *in_rooms(shkp->mx, shkp->my, 0) &&
1408. 			    !costly_spot(u.ux, u.uy))
1409. 			make_angry_shk(shkp, ox, oy);
1410. 		    else {
1411. 			pline("%s gets angry!", Monnam(shkp));
1412. 			hot_pursuit(shkp);
1413. 		    }
1414. 		} else Norep("%s is furious!", Monnam(shkp));
1415. 	    }
1416. 	}
1417. 	delobj(obj);
1418. 	return otmp;
1419. }
1420. 
1421. /*
1422.  * Object obj was hit by the effect of the wand/spell otmp.  Return
1423.  * non-zero if the wand/spell had any effect.
1424.  */
1425. int
1426. bhito(obj, otmp)
1427. struct obj *obj, *otmp;
1428. {
1429. 	int res = 1;	/* affected object by default */
1430. 
1431. 	if (obj->bypass) {
1432. 		/* The bypass bit is currently only used as follows:
1433. 		 *
1434. 		 * POLYMORPH - When a monster being polymorphed drops something
1435. 		 *             from its inventory as a result of the change.
1436. 		 *             If the items fall to the floor, they are not
1437. 		 *             subject to direct subsequent polymorphing
1438. 		 *             themselves on that same zap. This makes it
1439. 		 *             consistent with items that remain in the
1440. 		 *             monster's inventory. They are not polymorphed
1441. 		 *             either.
1442. 		 * UNDEAD_TURNING - When an undead creature gets killed via
1443. 		 *	       undead turning, prevent its corpse from being
1444. 		 *	       immediately revived by the same effect.
1445. 		 *
1446. 		 * The bypass bit on all objects is reset each turn, whenever
1447. 		 * flags.bypasses is set.
1448. 		 *
1449. 		 * We check the obj->bypass bit above AND flags.bypasses
1450. 		 * as a safeguard against any stray occurrence left in an obj
1451. 		 * struct someplace, although that should never happen.
1452. 		 */
1453. 		if (flags.bypasses)
1454. 			return 0;
1455. 		else {
1456. #ifdef DEBUG
1457. 			pline("%s for a moment.", Tobjnam(obj, "pulsate"));
1458. #endif
1459. 			obj->bypass = 0;
1460. 		}
1461. 	}
1462. 
1463. 	/*
1464. 	 * Some parts of this function expect the object to be on the floor
1465. 	 * obj->{ox,oy} to be valid.  The exception to this (so far) is
1466. 	 * for the STONE_TO_FLESH spell.
1467. 	 */
1468. 	if (!(obj->where == OBJ_FLOOR || otmp->otyp == SPE_STONE_TO_FLESH))
1469. 	    impossible("bhito: obj is not floor or Stone To Flesh spell");
1470. 
1471. 	if (obj == uball) {
1472. 		res = 0;
1473. 	} else if (obj == uchain) {
1474. 		if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) {
1475. 		    unpunish();
1476. 		    makeknown(otmp->otyp);
1477. 		} else
1478. 		    res = 0;
1479. 	} else
1480. 	switch(otmp->otyp) {
1481. 	case WAN_POLYMORPH:
1482. 	case SPE_POLYMORPH:
1483. 		if (obj->otyp == WAN_POLYMORPH ||
1484. 			obj->otyp == SPE_POLYMORPH ||
1485. 			obj->otyp == POT_POLYMORPH ||
1486. 			obj_resists(obj, 5, 95)) {
1487. 		    res = 0;
1488. 		    break;
1489. 		}
1490. 		/* KMH, conduct */
1491. 		u.uconduct.polypiles++;
1492. 		/* any saved lock context will be dangerously obsolete */
1493. 		if (Is_box(obj)) (void) boxlock(obj, otmp);
1494. 
1495. 		if (obj_shudders(obj)) {
1496. 		    if (cansee(obj->ox, obj->oy))
1497. 			makeknown(otmp->otyp);
1498. 		    do_osshock(obj);
1499. 		    break;
1500. 		}
1501. 		obj = poly_obj(obj, STRANGE_OBJECT);
1502. 		newsym(obj->ox,obj->oy);
1503. 		break;
1504. 	case WAN_PROBING:
1505. 		res = !obj->dknown;
1506. 		/* target object has now been "seen (up close)" */
1507. 		obj->dknown = 1;
1508. 		if (Is_container(obj) || obj->otyp == STATUE) {
1509. 		    if (!obj->cobj)
1510. 			pline("%s empty.", Tobjnam(obj, "are"));
1511. 		    else {
1512. 			struct obj *o;
1513. 			/* view contents (not recursively) */
1514. 			for (o = obj->cobj; o; o = o->nobj)
1515. 			    o->dknown = 1;	/* "seen", even if blind */
1516. 			(void) display_cinventory(obj);
1517. 		    }
1518. 		    res = 1;
1519. 		}
1520. 		if (res) makeknown(WAN_PROBING);
1521. 		break;
1522. 	case WAN_STRIKING:
1523. 	case SPE_FORCE_BOLT:
1524. 		if (obj->otyp == BOULDER)
1525. 			fracture_rock(obj);
1526. 		else if (obj->otyp == STATUE)
1527. 			(void) break_statue(obj);
1528. 		else {
1529. 			if (!flags.mon_moving)
1530. 			    (void)hero_breaks(obj, obj->ox, obj->oy, FALSE);
1531. 			else
1532. 			    (void)breaks(obj, obj->ox, obj->oy);
1533. 			res = 0;
1534. 		}
1535. 		/* BUG[?]: shouldn't this depend upon you seeing it happen? */
1536. 		makeknown(otmp->otyp);
1537. 		break;
1538. 	case WAN_CANCELLATION:
1539. 	case SPE_CANCELLATION:
1540. 		cancel_item(obj);
1541. #ifdef TEXTCOLOR
1542. 		newsym(obj->ox,obj->oy);	/* might change color */
1543. #endif
1544. 		break;
1545. 	case SPE_DRAIN_LIFE:
1546. 		(void) drain_item(obj);
1547. 		break;
1548. 	case WAN_TELEPORTATION:
1549. 	case SPE_TELEPORT_AWAY:
1550. 		rloco(obj);
1551. 		break;
1552. 	case WAN_MAKE_INVISIBLE:
1553. #ifdef INVISIBLE_OBJECTS
1554. 		obj->oinvis = TRUE;
1555. 		newsym(obj->ox,obj->oy);	/* make object disappear */
1556. #endif
1557. 		break;
1558. 	case WAN_UNDEAD_TURNING:
1559. 	case SPE_TURN_UNDEAD:
1560. 		if (obj->otyp == EGG)
1561. 			revive_egg(obj);
1562. 		else
1563. 			res = !!revive(obj);
1564. 		break;
1565. 	case WAN_OPENING:
1566. 	case SPE_KNOCK:
1567. 	case WAN_LOCKING:
1568. 	case SPE_WIZARD_LOCK:
1569. 		if(Is_box(obj))
1570. 			res = boxlock(obj, otmp);
1571. 		else
1572. 			res = 0;
1573. 		if (res /* && otmp->oclass == WAND_CLASS */)
1574. 			makeknown(otmp->otyp);
1575. 		break;
1576. 	case WAN_SLOW_MONSTER:		/* no effect on objects */
1577. 	case SPE_SLOW_MONSTER:
1578. 	case WAN_SPEED_MONSTER:
1579. 	case WAN_NOTHING:
1580. 	case SPE_HEALING:
1581. 	case SPE_EXTRA_HEALING:
1582. 		res = 0;
1583. 		break;
1584. 	case SPE_STONE_TO_FLESH:
1585. 		if (objects[obj->otyp].oc_material != MINERAL &&
1586. 			objects[obj->otyp].oc_material != GEMSTONE) {
1587. 		    res = 0;
1588. 		    break;
1589. 		}
1590. 		/* add more if stone objects are added.. */
1591. 		switch (objects[obj->otyp].oc_class) {
1592. 		    case ROCK_CLASS:	/* boulders and statues */
1593. 			if (obj->otyp == BOULDER) {
1594. 			    obj = poly_obj(obj, HUGE_CHUNK_OF_MEAT);
1595. 			    if (In_sokoban(&u.uz))
1596. 				change_luck(-1);	/* Sokoban guilt */
1597. 			    goto smell;
1598. 			} else if (obj->otyp == STATUE) {
1599. 			    xchar oox, ooy;
1600. 
1601. 			    (void) get_obj_location(obj, &oox, &ooy, 0);
1602. 			    if (!animate_statue(obj, oox, ooy,
1603. 						ANIMATE_SPELL, (int *)0)) {
1604. makecorpse:			if (mons[obj->corpsenm].geno &
1605. 							(G_NOCORPSE|G_UNIQ)) {
1606. 				    res = 0;
1607. 				    break;
1608. 				}
1609. 				/* Unlikely to get here since genociding
1610. 				 * monsters also sets the G_NOCORPSE flag.
1611. 				 */
1612. 				obj = poly_obj(obj, CORPSE);
1613. 				break;
1614. 			    }
1615. 			} else { /* new rock class object... */
1616. 			    /* impossible? */
1617. 			    res = 0;
1618. 			}
1619. 			break;
1620. 		    case TOOL_CLASS:	/* figurine */
1621. 		    {
1622. 			struct monst *mon;
1623. 			xchar oox, ooy;
1624. 
1625. 			if (obj->otyp != FIGURINE) {
1626. 			    res = 0;
1627. 			    break;
1628. 			}
1629. 			(void) get_obj_location(obj, &oox, &ooy, 0);
1630. 			mon = makemon(&mons[obj->corpsenm],
1631. 				      oox, ooy, NO_MM_FLAGS);
1632. 			if (mon) {
1633. 			    delobj(obj);
1634. 			    if (cansee(mon->mx, mon->my))
1635. 				pline_The("figurine animates!");
1636. 			    break;
1637. 			}
1638. 			goto makecorpse;
1639. 		    }
1640. 		    /* maybe add weird things to become? */
1641. 		    case RING_CLASS:	/* some of the rings are stone */
1642. 			obj = poly_obj(obj, MEAT_RING);
1643. 			goto smell;
1644. 		    case WAND_CLASS:	/* marble wand */
1645. 			obj = poly_obj(obj, MEAT_STICK);
1646. 			goto smell;
1647. 		    case GEM_CLASS:	/* rocks & gems */
1648. 			obj = poly_obj(obj, MEATBALL);
1649. smell:
1650. 			if (herbivorous(youmonst.data) &&
1651. 				!carnivorous(youmonst.data))
1652. 			    Norep("You smell the odor of meat.");
1653. 			else
1654. 			    Norep("You smell a delicious smell.");
1655. 			break;
1656. 		    default:
1657. 			res = 0;
1658. 			break;
1659. 		}
1660. 		newsym(obj->ox,obj->oy);
1661. 		break;
1662. 	default:
1663. 		impossible("What an interesting effect (%d)", otmp->otyp);
1664. 		break;
1665. 	}
1666. 	return res;
1667. }
1668. 
1669. /* returns nonzero if something was hit */
1670. int
1671. bhitpile(obj,fhito,tx,ty)
1672.     struct obj *obj;
1673.     int FDECL((*fhito), (OBJ_P,OBJ_P));
1674.     int tx, ty;
1675. {
1676.     int hitanything = 0;
1677.     register struct obj *otmp, *next_obj;
1678. 
1679.     if (obj->otyp == SPE_FORCE_BOLT || obj->otyp == WAN_STRIKING) {
1680. 	struct trap *t = t_at(tx, ty);
1681. 
1682. 	/* We can't settle for the default calling sequence of
1683. 	   bhito(otmp) -> break_statue(otmp) -> activate_statue_trap(ox,oy)
1684. 	   because that last call might end up operating on our `next_obj'
1685. 	   (below), rather than on the current object, if it happens to
1686. 	   encounter a statue which mustn't become animated. */
1687. 	if (t && t->ttyp == STATUE_TRAP)
1688. 	    (void) activate_statue_trap(t, tx, ty, TRUE);
1689.     }
1690. 
1691.     poly_zapped = -1;
1692.     for(otmp = level.objects[tx][ty]; otmp; otmp = next_obj) {
1693. 	/* Fix for polymorph bug, Tim Wright */
1694. 	next_obj = otmp->nexthere;
1695. 	hitanything += (*fhito)(otmp, obj);
1696.     }
1697.     if(poly_zapped >= 0)
1698. 	create_polymon(level.objects[tx][ty], poly_zapped);
1699. 
1700.     return hitanything;
1701. }
1702. #endif /*OVLB*/
1703. #ifdef OVL1
1704. 
1705. /*
1706.  * zappable - returns 1 if zap is available, 0 otherwise.
1707.  *	      it removes a charge from the wand if zappable.
1708.  * added by GAN 11/03/86
1709.  */
1710. int
1711. zappable(wand)
1712. register struct obj *wand;
1713. {
1714. 	if(wand->spe < 0 || (wand->spe == 0 && rn2(121)))
1715. 		return 0;
1716. 	if(wand->spe == 0)
1717. 		You("wrest one last charge from the worn-out wand.");
1718. 	wand->spe--;
1719. 	return 1;
1720. }
1721. 
1722. /*
1723.  * zapnodir - zaps a NODIR wand/spell.
1724.  * added by GAN 11/03/86
1725.  */
1726. void
1727. zapnodir(obj)
1728. register struct obj *obj;
1729. {
1730. 	boolean known = FALSE;
1731. 
1732. 	switch(obj->otyp) {
1733. 		case WAN_LIGHT:
1734. 		case SPE_LIGHT:
1735. 			litroom(TRUE,obj);
1736. 			if (!Blind) known = TRUE;
1737. 			break;
1738. 		case WAN_SECRET_DOOR_DETECTION:
1739. 		case SPE_DETECT_UNSEEN:
1740. 			if(!findit()) return;
1741. 			if (!Blind) known = TRUE;
1742. 			break;
1743. 		case WAN_CREATE_MONSTER:
1744. 			known = create_critters(rn2(23) ? 1 : rn1(7,2),
1745. 					(struct permonst *)0);
1746. 			break;
1747. 		case WAN_WISHING:
1748. 			known = TRUE;
1749. 			if(Luck + rn2(5) < 0) {
1750. 				pline("Unfortunately, nothing happens.");
1751. 				break;
1752. 			}
1753. 			makewish();
1754. 			break;
1755. 		case WAN_ENLIGHTENMENT:
1756. 			known = TRUE;
1757. 			You_feel("self-knowledgeable...");
1758. 			display_nhwindow(WIN_MESSAGE, FALSE);
1759. 			enlightenment(FALSE);
1760. 			pline_The("feeling subsides.");
1761. 			exercise(A_WIS, TRUE);
1762. 			break;
1763. 	}
1764. 	if (known && !objects[obj->otyp].oc_name_known) {
1765. 		makeknown(obj->otyp);
1766. 		more_experienced(0,10);
1767. 	}
1768. }
1769. #endif /*OVL1*/
1770. #ifdef OVL0
1771. 
1772. STATIC_OVL void
1773. backfire(otmp)
1774. struct obj *otmp;
1775. {
1776. 	otmp->in_use = TRUE;	/* in case losehp() is fatal */
1777. 	pline("%s suddenly explodes!", The(xname(otmp)));
1778. 	losehp(d(otmp->spe+2,6), "exploding wand", KILLED_BY_AN);
1779. 	useup(otmp);
1780. }
1781. 
1782. static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 };
1783. 
1784. int
1785. dozap()
1786. {
1787. 	register struct obj *obj;
1788. 	int	damage;
1789. 
1790. 	if(check_capacity((char *)0)) return(0);
1791. 	obj = getobj(zap_syms, "zap");
1792. 	if(!obj) return(0);
1793. 
1794. 	check_unpaid(obj);
1795. 
1796. 	/* zappable addition done by GAN 11/03/86 */
1797. 	if(!zappable(obj)) pline(nothing_happens);
1798. 	else if(obj->cursed && !rn2(100)) {
1799. 		backfire(obj);	/* the wand blows up in your face! */
1800. 		exercise(A_STR, FALSE);
1801. 		return(1);
1802. 	} else if(!(objects[obj->otyp].oc_dir == NODIR) && !getdir((char *)0)) {
1803. 		if (!Blind)
1804. 		    pline("%s glows and fades.", The(xname(obj)));
1805. 		/* make him pay for knowing !NODIR */
1806. 	} else if(!u.dx && !u.dy && !u.dz && !(objects[obj->otyp].oc_dir == NODIR)) {
1807. 	    if ((damage = zapyourself(obj, TRUE)) != 0) {
1808. 		char buf[BUFSZ];
1809. 		Sprintf(buf, "zapped %sself with a wand", uhim());
1810. 		losehp(damage, buf, NO_KILLER_PREFIX);
1811. 	    }
1812. 	} else {
1813. 
1814. 		/*	Are we having fun yet?
1815. 		 * weffects -> buzz(obj->otyp) -> zhitm (temple priest) ->
1816. 		 * attack -> hitum -> known_hitum -> ghod_hitsu ->
1817. 		 * buzz(AD_ELEC) -> destroy_item(WAND_CLASS) ->
1818. 		 * useup -> obfree -> dealloc_obj -> free(obj)
1819. 		 */
1820. 		current_wand = obj;
1821. 		weffects(obj);
1822. 		obj = current_wand;
1823. 		current_wand = 0;
1824. 	}
1825. 	if (obj && obj->spe < 0) {
1826. 	    pline("%s to dust.", Tobjnam(obj, "turn"));
1827. 	    useup(obj);
1828. 	}
1829. 	update_inventory();	/* maybe used a charge */
1830. 	return(1);
1831. }
1832. 
1833. int
1834. zapyourself(obj, ordinary)
1835. struct obj *obj;
1836. boolean ordinary;
1837. {
1838. 	int	damage = 0;
1839. 	char buf[BUFSZ];
1840. 
1841. 	switch(obj->otyp) {
1842. 		case WAN_STRIKING:
1843. 		    makeknown(WAN_STRIKING);
1844. 		case SPE_FORCE_BOLT:
1845. 		    if(Antimagic) {
1846. 			shieldeff(u.ux, u.uy);
1847. 			pline("Boing!");
1848. 		    } else {
1849. 			if (ordinary) {
1850. 			    You("bash yourself!");
1851. 			    damage = d(2,12);
1852. 			} else
1853. 			    damage = d(1 + obj->spe,6);
1854. 			exercise(A_STR, FALSE);
1855. 		    }
1856. 		    break;
1857. 
1858. 		case WAN_LIGHTNING:
1859. 		    makeknown(WAN_LIGHTNING);
1860. 		    if (!Shock_resistance) {
1861. 			You("shock yourself!");
1862. 			damage = d(12,6);
1863. 			exercise(A_CON, FALSE);
1864. 		    } else {
1865. 			shieldeff(u.ux, u.uy);
1866. 			You("zap yourself, but seem unharmed.");
1867. 			ugolemeffects(AD_ELEC, d(12,6));
1868. 		    }
1869. 		    destroy_item(WAND_CLASS, AD_ELEC);
1870. 		    destroy_item(RING_CLASS, AD_ELEC);
1871. 		    if (!resists_blnd(&youmonst)) {
1872. 			    You(are_blinded_by_the_flash);
1873. 			    make_blinded((long)rnd(100),FALSE);
1874. 			    if (!Blind) Your(vision_clears);
1875. 		    }
1876. 		    break;
1877. 
1878. 		case SPE_FIREBALL:
1879. 		    You("explode a fireball on top of yourself!");
1880. 		    explode(u.ux, u.uy, 11, d(6,6), WAND_CLASS, EXPL_FIERY);
1881. 		    break;
1882. 		case WAN_FIRE:
1883. 		    makeknown(WAN_FIRE);
1884. 		case FIRE_HORN:
1885. 		    if (Fire_resistance) {
1886. 			shieldeff(u.ux, u.uy);
1887. 			You_feel("rather warm.");
1888. 			ugolemeffects(AD_FIRE, d(12,6));
1889. 		    } else {
1890. 			pline("You've set yourself afire!");
1891. 			damage = d(12,6);
1892. 		    }
1893. 		    burn_away_slime();
1894. 		    (void) burnarmor(&youmonst);
1895. 		    destroy_item(SCROLL_CLASS, AD_FIRE);
1896. 		    destroy_item(POTION_CLASS, AD_FIRE);
1897. 		    destroy_item(SPBOOK_CLASS, AD_FIRE);
1898. 		    break;
1899. 
1900. 		case WAN_COLD:
1901. 		    makeknown(WAN_COLD);
1902. 		case SPE_CONE_OF_COLD:
1903. 		case FROST_HORN:
1904. 		    if (Cold_resistance) {
1905. 			shieldeff(u.ux, u.uy);
1906. 			You_feel("a little chill.");
1907. 			ugolemeffects(AD_COLD, d(12,6));
1908. 		    } else {
1909. 			You("imitate a popsicle!");
1910. 			damage = d(12,6);
1911. 		    }
1912. 		    destroy_item(POTION_CLASS, AD_COLD);
1913. 		    break;
1914. 
1915. 		case WAN_MAGIC_MISSILE:
1916. 		    makeknown(WAN_MAGIC_MISSILE);
1917. 		case SPE_MAGIC_MISSILE:
1918. 		    if(Antimagic) {
1919. 			shieldeff(u.ux, u.uy);
1920. 			pline_The("missiles bounce!");
1921. 		    } else {
1922. 			damage = d(4,6);
1923. 			pline("Idiot!  You've shot yourself!");
1924. 		    }
1925. 		    break;
1926. 
1927. 		case WAN_POLYMORPH:
1928. 		    if (!Unchanging)
1929. 		    	makeknown(WAN_POLYMORPH);
1930. 		case SPE_POLYMORPH:
1931. 		    if (!Unchanging)
1932. 		    	polyself(FALSE);
1933. 		    break;
1934. 
1935. 		case WAN_CANCELLATION:
1936. 		case SPE_CANCELLATION:
1937. 		    cancel_monst(&youmonst, obj, TRUE, FALSE, TRUE);
1938. 		    break;
1939. 
1940. 		case SPE_DRAIN_LIFE:
1941. 			if (!Drain_resistance) {
1942. 				losexp("life drainage");
1943. 				makeknown(obj->otyp);
1944. 			}
1945. 			damage = 0;	/* No additional damage */
1946. 			break;
1947. 
1948. 		case WAN_MAKE_INVISIBLE: {
1949. 		    /* have to test before changing HInvis but must change
1950. 		     * HInvis before doing newsym().
1951. 		     */
1952. 		    int msg = !Invis && !Blind && !BInvis;
1953. 
1954. 		    if (BInvis && uarmc->otyp == MUMMY_WRAPPING) {
1955. 			/* A mummy wrapping absorbs it and protects you */
1956. 		        You_feel("rather itchy under your %s.", xname(uarmc));
1957. 		        break;
1958. 		    }
1959. 		    if (ordinary || !rn2(10)) {	/* permanent */
1960. 			HInvis |= FROMOUTSIDE;
1961. 		    } else {			/* temporary */
1962. 		    	incr_itimeout(&HInvis, d(obj->spe, 250));
1963. 		    }
1964. 		    if (msg) {
1965. 			makeknown(WAN_MAKE_INVISIBLE);
1966. 			newsym(u.ux, u.uy);
1967. 			self_invis_message();
1968. 		    }
1969. 		    break;
1970. 		}
1971. 
1972. 		case WAN_SPEED_MONSTER:
1973. 		    if (!(HFast & INTRINSIC)) {
1974. 			if (!Fast)
1975. 			    You("speed up.");
1976. 			else
1977. 			    Your("quickness feels more natural.");
1978. 			makeknown(WAN_SPEED_MONSTER);
1979. 			exercise(A_DEX, TRUE);
1980. 		    }
1981. 		    HFast |= FROMOUTSIDE;
1982. 		    break;
1983. 
1984. 		case WAN_SLEEP:
1985. 		    makeknown(WAN_SLEEP);
1986. 		case SPE_SLEEP:
1987. 		    if(Sleep_resistance) {
1988. 			shieldeff(u.ux, u.uy);
1989. 			You("don't feel sleepy!");
1990. 		    } else {
1991. 			pline_The("sleep ray hits you!");
1992. 			fall_asleep(-rnd(50), TRUE);
1993. 		    }
1994. 		    break;
1995. 
1996. 		case WAN_SLOW_MONSTER:
1997. 		case SPE_SLOW_MONSTER:
1998. 		    if(HFast & (TIMEOUT | INTRINSIC)) {
1999. 			u_slow_down();
2000. 			makeknown(obj->otyp);
2001. 		    }
2002. 		    break;
2003. 
2004. 		case WAN_TELEPORTATION:
2005. 		case SPE_TELEPORT_AWAY:
2006. 		    tele();
2007. 		    break;
2008. 
2009. 		case WAN_DEATH:
2010. 		case SPE_FINGER_OF_DEATH:
2011. 		    if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
2012. 			pline((obj->otyp == WAN_DEATH) ?
2013. 			  "The wand shoots an apparently harmless beam at you."
2014. 			  : "You seem no deader than before.");
2015. 			break;
2016. 		    }
2017. 		    Sprintf(buf, "shot %sself with a death ray", uhim());
2018. 		    killer = buf;
2019. 		    killer_format = NO_KILLER_PREFIX;
2020. 		    You("irradiate yourself with pure energy!");
2021. 		    You("die.");
2022. 		    makeknown(obj->otyp);
2023. 			/* They might survive with an amulet of life saving */
2024. 		    done(DIED);
2025. 		    break;
2026. 		case WAN_UNDEAD_TURNING:
2027. 		    makeknown(WAN_UNDEAD_TURNING);
2028. 		case SPE_TURN_UNDEAD:
2029. 		    (void) unturn_dead(&youmonst);
2030. 		    if (is_undead(youmonst.data)) {
2031. 			You_feel("frightened and %sstunned.",
2032. 			     Stunned ? "even more " : "");
2033. 			make_stunned(HStun + rnd(30), FALSE);
2034. 		    } else
2035. 			You("shudder in dread.");
2036. 		    break;
2037. 		case SPE_HEALING:
2038. 		case SPE_EXTRA_HEALING:
2039. 		    healup(d(6, obj->otyp == SPE_EXTRA_HEALING ? 8 : 4),
2040. 			   0, FALSE, (obj->otyp == SPE_EXTRA_HEALING));
2041. 		    You_feel("%sbetter.",
2042. 			obj->otyp == SPE_EXTRA_HEALING ? "much " : "");
2043. 		    break;
2044. 		case WAN_LIGHT:	/* (broken wand) */
2045. 		 /* assert( !ordinary ); */
2046. 		    damage = d(obj->spe, 25);
2047. #ifdef TOURIST
2048. 		case EXPENSIVE_CAMERA:
2049. #endif
2050. 		    damage += rnd(25);
2051. 		    if (!resists_blnd(&youmonst)) {
2052. 			You(are_blinded_by_the_flash);
2053. 			make_blinded((long)damage, FALSE);
2054. 			makeknown(obj->otyp);
2055. 			if (!Blind) Your(vision_clears);
2056. 		    }
2057. 		    damage = 0;	/* reset */
2058. 		    break;
2059. 		case WAN_OPENING:
2060. 		    if (Punished) makeknown(WAN_OPENING);
2061. 		case SPE_KNOCK:
2062. 		    if (Punished) Your("chain quivers for a moment.");
2063. 		    break;
2064. 		case WAN_DIGGING:
2065. 		case SPE_DIG:
2066. 		case SPE_DETECT_UNSEEN:
2067. 		case WAN_NOTHING:
2068. 		case WAN_LOCKING:
2069. 		case SPE_WIZARD_LOCK:
2070. 		    break;
2071. 		case WAN_PROBING:
2072. 		    for (obj = invent; obj; obj = obj->nobj)
2073. 			obj->dknown = 1;
2074. 		    /* note: `obj' reused; doesn't point at wand anymore */
2075. 		    makeknown(WAN_PROBING);
2076. 		    ustatusline();
2077. 		    break;
2078. 		case SPE_STONE_TO_FLESH:
2079. 		    {
2080. 		    struct obj *otemp, *onext;
2081. 		    boolean didmerge;
2082. 
2083. 		    if (u.umonnum == PM_STONE_GOLEM)
2084. 			(void) polymon(PM_FLESH_GOLEM);
2085. 		    if (Stoned) fix_petrification();	/* saved! */
2086. 		    /* but at a cost.. */
2087. 		    for (otemp = invent; otemp; otemp = onext) {
2088. 			onext = otemp->nobj;
2089. 			(void) bhito(otemp, obj);
2090. 			}
2091. 		    /*
2092. 		     * It is possible that we can now merge some inventory.
2093. 		     * Do a higly paranoid merge.  Restart from the beginning
2094. 		     * until no merges.
2095. 		     */
2096. 		    do {
2097. 			didmerge = FALSE;
2098. 			for (otemp = invent; !didmerge && otemp; otemp = otemp->nobj)
2099. 			    for (onext = otemp->nobj; onext; onext = onext->nobj)
2100. 			    	if (merged(&otemp, &onext)) {
2101. 			    		didmerge = TRUE;
2102. 			    		break;
2103. 			    		}
2104. 		    } while (didmerge);
2105. 		    }
2106. 		    break;
2107. 		default: impossible("object %d used?",obj->otyp);
2108. 		    break;
2109. 	}
2110. 	return(damage);
2111. }
2112. 
2113. #ifdef STEED
2114. /* you've zapped a wand downwards while riding
2115.  * Return TRUE if the steed was hit by the wand.
2116.  * Return FALSE if the steed was not hit by the wand.
2117.  */
2118. STATIC_OVL boolean
2119. zap_steed(obj)
2120. struct obj *obj;	/* wand or spell */
2121. {
2122. 	int steedhit = FALSE;
2123. 	
2124. 	switch (obj->otyp) {
2125. 
2126. 	   /*
2127. 	    * Wands that are allowed to hit the steed
2128. 	    * Carefully test the results of any that are
2129. 	    * moved here from the bottom section.
2130. 	    */
2131. 		case WAN_PROBING:
2132. 		    probe_monster(u.usteed);
2133. 		    makeknown(WAN_PROBING);
2134. 		    steedhit = TRUE;
2135. 		    break;
2136. 		case WAN_TELEPORTATION:
2137. 		case SPE_TELEPORT_AWAY:
2138. 		    /* you go together */
2139. 		    tele();
2140. 		    if(Teleport_control || !couldsee(u.ux0, u.uy0) ||
2141. 			(distu(u.ux0, u.uy0) >= 16))
2142. 				makeknown(obj->otyp);
2143. 		    steedhit = TRUE;
2144. 		    break;
2145. 
2146. 		/* Default processing via bhitm() for these */
2147. 		case SPE_CURE_SICKNESS:
2148. 		case WAN_MAKE_INVISIBLE:
2149. 		case WAN_CANCELLATION:
2150. 		case SPE_CANCELLATION:
2151. 		case WAN_POLYMORPH:
2152. 		case SPE_POLYMORPH:
2153. 		case WAN_STRIKING:
2154. 		case SPE_FORCE_BOLT:
2155. 		case WAN_SLOW_MONSTER:
2156. 		case SPE_SLOW_MONSTER:
2157. 		case WAN_SPEED_MONSTER:
2158. 		case SPE_HEALING:
2159. 		case SPE_EXTRA_HEALING:
2160. 		case SPE_DRAIN_LIFE:
2161. 		case WAN_OPENING:
2162. 		case SPE_KNOCK:
2163. 		    (void) bhitm(u.usteed, obj);
2164. 		    steedhit = TRUE;
2165. 		    break;
2166. 
2167. 		default:
2168. 		    steedhit = FALSE;
2169. 		    break;
2170. 	}
2171. 	return steedhit;
2172. }
2173. #endif
2174. 
2175. #endif /*OVL0*/
2176. #ifdef OVL3
2177. 
2178. /*
2179.  * cancel a monster (possibly the hero).  inventory is cancelled only
2180.  * if the monster is zapping itself directly, since otherwise the
2181.  * effect is too strong.  currently non-hero monsters do not zap
2182.  * themselves with cancellation.
2183.  */
2184. void
2185. cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel)
2186. register struct monst	*mdef;
2187. register struct obj	*obj;
2188. boolean			youattack, allow_cancel_kill, self_cancel;
2189. {
2190. 	boolean	youdefend = (mdef == &youmonst);
2191. 	static const char writing_vanishes[] =
2192. 				"Some writing vanishes from %s head!";
2193. 	static const char your[] = "your";	/* should be extern */
2194. 
2195. 	if (youdefend ? (!youattack && Antimagic)
2196. 		      : resist(mdef, obj->oclass, 0, NOTELL))
2197. 		return;		/* resisted cancellation */
2198. 
2199. 	if (self_cancel) {	/* 1st cancel inventory */
2200. 	    struct obj *otmp;
2201. 
2202. 	    for (otmp = (youdefend ? invent : mdef->minvent);
2203. 			    otmp; otmp = otmp->nobj)
2204. 		cancel_item(otmp);
2205. 	    if (youdefend) {
2206. 		flags.botl = 1;	/* potential AC change */
2207. 		find_ac();
2208. 	    }
2209. 	}
2210. 
2211. 	/* now handle special cases */
2212. 	if (youdefend) {
2213. 	    if (Upolyd) {
2214. 		if ((u.umonnum == PM_CLAY_GOLEM) && !Blind)
2215. 		    pline(writing_vanishes, your);
2216. 		rehumanize();
2217. 	    }
2218. 	} else {
2219. 	    mdef->mcan = TRUE;
2220. 
2221. 	    if (is_were(mdef->data) && mdef->data->mlet != S_HUMAN)
2222. 		were_change(mdef);
2223. 
2224. 	    if (mdef->data == &mons[PM_CLAY_GOLEM]) {
2225. 		if (canseemon(mdef))
2226. 		    pline(writing_vanishes, s_suffix(mon_nam(mdef)));
2227. 
2228. 		if (allow_cancel_kill) {
2229. 		    if (youattack)
2230. 			killed(mdef);
2231. 		    else
2232. 			monkilled(mdef, "", AD_SPEL);
2233. 		}
2234. 	    }
2235. 	}
2236. }
2237. 
2238. /* you've zapped an immediate type wand up or down */
2239. STATIC_OVL boolean
2240. zap_updown(obj)
2241. struct obj *obj;	/* wand or spell */
2242. {
2243. 	boolean striking = FALSE, disclose = FALSE;
2244. 	int x, y, xx, yy, ptmp;
2245. 	struct obj *otmp;
2246. 	struct engr *e;
2247. 	struct trap *ttmp;
2248. 	char buf[BUFSZ];
2249. 
2250. 	/* some wands have special effects other than normal bhitpile */
2251. 	/* drawbridge might change <u.ux,u.uy> */
2252. 	x = xx = u.ux;	/* <x,y> is zap location */
2253. 	y = yy = u.uy;	/* <xx,yy> is drawbridge (portcullis) position */
2254. 	ttmp = t_at(x, y); /* trap if there is one */
2255. 
2256. 	switch (obj->otyp) {
2257. 	case WAN_PROBING:
2258. 	    ptmp = 0;
2259. 	    if (u.dz < 0) {
2260. 		You("probe towards the %s.", ceiling(x,y));
2261. 	    } else {
2262. 		ptmp += bhitpile(obj, bhito, x, y);
2263. 		You("probe beneath the %s.", surface(x,y));
2264. 		ptmp += display_binventory(x, y, TRUE);
2265. 	    }
2266. 	    if (!ptmp) Your("probe reveals nothing.");
2267. 	    return TRUE;	/* we've done our own bhitpile */
2268. 	case WAN_OPENING:
2269. 	case SPE_KNOCK:
2270. 	    /* up or down, but at closed portcullis only */
2271. 	    if (is_db_wall(x,y) && find_drawbridge(&xx, &yy)) {
2272. 		open_drawbridge(xx, yy);
2273. 		disclose = TRUE;
2274. 	    } else if (u.dz > 0 && (x == xdnstair && y == ydnstair) &&
2275. 			/* can't use the stairs down to quest level 2 until
2276. 			   leader "unlocks" them; give feedback if you try */
2277. 			on_level(&u.uz, &qstart_level) && !ok_to_quest()) {
2278. 		pline_The("stairs seem to ripple momentarily.");
2279. 		disclose = TRUE;
2280. 	    }
2281. 	    break;
2282. 	case WAN_STRIKING:
2283. 	case SPE_FORCE_BOLT:
2284. 	    striking = TRUE;
2285. 	    /*FALLTHRU*/
2286. 	case WAN_LOCKING:
2287. 	case SPE_WIZARD_LOCK:
2288. 	    /* down at open bridge or up or down at open portcullis */
2289. 	    if ((levl[x][y].typ == DRAWBRIDGE_DOWN) ? (u.dz > 0) :
2290. 			(is_drawbridge_wall(x,y) && !is_db_wall(x,y)) &&
2291. 		    find_drawbridge(&xx, &yy)) {
2292. 		if (!striking)
2293. 		    close_drawbridge(xx, yy);
2294. 		else
2295. 		    destroy_drawbridge(xx, yy);
2296. 		disclose = TRUE;
2297. 	    } else if (striking && u.dz < 0 && rn2(3) &&
2298. 			!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) &&
2299. 			!Underwater && !Is_qstart(&u.uz)) {
2300. 		/* similar to zap_dig() */
2301. 		pline("A rock is dislodged from the %s and falls on your %s.",
2302. 		      ceiling(x, y), body_part(HEAD));
2303. 		losehp(rnd((uarmh && is_metallic(uarmh)) ? 2 : 6),
2304. 		       "falling rock", KILLED_BY_AN);
2305. 		if ((otmp = mksobj_at(ROCK, x, y, FALSE, FALSE)) != 0) {
2306. 		    (void)xname(otmp);	/* set dknown, maybe bknown */
2307. 		    stackobj(otmp);
2308. 		}
2309. 		newsym(x, y);
2310. 	    } else if (!striking && ttmp && ttmp->ttyp == TRAPDOOR && u.dz > 0) {
2311. 		if (!Blind) {
2312. 			if (ttmp->tseen) {
2313. 				pline("A trap door beneath you closes up then vanishes.");
2314. 				disclose = TRUE;
2315. 			} else {
2316. 				You("see a swirl of %s beneath you.",
2317. 					is_ice(x,y) ? "frost" : "dust");
2318. 			}
2319. 		} else {
2320. 			You_hear("a twang followed by a thud.");
2321. 		}
2322. 		deltrap(ttmp);
2323. 		ttmp = (struct trap *)0;
2324. 		newsym(x, y);
2325. 	    }
2326. 	    break;
2327. 	case SPE_STONE_TO_FLESH:
2328. 	    if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) ||
2329. 		     Underwater || (Is_qstart(&u.uz) && u.dz < 0)) {
2330. 		pline(nothing_happens);
2331. 	    } else if (u.dz < 0) {	/* we should do more... */
2332. 		pline("Blood drips on your %s.", body_part(FACE));
2333. 	    } else if (u.dz > 0 && !OBJ_AT(u.ux, u.uy)) {
2334. 		/*
2335. 		Print this message only if there wasn't an engraving
2336. 		affected here.  If water or ice, act like waterlevel case.
2337. 		*/
2338. 		e = engr_at(u.ux, u.uy);
2339. 		if (!(e && e->engr_type == ENGRAVE)) {
2340. 		    if (is_pool(u.ux, u.uy) || is_ice(u.ux, u.uy))
2341. 			pline(nothing_happens);
2342. 		    else
2343. 			pline("Blood %ss %s your %s.",
2344. 			      is_lava(u.ux, u.uy) ? "boil" : "pool",
2345. 			      Levitation ? "beneath" : "at",
2346. 			      makeplural(body_part(FOOT)));
2347. 		}
2348. 	    }
2349. 	    break;
2350. 	default:
2351. 	    break;
2352. 	}
2353. 
2354. 	if (u.dz > 0) {
2355. 	    /* zapping downward */
2356. 	    (void) bhitpile(obj, bhito, x, y);
2357. 
2358. 	    /* subset of engraving effects; none sets `disclose' */
2359. 	    if ((e = engr_at(x, y)) != 0 && e->engr_type != HEADSTONE) {
2360. 		switch (obj->otyp) {
2361. 		case WAN_POLYMORPH:
2362. 		case SPE_POLYMORPH:
2363. 		    del_engr(e);
2364. 		    make_engr_at(x, y, random_engraving(buf), moves, (xchar)0);
2365. 		    break;
2366. 		case WAN_CANCELLATION:
2367. 		case SPE_CANCELLATION:
2368. 		case WAN_MAKE_INVISIBLE:
2369. 		    del_engr(e);
2370. 		    break;
2371. 		case WAN_TELEPORTATION:
2372. 		case SPE_TELEPORT_AWAY:
2373. 		    rloc_engr(e);
2374. 		    break;
2375. 		case SPE_STONE_TO_FLESH:
2376. 		    if (e->engr_type == ENGRAVE) {
2377. 			/* only affects things in stone */
2378. 			pline_The(Hallucination ?
2379. 			    "floor runs like butter!" :
2380. 			    "edges on the floor get smoother.");
2381. 			wipe_engr_at(x, y, d(2,4));
2382. 			}
2383. 		    break;
2384. 		case WAN_STRIKING:
2385. 		case SPE_FORCE_BOLT:
2386. 		    wipe_engr_at(x, y, d(2,4));
2387. 		    break;
2388. 		default:
2389. 		    break;
2390. 		}
2391. 	    }
2392. 	}
2393. 
2394. 	return disclose;
2395. }
2396. 
2397. #endif /*OVL3*/
2398. #ifdef OVLB
2399. 
2400. /* called for various wand and spell effects - M. Stephenson */
2401. void
2402. weffects(obj)
2403. register struct	obj	*obj;
2404. {
2405. 	int otyp = obj->otyp;
2406. 	boolean disclose = FALSE, was_unkn = !objects[otyp].oc_name_known;
2407. 
2408. 	exercise(A_WIS, TRUE);
2409. #ifdef STEED
2410. 	if (u.usteed && (objects[otyp].oc_dir != NODIR) &&
2411. 	    !u.dx && !u.dy && (u.dz > 0) && zap_steed(obj)) {
2412. 		disclose = TRUE;
2413. 	} else
2414. #endif
2415. 	if (objects[otyp].oc_dir == IMMEDIATE) {
2416. 	    obj_zapped = FALSE;
2417. 
2418. 	    if (u.uswallow) {
2419. 		(void) bhitm(u.ustuck, obj);
2420. 		/* [how about `bhitpile(u.ustuck->minvent)' effect?] */
2421. 	    } else if (u.dz) {
2422. 		disclose = zap_updown(obj);
2423. 	    } else {
2424. 		(void) bhit(u.dx,u.dy, rn1(8,6),ZAPPED_WAND, bhitm,bhito, obj);
2425. 	    }
2426. 	    /* give a clue if obj_zapped */
2427. 	    if (obj_zapped)
2428. 		You_feel("shuddering vibrations.");
2429. 
2430. 	} else if (objects[otyp].oc_dir == NODIR) {
2431. 	    zapnodir(obj);
2432. 
2433. 	} else {
2434. 	    /* neither immediate nor directionless */
2435. 
2436. 	    if (otyp == WAN_DIGGING || otyp == SPE_DIG)
2437. 		zap_dig();
2438. 	    else if (otyp >= SPE_MAGIC_MISSILE && otyp <= SPE_FINGER_OF_DEATH)
2439. 		buzz(otyp - SPE_MAGIC_MISSILE + 10,
2440. 		     u.ulevel / 2 + 1,
2441. 		     u.ux, u.uy, u.dx, u.dy);
2442. 	    else if (otyp >= WAN_MAGIC_MISSILE && otyp <= WAN_LIGHTNING)
2443. 		buzz(otyp - WAN_MAGIC_MISSILE,
2444. 		     (otyp == WAN_MAGIC_MISSILE) ? 2 : 6,
2445. 		     u.ux, u.uy, u.dx, u.dy);
2446. 	    else
2447. 		impossible("weffects: unexpected spell or wand");
2448. 	    disclose = TRUE;
2449. 	}
2450. 	if (disclose && was_unkn) {
2451. 	    makeknown(otyp);
2452. 	    more_experienced(0,10);
2453. 	}
2454. 	return;
2455. }
2456. #endif /*OVLB*/
2457. #ifdef OVL0
2458. 
2459. /*
2460.  * Generate the to damage bonus for a spell. Based on the hero's intelligence
2461.  */
2462. int
2463. spell_damage_bonus()
2464. {
2465.     int tmp, intell = ACURR(A_INT);
2466. 
2467.     /* Punish low intellegence before low level else low intellegence
2468.        gets punished only when high level */
2469.     if (intell < 10)
2470. 	tmp = -3;
2471.     else if (u.ulevel < 5)
2472. 	tmp = 0;
2473.     else if (intell < 14)
2474. 	tmp = 0;
2475.     else if (intell <= 18)
2476. 	tmp = 1;
2477.     else		/* helm of brilliance */
2478. 	tmp = 2;
2479. 
2480.     return tmp;
2481. }
2482. 
2483. /*
2484.  * Generate the to hit bonus for a spell.  Based on the hero's skill in
2485.  * spell class and dexterity.
2486.  */
2487. STATIC_OVL int
2488. spell_hit_bonus(skill)
2489. int skill;
2490. {
2491.     int hit_bon = 0;
2492.     int dex = ACURR(A_DEX);
2493. 
2494.     switch (P_SKILL(spell_skilltype(skill))) {
2495. 	case P_ISRESTRICTED:
2496. 	case P_UNSKILLED:   hit_bon = -4; break;
2497. 	case P_BASIC:       hit_bon =  0; break;
2498. 	case P_SKILLED:     hit_bon =  2; break;
2499. 	case P_EXPERT:      hit_bon =  3; break;
2500.     }
2501. 
2502.     if (dex < 4)
2503. 	hit_bon -= 3;
2504.     else if (dex < 6)
2505. 	hit_bon -= 2;
2506.     else if (dex < 8)
2507. 	hit_bon -= 1;
2508.     else if (dex < 14)
2509. 	hit_bon -= 0;		/* Will change when print stuff below removed */
2510.     else
2511. 	hit_bon += dex - 14; /* Even increment for dextrous heroes (see weapon.c abon) */
2512. 
2513.     return hit_bon;
2514. }
2515. 
2516. const char *
2517. exclam(force)
2518. register int force;
2519. {
2520. 	/* force == 0 occurs e.g. with sleep ray */
2521. 	/* note that large force is usual with wands so that !! would
2522. 		require information about hand/weapon/wand */
2523. 	return (const char *)((force < 0) ? "?" : (force <= 4) ? "." : "!");
2524. }
2525. 
2526. void
2527. hit(str,mtmp,force)
2528. register const char *str;
2529. register struct monst *mtmp;
2530. register const char *force;		/* usually either "." or "!" */
2531. {
2532. 	if((!cansee(bhitpos.x,bhitpos.y) && !canspotmon(mtmp))
2533. 	   || !flags.verbose)
2534. 	    pline("%s %s it.", The(str), vtense(str, "hit"));
2535. 	else pline("%s %s %s%s", The(str), vtense(str, "hit"),
2536. 		   mon_nam(mtmp), force);
2537. }
2538. 
2539. void
2540. miss(str,mtmp)
2541. register const char *str;
2542. register struct monst *mtmp;
2543. {
2544. 	pline("%s %s %s.", The(str), vtense(str, "miss"),
2545. 	      ((cansee(bhitpos.x,bhitpos.y) || canspotmon(mtmp))
2546. 	       && flags.verbose) ?
2547. 	      mon_nam(mtmp) : "it");
2548. }
2549. #endif /*OVL0*/
2550. #ifdef OVL1
2551. 
2552. /* return TRUE if obj_type can't pass through iron bars */
2553. static boolean
2554. hits_bars(obj)
2555. struct obj *obj;
2556. {
2557.     int obj_type = obj->otyp;
2558.     /*
2559.     There should be a _lot_ of things here..., but iron ball
2560.     started this change and boulders, chests, and boxes were added later...
2561.     Corpses and statues that are at least medium size are also screened.
2562.     */
2563.     if (obj_type == BOULDER || obj_type == HEAVY_IRON_BALL || obj_type == LARGE_BOX ||
2564. 	obj_type == CHEST   || obj_type == ICE_BOX ||
2565. 	((obj_type == CORPSE || obj_type == STATUE)
2566. 	  && mons[obj->corpsenm].msize >= MZ_MEDIUM))
2567. 	return TRUE;
2568.     return FALSE;
2569. }
2570. 
2571. /*
2572.  *  Called for the following distance effects:
2573.  *	when a weapon is thrown (weapon == THROWN_WEAPON)
2574.  *	when an object is kicked (KICKED_WEAPON)
2575.  *	when an IMMEDIATE wand is zapped (ZAPPED_WAND)
2576.  *	when a light beam is flashed (FLASHED_LIGHT)
2577.  *	when a mirror is applied (INVIS_BEAM)
2578.  *  A thrown/kicked object falls down at the end of its range or when a monster
2579.  *  is hit.  The variable 'bhitpos' is set to the final position of the weapon
2580.  *  thrown/zapped.  The ray of a wand may affect (by calling a provided
2581.  *  function) several objects and monsters on its path.  The return value
2582.  *  is the monster hit (weapon != ZAPPED_WAND), or a null monster pointer.
2583.  *
2584.  *  Check !u.uswallow before calling bhit().
2585.  *  This function reveals the absence of a remembered invisible monster in
2586.  *  necessary cases (throwing or kicking weapons).  The presence of a real
2587.  *  one is revealed for a weapon, but if not a weapon is left up to fhitm().
2588.  */
2589. struct monst *
2590. bhit(ddx,ddy,range,weapon,fhitm,fhito,obj)
2591. register int ddx,ddy,range;		/* direction and range */
2592. int weapon;				/* see values in hack.h */
2593. int FDECL((*fhitm), (MONST_P, OBJ_P)),	/* fns called when mon/obj hit */
2594.     FDECL((*fhito), (OBJ_P, OBJ_P));
2595. struct obj *obj;			/* object tossed/used */
2596. {
2597. 	register struct monst *mtmp;
2598. 	register uchar typ;
2599. 	register boolean shopdoor = FALSE;
2600. 
2601. 	if (weapon == KICKED_WEAPON) {
2602. 	    /* object starts one square in front of player */
2603. 	    bhitpos.x = u.ux + ddx;
2604. 	    bhitpos.y = u.uy + ddy;
2605. 	    range--;
2606. 	} else {
2607. 	    bhitpos.x = u.ux;
2608. 	    bhitpos.y = u.uy;
2609. 	}
2610. 
2611. 	if (weapon == FLASHED_LIGHT) {
2612. 	    tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam));
2613. 	} else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM)
2614. 	    tmp_at(DISP_FLASH, obj_to_glyph(obj));
2615. 
2616. 	while(range-- > 0) {
2617. 	    int x,y;
2618. 
2619. 	    bhitpos.x += ddx;
2620. 	    bhitpos.y += ddy;
2621. 	    x = bhitpos.x; y = bhitpos.y;
2622. 
2623. 	    if(!isok(x, y)) {
2624. 		bhitpos.x -= ddx;
2625. 		bhitpos.y -= ddy;
2626. 		break;
2627. 	    }
2628. 
2629. 	    if(is_pick(obj) && inside_shop(x, y) &&
2630. 					   (mtmp = shkcatch(obj, x, y))) {
2631. 		tmp_at(DISP_END, 0);
2632. 		return(mtmp);
2633. 	    }
2634. 
2635. 	    typ = levl[bhitpos.x][bhitpos.y].typ;
2636. 
2637. 	    /* iron bars will block anything big enough */
2638. 	    if ((weapon == THROWN_WEAPON || weapon == KICKED_WEAPON)
2639. 	    		 && typ == IRONBARS && hits_bars(obj)) {
2640. 		bhitpos.x -= ddx;
2641. 		bhitpos.y -= ddy;
2642. 		break;
2643. 	    }
2644. 
2645. 	    if (weapon == ZAPPED_WAND && find_drawbridge(&x,&y))
2646. 		switch (obj->otyp) {
2647. 		    case WAN_OPENING:
2648. 		    case SPE_KNOCK:
2649. 			if (is_db_wall(bhitpos.x, bhitpos.y)) {
2650. 			    if (cansee(x,y) || cansee(bhitpos.x,bhitpos.y))
2651. 				makeknown(obj->otyp);
2652. 			    open_drawbridge(x,y);
2653. 			}
2654. 			break;
2655. 		    case WAN_LOCKING:
2656. 		    case SPE_WIZARD_LOCK:
2657. 			if ((cansee(x,y) || cansee(bhitpos.x, bhitpos.y))
2658. 			    && levl[x][y].typ == DRAWBRIDGE_DOWN)
2659. 			    makeknown(obj->otyp);
2660. 			close_drawbridge(x,y);
2661. 			break;
2662. 		    case WAN_STRIKING:
2663. 		    case SPE_FORCE_BOLT:
2664. 			if (typ != DRAWBRIDGE_UP)
2665. 			    destroy_drawbridge(x,y);
2666. 			makeknown(obj->otyp);
2667. 			break;
2668. 		}
2669. 
2670. 	    if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
2671. 		notonhead = (bhitpos.x != mtmp->mx ||
2672. 			     bhitpos.y != mtmp->my);
2673. 		if (weapon != FLASHED_LIGHT) {
2674. 			if(weapon != ZAPPED_WAND) {
2675. 			    if(weapon != INVIS_BEAM) tmp_at(DISP_END, 0);
2676. 			    if (cansee(bhitpos.x,bhitpos.y) && !canspotmon(mtmp)) {
2677. 				if (weapon != INVIS_BEAM) {
2678. 				    map_invisible(bhitpos.x, bhitpos.y);
2679. 				    return(mtmp);
2680. 				}
2681. 			    } else
2682. 				return(mtmp);
2683. 			}
2684. 			if (weapon != INVIS_BEAM) {
2685. 			    (*fhitm)(mtmp, obj);
2686. 			    range -= 3;
2687. 			}
2688. 		} else {
2689. 		    /* FLASHED_LIGHT hitting invisible monster
2690. 		       should pass through instead of stop so
2691. 		       we call flash_hits_mon() directly rather
2692. 		       than returning mtmp back to caller. That
2693. 		       allows the flash to keep on going. Note
2694. 		       that we use mtmp->minvis not canspotmon()
2695. 		       because it makes no difference whether
2696. 		       the hero can see the monster or not.*/
2697. 		    if (mtmp->minvis) {
2698. 			obj->ox = u.ux,  obj->oy = u.uy;
2699. 			(void) flash_hits_mon(mtmp, obj);
2700. 		    } else {
2701. 			tmp_at(DISP_END, 0);
2702. 		    	return(mtmp); 	/* caller will call flash_hits_mon */
2703. 		    }
2704. 		}
2705. 	    } else {
2706. 		if (weapon == ZAPPED_WAND && obj->otyp == WAN_PROBING &&
2707. 		   glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) {
2708. 		    unmap_object(bhitpos.x, bhitpos.y);
2709. 		    newsym(x, y);
2710. 		}
2711. 	    }
2712. 	    if(fhito) {
2713. 		if(bhitpile(obj,fhito,bhitpos.x,bhitpos.y))
2714. 		    range--;
2715. 	    } else {
2716. boolean costly = shop_keeper(*in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) &&
2717. 				costly_spot(bhitpos.x, bhitpos.y);
2718. 
2719. 		if(weapon == KICKED_WEAPON &&
2720. 		      ((obj->oclass == GOLD_CLASS &&
2721. 			 OBJ_AT(bhitpos.x, bhitpos.y)) ||
2722. 		    ship_object(obj, bhitpos.x, bhitpos.y, costly))) {
2723. 			tmp_at(DISP_END, 0);
2724. 			return (struct monst *)0;
2725. 		}
2726. 	    }
2727. 	    if(weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) {
2728. 		switch (obj->otyp) {
2729. 		case WAN_OPENING:
2730. 		case WAN_LOCKING:
2731. 		case WAN_STRIKING:
2732. 		case SPE_KNOCK:
2733. 		case SPE_WIZARD_LOCK:
2734. 		case SPE_FORCE_BOLT:
2735. 		    if (doorlock(obj, bhitpos.x, bhitpos.y)) {
2736. 			if (cansee(bhitpos.x, bhitpos.y) ||
2737. 			    (obj->otyp == WAN_STRIKING))
2738. 			    makeknown(obj->otyp);
2739. 			if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
2740. 			    && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) {
2741. 			    shopdoor = TRUE;
2742. 			    add_damage(bhitpos.x, bhitpos.y, 400L);
2743. 			}
2744. 		    }
2745. 		    break;
2746. 		}
2747. 	    }
2748. 	    if(!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) {
2749. 		bhitpos.x -= ddx;
2750. 		bhitpos.y -= ddy;
2751. 		break;
2752. 	    }
2753. 	    if(weapon != ZAPPED_WAND && weapon != INVIS_BEAM) {
2754. 		/* 'I' present but no monster: erase */
2755. 		/* do this before the tmp_at() */
2756. 		if (glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)
2757. 			&& cansee(x, y)) {
2758. 		    unmap_object(bhitpos.x, bhitpos.y);
2759. 		    newsym(x, y);
2760. 		}
2761. 		tmp_at(bhitpos.x, bhitpos.y);
2762. 		delay_output();
2763. 		/* kicked objects fall in pools */
2764. 		if((weapon == KICKED_WEAPON) &&
2765. 		   (is_pool(bhitpos.x, bhitpos.y) ||
2766. 		   is_lava(bhitpos.x, bhitpos.y)))
2767. 		    break;
2768. #ifdef SINKS
2769. 		if(IS_SINK(typ) && weapon != FLASHED_LIGHT)
2770. 		    break;	/* physical objects fall onto sink */
2771. #endif
2772. 	    }
2773. 	}
2774. 
2775. 	if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) tmp_at(DISP_END, 0);
2776. 
2777. 	if(shopdoor)
2778. 	    pay_for_damage("destroy");
2779. 
2780. 	return (struct monst *)0;
2781. }
2782. 
2783. struct monst *
2784. boomhit(dx, dy)
2785. int dx, dy;
2786. {
2787. 	register int i, ct;
2788. 	int boom = S_boomleft;	/* showsym[] index  */
2789. 	struct monst *mtmp;
2790. 
2791. 	bhitpos.x = u.ux;
2792. 	bhitpos.y = u.uy;
2793. 
2794. 	for (i = 0; i < 8; i++) if (xdir[i] == dx && ydir[i] == dy) break;
2795. 	tmp_at(DISP_FLASH, cmap_to_glyph(boom));
2796. 	for (ct = 0; ct < 10; ct++) {
2797. 		if(i == 8) i = 0;
2798. 		boom = (boom == S_boomleft) ? S_boomright : S_boomleft;
2799. 		tmp_at(DISP_CHANGE, cmap_to_glyph(boom));/* change glyph */
2800. 		dx = xdir[i];
2801. 		dy = ydir[i];
2802. 		bhitpos.x += dx;
2803. 		bhitpos.y += dy;
2804. 		if(MON_AT(bhitpos.x, bhitpos.y)) {
2805. 			mtmp = m_at(bhitpos.x,bhitpos.y);
2806. 			m_respond(mtmp);
2807. 			tmp_at(DISP_END, 0);
2808. 			return(mtmp);
2809. 		}
2810. 		if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ) ||
2811. 		   closed_door(bhitpos.x, bhitpos.y)) {
2812. 			bhitpos.x -= dx;
2813. 			bhitpos.y -= dy;
2814. 			break;
2815. 		}
2816. 		if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
2817. 			if(Fumbling || rn2(20) >= ACURR(A_DEX)) {
2818. 				/* we hit ourselves */
2819. 				(void) thitu(10, rnd(10), (struct obj *)0,
2820. 					"boomerang");
2821. 				break;
2822. 			} else {	/* we catch it */
2823. 				tmp_at(DISP_END, 0);
2824. 				You("skillfully catch the boomerang.");
2825. 				return(&youmonst);
2826. 			}
2827. 		}
2828. 		tmp_at(bhitpos.x, bhitpos.y);
2829. 		delay_output();
2830. 		if(ct % 5 != 0) i++;
2831. #ifdef SINKS
2832. 		if(IS_SINK(levl[bhitpos.x][bhitpos.y].typ))
2833. 			break;	/* boomerang falls on sink */
2834. #endif
2835. 	}
2836. 	tmp_at(DISP_END, 0);	/* do not leave last symbol */
2837. 	return (struct monst *)0;
2838. }
2839. 
2840. STATIC_OVL int
2841. zhitm(mon, type, nd, ootmp)			/* returns damage to mon */
2842. register struct monst *mon;
2843. register int type, nd;
2844. struct obj **ootmp;	/* to return worn armor for caller to disintegrate */
2845. {
2846. 	register int tmp = 0;
2847. 	register int abstype = abs(type) % 10;
2848. 	boolean sho_shieldeff = FALSE;
2849. 	boolean spellcaster = is_hero_spell(type); /* maybe get a bonus! */
2850. 
2851. 	*ootmp = (struct obj *)0;
2852. 	switch(abstype) {
2853. 	case ZT_MAGIC_MISSILE:
2854. 		if (resists_magm(mon)) {
2855. 		    sho_shieldeff = TRUE;
2856. 		    break;
2857. 		}
2858. 		tmp = d(nd,6);
2859. 		if (spellcaster)
2860. 		    tmp += spell_damage_bonus();
2861. #ifdef WIZ_PATCH_DEBUG
2862. 		if (spellcaster)
2863. 		    pline("Damage = %d + %d", tmp-spell_damage_bonus(),
2864. 			spell_damage_bonus());
2865. #endif
2866. 		break;
2867. 	case ZT_FIRE:
2868. 		if (resists_fire(mon)) {
2869. 		    sho_shieldeff = TRUE;
2870. 		    break;
2871. 		}
2872. 		tmp = d(nd,6);
2873. 		if (resists_cold(mon)) tmp += 7;
2874. 		if (spellcaster)
2875. 		    tmp += spell_damage_bonus();
2876. #ifdef WIZ_PATCH_DEBUG
2877. 		if (spellcaster)
2878. 		    pline("Damage = %d + %d",tmp-spell_damage_bonus(),
2879. 			spell_damage_bonus());
2880. #endif
2881. 		if (burnarmor(mon)) {
2882. 		    if (!rn2(3)) (void)destroy_mitem(mon, POTION_CLASS, AD_FIRE);
2883. 		    if (!rn2(3)) (void)destroy_mitem(mon, SCROLL_CLASS, AD_FIRE);
2884. 		    if (!rn2(5)) (void)destroy_mitem(mon, SPBOOK_CLASS, AD_FIRE);
2885. 		}
2886. 		break;
2887. 	case ZT_COLD:
2888. 		if (resists_cold(mon)) {
2889. 		    sho_shieldeff = TRUE;
2890. 		    break;
2891. 		}
2892. 		tmp = d(nd,6);
2893. 		if (resists_fire(mon)) tmp += d(nd, 3);
2894. 		if (spellcaster)
2895. 		    tmp += spell_damage_bonus();
2896. #ifdef WIZ_PATCH_DEBUG
2897. 		if (spellcaster)
2898. 		    pline("Damage = %d + %d", tmp-spell_damage_bonus(),
2899. 			spell_damage_bonus());
2900. #endif
2901. 		if (!rn2(3)) (void)destroy_mitem(mon, POTION_CLASS, AD_COLD);
2902. 		break;
2903. 	case ZT_SLEEP:
2904. 		tmp = 0;
2905. 		(void)sleep_monst(mon, d(nd, 25),
2906. 				type == ZT_WAND(ZT_SLEEP) ? WAND_CLASS : '\0');
2907. 		break;
2908. 	case ZT_DEATH:		/* death/disintegration */
2909. 		if(abs(type) != ZT_BREATH(ZT_DEATH)) {	/* death */
2910. 		    if(mon->data == &mons[PM_DEATH]) {
2911. 			mon->mhpmax += mon->mhpmax/2;
2912. 			if (mon->mhpmax >= MAGIC_COOKIE)
2913. 			    mon->mhpmax = MAGIC_COOKIE - 1;
2914. 			mon->mhp = mon->mhpmax;
2915. 			tmp = 0;
2916. 			break;
2917. 		    }
2918. 		    if (nonliving(mon->data) || is_demon(mon->data) ||
2919. 			    resists_magm(mon)) {	/* similar to player */
2920. 			sho_shieldeff = TRUE;
2921. 			break;
2922. 		    }
2923. 		    type = -1; /* so they don't get saving throws */
2924. 		} else {
2925. 		    struct obj *otmp2;
2926. 
2927. 		    if (resists_disint(mon)) {
2928. 			sho_shieldeff = TRUE;
2929. 		    } else if (mon->misc_worn_check & W_ARMS) {
2930. 			/* destroy shield; victim survives */
2931. 			*ootmp = which_armor(mon, W_ARMS);
2932. 		    } else if (mon->misc_worn_check & W_ARM) {
2933. 			/* destroy body armor, also cloak if present */
2934. 			*ootmp = which_armor(mon, W_ARM);
2935. 			if ((otmp2 = which_armor(mon, W_ARMC)) != 0)
2936. 			    m_useup(mon, otmp2);
2937. 		    } else {
2938. 			/* no body armor, victim dies; destroy cloak
2939. 			   and shirt now in case target gets life-saved */
2940. 			tmp = MAGIC_COOKIE;
2941. 			if ((otmp2 = which_armor(mon, W_ARMC)) != 0)
2942. 			    m_useup(mon, otmp2);
2943. #ifdef TOURIST
2944. 			if ((otmp2 = which_armor(mon, W_ARMU)) != 0)
2945. 			    m_useup(mon, otmp2);
2946. #endif
2947. 		    }
2948. 		    type = -1;	/* no saving throw wanted */
2949. 		    break;	/* not ordinary damage */
2950. 		}
2951. 		tmp = mon->mhp+1;
2952. 		break;
2953. 	case ZT_LIGHTNING:
2954. 		if (resists_elec(mon)) {
2955. 		    sho_shieldeff = TRUE;
2956. 		    tmp = 0;
2957. 		    /* can still blind the monster */
2958. 		} else
2959. 		    tmp = d(nd,6);
2960. 		if (spellcaster)
2961. 		    tmp += spell_damage_bonus();
2962. #ifdef WIZ_PATCH_DEBUG
2963. 		if (spellcaster)
2964. 		    pline("Damage = %d + %d", tmp-spell_damage_bonus(),
2965. 			spell_damage_bonus());
2966. #endif
2967. 		if (!resists_blnd(mon) &&
2968. 				!(type > 0 && u.uswallow && mon == u.ustuck)) {
2969. 			register unsigned rnd_tmp = rnd(50);
2970. 			mon->mcansee = 0;
2971. 			if((mon->mblinded + rnd_tmp) > 127)
2972. 				mon->mblinded = 127;
2973. 			else mon->mblinded += rnd_tmp;
2974. 		}
2975. 		if (!rn2(3)) (void)destroy_mitem(mon, WAND_CLASS, AD_ELEC);
2976. 		/* not actually possible yet */
2977. 		if (!rn2(3)) (void)destroy_mitem(mon, RING_CLASS, AD_ELEC);
2978. 		break;
2979. 	case ZT_POISON_GAS:
2980. 		if (resists_poison(mon)) {
2981. 		    sho_shieldeff = TRUE;
2982. 		    break;
2983. 		}
2984. 		tmp = d(nd,6);
2985. 		break;
2986. 	case ZT_ACID:
2987. 		if (resists_acid(mon)) {
2988. 		    sho_shieldeff = TRUE;
2989. 		    break;
2990. 		}
2991. 		tmp = d(nd,6);
2992. 		if (!rn2(6)) erode_obj(MON_WEP(mon), TRUE, TRUE);
2993. 		if (!rn2(6)) erode_armor(mon, TRUE);
2994. 		break;
2995. 	}
2996. 	if (sho_shieldeff) shieldeff(mon->mx, mon->my);
2997. 	if (is_hero_spell(type) && (Role_if(PM_KNIGHT) && u.uhave.questart))
2998. 	    tmp *= 2;
2999. 	if (tmp > 0 && type >= 0 &&
3000. 		resist(mon, type < ZT_SPELL(0) ? WAND_CLASS : '\0', 0, NOTELL))
3001. 	    tmp /= 2;
3002. 	if (tmp < 0) tmp = 0;		/* don't allow negative damage */
3003. #ifdef WIZ_PATCH_DEBUG
3004. 	pline("zapped monster hp = %d (= %d - %d)", mon->mhp-tmp,mon->mhp,tmp);
3005. #endif
3006. 	mon->mhp -= tmp;
3007. 	return(tmp);
3008. }
3009. 
3010. STATIC_OVL void
3011. zhitu(type, nd, fltxt, sx, sy)
3012. int type, nd;
3013. const char *fltxt;
3014. xchar sx, sy;
3015. {
3016. 	int dam = 0;
3017. 
3018. 	switch (abs(type) % 10) {
3019. 	case ZT_MAGIC_MISSILE:
3020. 	    if (Antimagic) {
3021. 		shieldeff(sx, sy);
3022. 		pline_The("missiles bounce off!");
3023. 	    } else {
3024. 		dam = d(nd,6);
3025. 		exercise(A_STR, FALSE);
3026. 	    }
3027. 	    break;
3028. 	case ZT_FIRE:
3029. 	    if (Fire_resistance) {
3030. 		shieldeff(sx, sy);
3031. 		You("don't feel hot!");
3032. 		ugolemeffects(AD_FIRE, d(nd, 6));
3033. 	    } else {
3034. 		dam = d(nd, 6);
3035. 	    }
3036. 	    burn_away_slime();
3037. 	    if (burnarmor(&youmonst)) {	/* "body hit" */
3038. 		if (!rn2(3)) destroy_item(POTION_CLASS, AD_FIRE);
3039. 		if (!rn2(3)) destroy_item(SCROLL_CLASS, AD_FIRE);
3040. 		if (!rn2(5)) destroy_item(SPBOOK_CLASS, AD_FIRE);
3041. 	    }
3042. 	    break;
3043. 	case ZT_COLD:
3044. 	    if (Cold_resistance) {
3045. 		shieldeff(sx, sy);
3046. 		You("don't feel cold.");
3047. 		ugolemeffects(AD_COLD, d(nd, 6));
3048. 	    } else {
3049. 		dam = d(nd, 6);
3050. 	    }
3051. 	    if (!rn2(3)) destroy_item(POTION_CLASS, AD_COLD);
3052. 	    break;
3053. 	case ZT_SLEEP:
3054. 	    if (Sleep_resistance) {
3055. 		shieldeff(u.ux, u.uy);
3056. 		You("don't feel sleepy.");
3057. 	    } else {
3058. 		fall_asleep(-d(nd,25), TRUE); /* sleep ray */
3059. 	    }
3060. 	    break;
3061. 	case ZT_DEATH:
3062. 	    if (abs(type) == ZT_BREATH(ZT_DEATH)) {
3063. 		if (Disint_resistance) {
3064. 		    You("are not disintegrated.");
3065. 		    break;
3066. 		} else if (uarms) {
3067. 		    /* destroy shield; other possessions are safe */
3068. 		    (void) destroy_arm(uarms);
3069. 		    break;
3070. 		} else if (uarm) {
3071. 		    /* destroy suit; if present, cloak goes too */
3072. 		    if (uarmc) (void) destroy_arm(uarmc);
3073. 		    (void) destroy_arm(uarm);
3074. 		    break;
3075. 		}
3076. 		/* no shield or suit, you're dead; wipe out cloak
3077. 		   and/or shirt in case of life-saving or bones */
3078. 		if (uarmc) (void) destroy_arm(uarmc);
3079. #ifdef TOURIST
3080. 		if (uarmu) (void) destroy_arm(uarmu);
3081. #endif
3082. 	    } else if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
3083. 		shieldeff(sx, sy);
3084. 		You("seem unaffected.");
3085. 		break;
3086. 	    } else if (Antimagic) {
3087. 		shieldeff(sx, sy);
3088. 		You("aren't affected.");
3089. 		break;
3090. 	    }
3091. 	    killer_format = KILLED_BY_AN;
3092. 	    killer = fltxt;
3093. 	    /* when killed by disintegration breath, don't leave corpse */
3094. 	    u.ugrave_arise = (type == -ZT_BREATH(ZT_DEATH)) ? -3 : NON_PM;
3095. 	    done(DIED);
3096. 	    return; /* lifesaved */
3097. 	case ZT_LIGHTNING:
3098. 	    if (Shock_resistance) {
3099. 		shieldeff(sx, sy);
3100. 		You("aren't affected.");
3101. 		ugolemeffects(AD_ELEC, d(nd, 6));
3102. 	    } else {
3103. 		dam = d(nd, 6);
3104. 		exercise(A_CON, FALSE);
3105. 	    }
3106. 	    if (!rn2(3)) destroy_item(WAND_CLASS, AD_ELEC);
3107. 	    if (!rn2(3)) destroy_item(RING_CLASS, AD_ELEC);
3108. 	    break;
3109. 	case ZT_POISON_GAS:
3110. 	    poisoned("blast", A_DEX, "poisoned blast", 15);
3111. 	    break;
3112. 	case ZT_ACID:
3113. 	    if (Acid_resistance) {
3114. 		dam = 0;
3115. 	    } else {
3116. 		pline_The("acid burns!");
3117. 		dam = d(nd,6);
3118. 		exercise(A_STR, FALSE);
3119. 	    }
3120. 	    /* using two weapons at once makes both of them more vulnerable */
3121. 	    if (!rn2(u.twoweap ? 3 : 6)) erode_obj(uwep, TRUE, TRUE);
3122. 	    if (u.twoweap && !rn2(3)) erode_obj(uswapwep, TRUE, TRUE);
3123. 	    if (!rn2(6)) erode_armor(&youmonst, TRUE);
3124. 	    break;
3125. 	}
3126. 
3127. 	if (Half_spell_damage && dam &&
3128. 	   type < 0 && (type > -20 || type < -29)) /* !Breath */
3129. 	    dam = (dam + 1) / 2;
3130. 	losehp(dam, fltxt, KILLED_BY_AN);
3131. 	return;
3132. }
3133. 
3134. #endif /*OVL1*/
3135. #ifdef OVLB
3136. 
3137. /*
3138.  * burn scrolls and spellbooks on floor at position x,y
3139.  * return the number of scrolls and spellbooks burned
3140.  */
3141. int
3142. burn_floor_paper(x, y, give_feedback, u_caused)
3143. int x, y;
3144. boolean give_feedback;	/* caller needs to decide about visibility checks */
3145. boolean u_caused;
3146. {
3147. 	struct obj *obj, *obj2;
3148. 	long i, scrquan, delquan;
3149. 	const char *what;
3150. 	int cnt = 0;
3151. 
3152. 	for (obj = level.objects[x][y]; obj; obj = obj2) {
3153. 	    obj2 = obj->nexthere;
3154. 	    if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) {
3155. 		if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL ||
3156. 			obj_resists(obj, 2, 100))
3157. 		    continue;
3158. 		scrquan = obj->quan;	/* number present */
3159. 		delquan = 0;		/* number to destroy */
3160. 		for (i = scrquan; i > 0; i--)
3161. 		    if (!rn2(3)) delquan++;
3162. 		if (delquan) {
3163. 		    /* save name before potential delobj() */
3164. 		    what = !give_feedback ? 0 : (x == u.ux && y == u.uy) ?
3165. 				xname(obj) : distant_name(obj, xname);
3166. 		    /* useupf(), which charges, only if hero caused damage */
3167. 		    if (u_caused) useupf(obj, delquan);
3168. 		    else if (delquan < scrquan) obj->quan -= delquan;
3169. 		    else delobj(obj);
3170. 		    cnt += delquan;
3171. 		    if (give_feedback) {
3172. 			if (delquan > 1)
3173. 			    pline("%ld %s burn.", delquan, what);
3174. 			else
3175. 			    pline("%s burns.", An(what));
3176. 		    }
3177. 		}
3178. 	    }
3179. 	}
3180. 	return cnt;
3181. }
3182. 
3183. /* will zap/spell/breath attack score a hit against armor class `ac'? */
3184. STATIC_OVL int
3185. zap_hit(ac, type)
3186. int ac;
3187. int type;	/* either hero cast spell type or 0 */
3188. {
3189.     int chance = rn2(20);
3190.     int spell_bonus = type ? spell_hit_bonus(type) : 0;
3191. 
3192.     /* small chance for naked target to avoid being hit */
3193.     if (!chance) return rnd(10) < ac+spell_bonus;
3194. 
3195.     /* very high armor protection does not achieve invulnerability */
3196.     ac = AC_VALUE(ac);
3197. 
3198.     return (3 - chance) < ac+spell_bonus;
3199. }
3200. 
3201. /* type ==   0 to   9 : you shooting a wand */
3202. /* type ==  10 to  19 : you casting a spell */
3203. /* type ==  20 to  29 : you breathing as a monster */
3204. /* type == -10 to -19 : monster casting spell */
3205. /* type == -20 to -29 : monster breathing at you */
3206. /* type == -30 to -39 : monster shooting a wand */
3207. /* called with dx = dy = 0 with vertical bolts */
3208. void
3209. buzz(type,nd,sx,sy,dx,dy)
3210. register int type, nd;
3211. register xchar sx,sy;
3212. register int dx,dy;
3213. {
3214.     int range, abstype = abs(type) % 10;
3215.     struct rm *lev;
3216.     register xchar lsx, lsy;
3217.     struct monst *mon;
3218.     coord save_bhitpos;
3219.     boolean shopdamage = FALSE;
3220.     register const char *fltxt;
3221.     struct obj *otmp;
3222.     int spell_type;
3223. 
3224.     /* if its a Hero Spell then get its SPE_TYPE */
3225.     spell_type = is_hero_spell(type) ? SPE_MAGIC_MISSILE + abstype : 0;
3226. 
3227.     fltxt = flash_types[(type <= -30) ? abstype : abs(type)];
3228.     if(u.uswallow) {
3229. 	register int tmp;
3230. 
3231. 	if(type < 0) return;
3232. 	tmp = zhitm(u.ustuck, type, nd, &otmp);
3233. 	if(!u.ustuck)	u.uswallow = 0;
3234. 	else	pline("%s rips into %s%s",
3235. 		      The(fltxt), mon_nam(u.ustuck), exclam(tmp));
3236. 	/* Using disintegration from the inside only makes a hole... */
3237. 	if (tmp == MAGIC_COOKIE)
3238. 	    u.ustuck->mhp = 0;
3239. 	if (u.ustuck->mhp < 1)
3240. 	    killed(u.ustuck);
3241. 	return;
3242.     }
3243.     if(type < 0) newsym(u.ux,u.uy);
3244.     range = rn1(7,7);
3245.     if(dx == 0 && dy == 0) range = 1;
3246.     save_bhitpos = bhitpos;
3247. 
3248.     tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype));
3249.     while(range-- > 0) {
3250. 	lsx = sx; sx += dx;
3251. 	lsy = sy; sy += dy;
3252. 	if(isok(sx,sy) && (lev = &levl[sx][sy])->typ) {
3253. 	    mon = m_at(sx, sy);
3254. 	    if(cansee(sx,sy)) {
3255. 		/* reveal/unreveal invisible monsters before tmp_at() */
3256. 		if (mon && !canspotmon(mon))
3257. 		    map_invisible(sx, sy);
3258. 		else if (!mon && glyph_is_invisible(levl[sx][sy].glyph)) {
3259. 		    unmap_object(sx, sy);
3260. 		    newsym(sx, sy);
3261. 		}
3262. 		if(ZAP_POS(lev->typ) || cansee(lsx,lsy))
3263. 		    tmp_at(sx,sy);
3264. 		delay_output(); /* wait a little */
3265. 	    }
3266. 	} else
3267. 	    goto make_bounce;
3268. 
3269. 	/* hit() and miss() need bhitpos to match the target */
3270. 	bhitpos.x = sx,  bhitpos.y = sy;
3271. 	/* Fireballs only damage when they explode */
3272. 	if (type != ZT_SPELL(ZT_FIRE))
3273. 	    range += zap_over_floor(sx, sy, type, &shopdamage);
3274. 
3275. 	if (mon) {
3276. 	    if (type == ZT_SPELL(ZT_FIRE)) break;
3277. 	    if (type >= 0) mon->mstrategy &= ~STRAT_WAITMASK;
3278. #ifdef STEED
3279. 	    buzzmonst:
3280. #endif
3281. 	    if (zap_hit(find_mac(mon), spell_type)) {
3282. 		if (mon_reflects(mon, (char *)0)) {
3283. 		    if(cansee(mon->mx,mon->my)) {
3284. 			hit(fltxt, mon, exclam(0));
3285. 			shieldeff(mon->mx, mon->my);
3286. 			(void) mon_reflects(mon, "But it reflects from %s %s!");
3287. 		    }
3288. 		    dx = -dx;
3289. 		    dy = -dy;
3290. 		} else {
3291. 		    boolean mon_could_move = mon->mcanmove;
3292. 		    int tmp = zhitm(mon, type, nd, &otmp);
3293. 
3294. 		    if (is_rider(mon->data) && abs(type) == ZT_BREATH(ZT_DEATH)) {
3295. 			if (canseemon(mon)) {
3296. 			    hit(fltxt, mon, ".");
3297. 			    pline("%s disintegrates.", Monnam(mon));
3298. 			    pline("%s body reintegrates before your %s!",
3299. 				  s_suffix(Monnam(mon)),
3300. 				  (eyecount(youmonst.data) == 1) ?
3301. 				  	body_part(EYE) : makeplural(body_part(EYE)));
3302. 			    pline("%s resurrects!", Monnam(mon));
3303. 			}
3304. 			mon->mhp = mon->mhpmax;
3305. 			break; /* Out of while loop */
3306. 		    }
3307. 		    if (mon->data == &mons[PM_DEATH] && abstype == ZT_DEATH) {
3308. 			if (canseemon(mon)) {
3309. 			    hit(fltxt, mon, ".");
3310. 			    pline("%s absorbs the deadly %s!", Monnam(mon),
3311. 				  type == ZT_BREATH(ZT_DEATH) ?
3312. 					"blast" : "ray");
3313. 			    pline("It seems even stronger than before.");
3314. 			}
3315. 			break; /* Out of while loop */
3316. 		    }
3317. 
3318. 		    if (tmp == MAGIC_COOKIE) { /* disintegration */
3319. 			struct obj *otmp2, *m_amulet = mlifesaver(mon);
3320. 
3321. 			if (canseemon(mon)) {
3322. 			    if (!m_amulet)
3323. 				pline("%s is disintegrated!", Monnam(mon));
3324. 			    else
3325. 				hit(fltxt, mon, "!");
3326. 			}
3327. #ifndef GOLDOBJ
3328. 			mon->mgold = 0L;
3329. #endif
3330. 
3331. /* note: worn amulet of life saving must be preserved in order to operate */
3332. #define oresist_disintegration(obj) \
3333. 		(objects[obj->otyp].oc_oprop == DISINT_RES || \
3334. 		 obj_resists(obj, 5, 50) || is_quest_artifact(obj) || \
3335. 		 obj == m_amulet)
3336. 
3337. 			for (otmp = mon->minvent; otmp; otmp = otmp2) {
3338. 			    otmp2 = otmp->nobj;
3339. 			    if (!oresist_disintegration(otmp)) {
3340. 				obj_extract_self(otmp);
3341. 				obfree(otmp, (struct obj *)0);
3342. 			    }
3343. 			}
3344. 
3345. 			if (type < 0)
3346. 			    monkilled(mon, (char *)0, -AD_RBRE);
3347. 			else
3348. 			    xkilled(mon, 2);
3349. 		    } else if(mon->mhp < 1) {
3350. 			if(type < 0)
3351. 			    monkilled(mon, fltxt, AD_RBRE);
3352. 			else
3353. 			    killed(mon);
3354. 		    } else {
3355. 			if (!otmp) {
3356. 			    /* normal non-fatal hit */
3357. 			    hit(fltxt, mon, exclam(tmp));
3358. 			} else {
3359. 			    /* some armor was destroyed; no damage done */
3360. 			    if (canseemon(mon))
3361. 				pline("%s %s is disintegrated!",
3362. 				      s_suffix(Monnam(mon)),
3363. 				      distant_name(otmp, xname));
3364. 			    m_useup(mon, otmp);
3365. 			}
3366. 			if (mon_could_move && !mon->mcanmove)	/* ZT_SLEEP */
3367. 			    slept_monst(mon);
3368. 		    }
3369. 		}
3370. 		range -= 2;
3371. 	    } else {
3372. 		miss(fltxt,mon);
3373. 	    }
3374. 	} else if (sx == u.ux && sy == u.uy && range >= 0) {
3375. 	    nomul(0);
3376. #ifdef STEED
3377. 	    if (u.usteed && !rn2(3) && !mon_reflects(u.usteed, (char *)0)) {
3378. 		    mon = u.usteed;
3379. 		    goto buzzmonst;
3380. 	    } else
3381. #endif
3382. 	    if (zap_hit((int) u.uac, 0)) {
3383. 		range -= 2;
3384. 		pline("%s hits you!", The(fltxt));
3385. 		if (Reflecting) {
3386. 		    if (!Blind) {
3387. 		    	(void) ureflects("But %s reflects from your %s!", "it");
3388. 		    } else
3389. 			pline("For some reason you are not affected.");
3390. 		    dx = -dx;
3391. 		    dy = -dy;
3392. 		    shieldeff(sx, sy);
3393. 		} else {
3394. 		    zhitu(type, nd, fltxt, sx, sy);
3395. 		}
3396. 	    } else {
3397. 		pline("%s whizzes by you!", The(fltxt));
3398. 	    }
3399. 	    if (abstype == ZT_LIGHTNING && !resists_blnd(&youmonst)) {
3400. 		You(are_blinded_by_the_flash);
3401. 		make_blinded((long)d(nd,50),FALSE);
3402. 		if (!Blind) Your(vision_clears);
3403. 	    }
3404. 	    stop_occupation();
3405. 	    nomul(0);
3406. 	}
3407. 
3408. 	if(!ZAP_POS(lev->typ) || (closed_door(sx, sy) && (range >= 0))) {
3409. 	    int bounce;
3410. 	    uchar rmn;
3411. 
3412.  make_bounce:
3413. 	    if (type == ZT_SPELL(ZT_FIRE)) {
3414. 		sx = lsx;
3415. 		sy = lsy;
3416. 		break; /* fireballs explode before the wall */
3417. 	    }
3418. 	    bounce = 0;
3419. 	    range--;
3420. 	    if(range && isok(lsx, lsy) && cansee(lsx,lsy))
3421. 		pline("%s bounces!", The(fltxt));
3422. 	    if(!dx || !dy || !rn2(20)) {
3423. 		dx = -dx;
3424. 		dy = -dy;
3425. 	    } else {
3426. 		if(isok(sx,lsy) && ZAP_POS(rmn = levl[sx][lsy].typ) &&
3427. 		   (IS_ROOM(rmn) || (isok(sx+dx,lsy) &&
3428. 				     ZAP_POS(levl[sx+dx][lsy].typ))))
3429. 		    bounce = 1;
3430. 		if(isok(lsx,sy) && ZAP_POS(rmn = levl[lsx][sy].typ) &&
3431. 		   (IS_ROOM(rmn) || (isok(lsx,sy+dy) &&
3432. 				     ZAP_POS(levl[lsx][sy+dy].typ))))
3433. 		    if(!bounce || rn2(2))
3434. 			bounce = 2;
3435. 
3436. 		switch(bounce) {
3437. 		case 0: dx = -dx; /* fall into... */
3438. 		case 1: dy = -dy; break;
3439. 		case 2: dx = -dx; break;
3440. 		}
3441. 		tmp_at(DISP_CHANGE, zapdir_to_glyph(dx,dy,abstype));
3442. 	    }
3443. 	}
3444.     }
3445.     tmp_at(DISP_END,0);
3446.     if (type == ZT_SPELL(ZT_FIRE))
3447. 	explode(sx, sy, type, d(12,6), 0, EXPL_FIERY);
3448.     if (shopdamage)
3449. 	pay_for_damage(abstype == ZT_FIRE ?  "burn away" :
3450. 		       abstype == ZT_COLD ?  "shatter" :
3451. 		       abstype == ZT_DEATH ? "disintegrate" : "destroy");
3452.     bhitpos = save_bhitpos;
3453. }
3454. #endif /*OVLB*/
3455. #ifdef OVL0
3456. 
3457. void
3458. melt_ice(x, y)
3459. xchar x, y;
3460. {
3461. 	struct rm *lev = &levl[x][y];
3462. 	struct obj *otmp;
3463. 
3464. 	if (lev->typ == DRAWBRIDGE_UP)
3465. 	    lev->drawbridgemask &= ~DB_ICE;	/* revert to DB_MOAT */
3466. 	else {	/* lev->typ == ICE */
3467. #ifdef STUPID
3468. 	    if (lev->icedpool == ICED_POOL) lev->typ = POOL;
3469. 	    else lev->typ = MOAT;
3470. #else
3471. 	    lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT);
3472. #endif
3473. 	    lev->icedpool = 0;
3474. 	}
3475. 	obj_ice_effects(x, y, FALSE);
3476. 	unearth_objs(x, y);
3477. 	if (Underwater) vision_recalc(1);
3478. 	newsym(x,y);
3479. 	if (cansee(x,y)) Norep("The ice crackles and melts.");
3480. 	if ((otmp = sobj_at(BOULDER, x, y)) != 0) {
3481. 	    if (cansee(x,y)) pline("%s settles...", An(xname(otmp)));
3482. 	    do {
3483. 		obj_extract_self(otmp);	/* boulder isn't being pushed */
3484. 		if (!boulder_hits_pool(otmp, x, y, FALSE))
3485. 		    impossible("melt_ice: no pool?");
3486. 		/* try again if there's another boulder and pool didn't fill */
3487. 	    } while (is_pool(x,y) && (otmp = sobj_at(BOULDER, x, y)) != 0);
3488. 	    newsym(x,y);
3489. 	}
3490. 	if (x == u.ux && y == u.uy)
3491. 		spoteffects(TRUE);	/* possibly drown, notice objects */
3492. }
3493. 
3494. /* Burn floor scrolls, evaporate pools, etc...  in a single square.  Used
3495.  * both for normal bolts of fire, cold, etc... and for fireballs.
3496.  * Sets shopdamage to TRUE if a shop door is destroyed, and returns the
3497.  * amount by which range is reduced (the latter is just ignored by fireballs)
3498.  */
3499. int
3500. zap_over_floor(x, y, type, shopdamage)
3501. xchar x, y;
3502. int type;
3503. boolean *shopdamage;
3504. {
3505. 	struct monst *mon;
3506. 	int abstype = abs(type) % 10;
3507. 	struct rm *lev = &levl[x][y];
3508. 	int rangemod = 0;
3509. 
3510. 	if(abstype == ZT_FIRE) {
3511. 	    struct trap *t = t_at(x, y);
3512. 
3513. 	    if (t && t->ttyp == WEB) {
3514. 		/* a burning web is too flimsy to notice if you can't see it */
3515. 		if (cansee(x,y)) Norep("A web bursts into flames!");
3516. 		(void) delfloortrap(t);
3517. 		if (cansee(x,y)) newsym(x,y);
3518. 	    }
3519. 	    if(is_ice(x, y)) {
3520. 		melt_ice(x, y);
3521. 	    } else if(is_pool(x,y)) {
3522. 		const char *msgtxt = "You hear hissing gas.";
3523. 		if(lev->typ != POOL) {	/* MOAT or DRAWBRIDGE_UP */
3524. 		    if (cansee(x,y)) msgtxt = "Some water evaporates.";
3525. 		} else {
3526. 		    register struct trap *ttmp;
3527. 
3528. 		    rangemod -= 3;
3529. 		    lev->typ = ROOM;
3530. 		    ttmp = maketrap(x, y, PIT);
3531. 		    if (ttmp) ttmp->tseen = 1;
3532. 		    if (cansee(x,y)) msgtxt = "The water evaporates.";
3533. 		}
3534. 		Norep(msgtxt);
3535. 		if (lev->typ == ROOM) newsym(x,y);
3536. 	    } else if(IS_FOUNTAIN(lev->typ)) {
3537. 		    if (cansee(x,y))
3538. 			pline("Steam billows from the fountain.");
3539. 		    rangemod -= 1;
3540. 		    dryup(x, y, type > 0);
3541. 	    }
3542. 	}
3543. 	else if(abstype == ZT_COLD && (is_pool(x,y) || is_lava(x,y))) {
3544. 		boolean lava = is_lava(x,y);
3545. 		boolean moat = (!lava && (lev->typ != POOL) &&
3546. 				(lev->typ != WATER) &&
3547. 				!Is_medusa_level(&u.uz) &&
3548. 				!Is_waterlevel(&u.uz));
3549. 
3550. 		if (lev->typ == WATER) {
3551. 		    /* For now, don't let WATER freeze. */
3552. 		    if (cansee(x,y))
3553. 			pline_The("water freezes for a moment.");
3554. 		    else
3555. 			You_hear("a soft crackling.");
3556. 		    rangemod -= 1000;	/* stop */
3557. 		} else {
3558. 		    rangemod -= 3;
3559. 		    if (lev->typ == DRAWBRIDGE_UP) {
3560. 			lev->drawbridgemask &= ~DB_UNDER;  /* clear lava */
3561. 			lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE);
3562. 		    } else {
3563. 			if (!lava)
3564. 			    lev->icedpool =
3565. 				    (lev->typ == POOL ? ICED_POOL : ICED_MOAT);
3566. 			lev->typ = (lava ? ROOM : ICE);
3567. 		    }
3568. 		    bury_objs(x,y);
3569. 		    if(cansee(x,y)) {
3570. 			if(moat)
3571. 				Norep("The moat is bridged with ice!");
3572. 			else if(lava)
3573. 				Norep("The lava cools and solidifies.");
3574. 			else
3575. 				Norep("The water freezes.");
3576. 			newsym(x,y);
3577. 		    } else if(flags.soundok && !lava)
3578. 			You_hear("a crackling sound.");
3579. 
3580. 		    if (x == u.ux && y == u.uy) {
3581. 			if (u.uinwater) {   /* not just `if (Underwater)' */
3582. 			    /* leave the no longer existent water */
3583. 			    u.uinwater = 0;
3584. 			    docrt();
3585. 			    vision_full_recalc = 1;
3586. 			} else if (u.utrap && u.utraptype == TT_LAVA) {
3587. 			    if (Passes_walls) {
3588. 				You("pass through the now-solid rock.");
3589. 			    } else {
3590. 				u.utrap = rn1(50,20);
3591. 				u.utraptype = TT_INFLOOR;
3592. 				You("are firmly stuck in the cooling rock.");
3593. 			    }
3594. 			}
3595. 		    } else if ((mon = m_at(x,y)) != 0) {
3596. 			/* probably ought to do some hefty damage to any
3597. 			   non-ice creature caught in freezing water;
3598. 			   at a minimum, eels are forced out of hiding */
3599. 			if (is_swimmer(mon->data) && mon->mundetected) {
3600. 			    mon->mundetected = 0;
3601. 			    newsym(x,y);
3602. 			}
3603. 		    }
3604. 		}
3605. 		obj_ice_effects(x,y,TRUE);
3606. 	}
3607. 	if(closed_door(x, y)) {
3608. 		int new_doormask = -1;
3609. 		const char *see_txt = 0, *sense_txt = 0, *hear_txt = 0;
3610. 		rangemod = -1000;
3611. 		switch(abstype) {
3612. 		case ZT_FIRE:
3613. 		    new_doormask = D_NODOOR;
3614. 		    see_txt = "The door is consumed in flames!";
3615. 		    sense_txt = "smell smoke.";
3616. 		    break;
3617. 		case ZT_COLD:
3618. 		    new_doormask = D_NODOOR;
3619. 		    see_txt = "The door freezes and shatters!";
3620. 		    sense_txt = "feel cold.";
3621. 		    break;
3622. 		case ZT_DEATH:
3623. 		    /* death spells/wands don't disintegrate */
3624. 		    if(abs(type) != ZT_BREATH(ZT_DEATH))
3625. 			goto def_case;
3626. 		    new_doormask = D_NODOOR;
3627. 		    see_txt = "The door disintegrates!";
3628. 		    hear_txt = "crashing wood.";
3629. 		    break;
3630. 		case ZT_LIGHTNING:
3631. 		    new_doormask = D_BROKEN;
3632. 		    see_txt = "The door splinters!";
3633. 		    hear_txt = "crackling.";
3634. 		    break;
3635. 		default:
3636. 		def_case:
3637. 		    if(cansee(x,y)) {
3638. 			pline_The("door absorbs %s %s!",
3639. 			      (type < 0) ? "the" : "your",
3640. 			      abs(type) < ZT_SPELL(0) ? "bolt" :
3641. 			      abs(type) < ZT_BREATH(0) ? "spell" :
3642. 			      "blast");
3643. 		    } else You_feel("vibrations.");
3644. 		    break;
3645. 		}
3646. 		if (new_doormask >= 0) {	/* door gets broken */
3647. 		    if (*in_rooms(x, y, SHOPBASE)) {
3648. 			if (type >= 0) {
3649. 			    add_damage(x, y, 400L);
3650. 			    *shopdamage = TRUE;
3651. 			} else	/* caused by monster */
3652. 			    add_damage(x, y, 0L);
3653. 		    }
3654. 		    lev->doormask = new_doormask;
3655. 		    unblock_point(x, y);	/* vision */
3656. 		    if (cansee(x, y)) {
3657. 			pline(see_txt);
3658. 			newsym(x, y);
3659. 		    } else if (sense_txt) {
3660. 			You(sense_txt);
3661. 		    } else if (hear_txt) {
3662. 			if (flags.soundok) You_hear(hear_txt);
3663. 		    }
3664. 		    if (picking_at(x, y)) {
3665. 			stop_occupation();
3666. 			reset_pick();
3667. 		    }
3668. 		}
3669. 	}
3670. 
3671. 	if(OBJ_AT(x, y) && abstype == ZT_FIRE)
3672. 		if (burn_floor_paper(x, y, FALSE, type > 0) && couldsee(x, y)) {
3673. 		    newsym(x,y);
3674. 		    You("%s of smoke.",
3675. 			!Blind ? "see a puff" : "smell a whiff");
3676. 		}
3677. 	if ((mon = m_at(x,y)) != 0) {
3678. 		/* Cannot use wakeup() which also angers the monster */
3679. 		mon->msleeping = 0;
3680. 		if(mon->m_ap_type) seemimic(mon);
3681. 		if(type >= 0) {
3682. 		    setmangry(mon);
3683. 		    if(mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE))
3684. 			ghod_hitsu(mon);
3685. 		    if(mon->isshk && !*u.ushops)
3686. 			hot_pursuit(mon);
3687. 		}
3688. 	}
3689. 	return rangemod;
3690. }
3691. 
3692. #endif /*OVL0*/
3693. #ifdef OVL3
3694. 
3695. void
3696. fracture_rock(obj)	/* fractured by pick-axe or wand of striking */
3697. register struct obj *obj;		   /* no texts here! */
3698. {
3699. 	/* A little Sokoban guilt... */
3700. 	if (obj->otyp == BOULDER && In_sokoban(&u.uz) && !flags.mon_moving)
3701. 	    change_luck(-1);
3702. 
3703. 	obj->otyp = ROCK;
3704. 	obj->quan = (long) rn1(60, 7);
3705. 	obj->owt = weight(obj);
3706. 	obj->oclass = GEM_CLASS;
3707. 	obj->known = FALSE;
3708. 	obj->onamelth = 0;		/* no names */
3709. 	obj->oxlth = 0;			/* no extra data */
3710. 	obj->oattached = OATTACHED_NOTHING;
3711. 	obj_extract_self(obj);		/* move rocks back on top */
3712. 	place_object(obj, obj->ox, obj->oy);
3713. 	if(!does_block(obj->ox,obj->oy,&levl[obj->ox][obj->oy]))
3714. 	    unblock_point(obj->ox,obj->oy);
3715. 	if(cansee(obj->ox,obj->oy))
3716. 	    newsym(obj->ox,obj->oy);
3717. }
3718. 
3719. /* handle statue hit by striking/force bolt/pick-axe */
3720. boolean
3721. break_statue(obj)
3722. register struct obj *obj;
3723. {
3724. 	/* [obj is assumed to be on floor, so no get_obj_location() needed] */
3725. 	struct trap *trap = t_at(obj->ox, obj->oy);
3726. 	struct obj *item;
3727. 
3728. 	if (trap && trap->ttyp == STATUE_TRAP &&
3729. 		activate_statue_trap(trap, obj->ox, obj->oy, TRUE))
3730. 	    return FALSE;
3731. 	/* drop any objects contained inside the statue */
3732. 	while ((item = obj->cobj) != 0) {
3733. 	    obj_extract_self(item);
3734. 	    place_object(item, obj->ox, obj->oy);
3735. 	}
3736. 	if (Role_if(PM_ARCHEOLOGIST) && !flags.mon_moving && obj->spe) {
3737. 	    You_feel("guilty about damaging such a historic statue.");
3738. 	    adjalign(-1);
3739. 	}
3740. 	obj->spe = 0;
3741. 	fracture_rock(obj);
3742. 	return TRUE;
3743. }
3744. 
3745. const char *destroy_strings[] = {
3746. 	"freezes and shatters", "freeze and shatter", "shattered potion",
3747. 	"boils and explodes", "boil and explode", "boiling potion",
3748. 	"catches fire and burns", "catch fire and burn", "burning scroll",
3749. 	"catches fire and burns", "catch fire and burn", "burning book",
3750. 	"turns to dust and vanishes", "turn to dust and vanish", "",
3751. 	"breaks apart and explodes", "break apart and explode", "exploding wand"
3752. };
3753. 
3754. void
3755. destroy_item(osym, dmgtyp)
3756. register int osym, dmgtyp;
3757. {
3758. 	register struct obj *obj, *obj2;
3759. 	register int dmg, xresist, skip;
3760. 	register long i, cnt, quan;
3761. 	register int dindx;
3762. 	const char *mult;
3763. 
3764. 	for(obj = invent; obj; obj = obj2) {
3765. 	    obj2 = obj->nobj;
3766. 	    if(obj->oclass != osym) continue; /* test only objs of type osym */
3767. 	    if(obj->oartifact) continue; /* don't destroy artifacts */
3768. 	    xresist = skip = 0;
3769. #ifdef GCC_WARN
3770. 	    dmg = dindx = 0;
3771. 	    quan = 0L;
3772. #endif
3773. 	    switch(dmgtyp) {
3774. 		case AD_COLD:
3775. 		    if(osym == POTION_CLASS && obj->otyp != POT_OIL) {
3776. 			quan = obj->quan;
3777. 			dindx = 0;
3778. 			dmg = rnd(4);
3779. 		    } else skip++;
3780. 		    break;
3781. 		case AD_FIRE:
3782. 		    xresist = (Fire_resistance && obj->oclass != POTION_CLASS);
3783. 
3784. 		    if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
3785. 			skip++;
3786. 		    if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
3787. 			skip++;
3788. 			if (!Blind)
3789. 			    pline("%s glows a strange %s, but remains intact.",
3790. 				The(xname(obj)), hcolor("dark red"));
3791. 		    }
3792. 		    quan = obj->quan;
3793. 		    switch(osym) {
3794. 			case POTION_CLASS:
3795. 			    dindx = 1;
3796. 			    dmg = rnd(6);
3797. 			    break;
3798. 			case SCROLL_CLASS:
3799. 			    dindx = 2;
3800. 			    dmg = 1;
3801. 			    break;
3802. 			case SPBOOK_CLASS:
3803. 			    dindx = 3;
3804. 			    dmg = 1;
3805. 			    break;
3806. 			default:
3807. 			    skip++;
3808. 			    break;
3809. 		    }
3810. 		    break;
3811. 		case AD_ELEC:
3812. 		    xresist = (Shock_resistance && obj->oclass != RING_CLASS);
3813. 		    quan = obj->quan;
3814. 		    switch(osym) {
3815. 			case RING_CLASS:
3816. 			    if(obj->otyp == RIN_SHOCK_RESISTANCE)
3817. 				    { skip++; break; }
3818. 			    dindx = 4;
3819. 			    dmg = 0;
3820. 			    break;
3821. 			case WAND_CLASS:
3822. 			    if(obj->otyp == WAN_LIGHTNING) { skip++; break; }
3823. #if 0
3824. 			    if (obj == current_wand) { skip++; break; }
3825. #endif
3826. 			    dindx = 5;
3827. 			    dmg = rnd(10);
3828. 			    break;
3829. 			default:
3830. 			    skip++;
3831. 			    break;
3832. 		    }
3833. 		    break;
3834. 		default:
3835. 		    skip++;
3836. 		    break;
3837. 	    }
3838. 	    if(!skip) {
3839. 		for(i = cnt = 0L; i < quan; i++)
3840. 		    if(!rn2(3)) cnt++;
3841. 
3842. 		if(!cnt) continue;
3843. 		if(cnt == quan)	mult = "Your";
3844. 		else	mult = (cnt == 1L) ? "One of your" : "Some of your";
3845. 		pline("%s %s %s!", mult, xname(obj),
3846. 			(cnt > 1L) ? destroy_strings[dindx*3 + 1]
3847. 				  : destroy_strings[dindx*3]);
3848. 		if(osym == POTION_CLASS && dmgtyp != AD_COLD) {
3849. 		    if (!breathless(youmonst.data) || haseyes(youmonst.data))
3850. 		    	potionbreathe(obj);
3851. 		}
3852. 		if (obj->owornmask) {
3853. 		    if (obj->owornmask & W_RING) /* ring being worn */
3854. 			Ring_gone(obj);
3855. 		    else
3856. 			setnotworn(obj);
3857. 		}
3858. 		if (obj == current_wand) current_wand = 0;	/* destroyed */
3859. 		for (i = 0; i < cnt; i++)
3860. 		    useup(obj);
3861. 		if(dmg) {
3862. 		    if(xresist)	You("aren't hurt!");
3863. 		    else {
3864. 			const char *how = destroy_strings[dindx * 3 + 2];
3865. 			boolean one = (cnt == 1L);
3866. 
3867. 			losehp(dmg, one ? how : (const char *)makeplural(how),
3868. 			       one ? KILLED_BY_AN : KILLED_BY);
3869. 			exercise(A_STR, FALSE);
3870. 		    }
3871. 		}
3872. 	    }
3873. 	}
3874. 	return;
3875. }
3876. 
3877. int
3878. destroy_mitem(mtmp, osym, dmgtyp)
3879. struct monst *mtmp;
3880. int osym, dmgtyp;
3881. {
3882. 	struct obj *obj, *obj2;
3883. 	int skip, tmp = 0;
3884. 	long i, cnt, quan;
3885. 	int dindx;
3886. 	boolean vis;
3887. 
3888. 	if (mtmp == &youmonst) {	/* this simplifies artifact_hit() */
3889. 	    destroy_item(osym, dmgtyp);
3890. 	    return 0;	/* arbitrary; value doesn't matter to artifact_hit() */
3891. 	}
3892. 
3893. 	vis = canseemon(mtmp);
3894. 	for(obj = mtmp->minvent; obj; obj = obj2) {
3895. 	    obj2 = obj->nobj;
3896. 	    if(obj->oclass != osym) continue; /* test only objs of type osym */
3897. 	    skip = 0;
3898. 	    quan = 0L;
3899. 	    dindx = 0;
3900. 
3901. 	    switch(dmgtyp) {
3902. 		case AD_COLD:
3903. 		    if(osym == POTION_CLASS && obj->otyp != POT_OIL) {
3904. 			quan = obj->quan;
3905. 			dindx = 0;
3906. 			tmp++;
3907. 		    } else skip++;
3908. 		    break;
3909. 		case AD_FIRE:
3910. 		    if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
3911. 			skip++;
3912. 		    if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
3913. 			skip++;
3914. 			if (vis)
3915. 			    pline("%s glows a strange %s, but remains intact.",
3916. 				The(distant_name(obj, xname)),
3917. 				hcolor("dark red"));
3918. 		    }
3919. 		    quan = obj->quan;
3920. 		    switch(osym) {
3921. 			case POTION_CLASS:
3922. 			    dindx = 1;
3923. 			    tmp++;
3924. 			    break;
3925. 			case SCROLL_CLASS:
3926. 			    dindx = 2;
3927. 			    tmp++;
3928. 			    break;
3929. 			case SPBOOK_CLASS:
3930. 			    dindx = 3;
3931. 			    tmp++;
3932. 			    break;
3933. 			default:
3934. 			    skip++;
3935. 			    break;
3936. 		    }
3937. 		    break;
3938. 		case AD_ELEC:
3939. 		    quan = obj->quan;
3940. 		    switch(osym) {
3941. 			case RING_CLASS:
3942. 			    if(obj->otyp == RIN_SHOCK_RESISTANCE)
3943. 				    { skip++; break; }
3944. 			    dindx = 4;
3945. 			    break;
3946. 			case WAND_CLASS:
3947. 			    if(obj->otyp == WAN_LIGHTNING) { skip++; break; }
3948. 			    dindx = 5;
3949. 			    tmp++;
3950. 			    break;
3951. 			default:
3952. 			    skip++;
3953. 			    break;
3954. 		    }
3955. 		    break;
3956. 		default:
3957. 		    skip++;
3958. 		    break;
3959. 	    }
3960. 	    if(!skip) {
3961. 		for(i = cnt = 0L; i < quan; i++)
3962. 		    if(!rn2(3)) cnt++;
3963. 
3964. 		if(!cnt) continue;
3965. 		if (vis) pline("%s %s %s!",
3966. 			s_suffix(Monnam(mtmp)), xname(obj),
3967. 			(cnt > 1L) ? destroy_strings[dindx*3 + 1]
3968. 				  : destroy_strings[dindx*3]);
3969. 		for(i = 0; i < cnt; i++) m_useup(mtmp, obj);
3970. 	    }
3971. 	}
3972. 	return(tmp);
3973. }
3974. 
3975. #endif /*OVL3*/
3976. #ifdef OVL2
3977. 
3978. int
3979. resist(mtmp, oclass, damage, tell)
3980. struct monst *mtmp;
3981. char oclass;
3982. int damage, tell;
3983. {
3984. 	int resisted;
3985. 	int alev, dlev;
3986. 
3987. 	/* attack level */
3988. 	switch (oclass) {
3989. 	    case WAND_CLASS:	alev = 12;	 break;
3990. 	    case TOOL_CLASS:	alev = 10;	 break;
3991. 	    case SCROLL_CLASS:	alev =  9;	 break;
3992. 	    case POTION_CLASS:	alev =  6;	 break;
3993. 	    case RING_CLASS:	alev =  5;	 break;
3994. 	    default:		alev = u.ulevel; break;		/* spell */
3995. 	}
3996. 	/* defense level */
3997. 	dlev = (int)mtmp->m_lev;
3998. 	if (dlev > 50) dlev = 50;
3999. 	else if (dlev < 1) dlev = is_mplayer(mtmp->data) ? u.ulevel : 1;
4000. 
4001. 	resisted = rn2(100 + alev - dlev) < mtmp->data->mr;
4002. 	if (resisted) {
4003. 	    if (tell) {
4004. 		shieldeff(mtmp->mx, mtmp->my);
4005. 		pline("%s resists!", Monnam(mtmp));
4006. 	    }
4007. 	    damage = (damage + 1) / 2;
4008. 	}
4009. 
4010. 	if (damage) {
4011. 	    mtmp->mhp -= damage;
4012. 	    if (mtmp->mhp < 1) {
4013. 		if(m_using) monkilled(mtmp, "", AD_RBRE);
4014. 		else killed(mtmp);
4015. 	    }
4016. 	}
4017. 	return(resisted);
4018. }
4019. 
4020. void
4021. makewish()
4022. {
4023. 	char buf[BUFSZ];
4024. 	struct obj *otmp, nothing;
4025. 	int tries = 0;
4026. 
4027. 	nothing = zeroobj;  /* lint suppression; only its address matters */
4028. 	if (flags.verbose) You("may wish for an object.");
4029. retry:
4030. 	getlin("For what do you wish?", buf);
4031. 	if(buf[0] == '\033') buf[0] = 0;
4032. 	/*
4033. 	 *  Note: if they wished for and got a non-object successfully,
4034. 	 *  otmp == &zeroobj.  That includes gold, or an artifact that
4035. 	 *  has been denied.  Wishing for "nothing" requires a separate
4036. 	 *  value to remain distinct.
4037. 	 */
4038. 	otmp = readobjnam(buf, &nothing, TRUE);
4039. 	if (!otmp) {
4040. 	    pline("Nothing fitting that description exists in the game.");
4041. 	    if (++tries < 5) goto retry;
4042. 	    pline(thats_enough_tries);
4043. 	    otmp = readobjnam((char *)0, (struct obj *)0, TRUE);
4044. 	    if (!otmp) return;	/* for safety; should never happen */
4045. 	} else if (otmp == &nothing) {
4046. 	    /* explicitly wished for "nothing", presumeably attempting
4047. 	       to retain wishless conduct */
4048. 	    return;
4049. 	}
4050. 
4051. 	/* KMH, conduct */
4052. 	u.uconduct.wishes++;
4053. 
4054. 	if (otmp != &zeroobj) {
4055. 	    /* place_object looses these */
4056. 	    boolean crysknife = (otmp->otyp == CRYSKNIFE);
4057. 	    int oerode = otmp->oerodeproof;
4058. 
4059. 	    /* in case touching this object turns out to be fatal */
4060. 	    place_object(otmp, u.ux, u.uy);
4061. 
4062. 	    if (otmp->oartifact && !touch_artifact(otmp,&youmonst)) {
4063. 		obj_extract_self(otmp);	/* remove it from the floor */
4064. 		dropy(otmp);		/* now put it back again :-) */
4065. 	    } else {
4066. 		obj_extract_self(otmp);
4067. 		if (crysknife) {
4068. 		    otmp->otyp = CRYSKNIFE;
4069. 		    otmp->oerodeproof = oerode;
4070. 		}
4071. 		/* The(aobjnam()) is safe since otmp is unidentified -dlc */
4072. 		(void) hold_another_object(otmp, u.uswallow ?
4073. 				       "Oops!  %s out of your reach!" :
4074. 				       Is_airlevel(&u.uz) || u.uinwater ?
4075. 				       "Oops!  %s away from you!" :
4076. 				       "Oops!  %s to the floor!",
4077. 				       The(aobjnam(otmp,
4078. 					     Is_airlevel(&u.uz) || u.uinwater ?
4079. 						   "slip" : "drop")),
4080. 				       (const char *)0);
4081. 	    }
4082. 	    u.ublesscnt += rn1(100,50);  /* the gods take notice */
4083. 	}
4084. }
4085. 
4086. #endif /*OVL2*/
4087. 
4088. /*zap.c*/