]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/store.c
1 /* $NetBSD: store.c,v 1.16 2012/06/19 05:30:44 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.16 2012/06/19 05:30:44 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
328 cursor((j
= (i
& 1) * 40 + 1), (k
= ((i
% 26) >> 1) + 5));
329 if (itm
[i
].qty
== 0) {
333 lprintf("%c) ", (i
% 26) + 'a');
334 if (itm
[i
].obj
== OPOTION
) {
335 lprintf("potion of%s", potionhide
[itm
[i
].arg
]);
336 } else if (itm
[i
].obj
== OSCROLL
) {
337 lprintf("scroll of%s", scrollhide
[itm
[i
].arg
]);
339 lprintf("%s", objectname
[itm
[i
].obj
]);
341 lprintf("%6ld", (long) (itm
[i
].price
* 10));
347 for the college of larn
349 u_char course
[26] = {0}; /* the list of courses taken */
350 static char coursetime
[] = {10, 15, 10, 20, 10, 10, 10, 5};
352 function to display the header info for the school
358 lprcat("The College of Larn offers the exciting opportunity of higher education to\n");
359 lprcat("all inhabitants of the caves. Here is a list of the class schedule:\n\n\n");
360 lprcat("\t\t Course Name \t Time Needed\n\n");
363 lprcat("\t\ta) Fighters Training I 10 mobuls"); /* line 7 of crt */
366 lprcat("\t\tb) Fighters Training II 15 mobuls");
369 lprcat("\t\tc) Introduction to Wizardry 10 mobuls");
372 lprcat("\t\td) Applied Wizardry 20 mobuls");
375 lprcat("\t\te) Behavioral Psychology 10 mobuls");
378 lprcat("\t\tf) Faith for Today 10 mobuls");
381 lprcat("\t\tg) Contemporary Dance 10 mobuls");
384 lprcat("\t\th) History of Larn 5 mobuls");
386 lprcat("\n\n\t\tAll courses cost 250 gold pieces.");
388 lprcat("You are presently carrying ");
396 nosignal
= 1; /* disable signals */
400 lprintf("%ld gold pieces. ", (long) c
[GOLD
]);
402 lprcat("\nWhat is your choice [");
404 lprcat(" to leave] ? ");
407 while ((i
< 'a' || i
> 'h') && (i
!= '\33') && (i
!= 12))
412 } else if (i
== '\33') {
414 drawscreen(); /* enable signals */
420 else if (course
[i
- 'a']) {
421 lprcat("\nSorry, but that class is filled.");
423 } else if (i
<= 'h') {
430 lprcat("\nYou feel stronger!");
435 if (course
[0] == 0) {
436 lprcat("\nSorry, but this class has a prerequisite of Fighters Training I");
441 lprcat("\nYou feel much stronger!");
444 c
[CONSTITUTION
] += 2;
448 c
[INTELLIGENCE
] += 2;
449 lprcat("\nThe task before you now seems more attainable!");
454 if (course
[2] == 0) {
455 lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry");
460 lprcat("\nThe task before you now seems very attainable!");
462 c
[INTELLIGENCE
] += 2;
467 lprcat("\nYou now feel like a born leader!");
473 lprcat("\nYou now feel more confident that you can find the potion in time!");
479 lprcat("\nYou feel like dancing!");
485 lprcat("\nYour instructor told you that the Eye of Larn is rumored to be guarded\n");
486 lprcat("by a platinum dragon who possesses psionic abilities. ");
490 time_used
+= coursetime
[i
- 'a'] * 100;
493 course
[i
- 'a']++; /* remember that he has
494 * taken that course */
496 c
[SPELLS
] = c
[SPELLMAX
]; /* he regenerated */
499 c
[BLINDCOUNT
] = 1; /* cure blindness too! */
501 c
[CONFUSE
] = 1; /* end confusion */
502 adjusttime((long) time_used
); /* adjust parameters for
512 * for the first national bank of Larn
514 int lasttime
= 0; /* last time he was in bank */
519 banktitle(" Welcome to the First National Bank of Larn.");
524 banktitle("Welcome to the 5th level branch office of the First National Bank of Larn.");
528 banktitle(const char *str
)
530 nosignal
= 1; /* disable signals */
533 if (outstanding_taxes
> 0) {
535 lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n");
537 lprintf("levied taxes have been paid. They have also told us that you owe %ld gp in\n", (long) outstanding_taxes
);
538 lprcat("taxes, and we must comply with them. We cannot serve you at this time. Sorry.\n");
539 lprcat("We suggest you go to the LRS office and pay your taxes.\n");
543 lprcat(" to leave: ");
549 nosignal
= 0; /* enable signals */
552 lprcat("\n\n\tGemstone\t Appraisal\t\tGemstone\t Appraisal");
554 nosignal
= 0; /* enable signals */
559 * function to put interest on your bank account
565 if (c
[BANKACCOUNT
] < 0)
567 else if ((c
[BANKACCOUNT
] > 0) && (c
[BANKACCOUNT
] < 500000)) {
568 i
= (gltime
- lasttime
) / 100; /* # mobuls elapsed */
569 while ((i
-- > 0) && (c
[BANKACCOUNT
] < 500000))
570 c
[BANKACCOUNT
] += c
[BANKACCOUNT
] / 250;
571 if (c
[BANKACCOUNT
] > 500000)
572 c
[BANKACCOUNT
] = 500000; /* interest limit */
574 lasttime
= (gltime
/ 100) * 100;
577 static short gemorder
[26] = {0}; /* the reference to screen location
579 static long gemvalue
[26] = {0}; /* the appraisal of the gems */
585 ointerest(); /* credit any needed interest */
587 for (k
= i
= 0; i
< 26; i
++)
595 if (iven
[i
] == OLARNEYE
) {
596 gemvalue
[i
] = 250000 - ((gltime
* 7) / 100) * 100;
597 if (gemvalue
[i
] < 50000)
600 gemvalue
[i
] = (255 & ivenarg
[i
]) * 100;
602 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
603 lprintf("%c) %s", i
+ 'a', objectname
[iven
[i
]]);
604 cursor((k
% 2) * 40 + 33, (k
>> 1) + 4);
605 lprintf("%5ld", (long) gemvalue
[i
]);
609 lprintf("You have %8ld gold pieces in the bank.", (long) c
[BANKACCOUNT
]);
611 lprintf("You have %8ld gold pieces", (long) c
[GOLD
]);
612 if (c
[BANKACCOUNT
] + c
[GOLD
] >= 500000)
613 lprcat("\nNote: Larndom law states that only deposits under 500,000gp can earn interest.");
616 lprcat("\nYour wish? [(");
618 lprcat(") deposit, (");
620 lprcat(") withdraw, (");
622 lprcat(") sell a stone, or ");
627 while (i
!= 'd' && i
!= 'w' && i
!= 's' && i
!= '\33')
631 lprcat("deposit\nHow much? ");
632 amt
= readnum((long) c
[GOLD
]);
634 lprcat("\nSorry, but we can't take negative gold!");
637 } else if (amt
> c
[GOLD
]) {
638 lprcat(" You don't have that much.");
642 c
[BANKACCOUNT
] += amt
;
647 lprcat("withdraw\nHow much? ");
648 amt
= readnum((long) c
[BANKACCOUNT
]);
650 lprcat("\nSorry, but we don't have any negative gold!");
653 } else if (amt
> c
[BANKACCOUNT
]) {
654 lprcat("\nYou don't have that much in the bank!");
658 c
[BANKACCOUNT
] -= amt
;
663 lprcat("\nWhich stone would you like to sell? ");
665 while ((i
< 'a' || i
> 'z') && i
!= '*')
668 for (i
= 0; i
< 26; i
++) {
670 c
[GOLD
] += gemvalue
[i
];
674 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
679 if (gemvalue
[i
= i
- 'a'] == 0) {
680 lprintf("\nItem %c is not a gemstone!", i
+ 'a');
684 c
[GOLD
] += gemvalue
[i
];
688 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
697 lprintf("%8ld", (long) c
[BANKACCOUNT
]);
699 lprintf("%8ld", (long) c
[GOLD
]);
703 #if 0 /* XXX: apparently unused */
705 subroutine to appraise any stone for the bank
708 appraise(int gemstone
)
711 for (j
= 0; j
< 26; j
++)
712 if (iven
[j
] == gemstone
) {
713 lprintf("\nI see you have %s", objectname
[gemstone
]);
714 if (gemstone
== OLARNEYE
)
715 lprcat(" I must commend you. I didn't think\nyou could get it.");
716 lprcat(" Shall I appraise it for you? ");
718 if (getyn() == 'y') {
719 lprcat("yes.\n Just one moment please \n");
721 if (gemstone
== OLARNEYE
) {
722 amt
= 250000 - ((gltime
* 7) / 100) * 100;
726 amt
= (255 & ivenarg
[j
]) * 100;
727 lprintf("\nI can see this is an excellent stone, It is worth %ld", (long) amt
);
728 lprcat("\nWould you like to sell it to us? ");
730 if (getyn() == 'y') {
735 lprcat("no thank you.\n");
736 if (gemstone
== OLARNEYE
)
737 lprcat("It is, of course, your privilege to keep the stone\n");
739 lprcat("no\nO. K.\n");
742 #endif /* 0 - unused */
745 function for the trading post
751 lprcat("Welcome to the Larn Trading Post. We buy items that explorers no longer find\n");
752 lprcat("useful. Since the condition of the items you bring in is not certain,\n");
753 lprcat("and we incur great expense in reconditioning the items, we usually pay\n");
754 lprcat("only 20% of their value were they to be new. If the items are badly\n");
755 lprcat("damaged, we will pay only 10% of their new value.\n\n");
761 int i
, j
, value
, isub
, izarg
;
762 dnditm
= dndcount
= 0;
763 nosignal
= 1; /* disable signals */
767 lprcat("\nWhat item do you want to sell to us [");
769 lprcat(" for list, or ");
773 while (i
> 'z' || (i
< 'a' && i
!= '*' && i
!= '\33' && i
!= '.'))
779 nosignal
= 0; /* enable signals */
784 if (iven
[isub
] == OSCROLL
)
785 if (scrollname
[ivenarg
[isub
]][0] == 0) {
788 } /* can't sell unidentified item */
789 if (iven
[isub
] == OPOTION
)
790 if (potionname
[ivenarg
[isub
]][0] == 0) {
793 } /* can't sell unidentified item */
799 } else if (iven
[isub
] == 0)
800 lprintf("\nYou don't have item %c!", isub
+ 'a');
802 for (j
= 0; j
< MAXITM
; j
++)
803 if ((itm
[j
].obj
== iven
[isub
]) || (iven
[isub
] == ODIAMOND
) || (iven
[isub
] == ORUBY
) || (iven
[isub
] == OEMERALD
) || (iven
[isub
] == OSAPPHIRE
)) {
805 show3(isub
); /* show what the item
807 if ((iven
[isub
] == ODIAMOND
) || (iven
[isub
] == ORUBY
)
808 || (iven
[isub
] == OEMERALD
) || (iven
[isub
] == OSAPPHIRE
))
809 value
= 20 * ivenarg
[isub
];
810 else if ((itm
[j
].obj
== OSCROLL
) || (itm
[j
].obj
== OPOTION
))
811 value
= 2 * itm
[j
+ ivenarg
[isub
]].price
;
813 izarg
= ivenarg
[isub
];
814 value
= itm
[j
].price
; /* appreciate if a +n
818 while ((izarg
-- > 0) && ((value
= 14 * (67 + value
) / 10) < 500000));
820 lprintf("\nItem (%c) is worth %ld gold pieces to us. Do you want to sell it? ", i
, (long) value
);
822 if (getyn() == 'y') {
827 if (c
[WIELD
] == isub
)
829 if (c
[SHIELD
] == isub
)
831 adjustcvalues(iven
[isub
], ivenarg
[isub
]);
834 lprcat("no thanks.\n");
835 j
= MAXITM
+ 100; /* get out of the inner
839 lprcat("\nSo sorry, but we are not authorized to accept that item.");
848 lprcat("\nSorry, we can't accept unidentified objects.");
852 * for the Larn Revenue Service
859 first
= nosignal
= 1; /* disable signals */
863 lprcat("Welcome to the Larn Revenue Service district office. How can we help you?");
870 lprcat("\n\nYour wish? [(");
872 lprcat(") pay taxes, or ");
877 while (i
!= 'p' && i
!= '\33')
881 lprcat("pay taxes\nHow much? ");
882 amt
= readnum((long) c
[GOLD
]);
884 lprcat("\nSorry, but we can't take negative gold\n");
886 } else if (amt
> c
[GOLD
])
887 lprcat(" You don't have that much.\n");
889 c
[GOLD
] -= paytaxes(amt
);
893 nosignal
= 0; /* enable signals */
900 if (outstanding_taxes
> 0)
901 lprintf("You presently owe %ld gp in taxes. ", (long) outstanding_taxes
);
903 lprcat("You do not owe us any taxes. ");
906 lprintf("You have %6ld gp. ", (long) c
[GOLD
]);
908 lprcat("You have no gold pieces. ");