Source:NetHack 3.4.3/src/worn.c

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

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

Top of file

  1. /*	SCCS Id: @(#)worn.c	3.4	2003/01/08	*/
  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 void FDECL(m_lose_armor, (struct monst *,struct obj *));
  4. STATIC_DCL void FDECL(m_dowear_type, (struct monst *,long, BOOLEAN_P, BOOLEAN_P));
  5. STATIC_DCL int FDECL(extra_pref, (struct monst *, struct obj *));
  6.  
  7. const struct worn {
  8. 	long w_mask;
  9. 	struct obj **w_obj;
  10. } worn[] = {
  11. 	{ W_ARM, &uarm },
  12. 	{ W_ARMC, &uarmc },
  13. 	{ W_ARMH, &uarmh },
  14. 	{ W_ARMS, &uarms },
  15. 	{ W_ARMG, &uarmg },
  16. 	{ W_ARMF, &uarmf },
  17. #ifdef TOURIST
  18. 	{ W_ARMU, &uarmu },
  19. #endif
  20. 	{ W_RINGL, &uleft },
  21. 	{ W_RINGR, &uright },
  22. 	{ W_WEP, &uwep },
  23. 	{ W_SWAPWEP, &uswapwep },
  24. 	{ W_QUIVER, &uquiver },
  25. 	{ W_AMUL, &uamul },
  26. 	{ W_TOOL, &ublindf },
  27. 	{ W_BALL, &uball },
  28. 	{ W_CHAIN, &uchain },
  29. 	{ 0, 0 }
  30. };
  31.  
  32. /* This only allows for one blocking item per property */
  33. #define w_blocks(o,m) \
  34. 		((o->otyp == MUMMY_WRAPPING && ((m) & W_ARMC)) ? INVIS : \
  35. 		 (o->otyp == CORNUTHAUM && ((m) & W_ARMH) && \
  36. 			!Role_if(PM_WIZARD)) ? CLAIRVOYANT : 0)
  37. 		/* note: monsters don't have clairvoyance, so your role
  38. 		   has no significant effect on their use of w_blocks() */

setworn

  1. /* Updated to use the extrinsic and blocked fields. */
  2. void
  3. setworn(obj, mask)
  4. register struct obj *obj;
  5. long mask;
  6. {
  7. 	register const struct worn *wp;
  8. 	register struct obj *oobj;
  9. 	register int p;
  10.  
  11. 	if ((mask & (W_ARM|I_SPECIAL)) == (W_ARM|I_SPECIAL)) {
  12. 	    /* restoring saved game; no properties are conferred via skin */
  13. 	    uskin = obj;
  14. 	 /* assert( !uarm ); */
  15. 	} else {
  16. 	    for(wp = worn; wp->w_mask; wp++) if(wp->w_mask & mask) {
  17. 		oobj = *(wp->w_obj);
  18. 		if(oobj && !(oobj->owornmask & wp->w_mask))
  19. 			impossible("Setworn: mask = %ld.", wp->w_mask);
  20. 		if(oobj) {
  21. 		    if (u.twoweap && (oobj->owornmask & (W_WEP|W_SWAPWEP)))
  22. 			u.twoweap = 0;
  23. 		    oobj->owornmask &= ~wp->w_mask;
  24. 		    if (wp->w_mask & ~(W_SWAPWEP|W_QUIVER)) {
  25. 			/* leave as "x = x <op> y", here and below, for broken
  26. 			 * compilers */
  27. 			p = objects[oobj->otyp].oc_oprop;
  28. 			u.uprops[p].extrinsic =
  29. 					u.uprops[p].extrinsic & ~wp->w_mask;
  30. 			if ((p = w_blocks(oobj,mask)) != 0)
  31. 			    u.uprops[p].blocked &= ~wp->w_mask;
  32. 			if (oobj->oartifact)
  33. 			    set_artifact_intrinsic(oobj, 0, mask);
  34. 		    }
  35. 		}
  36. 		*(wp->w_obj) = obj;
  37. 		if(obj) {
  38. 		    obj->owornmask |= wp->w_mask;
  39. 		    /* Prevent getting/blocking intrinsics from wielding
  40. 		     * potions, through the quiver, etc.
  41. 		     * Allow weapon-tools, too.
  42. 		     * wp_mask should be same as mask at this point.
  43. 		     */
  44. 		    if (wp->w_mask & ~(W_SWAPWEP|W_QUIVER)) {
  45. 			if (obj->oclass == WEAPON_CLASS || is_weptool(obj) ||
  46. 					    mask != W_WEP) {
  47. 			    p = objects[obj->otyp].oc_oprop;
  48. 			    u.uprops[p].extrinsic =
  49. 					u.uprops[p].extrinsic | wp->w_mask;
  50. 			    if ((p = w_blocks(obj, mask)) != 0)
  51. 				u.uprops[p].blocked |= wp->w_mask;
  52. 			}
  53. 			if (obj->oartifact)
  54. 			    set_artifact_intrinsic(obj, 1, mask);
  55. 		    }
  56. 		}
  57. 	    }
  58. 	}
  59. 	update_inventory();
  60. }

setnotworn

  1. /* called e.g. when obj is destroyed */
  2. /* Updated to use the extrinsic and blocked fields. */
  3. void
  4. setnotworn(obj)
  5. register struct obj *obj;
  6. {
  7. 	register const struct worn *wp;
  8. 	register int p;
  9.  
  10. 	if (!obj) return;
  11. 	if (obj == uwep || obj == uswapwep) u.twoweap = 0;
  12. 	for(wp = worn; wp->w_mask; wp++)
  13. 	    if(obj == *(wp->w_obj)) {
  14. 		*(wp->w_obj) = 0;
  15. 		p = objects[obj->otyp].oc_oprop;
  16. 		u.uprops[p].extrinsic = u.uprops[p].extrinsic & ~wp->w_mask;
  17. 		obj->owornmask &= ~wp->w_mask;
  18. 		if (obj->oartifact)
  19. 		    set_artifact_intrinsic(obj, 0, wp->w_mask);
  20. 		if ((p = w_blocks(obj,wp->w_mask)) != 0)
  21. 		    u.uprops[p].blocked &= ~wp->w_mask;
  22. 	    }
  23. 	update_inventory();
  24. }

mon_set_minvis

  1. void
  2. mon_set_minvis(mon)
  3. struct monst *mon;
  4. {
  5. 	mon->perminvis = 1;
  6. 	if (!mon->invis_blkd) {
  7. 	    mon->minvis = 1;
  8. 	    newsym(mon->mx, mon->my);		/* make it disappear */
  9. 	    if (mon->wormno) see_wsegs(mon);	/* and any tail too */
  10. 	}
  11. }

mon_adjust_speed

  1. void
  2. mon_adjust_speed(mon, adjust, obj)
  3. struct monst *mon;
  4. int adjust;	/* positive => increase speed, negative => decrease */
  5. struct obj *obj;	/* item to make known if effect can be seen */
  6. {
  7. struct obj *otmp;
  8. boolean give_msg = !in_mklev, petrify = FALSE;
  9. unsigned int oldspeed = mon->mspeed;
  10.  
  11. switch (adjust) {
  12. case  2:
  13. 	mon->permspeed = MFAST;
  14. 	give_msg = FALSE;	/* special case monster creation */
  15. 	break;
  16. case  1:
  17. 	if (mon->permspeed == MSLOW) mon->permspeed = 0;
  18. 	else mon->permspeed = MFAST;
  19. 	break;
  20. case  0:			/* just check for worn speed boots */
  21. 	break;
  22. case -1:
  23. 	if (mon->permspeed == MFAST) mon->permspeed = 0;
  24. 	else mon->permspeed = MSLOW;
  25. 	break;
  26. case -2:
  27. 	mon->permspeed = MSLOW;
  28. 	give_msg = FALSE;	/* (not currently used) */
  29. 	break;
  30. case -3:			/* petrification */
  31. 	/* take away intrinsic speed but don't reduce normal speed */
  32. 	if (mon->permspeed == MFAST) mon->permspeed = 0;
  33. 	petrify = TRUE;
  34. 	break;
  35. }
  36.  
  37. for (otmp = mon->minvent; otmp; otmp = otmp->nobj)
  38. 	if (otmp->owornmask && objects[otmp->otyp].oc_oprop == FAST)
  39. 	    break;
  40. if (otmp)		/* speed boots */
  41. 	mon->mspeed = MFAST;
  42. else
  43. 	mon->mspeed = mon->permspeed;
  44.  
  45. if (give_msg && (mon->mspeed != oldspeed || petrify) && canseemon(mon)) {
  46. 	/* fast to slow (skipping intermediate state) or vice versa */
  47. 	const char *howmuch = (mon->mspeed + oldspeed == MFAST + MSLOW) ?
  48. 				"much " : "";
  49.  
  50. 	if (petrify) {
  51. 	    /* mimic the player's petrification countdown; "slowing down"
  52. 	       even if fast movement rate retained via worn speed boots */
  53. 	    if (flags.verbose) pline("%s is slowing down.", Monnam(mon));
  54. 	} else if (adjust > 0 || mon->mspeed == MFAST)
  55. 	    pline("%s is suddenly moving %sfaster.", Monnam(mon), howmuch);
  56. 	else
  57. 	    pline("%s seems to be moving %sslower.", Monnam(mon), howmuch);
  58.  
  59. 	/* might discover an object if we see the speed change happen, but
  60. 	   avoid making possibly forgotten book known when casting its spell */
  61. 	if (obj != 0 && obj->dknown &&
  62. 		objects[obj->otyp].oc_class != SPBOOK_CLASS)
  63. 	    makeknown(obj->otyp);
  64. }
  65. }

update_mon_intrinsics

  1. /* armor put on or taken off; might be magical variety */
  2. void
  3. update_mon_intrinsics(mon, obj, on, silently)
  4. struct monst *mon;
  5. struct obj *obj;
  6. boolean on, silently;
  7. {
  8. int unseen;
  9. uchar mask;
  10. struct obj *otmp;
  11. int which = (int) objects[obj->otyp].oc_oprop;
  12.  
  13. unseen = !canseemon(mon);
  14. if (!which) goto maybe_blocks;
  15.  
  16. if (on) {
  17. 	switch (which) {
  18. 	 case INVIS:
  19. 	    mon->minvis = !mon->invis_blkd;
  20. 	    break;
  21. 	 case FAST:
  22. 	  {
  23. 	    boolean save_in_mklev = in_mklev;
  24. 	    if (silently) in_mklev = TRUE;
  25. 	    mon_adjust_speed(mon, 0, obj);
  26. 	    in_mklev = save_in_mklev;
  27. 	    break;
  28. 	  }
  29. 	/* properties handled elsewhere */
  30. 	 case ANTIMAGIC:
  31. 	 case REFLECTING:
  32. 	    break;
  33. 	/* properties which have no effect for monsters */
  34. 	 case CLAIRVOYANT:
  35. 	 case STEALTH:
  36. 	 case TELEPAT:
  37. 	    break;
  38. 	/* properties which should have an effect but aren't implemented */
  39. 	 case LEVITATION:
  40. 	 case WWALKING:
  41. 	    break;
  42. 	/* properties which maybe should have an effect but don't */
  43. 	 case DISPLACED:
  44. 	 case FUMBLING:
  45. 	 case JUMPING:
  46. 	 case PROTECTION:
  47. 	    break;
  48. 	 default:
  49. 	    if (which <= 8) {	/* 1 thru 8 correspond to MR_xxx mask values */
  50. 		/* FIRE,COLD,SLEEP,DISINT,SHOCK,POISON,ACID,STONE */
  51. 		mask = (uchar) (1 << (which - 1));
  52. 		mon->mintrinsics |= (unsigned short) mask;
  53. 	    }
  54. 	    break;
  55. 	}
  56. } else {	    /* off */
  57. 	switch (which) {
  58. 	 case INVIS:
  59. 	    mon->minvis = mon->perminvis;
  60. 	    break;
  61. 	 case FAST:
  62. 	  {
  63. 	    boolean save_in_mklev = in_mklev;
  64. 	    if (silently) in_mklev = TRUE;
  65. 	    mon_adjust_speed(mon, 0, obj);
  66. 	    in_mklev = save_in_mklev;
  67. 	    break;
  68. 	  }
  69. 	 case FIRE_RES:
  70. 	 case COLD_RES:
  71. 	 case SLEEP_RES:
  72. 	 case DISINT_RES:
  73. 	 case SHOCK_RES:
  74. 	 case POISON_RES:
  75. 	 case ACID_RES:
  76. 	 case STONE_RES:
  77. 	    mask = (uchar) (1 << (which - 1));
  78. 	    /* If the monster doesn't have this resistance intrinsically,
  79. 	       check whether any other worn item confers it.  Note that
  80. 	       we don't currently check for anything conferred via simply
  81. 	       carrying an object. */
  82. 	    if (!(mon->data->mresists & mask)) {
  83. 		for (otmp = mon->minvent; otmp; otmp = otmp->nobj)
  84. 		    if (otmp->owornmask &&
  85. 			    (int) objects[otmp->otyp].oc_oprop == which)
  86. 			break;
  87. 		if (!otmp)
  88. 		    mon->mintrinsics &= ~((unsigned short) mask);
  89. 	    }
  90. 	    break;
  91. 	 default:
  92. 	    break;
  93. 	}
  94. }
  95.  
  96. maybe_blocks:
  97. /* obj->owornmask has been cleared by this point, so we can't use it.
  98. However, since monsters don't wield armor, we don't have to guard
  99. against that and can get away with a blanket worn-mask value. */
  100. switch (w_blocks(obj,~0L)) {
  101. case INVIS:
  102. 	mon->invis_blkd = on ? 1 : 0;
  103. 	mon->minvis = on ? 0 : mon->perminvis;
  104. 	break;
  105. default:
  106. 	break;
  107. }
  108.  
  109. #ifdef STEED
  110. 	if (!on && mon == u.usteed && obj->otyp == SADDLE)
  111. 	    dismount_steed(DISMOUNT_FELL);
  112. #endif
  113.  
  114. /* if couldn't see it but now can, or vice versa, update display */
  115. if (!silently && (unseen ^ !canseemon(mon)))
  116. 	newsym(mon->mx, mon->my);
  117. }

find_mac

  1. int
  2. find_mac(mon)
  3. register struct monst *mon;
  4. {
  5. 	register struct obj *obj;
  6. 	int base = mon->data->ac;
  7. 	long mwflags = mon->misc_worn_check;
  8.  
  9. 	for (obj = mon->minvent; obj; obj = obj->nobj) {
  10. 	    if (obj->owornmask & mwflags)
  11. 		base -= ARM_BONUS(obj);
  12. 		/* since ARM_BONUS is positive, subtracting it increases AC */
  13. 	}
  14. 	return base;
  15. }
  1. /* weapons are handled separately; rings and eyewear aren't used by monsters */
  2.  
  3. /* Wear the best object of each type that the monster has.  During creation,
  4. * the monster can put everything on at once; otherwise, wearing takes time.
  5. * This doesn't affect monster searching for objects--a monster may very well
  6. * search for objects it would not want to wear, because we don't want to
  7. * check which_armor() each round.
  8. *
  9. * We'll let monsters put on shirts and/or suits under worn cloaks, but
  10. * not shirts under worn suits.  This is somewhat arbitrary, but it's
  11. * too tedious to have them remove and later replace outer garments,
  12. * and preventing suits under cloaks makes it a little bit too easy for
  13. * players to influence what gets worn.  Putting on a shirt underneath
  14. * already worn body armor is too obviously buggy...
  15. */

m_dowear

  1. void
  2. m_dowear(mon, creation)
  3. register struct monst *mon;
  4. boolean creation;
  5. {
  6. #define RACE_EXCEPTION TRUE
  7. 	/* Note the restrictions here are the same as in dowear in do_wear.c
  8. 	 * except for the additional restriction on intelligence.  (Players
  9. 	 * are always intelligent, even if polymorphed).
  10. 	 */
  11. 	if (verysmall(mon->data) || nohands(mon->data) || is_animal(mon->data))
  12. 		return;
  13. 	/* give mummies a chance to wear their wrappings
  14. 	 * and let skeletons wear their initial armor */
  15. 	if (mindless(mon->data) && (!creation ||
  16. 	    (mon->data->mlet != S_MUMMY && mon->data != &mons[PM_SKELETON])))
  17. 		return;
  18.  
  19. 	m_dowear_type(mon, W_AMUL, creation, FALSE);
  20. #ifdef TOURIST
  21. 	/* can't put on shirt if already wearing suit */
  22. 	if (!cantweararm(mon->data) || (mon->misc_worn_check & W_ARM))
  23. 	    m_dowear_type(mon, W_ARMU, creation, FALSE);
  24. #endif
  25. 	/* treating small as a special case allows
  26. 	   hobbits, gnomes, and kobolds to wear cloaks */
  27. 	if (!cantweararm(mon->data) || mon->data->msize == MZ_SMALL)
  28. 	    m_dowear_type(mon, W_ARMC, creation, FALSE);
  29. 	m_dowear_type(mon, W_ARMH, creation, FALSE);
  30. 	if (!MON_WEP(mon) || !bimanual(MON_WEP(mon)))
  31. 	    m_dowear_type(mon, W_ARMS, creation, FALSE);
  32. 	m_dowear_type(mon, W_ARMG, creation, FALSE);
  33. 	if (!slithy(mon->data) && mon->data->mlet != S_CENTAUR)
  34. 	    m_dowear_type(mon, W_ARMF, creation, FALSE);
  35. 	if (!cantweararm(mon->data))
  36. 	    m_dowear_type(mon, W_ARM, creation, FALSE);
  37. 	else
  38. 	    m_dowear_type(mon, W_ARM, creation, RACE_EXCEPTION);
  39. }

m_dowear_type

  1. STATIC_OVL void
  2. m_dowear_type(mon, flag, creation, racialexception)
  3. struct monst *mon;
  4. long flag;
  5. boolean creation;
  6. boolean racialexception;
  7. {
  8. 	struct obj *old, *best, *obj;
  9. 	int m_delay = 0;
  10. 	int unseen = !canseemon(mon);
  11. 	char nambuf[BUFSZ];
  12.  
  13. 	if (mon->mfrozen) return; /* probably putting previous item on */
  14.  
  15. 	/* Get a copy of monster's name before altering its visibility */
  16. 	Strcpy(nambuf, See_invisible ? Monnam(mon) : mon_nam(mon));
  17.  
  18. 	old = which_armor(mon, flag);
  19. 	if (old && old->cursed) return;
  20. 	if (old && flag == W_AMUL) return; /* no such thing as better amulets */
  21. 	best = old;
  22.  
  23. 	for(obj = mon->minvent; obj; obj = obj->nobj) {
  24. 	    switch(flag) {
  25. 		case W_AMUL:
  26. 		    if (obj->oclass != AMULET_CLASS ||
  27. 			    (obj->otyp != AMULET_OF_LIFE_SAVING &&
  28. 				obj->otyp != AMULET_OF_REFLECTION))
  29. 			continue;
  30. 		    best = obj;
  31. 		    goto outer_break; /* no such thing as better amulets */
  32. #ifdef TOURIST
  33. 		case W_ARMU:
  34. 		    if (!is_shirt(obj)) continue;
  35. 		    break;
  36. #endif
  37. 		case W_ARMC:
  38. 		    if (!is_cloak(obj)) continue;
  39. 		    break;
  40. 		case W_ARMH:
  41. 		    if (!is_helmet(obj)) continue;
  42. 		    /* (flimsy exception matches polyself handling) */
  43. 		    if (has_horns(mon->data) && !is_flimsy(obj)) continue;
  44. 		    break;
  45. 		case W_ARMS:
  46. 		    if (!is_shield(obj)) continue;
  47. 		    break;
  48. 		case W_ARMG:
  49. 		    if (!is_gloves(obj)) continue;
  50. 		    break;
  51. 		case W_ARMF:
  52. 		    if (!is_boots(obj)) continue;
  53. 		    break;
  54. 		case W_ARM:
  55. 		    if (!is_suit(obj)) continue;
  56. 		    if (racialexception && (racial_exception(mon, obj) < 1)) continue;
  57. 		    break;
  58. 	    }
  59. 	    if (obj->owornmask) continue;
  60. 	    /* I'd like to define a VISIBLE_ARM_BONUS which doesn't assume the
  61. 	     * monster knows obj->spe, but if I did that, a monster would keep
  62. 	     * switching forever between two -2 caps since when it took off one
  63. 	     * it would forget spe and once again think the object is better
  64. 	     * than what it already has.
  65. 	     */
  66. 	    if (best && (ARM_BONUS(best) + extra_pref(mon,best) >= ARM_BONUS(obj) + extra_pref(mon,obj)))
  67. 		continue;
  68. 	    best = obj;
  69. 	}
  70. outer_break:
  71. 	if (!best || best == old) return;
  72.  
  73. 	/* if wearing a cloak, account for the time spent removing
  74. 	   and re-wearing it when putting on a suit or shirt */
  75. 	if ((flag == W_ARM
  76. #ifdef TOURIST
  77. 	  || flag == W_ARMU
  78. #endif
  79. 			  ) && (mon->misc_worn_check & W_ARMC))
  80. 	    m_delay += 2;
  81. 	/* when upgrading a piece of armor, account for time spent
  82. 	   taking off current one */
  83. 	if (old)
  84. 	    m_delay += objects[old->otyp].oc_delay;
  85.  
  86. 	if (old) /* do this first to avoid "(being worn)" */
  87. 	    old->owornmask = 0L;
  88. 	if (!creation) {
  89. 	    if (canseemon(mon)) {
  90. 		char buf[BUFSZ];
  91.  
  92. 		if (old)
  93. 		    Sprintf(buf, " removes %s and", distant_name(old, doname));
  94. 		else
  95. 		    buf[0] = '\0';
  96. 		pline("%s%s puts on %s.", Monnam(mon),
  97. 		      buf, distant_name(best,doname));
  98. 	    } /* can see it */
  99. 	    m_delay += objects[best->otyp].oc_delay;
  100. 	    mon->mfrozen = m_delay;
  101. 	    if (mon->mfrozen) mon->mcanmove = 0;
  102. 	}
  103. 	if (old)
  104. 	    update_mon_intrinsics(mon, old, FALSE, creation);
  105. 	mon->misc_worn_check |= flag;
  106. 	best->owornmask |= flag;
  107. 	update_mon_intrinsics(mon, best, TRUE, creation);
  108. 	/* if couldn't see it but now can, or vice versa, */
  109. 	if (!creation && (unseen ^ !canseemon(mon))) {
  110. 		if (mon->minvis && !See_invisible) {
  111. 			pline("Suddenly you cannot see %s.", nambuf);
  112. 			makeknown(best->otyp);
  113. 		} /* else if (!mon->minvis) pline("%s suddenly appears!", Amonnam(mon)); */
  114. 	}
  115. }
  116. #undef RACE_EXCEPTION

which_armor

which_armor() takes two parameters, a monster and a worn flag macro (the W_FOO flags), and returns a pointer to an object worn by the monster in that slot, or NULL if no object worn in that slot.

  1. struct obj *
  2. which_armor(mon, flag)
  3. struct monst *mon;
  4. long flag;
  5. {
  6. 	register struct obj *obj;
  7.  
  8. 	for(obj = mon->minvent; obj; obj = obj->nobj)
  9. 		if (obj->owornmask & flag) return obj;
  10. 	return((struct obj *)0);
  11. }

m_lose_armor

  1. /* remove an item of armor and then drop it */
  2. STATIC_OVL void
  3. m_lose_armor(mon, obj)
  4. struct monst *mon;
  5. struct obj *obj;
  6. {
  7. 	mon->misc_worn_check &= ~obj->owornmask;
  8. 	if (obj->owornmask)
  9. 	    update_mon_intrinsics(mon, obj, FALSE, FALSE);
  10. 	obj->owornmask = 0L;
  11.  
  12. 	obj_extract_self(obj);
  13. 	place_object(obj, mon->mx, mon->my);
  14. 	/* call stackobj() if we ever drop anything that can merge */
  15. 	newsym(mon->mx, mon->my);
  16. }

clear_bypasses

  1. /* all objects with their bypass bit set should now be reset to normal */
  2. void
  3. clear_bypasses()
  4. {
  5. 	struct obj *otmp, *nobj;
  6. 	struct monst *mtmp;
  7.  
  8. 	for (otmp = fobj; otmp; otmp = nobj) {
  9. 	    nobj = otmp->nobj;
  10. 	    if (otmp->bypass) {
  11. 		otmp->bypass = 0;
  12. 		/* bypass will have inhibited any stacking, but since it's
  13. 		   used for polymorph handling, the objects here probably
  14. 		   have been transformed and won't be stacked in the usual
  15. 		   manner afterwards; so don't bother with this */
  16. #if 0
  17. 		if (objects[otmp->otyp].oc_merge) {
  18. 		    xchar ox, oy;
  19.  
  20. 		    (void) get_obj_location(otmp, &ox, &oy, 0);
  21. 		    stack_object(otmp);
  22. 		    newsym(ox, oy);
  23. 		}
  24. #endif	/*0*/
  25. 	    }
  26. 	}
  27. 	/* invent and mydogs chains shouldn't matter here */
  28. 	for (otmp = migrating_objs; otmp; otmp = otmp->nobj)
  29. 	    otmp->bypass = 0;
  30. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  31. 	    if (DEADMONSTER(mtmp)) continue;
  32. 	    for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  33. 		otmp->bypass = 0;
  34. 	}
  35. 	for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) {
  36. 	    for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  37. 		otmp->bypass = 0;
  38. 	}
  39. 	flags.bypasses = FALSE;
  40. }

bypass_obj

  1. void
  2. bypass_obj(obj)
  3. struct obj *obj;
  4. {
  5. 	obj->bypass = 1;
  6. 	flags.bypasses = TRUE;
  7. }

mon_break_armor

  1. void
  2. mon_break_armor(mon, polyspot)
  3. struct monst *mon;
  4. boolean polyspot;
  5. {
  6. 	register struct obj *otmp;
  7. 	struct permonst *mdat = mon->data;
  8. 	boolean vis = cansee(mon->mx, mon->my);
  9. 	boolean handless_or_tiny = (nohands(mdat) || verysmall(mdat));
  10. 	const char *pronoun = mhim(mon),
  11. 			*ppronoun = mhis(mon);
  12.  
  13. 	if (breakarm(mdat)) {
  14. 	    if ((otmp = which_armor(mon, W_ARM)) != 0) {
  15. 		if ((Is_dragon_scales(otmp) &&
  16. 			mdat == Dragon_scales_to_pm(otmp)) ||
  17. 		    (Is_dragon_mail(otmp) && mdat == Dragon_mail_to_pm(otmp)))
  18. 		    ;	/* no message here;
  19. 			   "the dragon merges with his scaly armor" is odd
  20. 			   and the monster's previous form is already gone */
  21. 		else if (vis)
  22. 		    pline("%s breaks out of %s armor!", Monnam(mon), ppronoun);
  23. 		else
  24. 		    You_hear("a cracking sound.");
  25. 		m_useup(mon, otmp);
  26. 	    }
  27. 	    if ((otmp = which_armor(mon, W_ARMC)) != 0) {
  28. 		if (otmp->oartifact) {
  29. 		    if (vis)
  30. 			pline("%s %s falls off!", s_suffix(Monnam(mon)),
  31. 				cloak_simple_name(otmp));
  32. 		    if (polyspot) bypass_obj(otmp);
  33. 		    m_lose_armor(mon, otmp);
  34. 		} else {
  35. 		    if (vis)
  36. 			pline("%s %s tears apart!", s_suffix(Monnam(mon)),
  37. 				cloak_simple_name(otmp));
  38. 		    else
  39. 			You_hear("a ripping sound.");
  40. 		    m_useup(mon, otmp);
  41. 		}
  42. 	    }
  43. #ifdef TOURIST
  44. 	    if ((otmp = which_armor(mon, W_ARMU)) != 0) {
  45. 		if (vis)
  46. 		    pline("%s shirt rips to shreds!", s_suffix(Monnam(mon)));
  47. 		else
  48. 		    You_hear("a ripping sound.");
  49. 		m_useup(mon, otmp);
  50. 	    }
  51. #endif
  52. 	} else if (sliparm(mdat)) {
  53. 	    if ((otmp = which_armor(mon, W_ARM)) != 0) {
  54. 		if (vis)
  55. 		    pline("%s armor falls around %s!",
  56. 				 s_suffix(Monnam(mon)), pronoun);
  57. 		else
  58. 		    You_hear("a thud.");
  59. 		if (polyspot) bypass_obj(otmp);
  60. 		m_lose_armor(mon, otmp);
  61. 	    }
  62. 	    if ((otmp = which_armor(mon, W_ARMC)) != 0) {
  63. 		if (vis) {
  64. 		    if (is_whirly(mon->data))
  65. 			pline("%s %s falls, unsupported!",
  66. 				     s_suffix(Monnam(mon)), cloak_simple_name(otmp));
  67. 		    else
  68. 			pline("%s shrinks out of %s %s!", Monnam(mon),
  69. 						ppronoun, cloak_simple_name(otmp));
  70. 		}
  71. 		if (polyspot) bypass_obj(otmp);
  72. 		m_lose_armor(mon, otmp);
  73. 	    }
  74. #ifdef TOURIST
  75. 	    if ((otmp = which_armor(mon, W_ARMU)) != 0) {
  76. 		if (vis) {
  77. 		    if (sliparm(mon->data))
  78. 			pline("%s seeps right through %s shirt!",
  79. 					Monnam(mon), ppronoun);
  80. 		    else
  81. 			pline("%s becomes much too small for %s shirt!",
  82. 					Monnam(mon), ppronoun);
  83. 		}
  84. 		if (polyspot) bypass_obj(otmp);
  85. 		m_lose_armor(mon, otmp);
  86. 	    }
  87. #endif
  88. 	}
  89. 	if (handless_or_tiny) {
  90. 	    /* [caller needs to handle weapon checks] */
  91. 	    if ((otmp = which_armor(mon, W_ARMG)) != 0) {
  92. 		if (vis)
  93. 		    pline("%s drops %s gloves%s!", Monnam(mon), ppronoun,
  94. 					MON_WEP(mon) ? " and weapon" : "");
  95. 		if (polyspot) bypass_obj(otmp);
  96. 		m_lose_armor(mon, otmp);
  97. 	    }
  98. 	    if ((otmp = which_armor(mon, W_ARMS)) != 0) {
  99. 		if (vis)
  100. 		    pline("%s can no longer hold %s shield!", Monnam(mon),
  101. 								ppronoun);
  102. 		else
  103. 		    You_hear("a clank.");
  104. 		if (polyspot) bypass_obj(otmp);
  105. 		m_lose_armor(mon, otmp);
  106. 	    }
  107. 	}
  108. 	if (handless_or_tiny || has_horns(mdat)) {
  109. 	    if ((otmp = which_armor(mon, W_ARMH)) != 0 &&
  110. 		    /* flimsy test for horns matches polyself handling */
  111. 		    (handless_or_tiny || !is_flimsy(otmp))) {
  112. 		if (vis)
  113. 		    pline("%s helmet falls to the %s!",
  114. 			  s_suffix(Monnam(mon)), surface(mon->mx, mon->my));
  115. 		else
  116. 		    You_hear("a clank.");
  117. 		if (polyspot) bypass_obj(otmp);
  118. 		m_lose_armor(mon, otmp);
  119. 	    }
  120. 	}
  121. 	if (handless_or_tiny || slithy(mdat) || mdat->mlet == S_CENTAUR) {
  122. 	    if ((otmp = which_armor(mon, W_ARMF)) != 0) {
  123. 		if (vis) {
  124. 		    if (is_whirly(mon->data))
  125. 			pline("%s boots fall away!",
  126. 				       s_suffix(Monnam(mon)));
  127. 		    else pline("%s boots %s off %s feet!",
  128. 			s_suffix(Monnam(mon)),
  129. 			verysmall(mdat) ? "slide" : "are pushed", ppronoun);
  130. 		}
  131. 		if (polyspot) bypass_obj(otmp);
  132. 		m_lose_armor(mon, otmp);
  133. 	    }
  134. 	}
  135. #ifdef STEED
  136. 	if (!can_saddle(mon)) {
  137. 	    if ((otmp = which_armor(mon, W_SADDLE)) != 0) {
  138. 		if (polyspot) bypass_obj(otmp);
  139. 		m_lose_armor(mon, otmp);
  140. 		if (vis)
  141. 		    pline("%s saddle falls off.", s_suffix(Monnam(mon)));
  142. 	    }
  143. 	    if (mon == u.usteed)
  144. 		goto noride;
  145. 	} else if (mon == u.usteed && !can_ride(mon)) {
  146. 	noride:
  147. 	    You("can no longer ride %s.", mon_nam(mon));
  148. 	    if (touch_petrifies(u.usteed->data) &&
  149. 			!Stone_resistance && rnl(3)) {
  150. 		char buf[BUFSZ];
  151.  
  152. 		You("touch %s.", mon_nam(u.usteed));
  153. 		Sprintf(buf, "falling off %s",
  154. 				an(u.usteed->data->mname));
  155. 		instapetrify(buf);
  156. 	    }
  157. 	    dismount_steed(DISMOUNT_FELL);
  158. 	}
  159. #endif
  160. 	return;
  161. }

extra_pref

  1. /* bias a monster's preferences towards armor that has special benefits. */
  2. /* currently only does speed boots, but might be expanded if monsters get to
  3. use more armor abilities */
  4. static int
  5. extra_pref(mon, obj)
  6. struct monst *mon;
  7. struct obj *obj;
  8. {
  9. if (obj) {
  10. 	if (obj->otyp == SPEED_BOOTS && mon->permspeed != MFAST)
  11. 	    return 20;
  12. }
  13. return 0;
  14. }

racial_exception

  1. /*
  2. * Exceptions to things based on race. Correctly checks polymorphed player race.
  3. * Returns:
  4. *	 0 No exception, normal rules apply.
  5. * 	 1 If the race/object combination is acceptable.
  6. *	-1 If the race/object combination is unacceptable.
  7. */
  8. int
  9. racial_exception(mon, obj)
  10. struct monst *mon;
  11. struct obj *obj;
  12. {
  13. const struct permonst *ptr = raceptr(mon);
  14.  
  15. /* Acceptable Exceptions: */
  16. /* Allow hobbits to wear elven armor - LoTR */
  17. if (ptr == &mons[PM_HOBBIT] && is_elven_armor(obj))
  18. 	return 1;
  19. /* Unacceptable Exceptions: */
  20. /* Checks for object that certain races should never use go here */
  21. /*	return -1; */
  22.  
  23. return 0;
  24. }
  25. /*worn.c*/