xref: /dragonfly/games/larn/moreobj.c (revision 984263bc)
1 /* moreobj.c 		Larn is copyrighted 1986 by Noah Morgan.
2  * $FreeBSD: src/games/larn/moreobj.c,v 1.4 1999/11/16 02:57:22 billf Exp $
3  *
4  *	Routines in this file:
5  *
6  *	oaltar()
7  *	othrone()
8  *	ochest()
9  *	ofountain()
10  */
11 #include "header.h"
12 
13 static void ohear();
14 
15 /*
16  *	******
17  *	OALTAR
18  *	******
19  *
20  *	subroutine to process an altar object
21  */
22 oaltar()
23 	{
24 	unsigned long k;
25 
26 	lprcat("\nDo you (p) pray  (d) desecrate"); iopts();
27 	while (1)
28 	  {
29 	  while (1) switch(getchar())
30 		{
31 		case 'p':	lprcat(" pray\nDo you (m) give money or (j) just pray? ");
32 					while (1) switch(getchar())
33 					  {
34 					  case 'j':	if (rnd(100)<75)
35 									lprcat("\nnothing happens");
36 								else if (rnd(13)<4) ohear();
37 								else if (rnd(43) == 10)
38 									{
39 									if (c[WEAR]) lprcat("\nYou feel your armor vibrate for a moment");
40 									enchantarmor(); return;
41 									}
42 								else if (rnd(43) == 10)
43 									{
44 									if (c[WIELD]) lprcat("\nYou feel your weapon vibrate for a moment");
45 									enchweapon(); return;
46 									}
47 								else createmonster(makemonst(level+1));
48 								return;
49 
50 					  case 'm':	lprcat("\n\n");  cursor(1,24);  cltoeoln();
51 					  			cursor(1,23);  cltoeoln();
52 								lprcat("how much do you donate? ");
53 								k = readnum((long)c[GOLD]);
54 								if (c[GOLD]<k)
55 									{
56 									lprcat("\nYou don't have that much!");
57 									return;
58 									}
59 								c[GOLD] -= k;
60 								if (k < c[GOLD]/10 || k<rnd(50))
61 									{ createmonster(makemonst(level+1)); c[AGGRAVATE] += 200; }
62 								else if (rnd(101) > 50)	{ ohear(); return; }
63 								else if (rnd(43) == 5)
64 									{
65 									if (c[WEAR]) lprcat("\nYou feel your armor vibrate for a moment");
66 									enchantarmor(); return;
67 									}
68 								else if (rnd(43) == 8)
69 									{
70 									if (c[WIELD]) lprcat("\nYou feel your weapon vibrate for a moment");
71 									enchweapon(); return;
72 									}
73 								else	lprcat("\nThank You.");
74 								bottomline();	return;
75 
76 					  case '\33':	return;
77 					  };
78 
79 		case 'd': lprcat(" desecrate");
80 				  if (rnd(100)<60)
81 						{ createmonster(makemonst(level+2)+8); c[AGGRAVATE] += 2500; }
82 					else
83 					if (rnd(101)<30)
84 						{
85 						lprcat("\nThe altar crumbles into a pile of dust before your eyes");
86 						forget();	/*	remember to destroy the altar	*/
87 						}
88 					else
89 						lprcat("\nnothing happens");
90 					return;
91 
92 		case 'i':
93 		case '\33': ignore();
94 				  if (rnd(100)<30)	{ createmonster(makemonst(level+1)); c[AGGRAVATE] += rnd(450); }
95 					else	lprcat("\nnothing happens");
96 					return;
97 		};
98 	  }
99 	}
100 
101 /*
102 	function to cast a +3 protection on the player
103  */
104 static void
105 ohear()
106 	{
107 	lprcat("\nYou have been heard!");
108 	if (c[ALTPRO]==0) c[MOREDEFENSES]+=3;
109 	c[ALTPRO] += 500;	/* protection field */
110 	bottomline();
111 	}
112 
113 /*
114 	*******
115 	OTHRONE
116 	*******
117 
118 	subroutine to process a throne object
119  */
120 othrone(arg)
121 	int arg;
122 	{
123 	int i,k;
124 
125 	lprcat("\nDo you (p) pry off jewels, (s) sit down"); iopts();
126 	while (1)
127 	  {
128 	  while (1) switch(getchar())
129 		{
130 		case 'p':	lprcat(" pry off");  k=rnd(101);
131 					if (k<25)
132 						{
133 						for (i=0; i<rnd(4); i++) creategem(); /* gems pop off the throne */
134 						item[playerx][playery]=ODEADTHRONE;
135 						know[playerx][playery]=0;
136 						}
137 					else if (k<40 && arg==0)
138 						{
139 						createmonster(GNOMEKING);
140 						item[playerx][playery]=OTHRONE2;
141 						know[playerx][playery]=0;
142 						}
143 					else lprcat("\nnothing happens");
144 					return;
145 
146 		case 's': 	lprcat(" sit down");  k=rnd(101);
147 				  	if (k<30 && arg==0)
148 						{
149 						createmonster(GNOMEKING);
150 						item[playerx][playery]=OTHRONE2;
151 						know[playerx][playery]=0;
152 						}
153 				  	else if (k<35) { lprcat("\nZaaaappp!  You've been teleported!\n"); beep(); oteleport(0); }
154 					else lprcat("\nnothing happens");
155 					return;
156 
157 		case 'i':
158 		case '\33': ignore(); return;
159 		};
160 	  }
161 	}
162 
163 odeadthrone()
164 	{
165 	int k;
166 
167 	lprcat("\nDo you (s) sit down"); iopts();
168 	while (1)
169 	  {
170 	  while (1) switch(getchar())
171 		{
172 		case 's': 	lprcat(" sit down");  k=rnd(101);
173 				  	if (k<35) { lprcat("\nZaaaappp!  You've been teleported!\n"); beep(); oteleport(0); }
174 					else lprcat("\nnothing happens");
175 					return;
176 
177 		case 'i':
178 		case '\33': ignore(); return;
179 		};
180 	  }
181 	}
182 
183 /*
184 	******
185 	OCHEST
186 	******
187 
188 	subroutine to process a throne object
189  */
190 ochest()
191 	{
192 	int i,k;
193 	lprcat("\nDo you (t) take it, (o) try to open it"); iopts();
194 	while (1)
195 	  {
196 	  while (1) switch(getchar())
197 		{
198 		case 'o':	lprcat(" open it");  k=rnd(101);
199 					if (k<40)
200 						{
201 						lprcat("\nThe chest explodes as you open it"); beep();
202 						i = rnd(10);  lastnum=281;  /* in case he dies */
203 						lprintf("\nYou suffer %d hit points damage!",(long)i);
204 						checkloss(i);
205 						switch(rnd(10))	/* see if he gets a curse */
206 							{
207 							case 1:	c[ITCHING]+= rnd(1000)+100;
208 									lprcat("\nYou feel an irritation spread over your skin!");
209 									beep();
210 									break;
211 
212 							case 2:	c[CLUMSINESS]+= rnd(1600)+200;
213 									lprcat("\nYou begin to lose hand to eye coordination!");
214 									beep();
215 									break;
216 
217 							case 3:	c[HALFDAM]+= rnd(1600)+200;
218 									beep();
219 									lprcat("\nA sickness engulfs you!");	break;
220 							};
221 						item[playerx][playery]=know[playerx][playery]=0;
222 						if (rnd(100)<69) creategem(); /* gems from the chest */
223 						dropgold(rnd(110*iarg[playerx][playery]+200));
224 						for (i=0; i<rnd(4); i++) something(iarg[playerx][playery]+2);
225 						}
226 					else lprcat("\nnothing happens");
227 					return;
228 
229 		case 't':	lprcat(" take");
230 					if (take(OCHEST,iarg[playerx][playery])==0)
231 						item[playerx][playery]=know[playerx][playery]=0;
232 					return;
233 
234 		case 'i':
235 		case '\33': ignore(); return;
236 		};
237 	  }
238 	}
239 
240 /*
241 	*********
242 	OFOUNTAIN
243 	*********
244  */
245 
246 ofountain()
247 	{
248 	int x;
249 	cursors();
250 	lprcat("\nDo you (d) drink, (w) wash yourself"); iopts();
251 	while (1) switch(getchar())
252 		{
253 		case 'd':	lprcat("drink");
254 					if (rnd(1501)<2)
255 						{
256 						lprcat("\nOops!  You seem to have caught the dreadful sleep!");
257 						beep(); lflush();  sleep(3);  died(280); return;
258 						}
259 					x = rnd(100);
260 					if (x<7)
261 						{
262 						c[HALFDAM] += 200+rnd(200);
263 						lprcat("\nYou feel a sickness coming on");
264 						}
265 					else if (x<13) quaffpotion(23); /* see invisible */
266 					else if (x < 45)
267 						lprcat("\nnothing seems to have happened");
268 					else if (rnd(3) != 2)
269 						fntchange(1);	/*	change char levels upward	*/
270 					else
271 						fntchange(-1);	/*	change char levels downward	*/
272 					if (rnd(12)<3)
273 						{
274 						lprcat("\nThe fountains bubbling slowly quiets");
275 						item[playerx][playery]=ODEADFOUNTAIN; /* dead fountain */
276 						know[playerx][playery]=0;
277 						}
278 					return;
279 
280 		case '\33':
281 		case 'i':	ignore();  return;
282 
283 		case 'w':	lprcat("wash yourself");
284 					if (rnd(100) < 11)
285 						{
286 						x=rnd((level<<2)+2);
287 						lprintf("\nOh no!  The water was foul!  You suffer %d hit points!",(long)x);
288 						lastnum=273; losehp(x); bottomline();  cursors();
289 						}
290 					else
291 					if (rnd(100) < 29)
292 						lprcat("\nYou got the dirt off!");
293 					else
294 					if (rnd(100) < 31)
295 						lprcat("\nThis water seems to be hard water!  The dirt didn't come off!");
296 					else
297 					if (rnd(100) < 34)
298 						createmonster(WATERLORD); /*	make water lord		*/
299 					else
300 					lprcat("\nnothing seems to have happened");
301 					return;
302 		}
303 	}
304 
305 /*
306 	***
307 	FCH
308 	***
309 
310 	subroutine to process an up/down of a character attribute for ofountain
311  */
312 static void
313 fch(how,x)
314 	int how;
315 	long *x;
316 	{
317 	if (how < 0)	 { lprcat(" went down by one!");	--(*x); }
318 		else		 { lprcat(" went up by one!");	(*x)++; }
319 	bottomline();
320 	}
321 
322 /*
323 	a subroutine to raise or lower character levels
324 	if x > 0 they are raised   if x < 0 they are lowered
325  */
326 fntchange(how)
327 	int how;
328 	{
329 	long j;
330 	lprc('\n');
331 	switch(rnd(9))
332 		{
333 		case 1:	lprcat("Your strength");		fch(how,&c[0]);		break;
334 		case 2:	lprcat("Your intelligence");	fch(how,&c[1]);		break;
335 		case 3:	lprcat("Your wisdom");			fch(how,&c[2]);		break;
336 		case 4:	lprcat("Your constitution");	fch(how,&c[3]);		break;
337 		case 5:	lprcat("Your dexterity");		fch(how,&c[4]);		break;
338 		case 6:	lprcat("Your charm");			fch(how,&c[5]);		break;
339 		case 7:	j=rnd(level+1);
340 				if (how < 0)
341 					{ lprintf("You lose %d hit point",(long)j);  if (j>1) lprcat("s!"); else lprc('!'); losemhp((int)j); }
342 				else
343 					{ lprintf("You gain %d hit point",(long)j);  if (j>1) lprcat("s!"); else lprc('!'); raisemhp((int)j); }
344 				bottomline();		break;
345 
346 		case 8:	j=rnd(level+1);
347 				if (how > 0)
348 					{
349 					lprintf("You just gained %d spell",(long)j);  raisemspells((int)j);
350 					if (j>1) lprcat("s!"); else lprc('!');
351 					}
352 				else
353 					{
354 					lprintf("You just lost %d spell",(long)j);	losemspells((int)j);
355 					if (j>1) lprcat("s!"); else lprc('!');
356 					}
357 				bottomline();		break;
358 
359 		case 9:	j = 5*rnd((level+1)*(level+1));
360 				if (how < 0)
361 					{
362 					lprintf("You just lost %d experience point",(long)j);
363 					if (j>1) lprcat("s!"); else lprc('!'); loseexperience((long)j);
364 					}
365 				else
366 					{
367 					lprintf("You just gained %d experience point",(long)j);
368 					if (j>1) lprcat("s!"); else lprc('!'); raiseexperience((long)j);
369 					}
370 				break;
371 		}
372 	cursors();
373 	}
374