X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/be2e4143844eacde377f9efb27dcb1b55e6ecaf6..3a8de0fa374d25dd9b8c96c15a8ff130376b2e0a:/larn/diag.c diff --git a/larn/diag.c b/larn/diag.c index e069e609..a3482c1d 100644 --- a/larn/diag.c +++ b/larn/diag.c @@ -1,16 +1,26 @@ +/* $NetBSD: diag.c,v 1.13 2012/06/19 05:30:43 dholland Exp $ */ + +/* diag.c Larn is copyrighted 1986 by Noah Morgan. */ +#include #ifndef lint -static char rcsid[] = "$Id: diag.c,v 1.3 1993/08/02 17:19:58 mycroft Exp $"; -#endif /* not lint */ +__RCSID("$NetBSD: diag.c,v 1.13 2012/06/19 05:30:43 dholland Exp $"); +#endif /* not lint */ -/* diag.c Larn is copyrighted 1986 by Noah Morgan. */ #include #include #include +#include +#include +#include #include "header.h" -extern long int initialtime; -extern int rmst,maxitm,lasttime; -extern char nosignal; +#include "extern.h" + +static void greedy(void); +static void fsorry(void); +static void fcheat(void); + static struct tms cputime; + /* *************************** DIAG -- dungeon diagnostics @@ -19,47 +29,47 @@ static struct tms cputime; subroutine to print out data for debugging */ #ifdef EXTRA -static int rndcount[16]; +static int rndcount[16]; +void diag() - { - register int i,j; - int hit,dam; - cursors(); lwclose(); - if (lcreat(diagfile) < 0) /* open the diagnostic file */ - { - lcreat((char*)0); lprcat("\ndiagnostic failure\n"); return(-1); - } - - write(1,"\nDiagnosing . . .\n",18); +{ + int i, j; + int hit, dam; + cursors(); + lwclose(); + if (lcreat(diagfile) < 0) { /* open the diagnostic file */ + lcreat((char *) 0); + lprcat("\ndiagnostic failure\n"); + return (-1); + } + write(1, "\nDiagnosing . . .\n", 18); lprcat("\n\nBeginning of DIAG diagnostics ----------\n"); -/* for the character attributes */ + /* for the character attributes */ - lprintf("\n\nPlayer attributes:\n\nHit points: %2d(%2d)",(long)c[HP],(long)c[HPMAX]); - lprintf("\ngold: %d Experience: %d Character level: %d Level in caverns: %d", - (long)c[GOLD],(long)c[EXPERIENCE],(long)c[LEVEL],(long)level); - lprintf("\nTotal types of monsters: %d",(long)MAXMONST+8); + lprintf("\n\nPlayer attributes:\n\nHit points: %2ld(%2ld)", (long) c[HP], (long) c[HPMAX]); + lprintf("\ngold: %ld Experience: %ld Character level: %ld Level in caverns: %ld", + (long) c[GOLD], (long) c[EXPERIENCE], (long) c[LEVEL], (long) level); + lprintf("\nTotal types of monsters: %ld", (long) MAXMONST + 8); lprcat("\f\nHere's the dungeon:\n\n"); - i=level; - for (j=0; j to save game\n",fname); - nosignal=0; return(-1); - } +static time_t zzz = 0; +int +savegame(char *fname) +{ + int i, k; + struct sphere *sp; + struct stat statbuf; + nosignal = 1; + lflush(); + savelevel(); + ointerest(); + if (lcreat(fname) < 0) { + lcreat((char *) 0); + lprintf("\nCan't open file <%s> to save game\n", fname); + nosignal = 0; + return (-1); + } set_score_output(); - lwrite((char*)beenhere,MAXLEVEL+MAXVLEVEL); - for (k=0; kp) - lwrite((char*)sp,sizeof(struct sphere)); /* save spheres of annihilation */ - time(&zzz); lprint((long)(zzz-initialtime)); - lwrite((char*)&zzz,sizeof(long)); - if (fstat(lfd,&statbuf)< 0) lprint(0L); - else lprint((long)statbuf.st_ino); /* inode # */ - lwclose(); lastmonst[0] = 0; + c[CPUTIME] += (cputime.tms_utime + cputime.tms_stime) / 60; + lwrite((char *) &c[0], 100 * sizeof(long)); + lprint((long) gltime); + lprc(level); + lprc(playerx); + lprc(playery); + lwrite((char *) iven, 26); + lwrite((char *) ivenarg, 26 * sizeof(short)); + for (k = 0; k < MAXSCROLL; k++) + lprc(scrollname[k][0]); + for (k = 0; k < MAXPOTION; k++) + lprc(potionname[k][0]); + lwrite((char *) spelknow, SPNUM); + lprc(wizard); + lprc(rmst); /* random monster generation counter */ + for (i = 0; i < 90; i++) + lprc(itm[i].qty); + lwrite((char *) course, 25); + lprc(cheat); + lprc(VERSION); + for (i = 0; i < MAXMONST; i++) + lprc(monster[i].genocided); /* genocide info */ + for (sp = spheres; sp; sp = sp->p) + lwrite((char *) sp, sizeof(struct sphere)); /* save spheres of + * annihilation */ + time(&zzz); + lprint((long) (zzz - initialtime)); + lwrite((char *) &zzz, sizeof(long)); + if (fstat(io_outfd, &statbuf) < 0) + lprint(0L); + else + lprint((long) statbuf.st_ino); /* inode # */ + lwclose(); + lastmonst[0] = 0; #ifndef VT100 setscroll(); -#endif VT100 - lcreat((char*)0); nosignal=0; - return(0); - } - -restoregame(fname) - char *fname; - { - register int i,k; - register struct sphere *sp,*sp2; - struct stat filetimes; - cursors(); lprcat("\nRestoring . . ."); lflush(); - if (lopen(fname) <= 0) - { - lcreat((char*)0); lprintf("\nCan't open file <%s>to restore game\n",fname); - nap(2000); c[GOLD]=c[BANKACCOUNT]=0; died(-265); return; - } +#endif /* VT100 */ + lcreat((char *) 0); + nosignal = 0; + return (0); +} - lrfill((char*)beenhere,MAXLEVEL+MAXVLEVEL); - for (k=0; kto restore game\n", fname); + nap(2000); + c[GOLD] = c[BANKACCOUNT] = 0; + died(-265); + return; + } + lrfill((char *) beenhere, MAXLEVEL + MAXVLEVEL); + for (k = 0; k < MAXLEVEL + MAXVLEVEL; k++) if (beenhere[k]) - lrfill((char*)&cell[k*MAXX*MAXY],sizeof(struct cel)*MAXY*MAXX); + lrfill((char *) &cell[k * MAXX * MAXY], sizeof(struct cel) * MAXY * MAXX); - lrfill((char*)&c[0],100*sizeof(long)); gtime = lrint(); + lrfill((char *) &c[0], 100 * sizeof(long)); + gltime = larn_lrint(); level = c[CAVELEVEL] = lgetc(); - playerx = lgetc(); playery = lgetc(); - lrfill((char*)iven,26); lrfill((char*)ivenarg,26*sizeof(short)); - for (k=0; kp=0; /* null out pointer */ - if (i==0) spheres=sp; /* beginning of list */ - else sp2->p = sp; + sp = (struct sphere *) malloc(sizeof(struct sphere)); + if (sp == 0) { + write(2, "Can't malloc() for sphere space\n", 32); + break; } + lrfill((char *) sp, sizeof(struct sphere)); /* get spheres of + * annihilation */ + sp->p = 0; /* null out pointer */ + if (i == 0) + spheres = sp; /* beginning of list */ + else + sp2->p = sp; + } time(&zzz); - initialtime = zzz-lrint(); - fstat(fd,&filetimes); /* get the creation and modification time of file */ - lrfill((char*)&zzz,sizeof(long)); zzz += 6; - if (filetimes.st_ctime > zzz) fsorry(); /* file create time */ - else if (filetimes.st_mtime > zzz) fsorry(); /* file modify time */ - if (c[HP]<0) { died(284); return; } /* died a post mortem death */ - + initialtime = zzz - larn_lrint(); + /* get the creation and modification time of file */ + fstat(io_infd, &filetimes); + lrfill((char *) &zzz, sizeof(long)); + zzz += 6; + if (filetimes.st_ctime > zzz) + fsorry(); /* file create time */ + else if (filetimes.st_mtime > zzz) + fsorry(); /* file modify time */ + if (c[HP] < 0) { + died(284); + return; + } /* died a post mortem death */ oldx = oldy = 0; - i = lrint(); /* inode # */ - if (i && (filetimes.st_ino!=i)) fsorry(); + /* XXX the following will break on 64-bit inode numbers */ + i = larn_lrint(); /* inode # */ + if (i && (filetimes.st_ino != (ino_t) i)) + fsorry(); lrclose(); - if (strcmp(fname,ckpfile) == 0) - { - if (lappend(fname) < 0) fcheat(); else { lprc(' '); lwclose(); } - lcreat((char*)0); + if (strcmp(fname, ckpfile) == 0) { + if (lappend(fname) < 0) + fcheat(); + else { + lprc(' '); + lwclose(); } - else if (unlink(fname) < 0) fcheat(); /* can't unlink save file */ -/* for the greedy cheater checker */ - for (k=0; k<6; k++) if (c[k]>99) greedy(); - if (c[HPMAX]>999 || c[SPELLMAX]>125) greedy(); - if (c[LEVEL]==25 && c[EXPERIENCE]>skill[24]) /* if patch up lev 25 player */ - { - long tmp; - tmp = c[EXPERIENCE]-skill[24]; /* amount to go up */ + lcreat((char *) 0); + } else if (unlink(fname) < 0) + fcheat(); /* can't unlink save file */ + /* for the greedy cheater checker */ + for (k = 0; k < 6; k++) + if (c[k] > 99) + greedy(); + if (c[HPMAX] > 999 || c[SPELLMAX] > 125) + greedy(); + if (c[LEVEL] == 25 && c[EXPERIENCE] > skill[24]) { /* if patch up lev 25 + * player */ + long tmp; + tmp = c[EXPERIENCE] - skill[24]; /* amount to go up */ c[EXPERIENCE] = skill[24]; - raiseexperience((long)tmp); - } - getlevel(); lasttime=gtime; + raiseexperience((long) tmp); } + getlevel(); + lasttime = gltime; +} /* subroutine to not allow greedy cheaters */ -greedy() - { +static void +greedy(void) +{ #if WIZID - if (wizard) return; + if (wizard) + return; #endif lprcat("\n\nI am so sorry, but your character is a little TOO good! Since this\n"); lprcat("cannot normally happen from an honest game, I must assume that you cheated.\n"); lprcat("In that you are GREEDY as well as a CHEATER, I cannot allow this game\n"); - lprcat("to continue.\n"); nap(5000); c[GOLD]=c[BANKACCOUNT]=0; died(-267); return; - } + lprcat("to continue.\n"); + nap(5000); + c[GOLD] = c[BANKACCOUNT] = 0; + died(-267); + return; +} /* subroutine to not allow altered save files and terminate the attempted restart */ -fsorry() - { +static void +fsorry(void) +{ lprcat("\nSorry, but your savefile has been altered.\n"); lprcat("However, seeing as I am a good sport, I will let you play.\n"); lprcat("Be advised though, you won't be placed on the normal scoreboard."); - cheat = 1; nap(4000); - } + cheat = 1; + nap(4000); +} /* subroutine to not allow game if save file can't be deleted */ -fcheat() - { +static void +fcheat(void) +{ #if WIZID - if (wizard) return; + if (wizard) + return; #endif lprcat("\nSorry, but your savefile can't be deleted. This can only mean\n"); lprcat("that you tried to CHEAT by protecting the directory the savefile\n"); lprcat("is in. Since this is unfair to the rest of the larn community, I\n"); lprcat("cannot let you play this game.\n"); - nap(5000); c[GOLD]=c[BANKACCOUNT]=0; died(-268); return; - } + nap(5000); + c[GOLD] = c[BANKACCOUNT] = 0; + died(-268); + return; +}