Source:NetHack 3.0.0/fountain.c

Below is the full text to fountain.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/fountain.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)fountain.c	3.0	88/12/22 2.   /* Code for drinking from fountains. */ 3.    /* Scott R. Turner, srt@ucla, 10/27/86 */ 4.   /* NetHack may be freely redistributed. See license for details. */ 5.     6.    #include "hack.h"  7. 8.   #ifdef FOUNTAINS 9.    10.   static 11.  void 12.  dowatersnakes /* Fountain of snakes! */ { 13.   	register int num = rnd(6); 14.  	if (!(mons[PM_WATER_MOCCASIN].geno & G_GENOD)) {	/* && chgd to &*/ 15.   16.   		pline("Good Lord!  An endless stream of snakes pours forth!"); 17.  		while(num-- > 0) (void) makemon(&mons[PM_WATER_MOCCASIN],u.ux,u.uy); 18.  	} else 19.  		pline("The fountain bubbles furiously for a moment, then calms."); 20.  }  21.    22.   static 23.  void 24.  dowaterdemon /* Water demon */ { 25.  register struct monst *mtmp; 26.   27.   	if((mtmp = makemon(&mons[PM_WATER_DEMON],u.ux,u.uy))) { 28.  	    You("have unleashed %s!", defmonnam(mtmp)); 29.   30.   	/* Give those on low levels a (slightly) better chance of survival */ 31.  	    if ( rnd(100) > (80 + dlevel)) { 32.  		pline("Grateful for his release, he grants you a wish!"); 33.  		makewish; 34.  		mongone(mtmp); 35.  	    }  36.   	}  37.   }  38.    39.   static 40.  void 41.  dowaternymph /* Water Nymph */ { 42.  	register struct monst *mtmp; 43.  	if((mtmp = makemon(&mons[PM_WATER_NYMPH],u.ux,u.uy))) { 44.   45.   		You("have attracted %s!", defmonnam(mtmp)); 46.  		mtmp->msleep = 0; 47.  	} else 48.  		pline("A large bubble rises to the surface and pops."); 49.  }  50.    51.    52.   static 53.  void 54.  dogushforth(drinking) /* Gushing forth in this room */ 55.  int drinking; 56.  {  57.   register int num = rnd(10); 58.  register xchar mx,my; 59.  register int tryct = 0; 60.  register int uroom = inroom(u.ux, u.uy); 61.  register struct mkroom *croom = &rooms[uroom]; 62.  register int madepool = 0; 63.   64.   	if(croom->hx < 0 || has_upstairs(croom) ||  65.   	   has_dnstairs(croom))  { 66.  		if (drinking) Your("thirst is quenched."); 67.  		else pline("Water sprays all over you."); 68.  		return; 69.  	}  70.   	while(num--) { 71.  	    do { 72.  		if(++tryct > 200)  { 73.  		    if(madepool) 74.  			pline("Water gushes forth from the overflowing fountain!"); 75.  		    else if (drinking) Your("thirst is quenched."); 76.  		else pline("Water sprays all over you."); 77.  		    return; 78.  		}  79.   		mx = somex(croom); 80.  		my = somey(croom); 81.  	    } while(nexttodoor(mx,my) || !((mx+my)%2) ||  82.   		    (mx == u.ux && my == u.uy) ||  83.   		    (IS_POOL(levl[mx][my].typ))); 84.  		        85.   	    /* Put a pool at mx, my */ 86.  		      87.   	    levl[mx][my].typ = POOL; 88.  	    levl[mx][my].doormask = 0; 89.  	    if(!Blind) atl(mx,my,(char) POOL_SYM); 90.  	    madepool = 1; 91.  	}  92.    93.   	pline("Water gushes forth from the overflowing fountain!"); 94.  }  95.    96.   static 97.  void 98.  dofindgem /* Find a gem in the sparkling waters. */ { 99.    100.  	if (!Blind) You("spot a gem in the sparkling waters!"); 101. 	(void) mkobj_at(GEM_SYM,u.ux,u.uy); 102. 	levl[u.ux][u.uy].doormask = T_LOOTED; 103. }  104.   105.  void 106. dryup{ 107. 	if (!rn2(3) && (levl[u.ux][u.uy].typ == FOUNTAIN)) { 108. 		pline("The fountain dries up!"); 109. 		levl[u.ux][u.uy].typ = ROOM; 110. 		levl[u.ux][u.uy].doormask = 0; 111. 		if(Invisible) newsym(u.ux, u.uy); 112. 		fountsound--; 113. 	}  114.  }  115.   116.  void 117. drinkfountain { 118.  119.  	/* What happens when you drink from a fountain? */ 120.  	register int fate = rnd(30); 121.  122.  	if(Levitation)	{ 123. 		You("are floating high above the fountain."); 124. 		return; 125. 	}  126.  	else if (fate < 10) { 127. 		pline("The cool draught refreshes you."); 128. 		lesshungry(rnd(10)); 129. 	} else { 130. 	    switch (fate) { 131.  132.  		case 19: /* Self-knowledge */ 133.  134.  			You("feel self-knowledgable..."); 135. 			more; 136. 			enlightenment; 137. 			pline("The feeling subsides."); 138. 			break; 139.  140.  		case 20: /* Foul water */ 141.  142.  			pline("The water is foul!  You gag and vomit."); 143. 			morehungry(rnd(20)+10); 144. 			vomit; 145. 			break; 146.  147.  		case 21: /* Poisonous */ 148.  149.  			pline("The water is contaminated!"); 150. 			if (Poison_resistance) { 151. 	   pline("Perhaps it is runoff from the nearby %s farm.", pl_fruit); 152. 			   losehp(rnd(4),"unrefrigerated sip of juice"); 153. 			   break; 154. 			}  155.  			losestr(rn1(4,3)); 156. 			losehp(rnd(10),"contaminated water"); 157. 			break; 158. 	  159.  		case 22: /* Fountain of snakes! */ 160.   161.  			dowatersnakes; 162. 			break; 163.  164.  		case 23: /* Water demon */ 165. 			dowaterdemon; 166. 			break; 167.  168.  		case 24: /* Curse an item... */ { 169.  			register struct obj *obj; 170.  171.  			pline("This water's no good!"); 172. 			morehungry(rnd(20)+10); 173. 			for(obj = invent; obj ; obj = obj->nobj) 174. 				if (!rn2(5))	curse(obj); 175. 			break; 176. 			}  177.  			  178.  		case 25: /* See invisible */ 179.  180.  			You("see an image of someone stalking you."); 181. 			pline("But it disappears."); 182. 			HSee_invisible |= INTRINSIC; 183. 			break; 184.  185.  		case 26: /* See Monsters */ 186.  187.  			(void) monster_detect((struct obj *)0); 188. 			break; 189.  190.  		case 27: /* Find a gem in the sparkling waters. */ 191.   192.  			if (levl[u.ux][u.uy].doormask == 0) { 193. 				dofindgem; 194. 				break; 195. 			}  196.   197.  		case 28: /* Water Nymph */ 198.  199.  			dowaternymph; 200. 			break; 201.  202.  		case 29: /* Scare */ { 203. 			register struct monst *mtmp; 204.  205.  			pline("This water gives you bad breath!"); 206. 			for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 207. 				mtmp->mflee = 1; 208. 			}  209.  			break; 210.  211.  		case 30: /* Gushing forth in this room */ 212.  213.  			dogushforth(TRUE); 214. 			break; 215.  216.  		default: 217.  218.  			pline("This tepid water is tasteless."); 219. 			break; 220. 	    }  221.  	}  222.  	dryup; 223. }  224.   225.  void 226. dipfountain(obj) 227. register struct obj *obj; 228. {  229.  	register int fate = rnd(30); 230.  231.  	if(Levitation)	You("are floating high above the fountain."); 232. 	else if(fate<10) 233. 		if(!obj->rustfree && is_sword(obj)) { 234. 			if(obj->spe > -6) { 235. 				Your("sword rusts somewhat."); 236. 				obj->spe--; 237. 			} else Your("sword looks quite rusted."); 238. 		} else pline("Well, it looks wet now."); 239. 	else if(fate<14) 240. 		if(obj->otyp == LONG_SWORD  241.  #ifndef NAMED_ITEMS  242.  		   && !strcmp(ONAME(obj), "Excalibur")  243.  #endif  244.  		   && u.ulevel >= 5  245.  		) { 246. 			/* The lady of the lake acts! - Eric Backus */ 247. 			/* Be *REAL* nice to him */ 248. 	pline("A murky hand from the depths reaches up to bless the sword."); 249. 	pline("As the hand retreats, the fountain disappears!"); 250.  251.  #ifndef NAMED_ITEMS 252. 			if(obj->spe < 5) obj->spe = 5; 253. #else 254. 			/* otherwise +rnd(10) / +5 "Super"sword */ 255. 			obj = oname(obj, "Excalibur", 1); 256. #endif 257. 			bless(obj); 258. 			obj->rustfree = 1; 259. 			levl[u.ux][u.uy].typ = ROOM; 260. 			if(Invisible) newsym(u.ux, u.uy); 261. 			fountsound--; 262. 			return; 263. 		} else pline ("Well, it looks wet now."); 264. 	else { 265. 	    switch (fate) { 266. 		case 16: /* Curse the item */ 267. 			pline("Well, it looks wet now."); 268. 			curse(obj); 269. 			break; 270. 		case 17: 271. 		case 18: 272. 		case 19: 273. 		case 20: /* Uncurse the item */ 274. 			if(obj->cursed) { 275. 			    if (!Blind) 276. 				pline("The water glows for a moment."); 277. 			    obj->cursed = 0; 278. 			} else { 279. 			    pline("A feeling of loss comes over you."); 280. 			}  281.  			break; 282. 		case 21: /* Water Demon */ 283. 			dowaterdemon; 284. 			break; 285. 		case 22: /* Water Nymph */ 286. 			dowaternymph; 287. 			break; 288. 		case 23: /* An Endless Stream Of Snakes */ 289. 			dowatersnakes; 290. 			break; 291. 		case 24: /* Find a gem */ 292. 			dofindgem; 293. 			break; 294. 		case 25: /* Water gushes forth */ 295. 			dogushforth(FALSE); 296. 			break; 297. 		case 26: /* Strange feeling */ 298. 			pline("A strange tingling runs up your %s.",  299.  							body_part(ARM)); 300. 			break; 301. 		case 27: /* Strange feeling */ 302. 			You("feel a sudden chill."); 303. 			break; 304. 		case 28: /* Strange feeling */ 305. 			pline("An urge to take a bath overwhelms you."); 306. 			if (u.ugold > 10) { 307. 			     	u.ugold -= somegold/10; 308. 			  You("lost some of your gold in the fountain!"); 309. 			  levl[u.ux][u.uy].doormask = 0; 310. 	 		}  311.  			break; 312. 		case 29: /* You see coins */ 313.  314.  		/* We make fountains have more coins the closer you are to the 315. 		 * surface. After all, there will have been more people going 316. 		 * by. Just like a shopping mall! Chris Woodbury */ 317.  318.  			mkgold((long)(rnd((MAXLEVEL-dlevel)*2)+5),u.ux,u.uy); 319. 		pline("Far below you, you see coins glistening in the water."); 320. 			break; 321. 		default: 322. 			break; 323. 	    }  324.  	}  325.  	dryup; 326. 	return; 327. }  328.  #endif 329.  330.  #ifdef SINKS 331. void 332. drinksink 333. {  334.  	if (Levitation) { 335. 		You("are floating high above the sink."); 336. 		return; 337. 	}  338.  	switch(rn2(20)) { 339. 		static struct obj *otmp; 340. 		case 0: You("take a sip of very cold water."); 341. 			break; 342. 		case 1: You("take a sip of very warm water."); 343. 			break; 344. 		case 2: You("take a sip of scalding hot water."); 345. 			if (Fire_resistance) 346. 				pline("It seems quite tasty."); 347. 			else losehp(rnd(6), "sip of boiling water"); 348. 			break; 349. 		case 3: if (mons[PM_SEWER_RAT].geno & G_GENOD) 350. 				pline("The sink seems quite dirty."); 351. 			else { 352. 				static struct monst *mtmp; 353.  354.  				mtmp = makemon(&mons[PM_SEWER_RAT], u.ux, u.uy); 355. 				pline("Eek!  There's %s in the sink!",  356.  					Blind ? "something squirmy" :  357.  					defmonnam(mtmp)); 358. 			}  359.  			break; 360. 		case 4: do { 361. 				otmp = mkobj(POTION_SYM,FALSE); 362. 			} while(otmp->otyp == POT_WATER); 363. 			otmp->cursed = otmp->blessed = 0; 364. 			if (Blind) 365. 				pline("The sink emits some odd liquid."); 366. 			else 367. 				pline("The sink emits a stream of %s water.",  368.  				    Hallucination ? hcolor :  369.  				    objects[otmp->otyp].oc_descr); 370. 			otmp->dknown = !(Blind || Hallucination); 371. 			otmp->quan++; /* Avoid panic upon useup */ 372. 			otmp->corpsenm = 1; /* kludge for docall */ 373. 			(void) dopotion(otmp); 374. 			obfree(otmp, (struct obj *)0); 375. 			break; 376. 		case 5: if (levl[u.ux][u.uy].doormask == 0) { 377. 			    You("find a ring in the sink!"); 378. 			    (void) mkobj_at(RING_SYM, u.ux, u.uy); 379. 			    levl[u.ux][u.uy].doormask = T_LOOTED; 380. 			} else pline("Some dirty water backs up in the drain."); 381. 			break; 382. 		case 6: pline("The pipes break!  Water spurts out!"); 383. 			sinksound--; 384. 			levl[u.ux][u.uy].doormask = 0; 385. #ifdef FOUNTAINS 386. 			levl[u.ux][u.uy].typ = FOUNTAIN; 387. 			fountsound++; 388. #else 389. 			levl[u.ux][u.uy].typ = ROOM; 390. #endif 391. 			if (Invisible) newsym(u.ux,u.uy); 392. 			break; 393. 		case 7: pline("The water moves as though of its own will!"); 394. 			if (!makemon(&mons[PM_WATER_ELEMENTAL], u.ux, u.uy)) 395. 				pline("But it quiets down."); 396. 			break; 397. 		case 8: pline("Yuk, this water tastes awful."); 398. 			more_experienced(1,0); 399. 			newexplevel; 400. 			break; 401. 		case 9: pline("Gaggg... this tastes like sewage!  You vomit."); 402. 			morehungry(rnd(30-ACURR(A_CON))+10); 403. 			vomit; 404. 			break; 405. #ifdef POLYSELF 406. 		case 10: pline("This water contains toxic wastes!"); 407. 			You("undergo a freakish metamorphosis!"); 408. 			polyself; 409. 			break; 410. #endif 411. 		/* more odd messages --JJB */ 412. 		case 11: You("hear clanking from the pipes...."); 413. 			break; 414. 		case 12: You("hear snatches of song from among the sewers..."); 415. 			break; 416. 		case 19: if (Hallucination) { 417. 				pline("A murky hand reaches up out of the drain... --oops--"); 418. 				break; 419. 			}  420.  		default: You("take a sip of %s water.",  421.  			rn2(3) ? (rn2(2) ? "cold" : "warm") : "hot"); 422. 	}  423.  }  424.  #endif /* SINKS /**/