billr@saab.CNA.TEK.COM (Bill Randle) (04/24/91)
Submitted-by: routley@tle.ENET.DEC.COM (Kevin Routley) Posting-number: Volume 12, Issue 61 Archive-name: larn2/Part08 Supersedes: larn: Volume 11, Issue 84-94 Environment: Unix, VMS, MS-DOS, OS/2, termcap #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 8 (of 12)." # Contents: bill.c create.c scores.c # Wrapped by billr@saab on Tue Apr 23 13:50:33 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'bill.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'bill.c'\" else echo shar: Extracting \"'bill.c'\" \(8393 characters\) sed "s/^X//" >'bill.c' <<'END_OF_FILE' X/* bill.c */ X#include "header.h" X#include "larndefs.h" X X# ifdef MAIL X# include "player.h" X# ifdef VMS X# define MAILTMP "sys$scratch:" X# else X# define MAILTMP "/tmp/#" X# endif Xstatic int pid; Xstatic char mail600[sizeof(MAILTMP)+sizeof("mail600")+20]; X# endif X/* X * function to create the tax bill for the user X */ X# ifdef MAIL Xstatic letter1() X# else Xstatic letter1(gold) Xlong gold; X# endif X { X# ifdef MAIL X sprintf(mail600,"%s%dmail600",MAILTMP,pid); /* prepare path */ X if (lcreat(mail600) < 0) { write(1,"can't write 600 letter\n",23); return(0);} X#ifndef RFCMAIL X lprcat("\n\n\n\n\n\n\n\n\n\n\n\n"); X#endif /*RFCMAIL*/ X# endif X#ifdef RFCMAIL X lprcat("From: LRS (Larn Revenue Service)\n"); X lprcat("Subject: Undeclared Income\n\n"); X#else /*RFCMAIL*/ X standout("From:"); lprcat(" the LRS (Larn Revenue Service)\n"); X standout("\nSubject:"); lprcat(" undeclared income\n"); X#endif /*RFCMAIL*/ X lprcat("\n We heard you survived the caverns of Larn. Let me be the"); X lprcat("\nfirst to congratulate you on your success. It is quite a feat."); X lprcat("\nIt must also have been very profitable for you."); X lprcat("\n\n The Dungeon Master has informed us that you brought"); X# ifdef MAIL X lprintf("\n%d gold pieces back with you from your journey. As the",(long)c[GOLD]); X# else X lprintf("\n%d gold pieces back with you from your journey. As the", gold); X# endif X lprcat("\ncounty of Larn is in dire need of funds, we have spared no time"); X lprintf("\nin preparing your tax bill. You owe %d gold pieces as", X# ifdef MAIL X (long)c[GOLD]*TAXRATE); X# else X gold * TAXRATE); X# endif X lprcat("\nof this notice, and is due within 5 days. Failure to pay will"); X lprcat("\nmean penalties. Once again, congratulations, We look forward"); X lprcat("\nto your future successful expeditions.\n"); X# ifdef MAIL X lwclose(); X# endif X return(1); X } X Xstatic letter2() X { X# ifdef MAIL X sprintf(mail600,"%s%dmail600",MAILTMP,pid); /* prepare path */ X if (lcreat(mail600) < 0) { write(1,"can't write 601 letter\n",23); return(0);} X#ifndef RFCMAIL X lprcat("\n\n\n\n\n\n\n\n\n\n\n\n"); X#endif /*RFCMAIL*/ X# endif X#ifdef RFCMAIL X lprcat("From: King (His Majesty King Wilfred of Larndom)\n"); X lprcat("Subject: A Noble Deed\n\n"); X#else /*RFCMAIL*/ X standout("From:"); lprcat(" His Majesty King Wilfred of Larndom\n"); X standout("\nSubject:"); lprcat(" a noble deed\n"); X#endif /*RFCMAIL*/ X lprcat("\n I have heard of your magnificent feat, and I, King Wilfred,"); X lprcat("\nforthwith declare today to be a national holiday. Furthermore,"); X lprcat("\nhence three days, Ye be invited to the castle to receive the"); X lprcat("\nhonour of Knight of the realm. Upon thy name shall it be written. . ."); X lprcat("\nBravery and courage be yours."); X lprcat("\nMay you live in happiness forevermore . . .\n"); X# ifdef MAIL X lwclose(); X# endif X return(1); X } X Xstatic letter3() X { X# ifdef MAIL X sprintf(mail600,"%s%dmail600",MAILTMP,pid); /* prepare path */ X if (lcreat(mail600) < 0) { write(1,"can't write 602 letter\n",23); return(0);} X#ifndef RFCMAIL X lprcat("\n\n\n\n\n\n\n\n\n\n\n\n"); X#endif /*RFCMAIL*/ X# endif X#ifdef RFCMAIL X lprcat("From: Endelford (Count Endelford)\n"); X lprcat("Subject: You Bastard!\n\n"); X#else /*RFCMAIL*/ X standout("From:"); lprcat(" Count Endelford\n"); X standout("\nSubject:"); lprcat(" You Bastard!\n"); X#endif /*RFCMAIL*/ X lprcat("\n I heard (from sources) of your journey. Congratulations!"); X lprcat("\nYou Bastard! With several attempts I have yet to endure the"); X lprcat(" caves,\nand you, a nobody, makes the journey! From this time"); X lprcat(" onward, bewarned\nupon our meeting you shall pay the price!\n"); X# ifdef MAIL X lwclose(); X# endif X return(1); X } X Xstatic letter4() X { X# ifdef MAIL X sprintf(mail600,"%s%dmail600", MAILTMP,pid); /* prepare path */ X if (lcreat(mail600) < 0) { write(1,"can't write 603 letter\n",23); return(0);} X#ifndef RFCMAIL X lprcat("\n\n\n\n\n\n\n\n\n\n\n\n"); X#endif /*RFCMAIL*/ X# endif X#ifdef RFCMAIL X lprcat("From: Mainair (Mainair, Duke of Larnty)\n"); X lprcat("Subject: High Praise\n\n"); X#else /*RFCMAIL*/ X standout("From:"); lprcat(" Mainair, Duke of Larnty\n"); X standout("\nSubject:"); lprcat(" High Praise\n"); X#endif /*RFCMAIL*/ X lprcat("\n With a certainty a hero I declare to be amongst us! A nod of"); X lprcat("\nfavour I send to thee. Me thinks Count Endelford this day of"); X lprcat("\nright breath'eth fire as of dragon of whom ye are slayer. I"); X lprcat("\nyearn to behold his anger and jealously. Should ye choose to"); X lprcat("\nunleash some of thy wealth upon those who be unfortunate, I,"); X lprcat("\nDuke Mainair, Shall equal thy gift also.\n"); X# ifdef MAIL X lwclose(); X# endif X return(1); X } X Xstatic letter5() X { X# ifdef MAIL X sprintf(mail600,"%s%dmail600", MAILTMP,pid); /* prepare path */ X if (lcreat(mail600) < 0) { write(1,"can't write 604 letter\n",23); return(0);} X#ifndef RFCMAIL X lprcat("\n\n\n\n\n\n\n\n\n\n\n\n"); X#endif /*RFCMAIL*/ X# endif X#ifdef RFCMAIL X lprcat("From: StMary (St. Mary's Children's Home)\n"); X lprcat("Subject: These Poor Children\n\n"); X#else /*RFCMAIL*/ X standout("From:"); lprcat(" St. Mary's Children's Home\n"); X standout("\nSubject:"); lprcat(" these poor children\n"); X#endif /*RFCMAIL*/ X lprcat("\n News of your great conquests has spread to all of Larndom."); X lprcat("\nMight I have a moment of a great man's time. We here at St."); X lprcat("\nMary's Children's Home are very poor, and many children are"); X lprcat("\nstarving. Disease is widespread and very often fatal without"); X lprcat("\ngood food. Could you possibly find it in your heart to help us"); X lprcat("\nin our plight? Whatever you could give will help much."); X lprcat("\n(your gift is tax deductible)\n"); X# ifdef MAIL X lwclose(); X# endif X return(1); X } X Xstatic letter6() X { X# ifdef MAIL X sprintf(mail600, "%s%dmail600", MAILTMP, pid); /* prepare path */ X if (lcreat(mail600) < 0) { write(1,"can't write 605 letter\n",23); return(0);} X#ifndef RFCMAIL X lprcat("\n\n\n\n\n\n\n\n\n\n\n\n"); X#endif X# endif X#ifdef RFCMAIL X lprcat("From: CancerSociety (The National Cancer Society of Larn)\n"); X lprcat("Subject: Hope\n\n"); X#else /*RFCMAIL*/ X standout("From:"); lprcat(" The National Cancer Society of Larn\n"); X standout("\nSubject:"); lprcat(" hope\n"); X#endif /*RFCMAIL*/ X lprcat("\nCongratulations on your successful expedition. We are sure much"); X lprcat("\ncourage and determination were needed on your quest. There are"); X lprcat("\nmany though, that could never hope to undertake such a journey"); X lprcat("\ndue to an enfeebling disease -- cancer. We at the National"); X lprcat("\nCancer Society of Larn wish to appeal to your philanthropy in"); X lprcat("\norder to save many good people -- possibly even yourself a few"); X lprcat("\nyears from now. Much work needs to be done in researching this"); X lprcat("\ndreaded disease, and you can help today. Could you please see it"); X lprcat("\nin your heart to give generously? Your continued good health"); X lprcat("\ncan be your everlasting reward.\n"); X# ifdef MAIL X lwclose(); X# endif X return(1); X } X X Xstatic int (*pfn[])()= { letter1, letter2, letter3, letter4, letter5, letter6 }; X X# ifdef MAIL X/* X * function to mail the letters to the player if a winner X */ Xmailbill() X { X#ifdef VMS X register int i; X char buf[128]; X pid = getpid(); X for (i=0; i<sizeof(pfn)/sizeof(int (*)()); i++) X if ((*pfn[i])()) { X sprintf(buf, "mail %s %s\n", loginname, mail600); X oneliner(buf); X delete(mail600); X } X } X#else X register int i; X char buf[128]; X wait(0); pid=getpid(); X if (fork() == 0) X { X resetscroll(); X for (i=0; i<sizeof(pfn)/sizeof(int (*)()); i++) X if ((*pfn[i])()) X { X sleep(20); X sprintf(buf,"mail %s < %s",loginname,mail600); X system(buf); unlink(mail600); X } X exit(); X } X } X#endif X# else X X/* Page the mail to the terminal - dgk X */ Xreadmail(gold) Xlong gold; X{ X register int i; X X for (i = 0; i < (sizeof pfn) / (sizeof pfn[0]); i++) { X resetscroll(); X clear(); X (*pfn[i])(gold); /* a bit dirty 'cause of args */ X retcont(); X } X} X# endif END_OF_FILE if test 8393 -ne `wc -c <'bill.c'`; then echo shar: \"'bill.c'\" unpacked with wrong size! fi # end of 'bill.c' fi if test -f 'create.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'create.c'\" else echo shar: Extracting \"'create.c'\" \(15884 characters\) sed "s/^X//" >'create.c' <<'END_OF_FILE' X/* create.c */ X#include "header.h" X#include "larndefs.h" X#include "monsters.h" X#include "objects.h" X#include "player.h" X X/* X makeplayer() X X subroutine to create the player and the players attributes X this is called at the beginning of a game and at no other time X */ Xmakeplayer() X { X register int i; X scbr(); clear(); X c[HPMAX]=c[HP]=10; /* start player off with 15 hit points */ X c[LEVEL]=1; /* player starts at level one */ X c[SPELLMAX]=c[SPELLS]=1; /* total # spells starts off as 3 */ X c[REGENCOUNTER]=16; c[ECOUNTER]=96; /*start regeneration correctly*/ X c[SHIELD] = c[WEAR] = c[WIELD] = -1; X for (i=0; i<26; i++) iven[i]=0; X spelknow[0]=spelknow[1]=1; /*he knows protection, magic missile*/ X if (c[HARDGAME]<=0) X { X iven[0]=OLEATHER; iven[1]=ODAGGER; iven[2] = 0; X ivenarg[1]=ivenarg[0]=c[WEAR]=0; c[WIELD]=1; X } X playerx=rnd(MAXX-2); playery=rnd(MAXY-2); X regen_bottom = TRUE ; X for (i=0; i<6; i++) c[i]=12; /* make the attributes, ie str, int, etc. */ X recalc(); X } X X/* X newcavelevel(level) X int level; X X function to enter a new level. This routine must be called anytime the X player changes levels. If that level is unknown it will be created. X A new set of monsters will be created for a new level, and existing X levels will get a few more monsters. X Note that it is here we remove genocided monsters from the present level. X */ Xnewcavelevel(x) X register int x; X { X register int i,j; X if (beenhere[level]) savelevel(); /* put the level back into storage */ X level = x; /* get the new level and put in working storage */ X if (beenhere[x]) X { X getlevel(); X sethp(0); X positionplayer(); X checkgen(); X return; X } X X /* fill in new level X */ X for (i=0; i<MAXY; i++) X for (j=0; j<MAXX; j++) X know[j][i]=mitem[j][i]=0; X makemaze(x); X makeobject(x); X beenhere[x]=1; X sethp(1); X positionplayer(); X checkgen(); /* wipe out any genocided monsters */ X X#if WIZID X if (wizard || x==0) X#else X if (x==0) X#endif X for (j=0; j<MAXY; j++) X for (i=0; i<MAXX; i++) X know[i][j] = KNOWALL; X } X X/* X makemaze(level) X int level; X X subroutine to make the caverns for a given level. only walls are made. X */ Xstatic int mx,mxl,mxh,my,myl,myh,tmp2; Xstatic makemaze(k) X int k; X { X register int i,j,tmp; X int z; X if (k > 1 && (rnd(17)<=4 || k==MAXLEVEL-1 || k==MAXLEVEL+MAXVLEVEL-1)) X { X if (cannedlevel(k)); return; /* read maze from data file */ X } X if (k==0) tmp=0; else tmp=OWALL; X for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) item[j][i]=tmp; X if (k==0) return; eat(1,1); X if (k==1) item[33][MAXY-1] = OENTRANCE; X X/* now for open spaces -- not on level 10 */ X if (k != MAXLEVEL-1) X { X tmp2 = rnd(3)+3; X for (tmp=0; tmp<tmp2; tmp++) X { X my = rnd(11)+2; myl = my - rnd(2); myh = my + rnd(2); X if (k < MAXLEVEL) X { X mx = rnd(44)+5; mxl = mx - rnd(4); mxh = mx + rnd(12)+3; X z=0; X } X else X { X mx = rnd(60)+3; mxl = mx - rnd(2); mxh = mx + rnd(2); X z = makemonst(k); X } X for (i=mxl; i<mxh; i++) for (j=myl; j<myh; j++) X { item[i][j]=0; X if ((mitem[i][j]=z)) hitp[i][j]=monster[z].hitpoints; X } X } X } X if (k!=MAXLEVEL-1) { my=rnd(MAXY-2); for (i=1; i<MAXX-1; i++) item[i][my] = 0; } X if (k>1) treasureroom(k); X } X X/* X function to eat away a filled in maze X */ Xeat(xx,yy) X register int xx,yy; X { X register int dir,try; X dir = rnd(4); try=2; X while (try) X { X switch(dir) X { X case 1: if (xx <= 2) break; /* west */ X if ((item[xx-1][yy]!=OWALL) || (item[xx-2][yy]!=OWALL)) break; X item[xx-1][yy] = item[xx-2][yy] = 0; X eat(xx-2,yy); break; X X case 2: if (xx >= MAXX-3) break; /* east */ X if ((item[xx+1][yy]!=OWALL) || (item[xx+2][yy]!=OWALL)) break; X item[xx+1][yy] = item[xx+2][yy] = 0; X eat(xx+2,yy); break; X X case 3: if (yy <= 2) break; /* south */ X if ((item[xx][yy-1]!=OWALL) || (item[xx][yy-2]!=OWALL)) break; X item[xx][yy-1] = item[xx][yy-2] = 0; X eat(xx,yy-2); break; X X case 4: if (yy >= MAXY-3 ) break; /* north */ X if ((item[xx][yy+1]!=OWALL) || (item[xx][yy+2]!=OWALL)) break; X item[xx][yy+1] = item[xx][yy+2] = 0; X eat(xx,yy+2); break; X }; X if (++dir > 4) { dir=1; --try; } X } X } X X/* X * function to read in a maze from a data file X * X * Format of maze data file: 1st character = # of mazes in file (ascii digit) X * For each maze: 18 lines (1st 17 used) 67 characters per line X * X * Special characters in maze data file: X * X * # wall D door . random monster X * ~ eye of larn ! cure dianthroritis X * - random object X */ Xstatic cannedlevel(k) X int k; X { X char *row,*lgetl(); X register int i,j; X int it,arg,mit,marg; X if (lopen(larnlevels)<0) X { X write(1,"Can't open the maze data file\n",30); died(-282); return(0); X } X i=lgetc(); if (i<='0') { died(-282); return(0); } X for (i=18*rund(i-'0'); i>0; i--) lgetl(); /* advance to desired maze */ X for (i=0; i<MAXY; i++) X { X row = lgetl(); X for (j=0; j<MAXX; j++) X { X it = mit = arg = marg = 0; X switch(*row++) X { X case '#': it = OWALL; break; X case 'D': it = OCLOSEDDOOR; arg = rnd(30); break; X case '~': if (k!=MAXLEVEL-1) break; X it = OLARNEYE; X mit = rund(8)+DEMONLORD; X marg = monster[mit].hitpoints; break; X case '!': if (k!=MAXLEVEL+MAXVLEVEL-1) break; X it = OPOTION; arg = 21; X mit = DEMONLORD+7; X marg = monster[mit].hitpoints; break; X case '.': if (k<MAXLEVEL) break; X mit = makemonst(k+1); X marg = monster[mit].hitpoints; break; X case '-': it = newobject(k+1,&arg); break; X }; X item[j][i] = it; iarg[j][i] = arg; X mitem[j][i] = mit; hitp[j][i] = marg; X X#if WIZID X know[j][i] = (wizard) ? KNOWALL : 0; X#else X know[j][i] = 0; X#endif X } X } X lrclose(); X return(1); X } X X/* X function to make a treasure room on a level X level 10's treasure room has the eye in it and demon lords X level V3 has potion of cure dianthroritis and demon prince X */ Xstatic treasureroom(lv) X register int lv; X { X register int tx,ty,xsize,ysize; X X for (tx=1+rnd(10); tx<MAXX-10; tx+=10) X if ( (lv==MAXLEVEL-1) || (lv==MAXLEVEL+MAXVLEVEL-1) || rnd(13)==2) X { X xsize = rnd(6)+3; ysize = rnd(3)+3; X ty = rnd(MAXY-9)+1; /* upper left corner of room */ X if (lv==MAXLEVEL-1 || lv==MAXLEVEL+MAXVLEVEL-1) X troom(lv,xsize,ysize,tx=tx+rnd(MAXX-24),ty,rnd(3)+6); X else troom(lv,xsize,ysize,tx,ty,rnd(9)); X } X } X X/* X * subroutine to create a treasure room of any size at a given location X * room is filled with objects and monsters X * the coordinate given is that of the upper left corner of the room X */ Xstatic troom(lv,xsize,ysize,tx,ty,glyph) X int lv,xsize,ysize,tx,ty,glyph; X { X register int i,j; X int tp1,tp2; X for (j=ty-1; j<=ty+ysize; j++) X for (i=tx-1; i<=tx+xsize; i++) /* clear out space for room */ X item[i][j]=0; X for (j=ty; j<ty+ysize; j++) X for (i=tx; i<tx+xsize; i++) /* now put in the walls */ X { X item[i][j]=OWALL; mitem[i][j]=0; X } X for (j=ty+1; j<ty+ysize-1; j++) X for (i=tx+1; i<tx+xsize-1; i++) /* now clear out interior */ X item[i][j]=0; X X switch(rnd(2)) /* locate the door on the treasure room */ X { X case 1: item[i=tx+rund(xsize)][j=ty+(ysize-1)*rund(2)]=OCLOSEDDOOR; X iarg[i][j] = glyph; /* on horizontal walls */ X break; X case 2: item[i=tx+(xsize-1)*rund(2)][j=ty+rund(ysize)]=OCLOSEDDOOR; X iarg[i][j] = glyph; /* on vertical walls */ X break; X }; X X tp1=playerx; tp2=playery; playery=ty+(ysize>>1); X if (c[HARDGAME]<2) X for (playerx=tx+1; playerx<=tx+xsize-2; playerx+=2) X for (i=0, j=rnd(6); i<=j; i++) X { something(lv+2); createmonster(makemonst(lv+1)); } X else X for (playerx=tx+1; playerx<=tx+xsize-2; playerx+=2) X for (i=0, j=rnd(4); i<=j; i++) X { something(lv+2); createmonster(makemonst(lv+3)); } X X playerx=tp1; playery=tp2; X } X X/* X *********** X MAKE_OBJECT X *********** X subroutine to create the objects in the maze for the given level X */ Xstatic makeobject(j) X register int j; X { X register int i; X if (j==0) X { X fillroom(OENTRANCE,0); /* entrance to dungeon */ X fillroom(ODNDSTORE,0); /* the DND STORE */ X fillroom(OSCHOOL,0); /* college of Larn */ X fillroom(OBANK,0); /* 1st national bank of larn */ X fillroom(OVOLDOWN,0); /* volcano shaft to temple */ X fillroom(OHOME,0); /* the players home & family */ X fillroom(OTRADEPOST,0); /* the trading post */ X fillroom(OLRS,0); /* the larn revenue service */ X return; X } X X if (j==MAXLEVEL) fillroom(OVOLUP,0); /* volcano shaft up from the temple */ X X/* make the fixed objects in the maze STAIRS */ X if ((j>0) && (j != MAXLEVEL-1) && (j != MAXLEVEL+MAXVLEVEL-1)) X fillroom(OSTAIRSDOWN,0); X if ((j > 1) && (j != MAXLEVEL)) X fillroom(OSTAIRSUP,0); X X/* make the random objects in the maze */ X X fillmroom(rund(3),OBOOK,j); X fillmroom(rund(3),OALTAR,0); X fillmroom(rund(3),OSTATUE,0); X fillmroom(rund(3),OPIT,0); X fillmroom(rund(3),OFOUNTAIN,0); X fillmroom( rnd(3)-2,OIVTELETRAP,0); X fillmroom(rund(2),OTHRONE,0); X fillmroom(rund(2),OMIRROR,0); X fillmroom(rund(2),OTRAPARROWIV,0); X fillmroom( rnd(3)-2,OIVDARTRAP,0); X fillmroom(rund(3),OCOOKIE,0); X if (j==1) X fillmroom(1,OCHEST,j); X else X fillmroom(rund(2),OCHEST,j); X if ((j != MAXLEVEL-1) && (j != MAXLEVEL+MAXVLEVEL-1)) X fillmroom(rund(2),OIVTRAPDOOR,0); X if (j<=10) X { X fillmroom((rund(2)),ODIAMOND,rnd(10*j+1)+10); X fillmroom(rund(2),ORUBY,rnd(6*j+1)+6); X fillmroom(rund(2),OEMERALD,rnd(4*j+1)+4); X fillmroom(rund(2),OSAPPHIRE,rnd(3*j+1)+2); X } X for (i=0; i<rnd(4)+3; i++) X fillroom(OPOTION,newpotion()); /* make a POTION */ X for (i=0; i<rnd(5)+3; i++) X fillroom(OSCROLL,newscroll()); /* make a SCROLL */ X for (i=0; i<rnd(12)+11; i++) X fillroom(OGOLDPILE,12*rnd(j+1)+(j<<3)+10); /* make GOLD */ X if (j==5) X fillroom(OBANK2,0); /* branch office of the bank */ X froom(2,ORING,0); /* a ring mail */ X froom(1,OSTUDLEATHER,0); /* a studded leather */ X froom(3,OSPLINT,0); /* a splint mail */ X froom(5,OSHIELD,rund(3)); /* a shield */ X froom(2,OBATTLEAXE,rund(3)); /* a battle axe */ X froom(5,OLONGSWORD,rund(3)); /* a long sword */ X froom(5,OFLAIL,rund(3)); /* a flail */ X froom(4,OREGENRING,rund(3)); /* ring of regeneration */ X froom(1,OPROTRING,rund(3)); /* ring of protection */ X froom(2,OSTRRING,1+rnd(3)); /* ring of strength */ X froom(7,OSPEAR,rnd(5)); /* a spear */ X froom(3,OORBOFDRAGON,0); /* orb of dragon slaying*/ X froom(4,OSPIRITSCARAB,0); /* scarab of negate spirit*/ X froom(4,OCUBEofUNDEAD,0); /* cube of undead control */ X froom(2,ORINGOFEXTRA,0); /* ring of extra regen */ X froom(3,ONOTHEFT,0); /* device of antitheft */ X froom(2,OSWORDofSLASHING,0); /* sword of slashing */ X if (c[BESSMANN]==0) X { X froom(4,OHAMMER,0);/*Bessman's flailing hammer*/ X c[BESSMANN]=1; X } X if (c[HARDGAME]<3 || (rnd(4)==3)) X { X if (j>3) X { X froom(3,OSWORD,3); /* sunsword + 3 */ X froom(5,O2SWORD,rnd(4)); /* a two handed sword */ X froom(3,OBELT,4); /* belt of striking */ X froom(3,OENERGYRING,3); /* energy ring */ X froom(4,OPLATE,5); /* platemail + 5 */ X froom(3,OCLEVERRING,1+rnd(2)); /* ring of cleverness */ X } X } X } X X/* X subroutine to fill in a number of objects of the same kind X */ X Xstatic fillmroom(n,what,arg) X int n,arg; X char what; X { X register int i; X for (i=0; i<n; i++) fillroom(what,arg); X } Xstatic froom(n,itm,arg) X int n,arg; X char itm; X { if (rnd(151) < n) fillroom(itm,arg); } X X/* X subroutine to put an object into an empty room X * uses a random walk X */ Xstatic fillroom(what,arg) X int arg; X char what; X { X register int x,y; X X#ifdef EXTRA X c[FILLROOM]++; X#endif X X x=rnd(MAXX-2); y=rnd(MAXY-2); X while (item[x][y]) X { X X#ifdef EXTRA X c[RANDOMWALK]++; /* count up these random walks */ X#endif X X x += rnd(3)-2; y += rnd(3)-2; X if (x > MAXX-2) x=1; if (x < 1) x=MAXX-2; X if (y > MAXY-2) y=1; if (y < 1) y=MAXY-2; X } X item[x][y]=what; iarg[x][y]=arg; X } X X/* X subroutine to put monsters into an empty room without walls or other X monsters X */ Xfillmonst(what) X char what; X { X register int x,y,trys; X for (trys=5; trys>0; --trys) /* max # of creation attempts */ X { X x=rnd(MAXX-2); y=rnd(MAXY-2); X if ((item[x][y]==0) && (mitem[x][y]==0) && ((playerx!=x) || (playery!=y))) X { X mitem[x][y] = what; know[x][y] &= ~KNOWHERE; X hitp[x][y] = monster[what].hitpoints; return(0); X } X } X return(-1); /* creation failure */ X } X X/* X creates an entire set of monsters for a level X must be done when entering a new level X if sethp(1) then wipe out old monsters else leave them there X */ Xstatic sethp(flg) X int flg; X { X register int i,j; X if (flg) for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) stealth[j][i]=0; X if (level==0) { c[TELEFLAG]=0; return; } /* if teleported and found level 1 then know level we are on */ X if (flg) j = rnd(12) + 2 + (level>>1); else j = (level>>1) + 1; X for (i=0; i<j; i++) fillmonst(makemonst(level)); X } X X/* X * Function to destroy all genocided monsters on the present level X */ Xstatic checkgen() X { X register int x,y; X for (y=0; y<MAXY; y++) X for (x=0; x<MAXX; x++) X if (monster[mitem[x][y]].genocided) X mitem[x][y]=0; /* no more monster */ X } END_OF_FILE if test 15884 -ne `wc -c <'create.c'`; then echo shar: \"'create.c'\" unpacked with wrong size! fi # end of 'create.c' fi if test -f 'scores.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'scores.c'\" else echo shar: Extracting \"'scores.c'\" \(26064 characters\) sed "s/^X//" >'scores.c' <<'END_OF_FILE' X/* scores.c X * X * readboard() Function to read in the scoreboard into a static buffer X * writeboard() Function to write the scoreboard from readboard()'s buffer X * makeboard() Function to create a new scoreboard (wipe out old one) X * hashewon() Function to return 1 if player has won a game before, else 0 X * long paytaxes(x) Function to pay taxes if any are due X * winshou() Subroutine to print out the winning scoreboard X * shou(x) Subroutine to print out the non-winners scoreboard X * showscores() Function to show the scoreboard on the terminal X * showallscores() Function to show scores and the iven lists that go with them X * sortboard() Function to sort the scoreboard X * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard X * new1sub(score,i,whoo,taxes) Subroutine to put player into a X * new2sub(score,i,whoo,whyded) Subroutine to put player into a X * died(x) Subroutine to record who played larn, and what the score was X * diedsub(x) Subroutine to print out a line showing player when he is killed X * diedlog() Subroutine to read a log file and print it out in ascii format X * getplid(name) Function to get players id # from id file X */ X#ifdef VMS X# include <types.h> X# include <stat.h> X#else X# include <sys/types.h> X# ifndef MSDOS X# include <sys/times.h> X# endif X# include <sys/stat.h> X#endif X#include "header.h" X#include "larndefs.h" X#include "monsters.h" X#include "objects.h" X#include "player.h" X Xstruct scofmt /* This is the structure for the scoreboard */ X { X long score; /* the score of the player */ X long suid; /* the user id number of the player */ X short what; /* the number of the monster that killed player */ X short level; /* the level player was on when he died */ X short hardlev; /* the level of difficulty player played at */ X short order; /* the relative ordering place of this entry */ X char who[40]; /* the name of the character */ X char sciv[26][2]; /* this is the inventory list of the character */ X }; Xstruct wscofmt /* This is the structure for the winning scoreboard */ X { X long score; /* the score of the player */ X long timeused; /* the time used in mobuls to win the game */ X long taxes; /* taxes he owes to LRS */ X long suid; /* the user id number of the player */ X short hardlev; /* the level of difficulty player played at */ X short order; /* the relative ordering place of this entry */ X# ifndef MAIL /* dgk */ X char hasmail; /* 1 if mail is to be read, 0 otherwise */ X# endif X char who[40]; /* the name of the character */ X }; X Xstruct log_fmt /* 102 bytes struct for the log file */ X { X long score; /* the players score */ X long diedtime; /* time when game was over */ X short cavelev; /* level in caves */ X short diff; /* difficulty player played at */ X#ifdef EXTRA X long elapsedtime; /* real time of game in seconds */ X long bytout; /* bytes input and output */ X long bytin; X long moves; /* number of moves made by player */ X short ac; /* armor class of player */ X short hp,hpmax; /* players hitpoints */ X short cputime; /* cpu time needed in seconds */ X short killed,spused;/* monsters killed and spells cast */ X short usage; /* usage of the cpu in % */ X short lev; /* player level */ X#endif X char who[12]; /* player name */ X char what[46]; /* what happened to player */ X }; X Xstatic struct scofmt sco[SCORESIZE]; /* the structure for the scoreboard */ Xstatic struct wscofmt winr[SCORESIZE]; /* struct for the winning scoreboard */ Xstatic struct log_fmt logg; /* structure for the log file */ Xstatic char *whydead[] = { X "quit", "suspended", "self - annihilated", "shot by an arrow", X "hit by a dart", "fell into a pit", "fell into a bottomless pit", X "a winner", "trapped in solid rock", "killed by a missing save file", X "killed by an old save file", "caught by the greedy cheater checker trap", X "killed by a protected save file","killed his family and committed suicide", X "erased by a wayward finger", "fell through a bottomless trap door", X "fell through a trap door", "drank some poisonous water", X "fried by an electric shock", "slipped on a volcano shaft", X "killed by a stupid act of frustration", "attacked by a revolting demon", X "hit by his own magic", "demolished by an unseen attacker", X "fell into the dreadful sleep", "killed by an exploding chest", X/*26*/ "killed by a missing maze data file", "annihilated in a sphere", X "died a post mortem death","wasted by a malloc() failure" X }; X X X/* X * readboard() Function to read in the scoreboard into a static buffer X * X * returns -1 if unable to read in the scoreboard, returns 0 if all is OK X */ Xstatic readboard() X { X if (lopen(scorefile)<0) X { lprcat("Can't read scoreboard\n"); lflush(); return(-1); } X lrfill((char*)sco,sizeof(sco)); lrfill((char*)winr,sizeof(winr)); X lrclose(); lcreat((char*)0); return(0); X } X X/* X * writeboard() Function to write the scoreboard from readboard()'s buffer X * X * returns -1 if unable to write the scoreboard, returns 0 if all is OK X */ Xstatic writeboard() X { X set_score_output(); X if (lcreat(scorefile)<0) X { lprcat("Can't write scoreboard\n"); lflush(); return(-1); } X lwrite((char*)sco,sizeof(sco)); lwrite((char*)winr,sizeof(winr)); X lwclose(); lcreat((char*)0); return(0); X } X X/* X * makeboard() Function to create a new scoreboard (wipe out old one) X * X * returns -1 if unable to write the scoreboard, returns 0 if all is OK X */ Xmakeboard() X { X register int i; X for (i=0; i<SCORESIZE; i++) X { X winr[i].taxes = winr[i].score = sco[i].score = 0; X winr[i].order = sco[i].order = i; X } X if (writeboard()) return(-1); X chmod(scorefile,0666); X return(0); X } X X/* X * hashewon() Function to return 1 if player has won a game before, else 0 X * X * This function also sets c[HARDGAME] to appropriate value -- 0 if not a X * winner, otherwise the next level of difficulty listed in the winners X * scoreboard. This function also sets outstanding_taxes to the value in X * the winners scoreboard. X */ Xhashewon() X { X register int i; X c[HARDGAME] = 0; X if (readboard() < 0) return(0); /* can't find scoreboard */ X for (i=0; i<SCORESIZE; i++) /* search through winners scoreboard */ X if (winr[i].suid == userid) X if (winr[i].score > 0) X { X c[HARDGAME]=winr[i].hardlev+1; outstanding_taxes=winr[i].taxes; X return(1); X } X return(0); X } X X# ifndef MAIL /* dgk */ Xcheckmail() X{ X register int i; X long gold, taxes; X X if (readboard() < 0) X return; /* can't find scoreboard */ X for (i = 0; i < SCORESIZE; i++) /* search through winners scoreboard */ X if (winr[i].suid == userid X && winr[i].score > 0 X && winr[i].hasmail) { X winr[i].hasmail = 0; X gold = taxes = winr[i].taxes; X writeboard(); X X /* Intuit the amount of gold -- should have changed X * the score file, but ... TAXRATE is an fraction. X */ X while ((gold * TAXRATE) < taxes) X gold += taxes; X readmail(gold); X } X} X# endif X X X/* X * long paytaxes(x) Function to pay taxes if any are due X * X * Enter with the amount (in gp) to pay on the taxes. X * Returns amount actually paid. X */ Xlong paytaxes(x) X long x; X { X register int i; X register long amt; X if (x<0) return(0L); X if (readboard()<0) return(0L); X for (i=0; i<SCORESIZE; i++) X if (winr[i].suid == userid) /* look for players winning entry */ X if (winr[i].score>0) /* search for a winning entry for the player */ X { X amt = winr[i].taxes; X if (x < amt) amt=x; /* don't overpay taxes (Ughhhhh) */ X winr[i].taxes -= amt; X outstanding_taxes -= amt; X if (writeboard()<0) return(0); X return(amt); X } X return(0L); /* couldn't find user on winning scoreboard */ X } X X/* X * winshou() Subroutine to print out the winning scoreboard X * X * Returns the number of players on scoreboard that were shown X */ Xstatic winshou() X { X register struct wscofmt *p; X register int i,j,count; X for (count=j=i=0; i<SCORESIZE; i++) /* is there anyone on the scoreboard? */ X if (winr[i].score != 0) X { j++; break; } X if (j) X { X lprcat("\n Score Difficulty Time Needed Larn Winners List\n"); X X for (i=0; i<SCORESIZE; i++) /* this loop is needed to print out the */ X for (j=0; j<SCORESIZE; j++) /* winners in order */ X { X p = &winr[j]; /* pointer to the scoreboard entry */ X if (p->order == i) X { X if (p->score) X { X count++; X lprintf("%10d %2d %5d Mobuls %s \n", X (long)p->score,(long)p->hardlev,(long)p->timeused,p->who); X } X break; X } X } X } X return(count); /* return number of people on scoreboard */ X } X X/* X * shou(x) Subroutine to print out the non-winners scoreboard X * int x; X * X * Enter with 0 to list the scores, enter with 1 to list inventories too X * Returns the number of players on scoreboard that were shown X */ Xstatic shou(x) X int x; X { X register int i,j,n,k; X int count; X for (count=j=i=0; i<SCORESIZE; i++) /* is the scoreboard empty? */ X if (sco[i].score!= 0) X { j++; break; } X if (j) X { X lprcat("\n Score Difficulty Larn Visitor Log\n"); X for (i=0; i<SCORESIZE; i++) /* be sure to print them out in order */ X for (j=0; j<SCORESIZE; j++) X if (sco[j].order == i) X { X if (sco[j].score) X { X count++; X lprintf("%10d %2d %s ", X (long)sco[j].score,(long)sco[j].hardlev,sco[j].who); X if (sco[j].what < 256) lprintf("killed by a %s",monster[sco[j].what].name); X else lprintf("%s",whydead[sco[j].what - 256]); X if (x != 263) lprintf(" on %s",levelname[sco[j].level]); X if (x) X { X for (n=0; n<26; n++) { iven[n]=sco[j].sciv[n][0]; ivenarg[n]=sco[j].sciv[n][1]; } X for (k=1; k<99; k++) X for (n=0; n<26; n++) X if (k==iven[n]) show3(n); X lprcat("\n\n"); X } X else lprc('\n'); X } X j=SCORESIZE; X } X } X return(count); /* return the number of players just shown */ X } X X/* X * showscores() Function to show the scoreboard on the terminal X * X * Returns nothing of value X */ Xstatic char esb[] = "The scoreboard is empty.\n"; Xshowscores() X { X register int i,j; X lflush(); lcreat((char*)0); if (readboard()<0) return; X i=winshou(); j=shou(0); X if (i+j == 0) lprcat(esb); else lprc('\n'); X lflush(); X } X X/* X * showallscores() Function to show scores and the iven lists that go with them X * X * Returns nothing of value X */ Xshowallscores() X { X register int i,j; X lflush(); lcreat((char*)0); if (readboard()<0) return; X c[WEAR] = c[WIELD] = c[SHIELD] = -1; /* not wielding or wearing anything */ X for (i=0; i<MAXPOTION; i++) potionname[i][0]=' '; X for (i=0; i<MAXSCROLL; i++) scrollname[i][0]=' '; X i=winshou(); j=shou(1); X if (i+j==0) lprcat(esb); else lprc('\n'); X lflush(); X } X X/* X * sortboard() Function to sort the scoreboard X * X * Returns 0 if no sorting done, else returns 1 X */ Xstatic sortboard() X { X register int i,j,pos; X long jdat; X for (i=0; i<SCORESIZE; i++) sco[i].order = winr[i].order = -1; X pos=0; while (pos < SCORESIZE) X { X jdat=0; X for (i=0; i<SCORESIZE; i++) X if ((sco[i].order < 0) && (sco[i].score >= jdat)) X { j=i; jdat=sco[i].score; } X sco[j].order = pos++; X } X pos=0; while (pos < SCORESIZE) X { X jdat=0; X for (i=0; i<SCORESIZE; i++) X if ((winr[i].order < 0) && (winr[i].score >= jdat)) X { j=i; jdat=winr[i].score; } X winr[j].order = pos++; X } X return(1); X } X X/* X * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard X * int score, winner, whyded; X * char *whoo; X * X * Enter with the total score in gp in score, players name in whoo, X * died() reason # in whyded, and TRUE/FALSE in winner if a winner X * ex. newscore(1000, "player 1", 32, 0); X */ Xstatic newscore(score, whoo, whyded, winner) X long score; X int winner, whyded; X char *whoo; X { X register int i; X long taxes; X if (readboard() < 0) return; /* do the scoreboard */ X /* if a winner then delete all non-winning scores */ X if (cheat) winner=0; /* if he cheated, don't let him win */ X if (winner) X { X for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid) sco[i].score=0; X taxes = score*TAXRATE; X score += 100000*c[HARDGAME]; /* bonus for winning */ X /* if he has a slot on the winning scoreboard update it if greater score */ X for (i=0; i<SCORESIZE; i++) if (winr[i].suid == userid) X { new1sub(score,i,whoo,taxes); return; } X /* he had no entry. look for last entry and see if he has a greater score */ X for (i=0; i<SCORESIZE; i++) if (winr[i].order == SCORESIZE-1) X { new1sub(score,i,whoo,taxes); return; } X } X else if (!cheat) /* for not winning scoreboard */ X { X /* if he has a slot on the scoreboard update it if greater score */ X for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid) X { new2sub(score,i,whoo,whyded); return; } X /* he had no entry. look for last entry and see if he has a greater score */ X for (i=0; i<SCORESIZE; i++) if (sco[i].order == SCORESIZE-1) X { new2sub(score,i,whoo,whyded); return; } X } X } X X/* X * new1sub(score,i,whoo,taxes) Subroutine to put player into a X * int score,i,whyded,taxes; winning scoreboard entry if his score X * char *whoo; is high enough X * X * Enter with the total score in gp in score, players name in whoo, X * died() reason # in whyded, and TRUE/FALSE in winner if a winner X * slot in scoreboard in i, and the tax bill in taxes. X * Returns nothing of value X */ Xstatic new1sub(score,i,whoo,taxes) X long score,taxes; X int i; X char *whoo; X { X register struct wscofmt *p; X p = &winr[i]; X p->taxes += taxes; X if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) X { X strcpy(p->who,whoo); p->score=score; X p->hardlev=c[HARDGAME]; p->suid=userid; X p->timeused=gtime/100; X# ifndef MAIL /* dgk */ X p->hasmail = 1; X# endif X } X } X X/* X * new2sub(score,i,whoo,whyded) Subroutine to put player into a X * int score,i,whyded,taxes; non-winning scoreboard entry if his X * char *whoo; score is high enough X * X * Enter with the total score in gp in score, players name in whoo, X * died() reason # in whyded, and slot in scoreboard in i. X * Returns nothing of value X */ Xstatic new2sub(score,i,whoo,whyded) X long score; X int i,whyded; X char *whoo; X { X register int j; X register struct scofmt *p; X p = &sco[i]; X if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) X { X strcpy(p->who,whoo); p->score=score; X p->what=whyded; p->hardlev=c[HARDGAME]; X p->suid=userid; p->level=level; X for (j=0; j<26; j++) X { p->sciv[j][0]=iven[j]; p->sciv[j][1]=ivenarg[j]; } X } X } X X/* X * died(x) Subroutine to record who played larn, and what the score was X * int x; X * X * if x < 0 then don't show scores X * died() never returns! (unless c[LIFEPROT] and a reincarnatable death!) X * X * < 256 killed by the monster number X * 256 quit X * 257 suspended X * 258 self - annihilated X * 259 shot by an arrow X * 260 hit by a dart X * 261 fell into a pit X * 262 fell into a bottomless pit X * 263 a winner X * 264 trapped in solid rock X * 265 killed by a missing save file X * 266 killed by an old save file X * 267 caught by the greedy cheater checker trap X * 268 killed by a protected save file X * 269 killed his family and killed himself X * 270 erased by a wayward finger X * 271 fell through a bottomless trap door X * 272 fell through a trap door X * 273 drank some poisonous water X * 274 fried by an electric shock X * 275 slipped on a volcano shaft X * 276 killed by a stupid act of frustration X * 277 attacked by a revolting demon X * 278 hit by his own magic X * 279 demolished by an unseen attacker X * 280 fell into the dreadful sleep X * 281 killed by an exploding chest X * 282 killed by a missing maze data file X * 283 killed by a sphere of annihilation X * 284 died a post mortem death X * 285 malloc() failure X * 300 quick quit -- don't put on scoreboard X */ X Xstatic int scorerror; Xdied(x) X int x; X { X register int f,win; X char ch,*mod; X long zzz,i; X# ifdef EXTRA X struct tms cputime; X# endif X if (c[LIFEPROT]>0) /* if life protection */ X { X switch((x>0) ? x : -x) X { X case 256: case 257: case 262: case 263: case 265: case 266: X case 267: case 268: case 269: case 271: case 282: case 284: X case 285: case 300: goto invalid; /* can't be saved */ X }; X --c[LIFEPROT]; c[HP]=1; --c[CONSTITUTION]; X cursors(); lprcat("\nYou feel wiiieeeeerrrrrd all over! "); beep(); X lflush(); sleep(4); X return; /* only case where died() returns */ X } Xinvalid: X clearvt100(); lflush(); f=0; X if (ckpflag) unlink(ckpfile); /* remove checkpoint file if used */ X# ifdef MSDOS X if (swapfd) { X close(swapfd); X (void) unlink(swapfile);/* Remove swapfile */ X } X unsetraw(); X# endif X if (x<0) { f++; x = -x; } /* if we are not to display the scores */ X if ((x == 300) || (x == 257)) exit(); /* for quick exit or saved game */ X if (x == 263) win = 1; else win = 0; X c[GOLD] += c[BANKACCOUNT]; c[BANKACCOUNT] = 0; X /* now enter the player at the end of the scoreboard */ X newscore(c[GOLD], logname, x, win); X diedsub(x); /* print out the score line */ lflush(); X X set_score_output(); X if ((wizard == 0) && (c[GOLD] > 0)) /* wizards can't score */ X { X if (lappend(logfile)<0) /* append to file */ X { X if (lcreat(logfile)<0) /* and can't create new log file */ X { X lcreat((char*)0); X lprcat("\nCan't open record file: I can't post your score.\n"); X sncbr(); resetscroll(); lflush(); exit(); X } X chmod(logfile,0666); X } X strcpy(logg.who,loginname); X logg.score = c[GOLD]; logg.diff = c[HARDGAME]; X if (x < 256) X { X ch = *monster[x].name; X if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') X mod="an"; else mod="a"; X sprintf(logg.what,"killed by %s %s",mod,monster[x].name); X } X else sprintf(logg.what,"%s",whydead[x - 256]); X logg.cavelev=level; X time(&zzz); /* get cpu time -- write out score info */ X logg.diedtime=zzz; X#ifdef EXTRA X times(&cputime); /* get cpu time -- write out score info */ X logg.cputime = i = (cputime.tms_utime + cputime.tms_stime)/60 + c[CPUTIME]; X logg.lev=c[LEVEL]; logg.ac=c[AC]; X logg.hpmax=c[HPMAX]; logg.hp=c[HP]; X logg.elapsedtime=(zzz-initialtime+59)/60; X logg.usage=(10000*i)/(zzz-initialtime); X logg.bytin=c[BYTESIN]; logg.bytout=c[BYTESOUT]; X logg.moves=c[MOVESMADE]; logg.spused=c[SPELLSCAST]; X logg.killed=c[MONSTKILLED]; X#endif X lwrite((char*)&logg,sizeof(struct log_fmt)); lwclose(); X X/* now for the scoreboard maintenance -- not for a suspended game */ X if (x != 257) X { X if (sortboard()) scorerror = writeboard(); X } X } X if ((x==256) || (x==257) || (f != 0)) exit(); X if (scorerror == 0) showscores(); /* if we updated the scoreboard */ X# ifdef MAIL X if (x == 263) mailbill(); X# endif X exit(); X } X X/* X * diedsub(x) Subroutine to print out the line showing the player when he is killed X * int x; X */ Xstatic diedsub(x) Xint x; X { X register char ch,*mod; X lprintf("Score: %d, Diff: %d, %s ",(long)c[GOLD],(long)c[HARDGAME],logname); X if (x < 256) X { X ch = *monster[x].name; X if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') X mod="an"; else mod="a"; X lprintf("killed by %s %s",mod,monster[x].name); X } X else lprintf("%s",whydead[x - 256]); X if (x != 263) lprintf(" on %s\n",levelname[level]); else lprc('\n'); X } X X/* X * diedlog() Subroutine to read a log file and print it out in ascii format X */ Xdiedlog() X { X register int n; X register char *p; X struct stat stbuf; X lcreat((char*)0); X if (lopen(logfile)<0) X { X lprintf("Can't locate log file <%s>\n",logfile); X return; X } X if (fstat(fd,&stbuf) < 0) X { X lprintf("Can't stat log file <%s>\n",logfile); X return; X } X for (n=stbuf.st_size/sizeof(struct log_fmt); n>0; --n) X { X lrfill((char*)&logg,sizeof(struct log_fmt)); X p = ctime(&logg.diedtime); p[16]='\n'; p[17]=0; X 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); X#ifdef EXTRA X if (logg.moves<=0) logg.moves=1; X 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)); X lprintf(" CPU time used: %d seconds, Machine usage: %d.%02d%%\n",(long)(logg.cputime),(long)(logg.usage/100),(long)(logg.usage%100)); X 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)); X lprintf(" out bytes per move: %d, time per move: %d ms\n",(long)(logg.bytout/logg.moves),(long)((logg.cputime*1000)/logg.moves)); X#endif X } X lflush(); lrclose(); return; X } X X#ifndef UIDSCORE X/* X * getplid(name) Function to get players id # from id file X * X * Enter with the name of the players character in name. X * Returns the id # of the players character, or -1 if failure. X * This routine will try to find the name in the id file, if its not there, X * it will try to make a new entry in the file. Only returns -1 if can't X * find him in the file, and can't make a new entry in the file. X * Format of playerids file: X * Id # in ascii \n character name \n X */ Xstatic int havepid= -1; /* playerid # if previously done */ Xgetplid(nam) X char *nam; X { X int fd7,high=999,no; X register char *p,*p2; X char name[80]; X if (havepid != -1) return(havepid); /* already did it */ X lflush(); /* flush any pending I/O */ X sprintf(name,"%s\n",nam); /* append a \n to name */ X if (lopen(playerids) < 0) /* no file, make it */ X { X if ((fd7=creat(playerids,0666)) < 0) return(-1); /* can't make it */ X close(fd7); goto addone; /* now append new playerid record to file */ X } X for (;;) /* now search for the name in the player id file */ X { X p = lgetl(); if (p==NULL) break; /* EOF? */ X no = atoi(p); /* the id # */ X p2= lgetl(); if (p2==NULL) break; /* EOF? */ X if (no>high) high=no; /* accumulate highest id # */ X if (strcmp(p2,name)==0) /* we found him */ X { X return(no); /* his id number */ X } X } X lrclose(); X /* if we get here, we didn't find him in the file -- put him there */ Xaddone: X if (lappend(playerids) < 0) return(-1); /* can't open file for append */ X lprintf("%d\n%s",(long)++high,name); /* new id # and name */ X lwclose(); X lcreat((char*)0); /* re-open terminal channel */ X return(high); X } X#endif UIDSCORE END_OF_FILE if test 26064 -ne `wc -c <'scores.c'`; then echo shar: \"'scores.c'\" unpacked with wrong size! fi # end of 'scores.c' fi echo shar: End of archive 8 \(of 12\). cp /dev/null ark8isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 12 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0