1 /* $NetBSD: store.c,v 1.14 2008/02/03 21:24:59 dholland Exp $ */
4 * Copyright (c) 1988 The Regents of the University of California.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)store.c 5.4 (Berkeley) 5/13/91";
37 __RCSID("$NetBSD: store.c,v 1.14 2008/02/03 21:24:59 dholland Exp $");
41 /* store.c Larn is copyrighted 1986 by Noah Morgan. */
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 obanksub(void);
51 static void otradhead(void);
52 static void cnsitm(void);
54 static int dndcount
= 0, dnditm
= 0;
56 /* number of items in the dnd inventory table */
59 /* this is the data for the stuff in the dnd store */
60 struct _itm itm
[90] = {
62 * cost iven name iven arg how gp
63 * iven[] ivenarg[] many
67 {10, OSTUDLEATHER
, 0, 2},
72 {900, OPLATEARMOR
, 0, 1},
73 {2600, OSSPLATE
, 0, 1},
77 * cost iven name iven arg how gp
78 * iven[] ivenarg[] many
84 {150, OBATTLEAXE
, 0, 2},
85 {450, OLONGSWORD
, 0, 2},
86 {1000, O2SWORD
, 0, 2},
88 {16500, OLANCE
, 0, 1},
89 {6000, OSWORDofSLASHING
, 0, 0},
90 {10000, OHAMMER
, 0, 0},
93 * cost iven name iven arg how gp
94 * iven[] ivenarg[] many
97 {150, OPROTRING
, 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},
108 {400, OAMULET
, 0, 1},
110 {6500, OORBOFDRAGON
, 0, 0},
111 {5500, OSPIRITSCARAB
, 0, 0},
112 {5000, OCUBEofUNDEAD
, 0, 0},
113 {6000, ONOTHEFT
, 0, 0},
120 * cost iven name iven arg how gp
121 * iven[] ivenarg[] many
126 {520, OPOTION
, 2, 1},
127 {100, OPOTION
, 3, 2},
129 {150, OPOTION
, 5, 2},
132 {200, OPOTION
, 8, 1},
134 {80, OPOTION
, 10, 1},
137 * cost iven name iven arg how gp
138 * iven[] ivenarg[] many
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},
155 * cost iven name iven arg how gp
156 * iven[] ivenarg[] many
159 {100, OSCROLL
, 0, 2},
160 {125, OSCROLL
, 1, 2},
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},
173 * cost iven name iven arg how gp
174 * iven[] ivenarg[] many
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}
192 function for the dnd store
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.");
206 for (i
= dnditm
; i
< 26 + dnditm
; i
++)
215 lprcat("\nYou can't carry anything more!");
223 lprcat("\nSorry, but we are out of that item.");
231 lprcat("\nYou don't have enough gold to pay for that!");
241 nosignal
= 1; /* disable signals */
244 if (outstanding_taxes
> 0) {
245 lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n");
247 lprintf("They have also told us that you owe %ld 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");
252 lprcat(" to leave: ");
258 nosignal
= 0; /* enable signals */
264 lprintf("%ld gold pieces", (long) c
[GOLD
]);
266 cl_dn(1, 20); /* erase to eod */
267 lprcat("\nEnter your transaction [");
269 lprcat(" for more, ");
271 lprcat(" to leave]? ");
273 while ((i
< 'a' || i
> 'z') && (i
!= ' ') && (i
!= '\33') && (i
!= 12))
279 } else if (i
== '\33') {
281 nosignal
= 0; /* enable signals */
283 } else if (i
== ' ') {
285 if ((dnditm
+= 26) >= MAXITM
)
288 } else { /* buy something */
289 lprc(i
);/* echo the byte */
293 else if (itm
[i
].qty
<= 0)
295 else if (pocketfull())
297 else if (c
[GOLD
] < itm
[i
].price
* 10)
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
];
305 c
[GOLD
] -= itm
[i
].price
* 10;
307 take(itm
[i
].obj
, itm
[i
].arg
);
320 to print the item list; used in dndstore() enter with the index into itm
329 cursor((j
= (i
& 1) * 40 + 1), (k
= ((i
% 26) >> 1) + 5));
330 if (itm
[i
].qty
== 0) {
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
]);
340 lprintf("%s", objectname
[itm
[i
].obj
]);
342 lprintf("%6ld", (long) (itm
[i
].price
* 10));
348 for the college of larn
350 u_char course
[26] = {0}; /* the list of courses taken */
351 static char coursetime
[] = {10, 15, 10, 20, 10, 10, 10, 5};
353 function to display the header info for the school
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");
364 lprcat("\t\ta) Fighters Training I 10 mobuls"); /* line 7 of crt */
367 lprcat("\t\tb) Fighters Training II 15 mobuls");
370 lprcat("\t\tc) Introduction to Wizardry 10 mobuls");
373 lprcat("\t\td) Applied Wizardry 20 mobuls");
376 lprcat("\t\te) Behavioral Psychology 10 mobuls");
379 lprcat("\t\tf) Faith for Today 10 mobuls");
382 lprcat("\t\tg) Contemporary Dance 10 mobuls");
385 lprcat("\t\th) History of Larn 5 mobuls");
387 lprcat("\n\n\t\tAll courses cost 250 gold pieces.");
389 lprcat("You are presently carrying ");
397 nosignal
= 1; /* disable signals */
401 lprintf("%ld gold pieces. ", (long) c
[GOLD
]);
403 lprcat("\nWhat is your choice [");
405 lprcat(" to leave] ? ");
408 while ((i
< 'a' || i
> 'h') && (i
!= '\33') && (i
!= 12))
413 } else if (i
== '\33') {
415 drawscreen(); /* enable signals */
421 else if (course
[i
- 'a']) {
422 lprcat("\nSorry, but that class is filled.");
424 } else if (i
<= 'h') {
431 lprcat("\nYou feel stronger!");
436 if (course
[0] == 0) {
437 lprcat("\nSorry, but this class has a prerequisite of Fighters Training I");
442 lprcat("\nYou feel much stronger!");
445 c
[CONSTITUTION
] += 2;
449 c
[INTELLIGENCE
] += 2;
450 lprcat("\nThe task before you now seems more attainable!");
455 if (course
[2] == 0) {
456 lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry");
461 lprcat("\nThe task before you now seems very attainable!");
463 c
[INTELLIGENCE
] += 2;
468 lprcat("\nYou now feel like a born leader!");
474 lprcat("\nYou now feel more confident that you can find the potion in time!");
480 lprcat("\nYou feel like dancing!");
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. ");
491 time_used
+= coursetime
[i
- 'a'] * 100;
494 course
[i
- 'a']++; /* remember that he has
495 * taken that course */
497 c
[SPELLS
] = c
[SPELLMAX
]; /* he regenerated */
500 c
[BLINDCOUNT
] = 1; /* cure blindness too! */
502 c
[CONFUSE
] = 1; /* end confusion */
503 adjusttime((long) time_used
); /* adjust parameters for
513 * for the first national bank of Larn
515 int lasttime
= 0; /* last time he was in bank */
520 banktitle(" Welcome to the First National Bank of Larn.");
525 banktitle("Welcome to the 5th level branch office of the First National Bank of Larn.");
529 banktitle(const char *str
)
531 nosignal
= 1; /* disable signals */
534 if (outstanding_taxes
> 0) {
536 lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n");
538 lprintf("levied taxes have been paid. They have also told us that you owe %ld 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");
544 lprcat(" to leave: ");
550 nosignal
= 0; /* enable signals */
553 lprcat("\n\n\tGemstone\t Appraisal\t\tGemstone\t Appraisal");
555 nosignal
= 0; /* enable signals */
560 * function to put interest on your bank account
566 if (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 */
575 lasttime
= (gltime
/ 100) * 100;
578 static short gemorder
[26] = {0}; /* the reference to screen location
580 static long gemvalue
[26] = {0}; /* the appraisal of the gems */
586 ointerest(); /* credit any needed interest */
588 for (k
= i
= 0; i
< 26; i
++)
596 if (iven
[i
] == OLARNEYE
) {
597 gemvalue
[i
] = 250000 - ((gltime
* 7) / 100) * 100;
598 if (gemvalue
[i
] < 50000)
601 gemvalue
[i
] = (255 & ivenarg
[i
]) * 100;
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("%5ld", (long) gemvalue
[i
]);
610 lprintf("You have %8ld gold pieces in the bank.", (long) c
[BANKACCOUNT
]);
612 lprintf("You have %8ld 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.");
617 lprcat("\nYour wish? [(");
619 lprcat(") deposit, (");
621 lprcat(") withdraw, (");
623 lprcat(") sell a stone, or ");
628 while (i
!= 'd' && i
!= 'w' && i
!= 's' && i
!= '\33')
632 lprcat("deposit\nHow much? ");
633 amt
= readnum((long) c
[GOLD
]);
635 lprcat("\nSorry, but we can't take negative gold!");
638 } else if (amt
> c
[GOLD
]) {
639 lprcat(" You don't have that much.");
643 c
[BANKACCOUNT
] += amt
;
648 lprcat("withdraw\nHow much? ");
649 amt
= readnum((long) c
[BANKACCOUNT
]);
651 lprcat("\nSorry, but we don't have any negative gold!");
654 } else if (amt
> c
[BANKACCOUNT
]) {
655 lprcat("\nYou don't have that much in the bank!");
659 c
[BANKACCOUNT
] -= amt
;
664 lprcat("\nWhich stone would you like to sell? ");
666 while ((i
< 'a' || i
> 'z') && i
!= '*')
669 for (i
= 0; i
< 26; i
++) {
671 c
[GOLD
] += gemvalue
[i
];
675 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
680 if (gemvalue
[i
= i
- 'a'] == 0) {
681 lprintf("\nItem %c is not a gemstone!", i
+ 'a');
685 c
[GOLD
] += gemvalue
[i
];
689 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
698 lprintf("%8ld", (long) c
[BANKACCOUNT
]);
700 lprintf("%8ld", (long) c
[GOLD
]);
704 #if 0 /* XXX: apparently unused */
706 subroutine to appraise any stone for the bank
709 appraise(int gemstone
)
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? ");
719 if (getyn() == 'y') {
720 lprcat("yes.\n Just one moment please \n");
722 if (gemstone
== OLARNEYE
) {
723 amt
= 250000 - ((gltime
* 7) / 100) * 100;
727 amt
= (255 & ivenarg
[j
]) * 100;
728 lprintf("\nI can see this is an excellent stone, It is worth %ld", (long) amt
);
729 lprcat("\nWould you like to sell it to us? ");
731 if (getyn() == 'y') {
736 lprcat("no thank you.\n");
737 if (gemstone
== OLARNEYE
)
738 lprcat("It is, of course, your privilege to keep the stone\n");
740 lprcat("no\nO. K.\n");
743 #endif /* 0 - unused */
746 function for the trading post
752 lprcat("Welcome to the Larn Trading Post. We buy items that explorers no longer find\n");
753 lprcat("useful. Since the condition of the items you bring in is not certain,\n");
754 lprcat("and we incur great expense in reconditioning the items, we usually pay\n");
755 lprcat("only 20% of their value were they to be new. If the items are badly\n");
756 lprcat("damaged, we will pay only 10% of their new value.\n\n");
762 int i
, j
, value
, isub
, izarg
;
763 dnditm
= dndcount
= 0;
764 nosignal
= 1; /* disable signals */
768 lprcat("\nWhat item do you want to sell to us [");
770 lprcat(" for list, or ");
774 while (i
> 'z' || (i
< 'a' && i
!= '*' && i
!= '\33' && i
!= '.'))
780 nosignal
= 0; /* enable signals */
785 if (iven
[isub
] == OSCROLL
)
786 if (scrollname
[ivenarg
[isub
]][0] == 0) {
789 } /* can't sell unidentified item */
790 if (iven
[isub
] == OPOTION
)
791 if (potionname
[ivenarg
[isub
]][0] == 0) {
794 } /* can't sell unidentified item */
800 } else if (iven
[isub
] == 0)
801 lprintf("\nYou don't have item %c!", isub
+ 'a');
803 for (j
= 0; j
< MAXITM
; j
++)
804 if ((itm
[j
].obj
== iven
[isub
]) || (iven
[isub
] == ODIAMOND
) || (iven
[isub
] == ORUBY
) || (iven
[isub
] == OEMERALD
) || (iven
[isub
] == OSAPPHIRE
)) {
806 show3(isub
); /* show what the item
808 if ((iven
[isub
] == ODIAMOND
) || (iven
[isub
] == ORUBY
)
809 || (iven
[isub
] == OEMERALD
) || (iven
[isub
] == OSAPPHIRE
))
810 value
= 20 * ivenarg
[isub
];
811 else if ((itm
[j
].obj
== OSCROLL
) || (itm
[j
].obj
== OPOTION
))
812 value
= 2 * itm
[j
+ ivenarg
[isub
]].price
;
814 izarg
= ivenarg
[isub
];
815 value
= itm
[j
].price
; /* appreciate if a +n
819 while ((izarg
-- > 0) && ((value
= 14 * (67 + value
) / 10) < 500000));
821 lprintf("\nItem (%c) is worth %ld gold pieces to us. Do you want to sell it? ", i
, (long) value
);
823 if (getyn() == 'y') {
828 if (c
[WIELD
] == isub
)
830 if (c
[SHIELD
] == isub
)
832 adjustcvalues(iven
[isub
], ivenarg
[isub
]);
835 lprcat("no thanks.\n");
836 j
= MAXITM
+ 100; /* get out of the inner
840 lprcat("\nSo sorry, but we are not authorized to accept that item.");
849 lprcat("\nSorry, we can't accept unidentified objects.");
853 * for the Larn Revenue Service
860 first
= nosignal
= 1; /* disable signals */
864 lprcat("Welcome to the Larn Revenue Service district office. How can we help you?");
871 lprcat("\n\nYour wish? [(");
873 lprcat(") pay taxes, or ");
878 while (i
!= 'p' && i
!= '\33')
882 lprcat("pay taxes\nHow much? ");
883 amt
= readnum((long) c
[GOLD
]);
885 lprcat("\nSorry, but we can't take negative gold\n");
887 } else if (amt
> c
[GOLD
])
888 lprcat(" You don't have that much.\n");
890 c
[GOLD
] -= paytaxes(amt
);
894 nosignal
= 0; /* enable signals */
901 if (outstanding_taxes
> 0)
902 lprintf("You presently owe %ld gp in taxes. ", (long) outstanding_taxes
);
904 lprcat("You do not owe us any taxes. ");
907 lprintf("You have %6ld gp. ", (long) c
[GOLD
]);
909 lprcat("You have no gold pieces. ");