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