Source:NetHack 1.3d/fountain.c

From NetHackWiki
Revision as of 23:51, 3 March 2008 by Kernigh bot (talk | contribs) (NetHack 1.3d/fountain.c moved to Source:NetHack 1.3d/fountain.c: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

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

Screenshots and source code from Hack are used under the CWI license.

1.    /*	SCCS Id: @(#)fountain.c	1.3	87/07/14
2.    /* fountain.c  v 1.4.1 */
3.    
4.    /*
5.     * Revision 1.4.1  87/05/20  11:53:00  M. Stephenson
6.     * Implementation of KAA bug fixes.
7.     *
8.     * Revision 1.4    87/05/04  17:39:00  M. Stephenson
9.     * Integration of independent modifications
10.    *
11.    * Revision 1.3    87/03/02            Eric Backus
12.    * Rearranged, and dipfountain added
13.    * 
14.    * Revision 1.2    87/03/01  13:59:59  gil
15.    * patches
16.    * 
17.    * Revision 1.1    87/02/11  15:14:10  gil
18.    * Initial revision
19.    *
20.    */
21.   
22.   /* Code for drinking from fountains.   */
23.   /* Scott R. Turner, srt@ucla, 10/27/86 */
24.   
25.   #include "hack.h"
26.   
27.   extern struct monst *mkmon_at();
28.   extern char genocided[];
29.   
30.   #ifdef FOUNTAINS
31.   #define somex() ((rand()%(croom->hx-croom->lx+1))+croom->lx)
32.   #define somey() ((rand()%(croom->hy-croom->ly+1))+croom->ly)
33.   
34.   dowatersnakes() /* Fountain of snakes! */ {
35.   	register int num = rnd(6);
36.   	if (!index(genocided, 'S')) {
37.   
38.   		pline("Good Lord!  An endless stream of snakes pours forth!");
39.   		while(num-- > 0) (void) mkmon_at('S',u.ux,u.uy);
40.   	} else
41.   		pline("The fountain bubbles furiously for a moment, then calms.");
42.   }
43.   
44.   dowaterdemon() /* Water demon */ {
45.   register struct monst *mtmp;
46.   
47.   	pline("You have unleashed a water demon!");
48.   	mtmp = mkmon_at('&',u.ux,u.uy);
49.   	if (rnd(100)>97) {
50.   	    pline("He is grateful for his release and grants you a wish!");
51.   	    makewish();
52.   	    mondied(mtmp);
53.   	}
54.   }
55.   
56.   dowaternymph() /* Water Nymph */ {
57.   	register struct monst *mtmp;
58.   	if(!index(genocided, 'N')) {
59.   
60.   		pline("You have attracted a water nymph!");
61.   		mtmp = mkmon_at('N',u.ux,u.uy);
62.   		mtmp->msleep = 0;
63.   	} else
64.   		pline("A large bubble rises to the surface and pops.");
65.   }
66.   
67.   #include	"mkroom.h"
68.   
69.   dogushforth() /* Gushing forth in this room */ {
70.   register int num = rnd(10);
71.   register xchar mx,my;
72.   register int tryct = 0;
73.   register int uroom = inroom(u.ux, u.uy);
74.   register struct mkroom *croom = &rooms[uroom];
75.   register int madepool = 0;
76.   
77.   	if(croom->hx < 0 || has_upstairs(croom) ||
78.   	   has_dnstairs(croom))  {
79.   		pline("Your thirst is quenched.");
80.   		return;
81.   	}
82.   	while(num--) {
83.   	    do {
84.   		if(++tryct > 200)  {
85.   		    if(madepool)
86.   			pline("Water gushes forth from the overflowing fountain!");
87.   		    else
88.   			pline("Your thirst is quenched.");
89.   		    return;
90.   		}
91.   		mx = somex();
92.   		my = somey();
93.   	    } while(nexttodoor(mx,my) || !((mx+my)%2) ||
94.   		    (mx == u.ux && my == u.uy) ||
95.   		    (IS_POOL(levl[mx][my].typ)));
96.   		       
97.   	    /* Put a pool at mx, my */
98.   		     
99.   	    levl[mx][my].typ = POOL;
100.  	    atl(mx,my,POOL_SYM);
101.  	    madepool = 1;
102.  	}
103.  
104.  	pline("Water gushes forth from the overflowing fountain!");
105.  }
106.  
107.  dofindgem() /* Find a gem in the sparkling waters. */ {
108.  
109.  	if (!Blind) pline("You spot a gem in the sparkling waters!");
110.  	mkobj_at('*',u.ux,u.uy);
111.  }
112.  
113.  dryup(){
114.  	if (!rn2(5) && (levl[u.ux][u.uy].typ == FOUNTAIN)) {
115.  		pline("The fountain dries up!");
116.  		levl[u.ux][u.uy].typ = ROOM;
117.  		if(Invis) newsym(u.ux, u.uy);
118.  	}
119.  }
120.  
121.  drinkfountain(){
122.  
123.         /* What happens when you drink from a fountain? */
124.  
125.         register int fate = rnd(30);
126.  
127.         if (fate < 10) {
128.  	  pline("The cool draught refreshes you.");
129.  	  lesshungry(rnd(10));
130.         } 
131.         else
132.  	  switch (fate) {
133.  
134.  	       case 20: /* Foul water */
135.  
136.  			pline("The water is foul!  You gag and vomit.");
137.  			morehungry(rnd(20)+10);
138.  			if(Sick)  {
139.  				Sick = 0;
140.  				pline("What a relief!");
141.  			}
142.  			break;
143.  
144.  	       case 21: /* Poisonous */
145.  
146.  			pline("The water is contaminated!");
147.  			if (Poison_resistance) {
148.  			   pline("Perhaps it is run off from the nearby orange farm.");
149.  			   losehp(rnd(4),"contaminated water");
150.  			   break;
151.  			}
152.  			losestr(rn1(4,3));
153.  			losehp(rnd(10),"contaminated water");
154.  			break;
155.  	
156.  	       case 22: /* Fountain of snakes! */
157.  			dowatersnakes();
158.  			break;
159.  
160.  	       case 23: /* Water demon */
161.  			dowaterdemon();
162.  			break;
163.  
164.  	       case 24: /* Curse an item... */ {
165.  			register struct obj *obj;
166.  
167.  			pline("This water's no good!");
168.  			morehungry(rnd(20)+10);
169.  			for(obj = invent; obj ; obj = obj->nobj)
170.  				if (!rn2(5))	obj->cursed++;
171.  			break;
172.  			}
173.  			 
174.  	       case 25: /* See invisible */
175.  
176.  			pline("You see an image of someone stalking you.");
177.  			pline("But it disappears.");
178.  			HSee_invisible |= INTRINSIC;
179.  			break;
180.  
181.  	       case 26: /* See Monsters */{
182.  
183.  		       register struct monst *mtmp;
184.  			if(!fmon) {
185.  			       pline("You feel oddly disturbed.");
186.  			} else {
187.  				cls();
188.  				for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
189.  					if(mtmp->mx > 0)
190.  						at(mtmp->mx,mtmp->my,mtmp->data->mlet);
191.  				prme();
192.  				pline("You sense the presence of monsters.");
193.  				more();
194.  				docrt();
195.  			}
196.  			break; }
197.  
198.  	       case 27: /* Find a gem in the sparkling waters. */
199.  			dofindgem();
200.  			break;
201.  
202.  	       case 28: /* Water Nymph */
203.  		       dowaternymph();
204.  		       break;
205.  
206.  	       case 29: /* Scare */ {
207.  			register struct monst *mtmp;
208.  
209.  			pline("This water gives you bad breath!");
210.  			for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 
211.  				mtmp->mflee = 1;
212.  			}
213.  			break;
214.  
215.  	       case 30: /* Gushing forth in this room */
216.  			dogushforth();
217.  			break;
218.  	  }
219.  
220.  	dryup();
221.  
222.  }
223.  
224.  dipfountain(obj)
225.  register struct obj *obj;
226.  {
227.  	register int fate = rnd(30);
228.  
229.  	if(fate<10)
230.  		if(!obj->rustfree &&
231.  			/* Only swords affected here */
232.  			(obj->otyp == LONG_SWORD ||
233.  			obj->otyp == KATANA ||
234.  			obj->otyp == BROAD_SWORD ||
235.  			obj->otyp == SHORT_SWORD ||
236.  			obj->otyp == TWO_HANDED_SWORD)) {
237.  			if(obj->spe > -6) {
238.  				pline("Your weapon rusts somewhat.");
239.  				obj->spe--;
240.  			} else pline("Your weapon looks quite rusted.");
241.  		} else pline("Well, it looks wet now.");
242.  	else if(fate<14)
243.  		if(obj->otyp == LONG_SWORD && !strcmp(ONAME(obj),"Excalibur")){
244.  			/* The lady of the lake acts! - Eric Backus */
245.  			/* Be *REAL* nice to him */
246.  	pline("A murky hand from the depths reaches up to bless the sword.");
247.  	pline("As the hand retreats, the fountain disappears!");
248.  			if(obj->spe < 5) obj->spe = 5;
249.  			obj->cursed = 0;
250.  			obj->rustfree = 1;
251.  			levl[u.ux][u.uy].typ = ROOM;
252.  			if(Invis) newsym(u.ux, u.uy);
253.  			return(0);
254.  		} else pline ("Well, it looks wet now.");
255.  	else
256.  		switch (fate) {
257.  			case 16: /* Curse the item */
258.  				pline("Well, it looks wet now.");
259.  				obj->cursed = 1;
260.  				break;
261.  			case 17:
262.  			case 18:
263.  			case 19:
264.  			case 20: /* Uncurse the item */
265.  				if(obj->cursed) {
266.  				    pline("The water glows for a moment.");
267.  				    obj->cursed = 0;
268.  				} else {
269.  				    pline("A feeling of loss comes over you.");
270.  				}
271.  				break;
272.  			case 21: /* Water Demon */
273.  				dowaterdemon();
274.  				break;
275.  			case 22: /* Water Nymph */
276.  				dowaternymph();
277.  				break;
278.  			case 23: /* An Endless Stream Of Snakes */
279.  				dowatersnakes();
280.  				break;
281.  			case 24: /* Find a gem */
282.  				dofindgem();
283.  				break;
284.  			case 25: /* Water gushes forth */
285.  				dogushforth();
286.  				break;
287.  			case 26: /* Strange feeling */
288.  				pline("A strange tingling runs up your arm.");
289.  				break;
290.  			case 27: /* Strange feeling */
291.  				pline("You feel a sudden chill.");
292.  				break;
293.  			case 28: /* Strange feeling */
294.  			pline("An urge to take a bath nearly overwhelms you.");
295.  				break;
296.  			case 29: /* You see coins */
297.  		pline("Far below you, you see coins glistening in the water.");
298.  				break;
299.  			default:
300.  				break;
301.  		}
302.  	dryup();
303.  	return(0);
304.  }
305.  #endif