Home | History | Annotate | Line # | Download | only in larn
scores.c revision 1.5
      1 #ifndef lint
      2 static char rcsid[] = "$NetBSD: scores.c,v 1.5 1995/04/24 12:24:08 cgd Exp $";
      3 #endif /* not lint */
      4 
      5 /* scores.c			 Larn is copyrighted 1986 by Noah Morgan.
      6  *
      7  *	Functions in this file are:
      8  *
      9  *	readboard() 	Function to read in the scoreboard into a static buffer
     10  *	writeboard()	Function to write the scoreboard from readboard()'s buffer
     11  *	makeboard() 	Function to create a new scoreboard (wipe out old one)
     12  *	hashewon()	 Function to return 1 if player has won a game before, else 0
     13  *	long paytaxes(x)	 Function to pay taxes if any are due
     14  *	winshou()		Subroutine to print out the winning scoreboard
     15  *	shou(x)			Subroutine to print out the non-winners scoreboard
     16  *	showscores()		Function to show the scoreboard on the terminal
     17  *	showallscores()	Function to show scores and the iven lists that go with them
     18  *	sortboard()		Function to sort the scoreboard
     19  *	newscore(score, whoo, whyded, winner) 	Function to add entry to scoreboard
     20  *	new1sub(score,i,whoo,taxes) 		  Subroutine to put player into a
     21  *	new2sub(score,i,whoo,whyded)	 	  Subroutine to put player into a
     22  *	died(x) 	Subroutine to record who played larn, and what the score was
     23  *	diedsub(x) Subroutine to print out a line showing player when he is killed
     24  *	diedlog() 	Subroutine to read a log file and print it out in ascii format
     25  *	getplid(name)		Function to get players id # from id file
     26  *
     27  */
     28 #include <sys/types.h>
     29 #include <sys/times.h>
     30 #include <sys/stat.h>
     31 #include "header.h"
     32 #include <string.h>
     33 
     34 struct scofmt			/*	This is the structure for the scoreboard 		*/
     35 	{
     36 	long score;			/* the score of the player 							*/
     37 	long suid;			/* the user id number of the player 				*/
     38 	short what;			/* the number of the monster that killed player 	*/
     39 	short level;		/* the level player was on when he died 			*/
     40 	short hardlev;		/* the level of difficulty player played at 		*/
     41 	short order;		/* the relative ordering place of this entry 		*/
     42 	char who[40];		/* the name of the character 						*/
     43 	char sciv[26][2];	/* this is the inventory list of the character 		*/
     44 	};
     45 struct wscofmt			/* This is the structure for the winning scoreboard */
     46 	{
     47 	long score;			/* the score of the player 							*/
     48 	long timeused;		/* the time used in mobuls to win the game 			*/
     49 	long taxes;			/* taxes he owes to LRS 							*/
     50 	long suid;			/* the user id number of the player 				*/
     51 	short hardlev;		/* the level of difficulty player played at 		*/
     52 	short order;		/* the relative ordering place of this entry 		*/
     53 	char who[40];		/* the name of the character 						*/
     54 	};
     55 
     56 struct log_fmt			/* 102 bytes struct for the log file 				*/
     57 	{
     58 	long score;			/* the players score 								*/
     59 	time_t diedtime;	/* time when game was over 							*/
     60 	short cavelev;		/* level in caves 									*/
     61 	short diff;			/* difficulty player played at 						*/
     62 #ifdef EXTRA
     63 	long elapsedtime;	/* real time of game in seconds 					*/
     64 	long bytout;		/* bytes input and output 							*/
     65 	long bytin;
     66 	long moves;			/* number of moves made by player 					*/
     67 	short ac;			/* armor class of player 							*/
     68 	short hp,hpmax;		/* players hitpoints 								*/
     69 	short cputime;		/* cpu time needed in seconds 						*/
     70 	short killed,spused;/* monsters killed and spells cast 					*/
     71 	short usage;		/* usage of the cpu in % 							*/
     72 	short lev;			/* player level 									*/
     73 #endif
     74 	char who[12];		/* player name 										*/
     75 	char what[46];		/* what happened to player 							*/
     76 	};
     77 
     78 static struct scofmt sco[SCORESIZE];	/* the structure for the scoreboard  */
     79 static struct wscofmt winr[SCORESIZE];	/* struct for the winning scoreboard */
     80 static struct log_fmt logg;				/* structure for the log file 		 */
     81 static char *whydead[] = {
     82 	"quit", "suspended", "self - annihilated", "shot by an arrow",
     83 	"hit by a dart", "fell into a pit", "fell into a bottomless pit",
     84 	"a winner", "trapped in solid rock", "killed by a missing save file",
     85 	"killed by an old save file", "caught by the greedy cheater checker trap",
     86 	"killed by a protected save file","killed his family and committed suicide",
     87 	"erased by a wayward finger", "fell through a bottomless trap door",
     88 	"fell through a trap door", "drank some poisonous water",
     89 	"fried by an electric shock", "slipped on a volcano shaft",
     90 	"killed by a stupid act of frustration", "attacked by a revolting demon",
     91 	"hit by his own magic", "demolished by an unseen attacker",
     92 	"fell into the dreadful sleep", "killed by an exploding chest",
     93 /*26*/	"killed by a missing maze data file", "annihilated in a sphere",
     94 	"died a post mortem death","wasted by a malloc() failure"
     95 	};
     96 
     97 /*
     98  *	readboard() 	Function to read in the scoreboard into a static buffer
     99  *
    100  *	returns -1 if unable to read in the scoreboard, returns 0 if all is OK
    101  */
    102 readboard()
    103 	{
    104 	if (lopen(scorefile)<0)
    105 	  { lprcat("Can't read scoreboard\n"); lflush(); return(-1); }
    106 	lrfill((char*)sco,sizeof(sco));		lrfill((char*)winr,sizeof(winr));
    107 	lrclose();  lcreat((char*)0);  return(0);
    108 	}
    109 
    110 /*
    111  *	writeboard()	Function to write the scoreboard from readboard()'s buffer
    112  *
    113  *	returns -1 if unable to write the scoreboard, returns 0 if all is OK
    114  */
    115 writeboard()
    116 	{
    117 	set_score_output();
    118 	if (lcreat(scorefile)<0)
    119 	  { lprcat("Can't write scoreboard\n"); lflush(); return(-1); }
    120 	lwrite((char*)sco,sizeof(sco));		lwrite((char*)winr,sizeof(winr));
    121 	lwclose();  lcreat((char*)0);  return(0);
    122 	}
    123 
    124 /*
    125  *	makeboard() 		Function to create a new scoreboard (wipe out old one)
    126  *
    127  *	returns -1 if unable to write the scoreboard, returns 0 if all is OK
    128  */
    129 makeboard()
    130 	{
    131 	register int i;
    132 	for (i=0; i<SCORESIZE; i++)
    133 		{
    134 		winr[i].taxes = winr[i].score = sco[i].score = 0;
    135 		winr[i].order = sco[i].order = i;
    136 		}
    137 	if (writeboard()) return(-1);
    138 	chmod(scorefile,0660);
    139 	return(0);
    140 	}
    141 
    142 /*
    143  *	hashewon()	 Function to return 1 if player has won a game before, else 0
    144  *
    145  *	This function also sets c[HARDGAME] to appropriate value -- 0 if not a
    146  *	winner, otherwise the next level of difficulty listed in the winners
    147  *	scoreboard.  This function also sets outstanding_taxes to the value in
    148  *	the winners scoreboard.
    149  */
    150 hashewon()
    151 	{
    152 	register int i;
    153 	c[HARDGAME] = 0;
    154 	if (readboard() < 0) return(0);	/* can't find scoreboard */
    155 	for (i=0; i<SCORESIZE; i++)	/* search through winners scoreboard */
    156 	   if (winr[i].suid == userid)
    157 		  if (winr[i].score > 0)
    158 			{
    159 			c[HARDGAME]=winr[i].hardlev+1;  outstanding_taxes=winr[i].taxes;
    160 			return(1);
    161 			}
    162 	return(0);
    163 	}
    164 
    165 /*
    166  *	long paytaxes(x)		 Function to pay taxes if any are due
    167  *
    168  *	Enter with the amount (in gp) to pay on the taxes.
    169  *	Returns amount actually paid.
    170  */
    171 long paytaxes(x)
    172 	long x;
    173 	{
    174 	register int i;
    175 	register long amt;
    176 	if (x<0) return(0L);
    177 	if (readboard()<0) return(0L);
    178 	for (i=0; i<SCORESIZE; i++)
    179 		if (winr[i].suid == userid)	/* look for players winning entry */
    180 			if (winr[i].score>0) /* search for a winning entry for the player */
    181 				{
    182 				amt = winr[i].taxes;
    183 				if (x < amt) amt=x;		/* don't overpay taxes (Ughhhhh) */
    184 				winr[i].taxes -= amt;
    185 				outstanding_taxes -= amt;
    186 				if (writeboard()<0) return(0);
    187 				return(amt);
    188 				}
    189 	return(0L);	/* couldn't find user on winning scoreboard */
    190 	}
    191 
    192 /*
    193  *	winshou()		Subroutine to print out the winning scoreboard
    194  *
    195  *	Returns the number of players on scoreboard that were shown
    196  */
    197 winshou()
    198 	{
    199 	register struct wscofmt *p;
    200 	register int i,j,count;
    201 	for (count=j=i=0; i<SCORESIZE; i++) /* is there anyone on the scoreboard? */
    202 		if (winr[i].score != 0)
    203 			{ j++; break; }
    204 	if (j)
    205 		{
    206 		lprcat("\n  Score    Difficulty   Time Needed   Larn Winners List\n");
    207 
    208 		for (i=0; i<SCORESIZE; i++)	/* this loop is needed to print out the */
    209 		  for (j=0; j<SCORESIZE; j++) /* winners in order */
    210 			{
    211 			p = &winr[j];	/* pointer to the scoreboard entry */
    212 			if (p->order == i)
    213 				{
    214 				if (p->score)
    215 					{
    216 					count++;
    217 					lprintf("%10d     %2d      %5d Mobuls   %s \n",
    218 					(long)p->score,(long)p->hardlev,(long)p->timeused,p->who);
    219 					}
    220 				break;
    221 				}
    222 			}
    223 		}
    224 	return(count);	/* return number of people on scoreboard */
    225 	}
    226 
    227 /*
    228  *	shou(x)			Subroutine to print out the non-winners scoreboard
    229  *		int x;
    230  *
    231  *	Enter with 0 to list the scores, enter with 1 to list inventories too
    232  *	Returns the number of players on scoreboard that were shown
    233  */
    234 shou(x)
    235 	int x;
    236 	{
    237 	register int i,j,n,k;
    238 	int count;
    239 	for (count=j=i=0; i<SCORESIZE; i++)	/* is the scoreboard empty? */
    240 		if (sco[i].score!= 0)
    241 			{ j++; break; }
    242 	if (j)
    243 		{
    244 		lprcat("\n   Score   Difficulty   Larn Visitor Log\n");
    245 		for (i=0; i<SCORESIZE; i++) /* be sure to print them out in order */
    246 		  for (j=0; j<SCORESIZE; j++)
    247 			if (sco[j].order == i)
    248 				{
    249 				if (sco[j].score)
    250 					{
    251 					count++;
    252 					lprintf("%10d     %2d       %s ",
    253 						(long)sco[j].score,(long)sco[j].hardlev,sco[j].who);
    254 					if (sco[j].what < 256) lprintf("killed by a %s",monster[sco[j].what].name);
    255 						else lprintf("%s",whydead[sco[j].what - 256]);
    256 					if (x != 263) lprintf(" on %s",levelname[sco[j].level]);
    257 					if (x)
    258 						{
    259 						for (n=0; n<26; n++) { iven[n]=sco[j].sciv[n][0]; ivenarg[n]=sco[j].sciv[n][1]; }
    260 						for (k=1; k<99; k++)
    261 						  for (n=0; n<26; n++)
    262 							if (k==iven[n])  { srcount=0; show3(n); }
    263 						lprcat("\n\n");
    264 						}
    265 					else lprc('\n');
    266 					}
    267 				j=SCORESIZE;
    268 				}
    269 		}
    270 	return(count);	/* return the number of players just shown */
    271 	}
    272 
    273 /*
    274  *	showscores()		Function to show the scoreboard on the terminal
    275  *
    276  *	Returns nothing of value
    277  */
    278 static char esb[] = "The scoreboard is empty.\n";
    279 showscores()
    280 	{
    281 	register int i,j;
    282 	lflush();  lcreat((char*)0);  if (readboard()<0) return;
    283 	i=winshou();	j=shou(0);
    284 	if (i+j == 0) lprcat(esb); else lprc('\n');
    285 	lflush();
    286 	}
    287 
    288 /*
    289  *	showallscores()	Function to show scores and the iven lists that go with them
    290  *
    291  *	Returns nothing of value
    292  */
    293 showallscores()
    294 	{
    295 	register int i,j;
    296 	lflush();  lcreat((char*)0);  if (readboard()<0) return;
    297 	c[WEAR] = c[WIELD] = c[SHIELD] = -1;  /* not wielding or wearing anything */
    298 	for (i=0; i<MAXPOTION; i++) potionname[i]=potionhide[i];
    299 	for (i=0; i<MAXSCROLL; i++) scrollname[i]=scrollhide[i];
    300 	i=winshou();  j=shou(1);
    301 	if (i+j==0) lprcat(esb); else lprc('\n');
    302 	lflush();
    303 	}
    304 
    305 /*
    306  *	sortboard()		Function to sort the scoreboard
    307  *
    308  *	Returns 0 if no sorting done, else returns 1
    309  */
    310 sortboard()
    311 	{
    312 	register int i,j,pos;
    313 	long jdat;
    314 	for (i=0; i<SCORESIZE; i++) sco[i].order = winr[i].order = -1;
    315 	pos=0;  while (pos < SCORESIZE)
    316 		{
    317 		jdat=0;
    318 		for (i=0; i<SCORESIZE; i++)
    319 			if ((sco[i].order < 0) && (sco[i].score >= jdat))
    320 				{ j=i;  jdat=sco[i].score; }
    321 		sco[j].order = pos++;
    322 		}
    323 	pos=0;  while (pos < SCORESIZE)
    324 		{
    325 		jdat=0;
    326 		for (i=0; i<SCORESIZE; i++)
    327 			if ((winr[i].order < 0) && (winr[i].score >= jdat))
    328 				{ j=i;  jdat=winr[i].score; }
    329 		winr[j].order = pos++;
    330 		}
    331 	return(1);
    332 	}
    333 
    334 /*
    335  *	newscore(score, whoo, whyded, winner) 	Function to add entry to scoreboard
    336  *		int score, winner, whyded;
    337  *		char *whoo;
    338  *
    339  *	Enter with the total score in gp in score,  players name in whoo,
    340  *		died() reason # in whyded, and TRUE/FALSE in winner if a winner
    341  *	ex.		newscore(1000, "player 1", 32, 0);
    342  */
    343 newscore(score, whoo, whyded, winner)
    344 	long score;
    345 	int winner, whyded;
    346 	char *whoo;
    347 	{
    348 	register int i;
    349 	long taxes;
    350 	if (readboard() < 0) return; 	/*	do the scoreboard	*/
    351 	/* if a winner then delete all non-winning scores */
    352 	if (cheat) winner=0;	/* if he cheated, don't let him win */
    353 	if (winner)
    354 		{
    355 		for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid) sco[i].score=0;
    356 		taxes = score*TAXRATE;
    357 		score += 100000*c[HARDGAME];	/* bonus for winning */
    358 	/* if he has a slot on the winning scoreboard update it if greater score */
    359 		for (i=0; i<SCORESIZE; i++) if (winr[i].suid == userid)
    360 				{ new1sub(score,i,whoo,taxes); return; }
    361 	/* he had no entry. look for last entry and see if he has a greater score */
    362 		for (i=0; i<SCORESIZE; i++) if (winr[i].order == SCORESIZE-1)
    363 				{ new1sub(score,i,whoo,taxes); return; }
    364 		}
    365 	else if (!cheat) /* for not winning scoreboard */
    366 		{
    367 	/* if he has a slot on the scoreboard update it if greater score */
    368 		for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid)
    369 				{ new2sub(score,i,whoo,whyded); return; }
    370 	/* he had no entry. look for last entry and see if he has a greater score */
    371 		for (i=0; i<SCORESIZE; i++) if (sco[i].order == SCORESIZE-1)
    372 				{ new2sub(score,i,whoo,whyded); return; }
    373 		}
    374 	}
    375 
    376 /*
    377  *	new1sub(score,i,whoo,taxes) 	  Subroutine to put player into a
    378  *		int score,i,whyded,taxes;		  winning scoreboard entry if his score
    379  *		char *whoo; 					  is high enough
    380  *
    381  *	Enter with the total score in gp in score,  players name in whoo,
    382  *		died() reason # in whyded, and TRUE/FALSE in winner if a winner
    383  *		slot in scoreboard in i, and the tax bill in taxes.
    384  *	Returns nothing of value
    385  */
    386 new1sub(score,i,whoo,taxes)
    387 	long score,taxes;
    388 	int i;
    389 	char *whoo;
    390 	{
    391 	register struct wscofmt *p;
    392 	p = &winr[i];
    393 	p->taxes += taxes;
    394 	if ((score >= p->score) || (c[HARDGAME] > p->hardlev))
    395 		{
    396 		strcpy(p->who,whoo);  		p->score=score;
    397 		p->hardlev=c[HARDGAME];		p->suid=userid;
    398 		p->timeused=gtime/100;
    399 		}
    400 	}
    401 
    402 /*
    403  *	new2sub(score,i,whoo,whyded)	 	  Subroutine to put player into a
    404  *		int score,i,whyded,taxes;		  non-winning scoreboard entry if his
    405  *		char *whoo; 					  score is high enough
    406  *
    407  *	Enter with the total score in gp in score,  players name in whoo,
    408  *		died() reason # in whyded, and slot in scoreboard in i.
    409  *	Returns nothing of value
    410  */
    411 new2sub(score,i,whoo,whyded)
    412 	long score;
    413 	int i,whyded;
    414 	char *whoo;
    415 	{
    416 	register int j;
    417 	register struct scofmt *p;
    418 	p = &sco[i];
    419 	if ((score >= p->score) || (c[HARDGAME] > p->hardlev))
    420 		{
    421 		strcpy(p->who,whoo);  p->score=score;
    422 		p->what=whyded;       p->hardlev=c[HARDGAME];
    423 		p->suid=userid;		  p->level=level;
    424 		for (j=0; j<26; j++)
    425 			{ p->sciv[j][0]=iven[j]; p->sciv[j][1]=ivenarg[j]; }
    426 		}
    427 	}
    428 
    429 /*
    430  *	died(x) 	Subroutine to record who played larn, and what the score was
    431  *		int x;
    432  *
    433  *	if x < 0 then don't show scores
    434  *	died() never returns! (unless c[LIFEPROT] and a reincarnatable death!)
    435  *
    436  *		< 256	killed by the monster number
    437  *		256		quit
    438  *		257		suspended
    439  *		258		self - annihilated
    440  *		259		shot by an arrow
    441  *		260		hit by a dart
    442  *		261		fell into a pit
    443  *		262		fell into a bottomless pit
    444  *		263		a winner
    445  *		264		trapped in solid rock
    446  *		265		killed by a missing save file
    447  *		266		killed by an old save file
    448  *		267		caught by the greedy cheater checker trap
    449  *		268		killed by a protected save file
    450  *		269		killed his family and killed himself
    451  *		270		erased by a wayward finger
    452  *		271		fell through a bottomless trap door
    453  *		272		fell through a trap door
    454  *		273		drank some poisonous water
    455  *		274		fried by an electric shock
    456  *		275		slipped on a volcano shaft
    457  *		276		killed by a stupid act of frustration
    458  *		277		attacked by a revolting demon
    459  *		278		hit by his own magic
    460  *		279		demolished by an unseen attacker
    461  *		280		fell into the dreadful sleep
    462  *		281		killed by an exploding chest
    463  *		282		killed by a missing maze data file
    464  *		283		killed by a sphere of annihilation
    465  *		284		died a post mortem death
    466  *		285		malloc() failure
    467  *		300		quick quit -- don't put on scoreboard
    468  */
    469 
    470 static int scorerror;
    471 died(x)
    472 	int x;
    473 	{
    474 	register int f,win;
    475 	char ch,*mod;
    476 	time_t zzz;
    477 	long i;
    478 	struct tms cputime;
    479 	if (c[LIFEPROT]>0) /* if life protection */
    480 		{
    481 		switch((x>0) ? x : -x)
    482 			{
    483 			case 256: case 257: case 262: case 263: case 265: case 266:
    484 			case 267: case 268: case 269: case 271: case 282: case 284:
    485 			case 285: case 300:  goto invalid; /* can't be saved */
    486 			};
    487 		--c[LIFEPROT]; c[HP]=1; --c[CONSTITUTION];
    488 		cursors(); lprcat("\nYou feel wiiieeeeerrrrrd all over! "); beep();
    489 		lflush();  sleep(4);
    490 		return; /* only case where died() returns */
    491 		}
    492 invalid:
    493 	clearvt100();  lflush();  f=0;
    494 	if (ckpflag) unlink(ckpfile);	/* remove checkpoint file if used */
    495 	if (x<0) { f++; x = -x; }	/* if we are not to display the scores */
    496 	if ((x == 300) || (x == 257))  exit();	/* for quick exit or saved game */
    497 	if (x == 263)  win = 1;  else  win = 0;
    498 	c[GOLD] += c[BANKACCOUNT];   c[BANKACCOUNT] = 0;
    499 		/*	now enter the player at the end of the scoreboard */
    500 	newscore(c[GOLD], logname, x, win);
    501 	diedsub(x);	/* print out the score line */  lflush();
    502 
    503 	set_score_output();
    504 	if ((wizard == 0) && (c[GOLD] > 0)) 	/*	wizards can't score		*/
    505 		{
    506 #ifndef NOLOG
    507 		if (lappend(logfile)<0)  /* append to file */
    508 			{
    509 			if (lcreat(logfile)<0) /* and can't create new log file */
    510 		    	{
    511 				lcreat((char*)0);
    512 				lprcat("\nCan't open record file:  I can't post your score.\n");
    513 				sncbr();  resetscroll();  lflush();  exit();
    514 				}
    515 			chmod(logfile,0660);
    516 			}
    517 		strcpy(logg.who,loginname);
    518 		logg.score = c[GOLD];		logg.diff = c[HARDGAME];
    519 		if (x < 256)
    520 			{
    521 			ch = *monster[x].name;
    522 			if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
    523 				mod="an";  else mod="a";
    524 			sprintf(logg.what,"killed by %s %s",mod,monster[x].name);
    525 			}
    526 		else sprintf(logg.what,"%s",whydead[x - 256]);
    527 		logg.cavelev=level;
    528 		time(&zzz);	  /* get cpu time -- write out score info */
    529 		logg.diedtime=zzz;
    530 #ifdef EXTRA
    531 		times(&cputime);  /* get cpu time -- write out score info */
    532 		logg.cputime = i = (cputime.tms_utime + cputime.tms_stime)/60 + c[CPUTIME];
    533 		logg.lev=c[LEVEL];			logg.ac=c[AC];
    534 		logg.hpmax=c[HPMAX];		logg.hp=c[HP];
    535 		logg.elapsedtime=(zzz-initialtime+59)/60;
    536 		logg.usage=(10000*i)/(zzz-initialtime);
    537 		logg.bytin=c[BYTESIN];		logg.bytout=c[BYTESOUT];
    538 		logg.moves=c[MOVESMADE];	logg.spused=c[SPELLSCAST];
    539 		logg.killed=c[MONSTKILLED];
    540 #endif
    541 		lwrite((char*)&logg,sizeof(struct log_fmt));	 lwclose();
    542 #endif NOLOG
    543 
    544 /*	now for the scoreboard maintenance -- not for a suspended game 	*/
    545 		if (x != 257)
    546 			{
    547 			if (sortboard())  scorerror = writeboard();
    548 			}
    549 		}
    550 	if ((x==256) || (x==257) || (f != 0)) exit();
    551 	if (scorerror == 0) showscores();	/* if we updated the scoreboard */
    552 	if (x == 263) mailbill();		exit();
    553 	}
    554 
    555 /*
    556  *	diedsub(x) Subroutine to print out the line showing the player when he is killed
    557  *		int x;
    558  */
    559 diedsub(x)
    560 int x;
    561 	{
    562 	register char ch,*mod;
    563 	lprintf("Score: %d, Diff: %d,  %s ",(long)c[GOLD],(long)c[HARDGAME],logname);
    564 	if (x < 256)
    565 		{
    566 		ch = *monster[x].name;
    567 		if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
    568 			mod="an";  else mod="a";
    569 		lprintf("killed by %s %s",mod,monster[x].name);
    570 		}
    571 	else lprintf("%s",whydead[x - 256]);
    572 	if (x != 263) lprintf(" on %s\n",levelname[level]);  else lprc('\n');
    573 	}
    574 
    575 /*
    576  *	diedlog() 	Subroutine to read a log file and print it out in ascii format
    577  */
    578 diedlog()
    579 	{
    580 	register int n;
    581 	register char *p;
    582 	struct stat stbuf;
    583 	lcreat((char*)0);
    584 	if (lopen(logfile)<0)
    585 		{
    586 		lprintf("Can't locate log file <%s>\n",logfile);
    587 		return;
    588 		}
    589 	if (fstat(fd,&stbuf) < 0)
    590 		{
    591 		lprintf("Can't  stat log file <%s>\n",logfile);
    592 		return;
    593 		}
    594 	for (n=stbuf.st_size/sizeof(struct log_fmt); n>0; --n)
    595 		{
    596 		lrfill((char*)&logg,sizeof(struct log_fmt));
    597 		p = ctime(&logg.diedtime); p[16]='\n'; p[17]=0;
    598 		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);
    599 #ifdef EXTRA
    600 		if (logg.moves<=0) logg.moves=1;
    601 		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));
    602 		lprintf("  CPU time used: %d seconds,  Machine usage: %d.%02d%%\n",(long)(logg.cputime),(long)(logg.usage/100),(long)(logg.usage%100));
    603 		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));
    604 		lprintf("  out bytes per move: %d,  time per move: %d ms\n",(long)(logg.bytout/logg.moves),(long)((logg.cputime*1000)/logg.moves));
    605 #endif
    606 		}
    607 		lflush();  lrclose();  return;
    608 	}
    609 
    610 #ifndef UIDSCORE
    611 /*
    612  *	getplid(name)		Function to get players id # from id file
    613  *
    614  *	Enter with the name of the players character in name.
    615  *	Returns the id # of the players character, or -1 if failure.
    616  *	This routine will try to find the name in the id file, if its not there,
    617  *	it will try to make a new entry in the file.  Only returns -1 if can't
    618  *	find him in the file, and can't make a new entry in the file.
    619  *	Format of playerids file:
    620  *			Id # in ascii     \n     character name     \n
    621  */
    622 static int havepid= -1;	/* playerid # if previously done */
    623 getplid(nam)
    624 	char *nam;
    625 	{
    626 	int fd7,high=999,no;
    627 	register char *p,*p2;
    628 	char name[80];
    629 	if (havepid != -1) return(havepid);	/* already did it */
    630 	lflush();	/* flush any pending I/O */
    631 	sprintf(name,"%s\n",nam);	/* append a \n to name */
    632 	if (lopen(playerids) < 0)	/* no file, make it */
    633 		{
    634 		if ((fd7=creat(playerids,0666)) < 0)  return(-1); /* can't make it */
    635 		close(fd7);  goto addone;	/* now append new playerid record to file */
    636 		}
    637 	for (;;)	/* now search for the name in the player id file */
    638 		{
    639 		p = lgetl();  if (p==NULL) break;	/* EOF? */
    640 		no = atoi(p);	/* the id # */
    641 		p2= lgetl();  if (p2==NULL) break;	/* EOF? */
    642 		if (no>high) high=no;	/* accumulate highest id # */
    643 		if (strcmp(p2,name)==0)	/* we found him */
    644 			{
    645 			return(no);	/* his id number */
    646 			}
    647 		}
    648 	lrclose();
    649 	/* if we get here, we didn't find him in the file -- put him there */
    650 addone:
    651 	if (lappend(playerids) < 0) return(-1);	/* can't open file for append */
    652 	lprintf("%d\n%s",(long)++high,name);  /* new id # and name */
    653 	lwclose();
    654 	lcreat((char*)0);	/* re-open terminal channel */
    655 	return(high);
    656 	}
    657 #endif UIDSCORE
    658 
    659