]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/diag.c
1 /* $NetBSD: diag.c,v 1.10 2006/05/11 10:23:24 mrg Exp $ */
3 /* diag.c Larn is copyrighted 1986 by Noah Morgan. */
6 __RCSID("$NetBSD: diag.c,v 1.10 2006/05/11 10:23:24 mrg Exp $");
10 #include <sys/times.h>
17 static struct tms cputime
;
19 ***************************
20 DIAG -- dungeon diagnostics
21 ***************************
23 subroutine to print out data for debugging
26 static int rndcount
[16];
34 if (lcreat(diagfile
) < 0) { /* open the diagnostic file */
36 lprcat("\ndiagnostic failure\n");
39 write(1, "\nDiagnosing . . .\n", 18);
40 lprcat("\n\nBeginning of DIAG diagnostics ----------\n");
42 /* for the character attributes */
44 lprintf("\n\nPlayer attributes:\n\nHit points: %2d(%2d)", (long) c
[HP
], (long) c
[HPMAX
]);
45 lprintf("\ngold: %d Experience: %d Character level: %d Level in caverns: %d",
46 (long) c
[GOLD
], (long) c
[EXPERIENCE
], (long) c
[LEVEL
], (long) level
);
47 lprintf("\nTotal types of monsters: %d", (long) MAXMONST
+ 8);
49 lprcat("\f\nHere's the dungeon:\n\n");
52 for (j
= 0; j
< MAXLEVEL
+ MAXVLEVEL
; j
++) {
54 lprintf("\nMaze for level %s:\n", levelname
[level
]);
59 lprcat("\f\nNow for the monster data:\n\n");
60 lprcat(" Monster Name LEV AC DAM ATT DEF GOLD HP EXP \n");
61 lprcat("--------------------------------------------------------------------------\n");
62 for (i
= 0; i
<= MAXMONST
+ 8; i
++) {
63 lprintf("%19s %2d %3d ", monster
[i
].name
, (long) monster
[i
].level
, (long) monster
[i
].armorclass
);
64 lprintf(" %3d %3d %3d ", (long) monster
[i
].damage
, (long) monster
[i
].attack
, (long) monster
[i
].defense
);
65 lprintf("%6d %3d %6d\n", (long) monster
[i
].gold
, (long) monster
[i
].hitpoints
, (long) monster
[i
].experience
);
68 lprcat("\n\nHere's a Table for the to hit percentages\n");
69 lprcat("\n We will be assuming that players level = 2 * monster level");
70 lprcat("\n and that the players dexterity and strength are 16.");
71 lprcat("\n to hit: if (rnd(22) < (2[monst AC] + your level + dex + WC/8 -1)/2) then hit");
72 lprcat("\n damage = rund(8) + WC/2 + STR - c[HARDGAME] - 4");
73 lprcat("\n to hit: if rnd(22) < to hit then player hits\n");
74 lprcat("\n Each entry is as follows: to hit / damage / number hits to kill\n");
75 lprcat("\n monster WC = 4 WC = 20 WC = 40");
76 lprcat("\n---------------------------------------------------------------");
77 for (i
= 0; i
<= MAXMONST
+ 8; i
++) {
78 hit
= 2 * monster
[i
].armorclass
+ 2 * monster
[i
].level
+ 16;
79 dam
= 16 - c
[HARDGAME
];
80 lprintf("\n%20s %2d/%2d/%2d %2d/%2d/%2d %2d/%2d/%2d",
82 (long) (hit
/ 2), (long) max(0, dam
+ 2), (long) (monster
[i
].hitpoints
/ (dam
+ 2) + 1),
83 (long) ((hit
+ 2) / 2), (long) max(0, dam
+ 10), (long) (monster
[i
].hitpoints
/ (dam
+ 10) + 1),
84 (long) ((hit
+ 5) / 2), (long) max(0, dam
+ 20), (long) (monster
[i
].hitpoints
/ (dam
+ 20) + 1));
87 lprcat("\n\nHere's the list of available potions:\n\n");
88 for (i
= 0; i
< MAXPOTION
; i
++)
89 lprintf("%20s\n", &potionhide
[i
][1]);
90 lprcat("\n\nHere's the list of available scrolls:\n\n");
91 for (i
= 0; i
< MAXSCROLL
; i
++)
92 lprintf("%20s\n", &scrollhide
[i
][1]);
93 lprcat("\n\nHere's the spell list:\n\n");
94 lprcat("spell name description\n");
95 lprcat("-------------------------------------------------------------------------------------------\n\n");
96 for (j
= 0; j
< SPNUM
; j
++) {
99 lprintf(" %21s %s\n", spelname
[j
], speldescript
[j
]);
102 lprcat("\n\nFor the c[] array:\n");
103 for (j
= 0; j
< 100; j
+= 10) {
104 lprintf("\nc[%2d] = ", (long) j
);
105 for (i
= 0; i
< 9; i
++)
106 lprintf("%5d ", (long) c
[i
+ j
]);
109 lprcat("\n\nTest of random number generator ----------------");
110 lprcat("\n for 25,000 calls divided into 16 slots\n\n");
112 for (i
= 0; i
< 16; i
++)
114 for (i
= 0; i
< 25000; i
++)
115 rndcount
[rund(16)]++;
116 for (i
= 0; i
< 16; i
++) {
117 lprintf(" %5d", (long) rndcount
[i
]);
125 lprcat("Done Diagnosing . . .");
129 subroutine to count the number of occurrences of an object
138 for (i
= 0; i
< MAXX
; i
++)
139 for (j
= 0; j
< MAXY
; j
++)
140 for (p
= 0; p
< MAXLEVEL
; p
++)
141 if (cell
[p
* MAXX
* MAXY
+ i
* MAXY
+ j
].item
== l
)
147 subroutine to draw the whole screen as the player knows it
154 for (i
= 0; i
< MAXY
; i
++)
155 /* for the east west walls of this line */
157 for (j
= 0; j
< MAXX
; j
++)
159 lprc(monstnamelist
[k
]);
161 lprc(objnamelist
[item
[j
][i
]]);
169 to save the game in a file
171 static time_t zzz
= 0;
184 if (lcreat(fname
) < 0) {
186 lprintf("\nCan't open file <%s> to save game\n", fname
);
191 lwrite((char *) beenhere
, MAXLEVEL
+ MAXVLEVEL
);
192 for (k
= 0; k
< MAXLEVEL
+ MAXVLEVEL
; k
++)
194 lwrite((char *) &cell
[k
* MAXX
* MAXY
], sizeof(struct cel
) * MAXY
* MAXX
);
195 times(&cputime
); /* get cpu time */
196 c
[CPUTIME
] += (cputime
.tms_utime
+ cputime
.tms_stime
) / 60;
197 lwrite((char *) &c
[0], 100 * sizeof(long));
198 lprint((long) gltime
);
202 lwrite((char *) iven
, 26);
203 lwrite((char *) ivenarg
, 26 * sizeof(short));
204 for (k
= 0; k
< MAXSCROLL
; k
++)
205 lprc(scrollname
[k
][0]);
206 for (k
= 0; k
< MAXPOTION
; k
++)
207 lprc(potionname
[k
][0]);
208 lwrite((char *) spelknow
, SPNUM
);
210 lprc(rmst
); /* random monster generation counter */
211 for (i
= 0; i
< 90; i
++)
213 lwrite((char *) course
, 25);
216 for (i
= 0; i
< MAXMONST
; i
++)
217 lprc(monster
[i
].genocided
); /* genocide info */
218 for (sp
= spheres
; sp
; sp
= sp
->p
)
219 lwrite((char *) sp
, sizeof(struct sphere
)); /* save spheres of
222 lprint((long) (zzz
- initialtime
));
223 lwrite((char *) &zzz
, sizeof(long));
224 if (fstat(lfd
, &statbuf
) < 0)
227 lprint((long) statbuf
.st_ino
); /* inode # */
243 struct sphere
*sp
, *sp2
;
244 struct stat filetimes
;
246 lprcat("\nRestoring . . .");
248 if (lopen(fname
) <= 0) {
250 lprintf("\nCan't open file <%s>to restore game\n", fname
);
252 c
[GOLD
] = c
[BANKACCOUNT
] = 0;
256 lrfill((char *) beenhere
, MAXLEVEL
+ MAXVLEVEL
);
257 for (k
= 0; k
< MAXLEVEL
+ MAXVLEVEL
; k
++)
259 lrfill((char *) &cell
[k
* MAXX
* MAXY
], sizeof(struct cel
) * MAXY
* MAXX
);
261 lrfill((char *) &c
[0], 100 * sizeof(long));
262 gltime
= larn_lrint();
263 level
= c
[CAVELEVEL
] = lgetc();
266 lrfill((char *) iven
, 26);
267 lrfill((char *) ivenarg
, 26 * sizeof(short));
268 for (k
= 0; k
< MAXSCROLL
; k
++)
269 scrollname
[k
] = lgetc() ? scrollhide
[k
] : "";
270 for (k
= 0; k
< MAXPOTION
; k
++)
271 potionname
[k
] = lgetc() ? potionhide
[k
] : "";
272 lrfill((char *) spelknow
, SPNUM
);
274 rmst
= lgetc(); /* random monster creation flag */
276 for (i
= 0; i
< 90; i
++)
277 itm
[i
].qty
= lgetc();
278 lrfill((char *) course
, 25);
280 if (VERSION
!= lgetc()) { /* version number */
282 lprcat("Sorry, But your save file is for an older version of larn\n");
284 c
[GOLD
] = c
[BANKACCOUNT
] = 0;
288 for (i
= 0; i
< MAXMONST
; i
++)
289 monster
[i
].genocided
= lgetc(); /* genocide info */
290 for (sp
= 0, i
= 0; i
< c
[SPHCAST
]; i
++) {
292 sp
= (struct sphere
*) malloc(sizeof(struct sphere
));
294 write(2, "Can't malloc() for sphere space\n", 32);
297 lrfill((char *) sp
, sizeof(struct sphere
)); /* get spheres of
299 sp
->p
= 0; /* null out pointer */
301 spheres
= sp
; /* beginning of list */
307 initialtime
= zzz
- larn_lrint();
308 fstat(fd
, &filetimes
); /* get the creation and modification time of
310 lrfill((char *) &zzz
, sizeof(long));
312 if (filetimes
.st_ctime
> zzz
)
313 fsorry(); /* file create time */
314 else if (filetimes
.st_mtime
> zzz
)
315 fsorry(); /* file modify time */
319 } /* died a post mortem death */
321 i
= larn_lrint(); /* inode # */
322 if (i
&& (filetimes
.st_ino
!= i
))
325 if (strcmp(fname
, ckpfile
) == 0) {
326 if (lappend(fname
) < 0)
333 } else if (unlink(fname
) < 0)
334 fcheat(); /* can't unlink save file */
335 /* for the greedy cheater checker */
336 for (k
= 0; k
< 6; k
++)
339 if (c
[HPMAX
] > 999 || c
[SPELLMAX
] > 125)
341 if (c
[LEVEL
] == 25 && c
[EXPERIENCE
] > skill
[24]) { /* if patch up lev 25
344 tmp
= c
[EXPERIENCE
] - skill
[24]; /* amount to go up */
345 c
[EXPERIENCE
] = skill
[24];
346 raiseexperience((long) tmp
);
353 subroutine to not allow greedy cheaters
363 lprcat("\n\nI am so sorry, but your character is a little TOO good! Since this\n");
364 lprcat("cannot normally happen from an honest game, I must assume that you cheated.\n");
365 lprcat("In that you are GREEDY as well as a CHEATER, I cannot allow this game\n");
366 lprcat("to continue.\n");
368 c
[GOLD
] = c
[BANKACCOUNT
] = 0;
374 subroutine to not allow altered save files and terminate the attempted
380 lprcat("\nSorry, but your savefile has been altered.\n");
381 lprcat("However, seeing as I am a good sport, I will let you play.\n");
382 lprcat("Be advised though, you won't be placed on the normal scoreboard.");
388 subroutine to not allow game if save file can't be deleted
398 lprcat("\nSorry, but your savefile can't be deleted. This can only mean\n");
399 lprcat("that you tried to CHEAT by protecting the directory the savefile\n");
400 lprcat("is in. Since this is unfair to the rest of the larn community, I\n");
401 lprcat("cannot let you play this game.\n");
403 c
[GOLD
] = c
[BANKACCOUNT
] = 0;