📄 scores.c
字号:
/* * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard * int score, winner, whyded; * char *whoo; * * Enter with the total score in gp in score, players name in whoo, * died() reason # in whyded, and TRUE/FALSE in winner if a winner * ex. newscore(1000, "player 1", 32, 0); */newscore(score, whoo, whyded, winner) long score; int winner, whyded; char *whoo; { register int i; long taxes; if (readboard() < 0) return; /* do the scoreboard */ /* if a winner then delete all non-winning scores */ if (cheat) winner=0; /* if he cheated, don't let him win */ if (winner) { for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid) sco[i].score=0; taxes = score*TAXRATE; score += 100000*c[HARDGAME]; /* bonus for winning */ /* if he has a slot on the winning scoreboard update it if greater score */ for (i=0; i<SCORESIZE; i++) if (winr[i].suid == userid) { new1sub(score,i,whoo,taxes); return; } /* he had no entry. look for last entry and see if he has a greater score */ for (i=0; i<SCORESIZE; i++) if (winr[i].order == SCORESIZE-1) { new1sub(score,i,whoo,taxes); return; } } else if (!cheat) /* for not winning scoreboard */ { /* if he has a slot on the scoreboard update it if greater score */ for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid) { new2sub(score,i,whoo,whyded); return; } /* he had no entry. look for last entry and see if he has a greater score */ for (i=0; i<SCORESIZE; i++) if (sco[i].order == SCORESIZE-1) { new2sub(score,i,whoo,whyded); return; } } }/* * new1sub(score,i,whoo,taxes) Subroutine to put player into a * int score,i,whyded,taxes; winning scoreboard entry if his score * char *whoo; is high enough * * Enter with the total score in gp in score, players name in whoo, * died() reason # in whyded, and TRUE/FALSE in winner if a winner * slot in scoreboard in i, and the tax bill in taxes. * Returns nothing of value */new1sub(score,i,whoo,taxes) long score,taxes; int i; char *whoo; { register struct wscofmt *p; p = &winr[i]; p->taxes += taxes; if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) { strcpy(p->who,whoo); p->score=score; p->hardlev=c[HARDGAME]; p->suid=userid; p->timeused=gtime/100; } }/* * new2sub(score,i,whoo,whyded) Subroutine to put player into a * int score,i,whyded,taxes; non-winning scoreboard entry if his * char *whoo; score is high enough * * Enter with the total score in gp in score, players name in whoo, * died() reason # in whyded, and slot in scoreboard in i. * Returns nothing of value */new2sub(score,i,whoo,whyded) long score; int i,whyded; char *whoo; { register int j; register struct scofmt *p; p = &sco[i]; if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) { strcpy(p->who,whoo); p->score=score; p->what=whyded; p->hardlev=c[HARDGAME]; p->suid=userid; p->level=level; for (j=0; j<26; j++) { p->sciv[j][0]=iven[j]; p->sciv[j][1]=ivenarg[j]; } } }/* * died(x) Subroutine to record who played larn, and what the score was * int x; * * if x < 0 then don't show scores * died() never returns! (unless c[LIFEPROT] and a reincarnatable death!) * * < 256 killed by the monster number * 256 quit * 257 suspended * 258 self - annihilated * 259 shot by an arrow * 260 hit by a dart * 261 fell into a pit * 262 fell into a bottomless pit * 263 a winner * 264 trapped in solid rock * 265 killed by a missing save file * 266 killed by an old save file * 267 caught by the greedy cheater checker trap * 268 killed by a protected save file * 269 killed his family and killed himself * 270 erased by a wayward finger * 271 fell through a bottomless trap door * 272 fell through a trap door * 273 drank some poisonous water * 274 fried by an electric shock * 275 slipped on a volcano shaft * 276 killed by a stupid act of frustration * 277 attacked by a revolting demon * 278 hit by his own magic * 279 demolished by an unseen attacker * 280 fell into the dreadful sleep * 281 killed by an exploding chest * 282 killed by a missing maze data file * 283 killed by a sphere of annihilation * 284 died a post mortem death * 285 malloc() failure * 300 quick quit -- don't put on scoreboard */static int scorerror;died(x) int x; { register int f,win; char ch,*mod; long zzz,i; struct tms cputime; if (c[LIFEPROT]>0) /* if life protection */ { switch((x>0) ? x : -x) { case 256: case 257: case 262: case 263: case 265: case 266: case 267: case 268: case 269: case 271: case 282: case 284: case 285: case 300: goto invalid; /* can't be saved */ }; --c[LIFEPROT]; c[HP]=1; --c[CONSTITUTION]; cursors(); lprcat("\nYou feel wiiieeeeerrrrrd all over! "); beep(); lflush(); sleep(4); return; /* only case where died() returns */ }invalid: clearvt100(); lflush(); f=0; if (ckpflag) unlink(ckpfile); /* remove checkpoint file if used */ if (x<0) { f++; x = -x; } /* if we are not to display the scores */ if ((x == 300) || (x == 257)) exit(); /* for quick exit or saved game */ if (x == 263) win = 1; else win = 0; c[GOLD] += c[BANKACCOUNT]; c[BANKACCOUNT] = 0; /* now enter the player at the end of the scoreboard */ newscore(c[GOLD], logname, x, win); diedsub(x); /* print out the score line */ lflush(); set_score_output(); if ((wizard == 0) && (c[GOLD] > 0)) /* wizards can't score */ {#ifndef NOLOG if (lappend(logfile)<0) /* append to file */ { if (lcreat(logfile)<0) /* and can't create new log file */ { lcreat((char*)0); lprcat("\nCan't open record file: I can't post your score.\n"); sncbr(); resetscroll(); lflush(); exit(); } chmod(logfile,0660); } strcpy(logg.who,loginname); logg.score = c[GOLD]; logg.diff = c[HARDGAME]; if (x < 256) { ch = *monster[x].name; if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') mod="an"; else mod="a"; sprintf(logg.what,"killed by %s %s",mod,monster[x].name); } else sprintf(logg.what,"%s",whydead[x - 256]); logg.cavelev=level; time(&zzz); /* get cpu time -- write out score info */ logg.diedtime=zzz;#ifdef EXTRA times(&cputime); /* get cpu time -- write out score info */ logg.cputime = i = (cputime.tms_utime + cputime.tms_stime)/60 + c[CPUTIME]; logg.lev=c[LEVEL]; logg.ac=c[AC]; logg.hpmax=c[HPMAX]; logg.hp=c[HP]; logg.elapsedtime=(zzz-initialtime+59)/60; logg.usage=(10000*i)/(zzz-initialtime); logg.bytin=c[BYTESIN]; logg.bytout=c[BYTESOUT]; logg.moves=c[MOVESMADE]; logg.spused=c[SPELLSCAST]; logg.killed=c[MONSTKILLED];#endif lwrite((char*)&logg,sizeof(struct log_fmt)); lwclose();#endif NOLOG/* now for the scoreboard maintenance -- not for a suspended game */ if (x != 257) { if (sortboard()) scorerror = writeboard(); } } if ((x==256) || (x==257) || (f != 0)) exit(); if (scorerror == 0) showscores(); /* if we updated the scoreboard */ if (x == 263) mailbill(); exit(); }/* * diedsub(x) Subroutine to print out the line showing the player when he is killed * int x; */diedsub(x)int x; { register char ch,*mod; lprintf("Score: %d, Diff: %d, %s ",(long)c[GOLD],(long)c[HARDGAME],logname); if (x < 256) { ch = *monster[x].name; if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') mod="an"; else mod="a"; lprintf("killed by %s %s",mod,monster[x].name); } else lprintf("%s",whydead[x - 256]); if (x != 263) lprintf(" on %s\n",levelname[level]); else lprc('\n'); }/* * diedlog() Subroutine to read a log file and print it out in ascii format */diedlog() { register int n; register char *p; struct stat stbuf; lcreat((char*)0); if (lopen(logfile)<0) { lprintf("Can't locate log file <%s>\n",logfile); return; } if (fstat(fd,&stbuf) < 0) { lprintf("Can't stat log file <%s>\n",logfile); return; } for (n=stbuf.st_size/sizeof(struct log_fmt); n>0; --n) { lrfill((char*)&logg,sizeof(struct log_fmt)); p = ctime(&logg.diedtime); p[16]='\n'; p[17]=0; lprintf("Score: %d, Diff: %d, %s %s on %d at %s",(long)(logg.score),(long)(logg.diff),logg.who,logg.what,(long)(logg.cavelev),p+4);#ifdef EXTRA if (logg.moves<=0) logg.moves=1; lprintf(" Experience Level: %d, AC: %d, HP: %d/%d, Elapsed Time: %d minutes\n",(long)(logg.lev),(long)(logg.ac),(long)(logg.hp),(long)(logg.hpmax),(long)(logg.elapsedtime)); lprintf(" CPU time used: %d seconds, Machine usage: %d.%02d%%\n",(long)(logg.cputime),(long)(logg.usage/100),(long)(logg.usage%100)); lprintf(" BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n",(long)(logg.bytin),(long)(logg.bytout),(long)(logg.moves),(long)(logg.killed),(long)(logg.spused)); lprintf(" out bytes per move: %d, time per move: %d ms\n",(long)(logg.bytout/logg.moves),(long)((logg.cputime*1000)/logg.moves));#endif } lflush(); lrclose(); return; }#ifndef UIDSCORE/* * getplid(name) Function to get players id # from id file * * Enter with the name of the players character in name. * Returns the id # of the players character, or -1 if failure. * This routine will try to find the name in the id file, if its not there, * it will try to make a new entry in the file. Only returns -1 if can't * find him in the file, and can't make a new entry in the file. * Format of playerids file: * Id # in ascii \n character name \n */static int havepid= -1; /* playerid # if previously done */getplid(nam) char *nam; { int fd7,high=999,no; register char *p,*p2; char name[80]; if (havepid != -1) return(havepid); /* already did it */ lflush(); /* flush any pending I/O */ sprintf(name,"%s\n",nam); /* append a \n to name */ if (lopen(playerids) < 0) /* no file, make it */ { if ((fd7=creat(playerids,0666)) < 0) return(-1); /* can't make it */ close(fd7); goto addone; /* now append new playerid record to file */ } for (;;) /* now search for the name in the player id file */ { p = lgetl(); if (p==NULL) break; /* EOF? */ no = atoi(p); /* the id # */ p2= lgetl(); if (p2==NULL) break; /* EOF? */ if (no>high) high=no; /* accumulate highest id # */ if (strcmp(p2,name)==0) /* we found him */ { return(no); /* his id number */ } } lrclose(); /* if we get here, we didn't find him in the file -- put him there */addone: if (lappend(playerids) < 0) return(-1); /* can't open file for append */ lprintf("%d\n%s",(long)++high,name); /* new id # and name */ lwclose(); lcreat((char*)0); /* re-open terminal channel */ return(high); }#endif UIDSCORE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -