Source:NetHack 3.2.0/do wear.c

From NetHackWiki
(Redirected from NetHack 3.2.0/do wear.c)
Jump to navigation Jump to search

Below is the full text to do_wear.c from the source code of NetHack 3.2.0.

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

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.    /*	SCCS Id: @(#)do_wear.c	3.2	96/02/29	*/
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.    #ifndef OVLB
8.    
9.    STATIC_DCL long takeoff_mask, taking_off;
10.   
11.   #else /* OVLB */
12.   
13.   STATIC_OVL NEARDATA long takeoff_mask = 0L, taking_off = 0L;
14.   
15.   static NEARDATA int todelay;
16.   
17.   static NEARDATA const char see_yourself[] = "see yourself";
18.   static NEARDATA const char unknown_type[] = "Unknown type of %s (%d)";
19.   static NEARDATA const char *c_armor  = "armor",
20.   			   *c_suit   = "suit",
21.   #ifdef TOURIST
22.   			   *c_shirt  = "shirt",
23.   #endif
24.   			   *c_cloak  = "cloak",
25.   			   *c_gloves = "gloves",
26.   			   *c_boots  = "boots",
27.   			   *c_helmet = "helmet",
28.   			   *c_shield = "shield",
29.   			   *c_weapon = "weapon",
30.   			   *c_sword  = "sword",
31.   			   *c_axe    = "axe",
32.   			   *c_that_  = "that";
33.   
34.   static NEARDATA const long takeoff_order[] = { WORN_BLINDF, 1L, /* weapon */
35.   	WORN_SHIELD, WORN_GLOVES, LEFT_RING, RIGHT_RING, WORN_CLOAK,
36.   	WORN_HELMET, WORN_AMUL, WORN_ARMOR,
37.   #ifdef TOURIST
38.   	WORN_SHIRT,
39.   #endif
40.   	WORN_BOOTS, 0L };
41.   
42.   static void FDECL(on_msg, (struct obj *));
43.   STATIC_PTR int NDECL(Armor_on);
44.   STATIC_PTR int NDECL(Boots_on);
45.   static int NDECL(Cloak_on);
46.   STATIC_PTR int NDECL(Helmet_on);
47.   STATIC_PTR int NDECL(Gloves_on);
48.   static void NDECL(Amulet_on);
49.   static void FDECL(Ring_off_or_gone, (struct obj *, BOOLEAN_P));
50.   STATIC_PTR int FDECL(select_off, (struct obj *));
51.   static struct obj *NDECL(do_takeoff);
52.   STATIC_PTR int NDECL(take_off);
53.   static int FDECL(menu_remarm, (int));
54.   static void FDECL(already_wearing, (const char*));
55.   
56.   void
57.   off_msg(otmp)
58.   register struct obj *otmp;
59.   {
60.   	if(flags.verbose)
61.   	    You("were wearing %s.", doname(otmp));
62.   }
63.   
64.   /* for items that involve no delay */
65.   static void
66.   on_msg(otmp)
67.   register struct obj *otmp;
68.   {
69.   	if(flags.verbose)
70.   	    You("are now wearing %s.",
71.   		obj_is_pname(otmp) ? the(xname(otmp)) : an(xname(otmp)));
72.   }
73.   
74.   /*
75.    * The Type_on() functions should be called *after* setworn().
76.    * The Type_off() functions call setworn() themselves.
77.    */
78.   
79.   STATIC_PTR
80.   int
81.   Boots_on()
82.   {
83.       long oldprop = u.uprops[objects[uarmf->otyp].oc_oprop].p_flgs & ~WORN_BOOTS;
84.   
85.       switch(uarmf->otyp) {
86.   	case LOW_BOOTS:
87.   	case IRON_SHOES:
88.   	case HIGH_BOOTS:
89.   	case JUMPING_BOOTS:
90.   		break;
91.   	case WATER_WALKING_BOOTS:
92.   		if (u.uinwater) spoteffects();
93.   		break;
94.   	case SPEED_BOOTS:
95.   		/* Speed boots are still better than intrinsic speed, */
96.   		/* though not better than potion speed */
97.   		if (!(oldprop & TIMEOUT)) {
98.   			makeknown(uarmf->otyp);
99.   			You_feel("yourself speed up%s.",
100.  				oldprop ? " a bit more" : "");
101.  		}
102.  		break;
103.  	case ELVEN_BOOTS:
104.  		if (!oldprop) {
105.  			makeknown(uarmf->otyp);
106.  			You("walk very quietly.");
107.  		}
108.  		break;
109.  	case FUMBLE_BOOTS:
110.  		if (!(oldprop & ~TIMEOUT))
111.  			Fumbling += rnd(20);
112.  		break;
113.  	case LEVITATION_BOOTS:
114.  		if (!oldprop) {
115.  			makeknown(uarmf->otyp);
116.  			float_up();
117.  		}
118.  		break;
119.  	default: impossible(unknown_type, c_boots, uarmf->otyp);
120.      }
121.      return 0;
122.  }
123.  
124.  int
125.  Boots_off()
126.  {
127.      int otyp = uarmf->otyp;
128.      long oldprop = u.uprops[objects[otyp].oc_oprop].p_flgs & ~WORN_BOOTS;
129.  
130.  	/* For levitation, float_down() returns if Levitation, so we
131.  	 * must do a setworn() _before_ the levitation case.
132.  	 */
133.      setworn((struct obj *)0, W_ARMF);
134.      switch (otyp) {
135.  	case SPEED_BOOTS:
136.  		if (!(oldprop & TIMEOUT)) {
137.  			makeknown(otyp);
138.  			You_feel("yourself slow down%s.",
139.  				oldprop ? " a bit" : "");
140.  		}
141.  		break;
142.  	case WATER_WALKING_BOOTS:
143.  		if (is_pool(u.ux,u.uy) && !Levitation
144.  			    && !is_flyer(uasmon) && !is_clinger(uasmon)) {
145.  			makeknown(otyp);
146.  			/* make boots known in case you survive the drowning */
147.  			spoteffects();
148.  		}
149.  		break;
150.  	case ELVEN_BOOTS:
151.  		if (!oldprop) {
152.  			makeknown(otyp);
153.  			You("sure are noisy.");
154.  		}
155.  		break;
156.  	case FUMBLE_BOOTS:
157.  		if (!(oldprop & ~TIMEOUT))
158.  			Fumbling = 0;
159.  		break;
160.  	case LEVITATION_BOOTS:
161.  		if (!oldprop) {
162.  			(void) float_down(0L);
163.  			makeknown(otyp);
164.  		}
165.  		break;
166.  	case LOW_BOOTS:
167.  	case IRON_SHOES:
168.  	case HIGH_BOOTS:
169.  	case JUMPING_BOOTS:
170.  		break;
171.  	default: impossible(unknown_type, c_boots, otyp);
172.      }
173.      return 0;
174.  }
175.  
176.  static int
177.  Cloak_on()
178.  {
179.      long oldprop = u.uprops[objects[uarmc->otyp].oc_oprop].p_flgs & ~WORN_CLOAK;
180.  
181.      switch(uarmc->otyp) {
182.  	case ELVEN_CLOAK:
183.  	case CLOAK_OF_PROTECTION:
184.  	case CLOAK_OF_DISPLACEMENT:
185.  		makeknown(uarmc->otyp);
186.  		break;
187.  	case ORCISH_CLOAK:
188.  	case DWARVISH_CLOAK:
189.  	case CLOAK_OF_MAGIC_RESISTANCE:
190.  		break;
191.  	case MUMMY_WRAPPING:
192.  		/* Note: it's already being worn, so we have to cheat here. */
193.  		if (((HInvis & ~I_BLOCKED) || pm_invisible(uasmon))
194.  		    && !See_invisible && !Blind) {
195.  			newsym(u.ux,u.uy);
196.  			You("can %s!", see_yourself);
197.  		}
198.  		break;
199.  	case CLOAK_OF_INVISIBILITY:
200.  		/* since cloak of invisibility was worn, we know mummy wrapping
201.  		   wasn't, so no need to check `oldprop' against I_BLOCKED */
202.  		if (!oldprop && !See_invisible && !Blind) {
203.  			makeknown(uarmc->otyp);
204.  			newsym(u.ux,u.uy);
205.  			pline("Suddenly you cannot %s.", see_yourself);
206.  		}
207.  		break;
208.  	case OILSKIN_CLOAK:
209.  		pline("%s fits very tightly.",The(xname(uarmc)));
210.  		break;
211.  	default: impossible(unknown_type, c_cloak, uarmc->otyp);
212.      }
213.      return 0;
214.  }
215.  
216.  int
217.  Cloak_off()
218.  {
219.      int otyp = uarmc->otyp;
220.      long oldprop = u.uprops[objects[otyp].oc_oprop].p_flgs & ~WORN_CLOAK;
221.  
222.  	/* For mummy wrapping, taking it off first resets `Invisible'. */
223.      setworn((struct obj *)0, W_ARMC);
224.      switch (otyp) {
225.  	case ELVEN_CLOAK:
226.  	case ORCISH_CLOAK:
227.  	case DWARVISH_CLOAK:
228.  	case CLOAK_OF_PROTECTION:
229.  	case CLOAK_OF_MAGIC_RESISTANCE:
230.  	case CLOAK_OF_DISPLACEMENT:
231.  	case OILSKIN_CLOAK:
232.  		break;
233.  	case MUMMY_WRAPPING:
234.  		if (Invisible && !Blind) {
235.  			newsym(u.ux,u.uy);
236.  			You("can no longer %s.", see_yourself);
237.  		}
238.  		break;
239.  	case CLOAK_OF_INVISIBILITY:
240.  		if (!oldprop && !See_invisible && !Blind) {
241.  			makeknown(CLOAK_OF_INVISIBILITY);
242.  			newsym(u.ux,u.uy);
243.  			pline("Suddenly you can %s.", see_yourself);
244.  		}
245.  		break;
246.  	default: impossible(unknown_type, c_cloak, otyp);
247.      }
248.      return 0;
249.  }
250.  
251.  STATIC_PTR
252.  int
253.  Helmet_on()
254.  {
255.      switch(uarmh->otyp) {
256.  	case FEDORA:
257.  	case HELMET:
258.  	case DENTED_POT:
259.  	case ELVEN_LEATHER_HELM:
260.  	case DWARVISH_IRON_HELM:
261.  	case ORCISH_HELM:
262.  	case HELM_OF_TELEPATHY:
263.  		break;
264.  	case HELM_OF_BRILLIANCE:
265.  		if (uarmh->spe) {
266.  			ABON(A_INT) += uarmh->spe;
267.  			ABON(A_WIS) += uarmh->spe;
268.  			flags.botl = 1;
269.  			makeknown(uarmh->otyp);
270.  		}
271.  		break;
272.  	case CORNUTHAUM:
273.  		/* people think marked wizards know what they're talking
274.  		 * about, but it takes trained arrogance to pull it off,
275.  		 * and the actual enchantment of the hat is irrelevant.
276.  		 */
277.  		ABON(A_CHA) += (Role_is('W') ? 1 : -1);
278.  		flags.botl = 1;
279.  		makeknown(uarmh->otyp);
280.  		break;
281.  	case HELM_OF_OPPOSITE_ALIGNMENT:
282.  		if (u.ualign.type == A_NEUTRAL)
283.  		    u.ualign.type = rn2(2) ? A_CHAOTIC : A_LAWFUL;
284.  		else u.ualign.type = -(u.ualign.type);
285.  		u.ublessed = 0; /* lose your god's protection */
286.  	     /* makeknown(uarmh->otyp);   -- moved below, after xname() */
287.  		/*FALLTHRU*/
288.  	case DUNCE_CAP:
289.  		if (!uarmh->cursed) {
290.  		    pline("%s %s%s for a moment.", The(xname(uarmh)),
291.  			  Blind ? "vibrates" : "glows ",
292.  			  Blind ? (const char *)"" : hcolor(Black));
293.  		    curse(uarmh);
294.  		}
295.  		flags.botl = 1;		/* reveal new alignment or INT & WIS */
296.  		if (Hallucination) {
297.  		    pline("My brain hurts!"); /* Monty Python's Flying Circus */
298.  		} else if (uarmh->otyp == DUNCE_CAP) {
299.  		    You_feel("%s.",	/* track INT change; ignore WIS */
300.  		  ACURR(A_INT) <= (ABASE(A_INT) + ABON(A_INT) + ATEMP(A_INT)) ?
301.  			     "like sitting in a corner" : "giddy");
302.  		} else {
303.  		    Your("%s oscillates briefly.",
304.  			 mindless(uasmon) ? body_part(HEAD) : "mind");
305.  		    makeknown(HELM_OF_OPPOSITE_ALIGNMENT);
306.  		}
307.  		break;
308.  	default: impossible(unknown_type, c_helmet, uarmh->otyp);
309.      }
310.      return 0;
311.  }
312.  
313.  int
314.  Helmet_off()
315.  {
316.      switch(uarmh->otyp) {
317.  	case FEDORA:
318.  	case HELMET:
319.  	case DENTED_POT:
320.  	case ELVEN_LEATHER_HELM:
321.  	case DWARVISH_IRON_HELM:
322.  	case ORCISH_HELM:
323.  		break;
324.  	case DUNCE_CAP:
325.  		flags.botl = 1;
326.  		break;
327.  	case CORNUTHAUM:
328.  		ABON(A_CHA) += (Role_is('W') ? -1 : 1);
329.  		flags.botl = 1;
330.  		break;
331.  	case HELM_OF_TELEPATHY:
332.  		/* need to update ability before calling see_monsters() */
333.  		setworn((struct obj *)0, W_ARMH);
334.  		see_monsters();
335.  		return 0;
336.  	case HELM_OF_BRILLIANCE:
337.  		if (uarmh->spe) {
338.  			ABON(A_INT) -= uarmh->spe;
339.  			ABON(A_WIS) -= uarmh->spe;
340.  			flags.botl = 1;
341.  		}
342.  		break;
343.  	case HELM_OF_OPPOSITE_ALIGNMENT:
344.  		u.ualign.type = u.ualignbase[0];
345.  		u.ublessed = 0; /* lose the other god's protection */
346.  		flags.botl = 1;
347.  		break;
348.  	default: impossible(unknown_type, c_helmet, uarmh->otyp);
349.      }
350.      setworn((struct obj *)0, W_ARMH);
351.      return 0;
352.  }
353.  
354.  STATIC_PTR
355.  int
356.  Gloves_on()
357.  {
358.      long oldprop =
359.  	u.uprops[objects[uarmg->otyp].oc_oprop].p_flgs & ~(WORN_GLOVES | TIMEOUT);
360.  
361.      switch(uarmg->otyp) {
362.  	case LEATHER_GLOVES:
363.  		break;
364.  	case GAUNTLETS_OF_FUMBLING:
365.  		if (!oldprop)
366.  			Fumbling += rnd(20);
367.  		break;
368.  	case GAUNTLETS_OF_POWER:
369.  		makeknown(uarmg->otyp);
370.  		flags.botl = 1; /* taken care of in attrib.c */
371.  		break;
372.  	case GAUNTLETS_OF_DEXTERITY:
373.  		if (uarmg->spe) makeknown(uarmg->otyp);
374.  		ABON(A_DEX) += uarmg->spe;
375.  		flags.botl = 1;
376.  		break;
377.  	default: impossible(unknown_type, c_gloves, uarmg->otyp);
378.      }
379.      return 0;
380.  }
381.  
382.  int
383.  Gloves_off()
384.  {
385.      long oldprop =
386.  	u.uprops[objects[uarmg->otyp].oc_oprop].p_flgs & ~(WORN_GLOVES | TIMEOUT);
387.  
388.      switch(uarmg->otyp) {
389.  	case LEATHER_GLOVES:
390.  		break;
391.  	case GAUNTLETS_OF_FUMBLING:
392.  		if (!oldprop)
393.  			Fumbling = 0;
394.  		break;
395.  	case GAUNTLETS_OF_POWER:
396.  		makeknown(uarmg->otyp);
397.  		flags.botl = 1; /* taken care of in attrib.c */
398.  		break;
399.  	case GAUNTLETS_OF_DEXTERITY:
400.  		if (uarmg->spe) makeknown(uarmg->otyp);
401.  		ABON(A_DEX) -= uarmg->spe;
402.  		flags.botl = 1;
403.  		break;
404.  	default: impossible(unknown_type, c_gloves, uarmg->otyp);
405.      }
406.      setworn((struct obj *)0, W_ARMG);
407.      if (uwep && uwep->otyp == CORPSE && uwep->corpsenm == PM_COCKATRICE) {
408.  	/* Prevent wielding cockatrice when not wearing gloves */
409.  	You("wield the cockatrice corpse in your bare %s.",
410.  	    makeplural(body_part(HAND)));
411.  	instapetrify("cockatrice corpse");
412.  	uwepgone();  /* life-saved still doesn't allow touching cockatrice */
413.      }
414.      return 0;
415.  }
416.  
417.  /*
418.  static int
419.  Shield_on()
420.  {
421.      switch(uarms->otyp) {
422.  	case SMALL_SHIELD:
423.  	case ELVEN_SHIELD:
424.  	case URUK_HAI_SHIELD:
425.  	case ORCISH_SHIELD:
426.  	case DWARVISH_ROUNDSHIELD:
427.  	case LARGE_SHIELD:
428.  	case SHIELD_OF_REFLECTION:
429.  		break;
430.  	default: impossible(unknown_type, c_shield, uarms->otyp);
431.      }
432.      return 0;
433.  }
434.  */
435.  
436.  int
437.  Shield_off()
438.  {
439.  /*
440.      switch(uarms->otyp) {
441.  	case SMALL_SHIELD:
442.  	case ELVEN_SHIELD:
443.  	case URUK_HAI_SHIELD:
444.  	case ORCISH_SHIELD:
445.  	case DWARVISH_ROUNDSHIELD:
446.  	case LARGE_SHIELD:
447.  	case SHIELD_OF_REFLECTION:
448.  		break;
449.  	default: impossible(unknown_type, c_shield, uarms->otyp);
450.      }
451.  */
452.      setworn((struct obj *)0, W_ARMS);
453.      return 0;
454.  }
455.  
456.  /* This must be done in worn.c, because one of the possible intrinsics conferred
457.   * is fire resistance, and we have to immediately set HFire_resistance in worn.c
458.   * since worn.c will check it before returning.
459.   */
460.  STATIC_PTR
461.  int
462.  Armor_on()
463.  {
464.      return 0;
465.  }
466.  
467.  int
468.  Armor_off()
469.  {
470.      setworn((struct obj *)0, W_ARM);
471.      return 0;
472.  }
473.  
474.  /* The gone functions differ from the off functions in that if you die from
475.   * taking it off and have life saving, you still die.
476.   */
477.  int
478.  Armor_gone()
479.  {
480.      setnotworn(uarm);
481.      return 0;
482.  }
483.  
484.  static void
485.  Amulet_on()
486.  {
487.      switch(uamul->otyp) {
488.  	case AMULET_OF_ESP:
489.  	case AMULET_OF_LIFE_SAVING:
490.  	case AMULET_VERSUS_POISON:
491.  	case AMULET_OF_REFLECTION:
492.  	case AMULET_OF_MAGICAL_BREATHING:
493.  	case FAKE_AMULET_OF_YENDOR:
494.  		break;
495.  	case AMULET_OF_CHANGE:
496.  		makeknown(AMULET_OF_CHANGE);
497.  		change_sex();
498.  		/* Don't use same message as polymorph */
499.  		You("are suddenly very %s!", flags.female ? "feminine"
500.  			: "masculine");
501.  		flags.botl = 1;
502.  		pline_The("amulet disintegrates!");
503.  		useup(uamul);
504.  		break;
505.  	case AMULET_OF_STRANGULATION:
506.  		makeknown(AMULET_OF_STRANGULATION);
507.  		pline("It constricts your throat!");
508.  		Strangled = 6;
509.  		break;
510.  	case AMULET_OF_RESTFUL_SLEEP:
511.  		Sleeping = rnd(100);
512.  		break;
513.  	case AMULET_OF_YENDOR:
514.  		break;
515.      }
516.  }
517.  
518.  void
519.  Amulet_off()
520.  {
521.      switch(uamul->otyp) {
522.  	case AMULET_OF_ESP:
523.  		/* need to update ability before calling see_monsters() */
524.  		setworn((struct obj *)0, W_AMUL);
525.  		see_monsters();
526.  		return;
527.  	case AMULET_OF_LIFE_SAVING:
528.  	case AMULET_VERSUS_POISON:
529.  	case AMULET_OF_REFLECTION:
530.  	case FAKE_AMULET_OF_YENDOR:
531.  		break;
532.  	case AMULET_OF_MAGICAL_BREATHING:
533.  		if (Underwater) {
534.  		    if (!breathless(uasmon) && !amphibious(uasmon)
535.  						&& !is_swimmer(uasmon))
536.  			You("suddenly inhale an unhealthy amount of water!");
537.  		    /* HMagical_breathing must be set off
538.  		       before calling drown() */
539.  		    setworn((struct obj *)0, W_AMUL);
540.  		    (void) drown();
541.  		    return;
542.  		}
543.  		break;
544.  	case AMULET_OF_CHANGE:
545.  		impossible("Wearing an amulet of change?");
546.  		break;
547.  	case AMULET_OF_STRANGULATION:
548.  		if (Strangled) {
549.  			You("can breathe more easily!");
550.  			Strangled = 0;
551.  		}
552.  		break;
553.  	case AMULET_OF_RESTFUL_SLEEP:
554.  		Sleeping = 0;
555.  		break;
556.  	case AMULET_OF_YENDOR:
557.  		break;
558.      }
559.      setworn((struct obj *)0, W_AMUL);
560.  }
561.  
562.  void
563.  Ring_on(obj)
564.  register struct obj *obj;
565.  {
566.      long oldprop = u.uprops[objects[obj->otyp].oc_oprop].p_flgs;
567.      int old_attrib;
568.  
569.      /* only mask out W_RING when we don't have both
570.         left and right rings of the same type */
571.      if ((oldprop & W_RING) != W_RING) oldprop &= ~W_RING;
572.  
573.      switch(obj->otyp){
574.  	case RIN_TELEPORTATION:
575.  	case RIN_REGENERATION:
576.  	case RIN_SEARCHING:
577.  	case RIN_STEALTH:
578.  	case RIN_HUNGER:
579.  	case RIN_AGGRAVATE_MONSTER:
580.  	case RIN_POISON_RESISTANCE:
581.  	case RIN_FIRE_RESISTANCE:
582.  	case RIN_COLD_RESISTANCE:
583.  	case RIN_SHOCK_RESISTANCE:
584.  	case RIN_CONFLICT:
585.  	case RIN_WARNING:
586.  	case RIN_TELEPORT_CONTROL:
587.  	case RIN_POLYMORPH:
588.  	case RIN_POLYMORPH_CONTROL:
589.  		break;
590.  	case RIN_SEE_INVISIBLE:
591.  		/* can now see invisible monsters */
592.  		set_mimic_blocking(); /* do special mimic handling */
593.  		see_monsters();
594.  
595.  		if (Invis && !oldprop && !perceives(uasmon) && !Blind) {
596.  			newsym(u.ux,u.uy);
597.  			pline("Suddenly you can see yourself.");
598.  			makeknown(RIN_SEE_INVISIBLE);
599.  		}
600.  		break;
601.  	case RIN_INVISIBILITY:
602.  		if (!oldprop && !See_invisible && !Blind) {
603.  			makeknown(RIN_INVISIBILITY);
604.  			newsym(u.ux,u.uy);
605.  			Your("body takes on a %s transparency...",
606.  				Hallucination ? "normal" : "strange");
607.  		}
608.  		break;
609.  	case RIN_ADORNMENT:
610.  		old_attrib = ACURR(A_CHA);
611.  		ABON(A_CHA) += obj->spe;
612.  		flags.botl = 1;
613.  		if (ACURR(A_CHA) != old_attrib ||
614.  		    (objects[RIN_ADORNMENT].oc_name_known &&
615.  		     old_attrib != 25 && old_attrib != 3)) {
616.  			makeknown(RIN_ADORNMENT);
617.  			obj->known = TRUE;
618.  		}
619.  		break;
620.  	case RIN_LEVITATION:
621.  		if(!oldprop) {
622.  			float_up();
623.  			makeknown(RIN_LEVITATION);
624.  			obj->known = TRUE;
625.  		}
626.  		break;
627.  	case RIN_GAIN_STRENGTH:
628.  		old_attrib = ACURR(A_STR);
629.  		ABON(A_STR) += obj->spe;
630.  		flags.botl = 1;
631.  		if (ACURR(A_STR) != old_attrib ||
632.  		    (objects[RIN_GAIN_STRENGTH].oc_name_known &&
633.  		     old_attrib != 125 && old_attrib != 3)) {
634.  			makeknown(RIN_GAIN_STRENGTH);
635.  			obj->known = TRUE;
636.  		}
637.  		break;
638.  	case RIN_INCREASE_DAMAGE:
639.  		u.udaminc += obj->spe;
640.  		break;
641.  	case RIN_PROTECTION_FROM_SHAPE_CHAN:
642.  		rescham();
643.  		break;
644.  	case RIN_PROTECTION:
645.  		flags.botl = 1;
646.  		if (obj->spe || objects[RIN_PROTECTION].oc_name_known) {
647.  			makeknown(RIN_PROTECTION);
648.  			obj->known = TRUE;
649.  		}
650.  		break;
651.      }
652.  }
653.  
654.  static void
655.  Ring_off_or_gone(obj,gone)
656.  register struct obj *obj;
657.  boolean gone;
658.  {
659.      register long mask = obj->owornmask & W_RING;
660.      int old_attrib;
661.  
662.      if(!(u.uprops[objects[obj->otyp].oc_oprop].p_flgs & mask))
663.  	impossible("Strange... I didn't know you had that ring.");
664.      if(gone) setnotworn(obj);
665.      else setworn((struct obj *)0, obj->owornmask);
666.      switch(obj->otyp) {
667.  	case RIN_TELEPORTATION:
668.  	case RIN_REGENERATION:
669.  	case RIN_SEARCHING:
670.  	case RIN_STEALTH:
671.  	case RIN_HUNGER:
672.  	case RIN_AGGRAVATE_MONSTER:
673.  	case RIN_POISON_RESISTANCE:
674.  	case RIN_FIRE_RESISTANCE:
675.  	case RIN_COLD_RESISTANCE:
676.  	case RIN_SHOCK_RESISTANCE:
677.  	case RIN_CONFLICT:
678.  	case RIN_WARNING:
679.  	case RIN_TELEPORT_CONTROL:
680.  	case RIN_POLYMORPH:
681.  	case RIN_POLYMORPH_CONTROL:
682.  		break;
683.  	case RIN_SEE_INVISIBLE:
684.  		/* Make invisible monsters go away */
685.  		if (!See_invisible) {
686.  		    set_mimic_blocking(); /* do special mimic handling */
687.  		    see_monsters();
688.  		}
689.  
690.  		if (Invisible && !Blind) {
691.  			newsym(u.ux,u.uy);
692.  			pline("Suddenly you cannot see yourself.");
693.  			makeknown(RIN_SEE_INVISIBLE);
694.  		}
695.  		break;
696.  	case RIN_INVISIBILITY:
697.  		if (!Invis && !(HInvis & I_BLOCKED) &&
698.  		    !See_invisible && !Blind) {
699.  			newsym(u.ux,u.uy);
700.  			Your("body seems to unfade...");
701.  			makeknown(RIN_INVISIBILITY);
702.  		}
703.  		break;
704.  	case RIN_ADORNMENT:
705.  		old_attrib = ACURR(A_CHA);
706.  		ABON(A_CHA) -= obj->spe;
707.  		if (ACURR(A_CHA) != old_attrib) makeknown(RIN_ADORNMENT);
708.  		flags.botl = 1;
709.  		break;
710.  	case RIN_LEVITATION:
711.  		(void) float_down(0L);
712.  		if (!Levitation) makeknown(RIN_LEVITATION);
713.  		break;
714.  	case RIN_GAIN_STRENGTH:
715.  		old_attrib = ACURR(A_STR);
716.  		ABON(A_STR) -= obj->spe;
717.  		if (ACURR(A_STR) != old_attrib) makeknown(RIN_GAIN_STRENGTH);
718.  		flags.botl = 1;
719.  		break;
720.  	case RIN_INCREASE_DAMAGE:
721.  		u.udaminc -= obj->spe;
722.  		break;
723.  	case RIN_PROTECTION_FROM_SHAPE_CHAN:
724.  		/* If you're no longer protected, let the chameleons
725.  		 * change shape again -dgk
726.  		 */
727.  		restartcham();
728.  		break;
729.      }
730.  }
731.  
732.  void
733.  Ring_off(obj)
734.  struct obj *obj;
735.  {
736.  	Ring_off_or_gone(obj,FALSE);
737.  }
738.  
739.  void
740.  Ring_gone(obj)
741.  struct obj *obj;
742.  {
743.  	Ring_off_or_gone(obj,TRUE);
744.  }
745.  
746.  void
747.  Blindf_on(otmp)
748.  register struct obj *otmp;
749.  {
750.  	long already_blinded = Blinded;
751.  
752.  	if (otmp == uwep)
753.  	    setuwep((struct obj *) 0);
754.  	setworn(otmp, W_TOOL);
755.  	if (otmp->otyp == TOWEL && flags.verbose)
756.  	    You("wrap %s around your %s.", an(xname(otmp)), body_part(HEAD));
757.  	on_msg(otmp);
758.  	if (!already_blinded) {
759.  	    if (Punished) set_bc(0);	/* Set ball&chain variables before */
760.  					/* the hero goes blind.		   */
761.  	    if (Telepat) see_monsters();/* sense monsters */
762.  	    vision_full_recalc = 1;	/* recalc vision limits */
763.  	    flags.botl = 1;
764.  	}
765.  }
766.  
767.  void
768.  Blindf_off(otmp)
769.  register struct obj *otmp;
770.  {
771.  	setworn((struct obj *)0, otmp->owornmask);
772.  	off_msg(otmp);
773.  	if (!Blinded) {
774.  	    if (Telepat) see_monsters();/* no longer sense monsters */
775.  	    vision_full_recalc = 1;	/* recalc vision limits */
776.  	    flags.botl = 1;
777.  	} else
778.  	    You("still cannot see.");
779.  }
780.  
781.  /* called in main to set intrinsics of worn start-up items */
782.  void
783.  set_wear()
784.  {
785.  	if (uarm)  (void) Armor_on();
786.  	if (uarmc) (void) Cloak_on();
787.  	if (uarmf) (void) Boots_on();
788.  	if (uarmg) (void) Gloves_on();
789.  	if (uarmh) (void) Helmet_on();
790.  /*	if (uarms) (void) Shield_on(); */
791.  }
792.  
793.  boolean
794.  donning(otmp)
795.  register struct obj *otmp;
796.  {
797.      return((boolean)((otmp == uarmf && (afternmv == Boots_on || afternmv == Boots_off))
798.  	|| (otmp == uarmh && (afternmv == Helmet_on || afternmv == Helmet_off))
799.  	|| (otmp == uarmg && (afternmv == Gloves_on || afternmv == Gloves_off))
800.  	|| (otmp == uarm && (afternmv == Armor_on || afternmv == Armor_off))));
801.  }
802.  
803.  void
804.  cancel_don()
805.  {
806.  	/* the piece of armor we were donning/doffing has vanished, so stop
807.  	 * wasting time on it (and don't dereference it when donning would
808.  	 * otherwise finish)
809.  	 */
810.  	afternmv = 0;
811.  	nomovemsg = (char *)0;
812.  	multi = 0;
813.  }
814.  
815.  static NEARDATA const char clothes[] = {ARMOR_CLASS, 0};
816.  static NEARDATA const char accessories[] = {RING_CLASS, AMULET_CLASS, TOOL_CLASS, 0};
817.  
818.  int
819.  dotakeoff()
820.  {
821.  	register struct obj *otmp = (struct obj *)0;
822.  	int armorpieces = 0;
823.  
824.  #define MOREARM(x) if (x) { armorpieces++; otmp = x; }
825.  	MOREARM(uarmh);
826.  	MOREARM(uarms);
827.  	MOREARM(uarmg);
828.  	MOREARM(uarmf);
829.  	if (uarmc) {
830.  		armorpieces++;
831.  		otmp = uarmc;
832.  	} else if (uarm) {
833.  		armorpieces++;
834.  		otmp = uarm;
835.  #ifdef TOURIST
836.  	} else if (uarmu) {
837.  		armorpieces++;
838.  		otmp = uarmu;
839.  #endif
840.  	}
841.  	if (!armorpieces) {
842.  	     /* assert( GRAY_DRAGON_SCALES > YELLOW_DRAGON_SCALE_MAIL ); */
843.  		if (uskin)
844.  		    pline_The("%s merged with your skin!",
845.  			      uskin->otyp >= GRAY_DRAGON_SCALES ?
846.  				"dragon scales are" : "dragon scale mail is");
847.  		else
848.  		    pline("Not wearing any armor.");
849.  		return 0;
850.  	}
851.  	if (armorpieces > 1)
852.  		otmp = getobj(clothes, "take off");
853.  	if (otmp == 0) return(0);
854.  	if (!(otmp->owornmask & W_ARMOR)) {
855.  		You("are not wearing that.");
856.  		return(0);
857.  	}
858.  	/* note: the `uskin' case shouldn't be able to happen here; dragons
859.  	   can't wear any armor so will end up with `armorpieces == 0' above */
860.  	if (otmp == uskin || ((otmp == uarm) && uarmc)
861.  #ifdef TOURIST
862.  			  || ((otmp == uarmu) && (uarmc || uarm))
863.  #endif
864.  		) {
865.  	    You_cant("take that off.");
866.  	    return 0;
867.  	}
868.  	if (otmp == uarmg && welded(uwep)) {
869.  	    You("seem unable to take off the gloves while holding your %s.",
870.  		is_sword(uwep) ? c_sword : c_weapon);
871.  	    uwep->bknown = TRUE;
872.  	    return 0;
873.  	}
874.  	if (otmp == uarmg && Glib) {
875.  	    You_cant("remove the slippery gloves with your slippery fingers.");
876.  	    return 0;
877.  	}
878.  	if (otmp == uarmf && u.utrap && (u.utraptype == TT_BEARTRAP ||
879.  					u.utraptype == TT_INFLOOR)) { /* -3. */
880.  	    if(u.utraptype == TT_BEARTRAP)
881.  		pline_The("bear trap prevents you from pulling your %s out.",
882.  		      body_part(FOOT));
883.  	    else
884.  		You("are stuck in the %s, and cannot pull your %s out.",
885.  		    surface(u.ux, u.uy), makeplural(body_part(FOOT)));
886.  		return(0);
887.  	}
888.  	reset_remarm();			/* since you may change ordering */
889.  	(void) armoroff(otmp);
890.  	return(1);
891.  }
892.  
893.  int
894.  doremring()
895.  {
896.  	register struct obj *otmp = 0;
897.  	int Accessories = 0;
898.  
899.  #define MOREACC(x) if (x) { Accessories++; otmp = x; }
900.  	MOREACC(uleft);
901.  	MOREACC(uright);
902.  	MOREACC(uamul);
903.  	MOREACC(ublindf);
904.  
905.  	if(!Accessories) {
906.  		pline("Not wearing any accessories.");
907.  		return(0);
908.  	}
909.  	if (Accessories != 1) otmp = getobj(accessories, "take off");
910.  	if(!otmp) return(0);
911.  	if(!(otmp->owornmask & (W_RING | W_AMUL | W_TOOL))) {
912.  		You("are not wearing that.");
913.  		return(0);
914.  	}
915.  	if(cursed(otmp)) return(0);
916.  	if(otmp->oclass == RING_CLASS) {
917.  		if (nolimbs(uasmon)) {
918.  			pline("It seems to be stuck.");
919.  			return(0);
920.  		}
921.  		if (uarmg && uarmg->cursed) {
922.  			uarmg->bknown = TRUE;
923.  			You(
924.  	    "seem unable to remove your ring without taking off your gloves.");
925.  			return(0);
926.  		}
927.  		if (welded(uwep) && bimanual(uwep)) {
928.  			uwep->bknown = TRUE;
929.  			You(
930.  	       "seem unable to remove the ring while your hands hold your %s.",
931.  			    is_sword(uwep) ? c_sword : c_weapon);
932.  			return(0);
933.  		}
934.  		if (welded(uwep) && otmp==uright) {
935.  			uwep->bknown = TRUE;
936.  			You(
937.  	 "seem unable to remove the ring while your right hand holds your %s.",
938.  			    is_sword(uwep) ? c_sword : c_weapon);
939.  			return(0);
940.  		}
941.  		/* Sometimes we want to give the off_msg before removing and
942.  		 * sometimes after; for instance, "you were wearing a moonstone
943.  		 * ring (on right hand)" is desired but "you were wearing a
944.  		 * square amulet (being worn)" is not because of the redundant
945.  		 * "being worn".
946.  		 */
947.  		off_msg(otmp);
948.  		Ring_off(otmp);
949.  	} else if(otmp->oclass == AMULET_CLASS) {
950.  		Amulet_off();
951.  		off_msg(otmp);
952.  	} else Blindf_off(otmp); /* does its own off_msg */
953.  	return(1);
954.  }
955.  
956.  /* Check if something worn is cursed _and_ unremovable. */
957.  int
958.  cursed(otmp)
959.  register struct obj *otmp;
960.  {
961.  	/* Curses, like chickens, come home to roost. */
962.  	if((otmp == uwep) ? welded(otmp) : (int)otmp->cursed) {
963.  		You("can't.  %s to be cursed.",
964.  			(is_boots(otmp) || is_gloves(otmp) || otmp->quan > 1L)
965.  			? "They seem" : "It seems");
966.  		otmp->bknown = TRUE;
967.  		return(1);
968.  	}
969.  	return(0);
970.  }
971.  
972.  int
973.  armoroff(otmp)
974.  register struct obj *otmp;
975.  {
976.  	register int delay = -objects[otmp->otyp].oc_delay;
977.  
978.  	if(cursed(otmp)) return(0);
979.  	if(delay) {
980.  		nomul(delay);
981.  		if (is_helmet(otmp)) {
982.  			nomovemsg = "You finish taking off your helmet.";
983.  			afternmv = Helmet_off;
984.  		     }
985.  		else if (is_gloves(otmp)) {
986.  			nomovemsg = "You finish taking off your gloves.";
987.  			afternmv = Gloves_off;
988.  		     }
989.  		else if (is_boots(otmp)) {
990.  			nomovemsg = "You finish taking off your boots.";
991.  			afternmv = Boots_off;
992.  		     }
993.  		else {
994.  			nomovemsg = "You finish taking off your suit.";
995.  			afternmv = Armor_off;
996.  		}
997.  	} else {
998.  		/* Be warned!  We want off_msg after removing the item to
999.  		 * avoid "You were wearing ____ (being worn)."  However, an
1000. 		 * item which grants fire resistance might cause some trouble
1001. 		 * if removed in Hell and lifesaving puts it back on; in this
1002. 		 * case the message will be printed at the wrong time (after
1003. 		 * the messages saying you died and were lifesaved).  Luckily,
1004. 		 * no cloak, shield, or fast-removable armor grants fire
1005. 		 * resistance, so we can safely do the off_msg afterwards.
1006. 		 * Rings do grant fire resistance, but for rings we want the
1007. 		 * off_msg before removal anyway so there's no problem.  Take
1008. 		 * care in adding armors granting fire resistance; this code
1009. 		 * might need modification.
1010. 		 * 3.2 (actually 3.1 even): this comment is obsolete since
1011. 		 * fire resistance is not needed for Gehennom.
1012. 		 */
1013. 		if(is_cloak(otmp))
1014. 			(void) Cloak_off();
1015. 		else if(is_shield(otmp))
1016. 			(void) Shield_off();
1017. 		else setworn((struct obj *)0, otmp->owornmask & W_ARMOR);
1018. 		off_msg(otmp);
1019. 	}
1020. 	takeoff_mask = taking_off = 0L;
1021. 	return(1);
1022. }
1023. 
1024. static void
1025. already_wearing(cc)
1026. const char *cc;
1027. {
1028. 	You("are already wearing %s%c", cc, (cc == c_that_) ? '!' : '.');
1029. }
1030. 
1031. /* the 'W' command */
1032. int
1033. dowear()
1034. {
1035. 	register struct obj *otmp;
1036. 	register int delay;
1037. 	register int err = 0;
1038. 	long mask = 0;
1039. 	const char *which;
1040. 
1041. 	/* cantweararm checks for suits of armor */
1042. 	/* verysmall or nohands checks for shields, gloves, etc... */
1043. 	if ((verysmall(uasmon) || nohands(uasmon))) {
1044. 		pline("Don't even bother.");
1045. 		return(0);
1046. 	}
1047. 
1048. 	otmp = getobj(clothes, "wear");
1049. 	if(!otmp) return(0);
1050. 
1051. 	which = is_cloak(otmp) ? c_cloak :
1052. #ifdef TOURIST
1053. 		is_shirt(otmp) ? c_shirt :
1054. #endif
1055. 		is_suit(otmp)  ? c_suit  : 0;
1056. 	if (which && cantweararm(uasmon) &&
1057. 		/* same exception for cloaks as used in m_dowear() */
1058. 		(which != c_cloak || uasmon->msize != MZ_SMALL)) {
1059. 	    pline_The("%s will not fit on your body.", which);
1060. 	    return 0;
1061. 	} else if (otmp->owornmask & W_ARMOR) {
1062. 	    already_wearing(c_that_);
1063. 	    return 0;
1064. 	}
1065. 
1066. 	if(is_helmet(otmp)) {
1067. 		if(uarmh) {
1068. 			already_wearing(an(c_helmet));
1069. 			err++;
1070. 		} else
1071. 			mask = W_ARMH;
1072. 	} else if(is_shield(otmp)){
1073. 		if(uarms) {
1074. 			already_wearing(an(c_shield));
1075. 			err++;
1076. 		}
1077. 		if(uwep && bimanual(uwep)) {
1078. 		    You("cannot wear a shield while wielding a two-handed %s.",
1079. 			is_sword(uwep) ? c_sword :
1080. 				uwep->otyp == BATTLE_AXE ? c_axe : c_weapon);
1081. 			err++;
1082. 		}
1083. 		if(!err) mask = W_ARMS;
1084. 	} else if(is_boots(otmp)) {
1085. 		if (uarmf) {
1086. 			already_wearing(c_boots);
1087. 			err++;
1088. 		} else if (Upolyd && slithy(uasmon)) {
1089. 			You("have no feet...");	/* not body_part(FOOT) */
1090. 			err++;
1091. 		} else if (u.utrap && (u.utraptype == TT_BEARTRAP ||
1092. 				  u.utraptype == TT_INFLOOR)) {
1093. 			if (u.utraptype == TT_BEARTRAP)
1094. 			    Your("%s is trapped!", body_part(FOOT));
1095. 			else
1096. 			    Your("%s are stuck in the %s!",
1097. 				 makeplural(body_part(FOOT)),
1098. 				 surface(u.ux, u.uy));
1099. 			err++;
1100. 		} else
1101. 			mask = W_ARMF;
1102. 	} else if(is_gloves(otmp)) {
1103. 		if(uarmg) {
1104. 			already_wearing(c_gloves);
1105. 			err++;
1106. 		} else if (welded(uwep)) {
1107. 			You("cannot wear gloves over your %s.",
1108. 			      is_sword(uwep) ? c_sword : c_weapon);
1109. 			err++;
1110. 		} else
1111. 			mask = W_ARMG;
1112. #ifdef TOURIST
1113. 	} else if(is_shirt(otmp)) {
1114. 		if (uarm || uarmc || uarmu) {
1115. 			if(uarmu)
1116. 			   already_wearing(an(c_shirt));
1117. 			else
1118. 			   You_cant("wear that over your %s.",
1119. 				 (uarm && !uarmc) ? c_armor : c_cloak);
1120. 			err++;
1121. 		} else
1122. 			mask = W_ARMU;
1123. #endif
1124. 	} else if(is_cloak(otmp)) {
1125. 		if(uarmc) {
1126. 			already_wearing(an(c_cloak));
1127. 			err++;
1128. 		} else
1129. 			mask = W_ARMC;
1130. 	} else {
1131. 		if(uarmc) {
1132. 			You("cannot wear armor over a cloak.");
1133. 			err++;
1134. 		} else if(uarm) {
1135. 			already_wearing("some armor");
1136. 			err++;
1137. 		}
1138. 		if(!err) mask = W_ARM;
1139. 	}
1140. /* Unnecessary since now only weapons and special items like pick-axes get
1141.  * welded to your hand, not armor
1142. 	if(welded(otmp)) {
1143. 		if(!err++)
1144. 			weldmsg(otmp, FALSE);
1145. 	}
1146.  */
1147. 	if(err) return(0);
1148. 
1149. 	if (otmp->oartifact && !touch_artifact(otmp, &youmonst))
1150. 	    return 1;	/* costs a turn even though it didn't get worn */
1151. 
1152. 	if (otmp->otyp == HELM_OF_OPPOSITE_ALIGNMENT &&
1153. 			qstart_level.dnum == u.uz.dnum) {	/* in quest */
1154. 		You("narrowly avoid losing all chance at your goal.");
1155. 		u.ublessed = 0; /* lose your god's protection */
1156. 		makeknown(otmp->otyp);
1157. 		flags.botl = 1;
1158. 		return 1;
1159. 	}
1160. 
1161. 	otmp->known = TRUE;
1162. 	if(otmp == uwep)
1163. 		setuwep((struct obj *)0);
1164. 	setworn(otmp, mask);
1165. 	delay = -objects[otmp->otyp].oc_delay;
1166. 	if(delay){
1167. 		nomul(delay);
1168. 		if(is_boots(otmp)) afternmv = Boots_on;
1169. 		if(is_helmet(otmp)) afternmv = Helmet_on;
1170. 		if(is_gloves(otmp)) afternmv = Gloves_on;
1171. 		if(otmp == uarm) afternmv = Armor_on;
1172. 		nomovemsg = "You finish your dressing maneuver.";
1173. 	} else {
1174. 		if(is_cloak(otmp)) (void) Cloak_on();
1175. /*		if(is_shield(otmp)) (void) Shield_on(); */
1176. 		on_msg(otmp);
1177. 	}
1178. 	takeoff_mask = taking_off = 0L;
1179. 	return(1);
1180. }
1181. 
1182. int
1183. doputon()
1184. {
1185. 	register struct obj *otmp;
1186. 	long mask = 0L;
1187. 
1188. 	if(uleft && uright && uamul && ublindf) {
1189.     Your("%s%s are full, and you're already wearing an amulet and a blindfold.",
1190. 			humanoid(uasmon) ? "ring-" : "",
1191. 			makeplural(body_part(FINGER)));
1192. 		return(0);
1193. 	}
1194. 	otmp = getobj(accessories, "wear");
1195. 	if(!otmp) return(0);
1196. 	if(otmp->owornmask & (W_RING | W_AMUL | W_TOOL)) {
1197. 		already_wearing(c_that_);
1198. 		return(0);
1199. 	}
1200. 	if(welded(otmp)) {
1201. 		weldmsg(otmp, TRUE);
1202. 		return(0);
1203. 	}
1204. 	if(otmp == uwep)
1205. 		setuwep((struct obj *)0);
1206. 	if(otmp->oclass == RING_CLASS) {
1207. 		if(nolimbs(uasmon)) {
1208. 			You("cannot make the ring stick to your body.");
1209. 			return(0);
1210. 		}
1211. 		if(uleft && uright){
1212. 			pline("There are no more %s%s to fill.",
1213. 				humanoid(uasmon) ? "ring-" : "",
1214. 				makeplural(body_part(FINGER)));
1215. 			return(0);
1216. 		}
1217. 		if(uleft) mask = RIGHT_RING;
1218. 		else if(uright) mask = LEFT_RING;
1219. 		else do {
1220. 			char qbuf[QBUFSZ];
1221. 			char answer;
1222. 
1223. 			Sprintf(qbuf, "What %s%s, Right or Left?",
1224. 				humanoid(uasmon) ? "ring-" : "",
1225. 				body_part(FINGER));
1226. 			if(!(answer = yn_function(qbuf, "rl", '\0')))
1227. 				return(0);
1228. 			switch(answer){
1229. 			case 'l':
1230. 			case 'L':
1231. 				mask = LEFT_RING;
1232. 				break;
1233. 			case 'r':
1234. 			case 'R':
1235. 				mask = RIGHT_RING;
1236. 				break;
1237. 			}
1238. 		} while(!mask);
1239. 		if (uarmg && uarmg->cursed) {
1240. 			uarmg->bknown = TRUE;
1241. 		    You("cannot remove your gloves to put on the ring.");
1242. 			return(0);
1243. 		}
1244. 		if (welded(uwep) && bimanual(uwep)) {
1245. 			/* welded will set bknown */
1246. 	    You("cannot free your weapon hands to put on the ring.");
1247. 			return(0);
1248. 		}
1249. 		if (welded(uwep) && mask==RIGHT_RING) {
1250. 			/* welded will set bknown */
1251. 	    You("cannot free your weapon hand to put on the ring.");
1252. 			return(0);
1253. 		}
1254. 		setworn(otmp, mask);
1255. 		Ring_on(otmp);
1256. 	} else if (otmp->oclass == AMULET_CLASS) {
1257. 		if(uamul) {
1258. 			already_wearing("an amulet");
1259. 			return(0);
1260. 		}
1261. 		setworn(otmp, W_AMUL);
1262. 		if (otmp->otyp == AMULET_OF_CHANGE) {
1263. 			Amulet_on();
1264. 			/* Don't do a prinv() since the amulet is now gone */
1265. 			return(1);
1266. 		}
1267. 		Amulet_on();
1268. 	} else {	/* it's a blindfold */
1269. 		if (ublindf) {
1270. 			if (ublindf->otyp == TOWEL)
1271. 				Your("%s is already covered by a towel.",
1272. 					body_part(FACE));
1273. 			else
1274. 				already_wearing("a blindfold");
1275. 			return(0);
1276. 		}
1277. 		if (otmp->otyp != BLINDFOLD && otmp->otyp != TOWEL) {
1278. 			You_cant("wear that!");
1279. 			return(0);
1280. 		}
1281. 		Blindf_on(otmp);
1282. 		return(1);
1283. 	}
1284. 	prinv((char *)0, otmp, 0L);
1285. 	return(1);
1286. }
1287. 
1288. #endif /* OVLB */
1289. 
1290. #ifdef OVL0
1291. 
1292. void
1293. find_ac()
1294. {
1295. 	register int uac = 10;
1296. 	if (u.mtimedone) uac = mons[u.umonnum].ac;
1297. 	if(uarm) uac -= ARM_BONUS(uarm);
1298. 	if(uarmc) uac -= ARM_BONUS(uarmc);
1299. 	if(uarmh) uac -= ARM_BONUS(uarmh);
1300. 	if(uarmf) uac -= ARM_BONUS(uarmf);
1301. 	if(uarms) uac -= ARM_BONUS(uarms);
1302. 	if(uarmg) uac -= ARM_BONUS(uarmg);
1303. #ifdef TOURIST
1304. 	if(uarmu) uac -= ARM_BONUS(uarmu);
1305. #endif
1306. 	if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe;
1307. 	if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe;
1308. 	if (Protection & INTRINSIC) uac -= u.ublessed;
1309. 	if(uac != u.uac){
1310. 		u.uac = uac;
1311. 		flags.botl = 1;
1312. 	}
1313. }
1314. 
1315. #endif /* OVL0 */
1316. #ifdef OVLB
1317. 
1318. void
1319. glibr()
1320. {
1321. 	register struct obj *otmp;
1322. 	int xfl = 0;
1323. 	boolean leftfall, rightfall;
1324. 
1325. 	leftfall = (uleft && !uleft->cursed &&
1326. 		    (!uwep || !welded(uwep) || !bimanual(uwep)));
1327. 	rightfall = (uright && !uright->cursed && (!welded(uwep)));
1328. 	if (!uarmg && (leftfall || rightfall) && !nolimbs(uasmon)) {
1329. 		/* changed so cursed rings don't fall off, GAN 10/30/86 */
1330. 		Your("%s off your %s.",
1331. 			(leftfall && rightfall) ? "rings slip" : "ring slips",
1332. 			makeplural(body_part(FINGER)));
1333. 		xfl++;
1334. 		if (leftfall) {
1335. 			otmp = uleft;
1336. 			Ring_off(uleft);
1337. 			dropx(otmp);
1338. 		}
1339. 		if (rightfall) {
1340. 			otmp = uright;
1341. 			Ring_off(uright);
1342. 			dropx(otmp);
1343. 		}
1344. 	}
1345. 	otmp = uwep;
1346. 	if (otmp && !welded(otmp)) {
1347. 		/* changed so cursed weapons don't fall, GAN 10/30/86 */
1348. 		Your("%s %sslips from your %s.",
1349. 			is_sword(otmp) ? c_sword :
1350. 				makesingular(oclass_names[(int)otmp->oclass]),
1351. 			xfl ? "also " : "",
1352. 			makeplural(body_part(HAND)));
1353. 		setuwep((struct obj *)0);
1354. 		if (otmp->otyp != LOADSTONE || !otmp->cursed)
1355. 			dropx(otmp);
1356. 	}
1357. }
1358. 
1359. struct obj *
1360. some_armor()
1361. {
1362. 	register struct obj *otmph = (uarmc ? uarmc : uarm);
1363. 	if(uarmh && (!otmph || !rn2(4))) otmph = uarmh;
1364. 	if(uarmg && (!otmph || !rn2(4))) otmph = uarmg;
1365. 	if(uarmf && (!otmph || !rn2(4))) otmph = uarmf;
1366. 	if(uarms && (!otmph || !rn2(4))) otmph = uarms;
1367. #ifdef TOURIST
1368. 	if(!uarm && !uarmc && uarmu && (!otmph || !rn2(4))) otmph = uarmu;
1369. #endif
1370. 	return(otmph);
1371. }
1372. 
1373. void
1374. erode_armor(acid_dmg)
1375. boolean acid_dmg;
1376. {
1377. 	register struct obj *otmph = some_armor();
1378. 
1379. 	if (otmph && otmph != uarmf) {
1380. 	    if (otmph->greased) {
1381. 		grease_protect(otmph,(char *)0,FALSE);
1382. 		return;
1383. 	    }
1384. 	    if (otmph->oerodeproof ||
1385. 		(acid_dmg ? !is_corrodeable(otmph) : !is_rustprone(otmph))) {
1386. 		if (flags.verbose || !(otmph->oerodeproof && otmph->rknown))
1387. 			Your("%s not affected.", aobjnam(otmph, "are"));
1388. 		if (otmph->oerodeproof) otmph->rknown = TRUE;
1389. 		return;
1390. 	    }
1391. 	    if (otmph->oeroded < MAX_ERODE) {
1392. 		Your("%s%s!", aobjnam(otmph, acid_dmg ? "corrode" : "rust"),
1393. 			otmph->oeroded+1 == MAX_ERODE ? " completely" :
1394. 			otmph->oeroded ? " further" : "");
1395. 		otmph->oeroded++;
1396. 		return;
1397. 	    }
1398. 	    if (flags.verbose)
1399. 		Your("%s completely %s.",
1400. 		     aobjnam(otmph, Blind ? "feel" : "look"),
1401. 		     acid_dmg ? "corroded" : "rusty");
1402. 	}
1403. }
1404. 
1405. STATIC_PTR
1406. int
1407. select_off(otmp)
1408. register struct obj *otmp;
1409. {
1410. 	if(!otmp) return(0);
1411. 	if(cursed(otmp)) return(0);
1412. 	if(otmp->oclass==RING_CLASS && nolimbs(uasmon)) return(0);
1413. 	if(welded(uwep) && (otmp==uarmg || otmp==uright || (otmp==uleft
1414. 			&& bimanual(uwep))))
1415. 		return(0);
1416. 	if(uarmg && uarmg->cursed && (otmp==uright || otmp==uleft)) {
1417. 		uarmg->bknown = TRUE;
1418. 		return(0);
1419. 	}
1420. 	if(otmp == uarmf && u.utrap && (u.utraptype == TT_BEARTRAP ||
1421. 					u.utraptype == TT_INFLOOR)) {
1422. 		return (0);
1423. 	}
1424. 	if((otmp==uarm
1425. #ifdef TOURIST
1426. 			|| otmp==uarmu
1427. #endif
1428. 					) && uarmc && uarmc->cursed) {
1429. 		uarmc->bknown = TRUE;
1430. 		return(0);
1431. 	}
1432. #ifdef TOURIST
1433. 	if(otmp==uarmu && uarm && uarm->cursed) {
1434. 		uarm->bknown = TRUE;
1435. 		return(0);
1436. 	}
1437. #endif
1438. 
1439. 	if(otmp == uarm) takeoff_mask |= WORN_ARMOR;
1440. 	else if(otmp == uarmc) takeoff_mask |= WORN_CLOAK;
1441. 	else if(otmp == uarmf) takeoff_mask |= WORN_BOOTS;
1442. 	else if(otmp == uarmg) takeoff_mask |= WORN_GLOVES;
1443. 	else if(otmp == uarmh) takeoff_mask |= WORN_HELMET;
1444. 	else if(otmp == uarms) takeoff_mask |= WORN_SHIELD;
1445. #ifdef TOURIST
1446. 	else if(otmp == uarmu) takeoff_mask |= WORN_SHIRT;
1447. #endif
1448. 	else if(otmp == uleft) takeoff_mask |= LEFT_RING;
1449. 	else if(otmp == uright) takeoff_mask |= RIGHT_RING;
1450. 	else if(otmp == uamul) takeoff_mask |= WORN_AMUL;
1451. 	else if(otmp == ublindf) takeoff_mask |= WORN_BLINDF;
1452. 	else if(otmp == uwep) takeoff_mask |= 1L;	/* WIELDED_WEAPON */
1453. 
1454. 	else impossible("select_off: %s???", doname(otmp));
1455. 
1456. 	return(0);
1457. }
1458. 
1459. static struct obj *
1460. do_takeoff()
1461. {
1462. 	register struct obj *otmp = (struct obj *)0;
1463. 
1464. 	if (taking_off == 1L) { /* weapon */
1465. 	  if(!cursed(uwep)) {
1466. 	    setuwep((struct obj *) 0);
1467. 	    You("are empty %s.", body_part(HANDED));
1468. 	  }
1469. 	} else if (taking_off ==  WORN_ARMOR) {
1470. 	  otmp = uarm;
1471. 	  if(!cursed(otmp)) (void) Armor_off();
1472. 	} else if (taking_off == WORN_CLOAK) {
1473. 	  otmp = uarmc;
1474. 	  if(!cursed(otmp)) (void) Cloak_off();
1475. 	} else if (taking_off == WORN_BOOTS) {
1476. 	  otmp = uarmf;
1477. 	  if(!cursed(otmp)) (void) Boots_off();
1478. 	} else if (taking_off == WORN_GLOVES) {
1479. 	  otmp = uarmg;
1480. 	  if(!cursed(otmp)) (void) Gloves_off();
1481. 	} else if (taking_off == WORN_HELMET) {
1482. 	  otmp = uarmh;
1483. 	  if(!cursed(otmp)) (void) Helmet_off();
1484. 	} else if (taking_off == WORN_SHIELD) {
1485. 	  otmp = uarms;
1486. 	  if(!cursed(otmp)) (void) Shield_off();
1487. #ifdef TOURIST
1488. 	} else if (taking_off == WORN_SHIRT) {
1489. 	  otmp = uarmu;
1490. 	  if(!cursed(otmp))
1491. 	    setworn((struct obj *)0, uarmu->owornmask & W_ARMOR);
1492. #endif
1493. 	} else if (taking_off == WORN_AMUL) {
1494. 	  otmp = uamul;
1495. 	  if(!cursed(otmp)) Amulet_off();
1496. 	} else if (taking_off == LEFT_RING) {
1497. 	  otmp = uleft;
1498. 	  if(!cursed(otmp)) Ring_off(uleft);
1499. 	} else if (taking_off == RIGHT_RING) {
1500. 	  otmp = uright;
1501. 	  if(!cursed(otmp)) Ring_off(uright);
1502. 	} else if (taking_off == WORN_BLINDF) {
1503. 	  if(!cursed(ublindf)) {
1504. 	    setworn((struct obj *)0, ublindf->owornmask);
1505. 	    if(!Blinded) make_blinded(1L,FALSE); /* See on next move */
1506. 	    else	 You("still cannot see.");
1507. 	  }
1508. 	} else impossible("do_takeoff: taking off %lx", taking_off);
1509. 
1510. 	return(otmp);
1511. }
1512. 
1513. STATIC_PTR
1514. int
1515. take_off()
1516. {
1517. 	register int i;
1518. 	register struct obj *otmp;
1519. 
1520. 	if(taking_off) {
1521. 	    if(todelay > 0) {
1522. 
1523. 		todelay--;
1524. 		return(1);	/* still busy */
1525. 	    } else if((otmp = do_takeoff())) off_msg(otmp);
1526. 
1527. 	    takeoff_mask &= ~taking_off;
1528. 	    taking_off = 0L;
1529. 	}
1530. 
1531. 	for(i = 0; takeoff_order[i]; i++)
1532. 	    if(takeoff_mask & takeoff_order[i]) {
1533. 		taking_off = takeoff_order[i];
1534. 		break;
1535. 	    }
1536. 
1537. 	otmp = (struct obj *) 0;
1538. 	todelay = 0;
1539. 
1540. 	if (taking_off == 0L) {
1541. 	  You("finish disrobing.");
1542. 	  return 0;
1543. 	} else if (taking_off == 1L) {
1544. 	  todelay = 1;
1545. 	} else if (taking_off == WORN_ARMOR) {
1546. 	  otmp = uarm;
1547. 	  /* If a cloak is being worn, add the time to take it off and put
1548. 	   * it back on again.  Kludge alert! since that time is 0 for all
1549. 	   * known cloaks, add 1 so that it actually matters...
1550. 	   */
1551. 	  if (uarmc) todelay += 2 * objects[uarmc->otyp].oc_delay + 1;
1552. 	} else if (taking_off == WORN_CLOAK) {
1553. 	  otmp = uarmc;
1554. 	} else if (taking_off == WORN_BOOTS) {
1555. 	  otmp = uarmf;
1556. 	} else if (taking_off == WORN_GLOVES) {
1557. 	  otmp = uarmg;
1558. 	} else if (taking_off == WORN_HELMET) {
1559. 	  otmp = uarmh;
1560. 	} else if (taking_off == WORN_SHIELD) {
1561. 	  otmp = uarms;
1562. #ifdef TOURIST
1563. 	} else if (taking_off == WORN_SHIRT) {
1564. 	  otmp = uarmu;
1565. 	  /* add the time to take off and put back on armor and/or cloak */
1566. 	  if (uarm)  todelay += 2 * objects[uarm->otyp].oc_delay;
1567. 	  if (uarmc) todelay += 2 * objects[uarmc->otyp].oc_delay + 1;
1568. #endif
1569. 	} else if (taking_off == WORN_AMUL) {
1570. 	  todelay = 1;
1571. 	} else if (taking_off == LEFT_RING) {
1572. 	  todelay = 1;
1573. 	} else if (taking_off == RIGHT_RING) {
1574. 	  todelay = 1;
1575. 	} else if (taking_off == WORN_BLINDF) {
1576. 	  todelay = 2;
1577. 	} else {
1578. 	  impossible("take_off: taking off %lx", taking_off);
1579. 	  return 0;	/* force done */
1580. 	}
1581. 
1582. 	if (otmp) todelay += objects[otmp->otyp].oc_delay;
1583. 	set_occupation(take_off, "disrobing", 0);
1584. 	return(1);		/* get busy */
1585. }
1586. 
1587. #endif /* OVLB */
1588. #ifdef OVL1
1589. 
1590. void
1591. reset_remarm()
1592. {
1593. 	taking_off = takeoff_mask =0L;
1594. }
1595. 
1596. #endif /* OVL1 */
1597. #ifdef OVLB
1598. 
1599. int
1600. doddoremarm()
1601. {
1602.     int result = 0;
1603. 
1604.     if (taking_off || takeoff_mask) {
1605. 	You("continue disrobing.");
1606. 	set_occupation(take_off, "disrobing", 0);
1607. 	return(take_off());
1608.     } else if (!uwep && !uamul && !ublindf &&
1609. 		!uleft && !uright && !wearing_armor()) {
1610. 	You("are not wearing anything.");
1611. 	return 0;
1612.     }
1613. 
1614.     add_valid_menu_class(0); /* reset */
1615.     if (flags.menu_style != MENU_TRADITIONAL ||
1616. 	    (result = ggetobj("take off", select_off, 0, FALSE)) < -1)
1617. 	result = menu_remarm(result);
1618. 
1619.     return takeoff_mask ? take_off() : 0;
1620. }
1621. 
1622. static int
1623. menu_remarm(retry)
1624. int retry;
1625. {
1626.     int n, i = 0;
1627.     menu_item *pick_list;
1628.     boolean all_worn_categories = TRUE;
1629. 
1630.     if (retry) {
1631. 	all_worn_categories = (retry == -2);
1632.     } else if (flags.menu_style == MENU_FULL) {
1633. 	all_worn_categories = FALSE;
1634. 	n = query_category("What type of things do you want to take off?",
1635. 			   invent, WORN_TYPES|ALL_TYPES, &pick_list, PICK_ANY);
1636. 	if (!n) return 0;
1637. 	for (i = 0; i < n; i++) {
1638. 	    if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
1639. 		all_worn_categories = TRUE;
1640. 	    else
1641. 		add_valid_menu_class(pick_list[i].item.a_int);
1642. 	}
1643. 	free((genericptr_t) pick_list);
1644.     } else if (flags.menu_style == MENU_COMBINATION) {
1645. 	all_worn_categories = FALSE;
1646. 	if (ggetobj("take off", select_off, 0, TRUE) == -2)
1647. 	    all_worn_categories = TRUE;
1648.     }
1649. 
1650.     n = query_objlist("What do you want to take off?", invent,
1651. 			SIGNAL_NOMENU|USE_INVLET|INVORDER_SORT,
1652. 			&pick_list, PICK_ANY,
1653. 			all_worn_categories ? is_worn : is_worn_by_type);
1654.     if (n > 0) {
1655. 	for (i = 0; i < n; i++)
1656. 	    (void) select_off(pick_list[i].item.a_obj);
1657. 	free((genericptr_t) pick_list);
1658.     } else if (n < 0) {
1659. 	pline("There is nothing else you can remove or unwield.");
1660.     }
1661.     return 0;
1662. }
1663. 
1664. int
1665. destroy_arm(atmp)
1666. register struct obj *atmp;
1667. {
1668. 	register struct obj *otmp;
1669. #define DESTROY_ARM(o) ((otmp = (o)) != 0 && \
1670. 			(!atmp || atmp == otmp) && \
1671. 			(!obj_resists(otmp, 0, 90)))
1672. 
1673. 	if (DESTROY_ARM(uarmc)) {
1674. 		Your("cloak crumbles and turns to dust!");
1675. 		(void) Cloak_off();
1676. 		useup(otmp);
1677. 	} else if (DESTROY_ARM(uarm)) {
1678. 		/* may be disintegrated by spell or dragon breath... */
1679. 		if (donning(otmp)) cancel_don();
1680. 		Your("armor turns to dust and falls to the %s!",
1681. 			surface(u.ux,u.uy));
1682. 		(void) Armor_gone();
1683. 		useup(otmp);
1684. #ifdef TOURIST
1685. 	} else if (DESTROY_ARM(uarmu)) {
1686. 		Your("shirt crumbles into tiny threads and falls apart!");
1687. 		useup(otmp);
1688. #endif
1689. 	} else if (DESTROY_ARM(uarmh)) {
1690. 		if (donning(otmp)) cancel_don();
1691. 		Your("helmet turns to dust and is blown away!");
1692. 		(void) Helmet_off();
1693. 		useup(otmp);
1694. 	} else if (DESTROY_ARM(uarmg)) {
1695. 		if (donning(otmp)) cancel_don();
1696. 		Your("gloves vanish!");
1697. 		(void) Gloves_off();
1698. 		useup(otmp);
1699. 		selftouch("You");
1700. 	} else if (DESTROY_ARM(uarmf)) {
1701. 		if (donning(otmp)) cancel_don();
1702. 		Your("boots disintegrate!");
1703. 		(void) Boots_off();
1704. 		useup(otmp);
1705. 	} else if (DESTROY_ARM(uarms)) {
1706. 		Your("shield crumbles away!");
1707. 		(void) Shield_off();
1708. 		useup(otmp);
1709. 	} else	return(0);		/* could not destroy anything */
1710. 
1711. #undef DESTROY_ARM
1712. 	return(1);
1713. }
1714. 
1715. void
1716. adj_abon(otmp, delta)
1717. register struct obj *otmp;
1718. register schar delta;
1719. {
1720. 	if (uarmg && otmp->otyp == GAUNTLETS_OF_DEXTERITY) {
1721. 		ABON(A_DEX) += (delta);
1722. 		flags.botl = 1;
1723. 	}
1724. 	if (uarmh && otmp->otyp == HELM_OF_BRILLIANCE) {
1725. 		ABON(A_INT) += (delta);
1726. 		ABON(A_WIS) += (delta);
1727. 		flags.botl = 1;
1728. 	}
1729. }
1730. 
1731. #endif /* OVLB */
1732. 
1733. /*do_wear.c*/