]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/diag.c
1 /* $NetBSD: diag.c,v 1.8 1997/10/18 20:03:12 christos Exp $ */
3 /* diag.c Larn is copyrighted 1986 by Noah Morgan. */
6 __RCSID("$NetBSD: diag.c,v 1.8 1997/10/18 20:03:12 christos Exp $");
10 #include <sys/times.h>
16 static struct tms cputime
;
18 ***************************
19 DIAG -- dungeon diagnostics
20 ***************************
22 subroutine to print out data for debugging
25 static int rndcount
[16];
33 if (lcreat(diagfile
) < 0) { /* open the diagnostic file */
35 lprcat("\ndiagnostic failure\n");
38 write(1, "\nDiagnosing . . .\n", 18);
39 lprcat("\n\nBeginning of DIAG diagnostics ----------\n");
41 /* for the character attributes */
43 lprintf("\n\nPlayer attributes:\n\nHit points: %2d(%2d)", (long) c
[HP
], (long) c
[HPMAX
]);
44 lprintf("\ngold: %d Experience: %d Character level: %d Level in caverns: %d",
45 (long) c
[GOLD
], (long) c
[EXPERIENCE
], (long) c
[LEVEL
], (long) level
);
46 lprintf("\nTotal types of monsters: %d", (long) MAXMONST
+ 8);
48 lprcat("\f\nHere's the dungeon:\n\n");
51 for (j
= 0; j
< MAXLEVEL
+ MAXVLEVEL
; j
++) {
53 lprintf("\nMaze for level %s:\n", levelname
[level
]);
58 lprcat("\f\nNow for the monster data:\n\n");
59 lprcat(" Monster Name LEV AC DAM ATT DEF GOLD HP EXP \n");
60 lprcat("--------------------------------------------------------------------------\n");
61 for (i
= 0; i
<= MAXMONST
+ 8; i
++) {
62 lprintf("%19s %2d %3d ", monster
[i
].name
, (long) monster
[i
].level
, (long) monster
[i
].armorclass
);
63 lprintf(" %3d %3d %3d ", (long) monster
[i
].damage
, (long) monster
[i
].attack
, (long) monster
[i
].defense
);
64 lprintf("%6d %3d %6d\n", (long) monster
[i
].gold
, (long) monster
[i
].hitpoints
, (long) monster
[i
].experience
);
67 lprcat("\n\nHere's a Table for the to hit percentages\n");
68 lprcat("\n We will be assuming that players level = 2 * monster level");
69 lprcat("\n and that the players dexterity and strength are 16.");
70 lprcat("\n to hit: if (rnd(22) < (2[monst AC] + your level + dex + WC/8 -1)/2) then hit");
71 lprcat("\n damage = rund(8) + WC/2 + STR - c[HARDGAME] - 4");
72 lprcat("\n to hit: if rnd(22) < to hit then player hits\n");
73 lprcat("\n Each entry is as follows: to hit / damage / number hits to kill\n");
74 lprcat("\n monster WC = 4 WC = 20 WC = 40");
75 lprcat("\n---------------------------------------------------------------");
76 for (i
= 0; i
<= MAXMONST
+ 8; i
++) {
77 hit
= 2 * monster
[i
].armorclass
+ 2 * monster
[i
].level
+ 16;
78 dam
= 16 - c
[HARDGAME
];
79 lprintf("\n%20s %2d/%2d/%2d %2d/%2d/%2d %2d/%2d/%2d",
81 (long) (hit
/ 2), (long) max(0, dam
+ 2), (long) (monster
[i
].hitpoints
/ (dam
+ 2) + 1),
82 (long) ((hit
+ 2) / 2), (long) max(0, dam
+ 10), (long) (monster
[i
].hitpoints
/ (dam
+ 10) + 1),
83 (long) ((hit
+ 5) / 2), (long) max(0, dam
+ 20), (long) (monster
[i
].hitpoints
/ (dam
+ 20) + 1));
86 lprcat("\n\nHere's the list of available potions:\n\n");
87 for (i
= 0; i
< MAXPOTION
; i
++)
88 lprintf("%20s\n", &potionhide
[i
][1]);
89 lprcat("\n\nHere's the list of available scrolls:\n\n");
90 for (i
= 0; i
< MAXSCROLL
; i
++)
91 lprintf("%20s\n", &scrollhide
[i
][1]);
92 lprcat("\n\nHere's the spell list:\n\n");
93 lprcat("spell name description\n");
94 lprcat("-------------------------------------------------------------------------------------------\n\n");
95 for (j
= 0; j
< SPNUM
; j
++) {
98 lprintf(" %21s %s\n", spelname
[j
], speldescript
[j
]);
101 lprcat("\n\nFor the c[] array:\n");
102 for (j
= 0; j
< 100; j
+= 10) {
103 lprintf("\nc[%2d] = ", (long) j
);
104 for (i
= 0; i
< 9; i
++)
105 lprintf("%5d ", (long) c
[i
+ j
]);
108 lprcat("\n\nTest of random number generator ----------------");
109 lprcat("\n for 25,000 calls divided into 16 slots\n\n");
111 for (i
= 0; i
< 16; i
++)
113 for (i
= 0; i
< 25000; i
++)
114 rndcount
[rund(16)]++;
115 for (i
= 0; i
< 16; i
++) {
116 lprintf(" %5d", (long) rndcount
[i
]);
124 lprcat("Done Diagnosing . . .");
128 subroutine to count the number of occurrences of an object
137 for (i
= 0; i
< MAXX
; i
++)
138 for (j
= 0; j
< MAXY
; j
++)
139 for (p
= 0; p
< MAXLEVEL
; p
++)
140 if (cell
[p
* MAXX
* MAXY
+ i
* MAXY
+ j
].item
== l
)
146 subroutine to draw the whole screen as the player knows it
153 for (i
= 0; i
< MAXY
; i
++)
154 /* for the east west walls of this line */
156 for (j
= 0; j
< MAXX
; j
++)
158 lprc(monstnamelist
[k
]);
160 lprc(objnamelist
[item
[j
][i
]]);
168 to save the game in a file
170 static time_t zzz
= 0;
183 if (lcreat(fname
) < 0) {
185 lprintf("\nCan't open file <%s> to save game\n", fname
);
190 lwrite((char *) beenhere
, MAXLEVEL
+ MAXVLEVEL
);
191 for (k
= 0; k
< MAXLEVEL
+ MAXVLEVEL
; k
++)
193 lwrite((char *) &cell
[k
* MAXX
* MAXY
], sizeof(struct cel
) * MAXY
* MAXX
);
194 times(&cputime
); /* get cpu time */
195 c
[CPUTIME
] += (cputime
.tms_utime
+ cputime
.tms_stime
) / 60;
196 lwrite((char *) &c
[0], 100 * sizeof(long));
197 lprint((long) gltime
);
201 lwrite((char *) iven
, 26);
202 lwrite((char *) ivenarg
, 26 * sizeof(short));
203 for (k
= 0; k
< MAXSCROLL
; k
++)
204 lprc(scrollname
[k
][0]);
205 for (k
= 0; k
< MAXPOTION
; k
++)
206 lprc(potionname
[k
][0]);
207 lwrite((char *) spelknow
, SPNUM
);
209 lprc(rmst
); /* random monster generation counter */
210 for (i
= 0; i
< 90; i
++)
212 lwrite((char *) course
, 25);
215 for (i
= 0; i
< MAXMONST
; i
++)
216 lprc(monster
[i
].genocided
); /* genocide info */
217 for (sp
= spheres
; sp
; sp
= sp
->p
)
218 lwrite((char *) sp
, sizeof(struct sphere
)); /* save spheres of
221 lprint((long) (zzz
- initialtime
));
222 lwrite((char *) &zzz
, sizeof(long));
223 if (fstat(lfd
, &statbuf
) < 0)
226 lprint((long) statbuf
.st_ino
); /* inode # */
242 struct sphere
*sp
, *sp2
;
243 struct stat filetimes
;
245 lprcat("\nRestoring . . .");
247 if (lopen(fname
) <= 0) {
249 lprintf("\nCan't open file <%s>to restore game\n", fname
);
251 c
[GOLD
] = c
[BANKACCOUNT
] = 0;
255 lrfill((char *) beenhere
, MAXLEVEL
+ MAXVLEVEL
);
256 for (k
= 0; k
< MAXLEVEL
+ MAXVLEVEL
; k
++)
258 lrfill((char *) &cell
[k
* MAXX
* MAXY
], sizeof(struct cel
) * MAXY
* MAXX
);
260 lrfill((char *) &c
[0], 100 * sizeof(long));
262 level
= c
[CAVELEVEL
] = lgetc();
265 lrfill((char *) iven
, 26);
266 lrfill((char *) ivenarg
, 26 * sizeof(short));
267 for (k
= 0; k
< MAXSCROLL
; k
++)
268 scrollname
[k
] = lgetc() ? scrollhide
[k
] : "";
269 for (k
= 0; k
< MAXPOTION
; k
++)
270 potionname
[k
] = lgetc() ? potionhide
[k
] : "";
271 lrfill((char *) spelknow
, SPNUM
);
273 rmst
= lgetc(); /* random monster creation flag */
275 for (i
= 0; i
< 90; i
++)
276 itm
[i
].qty
= lgetc();
277 lrfill((char *) course
, 25);
279 if (VERSION
!= lgetc()) { /* version number */
281 lprcat("Sorry, But your save file is for an older version of larn\n");
283 c
[GOLD
] = c
[BANKACCOUNT
] = 0;
287 for (i
= 0; i
< MAXMONST
; i
++)
288 monster
[i
].genocided
= lgetc(); /* genocide info */
289 for (sp
= 0, i
= 0; i
< c
[SPHCAST
]; i
++) {
291 sp
= (struct sphere
*) malloc(sizeof(struct sphere
));
293 write(2, "Can't malloc() for sphere space\n", 32);
296 lrfill((char *) sp
, sizeof(struct sphere
)); /* get spheres of
298 sp
->p
= 0; /* null out pointer */
300 spheres
= sp
; /* beginning of list */
306 initialtime
= zzz
- lrint();
307 fstat(fd
, &filetimes
); /* get the creation and modification time of
309 lrfill((char *) &zzz
, sizeof(long));
311 if (filetimes
.st_ctime
> zzz
)
312 fsorry(); /* file create time */
313 else if (filetimes
.st_mtime
> zzz
)
314 fsorry(); /* file modify time */
318 } /* died a post mortem death */
320 i
= lrint(); /* inode # */
321 if (i
&& (filetimes
.st_ino
!= i
))
324 if (strcmp(fname
, ckpfile
) == 0) {
325 if (lappend(fname
) < 0)
332 } else if (unlink(fname
) < 0)
333 fcheat(); /* can't unlink save file */
334 /* for the greedy cheater checker */
335 for (k
= 0; k
< 6; k
++)
338 if (c
[HPMAX
] > 999 || c
[SPELLMAX
] > 125)
340 if (c
[LEVEL
] == 25 && c
[EXPERIENCE
] > skill
[24]) { /* if patch up lev 25
343 tmp
= c
[EXPERIENCE
] - skill
[24]; /* amount to go up */
344 c
[EXPERIENCE
] = skill
[24];
345 raiseexperience((long) tmp
);
352 subroutine to not allow greedy cheaters
362 lprcat("\n\nI am so sorry, but your character is a little TOO good! Since this\n");
363 lprcat("cannot normally happen from an honest game, I must assume that you cheated.\n");
364 lprcat("In that you are GREEDY as well as a CHEATER, I cannot allow this game\n");
365 lprcat("to continue.\n");
367 c
[GOLD
] = c
[BANKACCOUNT
] = 0;
373 subroutine to not allow altered save files and terminate the attempted
379 lprcat("\nSorry, but your savefile has been altered.\n");
380 lprcat("However, seeing as I am a good sport, I will let you play.\n");
381 lprcat("Be advised though, you won't be placed on the normal scoreboard.");
387 subroutine to not allow game if save file can't be deleted
397 lprcat("\nSorry, but your savefile can't be deleted. This can only mean\n");
398 lprcat("that you tried to CHEAT by protecting the directory the savefile\n");
399 lprcat("is in. Since this is unfair to the rest of the larn community, I\n");
400 lprcat("cannot let you play this game.\n");
402 c
[GOLD
] = c
[BANKACCOUNT
] = 0;