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