Initial import from FreeBSD RELENG_4:
[dragonfly.git] / games / larn / store.c
1 /*-
2  * Copyright (c) 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33
34 #ifndef lint
35 #if 0
36 static char sccsid[] = "@(#)store.c     5.4 (Berkeley) 5/13/91";
37 #endif
38 static const char rcsid[] =
39  "$FreeBSD: src/games/larn/store.c,v 1.5 1999/11/30 03:49:00 billf Exp $";
40 #endif /* not lint */
41
42 /*      store.c         Larn is copyrighted 1986 by Noah Morgan. */
43 #include "header.h"
44 static int dndcount=0,dnditm=0;
45
46 /*      this is the data for the stuff in the dnd store */
47 int maxitm=83;  /* number of items in the dnd inventory table   */
48 struct _itm itm[90] = {
49 /*cost    memory        iven name       iven arg   how
50   gp     pointer          iven[]        ivenarg[]  many */
51
52 { 2,            0,              OLEATHER,               0,              3       },
53 { 10,           0,              OSTUDLEATHER,   0,              2       },
54 { 40,           0,              ORING,                  0,              2       },
55 { 85,           0,              OCHAIN,                 0,              2       },
56 { 220,          0,              OSPLINT,                0,              1       },
57 { 400,          0,              OPLATE,                 0,              1       },
58 { 900,          0,              OPLATEARMOR,    0,              1       },
59 { 2600,         0,              OSSPLATE,               0,              1       },
60 { 150,          0,              OSHIELD,                0,              1       },
61
62 /*cost    memory        iven name       iven arg   how
63   gp     pointer          iven[]        ivenarg[]  many */
64
65 { 2,            0,              ODAGGER,                0,              3       },
66 { 20,           0,              OSPEAR,                 0,              3       },
67 { 80,           0,              OFLAIL,                 0,              2       },
68 { 150,          0,              OBATTLEAXE,             0,              2       },
69 { 450,          0,              OLONGSWORD,             0,              2       },
70 { 1000,         0,              O2SWORD,                0,              2       },
71 { 5000,         0,              OSWORD,                 0,              1       },
72 { 16500,        0,              OLANCE,                 0,              1       },
73 { 6000,         0,       OSWORDofSLASHING,      0,              0       },
74 { 10000,        0,              OHAMMER,                0,              0       },
75
76 /*cost    memory        iven name       iven arg   how
77   gp     pointer          iven[]        ivenarg[]  many */
78
79 { 150,          0,              OPROTRING,              1,              1       },
80 { 85,           0,              OSTRRING,               1,              1       },
81 { 120,          0,              ODEXRING,               1,              1       },
82 { 120,          0,              OCLEVERRING,    1,              1       },
83 { 180,          0,              OENERGYRING,    0,              1       },
84 { 125,          0,              ODAMRING,               0,              1       },
85 { 220,          0,              OREGENRING,             0,              1       },
86 { 1000,         0,              ORINGOFEXTRA,   0,              1       },
87
88 { 280,          0,              OBELT,                  0,              1       },
89
90 { 400,          0,              OAMULET,                0,              1       },
91
92 { 6500,         0,              OORBOFDRAGON,   0,              0       },
93 { 5500,         0,              OSPIRITSCARAB,  0,              0       },
94 { 5000,         0,              OCUBEofUNDEAD,  0,              0       },
95 { 6000,         0,              ONOTHEFT,               0,              0       },
96
97 { 590,          0,              OCHEST,                 6,              1       },
98 { 200,          0,              OBOOK,                  8,              1       },
99 { 10,           0,              OCOOKIE,                0,              3       },
100
101 /*cost    memory        iven name       iven arg   how
102   gp     pointer          iven[]        ivenarg[]  many */
103
104 {       20,             potionname,     OPOTION,        0,              6       },
105 {       90,             potionname,     OPOTION,        1,              5       },
106 {       520,    potionname,     OPOTION,        2,              1       },
107 {       100,    potionname,     OPOTION,        3,              2       },
108 {       50,             potionname,     OPOTION,        4,              2       },
109 {       150,    potionname,     OPOTION,        5,              2       },
110 {       70,             potionname,     OPOTION,        6,              1       },
111 {       30,             potionname,     OPOTION,        7,              7       },
112 {       200,    potionname,     OPOTION,        8,              1       },
113 {       50,             potionname,     OPOTION,        9,              1       },
114 {       80,             potionname,     OPOTION,        10,             1       },
115
116 /*cost    memory        iven name       iven arg   how
117   gp     pointer          iven[]        ivenarg[]  many */
118
119 {       30,             potionname,     OPOTION,        11,             3       },
120 {       20,             potionname,     OPOTION,        12,             5       },
121 {       40,             potionname,     OPOTION,        13,             3       },
122 {       35,             potionname,     OPOTION,        14,             2       },
123 {       520,    potionname,     OPOTION,        15,             1       },
124 {       90,             potionname,     OPOTION,        16,             2       },
125 {       200,    potionname,     OPOTION,        17,             2       },
126 {       220,    potionname,     OPOTION,        18,             4       },
127 {       80,             potionname,     OPOTION,        19,             6       },
128 {       370,    potionname,     OPOTION,        20,             3       },
129 {       50,             potionname,     OPOTION,        22,             1       },
130 {       150,    potionname,     OPOTION,        23,             3       },
131
132 /*cost    memory        iven name       iven arg   how
133   gp     pointer          iven[]        ivenarg[]  many */
134
135 { 100,  scrollname,             OSCROLL,        0,              2       },
136 { 125,  scrollname,             OSCROLL,        1,              2       },
137 { 60,   scrollname,             OSCROLL,        2,              4       },
138 { 10,   scrollname,             OSCROLL,        3,              4       },
139 { 100,  scrollname,             OSCROLL,        4,              3       },
140 { 200,  scrollname,             OSCROLL,        5,              2       },
141 { 110,  scrollname,             OSCROLL,        6,              1       },
142 { 500,  scrollname,             OSCROLL,        7,              2       },
143 { 200,  scrollname,             OSCROLL,        8,              2       },
144 { 250,  scrollname,             OSCROLL,        9,              4       },
145 { 20,   scrollname,             OSCROLL,        10,             5       },
146 { 30,   scrollname,             OSCROLL,        11,             3       },
147
148 /*cost    memory        iven name       iven arg   how
149   gp     pointer          iven[]        ivenarg[]  many */
150
151 { 340,  scrollname,             OSCROLL,        12,             1       },
152 { 340,  scrollname,             OSCROLL,        13,             1       },
153 { 300,  scrollname,             OSCROLL,        14,             2       },
154 { 400,  scrollname,             OSCROLL,        15,             2       },
155 { 500,  scrollname,             OSCROLL,        16,             2       },
156 { 1000, scrollname,             OSCROLL,        17,             1       },
157 { 500,  scrollname,             OSCROLL,        18,             1       },
158 { 340,  scrollname,             OSCROLL,        19,             2       },
159 { 220,  scrollname,             OSCROLL,        20,             3       },
160 { 3900, scrollname,             OSCROLL,        21,             0       },
161 { 610,  scrollname,             OSCROLL,        22,             1       },
162 { 3000, scrollname,             OSCROLL,        23,             0       }
163  };
164
165 /*
166         function for the dnd store
167  */
168 dnd_2hed()
169     {
170         lprcat("Welcome to the Larn Thrift Shoppe.  We stock many items explorers find useful\n");
171         lprcat(" in their adventures.  Feel free to browse to your hearts content.\n");
172         lprcat("Also be advised, if you break 'em, you pay for 'em.");
173         }
174
175 static void dnditem();
176
177 dnd_hed()
178         {
179         int i;
180         for (i=dnditm; i<26+dnditm; i++)        dnditem(i);
181         cursor(50,18); lprcat("You have ");
182         }
183
184 static void
185 handsfull()
186 {
187         lprcat("\nYou can't carry anything more!");
188         lflush();
189         nap(2200);
190 }
191
192 static void
193 outofstock()
194 {
195         lprcat("\nSorry, but we are out of that item.");
196         lflush();
197         nap(2200);
198 }
199
200 static void nogold()
201 {
202         lprcat("\nYou don't have enough gold to pay for that!");
203         lflush();
204         nap(2200);
205 }
206
207 dndstore()
208   {
209   int i;
210   dnditm = 0;
211   nosignal = 1; /* disable signals */
212   clear();  dnd_2hed();
213   if (outstanding_taxes>0)
214         {
215         lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n"); beep();
216         lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n",(long)outstanding_taxes);
217         lprcat("comply with the law, we cannot serve you at this time.  Soo Sorry.\n");
218         cursors();
219         lprcat("\nPress "); standout("escape"); lprcat(" to leave: "); lflush();
220         i=0;
221         while (i!='\33') i=getchar();
222         drawscreen();  nosignal = 0; /* enable signals */ return;
223         }
224
225   dnd_hed();
226   while (1)
227         {
228         cursor(59,18); lprintf("%d gold pieces",(long)c[GOLD]);
229         cltoeoln(); cl_dn(1,20);        /* erase to eod */
230         lprcat("\nEnter your transaction ["); standout("space");
231         lprcat(" for more, "); standout("escape");
232         lprcat(" to leave]? ");
233         i=0;
234         while ((i<'a' || i>'z') && (i!=' ') && (i!='\33') && (i!=12))  i=getchar();
235         if (i==12) { clear();  dnd_2hed();  dnd_hed(); }
236         else if (i=='\33')
237                 { drawscreen();  nosignal = 0; /* enable signals */ return; }
238         else if (i==' ')
239                 {
240                 cl_dn(1,4);
241                 if ((dnditm += 26) >= maxitm) dnditm=0; dnd_hed();
242                 }
243         else
244                 {  /* buy something */
245                 lprc(i);        /* echo the byte */
246                 i += dnditm - 'a';
247                 if (i>=maxitm) outofstock(); else
248                 if (itm[i].qty <= 0) outofstock(); else
249                 if (pocketfull()) handsfull(); else
250                 if (c[GOLD] < itm[i].price*10) nogold(); else
251                         {
252                         if (itm[i].mem != 0) *itm[i].mem[itm[i].arg] = ' ';
253                         c[GOLD] -= itm[i].price*10;
254                         itm[i].qty--;  take(itm[i].obj,itm[i].arg);
255                         if (itm[i].qty==0) dnditem(i);  nap(1001);
256                         }
257                 }
258
259         }
260   }
261
262 /*
263         dnditem(index)
264
265         to print the item list;  used in dndstore() enter with the index into itm
266  */
267 static void
268 dnditem(i)
269         int i;
270         {
271         int j,k;
272         if (i >= maxitm)  return;
273         cursor( (j=(i&1)*40+1) , (k=((i%26)>>1)+5) );
274         if (itm[i].qty == 0)  { lprintf("%39s","");  return; }
275         lprintf("%c) ",(i%26)+'a');
276         if (itm[i].obj == OPOTION)
277                 { lprcat("potion of "); lprintf("%s",&potionname[itm[i].arg][1]); }
278         else if (itm[i].obj == OSCROLL)
279                 { lprcat("scroll of "); lprintf("%s",&scrollname[itm[i].arg][1]); }
280         else lprintf("%s",objectname[itm[i].obj]);
281         cursor( j+31,k );  lprintf("%6d",(long)(itm[i].price*10));
282         }
283
284 \f
285 /*
286         for the college of larn
287  */
288 char course[26]={0};    /*      the list of courses taken       */
289 char coursetime[] = { 10, 15, 10, 20, 10, 10, 10, 5 };
290 /*
291         function to display the header info for the school
292  */
293 sch_hed()
294         {
295         clear();
296         lprcat("The College of Larn offers the exciting opportunity of higher education to\n");
297         lprcat("all inhabitants of the caves.  Here is a list of the class schedule:\n\n\n");
298         lprcat("\t\t    Course Name \t       Time Needed\n\n");
299
300         if (course[0]==0) lprcat("\t\ta)  Fighters Training I         10 mobuls"); /*line 7 of crt*/
301         lprc('\n');
302         if (course[1]==0) lprcat("\t\tb)  Fighters Training II        15 mobuls");
303         lprc('\n');
304         if (course[2]==0) lprcat("\t\tc)  Introduction to Wizardry    10 mobuls");
305         lprc('\n');
306         if (course[3]==0) lprcat("\t\td)  Applied Wizardry            20 mobuls");
307         lprc('\n');
308         if (course[4]==0) lprcat("\t\te)  Behavioral Psychology       10 mobuls");
309         lprc('\n');
310         if (course[5]==0) lprcat("\t\tf)  Faith for Today             10 mobuls");
311         lprc('\n');
312         if (course[6]==0) lprcat("\t\tg)  Contemporary Dance          10 mobuls");
313         lprc('\n');
314         if (course[7]==0) lprcat("\t\th)  History of Larn              5 mobuls");
315
316         lprcat("\n\n\t\tAll courses cost 250 gold pieces.");
317         cursor(30,18);
318         lprcat("You are presently carrying ");
319         }
320
321 oschool()
322         {
323         int i;
324         long time_used;
325         nosignal = 1; /* disable signals */
326         sch_hed();
327         while (1)
328                 {
329                 cursor(57,18); lprintf("%d gold pieces.   ",(long)c[GOLD]); cursors();
330                 lprcat("\nWhat is your choice ["); standout("escape");
331                 lprcat(" to leave] ? ");  yrepcount=0;
332                 i=0;  while ((i<'a' || i>'h') && (i!='\33') && (i!=12)) i=getchar();
333                 if (i==12) { sch_hed();  continue; }
334                 else if (i=='\33')
335                         { nosignal = 0; drawscreen();  /* enable signals */ return; }
336                 lprc(i);
337                 if (c[GOLD] < 250)  nogold();  else
338                 if (course[i-'a'])
339                         { lprcat("\nSorry, but that class is filled."); nap(1000); }
340                 else
341                 if (i <= 'h')
342                         {
343                         c[GOLD] -= 250; time_used=0;
344                         switch(i)
345                                 {
346                                 case 'a':       c[STRENGTH] += 2;  c[CONSTITUTION]++;
347                                                         lprcat("\nYou feel stronger!");
348                                                         cl_line(16,7);
349                                                         break;
350
351                                 case 'b':       if (course[0]==0)
352                                                                 {
353                                                                 lprcat("\nSorry, but this class has a prerequisite of Fighters Training I");
354                                                                 c[GOLD]+=250;  time_used= -10000;  break;
355                                                                 }
356                                                         lprcat("\nYou feel much stronger!");
357                                                         cl_line(16,8);
358                                                         c[STRENGTH] += 2;  c[CONSTITUTION] += 2;  break;
359
360                                 case 'c':       c[INTELLIGENCE] += 2;
361                                                         lprcat("\nThe task before you now seems more attainable!");
362                                                         cl_line(16,9);  break;
363
364                                 case 'd':       if (course[2]==0)
365                                                                 {
366                                                                 lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry");
367                                                                 c[GOLD]+=250;  time_used= -10000;  break;
368                                                                 }
369                                                         lprcat("\nThe task before you now seems very attainable!");
370                                                         cl_line(16,10);
371                                                         c[INTELLIGENCE] += 2;  break;
372
373                                 case 'e':       c[CHARISMA] += 3;
374                                                         lprcat("\nYou now feel like a born leader!");
375                                                         cl_line(16,11);  break;
376
377                                 case 'f':       c[WISDOM] += 2;
378                                                         lprcat("\nYou now feel more confident that you can find the potion in time!");
379                                                         cl_line(16,12);  break;
380
381                                 case 'g':       c[DEXTERITY] += 3;
382                                                         lprcat("\nYou feel like dancing!");
383                                                         cl_line(16,13);  break;
384
385                                 case 'h':       c[INTELLIGENCE]++;
386                                                         lprcat("\nYour instructor told you that the Eye of Larn is rumored to be guarded\n");
387                                                         lprcat("by a platinum dragon who possesses psionic abilities. ");
388                                                         cl_line(16,14);  break;
389                                 }
390                         time_used += coursetime[i-'a']*100;
391                         if (time_used > 0)
392                           {
393                           gtime += time_used;
394                           course[i-'a']++;      /*      remember that he has taken that course  */
395                           c[HP] = c[HPMAX];  c[SPELLS] = c[SPELLMAX]; /* he regenerated */
396
397                           if (c[BLINDCOUNT])    c[BLINDCOUNT]=1;  /* cure blindness too!  */
398                           if (c[CONFUSE])               c[CONFUSE]=1;   /*      end confusion   */
399                           adjtime((long)time_used);     /* adjust parameters for time change */
400                           }
401                         nap(1000);
402                         }
403                 }
404         }
405 \f
406 /*
407  *      for the first national bank of Larn
408  */
409 int lasttime=0; /* last time he was in bank */
410 static void banktitle();
411
412 obank()
413         {
414         banktitle("    Welcome to the First National Bank of Larn.");
415         }
416 obank2()
417         {
418         banktitle("Welcome to the 5th level branch office of the First National Bank of Larn.");
419         }
420 static void
421 banktitle(str)
422         char *str;
423         {
424         nosignal = 1; /* disable signals */
425         clear();  lprcat(str);
426         if (outstanding_taxes>0)
427                 {
428                 int i;
429                 lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n"); beep();
430                 lprintf("levied taxes have been paid.  They have also told us that you owe %d gp in\n",(long)outstanding_taxes);
431                 lprcat("taxes, and we must comply with them. We cannot serve you at this time.  Sorry.\n");
432                 lprcat("We suggest you go to the LRS office and pay your taxes.\n");
433                 cursors();
434                 lprcat("\nPress "); standout("escape"); lprcat(" to leave: "); lflush();
435                 i=0;
436                 while (i!='\33') i=getchar();
437                 drawscreen();  nosignal = 0; /* enable signals */ return;
438                 }
439         lprcat("\n\n\tGemstone\t      Appraisal\t\tGemstone\t      Appraisal");
440         obanksub();             nosignal = 0; /* enable signals */
441         drawscreen();
442         }
443
444 /*
445  *      function to put interest on your bank account
446  */
447 ointerest()
448         {
449         int i;
450         if (c[BANKACCOUNT]<0) c[BANKACCOUNT] = 0;
451         else if ((c[BANKACCOUNT]>0) && (c[BANKACCOUNT]<500000))
452                 {
453                 i = (gtime-lasttime)/100; /* # mobuls elapsed */
454                 while ((i-- > 0) && (c[BANKACCOUNT]<500000))
455                         c[BANKACCOUNT] += c[BANKACCOUNT]/250;
456                 if (c[BANKACCOUNT]>500000) c[BANKACCOUNT]=500000; /* interest limit */
457                 }
458         lasttime = (gtime/100)*100;
459         }
460
461 static short gemorder[26]={0};  /* the reference to screen location for each */
462 static long gemvalue[26]={0};   /* the appraisal of the gems */
463 obanksub()
464         {
465         unsigned long amt;
466         int i,k;
467         ointerest();    /* credit any needed interest */
468
469         for (k=i=0; i<26; i++)
470                 switch(iven[i])
471                         {
472                         case OLARNEYE: case ODIAMOND: case OEMERALD:
473                         case ORUBY: case OSAPPHIRE:
474
475                                         if (iven[i]==OLARNEYE)
476                                                 {
477                                                 gemvalue[i]=250000-((gtime*7)/100)*100;
478                                                 if (gemvalue[i]<50000) gemvalue[i]=50000;
479                                                 }
480                                         else gemvalue[i] = (255&ivenarg[i])*100;
481                                         gemorder[i]=k;
482                                         cursor( (k%2)*40+1 , (k>>1)+4 );
483                                         lprintf("%c) %s",i+'a',objectname[iven[i]]);
484                                         cursor( (k%2)*40+33 , (k>>1)+4 );
485                                         lprintf("%5d",(long)gemvalue[i]);  k++;
486                         };
487         cursor(31,17); lprintf("You have %8d gold pieces in the bank.",(long)c[BANKACCOUNT]);
488         cursor(40,18); lprintf("You have %8d gold pieces",(long)c[GOLD]);
489         if (c[BANKACCOUNT]+c[GOLD] >= 500000)
490                 lprcat("\nNote:  Larndom law states that only deposits under 500,000gp  can earn interest.");
491         while (1)
492                 {
493                 cl_dn(1,20);
494                 lprcat("\nYour wish? [("); standout("d"); lprcat(") deposit, (");
495                 standout("w"); lprcat(") withdraw, ("); standout("s");
496                 lprcat(") sell a stone, or "); standout("escape"); lprcat("]  ");
497                 yrepcount=0;
498                 i=0; while (i!='d' && i!='w' && i!='s' && i!='\33') i=getchar();
499                 switch(i)
500                         {
501                         case 'd':       lprcat("deposit\nHow much? ");  amt = readnum((long)c[GOLD]);
502                                                 if (amt<0) { lprcat("\nSorry, but we can't take negative gold!"); nap(2000); amt=0; } else
503                                                 if (amt>c[GOLD])
504                                                   { lprcat("  You don't have that much.");  nap(2000); }
505                                                 else { c[GOLD] -= amt;  c[BANKACCOUNT] += amt; }
506                                                 break;
507
508                         case 'w':       lprcat("withdraw\nHow much? "); amt = readnum((long)c[BANKACCOUNT]);
509                                                 if (amt<0) { lprcat("\nSorry, but we don't have any negative gold!");  nap(2000); amt=0; }
510                                                 else if (amt > c[BANKACCOUNT])
511                                                   { lprcat("\nYou don't have that much in the bank!"); nap(2000); }
512                                                 else { c[GOLD] += amt;  c[BANKACCOUNT] -= amt; }
513                                                 break;
514
515                         case 's':       lprcat("\nWhich stone would you like to sell? ");
516                                                 i=0; while ((i<'a' || i>'z') && i!='*') i=getchar();
517                                                 if (i=='*')
518                                                   for (i=0; i<26; i++)
519                                                         {
520                                                         if (gemvalue[i])
521                                                                 {
522                                                                 c[GOLD]+=gemvalue[i];  iven[i]=0;
523                                                                 gemvalue[i]=0;  k = gemorder[i];
524                                                                 cursor( (k%2)*40+1 , (k>>1)+4 );
525                                                                 lprintf("%39s","");
526                                                                 }
527                                                         }
528                                                 else
529                                                         {
530                                                         if (gemvalue[i=i-'a']==0)
531                                                                 {
532                                                                 lprintf("\nItem %c is not a gemstone!",i+'a');
533                                                                 nap(2000); break;
534                                                                 }
535                                                         c[GOLD]+=gemvalue[i];  iven[i]=0;
536                                                         gemvalue[i]=0;  k = gemorder[i];
537                                                         cursor( (k%2)*40+1 , (k>>1)+4 ); lprintf("%39s","");
538                                                         }
539                                                 break;
540
541                         case '\33':     return;
542                         };
543                 cursor(40,17); lprintf("%8d",(long)c[BANKACCOUNT]);
544                 cursor(49,18); lprintf("%8d",(long)c[GOLD]);
545                 }
546         }
547
548 /*
549         subroutine to appraise any stone for the bank
550  */
551 appraise(gemstone)
552         int gemstone;
553         {
554         int j,amt;
555         for (j=0; j<26; j++)
556           if (iven[j]==gemstone)
557                 {
558                 lprintf("\nI see you have %s",objectname[gemstone]);
559                 if (gemstone==OLARNEYE) lprcat("  I must commend you.  I didn't think\nyou could get it.");
560                 lprcat("  Shall I appraise it for you? ");  yrepcount=0;
561                 if (getyn()=='y')
562                         {
563                         lprcat("yes.\n  Just one moment please \n");  nap(1000);
564                         if (gemstone==OLARNEYE)
565                                 {
566                                 amt = 250000-((gtime*7)/100)*100;
567                                 if (amt<50000) amt=50000;
568                                 }
569                         else amt = (255 & ivenarg[j]) * 100;
570                         lprintf("\nI can see this is an excellent stone, It is worth %d",(long)amt);
571                         lprcat("\nWould you like to sell it to us? ");  yrepcount=0;
572                         if (getyn()=='y') { lprcat("yes\n"); c[GOLD]+=amt;  iven[j]=0; }
573                         else lprcat("no thank you.\n");
574                         if (gemstone==OLARNEYE) lprcat("It is, of course, your privilege to keep the stone\n");
575                         }
576                 else lprcat("no\nO. K.\n");
577                 }
578         }
579 /*
580         function for the trading post
581  */
582 static otradhead()
583         {
584     clear();
585         lprcat("Welcome to the Larn Trading Post.  We buy items that explorers no longer find\n");
586     lprcat("useful.  Since the condition of the items you bring in is not certain,\n");
587     lprcat("and we incur great expense in reconditioning the items, we usually pay\n");
588     lprcat("only 20% of their value were they to be new.  If the items are badly\n");
589         lprcat("damaged, we will pay only 10% of their new value.\n\n");
590         }
591
592 otradepost()
593   {
594   int i,j,value,isub,izarg;
595   dnditm = dndcount = 0;
596   nosignal = 1; /* disable signals */
597   resetscroll();        otradhead();
598   while (1)
599         {
600         lprcat("\nWhat item do you want to sell to us ["); standout("*");
601         lprcat(" for list, or "); standout("escape"); lprcat("] ? ");
602         i=0; while (i>'z' || (i<'a' && i!='*' && i!='\33' && i!='.')) i=getchar();
603         if (i == '\33')
604                 { setscroll(); recalc(); drawscreen(); nosignal=0; /* enable signals */ return; }
605         isub = i - 'a';         j=0;
606         if (iven[isub]==OSCROLL) if (scrollname[ivenarg[isub]][0]==0)
607                 { j=1; cnsitm(); }      /* can't sell unidentified item */
608         if (iven[isub]==OPOTION) if (potionname[ivenarg[isub]][0]==0)
609                 { j=1; cnsitm(); }      /* can't sell unidentified item */
610         if (!j)
611           if (i=='*') { clear(); qshowstr(); otradhead(); }
612         else  if (iven[isub]==0)  lprintf("\nYou don't have item %c!",isub+'a');
613         else
614                 {
615                 for (j=0; j<maxitm; j++)
616                   if ((itm[j].obj == iven[isub]) || (iven[isub] == ODIAMOND) || (iven[isub] == ORUBY) || (iven[isub] == OEMERALD) || (iven[isub] == OSAPPHIRE))
617                         {
618                         srcount=0;  show3(isub);        /* show what the item was */
619                         if ((iven[isub] == ODIAMOND) || (iven[isub] == ORUBY)
620                                 || (iven[isub] == OEMERALD) || (iven[isub] == OSAPPHIRE))
621                                 value = 20*ivenarg[isub];
622                         else
623                         if ((itm[j].obj == OSCROLL) || (itm[j].obj == OPOTION))  value = 2*itm[j+ivenarg[isub]].price;
624                         else
625                                 {
626                                 izarg=ivenarg[isub];  value = itm[j].price;     /* appreciate if a +n object */
627                                 if (izarg >= 0) value *= 2;
628                                 while ((izarg-- > 0) && ((value=14*(67+value)/10) < 500000));
629                                 }
630                         lprintf("\nItem (%c) is worth %d gold pieces to us.  Do you want to sell it? ",i,(long)value);
631                         yrepcount=0;
632                         if (getyn()=='y')
633                                 {
634                                 lprcat("yes\n"); c[GOLD]+=value;
635                                 if (c[WEAR] == isub) c[WEAR] = -1;
636                                 if (c[WIELD] == isub) c[WIELD] = -1;
637                                 if (c[SHIELD] == isub) c[SHIELD] = -1;
638                                 adjustcvalues(iven[isub],ivenarg[isub]);
639                                 iven[isub]=0;
640                                 }
641                         else lprcat("no thanks.\n");
642                         j = maxitm+100; /* get out of the inner loop */
643                         }
644                 if (j <= maxitm+2) lprcat("\nSo sorry, but we are not authorized to accept that item.");
645                 }
646         }
647   }
648
649 cnsitm()
650         { lprcat("\nSorry, we can't accept unidentified objects."); }
651
652 /*
653  *      for the Larn Revenue Service
654  */
655 olrs()
656         {
657         int i,first;
658         unsigned long amt;
659         first = nosignal = 1; /* disable signals */
660         clear();  resetscroll(); cursor(1,4);
661         lprcat("Welcome to the Larn Revenue Service district office.  How can we help you?");
662         while (1)
663                 {
664                 if (first) { first=0; goto nxt; }
665                 cursors();
666                 lprcat("\n\nYour wish? [(");
667                 standout("p");
668                 lprcat(") pay taxes, or ");
669                 standout("escape");
670                 lprcat("]  ");  yrepcount=0;
671                 i=0; while (i!='p' && i!='\33') i=getchar();
672                 switch(i)
673                         {
674                         case 'p':       lprcat("pay taxes\nHow much? "); amt = readnum((long)c[GOLD]);
675                                                 if (amt<0) { lprcat("\nSorry, but we can't take negative gold\n"); amt=0; } else
676                                                 if (amt>c[GOLD])        lprcat("  You don't have that much.\n");
677                                                 else  c[GOLD] -= paytaxes((long)amt);
678                                                 break;
679
680                         case '\33':     nosignal = 0; /* enable signals */
681                                                 setscroll(); drawscreen();      return;
682                         };
683
684 nxt:    cursor(1,6);
685                 if (outstanding_taxes>0)
686                         lprintf("You presently owe %d gp in taxes.  ",(long)outstanding_taxes);
687                 else
688                         lprcat("You do not owe us any taxes.           ");
689                 cursor(1,8);
690                 if (c[GOLD]>0)
691                         lprintf("You have %6d gp.    ",(long)c[GOLD]);
692                 else
693                         lprcat("You have no gold pieces.  ");
694                 }
695         }