Source:NetHack 3.6.2/src/fountain.c
Jump to navigation
Jump to search
Below is the full text to fountain.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/fountain.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 fountain.c $NHDT-Date: 1544442711 2018/12/10 11:51:51 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.60 $ */ 2. /* Copyright Scott R. Turner, srt@ucla, 10/27/86 */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. /* Code for drinking from fountains. */ 6. 7. #include "hack.h" 8. 9. STATIC_DCL void NDECL(dowatersnakes); 10. STATIC_DCL void NDECL(dowaterdemon); 11. STATIC_DCL void NDECL(dowaternymph); 12. STATIC_PTR void FDECL(gush, (int, int, genericptr_t)); 13. STATIC_DCL void NDECL(dofindgem); 14. 15. /* used when trying to dip in or drink from fountain or sink or pool while 16. levitating above it, or when trying to move downwards in that state */ 17. void 18. floating_above(what) 19. const char *what; 20. { 21. const char *umsg = "are floating high above the %s."; 22. 23. if (u.utrap && (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA)) { 24. /* when stuck in floor (not possible at fountain or sink location, 25. so must be attempting to move down), override the usual message */ 26. umsg = "are trapped in the %s."; 27. what = surface(u.ux, u.uy); /* probably redundant */ 28. } 29. You(umsg, what); 30. } 31. 32. /* Fountain of snakes! */ 33. STATIC_OVL void 34. dowatersnakes() 35. { 36. register int num = rn1(5, 2); 37. struct monst *mtmp; 38. 39. if (!(mvitals[PM_WATER_MOCCASIN].mvflags & G_GONE)) { 40. if (!Blind) 41. pline("An endless stream of %s pours forth!", 42. Hallucination ? makeplural(rndmonnam(NULL)) : "snakes"); 43. else 44. You_hear("%s hissing!", something); 45. while (num-- > 0) 46. if ((mtmp = makemon(&mons[PM_WATER_MOCCASIN], u.ux, u.uy, 47. NO_MM_FLAGS)) != 0 48. && t_at(mtmp->mx, mtmp->my)) 49. (void) mintrap(mtmp); 50. } else 51. pline_The("fountain bubbles furiously for a moment, then calms."); 52. } 53. 54. /* Water demon */ 55. STATIC_OVL void 56. dowaterdemon() 57. { 58. struct monst *mtmp; 59. 60. if (!(mvitals[PM_WATER_DEMON].mvflags & G_GONE)) { 61. if ((mtmp = makemon(&mons[PM_WATER_DEMON], u.ux, u.uy, 62. NO_MM_FLAGS)) != 0) { 63. if (!Blind) 64. You("unleash %s!", a_monnam(mtmp)); 65. else 66. You_feel("the presence of evil."); 67. 68. /* Give those on low levels a (slightly) better chance of survival 69. */ 70. if (rnd(100) > (80 + level_difficulty())) { 71. pline("Grateful for %s release, %s grants you a wish!", 72. mhis(mtmp), mhe(mtmp)); 73. /* give a wish and discard the monster (mtmp set to null) */ 74. mongrantswish(&mtmp); 75. } else if (t_at(mtmp->mx, mtmp->my)) 76. (void) mintrap(mtmp); 77. } 78. } else 79. pline_The("fountain bubbles furiously for a moment, then calms."); 80. } 81. 82. /* Water Nymph */ 83. STATIC_OVL void 84. dowaternymph() 85. { 86. register struct monst *mtmp; 87. 88. if (!(mvitals[PM_WATER_NYMPH].mvflags & G_GONE) 89. && (mtmp = makemon(&mons[PM_WATER_NYMPH], u.ux, u.uy, 90. NO_MM_FLAGS)) != 0) { 91. if (!Blind) 92. You("attract %s!", a_monnam(mtmp)); 93. else 94. You_hear("a seductive voice."); 95. mtmp->msleeping = 0; 96. if (t_at(mtmp->mx, mtmp->my)) 97. (void) mintrap(mtmp); 98. } else if (!Blind) 99. pline("A large bubble rises to the surface and pops."); 100. else 101. You_hear("a loud pop."); 102. } 103. 104. /* Gushing forth along LOS from (u.ux, u.uy) */ 105. void 106. dogushforth(drinking) 107. int drinking; 108. { 109. int madepool = 0; 110. 111. do_clear_area(u.ux, u.uy, 7, gush, (genericptr_t) &madepool); 112. if (!madepool) { 113. if (drinking) 114. Your("thirst is quenched."); 115. else 116. pline("Water sprays all over you."); 117. } 118. } 119. 120. STATIC_PTR void 121. gush(x, y, poolcnt) 122. int x, y; 123. genericptr_t poolcnt; 124. { 125. register struct monst *mtmp; 126. register struct trap *ttmp; 127. 128. if (((x + y) % 2) || (x == u.ux && y == u.uy) 129. || (rn2(1 + distmin(u.ux, u.uy, x, y))) || (levl[x][y].typ != ROOM) 130. || (sobj_at(BOULDER, x, y)) || nexttodoor(x, y)) 131. return; 132. 133. if ((ttmp = t_at(x, y)) != 0 && !delfloortrap(ttmp)) 134. return; 135. 136. if (!((*(int *) poolcnt)++)) 137. pline("Water gushes forth from the overflowing fountain!"); 138. 139. /* Put a pool at x, y */ 140. levl[x][y].typ = POOL, levl[x][y].flags = 0; 141. /* No kelp! */ 142. del_engr_at(x, y); 143. water_damage_chain(level.objects[x][y], TRUE); 144. 145. if ((mtmp = m_at(x, y)) != 0) 146. (void) minliquid(mtmp); 147. else 148. newsym(x, y); 149. } 150. 151. /* Find a gem in the sparkling waters. */ 152. STATIC_OVL void 153. dofindgem() 154. { 155. if (!Blind) 156. You("spot a gem in the sparkling waters!"); 157. else 158. You_feel("a gem here!"); 159. (void) mksobj_at(rnd_class(DILITHIUM_CRYSTAL, LUCKSTONE - 1), u.ux, u.uy, 160. FALSE, FALSE); 161. SET_FOUNTAIN_LOOTED(u.ux, u.uy); 162. newsym(u.ux, u.uy); 163. exercise(A_WIS, TRUE); /* a discovery! */ 164. } 165. 166. void 167. dryup(x, y, isyou) 168. xchar x, y; 169. boolean isyou; 170. { 171. if (IS_FOUNTAIN(levl[x][y].typ) 172. && (!rn2(3) || FOUNTAIN_IS_WARNED(x, y))) { 173. if (isyou && in_town(x, y) && !FOUNTAIN_IS_WARNED(x, y)) { 174. struct monst *mtmp; 175. 176. SET_FOUNTAIN_WARNED(x, y); 177. /* Warn about future fountain use. */ 178. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 179. if (DEADMONSTER(mtmp)) 180. continue; 181. if (is_watch(mtmp->data) && couldsee(mtmp->mx, mtmp->my) 182. && mtmp->mpeaceful) { 183. if (!Deaf) { 184. pline("%s yells:", Amonnam(mtmp)); 185. verbalize("Hey, stop using that fountain!"); 186. } else { 187. pline("%s earnestly %s %s %s!", 188. Amonnam(mtmp), 189. nolimbs(mtmp->data) ? "shakes" : "waves", 190. mhis(mtmp), 191. nolimbs(mtmp->data) 192. ? mbodypart(mtmp, HEAD) 193. : makeplural(mbodypart(mtmp, ARM))); 194. } 195. break; 196. } 197. } 198. /* You can see or hear this effect */ 199. if (!mtmp) 200. pline_The("flow reduces to a trickle."); 201. return; 202. } 203. if (isyou && wizard) { 204. if (yn("Dry up fountain?") == 'n') 205. return; 206. } 207. /* replace the fountain with ordinary floor */ 208. levl[x][y].typ = ROOM, levl[x][y].flags = 0; 209. levl[x][y].blessedftn = 0; 210. if (cansee(x, y)) 211. pline_The("fountain dries up!"); 212. /* The location is seen if the hero/monster is invisible 213. or felt if the hero is blind. */ 214. newsym(x, y); 215. level.flags.nfountains--; 216. if (isyou && in_town(x, y)) 217. (void) angry_guards(FALSE); 218. } 219. } 220. 221. void 222. drinkfountain() 223. { 224. /* What happens when you drink from a fountain? */ 225. register boolean mgkftn = (levl[u.ux][u.uy].blessedftn == 1); 226. register int fate = rnd(30); 227. 228. if (Levitation) { 229. floating_above("fountain"); 230. return; 231. } 232. 233. if (mgkftn && u.uluck >= 0 && fate >= 10) { 234. int i, ii, littleluck = (u.uluck < 4); 235. 236. pline("Wow! This makes you feel great!"); 237. /* blessed restore ability */ 238. for (ii = 0; ii < A_MAX; ii++) 239. if (ABASE(ii) < AMAX(ii)) { 240. ABASE(ii) = AMAX(ii); 241. context.botl = 1; 242. } 243. /* gain ability, blessed if "natural" luck is high */ 244. i = rn2(A_MAX); /* start at a random attribute */ 245. for (ii = 0; ii < A_MAX; ii++) { 246. if (adjattrib(i, 1, littleluck ? -1 : 0) && littleluck) 247. break; 248. if (++i >= A_MAX) 249. i = 0; 250. } 251. display_nhwindow(WIN_MESSAGE, FALSE); 252. pline("A wisp of vapor escapes the fountain..."); 253. exercise(A_WIS, TRUE); 254. levl[u.ux][u.uy].blessedftn = 0; 255. return; 256. } 257. 258. if (fate < 10) { 259. pline_The("cool draught refreshes you."); 260. u.uhunger += rnd(10); /* don't choke on water */ 261. newuhs(FALSE); 262. if (mgkftn) 263. return; 264. } else { 265. switch (fate) { 266. case 19: /* Self-knowledge */ 267. You_feel("self-knowledgeable..."); 268. display_nhwindow(WIN_MESSAGE, FALSE); 269. enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); 270. exercise(A_WIS, TRUE); 271. pline_The("feeling subsides."); 272. break; 273. case 20: /* Foul water */ 274. pline_The("water is foul! You gag and vomit."); 275. morehungry(rn1(20, 11)); 276. vomit(); 277. break; 278. case 21: /* Poisonous */ 279. pline_The("water is contaminated!"); 280. if (Poison_resistance) { 281. pline("Perhaps it is runoff from the nearby %s farm.", 282. fruitname(FALSE)); 283. losehp(rnd(4), "unrefrigerated sip of juice", KILLED_BY_AN); 284. break; 285. } 286. losestr(rn1(4, 3)); 287. losehp(rnd(10), "contaminated water", KILLED_BY); 288. exercise(A_CON, FALSE); 289. break; 290. case 22: /* Fountain of snakes! */ 291. dowatersnakes(); 292. break; 293. case 23: /* Water demon */ 294. dowaterdemon(); 295. break; 296. case 24: /* Curse an item */ { 297. register struct obj *obj; 298. 299. pline("This water's no good!"); 300. morehungry(rn1(20, 11)); 301. exercise(A_CON, FALSE); 302. for (obj = invent; obj; obj = obj->nobj) 303. if (!rn2(5)) 304. curse(obj); 305. break; 306. } 307. case 25: /* See invisible */ 308. if (Blind) { 309. if (Invisible) { 310. You("feel transparent."); 311. } else { 312. You("feel very self-conscious."); 313. pline("Then it passes."); 314. } 315. } else { 316. You_see("an image of someone stalking you."); 317. pline("But it disappears."); 318. } 319. HSee_invisible |= FROMOUTSIDE; 320. newsym(u.ux, u.uy); 321. exercise(A_WIS, TRUE); 322. break; 323. case 26: /* See Monsters */ 324. (void) monster_detect((struct obj *) 0, 0); 325. exercise(A_WIS, TRUE); 326. break; 327. case 27: /* Find a gem in the sparkling waters. */ 328. if (!FOUNTAIN_IS_LOOTED(u.ux, u.uy)) { 329. dofindgem(); 330. break; 331. } 332. /*FALLTHRU*/ 333. case 28: /* Water Nymph */ 334. dowaternymph(); 335. break; 336. case 29: /* Scare */ 337. { 338. register struct monst *mtmp; 339. 340. pline("This %s gives you bad breath!", 341. hliquid("water")); 342. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 343. if (DEADMONSTER(mtmp)) 344. continue; 345. monflee(mtmp, 0, FALSE, FALSE); 346. } 347. break; 348. } 349. case 30: /* Gushing forth in this room */ 350. dogushforth(TRUE); 351. break; 352. default: 353. pline("This tepid %s is tasteless.", 354. hliquid("water")); 355. break; 356. } 357. } 358. dryup(u.ux, u.uy, TRUE); 359. } 360. 361. void 362. dipfountain(obj) 363. register struct obj *obj; 364. { 365. if (Levitation) { 366. floating_above("fountain"); 367. return; 368. } 369. 370. /* Don't grant Excalibur when there's more than one object. */ 371. /* (quantity could be > 1 if merged daggers got polymorphed) */ 372. if (obj->otyp == LONG_SWORD && obj->quan == 1L && u.ulevel >= 5 && !rn2(6) 373. && !obj->oartifact 374. && !exist_artifact(LONG_SWORD, artiname(ART_EXCALIBUR))) { 375. if (u.ualign.type != A_LAWFUL) { 376. /* Ha! Trying to cheat her. */ 377. pline("A freezing mist rises from the %s and envelopes the sword.", 378. hliquid("water")); 379. pline_The("fountain disappears!"); 380. curse(obj); 381. if (obj->spe > -6 && !rn2(3)) 382. obj->spe--; 383. obj->oerodeproof = FALSE; 384. exercise(A_WIS, FALSE); 385. } else { 386. /* The lady of the lake acts! - Eric Backus */ 387. /* Be *REAL* nice */ 388. pline( 389. "From the murky depths, a hand reaches up to bless the sword."); 390. pline("As the hand retreats, the fountain disappears!"); 391. obj = oname(obj, artiname(ART_EXCALIBUR)); 392. discover_artifact(ART_EXCALIBUR); 393. bless(obj); 394. obj->oeroded = obj->oeroded2 = 0; 395. obj->oerodeproof = TRUE; 396. exercise(A_WIS, TRUE); 397. } 398. update_inventory(); 399. levl[u.ux][u.uy].typ = ROOM, levl[u.ux][u.uy].flags = 0; 400. newsym(u.ux, u.uy); 401. level.flags.nfountains--; 402. if (in_town(u.ux, u.uy)) 403. (void) angry_guards(FALSE); 404. return; 405. } else { 406. int er = water_damage(obj, NULL, TRUE); 407. 408. if (obj->otyp == POT_ACID 409. && er != ER_DESTROYED) { /* Acid and water don't mix */ 410. useup(obj); 411. return; 412. } else if (er != ER_NOTHING && !rn2(2)) { /* no further effect */ 413. return; 414. } 415. } 416. 417. switch (rnd(30)) { 418. case 16: /* Curse the item */ 419. curse(obj); 420. break; 421. case 17: 422. case 18: 423. case 19: 424. case 20: /* Uncurse the item */ 425. if (obj->cursed) { 426. if (!Blind) 427. pline_The("%s glows for a moment.", hliquid("water")); 428. uncurse(obj); 429. } else { 430. pline("A feeling of loss comes over you."); 431. } 432. break; 433. case 21: /* Water Demon */ 434. dowaterdemon(); 435. break; 436. case 22: /* Water Nymph */ 437. dowaternymph(); 438. break; 439. case 23: /* an Endless Stream of Snakes */ 440. dowatersnakes(); 441. break; 442. case 24: /* Find a gem */ 443. if (!FOUNTAIN_IS_LOOTED(u.ux, u.uy)) { 444. dofindgem(); 445. break; 446. } 447. /*FALLTHRU*/ 448. case 25: /* Water gushes forth */ 449. dogushforth(FALSE); 450. break; 451. case 26: /* Strange feeling */ 452. pline("A strange tingling runs up your %s.", body_part(ARM)); 453. break; 454. case 27: /* Strange feeling */ 455. You_feel("a sudden chill."); 456. break; 457. case 28: /* Strange feeling */ 458. pline("An urge to take a bath overwhelms you."); 459. { 460. long money = money_cnt(invent); 461. struct obj *otmp; 462. if (money > 10) { 463. /* Amount to lose. Might get rounded up as fountains don't 464. * pay change... */ 465. money = somegold(money) / 10; 466. for (otmp = invent; otmp && money > 0; otmp = otmp->nobj) 467. if (otmp->oclass == COIN_CLASS) { 468. int denomination = objects[otmp->otyp].oc_cost; 469. long coin_loss = 470. (money + denomination - 1) / denomination; 471. coin_loss = min(coin_loss, otmp->quan); 472. otmp->quan -= coin_loss; 473. money -= coin_loss * denomination; 474. if (!otmp->quan) 475. delobj(otmp); 476. } 477. You("lost some of your money in the fountain!"); 478. CLEAR_FOUNTAIN_LOOTED(u.ux, u.uy); 479. exercise(A_WIS, FALSE); 480. } 481. } 482. break; 483. case 29: /* You see coins */ 484. /* We make fountains have more coins the closer you are to the 485. * surface. After all, there will have been more people going 486. * by. Just like a shopping mall! Chris Woodbury */ 487. 488. if (FOUNTAIN_IS_LOOTED(u.ux, u.uy)) 489. break; 490. SET_FOUNTAIN_LOOTED(u.ux, u.uy); 491. (void) mkgold((long) (rnd((dunlevs_in_dungeon(&u.uz) - dunlev(&u.uz) 492. + 1) * 2) + 5), 493. u.ux, u.uy); 494. if (!Blind) 495. pline("Far below you, you see coins glistening in the %s.", 496. hliquid("water")); 497. exercise(A_WIS, TRUE); 498. newsym(u.ux, u.uy); 499. break; 500. } 501. update_inventory(); 502. dryup(u.ux, u.uy, TRUE); 503. } 504. 505. void 506. breaksink(x, y) 507. int x, y; 508. { 509. if (cansee(x, y) || (x == u.ux && y == u.uy)) 510. pline_The("pipes break! Water spurts out!"); 511. level.flags.nsinks--; 512. levl[x][y].typ = FOUNTAIN, levl[x][y].looted = 0; 513. levl[x][y].blessedftn = 0; 514. SET_FOUNTAIN_LOOTED(x, y); 515. level.flags.nfountains++; 516. newsym(x, y); 517. } 518. 519. void 520. drinksink() 521. { 522. struct obj *otmp; 523. struct monst *mtmp; 524. 525. if (Levitation) { 526. floating_above("sink"); 527. return; 528. } 529. switch (rn2(20)) { 530. case 0: 531. You("take a sip of very cold %s.", hliquid("water")); 532. break; 533. case 1: 534. You("take a sip of very warm %s.", hliquid("water")); 535. break; 536. case 2: 537. You("take a sip of scalding hot %s.", hliquid("water")); 538. if (Fire_resistance) 539. pline("It seems quite tasty."); 540. else 541. losehp(rnd(6), "sipping boiling water", KILLED_BY); 542. /* boiling water burns considered fire damage */ 543. break; 544. case 3: 545. if (mvitals[PM_SEWER_RAT].mvflags & G_GONE) 546. pline_The("sink seems quite dirty."); 547. else { 548. mtmp = makemon(&mons[PM_SEWER_RAT], u.ux, u.uy, NO_MM_FLAGS); 549. if (mtmp) 550. pline("Eek! There's %s in the sink!", 551. (Blind || !canspotmon(mtmp)) ? "something squirmy" 552. : a_monnam(mtmp)); 553. } 554. break; 555. case 4: 556. do { 557. otmp = mkobj(POTION_CLASS, FALSE); 558. if (otmp->otyp == POT_WATER) { 559. obfree(otmp, (struct obj *) 0); 560. otmp = (struct obj *) 0; 561. } 562. } while (!otmp); 563. otmp->cursed = otmp->blessed = 0; 564. pline("Some %s liquid flows from the faucet.", 565. Blind ? "odd" : hcolor(OBJ_DESCR(objects[otmp->otyp]))); 566. otmp->dknown = !(Blind || Hallucination); 567. otmp->quan++; /* Avoid panic upon useup() */ 568. otmp->fromsink = 1; /* kludge for docall() */ 569. (void) dopotion(otmp); 570. obfree(otmp, (struct obj *) 0); 571. break; 572. case 5: 573. if (!(levl[u.ux][u.uy].looted & S_LRING)) { 574. You("find a ring in the sink!"); 575. (void) mkobj_at(RING_CLASS, u.ux, u.uy, TRUE); 576. levl[u.ux][u.uy].looted |= S_LRING; 577. exercise(A_WIS, TRUE); 578. newsym(u.ux, u.uy); 579. } else 580. pline("Some dirty %s backs up in the drain.", hliquid("water")); 581. break; 582. case 6: 583. breaksink(u.ux, u.uy); 584. break; 585. case 7: 586. pline_The("%s moves as though of its own will!", hliquid("water")); 587. if ((mvitals[PM_WATER_ELEMENTAL].mvflags & G_GONE) 588. || !makemon(&mons[PM_WATER_ELEMENTAL], u.ux, u.uy, NO_MM_FLAGS)) 589. pline("But it quiets down."); 590. break; 591. case 8: 592. pline("Yuk, this %s tastes awful.", hliquid("water")); 593. more_experienced(1, 0); 594. newexplevel(); 595. break; 596. case 9: 597. pline("Gaggg... this tastes like sewage! You vomit."); 598. morehungry(rn1(30 - ACURR(A_CON), 11)); 599. vomit(); 600. break; 601. case 10: 602. pline("This %s contains toxic wastes!", hliquid("water")); 603. if (!Unchanging) { 604. You("undergo a freakish metamorphosis!"); 605. polyself(0); 606. } 607. break; 608. /* more odd messages --JJB */ 609. case 11: 610. You_hear("clanking from the pipes..."); 611. break; 612. case 12: 613. You_hear("snatches of song from among the sewers..."); 614. break; 615. case 19: 616. if (Hallucination) { 617. pline("From the murky drain, a hand reaches up... --oops--"); 618. break; 619. } 620. /*FALLTHRU*/ 621. default: 622. You("take a sip of %s %s.", 623. rn2(3) ? (rn2(2) ? "cold" : "warm") : "hot", 624. hliquid("water")); 625. } 626. } 627. 628. /*fountain.c*/