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