]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/diag.c
2 static char rcsid
[] = "$NetBSD: diag.c,v 1.6 1995/04/24 12:23:49 cgd Exp $";
5 /* diag.c Larn is copyrighted 1986 by Noah Morgan. */
10 extern long int initialtime
;
11 extern int rmst
,maxitm
,lasttime
;
13 static struct tms cputime
;
15 ***************************
16 DIAG -- dungeon diagnostics
17 ***************************
19 subroutine to print out data for debugging
22 static int rndcount
[16];
28 if (lcreat(diagfile
) < 0) /* open the diagnostic file */
30 lcreat((char*)0); lprcat("\ndiagnostic failure\n"); return(-1);
33 write(1,"\nDiagnosing . . .\n",18);
34 lprcat("\n\nBeginning of DIAG diagnostics ----------\n");
36 /* for the character attributes */
38 lprintf("\n\nPlayer attributes:\n\nHit points: %2d(%2d)",(long)c
[HP
],(long)c
[HPMAX
]);
39 lprintf("\ngold: %d Experience: %d Character level: %d Level in caverns: %d",
40 (long)c
[GOLD
],(long)c
[EXPERIENCE
],(long)c
[LEVEL
],(long)level
);
41 lprintf("\nTotal types of monsters: %d",(long)MAXMONST
+8);
43 lprcat("\f\nHere's the dungeon:\n\n");
46 for (j
=0; j
<MAXLEVEL
+MAXVLEVEL
; j
++)
49 lprintf("\nMaze for level %s:\n",levelname
[level
]);
54 lprcat("\f\nNow for the monster data:\n\n");
55 lprcat(" Monster Name LEV AC DAM ATT DEF GOLD HP EXP \n");
56 lprcat("--------------------------------------------------------------------------\n");
57 for (i
=0; i
<=MAXMONST
+8; i
++)
59 lprintf("%19s %2d %3d ",monster
[i
].name
,(long)monster
[i
].level
,(long)monster
[i
].armorclass
);
60 lprintf(" %3d %3d %3d ",(long)monster
[i
].damage
,(long)monster
[i
].attack
,(long)monster
[i
].defense
);
61 lprintf("%6d %3d %6d\n",(long)monster
[i
].gold
,(long)monster
[i
].hitpoints
,(long)monster
[i
].experience
);
64 lprcat("\n\nHere's a Table for the to hit percentages\n");
65 lprcat("\n We will be assuming that players level = 2 * monster level");
66 lprcat("\n and that the players dexterity and strength are 16.");
67 lprcat("\n to hit: if (rnd(22) < (2[monst AC] + your level + dex + WC/8 -1)/2) then hit");
68 lprcat("\n damage = rund(8) + WC/2 + STR - c[HARDGAME] - 4");
69 lprcat("\n to hit: if rnd(22) < to hit then player hits\n");
70 lprcat("\n Each entry is as follows: to hit / damage / number hits to kill\n");
71 lprcat("\n monster WC = 4 WC = 20 WC = 40");
72 lprcat("\n---------------------------------------------------------------");
73 for (i
=0; i
<=MAXMONST
+8; i
++)
75 hit
= 2*monster
[i
].armorclass
+2*monster
[i
].level
+16;
76 dam
= 16 - c
[HARDGAME
];
77 lprintf("\n%20s %2d/%2d/%2d %2d/%2d/%2d %2d/%2d/%2d",
79 (long)(hit
/2),(long)max(0,dam
+2),(long)(monster
[i
].hitpoints
/(dam
+2)+1),
80 (long)((hit
+2)/2),(long)max(0,dam
+10),(long)(monster
[i
].hitpoints
/(dam
+10)+1),
81 (long)((hit
+5)/2),(long)max(0,dam
+20),(long)(monster
[i
].hitpoints
/(dam
+20)+1));
84 lprcat("\n\nHere's the list of available potions:\n\n");
85 for (i
=0; i
<MAXPOTION
; i
++) lprintf("%20s\n",&potionhide
[i
][1]);
86 lprcat("\n\nHere's the list of available scrolls:\n\n");
87 for (i
=0; i
<MAXSCROLL
; i
++) lprintf("%20s\n",&scrollhide
[i
][1]);
88 lprcat("\n\nHere's the spell list:\n\n");
89 lprcat("spell name description\n");
90 lprcat("-------------------------------------------------------------------------------------------\n\n");
91 for (j
=0; j
<SPNUM
; j
++)
93 lprc(' '); lprcat(spelcode
[j
]);
94 lprintf(" %21s %s\n",spelname
[j
],speldescript
[j
]);
97 lprcat("\n\nFor the c[] array:\n");
98 for (j
=0; j
<100; j
+=10)
100 lprintf("\nc[%2d] = ",(long)j
); for (i
=0; i
<9; i
++) lprintf("%5d ",(long)c
[i
+j
]);
103 lprcat("\n\nTest of random number generator ----------------");
104 lprcat("\n for 25,000 calls divided into 16 slots\n\n");
106 for (i
=0; i
<16; i
++) rndcount
[i
]=0;
107 for (i
=0; i
<25000; i
++) rndcount
[rund(16)]++;
108 for (i
=0; i
<16; i
++) { lprintf(" %5d",(long)rndcount
[i
]); if (i
==7) lprc('\n'); }
110 lprcat("\n\n"); lwclose();
111 lcreat((char*)0); lprcat("Done Diagnosing . . .");
115 subroutine to count the number of occurrences of an object
123 for (i
=0; i
<MAXX
; i
++)
124 for (j
=0; j
<MAXY
; j
++)
125 for (p
=0; p
<MAXLEVEL
; p
++)
126 if (cell
[p
*MAXX
*MAXY
+i
*MAXY
+j
].item
== l
) k
++;
131 subroutine to draw the whole screen as the player knows it
137 for (i
=0; i
<MAXY
; i
++)
139 /* for the east west walls of this line */
141 for (j
=0; j
<MAXX
; j
++) if (k
=mitem
[j
][i
]) lprc(monstnamelist
[k
]); else
142 lprc(objnamelist
[item
[j
][i
]]);
149 to save the game in a file
156 register struct sphere
*sp
;
158 nosignal
=1; lflush(); savelevel();
160 if (lcreat(fname
) < 0)
162 lcreat((char*)0); lprintf("\nCan't open file <%s> to save game\n",fname
);
163 nosignal
=0; return(-1);
167 lwrite((char*)beenhere
,MAXLEVEL
+MAXVLEVEL
);
168 for (k
=0; k
<MAXLEVEL
+MAXVLEVEL
; k
++)
170 lwrite((char*)&cell
[k
*MAXX
*MAXY
],sizeof(struct cel
)*MAXY
*MAXX
);
171 times(&cputime
); /* get cpu time */
172 c
[CPUTIME
] += (cputime
.tms_utime
+cputime
.tms_stime
)/60;
173 lwrite((char*)&c
[0],100*sizeof(long));
174 lprint((long)gtime
); lprc(level
);
175 lprc(playerx
); lprc(playery
);
176 lwrite((char*)iven
,26); lwrite((char*)ivenarg
,26*sizeof(short));
177 for (k
=0; k
<MAXSCROLL
; k
++) lprc(scrollname
[k
][0]);
178 for (k
=0; k
<MAXPOTION
; k
++) lprc(potionname
[k
][0]);
179 lwrite((char*)spelknow
,SPNUM
); lprc(wizard
);
180 lprc(rmst
); /* random monster generation counter */
181 for (i
=0; i
<90; i
++) lprc(itm
[i
].qty
);
182 lwrite((char*)course
,25); lprc(cheat
); lprc(VERSION
);
183 for (i
=0; i
<MAXMONST
; i
++) lprc(monster
[i
].genocided
); /* genocide info */
184 for (sp
=spheres
; sp
; sp
=sp
->p
)
185 lwrite((char*)sp
,sizeof(struct sphere
)); /* save spheres of annihilation */
186 time(&zzz
); lprint((long)(zzz
-initialtime
));
187 lwrite((char*)&zzz
,sizeof(long));
188 if (fstat(lfd
,&statbuf
)< 0) lprint(0L);
189 else lprint((long)statbuf
.st_ino
); /* inode # */
190 lwclose(); lastmonst
[0] = 0;
194 lcreat((char*)0); nosignal
=0;
202 register struct sphere
*sp
,*sp2
;
203 struct stat filetimes
;
204 cursors(); lprcat("\nRestoring . . ."); lflush();
205 if (lopen(fname
) <= 0)
207 lcreat((char*)0); lprintf("\nCan't open file <%s>to restore game\n",fname
);
208 nap(2000); c
[GOLD
]=c
[BANKACCOUNT
]=0; died(-265); return;
211 lrfill((char*)beenhere
,MAXLEVEL
+MAXVLEVEL
);
212 for (k
=0; k
<MAXLEVEL
+MAXVLEVEL
; k
++)
214 lrfill((char*)&cell
[k
*MAXX
*MAXY
],sizeof(struct cel
)*MAXY
*MAXX
);
216 lrfill((char*)&c
[0],100*sizeof(long)); gtime
= lrint();
217 level
= c
[CAVELEVEL
] = lgetc();
218 playerx
= lgetc(); playery
= lgetc();
219 lrfill((char*)iven
,26); lrfill((char*)ivenarg
,26*sizeof(short));
220 for (k
=0; k
<MAXSCROLL
; k
++) scrollname
[k
] = lgetc() ? scrollhide
[k
] : "";
221 for (k
=0; k
<MAXPOTION
; k
++) potionname
[k
] = lgetc() ? potionhide
[k
] : "";
222 lrfill((char*)spelknow
,SPNUM
); wizard
= lgetc();
223 rmst
= lgetc(); /* random monster creation flag */
225 for (i
=0; i
<90; i
++) itm
[i
].qty
= lgetc();
226 lrfill((char*)course
,25); cheat
= lgetc();
227 if (VERSION
!= lgetc()) /* version number */
230 lprcat("Sorry, But your save file is for an older version of larn\n");
231 nap(2000); c
[GOLD
]=c
[BANKACCOUNT
]=0; died(-266); return;
234 for (i
=0; i
<MAXMONST
; i
++) monster
[i
].genocided
=lgetc(); /* genocide info */
235 for (sp
=0,i
=0; i
<c
[SPHCAST
]; i
++)
238 sp
= (struct sphere
*)malloc(sizeof(struct sphere
));
239 if (sp
==0) { write(2,"Can't malloc() for sphere space\n",32); break; }
240 lrfill((char*)sp
,sizeof(struct sphere
)); /* get spheres of annihilation */
241 sp
->p
=0; /* null out pointer */
242 if (i
==0) spheres
=sp
; /* beginning of list */
247 initialtime
= zzz
-lrint();
248 fstat(fd
,&filetimes
); /* get the creation and modification time of file */
249 lrfill((char*)&zzz
,sizeof(long)); zzz
+= 6;
250 if (filetimes
.st_ctime
> zzz
) fsorry(); /* file create time */
251 else if (filetimes
.st_mtime
> zzz
) fsorry(); /* file modify time */
252 if (c
[HP
]<0) { died(284); return; } /* died a post mortem death */
255 i
= lrint(); /* inode # */
256 if (i
&& (filetimes
.st_ino
!=i
)) fsorry();
258 if (strcmp(fname
,ckpfile
) == 0)
260 if (lappend(fname
) < 0) fcheat(); else { lprc(' '); lwclose(); }
263 else if (unlink(fname
) < 0) fcheat(); /* can't unlink save file */
264 /* for the greedy cheater checker */
265 for (k
=0; k
<6; k
++) if (c
[k
]>99) greedy();
266 if (c
[HPMAX
]>999 || c
[SPELLMAX
]>125) greedy();
267 if (c
[LEVEL
]==25 && c
[EXPERIENCE
]>skill
[24]) /* if patch up lev 25 player */
270 tmp
= c
[EXPERIENCE
]-skill
[24]; /* amount to go up */
271 c
[EXPERIENCE
] = skill
[24];
272 raiseexperience((long)tmp
);
274 getlevel(); lasttime
=gtime
;
278 subroutine to not allow greedy cheaters
286 lprcat("\n\nI am so sorry, but your character is a little TOO good! Since this\n");
287 lprcat("cannot normally happen from an honest game, I must assume that you cheated.\n");
288 lprcat("In that you are GREEDY as well as a CHEATER, I cannot allow this game\n");
289 lprcat("to continue.\n"); nap(5000); c
[GOLD
]=c
[BANKACCOUNT
]=0; died(-267); return;
293 subroutine to not allow altered save files and terminate the attempted
298 lprcat("\nSorry, but your savefile has been altered.\n");
299 lprcat("However, seeing as I am a good sport, I will let you play.\n");
300 lprcat("Be advised though, you won't be placed on the normal scoreboard.");
301 cheat
= 1; nap(4000);
305 subroutine to not allow game if save file can't be deleted
313 lprcat("\nSorry, but your savefile can't be deleted. This can only mean\n");
314 lprcat("that you tried to CHEAT by protecting the directory the savefile\n");
315 lprcat("is in. Since this is unfair to the rest of the larn community, I\n");
316 lprcat("cannot let you play this game.\n");
317 nap(5000); c
[GOLD
]=c
[BANKACCOUNT
]=0; died(-268); return;