]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/diag.c
52daf12176625653bb8bee26979ff774a929ff8b
1 /* diag.c Larn is copyrighted 1986 by Noah Morgan. */
6 extern long int initialtime
;
7 extern int rmst
,maxitm
,lasttime
;
9 static struct tms cputime
;
11 ***************************
12 DIAG -- dungeon diagnostics
13 ***************************
15 subroutine to print out data for debugging
18 static int rndcount
[16];
24 if (lcreat(diagfile
) < 0) /* open the diagnostic file */
26 lcreat((char*)0); lprcat("\ndiagnostic failure\n"); return(-1);
29 write(1,"\nDiagnosing . . .\n",18);
30 lprcat("\n\nBeginning of DIAG diagnostics ----------\n");
32 /* for the character attributes */
34 lprintf("\n\nPlayer attributes:\n\nHit points: %2d(%2d)",(long)c
[HP
],(long)c
[HPMAX
]);
35 lprintf("\ngold: %d Experience: %d Character level: %d Level in caverns: %d",
36 (long)c
[GOLD
],(long)c
[EXPERIENCE
],(long)c
[LEVEL
],(long)level
);
37 lprintf("\nTotal types of monsters: %d",(long)MAXMONST
+8);
39 lprcat("\f\nHere's the dungeon:\n\n");
42 for (j
=0; j
<MAXLEVEL
+MAXVLEVEL
; j
++)
45 lprintf("\nMaze for level %s:\n",levelname
[level
]);
50 lprcat("\f\nNow for the monster data:\n\n");
51 lprcat(" Monster Name LEV AC DAM ATT DEF GOLD HP EXP \n");
52 lprcat("--------------------------------------------------------------------------\n");
53 for (i
=0; i
<=MAXMONST
+8; i
++)
55 lprintf("%19s %2d %3d ",monster
[i
].name
,(long)monster
[i
].level
,(long)monster
[i
].armorclass
);
56 lprintf(" %3d %3d %3d ",(long)monster
[i
].damage
,(long)monster
[i
].attack
,(long)monster
[i
].defense
);
57 lprintf("%6d %3d %6d\n",(long)monster
[i
].gold
,(long)monster
[i
].hitpoints
,(long)monster
[i
].experience
);
60 lprcat("\n\nHere's a Table for the to hit percentages\n");
61 lprcat("\n We will be assuming that players level = 2 * monster level");
62 lprcat("\n and that the players dexterity and strength are 16.");
63 lprcat("\n to hit: if (rnd(22) < (2[monst AC] + your level + dex + WC/8 -1)/2) then hit");
64 lprcat("\n damage = rund(8) + WC/2 + STR - c[HARDGAME] - 4");
65 lprcat("\n to hit: if rnd(22) < to hit then player hits\n");
66 lprcat("\n Each entry is as follows: to hit / damage / number hits to kill\n");
67 lprcat("\n monster WC = 4 WC = 20 WC = 40");
68 lprcat("\n---------------------------------------------------------------");
69 for (i
=0; i
<=MAXMONST
+8; i
++)
71 hit
= 2*monster
[i
].armorclass
+2*monster
[i
].level
+16;
72 dam
= 16 - c
[HARDGAME
];
73 lprintf("\n%20s %2d/%2d/%2d %2d/%2d/%2d %2d/%2d/%2d",
75 (long)(hit
/2),(long)max(0,dam
+2),(long)(monster
[i
].hitpoints
/(dam
+2)+1),
76 (long)((hit
+2)/2),(long)max(0,dam
+10),(long)(monster
[i
].hitpoints
/(dam
+10)+1),
77 (long)((hit
+5)/2),(long)max(0,dam
+20),(long)(monster
[i
].hitpoints
/(dam
+20)+1));
80 lprcat("\n\nHere's the list of available potions:\n\n");
81 for (i
=0; i
<MAXPOTION
; i
++) lprintf("%20s\n",&potionname
[i
][1]);
82 lprcat("\n\nHere's the list of available scrolls:\n\n");
83 for (i
=0; i
<MAXSCROLL
; i
++) lprintf("%20s\n",&scrollname
[i
][1]);
84 lprcat("\n\nHere's the spell list:\n\n");
85 lprcat("spell name description\n");
86 lprcat("-------------------------------------------------------------------------------------------\n\n");
87 for (j
=0; j
<SPNUM
; j
++)
89 lprc(' '); lprcat(spelcode
[j
]);
90 lprintf(" %21s %s\n",spelname
[j
],speldescript
[j
]);
93 lprcat("\n\nFor the c[] array:\n");
94 for (j
=0; j
<100; j
+=10)
96 lprintf("\nc[%2d] = ",(long)j
); for (i
=0; i
<9; i
++) lprintf("%5d ",(long)c
[i
+j
]);
99 lprcat("\n\nTest of random number generator ----------------");
100 lprcat("\n for 25,000 calls divided into 16 slots\n\n");
102 for (i
=0; i
<16; i
++) rndcount
[i
]=0;
103 for (i
=0; i
<25000; i
++) rndcount
[rund(16)]++;
104 for (i
=0; i
<16; i
++) { lprintf(" %5d",(long)rndcount
[i
]); if (i
==7) lprc('\n'); }
106 lprcat("\n\n"); lwclose();
107 lcreat((char*)0); lprcat("Done Diagnosing . . .");
111 subroutine to count the number of occurrences of an object
119 for (i
=0; i
<MAXX
; i
++)
120 for (j
=0; j
<MAXY
; j
++)
121 for (p
=0; p
<MAXLEVEL
; p
++)
122 if (cell
[p
*MAXX
*MAXY
+i
*MAXY
+j
].item
== l
) k
++;
127 subroutine to draw the whole screen as the player knows it
133 for (i
=0; i
<MAXY
; i
++)
135 /* for the east west walls of this line */
137 for (j
=0; j
<MAXX
; j
++) if (k
=mitem
[j
][i
]) lprc(monstnamelist
[k
]); else
138 lprc(objnamelist
[item
[j
][i
]]);
145 to save the game in a file
147 static long int zzz
=0;
152 register struct sphere
*sp
;
154 nosignal
=1; lflush(); savelevel();
156 if (lcreat(fname
) < 0)
158 lcreat((char*)0); lprintf("\nCan't open file <%s> to save game\n",fname
);
159 nosignal
=0; return(-1);
163 lwrite((char*)beenhere
,MAXLEVEL
+MAXVLEVEL
);
164 for (k
=0; k
<MAXLEVEL
+MAXVLEVEL
; k
++)
166 lwrite((char*)&cell
[k
*MAXX
*MAXY
],sizeof(struct cel
)*MAXY
*MAXX
);
167 times(&cputime
); /* get cpu time */
168 c
[CPUTIME
] += (cputime
.tms_utime
+cputime
.tms_stime
)/60;
169 lwrite((char*)&c
[0],100*sizeof(long));
170 lprint((long)gtime
); lprc(level
);
171 lprc(playerx
); lprc(playery
);
172 lwrite((char*)iven
,26); lwrite((char*)ivenarg
,26*sizeof(short));
173 for (k
=0; k
<MAXSCROLL
; k
++) lprc(scrollname
[k
][0]);
174 for (k
=0; k
<MAXPOTION
; k
++) lprc(potionname
[k
][0]);
175 lwrite((char*)spelknow
,SPNUM
); lprc(wizard
);
176 lprc(rmst
); /* random monster generation counter */
177 for (i
=0; i
<90; i
++) lprc(itm
[i
].qty
);
178 lwrite((char*)course
,25); lprc(cheat
); lprc(VERSION
);
179 for (i
=0; i
<MAXMONST
; i
++) lprc(monster
[i
].genocided
); /* genocide info */
180 for (sp
=spheres
; sp
; sp
=sp
->p
)
181 lwrite((char*)sp
,sizeof(struct sphere
)); /* save spheres of annihilation */
182 time(&zzz
); lprint((long)(zzz
-initialtime
));
183 lwrite((char*)&zzz
,sizeof(long));
184 if (fstat(lfd
,&statbuf
)< 0) lprint(0L);
185 else lprint((long)statbuf
.st_ino
); /* inode # */
186 lwclose(); lastmonst
[0] = 0;
190 lcreat((char*)0); nosignal
=0;
198 register struct sphere
*sp
,*sp2
;
199 struct stat filetimes
;
200 cursors(); lprcat("\nRestoring . . ."); lflush();
201 if (lopen(fname
) <= 0)
203 lcreat((char*)0); lprintf("\nCan't open file <%s>to restore game\n",fname
);
204 nap(2000); c
[GOLD
]=c
[BANKACCOUNT
]=0; died(-265); return;
207 lrfill((char*)beenhere
,MAXLEVEL
+MAXVLEVEL
);
208 for (k
=0; k
<MAXLEVEL
+MAXVLEVEL
; k
++)
210 lrfill((char*)&cell
[k
*MAXX
*MAXY
],sizeof(struct cel
)*MAXY
*MAXX
);
212 lrfill((char*)&c
[0],100*sizeof(long)); gtime
= lrint();
213 level
= c
[CAVELEVEL
] = lgetc();
214 playerx
= lgetc(); playery
= lgetc();
215 lrfill((char*)iven
,26); lrfill((char*)ivenarg
,26*sizeof(short));
216 for (k
=0; k
<MAXSCROLL
; k
++) scrollname
[k
] = lgetc() ? scrollhide
[k
] : "";
217 for (k
=0; k
<MAXPOTION
; k
++) potionname
[k
] = lgetc() ? potionhide
[k
] : "";
218 lrfill((char*)spelknow
,SPNUM
); wizard
= lgetc();
219 rmst
= lgetc(); /* random monster creation flag */
221 for (i
=0; i
<90; i
++) itm
[i
].qty
= lgetc();
222 lrfill((char*)course
,25); cheat
= lgetc();
223 if (VERSION
!= lgetc()) /* version number */
226 lprcat("Sorry, But your save file is for an older version of larn\n");
227 nap(2000); c
[GOLD
]=c
[BANKACCOUNT
]=0; died(-266); return;
230 for (i
=0; i
<MAXMONST
; i
++) monster
[i
].genocided
=lgetc(); /* genocide info */
231 for (sp
=0,i
=0; i
<c
[SPHCAST
]; i
++)
234 sp
= (struct sphere
*)malloc(sizeof(struct sphere
));
235 if (sp
==0) { write(2,"Can't malloc() for sphere space\n",32); break; }
236 lrfill((char*)sp
,sizeof(struct sphere
)); /* get spheres of annihilation */
237 sp
->p
=0; /* null out pointer */
238 if (i
==0) spheres
=sp
; /* beginning of list */
243 initialtime
= zzz
-lrint();
244 fstat(fd
,&filetimes
); /* get the creation and modification time of file */
245 lrfill((char*)&zzz
,sizeof(long)); zzz
+= 6;
246 if (filetimes
.st_ctime
> zzz
) fsorry(); /* file create time */
247 else if (filetimes
.st_mtime
> zzz
) fsorry(); /* file modify time */
248 if (c
[HP
]<0) { died(284); return; } /* died a post mortem death */
251 i
= lrint(); /* inode # */
252 if (i
&& (filetimes
.st_ino
!=i
)) fsorry();
254 if (strcmp(fname
,ckpfile
) == 0)
256 if (lappend(fname
) < 0) fcheat(); else { lprc(' '); lwclose(); }
259 else if (unlink(fname
) < 0) fcheat(); /* can't unlink save file */
260 /* for the greedy cheater checker */
261 for (k
=0; k
<6; k
++) if (c
[k
]>99) greedy();
262 if (c
[HPMAX
]>999 || c
[SPELLMAX
]>125) greedy();
263 if (c
[LEVEL
]==25 && c
[EXPERIENCE
]>skill
[24]) /* if patch up lev 25 player */
266 tmp
= c
[EXPERIENCE
]-skill
[24]; /* amount to go up */
267 c
[EXPERIENCE
] = skill
[24];
268 raiseexperience((long)tmp
);
270 getlevel(); lasttime
=gtime
;
274 subroutine to not allow greedy cheaters
282 lprcat("\n\nI am so sorry, but your character is a little TOO good! Since this\n");
283 lprcat("cannot normally happen from an honest game, I must assume that you cheated.\n");
284 lprcat("In that you are GREEDY as well as a CHEATER, I cannot allow this game\n");
285 lprcat("to continue.\n"); nap(5000); c
[GOLD
]=c
[BANKACCOUNT
]=0; died(-267); return;
289 subroutine to not allow altered save files and terminate the attempted
294 lprcat("\nSorry, but your savefile has been altered.\n");
295 lprcat("However, seeing as I am a good sport, I will let you play.\n");
296 lprcat("Be advised though, you won't be placed on the normal scoreboard.");
297 cheat
= 1; nap(4000);
301 subroutine to not allow game if save file can't be deleted
309 lprcat("\nSorry, but your savefile can't be deleted. This can only mean\n");
310 lprcat("that you tried to CHEAT by protecting the directory the savefile\n");
311 lprcat("is in. Since this is unfair to the rest of the larn community, I\n");
312 lprcat("cannot let you play this game.\n");
313 nap(5000); c
[GOLD
]=c
[BANKACCOUNT
]=0; died(-268); return;