home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / do_wear.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  37.8 KB  |  1,671 lines  |  [TEXT/R*ch]

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