Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!uw-beaver!zephyr.ens.tek.com!master!saab!billr From: billr@saab.CNA.TEK.COM (Bill Randle) Newsgroups: comp.sources.games Subject: v12i061: larn2 - dungeon type adventure game (V12.3), Part08/12 Message-ID: <1123@masterCNA.TEK.COM> Date: 23 Apr 91 20:59:26 GMT Sender: news@masterCNA.TEK.COM Lines: 1517 Approved: billr@saab.CNA.TEK.COM 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 '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'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 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; i1) 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>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; i3) 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 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>1); else j = (level>>1) + 1; X for (i=0; i'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 X# include X#else X# include X# ifndef MSDOS X# include X# endif X# include 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 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; i0) /* 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; iorder == 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= 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= 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; itaxes += 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