xref: /csrg-svn/games/adventure/init.c (revision 37005)
16735Srrh #
26735Srrh /*      Re-coding of advent in C: data initialization                   */
36735Srrh 
4*37005Sbostic static char sccsid[] = "	init.c	4.2	89/03/05	";
56735Srrh 
6*37005Sbostic #include <sys/types.h>
7*37005Sbostic #include <stdio.h>
8*37005Sbostic #include "hdr.h"
9*37005Sbostic #include "pathnames.h"
106735Srrh 
116735Srrh int blklin = TRUE;
126735Srrh int setup  = 0;
136735Srrh 
146735Srrh int setbit[16] = {1,2,4,010,020,040,0100,0200,0400,01000,02000,04000,
156735Srrh 		  010000,020000,040000,0100000};
166735Srrh 
176735Srrh 
186735Srrh init(command)                           /* everything for 1st time run  */
196735Srrh char *command;                          /* command we were called with  */
206735Srrh {       int stat,adfd;
216735Srrh 	rdata();                        /* read data from orig. file    */
226735Srrh 	linkdata();
236735Srrh 	poof();
246735Srrh 	setup=1;                        /* indicate that data is in     */
25*37005Sbostic 	if (save(command, "adventure") < 0) {
26*37005Sbostic 		fprintf(stderr, "adventure: save failed\n");
27*37005Sbostic 		exit(1);
286735Srrh 	}
29*37005Sbostic 	adfd=open("adventure",1);
306735Srrh 	lseek(adfd,0L,2);
316735Srrh 	close(datfd);
32*37005Sbostic 	if (vfork() == 0) {
33*37005Sbostic 		dup2(adfd, 1);
34*37005Sbostic 		execl(_PATH_CAT, "cat", TMPFILE, 0);
35*37005Sbostic 		fprintf(stderr, "adventure: unable to find %s\n", _PATH_CAT);
36*37005Sbostic 		exit(1);
376735Srrh 	}
386735Srrh 	wait(&stat);
396735Srrh 	unlink(TMPFILE);
40*37005Sbostic 	exit(stat);
416735Srrh }
426735Srrh 
436735Srrh 
446735Srrh linkdata()                              /*  secondary data manipulation */
456735Srrh {       register int i,j;
466735Srrh 	/*      array linkages          */
476735Srrh 	for (i=1; i<=LOCSIZ; i++)
486735Srrh 		if (ltext[i].seekadr!=0 && travel[i] != 0)
496735Srrh 			if ((travel[i]->tverb)==1) cond[i]=2;
506735Srrh 	for (j=100; j>0; j--)
516735Srrh 		if (fixd[j]>0)
526735Srrh 		{       drop(j+100,fixd[j]);
536735Srrh 			drop(j,plac[j]);
546735Srrh 		}
556735Srrh 	for (j=100; j>0; j--)
566735Srrh 	{       fixed[j]=fixd[j];
576735Srrh 		if (plac[j]!=0 && fixd[j]<=0) drop(j,plac[j]);
586735Srrh 	}
596735Srrh 
606735Srrh 	maxtrs=79;
616735Srrh 	tally=0;
626735Srrh 	tally2=0;
636735Srrh 
646735Srrh 	for (i=50; i<=maxtrs; i++)
656735Srrh 	{       if (ptext[i].seekadr!=0) prop[i] = -1;
666735Srrh 		tally -= prop[i];
676735Srrh 	}
686735Srrh 
696735Srrh 	/* define mnemonics */
706735Srrh 	keys=vocab("keys",1);
716735Srrh 	lamp=vocab("lamp",1);
726735Srrh 	grate=vocab("grate",1);
736735Srrh 	cage=vocab("cage",1);
746735Srrh 	rod=vocab("rod",1);
756735Srrh 	rod2=rod+1;
766735Srrh 	steps=vocab("steps",1);
776735Srrh 	bird=vocab("bird",1);
786735Srrh 	door=vocab("door",1);
796735Srrh 	pillow=vocab("pillow",1);
806735Srrh 	snake=vocab("snake",1);
816735Srrh 	fissur=vocab("fissu",1);
826735Srrh 	tablet=vocab("table",1);
836735Srrh 	clam=vocab("clam",1);
846735Srrh 	oyster=vocab("oyster",1);
856735Srrh 	magzin=vocab("magaz",1);
866735Srrh 	dwarf=vocab("dwarf",1);
876735Srrh 	knife=vocab("knife",1);
886735Srrh 	food=vocab("food",1);
896735Srrh 	bottle=vocab("bottl",1);
906735Srrh 	water=vocab("water",1);
916735Srrh 	oil=vocab("oil",1);
926735Srrh 	plant=vocab("plant",1);
936735Srrh 	plant2=plant+1;
946735Srrh 	axe=vocab("axe",1);
956735Srrh 	mirror=vocab("mirro",1);
966735Srrh 	dragon=vocab("drago",1);
976735Srrh 	chasm=vocab("chasm",1);
986735Srrh 	troll=vocab("troll",1);
996735Srrh 	troll2=troll+1;
1006735Srrh 	bear=vocab("bear",1);
1016735Srrh 	messag=vocab("messa",1);
1026735Srrh 	vend=vocab("vendi",1);
1036735Srrh 	batter=vocab("batte",1);
1046735Srrh 
1056735Srrh 	nugget=vocab("gold",1);
1066735Srrh 	coins=vocab("coins",1);
1076735Srrh 	chest=vocab("chest",1);
1086735Srrh 	eggs=vocab("eggs",1);
1096735Srrh 	tridnt=vocab("tride",1);
1106735Srrh 	vase=vocab("vase",1);
1116735Srrh 	emrald=vocab("emera",1);
1126735Srrh 	pyram=vocab("pyram",1);
1136735Srrh 	pearl=vocab("pearl",1);
1146735Srrh 	rug=vocab("rug",1);
1156735Srrh 	chain=vocab("chain",1);
1166735Srrh 
1176735Srrh 	back=vocab("back",0);
1186735Srrh 	look=vocab("look",0);
1196735Srrh 	cave=vocab("cave",0);
1206735Srrh 	null=vocab("null",0);
1216735Srrh 	entrnc=vocab("entra",0);
1226735Srrh 	dprssn=vocab("depre",0);
1236735Srrh 
1246735Srrh 	say=vocab("say",2);
1256735Srrh 	lock=vocab("lock",2);
1266735Srrh 	throw=vocab("throw",2);
1276735Srrh 	find=vocab("find",2);
1286735Srrh 	invent=vocab("inven",2);
1296735Srrh 	/* initialize dwarves */
1306735Srrh 	chloc=114;
1316735Srrh 	chloc2=140;
1326735Srrh 	for (i=1; i<=6; i++)
1336735Srrh 		dseen[i]=FALSE;
1346735Srrh 	dflag=0;
1356735Srrh 	dloc[1]=19;
1366735Srrh 	dloc[2]=27;
1376735Srrh 	dloc[3]=33;
1386735Srrh 	dloc[4]=44;
1396735Srrh 	dloc[5]=64;
1406735Srrh 	dloc[6]=chloc;
1416735Srrh 	daltlc=18;
1426735Srrh 
1436735Srrh 	/* random flags & ctrs */
1446735Srrh 	turns=0;
1456735Srrh 	lmwarn=FALSE;
1466735Srrh 	iwest=0;
1476735Srrh 	knfloc=0;
1486735Srrh 	detail=0;
1496735Srrh 	abbnum=5;
1506735Srrh 	for (i=0; i<=4; i++)
1516735Srrh 		if (rtext[2*i+81].seekadr!=0) maxdie=i+1;
1526735Srrh 	numdie=holdng=dkill=foobar=bonus=0;
1536735Srrh 	clock1=30;
1546735Srrh 	clock2=50;
1556735Srrh 	saved=0;
1566735Srrh 	closng=panic=closed=scorng=FALSE;
1576735Srrh }
1586735Srrh 
1596735Srrh 
1606735Srrh 
1616735Srrh trapdel()                               /* come here if he hits a del   */
1626735Srrh {	delhit++;			/* main checks, treats as QUIT  */
1636735Srrh 	signal(2,trapdel);		/* catch subsequent DELs        */
1646735Srrh }
1656735Srrh 
1666735Srrh 
1676735Srrh startup()
168*37005Sbostic {
169*37005Sbostic 	time_t time();
170*37005Sbostic 
1716735Srrh 	demo=start(0);
172*37005Sbostic 	srand((int)(time((time_t *)NULL)));	/* random seed */
173*37005Sbostic 	/* srand(371);				/* non-random seed */
1746735Srrh 	hinted[3]=yes(65,1,0);
1756735Srrh 	newloc=1;
1766735Srrh 	setup=3;
1776735Srrh 	limit=330;
1786735Srrh 	if (hinted[3]) limit=1000;      /* better batteries if instrucs */
1796735Srrh }
1806735Srrh 
181