summaryrefslogtreecommitdiffstats
path: root/larn/object.c
blob: 942b6bce3e522d1eacb08a799ae299108b605a1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
/*	$NetBSD: object.c,v 1.17 2019/02/03 03:19:25 mrg Exp $	*/

/* object.c		Larn is copyrighted 1986 by Noah Morgan. */

#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: object.c,v 1.17 2019/02/03 03:19:25 mrg Exp $");
#endif				/* not lint */
#include "header.h"
#include "extern.h"

static void finditem(int);
static void ostairs(int);
static void opotion(int);
static void oscroll(int);
static void oorb(void);
static void opit(void);
static void obottomless(void);
static void oelevator(int);
static void ostatue(void);
static void omirror(void);
static void obook(void);
static void ocookie(void);
static void ogold(int);
static void ohome(void);

/*
	lookforobject

	subroutine to look for an object and give the player his options
	if an object was found.
 */
void
lookforobject(void)
{
	int    i, j;
	if (c[TIMESTOP])
		return;		/* can't find objects if time is stopped	 */
	i = item[playerx][playery];
	if (i == 0)
		return;
	showcell(playerx, playery);
	cursors();
	yrepcount = 0;
	switch (i) {
	case OGOLDPILE:
	case OMAXGOLD:
	case OKGOLD:
	case ODGOLD:
		lprcat("\n\nYou have found some gold!");
		ogold(i);
		break;

	case OPOTION:
		lprcat("\n\nYou have found a magic potion");
		i = iarg[playerx][playery];
		if (potionname[i][0] != 0)
			lprintf(" of%s", potionname[i]);
		opotion(i);
		break;

	case OSCROLL:
		lprcat("\n\nYou have found a magic scroll");
		i = iarg[playerx][playery];
		if (scrollname[i][0] != 0)
			lprintf(" of%s", scrollname[i]);
		oscroll(i);
		break;

	case OALTAR:
		if (nearbymonst())
			return;
		lprcat("\n\nThere is a Holy Altar here!");
		oaltar();
		break;

	case OBOOK:
		lprcat("\n\nYou have found a book.");
		obook();
		break;

	case OCOOKIE:
		lprcat("\n\nYou have found a fortune cookie.");
		ocookie();
		break;

	case OTHRONE:
		if (nearbymonst())
			return;
		lprintf("\n\nThere is %s here!", objectname[i]);
		othrone(0);
		break;

	case OTHRONE2:
		if (nearbymonst())
			return;
		lprintf("\n\nThere is %s here!", objectname[i]);
		othrone(1);
		break;

	case ODEADTHRONE:
		lprintf("\n\nThere is %s here!", objectname[i]);
		odeadthrone();
		break;

	case OORB:
		lprcat("\n\nYou have found the Orb!!!!!");
		oorb();
		break;

	case OPIT:
		lprcat("\n\nYou're standing at the top of a pit.");
		opit();
		break;

	case OSTAIRSUP:
		lprcat("\n\nThere is a circular staircase here");
		ostairs(1);	/* up */
		break;

	case OELEVATORUP:
		lprcat("\n\nYou feel heavy for a moment, but the feeling disappears");
		oelevator(1);	/* up  */
		break;

	case OFOUNTAIN:
		if (nearbymonst())
			return;
		lprcat("\n\nThere is a fountain here");
		ofountain();
		break;

	case OSTATUE:
		if (nearbymonst())
			return;
		lprcat("\n\nYou are standing in front of a statue");
		ostatue();
		break;

	case OCHEST:
		lprcat("\n\nThere is a chest here");
		ochest();
		break;

	case OIVTELETRAP:
		if (rnd(11) < 6)
			return;
		item[playerx][playery] = OTELEPORTER;
		know[playerx][playery] = 1;

		/* FALLTHROUGH */
	case OTELEPORTER:
		lprcat("\nZaaaappp!  You've been teleported!\n");
		beep();
		nap(3000);
		oteleport(0);
		break;

	case OSCHOOL:
		if (nearbymonst())
			return;
		lprcat("\n\nYou have found the College of Larn.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i = 0;
		while ((i != 'g') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if (i == 'g') {
			oschool();	/* the college of larn	 */
		} else
			lprcat(" stay here");
		break;

	case OMIRROR:
		if (nearbymonst())
			return;
		lprcat("\n\nThere is a mirror here");
		omirror();
		break;

	case OBANK2:
	case OBANK:
		if (nearbymonst())
			return;
		if (i == OBANK)
			lprcat("\n\nYou have found the bank of Larn.");
		else
			lprcat("\n\nYou have found a branch office of the bank of Larn.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		j = 0;
		while ((j != 'g') && (j != 'i') && (j != '\33'))
			j = ttgetch();
		if (j == 'g') {
			if (i == OBANK)
				obank();
			else
				obank2();	/* the bank of larn  */
		} else
			lprcat(" stay here");
		break;

	case ODEADFOUNTAIN:
		if (nearbymonst())
			return;
		lprcat("\n\nThere is a dead fountain here");
		break;

	case ODNDSTORE:
		if (nearbymonst())
			return;
		lprcat("\n\nThere is a DND store here.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i = 0;
		while ((i != 'g') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if (i == 'g')
			dndstore();	/* the dnd adventurers store  */
		else
			lprcat(" stay here");
		break;

	case OSTAIRSDOWN:
		lprcat("\n\nThere is a circular staircase here");
		ostairs(-1);	/* down */
		break;

	case OELEVATORDOWN:
		lprcat("\n\nYou feel light for a moment, but the feeling disappears");
		oelevator(-1);	/* down	 */
		break;

	case OOPENDOOR:
		lprintf("\n\nYou have found %s", objectname[i]);
		lprcat("\nDo you (c) close it");
		iopts();
		i = 0;
		while ((i != 'c') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if ((i == '\33') || (i == 'i')) {
			ignore();
			break;
		}
		lprcat("close");
		forget();
		item[playerx][playery] = OCLOSEDDOOR;
		iarg[playerx][playery] = 0;
		playerx = lastpx;
		playery = lastpy;
		break;

	case OCLOSEDDOOR:
		lprintf("\n\nYou have found %s", objectname[i]);
		lprcat("\nDo you (o) try to open it");
		iopts();
		i = 0;
		while ((i != 'o') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if ((i == '\33') || (i == 'i')) {
			ignore();
			playerx = lastpx;
			playery = lastpy;
			break;
		} else {
			lprcat("open");
			if (rnd(11) < 7) {
				switch (iarg[playerx][playery]) {
				case 6:
					c[AGGRAVATE] += rnd(400);
					break;

				case 7:
					lprcat("\nYou are jolted by an electric shock ");
					lastnum = 274;
					losehp(rnd(20));
					bottomline();
					break;

				case 8:
					loselevel();
					break;

				case 9:
					lprcat("\nYou suddenly feel weaker ");
					if (c[STRENGTH] > 3)
						c[STRENGTH]--;
					bottomline();
					break;

				default:
					break;
				}
				playerx = lastpx;
				playery = lastpy;
			} else {
				forget();
				item[playerx][playery] = OOPENDOOR;
			}
		}
		break;

	case OENTRANCE:
		lprcat("\nYou have found ");
		lprcat(objectname[OENTRANCE]);
		lprcat("\nDo you (g) go inside");
		iopts();
		i = 0;
		while ((i != 'g') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if (i == 'g') {
			newcavelevel(1);
			playerx = 33;
			playery = MAXY - 2;
			item[33][MAXY - 1] = know[33][MAXY - 1] = mitem[33][MAXY - 1] = 0;
			draws(0, MAXX, 0, MAXY);
			bot_linex();
			return;
		} else
			ignore();
		break;

	case OVOLDOWN:
		lprcat("\nYou have found ");
		lprcat(objectname[OVOLDOWN]);
		lprcat("\nDo you (c) climb down");
		iopts();
		i = 0;
		while ((i != 'c') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if ((i == '\33') || (i == 'i')) {
			ignore();
			break;
		}
		if (level != 0) {
			lprcat("\nThe shaft only extends 5 feet downward!");
			return;
		}
		if (packweight() > 45 + 3 * (c[STRENGTH] + c[STREXTRA])) {
			lprcat("\nYou slip and fall down the shaft");
			beep();
			lastnum = 275;
			losehp(30 + rnd(20));
			bottomhp();
		} else
			lprcat("climb down");
		nap(3000);
		newcavelevel(MAXLEVEL);
		for (i = 0; i < MAXY; i++)
			for (j = 0; j < MAXX; j++)	/* put player near
							 * volcano shaft */
				if (item[j][i] == OVOLUP) {
					playerx = j;
					playery = i;
					j = MAXX;
					i = MAXY;
					positionplayer();
				}
		draws(0, MAXX, 0, MAXY);
		bot_linex();
		return;

	case OVOLUP:
		lprcat("\nYou have found ");
		lprcat(objectname[OVOLUP]);
		lprcat("\nDo you (c) climb up");
		iopts();
		i = 0;
		while ((i != 'c') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if ((i == '\33') || (i == 'i')) {
			ignore();
			break;
		}
		if (level != 11) {
			lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!");
			return;
		}
		if (packweight() > 45 + 5 * (c[STRENGTH] + c[STREXTRA])) {
			lprcat("\nYou slip and fall down the shaft");
			beep();
			lastnum = 275;
			losehp(15 + rnd(20));
			bottomhp();
			return;
		}
		lprcat("climb up");
		lflush();
		nap(3000);
		newcavelevel(0);
		for (i = 0; i < MAXY; i++)
			for (j = 0; j < MAXX; j++)	/* put player near
							 * volcano shaft */
				if (item[j][i] == OVOLDOWN) {
					playerx = j;
					playery = i;
					j = MAXX;
					i = MAXY;
					positionplayer();
				}
		draws(0, MAXX, 0, MAXY);
		bot_linex();
		return;

	case OTRAPARROWIV:
		if (rnd(17) < 13)
			return;	/* for an arrow trap */
		item[playerx][playery] = OTRAPARROW;
		know[playerx][playery] = 0;

		/* FALLTHROUGH */
	case OTRAPARROW:
		lprcat("\nYou are hit by an arrow");
		beep();		/* for an arrow trap */
		lastnum = 259;
		losehp(rnd(10) + level);
		bottomhp();
		return;

	case OIVDARTRAP:
		if (rnd(17) < 13)
			return;	/* for a dart trap */
		item[playerx][playery] = ODARTRAP;
		know[playerx][playery] = 0;

		/* FALLTHROUGH */
	case ODARTRAP:
		lprcat("\nYou are hit by a dart");
		beep();		/* for a dart trap */
		lastnum = 260;
		losehp(rnd(5));
		if ((--c[STRENGTH]) < 3)
			c[STRENGTH] = 3;
		bottomline();
		return;

	case OIVTRAPDOOR:
		if (rnd(17) < 13)
			return;	/* for a trap door */
		item[playerx][playery] = OTRAPDOOR;
		know[playerx][playery] = 1;

		/* FALLTHROUGH */
	case OTRAPDOOR:
		lastnum = 272;	/* a trap door */
		if ((level == MAXLEVEL - 1) || (level == MAXLEVEL + MAXVLEVEL - 1)) {
			lprcat("\nYou fell through a bottomless trap door!");
			beep();
			nap(3000);
			died(271);
		}
		lprcat("\nYou fall through a trap door!");
		beep();		/* for a trap door */
		losehp(rnd(5 + level));
		nap(2000);
		newcavelevel(level + 1);
		draws(0, MAXX, 0, MAXY);
		bot_linex();
		return;


	case OTRADEPOST:
		if (nearbymonst())
			return;
		lprcat("\nYou have found the Larn trading Post.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i = 0;
		while ((i != 'g') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if (i == 'g')
			otradepost();
		else
			lprcat("stay here");
		return;

	case OHOME:
		if (nearbymonst())
			return;
		lprcat("\nYou have found your way home.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i = 0;
		while ((i != 'g') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if (i == 'g')
			ohome();
		else
			lprcat("stay here");
		return;

	case OWALL:
		break;

	case OANNIHILATION:
		died(283);
		return;		/* annihilated by sphere of annihilation */

	case OLRS:
		if (nearbymonst())
			return;
		lprcat("\n\nThere is an LRS office here.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i = 0;
		while ((i != 'g') && (i != 'i') && (i != '\33'))
			i = ttgetch();
		if (i == 'g')
			olrs();	/* the larn revenue service */
		else
			lprcat(" stay here");
		break;

	default:
		finditem(i);
		break;
	};
}

/*
	function to say what object we found and ask if player wants to take it
 */
static void
finditem(int theitem)
{
	int             tmp, i;
	lprintf("\n\nYou have found %s ", objectname[theitem]);
	tmp = iarg[playerx][playery];
	switch (theitem) {
	case ODIAMOND:
	case ORUBY:
	case OEMERALD:
	case OSAPPHIRE:
	case OSPIRITSCARAB:
	case OORBOFDRAGON:
	case OCUBEofUNDEAD:
	case ONOTHEFT:
		break;

	default:
		if (tmp > 0)
			lprintf("+ %ld", (long) tmp);
		else if (tmp < 0)
			lprintf(" %ld", (long) tmp);
	}
	lprcat("\nDo you want to (t) take it");
	iopts();
	i = 0;
	while (i != 't' && i != 'i' && i != '\33')
		i = ttgetch();
	if (i == 't') {
		lprcat("take");
		if (take(theitem, tmp) == 0)
			forget();
		return;
	}
	ignore();
}



/*
	subroutine to process the stair cases
	if dir > 0 the up else down
 */
static void
ostairs(int dir)
{
	int    k;
	lprcat("\nDo you (s) stay here  ");
	if (dir > 0)
		lprcat("(u) go up  ");
	else
		lprcat("(d) go down  ");
	lprcat("or (f) kick stairs? ");

	while (1)
		switch (ttgetch()) {
		case '\33':
		case 's':
		case 'i':
			lprcat("stay here");
			return;

		case 'f':
			lprcat("kick stairs");
			if (rnd(2) == 1)
				lprcat("\nI hope you feel better.  Showing anger rids you of frustration.");
			else {
				k = rnd((level + 1) << 1);
				lprintf("\nYou hurt your foot dumb dumb!  You suffer %ld hit points", (long) k);
				lastnum = 276;
				losehp(k);
				bottomline();
			}
			return;

		case 'u':
			lprcat("go up");
			if (dir < 0)
				lprcat("\nThe stairs don't go up!");
			else if (level >= 2 && level != 11) {
				k = level;
				newcavelevel(level - 1);
				draws(0, MAXX, 0, MAXY);
				bot_linex();
			} else
				lprcat("\nThe stairs lead to a dead end!");
			return;

		case 'd':
			lprcat("go down");
			if (dir > 0)
				lprcat("\nThe stairs don't go down!");
			else if (level != 0 && level != 10 && level != 13) {
				k = level;
				newcavelevel(level + 1);
				draws(0, MAXX, 0, MAXY);
				bot_linex();
			} else
				lprcat("\nThe stairs lead to a dead end!");
			return;
		};
}



/*
	subroutine to handle a teleport trap +/- 1 level maximum
 */
void
oteleport(int err)
{
	int    tmp;
	if (err)
		if (rnd(151) < 3)
			died(264);	/* stuck in a rock */
	c[TELEFLAG] = 1;	/* show ?? on bottomline if been teleported	 */
	if (level == 0)
		tmp = 0;
	else if (level < MAXLEVEL) {
		tmp = rnd(5) + level - 3;
		if (tmp >= MAXLEVEL)
			tmp = MAXLEVEL - 1;
		if (tmp < 1)
			tmp = 1;
	} else {
		tmp = rnd(3) + level - 2;
		if (tmp >= MAXLEVEL + MAXVLEVEL)
			tmp = MAXLEVEL + MAXVLEVEL - 1;
		if (tmp < MAXLEVEL)
			tmp = MAXLEVEL;
	}
	playerx = rnd(MAXX - 2);
	playery = rnd(MAXY - 2);
	if (level != tmp)
		newcavelevel(tmp);
	positionplayer();
	draws(0, MAXX, 0, MAXY);
	bot_linex();
}


/*
	function to process a potion
 */
static void
opotion(int pot)
{
	lprcat("\nDo you (d) drink it, (t) take it");
	iopts();
	while (1)
		switch (ttgetch()) {
		case '\33':
		case 'i':
			ignore();
			return;

		case 'd':
			lprcat("drink\n");
			forget();	/* destroy potion	 */
			quaffpotion(pot);
			return;

		case 't':
			lprcat("take\n");
			if (take(OPOTION, pot) == 0)
				forget();
			return;
		};
}

/*
	function to drink a potion
 */
void
quaffpotion(int pot)
{
	int    i, j, k;
	if (pot < 0 || pot >= MAXPOTION)
		return;		/* check for within bounds */
	potionname[pot] = potionhide[pot];
	switch (pot) {
	case 9:
		lprcat("\nYou feel greedy . . .");
		nap(2000);
		for (i = 0; i < MAXY; i++)
			for (j = 0; j < MAXX; j++)
				if ((item[j][i] == OGOLDPILE) || (item[j][i] == OMAXGOLD)) {
					know[j][i] = 1;
					show1cell(j, i);
				}
		showplayer();
		return;

	case 19:
		lprcat("\nYou feel greedy . . .");
		nap(2000);
		for (i = 0; i < MAXY; i++)
			for (j = 0; j < MAXX; j++) {
				k = item[j][i];
				if ((k == ODIAMOND) || (k == ORUBY) || (k == OEMERALD) || (k == OMAXGOLD)
				    || (k == OSAPPHIRE) || (k == OLARNEYE) || (k == OGOLDPILE)) {
					know[j][i] = 1;
					show1cell(j, i);
				}
			}
		showplayer();
		return;

	case 20:
		c[HP] = c[HPMAX];
		break;		/* instant healing */

	case 1:
		lprcat("\nYou feel better");
		if (c[HP] == c[HPMAX])
			raisemhp(1);
		else if ((c[HP] += rnd(20) + 20 + c[LEVEL]) > c[HPMAX])
			c[HP] = c[HPMAX];
		break;

	case 2:
		lprcat("\nSuddenly, you feel much more skillful!");
		raiselevel();
		raisemhp(1);
		return;

	case 3:
		lprcat("\nYou feel strange for a moment");
		c[rund(6)]++;
		break;

	case 4:
		lprcat("\nYou feel more self confident!");
		c[WISDOM] += rnd(2);
		break;

	case 5:
		lprcat("\nWow!  You feel great!");
		if (c[STRENGTH] < 12)
			c[STRENGTH] = 12;
		else
			c[STRENGTH]++;
		break;

	case 6:
		lprcat("\nYour charm went up by one!");
		c[CHARISMA]++;
		break;

	case 8:
		lprcat("\nYour intelligence went up by one!");
		c[INTELLIGENCE]++;
		break;

	case 10:
		for (i = 0; i < MAXY; i++)
			for (j = 0; j < MAXX; j++)
				if (mitem[j][i]) {
					know[j][i] = 1;
					show1cell(j, i);
				}
		 /* monster detection	 */ return;

	case 12:
		lprcat("\nThis potion has no taste to it");
		return;

	case 15:
		lprcat("\nWOW!!!  You feel Super-fantastic!!!");
		if (c[HERO] == 0)
			for (i = 0; i < 6; i++)
				c[i] += 11;
		c[HERO] += 250;
		break;

	case 16:
		lprcat("\nYou have a greater intestinal constitude!");
		c[CONSTITUTION]++;
		break;

	case 17:
		lprcat("\nYou now have incredibly bulging muscles!!!");
		if (c[GIANTSTR] == 0)
			c[STREXTRA] += 21;
		c[GIANTSTR] += 700;
		break;

	case 18:
		lprcat("\nYou feel a chill run up your spine!");
		c[FIRERESISTANCE] += 1000;
		break;

	case 0:
		lprcat("\nYou fall asleep. . .");
		i = rnd(11) - (c[CONSTITUTION] >> 2) + 2;
		while (--i > 0) {
			parse2();
			nap(1000);
		}
		cursors();
		lprcat("\nYou woke up!");
		return;

	case 7:
		lprcat("\nYou become dizzy!");
		if (--c[STRENGTH] < 3)
			c[STRENGTH] = 3;
		break;

	case 11:
		lprcat("\nYou stagger for a moment . .");
		for (i = 0; i < MAXY; i++)
			for (j = 0; j < MAXX; j++)
				know[j][i] = 0;
		nap(2000);
		draws(0, MAXX, 0, MAXY);	/* potion of forgetfulness */
		return;

	case 13:
		lprcat("\nYou can't see anything!");	/* blindness */
		c[BLINDCOUNT] += 500;
		return;

	case 14:
		lprcat("\nYou feel confused");
		c[CONFUSE] += 20 + rnd(9);
		return;

	case 21:
		lprcat("\nYou don't seem to be affected");
		return;		/* cure dianthroritis */

	case 22:
		lprcat("\nYou feel a sickness engulf you");	/* poison */
		c[HALFDAM] += 200 + rnd(200);
		return;

	case 23:
		lprcat("\nYou feel your vision sharpen");	/* see invisible */
		c[SEEINVISIBLE] += rnd(1000) + 400;
		monstnamelist[INVISIBLESTALKER] = 'I';
		return;
	};
	bottomline();		/* show new stats		 */
	return;
}


/*
	function to process a magic scroll
 */
static void
oscroll(int typ)
{
	lprcat("\nDo you ");
	if (c[BLINDCOUNT] == 0)
		lprcat("(r) read it, ");
	lprcat("(t) take it");
	iopts();
	while (1)
		switch (ttgetch()) {
		case '\33':
		case 'i':
			ignore();
			return;

		case 'r':
			if (c[BLINDCOUNT])
				break;
			lprcat("read");
			forget();
			if (typ == 2 || typ == 15) {
				show1cell(playerx, playery);
				cursors();
			}
			 /* destroy it	 */ read_scroll(typ);
			return;

		case 't':
			lprcat("take");
			if (take(OSCROLL, typ) == 0)
				forget();	/* destroy it	 */
			return;
		};
}

/*
	data for the function to read a scroll
 */
static int      xh, yh, yl, xl;
static u_char     curse[] = {
	BLINDCOUNT, CONFUSE, AGGRAVATE, HASTEMONST, ITCHING,
	LAUGHING, DRAINSTRENGTH, CLUMSINESS, INFEEBLEMENT, HALFDAM
};

static u_char     exten[] = {
	PROTECTIONTIME, DEXCOUNT, STRCOUNT, CHARMCOUNT, INVISIBILITY,
	CANCELLATION, HASTESELF, GLOBE, SCAREMONST, HOLDMONST, TIMESTOP
};

static u_char time_change[] = {
	HASTESELF, HERO, ALTPRO, PROTECTIONTIME, DEXCOUNT, STRCOUNT,
	GIANTSTR, CHARMCOUNT, INVISIBILITY, CANCELLATION, HASTESELF,
	AGGRAVATE, SCAREMONST, STEALTH, AWARENESS, HOLDMONST,
	HASTEMONST, FIRERESISTANCE, GLOBE, SPIRITPRO, UNDEADPRO,
	HALFDAM, SEEINVISIBLE, ITCHING, CLUMSINESS, WTW
};

/*
 *	function to adjust time when time warping and taking courses in school
 */
void
adjusttime(long tim)
{
	int    j;
	for (j = 0; j < 26; j++)/* adjust time related parameters */
		if (c[time_change[j]])
			if ((c[time_change[j]] -= tim) < 1)
				c[time_change[j]] = 1;
	regen();
}

/*
	function to read a scroll
 */
void
read_scroll(int typ)
{
	int    i, j;
	if (typ < 0 || typ >= MAXSCROLL)
		return;		/* be sure we are within bounds */
	scrollname[typ] = scrollhide[typ];
	switch (typ) {
	case 0:
		lprcat("\nYour armor glows for a moment");
		enchantarmor();
		return;

	case 1:
		lprcat("\nYour weapon glows for a moment");
		enchweapon();
		return;		/* enchant weapon */

	case 2:
		lprcat("\nYou have been granted enlightenment!");
		yh = min(playery + 7, MAXY);
		xh = min(playerx + 25, MAXX);
		yl = max(playery - 7, 0);
		xl = max(playerx - 25, 0);
		for (i = yl; i < yh; i++)
			for (j = xl; j < xh; j++)
				know[j][i] = 1;
		nap(2000);
		draws(xl, xh, yl, yh);
		return;

	case 3:
		lprcat("\nThis scroll seems to be blank");
		return;

	case 4:
		createmonster(makemonst(level + 1));
		return;		/* this one creates a monster  */

	case 5:
		something(level);	/* create artifact		 */
		return;

	case 6:
		c[AGGRAVATE] += 800;
		return;		/* aggravate monsters */

	case 7:
		gltime += (i = rnd(1000) - 850);	/* time warp */
		if (i >= 0)
			lprintf("\nYou went forward in time by %ld mobuls", (long) ((i + 99) / 100));
		else
			lprintf("\nYou went backward in time by %ld mobuls", (long) (-(i + 99) / 100));
		adjusttime((long) i);	/* adjust time for time warping */
		return;

	case 8:
		oteleport(0);
		return;		/* teleportation */

	case 9:
		c[AWARENESS] += 1800;
		return;		/* expanded awareness	 */

	case 10:
		c[HASTEMONST] += rnd(55) + 12;
		return;		/* haste monster */

	case 11:
		for (i = 0; i < MAXY; i++)
			for (j = 0; j < MAXX; j++)
				if (mitem[j][i])
					hitp[j][i] = monster[mitem[j][i]].hitpoints;
		return;		/* monster healing */
	case 12:
		c[SPIRITPRO] += 300 + rnd(200);
		bottomline();
		return;		/* spirit protection */

	case 13:
		c[UNDEADPRO] += 300 + rnd(200);
		bottomline();
		return;		/* undead protection */

	case 14:
		c[STEALTH] += 250 + rnd(250);
		bottomline();
		return;		/* stealth */

	case 15:
		lprcat("\nYou have been granted enlightenment!");	/* magic mapping */
		for (i = 0; i < MAXY; i++)
			for (j = 0; j < MAXX; j++)
				know[j][i] = 1;
		nap(2000);
		draws(0, MAXX, 0, MAXY);
		return;

	case 16:
		c[HOLDMONST] += 30;
		bottomline();
		return;		/* hold monster */

	case 17:
		for (i = 0; i < 26; i++)	/* gem perfection */
			switch (iven[i]) {
			case ODIAMOND:
			case ORUBY:
			case OEMERALD:
			case OSAPPHIRE:
				j = ivenarg[i];
				j &= 255;
				j <<= 1;
				if (j > 255)
					j = 255;	/* double value */
				ivenarg[i] = j;
				break;
			}
		break;

	case 18:
		for (i = 0; i < 11; i++)
			c[exten[i]] <<= 1;	/* spell extension */
		break;

	case 19:
		for (i = 0; i < 26; i++) {	/* identify */
			if (iven[i] == OPOTION)
				potionname[ivenarg[i]] = potionhide[ivenarg[i]];
			if (iven[i] == OSCROLL)
				scrollname[ivenarg[i]] = scrollhide[ivenarg[i]];
		}
		break;

	case 20:
		for (i = 0; i < 10; i++)	/* remove curse */
			if (c[curse[i]])
				c[curse[i]] = 1;
		break;

	case 21:
		annihilate();
		break;		/* scroll of annihilation */

	case 22:
		godirect(22, 150, "The ray hits the %s", 0, ' ');	/* pulverization */
		break;
	case 23:
		c[LIFEPROT]++;
		break;		/* life protection */
	};
}



static void
oorb(void)
{
}

static void
opit(void)
{
	int    i;
	if (rnd(101) < 81) {
		if (rnd(70) > 9 * c[DEXTERITY] - packweight() || rnd(101) < 5) {
			if (level == MAXLEVEL - 1)
				obottomless();
			else if (level == MAXLEVEL + MAXVLEVEL - 1)
				obottomless();
			else {
				if (rnd(101) < 20) {
					i = 0;
					lprcat("\nYou fell into a pit!  Your fall is cushioned by an unknown force\n");
				} else {
					i = rnd(level * 3 + 3);
					lprintf("\nYou fell into a pit!  You suffer %ld hit points damage", (long) i);
					lastnum = 261;	/* if he dies scoreboard
							 * will say so */
				}
				losehp(i);
				nap(2000);
				newcavelevel(level + 1);
				draws(0, MAXX, 0, MAXY);
			}
		}
	}
}

static void
obottomless(void)
{
	lprcat("\nYou fell into a bottomless pit!");
	beep();
	nap(3000);
	died(262);
}

static void
oelevator(int dir)
{
#ifdef lint
	int             x;
	x = dir;
	dir = x;
#endif	/* lint */
}

static void
ostatue(void)
{
}

static void
omirror(void)
{
}

static void
obook(void)
{
	lprcat("\nDo you ");
	if (c[BLINDCOUNT] == 0)
		lprcat("(r) read it, ");
	lprcat("(t) take it");
	iopts();
	while (1)
		switch (ttgetch()) {
		case '\33':
		case 'i':
			ignore();
			return;

		case 'r':
			if (c[BLINDCOUNT])
				break;
			lprcat("read");
			 /* no more book	 */ readbook(iarg[playerx][playery]);
			forget();
			return;

		case 't':
			lprcat("take");
			if (take(OBOOK, iarg[playerx][playery]) == 0)
				forget();	/* no more book	 */
			return;
		};
}

/*
	function to read a book
 */
void
readbook(int lev)
{
	int    i, tmp;
	if (lev <= 3)
		i = rund((tmp = splev[lev]) ? tmp : 1);
	else
		i = rnd((tmp = splev[lev] - 9) ? tmp : 1) + 9;
	spelknow[i] = 1;
	lprintf("\nSpell \"%s\":  %s\n%s", spelcode[i], spelname[i], speldescript[i]);
	if (rnd(10) == 4) {
		lprcat("\nYour int went up by one!");
		c[INTELLIGENCE]++;
		bottomline();
	}
}

static void
ocookie(void)
{
	const char *p;

	lprcat("\nDo you (e) eat it, (t) take it");
	iopts();
	while (1)
		switch (ttgetch()) {
		case '\33':
		case 'i':
			ignore();
			return;

		case 'e':
			lprcat("eat\nThe cookie tasted good.");
			forget();	/* no more cookie	 */
			if (c[BLINDCOUNT])
				return;
			if (!(p = fortune()))
				return;
			lprcat("  A message inside the cookie reads:\n");
			lprcat(p);
			return;

		case 't':
			lprcat("take");
			if (take(OCOOKIE, 0) == 0)
				forget();	/* no more book	 */
			return;
		};
}


/*
 * routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth
 * 100* the argument
 */
static void
ogold(int arg)
{
	long   i;
	i = iarg[playerx][playery];
	if (arg == OMAXGOLD)
		i *= 100;
	else if (arg == OKGOLD)
		i *= 1000;
	else if (arg == ODGOLD)
		i *= 10;
	lprintf("\nIt is worth %ld!", (long) i);
	c[GOLD] += i;
	bottomgold();
	item[playerx][playery] = know[playerx][playery] = 0;	/* destroy gold	 */
}

static void
ohome(void)
{
	int    i;
	nosignal = 1;		/* disable signals */
	for (i = 0; i < 26; i++)
		if (iven[i] == OPOTION)
			if (ivenarg[i] == 21) {
				iven[i] = 0;	/* remove the potion of cure
						 * dianthroritis from
						 * inventory */
				clear();
				lprcat("Congratulations.  You found a potion of cure dianthroritis.\n");
				lprcat("\nFrankly, No one thought you could do it.  Boy!  Did you surprise them!\n");
				if (gltime > TIMELIMIT) {
					lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
					lprcat("You didn't make it in time.  In your agony, you kill the doctor,\nyour wife, and yourself!  Too bad!\n");
					nap(5000);
					died(269);
				} else {
					lprcat("\nThe doctor is now administering the potion, and in a few moments\n");
					lprcat("Your daughter should be well on her way to recovery.\n");
					nap(6000);
					lprcat("\nThe potion is");
					nap(3000);
					lprcat(" working!  The doctor thinks that\n");
					lprcat("your daughter will recover in a few days.  Congratulations!\n");
					beep();
					nap(5000);
					died(263);
				}
			}
	while (1) {
		clear();
		lprintf("Welcome home %s.  Latest word from the doctor is not good.\n", logname);

		if (gltime > TIMELIMIT) {
			lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
			lprcat("You didn't make it in time.  In your agony, you kill the doctor,\nyour wife, and yourself!  Too bad!\n");
			nap(5000);
			died(269);
		}
		lprcat("\nThe diagnosis is confirmed as dianthroritis.  He guesses that\n");
		lprintf("your daughter has only %ld mobuls left in this world.  It's up to you,\n", (long) ((TIMELIMIT - gltime + 99) / 100));
		lprintf("%s, to find the only hope for your daughter, the very rare\n", logname);
		lprcat("potion of cure dianthroritis.  It is rumored that only deep in the\n");
		lprcat("depths of the caves can this potion be found.\n\n\n");
		lprcat("\n     ----- press ");
		standout("return");
		lprcat(" to continue, ");
		standout("escape");
		lprcat(" to leave ----- ");
		i = ttgetch();
		while (i != '\33' && i != '\n')
			i = ttgetch();
		if (i == '\33') {
			drawscreen();
			nosignal = 0;	/* enable signals */
			return;
		}
	}
}

/* routine to save program space	 */
void
iopts(void)
{
	lprcat(", or (i) ignore it? ");
}

void
ignore(void)
{
	lprcat("ignore\n");
}