Source:NetHack 3.4.3/src/zap.c

From NetHackWiki
(Redirected from Source:Ref/fracture rock)
Jump to: navigation, search

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

Top of file

  1. /*	SCCS Id: @(#)zap.c	3.4	2003/08/24	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

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

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

  1. #include "hack.h"
  2.  
  3. /* Disintegration rays have special treatment; corpses are never left.
  4. * But the routine which calculates the damage is separate from the routine
  5. * which kills the monster.  The damage routine returns this cookie to
  6. * indicate that the monster should be disintegrated.
  7. */
  8. #define MAGIC_COOKIE 1000
  9.  
  10. #ifdef OVLB
  11. static NEARDATA boolean obj_zapped;
  12. static NEARDATA int poly_zapped;
  13. #endif
  14.  
  15. extern boolean notonhead;	/* for long worms */
  16.  
  17. /* kludge to use mondied instead of killed */
  18. extern boolean m_using;
  19.  
  20. STATIC_DCL void FDECL(costly_cancel, (struct obj *));
  21. STATIC_DCL void FDECL(polyuse, (struct obj*, int, int));
  22. STATIC_DCL void FDECL(create_polymon, (struct obj *, int));
  23. STATIC_DCL boolean FDECL(zap_updown, (struct obj *));
  24. STATIC_DCL int FDECL(zhitm, (struct monst *,int,int,struct obj **));
  25. STATIC_DCL void FDECL(zhitu, (int,int,const char *,XCHAR_P,XCHAR_P));
  26. STATIC_DCL void FDECL(revive_egg, (struct obj *));
  27. #ifdef STEED
  28. STATIC_DCL boolean FDECL(zap_steed, (struct obj *));
  29. #endif
  30.  
  31. #ifdef OVLB
  32. STATIC_DCL int FDECL(zap_hit, (int,int));
  33. #endif
  34. #ifdef OVL0
  35. STATIC_DCL void FDECL(backfire, (struct obj *));
  36. STATIC_DCL int FDECL(spell_hit_bonus, (int));
  37. #endif
  38.  
  39. #define ZT_MAGIC_MISSILE	(AD_MAGM-1)
  40. #define ZT_FIRE			(AD_FIRE-1)
  41. #define ZT_COLD			(AD_COLD-1)
  42. #define ZT_SLEEP		(AD_SLEE-1)
  43. #define ZT_DEATH		(AD_DISN-1)	/* or disintegration */
  44. #define ZT_LIGHTNING		(AD_ELEC-1)
  45. #define ZT_POISON_GAS		(AD_DRST-1)
  46. #define ZT_ACID			(AD_ACID-1)
  47. /* 8 and 9 are currently unassigned */
  48.  
  49. #define ZT_WAND(x)		(x)
  50. #define ZT_SPELL(x)		(10+(x))
  51. #define ZT_BREATH(x)		(20+(x))
  52.  
  53. #define is_hero_spell(type)	((type) >= 10 && (type) < 20)
  54.  
  55. #ifndef OVLB
  56. STATIC_VAR const char are_blinded_by_the_flash[];
  57. extern const char * const flash_types[];
  58. #else
  59. STATIC_VAR const char are_blinded_by_the_flash[] = "are blinded by the flash!";
  60.  
  61. const char * const flash_types[] = {	/* also used in buzzmu(mcastu.c) */
  62. 	"magic missile",	/* Wands must be 0-9 */
  63. 	"bolt of fire",
  64. 	"bolt of cold",
  65. 	"sleep ray",
  66. 	"death ray",
  67. 	"bolt of lightning",
  68. 	"",
  69. 	"",
  70. 	"",
  71. 	"",
  72.  
  73. 	"magic missile",	/* Spell equivalents must be 10-19 */
  74. 	"fireball",
  75. 	"cone of cold",
  76. 	"sleep ray",
  77. 	"finger of death",
  78. 	"bolt of lightning",	/* There is no spell, used for retribution */
  79. 	"",
  80. 	"",
  81. 	"",
  82. 	"",
  83.  
  84. 	"blast of missiles",	/* Dragon breath equivalents 20-29*/
  85. 	"blast of fire",
  86. 	"blast of frost",
  87. 	"blast of sleep gas",
  88. 	"blast of disintegration",
  89. 	"blast of lightning",
  90. 	"blast of poison gas",
  91. 	"blast of acid",
  92. 	"",
  93. 	""
  94. };

bhitm

  1. /* Routines for IMMEDIATE wands and spells. */
  2. /* bhitm: monster mtmp was hit by the effect of wand or spell otmp */
  3. int
  4. bhitm(mtmp, otmp)
  5. struct monst *mtmp;
  6. struct obj *otmp;
  7. {
  8. 	boolean wake = TRUE;	/* Most 'zaps' should wake monster */
  9. 	boolean reveal_invis = FALSE;
  10. 	boolean dbldam = Role_if(PM_KNIGHT) && u.uhave.questart;
  11. 	int dmg, otyp = otmp->otyp;
  12. 	const char *zap_type_text = "spell";
  13. 	struct obj *obj;
  14. 	boolean disguised_mimic = (mtmp->data->mlet == S_MIMIC &&
  15. 				   mtmp->m_ap_type != M_AP_NOTHING);
  16.  
  17. 	if (u.uswallow && mtmp == u.ustuck)
  18. 	    reveal_invis = FALSE;
  19.  
  20. 	switch(otyp) {
  21. 	case WAN_STRIKING:
  22. 		zap_type_text = "wand";
  23. 		/* fall through */
  24. 	case SPE_FORCE_BOLT:
  25. 		reveal_invis = TRUE;
  26. 		if (resists_magm(mtmp)) {	/* match effect on player */
  27. 			shieldeff(mtmp->mx, mtmp->my);
  28. 			break;	/* skip makeknown */
  29. 		} else if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) {
  30. 			dmg = d(2,12);
  31. 			if(dbldam) dmg *= 2;
  32. 			if (otyp == SPE_FORCE_BOLT)
  33. 			    dmg += spell_damage_bonus();
  34. 			hit(zap_type_text, mtmp, exclam(dmg));
  35. 			(void) resist(mtmp, otmp->oclass, dmg, TELL);
  36. 		} else miss(zap_type_text, mtmp);
  37. 		makeknown(otyp);
  38. 		break;
  39. 	case WAN_SLOW_MONSTER:
  40. 	case SPE_SLOW_MONSTER:
  41. 		if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
  42. 			mon_adjust_speed(mtmp, -1, otmp);
  43. 			m_dowear(mtmp, FALSE); /* might want speed boots */
  44. 			if (u.uswallow && (mtmp == u.ustuck) &&
  45. 			    is_whirly(mtmp->data)) {
  46. 				You("disrupt %s!", mon_nam(mtmp));
  47. 				pline("A huge hole opens up...");
  48. 				expels(mtmp, mtmp->data, TRUE);
  49. 			}
  50. 		}
  51. 		break;
  52. 	case WAN_SPEED_MONSTER:
  53. 		if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
  54. 			mon_adjust_speed(mtmp, 1, otmp);
  55. 			m_dowear(mtmp, FALSE); /* might want speed boots */
  56. 		}
  57. 		break;
  58. 	case WAN_UNDEAD_TURNING:
  59. 	case SPE_TURN_UNDEAD:
  60. 		wake = FALSE;
  61. 		if (unturn_dead(mtmp)) wake = TRUE;
  62. 		if (is_undead(mtmp->data)) {
  63. 			reveal_invis = TRUE;
  64. 			wake = TRUE;
  65. 			dmg = rnd(8);
  66. 			if(dbldam) dmg *= 2;
  67. 			if (otyp == SPE_TURN_UNDEAD)
  68. 				dmg += spell_damage_bonus();
  69. 			flags.bypasses = TRUE;	/* for make_corpse() */
  70. 			if (!resist(mtmp, otmp->oclass, dmg, NOTELL)) {
  71. 			    if (mtmp->mhp > 0) monflee(mtmp, 0, FALSE, TRUE);
  72. 			}
  73. 		}
  74. 		break;
  75. 	case WAN_POLYMORPH:
  76. 	case SPE_POLYMORPH:
  77. 	case POT_POLYMORPH:
  78. 		if (resists_magm(mtmp)) {
  79. 		    /* magic resistance protects from polymorph traps, so make
  80. 		       it guard against involuntary polymorph attacks too... */
  81. 		    shieldeff(mtmp->mx, mtmp->my);
  82. 		} else if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
  83. 		    /* natural shapechangers aren't affected by system shock
  84. 		       (unless protection from shapechangers is interfering
  85. 		       with their metabolism...) */
  86. 		    if (mtmp->cham == CHAM_ORDINARY && !rn2(25)) {
  87. 			if (canseemon(mtmp)) {
  88. 			    pline("%s shudders!", Monnam(mtmp));
  89. 			    makeknown(otyp);
  90. 			}
  91. 			/* dropped inventory shouldn't be hit by this zap */
  92. 			for (obj = mtmp->minvent; obj; obj = obj->nobj)
  93. 			    bypass_obj(obj);
  94. 			/* flags.bypasses = TRUE; ## for make_corpse() */
  95. 			/* no corpse after system shock */
  96. 			xkilled(mtmp, 3);
  97. 		    } else if (newcham(mtmp, (struct permonst *)0,
  98. 				       (otyp != POT_POLYMORPH), FALSE)) {
  99. 			if (!Hallucination && canspotmon(mtmp))
  100. 			    makeknown(otyp);
  101. 		    }
  102. 		}
  103. 		break;
  104. 	case WAN_CANCELLATION:
  105. 	case SPE_CANCELLATION:
  106. 		(void) cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE);
  107. 		break;
  108. 	case WAN_TELEPORTATION:
  109. 	case SPE_TELEPORT_AWAY:
  110. 		reveal_invis = !u_teleport_mon(mtmp, TRUE);
  111. 		break;
  112. 	case WAN_MAKE_INVISIBLE:
  113. 	    {
  114. 		int oldinvis = mtmp->minvis;
  115. 		char nambuf[BUFSZ];
  116.  
  117. 		/* format monster's name before altering its visibility */
  118. 		Strcpy(nambuf, Monnam(mtmp));
  119. 		mon_set_minvis(mtmp);
  120. 		if (!oldinvis && knowninvisible(mtmp)) {
  121. 		    pline("%s turns transparent!", nambuf);
  122. 		    makeknown(otyp);
  123. 		}
  124. 		break;
  125. 	    }
  126. 	case WAN_NOTHING:
  127. 	case WAN_LOCKING:
  128. 	case SPE_WIZARD_LOCK:
  129. 		wake = FALSE;
  130. 		break;
  131. 	case WAN_PROBING:
  132. 		wake = FALSE;
  133. 		reveal_invis = TRUE;
  134. 		probe_monster(mtmp);
  135. 		makeknown(otyp);
  136. 		break;
  137. 	case WAN_OPENING:
  138. 	case SPE_KNOCK:
  139. 		wake = FALSE;	/* don't want immediate counterattack */
  140. 		if (u.uswallow && mtmp == u.ustuck) {
  141. 			if (is_animal(mtmp->data)) {
  142. 				if (Blind) You_feel("a sudden rush of air!");
  143. 				else pline("%s opens its mouth!", Monnam(mtmp));
  144. 			}
  145. 			expels(mtmp, mtmp->data, TRUE);
  146. #ifdef STEED
  147. 		} else if (!!(obj = which_armor(mtmp, W_SADDLE))) {
  148. 			mtmp->misc_worn_check &= ~obj->owornmask;
  149. 			update_mon_intrinsics(mtmp, obj, FALSE, FALSE);
  150. 			obj->owornmask = 0L;
  151. 			obj_extract_self(obj);
  152. 			place_object(obj, mtmp->mx, mtmp->my);
  153. 			/* call stackobj() if we ever drop anything that can merge */
  154. 			newsym(mtmp->mx, mtmp->my);
  155. #endif
  156. 		}
  157. 		break;
  158. 	case SPE_HEALING:
  159. 	case SPE_EXTRA_HEALING:
  160. 		reveal_invis = TRUE;
  161. 	    if (mtmp->data != &mons[PM_PESTILENCE]) {
  162. 		wake = FALSE;		/* wakeup() makes the target angry */
  163. 		mtmp->mhp += d(6, otyp == SPE_EXTRA_HEALING ? 8 : 4);
  164. 		if (mtmp->mhp > mtmp->mhpmax)
  165. 		    mtmp->mhp = mtmp->mhpmax;
  166. 		if (mtmp->mblinded) {
  167. 		    mtmp->mblinded = 0;
  168. 		    mtmp->mcansee = 1;
  169. 		}
  170. 		if (canseemon(mtmp)) {
  171. 		    if (disguised_mimic) {
  172. 			if (mtmp->m_ap_type == M_AP_OBJECT &&
  173. 			    mtmp->mappearance == STRANGE_OBJECT) {
  174. 			    /* it can do better now */
  175. 			    set_mimic_sym(mtmp);
  176. 			    newsym(mtmp->mx, mtmp->my);
  177. 			} else
  178. 			    mimic_hit_msg(mtmp, otyp);
  179. 		    } else pline("%s looks%s better.", Monnam(mtmp),
  180. 				 otyp == SPE_EXTRA_HEALING ? " much" : "" );
  181. 		}
  182. 		if (mtmp->mtame || mtmp->mpeaceful) {
  183. 		    adjalign(Role_if(PM_HEALER) ? 1 : sgn(u.ualign.type));
  184. 		}
  185. 	    } else {	/* Pestilence */
  186. 		/* Pestilence will always resist; damage is half of 3d{4,8} */
  187. 		(void) resist(mtmp, otmp->oclass,
  188. 			      d(3, otyp == SPE_EXTRA_HEALING ? 8 : 4), TELL);
  189. 	    }
  190. 		break;
  191. 	case WAN_LIGHT:	/* (broken wand) */
  192. 		if (flash_hits_mon(mtmp, otmp)) {
  193. 		    makeknown(WAN_LIGHT);
  194. 		    reveal_invis = TRUE;
  195. 		}
  196. 		break;
  197. 	case WAN_SLEEP:	/* (broken wand) */
  198. 		/* [wakeup() doesn't rouse victims of temporary sleep,
  199. 		    so it's okay to leave `wake' set to TRUE here] */
  200. 		reveal_invis = TRUE;
  201. 		if (sleep_monst(mtmp, d(1 + otmp->spe, 12), WAND_CLASS))
  202. 		    slept_monst(mtmp);
  203. 		if (!Blind) makeknown(WAN_SLEEP);
  204. 		break;
  205. 	case SPE_STONE_TO_FLESH:
  206. 		if (monsndx(mtmp->data) == PM_STONE_GOLEM) {
  207. 		    char *name = Monnam(mtmp);
  208. 		    /* turn into flesh golem */
  209. 		    if (newcham(mtmp, &mons[PM_FLESH_GOLEM], FALSE, FALSE)) {
  210. 			if (canseemon(mtmp))
  211. 			    pline("%s turns to flesh!", name);
  212. 		    } else {
  213. 			if (canseemon(mtmp))
  214. 			    pline("%s looks rather fleshy for a moment.",
  215. 				  name);
  216. 		    }
  217. 		} else
  218. 		    wake = FALSE;
  219. 		break;
  220. 	case SPE_DRAIN_LIFE:
  221. 		dmg = rnd(8);
  222. 		if(dbldam) dmg *= 2;
  223. 		if (otyp == SPE_DRAIN_LIFE)
  224. 			dmg += spell_damage_bonus();
  225. 		if (resists_drli(mtmp))
  226. 		    shieldeff(mtmp->mx, mtmp->my);
  227. 		else if (!resist(mtmp, otmp->oclass, dmg, NOTELL) &&
  228. 				mtmp->mhp > 0) {
  229. 		    mtmp->mhp -= dmg;
  230. 		    mtmp->mhpmax -= dmg;
  231. 		    if (mtmp->mhp <= 0 || mtmp->mhpmax <= 0 || mtmp->m_lev < 1)
  232. 			xkilled(mtmp, 1);
  233. 		    else {
  234. 			mtmp->m_lev--;
  235. 			if (canseemon(mtmp))
  236. 			    pline("%s suddenly seems weaker!", Monnam(mtmp));
  237. 		    }
  238. 		}
  239. 		break;
  240. 	default:
  241. 		impossible("What an interesting effect (%d)", otyp);
  242. 		break;
  243. 	}
  244. 	if(wake) {
  245. 	    if(mtmp->mhp > 0) {
  246. 		wakeup(mtmp);
  247. 		m_respond(mtmp);
  248. 		if(mtmp->isshk && !*u.ushops) hot_pursuit(mtmp);
  249. 	    } else if(mtmp->m_ap_type)
  250. 		seemimic(mtmp); /* might unblock if mimicing a boulder/door */
  251. 	}
  252. 	/* note: bhitpos won't be set if swallowed, but that's okay since
  253. 	 * reveal_invis will be false.  We can't use mtmp->mx, my since it
  254. 	 * might be an invisible worm hit on the tail.
  255. 	 */
  256. 	if (reveal_invis) {
  257. 	    if (mtmp->mhp > 0 && cansee(bhitpos.x, bhitpos.y) &&
  258. 							!canspotmon(mtmp))
  259. 		map_invisible(bhitpos.x, bhitpos.y);
  260. 	}
  261. 	return 0;
  262. }

probe_monster

  1. void
  2. probe_monster(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	struct obj *otmp;
  6.  
  7. 	mstatusline(mtmp);
  8. 	if (notonhead) return;	/* don't show minvent for long worm tail */
  9.  
  10. #ifndef GOLDOBJ
  11. 	if (mtmp->minvent || mtmp->mgold) {
  12. #else
  13. 	if (mtmp->minvent) {
  14. #endif
  15. 	    for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  16. 		otmp->dknown = 1;	/* treat as "seen" */
  17. 	    (void) display_minventory(mtmp, MINV_ALL, (char *)0);
  18. 	} else {
  19. 	    pline("%s is not carrying anything.", noit_Monnam(mtmp));
  20. 	}
  21. }
  22.  
  23. #endif /*OVLB*/

get_obj_location

  1. #ifdef OVL1
  2.  
  3. /*
  4. * Return the object's physical location.  This only makes sense for
  5. * objects that are currently on the level (i.e. migrating objects
  6. * are nowhere).  By default, only things that can be seen (in hero's
  7. * inventory, monster's inventory, or on the ground) are reported.
  8. * By adding BURIED_TOO and/or CONTAINED_TOO flags, you can also get
  9. * the location of buried and contained objects.  Note that if an
  10. * object is carried by a monster, its reported position may change
  11. * from turn to turn.  This function returns FALSE if the position
  12. * is not available or subject to the constraints above.
  13. */
  14. boolean
  15. get_obj_location(obj, xp, yp, locflags)
  16. struct obj *obj;
  17. xchar *xp, *yp;
  18. int locflags;
  19. {
  20. 	switch (obj->where) {
  21. 	    case OBJ_INVENT:
  22. 		*xp = u.ux;
  23. 		*yp = u.uy;
  24. 		return TRUE;
  25. 	    case OBJ_FLOOR:
  26. 		*xp = obj->ox;
  27. 		*yp = obj->oy;
  28. 		return TRUE;
  29. 	    case OBJ_MINVENT:
  30. 		if (obj->ocarry->mx) {
  31. 		    *xp = obj->ocarry->mx;
  32. 		    *yp = obj->ocarry->my;
  33. 		    return TRUE;
  34. 		}
  35. 		break;	/* !mx => migrating monster */
  36. 	    case OBJ_BURIED:
  37. 		if (locflags & BURIED_TOO) {
  38. 		    *xp = obj->ox;
  39. 		    *yp = obj->oy;
  40. 		    return TRUE;
  41. 		}
  42. 		break;
  43. 	    case OBJ_CONTAINED:
  44. 		if (locflags & CONTAINED_TOO)
  45. 		    return get_obj_location(obj->ocontainer, xp, yp, locflags);
  46. 		break;
  47. 	}
  48. 	*xp = *yp = 0;
  49. 	return FALSE;
  50. }

get_mon_location

  1. boolean
  2. get_mon_location(mon, xp, yp, locflags)
  3. struct monst *mon;
  4. xchar *xp, *yp;
  5. int locflags;	/* non-zero means get location even if monster is buried */
  6. {
  7. 	if (mon == &youmonst) {
  8. 	    *xp = u.ux;
  9. 	    *yp = u.uy;
  10. 	    return TRUE;
  11. 	} else if (mon->mx > 0 && (!mon->mburied || locflags)) {
  12. 	    *xp = mon->mx;
  13. 	    *yp = mon->my;
  14. 	    return TRUE;
  15. 	} else {	/* migrating or buried */
  16. 	    *xp = *yp = 0;
  17. 	    return FALSE;
  18. 	}
  19. }

montraits

  1. /* used by revive() and animate_statue() */
  2. struct monst *
  3. montraits(obj,cc)
  4. struct obj *obj;
  5. coord *cc;
  6. {
  7. 	struct monst *mtmp = (struct monst *)0;
  8. 	struct monst *mtmp2 = (struct monst *)0;
  9.  
  10. 	if (obj->oxlth && (obj->oattached == OATTACHED_MONST))
  11. 		mtmp2 = get_mtraits(obj, TRUE);
  12. 	if (mtmp2) {
  13. 		/* save_mtraits() validated mtmp2->mnum */
  14. 		mtmp2->data = &mons[mtmp2->mnum];
  15. 		if (mtmp2->mhpmax <= 0 && !is_rider(mtmp2->data))
  16. 			return (struct monst *)0;
  17. 		mtmp = makemon(mtmp2->data,
  18. 				cc->x, cc->y, NO_MINVENT|MM_NOWAIT|MM_NOCOUNTBIRTH);
  19. 		if (!mtmp) return mtmp;
  20.  
  21. 		/* heal the monster */
  22. 		if (mtmp->mhpmax > mtmp2->mhpmax && is_rider(mtmp2->data))
  23. 			mtmp2->mhpmax = mtmp->mhpmax;
  24. 		mtmp2->mhp = mtmp2->mhpmax;
  25. 		/* Get these ones from mtmp */
  26. 		mtmp2->minvent = mtmp->minvent; /*redundant*/
  27. 		/* monster ID is available if the monster died in the current
  28. 		   game, but should be zero if the corpse was in a bones level
  29. 		   (we cleared it when loading bones) */
  30. 		if (!mtmp2->m_id)
  31. 		    mtmp2->m_id = mtmp->m_id;
  32. 		mtmp2->mx   = mtmp->mx;
  33. 		mtmp2->my   = mtmp->my;
  34. 		mtmp2->mux  = mtmp->mux;
  35. 		mtmp2->muy  = mtmp->muy;
  36. 		mtmp2->mw   = mtmp->mw;
  37. 		mtmp2->wormno = mtmp->wormno;
  38. 		mtmp2->misc_worn_check = mtmp->misc_worn_check;
  39. 		mtmp2->weapon_check = mtmp->weapon_check;
  40. 		mtmp2->mtrapseen = mtmp->mtrapseen;
  41. 		mtmp2->mflee = mtmp->mflee;
  42. 		mtmp2->mburied = mtmp->mburied;
  43. 		mtmp2->mundetected = mtmp->mundetected;
  44. 		mtmp2->mfleetim = mtmp->mfleetim;
  45. 		mtmp2->mlstmv = mtmp->mlstmv;
  46. 		mtmp2->m_ap_type = mtmp->m_ap_type;
  47. 		/* set these ones explicitly */
  48. 		mtmp2->mavenge = 0;
  49. 		mtmp2->meating = 0;
  50. 		mtmp2->mleashed = 0;
  51. 		mtmp2->mtrapped = 0;
  52. 		mtmp2->msleeping = 0;
  53. 		mtmp2->mfrozen = 0;
  54. 		mtmp2->mcanmove = 1;
  55. 		/* most cancelled monsters return to normal,
  56. 		   but some need to stay cancelled */
  57. 		if (!dmgtype(mtmp2->data, AD_SEDU)
  58. #ifdef SEDUCE
  59. 				&& !dmgtype(mtmp2->data, AD_SSEX)
  60. #endif
  61. 		    ) mtmp2->mcan = 0;
  62. 		mtmp2->mcansee = 1;	/* set like in makemon */
  63. 		mtmp2->mblinded = 0;
  64. 		mtmp2->mstun = 0;
  65. 		mtmp2->mconf = 0;
  66. 		replmon(mtmp,mtmp2);
  67. 	}
  68. 	return mtmp2;
  69. }

get_container_location

  1. /*
  2. * get_container_location() returns the following information
  3. * about the outermost container:
  4. * loc argument gets set to: 
  5. *	OBJ_INVENT	if in hero's inventory; return 0.
  6. *	OBJ_FLOOR	if on the floor; return 0.
  7. *	OBJ_BURIED	if buried; return 0.
  8. *	OBJ_MINVENT	if in monster's inventory; return monster.
  9. * container_nesting is updated with the nesting depth of the containers
  10. * if applicable.
  11. */
  12. struct monst *
  13. get_container_location(obj, loc, container_nesting)
  14. struct obj *obj;
  15. int *loc;
  16. int *container_nesting;
  17. {
  18. 	if (!obj || !loc)
  19. 		return 0;
  20.  
  21. 	if (container_nesting) *container_nesting = 0;
  22. 	while (obj && obj->where == OBJ_CONTAINED) {
  23. 		if (container_nesting) *container_nesting += 1;
  24. 		obj = obj->ocontainer;
  25. 	}
  26. 	if (obj) {
  27. 	    *loc = obj->where;	/* outermost container's location */
  28. 	    if (obj->where == OBJ_MINVENT) return obj->ocarry;
  29. 	}
  30. 	return (struct monst *)0;
  31. }

revive

  1. /*
  2. * Attempt to revive the given corpse, return the revived monster if
  3. * successful.  Note: this does NOT use up the corpse if it fails.
  4. */
  5. struct monst *
  6. revive(obj)
  7. register struct obj *obj;
  8. {
  9. 	register struct monst *mtmp = (struct monst *)0;
  10. 	struct obj *container = (struct obj *)0;
  11. 	int container_nesting = 0;
  12. 	schar savetame = 0;
  13. 	boolean recorporealization = FALSE;
  14. 	boolean in_container = FALSE;
  15. 	if(obj->otyp == CORPSE) {
  16. 		int montype = obj->corpsenm;
  17. 		xchar x, y;
  18.  
  19. 		if (obj->where == OBJ_CONTAINED) {
  20. 			/* deal with corpses in [possibly nested] containers */
  21. 			struct monst *carrier;
  22. 			int holder = 0;
  23.  
  24. 			container = obj->ocontainer;
  25. 			carrier = get_container_location(container, &holder,
  26. 							&container_nesting);
  27. 			switch(holder) {
  28. 			    case OBJ_MINVENT:
  29. 				x = carrier->mx; y = carrier->my;
  30. 				in_container = TRUE;
  31. 				break;
  32. 			    case OBJ_INVENT:
  33. 				x = u.ux; y = u.uy;
  34. 				in_container = TRUE;
  35. 				break;
  36. 			    case OBJ_FLOOR:
  37. 				if (!get_obj_location(obj, &x, &y, CONTAINED_TOO))
  38. 					return (struct monst *) 0;
  39. 				in_container = TRUE;
  40. 				break;
  41. 			    default:
  42. 			    	return (struct monst *)0;
  43. 			}
  44. 		} else {
  45. 			/* only for invent, minvent, or floor */
  46. 			if (!get_obj_location(obj, &x, &y, 0))
  47. 			    return (struct monst *) 0;
  48. 		}
  49. 		if (in_container) {
  50. 			/* Rules for revival from containers:
  51. 			   - the container cannot be locked
  52. 			   - the container cannot be heavily nested (>2 is arbitrary)
  53. 			   - the container cannot be a statue or bag of holding
  54. 			     (except in very rare cases for the latter)
  55. 			*/
  56. 			if (!x || !y || container->olocked || container_nesting > 2 ||
  57. 			    container->otyp == STATUE ||
  58. 			    (container->otyp == BAG_OF_HOLDING && rn2(40)))
  59. 				return (struct monst *)0;
  60. 		}
  61.  
  62. 		if (MON_AT(x,y)) {
  63. 		    coord new_xy;
  64.  
  65. 		    if (enexto(&new_xy, x, y, &mons[montype]))
  66. 			x = new_xy.x,  y = new_xy.y;
  67. 		}
  68.  
  69. 		if(cant_create(&montype, TRUE)) {
  70. 			/* make a zombie or worm instead */
  71. 			mtmp = makemon(&mons[montype], x, y,
  72. 				       NO_MINVENT|MM_NOWAIT);
  73. 			if (mtmp) {
  74. 				mtmp->mhp = mtmp->mhpmax = 100;
  75. 				mon_adjust_speed(mtmp, 2, (struct obj *)0); /* MFAST */
  76. 			}
  77. 		} else {
  78. 		    if (obj->oxlth && (obj->oattached == OATTACHED_MONST)) {
  79. 			    coord xy;
  80. 			    xy.x = x; xy.y = y;
  81. 		    	    mtmp = montraits(obj, &xy);
  82. 		    	    if (mtmp && mtmp->mtame && !mtmp->isminion)
  83. 				wary_dog(mtmp, TRUE);
  84. 		    } else
  85. 		            mtmp = makemon(&mons[montype], x, y,
  86. 				       NO_MINVENT|MM_NOWAIT|MM_NOCOUNTBIRTH);
  87. 		    if (mtmp) {
  88. 			if (obj->oxlth && (obj->oattached == OATTACHED_M_ID)) {
  89. 			    unsigned m_id;
  90. 			    struct monst *ghost;
  91. 			    (void) memcpy((genericptr_t)&m_id,
  92. 				    (genericptr_t)obj->oextra, sizeof(m_id));
  93. 			    ghost = find_mid(m_id, FM_FMON);
  94. 		    	    if (ghost && ghost->data == &mons[PM_GHOST]) {
  95. 		    		    int x2, y2;
  96. 		    		    x2 = ghost->mx; y2 = ghost->my;
  97. 		    		    if (ghost->mtame)
  98. 		    		    	savetame = ghost->mtame;
  99. 		    		    if (canseemon(ghost))
  100. 		    		  	pline("%s is suddenly drawn into its former body!",
  101. 						Monnam(ghost));
  102. 				    mondead(ghost);
  103. 				    recorporealization = TRUE;
  104. 				    newsym(x2, y2);
  105. 			    }
  106. 			    /* don't mess with obj->oxlth here */
  107. 			    obj->oattached = OATTACHED_NOTHING;
  108. 			}
  109. 			/* Monster retains its name */
  110. 			if (obj->onamelth)
  111. 			    mtmp = christen_monst(mtmp, ONAME(obj));
  112. 			/* flag the quest leader as alive. */
  113. 			if (mtmp->data->msound == MS_LEADER || mtmp->m_id ==
  114. 				quest_status.leader_m_id)
  115. 			    quest_status.leader_is_dead = FALSE;
  116. 		    }
  117. 		}
  118. 		if (mtmp) {
  119. 			if (obj->oeaten)
  120. 				mtmp->mhp = eaten_stat(mtmp->mhp, obj);
  121. 			/* track that this monster was revived at least once */
  122. 			mtmp->mrevived = 1;
  123.  
  124. 			if (recorporealization) {
  125. 				/* If mtmp is revivification of former tame ghost*/
  126. 				if (savetame) {
  127. 				    struct monst *mtmp2 = tamedog(mtmp, (struct obj *)0);
  128. 				    if (mtmp2) {
  129. 					mtmp2->mtame = savetame;
  130. 					mtmp = mtmp2;
  131. 				    }
  132. 				}
  133. 				/* was ghost, now alive, it's all very confusing */
  134. 				mtmp->mconf = 1;
  135. 			}
  136.  
  137. 			switch (obj->where) {
  138. 			    case OBJ_INVENT:
  139. 				useup(obj);
  140. 				break;
  141. 			    case OBJ_FLOOR:
  142. 				/* in case MON_AT+enexto for invisible mon */
  143. 				x = obj->ox,  y = obj->oy;
  144. 				/* not useupf(), which charges */
  145. 				if (obj->quan > 1L)
  146. 				    obj = splitobj(obj, 1L);
  147. 				delobj(obj);
  148. 				newsym(x, y);
  149. 				break;
  150. 			    case OBJ_MINVENT:
  151. 				m_useup(obj->ocarry, obj);
  152. 				break;
  153. 			    case OBJ_CONTAINED:
  154. 				obj_extract_self(obj);
  155. 				obfree(obj, (struct obj *) 0);
  156. 				break;
  157. 			    default:
  158. 				panic("revive");
  159. 			}
  160. 		}
  161. 	}
  162. 	return mtmp;
  163. }

revive_egg

  1. STATIC_OVL void
  2. revive_egg(obj)
  3. struct obj *obj;
  4. {
  5. 	/*
  6. 	 * Note: generic eggs with corpsenm set to NON_PM will never hatch.
  7. 	 */
  8. 	if (obj->otyp != EGG) return;
  9. 	if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE))
  10. 	    attach_egg_hatch_timeout(obj);
  11. }

unturn_dead

  1. /* try to revive all corpses and eggs carried by `mon' */
  2. int
  3. unturn_dead(mon)
  4. struct monst *mon;
  5. {
  6. 	struct obj *otmp, *otmp2;
  7. 	struct monst *mtmp2;
  8. 	char owner[BUFSZ], corpse[BUFSZ];
  9. 	boolean youseeit;
  10. 	int once = 0, res = 0;
  11.  
  12. 	youseeit = (mon == &youmonst) ? TRUE : canseemon(mon);
  13. 	otmp2 = (mon == &youmonst) ? invent : mon->minvent;
  14.  
  15. 	while ((otmp = otmp2) != 0) {
  16. 	    otmp2 = otmp->nobj;
  17. 	    if (otmp->otyp == EGG)
  18. 		revive_egg(otmp);
  19. 	    if (otmp->otyp != CORPSE) continue;
  20. 	    /* save the name; the object is liable to go away */
  21. 	    if (youseeit) Strcpy(corpse, corpse_xname(otmp, TRUE));
  22.  
  23. 	    /* for a merged group, only one is revived; should this be fixed? */
  24. 	    if ((mtmp2 = revive(otmp)) != 0) {
  25. 		++res;
  26. 		if (youseeit) {
  27. 		    if (!once++) Strcpy(owner,
  28. 					(mon == &youmonst) ? "Your" :
  29. 					s_suffix(Monnam(mon)));
  30. 		    pline("%s %s suddenly comes alive!", owner, corpse);
  31. 		} else if (canseemon(mtmp2))
  32. 		    pline("%s suddenly appears!", Amonnam(mtmp2));
  33. 	    }
  34. 	}
  35. 	return res;
  36. }
  37. #endif /*OVL1*/

costly_cancel

  1. #ifdef OVLB
  2. static const char charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS, 0 };
  3.  
  4. STATIC_OVL void
  5. costly_cancel(obj)
  6. register struct obj *obj;
  7. {
  8. 	char objroom;
  9. 	struct monst *shkp = (struct monst *)0;
  10.  
  11. 	if (obj->no_charge) return;
  12.  
  13. 	switch (obj->where) {
  14. 	case OBJ_INVENT:
  15. 		if (obj->unpaid) {
  16. 		    shkp = shop_keeper(*u.ushops);
  17. 		    if (!shkp) return;
  18. 		    Norep("You cancel an unpaid object, you pay for it!");
  19. 		    bill_dummy_object(obj);
  20. 		}
  21. 		break;
  22. 	case OBJ_FLOOR:
  23. 		objroom = *in_rooms(obj->ox, obj->oy, SHOPBASE);
  24. 		shkp = shop_keeper(objroom);
  25. 		if (!shkp || !inhishop(shkp)) return;
  26. 		if (costly_spot(u.ux, u.uy) && objroom == *u.ushops) {
  27. 		    Norep("You cancel it, you pay for it!");
  28. 		    bill_dummy_object(obj);
  29. 		} else
  30. 		    (void) stolen_value(obj, obj->ox, obj->oy, FALSE, FALSE);
  31. 		break;
  32. 	}
  33. }

cancel_item

  1. /* cancel obj, possibly carried by you or a monster */
  2. void
  3. cancel_item(obj)
  4. register struct obj *obj;
  5. {
  6. 	boolean	u_ring = (obj == uleft) || (obj == uright);
  7. 	register boolean holy = (obj->otyp == POT_WATER && obj->blessed);
  8.  
  9. 	switch(obj->otyp) {
  10. 		case RIN_GAIN_STRENGTH:
  11. 			if ((obj->owornmask & W_RING) && u_ring) {
  12. 				ABON(A_STR) -= obj->spe;
  13. 				flags.botl = 1;
  14. 			}
  15. 			break;
  16. 		case RIN_GAIN_CONSTITUTION:
  17. 			if ((obj->owornmask & W_RING) && u_ring) {
  18. 				ABON(A_CON) -= obj->spe;
  19. 				flags.botl = 1;
  20. 			}
  21. 			break;
  22. 		case RIN_ADORNMENT:
  23. 			if ((obj->owornmask & W_RING) && u_ring) {
  24. 				ABON(A_CHA) -= obj->spe;
  25. 				flags.botl = 1;
  26. 			}
  27. 			break;
  28. 		case RIN_INCREASE_ACCURACY:
  29. 			if ((obj->owornmask & W_RING) && u_ring)
  30. 				u.uhitinc -= obj->spe;
  31. 			break;
  32. 		case RIN_INCREASE_DAMAGE:
  33. 			if ((obj->owornmask & W_RING) && u_ring)
  34. 				u.udaminc -= obj->spe;
  35. 			break;
  36. 		case GAUNTLETS_OF_DEXTERITY:
  37. 			if ((obj->owornmask & W_ARMG) && (obj == uarmg)) {
  38. 				ABON(A_DEX) -= obj->spe;
  39. 				flags.botl = 1;
  40. 			}
  41. 			break;
  42. 		case HELM_OF_BRILLIANCE:
  43. 			if ((obj->owornmask & W_ARMH) && (obj == uarmh)) {
  44. 				ABON(A_INT) -= obj->spe;
  45. 				ABON(A_WIS) -= obj->spe;
  46. 				flags.botl = 1;
  47. 			}
  48. 			break;
  49. 		/* case RIN_PROTECTION:  not needed */
  50. 	}
  51. 	if (objects[obj->otyp].oc_magic
  52. 	    || (obj->spe && (obj->oclass == ARMOR_CLASS ||
  53. 			     obj->oclass == WEAPON_CLASS || is_weptool(obj)))
  54. 	    || obj->otyp == POT_ACID || obj->otyp == POT_SICKNESS) {
  55. 	    if (obj->spe != ((obj->oclass == WAND_CLASS) ? -1 : 0) &&
  56. 	       obj->otyp != WAN_CANCELLATION &&
  57. 		 /* can't cancel cancellation */
  58. 		 obj->otyp != MAGIC_LAMP &&
  59. 		 obj->otyp != CANDELABRUM_OF_INVOCATION) {
  60. 		costly_cancel(obj);
  61. 		obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0;
  62. 	    }
  63. 	    switch (obj->oclass) {
  64. 	      case SCROLL_CLASS:
  65. 		costly_cancel(obj);
  66. 		obj->otyp = SCR_BLANK_PAPER;
  67. 		obj->spe = 0;
  68. 		break;
  69. 	      case SPBOOK_CLASS:
  70. 		if (obj->otyp != SPE_CANCELLATION &&
  71. 			obj->otyp != SPE_BOOK_OF_THE_DEAD) {
  72. 		    costly_cancel(obj);
  73. 		    obj->otyp = SPE_BLANK_PAPER;
  74. 		}
  75. 		break;
  76. 	      case POTION_CLASS:
  77. 		costly_cancel(obj);
  78. 		if (obj->otyp == POT_SICKNESS ||
  79. 		    obj->otyp == POT_SEE_INVISIBLE) {
  80. 	    /* sickness is "biologically contaminated" fruit juice; cancel it
  81. 	     * and it just becomes fruit juice... whereas see invisible
  82. 	     * tastes like "enchanted" fruit juice, it similarly cancels.
  83. 	     */
  84. 		    obj->otyp = POT_FRUIT_JUICE;
  85. 		} else {
  86. 	            obj->otyp = POT_WATER;
  87. 		    obj->odiluted = 0; /* same as any other water */
  88. 		}
  89. 		break;
  90. 	    }
  91. 	}
  92. 	if (holy) costly_cancel(obj);
  93. 	unbless(obj);
  94. 	uncurse(obj);
  95. #ifdef INVISIBLE_OBJECTS
  96. 	if (obj->oinvis) obj->oinvis = 0;
  97. #endif
  98. 	return;
  99. }

drain_item

  1. /* Remove a positive enchantment or charge from obj,
  2. * possibly carried by you or a monster
  3. */
  4. boolean
  5. drain_item(obj)
  6. register struct obj *obj;
  7. {
  8. 	boolean u_ring;
  9.  
  10. 	/* Is this a charged/enchanted object? */
  11. 	if (!obj || (!objects[obj->otyp].oc_charged &&
  12. 			obj->oclass != WEAPON_CLASS &&
  13. 			obj->oclass != ARMOR_CLASS && !is_weptool(obj)) ||
  14. 			obj->spe <= 0)
  15. 	    return (FALSE);
  16. 	if (obj_resists(obj, 10, 90))
  17. 	    return (FALSE);
  18.  
  19. 	/* Charge for the cost of the object */
  20. 	costly_cancel(obj);	/* The term "cancel" is okay for now */
  21.  
  22. 	/* Drain the object and any implied effects */
  23. 	obj->spe--;
  24. 	u_ring = (obj == uleft) || (obj == uright);
  25. 	switch(obj->otyp) {
  26. 	case RIN_GAIN_STRENGTH:
  27. 	    if ((obj->owornmask & W_RING) && u_ring) {
  28. 	    	ABON(A_STR)--;
  29. 	    	flags.botl = 1;
  30. 	    }
  31. 	    break;
  32. 	case RIN_GAIN_CONSTITUTION:
  33. 	    if ((obj->owornmask & W_RING) && u_ring) {
  34. 	    	ABON(A_CON)--;
  35. 	    	flags.botl = 1;
  36. 	    }
  37. 	    break;
  38. 	case RIN_ADORNMENT:
  39. 	    if ((obj->owornmask & W_RING) && u_ring) {
  40. 	    	ABON(A_CHA)--;
  41. 	    	flags.botl = 1;
  42. 	    }
  43. 	    break;
  44. 	case RIN_INCREASE_ACCURACY:
  45. 	    if ((obj->owornmask & W_RING) && u_ring)
  46. 	    	u.uhitinc--;
  47. 	    break;
  48. 	case RIN_INCREASE_DAMAGE:
  49. 	    if ((obj->owornmask & W_RING) && u_ring)
  50. 	    	u.udaminc--;
  51. 	    break;
  52. 	case HELM_OF_BRILLIANCE:
  53. 	    if ((obj->owornmask & W_ARMH) && (obj == uarmh)) {
  54. 	    	ABON(A_INT)--;
  55. 	    	ABON(A_WIS)--;
  56. 	    	flags.botl = 1;
  57. 	    }
  58. 	    break;
  59. 	case GAUNTLETS_OF_DEXTERITY:
  60. 	    if ((obj->owornmask & W_ARMG) && (obj == uarmg)) {
  61. 	    	ABON(A_DEX)--;
  62. 	    	flags.botl = 1;
  63. 	    }
  64. 	    break;
  65. 	case RIN_PROTECTION:
  66. 	    flags.botl = 1;
  67. 	    break;
  68. 	}
  69. 	if (carried(obj)) update_inventory();
  70. 	return (TRUE);
  71. }
  72.  
  73. #endif /*OVLB*/

obj_resists

  1. #ifdef OVL0
  2.  
  3. boolean
  4. obj_resists(obj, ochance, achance)
  5. struct obj *obj;
  6. int ochance, achance;	/* percent chance for ordinary objects, artifacts */
  7. {
  8. 	if (obj->otyp == AMULET_OF_YENDOR ||
  9. 	    obj->otyp == SPE_BOOK_OF_THE_DEAD ||
  10. 	    obj->otyp == CANDELABRUM_OF_INVOCATION ||
  11. 	    obj->otyp == BELL_OF_OPENING ||
  12. 	    (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) {
  13. 		return TRUE;
  14. 	} else {
  15. 		int chance = rn2(100);
  16.  
  17. 		return((boolean)(chance < (obj->oartifact ? achance : ochance)));
  18. 	}
  19. }

obj_shudders

  1. boolean
  2. obj_shudders(obj)
  3. struct obj *obj;
  4. {
  5. 	int	zap_odds;
  6.  
  7. 	if (obj->oclass == WAND_CLASS)
  8. 		zap_odds = 3;	/* half-life = 2 zaps */
  9. 	else if (obj->cursed)
  10. 		zap_odds = 3;	/* half-life = 2 zaps */
  11. 	else if (obj->blessed)
  12. 		zap_odds = 12;	/* half-life = 8 zaps */
  13. 	else
  14. 		zap_odds = 8;	/* half-life = 6 zaps */
  15.  
  16. 	/* adjust for "large" quantities of identical things */
  17. 	if(obj->quan > 4L) zap_odds /= 2;
  18.  
  19. 	return((boolean)(! rn2(zap_odds)));
  20. }
  21. #endif /*OVL0*/

polyuse

  1. #ifdef OVLB
  2.  
  3. /* Use up at least minwt number of things made of material mat.
  4. * There's also a chance that other stuff will be used up.  Finally,
  5. * there's a random factor here to keep from always using the stuff
  6. * at the top of the pile.
  7. */
  8. STATIC_OVL void
  9. polyuse(objhdr, mat, minwt)
  10. struct obj *objhdr;
  11. int mat, minwt;
  12. {
  13. register struct obj *otmp, *otmp2;
  14.  
  15. for(otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) {
  16. 	otmp2 = otmp->nexthere;
  17. 	if (otmp == uball || otmp == uchain) continue;
  18. 	if (obj_resists(otmp, 0, 0)) continue;	/* preserve unique objects */
  19. #ifdef MAIL
  20. 	if (otmp->otyp == SCR_MAIL) continue;
  21. #endif
  22.  
  23. 	if (((int) objects[otmp->otyp].oc_material == mat) ==
  24. 		(rn2(minwt + 1) != 0)) {
  25. 	    /* appropriately add damage to bill */
  26. 	    if (costly_spot(otmp->ox, otmp->oy)) {
  27. 		if (*u.ushops)
  28. 			addtobill(otmp, FALSE, FALSE, FALSE);
  29. 		else
  30. 			(void)stolen_value(otmp,
  31. 					   otmp->ox, otmp->oy, FALSE, FALSE);
  32. 	    }
  33. 	    if (otmp->quan < LARGEST_INT)
  34. 		minwt -= (int)otmp->quan;
  35. 	    else
  36. 		minwt = 0;
  37. 	    delobj(otmp);
  38. 	}
  39. }
  40. }

create_polymon

  1. /*
  2. * Polymorph some of the stuff in this pile into a monster, preferably
  3. * a golem of the kind okind.
  4. */
  5. STATIC_OVL void
  6. create_polymon(obj, okind)
  7. struct obj *obj;
  8. int okind;
  9. {
  10. 	struct permonst *mdat = (struct permonst *)0;
  11. 	struct monst *mtmp;
  12. 	const char *material;
  13. 	int pm_index;
  14.  
  15. 	/* no golems if you zap only one object -- not enough stuff */
  16. 	if(!obj || (!obj->nexthere && obj->quan == 1L)) return;
  17.  
  18. 	/* some of these choices are arbitrary */
  19. 	switch(okind) {
  20. 	case IRON:
  21. 	case METAL:
  22. 	case MITHRIL:
  23. 	    pm_index = PM_IRON_GOLEM;
  24. 	    material = "metal ";
  25. 	    break;
  26. 	case COPPER:
  27. 	case SILVER:
  28. 	case PLATINUM:
  29. 	case GEMSTONE:
  30. 	case MINERAL:
  31. 	    pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM;
  32. 	    material = "lithic ";
  33. 	    break;
  34. 	case 0:
  35. 	case FLESH:
  36. 	    /* there is no flesh type, but all food is type 0, so we use it */
  37. 	    pm_index = PM_FLESH_GOLEM;
  38. 	    material = "organic ";
  39. 	    break;
  40. 	case WOOD:
  41. 	    pm_index = PM_WOOD_GOLEM;
  42. 	    material = "wood ";
  43. 	    break;
  44. 	case LEATHER:
  45. 	    pm_index = PM_LEATHER_GOLEM;
  46. 	    material = "leather ";
  47. 	    break;
  48. 	case CLOTH:
  49. 	    pm_index = PM_ROPE_GOLEM;
  50. 	    material = "cloth ";
  51. 	    break;
  52. 	case BONE:
  53. 	    pm_index = PM_SKELETON;     /* nearest thing to "bone golem" */
  54. 	    material = "bony ";
  55. 	    break;
  56. 	case GOLD:
  57. 	    pm_index = PM_GOLD_GOLEM;
  58. 	    material = "gold ";
  59. 	    break;
  60. 	case GLASS:
  61. 	    pm_index = PM_GLASS_GOLEM;
  62. 	    material = "glassy ";
  63. 	    break;
  64. 	case PAPER:
  65. 	    pm_index = PM_PAPER_GOLEM;
  66. 	    material = "paper ";
  67. 	    break;
  68. 	default:
  69. 	    /* if all else fails... */
  70. 	    pm_index = PM_STRAW_GOLEM;
  71. 	    material = "";
  72. 	    break;
  73. 	}
  74.  
  75. 	if (!(mvitals[pm_index].mvflags & G_GENOD))
  76. 		mdat = &mons[pm_index];
  77.  
  78. 	mtmp = makemon(mdat, obj->ox, obj->oy, NO_MM_FLAGS);
  79. 	polyuse(obj, okind, (int)mons[pm_index].cwt);
  80.  
  81. 	if(mtmp && cansee(mtmp->mx, mtmp->my)) {
  82. 	    pline("Some %sobjects meld, and %s arises from the pile!",
  83. 		  material, a_monnam(mtmp));
  84. 	}
  85. }

do_osshock

  1. /* Assumes obj is on the floor. */
  2. void
  3. do_osshock(obj)
  4. struct obj *obj;
  5. {
  6. 	long i;
  7.  
  8. #ifdef MAIL
  9. 	if (obj->otyp == SCR_MAIL) return;
  10. #endif
  11. 	obj_zapped = TRUE;
  12.  
  13. 	if(poly_zapped < 0) {
  14. 	    /* some may metamorphosize */
  15. 	    for (i = obj->quan; i; i--)
  16. 		if (! rn2(Luck + 45)) {
  17. 		    poly_zapped = objects[obj->otyp].oc_material;
  18. 		    break;
  19. 		}
  20. 	}
  21.  
  22. 	/* if quan > 1 then some will survive intact */
  23. 	if (obj->quan > 1L) {
  24. 	    if (obj->quan > LARGEST_INT)
  25. 		obj = splitobj(obj, (long)rnd(30000));
  26. 	    else
  27. 		obj = splitobj(obj, (long)rnd((int)obj->quan - 1));
  28. 	}
  29.  
  30. 	/* appropriately add damage to bill */
  31. 	if (costly_spot(obj->ox, obj->oy)) {
  32. 		if (*u.ushops)
  33. 			addtobill(obj, FALSE, FALSE, FALSE);
  34. 		else
  35. 			(void)stolen_value(obj,
  36. 					   obj->ox, obj->oy, FALSE, FALSE);
  37. 	}
  38.  
  39. 	/* zap the object */
  40. 	delobj(obj);
  41. }

poly_obj

  1. /*
  2. * Polymorph the object to the given object ID.  If the ID is STRANGE_OBJECT
  3. * then pick random object from the source's class (this is the standard
  4. * "polymorph" case).  If ID is set to a specific object, inhibit fusing
  5. * n objects into 1.  This could have been added as a flag, but currently
  6. * it is tied to not being the standard polymorph case. The new polymorphed
  7. * object replaces obj in its link chains.  Return value is a pointer to
  8. * the new object.
  9. *
  10. * This should be safe to call for an object anywhere.
  11. */
  12. struct obj *
  13. poly_obj(obj, id)
  14. 	struct obj *obj;
  15. 	int id;
  16. {
  17. 	struct obj *otmp;
  18. 	xchar ox, oy;
  19. 	boolean can_merge = (id == STRANGE_OBJECT);
  20. 	int obj_location = obj->where;
  21.  
  22. 	if (obj->otyp == BOULDER && In_sokoban(&u.uz))
  23. 	    change_luck(-1);	/* Sokoban guilt */
  24. 	if (id == STRANGE_OBJECT) { /* preserve symbol */
  25. 	    int try_limit = 3;
  26. 	    /* Try up to 3 times to make the magic-or-not status of
  27. 	       the new item be the same as it was for the old one. */
  28. 	    otmp = (struct obj *)0;
  29. 	    do {
  30. 		if (otmp) delobj(otmp);
  31. 		otmp = mkobj(obj->oclass, FALSE);
  32. 	    } while (--try_limit > 0 &&
  33. 		  objects[obj->otyp].oc_magic != objects[otmp->otyp].oc_magic);
  34. 	} else {
  35. 	    /* literally replace obj with this new thing */
  36. 	    otmp = mksobj(id, FALSE, FALSE);
  37. 	/* Actually more things use corpsenm but they polymorph differently */
  38. #define USES_CORPSENM(typ) ((typ)==CORPSE || (typ)==STATUE || (typ)==FIGURINE)
  39. 	    if (USES_CORPSENM(obj->otyp) && USES_CORPSENM(id))
  40. 		otmp->corpsenm = obj->corpsenm;
  41. #undef USES_CORPSENM
  42. 	}
  43.  
  44. 	/* preserve quantity */
  45. 	otmp->quan = obj->quan;
  46. 	/* preserve the shopkeepers (lack of) interest */
  47. 	otmp->no_charge = obj->no_charge;
  48. 	/* preserve inventory letter if in inventory */
  49. 	if (obj_location == OBJ_INVENT)
  50. 	    otmp->invlet = obj->invlet;
  51. #ifdef MAIL
  52. 	/* You can't send yourself 100 mail messages and then
  53. 	 * polymorph them into useful scrolls
  54. 	 */
  55. 	if (obj->otyp == SCR_MAIL) {
  56. 		otmp->otyp = SCR_MAIL;
  57. 		otmp->spe = 1;
  58. 	}
  59. #endif
  60.  
  61. 	/* avoid abusing eggs laid by you */
  62. 	if (obj->otyp == EGG && obj->spe) {
  63. 		int mnum, tryct = 100;
  64.  
  65. 		/* first, turn into a generic egg */
  66. 		if (otmp->otyp == EGG)
  67. 		    kill_egg(otmp);
  68. 		else {
  69. 		    otmp->otyp = EGG;
  70. 		    otmp->owt = weight(otmp);
  71. 		}
  72. 		otmp->corpsenm = NON_PM;
  73. 		otmp->spe = 0;
  74.  
  75. 		/* now change it into something layed by the hero */
  76. 		while (tryct--) {
  77. 		    mnum = can_be_hatched(random_monster());
  78. 		    if (mnum != NON_PM && !dead_species(mnum, TRUE)) {
  79. 			otmp->spe = 1;	/* layed by hero */
  80. 			otmp->corpsenm = mnum;
  81. 			attach_egg_hatch_timeout(otmp);
  82. 			break;
  83. 		    }
  84. 		}
  85. 	}
  86.  
  87. 	/* keep special fields (including charges on wands) */
  88. 	if (index(charged_objs, otmp->oclass)) otmp->spe = obj->spe;
  89. 	otmp->recharged = obj->recharged;
  90.  
  91. 	otmp->cursed = obj->cursed;
  92. 	otmp->blessed = obj->blessed;
  93. 	otmp->oeroded = obj->oeroded;
  94. 	otmp->oeroded2 = obj->oeroded2;
  95. 	if (!is_flammable(otmp) && !is_rustprone(otmp)) otmp->oeroded = 0;
  96. 	if (!is_corrodeable(otmp) && !is_rottable(otmp)) otmp->oeroded2 = 0;
  97. 	if (is_damageable(otmp))
  98. 	    otmp->oerodeproof = obj->oerodeproof;
  99.  
  100. 	/* Keep chest/box traps and poisoned ammo if we may */
  101. 	if (obj->otrapped && Is_box(otmp)) otmp->otrapped = TRUE;
  102.  
  103. 	if (obj->opoisoned && is_poisonable(otmp))
  104. 		otmp->opoisoned = TRUE;
  105.  
  106. 	if (id == STRANGE_OBJECT && obj->otyp == CORPSE) {
  107. 	/* turn crocodile corpses into shoes */
  108. 	    if (obj->corpsenm == PM_CROCODILE) {
  109. 		otmp->otyp = LOW_BOOTS;
  110. 		otmp->oclass = ARMOR_CLASS;
  111. 		otmp->spe = 0;
  112. 		otmp->oeroded = 0;
  113. 		otmp->oerodeproof = TRUE;
  114. 		otmp->quan = 1L;
  115. 		otmp->cursed = FALSE;
  116. 	    }

Crocodile corpses (not baby crocodiles) are polymorphed into fireproof +0 pair of low boots that will also be blessed if the corpse was blessed.

  1. 	}
  2.  
  3. 	/* no box contents --KAA */
  4. 	if (Has_contents(otmp)) delete_contents(otmp);
  5.  
  6. 	/* 'n' merged objects may be fused into 1 object */
  7. 	if (otmp->quan > 1L && (!objects[otmp->otyp].oc_merge ||
  8. 				(can_merge && otmp->quan > (long)rn2(1000))))
  9. 	    otmp->quan = 1L;
  10.  
  11. 	switch (otmp->oclass) {
  12.  
  13. 	case TOOL_CLASS:
  14. 	    if (otmp->otyp == MAGIC_LAMP) {
  15. 		otmp->otyp = OIL_LAMP;
  16. 		otmp->age = 1500L;	/* "best" oil lamp possible */
  17. 	    } else if (otmp->otyp == MAGIC_MARKER) {
  18. 		otmp->recharged = 1;	/* degraded quality */
  19. 	    }
  20. 	    /* don't care about the recharge count of other tools */
  21. 	    break;
  22.  
  23. 	case WAND_CLASS:
  24. 	    while (otmp->otyp == WAN_WISHING || otmp->otyp == WAN_POLYMORPH)
  25. 		otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING);
  26. 	    /* altering the object tends to degrade its quality
  27. 	       (analogous to spellbook `read count' handling) */
  28. 	    if ((int)otmp->recharged < rn2(7))	/* recharge_limit */
  29. 		otmp->recharged++;
  30. 	    break;
  31.  
  32. 	case POTION_CLASS:
  33. 	    while (otmp->otyp == POT_POLYMORPH)
  34. 		otmp->otyp = rnd_class(POT_GAIN_ABILITY, POT_WATER);
  35. 	    break;
  36.  
  37. 	case SPBOOK_CLASS:
  38. 	    while (otmp->otyp == SPE_POLYMORPH)
  39. 		otmp->otyp = rnd_class(SPE_DIG, SPE_BLANK_PAPER);
  40. 	    /* reduce spellbook abuse */
  41. 	    otmp->spestudied = obj->spestudied + 1;
  42. 	    break;
  43.  
  44. 	case GEM_CLASS:
  45. 	    if (otmp->quan > (long) rnd(4) &&
  46. 		    objects[obj->otyp].oc_material == MINERAL &&
  47. 		    objects[otmp->otyp].oc_material != MINERAL) {
  48. 		otmp->otyp = ROCK;	/* transmutation backfired */
  49. 		otmp->quan /= 2L;	/* some material has been lost */
  50. 	    }
  51. 	    break;
  52. 	}
  53.  
  54. 	/* update the weight */
  55. 	otmp->owt = weight(otmp);
  56.  
  57. 	/* for now, take off worn items being polymorphed */
  58. 	if (obj_location == OBJ_INVENT) {
  59. 	    if (id == STRANGE_OBJECT)
  60. 		remove_worn_item(obj, TRUE);
  61. 	    else {
  62. 		/* This is called only for stone to flesh.  It's a lot simpler
  63. 		 * than it otherwise might be.  We don't need to check for
  64. 		 * special effects when putting them on (no meat objects have
  65. 		 * any) and only three worn masks are possible.
  66. 		 */
  67. 		otmp->owornmask = obj->owornmask;
  68. 		remove_worn_item(obj, TRUE);
  69. 		setworn(otmp, otmp->owornmask);
  70. 		if (otmp->owornmask & LEFT_RING)
  71. 		    uleft = otmp;
  72. 		if (otmp->owornmask & RIGHT_RING)
  73. 		    uright = otmp;
  74. 		if (otmp->owornmask & W_WEP)
  75. 		    uwep = otmp;
  76. 		if (otmp->owornmask & W_SWAPWEP)
  77. 		    uswapwep = otmp;
  78. 		if (otmp->owornmask & W_QUIVER)
  79. 		    uquiver = otmp;
  80. 		goto no_unwear;
  81. 	    }
  82. 	}
  83.  
  84. 	/* preserve the mask in case being used by something else */
  85. 	otmp->owornmask = obj->owornmask;
  86. no_unwear:
  87.  
  88. 	if (obj_location == OBJ_FLOOR && obj->otyp == BOULDER &&
  89. 		otmp->otyp != BOULDER)
  90. 	    unblock_point(obj->ox, obj->oy);
  91.  
  92. 	/* ** we are now done adjusting the object ** */
  93.  
  94.  
  95. 	/* swap otmp for obj */
  96. 	replace_object(obj, otmp);
  97. 	if (obj_location == OBJ_INVENT) {
  98. 	    /*
  99. 	     * We may need to do extra adjustments for the hero if we're
  100. 	     * messing with the hero's inventory.  The following calls are
  101. 	     * equivalent to calling freeinv on obj and addinv on otmp,
  102. 	     * while doing an in-place swap of the actual objects.
  103. 	     */
  104. 	    freeinv_core(obj);
  105. 	    addinv_core1(otmp);
  106. 	    addinv_core2(otmp);
  107. 	}
  108.  
  109. 	if ((!carried(otmp) || obj->unpaid) &&
  110. 		get_obj_location(otmp, &ox, &oy, BURIED_TOO|CONTAINED_TOO) &&
  111. 		costly_spot(ox, oy)) {
  112. 	    register struct monst *shkp =
  113. 		shop_keeper(*in_rooms(ox, oy, SHOPBASE));
  114.  
  115. 	    if ((!obj->no_charge ||
  116. 		 (Has_contents(obj) &&
  117. 		    (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 0L)))
  118. 	       && inhishop(shkp)) {
  119. 		if(shkp->mpeaceful) {
  120. 		    if(*u.ushops && *in_rooms(u.ux, u.uy, 0) ==
  121. 			    *in_rooms(shkp->mx, shkp->my, 0) &&
  122. 			    !costly_spot(u.ux, u.uy))
  123. 			make_angry_shk(shkp, ox, oy);
  124. 		    else {
  125. 			pline("%s gets angry!", Monnam(shkp));
  126. 			hot_pursuit(shkp);
  127. 		    }
  128. 		} else Norep("%s is furious!", Monnam(shkp));
  129. 	    }
  130. 	}
  131. 	delobj(obj);
  132. 	return otmp;
  133. }

bhito

  1. /*
  2. * Object obj was hit by the effect of the wand/spell otmp.  Return
  3. * non-zero if the wand/spell had any effect.
  4. */
  5. int
  6. bhito(obj, otmp)
  7. struct obj *obj, *otmp;
  8. {
  9. 	int res = 1;	/* affected object by default */
  10. 	xchar refresh_x, refresh_y;
  11.  
  12. 	if (obj->bypass) {
  13. 		/* The bypass bit is currently only used as follows:
  14. 		 *
  15. 		 * POLYMORPH - When a monster being polymorphed drops something
  16. 		 *             from its inventory as a result of the change.
  17. 		 *             If the items fall to the floor, they are not
  18. 		 *             subject to direct subsequent polymorphing
  19. 		 *             themselves on that same zap. This makes it
  20. 		 *             consistent with items that remain in the
  21. 		 *             monster's inventory. They are not polymorphed
  22. 		 *             either.
  23. 		 * UNDEAD_TURNING - When an undead creature gets killed via
  24. 		 *	       undead turning, prevent its corpse from being
  25. 		 *	       immediately revived by the same effect.
  26. 		 *
  27. 		 * The bypass bit on all objects is reset each turn, whenever
  28. 		 * flags.bypasses is set.
  29. 		 *
  30. 		 * We check the obj->bypass bit above AND flags.bypasses
  31. 		 * as a safeguard against any stray occurrence left in an obj
  32. 		 * struct someplace, although that should never happen.
  33. 		 */
  34. 		if (flags.bypasses)
  35. 			return 0;
  36. 		else {
  37. #ifdef DEBUG
  38. 			pline("%s for a moment.", Tobjnam(obj, "pulsate"));
  39. #endif
  40. 			obj->bypass = 0;
  41. 		}
  42. 	}
  43.  
  44. 	/*
  45. 	 * Some parts of this function expect the object to be on the floor
  46. 	 * obj->{ox,oy} to be valid.  The exception to this (so far) is
  47. 	 * for the STONE_TO_FLESH spell.
  48. 	 */
  49. 	if (!(obj->where == OBJ_FLOOR || otmp->otyp == SPE_STONE_TO_FLESH))
  50. 	    impossible("bhito: obj is not floor or Stone To Flesh spell");
  51.  
  52. 	if (obj == uball) {
  53. 		res = 0;
  54. 	} else if (obj == uchain) {
  55. 		if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) {
  56. 		    unpunish();
  57. 		    makeknown(otmp->otyp);
  58. 		} else
  59. 		    res = 0;
  60. 	} else
  61. 	switch(otmp->otyp) {
  62. 	case WAN_POLYMORPH:
  63. 	case SPE_POLYMORPH:
  64. 		if (obj->otyp == WAN_POLYMORPH ||
  65. 			obj->otyp == SPE_POLYMORPH ||
  66. 			obj->otyp == POT_POLYMORPH ||
  67. 			obj_resists(obj, 5, 95)) {
  68. 		    res = 0;
  69. 		    break;
  70. 		}
  71. 		/* KMH, conduct */
  72. 		u.uconduct.polypiles++;
  73. 		/* any saved lock context will be dangerously obsolete */
  74. 		if (Is_box(obj)) (void) boxlock(obj, otmp);
  75.  
  76. 		if (obj_shudders(obj)) {
  77. 		    if (cansee(obj->ox, obj->oy))
  78. 			makeknown(otmp->otyp);
  79. 		    do_osshock(obj);
  80. 		    break;
  81. 		}
  82. 		obj = poly_obj(obj, STRANGE_OBJECT);
  83. 		newsym(obj->ox,obj->oy);
  84. 		break;
  85. 	case WAN_PROBING:
  86. 		res = !obj->dknown;
  87. 		/* target object has now been "seen (up close)" */
  88. 		obj->dknown = 1;
  89. 		if (Is_container(obj) || obj->otyp == STATUE) {
  90. 		    if (!obj->cobj)
  91. 			pline("%s empty.", Tobjnam(obj, "are"));
  92. 		    else {
  93. 			struct obj *o;
  94. 			/* view contents (not recursively) */
  95. 			for (o = obj->cobj; o; o = o->nobj)
  96. 			    o->dknown = 1;	/* "seen", even if blind */
  97. 			(void) display_cinventory(obj);
  98. 		    }
  99. 		    res = 1;
  100. 		}
  101. 		if (res) makeknown(WAN_PROBING);
  102. 		break;
  103. 	case WAN_STRIKING:
  104. 	case SPE_FORCE_BOLT:
  105. 		if (obj->otyp == BOULDER)
  106. 			fracture_rock(obj);
  107. 		else if (obj->otyp == STATUE)
  108. 			(void) break_statue(obj);
  109. 		else {
  110. 			if (!flags.mon_moving)
  111. 			    (void)hero_breaks(obj, obj->ox, obj->oy, FALSE);
  112. 			else
  113. 			    (void)breaks(obj, obj->ox, obj->oy);
  114. 			res = 0;
  115. 		}
  116. 		/* BUG[?]: shouldn't this depend upon you seeing it happen? */
  117. 		makeknown(otmp->otyp);
  118. 		break;
  119. 	case WAN_CANCELLATION:
  120. 	case SPE_CANCELLATION:
  121. 		cancel_item(obj);
  122. #ifdef TEXTCOLOR
  123. 		newsym(obj->ox,obj->oy);	/* might change color */
  124. #endif
  125. 		break;
  126. 	case SPE_DRAIN_LIFE:
  127. 		(void) drain_item(obj);
  128. 		break;
  129. 	case WAN_TELEPORTATION:
  130. 	case SPE_TELEPORT_AWAY:
  131. 		rloco(obj);
  132. 		break;
  133. 	case WAN_MAKE_INVISIBLE:
  134. #ifdef INVISIBLE_OBJECTS
  135. 		obj->oinvis = TRUE;
  136. 		newsym(obj->ox,obj->oy);	/* make object disappear */
  137. #endif
  138. 		break;
  139. 	case WAN_UNDEAD_TURNING:
  140. 	case SPE_TURN_UNDEAD:
  141. 		if (obj->otyp == EGG)
  142. 			revive_egg(obj);
  143. 		else
  144. 			res = !!revive(obj);
  145. 		break;
  146. 	case WAN_OPENING:
  147. 	case SPE_KNOCK:
  148. 	case WAN_LOCKING:
  149. 	case SPE_WIZARD_LOCK:
  150. 		if(Is_box(obj))
  151. 			res = boxlock(obj, otmp);
  152. 		else
  153. 			res = 0;
  154. 		if (res /* && otmp->oclass == WAND_CLASS */)
  155. 			makeknown(otmp->otyp);
  156. 		break;
  157. 	case WAN_SLOW_MONSTER:		/* no effect on objects */
  158. 	case SPE_SLOW_MONSTER:
  159. 	case WAN_SPEED_MONSTER:
  160. 	case WAN_NOTHING:
  161. 	case SPE_HEALING:
  162. 	case SPE_EXTRA_HEALING:
  163. 		res = 0;
  164. 		break;
  165. 	case SPE_STONE_TO_FLESH:
  166. 		refresh_x = obj->ox; refresh_y = obj->oy;
  167. 		if (objects[obj->otyp].oc_material != MINERAL &&
  168. 			objects[obj->otyp].oc_material != GEMSTONE) {
  169. 		    res = 0;
  170. 		    break;
  171. 		}
  172. 		/* add more if stone objects are added.. */
  173. 		switch (objects[obj->otyp].oc_class) {
  174. 		    case ROCK_CLASS:	/* boulders and statues */
  175. 			if (obj->otyp == BOULDER) {
  176. 			    obj = poly_obj(obj, HUGE_CHUNK_OF_MEAT);
  177. 			    goto smell;
  178. 			} else if (obj->otyp == STATUE) {
  179. 			    xchar oox, ooy;
  180.  
  181. 			    (void) get_obj_location(obj, &oox, &ooy, 0);
  182. 			    refresh_x = oox; refresh_y = ooy;
  183. 			    if (vegetarian(&mons[obj->corpsenm])) {
  184. 				/* Don't animate monsters that aren't flesh */
  185. 				obj = poly_obj(obj, MEATBALL);
  186. 			    	goto smell;
  187. 			    }
  188. 			    if (!animate_statue(obj, oox, ooy,
  189. 						ANIMATE_SPELL, (int *)0)) {
  190. 				struct obj *item;
  191. makecorpse:			if (mons[obj->corpsenm].geno &
  192. 							(G_NOCORPSE|G_UNIQ)) {
  193. 				    res = 0;
  194. 				    break;
  195. 				}
  196. 				/* Unlikely to get here since genociding
  197. 				 * monsters also sets the G_NOCORPSE flag.
  198. 				 * Drop the contents, poly_obj looses them.
  199. 				 */
  200. 				while ((item = obj->cobj) != 0) {
  201. 				    obj_extract_self(item);
  202. 				    place_object(item, oox, ooy);
  203. 				}
  204. 				obj = poly_obj(obj, CORPSE);
  205. 				break;
  206. 			    }
  207. 			} else { /* new rock class object... */
  208. 			    /* impossible? */
  209. 			    res = 0;
  210. 			}
  211. 			break;
  212. 		    case TOOL_CLASS:	/* figurine */
  213. 		    {
  214. 			struct monst *mon;
  215. 			xchar oox, ooy;
  216.  
  217. 			if (obj->otyp != FIGURINE) {
  218. 			    res = 0;
  219. 			    break;
  220. 			}
  221. 			if (vegetarian(&mons[obj->corpsenm])) {
  222. 			    /* Don't animate monsters that aren't flesh */
  223. 			    obj = poly_obj(obj, MEATBALL);
  224. 			    goto smell;
  225. 			}
  226. 			(void) get_obj_location(obj, &oox, &ooy, 0);
  227. 			refresh_x = oox; refresh_y = ooy;
  228. 			mon = makemon(&mons[obj->corpsenm],
  229. 				      oox, ooy, NO_MM_FLAGS);
  230. 			if (mon) {
  231. 			    delobj(obj);
  232. 			    if (cansee(mon->mx, mon->my))
  233. 				pline_The("figurine animates!");
  234. 			    break;
  235. 			}
  236. 			goto makecorpse;
  237. 		    }
  238. 		    /* maybe add weird things to become? */
  239. 		    case RING_CLASS:	/* some of the rings are stone */
  240. 			obj = poly_obj(obj, MEAT_RING);
  241. 			goto smell;
  242. 		    case WAND_CLASS:	/* marble wand */
  243. 			obj = poly_obj(obj, MEAT_STICK);
  244. 			goto smell;
  245. 		    case GEM_CLASS:	/* rocks & gems */
  246. 			obj = poly_obj(obj, MEATBALL);
  247. smell:
  248. 			if (herbivorous(youmonst.data) &&
  249. 			    (!carnivorous(youmonst.data) ||
  250. 			     Role_if(PM_MONK) || !u.uconduct.unvegetarian))
  251. 			    Norep("You smell the odor of meat.");
  252. 			else
  253. 			    Norep("You smell a delicious smell.");
  254. 			break;
  255. 		    case WEAPON_CLASS:	/* crysknife */
  256. 		    	/* fall through */
  257. 		    default:
  258. 			res = 0;
  259. 			break;
  260. 		}
  261. 		newsym(refresh_x, refresh_y);
  262. 		break;
  263. 	default:
  264. 		impossible("What an interesting effect (%d)", otmp->otyp);
  265. 		break;
  266. 	}
  267. 	return res;
  268. }

bhitpile

  1. /* returns nonzero if something was hit */
  2. int
  3. bhitpile(obj,fhito,tx,ty)
  4. 	struct obj *obj;
  5. 	int FDECL((*fhito), (OBJ_P,OBJ_P));
  6. 	int tx, ty;
  7. {
  8. 	int hitanything = 0;
  9. 	register struct obj *otmp, *next_obj;
  10.  
  11. 	if (obj->otyp == SPE_FORCE_BOLT || obj->otyp == WAN_STRIKING) {
  12. 	struct trap *t = t_at(tx, ty);
  13.  
  14. 	/* We can't settle for the default calling sequence of
  15. 	   bhito(otmp) -> break_statue(otmp) -> activate_statue_trap(ox,oy)
  16. 	   because that last call might end up operating on our `next_obj'
  17. 	   (below), rather than on the current object, if it happens to
  18. 	   encounter a statue which mustn't become animated. */
  19. 	if (t && t->ttyp == STATUE_TRAP &&
  20. 	    activate_statue_trap(t, tx, ty, TRUE) && obj->otyp == WAN_STRIKING)
  21. 	    makeknown(obj->otyp);
  22. 	}
  23.  
  24. 	poly_zapped = -1;
  25. 	for(otmp = level.objects[tx][ty]; otmp; otmp = next_obj) {
  26. 	/* Fix for polymorph bug, Tim Wright */
  27. 	next_obj = otmp->nexthere;
  28. 	hitanything += (*fhito)(otmp, obj);
  29. 	}
  30. 	if(poly_zapped >= 0)
  31. 	create_polymon(level.objects[tx][ty], poly_zapped);
  32.  
  33. 	return hitanything;
  34. }
  35. #endif /*OVLB*/

zappable

  1. #ifdef OVL1
  2.  
  3. /*
  4. * zappable - returns 1 if zap is available, 0 otherwise.
  5. *	      it removes a charge from the wand if zappable.
  6. * added by GAN 11/03/86
  7. */
  8. int
  9. zappable(wand)
  10. register struct obj *wand;
  11. {
  12. 	if(wand->spe < 0 || (wand->spe == 0 && rn2(121)))
  13. 		return 0;
  14. 	if(wand->spe == 0)
  15. 		You("wrest one last charge from the worn-out wand.");
  16. 	wand->spe--;
  17. 	return 1;
  18. }

zapnodir

  1. /*
  2. * zapnodir - zaps a NODIR wand/spell.
  3. * added by GAN 11/03/86
  4. */
  5. void
  6. zapnodir(obj)
  7. register struct obj *obj;
  8. {
  9. 	boolean known = FALSE;
  10.  
  11. 	switch(obj->otyp) {
  12. 		case WAN_LIGHT:
  13. 		case SPE_LIGHT:
  14. 			litroom(TRUE,obj);
  15. 			if (!Blind) known = TRUE;
  16. 			break;
  17. 		case WAN_SECRET_DOOR_DETECTION:
  18. 		case SPE_DETECT_UNSEEN:
  19. 			if(!findit()) return;
  20. 			if (!Blind) known = TRUE;
  21. 			break;
  22. 		case WAN_CREATE_MONSTER:
  23. 			known = create_critters(rn2(23) ? 1 : rn1(7,2),
  24. 					(struct permonst *)0);
  25. 			break;
  26. 		case WAN_WISHING:
  27. 			known = TRUE;
  28. 			if(Luck + rn2(5) < 0) {
  29. 				pline("Unfortunately, nothing happens.");
  30. 				break;
  31. 			}
  32. 			makewish();
  33. 			break;
  34. 		case WAN_ENLIGHTENMENT:
  35. 			known = TRUE;
  36. 			You_feel("self-knowledgeable...");
  37. 			display_nhwindow(WIN_MESSAGE, FALSE);
  38. 			enlightenment(FALSE);
  39. 			pline_The("feeling subsides.");
  40. 			exercise(A_WIS, TRUE);
  41. 			break;
  42. 	}
  43. 	if (known && !objects[obj->otyp].oc_name_known) {
  44. 		makeknown(obj->otyp);
  45. 		more_experienced(0,10);
  46. 	}
  47. }
  48. #endif /*OVL1*/
  49. #ifdef OVL0

backfire

  1. STATIC_OVL void
  2. backfire(otmp)
  3. struct obj *otmp;
  4. {
  5. 	otmp->in_use = TRUE;	/* in case losehp() is fatal */
  6. 	pline("%s suddenly explodes!", The(xname(otmp)));
  7. 	losehp(d(otmp->spe+2,6), "exploding wand", KILLED_BY_AN);
  8. 	useup(otmp);
  9. }

dozap

This is the first function to execute when the player wants to zap a wand. It is called by rhack, because it is the handler defined for the "z" command by the cmdlist array in cmd.c.

When a player zaps a wand, execution flows thusly: moveloop in allmain.c -> rhack in cmd.c -> here.

zapyourself and weffects (wand effects) handle the wands work. weffects delegates to several other functions: zap_steed; bhitm (beam hit monster) to hit a monster that has you engulfed when you zap a beam wand, zap_updown for zapping a beam wand up or down, and bhit (beam hit) for zapping such a wand outwards; zap_nodir for zapping a directionless wand; zap_dig and buzz handle zapping ray based wands up, down, and outwards.

zap.c has many functions for handling the intricacies of wand zapping, and many of these functions call each other. bhit for instance calls bhitpile and bhitm when it finds item piles and monsters in the path of the beam. bhitpile calls bhito (beam hit object) to actually affect the items.

  1. static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 };
  2.  
  3. int
  4. dozap()
  5. {
  6. 	register struct obj *obj;
  7. 	int	damage;
  8.  
  9. 	if(check_capacity((char *)0)) return(0);
  10. 	obj = getobj(zap_syms, "zap");
  11. 	if(!obj) return(0);
  12.  
  13. 	check_unpaid(obj);
  14.  
  15. 	/* zappable addition done by GAN 11/03/86 */
  16. 	if(!zappable(obj)) pline(nothing_happens);
  17. 	else if(obj->cursed && !rn2(100)) {
  18. 		backfire(obj);	/* the wand blows up in your face! */
  19. 		exercise(A_STR, FALSE);
  20. 		return(1);
  21. 	} else if(!(objects[obj->otyp].oc_dir == NODIR) && !getdir((char *)0)) {
  22. 		if (!Blind)
  23. 		    pline("%s glows and fades.", The(xname(obj)));
  24. 		/* make him pay for knowing !NODIR */
  25. 	} else if(!u.dx && !u.dy && !u.dz && !(objects[obj->otyp].oc_dir == NODIR)) {
  26. 	    if ((damage = zapyourself(obj, TRUE)) != 0) {
  27. 		char buf[BUFSZ];
  28. 		Sprintf(buf, "zapped %sself with a wand", uhim());
  29. 		losehp(damage, buf, NO_KILLER_PREFIX);
  30. 	    }
  31. 	} else {
  32.  
  33. 		/*	Are we having fun yet?
  34. 		 * weffects -> buzz(obj->otyp) -> zhitm (temple priest) ->
  35. 		 * attack -> hitum -> known_hitum -> ghod_hitsu ->
  36. 		 * buzz(AD_ELEC) -> destroy_item(WAND_CLASS) ->
  37. 		 * useup -> obfree -> dealloc_obj -> free(obj)
  38. 		 */
  39. 		current_wand = obj;
  40. 		weffects(obj);
  41. 		obj = current_wand;
  42. 		current_wand = 0;
  43. 	}
  44. 	if (obj && obj->spe < 0) {
  45. 	    pline("%s to dust.", Tobjnam(obj, "turn"));
  46. 	    useup(obj);
  47. 	}
  48. 	update_inventory();	/* maybe used a charge */
  49. 	return(1);
  50. }

zapyourself

  1. int
  2. zapyourself(obj, ordinary)
  3. struct obj *obj;
  4. boolean ordinary;
  5. {
  6. 	int	damage = 0;
  7. 	char buf[BUFSZ];
  8.  
  9. 	switch(obj->otyp) {
  10. 		case WAN_STRIKING:
  11. 		    makeknown(WAN_STRIKING);
  12. 		case SPE_FORCE_BOLT:
  13. 		    if(Antimagic) {
  14. 			shieldeff(u.ux, u.uy);
  15. 			pline("Boing!");
  16. 		    } else {
  17. 			if (ordinary) {
  18. 			    You("bash yourself!");
  19. 			    damage = d(2,12);
  20. 			} else
  21. 			    damage = d(1 + obj->spe,6);
  22. 			exercise(A_STR, FALSE);
  23. 		    }
  24. 		    break;
  25.  
  26. 		case WAN_LIGHTNING:
  27. 		    makeknown(WAN_LIGHTNING);
  28. 		    if (!Shock_resistance) {
  29. 			You("shock yourself!");
  30. 			damage = d(12,6);
  31. 			exercise(A_CON, FALSE);
  32. 		    } else {
  33. 			shieldeff(u.ux, u.uy);
  34. 			You("zap yourself, but seem unharmed.");
  35. 			ugolemeffects(AD_ELEC, d(12,6));
  36. 		    }
  37. 		    destroy_item(WAND_CLASS, AD_ELEC);
  38. 		    destroy_item(RING_CLASS, AD_ELEC);
  39. 		    if (!resists_blnd(&youmonst)) {
  40. 			    You(are_blinded_by_the_flash);
  41. 			    make_blinded((long)rnd(100),FALSE);
  42. 			    if (!Blind) Your(vision_clears);
  43. 		    }
  44. 		    break;
  45.  
  46. 		case SPE_FIREBALL:
  47. 		    You("explode a fireball on top of yourself!");
  48. 		    explode(u.ux, u.uy, 11, d(6,6), WAND_CLASS, EXPL_FIERY);
  49. 		    break;
  50. 		case WAN_FIRE:
  51. 		    makeknown(WAN_FIRE);
  52. 		case FIRE_HORN:
  53. 		    if (Fire_resistance) {
  54. 			shieldeff(u.ux, u.uy);
  55. 			You_feel("rather warm.");
  56. 			ugolemeffects(AD_FIRE, d(12,6));
  57. 		    } else {
  58. 			pline("You've set yourself afire!");
  59. 			damage = d(12,6);
  60. 		    }
  61. 		    burn_away_slime();
  62. 		    (void) burnarmor(&youmonst);
  63. 		    destroy_item(SCROLL_CLASS, AD_FIRE);
  64. 		    destroy_item(POTION_CLASS, AD_FIRE);
  65. 		    destroy_item(SPBOOK_CLASS, AD_FIRE);
  66. 		    break;
  67.  
  68. 		case WAN_COLD:
  69. 		    makeknown(WAN_COLD);
  70. 		case SPE_CONE_OF_COLD:
  71. 		case FROST_HORN:
  72. 		    if (Cold_resistance) {
  73. 			shieldeff(u.ux, u.uy);
  74. 			You_feel("a little chill.");
  75. 			ugolemeffects(AD_COLD, d(12,6));
  76. 		    } else {
  77. 			You("imitate a popsicle!");
  78. 			damage = d(12,6);
  79. 		    }
  80. 		    destroy_item(POTION_CLASS, AD_COLD);
  81. 		    break;
  82.  
  83. 		case WAN_MAGIC_MISSILE:
  84. 		    makeknown(WAN_MAGIC_MISSILE);
  85. 		case SPE_MAGIC_MISSILE:
  86. 		    if(Antimagic) {
  87. 			shieldeff(u.ux, u.uy);
  88. 			pline_The("missiles bounce!");
  89. 		    } else {
  90. 			damage = d(4,6);
  91. 			pline("Idiot!  You've shot yourself!");
  92. 		    }
  93. 		    break;
  94.  
  95. 		case WAN_POLYMORPH:
  96. 		    if (!Unchanging)
  97. 		    	makeknown(WAN_POLYMORPH);
  98. 		case SPE_POLYMORPH:
  99. 		    if (!Unchanging)
  100. 		    	polyself(FALSE);
  101. 		    break;
  102.  
  103. 		case WAN_CANCELLATION:
  104. 		case SPE_CANCELLATION:
  105. 		    (void) cancel_monst(&youmonst, obj, TRUE, FALSE, TRUE);
  106. 		    break;
  107.  
  108. 		case SPE_DRAIN_LIFE:
  109. 			if (!Drain_resistance) {
  110. 				losexp("life drainage");
  111. 				makeknown(obj->otyp);
  112. 			}
  113. 			damage = 0;	/* No additional damage */
  114. 			break;
  115.  
  116. 		case WAN_MAKE_INVISIBLE: {
  117. 		    /* have to test before changing HInvis but must change
  118. 		     * HInvis before doing newsym().
  119. 		     */
  120. 		    int msg = !Invis && !Blind && !BInvis;
  121.  
  122. 		    if (BInvis && uarmc->otyp == MUMMY_WRAPPING) {
  123. 			/* A mummy wrapping absorbs it and protects you */
  124. 		        You_feel("rather itchy under your %s.", xname(uarmc));
  125. 		        break;
  126. 		    }
  127. 		    if (ordinary || !rn2(10)) {	/* permanent */
  128. 			HInvis |= FROMOUTSIDE;
  129. 		    } else {			/* temporary */
  130. 		    	incr_itimeout(&HInvis, d(obj->spe, 250));
  131. 		    }
  132. 		    if (msg) {
  133. 			makeknown(WAN_MAKE_INVISIBLE);
  134. 			newsym(u.ux, u.uy);
  135. 			self_invis_message();
  136. 		    }
  137. 		    break;
  138. 		}
  139.  
  140. 		case WAN_SPEED_MONSTER:
  141. 		    if (!(HFast & INTRINSIC)) {
  142. 			if (!Fast)
  143. 			    You("speed up.");
  144. 			else
  145. 			    Your("quickness feels more natural.");
  146. 			makeknown(WAN_SPEED_MONSTER);
  147. 			exercise(A_DEX, TRUE);
  148. 		    }
  149. 		    HFast |= FROMOUTSIDE;
  150. 		    break;
  151.  
  152. 		case WAN_SLEEP:
  153. 		    makeknown(WAN_SLEEP);
  154. 		case SPE_SLEEP:
  155. 		    if(Sleep_resistance) {
  156. 			shieldeff(u.ux, u.uy);
  157. 			You("don't feel sleepy!");
  158. 		    } else {
  159. 			pline_The("sleep ray hits you!");
  160. 			fall_asleep(-rnd(50), TRUE);
  161. 		    }
  162. 		    break;
  163.  
  164. 		case WAN_SLOW_MONSTER:
  165. 		case SPE_SLOW_MONSTER:
  166. 		    if(HFast & (TIMEOUT | INTRINSIC)) {
  167. 			u_slow_down();
  168. 			makeknown(obj->otyp);
  169. 		    }
  170. 		    break;
  171.  
  172. 		case WAN_TELEPORTATION:
  173. 		case SPE_TELEPORT_AWAY:
  174. 		    tele();
  175. 		    break;
  176.  
  177. 		case WAN_DEATH:
  178. 		case SPE_FINGER_OF_DEATH:
  179. 		    if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
  180. 			pline((obj->otyp == WAN_DEATH) ?
  181. 			  "The wand shoots an apparently harmless beam at you."
  182. 			  : "You seem no deader than before.");
  183. 			break;
  184. 		    }
  185. 		    Sprintf(buf, "shot %sself with a death ray", uhim());
  186. 		    killer = buf;
  187. 		    killer_format = NO_KILLER_PREFIX;
  188. 		    You("irradiate yourself with pure energy!");
  189. 		    You("die.");
  190. 		    makeknown(obj->otyp);
  191. 			/* They might survive with an amulet of life saving */
  192. 		    done(DIED);
  193. 		    break;
  194. 		case WAN_UNDEAD_TURNING:
  195. 		    makeknown(WAN_UNDEAD_TURNING);
  196. 		case SPE_TURN_UNDEAD:
  197. 		    (void) unturn_dead(&youmonst);
  198. 		    if (is_undead(youmonst.data)) {
  199. 			You_feel("frightened and %sstunned.",
  200. 			     Stunned ? "even more " : "");
  201. 			make_stunned(HStun + rnd(30), FALSE);
  202. 		    } else
  203. 			You("shudder in dread.");
  204. 		    break;
  205. 		case SPE_HEALING:
  206. 		case SPE_EXTRA_HEALING:
  207. 		    healup(d(6, obj->otyp == SPE_EXTRA_HEALING ? 8 : 4),
  208. 			   0, FALSE, (obj->otyp == SPE_EXTRA_HEALING));
  209. 		    You_feel("%sbetter.",
  210. 			obj->otyp == SPE_EXTRA_HEALING ? "much " : "");
  211. 		    break;
  212. 		case WAN_LIGHT:	/* (broken wand) */
  213. 		 /* assert( !ordinary ); */
  214. 		    damage = d(obj->spe, 25);
  215. #ifdef TOURIST
  216. 		case EXPENSIVE_CAMERA:
  217. #endif
  218. 		    damage += rnd(25);
  219. 		    if (!resists_blnd(&youmonst)) {
  220. 			You(are_blinded_by_the_flash);
  221. 			make_blinded((long)damage, FALSE);
  222. 			makeknown(obj->otyp);
  223. 			if (!Blind) Your(vision_clears);
  224. 		    }
  225. 		    damage = 0;	/* reset */
  226. 		    break;
  227. 		case WAN_OPENING:
  228. 		    if (Punished) makeknown(WAN_OPENING);
  229. 		case SPE_KNOCK:
  230. 		    if (Punished) Your("chain quivers for a moment.");
  231. 		    break;
  232. 		case WAN_DIGGING:
  233. 		case SPE_DIG:
  234. 		case SPE_DETECT_UNSEEN:
  235. 		case WAN_NOTHING:
  236. 		case WAN_LOCKING:
  237. 		case SPE_WIZARD_LOCK:
  238. 		    break;
  239. 		case WAN_PROBING:
  240. 		    for (obj = invent; obj; obj = obj->nobj)
  241. 			obj->dknown = 1;
  242. 		    /* note: `obj' reused; doesn't point at wand anymore */
  243. 		    makeknown(WAN_PROBING);
  244. 		    ustatusline();
  245. 		    break;
  246. 		case SPE_STONE_TO_FLESH:
  247. 		    {
  248. 		    struct obj *otemp, *onext;
  249. 		    boolean didmerge;
  250.  
  251. 		    if (u.umonnum == PM_STONE_GOLEM)
  252. 			(void) polymon(PM_FLESH_GOLEM);
  253. 		    if (Stoned) fix_petrification();	/* saved! */
  254. 		    /* but at a cost.. */
  255. 		    for (otemp = invent; otemp; otemp = onext) {
  256. 			onext = otemp->nobj;
  257. 			(void) bhito(otemp, obj);
  258. 			}
  259. 		    /*
  260. 		     * It is possible that we can now merge some inventory.
  261. 		     * Do a higly paranoid merge.  Restart from the beginning
  262. 		     * until no merges.
  263. 		     */
  264. 		    do {
  265. 			didmerge = FALSE;
  266. 			for (otemp = invent; !didmerge && otemp; otemp = otemp->nobj)
  267. 			    for (onext = otemp->nobj; onext; onext = onext->nobj)
  268. 			    	if (merged(&otemp, &onext)) {
  269. 			    		didmerge = TRUE;
  270. 			    		break;
  271. 			    		}
  272. 		    } while (didmerge);
  273. 		    }
  274. 		    break;
  275. 		default: impossible("object %d used?",obj->otyp);
  276. 		    break;
  277. 	}
  278. 	return(damage);
  279. }

zap_steed

  1. #ifdef STEED
  2. /* you've zapped a wand downwards while riding
  3. * Return TRUE if the steed was hit by the wand.
  4. * Return FALSE if the steed was not hit by the wand.
  5. */
  6. STATIC_OVL boolean
  7. zap_steed(obj)
  8. struct obj *obj;	/* wand or spell */
  9. {
  10. 	int steedhit = FALSE;
  11.  
  12. 	switch (obj->otyp) {
  13.  
  14. 	   /*
  15. 	    * Wands that are allowed to hit the steed
  16. 	    * Carefully test the results of any that are
  17. 	    * moved here from the bottom section.
  18. 	    */
  19. 		case WAN_PROBING:
  20. 		    probe_monster(u.usteed);
  21. 		    makeknown(WAN_PROBING);
  22. 		    steedhit = TRUE;
  23. 		    break;
  24. 		case WAN_TELEPORTATION:
  25. 		case SPE_TELEPORT_AWAY:
  26. 		    /* you go together */
  27. 		    tele();
  28. 		    if(Teleport_control || !couldsee(u.ux0, u.uy0) ||
  29. 			(distu(u.ux0, u.uy0) >= 16))
  30. 				makeknown(obj->otyp);
  31. 		    steedhit = TRUE;
  32. 		    break;
  33.  
  34. 		/* Default processing via bhitm() for these */
  35. 		case SPE_CURE_SICKNESS:
  36. 		case WAN_MAKE_INVISIBLE:
  37. 		case WAN_CANCELLATION:
  38. 		case SPE_CANCELLATION:
  39. 		case WAN_POLYMORPH:
  40. 		case SPE_POLYMORPH:
  41. 		case WAN_STRIKING:
  42. 		case SPE_FORCE_BOLT:
  43. 		case WAN_SLOW_MONSTER:
  44. 		case SPE_SLOW_MONSTER:
  45. 		case WAN_SPEED_MONSTER:
  46. 		case SPE_HEALING:
  47. 		case SPE_EXTRA_HEALING:
  48. 		case SPE_DRAIN_LIFE:
  49. 		case WAN_OPENING:
  50. 		case SPE_KNOCK:
  51. 		    (void) bhitm(u.usteed, obj);
  52. 		    steedhit = TRUE;
  53. 		    break;
  54.  
  55. 		default:
  56. 		    steedhit = FALSE;
  57. 		    break;
  58. 	}
  59. 	return steedhit;
  60. }
  61. #endif
  62.  
  63. #endif /*OVL0*/

cancel_monst

  1. #ifdef OVL3
  2.  
  3. /*
  4. * cancel a monster (possibly the hero).  inventory is cancelled only
  5. * if the monster is zapping itself directly, since otherwise the
  6. * effect is too strong.  currently non-hero monsters do not zap
  7. * themselves with cancellation.
  8. */
  9. boolean
  10. cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel)
  11. register struct monst	*mdef;
  12. register struct obj	*obj;
  13. boolean			youattack, allow_cancel_kill, self_cancel;
  14. {
  15. 	boolean	youdefend = (mdef == &youmonst);
  16. 	static const char writing_vanishes[] =
  17. 				"Some writing vanishes from %s head!";
  18. 	static const char your[] = "your";	/* should be extern */
  19.  
  20. 	if (youdefend ? (!youattack && Antimagic)
  21. 		      : resist(mdef, obj->oclass, 0, NOTELL))
  22. 		return FALSE;	/* resisted cancellation */
  23.  
  24. 	if (self_cancel) {	/* 1st cancel inventory */
  25. 	    struct obj *otmp;
  26.  
  27. 	    for (otmp = (youdefend ? invent : mdef->minvent);
  28. 			    otmp; otmp = otmp->nobj)
  29. 		cancel_item(otmp);
  30. 	    if (youdefend) {
  31. 		flags.botl = 1;	/* potential AC change */
  32. 		find_ac();
  33. 	    }
  34. 	}
  35.  
  36. 	/* now handle special cases */
  37. 	if (youdefend) {
  38. 	    if (Upolyd) {
  39. 		if ((u.umonnum == PM_CLAY_GOLEM) && !Blind)
  40. 		    pline(writing_vanishes, your);
  41.  
  42. 		if (Unchanging)
  43. 		    Your("amulet grows hot for a moment, then cools.");
  44. 		else
  45. 		    rehumanize();
  46. 	    }
  47. 	} else {
  48. 	    mdef->mcan = TRUE;
  49.  
  50. 	    if (is_were(mdef->data) && mdef->data->mlet != S_HUMAN)
  51. 		were_change(mdef);
  52.  
  53. 	    if (mdef->data == &mons[PM_CLAY_GOLEM]) {
  54. 		if (canseemon(mdef))
  55. 		    pline(writing_vanishes, s_suffix(mon_nam(mdef)));
  56.  
  57. 		if (allow_cancel_kill) {
  58. 		    if (youattack)
  59. 			killed(mdef);
  60. 		    else
  61. 			monkilled(mdef, "", AD_SPEL);
  62. 		}
  63. 	    }
  64. 	}
  65. 	return TRUE;
  66. }

zap_updown

  1. /* you've zapped an immediate type wand up or down */
  2. STATIC_OVL boolean
  3. zap_updown(obj)
  4. struct obj *obj;	/* wand or spell */
  5. {
  6. 	boolean striking = FALSE, disclose = FALSE;
  7. 	int x, y, xx, yy, ptmp;
  8. 	struct obj *otmp;
  9. 	struct engr *e;
  10. 	struct trap *ttmp;
  11. 	char buf[BUFSZ];
  12.  
  13. 	/* some wands have special effects other than normal bhitpile */
  14. 	/* drawbridge might change <nowiki><</nowiki>u.ux,u.uy> */
  15. 	x = xx = u.ux;	/* <x,y> is zap location */
  16. 	y = yy = u.uy;	/* <xx,yy> is drawbridge (portcullis) position */
  17. 	ttmp = t_at(x, y); /* trap if there is one */
  18.  
  19. 	switch (obj->otyp) {
  20. 	case WAN_PROBING:
  21. 	    ptmp = 0;
  22. 	    if (u.dz < 0) {
  23. 		You("probe towards the %s.", ceiling(x,y));
  24. 	    } else {
  25. 		ptmp += bhitpile(obj, bhito, x, y);
  26. 		You("probe beneath the %s.", surface(x,y));
  27. 		ptmp += display_binventory(x, y, TRUE);
  28. 	    }
  29. 	    if (!ptmp) Your("probe reveals nothing.");
  30. 	    return TRUE;	/* we've done our own bhitpile */
  31. 	case WAN_OPENING:
  32. 	case SPE_KNOCK:
  33. 	    /* up or down, but at closed portcullis only */
  34. 	    if (is_db_wall(x,y) && find_drawbridge(&xx, &yy)) {
  35. 		open_drawbridge(xx, yy);
  36. 		disclose = TRUE;
  37. 	    } else if (u.dz > 0 && (x == xdnstair && y == ydnstair) &&
  38. 			/* can't use the stairs down to quest level 2 until
  39. 			   leader "unlocks" them; give feedback if you try */
  40. 			on_level(&u.uz, &qstart_level) && !ok_to_quest()) {
  41. 		pline_The("stairs seem to ripple momentarily.");
  42. 		disclose = TRUE;
  43. 	    }
  44. 	    break;
  45. 	case WAN_STRIKING:
  46. 	case SPE_FORCE_BOLT:
  47. 	    striking = TRUE;
  48. 	    /*FALLTHRU*/
  49. 	case WAN_LOCKING:
  50. 	case SPE_WIZARD_LOCK:
  51. 	    /* down at open bridge or up or down at open portcullis */
  52. 	    if ((levl[x][y].typ == DRAWBRIDGE_DOWN) ? (u.dz > 0) :
  53. 			(is_drawbridge_wall(x,y) && !is_db_wall(x,y)) &&
  54. 		    find_drawbridge(&xx, &yy)) {
  55. 		if (!striking)
  56. 		    close_drawbridge(xx, yy);
  57. 		else
  58. 		    destroy_drawbridge(xx, yy);
  59. 		disclose = TRUE;
  60. 	    } else if (striking && u.dz < 0 && rn2(3) &&
  61. 			!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) &&
  62. 			!Underwater && !Is_qstart(&u.uz)) {
  63. 		/* similar to zap_dig() */
  64. 		pline("A rock is dislodged from the %s and falls on your %s.",
  65. 		      ceiling(x, y), body_part(HEAD));
  66. 		losehp(rnd((uarmh && is_metallic(uarmh)) ? 2 : 6),
  67. 		       "falling rock", KILLED_BY_AN);
  68. 		if ((otmp = mksobj_at(ROCK, x, y, FALSE, FALSE)) != 0) {
  69. 		    (void)xname(otmp);	/* set dknown, maybe bknown */
  70. 		    stackobj(otmp);
  71. 		}
  72. 		newsym(x, y);
  73. 	    } else if (!striking && ttmp && ttmp->ttyp == TRAPDOOR && u.dz > 0) {
  74. 		if (!Blind) {
  75. 			if (ttmp->tseen) {
  76. 				pline("A trap door beneath you closes up then vanishes.");
  77. 				disclose = TRUE;
  78. 			} else {
  79. 				You("see a swirl of %s beneath you.",
  80. 					is_ice(x,y) ? "frost" : "dust");
  81. 			}
  82. 		} else {
  83. 			You_hear("a twang followed by a thud.");
  84. 		}
  85. 		deltrap(ttmp);
  86. 		ttmp = (struct trap *)0;
  87. 		newsym(x, y);
  88. 	    }
  89. 	    break;
  90. 	case SPE_STONE_TO_FLESH:
  91. 	    if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) ||
  92. 		     Underwater || (Is_qstart(&u.uz) && u.dz < 0)) {
  93. 		pline(nothing_happens);
  94. 	    } else if (u.dz < 0) {	/* we should do more... */
  95. 		pline("Blood drips on your %s.", body_part(FACE));
  96. 	    } else if (u.dz > 0 && !OBJ_AT(u.ux, u.uy)) {
  97. 		/*
  98. 		Print this message only if there wasn't an engraving
  99. 		affected here.  If water or ice, act like waterlevel case.
  100. 		*/
  101. 		e = engr_at(u.ux, u.uy);
  102. 		if (!(e && e->engr_type == ENGRAVE)) {
  103. 		    if (is_pool(u.ux, u.uy) || is_ice(u.ux, u.uy))
  104. 			pline(nothing_happens);
  105. 		    else
  106. 			pline("Blood %ss %s your %s.",
  107. 			      is_lava(u.ux, u.uy) ? "boil" : "pool",
  108. 			      Levitation ? "beneath" : "at",
  109. 			      makeplural(body_part(FOOT)));
  110. 		}
  111. 	    }
  112. 	    break;
  113. 	default:
  114. 	    break;
  115. 	}
  116.  
  117. 	if (u.dz > 0) {
  118. 	    /* zapping downward */
  119. 	    (void) bhitpile(obj, bhito, x, y);
  120.  
  121. 	    /* subset of engraving effects; none sets `disclose' */
  122. 	    if ((e = engr_at(x, y)) != 0 && e->engr_type != HEADSTONE) {
  123. 		switch (obj->otyp) {
  124. 		case WAN_POLYMORPH:
  125. 		case SPE_POLYMORPH:
  126. 		    del_engr(e);
  127. 		    make_engr_at(x, y, random_engraving(buf), moves, (xchar)0);
  128. 		    break;
  129. 		case WAN_CANCELLATION:
  130. 		case SPE_CANCELLATION:
  131. 		case WAN_MAKE_INVISIBLE:
  132. 		    del_engr(e);
  133. 		    break;
  134. 		case WAN_TELEPORTATION:
  135. 		case SPE_TELEPORT_AWAY:
  136. 		    rloc_engr(e);
  137. 		    break;
  138. 		case SPE_STONE_TO_FLESH:
  139. 		    if (e->engr_type == ENGRAVE) {
  140. 			/* only affects things in stone */
  141. 			pline_The(Hallucination ?
  142. 			    "floor runs like butter!" :
  143. 			    "edges on the floor get smoother.");
  144. 			wipe_engr_at(x, y, d(2,4));
  145. 			}
  146. 		    break;
  147. 		case WAN_STRIKING:
  148. 		case SPE_FORCE_BOLT:
  149. 		    wipe_engr_at(x, y, d(2,4));
  150. 		    break;
  151. 		default:
  152. 		    break;
  153. 		}
  154. 	    }
  155. 	}
  156.  
  157. 	return disclose;
  158. }
  159.  
  160. #endif /*OVL3*/

weffects

  1. #ifdef OVLB
  2.  
  3. /* called for various wand and spell effects - M. Stephenson */
  4. void
  5. weffects(obj)
  6. register struct	obj	*obj;
  7. {
  8. 	int otyp = obj->otyp;
  9. 	boolean disclose = FALSE, was_unkn = !objects[otyp].oc_name_known;
  10.  
  11. 	exercise(A_WIS, TRUE);
  12. #ifdef STEED
  13. 	if (u.usteed && (objects[otyp].oc_dir != NODIR) &&
  14. 	    !u.dx && !u.dy && (u.dz > 0) && zap_steed(obj)) {
  15. 		disclose = TRUE;
  16. 	} else
  17. #endif
  18. 	if (objects[otyp].oc_dir == IMMEDIATE) {
  19. 	    obj_zapped = FALSE;
  20.  
  21. 	    if (u.uswallow) {
  22. 		(void) bhitm(u.ustuck, obj);
  23. 		/* [how about `bhitpile(u.ustuck->minvent)' effect?] */
  24. 	    } else if (u.dz) {
  25. 		disclose = zap_updown(obj);
  26. 	    } else {
  27. 		(void) bhit(u.dx,u.dy, rn1(8,6),ZAPPED_WAND, bhitm,bhito, obj);
  28. 	    }
  29. 	    /* give a clue if obj_zapped */
  30. 	    if (obj_zapped)
  31. 		You_feel("shuddering vibrations.");
  32.  
  33. 	} else if (objects[otyp].oc_dir == NODIR) {
  34. 	    zapnodir(obj);
  35.  
  36. 	} else {
  37. 	    /* neither immediate nor directionless */
  38.  
  39. 	    if (otyp == WAN_DIGGING || otyp == SPE_DIG)
  40. 		zap_dig();
  41. 	    else if (otyp >= SPE_MAGIC_MISSILE && otyp <= SPE_FINGER_OF_DEATH)
  42. 		buzz(otyp - SPE_MAGIC_MISSILE + 10,
  43. 		     u.ulevel / 2 + 1,
  44. 		     u.ux, u.uy, u.dx, u.dy);
  45. 	    else if (otyp >= WAN_MAGIC_MISSILE && otyp <= WAN_LIGHTNING)
  46. 		buzz(otyp - WAN_MAGIC_MISSILE,
  47. 		     (otyp == WAN_MAGIC_MISSILE) ? 2 : 6,
  48. 		     u.ux, u.uy, u.dx, u.dy);
  49. 	    else
  50. 		impossible("weffects: unexpected spell or wand");
  51. 	    disclose = TRUE;
  52. 	}
  53. 	if (disclose && was_unkn) {
  54. 	    makeknown(otyp);
  55. 	    more_experienced(0,10);
  56. 	}
  57. 	return;
  58. }
  59. #endif /*OVLB*/

spell_damage_bonus

  1. #ifdef OVL0
  2.  
  3. /*
  4. * Generate the to damage bonus for a spell. Based on the hero's intelligence
  5. */
  6. int
  7. spell_damage_bonus()
  8. {
  9. int tmp, intell = ACURR(A_INT);
  10.  
  11. /* Punish low intellegence before low level else low intellegence
  12. gets punished only when high level */
  13. if (intell < 10)
  14. 	tmp = -3;
  15. else if (u.ulevel < 5)
  16. 	tmp = 0;
  17. else if (intell < 14)
  18. 	tmp = 0;
  19. else if (intell <= 18)
  20. 	tmp = 1;
  21. else		/* helm of brilliance */
  22. 	tmp = 2;
  23.  
  24. return tmp;
  25. }

spell_hit_bonus

  1. /*
  2. * Generate the to hit bonus for a spell.  Based on the hero's skill in
  3. * spell class and dexterity.
  4. */
  5. STATIC_OVL int
  6. spell_hit_bonus(skill)
  7. int skill;
  8. {
  9. int hit_bon = 0;
  10. int dex = ACURR(A_DEX);
  11.  
  12. switch (P_SKILL(spell_skilltype(skill))) {
  13. 	case P_ISRESTRICTED:
  14. 	case P_UNSKILLED:   hit_bon = -4; break;
  15. 	case P_BASIC:       hit_bon =  0; break;
  16. 	case P_SKILLED:     hit_bon =  2; break;
  17. 	case P_EXPERT:      hit_bon =  3; break;
  18. }
  19.  
  20. if (dex < 4)
  21. 	hit_bon -= 3;
  22. else if (dex < 6)
  23. 	hit_bon -= 2;
  24. else if (dex < 8)
  25. 	hit_bon -= 1;
  26. else if (dex < 14)
  27. 	hit_bon -= 0;		/* Will change when print stuff below removed */
  28. else
  29. 	hit_bon += dex - 14; /* Even increment for dextrous heroes (see weapon.c abon) */
  30.  
  31. return hit_bon;
  32. }

exclam

  1. const char *
  2. exclam(force)
  3. register int force;
  4. {
  5. 	/* force == 0 occurs e.g. with sleep ray */
  6. 	/* note that large force is usual with wands so that !! would
  7. 		require information about hand/weapon/wand */
  8. 	return (const char *)((force < 0) ? "?" : (force <= 4) ? "." : "!");
  9. }

hit

  1. void
  2. hit(str,mtmp,force)
  3. register const char *str;
  4. register struct monst *mtmp;
  5. register const char *force;		/* usually either "." or "!" */
  6. {
  7. 	if((!cansee(bhitpos.x,bhitpos.y) && !canspotmon(mtmp) &&
  8. 	     !(u.uswallow && mtmp == u.ustuck))
  9. 	   || !flags.verbose)
  10. 	    pline("%s %s it.", The(str), vtense(str, "hit"));
  11. 	else pline("%s %s %s%s", The(str), vtense(str, "hit"),
  12. 		   mon_nam(mtmp), force);
  13. }

miss

  1. void
  2. miss(str,mtmp)
  3. register const char *str;
  4. register struct monst *mtmp;
  5. {
  6. 	pline("%s %s %s.", The(str), vtense(str, "miss"),
  7. 	      ((cansee(bhitpos.x,bhitpos.y) || canspotmon(mtmp))
  8. 	       && flags.verbose) ?
  9. 	      mon_nam(mtmp) : "it");
  10. }
  11. #endif /*OVL0*/

bhit

  1. #ifdef OVL1
  2.  
  3. /*
  4. *  Called for the following distance effects:
  5. *	when a weapon is thrown (weapon == THROWN_WEAPON)
  6. *	when an object is kicked (KICKED_WEAPON)
  7. *	when an IMMEDIATE wand is zapped (ZAPPED_WAND)
  8. *	when a light beam is flashed (FLASHED_LIGHT)
  9. *	when a mirror is applied (INVIS_BEAM)
  10. *  A thrown/kicked object falls down at the end of its range or when a monster
  11. *  is hit.  The variable 'bhitpos' is set to the final position of the weapon
  12. *  thrown/zapped.  The ray of a wand may affect (by calling a provided
  13. *  function) several objects and monsters on its path.  The return value
  14. *  is the monster hit (weapon != ZAPPED_WAND), or a null monster pointer.
  15. *
  16. *  Check !u.uswallow before calling bhit().
  17. *  This function reveals the absence of a remembered invisible monster in
  18. *  necessary cases (throwing or kicking weapons).  The presence of a real
  19. *  one is revealed for a weapon, but if not a weapon is left up to fhitm().
  20. */
  21. struct monst *
  22. bhit(ddx,ddy,range,weapon,fhitm,fhito,obj)
  23. register int ddx,ddy,range;		/* direction and range */
  24. int weapon;				/* see values in hack.h */
  25. int FDECL((*fhitm), (MONST_P, OBJ_P)),	/* fns called when mon/obj hit */
  26. FDECL((*fhito), (OBJ_P, OBJ_P));
  27. struct obj *obj;			/* object tossed/used */
  28. {
  29. 	struct monst *mtmp;
  30. 	uchar typ;
  31. 	boolean shopdoor = FALSE, point_blank = TRUE;
  32.  
  33. 	if (weapon == KICKED_WEAPON) {
  34. 	    /* object starts one square in front of player */
  35. 	    bhitpos.x = u.ux + ddx;
  36. 	    bhitpos.y = u.uy + ddy;
  37. 	    range--;
  38. 	} else {
  39. 	    bhitpos.x = u.ux;
  40. 	    bhitpos.y = u.uy;
  41. 	}
  42.  
  43. 	if (weapon == FLASHED_LIGHT) {
  44. 	    tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam));
  45. 	} else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM)
  46. 	    tmp_at(DISP_FLASH, obj_to_glyph(obj));
  47.  
  48. 	while(range-- > 0) {
  49. 	    int x,y;
  50.  
  51. 	    bhitpos.x += ddx;
  52. 	    bhitpos.y += ddy;
  53. 	    x = bhitpos.x; y = bhitpos.y;
  54.  
  55. 	    if(!isok(x, y)) {
  56. 		bhitpos.x -= ddx;
  57. 		bhitpos.y -= ddy;
  58. 		break;
  59. 	    }
  60.  
  61. 	    if(is_pick(obj) && inside_shop(x, y) &&
  62. 					   (mtmp = shkcatch(obj, x, y))) {
  63. 		tmp_at(DISP_END, 0);
  64. 		return(mtmp);
  65. 	    }
  66.  
  67. 	    typ = levl[bhitpos.x][bhitpos.y].typ;
  68.  
  69. 	    /* iron bars will block anything big enough */
  70. 	    if ((weapon == THROWN_WEAPON || weapon == KICKED_WEAPON) &&
  71. 		    typ == IRONBARS &&
  72. 		    hits_bars(&obj, x - ddx, y - ddy,
  73. 			      point_blank ? 0 : !rn2(5), 1)) {
  74. 		/* caveat: obj might now be null... */
  75. 		bhitpos.x -= ddx;
  76. 		bhitpos.y -= ddy;
  77. 		break;
  78. 	    }
  79.  
  80. 	    if (weapon == ZAPPED_WAND && find_drawbridge(&x,&y))
  81. 		switch (obj->otyp) {
  82. 		    case WAN_OPENING:
  83. 		    case SPE_KNOCK:
  84. 			if (is_db_wall(bhitpos.x, bhitpos.y)) {
  85. 			    if (cansee(x,y) || cansee(bhitpos.x,bhitpos.y))
  86. 				makeknown(obj->otyp);
  87. 			    open_drawbridge(x,y);
  88. 			}
  89. 			break;
  90. 		    case WAN_LOCKING:
  91. 		    case SPE_WIZARD_LOCK:
  92. 			if ((cansee(x,y) || cansee(bhitpos.x, bhitpos.y))
  93. 			    && levl[x][y].typ == DRAWBRIDGE_DOWN)
  94. 			    makeknown(obj->otyp);
  95. 			close_drawbridge(x,y);
  96. 			break;
  97. 		    case WAN_STRIKING:
  98. 		    case SPE_FORCE_BOLT:
  99. 			if (typ != DRAWBRIDGE_UP)
  100. 			    destroy_drawbridge(x,y);
  101. 			makeknown(obj->otyp);
  102. 			break;
  103. 		}
  104.  
  105. 	    if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  106. 		notonhead = (bhitpos.x != mtmp->mx ||
  107. 			     bhitpos.y != mtmp->my);
  108. 		if (weapon != FLASHED_LIGHT) {
  109. 			if(weapon != ZAPPED_WAND) {
  110. 			    if(weapon != INVIS_BEAM) tmp_at(DISP_END, 0);
  111. 			    if (cansee(bhitpos.x,bhitpos.y) && !canspotmon(mtmp)) {
  112. 				if (weapon != INVIS_BEAM) {
  113. 				    map_invisible(bhitpos.x, bhitpos.y);
  114. 				    return(mtmp);
  115. 				}
  116. 			    } else
  117. 				return(mtmp);
  118. 			}
  119. 			if (weapon != INVIS_BEAM) {
  120. 			    (*fhitm)(mtmp, obj);
  121. 			    range -= 3;
  122. 			}
  123. 		} else {
  124. 		    /* FLASHED_LIGHT hitting invisible monster
  125. 		       should pass through instead of stop so
  126. 		       we call flash_hits_mon() directly rather
  127. 		       than returning mtmp back to caller. That
  128. 		       allows the flash to keep on going. Note
  129. 		       that we use mtmp->minvis not canspotmon()
  130. 		       because it makes no difference whether
  131. 		       the hero can see the monster or not.*/
  132. 		    if (mtmp->minvis) {
  133. 			obj->ox = u.ux,  obj->oy = u.uy;
  134. 			(void) flash_hits_mon(mtmp, obj);
  135. 		    } else {
  136. 			tmp_at(DISP_END, 0);
  137. 		    	return(mtmp); 	/* caller will call flash_hits_mon */
  138. 		    }
  139. 		}
  140. 	    } else {
  141. 		if (weapon == ZAPPED_WAND && obj->otyp == WAN_PROBING &&
  142. 		   glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) {
  143. 		    unmap_object(bhitpos.x, bhitpos.y);
  144. 		    newsym(x, y);
  145. 		}
  146. 	    }
  147. 	    if(fhito) {
  148. 		if(bhitpile(obj,fhito,bhitpos.x,bhitpos.y))
  149. 		    range--;
  150. 	    } else {
  151. 		if(weapon == KICKED_WEAPON &&
  152. 		      ((obj->oclass == COIN_CLASS &&
  153. 			 OBJ_AT(bhitpos.x, bhitpos.y)) ||
  154. 			    ship_object(obj, bhitpos.x, bhitpos.y,
  155. 					costly_spot(bhitpos.x, bhitpos.y)))) {
  156. 			tmp_at(DISP_END, 0);
  157. 			return (struct monst *)0;
  158. 		}
  159. 	    }
  160. 	    if(weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) {
  161. 		switch (obj->otyp) {
  162. 		case WAN_OPENING:
  163. 		case WAN_LOCKING:
  164. 		case WAN_STRIKING:
  165. 		case SPE_KNOCK:
  166. 		case SPE_WIZARD_LOCK:
  167. 		case SPE_FORCE_BOLT:
  168. 		    if (doorlock(obj, bhitpos.x, bhitpos.y)) {
  169. 			if (cansee(bhitpos.x, bhitpos.y) ||
  170. 			    (obj->otyp == WAN_STRIKING))
  171. 			    makeknown(obj->otyp);
  172. 			if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
  173. 			    && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) {
  174. 			    shopdoor = TRUE;
  175. 			    add_damage(bhitpos.x, bhitpos.y, 400L);
  176. 			}
  177. 		    }
  178. 		    break;
  179. 		}
  180. 	    }
  181. 	    if(!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) {
  182. 		bhitpos.x -= ddx;
  183. 		bhitpos.y -= ddy;
  184. 		break;
  185. 	    }
  186. 	    if(weapon != ZAPPED_WAND && weapon != INVIS_BEAM) {
  187. 		/* 'I' present but no monster: erase */
  188. 		/* do this before the tmp_at() */
  189. 		if (glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)
  190. 			&& cansee(x, y)) {
  191. 		    unmap_object(bhitpos.x, bhitpos.y);
  192. 		    newsym(x, y);
  193. 		}
  194. 		tmp_at(bhitpos.x, bhitpos.y);
  195. 		delay_output();
  196. 		/* kicked objects fall in pools */
  197. 		if((weapon == KICKED_WEAPON) &&
  198. 		   (is_pool(bhitpos.x, bhitpos.y) ||
  199. 		   is_lava(bhitpos.x, bhitpos.y)))
  200. 		    break;
  201. #ifdef SINKS
  202. 		if(IS_SINK(typ) && weapon != FLASHED_LIGHT)
  203. 		    break;	/* physical objects fall onto sink */
  204. #endif
  205. 	    }
  206. 	    /* limit range of ball so hero won't make an invalid move */
  207. 	    if (weapon == THROWN_WEAPON && range > 0 &&
  208. 		obj->otyp == HEAVY_IRON_BALL) {
  209. 		struct obj *bobj;
  210. 		struct trap *t;
  211. 		if ((bobj = sobj_at(BOULDER, x, y)) != 0) {
  212. 		    if (cansee(x,y))
  213. 			pline("%s hits %s.",
  214. 			      The(distant_name(obj, xname)), an(xname(bobj)));
  215. 		    range = 0;
  216. 		} else if (obj == uball) {
  217. 		    if (!test_move(x - ddx, y - ddy, ddx, ddy, TEST_MOVE)) {
  218. 			/* nb: it didn't hit anything directly */
  219. 			if (cansee(x,y))
  220. 			    pline("%s jerks to an abrupt halt.",
  221. 				  The(distant_name(obj, xname))); /* lame */
  222. 			range = 0;
  223. 		    } else if (In_sokoban(&u.uz) && (t = t_at(x, y)) != 0 &&
  224. 			       (t->ttyp == PIT || t->ttyp == SPIKED_PIT ||
  225. 				t->ttyp == HOLE || t->ttyp == TRAPDOOR)) {
  226. 			/* hero falls into the trap, so ball stops */
  227. 			range = 0;
  228. 		    }
  229. 		}
  230. 	    }
  231.  
  232. 	    /* thrown/kicked missile has moved away from its starting spot */
  233. 	    point_blank = FALSE;	/* affects passing through iron bars */
  234. 	}
  235.  
  236. 	if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) tmp_at(DISP_END, 0);
  237.  
  238. 	if(shopdoor)
  239. 	    pay_for_damage("destroy", FALSE);
  240.  
  241. 	return (struct monst *)0;
  242. }

boomhit

  1. struct monst *
  2. boomhit(dx, dy)
  3. int dx, dy;
  4. {
  5. 	register int i, ct;
  6. 	int boom = S_boomleft;	/* showsym[] index  */
  7. 	struct monst *mtmp;
  8.  
  9. 	bhitpos.x = u.ux;
  10. 	bhitpos.y = u.uy;
  11.  
  12. 	for (i = 0; i < 8; i++) if (xdir[i] == dx && ydir[i] == dy) break;
  13. 	tmp_at(DISP_FLASH, cmap_to_glyph(boom));
  14. 	for (ct = 0; ct < 10; ct++) {
  15. 		if(i == 8) i = 0;
  16. 		boom = (boom == S_boomleft) ? S_boomright : S_boomleft;
  17. 		tmp_at(DISP_CHANGE, cmap_to_glyph(boom));/* change glyph */
  18. 		dx = xdir[i];
  19. 		dy = ydir[i];
  20. 		bhitpos.x += dx;
  21. 		bhitpos.y += dy;
  22. 		if(MON_AT(bhitpos.x, bhitpos.y)) {
  23. 			mtmp = m_at(bhitpos.x,bhitpos.y);
  24. 			m_respond(mtmp);
  25. 			tmp_at(DISP_END, 0);
  26. 			return(mtmp);
  27. 		}
  28. 		if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ) ||
  29. 		   closed_door(bhitpos.x, bhitpos.y)) {
  30. 			bhitpos.x -= dx;
  31. 			bhitpos.y -= dy;
  32. 			break;
  33. 		}
  34. 		if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
  35. 			if(Fumbling || rn2(20) >= ACURR(A_DEX)) {
  36. 				/* we hit ourselves */
  37. 				(void) thitu(10, rnd(10), (struct obj *)0,
  38. 					"boomerang");
  39. 				break;
  40. 			} else {	/* we catch it */
  41. 				tmp_at(DISP_END, 0);
  42. 				You("skillfully catch the boomerang.");
  43. 				return(&youmonst);
  44. 			}
  45. 		}
  46. 		tmp_at(bhitpos.x, bhitpos.y);
  47. 		delay_output();
  48. 		if(ct % 5 != 0) i++;
  49. #ifdef SINKS
  50. 		if(IS_SINK(levl[bhitpos.x][bhitpos.y].typ))
  51. 			break;	/* boomerang falls on sink */
  52. #endif
  53. 	}
  54. 	tmp_at(DISP_END, 0);	/* do not leave last symbol */
  55. 	return (struct monst *)0;
  56. }

zhitm

  1. STATIC_OVL int
  2. zhitm(mon, type, nd, ootmp)			/* returns damage to mon */
  3. register struct monst *mon;
  4. register int type, nd;
  5. struct obj **ootmp;	/* to return worn armor for caller to disintegrate */
  6. {
  7. 	register int tmp = 0;
  8. 	register int abstype = abs(type) % 10;
  9. 	boolean sho_shieldeff = FALSE;
  10. 	boolean spellcaster = is_hero_spell(type); /* maybe get a bonus! */
  11.  
  12. 	*ootmp = (struct obj *)0;
  13. 	switch(abstype) {
  14. 	case ZT_MAGIC_MISSILE:
  15. 		if (resists_magm(mon)) {
  16. 		    sho_shieldeff = TRUE;
  17. 		    break;
  18. 		}
  19. 		tmp = d(nd,6);
  20. 		if (spellcaster)
  21. 		    tmp += spell_damage_bonus();
  22. #ifdef WIZ_PATCH_DEBUG
  23. 		if (spellcaster)
  24. 		    pline("Damage = %d + %d", tmp-spell_damage_bonus(),
  25. 			spell_damage_bonus());
  26. #endif
  27. 		break;
  28. 	case ZT_FIRE:
  29. 		if (resists_fire(mon)) {
  30. 		    sho_shieldeff = TRUE;
  31. 		    break;
  32. 		}
  33. 		tmp = d(nd,6);
  34. 		if (resists_cold(mon)) tmp += 7;
  35. 		if (spellcaster)
  36. 		    tmp += spell_damage_bonus();
  37. #ifdef WIZ_PATCH_DEBUG
  38. 		if (spellcaster)
  39. 		    pline("Damage = %d + %d",tmp-spell_damage_bonus(),
  40. 			spell_damage_bonus());
  41. #endif
  42. 		if (burnarmor(mon)) {
  43. 		    if (!rn2(3)) (void)destroy_mitem(mon, POTION_CLASS, AD_FIRE);
  44. 		    if (!rn2(3)) (void)destroy_mitem(mon, SCROLL_CLASS, AD_FIRE);
  45. 		    if (!rn2(5)) (void)destroy_mitem(mon, SPBOOK_CLASS, AD_FIRE);
  46. 		}
  47. 		break;
  48. 	case ZT_COLD:
  49. 		if (resists_cold(mon)) {
  50. 		    sho_shieldeff = TRUE;
  51. 		    break;
  52. 		}
  53. 		tmp = d(nd,6);
  54. 		if (resists_fire(mon)) tmp += d(nd, 3);
  55. 		if (spellcaster)
  56. 		    tmp += spell_damage_bonus();
  57. #ifdef WIZ_PATCH_DEBUG
  58. 		if (spellcaster)
  59. 		    pline("Damage = %d + %d", tmp-spell_damage_bonus(),
  60. 			spell_damage_bonus());
  61. #endif
  62. 		if (!rn2(3)) (void)destroy_mitem(mon, POTION_CLASS, AD_COLD);
  63. 		break;
  64. 	case ZT_SLEEP:
  65. 		tmp = 0;
  66. 		(void)sleep_monst(mon, d(nd, 25),
  67. 				type == ZT_WAND(ZT_SLEEP) ? WAND_CLASS : '\0');
  68. 		break;
  69. 	case ZT_DEATH:		/* death/disintegration */
  70. 		if(abs(type) != ZT_BREATH(ZT_DEATH)) {	/* death */
  71. 		    if(mon->data == &mons[PM_DEATH]) {
  72. 			mon->mhpmax += mon->mhpmax/2;
  73. 			if (mon->mhpmax >= MAGIC_COOKIE)
  74. 			    mon->mhpmax = MAGIC_COOKIE - 1;
  75. 			mon->mhp = mon->mhpmax;
  76. 			tmp = 0;
  77. 			break;
  78. 		    }
  79. 		    if (nonliving(mon->data) || is_demon(mon->data) ||
  80. 			    resists_magm(mon)) {	/* similar to player */
  81. 			sho_shieldeff = TRUE;
  82. 			break;
  83. 		    }
  84. 		    type = -1; /* so they don't get saving throws */
  85. 		} else {
  86. 		    struct obj *otmp2;
  87.  
  88. 		    if (resists_disint(mon)) {
  89. 			sho_shieldeff = TRUE;
  90. 		    } else if (mon->misc_worn_check & W_ARMS) {
  91. 			/* destroy shield; victim survives */
  92. 			*ootmp = which_armor(mon, W_ARMS);
  93. 		    } else if (mon->misc_worn_check & W_ARM) {
  94. 			/* destroy body armor, also cloak if present */
  95. 			*ootmp = which_armor(mon, W_ARM);
  96. 			if ((otmp2 = which_armor(mon, W_ARMC)) != 0)
  97. 			    m_useup(mon, otmp2);
  98. 		    } else {
  99. 			/* no body armor, victim dies; destroy cloak
  100. 			   and shirt now in case target gets life-saved */
  101. 			tmp = MAGIC_COOKIE;
  102. 			if ((otmp2 = which_armor(mon, W_ARMC)) != 0)
  103. 			    m_useup(mon, otmp2);
  104. #ifdef TOURIST
  105. 			if ((otmp2 = which_armor(mon, W_ARMU)) != 0)
  106. 			    m_useup(mon, otmp2);
  107. #endif
  108. 		    }
  109. 		    type = -1;	/* no saving throw wanted */
  110. 		    break;	/* not ordinary damage */
  111. 		}
  112. 		tmp = mon->mhp+1;
  113. 		break;
  114. 	case ZT_LIGHTNING:
  115. 		if (resists_elec(mon)) {
  116. 		    sho_shieldeff = TRUE;
  117. 		    tmp = 0;
  118. 		    /* can still blind the monster */
  119. 		} else
  120. 		    tmp = d(nd,6);
  121. 		if (spellcaster)
  122. 		    tmp += spell_damage_bonus();
  123. #ifdef WIZ_PATCH_DEBUG
  124. 		if (spellcaster)
  125. 		    pline("Damage = %d + %d", tmp-spell_damage_bonus(),
  126. 			spell_damage_bonus());
  127. #endif
  128. 		if (!resists_blnd(mon) &&
  129. 				!(type > 0 && u.uswallow && mon == u.ustuck)) {
  130. 			register unsigned rnd_tmp = rnd(50);
  131. 			mon->mcansee = 0;
  132. 			if((mon->mblinded + rnd_tmp) > 127)
  133. 				mon->mblinded = 127;
  134. 			else mon->mblinded += rnd_tmp;
  135. 		}
  136. 		if (!rn2(3)) (void)destroy_mitem(mon, WAND_CLASS, AD_ELEC);
  137. 		/* not actually possible yet */
  138. 		if (!rn2(3)) (void)destroy_mitem(mon, RING_CLASS, AD_ELEC);
  139. 		break;
  140. 	case ZT_POISON_GAS:
  141. 		if (resists_poison(mon)) {
  142. 		    sho_shieldeff = TRUE;
  143. 		    break;
  144. 		}
  145. 		tmp = d(nd,6);
  146. 		break;
  147. 	case ZT_ACID:
  148. 		if (resists_acid(mon)) {
  149. 		    sho_shieldeff = TRUE;
  150. 		    break;
  151. 		}
  152. 		tmp = d(nd,6);
  153. 		if (!rn2(6)) erode_obj(MON_WEP(mon), TRUE, TRUE);
  154. 		if (!rn2(6)) erode_armor(mon, TRUE);
  155. 		break;
  156. 	}
  157. 	if (sho_shieldeff) shieldeff(mon->mx, mon->my);
  158. 	if (is_hero_spell(type) && (Role_if(PM_KNIGHT) && u.uhave.questart))
  159. 	    tmp *= 2;
  160. 	if (tmp > 0 && type >= 0 &&
  161. 		resist(mon, type < ZT_SPELL(0) ? WAND_CLASS : '\0', 0, NOTELL))
  162. 	    tmp /= 2;
  163. 	if (tmp < 0) tmp = 0;		/* don't allow negative damage */
  164. #ifdef WIZ_PATCH_DEBUG
  165. 	pline("zapped monster hp = %d (= %d - %d)", mon->mhp-tmp,mon->mhp,tmp);
  166. #endif
  167. 	mon->mhp -= tmp;
  168. 	return(tmp);
  169. }

zhitu

  1. STATIC_OVL void
  2. zhitu(type, nd, fltxt, sx, sy)
  3. int type, nd;
  4. const char *fltxt;
  5. xchar sx, sy;
  6. {
  7. 	int dam = 0;
  8.  
  9. 	switch (abs(type) % 10) {
  10. 	case ZT_MAGIC_MISSILE:
  11. 	    if (Antimagic) {
  12. 		shieldeff(sx, sy);
  13. 		pline_The("missiles bounce off!");
  14. 	    } else {
  15. 		dam = d(nd,6);
  16. 		exercise(A_STR, FALSE);
  17. 	    }
  18. 	    break;
  19. 	case ZT_FIRE:
  20. 	    if (Fire_resistance) {
  21. 		shieldeff(sx, sy);
  22. 		You("don't feel hot!");
  23. 		ugolemeffects(AD_FIRE, d(nd, 6));
  24. 	    } else {
  25. 		dam = d(nd, 6);
  26. 	    }
  27. 	    burn_away_slime();
  28. 	    if (burnarmor(&youmonst)) {	/* "body hit" */
  29. 		if (!rn2(3)) destroy_item(POTION_CLASS, AD_FIRE);
  30. 		if (!rn2(3)) destroy_item(SCROLL_CLASS, AD_FIRE);
  31. 		if (!rn2(5)) destroy_item(SPBOOK_CLASS, AD_FIRE);
  32. 	    }
  33. 	    break;
  34. 	case ZT_COLD:
  35. 	    if (Cold_resistance) {
  36. 		shieldeff(sx, sy);
  37. 		You("don't feel cold.");
  38. 		ugolemeffects(AD_COLD, d(nd, 6));
  39. 	    } else {
  40. 		dam = d(nd, 6);
  41. 	    }
  42. 	    if (!rn2(3)) destroy_item(POTION_CLASS, AD_COLD);
  43. 	    break;
  44. 	case ZT_SLEEP:
  45. 	    if (Sleep_resistance) {
  46. 		shieldeff(u.ux, u.uy);
  47. 		You("don't feel sleepy.");
  48. 	    } else {
  49. 		fall_asleep(-d(nd,25), TRUE); /* sleep ray */
  50. 	    }
  51. 	    break;
  52. 	case ZT_DEATH:
  53. 	    if (abs(type) == ZT_BREATH(ZT_DEATH)) {
  54. 		if (Disint_resistance) {
  55. 		    You("are not disintegrated.");
  56. 		    break;
  57. 		} else if (uarms) {
  58. 		    /* destroy shield; other possessions are safe */
  59. 		    (void) destroy_arm(uarms);
  60. 		    break;
  61. 		} else if (uarm) {
  62. 		    /* destroy suit; if present, cloak goes too */
  63. 		    if (uarmc) (void) destroy_arm(uarmc);
  64. 		    (void) destroy_arm(uarm);
  65. 		    break;
  66. 		}
  67. 		/* no shield or suit, you're dead; wipe out cloak
  68. 		   and/or shirt in case of life-saving or bones */
  69. 		if (uarmc) (void) destroy_arm(uarmc);
  70. #ifdef TOURIST
  71. 		if (uarmu) (void) destroy_arm(uarmu);
  72. #endif
  73. 	    } else if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
  74. 		shieldeff(sx, sy);
  75. 		You("seem unaffected.");
  76. 		break;
  77. 	    } else if (Antimagic) {
  78. 		shieldeff(sx, sy);
  79. 		You("aren't affected.");
  80. 		break;
  81. 	    }
  82. 	    killer_format = KILLED_BY_AN;
  83. 	    killer = fltxt;
  84. 	    /* when killed by disintegration breath, don't leave corpse */
  85. 	    u.ugrave_arise = (type == -ZT_BREATH(ZT_DEATH)) ? -3 : NON_PM;
  86. 	    done(DIED);
  87. 	    return; /* lifesaved */
  88. 	case ZT_LIGHTNING:
  89. 	    if (Shock_resistance) {
  90. 		shieldeff(sx, sy);
  91. 		You("aren't affected.");
  92. 		ugolemeffects(AD_ELEC, d(nd, 6));
  93. 	    } else {
  94. 		dam = d(nd, 6);
  95. 		exercise(A_CON, FALSE);
  96. 	    }
  97. 	    if (!rn2(3)) destroy_item(WAND_CLASS, AD_ELEC);
  98. 	    if (!rn2(3)) destroy_item(RING_CLASS, AD_ELEC);
  99. 	    break;
  100. 	case ZT_POISON_GAS:
  101. 	    poisoned("blast", A_DEX, "poisoned blast", 15);
  102. 	    break;
  103. 	case ZT_ACID:
  104. 	    if (Acid_resistance) {
  105. 		dam = 0;
  106. 	    } else {
  107. 		pline_The("acid burns!");
  108. 		dam = d(nd,6);
  109. 		exercise(A_STR, FALSE);
  110. 	    }
  111. 	    /* using two weapons at once makes both of them more vulnerable */
  112. 	    if (!rn2(u.twoweap ? 3 : 6)) erode_obj(uwep, TRUE, TRUE);
  113. 	    if (u.twoweap && !rn2(3)) erode_obj(uswapwep, TRUE, TRUE);
  114. 	    if (!rn2(6)) erode_armor(&youmonst, TRUE);
  115. 	    break;
  116. 	}
  117.  
  118. 	if (Half_spell_damage && dam &&
  119. 	   type < 0 && (type > -20 || type < -29)) /* !Breath */
  120. 	    dam = (dam + 1) / 2;
  121. 	losehp(dam, fltxt, KILLED_BY_AN);
  122. 	return;
  123. }
  124.  
  125. #endif /*OVL1*/

burn_floor_paper

  1. #ifdef OVLB
  2.  
  3. /*
  4. * burn scrolls and spellbooks on floor at position x,y
  5. * return the number of scrolls and spellbooks burned
  6. */
  7. int
  8. burn_floor_paper(x, y, give_feedback, u_caused)
  9. int x, y;
  10. boolean give_feedback;	/* caller needs to decide about visibility checks */
  11. boolean u_caused;
  12. {
  13. 	struct obj *obj, *obj2;
  14. 	long i, scrquan, delquan;
  15. 	char buf1[BUFSZ], buf2[BUFSZ];
  16. 	int cnt = 0;
  17.  
  18. 	for (obj = level.objects[x][y]; obj; obj = obj2) {
  19. 	    obj2 = obj->nexthere;
  20. 	    if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) {
  21. 		if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL ||
  22. 			obj_resists(obj, 2, 100))
  23. 		    continue;
  24. 		scrquan = obj->quan;	/* number present */
  25. 		delquan = 0;		/* number to destroy */
  26. 		for (i = scrquan; i > 0; i--)
  27. 		    if (!rn2(3)) delquan++;
  28. 		if (delquan) {
  29. 		    /* save name before potential delobj() */
  30. 		    if (give_feedback) {
  31. 			obj->quan = 1;
  32. 			Strcpy(buf1, (x == u.ux && y == u.uy) ?
  33. 				xname(obj) : distant_name(obj, xname));
  34. 			obj->quan = 2;
  35. 		    	Strcpy(buf2, (x == u.ux && y == u.uy) ?
  36. 				xname(obj) : distant_name(obj, xname));
  37. 			obj->quan = scrquan;
  38. 		    }
  39. 		    /* useupf(), which charges, only if hero caused damage */
  40. 		    if (u_caused) useupf(obj, delquan);
  41. 		    else if (delquan < scrquan) obj->quan -= delquan;
  42. 		    else delobj(obj);
  43. 		    cnt += delquan;
  44. 		    if (give_feedback) {
  45. 			if (delquan > 1)
  46. 			    pline("%ld %s burn.", delquan, buf2);
  47. 			else
  48. 			    pline("%s burns.", An(buf1));
  49. 		    }
  50. 		}
  51. 	    }
  52. 	}
  53. 	return cnt;
  54. }

zap_hit

  1. /* will zap/spell/breath attack score a hit against armor class `ac'? */
  2. STATIC_OVL int
  3. zap_hit(ac, type)
  4. int ac;
  5. int type;	/* either hero cast spell type or 0 */
  6. {
  7. int chance = rn2(20);
  8. int spell_bonus = type ? spell_hit_bonus(type) : 0;
  9.  
  10. /* small chance for naked target to avoid being hit */
  11. if (!chance) return rnd(10) < ac+spell_bonus;
  12.  
  13. /* very high armor protection does not achieve invulnerability */
  14. ac = AC_VALUE(ac);
  15.  
  16. return (3 - chance) < ac+spell_bonus;
  17. }

buzz

  1. /* type ==   0 to   9 : you shooting a wand */
  2. /* type ==  10 to  19 : you casting a spell */
  3. /* type ==  20 to  29 : you breathing as a monster */
  4. /* type == -10 to -19 : monster casting spell */
  5. /* type == -20 to -29 : monster breathing at you */
  6. /* type == -30 to -39 : monster shooting a wand */
  7. /* called with dx = dy = 0 with vertical bolts */
  8. void
  9. buzz(type,nd,sx,sy,dx,dy)
  10. register int type, nd;
  11. register xchar sx,sy;
  12. register int dx,dy;
  13. {
  14. int range, abstype = abs(type) % 10;
  15. struct rm *lev;
  16. register xchar lsx, lsy;
  17. struct monst *mon;
  18. coord save_bhitpos;
  19. boolean shopdamage = FALSE;
  20. register const char *fltxt;
  21. struct obj *otmp;
  22. int spell_type;
  23.  
  24. /* if its a Hero Spell then get its SPE_TYPE */
  25. spell_type = is_hero_spell(type) ? SPE_MAGIC_MISSILE + abstype : 0;
  26.  
  27. fltxt = flash_types[(type <= -30) ? abstype : abs(type)];
  28. if(u.uswallow) {
  29. 	register int tmp;
  30.  
  31. 	if(type < 0) return;
  32. 	tmp = zhitm(u.ustuck, type, nd, &otmp);
  33. 	if(!u.ustuck)	u.uswallow = 0;
  34. 	else	pline("%s rips into %s%s",
  35. 		      The(fltxt), mon_nam(u.ustuck), exclam(tmp));
  36. 	/* Using disintegration from the inside only makes a hole... */
  37. 	if (tmp == MAGIC_COOKIE)
  38. 	    u.ustuck->mhp = 0;
  39. 	if (u.ustuck->mhp < 1)
  40. 	    killed(u.ustuck);
  41. 	return;
  42. }
  43. if(type < 0) newsym(u.ux,u.uy);
  44. range = rn1(7,7);
  45. if(dx == 0 && dy == 0) range = 1;
  46. save_bhitpos = bhitpos;
  47.  
  48. tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype));
  49. while(range-- > 0) {
  50. 	lsx = sx; sx += dx;
  51. 	lsy = sy; sy += dy;
  52. 	if(isok(sx,sy) && (lev = &levl[sx][sy])->typ) {
  53. 	    mon = m_at(sx, sy);
  54. 	    if(cansee(sx,sy)) {
  55. 		/* reveal/unreveal invisible monsters before tmp_at() */
  56. 		if (mon && !canspotmon(mon))
  57. 		    map_invisible(sx, sy);
  58. 		else if (!mon && glyph_is_invisible(levl[sx][sy].glyph)) {
  59. 		    unmap_object(sx, sy);
  60. 		    newsym(sx, sy);
  61. 		}
  62. 		if(ZAP_POS(lev->typ) || cansee(lsx,lsy))
  63. 		    tmp_at(sx,sy);
  64. 		delay_output(); /* wait a little */
  65. 	    }
  66. 	} else
  67. 	    goto make_bounce;
  68.  
  69. 	/* hit() and miss() need bhitpos to match the target */
  70. 	bhitpos.x = sx,  bhitpos.y = sy;
  71. 	/* Fireballs only damage when they explode */
  72. 	if (type != ZT_SPELL(ZT_FIRE))
  73. 	    range += zap_over_floor(sx, sy, type, &shopdamage);
  74.  
  75. 	if (mon) {
  76. 	    if (type == ZT_SPELL(ZT_FIRE)) break;
  77. 	    if (type >= 0) mon->mstrategy &= ~STRAT_WAITMASK;
  78. #ifdef STEED
  79. 	    buzzmonst:
  80. #endif
  81. 	    if (zap_hit(find_mac(mon), spell_type)) {
  82. 		if (mon_reflects(mon, (char *)0)) {
  83. 		    if(cansee(mon->mx,mon->my)) {
  84. 			hit(fltxt, mon, exclam(0));
  85. 			shieldeff(mon->mx, mon->my);
  86. 			(void) mon_reflects(mon, "But it reflects from %s %s!");
  87. 		    }
  88. 		    dx = -dx;
  89. 		    dy = -dy;
  90. 		} else {
  91. 		    boolean mon_could_move = mon->mcanmove;
  92. 		    int tmp = zhitm(mon, type, nd, &otmp);
  93.  
  94. 		    if (is_rider(mon->data) && abs(type) == ZT_BREATH(ZT_DEATH)) {
  95. 			if (canseemon(mon)) {
  96. 			    hit(fltxt, mon, ".");
  97. 			    pline("%s disintegrates.", Monnam(mon));
  98. 			    pline("%s body reintegrates before your %s!",
  99. 				  s_suffix(Monnam(mon)),
  100. 				  (eyecount(youmonst.data) == 1) ?
  101. 				  	body_part(EYE) : makeplural(body_part(EYE)));
  102. 			    pline("%s resurrects!", Monnam(mon));
  103. 			}
  104. 			mon->mhp = mon->mhpmax;
  105. 			break; /* Out of while loop */
  106. 		    }
  107. 		    if (mon->data == &mons[PM_DEATH] && abstype == ZT_DEATH) {
  108. 			if (canseemon(mon)) {
  109. 			    hit(fltxt, mon, ".");
  110. 			    pline("%s absorbs the deadly %s!", Monnam(mon),
  111. 				  type == ZT_BREATH(ZT_DEATH) ?
  112. 					"blast" : "ray");
  113. 			    pline("It seems even stronger than before.");
  114. 			}
  115. 			break; /* Out of while loop */
  116. 		    }
  117.  
  118. 		    if (tmp == MAGIC_COOKIE) { /* disintegration */
  119. 			struct obj *otmp2, *m_amulet = mlifesaver(mon);
  120.  
  121. 			if (canseemon(mon)) {
  122. 			    if (!m_amulet)
  123. 				pline("%s is disintegrated!", Monnam(mon));
  124. 			    else
  125. 				hit(fltxt, mon, "!");
  126. 			}
  127. #ifndef GOLDOBJ
  128. 			mon->mgold = 0L;
  129. #endif
  130.  
  131. /* note: worn amulet of life saving must be preserved in order to operate */
  132. #define oresist_disintegration(obj) \
  133. 		(objects[obj->otyp].oc_oprop == DISINT_RES || \
  134. 		 obj_resists(obj, 5, 50) || is_quest_artifact(obj) || \
  135. 		 obj == m_amulet)
  136.  
  137. 			for (otmp = mon->minvent; otmp; otmp = otmp2) {
  138. 			    otmp2 = otmp->nobj;
  139. 			    if (!oresist_disintegration(otmp)) {
  140. 				obj_extract_self(otmp);
  141. 				obfree(otmp, (struct obj *)0);
  142. 			    }
  143. 			}
  144.  
  145. 			if (type < 0)
  146. 			    monkilled(mon, (char *)0, -AD_RBRE);
  147. 			else
  148. 			    xkilled(mon, 2);
  149. 		    } else if(mon->mhp < 1) {
  150. 			if(type < 0)
  151. 			    monkilled(mon, fltxt, AD_RBRE);
  152. 			else
  153. 			    killed(mon);
  154. 		    } else {
  155. 			if (!otmp) {
  156. 			    /* normal non-fatal hit */
  157. 			    hit(fltxt, mon, exclam(tmp));
  158. 			} else {
  159. 			    /* some armor was destroyed; no damage done */
  160. 			    if (canseemon(mon))
  161. 				pline("%s %s is disintegrated!",
  162. 				      s_suffix(Monnam(mon)),
  163. 				      distant_name(otmp, xname));
  164. 			    m_useup(mon, otmp);
  165. 			}
  166. 			if (mon_could_move && !mon->mcanmove)	/* ZT_SLEEP */
  167. 			    slept_monst(mon);
  168. 		    }
  169. 		}
  170. 		range -= 2;
  171. 	    } else {
  172. 		miss(fltxt,mon);
  173. 	    }
  174. 	} else if (sx == u.ux && sy == u.uy && range >= 0) {
  175. 	    nomul(0);
  176. #ifdef STEED
  177. 	    if (u.usteed && !rn2(3) && !mon_reflects(u.usteed, (char *)0)) {
  178. 		    mon = u.usteed;
  179. 		    goto buzzmonst;
  180. 	    } else
  181. #endif
  182. 	    if (zap_hit((int) u.uac, 0)) {
  183. 		range -= 2;
  184. 		pline("%s hits you!", The(fltxt));
  185. 		if (Reflecting) {
  186. 		    if (!Blind) {
  187. 		    	(void) ureflects("But %s reflects from your %s!", "it");
  188. 		    } else
  189. 			pline("For some reason you are not affected.");
  190. 		    dx = -dx;
  191. 		    dy = -dy;
  192. 		    shieldeff(sx, sy);
  193. 		} else {
  194. 		    zhitu(type, nd, fltxt, sx, sy);
  195. 		}
  196. 	    } else {
  197. 		pline("%s whizzes by you!", The(fltxt));
  198. 	    }
  199. 	    if (abstype == ZT_LIGHTNING && !resists_blnd(&youmonst)) {
  200. 		You(are_blinded_by_the_flash);
  201. 		make_blinded((long)d(nd,50),FALSE);
  202. 		if (!Blind) Your(vision_clears);
  203. 	    }
  204. 	    stop_occupation();
  205. 	    nomul(0);
  206. 	}
  207.  
  208. 	if(!ZAP_POS(lev->typ) || (closed_door(sx, sy) && (range >= 0))) {
  209. 	    int bounce;
  210. 	    uchar rmn;
  211.  
  212. make_bounce:
  213. 	    if (type == ZT_SPELL(ZT_FIRE)) {
  214. 		sx = lsx;
  215. 		sy = lsy;
  216. 		break; /* fireballs explode before the wall */
  217. 	    }
  218. 	    bounce = 0;
  219. 	    range--;
  220. 	    if(range && isok(lsx, lsy) && cansee(lsx,lsy))
  221. 		pline("%s bounces!", The(fltxt));
  222. 	    if(!dx || !dy || !rn2(20)) {
  223. 		dx = -dx;
  224. 		dy = -dy;
  225. 	    } else {
  226. 		if(isok(sx,lsy) && ZAP_POS(rmn = levl[sx][lsy].typ) &&
  227. 		   !closed_door(sx,lsy) &&
  228. 		   (IS_ROOM(rmn) || (isok(sx+dx,lsy) &&
  229. 				     ZAP_POS(levl[sx+dx][lsy].typ))))
  230. 		    bounce = 1;
  231. 		if(isok(lsx,sy) && ZAP_POS(rmn = levl[lsx][sy].typ) &&
  232. 		   !closed_door(lsx,sy) &&
  233. 		   (IS_ROOM(rmn) || (isok(lsx,sy+dy) &&
  234. 				     ZAP_POS(levl[lsx][sy+dy].typ))))
  235. 		    if(!bounce || rn2(2))
  236. 			bounce = 2;
  237.  
  238. 		switch(bounce) {
  239. 		case 0: dx = -dx; /* fall into... */
  240. 		case 1: dy = -dy; break;
  241. 		case 2: dx = -dx; break;
  242. 		}
  243. 		tmp_at(DISP_CHANGE, zapdir_to_glyph(dx,dy,abstype));
  244. 	    }
  245. 	}
  246. }
  247. tmp_at(DISP_END,0);
  248. if (type == ZT_SPELL(ZT_FIRE))
  249. 	explode(sx, sy, type, d(12,6), 0, EXPL_FIERY);
  250. if (shopdamage)
  251. 	pay_for_damage(abstype == ZT_FIRE ?  "burn away" :
  252. 		       abstype == ZT_COLD ?  "shatter" :
  253. 		       abstype == ZT_DEATH ? "disintegrate" : "destroy", FALSE);
  254. bhitpos = save_bhitpos;
  255. }
  256. #endif /*OVLB*/

melt_ice

  1. #ifdef OVL0
  2.  
  3. void
  4. melt_ice(x, y)
  5. xchar x, y;
  6. {
  7. 	struct rm *lev = &levl[x][y];
  8. 	struct obj *otmp;
  9.  
  10. 	if (lev->typ == DRAWBRIDGE_UP)
  11. 	    lev->drawbridgemask &= ~DB_ICE;	/* revert to DB_MOAT */
  12. 	else {	/* lev->typ == ICE */
  13. #ifdef STUPID
  14. 	    if (lev->icedpool == ICED_POOL) lev->typ = POOL;
  15. 	    else lev->typ = MOAT;
  16. #else
  17. 	    lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT);
  18. #endif
  19. 	    lev->icedpool = 0;
  20. 	}
  21. 	obj_ice_effects(x, y, FALSE);
  22. 	unearth_objs(x, y);
  23. 	if (Underwater) vision_recalc(1);
  24. 	newsym(x,y);
  25. 	if (cansee(x,y)) Norep("The ice crackles and melts.");
  26. 	if ((otmp = sobj_at(BOULDER, x, y)) != 0) {
  27. 	    if (cansee(x,y)) pline("%s settles...", An(xname(otmp)));
  28. 	    do {
  29. 		obj_extract_self(otmp);	/* boulder isn't being pushed */
  30. 		if (!boulder_hits_pool(otmp, x, y, FALSE))
  31. 		    impossible("melt_ice: no pool?");
  32. 		/* try again if there's another boulder and pool didn't fill */
  33. 	    } while (is_pool(x,y) && (otmp = sobj_at(BOULDER, x, y)) != 0);
  34. 	    newsym(x,y);
  35. 	}
  36. 	if (x == u.ux && y == u.uy)
  37. 		spoteffects(TRUE);	/* possibly drown, notice objects */
  38. }

zap_over_floor

  1. /* Burn floor scrolls, evaporate pools, etc...  in a single square.  Used
  2. * both for normal bolts of fire, cold, etc... and for fireballs.
  3. * Sets shopdamage to TRUE if a shop door is destroyed, and returns the
  4. * amount by which range is reduced (the latter is just ignored by fireballs)
  5. */
  6. int
  7. zap_over_floor(x, y, type, shopdamage)
  8. xchar x, y;
  9. int type;
  10. boolean *shopdamage;
  11. {
  12. 	struct monst *mon;
  13. 	int abstype = abs(type) % 10;
  14. 	struct rm *lev = &levl[x][y];
  15. 	int rangemod = 0;
  16.  
  17. 	if(abstype == ZT_FIRE) {
  18. 	    struct trap *t = t_at(x, y);
  19.  
  20. 	    if (t && t->ttyp == WEB) {
  21. 		/* a burning web is too flimsy to notice if you can't see it */
  22. 		if (cansee(x,y)) Norep("A web bursts into flames!");
  23. 		(void) delfloortrap(t);
  24. 		if (cansee(x,y)) newsym(x,y);
  25. 	    }
  26. 	    if(is_ice(x, y)) {
  27. 		melt_ice(x, y);
  28. 	    } else if(is_pool(x,y)) {
  29. 		const char *msgtxt = "You hear hissing gas.";
  30. 		if(lev->typ != POOL) {	/* MOAT or DRAWBRIDGE_UP */
  31. 		    if (cansee(x,y)) msgtxt = "Some water evaporates.";
  32. 		} else {
  33. 		    register struct trap *ttmp;
  34.  
  35. 		    rangemod -= 3;
  36. 		    lev->typ = ROOM;
  37. 		    ttmp = maketrap(x, y, PIT);
  38. 		    if (ttmp) ttmp->tseen = 1;
  39. 		    if (cansee(x,y)) msgtxt = "The water evaporates.";
  40. 		}
  41. 		Norep(msgtxt);
  42. 		if (lev->typ == ROOM) newsym(x,y);
  43. 	    } else if(IS_FOUNTAIN(lev->typ)) {
  44. 		    if (cansee(x,y))
  45. 			pline("Steam billows from the fountain.");
  46. 		    rangemod -= 1;
  47. 		    dryup(x, y, type > 0);
  48. 	    }
  49. 	}
  50. 	else if(abstype == ZT_COLD && (is_pool(x,y) || is_lava(x,y))) {
  51. 		boolean lava = is_lava(x,y);
  52. 		boolean moat = (!lava && (lev->typ != POOL) &&
  53. 				(lev->typ != WATER) &&
  54. 				!Is_medusa_level(&u.uz) &&
  55. 				!Is_waterlevel(&u.uz));
  56.  
  57. 		if (lev->typ == WATER) {
  58. 		    /* For now, don't let WATER freeze. */
  59. 		    if (cansee(x,y))
  60. 			pline_The("water freezes for a moment.");
  61. 		    else
  62. 			You_hear("a soft crackling.");
  63. 		    rangemod -= 1000;	/* stop */
  64. 		} else {
  65. 		    rangemod -= 3;
  66. 		    if (lev->typ == DRAWBRIDGE_UP) {
  67. 			lev->drawbridgemask &= ~DB_UNDER;  /* clear lava */
  68. 			lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE);
  69. 		    } else {
  70. 			if (!lava)
  71. 			    lev->icedpool =
  72. 				    (lev->typ == POOL ? ICED_POOL : ICED_MOAT);
  73. 			lev->typ = (lava ? ROOM : ICE);
  74. 		    }
  75. 		    bury_objs(x,y);
  76. 		    if(cansee(x,y)) {
  77. 			if(moat)
  78. 				Norep("The moat is bridged with ice!");
  79. 			else if(lava)
  80. 				Norep("The lava cools and solidifies.");
  81. 			else
  82. 				Norep("The water freezes.");
  83. 			newsym(x,y);
  84. 		    } else if(flags.soundok && !lava)
  85. 			You_hear("a crackling sound.");
  86.  
  87. 		    if (x == u.ux && y == u.uy) {
  88. 			if (u.uinwater) {   /* not just `if (Underwater)' */
  89. 			    /* leave the no longer existent water */
  90. 			    u.uinwater = 0;
  91. 			    u.uundetected = 0;
  92. 			    docrt();
  93. 			    vision_full_recalc = 1;
  94. 			} else if (u.utrap && u.utraptype == TT_LAVA) {
  95. 			    if (Passes_walls) {
  96. 				You("pass through the now-solid rock.");
  97. 			    } else {
  98. 				u.utrap = rn1(50,20);
  99. 				u.utraptype = TT_INFLOOR;
  100. 				You("are firmly stuck in the cooling rock.");
  101. 			    }
  102. 			}
  103. 		    } else if ((mon = m_at(x,y)) != 0) {
  104. 			/* probably ought to do some hefty damage to any
  105. 			   non-ice creature caught in freezing water;
  106. 			   at a minimum, eels are forced out of hiding */
  107. 			if (is_swimmer(mon->data) && mon->mundetected) {
  108. 			    mon->mundetected = 0;
  109. 			    newsym(x,y);
  110. 			}
  111. 		    }
  112. 		}
  113. 		obj_ice_effects(x,y,TRUE);
  114. 	}
  115. 	if(closed_door(x, y)) {
  116. 		int new_doormask = -1;
  117. 		const char *see_txt = 0, *sense_txt = 0, *hear_txt = 0;
  118. 		rangemod = -1000;
  119. 		switch(abstype) {
  120. 		case ZT_FIRE:
  121. 		    new_doormask = D_NODOOR;
  122. 		    see_txt = "The door is consumed in flames!";
  123. 		    sense_txt = "smell smoke.";
  124. 		    break;
  125. 		case ZT_COLD:
  126. 		    new_doormask = D_NODOOR;
  127. 		    see_txt = "The door freezes and shatters!";
  128. 		    sense_txt = "feel cold.";
  129. 		    break;
  130. 		case ZT_DEATH:
  131. 		    /* death spells/wands don't disintegrate */
  132. 		    if(abs(type) != ZT_BREATH(ZT_DEATH))
  133. 			goto def_case;
  134. 		    new_doormask = D_NODOOR;
  135. 		    see_txt = "The door disintegrates!";
  136. 		    hear_txt = "crashing wood.";
  137. 		    break;
  138. 		case ZT_LIGHTNING:
  139. 		    new_doormask = D_BROKEN;
  140. 		    see_txt = "The door splinters!";
  141. 		    hear_txt = "crackling.";
  142. 		    break;
  143. 		default:
  144. 		def_case:
  145. 		    if(cansee(x,y)) {
  146. 			pline_The("door absorbs %s %s!",
  147. 			      (type < 0) ? "the" : "your",
  148. 			      abs(type) < ZT_SPELL(0) ? "bolt" :
  149. 			      abs(type) < ZT_BREATH(0) ? "spell" :
  150. 			      "blast");
  151. 		    } else You_feel("vibrations.");
  152. 		    break;
  153. 		}
  154. 		if (new_doormask >= 0) {	/* door gets broken */
  155. 		    if (*in_rooms(x, y, SHOPBASE)) {
  156. 			if (type >= 0) {
  157. 			    add_damage(x, y, 400L);
  158. 			    *shopdamage = TRUE;
  159. 			} else	/* caused by monster */
  160. 			    add_damage(x, y, 0L);
  161. 		    }
  162. 		    lev->doormask = new_doormask;
  163. 		    unblock_point(x, y);	/* vision */
  164. 		    if (cansee(x, y)) {
  165. 			pline(see_txt);
  166. 			newsym(x, y);
  167. 		    } else if (sense_txt) {
  168. 			You(sense_txt);
  169. 		    } else if (hear_txt) {
  170. 			if (flags.soundok) You_hear(hear_txt);
  171. 		    }
  172. 		    if (picking_at(x, y)) {
  173. 			stop_occupation();
  174. 			reset_pick();
  175. 		    }
  176. 		}
  177. 	}
  178.  
  179. 	if(OBJ_AT(x, y) && abstype == ZT_FIRE)
  180. 		if (burn_floor_paper(x, y, FALSE, type > 0) && couldsee(x, y)) {
  181. 		    newsym(x,y);
  182. 		    You("%s of smoke.",
  183. 			!Blind ? "see a puff" : "smell a whiff");
  184. 		}
  185. 	if ((mon = m_at(x,y)) != 0) {
  186. 		/* Cannot use wakeup() which also angers the monster */
  187. 		mon->msleeping = 0;
  188. 		if(mon->m_ap_type) seemimic(mon);
  189. 		if(type >= 0) {
  190. 		    setmangry(mon);
  191. 		    if(mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE))
  192. 			ghod_hitsu(mon);
  193. 		    if(mon->isshk && !*u.ushops)
  194. 			hot_pursuit(mon);
  195. 		}
  196. 	}
  197. 	return rangemod;
  198. }
  199.  
  200. #endif /*OVL0*/

fracture_rock

  1. #ifdef OVL3
  2.  
  3. void
  4. fracture_rock(obj)	/* fractured by pick-axe or wand of striking */
  5. register struct obj *obj;		   /* no texts here! */
  6. {
  7. 	/* A little Sokoban guilt... */
  8. 	if (obj->otyp == BOULDER && In_sokoban(&u.uz) && !flags.mon_moving)
  9. 	    change_luck(-1);
  10.  
  11. 	obj->otyp = ROCK;
  12. 	obj->quan = (long) rn1(60, 7);
  13. 	obj->owt = weight(obj);
  14. 	obj->oclass = GEM_CLASS;
  15. 	obj->known = FALSE;
  16. 	obj->onamelth = 0;		/* no names */
  17. 	obj->oxlth = 0;			/* no extra data */
  18. 	obj->oattached = OATTACHED_NOTHING;
  19. 	if (obj->where == OBJ_FLOOR) {
  20. 		obj_extract_self(obj);		/* move rocks back on top */
  21. 		place_object(obj, obj->ox, obj->oy);
  22. 		if(!does_block(obj->ox,obj->oy,&levl[obj->ox][obj->oy]))
  23. 	    		unblock_point(obj->ox,obj->oy);
  24. 		if(cansee(obj->ox,obj->oy))
  25. 		    newsym(obj->ox,obj->oy);
  26. 	}
  27. }

break_statue

  1. /* handle statue hit by striking/force bolt/pick-axe */
  2. boolean
  3. break_statue(obj)
  4. register struct obj *obj;
  5. {
  6. 	/* [obj is assumed to be on floor, so no get_obj_location() needed] */
  7. 	struct trap *trap = t_at(obj->ox, obj->oy);
  8. 	struct obj *item;
  9.  
  10. 	if (trap && trap->ttyp == STATUE_TRAP &&
  11. 		activate_statue_trap(trap, obj->ox, obj->oy, TRUE))
  12. 	    return FALSE;
  13. 	/* drop any objects contained inside the statue */
  14. 	while ((item = obj->cobj) != 0) {
  15. 	    obj_extract_self(item);
  16. 	    place_object(item, obj->ox, obj->oy);
  17. 	}
  18. 	if (Role_if(PM_ARCHEOLOGIST) && !flags.mon_moving && (obj->spe & STATUE_HISTORIC)) {
  19. 	    You_feel("guilty about damaging such a historic statue.");
  20. 	    adjalign(-1);
  21. 	}
  22. 	obj->spe = 0;
  23. 	fracture_rock(obj);
  24. 	return TRUE;
  25. }

destroy_strings

  1. const char * const destroy_strings[] = {	/* also used in trap.c */
  2. 	"freezes and shatters", "freeze and shatter", "shattered potion",
  3. 	"boils and explodes", "boil and explode", "boiling potion",
  4. 	"catches fire and burns", "catch fire and burn", "burning scroll",
  5. 	"catches fire and burns", "catch fire and burn", "burning book",
  6. 	"turns to dust and vanishes", "turn to dust and vanish", "",
  7. 	"breaks apart and explodes", "break apart and explode", "exploding wand"
  8. };

destroy_item

  1. void
  2. destroy_item(osym, dmgtyp)
  3. register int osym, dmgtyp;
  4. {
  5. 	register struct obj *obj, *obj2;
  6. 	register int dmg, xresist, skip;
  7. 	register long i, cnt, quan;
  8. 	register int dindx;
  9. 	const char *mult;
  10.  
  11. 	for(obj = invent; obj; obj = obj2) {
  12. 	    obj2 = obj->nobj;
  13. 	    if(obj->oclass != osym) continue; /* test only objs of type osym */
  14. 	    if(obj->oartifact) continue; /* don't destroy artifacts */
  15. 	    if(obj->in_use && obj->quan == 1) continue; /* not available */
  16. 	    xresist = skip = 0;
  17. #ifdef GCC_WARN
  18. 	    dmg = dindx = 0;
  19. 	    quan = 0L;
  20. #endif
  21. 	    switch(dmgtyp) {
  22. 		case AD_COLD:
  23. 		    if(osym == POTION_CLASS && obj->otyp != POT_OIL) {
  24. 			quan = obj->quan;
  25. 			dindx = 0;
  26. 			dmg = rnd(4);
  27. 		    } else skip++;
  28. 		    break;
  29. 		case AD_FIRE:
  30. 		    xresist = (Fire_resistance && obj->oclass != POTION_CLASS);
  31.  
  32. 		    if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
  33. 			skip++;
  34. 		    if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  35. 			skip++;
  36. 			if (!Blind)
  37. 			    pline("%s glows a strange %s, but remains intact.",
  38. 				The(xname(obj)), hcolor("dark red"));
  39. 		    }
  40. 		    quan = obj->quan;
  41. 		    switch(osym) {
  42. 			case POTION_CLASS:
  43. 			    dindx = 1;
  44. 			    dmg = rnd(6);
  45. 			    break;
  46. 			case SCROLL_CLASS:
  47. 			    dindx = 2;
  48. 			    dmg = 1;
  49. 			    break;
  50. 			case SPBOOK_CLASS:
  51. 			    dindx = 3;
  52. 			    dmg = 1;
  53. 			    break;
  54. 			default:
  55. 			    skip++;
  56. 			    break;
  57. 		    }
  58. 		    break;
  59. 		case AD_ELEC:
  60. 		    xresist = (Shock_resistance && obj->oclass != RING_CLASS);
  61. 		    quan = obj->quan;
  62. 		    switch(osym) {
  63. 			case RING_CLASS:
  64. 			    if(obj->otyp == RIN_SHOCK_RESISTANCE)
  65. 				    { skip++; break; }
  66. 			    dindx = 4;
  67. 			    dmg = 0;
  68. 			    break;
  69. 			case WAND_CLASS:
  70. 			    if(obj->otyp == WAN_LIGHTNING) { skip++; break; }
  71. #if 0
  72. 			    if (obj == current_wand) { skip++; break; }
  73. #endif
  74. 			    dindx = 5;
  75. 			    dmg = rnd(10);
  76. 			    break;
  77. 			default:
  78. 			    skip++;
  79. 			    break;
  80. 		    }
  81. 		    break;
  82. 		default:
  83. 		    skip++;
  84. 		    break;
  85. 	    }
  86. 	    if(!skip) {
  87. 		if (obj->in_use) --quan; /* one will be used up elsewhere */
  88. 		for(i = cnt = 0L; i < quan; i++)
  89. 		    if(!rn2(3)) cnt++;
  90.  
  91. 		if(!cnt) continue;
  92. 		if(cnt == quan)	mult = "Your";
  93. 		else	mult = (cnt == 1L) ? "One of your" : "Some of your";
  94. 		pline("%s %s %s!", mult, xname(obj),
  95. 			(cnt > 1L) ? destroy_strings[dindx*3 + 1]
  96. 				  : destroy_strings[dindx*3]);
  97. 		if(osym == POTION_CLASS && dmgtyp != AD_COLD) {
  98. 		    if (!breathless(youmonst.data) || haseyes(youmonst.data))
  99. 		    	potionbreathe(obj);
  100. 		}
  101. 		if (obj->owornmask) {
  102. 		    if (obj->owornmask & W_RING) /* ring being worn */
  103. 			Ring_gone(obj);
  104. 		    else
  105. 			setnotworn(obj);
  106. 		}
  107. 		if (obj == current_wand) current_wand = 0;	/* destroyed */
  108. 		for (i = 0; i < cnt; i++)
  109. 		    useup(obj);
  110. 		if(dmg) {
  111. 		    if(xresist)	You("aren't hurt!");
  112. 		    else {
  113. 			const char *how = destroy_strings[dindx * 3 + 2];
  114. 			boolean one = (cnt == 1L);
  115.  
  116. 			losehp(dmg, one ? how : (const char *)makeplural(how),
  117. 			       one ? KILLED_BY_AN : KILLED_BY);
  118. 			exercise(A_STR, FALSE);
  119. 		    }
  120. 		}
  121. 	    }
  122. 	}
  123. 	return;
  124. }

destroy_mitem

  1. int
  2. destroy_mitem(mtmp, osym, dmgtyp)
  3. struct monst *mtmp;
  4. int osym, dmgtyp;
  5. {
  6. 	struct obj *obj, *obj2;
  7. 	int skip, tmp = 0;
  8. 	long i, cnt, quan;
  9. 	int dindx;
  10. 	boolean vis;
  11.  
  12. 	if (mtmp == &youmonst) {	/* this simplifies artifact_hit() */
  13. 	    destroy_item(osym, dmgtyp);
  14. 	    return 0;	/* arbitrary; value doesn't matter to artifact_hit() */
  15. 	}
  16.  
  17. 	vis = canseemon(mtmp);
  18. 	for(obj = mtmp->minvent; obj; obj = obj2) {
  19. 	    obj2 = obj->nobj;
  20. 	    if(obj->oclass != osym) continue; /* test only objs of type osym */
  21. 	    skip = 0;
  22. 	    quan = 0L;
  23. 	    dindx = 0;
  24.  
  25. 	    switch(dmgtyp) {
  26. 		case AD_COLD:
  27. 		    if(osym == POTION_CLASS && obj->otyp != POT_OIL) {
  28. 			quan = obj->quan;
  29. 			dindx = 0;
  30. 			tmp++;
  31. 		    } else skip++;
  32. 		    break;
  33. 		case AD_FIRE:
  34. 		    if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
  35. 			skip++;
  36. 		    if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  37. 			skip++;
  38. 			if (vis)
  39. 			    pline("%s glows a strange %s, but remains intact.",
  40. 				The(distant_name(obj, xname)),
  41. 				hcolor("dark red"));
  42. 		    }
  43. 		    quan = obj->quan;
  44. 		    switch(osym) {
  45. 			case POTION_CLASS:
  46. 			    dindx = 1;
  47. 			    tmp++;
  48. 			    break;
  49. 			case SCROLL_CLASS:
  50. 			    dindx = 2;
  51. 			    tmp++;
  52. 			    break;
  53. 			case SPBOOK_CLASS:
  54. 			    dindx = 3;
  55. 			    tmp++;
  56. 			    break;
  57. 			default:
  58. 			    skip++;
  59. 			    break;
  60. 		    }
  61. 		    break;
  62. 		case AD_ELEC:
  63. 		    quan = obj->quan;
  64. 		    switch(osym) {
  65. 			case RING_CLASS:
  66. 			    if(obj->otyp == RIN_SHOCK_RESISTANCE)
  67. 				    { skip++; break; }
  68. 			    dindx = 4;
  69. 			    break;
  70. 			case WAND_CLASS:
  71. 			    if(obj->otyp == WAN_LIGHTNING) { skip++; break; }
  72. 			    dindx = 5;
  73. 			    tmp++;
  74. 			    break;
  75. 			default:
  76. 			    skip++;
  77. 			    break;
  78. 		    }
  79. 		    break;
  80. 		default:
  81. 		    skip++;
  82. 		    break;
  83. 	    }
  84. 	    if(!skip) {
  85. 		for(i = cnt = 0L; i < quan; i++)
  86. 		    if(!rn2(3)) cnt++;
  87.  
  88. 		if(!cnt) continue;
  89. 		if (vis) pline("%s %s %s!",
  90. 			s_suffix(Monnam(mtmp)), xname(obj),
  91. 			(cnt > 1L) ? destroy_strings[dindx*3 + 1]
  92. 				  : destroy_strings[dindx*3]);
  93. 		for(i = 0; i < cnt; i++) m_useup(mtmp, obj);
  94. 	    }
  95. 	}
  96. 	return(tmp);
  97. }
  98.  
  99. #endif /*OVL3*/

resist

  1. #ifdef OVL2
  2.  
  3. int
  4. resist(mtmp, oclass, damage, tell)
  5. struct monst *mtmp;
  6. char oclass;
  7. int damage, tell;
  8. {
  9. 	int resisted;
  10. 	int alev, dlev;
  11.  
  12. 	/* attack level */
  13. 	switch (oclass) {
  14. 	    case WAND_CLASS:	alev = 12;	 break;
  15. 	    case TOOL_CLASS:	alev = 10;	 break;	/* instrument */
  16. 	    case WEAPON_CLASS:	alev = 10;	 break;	/* artifact */
  17. 	    case SCROLL_CLASS:	alev =  9;	 break;
  18. 	    case POTION_CLASS:	alev =  6;	 break;
  19. 	    case RING_CLASS:	alev =  5;	 break;
  20. 	    default:		alev = u.ulevel; break;	/* spell */
  21. 	}
  22. 	/* defense level */
  23. 	dlev = (int)mtmp->m_lev;
  24. 	if (dlev > 50) dlev = 50;
  25. 	else if (dlev < 1) dlev = is_mplayer(mtmp->data) ? u.ulevel : 1;
  26.  
  27. 	resisted = rn2(100 + alev - dlev) < mtmp->data->mr;
  28. 	if (resisted) {
  29. 	    if (tell) {
  30. 		shieldeff(mtmp->mx, mtmp->my);
  31. 		pline("%s resists!", Monnam(mtmp));
  32. 	    }
  33. 	    damage = (damage + 1) / 2;
  34. 	}
  35.  
  36. 	if (damage) {
  37. 	    mtmp->mhp -= damage;
  38. 	    if (mtmp->mhp < 1) {
  39. 		if(m_using) monkilled(mtmp, "", AD_RBRE);
  40. 		else killed(mtmp);
  41. 	    }
  42. 	}
  43. 	return(resisted);
  44. }

makewish

  1. void
  2. makewish()
  3. {
  4. 	char buf[BUFSZ];
  5. 	struct obj *otmp, nothing;
  6. 	int tries = 0;
  7.  
  8. 	nothing = zeroobj;  /* lint suppression; only its address matters */
  9. 	if (flags.verbose) You("may wish for an object.");
  10. retry:
  11. 	getlin("For what do you wish?", buf);
  12. 	if(buf[0] == '\033') buf[0] = 0;
  13. 	/*
  14. 	 *  Note: if they wished for and got a non-object successfully,
  15. 	 *  otmp == &zeroobj.  That includes gold, or an artifact that
  16. 	 *  has been denied.  Wishing for "nothing" requires a separate
  17. 	 *  value to remain distinct.
  18. 	 */
  19. 	otmp = readobjnam(buf, &nothing, TRUE);
  20. 	if (!otmp) {
  21. 	    pline("Nothing fitting that description exists in the game.");
  22. 	    if (++tries < 5) goto retry;
  23. 	    pline(thats_enough_tries);
  24. 	    otmp = readobjnam((char *)0, (struct obj *)0, TRUE);
  25. 	    if (!otmp) return;	/* for safety; should never happen */
  26. 	} else if (otmp == &nothing) {
  27. 	    /* explicitly wished for "nothing", presumeably attempting
  28. 	       to retain wishless conduct */
  29. 	    return;
  30. 	}
  31.  
  32. 	/* KMH, conduct */
  33. 	u.uconduct.wishes++;
  34.  
  35. 	if (otmp != &zeroobj) {
  36. 	    /* The(aobjnam()) is safe since otmp is unidentified -dlc */
  37. 	    (void) hold_another_object(otmp, u.uswallow ?
  38. 				       "Oops!  %s out of your reach!" :
  39. 				       (Is_airlevel(&u.uz) ||
  40. 					Is_waterlevel(&u.uz) ||
  41. 					levl[u.ux][u.uy].typ < IRONBARS ||
  42. 					levl[u.ux][u.uy].typ >= ICE) ?
  43. 				       "Oops!  %s away from you!" :
  44. 				       "Oops!  %s to the floor!",
  45. 				       The(aobjnam(otmp,
  46. 					     Is_airlevel(&u.uz) || u.uinwater ?
  47. 						   "slip" : "drop")),
  48. 				       (const char *)0);
  49. 	    u.ublesscnt += rn1(100,50);  /* the gods take notice */
  50. 	}
  51. }
  52.  
  53. #endif /*OVL2*/
  54.  
  55. /*zap.c*/