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