Source:NetHack 3.6.4/src/do wear.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to do_wear.c from the source code of NetHack 3.6.4. To link to a particular line, write [[Source:NetHack 3.6.4/src/do_wear.c#line12]], for example.

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. /* NetHack 3.6	do_wear.c	$NHDT-Date: 1575214670 2019/12/01 15:37:50 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.116 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2012. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. 
8. static NEARDATA const char see_yourself[] = "see yourself";
9. static NEARDATA const char unknown_type[] = "Unknown type of %s (%d)";
10. static NEARDATA const char c_armor[] = "armor", c_suit[] = "suit",
11.                            c_shirt[] = "shirt", c_cloak[] = "cloak",
12.                            c_gloves[] = "gloves", c_boots[] = "boots",
13.                            c_helmet[] = "helmet", c_shield[] = "shield",
14.                            c_weapon[] = "weapon", c_sword[] = "sword",
15.                            c_axe[] = "axe", c_that_[] = "that";
16. 
17. static NEARDATA const long takeoff_order[] = {
18.     WORN_BLINDF, W_WEP,      WORN_SHIELD, WORN_GLOVES, LEFT_RING,
19.     RIGHT_RING,  WORN_CLOAK, WORN_HELMET, WORN_AMUL,   WORN_ARMOR,
20.     WORN_SHIRT,  WORN_BOOTS, W_SWAPWEP,   W_QUIVER,    0L
21. };
22. 
23. STATIC_DCL void FDECL(on_msg, (struct obj *));
24. STATIC_DCL void FDECL(toggle_stealth, (struct obj *, long, BOOLEAN_P));
25. STATIC_DCL void FDECL(toggle_displacement, (struct obj *, long, BOOLEAN_P));
26. STATIC_PTR int NDECL(Armor_on);
27. /* int NDECL(Boots_on); -- moved to extern.h */
28. STATIC_PTR int NDECL(Cloak_on);
29. STATIC_PTR int NDECL(Helmet_on);
30. STATIC_PTR int NDECL(Gloves_on);
31. STATIC_DCL void FDECL(wielding_corpse, (struct obj *, BOOLEAN_P));
32. STATIC_PTR int NDECL(Shield_on);
33. STATIC_PTR int NDECL(Shirt_on);
34. STATIC_DCL void NDECL(Amulet_on);
35. STATIC_DCL void FDECL(learnring, (struct obj *, BOOLEAN_P));
36. STATIC_DCL void FDECL(Ring_off_or_gone, (struct obj *, BOOLEAN_P));
37. STATIC_PTR int FDECL(select_off, (struct obj *));
38. STATIC_DCL struct obj *NDECL(do_takeoff);
39. STATIC_PTR int NDECL(take_off);
40. STATIC_DCL int FDECL(menu_remarm, (int));
41. STATIC_DCL void FDECL(count_worn_stuff, (struct obj **, BOOLEAN_P));
42. STATIC_PTR int FDECL(armor_or_accessory_off, (struct obj *));
43. STATIC_PTR int FDECL(accessory_or_armor_on, (struct obj *));
44. STATIC_DCL void FDECL(already_wearing, (const char *));
45. STATIC_DCL void FDECL(already_wearing2, (const char *, const char *));
46. 
47. /* plural "fingers" or optionally "gloves" */
48. const char *
49. fingers_or_gloves(check_gloves)
50. boolean check_gloves;
51. {
52.     return ((check_gloves && uarmg)
53.             ? gloves_simple_name(uarmg) /* "gloves" or "gauntlets" */
54.             : makeplural(body_part(FINGER))); /* "fingers" */
55. }
56. 
57. void
58. off_msg(otmp)
59. struct obj *otmp;
60. {
61.     if (flags.verbose)
62.         You("were wearing %s.", doname(otmp));
63. }
64. 
65. /* for items that involve no delay */
66. STATIC_OVL void
67. on_msg(otmp)
68. struct obj *otmp;
69. {
70.     if (flags.verbose) {
71.         char how[BUFSZ];
72.         /* call xname() before obj_is_pname(); formatting obj's name
73.            might set obj->dknown and that affects the pname test */
74.         const char *otmp_name = xname(otmp);
75. 
76.         how[0] = '\0';
77.         if (otmp->otyp == TOWEL)
78.             Sprintf(how, " around your %s", body_part(HEAD));
79.         You("are now wearing %s%s.",
80.             obj_is_pname(otmp) ? the(otmp_name) : an(otmp_name), how);
81.     }
82. }
83. 
84. /* starting equipment gets auto-worn at beginning of new game,
85.    and we don't want stealth or displacement feedback then */
86. static boolean initial_don = FALSE; /* manipulated in set_wear() */
87. 
88. /* putting on or taking off an item which confers stealth;
89.    give feedback and discover it iff stealth state is changing */
90. STATIC_OVL
91. void
92. toggle_stealth(obj, oldprop, on)
93. struct obj *obj;
94. long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */
95. boolean on;
96. {
97.     if (on ? initial_don : context.takeoff.cancelled_don)
98.         return;
99. 
100.     if (!oldprop /* extrinsic stealth from something else */
101.         && !HStealth /* intrinsic stealth */
102.         && !BStealth) { /* stealth blocked by something */
103.         if (obj->otyp == RIN_STEALTH)
104.             learnring(obj, TRUE);
105.         else
106.             makeknown(obj->otyp);
107. 
108.         if (on) {
109.             if (!is_boots(obj))
110.                 You("move very quietly.");
111.             else if (Levitation || Flying)
112.                 You("float imperceptibly.");
113.             else
114.                 You("walk very quietly.");
115.         } else {
116.             You("sure are noisy.");
117.         }
118.     }
119. }
120. 
121. /* putting on or taking off an item which confers displacement;
122.    give feedback and discover it iff displacement state is changing *and*
123.    hero is able to see self (or sense monsters) */
124. STATIC_OVL
125. void
126. toggle_displacement(obj, oldprop, on)
127. struct obj *obj;
128. long oldprop; /* prop[].extrinsic, with obj->owornmask stripped by caller */
129. boolean on;
130. {
131.     if (on ? initial_don : context.takeoff.cancelled_don)
132.         return;
133. 
134.     if (!oldprop /* extrinsic displacement from something else */
135.         && !(u.uprops[DISPLACED].intrinsic) /* (theoretical) */
136.         && !(u.uprops[DISPLACED].blocked) /* (also theoretical) */
137.         /* we don't use canseeself() here because it augments vision
138.            with touch, which isn't appropriate for deciding whether
139.            we'll notice that monsters have trouble spotting the hero */
140.         && ((!Blind         /* see anything */
141.              && !u.uswallow /* see surroundings */
142.              && !Invisible) /* see self */
143.             /* actively sensing nearby monsters via telepathy or extended
144.                monster detection overrides vision considerations because
145.                hero also senses self in this situation */
146.             || (Unblind_telepat
147.                 || (Blind_telepat && Blind)
148.                 || Detect_monsters))) {
149.         makeknown(obj->otyp);
150. 
151.         You_feel("that monsters%s have difficulty pinpointing your location.",
152.                  on ? "" : " no longer");
153.     }
154. }
155. 
156. /*
157.  * The Type_on() functions should be called *after* setworn().
158.  * The Type_off() functions call setworn() themselves.
159.  * [Blindf_on() is an exception and calls setworn() itself.]
160.  */
161. 
162. int
163. Boots_on(VOID_ARGS)
164. {
165.     long oldprop =
166.         u.uprops[objects[uarmf->otyp].oc_oprop].extrinsic & ~WORN_BOOTS;
167. 
168.     switch (uarmf->otyp) {
169.     case LOW_BOOTS:
170.     case IRON_SHOES:
171.     case HIGH_BOOTS:
172.     case JUMPING_BOOTS:
173.     case KICKING_BOOTS:
174.         break;
175.     case WATER_WALKING_BOOTS:
176.         if (u.uinwater)
177.             spoteffects(TRUE);
178.         /* (we don't need a lava check here since boots can't be
179.            put on while feet are stuck) */
180.         break;
181.     case SPEED_BOOTS:
182.         /* Speed boots are still better than intrinsic speed, */
183.         /* though not better than potion speed */
184.         if (!oldprop && !(HFast & TIMEOUT)) {
185.             makeknown(uarmf->otyp);
186.             You_feel("yourself speed up%s.",
187.                      (oldprop || HFast) ? " a bit more" : "");
188.         }
189.         break;
190.     case ELVEN_BOOTS:
191.         toggle_stealth(uarmf, oldprop, TRUE);
192.         break;
193.     case FUMBLE_BOOTS:
194.         if (!oldprop && !(HFumbling & ~TIMEOUT))
195.             incr_itimeout(&HFumbling, rnd(20));
196.         break;
197.     case LEVITATION_BOOTS:
198.         if (!oldprop && !HLevitation && !(BLevitation & FROMOUTSIDE)) {
199.             uarmf->known = 1; /* might come off if putting on over a sink,
200.                                * so uarmf could be Null below; status line
201.                                * gets updated during brief interval they're
202.                                * worn so hero and player learn enchantment */
203.             context.botl = 1; /* status hilites might mark AC changed */
204.             makeknown(uarmf->otyp);
205.             float_up();
206.             if (Levitation)
207.                 spoteffects(FALSE); /* for sink effect */
208.         } else {
209.             float_vs_flight(); /* maybe toggle BFlying's I_SPECIAL */
210.         }
211.         break;
212.     default:
213.         impossible(unknown_type, c_boots, uarmf->otyp);
214.     }
215.     if (uarmf) /* could be Null here (levitation boots put on over a sink) */
216.         uarmf->known = 1; /* boots' +/- evident because of status line AC */
217.     return 0;
218. }
219. 
220. int
221. Boots_off(VOID_ARGS)
222. {
223.     struct obj *otmp = uarmf;
224.     int otyp = otmp->otyp;
225.     long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_BOOTS;
226. 
227.     context.takeoff.mask &= ~W_ARMF;
228.     /* For levitation, float_down() returns if Levitation, so we
229.      * must do a setworn() _before_ the levitation case.
230.      */
231.     setworn((struct obj *) 0, W_ARMF);
232.     switch (otyp) {
233.     case SPEED_BOOTS:
234.         if (!Very_fast && !context.takeoff.cancelled_don) {
235.             makeknown(otyp);
236.             You_feel("yourself slow down%s.", Fast ? " a bit" : "");
237.         }
238.         break;
239.     case WATER_WALKING_BOOTS:
240.         /* check for lava since fireproofed boots make it viable */
241.         if ((is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy))
242.             && !Levitation && !Flying && !is_clinger(youmonst.data)
243.             && !context.takeoff.cancelled_don
244.             /* avoid recursive call to lava_effects() */
245.             && !iflags.in_lava_effects) {
246.             /* make boots known in case you survive the drowning */
247.             makeknown(otyp);
248.             spoteffects(TRUE);
249.         }
250.         break;
251.     case ELVEN_BOOTS:
252.         toggle_stealth(otmp, oldprop, FALSE);
253.         break;
254.     case FUMBLE_BOOTS:
255.         if (!oldprop && !(HFumbling & ~TIMEOUT))
256.             HFumbling = EFumbling = 0;
257.         break;
258.     case LEVITATION_BOOTS:
259.         if (!oldprop && !HLevitation && !(BLevitation & FROMOUTSIDE)
260.             && !context.takeoff.cancelled_don) {
261.             (void) float_down(0L, 0L);
262.             makeknown(otyp);
263.         } else {
264.             float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
265.         }
266.         break;
267.     case LOW_BOOTS:
268.     case IRON_SHOES:
269.     case HIGH_BOOTS:
270.     case JUMPING_BOOTS:
271.     case KICKING_BOOTS:
272.         break;
273.     default:
274.         impossible(unknown_type, c_boots, otyp);
275.     }
276.     context.takeoff.cancelled_don = FALSE;
277.     return 0;
278. }
279. 
280. STATIC_PTR int
281. Cloak_on(VOID_ARGS)
282. {
283.     long oldprop =
284.         u.uprops[objects[uarmc->otyp].oc_oprop].extrinsic & ~WORN_CLOAK;
285. 
286.     switch (uarmc->otyp) {
287.     case ORCISH_CLOAK:
288.     case DWARVISH_CLOAK:
289.     case CLOAK_OF_MAGIC_RESISTANCE:
290.     case ROBE:
291.     case LEATHER_CLOAK:
292.         break;
293.     case CLOAK_OF_PROTECTION:
294.         makeknown(uarmc->otyp);
295.         break;
296.     case ELVEN_CLOAK:
297.         toggle_stealth(uarmc, oldprop, TRUE);
298.         break;
299.     case CLOAK_OF_DISPLACEMENT:
300.         toggle_displacement(uarmc, oldprop, TRUE);
301.         break;
302.     case MUMMY_WRAPPING:
303.         /* Note: it's already being worn, so we have to cheat here. */
304.         if ((HInvis || EInvis) && !Blind) {
305.             newsym(u.ux, u.uy);
306.             You("can %s!", See_invisible ? "no longer see through yourself"
307.                                          : see_yourself);
308.         }
309.         break;
310.     case CLOAK_OF_INVISIBILITY:
311.         /* since cloak of invisibility was worn, we know mummy wrapping
312.            wasn't, so no need to check `oldprop' against blocked */
313.         if (!oldprop && !HInvis && !Blind) {
314.             makeknown(uarmc->otyp);
315.             newsym(u.ux, u.uy);
316.             pline("Suddenly you can%s yourself.",
317.                   See_invisible ? " see through" : "not see");
318.         }
319.         break;
320.     case OILSKIN_CLOAK:
321.         pline("%s very tightly.", Tobjnam(uarmc, "fit"));
322.         break;
323.     /* Alchemy smock gives poison _and_ acid resistance */
324.     case ALCHEMY_SMOCK:
325.         EAcid_resistance |= WORN_CLOAK;
326.         break;
327.     default:
328.         impossible(unknown_type, c_cloak, uarmc->otyp);
329.     }
330.     if (uarmc) /* no known instance of !uarmc here but play it safe */
331.         uarmc->known = 1; /* cloak's +/- evident because of status line AC */
332.     return 0;
333. }
334. 
335. int
336. Cloak_off(VOID_ARGS)
337. {
338.     struct obj *otmp = uarmc;
339.     int otyp = otmp->otyp;
340.     long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_CLOAK;
341. 
342.     context.takeoff.mask &= ~W_ARMC;
343.     /* For mummy wrapping, taking it off first resets `Invisible'. */
344.     setworn((struct obj *) 0, W_ARMC);
345.     switch (otyp) {
346.     case ORCISH_CLOAK:
347.     case DWARVISH_CLOAK:
348.     case CLOAK_OF_PROTECTION:
349.     case CLOAK_OF_MAGIC_RESISTANCE:
350.     case OILSKIN_CLOAK:
351.     case ROBE:
352.     case LEATHER_CLOAK:
353.         break;
354.     case ELVEN_CLOAK:
355.         toggle_stealth(otmp, oldprop, FALSE);
356.         break;
357.     case CLOAK_OF_DISPLACEMENT:
358.         toggle_displacement(otmp, oldprop, FALSE);
359.         break;
360.     case MUMMY_WRAPPING:
361.         if (Invis && !Blind) {
362.             newsym(u.ux, u.uy);
363.             You("can %s.", See_invisible ? "see through yourself"
364.                                          : "no longer see yourself");
365.         }
366.         break;
367.     case CLOAK_OF_INVISIBILITY:
368.         if (!oldprop && !HInvis && !Blind) {
369.             makeknown(CLOAK_OF_INVISIBILITY);
370.             newsym(u.ux, u.uy);
371.             pline("Suddenly you can %s.",
372.                   See_invisible ? "no longer see through yourself"
373.                                 : see_yourself);
374.         }
375.         break;
376.     /* Alchemy smock gives poison _and_ acid resistance */
377.     case ALCHEMY_SMOCK:
378.         EAcid_resistance &= ~WORN_CLOAK;
379.         break;
380.     default:
381.         impossible(unknown_type, c_cloak, otyp);
382.     }
383.     return 0;
384. }
385. 
386. STATIC_PTR
387. int
388. Helmet_on(VOID_ARGS)
389. {
390.     switch (uarmh->otyp) {
391.     case FEDORA:
392.     case HELMET:
393.     case DENTED_POT:
394.     case ELVEN_LEATHER_HELM:
395.     case DWARVISH_IRON_HELM:
396.     case ORCISH_HELM:
397.     case HELM_OF_TELEPATHY:
398.         break;
399.     case HELM_OF_BRILLIANCE:
400.         adj_abon(uarmh, uarmh->spe);
401.         break;
402.     case CORNUTHAUM:
403.         /* people think marked wizards know what they're talking about,
404.            but it takes trained arrogance to pull it off, and the actual
405.            enchantment of the hat is irrelevant */
406.         ABON(A_CHA) += (Role_if(PM_WIZARD) ? 1 : -1);
407.         context.botl = 1;
408.         makeknown(uarmh->otyp);
409.         break;
410.     case HELM_OF_OPPOSITE_ALIGNMENT:
411.         uarmh->known = 1; /* do this here because uarmh could get cleared */
412.         /* changing alignment can toggle off active artifact properties,
413.            including levitation; uarmh could get dropped or destroyed here
414.            by hero falling onto a polymorph trap or into water (emergency
415.            disrobe) or maybe lava (probably not, helm isn't 'organic') */
416.         uchangealign((u.ualign.type != A_NEUTRAL)
417.                          ? -u.ualign.type
418.                          : (uarmh->o_id % 2) ? A_CHAOTIC : A_LAWFUL,
419.                      1);
420.         /* makeknown(HELM_OF_OPPOSITE_ALIGNMENT); -- below, after Tobjnam() */
421.     /*FALLTHRU*/
422.     case DUNCE_CAP:
423.         if (uarmh && !uarmh->cursed) {
424.             if (Blind)
425.                 pline("%s for a moment.", Tobjnam(uarmh, "vibrate"));
426.             else
427.                 pline("%s %s for a moment.", Tobjnam(uarmh, "glow"),
428.                       hcolor(NH_BLACK));
429.             curse(uarmh);
430.         }
431.         context.botl = 1; /* reveal new alignment or INT & WIS */
432.         if (Hallucination) {
433.             pline("My brain hurts!"); /* Monty Python's Flying Circus */
434.         } else if (uarmh && uarmh->otyp == DUNCE_CAP) {
435.             You_feel("%s.", /* track INT change; ignore WIS */
436.                      ACURR(A_INT)
437.                              <= (ABASE(A_INT) + ABON(A_INT) + ATEMP(A_INT))
438.                          ? "like sitting in a corner"
439.                          : "giddy");
440.         } else {
441.             /* [message formerly given here moved to uchangealign()] */
442.             makeknown(HELM_OF_OPPOSITE_ALIGNMENT);
443.         }
444.         break;
445.     default:
446.         impossible(unknown_type, c_helmet, uarmh->otyp);
447.     }
448.     /* uarmh could be Null due to uchangealign() */
449.     if (uarmh)
450.         uarmh->known = 1; /* helmet's +/- evident because of status line AC */
451.     return 0;
452. }
453. 
454. int
455. Helmet_off(VOID_ARGS)
456. {
457.     context.takeoff.mask &= ~W_ARMH;
458. 
459.     switch (uarmh->otyp) {
460.     case FEDORA:
461.     case HELMET:
462.     case DENTED_POT:
463.     case ELVEN_LEATHER_HELM:
464.     case DWARVISH_IRON_HELM:
465.     case ORCISH_HELM:
466.         break;
467.     case DUNCE_CAP:
468.         context.botl = 1;
469.         break;
470.     case CORNUTHAUM:
471.         if (!context.takeoff.cancelled_don) {
472.             ABON(A_CHA) += (Role_if(PM_WIZARD) ? -1 : 1);
473.             context.botl = 1;
474.         }
475.         break;
476.     case HELM_OF_TELEPATHY:
477.         /* need to update ability before calling see_monsters() */
478.         setworn((struct obj *) 0, W_ARMH);
479.         see_monsters();
480.         return 0;
481.     case HELM_OF_BRILLIANCE:
482.         if (!context.takeoff.cancelled_don)
483.             adj_abon(uarmh, -uarmh->spe);
484.         break;
485.     case HELM_OF_OPPOSITE_ALIGNMENT:
486.         /* changing alignment can toggle off active artifact
487.            properties, including levitation; uarmh could get
488.            dropped or destroyed here */
489.         uchangealign(u.ualignbase[A_CURRENT], 2);
490.         break;
491.     default:
492.         impossible(unknown_type, c_helmet, uarmh->otyp);
493.     }
494.     setworn((struct obj *) 0, W_ARMH);
495.     context.takeoff.cancelled_don = FALSE;
496.     return 0;
497. }
498. 
499. STATIC_PTR
500. int
501. Gloves_on(VOID_ARGS)
502. {
503.     long oldprop =
504.         u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES;
505. 
506.     switch (uarmg->otyp) {
507.     case LEATHER_GLOVES:
508.         break;
509.     case GAUNTLETS_OF_FUMBLING:
510.         if (!oldprop && !(HFumbling & ~TIMEOUT))
511.             incr_itimeout(&HFumbling, rnd(20));
512.         break;
513.     case GAUNTLETS_OF_POWER:
514.         makeknown(uarmg->otyp);
515.         context.botl = 1; /* taken care of in attrib.c */
516.         break;
517.     case GAUNTLETS_OF_DEXTERITY:
518.         adj_abon(uarmg, uarmg->spe);
519.         break;
520.     default:
521.         impossible(unknown_type, c_gloves, uarmg->otyp);
522.     }
523.     if (uarmg) /* no known instance of !uarmg here but play it safe */
524.         uarmg->known = 1; /* gloves' +/- evident because of status line AC */
525.     return 0;
526. }
527. 
528. STATIC_OVL void
529. wielding_corpse(obj, voluntary)
530. struct obj *obj;
531. boolean voluntary; /* taking gloves off on purpose? */
532. {
533.     char kbuf[BUFSZ];
534. 
535.     if (!obj || obj->otyp != CORPSE)
536.         return;
537.     if (obj != uwep && (obj != uswapwep || !u.twoweap))
538.         return;
539. 
540.     if (touch_petrifies(&mons[obj->corpsenm]) && !Stone_resistance) {
541.         You("now wield %s in your bare %s.",
542.             corpse_xname(obj, (const char *) 0, CXN_ARTICLE),
543.             makeplural(body_part(HAND)));
544.         Sprintf(kbuf, "%s gloves while wielding %s",
545.                 voluntary ? "removing" : "losing", killer_xname(obj));
546.         instapetrify(kbuf);
547.         /* life-saved; can't continue wielding cockatrice corpse though */
548.         remove_worn_item(obj, FALSE);
549.     }
550. }
551. 
552. int
553. Gloves_off(VOID_ARGS)
554. {
555.     long oldprop =
556.         u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES;
557.     boolean on_purpose = !context.mon_moving && !uarmg->in_use;
558. 
559.     context.takeoff.mask &= ~W_ARMG;
560. 
561.     switch (uarmg->otyp) {
562.     case LEATHER_GLOVES:
563.         break;
564.     case GAUNTLETS_OF_FUMBLING:
565.         if (!oldprop && !(HFumbling & ~TIMEOUT))
566.             HFumbling = EFumbling = 0;
567.         break;
568.     case GAUNTLETS_OF_POWER:
569.         makeknown(uarmg->otyp);
570.         context.botl = 1; /* taken care of in attrib.c */
571.         break;
572.     case GAUNTLETS_OF_DEXTERITY:
573.         if (!context.takeoff.cancelled_don)
574.             adj_abon(uarmg, -uarmg->spe);
575.         break;
576.     default:
577.         impossible(unknown_type, c_gloves, uarmg->otyp);
578.     }
579.     setworn((struct obj *) 0, W_ARMG);
580.     context.takeoff.cancelled_don = FALSE;
581.     (void) encumber_msg(); /* immediate feedback for GoP */
582. 
583.     /* usually can't remove gloves when they're slippery but it can
584.        be done by having them fall off (polymorph), stolen, or
585.        destroyed (scroll, overenchantment, monster spell); if that
586.        happens, 'cure' slippery fingers so that it doesn't transfer
587.        from gloves to bare hands */
588.     if (Glib)
589.         make_glib(0); /* for update_inventory() */
590. 
591.     /* prevent wielding cockatrice when not wearing gloves */
592.     if (uwep && uwep->otyp == CORPSE)
593.         wielding_corpse(uwep, on_purpose);
594. 
595.     /* KMH -- ...or your secondary weapon when you're wielding it
596.        [This case can't actually happen; twoweapon mode won't
597.        engage if a corpse has been set up as the alternate weapon.] */
598.     if (u.twoweap && uswapwep && uswapwep->otyp == CORPSE)
599.         wielding_corpse(uswapwep, on_purpose);
600. 
601.     return 0;
602. }
603. 
604. STATIC_PTR int
605. Shield_on(VOID_ARGS)
606. {
607.     /* no shield currently requires special handling when put on, but we
608.        keep this uncommented in case somebody adds a new one which does
609.        [reflection is handled by setting u.uprops[REFLECTION].extrinsic
610.        in setworn() called by armor_or_accessory_on() before Shield_on()] */
611.     switch (uarms->otyp) {
612.     case SMALL_SHIELD:
613.     case ELVEN_SHIELD:
614.     case URUK_HAI_SHIELD:
615.     case ORCISH_SHIELD:
616.     case DWARVISH_ROUNDSHIELD:
617.     case LARGE_SHIELD:
618.     case SHIELD_OF_REFLECTION:
619.         break;
620.     default:
621.         impossible(unknown_type, c_shield, uarms->otyp);
622.     }
623.     if (uarms) /* no known instance of !uarmgs here but play it safe */
624.         uarms->known = 1; /* shield's +/- evident because of status line AC */
625.     return 0;
626. }
627. 
628. int
629. Shield_off(VOID_ARGS)
630. {
631.     context.takeoff.mask &= ~W_ARMS;
632. 
633.     /* no shield currently requires special handling when taken off, but we
634.        keep this uncommented in case somebody adds a new one which does */
635.     switch (uarms->otyp) {
636.     case SMALL_SHIELD:
637.     case ELVEN_SHIELD:
638.     case URUK_HAI_SHIELD:
639.     case ORCISH_SHIELD:
640.     case DWARVISH_ROUNDSHIELD:
641.     case LARGE_SHIELD:
642.     case SHIELD_OF_REFLECTION:
643.         break;
644.     default:
645.         impossible(unknown_type, c_shield, uarms->otyp);
646.     }
647. 
648.     setworn((struct obj *) 0, W_ARMS);
649.     return 0;
650. }
651. 
652. STATIC_PTR int
653. Shirt_on(VOID_ARGS)
654. {
655.     /* no shirt currently requires special handling when put on, but we
656.        keep this uncommented in case somebody adds a new one which does */
657.     switch (uarmu->otyp) {
658.     case HAWAIIAN_SHIRT:
659.     case T_SHIRT:
660.         break;
661.     default:
662.         impossible(unknown_type, c_shirt, uarmu->otyp);
663.     }
664.     if (uarmu) /* no known instances of !uarmu here but play it safe */
665.         uarmu->known = 1; /* shirt's +/- evident because of status line AC */
666.     return 0;
667. }
668. 
669. int
670. Shirt_off(VOID_ARGS)
671. {
672.     context.takeoff.mask &= ~W_ARMU;
673. 
674.     /* no shirt currently requires special handling when taken off, but we
675.        keep this uncommented in case somebody adds a new one which does */
676.     switch (uarmu->otyp) {
677.     case HAWAIIAN_SHIRT:
678.     case T_SHIRT:
679.         break;
680.     default:
681.         impossible(unknown_type, c_shirt, uarmu->otyp);
682.     }
683. 
684.     setworn((struct obj *) 0, W_ARMU);
685.     return 0;
686. }
687. 
688. STATIC_PTR
689. int
690. Armor_on(VOID_ARGS)
691. {
692.     /*
693.      * No suits require special handling.  Special properties conferred by
694.      * suits are set up as intrinsics (actually 'extrinsics') by setworn()
695.      * which is called by armor_or_accessory_on() before Armor_on().
696.      */
697.     if (uarm) /* no known instances of !uarm here but play it safe */
698.         uarm->known = 1; /* suit's +/- evident because of status line AC */
699.     return 0;
700. }
701. 
702. int
703. Armor_off(VOID_ARGS)
704. {
705.     context.takeoff.mask &= ~W_ARM;
706.     setworn((struct obj *) 0, W_ARM);
707.     context.takeoff.cancelled_don = FALSE;
708.     return 0;
709. }
710. 
711. /* The gone functions differ from the off functions in that if you die from
712.  * taking it off and have life saving, you still die.  [Obsolete reference
713.  * to lack of fire resistance being fatal in hell (nethack 3.0) and life
714.  * saving putting a removed item back on to prevent that from immediately
715.  * repeating.]
716.  */
717. int
718. Armor_gone()
719. {
720.     context.takeoff.mask &= ~W_ARM;
721.     setnotworn(uarm);
722.     context.takeoff.cancelled_don = FALSE;
723.     return 0;
724. }
725. 
726. STATIC_OVL void
727. Amulet_on()
728. {
729.     /* make sure amulet isn't wielded; can't use remove_worn_item()
730.        here because it has already been set worn in amulet slot */
731.     if (uamul == uwep)
732.         setuwep((struct obj *) 0);
733.     else if (uamul == uswapwep)
734.         setuswapwep((struct obj *) 0);
735.     else if (uamul == uquiver)
736.         setuqwep((struct obj *) 0);
737. 
738.     switch (uamul->otyp) {
739.     case AMULET_OF_ESP:
740.     case AMULET_OF_LIFE_SAVING:
741.     case AMULET_VERSUS_POISON:
742.     case AMULET_OF_REFLECTION:
743.     case AMULET_OF_MAGICAL_BREATHING:
744.     case FAKE_AMULET_OF_YENDOR:
745.         break;
746.     case AMULET_OF_UNCHANGING:
747.         if (Slimed)
748.             make_slimed(0L, (char *) 0);
749.         break;
750.     case AMULET_OF_CHANGE: {
751.         int orig_sex = poly_gender();
752. 
753.         if (Unchanging)
754.             break;
755.         change_sex();
756.         /* Don't use same message as polymorph */
757.         if (orig_sex != poly_gender()) {
758.             makeknown(AMULET_OF_CHANGE);
759.             You("are suddenly very %s!",
760.                 flags.female ? "feminine" : "masculine");
761.             context.botl = 1;
762.         } else
763.             /* already polymorphed into single-gender monster; only
764.                changed the character's base sex */
765.             You("don't feel like yourself.");
766.         pline_The("amulet disintegrates!");
767.         if (orig_sex == poly_gender() && uamul->dknown
768.             && !objects[AMULET_OF_CHANGE].oc_name_known
769.             && !objects[AMULET_OF_CHANGE].oc_uname)
770.             docall(uamul);
771.         useup(uamul);
772.         break;
773.     }
774.     case AMULET_OF_STRANGULATION:
775.         if (can_be_strangled(&youmonst)) {
776.             makeknown(AMULET_OF_STRANGULATION);
777.             Strangled = 6L;
778.             context.botl = TRUE;
779.             pline("It constricts your throat!");
780.         }
781.         break;
782.     case AMULET_OF_RESTFUL_SLEEP: {
783.         long newnap = (long) rnd(100), oldnap = (HSleepy & TIMEOUT);
784. 
785.         /* avoid clobbering FROMOUTSIDE bit, which might have
786.            gotten set by previously eating one of these amulets */
787.         if (newnap < oldnap || oldnap == 0L)
788.             HSleepy = (HSleepy & ~TIMEOUT) | newnap;
789.     } break;
790.     case AMULET_OF_YENDOR:
791.         break;
792.     }
793. }
794. 
795. void
796. Amulet_off()
797. {
798.     context.takeoff.mask &= ~W_AMUL;
799. 
800.     switch (uamul->otyp) {
801.     case AMULET_OF_ESP:
802.         /* need to update ability before calling see_monsters() */
803.         setworn((struct obj *) 0, W_AMUL);
804.         see_monsters();
805.         return;
806.     case AMULET_OF_LIFE_SAVING:
807.     case AMULET_VERSUS_POISON:
808.     case AMULET_OF_REFLECTION:
809.     case AMULET_OF_CHANGE:
810.     case AMULET_OF_UNCHANGING:
811.     case FAKE_AMULET_OF_YENDOR:
812.         break;
813.     case AMULET_OF_MAGICAL_BREATHING:
814.         if (Underwater) {
815.             /* HMagical_breathing must be set off
816.                 before calling drown() */
817.             setworn((struct obj *) 0, W_AMUL);
818.             if (!breathless(youmonst.data) && !amphibious(youmonst.data)
819.                 && !Swimming) {
820.                 You("suddenly inhale an unhealthy amount of %s!",
821.                     hliquid("water"));
822.                 (void) drown();
823.             }
824.             return;
825.         }
826.         break;
827.     case AMULET_OF_STRANGULATION:
828.         if (Strangled) {
829.             Strangled = 0L;
830.             context.botl = TRUE;
831.             if (Breathless)
832.                 Your("%s is no longer constricted!", body_part(NECK));
833.             else
834.                 You("can breathe more easily!");
835.         }
836.         break;
837.     case AMULET_OF_RESTFUL_SLEEP:
838.         setworn((struct obj *) 0, W_AMUL);
839.         /* HSleepy = 0L; -- avoid clobbering FROMOUTSIDE bit */
840.         if (!ESleepy && !(HSleepy & ~TIMEOUT))
841.             HSleepy &= ~TIMEOUT; /* clear timeout bits */
842.         return;
843.     case AMULET_OF_YENDOR:
844.         break;
845.     }
846.     setworn((struct obj *) 0, W_AMUL);
847.     return;
848. }
849. 
850. /* handle ring discovery; comparable to learnwand() */
851. STATIC_OVL void
852. learnring(ring, observed)
853. struct obj *ring;
854. boolean observed;
855. {
856.     int ringtype = ring->otyp;
857. 
858.     /* if effect was observeable then we usually discover the type */
859.     if (observed) {
860.         /* if we already know the ring type which accomplishes this
861.            effect (assumes there is at most one type for each effect),
862.            mark this ring as having been seen (no need for makeknown);
863.            otherwise if we have seen this ring, discover its type */
864.         if (objects[ringtype].oc_name_known)
865.             ring->dknown = 1;
866.         else if (ring->dknown)
867.             makeknown(ringtype);
868. #if 0 /* see learnwand() */
869.         else
870.             ring->eknown = 1;
871. #endif
872.     }
873. 
874.     /* make enchantment of charged ring known (might be +0) and update
875.        perm invent window if we've seen this ring and know its type */
876.     if (ring->dknown && objects[ringtype].oc_name_known) {
877.         if (objects[ringtype].oc_charged)
878.             ring->known = 1;
879.         update_inventory();
880.     }
881. }
882. 
883. void
884. Ring_on(obj)
885. register struct obj *obj;
886. {
887.     long oldprop = u.uprops[objects[obj->otyp].oc_oprop].extrinsic;
888.     int old_attrib, which;
889.     boolean observable;
890. 
891.     /* make sure ring isn't wielded; can't use remove_worn_item()
892.        here because it has already been set worn in a ring slot */
893.     if (obj == uwep)
894.         setuwep((struct obj *) 0);
895.     else if (obj == uswapwep)
896.         setuswapwep((struct obj *) 0);
897.     else if (obj == uquiver)
898.         setuqwep((struct obj *) 0);
899. 
900.     /* only mask out W_RING when we don't have both
901.        left and right rings of the same type */
902.     if ((oldprop & W_RING) != W_RING)
903.         oldprop &= ~W_RING;
904. 
905.     switch (obj->otyp) {
906.     case RIN_TELEPORTATION:
907.     case RIN_REGENERATION:
908.     case RIN_SEARCHING:
909.     case RIN_HUNGER:
910.     case RIN_AGGRAVATE_MONSTER:
911.     case RIN_POISON_RESISTANCE:
912.     case RIN_FIRE_RESISTANCE:
913.     case RIN_COLD_RESISTANCE:
914.     case RIN_SHOCK_RESISTANCE:
915.     case RIN_CONFLICT:
916.     case RIN_TELEPORT_CONTROL:
917.     case RIN_POLYMORPH:
918.     case RIN_POLYMORPH_CONTROL:
919.     case RIN_FREE_ACTION:
920.     case RIN_SLOW_DIGESTION:
921.     case RIN_SUSTAIN_ABILITY:
922.     case MEAT_RING:
923.         break;
924.     case RIN_STEALTH:
925.         toggle_stealth(obj, oldprop, TRUE);
926.         break;
927.     case RIN_WARNING:
928.         see_monsters();
929.         break;
930.     case RIN_SEE_INVISIBLE:
931.         /* can now see invisible monsters */
932.         set_mimic_blocking(); /* do special mimic handling */
933.         see_monsters();
934. 
935.         if (Invis && !oldprop && !HSee_invisible && !Blind) {
936.             newsym(u.ux, u.uy);
937.             pline("Suddenly you are transparent, but there!");
938.             learnring(obj, TRUE);
939.         }
940.         break;
941.     case RIN_INVISIBILITY:
942.         if (!oldprop && !HInvis && !BInvis && !Blind) {
943.             learnring(obj, TRUE);
944.             newsym(u.ux, u.uy);
945.             self_invis_message();
946.         }
947.         break;
948.     case RIN_LEVITATION:
949.         if (!oldprop && !HLevitation && !(BLevitation & FROMOUTSIDE)) {
950.             float_up();
951.             learnring(obj, TRUE);
952.             if (Levitation)
953.                 spoteffects(FALSE); /* for sinks */
954.         } else {
955.             float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
956.         }
957.         break;
958.     case RIN_GAIN_STRENGTH:
959.         which = A_STR;
960.         goto adjust_attrib;
961.     case RIN_GAIN_CONSTITUTION:
962.         which = A_CON;
963.         goto adjust_attrib;
964.     case RIN_ADORNMENT:
965.         which = A_CHA;
966.  adjust_attrib:
967.         old_attrib = ACURR(which);
968.         ABON(which) += obj->spe;
969.         observable = (old_attrib != ACURR(which));
970.         /* if didn't change, usually means ring is +0 but might
971.            be because nonzero couldn't go below min or above max;
972.            learn +0 enchantment if attribute value is not stuck
973.            at a limit [and ring has been seen and its type is
974.            already discovered, both handled by learnring()] */
975.         if (observable || !extremeattr(which))
976.             learnring(obj, observable);
977.         context.botl = 1;
978.         break;
979.     case RIN_INCREASE_ACCURACY: /* KMH */
980.         u.uhitinc += obj->spe;
981.         break;
982.     case RIN_INCREASE_DAMAGE:
983.         u.udaminc += obj->spe;
984.         break;
985.     case RIN_PROTECTION_FROM_SHAPE_CHAN:
986.         rescham();
987.         break;
988.     case RIN_PROTECTION:
989.         /* usually learn enchantment and discover type;
990.            won't happen if ring is unseen or if it's +0
991.            and the type hasn't been discovered yet */
992.         observable = (obj->spe != 0);
993.         learnring(obj, observable);
994.         if (obj->spe)
995.             find_ac(); /* updates botl */
996.         break;
997.     }
998. }
999. 
1000. STATIC_OVL void
1001. Ring_off_or_gone(obj, gone)
1002. register struct obj *obj;
1003. boolean gone;
1004. {
1005.     long mask = (obj->owornmask & W_RING);
1006.     int old_attrib, which;
1007.     boolean observable;
1008. 
1009.     context.takeoff.mask &= ~mask;
1010.     if (!(u.uprops[objects[obj->otyp].oc_oprop].extrinsic & mask))
1011.         impossible("Strange... I didn't know you had that ring.");
1012.     if (gone)
1013.         setnotworn(obj);
1014.     else
1015.         setworn((struct obj *) 0, obj->owornmask);
1016. 
1017.     switch (obj->otyp) {
1018.     case RIN_TELEPORTATION:
1019.     case RIN_REGENERATION:
1020.     case RIN_SEARCHING:
1021.     case RIN_HUNGER:
1022.     case RIN_AGGRAVATE_MONSTER:
1023.     case RIN_POISON_RESISTANCE:
1024.     case RIN_FIRE_RESISTANCE:
1025.     case RIN_COLD_RESISTANCE:
1026.     case RIN_SHOCK_RESISTANCE:
1027.     case RIN_CONFLICT:
1028.     case RIN_TELEPORT_CONTROL:
1029.     case RIN_POLYMORPH:
1030.     case RIN_POLYMORPH_CONTROL:
1031.     case RIN_FREE_ACTION:
1032.     case RIN_SLOW_DIGESTION:
1033.     case RIN_SUSTAIN_ABILITY:
1034.     case MEAT_RING:
1035.         break;
1036.     case RIN_STEALTH:
1037.         toggle_stealth(obj, (EStealth & ~mask), FALSE);
1038.         break;
1039.     case RIN_WARNING:
1040.         see_monsters();
1041.         break;
1042.     case RIN_SEE_INVISIBLE:
1043.         /* Make invisible monsters go away */
1044.         if (!See_invisible) {
1045.             set_mimic_blocking(); /* do special mimic handling */
1046.             see_monsters();
1047.         }
1048. 
1049.         if (Invisible && !Blind) {
1050.             newsym(u.ux, u.uy);
1051.             pline("Suddenly you cannot see yourself.");
1052.             learnring(obj, TRUE);
1053.         }
1054.         break;
1055.     case RIN_INVISIBILITY:
1056.         if (!Invis && !BInvis && !Blind) {
1057.             newsym(u.ux, u.uy);
1058.             Your("body seems to unfade%s.",
1059.                  See_invisible ? " completely" : "..");
1060.             learnring(obj, TRUE);
1061.         }
1062.         break;
1063.     case RIN_LEVITATION:
1064.         if (!(BLevitation & FROMOUTSIDE)) {
1065.             (void) float_down(0L, 0L);
1066.             if (!Levitation)
1067.                 learnring(obj, TRUE);
1068.         } else {
1069.             float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
1070.         }
1071.         break;
1072.     case RIN_GAIN_STRENGTH:
1073.         which = A_STR;
1074.         goto adjust_attrib;
1075.     case RIN_GAIN_CONSTITUTION:
1076.         which = A_CON;
1077.         goto adjust_attrib;
1078.     case RIN_ADORNMENT:
1079.         which = A_CHA;
1080.  adjust_attrib:
1081.         old_attrib = ACURR(which);
1082.         ABON(which) -= obj->spe;
1083.         observable = (old_attrib != ACURR(which));
1084.         /* same criteria as Ring_on() */
1085.         if (observable || !extremeattr(which))
1086.             learnring(obj, observable);
1087.         context.botl = 1;
1088.         break;
1089.     case RIN_INCREASE_ACCURACY: /* KMH */
1090.         u.uhitinc -= obj->spe;
1091.         break;
1092.     case RIN_INCREASE_DAMAGE:
1093.         u.udaminc -= obj->spe;
1094.         break;
1095.     case RIN_PROTECTION:
1096.         /* might have been put on while blind and we can now see
1097.            or perhaps been forgotten due to amnesia */
1098.         observable = (obj->spe != 0);
1099.         learnring(obj, observable);
1100.         if (obj->spe)
1101.             find_ac(); /* updates botl */
1102.         break;
1103.     case RIN_PROTECTION_FROM_SHAPE_CHAN:
1104.         /* If you're no longer protected, let the chameleons
1105.          * change shape again -dgk
1106.          */
1107.         restartcham();
1108.         break;
1109.     }
1110. }
1111. 
1112. void
1113. Ring_off(obj)
1114. struct obj *obj;
1115. {
1116.     Ring_off_or_gone(obj, FALSE);
1117. }
1118. 
1119. void
1120. Ring_gone(obj)
1121. struct obj *obj;
1122. {
1123.     Ring_off_or_gone(obj, TRUE);
1124. }
1125. 
1126. void
1127. Blindf_on(otmp)
1128. struct obj *otmp;
1129. {
1130.     boolean already_blind = Blind, changed = FALSE;
1131. 
1132.     /* blindfold might be wielded; release it for wearing */
1133.     if (otmp->owornmask & W_WEAPONS)
1134.         remove_worn_item(otmp, FALSE);
1135.     setworn(otmp, W_TOOL);
1136.     on_msg(otmp);
1137. 
1138.     if (Blind && !already_blind) {
1139.         changed = TRUE;
1140.         if (flags.verbose)
1141.             You_cant("see any more.");
1142.         /* set ball&chain variables before the hero goes blind */
1143.         if (Punished)
1144.             set_bc(0);
1145.     } else if (already_blind && !Blind) {
1146.         changed = TRUE;
1147.         /* "You are now wearing the Eyes of the Overworld." */
1148.         if (u.uroleplay.blind) {
1149.             /* this can only happen by putting on the Eyes of the Overworld;
1150.                that shouldn't actually produce a permanent cure, but we
1151.                can't let the "blind from birth" conduct remain intact */
1152.             pline("For the first time in your life, you can see!");
1153.             u.uroleplay.blind = FALSE;
1154.         } else
1155.             You("can see!");
1156.     }
1157.     if (changed) {
1158.         toggle_blindness(); /* potion.c */
1159.     }
1160. }
1161. 
1162. void
1163. Blindf_off(otmp)
1164. struct obj *otmp;
1165. {
1166.     boolean was_blind = Blind, changed = FALSE;
1167. 
1168.     if (!otmp) {
1169.         impossible("Blindf_off without otmp");
1170.         return;
1171.     }
1172.     context.takeoff.mask &= ~W_TOOL;
1173.     setworn((struct obj *) 0, otmp->owornmask);
1174.     off_msg(otmp);
1175. 
1176.     if (Blind) {
1177.         if (was_blind) {
1178.             /* "still cannot see" makes no sense when removing lenses
1179.                since they can't have been the cause of your blindness */
1180.             if (otmp->otyp != LENSES)
1181.                 You("still cannot see.");
1182.         } else {
1183.             changed = TRUE; /* !was_blind */
1184.             /* "You were wearing the Eyes of the Overworld." */
1185.             You_cant("see anything now!");
1186.             /* set ball&chain variables before the hero goes blind */
1187.             if (Punished)
1188.                 set_bc(0);
1189.         }
1190.     } else if (was_blind) {
1191.         if (!gulp_blnd_check()) {
1192.             changed = TRUE; /* !Blind */
1193.             You("can see again.");
1194.         }
1195.     }
1196.     if (changed) {
1197.         toggle_blindness(); /* potion.c */
1198.     }
1199. }
1200. 
1201. /* called in moveloop()'s prologue to set side-effects of worn start-up items;
1202.    also used by poly_obj() when a worn item gets transformed */
1203. void
1204. set_wear(obj)
1205. struct obj *obj; /* if null, do all worn items; otherwise just obj itself */
1206. {
1207.     initial_don = !obj;
1208. 
1209.     if (!obj ? ublindf != 0 : (obj == ublindf))
1210.         (void) Blindf_on(ublindf);
1211.     if (!obj ? uright != 0 : (obj == uright))
1212.         (void) Ring_on(uright);
1213.     if (!obj ? uleft != 0 : (obj == uleft))
1214.         (void) Ring_on(uleft);
1215.     if (!obj ? uamul != 0 : (obj == uamul))
1216.         (void) Amulet_on();
1217. 
1218.     if (!obj ? uarmu != 0 : (obj == uarmu))
1219.         (void) Shirt_on();
1220.     if (!obj ? uarm != 0 : (obj == uarm))
1221.         (void) Armor_on();
1222.     if (!obj ? uarmc != 0 : (obj == uarmc))
1223.         (void) Cloak_on();
1224.     if (!obj ? uarmf != 0 : (obj == uarmf))
1225.         (void) Boots_on();
1226.     if (!obj ? uarmg != 0 : (obj == uarmg))
1227.         (void) Gloves_on();
1228.     if (!obj ? uarmh != 0 : (obj == uarmh))
1229.         (void) Helmet_on();
1230.     if (!obj ? uarms != 0 : (obj == uarms))
1231.         (void) Shield_on();
1232. 
1233.     initial_don = FALSE;
1234. }
1235. 
1236. /* check whether the target object is currently being put on (or taken off--
1237.    also checks for doffing--[why?]) */
1238. boolean
1239. donning(otmp)
1240. struct obj *otmp;
1241. {
1242.     boolean result = FALSE;
1243. 
1244.     /* 'W' (or 'P' used for armor) sets afternmv */
1245.     if (doffing(otmp))
1246.         result = TRUE;
1247.     else if (otmp == uarm)
1248.         result = (afternmv == Armor_on);
1249.     else if (otmp == uarmu)
1250.         result = (afternmv == Shirt_on);
1251.     else if (otmp == uarmc)
1252.         result = (afternmv == Cloak_on);
1253.     else if (otmp == uarmf)
1254.         result = (afternmv == Boots_on);
1255.     else if (otmp == uarmh)
1256.         result = (afternmv == Helmet_on);
1257.     else if (otmp == uarmg)
1258.         result = (afternmv == Gloves_on);
1259.     else if (otmp == uarms)
1260.         result = (afternmv == Shield_on);
1261. 
1262.     return result;
1263. }
1264. 
1265. /* check whether the target object is currently being taken off,
1266.    so that stop_donning() and steal() can vary messages and doname()
1267.    can vary "(being worn)" suffix */
1268. boolean
1269. doffing(otmp)
1270. struct obj *otmp;
1271. {
1272.     long what = context.takeoff.what;
1273.     boolean result = FALSE;
1274. 
1275.     /* 'T' (or 'R' used for armor) sets afternmv, 'A' sets takeoff.what */
1276.     if (otmp == uarm)
1277.         result = (afternmv == Armor_off || what == WORN_ARMOR);
1278.     else if (otmp == uarmu)
1279.         result = (afternmv == Shirt_off || what == WORN_SHIRT);
1280.     else if (otmp == uarmc)
1281.         result = (afternmv == Cloak_off || what == WORN_CLOAK);
1282.     else if (otmp == uarmf)
1283.         result = (afternmv == Boots_off || what == WORN_BOOTS);
1284.     else if (otmp == uarmh)
1285.         result = (afternmv == Helmet_off || what == WORN_HELMET);
1286.     else if (otmp == uarmg)
1287.         result = (afternmv == Gloves_off || what == WORN_GLOVES);
1288.     else if (otmp == uarms)
1289.         result = (afternmv == Shield_off || what == WORN_SHIELD);
1290.     /* these 1-turn items don't need 'afternmv' checks */
1291.     else if (otmp == uamul)
1292.         result = (what == WORN_AMUL);
1293.     else if (otmp == uleft)
1294.         result = (what == LEFT_RING);
1295.     else if (otmp == uright)
1296.         result = (what == RIGHT_RING);
1297.     else if (otmp == ublindf)
1298.         result = (what == WORN_BLINDF);
1299.     else if (otmp == uwep)
1300.         result = (what == W_WEP);
1301.     else if (otmp == uswapwep)
1302.         result = (what == W_SWAPWEP);
1303.     else if (otmp == uquiver)
1304.         result = (what == W_QUIVER);
1305. 
1306.     return result;
1307. }
1308. 
1309. /* despite their names, cancel_don() and cancel_doff() both apply to both
1310.    donning and doffing... */
1311. void
1312. cancel_doff(obj, slotmask)
1313. struct obj *obj;
1314. long slotmask;
1315. {
1316.     /* Called by setworn() for old item in specified slot or by setnotworn()
1317.      * for specified item.  We don't want to call cancel_don() if we got
1318.      * here via <X>_off() -> setworn((struct obj *)0) -> cancel_doff()
1319.      * because that would stop the 'A' command from continuing with next
1320.      * selected item.  So do_takeoff() sets a flag in takeoff.mask for us.
1321.      * [For taking off an individual item with 'T'/'R'/'w-', it doesn't
1322.      * matter whether cancel_don() gets called here--the item has already
1323.      * been removed by now.]
1324.      */
1325.     if (!(context.takeoff.mask & I_SPECIAL) && donning(obj))
1326.         cancel_don(); /* applies to doffing too */
1327.     context.takeoff.mask &= ~slotmask;
1328. }
1329. 
1330. /* despite their names, cancel_don() and cancel_doff() both apply to both
1331.    donning and doffing... */
1332. void
1333. cancel_don()
1334. {
1335.     /* the piece of armor we were donning/doffing has vanished, so stop
1336.      * wasting time on it (and don't dereference it when donning would
1337.      * otherwise finish)
1338.      */
1339.     context.takeoff.cancelled_don =
1340.         (afternmv == Boots_on || afternmv == Helmet_on
1341.          || afternmv == Gloves_on || afternmv == Armor_on);
1342.     afternmv = (int NDECL((*))) 0;
1343.     nomovemsg = (char *) 0;
1344.     multi = 0;
1345.     context.takeoff.delay = 0;
1346.     context.takeoff.what = 0L;
1347. }
1348. 
1349. /* called by steal() during theft from hero; interrupt donning/doffing */
1350. int
1351. stop_donning(stolenobj)
1352. struct obj *stolenobj; /* no message if stolenobj is already being doffing */
1353. {
1354.     char buf[BUFSZ];
1355.     struct obj *otmp;
1356.     boolean putting_on;
1357.     int result = 0;
1358. 
1359.     for (otmp = invent; otmp; otmp = otmp->nobj)
1360.         if ((otmp->owornmask & W_ARMOR) && donning(otmp))
1361.             break;
1362.     /* at most one item will pass donning() test at any given time */
1363.     if (!otmp)
1364.         return 0;
1365. 
1366.     /* donning() returns True when doffing too; doffing() is more specific */
1367.     putting_on = !doffing(otmp);
1368.     /* cancel_don() looks at afternmv; it can also cancel doffing */
1369.     cancel_don();
1370.     /* don't want <armor>_on() or <armor>_off() being called
1371.        by unmul() since the on or off action isn't completing */
1372.     afternmv = (int NDECL((*))) 0;
1373.     if (putting_on || otmp != stolenobj) {
1374.         Sprintf(buf, "You stop %s %s.",
1375.                 putting_on ? "putting on" : "taking off",
1376.                 thesimpleoname(otmp));
1377.     } else {
1378.         buf[0] = '\0';   /* silently stop doffing stolenobj */
1379.         result = -multi; /* remember this before calling unmul() */
1380.     }
1381.     unmul(buf);
1382.     /* while putting on, item becomes worn immediately but side-effects are
1383.        deferred until the delay expires; when interrupted, make it unworn
1384.        (while taking off, item stays worn until the delay expires; when
1385.        interrupted, leave it worn) */
1386.     if (putting_on)
1387.         remove_worn_item(otmp, FALSE);
1388. 
1389.     return result;
1390. }
1391. 
1392. /* both 'clothes' and 'accessories' now include both armor and accessories;
1393.    TOOL_CLASS is for eyewear, FOOD_CLASS is for MEAT_RING */
1394. static NEARDATA const char clothes[] = {
1395.     ARMOR_CLASS, RING_CLASS, AMULET_CLASS, TOOL_CLASS, FOOD_CLASS, 0
1396. };
1397. static NEARDATA const char accessories[] = {
1398.     RING_CLASS, AMULET_CLASS, TOOL_CLASS, FOOD_CLASS, ARMOR_CLASS, 0
1399. };
1400. STATIC_VAR NEARDATA int Narmorpieces, Naccessories;
1401. 
1402. /* assign values to Narmorpieces and Naccessories */
1403. STATIC_OVL void
1404. count_worn_stuff(which, accessorizing)
1405. struct obj **which; /* caller wants this when count is 1 */
1406. boolean accessorizing;
1407. {
1408.     struct obj *otmp;
1409. 
1410.     Narmorpieces = Naccessories = 0;
1411. 
1412. #define MOREWORN(x,wtyp) do { if (x) { wtyp++; otmp = x; } } while (0)
1413.     otmp = 0;
1414.     MOREWORN(uarmh, Narmorpieces);
1415.     MOREWORN(uarms, Narmorpieces);
1416.     MOREWORN(uarmg, Narmorpieces);
1417.     MOREWORN(uarmf, Narmorpieces);
1418.     /* for cloak/suit/shirt, we only count the outermost item so that it
1419.        can be taken off without confirmation if final count ends up as 1 */
1420.     if (uarmc)
1421.         MOREWORN(uarmc, Narmorpieces);
1422.     else if (uarm)
1423.         MOREWORN(uarm, Narmorpieces);
1424.     else if (uarmu)
1425.         MOREWORN(uarmu, Narmorpieces);
1426.     if (!accessorizing)
1427.         *which = otmp; /* default item iff Narmorpieces is 1 */
1428. 
1429.     otmp = 0;
1430.     MOREWORN(uleft, Naccessories);
1431.     MOREWORN(uright, Naccessories);
1432.     MOREWORN(uamul, Naccessories);
1433.     MOREWORN(ublindf, Naccessories);
1434.     if (accessorizing)
1435.         *which = otmp; /* default item iff Naccessories is 1 */
1436. #undef MOREWORN
1437. }
1438. 
1439. /* take off one piece or armor or one accessory;
1440.    shared by dotakeoff('T') and doremring('R') */
1441. STATIC_OVL int
1442. armor_or_accessory_off(obj)
1443. struct obj *obj;
1444. {
1445.     if (!(obj->owornmask & (W_ARMOR | W_ACCESSORY))) {
1446.         You("are not wearing that.");
1447.         return 0;
1448.     }
1449.     if (obj == uskin
1450.         || ((obj == uarm) && uarmc)
1451.         || ((obj == uarmu) && (uarmc || uarm))) {
1452.         char why[QBUFSZ], what[QBUFSZ];
1453. 
1454.         why[0] = what[0] = '\0';
1455.         if (obj != uskin) {
1456.             if (uarmc)
1457.                 Strcat(what, cloak_simple_name(uarmc));
1458.             if ((obj == uarmu) && uarm) {
1459.                 if (uarmc)
1460.                     Strcat(what, " and ");
1461.                 Strcat(what, suit_simple_name(uarm));
1462.             }
1463.             Sprintf(why, " without taking off your %s first", what);
1464.         } else {
1465.             Strcpy(why, "; it's embedded");
1466.         }
1467.         You_cant("take that off%s.", why);
1468.         return 0;
1469.     }
1470. 
1471.     reset_remarm(); /* clear context.takeoff.mask and context.takeoff.what */
1472.     (void) select_off(obj);
1473.     if (!context.takeoff.mask)
1474.         return 0;
1475.     /* none of armoroff()/Ring_/Amulet/Blindf_off() use context.takeoff.mask */
1476.     reset_remarm();
1477. 
1478.     if (obj->owornmask & W_ARMOR) {
1479.         (void) armoroff(obj);
1480.     } else if (obj == uright || obj == uleft) {
1481.         /* Sometimes we want to give the off_msg before removing and
1482.          * sometimes after; for instance, "you were wearing a moonstone
1483.          * ring (on right hand)" is desired but "you were wearing a
1484.          * square amulet (being worn)" is not because of the redundant
1485.          * "being worn".
1486.          */
1487.         off_msg(obj);
1488.         Ring_off(obj);
1489.     } else if (obj == uamul) {
1490.         Amulet_off();
1491.         off_msg(obj);
1492.     } else if (obj == ublindf) {
1493.         Blindf_off(obj); /* does its own off_msg */
1494.     } else {
1495.         impossible("removing strange accessory?");
1496.         if (obj->owornmask)
1497.             remove_worn_item(obj, FALSE);
1498.     }
1499.     return 1;
1500. }
1501. 
1502. /* the 'T' command */
1503. int
1504. dotakeoff()
1505. {
1506.     struct obj *otmp = (struct obj *) 0;
1507. 
1508.     count_worn_stuff(&otmp, FALSE);
1509.     if (!Narmorpieces && !Naccessories) {
1510.         /* assert( GRAY_DRAGON_SCALES > YELLOW_DRAGON_SCALE_MAIL ); */
1511.         if (uskin)
1512.             pline_The("%s merged with your skin!",
1513.                       uskin->otyp >= GRAY_DRAGON_SCALES
1514.                           ? "dragon scales are"
1515.                           : "dragon scale mail is");
1516.         else
1517.             pline("Not wearing any armor or accessories.");
1518.         return 0;
1519.     }
1520.     if (Narmorpieces != 1 || ParanoidRemove)
1521.         otmp = getobj(clothes, "take off");
1522.     if (!otmp)
1523.         return 0;
1524. 
1525.     return armor_or_accessory_off(otmp);
1526. }
1527. 
1528. /* the 'R' command */
1529. int
1530. doremring()
1531. {
1532.     struct obj *otmp = 0;
1533. 
1534.     count_worn_stuff(&otmp, TRUE);
1535.     if (!Naccessories && !Narmorpieces) {
1536.         pline("Not wearing any accessories or armor.");
1537.         return 0;
1538.     }
1539.     if (Naccessories != 1 || ParanoidRemove)
1540.         otmp = getobj(accessories, "remove");
1541.     if (!otmp)
1542.         return 0;
1543. 
1544.     return armor_or_accessory_off(otmp);
1545. }
1546. 
1547. /* Check if something worn is cursed _and_ unremovable. */
1548. int
1549. cursed(otmp)
1550. struct obj *otmp;
1551. {
1552.     if (!otmp) {
1553.         impossible("cursed without otmp");
1554.         return 0;
1555.     }
1556.     /* Curses, like chickens, come home to roost. */
1557.     if ((otmp == uwep) ? welded(otmp) : (int) otmp->cursed) {
1558.         boolean use_plural = (is_boots(otmp) || is_gloves(otmp)
1559.                               || otmp->otyp == LENSES || otmp->quan > 1L);
1560. 
1561.         /* might be trying again after applying grease to hands */
1562.         if (Glib && otmp->bknown
1563.             /* for weapon, we'll only get here via 'A )' */
1564.             && (uarmg ? (otmp == uwep)
1565.                       : ((otmp->owornmask & (W_WEP | W_RING)) != 0)))
1566.             pline("Despite your slippery %s, you can't.",
1567.                   fingers_or_gloves(TRUE));
1568.         else
1569.             You("can't.  %s cursed.", use_plural ? "They are" : "It is");
1570.         set_bknown(otmp, 1);
1571.         return 1;
1572.     }
1573.     return 0;
1574. }
1575. 
1576. int
1577. armoroff(otmp)
1578. struct obj *otmp;
1579. {
1580.     static char offdelaybuf[60];
1581.     int delay = -objects[otmp->otyp].oc_delay;
1582.     const char *what = 0;
1583. 
1584.     if (cursed(otmp))
1585.         return 0;
1586.     /* this used to make assumptions about which types of armor had
1587.        delays and which didn't; now both are handled for all types */
1588.     if (delay) {
1589.         nomul(delay);
1590.         multi_reason = "disrobing";
1591.         if (is_helmet(otmp)) {
1592.             what = helm_simple_name(otmp);
1593.             afternmv = Helmet_off;
1594.         } else if (is_gloves(otmp)) {
1595.             what = gloves_simple_name(otmp);
1596.             afternmv = Gloves_off;
1597.         } else if (is_boots(otmp)) {
1598.             what = c_boots;
1599.             afternmv = Boots_off;
1600.         } else if (is_suit(otmp)) {
1601.             what = suit_simple_name(otmp);
1602.             afternmv = Armor_off;
1603.         } else if (is_cloak(otmp)) {
1604.             what = cloak_simple_name(otmp);
1605.             afternmv = Cloak_off;
1606.         } else if (is_shield(otmp)) {
1607.             what = c_shield;
1608.             afternmv = Shield_off;
1609.         } else if (is_shirt(otmp)) {
1610.             what = c_shirt;
1611.             afternmv = Shirt_off;
1612.         } else {
1613.             impossible("Taking off unknown armor (%d: %d), delay %d",
1614.                        otmp->otyp, objects[otmp->otyp].oc_armcat, delay);
1615.         }
1616.         if (what) {
1617.             Sprintf(offdelaybuf, "You finish taking off your %s.", what);
1618.             nomovemsg = offdelaybuf;
1619.         }
1620.     } else {
1621.         /* Be warned!  We want off_msg after removing the item to
1622.          * avoid "You were wearing ____ (being worn)."  However, an
1623.          * item which grants fire resistance might cause some trouble
1624.          * if removed in Hell and lifesaving puts it back on; in this
1625.          * case the message will be printed at the wrong time (after
1626.          * the messages saying you died and were lifesaved).  Luckily,
1627.          * no cloak, shield, or fast-removable armor grants fire
1628.          * resistance, so we can safely do the off_msg afterwards.
1629.          * Rings do grant fire resistance, but for rings we want the
1630.          * off_msg before removal anyway so there's no problem.  Take
1631.          * care in adding armors granting fire resistance; this code
1632.          * might need modification.
1633.          * 3.2 (actually 3.1 even): that comment is obsolete since
1634.          * fire resistance is not required for Gehennom so setworn()
1635.          * doesn't force the resistance granting item to be re-worn
1636.          * after being lifesaved anymore.
1637.          */
1638.         if (is_cloak(otmp))
1639.             (void) Cloak_off();
1640.         else if (is_shield(otmp))
1641.             (void) Shield_off();
1642.         else if (is_helmet(otmp))
1643.             (void) Helmet_off();
1644.         else if (is_gloves(otmp))
1645.             (void) Gloves_off();
1646.         else if (is_boots(otmp))
1647.             (void) Boots_off();
1648.         else if (is_shirt(otmp))
1649.             (void) Shirt_off();
1650.         else if (is_suit(otmp))
1651.             (void) Armor_off();
1652.         else
1653.             impossible("Taking off unknown armor (%d: %d), no delay",
1654.                        otmp->otyp, objects[otmp->otyp].oc_armcat);
1655.         off_msg(otmp);
1656.     }
1657.     context.takeoff.mask = context.takeoff.what = 0L;
1658.     return 1;
1659. }
1660. 
1661. STATIC_OVL void
1662. already_wearing(cc)
1663. const char *cc;
1664. {
1665.     You("are already wearing %s%c", cc, (cc == c_that_) ? '!' : '.');
1666. }
1667. 
1668. STATIC_OVL void
1669. already_wearing2(cc1, cc2)
1670. const char *cc1, *cc2;
1671. {
1672.     You_cant("wear %s because you're wearing %s there already.", cc1, cc2);
1673. }
1674. 
1675. /*
1676.  * canwearobj checks to see whether the player can wear a piece of armor
1677.  *
1678.  * inputs: otmp (the piece of armor)
1679.  *         noisy (if TRUE give error messages, otherwise be quiet about it)
1680.  * output: mask (otmp's armor type)
1681.  */
1682. int
1683. canwearobj(otmp, mask, noisy)
1684. struct obj *otmp;
1685. long *mask;
1686. boolean noisy;
1687. {
1688.     int err = 0;
1689.     const char *which;
1690. 
1691.     /* this is the same check as for 'W' (dowear), but different message,
1692.        in case we get here via 'P' (doputon) */
1693.     if (verysmall(youmonst.data) || nohands(youmonst.data)) {
1694.         if (noisy)
1695.             You("can't wear any armor in your current form.");
1696.         return 0;
1697.     }
1698. 
1699.     which = is_cloak(otmp)
1700.                 ? c_cloak
1701.                 : is_shirt(otmp)
1702.                     ? c_shirt
1703.                     : is_suit(otmp)
1704.                         ? c_suit
1705.                         : 0;
1706.     if (which && cantweararm(youmonst.data)
1707.         /* same exception for cloaks as used in m_dowear() */
1708.         && (which != c_cloak || youmonst.data->msize != MZ_SMALL)
1709.         && (racial_exception(&youmonst, otmp) < 1)) {
1710.         if (noisy)
1711.             pline_The("%s will not fit on your body.", which);
1712.         return 0;
1713.     } else if (otmp->owornmask & W_ARMOR) {
1714.         if (noisy)
1715.             already_wearing(c_that_);
1716.         return 0;
1717.     }
1718. 
1719.     if (welded(uwep) && bimanual(uwep) && (is_suit(otmp) || is_shirt(otmp))) {
1720.         if (noisy)
1721.             You("cannot do that while holding your %s.",
1722.                 is_sword(uwep) ? c_sword : c_weapon);
1723.         return 0;
1724.     }
1725. 
1726.     if (is_helmet(otmp)) {
1727.         if (uarmh) {
1728.             if (noisy)
1729.                 already_wearing(an(helm_simple_name(uarmh)));
1730.             err++;
1731.         } else if (Upolyd && has_horns(youmonst.data) && !is_flimsy(otmp)) {
1732.             /* (flimsy exception matches polyself handling) */
1733.             if (noisy)
1734.                 pline_The("%s won't fit over your horn%s.",
1735.                           helm_simple_name(otmp),
1736.                           plur(num_horns(youmonst.data)));
1737.             err++;
1738.         } else
1739.             *mask = W_ARMH;
1740.     } else if (is_shield(otmp)) {
1741.         if (uarms) {
1742.             if (noisy)
1743.                 already_wearing(an(c_shield));
1744.             err++;
1745.         } else if (uwep && bimanual(uwep)) {
1746.             if (noisy)
1747.                 You("cannot wear a shield while wielding a two-handed %s.",
1748.                     is_sword(uwep) ? c_sword : (uwep->otyp == BATTLE_AXE)
1749.                                                    ? c_axe
1750.                                                    : c_weapon);
1751.             err++;
1752.         } else if (u.twoweap) {
1753.             if (noisy)
1754.                 You("cannot wear a shield while wielding two weapons.");
1755.             err++;
1756.         } else
1757.             *mask = W_ARMS;
1758.     } else if (is_boots(otmp)) {
1759.         if (uarmf) {
1760.             if (noisy)
1761.                 already_wearing(c_boots);
1762.             err++;
1763.         } else if (Upolyd && slithy(youmonst.data)) {
1764.             if (noisy)
1765.                 You("have no feet..."); /* not body_part(FOOT) */
1766.             err++;
1767.         } else if (Upolyd && youmonst.data->mlet == S_CENTAUR) {
1768.             /* break_armor() pushes boots off for centaurs,
1769.                so don't let dowear() put them back on... */
1770.             if (noisy)
1771.                 pline("You have too many hooves to wear %s.",
1772.                       c_boots); /* makeplural(body_part(FOOT)) yields
1773.                                    "rear hooves" which sounds odd */
1774.             err++;
1775.         } else if (u.utrap
1776.                    && (u.utraptype == TT_BEARTRAP || u.utraptype == TT_INFLOOR
1777.                        || u.utraptype == TT_LAVA
1778.                        || u.utraptype == TT_BURIEDBALL)) {
1779.             if (u.utraptype == TT_BEARTRAP) {
1780.                 if (noisy)
1781.                     Your("%s is trapped!", body_part(FOOT));
1782.             } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) {
1783.                 if (noisy)
1784.                     Your("%s are stuck in the %s!",
1785.                          makeplural(body_part(FOOT)), surface(u.ux, u.uy));
1786.             } else { /*TT_BURIEDBALL*/
1787.                 if (noisy)
1788.                     Your("%s is attached to the buried ball!",
1789.                          body_part(LEG));
1790.             }
1791.             err++;
1792.         } else
1793.             *mask = W_ARMF;
1794.     } else if (is_gloves(otmp)) {
1795.         if (uarmg) {
1796.             if (noisy)
1797.                 already_wearing(c_gloves);
1798.             err++;
1799.         } else if (welded(uwep)) {
1800.             if (noisy)
1801.                 You("cannot wear gloves over your %s.",
1802.                     is_sword(uwep) ? c_sword : c_weapon);
1803.             err++;
1804.         } else if (Glib) {
1805.             /* prevent slippery bare fingers from transferring to
1806.                gloved fingers */
1807.             if (noisy)
1808.                 Your("%s are too slippery to pull on %s.",
1809.                      fingers_or_gloves(FALSE), gloves_simple_name(otmp));
1810.             err++;
1811.         } else
1812.             *mask = W_ARMG;
1813.     } else if (is_shirt(otmp)) {
1814.         if (uarm || uarmc || uarmu) {
1815.             if (uarmu) {
1816.                 if (noisy)
1817.                     already_wearing(an(c_shirt));
1818.             } else {
1819.                 if (noisy)
1820.                     You_cant("wear that over your %s.",
1821.                              (uarm && !uarmc) ? c_armor
1822.                                               : cloak_simple_name(uarmc));
1823.             }
1824.             err++;
1825.         } else
1826.             *mask = W_ARMU;
1827.     } else if (is_cloak(otmp)) {
1828.         if (uarmc) {
1829.             if (noisy)
1830.                 already_wearing(an(cloak_simple_name(uarmc)));
1831.             err++;
1832.         } else
1833.             *mask = W_ARMC;
1834.     } else if (is_suit(otmp)) {
1835.         if (uarmc) {
1836.             if (noisy)
1837.                 You("cannot wear armor over a %s.", cloak_simple_name(uarmc));
1838.             err++;
1839.         } else if (uarm) {
1840.             if (noisy)
1841.                 already_wearing("some armor");
1842.             err++;
1843.         } else
1844.             *mask = W_ARM;
1845.     } else {
1846.         /* getobj can't do this after setting its allow_all flag; that
1847.            happens if you have armor for slots that are covered up or
1848.            extra armor for slots that are filled */
1849.         if (noisy)
1850.             silly_thing("wear", otmp);
1851.         err++;
1852.     }
1853.     /* Unnecessary since now only weapons and special items like pick-axes get
1854.      * welded to your hand, not armor
1855.         if (welded(otmp)) {
1856.             if (!err++) {
1857.                 if (noisy) weldmsg(otmp);
1858.             }
1859.         }
1860.      */
1861.     return !err;
1862. }
1863. 
1864. STATIC_OVL int
1865. accessory_or_armor_on(obj)
1866. struct obj *obj;
1867. {
1868.     long mask = 0L;
1869.     boolean armor, ring, eyewear;
1870. 
1871.     if (obj->owornmask & (W_ACCESSORY | W_ARMOR)) {
1872.         already_wearing(c_that_);
1873.         return 0;
1874.     }
1875.     armor = (obj->oclass == ARMOR_CLASS);
1876.     ring = (obj->oclass == RING_CLASS || obj->otyp == MEAT_RING);
1877.     eyewear = (obj->otyp == BLINDFOLD || obj->otyp == TOWEL
1878.                || obj->otyp == LENSES);
1879.     /* checks which are performed prior to actually touching the item */
1880.     if (armor) {
1881.         if (!canwearobj(obj, &mask, TRUE))
1882.             return 0;
1883. 
1884.         if (obj->otyp == HELM_OF_OPPOSITE_ALIGNMENT
1885.             && qstart_level.dnum == u.uz.dnum) { /* in quest */
1886.             if (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL])
1887.                 You("narrowly avoid losing all chance at your goal.");
1888.             else /* converted */
1889.                 You("are suddenly overcome with shame and change your mind.");
1890.             u.ublessed = 0; /* lose your god's protection */
1891.             makeknown(obj->otyp);
1892.             context.botl = 1; /*for AC after zeroing u.ublessed */
1893.             return 1;
1894.         }
1895.     } else {
1896.         /* accessory */
1897.         if (ring) {
1898.             char answer, qbuf[QBUFSZ];
1899.             int res = 0;
1900. 
1901.             if (nolimbs(youmonst.data)) {
1902.                 You("cannot make the ring stick to your body.");
1903.                 return 0;
1904.             }
1905.             if (uleft && uright) {
1906.                 There("are no more %s%s to fill.",
1907.                       humanoid(youmonst.data) ? "ring-" : "",
1908.                       fingers_or_gloves(FALSE));
1909.                 return 0;
1910.             }
1911.             if (uleft) {
1912.                 mask = RIGHT_RING;
1913.             } else if (uright) {
1914.                 mask = LEFT_RING;
1915.             } else {
1916.                 do {
1917.                     Sprintf(qbuf, "Which %s%s, Right or Left?",
1918.                             humanoid(youmonst.data) ? "ring-" : "",
1919.                             body_part(FINGER));
1920.                     answer = yn_function(qbuf, "rl", '\0');
1921.                     switch (answer) {
1922.                     case '\0':
1923.                         return 0;
1924.                     case 'l':
1925.                     case 'L':
1926.                         mask = LEFT_RING;
1927.                         break;
1928.                     case 'r':
1929.                     case 'R':
1930.                         mask = RIGHT_RING;
1931.                         break;
1932.                     }
1933.                 } while (!mask);
1934.             }
1935.             if (uarmg && Glib) {
1936.                 Your(
1937.               "%s are too slippery to remove, so you cannot put on the ring.",
1938.                      gloves_simple_name(uarmg));
1939.                 return 1; /* always uses move */
1940.             }
1941.             if (uarmg && uarmg->cursed) {
1942.                 res = !uarmg->bknown;
1943.                 set_bknown(uarmg, 1);
1944.                 You("cannot remove your %s to put on the ring.", c_gloves);
1945.                 return res; /* uses move iff we learned gloves are cursed */
1946.             }
1947.             if (uwep) {
1948.                 res = !uwep->bknown; /* check this before calling welded() */
1949.                 if ((mask == RIGHT_RING || bimanual(uwep)) && welded(uwep)) {
1950.                     const char *hand = body_part(HAND);
1951. 
1952.                     /* welded will set bknown */
1953.                     if (bimanual(uwep))
1954.                         hand = makeplural(hand);
1955.                     You("cannot free your weapon %s to put on the ring.",
1956.                         hand);
1957.                     return res; /* uses move iff we learned weapon is cursed */
1958.                 }
1959.             }
1960.         } else if (obj->oclass == AMULET_CLASS) {
1961.             if (uamul) {
1962.                 already_wearing("an amulet");
1963.                 return 0;
1964.             }
1965.         } else if (eyewear) {
1966.             if (ublindf) {
1967.                 if (ublindf->otyp == TOWEL)
1968.                     Your("%s is already covered by a towel.",
1969.                          body_part(FACE));
1970.                 else if (ublindf->otyp == BLINDFOLD) {
1971.                     if (obj->otyp == LENSES)
1972.                         already_wearing2("lenses", "a blindfold");
1973.                     else
1974.                         already_wearing("a blindfold");
1975.                 } else if (ublindf->otyp == LENSES) {
1976.                     if (obj->otyp == BLINDFOLD)
1977.                         already_wearing2("a blindfold", "some lenses");
1978.                     else
1979.                         already_wearing("some lenses");
1980.                 } else {
1981.                     already_wearing(something); /* ??? */
1982.                 }
1983.                 return 0;
1984.             }
1985.         } else {
1986.             /* neither armor nor accessory */
1987.             You_cant("wear that!");
1988.             return 0;
1989.         }
1990.     }
1991. 
1992.     if (!retouch_object(&obj, FALSE))
1993.         return 1; /* costs a turn even though it didn't get worn */
1994. 
1995.     if (armor) {
1996.         int delay;
1997. 
1998.         /* if the armor is wielded, release it for wearing (won't be
1999.            welded even if cursed; that only happens for weapons/weptools) */
2000.         if (obj->owornmask & W_WEAPONS)
2001.             remove_worn_item(obj, FALSE);
2002.         /*
2003.          * Setting obj->known=1 is done because setworn() causes hero's AC
2004.          * to change so armor's +/- value is evident via the status line.
2005.          * We used to set it here because of that, but then it would stick
2006.          * if a nymph stole the armor before it was fully worn.  Delay it
2007.          * until the aftermv action.  The player may still know this armor's
2008.          * +/- amount if donning gets interrupted, but the hero won't.
2009.          *
2010.         obj->known = 1;
2011.          */
2012.         setworn(obj, mask);
2013.         /* if there's no delay, we'll execute 'aftermv' immediately */
2014.         if (obj == uarm)
2015.             afternmv = Armor_on;
2016.         else if (obj == uarmh)
2017.             afternmv = Helmet_on;
2018.         else if (obj == uarmg)
2019.             afternmv = Gloves_on;
2020.         else if (obj == uarmf)
2021.             afternmv = Boots_on;
2022.         else if (obj == uarms)
2023.             afternmv = Shield_on;
2024.         else if (obj == uarmc)
2025.             afternmv = Cloak_on;
2026.         else if (obj == uarmu)
2027.             afternmv = Shirt_on;
2028.         else
2029.             panic("wearing armor not worn as armor? [%08lx]", obj->owornmask);
2030. 
2031.         delay = -objects[obj->otyp].oc_delay;
2032.         if (delay) {
2033.             nomul(delay);
2034.             multi_reason = "dressing up";
2035.             nomovemsg = "You finish your dressing maneuver.";
2036.         } else {
2037.             unmul(""); /* call (*aftermv)(), clear it+nomovemsg+multi_reason */
2038.             on_msg(obj);
2039.         }
2040.         context.takeoff.mask = context.takeoff.what = 0L;
2041.     } else { /* not armor */
2042.         boolean give_feedback = FALSE;
2043. 
2044.         /* [releasing wielded accessory handled in Xxx_on()] */
2045.         if (ring) {
2046.             setworn(obj, mask);
2047.             Ring_on(obj);
2048.             give_feedback = TRUE;
2049.         } else if (obj->oclass == AMULET_CLASS) {
2050.             setworn(obj, W_AMUL);
2051.             Amulet_on();
2052.             /* no feedback here if amulet of change got used up */
2053.             give_feedback = (uamul != 0);
2054.         } else if (eyewear) {
2055.             /* setworn() handled by Blindf_on() */
2056.             Blindf_on(obj);
2057.             /* message handled by Blindf_on(); leave give_feedback False */
2058.         }
2059.         /* feedback for ring or for amulet other than 'change' */
2060.         if (give_feedback && is_worn(obj))
2061.             prinv((char *) 0, obj, 0L);
2062.     }
2063.     return 1;
2064. }
2065. 
2066. /* the 'W' command */
2067. int
2068. dowear()
2069. {
2070.     struct obj *otmp;
2071. 
2072.     /* cantweararm() checks for suits of armor, not what we want here;
2073.        verysmall() or nohands() checks for shields, gloves, etc... */
2074.     if (verysmall(youmonst.data) || nohands(youmonst.data)) {
2075.         pline("Don't even bother.");
2076.         return 0;
2077.     }
2078.     if (uarm && uarmu && uarmc && uarmh && uarms && uarmg && uarmf
2079.         && uleft && uright && uamul && ublindf) {
2080.         /* 'W' message doesn't mention accessories */
2081.         You("are already wearing a full complement of armor.");
2082.         return 0;
2083.     }
2084.     otmp = getobj(clothes, "wear");
2085.     return otmp ? accessory_or_armor_on(otmp) : 0;
2086. }
2087. 
2088. /* the 'P' command */
2089. int
2090. doputon()
2091. {
2092.     struct obj *otmp;
2093. 
2094.     if (uleft && uright && uamul && ublindf
2095.         && uarm && uarmu && uarmc && uarmh && uarms && uarmg && uarmf) {
2096.         /* 'P' message doesn't mention armor */
2097.         Your("%s%s are full, and you're already wearing an amulet and %s.",
2098.              humanoid(youmonst.data) ? "ring-" : "",
2099.              fingers_or_gloves(FALSE),
2100.              (ublindf->otyp == LENSES) ? "some lenses" : "a blindfold");
2101.         return 0;
2102.     }
2103.     otmp = getobj(accessories, "put on");
2104.     return otmp ? accessory_or_armor_on(otmp) : 0;
2105. }
2106. 
2107. /* calculate current armor class */
2108. void
2109. find_ac()
2110. {
2111.     int uac = mons[u.umonnum].ac; /* base armor class for current form */
2112. 
2113.     /* armor class from worn gear */
2114.     if (uarm)
2115.         uac -= ARM_BONUS(uarm);
2116.     if (uarmc)
2117.         uac -= ARM_BONUS(uarmc);
2118.     if (uarmh)
2119.         uac -= ARM_BONUS(uarmh);
2120.     if (uarmf)
2121.         uac -= ARM_BONUS(uarmf);
2122.     if (uarms)
2123.         uac -= ARM_BONUS(uarms);
2124.     if (uarmg)
2125.         uac -= ARM_BONUS(uarmg);
2126.     if (uarmu)
2127.         uac -= ARM_BONUS(uarmu);
2128.     if (uleft && uleft->otyp == RIN_PROTECTION)
2129.         uac -= uleft->spe;
2130.     if (uright && uright->otyp == RIN_PROTECTION)
2131.         uac -= uright->spe;
2132. 
2133.     /* armor class from other sources */
2134.     if (HProtection & INTRINSIC)
2135.         uac -= u.ublessed;
2136.     uac -= u.uspellprot;
2137. 
2138.     /* [The magic binary numbers 127 and -128 should be replaced with the
2139.      * mystic decimal numbers 99 and -99 which require no explanation to
2140.      * the uninitiated and would cap the width of a status line value at
2141.      * one less character.]
2142.      */
2143.     if (uac < -128)
2144.         uac = -128; /* u.uac is an schar */
2145.     else if (uac > 127)
2146.         uac = 127; /* for completeness */
2147. 
2148.     if (uac != u.uac) {
2149.         u.uac = uac;
2150.         context.botl = 1;
2151.     }
2152. }
2153. 
2154. void
2155. glibr()
2156. {
2157.     register struct obj *otmp;
2158.     int xfl = 0;
2159.     boolean leftfall, rightfall, wastwoweap = FALSE;
2160.     const char *otherwep = 0, *thiswep, *which, *hand;
2161. 
2162.     leftfall = (uleft && !uleft->cursed
2163.                 && (!uwep || !welded(uwep) || !bimanual(uwep)));
2164.     rightfall = (uright && !uright->cursed && (!welded(uwep)));
2165.     if (!uarmg && (leftfall || rightfall) && !nolimbs(youmonst.data)) {
2166.         /* changed so cursed rings don't fall off, GAN 10/30/86 */
2167.         Your("%s off your %s.",
2168.              (leftfall && rightfall) ? "rings slip" : "ring slips",
2169.              (leftfall && rightfall) ? fingers_or_gloves(FALSE)
2170.                                      : body_part(FINGER));
2171.         xfl++;
2172.         if (leftfall) {
2173.             otmp = uleft;
2174.             Ring_off(uleft);
2175.             dropx(otmp);
2176.         }
2177.         if (rightfall) {
2178.             otmp = uright;
2179.             Ring_off(uright);
2180.             dropx(otmp);
2181.         }
2182.     }
2183. 
2184.     otmp = uswapwep;
2185.     if (u.twoweap && otmp) {
2186.         /* secondary weapon doesn't need nearly as much handling as
2187.            primary; when in two-weapon mode, we know it's one-handed
2188.            with something else in the other hand and also that it's
2189.            a weapon or weptool rather than something unusual, plus
2190.            we don't need to compare its type with the primary */
2191.         otherwep = is_sword(otmp) ? c_sword : weapon_descr(otmp);
2192.         if (otmp->quan > 1L)
2193.             otherwep = makeplural(otherwep);
2194.         hand = body_part(HAND);
2195.         which = "left ";
2196.         Your("%s %s%s from your %s%s.", otherwep, xfl ? "also " : "",
2197.              otense(otmp, "slip"), which, hand);
2198.         xfl++;
2199.         wastwoweap = TRUE;
2200.         setuswapwep((struct obj *) 0); /* clears u.twoweap */
2201.         if (canletgo(otmp, ""))
2202.             dropx(otmp);
2203.     }
2204.     otmp = uwep;
2205.     if (otmp && !welded(otmp)) {
2206.         long savequan = otmp->quan;
2207. 
2208.         /* nice wording if both weapons are the same type */
2209.         thiswep = is_sword(otmp) ? c_sword : weapon_descr(otmp);
2210.         if (otherwep && strcmp(thiswep, makesingular(otherwep)))
2211.             otherwep = 0;
2212.         if (otmp->quan > 1L) {
2213.             /* most class names for unconventional wielded items
2214.                are ok, but if wielding multiple apples or rations
2215.                we don't want "your foods slip", so force non-corpse
2216.                food to be singular; skipping makeplural() isn't
2217.                enough--we need to fool otense() too */
2218.             if (!strcmp(thiswep, "food"))
2219.                 otmp->quan = 1L;
2220.             else
2221.                 thiswep = makeplural(thiswep);
2222.         }
2223.         hand = body_part(HAND);
2224.         which = "";
2225.         if (bimanual(otmp))
2226.             hand = makeplural(hand);
2227.         else if (wastwoweap)
2228.             which = "right "; /* preceding msg was about left */
2229.         pline("%s %s%s %s%s from your %s%s.",
2230.               !strncmp(thiswep, "corpse", 6) ? "The" : "Your",
2231.               otherwep ? "other " : "", thiswep, xfl ? "also " : "",
2232.               otense(otmp, "slip"), which, hand);
2233.         /* xfl++; */
2234.         otmp->quan = savequan;
2235.         setuwep((struct obj *) 0);
2236.         if (canletgo(otmp, ""))
2237.             dropx(otmp);
2238.     }
2239. }
2240. 
2241. struct obj *
2242. some_armor(victim)
2243. struct monst *victim;
2244. {
2245.     register struct obj *otmph, *otmp;
2246. 
2247.     otmph = (victim == &youmonst) ? uarmc : which_armor(victim, W_ARMC);
2248.     if (!otmph)
2249.         otmph = (victim == &youmonst) ? uarm : which_armor(victim, W_ARM);
2250.     if (!otmph)
2251.         otmph = (victim == &youmonst) ? uarmu : which_armor(victim, W_ARMU);
2252. 
2253.     otmp = (victim == &youmonst) ? uarmh : which_armor(victim, W_ARMH);
2254.     if (otmp && (!otmph || !rn2(4)))
2255.         otmph = otmp;
2256.     otmp = (victim == &youmonst) ? uarmg : which_armor(victim, W_ARMG);
2257.     if (otmp && (!otmph || !rn2(4)))
2258.         otmph = otmp;
2259.     otmp = (victim == &youmonst) ? uarmf : which_armor(victim, W_ARMF);
2260.     if (otmp && (!otmph || !rn2(4)))
2261.         otmph = otmp;
2262.     otmp = (victim == &youmonst) ? uarms : which_armor(victim, W_ARMS);
2263.     if (otmp && (!otmph || !rn2(4)))
2264.         otmph = otmp;
2265.     return otmph;
2266. }
2267. 
2268. /* used for praying to check and fix levitation trouble */
2269. struct obj *
2270. stuck_ring(ring, otyp)
2271. struct obj *ring;
2272. int otyp;
2273. {
2274.     if (ring != uleft && ring != uright) {
2275.         impossible("stuck_ring: neither left nor right?");
2276.         return (struct obj *) 0;
2277.     }
2278. 
2279.     if (ring && ring->otyp == otyp) {
2280.         /* reasons ring can't be removed match those checked by select_off();
2281.            limbless case has extra checks because ordinarily it's temporary */
2282.         if (nolimbs(youmonst.data) && uamul
2283.             && uamul->otyp == AMULET_OF_UNCHANGING && uamul->cursed)
2284.             return uamul;
2285.         if (welded(uwep) && (ring == uright || bimanual(uwep)))
2286.             return uwep;
2287.         if (uarmg && uarmg->cursed)
2288.             return uarmg;
2289.         if (ring->cursed)
2290.             return ring;
2291.         /* normally outermost layer is processed first, but slippery gloves
2292.            wears off quickly so uncurse ring itself before handling those */
2293.         if (uarmg && Glib)
2294.             return uarmg;
2295.     }
2296.     /* either no ring or not right type or nothing prevents its removal */
2297.     return (struct obj *) 0;
2298. }
2299. 
2300. /* also for praying; find worn item that confers "Unchanging" attribute */
2301. struct obj *
2302. unchanger()
2303. {
2304.     if (uamul && uamul->otyp == AMULET_OF_UNCHANGING)
2305.         return uamul;
2306.     return 0;
2307. }
2308. 
2309. STATIC_PTR
2310. int
2311. select_off(otmp)
2312. register struct obj *otmp;
2313. {
2314.     struct obj *why;
2315.     char buf[BUFSZ];
2316. 
2317.     if (!otmp)
2318.         return 0;
2319.     *buf = '\0'; /* lint suppression */
2320. 
2321.     /* special ring checks */
2322.     if (otmp == uright || otmp == uleft) {
2323.         struct obj glibdummy;
2324. 
2325.         if (nolimbs(youmonst.data)) {
2326.             pline_The("ring is stuck.");
2327.             return 0;
2328.         }
2329.         glibdummy = zeroobj;
2330.         why = 0; /* the item which prevents ring removal */
2331.         if (welded(uwep) && (otmp == uright || bimanual(uwep))) {
2332.             Sprintf(buf, "free a weapon %s", body_part(HAND));
2333.             why = uwep;
2334.         } else if (uarmg && (uarmg->cursed || Glib)) {
2335.             Sprintf(buf, "take off your %s%s",
2336.                     Glib ? "slippery " : "", gloves_simple_name(uarmg));
2337.             why = !Glib ? uarmg : &glibdummy;
2338.         }
2339.         if (why) {
2340.             You("cannot %s to remove the ring.", buf);
2341.             set_bknown(why, 1);
2342.             return 0;
2343.         }
2344.     }
2345.     /* special glove checks */
2346.     if (otmp == uarmg) {
2347.         if (welded(uwep)) {
2348.             You("are unable to take off your %s while wielding that %s.",
2349.                 c_gloves, is_sword(uwep) ? c_sword : c_weapon);
2350.             set_bknown(uwep, 1);
2351.             return 0;
2352.         } else if (Glib) {
2353.             pline("%s %s are too slippery to take off.",
2354.                   uarmg->unpaid ? "The" : "Your", /* simplified Shk_Your() */
2355.                   gloves_simple_name(uarmg));
2356.             return 0;
2357.         }
2358.     }
2359.     /* special boot checks */
2360.     if (otmp == uarmf) {
2361.         if (u.utrap && u.utraptype == TT_BEARTRAP) {
2362.             pline_The("bear trap prevents you from pulling your %s out.",
2363.                       body_part(FOOT));
2364.             return 0;
2365.         } else if (u.utrap && u.utraptype == TT_INFLOOR) {
2366.             You("are stuck in the %s, and cannot pull your %s out.",
2367.                 surface(u.ux, u.uy), makeplural(body_part(FOOT)));
2368.             return 0;
2369.         }
2370.     }
2371.     /* special suit and shirt checks */
2372.     if (otmp == uarm || otmp == uarmu) {
2373.         why = 0; /* the item which prevents disrobing */
2374.         if (uarmc && uarmc->cursed) {
2375.             Sprintf(buf, "remove your %s", cloak_simple_name(uarmc));
2376.             why = uarmc;
2377.         } else if (otmp == uarmu && uarm && uarm->cursed) {
2378.             Sprintf(buf, "remove your %s", c_suit);
2379.             why = uarm;
2380.         } else if (welded(uwep) && bimanual(uwep)) {
2381.             Sprintf(buf, "release your %s",
2382.                     is_sword(uwep) ? c_sword : (uwep->otyp == BATTLE_AXE)
2383.                                                    ? c_axe
2384.                                                    : c_weapon);
2385.             why = uwep;
2386.         }
2387.         if (why) {
2388.             You("cannot %s to take off %s.", buf, the(xname(otmp)));
2389.             set_bknown(why, 1);
2390.             return 0;
2391.         }
2392.     }
2393.     /* basic curse check */
2394.     if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) {
2395.         ; /* some items can be removed even when cursed */
2396.     } else {
2397.         /* otherwise, this is fundamental */
2398.         if (cursed(otmp))
2399.             return 0;
2400.     }
2401. 
2402.     if (otmp == uarm)
2403.         context.takeoff.mask |= WORN_ARMOR;
2404.     else if (otmp == uarmc)
2405.         context.takeoff.mask |= WORN_CLOAK;
2406.     else if (otmp == uarmf)
2407.         context.takeoff.mask |= WORN_BOOTS;
2408.     else if (otmp == uarmg)
2409.         context.takeoff.mask |= WORN_GLOVES;
2410.     else if (otmp == uarmh)
2411.         context.takeoff.mask |= WORN_HELMET;
2412.     else if (otmp == uarms)
2413.         context.takeoff.mask |= WORN_SHIELD;
2414.     else if (otmp == uarmu)
2415.         context.takeoff.mask |= WORN_SHIRT;
2416.     else if (otmp == uleft)
2417.         context.takeoff.mask |= LEFT_RING;
2418.     else if (otmp == uright)
2419.         context.takeoff.mask |= RIGHT_RING;
2420.     else if (otmp == uamul)
2421.         context.takeoff.mask |= WORN_AMUL;
2422.     else if (otmp == ublindf)
2423.         context.takeoff.mask |= WORN_BLINDF;
2424.     else if (otmp == uwep)
2425.         context.takeoff.mask |= W_WEP;
2426.     else if (otmp == uswapwep)
2427.         context.takeoff.mask |= W_SWAPWEP;
2428.     else if (otmp == uquiver)
2429.         context.takeoff.mask |= W_QUIVER;
2430. 
2431.     else
2432.         impossible("select_off: %s???", doname(otmp));
2433. 
2434.     return 0;
2435. }
2436. 
2437. STATIC_OVL struct obj *
2438. do_takeoff()
2439. {
2440.     struct obj *otmp = (struct obj *) 0;
2441.     struct takeoff_info *doff = &context.takeoff;
2442. 
2443.     context.takeoff.mask |= I_SPECIAL; /* set flag for cancel_doff() */
2444.     if (doff->what == W_WEP) {
2445.         if (!cursed(uwep)) {
2446.             setuwep((struct obj *) 0);
2447.             You("are empty %s.", body_part(HANDED));
2448.             u.twoweap = FALSE;
2449.         }
2450.     } else if (doff->what == W_SWAPWEP) {
2451.         setuswapwep((struct obj *) 0);
2452.         You("no longer have a second weapon readied.");
2453.         u.twoweap = FALSE;
2454.     } else if (doff->what == W_QUIVER) {
2455.         setuqwep((struct obj *) 0);
2456.         You("no longer have ammunition readied.");
2457.     } else if (doff->what == WORN_ARMOR) {
2458.         otmp = uarm;
2459.         if (!cursed(otmp))
2460.             (void) Armor_off();
2461.     } else if (doff->what == WORN_CLOAK) {
2462.         otmp = uarmc;
2463.         if (!cursed(otmp))
2464.             (void) Cloak_off();
2465.     } else if (doff->what == WORN_BOOTS) {
2466.         otmp = uarmf;
2467.         if (!cursed(otmp))
2468.             (void) Boots_off();
2469.     } else if (doff->what == WORN_GLOVES) {
2470.         otmp = uarmg;
2471.         if (!cursed(otmp))
2472.             (void) Gloves_off();
2473.     } else if (doff->what == WORN_HELMET) {
2474.         otmp = uarmh;
2475.         if (!cursed(otmp))
2476.             (void) Helmet_off();
2477.     } else if (doff->what == WORN_SHIELD) {
2478.         otmp = uarms;
2479.         if (!cursed(otmp))
2480.             (void) Shield_off();
2481.     } else if (doff->what == WORN_SHIRT) {
2482.         otmp = uarmu;
2483.         if (!cursed(otmp))
2484.             (void) Shirt_off();
2485.     } else if (doff->what == WORN_AMUL) {
2486.         otmp = uamul;
2487.         if (!cursed(otmp))
2488.             Amulet_off();
2489.     } else if (doff->what == LEFT_RING) {
2490.         otmp = uleft;
2491.         if (!cursed(otmp))
2492.             Ring_off(uleft);
2493.     } else if (doff->what == RIGHT_RING) {
2494.         otmp = uright;
2495.         if (!cursed(otmp))
2496.             Ring_off(uright);
2497.     } else if (doff->what == WORN_BLINDF) {
2498.         if (!cursed(ublindf))
2499.             Blindf_off(ublindf);
2500.     } else {
2501.         impossible("do_takeoff: taking off %lx", doff->what);
2502.     }
2503.     context.takeoff.mask &= ~I_SPECIAL; /* clear cancel_doff() flag */
2504. 
2505.     return otmp;
2506. }
2507. 
2508. /* occupation callback for 'A' */
2509. STATIC_PTR
2510. int
2511. take_off(VOID_ARGS)
2512. {
2513.     register int i;
2514.     register struct obj *otmp;
2515.     struct takeoff_info *doff = &context.takeoff;
2516. 
2517.     if (doff->what) {
2518.         if (doff->delay > 0) {
2519.             doff->delay--;
2520.             return 1; /* still busy */
2521.         }
2522.         if ((otmp = do_takeoff()) != 0)
2523.             off_msg(otmp);
2524.         doff->mask &= ~doff->what;
2525.         doff->what = 0L;
2526.     }
2527. 
2528.     for (i = 0; takeoff_order[i]; i++)
2529.         if (doff->mask & takeoff_order[i]) {
2530.             doff->what = takeoff_order[i];
2531.             break;
2532.         }
2533. 
2534.     otmp = (struct obj *) 0;
2535.     doff->delay = 0;
2536. 
2537.     if (doff->what == 0L) {
2538.         You("finish %s.", doff->disrobing);
2539.         return 0;
2540.     } else if (doff->what == W_WEP) {
2541.         doff->delay = 1;
2542.     } else if (doff->what == W_SWAPWEP) {
2543.         doff->delay = 1;
2544.     } else if (doff->what == W_QUIVER) {
2545.         doff->delay = 1;
2546.     } else if (doff->what == WORN_ARMOR) {
2547.         otmp = uarm;
2548.         /* If a cloak is being worn, add the time to take it off and put
2549.          * it back on again.  Kludge alert! since that time is 0 for all
2550.          * known cloaks, add 1 so that it actually matters...
2551.          */
2552.         if (uarmc)
2553.             doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1;
2554.     } else if (doff->what == WORN_CLOAK) {
2555.         otmp = uarmc;
2556.     } else if (doff->what == WORN_BOOTS) {
2557.         otmp = uarmf;
2558.     } else if (doff->what == WORN_GLOVES) {
2559.         otmp = uarmg;
2560.     } else if (doff->what == WORN_HELMET) {
2561.         otmp = uarmh;
2562.     } else if (doff->what == WORN_SHIELD) {
2563.         otmp = uarms;
2564.     } else if (doff->what == WORN_SHIRT) {
2565.         otmp = uarmu;
2566.         /* add the time to take off and put back on armor and/or cloak */
2567.         if (uarm)
2568.             doff->delay += 2 * objects[uarm->otyp].oc_delay;
2569.         if (uarmc)
2570.             doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1;
2571.     } else if (doff->what == WORN_AMUL) {
2572.         doff->delay = 1;
2573.     } else if (doff->what == LEFT_RING) {
2574.         doff->delay = 1;
2575.     } else if (doff->what == RIGHT_RING) {
2576.         doff->delay = 1;
2577.     } else if (doff->what == WORN_BLINDF) {
2578.         /* [this used to be 2, but 'R' (and 'T') only require 1 turn to
2579.            remove a blindfold, so 'A' shouldn't have been requiring 2] */
2580.         doff->delay = 1;
2581.     } else {
2582.         impossible("take_off: taking off %lx", doff->what);
2583.         return 0; /* force done */
2584.     }
2585. 
2586.     if (otmp)
2587.         doff->delay += objects[otmp->otyp].oc_delay;
2588. 
2589.     /* Since setting the occupation now starts the counter next move, that
2590.      * would always produce a delay 1 too big per item unless we subtract
2591.      * 1 here to account for it.
2592.      */
2593.     if (doff->delay > 0)
2594.         doff->delay--;
2595. 
2596.     set_occupation(take_off, doff->disrobing, 0);
2597.     return 1; /* get busy */
2598. }
2599. 
2600. /* clear saved context to avoid inappropriate resumption of interrupted 'A' */
2601. void
2602. reset_remarm()
2603. {
2604.     context.takeoff.what = context.takeoff.mask = 0L;
2605.     context.takeoff.disrobing[0] = '\0';
2606. }
2607. 
2608. /* the 'A' command -- remove multiple worn items */
2609. int
2610. doddoremarm()
2611. {
2612.     int result = 0;
2613. 
2614.     if (context.takeoff.what || context.takeoff.mask) {
2615.         You("continue %s.", context.takeoff.disrobing);
2616.         set_occupation(take_off, context.takeoff.disrobing, 0);
2617.         return 0;
2618.     } else if (!uwep && !uswapwep && !uquiver && !uamul && !ublindf && !uleft
2619.                && !uright && !wearing_armor()) {
2620.         You("are not wearing anything.");
2621.         return 0;
2622.     }
2623. 
2624.     add_valid_menu_class(0); /* reset */
2625.     if (flags.menu_style != MENU_TRADITIONAL
2626.         || (result = ggetobj("take off", select_off, 0, FALSE,
2627.                              (unsigned *) 0)) < -1)
2628.         result = menu_remarm(result);
2629. 
2630.     if (context.takeoff.mask) {
2631.         /* default activity for armor and/or accessories,
2632.            possibly combined with weapons */
2633.         (void) strncpy(context.takeoff.disrobing, "disrobing", CONTEXTVERBSZ);
2634.         /* specific activity when handling weapons only */
2635.         if (!(context.takeoff.mask & ~W_WEAPONS))
2636.             (void) strncpy(context.takeoff.disrobing, "disarming",
2637.                            CONTEXTVERBSZ);
2638.         (void) take_off();
2639.     }
2640.     /* The time to perform the command is already completely accounted for
2641.      * in take_off(); if we return 1, that would add an extra turn to each
2642.      * disrobe.
2643.      */
2644.     return 0;
2645. }
2646. 
2647. STATIC_OVL int
2648. menu_remarm(retry)
2649. int retry;
2650. {
2651.     int n, i = 0;
2652.     menu_item *pick_list;
2653.     boolean all_worn_categories = TRUE;
2654. 
2655.     if (retry) {
2656.         all_worn_categories = (retry == -2);
2657.     } else if (flags.menu_style == MENU_FULL) {
2658.         all_worn_categories = FALSE;
2659.         n = query_category("What type of things do you want to take off?",
2660.                            invent, (WORN_TYPES | ALL_TYPES
2661.                                     | UNPAID_TYPES | BUCX_TYPES),
2662.                            &pick_list, PICK_ANY);
2663.         if (!n)
2664.             return 0;
2665.         for (i = 0; i < n; i++) {
2666.             if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
2667.                 all_worn_categories = TRUE;
2668.             else
2669.                 add_valid_menu_class(pick_list[i].item.a_int);
2670.         }
2671.         free((genericptr_t) pick_list);
2672.     } else if (flags.menu_style == MENU_COMBINATION) {
2673.         unsigned ggofeedback = 0;
2674. 
2675.         i = ggetobj("take off", select_off, 0, TRUE, &ggofeedback);
2676.         if (ggofeedback & ALL_FINISHED)
2677.             return 0;
2678.         all_worn_categories = (i == -2);
2679.     }
2680.     if (menu_class_present('u')
2681.         || menu_class_present('B') || menu_class_present('U')
2682.         || menu_class_present('C') || menu_class_present('X'))
2683.         all_worn_categories = FALSE;
2684. 
2685.     n = query_objlist("What do you want to take off?", &invent,
2686.                       (SIGNAL_NOMENU | USE_INVLET | INVORDER_SORT),
2687.                       &pick_list, PICK_ANY,
2688.                       all_worn_categories ? is_worn : is_worn_by_type);
2689.     if (n > 0) {
2690.         for (i = 0; i < n; i++)
2691.             (void) select_off(pick_list[i].item.a_obj);
2692.         free((genericptr_t) pick_list);
2693.     } else if (n < 0 && flags.menu_style != MENU_COMBINATION) {
2694.         There("is nothing else you can remove or unwield.");
2695.     }
2696.     return 0;
2697. }
2698. 
2699. /* hit by destroy armor scroll/black dragon breath/monster spell */
2700. int
2701. destroy_arm(atmp)
2702. register struct obj *atmp;
2703. {
2704.     register struct obj *otmp;
2705. #define DESTROY_ARM(o)                            \
2706.     ((otmp = (o)) != 0 && (!atmp || atmp == otmp) \
2707.              && (!obj_resists(otmp, 0, 90))       \
2708.          ? (otmp->in_use = TRUE)                  \
2709.          : FALSE)
2710. 
2711.     if (DESTROY_ARM(uarmc)) {
2712.         if (donning(otmp))
2713.             cancel_don();
2714.         Your("%s crumbles and turns to dust!", cloak_simple_name(uarmc));
2715.         (void) Cloak_off();
2716.         useup(otmp);
2717.     } else if (DESTROY_ARM(uarm)) {
2718.         if (donning(otmp))
2719.             cancel_don();
2720.         Your("armor turns to dust and falls to the %s!", surface(u.ux, u.uy));
2721.         (void) Armor_gone();
2722.         useup(otmp);
2723.     } else if (DESTROY_ARM(uarmu)) {
2724.         if (donning(otmp))
2725.             cancel_don();
2726.         Your("shirt crumbles into tiny threads and falls apart!");
2727.         (void) Shirt_off();
2728.         useup(otmp);
2729.     } else if (DESTROY_ARM(uarmh)) {
2730.         if (donning(otmp))
2731.             cancel_don();
2732.         Your("%s turns to dust and is blown away!", helm_simple_name(uarmh));
2733.         (void) Helmet_off();
2734.         useup(otmp);
2735.     } else if (DESTROY_ARM(uarmg)) {
2736.         if (donning(otmp))
2737.             cancel_don();
2738.         Your("gloves vanish!");
2739.         (void) Gloves_off();
2740.         useup(otmp);
2741.         selftouch("You");
2742.     } else if (DESTROY_ARM(uarmf)) {
2743.         if (donning(otmp))
2744.             cancel_don();
2745.         Your("boots disintegrate!");
2746.         (void) Boots_off();
2747.         useup(otmp);
2748.     } else if (DESTROY_ARM(uarms)) {
2749.         if (donning(otmp))
2750.             cancel_don();
2751.         Your("shield crumbles away!");
2752.         (void) Shield_off();
2753.         useup(otmp);
2754.     } else {
2755.         return 0; /* could not destroy anything */
2756.     }
2757. 
2758. #undef DESTROY_ARM
2759.     stop_occupation();
2760.     return 1;
2761. }
2762. 
2763. void
2764. adj_abon(otmp, delta)
2765. register struct obj *otmp;
2766. register schar delta;
2767. {
2768.     if (uarmg && uarmg == otmp && otmp->otyp == GAUNTLETS_OF_DEXTERITY) {
2769.         if (delta) {
2770.             makeknown(uarmg->otyp);
2771.             ABON(A_DEX) += (delta);
2772.         }
2773.         context.botl = 1;
2774.     }
2775.     if (uarmh && uarmh == otmp && otmp->otyp == HELM_OF_BRILLIANCE) {
2776.         if (delta) {
2777.             makeknown(uarmh->otyp);
2778.             ABON(A_INT) += (delta);
2779.             ABON(A_WIS) += (delta);
2780.         }
2781.         context.botl = 1;
2782.     }
2783. }
2784. 
2785. /* decide whether a worn item is covered up by some other worn item,
2786.    used for dipping into liquid and applying grease;
2787.    some criteria are different than select_off()'s */
2788. boolean
2789. inaccessible_equipment(obj, verb, only_if_known_cursed)
2790. struct obj *obj;
2791. const char *verb; /* "dip" or "grease", or null to avoid messages */
2792. boolean only_if_known_cursed; /* ignore covering unless known to be cursed */
2793. {
2794.     static NEARDATA const char need_to_take_off_outer_armor[] =
2795.         "need to take off %s to %s %s.";
2796.     char buf[BUFSZ];
2797.     boolean anycovering = !only_if_known_cursed; /* more comprehensible... */
2798. #define BLOCKSACCESS(x) (anycovering || ((x)->cursed && (x)->bknown))
2799. 
2800.     if (!obj || !obj->owornmask)
2801.         return FALSE; /* not inaccessible */
2802. 
2803.     /* check for suit covered by cloak */
2804.     if (obj == uarm && uarmc && BLOCKSACCESS(uarmc)) {
2805.         if (verb) {
2806.             Strcpy(buf, yname(uarmc));
2807.             You(need_to_take_off_outer_armor, buf, verb, yname(obj));
2808.         }
2809.         return TRUE;
2810.     }
2811.     /* check for shirt covered by suit and/or cloak */
2812.     if (obj == uarmu
2813.         && ((uarm && BLOCKSACCESS(uarm)) || (uarmc && BLOCKSACCESS(uarmc)))) {
2814.         if (verb) {
2815.             char cloaktmp[QBUFSZ], suittmp[QBUFSZ];
2816.             /* if sameprefix, use yname and xname to get "your cloak and suit"
2817.                or "Manlobbi's cloak and suit"; otherwise, use yname and yname
2818.                to get "your cloak and Manlobbi's suit" or vice versa */
2819.             boolean sameprefix = (uarm && uarmc
2820.                                   && !strcmp(shk_your(cloaktmp, uarmc),
2821.                                              shk_your(suittmp, uarm)));
2822. 
2823.             *buf = '\0';
2824.             if (uarmc)
2825.                 Strcat(buf, yname(uarmc));
2826.             if (uarm && uarmc)
2827.                 Strcat(buf, " and ");
2828.             if (uarm)
2829.                 Strcat(buf, sameprefix ? xname(uarm) : yname(uarm));
2830.             You(need_to_take_off_outer_armor, buf, verb, yname(obj));
2831.         }
2832.         return TRUE;
2833.     }
2834.     /* check for ring covered by gloves */
2835.     if ((obj == uleft || obj == uright) && uarmg && BLOCKSACCESS(uarmg)) {
2836.         if (verb) {
2837.             Strcpy(buf, yname(uarmg));
2838.             You(need_to_take_off_outer_armor, buf, verb, yname(obj));
2839.         }
2840.         return TRUE;
2841.     }
2842.     /* item is not inaccessible */
2843.     return FALSE;
2844. }
2845. 
2846. /*do_wear.c*/