Source:NetHack 3.6.6/src/potion.c
Jump to navigation
Jump to search
Below is the full text to potion.c from the source code of NetHack 3.6.6. To link to a particular line, write [[Source:NetHack 3.6.6/src/potion.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 3.6 potion.c $NHDT-Date: 1573848199 2019/11/15 20:03:19 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.167 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2013. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. boolean notonhead = FALSE; 9. 10. static NEARDATA int nothing, unkn; 11. static NEARDATA const char beverages[] = { POTION_CLASS, 0 }; 12. 13. STATIC_DCL long FDECL(itimeout, (long)); 14. STATIC_DCL long FDECL(itimeout_incr, (long, int)); 15. STATIC_DCL void NDECL(ghost_from_bottle); 16. STATIC_DCL boolean 17. FDECL(H2Opotion_dip, (struct obj *, struct obj *, BOOLEAN_P, const char *)); 18. STATIC_DCL short FDECL(mixtype, (struct obj *, struct obj *)); 19. 20. /* force `val' to be within valid range for intrinsic timeout value */ 21. STATIC_OVL long 22. itimeout(val) 23. long val; 24. { 25. if (val >= TIMEOUT) 26. val = TIMEOUT; 27. else if (val < 1) 28. val = 0; 29. 30. return val; 31. } 32. 33. /* increment `old' by `incr' and force result to be valid intrinsic timeout */ 34. STATIC_OVL long 35. itimeout_incr(old, incr) 36. long old; 37. int incr; 38. { 39. return itimeout((old & TIMEOUT) + (long) incr); 40. } 41. 42. /* set the timeout field of intrinsic `which' */ 43. void 44. set_itimeout(which, val) 45. long *which, val; 46. { 47. *which &= ~TIMEOUT; 48. *which |= itimeout(val); 49. } 50. 51. /* increment the timeout field of intrinsic `which' */ 52. void 53. incr_itimeout(which, incr) 54. long *which; 55. int incr; 56. { 57. set_itimeout(which, itimeout_incr(*which, incr)); 58. } 59. 60. void 61. make_confused(xtime, talk) 62. long xtime; 63. boolean talk; 64. { 65. long old = HConfusion; 66. 67. if (Unaware) 68. talk = FALSE; 69. 70. if (!xtime && old) { 71. if (talk) 72. You_feel("less %s now.", Hallucination ? "trippy" : "confused"); 73. } 74. if ((xtime && !old) || (!xtime && old)) 75. context.botl = TRUE; 76. 77. set_itimeout(&HConfusion, xtime); 78. } 79. 80. void 81. make_stunned(xtime, talk) 82. long xtime; 83. boolean talk; 84. { 85. long old = HStun; 86. 87. if (Unaware) 88. talk = FALSE; 89. 90. if (!xtime && old) { 91. if (talk) 92. You_feel("%s now.", 93. Hallucination ? "less wobbly" : "a bit steadier"); 94. } 95. if (xtime && !old) { 96. if (talk) { 97. if (u.usteed) 98. You("wobble in the saddle."); 99. else 100. You("%s...", stagger(youmonst.data, "stagger")); 101. } 102. } 103. if ((!xtime && old) || (xtime && !old)) 104. context.botl = TRUE; 105. 106. set_itimeout(&HStun, xtime); 107. } 108. 109. /* Sick is overloaded with both fatal illness and food poisoning (via 110. u.usick_type bit mask), but delayed killer can only support one or 111. the other at a time. They should become separate intrinsics.... */ 112. void 113. make_sick(xtime, cause, talk, type) 114. long xtime; 115. const char *cause; /* sickness cause */ 116. boolean talk; 117. int type; 118. { 119. struct kinfo *kptr; 120. long old = Sick; 121. 122. #if 0 /* tell player even if hero is unconscious */ 123. if (Unaware) 124. talk = FALSE; 125. #endif 126. if (xtime > 0L) { 127. if (Sick_resistance) 128. return; 129. if (!old) { 130. /* newly sick */ 131. You_feel("deathly sick."); 132. } else { 133. /* already sick */ 134. if (talk) 135. You_feel("%s worse.", xtime <= Sick / 2L ? "much" : "even"); 136. } 137. set_itimeout(&Sick, xtime); 138. u.usick_type |= type; 139. context.botl = TRUE; 140. } else if (old && (type & u.usick_type)) { 141. /* was sick, now not */ 142. u.usick_type &= ~type; 143. if (u.usick_type) { /* only partly cured */ 144. if (talk) 145. You_feel("somewhat better."); 146. set_itimeout(&Sick, Sick * 2); /* approximation */ 147. } else { 148. if (talk) 149. You_feel("cured. What a relief!"); 150. Sick = 0L; /* set_itimeout(&Sick, 0L) */ 151. } 152. context.botl = TRUE; 153. } 154. 155. kptr = find_delayed_killer(SICK); 156. if (Sick) { 157. exercise(A_CON, FALSE); 158. /* setting delayed_killer used to be unconditional, but that's 159. not right when make_sick(0) is called to cure food poisoning 160. if hero was also fatally ill; this is only approximate */ 161. if (xtime || !old || !kptr) { 162. int kpfx = ((cause && !strcmp(cause, "#wizintrinsic")) 163. ? KILLED_BY : KILLED_BY_AN); 164. 165. delayed_killer(SICK, kpfx, cause); 166. } 167. } else 168. dealloc_killer(kptr); 169. } 170. 171. void 172. make_slimed(xtime, msg) 173. long xtime; 174. const char *msg; 175. { 176. long old = Slimed; 177. 178. #if 0 /* tell player even if hero is unconscious */ 179. if (Unaware) 180. msg = 0; 181. #endif 182. set_itimeout(&Slimed, xtime); 183. if ((xtime != 0L) ^ (old != 0L)) { 184. context.botl = TRUE; 185. if (msg) 186. pline("%s", msg); 187. } 188. if (!Slimed) { 189. dealloc_killer(find_delayed_killer(SLIMED)); 190. /* fake appearance is set late in turn-to-slime countdown */ 191. if (U_AP_TYPE == M_AP_MONSTER 192. && youmonst.mappearance == PM_GREEN_SLIME) { 193. youmonst.m_ap_type = M_AP_NOTHING; 194. youmonst.mappearance = 0; 195. } 196. } 197. } 198. 199. /* start or stop petrification */ 200. void 201. make_stoned(xtime, msg, killedby, killername) 202. long xtime; 203. const char *msg; 204. int killedby; 205. const char *killername; 206. { 207. long old = Stoned; 208. 209. #if 0 /* tell player even if hero is unconscious */ 210. if (Unaware) 211. msg = 0; 212. #endif 213. set_itimeout(&Stoned, xtime); 214. if ((xtime != 0L) ^ (old != 0L)) { 215. context.botl = TRUE; 216. if (msg) 217. pline("%s", msg); 218. } 219. if (!Stoned) 220. dealloc_killer(find_delayed_killer(STONED)); 221. else if (!old) 222. delayed_killer(STONED, killedby, killername); 223. } 224. 225. void 226. make_vomiting(xtime, talk) 227. long xtime; 228. boolean talk; 229. { 230. long old = Vomiting; 231. 232. if (Unaware) 233. talk = FALSE; 234. 235. set_itimeout(&Vomiting, xtime); 236. context.botl = TRUE; 237. if (!xtime && old) 238. if (talk) 239. You_feel("much less nauseated now."); 240. } 241. 242. static const char vismsg[] = "vision seems to %s for a moment but is %s now."; 243. static const char eyemsg[] = "%s momentarily %s."; 244. 245. void 246. make_blinded(xtime, talk) 247. long xtime; 248. boolean talk; 249. { 250. long old = Blinded; 251. boolean u_could_see, can_see_now; 252. const char *eyes; 253. 254. /* we need to probe ahead in case the Eyes of the Overworld 255. are or will be overriding blindness */ 256. u_could_see = !Blind; 257. Blinded = xtime ? 1L : 0L; 258. can_see_now = !Blind; 259. Blinded = old; /* restore */ 260. 261. if (Unaware) 262. talk = FALSE; 263. 264. if (can_see_now && !u_could_see) { /* regaining sight */ 265. if (talk) { 266. if (Hallucination) 267. pline("Far out! Everything is all cosmic again!"); 268. else 269. You("can see again."); 270. } 271. } else if (old && !xtime) { 272. /* clearing temporary blindness without toggling blindness */ 273. if (talk) { 274. if (!haseyes(youmonst.data)) { 275. strange_feeling((struct obj *) 0, (char *) 0); 276. } else if (Blindfolded) { 277. eyes = body_part(EYE); 278. if (eyecount(youmonst.data) != 1) 279. eyes = makeplural(eyes); 280. Your(eyemsg, eyes, vtense(eyes, "itch")); 281. } else { /* Eyes of the Overworld */ 282. Your(vismsg, "brighten", Hallucination ? "sadder" : "normal"); 283. } 284. } 285. } 286. 287. if (u_could_see && !can_see_now) { /* losing sight */ 288. if (talk) { 289. if (Hallucination) 290. pline("Oh, bummer! Everything is dark! Help!"); 291. else 292. pline("A cloud of darkness falls upon you."); 293. } 294. /* Before the hero goes blind, set the ball&chain variables. */ 295. if (Punished) 296. set_bc(0); 297. } else if (!old && xtime) { 298. /* setting temporary blindness without toggling blindness */ 299. if (talk) { 300. if (!haseyes(youmonst.data)) { 301. strange_feeling((struct obj *) 0, (char *) 0); 302. } else if (Blindfolded) { 303. eyes = body_part(EYE); 304. if (eyecount(youmonst.data) != 1) 305. eyes = makeplural(eyes); 306. Your(eyemsg, eyes, vtense(eyes, "twitch")); 307. } else { /* Eyes of the Overworld */ 308. Your(vismsg, "dim", Hallucination ? "happier" : "normal"); 309. } 310. } 311. } 312. 313. set_itimeout(&Blinded, xtime); 314. 315. if (u_could_see ^ can_see_now) { /* one or the other but not both */ 316. toggle_blindness(); 317. } 318. } 319. 320. /* blindness has just started or just ended--caller enforces that; 321. called by Blindf_on(), Blindf_off(), and make_blinded() */ 322. void 323. toggle_blindness() 324. { 325. boolean Stinging = (uwep && (EWarn_of_mon & W_WEP) != 0L); 326. 327. /* blindness has just been toggled */ 328. context.botl = TRUE; /* status conditions need update */ 329. vision_full_recalc = 1; /* vision has changed */ 330. /* this vision recalculation used to be deferred until moveloop(), 331. but that made it possible for vision irregularities to occur 332. (cited case was force bolt hitting an adjacent potion of blindness 333. and then a secret door; hero was blinded by vapors but then got the 334. message "a door appears in the wall" because wall spot was IN_SIGHT) */ 335. vision_recalc(0); 336. if (Blind_telepat || Infravision || Stinging) 337. see_monsters(); /* also counts EWarn_of_mon monsters */ 338. /* 339. * Avoid either of the sequences 340. * "Sting starts glowing", [become blind], "Sting stops quivering" or 341. * "Sting starts quivering", [regain sight], "Sting stops glowing" 342. * by giving "Sting is quivering" when becoming blind or 343. * "Sting is glowing" when regaining sight so that the eventual 344. * "stops" message matches the most recent "Sting is ..." one. 345. */ 346. if (Stinging) 347. Sting_effects(-1); 348. /* update dknown flag for inventory picked up while blind */ 349. if (!Blind) 350. learn_unseen_invent(); 351. } 352. 353. boolean 354. make_hallucinated(xtime, talk, mask) 355. long xtime; /* nonzero if this is an attempt to turn on hallucination */ 356. boolean talk; 357. long mask; /* nonzero if resistance status should change by mask */ 358. { 359. long old = HHallucination; 360. boolean changed = 0; 361. const char *message, *verb; 362. 363. if (Unaware) 364. talk = FALSE; 365. 366. message = (!xtime) ? "Everything %s SO boring now." 367. : "Oh wow! Everything %s so cosmic!"; 368. verb = (!Blind) ? "looks" : "feels"; 369. 370. if (mask) { 371. if (HHallucination) 372. changed = TRUE; 373. 374. if (!xtime) 375. EHalluc_resistance |= mask; 376. else 377. EHalluc_resistance &= ~mask; 378. } else { 379. if (!EHalluc_resistance && (!!HHallucination != !!xtime)) 380. changed = TRUE; 381. set_itimeout(&HHallucination, xtime); 382. 383. /* clearing temporary hallucination without toggling vision */ 384. if (!changed && !HHallucination && old && talk) { 385. if (!haseyes(youmonst.data)) { 386. strange_feeling((struct obj *) 0, (char *) 0); 387. } else if (Blind) { 388. const char *eyes = body_part(EYE); 389. 390. if (eyecount(youmonst.data) != 1) 391. eyes = makeplural(eyes); 392. Your(eyemsg, eyes, vtense(eyes, "itch")); 393. } else { /* Grayswandir */ 394. Your(vismsg, "flatten", "normal"); 395. } 396. } 397. } 398. 399. if (changed) { 400. /* in case we're mimicking an orange (hallucinatory form 401. of mimicking gold) update the mimicking's-over message */ 402. if (!Hallucination) 403. eatmupdate(); 404. 405. if (u.uswallow) { 406. swallowed(0); /* redraw swallow display */ 407. } else { 408. /* The see_* routines should be called *before* the pline. */ 409. see_monsters(); 410. see_objects(); 411. see_traps(); 412. } 413. 414. /* for perm_inv and anything similar 415. (eg. Qt windowport's equipped items display) */ 416. update_inventory(); 417. 418. context.botl = TRUE; 419. if (talk) 420. pline(message, verb); 421. } 422. return changed; 423. } 424. 425. void 426. make_deaf(xtime, talk) 427. long xtime; 428. boolean talk; 429. { 430. long old = HDeaf; 431. 432. if (Unaware) 433. talk = FALSE; 434. 435. set_itimeout(&HDeaf, xtime); 436. if ((xtime != 0L) ^ (old != 0L)) { 437. context.botl = TRUE; 438. if (talk) 439. You(old ? "can hear again." : "are unable to hear anything."); 440. } 441. } 442. 443. /* set or clear "slippery fingers" */ 444. void 445. make_glib(xtime) 446. int xtime; 447. { 448. set_itimeout(&Glib, xtime); 449. /* may change "(being worn)" to "(being worn; slippery)" or vice versa */ 450. if (uarmg) 451. update_inventory(); 452. } 453. 454. void 455. self_invis_message() 456. { 457. pline("%s %s.", 458. Hallucination ? "Far out, man! You" 459. : "Gee! All of a sudden, you", 460. See_invisible ? "can see right through yourself" 461. : "can't see yourself"); 462. } 463. 464. STATIC_OVL void 465. ghost_from_bottle() 466. { 467. struct monst *mtmp = makemon(&mons[PM_GHOST], u.ux, u.uy, NO_MM_FLAGS); 468. 469. if (!mtmp) { 470. pline("This bottle turns out to be empty."); 471. return; 472. } 473. if (Blind) { 474. pline("As you open the bottle, %s emerges.", something); 475. return; 476. } 477. pline("As you open the bottle, an enormous %s emerges!", 478. Hallucination ? rndmonnam(NULL) : (const char *) "ghost"); 479. if (flags.verbose) 480. You("are frightened to death, and unable to move."); 481. nomul(-3); 482. multi_reason = "being frightened to death"; 483. nomovemsg = "You regain your composure."; 484. } 485. 486. /* "Quaffing is like drinking, except you spill more." - Terry Pratchett */ 487. int 488. dodrink() 489. { 490. register struct obj *otmp; 491. const char *potion_descr; 492. 493. if (Strangled) { 494. pline("If you can't breathe air, how can you drink liquid?"); 495. return 0; 496. } 497. /* Is there a fountain to drink from here? */ 498. if (IS_FOUNTAIN(levl[u.ux][u.uy].typ) 499. /* not as low as floor level but similar restrictions apply */ 500. && can_reach_floor(FALSE)) { 501. if (yn("Drink from the fountain?") == 'y') { 502. drinkfountain(); 503. return 1; 504. } 505. } 506. /* Or a kitchen sink? */ 507. if (IS_SINK(levl[u.ux][u.uy].typ) 508. /* not as low as floor level but similar restrictions apply */ 509. && can_reach_floor(FALSE)) { 510. if (yn("Drink from the sink?") == 'y') { 511. drinksink(); 512. return 1; 513. } 514. } 515. /* Or are you surrounded by water? */ 516. if (Underwater && !u.uswallow) { 517. if (yn("Drink the water around you?") == 'y') { 518. pline("Do you know what lives in this water?"); 519. return 1; 520. } 521. } 522. 523. otmp = getobj(beverages, "drink"); 524. if (!otmp) 525. return 0; 526. 527. /* quan > 1 used to be left to useup(), but we need to force 528. the current potion to be unworn, and don't want to do 529. that for the entire stack when starting with more than 1. 530. [Drinking a wielded potion of polymorph can trigger a shape 531. change which causes hero's weapon to be dropped. In 3.4.x, 532. that led to an "object lost" panic since subsequent useup() 533. was no longer dealing with an inventory item. Unwearing 534. the current potion is intended to keep it in inventory.] */ 535. if (otmp->quan > 1L) { 536. otmp = splitobj(otmp, 1L); 537. otmp->owornmask = 0L; /* rest of original stuck unaffected */ 538. } else if (otmp->owornmask) { 539. remove_worn_item(otmp, FALSE); 540. } 541. otmp->in_use = TRUE; /* you've opened the stopper */ 542. 543. potion_descr = OBJ_DESCR(objects[otmp->otyp]); 544. if (potion_descr) { 545. if (!strcmp(potion_descr, "milky") 546. && !(mvitals[PM_GHOST].mvflags & G_GONE) 547. && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_GHOST].born))) { 548. ghost_from_bottle(); 549. useup(otmp); 550. return 1; 551. } else if (!strcmp(potion_descr, "smoky") 552. && !(mvitals[PM_DJINNI].mvflags & G_GONE) 553. && !rn2(POTION_OCCUPANT_CHANCE(mvitals[PM_DJINNI].born))) { 554. djinni_from_bottle(otmp); 555. useup(otmp); 556. return 1; 557. } 558. } 559. return dopotion(otmp); 560. } 561. 562. int 563. dopotion(otmp) 564. register struct obj *otmp; 565. { 566. int retval; 567. 568. otmp->in_use = TRUE; 569. nothing = unkn = 0; 570. if ((retval = peffects(otmp)) >= 0) 571. return retval; 572. 573. if (nothing) { 574. unkn++; 575. You("have a %s feeling for a moment, then it passes.", 576. Hallucination ? "normal" : "peculiar"); 577. } 578. if (otmp->dknown && !objects[otmp->otyp].oc_name_known) { 579. if (!unkn) { 580. makeknown(otmp->otyp); 581. more_experienced(0, 10); 582. } else if (!objects[otmp->otyp].oc_uname) 583. docall(otmp); 584. } 585. useup(otmp); 586. return 1; 587. } 588. 589. int 590. peffects(otmp) 591. register struct obj *otmp; 592. { 593. register int i, ii, lim; 594. 595. switch (otmp->otyp) { 596. case POT_RESTORE_ABILITY: 597. case SPE_RESTORE_ABILITY: 598. unkn++; 599. if (otmp->cursed) { 600. pline("Ulch! This makes you feel mediocre!"); 601. break; 602. } else { 603. /* unlike unicorn horn, overrides Fixed_abil */ 604. pline("Wow! This makes you feel %s!", 605. (otmp->blessed) 606. ? (unfixable_trouble_count(FALSE) ? "better" : "great") 607. : "good"); 608. i = rn2(A_MAX); /* start at a random point */ 609. for (ii = 0; ii < A_MAX; ii++) { 610. lim = AMAX(i); 611. /* this used to adjust 'lim' for A_STR when u.uhs was 612. WEAK or worse, but that's handled via ATEMP(A_STR) now */ 613. if (ABASE(i) < lim) { 614. ABASE(i) = lim; 615. context.botl = 1; 616. /* only first found if not blessed */ 617. if (!otmp->blessed) 618. break; 619. } 620. if (++i >= A_MAX) 621. i = 0; 622. } 623. 624. /* when using the potion (not the spell) also restore lost levels, 625. to make the potion more worth keeping around for players with 626. the spell or with a unihorn; this is better than full healing 627. in that it can restore all of them, not just half, and a 628. blessed potion restores them all at once */ 629. if (otmp->otyp == POT_RESTORE_ABILITY && u.ulevel < u.ulevelmax) { 630. do { 631. pluslvl(FALSE); 632. } while (u.ulevel < u.ulevelmax && otmp->blessed); 633. } 634. } 635. break; 636. case POT_HALLUCINATION: 637. if (Hallucination || Halluc_resistance) 638. nothing++; 639. (void) make_hallucinated(itimeout_incr(HHallucination, 640. rn1(200, 600 - 300 * bcsign(otmp))), 641. TRUE, 0L); 642. break; 643. case POT_WATER: 644. if (!otmp->blessed && !otmp->cursed) { 645. pline("This tastes like %s.", hliquid("water")); 646. u.uhunger += rnd(10); 647. newuhs(FALSE); 648. break; 649. } 650. unkn++; 651. if (is_undead(youmonst.data) || is_demon(youmonst.data) 652. || u.ualign.type == A_CHAOTIC) { 653. if (otmp->blessed) { 654. pline("This burns like %s!", hliquid("acid")); 655. exercise(A_CON, FALSE); 656. if (u.ulycn >= LOW_PM) { 657. Your("affinity to %s disappears!", 658. makeplural(mons[u.ulycn].mname)); 659. if (youmonst.data == &mons[u.ulycn]) 660. you_unwere(FALSE); 661. set_ulycn(NON_PM); /* cure lycanthropy */ 662. } 663. losehp(Maybe_Half_Phys(d(2, 6)), "potion of holy water", 664. KILLED_BY_AN); 665. } else if (otmp->cursed) { 666. You_feel("quite proud of yourself."); 667. healup(d(2, 6), 0, 0, 0); 668. if (u.ulycn >= LOW_PM && !Upolyd) 669. you_were(); 670. exercise(A_CON, TRUE); 671. } 672. } else { 673. if (otmp->blessed) { 674. You_feel("full of awe."); 675. make_sick(0L, (char *) 0, TRUE, SICK_ALL); 676. exercise(A_WIS, TRUE); 677. exercise(A_CON, TRUE); 678. if (u.ulycn >= LOW_PM) 679. you_unwere(TRUE); /* "Purified" */ 680. /* make_confused(0L, TRUE); */ 681. } else { 682. if (u.ualign.type == A_LAWFUL) { 683. pline("This burns like %s!", hliquid("acid")); 684. losehp(Maybe_Half_Phys(d(2, 6)), "potion of unholy water", 685. KILLED_BY_AN); 686. } else 687. You_feel("full of dread."); 688. if (u.ulycn >= LOW_PM && !Upolyd) 689. you_were(); 690. exercise(A_CON, FALSE); 691. } 692. } 693. break; 694. case POT_BOOZE: 695. unkn++; 696. pline("Ooph! This tastes like %s%s!", 697. otmp->odiluted ? "watered down " : "", 698. Hallucination ? "dandelion wine" : "liquid fire"); 699. if (!otmp->blessed) 700. make_confused(itimeout_incr(HConfusion, d(3, 8)), FALSE); 701. /* the whiskey makes us feel better */ 702. if (!otmp->odiluted) 703. healup(1, 0, FALSE, FALSE); 704. u.uhunger += 10 * (2 + bcsign(otmp)); 705. newuhs(FALSE); 706. exercise(A_WIS, FALSE); 707. if (otmp->cursed) { 708. You("pass out."); 709. multi = -rnd(15); 710. nomovemsg = "You awake with a headache."; 711. } 712. break; 713. case POT_ENLIGHTENMENT: 714. if (otmp->cursed) { 715. unkn++; 716. You("have an uneasy feeling..."); 717. exercise(A_WIS, FALSE); 718. } else { 719. if (otmp->blessed) { 720. (void) adjattrib(A_INT, 1, FALSE); 721. (void) adjattrib(A_WIS, 1, FALSE); 722. } 723. You_feel("self-knowledgeable..."); 724. display_nhwindow(WIN_MESSAGE, FALSE); 725. enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); 726. pline_The("feeling subsides."); 727. exercise(A_WIS, TRUE); 728. } 729. break; 730. case SPE_INVISIBILITY: 731. /* spell cannot penetrate mummy wrapping */ 732. if (BInvis && uarmc->otyp == MUMMY_WRAPPING) { 733. You_feel("rather itchy under %s.", yname(uarmc)); 734. break; 735. } 736. /* FALLTHRU */ 737. case POT_INVISIBILITY: 738. if (Invis || Blind || BInvis) { 739. nothing++; 740. } else { 741. self_invis_message(); 742. } 743. if (otmp->blessed) 744. HInvis |= FROMOUTSIDE; 745. else 746. incr_itimeout(&HInvis, rn1(15, 31)); 747. newsym(u.ux, u.uy); /* update position */ 748. if (otmp->cursed) { 749. pline("For some reason, you feel your presence is known."); 750. aggravate(); 751. } 752. break; 753. case POT_SEE_INVISIBLE: /* tastes like fruit juice in Rogue */ 754. case POT_FRUIT_JUICE: { 755. int msg = Invisible && !Blind; 756. 757. unkn++; 758. if (otmp->cursed) 759. pline("Yecch! This tastes %s.", 760. Hallucination ? "overripe" : "rotten"); 761. else 762. pline( 763. Hallucination 764. ? "This tastes like 10%% real %s%s all-natural beverage." 765. : "This tastes like %s%s.", 766. otmp->odiluted ? "reconstituted " : "", fruitname(TRUE)); 767. if (otmp->otyp == POT_FRUIT_JUICE) { 768. u.uhunger += (otmp->odiluted ? 5 : 10) * (2 + bcsign(otmp)); 769. newuhs(FALSE); 770. break; 771. } 772. if (!otmp->cursed) { 773. /* Tell them they can see again immediately, which 774. * will help them identify the potion... 775. */ 776. make_blinded(0L, TRUE); 777. } 778. if (otmp->blessed) 779. HSee_invisible |= FROMOUTSIDE; 780. else 781. incr_itimeout(&HSee_invisible, rn1(100, 750)); 782. set_mimic_blocking(); /* do special mimic handling */ 783. see_monsters(); /* see invisible monsters */ 784. newsym(u.ux, u.uy); /* see yourself! */ 785. if (msg && !Blind) { /* Blind possible if polymorphed */ 786. You("can see through yourself, but you are visible!"); 787. unkn--; 788. } 789. break; 790. } 791. case POT_PARALYSIS: 792. if (Free_action) { 793. You("stiffen momentarily."); 794. } else { 795. if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) 796. You("are motionlessly suspended."); 797. else if (u.usteed) 798. You("are frozen in place!"); 799. else 800. Your("%s are frozen to the %s!", makeplural(body_part(FOOT)), 801. surface(u.ux, u.uy)); 802. nomul(-(rn1(10, 25 - 12 * bcsign(otmp)))); 803. multi_reason = "frozen by a potion"; 804. nomovemsg = You_can_move_again; 805. exercise(A_DEX, FALSE); 806. } 807. break; 808. case POT_SLEEPING: 809. if (Sleep_resistance || Free_action) { 810. You("yawn."); 811. } else { 812. You("suddenly fall asleep!"); 813. fall_asleep(-rn1(10, 25 - 12 * bcsign(otmp)), TRUE); 814. } 815. break; 816. case POT_MONSTER_DETECTION: 817. case SPE_DETECT_MONSTERS: 818. if (otmp->blessed) { 819. int x, y; 820. 821. if (Detect_monsters) 822. nothing++; 823. unkn++; 824. /* after a while, repeated uses become less effective */ 825. if ((HDetect_monsters & TIMEOUT) >= 300L) 826. i = 1; 827. else 828. i = rn1(40, 21); 829. incr_itimeout(&HDetect_monsters, i); 830. for (x = 1; x < COLNO; x++) { 831. for (y = 0; y < ROWNO; y++) { 832. if (levl[x][y].glyph == GLYPH_INVISIBLE) { 833. unmap_object(x, y); 834. newsym(x, y); 835. } 836. if (MON_AT(x, y)) 837. unkn = 0; 838. } 839. } 840. see_monsters(); 841. if (unkn) 842. You_feel("lonely."); 843. break; 844. } 845. if (monster_detect(otmp, 0)) 846. return 1; /* nothing detected */ 847. exercise(A_WIS, TRUE); 848. break; 849. case POT_OBJECT_DETECTION: 850. case SPE_DETECT_TREASURE: 851. if (object_detect(otmp, 0)) 852. return 1; /* nothing detected */ 853. exercise(A_WIS, TRUE); 854. break; 855. case POT_SICKNESS: 856. pline("Yecch! This stuff tastes like poison."); 857. if (otmp->blessed) { 858. pline("(But in fact it was mildly stale %s.)", fruitname(TRUE)); 859. if (!Role_if(PM_HEALER)) { 860. /* NB: blessed otmp->fromsink is not possible */ 861. losehp(1, "mildly contaminated potion", KILLED_BY_AN); 862. } 863. } else { 864. if (Poison_resistance) 865. pline("(But in fact it was biologically contaminated %s.)", 866. fruitname(TRUE)); 867. if (Role_if(PM_HEALER)) { 868. pline("Fortunately, you have been immunized."); 869. } else { 870. char contaminant[BUFSZ]; 871. int typ = rn2(A_MAX); 872. 873. Sprintf(contaminant, "%s%s", 874. (Poison_resistance) ? "mildly " : "", 875. (otmp->fromsink) ? "contaminated tap water" 876. : "contaminated potion"); 877. if (!Fixed_abil) { 878. poisontell(typ, FALSE); 879. (void) adjattrib(typ, Poison_resistance ? -1 : -rn1(4, 3), 880. 1); 881. } 882. if (!Poison_resistance) { 883. if (otmp->fromsink) 884. losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant, 885. KILLED_BY); 886. else 887. losehp(rnd(10) + 5 * !!(otmp->cursed), contaminant, 888. KILLED_BY_AN); 889. } else { 890. /* rnd loss is so that unblessed poorer than blessed */ 891. losehp(1 + rn2(2), contaminant, 892. (otmp->fromsink) ? KILLED_BY : KILLED_BY_AN); 893. } 894. exercise(A_CON, FALSE); 895. } 896. } 897. if (Hallucination) { 898. You("are shocked back to your senses!"); 899. (void) make_hallucinated(0L, FALSE, 0L); 900. } 901. break; 902. case POT_CONFUSION: 903. if (!Confusion) { 904. if (Hallucination) { 905. pline("What a trippy feeling!"); 906. unkn++; 907. } else 908. pline("Huh, What? Where am I?"); 909. } else 910. nothing++; 911. make_confused(itimeout_incr(HConfusion, 912. rn1(7, 16 - 8 * bcsign(otmp))), 913. FALSE); 914. break; 915. case POT_GAIN_ABILITY: 916. if (otmp->cursed) { 917. pline("Ulch! That potion tasted foul!"); 918. unkn++; 919. } else if (Fixed_abil) { 920. nothing++; 921. } else { /* If blessed, increase all; if not, try up to */ 922. int itmp; /* 6 times to find one which can be increased. */ 923. 924. i = -1; /* increment to 0 */ 925. for (ii = A_MAX; ii > 0; ii--) { 926. i = (otmp->blessed ? i + 1 : rn2(A_MAX)); 927. /* only give "your X is already as high as it can get" 928. message on last attempt (except blessed potions) */ 929. itmp = (otmp->blessed || ii == 1) ? 0 : -1; 930. if (adjattrib(i, 1, itmp) && !otmp->blessed) 931. break; 932. } 933. } 934. break; 935. case POT_SPEED: 936. /* skip when mounted; heal_legs() would heal steed's legs */ 937. if (Wounded_legs && !otmp->cursed && !u.usteed) { 938. heal_legs(0); 939. unkn++; 940. break; 941. } 942. /* FALLTHRU */ 943. case SPE_HASTE_SELF: 944. if (!Very_fast) { /* wwf@doe.carleton.ca */ 945. You("are suddenly moving %sfaster.", Fast ? "" : "much "); 946. } else { 947. Your("%s get new energy.", makeplural(body_part(LEG))); 948. unkn++; 949. } 950. exercise(A_DEX, TRUE); 951. incr_itimeout(&HFast, rn1(10, 100 + 60 * bcsign(otmp))); 952. break; 953. case POT_BLINDNESS: 954. if (Blind) 955. nothing++; 956. make_blinded(itimeout_incr(Blinded, 957. rn1(200, 250 - 125 * bcsign(otmp))), 958. (boolean) !Blind); 959. break; 960. case POT_GAIN_LEVEL: 961. if (otmp->cursed) { 962. unkn++; 963. /* they went up a level */ 964. if ((ledger_no(&u.uz) == 1 && u.uhave.amulet) 965. || Can_rise_up(u.ux, u.uy, &u.uz)) { 966. const char *riseup = "rise up, through the %s!"; 967. 968. if (ledger_no(&u.uz) == 1) { 969. You(riseup, ceiling(u.ux, u.uy)); 970. goto_level(&earth_level, FALSE, FALSE, FALSE); 971. } else { 972. register int newlev = depth(&u.uz) - 1; 973. d_level newlevel; 974. 975. get_level(&newlevel, newlev); 976. if (on_level(&newlevel, &u.uz)) { 977. pline("It tasted bad."); 978. break; 979. } else 980. You(riseup, ceiling(u.ux, u.uy)); 981. goto_level(&newlevel, FALSE, FALSE, FALSE); 982. } 983. } else 984. You("have an uneasy feeling."); 985. break; 986. } 987. pluslvl(FALSE); 988. /* blessed potions place you at a random spot in the 989. middle of the new level instead of the low point */ 990. if (otmp->blessed) 991. u.uexp = rndexp(TRUE); 992. break; 993. case POT_HEALING: 994. You_feel("better."); 995. healup(d(6 + 2 * bcsign(otmp), 4), !otmp->cursed ? 1 : 0, 996. !!otmp->blessed, !otmp->cursed); 997. exercise(A_CON, TRUE); 998. break; 999. case POT_EXTRA_HEALING: 1000. You_feel("much better."); 1001. healup(d(6 + 2 * bcsign(otmp), 8), 1002. otmp->blessed ? 5 : !otmp->cursed ? 2 : 0, !otmp->cursed, 1003. TRUE); 1004. (void) make_hallucinated(0L, TRUE, 0L); 1005. exercise(A_CON, TRUE); 1006. exercise(A_STR, TRUE); 1007. break; 1008. case POT_FULL_HEALING: 1009. You_feel("completely healed."); 1010. healup(400, 4 + 4 * bcsign(otmp), !otmp->cursed, TRUE); 1011. /* Restore one lost level if blessed */ 1012. if (otmp->blessed && u.ulevel < u.ulevelmax) { 1013. /* when multiple levels have been lost, drinking 1014. multiple potions will only get half of them back */ 1015. u.ulevelmax -= 1; 1016. pluslvl(FALSE); 1017. } 1018. (void) make_hallucinated(0L, TRUE, 0L); 1019. exercise(A_STR, TRUE); 1020. exercise(A_CON, TRUE); 1021. break; 1022. case POT_LEVITATION: 1023. case SPE_LEVITATION: 1024. /* 1025. * BLevitation will be set if levitation is blocked due to being 1026. * inside rock (currently or formerly in phazing xorn form, perhaps) 1027. * but it doesn't prevent setting or incrementing Levitation timeout 1028. * (which will take effect after escaping from the rock if it hasn't 1029. * expired by then). 1030. */ 1031. if (!Levitation && !BLevitation) { 1032. /* kludge to ensure proper operation of float_up() */ 1033. set_itimeout(&HLevitation, 1L); 1034. float_up(); 1035. /* This used to set timeout back to 0, then increment it below 1036. for blessed and uncursed effects. But now we leave it so 1037. that cursed effect yields "you float down" on next turn. 1038. Blessed and uncursed get one extra turn duration. */ 1039. } else /* already levitating, or can't levitate */ 1040. nothing++; 1041. 1042. if (otmp->cursed) { 1043. /* 'already levitating' used to block the cursed effect(s) 1044. aside from ~I_SPECIAL; it was not clear whether that was 1045. intentional; either way, it no longer does (as of 3.6.1) */ 1046. HLevitation &= ~I_SPECIAL; /* can't descend upon demand */ 1047. if (BLevitation) { 1048. ; /* rising via levitation is blocked */ 1049. } else if ((u.ux == xupstair && u.uy == yupstair) 1050. || (sstairs.up && u.ux == sstairs.sx && u.uy == sstairs.sy) 1051. || (xupladder && u.ux == xupladder && u.uy == yupladder)) { 1052. (void) doup(); 1053. /* in case we're already Levitating, which would have 1054. resulted in incrementing 'nothing' */ 1055. nothing = 0; /* not nothing after all */ 1056. } else if (has_ceiling(&u.uz)) { 1057. int dmg = rnd(!uarmh ? 10 : !is_metallic(uarmh) ? 6 : 3); 1058. 1059. You("hit your %s on the %s.", body_part(HEAD), 1060. ceiling(u.ux, u.uy)); 1061. losehp(Maybe_Half_Phys(dmg), "colliding with the ceiling", 1062. KILLED_BY); 1063. nothing = 0; /* not nothing after all */ 1064. } 1065. } else if (otmp->blessed) { 1066. /* at this point, timeout is already at least 1 */ 1067. incr_itimeout(&HLevitation, rn1(50, 250)); 1068. /* can descend at will (stop levitating via '>') provided timeout 1069. is the only factor (ie, not also wearing Lev ring or boots) */ 1070. HLevitation |= I_SPECIAL; 1071. } else /* timeout is already at least 1 */ 1072. incr_itimeout(&HLevitation, rn1(140, 10)); 1073. 1074. if (Levitation && IS_SINK(levl[u.ux][u.uy].typ)) 1075. spoteffects(FALSE); 1076. /* levitating blocks flying */ 1077. float_vs_flight(); 1078. break; 1079. case POT_GAIN_ENERGY: { /* M. Stephenson */ 1080. int num; 1081. 1082. if (otmp->cursed) 1083. You_feel("lackluster."); 1084. else 1085. pline("Magical energies course through your body."); 1086. 1087. /* old: num = rnd(5) + 5 * otmp->blessed + 1; 1088. * blessed: +7..11 max & current (+9 avg) 1089. * uncursed: +2.. 6 max & current (+4 avg) 1090. * cursed: -2.. 6 max & current (-4 avg) 1091. * new: (3.6.0) 1092. * blessed: +3..18 max (+10.5 avg), +9..54 current (+31.5 avg) 1093. * uncursed: +2..12 max (+ 7 avg), +6..36 current (+21 avg) 1094. * cursed: -1.. 6 max (- 3.5 avg), -3..18 current (-10.5 avg) 1095. */ 1096. num = d(otmp->blessed ? 3 : !otmp->cursed ? 2 : 1, 6); 1097. if (otmp->cursed) 1098. num = -num; /* subtract instead of add when cursed */ 1099. u.uenmax += num; 1100. if (u.uenmax <= 0) 1101. u.uenmax = 0; 1102. u.uen += 3 * num; 1103. if (u.uen > u.uenmax) 1104. u.uen = u.uenmax; 1105. else if (u.uen <= 0) 1106. u.uen = 0; 1107. context.botl = 1; 1108. exercise(A_WIS, TRUE); 1109. break; 1110. } 1111. case POT_OIL: { /* P. Winner */ 1112. boolean good_for_you = FALSE; 1113. 1114. if (otmp->lamplit) { 1115. if (likes_fire(youmonst.data)) { 1116. pline("Ahh, a refreshing drink."); 1117. good_for_you = TRUE; 1118. } else { 1119. You("burn your %s.", body_part(FACE)); 1120. /* fire damage */ 1121. losehp(d(Fire_resistance ? 1 : 3, 4), "burning potion of oil", 1122. KILLED_BY_AN); 1123. } 1124. } else if (otmp->cursed) 1125. pline("This tastes like castor oil."); 1126. else 1127. pline("That was smooth!"); 1128. exercise(A_WIS, good_for_you); 1129. break; 1130. } 1131. case POT_ACID: 1132. if (Acid_resistance) { 1133. /* Not necessarily a creature who _likes_ acid */ 1134. pline("This tastes %s.", Hallucination ? "tangy" : "sour"); 1135. } else { 1136. int dmg; 1137. 1138. pline("This burns%s!", 1139. otmp->blessed ? " a little" : otmp->cursed ? " a lot" 1140. : " like acid"); 1141. dmg = d(otmp->cursed ? 2 : 1, otmp->blessed ? 4 : 8); 1142. losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN); 1143. exercise(A_CON, FALSE); 1144. } 1145. if (Stoned) 1146. fix_petrification(); 1147. unkn++; /* holy/unholy water can burn like acid too */ 1148. break; 1149. case POT_POLYMORPH: 1150. You_feel("a little %s.", Hallucination ? "normal" : "strange"); 1151. if (!Unchanging) 1152. polyself(0); 1153. break; 1154. default: 1155. impossible("What a funny potion! (%u)", otmp->otyp); 1156. return 0; 1157. } 1158. return -1; 1159. } 1160. 1161. void 1162. healup(nhp, nxtra, curesick, cureblind) 1163. int nhp, nxtra; 1164. register boolean curesick, cureblind; 1165. { 1166. if (nhp) { 1167. if (Upolyd) { 1168. u.mh += nhp; 1169. if (u.mh > u.mhmax) 1170. u.mh = (u.mhmax += nxtra); 1171. } else { 1172. u.uhp += nhp; 1173. if (u.uhp > u.uhpmax) 1174. u.uhp = (u.uhpmax += nxtra); 1175. } 1176. } 1177. if (cureblind) { 1178. /* 3.6.1: it's debatible whether healing magic should clean off 1179. mundane 'dirt', but if it doesn't, blindness isn't cured */ 1180. u.ucreamed = 0; 1181. make_blinded(0L, TRUE); 1182. /* heal deafness too */ 1183. make_deaf(0L, TRUE); 1184. } 1185. if (curesick) { 1186. make_vomiting(0L, TRUE); 1187. make_sick(0L, (char *) 0, TRUE, SICK_ALL); 1188. } 1189. context.botl = 1; 1190. return; 1191. } 1192. 1193. void 1194. strange_feeling(obj, txt) 1195. struct obj *obj; 1196. const char *txt; 1197. { 1198. if (flags.beginner || !txt) 1199. You("have a %s feeling for a moment, then it passes.", 1200. Hallucination ? "normal" : "strange"); 1201. else 1202. pline1(txt); 1203. 1204. if (!obj) /* e.g., crystal ball finds no traps */ 1205. return; 1206. 1207. if (obj->dknown && !objects[obj->otyp].oc_name_known 1208. && !objects[obj->otyp].oc_uname) 1209. docall(obj); 1210. 1211. useup(obj); 1212. } 1213. 1214. const char *bottlenames[] = { "bottle", "phial", "flagon", "carafe", 1215. "flask", "jar", "vial" }; 1216. 1217. const char * 1218. bottlename() 1219. { 1220. return bottlenames[rn2(SIZE(bottlenames))]; 1221. } 1222. 1223. /* handle item dipped into water potion or steed saddle splashed by same */ 1224. STATIC_OVL boolean 1225. H2Opotion_dip(potion, targobj, useeit, objphrase) 1226. struct obj *potion, *targobj; 1227. boolean useeit; 1228. const char *objphrase; /* "Your widget glows" or "Steed's saddle glows" */ 1229. { 1230. void FDECL((*func), (OBJ_P)) = 0; 1231. const char *glowcolor = 0; 1232. #define COST_alter (-2) 1233. #define COST_none (-1) 1234. int costchange = COST_none; 1235. boolean altfmt = FALSE, res = FALSE; 1236. 1237. if (!potion || potion->otyp != POT_WATER) 1238. return FALSE; 1239. 1240. if (potion->blessed) { 1241. if (targobj->cursed) { 1242. func = uncurse; 1243. glowcolor = NH_AMBER; 1244. costchange = COST_UNCURS; 1245. } else if (!targobj->blessed) { 1246. func = bless; 1247. glowcolor = NH_LIGHT_BLUE; 1248. costchange = COST_alter; 1249. altfmt = TRUE; /* "with a <color> aura" */ 1250. } 1251. } else if (potion->cursed) { 1252. if (targobj->blessed) { 1253. func = unbless; 1254. glowcolor = "brown"; 1255. costchange = COST_UNBLSS; 1256. } else if (!targobj->cursed) { 1257. func = curse; 1258. glowcolor = NH_BLACK; 1259. costchange = COST_alter; 1260. altfmt = TRUE; 1261. } 1262. } else { 1263. /* dipping into uncursed water; carried() check skips steed saddle */ 1264. if (carried(targobj)) { 1265. if (water_damage(targobj, 0, TRUE) != ER_NOTHING) 1266. res = TRUE; 1267. } 1268. } 1269. if (func) { 1270. /* give feedback before altering the target object; 1271. this used to set obj->bknown even when not seeing 1272. the effect; now hero has to see the glow, and bknown 1273. is cleared instead of set if perception is distorted */ 1274. if (useeit) { 1275. glowcolor = hcolor(glowcolor); 1276. if (altfmt) 1277. pline("%s with %s aura.", objphrase, an(glowcolor)); 1278. else 1279. pline("%s %s.", objphrase, glowcolor); 1280. iflags.last_msg = PLNMSG_OBJ_GLOWS; 1281. targobj->bknown = !Hallucination; 1282. } else { 1283. /* didn't see what happened: forget the BUC state if that was 1284. known unless the bless/curse state of the water is known; 1285. without this, hero would know the new state even without 1286. seeing the glow; priest[ess] will immediately relearn it */ 1287. if (!potion->bknown || !potion->dknown) 1288. targobj->bknown = 0; 1289. /* [should the bknown+dknown exception require that water 1290. be discovered or at least named?] */ 1291. } 1292. /* potions of water are the only shop goods whose price depends 1293. on their curse/bless state */ 1294. if (targobj->unpaid && targobj->otyp == POT_WATER) { 1295. if (costchange == COST_alter) 1296. /* added blessing or cursing; update shop 1297. bill to reflect item's new higher price */ 1298. alter_cost(targobj, 0L); 1299. else if (costchange != COST_none) 1300. /* removed blessing or cursing; you 1301. degraded it, now you'll have to buy it... */ 1302. costly_alteration(targobj, costchange); 1303. } 1304. /* finally, change curse/bless state */ 1305. (*func)(targobj); 1306. res = TRUE; 1307. } 1308. return res; 1309. } 1310. 1311. /* potion obj hits monster mon, which might be youmonst; obj always used up */ 1312. void 1313. potionhit(mon, obj, how) 1314. struct monst *mon; 1315. struct obj *obj; 1316. int how; 1317. { 1318. const char *botlnam = bottlename(); 1319. boolean isyou = (mon == &youmonst); 1320. int distance, tx, ty; 1321. struct obj *saddle = (struct obj *) 0; 1322. boolean hit_saddle = FALSE, your_fault = (how <= POTHIT_HERO_THROW); 1323. 1324. if (isyou) { 1325. tx = u.ux, ty = u.uy; 1326. distance = 0; 1327. pline_The("%s crashes on your %s and breaks into shards.", botlnam, 1328. body_part(HEAD)); 1329. losehp(Maybe_Half_Phys(rnd(2)), 1330. (how == POTHIT_OTHER_THROW) ? "propelled potion" /* scatter */ 1331. : "thrown potion", 1332. KILLED_BY_AN); 1333. } else { 1334. tx = mon->mx, ty = mon->my; 1335. /* sometimes it hits the saddle */ 1336. if (((mon->misc_worn_check & W_SADDLE) 1337. && (saddle = which_armor(mon, W_SADDLE))) 1338. && (!rn2(10) 1339. || (obj->otyp == POT_WATER 1340. && ((rnl(10) > 7 && obj->cursed) 1341. || (rnl(10) < 4 && obj->blessed) || !rn2(3))))) 1342. hit_saddle = TRUE; 1343. distance = distu(tx, ty); 1344. if (!cansee(tx, ty)) { 1345. pline("Crash!"); 1346. } else { 1347. char *mnam = mon_nam(mon); 1348. char buf[BUFSZ]; 1349. 1350. if (hit_saddle && saddle) { 1351. Sprintf(buf, "%s saddle", 1352. s_suffix(x_monnam(mon, ARTICLE_THE, (char *) 0, 1353. (SUPPRESS_IT | SUPPRESS_SADDLE), 1354. FALSE))); 1355. } else if (has_head(mon->data)) { 1356. Sprintf(buf, "%s %s", s_suffix(mnam), 1357. (notonhead ? "body" : "head")); 1358. } else { 1359. Strcpy(buf, mnam); 1360. } 1361. pline_The("%s crashes on %s and breaks into shards.", botlnam, 1362. buf); 1363. } 1364. if (rn2(5) && mon->mhp > 1 && !hit_saddle) 1365. mon->mhp--; 1366. } 1367. 1368. /* oil doesn't instantly evaporate; Neither does a saddle hit */ 1369. if (obj->otyp != POT_OIL && !hit_saddle && cansee(tx, ty)) 1370. pline("%s.", Tobjnam(obj, "evaporate")); 1371. 1372. if (isyou) { 1373. switch (obj->otyp) { 1374. case POT_OIL: 1375. if (obj->lamplit) 1376. explode_oil(obj, u.ux, u.uy); 1377. break; 1378. case POT_POLYMORPH: 1379. You_feel("a little %s.", Hallucination ? "normal" : "strange"); 1380. if (!Unchanging && !Antimagic) 1381. polyself(0); 1382. break; 1383. case POT_ACID: 1384. if (!Acid_resistance) { 1385. int dmg; 1386. 1387. pline("This burns%s!", 1388. obj->blessed ? " a little" 1389. : obj->cursed ? " a lot" : ""); 1390. dmg = d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8); 1391. losehp(Maybe_Half_Phys(dmg), "potion of acid", KILLED_BY_AN); 1392. } 1393. break; 1394. } 1395. } else if (hit_saddle && saddle) { 1396. char *mnam, buf[BUFSZ], saddle_glows[BUFSZ]; 1397. boolean affected = FALSE; 1398. boolean useeit = !Blind && canseemon(mon) && cansee(tx, ty); 1399. 1400. mnam = x_monnam(mon, ARTICLE_THE, (char *) 0, 1401. (SUPPRESS_IT | SUPPRESS_SADDLE), FALSE); 1402. Sprintf(buf, "%s", upstart(s_suffix(mnam))); 1403. 1404. switch (obj->otyp) { 1405. case POT_WATER: 1406. Sprintf(saddle_glows, "%s %s", buf, aobjnam(saddle, "glow")); 1407. affected = H2Opotion_dip(obj, saddle, useeit, saddle_glows); 1408. break; 1409. case POT_POLYMORPH: 1410. /* Do we allow the saddle to polymorph? */ 1411. break; 1412. } 1413. if (useeit && !affected) 1414. pline("%s %s wet.", buf, aobjnam(saddle, "get")); 1415. } else { 1416. boolean angermon = your_fault, cureblind = FALSE; 1417. 1418. switch (obj->otyp) { 1419. case POT_FULL_HEALING: 1420. cureblind = TRUE; 1421. /*FALLTHRU*/ 1422. case POT_EXTRA_HEALING: 1423. if (!obj->cursed) 1424. cureblind = TRUE; 1425. /*FALLTHRU*/ 1426. case POT_HEALING: 1427. if (obj->blessed) 1428. cureblind = TRUE; 1429. if (mon->data == &mons[PM_PESTILENCE]) 1430. goto do_illness; 1431. /*FALLTHRU*/ 1432. case POT_RESTORE_ABILITY: 1433. case POT_GAIN_ABILITY: 1434. do_healing: 1435. angermon = FALSE; 1436. if (mon->mhp < mon->mhpmax) { 1437. mon->mhp = mon->mhpmax; 1438. if (canseemon(mon)) 1439. pline("%s looks sound and hale again.", Monnam(mon)); 1440. } 1441. if (cureblind) 1442. mcureblindness(mon, canseemon(mon)); 1443. break; 1444. case POT_SICKNESS: 1445. if (mon->data == &mons[PM_PESTILENCE]) 1446. goto do_healing; 1447. if (dmgtype(mon->data, AD_DISE) 1448. /* won't happen, see prior goto */ 1449. || dmgtype(mon->data, AD_PEST) 1450. /* most common case */ 1451. || resists_poison(mon)) { 1452. if (canseemon(mon)) 1453. pline("%s looks unharmed.", Monnam(mon)); 1454. break; 1455. } 1456. do_illness: 1457. if ((mon->mhpmax > 3) && !resist(mon, POTION_CLASS, 0, NOTELL)) 1458. mon->mhpmax /= 2; 1459. if ((mon->mhp > 2) && !resist(mon, POTION_CLASS, 0, NOTELL)) 1460. mon->mhp /= 2; 1461. if (mon->mhp > mon->mhpmax) 1462. mon->mhp = mon->mhpmax; 1463. if (canseemon(mon)) 1464. pline("%s looks rather ill.", Monnam(mon)); 1465. break; 1466. case POT_CONFUSION: 1467. case POT_BOOZE: 1468. if (!resist(mon, POTION_CLASS, 0, NOTELL)) 1469. mon->mconf = TRUE; 1470. break; 1471. case POT_INVISIBILITY: { 1472. boolean sawit = canspotmon(mon); 1473. 1474. angermon = FALSE; 1475. mon_set_minvis(mon); 1476. if (sawit && !canspotmon(mon) && cansee(mon->mx, mon->my)) 1477. map_invisible(mon->mx, mon->my); 1478. break; 1479. } 1480. case POT_SLEEPING: 1481. /* wakeup() doesn't rouse victims of temporary sleep */ 1482. if (sleep_monst(mon, rnd(12), POTION_CLASS)) { 1483. pline("%s falls asleep.", Monnam(mon)); 1484. slept_monst(mon); 1485. } 1486. break; 1487. case POT_PARALYSIS: 1488. if (mon->mcanmove) { 1489. /* really should be rnd(5) for consistency with players 1490. * breathing potions, but... 1491. */ 1492. paralyze_monst(mon, rnd(25)); 1493. } 1494. break; 1495. case POT_SPEED: 1496. angermon = FALSE; 1497. mon_adjust_speed(mon, 1, obj); 1498. break; 1499. case POT_BLINDNESS: 1500. if (haseyes(mon->data)) { 1501. int btmp = 64 + rn2(32) 1502. + rn2(32) * !resist(mon, POTION_CLASS, 0, NOTELL); 1503. 1504. btmp += mon->mblinded; 1505. mon->mblinded = min(btmp, 127); 1506. mon->mcansee = 0; 1507. } 1508. break; 1509. case POT_WATER: 1510. if (is_undead(mon->data) || is_demon(mon->data) 1511. || is_were(mon->data) || is_vampshifter(mon)) { 1512. if (obj->blessed) { 1513. pline("%s %s in pain!", Monnam(mon), 1514. is_silent(mon->data) ? "writhes" : "shrieks"); 1515. if (!is_silent(mon->data)) 1516. wake_nearto(tx, ty, mon->data->mlevel * 10); 1517. mon->mhp -= d(2, 6); 1518. /* should only be by you */ 1519. if (DEADMONSTER(mon)) 1520. killed(mon); 1521. else if (is_were(mon->data) && !is_human(mon->data)) 1522. new_were(mon); /* revert to human */ 1523. } else if (obj->cursed) { 1524. angermon = FALSE; 1525. if (canseemon(mon)) 1526. pline("%s looks healthier.", Monnam(mon)); 1527. mon->mhp += d(2, 6); 1528. if (mon->mhp > mon->mhpmax) 1529. mon->mhp = mon->mhpmax; 1530. if (is_were(mon->data) && is_human(mon->data) 1531. && !Protection_from_shape_changers) 1532. new_were(mon); /* transform into beast */ 1533. } 1534. } else if (mon->data == &mons[PM_GREMLIN]) { 1535. angermon = FALSE; 1536. (void) split_mon(mon, (struct monst *) 0); 1537. } else if (mon->data == &mons[PM_IRON_GOLEM]) { 1538. if (canseemon(mon)) 1539. pline("%s rusts.", Monnam(mon)); 1540. mon->mhp -= d(1, 6); 1541. /* should only be by you */ 1542. if (DEADMONSTER(mon)) 1543. killed(mon); 1544. } 1545. break; 1546. case POT_OIL: 1547. if (obj->lamplit) 1548. explode_oil(obj, tx, ty); 1549. break; 1550. case POT_ACID: 1551. if (!resists_acid(mon) && !resist(mon, POTION_CLASS, 0, NOTELL)) { 1552. pline("%s %s in pain!", Monnam(mon), 1553. is_silent(mon->data) ? "writhes" : "shrieks"); 1554. if (!is_silent(mon->data)) 1555. wake_nearto(tx, ty, mon->data->mlevel * 10); 1556. mon->mhp -= d(obj->cursed ? 2 : 1, obj->blessed ? 4 : 8); 1557. if (DEADMONSTER(mon)) { 1558. if (your_fault) 1559. killed(mon); 1560. else 1561. monkilled(mon, "", AD_ACID); 1562. } 1563. } 1564. break; 1565. case POT_POLYMORPH: 1566. (void) bhitm(mon, obj); 1567. break; 1568. /* 1569. case POT_GAIN_LEVEL: 1570. case POT_LEVITATION: 1571. case POT_FRUIT_JUICE: 1572. case POT_MONSTER_DETECTION: 1573. case POT_OBJECT_DETECTION: 1574. break; 1575. */ 1576. } 1577. /* target might have been killed */ 1578. if (!DEADMONSTER(mon)) { 1579. if (angermon) 1580. wakeup(mon, TRUE); 1581. else 1582. mon->msleeping = 0; 1583. } 1584. } 1585. 1586. /* Note: potionbreathe() does its own docall() */ 1587. if ((distance == 0 || (distance < 3 && rn2(5))) 1588. && (!breathless(youmonst.data) || haseyes(youmonst.data))) 1589. potionbreathe(obj); 1590. else if (obj->dknown && !objects[obj->otyp].oc_name_known 1591. && !objects[obj->otyp].oc_uname && cansee(tx, ty)) 1592. docall(obj); 1593. 1594. if (*u.ushops && obj->unpaid) { 1595. struct monst *shkp = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE)); 1596. 1597. /* neither of the first two cases should be able to happen; 1598. only the hero should ever have an unpaid item, and only 1599. when inside a tended shop */ 1600. if (!shkp) /* if shkp was killed, unpaid ought to cleared already */ 1601. obj->unpaid = 0; 1602. else if (context.mon_moving) /* obj thrown by monster */ 1603. subfrombill(obj, shkp); 1604. else /* obj thrown by hero */ 1605. (void) stolen_value(obj, u.ux, u.uy, (boolean) shkp->mpeaceful, 1606. FALSE); 1607. } 1608. obfree(obj, (struct obj *) 0); 1609. } 1610. 1611. /* vapors are inhaled or get in your eyes */ 1612. void 1613. potionbreathe(obj) 1614. register struct obj *obj; 1615. { 1616. int i, ii, isdone, kn = 0; 1617. boolean cureblind = FALSE; 1618. 1619. /* potion of unholy water might be wielded; prevent 1620. you_were() -> drop_weapon() from dropping it so that it 1621. remains in inventory where our caller expects it to be */ 1622. obj->in_use = 1; 1623. 1624. switch (obj->otyp) { 1625. case POT_RESTORE_ABILITY: 1626. case POT_GAIN_ABILITY: 1627. if (obj->cursed) { 1628. if (!breathless(youmonst.data)) 1629. pline("Ulch! That potion smells terrible!"); 1630. else if (haseyes(youmonst.data)) { 1631. const char *eyes = body_part(EYE); 1632. 1633. if (eyecount(youmonst.data) != 1) 1634. eyes = makeplural(eyes); 1635. Your("%s %s!", eyes, vtense(eyes, "sting")); 1636. } 1637. break; 1638. } else { 1639. i = rn2(A_MAX); /* start at a random point */ 1640. for (isdone = ii = 0; !isdone && ii < A_MAX; ii++) { 1641. if (ABASE(i) < AMAX(i)) { 1642. ABASE(i)++; 1643. /* only first found if not blessed */ 1644. isdone = !(obj->blessed); 1645. context.botl = 1; 1646. } 1647. if (++i >= A_MAX) 1648. i = 0; 1649. } 1650. } 1651. break; 1652. case POT_FULL_HEALING: 1653. if (Upolyd && u.mh < u.mhmax) 1654. u.mh++, context.botl = 1; 1655. if (u.uhp < u.uhpmax) 1656. u.uhp++, context.botl = 1; 1657. cureblind = TRUE; 1658. /*FALLTHRU*/ 1659. case POT_EXTRA_HEALING: 1660. if (Upolyd && u.mh < u.mhmax) 1661. u.mh++, context.botl = 1; 1662. if (u.uhp < u.uhpmax) 1663. u.uhp++, context.botl = 1; 1664. if (!obj->cursed) 1665. cureblind = TRUE; 1666. /*FALLTHRU*/ 1667. case POT_HEALING: 1668. if (Upolyd && u.mh < u.mhmax) 1669. u.mh++, context.botl = 1; 1670. if (u.uhp < u.uhpmax) 1671. u.uhp++, context.botl = 1; 1672. if (obj->blessed) 1673. cureblind = TRUE; 1674. if (cureblind) { 1675. make_blinded(0L, !u.ucreamed); 1676. make_deaf(0L, TRUE); 1677. } 1678. exercise(A_CON, TRUE); 1679. break; 1680. case POT_SICKNESS: 1681. if (!Role_if(PM_HEALER)) { 1682. if (Upolyd) { 1683. if (u.mh <= 5) 1684. u.mh = 1; 1685. else 1686. u.mh -= 5; 1687. } else { 1688. if (u.uhp <= 5) 1689. u.uhp = 1; 1690. else 1691. u.uhp -= 5; 1692. } 1693. context.botl = 1; 1694. exercise(A_CON, FALSE); 1695. } 1696. break; 1697. case POT_HALLUCINATION: 1698. You("have a momentary vision."); 1699. break; 1700. case POT_CONFUSION: 1701. case POT_BOOZE: 1702. if (!Confusion) 1703. You_feel("somewhat dizzy."); 1704. make_confused(itimeout_incr(HConfusion, rnd(5)), FALSE); 1705. break; 1706. case POT_INVISIBILITY: 1707. if (!Blind && !Invis) { 1708. kn++; 1709. pline("For an instant you %s!", 1710. See_invisible ? "could see right through yourself" 1711. : "couldn't see yourself"); 1712. } 1713. break; 1714. case POT_PARALYSIS: 1715. kn++; 1716. if (!Free_action) { 1717. pline("%s seems to be holding you.", Something); 1718. nomul(-rnd(5)); 1719. multi_reason = "frozen by a potion"; 1720. nomovemsg = You_can_move_again; 1721. exercise(A_DEX, FALSE); 1722. } else 1723. You("stiffen momentarily."); 1724. break; 1725. case POT_SLEEPING: 1726. kn++; 1727. if (!Free_action && !Sleep_resistance) { 1728. You_feel("rather tired."); 1729. nomul(-rnd(5)); 1730. multi_reason = "sleeping off a magical draught"; 1731. nomovemsg = You_can_move_again; 1732. exercise(A_DEX, FALSE); 1733. } else 1734. You("yawn."); 1735. break; 1736. case POT_SPEED: 1737. if (!Fast) 1738. Your("knees seem more flexible now."); 1739. incr_itimeout(&HFast, rnd(5)); 1740. exercise(A_DEX, TRUE); 1741. break; 1742. case POT_BLINDNESS: 1743. if (!Blind && !Unaware) { 1744. kn++; 1745. pline("It suddenly gets dark."); 1746. } 1747. make_blinded(itimeout_incr(Blinded, rnd(5)), FALSE); 1748. if (!Blind && !Unaware) 1749. Your1(vision_clears); 1750. break; 1751. case POT_WATER: 1752. if (u.umonnum == PM_GREMLIN) { 1753. (void) split_mon(&youmonst, (struct monst *) 0); 1754. } else if (u.ulycn >= LOW_PM) { 1755. /* vapor from [un]holy water will trigger 1756. transformation but won't cure lycanthropy */ 1757. if (obj->blessed && youmonst.data == &mons[u.ulycn]) 1758. you_unwere(FALSE); 1759. else if (obj->cursed && !Upolyd) 1760. you_were(); 1761. } 1762. break; 1763. case POT_ACID: 1764. case POT_POLYMORPH: 1765. exercise(A_CON, FALSE); 1766. break; 1767. /* 1768. case POT_GAIN_LEVEL: 1769. case POT_LEVITATION: 1770. case POT_FRUIT_JUICE: 1771. case POT_MONSTER_DETECTION: 1772. case POT_OBJECT_DETECTION: 1773. case POT_OIL: 1774. break; 1775. */ 1776. } 1777. /* note: no obfree() -- that's our caller's responsibility */ 1778. if (obj->dknown) { 1779. if (kn) 1780. makeknown(obj->otyp); 1781. else if (!objects[obj->otyp].oc_name_known 1782. && !objects[obj->otyp].oc_uname) 1783. docall(obj); 1784. } 1785. } 1786. 1787. /* returns the potion type when o1 is dipped in o2 */ 1788. STATIC_OVL short 1789. mixtype(o1, o2) 1790. register struct obj *o1, *o2; 1791. { 1792. int o1typ = o1->otyp, o2typ = o2->otyp; 1793. 1794. /* cut down on the number of cases below */ 1795. if (o1->oclass == POTION_CLASS 1796. && (o2typ == POT_GAIN_LEVEL || o2typ == POT_GAIN_ENERGY 1797. || o2typ == POT_HEALING || o2typ == POT_EXTRA_HEALING 1798. || o2typ == POT_FULL_HEALING || o2typ == POT_ENLIGHTENMENT 1799. || o2typ == POT_FRUIT_JUICE)) { 1800. /* swap o1 and o2 */ 1801. o1typ = o2->otyp; 1802. o2typ = o1->otyp; 1803. } 1804. 1805. switch (o1typ) { 1806. case POT_HEALING: 1807. if (o2typ == POT_SPEED) 1808. return POT_EXTRA_HEALING; 1809. /*FALLTHRU*/ 1810. case POT_EXTRA_HEALING: 1811. case POT_FULL_HEALING: 1812. if (o2typ == POT_GAIN_LEVEL || o2typ == POT_GAIN_ENERGY) 1813. return (o1typ == POT_HEALING) ? POT_EXTRA_HEALING 1814. : (o1typ == POT_EXTRA_HEALING) ? POT_FULL_HEALING 1815. : POT_GAIN_ABILITY; 1816. /*FALLTHRU*/ 1817. case UNICORN_HORN: 1818. switch (o2typ) { 1819. case POT_SICKNESS: 1820. return POT_FRUIT_JUICE; 1821. case POT_HALLUCINATION: 1822. case POT_BLINDNESS: 1823. case POT_CONFUSION: 1824. return POT_WATER; 1825. } 1826. break; 1827. case AMETHYST: /* "a-methyst" == "not intoxicated" */ 1828. if (o2typ == POT_BOOZE) 1829. return POT_FRUIT_JUICE; 1830. break; 1831. case POT_GAIN_LEVEL: 1832. case POT_GAIN_ENERGY: 1833. switch (o2typ) { 1834. case POT_CONFUSION: 1835. return (rn2(3) ? POT_BOOZE : POT_ENLIGHTENMENT); 1836. case POT_HEALING: 1837. return POT_EXTRA_HEALING; 1838. case POT_EXTRA_HEALING: 1839. return POT_FULL_HEALING; 1840. case POT_FULL_HEALING: 1841. return POT_GAIN_ABILITY; 1842. case POT_FRUIT_JUICE: 1843. return POT_SEE_INVISIBLE; 1844. case POT_BOOZE: 1845. return POT_HALLUCINATION; 1846. } 1847. break; 1848. case POT_FRUIT_JUICE: 1849. switch (o2typ) { 1850. case POT_SICKNESS: 1851. return POT_SICKNESS; 1852. case POT_ENLIGHTENMENT: 1853. case POT_SPEED: 1854. return POT_BOOZE; 1855. case POT_GAIN_LEVEL: 1856. case POT_GAIN_ENERGY: 1857. return POT_SEE_INVISIBLE; 1858. } 1859. break; 1860. case POT_ENLIGHTENMENT: 1861. switch (o2typ) { 1862. case POT_LEVITATION: 1863. if (rn2(3)) 1864. return POT_GAIN_LEVEL; 1865. break; 1866. case POT_FRUIT_JUICE: 1867. return POT_BOOZE; 1868. case POT_BOOZE: 1869. return POT_CONFUSION; 1870. } 1871. break; 1872. } 1873. 1874. return STRANGE_OBJECT; 1875. } 1876. 1877. /* #dip command */ 1878. int 1879. dodip() 1880. { 1881. static const char Dip_[] = "Dip "; 1882. register struct obj *potion, *obj; 1883. struct obj *singlepotion; 1884. uchar here; 1885. char allowall[2]; 1886. short mixture; 1887. char qbuf[QBUFSZ], obuf[QBUFSZ]; 1888. const char *shortestname; /* last resort obj name for prompt */ 1889. 1890. allowall[0] = ALL_CLASSES; 1891. allowall[1] = '\0'; 1892. if (!(obj = getobj(allowall, "dip"))) 1893. return 0; 1894. if (inaccessible_equipment(obj, "dip", FALSE)) 1895. return 0; 1896. 1897. shortestname = (is_plural(obj) || pair_of(obj)) ? "them" : "it"; 1898. /* 1899. * Bypass safe_qbuf() since it doesn't handle varying suffix without 1900. * an awful lot of support work. Format the object once, even though 1901. * the fountain and pool prompts offer a lot more room for it. 1902. * 3.6.0 used thesimpleoname() unconditionally, which posed no risk 1903. * of buffer overflow but drew bug reports because it omits user- 1904. * supplied type name. 1905. * getobj: "What do you want to dip <the object> into? [xyz or ?*] " 1906. */ 1907. Strcpy(obuf, short_oname(obj, doname, thesimpleoname, 1908. /* 128 - (24 + 54 + 1) leaves 49 for <object> */ 1909. QBUFSZ - sizeof "What do you want to dip \ 1910. into? [abdeghjkmnpqstvwyzBCEFHIKLNOQRTUWXZ#-# or ?*] ")); 1911. 1912. here = levl[u.ux][u.uy].typ; 1913. /* Is there a fountain to dip into here? */ 1914. if (IS_FOUNTAIN(here)) { 1915. Sprintf(qbuf, "%s%s into the fountain?", Dip_, 1916. flags.verbose ? obuf : shortestname); 1917. /* "Dip <the object> into the fountain?" */ 1918. if (yn(qbuf) == 'y') { 1919. dipfountain(obj); 1920. return 1; 1921. } 1922. } else if (is_pool(u.ux, u.uy)) { 1923. const char *pooltype = waterbody_name(u.ux, u.uy); 1924. 1925. Sprintf(qbuf, "%s%s into the %s?", Dip_, 1926. flags.verbose ? obuf : shortestname, pooltype); 1927. /* "Dip <the object> into the {pool, moat, &c}?" */ 1928. if (yn(qbuf) == 'y') { 1929. if (Levitation) { 1930. floating_above(pooltype); 1931. } else if (u.usteed && !is_swimmer(u.usteed->data) 1932. && P_SKILL(P_RIDING) < P_BASIC) { 1933. rider_cant_reach(); /* not skilled enough to reach */ 1934. } else { 1935. if (obj->otyp == POT_ACID) 1936. obj->in_use = 1; 1937. if (water_damage(obj, 0, TRUE) != ER_DESTROYED && obj->in_use) 1938. useup(obj); 1939. } 1940. return 1; 1941. } 1942. } 1943. 1944. /* "What do you want to dip <the object> into? [xyz or ?*] " */ 1945. Sprintf(qbuf, "dip %s into", flags.verbose ? obuf : shortestname); 1946. potion = getobj(beverages, qbuf); 1947. if (!potion) 1948. return 0; 1949. if (potion == obj && potion->quan == 1L) { 1950. pline("That is a potion bottle, not a Klein bottle!"); 1951. return 0; 1952. } 1953. potion->in_use = TRUE; /* assume it will be used up */ 1954. if (potion->otyp == POT_WATER) { 1955. boolean useeit = !Blind || (obj == ublindf && Blindfolded_only); 1956. const char *obj_glows = Yobjnam2(obj, "glow"); 1957. 1958. if (H2Opotion_dip(potion, obj, useeit, obj_glows)) 1959. goto poof; 1960. } else if (obj->otyp == POT_POLYMORPH || potion->otyp == POT_POLYMORPH) { 1961. /* some objects can't be polymorphed */ 1962. if (obj->otyp == potion->otyp /* both POT_POLY */ 1963. || obj->otyp == WAN_POLYMORPH || obj->otyp == SPE_POLYMORPH 1964. || obj == uball || obj == uskin 1965. || obj_resists(obj->otyp == POT_POLYMORPH ? potion : obj, 1966. 5, 95)) { 1967. pline1(nothing_happens); 1968. } else { 1969. short save_otyp = obj->otyp; 1970. 1971. /* KMH, conduct */ 1972. u.uconduct.polypiles++; 1973. 1974. obj = poly_obj(obj, STRANGE_OBJECT); 1975. 1976. /* 1977. * obj might be gone: 1978. * poly_obj() -> set_wear() -> Amulet_on() -> useup() 1979. * if obj->otyp is worn amulet and becomes AMULET_OF_CHANGE. 1980. */ 1981. if (!obj) { 1982. makeknown(POT_POLYMORPH); 1983. return 1; 1984. } else if (obj->otyp != save_otyp) { 1985. makeknown(POT_POLYMORPH); 1986. useup(potion); 1987. prinv((char *) 0, obj, 0L); 1988. return 1; 1989. } else { 1990. pline("Nothing seems to happen."); 1991. goto poof; 1992. } 1993. } 1994. potion->in_use = FALSE; /* didn't go poof */ 1995. return 1; 1996. } else if (obj->oclass == POTION_CLASS && obj->otyp != potion->otyp) { 1997. int amt = (int) obj->quan; 1998. boolean magic; 1999. 2000. mixture = mixtype(obj, potion); 2001. 2002. magic = (mixture != STRANGE_OBJECT) ? objects[mixture].oc_magic 2003. : (objects[obj->otyp].oc_magic || objects[potion->otyp].oc_magic); 2004. Strcpy(qbuf, "The"); /* assume full stack */ 2005. if (amt > (magic ? 3 : 7)) { 2006. /* trying to dip multiple potions will usually affect only a 2007. subset; pick an amount between 3 and 8, inclusive, for magic 2008. potion result, between 7 and N for non-magic */ 2009. if (magic) 2010. amt = rnd(min(amt, 8) - (3 - 1)) + (3 - 1); /* 1..6 + 2 */ 2011. else 2012. amt = rnd(amt - (7 - 1)) + (7 - 1); /* 1..(N-6) + 6 */ 2013. 2014. if ((long) amt < obj->quan) { 2015. obj = splitobj(obj, (long) amt); 2016. Sprintf(qbuf, "%ld of the", obj->quan); 2017. } 2018. } 2019. /* [N of] the {obj(s)} mix(es) with [one of] {the potion}... */ 2020. pline("%s %s %s with %s%s...", qbuf, simpleonames(obj), 2021. otense(obj, "mix"), (potion->quan > 1L) ? "one of " : "", 2022. thesimpleoname(potion)); 2023. /* get rid of 'dippee' before potential perm_invent updates */ 2024. useup(potion); /* now gone */ 2025. /* Mixing potions is dangerous... 2026. KMH, balance patch -- acid is particularly unstable */ 2027. if (obj->cursed || obj->otyp == POT_ACID || !rn2(10)) { 2028. /* it would be better to use up the whole stack in advance 2029. of the message, but we can't because we need to keep it 2030. around for potionbreathe() [and we can't set obj->in_use 2031. to 'amt' because that's not implemented] */ 2032. obj->in_use = 1; 2033. pline("%sThey explode!", !Deaf ? "BOOM! " : ""); 2034. wake_nearto(u.ux, u.uy, (BOLT_LIM + 1) * (BOLT_LIM + 1)); 2035. exercise(A_STR, FALSE); 2036. if (!breathless(youmonst.data) || haseyes(youmonst.data)) 2037. potionbreathe(obj); 2038. useupall(obj); 2039. losehp(amt + rnd(9), /* not physical damage */ 2040. "alchemic blast", KILLED_BY_AN); 2041. return 1; 2042. } 2043. 2044. obj->blessed = obj->cursed = obj->bknown = 0; 2045. if (Blind || Hallucination) 2046. obj->dknown = 0; 2047. 2048. if (mixture != STRANGE_OBJECT) { 2049. obj->otyp = mixture; 2050. } else { 2051. struct obj *otmp; 2052. 2053. switch (obj->odiluted ? 1 : rnd(8)) { 2054. case 1: 2055. obj->otyp = POT_WATER; 2056. break; 2057. case 2: 2058. case 3: 2059. obj->otyp = POT_SICKNESS; 2060. break; 2061. case 4: 2062. otmp = mkobj(POTION_CLASS, FALSE); 2063. obj->otyp = otmp->otyp; 2064. obfree(otmp, (struct obj *) 0); 2065. break; 2066. default: 2067. useupall(obj); 2068. pline_The("mixture %sevaporates.", 2069. !Blind ? "glows brightly and " : ""); 2070. return 1; 2071. } 2072. } 2073. obj->odiluted = (obj->otyp != POT_WATER); 2074. 2075. if (obj->otyp == POT_WATER && !Hallucination) { 2076. pline_The("mixture bubbles%s.", Blind ? "" : ", then clears"); 2077. } else if (!Blind) { 2078. pline_The("mixture looks %s.", 2079. hcolor(OBJ_DESCR(objects[obj->otyp]))); 2080. } 2081. 2082. /* this is required when 'obj' was split off from a bigger stack, 2083. so that 'obj' will now be assigned its own inventory slot; 2084. it has a side-effect of merging 'obj' into another compatible 2085. stack if there is one, so we do it even when no split has 2086. been made in order to get the merge result for both cases; 2087. as a consequence, mixing while Fumbling drops the mixture */ 2088. freeinv(obj); 2089. (void) hold_another_object(obj, "You drop %s!", doname(obj), 2090. (const char *) 0); 2091. return 1; 2092. } 2093. 2094. if (potion->otyp == POT_ACID && obj->otyp == CORPSE 2095. && obj->corpsenm == PM_LICHEN) { 2096. pline("%s %s %s around the edges.", The(cxname(obj)), 2097. otense(obj, "turn"), Blind ? "wrinkled" 2098. : potion->odiluted ? hcolor(NH_ORANGE) 2099. : hcolor(NH_RED)); 2100. potion->in_use = FALSE; /* didn't go poof */ 2101. if (potion->dknown 2102. && !objects[potion->otyp].oc_name_known 2103. && !objects[potion->otyp].oc_uname) 2104. docall(potion); 2105. return 1; 2106. } 2107. 2108. if (potion->otyp == POT_WATER && obj->otyp == TOWEL) { 2109. pline_The("towel soaks it up!"); 2110. /* wetting towel already done via water_damage() in H2Opotion_dip */ 2111. goto poof; 2112. } 2113. 2114. if (is_poisonable(obj)) { 2115. if (potion->otyp == POT_SICKNESS && !obj->opoisoned) { 2116. char buf[BUFSZ]; 2117. 2118. if (potion->quan > 1L) 2119. Sprintf(buf, "One of %s", the(xname(potion))); 2120. else 2121. Strcpy(buf, The(xname(potion))); 2122. pline("%s forms a coating on %s.", buf, the(xname(obj))); 2123. obj->opoisoned = TRUE; 2124. goto poof; 2125. } else if (obj->opoisoned && (potion->otyp == POT_HEALING 2126. || potion->otyp == POT_EXTRA_HEALING 2127. || potion->otyp == POT_FULL_HEALING)) { 2128. pline("A coating wears off %s.", the(xname(obj))); 2129. obj->opoisoned = 0; 2130. goto poof; 2131. } 2132. } 2133. 2134. if (potion->otyp == POT_ACID) { 2135. if (erode_obj(obj, 0, ERODE_CORRODE, EF_GREASE) != ER_NOTHING) 2136. goto poof; 2137. } 2138. 2139. if (potion->otyp == POT_OIL) { 2140. boolean wisx = FALSE; 2141. 2142. if (potion->lamplit) { /* burning */ 2143. fire_damage(obj, TRUE, u.ux, u.uy); 2144. } else if (potion->cursed) { 2145. pline_The("potion spills and covers your %s with oil.", 2146. fingers_or_gloves(TRUE)); 2147. make_glib((int) (Glib & TIMEOUT) + d(2, 10)); 2148. } else if (obj->oclass != WEAPON_CLASS && !is_weptool(obj)) { 2149. /* the following cases apply only to weapons */ 2150. goto more_dips; 2151. /* Oil removes rust and corrosion, but doesn't unburn. 2152. * Arrows, etc are classed as metallic due to arrowhead 2153. * material, but dipping in oil shouldn't repair them. 2154. */ 2155. } else if ((!is_rustprone(obj) && !is_corrodeable(obj)) 2156. || is_ammo(obj) || (!obj->oeroded && !obj->oeroded2)) { 2157. /* uses up potion, doesn't set obj->greased */ 2158. if (!Blind) 2159. pline("%s %s with an oily sheen.", Yname2(obj), 2160. otense(obj, "gleam")); 2161. else /*if (!uarmg)*/ 2162. pline("%s %s oily.", Yname2(obj), otense(obj, "feel")); 2163. } else { 2164. pline("%s %s less %s.", Yname2(obj), 2165. otense(obj, !Blind ? "are" : "feel"), 2166. (obj->oeroded && obj->oeroded2) 2167. ? "corroded and rusty" 2168. : obj->oeroded ? "rusty" : "corroded"); 2169. if (obj->oeroded > 0) 2170. obj->oeroded--; 2171. if (obj->oeroded2 > 0) 2172. obj->oeroded2--; 2173. wisx = TRUE; 2174. } 2175. exercise(A_WIS, wisx); 2176. if (potion->dknown) 2177. makeknown(potion->otyp); 2178. useup(potion); 2179. return 1; 2180. } 2181. more_dips: 2182. 2183. /* Allow filling of MAGIC_LAMPs to prevent identification by player */ 2184. if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP) 2185. && (potion->otyp == POT_OIL)) { 2186. /* Turn off engine before fueling, turn off fuel too :-) */ 2187. if (obj->lamplit || potion->lamplit) { 2188. useup(potion); 2189. explode(u.ux, u.uy, 11, d(6, 6), 0, EXPL_FIERY); 2190. exercise(A_WIS, FALSE); 2191. return 1; 2192. } 2193. /* Adding oil to an empty magic lamp renders it into an oil lamp */ 2194. if ((obj->otyp == MAGIC_LAMP) && obj->spe == 0) { 2195. obj->otyp = OIL_LAMP; 2196. obj->age = 0; 2197. } 2198. if (obj->age > 1000L) { 2199. pline("%s %s full.", Yname2(obj), otense(obj, "are")); 2200. potion->in_use = FALSE; /* didn't go poof */ 2201. } else { 2202. You("fill %s with oil.", yname(obj)); 2203. check_unpaid(potion); /* Yendorian Fuel Tax */ 2204. /* burns more efficiently in a lamp than in a bottle; 2205. diluted potion provides less benefit but we don't attempt 2206. to track that the lamp now also has some non-oil in it */ 2207. obj->age += (!potion->odiluted ? 4L : 3L) * potion->age / 2L; 2208. if (obj->age > 1500L) 2209. obj->age = 1500L; 2210. useup(potion); 2211. exercise(A_WIS, TRUE); 2212. } 2213. if (potion->dknown) 2214. makeknown(POT_OIL); 2215. obj->spe = 1; 2216. update_inventory(); 2217. return 1; 2218. } 2219. 2220. potion->in_use = FALSE; /* didn't go poof */ 2221. if ((obj->otyp == UNICORN_HORN || obj->otyp == AMETHYST) 2222. && (mixture = mixtype(obj, potion)) != STRANGE_OBJECT) { 2223. char oldbuf[BUFSZ], newbuf[BUFSZ]; 2224. short old_otyp = potion->otyp; 2225. boolean old_dknown = FALSE; 2226. boolean more_than_one = potion->quan > 1L; 2227. 2228. oldbuf[0] = '\0'; 2229. if (potion->dknown) { 2230. old_dknown = TRUE; 2231. Sprintf(oldbuf, "%s ", hcolor(OBJ_DESCR(objects[potion->otyp]))); 2232. } 2233. /* with multiple merged potions, split off one and 2234. just clear it */ 2235. if (potion->quan > 1L) { 2236. singlepotion = splitobj(potion, 1L); 2237. } else 2238. singlepotion = potion; 2239. 2240. costly_alteration(singlepotion, COST_NUTRLZ); 2241. singlepotion->otyp = mixture; 2242. singlepotion->blessed = 0; 2243. if (mixture == POT_WATER) 2244. singlepotion->cursed = singlepotion->odiluted = 0; 2245. else 2246. singlepotion->cursed = obj->cursed; /* odiluted left as-is */ 2247. singlepotion->bknown = FALSE; 2248. if (Blind) { 2249. singlepotion->dknown = FALSE; 2250. } else { 2251. singlepotion->dknown = !Hallucination; 2252. *newbuf = '\0'; 2253. if (mixture == POT_WATER && singlepotion->dknown) 2254. Sprintf(newbuf, "clears"); 2255. else if (!Blind) 2256. Sprintf(newbuf, "turns %s", 2257. hcolor(OBJ_DESCR(objects[mixture]))); 2258. if (*newbuf) 2259. pline_The("%spotion%s %s.", oldbuf, 2260. more_than_one ? " that you dipped into" : "", 2261. newbuf); 2262. else 2263. pline("Something happens."); 2264. 2265. if (old_dknown 2266. && !objects[old_otyp].oc_name_known 2267. && !objects[old_otyp].oc_uname) { 2268. struct obj fakeobj; 2269. 2270. fakeobj = zeroobj; 2271. fakeobj.dknown = 1; 2272. fakeobj.otyp = old_otyp; 2273. fakeobj.oclass = POTION_CLASS; 2274. docall(&fakeobj); 2275. } 2276. } 2277. obj_extract_self(singlepotion); 2278. singlepotion = hold_another_object(singlepotion, 2279. "You juggle and drop %s!", 2280. doname(singlepotion), 2281. (const char *) 0); 2282. nhUse(singlepotion); 2283. update_inventory(); 2284. return 1; 2285. } 2286. 2287. pline("Interesting..."); 2288. return 1; 2289. 2290. poof: 2291. if (potion->dknown 2292. && !objects[potion->otyp].oc_name_known 2293. && !objects[potion->otyp].oc_uname) 2294. docall(potion); 2295. useup(potion); 2296. return 1; 2297. } 2298. 2299. /* *monp grants a wish and then leaves the game */ 2300. void 2301. mongrantswish(monp) 2302. struct monst **monp; 2303. { 2304. struct monst *mon = *monp; 2305. int mx = mon->mx, my = mon->my, glyph = glyph_at(mx, my); 2306. 2307. /* remove the monster first in case wish proves to be fatal 2308. (blasted by artifact), to keep it out of resulting bones file */ 2309. mongone(mon); 2310. *monp = 0; /* inform caller that monster is gone */ 2311. /* hide that removal from player--map is visible during wish prompt */ 2312. tmp_at(DISP_ALWAYS, glyph); 2313. tmp_at(mx, my); 2314. /* grant the wish */ 2315. makewish(); 2316. /* clean up */ 2317. tmp_at(DISP_END, 0); 2318. } 2319. 2320. void 2321. djinni_from_bottle(obj) 2322. struct obj *obj; 2323. { 2324. struct monst *mtmp; 2325. int chance; 2326. 2327. if (!(mtmp = makemon(&mons[PM_DJINNI], u.ux, u.uy, NO_MM_FLAGS))) { 2328. pline("It turns out to be empty."); 2329. return; 2330. } 2331. 2332. if (!Blind) { 2333. pline("In a cloud of smoke, %s emerges!", a_monnam(mtmp)); 2334. pline("%s speaks.", Monnam(mtmp)); 2335. } else { 2336. You("smell acrid fumes."); 2337. pline("%s speaks.", Something); 2338. } 2339. 2340. chance = rn2(5); 2341. if (obj->blessed) 2342. chance = (chance == 4) ? rnd(4) : 0; 2343. else if (obj->cursed) 2344. chance = (chance == 0) ? rn2(4) : 4; 2345. /* 0,1,2,3,4: b=80%,5,5,5,5; nc=20%,20,20,20,20; c=5%,5,5,5,80 */ 2346. 2347. switch (chance) { 2348. case 0: 2349. verbalize("I am in your debt. I will grant one wish!"); 2350. /* give a wish and discard the monster (mtmp set to null) */ 2351. mongrantswish(&mtmp); 2352. break; 2353. case 1: 2354. verbalize("Thank you for freeing me!"); 2355. (void) tamedog(mtmp, (struct obj *) 0); 2356. break; 2357. case 2: 2358. verbalize("You freed me!"); 2359. mtmp->mpeaceful = TRUE; 2360. set_malign(mtmp); 2361. break; 2362. case 3: 2363. verbalize("It is about time!"); 2364. if (canspotmon(mtmp)) 2365. pline("%s vanishes.", Monnam(mtmp)); 2366. mongone(mtmp); 2367. break; 2368. default: 2369. verbalize("You disturbed me, fool!"); 2370. mtmp->mpeaceful = FALSE; 2371. set_malign(mtmp); 2372. break; 2373. } 2374. } 2375. 2376. /* clone a gremlin or mold (2nd arg non-null implies heat as the trigger); 2377. hit points are cut in half (odd HP stays with original) */ 2378. struct monst * 2379. split_mon(mon, mtmp) 2380. struct monst *mon, /* monster being split */ 2381. *mtmp; /* optional attacker whose heat triggered it */ 2382. { 2383. struct monst *mtmp2; 2384. char reason[BUFSZ]; 2385. 2386. reason[0] = '\0'; 2387. if (mtmp) 2388. Sprintf(reason, " from %s heat", 2389. (mtmp == &youmonst) ? the_your[1] 2390. : (const char *) s_suffix(mon_nam(mtmp))); 2391. 2392. if (mon == &youmonst) { 2393. mtmp2 = cloneu(); 2394. if (mtmp2) { 2395. mtmp2->mhpmax = u.mhmax / 2; 2396. u.mhmax -= mtmp2->mhpmax; 2397. context.botl = 1; 2398. You("multiply%s!", reason); 2399. } 2400. } else { 2401. mtmp2 = clone_mon(mon, 0, 0); 2402. if (mtmp2) { 2403. mtmp2->mhpmax = mon->mhpmax / 2; 2404. mon->mhpmax -= mtmp2->mhpmax; 2405. if (canspotmon(mon)) 2406. pline("%s multiplies%s!", Monnam(mon), reason); 2407. } 2408. } 2409. return mtmp2; 2410. } 2411. 2412. /*potion.c*/