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