VMS Larn 12.0 is here! (part 6 of 6)

16 views
Skip to first unread message

u566393908ea

unread,
Aug 30, 1986, 6:08:11 PM8/30/86
to
Hello all! This is a port of Larn v12.0 to VAX/VMS. Now everyone can save
his/her daughter!! Just unpack using /bin/sh and read readme.txt.

- Mark Nagel

P.S. Thanks to Lord Kahless for letting me post this!

-------------------------------cut here-------------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# object.c
# scores.c
# store.c
# This archive created: Sat Aug 30 14:53:02 1986
export PATH; PATH=/bin:$PATH
echo shar: extracting "'object.c'" '(28817 characters)'
if test -f 'object.c'
then
echo shar: will not over-write existing file "'object.c'"
else
cat << \SHAR_EOF > 'object.c'

/* object.c Larn is copyrighted 1986 by Noah Morgan. */

#include "header.h"

/*
***************
LOOK_FOR_OBJECT
***************

subroutine to look for an object and give the player his options
if an object was found.
*/

lookforobject ()
{
register int i,j;

if (c[TIMESTOP])
return; /* can't find objects is time is stopped */
i = item[playerx][playery];
if (i == 0)
return;
showcell (playerx, playery);
cursors ();
yrepcount = 0;
switch (i) {
case OGOLDPILE:
case OMAXGOLD:
case OKGOLD:
case ODGOLD:
lprcat ("\n\nYou have found some gold!");
ogold (i);
break;

case OPOTION:
lprcat ("\n\nYou have found a magic potion");
i = iarg[playerx][playery];
if (potionname[i][0])
lprintf (" of %s", &potionname[i][1]);
opotion (i);
break;

case OSCROLL:
lprcat ("\n\nYou have found a magic scroll");
i = iarg[playerx][playery];
if (scrollname[i][0])
lprintf (" of %s", &scrollname[i][1]);
oscroll (i);
break;

case OALTAR:
if (nearbymonst ())
return;
lprcat ("\n\nThere is a Holy Altar here!");
oaltar ();
break;

case OBOOK:
lprcat ("\n\nYou have found a book.");
obook ();
break;

case OCOOKIE:
lprcat ("\n\nYou have found a fortune cookie.");
ocookie ();
break;

case OTHRONE:
if (nearbymonst ())
return;
lprintf ("\n\nThere is %s here!", objectname[i]);
othrone (0);
break;

case OTHRONE2:
if (nearbymonst ())
return;
lprintf ("\n\nThere is %s here!", objectname[i]);
othrone (1);
break;

case ODEADTHRONE:
lprintf ("\n\nThere is %s here!", objectname[i]);
odeadthrone ();
break;

case OORB:
lprcat ("\n\nYou have found the Orb!!!!!");
oorb ();
break;

case OPIT:
lprcat ("\n\nYou're standing at the top of a pit.");
opit ();
break;

case OSTAIRSUP:
lprcat ("\n\nThere is a circular staircase here");
ostairs (1); /* up */
break;

case OELEVATORUP:
lprcat ("\n\nYou feel heavy for a moment, but the feeling disappears");
oelevator (1); /* up */
break;

case OFOUNTAIN:
if (nearbymonst ())
return;
lprcat ("\n\nThere is a fountain here");
ofountain ();
break;

case OSTATUE:
if (nearbymonst ())
return;
lprcat ("\n\nYou are standing in front of a statue");
ostatue ();
break;

case OCHEST:
lprcat ("\n\nThere is a chest here");
ochest ();
break;

case OIVTELETRAP:
if (rnd (11) < 6)
return;
item[playerx][playery] = OTELEPORTER;
know[playerx][playery] = 1;

case OTELEPORTER:
lprcat ("\nZaaaappp! You've been teleported!\n");
beep ();
nap (3000);
oteleport (0);
break;

case OSCHOOL:
if (nearbymonst ())
return;
lprcat ("\n\nYou have found the College of Larn.");
lprcat ("\nDo you (g) go inside, or (i) stay here? ");
i = 0;
while ((i != 'g') && (i != 'i') && (i != '\33'))
i = readchar ();
if (i == 'g') {
oschool (); /* the college of larn */
}
else
lprcat (" stay here");
break;

case OMIRROR:
if (nearbymonst ())
return;
lprcat ("\n\nThere is a mirror here");
omirror ();
break;

case OBANK2:
case OBANK:
if (nearbymonst ())
return;
if (i == OBANK)
lprcat ("\n\nYou have found the bank of Larn.");
else
lprcat ("\n\nYou have found a branch office of the bank of Larn.");
lprcat ("\nDo you (g) go inside, or (i) stay here? ");
j = 0;
while ((j != 'g') && (j != 'i') && (j != '\33'))
j = readchar ();
if (j == 'g') {
if (i == OBANK)
obank ();
else
obank2 (); /* the bank of larn */
}
else
lprcat (" stay here");
break;

case ODEADFOUNTAIN:
if (nearbymonst ())
return;
lprcat ("\n\nThere is a dead fountain here");
break;

case ODNDSTORE:
if (nearbymonst ())
return;
lprcat ("\n\nThere is a DND store here.");
lprcat ("\nDo you (g) go inside, or (i) stay here? ");
i = 0;
while ((i != 'g') && (i != 'i') && (i != '\33'))
i = readchar ();
if (i == 'g')
dndstore (); /* the dnd adventurers store */
else
lprcat (" stay here");
break;

case OSTAIRSDOWN:
lprcat ("\n\nThere is a circular staircase here");
ostairs (-1); /* down */
break;

case OELEVATORDOWN:
lprcat ("\n\nYou feel light for a moment, but the feeling disappears");
oelevator (-1); /* down */
break;

case OOPENDOOR:
lprintf ("\n\nYou have found %s", objectname[i]);
lprcat ("\nDo you (c) close it");
iopts ();
i = 0;
while ((i != 'c') && (i != 'i') && (i != '\33'))
i = readchar ();
if ((i == '\33') || (i == 'i')) {
ignore ();
break;
}
lprcat ("close");
forget ();
item[playerx][playery] = OCLOSEDDOOR;
iarg[playerx][playery] = 0;
playerx = lastpx;
playery = lastpy;
break;

case OCLOSEDDOOR:
lprintf ("\n\nYou have found %s", objectname[i]);
lprcat ("\nDo you (o) try to open it");
iopts ();
i = 0;
while ((i != 'o') && (i != 'i') && (i != '\33'))
i = readchar ();
if ((i == '\33') || (i == 'i')) {
ignore ();
playerx = lastpx;
playery = lastpy;
break;
}
else {
lprcat ("open");
if (rnd (11) < 7) {
switch (iarg[playerx][playery]) {
case 6:
c[AGGRAVATE] += rnd (400);
break;

case 7:
lprcat ("\nYou are jolted by an electric shock ");
lastnum = 274;
losehp (rnd (20));
bottomline ();
break;

case 8:
loselevel ();
break;

case 9:
lprcat ("\nYou suddenly feel weaker ");
if (c[STRENGTH] > 3)
c[STRENGTH]--;
bottomline ();
break;

default:
break;
}
playerx = lastpx;
playery = lastpy;
}
else {
forget ();
item[playerx][playery] = OOPENDOOR;
}
}
break;

case OENTRANCE:
lprcat ("\nYou have found ");
lprcat (objectname[OENTRANCE]);
lprcat ("\nDo you (g) go inside");
iopts ();
i = 0;
while ((i != 'g') && (i != 'i') && (i != '\33'))
i = readchar ();
if (i == 'g') {
newcavelevel (1);
playerx = 33;
playery = MAXY - 2;
item[33][MAXY - 1] = know[33][MAXY - 1] = mitem[33][MAXY - 1] = 0;
draws (0, MAXX, 0, MAXY);
bot_linex ();
return;
}
else
ignore ();
break;

case OVOLDOWN:
lprcat ("\nYou have found ");
lprcat (objectname[OVOLDOWN]);
lprcat ("\nDo you (c) climb down");
iopts ();
i = 0;
while ((i != 'c') && (i != 'i') && (i != '\33'))
i = readchar ();
if ((i == '\33') || (i == 'i')) {
ignore ();
break;
}
if (level != 0) {
lprcat ("\nThe shaft only extends 5 feet downward!");
return;
}
if (packweight () > 45 + 3 * (c[STRENGTH] + c[STREXTRA])) {
lprcat ("\nYou slip and fall down the shaft");
beep ();
lastnum = 275;
losehp (30 + rnd (20));
bottomhp ();
}

else
lprcat ("climb down");
nap (3000);
newcavelevel (MAXLEVEL);
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++)/* put player near volcano shaft */
if (item[j][i] == OVOLUP) {
playerx = j;
playery = i;
j = MAXX;
i = MAXY;
positionplayer ();
}
draws (0, MAXX, 0, MAXY);
bot_linex ();
return;

case OVOLUP:
lprcat ("\nYou have found ");
lprcat (objectname[OVOLUP]);
lprcat ("\nDo you (c) climb up");
iopts ();
i = 0;
while ((i != 'c') && (i != 'i') && (i != '\33'))
i = readchar ();
if ((i == '\33') || (i == 'i')) {
ignore ();
break;
}
if (level != 11) {
lprcat ("\nThe shaft only extends 8 feet upwards before you find a blockage!");
return;
}
if (packweight () > 45 + 5 * (c[STRENGTH] + c[STREXTRA])) {
lprcat ("\nYou slip and fall down the shaft");
beep ();
lastnum = 275;
losehp (15 + rnd (20));
bottomhp ();
return;
}
lprcat ("climb up");
lflush ();
nap (3000);
newcavelevel (0);
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++)/* put player near volcano shaft */
if (item[j][i] == OVOLDOWN) {
playerx = j;
playery = i;
j = MAXX;
i = MAXY;
positionplayer ();
}
draws (0, MAXX, 0, MAXY);
bot_linex ();
return;

case OTRAPARROWIV:
if (rnd (17) < 13)
return; /* for an arrow trap */
item[playerx][playery] = OTRAPARROW;
know[playerx][playery] = 0;

case OTRAPARROW:
lprcat ("\nYou are hit by an arrow");
beep (); /* for an arrow trap */
lastnum = 259;
losehp (rnd (10) + level);
bottomhp ();
return;

case OIVDARTRAP:
if (rnd (17) < 13)
return; /* for a dart trap */
item[playerx][playery] = ODARTRAP;
know[playerx][playery] = 0;

case ODARTRAP:
lprcat ("\nYou are hit by a dart");
beep (); /* for a dart trap */
lastnum = 260;
losehp (rnd (5));
if ((--c[STRENGTH]) < 3)
c[STRENGTH] = 3;
bottomline ();
return;

case OIVTRAPDOOR:
if (rnd (17) < 13)
return; /* for a trap door */
item[playerx][playery] = OTRAPDOOR;
know[playerx][playery] = 1;

case OTRAPDOOR:
lastnum = 272; /* a trap door */
if ((level == MAXLEVEL - 1) || (level == MAXLEVEL + MAXVLEVEL - 1)) {
lprcat ("\nYou fell through a bottomless trap door!");
beep ();
nap (3000);
died (271);
}
lprcat ("\nYou fall through a trap door!");
beep (); /* for a trap door */
losehp (rnd (5 + level));
nap (2000);
newcavelevel (level + 1);
draws (0, MAXX, 0, MAXY);
bot_linex ();
return;


case OTRADEPOST:
if (nearbymonst ())
return;
lprcat ("\nYou have found the Larn trading Post.");
lprcat ("\nDo you (g) go inside, or (i) stay here? ");
i = 0;
while ((i != 'g') && (i != 'i') && (i != '\33'))
i = readchar ();
if (i == 'g')
otradepost ();
else
lprcat ("stay here");
return;

case OHOME:
if (nearbymonst ())
return;
lprcat ("\nYou have found your way home.");
lprcat ("\nDo you (g) go inside, or (i) stay here? ");
i = 0;
while ((i != 'g') && (i != 'i') && (i != '\33'))
i = readchar ();
if (i == 'g')
ohome ();
else
lprcat ("stay here");
return;

case OWALL:
break;

case OANNIHILATION:
died (283);
return; /* annihilated by sphere of annihilation */

case OLRS:
if (nearbymonst ())
return;
lprcat ("\n\nThere is an LRS office here.");
lprcat ("\nDo you (g) go inside, or (i) stay here? ");
i = 0;
while ((i != 'g') && (i != 'i') && (i != '\33'))
i = readchar ();
if (i == 'g')
olrs (); /* the larn revenue service */
else
lprcat (" stay here");
break;

default:
finditem (i);
break;
};
}

/*
function to say what object we found and ask if player wants to take it
*/
finditem (itm)
int itm;
{
int tmp,
i;
lprintf ("\n\nYou have found %s ", objectname[itm]);
tmp = iarg[playerx][playery];
switch (itm) {
case ODIAMOND:
case ORUBY:
case OEMERALD:
case OSAPPHIRE:
case OSPIRITSCARAB:
case OORBOFDRAGON:
case OCUBEofUNDEAD:
case ONOTHEFT:
break;

default:
if (tmp > 0)
lprintf ("+ %d", (long) tmp);
else
if (tmp < 0)
lprintf (" %d", (long) tmp);
}
lprcat ("\nDo you want to (t) take it");
iopts ();
i = 0;
while (i != 't' && i != 'i' && i != '\33')
i = readchar ();
if (i == 't') {
lprcat ("take");
if (take (itm, tmp) == 0)
forget ();
return;
}
ignore ();
}


/*
*******
OSTAIRS
*******

subroutine to process the stair cases
if dir > 0 the up else down
*/
ostairs (dir)
int dir;
{
register int k;
lprcat ("\nDo you (s) stay here ");
if (dir > 0)
lprcat ("(u) go up ");
else
lprcat ("(d) go down ");
lprcat ("or (f) kick stairs? ");

while (1)
switch (readchar ()) {
case '\33':
case 's':
case 'i':
lprcat ("stay here");
return;

case 'f':
lprcat ("kick stairs");
if (rnd (2) == 1)
lprcat ("\nI hope you feel better. Showing anger rids you of frustration.");
else {
k = rnd ((level + 1) << 1);
lprintf ("\nYou hurt your foot dumb dumb! You suffer %d hit points", (long) k);
lastnum = 276;
losehp (k);
bottomline ();
}
return;

case 'u':
lprcat ("go up");
if (dir < 0)
lprcat ("\nThe stairs don't go up!");
else
if (level >= 2 && level != 11) {
k = level;
newcavelevel (level - 1);
draws (0, MAXX, 0, MAXY);
bot_linex ();
}
else
lprcat ("\nThe stairs lead to a dead end!");
return;

case 'd':
lprcat ("go down");
if (dir > 0)
lprcat ("\nThe stairs don't go down!");
else
if (level != 0 && level != 10 && level != 13) {
k = level;
newcavelevel (level + 1);
draws (0, MAXX, 0, MAXY);
bot_linex ();
}
else
lprcat ("\nThe stairs lead to a dead end!");
return;
};
}


/*
*********
OTELEPORTER
*********

subroutine to handle a teleport trap +/- 1 level maximum
*/
oteleport (err)
int err;
{
register int tmp;
if (err)
if (rnd (151) < 3)
died (264); /* stuck in a rock */
c[TELEFLAG] = 1; /* show ?? on bottomline if been teleported */
if (level == 0)
tmp = 0;
else
if (level < MAXLEVEL) {
tmp = rnd (5) + level - 3;
if (tmp >= MAXLEVEL)
tmp = MAXLEVEL - 1;
if (tmp < 1)
tmp = 1;
}
else {
tmp = rnd (3) + level - 2;
if (tmp >= MAXLEVEL + MAXVLEVEL)
tmp = MAXLEVEL + MAXVLEVEL - 1;
if (tmp < MAXLEVEL)
tmp = MAXLEVEL;
}
playerx = rnd (MAXX - 2);
playery = rnd (MAXY - 2);
if (level != tmp)
newcavelevel (tmp);
positionplayer ();
draws (0, MAXX, 0, MAXY);
bot_linex ();
}

/*
*******
OPOTION
*******

function to process a potion
*/
opotion (pot)
int pot;
{
lprcat ("\nDo you (d) drink it, (t) take it");
iopts ();
while (1)
switch (readchar ()) {
case '\33':
case 'i':
ignore ();
return;

case 'd':
lprcat ("drink\n");
forget (); /* destroy potion */
quaffpotion (pot);
return;

case 't':
lprcat ("take\n");
if (take (OPOTION, pot) == 0)
forget ();
return;
};
}

/*
function to drink a potion
*/
quaffpotion (pot)
int pot;
{
register int i,
j,
k;
if (pot < 0 || pot >= MAXPOTION)
return; /* check for within bounds */
potionname[pot][0] = ' ';
switch (pot) {
case 9:
lprcat ("\nYou feel greedy . . .");
nap (2000);
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++)
if ((item[j][i] == OGOLDPILE) || (item[j][i] == OMAXGOLD)) {
know[j][i] = 1;
show1cell (j, i);
}
showplayer ();
return;

case 19:
lprcat ("\nYou feel greedy . . .");
nap (2000);
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++) {
k = item[j][i];
if ((k == ODIAMOND) || (k == ORUBY) || (k == OEMERALD) || (k == OMAXGOLD)
|| (k == OSAPPHIRE) || (k == OLARNEYE) || (k == OGOLDPILE)) {
know[j][i] = 1;
show1cell (j, i);
}
}
showplayer ();
return;

case 20:
c[HP] = c[HPMAX];
break; /* instant healing */

case 1:
lprcat ("\nYou feel better");
if (c[HP] == c[HPMAX])
raisemhp (1);
else
if ((c[HP] += rnd (20) + 20 + c[LEVEL]) > c[HPMAX])
c[HP] = c[HPMAX];
break;

case 2:
lprcat ("\nSuddenly, you feel much more skillful!");
raiselevel ();
raisemhp (1);
return;

case 3:
lprcat ("\nYou feel strange for a moment");
c[rund (6)]++;
break;

case 4:
lprcat ("\nYou feel more self confident!");
c[WISDOM] += rnd (2);
break;

case 5:
lprcat ("\nWow! You feel great!");
if (c[STRENGTH] < 12)
c[STRENGTH] = 12;
else
c[STRENGTH]++;
break;

case 6:
lprcat ("\nYour charm went up by one!");
c[CHARISMA]++;
break;

case 8:
lprcat ("\nYour intelligence went up by one!");
c[INTELLIGENCE]++;
break;

case 10:
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++)
if (mitem[j][i]) {
know[j][i] = 1;
show1cell (j, i);
}
/* monster detection */ return;

case 12:
lprcat ("\nThis potion has no taste to it");
return;

case 15:
lprcat ("\nWOW!!! You feel Super-fantastic!!!");
if (c[HERO] == 0)
for (i = 0; i < 6; i++)
c[i] += 11;
c[HERO] += 250;
break;

case 16:
lprcat ("\nYou have a greater intestinal constitude!");
c[CONSTITUTION]++;
break;

case 17:
lprcat ("\nYou now have incredibly bulging muscles!!!");
if (c[GIANTSTR] == 0)
c[STREXTRA] += 21;
c[GIANTSTR] += 700;
break;

case 18:
lprcat ("\nYou feel a chill run up your spine!");
c[FIRERESISTANCE] += 1000;
break;

case 0:
lprcat ("\nYou fall asleep. . .");
i = rnd (11) - (c[CONSTITUTION] >> 2) + 2;
while (--i > 0) {
parse2 ();
nap (1000);
}
cursors ();
lprcat ("\nYou woke up!");
return;

case 7:
lprcat ("\nYou become dizzy!");
if (--c[STRENGTH] < 3)
c[STRENGTH] = 3;
break;

case 11:
lprcat ("\nYou stagger for a moment . .");
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++)
know[j][i] = 0;
nap (2000);
draws (0, MAXX, 0, MAXY);/* potion of forgetfulness */
return;

case 13:
lprcat ("\nYou can't see anything!");/* blindness */
c[BLINDCOUNT] += 500;
return;

case 14:
lprcat ("\nYou feel confused");
c[CONFUSE] += 20 + rnd (9);
return;

case 21:
lprcat ("\nYou don't seem to be affected");
return; /* cure dianthroritis */

case 22:
lprcat ("\nYou feel a sickness engulf you");/* poison */
c[HALFDAM] += 200 + rnd (200);
return;

case 23:
lprcat ("\nYou feel your vision sharpen");/* see invisible */
c[SEEINVISIBLE] += rnd (1000) + 400;
monstnamelist[INVISIBLESTALKER] = 'I';
return;
};
bottomline (); /* show new stats */
return;
}

/*
*******
OSCROLL
*******

function to process a magic scroll
*/
oscroll (typ)
int typ;
{
lprcat ("\nDo you ");
if (c[BLINDCOUNT] == 0)
lprcat ("(r) read it, ");
lprcat ("(t) take it");
iopts ();
while (1)
switch (readchar ()) {
case '\33':
case 'i':
ignore ();
return;

case 'r':
if (c[BLINDCOUNT])
break;
lprcat ("read");
forget ();
if (typ == 2 || typ == 15) {
show1cell (playerx, playery);
cursors ();
}
/* destroy it */ read_scroll (typ);
return;

case 't':
lprcat ("take");
if (take (OSCROLL, typ) == 0)
forget (); /* destroy it */
return;
};
}

/*
data for the function to read a scroll
*/
static int xh,
yh,
yl,
xl;
static char curse[] = {
BLINDCOUNT, CONFUSE, AGGRAVATE, HASTEMONST, ITCHING,
LAUGHING, DRAINSTRENGTH, CLUMSINESS, INFEEBLEMENT, HALFDAM
};
static char exten[] = {
PROTECTIONTIME, DEXCOUNT, STRCOUNT, CHARMCOUNT,
INVISIBILITY, CANCELLATION, HASTESELF, GLOBE, SCAREMONST, HOLDMONST, TIMESTOP
};
char time_change[] = {
HASTESELF, HERO, ALTPRO, PROTECTIONTIME, DEXCOUNT,
STRCOUNT, GIANTSTR, CHARMCOUNT, INVISIBILITY, CANCELLATION,
HASTESELF, AGGRAVATE, SCAREMONST, STEALTH, AWARENESS, HOLDMONST, HASTEMONST,
FIRERESISTANCE, GLOBE, SPIRITPRO, UNDEADPRO, HALFDAM, SEEINVISIBLE,
ITCHING, CLUMSINESS, WTW
};
/*
* function to adjust time when time warping and taking courses in school
*/
adjtime (tim)
register long tim;
{
register int j;
for (j = 0; j < 26; j++) /* adjust time related parameters */
if (c[time_change[j]])
if ((c[time_change[j]] -= tim) < 1)
c[time_change[j]] = 1;
regen ();
}

/*
function to read a scroll
*/
read_scroll (typ)
int typ;
{
register int i,
j;
if (typ < 0 || typ >= MAXSCROLL)
return; /* be sure we are within bounds */
scrollname[typ][0] = ' ';
switch (typ) {
case 0:
lprcat ("\nYour armor glows for a moment");
enchantarmor ();
return;

case 1:
lprcat ("\nYour weapon glows for a moment");
enchweapon ();
return; /* enchant weapon */

case 2:
lprcat ("\nYou have been granted enlightenment!");
yh = min (playery + 7, MAXY);
xh = min (playerx + 25, MAXX);
yl = max (playery - 7, 0);
xl = max (playerx - 25, 0);
for (i = yl; i < yh; i++)
for (j = xl; j < xh; j++)
know[j][i] = 1;
nap (2000);
draws (xl, xh, yl, yh);
return;

case 3:
lprcat ("\nThis scroll seems to be blank");
return;

case 4:
createmonster (makemonst (level + 1));
return; /* this one creates a monster */

case 5:
something (level); /* create artifact */
return;

case 6:
c[AGGRAVATE] += 800;
return; /* aggravate monsters */

case 7:
gtime += (i = rnd (1000) - 850);/* time warp */

if (i >= 0)
lprintf ("\nYou went forward in time by %d mobuls", (long) ((i + 99) / 100));
else
lprintf ("\nYou went backward in time by %d mobuls", (long) (-(i + 99) / 100));
adjtime ((long) i); /* adjust time for time warping */
return;

case 8:
oteleport (0);
return; /* teleportation */

case 9:
c[AWARENESS] += 1800;
return; /* expanded awareness */

case 10:
c[HASTEMONST] += rnd (55) + 12;
return; /* haste monster */

case 11:
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++)
if (mitem[j][i])
hitp[j][i] = monster[mitem[j][i]].hitpoints;
return; /* monster healing */
case 12:
c[SPIRITPRO] += 300 + rnd (200);
bottomline ();
return; /* spirit protection */

case 13:
c[UNDEADPRO] += 300 + rnd (200);
bottomline ();
return; /* undead protection */

case 14:
c[STEALTH] += 250 + rnd (250);
bottomline ();
return; /* stealth */

case 15:
lprcat ("\nYou have been granted enlightenment!");/* magic mapping */
for (i = 0; i < MAXY; i++)
for (j = 0; j < MAXX; j++)
know[j][i] = 1;
nap (2000);
draws (0, MAXX, 0, MAXY);
return;

case 16:
c[HOLDMONST] += 30;
bottomline ();
return; /* hold monster */

case 17:
for (i = 0; i < 26; i++)/* gem perfection */
switch (iven[i]) {
case ODIAMOND:
case ORUBY:
case OEMERALD:
case OSAPPHIRE:
j = ivenarg[i];
j &= 255;
j <<= 1;
if (j > 255)
j = 255;/* double value */
ivenarg[i] = j;
break;
}
break;

case 18:
for (i = 0; i < 11; i++)
c[exten[i]] <<= 1;/* spell extension */
break;

case 19:
for (i = 0; i < 26; i++) {/* identify */
if (iven[i] == OPOTION)
potionname[ivenarg[i]][0] = ' ';
if (iven[i] == OSCROLL)
scrollname[ivenarg[i]][0] = ' ';
}
break;

case 20:
for (i = 0; i < 10; i++)/* remove curse */
if (c[curse[i]])
c[curse[i]] = 1;
break;

case 21:
annihilate ();
break; /* scroll of annihilation */

case 22:
godirect (22, 150, "The ray hits the %s", 0, ' ');/* pulverization */
break;
case 23:
c[LIFEPROT]++;
break; /* life protection */
};
}


oorb () {
}

opit () {
register int i;
if (rnd (101) < 81)
if (rnd (70) > 9 * c[DEXTERITY] - packweight () || rnd (101) < 5)
if (level == MAXLEVEL - 1)
obottomless ();
else
if (level == MAXLEVEL + MAXVLEVEL - 1)
obottomless ();
else {
if (rnd (101) < 20) {
i = 0;
lprcat ("\nYou fell into a pit! Your fall is cushioned by an unknown force\n");
}
else {
i = rnd (level * 3 + 3);
lprintf ("\nYou fell into a pit! You suffer %d hit points damage", (long) i);
lastnum = 261;/* if he dies scoreboard will say so */
}
losehp (i);
nap (2000);
newcavelevel (level + 1);
draws (0, MAXX, 0, MAXY);
}
}

obottomless () {
lprcat ("\nYou fell into a bottomless pit!");
beep ();
nap (3000);
died (262);
}
oelevator (dir)
int dir;
{
#ifdef lint
int x;
x = dir;
dir = x;
#endif lint
}

ostatue () {
}

omirror () {
}

obook () {
lprcat ("\nDo you ");
if (c[BLINDCOUNT] == 0)
lprcat ("(r) read it, ");
lprcat ("(t) take it");
iopts ();
while (1)
switch (readchar ()) {
case '\33':
case 'i':
ignore ();
return;

case 'r':
if (c[BLINDCOUNT])
break;
lprcat ("read");
/* no more book */ readbook (iarg[playerx][playery]);
forget ();
return;

case 't':
lprcat ("take");
if (take (OBOOK, iarg[playerx][playery]) == 0)
forget (); /* no more book */
return;
};
}

/*
function to read a book
*/
readbook (lev)
register int lev;
{
register int i,
tmp;
if (lev <= 3)
i = rund ((tmp = splev[lev]) ? tmp : 1);
else
i = rnd ((tmp = splev[lev] - 9) ? tmp : 1) + 9;
spelknow[i] = 1;
lprintf ("\nSpell \"%s\": %s\n%s", spelcode[i], spelname[i], speldescript[i]);
if (rnd (10) == 4) {
lprcat ("\nYour int went up by one!");
c[INTELLIGENCE]++;
bottomline ();
}
}

ocookie () {
char *p;
lprcat ("\nDo you (e) eat it, (t) take it");
iopts ();
while (1)
switch (readchar ()) {
case '\33':
case 'i':
ignore ();
return;

case 'e':
lprcat ("eat\nThe cookie tasted good.");
forget (); /* no more cookie */
if (c[BLINDCOUNT])
return;
if (!(p = fortune (fortfile)))
return;
lprcat (" A message inside the cookie reads:\n");
lprcat (p);
return;

case 't':
lprcat ("take");
if (take (OCOOKIE, 0) == 0)
forget (); /* no more book */
return;
};
}


/* routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth 100* the argument */
ogold (arg)
int arg;
{
register long i;
i = iarg[playerx][playery];
if (arg == OMAXGOLD)
i *= 100;
else
if (arg == OKGOLD)
i *= 1000;
else
if (arg == ODGOLD)
i *= 10;
lprintf ("\nIt is worth %d!", (long) i);
c[GOLD] += i;
bottomgold ();
item[playerx][playery] = know[playerx][playery] = 0;/* destroy gold */
}

ohome () {
register int i;
nosignal = 1; /* disable signals */
for (i = 0; i < 26; i++)
if (iven[i] == OPOTION)
if (ivenarg[i] == 21) {
iven[i] = 0; /* remove the potion of cure dianthroritis from inventory */
clear ();
lprcat ("Congratulations. You found a potion of cure dianthroritis.\n");
lprcat ("\nFrankly, No one thought you could do it. Boy! Did you surprise them!\n");
if (gtime > TIMELIMIT) {
lprcat ("\nThe doctor has the sad duty to inform you that your daughter died!\n");
lprcat ("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
nap (5000);
died (269);
}
else {
lprcat ("\nThe doctor is now administering the potion, and in a few moments\n");
lprcat ("Your daughter should be well on her way to recovery.\n");
nap (6000);
lprcat ("\nThe potion is");
nap (3000);
lprcat (" working! The doctor thinks that\n");
lprcat ("your daughter will recover in a few days. Congratulations!\n");
beep ();
nap (5000);
died (263);
}
}

while (1) {
clear ();
lprintf ("Welcome home %s. Latest word from the doctor is not good.\n", logname);

if (gtime > TIMELIMIT) {
lprcat ("\nThe doctor has the sad duty to inform you that your daughter died!\n");
lprcat ("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
nap (5000);
died (269);
}

lprcat ("\nThe diagnosis is confirmed as dianthroritis. He guesses that\n");
lprintf ("your daughter has only %d mobuls left in this world. It's up to you,\n", (long) ((TIMELIMIT - gtime + 99) / 100));
lprintf ("%s, to find the only hope for your daughter, the very rare\n", logname);
lprcat ("potion of cure dianthroritis. It is rumored that only deep in the\n");
lprcat ("depths of the caves can this potion be found.\n\n\n");
lprcat ("\n ----- press ");
standout ("return");
lprcat (" to continue, ");
standout ("escape");
lprcat (" to leave ----- ");
i = readchar ();
while (i != '\33' && i != '\n')
i = readchar ();
if (i == '\33') {
drawscreen ();
nosignal = 0; /* enable signals */
return;
}
}
}

/* routine to save program space */
iopts () {
lprcat (", or (i) ignore it? ");
}
ignore () {
lprcat ("ignore\n");
}
SHAR_EOF
if test 28817 -ne "`wc -c < 'object.c'`"
then
echo shar: error transmitting "'object.c'" '(should have been 28817 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'scores.c'" '(22296 characters)'
if test -f 'scores.c'
then
echo shar: will not over-write existing file "'scores.c'"
else
cat << \SHAR_EOF > 'scores.c'

/* scores.c Larn is copyrighted 1986 by Noah Morgan.
*
* Functions in this file are:
*
* readboard() Function to read in the scoreboard into a static buffer
* writeboard() Function to write the scoreboard from readboard()'s buffer
* makeboard() Function to create a new scoreboard(wipe out old one)
* hashewon() Function to return 1 if player has won a game before, else 0
* long paytaxes(x) Function to pay taxes if any are due
* winshou() Subroutine to print out the winning scoreboard
* shou(x) Subroutine to print out the non-winners scoreboard
* showscores() Function to show the scoreboard on the terminal
* showallscores() Function to show scores and the iven lists that go with them
* sortboard() Function to sort the scoreboard
* newscore(score, whoo, whyded, winner) Function to add entry to scoreboard
* new1sub(score,i,whoo,taxes) Subroutine to put player into a
* new2sub(score,i,whoo,whyded) Subroutine to put player into a
* died(x) Subroutine to record who played larn, and what the score was
* diedsub(x) Subroutine to print out a line showing player when he is killed
* diedlog() Subroutine to read a log file and print it out in ascii format
* getplid(name) Function to get players id # from id file
*
*/
#include <times.h>
#include <stat.h>
#include "header.h"

struct scofmt { /* This is the structure for the scoreboard */
long score; /* the score of the player */
long suid; /* the user id number of the player */
short what; /* the number of the monster that killed player */
short level; /* the level player was on when he died */
short hardlev; /* the level of difficulty player played at */
short order; /* the relative ordering place of this entry */
char who[40]; /* the name of the character */
char sciv[26][2];/* this is the inventory list of the character */
};

struct wscofmt { /* This is the structure for the winning scoreboard */
long score; /* the score of the player */
long timeused; /* the time used in mobuls to win the game */
long taxes; /* taxes he owes to LRS */
long suid; /* the user id number of the player */
short hardlev; /* the level of difficulty player played at */
short order; /* the relative ordering place of this entry */
char who[40]; /* the name of the character */
};

struct log_fmt { /* 102 bytes struct for the log file */
long score; /* the players score */
long diedtime; /* time when game was over */
short cavelev; /* level in caves */
short diff; /* difficulty player played at */
#ifdef EXTRA
long elapsedtime;/* real time of game in seconds */
long bytout; /* bytes input and output */
long bytin;
long moves; /* number of moves made by player */
short ac; /* armor class of player */
short hp,hpmax; /* players hitpoints */
short cputime; /* cpu time needed in seconds */
short killed,
spused; /* monsters killed and spells cast */
short usage; /* usage of the cpu in % */
short lev; /* player level */
#endif
char who[12]; /* player name */
char what[46]; /* what happened to player */
};

static struct scofmt sco[SCORESIZE];/* the structure for the scoreboard */
static struct wscofmt winr[SCORESIZE];/* struct for the winning scoreboard */
static struct log_fmt logg; /* structure for the log file */
static char *whydead[] = {
"quit", "suspended", "self - annihilated", "shot by an arrow",
"hit by a dart", "fell into a pit", "fell into a bottomless pit",
"a winner", "trapped in solid rock", "killed by a missing save file",
"killed by an old save file", "caught by the greedy cheater checker trap",
"killed by a protected save file", "killed his family and committed suicide",
"erased by a wayward finger", "fell through a bottomless trap door",
"fell through a trap door", "drank some poisonous water",
"fried by an electric shock", "slipped on a volcano shaft",
"killed by a stupid act of frustration", "attacked by a revolting demon",
"hit by his own magic", "demolished by an unseen attacker",
"fell into the dreadful sleep", "killed by an exploding chest",
/* 26 */ "killed by a missing maze data file", "annihilated in a sphere",
"died a post mortem death", "wasted by a malloc() failure"
};

/*
* readboard() Function to read in the scoreboard into a static buffer
*
* returns -1 if unable to read in the scoreboard, returns 0 if all is OK
*/
readboard()
{
if (lopen(scorefile) < 0) {
lprcat("Can't read scoreboard\n");
lflush();
return(-1);
}
lrfill((char *) sco, sizeof(sco));
lrfill((char *) winr, sizeof(winr));
lrclose();
lcreat((char *) 0);
return(0);
}

/*
* writeboard() Function to write the scoreboard from readboard()'s buffer
*
* returns -1 if unable to write the scoreboard, returns 0 if all is OK
*/
writeboard()
{
set_score_output();
delete(scorefile); /* otherwise we get many many copies */
if (lcreat(scorefile) < 0) {
lprcat("Can't write scoreboard\n");
lflush();
return(-1);
}
lwrite((char *) sco, sizeof(sco));
lwrite((char *) winr, sizeof(winr));
lwclose();
lcreat((char *) 0);
return(0);
}

/*
* makeboard() Function to create a new scoreboard(wipe out old one)
*
* returns -1 if unable to write the scoreboard, returns 0 if all is OK
*/
makeboard()
{
register int i;

for (i = 0; i < SCORESIZE; i++) {
winr[i].taxes = winr[i].score = sco[i].score = 0;
winr[i].order = sco[i].order = i;
}
if (writeboard())
return(-1);
chmod(scorefile, 0664);
return(0);
}

/*
* hashewon() Function to return 1 if player has won a game before, else 0
*
* This function also sets c[HARDGAME] to appropriate value -- 0 if not a
* winner, otherwise the next level of difficulty listed in the winners
* scoreboard. This function also sets outstanding_taxes to the value in
* the winners scoreboard.
*/
hashewon()
{
register int i;

c[HARDGAME] = 0;
if (readboard() < 0)
return(0); /* can't find scoreboard */
for (i = 0; i < SCORESIZE; i++)/* search through winners scoreboard */
if (winr[i].suid == userid)
if (winr[i].score > 0) {
c[HARDGAME] = winr[i].hardlev + 1;
outstanding_taxes = winr[i].taxes;
return(1);
}
return(0);
}

/*
* long paytaxes(x) Function to pay taxes if any are due
*
* Enter with the amount(in gp) to pay on the taxes.
* Returns amount actually paid.
*/
long paytaxes(x)
long x;
{
register int i;
register long amt;

if (x < 0)
return(0L);
if (readboard() < 0)
return(0L);
for (i = 0; i < SCORESIZE; i++)
if (winr[i].suid == userid)/* look for players winning entry */
if (winr[i].score > 0) {/* search for a winning entry for the player */
amt = winr[i].taxes;
if (x < amt)
amt = x; /* don't overpay taxes(Ughhhhh) */
winr[i].taxes -= amt;
outstanding_taxes -= amt;
if (writeboard() < 0)
return(0);
return(amt);
}
return(0L); /* couldn't find user on winning scoreboard */
}

/*
* winshou() Subroutine to print out the winning scoreboard
*
* Returns the number of players on scoreboard that were shown
*/
winshou()
{
register struct wscofmt *p;
register int i,j,count;

for (count = j = i = 0; i < SCORESIZE; i++)/* is there anyone on the scoreboard? */
if (winr[i].score != 0) {
j++;
break;
}
if (j) {
lprcat("\n Score Difficulty Time Needed Larn Winners List\n");

for (i = 0; i < SCORESIZE; i++)/* this loop is needed to print out the */
for (j = 0; j < SCORESIZE; j++) {/* winners in order */
p = &winr[j]; /* pointer to the scoreboard entry */
if (p -> order == i) {
if (p -> score) {
count++;
lprintf("%10d %2d %5d Mobuls %s \n",
(long) p -> score,(long) p -> hardlev,(long) p -> timeused, p -> who);
}
break;
}
}
}
return(count); /* return number of people on scoreboard */
}

/*
* shou(x) Subroutine to print out the non-winners scoreboard
* int x;
*
* Enter with 0 to list the scores, enter with 1 to list inventories too
* Returns the number of players on scoreboard that were shown
*/
shou(x)
int x;
{
register int i,j,n,k;
int count;

for (count = j = i = 0; i < SCORESIZE; i++)/* is the scoreboard empty? */
if (sco[i].score != 0) {
j++;
break;
}
if (j) {
lprcat("\n Score Difficulty Larn Visitor Log\n");
for (i = 0; i < SCORESIZE; i++)/* be sure to print them out in order */
for (j = 0; j < SCORESIZE; j++)
if (sco[j].order == i) {
if (sco[j].score) {
count++;
lprintf("%10d %2d %s ",
(long) sco[j].score,(long) sco[j].hardlev, sco[j].who);
if (sco[j].what < 256)
lprintf("killed by a %s", monster[sco[j].what].name);
else
lprintf("%s", whydead[sco[j].what - 256]);
if (x != 263)
lprintf(" on %s", levelname[sco[j].level]);
if (x) {
for (n = 0; n < 26; n++) {
iven[n] = sco[j].sciv[n][0];
ivenarg[n] = sco[j].sciv[n][1];
}
for (k = 1; k < 99; k++)
for (n = 0; n < 26; n++)
if (k == iven[n]) {
srcount = 0;
show3(n);
}
lprcat("\n\n");
}
else
lprc('\n');
}
j = SCORESIZE;
}
}
return(count); /* return the number of players just shown */
}

/*
* showscores() Function to show the scoreboard on the terminal
*
* Returns nothing of value
*/
static char esb[] = "The scoreboard is empty.\n";
showscores()
{
register int i,j;

lflush();
lcreat((char *) 0);
if (readboard() < 0)
return;
i = winshou();
j = shou(0);
if (i + j == 0)
lprcat(esb);
else
lprc('\n');
lflush();
}

/*
* showallscores() Function to show scores and the iven lists that go with them
*
* Returns nothing of value
*/
showallscores()
{
register int i,j;

lflush();
lcreat((char *) 0);
if (readboard() < 0)
return;
c[WEAR] = c[WIELD] = c[SHIELD] = -1;/* not wielding or wearing anything */
for (i = 0; i < MAXPOTION; i++)
potionname[i][0] = ' ';
for (i = 0; i < MAXSCROLL; i++)
scrollname[i][0] = ' ';
i = winshou();
j = shou(1);
if (i + j == 0)
lprcat(esb);
else
lprc('\n');
lflush();
}

/*
* sortboard() Function to sort the scoreboard
*
* Returns 0 if no sorting done, else returns 1
*/
sortboard()
{
register int i,j,pos;
long jdat;

for (i = 0; i < SCORESIZE; i++)
sco[i].order = winr[i].order = -1;
pos = 0;
while (pos < SCORESIZE) {
jdat = 0;
for (i = 0; i < SCORESIZE; i++)
if ((sco[i].order < 0) &&(sco[i].score >= jdat)) {
j = i;
jdat = sco[i].score;
}
sco[j].order = pos++;
}
pos = 0;
while (pos < SCORESIZE) {
jdat = 0;
for (i = 0; i < SCORESIZE; i++)
if ((winr[i].order < 0) &&(winr[i].score >= jdat)) {
j = i;
jdat = winr[i].score;
}
winr[j].order = pos++;
}
return(1);
}

/*
* newscore(score, whoo, whyded, winner) Function to add entry to scoreboard
* int score, winner, whyded;
* char *whoo;
*
* Enter with the total score in gp in score, players name in whoo,
* died() reason # in whyded, and TRUE/FALSE in winner if a winner
* ex. newscore(1000, "player 1", 32, 0);
*/
newscore(score, whoo, whyded, winner)
long score;
int winner,whyded;
char *whoo;
{
register int i;
long taxes;

if (readboard() < 0)
return; /* do the scoreboard */
/* if a winner then delete all non-winning scores */
if (cheat)
winner = 0; /* if he cheated, don't let him win */
if (winner) {
for (i = 0; i < SCORESIZE; i++)
if (sco[i].suid == userid)
sco[i].score = 0;
taxes = score * TAXRATE;
score += 100000 * c[HARDGAME];/* bonus for winning */
/* if he has a slot on the winning scoreboard update it if greater score */
for (i = 0; i < SCORESIZE; i++)
if (winr[i].suid == userid) {
new1sub(score, i, whoo, taxes);
return;
}
/* he had no entry. look for last entry and see if he has a greater score */
for (i = 0; i < SCORESIZE; i++)
if (winr[i].order == SCORESIZE - 1) {
new1sub(score, i, whoo, taxes);
return;
}
} else
if (!cheat) { /* for not winning scoreboard */
/* if he has a slot on the scoreboard update it if greater score */
for (i = 0; i < SCORESIZE; i++)
if (sco[i].suid == userid) {
new2sub(score, i, whoo, whyded);
return;
}
/* he had no entry. look for last entry and see if he has a greater score */
for (i = 0; i < SCORESIZE; i++)
if (sco[i].order == SCORESIZE - 1) {
new2sub(score, i, whoo, whyded);
return;
}
}
}

/*
* new1sub(score,i,whoo,taxes) Subroutine to put player into a
* int score,i,whyded,taxes; winning scoreboard entry if his score
* char *whoo; is high enough
*
* Enter with the total score in gp in score, players name in whoo,
* died() reason # in whyded, and TRUE/FALSE in winner if a winner
* slot in scoreboard in i, and the tax bill in taxes.
* Returns nothing of value
*/
new1sub(score, i, whoo, taxes)
long score,taxes;
int i;
char *whoo;
{
register struct wscofmt *p;

p = &winr[i];
p -> taxes += taxes;
if ((score >= p -> score) ||(c[HARDGAME] > p -> hardlev)) {
strcpy(p -> who, whoo);
p -> score = score;
p -> hardlev = c[HARDGAME];
p -> suid = userid;
p -> timeused = gtime / 100;
}
}

/*
* new2sub(score,i,whoo,whyded) Subroutine to put player into a
* int score,i,whyded,taxes; non-winning scoreboard entry if his
* char *whoo; score is high enough
*
* Enter with the total score in gp in score, players name in whoo,
* died() reason # in whyded, and slot in scoreboard in i.
* Returns nothing of value
*/
new2sub(score, i, whoo, whyded)
long score;
int i,whyded;
char *whoo;
{
register int j;
register struct scofmt *p;

p = &sco[i];
if ((score >= p -> score) ||(c[HARDGAME] > p -> hardlev)) {
strcpy(p -> who, whoo);
p -> score = score;
p -> what = whyded;
p -> hardlev = c[HARDGAME];
p -> suid = userid;
p -> level = level;
for (j = 0; j < 26; j++) {
p -> sciv[j][0] = iven[j];
p -> sciv[j][1] = ivenarg[j];
}
}
}

/*
* died(x) Subroutine to record who played larn, and what the score was
* int x;
*
* if x < 0 then don't show scores
* died() never returns!(unless c[LIFEPROT] and a reincarnatable death!)
*
* < 256 killed by the monster number
* 256 quit
* 257 suspended
* 258 self - annihilated
* 259 shot by an arrow
* 260 hit by a dart
* 261 fell into a pit
* 262 fell into a bottomless pit
* 263 a winner
* 264 trapped in solid rock
* 265 killed by a missing save file
* 266 killed by an old save file
* 267 caught by the greedy cheater checker trap
* 268 killed by a protected save file
* 269 killed his family and killed himself
* 270 erased by a wayward finger
* 271 fell through a bottomless trap door
* 272 fell through a trap door
* 273 drank some poisonous water
* 274 fried by an electric shock
* 275 slipped on a volcano shaft
* 276 killed by a stupid act of frustration
* 277 attacked by a revolting demon
* 278 hit by his own magic
* 279 demolished by an unseen attacker
* 280 fell into the dreadful sleep
* 281 killed by an exploding chest
* 282 killed by a missing maze data file
* 283 killed by a sphere of annihilation
* 284 died a post mortem death
* 285 malloc() failure
* 300 quick quit -- don't put on scoreboard
*/

static int scorerror;

died(x)
int x;
{
register int f,win;
char ch,*mod;
long zzz,i;
struct tms cputime;

if (c[LIFEPROT] > 0) { /* if life protection */
switch((x > 0) ? x : -x) {
case 256:
case 257:
case 262:
case 263:
case 265:
case 266:
case 267:
case 268:
case 269:
case 271:
case 282:
case 284:
case 285:
case 300:
goto invalid; /* can't be saved */
};
--c[LIFEPROT];
c[HP] = 1;
--c[CONSTITUTION];
cursors();
lprcat("\nYou feel wiiieeeeerrrrrd all over! ");
beep();
lflush();
sleep(4);
return; /* only case where died() returns */
}
invalid:
clearvt100();
lflush();
f = 0;
if (ckpflag)
delete(ckpfile); /* remove checkpoint file if used */
if (x < 0) {
f++;
x = -x;
} /* if we are not to display the scores */
if ((x == 300) ||(x == 257))
exit(); /* for quick exit or saved game */
if (x == 263)
win = 1;
else
win = 0;
c[GOLD] += c[BANKACCOUNT];
c[BANKACCOUNT] = 0;
/* now enter the player at the end of the scoreboard */
newscore(c[GOLD], logname, x, win);
diedsub(x); /* print out the score line */
lflush();

set_score_output();
if ((wizard == 0) &&(c[GOLD] > 0)) {/* wizards can't score */
if (lappend(logfile) < 0) {/* append to file */
if (lcreat(logfile) < 0) {/* and can't create new log file */
lcreat((char *) 0);
lprcat("\nCan't open record file: I can't post your score.\n");
sncbr();
resetscroll();
lflush();
exit();
}
chmod(logfile, 0666);
}
strcpy(logg.who, loginname);
logg.score = c[GOLD];
logg.diff = c[HARDGAME];
if (x < 256) {
ch = *monster[x].name;
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
mod = "an";
else
mod = "a";
sprintf(logg.what, "killed by %s %s", mod, monster[x].name);
} else
sprintf(logg.what, "%s", whydead[x - 256]);
logg.cavelev = level;
time(&zzz); /* get current time -- write out score info */
logg.diedtime = zzz;
#ifdef EXTRA
times(&cputime); /* get cpu time -- write out score info */
logg.cputime = i = (cputime.tms_utime + cputime.tms_stime - start_cpu) / 100 + c[CPUTIME];
logg.lev = c[LEVEL];
logg.ac = c[AC];
logg.hpmax = c[HPMAX];
logg.hp = c[HP];
logg.elapsedtime = (zzz - initialtime + 59) / 60;
logg.usage = (10000 * i) / (zzz - initialtime);
logg.bytin = c[BYTESIN];
logg.bytout = c[BYTESOUT];
logg.moves = c[MOVESMADE];
logg.spused = c[SPELLSCAST];
logg.killed = c[MONSTKILLED];
#endif
lwrite((char *) & logg, sizeof(struct log_fmt));
lwclose();

/* now for the scoreboard maintenance -- not for a suspended game */
if (x != 257) {
if (sortboard())
scorerror = writeboard();
}
}
if ((x == 256) ||(x == 257) ||(f != 0))
exit();
if (scorerror == 0)
showscores(); /* if we updated the scoreboard */
if (x == 263)
mailbill();
exit();
}

/*
* diedsub(x) Subroutine to print out the line showing the player when he is killed
* int x;
*/
diedsub(x)
int x;
{
register char ch,*mod;

lprintf("Score: %d, Diff: %d, %s ",(long) c[GOLD],(long) c[HARDGAME], logname);
if (x < 256) {
ch = *monster[x].name;
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
mod = "an";
else
mod = "a";
lprintf("killed by %s %s", mod, monster[x].name);
}
else
lprintf("%s", whydead[x - 256]);
if (x != 263)
lprintf(" on %s\n", levelname[level]);
else
lprc('\n');
}

/*
* diedlog() Subroutine to read a log file and print it out in ascii format
*/
diedlog()
{
register int n;
register char *p;
struct stat stbuf;

lcreat((char *) 0);
if (lopen(logfile) < 0) {
lprintf("Can't locate log file \"%s\"\n", logfile);
return;
}
if (fstat(fd, &stbuf) < 0) {
lprintf("Can't stat log file \"%s\"\n", logfile);
return;
}
for (n = stbuf.st_size / sizeof(struct log_fmt); n > 0; --n) {
lrfill((char *) & logg, sizeof(struct log_fmt));
p = ctime(&logg.diedtime);
p[16] = '\n';
p[17] = 0;
lprintf("Score: %d, Diff: %d, %s %s on %d at %s",(long)(logg.score),(long)(logg.diff), logg.who, logg.what,(long)(logg.cavelev), p + 4);
#ifdef EXTRA
if (logg.moves <= 0)
logg.moves = 1;
lprintf(" Experience Level: %d, AC: %d, HP: %d/%d, Elapsed Time: %d minutes\n",
(long)(logg.lev),(long)(logg.ac),(long)(logg.hp),(long)(logg.hpmax),(long)(logg.elapsedtime));
lprintf(" CPU time used: %d seconds, Machine usage: %d.%02d%%\n",
(long)(logg.cputime),(long)(logg.usage / 100),(long)(logg.usage % 100));
lprintf(" BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n",
(long)(logg.bytin),(long)(logg.bytout),(long)(logg.moves),(long)(logg.killed),(long)(logg.spused));
lprintf(" out bytes per move: %d, time per move: %d ms\n",
(long)(logg.bytout / logg.moves),(long)((logg.cputime * 1000) / logg.moves));
#endif
}
lflush();
lrclose();
return;
}

#ifndef UIDSCORE
/*
* getplid(name) Function to get players id # from id file
*
* Enter with the name of the players character in name.
* Returns the id # of the players character, or -1 if failure.
* This routine will try to find the name in the id file, if its not there,
* it will try to make a new entry in the file. Only returns -1 if can't
* find him in the file, and can't make a new entry in the file.
* Format of playerids file:
* Id # in ascii \n character name \n
*/
static int havepid = -1; /* playerid # if previously done */

getplid(nam)
char *nam;
{
int fd7,high = 999,no;
register char *p,*p2;
char name[80];

if (havepid != -1)
return(havepid); /* already did it */
lflush(); /* flush any pending I/O */
sprintf(name, "%s\n", nam); /* append a \n to name */
if (lopen(playerids) < 0) { /* no file, make it */
if (lcreat(playerids) < 0)
return(-1); /* can't make it */
lwclose();
goto addone; /* now append new playerid record to file */
}
for (;;) { /* now search for the name in the player id file */
p = lgetl();
if (p == NULL)
break; /* EOF? */
no = atoi(p); /* the id # */
p2 = lgetl();
if (p2 == NULL)
break; /* EOF? */
if (no > high)
high = no; /* accumulate highest id # */
if (strcmp(p2, name) == 0) {/* we found him */
return(no); /* his id number */
}
}
lrclose();
/* if we get here, we didn't find him in the file -- put him there */
addone:
if (lappend(playerids) < 0)
return(-1); /* can't open file for append */
lprintf("%d\n%s",(long) ++high, name);/* new id # and name */
lwclose();
lcreat((char *) 0); /* re-open terminal channel */
return(high);
}
#endif UIDSCORE
SHAR_EOF
if test 22296 -ne "`wc -c < 'scores.c'`"
then
echo shar: error transmitting "'scores.c'" '(should have been 22296 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'store.c'" '(22511 characters)'
if test -f 'store.c'
then
echo shar: will not over-write existing file "'store.c'"
else
cat << \SHAR_EOF > 'store.c'

/* store.c Larn is copyrighted 1986 by Noah Morgan. */

#include "header.h"

static int dndcount = 0,dnditm = 0;

/* this is the data for the stuff in the dnd store */
int maxitm = 83; /* number of items in the dnd inventory table */

globaldef struct _itm itm[90] = {
/* cost memory iven name iven arg how
gp pointer iven[] ivenarg[] many */

{ 2, 0, OLEATHER, 0, 3 },
{ 10, 0, OSTUDLEATHER, 0, 2 },
{ 40, 0, ORING, 0, 2 },
{ 85, 0, OCHAIN, 0, 2 },
{ 220, 0, OSPLINT, 0, 1 },
{ 400, 0, OPLATE, 0, 1 },
{ 900, 0, OPLATEARMOR, 0, 1 },
{ 2600, 0, OSSPLATE, 0, 1 },
{ 150, 0, OSHIELD, 0, 1 },

/* cost memory iven name iven arg how
gp pointer iven[] ivenarg[] many */

{ 2, 0, ODAGGER, 0, 3 },
{ 20, 0, OSPEAR, 0, 3 },
{ 80, 0, OFLAIL, 0, 2},
{ 150, 0, OBATTLEAXE, 0, 2},
{ 450, 0, OLONGSWORD, 0, 2},
{ 1000, 0, O2SWORD, 0, 2},
{ 5000, 0, OSWORD, 0, 1},
{ 16500, 0, OLANCE, 0, 1},
{ 6000, 0, OSWORDofSLASHING, 0, 0},
{ 10000, 0, OHAMMER, 0, 0 },

/* cost memory iven name iven arg how
gp pointer iven[] ivenarg[] many */

{
150, 0, OPROTRING, 1, 1
}
,
{
85, 0, OSTRRING, 1, 1
}
,
{
120, 0, ODEXRING, 1, 1
}
,
{
120, 0, OCLEVERRING, 1, 1
}
,
{
180, 0, OENERGYRING, 0, 1
}
,
{
125, 0, ODAMRING, 0, 1
}
,
{
220, 0, OREGENRING, 0, 1
}
,
{
1000, 0, ORINGOFEXTRA, 0, 1
}
,

{
280, 0, OBELT, 0, 1
}
,

{
400, 0, OAMULET, 0, 1
}
,

{
6500, 0, OORBOFDRAGON, 0, 0
}
,
{
5500, 0, OSPIRITSCARAB, 0, 0
}
,
{
5000, 0, OCUBEofUNDEAD, 0, 0
}
,
{
6000, 0, ONOTHEFT, 0, 0
}
,

{
590, 0, OCHEST, 6, 1
}
,
{
200, 0, OBOOK, 8, 1
}
,
{
10, 0, OCOOKIE, 0, 3
}
,

/* cost memory iven name iven arg how
gp pointer iven[] ivenarg[] many */

{
20, potionname, OPOTION, 0, 6
}
,
{
90, potionname, OPOTION, 1, 5
}
,
{
520, potionname, OPOTION, 2, 1
}
,
{
100, potionname, OPOTION, 3, 2
}
,
{
50, potionname, OPOTION, 4, 2
}
,
{
150, potionname, OPOTION, 5, 2
}
,
{
70, potionname, OPOTION, 6, 1
}
,
{
30, potionname, OPOTION, 7, 7
}
,
{
200, potionname, OPOTION, 8, 1
}
,
{
50, potionname, OPOTION, 9, 1
}
,
{
80, potionname, OPOTION, 10, 1
}
,

/* cost memory iven name iven arg how
gp pointer iven[] ivenarg[] many */

{
30, potionname, OPOTION, 11, 3
}
,
{
20, potionname, OPOTION, 12, 5
}
,
{
40, potionname, OPOTION, 13, 3
}
,
{
35, potionname, OPOTION, 14, 2
}
,
{
520, potionname, OPOTION, 15, 1
}
,
{
90, potionname, OPOTION, 16, 2
}
,
{
200, potionname, OPOTION, 17, 2
}
,
{
220, potionname, OPOTION, 18, 4
}
,
{
80, potionname, OPOTION, 19, 6
}
,
{
370, potionname, OPOTION, 20, 3
}
,
{
50, potionname, OPOTION, 22, 1
}
,
{
150, potionname, OPOTION, 23, 3
}
,

/* cost memory iven name iven arg how
gp pointer iven[] ivenarg[] many */

{
100, scrollname, OSCROLL, 0, 2
}
,
{
125, scrollname, OSCROLL, 1, 2
}
,
{
60, scrollname, OSCROLL, 2, 4
}
,
{
10, scrollname, OSCROLL, 3, 4
}
,
{
100, scrollname, OSCROLL, 4, 3
}
,
{
200, scrollname, OSCROLL, 5, 2
}
,
{
110, scrollname, OSCROLL, 6, 1
}
,
{
500, scrollname, OSCROLL, 7, 2
}
,
{
200, scrollname, OSCROLL, 8, 2
}
,
{
250, scrollname, OSCROLL, 9, 4
}
,
{
20, scrollname, OSCROLL, 10, 5
}
,
{
30, scrollname, OSCROLL, 11, 3
}
,

/* cost memory iven name iven arg how
gp pointer iven[] ivenarg[] many */

{
340, scrollname, OSCROLL, 12, 1
}
,
{
340, scrollname, OSCROLL, 13, 1
}
,
{
300, scrollname, OSCROLL, 14, 2
}
,
{
400, scrollname, OSCROLL, 15, 2
}
,
{
500, scrollname, OSCROLL, 16, 2
}
,
{
1000, scrollname, OSCROLL, 17, 1
}
,
{
500, scrollname, OSCROLL, 18, 1
}
,
{
340, scrollname, OSCROLL, 19, 2
}
,
{
220, scrollname, OSCROLL, 20, 3
}
,
{
3900, scrollname, OSCROLL, 21, 0
}
,
{
610, scrollname, OSCROLL, 22, 1
}
,
{
3000, scrollname, OSCROLL, 23, 0
}
};


/*
function for the dnd store
*/
dnd_2hed()
{
lprcat("Welcome to the Larn Thrift Shoppe. We stock many items explorers find useful\n");
lprcat(" in their adventures. Feel free to browse to your hearts content.\n");
lprcat("Also be advised, if you break 'em, you pay for 'em.");
}

dnd_hed()
{
register int i;

for (i = dnditm; i < 26 + dnditm; i++)
dnditem(i);
cursor(50, 18);
lprcat("You have ");
}

dndstore()
{
register int i;

dnditm = 0;
nosignal = 1; /* disable signals */
clear();
dnd_2hed();
if (outstanding_taxes > 0) {
lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n");
beep();
lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n",(long) outstanding_taxes);
lprcat("comply with the law, we cannot serve you at this time. Soo Sorry.\n");
cursors();
lprcat("\nPress ");
standout("escape");
lprcat(" to leave: ");
lflush();
i = 0;
while (i != '\33')
i = readchar();
drawscreen();
nosignal = 0; /* enable signals */
return;
}

dnd_hed();
while (1) {
cursor(59, 18);
lprintf("%d gold pieces",(long) c[GOLD]);
cltoeoln();
cl_dn(1, 20); /* erase to eod */
lprcat("\nEnter your transaction [");
standout("space");
lprcat(" for more, ");
standout("escape");
lprcat(" to leave]? ");
i = 0;
while ((i < 'a' || i > 'z') &&(i != ' ') &&(i != '\33') &&(i != 12))
i = readchar();
if (i == 12) {
clear();
dnd_2hed();
dnd_hed();
} else
if (i == '\33') {
drawscreen();
nosignal = 0; /* enable signals */
return;
} else
if (i == ' ') {
cl_dn(1, 4);
if ((dnditm += 26) >= maxitm)
dnditm = 0;
dnd_hed();
} else { /* buy something */
lprc(i); /* echo the byte */
i += dnditm - 'a';
if (i >= maxitm)
outofstock();
else
if (itm[i].qty <= 0)
outofstock();
else
if (pocketfull())
handsfull();
else
if (c[GOLD] < itm[i].price * 10)
nogold();
else {
if (itm[i].mem != 0)
*itm[i].mem[itm[i].arg] = ' ';
c[GOLD] -= itm[i].price * 10;
itm[i].qty--;
take(itm[i].obj, itm[i].arg);
if (itm[i].qty == 0)
dnditem(i);
nap(1001);
}
}

}
}


/*
function for the players hands are full
*/
static handsfull()
{
lprcat("\nYou can't carry anything more!");
lflush();
nap(2200);
}

static outofstock()
{
lprcat("\nSorry, but we are out of that item.");
lflush();
nap(2200);
}

static nogold()
{
lprcat("\nYou don't have enough gold to pay for that!");
lflush();
nap(2200);
}

/*
dnditem(index)

to print the item list; used in dndstore() enter with the index into itm
*/
static dnditem(i)
register int i;
{
register int j,k;

if (i >= maxitm)
return;
cursor((j = (i & 1) * 40 + 1),(k = ((i % 26) >> 1) + 5));
if (itm[i].qty == 0) {
lprintf("%39s", "");
return;
}
lprintf("%c) ",(i % 26) + 'a');
if (itm[i].obj == OPOTION) {
lprcat("potion of ");
lprintf("%s", &potionname[itm[i].arg][1]);
} else
if (itm[i].obj == OSCROLL) {
lprcat("scroll of ");
lprintf("%s", &scrollname[itm[i].arg][1]);
} else
lprintf("%s", objectname[itm[i].obj]);
cursor(j + 31, k);
lprintf("%6d",(long)(itm[i].price * 10));
}


/*
for the college of larn
*/
globaldef char course[26] = 0; /* the list of courses taken */
char coursetime[] = {
10, 15, 10, 20, 10, 10, 10, 5
};
/*
function to display the header info for the school
*/
sch_hed()
{
clear();
lprcat("The College of Larn offers the exciting opportunity of higher education to\n");
lprcat("all inhabitants of the caves. Here is a list of the class schedule:\n\n\n");
lprcat("\t\t Course Name \t Time Needed\n\n");

if (course[0] == 0)
lprcat("\t\ta) Fighters Training I 10 mobuls");/* line 7 of crt */
lprc('\n');
if (course[1] == 0)
lprcat("\t\tb) Fighters Training II 15 mobuls");
lprc('\n');
if (course[2] == 0)
lprcat("\t\tc) Introduction to Wizardry 10 mobuls");
lprc('\n');
if (course[3] == 0)
lprcat("\t\td) Applied Wizardry 20 mobuls");
lprc('\n');
if (course[4] == 0)
lprcat("\t\te) Behavioral Psychology 10 mobuls");
lprc('\n');
if (course[5] == 0)
lprcat("\t\tf) Faith for Today 10 mobuls");
lprc('\n');
if (course[6] == 0)
lprcat("\t\tg) Contemporary Dance 10 mobuls");
lprc('\n');
if (course[7] == 0)
lprcat("\t\th) History of Larn 5 mobuls");

lprcat("\n\n\t\tAll courses cost 250 gold pieces.");
cursor(30, 18);
lprcat("You are presently carrying ");
}

oschool() {
register int i;
long time_used;
nosignal = 1; /* disable signals */
sch_hed();
while (1) {
cursor(57, 18);
lprintf("%d gold pieces. ",(long) c[GOLD]);
cursors();
lprcat("\nWhat is your choice [");
standout("escape");
lprcat(" to leave] ? ");
yrepcount = 0;
i = 0;
while ((i < 'a' || i > 'h') &&(i != '\33') &&(i != 12))
i = readchar();
if (i == 12) {
sch_hed();
continue;
}
else
if (i == '\33') {
nosignal = 0;
drawscreen(); /* enable signals */
return;
}
lprc(i);
if (c[GOLD] < 250)
nogold();
else
if (course[i - 'a']) {
lprcat("\nSorry, but that class is filled.");
nap(1000);
}
else
if (i <= 'h') {
c[GOLD] -= 250;
time_used = 0;
switch(i) {
case 'a':
c[STRENGTH] += 2;
c[CONSTITUTION]++;
lprcat("\nYou feel stronger!");
cl_line(16, 7);
break;

case 'b':
if (course[0] == 0) {
lprcat("\nSorry, but this class has a prerequisite of Fighters Training I");
c[GOLD] += 250;
time_used = -10000;
break;
}
lprcat("\nYou feel much stronger!");
cl_line(16, 8);
c[STRENGTH] += 2;
c[CONSTITUTION] += 2;
break;

case 'c':
c[INTELLIGENCE] += 2;
lprcat("\nThe task before you now seems more attainable!");
cl_line(16, 9);
break;

case 'd':
if (course[2] == 0) {
lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry");
c[GOLD] += 250;
time_used = -10000;
break;
}
lprcat("\nThe task before you now seems very attainable!");
cl_line(16, 10);
c[INTELLIGENCE] += 2;
break;

case 'e':
c[CHARISMA] += 3;
lprcat("\nYou now feel like a born leader!");
cl_line(16, 11);
break;

case 'f':
c[WISDOM] += 2;
lprcat("\nYou now feel more confident that you can find the potion in time!");
cl_line(16, 12);
break;

case 'g':
c[DEXTERITY] += 3;
lprcat("\nYou feel like dancing!");
cl_line(16, 13);
break;

case 'h':
c[INTELLIGENCE]++;
lprcat("\nYour instructor told you that the Eye of Larn is rumored to be guarded\n");
lprcat("by a platinum dragon who possesses psionic abilities. ");
cl_line(16, 14);
break;
}
time_used += coursetime[i - 'a'] * 100;
if (time_used > 0) {
gtime += time_used;
course[i - 'a']++;/* remember that he has taken that course */
c[HP] = c[HPMAX];
c[SPELLS] = c[SPELLMAX];/* he regenerated */


if (c[BLINDCOUNT])
c[BLINDCOUNT] = 1;/* cure blindness too! */
if (c[CONFUSE])
c[CONFUSE] = 1;/* end confusion */
adjtime((long) time_used);/* adjust parameters for time change */
}
nap(1000);
}
}
}

/*
* for the first national bank of Larn
*/
int lasttime = 0; /* last time he was in bank */
obank() {
banktitle(" Welcome to the First National Bank of Larn.");
}
obank2() {
banktitle("Welcome to the 5th level branch office of the First National Bank of Larn.");
}
static banktitle(str)
char *str;
{
nosignal = 1; /* disable signals */
clear();
lprcat(str);
if (outstanding_taxes > 0) {
register int i;
lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n");
beep();
lprintf("levied taxes have been paid. They have also told us that you owe %d gp in\n",(long) outstanding_taxes);
lprcat("taxes, and we must comply with them. We cannot serve you at this time. Sorry.\n");
lprcat("We suggest you go to the LRS office and pay your taxes.\n");
cursors();
lprcat("\nPress ");
standout("escape");
lprcat(" to leave: ");
lflush();
i = 0;
while (i != '\33')
i = readchar();
drawscreen();
nosignal = 0; /* enable signals */
return;
}
lprcat("\n\n\tGemstone\t Appraisal\t\tGemstone\t Appraisal");
obanksub();
nosignal = 0; /* enable signals */
drawscreen();
}

/*
* function to put interest on your bank account
*/
ointerest() {
register int i;
if (c[BANKACCOUNT] < 0)
c[BANKACCOUNT] = 0;
else
if ((c[BANKACCOUNT] > 0) &&(c[BANKACCOUNT] < 500000)) {
i = (gtime - lasttime) / 100;/* # mobuls elapsed */
while ((i-- > 0) &&(c[BANKACCOUNT] < 500000))
c[BANKACCOUNT] += c[BANKACCOUNT] / 250;
if (c[BANKACCOUNT] > 500000)
c[BANKACCOUNT] = 500000;/* interest limit */
}
lasttime = (gtime / 100) * 100;
}

static short gemorder[26] = 0;/* the reference to screen location for each */
static long gemvalue[26] = 0; /* the appraisal of the gems */
obanksub() {
unsigned long amt;
register int i,
k;
ointerest(); /* credit any needed interest */

for (k = i = 0; i < 26; i++)
switch(iven[i]) {
case OLARNEYE:
case ODIAMOND:
case OEMERALD:
case ORUBY:
case OSAPPHIRE:

if (iven[i] == OLARNEYE) {
gemvalue[i] = 250000 - ((gtime * 7) / 100) * 100;
if (gemvalue[i] < 50000)
gemvalue[i] = 50000;
}
else
gemvalue[i] = (255 & ivenarg[i]) * 100;
gemorder[i] = k;
cursor((k % 2) * 40 + 1,(k >> 1) + 4);
lprintf("%c) %s", i + 'a', objectname[iven[i]]);
cursor((k % 2) * 40 + 33,(k >> 1) + 4);
lprintf("%5d",(long) gemvalue[i]);
k++;
};
cursor(31, 17);
lprintf("You have %8d gold pieces in the bank.",(long) c[BANKACCOUNT]);
cursor(40, 18);
lprintf("You have %8d gold pieces",(long) c[GOLD]);
if (c[BANKACCOUNT] + c[GOLD] >= 500000)
lprcat("\nNote: Larndom law states that only deposits under 500,000gp can earn interest.");
while (1) {
cl_dn(1, 20);
lprcat("\nYour wish? [(");
standout("d");
lprcat(") deposit,(");
standout("w");
lprcat(") withdraw,(");
standout("s");
lprcat(") sell a stone, or ");
standout("escape");
lprcat("] ");
yrepcount = 0;
i = 0;
while (i != 'd' && i != 'w' && i != 's' && i != '\33')
i = readchar();
switch(i) {
case 'd':
lprcat("deposit\nHow much? ");
amt = readnum((long) c[GOLD]);
if (amt < 0) {
lprcat("\nSorry, but we can't take negative gold!");
nap(2000);
amt = 0;
}
else
if (amt > c[GOLD]) {
lprcat(" You don't have that much.");
nap(2000);
}
else {
c[GOLD] -= amt;
c[BANKACCOUNT] += amt;
}
break;

case 'w':
lprcat("withdraw\nHow much? ");
amt = readnum((long) c[BANKACCOUNT]);
if (amt < 0) {
lprcat("\nSorry, but we don't have any negative gold!");
nap(2000);
amt = 0;
}
else
if (amt > c[BANKACCOUNT]) {
lprcat("\nYou don't have that much in the bank!");
nap(2000);
}
else {
c[GOLD] += amt;
c[BANKACCOUNT] -= amt;
}
break;

case 's':
lprcat("\nWhich stone would you like to sell? ");
i = 0;
while ((i < 'a' || i > 'z') && i != '*')
i = readchar();
if (i == '*')
for (i = 0; i < 26; i++) {
if (gemvalue[i]) {
c[GOLD] += gemvalue[i];
iven[i] = 0;
gemvalue[i] = 0;
k = gemorder[i];
cursor((k % 2) * 40 + 1,(k >> 1) + 4);
lprintf("%39s", "");
}
}
else {
if (gemvalue[i = i - 'a'] == 0) {
lprintf("\nItem %c is not a gemstone!", i + 'a');
nap(2000);
break;
}
c[GOLD] += gemvalue[i];
iven[i] = 0;
gemvalue[i] = 0;
k = gemorder[i];
cursor((k % 2) * 40 + 1,(k >> 1) + 4);
lprintf("%39s", "");
}
break;

case '\33':
return;
};
cursor(40, 17);
lprintf("%8d",(long) c[BANKACCOUNT]);
cursor(49, 18);
lprintf("%8d",(long) c[GOLD]);
}
}

/*
subroutine to appraise any stone for the bank
*/
appraise(gemstone)
register int gemstone;
{
register int j,
amt;
for (j = 0; j < 26; j++)
if (iven[j] == gemstone) {
lprintf("\nI see you have %s", objectname[gemstone]);
if (gemstone == OLARNEYE)
lprcat(" I must commend you. I didn't think\nyou could get it.");
lprcat(" Shall I appraise it for you? ");
yrepcount = 0;
if (getyn() == 'y') {
lprcat("yes.\n Just one moment please \n");
nap(1000);
if (gemstone == OLARNEYE) {
amt = 250000 - ((gtime * 7) / 100) * 100;
if (amt < 50000)
amt = 50000;
}
else
amt = (255 & ivenarg[j]) * 100;
lprintf("\nI can see this is an excellent stone, It is worth %d",(long) amt);
lprcat("\nWould you like to sell it to us? ");
yrepcount = 0;
if (getyn() == 'y') {
lprcat("yes\n");
c[GOLD] += amt;
iven[j] = 0;
}
else
lprcat("no thank you.\n");
if (gemstone == OLARNEYE)
lprcat("It is, of course, your privilege to keep the stone\n");
}
else
lprcat("no\nO. K.\n");
}
}
/*
function for the trading post
*/
static otradhead() {
clear();
lprcat("Welcome to the Larn Trading Post. We buy items that explorers no longer find\n");
lprcat("useful. Since the condition of the items you bring in is not certain,\n");
lprcat("and we incur great expense in reconditioning the items, we usually pay\n");
lprcat("only 20% of their value were they to be new. If the items are badly\n");
lprcat("damaged, we will pay only 10% of their new value.\n\n");
}

otradepost() {
register int i,
j,
value,
isub,
izarg;
dnditm = dndcount = 0;
nosignal = 1; /* disable signals */
resetscroll();
otradhead();
while (1) {
lprcat("\nWhat item do you want to sell to us [");
standout("*");
lprcat(" for list, or ");
standout("escape");
lprcat("] ? ");
i = 0;
while (i > 'z' ||(i < 'a' && i != '*' && i != '\33' && i != '.'))
i = readchar();
if (i == '\33') {
setscroll();
recalc();
drawscreen();
nosignal = 0; /* enable signals */
return;
}
isub = i - 'a';
j = 0;
if (iven[isub] == OSCROLL)
if (scrollname[ivenarg[isub]][0] == 0) {
j = 1;
cnsitm();
} /* can't sell unidentified item */
if (iven[isub] == OPOTION)
if (potionname[ivenarg[isub]][0] == 0) {
j = 1;
cnsitm();
} /* can't sell unidentified item */
if (!j)
if (i == '*') {
clear();
qshowstr();
otradhead();
}
else
if (iven[isub] == 0)
lprintf("\nYou don't have item %c!", isub + 'a');
else {
for (j = 0; j < maxitm; j++)
if ((itm[j].obj == iven[isub]) ||(iven[isub] == ODIAMOND) ||(iven[isub] == ORUBY) ||(iven[isub] == OEMERALD) ||(iven[isub] == OSAPPHIRE)) {
srcount = 0;
show3(isub);/* show what the item was */
if ((iven[isub] == ODIAMOND) ||(iven[isub] == ORUBY)
||(iven[isub] == OEMERALD) ||(iven[isub] == OSAPPHIRE))
value = 20 * ivenarg[isub];
else
if ((itm[j].obj == OSCROLL) ||(itm[j].obj == OPOTION))
value = 2 * itm[j + ivenarg[isub]].price;
else {
izarg = ivenarg[isub];
value = itm[j].price;/* appreciate if a +n object */
if (izarg >= 0)
value *= 2;
while ((izarg-- > 0) &&((value = 14 *(67 + value) / 10) < 500000));
}
lprintf("\nItem(%c) is worth %d gold pieces to us. Do you want to sell it? ", i,(long) value);
yrepcount = 0;
if (getyn() == 'y') {
lprcat("yes\n");
c[GOLD] += value;
if (c[WEAR] == isub)
c[WEAR] = -1;
if (c[WIELD] == isub)
c[WIELD] = -1;
if (c[SHIELD] == isub)
c[SHIELD] = -1;
adjustcvalues(iven[isub], ivenarg[isub]);
iven[isub] = 0;
}
else
lprcat("no thanks.\n");
j = maxitm + 100;/* get out of the inner loop */
}
if (j <= maxitm + 2)
lprcat("\nSo sorry, but we are not authorized to accept that item.");
}
}
}

cnsitm() {
lprcat("\nSorry, we can't accept unidentified objects.");
}

/*
* for the Larn Revenue Service
*/
olrs() {
register int i,
first;
unsigned long amt;
first = nosignal = 1; /* disable signals */
clear();
resetscroll();
cursor(1, 4);
lprcat("Welcome to the Larn Revenue Service district office. How can we help you?");
while (1) {
if (first) {
first = 0;
goto nxt;
}
cursors();
lprcat("\n\nYour wish? [(");
standout("p");
lprcat(") pay taxes, or ");
standout("escape");
lprcat("] ");
yrepcount = 0;
i = 0;
while (i != 'p' && i != '\33')
i = readchar();
switch(i) {
case 'p':
lprcat("pay taxes\nHow much? ");
amt = readnum((long) c[GOLD]);
if (amt < 0) {
lprcat("\nSorry, but we can't take negative gold\n");
amt = 0;
}
else
if (amt > c[GOLD])
lprcat(" You don't have that much.\n");
else
c[GOLD] -= paytaxes((long) amt);
break;

case '\33':
nosignal = 0; /* enable signals */
setscroll();
drawscreen();
return;
};

nxt:
cursor(1, 6);
if (outstanding_taxes > 0)
lprintf("You presently owe %d gp in taxes. ",(long) outstanding_taxes);
else
lprcat("You do not owe us any taxes. ");
cursor(1, 8);
if (c[GOLD] > 0)
lprintf("You have %6d gp. ",(long) c[GOLD]);
else
lprcat("You have no gold pieces. ");
}
}
SHAR_EOF
if test 22511 -ne "`wc -c < 'store.c'`"
then
echo shar: error transmitting "'store.c'" '(should have been 22511 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0

Reply all
Reply to author
Forward
0 new messages