xref: /original-bsd/games/adventure/init.c (revision a1c2194a)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * The game adventure was original written Fortran by Will Crowther
6  * and Don Woods.  It was later translated to C and enhanced by
7  * Jim Gillogly.
8  *
9  * %sccs.include.redist.c%
10  */
11 
12 #ifndef lint
13 static char sccsid[] = "@(#)init.c	5.1 (Berkeley) 04/08/91";
14 #endif /* not lint */
15 
16 /*      Re-coding of advent in C: data initialization                   */
17 
18 #include <sys/types.h>
19 #include <stdio.h>
20 #include "hdr.h"
21 #include "pathnames.h"
22 
23 int blklin = TRUE;
24 int setup  = 0;
25 
26 int setbit[16] = {1,2,4,010,020,040,0100,0200,0400,01000,02000,04000,
27 		  010000,020000,040000,0100000};
28 
29 
30 init(command)                           /* everything for 1st time run  */
31 char *command;                          /* command we were called with  */
32 {       int stat,adfd;
33 	rdata();                        /* read data from orig. file    */
34 	linkdata();
35 	poof();
36 	setup=1;                        /* indicate that data is in     */
37 	if (save(command, "adventure") < 0) {
38 		fprintf(stderr, "adventure: save failed\n");
39 		exit(1);
40 	}
41 	adfd=open("adventure",1);
42 	lseek(adfd,0L,2);
43 	close(datfd);
44 	if (vfork() == 0) {
45 		dup2(adfd, 1);
46 		execl(_PATH_CAT, "cat", TMPFILE, 0);
47 		fprintf(stderr, "adventure: unable to find %s\n", _PATH_CAT);
48 		exit(1);
49 	}
50 	wait(&stat);
51 	unlink(TMPFILE);
52 	exit(stat);
53 }
54 
55 
56 linkdata()                              /*  secondary data manipulation */
57 {       register int i,j;
58 	/*      array linkages          */
59 	for (i=1; i<=LOCSIZ; i++)
60 		if (ltext[i].seekadr!=0 && travel[i] != 0)
61 			if ((travel[i]->tverb)==1) cond[i]=2;
62 	for (j=100; j>0; j--)
63 		if (fixd[j]>0)
64 		{       drop(j+100,fixd[j]);
65 			drop(j,plac[j]);
66 		}
67 	for (j=100; j>0; j--)
68 	{       fixed[j]=fixd[j];
69 		if (plac[j]!=0 && fixd[j]<=0) drop(j,plac[j]);
70 	}
71 
72 	maxtrs=79;
73 	tally=0;
74 	tally2=0;
75 
76 	for (i=50; i<=maxtrs; i++)
77 	{       if (ptext[i].seekadr!=0) prop[i] = -1;
78 		tally -= prop[i];
79 	}
80 
81 	/* define mnemonics */
82 	keys=vocab("keys",1);
83 	lamp=vocab("lamp",1);
84 	grate=vocab("grate",1);
85 	cage=vocab("cage",1);
86 	rod=vocab("rod",1);
87 	rod2=rod+1;
88 	steps=vocab("steps",1);
89 	bird=vocab("bird",1);
90 	door=vocab("door",1);
91 	pillow=vocab("pillow",1);
92 	snake=vocab("snake",1);
93 	fissur=vocab("fissu",1);
94 	tablet=vocab("table",1);
95 	clam=vocab("clam",1);
96 	oyster=vocab("oyster",1);
97 	magzin=vocab("magaz",1);
98 	dwarf=vocab("dwarf",1);
99 	knife=vocab("knife",1);
100 	food=vocab("food",1);
101 	bottle=vocab("bottl",1);
102 	water=vocab("water",1);
103 	oil=vocab("oil",1);
104 	plant=vocab("plant",1);
105 	plant2=plant+1;
106 	axe=vocab("axe",1);
107 	mirror=vocab("mirro",1);
108 	dragon=vocab("drago",1);
109 	chasm=vocab("chasm",1);
110 	troll=vocab("troll",1);
111 	troll2=troll+1;
112 	bear=vocab("bear",1);
113 	messag=vocab("messa",1);
114 	vend=vocab("vendi",1);
115 	batter=vocab("batte",1);
116 
117 	nugget=vocab("gold",1);
118 	coins=vocab("coins",1);
119 	chest=vocab("chest",1);
120 	eggs=vocab("eggs",1);
121 	tridnt=vocab("tride",1);
122 	vase=vocab("vase",1);
123 	emrald=vocab("emera",1);
124 	pyram=vocab("pyram",1);
125 	pearl=vocab("pearl",1);
126 	rug=vocab("rug",1);
127 	chain=vocab("chain",1);
128 
129 	back=vocab("back",0);
130 	look=vocab("look",0);
131 	cave=vocab("cave",0);
132 	null=vocab("null",0);
133 	entrnc=vocab("entra",0);
134 	dprssn=vocab("depre",0);
135 
136 	say=vocab("say",2);
137 	lock=vocab("lock",2);
138 	throw=vocab("throw",2);
139 	find=vocab("find",2);
140 	invent=vocab("inven",2);
141 	/* initialize dwarves */
142 	chloc=114;
143 	chloc2=140;
144 	for (i=1; i<=6; i++)
145 		dseen[i]=FALSE;
146 	dflag=0;
147 	dloc[1]=19;
148 	dloc[2]=27;
149 	dloc[3]=33;
150 	dloc[4]=44;
151 	dloc[5]=64;
152 	dloc[6]=chloc;
153 	daltlc=18;
154 
155 	/* random flags & ctrs */
156 	turns=0;
157 	lmwarn=FALSE;
158 	iwest=0;
159 	knfloc=0;
160 	detail=0;
161 	abbnum=5;
162 	for (i=0; i<=4; i++)
163 		if (rtext[2*i+81].seekadr!=0) maxdie=i+1;
164 	numdie=holdng=dkill=foobar=bonus=0;
165 	clock1=30;
166 	clock2=50;
167 	saved=0;
168 	closng=panic=closed=scorng=FALSE;
169 }
170 
171 
172 
173 trapdel()                               /* come here if he hits a del   */
174 {	delhit++;			/* main checks, treats as QUIT  */
175 	signal(2,trapdel);		/* catch subsequent DELs        */
176 }
177 
178 
179 startup()
180 {
181 	time_t time();
182 
183 	demo=start(0);
184 	srand((int)(time((time_t *)NULL)));	/* random seed */
185 	/* srand(371);				/* non-random seed */
186 	hinted[3]=yes(65,1,0);
187 	newloc=1;
188 	setup=3;
189 	limit=330;
190 	if (hinted[3]) limit=1000;      /* better batteries if instrucs */
191 }
192 
193