Source:NetHack 3.4.3/src/steal.c

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

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

Top of File

  1. /*	SCCS Id: @(#)steal.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. #include "hack.h"
  2.  
  3. STATIC_PTR int NDECL(stealarm);
  4.  
  5. #ifdef OVLB
  6. STATIC_DCL const char *FDECL(equipname, (struct obj *));
  7. STATIC_DCL void FDECL(mdrop_obj, (struct monst *,struct obj *,BOOLEAN_P));

equipname

  1. STATIC_OVL const char *
  2. equipname(otmp)
  3. register struct obj *otmp;
  4. {
  5. 	return (
  6. #ifdef TOURIST
  7. 		(otmp == uarmu) ? "shirt" :
  8. #endif
  9. 		(otmp == uarmf) ? "boots" :
  10. 		(otmp == uarms) ? "shield" :
  11. 		(otmp == uarmg) ? "gloves" :
  12. 		(otmp == uarmc) ? cloak_simple_name(otmp) :
  13. 		(otmp == uarmh) ? "helmet" : "armor");
  14. }

somegold without GOLDOBJ

  1. #ifndef GOLDOBJ
  2. long		/* actually returns something that fits in an int */
  3. somegold()
  4. {
  5. #ifdef LINT	/* long conv. ok */
  6. 	return(0L);
  7. #else
  8. 	return (long)( (u.ugold < 100) ? u.ugold :
  9. 		(u.ugold > 10000) ? rnd(10000) : rnd((int) u.ugold) );
  10. #endif
  11. }

stealgold without GOLDOBJ

  1. void
  2. stealgold(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	register struct obj *gold = g_at(u.ux, u.uy);
  6. 	register long tmp;
  7.  
  8. 	if (gold && ( !u.ugold || gold->quan > u.ugold || !rn2(5))) {
  9. 	    mtmp->mgold += gold->quan;
  10. 	    delobj(gold);
  11. 	    newsym(u.ux, u.uy);
  12. 	    pline("%s quickly snatches some gold from between your %s!",
  13. 		    Monnam(mtmp), makeplural(body_part(FOOT)));
  14. 	    if(!u.ugold || !rn2(5)) {
  15. 		if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE);
  16. 		/* do not set mtmp->mavenge here; gold on the floor is fair game */
  17. 		monflee(mtmp, 0, FALSE, FALSE);
  18. 	    }
  19. 	} else if(u.ugold) {
  20. 	    u.ugold -= (tmp = somegold());
  21. 	    Your("purse feels lighter.");
  22. 	    mtmp->mgold += tmp;
  23. 	if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE);
  24. 	    mtmp->mavenge = 1;
  25. 	    monflee(mtmp, 0, FALSE, FALSE);
  26. 	    flags.botl = 1;
  27. 	}
  28. }

somegold with GOLDOBJ

  1. #else /* !GOLDOBJ */
  2.  
  3. long		/* actually returns something that fits in an int */
  4. somegold(umoney)
  5. long umoney;
  6. {
  7. #ifdef LINT	/* long conv. ok */
  8. 	return(0L);
  9. #else
  10. 	return (long)( (umoney < 100) ? umoney :
  11. 		(umoney > 10000) ? rnd(10000) : rnd((int) umoney) );
  12. #endif
  13. }

findgold

  1. /*
  2. Find the first (and hopefully only) gold object in a chain.
  3. Used when leprechaun (or you as leprechaun) looks for
  4. someone else's gold.  Returns a pointer so the gold may
  5. be seized without further searching.
  6. May search containers too.
  7. Deals in gold only, as leprechauns don't care for lesser coins.
  8. */
  9. struct obj *
  10. findgold(chain)
  11. register struct obj *chain;
  12. {
  13. while (chain && chain->otyp != GOLD_PIECE) chain = chain->nobj;
  14. return chain;
  15. }

stealgold with GOLDOBJ

  1. /* 
  2. Steal gold coins only.  Leprechauns don't care for lesser coins.
  3. */
  4. void
  5. stealgold(mtmp)
  6. register struct monst *mtmp;
  7. {
  8. 	register struct obj *fgold = g_at(u.ux, u.uy);
  9. 	register struct obj *ygold;
  10. 	register long tmp;
  11.  
  12. /* skip lesser coins on the floor */        
  13. while (fgold && fgold->otyp != GOLD_PIECE) fgold = fgold->nexthere; 
  14.  
  15. /* Do you have real gold? */
  16. ygold = findgold(invent);
  17.  
  18. 	if (fgold && ( !ygold || fgold->quan > ygold->quan || !rn2(5))) {
  19. obj_extract_self(fgold);
  20. 	    add_to_minv(mtmp, fgold);
  21. 	    newsym(u.ux, u.uy);
  22. 	    pline("%s quickly snatches some gold from between your %s!",
  23. 		    Monnam(mtmp), makeplural(body_part(FOOT)));
  24. 	    if(!ygold || !rn2(5)) {
  25. 		if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE);
  26. 		monflee(mtmp, 0, FALSE, FALSE);
  27. 	    }
  28. 	} else if(ygold) {
  29. const int gold_price = objects[GOLD_PIECE].oc_cost;
  30. 	    tmp = (somegold(money_cnt(invent)) + gold_price - 1) / gold_price;
  31. 	    tmp = min(tmp, ygold->quan);
  32. if (tmp < ygold->quan) ygold = splitobj(ygold, tmp);
  33. freeinv(ygold);
  34. add_to_minv(mtmp, ygold);
  35. 	    Your("purse feels lighter.");
  36. 	    if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE);
  37. 	    monflee(mtmp, 0, FALSE, FALSE);
  38. 	    flags.botl = 1;
  39. 	}
  40. }
  41. #endif /* GOLDOBJ */

stealarm

  1. /* steal armor after you finish taking it off */
  2. unsigned int stealoid;		/* object to be stolen */
  3. unsigned int stealmid;		/* monster doing the stealing */
  4.  
  5. STATIC_PTR int
  6. stealarm()
  7. {
  8. 	register struct monst *mtmp;
  9. 	register struct obj *otmp;
  10.  
  11. 	for(otmp = invent; otmp; otmp = otmp->nobj) {
  12. 	    if(otmp->o_id == stealoid) {
  13. 		for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  14. 		    if(mtmp->m_id == stealmid) {
  15. 			if(DEADMONSTER(mtmp)) impossible("stealarm(): dead monster stealing"); 
  16. 			if(!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */
  17. 			    goto botm;
  18. 			if(otmp->unpaid)
  19. 			    subfrombill(otmp, shop_keeper(*u.ushops));
  20. 			freeinv(otmp);
  21. 			pline("%s steals %s!", Monnam(mtmp), doname(otmp));
  22. 			(void) mpickobj(mtmp,otmp);	/* may free otmp */
  23. 			/* Implies seduction, "you gladly hand over ..."
  24. 			   so we don't set mavenge bit here. */
  25. 			monflee(mtmp, 0, FALSE, FALSE);
  26. 			if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE);
  27. 		        break;
  28. 		    }
  29. 		}
  30. 		break;
  31. 	    }
  32. 	}
  33. botm:   stealoid = 0;
  34. 	return 0;
  35. }

remove_worn_item

  1. /* An object you're wearing has been taken off by a monster (theft or
  2. seduction).  Also used if a worn item gets transformed (stone to flesh). */
  3. void
  4. remove_worn_item(obj, unchain_ball)
  5. struct obj *obj;
  6. boolean unchain_ball;	/* whether to unpunish or just unwield */
  7. {
  8. 	if (donning(obj))
  9. 	    cancel_don();
  10. 	if (!obj->owornmask)
  11. 	    return;
  12.  
  13. 	if (obj->owornmask & W_ARMOR) {
  14. 	    if (obj == uskin) {
  15. 		impossible("Removing embedded scales?");
  16. 		skinback(TRUE);		/* uarm = uskin; uskin = 0; */
  17. 	    }
  18. 	    if (obj == uarm) (void) Armor_off();
  19. 	    else if (obj == uarmc) (void) Cloak_off();
  20. 	    else if (obj == uarmf) (void) Boots_off();
  21. 	    else if (obj == uarmg) (void) Gloves_off();
  22. 	    else if (obj == uarmh) (void) Helmet_off();
  23. 	    else if (obj == uarms) (void) Shield_off();
  24. #ifdef TOURIST
  25. 	    else if (obj == uarmu) (void) Shirt_off();
  26. #endif
  27. 	    /* catchall -- should never happen */
  28. 	    else setworn((struct obj *)0, obj->owornmask & W_ARMOR);
  29. 	} else if (obj->owornmask & W_AMUL) {
  30. 	    Amulet_off();
  31. 	} else if (obj->owornmask & W_RING) {
  32. 	    Ring_gone(obj);
  33. 	} else if (obj->owornmask & W_TOOL) {
  34. 	    Blindf_off(obj);
  35. 	} else if (obj->owornmask & (W_WEP|W_SWAPWEP|W_QUIVER)) {
  36. 	    if (obj == uwep)
  37. 		uwepgone();
  38. 	    if (obj == uswapwep)
  39. 		uswapwepgone();
  40. 	    if (obj == uquiver)
  41. 		uqwepgone();
  42. 	}
  43.  
  44. 	if (obj->owornmask & (W_BALL|W_CHAIN)) {
  45. 	    if (unchain_ball) unpunish();
  46. 	} else if (obj->owornmask) {
  47. 	    /* catchall */
  48. 	    setnotworn(obj);
  49. 	}
  50. }

steal

  1. /* Returns 1 when something was stolen (or at least, when N should flee now)
  2. * Returns -1 if the monster died in the attempt
  3. * Avoid stealing the object stealoid
  4. */
  5. int
  6. steal(mtmp, objnambuf)
  7. struct monst *mtmp;
  8. char *objnambuf;
  9. {
  10. 	struct obj *otmp;
  11. 	int tmp, could_petrify, named = 0, armordelay;
  12. 	boolean monkey_business; /* true iff an animal is doing the thievery */
  13.  
  14. 	if (objnambuf) *objnambuf = '\0';
  15. 	/* the following is true if successful on first of two attacks. */
  16. 	if(!monnear(mtmp, u.ux, u.uy)) return(0);
  17.  
  18. 	/* food being eaten might already be used up but will not have
  19. 	   been removed from inventory yet; we don't want to steal that,
  20. 	   so this will cause it to be removed now */
  21. 	if (occupation) (void) maybe_finished_meal(FALSE);
  22.  
  23. 	if (!invent || (inv_cnt() == 1 && uskin)) {
  24. nothing_to_steal:
  25. 	    /* Not even a thousand men in armor can strip a naked man. */
  26. 	    if(Blind)
  27. 	      pline("Somebody tries to rob you, but finds nothing to steal.");
  28. 	    else
  29. 	      pline("%s tries to rob you, but there is nothing to steal!",
  30. 		Monnam(mtmp));
  31. 	    return(1);	/* let her flee */
  32. 	}
  33.  
  34. 	monkey_business = is_animal(mtmp->data);
  35. 	if (monkey_business) {
  36. 	    ;	/* skip ring special cases */
  37. 	} else if (Adornment & LEFT_RING) {
  38. 	    otmp = uleft;
  39. 	    goto gotobj;
  40. 	} else if (Adornment & RIGHT_RING) {
  41. 	    otmp = uright;
  42. 	    goto gotobj;
  43. 	}
  44.  
  45. 	tmp = 0;
  46. 	for(otmp = invent; otmp; otmp = otmp->nobj)
  47. 	    if ((!uarm || otmp != uarmc) && otmp != uskin
  48. #ifdef INVISIBLE_OBJECTS
  49. 				&& (!otmp->oinvis || perceives(mtmp->data))
  50. #endif
  51. 				)
  52. 		tmp += ((otmp->owornmask &
  53. 			(W_ARMOR | W_RING | W_AMUL | W_TOOL)) ? 5 : 1);
  54. 	if (!tmp) goto nothing_to_steal;
  55. 	tmp = rn2(tmp);
  56. 	for(otmp = invent; otmp; otmp = otmp->nobj)
  57. 	    if ((!uarm || otmp != uarmc) && otmp != uskin
  58. #ifdef INVISIBLE_OBJECTS
  59. 				&& (!otmp->oinvis || perceives(mtmp->data))
  60. #endif
  61. 			)
  62. 		if((tmp -= ((otmp->owornmask &
  63. 			(W_ARMOR | W_RING | W_AMUL | W_TOOL)) ? 5 : 1)) < 0)
  64. 			break;
  65. 	if(!otmp) {
  66. 		impossible("Steal fails!");
  67. 		return(0);
  68. 	}
  69. 	/* can't steal gloves while wielding - so steal the wielded item. */
  70. 	if (otmp == uarmg && uwep)
  71. 	    otmp = uwep;
  72. 	/* can't steal armor while wearing cloak - so steal the cloak. */
  73. 	else if(otmp == uarm && uarmc) otmp = uarmc;
  74. #ifdef TOURIST
  75. 	else if(otmp == uarmu && uarmc) otmp = uarmc;
  76. 	else if(otmp == uarmu && uarm) otmp = uarm;
  77. #endif
  78. gotobj:
  79. 	if(otmp->o_id == stealoid) return(0);
  80.  
  81. 	/* animals can't overcome curse stickiness nor unlock chains */
  82. 	if (monkey_business) {
  83. 	    boolean ostuck;
  84. 	    /* is the player prevented from voluntarily giving up this item?
  85. 	       (ignores loadstones; the !can_carry() check will catch those) */
  86. 	    if (otmp == uball)
  87. 		ostuck = TRUE;	/* effectively worn; curse is implicit */
  88. 	    else if (otmp == uquiver || (otmp == uswapwep && !u.twoweap))
  89. 		ostuck = FALSE;	/* not really worn; curse doesn't matter */
  90. 	    else
  91. 		ostuck = (otmp->cursed && otmp->owornmask);
  92.  
  93. 	    if (ostuck || !can_carry(mtmp, otmp)) {
  94. 		static const char * const how[] = { "steal","snatch","grab","take" };
  95. cant_take:
  96. 		pline("%s tries to %s your %s but gives up.",
  97. 		      Monnam(mtmp), how[rn2(SIZE(how))],
  98. 		      (otmp->owornmask & W_ARMOR) ? equipname(otmp) :
  99. 		       cxname(otmp));
  100. 		/* the fewer items you have, the less likely the thief
  101. 		   is going to stick around to try again (0) instead of
  102. 		   running away (1) */
  103. 		return !rn2(inv_cnt() / 5 + 2);
  104. 	    }
  105. 	}
  106.  
  107. 	if (otmp->otyp == LEASH && otmp->leashmon) {
  108. 	    if (monkey_business && otmp->cursed) goto cant_take;
  109. 	    o_unleash(otmp);
  110. 	}
  111.  
  112. 	/* you're going to notice the theft... */
  113. 	stop_occupation();
  114.  
  115. 	if((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))){
  116. 		switch(otmp->oclass) {
  117. 		case TOOL_CLASS:
  118. 		case AMULET_CLASS:
  119. 		case RING_CLASS:
  120. 		case FOOD_CLASS: /* meat ring */
  121. 		    remove_worn_item(otmp, TRUE);
  122. 		    break;
  123. 		case ARMOR_CLASS:
  124. 		    armordelay = objects[otmp->otyp].oc_delay;
  125. 		    /* Stop putting on armor which has been stolen. */
  126. 		    if (donning(otmp)) {
  127. 			remove_worn_item(otmp, TRUE);
  128. 			break;
  129. 		    } else if (monkey_business) {
  130. 			/* animals usually don't have enough patience
  131. 			   to take off items which require extra time */
  132. 			if (armordelay >= 1 && rn2(10)) goto cant_take;
  133. 			remove_worn_item(otmp, TRUE);
  134. 			break;
  135. 		    } else {
  136. 			int curssv = otmp->cursed;
  137. 			int slowly;
  138. 			boolean seen = canspotmon(mtmp);
  139.  
  140. 			otmp->cursed = 0;
  141. 			/* can't charm you without first waking you */
  142. 			if (multi < 0 && is_fainted()) unmul((char *)0);
  143. 			slowly = (armordelay >= 1 || multi < 0);
  144. 			if(flags.female)
  145. 			    pline("%s charms you.  You gladly %s your %s.",
  146. 				  !seen ? "She" : Monnam(mtmp),
  147. 				  curssv ? "let her take" :
  148. 				  slowly ? "start removing" : "hand over",
  149. 				  equipname(otmp));
  150. 			else
  151. 			    pline("%s seduces you and %s off your %s.",
  152. 				  !seen ? "She" : Adjmonnam(mtmp, "beautiful"),
  153. 				  curssv ? "helps you to take" :
  154. 				  slowly ? "you start taking" : "you take",
  155. 				  equipname(otmp));
  156. 			named++;
  157. 			/* the following is to set multi for later on */
  158. 			nomul(-armordelay);
  159. 			remove_worn_item(otmp, TRUE);
  160. 			otmp->cursed = curssv;
  161. 			if(multi < 0){
  162. 				/*
  163. 				multi = 0;
  164. 				nomovemsg = 0;
  165. 				afternmv = 0;
  166. 				*/
  167. 				stealoid = otmp->o_id;
  168. 				stealmid = mtmp->m_id;
  169. 				afternmv = stealarm;
  170. 				return(0);
  171. 			}
  172. 		    }
  173. 		    break;
  174. 		default:
  175. 		    impossible("Tried to steal a strange worn thing. [%d]",
  176. 			       otmp->oclass);
  177. 		}
  178. 	}
  179. 	else if (otmp->owornmask)
  180. 	    remove_worn_item(otmp, TRUE);
  181.  
  182. 	/* do this before removing it from inventory */
  183. 	if (objnambuf) Strcpy(objnambuf, yname(otmp));
  184. 	/* set mavenge bit so knights won't suffer an
  185. 	 * alignment penalty during retaliation;
  186. 	 */
  187. 	mtmp->mavenge = 1;
  188.  
  189. 	freeinv(otmp);
  190. 	pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
  191. 	could_petrify = (otmp->otyp == CORPSE &&
  192. 			 touch_petrifies(&mons[otmp->corpsenm]));
  193. 	(void) mpickobj(mtmp,otmp);	/* may free otmp */
  194. 	if (could_petrify && !(mtmp->misc_worn_check & W_ARMG)) {
  195. 	    minstapetrify(mtmp, TRUE);
  196. 	    return -1;
  197. 	}
  198. 	return((multi < 0) ? 0 : 1);
  199. }
  200.  
  201. #endif /* OVLB */

mpickobj

  1. #ifdef OVL1
  2.  
  3. /* Returns 1 if otmp is free'd, 0 otherwise. */
  4. int
  5. mpickobj(mtmp,otmp)
  6. register struct monst *mtmp;
  7. register struct obj *otmp;
  8. {
  9. int freed_otmp;
  10.  
  11. #ifndef GOLDOBJ
  12. if (otmp->oclass == COIN_CLASS) {
  13. 	mtmp->mgold += otmp->quan;
  14. 	obfree(otmp, (struct obj *)0);
  15. 	freed_otmp = 1;
  16. } else {
  17. #endif
  18. boolean snuff_otmp = FALSE;
  19. /* don't want hidden light source inside the monster; assumes that
  20. engulfers won't have external inventories; whirly monsters cause
  21. the light to be extinguished rather than letting it shine thru */
  22. if (otmp->lamplit &&  /* hack to avoid function calls for most objs */
  23. 	obj_sheds_light(otmp) &&
  24. 	attacktype(mtmp->data, AT_ENGL)) {
  25. 	/* this is probably a burning object that you dropped or threw */
  26. 	if (u.uswallow && mtmp == u.ustuck && !Blind)
  27. 	    pline("%s out.", Tobjnam(otmp, "go"));
  28. 	snuff_otmp = TRUE;
  29. }
  30. /* Must do carrying effects on object prior to add_to_minv() */
  31. carry_obj_effects(otmp);
  32. /* add_to_minv() might free otmp [if merged with something else],
  33. so we have to call it after doing the object checks */
  34. freed_otmp = add_to_minv(mtmp, otmp);
  35. /* and we had to defer this until object is in mtmp's inventory */
  36. if (snuff_otmp) snuff_light_source(mtmp->mx, mtmp->my);
  37. #ifndef GOLDOBJ
  38. }
  39. #endif
  40. return freed_otmp;
  41. }
  42.  
  43. #endif /* OVL1 */

stealamulet

  1. #ifdef OVLB
  2.  
  3. void
  4. stealamulet(mtmp)
  5. struct monst *mtmp;
  6. {
  7. struct obj *otmp = (struct obj *)0;
  8. int real=0, fake=0;
  9.  
  10. /* select the artifact to steal */
  11. if(u.uhave.amulet) {
  12. 	real = AMULET_OF_YENDOR;
  13. 	fake = FAKE_AMULET_OF_YENDOR;
  14. } else if(u.uhave.questart) {
  15. 	for(otmp = invent; otmp; otmp = otmp->nobj)
  16. 	    if(is_quest_artifact(otmp)) break;
  17. 	if (!otmp) return;	/* should we panic instead? */
  18. } else if(u.uhave.bell) {
  19. 	real = BELL_OF_OPENING;
  20. 	fake = BELL;
  21. } else if(u.uhave.book) {
  22. 	real = SPE_BOOK_OF_THE_DEAD;
  23. } else if(u.uhave.menorah) {
  24. 	real = CANDELABRUM_OF_INVOCATION;
  25. } else return;	/* you have nothing of special interest */
  26.  
  27. if (!otmp) {
  28. 	/* If we get here, real and fake have been set up. */
  29. 	for(otmp = invent; otmp; otmp = otmp->nobj)
  30. 	    if(otmp->otyp == real || (otmp->otyp == fake && !mtmp->iswiz))
  31. 		break;
  32. }
  33.  
  34. if (otmp) { /* we have something to snatch */
  35. 	if (otmp->owornmask)
  36. 	    remove_worn_item(otmp, TRUE);
  37. 	freeinv(otmp);
  38. 	/* mpickobj wont merge otmp because none of the above things
  39. 	   to steal are mergable */
  40. 	(void) mpickobj(mtmp,otmp);	/* may merge and free otmp */
  41. 	pline("%s stole %s!", Monnam(mtmp), doname(otmp));
  42. 	if (can_teleport(mtmp->data) && !tele_restrict(mtmp))
  43. 	    (void) rloc(mtmp, FALSE);
  44. }
  45. }
  46.  
  47. #endif /* OVLB */

mdrop_obj

  1. #ifdef OVL0
  2.  
  3. /* drop one object taken from a (possibly dead) monster's inventory */
  4. STATIC_OVL void
  5. mdrop_obj(mon, obj, verbosely)
  6. struct monst *mon;
  7. struct obj *obj;
  8. boolean verbosely;
  9. {
  10. int omx = mon->mx, omy = mon->my;
  11.  
  12. if (obj->owornmask) {
  13. 	/* perform worn item handling if the monster is still alive */
  14. 	if (mon->mhp > 0) {
  15. 	    mon->misc_worn_check &= ~obj->owornmask;
  16. 	    update_mon_intrinsics(mon, obj, FALSE, TRUE);
  17. 	 /* obj_no_longer_held(obj); -- done by place_object */
  18. 	    if (obj->owornmask & W_WEP) setmnotwielded(mon, obj);
  19. #ifdef STEED
  20. 	/* don't charge for an owned saddle on dead steed */
  21. 	} else if (mon->mtame && (obj->owornmask & W_SADDLE) && 
  22. 		!obj->unpaid && costly_spot(omx, omy)) {
  23. 	    obj->no_charge = 1;
  24. #endif
  25. 	}
  26. 	obj->owornmask = 0L;
  27. }
  28. if (verbosely && cansee(omx, omy))
  29. 	pline("%s drops %s.", Monnam(mon), distant_name(obj, doname));
  30. if (!flooreffects(obj, omx, omy, "fall")) {
  31. 	place_object(obj, omx, omy);
  32. 	stackobj(obj);
  33. }
  34. }

mdrop_special_objs

  1. /* some monsters bypass the normal rules for moving between levels or
  2. even leaving the game entirely; when that happens, prevent them from
  3. taking the Amulet or invocation tools with them */
  4. void
  5. mdrop_special_objs(mon)
  6. struct monst *mon;
  7. {
  8. struct obj *obj, *otmp;
  9.  
  10. for (obj = mon->minvent; obj; obj = otmp) {
  11. 	otmp = obj->nobj;
  12. 	/* the Amulet, invocation tools, and Rider corpses resist even when
  13. 	   artifacts and ordinary objects are given 0% resistance chance */
  14. 	if (obj_resists(obj, 0, 0)) {
  15. 	    obj_extract_self(obj);
  16. 	    mdrop_obj(mon, obj, FALSE);
  17. 	}
  18. }
  19. }

relobj

  1. /* release the objects the creature is carrying */
  2. void
  3. relobj(mtmp,show,is_pet)
  4. register struct monst *mtmp;
  5. register int show;
  6. boolean is_pet;		/* If true, pet should keep wielded/worn items */
  7. {
  8. 	register struct obj *otmp;
  9. 	register int omx = mtmp->mx, omy = mtmp->my;
  10. 	struct obj *keepobj = 0;
  11. 	struct obj *wep = MON_WEP(mtmp);
  12. 	boolean item1 = FALSE, item2 = FALSE;
  13.  
  14. 	if (!is_pet || mindless(mtmp->data) || is_animal(mtmp->data))
  15. 		item1 = item2 = TRUE;
  16. 	if (!tunnels(mtmp->data) || !needspick(mtmp->data))
  17. 		item1 = TRUE;
  18.  
  19. 	while ((otmp = mtmp->minvent) != 0) {
  20. 		obj_extract_self(otmp);
  21. 		/* special case: pick-axe and unicorn horn are non-worn */
  22. 		/* items that we also want pets to keep 1 of */
  23. 		/* (It is a coincidence that these can also be wielded.) */
  24. 		if (otmp->owornmask || otmp == wep ||
  25. 		    ((!item1 && otmp->otyp == PICK_AXE) ||
  26. 		     (!item2 && otmp->otyp == UNICORN_HORN && !otmp->cursed))) {
  27. 			if (is_pet) { /* dont drop worn/wielded item */
  28. 				if (otmp->otyp == PICK_AXE)
  29. 					item1 = TRUE;
  30. 				if (otmp->otyp == UNICORN_HORN && !otmp->cursed)
  31. 					item2 = TRUE;
  32. 				otmp->nobj = keepobj;
  33. 				keepobj = otmp;
  34. 				continue;
  35. 			}
  36. 		}
  37. 		mdrop_obj(mtmp, otmp, is_pet && flags.verbose);
  38. 	}
  39.  
  40. 	/* put kept objects back */
  41. 	while ((otmp = keepobj) != (struct obj *)0) {
  42. 	    keepobj = otmp->nobj;
  43. 	    (void) add_to_minv(mtmp, otmp);
  44. 	}
  45. #ifndef GOLDOBJ
  46. 	if (mtmp->mgold) {
  47. 		register long g = mtmp->mgold;
  48. 		(void) mkgold(g, omx, omy);
  49. 		if (is_pet && cansee(omx, omy) && flags.verbose)
  50. 			pline("%s drops %ld gold piece%s.", Monnam(mtmp),
  51. 				g, plur(g));
  52. 		mtmp->mgold = 0L;
  53. 	}
  54. #endif
  55.  
  56. 	if (show & cansee(omx, omy))
  57. 		newsym(omx, omy);
  58. }
  59.  
  60. #endif /* OVL0 */
  61.  
  62. /*steal.c*/