DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T d

⟦b967b647c⟧ TextFile

    Length: 12096 (0x2f40)
    Types: TextFile
    Names: »diag.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Ularn/diag.c« 

TextFile

/*	diag.c	*/
#include "header.h"

extern long int initialtime;
extern int rmst,maxitm,lasttime;
extern char nosignal;

char *cdef[] = {
	"STRENGTH", "INTELLIGENCE", "WISDOM", "CONSTITUTION", "DEXTERITY",
	"CHARISMA", "HPMAX", "HP", "GOLD", "EXPERIENCE",
	"LEVEL", "REGEN", "WCLASS", "AC", "BANKACCOUNT",
	"SPELLMAX", "SPELLS", "ENERGY", "ECOUNTER", "MOREDEFENSES",
	"WEAR", "PROTECTIONTIME", "WIELD", "AMULET", "REGENCOUNTER",
	"MOREDAM", "DEXCOUNT", "STRCOUNT", "BLINDCOUNT", "CAVELEVEL",
	"CONFUSE", "ALTPRO", "HERO", "CHARMCOUNT", "INVISIBILITY",
	"CANCELLATION", "HASTESELF", "EYEOFLARN", "AGGRAVATE ", "GLOBE",
	"TELEFLAG", "SLAYING", "NEGATESPIRIT", "SCAREMONST ", "AWARENESS",
	"HOLDMONST", "TIMESTOP", "HASTEMONST", "CUBEofUNDEAD", "GIANTSTR",
	"FIRERESISTANCE", "BESSMANN", "NOTHEFT", "HARDGAME", "",
	"", "", "", "", "",
	"LANCEDEATH", "SPIRITPRO", "UNDEADPRO", "SHIELD ", "STEALTH",
	"ITCHING", "LAUGHING", "DRAINSTRENGTH", "CLUMSINESS", "INFEEBLEMENT",
	"HALFDAM", "SEEINVISIBLE", "FILLROOM", "", "SPHCAST",
	"WTW", "STREXTRA", "TMP", "LIFEPROT", "ORB",
	"ELVUP", "ELVDOWN", "HAND", "CUBEUNDEAD", "DRAGSLAY", 
	"NEGATE", "URN", "LAMP", "TALISMAN", "WAND", 
	"STAFF", "DEVICE", "SLASH", "ELVEN", "VORP", 
	"SLAY", "PAD", "COKED", "", "" };

char *ivendef[] = {
	"",
	"OALTAR", "OTHRONE", "OORB", "OPIT", "OSTAIRSUP",
	"OELEVATORUP", "OFOUNTAIN", "OSTATUE", "OTELEPORTER", "OSCHOOL",
	"OMIRROR", "ODNDSTORE", "OSTAIRSDOWN", "OELEVATORDOWN", "OBANK2",
	"OBANK", "ODEADFOUNTAIN", "OGOLDPILE", "OOPENDOOR", "OCLOSEDDOOR",
	"OWALL", "OTRAPARROW", "OTRAPARROWIV", "OLARNEYE", "OPLATE",
	"OCHAIN", "OLEATHER", "ORING", "OSTUDLEATHER", "OSPLINT",
	"OPLATEARMOR", "OSSPLATE", "OSHIELD", "OSWORDofSLASHING", "OHAMMER",
	"OSWORD", "O2SWORD", "OSPEAR", "ODAGGER", "OBATTLEAXE",
	"OLONGSWORD", "OFLAIL", "OLANCE", "ORINGOFEXTRA", "OREGENRING",
	"OPROTRING", "OENERGYRING", "ODEXRING", "OSTRRING", "OCLEVERRING",
	"ODAMRING", "OBELT", "OSCROLL", "OPOTION", "OBOOK",
	"OCHEST", "OAMULET", "OORBOFDRAGON", "OSPIRITSCARAB", "OCUBEofUNDEAD",
	"ONOTHEFT", "ODIAMOND", "ORUBY", "OEMERALD", "OSAPPHIRE",
	"OENTRANCE", "OVOLDOWN", "OVOLUP", "OHOME", "OMAXGOLD",
	"OKGOLD", "ODGOLD", "OIVDARTRAP", "ODARTRAP", "OTRAPDOOR",
	"OIVTRAPDOOR", "OTRADEPOST", "OIVTELETRAP", "ODEADTHRONE", "OANNIHILATION",
	"OTHRONE2", "OLRS", "OCOOKIE", "OURN", "OBRASSLAMP",
	"OHANDofFEAR", "OSPHTALISMAN", "OWWAND", "OPSTAFF", "OVORPAL",
	"OSLAYER", "OELVENCHAIN", "OSPEED", "OACID", "OHASH",
	"OSHROOMS", "OCOKE", "OPAD", "" };


/*
	***************************
	DIAG -- dungeon diagnostics
	***************************

	print out data for debugging
 */

FILE *dfile;

diag()
{
	register int	i, j;

	if ((dfile = fopen(diagfile, "w")) == NULL) {
		return(0);
	}
	lprcat("\nDiagnosing . . .\n");
	lflush();

	fprintf(dfile,"\n-------- Beginning of DIAG diagnostics ---------\n\n");

	fprintf(dfile, "Hit points: %2ld(%2ld)\n", c[HP], c[HPMAX]);

	fprintf(dfile, "gold: %ld  Experience: %ld  Character level: %d  Level in caverns: %ld\n",
	(long) c[GOLD],
	(long) c[EXPERIENCE],
	(long) c[LEVEL],
	level);

	fprintf(dfile, "\nFor the c[] array:\n");
	fflush(dfile);

	for( j=0; j<100; j++)
		fprintf(dfile, "c[%d]\t%-20s\t= %ld\n", j, cdef[j], c[j]);
	fprintf(dfile, "\n\n");
	fflush(dfile);

	fprintf(dfile, "Inventory\n");
	for (j=0; j<26; j++) {
		fprintf (dfile, "iven[%d] %-12s = %d", 
		j, ivendef[iven[j]], iven[j] );
		fprintf (dfile, "\t%s", objectname[iven[j]] );
		fprintf (dfile, "\t+ %d\n", ivenarg[j] );
	}

	fprintf(dfile, "\nHere are the maps:\n\n");
	monstnamelist[DEMONLORD] = '1';
	monstnamelist[DEMONLORD+1] = '2';
	monstnamelist[DEMONLORD+2] = '3';
	monstnamelist[DEMONLORD+3] = '4';
	monstnamelist[DEMONLORD+4] = '5';
	monstnamelist[DEMONLORD+5] = '6';
	monstnamelist[DEMONLORD+6] = '7';
	monstnamelist[DEMONPRINCE] = '9';
	monstnamelist[LUCIFER] = '0';
	i = level;
	for (j = 0; j <= MAXLEVEL+MAXVLEVEL-1; j++) {
		newcavelevel(j);
		fprintf(dfile, "\n-------------------------------------------------------------------\n");
		fprintf(dfile, "Map %s    level %d\n", 
		levelname[level], level);
		fprintf(dfile, "-------------------------------------------------------------------\n");
		diagdrawscreen();
		fflush(dfile);
	}
	level = i;
	getlevel();

	fprintf(dfile, "\n\nNow for the monster data:\n\n");
	fprintf(dfile, "\nTotal types of monsters: %d\n\n", MAXMONST + 8);
	fprintf(dfile, "   Monster Name      LEV  AC   DAM  ATT  DEF    GOLD   HP     EXP\n");
	fprintf(dfile, "-----------------------------------------------------------------\n");
	fflush(dfile);

	for (i = 0; i <= MAXMONST + 8; i++) {
		fprintf(dfile, "%19s  %2d  %3d ", 
		monster[i].name, 
		monster[i].level, 
		monster[i].armorclass);
		fprintf(dfile, " %3d  %3d  %3d  ", 
		monster[i].damage, 
		monster[i].attack, 
		monster[i].defense);
		fprintf(dfile, "%6d  %3d   %6ld\n", 
		monster[i].gold, 
		monster[i].hitpoints,
		(long) monster[i].experience);
		fflush(dfile);
	}

	fprintf(dfile, "\nAvailable potions:\n\n");
	for (i = 0; i < MAXPOTION; i++)
		fprintf(dfile, "%20s\n", &potionname[i][1]);
	fflush(dfile);

	fprintf(dfile, "\nAvailable scrolls:\n\n");
	for (i = 0; i < MAXSCROLL; i++)
		fprintf(dfile, "%20s\n", &scrollname[i][1]);
	fflush(dfile);

	fprintf(dfile, "\nSpell list:\n\n");
	fprintf(dfile, "spell#  name           description\n");
	fprintf(dfile, "-------------------------------------------------\n\n");

	for (j = 0; j < SPNUM; j++) {
		fprintf(dfile, "%-10s", spelcode[j]);
		fprintf(dfile," %21s\n", spelname[j]);
		fprintf(dfile,"%s\n", speldescript[j]);
	}
	fflush(dfile);

	fprintf(dfile, "\nObject list\n\n");
	fprintf(dfile, "\nj \tObject \tName\n");
	fprintf(dfile, "---------------------------------\n");
	for (j = 0; j < MAXOBJ; j++)
		fprintf(dfile, "%d \t%c \t%s\n",
		j,
		objnamelist[j],
		objectname[j] );
	fflush(dfile);

	fprintf(dfile,"\n-------- End of DIAG diagnostics ---------\n");
	fflush(dfile);
	fclose(dfile);

	lprcat("\nDone Diagnosing.\n");
	lflush();
	return(0);
}


/*
	draw the whole screen
 */
diagdrawscreen()
{
	register int	i, j, k;

	/* east west walls of this line	*/
	for (i = 0; i < MAXY; i++) {			
		for (j = 0; j < MAXX; j++)
			if (k = mitem[j][i])
				fprintf(dfile, "%c", monstnamelist[k]);
			else
				fprintf(dfile, "%c", objnamelist[item[j][i]]);
		fprintf(dfile, "\n");
	}
}
/*
	to save the game in a file
 */
static long int zzz=0;
savegame(fname)
char *fname;
{
	register int i,k;
	register 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; k<MAXLEVEL+MAXVLEVEL; k++)
		if (beenhere[k])
			lwrite((char*)&cell[k*MAXX*MAXY],sizeof(struct cel)*MAXY*MAXX);
	lwrite((char*)&c[0],100*sizeof(long));
	lprint((long)gtime);		
	lprc(level);
	lprc(playerx);		
	lprc(playery);
	lwrite((char*)iven,26);	
	lwrite((char*)ivenarg,26*sizeof(short));
	lwrite((char*)char_class,20);	
	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);		

	/* genocide info */
	for (i=0; i<MAXMONST; i++) lprc(monster[i].genocided);

	/* save spheres of annihilation */
	for (sp=spheres; sp; sp=sp->p)
		lwrite((char*)sp,sizeof(struct sphere));	

	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;
	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;
	}

	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*)&c[0],100*sizeof(long));	
	gtime = lrint();
	level = c[CAVELEVEL] = lgetc();

	playerx = lgetc();		
	playery = lgetc();

	lrfill((char*)iven,26);
	lrfill((char*)ivenarg,26*sizeof(short));
	lrfill((char*)char_class,20);		

	for (k=0; k<MAXSCROLL; k++)  scrollname[k][0] = lgetc();
	for (k=0; k<MAXPOTION; k++)  potionname[k][0] = lgetc();

	lrfill((char*)spelknow,SPNUM);		

	wizard = lgetc();
	rmst = lgetc();			/*	random monster creation flag */

	for (i=0; i<90; i++)	
		itm[i].qty = lgetc();

	lrfill((char*)course,25);			
	cheat = lgetc();

	/* genocide info */
	for (i=0; i<MAXMONST; i++) monster[i].genocided=lgetc(); 

	for (sp=0,i=0; i<c[SPHCAST]; i++) {
		sp2 = sp;
		sp = (struct sphere *)malloc(sizeof(struct sphere));
		if (sp==0) { 
			fprintf(stderr, "Can't malloc() for sphere space\n"); 
			break; 
		}
		/* get spheres of annihilation */
		lrfill((char*)sp,sizeof(struct sphere));	
		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 */

	oldx = oldy = 0;

	i = lrint();  /* inode # */
	if (i && (filetimes.st_ino!=i)) 
		fsorry();	/* different inode number, file was copied */

	lrclose();

	if (strcmp(fname,ckpfile) == 0) {
		if (lappend(fname) < 0) 
			fcheat();  
		else { 
			lprc(' '); 
			lwclose(); 
		}
		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]) {
		long tmp = c[EXPERIENCE]-skill[24]; /* amount to go up */
		c[EXPERIENCE] = skill[24];
		raiseexperience((long)tmp);
	}
	getlevel();  
	lasttime=gtime;

	for (k=0; k<26; k++) 
		if (iven[k] == OLARNEYE) {
			monstnamelist[DEMONLORD] = '1';
			monstnamelist[DEMONLORD+1] = '2';
			monstnamelist[DEMONLORD+2] = '3';
			monstnamelist[DEMONLORD+3] = '4';
			monstnamelist[DEMONLORD+4] = '5';
			monstnamelist[DEMONLORD+5] = '6';
			monstnamelist[DEMONLORD+6] = '7';
			monstnamelist[DEMONPRINCE] = '9';
			monstnamelist[LUCIFER] = '0';
			break;
		}
}

/*
	subroutine to not allow greedy cheaters
 */
greedy()
{
	if (wizard) return;

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;
}

/*
	subroutine to not allow altered save files and terminate the attempted
	restart
 */
fsorry()
{
	if(cheat) return;
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 scoreboard.");
	cheat = 1;	
	nap(4000);
}

/*
	subroutine to not allow game if save file can't be deleted
 */
fcheat()
{
	if (wizard) return;
	if(cheat) return;

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 Ularn community, I\n");
lprcat("cannot let you play this game.\n");
	nap(5000);  
	c[GOLD]=c[BANKACCOUNT]=0;  
	died(-268); 
	return;
}