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