]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
2 * setup.c - set up all files for Phantasia
9 /************************************************************************
11 / FUNCTION NAME: main()
13 / FUNCTION: setup files for Phantasia 3.3.2
15 / AUTHOR: E. A. Estes, 12/4/85
21 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
22 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
23 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
25 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
27 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
31 / This program tries to verify the parameters specified in
34 / Create all necessary files. Note that nothing needs to be
36 / Also, the monster binary data base is created here.
38 /************************************************************************/
40 static char *files
[] = { /* all files to create */
52 char *monsterfile
="monsters.asc";
59 register char **filename
; /* for pointing to file names */
60 register int fd
; /* file descriptor */
61 FILE *fp
; /* for opening files */
62 struct stat fbuf
; /* for getting files statistics */
65 while ((ch
= getopt(argc
, argv
, "m:")) != EOF
)
77 srandom((unsigned) time((long *) NULL
)); /* prime random numbers */
79 umask(0117); /* only owner can read/write created files */
81 /* try to create data files */
83 while (*filename
!= NULL
)
84 /* create each file */
86 if (stat(*filename
, &fbuf
) == 0)
87 /* file exists; remove it */
89 if (!strcmp(*filename
, _PATH_PEOPLE
))
90 /* do not reset character file if it already exists */
96 if (unlink(*filename
) < 0)
97 Error("Cannot unlink %s.\n", *filename
);
101 if ((fd
= creat(*filename
, 0660)) < 0)
102 Error("Cannot create %s.\n", *filename
);
105 close(fd
); /* close newly created file */
107 ++filename
; /* process next file */
110 /* put holy grail info into energy void file */
111 Enrgyvoid
.ev_active
= TRUE
;
112 Enrgyvoid
.ev_x
= ROLL(-1.0e6
, 2.0e6
);
113 Enrgyvoid
.ev_y
= ROLL(-1.0e6
, 2.0e6
);
114 if ((fp
= fopen(_PATH_VOID
, "w")) == NULL
)
115 Error("Cannot update %s.\n", _PATH_VOID
);
118 fwrite(&Enrgyvoid
, SZ_VOIDSTRUCT
, 1, fp
);
122 /* create binary monster data base */
123 if ((Monstfp
= fopen(_PATH_MONST
, "w")) == NULL
)
124 Error("Cannot update %s.\n", _PATH_MONST
);
127 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
130 Error("cannot open %s to create monster database.\n", "monsters.asc");
134 Curmonster
.m_o_strength
=
135 Curmonster
.m_o_speed
=
136 Curmonster
.m_maxspeed
=
137 Curmonster
.m_o_energy
=
139 Curmonster
.m_skirmish
= 0.0;
141 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
142 /* read in text file, convert to binary */
144 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
145 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
146 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
147 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
148 &Curmonster
.m_type
, &Curmonster
.m_flock
);
150 strcpy(Curmonster
.m_name
, Databuf
);
151 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
158 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
159 /* write to motd file */
160 printf("One line 'motd' ? ");
161 if (fgets(Databuf
, SZ_DATABUF
, stdin
) == NULL
)
163 if ((fp
= fopen(_PATH_MOTD
, "w")) == NULL
)
164 Error("Cannot update %s.\n", _PATH_MOTD
);
167 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
171 /* report compile-time options */
172 printf("Compiled options:\n\n");
173 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
174 printf("Wizard: root UID: 0\n");
177 printf("Compiled for BSD 4.1\n");
181 printf("Compiled for BSD 4.2\n");
185 printf("Compiled for System III\n");
189 printf("Compiled for System V\n");
197 /************************************************************************
199 / FUNCTION NAME: Error()
201 / FUNCTION: print an error message, and exit
203 / AUTHOR: E. A. Estes, 12/4/85
206 / char *str - format string for printf()
207 / char *file - file which caused error
211 / MODULES CALLED: exit(), perror(), fprintf()
213 / GLOBAL INPUTS: _iob[]
215 / GLOBAL OUTPUTS: none
218 / Print an error message, then exit.
220 /************************************************************************/
225 fprintf(stderr
, "Error: ");
226 fprintf(stderr
, str
, file
);
232 /************************************************************************
234 / FUNCTION NAME: drandom()
236 / FUNCTION: return a random number
238 / AUTHOR: E. A. Estes, 2/7/86
244 / MODULES CALLED: random()
246 / GLOBAL INPUTS: none
248 / GLOBAL OUTPUTS: none
252 /************************************************************************/
257 if (sizeof(int) != 2)
258 return((double) (random() & 0x7fff) / 32768.0);
260 return((double) random() / 32768.0);