📄 scores.c
字号:
/* scores.c Larn is copyrighted 1986 by Noah Morgan. * * Functions in this file are: * * readboard() Function to read in the scoreboard into a static buffer * writeboard() Function to write the scoreboard from readboard()'s buffer * makeboard() Function to create a new scoreboard (wipe out old one) * hashewon() Function to return 1 if player has won a game before, else 0 * long paytaxes(x) Function to pay taxes if any are due * winshou() Subroutine to print out the winning scoreboard * shou(x) Subroutine to print out the non-winners scoreboard * showscores() Function to show the scoreboard on the terminal * showallscores() Function to show scores and the iven lists that go with them * sortboard() Function to sort the scoreboard * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard * new1sub(score,i,whoo,taxes) Subroutine to put player into a * new2sub(score,i,whoo,whyded) Subroutine to put player into a * died(x) Subroutine to record who played larn, and what the score was * diedsub(x) Subroutine to print out a line showing player when he is killed * diedlog() Subroutine to read a log file and print it out in ascii format * getplid(name) Function to get players id # from id file * */#include <sys/types.h>#include <sys/times.h>#include <sys/stat.h>#include "header.h"struct scofmt /* This is the structure for the scoreboard */ { long score; /* the score of the player */ long suid; /* the user id number of the player */ short what; /* the number of the monster that killed player */ short level; /* the level player was on when he died */ short hardlev; /* the level of difficulty player played at */ short order; /* the relative ordering place of this entry */ char who[40]; /* the name of the character */ char sciv[26][2]; /* this is the inventory list of the character */ };struct wscofmt /* This is the structure for the winning scoreboard */ { long score; /* the score of the player */ long timeused; /* the time used in mobuls to win the game */ long taxes; /* taxes he owes to LRS */ long suid; /* the user id number of the player */ short hardlev; /* the level of difficulty player played at */ short order; /* the relative ordering place of this entry */ char who[40]; /* the name of the character */ };struct log_fmt /* 102 bytes struct for the log file */ { long score; /* the players score */ long diedtime; /* time when game was over */ short cavelev; /* level in caves */ short diff; /* difficulty player played at */#ifdef EXTRA long elapsedtime; /* real time of game in seconds */ long bytout; /* bytes input and output */ long bytin; long moves; /* number of moves made by player */ short ac; /* armor class of player */ short hp,hpmax; /* players hitpoints */ short cputime; /* cpu time needed in seconds */ short killed,spused;/* monsters killed and spells cast */ short usage; /* usage of the cpu in % */ short lev; /* player level */#endif char who[12]; /* player name */ char what[46]; /* what happened to player */ };static struct scofmt sco[SCORESIZE]; /* the structure for the scoreboard */static struct wscofmt winr[SCORESIZE]; /* struct for the winning scoreboard */static struct log_fmt logg; /* structure for the log file */static char *whydead[] = { "quit", "suspended", "self - annihilated", "shot by an arrow", "hit by a dart", "fell into a pit", "fell into a bottomless pit", "a winner", "trapped in solid rock", "killed by a missing save file", "killed by an old save file", "caught by the greedy cheater checker trap", "killed by a protected save file","killed his family and committed suicide", "erased by a wayward finger", "fell through a bottomless trap door", "fell through a trap door", "drank some poisonous water", "fried by an electric shock", "slipped on a volcano shaft", "killed by a stupid act of frustration", "attacked by a revolting demon", "hit by his own magic", "demolished by an unseen attacker", "fell into the dreadful sleep", "killed by an exploding chest",/*26*/ "killed by a missing maze data file", "annihilated in a sphere", "died a post mortem death","wasted by a malloc() failure" };/* * readboard() Function to read in the scoreboard into a static buffer * * returns -1 if unable to read in the scoreboard, returns 0 if all is OK */readboard() { if (lopen(scorefile)<0) { lprcat("Can't read scoreboard\n"); lflush(); return(-1); } lrfill((char*)sco,sizeof(sco)); lrfill((char*)winr,sizeof(winr)); lrclose(); lcreat((char*)0); return(0); }/* * writeboard() Function to write the scoreboard from readboard()'s buffer * * returns -1 if unable to write the scoreboard, returns 0 if all is OK */writeboard() { set_score_output(); if (lcreat(scorefile)<0) { lprcat("Can't write scoreboard\n"); lflush(); return(-1); } lwrite((char*)sco,sizeof(sco)); lwrite((char*)winr,sizeof(winr)); lwclose(); lcreat((char*)0); return(0); }/* * makeboard() Function to create a new scoreboard (wipe out old one) * * returns -1 if unable to write the scoreboard, returns 0 if all is OK */makeboard() { register int i; for (i=0; i<SCORESIZE; i++) { winr[i].taxes = winr[i].score = sco[i].score = 0; winr[i].order = sco[i].order = i; } if (writeboard()) return(-1); chmod(scorefile,0660); return(0); }/* * hashewon() Function to return 1 if player has won a game before, else 0 * * This function also sets c[HARDGAME] to appropriate value -- 0 if not a * winner, otherwise the next level of difficulty listed in the winners * scoreboard. This function also sets outstanding_taxes to the value in * the winners scoreboard. */hashewon() { register int i; c[HARDGAME] = 0; if (readboard() < 0) return(0); /* can't find scoreboard */ for (i=0; i<SCORESIZE; i++) /* search through winners scoreboard */ if (winr[i].suid == userid) if (winr[i].score > 0) { c[HARDGAME]=winr[i].hardlev+1; outstanding_taxes=winr[i].taxes; return(1); } return(0); }/* * long paytaxes(x) Function to pay taxes if any are due * * Enter with the amount (in gp) to pay on the taxes. * Returns amount actually paid. */long paytaxes(x) long x; { register int i; register long amt; if (x<0) return(0L); if (readboard()<0) return(0L); for (i=0; i<SCORESIZE; i++) if (winr[i].suid == userid) /* look for players winning entry */ if (winr[i].score>0) /* search for a winning entry for the player */ { amt = winr[i].taxes; if (x < amt) amt=x; /* don't overpay taxes (Ughhhhh) */ winr[i].taxes -= amt; outstanding_taxes -= amt; if (writeboard()<0) return(0); return(amt); } return(0L); /* couldn't find user on winning scoreboard */ }/* * winshou() Subroutine to print out the winning scoreboard * * Returns the number of players on scoreboard that were shown */winshou() { register struct wscofmt *p; register int i,j,count; for (count=j=i=0; i<SCORESIZE; i++) /* is there anyone on the scoreboard? */ if (winr[i].score != 0) { j++; break; } if (j) { lprcat("\n Score Difficulty Time Needed Larn Winners List\n"); for (i=0; i<SCORESIZE; i++) /* this loop is needed to print out the */ for (j=0; j<SCORESIZE; j++) /* winners in order */ { p = &winr[j]; /* pointer to the scoreboard entry */ if (p->order == i) { if (p->score) { count++; lprintf("%10d %2d %5d Mobuls %s \n", (long)p->score,(long)p->hardlev,(long)p->timeused,p->who); } break; } } } return(count); /* return number of people on scoreboard */ }/* * shou(x) Subroutine to print out the non-winners scoreboard * int x; * * Enter with 0 to list the scores, enter with 1 to list inventories too * Returns the number of players on scoreboard that were shown */shou(x) int x; { register int i,j,n,k; int count; for (count=j=i=0; i<SCORESIZE; i++) /* is the scoreboard empty? */ if (sco[i].score!= 0) { j++; break; } if (j) { lprcat("\n Score Difficulty Larn Visitor Log\n"); for (i=0; i<SCORESIZE; i++) /* be sure to print them out in order */ for (j=0; j<SCORESIZE; j++) if (sco[j].order == i) { if (sco[j].score) { count++; lprintf("%10d %2d %s ", (long)sco[j].score,(long)sco[j].hardlev,sco[j].who); if (sco[j].what < 256) lprintf("killed by a %s",monster[sco[j].what].name); else lprintf("%s",whydead[sco[j].what - 256]); if (x != 263) lprintf(" on %s",levelname[sco[j].level]); if (x) { for (n=0; n<26; n++) { iven[n]=sco[j].sciv[n][0]; ivenarg[n]=sco[j].sciv[n][1]; } for (k=1; k<99; k++) for (n=0; n<26; n++) if (k==iven[n]) { srcount=0; show3(n); } lprcat("\n\n"); } else lprc('\n'); } j=SCORESIZE; } } return(count); /* return the number of players just shown */ }/* * showscores() Function to show the scoreboard on the terminal * * Returns nothing of value */static char esb[] = "The scoreboard is empty.\n";showscores() { register int i,j; lflush(); lcreat((char*)0); if (readboard()<0) return; i=winshou(); j=shou(0); if (i+j == 0) lprcat(esb); else lprc('\n'); lflush(); }/* * showallscores() Function to show scores and the iven lists that go with them * * Returns nothing of value */showallscores() { register int i,j; lflush(); lcreat((char*)0); if (readboard()<0) return; c[WEAR] = c[WIELD] = c[SHIELD] = -1; /* not wielding or wearing anything */ for (i=0; i<MAXPOTION; i++) potionname[i][0]=' '; for (i=0; i<MAXSCROLL; i++) scrollname[i][0]=' '; i=winshou(); j=shou(1); if (i+j==0) lprcat(esb); else lprc('\n'); lflush(); }/* * sortboard() Function to sort the scoreboard * * Returns 0 if no sorting done, else returns 1 */sortboard() { register int i,j,pos; long jdat; for (i=0; i<SCORESIZE; i++) sco[i].order = winr[i].order = -1; pos=0; while (pos < SCORESIZE) { jdat=0; for (i=0; i<SCORESIZE; i++) if ((sco[i].order < 0) && (sco[i].score >= jdat)) { j=i; jdat=sco[i].score; } sco[j].order = pos++; } pos=0; while (pos < SCORESIZE) { jdat=0; for (i=0; i<SCORESIZE; i++) if ((winr[i].order < 0) && (winr[i].score >= jdat)) { j=i; jdat=winr[i].score; } winr[j].order = pos++; } return(1); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -