Source:NetHack 3.4.3/src/mthrowu.c

From NetHackWiki
(Redirected from Source:Mthrowu.c)
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)mthrowu.c	3.4	2003/05/09	*/
  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 int FDECL(drop_throw,(struct obj *,BOOLEAN_P,int,int));
  4.  
  5. #define URETREATING(x,y) (distmin(u.ux,u.uy,x,y) > distmin(u.ux0,u.uy0,x,y))
  6.  
  7. #define POLE_LIM 5	/* How far monsters can use pole-weapons */
  8.  
  9. #ifndef OVLB
  10.  
  11. STATIC_DCL const char *breathwep[];
  12.  
  13. #else /* OVLB */
  14.  
  15. /*
  16. * Keep consistent with breath weapons in zap.c, and AD_* in monattk.h.
  17. */
  18. STATIC_OVL NEARDATA const char *breathwep[] = {
  19. 				"fragments",
  20. 				"fire",
  21. 				"frost",
  22. 				"sleep gas",
  23. 				"a disintegration blast",
  24. 				"lightning",
  25. 				"poison gas",
  26. 				"acid",
  27. 				"strange breath #8",
  28. 				"strange breath #9"
  29. };

thitu[edit]

  1. /* hero is hit by something other than a monster */
  2. int
  3. thitu(tlev, dam, obj, name)
  4. int tlev, dam;
  5. struct obj *obj;
  6. const char *name;	/* if null, then format `obj' */
  7. {
  8. 	const char *onm, *knm;
  9. 	boolean is_acid;
  10. 	int kprefix = KILLED_BY_AN;
  11. 	char onmbuf[BUFSZ], knmbuf[BUFSZ];
  12.  
  13. 	if (!name) {
  14. 	    if (!obj) panic("thitu: name & obj both null?");
  15. 	    name = strcpy(onmbuf,
  16. 			 (obj->quan > 1L) ? doname(obj) : mshot_xname(obj));
  17. 	    knm = strcpy(knmbuf, killer_xname(obj));
  18. 	    kprefix = KILLED_BY;  /* killer_name supplies "an" if warranted */
  19. 	} else {
  20. 	    knm = name;
  21. 	    /* [perhaps ought to check for plural here to] */
  22. 	    if (!strncmpi(name, "the ", 4) ||
  23. 		    !strncmpi(name, "an ", 3) ||
  24. 		    !strncmpi(name, "a ", 2)) kprefix = KILLED_BY;
  25. 	}
  26. 	onm = (obj && obj_is_pname(obj)) ? the(name) :
  27. 			    (obj && obj->quan > 1L) ? name : an(name);
  28. 	is_acid = (obj && obj->otyp == ACID_VENOM);
  29.  
  30. 	if(u.uac + tlev <= rnd(20)) {
  31. 		if(Blind || !flags.verbose) pline("It misses.");
  32. 		else You("are almost hit by %s.", onm);
  33. 		return(0);
  34. 	} else {
  35. 		if(Blind || !flags.verbose) You("are hit!");
  36. 		else You("are hit by %s%s", onm, exclam(dam));
  37.  
  38. 		if (obj && objects[obj->otyp].oc_material == SILVER
  39. 				&& hates_silver(youmonst.data)) {
  40. 			dam += rnd(20);
  41. 			pline_The("silver sears your flesh!");
  42. 			exercise(A_CON, FALSE);
  43. 		}
  44. 		if (is_acid && Acid_resistance)
  45. 			pline("It doesn't seem to hurt you.");
  46. 		else {
  47. 			if (is_acid) pline("It burns!");
  48. 			if (Half_physical_damage) dam = (dam+1) / 2;
  49. 			losehp(dam, knm, kprefix);
  50. 			exercise(A_STR, FALSE);
  51. 		}
  52. 		return(1);
  53. 	}
  54. }

drop_throw[edit]

  1. /* Be sure this corresponds with what happens to player-thrown objects in
  2. * dothrow.c (for consistency). --KAA
  3. * Returns 0 if object still exists (not destroyed).
  4. */
  5.  
  6. STATIC_OVL int
  7. drop_throw(obj, ohit, x, y)
  8. register struct obj *obj;
  9. boolean ohit;
  10. int x,y;
  11. {
  12. 	int retvalu = 1;
  13. 	int create;
  14. 	struct monst *mtmp;
  15. 	struct trap *t;
  16.  
  17. 	if (obj->otyp == CREAM_PIE || obj->oclass == VENOM_CLASS ||
  18. 		    (ohit && obj->otyp == EGG))
  19. 		create = 0;
  20. 	else if (ohit && (is_multigen(obj) || obj->otyp == ROCK))
  21. 		create = !rn2(3);
  22. 	else create = 1;
  23.  
  24. 	if (create && !((mtmp = m_at(x, y)) && (mtmp->mtrapped) &&
  25. 			(t = t_at(x, y)) && ((t->ttyp == PIT) ||
  26. 			(t->ttyp == SPIKED_PIT)))) {
  27. 		int objgone = 0;
  28.  
  29. 		if (down_gate(x, y) != -1)
  30. 			objgone = ship_object(obj, x, y, FALSE);
  31. 		if (!objgone) {
  32. 			if (!flooreffects(obj,x,y,"fall")) { /* don't double-dip on damage */
  33. 			    place_object(obj, x, y);
  34. 			    if (!mtmp && x == u.ux && y == u.uy)
  35. 				mtmp = &youmonst;
  36. 			    if (mtmp && ohit)
  37. 				passive_obj(mtmp, obj, (struct attack *)0);
  38. 			    stackobj(obj);
  39. 			    retvalu = 0;
  40. 			}
  41. 		}
  42. 	} else obfree(obj, (struct obj*) 0);
  43. 	return retvalu;
  44. }
  45.  
  46. #endif /* OVLB */
  47. #ifdef OVL1

ohitmon[edit]

  1. /* an object launched by someone/thing other than player attacks a monster;
  2. return 1 if the object has stopped moving (hit or its range used up) */
  3. int
  4. ohitmon(mtmp, otmp, range, verbose)
  5. struct monst *mtmp;	/* accidental target */
  6. struct obj *otmp;	/* missile; might be destroyed by drop_throw */
  7. int range;		/* how much farther will object travel if it misses */
  8. 			/* Use -1 to signify to keep going even after hit, */
  9. 			/* unless its gone (used for rolling_boulder_traps) */
  10. boolean verbose;  /* give message(s) even when you can't see what happened */
  11. {
  12. 	int damage, tmp;
  13. 	boolean vis, ismimic;
  14. 	int objgone = 1;
  15.  
  16. 	ismimic = mtmp->m_ap_type && mtmp->m_ap_type != M_AP_MONSTER;
  17. 	vis = cansee(bhitpos.x, bhitpos.y);
  18.  
  19. 	tmp = 5 + find_mac(mtmp) + omon_adj(mtmp, otmp, FALSE);
  20. 	if (tmp < rnd(20)) {
  21. 	    if (!ismimic) {
  22. 		if (vis) miss(distant_name(otmp, mshot_xname), mtmp);
  23. 		else if (verbose) pline("It is missed.");
  24. 	    }
  25. 	    if (!range) { /* Last position; object drops */
  26. 		(void) drop_throw(otmp, 0, mtmp->mx, mtmp->my);
  27. 		return 1;
  28. 	    }
  29. 	} else if (otmp->oclass == POTION_CLASS) {
  30. 	    if (ismimic) seemimic(mtmp);
  31. 	    mtmp->msleeping = 0;
  32. 	    if (vis) otmp->dknown = 1;
  33. 	    potionhit(mtmp, otmp, FALSE);
  34. 	    return 1;
  35. 	} else {
  36. 	    damage = dmgval(otmp, mtmp);
  37. 	    if (otmp->otyp == ACID_VENOM && resists_acid(mtmp))
  38. 		damage = 0;
  39. 	    if (ismimic) seemimic(mtmp);
  40. 	    mtmp->msleeping = 0;
  41. 	    if (vis) hit(distant_name(otmp,mshot_xname), mtmp, exclam(damage));
  42. 	    else if (verbose) pline("%s is hit%s", Monnam(mtmp), exclam(damage));
  43.  
  44. 	    if (otmp->opoisoned && is_poisonable(otmp)) {
  45. 		if (resists_poison(mtmp)) {
  46. 		    if (vis) pline_The("poison doesn't seem to affect %s.",
  47. 				   mon_nam(mtmp));
  48. 		} else {
  49. 		    if (rn2(30)) {
  50. 			damage += rnd(6);
  51. 		    } else {
  52. 			if (vis) pline_The("poison was deadly...");
  53. 			damage = mtmp->mhp;
  54. 		    }
  55. 		}
  56. 	    }
  57. 	    if (objects[otmp->otyp].oc_material == SILVER &&
  58. 		    hates_silver(mtmp->data)) {
  59. 		if (vis) pline_The("silver sears %s flesh!",
  60. 				s_suffix(mon_nam(mtmp)));
  61. 		else if (verbose) pline("Its flesh is seared!");
  62. 	    }
  63. 	    if (otmp->otyp == ACID_VENOM && cansee(mtmp->mx,mtmp->my)) {
  64. 		if (resists_acid(mtmp)) {
  65. 		    if (vis || verbose)
  66. 			pline("%s is unaffected.", Monnam(mtmp));
  67. 		    damage = 0;
  68. 		} else {
  69. 		    if (vis) pline_The("acid burns %s!", mon_nam(mtmp));
  70. 		    else if (verbose) pline("It is burned!");
  71. 		}
  72. 	    }
  73. 	    mtmp->mhp -= damage;
  74. 	    if (mtmp->mhp < 1) {
  75. 		if (vis || verbose)
  76. 		    pline("%s is %s!", Monnam(mtmp),
  77. 			(nonliving(mtmp->data) || !canspotmon(mtmp))
  78. 			? "destroyed" : "killed");
  79. 		/* don't blame hero for unknown rolling boulder trap */
  80. 		if (!flags.mon_moving &&
  81. 		    (otmp->otyp != BOULDER || range >= 0 || !otmp->otrapped))
  82. 		    xkilled(mtmp,0);
  83. 		else mondied(mtmp);
  84. 	    }
  85.  
  86. 	    if (can_blnd((struct monst*)0, mtmp,
  87. 		    (uchar)(otmp->otyp == BLINDING_VENOM ? AT_SPIT : AT_WEAP),
  88. 		    otmp)) {
  89. 		if (vis && mtmp->mcansee)
  90. 		    pline("%s is blinded by %s.", Monnam(mtmp), the(xname(otmp)));
  91. 		mtmp->mcansee = 0;
  92. 		tmp = (int)mtmp->mblinded + rnd(25) + 20;
  93. 		if (tmp > 127) tmp = 127;
  94. 		mtmp->mblinded = tmp;
  95. 	    }
  96.  
  97. 	    objgone = drop_throw(otmp, 1, bhitpos.x, bhitpos.y);
  98. 	    if (!objgone && range == -1) {  /* special case */
  99. 		    obj_extract_self(otmp); /* free it for motion again */
  100. 		    return 0;
  101. 	    }
  102. 	    return 1;
  103. 	}
  104. 	return 0;
  105. }

m_throw[edit]

  1. void
  2. m_throw(mon, x, y, dx, dy, range, obj)
  3. 	register struct monst *mon;
  4. 	register int x,y,dx,dy,range;		/* direction and range */
  5. 	register struct obj *obj;
  6. {
  7. 	register struct monst *mtmp;
  8. 	struct obj *singleobj;
  9. 	char sym = obj->oclass;
  10. 	int hitu, blindinc = 0;
  11.  
  12. 	bhitpos.x = x;
  13. 	bhitpos.y = y;
  14.  
  15. 	if (obj->quan == 1L) {
  16. 	    /*
  17. 	     * Remove object from minvent.  This cannot be done later on;
  18. 	     * what if the player dies before then, leaving the monster
  19. 	     * with 0 daggers?  (This caused the infamous 2^32-1 orcish
  20. 	     * dagger bug).
  21. 	     *
  22. 	     * VENOM is not in minvent - it should already be OBJ_FREE.
  23. 	     * The extract below does nothing.
  24. 	     */
  25.  
  26. 	    /* not possibly_unwield, which checks the object's */
  27. 	    /* location, not its existence */
  28. 	    if (MON_WEP(mon) == obj) {
  29. 		    setmnotwielded(mon,obj);
  30. 		    MON_NOWEP(mon);
  31. 	    }
  32. 	    obj_extract_self(obj);
  33. 	    singleobj = obj;
  34. 	    obj = (struct obj *) 0;
  35. 	} else {
  36. 	    singleobj = splitobj(obj, 1L);
  37. 	    obj_extract_self(singleobj);
  38. 	}
  39.  
  40. 	singleobj->owornmask = 0; /* threw one of multiple weapons in hand? */
  41.  
  42. 	if (singleobj->cursed && (dx || dy) && !rn2(7)) {
  43. 	    if(canseemon(mon) && flags.verbose) {
  44. 		if(is_ammo(singleobj))
  45. 		    pline("%s misfires!", Monnam(mon));
  46. 		else
  47. 		    pline("%s as %s throws it!",
  48. 			  Tobjnam(singleobj, "slip"), mon_nam(mon));
  49. 	    }
  50. 	    dx = rn2(3)-1;
  51. 	    dy = rn2(3)-1;
  52. 	    /* check validity of new direction */
  53. 	    if (!dx && !dy) {
  54. 		(void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
  55. 		return;
  56. 	    }
  57. 	}
  58.  
  59. 	/* pre-check for doors, walls and boundaries.
  60. 	   Also need to pre-check for bars regardless of direction;
  61. 	   the random chance for small objects hitting bars is
  62. 	   skipped when reaching them at point blank range */
  63. 	if (!isok(bhitpos.x+dx,bhitpos.y+dy)
  64. 	    || IS_ROCK(levl[bhitpos.x+dx][bhitpos.y+dy].typ)
  65. 	    || closed_door(bhitpos.x+dx, bhitpos.y+dy)
  66. 	    || (levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS &&
  67. 		hits_bars(&singleobj, bhitpos.x, bhitpos.y, 0, 0))) {
  68. 	    (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
  69. 	    return;
  70. 	}
  71.  
  72. 	/* Note: drop_throw may destroy singleobj.  Since obj must be destroyed
  73. 	 * early to avoid the dagger bug, anyone who modifies this code should
  74. 	 * be careful not to use either one after it's been freed.
  75. 	 */
  76. 	if (sym) tmp_at(DISP_FLASH, obj_to_glyph(singleobj));
  77. 	while(range-- > 0) { /* Actually the loop is always exited by break */
  78. 		bhitpos.x += dx;
  79. 		bhitpos.y += dy;
  80. 		if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  81. 		    if (ohitmon(mtmp, singleobj, range, TRUE))
  82. 			break;
  83. 		} else if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
  84. 		    if (multi) nomul(0);
  85.  
  86. 		    if (singleobj->oclass == GEM_CLASS &&
  87. 			    singleobj->otyp <= LAST_GEM+9 /* 9 glass colors */
  88. 			    && is_unicorn(youmonst.data)) {
  89. 			if (singleobj->otyp > LAST_GEM) {
  90. 			    You("catch the %s.", xname(singleobj));
  91. 			    You("are not interested in %s junk.",
  92. 				s_suffix(mon_nam(mon)));
  93. 			    makeknown(singleobj->otyp);
  94. 			    dropy(singleobj);
  95. 			} else {
  96. 			    You("accept %s gift in the spirit in which it was intended.",
  97. 				s_suffix(mon_nam(mon)));
  98. 			    (void)hold_another_object(singleobj,
  99. 				"You catch, but drop, %s.", xname(singleobj),
  100. 				"You catch:");
  101. 			}
  102. 			break;
  103. 		    }
  104. 		    if (singleobj->oclass == POTION_CLASS) {
  105. 			if (!Blind) singleobj->dknown = 1;
  106. 			potionhit(&youmonst, singleobj, FALSE);
  107. 			break;
  108. 		    }
  109. 		    switch(singleobj->otyp) {
  110. 			int dam, hitv;
  111. 			case EGG:
  112. 			    if (!touch_petrifies(&mons[singleobj->corpsenm])) {
  113. 				impossible("monster throwing egg type %d",
  114. 					singleobj->corpsenm);
  115. 				hitu = 0;
  116. 				break;
  117. 			    }
  118. 			    /* fall through */
  119. 			case CREAM_PIE:
  120. 			case BLINDING_VENOM:
  121. 			    hitu = thitu(8, 0, singleobj, (char *)0);
  122. 			    break;
  123. 			default:
  124. 			    dam = dmgval(singleobj, &youmonst);
  125. 			    hitv = 3 - distmin(u.ux,u.uy, mon->mx,mon->my);
  126. 			    if (hitv < -4) hitv = -4;
  127. 			    if (is_elf(mon->data) &&
  128. 				objects[singleobj->otyp].oc_skill == P_BOW) {
  129. 				hitv++;
  130. 				if (MON_WEP(mon) &&
  131. 				    MON_WEP(mon)->otyp == ELVEN_BOW)
  132. 				    hitv++;
  133. 				if(singleobj->otyp == ELVEN_ARROW) dam++;
  134. 			    }
  135. 			    if (bigmonst(youmonst.data)) hitv++;
  136. 			    hitv += 8 + singleobj->spe;
  137. 			    if (dam < 1) dam = 1;
  138. 			    hitu = thitu(hitv, dam, singleobj, (char *)0);
  139. 		    }
  140. 		    if (hitu && singleobj->opoisoned &&
  141. 			is_poisonable(singleobj)) {
  142. 			char onmbuf[BUFSZ], knmbuf[BUFSZ];
  143.  
  144. 			Strcpy(onmbuf, xname(singleobj));
  145. 			Strcpy(knmbuf, killer_xname(singleobj));
  146. 			poisoned(onmbuf, A_STR, knmbuf, -10);
  147. 		    }
  148. 		    if(hitu &&
  149. 		       can_blnd((struct monst*)0, &youmonst,
  150. 				(uchar)(singleobj->otyp == BLINDING_VENOM ?
  151. 					AT_SPIT : AT_WEAP), singleobj)) {
  152. 			blindinc = rnd(25);
  153. 			if(singleobj->otyp == CREAM_PIE) {
  154. 			    if(!Blind) pline("Yecch!  You've been creamed.");
  155. 			    else pline("There's %s sticky all over your %s.",
  156. 				       something,
  157. 				       body_part(FACE));
  158. 			} else if(singleobj->otyp == BLINDING_VENOM) {
  159. 			    int num_eyes = eyecount(youmonst.data);
  160. 			    /* venom in the eyes */
  161. 			    if(!Blind) pline_The("venom blinds you.");
  162. 			    else Your("%s sting%s.",
  163. 				      (num_eyes == 1) ? body_part(EYE) :
  164. 						makeplural(body_part(EYE)),
  165. 				      (num_eyes == 1) ? "s" : "");
  166. 			}
  167. 		    }
  168. 		    if (hitu && singleobj->otyp == EGG) {
  169. 			if (!Stone_resistance
  170. 			    && !(poly_when_stoned(youmonst.data) &&
  171. 				 polymon(PM_STONE_GOLEM))) {
  172. 			    Stoned = 5;
  173. 			    killer = (char *) 0;
  174. 			}
  175. 		    }
  176. 		    stop_occupation();
  177. 		    if (hitu || !range) {
  178. 			(void) drop_throw(singleobj, hitu, u.ux, u.uy);
  179. 			break;
  180. 		    }
  181. 		} else if (!range	/* reached end of path */
  182. 			/* missile hits edge of screen */
  183. 			|| !isok(bhitpos.x+dx,bhitpos.y+dy)
  184. 			/* missile hits the wall */
  185. 			|| IS_ROCK(levl[bhitpos.x+dx][bhitpos.y+dy].typ)
  186. 			/* missile hit closed door */
  187. 			|| closed_door(bhitpos.x+dx, bhitpos.y+dy)
  188. 			/* missile might hit iron bars */
  189. 			|| (levl[bhitpos.x+dx][bhitpos.y+dy].typ == IRONBARS &&
  190. 			hits_bars(&singleobj, bhitpos.x, bhitpos.y, !rn2(5), 0))
  191. #ifdef SINKS
  192. 			/* Thrown objects "sink" */
  193. 			|| IS_SINK(levl[bhitpos.x][bhitpos.y].typ)
  194. #endif
  195. 								) {
  196. 		    if (singleobj) /* hits_bars might have destroyed it */
  197. 			(void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
  198. 		    break;
  199. 		}
  200. 		tmp_at(bhitpos.x, bhitpos.y);
  201. 		delay_output();
  202. 	}
  203. 	tmp_at(bhitpos.x, bhitpos.y);
  204. 	delay_output();
  205. 	tmp_at(DISP_END, 0);
  206.  
  207. 	if (blindinc) {
  208. 		u.ucreamed += blindinc;
  209. 		make_blinded(Blinded + (long)blindinc, FALSE);
  210. 		if (!Blind) Your(vision_clears);
  211. 	}
  212. }
  213.  
  214. #endif /* OVL1 */
  215. #ifdef OVLB

m_useup[edit]

  1. /* Remove an item from the monster's inventory and destroy it. */
  2. void
  3. m_useup(mon, obj)
  4. struct monst *mon;
  5. struct obj *obj;
  6. {
  7. 	if (obj->quan > 1L) {
  8. 		obj->quan--;
  9. 		obj->owt = weight(obj);
  10. 	} else {
  11. 		obj_extract_self(obj);
  12. 		possibly_unwield(mon, FALSE);
  13. 		if (obj->owornmask) {
  14. 		    mon->misc_worn_check &= ~obj->owornmask;
  15. 		    update_mon_intrinsics(mon, obj, FALSE, FALSE);
  16. 		}
  17. 		obfree(obj, (struct obj*) 0);
  18. 	}
  19. }
  20.  
  21. #endif /* OVLB */
  22. #ifdef OVL1

thrwmu[edit]

  1. /* monster attempts ranged weapon attack against player */
  2. void
  3. thrwmu(mtmp)
  4. struct monst *mtmp;
  5. {
  6. 	struct obj *otmp, *mwep;
  7. 	xchar x, y;
  8. 	schar skill;
  9. 	int multishot;
  10. 	const char *onm;
  11.  
  12. 	/* Rearranged beginning so monsters can use polearms not in a line */
  13. 	if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) {
  14. 	    mtmp->weapon_check = NEED_RANGED_WEAPON;
  15. 	    /* mon_wield_item resets weapon_check as appropriate */
  16. 	    if(mon_wield_item(mtmp) != 0) return;
  17. 	}
  18.  
  19. 	/* Pick a weapon */
  20. 	otmp = select_rwep(mtmp);
  21. 	if (!otmp) return;
  22.  
  23. 	if (is_pole(otmp)) {
  24. 	    int dam, hitv;
  25.  
  26. 	    if (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) > POLE_LIM ||
  27. 		    !couldsee(mtmp->mx, mtmp->my))
  28. 		return;	/* Out of range, or intervening wall */
  29.  
  30. 	    if (canseemon(mtmp)) {
  31. 		onm = xname(otmp);
  32. 		pline("%s thrusts %s.", Monnam(mtmp),
  33. 		      obj_is_pname(otmp) ? the(onm) : an(onm));
  34. 	    }
  35.  
  36. 	    dam = dmgval(otmp, &youmonst);
  37. 	    hitv = 3 - distmin(u.ux,u.uy, mtmp->mx,mtmp->my);
  38. 	    if (hitv < -4) hitv = -4;
  39. 	    if (bigmonst(youmonst.data)) hitv++;
  40. 	    hitv += 8 + otmp->spe;
  41. 	    if (dam < 1) dam = 1;
  42.  
  43. 	    (void) thitu(hitv, dam, otmp, (char *)0);
  44. 	    stop_occupation();
  45. 	    return;
  46. 	}
  47.  
  48. 	x = mtmp->mx;
  49. 	y = mtmp->my;
  50. 	/* If you are coming toward the monster, the monster
  51. 	 * should try to soften you up with missiles.  If you are
  52. 	 * going away, you are probably hurt or running.  Give
  53. 	 * chase, but if you are getting too far away, throw.
  54. 	 */
  55. 	if (!lined_up(mtmp) ||
  56. 		(URETREATING(x,y) &&
  57. 			rn2(BOLT_LIM - distmin(x,y,mtmp->mux,mtmp->muy))))
  58. 	    return;
  59.  
  60. 	skill = objects[otmp->otyp].oc_skill;
  61. 	mwep = MON_WEP(mtmp);		/* wielded weapon */
  62.  
  63. 	/* Multishot calculations */
  64. 	multishot = 1;
  65. 	if ((ammo_and_launcher(otmp, mwep) || skill == P_DAGGER ||
  66. 		skill == -P_DART || skill == -P_SHURIKEN) && !mtmp->mconf) {
  67. 	    /* Assumes lords are skilled, princes are expert */
  68. 	    if (is_prince(mtmp->data)) multishot += 2;
  69. 	    else if (is_lord(mtmp->data)) multishot++;
  70.  
  71. 	    switch (monsndx(mtmp->data)) {
  72. 	    case PM_RANGER:
  73. 		    multishot++;
  74. 		    break;
  75. 	    case PM_ROGUE:
  76. 		    if (skill == P_DAGGER) multishot++;
  77. 		    break;
  78. 	    case PM_NINJA:
  79. 	    case PM_SAMURAI:
  80. 		    if (otmp->otyp == YA && mwep &&
  81. 			mwep->otyp == YUMI) multishot++;
  82. 		    break;
  83. 	    default:
  84. 		break;
  85. 	    }
  86. 	    /* racial bonus */
  87. 	    if ((is_elf(mtmp->data) &&
  88. 		    otmp->otyp == ELVEN_ARROW &&
  89. 		    mwep && mwep->otyp == ELVEN_BOW) ||
  90. 		(is_orc(mtmp->data) &&
  91. 		    otmp->otyp == ORCISH_ARROW &&
  92. 		    mwep && mwep->otyp == ORCISH_BOW))
  93. 		multishot++;
  94.  
  95. 	    if ((long)multishot > otmp->quan) multishot = (int)otmp->quan;
  96. 	    if (multishot < 1) multishot = 1;
  97. 	    else multishot = rnd(multishot);
  98. 	}
  99.  
  100. 	if (canseemon(mtmp)) {
  101. 	    char onmbuf[BUFSZ];
  102.  
  103. 	    if (multishot > 1) {
  104. 		/* "N arrows"; multishot > 1 implies otmp->quan > 1, so
  105. 		   xname()'s result will already be pluralized */
  106. 		Sprintf(onmbuf, "%d %s", multishot, xname(otmp));
  107. 		onm = onmbuf;
  108. 	    } else {
  109. 		/* "an arrow" */
  110. 		onm = singular(otmp, xname);
  111. 		onm = obj_is_pname(otmp) ? the(onm) : an(onm);
  112. 	    }
  113. 	    m_shot.s = ammo_and_launcher(otmp,mwep) ? TRUE : FALSE;
  114. 	    pline("%s %s %s!", Monnam(mtmp),
  115. 		  m_shot.s ? "shoots" : "throws", onm);
  116. 	    m_shot.o = otmp->otyp;
  117. 	} else {
  118. 	    m_shot.o = STRANGE_OBJECT;	/* don't give multishot feedback */
  119. 	}
  120.  
  121. 	m_shot.n = multishot;
  122. 	for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++)
  123. 	    m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby),
  124. 		    distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy), otmp);
  125. 	m_shot.n = m_shot.i = 0;
  126. 	m_shot.o = STRANGE_OBJECT;
  127. 	m_shot.s = FALSE;
  128.  
  129. 	nomul(0);
  130. }
  131.  
  132. #endif /* OVL1 */
  133. #ifdef OVLB

spitmu[edit]

  1. int
  2. spitmu(mtmp, mattk)		/* monster spits substance at you */
  3. register struct monst *mtmp;
  4. register struct attack *mattk;
  5. {
  6. 	register struct obj *otmp;
  7.  
  8. 	if(mtmp->mcan) {
  9.  
  10. 	    if(flags.soundok)
  11. 		pline("A dry rattle comes from %s throat.",
  12. 		                      s_suffix(mon_nam(mtmp)));
  13. 	    return 0;
  14. 	}
  15. 	if(lined_up(mtmp)) {
  16. 		switch (mattk->adtyp) {
  17. 		    case AD_BLND:
  18. 		    case AD_DRST:
  19. 			otmp = mksobj(BLINDING_VENOM, TRUE, FALSE);
  20. 			break;
  21. 		    default:
  22. 			impossible("bad attack type in spitmu");
  23. 				/* fall through */
  24. 		    case AD_ACID:
  25. 			otmp = mksobj(ACID_VENOM, TRUE, FALSE);
  26. 			break;
  27. 		}
  28. 		if(!rn2(BOLT_LIM-distmin(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy))) {
  29. 		    if (canseemon(mtmp))
  30. 			pline("%s spits venom!", Monnam(mtmp));
  31. 		    m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby),
  32. 			distmin(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy), otmp);
  33. 		    nomul(0);
  34. 		    return 0;
  35. 		}
  36. 	}
  37. 	return 0;
  38. }
  39.  
  40. #endif /* OVLB */
  41. #ifdef OVL1

breamu[edit]

  1. int
  2. breamu(mtmp, mattk)			/* monster breathes at you (ranged) */
  3. 	register struct monst *mtmp;
  4. 	register struct attack  *mattk;
  5. {
  6. 	/* if new breath types are added, change AD_ACID to max type */
  7. 	int typ = (mattk->adtyp == AD_RBRE) ? rnd(AD_ACID) : mattk->adtyp ;
  8.  
  9. 	if(lined_up(mtmp)) {
  10.  
  11. 	    if(mtmp->mcan) {
  12. 		if(flags.soundok) {
  13. 		    if(canseemon(mtmp))
  14. 			pline("%s coughs.", Monnam(mtmp));
  15. 		    else
  16. 			You_hear("a cough.");
  17. 		}
  18. 		return(0);
  19. 	    }
  20. 	    if(!mtmp->mspec_used && rn2(3)) {
  21.  
  22. 		if((typ >= AD_MAGM) && (typ <= AD_ACID)) {
  23.  
  24. 		    if(canseemon(mtmp))
  25. 			pline("%s breathes %s!", Monnam(mtmp),
  26. 			      breathwep[typ-1]);
  27. 		    buzz((int) (-20 - (typ-1)), (int)mattk->damn,
  28. 			 mtmp->mx, mtmp->my, sgn(tbx), sgn(tby));
  29. 		    nomul(0);
  30. 		    /* breath runs out sometimes. Also, give monster some
  31. 		     * cunning; don't breath if the player fell asleep.
  32. 		     */
  33. 		    if(!rn2(3))
  34. 			mtmp->mspec_used = 10+rn2(20);
  35. 		    if(typ == AD_SLEE && !Sleep_resistance)
  36. 			mtmp->mspec_used += rnd(20);
  37. 		} else impossible("Breath weapon %d used", typ-1);
  38. 	    }
  39. 	}
  40. 	return(1);
  41. }

linedup[edit]

  1. boolean
  2. linedup(ax, ay, bx, by)
  3. register xchar ax, ay, bx, by;
  4. {
  5. 	tbx = ax - bx;	/* These two values are set for use */
  6. 	tby = ay - by;	/* after successful return.	    */
  7.  
  8. 	/* sometimes displacement makes a monster think that you're at its
  9. 	   own location; prevent it from throwing and zapping in that case */
  10. 	if (!tbx && !tby) return FALSE;
  11.  
  12. 	if((!tbx || !tby || abs(tbx) == abs(tby)) /* straight line or diagonal */
  13. 	   && distmin(tbx, tby, 0, 0) < BOLT_LIM) {
  14. 	    if(ax == u.ux && ay == u.uy) return((boolean)(couldsee(bx,by)));
  15. 	    else if(clear_path(ax,ay,bx,by)) return TRUE;
  16. 	}
  17. 	return FALSE;
  18. }

lined_up[edit]

  1. boolean
  2. lined_up(mtmp)		/* is mtmp in position to use ranged attack? */
  3. 	register struct monst *mtmp;
  4. {
  5. 	return(linedup(mtmp->mux,mtmp->muy,mtmp->mx,mtmp->my));
  6. }
  7.  
  8. #endif /* OVL1 */
  9. #ifdef OVL0

m_carrying[edit]

  1. /* Check if a monster is carrying a particular item.
  2. */
  3. struct obj *
  4. m_carrying(mtmp, type)
  5. struct monst *mtmp;
  6. int type;
  7. {
  8. 	register struct obj *otmp;
  9.  
  10. 	for(otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  11. 		if(otmp->otyp == type)
  12. 			return(otmp);
  13. 	return((struct obj *) 0);
  14. }

hits_bars[edit]

  1. /* TRUE iff thrown/kicked/rolled object doesn't pass through iron bars */
  2. boolean
  3. hits_bars(obj_p, x, y, always_hit, whodidit)
  4. struct obj **obj_p;	/* *obj_p will be set to NULL if object breaks */
  5. int x, y;
  6. int always_hit;	/* caller can force a hit for items which would fit through */
  7. int whodidit;	/* 1==hero, 0=other, -1==just check whether it'll pass thru */
  8. {
  9. struct obj *otmp = *obj_p;
  10. int obj_type = otmp->otyp;
  11. boolean hits = always_hit;
  12.  
  13. if (!hits)
  14. 	switch (otmp->oclass) {
  15. 	case WEAPON_CLASS:
  16. 	    {
  17. 		int oskill = objects[obj_type].oc_skill;
  18.  
  19. 		hits = (oskill != -P_BOW  && oskill != -P_CROSSBOW &&
  20. 			oskill != -P_DART && oskill != -P_SHURIKEN &&
  21. 			oskill != P_SPEAR && oskill != P_JAVELIN &&
  22. 			oskill != P_KNIFE);	/* but not dagger */
  23. 		break;
  24. 	    }
  25. 	case ARMOR_CLASS:
  26. 		hits = (objects[obj_type].oc_armcat != ARM_GLOVES);
  27. 		break;
  28. 	case TOOL_CLASS:
  29. 		hits = (obj_type != SKELETON_KEY &&
  30. 			obj_type != LOCK_PICK &&
  31. #ifdef TOURIST
  32. 			obj_type != CREDIT_CARD &&
  33. #endif
  34. 			obj_type != TALLOW_CANDLE &&
  35. 			obj_type != WAX_CANDLE &&
  36. 			obj_type != LENSES &&
  37. 			obj_type != TIN_WHISTLE &&
  38. 			obj_type != MAGIC_WHISTLE);
  39. 		break;
  40. 	case ROCK_CLASS:	/* includes boulder */
  41. 		if (obj_type != STATUE ||
  42. 			mons[otmp->corpsenm].msize > MZ_TINY) hits = TRUE;
  43. 		break;
  44. 	case FOOD_CLASS:
  45. 		if (obj_type == CORPSE &&
  46. 			mons[otmp->corpsenm].msize > MZ_TINY) hits = TRUE;
  47. 		else
  48. 		    hits = (obj_type == MEAT_STICK ||
  49. 			    obj_type == HUGE_CHUNK_OF_MEAT);
  50. 		break;
  51. 	case SPBOOK_CLASS:
  52. 	case WAND_CLASS:
  53. 	case BALL_CLASS:
  54. 	case CHAIN_CLASS:
  55. 		hits = TRUE;
  56. 		break;
  57. 	default:
  58. 		break;
  59. 	}
  60.  
  61. if (hits && whodidit != -1) {
  62. 	if (whodidit ? hero_breaks(otmp, x, y, FALSE) : breaks(otmp, x, y))
  63. 	    *obj_p = otmp = 0;		/* object is now gone */
  64. 	    /* breakage makes its own noises */
  65. 	else if (obj_type == BOULDER || obj_type == HEAVY_IRON_BALL)
  66. 	    pline("Whang!");
  67. 	else if (otmp->oclass == COIN_CLASS ||
  68. 		objects[obj_type].oc_material == GOLD ||
  69. 		objects[obj_type].oc_material == SILVER)
  70. 	    pline("Clink!");
  71. 	else
  72. 	    pline("Clonk!");
  73. }
  74.  
  75. return hits;
  76. }
  77.  
  78. #endif /* OVL0 */
  79.  
  80. /*mthrowu.c*/