home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / HACKSRC.ZIP / DO_WEAR.C < prev    next >
C/C++ Source or Header  |  1985-10-16  |  8KB  |  345 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* do_wear.c - version 1.0.3 */
  3.  
  4. #include <stdio.h>
  5. #include "hack.h"
  6. extern char *nomovemsg;
  7. extern char quitchars[];
  8. extern char *Doname();
  9.  
  10. off_msg(otmp) register struct obj *otmp; {
  11.     pline("You were wearing %s.", doname(otmp));
  12. }
  13.  
  14. doremarm() {
  15.     register struct obj *otmp;
  16.     if(!uarm && !uarmh && !uarms && !uarmg) {
  17.         pline("Not wearing any armor.");
  18.         return(0);
  19.     }
  20.     otmp = (!uarmh && !uarms && !uarmg) ? uarm :
  21.         (!uarms && !uarm && !uarmg) ? uarmh :
  22.         (!uarmh && !uarm && !uarmg) ? uarms :
  23.         (!uarmh && !uarm && !uarms) ? uarmg :
  24.         getobj("[", "take off");
  25.     if(!otmp) return(0);
  26.     if(!(otmp->owornmask & (W_ARMOR - W_ARM2))) {
  27.         pline("You can't take that off.");
  28.         return(0);
  29.     }
  30.     if( otmp == uarmg && uwep && uwep->cursed ) {    /* myers@uwmacc */
  31.  pline("You seem not able to take off the gloves while holding your weapon.");
  32.         return(0);
  33.     }
  34.     (void) armoroff(otmp);
  35.     return(1);
  36. }
  37.  
  38. doremring() {
  39.     if(!uleft && !uright){
  40.         pline("Not wearing any ring.");
  41.         return(0);
  42.     }
  43.     if(!uleft)
  44.         return(dorr(uright));
  45.     if(!uright)
  46.         return(dorr(uleft));
  47.     if(uleft && uright) while(1) {
  48.         char answer;
  49.  
  50.         pline("What ring, Right or Left? [ rl?]");
  51.         if(index(quitchars, (answer = readchar())))
  52.             return(0);
  53.         switch(answer) {
  54.         case 'l':
  55.         case 'L':
  56.             return(dorr(uleft));
  57.         case 'r':
  58.         case 'R':
  59.             return(dorr(uright));
  60.         case '?':
  61.             (void) doprring();
  62.             /* might look at morc here %% */
  63.         }
  64.     }
  65.     /* NOTREACHED */
  66. #ifdef lint
  67.     return(0);
  68. #endif lint
  69. }
  70.  
  71. dorr(otmp) register struct obj *otmp; {
  72.     if(cursed(otmp)) return(0);
  73.     ringoff(otmp);
  74.     off_msg(otmp);
  75.     return(1);
  76. }
  77.  
  78. cursed(otmp) register struct obj *otmp; {
  79.     if(otmp->cursed){
  80.         pline("You can't. It appears to be cursed.");
  81.         return(1);
  82.     }
  83.     return(0);
  84. }
  85.  
  86. armoroff(otmp) register struct obj *otmp; {
  87. register int delay = -objects[otmp->otyp].oc_delay;
  88.     if(cursed(otmp)) return(0);
  89.     setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
  90.     if(delay) {
  91.         nomul(delay);
  92.         switch(otmp->otyp) {
  93.         case HELMET:
  94.             nomovemsg = "You finished taking off your helmet.";
  95.             break;
  96.         case PAIR_OF_GLOVES:
  97.             nomovemsg = "You finished taking off your gloves";
  98.             break;
  99.         default:
  100.             nomovemsg = "You finished taking off your suit.";
  101.         }
  102.     } else {
  103.         off_msg(otmp);
  104.     }
  105.     return(1);
  106. }
  107.  
  108. doweararm() {
  109.     register struct obj *otmp;
  110.     register int delay;
  111.     register int err = 0;
  112.     long mask = 0;
  113.  
  114.     otmp = getobj("[", "wear");
  115.     if(!otmp) return(0);
  116.     if(otmp->owornmask & W_ARMOR) {
  117.         pline("You are already wearing that!");
  118.         return(0);
  119.     }
  120.     if(otmp->otyp == HELMET){
  121.         if(uarmh) {
  122.             pline("You are already wearing a helmet.");
  123.             err++;
  124.         } else
  125.             mask = W_ARMH;
  126.     } else if(otmp->otyp == SHIELD){
  127.         if(uarms) pline("You are already wearing a shield."), err++;
  128.         if(uwep && uwep->otyp == TWO_HANDED_SWORD)
  129.     pline("You cannot wear a shield and wield a two-handed sword."), err++;
  130.         if(!err) mask = W_ARMS;
  131.     } else if(otmp->otyp == PAIR_OF_GLOVES) {
  132.         if(uarmg) {
  133.             pline("You are already wearing gloves.");
  134.             err++;
  135.         } else
  136.         if(uwep && uwep->cursed) {
  137.             pline("You cannot wear gloves over your weapon.");
  138.             err++;
  139.         } else
  140.             mask = W_ARMG;
  141.     } else {
  142.         if(uarm) {
  143.             if(otmp->otyp != ELVEN_CLOAK || uarm2) {
  144.                 pline("You are already wearing some armor.");
  145.                 err++;
  146.             }
  147.         }
  148.         if(!err) mask = W_ARM;
  149.     }
  150.     if(otmp == uwep && uwep->cursed) {
  151.         if(!err++)
  152.             pline("%s is welded to your hand.", Doname(uwep));
  153.     }
  154.     if(err) return(0);
  155.     setworn(otmp, mask);
  156.     if(otmp == uwep)
  157.         setuwep((struct obj *) 0);
  158.     delay = -objects[otmp->otyp].oc_delay;
  159.     if(delay){
  160.         nomul(delay);
  161.         nomovemsg = "You finished your dressing manoeuvre.";
  162.     }
  163.     otmp->known = 1;
  164.     return(1);
  165. }
  166.  
  167. dowearring() {
  168.     register struct obj *otmp;
  169.     long mask = 0;
  170.     long oldprop;
  171.  
  172.     if(uleft && uright){
  173.         pline("There are no more ring-fingers to fill.");
  174.         return(0);
  175.     }
  176.     otmp = getobj("=", "wear");
  177.     if(!otmp) return(0);
  178.     if(otmp->owornmask & W_RING) {
  179.         pline("You are already wearing that!");
  180.         return(0);
  181.     }
  182.     if(otmp == uleft || otmp == uright) {
  183.         pline("You are already wearing that.");
  184.         return(0);
  185.     }
  186.     if(otmp == uwep && uwep->cursed) {
  187.         pline("%s is welded to your hand.", Doname(uwep));
  188.         return(0);
  189.     }
  190.     if(uleft) mask = RIGHT_RING;
  191.     else if(uright) mask = LEFT_RING;
  192.     else do {
  193.         char answer;
  194.  
  195.          pline("What ring-finger, Right or Left? ");
  196.         if(index(quitchars, (answer = readchar())))
  197.             return(0);
  198.         switch(answer){
  199.         case 'l':
  200.         case 'L':
  201.             mask = LEFT_RING;
  202.             break;
  203.         case 'r':
  204.         case 'R':
  205.             mask = RIGHT_RING;
  206.             break;
  207.         }
  208.     } while(!mask);
  209.     setworn(otmp, mask);
  210.     if(otmp == uwep)
  211.         setuwep((struct obj *) 0);
  212.     oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
  213.     u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
  214.     switch(otmp->otyp){
  215.     case RIN_LEVITATION:
  216.         if(!oldprop) float_up();
  217.         break;
  218.     case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
  219.         rescham();
  220.         break;
  221.     case RIN_GAIN_STRENGTH:
  222.         u.ustr += otmp->spe;
  223.         u.ustrmax += otmp->spe;
  224.         if(u.ustr > 118) u.ustr = 118;
  225.         if(u.ustrmax > 118) u.ustrmax = 118;
  226.         flags.botl = 1;
  227.         break;
  228.     case RIN_INCREASE_DAMAGE:
  229.         u.udaminc += otmp->spe;
  230.         break;
  231.     }
  232.     prinv(otmp);
  233.     return(1);
  234. }
  235.  
  236. ringoff(obj)
  237. register struct obj *obj;
  238. {
  239. register long mask;
  240.     mask = obj->owornmask & W_RING;
  241.     setworn((struct obj *) 0, obj->owornmask);
  242.     if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
  243.         impossible("Strange... I didnt know you had that ring.");
  244.     u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
  245.     switch(obj->otyp) {
  246.     case RIN_FIRE_RESISTANCE:
  247.         /* Bad luck if the player is in hell... --jgm */
  248.         if (!Fire_resistance && dlevel >= 30) {
  249.             pline("The flames of Hell burn you to a crisp.");
  250.             killer = "stupidity in hell";
  251.             done("burned");
  252.         }
  253.         break;
  254.     case RIN_LEVITATION:
  255.         if(!Levitation) {    /* no longer floating */
  256.             float_down();
  257.         }
  258.         break;
  259.     case RIN_GAIN_STRENGTH:
  260.         u.ustr -= obj->spe;
  261.         u.ustrmax -= obj->spe;
  262.         if(u.ustr > 118) u.ustr = 118;
  263.         if(u.ustrmax > 118) u.ustrmax = 118;
  264.         flags.botl = 1;
  265.         break;
  266.     case RIN_INCREASE_DAMAGE:
  267.         u.udaminc -= obj->spe;
  268.         break;
  269. #ifdef DGK
  270.     case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
  271.         /* If you're no longer protected, let the chameleons
  272.          * change shape again -dgk
  273.          */
  274.         restartcham();
  275.         break;
  276. #endif DGK
  277.     }
  278. }
  279.  
  280. find_ac(){
  281. register int uac = 10;
  282.     if(uarm) uac -= ARM_BONUS(uarm);
  283.     if(uarm2) uac -= ARM_BONUS(uarm2);
  284.     if(uarmh) uac -= ARM_BONUS(uarmh);
  285.     if(uarms) uac -= ARM_BONUS(uarms);
  286.     if(uarmg) uac -= ARM_BONUS(uarmg);
  287.     if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe;
  288.     if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe;
  289.     if(uac != u.uac){
  290.         u.uac = uac;
  291.         flags.botl = 1;
  292.     }
  293. }
  294.  
  295. glibr(){
  296. register struct obj *otmp;
  297. int xfl = 0;
  298.     if(!uarmg) if(uleft || uright) {
  299.         /* Note: at present also cursed rings fall off */
  300.         pline("Your %s off your fingers.",
  301.             (uleft && uright) ? "rings slip" : "ring slips");
  302.         xfl++;
  303.         if((otmp = uleft) != Null(obj)){
  304.             ringoff(uleft);
  305.             dropx(otmp);
  306.         }
  307.         if((otmp = uright) != Null(obj)){
  308.             ringoff(uright);
  309.             dropx(otmp);
  310.         }
  311.     }
  312.     if((otmp = uwep) != Null(obj)){
  313.         /* Note: at present also cursed weapons fall */
  314.         setuwep((struct obj *) 0);
  315.         dropx(otmp);
  316.         pline("Your weapon %sslips from your hands.",
  317.             xfl ? "also " : "");
  318.     }
  319. }
  320.  
  321. struct obj *
  322. some_armor(){
  323. register struct obj *otmph = uarm;
  324.     if(uarmh && (!otmph || !rn2(4))) otmph = uarmh;
  325.     if(uarmg && (!otmph || !rn2(4))) otmph = uarmg;
  326.     if(uarms && (!otmph || !rn2(4))) otmph = uarms;
  327.     return(otmph);
  328. }
  329.  
  330. corrode_armor(){
  331. register struct obj *otmph = some_armor();
  332.     if(otmph){
  333.         if(otmph->rustfree ||
  334.            otmph->otyp == ELVEN_CLOAK ||
  335.            otmph->otyp == LEATHER_ARMOR ||
  336.            otmph->otyp == STUDDED_LEATHER_ARMOR) {
  337.             pline("Your %s not affected!",
  338.                 aobjnam(otmph, "are"));
  339.             return;
  340.         }
  341.         pline("Your %s!", aobjnam(otmph, "corrode"));
  342.         otmph->spe--;
  343.     }
  344. }
  345.