]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/store.c
1 /* $NetBSD: store.c,v 1.13 2008/02/03 19:29:50 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.13 2008/02/03 19:29:50 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 otradhead(void);
52 static int dndcount
= 0, dnditm
= 0;
54 /* number of items in the dnd inventory table */
57 /* this is the data for the stuff in the dnd store */
58 struct _itm itm
[90] = {
60 * cost iven name iven arg how gp
61 * iven[] ivenarg[] many
65 {10, OSTUDLEATHER
, 0, 2},
70 {900, OPLATEARMOR
, 0, 1},
71 {2600, OSSPLATE
, 0, 1},
75 * cost iven name iven arg how gp
76 * iven[] ivenarg[] many
82 {150, OBATTLEAXE
, 0, 2},
83 {450, OLONGSWORD
, 0, 2},
84 {1000, O2SWORD
, 0, 2},
86 {16500, OLANCE
, 0, 1},
87 {6000, OSWORDofSLASHING
, 0, 0},
88 {10000, OHAMMER
, 0, 0},
91 * cost iven name iven arg how gp
92 * iven[] ivenarg[] many
95 {150, OPROTRING
, 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},
106 {400, OAMULET
, 0, 1},
108 {6500, OORBOFDRAGON
, 0, 0},
109 {5500, OSPIRITSCARAB
, 0, 0},
110 {5000, OCUBEofUNDEAD
, 0, 0},
111 {6000, ONOTHEFT
, 0, 0},
118 * cost iven name iven arg how gp
119 * iven[] ivenarg[] many
124 {520, OPOTION
, 2, 1},
125 {100, OPOTION
, 3, 2},
127 {150, OPOTION
, 5, 2},
130 {200, OPOTION
, 8, 1},
132 {80, OPOTION
, 10, 1},
135 * cost iven name iven arg how gp
136 * iven[] ivenarg[] many
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},
153 * cost iven name iven arg how gp
154 * iven[] ivenarg[] many
157 {100, OSCROLL
, 0, 2},
158 {125, OSCROLL
, 1, 2},
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},
171 * cost iven name iven arg how gp
172 * iven[] ivenarg[] many
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}
190 function for the dnd store
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.");
204 for (i
= dnditm
; i
< 26 + dnditm
; i
++)
213 lprcat("\nYou can't carry anything more!");
221 lprcat("\nSorry, but we are out of that item.");
229 lprcat("\nYou don't have enough gold to pay for that!");
239 nosignal
= 1; /* disable signals */
242 if (outstanding_taxes
> 0) {
243 lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n");
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");
250 lprcat(" to leave: ");
256 nosignal
= 0; /* enable signals */
262 lprintf("%ld gold pieces", (long) c
[GOLD
]);
264 cl_dn(1, 20); /* erase to eod */
265 lprcat("\nEnter your transaction [");
267 lprcat(" for more, ");
269 lprcat(" to leave]? ");
271 while ((i
< 'a' || i
> 'z') && (i
!= ' ') && (i
!= '\33') && (i
!= 12))
277 } else if (i
== '\33') {
279 nosignal
= 0; /* enable signals */
281 } else if (i
== ' ') {
283 if ((dnditm
+= 26) >= MAXITM
)
286 } else { /* buy something */
287 lprc(i
);/* echo the byte */
291 else if (itm
[i
].qty
<= 0)
293 else if (pocketfull())
295 else if (c
[GOLD
] < itm
[i
].price
* 10)
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
];
303 c
[GOLD
] -= itm
[i
].price
* 10;
305 take(itm
[i
].obj
, itm
[i
].arg
);
318 to print the item list; used in dndstore() enter with the index into itm
327 cursor((j
= (i
& 1) * 40 + 1), (k
= ((i
% 26) >> 1) + 5));
328 if (itm
[i
].qty
== 0) {
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
]);
338 lprintf("%s", objectname
[itm
[i
].obj
]);
340 lprintf("%6ld", (long) (itm
[i
].price
* 10));
346 for the college of larn
348 u_char course
[26] = {0}; /* the list of courses taken */
349 char coursetime
[] = {10, 15, 10, 20, 10, 10, 10, 5};
351 function to display the header info for the school
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");
362 lprcat("\t\ta) Fighters Training I 10 mobuls"); /* line 7 of crt */
365 lprcat("\t\tb) Fighters Training II 15 mobuls");
368 lprcat("\t\tc) Introduction to Wizardry 10 mobuls");
371 lprcat("\t\td) Applied Wizardry 20 mobuls");
374 lprcat("\t\te) Behavioral Psychology 10 mobuls");
377 lprcat("\t\tf) Faith for Today 10 mobuls");
380 lprcat("\t\tg) Contemporary Dance 10 mobuls");
383 lprcat("\t\th) History of Larn 5 mobuls");
385 lprcat("\n\n\t\tAll courses cost 250 gold pieces.");
387 lprcat("You are presently carrying ");
395 nosignal
= 1; /* disable signals */
399 lprintf("%ld gold pieces. ", (long) c
[GOLD
]);
401 lprcat("\nWhat is your choice [");
403 lprcat(" to leave] ? ");
406 while ((i
< 'a' || i
> 'h') && (i
!= '\33') && (i
!= 12))
411 } else if (i
== '\33') {
413 drawscreen(); /* enable signals */
419 else if (course
[i
- 'a']) {
420 lprcat("\nSorry, but that class is filled.");
422 } else if (i
<= 'h') {
429 lprcat("\nYou feel stronger!");
434 if (course
[0] == 0) {
435 lprcat("\nSorry, but this class has a prerequisite of Fighters Training I");
440 lprcat("\nYou feel much stronger!");
443 c
[CONSTITUTION
] += 2;
447 c
[INTELLIGENCE
] += 2;
448 lprcat("\nThe task before you now seems more attainable!");
453 if (course
[2] == 0) {
454 lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry");
459 lprcat("\nThe task before you now seems very attainable!");
461 c
[INTELLIGENCE
] += 2;
466 lprcat("\nYou now feel like a born leader!");
472 lprcat("\nYou now feel more confident that you can find the potion in time!");
478 lprcat("\nYou feel like dancing!");
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. ");
489 time_used
+= coursetime
[i
- 'a'] * 100;
492 course
[i
- 'a']++; /* remember that he has
493 * taken that course */
495 c
[SPELLS
] = c
[SPELLMAX
]; /* he regenerated */
498 c
[BLINDCOUNT
] = 1; /* cure blindness too! */
500 c
[CONFUSE
] = 1; /* end confusion */
501 adjusttime((long) time_used
); /* adjust parameters for
511 * for the first national bank of Larn
513 int lasttime
= 0; /* last time he was in bank */
518 banktitle(" Welcome to the First National Bank of Larn.");
523 banktitle("Welcome to the 5th level branch office of the First National Bank of Larn.");
527 banktitle(const char *str
)
529 nosignal
= 1; /* disable signals */
532 if (outstanding_taxes
> 0) {
534 lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n");
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");
542 lprcat(" to leave: ");
548 nosignal
= 0; /* enable signals */
551 lprcat("\n\n\tGemstone\t Appraisal\t\tGemstone\t Appraisal");
553 nosignal
= 0; /* enable signals */
558 * function to put interest on your bank account
564 if (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 */
573 lasttime
= (gltime
/ 100) * 100;
576 static short gemorder
[26] = {0}; /* the reference to screen location
578 static long gemvalue
[26] = {0}; /* the appraisal of the gems */
584 ointerest(); /* credit any needed interest */
586 for (k
= i
= 0; i
< 26; i
++)
594 if (iven
[i
] == OLARNEYE
) {
595 gemvalue
[i
] = 250000 - ((gltime
* 7) / 100) * 100;
596 if (gemvalue
[i
] < 50000)
599 gemvalue
[i
] = (255 & ivenarg
[i
]) * 100;
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
]);
608 lprintf("You have %8ld gold pieces in the bank.", (long) c
[BANKACCOUNT
]);
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.");
615 lprcat("\nYour wish? [(");
617 lprcat(") deposit, (");
619 lprcat(") withdraw, (");
621 lprcat(") sell a stone, or ");
626 while (i
!= 'd' && i
!= 'w' && i
!= 's' && i
!= '\33')
630 lprcat("deposit\nHow much? ");
631 amt
= readnum((long) c
[GOLD
]);
633 lprcat("\nSorry, but we can't take negative gold!");
636 } else if (amt
> c
[GOLD
]) {
637 lprcat(" You don't have that much.");
641 c
[BANKACCOUNT
] += amt
;
646 lprcat("withdraw\nHow much? ");
647 amt
= readnum((long) c
[BANKACCOUNT
]);
649 lprcat("\nSorry, but we don't have any negative gold!");
652 } else if (amt
> c
[BANKACCOUNT
]) {
653 lprcat("\nYou don't have that much in the bank!");
657 c
[BANKACCOUNT
] -= amt
;
662 lprcat("\nWhich stone would you like to sell? ");
664 while ((i
< 'a' || i
> 'z') && i
!= '*')
667 for (i
= 0; i
< 26; i
++) {
669 c
[GOLD
] += gemvalue
[i
];
673 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
678 if (gemvalue
[i
= i
- 'a'] == 0) {
679 lprintf("\nItem %c is not a gemstone!", i
+ 'a');
683 c
[GOLD
] += gemvalue
[i
];
687 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
696 lprintf("%8ld", (long) c
[BANKACCOUNT
]);
698 lprintf("%8ld", (long) c
[GOLD
]);
703 subroutine to appraise any stone for the bank
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? ");
717 if (getyn() == 'y') {
718 lprcat("yes.\n Just one moment please \n");
720 if (gemstone
== OLARNEYE
) {
721 amt
= 250000 - ((gltime
* 7) / 100) * 100;
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? ");
729 if (getyn() == 'y') {
734 lprcat("no thank you.\n");
735 if (gemstone
== OLARNEYE
)
736 lprcat("It is, of course, your privilege to keep the stone\n");
738 lprcat("no\nO. K.\n");
742 function for the trading post
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");
758 int i
, j
, value
, isub
, izarg
;
759 dnditm
= dndcount
= 0;
760 nosignal
= 1; /* disable signals */
764 lprcat("\nWhat item do you want to sell to us [");
766 lprcat(" for list, or ");
770 while (i
> 'z' || (i
< 'a' && i
!= '*' && i
!= '\33' && i
!= '.'))
776 nosignal
= 0; /* enable signals */
781 if (iven
[isub
] == OSCROLL
)
782 if (scrollname
[ivenarg
[isub
]][0] == 0) {
785 } /* can't sell unidentified item */
786 if (iven
[isub
] == OPOTION
)
787 if (potionname
[ivenarg
[isub
]][0] == 0) {
790 } /* can't sell unidentified item */
796 } else if (iven
[isub
] == 0)
797 lprintf("\nYou don't have item %c!", isub
+ 'a');
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
)) {
802 show3(isub
); /* show what the item
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
;
810 izarg
= ivenarg
[isub
];
811 value
= itm
[j
].price
; /* appreciate if a +n
815 while ((izarg
-- > 0) && ((value
= 14 * (67 + value
) / 10) < 500000));
817 lprintf("\nItem (%c) is worth %ld gold pieces to us. Do you want to sell it? ", i
, (long) value
);
819 if (getyn() == 'y') {
824 if (c
[WIELD
] == isub
)
826 if (c
[SHIELD
] == isub
)
828 adjustcvalues(iven
[isub
], ivenarg
[isub
]);
831 lprcat("no thanks.\n");
832 j
= MAXITM
+ 100; /* get out of the inner
836 lprcat("\nSo sorry, but we are not authorized to accept that item.");
845 lprcat("\nSorry, we can't accept unidentified objects.");
849 * for the Larn Revenue Service
856 first
= nosignal
= 1; /* disable signals */
860 lprcat("Welcome to the Larn Revenue Service district office. How can we help you?");
867 lprcat("\n\nYour wish? [(");
869 lprcat(") pay taxes, or ");
874 while (i
!= 'p' && i
!= '\33')
878 lprcat("pay taxes\nHow much? ");
879 amt
= readnum((long) c
[GOLD
]);
881 lprcat("\nSorry, but we can't take negative gold\n");
883 } else if (amt
> c
[GOLD
])
884 lprcat(" You don't have that much.\n");
886 c
[GOLD
] -= paytaxes(amt
);
890 nosignal
= 0; /* enable signals */
897 if (outstanding_taxes
> 0)
898 lprintf("You presently owe %ld gp in taxes. ", (long) outstanding_taxes
);
900 lprcat("You do not owe us any taxes. ");
903 lprintf("You have %6ld gp. ", (long) c
[GOLD
]);
905 lprcat("You have no gold pieces. ");