Source:NetHack 3.3.0/zap.c

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

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

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