Source:NetHack 3.4.3/src/uhitm.c

From NetHackWiki
(Redirected from Source:Ref/start engulf)
Jump to: navigation, search

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

Top of file

  1. /*	SCCS Id: @(#)uhitm.c	3.4	2003/02/18	*/
  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. STATIC_DCL boolean FDECL(known_hitum, (struct monst *,int *,struct attack *));
  4. STATIC_DCL void FDECL(steal_it, (struct monst *, struct attack *));
  5. STATIC_DCL boolean FDECL(hitum, (struct monst *,int,struct attack *));
  6. STATIC_DCL boolean FDECL(hmon_hitmon, (struct monst *,struct obj *,int));
  7. #ifdef STEED
  8. STATIC_DCL int FDECL(joust, (struct monst *,struct obj *));
  9. #endif
  10. STATIC_DCL void NDECL(demonpet);
  11. STATIC_DCL boolean FDECL(m_slips_free, (struct monst *mtmp,struct attack *mattk));
  12. STATIC_DCL int FDECL(explum, (struct monst *,struct attack *));
  13. STATIC_DCL void FDECL(start_engulf, (struct monst *));
  14. STATIC_DCL void NDECL(end_engulf);
  15. STATIC_DCL int FDECL(gulpum, (struct monst *,struct attack *));
  16. STATIC_DCL boolean FDECL(hmonas, (struct monst *,int));
  17. STATIC_DCL void FDECL(nohandglow, (struct monst *));
  18. STATIC_DCL boolean FDECL(shade_aware, (struct obj *));
  19.  
  20. extern boolean notonhead;	/* for long worms */
  21. /* The below might become a parameter instead if we use it a lot */
  22. static int dieroll;
  23. /* Used to flag attacks caused by Stormbringer's maliciousness. */
  24. static boolean override_confirmation = FALSE;
  25.  
  26. #define PROJECTILE(obj)	((obj) && is_ammo(obj))

hurtmarmor

  1. /* modified from hurtarmor() in mhitu.c */
  2. /* This is not static because it is also used for monsters rusting monsters */
  3. void
  4. hurtmarmor(mdef, attk)
  5. struct monst *mdef;
  6. int attk;
  7. {
  8. 	int	hurt;
  9. 	struct obj *target;
  10.  
  11. 	switch(attk) {
  12. 	    /* 0 is burning, which we should never be called with */
  13. 	    case AD_RUST: hurt = 1; break;
  14. 	    case AD_CORR: hurt = 3; break;
  15. 	    default: hurt = 2; break;
  16. 	}
  17. 	/* What the following code does: it keeps looping until it
  18. 	 * finds a target for the rust monster.
  19. 	 * Head, feet, etc... not covered by metal, or covered by
  20. 	 * rusty metal, are not targets.  However, your body always
  21. 	 * is, no matter what covers it.
  22. 	 */
  23. 	while (1) {
  24. 	    switch(rn2(5)) {
  25. 	    case 0:
  26. 		target = which_armor(mdef, W_ARMH);
  27. 		if (!target || !rust_dmg(target, xname(target), hurt, FALSE, mdef))
  28. 		    continue;
  29. 		break;
  30. 	    case 1:
  31. 		target = which_armor(mdef, W_ARMC);
  32. 		if (target) {
  33. 		    (void)rust_dmg(target, xname(target), hurt, TRUE, mdef);
  34. 		    break;
  35. 		}
  36. 		if ((target = which_armor(mdef, W_ARM)) != (struct obj *)0) {
  37. 		    (void)rust_dmg(target, xname(target), hurt, TRUE, mdef);
  38. #ifdef TOURIST
  39. 		} else if ((target = which_armor(mdef, W_ARMU)) != (struct obj *)0) {
  40. 		    (void)rust_dmg(target, xname(target), hurt, TRUE, mdef);
  41. #endif
  42. 		}
  43. 		break;
  44. 	    case 2:
  45. 		target = which_armor(mdef, W_ARMS);
  46. 		if (!target || !rust_dmg(target, xname(target), hurt, FALSE, mdef))
  47. 		    continue;
  48. 		break;
  49. 	    case 3:
  50. 		target = which_armor(mdef, W_ARMG);
  51. 		if (!target || !rust_dmg(target, xname(target), hurt, FALSE, mdef))
  52. 		    continue;
  53. 		break;
  54. 	    case 4:
  55. 		target = which_armor(mdef, W_ARMF);
  56. 		if (!target || !rust_dmg(target, xname(target), hurt, FALSE, mdef))
  57. 		    continue;
  58. 		break;
  59. 	    }
  60. 	    break; /* Out of while loop */
  61. 	}
  62. }

attack_checks

  1. /* FALSE means it's OK to attack */
  2. boolean
  3. attack_checks(mtmp, wep)
  4. register struct monst *mtmp;
  5. struct obj *wep;	/* uwep for attack(), null for kick_monster() */
  6. {
  7. 	char qbuf[QBUFSZ];
  8.  
  9. 	/* if you're close enough to attack, alert any waiting monster */
  10. 	mtmp->mstrategy &= ~STRAT_WAITMASK;
  11.  
  12. 	if (u.uswallow && mtmp == u.ustuck) return FALSE;
  13.  
  14. 	if (flags.forcefight) {
  15. 		/* Do this in the caller, after we checked that the monster
  16. 		 * didn't die from the blow.  Reason: putting the 'I' there
  17. 		 * causes the hero to forget the square's contents since
  18. 		 * both 'I' and remembered contents are stored in .glyph.
  19. 		 * If the monster dies immediately from the blow, the 'I' will
  20. 		 * not stay there, so the player will have suddenly forgotten
  21. 		 * the square's contents for no apparent reason.
  22. 		if (!canspotmon(mtmp) &&
  23. 		    !glyph_is_invisible(levl[u.ux+u.dx][u.uy+u.dy].glyph))
  24. 			map_invisible(u.ux+u.dx, u.uy+u.dy);
  25. 		 */
  26. 		return FALSE;
  27. 	}
  28.  
  29. 	/* Put up an invisible monster marker, but with exceptions for
  30. 	 * monsters that hide and monsters you've been warned about.
  31. 	 * The former already prints a warning message and
  32. 	 * prevents you from hitting the monster just via the hidden monster
  33. 	 * code below; if we also did that here, similar behavior would be
  34. 	 * happening two turns in a row.  The latter shows a glyph on
  35. 	 * the screen, so you know something is there.
  36. 	 */
  37. 	if (!canspotmon(mtmp) &&
  38. 		    !glyph_is_warning(glyph_at(u.ux+u.dx,u.uy+u.dy)) &&
  39. 		    !glyph_is_invisible(levl[u.ux+u.dx][u.uy+u.dy].glyph) &&
  40. 		    !(!Blind && mtmp->mundetected && hides_under(mtmp->data))) {
  41. 		pline("Wait!  There's %s there you can't see!",
  42. 			something);
  43. 		map_invisible(u.ux+u.dx, u.uy+u.dy);
  44. 		/* if it was an invisible mimic, treat it as if we stumbled
  45. 		 * onto a visible mimic
  46. 		 */
  47. 		if(mtmp->m_ap_type && !Protection_from_shape_changers) {
  48. 		    if(!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data,AD_STCK))
  49. 			u.ustuck = mtmp;
  50. 		}
  51. 		wakeup(mtmp); /* always necessary; also un-mimics mimics */
  52. 		return TRUE;
  53. 	}
  54.  
  55. 	if (mtmp->m_ap_type && !Protection_from_shape_changers &&
  56. 	   !sensemon(mtmp) &&
  57. 	   !glyph_is_warning(glyph_at(u.ux+u.dx,u.uy+u.dy))) {
  58. 		/* If a hidden mimic was in a square where a player remembers
  59. 		 * some (probably different) unseen monster, the player is in
  60. 		 * luck--he attacks it even though it's hidden.
  61. 		 */
  62. 		if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) {
  63. 		    seemimic(mtmp);
  64. 		    return(FALSE);
  65. 		}
  66. 		stumble_onto_mimic(mtmp);
  67. 		return TRUE;
  68. 	}
  69.  
  70. 	if (mtmp->mundetected && !canseemon(mtmp) &&
  71. 		!glyph_is_warning(glyph_at(u.ux+u.dx,u.uy+u.dy)) &&
  72. 		(hides_under(mtmp->data) || mtmp->data->mlet == S_EEL)) {
  73. 	    mtmp->mundetected = mtmp->msleeping = 0;
  74. 	    newsym(mtmp->mx, mtmp->my);
  75. 	    if (glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph)) {
  76. 		seemimic(mtmp);
  77. 		return(FALSE);
  78. 	    }
  79. 	    if (!(Blind ? Blind_telepat : Unblind_telepat)) {
  80. 		struct obj *obj;
  81.  
  82. 		if (Blind || (is_pool(mtmp->mx,mtmp->my) && !Underwater))
  83. 		    pline("Wait!  There's a hidden monster there!");
  84. 		else if ((obj = level.objects[mtmp->mx][mtmp->my]) != 0)
  85. 		    pline("Wait!  There's %s hiding under %s!",
  86. 			  an(l_monnam(mtmp)), doname(obj));
  87. 		return TRUE;
  88. 	    }
  89. 	}
  90.  
  91. 	/*
  92. 	 * make sure to wake up a monster from the above cases if the
  93. 	 * hero can sense that the monster is there.
  94. 	 */
  95. 	if ((mtmp->mundetected || mtmp->m_ap_type) && sensemon(mtmp)) {
  96. 	    mtmp->mundetected = 0;
  97. 	    wakeup(mtmp);
  98. 	}
  99.  
  100. 	if (flags.confirm && mtmp->mpeaceful
  101. 	    && !Confusion && !Hallucination && !Stunned) {
  102. 		/* Intelligent chaotic weapons (Stormbringer) want blood */
  103. 		if (wep && wep->oartifact == ART_STORMBRINGER) {
  104. 			override_confirmation = TRUE;
  105. 			return(FALSE);
  106. 		}
  107. 		if (canspotmon(mtmp)) {
  108. 			Sprintf(qbuf, "Really attack %s?", mon_nam(mtmp));
  109. 			if (yn(qbuf) != 'y') {
  110. 				flags.move = 0;
  111. 				return(TRUE);
  112. 			}
  113. 		}
  114. 	}
  115.  
  116. 	return(FALSE);
  117. }

check_caitiff

  1. /*
  2. * It is unchivalrous for a knight to attack the defenseless or from behind.
  3. */
  4. void
  5. check_caitiff(mtmp)
  6. struct monst *mtmp;
  7. {
  8. 	if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL &&
  9. 	    (!mtmp->mcanmove || mtmp->msleeping ||
  10. 	     (mtmp->mflee && !mtmp->mavenge)) &&
  11. 	    u.ualign.record > -10) {
  12. 	    You("caitiff!");
  13. 	    adjalign(-1);
  14. 	}
  15. }

find_roll_to_hit

  1. schar
  2. find_roll_to_hit(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	schar tmp;
  6. 	int tmp2;
  7.  
  8. 	tmp = 1 + Luck + abon() + find_mac(mtmp) + u.uhitinc +
  9. 		maybe_polyd(youmonst.data->mlevel, u.ulevel);
  10.  
  11. 	check_caitiff(mtmp);
  12.  
  13. /*	attacking peaceful creatures is bad for the samurai's giri */
  14. 	if (Role_if(PM_SAMURAI) && mtmp->mpeaceful &&
  15. 	    u.ualign.record > -10) {
  16. 	    You("dishonorably attack the innocent!");
  17. 	    adjalign(-1);
  18. 	}
  19.  
  20. /*	Adjust vs. (and possibly modify) monster state.		*/
  21.  
  22. 	if(mtmp->mstun) tmp += 2;
  23. 	if(mtmp->mflee) tmp += 2;
  24.  
  25. 	if (mtmp->msleeping) {
  26. 		mtmp->msleeping = 0;
  27. 		tmp += 2;
  28. 	}
  29. 	if(!mtmp->mcanmove) {
  30. 		tmp += 4;
  31. 		if(!rn2(10)) {
  32. 			mtmp->mcanmove = 1;
  33. 			mtmp->mfrozen = 0;
  34. 		}
  35. 	}
  36. 	if (is_orc(mtmp->data) && maybe_polyd(is_elf(youmonst.data),
  37. 			Race_if(PM_ELF)))
  38. 	    tmp++;
  39. 	if(Role_if(PM_MONK) && !Upolyd) {
  40. 	    if (uarm) {
  41. 		Your("armor is rather cumbersome...");
  42. 		tmp -= urole.spelarmr;
  43. 	    } else if (!uwep && !uarms) {
  44. 		tmp += (u.ulevel / 3) + 2;
  45. 	    }
  46. 	}
  47.  
  48. /*	with a lot of luggage, your agility diminishes */
  49. 	if ((tmp2 = near_capacity()) != 0) tmp -= (tmp2*2) - 1;
  50. 	if (u.utrap) tmp -= 3;
  51. /*	Some monsters have a combination of weapon attacks and non-weapon
  52. *	attacks.  It is therefore wrong to add hitval to tmp; we must add
  53. *	it only for the specific attack (in hmonas()).
  54. */
  55. 	if (uwep && !Upolyd) {
  56. 		tmp += hitval(uwep, mtmp);
  57. 		tmp += weapon_hit_bonus(uwep);
  58. 	}
  59. 	return tmp;
  60. }

attack

  1. /* try to attack; return FALSE if monster evaded */
  2. /* u.dx and u.dy must be set */
  3. boolean
  4. attack(mtmp)
  5. register struct monst *mtmp;
  6. {
  7. 	schar tmp;
  8. 	register struct permonst *mdat = mtmp->data;
  9.  
  10. 	/* This section of code provides protection against accidentally
  11. 	 * hitting peaceful (like '@') and tame (like 'd') monsters.
  12. 	 * Protection is provided as long as player is not: blind, confused,
  13. 	 * hallucinating or stunned.
  14. 	 * changes by wwp 5/16/85
  15. 	 * More changes 12/90, -dkh-. if its tame and safepet, (and protected
  16. 	 * 07/92) then we assume that you're not trying to attack. Instead,
  17. 	 * you'll usually just swap places if this is a movement command
  18. 	 */
  19. 	/* Intelligent chaotic weapons (Stormbringer) want blood */
  20. 	if (is_safepet(mtmp) && !flags.forcefight) {
  21. 	    if (!uwep || uwep->oartifact != ART_STORMBRINGER) {
  22. 		/* there are some additional considerations: this won't work
  23. 		 * if in a shop or Punished or you miss a random roll or
  24. 		 * if you can walk thru walls and your pet cannot (KAA) or
  25. 		 * if your pet is a long worm (unless someone does better).
  26. 		 * there's also a chance of displacing a "frozen" monster.
  27. 		 * sleeping monsters might magically walk in their sleep.
  28. 		 */
  29. 		boolean foo = (Punished || !rn2(7) || is_longworm(mtmp->data)),
  30. 			inshop = FALSE;
  31. 		char *p;
  32.  
  33. 		for (p = in_rooms(mtmp->mx, mtmp->my, SHOPBASE); *p; p++)
  34. 		    if (tended_shop(&rooms[*p - ROOMOFFSET])) {
  35. 			inshop = TRUE;
  36. 			break;
  37. 		    }
  38.  
  39. 		if (inshop || foo ||
  40. 			(IS_ROCK(levl[u.ux][u.uy].typ) &&
  41. 					!passes_walls(mtmp->data))) {
  42. 		    char buf[BUFSZ];
  43.  
  44. 		    monflee(mtmp, rnd(6), FALSE, FALSE);
  45. 		    Strcpy(buf, y_monnam(mtmp));
  46. 		    buf[0] = highc(buf[0]);
  47. 		    You("stop.  %s is in the way!", buf);
  48. 		    return(TRUE);
  49. 		} else if ((mtmp->mfrozen || (! mtmp->mcanmove)
  50. 				|| (mtmp->data->mmove == 0)) && rn2(6)) {
  51. 		    pline("%s doesn't seem to move!", Monnam(mtmp));
  52. 		    return(TRUE);
  53. 		} else return(FALSE);
  54. 	    }
  55. 	}
  56.  
  57. 	/* possibly set in attack_checks;
  58. 	   examined in known_hitum, called via hitum or hmonas below */
  59. 	override_confirmation = FALSE;
  60. 	if (attack_checks(mtmp, uwep)) return(TRUE);
  61.  
  62. 	if (Upolyd) {
  63. 		/* certain "pacifist" monsters don't attack */
  64. 		if(noattacks(youmonst.data)) {
  65. 			You("have no way to attack monsters physically.");
  66. 			mtmp->mstrategy &= ~STRAT_WAITMASK;
  67. 			goto atk_done;
  68. 		}
  69. 	}
  70.  
  71. 	if(check_capacity("You cannot fight while so heavily loaded."))
  72. 	    goto atk_done;
  73.  
  74. 	if (u.twoweap && !can_twoweapon())
  75. 		untwoweapon();
  76.  
  77. 	if(unweapon) {
  78. 	    unweapon = FALSE;
  79. 	    if(flags.verbose) {
  80. 		if(uwep)
  81. 		    You("begin bashing monsters with your %s.",
  82. 			aobjnam(uwep, (char *)0));
  83. 		else if (!cantwield(youmonst.data))
  84. 		    You("begin %sing monsters with your %s %s.",
  85. 			Role_if(PM_MONK) ? "strik" : "bash",
  86. 			uarmg ? "gloved" : "bare",	/* Del Lamb */
  87. 			makeplural(body_part(HAND)));
  88. 	    }
  89. 	}
  90. 	exercise(A_STR, TRUE);		/* you're exercising muscles */
  91. 	/* andrew@orca: prevent unlimited pick-axe attacks */
  92. 	u_wipe_engr(3);
  93.  
  94. 	/* Is the "it died" check actually correct? */
  95. 	if(mdat->mlet == S_LEPRECHAUN && !mtmp->mfrozen && !mtmp->msleeping &&
  96. 	   !mtmp->mconf && mtmp->mcansee && !rn2(7) &&
  97. 	   (m_move(mtmp, 0) == 2 ||			    /* it died */
  98. 	   mtmp->mx != u.ux+u.dx || mtmp->my != u.uy+u.dy)) /* it moved */
  99. 		return(FALSE);
  100.  
  101. 	tmp = find_roll_to_hit(mtmp);
  102. 	if (Upolyd)
  103. 		(void) hmonas(mtmp, tmp);
  104. 	else
  105. 		(void) hitum(mtmp, tmp, youmonst.data->mattk);
  106. 	mtmp->mstrategy &= ~STRAT_WAITMASK;
  107.  
  108. atk_done:
  109. 	/* see comment in attack_checks() */
  110. 	/* we only need to check for this if we did an attack_checks()
  111. 	 * and it returned 0 (it's okay to attack), and the monster didn't
  112. 	 * evade.
  113. 	 */
  114. 	if (flags.forcefight && mtmp->mhp > 0 && !canspotmon(mtmp) &&
  115. 	    !glyph_is_invisible(levl[u.ux+u.dx][u.uy+u.dy].glyph) &&
  116. 	    !(u.uswallow && mtmp == u.ustuck))
  117. 		map_invisible(u.ux+u.dx, u.uy+u.dy);
  118.  
  119. 	return(TRUE);
  120. }

known_hitum

  1. STATIC_OVL boolean
  2. known_hitum(mon, mhit, uattk)	/* returns TRUE if monster still lives */
  3. register struct monst *mon;
  4. register int *mhit;
  5. struct attack *uattk;
  6. {
  7. 	register boolean malive = TRUE;
  8.  
  9. 	if (override_confirmation) {
  10. 	    /* this may need to be generalized if weapons other than
  11. 	       Stormbringer acquire similar anti-social behavior... */
  12. 	    if (flags.verbose) Your("bloodthirsty blade attacks!");
  13. 	}
  14.  
  15. 	if(!*mhit) {
  16. 	    missum(mon, uattk);
  17. 	} else {
  18. 	    int oldhp = mon->mhp,
  19. 		x = u.ux + u.dx, y = u.uy + u.dy;
  20.  
  21. 	    /* KMH, conduct */
  22. 	    if (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))
  23. 		u.uconduct.weaphit++;
  24.  
  25. 	    /* we hit the monster; be careful: it might die or
  26. 	       be knocked into a different location */
  27. 	    notonhead = (mon->mx != x || mon->my != y);
  28. 	    malive = hmon(mon, uwep, 0);
  29. 	    /* this assumes that Stormbringer was uwep not uswapwep */ 
  30. 	    if (malive && u.twoweap && !override_confirmation &&
  31. 		    m_at(x, y) == mon)
  32. 		malive = hmon(mon, uswapwep, 0);
  33. 	    if (malive) {
  34. 		/* monster still alive */
  35. 		if(!rn2(25) && mon->mhp < mon->mhpmax/2
  36. 			    && !(u.uswallow && mon == u.ustuck)) {
  37. 		    /* maybe should regurgitate if swallowed? */
  38. 		    if(!rn2(3)) {
  39. 			monflee(mon, rnd(100), FALSE, TRUE);
  40. 		    } else monflee(mon, 0, FALSE, TRUE);
  41.  
  42. 		    if(u.ustuck == mon && !u.uswallow && !sticks(youmonst.data))
  43. 			u.ustuck = 0;
  44. 		}
  45. 		/* Vorpal Blade hit converted to miss */
  46. 		/* could be headless monster or worm tail */
  47. 		if (mon->mhp == oldhp) {
  48. 		    *mhit = 0;
  49. 		    /* a miss does not break conduct */
  50. 		    if (uwep &&
  51. 			(uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))
  52. 			--u.uconduct.weaphit;
  53. 		}
  54. 		if (mon->wormno && *mhit)
  55. 		    cutworm(mon, x, y, uwep);
  56. 	    }
  57. 	}
  58. 	return(malive);
  59. }

hitum

  1. STATIC_OVL boolean
  2. hitum(mon, tmp, uattk)		/* returns TRUE if monster still lives */
  3. struct monst *mon;
  4. int tmp;
  5. struct attack *uattk;
  6. {
  7. 	boolean malive;
  8. 	int mhit = (tmp > (dieroll = rnd(20)) || u.uswallow);
  9.  
  10. 	if(tmp > dieroll) exercise(A_DEX, TRUE);
  11. 	malive = known_hitum(mon, &mhit, uattk);
  12. 	(void) passive(mon, mhit, malive, AT_WEAP);
  13. 	return(malive);
  14. }

hmon

  1. boolean			/* general "damage monster" routine */
  2. hmon(mon, obj, thrown)		/* return TRUE if mon still alive */
  3. struct monst *mon;
  4. struct obj *obj;
  5. int thrown;
  6. {
  7. 	boolean result, anger_guards;
  8.  
  9. 	anger_guards = (mon->mpeaceful &&
  10. 			    (mon->ispriest || mon->isshk ||
  11. 			     mon->data == &mons[PM_WATCHMAN] ||
  12. 			     mon->data == &mons[PM_WATCH_CAPTAIN]));
  13. 	result = hmon_hitmon(mon, obj, thrown);
  14. 	if (mon->ispriest && !rn2(2)) ghod_hitsu(mon);
  15. 	if (anger_guards) (void)angry_guards(!flags.soundok);
  16. 	return result;
  17. }

hmon_hitmon

  1. /* guts of hmon() */
  2. STATIC_OVL boolean
  3. hmon_hitmon(mon, obj, thrown)
  4. struct monst *mon;
  5. struct obj *obj;
  6. int thrown;
  7. {
  8. 	int tmp;
  9. 	struct permonst *mdat = mon->data;
  10. 	int barehand_silver_rings = 0;
  11. 	/* The basic reason we need all these booleans is that we don't want
  12. 	 * a "hit" message when a monster dies, so we have to know how much
  13. 	 * damage it did _before_ outputting a hit message, but any messages
  14. 	 * associated with the damage don't come out until _after_ outputting
  15. 	 * a hit message.
  16. 	 */
  17. 	boolean hittxt = FALSE, destroyed = FALSE, already_killed = FALSE;
  18. 	boolean get_dmg_bonus = TRUE;
  19. 	boolean ispoisoned = FALSE, needpoismsg = FALSE, poiskilled = FALSE;
  20. 	boolean silvermsg = FALSE, silverobj = FALSE;
  21. 	boolean valid_weapon_attack = FALSE;
  22. 	boolean unarmed = !uwep && !uarm && !uarms;
  23. #ifdef STEED
  24. 	int jousting = 0;
  25. #endif
  26. 	int wtype;
  27. 	struct obj *monwep;
  28. 	char yourbuf[BUFSZ];
  29. 	char unconventional[BUFSZ];	/* substituted for word "attack" in msg */
  30. 	char saved_oname[BUFSZ];
  31.  
  32. 	unconventional[0] = '\0';
  33. 	saved_oname[0] = '\0';
  34.  
  35. 	wakeup(mon);
  36. 	if(!obj) {	/* attack with bare hands */
  37. 	    if (mdat == &mons[PM_SHADE])
  38. 		tmp = 0;
  39. 	    else if (martial_bonus())
  40. 		tmp = rnd(4);	/* bonus for martial arts */
  41. 	    else
  42. 		tmp = rnd(2);
  43. 	    valid_weapon_attack = (tmp > 1);
  44. 	    /* blessed gloves give bonuses when fighting 'bare-handed' */
  45. 	    if (uarmg && uarmg->blessed && (is_undead(mdat) || is_demon(mdat)))
  46. 		tmp += rnd(4);
  47. 	    /* So do silver rings.  Note: rings are worn under gloves, so you
  48. 	     * don't get both bonuses.
  49. 	     */
  50. 	    if (!uarmg) {
  51. 		if (uleft && objects[uleft->otyp].oc_material == SILVER)
  52. 		    barehand_silver_rings++;
  53. 		if (uright && objects[uright->otyp].oc_material == SILVER)
  54. 		    barehand_silver_rings++;
  55. 		if (barehand_silver_rings && hates_silver(mdat)) {
  56. 		    tmp += rnd(20);
  57. 		    silvermsg = TRUE;
  58. 		}
  59. 	    }
  60. 	} else {
  61. 	    Strcpy(saved_oname, cxname(obj));
  62. 	    if(obj->oclass == WEAPON_CLASS || is_weptool(obj) ||
  63. 	       obj->oclass == GEM_CLASS) {
  64.  
  65. 		/* is it not a melee weapon? */
  66. 		if (/* if you strike with a bow... */
  67. 		    is_launcher(obj) ||
  68. 		    /* or strike with a missile in your hand... */
  69. 		    (!thrown && (is_missile(obj) || is_ammo(obj))) ||
  70. 		    /* or use a pole at short range and not mounted... */
  71. 		    (!thrown &&
  72. #ifdef STEED
  73. 		     !u.usteed &&
  74. #endif
  75. 		     is_pole(obj)) ||
  76. 		    /* or throw a missile without the proper bow... */
  77. 		    (is_ammo(obj) && !ammo_and_launcher(obj, uwep))) {
  78. 		    /* then do only 1-2 points of damage */
  79. 		    if (mdat == &mons[PM_SHADE] && obj->otyp != SILVER_ARROW)
  80. 			tmp = 0;
  81. 		    else
  82. 			tmp = rnd(2);
  83. 		    if (!thrown && obj == uwep && obj->otyp == BOOMERANG &&
  84. 			    rnl(4) == 4-1) {
  85. 			boolean more_than_1 = (obj->quan > 1L);
  86.  
  87. 			pline("As you hit %s, %s%s %s breaks into splinters.",
  88. 			      mon_nam(mon), more_than_1 ? "one of " : "",
  89. 			      shk_your(yourbuf, obj), xname(obj));
  90. 			if (!more_than_1) uwepgone();	/* set unweapon */
  91. 			useup(obj);
  92. 			if (!more_than_1) obj = (struct obj *) 0;
  93. 			hittxt = TRUE;
  94. 			if (mdat != &mons[PM_SHADE])
  95. 			    tmp++;
  96. 		    }
  97. 		} else {
  98. 		    tmp = dmgval(obj, mon);
  99. 		    /* a minimal hit doesn't exercise proficiency */
  100. 		    valid_weapon_attack = (tmp > 1);
  101. 		    if (!valid_weapon_attack || mon == u.ustuck || u.twoweap) {
  102. 			;	/* no special bonuses */
  103. 		    } else if (mon->mflee && Role_if(PM_ROGUE) && !Upolyd) {
  104. 			You("strike %s from behind!", mon_nam(mon));
  105. 			tmp += rnd(u.ulevel);
  106. 			hittxt = TRUE;
  107. 		    } else if (dieroll == 2 && obj == uwep &&
  108. 			  obj->oclass == WEAPON_CLASS &&
  109. 			  (bimanual(obj) ||
  110. 			    (Role_if(PM_SAMURAI) && obj->otyp == KATANA && !uarms)) &&
  111. 			  ((wtype = uwep_skill_type()) != P_NONE &&
  112. 			    P_SKILL(wtype) >= P_SKILLED) &&
  113. 			  ((monwep = MON_WEP(mon)) != 0 &&
  114. 			   !is_flimsy(monwep) &&
  115. 			   !obj_resists(monwep,
  116. 				 50 + 15 * greatest_erosion(obj), 100))) {
  117. 			/*
  118. 			 * 2.5% chance of shattering defender's weapon when
  119. 			 * using a two-handed weapon; less if uwep is rusted.
  120. 			 * [dieroll == 2 is most successful non-beheading or
  121. 			 * -bisecting hit, in case of special artifact damage;
  122. 			 * the percentage chance is (1/20)*(50/100).]
  123. 			 */
  124. 			setmnotwielded(mon,monwep);
  125. 			MON_NOWEP(mon);
  126. 			mon->weapon_check = NEED_WEAPON;
  127. 			pline("%s %s %s from the force of your blow!",
  128. 			      s_suffix(Monnam(mon)), xname(monwep),
  129. 			      otense(monwep, "shatter"));
  130. 			m_useup(mon, monwep);
  131. 			/* If someone just shattered MY weapon, I'd flee! */
  132. 			if (rn2(4)) {
  133. 			    monflee(mon, d(2,3), TRUE, TRUE);
  134. 			}
  135. 			hittxt = TRUE;
  136. 		    }
  137.  
  138. 		    if (obj->oartifact &&
  139. 			artifact_hit(&youmonst, mon, obj, &tmp, dieroll)) {
  140. 			if(mon->mhp <= 0) /* artifact killed monster */
  141. 			    return FALSE;
  142. 			if (tmp == 0) return TRUE;
  143. 			hittxt = TRUE;
  144. 		    }
  145. 		    if (objects[obj->otyp].oc_material == SILVER
  146. 				&& hates_silver(mdat)) {
  147. 			silvermsg = TRUE; silverobj = TRUE;
  148. 		    }
  149. #ifdef STEED
  150. 		    if (u.usteed && !thrown && tmp > 0 &&
  151. 			    weapon_type(obj) == P_LANCE && mon != u.ustuck) {
  152. 			jousting = joust(mon, obj);
  153. 			/* exercise skill even for minimal damage hits */
  154. 			if (jousting) valid_weapon_attack = TRUE;
  155. 		    }
  156. #endif
  157. 		    if (thrown && (is_ammo(obj) || is_missile(obj))) {
  158. 			if (ammo_and_launcher(obj, uwep)) {
  159. 			    /* Elves and Samurai do extra damage using
  160. 			     * their bows&arrows; they're highly trained.
  161. 			     */
  162. 			    if (Role_if(PM_SAMURAI) &&
  163. 				obj->otyp == YA && uwep->otyp == YUMI)
  164. 				tmp++;
  165. 			    else if (Race_if(PM_ELF) &&
  166. 				     obj->otyp == ELVEN_ARROW &&
  167. 				     uwep->otyp == ELVEN_BOW)
  168. 				tmp++;
  169. 			}
  170. 			if(obj->opoisoned && is_poisonable(obj))
  171. 			    ispoisoned = TRUE;
  172. 		    }
  173. 		}
  174. 	    } else if(obj->oclass == POTION_CLASS) {
  175. 		if (obj->quan > 1L)
  176. 		    obj = splitobj(obj, 1L);
  177. 		else
  178. 		    setuwep((struct obj *)0);
  179. 		freeinv(obj);
  180. 		potionhit(mon, obj, TRUE);
  181. 		if (mon->mhp <= 0) return FALSE;	/* killed */
  182. 		hittxt = TRUE;
  183. 		/* in case potion effect causes transformation */
  184. 		mdat = mon->data;
  185. 		tmp = (mdat == &mons[PM_SHADE]) ? 0 : 1;
  186. 	    } else {
  187. 		if (mdat == &mons[PM_SHADE] && !shade_aware(obj)) {
  188. 		    tmp = 0;
  189. 		    Strcpy(unconventional, cxname(obj));
  190. 		} else {
  191. 		    switch(obj->otyp) {
  192. 		    case BOULDER:		/* 1d20 */
  193. 		    case HEAVY_IRON_BALL:	/* 1d25 */
  194. 		    case IRON_CHAIN:		/* 1d4+1 */
  195. 			tmp = dmgval(obj, mon);
  196. 			break;
  197. 		    case MIRROR:
  198. 			if (breaktest(obj)) {
  199. 			    You("break %s mirror.  That's bad luck!",
  200. 				shk_your(yourbuf, obj));
  201. 			    change_luck(-2);
  202. 			    useup(obj);
  203. 			    obj = (struct obj *) 0;
  204. 			    unarmed = FALSE;	/* avoid obj==0 confusion */
  205. 			    get_dmg_bonus = FALSE;
  206. 			    hittxt = TRUE;
  207. 			}
  208. 			tmp = 1;
  209. 			break;
  210. #ifdef TOURIST
  211. 		    case EXPENSIVE_CAMERA:
  212. 			You("succeed in destroying %s camera.  Congratulations!",
  213. 			        shk_your(yourbuf, obj));
  214. 			useup(obj);
  215. 			return(TRUE);
  216. 			/*NOTREACHED*/
  217. 			break;
  218. #endif
  219. 		    case CORPSE:		/* fixed by polder@cs.vu.nl */
  220. 			if (touch_petrifies(&mons[obj->corpsenm])) {
  221. 			    static const char withwhat[] = "corpse";
  222. 			    tmp = 1;
  223. 			    hittxt = TRUE;
  224. 			    You("hit %s with %s %s.", mon_nam(mon),
  225. 				obj->dknown ? the(mons[obj->corpsenm].mname) :
  226. 				an(mons[obj->corpsenm].mname),
  227. 				(obj->quan > 1) ? makeplural(withwhat) : withwhat);
  228. 			    if (!munstone(mon, TRUE))
  229. 				minstapetrify(mon, TRUE);
  230. 			    if (resists_ston(mon)) break;
  231. 			    /* note: hp may be <= 0 even if munstoned==TRUE */
  232. 			    return (boolean) (mon->mhp > 0);
  233. #if 0
  234. 			} else if (touch_petrifies(mdat)) {
  235. 			    /* maybe turn the corpse into a statue? */
  236. #endif
  237. 			}
  238. 			tmp = (obj->corpsenm >= LOW_PM ?
  239. 					mons[obj->corpsenm].msize : 0) + 1;
  240. 			break;
  241. 		    case EGG:
  242. 		      {
  243. #define useup_eggs(o)	{ if (thrown) obfree(o,(struct obj *)0); \
  244. 			  else useupall(o); \
  245. 			  o = (struct obj *)0; }	/* now gone */
  246. 			long cnt = obj->quan;
  247.  
  248. 			tmp = 1;		/* nominal physical damage */
  249. 			get_dmg_bonus = FALSE;
  250. 			hittxt = TRUE;		/* message always given */
  251. 			/* egg is always either used up or transformed, so next
  252. 			   hand-to-hand attack should yield a "bashing" mesg */
  253. 			if (obj == uwep) unweapon = TRUE;
  254. 			if (obj->spe && obj->corpsenm >= LOW_PM) {
  255. 			    if (obj->quan < 5)
  256. 				change_luck((schar) -(obj->quan));
  257. 			    else
  258. 				change_luck(-5);
  259. 			}
  260.  
  261. 			if (touch_petrifies(&mons[obj->corpsenm])) {
  262. 			    /*learn_egg_type(obj->corpsenm);*/
  263. 			    pline("Splat! You hit %s with %s %s egg%s!",
  264. 				mon_nam(mon),
  265. 				obj->known ? "the" : cnt > 1L ? "some" : "a",
  266. 				obj->known ? mons[obj->corpsenm].mname : "petrifying",
  267. 				plur(cnt));
  268. 			    obj->known = 1;	/* (not much point...) */
  269. 			    useup_eggs(obj);
  270. 			    if (!munstone(mon, TRUE))
  271. 				minstapetrify(mon, TRUE);
  272. 			    if (resists_ston(mon)) break;
  273. 			    return (boolean) (mon->mhp > 0);
  274. 			} else {	/* ordinary egg(s) */
  275. 			    const char *eggp =
  276. 				     (obj->corpsenm != NON_PM && obj->known) ?
  277. 					      the(mons[obj->corpsenm].mname) :
  278. 					      (cnt > 1L) ? "some" : "an";
  279. 			    You("hit %s with %s egg%s.",
  280. 				mon_nam(mon), eggp, plur(cnt));
  281. 			    if (touch_petrifies(mdat) && !stale_egg(obj)) {
  282. 				pline_The("egg%s %s alive any more...",
  283. 				      plur(cnt),
  284. 				      (cnt == 1L) ? "isn't" : "aren't");
  285. 				if (obj->timed) obj_stop_timers(obj);
  286. 				obj->otyp = ROCK;
  287. 				obj->oclass = GEM_CLASS;
  288. 				obj->oartifact = 0;
  289. 				obj->spe = 0;
  290. 				obj->known = obj->dknown = obj->bknown = 0;
  291. 				obj->owt = weight(obj);
  292. 				if (thrown) place_object(obj, mon->mx, mon->my);
  293. 			    } else {
  294. 				pline("Splat!");
  295. 				useup_eggs(obj);
  296. 				exercise(A_WIS, FALSE);
  297. 			    }
  298. 			}
  299. 			break;
  300. #undef useup_eggs
  301. 		      }
  302. 		    case CLOVE_OF_GARLIC:	/* no effect against demons */
  303. 			if (is_undead(mdat)) {
  304. 			    monflee(mon, d(2, 4), FALSE, TRUE);
  305. 			}
  306. 			tmp = 1;
  307. 			break;
  308. 		    case CREAM_PIE:
  309. 		    case BLINDING_VENOM:
  310. 			mon->msleeping = 0;
  311. 			if (can_blnd(&youmonst, mon, (uchar)
  312. 				    (obj->otyp == BLINDING_VENOM
  313. 				     ? AT_SPIT : AT_WEAP), obj)) {
  314. 			    if (Blind) {
  315. 				pline(obj->otyp == CREAM_PIE ?
  316. 				      "Splat!" : "Splash!");
  317. 			    } else if (obj->otyp == BLINDING_VENOM) {
  318. 				pline_The("venom blinds %s%s!", mon_nam(mon),
  319. 					  mon->mcansee ? "" : " further");
  320. 			    } else {
  321. 				char *whom = mon_nam(mon);
  322. 				char *what = The(xname(obj));
  323. 				if (!thrown && obj->quan > 1)
  324. 				    what = An(singular(obj, xname));
  325. 				/* note: s_suffix returns a modifiable buffer */
  326. 				if (haseyes(mdat)
  327. 				    && mdat != &mons[PM_FLOATING_EYE])
  328. 				    whom = strcat(strcat(s_suffix(whom), " "),
  329. 						  mbodypart(mon, FACE));
  330. 				pline("%s %s over %s!",
  331. 				      what, vtense(what, "splash"), whom);
  332. 			    }
  333. 			    setmangry(mon);
  334. 			    mon->mcansee = 0;
  335. 			    tmp = rn1(25, 21);
  336. 			    if(((int) mon->mblinded + tmp) > 127)
  337. 				mon->mblinded = 127;
  338. 			    else mon->mblinded += tmp;
  339. 			} else {
  340. 			    pline(obj->otyp==CREAM_PIE ? "Splat!" : "Splash!");
  341. 			    setmangry(mon);
  342. 			}
  343. 			if (thrown) obfree(obj, (struct obj *)0);
  344. 			else useup(obj);
  345. 			hittxt = TRUE;
  346. 			get_dmg_bonus = FALSE;
  347. 			tmp = 0;
  348. 			break;
  349. 		    case ACID_VENOM: /* thrown (or spit) */
  350. 			if (resists_acid(mon)) {
  351. 				Your("venom hits %s harmlessly.",
  352. 					mon_nam(mon));
  353. 				tmp = 0;
  354. 			} else {
  355. 				Your("venom burns %s!", mon_nam(mon));
  356. 				tmp = dmgval(obj, mon);
  357. 			}
  358. 			if (thrown) obfree(obj, (struct obj *)0);
  359. 			else useup(obj);
  360. 			hittxt = TRUE;
  361. 			get_dmg_bonus = FALSE;
  362. 			break;
  363. 		    default:
  364. 			/* non-weapons can damage because of their weight */
  365. 			/* (but not too much) */
  366. 			tmp = obj->owt/100;
  367. 			if(tmp < 1) tmp = 1;
  368. 			else tmp = rnd(tmp);
  369. 			if(tmp > 6) tmp = 6;
  370. 			/*
  371. 			 * Things like silver wands can arrive here so
  372. 			 * so we need another silver check.
  373. 			 */
  374. 			if (objects[obj->otyp].oc_material == SILVER
  375. 						&& hates_silver(mdat)) {
  376. 				tmp += rnd(20);
  377. 				silvermsg = TRUE; silverobj = TRUE;
  378. 			}
  379. 		    }
  380. 		}
  381. 	    }
  382. 	}
  383.  
  384. 	/****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG)
  385. 	 *      *OR* if attacking bare-handed!! */
  386.  
  387. 	if (get_dmg_bonus && tmp > 0) {
  388. 		tmp += u.udaminc;
  389. 		/* If you throw using a propellor, you don't get a strength
  390. 		 * bonus but you do get an increase-damage bonus.
  391. 		 */
  392. 		if(!thrown || !obj || !uwep || !ammo_and_launcher(obj, uwep))
  393. 		    tmp += dbon();
  394. 	}
  395.  
  396. 	if (valid_weapon_attack) {
  397. 	    struct obj *wep;
  398.  
  399. 	    /* to be valid a projectile must have had the correct projector */
  400. 	    wep = PROJECTILE(obj) ? uwep : obj;
  401. 	    tmp += weapon_dam_bonus(wep);
  402. 	    /* [this assumes that `!thrown' implies wielded...] */
  403. 	    wtype = thrown ? weapon_type(wep) : uwep_skill_type();
  404. 	    use_skill(wtype, 1);
  405. 	}
  406.  
  407. 	if (ispoisoned) {
  408. 	    int nopoison = (10 - (obj->owt/10));            
  409. 	    if(nopoison < 2) nopoison = 2;
  410. 	    if Role_if(PM_SAMURAI) {
  411. 		You("dishonorably use a poisoned weapon!");
  412. 		adjalign(-sgn(u.ualign.type));
  413. 	    } else if ((u.ualign.type == A_LAWFUL) && (u.ualign.record > -10)) {
  414. 		You_feel("like an evil coward for using a poisoned weapon.");
  415. 		adjalign(-1);
  416. 	    }
  417. 	    if (obj && !rn2(nopoison)) {
  418. 		obj->opoisoned = FALSE;
  419. 		Your("%s %s no longer poisoned.", xname(obj),
  420. 		     otense(obj, "are"));
  421. 	    }
  422. 	    if (resists_poison(mon))
  423. 		needpoismsg = TRUE;
  424. 	    else if (rn2(10))
  425. 		tmp += rnd(6);
  426. 	    else poiskilled = TRUE;
  427. 	}
  428. 	if (tmp < 1) {
  429. 	    /* make sure that negative damage adjustment can't result
  430. 	       in inadvertently boosting the victim's hit points */
  431. 	    tmp = 0;
  432. 	    if (mdat == &mons[PM_SHADE]) {
  433. 		if (!hittxt) {
  434. 		    const char *what = unconventional[0] ? unconventional : "attack";
  435. 		    Your("%s %s harmlessly through %s.",
  436. 		    	what, vtense(what, "pass"),
  437. 			mon_nam(mon));
  438. 		    hittxt = TRUE;
  439. 		}
  440. 	    } else {
  441. 		if (get_dmg_bonus) tmp = 1;
  442. 	    }
  443. 	}
  444.  
  445. #ifdef STEED
  446. 	if (jousting) {
  447. 	    tmp += d(2, (obj == uwep) ? 10 : 2);	/* [was in dmgval()] */
  448. 	    You("joust %s%s",
  449. 			 mon_nam(mon), canseemon(mon) ? exclam(tmp) : ".");
  450. 	    if (jousting < 0) {
  451. 		Your("%s shatters on impact!", xname(obj));
  452. 		/* (must be either primary or secondary weapon to get here) */
  453. 		u.twoweap = FALSE;	/* untwoweapon() is too verbose here */
  454. 		if (obj == uwep) uwepgone();		/* set unweapon */
  455. 		/* minor side-effect: broken lance won't split puddings */
  456. 		useup(obj);
  457. 		obj = 0;
  458. 	    }
  459. 	    /* avoid migrating a dead monster */
  460. 	    if (mon->mhp > tmp) {
  461. 		mhurtle(mon, u.dx, u.dy, 1);
  462. 		mdat = mon->data; /* in case of a polymorph trap */
  463. 		if (DEADMONSTER(mon)) already_killed = TRUE;
  464. 	    }
  465. 	    hittxt = TRUE;
  466. 	} else
  467. #endif
  468.  
  469. 	/* VERY small chance of stunning opponent if unarmed. */
  470. 	if (unarmed && tmp > 1 && !thrown && !obj && !Upolyd) {
  471. 	    if (rnd(100) < P_SKILL(P_BARE_HANDED_COMBAT) &&
  472. 			!bigmonst(mdat) && !thick_skinned(mdat)) {
  473. 		if (canspotmon(mon))
  474. 		    pline("%s %s from your powerful strike!", Monnam(mon),
  475. 			  makeplural(stagger(mon->data, "stagger")));
  476. 		/* avoid migrating a dead monster */
  477. 		if (mon->mhp > tmp) {
  478. 		    mhurtle(mon, u.dx, u.dy, 1);
  479. 		    mdat = mon->data; /* in case of a polymorph trap */
  480. 		    if (DEADMONSTER(mon)) already_killed = TRUE;
  481. 		}
  482. 		hittxt = TRUE;
  483. 	    }
  484. 	}
  485.  
  486. 	if (!already_killed) mon->mhp -= tmp;
  487. 	/* adjustments might have made tmp become less than what
  488. 	   a level draining artifact has already done to max HP */
  489. 	if (mon->mhp > mon->mhpmax) mon->mhp = mon->mhpmax;
  490. 	if (mon->mhp < 1)
  491. 		destroyed = TRUE;
  492. 	if (mon->mtame && (!mon->mflee || mon->mfleetim) && tmp > 0) {
  493. 		abuse_dog(mon);
  494. 		monflee(mon, 10 * rnd(tmp), FALSE, FALSE);
  495. 	}
  496. 	if((mdat == &mons[PM_BLACK_PUDDING] || mdat == &mons[PM_BROWN_PUDDING])
  497. 		   && obj && obj == uwep
  498. 		   && objects[obj->otyp].oc_material == IRON
  499. 		   && mon->mhp > 1 && !thrown && !mon->mcan
  500. 		   /* && !destroyed  -- guaranteed by mhp > 1 */ ) {
  501. 		if (clone_mon(mon, 0, 0)) {
  502. 			pline("%s divides as you hit it!", Monnam(mon));
  503. 			hittxt = TRUE;
  504. 		}
  505. 	}
  506.  
  507. 	if (!hittxt &&			/*( thrown => obj exists )*/
  508. 	  (!destroyed || (thrown && m_shot.n > 1 && m_shot.o == obj->otyp))) {
  509. 		if (thrown) hit(mshot_xname(obj), mon, exclam(tmp));
  510. 		else if (!flags.verbose) You("hit it.");
  511. 		else You("%s %s%s", Role_if(PM_BARBARIAN) ? "smite" : "hit",
  512. 			 mon_nam(mon), canseemon(mon) ? exclam(tmp) : ".");
  513. 	}
  514.  
  515. 	if (silvermsg) {
  516. 		const char *fmt;
  517. 		char *whom = mon_nam(mon);
  518. 		char silverobjbuf[BUFSZ];
  519.  
  520. 		if (canspotmon(mon)) {
  521. 		    if (barehand_silver_rings == 1)
  522. 			fmt = "Your silver ring sears %s!";
  523. 		    else if (barehand_silver_rings == 2)
  524. 			fmt = "Your silver rings sear %s!";
  525. 		    else if (silverobj && saved_oname[0]) {
  526. 		    	Sprintf(silverobjbuf, "Your %s%s %s %%s!",
  527. 		    		strstri(saved_oname, "silver") ?
  528. 					"" : "silver ",
  529. 				saved_oname, vtense(saved_oname, "sear"));
  530. 		    	fmt = silverobjbuf;
  531. 		    } else
  532. 			fmt = "The silver sears %s!";
  533. 		} else {
  534. 		    *whom = highc(*whom);	/* "it" -> "It" */
  535. 		    fmt = "%s is seared!";
  536. 		}
  537. 		/* note: s_suffix returns a modifiable buffer */
  538. 		if (!noncorporeal(mdat))
  539. 		    whom = strcat(s_suffix(whom), " flesh");
  540. 		pline(fmt, whom);
  541. 	}
  542.  
  543. 	if (needpoismsg)
  544. 		pline_The("poison doesn't seem to affect %s.", mon_nam(mon));
  545. 	if (poiskilled) {
  546. 		pline_The("poison was deadly...");
  547. 		if (!already_killed) xkilled(mon, 0);
  548. 		return FALSE;
  549. 	} else if (destroyed) {
  550. 		if (!already_killed)
  551. 		    killed(mon);	/* takes care of most messages */
  552. 	} else if(u.umconf && !thrown) {
  553. 		nohandglow(mon);
  554. 		if (!mon->mconf && !resist(mon, SPBOOK_CLASS, 0, NOTELL)) {
  555. 			mon->mconf = 1;
  556. 			if (!mon->mstun && mon->mcanmove && !mon->msleeping &&
  557. 				canseemon(mon))
  558. 			    pline("%s appears confused.", Monnam(mon));
  559. 		}
  560. 	}
  561.  
  562. 	return((boolean)(destroyed ? FALSE : TRUE));
  563. }

shade_aware

  1. STATIC_OVL boolean
  2. shade_aware(obj)
  3. struct obj *obj;
  4. {
  5. 	if (!obj) return FALSE;
  6. 	/*
  7. 	 * The things in this list either
  8. 	 * 1) affect shades.
  9. 	 *  OR
  10. 	 * 2) are dealt with properly by other routines
  11. 	 *    when it comes to shades.
  12. 	 */
  13. 	if (obj->otyp == BOULDER || obj->otyp == HEAVY_IRON_BALL
  14. 	    || obj->otyp == IRON_CHAIN		/* dmgval handles those first three */
  15. 	    || obj->otyp == MIRROR		/* silver in the reflective surface */
  16. 	    || obj->otyp == CLOVE_OF_GARLIC	/* causes shades to flee */
  17. 	    || objects[obj->otyp].oc_material == SILVER)
  18. 		return TRUE;
  19. 	return FALSE;
  20. }

m_slips_free

  1. /* check whether slippery clothing protects from hug or wrap attack */
  2. /* [currently assumes that you are the attacker] */
  3. STATIC_OVL boolean
  4. m_slips_free(mdef, mattk)
  5. struct monst *mdef;
  6. struct attack *mattk;
  7. {
  8. 	struct obj *obj;
  9.  
  10. 	if (mattk->adtyp == AD_DRIN) {
  11. 	    /* intelligence drain attacks the head */
  12. 	    obj = which_armor(mdef, W_ARMH);
  13. 	} else {
  14. 	    /* grabbing attacks the body */
  15. 	    obj = which_armor(mdef, W_ARMC);		/* cloak */
  16. 	    if (!obj) obj = which_armor(mdef, W_ARM);	/* suit */
  17. #ifdef TOURIST
  18. 	    if (!obj) obj = which_armor(mdef, W_ARMU);	/* shirt */
  19. #endif
  20. 	}
  21.  
  22. 	/* if your cloak/armor is greased, monster slips off; this
  23. 	   protection might fail (33% chance) when the armor is cursed */
  24. 	if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK) &&
  25. 		(!obj->cursed || rn2(3))) {
  26. 	    You("%s %s %s %s!",
  27. 		mattk->adtyp == AD_WRAP ?
  28. 			"slip off of" : "grab, but cannot hold onto",
  29. 		s_suffix(mon_nam(mdef)),
  30. 		obj->greased ? "greased" : "slippery",
  31. 		/* avoid "slippery slippery cloak"
  32. 		   for undiscovered oilskin cloak */
  33. 		(obj->greased || objects[obj->otyp].oc_name_known) ?
  34. 			xname(obj) : cloak_simple_name(obj));
  35.  
  36. 	    if (obj->greased && !rn2(2)) {
  37. 		pline_The("grease wears off.");
  38. 		obj->greased = 0;
  39. 	    }
  40. 	    return TRUE;
  41. 	}
  42. 	return FALSE;
  43. }

joust

  1. /* used when hitting a monster with a lance while mounted */
  2. STATIC_OVL int	/* 1: joust hit; 0: ordinary hit; -1: joust but break lance */
  3. joust(mon, obj)
  4. struct monst *mon;	/* target */
  5. struct obj *obj;	/* weapon */
  6. {
  7. int skill_rating, joust_dieroll;
  8.  
  9. if (Fumbling || Stunned) return 0;
  10. /* sanity check; lance must be wielded in order to joust */
  11. if (obj != uwep && (obj != uswapwep || !u.twoweap)) return 0;
  12.  
  13. /* if using two weapons, use worse of lance and two-weapon skills */
  14. skill_rating = P_SKILL(weapon_type(obj));	/* lance skill */
  15. if (u.twoweap && P_SKILL(P_TWO_WEAPON_COMBAT) < skill_rating)
  16. 	skill_rating = P_SKILL(P_TWO_WEAPON_COMBAT);
  17. if (skill_rating == P_ISRESTRICTED) skill_rating = P_UNSKILLED; /* 0=>1 */
  18.  
  19. /* odds to joust are expert:80%, skilled:60%, basic:40%, unskilled:20% */
  20. if ((joust_dieroll = rn2(5)) < skill_rating) {
  21. 	if (joust_dieroll == 0 && rnl(50) == (50-1) &&
  22. 		!unsolid(mon->data) && !obj_resists(obj, 0, 100))
  23. 	    return -1;	/* hit that breaks lance */
  24. 	return 1;	/* successful joust */
  25. }
  26. return 0;	/* no joust bonus; revert to ordinary attack */
  27. }

demonpet

  1. /*
  2. * Send in a demon pet for the hero.  Exercise wisdom.
  3. *
  4. * This function used to be inline to damageum(), but the Metrowerks compiler
  5. * (DR4 and DR4.5) screws up with an internal error 5 "Expression Too Complex."
  6. * Pulling it out makes it work.
  7. */
  8. STATIC_OVL void
  9. demonpet()
  10. {
  11. 	int i;
  12. 	struct permonst *pm;
  13. 	struct monst *dtmp;
  14.  
  15. 	pline("Some hell-p has arrived!");
  16. 	i = !rn2(6) ? ndemon(u.ualign.type) : NON_PM;
  17. 	pm = i != NON_PM ? &mons[i] : youmonst.data;
  18. 	if ((dtmp = makemon(pm, u.ux, u.uy, NO_MM_FLAGS)) != 0)
  19. 	    (void)tamedog(dtmp, (struct obj *)0);
  20. 	exercise(A_WIS, TRUE);
  21. }

steal_it

  1. /*
  2. * Player uses theft attack against monster.
  3. *
  4. * If the target is wearing body armor, take all of its possesions;
  5. * otherwise, take one object.  [Is this really the behavior we want?]
  6. *
  7. * This routine implicitly assumes that there is no way to be able to
  8. * resist petfication (ie, be polymorphed into a xorn or golem) at the
  9. * same time as being able to steal (poly'd into nymph or succubus).
  10. * If that ever changes, the check for touching a cockatrice corpse
  11. * will need to be smarter about whether to break out of the theft loop.
  12. */
  13. STATIC_OVL void
  14. steal_it(mdef, mattk)
  15. struct monst *mdef;
  16. struct attack *mattk;
  17. {
  18. 	struct obj *otmp, *stealoid, **minvent_ptr;
  19. 	long unwornmask;
  20.  
  21. 	if (!mdef->minvent) return;		/* nothing to take */
  22.  
  23. 	/* look for worn body armor */
  24. 	stealoid = (struct obj *)0;
  25. 	if (could_seduce(&youmonst, mdef, mattk)) {
  26. 	    /* find armor, and move it to end of inventory in the process */
  27. 	    minvent_ptr = &mdef->minvent;
  28. 	    while ((otmp = *minvent_ptr) != 0)
  29. 		if (otmp->owornmask & W_ARM) {
  30. 		    if (stealoid) panic("steal_it: multiple worn suits");
  31. 		    *minvent_ptr = otmp->nobj;	/* take armor out of minvent */
  32. 		    stealoid = otmp;
  33. 		    stealoid->nobj = (struct obj *)0;
  34. 		} else {
  35. 		    minvent_ptr = &otmp->nobj;
  36. 		}
  37. 	    *minvent_ptr = stealoid;	/* put armor back into minvent */
  38. 	}
  39.  
  40. 	if (stealoid) {		/* we will be taking everything */
  41. 	    if (gender(mdef) == (int) u.mfemale &&
  42. 			youmonst.data->mlet == S_NYMPH)
  43. 		You("charm %s.  She gladly hands over her possessions.",
  44. 		    mon_nam(mdef));
  45. 	    else
  46. 		You("seduce %s and %s starts to take off %s clothes.",
  47. 		    mon_nam(mdef), mhe(mdef), mhis(mdef));
  48. 	}
  49.  
  50. 	while ((otmp = mdef->minvent) != 0) {
  51. 	    if (!Upolyd) break;		/* no longer have ability to steal */
  52. 	    /* take the object away from the monster */
  53. 	    obj_extract_self(otmp);
  54. 	    if ((unwornmask = otmp->owornmask) != 0L) {
  55. 		mdef->misc_worn_check &= ~unwornmask;
  56. 		if (otmp->owornmask & W_WEP) {
  57. 		    setmnotwielded(mdef,otmp);
  58. 		    MON_NOWEP(mdef);
  59. 		}
  60. 		otmp->owornmask = 0L;
  61. 		update_mon_intrinsics(mdef, otmp, FALSE, FALSE);
  62.  
  63. 		if (otmp == stealoid)	/* special message for final item */
  64. 		    pline("%s finishes taking off %s suit.",
  65. 			  Monnam(mdef), mhis(mdef));
  66. 	    }
  67. 	    /* give the object to the character */
  68. 	    otmp = hold_another_object(otmp, "You snatched but dropped %s.",
  69. 				       doname(otmp), "You steal: ");
  70. 	    if (otmp->where != OBJ_INVENT) continue;
  71. 	    if (otmp->otyp == CORPSE &&
  72. 		    touch_petrifies(&mons[otmp->corpsenm]) && !uarmg) {
  73. 		char kbuf[BUFSZ];
  74.  
  75. 		Sprintf(kbuf, "stolen %s corpse", mons[otmp->corpsenm].mname);
  76. 		instapetrify(kbuf);
  77. 		break;		/* stop the theft even if hero survives */
  78. 	    }
  79. 	    /* more take-away handling, after theft message */
  80. 	    if (unwornmask & W_WEP) {		/* stole wielded weapon */
  81. 		possibly_unwield(mdef, FALSE);
  82. 	    } else if (unwornmask & W_ARMG) {	/* stole worn gloves */
  83. 		mselftouch(mdef, (const char *)0, TRUE);
  84. 		if (mdef->mhp <= 0)	/* it's now a statue */
  85. 		    return;		/* can't continue stealing */
  86. 	    }
  87.  
  88. 	    if (!stealoid) break;	/* only taking one item */
  89. 	}
  90. }

damageum

  1. int
  2. damageum(mdef, mattk)
  3. register struct monst *mdef;
  4. register struct attack *mattk;
  5. {
  6. 	register struct permonst *pd = mdef->data;
  7. 	register int	tmp = d((int)mattk->damn, (int)mattk->damd);
  8. 	int armpro;
  9. 	boolean negated;
  10.  
  11. 	armpro = magic_negation(mdef);
  12. 	/* since hero can't be cancelled, only defender's armor applies */
  13. 	negated = !((rn2(3) >= armpro) || !rn2(50));
  14.  
  15. 	if (is_demon(youmonst.data) && !rn2(13) && !uwep
  16. 		&& u.umonnum != PM_SUCCUBUS && u.umonnum != PM_INCUBUS
  17. 		&& u.umonnum != PM_BALROG) {
  18. 	    demonpet();
  19. 	    return(0);
  20. 	}
  21. 	switch(mattk->adtyp) {
  22. 	    case AD_STUN:
  23. 		if(!Blind)
  24. 		    pline("%s %s for a moment.", Monnam(mdef),
  25. 			  makeplural(stagger(mdef->data, "stagger")));
  26. 		mdef->mstun = 1;
  27. 		goto physical;
  28. 	    case AD_LEGS:
  29. 	     /* if (u.ucancelled) { */
  30. 	     /*    tmp = 0;	    */
  31. 	     /*    break;	    */
  32. 	     /* }		    */
  33. 		goto physical;
  34. 	    case AD_WERE:	    /* no special effect on monsters */
  35. 	    case AD_HEAL:	    /* likewise */
  36. 	    case AD_PHYS:
  37. physical:
  38. 		if(mattk->aatyp == AT_WEAP) {
  39. 		    if(uwep) tmp = 0;
  40. 		} else if(mattk->aatyp == AT_KICK) {
  41. 		    if(thick_skinned(mdef->data)) tmp = 0;
  42. 		    if(mdef->data == &mons[PM_SHADE]) {
  43. 			if (!(uarmf && uarmf->blessed)) {
  44. 			    impossible("bad shade attack function flow?");
  45. 			    tmp = 0;
  46. 			} else
  47. 			    tmp = rnd(4); /* bless damage */
  48. 		    }
  49. 		}
  50. 		break;
  51. 	    case AD_FIRE:
  52. 		if (negated) {
  53. 		    tmp = 0;
  54. 		    break;
  55. 		}
  56. 		if (!Blind)
  57. 		    pline("%s is %s!", Monnam(mdef),
  58. 			  on_fire(mdef->data, mattk));
  59. 		if (pd == &mons[PM_STRAW_GOLEM] ||
  60. 		    pd == &mons[PM_PAPER_GOLEM]) {
  61. 		    if (!Blind)
  62. 			pline("%s burns completely!", Monnam(mdef));
  63. 		    xkilled(mdef,2);
  64. 		    tmp = 0;
  65. 		    break;
  66. 		    /* Don't return yet; keep hp<1 and tmp=0 for pet msg */
  67. 		}
  68. 		tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
  69. 		tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
  70. 		if (resists_fire(mdef)) {
  71. 		    if (!Blind)
  72. 			pline_The("fire doesn't heat %s!", mon_nam(mdef));
  73. 		    golemeffects(mdef, AD_FIRE, tmp);
  74. 		    shieldeff(mdef->mx, mdef->my);
  75. 		    tmp = 0;
  76. 		}
  77. 		/* only potions damage resistant players in destroy_item */
  78. 		tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
  79. 		break;
  80. 	    case AD_COLD:
  81. 		if (negated) {
  82. 		    tmp = 0;
  83. 		    break;
  84. 		}
  85. 		if (!Blind) pline("%s is covered in frost!", Monnam(mdef));
  86. 		if (resists_cold(mdef)) {
  87. 		    shieldeff(mdef->mx, mdef->my);
  88. 		    if (!Blind)
  89. 			pline_The("frost doesn't chill %s!", mon_nam(mdef));
  90. 		    golemeffects(mdef, AD_COLD, tmp);
  91. 		    tmp = 0;
  92. 		}
  93. 		tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD);
  94. 		break;
  95. 	    case AD_ELEC:
  96. 		if (negated) {
  97. 		    tmp = 0;
  98. 		    break;
  99. 		}
  100. 		if (!Blind) pline("%s is zapped!", Monnam(mdef));
  101. 		tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
  102. 		if (resists_elec(mdef)) {
  103. 		    if (!Blind)
  104. 			pline_The("zap doesn't shock %s!", mon_nam(mdef));
  105. 		    golemeffects(mdef, AD_ELEC, tmp);
  106. 		    shieldeff(mdef->mx, mdef->my);
  107. 		    tmp = 0;
  108. 		}
  109. 		/* only rings damage resistant players in destroy_item */
  110. 		tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC);
  111. 		break;
  112. 	    case AD_ACID:
  113. 		if (resists_acid(mdef)) tmp = 0;
  114. 		break;
  115. 	    case AD_STON:
  116. 		if (!munstone(mdef, TRUE))
  117. 		    minstapetrify(mdef, TRUE);
  118. 		tmp = 0;
  119. 		break;
  120. #ifdef SEDUCE
  121. 	    case AD_SSEX:
  122. #endif
  123. 	    case AD_SEDU:
  124. 	    case AD_SITM:
  125. 		steal_it(mdef, mattk);
  126. 		tmp = 0;
  127. 		break;
  128. 	    case AD_SGLD:
  129. #ifndef GOLDOBJ
  130. 		if (mdef->mgold) {
  131. 		    u.ugold += mdef->mgold;
  132. 		    mdef->mgold = 0;
  133. 		    Your("purse feels heavier.");
  134. 		}
  135. #else
  136. /* This you as a leprechaun, so steal
  137. real gold only, no lesser coins */
  138. 	        {
  139. 		    struct obj *mongold = findgold(mdef->minvent);
  140. 	            if (mongold) {
  141. 		        obj_extract_self(mongold);  
  142. 		        if (merge_choice(invent, mongold) || inv_cnt() < 52) {
  143. 			    addinv(mongold);
  144. 			    Your("purse feels heavier.");
  145. 			} else {
  146. You("grab %s's gold, but find no room in your knapsack.", mon_nam(mdef));
  147. 			    dropy(mongold);
  148. 		        }
  149. 		    }
  150. 	        }
  151. #endif
  152. 		exercise(A_DEX, TRUE);
  153. 		tmp = 0;
  154. 		break;
  155. 	    case AD_TLPT:
  156. 		if (tmp <= 0) tmp = 1;
  157. 		if (!negated && tmp < mdef->mhp) {
  158. 		    char nambuf[BUFSZ];
  159. 		    boolean u_saw_mon = canseemon(mdef) ||
  160. 					(u.uswallow && u.ustuck == mdef);
  161. 		    /* record the name before losing sight of monster */
  162. 		    Strcpy(nambuf, Monnam(mdef));
  163. 		    if (u_teleport_mon(mdef, FALSE) &&
  164. 			    u_saw_mon && !canseemon(mdef))
  165. 			pline("%s suddenly disappears!", nambuf);
  166. 		}
  167. 		break;
  168. 	    case AD_BLND:
  169. 		if (can_blnd(&youmonst, mdef, mattk->aatyp, (struct obj*)0)) {
  170. 		    if(!Blind && mdef->mcansee)
  171. 			pline("%s is blinded.", Monnam(mdef));
  172. 		    mdef->mcansee = 0;
  173. 		    tmp += mdef->mblinded;
  174. 		    if (tmp > 127) tmp = 127;
  175. 		    mdef->mblinded = tmp;
  176. 		}
  177. 		tmp = 0;
  178. 		break;
  179. 	    case AD_CURS:
  180. 		if (night() && !rn2(10) && !mdef->mcan) {
  181. 		    if (mdef->data == &mons[PM_CLAY_GOLEM]) {
  182. 			if (!Blind)
  183. 			    pline("Some writing vanishes from %s head!",
  184. 				s_suffix(mon_nam(mdef)));
  185. 			xkilled(mdef, 0);
  186. 			/* Don't return yet; keep hp<1 and tmp=0 for pet msg */
  187. 		    } else {
  188. 			mdef->mcan = 1;
  189. 			You("chuckle.");
  190. 		    }
  191. 		}
  192. 		tmp = 0;
  193. 		break;
  194. 	    case AD_DRLI:
  195. 		if (!negated && !rn2(3) && !resists_drli(mdef)) {
  196. 			int xtmp = d(2,6);
  197. 			pline("%s suddenly seems weaker!", Monnam(mdef));
  198. 			mdef->mhpmax -= xtmp;
  199. 			if ((mdef->mhp -= xtmp) <= 0 || !mdef->m_lev) {
  200. 				pline("%s dies!", Monnam(mdef));
  201. 				xkilled(mdef,0);
  202. 			} else
  203. 				mdef->m_lev--;
  204. 			tmp = 0;
  205. 		}
  206. 		break;
  207. 	    case AD_RUST:
  208. 		if (pd == &mons[PM_IRON_GOLEM]) {
  209. 			pline("%s falls to pieces!", Monnam(mdef));
  210. 			xkilled(mdef,0);
  211. 		}
  212. 		hurtmarmor(mdef, AD_RUST);
  213. 		tmp = 0;
  214. 		break;
  215. 	    case AD_CORR:
  216. 		hurtmarmor(mdef, AD_CORR);
  217. 		tmp = 0;
  218. 		break;
  219. 	    case AD_DCAY:
  220. 		if (pd == &mons[PM_WOOD_GOLEM] ||
  221. 		    pd == &mons[PM_LEATHER_GOLEM]) {
  222. 			pline("%s falls to pieces!", Monnam(mdef));
  223. 			xkilled(mdef,0);
  224. 		}
  225. 		hurtmarmor(mdef, AD_DCAY);
  226. 		tmp = 0;
  227. 		break;
  228. 	    case AD_DRST:
  229. 	    case AD_DRDX:
  230. 	    case AD_DRCO:
  231. 		if (!negated && !rn2(8)) {
  232. 		    Your("%s was poisoned!", mpoisons_subj(&youmonst, mattk));
  233. 		    if (resists_poison(mdef))
  234. 			pline_The("poison doesn't seem to affect %s.",
  235. 				mon_nam(mdef));
  236. 		    else {
  237. 			if (!rn2(10)) {
  238. 			    Your("poison was deadly...");
  239. 			    tmp = mdef->mhp;
  240. 			} else tmp += rn1(10,6);
  241. 		    }
  242. 		}
  243. 		break;
  244. 	    case AD_DRIN:
  245. 		if (notonhead || !has_head(mdef->data)) {
  246. 		    pline("%s doesn't seem harmed.", Monnam(mdef));
  247. 		    tmp = 0;
  248. 		    if (!Unchanging && mdef->data == &mons[PM_GREEN_SLIME]) {
  249. 			if (!Slimed) {
  250. 			    You("suck in some slime and don't feel very well.");
  251. 			    Slimed = 10L;
  252. 			}
  253. 		    }
  254. 		    break;
  255. 		}
  256. 		if (m_slips_free(mdef, mattk)) break;
  257.  
  258. 		if ((mdef->misc_worn_check & W_ARMH) && rn2(8)) {
  259. 		    pline("%s helmet blocks your attack to %s head.",
  260. 			  s_suffix(Monnam(mdef)), mhis(mdef));
  261. 		    break;
  262. 		}
  263.  
  264. 		You("eat %s brain!", s_suffix(mon_nam(mdef)));
  265. 		u.uconduct.food++;
  266. 		if (touch_petrifies(mdef->data) && !Stone_resistance && !Stoned) {
  267. 		    Stoned = 5;
  268. 		    killer_format = KILLED_BY_AN;
  269. 		    delayed_killer = mdef->data->mname;
  270. 		}
  271. 		if (!vegan(mdef->data))
  272. 		    u.uconduct.unvegan++;
  273. 		if (!vegetarian(mdef->data))
  274. 		    violated_vegetarian();
  275. 		if (mindless(mdef->data)) {
  276. 		    pline("%s doesn't notice.", Monnam(mdef));
  277. 		    break;
  278. 		}
  279. 		tmp += rnd(10);
  280. 		morehungry(-rnd(30)); /* cannot choke */
  281. 		if (ABASE(A_INT) < AMAX(A_INT)) {
  282. 			ABASE(A_INT) += rnd(4);
  283. 			if (ABASE(A_INT) > AMAX(A_INT))
  284. 				ABASE(A_INT) = AMAX(A_INT);
  285. 			flags.botl = 1;
  286. 		}
  287. 		exercise(A_WIS, TRUE);
  288. 		break;
  289. 	    case AD_STCK:
  290. 		if (!negated && !sticks(mdef->data))
  291. 		    u.ustuck = mdef; /* it's now stuck to you */
  292. 		break;
  293. 	    case AD_WRAP:
  294. 		if (!sticks(mdef->data)) {
  295. 		    if (!u.ustuck && !rn2(10)) {
  296. 			if (m_slips_free(mdef, mattk)) {
  297. 			    tmp = 0;
  298. 			} else {
  299. 			    You("swing yourself around %s!",
  300. 				  mon_nam(mdef));
  301. 			    u.ustuck = mdef;
  302. 			}
  303. 		    } else if(u.ustuck == mdef) {
  304. 			/* Monsters don't wear amulets of magical breathing */
  305. 			if (is_pool(u.ux,u.uy) && !is_swimmer(mdef->data) &&
  306. 			    !amphibious(mdef->data)) {
  307. 			    You("drown %s...", mon_nam(mdef));
  308. 			    tmp = mdef->mhp;
  309. 			} else if(mattk->aatyp == AT_HUGS)
  310. 			    pline("%s is being crushed.", Monnam(mdef));
  311. 		    } else {
  312. 			tmp = 0;
  313. 			if (flags.verbose)
  314. 			    You("brush against %s %s.",
  315. 				s_suffix(mon_nam(mdef)),
  316. 				mbodypart(mdef, LEG));
  317. 		    }
  318. 		} else tmp = 0;
  319. 		break;
  320. 	    case AD_PLYS:
  321. 		if (!negated && mdef->mcanmove && !rn2(3) && tmp < mdef->mhp) {
  322. 		    if (!Blind) pline("%s is frozen by you!", Monnam(mdef));
  323. 		    mdef->mcanmove = 0;
  324. 		    mdef->mfrozen = rnd(10);
  325. 		}
  326. 		break;
  327. 	    case AD_SLEE:
  328. 		if (!negated && !mdef->msleeping &&
  329. 			    sleep_monst(mdef, rnd(10), -1)) {
  330. 		    if (!Blind)
  331. 			pline("%s is put to sleep by you!", Monnam(mdef));
  332. 		    slept_monst(mdef);
  333. 		}
  334. 		break;
  335. 	    case AD_SLIM:
  336. 		if (negated) break;	/* physical damage only */
  337. 		if (!rn2(4) && !flaming(mdef->data) &&
  338. 				mdef->data != &mons[PM_GREEN_SLIME]) {
  339. 		    You("turn %s into slime.", mon_nam(mdef));
  340. 		    (void) newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, FALSE);
  341. 		    tmp = 0;
  342. 		}
  343. 		break;
  344. 	    case AD_ENCH:	/* KMH -- remove enchantment (disenchanter) */
  345. 		/* there's no msomearmor() function, so just do damage */
  346. 	     /* if (negated) break; */
  347. 		break;
  348. 	    case AD_SLOW:
  349. 		if (!negated && mdef->mspeed != MSLOW) {
  350. 		    unsigned int oldspeed = mdef->mspeed;
  351.  
  352. 		    mon_adjust_speed(mdef, -1, (struct obj *)0);
  353. 		    if (mdef->mspeed != oldspeed && canseemon(mdef))
  354. 			pline("%s slows down.", Monnam(mdef));
  355. 		}
  356. 		break;
  357. 	    case AD_CONF:
  358. 		if (!mdef->mconf) {
  359. 		    if (canseemon(mdef))
  360. 			pline("%s looks confused.", Monnam(mdef));
  361. 		    mdef->mconf = 1;
  362. 		}
  363. 		break;
  364. 	    default:	tmp = 0;
  365. 		break;
  366. 	}
  367.  
  368. 	mdef->mstrategy &= ~STRAT_WAITFORU; /* in case player is very fast */
  369. 	if((mdef->mhp -= tmp) < 1) {
  370. 	    if (mdef->mtame && !cansee(mdef->mx,mdef->my)) {
  371. 		You_feel("embarrassed for a moment.");
  372. 		if (tmp) xkilled(mdef, 0); /* !tmp but hp<1: already killed */
  373. 	    } else if (!flags.verbose) {
  374. 		You("destroy it!");
  375. 		if (tmp) xkilled(mdef, 0);
  376. 	    } else
  377. 		if (tmp) killed(mdef);
  378. 	    return(2);
  379. 	}
  380. 	return(1);
  381. }

explum

  1. STATIC_OVL int
  2. explum(mdef, mattk)
  3. register struct monst *mdef;
  4. register struct attack *mattk;
  5. {
  6. 	register int tmp = d((int)mattk->damn, (int)mattk->damd);
  7.  
  8. 	You("explode!");
  9. 	switch(mattk->adtyp) {
  10. 	    boolean resistance; /* only for cold/fire/elec */
  11.  
  12. 	    case AD_BLND:
  13. 		if (!resists_blnd(mdef)) {
  14. 		    pline("%s is blinded by your flash of light!", Monnam(mdef));
  15. 		    mdef->mblinded = min((int)mdef->mblinded + tmp, 127);
  16. 		    mdef->mcansee = 0;
  17. 		}
  18. 		break;
  19. 	    case AD_HALU:
  20. 		if (haseyes(mdef->data) && mdef->mcansee) {
  21. 		    pline("%s is affected by your flash of light!",
  22. 			  Monnam(mdef));
  23. 		    mdef->mconf = 1;
  24. 		}
  25. 		break;
  26. 	    case AD_COLD:
  27. 		resistance = resists_cold(mdef);
  28. 		goto common;
  29. 	    case AD_FIRE:
  30. 		resistance = resists_fire(mdef);
  31. 		goto common;
  32. 	    case AD_ELEC:
  33. 		resistance = resists_elec(mdef);
  34. common:
  35. 		if (!resistance) {
  36. 		    pline("%s gets blasted!", Monnam(mdef));
  37. 		    mdef->mhp -= tmp;
  38. 		    if (mdef->mhp <= 0) {
  39. 			 killed(mdef);
  40. 			 return(2);
  41. 		    }
  42. 		} else {
  43. 		    shieldeff(mdef->mx, mdef->my);
  44. 		    if (is_golem(mdef->data))
  45. 			golemeffects(mdef, (int)mattk->adtyp, tmp);
  46. 		    else
  47. 			pline_The("blast doesn't seem to affect %s.",
  48. 				mon_nam(mdef));
  49. 		}
  50. 		break;
  51. 	    default:
  52. 		break;
  53. 	}
  54. 	return(1);
  55. }

start_engulf

  1. STATIC_OVL void
  2. start_engulf(mdef)
  3. struct monst *mdef;
  4. {
  5. 	if (!Invisible) {
  6. 		map_location(u.ux, u.uy, TRUE);
  7. 		tmp_at(DISP_ALWAYS, mon_to_glyph(&youmonst));
  8. 		tmp_at(mdef->mx, mdef->my);
  9. 	}
  10. 	You("engulf %s!", mon_nam(mdef));
  11. 	delay_output();
  12. 	delay_output();
  13. }

end_engulf

  1. STATIC_OVL void
  2. end_engulf()
  3. {
  4. 	if (!Invisible) {
  5. 		tmp_at(DISP_END, 0);
  6. 		newsym(u.ux, u.uy);
  7. 	}
  8. }

gulpum

  1. STATIC_OVL int
  2. gulpum(mdef,mattk)
  3. register struct monst *mdef;
  4. register struct attack *mattk;
  5. {
  6. 	register int tmp;
  7. 	register int dam = d((int)mattk->damn, (int)mattk->damd);
  8. 	struct obj *otmp;
  9. 	/* Not totally the same as for real monsters.  Specifically, these
  10. 	 * don't take multiple moves.  (It's just too hard, for too little
  11. 	 * result, to program monsters which attack from inside you, which
  12. 	 * would be necessary if done accurately.)  Instead, we arbitrarily
  13. 	 * kill the monster immediately for AD_DGST and we regurgitate them
  14. 	 * after exactly 1 round of attack otherwise.  -KAA
  15. 	 */
  16.  
  17. 	if(mdef->data->msize >= MZ_HUGE) return 0;
  18.  
  19. 	if(u.uhunger < 1500 && !u.uswallow) {
  20. 	    for (otmp = mdef->minvent; otmp; otmp = otmp->nobj)
  21. 		(void) snuff_lit(otmp);
  22.  
  23. 	    if(!touch_petrifies(mdef->data) || Stone_resistance) {
  24. #ifdef LINT	/* static char msgbuf[BUFSZ]; */
  25. 		char msgbuf[BUFSZ];
  26. #else
  27. 		static char msgbuf[BUFSZ];
  28. #endif
  29. 		start_engulf(mdef);
  30. 		switch(mattk->adtyp) {
  31. 		    case AD_DGST:
  32. 			/* eating a Rider or its corpse is fatal */
  33. 			if (is_rider(mdef->data)) {
  34. 			 pline("Unfortunately, digesting any of it is fatal.");
  35. 			    end_engulf();
  36. 			    Sprintf(msgbuf, "unwisely tried to eat %s",
  37. 				    mdef->data->mname);
  38. 			    killer = msgbuf;
  39. 			    killer_format = NO_KILLER_PREFIX;
  40. 			    done(DIED);
  41. 			    return 0;		/* lifesaved */
  42. 			}
  43.  
  44. 			if (Slow_digestion) {
  45. 			    dam = 0;
  46. 			    break;
  47. 			}
  48.  
  49. 			/* KMH, conduct */
  50. 			u.uconduct.food++;
  51. 			if (!vegan(mdef->data))
  52. 			     u.uconduct.unvegan++;
  53. 			if (!vegetarian(mdef->data))
  54. 			     violated_vegetarian();
  55.  
  56. 			/* Use up amulet of life saving */
  57. 			if (!!(otmp = mlifesaver(mdef))) m_useup(mdef, otmp);
  58.  
  59. 			newuhs(FALSE);
  60. 			xkilled(mdef,2);
  61. 			if (mdef->mhp > 0) { /* monster lifesaved */
  62. 			    You("hurriedly regurgitate the sizzling in your %s.",
  63. 				body_part(STOMACH));
  64. 			} else {
  65. 			    tmp = 1 + (mdef->data->cwt >> 8);
  66. 			    if (corpse_chance(mdef, &youmonst, TRUE) &&
  67. 				!(mvitals[monsndx(mdef->data)].mvflags &
  68. 				  G_NOCORPSE)) {
  69. 				/* nutrition only if there can be a corpse */
  70. 				u.uhunger += (mdef->data->cnutrit+1) / 2;
  71. 			    } else tmp = 0;
  72. 			    Sprintf(msgbuf, "You totally digest %s.",
  73. 					    mon_nam(mdef));
  74. 			    if (tmp != 0) {
  75. 				/* setting afternmv = end_engulf is tempting,
  76. 				 * but will cause problems if the player is
  77. 				 * attacked (which uses his real location) or
  78. 				 * if his See_invisible wears off
  79. 				 */
  80. 				You("digest %s.", mon_nam(mdef));
  81. 				if (Slow_digestion) tmp *= 2;
  82. 				nomul(-tmp);
  83. 				nomovemsg = msgbuf;
  84. 			    } else pline("%s", msgbuf);
  85. 			    if (mdef->data == &mons[PM_GREEN_SLIME]) {
  86. 				Sprintf(msgbuf, "%s isn't sitting well with you.",
  87. 					The(mdef->data->mname));
  88. 				if (!Unchanging) {
  89. 					Slimed = 5L;
  90. 					flags.botl = 1;
  91. 				}
  92. 			    } else
  93. 			    exercise(A_CON, TRUE);
  94. 			}
  95. 			end_engulf();
  96. 			return(2);
  97. 		    case AD_PHYS:
  98. 			if (youmonst.data == &mons[PM_FOG_CLOUD]) {
  99. 			    pline("%s is laden with your moisture.",
  100. 				  Monnam(mdef));
  101. 			    if (amphibious(mdef->data) &&
  102. 				!flaming(mdef->data)) {
  103. 				dam = 0;
  104. 				pline("%s seems unharmed.", Monnam(mdef));
  105. 			    }
  106. 			} else
  107. 			    pline("%s is pummeled with your debris!",
  108. 				  Monnam(mdef));
  109. 			break;
  110. 		    case AD_ACID:
  111. 			pline("%s is covered with your goo!", Monnam(mdef));
  112. 			if (resists_acid(mdef)) {
  113. 			    pline("It seems harmless to %s.", mon_nam(mdef));
  114. 			    dam = 0;
  115. 			}
  116. 			break;
  117. 		    case AD_BLND:
  118. 			if (can_blnd(&youmonst, mdef, mattk->aatyp, (struct obj *)0)) {
  119. 			    if (mdef->mcansee)
  120. 				pline("%s can't see in there!", Monnam(mdef));
  121. 			    mdef->mcansee = 0;
  122. 			    dam += mdef->mblinded;
  123. 			    if (dam > 127) dam = 127;
  124. 			    mdef->mblinded = dam;
  125. 			}
  126. 			dam = 0;
  127. 			break;
  128. 		    case AD_ELEC:
  129. 			if (rn2(2)) {
  130. 			    pline_The("air around %s crackles with electricity.", mon_nam(mdef));
  131. 			    if (resists_elec(mdef)) {
  132. 				pline("%s seems unhurt.", Monnam(mdef));
  133. 				dam = 0;
  134. 			    }
  135. 			    golemeffects(mdef,(int)mattk->adtyp,dam);
  136. 			} else dam = 0;
  137. 			break;
  138. 		    case AD_COLD:
  139. 			if (rn2(2)) {
  140. 			    if (resists_cold(mdef)) {
  141. 				pline("%s seems mildly chilly.", Monnam(mdef));
  142. 				dam = 0;
  143. 			    } else
  144. 				pline("%s is freezing to death!",Monnam(mdef));
  145. 			    golemeffects(mdef,(int)mattk->adtyp,dam);
  146. 			} else dam = 0;
  147. 			break;
  148. 		    case AD_FIRE:
  149. 			if (rn2(2)) {
  150. 			    if (resists_fire(mdef)) {
  151. 				pline("%s seems mildly hot.", Monnam(mdef));
  152. 				dam = 0;
  153. 			    } else
  154. 				pline("%s is burning to a crisp!",Monnam(mdef));
  155. 			    golemeffects(mdef,(int)mattk->adtyp,dam);
  156. 			} else dam = 0;
  157. 			break;
  158. 		}
  159. 		end_engulf();
  160. 		if ((mdef->mhp -= dam) <= 0) {
  161. 		    killed(mdef);
  162. 		    if (mdef->mhp <= 0)	/* not lifesaved */
  163. 			return(2);
  164. 		}
  165. 		You("%s %s!", is_animal(youmonst.data) ? "regurgitate"
  166. 			: "expel", mon_nam(mdef));
  167. 		if (Slow_digestion || is_animal(youmonst.data)) {
  168. 		    pline("Obviously, you didn't like %s taste.",
  169. 			  s_suffix(mon_nam(mdef)));
  170. 		}
  171. 	    } else {
  172. 		char kbuf[BUFSZ];
  173.  
  174. 		You("bite into %s.", mon_nam(mdef));
  175. 		Sprintf(kbuf, "swallowing %s whole", an(mdef->data->mname));
  176. 		instapetrify(kbuf);
  177. 	    }
  178. 	}
  179. 	return(0);
  180. }

missum

  1. void
  2. missum(mdef,mattk)
  3. register struct monst *mdef;
  4. register struct attack *mattk;
  5. {
  6. 	if (could_seduce(&youmonst, mdef, mattk))
  7. 		You("pretend to be friendly to %s.", mon_nam(mdef));
  8. 	else if(canspotmon(mdef) && flags.verbose)
  9. 		You("miss %s.", mon_nam(mdef));
  10. 	else
  11. 		You("miss it.");
  12. 	if (!mdef->msleeping && mdef->mcanmove)
  13. 		wakeup(mdef);
  14. }

hmonas

  1. STATIC_OVL boolean
  2. hmonas(mon, tmp)		/* attack monster as a monster. */
  3. register struct monst *mon;
  4. register int tmp;
  5. {
  6. 	struct attack *mattk, alt_attk;
  7. 	int	i, sum[NATTK], hittmp = 0;
  8. 	int	nsum = 0;
  9. 	int	dhit = 0;
  10.  
  11. 	for(i = 0; i < NATTK; i++) {
  12.  
  13. 	    sum[i] = 0;
  14. 	    mattk = getmattk(youmonst.data, i, sum, &alt_attk);
  15. 	    switch(mattk->aatyp) {
  16. 		case AT_WEAP:
  17. use_weapon:
  18. 	/* Certain monsters don't use weapons when encountered as enemies,
  19. 	 * but players who polymorph into them have hands or claws and thus
  20. 	 * should be able to use weapons.  This shouldn't prohibit the use
  21. 	 * of most special abilities, either.
  22. 	 */
  23. 	/* Potential problem: if the monster gets multiple weapon attacks,
  24. 	 * we currently allow the player to get each of these as a weapon
  25. 	 * attack.  Is this really desirable?
  26. 	 */
  27. 			if (uwep) {
  28. 			    hittmp = hitval(uwep, mon);
  29. 			    hittmp += weapon_hit_bonus(uwep);
  30. 			    tmp += hittmp;
  31. 			}
  32. 			dhit = (tmp > (dieroll = rnd(20)) || u.uswallow);
  33. 			/* KMH -- Don't accumulate to-hit bonuses */
  34. 			if (uwep) tmp -= hittmp;
  35. 			/* Enemy dead, before any special abilities used */
  36. 			if (!known_hitum(mon,&dhit,mattk)) {
  37. 			    sum[i] = 2;
  38. 			    break;
  39. 			} else sum[i] = dhit;
  40. 			/* might be a worm that gets cut in half */
  41. 			if (m_at(u.ux+u.dx, u.uy+u.dy) != mon) return((boolean)(nsum != 0));
  42. 			/* Do not print "You hit" message, since known_hitum
  43. 			 * already did it.
  44. 			 */
  45. 			if (dhit && mattk->adtyp != AD_SPEL
  46. 				&& mattk->adtyp != AD_PHYS)
  47. 				sum[i] = damageum(mon,mattk);
  48. 			break;
  49. 		case AT_CLAW:
  50. 			if (i==0 && uwep && !cantwield(youmonst.data)) goto use_weapon;
  51. #ifdef SEDUCE
  52. 			/* succubi/incubi are humanoid, but their _second_
  53. 			 * attack is AT_CLAW, not their first...
  54. 			 */
  55. 			if (i==1 && uwep && (u.umonnum == PM_SUCCUBUS ||
  56. 				u.umonnum == PM_INCUBUS)) goto use_weapon;
  57. #endif
  58. 		case AT_KICK:
  59. 		case AT_BITE:
  60. 		case AT_STNG:
  61. 		case AT_TUCH:
  62. 		case AT_BUTT:
  63. 		case AT_TENT:
  64. 			if (i==0 && uwep && (youmonst.data->mlet==S_LICH)) goto use_weapon;
  65. 			if ((dhit = (tmp > rnd(20) || u.uswallow)) != 0) {
  66. 			    int compat;
  67.  
  68. 			    if (!u.uswallow &&
  69. 				(compat=could_seduce(&youmonst, mon, mattk))) {
  70. 				You("%s %s %s.",
  71. 				    mon->mcansee && haseyes(mon->data)
  72. 				    ? "smile at" : "talk to",
  73. 				    mon_nam(mon),
  74. 				    compat == 2 ? "engagingly":"seductively");
  75. 				/* doesn't anger it; no wakeup() */
  76. 				sum[i] = damageum(mon, mattk);
  77. 				break;
  78. 			    }
  79. 			    wakeup(mon);
  80. 			    /* maybe this check should be in damageum()? */
  81. 			    if (mon->data == &mons[PM_SHADE] &&
  82. 					!(mattk->aatyp == AT_KICK &&
  83. 					    uarmf && uarmf->blessed)) {
  84. 				Your("attack passes harmlessly through %s.",
  85. 				    mon_nam(mon));
  86. 				break;
  87. 			    }
  88. 			    if (mattk->aatyp == AT_KICK)
  89. 				    You("kick %s.", mon_nam(mon));
  90. 			    else if (mattk->aatyp == AT_BITE)
  91. 				    You("bite %s.", mon_nam(mon));
  92. 			    else if (mattk->aatyp == AT_STNG)
  93. 				    You("sting %s.", mon_nam(mon));
  94. 			    else if (mattk->aatyp == AT_BUTT)
  95. 				    You("butt %s.", mon_nam(mon));
  96. 			    else if (mattk->aatyp == AT_TUCH)
  97. 				    You("touch %s.", mon_nam(mon));
  98. 			    else if (mattk->aatyp == AT_TENT)
  99. 				    Your("tentacles suck %s.", mon_nam(mon));
  100. 			    else You("hit %s.", mon_nam(mon));
  101. 			    sum[i] = damageum(mon, mattk);
  102. 			} else
  103. 			    missum(mon, mattk);
  104. 			break;
  105.  
  106. 		case AT_HUGS:
  107. 			/* automatic if prev two attacks succeed, or if
  108. 			 * already grabbed in a previous attack
  109. 			 */
  110. 			dhit = 1;
  111. 			wakeup(mon);
  112. 			if (mon->data == &mons[PM_SHADE])
  113. 			    Your("hug passes harmlessly through %s.",
  114. 				mon_nam(mon));
  115. 			else if (!sticks(mon->data) && !u.uswallow) {
  116. 			    if (mon==u.ustuck) {
  117. 				pline("%s is being %s.", Monnam(mon),
  118. 				    u.umonnum==PM_ROPE_GOLEM ? "choked":
  119. 				    "crushed");
  120. 				sum[i] = damageum(mon, mattk);
  121. 			    } else if(i >= 2 && sum[i-1] && sum[i-2]) {
  122. 				You("grab %s!", mon_nam(mon));
  123. 				u.ustuck = mon;
  124. 				sum[i] = damageum(mon, mattk);
  125. 			    }
  126. 			}
  127. 			break;
  128.  
  129. 		case AT_EXPL:	/* automatic hit if next to */
  130. 			dhit = -1;
  131. 			wakeup(mon);
  132. 			sum[i] = explum(mon, mattk);
  133. 			break;
  134.  
  135. 		case AT_ENGL:
  136. 			if((dhit = (tmp > rnd(20+i)))) {
  137. 				wakeup(mon);
  138. 				if (mon->data == &mons[PM_SHADE])
  139. 				    Your("attempt to surround %s is harmless.",
  140. 					mon_nam(mon));
  141. 				else {
  142. 				    sum[i]= gulpum(mon,mattk);
  143. 				    if (sum[i] == 2 &&
  144. 					    (mon->data->mlet == S_ZOMBIE ||
  145. 						mon->data->mlet == S_MUMMY) &&
  146. 					    rn2(5) &&
  147. 					    !Sick_resistance) {
  148. 					You_feel("%ssick.",
  149. 					    (Sick) ? "very " : "");
  150. 					mdamageu(mon, rnd(8));
  151. 				    }
  152. 				}
  153. 			} else
  154. 				missum(mon, mattk);
  155. 			break;
  156.  
  157. 		case AT_MAGC:
  158. 			/* No check for uwep; if wielding nothing we want to
  159. 			 * do the normal 1-2 points bare hand damage...
  160. 			 */
  161. 			if (i==0 && (youmonst.data->mlet==S_KOBOLD
  162. 				|| youmonst.data->mlet==S_ORC
  163. 				|| youmonst.data->mlet==S_GNOME
  164. 				)) goto use_weapon;
  165.  
  166. 		case AT_NONE:
  167. 		case AT_BOOM:
  168. 			continue;
  169. 			/* Not break--avoid passive attacks from enemy */
  170.  
  171. 		case AT_BREA:
  172. 		case AT_SPIT:
  173. 		case AT_GAZE:	/* all done using #monster command */
  174. 			dhit = 0;
  175. 			break;
  176.  
  177. 		default: /* Strange... */
  178. 			impossible("strange attack of yours (%d)",
  179. 				 mattk->aatyp);
  180. 	    }
  181. 	    if (dhit == -1) {
  182. 		u.mh = -1;	/* dead in the current form */
  183. 		rehumanize();
  184. 	    }
  185. 	    if (sum[i] == 2)
  186. 		return((boolean)passive(mon, 1, 0, mattk->aatyp));
  187. 							/* defender dead */
  188. 	    else {
  189. 		(void) passive(mon, sum[i], 1, mattk->aatyp);
  190. 		nsum |= sum[i];
  191. 	    }
  192. 	    if (!Upolyd)
  193. 		break; /* No extra attacks if no longer a monster */
  194. 	    if (multi < 0)
  195. 		break; /* If paralyzed while attacking, i.e. floating eye */
  196. 	}
  197. 	return((boolean)(nsum != 0));
  198. }

passive

  1. /*	Special (passive) attacks on you by monsters done here.		*/
  2.  
  3. int
  4. passive(mon, mhit, malive, aatyp)
  5. register struct monst *mon;
  6. register boolean mhit;
  7. register int malive;
  8. uchar aatyp;
  9. {
  10. 	register struct permonst *ptr = mon->data;
  11. 	register int i, tmp;
  12.  
  13. 	for(i = 0; ; i++) {
  14. 	    if(i >= NATTK) return(malive | mhit);	/* no passive attacks */
  15. 	    if(ptr->mattk[i].aatyp == AT_NONE) break;	/* try this one */
  16. 	}
  17. 	/* Note: tmp not always used */
  18. 	if (ptr->mattk[i].damn)
  19. 	    tmp = d((int)ptr->mattk[i].damn, (int)ptr->mattk[i].damd);
  20. 	else if(ptr->mattk[i].damd)
  21. 	    tmp = d((int)mon->m_lev+1, (int)ptr->mattk[i].damd);
  22. 	else
  23. 	    tmp = 0;
  24.  
  25. /*	These affect you even if they just died */
  26.  
  27. 	switch(ptr->mattk[i].adtyp) {
  28.  
  29. 	  case AD_ACID:
  30. 	    if(mhit && rn2(2)) {
  31. 		if (Blind || !flags.verbose) You("are splashed!");
  32. 		else	You("are splashed by %s acid!",
  33. 			                s_suffix(mon_nam(mon)));
  34.  
  35. 		if (!Acid_resistance)
  36. 			mdamageu(mon, tmp);
  37. 		if(!rn2(30)) erode_armor(&youmonst, TRUE);
  38. 	    }
  39. 	    if (mhit) {
  40. 		if (aatyp == AT_KICK) {
  41. 		    if (uarmf && !rn2(6))
  42. 			(void)rust_dmg(uarmf, xname(uarmf), 3, TRUE, &youmonst);
  43. 		} else if (aatyp == AT_WEAP || aatyp == AT_CLAW ||
  44. 			   aatyp == AT_MAGC || aatyp == AT_TUCH)
  45. 		    passive_obj(mon, (struct obj*)0, &(ptr->mattk[i]));
  46. 	    }
  47. 	    exercise(A_STR, FALSE);
  48. 	    break;
  49. 	  case AD_STON:
  50. 	    if (mhit) {		/* successful attack */
  51. 		long protector = attk_protection((int)aatyp);
  52.  
  53. 		/* hero using monsters' AT_MAGC attack is hitting hand to
  54. 		   hand rather than casting a spell */
  55. 		if (aatyp == AT_MAGC) protector = W_ARMG;
  56.  
  57. 		if (protector == 0L ||		/* no protection */
  58. 			(protector == W_ARMG && !uarmg && !uwep) ||
  59. 			(protector == W_ARMF && !uarmf) ||
  60. 			(protector == W_ARMH && !uarmh) ||
  61. 			(protector == (W_ARMC|W_ARMG) && (!uarmc || !uarmg))) {
  62. 		    if (!Stone_resistance &&
  63. 			    !(poly_when_stoned(youmonst.data) &&
  64. 				polymon(PM_STONE_GOLEM))) {
  65. 			You("turn to stone...");
  66. 			done_in_by(mon);
  67. 			return 2;
  68. 		    }
  69. 		}
  70. 	    }
  71. 	    break;
  72. 	  case AD_RUST:
  73. 	    if(mhit && !mon->mcan) {
  74. 		if (aatyp == AT_KICK) {
  75. 		    if (uarmf)
  76. 			(void)rust_dmg(uarmf, xname(uarmf), 1, TRUE, &youmonst);
  77. 		} else if (aatyp == AT_WEAP || aatyp == AT_CLAW ||
  78. 			   aatyp == AT_MAGC || aatyp == AT_TUCH)
  79. 		    passive_obj(mon, (struct obj*)0, &(ptr->mattk[i]));
  80. 	    }
  81. 	    break;
  82. 	  case AD_CORR:
  83. 	    if(mhit && !mon->mcan) {
  84. 		if (aatyp == AT_KICK) {
  85. 		    if (uarmf)
  86. 			(void)rust_dmg(uarmf, xname(uarmf), 3, TRUE, &youmonst);
  87. 		} else if (aatyp == AT_WEAP || aatyp == AT_CLAW ||
  88. 			   aatyp == AT_MAGC || aatyp == AT_TUCH)
  89. 		    passive_obj(mon, (struct obj*)0, &(ptr->mattk[i]));
  90. 	    }
  91. 	    break;
  92. 	  case AD_MAGM:
  93. 	    /* wrath of gods for attacking Oracle */
  94. 	    if(Antimagic) {
  95. 		shieldeff(u.ux, u.uy);
  96. 		pline("A hail of magic missiles narrowly misses you!");
  97. 	    } else {
  98. 		You("are hit by magic missiles appearing from thin air!");
  99. 		mdamageu(mon, tmp);
  100. 	    }
  101. 	    break;
  102. 	  case AD_ENCH:	/* KMH -- remove enchantment (disenchanter) */
  103. 	    if (mhit) {
  104. 		struct obj *obj = (struct obj *)0;
  105.  
  106. 		if (aatyp == AT_KICK) {
  107. 		    obj = uarmf;
  108. 		    if (!obj) break;
  109. 		} else if (aatyp == AT_BITE || aatyp == AT_BUTT ||
  110. 			   (aatyp >= AT_STNG && aatyp < AT_WEAP)) {
  111. 		    break;		/* no object involved */
  112. 		}
  113. 		passive_obj(mon, obj, &(ptr->mattk[i]));
  114. 	    }
  115. 	    break;
  116. 	  default:
  117. 	    break;
  118. 	}
  119.  
  120. /*	These only affect you if they still live */
  121.  
  122. 	if(malive && !mon->mcan && rn2(3)) {
  123.  
  124. 	    switch(ptr->mattk[i].adtyp) {
  125.  
  126. 	      case AD_PLYS:
  127. 		if(ptr == &mons[PM_FLOATING_EYE]) {
  128. 		    if (!canseemon(mon)) {
  129. 			break;
  130. 		    }
  131. 		    if(mon->mcansee) {
  132. 			if (ureflects("%s gaze is reflected by your %s.",
  133. 				    s_suffix(Monnam(mon))))
  134. 			    ;
  135. 			else if (Free_action)
  136. 			    You("momentarily stiffen under %s gaze!",
  137. 				    s_suffix(mon_nam(mon)));
  138. 			else {
  139. 			    You("are frozen by %s gaze!",
  140. 				  s_suffix(mon_nam(mon)));
  141. 			    nomul((ACURR(A_WIS) > 12 || rn2(4)) ? -tmp : -127);
  142. 			}
  143. 		    } else {
  144. 			pline("%s cannot defend itself.",
  145. 				Adjmonnam(mon,"blind"));
  146. 			if(!rn2(500)) change_luck(-1);
  147. 		    }
  148. 		} else if (Free_action) {
  149. 		    You("momentarily stiffen.");
  150. 		} else { /* gelatinous cube */
  151. 		    You("are frozen by %s!", mon_nam(mon));
  152. 	    	    nomovemsg = 0;	/* default: "you can move again" */
  153. 		    nomul(-tmp);
  154. 		    exercise(A_DEX, FALSE);
  155. 		}
  156. 		break;
  157. 	      case AD_COLD:		/* brown mold or blue jelly */
  158. 		if(monnear(mon, u.ux, u.uy)) {
  159. 		    if(Cold_resistance) {
  160. 			shieldeff(u.ux, u.uy);
  161. 			You_feel("a mild chill.");
  162. 			ugolemeffects(AD_COLD, tmp);
  163. 			break;
  164. 		    }
  165. 		    You("are suddenly very cold!");
  166. 		    mdamageu(mon, tmp);
  167. 		/* monster gets stronger with your heat! */
  168. 		    mon->mhp += tmp / 2;
  169. 		    if (mon->mhpmax < mon->mhp) mon->mhpmax = mon->mhp;
  170. 		/* at a certain point, the monster will reproduce! */
  171. 		    if(mon->mhpmax > ((int) (mon->m_lev+1) * 8))
  172. 			(void)split_mon(mon, &youmonst);
  173. 		}
  174. 		break;
  175. 	      case AD_STUN:		/* specifically yellow mold */
  176. 		if(!Stunned)
  177. 		    make_stunned((long)tmp, TRUE);
  178. 		break;
  179. 	      case AD_FIRE:
  180. 		if(monnear(mon, u.ux, u.uy)) {
  181. 		    if(Fire_resistance) {
  182. 			shieldeff(u.ux, u.uy);
  183. 			You_feel("mildly warm.");
  184. 			ugolemeffects(AD_FIRE, tmp);
  185. 			break;
  186. 		    }
  187. 		    You("are suddenly very hot!");
  188. 		    mdamageu(mon, tmp);
  189. 		}
  190. 		break;
  191. 	      case AD_ELEC:
  192. 		if(Shock_resistance) {
  193. 		    shieldeff(u.ux, u.uy);
  194. 		    You_feel("a mild tingle.");
  195. 		    ugolemeffects(AD_ELEC, tmp);
  196. 		    break;
  197. 		}
  198. 		You("are jolted with electricity!");
  199. 		mdamageu(mon, tmp);
  200. 		break;
  201. 	      default:
  202. 		break;
  203. 	    }
  204. 	}
  205. 	return(malive | mhit);
  206. }

passive_obj

  1. /*
  2. * Special (passive) attacks on an attacking object by monsters done here.
  3. * Assumes the attack was successful.
  4. */
  5. void
  6. passive_obj(mon, obj, mattk)
  7. register struct monst *mon;
  8. register struct obj *obj;	/* null means pick uwep, uswapwep or uarmg */
  9. struct attack *mattk;		/* null means we find one internally */
  10. {
  11. 	register struct permonst *ptr = mon->data;
  12. 	register int i;
  13.  
  14. 	/* if caller hasn't specified an object, use uwep, uswapwep or uarmg */
  15. 	if (!obj) {
  16. 	    obj = (u.twoweap && uswapwep && !rn2(2)) ? uswapwep : uwep;
  17. 	    if (!obj && mattk->adtyp == AD_ENCH)
  18. 		obj = uarmg;		/* no weapon? then must be gloves */
  19. 	    if (!obj) return;		/* no object to affect */
  20. 	}
  21.  
  22. 	/* if caller hasn't specified an attack, find one */
  23. 	if (!mattk) {
  24. 	    for(i = 0; ; i++) {
  25. 		if(i >= NATTK) return;	/* no passive attacks */
  26. 		if(ptr->mattk[i].aatyp == AT_NONE) break; /* try this one */
  27. 	    }
  28. 	    mattk = &(ptr->mattk[i]);
  29. 	}
  30.  
  31. 	switch(mattk->adtyp) {
  32.  
  33. 	case AD_ACID:
  34. 	    if(!rn2(6)) {
  35. 		erode_obj(obj, TRUE, FALSE);
  36. 	    }
  37. 	    break;
  38. 	case AD_RUST:
  39. 	    if(!mon->mcan) {
  40. 		erode_obj(obj, FALSE, FALSE);
  41. 	    }
  42. 	    break;
  43. 	case AD_CORR:
  44. 	    if(!mon->mcan) {
  45. 		erode_obj(obj, TRUE, FALSE);
  46. 	    }
  47. 	    break;
  48. 	case AD_ENCH:
  49. 	    if (!mon->mcan) {
  50. 		if (drain_item(obj) && carried(obj) &&
  51. 		    (obj->known || obj->oclass == ARMOR_CLASS)) {
  52. 		    Your("%s less effective.", aobjnam(obj, "seem"));
  53. 	    	}
  54. 	    	break;
  55. 	    }
  56. 	  default:
  57. 	    break;
  58. 	}
  59.  
  60. 	if (carried(obj)) update_inventory();
  61. }

stumble_onto_mimic

  1. /* Note: caller must ascertain mtmp is mimicking... */
  2. void
  3. stumble_onto_mimic(mtmp)
  4. struct monst *mtmp;
  5. {
  6. 	const char *fmt = "Wait!  That's %s!",
  7. 		   *generic = "a monster",
  8. 		   *what = 0;
  9.  
  10. 	if(!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data,AD_STCK))
  11. 	    u.ustuck = mtmp;
  12.  
  13. 	if (Blind) {
  14. 	    if (!Blind_telepat)
  15. 		what = generic;		/* with default fmt */
  16. 	    else if (mtmp->m_ap_type == M_AP_MONSTER)
  17. 		what = a_monnam(mtmp);	/* differs from what was sensed */
  18. 	} else {
  19. 	    int glyph = levl[u.ux+u.dx][u.uy+u.dy].glyph;
  20.  
  21. 	    if (glyph_is_cmap(glyph) &&
  22. 		    (glyph_to_cmap(glyph) == S_hcdoor ||
  23. 		     glyph_to_cmap(glyph) == S_vcdoor))
  24. 		fmt = "The door actually was %s!";
  25. 	    else if (glyph_is_object(glyph) &&
  26. 		    glyph_to_obj(glyph) == GOLD_PIECE)
  27. 		fmt = "That gold was %s!";
  28.  
  29. 	    /* cloned Wiz starts out mimicking some other monster and
  30. 	       might make himself invisible before being revealed */
  31. 	    if (mtmp->minvis && !See_invisible)
  32. 		what = generic;
  33. 	    else
  34. 		what = a_monnam(mtmp);
  35. 	}
  36. 	if (what) pline(fmt, what);
  37.  
  38. 	wakeup(mtmp);	/* clears mimicking */
  39. }

nohandglow

  1. STATIC_OVL void
  2. nohandglow(mon)
  3. struct monst *mon;
  4. {
  5. 	char *hands=makeplural(body_part(HAND));
  6.  
  7. 	if (!u.umconf || mon->mconf) return;
  8. 	if (u.umconf == 1) {
  9. 		if (Blind)
  10. 			Your("%s stop tingling.", hands);
  11. 		else
  12. 			Your("%s stop glowing %s.", hands, hcolor(NH_RED));
  13. 	} else {
  14. 		if (Blind)
  15. 			pline_The("tingling in your %s lessens.", hands);
  16. 		else
  17. 			Your("%s no longer glow so brightly %s.", hands,
  18. 				hcolor(NH_RED));
  19. 	}
  20. 	u.umconf--;
  21. }

flash_hits_mon

  1. int
  2. flash_hits_mon(mtmp, otmp)
  3. struct monst *mtmp;
  4. struct obj *otmp;	/* source of flash */
  5. {
  6. 	int tmp, amt, res = 0, useeit = canseemon(mtmp);
  7.  
  8. 	if (mtmp->msleeping) {
  9. 	    mtmp->msleeping = 0;
  10. 	    if (useeit) {
  11. 		pline_The("flash awakens %s.", mon_nam(mtmp));
  12. 		res = 1;
  13. 	    }
  14. 	} else if (mtmp->data->mlet != S_LIGHT) {
  15. 	    if (!resists_blnd(mtmp)) {
  16. 		tmp = dist2(otmp->ox, otmp->oy, mtmp->mx, mtmp->my);
  17. 		if (useeit) {
  18. 		    pline("%s is blinded by the flash!", Monnam(mtmp));
  19. 		    res = 1;
  20. 		}
  21. 		if (mtmp->data == &mons[PM_GREMLIN]) {
  22. 		    /* Rule #1: Keep them out of the light. */
  23. 		    amt = otmp->otyp == WAN_LIGHT ? d(1 + otmp->spe, 4) :
  24. 		          rn2(min(mtmp->mhp,4));
  25. 		    pline("%s %s!", Monnam(mtmp), amt > mtmp->mhp / 2 ?
  26. 			  "wails in agony" : "cries out in pain");
  27. 		    if ((mtmp->mhp -= amt) <= 0) {
  28. 			if (flags.mon_moving)
  29. 			    monkilled(mtmp, (char *)0, AD_BLND);
  30. 			else
  31. 			    killed(mtmp);
  32. 		    } else if (cansee(mtmp->mx,mtmp->my) && !canspotmon(mtmp)){
  33. 			map_invisible(mtmp->mx, mtmp->my);
  34. 		    }
  35. 		}
  36. 		if (mtmp->mhp > 0) {
  37. 		    if (!flags.mon_moving) setmangry(mtmp);
  38. 		    if (tmp < 9 && !mtmp->isshk && rn2(4)) {
  39. 			if (rn2(4))
  40. 			    monflee(mtmp, rnd(100), FALSE, TRUE);
  41. 			else
  42. 			    monflee(mtmp, 0, FALSE, TRUE);
  43. 		    }
  44. 		    mtmp->mcansee = 0;
  45. 		    mtmp->mblinded = (tmp < 3) ? 0 : rnd(1 + 50/tmp);
  46. 		}
  47. 	    }
  48. 	}
  49. 	return res;
  50. }
  51.  
  52. /*uhitm.c*/