Fandom

Wikihack

Source:NetHack 3.4.0/worn.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

Warning! This is the source code from an old release. For the latest release, see Source code

The NetHack General Public License applies to screenshots, source code and other content from NetHack.
1.    /*	SCCS Id: @(#)worn.c	3.4	2002/02/07	*/
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include "hack.h"
6.    
7.    STATIC_DCL void FDECL(m_lose_armor, (struct monst *,struct obj *));
8.    STATIC_DCL void FDECL(m_dowear_type, (struct monst *,long,BOOLEAN_P));
9.    STATIC_DCL int FDECL(extra_pref, (struct monst *, struct obj *));
10.   
11.   const struct worn {
12.   	long w_mask;
13.   	struct obj **w_obj;
14.   } worn[] = {
15.   	{ W_ARM, &uarm },
16.   	{ W_ARMC, &uarmc },
17.   	{ W_ARMH, &uarmh },
18.   	{ W_ARMS, &uarms },
19.   	{ W_ARMG, &uarmg },
20.   	{ W_ARMF, &uarmf },
21.   #ifdef TOURIST
22.   	{ W_ARMU, &uarmu },
23.   #endif
24.   	{ W_RINGL, &uleft },
25.   	{ W_RINGR, &uright },
26.   	{ W_WEP, &uwep },
27.   	{ W_SWAPWEP, &uswapwep },
28.   	{ W_QUIVER, &uquiver },
29.   	{ W_AMUL, &uamul },
30.   	{ W_TOOL, &ublindf },
31.   	{ W_BALL, &uball },
32.   	{ W_CHAIN, &uchain },
33.   	{ 0, 0 }
34.   };
35.   
36.   /* This only allows for one blocking item per property */
37.   #define w_blocks(o,m) \
38.   		((o->otyp == MUMMY_WRAPPING && ((m) & W_ARMC)) ? INVIS : \
39.   		 (o->otyp == CORNUTHAUM && ((m) & W_ARMH) && \
40.   			!Role_if(PM_WIZARD)) ? CLAIRVOYANT : 0)
41.   		/* note: monsters don't have clairvoyance, so your role
42.   		   has no significant effect on their use of w_blocks() */
43.   
44.   
45.   /* Updated to use the extrinsic and blocked fields. */
46.   void
47.   setworn(obj, mask)
48.   register struct obj *obj;
49.   long mask;
50.   {
51.   	register const struct worn *wp;
52.   	register struct obj *oobj;
53.   	register int p;
54.   
55.   	if ((mask & (W_ARM|I_SPECIAL)) == (W_ARM|I_SPECIAL)) {
56.   	    /* restoring saved game; no properties are conferred via skin */
57.   	    uskin = obj;
58.   	 /* assert( !uarm ); */
59.   	} else {
60.   	    for(wp = worn; wp->w_mask; wp++) if(wp->w_mask & mask) {
61.   		oobj = *(wp->w_obj);
62.   		if(oobj && !(oobj->owornmask & wp->w_mask))
63.   			impossible("Setworn: mask = %ld.", wp->w_mask);
64.   		if(oobj) {
65.   		    if (u.twoweap && (oobj->owornmask & (W_WEP|W_SWAPWEP)))
66.   			u.twoweap = 0;
67.   		    oobj->owornmask &= ~wp->w_mask;
68.   		    if (wp->w_mask & ~(W_SWAPWEP|W_QUIVER)) {
69.   			/* leave as "x = x <op> y", here and below, for broken
70.   			 * compilers */
71.   			p = objects[oobj->otyp].oc_oprop;
72.   			u.uprops[p].extrinsic =
73.   					u.uprops[p].extrinsic & ~wp->w_mask;
74.   			if ((p = w_blocks(oobj,mask)) != 0)
75.   			    u.uprops[p].blocked &= ~wp->w_mask;
76.   			if (oobj->oartifact)
77.   			    set_artifact_intrinsic(oobj, 0, mask);
78.   		    }
79.   		}
80.   		*(wp->w_obj) = obj;
81.   		if(obj) {
82.   		    obj->owornmask |= wp->w_mask;
83.   		    /* Prevent getting/blocking intrinsics from wielding
84.   		     * potions, through the quiver, etc.
85.   		     * Allow weapon-tools, too.
86.   		     * wp_mask should be same as mask at this point.
87.   		     */
88.   		    if (wp->w_mask & ~(W_SWAPWEP|W_QUIVER)) {
89.   			if (obj->oclass == WEAPON_CLASS || is_weptool(obj) ||
90.   					    mask != W_WEP) {
91.   			    p = objects[obj->otyp].oc_oprop;
92.   			    u.uprops[p].extrinsic =
93.   					u.uprops[p].extrinsic | wp->w_mask;
94.   			    if ((p = w_blocks(obj, mask)) != 0)
95.   				u.uprops[p].blocked |= wp->w_mask;
96.   			}
97.   			if (obj->oartifact)
98.   			    set_artifact_intrinsic(obj, 1, mask);
99.   		    }
100.  		}
101.  	    }
102.  	}
103.  	update_inventory();
104.  }
105.  
106.  /* called e.g. when obj is destroyed */
107.  /* Updated to use the extrinsic and blocked fields. */
108.  void
109.  setnotworn(obj)
110.  register struct obj *obj;
111.  {
112.  	register const struct worn *wp;
113.  	register int p;
114.  
115.  	if (!obj) return;
116.  	if (obj == uwep || obj == uswapwep) u.twoweap = 0;
117.  	for(wp = worn; wp->w_mask; wp++)
118.  	    if(obj == *(wp->w_obj)) {
119.  		*(wp->w_obj) = 0;
120.  		p = objects[obj->otyp].oc_oprop;
121.  		u.uprops[p].extrinsic = u.uprops[p].extrinsic & ~wp->w_mask;
122.  		obj->owornmask &= ~wp->w_mask;
123.  		if (obj->oartifact)
124.  		    set_artifact_intrinsic(obj, 0, wp->w_mask);
125.  		if ((p = w_blocks(obj,wp->w_mask)) != 0)
126.  		    u.uprops[p].blocked &= ~wp->w_mask;
127.  	    }
128.  	update_inventory();
129.  }
130.  
131.  void
132.  mon_set_minvis(mon)
133.  struct monst *mon;
134.  {
135.  	mon->perminvis = 1;
136.  	if (!mon->invis_blkd) {
137.  	    mon->minvis = 1;
138.  	    newsym(mon->mx, mon->my);		/* make it disappear */
139.  	    if (mon->wormno) see_wsegs(mon);	/* and any tail too */
140.  	}
141.  }
142.  
143.  void
144.  mon_adjust_speed(mon, adjust, obj)
145.  struct monst *mon;
146.  int adjust;	/* positive => increase speed, negative => decrease */
147.  struct obj *obj;	/* item to make known if effect can be seen */
148.  {
149.      struct obj *otmp;
150.      boolean give_msg = !in_mklev;
151.      unsigned int oldspeed = mon->mspeed;
152.  
153.      switch (adjust) {
154.       case  2:
155.  	mon->permspeed = MFAST;
156.  	give_msg = FALSE;	/* special case monster creation */
157.  	break;
158.       case  1:
159.  	if (mon->permspeed == MSLOW) mon->permspeed = 0;
160.  	else mon->permspeed = MFAST;
161.  	break;
162.       case  0:			/* just check for worn speed boots */
163.  	break;
164.       case -1:
165.  	if (mon->permspeed == MFAST) mon->permspeed = 0;
166.  	else mon->permspeed = MSLOW;
167.  	break;
168.       case -2:
169.  	mon->permspeed = MSLOW;
170.  	give_msg = FALSE;	/* (not currently used) */
171.  	break;
172.      }
173.  
174.      for (otmp = mon->minvent; otmp; otmp = otmp->nobj)
175.  	if (otmp->owornmask && objects[otmp->otyp].oc_oprop == FAST)
176.  	    break;
177.      if (otmp)		/* speed boots */
178.  	mon->mspeed = MFAST;
179.      else
180.  	mon->mspeed = mon->permspeed;
181.  
182.      if (give_msg && mon->mspeed != oldspeed && canseemon(mon)) {
183.  	/* fast to slow (skipping intermediate state) or vice versa */
184.  	const char *howmuch = (mon->mspeed + oldspeed == MFAST + MSLOW) ?
185.  				"much " : "";
186.  
187.  	if (adjust > 0 || mon->mspeed == MFAST)
188.  	    pline("%s is suddenly moving %sfaster.", Monnam(mon), howmuch);
189.  	else
190.  	    pline("%s seems to be moving %sslower.", Monnam(mon), howmuch);
191.  
192.  	/* might discover an object if we see the speed change happen, but
193.  	   avoid making possibly forgotten book known when casting its spell */
194.  	if (obj != 0 && obj->dknown &&
195.  		objects[obj->otyp].oc_class != SPBOOK_CLASS)
196.  	    makeknown(obj->otyp);
197.      }
198.  }
199.  
200.  /* armor put on or taken off; might be magical variety */
201.  void
202.  update_mon_intrinsics(mon, obj, on)
203.  struct monst *mon;
204.  struct obj *obj;
205.  boolean on;
206.  {
207.      int unseen;
208.      uchar mask;
209.      struct obj *otmp;
210.      int which = (int) objects[obj->otyp].oc_oprop;
211.  
212.      unseen = !canseemon(mon);
213.      if (!which) goto maybe_blocks;
214.  
215.      if (on) {
216.  	switch (which) {
217.  	 case INVIS:
218.  	    mon->minvis = !mon->invis_blkd;
219.  	    break;
220.  	 case FAST:
221.  	    mon_adjust_speed(mon, 0, obj);
222.  	    break;
223.  	/* properties handled elsewhere */
224.  	 case ANTIMAGIC:
225.  	 case REFLECTING:
226.  	    break;
227.  	/* properties which have no effect for monsters */
228.  	 case CLAIRVOYANT:
229.  	 case STEALTH:
230.  	 case TELEPAT:
231.  	    break;
232.  	/* properties which should have an effect but aren't implemented */
233.  	 case LEVITATION:
234.  	 case WWALKING:
235.  	    break;
236.  	/* properties which maybe should have an effect but don't */
237.  	 case DISPLACED:
238.  	 case FUMBLING:
239.  	 case JUMPING:
240.  	 case PROTECTION:
241.  	    break;
242.  	 default:
243.  	    if (which <= 8) {	/* 1 thru 8 correspond to MR_xxx mask values */
244.  		/* FIRE,COLD,SLEEP,DISINT,SHOCK,POISON,ACID,STONE */
245.  		mask = (uchar) (1 << (which - 1));
246.  		mon->mintrinsics |= (unsigned short) mask;
247.  	    }
248.  	    break;
249.  	}
250.      } else {	    /* off */
251.  	switch (which) {
252.  	 case INVIS:
253.  	    mon->minvis = mon->perminvis;
254.  	    break;
255.  	 case FAST:
256.  	    mon_adjust_speed(mon, 0, obj);
257.  	    break;
258.  	 case FIRE_RES:
259.  	 case COLD_RES:
260.  	 case SLEEP_RES:
261.  	 case DISINT_RES:
262.  	 case SHOCK_RES:
263.  	 case POISON_RES:
264.  	 case ACID_RES:
265.  	 case STONE_RES:
266.  	    mask = (uchar) (1 << (which - 1));
267.  	    /* If the monster doesn't have this resistance intrinsically,
268.  	       check whether any other worn item confers it.  Note that
269.  	       we don't currently check for anything conferred via simply
270.  	       carrying an object. */
271.  	    if (!(mon->data->mresists & mask)) {
272.  		for (otmp = mon->minvent; otmp; otmp = otmp->nobj)
273.  		    if (otmp->owornmask &&
274.  			    (int) objects[otmp->otyp].oc_oprop == which)
275.  			break;
276.  		if (!otmp)
277.  		    mon->mintrinsics &= ~((unsigned short) mask);
278.  	    }
279.  	    break;
280.  	 default:
281.  	    break;
282.  	}
283.      }
284.  
285.   maybe_blocks:
286.      /* obj->owornmask has been cleared by this point, so we can't use it.
287.         However, since monsters don't wield armor, we don't have to guard
288.         against that and can get away with a blanket worn-mask value. */
289.      switch (w_blocks(obj,~0L)) {
290.       case INVIS:
291.  	mon->invis_blkd = on ? 1 : 0;
292.  	mon->minvis = on ? 0 : mon->perminvis;
293.  	break;
294.       default:
295.  	break;
296.      }
297.  
298.  #ifdef STEED
299.  	if (!on && mon == u.usteed && obj->otyp == SADDLE)
300.  	    dismount_steed(DISMOUNT_FELL);
301.  #endif
302.  
303.      /* if couldn't see it but now can, or vice versa, update display */
304.      if (unseen ^ !canseemon(mon))
305.  	newsym(mon->mx, mon->my);
306.  }
307.  
308.  int
309.  find_mac(mon)
310.  register struct monst *mon;
311.  {
312.  	register struct obj *obj;
313.  	int base = mon->data->ac;
314.  	long mwflags = mon->misc_worn_check;
315.  
316.  	for (obj = mon->minvent; obj; obj = obj->nobj) {
317.  	    if (obj->owornmask & mwflags)
318.  		base -= ARM_BONUS(obj);
319.  		/* since ARM_BONUS is positive, subtracting it increases AC */
320.  	}
321.  	return base;
322.  }
323.  
324.  /* weapons are handled separately; rings and eyewear aren't used by monsters */
325.  
326.  /* Wear the best object of each type that the monster has.  During creation,
327.   * the monster can put everything on at once; otherwise, wearing takes time.
328.   * This doesn't affect monster searching for objects--a monster may very well
329.   * search for objects it would not want to wear, because we don't want to
330.   * check which_armor() each round.
331.   *
332.   * We'll let monsters put on shirts and/or suits under worn cloaks, but
333.   * not shirts under worn suits.  This is somewhat arbitrary, but it's
334.   * too tedious to have them remove and later replace outer garments,
335.   * and preventing suits under cloaks makes it a little bit too easy for
336.   * players to influence what gets worn.  Putting on a shirt underneath
337.   * already worn body armor is too obviously buggy...
338.   */
339.  void
340.  m_dowear(mon, creation)
341.  register struct monst *mon;
342.  boolean creation;
343.  {
344.  	/* Note the restrictions here are the same as in dowear in do_wear.c
345.  	 * except for the additional restriction on intelligence.  (Players
346.  	 * are always intelligent, even if polymorphed).
347.  	 */
348.  	if (verysmall(mon->data) || nohands(mon->data) || is_animal(mon->data))
349.  		return;
350.  	/* give mummies a chance to wear their wrappings */
351.  	if (mindless(mon->data) && (mon->data->mlet != S_MUMMY || !creation))
352.  		return;
353.  
354.  	m_dowear_type(mon, W_AMUL, creation);
355.  #ifdef TOURIST
356.  	/* can't put on shirt if already wearing suit */
357.  	if (!cantweararm(mon->data) || (mon->misc_worn_check & W_ARM))
358.  	    m_dowear_type(mon, W_ARMU, creation);
359.  #endif
360.  	/* treating small as a special case allows
361.  	   hobbits, gnomes, and kobolds to wear cloaks */
362.  	if (!cantweararm(mon->data) || mon->data->msize == MZ_SMALL)
363.  	    m_dowear_type(mon, W_ARMC, creation);
364.  	m_dowear_type(mon, W_ARMH, creation);
365.  	if (!MON_WEP(mon) || !bimanual(MON_WEP(mon)))
366.  	    m_dowear_type(mon, W_ARMS, creation);
367.  	m_dowear_type(mon, W_ARMG, creation);
368.  	if (!slithy(mon->data) && mon->data->mlet != S_CENTAUR)
369.  	    m_dowear_type(mon, W_ARMF, creation);
370.  	if (!cantweararm(mon->data))
371.  	    m_dowear_type(mon, W_ARM, creation);
372.  }
373.  
374.  STATIC_OVL void
375.  m_dowear_type(mon, flag, creation)
376.  struct monst *mon;
377.  long flag;
378.  boolean creation;
379.  {
380.  	struct obj *old, *best, *obj;
381.  	int m_delay = 0;
382.  
383.  	if (mon->mfrozen) return; /* probably putting previous item on */
384.  
385.  	old = which_armor(mon, flag);
386.  	if (old && old->cursed) return;
387.  	if (old && flag == W_AMUL) return; /* no such thing as better amulets */
388.  	best = old;
389.  
390.  	for(obj = mon->minvent; obj; obj = obj->nobj) {
391.  	    switch(flag) {
392.  		case W_AMUL:
393.  		    if (obj->oclass != AMULET_CLASS ||
394.  			    (obj->otyp != AMULET_OF_LIFE_SAVING &&
395.  				obj->otyp != AMULET_OF_REFLECTION))
396.  			continue;
397.  		    best = obj;
398.  		    goto outer_break; /* no such thing as better amulets */
399.  #ifdef TOURIST
400.  		case W_ARMU:
401.  		    if (!is_shirt(obj)) continue;
402.  		    break;
403.  #endif
404.  		case W_ARMC:
405.  		    if (!is_cloak(obj)) continue;
406.  		    break;
407.  		case W_ARMH:
408.  		    if (!is_helmet(obj)) continue;
409.  		    break;
410.  		case W_ARMS:
411.  		    if (!is_shield(obj)) continue;
412.  		    break;
413.  		case W_ARMG:
414.  		    if (!is_gloves(obj)) continue;
415.  		    break;
416.  		case W_ARMF:
417.  		    if (!is_boots(obj)) continue;
418.  		    break;
419.  		case W_ARM:
420.  		    if (!is_suit(obj)) continue;
421.  		    break;
422.  	    }
423.  	    if (obj->owornmask) continue;
424.  	    /* I'd like to define a VISIBLE_ARM_BONUS which doesn't assume the
425.  	     * monster knows obj->spe, but if I did that, a monster would keep
426.  	     * switching forever between two -2 caps since when it took off one
427.  	     * it would forget spe and once again think the object is better
428.  	     * than what it already has.
429.  	     */
430.  	    if (best && (ARM_BONUS(best) + extra_pref(mon,best) >= ARM_BONUS(obj) + extra_pref(mon,obj)))
431.  		continue;
432.  	    best = obj;
433.  	}
434.  outer_break:
435.  	if (!best || best == old) return;
436.  
437.  	/* if wearing a cloak, account for the time spent removing
438.  	   and re-wearing it when putting on a suit or shirt */
439.  	if ((flag == W_ARM
440.  #ifdef TOURIST
441.  	  || flag == W_ARMU
442.  #endif
443.  			  ) && (mon->misc_worn_check & W_ARMC))
444.  	    m_delay += 2;
445.  	/* when upgrading a piece of armor, account for time spent
446.  	   taking off current one */
447.  	if (old)
448.  	    m_delay += objects[old->otyp].oc_delay;
449.  
450.  	if (old) /* do this first to avoid "(being worn)" */
451.  	    old->owornmask = 0L;
452.  	if (!creation) {
453.  	    if (canseemon(mon)) {
454.  		char buf[BUFSZ];
455.  
456.  		if (old)
457.  		    Sprintf(buf, " removes %s and", distant_name(old, doname));
458.  		else
459.  		    buf[0] = '\0';
460.  		pline("%s%s puts on %s.", Monnam(mon),
461.  		      buf, distant_name(best,doname));
462.  	    } /* can see it */
463.  	    m_delay += objects[best->otyp].oc_delay;
464.  	    mon->mfrozen = m_delay;
465.  	    if (mon->mfrozen) mon->mcanmove = 0;
466.  	}
467.  	if (old)
468.  	    update_mon_intrinsics(mon, old, FALSE);
469.  	mon->misc_worn_check |= flag;
470.  	best->owornmask |= flag;
471.  	update_mon_intrinsics(mon, best, TRUE);
472.  }
473.  
474.  struct obj *
475.  which_armor(mon, flag)
476.  struct monst *mon;
477.  long flag;
478.  {
479.  	register struct obj *obj;
480.  
481.  	for(obj = mon->minvent; obj; obj = obj->nobj)
482.  		if (obj->owornmask & flag) return obj;
483.  	return((struct obj *)0);
484.  }
485.  
486.  /* remove an item of armor and then drop it */
487.  STATIC_OVL void
488.  m_lose_armor(mon, obj)
489.  struct monst *mon;
490.  struct obj *obj;
491.  {
492.  	mon->misc_worn_check &= ~obj->owornmask;
493.  	obj->owornmask = 0L;
494.  	update_mon_intrinsics(mon, obj, FALSE);
495.  
496.  	obj_extract_self(obj);
497.  	place_object(obj, mon->mx, mon->my);
498.  	/* call stackobj() if we ever drop anything that can merge */
499.  	newsym(mon->mx, mon->my);
500.  }
501.  
502.  void
503.  clear_bypasses()
504.  {
505.  	struct obj *otmp, *nobj;
506.  
507.  	for (otmp = fobj; otmp; otmp = nobj) {
508.  	    nobj = otmp->nobj;
509.  	    if (otmp->bypass) {
510.  		otmp->bypass = 0;
511.  #if 0
512.  		/*  setting otmp->bypass changes mergability.
513.  		 *  If monster can ever drop anything that
514.                   *  can and should merge, this code block
515.  		 *  should be enabled.
516.  		 */
517.  		{
518.  		    struct obj *obj;
519.  		    xchar ox, oy;
520.  		    (void) get_obj_location(otmp, &ox, &oy, 0);
521.  		    obj_extract_self(otmp);
522.  		    obj = merge_choice(fobj, otmp);
523.  		    /* If it can't merge, then place it */
524.  		    if (!obj || (obj && !merged(&obj, &otmp)))
525.  		        place_object(otmp, ox, oy);
526.  		    newsym(ox, oy);
527.  		}
528.  #endif
529.  	    }
530.  	}
531.  	flags.bypasses = FALSE;
532.  }
533.  
534.  void
535.  bypass_obj(obj)
536.  struct obj *obj;
537.  {
538.  	obj->bypass = 1;
539.  	flags.bypasses = TRUE;
540.  }
541.  
542.  void
543.  mon_break_armor(mon, polyspot)
544.  struct monst *mon;
545.  boolean polyspot;
546.  {
547.  	register struct obj *otmp;
548.  	struct permonst *mdat = mon->data;
549.  	boolean vis = cansee(mon->mx, mon->my);
550.  	const char *pronoun = mhim(mon),
551.  			*ppronoun = mhis(mon);
552.  
553.  	if (breakarm(mdat)) {
554.  	    if ((otmp = which_armor(mon, W_ARM)) != 0) {
555.  		if ((Is_dragon_scales(otmp) &&
556.  			mdat == Dragon_scales_to_pm(otmp)) ||
557.  		    (Is_dragon_mail(otmp) && mdat == Dragon_mail_to_pm(otmp)))
558.  		    ;	/* no message here;
559.  			   "the dragon merges with his scaly armor" is odd
560.  			   and the monster's previous form is already gone */
561.  		else if (vis)
562.  		    pline("%s breaks out of %s armor!", Monnam(mon), ppronoun);
563.  		else
564.  		    You_hear("a cracking sound.");
565.  		m_useup(mon, otmp);
566.  	    }
567.  	    if ((otmp = which_armor(mon, W_ARMC)) != 0) {
568.  		if (otmp->oartifact) {
569.  		    if (vis)
570.  			pline("%s %s falls off!", s_suffix(Monnam(mon)),
571.  				cloak_simple_name(otmp));
572.  		    if (polyspot) bypass_obj(otmp);
573.  		    m_lose_armor(mon, otmp);
574.  		} else {
575.  		    if (vis)
576.  			pline("%s %s tears apart!", s_suffix(Monnam(mon)),
577.  				cloak_simple_name(otmp));
578.  		    else
579.  			You_hear("a ripping sound.");
580.  		    m_useup(mon, otmp);
581.  		}
582.  	    }
583.  #ifdef TOURIST
584.  	    if ((otmp = which_armor(mon, W_ARMU)) != 0) {
585.  		if (vis)
586.  		    pline("%s shirt rips to shreds!", s_suffix(Monnam(mon)));
587.  		else
588.  		    You_hear("a ripping sound.");
589.  		m_useup(mon, otmp);
590.  	    }
591.  #endif
592.  	} else if (sliparm(mdat)) {
593.  	    if ((otmp = which_armor(mon, W_ARM)) != 0) {
594.  		if (vis)
595.  		    pline("%s armor falls around %s!",
596.  				 s_suffix(Monnam(mon)), pronoun);
597.  		else
598.  		    You_hear("a thud.");
599.  		if (polyspot) bypass_obj(otmp);
600.  		m_lose_armor(mon, otmp);
601.  	    }
602.  	    if ((otmp = which_armor(mon, W_ARMC)) != 0) {
603.  		if (vis) {
604.  		    if (is_whirly(mon->data))
605.  			pline("%s %s falls, unsupported!",
606.  				     s_suffix(Monnam(mon)), cloak_simple_name(otmp));
607.  		    else
608.  			pline("%s shrinks out of %s %s!", Monnam(mon),
609.  						ppronoun, cloak_simple_name(otmp));
610.  		}
611.  		if (polyspot) bypass_obj(otmp);
612.  		m_lose_armor(mon, otmp);
613.  	    }
614.  #ifdef TOURIST
615.  	    if ((otmp = which_armor(mon, W_ARMU)) != 0) {
616.  		if (vis) {
617.  		    if (sliparm(mon->data))
618.  			pline("%s seeps right through %s shirt!",
619.  					Monnam(mon), ppronoun);
620.  		    else
621.  			pline("%s becomes much too small for %s shirt!",
622.  					Monnam(mon), ppronoun);
623.  		}
624.  		if (polyspot) bypass_obj(otmp);
625.  		m_lose_armor(mon, otmp);
626.  	    }
627.  #endif
628.  	}
629.  	if (nohands(mdat) || verysmall(mdat)) {
630.  	    if ((otmp = which_armor(mon, W_ARMG)) != 0) {
631.  		if (vis)
632.  		    pline("%s drops %s gloves%s!", Monnam(mon), ppronoun,
633.  					MON_WEP(mon) ? " and weapon" : "");
634.  		possibly_unwield(mon);
635.  		if (polyspot) bypass_obj(otmp);
636.  		m_lose_armor(mon, otmp);
637.  	    }
638.  	    if ((otmp = which_armor(mon, W_ARMS)) != 0) {
639.  		if (vis)
640.  		    pline("%s can no longer hold %s shield!", Monnam(mon),
641.  								ppronoun);
642.  		else
643.  		    You_hear("a clank.");
644.  		if (polyspot) bypass_obj(otmp);
645.  		m_lose_armor(mon, otmp);
646.  	    }
647.  	    if ((otmp = which_armor(mon, W_ARMH)) != 0) {
648.  		if (vis)
649.  		    pline("%s helmet falls to the %s!",
650.  			  s_suffix(Monnam(mon)), surface(mon->mx, mon->my));
651.  		else
652.  		    You_hear("a clank.");
653.  		if (polyspot) bypass_obj(otmp);
654.  		m_lose_armor(mon, otmp);
655.  	    }
656.  	}
657.  	if (nohands(mdat) || verysmall(mdat) || slithy(mdat) ||
658.  	    mdat->mlet == S_CENTAUR) {
659.  	    if ((otmp = which_armor(mon, W_ARMF)) != 0) {
660.  		if (vis) {
661.  		    if (is_whirly(mon->data))
662.  			pline("%s boots fall away!",
663.  				       s_suffix(Monnam(mon)));
664.  		    else pline("%s boots %s off %s feet!",
665.  			s_suffix(Monnam(mon)),
666.  			verysmall(mdat) ? "slide" : "are pushed", ppronoun);
667.  		}
668.  		if (polyspot) bypass_obj(otmp);
669.  		m_lose_armor(mon, otmp);
670.  	    }
671.  	}
672.  #ifdef STEED
673.  	if (!can_saddle(mon)) {
674.  	    if ((otmp = which_armor(mon, W_SADDLE)) != 0) {
675.  		if (polyspot) bypass_obj(otmp);
676.  		m_lose_armor(mon, otmp);
677.  		if (vis)
678.  		    pline("%s saddle falls off.", s_suffix(Monnam(mon)));
679.  	    }
680.  	    if (mon == u.usteed)
681.  		goto noride;
682.  	} else if (mon == u.usteed && !can_ride(mon)) {
683.  	noride:
684.  	    You("can no longer ride %s.", mon_nam(mon));
685.  	    if (touch_petrifies(u.usteed->data) &&
686.  			!Stone_resistance && rnl(3)) {
687.  		char buf[BUFSZ];
688.  
689.  		You("touch %s.", mon_nam(u.usteed));
690.  		Sprintf(buf, "falling off %s",
691.  				an(u.usteed->data->mname));
692.  		instapetrify(buf);
693.  	    }
694.  	    dismount_steed(DISMOUNT_FELL);
695.  	}
696.  #endif
697.  	return;
698.  }
699.  
700.  /* bias a monster's preferences towards armor that has special benefits. */
701.  /* currently only does speed boots, but might be expanded if monsters get to
702.     use more armor abilities */
703.  static int
704.  extra_pref(mon, obj)
705.  struct monst *mon;
706.  struct obj *obj;
707.  {
708.      if (obj) {
709.  	if (obj->otyp == SPEED_BOOTS && mon->permspeed != MFAST)
710.  	    return 20;
711.      }
712.      return 0;
713.  }
714.  /*worn.c*/

Also on Fandom

Random Wiki