Source:NetHack 3.4.3/src/mhitm.c

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

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

Top of file

  1. /*	SCCS Id: @(#)mhitm.c	3.4	2003/01/02	*/
  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. #include "artifact.h"
  3. #include "edog.h"
  4.  
  5. extern boolean notonhead;
  6.  
  7. #ifdef OVLB
  8.  
  9. static NEARDATA boolean vis, far_noise;
  10. static NEARDATA long noisetime;
  11. static NEARDATA struct obj *otmp;
  12.  
  13. static const char brief_feeling[] =
  14. 	"have a %s feeling for a moment, then it passes.";
  15.  
  16. STATIC_DCL char *FDECL(mon_nam_too, (char *,struct monst *,struct monst *));
  17. STATIC_DCL void FDECL(mrustm, (struct monst *, struct monst *, struct obj *));
  18. STATIC_DCL int FDECL(hitmm, (struct monst *,struct monst *,struct attack *));
  19. STATIC_DCL int FDECL(gazemm, (struct monst *,struct monst *,struct attack *));
  20. STATIC_DCL int FDECL(gulpmm, (struct monst *,struct monst *,struct attack *));
  21. STATIC_DCL int FDECL(explmm, (struct monst *,struct monst *,struct attack *));
  22. STATIC_DCL int FDECL(mdamagem, (struct monst *,struct monst *,struct attack *));
  23. STATIC_DCL void FDECL(mswingsm, (struct monst *, struct monst *, struct obj *));
  24. STATIC_DCL void FDECL(noises,(struct monst *,struct attack *));
  25. STATIC_DCL void FDECL(missmm,(struct monst *,struct monst *,struct attack *));
  26. STATIC_DCL int FDECL(passivemm, (struct monst *, struct monst *, BOOLEAN_P, int));
  27.  
  28. /* Needed for the special case of monsters wielding vorpal blades (rare).
  29. * If we use this a lot it should probably be a parameter to mdamagem()
  30. * instead of a global variable.
  31. */
  32. static int dieroll;

mon_name_too

  1. /* returns mon_nam(mon) relative to other_mon; normal name unless they're
  2. the same, in which case the reference is to {him|her|it} self */
  3. STATIC_OVL char *
  4. mon_nam_too(outbuf, mon, other_mon)
  5. char *outbuf;
  6. struct monst *mon, *other_mon;
  7. {
  8. 	Strcpy(outbuf, mon_nam(mon));
  9. 	if (mon == other_mon)
  10. 	    switch (pronoun_gender(mon)) {
  11. 	    case 0:	Strcpy(outbuf, "himself");  break;
  12. 	    case 1:	Strcpy(outbuf, "herself");  break;
  13. 	    default:	Strcpy(outbuf, "itself"); break;
  14. 	    }
  15. 	return outbuf;
  16. }

noises

  1. STATIC_OVL void
  2. noises(magr, mattk)
  3. 	register struct monst *magr;
  4. 	register struct	attack *mattk;
  5. {
  6. 	boolean farq = (distu(magr->mx, magr->my) > 15);
  7.  
  8. 	if(flags.soundok && (farq != far_noise || moves-noisetime > 10)) {
  9. 		far_noise = farq;
  10. 		noisetime = moves;
  11. 		You_hear("%s%s.",
  12. 			(mattk->aatyp == AT_EXPL) ? "an explosion" : "some noises",
  13. 			farq ? " in the distance" : "");
  14. 	}
  15. }

missmm

  1. STATIC_OVL
  2. void
  3. missmm(magr, mdef, mattk)
  4. 	register struct monst *magr, *mdef;
  5. 	struct attack *mattk;
  6. {
  7. 	const char *fmt;
  8. 	char buf[BUFSZ], mdef_name[BUFSZ];
  9.  
  10. 	if (vis) {
  11. 		if (!canspotmon(magr))
  12. 		    map_invisible(magr->mx, magr->my);
  13. 		if (!canspotmon(mdef))
  14. 		    map_invisible(mdef->mx, mdef->my);
  15. 		if (mdef->m_ap_type) seemimic(mdef);
  16. 		if (magr->m_ap_type) seemimic(magr);
  17. 		fmt = (could_seduce(magr,mdef,mattk) && !magr->mcan) ?
  18. 			"%s pretends to be friendly to" : "%s misses";
  19. 		Sprintf(buf, fmt, Monnam(magr));
  20. 		pline("%s %s.", buf, mon_nam_too(mdef_name, mdef, magr));
  21. 	} else  noises(magr, mattk);
  22. }

fightm

  1. /*
  2. *  fightm()  -- fight some other monster
  3. *
  4. *  Returns:
  5. *	0 - Monster did nothing.
  6. *	1 - If the monster made an attack.  The monster might have died.
  7. *
  8. *  There is an exception to the above.  If mtmp has the hero swallowed,
  9. *  then we report that the monster did nothing so it will continue to
  10. *  digest the hero.
  11. */
  12. int
  13. fightm(mtmp)		/* have monsters fight each other */
  14. 	register struct monst *mtmp;
  15. {
  16. 	register struct monst *mon, *nmon;
  17. 	int result, has_u_swallowed;
  18. #ifdef LINT
  19. 	nmon = 0;
  20. #endif
  21. 	/* perhaps the monster will resist Conflict */
  22. 	if(resist(mtmp, RING_CLASS, 0, 0))
  23. 	    return(0);
  24.  
  25. 	if(u.ustuck == mtmp) {
  26. 	    /* perhaps we're holding it... */
  27. 	    if(itsstuck(mtmp))
  28. 		return(0);
  29. 	}
  30. 	has_u_swallowed = (u.uswallow && (mtmp == u.ustuck));
  31.  
  32. 	for(mon = fmon; mon; mon = nmon) {
  33. 	    nmon = mon->nmon;
  34. 	    if(nmon == mtmp) nmon = mtmp->nmon;
  35. 	    /* Be careful to ignore monsters that are already dead, since we
  36. 	     * might be calling this before we've cleaned them up.  This can
  37. 	     * happen if the monster attacked a cockatrice bare-handedly, for
  38. 	     * instance.
  39. 	     */
  40. 	    if(mon != mtmp && !DEADMONSTER(mon)) {
  41. 		if(monnear(mtmp,mon->mx,mon->my)) {
  42. 		    if(!u.uswallow && (mtmp == u.ustuck)) {
  43. 			if(!rn2(4)) {
  44. 			    pline("%s releases you!", Monnam(mtmp));
  45. 			    u.ustuck = 0;
  46. 			} else
  47. 			    break;
  48. 		    }
  49.  
  50. 		    /* mtmp can be killed */
  51. 		    bhitpos.x = mon->mx;
  52. 		    bhitpos.y = mon->my;
  53. 		    notonhead = 0;
  54. 		    result = mattackm(mtmp,mon);
  55.  
  56. 		    if (result & MM_AGR_DIED) return 1;	/* mtmp died */
  57. 		    /*
  58. 		     *  If mtmp has the hero swallowed, lie and say there
  59. 		     *  was no attack (this allows mtmp to digest the hero).
  60. 		     */
  61. 		    if (has_u_swallowed) return 0;
  62.  
  63. 		    /* Allow attacked monsters a chance to hit back. Primarily
  64. 		     * to allow monsters that resist conflict to respond.
  65. 		     */
  66. 		    if ((result & MM_HIT) && !(result & MM_DEF_DIED) &&
  67. 			rn2(4) && mon->movement >= NORMAL_SPEED) {
  68. 			mon->movement -= NORMAL_SPEED;
  69. 			notonhead = 0;
  70. 			(void) mattackm(mon, mtmp);	/* return attack */
  71. 		    }
  72.  
  73. 		    return ((result & MM_HIT) ? 1 : 0);
  74. 		}
  75. 	    }
  76. 	}
  77. 	return 0;
  78. }

mattackm

  1. /*
  2. * mattackm() -- a monster attacks another monster.
  3. *
  4. * This function returns a result bitfield:
  5. *
  6. *	    --------- aggressor died
  7. *	   /  ------- defender died
  8. *	  /  /  ----- defender was hit
  9. *	 /  /  /
  10. *	x  x  x
  11. *
  12. *	0x4	MM_AGR_DIED
  13. *	0x2	MM_DEF_DIED
  14. *	0x1	MM_HIT
  15. *	0x0	MM_MISS
  16. *
  17. * Each successive attack has a lower probability of hitting.  Some rely on the
  18. * success of previous attacks.  ** this doen't seem to be implemented -dl **
  19. *
  20. * In the case of exploding monsters, the monster dies as well.
  21. */
  22. int
  23. mattackm(magr, mdef)
  24. register struct monst *magr,*mdef;
  25. {
  26. int		    i,		/* loop counter */
  27. 		    tmp,	/* amour class difference */
  28. 		    strike,	/* hit this attack */
  29. 		    attk,	/* attack attempted this time */
  30. 		    struck = 0,	/* hit at least once */
  31. 		    res[NATTK];	/* results of all attacks */
  32. struct attack   *mattk, alt_attk;
  33. struct permonst *pa, *pd;
  34.  
  35. if (!magr || !mdef) return(MM_MISS);		/* mike@genat */
  36. if (!magr->mcanmove || magr->msleeping) return(MM_MISS);
  37. pa = magr->data;  pd = mdef->data;
  38.  
  39. /* Grid bugs cannot attack at an angle. */
  40. if (pa == &mons[PM_GRID_BUG] && magr->mx != mdef->mx
  41. 						&& magr->my != mdef->my)
  42. 	return(MM_MISS);
  43.  
  44. /* Calculate the armour class differential. */
  45. tmp = find_mac(mdef) + magr->m_lev;
  46. if (mdef->mconf || !mdef->mcanmove || mdef->msleeping) {
  47. 	tmp += 4;
  48. 	mdef->msleeping = 0;
  49. }
  50.  
  51. /* undetect monsters become un-hidden if they are attacked */
  52. if (mdef->mundetected) {
  53. 	mdef->mundetected = 0;
  54. 	newsym(mdef->mx, mdef->my);
  55. 	if(canseemon(mdef) && !sensemon(mdef)) {
  56. 	    if (u.usleep) You("dream of %s.",
  57. 				(mdef->data->geno & G_UNIQ) ?
  58. 				a_monnam(mdef) : makeplural(m_monnam(mdef)));
  59. 	    else pline("Suddenly, you notice %s.", a_monnam(mdef));
  60. 	}
  61. }
  62.  
  63. /* Elves hate orcs. */
  64. if (is_elf(pa) && is_orc(pd)) tmp++;
  65.  
  66.  
  67. /* Set up the visibility of action */
  68. vis = (cansee(magr->mx,magr->my) && cansee(mdef->mx,mdef->my) && (canspotmon(magr) || canspotmon(mdef)));
  69.  
  70. /*	Set flag indicating monster has moved this turn.  Necessary since a
  71. *	monster might get an attack out of sequence (i.e. before its move) in
  72. *	some cases, in which case this still counts as its move for the round
  73. *	and it shouldn't move again.
  74. */
  75. magr->mlstmv = monstermoves;
  76.  
  77. /* Now perform all attacks for the monster. */
  78. for (i = 0; i < NATTK; i++) {
  79. 	res[i] = MM_MISS;
  80. 	mattk = getmattk(pa, i, res, &alt_attk);
  81. 	otmp = (struct obj *)0;
  82. 	attk = 1;
  83. 	switch (mattk->aatyp) {
  84. 	    case AT_WEAP:		/* "hand to hand" attacks */
  85. 		if (magr->weapon_check == NEED_WEAPON || !MON_WEP(magr)) {
  86. 		    magr->weapon_check = NEED_HTH_WEAPON;
  87. 		    if (mon_wield_item(magr) != 0) return 0;
  88. 		}
  89. 		possibly_unwield(magr, FALSE);
  90. 		otmp = MON_WEP(magr);
  91.  
  92. 		if (otmp) {
  93. 		    if (vis) mswingsm(magr, mdef, otmp);
  94. 		    tmp += hitval(otmp, mdef);
  95. 		}
  96. 		/* fall through */
  97. 	    case AT_CLAW:
  98. 	    case AT_KICK:
  99. 	    case AT_BITE:
  100. 	    case AT_STNG:
  101. 	    case AT_TUCH:
  102. 	    case AT_BUTT:
  103. 	    case AT_TENT:
  104. 		/* Nymph that teleported away on first attack? */
  105. 		if (distmin(magr->mx,magr->my,mdef->mx,mdef->my) > 1)
  106. 		    return MM_MISS;
  107. 		/* Monsters won't attack cockatrices physically if they
  108. 		 * have a weapon instead.  This instinct doesn't work for
  109. 		 * players, or under conflict or confusion. 
  110. 		 */
  111. 		if (!magr->mconf && !Conflict && otmp &&
  112. 		    mattk->aatyp != AT_WEAP && touch_petrifies(mdef->data)) {
  113. 		    strike = 0;
  114. 		    break;
  115. 		}
  116. 		dieroll = rnd(20 + i);
  117. 		strike = (tmp > dieroll);
  118. 		/* KMH -- don't accumulate to-hit bonuses */
  119. 		if (otmp)
  120. 		    tmp -= hitval(otmp, mdef);
  121. 		if (strike) {
  122. 		    res[i] = hitmm(magr, mdef, mattk);
  123. 		    if((mdef->data == &mons[PM_BLACK_PUDDING] || mdef->data == &mons[PM_BROWN_PUDDING])
  124. 		       && otmp && objects[otmp->otyp].oc_material == IRON
  125. 		       && mdef->mhp > 1 && !mdef->mcan)
  126. 		    {
  127. 			if (clone_mon(mdef, 0, 0)) {
  128. 			    if (vis) {
  129. 				char buf[BUFSZ];
  130.  
  131. 				Strcpy(buf, Monnam(mdef));
  132. 				pline("%s divides as %s hits it!", buf, mon_nam(magr));
  133. 			    }
  134. 			}
  135. 		    }
  136. 		} else
  137. 		    missmm(magr, mdef, mattk);
  138. 		break;
  139.  
  140. 	    case AT_HUGS:	/* automatic if prev two attacks succeed */
  141. 		strike = (i >= 2 && res[i-1] == MM_HIT && res[i-2] == MM_HIT);
  142. 		if (strike)
  143. 		    res[i] = hitmm(magr, mdef, mattk);
  144.  
  145. 		break;
  146.  
  147. 	    case AT_GAZE:
  148. 		strike = 0;	/* will not wake up a sleeper */
  149. 		res[i] = gazemm(magr, mdef, mattk);
  150. 		break;
  151.  
  152. 	    case AT_EXPL:
  153. 		res[i] = explmm(magr, mdef, mattk);
  154. 		if (res[i] == MM_MISS) { /* cancelled--no attack */
  155. 		    strike = 0;
  156. 		    attk = 0;
  157. 		} else
  158. 		    strike = 1;	/* automatic hit */
  159. 		break;
  160.  
  161. 	    case AT_ENGL:
  162. #ifdef STEED
  163. 		if (u.usteed && (mdef == u.usteed)) {
  164. 		    strike = 0;
  165. 		    break;
  166. 		} 
  167. #endif
  168. 		/* Engulfing attacks are directed at the hero if
  169. 		 * possible. -dlc
  170. 		 */
  171. 		if (u.uswallow && magr == u.ustuck)
  172. 		    strike = 0;
  173. 		else {
  174. 		    if ((strike = (tmp > rnd(20+i))))
  175. 			res[i] = gulpmm(magr, mdef, mattk);
  176. 		    else
  177. 			missmm(magr, mdef, mattk);
  178. 		}
  179. 		break;
  180.  
  181. 	    default:		/* no attack */
  182. 		strike = 0;
  183. 		attk = 0;
  184. 		break;
  185. 	}
  186.  
  187. 	if (attk && !(res[i] & MM_AGR_DIED))
  188. 	    res[i] = passivemm(magr, mdef, strike, res[i] & MM_DEF_DIED);
  189.  
  190. 	if (res[i] & MM_DEF_DIED) return res[i];
  191.  
  192. 	/*
  193. 	 *  Wake up the defender.  NOTE:  this must follow the check
  194. 	 *  to see if the defender died.  We don't want to modify
  195. 	 *  unallocated monsters!
  196. 	 */
  197. 	if (strike) mdef->msleeping = 0;
  198.  
  199. 	if (res[i] & MM_AGR_DIED)  return res[i];
  200. 	/* return if aggressor can no longer attack */
  201. 	if (!magr->mcanmove || magr->msleeping) return res[i];
  202. 	if (res[i] & MM_HIT) struck = 1;	/* at least one hit */
  203. }
  204.  
  205. return(struck ? MM_HIT : MM_MISS);
  206. }

hitmm

  1. /* Returns the result of mdamagem(). */
  2. STATIC_OVL int
  3. hitmm(magr, mdef, mattk)
  4. 	register struct monst *magr,*mdef;
  5. 	struct	attack *mattk;
  6. {
  7. 	if(vis){
  8. 		int compat;
  9. 		char buf[BUFSZ], mdef_name[BUFSZ];
  10.  
  11. 		if (!canspotmon(magr))
  12. 		    map_invisible(magr->mx, magr->my);
  13. 		if (!canspotmon(mdef))
  14. 		    map_invisible(mdef->mx, mdef->my);
  15. 		if(mdef->m_ap_type) seemimic(mdef);
  16. 		if(magr->m_ap_type) seemimic(magr);
  17. 		if((compat = could_seduce(magr,mdef,mattk)) && !magr->mcan) {
  18. 			Sprintf(buf, "%s %s", Monnam(magr),
  19. 				mdef->mcansee ? "smiles at" : "talks to");
  20. 			pline("%s %s %s.", buf, mon_nam(mdef),
  21. 				compat == 2 ?
  22. 					"engagingly" : "seductively");
  23. 		} else {
  24. 		    char magr_name[BUFSZ];
  25.  
  26. 		    Strcpy(magr_name, Monnam(magr));
  27. 		    switch (mattk->aatyp) {
  28. 			case AT_BITE:
  29. 				Sprintf(buf,"%s bites", magr_name);
  30. 				break;
  31. 			case AT_STNG:
  32. 				Sprintf(buf,"%s stings", magr_name);
  33. 				break;
  34. 			case AT_BUTT:
  35. 				Sprintf(buf,"%s butts", magr_name);
  36. 				break;
  37. 			case AT_TUCH:
  38. 				Sprintf(buf,"%s touches", magr_name);
  39. 				break;
  40. 			case AT_TENT:
  41. 				Sprintf(buf, "%s tentacles suck",
  42. 					s_suffix(magr_name));
  43. 				break;
  44. 			case AT_HUGS:
  45. 				if (magr != u.ustuck) {
  46. 				    Sprintf(buf,"%s squeezes", magr_name);
  47. 				    break;
  48. 				}
  49. 			default:
  50. 				Sprintf(buf,"%s hits", magr_name);
  51. 		    }
  52. 		    pline("%s %s.", buf, mon_nam_too(mdef_name, mdef, magr));
  53. 		}
  54. 	} else  noises(magr, mattk);
  55. 	return(mdamagem(magr, mdef, mattk));
  56. }

gazemm

  1. /* Returns the same values as mdamagem(). */
  2. STATIC_OVL int
  3. gazemm(magr, mdef, mattk)
  4. 	register struct monst *magr, *mdef;
  5. 	struct attack *mattk;
  6. {
  7. 	char buf[BUFSZ];
  8.  
  9. 	if(vis) {
  10. 		Sprintf(buf,"%s gazes at", Monnam(magr));
  11. 		pline("%s %s...", buf, mon_nam(mdef));
  12. 	}
  13.  
  14. 	if (magr->mcan || !magr->mcansee ||
  15. 	    (magr->minvis && !perceives(mdef->data)) ||
  16. 	    !mdef->mcansee || mdef->msleeping) {
  17. 	    if(vis) pline("but nothing happens.");
  18. 	    return(MM_MISS);
  19. 	}
  20. 	/* call mon_reflects 2x, first test, then, if visible, print message */
  21. 	if (magr->data == &mons[PM_MEDUSA] && mon_reflects(mdef, (char *)0)) {
  22. 	    if (canseemon(mdef))
  23. 		(void) mon_reflects(mdef,
  24. 				    "The gaze is reflected away by %s %s.");
  25. 	    if (mdef->mcansee) {
  26. 		if (mon_reflects(magr, (char *)0)) {
  27. 		    if (canseemon(magr))
  28. 			(void) mon_reflects(magr,
  29. 					"The gaze is reflected away by %s %s.");
  30. 		    return (MM_MISS);
  31. 		}
  32. 		if (mdef->minvis && !perceives(magr->data)) {
  33. 		    if (canseemon(magr)) {
  34. 			pline("%s doesn't seem to notice that %s gaze was reflected.",
  35. 			      Monnam(magr), mhis(magr));
  36. 		    }
  37. 		    return (MM_MISS);
  38. 		}
  39. 		if (canseemon(magr))
  40. 		    pline("%s is turned to stone!", Monnam(magr));
  41. 		monstone(magr);
  42. 		if (magr->mhp > 0) return (MM_MISS);
  43. 		return (MM_AGR_DIED);
  44. 	    }
  45. 	}
  46.  
  47. 	return(mdamagem(magr, mdef, mattk));
  48. }

gulpmm

  1. /* Returns the same values as mattackm(). */
  2. STATIC_OVL int
  3. gulpmm(magr, mdef, mattk)
  4. 	register struct monst *magr, *mdef;
  5. 	register struct	attack *mattk;
  6. {
  7. 	xchar	ax, ay, dx, dy;
  8. 	int	status;
  9. 	char buf[BUFSZ];
  10. 	struct obj *obj;
  11.  
  12. 	if (mdef->data->msize >= MZ_HUGE) return MM_MISS;
  13.  
  14. 	if (vis) {
  15. 		Sprintf(buf,"%s swallows", Monnam(magr));
  16. 		pline("%s %s.", buf, mon_nam(mdef));
  17. 	}
  18. 	for (obj = mdef->minvent; obj; obj = obj->nobj)
  19. 	    (void) snuff_lit(obj);
  20.  
  21. 	/*
  22. 	 *  All of this maniuplation is needed to keep the display correct.
  23. 	 *  There is a flush at the next pline().
  24. 	 */
  25. 	ax = magr->mx;
  26. 	ay = magr->my;
  27. 	dx = mdef->mx;
  28. 	dy = mdef->my;
  29. 	/*
  30. 	 *  Leave the defender in the monster chain at it's current position,
  31. 	 *  but don't leave it on the screen.  Move the agressor to the def-
  32. 	 *  ender's position.
  33. 	 */
  34. 	remove_monster(ax, ay);
  35. 	place_monster(magr, dx, dy);
  36. 	newsym(ax,ay);			/* erase old position */
  37. 	newsym(dx,dy);			/* update new position */
  38.  
  39. 	status = mdamagem(magr, mdef, mattk);
  40.  
  41. 	if ((status & MM_AGR_DIED) && (status & MM_DEF_DIED)) {
  42. 	    ;					/* both died -- do nothing  */
  43. 	}
  44. 	else if (status & MM_DEF_DIED) {	/* defender died */
  45. 	    /*
  46. 	     *  Note:  remove_monster() was called in relmon(), wiping out
  47. 	     *  magr from level.monsters[mdef->mx][mdef->my].  We need to
  48. 	     *  put it back and display it.	-kd
  49. 	     */
  50. 	    place_monster(magr, dx, dy);
  51. 	    newsym(dx, dy);
  52. 	}
  53. 	else if (status & MM_AGR_DIED) {	/* agressor died */
  54. 	    place_monster(mdef, dx, dy);
  55. 	    newsym(dx, dy);
  56. 	}
  57. 	else {					/* both alive, put them back */
  58. 	    if (cansee(dx, dy))
  59. 		pline("%s is regurgitated!", Monnam(mdef));
  60.  
  61. 	    place_monster(magr, ax, ay);
  62. 	    place_monster(mdef, dx, dy);
  63. 	    newsym(ax, ay);
  64. 	    newsym(dx, dy);
  65. 	}
  66.  
  67. 	return status;
  68. }

explmm

  1. STATIC_OVL int
  2. explmm(magr, mdef, mattk)
  3. 	register struct monst *magr, *mdef;
  4. 	register struct	attack *mattk;
  5. {
  6. 	int result;
  7.  
  8. 	if (magr->mcan)
  9. 	    return MM_MISS;
  10.  
  11. 	if(cansee(magr->mx, magr->my))
  12. 		pline("%s explodes!", Monnam(magr));
  13. 	else	noises(magr, mattk);
  14.  
  15. 	result = mdamagem(magr, mdef, mattk);
  16.  
  17. 	/* Kill off agressor if it didn't die. */
  18. 	if (!(result & MM_AGR_DIED)) {
  19. 	    mondead(magr);
  20. 	    if (magr->mhp > 0) return result;	/* life saved */
  21. 	    result |= MM_AGR_DIED;
  22. 	}
  23. 	if (magr->mtame)	/* give this one even if it was visible */
  24. 	    You(brief_feeling, "melancholy");
  25.  
  26. 	return result;
  27. }

mdamagem

  1. /*
  2. *  See comment at top of mattackm(), for return values.
  3. */
  4. STATIC_OVL int
  5. mdamagem(magr, mdef, mattk)
  6. 	register struct monst	*magr, *mdef;
  7. 	register struct attack	*mattk;
  8. {
  9. 	struct obj *obj;
  10. 	char buf[BUFSZ];
  11. 	struct permonst *pa = magr->data, *pd = mdef->data;
  12. 	int armpro, num, tmp = d((int)mattk->damn, (int)mattk->damd);
  13. 	boolean cancelled;
  14.  
  15. 	if (touch_petrifies(pd) && !resists_ston(magr)) {
  16. 	    long protector = attk_protection((int)mattk->aatyp),
  17. 		 wornitems = magr->misc_worn_check;
  18.  
  19. 	    /* wielded weapon gives same protection as gloves here */
  20. 	    if (otmp != 0) wornitems |= W_ARMG;
  21.  
  22. 	    if (protector == 0L ||
  23. 		  (protector != ~0L && (wornitems & protector) != protector)) {
  24. 		if (poly_when_stoned(pa)) {
  25. 		    mon_to_stone(magr);
  26. 		    return MM_HIT; /* no damage during the polymorph */
  27. 		}
  28. 		if (vis) pline("%s turns to stone!", Monnam(magr));
  29. 		monstone(magr);
  30. 		if (magr->mhp > 0) return 0;
  31. 		else if (magr->mtame && !vis)
  32. 		    You(brief_feeling, "peculiarly sad");
  33. 		return MM_AGR_DIED;
  34. 	    }
  35. 	}
  36.  
  37. 	/* cancellation factor is the same as when attacking the hero */
  38. 	armpro = magic_negation(mdef);
  39. 	cancelled = magr->mcan || !((rn2(3) >= armpro) || !rn2(50));
  40.  
  41. 	switch(mattk->adtyp) {
  42. 	    case AD_DGST:
  43. 		/* eating a Rider or its corpse is fatal */
  44. 		if (is_rider(mdef->data)) {
  45. 		    if (vis)
  46. 			pline("%s %s!", Monnam(magr),
  47. 			      mdef->data == &mons[PM_FAMINE] ?
  48. 				"belches feebly, shrivels up and dies" :
  49. 			      mdef->data == &mons[PM_PESTILENCE] ?
  50. 				"coughs spasmodically and collapses" :
  51. 				"vomits violently and drops dead");
  52. 		    mondied(magr);
  53. 		    if (magr->mhp > 0) return 0;	/* lifesaved */
  54. 		    else if (magr->mtame && !vis)
  55. 			You(brief_feeling, "queasy");
  56. 		    return MM_AGR_DIED;
  57. 		}
  58. 		if(flags.verbose && flags.soundok) verbalize("Burrrrp!");
  59. 		tmp = mdef->mhp;
  60. 		/* Use up amulet of life saving */
  61. 		if (!!(obj = mlifesaver(mdef))) m_useup(mdef, obj);
  62.  
  63. 		/* Is a corpse for nutrition possible?  It may kill magr */
  64. 		if (!corpse_chance(mdef, magr, TRUE) || magr->mhp < 1)
  65. 		    break;
  66.  
  67. 		/* Pets get nutrition from swallowing monster whole.
  68. 		 * No nutrition from G_NOCORPSE monster, eg, undead.
  69. 		 * DGST monsters don't die from undead corpses
  70. 		 */
  71. 		num = monsndx(mdef->data);
  72. 		if (magr->mtame && !magr->isminion &&
  73. 		    !(mvitals[num].mvflags & G_NOCORPSE)) {
  74. 		    struct obj *virtualcorpse = mksobj(CORPSE, FALSE, FALSE);
  75. 		    int nutrit;
  76.  
  77. 		    virtualcorpse->corpsenm = num;
  78. 		    virtualcorpse->owt = weight(virtualcorpse);
  79. 		    nutrit = dog_nutrition(magr, virtualcorpse);
  80. 		    dealloc_obj(virtualcorpse);
  81.  
  82. 		    /* only 50% nutrition, 25% of normal eating time */
  83. 		    if (magr->meating > 1) magr->meating = (magr->meating+3)/4;
  84. 		    if (nutrit > 1) nutrit /= 2;
  85. 		    EDOG(magr)->hungrytime += nutrit;
  86. 		}
  87. 		break;
  88. 	    case AD_STUN:
  89. 		if (magr->mcan) break;
  90. 		if (canseemon(mdef))
  91. 		    pline("%s %s for a moment.", Monnam(mdef),
  92. 			  makeplural(stagger(mdef->data, "stagger")));
  93. 		mdef->mstun = 1;
  94. 		goto physical;
  95. 	    case AD_LEGS:
  96. 		if (magr->mcan) {
  97. 		    tmp = 0;
  98. 		    break;
  99. 		}
  100. 		goto physical;
  101. 	    case AD_WERE:
  102. 	    case AD_HEAL:
  103. 	    case AD_PHYS:
  104. physical:
  105. 		if (mattk->aatyp == AT_KICK && thick_skinned(pd)) {
  106. 		    tmp = 0;
  107. 		} else if(mattk->aatyp == AT_WEAP) {
  108. 		    if(otmp) {
  109. 			if (otmp->otyp == CORPSE &&
  110. 				touch_petrifies(&mons[otmp->corpsenm]))
  111. 			    goto do_stone;
  112. 			tmp += dmgval(otmp, mdef);
  113. 			if (otmp->oartifact) {
  114. 			    (void)artifact_hit(magr,mdef, otmp, &tmp, dieroll);
  115. 			    if (mdef->mhp <= 0)
  116. 				return (MM_DEF_DIED |
  117. 					(grow_up(magr,mdef) ? 0 : MM_AGR_DIED));
  118. 			}
  119. 			if (tmp)
  120. 				mrustm(magr, mdef, otmp);
  121. 		    }
  122. 		} else if (magr->data == &mons[PM_PURPLE_WORM] &&
  123. 			    mdef->data == &mons[PM_SHRIEKER]) {
  124. 		    /* hack to enhance mm_aggression(); we don't want purple
  125. 		       worm's bite attack to kill a shrieker because then it
  126. 		       won't swallow the corpse; but if the target survives,
  127. 		       the subsequent engulf attack should accomplish that */
  128. 		    if (tmp >= mdef->mhp) tmp = mdef->mhp - 1;
  129. 		}
  130. 		break;
  131. 	    case AD_FIRE:
  132. 		if (cancelled) {
  133. 		    tmp = 0;
  134. 		    break;
  135. 		}
  136. 		if (vis)
  137. 		    pline("%s is %s!", Monnam(mdef),
  138. 			  on_fire(mdef->data, mattk));
  139. 		if (pd == &mons[PM_STRAW_GOLEM] ||
  140. 		    pd == &mons[PM_PAPER_GOLEM]) {
  141. 			if (vis) pline("%s burns completely!", Monnam(mdef));
  142. 			mondied(mdef);
  143. 			if (mdef->mhp > 0) return 0;
  144. 			else if (mdef->mtame && !vis)
  145. 			    pline("May %s roast in peace.", mon_nam(mdef));
  146. 			return (MM_DEF_DIED | (grow_up(magr,mdef) ?
  147. 							0 : MM_AGR_DIED));
  148. 		}
  149. 		tmp += destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
  150. 		tmp += destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
  151. 		if (resists_fire(mdef)) {
  152. 		    if (vis)
  153. 			pline_The("fire doesn't seem to burn %s!",
  154. 								mon_nam(mdef));
  155. 		    shieldeff(mdef->mx, mdef->my);
  156. 		    golemeffects(mdef, AD_FIRE, tmp);
  157. 		    tmp = 0;
  158. 		}
  159. 		/* only potions damage resistant players in destroy_item */
  160. 		tmp += destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
  161. 		break;
  162. 	    case AD_COLD:
  163. 		if (cancelled) {
  164. 		    tmp = 0;
  165. 		    break;
  166. 		}
  167. 		if (vis) pline("%s is covered in frost!", Monnam(mdef));
  168. 		if (resists_cold(mdef)) {
  169. 		    if (vis)
  170. 			pline_The("frost doesn't seem to chill %s!",
  171. 								mon_nam(mdef));
  172. 		    shieldeff(mdef->mx, mdef->my);
  173. 		    golemeffects(mdef, AD_COLD, tmp);
  174. 		    tmp = 0;
  175. 		}
  176. 		tmp += destroy_mitem(mdef, POTION_CLASS, AD_COLD);
  177. 		break;
  178. 	    case AD_ELEC:
  179. 		if (cancelled) {
  180. 		    tmp = 0;
  181. 		    break;
  182. 		}
  183. 		if (vis) pline("%s gets zapped!", Monnam(mdef));
  184. 		tmp += destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
  185. 		if (resists_elec(mdef)) {
  186. 		    if (vis) pline_The("zap doesn't shock %s!", mon_nam(mdef));
  187. 		    shieldeff(mdef->mx, mdef->my);
  188. 		    golemeffects(mdef, AD_ELEC, tmp);
  189. 		    tmp = 0;
  190. 		}
  191. 		/* only rings damage resistant players in destroy_item */
  192. 		tmp += destroy_mitem(mdef, RING_CLASS, AD_ELEC);
  193. 		break;
  194. 	    case AD_ACID:
  195. 		if (magr->mcan) {
  196. 		    tmp = 0;
  197. 		    break;
  198. 		}
  199. 		if (resists_acid(mdef)) {
  200. 		    if (vis)
  201. 			pline("%s is covered in acid, but it seems harmless.",
  202. 			      Monnam(mdef));
  203. 		    tmp = 0;
  204. 		} else if (vis) {
  205. 		    pline("%s is covered in acid!", Monnam(mdef));
  206. 		    pline("It burns %s!", mon_nam(mdef));
  207. 		}
  208. 		if (!rn2(30)) erode_armor(mdef, TRUE);
  209. 		if (!rn2(6)) erode_obj(MON_WEP(mdef), TRUE, TRUE);
  210. 		break;
  211. 	    case AD_RUST:
  212. 		if (magr->mcan) break;
  213. 		if (pd == &mons[PM_IRON_GOLEM]) {
  214. 			if (vis) pline("%s falls to pieces!", Monnam(mdef));
  215. 			mondied(mdef);
  216. 			if (mdef->mhp > 0) return 0;
  217. 			else if (mdef->mtame && !vis)
  218. 			    pline("May %s rust in peace.", mon_nam(mdef));
  219. 			return (MM_DEF_DIED | (grow_up(magr,mdef) ?
  220. 							0 : MM_AGR_DIED));
  221. 		}
  222. 		hurtmarmor(mdef, AD_RUST);
  223. 		mdef->mstrategy &= ~STRAT_WAITFORU;
  224. 		tmp = 0;
  225. 		break;
  226. 	    case AD_CORR:
  227. 		if (magr->mcan) break;
  228. 		hurtmarmor(mdef, AD_CORR);
  229. 		mdef->mstrategy &= ~STRAT_WAITFORU;
  230. 		tmp = 0;
  231. 		break;
  232. 	    case AD_DCAY:
  233. 		if (magr->mcan) break;
  234. 		if (pd == &mons[PM_WOOD_GOLEM] ||
  235. 		    pd == &mons[PM_LEATHER_GOLEM]) {
  236. 			if (vis) pline("%s falls to pieces!", Monnam(mdef));
  237. 			mondied(mdef);
  238. 			if (mdef->mhp > 0) return 0;
  239. 			else if (mdef->mtame && !vis)
  240. 			    pline("May %s rot in peace.", mon_nam(mdef));
  241. 			return (MM_DEF_DIED | (grow_up(magr,mdef) ?
  242. 							0 : MM_AGR_DIED));
  243. 		}
  244. 		hurtmarmor(mdef, AD_DCAY);
  245. 		mdef->mstrategy &= ~STRAT_WAITFORU;
  246. 		tmp = 0;
  247. 		break;
  248. 	    case AD_STON:
  249. 		if (magr->mcan) break;
  250. do_stone:
  251. 		/* may die from the acid if it eats a stone-curing corpse */
  252. 		if (munstone(mdef, FALSE)) goto post_stone;
  253. 		if (poly_when_stoned(pd)) {
  254. 			mon_to_stone(mdef);
  255. 			tmp = 0;
  256. 			break;
  257. 		}
  258. 		if (!resists_ston(mdef)) {
  259. 			if (vis) pline("%s turns to stone!", Monnam(mdef));
  260. 			monstone(mdef);
  261. post_stone:		if (mdef->mhp > 0) return 0;
  262. 			else if (mdef->mtame && !vis)
  263. 			    You(brief_feeling, "peculiarly sad");
  264. 			return (MM_DEF_DIED | (grow_up(magr,mdef) ?
  265. 							0 : MM_AGR_DIED));
  266. 		}
  267. 		tmp = (mattk->adtyp == AD_STON ? 0 : 1);
  268. 		break;
  269. 	    case AD_TLPT:
  270. 		if (!cancelled && tmp < mdef->mhp && !tele_restrict(mdef)) {
  271. 		    char mdef_Monnam[BUFSZ];
  272. 		    /* save the name before monster teleports, otherwise
  273. 		       we'll get "it" in the suddenly disappears message */
  274. 		    if (vis) Strcpy(mdef_Monnam, Monnam(mdef));
  275. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  276. 		    (void) rloc(mdef, FALSE);
  277. 		    if (vis && !canspotmon(mdef)
  278. #ifdef STEED
  279. 		    	&& mdef != u.usteed
  280. #endif
  281. 		    	)
  282. 			pline("%s suddenly disappears!", mdef_Monnam);
  283. 		}
  284. 		break;
  285. 	    case AD_SLEE:
  286. 		if (!cancelled && !mdef->msleeping &&
  287. 			sleep_monst(mdef, rnd(10), -1)) {
  288. 		    if (vis) {
  289. 			Strcpy(buf, Monnam(mdef));
  290. 			pline("%s is put to sleep by %s.", buf, mon_nam(magr));
  291. 		    }
  292. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  293. 		    slept_monst(mdef);
  294. 		}
  295. 		break;
  296. 	    case AD_PLYS:
  297. 		if(!cancelled && mdef->mcanmove) {
  298. 		    if (vis) {
  299. 			Strcpy(buf, Monnam(mdef));
  300. 			pline("%s is frozen by %s.", buf, mon_nam(magr));
  301. 		    }
  302. 		    mdef->mcanmove = 0;
  303. 		    mdef->mfrozen = rnd(10);
  304. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  305. 		}
  306. 		break;
  307. 	    case AD_SLOW:
  308. 		if (!cancelled && mdef->mspeed != MSLOW) {
  309. 		    unsigned int oldspeed = mdef->mspeed;
  310.  
  311. 		    mon_adjust_speed(mdef, -1, (struct obj *)0);
  312. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  313. 		    if (mdef->mspeed != oldspeed && vis)
  314. 			pline("%s slows down.", Monnam(mdef));
  315. 		}
  316. 		break;
  317. 	    case AD_CONF:
  318. 		/* Since confusing another monster doesn't have a real time
  319. 		 * limit, setting spec_used would not really be right (though
  320. 		 * we still should check for it).
  321. 		 */
  322. 		if (!magr->mcan && !mdef->mconf && !magr->mspec_used) {
  323. 		    if (vis) pline("%s looks confused.", Monnam(mdef));
  324. 		    mdef->mconf = 1;
  325. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  326. 		}
  327. 		break;
  328. 	    case AD_BLND:
  329. 		if (can_blnd(magr, mdef, mattk->aatyp, (struct obj*)0)) {
  330. 		    register unsigned rnd_tmp;
  331.  
  332. 		    if (vis && mdef->mcansee)
  333. 			pline("%s is blinded.", Monnam(mdef));
  334. 		    rnd_tmp = d((int)mattk->damn, (int)mattk->damd);
  335. 		    if ((rnd_tmp += mdef->mblinded) > 127) rnd_tmp = 127;
  336. 		    mdef->mblinded = rnd_tmp;
  337. 		    mdef->mcansee = 0;
  338. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  339. 		}
  340. 		tmp = 0;
  341. 		break;
  342. 	    case AD_HALU:
  343. 		if (!magr->mcan && haseyes(pd) && mdef->mcansee) {
  344. 		    if (vis) pline("%s looks %sconfused.",
  345. 				    Monnam(mdef), mdef->mconf ? "more " : "");
  346. 		    mdef->mconf = 1;
  347. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  348. 		}
  349. 		tmp = 0;
  350. 		break;
  351. 	    case AD_CURS:
  352. 		if (!night() && (pa == &mons[PM_GREMLIN])) break;
  353. 		if (!magr->mcan && !rn2(10)) {
  354. 		    mdef->mcan = 1;	/* cancelled regardless of lifesave */
  355. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  356. 		    if (is_were(pd) && pd->mlet != S_HUMAN)
  357. 			were_change(mdef);
  358. 		    if (pd == &mons[PM_CLAY_GOLEM]) {
  359. 			    if (vis) {
  360. 				pline("Some writing vanishes from %s head!",
  361. 				    s_suffix(mon_nam(mdef)));
  362. 				pline("%s is destroyed!", Monnam(mdef));
  363. 			    }
  364. 			    mondied(mdef);
  365. 			    if (mdef->mhp > 0) return 0;
  366. 			    else if (mdef->mtame && !vis)
  367. 				You(brief_feeling, "strangely sad");
  368. 			    return (MM_DEF_DIED | (grow_up(magr,mdef) ?
  369. 							0 : MM_AGR_DIED));
  370. 		    }
  371. 		    if (flags.soundok) {
  372. 			    if (!vis) You_hear("laughter.");
  373. 			    else pline("%s chuckles.", Monnam(magr));
  374. 		    }
  375. 		}
  376. 		break;
  377. 	    case AD_SGLD:
  378. 		tmp = 0;
  379. #ifndef GOLDOBJ
  380. 		if (magr->mcan || !mdef->mgold) break;
  381. 		/* technically incorrect; no check for stealing gold from
  382. 		 * between mdef's feet...
  383. 		 */
  384. 		magr->mgold += mdef->mgold;
  385. 		mdef->mgold = 0;
  386. #else
  387. if (magr->mcan) break;
  388. 		/* technically incorrect; no check for stealing gold from
  389. 		 * between mdef's feet...
  390. 		 */
  391. {
  392. 		    struct obj *gold = findgold(mdef->minvent);
  393. 		    if (!gold) break;
  394. obj_extract_self(gold);
  395. 		    add_to_minv(magr, gold);
  396. }
  397. #endif
  398. 		mdef->mstrategy &= ~STRAT_WAITFORU;
  399. 		if (vis) {
  400. 		    Strcpy(buf, Monnam(magr));
  401. 		    pline("%s steals some gold from %s.", buf, mon_nam(mdef));
  402. 		}
  403. 		if (!tele_restrict(magr)) {
  404. 		    (void) rloc(magr, FALSE);
  405. 		    if (vis && !canspotmon(magr))
  406. 			pline("%s suddenly disappears!", buf);
  407. 		}
  408. 		break;
  409. 	    case AD_DRLI:
  410. 		if (!cancelled && !rn2(3) && !resists_drli(mdef)) {
  411. 			tmp = d(2,6);
  412. 			if (vis)
  413. 			    pline("%s suddenly seems weaker!", Monnam(mdef));
  414. 			mdef->mhpmax -= tmp;
  415. 			if (mdef->m_lev == 0)
  416. 				tmp = mdef->mhp;
  417. 			else mdef->m_lev--;
  418. 			/* Automatic kill if drained past level 0 */
  419. 		}
  420. 		break;
  421. #ifdef SEDUCE
  422. 	    case AD_SSEX:
  423. #endif
  424. 	    case AD_SITM:	/* for now these are the same */
  425. 	    case AD_SEDU:
  426. 		if (magr->mcan) break;
  427. 		/* find an object to steal, non-cursed if magr is tame */
  428. 		for (obj = mdef->minvent; obj; obj = obj->nobj)
  429. 		    if (!magr->mtame || !obj->cursed)
  430. 			break;
  431.  
  432. 		if (obj) {
  433. 			char onambuf[BUFSZ], mdefnambuf[BUFSZ];
  434.  
  435. 			/* make a special x_monnam() call that never omits
  436. 			   the saddle, and save it for later messages */
  437. 			Strcpy(mdefnambuf, x_monnam(mdef, ARTICLE_THE, (char *)0, 0, FALSE));
  438.  
  439. 			otmp = obj;
  440. #ifdef STEED
  441. 			if (u.usteed == mdef &&
  442. 					otmp == which_armor(mdef, W_SADDLE))
  443. 				/* "You can no longer ride <steed>." */
  444. 				dismount_steed(DISMOUNT_POLY);
  445. #endif
  446. 			obj_extract_self(otmp);
  447. 			if (otmp->owornmask) {
  448. 				mdef->misc_worn_check &= ~otmp->owornmask;
  449. 				if (otmp->owornmask & W_WEP)
  450. 				    setmnotwielded(mdef,otmp);
  451. 				otmp->owornmask = 0L;
  452. 				update_mon_intrinsics(mdef, otmp, FALSE, FALSE);
  453. 			}
  454. 			/* add_to_minv() might free otmp [if it merges] */
  455. 			if (vis)
  456. 				Strcpy(onambuf, doname(otmp));
  457. 			(void) add_to_minv(magr, otmp);
  458. 			if (vis) {
  459. 				Strcpy(buf, Monnam(magr));
  460. 				pline("%s steals %s from %s!", buf,
  461. 				    onambuf, mdefnambuf);
  462. 			}
  463. 			possibly_unwield(mdef, FALSE);
  464. 			mdef->mstrategy &= ~STRAT_WAITFORU;
  465. 			mselftouch(mdef, (const char *)0, FALSE);
  466. 			if (mdef->mhp <= 0)
  467. 				return (MM_DEF_DIED | (grow_up(magr,mdef) ?
  468. 							0 : MM_AGR_DIED));
  469. 			if (magr->data->mlet == S_NYMPH &&
  470. 			    !tele_restrict(magr)) {
  471. 			    (void) rloc(magr, FALSE);
  472. 			    if (vis && !canspotmon(magr))
  473. 				pline("%s suddenly disappears!", buf);
  474. 			}
  475. 		}
  476. 		tmp = 0;
  477. 		break;
  478. 	    case AD_DRST:
  479. 	    case AD_DRDX:
  480. 	    case AD_DRCO:
  481. 		if (!cancelled && !rn2(8)) {
  482. 		    if (vis)
  483. 			pline("%s %s was poisoned!", s_suffix(Monnam(magr)),
  484. 			      mpoisons_subj(magr, mattk));
  485. 		    if (resists_poison(mdef)) {
  486. 			if (vis)
  487. 			    pline_The("poison doesn't seem to affect %s.",
  488. 				mon_nam(mdef));
  489. 		    } else {
  490. 			if (rn2(10)) tmp += rn1(10,6);
  491. 			else {
  492. 			    if (vis) pline_The("poison was deadly...");
  493. 			    tmp = mdef->mhp;
  494. 			}
  495. 		    }
  496. 		}
  497. 		break;
  498. 	    case AD_DRIN:
  499. 		if (notonhead || !has_head(pd)) {
  500. 		    if (vis) pline("%s doesn't seem harmed.", Monnam(mdef));
  501. 		    /* Not clear what to do for green slimes */
  502. 		    tmp = 0;
  503. 		    break;
  504. 		}
  505. 		if ((mdef->misc_worn_check & W_ARMH) && rn2(8)) {
  506. 		    if (vis) {
  507. 			Strcpy(buf, s_suffix(Monnam(mdef)));
  508. 			pline("%s helmet blocks %s attack to %s head.",
  509. 				buf, s_suffix(mon_nam(magr)),
  510. 				mhis(mdef));
  511. 		    }
  512. 		    break;
  513. 		}
  514. 		if (vis) pline("%s brain is eaten!", s_suffix(Monnam(mdef)));
  515. 		if (mindless(pd)) {
  516. 		    if (vis) pline("%s doesn't notice.", Monnam(mdef));
  517. 		    break;
  518. 		}
  519. 		tmp += rnd(10); /* fakery, since monsters lack INT scores */
  520. 		if (magr->mtame && !magr->isminion) {
  521. 		    EDOG(magr)->hungrytime += rnd(60);
  522. 		    magr->mconf = 0;
  523. 		}
  524. 		if (tmp >= mdef->mhp && vis)
  525. 		    pline("%s last thought fades away...",
  526. 			          s_suffix(Monnam(mdef)));
  527. 		break;
  528. 	    case AD_SLIM:
  529. 		if (cancelled) break;	/* physical damage only */
  530. 		if (!rn2(4) && !flaming(mdef->data) &&
  531. 				mdef->data != &mons[PM_GREEN_SLIME]) {
  532. 		    (void) newcham(mdef, &mons[PM_GREEN_SLIME], FALSE, vis);
  533. 		    mdef->mstrategy &= ~STRAT_WAITFORU;
  534. 		    tmp = 0;
  535. 		}
  536. 		break;
  537. 	    case AD_STCK:
  538. 		if (cancelled) tmp = 0;
  539. 		break;
  540. 	    case AD_WRAP: /* monsters cannot grab one another, it's too hard */
  541. 		if (magr->mcan) tmp = 0;
  542. 		break;
  543. 	    case AD_ENCH:
  544. 		/* there's no msomearmor() function, so just do damage */
  545. 	     /* if (cancelled) break; */
  546. 		break;
  547. 	    default:	tmp = 0;
  548. 			break;
  549. 	}
  550. 	if(!tmp) return(MM_MISS);
  551.  
  552. 	if((mdef->mhp -= tmp) < 1) {
  553. 	    if (m_at(mdef->mx, mdef->my) == magr) {  /* see gulpmm() */
  554. 		remove_monster(mdef->mx, mdef->my);
  555. 		mdef->mhp = 1;	/* otherwise place_monster will complain */
  556. 		place_monster(mdef, mdef->mx, mdef->my);
  557. 		mdef->mhp = 0;
  558. 	    }
  559. 	    monkilled(mdef, "", (int)mattk->adtyp);
  560. 	    if (mdef->mhp > 0) return 0; /* mdef lifesaved */
  561.  
  562. 	    if (mattk->adtyp == AD_DGST) {
  563. 		/* various checks similar to dog_eat and meatobj.
  564. 		 * after monkilled() to provide better message ordering */
  565. 		if (mdef->cham != CHAM_ORDINARY) {
  566. 		    (void) newcham(magr, (struct permonst *)0, FALSE, TRUE);
  567. 		} else if (mdef->data == &mons[PM_GREEN_SLIME]) {
  568. 		    (void) newcham(magr, &mons[PM_GREEN_SLIME], FALSE, TRUE);
  569. 		} else if (mdef->data == &mons[PM_WRAITH]) {
  570. 		    (void) grow_up(magr, (struct monst *)0);
  571. 		    /* don't grow up twice */
  572. 		    return (MM_DEF_DIED | (magr->mhp > 0 ? 0 : MM_AGR_DIED));
  573. 		} else if (mdef->data == &mons[PM_NURSE]) {
  574. 		    magr->mhp = magr->mhpmax;
  575. 		}
  576. 	    }
  577.  
  578. 	    return (MM_DEF_DIED | (grow_up(magr,mdef) ? 0 : MM_AGR_DIED));
  579. 	}
  580. 	return(MM_HIT);
  581. }
  582.  
  583. #endif /* OVLB */

noattacks

  1. #ifdef OVL0
  2.  
  3. int
  4. noattacks(ptr)			/* returns 1 if monster doesn't attack */
  5. 	struct	permonst *ptr;
  6. {
  7. 	int i;
  8.  
  9. 	for(i = 0; i < NATTK; i++)
  10. 		if(ptr->mattk[i].aatyp) return(0);
  11.  
  12. 	return(1);
  13. }

sleep_monst

  1. /* `mon' is hit by a sleep attack; return 1 if it's affected, 0 otherwise */
  2. int
  3. sleep_monst(mon, amt, how)
  4. struct monst *mon;
  5. int amt, how;
  6. {
  7. 	if (resists_sleep(mon) ||
  8. 		(how >= 0 && resist(mon, (char)how, 0, NOTELL))) {
  9. 	    shieldeff(mon->mx, mon->my);
  10. 	} else if (mon->mcanmove) {
  11. 	    amt += (int) mon->mfrozen;
  12. 	    if (amt > 0) {	/* sleep for N turns */
  13. 		mon->mcanmove = 0;
  14. 		mon->mfrozen = min(amt, 127);
  15. 	    } else {		/* sleep until awakened */
  16. 		mon->msleeping = 1;
  17. 	    }
  18. 	    return 1;
  19. 	}
  20. 	return 0;
  21. }

slept_monst

  1. /* sleeping grabber releases, engulfer doesn't; don't use for paralysis! */
  2. void
  3. slept_monst(mon)
  4. struct monst *mon;
  5. {
  6. 	if ((mon->msleeping || !mon->mcanmove) && mon == u.ustuck &&
  7. 		!sticks(youmonst.data) && !u.uswallow) {
  8. 	    pline("%s grip relaxes.", s_suffix(Monnam(mon)));
  9. 	    unstuck(mon);
  10. 	}
  11. }
  12.  
  13. #endif /* OVL0 */

mrustm

  1. #ifdef OVLB
  2.  
  3. STATIC_OVL void
  4. mrustm(magr, mdef, obj)
  5. register struct monst *magr, *mdef;
  6. register struct obj *obj;
  7. {
  8. 	boolean is_acid;
  9.  
  10. 	if (!magr || !mdef || !obj) return; /* just in case */
  11.  
  12. 	if (dmgtype(mdef->data, AD_CORR))
  13. 	    is_acid = TRUE;
  14. 	else if (dmgtype(mdef->data, AD_RUST))
  15. 	    is_acid = FALSE;
  16. 	else
  17. 	    return;
  18.  
  19. 	if (!mdef->mcan &&
  20. 	    (is_acid ? is_corrodeable(obj) : is_rustprone(obj)) &&
  21. 	    (is_acid ? obj->oeroded2 : obj->oeroded) < MAX_ERODE) {
  22. 		if (obj->greased || obj->oerodeproof || (obj->blessed && rn2(3))) {
  23. 		    if (cansee(mdef->mx, mdef->my) && flags.verbose)
  24. 			pline("%s weapon is not affected.",
  25. 			                 s_suffix(Monnam(magr)));
  26. 		    if (obj->greased && !rn2(2)) obj->greased = 0;
  27. 		} else {
  28. 		    if (cansee(mdef->mx, mdef->my)) {
  29. 			pline("%s %s%s!", s_suffix(Monnam(magr)),
  30. 			    aobjnam(obj, (is_acid ? "corrode" : "rust")),
  31. 			    (is_acid ? obj->oeroded2 : obj->oeroded)
  32. 				? " further" : "");
  33. 		    }
  34. 		    if (is_acid) obj->oeroded2++;
  35. 		    else obj->oeroded++;
  36. 		}
  37. 	}
  38. }

mswingsm

  1. STATIC_OVL void
  2. mswingsm(magr, mdef, otemp)
  3. register struct monst *magr, *mdef;
  4. register struct obj *otemp;
  5. {
  6. 	char buf[BUFSZ];
  7. 	if (!flags.verbose || Blind || !mon_visible(magr)) return;
  8. 	Strcpy(buf, mon_nam(mdef));
  9. 	pline("%s %s %s %s at %s.", Monnam(magr),
  10. 	      (objects[otemp->otyp].oc_dir & PIERCE) ? "thrusts" : "swings",
  11. 	      mhis(magr), singular(otemp, xname), buf);
  12. }

passivemm

  1. /*
  2. * Passive responses by defenders.  Does not replicate responses already
  3. * handled above.  Returns same values as mattackm.
  4. */
  5. STATIC_OVL int
  6. passivemm(magr,mdef,mhit,mdead)
  7. register struct monst *magr, *mdef;
  8. boolean mhit;
  9. int mdead;
  10. {
  11. 	register struct permonst *mddat = mdef->data;
  12. 	register struct permonst *madat = magr->data;
  13. 	char buf[BUFSZ];
  14. 	int i, tmp;
  15.  
  16. 	for(i = 0; ; i++) {
  17. 	    if(i >= NATTK) return (mdead | mhit); /* no passive attacks */
  18. 	    if(mddat->mattk[i].aatyp == AT_NONE) break;
  19. 	}
  20. 	if (mddat->mattk[i].damn)
  21. 	    tmp = d((int)mddat->mattk[i].damn,
  22. 				    (int)mddat->mattk[i].damd);
  23. 	else if(mddat->mattk[i].damd)
  24. 	    tmp = d((int)mddat->mlevel+1, (int)mddat->mattk[i].damd);
  25. 	else
  26. 	    tmp = 0;
  27.  
  28. 	/* These affect the enemy even if defender killed */
  29. 	switch(mddat->mattk[i].adtyp) {
  30. 	    case AD_ACID:
  31. 		if (mhit && !rn2(2)) {
  32. 		    Strcpy(buf, Monnam(magr));
  33. 		    if(canseemon(magr))
  34. 			pline("%s is splashed by %s acid!",
  35. 			      buf, s_suffix(mon_nam(mdef)));
  36. 		    if (resists_acid(magr)) {
  37. 			if(canseemon(magr))
  38. 			    pline("%s is not affected.", Monnam(magr));
  39. 			tmp = 0;
  40. 		    }
  41. 		} else tmp = 0;
  42. 		goto assess_dmg;
  43. 	    case AD_ENCH:	/* KMH -- remove enchantment (disenchanter) */
  44. 		if (mhit && !mdef->mcan && otmp) {
  45. 		    (void) drain_item(otmp);
  46. 		    /* No message */
  47. 		}
  48. 		break;
  49. 	    default:
  50. 		break;
  51. 	}
  52. 	if (mdead || mdef->mcan) return (mdead|mhit);
  53.  
  54. 	/* These affect the enemy only if defender is still alive */
  55. 	if (rn2(3)) switch(mddat->mattk[i].adtyp) {
  56. 	    case AD_PLYS: /* Floating eye */
  57. 		if (tmp > 127) tmp = 127;
  58. 		if (mddat == &mons[PM_FLOATING_EYE]) {
  59. 		    if (!rn2(4)) tmp = 127;
  60. 		    if (magr->mcansee && haseyes(madat) && mdef->mcansee &&
  61. 			(perceives(madat) || !mdef->minvis)) {
  62. 			Sprintf(buf, "%s gaze is reflected by %%s %%s.",
  63. 				s_suffix(mon_nam(mdef)));
  64. 			if (mon_reflects(magr,
  65. 					 canseemon(magr) ? buf : (char *)0))
  66. 				return(mdead|mhit);
  67. 			Strcpy(buf, Monnam(magr));
  68. 			if(canseemon(magr))
  69. 			    pline("%s is frozen by %s gaze!",
  70. 				  buf, s_suffix(mon_nam(mdef)));
  71. 			magr->mcanmove = 0;
  72. 			magr->mfrozen = tmp;
  73. 			return (mdead|mhit);
  74. 		    }
  75. 		} else { /* gelatinous cube */
  76. 		    Strcpy(buf, Monnam(magr));
  77. 		    if(canseemon(magr))
  78. 			pline("%s is frozen by %s.", buf, mon_nam(mdef));
  79. 		    magr->mcanmove = 0;
  80. 		    magr->mfrozen = tmp;
  81. 		    return (mdead|mhit);
  82. 		}
  83. 		return 1;
  84. 	    case AD_COLD:
  85. 		if (resists_cold(magr)) {
  86. 		    if (canseemon(magr)) {
  87. 			pline("%s is mildly chilly.", Monnam(magr));
  88. 			golemeffects(magr, AD_COLD, tmp);
  89. 		    }
  90. 		    tmp = 0;
  91. 		    break;
  92. 		}
  93. 		if(canseemon(magr))
  94. 		    pline("%s is suddenly very cold!", Monnam(magr));
  95. 		mdef->mhp += tmp / 2;
  96. 		if (mdef->mhpmax < mdef->mhp) mdef->mhpmax = mdef->mhp;
  97. 		if (mdef->mhpmax > ((int) (mdef->m_lev+1) * 8))
  98. 		    (void)split_mon(mdef, magr);
  99. 		break;
  100. 	    case AD_STUN:
  101. 		if (!magr->mstun) {
  102. 		    magr->mstun = 1;
  103. 		    if (canseemon(magr))
  104. 			pline("%s %s...", Monnam(magr),
  105. 			      makeplural(stagger(magr->data, "stagger")));
  106. 		}
  107. 		tmp = 0;
  108. 		break;
  109. 	    case AD_FIRE:
  110. 		if (resists_fire(magr)) {
  111. 		    if (canseemon(magr)) {
  112. 			pline("%s is mildly warmed.", Monnam(magr));
  113. 			golemeffects(magr, AD_FIRE, tmp);
  114. 		    }
  115. 		    tmp = 0;
  116. 		    break;
  117. 		}
  118. 		if(canseemon(magr))
  119. 		    pline("%s is suddenly very hot!", Monnam(magr));
  120. 		break;
  121. 	    case AD_ELEC:
  122. 		if (resists_elec(magr)) {
  123. 		    if (canseemon(magr)) {
  124. 			pline("%s is mildly tingled.", Monnam(magr));
  125. 			golemeffects(magr, AD_ELEC, tmp);
  126. 		    }
  127. 		    tmp = 0;
  128. 		    break;
  129. 		}
  130. 		if(canseemon(magr))
  131. 		    pline("%s is jolted with electricity!", Monnam(magr));
  132. 		break;
  133. 	    default: tmp = 0;
  134. 		break;
  135. 	}
  136. 	else tmp = 0;
  137.  
  138. assess_dmg:
  139. 	if((magr->mhp -= tmp) <= 0) {
  140. 		monkilled(magr, "", (int)mddat->mattk[i].adtyp);
  141. 		return (mdead | mhit | MM_AGR_DIED);
  142. 	}
  143. 	return (mdead | mhit);
  144. }

attk_protection

  1. /* "aggressive defense"; what type of armor prevents specified attack
  2. from touching its target? */
  3. long
  4. attk_protection(aatyp)
  5. int aatyp;
  6. {
  7. long w_mask = 0L;
  8.  
  9. switch (aatyp) {
  10. case AT_NONE:
  11. case AT_SPIT:
  12. case AT_EXPL:
  13. case AT_BOOM:
  14. case AT_GAZE:
  15. case AT_BREA:
  16. case AT_MAGC:
  17. 	w_mask = ~0L;		/* special case; no defense needed */
  18. 	break;
  19. case AT_CLAW:
  20. case AT_TUCH:
  21. case AT_WEAP:
  22. 	w_mask = W_ARMG;	/* caller needs to check for weapon */
  23. 	break;
  24. case AT_KICK:
  25. 	w_mask = W_ARMF;
  26. 	break;
  27. case AT_BUTT:
  28. 	w_mask = W_ARMH;
  29. 	break;
  30. case AT_HUGS:
  31. 	w_mask = (W_ARMC|W_ARMG); /* attacker needs both to be protected */
  32. 	break;
  33. case AT_BITE:
  34. case AT_STNG:
  35. case AT_ENGL:
  36. case AT_TENT:
  37. default:
  38. 	w_mask = 0L;		/* no defense available */
  39. 	break;
  40. }
  41. return w_mask;
  42. }
  43.  
  44. #endif /* OVLB */
  45.  
  46. /*mhitm.c*/