1 /* SCCS Id: @(#)fountain.c 3.4 2003/03/23 */
2 /* Copyright Scott R. Turner, srt@ucla, 10/27/86 */
3 /* NetHack may be freely redistributed. See license for details. */
5 /* Code for drinking from fountains. */
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);
19 You("are floating high above the %s.", what);
23 dowatersnakes() /* Fountain of snakes! */
25 register int num = rn1(5,2);
28 if (!(mvitals[PM_WATER_MOCCASIN].mvflags & G_GONE)) {
30 pline("An endless stream of %s pours forth!",
31 Hallucination ? makeplural(rndmonnam()) : "snakes");
33 You_hear("%s hissing!", something);
35 if((mtmp = makemon(&mons[PM_WATER_MOCCASIN],
36 u.ux, u.uy, NO_MM_FLAGS)) && t_at(mtmp->mx, mtmp->my))
39 pline_The("fountain bubbles furiously for a moment, then calms.");
44 dowaterdemon() /* Water demon */
46 register struct monst *mtmp;
48 if(!(mvitals[PM_WATER_DEMON].mvflags & G_GONE)) {
49 if((mtmp = makemon(&mons[PM_WATER_DEMON],u.ux,u.uy, NO_MM_FLAGS))) {
51 You("unleash %s!", a_monnam(mtmp));
53 You_feel("the presence of evil.");
55 /* Give those on low levels a (slightly) better chance of survival */
56 if (rnd(100) > (80 + level_difficulty())) {
57 pline("Grateful for %s release, %s grants you a wish!",
58 mhis(mtmp), mhe(mtmp));
61 } else if (t_at(mtmp->mx, mtmp->my))
65 pline_The("fountain bubbles furiously for a moment, then calms.");
69 dowaternymph() /* Water Nymph */
71 register struct monst *mtmp;
73 if(!(mvitals[PM_WATER_NYMPH].mvflags & G_GONE) &&
74 (mtmp = makemon(&mons[PM_WATER_NYMPH],u.ux,u.uy, NO_MM_FLAGS))) {
76 You("attract %s!", a_monnam(mtmp));
78 You_hear("a seductive voice.");
80 if (t_at(mtmp->mx, mtmp->my))
84 pline("A large bubble rises to the surface and pops.");
86 You_hear("a loud pop.");
90 dogushforth(drinking) /* Gushing forth along LOS from (u.ux, u.uy) */
95 do_clear_area(u.ux, u.uy, 7, gush, (genericptr_t)&madepool);
98 Your("thirst is quenched.");
100 pline("Water sprays all over you.");
107 genericptr_t poolcnt;
109 register struct monst *mtmp;
110 register struct trap *ttmp;
112 if (((x+y)%2) || (x == u.ux && y == u.uy) ||
113 (rn2(1 + distmin(u.ux, u.uy, x, y))) ||
114 (levl[x][y].typ != ROOM) ||
115 (sobj_at(BOULDER, x, y)) || nexttodoor(x, y))
118 if ((ttmp = t_at(x, y)) != 0 && !delfloortrap(ttmp))
121 if (!((*(int *)poolcnt)++))
122 pline("Water gushes forth from the overflowing fountain!");
124 /* Put a pool at x, y */
125 levl[x][y].typ = POOL;
128 water_damage(level.objects[x][y], FALSE, TRUE);
130 if ((mtmp = m_at(x, y)) != 0)
131 (void) minliquid(mtmp);
137 dofindgem() /* Find a gem in the sparkling waters. */
139 if (!Blind) You("spot a gem in the sparkling waters!");
140 else You_feel("a gem here!");
141 (void) mksobj_at(rnd_class(DILITHIUM_CRYSTAL, LUCKSTONE-1),
142 u.ux, u.uy, FALSE, FALSE);
143 SET_FOUNTAIN_LOOTED(u.ux,u.uy);
145 exercise(A_WIS, TRUE); /* a discovery! */
153 if (IS_FOUNTAIN(levl[x][y].typ) &&
154 (!rn2(3) || FOUNTAIN_IS_WARNED(x,y))) {
155 if(isyou && in_town(x, y) && !FOUNTAIN_IS_WARNED(x,y)) {
157 SET_FOUNTAIN_WARNED(x,y);
158 /* Warn about future fountain use. */
159 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
160 if (DEADMONSTER(mtmp)) continue;
161 if ((mtmp->data == &mons[PM_WATCHMAN] ||
162 mtmp->data == &mons[PM_WATCH_CAPTAIN]) &&
163 couldsee(mtmp->mx, mtmp->my) &&
165 pline("%s yells:", Amonnam(mtmp));
166 verbalize("Hey, stop using that fountain!");
170 /* You can see or hear this effect */
171 if(!mtmp) pline_The("flow reduces to a trickle.");
175 if (isyou && wizard) {
176 if (yn("Dry up fountain?") == 'n')
180 /* replace the fountain with ordinary floor */
181 levl[x][y].typ = ROOM;
182 levl[x][y].looted = 0;
183 levl[x][y].blessedftn = 0;
184 if (cansee(x,y)) pline_The("fountain dries up!");
185 /* The location is seen if the hero/monster is invisible */
186 /* or felt if the hero is blind. */
188 level.flags.nfountains--;
189 if(isyou && in_town(x, y))
190 (void) angry_guards(FALSE);
197 /* What happens when you drink from a fountain? */
198 register boolean mgkftn = (levl[u.ux][u.uy].blessedftn == 1);
199 register int fate = rnd(30);
202 floating_above("fountain");
206 if (mgkftn && u.uluck >= 0 && fate >= 10) {
207 int i, ii, littleluck = (u.uluck < 4);
209 pline("Wow! This makes you feel great!");
210 /* blessed restore ability */
211 for (ii = 0; ii < A_MAX; ii++)
212 if (ABASE(ii) < AMAX(ii)) {
213 ABASE(ii) = AMAX(ii);
216 /* gain ability, blessed if "natural" luck is high */
217 i = rn2(A_MAX); /* start at a random attribute */
218 for (ii = 0; ii < A_MAX; ii++) {
219 if (adjattrib(i, 1, littleluck ? -1 : 0) && littleluck)
221 if (++i >= A_MAX) i = 0;
223 display_nhwindow(WIN_MESSAGE, FALSE);
224 pline("A wisp of vapor escapes the fountain...");
225 exercise(A_WIS, TRUE);
226 levl[u.ux][u.uy].blessedftn = 0;
231 pline_The("cool draught refreshes you.");
232 u.uhunger += rnd(10); /* don't choke on water */
238 case 19: /* Self-knowledge */
240 You_feel("self-knowledgeable...");
241 display_nhwindow(WIN_MESSAGE, FALSE);
243 exercise(A_WIS, TRUE);
244 pline_The("feeling subsides.");
247 case 20: /* Foul water */
249 pline_The("water is foul! You gag and vomit.");
250 morehungry(rn1(20, 11));
254 case 21: /* Poisonous */
256 pline_The("water is contaminated!");
257 if (Poison_resistance) {
259 "Perhaps it is runoff from the nearby %s farm.",
261 losehp(rnd(4),"unrefrigerated sip of juice",
266 losehp(rnd(10),"contaminated water", KILLED_BY);
267 exercise(A_CON, FALSE);
270 case 22: /* Fountain of snakes! */
275 case 23: /* Water demon */
279 case 24: /* Curse an item */ {
280 register struct obj *obj;
282 pline("This water's no good!");
283 morehungry(rn1(20, 11));
284 exercise(A_CON, FALSE);
285 for(obj = invent; obj ; obj = obj->nobj)
286 if (!rn2(5)) curse(obj);
290 case 25: /* See invisible */
294 You("feel transparent.");
296 You("feel very self-conscious.");
297 pline("Then it passes.");
300 You("see an image of someone stalking you.");
301 pline("But it disappears.");
303 HSee_invisible |= FROMOUTSIDE;
305 exercise(A_WIS, TRUE);
308 case 26: /* See Monsters */
310 (void) monster_detect((struct obj *)0, 0);
311 exercise(A_WIS, TRUE);
314 case 27: /* Find a gem in the sparkling waters. */
316 if (!FOUNTAIN_IS_LOOTED(u.ux,u.uy)) {
321 case 28: /* Water Nymph */
326 case 29: /* Scare */ {
327 register struct monst *mtmp;
329 pline("This water gives you bad breath!");
330 for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
331 if(!DEADMONSTER(mtmp))
332 monflee(mtmp, 0, FALSE, FALSE);
336 case 30: /* Gushing forth in this room */
343 pline("This tepid water is tasteless.");
347 dryup(u.ux, u.uy, TRUE);
352 register struct obj *obj;
355 floating_above("fountain");
359 /* Don't grant Excalibur when there's more than one object. */
360 /* (quantity could be > 1 if merged daggers got polymorphed) */
361 if (obj->otyp == LONG_SWORD && obj->quan == 1L
362 && u.ulevel >= 5 && !rn2(6)
364 && !exist_artifact(LONG_SWORD, artiname(ART_EXCALIBUR))) {
366 if (u.ualign.type != A_LAWFUL) {
367 /* Ha! Trying to cheat her. */
368 pline("A freezing mist rises from the water and envelopes the sword.");
369 pline_The("fountain disappears!");
371 if (obj->spe > -6 && !rn2(3)) obj->spe--;
372 obj->oerodeproof = FALSE;
373 exercise(A_WIS, FALSE);
375 /* The lady of the lake acts! - Eric Backus */
377 pline("From the murky depths, a hand reaches up to bless the sword.");
378 pline("As the hand retreats, the fountain disappears!");
379 obj = oname(obj, artiname(ART_EXCALIBUR));
380 discover_artifact(ART_EXCALIBUR);
382 obj->oeroded = obj->oeroded2 = 0;
383 obj->oerodeproof = TRUE;
384 exercise(A_WIS, TRUE);
387 levl[u.ux][u.uy].typ = ROOM;
388 levl[u.ux][u.uy].looted = 0;
390 level.flags.nfountains--;
391 if(in_town(u.ux, u.uy))
392 (void) angry_guards(FALSE);
394 } else if (get_wet(obj) && !rn2(2))
397 /* Acid and water don't mix */
398 if (obj->otyp == POT_ACID) {
404 case 16: /* Curse the item */
410 case 20: /* Uncurse the item */
413 pline_The("water glows for a moment.");
416 pline("A feeling of loss comes over you.");
419 case 21: /* Water Demon */
422 case 22: /* Water Nymph */
425 case 23: /* an Endless Stream of Snakes */
428 case 24: /* Find a gem */
429 if (!FOUNTAIN_IS_LOOTED(u.ux,u.uy)) {
433 case 25: /* Water gushes forth */
436 case 26: /* Strange feeling */
437 pline("A strange tingling runs up your %s.",
440 case 27: /* Strange feeling */
441 You_feel("a sudden chill.");
443 case 28: /* Strange feeling */
444 pline("An urge to take a bath overwhelms you.");
447 u.ugold -= somegold() / 10;
448 You("lost some of your gold in the fountain!");
449 CLEAR_FOUNTAIN_LOOTED(u.ux,u.uy);
450 exercise(A_WIS, FALSE);
454 long money = money_cnt(invent);
457 /* Amount to loose. Might get rounded up as fountains don't pay change... */
458 money = somegold(money) / 10;
459 for (otmp = invent; otmp && money > 0; otmp = otmp->nobj) if (otmp->oclass == COIN_CLASS) {
460 int denomination = objects[otmp->otyp].oc_cost;
461 long coin_loss = (money + denomination - 1) / denomination;
462 coin_loss = min(coin_loss, otmp->quan);
463 otmp->quan -= coin_loss;
464 money -= coin_loss * denomination;
465 if (!otmp->quan) delobj(otmp);
467 You("lost some of your money in the fountain!");
468 CLEAR_FOUNTAIN_LOOTED(u.ux,u.uy);
469 exercise(A_WIS, FALSE);
474 case 29: /* You see coins */
476 /* We make fountains have more coins the closer you are to the
477 * surface. After all, there will have been more people going
478 * by. Just like a shopping mall! Chris Woodbury */
480 if (FOUNTAIN_IS_LOOTED(u.ux,u.uy)) break;
481 SET_FOUNTAIN_LOOTED(u.ux,u.uy);
483 (rnd((dunlevs_in_dungeon(&u.uz)-dunlev(&u.uz)+1)*2)+5),
486 pline("Far below you, you see coins glistening in the water.");
487 exercise(A_WIS, TRUE);
492 dryup(u.ux, u.uy, TRUE);
500 if(cansee(x,y) || (x == u.ux && y == u.uy))
501 pline_The("pipes break! Water spurts out!");
502 level.flags.nsinks--;
503 levl[x][y].doormask = 0;
504 levl[x][y].typ = FOUNTAIN;
505 level.flags.nfountains++;
516 floating_above("sink");
520 case 0: You("take a sip of very cold water.");
522 case 1: You("take a sip of very warm water.");
524 case 2: You("take a sip of scalding hot water.");
526 pline("It seems quite tasty.");
527 else losehp(rnd(6), "sipping boiling water", KILLED_BY);
529 case 3: if (mvitals[PM_SEWER_RAT].mvflags & G_GONE)
530 pline_The("sink seems quite dirty.");
532 mtmp = makemon(&mons[PM_SEWER_RAT],
533 u.ux, u.uy, NO_MM_FLAGS);
534 if (mtmp) pline("Eek! There's %s in the sink!",
535 (Blind || !canspotmon(mtmp)) ?
536 "something squirmy" :
541 otmp = mkobj(POTION_CLASS,FALSE);
542 if (otmp->otyp == POT_WATER) {
543 obfree(otmp, (struct obj *)0);
544 otmp = (struct obj *) 0;
547 otmp->cursed = otmp->blessed = 0;
548 pline("Some %s liquid flows from the faucet.",
550 hcolor(OBJ_DESCR(objects[otmp->otyp])));
551 otmp->dknown = !(Blind || Hallucination);
552 otmp->quan++; /* Avoid panic upon useup() */
553 otmp->fromsink = 1; /* kludge for docall() */
554 (void) dopotion(otmp);
555 obfree(otmp, (struct obj *)0);
557 case 5: if (!(levl[u.ux][u.uy].looted & S_LRING)) {
558 You("find a ring in the sink!");
559 (void) mkobj_at(RING_CLASS, u.ux, u.uy, TRUE);
560 levl[u.ux][u.uy].looted |= S_LRING;
561 exercise(A_WIS, TRUE);
563 } else pline("Some dirty water backs up in the drain.");
565 case 6: breaksink(u.ux,u.uy);
567 case 7: pline_The("water moves as though of its own will!");
568 if ((mvitals[PM_WATER_ELEMENTAL].mvflags & G_GONE)
569 || !makemon(&mons[PM_WATER_ELEMENTAL],
570 u.ux, u.uy, NO_MM_FLAGS))
571 pline("But it quiets down.");
573 case 8: pline("Yuk, this water tastes awful.");
574 more_experienced(1,0);
577 case 9: pline("Gaggg... this tastes like sewage! You vomit.");
578 morehungry(rn1(30-ACURR(A_CON), 11));
581 case 10: pline("This water contains toxic wastes!");
583 You("undergo a freakish metamorphosis!");
587 /* more odd messages --JJB */
588 case 11: You_hear("clanking from the pipes...");
590 case 12: You_hear("snatches of song from among the sewers...");
592 case 19: if (Hallucination) {
593 pline("From the murky drain, a hand reaches up... --oops--");
596 default: You("take a sip of %s water.",
597 rn2(3) ? (rn2(2) ? "cold" : "warm") : "hot");