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