Home | History | Annotate | Line # | Download | only in adventure
init.c revision 1.4
      1  1.4  mrg /*	$NetBSD: init.c,v 1.4 1996/05/21 21:53:05 mrg Exp $	*/
      2  1.2  cgd 
      3  1.1  jtc /*-
      4  1.1  jtc  * Copyright (c) 1993
      5  1.1  jtc  *	The Regents of the University of California.  All rights reserved.
      6  1.1  jtc  *
      7  1.1  jtc  * The game adventure was originally written in Fortran by Will Crowther
      8  1.1  jtc  * and Don Woods.  It was later translated to C and enhanced by Jim
      9  1.1  jtc  * Gillogly.  This code is derived from software contributed to Berkeley
     10  1.1  jtc  * by Jim Gillogly at The Rand Corporation.
     11  1.1  jtc  *
     12  1.1  jtc  * Redistribution and use in source and binary forms, with or without
     13  1.1  jtc  * modification, are permitted provided that the following conditions
     14  1.1  jtc  * are met:
     15  1.1  jtc  * 1. Redistributions of source code must retain the above copyright
     16  1.1  jtc  *    notice, this list of conditions and the following disclaimer.
     17  1.1  jtc  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.1  jtc  *    notice, this list of conditions and the following disclaimer in the
     19  1.1  jtc  *    documentation and/or other materials provided with the distribution.
     20  1.1  jtc  * 3. All advertising materials mentioning features or use of this software
     21  1.1  jtc  *    must display the following acknowledgement:
     22  1.1  jtc  *	This product includes software developed by the University of
     23  1.1  jtc  *	California, Berkeley and its contributors.
     24  1.1  jtc  * 4. Neither the name of the University nor the names of its contributors
     25  1.1  jtc  *    may be used to endorse or promote products derived from this software
     26  1.1  jtc  *    without specific prior written permission.
     27  1.1  jtc  *
     28  1.1  jtc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  1.1  jtc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  1.1  jtc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  1.1  jtc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  1.1  jtc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  1.1  jtc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  1.1  jtc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  1.1  jtc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  1.1  jtc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  1.1  jtc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  1.1  jtc  * SUCH DAMAGE.
     39  1.1  jtc  */
     40  1.1  jtc 
     41  1.1  jtc #ifndef lint
     42  1.2  cgd #if 0
     43  1.1  jtc static char sccsid[] = "@(#)init.c	8.1 (Berkeley) 6/2/93";
     44  1.2  cgd #else
     45  1.4  mrg static char rcsid[] = "$NetBSD: init.c,v 1.4 1996/05/21 21:53:05 mrg Exp $";
     46  1.2  cgd #endif
     47  1.1  jtc #endif /* not lint */
     48  1.1  jtc 
     49  1.1  jtc /*      Re-coding of advent in C: data initialization                   */
     50  1.1  jtc 
     51  1.1  jtc #include <sys/types.h>
     52  1.4  mrg #include <signal.h>
     53  1.1  jtc #include <stdio.h>
     54  1.1  jtc #include "hdr.h"
     55  1.1  jtc 
     56  1.1  jtc int blklin = TRUE;
     57  1.1  jtc 
     58  1.1  jtc int setbit[16] = {1,2,4,010,020,040,0100,0200,0400,01000,02000,04000,
     59  1.1  jtc 		  010000,020000,040000,0100000};
     60  1.1  jtc 
     61  1.1  jtc 
     62  1.1  jtc init(command)                           /* everything for 1st time run  */
     63  1.1  jtc char *command;                          /* command we were called with  */
     64  1.1  jtc {
     65  1.1  jtc 	rdata();                        /* read data from orig. file    */
     66  1.1  jtc 	linkdata();
     67  1.1  jtc 	poof();
     68  1.1  jtc }
     69  1.1  jtc 
     70  1.1  jtc char *decr(a,b,c,d,e)
     71  1.1  jtc char a,b,c,d,e;
     72  1.1  jtc {
     73  1.1  jtc 	static char buf[6];
     74  1.1  jtc 
     75  1.1  jtc 	buf[0] = a-'+';
     76  1.1  jtc 	buf[1] = b-'-';
     77  1.1  jtc 	buf[2] = c-'#';
     78  1.1  jtc 	buf[3] = d-'&';
     79  1.1  jtc 	buf[4] = e-'%';
     80  1.1  jtc 	buf[5] = 0;
     81  1.1  jtc 	return buf;
     82  1.1  jtc }
     83  1.1  jtc 
     84  1.1  jtc linkdata()                              /*  secondary data manipulation */
     85  1.1  jtc {       register int i,j;
     86  1.1  jtc 
     87  1.1  jtc 	/*      array linkages          */
     88  1.1  jtc 	for (i=1; i<=LOCSIZ; i++)
     89  1.1  jtc 		if (ltext[i].seekadr!=0 && travel[i] != 0)
     90  1.1  jtc 			if ((travel[i]->tverb)==1) cond[i]=2;
     91  1.1  jtc 	for (j=100; j>0; j--)
     92  1.1  jtc 		if (fixd[j]>0)
     93  1.1  jtc 		{       drop(j+100,fixd[j]);
     94  1.1  jtc 			drop(j,plac[j]);
     95  1.1  jtc 		}
     96  1.1  jtc 	for (j=100; j>0; j--)
     97  1.1  jtc 	{       fixed[j]=fixd[j];
     98  1.1  jtc 		if (plac[j]!=0 && fixd[j]<=0) drop(j,plac[j]);
     99  1.1  jtc 	}
    100  1.1  jtc 
    101  1.1  jtc 	maxtrs=79;
    102  1.1  jtc 	tally=0;
    103  1.1  jtc 	tally2=0;
    104  1.1  jtc 
    105  1.1  jtc 	for (i=50; i<=maxtrs; i++)
    106  1.1  jtc 	{       if (ptext[i].seekadr!=0) prop[i] = -1;
    107  1.1  jtc 		tally -= prop[i];
    108  1.1  jtc 	}
    109  1.1  jtc 
    110  1.1  jtc 	/* define mnemonics */
    111  1.1  jtc 	keys = vocab(DECR(k,e,y,s,\0), 1);
    112  1.1  jtc 	lamp = vocab(DECR(l,a,m,p,\0), 1);
    113  1.1  jtc 	grate = vocab(DECR(g,r,a,t,e), 1);
    114  1.1  jtc 	cage  = vocab(DECR(c,a,g,e,\0),1);
    115  1.1  jtc 	rod   = vocab(DECR(r,o,d,\0,\0),1);
    116  1.1  jtc 	rod2=rod+1;
    117  1.1  jtc 	steps=vocab(DECR(s,t,e,p,s),1);
    118  1.1  jtc 	bird  = vocab(DECR(b,i,r,d,\0),1);
    119  1.1  jtc 	door  = vocab(DECR(d,o,o,r,\0),1);
    120  1.1  jtc 	pillow= vocab(DECR(p,i,l,l,o), 1);
    121  1.1  jtc 	snake = vocab(DECR(s,n,a,k,e), 1);
    122  1.1  jtc 	fissur= vocab(DECR(f,i,s,s,u), 1);
    123  1.1  jtc 	tablet= vocab(DECR(t,a,b,l,e), 1);
    124  1.1  jtc 	clam  = vocab(DECR(c,l,a,m,\0),1);
    125  1.1  jtc 	oyster= vocab(DECR(o,y,s,t,e), 1);
    126  1.1  jtc 	magzin= vocab(DECR(m,a,g,a,z), 1);
    127  1.1  jtc 	dwarf = vocab(DECR(d,w,a,r,f), 1);
    128  1.1  jtc 	knife = vocab(DECR(k,n,i,f,e), 1);
    129  1.1  jtc 	food  = vocab(DECR(f,o,o,d,\0),1);
    130  1.1  jtc 	bottle= vocab(DECR(b,o,t,t,l), 1);
    131  1.1  jtc 	water = vocab(DECR(w,a,t,e,r), 1);
    132  1.1  jtc 	oil   = vocab(DECR(o,i,l,\0,\0),1);
    133  1.1  jtc 	plant = vocab(DECR(p,l,a,n,t), 1);
    134  1.1  jtc 	plant2=plant+1;
    135  1.1  jtc 	axe   = vocab(DECR(a,x,e,\0,\0),1);
    136  1.1  jtc 	mirror= vocab(DECR(m,i,r,r,o), 1);
    137  1.1  jtc 	dragon= vocab(DECR(d,r,a,g,o), 1);
    138  1.1  jtc 	chasm = vocab(DECR(c,h,a,s,m), 1);
    139  1.1  jtc 	troll = vocab(DECR(t,r,o,l,l), 1);
    140  1.1  jtc 	troll2=troll+1;
    141  1.1  jtc 	bear  = vocab(DECR(b,e,a,r,\0),1);
    142  1.1  jtc 	messag= vocab(DECR(m,e,s,s,a), 1);
    143  1.1  jtc 	vend  = vocab(DECR(v,e,n,d,i), 1);
    144  1.1  jtc 	batter= vocab(DECR(b,a,t,t,e), 1);
    145  1.1  jtc 
    146  1.1  jtc 	nugget= vocab(DECR(g,o,l,d,\0),1);
    147  1.1  jtc 	coins = vocab(DECR(c,o,i,n,s), 1);
    148  1.1  jtc 	chest = vocab(DECR(c,h,e,s,t), 1);
    149  1.1  jtc 	eggs  = vocab(DECR(e,g,g,s,\0),1);
    150  1.1  jtc 	tridnt= vocab(DECR(t,r,i,d,e), 1);
    151  1.1  jtc 	vase  = vocab(DECR(v,a,s,e,\0),1);
    152  1.1  jtc 	emrald= vocab(DECR(e,m,e,r,a), 1);
    153  1.1  jtc 	pyram = vocab(DECR(p,y,r,a,m), 1);
    154  1.1  jtc 	pearl = vocab(DECR(p,e,a,r,l), 1);
    155  1.1  jtc 	rug   = vocab(DECR(r,u,g,\0,\0),1);
    156  1.1  jtc 	chain = vocab(DECR(c,h,a,i,n), 1);
    157  1.1  jtc 
    158  1.1  jtc 	back  = vocab(DECR(b,a,c,k,\0),0);
    159  1.1  jtc 	look  = vocab(DECR(l,o,o,k,\0),0);
    160  1.1  jtc 	cave  = vocab(DECR(c,a,v,e,\0),0);
    161  1.1  jtc 	null  = vocab(DECR(n,u,l,l,\0),0);
    162  1.1  jtc 	entrnc= vocab(DECR(e,n,t,r,a), 0);
    163  1.1  jtc 	dprssn= vocab(DECR(d,e,p,r,e), 0);
    164  1.1  jtc 	enter = vocab(DECR(e,n,t,e,r), 0);
    165  1.1  jtc 
    166  1.1  jtc 	pour  = vocab(DECR(p,o,u,r,\0), 2);
    167  1.1  jtc 	say   = vocab(DECR(s,a,y,\0,\0),2);
    168  1.1  jtc 	lock  = vocab(DECR(l,o,c,k,\0),2);
    169  1.1  jtc 	throw = vocab(DECR(t,h,r,o,w), 2);
    170  1.1  jtc 	find  = vocab(DECR(f,i,n,d,\0),2);
    171  1.1  jtc 	invent= vocab(DECR(i,n,v,e,n), 2);
    172  1.1  jtc 
    173  1.1  jtc 	/* initialize dwarves */
    174  1.1  jtc 	chloc=114;
    175  1.1  jtc 	chloc2=140;
    176  1.1  jtc 	for (i=1; i<=6; i++)
    177  1.1  jtc 		dseen[i]=FALSE;
    178  1.1  jtc 	dflag=0;
    179  1.1  jtc 	dloc[1]=19;
    180  1.1  jtc 	dloc[2]=27;
    181  1.1  jtc 	dloc[3]=33;
    182  1.1  jtc 	dloc[4]=44;
    183  1.1  jtc 	dloc[5]=64;
    184  1.1  jtc 	dloc[6]=chloc;
    185  1.1  jtc 	daltlc=18;
    186  1.1  jtc 
    187  1.1  jtc 	/* random flags & ctrs */
    188  1.1  jtc 	turns=0;
    189  1.1  jtc 	lmwarn=FALSE;
    190  1.1  jtc 	iwest=0;
    191  1.1  jtc 	knfloc=0;
    192  1.1  jtc 	detail=0;
    193  1.1  jtc 	abbnum=5;
    194  1.1  jtc 	for (i=0; i<=4; i++)
    195  1.1  jtc 		if (rtext[2*i+81].seekadr!=0) maxdie=i+1;
    196  1.1  jtc 	numdie=holdng=dkill=foobar=bonus=0;
    197  1.1  jtc 	clock1=30;
    198  1.1  jtc 	clock2=50;
    199  1.1  jtc 	saved=0;
    200  1.1  jtc 	closng=panic=closed=scorng=FALSE;
    201  1.1  jtc }
    202  1.1  jtc 
    203  1.1  jtc 
    204  1.1  jtc 
    205  1.1  jtc trapdel()                               /* come here if he hits a del   */
    206  1.1  jtc {	delhit++;			/* main checks, treats as QUIT  */
    207  1.3  mrg 	signal(SIGINT,trapdel);		/* catch subsequent DELs        */
    208  1.1  jtc }
    209  1.1  jtc 
    210  1.1  jtc 
    211  1.1  jtc startup()
    212  1.1  jtc {
    213  1.1  jtc 	time_t time();
    214  1.1  jtc 
    215  1.1  jtc 	demo=Start(0);
    216  1.1  jtc 	srand((int)(time((time_t *)NULL)));	/* random seed */
    217  1.1  jtc 	/* srand(371);				/* non-random seed */
    218  1.1  jtc 	hinted[3]=yes(65,1,0);
    219  1.1  jtc 	newloc=1;
    220  1.1  jtc 	delhit = 0;
    221  1.1  jtc 	limit=330;
    222  1.1  jtc 	if (hinted[3]) limit=1000;      /* better batteries if instrucs */
    223  1.1  jtc }
    224