xref: /netbsd/games/larn/store.c (revision bf9ec67e)
1 /*	$NetBSD: store.c,v 1.8 2001/02/05 00:57:34 christos Exp $	 */
2 
3 /*-
4  * Copyright (c) 1988 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char     sccsid[] = "@(#)store.c	5.4 (Berkeley) 5/13/91";
40 #else
41 __RCSID("$NetBSD: store.c,v 1.8 2001/02/05 00:57:34 christos Exp $");
42 #endif
43 #endif				/* not lint */
44 
45 /* store.c		Larn is copyrighted 1986 by Noah Morgan. */
46 #include "header.h"
47 #include "extern.h"
48 
49 static void handsfull __P((void));
50 static void outofstock __P((void));
51 static void nogold __P((void));
52 static void dnditem __P((int));
53 static void banktitle __P((char *));
54 static void otradhead __P((void));
55 
56 static int      dndcount = 0, dnditm = 0;
57 
58 /* this is the data for the stuff in the dnd store	 */
59 int             maxitm = 83;	/* number of items in the dnd inventory table	 */
60 struct _itm     itm[90] = {
61 	/*
62 	 * cost 		iven name		iven arg   how gp
63 	 * iven[]		ivenarg[]  many
64 	 */
65 
66 	{2, OLEATHER, 0, 3},
67 	{10, OSTUDLEATHER, 0, 2},
68 	{40, ORING, 0, 2},
69 	{85, OCHAIN, 0, 2},
70 	{220, OSPLINT, 0, 1},
71 	{400, OPLATE, 0, 1},
72 	{900, OPLATEARMOR, 0, 1},
73 	{2600, OSSPLATE, 0, 1},
74 	{150, OSHIELD, 0, 1},
75 
76 	/*
77 	 * cost	 	iven name		iven arg   how gp
78 	 * iven[]		ivenarg[]  many
79 	 */
80 
81 	{2, ODAGGER, 0, 3},
82 	{20, OSPEAR, 0, 3},
83 	{80, OFLAIL, 0, 2},
84 	{150, OBATTLEAXE, 0, 2},
85 	{450, OLONGSWORD, 0, 2},
86 	{1000, O2SWORD, 0, 2},
87 	{5000, OSWORD, 0, 1},
88 	{16500, OLANCE, 0, 1},
89 	{6000, OSWORDofSLASHING, 0, 0},
90 	{10000, OHAMMER, 0, 0},
91 
92 	/*
93 	 * cost		iven name		iven arg   how gp
94 	 * iven[]		ivenarg[]  many
95 	 */
96 
97 	{150, OPROTRING, 1, 1},
98 	{85, OSTRRING, 1, 1},
99 	{120, ODEXRING, 1, 1},
100 	{120, OCLEVERRING, 1, 1},
101 	{180, OENERGYRING, 0, 1},
102 	{125, ODAMRING, 0, 1},
103 	{220, OREGENRING, 0, 1},
104 	{1000, ORINGOFEXTRA, 0, 1},
105 
106 	{280, OBELT, 0, 1},
107 
108 	{400, OAMULET, 0, 1},
109 
110 	{6500, OORBOFDRAGON, 0, 0},
111 	{5500, OSPIRITSCARAB, 0, 0},
112 	{5000, OCUBEofUNDEAD, 0, 0},
113 	{6000, ONOTHEFT, 0, 0},
114 
115 	{590, OCHEST, 6, 1},
116 	{200, OBOOK, 8, 1},
117 	{10, OCOOKIE, 0, 3},
118 
119 	/*
120 	 * cost		iven name		iven arg   how gp
121 	 * iven[]		ivenarg[]  many
122 	 */
123 
124 	{20, OPOTION, 0, 6},
125 	{90, OPOTION, 1, 5},
126 	{520, OPOTION, 2, 1},
127 	{100, OPOTION, 3, 2},
128 	{50, OPOTION, 4, 2},
129 	{150, OPOTION, 5, 2},
130 	{70, OPOTION, 6, 1},
131 	{30, OPOTION, 7, 7},
132 	{200, OPOTION, 8, 1},
133 	{50, OPOTION, 9, 1},
134 	{80, OPOTION, 10, 1},
135 
136 	/*
137 	 * cost		iven name		iven arg   how gp
138 	 * iven[]		ivenarg[]  many
139 	 */
140 
141 	{30, OPOTION, 11, 3},
142 	{20, OPOTION, 12, 5},
143 	{40, OPOTION, 13, 3},
144 	{35, OPOTION, 14, 2},
145 	{520, OPOTION, 15, 1},
146 	{90, OPOTION, 16, 2},
147 	{200, OPOTION, 17, 2},
148 	{220, OPOTION, 18, 4},
149 	{80, OPOTION, 19, 6},
150 	{370, OPOTION, 20, 3},
151 	{50, OPOTION, 22, 1},
152 	{150, OPOTION, 23, 3},
153 
154 	/*
155 	 * cost		iven name		iven arg   how gp
156 	 * iven[]		ivenarg[]  many
157 	 */
158 
159 	{100, OSCROLL, 0, 2},
160 	{125, OSCROLL, 1, 2},
161 	{60, OSCROLL, 2, 4},
162 	{10, OSCROLL, 3, 4},
163 	{100, OSCROLL, 4, 3},
164 	{200, OSCROLL, 5, 2},
165 	{110, OSCROLL, 6, 1},
166 	{500, OSCROLL, 7, 2},
167 	{200, OSCROLL, 8, 2},
168 	{250, OSCROLL, 9, 4},
169 	{20, OSCROLL, 10, 5},
170 	{30, OSCROLL, 11, 3},
171 
172 	/*
173 	 * cost 		iven name		iven arg   how gp
174 	 * iven[]		ivenarg[]  many
175 	 */
176 
177 	{340, OSCROLL, 12, 1},
178 	{340, OSCROLL, 13, 1},
179 	{300, OSCROLL, 14, 2},
180 	{400, OSCROLL, 15, 2},
181 	{500, OSCROLL, 16, 2},
182 	{1000, OSCROLL, 17, 1},
183 	{500, OSCROLL, 18, 1},
184 	{340, OSCROLL, 19, 2},
185 	{220, OSCROLL, 20, 3},
186 	{3900, OSCROLL, 21, 0},
187 	{610, OSCROLL, 22, 1},
188 	{3000, OSCROLL, 23, 0}
189 };
190 
191 /*
192 	function for the dnd store
193  */
194 void
195 dnd_2hed()
196 {
197 	lprcat("Welcome to the Larn Thrift Shoppe.  We stock many items explorers find useful\n");
198 	lprcat(" in their adventures.  Feel free to browse to your hearts content.\n");
199 	lprcat("Also be advised, if you break 'em, you pay for 'em.");
200 }
201 
202 void
203 dnd_hed()
204 {
205 	int    i;
206 	for (i = dnditm; i < 26 + dnditm; i++)
207 		dnditem(i);
208 	cursor(50, 18);
209 	lprcat("You have ");
210 }
211 
212 static void
213 handsfull()
214 {
215 	lprcat("\nYou can't carry anything more!");
216 	lflush();
217 	nap(2200);
218 }
219 
220 static void
221 outofstock()
222 {
223 	lprcat("\nSorry, but we are out of that item.");
224 	lflush();
225 	nap(2200);
226 }
227 
228 static void
229 nogold()
230 {
231 	lprcat("\nYou don't have enough gold to pay for that!");
232 	lflush();
233 	nap(2200);
234 }
235 
236 void
237 dndstore()
238 {
239 	int    i;
240 	dnditm = 0;
241 	nosignal = 1;		/* disable signals */
242 	clear();
243 	dnd_2hed();
244 	if (outstanding_taxes > 0) {
245 		lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n");
246 		beep();
247 		lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n", (long) outstanding_taxes);
248 		lprcat("comply with the law, we cannot serve you at this time.  Soo Sorry.\n");
249 		cursors();
250 		lprcat("\nPress ");
251 		standout("escape");
252 		lprcat(" to leave: ");
253 		lflush();
254 		i = 0;
255 		while (i != '\33')
256 			i = lgetchar();
257 		drawscreen();
258 		nosignal = 0;	/* enable signals */
259 		return;
260 	}
261 	dnd_hed();
262 	while (1) {
263 		cursor(59, 18);
264 		lprintf("%d gold pieces", (long) c[GOLD]);
265 		cltoeoln();
266 		cl_dn(1, 20);	/* erase to eod */
267 		lprcat("\nEnter your transaction [");
268 		standout("space");
269 		lprcat(" for more, ");
270 		standout("escape");
271 		lprcat(" to leave]? ");
272 		i = 0;
273 		while ((i < 'a' || i > 'z') && (i != ' ') && (i != '\33') && (i != 12))
274 			i = lgetchar();
275 		if (i == 12) {
276 			clear();
277 			dnd_2hed();
278 			dnd_hed();
279 		} else if (i == '\33') {
280 			drawscreen();
281 			nosignal = 0;	/* enable signals */
282 			return;
283 		} else if (i == ' ') {
284 			cl_dn(1, 4);
285 			if ((dnditm += 26) >= maxitm)
286 				dnditm = 0;
287 			dnd_hed();
288 		} else {	/* buy something */
289 			lprc(i);/* echo the byte */
290 			i += dnditm - 'a';
291 			if (i >= maxitm)
292 				outofstock();
293 			else if (itm[i].qty <= 0)
294 				outofstock();
295 			else if (pocketfull())
296 				handsfull();
297 			else if (c[GOLD] < itm[i].price * 10)
298 				nogold();
299 			else {
300 				if (itm[i].obj == OPOTION) {
301 					potionname[itm[i].arg] = potionhide[itm[i].arg];
302 				} else if (itm[i].obj == OSCROLL) {
303 					scrollname[itm[i].arg] = scrollhide[itm[i].arg];
304 				}
305 				c[GOLD] -= itm[i].price * 10;
306 				itm[i].qty--;
307 				take(itm[i].obj, itm[i].arg);
308 				if (itm[i].qty == 0)
309 					dnditem(i);
310 				nap(1001);
311 			}
312 		}
313 
314 	}
315 }
316 
317 /*
318 	dnditem(index)
319 
320 	to print the item list;  used in dndstore() enter with the index into itm
321  */
322 static void
323 dnditem(i)
324 	int    i;
325 {
326 	int    j, k;
327 	if (i >= maxitm)
328 		return;
329 	cursor((j = (i & 1) * 40 + 1), (k = ((i % 26) >> 1) + 5));
330 	if (itm[i].qty == 0) {
331 		lprintf("%39s", "");
332 		return;
333 	}
334 	lprintf("%c) ", (i % 26) + 'a');
335 	if (itm[i].obj == OPOTION) {
336 		lprintf("potion of%s", potionhide[itm[i].arg]);
337 	} else if (itm[i].obj == OSCROLL) {
338 		lprintf("scroll of%s", scrollhide[itm[i].arg]);
339 	} else
340 		lprintf("%s", objectname[itm[i].obj]);
341 	cursor(j + 31, k);
342 	lprintf("%6d", (long) (itm[i].price * 10));
343 }
344 
345 
346 
347 /*
348 	for the college of larn
349  */
350 u_char          course[26] = {0};	/* the list of courses taken	 */
351 char            coursetime[] = {10, 15, 10, 20, 10, 10, 10, 5};
352 /*
353 	function to display the header info for the school
354  */
355 void
356 sch_hed()
357 {
358 	clear();
359 	lprcat("The College of Larn offers the exciting opportunity of higher education to\n");
360 	lprcat("all inhabitants of the caves.  Here is a list of the class schedule:\n\n\n");
361 	lprcat("\t\t    Course Name \t       Time Needed\n\n");
362 
363 	if (course[0] == 0)
364 		lprcat("\t\ta)  Fighters Training I         10 mobuls");	/* line 7 of crt */
365 	lprc('\n');
366 	if (course[1] == 0)
367 		lprcat("\t\tb)  Fighters Training II        15 mobuls");
368 	lprc('\n');
369 	if (course[2] == 0)
370 		lprcat("\t\tc)  Introduction to Wizardry    10 mobuls");
371 	lprc('\n');
372 	if (course[3] == 0)
373 		lprcat("\t\td)  Applied Wizardry            20 mobuls");
374 	lprc('\n');
375 	if (course[4] == 0)
376 		lprcat("\t\te)  Behavioral Psychology       10 mobuls");
377 	lprc('\n');
378 	if (course[5] == 0)
379 		lprcat("\t\tf)  Faith for Today             10 mobuls");
380 	lprc('\n');
381 	if (course[6] == 0)
382 		lprcat("\t\tg)  Contemporary Dance          10 mobuls");
383 	lprc('\n');
384 	if (course[7] == 0)
385 		lprcat("\t\th)  History of Larn              5 mobuls");
386 
387 	lprcat("\n\n\t\tAll courses cost 250 gold pieces.");
388 	cursor(30, 18);
389 	lprcat("You are presently carrying ");
390 }
391 
392 void
393 oschool()
394 {
395 	int    i;
396 	long            time_used;
397 	nosignal = 1;		/* disable signals */
398 	sch_hed();
399 	while (1) {
400 		cursor(57, 18);
401 		lprintf("%d gold pieces.   ", (long) c[GOLD]);
402 		cursors();
403 		lprcat("\nWhat is your choice [");
404 		standout("escape");
405 		lprcat(" to leave] ? ");
406 		yrepcount = 0;
407 		i = 0;
408 		while ((i < 'a' || i > 'h') && (i != '\33') && (i != 12))
409 			i = lgetchar();
410 		if (i == 12) {
411 			sch_hed();
412 			continue;
413 		} else if (i == '\33') {
414 			nosignal = 0;
415 			drawscreen();	/* enable signals */
416 			return;
417 		}
418 		lprc(i);
419 		if (c[GOLD] < 250)
420 			nogold();
421 		else if (course[i - 'a']) {
422 			lprcat("\nSorry, but that class is filled.");
423 			nap(1000);
424 		} else if (i <= 'h') {
425 			c[GOLD] -= 250;
426 			time_used = 0;
427 			switch (i) {
428 			case 'a':
429 				c[STRENGTH] += 2;
430 				c[CONSTITUTION]++;
431 				lprcat("\nYou feel stronger!");
432 				cl_line(16, 7);
433 				break;
434 
435 			case 'b':
436 				if (course[0] == 0) {
437 					lprcat("\nSorry, but this class has a prerequisite of Fighters Training I");
438 					c[GOLD] += 250;
439 					time_used = -10000;
440 					break;
441 				}
442 				lprcat("\nYou feel much stronger!");
443 				cl_line(16, 8);
444 				c[STRENGTH] += 2;
445 				c[CONSTITUTION] += 2;
446 				break;
447 
448 			case 'c':
449 				c[INTELLIGENCE] += 2;
450 				lprcat("\nThe task before you now seems more attainable!");
451 				cl_line(16, 9);
452 				break;
453 
454 			case 'd':
455 				if (course[2] == 0) {
456 					lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry");
457 					c[GOLD] += 250;
458 					time_used = -10000;
459 					break;
460 				}
461 				lprcat("\nThe task before you now seems very attainable!");
462 				cl_line(16, 10);
463 				c[INTELLIGENCE] += 2;
464 				break;
465 
466 			case 'e':
467 				c[CHARISMA] += 3;
468 				lprcat("\nYou now feel like a born leader!");
469 				cl_line(16, 11);
470 				break;
471 
472 			case 'f':
473 				c[WISDOM] += 2;
474 				lprcat("\nYou now feel more confident that you can find the potion in time!");
475 				cl_line(16, 12);
476 				break;
477 
478 			case 'g':
479 				c[DEXTERITY] += 3;
480 				lprcat("\nYou feel like dancing!");
481 				cl_line(16, 13);
482 				break;
483 
484 			case 'h':
485 				c[INTELLIGENCE]++;
486 				lprcat("\nYour instructor told you that the Eye of Larn is rumored to be guarded\n");
487 				lprcat("by a platinum dragon who possesses psionic abilities. ");
488 				cl_line(16, 14);
489 				break;
490 			}
491 			time_used += coursetime[i - 'a'] * 100;
492 			if (time_used > 0) {
493 				gltime += time_used;
494 				course[i - 'a']++;	/* remember that he has
495 							 * taken that course	 */
496 				c[HP] = c[HPMAX];
497 				c[SPELLS] = c[SPELLMAX];	/* he regenerated */
498 
499 				if (c[BLINDCOUNT])
500 					c[BLINDCOUNT] = 1;	/* cure blindness too!  */
501 				if (c[CONFUSE])
502 					c[CONFUSE] = 1;	/* end confusion	 */
503 				adjusttime((long) time_used);	/* adjust parameters for
504 								 * time change */
505 			}
506 			nap(1000);
507 		}
508 	}
509 }
510 
511 
512 /*
513  *	for the first national bank of Larn
514  */
515 int             lasttime = 0;	/* last time he was in bank */
516 
517 void
518 obank()
519 {
520 	banktitle("    Welcome to the First National Bank of Larn.");
521 }
522 void
523 obank2()
524 {
525 	banktitle("Welcome to the 5th level branch office of the First National Bank of Larn.");
526 }
527 static void
528 banktitle(str)
529 	char           *str;
530 {
531 	nosignal = 1;		/* disable signals */
532 	clear();
533 	lprcat(str);
534 	if (outstanding_taxes > 0) {
535 		int    i;
536 		lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n");
537 		beep();
538 		lprintf("levied taxes have been paid.  They have also told us that you owe %d gp in\n", (long) outstanding_taxes);
539 		lprcat("taxes, and we must comply with them. We cannot serve you at this time.  Sorry.\n");
540 		lprcat("We suggest you go to the LRS office and pay your taxes.\n");
541 		cursors();
542 		lprcat("\nPress ");
543 		standout("escape");
544 		lprcat(" to leave: ");
545 		lflush();
546 		i = 0;
547 		while (i != '\33')
548 			i = lgetchar();
549 		drawscreen();
550 		nosignal = 0;	/* enable signals */
551 		return;
552 	}
553 	lprcat("\n\n\tGemstone\t      Appraisal\t\tGemstone\t      Appraisal");
554 	obanksub();
555 	nosignal = 0;		/* enable signals */
556 	drawscreen();
557 }
558 
559 /*
560  *	function to put interest on your bank account
561  */
562 void
563 ointerest()
564 {
565 	int    i;
566 	if (c[BANKACCOUNT] < 0)
567 		c[BANKACCOUNT] = 0;
568 	else if ((c[BANKACCOUNT] > 0) && (c[BANKACCOUNT] < 500000)) {
569 		i = (gltime - lasttime) / 100;	/* # mobuls elapsed */
570 		while ((i-- > 0) && (c[BANKACCOUNT] < 500000))
571 			c[BANKACCOUNT] += c[BANKACCOUNT] / 250;
572 		if (c[BANKACCOUNT] > 500000)
573 			c[BANKACCOUNT] = 500000;	/* interest limit */
574 	}
575 	lasttime = (gltime / 100) * 100;
576 }
577 
578 static short    gemorder[26] = {0};	/* the reference to screen location
579 					 * for each */
580 static long     gemvalue[26] = {0};	/* the appraisal of the gems */
581 void
582 obanksub()
583 {
584 	unsigned long   amt;
585 	int    i, k;
586 	ointerest();		/* credit any needed interest */
587 
588 	for (k = i = 0; i < 26; i++)
589 		switch (iven[i]) {
590 		case OLARNEYE:
591 		case ODIAMOND:
592 		case OEMERALD:
593 		case ORUBY:
594 		case OSAPPHIRE:
595 
596 			if (iven[i] == OLARNEYE) {
597 				gemvalue[i] = 250000 - ((gltime * 7) / 100) * 100;
598 				if (gemvalue[i] < 50000)
599 					gemvalue[i] = 50000;
600 			} else
601 				gemvalue[i] = (255 & ivenarg[i]) * 100;
602 			gemorder[i] = k;
603 			cursor((k % 2) * 40 + 1, (k >> 1) + 4);
604 			lprintf("%c) %s", i + 'a', objectname[iven[i]]);
605 			cursor((k % 2) * 40 + 33, (k >> 1) + 4);
606 			lprintf("%5d", (long) gemvalue[i]);
607 			k++;
608 		};
609 	cursor(31, 17);
610 	lprintf("You have %8d gold pieces in the bank.", (long) c[BANKACCOUNT]);
611 	cursor(40, 18);
612 	lprintf("You have %8d gold pieces", (long) c[GOLD]);
613 	if (c[BANKACCOUNT] + c[GOLD] >= 500000)
614 		lprcat("\nNote:  Larndom law states that only deposits under 500,000gp  can earn interest.");
615 	while (1) {
616 		cl_dn(1, 20);
617 		lprcat("\nYour wish? [(");
618 		standout("d");
619 		lprcat(") deposit, (");
620 		standout("w");
621 		lprcat(") withdraw, (");
622 		standout("s");
623 		lprcat(") sell a stone, or ");
624 		standout("escape");
625 		lprcat("]  ");
626 		yrepcount = 0;
627 		i = 0;
628 		while (i != 'd' && i != 'w' && i != 's' && i != '\33')
629 			i = lgetchar();
630 		switch (i) {
631 		case 'd':
632 			lprcat("deposit\nHow much? ");
633 			amt = readnum((long) c[GOLD]);
634 			if (amt < 0) {
635 				lprcat("\nSorry, but we can't take negative gold!");
636 				nap(2000);
637 				amt = 0;
638 			} else if (amt > c[GOLD]) {
639 				lprcat("  You don't have that much.");
640 				nap(2000);
641 			} else {
642 				c[GOLD] -= amt;
643 				c[BANKACCOUNT] += amt;
644 			}
645 			break;
646 
647 		case 'w':
648 			lprcat("withdraw\nHow much? ");
649 			amt = readnum((long) c[BANKACCOUNT]);
650 			if (amt < 0) {
651 				lprcat("\nSorry, but we don't have any negative gold!");
652 				nap(2000);
653 				amt = 0;
654 			} else if (amt > c[BANKACCOUNT]) {
655 				lprcat("\nYou don't have that much in the bank!");
656 				nap(2000);
657 			} else {
658 				c[GOLD] += amt;
659 				c[BANKACCOUNT] -= amt;
660 			}
661 			break;
662 
663 		case 's':
664 			lprcat("\nWhich stone would you like to sell? ");
665 			i = 0;
666 			while ((i < 'a' || i > 'z') && i != '*')
667 				i = lgetchar();
668 			if (i == '*')
669 				for (i = 0; i < 26; i++) {
670 					if (gemvalue[i]) {
671 						c[GOLD] += gemvalue[i];
672 						iven[i] = 0;
673 						gemvalue[i] = 0;
674 						k = gemorder[i];
675 						cursor((k % 2) * 40 + 1, (k >> 1) + 4);
676 						lprintf("%39s", "");
677 					}
678 				}
679 			else {
680 				if (gemvalue[i = i - 'a'] == 0) {
681 					lprintf("\nItem %c is not a gemstone!", i + 'a');
682 					nap(2000);
683 					break;
684 				}
685 				c[GOLD] += gemvalue[i];
686 				iven[i] = 0;
687 				gemvalue[i] = 0;
688 				k = gemorder[i];
689 				cursor((k % 2) * 40 + 1, (k >> 1) + 4);
690 				lprintf("%39s", "");
691 			}
692 			break;
693 
694 		case '\33':
695 			return;
696 		};
697 		cursor(40, 17);
698 		lprintf("%8d", (long) c[BANKACCOUNT]);
699 		cursor(49, 18);
700 		lprintf("%8d", (long) c[GOLD]);
701 	}
702 }
703 
704 /*
705 	subroutine to appraise any stone for the bank
706  */
707 void
708 appraise(gemstone)
709 	int    gemstone;
710 {
711 	int    j, amt;
712 	for (j = 0; j < 26; j++)
713 		if (iven[j] == gemstone) {
714 			lprintf("\nI see you have %s", objectname[gemstone]);
715 			if (gemstone == OLARNEYE)
716 				lprcat("  I must commend you.  I didn't think\nyou could get it.");
717 			lprcat("  Shall I appraise it for you? ");
718 			yrepcount = 0;
719 			if (getyn() == 'y') {
720 				lprcat("yes.\n  Just one moment please \n");
721 				nap(1000);
722 				if (gemstone == OLARNEYE) {
723 					amt = 250000 - ((gltime * 7) / 100) * 100;
724 					if (amt < 50000)
725 						amt = 50000;
726 				} else
727 					amt = (255 & ivenarg[j]) * 100;
728 				lprintf("\nI can see this is an excellent stone, It is worth %d", (long) amt);
729 				lprcat("\nWould you like to sell it to us? ");
730 				yrepcount = 0;
731 				if (getyn() == 'y') {
732 					lprcat("yes\n");
733 					c[GOLD] += amt;
734 					iven[j] = 0;
735 				} else
736 					lprcat("no thank you.\n");
737 				if (gemstone == OLARNEYE)
738 					lprcat("It is, of course, your privilege to keep the stone\n");
739 			} else
740 				lprcat("no\nO. K.\n");
741 		}
742 }
743 /*
744 	function for the trading post
745  */
746 static void
747 otradhead()
748 {
749 	clear();
750 	lprcat("Welcome to the Larn Trading Post.  We buy items that explorers no longer find\n");
751 	lprcat("useful.  Since the condition of the items you bring in is not certain,\n");
752 	lprcat("and we incur great expense in reconditioning the items, we usually pay\n");
753 	lprcat("only 20% of their value were they to be new.  If the items are badly\n");
754 	lprcat("damaged, we will pay only 10% of their new value.\n\n");
755 }
756 
757 void
758 otradepost()
759 {
760 	int    i, j, value, isub, izarg;
761 	dnditm = dndcount = 0;
762 	nosignal = 1;		/* disable signals */
763 	resetscroll();
764 	otradhead();
765 	while (1) {
766 		lprcat("\nWhat item do you want to sell to us [");
767 		standout("*");
768 		lprcat(" for list, or ");
769 		standout("escape");
770 		lprcat("] ? ");
771 		i = 0;
772 		while (i > 'z' || (i < 'a' && i != '*' && i != '\33' && i != '.'))
773 			i = lgetchar();
774 		if (i == '\33') {
775 			setscroll();
776 			recalc();
777 			drawscreen();
778 			nosignal = 0;	/* enable signals */
779 			return;
780 		}
781 		isub = i - 'a';
782 		j = 0;
783 		if (iven[isub] == OSCROLL)
784 			if (scrollname[ivenarg[isub]][0] == 0) {
785 				j = 1;
786 				cnsitm();
787 			}	/* can't sell unidentified item */
788 		if (iven[isub] == OPOTION)
789 			if (potionname[ivenarg[isub]][0] == 0) {
790 				j = 1;
791 				cnsitm();
792 			}	/* can't sell unidentified item */
793 		if (!j) {
794 			if (i == '*') {
795 				clear();
796 				qshowstr();
797 				otradhead();
798 			} else if (iven[isub] == 0)
799 				lprintf("\nYou don't have item %c!", isub + 'a');
800 			else {
801 				for (j = 0; j < maxitm; j++)
802 					if ((itm[j].obj == iven[isub]) || (iven[isub] == ODIAMOND) || (iven[isub] == ORUBY) || (iven[isub] == OEMERALD) || (iven[isub] == OSAPPHIRE)) {
803 						srcount = 0;
804 						show3(isub);	/* show what the item
805 								 * was */
806 						if ((iven[isub] == ODIAMOND) || (iven[isub] == ORUBY)
807 						    || (iven[isub] == OEMERALD) || (iven[isub] == OSAPPHIRE))
808 							value = 20 * ivenarg[isub];
809 						else if ((itm[j].obj == OSCROLL) || (itm[j].obj == OPOTION))
810 							value = 2 * itm[j + ivenarg[isub]].price;
811 						else {
812 							izarg = ivenarg[isub];
813 							value = itm[j].price;	/* appreciate if a +n
814 										 * object */
815 							if (izarg >= 0)
816 								value *= 2;
817 							while ((izarg-- > 0) && ((value = 14 * (67 + value) / 10) < 500000));
818 						}
819 						lprintf("\nItem (%c) is worth %d gold pieces to us.  Do you want to sell it? ", i, (long) value);
820 						yrepcount = 0;
821 						if (getyn() == 'y') {
822 							lprcat("yes\n");
823 							c[GOLD] += value;
824 							if (c[WEAR] == isub)
825 								c[WEAR] = -1;
826 							if (c[WIELD] == isub)
827 								c[WIELD] = -1;
828 							if (c[SHIELD] == isub)
829 								c[SHIELD] = -1;
830 							adjustcvalues(iven[isub], ivenarg[isub]);
831 							iven[isub] = 0;
832 						} else
833 							lprcat("no thanks.\n");
834 						j = maxitm + 100;	/* get out of the inner
835 									 * loop */
836 					}
837 				if (j <= maxitm + 2)
838 					lprcat("\nSo sorry, but we are not authorized to accept that item.");
839 			}
840 		}
841 	}
842 }
843 
844 void
845 cnsitm()
846 {
847 	lprcat("\nSorry, we can't accept unidentified objects.");
848 }
849 
850 /*
851  *	for the Larn Revenue Service
852  */
853 void
854 olrs()
855 {
856 	int    i, first;
857 	unsigned long   amt;
858 	first = nosignal = 1;	/* disable signals */
859 	clear();
860 	resetscroll();
861 	cursor(1, 4);
862 	lprcat("Welcome to the Larn Revenue Service district office.  How can we help you?");
863 	while (1) {
864 		if (first) {
865 			first = 0;
866 			goto nxt;
867 		}
868 		cursors();
869 		lprcat("\n\nYour wish? [(");
870 		standout("p");
871 		lprcat(") pay taxes, or ");
872 		standout("escape");
873 		lprcat("]  ");
874 		yrepcount = 0;
875 		i = 0;
876 		while (i != 'p' && i != '\33')
877 			i = lgetchar();
878 		switch (i) {
879 		case 'p':
880 			lprcat("pay taxes\nHow much? ");
881 			amt = readnum((long) c[GOLD]);
882 			if (amt < 0) {
883 				lprcat("\nSorry, but we can't take negative gold\n");
884 				amt = 0;
885 			} else if (amt > c[GOLD])
886 				lprcat("  You don't have that much.\n");
887 			else
888 				c[GOLD] -= paytaxes((long) amt);
889 			break;
890 
891 		case '\33':
892 			nosignal = 0;	/* enable signals */
893 			setscroll();
894 			drawscreen();
895 			return;
896 		};
897 
898 nxt:		cursor(1, 6);
899 		if (outstanding_taxes > 0)
900 			lprintf("You presently owe %d gp in taxes.  ", (long) outstanding_taxes);
901 		else
902 			lprcat("You do not owe us any taxes.           ");
903 		cursor(1, 8);
904 		if (c[GOLD] > 0)
905 			lprintf("You have %6d gp.    ", (long) c[GOLD]);
906 		else
907 			lprcat("You have no gold pieces.  ");
908 	}
909 }
910