Source:NetHack 5.0.0/src/do wear.c
Jump to navigation
Jump to search
Below is the full text to do_wear.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/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 5.0 do_wear.c $NHDT-Date: 1737343372 2025/01/19 19:22:52 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.201 $ */ 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. staticfn void on_msg(struct obj *); 24. staticfn void toggle_stealth(struct obj *, long, boolean); 25. staticfn int Armor_on(void); 26. /* int Boots_on(void); -- moved to extern.h */ 27. staticfn int Cloak_on(void); 28. staticfn int Helmet_on(void); 29. staticfn int Gloves_on(void); 30. staticfn int Shield_on(void); 31. staticfn int Shirt_on(void); 32. staticfn void dragon_armor_handling(struct obj *, boolean, boolean); 33. staticfn void Amulet_on(struct obj *) NONNULLARG1; 34. staticfn void learnring(struct obj *, boolean); 35. staticfn void adjust_attrib(struct obj *, int, int); 36. staticfn void Ring_off_or_gone(struct obj *, boolean); 37. staticfn int select_off(struct obj *); 38. staticfn struct obj *do_takeoff(void); 39. staticfn int take_off(void); 40. staticfn int menu_remarm(int); 41. staticfn void wornarm_destroyed(struct obj *); 42. staticfn void count_worn_stuff(struct obj **, boolean); 43. staticfn int armor_or_accessory_off(struct obj *); 44. staticfn int accessory_or_armor_on(struct obj *); 45. staticfn void already_wearing(const char *); 46. staticfn void already_wearing2(const char *, const char *); 47. staticfn int equip_ok(struct obj *, boolean, boolean); 48. staticfn int puton_ok(struct obj *); 49. staticfn int remove_ok(struct obj *); 50. staticfn int wear_ok(struct obj *); 51. staticfn int takeoff_ok(struct obj *); 52. /* maybe_destroy_armor() may return NULL */ 53. staticfn struct obj *maybe_destroy_armor(struct obj *, struct obj *, 54. boolean *) NONNULLARG3; 55. staticfn int obj_erode_type(struct obj *) NONNULLARG1; 56. staticfn boolean better_not_take_that_off(struct obj *) NONNULLARG1; 57. 58. /* plural "fingers" or optionally "gloves" */ 59. const char * 60. fingers_or_gloves(boolean check_gloves) 61. { 62. return ((check_gloves && uarmg) 63. ? gloves_simple_name(uarmg) /* "gloves" or "gauntlets" */ 64. : makeplural(body_part(FINGER))); /* "fingers" */ 65. } 66. 67. void 68. off_msg(struct obj *otmp) 69. { 70. if (flags.verbose) 71. You("were wearing %s.", doname(otmp)); 72. } 73. 74. /* for items that involve no delay */ 75. staticfn void 76. on_msg(struct obj *otmp) 77. { 78. /* on_msg() for rings and amulets just shows add-to-invent feedback 79. [after caller calls setworn(), for suffix: "(on {left|right} hand)" 80. or "(being worn)"]; eyewear too unless giving verbose message below */ 81. if ((otmp->owornmask & (W_RING | W_AMUL)) != 0L 82. || ((otmp->owornmask & W_TOOL) != 0L && !flags.verbose)) { 83. prinv((char *) NULL, otmp, 0L); 84. return; 85. } 86. 87. if (flags.verbose) { 88. char how[BUFSZ]; 89. /* call xname() before obj_is_pname(); formatting obj's name 90. might set obj->dknown and that affects the pname test */ 91. const char *otmp_name = xname(otmp); 92. 93. how[0] = '\0'; 94. if (otmp->otyp == TOWEL) 95. Sprintf(how, " around your %s", body_part(HEAD)); 96. You("are now wearing %s%s.", 97. obj_is_pname(otmp) ? the(otmp_name) : an(otmp_name), how); 98. } 99. } 100. 101. /* putting on or taking off an item which confers stealth; 102. give feedback and discover it iff stealth state is changing; 103. stealth is blocked by riding unless hero+steed fly (handled with 104. BStealth by mount and dismount routines) */ 105. staticfn 106. void 107. toggle_stealth( 108. struct obj *obj, 109. long oldprop, /* prop[].extrinsic, with obj->owornmask pre-stripped */ 110. boolean on) 111. { 112. if (on ? gi.initial_don : svc.context.takeoff.cancelled_don) 113. return; 114. 115. if (!oldprop /* extrinsic stealth from something else */ 116. && !HStealth /* intrinsic stealth */ 117. && !BStealth) { /* stealth blocked by something */ 118. if (obj->otyp == RIN_STEALTH) 119. learnring(obj, TRUE); 120. else /* discover elven cloak or elven boots */ 121. makeknown(obj->otyp); 122. 123. if (on) { 124. if (!is_boots(obj)) 125. You("move very quietly."); 126. else if (Levitation || Flying) 127. You("float imperceptibly."); 128. else 129. You("walk very quietly."); 130. } else { 131. boolean riding = (u.usteed != NULL); 132. 133. You("%s%s are noisy.", riding ? "and " : "sure", 134. riding ? x_monnam(u.usteed, ARTICLE_YOUR, (char *) NULL, 135. (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION), 136. FALSE) 137. : ""); 138. } 139. } 140. } 141. 142. /* putting on or taking off an item which confers displacement, or gaining 143. or losing timed displacement after eating a displacer beast corpse or tin; 144. give feedback and discover it iff displacement state is changing *and* 145. hero is able to see self (or sense monsters); for timed, 'obj' is Null 146. and this is only called for the message */ 147. void 148. toggle_displacement( 149. struct obj *obj, 150. long oldprop, /* prop[].extrinsic, with obj->owornmask 151. stripped by caller */ 152. boolean on) 153. { 154. if (on ? gi.initial_don : svc.context.takeoff.cancelled_don) 155. return; 156. 157. if (!oldprop /* extrinsic displacement from something else */ 158. && !(u.uprops[DISPLACED].intrinsic) /* timed, from eating */ 159. && !(u.uprops[DISPLACED].blocked) /* (theoretical) */ 160. /* we don't use canseeself() here because it augments vision 161. with touch, which isn't appropriate for deciding whether 162. we'll notice that monsters have trouble spotting the hero */ 163. && ((!Blind /* see anything */ 164. && !u.uswallow /* see surroundings */ 165. && !Invisible) /* see self */ 166. /* actively sensing nearby monsters via telepathy or extended 167. monster detection overrides vision considerations because 168. hero also senses self in this situation */ 169. || (Unblind_telepat 170. || (Blind_telepat && Blind) 171. || Detect_monsters))) { 172. if (obj) 173. makeknown(obj->otyp); 174. 175. You_feel("that monsters%s have difficulty pinpointing your location.", 176. on ? "" : " no longer"); 177. } 178. } 179. 180. /* 181. * The Type_on() functions should be called *after* setworn(). 182. * The Type_off() functions call setworn() themselves. 183. * [Blindf_on() is an exception and calls setworn() itself.] 184. */ 185. 186. int 187. Boots_on(void) 188. { 189. long oldprop = 190. u.uprops[objects[uarmf->otyp].oc_oprop].extrinsic & ~WORN_BOOTS; 191. 192. switch (uarmf->otyp) { 193. case LOW_BOOTS: 194. case IRON_SHOES: 195. case HIGH_BOOTS: 196. case JUMPING_BOOTS: 197. case KICKING_BOOTS: 198. break; 199. case WATER_WALKING_BOOTS: 200. /* 201. * Sequencing issue? If underwater (perhaps via magical breathing), 202. * putting on water walking boots produces "you slowly rise above 203. * the surface" then "you finish your dressing maneuver". 204. */ 205. 206. /* spoteffects() doesn't get called here; pooleffects() is called 207. during movement and u.uinwater is already False after setworn() */ 208. if (u.uinwater) 209. spoteffects(TRUE); 210. /* init'd in accessory_or_armor_on() and only used here */ 211. if (gw.wasinwater) { 212. if (!u.uinwater) 213. makeknown(WATER_WALKING_BOOTS); 214. gw.wasinwater = 0U; 215. } 216. /* (we don't need a lava check here since boots can't be 217. put on while feet are stuck) */ 218. break; 219. case SPEED_BOOTS: 220. /* Speed boots are still better than intrinsic speed, */ 221. /* though not better than potion speed */ 222. if (!oldprop && !(HFast & TIMEOUT)) { 223. makeknown(uarmf->otyp); 224. You_feel("yourself speed up%s.", 225. (oldprop || HFast) ? " a bit more" : ""); 226. } 227. break; 228. case ELVEN_BOOTS: 229. toggle_stealth(uarmf, oldprop, TRUE); 230. break; 231. case FUMBLE_BOOTS: 232. if (!oldprop && !(HFumbling & ~TIMEOUT)) 233. incr_itimeout(&HFumbling, rnd(20)); 234. break; 235. case LEVITATION_BOOTS: 236. if (!oldprop && !HLevitation && !(BLevitation & FROMOUTSIDE)) { 237. uarmf->known = 1; /* might come off if putting on over a sink, 238. * so uarmf could be Null below; status line 239. * gets updated during brief interval they're 240. * worn so hero and player learn enchantment */ 241. disp.botl = TRUE; /* status hilites might mark AC changed */ 242. makeknown(uarmf->otyp); 243. float_up(); 244. if (Levitation) 245. spoteffects(FALSE); /* for sink effect */ 246. } else { 247. float_vs_flight(); /* maybe toggle BFlying's I_SPECIAL */ 248. } 249. break; 250. default: 251. impossible(unknown_type, c_boots, uarmf->otyp); 252. } 253. /* uarmf could be Null here (levitation boots put on over a sink) */ 254. if (uarmf && !uarmf->known) { 255. uarmf->known = 1; /* boots' +/- evident because of status line AC */ 256. update_inventory(); 257. } 258. return 0; 259. } 260. 261. int 262. Boots_off(void) 263. { 264. struct obj *otmp = uarmf; 265. int otyp = otmp->otyp; 266. long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_BOOTS; 267. 268. svc.context.takeoff.mask &= ~W_ARMF; 269. /* For levitation, float_down() returns if Levitation, so we 270. * must do a setworn() _before_ the levitation case. 271. */ 272. setworn((struct obj *) 0, W_ARMF); 273. switch (otyp) { 274. case SPEED_BOOTS: 275. if (!Very_fast && !svc.context.takeoff.cancelled_don) { 276. makeknown(otyp); 277. You_feel("yourself slow down%s.", Fast ? " a bit" : ""); 278. } 279. break; 280. case WATER_WALKING_BOOTS: 281. /* check for lava since fireproofed boots make it viable */ 282. if ((is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)) 283. && !Levitation && !Flying 284. && !(is_clinger(gy.youmonst.data) && has_ceiling(&u.uz)) 285. && !svc.context.takeoff.cancelled_don 286. /* avoid recursive call to lava_effects() */ 287. && !iflags.in_lava_effects) { 288. /* make boots known in case you survive the drowning */ 289. makeknown(otyp); 290. spoteffects(TRUE); 291. } 292. break; 293. case ELVEN_BOOTS: 294. toggle_stealth(otmp, oldprop, FALSE); 295. break; 296. case FUMBLE_BOOTS: 297. if (!oldprop && !(HFumbling & ~TIMEOUT)) 298. HFumbling = EFumbling = 0; 299. break; 300. case LEVITATION_BOOTS: 301. if (!oldprop && !HLevitation && !(BLevitation & FROMOUTSIDE) 302. && !svc.context.takeoff.cancelled_don) { 303. /* lava_effects() sets in_lava_effects and calls Boots_off() 304. so hero is already in midst of floating down */ 305. if (!iflags.in_lava_effects) 306. (void) float_down(0L, 0L); 307. makeknown(otyp); 308. } else { 309. float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ 310. } 311. break; 312. case LOW_BOOTS: 313. case IRON_SHOES: 314. case HIGH_BOOTS: 315. case JUMPING_BOOTS: 316. case KICKING_BOOTS: 317. break; 318. default: 319. impossible(unknown_type, c_boots, otyp); 320. } 321. svc.context.takeoff.cancelled_don = FALSE; 322. return 0; 323. } 324. 325. staticfn int 326. Cloak_on(void) 327. { 328. long oldprop = 329. u.uprops[objects[uarmc->otyp].oc_oprop].extrinsic & ~WORN_CLOAK; 330. 331. switch (uarmc->otyp) { 332. case ORCISH_CLOAK: 333. case DWARVISH_CLOAK: 334. case CLOAK_OF_MAGIC_RESISTANCE: 335. case ROBE: 336. case LEATHER_CLOAK: 337. break; 338. case CLOAK_OF_PROTECTION: 339. makeknown(uarmc->otyp); 340. break; 341. case ELVEN_CLOAK: 342. toggle_stealth(uarmc, oldprop, TRUE); 343. break; 344. case CLOAK_OF_DISPLACEMENT: 345. toggle_displacement(uarmc, oldprop, TRUE); 346. break; 347. case MUMMY_WRAPPING: 348. /* Note: it's already being worn, so we have to cheat here. */ 349. if ((HInvis || EInvis) && !Blind) { 350. newsym(u.ux, u.uy); 351. You("can %s!", See_invisible ? "no longer see through yourself" 352. : see_yourself); 353. } 354. break; 355. case CLOAK_OF_INVISIBILITY: 356. /* since cloak of invisibility was worn, we know mummy wrapping 357. wasn't, so no need to check `oldprop' against blocked */ 358. if (!oldprop && !HInvis && !Blind) { 359. makeknown(uarmc->otyp); 360. newsym(u.ux, u.uy); 361. pline("Suddenly you can%s yourself.", 362. See_invisible ? " see through" : "not see"); 363. } 364. break; 365. case OILSKIN_CLOAK: 366. pline("%s very tightly.", Tobjnam(uarmc, "fit")); 367. break; 368. /* Alchemy smock gives poison _and_ acid resistance */ 369. case ALCHEMY_SMOCK: 370. EAcid_resistance |= WORN_CLOAK; 371. break; 372. default: 373. impossible(unknown_type, c_cloak, uarmc->otyp); 374. } 375. if (uarmc && !uarmc->known) { /* no known instance of !uarmc here */ 376. uarmc->known = 1; /* cloak's +/- evident because of status line AC */ 377. update_inventory(); 378. } 379. return 0; 380. } 381. 382. int 383. Cloak_off(void) 384. { 385. struct obj *otmp = uarmc; 386. int otyp = otmp->otyp; 387. long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_CLOAK; 388. 389. svc.context.takeoff.mask &= ~W_ARMC; 390. /* For mummy wrapping, taking it off first resets `Invisible'. */ 391. setworn((struct obj *) 0, W_ARMC); 392. switch (otyp) { 393. case ORCISH_CLOAK: 394. case DWARVISH_CLOAK: 395. case CLOAK_OF_PROTECTION: 396. case CLOAK_OF_MAGIC_RESISTANCE: 397. case OILSKIN_CLOAK: 398. case ROBE: 399. case LEATHER_CLOAK: 400. break; 401. case ELVEN_CLOAK: 402. toggle_stealth(otmp, oldprop, FALSE); 403. break; 404. case CLOAK_OF_DISPLACEMENT: 405. toggle_displacement(otmp, oldprop, FALSE); 406. break; 407. case MUMMY_WRAPPING: 408. if (Invis && !Blind) { 409. newsym(u.ux, u.uy); 410. You("can %s.", See_invisible ? "see through yourself" 411. : "no longer see yourself"); 412. } 413. break; 414. case CLOAK_OF_INVISIBILITY: 415. if (!oldprop && !HInvis && !Blind) { 416. makeknown(CLOAK_OF_INVISIBILITY); 417. newsym(u.ux, u.uy); 418. pline("Suddenly you can %s.", 419. See_invisible ? "no longer see through yourself" 420. : see_yourself); 421. } 422. break; 423. /* Alchemy smock gives poison _and_ acid resistance */ 424. case ALCHEMY_SMOCK: 425. EAcid_resistance &= ~WORN_CLOAK; 426. break; 427. default: 428. impossible(unknown_type, c_cloak, otyp); 429. } 430. return 0; 431. } 432. 433. staticfn int 434. Helmet_on(void) 435. { 436. switch (uarmh->otyp) { 437. case FEDORA: 438. if (Role_if(PM_ARCHEOLOGIST)) 439. change_luck(1); 440. break; 441. case HELMET: 442. case DENTED_POT: 443. case ELVEN_LEATHER_HELM: 444. case DWARVISH_IRON_HELM: 445. case ORCISH_HELM: 446. case HELM_OF_TELEPATHY: 447. break; 448. case HELM_OF_CAUTION: 449. see_monsters(); 450. break; 451. case HELM_OF_BRILLIANCE: 452. adj_abon(uarmh, uarmh->spe); 453. break; 454. case CORNUTHAUM: 455. /* people think marked wizards know what they're talking about, 456. but it takes trained arrogance to pull it off, and the actual 457. enchantment of the hat is irrelevant */ 458. ABON(A_CHA) += (Role_if(PM_WIZARD) ? 1 : -1); 459. disp.botl = TRUE; 460. makeknown(uarmh->otyp); 461. break; 462. case HELM_OF_OPPOSITE_ALIGNMENT: 463. uarmh->known = 1; /* do this here because uarmh could get cleared */ 464. /* changing alignment can toggle off active artifact properties, 465. including levitation; uarmh could get dropped or destroyed here 466. by hero falling onto a polymorph trap or into water (emergency 467. disrobe) or maybe lava (probably not, helm isn't 'organic') */ 468. uchangealign((u.ualign.type != A_NEUTRAL) 469. ? -u.ualign.type 470. : (uarmh->o_id % 2) ? A_CHAOTIC : A_LAWFUL, 471. A_CG_HELM_ON); 472. /* makeknown(HELM_OF_OPPOSITE_ALIGNMENT); -- below, after Tobjnam() */ 473. FALLTHROUGH; 474. /*FALLTHRU*/ 475. case DUNCE_CAP: 476. if (uarmh && !uarmh->cursed) { 477. if (Blind) 478. pline("%s for a moment.", Tobjnam(uarmh, "vibrate")); 479. else 480. pline("%s %s for a moment.", Tobjnam(uarmh, "glow"), 481. hcolor(NH_BLACK)); 482. curse(uarmh); 483. /* curse() doesn't touch bknown so doesn't update persistent 484. inventory; do so now [set_bknown() calls update_inventory()] */ 485. if (Blind) 486. set_bknown(uarmh, 0); /* lose bknown if previously set */ 487. else if (Role_if(PM_CLERIC)) 488. set_bknown(uarmh, 1); /* (bknown should already be set) */ 489. else if (uarmh->bknown) 490. update_inventory(); /* keep bknown as-is; display the curse */ 491. } 492. disp.botl = TRUE; /* reveal new alignment or INT & WIS */ 493. if (Hallucination) { 494. pline("My brain hurts!"); /* Monty Python's Flying Circus */ 495. } else if (uarmh && uarmh->otyp == DUNCE_CAP) { 496. You_feel("%s.", /* track INT change; ignore WIS */ 497. ACURR(A_INT) 498. <= (ABASE(A_INT) + ABON(A_INT) + ATEMP(A_INT)) 499. ? "like sitting in a corner" 500. : "giddy"); 501. } else { 502. /* [message formerly given here moved to uchangealign()] */ 503. makeknown(HELM_OF_OPPOSITE_ALIGNMENT); 504. } 505. break; 506. default: 507. impossible(unknown_type, c_helmet, uarmh->otyp); 508. } 509. /* uarmh could be Null due to uchangealign() */ 510. if (uarmh && !uarmh->known) { 511. uarmh->known = 1; /* helmet's +/- evident because of status line AC */ 512. update_inventory(); 513. } 514. return 0; 515. } 516. 517. int 518. Helmet_off(void) 519. { 520. svc.context.takeoff.mask &= ~W_ARMH; 521. 522. switch (uarmh->otyp) { 523. case FEDORA: 524. if (Role_if(PM_ARCHEOLOGIST)) 525. change_luck(-1); 526. break; 527. case HELMET: 528. case DENTED_POT: 529. case ELVEN_LEATHER_HELM: 530. case DWARVISH_IRON_HELM: 531. case ORCISH_HELM: 532. break; 533. case DUNCE_CAP: 534. disp.botl = TRUE; 535. break; 536. case CORNUTHAUM: 537. if (!svc.context.takeoff.cancelled_don) { 538. ABON(A_CHA) += (Role_if(PM_WIZARD) ? -1 : 1); 539. disp.botl = TRUE; 540. } 541. break; 542. case HELM_OF_TELEPATHY: 543. case HELM_OF_CAUTION: 544. /* need to update ability before calling see_monsters() */ 545. setworn((struct obj *) 0, W_ARMH); 546. see_monsters(); 547. return 0; 548. case HELM_OF_BRILLIANCE: 549. if (!svc.context.takeoff.cancelled_don) 550. adj_abon(uarmh, -uarmh->spe); 551. break; 552. case HELM_OF_OPPOSITE_ALIGNMENT: 553. /* changing alignment can toggle off active artifact 554. properties, including levitation; uarmh could get 555. dropped or destroyed here */ 556. uchangealign(u.ualignbase[A_CURRENT], A_CG_HELM_OFF); 557. break; 558. default: 559. impossible(unknown_type, c_helmet, uarmh->otyp); 560. } 561. setworn((struct obj *) 0, W_ARMH); 562. svc.context.takeoff.cancelled_don = FALSE; 563. return 0; 564. } 565. 566. /* hard helms provide better protection against falling rocks */ 567. boolean 568. hard_helmet(struct obj *obj) 569. { 570. if (!obj || !is_helmet(obj)) 571. return FALSE; 572. return (is_metallic(obj) || is_crackable(obj)) ? TRUE : FALSE; 573. } 574. 575. staticfn int 576. Gloves_on(void) 577. { 578. long oldprop = 579. u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES; 580. 581. switch (uarmg->otyp) { 582. case LEATHER_GLOVES: 583. break; 584. case GAUNTLETS_OF_FUMBLING: 585. if (!oldprop && !(HFumbling & ~TIMEOUT)) 586. incr_itimeout(&HFumbling, rnd(20)); 587. break; 588. case GAUNTLETS_OF_POWER: 589. makeknown(uarmg->otyp); 590. disp.botl = TRUE; /* taken care of in attrib.c */ 591. break; 592. case GAUNTLETS_OF_DEXTERITY: 593. adj_abon(uarmg, uarmg->spe); 594. break; 595. default: 596. impossible(unknown_type, c_gloves, uarmg->otyp); 597. } 598. if (!uarmg->known) { 599. uarmg->known = 1; /* gloves' +/- evident because of status line AC */ 600. update_inventory(); 601. } 602. return 0; 603. } 604. 605. /* check for wielding cockatrice corpse after taking off gloves or yellow 606. dragon scales/mail or having temporary stoning resistance time out */ 607. void 608. wielding_corpse( 609. struct obj *obj, /* uwep, potentially a wielded cockatrice corpse */ 610. struct obj *how, /* gloves or dragon armor or Null (resist timeout) */ 611. boolean voluntary) /* True: taking protective armor off on purpose */ 612. { 613. if (!obj || obj->otyp != CORPSE || uarmg) 614. return; 615. /* note: can't dual-wield with non-weapons/weapon-tools so u.twoweap 616. will always be false if uswapwep happens to be a corpse */ 617. if (obj != uwep && (obj != uswapwep || !u.twoweap)) 618. return; 619. 620. if (touch_petrifies(&mons[obj->corpsenm]) && !Stone_resistance) { 621. char kbuf[BUFSZ], hbuf[BUFSZ]; 622. 623. You("%s %s in your bare %s.", 624. (how && is_gloves(how)) ? "now wield" : "are wielding", 625. corpse_xname(obj, (const char *) 0, CXN_ARTICLE), 626. makeplural(body_part(HAND))); 627. /* "removing" ought to be "taking off" but that makes the 628. tombstone text more likely to be truncated */ 629. if (how) 630. Sprintf(hbuf, "%s %s", voluntary ? "removing" : "losing", 631. is_gloves(how) ? gloves_simple_name(how) 632. : strsubst(simpleonames(how), "set of ", "")); 633. else 634. Strcpy(hbuf, "resistance timing out"); 635. Snprintf(kbuf, sizeof kbuf, "%s while wielding %s", 636. hbuf, killer_xname(obj)); 637. instapetrify(kbuf); 638. /* life-saved or got poly'd into a stone golem; can't continue 639. wielding cockatrice corpse unless have now become resistant */ 640. if (!Stone_resistance) 641. remove_worn_item(obj, FALSE); 642. } 643. } 644. 645. int 646. Gloves_off(void) 647. { 648. struct obj *gloves = uarmg; /* needed after uarmg has been set to Null */ 649. long oldprop = 650. u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES; 651. boolean on_purpose = !svc.context.mon_moving && !uarmg->in_use; 652. 653. svc.context.takeoff.mask &= ~W_ARMG; 654. 655. switch (uarmg->otyp) { 656. case LEATHER_GLOVES: 657. break; 658. case GAUNTLETS_OF_FUMBLING: 659. if (!oldprop && !(HFumbling & ~TIMEOUT)) 660. HFumbling = EFumbling = 0; 661. break; 662. case GAUNTLETS_OF_POWER: 663. makeknown(uarmg->otyp); 664. disp.botl = TRUE; /* taken care of in attrib.c */ 665. break; 666. case GAUNTLETS_OF_DEXTERITY: 667. if (!svc.context.takeoff.cancelled_don) 668. adj_abon(uarmg, -uarmg->spe); 669. break; 670. default: 671. impossible(unknown_type, c_gloves, uarmg->otyp); 672. } 673. setworn((struct obj *) 0, W_ARMG); 674. svc.context.takeoff.cancelled_don = FALSE; 675. encumber_msg(); /* immediate feedback for GoP */ 676. 677. /* usually can't remove gloves when they're slippery but it can 678. be done by having them fall off (polymorph), stolen, or 679. destroyed (scroll, overenchantment, monster spell); if that 680. happens, 'cure' slippery fingers so that it doesn't transfer 681. from gloves to bare hands */ 682. if (Glib) 683. make_glib(0); /* for update_inventory() */ 684. 685. /* prevent wielding cockatrice when not wearing gloves */ 686. if (uwep && uwep->otyp == CORPSE) 687. wielding_corpse(uwep, gloves, on_purpose); 688. /* KMH -- ...or your secondary weapon when you're wielding it 689. [This case can't actually happen; twoweapon mode won't engage 690. if a corpse has been set up as either the primary or alternate 691. weapon. If it could happen and /both/ uwep and uswapwep could 692. be cockatrice corpses, life-saving for the first would need to 693. prevent the second from being fatal since conceptually they'd 694. be being touched simultaneously.] */ 695. if (u.twoweap && uswapwep && uswapwep->otyp == CORPSE) 696. wielding_corpse(uswapwep, gloves, on_purpose); 697. 698. if (condtests[bl_bareh].enabled) 699. disp.botl = TRUE; 700. 701. return 0; 702. } 703. 704. staticfn int 705. Shield_on(void) 706. { 707. /* no shield currently requires special handling when put on, but we 708. keep this uncommented in case somebody adds a new one which does 709. [the magical shields are handled by setting u.uprops[*].extrinsic 710. in setworn() called by armor_or_accessory_on() before Shield_on()] */ 711. switch (uarms->otyp) { 712. case SMALL_SHIELD: 713. case SHIELD_OF_DRAIN_RESISTANCE: 714. case SHIELD_OF_SHOCK_RESISTANCE: 715. case ELVEN_SHIELD: 716. case URUK_HAI_SHIELD: 717. case ORCISH_SHIELD: 718. case DWARVISH_ROUNDSHIELD: 719. case LARGE_SHIELD: 720. case SHIELD_OF_REFLECTION: 721. break; 722. default: 723. impossible(unknown_type, c_shield, uarms->otyp); 724. } 725. if (!uarms->known) { 726. uarms->known = 1; /* shield's +/- evident because of status line AC */ 727. update_inventory(); 728. } 729. return 0; 730. } 731. 732. int 733. Shield_off(void) 734. { 735. svc.context.takeoff.mask &= ~W_ARMS; 736. 737. /* no shield currently requires special handling when taken off, but we 738. keep this uncommented in case somebody adds a new one which does */ 739. switch (uarms->otyp) { 740. case SMALL_SHIELD: 741. case SHIELD_OF_DRAIN_RESISTANCE: 742. case SHIELD_OF_SHOCK_RESISTANCE: 743. case ELVEN_SHIELD: 744. case URUK_HAI_SHIELD: 745. case ORCISH_SHIELD: 746. case DWARVISH_ROUNDSHIELD: 747. case LARGE_SHIELD: 748. case SHIELD_OF_REFLECTION: 749. break; 750. default: 751. impossible(unknown_type, c_shield, uarms->otyp); 752. } 753. 754. setworn((struct obj *) 0, W_ARMS); 755. return 0; 756. } 757. 758. staticfn int 759. Shirt_on(void) 760. { 761. /* no shirt currently requires special handling when put on, but we 762. keep this uncommented in case somebody adds a new one which does */ 763. switch (uarmu->otyp) { 764. case HAWAIIAN_SHIRT: 765. case T_SHIRT: 766. break; 767. default: 768. impossible(unknown_type, c_shirt, uarmu->otyp); 769. } 770. if (!uarmu->known) { 771. uarmu->known = 1; /* shirt's +/- evident because of status line AC */ 772. update_inventory(); 773. } 774. return 0; 775. } 776. 777. int 778. Shirt_off(void) 779. { 780. svc.context.takeoff.mask &= ~W_ARMU; 781. 782. /* no shirt currently requires special handling when taken off, but we 783. keep this uncommented in case somebody adds a new one which does */ 784. switch (uarmu->otyp) { 785. case HAWAIIAN_SHIRT: 786. case T_SHIRT: 787. break; 788. default: 789. impossible(unknown_type, c_shirt, uarmu->otyp); 790. } 791. 792. setworn((struct obj *) 0, W_ARMU); 793. return 0; 794. } 795. 796. /* handle extra abilities for hero wearing dragon scale armor */ 797. staticfn void 798. dragon_armor_handling( 799. struct obj *otmp, /* armor being put on or taken off */ 800. boolean puton, /* True: on, False: off */ 801. boolean on_purpose) /* voluntary removal; not applicable for putting on */ 802. { 803. if (!otmp) 804. return; 805. 806. switch (otmp->otyp) { 807. /* grey: no extra effect */ 808. /* silver: no extra effect */ 809. case BLACK_DRAGON_SCALES: 810. case BLACK_DRAGON_SCALE_MAIL: 811. if (puton) { 812. EDrain_resistance |= W_ARM; 813. } else { 814. EDrain_resistance &= ~W_ARM; 815. } 816. break; 817. case BLUE_DRAGON_SCALES: 818. case BLUE_DRAGON_SCALE_MAIL: 819. if (puton) { 820. if (!Very_fast) 821. You("speed up%s.", Fast ? " a bit more" : ""); 822. EFast |= W_ARM; 823. } else { 824. EFast &= ~W_ARM; 825. if (!Very_fast && !svc.context.takeoff.cancelled_don) 826. You("slow down."); 827. } 828. break; 829. case GREEN_DRAGON_SCALES: 830. case GREEN_DRAGON_SCALE_MAIL: 831. if (puton) { 832. ESick_resistance |= W_ARM; 833. } else { 834. ESick_resistance &= ~W_ARM; 835. } 836. break; 837. case RED_DRAGON_SCALES: 838. case RED_DRAGON_SCALE_MAIL: 839. if (puton) { 840. EInfravision |= W_ARM; 841. } else { 842. EInfravision &= ~W_ARM; 843. } 844. see_monsters(); 845. break; 846. case GOLD_DRAGON_SCALES: 847. case GOLD_DRAGON_SCALE_MAIL: 848. (void) make_hallucinated((long) !puton, 849. program_state.restoring ? FALSE : TRUE, 850. W_ARM); 851. break; 852. case ORANGE_DRAGON_SCALES: 853. case ORANGE_DRAGON_SCALE_MAIL: 854. if (puton) { 855. Free_action |= W_ARM; 856. } else { 857. Free_action &= ~W_ARM; 858. } 859. break; 860. case YELLOW_DRAGON_SCALES: 861. case YELLOW_DRAGON_SCALE_MAIL: 862. if (puton) { 863. EStone_resistance |= W_ARM; 864. } else { 865. EStone_resistance &= ~W_ARM; 866. 867. /* prevent wielding cockatrice after losing stoning resistance 868. when not wearing gloves; the uswapwep case is always a no-op */ 869. wielding_corpse(uwep, otmp, on_purpose); 870. wielding_corpse(uswapwep, otmp, on_purpose); 871. } 872. break; 873. case WHITE_DRAGON_SCALES: 874. case WHITE_DRAGON_SCALE_MAIL: 875. if (puton) { 876. ESlow_digestion |= W_ARM; 877. } else { 878. ESlow_digestion &= ~W_ARM; 879. } 880. break; 881. default: 882. break; 883. } 884. } 885. 886. staticfn int 887. Armor_on(void) 888. { 889. if (!uarm) /* no known instances of !uarm here but play it safe */ 890. return 0; 891. if (!uarm->known) { 892. uarm->known = 1; /* suit's +/- evident because of status line AC */ 893. update_inventory(); 894. } 895. dragon_armor_handling(uarm, TRUE, TRUE); 896. /* gold DSM requires extra handling since it emits light when worn; 897. do that after the special armor handling */ 898. if (artifact_light(uarm) && !uarm->lamplit) { 899. begin_burn(uarm, FALSE); 900. if (!Blind) 901. pline("%s %s to shine %s!", 902. Yname2(uarm), otense(uarm, "begin"), 903. arti_light_description(uarm)); 904. } 905. return 0; 906. } 907. 908. int 909. Armor_off(void) 910. { 911. struct obj *otmp = uarm; 912. boolean was_arti_light = otmp && otmp->lamplit && artifact_light(otmp); 913. 914. svc.context.takeoff.mask &= ~W_ARM; 915. setworn((struct obj *) 0, W_ARM); 916. svc.context.takeoff.cancelled_don = FALSE; 917. 918. /* taking off yellow dragon scales/mail might be fatal; arti_light 919. comes from gold dragon scales/mail so they don't overlap, but 920. conceptually the non-fatal change should be done before the 921. potentially fatal change in case the latter results in bones */ 922. if (was_arti_light && !artifact_light(otmp)) { 923. end_burn(otmp, FALSE); 924. if (!Blind) 925. pline("%s shining.", Tobjnam(otmp, "stop")); 926. } 927. dragon_armor_handling(otmp, FALSE, TRUE); 928. 929. return 0; 930. } 931. 932. /* The gone functions differ from the off functions in that if you die from 933. * taking it off and have life saving, you still die. [Obsolete reference 934. * to lack of fire resistance being fatal in hell (nethack 3.0) and life 935. * saving putting a removed item back on to prevent that from immediately 936. * repeating.] 937. */ 938. int 939. Armor_gone(void) 940. { 941. struct obj *otmp = uarm; 942. boolean was_arti_light = otmp && otmp->lamplit && artifact_light(otmp); 943. 944. svc.context.takeoff.mask &= ~W_ARM; 945. setnotworn(uarm); 946. svc.context.takeoff.cancelled_don = FALSE; 947. 948. /* losing yellow dragon scales/mail might be fatal; arti_light 949. comes from gold dragon scales/mail so they don't overlap, but 950. conceptually the non-fatal change should be done before the 951. potentially fatal change in case the latter results in bones */ 952. if (was_arti_light && !artifact_light(otmp)) { 953. end_burn(otmp, FALSE); 954. if (!Blind) 955. pline("%s shining.", Tobjnam(otmp, "stop")); 956. } 957. dragon_armor_handling(otmp, FALSE, FALSE); 958. 959. return 0; 960. } 961. 962. staticfn void 963. Amulet_on(struct obj *amul) 964. { 965. boolean on_msg_done = FALSE; 966. 967. /* make sure amulet isn't wielded/alt-wielded/quivered, before wearing */ 968. remove_worn_item(amul, FALSE); 969. setworn(amul, W_AMUL); 970. 971. switch (uamul->otyp) { 972. case AMULET_OF_ESP: 973. case AMULET_OF_LIFE_SAVING: 974. case AMULET_VERSUS_POISON: 975. case AMULET_OF_REFLECTION: 976. case FAKE_AMULET_OF_YENDOR: 977. break; 978. case AMULET_OF_MAGICAL_BREATHING: { 979. boolean was_in_poison_gas; 980. 981. /* amulet is already on; we need to check hero's gas-cloud status 982. when it was off */ 983. EMagical_breathing &= ~W_AMUL; 984. was_in_poison_gas = region_danger(); 985. EMagical_breathing |= W_AMUL; 986. if (was_in_poison_gas) { 987. makeknown(AMULET_OF_MAGICAL_BREATHING); 988. on_msg(uamul); 989. on_msg_done = TRUE; 990. You("are no longer bothered by the poison gas."); 991. } 992. /* no need to check for becoming able to breathe underwater; 993. if we are underwater, we already can or we would have drowned */ 994. break; 995. } 996. case AMULET_OF_UNCHANGING: 997. if (Slimed) 998. make_slimed(0L, (char *) 0); 999. break; 1000. case AMULET_OF_CHANGE: { 1001. boolean call_it = FALSE; 1002. int new_sex, orig_sex = poly_gender(); 1003. 1004. /* in normal play it's not possible to put on an amulet of change 1005. while already wearing an amulet of unchanging, but in wizard 1006. mode the Unchanging attribute can be set via #wizintrinsic */ 1007. if (!Unchanging) 1008. change_sex(); 1009. 1010. new_sex = poly_gender(); 1011. if (new_sex != orig_sex) 1012. makeknown(AMULET_OF_CHANGE); 1013. on_msg(uamul); /* show 'z - amulet of change (being worn)' */ 1014. on_msg_done = TRUE; 1015. 1016. /* Don't use same message as polymorph */ 1017. if (new_sex != orig_sex) { 1018. newsym(u.ux, u.uy); /* glyphmon flag and tile have changed */ 1019. disp.botl = TRUE; /* role name or rank title might have changed */ 1020. You("are suddenly very %s!", 1021. flags.female ? "feminine" : "masculine"); 1022. } else { 1023. /* already polymorphed into single-gender monster; only 1024. changed the character's base sex */ 1025. You("don't feel like yourself."); 1026. /* checking dknown is redundant--amulets always have dknown set */ 1027. call_it = (uamul->dknown != 0); 1028. } 1029. livelog_newform(FALSE, orig_sex, new_sex); 1030. pline_The("amulet disintegrates!"); 1031. if (call_it) 1032. trycall(uamul); 1033. useup(uamul); 1034. break; 1035. } 1036. case AMULET_OF_STRANGULATION: 1037. /* note: might already be Strangled (via #wizintrinsic) */ 1038. if (can_be_strangled(&gy.youmonst) && !Strangled) { 1039. makeknown(AMULET_OF_STRANGULATION); 1040. Strangled = 6L; 1041. disp.botl = TRUE; 1042. on_msg(uamul); 1043. on_msg_done = TRUE; 1044. pline("It constricts your throat!"); 1045. } 1046. break; 1047. case AMULET_OF_RESTFUL_SLEEP: { 1048. long newnap = (long) rnd(98) + 2L, oldnap = (HSleepy & TIMEOUT); 1049. 1050. if (newnap < oldnap || oldnap == 0L) 1051. /* avoid clobbering FROMOUTSIDE bit, which might have 1052. gotten set by previously eating one of these amulets */ 1053. HSleepy = (HSleepy & ~TIMEOUT) | newnap; 1054. break; 1055. } 1056. case AMULET_OF_FLYING: 1057. /* setworn() has already set extrinsic flying */ 1058. float_vs_flight(); /* block flying if levitating */ 1059. if (Flying) { 1060. boolean already_flying; 1061. 1062. /* to determine whether this flight is new we have to muck 1063. about in the Flying intrinsic (actually extrinsic) */ 1064. EFlying &= ~W_AMUL; 1065. already_flying = !!Flying; 1066. EFlying |= W_AMUL; 1067. 1068. if (!already_flying) { 1069. makeknown(AMULET_OF_FLYING); 1070. on_msg(uamul); 1071. on_msg_done = TRUE; 1072. disp.botl = TRUE; /* status: 'Fly' On */ 1073. You("are now in flight."); 1074. } 1075. } 1076. break; 1077. case AMULET_OF_GUARDING: 1078. makeknown(AMULET_OF_GUARDING); 1079. find_ac(); 1080. break; 1081. case AMULET_OF_YENDOR: 1082. break; 1083. } 1084. 1085. if (!on_msg_done) 1086. on_msg(uamul); 1087. } 1088. 1089. void 1090. Amulet_off(void) 1091. { 1092. struct obj *amul = uamul; /* for off_msg() after setworn(NULL,W_AMUL) */ 1093. boolean mkn = FALSE, early_off_msg = FALSE; 1094. 1095. svc.context.takeoff.mask &= ~W_AMUL; 1096. 1097. switch (uamul->otyp) { 1098. case AMULET_OF_ESP: 1099. /* need to update ability before calling see_monsters() */ 1100. setworn((struct obj *) 0, W_AMUL); 1101. off_msg(amul); 1102. early_off_msg = TRUE; 1103. 1104. see_monsters(); 1105. break; 1106. case AMULET_OF_LIFE_SAVING: 1107. case AMULET_VERSUS_POISON: 1108. case AMULET_OF_REFLECTION: 1109. case AMULET_OF_CHANGE: 1110. case AMULET_OF_UNCHANGING: 1111. case FAKE_AMULET_OF_YENDOR: 1112. break; 1113. case AMULET_OF_MAGICAL_BREATHING: 1114. /* amulet is currently still on; take it off before calling drown() 1115. and region_danger(); call off_msg() before specific messages */ 1116. setworn((struct obj *) 0, W_AMUL); 1117. off_msg(amul); /* 'uamul' has been set to Null */ 1118. early_off_msg = TRUE; 1119. 1120. if (Underwater) { 1121. if (!cant_drown(gy.youmonst.data) && !Swimming) { 1122. You("suddenly inhale an unhealthy amount of %s!", 1123. hliquid("water")); 1124. mkn = TRUE; /* in case of life-saving */ 1125. (void) drown(); 1126. } 1127. } 1128. if (region_danger()) { 1129. /* "breathing": wouldn't get here otherwise */ 1130. You("are breathing poison gas!"); 1131. mkn = TRUE; 1132. } 1133. break; 1134. case AMULET_OF_STRANGULATION: 1135. setworn((struct obj *) 0, W_AMUL); 1136. off_msg(amul); 1137. early_off_msg = TRUE; 1138. 1139. if (Strangled) { 1140. Strangled = 0L; 1141. disp.botl = TRUE; 1142. if (Breathless) 1143. Your("%s is no longer constricted!", body_part(NECK)); 1144. else 1145. You("can breathe more easily!"); 1146. mkn = TRUE; 1147. } 1148. break; 1149. case AMULET_OF_RESTFUL_SLEEP: 1150. setworn((struct obj *) 0, W_AMUL); 1151. /* HSleepy = 0L; -- avoid clobbering FROMOUTSIDE bit */ 1152. if (!ESleepy && !(HSleepy & ~TIMEOUT)) 1153. HSleepy &= ~TIMEOUT; /* clear timeout bits */ 1154. break; 1155. case AMULET_OF_FLYING: { 1156. boolean was_flying = !!Flying; 1157. 1158. /* remove amulet 'early' to determine whether Flying changes; 1159. also in case spoteffects() does something with the amulet */ 1160. setworn((struct obj *) 0, W_AMUL); 1161. off_msg(amul); 1162. early_off_msg = TRUE; 1163. 1164. float_vs_flight(); /* probably not needed here */ 1165. if (was_flying && !Flying) { 1166. disp.botl = TRUE; /* status: 'Fly' Off */ 1167. You("%s.", (is_pool_or_lava(u.ux, u.uy) 1168. || Is_waterlevel(&u.uz) || Is_airlevel(&u.uz)) 1169. ? "stop flying" 1170. : "land"); 1171. mkn = TRUE; /* makeknown(AMULET_OF_FLYING) */ 1172. spoteffects(TRUE); 1173. } 1174. break; 1175. } 1176. case AMULET_OF_GUARDING: 1177. find_ac(); 1178. break; 1179. case AMULET_OF_YENDOR: 1180. break; 1181. } 1182. 1183. setworn((struct obj *) 0, W_AMUL); 1184. if (!early_off_msg) 1185. off_msg(amul); /* (not 'uamul'; it's Null now) */ 1186. if (mkn) 1187. makeknown(amul->otyp); 1188. return; 1189. } 1190. 1191. /* handle ring discovery; comparable to learnwand() */ 1192. staticfn void 1193. learnring(struct obj *ring, boolean observed) 1194. { 1195. int ringtype = ring->otyp; 1196. 1197. /* if effect was observable then we usually discover the type */ 1198. if (observed) { 1199. /* if we already know the ring type which accomplishes this 1200. effect (assumes there is at most one type for each effect), 1201. mark this ring as having been seen (no need for makeknown); 1202. otherwise if we have seen this ring, discover its type */ 1203. if (objects[ringtype].oc_name_known) 1204. observe_object(ring); 1205. else if (ring->dknown) 1206. makeknown(ringtype); 1207. #if 0 /* see learnwand() */ 1208. else 1209. observe_object(ring); 1210. #endif 1211. } 1212. 1213. /* make enchantment of charged ring known (might be +0) and update 1214. perm invent window if we've seen this ring and know its type */ 1215. if (ring->dknown && objects[ringtype].oc_name_known) { 1216. if (objects[ringtype].oc_charged) 1217. ring->known = 1; 1218. update_inventory(); 1219. } 1220. } 1221. 1222. staticfn void 1223. adjust_attrib(struct obj *obj, int which, int val) 1224. { 1225. int old_attrib; 1226. boolean observable; 1227. 1228. old_attrib = ACURR(which); 1229. ABON(which) += val; 1230. observable = (old_attrib != ACURR(which)); 1231. /* if didn't change, usually means ring is +0 but might 1232. be because nonzero couldn't go below min or above max; 1233. learn +0 enchantment if attribute value is not stuck 1234. at a limit [and ring has been seen and its type is 1235. already discovered, both handled by learnring()] */ 1236. if (observable || !extremeattr(which)) 1237. learnring(obj, observable); 1238. disp.botl = TRUE; 1239. } 1240. 1241. void 1242. Ring_on(struct obj *obj) 1243. { 1244. long oldprop = u.uprops[objects[obj->otyp].oc_oprop].extrinsic; 1245. boolean observable; 1246. 1247. /* make sure ring isn't wielded; can't use remove_worn_item() 1248. here because it has already been set worn in a ring slot */ 1249. if (obj == uwep) 1250. setuwep((struct obj *) 0); 1251. else if (obj == uswapwep) 1252. setuswapwep((struct obj *) 0); 1253. else if (obj == uquiver) 1254. setuqwep((struct obj *) 0); 1255. 1256. /* only mask out W_RING when we don't have both 1257. left and right rings of the same type */ 1258. if ((oldprop & W_RING) != W_RING) 1259. oldprop &= ~W_RING; 1260. 1261. switch (obj->otyp) { 1262. case RIN_TELEPORTATION: 1263. case RIN_REGENERATION: 1264. case RIN_SEARCHING: 1265. case RIN_HUNGER: 1266. case RIN_AGGRAVATE_MONSTER: 1267. case RIN_POISON_RESISTANCE: 1268. case RIN_FIRE_RESISTANCE: 1269. case RIN_COLD_RESISTANCE: 1270. case RIN_SHOCK_RESISTANCE: 1271. case RIN_CONFLICT: 1272. case RIN_TELEPORT_CONTROL: 1273. case RIN_POLYMORPH: 1274. case RIN_POLYMORPH_CONTROL: 1275. case RIN_FREE_ACTION: 1276. case RIN_SLOW_DIGESTION: 1277. case RIN_SUSTAIN_ABILITY: 1278. break; 1279. case MEAT_RING: 1280. /* wearing a meat ring does not affect vegan conduct */ 1281. break; 1282. case RIN_STEALTH: 1283. toggle_stealth(obj, oldprop, TRUE); 1284. break; 1285. case RIN_WARNING: 1286. see_monsters(); 1287. break; 1288. case RIN_SEE_INVISIBLE: 1289. /* can now see invisible monsters */ 1290. set_mimic_blocking(); /* do special mimic handling */ 1291. see_monsters(); 1292. 1293. if (Invis && !oldprop && !HSee_invisible && !Blind) { 1294. newsym(u.ux, u.uy); 1295. pline("Suddenly you are transparent, but there!"); 1296. learnring(obj, TRUE); 1297. } 1298. break; 1299. case RIN_INVISIBILITY: 1300. if (!oldprop && !HInvis && !BInvis && !Blind) { 1301. learnring(obj, TRUE); 1302. newsym(u.ux, u.uy); 1303. self_invis_message(); 1304. } 1305. break; 1306. case RIN_LEVITATION: 1307. if (!oldprop && !HLevitation && !(BLevitation & FROMOUTSIDE)) { 1308. float_up(); 1309. learnring(obj, TRUE); 1310. if (Levitation) 1311. spoteffects(FALSE); /* for sinks */ 1312. } else { 1313. float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ 1314. } 1315. break; 1316. case RIN_GAIN_STRENGTH: 1317. adjust_attrib(obj, A_STR, obj->spe); 1318. break; 1319. case RIN_GAIN_CONSTITUTION: 1320. adjust_attrib(obj, A_CON, obj->spe); 1321. break; 1322. case RIN_ADORNMENT: 1323. adjust_attrib(obj, A_CHA, obj->spe); 1324. break; 1325. case RIN_INCREASE_ACCURACY: /* KMH */ 1326. u.uhitinc += obj->spe; 1327. break; 1328. case RIN_INCREASE_DAMAGE: 1329. u.udaminc += obj->spe; 1330. break; 1331. case RIN_PROTECTION_FROM_SHAPE_CHAN: 1332. rescham(); 1333. break; 1334. case RIN_PROTECTION: 1335. /* usually learn enchantment and discover type; 1336. won't happen if ring is unseen or if it's +0 1337. and the type hasn't been discovered yet */ 1338. observable = (obj->spe != 0); 1339. learnring(obj, observable); 1340. if (obj->spe) 1341. find_ac(); /* updates botl */ 1342. break; 1343. } 1344. } 1345. 1346. staticfn void 1347. Ring_off_or_gone(struct obj *obj, boolean gone) 1348. { 1349. long mask = (obj->owornmask & W_RING); 1350. boolean observable; 1351. 1352. svc.context.takeoff.mask &= ~mask; 1353. if (!(u.uprops[objects[obj->otyp].oc_oprop].extrinsic & mask)) 1354. impossible("Strange... I didn't know you had that ring."); 1355. if (gone) 1356. setnotworn(obj); 1357. else 1358. setworn((struct obj *) 0, obj->owornmask); 1359. 1360. switch (obj->otyp) { 1361. case RIN_TELEPORTATION: 1362. case RIN_REGENERATION: 1363. case RIN_SEARCHING: 1364. case RIN_HUNGER: 1365. case RIN_AGGRAVATE_MONSTER: 1366. case RIN_POISON_RESISTANCE: 1367. case RIN_FIRE_RESISTANCE: 1368. case RIN_COLD_RESISTANCE: 1369. case RIN_SHOCK_RESISTANCE: 1370. case RIN_CONFLICT: 1371. case RIN_TELEPORT_CONTROL: 1372. case RIN_POLYMORPH: 1373. case RIN_POLYMORPH_CONTROL: 1374. case RIN_FREE_ACTION: 1375. case RIN_SLOW_DIGESTION: 1376. case RIN_SUSTAIN_ABILITY: 1377. case MEAT_RING: 1378. break; 1379. case RIN_STEALTH: 1380. toggle_stealth(obj, (EStealth & ~mask), FALSE); 1381. break; 1382. case RIN_WARNING: 1383. see_monsters(); 1384. break; 1385. case RIN_SEE_INVISIBLE: 1386. /* Make invisible monsters go away */ 1387. if (!See_invisible) { 1388. set_mimic_blocking(); /* do special mimic handling */ 1389. see_monsters(); 1390. } 1391. 1392. if (Invisible && !Blind) { 1393. newsym(u.ux, u.uy); 1394. pline("Suddenly you cannot see yourself."); 1395. learnring(obj, TRUE); 1396. } 1397. break; 1398. case RIN_INVISIBILITY: 1399. if (!Invis && !BInvis && !Blind) { 1400. newsym(u.ux, u.uy); 1401. Your("body seems to unfade%s.", 1402. See_invisible ? " completely" : ".."); 1403. learnring(obj, TRUE); 1404. } 1405. break; 1406. case RIN_LEVITATION: 1407. if (!(BLevitation & FROMOUTSIDE)) { 1408. (void) float_down(0L, 0L); 1409. if (!Levitation) 1410. learnring(obj, TRUE); 1411. } else { 1412. float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */ 1413. } 1414. break; 1415. case RIN_GAIN_STRENGTH: 1416. adjust_attrib(obj, A_STR, -obj->spe); 1417. break; 1418. case RIN_GAIN_CONSTITUTION: 1419. adjust_attrib(obj, A_CON, -obj->spe); 1420. break; 1421. case RIN_ADORNMENT: 1422. adjust_attrib(obj, A_CHA, -obj->spe); 1423. break; 1424. case RIN_INCREASE_ACCURACY: /* KMH */ 1425. u.uhitinc -= obj->spe; 1426. break; 1427. case RIN_INCREASE_DAMAGE: 1428. u.udaminc -= obj->spe; 1429. break; 1430. case RIN_PROTECTION: 1431. /* might have been put on while blind and we can now see 1432. or perhaps been forgotten due to amnesia */ 1433. observable = (obj->spe != 0); 1434. learnring(obj, observable); 1435. if (obj->spe) 1436. find_ac(); /* updates botl */ 1437. break; 1438. case RIN_PROTECTION_FROM_SHAPE_CHAN: 1439. /* if you're no longer protected, let the chameleons change 1440. shape again; however, might still be protected if wearing 1441. 2nd ring of this type (or via #wizintrinsic) */ 1442. if (!Protection_from_shape_changers) 1443. restartcham(); 1444. break; 1445. } 1446. } 1447. 1448. void 1449. Ring_off(struct obj *obj) 1450. { 1451. Ring_off_or_gone(obj, FALSE); 1452. } 1453. 1454. void 1455. Ring_gone(struct obj *obj) 1456. { 1457. Ring_off_or_gone(obj, TRUE); 1458. } 1459. 1460. void 1461. Blindf_on(struct obj *otmp) 1462. { 1463. boolean already_blind = Blind, changed = FALSE; 1464. 1465. /* blindfold might be wielded; release it for wearing */ 1466. remove_worn_item(otmp, FALSE); 1467. setworn(otmp, W_TOOL); 1468. on_msg(otmp); 1469. 1470. if (Blind && !already_blind) { 1471. changed = TRUE; 1472. if (flags.verbose) 1473. You_cant("see any more."); 1474. /* set ball&chain variables before the hero goes blind */ 1475. if (Punished) 1476. set_bc(0); 1477. } else if (already_blind && !Blind) { 1478. changed = TRUE; 1479. /* "You are now wearing the Eyes of the Overworld." */ 1480. if (u.uroleplay.blind) { 1481. /* this can only happen by putting on the Eyes of the Overworld; 1482. that shouldn't actually produce a permanent cure, but we 1483. can't let the "blind from birth" conduct remain intact */ 1484. pline("For the first time in your life, you can see!"); 1485. u.uroleplay.blind = FALSE; 1486. } else 1487. You("can see!"); 1488. } 1489. if (changed) { 1490. toggle_blindness(); /* potion.c */ 1491. } 1492. } 1493. 1494. void 1495. Blindf_off(struct obj *otmp) 1496. { 1497. boolean was_blind = Blind, changed = FALSE, 1498. nooffmsg = !otmp; 1499. 1500. if (!otmp) 1501. otmp = ublindf; 1502. if (!otmp) { 1503. impossible("Blindf_off without eyewear?"); 1504. return; 1505. } 1506. svc.context.takeoff.mask &= ~W_TOOL; 1507. setworn((struct obj *) 0, otmp->owornmask); 1508. if (!nooffmsg) 1509. off_msg(otmp); 1510. 1511. if (Blind) { 1512. if (was_blind) { 1513. /* "still cannot see" makes no sense when removing lenses 1514. since they can't have been the cause of your blindness */ 1515. if (otmp->otyp != LENSES) 1516. You("still cannot see."); 1517. } else { 1518. changed = TRUE; /* !was_blind */ 1519. /* "You were wearing the Eyes of the Overworld." */ 1520. You_cant("see anything now!"); 1521. /* set ball&chain variables before the hero goes blind */ 1522. if (Punished) 1523. set_bc(0); 1524. } 1525. } else if (was_blind) { 1526. if (!gulp_blnd_check()) { 1527. changed = TRUE; /* !Blind */ 1528. You("can see again."); 1529. } 1530. } 1531. if (changed) { 1532. toggle_blindness(); /* potion.c */ 1533. } 1534. } 1535. 1536. /* called in moveloop()'s prologue to set side-effects of worn start-up items; 1537. also used by poly_obj() when a worn item gets transformed */ 1538. void 1539. set_wear( 1540. struct obj *obj) /* if Null, do all worn items; otherwise just obj */ 1541. { 1542. gi.initial_don = !obj; 1543. 1544. if (!obj ? ublindf != 0 : (obj == ublindf)) 1545. (void) Blindf_on(ublindf); 1546. if (!obj ? uright != 0 : (obj == uright)) 1547. (void) Ring_on(uright); 1548. if (!obj ? uleft != 0 : (obj == uleft)) 1549. (void) Ring_on(uleft); 1550. if (!obj ? uamul != 0 : (obj == uamul)) 1551. (void) Amulet_on(uamul); 1552. 1553. if (!obj ? uarmu != 0 : (obj == uarmu)) 1554. (void) Shirt_on(); 1555. if (!obj ? uarm != 0 : (obj == uarm)) 1556. (void) Armor_on(); 1557. if (!obj ? uarmc != 0 : (obj == uarmc)) 1558. (void) Cloak_on(); 1559. if (!obj ? uarmf != 0 : (obj == uarmf)) 1560. (void) Boots_on(); 1561. if (!obj ? uarmg != 0 : (obj == uarmg)) 1562. (void) Gloves_on(); 1563. if (!obj ? uarmh != 0 : (obj == uarmh)) 1564. (void) Helmet_on(); 1565. if (!obj ? uarms != 0 : (obj == uarms)) 1566. (void) Shield_on(); 1567. 1568. gi.initial_don = FALSE; 1569. } 1570. 1571. /* check whether the target object is currently being put on (or taken off-- 1572. also checks for doffing--[why?]) */ 1573. boolean 1574. donning(struct obj *otmp) 1575. { 1576. boolean result = FALSE; 1577. 1578. /* 'W' (or 'P' used for armor) sets ga.afternmv */ 1579. if (doffing(otmp)) 1580. result = TRUE; 1581. else if (otmp == uarm) 1582. result = (ga.afternmv == Armor_on); 1583. else if (otmp == uarmu) 1584. result = (ga.afternmv == Shirt_on); 1585. else if (otmp == uarmc) 1586. result = (ga.afternmv == Cloak_on); 1587. else if (otmp == uarmf) 1588. result = (ga.afternmv == Boots_on); 1589. else if (otmp == uarmh) 1590. result = (ga.afternmv == Helmet_on); 1591. else if (otmp == uarmg) 1592. result = (ga.afternmv == Gloves_on); 1593. else if (otmp == uarms) 1594. result = (ga.afternmv == Shield_on); 1595. 1596. return result; 1597. } 1598. 1599. /* check whether the target object is currently being taken off, 1600. so that stop_donning() and steal() can vary messages and doname() 1601. can vary "(being worn)" suffix */ 1602. boolean 1603. doffing(struct obj *otmp) 1604. { 1605. long what = svc.context.takeoff.what; 1606. boolean result = FALSE; 1607. 1608. /* 'T' (or 'R' used for armor) sets ga.afternmv, 'A' sets takeoff.what */ 1609. if (otmp == uarm) 1610. result = (ga.afternmv == Armor_off || what == WORN_ARMOR); 1611. else if (otmp == uarmu) 1612. result = (ga.afternmv == Shirt_off || what == WORN_SHIRT); 1613. else if (otmp == uarmc) 1614. result = (ga.afternmv == Cloak_off || what == WORN_CLOAK); 1615. else if (otmp == uarmf) 1616. result = (ga.afternmv == Boots_off || what == WORN_BOOTS); 1617. else if (otmp == uarmh) 1618. result = (ga.afternmv == Helmet_off || what == WORN_HELMET); 1619. else if (otmp == uarmg) 1620. result = (ga.afternmv == Gloves_off || what == WORN_GLOVES); 1621. else if (otmp == uarms) 1622. result = (ga.afternmv == Shield_off || what == WORN_SHIELD); 1623. /* these 1-turn items don't need 'ga.afternmv' checks */ 1624. else if (otmp == uamul) 1625. result = (what == WORN_AMUL); 1626. else if (otmp == uleft) 1627. result = (what == LEFT_RING); 1628. else if (otmp == uright) 1629. result = (what == RIGHT_RING); 1630. else if (otmp == ublindf) 1631. result = (what == WORN_BLINDF); 1632. else if (otmp == uwep) 1633. result = (what == W_WEP); 1634. else if (otmp == uswapwep) 1635. result = (what == W_SWAPWEP); 1636. else if (otmp == uquiver) 1637. result = (what == W_QUIVER); 1638. 1639. return result; 1640. } 1641. 1642. /* despite their names, cancel_don() and cancel_doff() both apply to both 1643. donning and doffing... */ 1644. void 1645. cancel_doff(struct obj *obj, long slotmask) 1646. { 1647. /* Called by setworn() for old item in specified slot or by setnotworn() 1648. * for specified item. We don't want to call cancel_don() if we got 1649. * here via <X>_off() -> setworn((struct obj *) 0) -> cancel_doff() 1650. * because that would stop the 'A' command from continuing with next 1651. * selected item. So do_takeoff() sets a flag in takeoff.mask for us. 1652. * [For taking off an individual item with 'T'/'R'/'w-', it doesn't 1653. * matter whether cancel_don() gets called here--the item has already 1654. * been removed by now.] 1655. */ 1656. if (!(svc.context.takeoff.mask & I_SPECIAL) && donning(obj)) 1657. cancel_don(); /* applies to doffing too */ 1658. svc.context.takeoff.mask &= ~slotmask; 1659. } 1660. 1661. /* despite their names, cancel_don() and cancel_doff() both apply to both 1662. donning and doffing... */ 1663. void 1664. cancel_don(void) 1665. { 1666. /* the piece of armor we were donning/doffing has vanished, so stop 1667. * wasting time on it (and don't dereference it when donning would 1668. * otherwise finish); afternmv never has some of these values because 1669. * every item of the corresponding armor category takes 1 turn to wear, 1670. * but check all of them anyway 1671. */ 1672. svc.context.takeoff.cancelled_don = (ga.afternmv == Cloak_on 1673. || ga.afternmv == Armor_on 1674. || ga.afternmv == Shirt_on 1675. || ga.afternmv == Helmet_on 1676. || ga.afternmv == Gloves_on 1677. || ga.afternmv == Boots_on 1678. || ga.afternmv == Shield_on); 1679. ga.afternmv = (int (*)(void)) 0; 1680. gn.nomovemsg = (char *) 0; 1681. gm.multi = 0; 1682. svc.context.takeoff.delay = 0; 1683. svc.context.takeoff.what = 0L; 1684. } 1685. 1686. /* called by steal() during theft from hero; interrupt donning/doffing */ 1687. int 1688. stop_donning( 1689. struct obj *stolenobj) /* no mesg if stolenobj is already being doffed */ 1690. { 1691. char buf[BUFSZ]; 1692. struct obj *otmp; 1693. boolean putting_on; 1694. int result = 0; 1695. 1696. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 1697. if ((otmp->owornmask & W_ARMOR) && donning(otmp)) 1698. break; 1699. /* at most one item will pass donning() test at any given time */ 1700. if (!otmp) 1701. return 0; 1702. 1703. /* donning() returns True when doffing too; doffing() is more specific */ 1704. putting_on = !doffing(otmp); 1705. /* cancel_don() looks at afternmv; it can also cancel doffing */ 1706. cancel_don(); 1707. /* don't want <armor>_on() or <armor>_off() being called 1708. by unmul() since the on or off action isn't completing */ 1709. ga.afternmv = (int (*)(void)) 0; 1710. if (putting_on || otmp != stolenobj) { 1711. Sprintf(buf, "You stop %s %s.", 1712. putting_on ? "putting on" : "taking off", 1713. thesimpleoname(otmp)); 1714. } else { 1715. buf[0] = '\0'; /* silently stop doffing stolenobj */ 1716. result = (int) -gm.multi; /* remember this before calling unmul() */ 1717. } 1718. unmul(buf); 1719. /* while putting on, item becomes worn immediately but side-effects are 1720. deferred until the delay expires; when interrupted, make it unworn 1721. (while taking off, item stays worn until the delay expires; when 1722. interrupted, leave it worn) */ 1723. if (putting_on) 1724. remove_worn_item(otmp, FALSE); 1725. 1726. return result; 1727. } 1728. 1729. static NEARDATA int Narmorpieces, Naccessories; 1730. 1731. /* assign values to Narmorpieces and Naccessories */ 1732. staticfn void 1733. count_worn_stuff( 1734. struct obj **which, /* caller wants this when count is 1 */ 1735. boolean accessorizing) 1736. { 1737. struct obj *otmp; 1738. 1739. Narmorpieces = Naccessories = 0; 1740. 1741. #define MOREWORN(x,wtyp) do { if (x) { wtyp++; otmp = x; } } while (0) 1742. otmp = 0; 1743. MOREWORN(uarmh, Narmorpieces); 1744. MOREWORN(uarms, Narmorpieces); 1745. MOREWORN(uarmg, Narmorpieces); 1746. MOREWORN(uarmf, Narmorpieces); 1747. /* for cloak/suit/shirt, we only count the outermost item so that it 1748. can be taken off without confirmation if final count ends up as 1 */ 1749. if (uarmc) 1750. MOREWORN(uarmc, Narmorpieces); 1751. else if (uarm) 1752. MOREWORN(uarm, Narmorpieces); 1753. else if (uarmu) 1754. MOREWORN(uarmu, Narmorpieces); 1755. if (!accessorizing) 1756. *which = otmp; /* default item iff Narmorpieces is 1 */ 1757. 1758. otmp = 0; 1759. MOREWORN(uleft, Naccessories); 1760. MOREWORN(uright, Naccessories); 1761. MOREWORN(uamul, Naccessories); 1762. MOREWORN(ublindf, Naccessories); 1763. if (accessorizing) 1764. *which = otmp; /* default item iff Naccessories is 1 */ 1765. #undef MOREWORN 1766. } 1767. 1768. /* take off one piece or armor or one accessory; 1769. shared by dotakeoff('T') and doremring('R') */ 1770. staticfn int 1771. armor_or_accessory_off(struct obj *obj) 1772. { 1773. if (!(obj->owornmask & (W_ARMOR | W_ACCESSORY))) { 1774. You("are not wearing that."); 1775. return ECMD_OK; 1776. } 1777. if (obj == uskin 1778. || ((obj == uarm) && uarmc) 1779. || ((obj == uarmu) && (uarmc || uarm))) { 1780. char why[QBUFSZ], what[QBUFSZ]; 1781. 1782. why[0] = what[0] = '\0'; 1783. if (obj != uskin) { 1784. if (uarmc) 1785. Strcat(what, cloak_simple_name(uarmc)); 1786. if ((obj == uarmu) && uarm) { 1787. if (uarmc) 1788. Strcat(what, " and "); 1789. Strcat(what, suit_simple_name(uarm)); 1790. } 1791. Snprintf(why, sizeof why, " without taking off your %s first", 1792. what); 1793. } else { 1794. Strcpy(why, "; it's embedded"); 1795. } 1796. You_cant("take that off%s.", why); 1797. return ECMD_OK; 1798. } 1799. 1800. reset_remarm(); /* clear context.takeoff.mask and context.takeoff.what */ 1801. (void) select_off(obj); 1802. if (!svc.context.takeoff.mask) 1803. return ECMD_OK; 1804. /* none of armoroff()/Ring_/Amulet/Blindf_off() use context.takeoff.mask */ 1805. reset_remarm(); 1806. 1807. if (obj->owornmask & W_ARMOR) { 1808. (void) armoroff(obj); 1809. } else if (obj == uright || obj == uleft) { 1810. /* Sometimes we want to give the off_msg before removing and 1811. * sometimes after; for instance, "you were wearing a moonstone 1812. * ring (on right hand)" is desired but "you were wearing a 1813. * square amulet (being worn)" is not because of the redundant 1814. * "being worn". 1815. */ 1816. off_msg(obj); 1817. Ring_off(obj); 1818. } else if (obj == uamul) { 1819. Amulet_off(); /* does its own off_msg */ 1820. } else if (obj == ublindf) { 1821. Blindf_off(obj); /* does its own off_msg */ 1822. } else { 1823. impossible("removing strange accessory: %s", 1824. safe_typename(obj->otyp)); 1825. if (obj->owornmask) 1826. remove_worn_item(obj, FALSE); 1827. } 1828. return ECMD_TIME; 1829. } 1830. 1831. /* the #takeoff command - remove worn armor */ 1832. int 1833. dotakeoff(void) 1834. { 1835. struct obj *otmp = (struct obj *) 0; 1836. 1837. count_worn_stuff(&otmp, FALSE); 1838. if (!Narmorpieces && !Naccessories) { 1839. /* assert( GRAY_DRAGON_SCALES > YELLOW_DRAGON_SCALE_MAIL ); */ 1840. if (uskin) 1841. pline_The("%s merged with your skin!", 1842. uskin->otyp >= GRAY_DRAGON_SCALES 1843. ? "dragon scales are" 1844. : "dragon scale mail is"); 1845. else 1846. pline("Not wearing any armor or accessories."); 1847. return ECMD_OK; 1848. } 1849. if (Narmorpieces != 1 || ParanoidRemove || gi.item_action_in_progress) 1850. otmp = getobj("take off", takeoff_ok, GETOBJ_NOFLAGS); 1851. if (!otmp) 1852. return ECMD_CANCEL; 1853. 1854. return armor_or_accessory_off(otmp); 1855. } 1856. 1857. /* 'i' or 'I[' followed by <invlet> and then 'T'; 1858. plain dotakeoff() would not give any feedback when picking suit 1859. covered by cloak, or shirt covered by suit and/or cloak, due to the 1860. default behavior of equip_ok() (skipping inaccessible items) */ 1861. int 1862. ia_dotakeoff(void) 1863. { 1864. int res; 1865. 1866. gi.item_action_in_progress = TRUE; 1867. res = dotakeoff(); 1868. gi.item_action_in_progress = FALSE; 1869. return res; 1870. } 1871. 1872. /* the #remove command - take off ring or other accessory */ 1873. int 1874. doremring(void) 1875. { 1876. struct obj *otmp = 0; 1877. 1878. count_worn_stuff(&otmp, TRUE); 1879. if (!Naccessories && !Narmorpieces) { 1880. pline("Not wearing any accessories or armor."); 1881. return ECMD_OK; 1882. } 1883. if (Naccessories != 1 || ParanoidRemove || cmdq_peek(CQ_CANNED)) 1884. otmp = getobj("remove", remove_ok, GETOBJ_NOFLAGS); 1885. if (!otmp) 1886. return ECMD_CANCEL; 1887. 1888. return armor_or_accessory_off(otmp); 1889. } 1890. 1891. /* Check if something worn is cursed _and_ unremovable. */ 1892. int 1893. cursed(struct obj *otmp) 1894. { 1895. if (!otmp) { 1896. impossible("cursed without otmp"); 1897. return 0; 1898. } 1899. /* Curses, like chickens, come home to roost. */ 1900. if ((otmp == uwep) ? welded(otmp) : (int) otmp->cursed) { 1901. boolean use_plural = (is_boots(otmp) || is_gloves(otmp) 1902. || otmp->otyp == LENSES || otmp->quan > 1L); 1903. 1904. /* might be trying again after applying grease to hands */ 1905. if (Glib && otmp->bknown 1906. /* for weapon, we'll only get here via 'A )' */ 1907. && (uarmg ? (otmp == uwep) 1908. : ((otmp->owornmask & (W_WEP | W_RING)) != 0))) 1909. pline("Despite your slippery %s, you can't.", 1910. fingers_or_gloves(TRUE)); 1911. else 1912. You("can't. %s cursed.", use_plural ? "They are" : "It is"); 1913. set_bknown(otmp, 1); 1914. return 1; 1915. } 1916. return 0; 1917. } 1918. 1919. int 1920. armoroff(struct obj *otmp) 1921. { 1922. static char offdelaybuf[60]; 1923. int delay = -objects[otmp->otyp].oc_delay; 1924. const char *what = 0; 1925. 1926. if (cursed(otmp)) 1927. return 0; 1928. /* this used to make assumptions about which types of armor had 1929. delays and which didn't; now both are handled for all types */ 1930. if (delay) { 1931. nomul(delay); 1932. gm.multi_reason = "disrobing"; 1933. switch (objects[otmp->otyp].oc_armcat) { 1934. case ARM_SUIT: 1935. what = suit_simple_name(otmp); 1936. ga.afternmv = Armor_off; 1937. break; 1938. case ARM_SHIELD: 1939. what = shield_simple_name(otmp); 1940. ga.afternmv = Shield_off; 1941. break; 1942. case ARM_HELM: 1943. what = helm_simple_name(otmp); 1944. ga.afternmv = Helmet_off; 1945. break; 1946. case ARM_GLOVES: 1947. what = gloves_simple_name(otmp); 1948. ga.afternmv = Gloves_off; 1949. break; 1950. case ARM_BOOTS: 1951. what = boots_simple_name(otmp); 1952. ga.afternmv = Boots_off; 1953. break; 1954. case ARM_CLOAK: 1955. what = cloak_simple_name(otmp); 1956. ga.afternmv = Cloak_off; 1957. break; 1958. case ARM_SHIRT: 1959. what = shirt_simple_name(otmp); 1960. ga.afternmv = Shirt_off; 1961. break; 1962. default: 1963. impossible("Taking off unknown armor (%d: %d), delay %d", 1964. otmp->otyp, objects[otmp->otyp].oc_armcat, delay); 1965. break; 1966. } 1967. if (what) { 1968. /* sizeof offdelaybuf == 60; increase it if this becomes longer */ 1969. Snprintf(offdelaybuf, sizeof offdelaybuf, 1970. "You finish taking off your %s.", what); 1971. gn.nomovemsg = offdelaybuf; 1972. } 1973. } else { 1974. /* no delay so no '(*afternmv)()' or 'nomovemsg' */ 1975. switch (objects[otmp->otyp].oc_armcat) { 1976. case ARM_SUIT: 1977. (void) Armor_off(); 1978. break; 1979. case ARM_SHIELD: 1980. (void) Shield_off(); 1981. break; 1982. case ARM_HELM: 1983. (void) Helmet_off(); 1984. break; 1985. case ARM_GLOVES: 1986. (void) Gloves_off(); 1987. break; 1988. case ARM_BOOTS: 1989. (void) Boots_off(); 1990. break; 1991. case ARM_CLOAK: 1992. (void) Cloak_off(); 1993. break; 1994. case ARM_SHIRT: 1995. (void) Shirt_off(); 1996. break; 1997. default: 1998. impossible("Taking off unknown armor (%d: %d), no delay", 1999. otmp->otyp, objects[otmp->otyp].oc_armcat); 2000. break; 2001. } 2002. /* We want off_msg() after removing the item to 2003. avoid "You were wearing ____ (being worn)." */ 2004. off_msg(otmp); 2005. } 2006. svc.context.takeoff.mask = svc.context.takeoff.what = 0L; 2007. return 1; 2008. } 2009. 2010. staticfn void 2011. already_wearing(const char *cc) 2012. { 2013. You("are already wearing %s%c", cc, (cc == c_that_) ? '!' : '.'); 2014. } 2015. 2016. staticfn void 2017. already_wearing2(const char *cc1, const char *cc2) 2018. { 2019. You_cant("wear %s because you're wearing %s there already.", cc1, cc2); 2020. } 2021. 2022. /* 2023. * canwearobj checks to see whether the player can wear a piece of armor 2024. * 2025. * inputs: otmp (the piece of armor) 2026. * noisy (if TRUE give error messages, otherwise be quiet about it) 2027. * output: mask (otmp's armor type) 2028. */ 2029. int 2030. canwearobj(struct obj *otmp, long *mask, boolean noisy) 2031. { 2032. int err = 0; 2033. const char *which; 2034. 2035. /* this is the same check as for 'W' (dowear), but different message, 2036. in case we get here via 'P' (doputon) */ 2037. if (verysmall(gy.youmonst.data) || nohands(gy.youmonst.data)) { 2038. if (noisy) 2039. You("can't wear any armor in your current form."); 2040. return 0; 2041. } 2042. 2043. which = is_cloak(otmp) ? c_cloak 2044. : is_shirt(otmp) ? c_shirt 2045. : is_suit(otmp) ? c_suit 2046. : 0; 2047. if (which && cantweararm(gy.youmonst.data) 2048. /* same exception for cloaks as used in m_dowear() */ 2049. && (which != c_cloak 2050. || ((otmp->otyp != MUMMY_WRAPPING) 2051. ? gy.youmonst.data->msize != MZ_SMALL 2052. : !WrappingAllowed(gy.youmonst.data))) 2053. && (racial_exception(&gy.youmonst, otmp) < 1)) { 2054. if (noisy) 2055. pline_The("%s will not fit on your body.", which); 2056. return 0; 2057. } else if (otmp->owornmask & W_ARMOR) { 2058. if (noisy) 2059. already_wearing(c_that_); 2060. return 0; 2061. } 2062. 2063. if (welded(uwep) && bimanual(uwep) && (is_suit(otmp) || is_shirt(otmp))) { 2064. if (noisy) 2065. You("cannot do that while holding your %s.", 2066. is_sword(uwep) ? c_sword : c_weapon); 2067. return 0; 2068. } 2069. 2070. if (is_helmet(otmp)) { 2071. if (uarmh) { 2072. if (noisy) 2073. already_wearing(an(helm_simple_name(uarmh))); 2074. err++; 2075. } else if (Upolyd && has_horns(gy.youmonst.data) && !is_flimsy(otmp)) { 2076. /* (flimsy exception matches polyself handling) */ 2077. if (noisy) 2078. pline_The("%s won't fit over your horn%s.", 2079. helm_simple_name(otmp), 2080. plur(num_horns(gy.youmonst.data))); 2081. err++; 2082. } else 2083. *mask = W_ARMH; 2084. } else if (is_shield(otmp)) { 2085. if (uarms) { 2086. if (noisy) 2087. already_wearing(an(c_shield)); 2088. err++; 2089. } else if (uwep && bimanual(uwep)) { 2090. if (noisy) 2091. You("cannot wear a shield while wielding a two-handed %s.", 2092. is_sword(uwep) ? c_sword : (uwep->otyp == BATTLE_AXE) 2093. ? c_axe 2094. : c_weapon); 2095. err++; 2096. } else if (u.twoweap) { 2097. if (noisy) 2098. You("cannot wear a shield while wielding two weapons."); 2099. err++; 2100. } else 2101. *mask = W_ARMS; 2102. } else if (is_boots(otmp)) { 2103. if (uarmf) { 2104. if (noisy) 2105. already_wearing(c_boots); 2106. err++; 2107. } else if (Upolyd && slithy(gy.youmonst.data)) { 2108. if (noisy) 2109. You("have no feet..."); /* not body_part(FOOT) */ 2110. err++; 2111. } else if (Upolyd && gy.youmonst.data->mlet == S_CENTAUR) { 2112. /* break_armor() pushes boots off for centaurs, so don't let 2113. dowear() put them back on; 2114. makeplural(body_part(FOOT)) would yield "rear hooves" here, 2115. which sounds odd, so use hard-coded "hooves" */ 2116. if (noisy) 2117. You("have too many hooves to wear %s.", c_boots); 2118. err++; 2119. } else if (u.utrap 2120. && (u.utraptype == TT_BEARTRAP || u.utraptype == TT_INFLOOR 2121. || u.utraptype == TT_LAVA 2122. || u.utraptype == TT_BURIEDBALL)) { 2123. if (u.utraptype == TT_BEARTRAP) { 2124. if (noisy) 2125. Your("%s is trapped!", body_part(FOOT)); 2126. } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) { 2127. if (noisy) 2128. Your("%s are stuck in the %s!", 2129. makeplural(body_part(FOOT)), surface(u.ux, u.uy)); 2130. } else { /*TT_BURIEDBALL*/ 2131. if (noisy) 2132. Your("%s is attached to the buried ball!", 2133. body_part(LEG)); 2134. } 2135. err++; 2136. } else 2137. *mask = W_ARMF; 2138. } else if (is_gloves(otmp)) { 2139. if (uarmg) { 2140. if (noisy) 2141. already_wearing(c_gloves); 2142. err++; 2143. } else if (welded(uwep)) { 2144. if (noisy) 2145. You("cannot wear gloves over your %s.", 2146. is_sword(uwep) ? c_sword : c_weapon); 2147. err++; 2148. } else if (Glib) { 2149. /* prevent slippery bare fingers from transferring to 2150. gloved fingers */ 2151. if (noisy) 2152. Your("%s are too slippery to pull on %s.", 2153. fingers_or_gloves(FALSE), gloves_simple_name(otmp)); 2154. err++; 2155. } else 2156. *mask = W_ARMG; 2157. } else if (is_shirt(otmp)) { 2158. if (uarm || uarmc || uarmu) { 2159. if (uarmu) { 2160. if (noisy) 2161. already_wearing(an(c_shirt)); 2162. } else { 2163. if (noisy) 2164. You_cant("wear that over your %s.", 2165. (uarm && !uarmc) ? c_armor 2166. : cloak_simple_name(uarmc)); 2167. } 2168. err++; 2169. } else 2170. *mask = W_ARMU; 2171. } else if (is_cloak(otmp)) { 2172. if (uarmc) { 2173. if (noisy) 2174. already_wearing(an(cloak_simple_name(uarmc))); 2175. err++; 2176. } else 2177. *mask = W_ARMC; 2178. } else if (is_suit(otmp)) { 2179. if (uarmc) { 2180. if (noisy) 2181. You("cannot wear armor over a %s.", cloak_simple_name(uarmc)); 2182. err++; 2183. } else if (uarm) { 2184. if (noisy) 2185. already_wearing("some armor"); 2186. err++; 2187. } else 2188. *mask = W_ARM; 2189. } else { 2190. /* getobj can't do this after setting its allow_all flag; that 2191. happens if you have armor for slots that are covered up or 2192. extra armor for slots that are filled */ 2193. if (noisy) 2194. silly_thing("wear", otmp); 2195. err++; 2196. } 2197. /* Unnecessary since now only weapons and special items like pick-axes get 2198. * welded to your hand, not armor 2199. if (welded(otmp)) { 2200. if (!err++) { 2201. if (noisy) weldmsg(otmp); 2202. } 2203. } 2204. */ 2205. return !err; 2206. } 2207. 2208. staticfn int 2209. accessory_or_armor_on(struct obj *obj) 2210. { 2211. long mask = 0L; 2212. boolean armor, ring, amulet, eyewear; 2213. 2214. if (obj->owornmask & (W_ACCESSORY | W_ARMOR)) { 2215. already_wearing(c_that_); 2216. return ECMD_OK; 2217. } 2218. armor = (obj->oclass == ARMOR_CLASS); 2219. ring = (obj->oclass == RING_CLASS || obj->otyp == MEAT_RING); 2220. amulet = (obj->oclass == AMULET_CLASS); 2221. eyewear = (obj->otyp == BLINDFOLD || obj->otyp == TOWEL 2222. || obj->otyp == LENSES); 2223. /* checks which are performed prior to actually touching the item */ 2224. if (armor) { 2225. if (!canwearobj(obj, &mask, TRUE)) 2226. return ECMD_OK; 2227. 2228. if (obj->otyp == HELM_OF_OPPOSITE_ALIGNMENT 2229. && qstart_level.dnum == u.uz.dnum) { /* in quest */ 2230. if (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL]) 2231. You("narrowly avoid losing all chance at your goal."); 2232. else /* converted */ 2233. You("are suddenly overcome with shame and change your mind."); 2234. u.ublessed = 0; /* lose your god's protection */ 2235. makeknown(obj->otyp); 2236. disp.botl = TRUE; /* for AC after zeroing u.ublessed */ 2237. return ECMD_TIME; 2238. } 2239. } else { 2240. /* 2241. * FIXME: 2242. * except for the rings/nolimbs case, this allows you to put on 2243. * accessories without having any hands to manipulate them, and 2244. * to put them on when poly'd into a tiny or huge form where 2245. * they shouldn't fit. [If the latter situation changes, make 2246. * comparable change to break_armor(polyself.c).] 2247. */ 2248. 2249. /* accessory */ 2250. if (ring) { 2251. char answer, qbuf[QBUFSZ]; 2252. int res = 0; 2253. 2254. if (nolimbs(gy.youmonst.data)) { 2255. You("cannot make the ring stick to your body."); 2256. return ECMD_OK; 2257. } 2258. if (uleft && uright) { 2259. There("are no more %s%s to fill.", 2260. humanoid(gy.youmonst.data) ? "ring-" : "", 2261. fingers_or_gloves(FALSE)); 2262. return ECMD_OK; 2263. } 2264. if (uleft) { 2265. mask = RIGHT_RING; 2266. } else if (uright) { 2267. mask = LEFT_RING; 2268. } else { 2269. do { 2270. Sprintf(qbuf, "Which %s%s, Right or Left?", 2271. humanoid(gy.youmonst.data) ? "ring-" : "", 2272. body_part(FINGER)); 2273. answer = yn_function(qbuf, rightleftchars, '\0', TRUE); 2274. switch (answer) { 2275. case '\0': 2276. case '\033': 2277. return ECMD_OK; 2278. case 'l': 2279. case 'L': 2280. mask = LEFT_RING; 2281. break; 2282. case 'r': 2283. case 'R': 2284. mask = RIGHT_RING; 2285. break; 2286. } 2287. } while (!mask); 2288. } 2289. if (uarmg && Glib) { 2290. Your( 2291. "%s are too slippery to remove, so you cannot put on the ring.", 2292. gloves_simple_name(uarmg)); 2293. return ECMD_TIME; /* always uses move */ 2294. } 2295. if (uarmg && uarmg->cursed) { 2296. res = !uarmg->bknown; 2297. set_bknown(uarmg, 1); 2298. You("cannot remove your %s to put on the ring.", c_gloves); 2299. /* uses move iff we learned gloves are cursed */ 2300. return res ? ECMD_TIME : ECMD_OK; 2301. } 2302. if (uwep) { 2303. res = !uwep->bknown; /* check this before calling welded() */ 2304. if (((mask == RIGHT_RING && URIGHTY) 2305. || (mask == LEFT_RING && ULEFTY) 2306. || bimanual(uwep)) && welded(uwep)) { 2307. const char *hand = body_part(HAND); 2308. 2309. /* welded will set bknown */ 2310. if (bimanual(uwep)) 2311. hand = makeplural(hand); 2312. You("cannot free your weapon %s to put on the ring.", 2313. hand); 2314. /* uses move iff we learned weapon is cursed */ 2315. return res ? ECMD_TIME : ECMD_OK; 2316. } 2317. } 2318. } else if (amulet) { 2319. if (uamul) { 2320. already_wearing("an amulet"); 2321. return ECMD_OK; 2322. } 2323. } else if (eyewear) { 2324. if (!has_head(gy.youmonst.data)) { 2325. You("have no head to wear %s on.", ansimpleoname(obj)); 2326. return ECMD_OK; 2327. } 2328. 2329. if (ublindf) { 2330. if (ublindf->otyp == TOWEL) 2331. Your("%s is already covered by a towel.", 2332. body_part(FACE)); 2333. else if (ublindf->otyp == BLINDFOLD) { 2334. if (obj->otyp == LENSES) 2335. already_wearing2("lenses", "a blindfold"); 2336. else 2337. already_wearing("a blindfold"); 2338. } else if (ublindf->otyp == LENSES) { 2339. if (obj->otyp == BLINDFOLD) 2340. already_wearing2("a blindfold", "some lenses"); 2341. else 2342. already_wearing("some lenses"); 2343. } else { 2344. already_wearing(something); /* ??? */ 2345. } 2346. return ECMD_OK; 2347. } 2348. } else { 2349. /* neither armor nor accessory */ 2350. You_cant("wear that!"); 2351. return ECMD_OK; 2352. } 2353. } 2354. 2355. if (!retouch_object(&obj, FALSE)) 2356. return ECMD_TIME; /* costs a turn even though it didn't get worn */ 2357. 2358. if (armor) { 2359. int delay; 2360. 2361. /* if the armor is wielded, release it for wearing (won't be 2362. welded even if cursed; that only happens for weapons/weptools) */ 2363. if (obj->owornmask & W_WEAPONS) 2364. remove_worn_item(obj, FALSE); 2365. /* 2366. * Setting obj->known=1 is done because setworn() causes hero's AC 2367. * to change so armor's +/- value is evident via the status line. 2368. * We used to set it here because of that, but then it would stick 2369. * if a nymph stole the armor before it was fully worn. Delay it 2370. * until the afternmv action. The player may still know this armor's 2371. * +/- amount if donning gets interrupted, but the hero won't. 2372. * 2373. obj->known = 1; 2374. */ 2375. gw.wasinwater = u.uinwater; /* for WWALKING; Boots_on() is too late */ 2376. setworn(obj, mask); 2377. /* if there's no delay, we'll execute 'afternmv' immediately */ 2378. if (obj == uarm) 2379. ga.afternmv = Armor_on; 2380. else if (obj == uarmh) 2381. ga.afternmv = Helmet_on; 2382. else if (obj == uarmg) 2383. ga.afternmv = Gloves_on; 2384. else if (obj == uarmf) 2385. ga.afternmv = Boots_on; 2386. else if (obj == uarms) 2387. ga.afternmv = Shield_on; 2388. else if (obj == uarmc) 2389. ga.afternmv = Cloak_on; 2390. else if (obj == uarmu) 2391. ga.afternmv = Shirt_on; 2392. else 2393. panic("wearing armor not worn as armor? [%08lx]", obj->owornmask); 2394. 2395. delay = -objects[obj->otyp].oc_delay; 2396. if (delay) { 2397. nomul(delay); 2398. gm.multi_reason = "dressing up"; 2399. gn.nomovemsg = "You finish your dressing maneuver."; 2400. } else { 2401. unmul(""); /* call afternmv, clear it+nomovemsg+multi_reason */ 2402. on_msg(obj); 2403. } 2404. svc.context.takeoff.mask = svc.context.takeoff.what = 0L; 2405. /* gw.wasinwater = 0U; // can't clear this yet; Boots_on() needs it 2406. * and gets called via afternmv() after this routine has returned */ 2407. } else { /* not armor */ 2408. if (ring) { 2409. /* Ring_on() expects ring to already be worn as uleft or uright */ 2410. setworn(obj, mask); 2411. Ring_on(obj); 2412. /* is_worn(): 'obj' will always be worn here except when putting 2413. on a ring of levitation while at a sink location */ 2414. if (is_worn(obj)) 2415. on_msg(obj); 2416. } else if (amulet) { 2417. /* setworn() and on_msg() handled by Amulet_on() */ 2418. Amulet_on(obj); 2419. } else if (eyewear) { 2420. /* setworn() and on_msg() handled by Blindf_on() */ 2421. Blindf_on(obj); 2422. } else { 2423. impossible("putting on unexpected type of accessory: %s", 2424. safe_typename(obj->otyp)); 2425. } 2426. } 2427. return ECMD_TIME; 2428. } 2429. 2430. /* the #wear command */ 2431. int 2432. dowear(void) 2433. { 2434. struct obj *otmp; 2435. 2436. /* cantweararm() checks for suits of armor, not what we want here; 2437. verysmall() or nohands() checks for shields, gloves, etc... */ 2438. if (verysmall(gy.youmonst.data) || nohands(gy.youmonst.data)) { 2439. pline("Don't even bother."); 2440. return ECMD_OK; 2441. } 2442. if (uarm && uarmu && uarmc && uarmh && uarms && uarmg && uarmf 2443. && uleft && uright && uamul && ublindf) { 2444. /* 'W' message doesn't mention accessories */ 2445. You("are already wearing a full complement of armor."); 2446. return ECMD_OK; 2447. } 2448. otmp = getobj("wear", wear_ok, GETOBJ_NOFLAGS); 2449. return otmp ? accessory_or_armor_on(otmp) : ECMD_CANCEL; 2450. } 2451. 2452. /* the #puton command */ 2453. int 2454. doputon(void) 2455. { 2456. struct obj *otmp; 2457. 2458. if (uleft && uright && uamul && ublindf 2459. && uarm && uarmu && uarmc && uarmh && uarms && uarmg && uarmf) { 2460. /* 'P' message doesn't mention armor */ 2461. Your("%s%s are full, and you're already wearing an amulet and %s.", 2462. humanoid(gy.youmonst.data) ? "ring-" : "", 2463. fingers_or_gloves(FALSE), 2464. (ublindf->otyp == LENSES) ? "some lenses" : "a blindfold"); 2465. return ECMD_OK; 2466. } 2467. otmp = getobj("put on", puton_ok, GETOBJ_NOFLAGS); 2468. return otmp ? accessory_or_armor_on(otmp) : ECMD_CANCEL; 2469. } 2470. 2471. /* calculate current armor class */ 2472. void 2473. find_ac(void) 2474. { 2475. int uac = mons[u.umonnum].ac; /* base armor class for current form */ 2476. 2477. /* armor class from worn gear */ 2478. if (uarm) 2479. uac -= ARM_BONUS(uarm); 2480. if (uarmc) 2481. uac -= ARM_BONUS(uarmc); 2482. if (uarmh) 2483. uac -= ARM_BONUS(uarmh); 2484. if (uarmf) 2485. uac -= ARM_BONUS(uarmf); 2486. if (uarms) 2487. uac -= ARM_BONUS(uarms); 2488. if (uarmg) 2489. uac -= ARM_BONUS(uarmg); 2490. if (uarmu) 2491. uac -= ARM_BONUS(uarmu); 2492. if (uleft && uleft->otyp == RIN_PROTECTION) 2493. uac -= uleft->spe; 2494. if (uright && uright->otyp == RIN_PROTECTION) 2495. uac -= uright->spe; 2496. if (uamul && uamul->otyp == AMULET_OF_GUARDING) 2497. uac -= 2; /* fixed amount; main benefit is to MC */ 2498. 2499. /* armor class from other sources */ 2500. if (HProtection & INTRINSIC) 2501. uac -= u.ublessed; 2502. uac -= u.uspellprot; 2503. 2504. /* put a cap on armor class [5.0: was +127,-128, now reduced to +/- 99 */ 2505. if (abs(uac) > AC_MAX) 2506. uac = sgn(uac) * AC_MAX; 2507. 2508. if (uac != u.uac) { 2509. u.uac = uac; 2510. disp.botl = TRUE; 2511. #if 0 2512. /* these could conceivably be achieved out of order (by being near 2513. threshold and putting on +N dragon scale mail from bones, for 2514. instance), but if that happens, that's the order it happened; 2515. also, testing for these in the usual order would result in more 2516. record_achievement() attempts and rejects for duplication */ 2517. if (u.uac <= -20) 2518. record_achievement(ACH_AC_20); 2519. else if (u.uac <= -10) 2520. record_achievement(ACH_AC_10); 2521. else if (u.uac <= 0) 2522. record_achievement(ACH_AC_00); 2523. #endif 2524. } 2525. } 2526. 2527. void 2528. glibr(void) 2529. { 2530. struct obj *otmp; 2531. int xfl = 0; 2532. boolean leftfall, rightfall, wastwoweap = FALSE; 2533. const char *otherwep = 0, *thiswep, *which, *hand; 2534. 2535. leftfall = (uleft && !uleft->cursed 2536. && (!uwep || !(welded(uwep) && ULEFTY) 2537. || !bimanual(uwep))); 2538. rightfall = (uright && !uright->cursed 2539. && (!uwep || !(welded(uwep) && URIGHTY) 2540. || !bimanual(uwep))); 2541. /* 2542. leftfall = (uleft && !uleft->cursed 2543. && (!uwep || !welded(uwep) || !bimanual(uwep))); 2544. rightfall = (uright && !uright->cursed && (!welded(uwep))); 2545. */ 2546. 2547. if (!uarmg && (leftfall || rightfall) && !nolimbs(gy.youmonst.data)) { 2548. /* changed so cursed rings don't fall off, GAN 10/30/86 */ 2549. Your("%s off your %s.", 2550. (leftfall && rightfall) ? "rings slip" : "ring slips", 2551. (leftfall && rightfall) ? fingers_or_gloves(FALSE) 2552. : body_part(FINGER)); 2553. xfl++; 2554. if (leftfall) { 2555. otmp = uleft; 2556. Ring_off(uleft); 2557. dropx(otmp); 2558. cmdq_clear(CQ_CANNED); 2559. } 2560. if (rightfall) { 2561. otmp = uright; 2562. Ring_off(uright); 2563. dropx(otmp); 2564. cmdq_clear(CQ_CANNED); 2565. } 2566. } 2567. 2568. otmp = uswapwep; 2569. if (u.twoweap && otmp) { 2570. /* secondary weapon doesn't need nearly as much handling as 2571. primary; when in two-weapon mode, we know it's one-handed 2572. with something else in the other hand and also that it's 2573. a weapon or weptool rather than something unusual, plus 2574. we don't need to compare its type with the primary */ 2575. otherwep = is_sword(otmp) ? c_sword : weapon_descr(otmp); 2576. if (otmp->quan > 1L) 2577. otherwep = makeplural(otherwep); 2578. hand = body_part(HAND); 2579. which = URIGHTY ? "left " : "right "; /* text for the off hand */ 2580. Your("%s %s%s from your %s%s.", otherwep, xfl ? "also " : "", 2581. otense(otmp, "slip"), which, hand); 2582. xfl++; 2583. wastwoweap = TRUE; 2584. setuswapwep((struct obj *) 0); /* clears u.twoweap */ 2585. cmdq_clear(CQ_CANNED); 2586. if (canletgo(otmp, "")) 2587. dropx(otmp); 2588. } 2589. otmp = uwep; 2590. if (otmp && otmp->otyp != AKLYS && !welded(otmp)) { 2591. long savequan = otmp->quan; 2592. 2593. /* nice wording if both weapons are the same type */ 2594. thiswep = is_sword(otmp) ? c_sword : weapon_descr(otmp); 2595. if (otherwep && strcmp(thiswep, makesingular(otherwep))) 2596. otherwep = 0; 2597. if (otmp->quan > 1L) { 2598. /* most class names for unconventional wielded items 2599. are ok, but if wielding multiple apples or rations 2600. we don't want "your foods slip", so force non-corpse 2601. food to be singular; skipping makeplural() isn't 2602. enough--we need to fool otense() too */ 2603. if (!strcmp(thiswep, "food")) 2604. otmp->quan = 1L; 2605. else 2606. thiswep = makeplural(thiswep); 2607. } 2608. hand = body_part(HAND); 2609. which = ""; 2610. if (bimanual(otmp)) { 2611. hand = makeplural(hand); 2612. } else if (wastwoweap) { 2613. /* preceding msg was about non-dominant hand */ 2614. which = URIGHTY ? "right " : "left "; 2615. } 2616. pline("%s %s%s %s%s from your %s%s.", 2617. !strncmp(thiswep, "corpse", 6) ? "The" : "Your", 2618. otherwep ? "other " : "", thiswep, xfl ? "also " : "", 2619. otense(otmp, "slip"), which, hand); 2620. /* xfl++; */ 2621. otmp->quan = savequan; 2622. setuwep((struct obj *) 0); 2623. cmdq_clear(CQ_CANNED); 2624. if (canletgo(otmp, "")) 2625. dropx(otmp); 2626. } 2627. } 2628. 2629. struct obj * 2630. some_armor(struct monst *victim) 2631. { 2632. struct obj *otmph, *otmp; 2633. 2634. otmph = (victim == &gy.youmonst) ? uarmc : which_armor(victim, W_ARMC); 2635. if (!otmph) 2636. otmph = (victim == &gy.youmonst) ? uarm : which_armor(victim, W_ARM); 2637. if (!otmph) 2638. otmph = (victim == &gy.youmonst) ? uarmu : which_armor(victim, W_ARMU); 2639. 2640. otmp = (victim == &gy.youmonst) ? uarmh : which_armor(victim, W_ARMH); 2641. if (otmp && (!otmph || !rn2(4))) 2642. otmph = otmp; 2643. otmp = (victim == &gy.youmonst) ? uarmg : which_armor(victim, W_ARMG); 2644. if (otmp && (!otmph || !rn2(4))) 2645. otmph = otmp; 2646. otmp = (victim == &gy.youmonst) ? uarmf : which_armor(victim, W_ARMF); 2647. if (otmp && (!otmph || !rn2(4))) 2648. otmph = otmp; 2649. otmp = (victim == &gy.youmonst) ? uarms : which_armor(victim, W_ARMS); 2650. if (otmp && (!otmph || !rn2(4))) 2651. otmph = otmp; 2652. return otmph; 2653. } 2654. 2655. /* used for praying to check and fix levitation trouble */ 2656. struct obj * 2657. stuck_ring(struct obj *ring, int otyp) 2658. { 2659. if (ring != uleft && ring != uright) { 2660. impossible("stuck_ring: neither left nor right?"); 2661. return (struct obj *) 0; 2662. } 2663. 2664. if (ring && ring->otyp == otyp) { 2665. /* reasons ring can't be removed match those checked by select_off(); 2666. limbless case has extra checks because ordinarily it's temporary */ 2667. if (nolimbs(gy.youmonst.data) && uamul 2668. && uamul->otyp == AMULET_OF_UNCHANGING && uamul->cursed) 2669. return uamul; 2670. if (welded(uwep) && ((ring == RING_ON_PRIMARY) || bimanual(uwep))) 2671. return uwep; 2672. if (uarmg && uarmg->cursed) 2673. return uarmg; 2674. if (ring->cursed) 2675. return ring; 2676. /* normally outermost layer is processed first, but slippery gloves 2677. wears off quickly so uncurse ring itself before handling those */ 2678. if (uarmg && Glib) 2679. return uarmg; 2680. } 2681. /* either no ring or not right type or nothing prevents its removal */ 2682. return (struct obj *) 0; 2683. } 2684. 2685. /* also for praying; find worn item that confers "Unchanging" attribute */ 2686. struct obj * 2687. unchanger(void) 2688. { 2689. if (uamul && uamul->otyp == AMULET_OF_UNCHANGING) 2690. return uamul; 2691. return 0; 2692. } 2693. 2694. staticfn 2695. int 2696. select_off(struct obj *otmp) 2697. { 2698. struct obj *why; 2699. char buf[BUFSZ]; 2700. 2701. if (!otmp) 2702. return 0; 2703. *buf = '\0'; /* lint suppression */ 2704. 2705. /* special ring checks */ 2706. if (otmp == uright || otmp == uleft) { 2707. struct obj glibdummy; 2708. 2709. if (nolimbs(gy.youmonst.data)) { 2710. pline_The("ring is stuck."); 2711. return 0; 2712. } 2713. glibdummy = cg.zeroobj; 2714. why = 0; /* the item which prevents ring removal */ 2715. if (welded(uwep) && ((otmp == RING_ON_PRIMARY) || bimanual(uwep))) { 2716. Sprintf(buf, "free a weapon %s", body_part(HAND)); 2717. why = uwep; 2718. } else if (uarmg && (uarmg->cursed || Glib)) { 2719. Sprintf(buf, "take off your %s%s", 2720. Glib ? "slippery " : "", gloves_simple_name(uarmg)); 2721. why = !Glib ? uarmg : &glibdummy; 2722. } 2723. if (why) { 2724. You("cannot %s to remove the ring.", buf); 2725. set_bknown(why, 1); 2726. return 0; 2727. } 2728. } 2729. /* special glove checks */ 2730. if (otmp == uarmg) { 2731. if (welded(uwep)) { 2732. You("are unable to take off your %s while wielding that %s.", 2733. c_gloves, is_sword(uwep) ? c_sword : c_weapon); 2734. set_bknown(uwep, 1); 2735. return 0; 2736. } else if (Glib) { 2737. pline("%s %s are too slippery to take off.", 2738. uarmg->unpaid ? "The" : "Your", /* simplified Shk_Your() */ 2739. gloves_simple_name(uarmg)); 2740. return 0; 2741. } 2742. if (better_not_take_that_off(otmp)) 2743. return 0; 2744. } 2745. /* special boot checks */ 2746. if (otmp == uarmf) { 2747. if (u.utrap && u.utraptype == TT_BEARTRAP) { 2748. pline_The("bear trap prevents you from pulling your %s out.", 2749. body_part(FOOT)); 2750. return 0; 2751. } else if (u.utrap && u.utraptype == TT_INFLOOR) { 2752. You("are stuck in the %s, and cannot pull your %s out.", 2753. surface(u.ux, u.uy), makeplural(body_part(FOOT))); 2754. return 0; 2755. } 2756. } 2757. /* special suit and shirt checks */ 2758. if (otmp == uarm || otmp == uarmu) { 2759. why = 0; /* the item which prevents disrobing */ 2760. if (uarmc && uarmc->cursed) { 2761. Sprintf(buf, "remove your %s", cloak_simple_name(uarmc)); 2762. why = uarmc; 2763. } else if (otmp == uarmu && uarm && uarm->cursed) { 2764. Sprintf(buf, "remove your %s", c_suit); 2765. why = uarm; 2766. } else if (welded(uwep) && bimanual(uwep)) { 2767. Sprintf(buf, "release your %s", 2768. is_sword(uwep) ? c_sword : (uwep->otyp == BATTLE_AXE) 2769. ? c_axe 2770. : c_weapon); 2771. why = uwep; 2772. } 2773. if (why) { 2774. You("cannot %s to take off %s.", buf, the(xname(otmp))); 2775. set_bknown(why, 1); 2776. return 0; 2777. } 2778. } 2779. /* basic curse check */ 2780. if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) { 2781. ; /* some items can be removed even when cursed */ 2782. } else { 2783. /* otherwise, this is fundamental */ 2784. if (cursed(otmp)) 2785. return 0; 2786. } 2787. 2788. if (otmp == uarm) 2789. svc.context.takeoff.mask |= WORN_ARMOR; 2790. else if (otmp == uarmc) 2791. svc.context.takeoff.mask |= WORN_CLOAK; 2792. else if (otmp == uarmf) 2793. svc.context.takeoff.mask |= WORN_BOOTS; 2794. else if (otmp == uarmg) 2795. svc.context.takeoff.mask |= WORN_GLOVES; 2796. else if (otmp == uarmh) 2797. svc.context.takeoff.mask |= WORN_HELMET; 2798. else if (otmp == uarms) 2799. svc.context.takeoff.mask |= WORN_SHIELD; 2800. else if (otmp == uarmu) 2801. svc.context.takeoff.mask |= WORN_SHIRT; 2802. else if (otmp == uleft) 2803. svc.context.takeoff.mask |= LEFT_RING; 2804. else if (otmp == uright) 2805. svc.context.takeoff.mask |= RIGHT_RING; 2806. else if (otmp == uamul) 2807. svc.context.takeoff.mask |= WORN_AMUL; 2808. else if (otmp == ublindf) 2809. svc.context.takeoff.mask |= WORN_BLINDF; 2810. else if (otmp == uwep) 2811. svc.context.takeoff.mask |= W_WEP; 2812. else if (otmp == uswapwep) 2813. svc.context.takeoff.mask |= W_SWAPWEP; 2814. else if (otmp == uquiver) 2815. svc.context.takeoff.mask |= W_QUIVER; 2816. 2817. else 2818. impossible("select_off: %s???", doname(otmp)); 2819. 2820. return 0; 2821. } 2822. 2823. staticfn struct obj * 2824. do_takeoff(void) 2825. { 2826. struct obj *otmp = (struct obj *) 0; 2827. boolean was_twoweap = u.twoweap; 2828. struct takeoff_info *doff = &svc.context.takeoff; 2829. 2830. svc.context.takeoff.mask |= I_SPECIAL; /* set flag for cancel_doff() */ 2831. if (doff->what == W_WEP) { 2832. if (!cursed(uwep)) { 2833. setuwep((struct obj *) 0); 2834. if (was_twoweap) 2835. You("are no longer wielding either weapon."); 2836. else 2837. You("are %s.", empty_handed()); 2838. } 2839. } else if (doff->what == W_SWAPWEP) { 2840. setuswapwep((struct obj *) 0); 2841. You("%sno longer %s.", was_twoweap ? "are " : "", 2842. was_twoweap ? "wielding two weapons at once" 2843. : "have a second weapon readied"); 2844. } else if (doff->what == W_QUIVER) { 2845. setuqwep((struct obj *) 0); 2846. You("no longer have ammunition readied."); 2847. } else if (doff->what == WORN_ARMOR) { 2848. otmp = uarm; 2849. if (!cursed(otmp)) 2850. (void) Armor_off(); 2851. } else if (doff->what == WORN_CLOAK) { 2852. otmp = uarmc; 2853. if (!cursed(otmp)) 2854. (void) Cloak_off(); 2855. } else if (doff->what == WORN_BOOTS) { 2856. otmp = uarmf; 2857. if (!cursed(otmp)) 2858. (void) Boots_off(); 2859. } else if (doff->what == WORN_GLOVES) { 2860. otmp = uarmg; 2861. if (!cursed(otmp)) 2862. (void) Gloves_off(); 2863. } else if (doff->what == WORN_HELMET) { 2864. otmp = uarmh; 2865. if (!cursed(otmp)) 2866. (void) Helmet_off(); 2867. } else if (doff->what == WORN_SHIELD) { 2868. otmp = uarms; 2869. if (!cursed(otmp)) 2870. (void) Shield_off(); 2871. } else if (doff->what == WORN_SHIRT) { 2872. otmp = uarmu; 2873. if (!cursed(otmp)) 2874. (void) Shirt_off(); 2875. } else if (doff->what == WORN_AMUL) { 2876. otmp = uamul; 2877. if (!cursed(otmp)) 2878. Amulet_off(); 2879. } else if (doff->what == LEFT_RING) { 2880. otmp = uleft; 2881. if (!cursed(otmp)) 2882. Ring_off(uleft); 2883. } else if (doff->what == RIGHT_RING) { 2884. otmp = uright; 2885. if (!cursed(otmp)) 2886. Ring_off(uright); 2887. } else if (doff->what == WORN_BLINDF) { 2888. if (!cursed(ublindf)) 2889. Blindf_off(ublindf); 2890. } else { 2891. impossible("do_takeoff: taking off %lx", doff->what); 2892. } 2893. svc.context.takeoff.mask &= ~I_SPECIAL; /* clear cancel_doff() flag */ 2894. 2895. return otmp; 2896. } 2897. 2898. /* occupation callback for 'A' */ 2899. staticfn int 2900. take_off(void) 2901. { 2902. int i; 2903. struct obj *otmp; 2904. struct takeoff_info *doff = &svc.context.takeoff; 2905. 2906. if (doff->what) { 2907. if (doff->delay > 0) { 2908. doff->delay--; 2909. return 1; /* still busy */ 2910. } 2911. if ((otmp = do_takeoff()) != 0) 2912. off_msg(otmp); 2913. doff->mask &= ~doff->what; 2914. doff->what = 0L; 2915. } 2916. 2917. for (i = 0; takeoff_order[i]; i++) 2918. if (doff->mask & takeoff_order[i]) { 2919. doff->what = takeoff_order[i]; 2920. break; 2921. } 2922. 2923. otmp = (struct obj *) 0; 2924. doff->delay = 0; 2925. 2926. if (doff->what == 0L) { 2927. You("finish %s.", doff->disrobing); 2928. return 0; 2929. } else if (doff->what == W_WEP) { 2930. doff->delay = 1; 2931. } else if (doff->what == W_SWAPWEP) { 2932. doff->delay = 1; 2933. } else if (doff->what == W_QUIVER) { 2934. doff->delay = 1; 2935. } else if (doff->what == WORN_ARMOR) { 2936. otmp = uarm; 2937. /* If a cloak is being worn, add the time to take it off and put 2938. * it back on again. Kludge alert! since that time is 0 for all 2939. * known cloaks, add 1 so that it actually matters... 2940. */ 2941. if (uarmc) 2942. doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1; 2943. } else if (doff->what == WORN_CLOAK) { 2944. otmp = uarmc; 2945. } else if (doff->what == WORN_BOOTS) { 2946. otmp = uarmf; 2947. } else if (doff->what == WORN_GLOVES) { 2948. otmp = uarmg; 2949. } else if (doff->what == WORN_HELMET) { 2950. otmp = uarmh; 2951. } else if (doff->what == WORN_SHIELD) { 2952. otmp = uarms; 2953. } else if (doff->what == WORN_SHIRT) { 2954. otmp = uarmu; 2955. /* add the time to take off and put back on armor and/or cloak */ 2956. if (uarm) 2957. doff->delay += 2 * objects[uarm->otyp].oc_delay; 2958. if (uarmc) 2959. doff->delay += 2 * objects[uarmc->otyp].oc_delay + 1; 2960. } else if (doff->what == WORN_AMUL) { 2961. doff->delay = 1; 2962. } else if (doff->what == LEFT_RING) { 2963. doff->delay = 1; 2964. } else if (doff->what == RIGHT_RING) { 2965. doff->delay = 1; 2966. } else if (doff->what == WORN_BLINDF) { 2967. /* [this used to be 2, but 'R' (and 'T') only require 1 turn to 2968. remove a blindfold, so 'A' shouldn't have been requiring 2] */ 2969. doff->delay = 1; 2970. } else { 2971. impossible("take_off: taking off %lx", doff->what); 2972. return 0; /* force done */ 2973. } 2974. 2975. if (otmp) 2976. doff->delay += objects[otmp->otyp].oc_delay; 2977. 2978. /* Since setting the occupation now starts the counter next move, that 2979. * would always produce a delay 1 too big per item unless we subtract 2980. * 1 here to account for it. 2981. */ 2982. if (doff->delay > 0) 2983. doff->delay--; 2984. 2985. set_occupation(take_off, doff->disrobing, 0); 2986. return 1; /* get busy */ 2987. } 2988. 2989. staticfn boolean 2990. better_not_take_that_off(struct obj *otmp) 2991. { 2992. struct obj *corpse = carrying_stoning_corpse(); 2993. char buf[BUFSZ]; 2994. 2995. /* u_safe_from_fatal_corpse() with 2996. (st_corpse | st_petrifies | st_resists) instead of 2997. (st_corpse | st_petrifies) 2998. would also check for no stoning resistance before 2999. bothering to prompt, but losing stoning resistance 3000. later, without the gloves on could prove dangerous, 3001. so we won't factor that in */ 3002. if (corpse 3003. && !u_safe_from_fatal_corpse(corpse, st_corpse | st_petrifies)) { 3004. Snprintf(buf, sizeof buf, 3005. "Take off your %s despite carrying a dead %s?", 3006. gloves_simple_name(otmp), obj_pmname(corpse)); 3007. return (paranoid_ynq(TRUE, buf, FALSE) != 'y'); 3008. } 3009. return FALSE; 3010. } 3011. 3012. /* clear saved context to avoid inappropriate resumption of interrupted 'A' */ 3013. void 3014. reset_remarm(void) 3015. { 3016. svc.context.takeoff.what = svc.context.takeoff.mask = 0L; 3017. svc.context.takeoff.disrobing[0] = '\0'; 3018. } 3019. 3020. /* the #takeoffall command -- remove multiple worn items */ 3021. int 3022. doddoremarm(void) 3023. { 3024. int result = 0; 3025. 3026. if (svc.context.takeoff.what || svc.context.takeoff.mask) { 3027. You("continue %s.", svc.context.takeoff.disrobing); 3028. set_occupation(take_off, svc.context.takeoff.disrobing, 0); 3029. return ECMD_OK; 3030. } else if (!uwep && !uswapwep && !uquiver && !uamul && !ublindf 3031. && !uleft && !uright && !wearing_armor()) { 3032. You("are not wearing anything."); 3033. return ECMD_OK; 3034. } 3035. 3036. add_valid_menu_class(0); /* reset */ 3037. if (flags.menu_style != MENU_TRADITIONAL 3038. || (result = ggetobj("take off", select_off, 0, FALSE, 3039. (unsigned *) 0)) < -1) 3040. (void) menu_remarm(result); 3041. 3042. if (svc.context.takeoff.mask) { 3043. (void) strncpy(svc.context.takeoff.disrobing, 3044. (((svc.context.takeoff.mask & ~W_WEAPONS) != 0) 3045. /* default activity for armor and/or accessories, 3046. possibly combined with weapons */ 3047. ? "disrobing" 3048. /* specific activity when handling weapons only */ 3049. : "disarming"), CONTEXTVERBSZ); 3050. (void) take_off(); 3051. } 3052. /* The time to perform the command is already completely accounted for 3053. * in take_off(); if we return 1, that would add an extra turn to each 3054. * disrobe. 3055. */ 3056. return ECMD_OK; 3057. } 3058. 3059. /* #altunwield - just unwield alternate weapon, item-action '-' when picking 3060. uswapwep from context-sensitive inventory */ 3061. int 3062. remarm_swapwep(void) 3063. { 3064. struct _cmd_queue cq, *cmdq; 3065. unsigned oldbknown; 3066. 3067. if ((cmdq = cmdq_pop()) != 0) { 3068. /* '-' uswapwep item-action picked from context-sensitive invent */ 3069. cq = *cmdq; 3070. free(cmdq); 3071. } else { 3072. cq.typ = CMDQ_KEY; 3073. cq.key = '\0'; /* something other than '-' */ 3074. } 3075. if (cq.typ != CMDQ_KEY || cq.key != '-' || !uswapwep) 3076. return ECMD_FAIL; 3077. 3078. oldbknown = uswapwep->bknown; /* when deciding whether this command 3079. * has done something that takes time, 3080. * behave as if a cursed secondary weapon 3081. * can't be unwielded even though things 3082. * don't work that way... */ 3083. reset_remarm(); 3084. svc.context.takeoff.what = svc.context.takeoff.mask = W_SWAPWEP; 3085. (void) do_takeoff(); 3086. return (!uswapwep || uswapwep->bknown != oldbknown) ? ECMD_TIME : ECMD_OK; 3087. } 3088. 3089. staticfn int 3090. menu_remarm(int retry) 3091. { 3092. int n, i = 0; 3093. menu_item *pick_list; 3094. boolean all_worn_categories = TRUE; 3095. 3096. if (retry) { 3097. all_worn_categories = (retry == -2); 3098. } else if (flags.menu_style == MENU_FULL) { 3099. all_worn_categories = FALSE; 3100. n = query_category("What type of things do you want to take off?", 3101. gi.invent, (WORN_TYPES | ALL_TYPES 3102. | UNPAID_TYPES | BUCX_TYPES), 3103. &pick_list, PICK_ANY); 3104. if (!n) 3105. return 0; 3106. for (i = 0; i < n; i++) { 3107. if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) 3108. all_worn_categories = TRUE; 3109. else 3110. add_valid_menu_class(pick_list[i].item.a_int); 3111. } 3112. free((genericptr_t) pick_list); 3113. } else if (flags.menu_style == MENU_COMBINATION) { 3114. unsigned ggofeedback = 0; 3115. 3116. i = ggetobj("take off", select_off, 0, TRUE, &ggofeedback); 3117. if (ggofeedback & ALL_FINISHED) 3118. return 0; 3119. all_worn_categories = (i == -2); 3120. } 3121. if (menu_class_present('u') 3122. || menu_class_present('B') || menu_class_present('U') 3123. || menu_class_present('C') || menu_class_present('X')) 3124. all_worn_categories = FALSE; 3125. 3126. n = query_objlist("What do you want to take off?", &gi.invent, 3127. (SIGNAL_NOMENU | USE_INVLET | INVORDER_SORT), 3128. &pick_list, PICK_ANY, 3129. all_worn_categories ? is_worn : is_worn_by_type); 3130. if (n > 0) { 3131. for (i = 0; i < n; i++) 3132. (void) select_off(pick_list[i].item.a_obj); 3133. free((genericptr_t) pick_list); 3134. } else if (n < 0 && flags.menu_style != MENU_COMBINATION) { 3135. There("is nothing else you can remove or unwield."); 3136. } 3137. return 0; 3138. } 3139. 3140. /* take off the specific worn object and if it still exists after that, 3141. destroy it (taking off the item might already destroy it by dunking 3142. hero into lava) */ 3143. staticfn void 3144. wornarm_destroyed(struct obj *wornarm) 3145. { 3146. struct obj *invobj, *nextobj; 3147. unsigned wornoid = wornarm->o_id; 3148. 3149. /* cancel_don() resets 'afternmv' when appropriate but doesn't reset 3150. uarmc/uarm/&c so doing this now won't interfere with the tests in 3151. 'if (wornarm==uarmc) ... else if (wornarm==uarm) ... else ...' */ 3152. if (donning(wornarm)) 3153. cancel_don(); 3154. 3155. if (wornarm == uarmc) 3156. (void) Cloak_off(); 3157. else if (wornarm == uarm) 3158. (void) Armor_off(); 3159. else if (wornarm == uarmu) 3160. (void) Shirt_off(); 3161. else if (wornarm == uarmh) 3162. (void) Helmet_off(); 3163. else if (wornarm == uarmg) 3164. (void) Gloves_off(); 3165. else if (wornarm == uarmf) 3166. (void) Boots_off(); 3167. else if (wornarm == uarms) 3168. (void) Shield_off(); 3169. 3170. /* 'wornarm' might be destroyed as a side-effect of xxx_off() so 3171. using carried() to check wornarm->where==OBJ_INVENT is not viable; 3172. scan invent instead; if already freed it shouldn't be possible to 3173. have re-used the stale memory for a new item yet but verify o_id 3174. just in case */ 3175. for (invobj = gi.invent; invobj; invobj = nextobj) { 3176. nextobj = invobj->nobj; 3177. if (invobj == wornarm && invobj->o_id == wornoid) { 3178. useup(wornarm); 3179. break; 3180. } 3181. } 3182. } 3183. 3184. /* 3185. * returns impacted armor with its in_use bit set, 3186. * or Null. *resisted is updated to reflect whether 3187. * it resisted or not */ 3188. staticfn struct obj * 3189. maybe_destroy_armor(struct obj *armor, struct obj *atmp, boolean *resisted) 3190. { 3191. if ((armor != 0) && (!atmp || atmp == armor) 3192. && ((*resisted = obj_resists(armor, 0, 90)) == FALSE)) { 3193. armor->in_use = 1; 3194. return armor; 3195. } 3196. return (struct obj *) 0; 3197. } 3198. 3199. /* hit by destroy armor scroll/black dragon breath */ 3200. int 3201. disintegrate_arm(struct obj *atmp) 3202. { 3203. struct obj *otmp = (struct obj *) 0; 3204. boolean losing_gloves = FALSE, resisted = FALSE, 3205. resistedc = FALSE, resistedsuit = FALSE; 3206. /* 3207. * Note: if the cloak resisted, then the suit or shirt underneath 3208. * wouldn't be impacted either. Likewise, if the suit resisted, the 3209. * shirt underneath wouldn't be impacted. Since there are no artifact 3210. * cloaks or suits right now, this is unlikely to come into effect, 3211. * but it should behave appropriately if/when the situation changes. 3212. */ 3213. 3214. if ((otmp = maybe_destroy_armor(uarmc, atmp, &resistedc)) != 0) { 3215. urgent_pline("Your %s crumbles and turns to dust!", 3216. /* cloak/robe/apron/smock (ID'd apron)/wrapping */ 3217. cloak_simple_name(otmp)); 3218. } else if (!resistedc 3219. && (otmp = maybe_destroy_armor(uarm, atmp, &resistedsuit)) != 0) { 3220. const char *suit = suit_simple_name(otmp); 3221. 3222. /* for gold DSM, we don't want Armor_gone() to report that it 3223. stops shining _after_ we've been told that it is destroyed */ 3224. if (otmp->lamplit) 3225. end_burn(otmp, FALSE); 3226. urgent_pline("Your %s %s to dust and %s to the %s!", 3227. /* suit might be "dragon scales" so vtense() is needed */ 3228. suit, vtense(suit, "turn"), vtense(suit, "fall"), 3229. surface(u.ux, u.uy)); 3230. } else if (!resistedc && !resistedsuit 3231. && (otmp = maybe_destroy_armor(uarmu, atmp, &resisted)) != 0) { 3232. urgent_pline("Your %s crumbles into tiny threads and falls apart!", 3233. shirt_simple_name(otmp)); /* always "shirt" */ 3234. } else if ((otmp = maybe_destroy_armor(uarmh, atmp, &resisted)) != 0) { 3235. urgent_pline("Your %s turns to dust and is blown away!", 3236. helm_simple_name(otmp)); /* "helm" or "hat" */ 3237. } else if ((otmp = maybe_destroy_armor(uarmg, atmp, &resisted)) != 0) { 3238. urgent_pline("Your %s vanish!", gloves_simple_name(otmp)); 3239. losing_gloves = TRUE; 3240. } else if ((otmp = maybe_destroy_armor(uarmf, atmp, &resisted)) != 0) { 3241. urgent_pline("Your %s disintegrate!", boots_simple_name(otmp)); 3242. } else if ((otmp = maybe_destroy_armor(uarms, atmp, &resisted)) != 0) { 3243. urgent_pline("Your %s crumbles away!", shield_simple_name(otmp)); 3244. } else { 3245. return 0; /* could not destroy anything */ 3246. } 3247. 3248. /* cancel_don() if applicable, Cloak_off()/Armor_off()/&c, and useup() */ 3249. wornarm_destroyed(otmp); 3250. /* glove loss means wielded weapon will be touched */ 3251. if (losing_gloves) 3252. selftouch("You"); 3253. 3254. stop_occupation(); 3255. return 1; 3256. } 3257. 3258. /* return ERODE_foo erosion type which can apply to object */ 3259. staticfn int 3260. obj_erode_type(struct obj *otmp) 3261. { 3262. if (is_flammable(otmp)) 3263. return ERODE_BURN; 3264. else if (is_rustprone(otmp)) 3265. return ERODE_RUST; 3266. else if (is_crackable(otmp)) 3267. return ERODE_CRACK; 3268. else if (is_rottable(otmp)) 3269. return ERODE_ROT; 3270. else if (is_corrodeable(otmp)) 3271. return ERODE_CORRODE; 3272. return ERODE_NONE; 3273. } 3274. 3275. /* erode a number of worn armor(s). 3276. if the armor is hit when max eroded, destroys it. */ 3277. int 3278. destroy_arm(void) 3279. { 3280. struct obj *armors[7] = { NULL }; 3281. struct obj *otmp; 3282. int i, idx = 0, hits = rn2(4) + 1; 3283. int ret = 0; 3284. 3285. /* gather worn armor; include non-erodeable ones */ 3286. if (uarm) armors[idx++] = uarm; 3287. if (uarmc) armors[idx++] = uarmc; 3288. if (uarmh) armors[idx++] = uarmh; 3289. if (uarms) armors[idx++] = uarms; 3290. if (uarmg) armors[idx++] = uarmg; 3291. if (uarmf) armors[idx++] = uarmf; 3292. if (uarmu) armors[idx++] = uarmu; 3293. if (!idx) 3294. return 0; 3295. 3296. for (i = 0; i < hits; i++) { 3297. otmp = armors[rn2(idx)]; 3298. 3299. if (erosion_matters(otmp) && is_damageable(otmp) && !otmp->oerodeproof) { 3300. int erosion = obj_erode_type(otmp); 3301. 3302. if (erosion != ERODE_NONE) { 3303. int r = erode_obj(otmp, xname(otmp), erosion, EF_PAY|EF_DESTROY); 3304. 3305. if (r != ER_NOTHING) 3306. ret = 1; 3307. if (r == ER_DESTROYED) 3308. break; 3309. } 3310. } 3311. } 3312. 3313. if (ret) 3314. stop_occupation(); 3315. return ret; 3316. } 3317. 3318. void 3319. adj_abon(struct obj *otmp, schar delta) 3320. { 3321. if (uarmg && uarmg == otmp && otmp->otyp == GAUNTLETS_OF_DEXTERITY) { 3322. if (delta) { 3323. makeknown(uarmg->otyp); 3324. ABON(A_DEX) += (delta); 3325. } 3326. disp.botl = TRUE; 3327. } 3328. if (uarmh && uarmh == otmp && otmp->otyp == HELM_OF_BRILLIANCE) { 3329. if (delta) { 3330. makeknown(uarmh->otyp); 3331. ABON(A_INT) += (delta); 3332. ABON(A_WIS) += (delta); 3333. } 3334. disp.botl = TRUE; 3335. } 3336. } 3337. 3338. /* decide whether a worn item is covered up by some other worn item, 3339. used for dipping into liquid and applying grease and takeoff_ok(); 3340. some criteria are different than select_off()'s */ 3341. boolean 3342. inaccessible_equipment( 3343. struct obj *obj, 3344. const char *verb, /* "dip" or "grease", or null to avoid messages */ 3345. boolean only_if_known_cursed) /* ignore covering unless it is known to 3346. * be cursed */ 3347. { 3348. static NEARDATA const char need_to_take_off_outer_armor[] = 3349. "need to take off %s to %s %s."; 3350. char buf[BUFSZ]; 3351. boolean anycovering = !only_if_known_cursed; /* more comprehensible... */ 3352. #define BLOCKSACCESS(x) (anycovering || ((x)->cursed && (x)->bknown)) 3353. 3354. if (!obj || !obj->owornmask) 3355. return FALSE; /* not inaccessible */ 3356. 3357. /* check for suit covered by cloak */ 3358. if (obj == uarm && uarmc && BLOCKSACCESS(uarmc)) { 3359. if (verb) { 3360. Strcpy(buf, yname(uarmc)); 3361. You(need_to_take_off_outer_armor, buf, verb, yname(obj)); 3362. } 3363. return TRUE; 3364. } 3365. /* check for shirt covered by suit and/or cloak */ 3366. if (obj == uarmu 3367. && ((uarm && BLOCKSACCESS(uarm)) || (uarmc && BLOCKSACCESS(uarmc)))) { 3368. if (verb) { 3369. char cloaktmp[QBUFSZ], suittmp[QBUFSZ]; 3370. /* if sameprefix, use yname and xname to get "your cloak and suit" 3371. or "Manlobbi's cloak and suit"; otherwise, use yname and yname 3372. to get "your cloak and Manlobbi's suit" or vice versa */ 3373. boolean sameprefix = (uarm && uarmc 3374. && !strcmp(shk_your(cloaktmp, uarmc), 3375. shk_your(suittmp, uarm))); 3376. 3377. *buf = '\0'; 3378. if (uarmc) 3379. Strcat(buf, yname(uarmc)); 3380. if (uarm && uarmc) 3381. Strcat(buf, " and "); 3382. if (uarm) 3383. Strcat(buf, sameprefix ? xname(uarm) : yname(uarm)); 3384. You(need_to_take_off_outer_armor, buf, verb, yname(obj)); 3385. } 3386. return TRUE; 3387. } 3388. /* check for ring covered by gloves */ 3389. if ((obj == uleft || obj == uright) && uarmg && BLOCKSACCESS(uarmg)) { 3390. if (verb) { 3391. Strcpy(buf, yname(uarmg)); 3392. You(need_to_take_off_outer_armor, buf, verb, yname(obj)); 3393. } 3394. return TRUE; 3395. } 3396. /* item is not inaccessible */ 3397. return FALSE; 3398. 3399. #undef BLOCKSACCESS 3400. } 3401. 3402. /* not a getobj callback - unifies code among the other 4 getobj callbacks */ 3403. staticfn int 3404. equip_ok(struct obj *obj, boolean removing, boolean accessory) 3405. { 3406. boolean is_worn; 3407. long dummymask = 0; 3408. 3409. if (!obj) 3410. return GETOBJ_EXCLUDE; 3411. 3412. /* ignore for putting on if already worn, or removing if not worn */ 3413. is_worn = ((obj->owornmask & (W_ARMOR | W_ACCESSORY)) != 0); 3414. if (removing ^ is_worn) 3415. return GETOBJ_EXCLUDE_INACCESS; 3416. 3417. /* exclude most object classes outright */ 3418. if (obj->oclass != ARMOR_CLASS && obj->oclass != RING_CLASS 3419. && obj->oclass != AMULET_CLASS) { 3420. /* ... except for a few wearable exceptions outside these classes */ 3421. if (obj->otyp != MEAT_RING && obj->otyp != BLINDFOLD 3422. && obj->otyp != TOWEL && obj->otyp != LENSES) 3423. return GETOBJ_EXCLUDE; 3424. } 3425. 3426. /* armor with 'P' or 'R' or accessory with 'W' or 'T' */ 3427. if (accessory ^ (obj->oclass != ARMOR_CLASS)) 3428. return GETOBJ_DOWNPLAY; 3429. 3430. /* armor we can't wear, e.g. from polyform */ 3431. if (obj->oclass == ARMOR_CLASS && !removing 3432. && !canwearobj(obj, &dummymask, FALSE)) 3433. return GETOBJ_DOWNPLAY; 3434. 3435. /* Possible extension: downplay items (both accessories and armor) which 3436. * can't be worn because the slot is filled with something else. */ 3437. 3438. /* removing inaccessible equipment */ 3439. if (removing && !gi.item_action_in_progress) { 3440. if (inaccessible_equipment(obj, (const char *) 0, 3441. (obj->oclass == RING_CLASS))) 3442. return GETOBJ_EXCLUDE_INACCESS; 3443. } 3444. 3445. /* all good to go */ 3446. return GETOBJ_SUGGEST; 3447. } 3448. 3449. /* getobj callback for P command */ 3450. staticfn int 3451. puton_ok(struct obj *obj) 3452. { 3453. return equip_ok(obj, FALSE, TRUE); 3454. } 3455. 3456. /* getobj callback for R command */ 3457. staticfn int 3458. remove_ok(struct obj *obj) 3459. { 3460. return equip_ok(obj, TRUE, TRUE); 3461. } 3462. 3463. /* getobj callback for W command */ 3464. staticfn int 3465. wear_ok(struct obj *obj) 3466. { 3467. return equip_ok(obj, FALSE, FALSE); 3468. } 3469. 3470. /* getobj callback for T command */ 3471. staticfn int 3472. takeoff_ok(struct obj *obj) 3473. { 3474. return equip_ok(obj, TRUE, FALSE); 3475. } 3476. 3477. /* getobj callback for blessed destroy armor. 3478. suggest any worn armor, even if covered by other armor */ 3479. int 3480. any_worn_armor_ok(struct obj *obj) 3481. { 3482. if (obj && (obj->owornmask & W_ARMOR)) 3483. return GETOBJ_SUGGEST; 3484. return GETOBJ_EXCLUDE; 3485. } 3486. 3487. /* number of armor pieces worn by hero */ 3488. int 3489. count_worn_armor(void) 3490. { 3491. int ret = 0; 3492. 3493. if (uarm) ret++; 3494. if (uarmc) ret++; 3495. if (uarmh) ret++; 3496. if (uarms) ret++; 3497. if (uarmg) ret++; 3498. if (uarmf) ret++; 3499. if (uarmu) ret++; 3500. 3501. return ret; 3502. } 3503. 3504. /*do_wear.c*/