xref: /original-bsd/games/larn/object.c (revision b0ceb3f2)
1 /*	object.c		Larn is copyrighted 1986 by Noah Morgan. */
2 #include "header.h"
3 
4 /*
5 	***************
6 	LOOK_FOR_OBJECT
7 	***************
8 
9 	subroutine to look for an object and give the player his options
10 	if an object was found.
11  */
12 lookforobject()
13 {
14 register int i,j;
15 if (c[TIMESTOP])  return;	/* can't find objects is time is stopped	*/
16 i=item[playerx][playery];	if (i==0) return;
17 showcell(playerx,playery);  cursors();  yrepcount=0;
18 switch(i)
19 	{
20 	case OGOLDPILE:	case OMAXGOLD:
21 	case OKGOLD:	case ODGOLD:	lprcat("\n\nYou have found some gold!");	ogold(i);	break;
22 
23 	case OPOTION:	lprcat("\n\nYou have found a magic potion");
24 				i = iarg[playerx][playery];
25 				if (potionname[i][0]) lprintf(" of %s",&potionname[i][1]);  opotion(i);  break;
26 
27 	case OSCROLL:	lprcat("\n\nYou have found a magic scroll");
28 				i = iarg[playerx][playery];
29 				if (scrollname[i][0])	lprintf(" of %s",&scrollname[i][1]);
30 				oscroll(i);  break;
31 
32 	case OALTAR:	if (nearbymonst()) return;
33 					lprcat("\n\nThere is a Holy Altar here!"); oaltar(); break;
34 
35 	case OBOOK:	lprcat("\n\nYou have found a book."); obook(); break;
36 
37 	case OCOOKIE:	lprcat("\n\nYou have found a fortune cookie."); ocookie(); break;
38 
39 	case OTHRONE:	if (nearbymonst()) return;
40 					lprintf("\n\nThere is %s here!",objectname[i]); othrone(0); break;
41 
42 	case OTHRONE2:	if (nearbymonst()) return;
43 					lprintf("\n\nThere is %s here!",objectname[i]); othrone(1); break;
44 
45 	case ODEADTHRONE: lprintf("\n\nThere is %s here!",objectname[i]); odeadthrone(); break;
46 
47 	case OORB:		lprcat("\n\nYou have found the Orb!!!!!"); oorb(); break;
48 
49 	case OPIT:		lprcat("\n\nYou're standing at the top of a pit."); opit(); break;
50 
51 	case OSTAIRSUP:		lprcat("\n\nThere is a circular staircase here"); ostairs(1);  /* up */ break;
52 
53 	case OELEVATORUP:	lprcat("\n\nYou feel heavy for a moment, but the feeling disappears");
54 				oelevator(1);  /*  up  */  break;
55 
56 	case OFOUNTAIN:	if (nearbymonst()) return;
57 					lprcat("\n\nThere is a fountain here"); ofountain(); break;
58 
59 	case OSTATUE:	if (nearbymonst()) return;
60 					lprcat("\n\nYou are standing in front of a statue"); ostatue(); break;
61 
62 	case OCHEST:	lprcat("\n\nThere is a chest here");  ochest();  break;
63 
64 	case OIVTELETRAP:	if (rnd(11)<6) return;
65 						item[playerx][playery] = OTELEPORTER;
66 						know[playerx][playery] = 1;
67 
68 	case OTELEPORTER:	lprcat("\nZaaaappp!  You've been teleported!\n");
69 						beep(); nap(3000); oteleport(0);
70 						break;
71 
72 	case OSCHOOL:	if (nearbymonst()) return;
73 				lprcat("\n\nYou have found the College of Larn.");
74 				lprcat("\nDo you (g) go inside, or (i) stay here? ");
75 				i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
76 				if (i == 'g') { oschool();  /*	the college of larn	*/ }
77 				else	lprcat(" stay here");
78 				break;
79 
80 	case OMIRROR:	if (nearbymonst()) return;
81 					lprcat("\n\nThere is a mirror here");	omirror();	break;
82 
83 	case OBANK2:
84 	case OBANK:	if (nearbymonst()) return;
85 				if (i==OBANK) lprcat("\n\nYou have found the bank of Larn.");
86 				else lprcat("\n\nYou have found a branch office of the bank of Larn.");
87 				lprcat("\nDo you (g) go inside, or (i) stay here? ");
88 				j=0; while ((j!='g') && (j!='i') && (j!='\33')) j=getchar();
89 				if (j == 'g') {  if (i==OBANK) obank(); else obank2(); /*  the bank of larn  */  }
90 				else   lprcat(" stay here");
91 				break;
92 
93 	case ODEADFOUNTAIN:	if (nearbymonst()) return;
94 						lprcat("\n\nThere is a dead fountain here"); break;
95 
96 	case ODNDSTORE:	if (nearbymonst()) return;
97 					lprcat("\n\nThere is a DND store here.");
98 					lprcat("\nDo you (g) go inside, or (i) stay here? ");
99 					i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
100 					if (i == 'g')
101 						dndstore();  /*  the dnd adventurers store  */
102 					else  lprcat(" stay here");
103 					break;
104 
105 	case OSTAIRSDOWN:	lprcat("\n\nThere is a circular staircase here"); ostairs(-1); /* down */ break;
106 
107 	case OELEVATORDOWN:	lprcat("\n\nYou feel light for a moment, but the feeling disappears");
108 				oelevator(-1);	/*	down	*/
109 				break;
110 
111 	case OOPENDOOR:		lprintf("\n\nYou have found %s",objectname[i]);
112 						lprcat("\nDo you (c) close it"); iopts();
113 						i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar();
114 						if ((i=='\33') || (i=='i')) { ignore();  break; }
115 						lprcat("close");  forget();
116 						item[playerx][playery]=OCLOSEDDOOR;
117 						iarg[playerx][playery]=0;
118 						playerx = lastpx;  playery = lastpy;
119 						break;
120 
121 	case OCLOSEDDOOR:	lprintf("\n\nYou have found %s",objectname[i]);
122 						lprcat("\nDo you (o) try to open it"); iopts();
123 						i=0; while ((i!='o') && (i!='i') && (i!='\33')) i=getchar();
124 						if ((i=='\33') || (i=='i'))
125 							{ ignore();  playerx = lastpx;
126 							playery = lastpy; break; }
127 						else
128 						{
129 						lprcat("open");
130 						if (rnd(11)<7)
131 						  {
132 						  switch(iarg[playerx][playery])
133 							{
134 							case 6: c[AGGRAVATE] += rnd(400);	break;
135 
136 							case 7:	lprcat("\nYou are jolted by an electric shock ");
137 									lastnum=274; losehp(rnd(20));  bottomline();  break;
138 
139 							case 8:	loselevel();  break;
140 
141 							case 9:	lprcat("\nYou suddenly feel weaker ");
142 									if (c[STRENGTH]>3) c[STRENGTH]--;
143 									bottomline();  break;
144 
145 							default:	break;
146 							}
147 						  playerx = lastpx;  playery = lastpy;
148 						  }
149 						else
150 						  {
151 						  forget();  item[playerx][playery]=OOPENDOOR;
152 						  }
153 						}
154 						break;
155 
156 	case OENTRANCE:	lprcat("\nYou have found "); lprcat(objectname[OENTRANCE]);
157 					lprcat("\nDo you (g) go inside"); iopts();
158 					i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
159 					if (i == 'g')
160 						{
161 						newcavelevel(1); playerx=33; playery=MAXY-2;
162 						item[33][MAXY-1]=know[33][MAXY-1]=mitem[33][MAXY-1]=0;
163 						draws(0,MAXX,0,MAXY); bot_linex(); return;
164 						}
165 					else   ignore();
166 					break;
167 
168 	case OVOLDOWN:	lprcat("\nYou have found "); lprcat(objectname[OVOLDOWN]);
169 						lprcat("\nDo you (c) climb down"); iopts();
170 						i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar();
171 						if ((i=='\33') || (i=='i')) { ignore();  break; }
172 					if (level!=0) { lprcat("\nThe shaft only extends 5 feet downward!"); return; }
173 					if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); beep();
174 											  lastnum=275;  losehp(30+rnd(20)); bottomhp(); }
175 
176 					else lprcat("climb down");  nap(3000);  newcavelevel(MAXLEVEL);
177 					for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++) /* put player near volcano shaft */
178 						if (item[j][i]==OVOLUP) { playerx=j; playery=i; j=MAXX; i=MAXY; positionplayer(); }
179 					draws(0,MAXX,0,MAXY); bot_linex(); return;
180 
181 	case OVOLUP:	lprcat("\nYou have found "); lprcat(objectname[OVOLUP]);
182 						lprcat("\nDo you (c) climb up"); iopts();
183 						i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar();
184 						if ((i=='\33') || (i=='i')) { ignore();  break; }
185 					if (level!=11) { lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!"); return; }
186 					if (packweight() > 45+5*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); beep();
187 											  lastnum=275; losehp(15+rnd(20)); bottomhp(); return; }
188 					lprcat("climb up"); lflush(); nap(3000); newcavelevel(0);
189 					for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++) /* put player near volcano shaft */
190 						if (item[j][i]==OVOLDOWN) { playerx=j; playery=i; j=MAXX; i=MAXY; positionplayer(); }
191 					draws(0,MAXX,0,MAXY); bot_linex(); return;
192 
193 	case OTRAPARROWIV:	if (rnd(17)<13) return;	/* for an arrow trap */
194 						item[playerx][playery] = OTRAPARROW;
195 						know[playerx][playery] = 0;
196 
197 	case OTRAPARROW:	lprcat("\nYou are hit by an arrow"); beep();	/* for an arrow trap */
198 						lastnum=259;	losehp(rnd(10)+level);
199 						bottomhp();	return;
200 
201 	case OIVDARTRAP:	if (rnd(17)<13) return;		/* for a dart trap */
202 						item[playerx][playery] = ODARTRAP;
203 						know[playerx][playery] = 0;
204 
205 	case ODARTRAP:		lprcat("\nYou are hit by a dart"); beep();	/* for a dart trap */
206 						lastnum=260;	losehp(rnd(5));
207 						if ((--c[STRENGTH]) < 3) c[STRENGTH] = 3;
208 						bottomline();	return;
209 
210 	case OIVTRAPDOOR:	if (rnd(17)<13) return;		/* for a trap door */
211 						item[playerx][playery] = OTRAPDOOR;
212 						know[playerx][playery] = 1;
213 
214 	case OTRAPDOOR:		lastnum = 272; /* a trap door */
215 						if ((level==MAXLEVEL-1) || (level==MAXLEVEL+MAXVLEVEL-1))
216 							{ lprcat("\nYou fell through a bottomless trap door!"); beep();  nap(3000);  died(271); }
217 						lprcat("\nYou fall through a trap door!"); beep();	/* for a trap door */
218 						losehp(rnd(5+level));
219 						nap(2000);  newcavelevel(level+1);  draws(0,MAXX,0,MAXY); bot_linex();
220 						return;
221 
222 
223 	case OTRADEPOST:	if (nearbymonst()) return;
224 				lprcat("\nYou have found the Larn trading Post.");
225 				lprcat("\nDo you (g) go inside, or (i) stay here? ");
226 				i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
227 				if (i == 'g')  otradepost();  else  lprcat("stay here");
228 				return;
229 
230 	case OHOME:	if (nearbymonst()) return;
231 				lprcat("\nYou have found your way home.");
232 				lprcat("\nDo you (g) go inside, or (i) stay here? ");
233 				i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
234 				if (i == 'g')  ohome();  else  lprcat("stay here");
235 				return;
236 
237 	case OWALL:	break;
238 
239 	case OANNIHILATION:	died(283); return; 	/* annihilated by sphere of annihilation */
240 
241 	case OLRS:	if (nearbymonst()) return;
242 				lprcat("\n\nThere is an LRS office here.");
243 				lprcat("\nDo you (g) go inside, or (i) stay here? ");
244 				i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
245 				if (i == 'g')
246 					olrs();  /*  the larn revenue service */
247 				else  lprcat(" stay here");
248 				break;
249 
250 	default:	finditem(i); break;
251 	};
252 }
253 
254 /*
255 	function to say what object we found and ask if player wants to take it
256  */
257 finditem(itm)
258 	int itm;
259 	{
260 	int tmp,i;
261 	lprintf("\n\nYou have found %s ",objectname[itm]);
262 	tmp=iarg[playerx][playery];
263 	switch(itm)
264 		{
265 		case ODIAMOND:		case ORUBY:			case OEMERALD:
266 		case OSAPPHIRE:		case OSPIRITSCARAB:	case OORBOFDRAGON:
267 		case OCUBEofUNDEAD:	case ONOTHEFT:	break;
268 
269 		default:
270 		if (tmp>0) lprintf("+ %d",(long)tmp); else if (tmp<0) lprintf(" %d",(long)tmp);
271 		}
272 	lprcat("\nDo you want to (t) take it"); iopts();
273 	i=0; while (i!='t' && i!='i' && i!='\33') i=getchar();
274 	if (i == 't')
275 		{	lprcat("take");  if (take(itm,tmp)==0)  forget();	return;	}
276 	ignore();
277 	}
278 
279 
280 /*
281 	*******
282 	OSTAIRS
283 	*******
284 
285 	subroutine to process the stair cases
286 	if dir > 0 the up else down
287  */
288 ostairs(dir)
289 	int dir;
290 	{
291 	register int k;
292 	lprcat("\nDo you (s) stay here  ");
293 	if (dir > 0)	lprcat("(u) go up  ");	else	lprcat("(d) go down  ");
294 	lprcat("or (f) kick stairs? ");
295 
296 	while (1) switch(getchar())
297 		{
298 		case '\33':
299 		case 's':	case 'i':	lprcat("stay here");	return;
300 
301 		case 'f':	lprcat("kick stairs");
302 					if (rnd(2) == 1)
303 						lprcat("\nI hope you feel better.  Showing anger rids you of frustration.");
304 					else
305 						{
306 						k=rnd((level+1)<<1);
307 						lprintf("\nYou hurt your foot dumb dumb!  You suffer %d hit points",(long)k);
308 						lastnum=276;  losehp(k);  bottomline();
309 						}
310 					return;
311 
312 		case 'u':	lprcat("go up");
313 					if (dir < 0)	lprcat("\nThe stairs don't go up!");
314 					else
315 					  if (level>=2 && level!=11)
316 						{
317 						k = level;  newcavelevel(level-1);
318 						draws(0,MAXX,0,MAXY); bot_linex();
319 						}
320 					  else lprcat("\nThe stairs lead to a dead end!");
321 					return;
322 
323 		case 'd':	lprcat("go down");
324 					if (dir > 0)	lprcat("\nThe stairs don't go down!");
325 					else
326 					  if (level!=0 && level!=10 && level!=13)
327 						{
328 						k = level;  newcavelevel(level+1);
329 						draws(0,MAXX,0,MAXY); bot_linex();
330 						}
331 					  else lprcat("\nThe stairs lead to a dead end!");
332 					return;
333 		};
334 	}
335 
336 
337 /*
338 	*********
339 	OTELEPORTER
340 	*********
341 
342 	subroutine to handle a teleport trap +/- 1 level maximum
343  */
344 oteleport(err)
345 	int err;
346 	{
347 	register int tmp;
348 	if (err) if (rnd(151)<3)  died(264);  /*	stuck in a rock */
349 	c[TELEFLAG]=1;	/*	show ?? on bottomline if been teleported	*/
350 	if (level==0) tmp=0;
351 	else if (level < MAXLEVEL)
352 		{ tmp=rnd(5)+level-3; if (tmp>=MAXLEVEL) tmp=MAXLEVEL-1;
353 			if (tmp<1) tmp=1; }
354 	else
355 		{ tmp=rnd(3)+level-2; if (tmp>=MAXLEVEL+MAXVLEVEL) tmp=MAXLEVEL+MAXVLEVEL-1;
356 			if (tmp<MAXLEVEL) tmp=MAXLEVEL; }
357 	playerx = rnd(MAXX-2);	playery = rnd(MAXY-2);
358 	if (level != tmp)	newcavelevel(tmp);  positionplayer();
359 	draws(0,MAXX,0,MAXY); bot_linex();
360 	}
361 
362 /*
363 	*******
364 	OPOTION
365 	*******
366 
367 	function to process a potion
368  */
369 opotion(pot)
370 	int pot;
371 	{
372 	lprcat("\nDo you (d) drink it, (t) take it"); iopts();
373 	while (1) switch(getchar())
374 		{
375 		case '\33':
376 		case 'i':	ignore();  return;
377 
378 		case 'd':	lprcat("drink\n");	forget();	/*	destroy potion	*/
379 					quaffpotion(pot);		return;
380 
381 		case 't':	lprcat("take\n");	if (take(OPOTION,pot)==0)  forget();
382 					return;
383 		};
384 	}
385 
386 /*
387 	function to drink a potion
388  */
389 quaffpotion(pot)
390 	int pot;
391 	{
392 	register int i,j,k;
393 	if (pot<0 || pot>=MAXPOTION) return; /* check for within bounds */
394 	potionname[pot][0] = ' ';
395 	switch(pot)
396 		{
397 		case 9: lprcat("\nYou feel greedy . . .");   nap(2000);
398 				for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
399 				  if ((item[j][i]==OGOLDPILE) || (item[j][i]==OMAXGOLD))
400 					{
401 					know[j][i]=1; show1cell(j,i);
402 					}
403 				showplayer();  return;
404 
405 		case 19: lprcat("\nYou feel greedy . . .");   nap(2000);
406 				for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
407 					{
408 					k=item[j][i];
409 					if ((k==ODIAMOND) || (k==ORUBY) || (k==OEMERALD) || (k==OMAXGOLD)
410 						 || (k==OSAPPHIRE) || (k==OLARNEYE) || (k==OGOLDPILE))
411 						 {
412 						 know[j][i]=1; show1cell(j,i);
413 						 }
414 					}
415 				showplayer();  return;
416 
417 		case 20: c[HP] = c[HPMAX]; break;	/* instant healing */
418 
419 		case 1:	lprcat("\nYou feel better");
420 				if (c[HP] == c[HPMAX])  raisemhp(1);
421 				else if ((c[HP] += rnd(20)+20+c[LEVEL]) > c[HPMAX]) c[HP]=c[HPMAX];  break;
422 
423 		case 2:	lprcat("\nSuddenly, you feel much more skillful!");
424 				raiselevel();  raisemhp(1); return;
425 
426 		case 3:	lprcat("\nYou feel strange for a moment");
427 				c[rund(6)]++;  break;
428 
429 		case 4:	lprcat("\nYou feel more self confident!");
430 				c[WISDOM] += rnd(2);  break;
431 
432 		case 5:	lprcat("\nWow!  You feel great!");
433 				if (c[STRENGTH]<12) c[STRENGTH]=12; else c[STRENGTH]++;  break;
434 
435 		case 6:	lprcat("\nYour charm went up by one!");  c[CHARISMA]++;  break;
436 
437 		case 8:	lprcat("\nYour intelligence went up by one!");
438 				c[INTELLIGENCE]++;  break;
439 
440 		case 10: for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
441 				   if (mitem[j][i])
442 					{
443 					know[j][i]=1; show1cell(j,i);
444 					}
445 				 /*	monster detection	*/  return;
446 
447 		case 12: lprcat("\nThis potion has no taste to it");  return;
448 
449 		case 15: lprcat("\nWOW!!!  You feel Super-fantastic!!!");
450 				 if (c[HERO]==0) for (i=0; i<6; i++) c[i] += 11;
451 					c[HERO] += 250;  break;
452 
453 		case 16: lprcat("\nYou have a greater intestinal constitude!");
454 				 c[CONSTITUTION]++;  break;
455 
456 		case 17: lprcat("\nYou now have incredibly bulging muscles!!!");
457 				 if (c[GIANTSTR]==0) c[STREXTRA] += 21;
458 				 c[GIANTSTR] += 700;  break;
459 
460 		case 18: lprcat("\nYou feel a chill run up your spine!");
461 				 c[FIRERESISTANCE] += 1000;  break;
462 
463 		case 0:	lprcat("\nYou fall asleep. . .");
464 				i=rnd(11)-(c[CONSTITUTION]>>2)+2;  while(--i>0) { parse2();  nap(1000); }
465 				cursors();  lprcat("\nYou woke up!");  return;
466 
467 		case 7:	lprcat("\nYou become dizzy!");
468 				if (--c[STRENGTH] < 3) c[STRENGTH]=3;  break;
469 
470 		case 11: lprcat("\nYou stagger for a moment . .");
471 				 for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
472 					know[j][i]=0;
473 				 nap(2000);	draws(0,MAXX,0,MAXY); /* potion of forgetfulness */  return;
474 
475 		case 13: lprcat("\nYou can't see anything!");  /* blindness */
476 				 c[BLINDCOUNT]+=500;  return;
477 
478 		case 14: lprcat("\nYou feel confused"); c[CONFUSE]+= 20+rnd(9); return;
479 
480 		case 21: lprcat("\nYou don't seem to be affected");  return; /* cure dianthroritis */
481 
482 		case 22: lprcat("\nYou feel a sickness engulf you"); /* poison */
483 				 c[HALFDAM] += 200 + rnd(200);  return;
484 
485 		case 23: lprcat("\nYou feel your vision sharpen");	/* see invisible */
486 				 c[SEEINVISIBLE] += rnd(1000)+400;
487 				 monstnamelist[INVISIBLESTALKER] = 'I';  return;
488 		};
489 	bottomline();		/*	show new stats		*/  return;
490 	}
491 
492 /*
493 	*******
494 	OSCROLL
495 	*******
496 
497 	function to process a magic scroll
498  */
499 oscroll(typ)
500 	int typ;
501 	{
502 	lprcat("\nDo you ");
503 	if (c[BLINDCOUNT]==0) lprcat("(r) read it, "); lprcat("(t) take it"); iopts();
504 	while (1) switch(getchar())
505 		{
506 		case '\33':
507 		case 'i':	ignore();  return;
508 
509 		case 'r':	if (c[BLINDCOUNT]) break;
510 					lprcat("read"); forget();
511 					if (typ==2 || typ==15)  { show1cell(playerx,playery); cursors(); }
512 					/*	destroy it	*/	read_scroll(typ);  return;
513 
514 		case 't':	lprcat("take"); if (take(OSCROLL,typ)==0)	forget();	/*	destroy it	*/
515 					return;
516 		};
517 	}
518 
519 /*
520 	data for the function to read a scroll
521  */
522 static int xh,yh,yl,xl;
523 static char curse[] = { BLINDCOUNT, CONFUSE, AGGRAVATE, HASTEMONST, ITCHING,
524 	LAUGHING, DRAINSTRENGTH, CLUMSINESS, INFEEBLEMENT, HALFDAM };
525 static char exten[] = { PROTECTIONTIME, DEXCOUNT, STRCOUNT, CHARMCOUNT,
526 	INVISIBILITY, CANCELLATION, HASTESELF, GLOBE, SCAREMONST, HOLDMONST, TIMESTOP };
527 char time_change[] = { HASTESELF,HERO,ALTPRO,PROTECTIONTIME,DEXCOUNT,
528 	STRCOUNT,GIANTSTR,CHARMCOUNT,INVISIBILITY,CANCELLATION,
529 	HASTESELF,AGGRAVATE,SCAREMONST,STEALTH,AWARENESS,HOLDMONST,HASTEMONST,
530 	FIRERESISTANCE,GLOBE,SPIRITPRO,UNDEADPRO,HALFDAM,SEEINVISIBLE,
531 	ITCHING,CLUMSINESS, WTW };
532 /*
533  *	function to adjust time when time warping and taking courses in school
534  */
535 adjtime(tim)
536 	register long tim;
537 	{
538 	register int j;
539 	for (j=0; j<26; j++)	/* adjust time related parameters */
540 		if (c[time_change[j]])
541 			if ((c[time_change[j]] -= tim) < 1) c[time_change[j]]=1;
542 	regen();
543 	}
544 
545 /*
546 	function to read a scroll
547  */
548 read_scroll(typ)
549 	int typ;
550 	{
551 	register int i,j;
552 	if (typ<0 || typ>=MAXSCROLL) return;  /* be sure we are within bounds */
553 	scrollname[typ][0] = ' ';
554 	switch(typ)
555 	  {
556 	  case 0:	lprcat("\nYour armor glows for a moment");  enchantarmor(); return;
557 
558 	  case 1:	lprcat("\nYour weapon glows for a moment"); enchweapon(); return;  /* enchant weapon */
559 
560 	  case 2:	lprcat("\nYou have been granted enlightenment!");
561 				yh = min(playery+7,MAXY);	xh = min(playerx+25,MAXX);
562 				yl = max(playery-7,0);		xl = max(playerx-25,0);
563 				for (i=yl; i<yh; i++) for (j=xl; j<xh; j++)  know[j][i]=1;
564 				nap(2000);	draws(xl,xh,yl,yh);	return;
565 
566 	  case 3:	lprcat("\nThis scroll seems to be blank");	return;
567 
568 	  case 4:	createmonster(makemonst(level+1));  return;  /*  this one creates a monster  */
569 
570 	  case 5:	something(level);	/*	create artifact		*/  return;
571 
572 	  case 6:	c[AGGRAVATE]+=800; return; /* aggravate monsters */
573 
574 	  case 7:	gtime += (i = rnd(1000) - 850); /* time warp */
575 				if (i>=0) lprintf("\nYou went forward in time by %d mobuls",(long)((i+99)/100));
576 				else lprintf("\nYou went backward in time by %d mobuls",(long)(-(i+99)/100));
577 				adjtime((long)i);	/* adjust time for time warping */
578 				return;
579 
580 	  case 8:	oteleport(0);	  return;	/*	teleportation */
581 
582 	  case 9:	c[AWARENESS] += 1800;  return;	/* expanded awareness	*/
583 
584 	  case 10:	c[HASTEMONST] += rnd(55)+12; return;	/* haste monster */
585 
586 	  case 11:	for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
587 					if (mitem[j][i])
588 						hitp[j][i] = monster[mitem[j][i]].hitpoints;
589 				return;	/* monster healing */
590 	  case 12:	c[SPIRITPRO] += 300 + rnd(200); bottomline(); return; /* spirit protection */
591 
592 	  case 13:	c[UNDEADPRO] += 300 + rnd(200); bottomline(); return; /* undead protection */
593 
594 	  case 14:	c[STEALTH] += 250 + rnd(250);  bottomline(); return; /* stealth */
595 
596 	  case 15:	lprcat("\nYou have been granted enlightenment!"); /* magic mapping */
597 				for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++)  know[j][i]=1;
598 				nap(2000);	draws(0,MAXX,0,MAXY);	return;
599 
600 	  case 16:	c[HOLDMONST] += 30; bottomline(); return; /* hold monster */
601 
602 	  case 17:	for (i=0; i<26; i++)	/* gem perfection */
603 					switch(iven[i])
604 						{
605 						case ODIAMOND:	case ORUBY:
606 						case OEMERALD:	case OSAPPHIRE:
607 							j = ivenarg[i];  j &= 255;  j <<= 1;
608 							if (j  > 255) j=255; /* double value */
609 							ivenarg[i] = j;	break;
610 						}
611 				break;
612 
613 	  case 18:	for (i=0; i<11; i++)	c[exten[i]] <<= 1; /* spell extension */
614 				break;
615 
616 	  case 19:	for (i=0; i<26; i++)	/* identify */
617 					{
618 					if (iven[i]==OPOTION)  potionname[ivenarg[i]][0] = ' ';
619 					if (iven[i]==OSCROLL)  scrollname[ivenarg[i]][0] = ' ';
620 					}
621 				break;
622 
623 	  case 20:	for (i=0; i<10; i++)	/* remove curse */
624 					if (c[curse[i]]) c[curse[i]] = 1;
625 				break;
626 
627 	  case 21:	annihilate();	break;	/* scroll of annihilation */
628 
629 	  case 22:	godirect(22,150,"The ray hits the %s",0,' ');	/* pulverization */
630 				break;
631 	  case 23:  c[LIFEPROT]++;  break; /* life protection */
632 	  };
633 	}
634 
635 
636 oorb()
637 	{
638 	}
639 
640 opit()
641 	{
642 	register int i;
643 	if (rnd(101)<81)
644 	  if (rnd(70) > 9*c[DEXTERITY]-packweight() || rnd(101)<5)
645 		if (level==MAXLEVEL-1) obottomless(); else
646 		if (level==MAXLEVEL+MAXVLEVEL-1) obottomless(); else
647 			{
648 			if (rnd(101)<20)
649 				{
650 				i=0; lprcat("\nYou fell into a pit!  Your fall is cushioned by an unknown force\n");
651 				}
652 			else
653 				{
654 				i = rnd(level*3+3);
655 				lprintf("\nYou fell into a pit!  You suffer %d hit points damage",(long)i);
656 				lastnum=261; 	/*	if he dies scoreboard will say so */
657 				}
658 			losehp(i); nap(2000);  newcavelevel(level+1);  draws(0,MAXX,0,MAXY);
659 			}
660 	}
661 
662 obottomless()
663 	{
664 	lprcat("\nYou fell into a bottomless pit!");  beep(); nap(3000);  died(262);
665 	}
666 oelevator(dir)
667 	int dir;
668 	{
669 #ifdef lint
670 	int x;
671 	x=dir;
672 	dir=x;
673 #endif lint
674 	}
675 
676 ostatue()
677 	{
678 	}
679 
680 omirror()
681 	{
682 	}
683 
684 obook()
685 	{
686 	lprcat("\nDo you ");
687 	if (c[BLINDCOUNT]==0) lprcat("(r) read it, "); lprcat("(t) take it"); iopts();
688 	while (1) switch(getchar())
689 		{
690 		case '\33':
691 		case 'i':	ignore();	return;
692 
693 		case 'r':	if (c[BLINDCOUNT]) break;
694 					lprcat("read");
695 					/* no more book	*/	readbook(iarg[playerx][playery]);  forget(); return;
696 
697 		case 't':	lprcat("take");  if (take(OBOOK,iarg[playerx][playery])==0)  forget();	/* no more book	*/
698 					return;
699 		};
700 	}
701 
702 /*
703 	function to read a book
704  */
705 readbook(lev)
706 	register int lev;
707 	{
708 	register int i,tmp;
709 	if (lev<=3) i = rund((tmp=splev[lev])?tmp:1); else
710 		i = rnd((tmp=splev[lev]-9)?tmp:1) + 9;
711 	spelknow[i]=1;
712 	lprintf("\nSpell \"%s\":  %s\n%s",spelcode[i],spelname[i],speldescript[i]);
713 	if (rnd(10)==4)
714 	 { lprcat("\nYour int went up by one!"); c[INTELLIGENCE]++; bottomline(); }
715 	}
716 
717 ocookie()
718 	{
719 	char *p;
720 	lprcat("\nDo you (e) eat it, (t) take it"); iopts();
721 	while (1) switch(getchar())
722 		{
723 		case '\33':
724 		case 'i':	ignore();	return;
725 
726 		case 'e':	lprcat("eat\nThe cookie tasted good.");
727 					forget(); /* no more cookie	*/
728 					if (c[BLINDCOUNT]) return;
729 					if (!(p=fortune(fortfile))) return;
730 					lprcat("  A message inside the cookie reads:\n"); lprcat(p);
731 					return;
732 
733 		case 't':	lprcat("take");  if (take(OCOOKIE,0)==0) forget();	/* no more book	*/
734 					return;
735 		};
736 	}
737 
738 
739 /* routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth 100* the argument */
740 ogold(arg)
741 	int arg;
742 	{
743 	register long i;
744 	i = iarg[playerx][playery];
745 	if (arg==OMAXGOLD) i *= 100;
746 		else if (arg==OKGOLD) i *= 1000;
747 			else if (arg==ODGOLD) i *= 10;
748 	lprintf("\nIt is worth %d!",(long)i);	c[GOLD] += i;  bottomgold();
749 	item[playerx][playery] = know[playerx][playery] = 0; /*	destroy gold	*/
750 	}
751 
752 ohome()
753 	{
754 	register int i;
755 	nosignal = 1;	/* disable signals */
756 	for (i=0; i<26; i++) if (iven[i]==OPOTION) if (ivenarg[i]==21)
757 		{
758 		iven[i]=0;	/* remove the potion of cure dianthroritis from inventory */
759 		clear(); lprcat("Congratulations.  You found a potion of cure dianthroritis.\n");
760 		lprcat("\nFrankly, No one thought you could do it.  Boy!  Did you surprise them!\n");
761 		if (gtime>TIMELIMIT)
762 			{
763 			lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
764 			lprcat("You didn't make it in time.  In your agony, you kill the doctor,\nyour wife, and yourself!  Too bad!\n");
765 			nap(5000); died(269);
766 			}
767 		else
768 			{
769 			lprcat("\nThe doctor is now administering the potion, and in a few moments\n");
770 			lprcat("Your daughter should be well on her way to recovery.\n");
771 			nap(6000);
772 			lprcat("\nThe potion is"); nap(3000); lprcat(" working!  The doctor thinks that\n");
773 			lprcat("your daughter will recover in a few days.  Congratulations!\n");
774 			beep(); nap(5000); died(263);
775 			}
776 		}
777 
778 	while (1)
779 		{
780 		clear(); lprintf("Welcome home %s.  Latest word from the doctor is not good.\n",logname);
781 
782 		if (gtime>TIMELIMIT)
783 			{
784 			lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
785 			lprcat("You didn't make it in time.  In your agony, you kill the doctor,\nyour wife, and yourself!  Too bad!\n");
786 			nap(5000); died(269);
787 			}
788 
789 		lprcat("\nThe diagnosis is confirmed as dianthroritis.  He guesses that\n");
790 		lprintf("your daughter has only %d mobuls left in this world.  It's up to you,\n",(long)((TIMELIMIT-gtime+99)/100));
791 		lprintf("%s, to find the only hope for your daughter, the very rare\n",logname);
792 		lprcat("potion of cure dianthroritis.  It is rumored that only deep in the\n");
793 		lprcat("depths of the caves can this potion be found.\n\n\n");
794 		lprcat("\n     ----- press "); standout("return");
795 		lprcat(" to continue, "); standout("escape");
796 		lprcat(" to leave ----- ");
797 		i=getchar();  while (i!='\33' && i!='\n') i=getchar();
798 		if (i=='\33') { drawscreen(); nosignal = 0; /* enable signals */ return; }
799 		}
800 	}
801 
802 /*	routine to save program space	*/
803 iopts()
804 	{	lprcat(", or (i) ignore it? ");	}
805 ignore()
806 	{	lprcat("ignore\n");	}
807 
808