2 * Copyright (c) 1988 The Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)store.c 5.4 (Berkeley) 5/13/91
30 * $FreeBSD: src/games/larn/store.c,v 1.5 1999/11/30 03:49:00 billf Exp $
31 * $DragonFly: src/games/larn/store.c,v 1.4 2006/08/26 17:05:05 pavalos Exp $
34 /* store.c Larn is copyrighted 1986 by Noah Morgan. */
37 static void dnd_2hed(void);
38 static void dnd_hed(void);
39 static void handsfull(void);
40 static void outofstock(void);
41 static void nogold(void);
42 static void dnditem(int);
43 static void sch_hed(void);
44 static void banktitle(const char *);
45 static void obanksub(void);
46 static void otradhead(void);
47 static void cnsitm(void);
49 static int dndcount
= 0, dnditm
= 0;
51 /* this is the data for the stuff in the dnd store */
52 int maxitm
= 83; /* number of items in the dnd inventory table */
53 struct _itm itm_
[90] = {
54 /*cost iven name iven arg how
55 gp iven[] ivenarg[] many */
57 { 2, OLEATHER
, 0, 3 },
58 { 10, OSTUDLEATHER
, 0, 2 },
61 { 220, OSPLINT
, 0, 1 },
62 { 400, OPLATE
, 0, 1 },
63 { 900, OPLATEARMOR
, 0, 1 },
64 { 2600, OSSPLATE
, 0, 1 },
65 { 150, OSHIELD
, 0, 1 },
67 /*cost iven name iven arg how
68 gp iven[] ivenarg[] many */
73 { 150, OBATTLEAXE
, 0, 2 },
74 { 450, OLONGSWORD
, 0, 2 },
75 { 1000, O2SWORD
, 0, 2 },
76 { 5000, OSWORD
, 0, 1 },
77 { 16500, OLANCE
, 0, 1 },
78 { 6000, OSWORDofSLASHING
, 0, 0 },
79 { 10000, OHAMMER
, 0, 0 },
81 /*cost iven name iven arg how
82 gp iven[] ivenarg[] many */
84 { 150, OPROTRING
, 1, 1 },
85 { 85, OSTRRING
, 1, 1 },
86 { 120, ODEXRING
, 1, 1 },
87 { 120, OCLEVERRING
, 1, 1 },
88 { 180, OENERGYRING
, 0, 1 },
89 { 125, ODAMRING
, 0, 1 },
90 { 220, OREGENRING
, 0, 1 },
91 { 1000, ORINGOFEXTRA
, 0, 1 },
95 { 400, OAMULET
, 0, 1 },
97 { 6500, OORBOFDRAGON
, 0, 0 },
98 { 5500, OSPIRITSCARAB
, 0, 0 },
99 { 5000, OCUBEofUNDEAD
, 0, 0 },
100 { 6000, ONOTHEFT
, 0, 0 },
102 { 590, OCHEST
, 6, 1 },
103 { 200, OBOOK
, 8, 1 },
104 { 10, OCOOKIE
, 0, 3 },
106 /*cost iven name iven arg how
107 gp iven[] ivenarg[] many */
109 { 20, OPOTION
, 0, 6 },
110 { 90, OPOTION
, 1, 5 },
111 { 520, OPOTION
, 2, 1 },
112 { 100, OPOTION
, 3, 2 },
113 { 50, OPOTION
, 4, 2 },
114 { 150, OPOTION
, 5, 2 },
115 { 70, OPOTION
, 6, 1 },
116 { 30, OPOTION
, 7, 7 },
117 { 200, OPOTION
, 8, 1 },
118 { 50, OPOTION
, 9, 1 },
119 { 80, OPOTION
, 10, 1 },
121 /*cost iven name iven arg how
122 gp iven[] ivenarg[] many */
124 { 30, OPOTION
, 11, 3 },
125 { 20, OPOTION
, 12, 5 },
126 { 40, OPOTION
, 13, 3 },
127 { 35, OPOTION
, 14, 2 },
128 { 520, OPOTION
, 15, 1 },
129 { 90, OPOTION
, 16, 2 },
130 { 200, OPOTION
, 17, 2 },
131 { 220, OPOTION
, 18, 4 },
132 { 80, OPOTION
, 19, 6 },
133 { 370, OPOTION
, 20, 3 },
134 { 50, OPOTION
, 22, 1 },
135 { 150, OPOTION
, 23, 3 },
137 /*cost iven name iven arg how
138 gp iven[] ivenarg[] many */
140 { 100, OSCROLL
, 0, 2 },
141 { 125, OSCROLL
, 1, 2 },
142 { 60, OSCROLL
, 2, 4 },
143 { 10, OSCROLL
, 3, 4 },
144 { 100, OSCROLL
, 4, 3 },
145 { 200, OSCROLL
, 5, 2 },
146 { 110, OSCROLL
, 6, 1 },
147 { 500, OSCROLL
, 7, 2 },
148 { 200, OSCROLL
, 8, 2 },
149 { 250, OSCROLL
, 9, 4 },
150 { 20, OSCROLL
, 10, 5 },
151 { 30, OSCROLL
, 11, 3 },
153 /*cost iven name iven arg how
154 gp iven[] ivenarg[] many */
156 { 340, OSCROLL
, 12, 1 },
157 { 340, OSCROLL
, 13, 1 },
158 { 300, OSCROLL
, 14, 2 },
159 { 400, OSCROLL
, 15, 2 },
160 { 500, OSCROLL
, 16, 2 },
161 { 1000, OSCROLL
, 17, 1 },
162 { 500, OSCROLL
, 18, 1 },
163 { 340, OSCROLL
, 19, 2 },
164 { 220, OSCROLL
, 20, 3 },
165 { 3900, OSCROLL
, 21, 0 },
166 { 610, OSCROLL
, 22, 1 },
167 { 3000, OSCROLL
, 23, 0 }
171 function for the dnd store
176 lprcat("Welcome to the Larn Thrift Shoppe. We stock many items explorers find useful\n");
177 lprcat(" in their adventures. Feel free to browse to your hearts content.\n");
178 lprcat("Also be advised, if you break 'em, you pay for 'em.");
185 for (i
= dnditm
; i
< 26 + dnditm
; i
++)
194 lprcat("\nYou can't carry anything more!");
202 lprcat("\nSorry, but we are out of that item.");
210 lprcat("\nYou don't have enough gold to pay for that!");
220 nosignal
= 1; /* disable signals */
223 if (outstanding_taxes
> 0) {
224 lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n");
226 lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n", (long)outstanding_taxes
);
227 lprcat("comply with the law, we cannot serve you at this time. Soo Sorry.\n");
231 lprcat(" to leave: ");
237 nosignal
= 0; /* enable signals */
244 lprintf("%d gold pieces", (long)c
[GOLD
]);
246 cl_dn(1, 20); /* erase to eod */
247 lprcat("\nEnter your transaction [");
249 lprcat(" for more, ");
251 lprcat(" to leave]? ");
253 while ((i
< 'a' || i
> 'z') && (i
!= ' ') && (i
!= '\33') && (i
!= 12))
259 } else if (i
== '\33') {
261 nosignal
= 0; /* enable signals */
263 } else if (i
== ' ') {
265 if ((dnditm
+= 26) >= maxitm
)
268 } else { /* buy something */
269 lprc(i
);/* echo the byte */
273 else if (itm_
[i
].qty
<= 0)
275 else if (pocketfull())
277 else if (c
[GOLD
] < itm_
[i
].price
* 10)
280 if (itm_
[i
].obj
== OPOTION
)
281 potionname
[itm_
[i
].arg
] = potionhide
[itm_
[i
].arg
];
282 else if (itm_
[i
].obj
== OSCROLL
)
283 scrollname
[itm_
[i
].arg
] = scrollhide
[itm_
[i
].arg
];
284 c
[GOLD
] -= itm_
[i
].price
* 10;
286 take(itm_
[i
].obj
, itm_
[i
].arg
);
287 if (itm_
[i
].qty
== 0)
298 to print the item list; used in dndstore() enter with the index into itm_
306 cursor((j
= (i
& 1) * 40 + 1), (k
= ((i
% 26) >> 1) + 5));
307 if (itm_
[i
].qty
== 0) {
311 lprintf("%c) ", (i
% 26) + 'a');
312 if (itm_
[i
].obj
== OPOTION
) {
313 lprcat("potion of ");
314 lprintf("%s", potionhide
[itm_
[i
].arg
]);
315 } else if (itm_
[i
].obj
== OSCROLL
) {
316 lprcat("scroll of ");
317 lprintf("%s", scrollhide
[itm_
[i
].arg
]);
319 lprintf("%s", objectname
[itm_
[i
].obj
]);
321 lprintf("%6d", (long)(itm_
[i
].price
* 10));
325 for the college of larn
327 char course
[26] = { 0 }; /* the list of courses taken */
328 char coursetime
[] = { 10, 15, 10, 20, 10, 10, 10, 5 };
330 function to display the header info for the school
336 lprcat("The College of Larn offers the exciting opportunity of higher education to\n");
337 lprcat("all inhabitants of the caves. Here is a list of the class schedule:\n\n\n");
338 lprcat("\t\t Course Name \t Time Needed\n\n");
341 lprcat("\t\ta) Fighters Training I 10 mobuls"); /* line 7 of crt */
344 lprcat("\t\tb) Fighters Training II 15 mobuls");
347 lprcat("\t\tc) Introduction to Wizardry 10 mobuls");
350 lprcat("\t\td) Applied Wizardry 20 mobuls");
353 lprcat("\t\te) Behavioral Psychology 10 mobuls");
356 lprcat("\t\tf) Faith for Today 10 mobuls");
359 lprcat("\t\tg) Contemporary Dance 10 mobuls");
362 lprcat("\t\th) History of Larn 5 mobuls");
364 lprcat("\n\n\t\tAll courses cost 250 gold pieces.");
366 lprcat("You are presently carrying ");
374 nosignal
= 1; /* disable signals */
378 lprintf("%d gold pieces. ", (long)c
[GOLD
]);
380 lprcat("\nWhat is your choice [");
382 lprcat(" to leave] ? ");
385 while ((i
< 'a' || i
> 'h') && (i
!= '\33') && (i
!= 12))
390 } else if (i
== '\33') {
392 drawscreen(); /* enable signals */
398 else if (course
[i
- 'a']) {
399 lprcat("\nSorry, but that class is filled.");
401 } else if (i
<= 'h') {
408 lprcat("\nYou feel stronger!");
413 if (course
[0] == 0) {
414 lprcat("\nSorry, but this class has a prerequisite of Fighters Training I");
419 lprcat("\nYou feel much stronger!");
422 c
[CONSTITUTION
] += 2;
426 c
[INTELLIGENCE
] += 2;
427 lprcat("\nThe task before you now seems more attainable!");
432 if (course
[2] == 0) {
433 lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry");
438 lprcat("\nThe task before you now seems very attainable!");
440 c
[INTELLIGENCE
] += 2;
445 lprcat("\nYou now feel like a born leader!");
451 lprcat("\nYou now feel more confident that you can find the potion in time!");
457 lprcat("\nYou feel like dancing!");
463 lprcat("\nYour instructor told you that the Eye of Larn is rumored to be guarded\n");
464 lprcat("by a platinum dragon who possesses psionic abilities. ");
468 time_used
+= coursetime
[i
- 'a'] * 100;
471 course
[i
- 'a']++; /* remember that he has taken that course */
473 c
[SPELLS
] = c
[SPELLMAX
]; /* he regenerated */
476 c
[BLINDCOUNT
] = 1; /* cure blindness too! */
478 c
[CONFUSE
] = 1; /* end confusion */
479 larn_adjtime((long)time_used
); /* adjust parameters for time change */
487 * for the first national bank of Larn
489 int lasttime
= 0; /* last time he was in bank */
494 banktitle(" Welcome to the First National Bank of Larn.");
500 banktitle("Welcome to the 5th level branch office of the First National Bank of Larn.");
504 banktitle(const char *str
)
506 nosignal
= 1; /* disable signals */
509 if (outstanding_taxes
> 0) {
511 lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n");
513 lprintf("levied taxes have been paid. They have also told us that you owe %d gp in\n", (long)outstanding_taxes
);
514 lprcat("taxes, and we must comply with them. We cannot serve you at this time. Sorry.\n");
515 lprcat("We suggest you go to the LRS office and pay your taxes.\n");
519 lprcat(" to leave: ");
525 nosignal
= 0; /* enable signals */
528 lprcat("\n\n\tGemstone\t Appraisal\t\tGemstone\t Appraisal");
530 nosignal
= 0; /* enable signals */
535 * function to put interest on your bank account
541 if (c
[BANKACCOUNT
] < 0)
543 else if ((c
[BANKACCOUNT
] > 0) && (c
[BANKACCOUNT
] < 500000)) {
544 i
= (gtime
- lasttime
) / 100; /* # mobuls elapsed */
545 while ((i
-- > 0) && (c
[BANKACCOUNT
] < 500000))
546 c
[BANKACCOUNT
] += c
[BANKACCOUNT
] / 250;
547 if (c
[BANKACCOUNT
] > 500000)
548 c
[BANKACCOUNT
] = 500000; /* interest limit */
550 lasttime
= (gtime
/ 100) * 100;
553 static short gemorder
[26] = { 0 }; /* the reference to screen location for each */
554 static long gemvalue
[26] = { 0 }; /* the appraisal of the gems */
561 ointerest(); /* credit any needed interest */
563 for (k
= i
= 0; i
< 26; i
++)
571 if (iven
[i
] == OLARNEYE
) {
572 gemvalue
[i
] = 250000 - ((gtime
* 7) / 100) * 100;
573 if (gemvalue
[i
] < 50000)
576 gemvalue
[i
] = (255 & ivenarg
[i
]) * 100;
578 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
579 lprintf("%c) %s", i
+ 'a', objectname
[(int)iven
[i
]]);
580 cursor((k
% 2) * 40 + 33, (k
>> 1) + 4);
581 lprintf("%5d", (long)gemvalue
[i
]);
585 lprintf("You have %8d gold pieces in the bank.", (long)c
[BANKACCOUNT
]);
587 lprintf("You have %8d gold pieces", (long)c
[GOLD
]);
588 if (c
[BANKACCOUNT
] + c
[GOLD
] >= 500000)
589 lprcat("\nNote: Larndom law states that only deposits under 500,000gp can earn interest.");
592 lprcat("\nYour wish? [(");
594 lprcat(") deposit, (");
596 lprcat(") withdraw, (");
598 lprcat(") sell a stone, or ");
603 while (i
!= 'd' && i
!= 'w' && i
!= 's' && i
!= '\33')
607 lprcat("deposit\nHow much? ");
608 amt
= readnum((long)c
[GOLD
]);
609 if (amt
> (unsigned)c
[GOLD
]) {
610 lprcat(" You don't have that much.");
614 c
[BANKACCOUNT
] += amt
;
619 lprcat("withdraw\nHow much? ");
620 amt
= readnum((long)c
[BANKACCOUNT
]);
621 if (amt
> (unsigned)c
[BANKACCOUNT
]) {
622 lprcat("\nYou don't have that much in the bank!");
626 c
[BANKACCOUNT
] -= amt
;
631 lprcat("\nWhich stone would you like to sell? ");
633 while ((i
< 'a' || i
> 'z') && i
!= '*')
636 for (i
= 0; i
< 26; i
++) {
638 c
[GOLD
] += gemvalue
[i
];
642 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
647 if (gemvalue
[i
= i
- 'a'] == 0) {
648 lprintf("\nItem %c is not a gemstone!", i
+ 'a');
652 c
[GOLD
] += gemvalue
[i
];
656 cursor((k
% 2) * 40 + 1, (k
>> 1) + 4);
665 lprintf("%8d", (long)c
[BANKACCOUNT
]);
667 lprintf("%8d", (long)c
[GOLD
]);
671 function for the trading post
677 lprcat("Welcome to the Larn Trading Post. We buy items that explorers no longer find\n");
678 lprcat("useful. Since the condition of the items you bring in is not certain,\n");
679 lprcat("and we incur great expense in reconditioning the items, we usually pay\n");
680 lprcat("only 20% of their value were they to be new. If the items are badly\n");
681 lprcat("damaged, we will pay only 10% of their new value.\n\n");
687 int i
, j
, value
, isub
, izarg
;
688 dnditm
= dndcount
= 0;
689 nosignal
= 1; /* disable signals */
693 lprcat("\nWhat item do you want to sell to us [");
695 lprcat(" for list, or ");
699 while (i
> 'z' || (i
< 'a' && i
!= '*' && i
!= '\33' && i
!= '.')) i
= getchr();
704 nosignal
= 0; /* enable signals */
709 if (iven
[isub
] == OSCROLL
)
710 if (scrollname
[ivenarg
[isub
]][0] == 0) {
713 } /* can't sell unidentified item */
714 if (iven
[isub
] == OPOTION
)
715 if (potionname
[ivenarg
[isub
]][0] == 0) {
718 } /* can't sell unidentified item */
724 } else if (iven
[isub
] == 0)
725 lprintf("\nYou don't have item %c!", isub
+ 'a');
727 for (j
= 0; j
< maxitm
; j
++)
728 if ((itm_
[j
].obj
== iven
[isub
]) || (iven
[isub
] == ODIAMOND
) || (iven
[isub
] == ORUBY
) || (iven
[isub
] == OEMERALD
) || (iven
[isub
] == OSAPPHIRE
)) {
730 show3(isub
); /* show what the item was */
731 if ((iven
[isub
] == ODIAMOND
) || (iven
[isub
] == ORUBY
)
732 || (iven
[isub
] == OEMERALD
) || (iven
[isub
] == OSAPPHIRE
))
733 value
= 20 * ivenarg
[isub
];
734 else if ((itm_
[j
].obj
== OSCROLL
) || (itm_
[j
].obj
== OPOTION
)) value
= 2 * itm_
[j
+ ivenarg
[isub
]].price
;
736 izarg
= ivenarg
[isub
];
737 value
= itm_
[j
].price
; /* appreciate if a +n object */
740 while ((izarg
-- > 0) && ((value
= 14 * (67 + value
) / 10) < 500000))
743 lprintf("\nItem (%c) is worth %d gold pieces to us. Do you want to sell it? ", i
, (long)value
);
745 if (getyn() == 'y') {
750 if (c
[WIELD
] == isub
)
752 if (c
[SHIELD
] == isub
)
754 adjustcvalues(iven
[isub
], ivenarg
[isub
]);
757 lprcat("no thanks.\n");
758 j
= maxitm
+ 100; /* get out of the inner loop */
761 lprcat("\nSo sorry, but we are not authorized to accept that item.");
770 lprcat("\nSorry, we can't accept unidentified objects.");
774 * for the Larn Revenue Service
781 first
= nosignal
= 1; /* disable signals */
785 lprcat("Welcome to the Larn Revenue Service district office. How can we help you?");
792 lprcat("\n\nYour wish? [(");
794 lprcat(") pay taxes, or ");
799 while (i
!= 'p' && i
!= '\33')
803 lprcat("pay taxes\nHow much? ");
804 amt
= readnum((long)c
[GOLD
]);
805 if (amt
> (unsigned)c
[GOLD
])
806 lprcat(" You don't have that much.\n");
808 c
[GOLD
] -= paytaxes((long)amt
);
812 nosignal
= 0; /* enable signals */
819 if (outstanding_taxes
> 0)
820 lprintf("You presently owe %d gp in taxes. ", (long)outstanding_taxes
);
822 lprcat("You do not owe us any taxes. ");
825 lprintf("You have %6d gp. ", (long)c
[GOLD
]);
827 lprcat("You have no gold pieces. ");