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