Source:NetHack 3.4.3/src/dothrow.c

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

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

Top of file

  1. /*	SCCS Id: @(#)dothrow.c	3.4	2003/12/04	*/
  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. /* Contains code for 't' (throw) */
  2.  
  3. #include "hack.h"
  4. #include "edog.h"
  5.  
  6. STATIC_DCL int FDECL(throw_obj, (struct obj *,int));
  7. STATIC_DCL void NDECL(autoquiver);
  8. STATIC_DCL int FDECL(gem_accept, (struct monst *, struct obj *));
  9. STATIC_DCL void FDECL(tmiss, (struct obj *, struct monst *));
  10. STATIC_DCL int FDECL(throw_gold, (struct obj *));
  11. STATIC_DCL void FDECL(check_shop_obj, (struct obj *,XCHAR_P,XCHAR_P,BOOLEAN_P));
  12. STATIC_DCL void FDECL(breakobj, (struct obj *,XCHAR_P,XCHAR_P,BOOLEAN_P,BOOLEAN_P));
  13. STATIC_DCL void FDECL(breakmsg, (struct obj *,BOOLEAN_P));
  14. STATIC_DCL boolean FDECL(toss_up,(struct obj *, BOOLEAN_P));
  15. STATIC_DCL boolean FDECL(throwing_weapon, (struct obj *));
  16. STATIC_DCL void FDECL(sho_obj_return_to_u, (struct obj *obj));
  17. STATIC_DCL boolean FDECL(mhurtle_step, (genericptr_t,int,int));
  18.  
  19.  
  20. static NEARDATA const char toss_objs[] =
  21. 	{ ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, WEAPON_CLASS, 0 };
  22. /* different default choices when wielding a sling (gold must be included) */
  23. static NEARDATA const char bullets[] =
  24. 	{ ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, GEM_CLASS, 0 };
  25.  
  26. struct obj *thrownobj = 0;	/* tracks an object until it lands */
  27.  
  28. extern boolean notonhead;	/* for long worms */

throw_obj

  1. /* Throw the selected object, asking for direction */
  2. STATIC_OVL int
  3. throw_obj(obj, shotlimit)
  4. struct obj *obj;
  5. int shotlimit;
  6. {
  7. 	struct obj *otmp;
  8. 	int multishot = 1;
  9. 	schar skill;
  10. 	long wep_mask;
  11. 	boolean twoweap;
  12.  
  13. 	/* ask "in what direction?" */
  14. #ifndef GOLDOBJ
  15. 	if (!getdir((char *)0)) {
  16. 		if (obj->oclass == COIN_CLASS) {
  17. 		    u.ugold += obj->quan;
  18. 		    flags.botl = 1;
  19. 		    dealloc_obj(obj);
  20. 		}
  21. 		return(0);
  22. 	}
  23.  
  24. 	if(obj->oclass == COIN_CLASS) return(throw_gold(obj));
  25. #else
  26. 	if (!getdir((char *)0)) {
  27. 	    /* obj might need to be merged back into the singular gold object */
  28. 	    freeinv(obj);
  29. 	    addinv(obj);
  30. 	    return(0);
  31. 	}
  32.  
  33. /*
  34. 	  Throwing money is usually for getting rid of it when
  35. a leprechaun approaches, or for bribing an oncoming 
  36. angry monster.  So throw the whole object.
  37.  
  38. If the money is in quiver, throw one coin at a time,
  39. possibly using a sling.
  40. */
  41. 	if(obj->oclass == COIN_CLASS && obj != uquiver) return(throw_gold(obj));
  42. #endif
  43.  
  44. 	if(!canletgo(obj,"throw"))
  45. 		return(0);
  46. 	if (obj->oartifact == ART_MJOLLNIR && obj != uwep) {
  47. 	    pline("%s must be wielded before it can be thrown.",
  48. 		The(xname(obj)));
  49. 		return(0);
  50. 	}
  51. 	if ((obj->oartifact == ART_MJOLLNIR && ACURR(A_STR) < STR19(25))
  52. 	   || (obj->otyp == BOULDER && !throws_rocks(youmonst.data))) {
  53. 		pline("It's too heavy.");
  54. 		return(1);
  55. 	}
  56. 	if(!u.dx && !u.dy && !u.dz) {
  57. 		You("cannot throw an object at yourself.");
  58. 		return(0);
  59. 	}
  60. 	u_wipe_engr(2);
  61. 	if (!uarmg && !Stone_resistance && (obj->otyp == CORPSE &&
  62. 		    touch_petrifies(&mons[obj->corpsenm]))) {
  63. 		You("throw the %s corpse with your bare %s.",
  64. 		    mons[obj->corpsenm].mname, body_part(HAND));
  65. 		Sprintf(killer_buf, "%s corpse", an(mons[obj->corpsenm].mname));
  66. 		instapetrify(killer_buf);
  67. 	}
  68. 	if (welded(obj)) {
  69. 		weldmsg(obj);
  70. 		return 1;
  71. 	}
  72.  
  73. 	/* Multishot calculations
  74. 	 */
  75. 	skill = objects[obj->otyp].oc_skill;
  76. 	if ((ammo_and_launcher(obj, uwep) || skill == P_DAGGER ||
  77. 			skill == -P_DART || skill == -P_SHURIKEN) &&
  78. 		!(Confusion || Stunned)) {
  79. 	    /* Bonus if the player is proficient in this weapon... */
  80. 	    switch (P_SKILL(weapon_type(obj))) {
  81. 	    default:	break; /* No bonus */
  82. 	    case P_SKILLED:	multishot++; break;
  83. 	    case P_EXPERT:	multishot += 2; break;
  84. 	    }
  85. 	    /* ...or is using a special weapon for their role... */
  86. 	    switch (Role_switch) {
  87. 	    case PM_RANGER:
  88. 		multishot++;
  89. 		break;
  90. 	    case PM_ROGUE:
  91. 		if (skill == P_DAGGER) multishot++;
  92. 		break;
  93. 	    case PM_SAMURAI:
  94. 		if (obj->otyp == YA && uwep && uwep->otyp == YUMI) multishot++;
  95. 		break;
  96. 	    default:
  97. 		break;	/* No bonus */
  98. 	    }
  99. 	    /* ...or using their race's special bow */
  100. 	    switch (Race_switch) {
  101. 	    case PM_ELF:
  102. 		if (obj->otyp == ELVEN_ARROW && uwep &&
  103. 				uwep->otyp == ELVEN_BOW) multishot++;
  104. 		break;
  105. 	    case PM_ORC:
  106. 		if (obj->otyp == ORCISH_ARROW && uwep &&
  107. 				uwep->otyp == ORCISH_BOW) multishot++;
  108. 		break;
  109. 	    default:
  110. 		break;	/* No bonus */
  111. 	    }
  112. 	}
  113.  
  114. 	if ((long)multishot > obj->quan) multishot = (int)obj->quan;
  115. 	multishot = rnd(multishot);
  116. 	if (shotlimit > 0 && multishot > shotlimit) multishot = shotlimit;
  117.  
  118. 	m_shot.s = ammo_and_launcher(obj,uwep) ? TRUE : FALSE;
  119. 	/* give a message if shooting more than one, or if player
  120. 	   attempted to specify a count */
  121. 	if (multishot > 1 || shotlimit > 0) {
  122. 	    /* "You shoot N arrows." or "You throw N daggers." */
  123. 	    You("%s %d %s.",
  124. 		m_shot.s ? "shoot" : "throw",
  125. 		multishot,	/* (might be 1 if player gave shotlimit) */
  126. 		(multishot == 1) ? singular(obj, xname) :  xname(obj));
  127. 	}
  128.  
  129. 	wep_mask = obj->owornmask;
  130. 	m_shot.o = obj->otyp;
  131. 	m_shot.n = multishot;
  132. 	for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) {
  133. 	    twoweap = u.twoweap;
  134. 	    /* split this object off from its slot if necessary */
  135. 	    if (obj->quan > 1L) {
  136. 		otmp = splitobj(obj, 1L);
  137. 	    } else {
  138. 		otmp = obj;
  139. 		if (otmp->owornmask)
  140. 		    remove_worn_item(otmp, FALSE);
  141. 	    }
  142. 	    freeinv(otmp);
  143. 	    throwit(otmp, wep_mask, twoweap);
  144. 	}
  145. 	m_shot.n = m_shot.i = 0;
  146. 	m_shot.o = STRANGE_OBJECT;
  147. 	m_shot.s = FALSE;
  148.  
  149. 	return 1;
  150. }

dothrow

  1. int
  2. dothrow()
  3. {
  4. 	register struct obj *obj;
  5. 	int shotlimit;
  6.  
  7. 	/*
  8. 	 * Since some characters shoot multiple missiles at one time,
  9. 	 * allow user to specify a count prefix for 'f' or 't' to limit
  10. 	 * number of items thrown (to avoid possibly hitting something
  11. 	 * behind target after killing it, or perhaps to conserve ammo).
  12. 	 *
  13. 	 * Prior to 3.3.0, command ``3t'' meant ``t(shoot) t(shoot) t(shoot)''
  14. 	 * and took 3 turns.  Now it means ``t(shoot at most 3 missiles)''.
  15. 	 */
  16. 	/* kludge to work around parse()'s pre-decrement of `multi' */
  17. 	shotlimit = (multi || save_cm) ? multi + 1 : 0;
  18. 	multi = 0;		/* reset; it's been used up */
  19.  
  20. 	if (notake(youmonst.data)) {
  21. 	    You("are physically incapable of throwing anything.");
  22. 	    return 0;
  23. 	}
  24.  
  25. 	if(check_capacity((char *)0)) return(0);
  26. 	obj = getobj(uslinging() ? bullets : toss_objs, "throw");
  27. 	/* it is also possible to throw food */
  28. 	/* (or jewels, or iron balls... ) */
  29.  
  30. 	if (!obj) return(0);
  31. 	return throw_obj(obj, shotlimit);
  32. }

autoquiver

  1. /* KMH -- Automatically fill quiver */
  2. /* Suggested by Jeffrey Bay <jbay@convex.hp.com> */
  3. static void
  4. autoquiver()
  5. {
  6. 	struct obj *otmp, *oammo = 0, *omissile = 0, *omisc = 0, *altammo = 0;
  7.  
  8. 	if (uquiver)
  9. 	    return;
  10.  
  11. 	/* Scan through the inventory */
  12. 	for (otmp = invent; otmp; otmp = otmp->nobj) {
  13. 	    if (otmp->owornmask || otmp->oartifact || !otmp->dknown) {
  14. 		;	/* Skip it */
  15. 	    } else if (otmp->otyp == ROCK ||
  16. 			/* seen rocks or known flint or known glass */
  17. 			(objects[otmp->otyp].oc_name_known &&
  18. 			 otmp->otyp == FLINT) ||
  19. 			(objects[otmp->otyp].oc_name_known &&
  20. 			 otmp->oclass == GEM_CLASS &&
  21. 			 objects[otmp->otyp].oc_material == GLASS)) {
  22. 		if (uslinging())
  23. 		    oammo = otmp;
  24. 		else if (ammo_and_launcher(otmp, uswapwep))
  25. 		    altammo = otmp;
  26. 		else if (!omisc)
  27. 		    omisc = otmp;
  28. 	    } else if (otmp->oclass == GEM_CLASS) {
  29. 		;	/* skip non-rock gems--they're ammo but
  30. 			   player has to select them explicitly */
  31. 	    } else if (is_ammo(otmp)) {
  32. 		if (ammo_and_launcher(otmp, uwep))
  33. 		    /* Ammo matched with launcher (bow and arrow, crossbow and bolt) */
  34. 		    oammo = otmp;
  35. 		else if (ammo_and_launcher(otmp, uswapwep))
  36. 		    altammo = otmp;
  37. 		else
  38. 		    /* Mismatched ammo (no better than an ordinary weapon) */
  39. 		    omisc = otmp;
  40. 	    } else if (is_missile(otmp)) {
  41. 		/* Missile (dart, shuriken, etc.) */
  42. 		omissile = otmp;
  43. 	    } else if (otmp->oclass == WEAPON_CLASS && throwing_weapon(otmp)) {
  44. 		/* Ordinary weapon */
  45. 		if (objects[otmp->otyp].oc_skill == P_DAGGER
  46. 			&& !omissile) 
  47. 		    omissile = otmp;
  48. 		else
  49. 		    omisc = otmp;
  50. 	    }
  51. 	}
  52.  
  53. 	/* Pick the best choice */
  54. 	if (oammo)
  55. 	    setuqwep(oammo);
  56. 	else if (omissile)
  57. 	    setuqwep(omissile);
  58. 	else if (altammo)
  59. 	    setuqwep(altammo);
  60. 	else if (omisc)
  61. 	    setuqwep(omisc);
  62.  
  63. 	return;
  64. }

dofire

  1. /* Throw from the quiver */
  2. int
  3. dofire()
  4. {
  5. 	int shotlimit;
  6.  
  7. 	if (notake(youmonst.data)) {
  8. 	    You("are physically incapable of doing that.");
  9. 	    return 0;
  10. 	}
  11.  
  12. 	if(check_capacity((char *)0)) return(0);
  13. 	if (!uquiver) {
  14. 		if (!flags.autoquiver) {
  15. 			/* Don't automatically fill the quiver */
  16. 			You("have no ammunition readied!");
  17. 			return(dothrow());
  18. 		}
  19. 		autoquiver();
  20. 		if (!uquiver) {
  21. 			You("have nothing appropriate for your quiver!");
  22. 			return(dothrow());
  23. 		} else {
  24. 			You("fill your quiver:");
  25. 			prinv((char *)0, uquiver, 0L);
  26. 		}
  27. 	}
  28.  
  29. 	/*
  30. 	 * Since some characters shoot multiple missiles at one time,
  31. 	 * allow user to specify a count prefix for 'f' or 't' to limit
  32. 	 * number of items thrown (to avoid possibly hitting something
  33. 	 * behind target after killing it, or perhaps to conserve ammo).
  34. 	 *
  35. 	 * The number specified can never increase the number of missiles.
  36. 	 * Using ``5f'' when the shooting skill (plus RNG) dictates launch
  37. 	 * of 3 projectiles will result in 3 being shot, not 5.
  38. 	 */
  39. 	/* kludge to work around parse()'s pre-decrement of `multi' */
  40. 	shotlimit = (multi || save_cm) ? multi + 1 : 0;
  41. 	multi = 0;		/* reset; it's been used up */
  42.  
  43. 	return throw_obj(uquiver, shotlimit);
  44. }

hitfloor

  1. /*
  2. * Object hits floor at hero's feet.  Called from drop() and throwit().
  3. */
  4. void
  5. hitfloor(obj)
  6. register struct obj *obj;
  7. {
  8. 	if (IS_SOFT(levl[u.ux][u.uy].typ) || u.uinwater) {
  9. 		dropy(obj);
  10. 		return;
  11. 	}
  12. 	if (IS_ALTAR(levl[u.ux][u.uy].typ))
  13. 		doaltarobj(obj);
  14. 	else
  15. 		pline("%s hit%s the %s.", Doname2(obj),
  16. 		      (obj->quan == 1L) ? "s" : "", surface(u.ux,u.uy));
  17.  
  18. 	if (hero_breaks(obj, u.ux, u.uy, TRUE)) return;
  19. 	if (ship_object(obj, u.ux, u.uy, FALSE)) return;
  20. 	dropy(obj);
  21. 	if (!u.uswallow) container_impact_dmg(obj);
  22. }

walk_path

  1. /*
  2. * Walk a path from src_cc to dest_cc, calling a proc for each location
  3. * except the starting one.  If the proc returns FALSE, stop walking
  4. * and return FALSE.  If stopped early, dest_cc will be the location
  5. * before the failed callback.
  6. */
  7. boolean
  8. walk_path(src_cc, dest_cc, check_proc, arg)
  9. coord *src_cc;
  10. coord *dest_cc;
  11. boolean FDECL((*check_proc), (genericptr_t, int, int));
  12. genericptr_t arg;
  13. {
  14. int x, y, dx, dy, x_change, y_change, err, i, prev_x, prev_y;
  15. boolean keep_going = TRUE;
  16.  
  17. /* Use Bresenham's Line Algorithm to walk from src to dest */
  18. dx = dest_cc->x - src_cc->x;
  19. dy = dest_cc->y - src_cc->y;
  20. prev_x = x = src_cc->x;
  21. prev_y = y = src_cc->y;
  22.  
  23. if (dx < 0) {
  24. 	x_change = -1;
  25. 	dx = -dx;
  26. } else
  27. 	x_change = 1;
  28. if (dy < 0) {
  29. 	y_change = -1;
  30. 	dy = -dy;
  31. } else
  32. 	y_change = 1;
  33.  
  34. i = err = 0;
  35. if (dx < dy) {
  36. 	while (i++ < dy) {
  37. 	    prev_x = x;
  38. 	    prev_y = y;
  39. 	    y += y_change;
  40. 	    err += dx;
  41. 	    if (err >= dy) {
  42. 		x += x_change;
  43. 		err -= dy;
  44. 	    }
  45. 	/* check for early exit condition */
  46. 	if (!(keep_going = (*check_proc)(arg, x, y)))
  47. 	    break;
  48. 	}
  49. } else {
  50. 	while (i++ < dx) {
  51. 	    prev_x = x;
  52. 	    prev_y = y;
  53. 	    x += x_change;
  54. 	    err += dy;
  55. 	    if (err >= dx) {
  56. 		y += y_change;
  57. 		err -= dx;
  58. 	    }
  59. 	/* check for early exit condition */
  60. 	if (!(keep_going = (*check_proc)(arg, x, y)))
  61. 	    break;
  62. 	}
  63. }
  64.  
  65. if (keep_going)
  66. 	return TRUE;	/* successful */
  67.  
  68. dest_cc->x = prev_x;
  69. dest_cc->y = prev_y;
  70. return FALSE;
  71. }

hurtle_step

  1. /*
  2. * Single step for the hero flying through the air from jumping, flying,
  3. * etc.  Called from hurtle() and jump() via walk_path().  We expect the
  4. * argument to be a pointer to an integer -- the range -- which is
  5. * used in the calculation of points off if we hit something.
  6. *
  7. * Bumping into monsters won't cause damage but will wake them and make
  8. * them angry.  Auto-pickup isn't done, since you don't have control over
  9. * your movements at the time.
  10. *
  11. * Possible additions/changes:
  12. *	o really attack monster if we hit one
  13. *	o set stunned if we hit a wall or door
  14. *	o reset nomul when we stop
  15. *	o creepy feeling if pass through monster (if ever implemented...)
  16. *	o bounce off walls
  17. *	o let jumps go over boulders
  18. */
  19. boolean
  20. hurtle_step(arg, x, y)
  21. genericptr_t arg;
  22. int x, y;
  23. {
  24. int ox, oy, *range = (int *)arg;
  25. struct obj *obj;
  26. struct monst *mon;
  27. boolean may_pass = TRUE;
  28. struct trap *ttmp;
  29.  
  30. if (!isok(x,y)) {
  31. 	You_feel("the spirits holding you back.");
  32. 	return FALSE;
  33. } else if (!in_out_region(x, y)) {
  34. 	return FALSE;
  35. } else if (*range == 0) {
  36. 	return FALSE;			/* previous step wants to stop now */
  37. }
  38.  
  39. if (!Passes_walls || !(may_pass = may_passwall(x, y))) {
  40. 	if (IS_ROCK(levl[x][y].typ) || closed_door(x,y)) {
  41. 	    const char *s;
  42.  
  43. 	    pline("Ouch!");
  44. 	    if (IS_TREE(levl[x][y].typ))
  45. 		s = "bumping into a tree";
  46. 	    else if (IS_ROCK(levl[x][y].typ))
  47. 		s = "bumping into a wall";
  48. 	    else
  49. 		s = "bumping into a door";
  50. 	    losehp(rnd(2+*range), s, KILLED_BY);
  51. 	    return FALSE;
  52. 	}
  53. 	if (levl[x][y].typ == IRONBARS) {
  54. 	    You("crash into some iron bars.  Ouch!");
  55. 	    losehp(rnd(2+*range), "crashing into iron bars", KILLED_BY);
  56. 	    return FALSE;
  57. 	}
  58. 	if ((obj = sobj_at(BOULDER,x,y)) != 0) {
  59. 	    You("bump into a %s.  Ouch!", xname(obj));
  60. 	    losehp(rnd(2+*range), "bumping into a boulder", KILLED_BY);
  61. 	    return FALSE;
  62. 	}
  63. 	if (!may_pass) {
  64. 	    /* did we hit a no-dig non-wall position? */
  65. 	    You("smack into something!");
  66. 	    losehp(rnd(2+*range), "touching the edge of the universe", KILLED_BY);
  67. 	    return FALSE;
  68. 	}
  69. 	if ((u.ux - x) && (u.uy - y) &&
  70. 		bad_rock(youmonst.data,u.ux,y) && bad_rock(youmonst.data,x,u.uy)) {
  71. 	    boolean too_much = (invent && (inv_weight() + weight_cap() > 600));
  72. 	    /* Move at a diagonal. */
  73. 	    if (bigmonst(youmonst.data) || too_much) {
  74. 		You("%sget forcefully wedged into a crevice.",
  75. 			too_much ? "and all your belongings " : "");
  76. 		losehp(rnd(2+*range), "wedging into a narrow crevice", KILLED_BY);
  77. 		return FALSE;
  78. 	    }
  79. 	}
  80. }
  81.  
  82. if ((mon = m_at(x, y)) != 0) {
  83. 	You("bump into %s.", a_monnam(mon));
  84. 	wakeup(mon);
  85. 	return FALSE;
  86. }
  87. if ((u.ux - x) && (u.uy - y) &&
  88. 	bad_rock(youmonst.data,u.ux,y) && bad_rock(youmonst.data,x,u.uy)) {
  89. 	/* Move at a diagonal. */
  90. 	if (In_sokoban(&u.uz)) {
  91. 	    You("come to an abrupt halt!");
  92. 	    return FALSE;
  93. 	}
  94. }
  95.  
  96. ox = u.ux;
  97. oy = u.uy;
  98. u.ux = x;
  99. u.uy = y;
  100. newsym(ox, oy);		/* update old position */
  101. vision_recalc(1);		/* update for new position */
  102. flush_screen(1);
  103. /* FIXME:
  104. * Each trap should really trigger on the recoil if
  105. * it would trigger during normal movement. However,
  106. * not all the possible side-effects of this are
  107. * tested [as of 3.4.0] so we trigger those that
  108. * we have tested, and offer a message for the
  109. * ones that we have not yet tested.
  110. */
  111. if ((ttmp = t_at(x, y)) != 0) {
  112. 	if (ttmp->ttyp == MAGIC_PORTAL) {
  113. 		dotrap(ttmp,0);
  114. 		return FALSE;
  115. 	} else if (ttmp->ttyp == FIRE_TRAP) {
  116. 		dotrap(ttmp,0);
  117. 	} else if ((ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT ||
  118. 		    ttmp->ttyp == HOLE || ttmp->ttyp == TRAPDOOR) &&
  119. 		   In_sokoban(&u.uz)) {
  120. 		/* Air currents overcome the recoil */
  121. 		dotrap(ttmp,0);
  122. 		*range = 0;
  123. 		return TRUE;
  124. 	} else {
  125. 		if (ttmp->tseen)
  126. 		    You("pass right over %s %s.",
  127. 		    	(ttmp->ttyp == ARROW_TRAP) ? "an" : "a",
  128. 		    	defsyms[trap_to_defsym(ttmp->ttyp)].explanation);
  129. 	}
  130. }
  131. if (--*range < 0)		/* make sure our range never goes negative */
  132. 	*range = 0;
  133. if (*range != 0)
  134. 	delay_output();
  135. return TRUE;
  136. }

mhurtle_step

  1. STATIC_OVL boolean
  2. mhurtle_step(arg, x, y)
  3. genericptr_t arg;
  4. int x, y;
  5. {
  6. 	struct monst *mon = (struct monst *)arg;
  7.  
  8. 	/* TODO: Treat walls, doors, iron bars, pools, lava, etc. specially
  9. 	 * rather than just stopping before.
  10. 	 */
  11. 	if (goodpos(x, y, mon, 0) && m_in_out_region(mon, x, y)) {
  12. 	    remove_monster(mon->mx, mon->my);
  13. 	    newsym(mon->mx, mon->my);
  14. 	    place_monster(mon, x, y);
  15. 	    newsym(mon->mx, mon->my);
  16. 	    set_apparxy(mon);
  17. 	    (void) mintrap(mon);
  18. 	    return TRUE;
  19. 	}
  20. 	return FALSE;
  21. }

hurtle

  1. /*
  2. * The player moves through the air for a few squares as a result of
  3. * throwing or kicking something.
  4. *
  5. * dx and dy should be the direction of the hurtle, not of the original
  6. * kick or throw and be only.
  7. */
  8. void
  9. hurtle(dx, dy, range, verbose)
  10. int dx, dy, range;
  11. boolean verbose;
  12. {
  13. coord uc, cc;
  14.  
  15. /* The chain is stretched vertically, so you shouldn't be able to move
  16. * very far diagonally.  The premise that you should be able to move one
  17. * spot leads to calculations that allow you to only move one spot away
  18. * from the ball, if you are levitating over the ball, or one spot
  19. * towards the ball, if you are at the end of the chain.  Rather than
  20. * bother with all of that, assume that there is no slack in the chain
  21. * for diagonal movement, give the player a message and return.
  22. */
  23. if(Punished && !carried(uball)) {
  24. 	You_feel("a tug from the iron ball.");
  25. 	nomul(0);
  26. 	return;
  27. } else if (u.utrap) {
  28. 	You("are anchored by the %s.",
  29. 	    u.utraptype == TT_WEB ? "web" : u.utraptype == TT_LAVA ? "lava" :
  30. 		u.utraptype == TT_INFLOOR ? surface(u.ux,u.uy) : "trap");
  31. 	nomul(0);
  32. 	return;
  33. }
  34.  
  35. /* make sure dx and dy are [-1,0,1] */
  36. dx = sgn(dx);
  37. dy = sgn(dy);
  38.  
  39. if(!range || (!dx && !dy) || u.ustuck) return; /* paranoia */
  40.  
  41. nomul(-range);
  42. if (verbose)
  43. 	You("%s in the opposite direction.", range > 1 ? "hurtle" : "float");
  44. /* if we're in the midst of shooting multiple projectiles, stop */
  45. if (m_shot.i < m_shot.n) {
  46. 	/* last message before hurtling was "you shoot N arrows" */
  47. 	You("stop %sing after the first %s.",
  48. 	    m_shot.s ? "shoot" : "throw", m_shot.s ? "shot" : "toss");
  49. 	m_shot.n = m_shot.i;	/* make current shot be the last */
  50. }
  51. if (In_sokoban(&u.uz))
  52. 	change_luck(-1);	/* Sokoban guilt */
  53. uc.x = u.ux;
  54. uc.y = u.uy;
  55. /* this setting of cc is only correct if dx and dy are [-1,0,1] only */
  56. cc.x = u.ux + (dx * range);
  57. cc.y = u.uy + (dy * range);
  58. (void) walk_path(&uc, &cc, hurtle_step, (genericptr_t)&range);
  59. }

mhurtle

  1. /* Move a monster through the air for a few squares.
  2. */
  3. void
  4. mhurtle(mon, dx, dy, range)
  5. 	struct monst *mon;
  6. 	int dx, dy, range;
  7. {
  8. coord mc, cc;
  9.  
  10. 	/* At the very least, debilitate the monster */
  11. 	mon->movement = 0;
  12. 	mon->mstun = 1;
  13.  
  14. 	/* Is the monster stuck or too heavy to push?
  15. 	 * (very large monsters have too much inertia, even floaters and flyers)
  16. 	 */
  17. 	if (mon->data->msize >= MZ_HUGE || mon == u.ustuck || mon->mtrapped)
  18. 	    return;
  19.  
  20. /* Make sure dx and dy are [-1,0,1] */
  21. dx = sgn(dx);
  22. dy = sgn(dy);
  23. if(!range || (!dx && !dy)) return; /* paranoia */
  24.  
  25. 	/* Send the monster along the path */
  26. 	mc.x = mon->mx;
  27. 	mc.y = mon->my;
  28. 	cc.x = mon->mx + (dx * range);
  29. 	cc.y = mon->my + (dy * range);
  30. 	(void) walk_path(&mc, &cc, mhurtle_step, (genericptr_t)mon);
  31. 	return;
  32. }

check_shop_obj

  1. STATIC_OVL void
  2. check_shop_obj(obj, x, y, broken)
  3. register struct obj *obj;
  4. register xchar x, y;
  5. register boolean broken;
  6. {
  7. 	struct monst *shkp = shop_keeper(*u.ushops);
  8.  
  9. 	if(!shkp) return;
  10.  
  11. 	if(broken) {
  12. 		if (obj->unpaid) {
  13. 		    (void)stolen_value(obj, u.ux, u.uy,
  14. 				       (boolean)shkp->mpeaceful, FALSE);
  15. 		    subfrombill(obj, shkp);
  16. 		}
  17. 		obj->no_charge = 1;
  18. 		return;
  19. 	}
  20.  
  21. 	if (!costly_spot(x, y) || *in_rooms(x, y, SHOPBASE) != *u.ushops) {
  22. 		/* thrown out of a shop or into a different shop */
  23. 		if (obj->unpaid) {
  24. 		    (void)stolen_value(obj, u.ux, u.uy,
  25. 				       (boolean)shkp->mpeaceful, FALSE);
  26. 		    subfrombill(obj, shkp);
  27. 		}
  28. 	} else {
  29. 		if (costly_spot(u.ux, u.uy) && costly_spot(x, y)) {
  30. 		    if(obj->unpaid) subfrombill(obj, shkp);
  31. 		    else if(!(x == shkp->mx && y == shkp->my))
  32. 			    sellobj(obj, x, y);
  33. 		}
  34. 	}
  35. }

toss_up

  1. /*
  2. * Hero tosses an object upwards with appropriate consequences.
  3. *
  4. * Returns FALSE if the object is gone.
  5. */
  6. STATIC_OVL boolean
  7. toss_up(obj, hitsroof)
  8. struct obj *obj;
  9. boolean hitsroof;
  10. {
  11. const char *almost;
  12. /* note: obj->quan == 1 */
  13.  
  14. if (hitsroof) {
  15. 	if (breaktest(obj)) {
  16. 		pline("%s hits the %s.", Doname2(obj), ceiling(u.ux, u.uy));
  17. 		breakmsg(obj, !Blind);
  18. 		breakobj(obj, u.ux, u.uy, TRUE, TRUE);
  19. 		return FALSE;
  20. 	}
  21. 	almost = "";
  22. } else {
  23. 	almost = " almost";
  24. }
  25. pline("%s%s hits the %s, then falls back on top of your %s.",
  26. 	  Doname2(obj), almost, ceiling(u.ux,u.uy), body_part(HEAD));
  27.  
  28. /* object now hits you */
  29.  
  30. if (obj->oclass == POTION_CLASS) {
  31. 	potionhit(&youmonst, obj, TRUE);
  32. } else if (breaktest(obj)) {
  33. 	int otyp = obj->otyp, ocorpsenm = obj->corpsenm;
  34. 	int blindinc;
  35.  
  36. 	/* need to check for blindness result prior to destroying obj */
  37. 	blindinc = (otyp == CREAM_PIE || otyp == BLINDING_VENOM) &&
  38. 		   /* AT_WEAP is ok here even if attack type was AT_SPIT */
  39. 		   can_blnd(&youmonst, &youmonst, AT_WEAP, obj) ? rnd(25) : 0;
  40.  
  41. 	breakmsg(obj, !Blind);
  42. 	breakobj(obj, u.ux, u.uy, TRUE, TRUE);
  43. 	obj = 0;	/* it's now gone */
  44. 	switch (otyp) {
  45. 	case EGG:
  46. 		if (touch_petrifies(&mons[ocorpsenm]) &&
  47. 		    !uarmh && !Stone_resistance &&
  48. 		    !(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM)))
  49. 		goto petrify;
  50. 	case CREAM_PIE:
  51. 	case BLINDING_VENOM:
  52. 		pline("You've got it all over your %s!", body_part(FACE));
  53. 		if (blindinc) {
  54. 		    if (otyp == BLINDING_VENOM && !Blind)
  55. 			pline("It blinds you!");
  56. 		    u.ucreamed += blindinc;
  57. 		    make_blinded(Blinded + (long)blindinc, FALSE);
  58. 		    if (!Blind) Your(vision_clears);
  59. 		}
  60. 		break;
  61. 	default:
  62. 		break;
  63. 	}
  64. 	return FALSE;
  65. } else {		/* neither potion nor other breaking object */
  66. 	boolean less_damage = uarmh && is_metallic(uarmh), artimsg = FALSE;
  67. 	int dmg = dmgval(obj, &youmonst);
  68.  
  69. 	if (obj->oartifact)
  70. 	    /* need a fake die roll here; rn1(18,2) avoids 1 and 20 */
  71. 	    artimsg = artifact_hit((struct monst *)0, &youmonst,
  72. 				   obj, &dmg, rn1(18,2));
  73.  
  74. 	if (!dmg) {	/* probably wasn't a weapon; base damage on weight */
  75. 	    dmg = (int) obj->owt / 100;
  76. 	    if (dmg < 1) dmg = 1;
  77. 	    else if (dmg > 6) dmg = 6;
  78. 	    if (youmonst.data == &mons[PM_SHADE] &&
  79. 		    objects[obj->otyp].oc_material != SILVER)
  80. 		dmg = 0;
  81. 	}
  82. 	if (dmg > 1 && less_damage) dmg = 1;
  83. 	if (dmg > 0) dmg += u.udaminc;
  84. 	if (dmg < 0) dmg = 0;	/* beware negative rings of increase damage */
  85. 	if (Half_physical_damage) dmg = (dmg + 1) / 2;
  86.  
  87. 	if (uarmh) {
  88. 	    if (less_damage && dmg < (Upolyd ? u.mh : u.uhp)) {
  89. 		if (!artimsg)
  90. 		    pline("Fortunately, you are wearing a hard helmet.");
  91. 	    } else if (flags.verbose &&
  92. 		    !(obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])))
  93. 		Your("%s does not protect you.", xname(uarmh));
  94. 	} else if (obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])) {
  95. 	    if (!Stone_resistance &&
  96. 		    !(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) {
  97. petrify:
  98. 		killer_format = KILLED_BY;
  99. 		killer = "elementary physics";	/* "what goes up..." */
  100. 		You("turn to stone.");
  101. 		if (obj) dropy(obj);	/* bypass most of hitfloor() */
  102. 		done(STONING);
  103. 		return obj ? TRUE : FALSE;
  104. 	    }
  105. 	}
  106. 	hitfloor(obj);
  107. 	losehp(dmg, "falling object", KILLED_BY_AN);
  108. }
  109. return TRUE;
  110. }

throwing_weapon

  1. /* return true for weapon meant to be thrown; excludes ammo */
  2. STATIC_OVL boolean
  3. throwing_weapon(obj)
  4. struct obj *obj;
  5. {
  6. 	return (is_missile(obj) || is_spear(obj) ||
  7. 		/* daggers and knife (excludes scalpel) */
  8. 		(is_blade(obj) && !is_sword(obj) &&
  9. 		 (objects[obj->otyp].oc_dir & PIERCE)) ||
  10. 		/* special cases [might want to add AXE] */
  11. 		obj->otyp == WAR_HAMMER || obj->otyp == AKLYS);
  12. }

sho_obj_return_to_u

  1. /* the currently thrown object is returning to you (not for boomerangs) */
  2. STATIC_OVL void
  3. sho_obj_return_to_u(obj)
  4. struct obj *obj;
  5. {
  6. /* might already be our location (bounced off a wall) */
  7. if (bhitpos.x != u.ux || bhitpos.y != u.uy) {
  8. 	int x = bhitpos.x - u.dx, y = bhitpos.y - u.dy;
  9.  
  10. 	tmp_at(DISP_FLASH, obj_to_glyph(obj));
  11. 	while(x != u.ux || y != u.uy) {
  12. 	    tmp_at(x, y);
  13. 	    delay_output();
  14. 	    x -= u.dx; y -= u.dy;
  15. 	}
  16. 	tmp_at(DISP_END, 0);
  17. }
  18. }

throwit

  1. void
  2. throwit(obj, wep_mask, twoweap)
  3. register struct obj *obj;
  4. long wep_mask;	/* used to re-equip returning boomerang */
  5. boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */
  6. {
  7. 	register struct monst *mon;
  8. 	register int range, urange;
  9. 	boolean impaired = (Confusion || Stunned || Blind ||
  10. 			   Hallucination || Fumbling);
  11.  
  12. 	if ((obj->cursed || obj->greased) && (u.dx || u.dy) && !rn2(7)) {
  13. 	    boolean slipok = TRUE;
  14. 	    if (ammo_and_launcher(obj, uwep))
  15. 		pline("%s!", Tobjnam(obj, "misfire"));
  16. 	    else {
  17. 		/* only slip if it's greased or meant to be thrown */
  18. 		if (obj->greased || throwing_weapon(obj))
  19. 		    /* BUG: this message is grammatically incorrect if obj has
  20. 		       a plural name; greased gloves or boots for instance. */
  21. 		    pline("%s as you throw it!", Tobjnam(obj, "slip"));
  22. 		else slipok = FALSE;
  23. 	    }
  24. 	    if (slipok) {
  25. 		u.dx = rn2(3)-1;
  26. 		u.dy = rn2(3)-1;
  27. 		if (!u.dx && !u.dy) u.dz = 1;
  28. 		impaired = TRUE;
  29. 	    }
  30. 	}
  31.  
  32. 	if ((u.dx || u.dy || (u.dz < 1)) &&
  33. 	    calc_capacity((int)obj->owt) > SLT_ENCUMBER &&
  34. 	    (Upolyd ? (u.mh < 5 && u.mh != u.mhmax)
  35. 	     : (u.uhp < 10 && u.uhp != u.uhpmax)) &&
  36. 	    obj->owt > (unsigned)((Upolyd ? u.mh : u.uhp) * 2) &&
  37. 	    !Is_airlevel(&u.uz)) {
  38. 	    You("have so little stamina, %s drops from your grasp.",
  39. 		the(xname(obj)));
  40. 	    exercise(A_CON, FALSE);
  41. 	    u.dx = u.dy = 0;
  42. 	    u.dz = 1;
  43. 	}
  44.  
  45. 	thrownobj = obj;
  46.  
  47. 	if(u.uswallow) {
  48. 		mon = u.ustuck;
  49. 		bhitpos.x = mon->mx;
  50. 		bhitpos.y = mon->my;
  51. 	} else if(u.dz) {
  52. 	    if (u.dz < 0 && Role_if(PM_VALKYRIE) &&
  53. 		    obj->oartifact == ART_MJOLLNIR && !impaired) {
  54. 		pline("%s the %s and returns to your hand!",
  55. 		      Tobjnam(obj, "hit"), ceiling(u.ux,u.uy));
  56. 		obj = addinv(obj);
  57. 		(void) encumber_msg();
  58. 		setuwep(obj);
  59. 		u.twoweap = twoweap;
  60. 	    } else if (u.dz < 0 && !Is_airlevel(&u.uz) &&
  61. 		    !Underwater && !Is_waterlevel(&u.uz)) {
  62. 		(void) toss_up(obj, rn2(5));
  63. 	    } else {
  64. 		hitfloor(obj);
  65. 	    }
  66. 	    thrownobj = (struct obj*)0;
  67. 	    return;
  68.  
  69. 	} else if(obj->otyp == BOOMERANG && !Underwater) {
  70. 		if(Is_airlevel(&u.uz) || Levitation)
  71. 		    hurtle(-u.dx, -u.dy, 1, TRUE);
  72. 		mon = boomhit(u.dx, u.dy);
  73. 		if(mon == &youmonst) {		/* the thing was caught */
  74. 			exercise(A_DEX, TRUE);
  75. 			obj = addinv(obj);
  76. 			(void) encumber_msg();
  77. 			if (wep_mask && !(obj->owornmask & wep_mask)) {
  78. 			    setworn(obj, wep_mask);
  79. 			    u.twoweap = twoweap;
  80. 			}
  81. 			thrownobj = (struct obj*)0;
  82. 			return;
  83. 		}
  84. 	} else {
  85. 		urange = (int)(ACURRSTR)/2;
  86. 		/* balls are easy to throw or at least roll */
  87. 		/* also, this insures the maximum range of a ball is greater
  88. 		 * than 1, so the effects from throwing attached balls are
  89. 		 * actually possible
  90. 		 */
  91. 		if (obj->otyp == HEAVY_IRON_BALL)
  92. 			range = urange - (int)(obj->owt/100);
  93. 		else
  94. 			range = urange - (int)(obj->owt/40);
  95. 		if (obj == uball) {
  96. 			if (u.ustuck) range = 1;
  97. 			else if (range >= 5) range = 5;
  98. 		}
  99. 		if (range < 1) range = 1;
  100.  
  101. 		if (is_ammo(obj)) {
  102. 		    if (ammo_and_launcher(obj, uwep))
  103. 			range++;
  104. 		    else if (obj->oclass != GEM_CLASS)
  105. 			range /= 2;
  106. 		}
  107.  
  108. 		if (Is_airlevel(&u.uz) || Levitation) {
  109. 		    /* action, reaction... */
  110. 		    urange -= range;
  111. 		    if(urange < 1) urange = 1;
  112. 		    range -= urange;
  113. 		    if(range < 1) range = 1;
  114. 		}
  115.  
  116. 		if (obj->otyp == BOULDER)
  117. 		    range = 20;		/* you must be giant */
  118. 		else if (obj->oartifact == ART_MJOLLNIR)
  119. 		    range = (range + 1) / 2;	/* it's heavy */
  120. 		else if (obj == uball && u.utrap && u.utraptype == TT_INFLOOR)
  121. 		    range = 1;
  122.  
  123. 		if (Underwater) range = 1;
  124.  
  125. 		mon = bhit(u.dx, u.dy, range, THROWN_WEAPON,
  126. 			   (int FDECL((*),(MONST_P,OBJ_P)))0,
  127. 			   (int FDECL((*),(OBJ_P,OBJ_P)))0,
  128. 			   obj);
  129.  
  130. 		/* have to do this after bhit() so u.ux & u.uy are correct */
  131. 		if(Is_airlevel(&u.uz) || Levitation)
  132. 		    hurtle(-u.dx, -u.dy, urange, TRUE);
  133. 	}
  134.  
  135. 	if (mon) {
  136. 		boolean obj_gone;
  137.  
  138. 		if (mon->isshk &&
  139. 		    obj->where == OBJ_MINVENT && obj->ocarry == mon) {
  140. 		    thrownobj = (struct obj*)0;
  141. 		    return;		/* alert shk caught it */
  142. 		}
  143. 		(void) snuff_candle(obj);
  144. 		notonhead = (bhitpos.x != mon->mx || bhitpos.y != mon->my);
  145. 		obj_gone = thitmonst(mon, obj);
  146. 		/* Monster may have been tamed; this frees old mon */
  147. 		mon = m_at(bhitpos.x, bhitpos.y);
  148.  
  149. 		/* [perhaps this should be moved into thitmonst or hmon] */
  150. 		if (mon && mon->isshk &&
  151. 			(!inside_shop(u.ux, u.uy) ||
  152. 			 !index(in_rooms(mon->mx, mon->my, SHOPBASE), *u.ushops)))
  153. 		    hot_pursuit(mon);
  154.  
  155. 		if (obj_gone) return;
  156. 	}
  157.  
  158. 	if (u.uswallow) {
  159. 		/* ball is not picked up by monster */
  160. 		if (obj != uball) (void) mpickobj(u.ustuck,obj);
  161. 	} else {
  162. 		/* the code following might become part of dropy() */
  163. 		if (obj->oartifact == ART_MJOLLNIR &&
  164. 			Role_if(PM_VALKYRIE) && rn2(100)) {
  165. 		    /* we must be wearing Gauntlets of Power to get here */
  166. 		    sho_obj_return_to_u(obj);	    /* display its flight */
  167.  
  168. 		    if (!impaired && rn2(100)) {
  169. 			pline("%s to your hand!", Tobjnam(obj, "return"));
  170. 			obj = addinv(obj);
  171. 			(void) encumber_msg();
  172. 			setuwep(obj);
  173. 			u.twoweap = twoweap;
  174. 			if(cansee(bhitpos.x, bhitpos.y))
  175. 			    newsym(bhitpos.x,bhitpos.y);
  176. 		    } else {
  177. 			int dmg = rn2(2);
  178. 			if (!dmg) {
  179. 			    pline(Blind ? "%s lands %s your %s." :
  180. 					"%s back to you, landing %s your %s.",
  181. 				  Blind ? Something : Tobjnam(obj, "return"),
  182. 				  Levitation ? "beneath" : "at",
  183. 				  makeplural(body_part(FOOT)));
  184. 			} else {
  185. 			    dmg += rnd(3);
  186. 			    pline(Blind ? "%s your %s!" :
  187. 					"%s back toward you, hitting your %s!",
  188. 				  Tobjnam(obj, Blind ? "hit" : "fly"),
  189. 				  body_part(ARM));
  190. 			    (void) artifact_hit((struct monst *)0,
  191. 						&youmonst, obj, &dmg, 0);
  192. 			    losehp(dmg, xname(obj),
  193. 				obj_is_pname(obj) ? KILLED_BY : KILLED_BY_AN);
  194. 			}
  195. 			if (ship_object(obj, u.ux, u.uy, FALSE)) {
  196. 		    	    thrownobj = (struct obj*)0;
  197. 			    return;
  198. 			}
  199. 			dropy(obj);
  200. 		    }
  201. 		    thrownobj = (struct obj*)0;
  202. 		    return;
  203. 		}
  204.  
  205. 		if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ) &&
  206. 			breaktest(obj)) {
  207. 		    tmp_at(DISP_FLASH, obj_to_glyph(obj));
  208. 		    tmp_at(bhitpos.x, bhitpos.y);
  209. 		    delay_output();
  210. 		    tmp_at(DISP_END, 0);
  211. 		    breakmsg(obj, cansee(bhitpos.x, bhitpos.y));
  212. 		    breakobj(obj, bhitpos.x, bhitpos.y, TRUE, TRUE);
  213. 		    return;
  214. 		}
  215. 		if(flooreffects(obj,bhitpos.x,bhitpos.y,"fall")) return;
  216. 		obj_no_longer_held(obj);
  217. 		if (mon && mon->isshk && is_pick(obj)) {
  218. 		    if (cansee(bhitpos.x, bhitpos.y))
  219. 			pline("%s snatches up %s.",
  220. 			      Monnam(mon), the(xname(obj)));
  221. 		    if(*u.ushops)
  222. 			check_shop_obj(obj, bhitpos.x, bhitpos.y, FALSE);
  223. 		    (void) mpickobj(mon, obj);	/* may merge and free obj */
  224. 		    thrownobj = (struct obj*)0;
  225. 		    return;
  226. 		}
  227. 		(void) snuff_candle(obj);
  228. 		if (!mon && ship_object(obj, bhitpos.x, bhitpos.y, FALSE)) {
  229. 		    thrownobj = (struct obj*)0;
  230. 		    return;
  231. 		}
  232. 		thrownobj = (struct obj*)0;
  233. 		place_object(obj, bhitpos.x, bhitpos.y);
  234. 		if(*u.ushops && obj != uball)
  235. 		    check_shop_obj(obj, bhitpos.x, bhitpos.y, FALSE);
  236.  
  237. 		stackobj(obj);
  238. 		if (obj == uball)
  239. 		    drop_ball(bhitpos.x, bhitpos.y);
  240. 		if (cansee(bhitpos.x, bhitpos.y))
  241. 		    newsym(bhitpos.x,bhitpos.y);
  242. 		if (obj_sheds_light(obj))
  243. 		    vision_full_recalc = 1;
  244. 		if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ))
  245. 		    container_impact_dmg(obj);
  246. 	}
  247. }

omon_adj

  1. /* an object may hit a monster; various factors adjust the chance of hitting */
  2. int
  3. omon_adj(mon, obj, mon_notices)
  4. struct monst *mon;
  5. struct obj *obj;
  6. boolean mon_notices;
  7. {
  8. 	int tmp = 0;
  9.  
  10. 	/* size of target affects the chance of hitting */
  11. 	tmp += (mon->data->msize - MZ_MEDIUM);		/* -2..+5 */
  12. 	/* sleeping target is more likely to be hit */
  13. 	if (mon->msleeping) {
  14. 	    tmp += 2;
  15. 	    if (mon_notices) mon->msleeping = 0;
  16. 	}
  17. 	/* ditto for immobilized target */
  18. 	if (!mon->mcanmove || !mon->data->mmove) {
  19. 	    tmp += 4;
  20. 	    if (mon_notices && mon->data->mmove && !rn2(10)) {
  21. 		mon->mcanmove = 1;
  22. 		mon->mfrozen = 0;
  23. 	    }
  24. 	}
  25. 	/* some objects are more likely to hit than others */
  26. 	switch (obj->otyp) {
  27. 	case HEAVY_IRON_BALL:
  28. 	    if (obj != uball) tmp += 2;
  29. 	    break;
  30. 	case BOULDER:
  31. 	    tmp += 6;
  32. 	    break;
  33. 	default:
  34. 	    if (obj->oclass == WEAPON_CLASS || is_weptool(obj) ||
  35. 		    obj->oclass == GEM_CLASS)
  36. 		tmp += hitval(obj, mon);
  37. 	    break;
  38. 	}
  39. 	return tmp;
  40. }

tmiss

  1. /* thrown object misses target monster */
  2. STATIC_OVL void
  3. tmiss(obj, mon)
  4. struct obj *obj;
  5. struct monst *mon;
  6. {
  7. const char *missile = mshot_xname(obj);
  8.  
  9. /* If the target can't be seen or doesn't look like a valid target,
  10. avoid "the arrow misses it," or worse, "the arrows misses the mimic."
  11. An attentive player will still notice that this is different from
  12. an arrow just landing short of any target (no message in that case),
  13. so will realize that there is a valid target here anyway. */
  14. if (!canseemon(mon) || (mon->m_ap_type && mon->m_ap_type != M_AP_MONSTER))
  15. 	pline("%s %s.", The(missile), otense(obj, "miss"));
  16. else
  17. 	miss(missile, mon);
  18. if (!rn2(3)) wakeup(mon);
  19. return;
  20. }

thitmonst

  1. #define quest_arti_hits_leader(obj,mon)	\
  2. (obj->oartifact && is_quest_artifact(obj) && (mon->data->msound == MS_LEADER))
  3.  
  4. /*
  5. * Object thrown by player arrives at monster's location.
  6. * Return 1 if obj has disappeared or otherwise been taken care of,
  7. * 0 if caller must take care of it.
  8. */
  9. int
  10. thitmonst(mon, obj)
  11. register struct monst *mon;
  12. register struct obj   *obj;
  13. {
  14. 	register int	tmp; /* Base chance to hit */
  15. 	register int	disttmp; /* distance modifier */
  16. 	int otyp = obj->otyp;
  17. 	boolean guaranteed_hit = (u.uswallow && mon == u.ustuck);
  18.  
  19. 	/* Differences from melee weapons:
  20. 	 *
  21. 	 * Dex still gives a bonus, but strength does not.
  22. 	 * Polymorphed players lacking attacks may still throw.
  23. 	 * There's a base -1 to hit.
  24. 	 * No bonuses for fleeing or stunned targets (they don't dodge
  25. 	 *    melee blows as readily, but dodging arrows is hard anyway).
  26. 	 * Not affected by traps, etc.
  27. 	 * Certain items which don't in themselves do damage ignore tmp.
  28. 	 * Distance and monster size affect chance to hit.
  29. 	 */
  30. 	tmp = -1 + Luck + find_mac(mon) + u.uhitinc +
  31. 			maybe_polyd(youmonst.data->mlevel, u.ulevel);
  32. 	if (ACURR(A_DEX) < 4) tmp -= 3;
  33. 	else if (ACURR(A_DEX) < 6) tmp -= 2;
  34. 	else if (ACURR(A_DEX) < 8) tmp -= 1;
  35. 	else if (ACURR(A_DEX) >= 14) tmp += (ACURR(A_DEX) - 14);
  36.  
  37. 	/* Modify to-hit depending on distance; but keep it sane.
  38. 	 * Polearms get a distance penalty even when wielded; it's
  39. 	 * hard to hit at a distance.
  40. 	 */
  41. 	disttmp = 3 - distmin(u.ux, u.uy, mon->mx, mon->my);
  42. 	if(disttmp < -4) disttmp = -4;
  43. 	tmp += disttmp;
  44.  
  45. 	/* gloves are a hinderance to proper use of bows */
  46. 	if (uarmg && uwep && objects[uwep->otyp].oc_skill == P_BOW) {
  47. 	    switch (uarmg->otyp) {
  48. 	    case GAUNTLETS_OF_POWER:    /* metal */
  49. 		tmp -= 2;
  50. 		break;
  51. 	    case GAUNTLETS_OF_FUMBLING:
  52. 		tmp -= 3;
  53. 		break;
  54. 	    case LEATHER_GLOVES:
  55. 	    case GAUNTLETS_OF_DEXTERITY:
  56. 		break;
  57. 	    default:
  58. 		impossible("Unknown type of gloves (%d)", uarmg->otyp);
  59. 		break;
  60. 	    }
  61. 	}
  62.  
  63. 	tmp += omon_adj(mon, obj, TRUE);
  64. 	if (is_orc(mon->data) && maybe_polyd(is_elf(youmonst.data),
  65. 			Race_if(PM_ELF)))
  66. 	    tmp++;
  67. 	if (guaranteed_hit) {
  68. 	    tmp += 1000; /* Guaranteed hit */
  69. 	}
  70.  
  71. 	if (obj->oclass == GEM_CLASS && is_unicorn(mon->data)) {
  72. 	    if (mon->mtame) {
  73. 		pline("%s catches and drops %s.", Monnam(mon), the(xname(obj)));
  74. 		return 0;
  75. 	    } else {
  76. 		pline("%s catches %s.", Monnam(mon), the(xname(obj)));
  77. 		return gem_accept(mon, obj);
  78. 	    }
  79. 	}
  80.  
  81. 	/* don't make game unwinnable if naive player throws artifact
  82. 	   at leader.... */
  83. 	if (quest_arti_hits_leader(obj, mon)) {
  84. 	    /* not wakeup(), which angers non-tame monsters */
  85. 	    mon->msleeping = 0;
  86. 	    mon->mstrategy &= ~STRAT_WAITMASK;
  87.  
  88. 	    if (mon->mcanmove) {
  89. 		pline("%s catches %s.", Monnam(mon), the(xname(obj)));
  90. 		if (mon->mpeaceful) {
  91. 		    boolean next2u = monnear(mon, u.ux, u.uy);
  92.  
  93. 		    finish_quest(obj);	/* acknowledge quest completion */
  94. 		    pline("%s %s %s back to you.", Monnam(mon),
  95. 			  (next2u ? "hands" : "tosses"), the(xname(obj)));
  96. 		    if (!next2u) sho_obj_return_to_u(obj);
  97. 		    obj = addinv(obj);	/* back into your inventory */
  98. 		    (void) encumber_msg();
  99. 		} else {
  100. 		    /* angry leader caught it and isn't returning it */
  101. 		    (void) mpickobj(mon, obj);
  102. 		}
  103. 		return 1;		/* caller doesn't need to place it */
  104. 	    }
  105. 	    return(0);
  106. 	}
  107.  
  108. 	if (obj->oclass == WEAPON_CLASS || is_weptool(obj) ||
  109. 		obj->oclass == GEM_CLASS) {
  110. 	    if (is_ammo(obj)) {
  111. 		if (!ammo_and_launcher(obj, uwep)) {
  112. 		    tmp -= 4;
  113. 		} else {
  114. 		    tmp += uwep->spe - greatest_erosion(uwep);
  115. 		    tmp += weapon_hit_bonus(uwep);
  116. 		    if (uwep->oartifact) tmp += spec_abon(uwep, mon);
  117. 		    /*
  118. 		     * Elves and Samurais are highly trained w/bows,
  119. 		     * especially their own special types of bow.
  120. 		     * Polymorphing won't make you a bow expert.
  121. 		     */
  122. 		    if ((Race_if(PM_ELF) || Role_if(PM_SAMURAI)) &&
  123. 				(!Upolyd || your_race(youmonst.data)) &&
  124. 				objects[uwep->otyp].oc_skill == P_BOW) {
  125. 			tmp++;
  126. 			if (Race_if(PM_ELF) && uwep->otyp == ELVEN_BOW)
  127. 			    tmp++;
  128. 			else if (Role_if(PM_SAMURAI) && uwep->otyp == YUMI)
  129. 			    tmp++;
  130. 		    }
  131. 		}
  132. 	    } else {
  133. 		if (otyp == BOOMERANG)		/* arbitrary */
  134. 		    tmp += 4;
  135. 		else if (throwing_weapon(obj))	/* meant to be thrown */
  136. 		    tmp += 2;
  137. 		else				/* not meant to be thrown */
  138. 		    tmp -= 2;
  139. 		/* we know we're dealing with a weapon or weptool handled
  140. 		   by WEAPON_SKILLS once ammo objects have been excluded */
  141. 		tmp += weapon_hit_bonus(obj);
  142. 	    }
  143.  
  144. 	    if (tmp >= rnd(20)) {
  145. 		if (hmon(mon,obj,1)) {	/* mon still alive */
  146. 		    cutworm(mon, bhitpos.x, bhitpos.y, obj);
  147. 		}
  148. 		exercise(A_DEX, TRUE);
  149. 		/* projectiles other than magic stones
  150. 		   sometimes disappear when thrown */
  151. 		if (objects[otyp].oc_skill < P_NONE &&
  152. 				objects[otyp].oc_skill > -P_BOOMERANG &&
  153. 				!objects[otyp].oc_magic) {
  154. 		    /* we were breaking 2/3 of everything unconditionally.
  155. 		     * we still don't want anything to survive unconditionally,
  156. 		     * but we need ammo to stay around longer on average.
  157. 		     */
  158. 		    int broken, chance;
  159. 		    chance = 3 + greatest_erosion(obj) - obj->spe;
  160. 		    if (chance > 1)
  161. 			broken = rn2(chance);
  162. 		    else
  163. 			broken = !rn2(4);
  164. 		    if (obj->blessed && !rnl(4))
  165. 			broken = 0;
  166.  
  167. 		    if (broken) {
  168. 			if (*u.ushops)
  169. 			    check_shop_obj(obj, bhitpos.x,bhitpos.y, TRUE);
  170. 			obfree(obj, (struct obj *)0);
  171. 			return 1;
  172. 		    }
  173. 		}
  174. 		passive_obj(mon, obj, (struct attack *)0);
  175. 	    } else {
  176. 		tmiss(obj, mon);
  177. 	    }
  178.  
  179. 	} else if (otyp == HEAVY_IRON_BALL) {
  180. 	    exercise(A_STR, TRUE);
  181. 	    if (tmp >= rnd(20)) {
  182. 		int was_swallowed = guaranteed_hit;
  183.  
  184. 		exercise(A_DEX, TRUE);
  185. 		if (!hmon(mon,obj,1)) {		/* mon killed */
  186. 		    if (was_swallowed && !u.uswallow && obj == uball)
  187. 			return 1;	/* already did placebc() */
  188. 		}
  189. 	    } else {
  190. 		tmiss(obj, mon);
  191. 	    }
  192.  
  193. 	} else if (otyp == BOULDER) {
  194. 	    exercise(A_STR, TRUE);
  195. 	    if (tmp >= rnd(20)) {
  196. 		exercise(A_DEX, TRUE);
  197. 		(void) hmon(mon,obj,1);
  198. 	    } else {
  199. 		tmiss(obj, mon);
  200. 	    }
  201.  
  202. 	} else if ((otyp == EGG || otyp == CREAM_PIE ||
  203. 		    otyp == BLINDING_VENOM || otyp == ACID_VENOM) &&
  204. 		(guaranteed_hit || ACURR(A_DEX) > rnd(25))) {
  205. 	    (void) hmon(mon, obj, 1);
  206. 	    return 1;	/* hmon used it up */
  207.  
  208. 	} else if (obj->oclass == POTION_CLASS &&
  209. 		(guaranteed_hit || ACURR(A_DEX) > rnd(25))) {
  210. 	    potionhit(mon, obj, TRUE);
  211. 	    return 1;
  212.  
  213. 	} else if (befriend_with_obj(mon->data, obj) ||
  214. 		   (mon->mtame && dogfood(mon, obj) <= ACCFOOD)) {
  215. 	    if (tamedog(mon, obj))
  216. 		return 1;           	/* obj is gone */
  217. 	    else {
  218. 		/* not tmiss(), which angers non-tame monsters */
  219. 		miss(xname(obj), mon);
  220. 		mon->msleeping = 0;
  221. 		mon->mstrategy &= ~STRAT_WAITMASK;
  222. 	    }
  223. 	} else if (guaranteed_hit) {
  224. 	    /* this assumes that guaranteed_hit is due to swallowing */
  225. 	    wakeup(mon);
  226. 	    if (obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])) {
  227. 		if (is_animal(u.ustuck->data)) {
  228. 			minstapetrify(u.ustuck, TRUE);
  229. 			/* Don't leave a cockatrice corpse available in a statue */
  230. 			if (!u.uswallow) {
  231. 				delobj(obj);
  232. 				return 1;
  233. 			}
  234. 	    	}
  235. 	    }
  236. 	    pline("%s into %s %s.",
  237. 		Tobjnam(obj, "vanish"), s_suffix(mon_nam(mon)),
  238. 		is_animal(u.ustuck->data) ? "entrails" : "currents");
  239. 	} else {
  240. 	    tmiss(obj, mon);
  241. 	}
  242.  
  243. 	return 0;
  244. }

gem_accept

  1. STATIC_OVL int
  2. gem_accept(mon, obj)
  3. register struct monst *mon;
  4. register struct obj *obj;
  5. {
  6. 	char buf[BUFSZ];
  7. 	boolean is_buddy = sgn(mon->data->maligntyp) == sgn(u.ualign.type);
  8. 	boolean is_gem = objects[obj->otyp].oc_material == GEMSTONE;
  9. 	int ret = 0;
  10. 	static NEARDATA const char nogood[] = " is not interested in your junk.";
  11. 	static NEARDATA const char acceptgift[] = " accepts your gift.";
  12. 	static NEARDATA const char maybeluck[] = " hesitatingly";
  13. 	static NEARDATA const char noluck[] = " graciously";
  14. 	static NEARDATA const char addluck[] = " gratefully";
  15.  
  16. 	Strcpy(buf,Monnam(mon));
  17. 	mon->mpeaceful = 1;
  18. 	mon->mavenge = 0;
  19.  
  20. 	/* object properly identified */
  21. 	if(obj->dknown && objects[obj->otyp].oc_name_known) {
  22. 		if(is_gem) {
  23. 			if(is_buddy) {
  24. 				Strcat(buf,addluck);
  25. 				change_luck(5);
  26. 			} else {
  27. 				Strcat(buf,maybeluck);
  28. 				change_luck(rn2(7)-3);
  29. 			}
  30. 		} else {
  31. 			Strcat(buf,nogood);
  32. 			goto nopick;
  33. 		}
  34. 	/* making guesses */
  35. 	} else if(obj->onamelth || objects[obj->otyp].oc_uname) {
  36. 		if(is_gem) {
  37. 			if(is_buddy) {
  38. 				Strcat(buf,addluck);
  39. 				change_luck(2);
  40. 			} else {
  41. 				Strcat(buf,maybeluck);
  42. 				change_luck(rn2(3)-1);
  43. 			}
  44. 		} else {
  45. 			Strcat(buf,nogood);
  46. 			goto nopick;
  47. 		}
  48. 	/* value completely unknown to @ */
  49. 	} else {
  50. 		if(is_gem) {
  51. 			if(is_buddy) {
  52. 				Strcat(buf,addluck);
  53. 				change_luck(1);
  54. 			} else {
  55. 				Strcat(buf,maybeluck);
  56. 				change_luck(rn2(3)-1);
  57. 			}
  58. 		} else {
  59. 			Strcat(buf,noluck);
  60. 		}
  61. 	}
  62. 	Strcat(buf,acceptgift);
  63. 	if(*u.ushops) check_shop_obj(obj, mon->mx, mon->my, TRUE);
  64. 	(void) mpickobj(mon, obj);	/* may merge and free obj */
  65. 	ret = 1;
  66.  
  67. nopick:
  68. 	if(!Blind) pline("%s", buf);
  69. 	if (!tele_restrict(mon)) (void) rloc(mon, FALSE);
  70. 	return(ret);
  71. }

Missile breaking

  1. /*
  2. * Comments about the restructuring of the old breaks() routine.
  3. *
  4. * There are now three distinct phases to object breaking:
  5. *     breaktest() - which makes the check/decision about whether the
  6. *                   object is going to break.
  7. *     breakmsg()  - which outputs a message about the breakage,
  8. *                   appropriate for that particular object. Should
  9. *                   only be called after a positve breaktest().
  10. *                   on the object and, if it going to be called,
  11. *                   it must be called before calling breakobj().
  12. *                   Calling breakmsg() is optional.
  13. *     breakobj()  - which actually does the breakage and the side-effects
  14. *                   of breaking that particular object. This should
  15. *                   only be called after a positive breaktest() on the
  16. *                   object.
  17. *
  18. * Each of the above routines is currently static to this source module.
  19. * There are two routines callable from outside this source module which
  20. * perform the routines above in the correct sequence.
  21. *
  22. *   hero_breaks() - called when an object is to be broken as a result
  23. *                   of something that the hero has done. (throwing it,
  24. *                   kicking it, etc.)
  25. *   breaks()      - called when an object is to be broken for some
  26. *                   reason other than the hero doing something to it.
  27. */

hero_breaks

  1. /*
  2. * The hero causes breakage of an object (throwing, dropping it, etc.)
  3. * Return 0 if the object didn't break, 1 if the object broke.
  4. */
  5. int
  6. hero_breaks(obj, x, y, from_invent)
  7. struct obj *obj;
  8. xchar x, y;		/* object location (ox, oy may not be right) */
  9. boolean from_invent;	/* thrown or dropped by player; maybe on shop bill */
  10. {
  11. 	boolean in_view = !Blind;
  12. 	if (!breaktest(obj)) return 0;
  13. 	breakmsg(obj, in_view);
  14. 	breakobj(obj, x, y, TRUE, from_invent);
  15. 	return 1;
  16. }

breaks

  1. /*
  2. * The object is going to break for a reason other than the hero doing
  3. * something to it.
  4. * Return 0 if the object doesn't break, 1 if the object broke.
  5. */
  6. int
  7. breaks(obj, x, y)
  8. struct obj *obj;
  9. xchar x, y;		/* object location (ox, oy may not be right) */
  10. {
  11. 	boolean in_view = Blind ? FALSE : cansee(x, y);
  12.  
  13. 	if (!breaktest(obj)) return 0;
  14. 	breakmsg(obj, in_view);
  15. 	breakobj(obj, x, y, FALSE, FALSE);
  16. 	return 1;
  17. }

breakobj

  1. /*
  2. * Unconditionally break an object. Assumes all resistance checks
  3. * and break messages have been delivered prior to getting here.
  4. */
  5. STATIC_OVL void
  6. breakobj(obj, x, y, hero_caused, from_invent)
  7. struct obj *obj;
  8. xchar x, y;		/* object location (ox, oy may not be right) */
  9. boolean hero_caused;	/* is this the hero's fault? */
  10. boolean from_invent;
  11. {
  12. 	switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) {
  13. 		case MIRROR:
  14. 			if (hero_caused)
  15. 			    change_luck(-2);
  16. 			break;
  17. 		case POT_WATER:		/* really, all potions */
  18. 			if (obj->otyp == POT_OIL && obj->lamplit) {
  19. 			    splatter_burning_oil(x,y);
  20. 			} else if (distu(x,y) <= 2) {
  21. 			    if (!breathless(youmonst.data) || haseyes(youmonst.data)) {
  22. 				if (obj->otyp != POT_WATER) {
  23. 					if (!breathless(youmonst.data))
  24. 			    		     /* [what about "familiar odor" when known?] */
  25. 					    You("smell a peculiar odor...");
  26. 					else {
  27. 					    int numeyes = eyecount(youmonst.data);
  28. 					    Your("%s water%s.",
  29. 						 (numeyes == 1) ? body_part(EYE) :
  30. 							makeplural(body_part(EYE)),
  31. 						 (numeyes == 1) ? "s" : "");
  32. 					}
  33. 				}
  34. 				potionbreathe(obj);
  35. 			    }
  36. 			}
  37. 			/* monster breathing isn't handled... [yet?] */
  38. 			break;
  39. 		case EGG:
  40. 			/* breaking your own eggs is bad luck */
  41. 			if (hero_caused && obj->spe && obj->corpsenm >= LOW_PM)
  42. 			    change_luck((schar) -min(obj->quan, 5L));
  43. 			break;
  44. 	}
  45. 	if (hero_caused) {
  46. 	    if (from_invent) {
  47. 		if (*u.ushops)
  48. 			check_shop_obj(obj, x, y, TRUE);
  49. 	    } else if (!obj->no_charge && costly_spot(x, y)) {
  50. 		/* it is assumed that the obj is a floor-object */
  51. 		char *o_shop = in_rooms(x, y, SHOPBASE);
  52. 		struct monst *shkp = shop_keeper(*o_shop);
  53.  
  54. 		if (shkp) {		/* (implies *o_shop != '\0') */
  55. 		    static NEARDATA long lastmovetime = 0L;
  56. 		    static NEARDATA boolean peaceful_shk = FALSE;
  57. 		    /*  We want to base shk actions on her peacefulness
  58. 			at start of this turn, so that "simultaneous"
  59. 			multiple breakage isn't drastically worse than
  60. 			single breakage.  (ought to be done via ESHK)  */
  61. 		    if (moves != lastmovetime)
  62. 			peaceful_shk = shkp->mpeaceful;
  63. 		    if (stolen_value(obj, x, y, peaceful_shk, FALSE) > 0L &&
  64. 			(*o_shop != u.ushops[0] || !inside_shop(u.ux, u.uy)) &&
  65. 			moves != lastmovetime) make_angry_shk(shkp, x, y);
  66. 		    lastmovetime = moves;
  67. 		}
  68. 	    }
  69. 	}
  70. 	delobj(obj);
  71. }

breaktest

  1. /*
  2. * Check to see if obj is going to break, but don't actually break it.
  3. * Return 0 if the object isn't going to break, 1 if it is.
  4. */
  5. boolean
  6. breaktest(obj)
  7. struct obj *obj;
  8. {
  9. 	if (obj_resists(obj, 1, 99)) return 0;
  10. 	if (objects[obj->otyp].oc_material == GLASS && !obj->oartifact &&
  11. 		obj->oclass != GEM_CLASS)
  12. 	    return 1;
  13. 	switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) {
  14. #ifdef TOURIST
  15. 		case EXPENSIVE_CAMERA:
  16. #endif
  17. 		case POT_WATER:		/* really, all potions */
  18. 		case EGG:
  19. 		case CREAM_PIE:
  20. 		case MELON:
  21. 		case ACID_VENOM:
  22. 		case BLINDING_VENOM:
  23. 			return 1;
  24. 		default:
  25. 			return 0;
  26. 	}
  27. }

breakmsg

  1. STATIC_OVL void
  2. breakmsg(obj, in_view)
  3. struct obj *obj;
  4. boolean in_view;
  5. {
  6. 	const char *to_pieces;
  7.  
  8. 	to_pieces = "";
  9. 	switch (obj->oclass == POTION_CLASS ? POT_WATER : obj->otyp) {
  10. 		default: /* glass or crystal wand */
  11. 		    if (obj->oclass != WAND_CLASS)
  12. 			impossible("breaking odd object?");
  13. 		case CRYSTAL_PLATE_MAIL:
  14. 		case LENSES:
  15. 		case MIRROR:
  16. 		case CRYSTAL_BALL:
  17. #ifdef TOURIST
  18. 		case EXPENSIVE_CAMERA:
  19. #endif
  20. 			to_pieces = " into a thousand pieces";
  21. 			/*FALLTHRU*/
  22. 		case POT_WATER:		/* really, all potions */
  23. 			if (!in_view)
  24. 			    You_hear("%s shatter!", something);
  25. 			else
  26. 			    pline("%s shatter%s%s!", Doname2(obj),
  27. 				(obj->quan==1) ? "s" : "", to_pieces);
  28. 			break;
  29. 		case EGG:
  30. 		case MELON:
  31. 			pline("Splat!");
  32. 			break;
  33. 		case CREAM_PIE:
  34. 			if (in_view) pline("What a mess!");
  35. 			break;
  36. 		case ACID_VENOM:
  37. 		case BLINDING_VENOM:
  38. 			pline("Splash!");
  39. 			break;
  40. 	}
  41. }

throw_gold

  1. STATIC_OVL int
  2. throw_gold(obj)
  3. struct obj *obj;
  4. {
  5. 	int range, odx, ody;
  6. #ifndef GOLDOBJ
  7. 	long zorks = obj->quan;
  8. #endif
  9. 	register struct monst *mon;
  10.  
  11. 	if(!u.dx && !u.dy && !u.dz) {
  12. #ifndef GOLDOBJ
  13. 		u.ugold += obj->quan;
  14. 		flags.botl = 1;
  15. 		dealloc_obj(obj);
  16. #endif
  17. 		You("cannot throw gold at yourself.");
  18. 		return(0);
  19. 	}
  20. #ifdef GOLDOBJ
  21. freeinv(obj);
  22. #endif
  23. 	if(u.uswallow) {
  24. 		pline(is_animal(u.ustuck->data) ?
  25. 			"%s in the %s's entrails." : "%s into %s.",
  26. #ifndef GOLDOBJ
  27. 			"The gold disappears", mon_nam(u.ustuck));
  28. 		u.ustuck->mgold += zorks;
  29. 		dealloc_obj(obj);
  30. #else
  31. 			"The money disappears", mon_nam(u.ustuck));
  32. 		add_to_minv(u.ustuck, obj);
  33. #endif
  34. 		return(1);
  35. 	}
  36.  
  37. 	if(u.dz) {
  38. 		if (u.dz < 0 && !Is_airlevel(&u.uz) &&
  39. 					!Underwater && !Is_waterlevel(&u.uz)) {
  40. 	pline_The("gold hits the %s, then falls back on top of your %s.",
  41. 		    ceiling(u.ux,u.uy), body_part(HEAD));
  42. 		    /* some self damage? */
  43. 		    if(uarmh) pline("Fortunately, you are wearing a helmet!");
  44. 		}
  45. 		bhitpos.x = u.ux;
  46. 		bhitpos.y = u.uy;
  47. 	} else {
  48. 		/* consistent with range for normal objects */
  49. 		range = (int)((ACURRSTR)/2 - obj->owt/40);
  50.  
  51. 		/* see if the gold has a place to move into */
  52. 		odx = u.ux + u.dx;
  53. 		ody = u.uy + u.dy;
  54. 		if(!ZAP_POS(levl[odx][ody].typ) || closed_door(odx, ody)) {
  55. 			bhitpos.x = u.ux;
  56. 			bhitpos.y = u.uy;
  57. 		} else {
  58. 			mon = bhit(u.dx, u.dy, range, THROWN_WEAPON,
  59. 				   (int FDECL((*),(MONST_P,OBJ_P)))0,
  60. 				   (int FDECL((*),(OBJ_P,OBJ_P)))0,
  61. 				   obj);
  62. 			if(mon) {
  63. 			    if (ghitm(mon, obj))	/* was it caught? */
  64. 				return 1;
  65. 			} else {
  66. 			    if(ship_object(obj, bhitpos.x, bhitpos.y, FALSE))
  67. 				return 1;
  68. 			}
  69. 		}
  70. 	}
  71.  
  72. 	if(flooreffects(obj,bhitpos.x,bhitpos.y,"fall")) return(1);
  73. 	if(u.dz > 0)
  74. 		pline_The("gold hits the %s.", surface(bhitpos.x,bhitpos.y));
  75. 	place_object(obj,bhitpos.x,bhitpos.y);
  76. 	if(*u.ushops) sellobj(obj, bhitpos.x, bhitpos.y);
  77. 	stackobj(obj);
  78. 	newsym(bhitpos.x,bhitpos.y);
  79. 	return(1);
  80. }
  81.  
  82. /*dothrow.c*/