Mercurial > ~darius > hgwebdir.cgi > paradise_server
comparison src/sysdefaults.c @ 8:0836fb919dfa
First entry of Paradise Server 2.9 patch 10 Beta
author | darius |
---|---|
date | Sat, 06 Dec 1997 04:37:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:814de70c9f67 | 8:0836fb919dfa |
---|---|
1 /*-------------------------------------------------------------------------- | |
2 NETREK II -- Paradise | |
3 | |
4 Permission to use, copy, modify, and distribute this software and its | |
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL | |
6 purpose and without fee is hereby granted, provided that this copyright | |
7 notice appear in all copies. No representations are made about the | |
8 suitability of this software for any purpose. This software is provided | |
9 "as is" without express or implied warranty. | |
10 | |
11 Xtrek Copyright 1986 Chris Guthrie | |
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith | |
13 Scott Silvey | |
14 Paradise II (Netrek II) Copyright 1993 Larry Denys | |
15 Kurt Olsen | |
16 Brandon Gillespie | |
17 --------------------------------------------------------------------------*/ | |
18 | |
19 | |
20 #include "config.h" | |
21 | |
22 #include <stdio.h> | |
23 #include <math.h> | |
24 #include <string.h> | |
25 | |
26 #include <sys/types.h> | |
27 #include <sys/stat.h> | |
28 | |
29 #include "defs.h" | |
30 #include "struct.h" | |
31 #include "data.h" | |
32 #include "getship.h" | |
33 #include "shmem.h" | |
34 #include "path.h" | |
35 #include "structdesc.h" | |
36 | |
37 | |
38 /*-----------------------------MODULE VARS--------------------------------*/ | |
39 | |
40 static struct stat oldstat; /* to hold info about file so we */ | |
41 /* can check whether it has changed */ | |
42 | |
43 /* these might not match new designations provided in the sysdef. Oh well */ | |
44 static char *shiptypes[NUM_TYPES] = { | |
45 "SC", "DD", "CA", "BB", "AS", "SB", "AT", | |
46 "JS", "FR", "WB", "CL", "CV", "UT", "PT" | |
47 }; | |
48 | |
49 | |
50 static char *weapontypes[WP_MAX] = {"PLASMA", "TRACTOR", "MISSILE", "FIGHTER"}; | |
51 | |
52 static char *systemtypes[SHIPS_SYSTEMS] = { | |
53 "PLASMA", "TRACTOR", "MISSILE", "FIGHTER", "PHOTON", "PHASER", "SHIELD", | |
54 "REPAIR", "CLOAK", "SCANNER", "SENSOR", "WARP", "IMPULSE", "DOCK", | |
55 "NAVIGATION", "COMMUNICATION", | |
56 }; | |
57 | |
58 /*--------------------------------------------------------------------------*/ | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 /*-----------------------------INTERNAL FUNCTIONS-------------------------*/ | |
67 | |
68 static void | |
69 load_clue_phrases() | |
70 { | |
71 char *path; | |
72 FILE *fp; | |
73 int count; | |
74 int i; | |
75 char *s = cluephrase_storage; /* damn, I'm tired of typing it */ | |
76 | |
77 path = build_path(CLUEPHRASEFILE); | |
78 | |
79 fp = fopen(path, "r"); | |
80 if (!fp) | |
81 return; | |
82 | |
83 count = fread(s, 1, CLUEPHRASE_SIZE - 2, fp); | |
84 fclose(fp); | |
85 | |
86 if (count < 0) | |
87 { | |
88 /* ACK, read fail */ | |
89 s[0] = 0; | |
90 } | |
91 else | |
92 { | |
93 s[count] = 0; /* two zeros terminates the clue phrase list */ | |
94 s[count + 1] = 0; | |
95 for (i = 0; i < count; i++) | |
96 if (s[i] == '\n') | |
97 s[i] = 0; | |
98 } | |
99 } | |
100 | |
101 /*------------------------------READSTRINGS-------------------------------*/ | |
102 /* | |
103 * This function reads in a list of strings. An array of strings contains | |
104 * the name of the possible strings in the list. If the string is read in | |
105 * from the file and matches one of the strings in the array, then the | |
106 * corresponding element in the parameter 'array' is set to 1. All keys must | |
107 * be of the same length. | |
108 */ | |
109 | |
110 | |
111 #ifndef SYSV /* HP's have a problem with this */ | |
112 extern int fprintf(); | |
113 #endif | |
114 #ifndef IRIX | |
115 extern int sscanf(); | |
116 #endif | |
117 #ifndef linux | |
118 extern int atoi(); | |
119 #endif /* linux */ | |
120 extern int fclose(); | |
121 | |
122 void | |
123 readstrings(type, string, keys, array, max) | |
124 char *type; /* Used to specify the type for err messages */ | |
125 char *string; /* the string to parse. */ | |
126 char **keys; /* the array of key strings */ | |
127 int *array; /* the array tofill with 1's */ | |
128 int max; /* the size of the array */ | |
129 { | |
130 int i; /* looping var */ | |
131 | |
132 while (*string != '\0') | |
133 { /* go until end of string */ | |
134 while ((*string == '\n') || (*string == ' ') || (*string == ',') | |
135 || (*string == '\t')) | |
136 string++; /* go to next char if white space */ | |
137 if (*string == '\0') /* if end of string found */ | |
138 break; | |
139 for (i = 0; i < max; i++) | |
140 { /* search through keys */ | |
141 if (strncmp(keys[i], string, strlen(keys[i])) == 0) | |
142 { | |
143 string += strlen(keys[i]); /* go to next key */ | |
144 array[i] = 1; /* set array element to 1 */ | |
145 break; /* found it, break out of for loop */ | |
146 } | |
147 } | |
148 if (i == max) | |
149 { /* if unknown key then */ | |
150 fprintf(stderr, "%s type %s unknown!\n", type, string); | |
151 string++; /* print error */ | |
152 } | |
153 } | |
154 } | |
155 | |
156 | |
157 /* modifies flagp to return result */ | |
158 void | |
159 read_longflags(flagp, str, names) | |
160 long *flagp; | |
161 char *str; | |
162 char **names; | |
163 { | |
164 char buf[80]; | |
165 | |
166 *flagp = 0; | |
167 | |
168 while (*str) | |
169 { | |
170 int i; | |
171 i = 0; | |
172 while (*str != 0 && *str != ',') | |
173 buf[i++] = *(str++); | |
174 if (*str == ',') | |
175 str++; | |
176 buf[i] = 0; | |
177 | |
178 for (i = 0; names[i]; i++) | |
179 if (0 == strcasecmp(buf, names[i])) | |
180 break; | |
181 | |
182 if (!names[i]) | |
183 { | |
184 fprintf(stderr, "unknown flag %s\n", buf); | |
185 continue; | |
186 } | |
187 *flagp |= 1 << i; | |
188 } | |
189 } | |
190 | |
191 | |
192 /*--------------------------------SHIPDEFS---------------------------------*/ | |
193 /* | |
194 * This function gets all of the field values for a ship. Each line of input | |
195 * for the ship fields has a single ship field on it. The name of the ship | |
196 * field is followed by the value to place in that field. The function stops | |
197 * when it encounters a line with "end" on it. It places the values into | |
198 * the shipvals so that the next time getship is called, the new values will | |
199 * be used. | |
200 */ | |
201 | |
202 void | |
203 shipdefs(s, f) | |
204 int s; /* ship number */ | |
205 FILE *f; /* file to load from */ | |
206 { | |
207 struct ship *currship = shipvals + s; | |
208 char buf[256]; /* to get a string from file */ | |
209 char field_name[64]; /* to get name of field */ | |
210 char value[256]; /* to get name */ | |
211 char sdesig[64]; /* to get ship letters */ | |
212 int len; /* to hold length of read in string */ | |
213 int i; /* looping var */ | |
214 int offset; /* to offset into ship structure */ | |
215 | |
216 if ((s < 0) || (s >= NUM_TYPES)) | |
217 { /* invalid ship number? */ | |
218 fprintf(stderr, "invalid ship number in .sysdef file\n"); | |
219 return; | |
220 } | |
221 while (1) | |
222 { /* loop until break */ | |
223 if (0 == fgets(buf, sizeof(buf), f)) /* get a string of input */ | |
224 break; /* if end of file then break */ | |
225 if (buf[0] == '!') | |
226 continue; /* skip lines that begin with ! */ | |
227 len = strlen(buf); | |
228 if (buf[len - 1] == '\n') /* blast trailing newline */ | |
229 buf[--len] = 0; | |
230 if (strncmp(buf, "end", 3) == 0) | |
231 { /* if end of ship then break */ | |
232 return; | |
233 } | |
234 if (shipvals == 0) | |
235 continue; | |
236 | |
237 /* get field name and value */ | |
238 sscanf(buf, "%s %s %s", sdesig, field_name, value); | |
239 | |
240 for (i = 0; ship_fields[i].name; i++) | |
241 { /* loop through field names */ | |
242 if (strcmp(field_name, ship_fields[i].name) == 0 || /* found field? */ | |
243 (strncmp(field_name, "s_", 2) == 0 && | |
244 strcmp(field_name + 2, ship_fields[i].name) == 0)) | |
245 break; | |
246 } | |
247 if (ship_fields[i].name == 0) | |
248 { /* if we did not find name */ | |
249 fprintf(stderr, "invalid field name in ship description `%s'\n", | |
250 field_name); | |
251 continue; /* print error, get next */ | |
252 } | |
253 offset = ship_fields[i].offset; /* get offset into struct */ | |
254 switch (ship_fields[i].type) | |
255 { /* parse the right type */ | |
256 case FT_CHAR: | |
257 sscanf(value, "%c", offset + (char *) currship); | |
258 break; | |
259 case FT_SHORT: | |
260 sscanf(value, "%hi", (short *) (offset + (char *) currship)); | |
261 break; | |
262 case FT_INT: | |
263 sscanf(value, "%i", (int *) (offset + (char *) currship)); | |
264 break; | |
265 case FT_LONG: | |
266 sscanf(value, "%li", (long *) (offset + (char *) currship)); | |
267 break; | |
268 case FT_FLOAT: | |
269 sscanf(value, "%f", (float *) (offset + (char *) currship)); | |
270 break; | |
271 case FT_STRING: | |
272 sscanf(value, "%s", offset + (char *) currship); | |
273 break; | |
274 case FT_LONGFLAGS: | |
275 read_longflags((long *) (offset + (char *) currship), value, | |
276 (char **) ship_fields[i].aux); | |
277 break; | |
278 default: | |
279 fprintf(stderr, "Internal error, unknown field type %d\n", | |
280 ship_fields[i].type); | |
281 } | |
282 } | |
283 } | |
284 | |
285 /*--------------------------------------------------------------------------*/ | |
286 void | |
287 initteamvals() | |
288 { | |
289 strcpy(teams[NOBODY].nickname, "Independent"); | |
290 strcpy(teams[NOBODY].name, "Independents"); | |
291 teams[NOBODY].letter = 'I'; | |
292 strcpy(teams[NOBODY].shortname, "IND"); | |
293 | |
294 strcpy(teams[FED].nickname, "Fed"); | |
295 strcpy(teams[FED].name, "Federation"); | |
296 teams[FED].letter = 'F'; | |
297 strcpy(teams[FED].shortname, "FED"); | |
298 | |
299 strcpy(teams[ROM].nickname, "Romulan"); | |
300 strcpy(teams[ROM].name, "Romulans"); | |
301 teams[ROM].letter = 'R'; | |
302 strcpy(teams[ROM].shortname, "ROM"); | |
303 | |
304 strcpy(teams[KLI].nickname, "Klingon"); | |
305 strcpy(teams[KLI].name, "Klingons"); | |
306 teams[KLI].letter = 'K'; | |
307 strcpy(teams[KLI].shortname, "KLI"); | |
308 | |
309 strcpy(teams[ORI].nickname, "Orion"); | |
310 strcpy(teams[ORI].name, "Orions"); | |
311 teams[ORI].letter = 'O'; | |
312 strcpy(teams[ORI].shortname, "ORI"); | |
313 } | |
314 | |
315 /*--------------------------------------------------------------------------*/ | |
316 | |
317 | |
318 | |
319 #define OFFSET_OF(field) ( (char*)(&((struct configuration*)0)->field) -\ | |
320 (char*)0) | |
321 | |
322 static struct field_desc config_fields[] = { | |
323 {"TOURN", FT_INT, OFFSET_OF(tournplayers)}, | |
324 {"TESTERS", FT_INT, OFFSET_OF(ntesters)}, | |
325 | |
326 {"CONFIRM", FT_BYTE, OFFSET_OF(binconfirm)}, | |
327 {"MAXLOAD", FT_FLOAT, OFFSET_OF(maxload)}, | |
328 {"UDP", FT_BYTE, OFFSET_OF(udpAllowed)}, | |
329 {"MINUPDDELAY", FT_INT, OFFSET_OF(min_upd_delay)}, | |
330 {"MINOBSUPDDELAY", FT_INT, OFFSET_OF(min_observer_upd_delay)}, | |
331 | |
332 {"PLKILLS", FT_FLOAT, OFFSET_OF(plkills)}, | |
333 {"MSKILLS", FT_FLOAT, OFFSET_OF(mskills)}, | |
334 {"EROSION", FT_FLOAT, OFFSET_OF(erosion)}, | |
335 {"PENETRATION", FT_FLOAT, OFFSET_OF(penetration)}, | |
336 {"NEWTURN", FT_INT, OFFSET_OF(newturn)}, | |
337 {"HIDDEN", FT_INT, OFFSET_OF(hiddenenemy)}, | |
338 {"PLANUPDSPD", FT_FLOAT, OFFSET_OF(planupdspd)}, | |
339 {"GALAXYGENERATOR", FT_INT, OFFSET_OF(galaxygenerator)}, | |
340 {"NUMWORMPAIRS", FT_INT, OFFSET_OF(num_wormpairs)}, | |
341 {"NUMNEBULA", FT_INT, OFFSET_OF(num_nebula)}, | |
342 {"NEBULADENSITY", FT_INT, OFFSET_OF(nebula_density)}, | |
343 {"NEBULASUBCLOUDS", FT_INT, OFFSET_OF(nebula_subclouds)}, | |
344 {"NUMASTEROID", FT_INT, OFFSET_OF(num_asteroid)}, | |
345 {"ASTEROIDTHICKNESS", FT_FLOAT, OFFSET_OF(asteroid_thickness)}, | |
346 {"ASTEROIDDENSITY", FT_INT, OFFSET_OF(asteroid_density)}, | |
347 {"ASTEROIDRADIUS", FT_INT, OFFSET_OF(asteroid_radius)}, | |
348 {"ASTEROIDTHICKVAR", FT_FLOAT, OFFSET_OF(asteroid_thick_variance)}, | |
349 {"ASTEROIDDENSVAR", FT_INT, OFFSET_OF(asteroid_dens_variance)}, | |
350 {"ASTEROIDRADVAR", FT_INT, OFFSET_OF(asteroid_rad_variance)}, | |
351 {"POPSCHEME", FT_BYTE, OFFSET_OF(popscheme)}, | |
352 {"POPCHOICE", FT_BYTE, OFFSET_OF(popchoice)}, | |
353 {"POPSPEED%", FT_INT, OFFSET_OF(popspeed)}, | |
354 {"RESOURCEBOMBING", FT_BYTE, OFFSET_OF(resource_bombing)}, | |
355 {"REVOLTS", FT_BYTE, OFFSET_OF(revolts)}, | |
356 {"BRONCOSHIPVALS", FT_BYTE, OFFSET_OF(bronco_shipvals)}, | |
357 {"EVACUATION", FT_BYTE, OFFSET_OF(evacuation)}, | |
358 {"JUSTIFY_GALAXY", FT_BYTE, OFFSET_OF(justify_galaxy)}, | |
359 {"AFTERBURNERS", FT_BYTE, OFFSET_OF(afterburners)}, | |
360 {"WARPDRIVE", FT_BYTE, OFFSET_OF(warpdrive)}, | |
361 {"FUELEXPLOSIONS", FT_BYTE, OFFSET_OF(fuel_explosions)}, | |
362 {"NEWCLOAK", FT_BYTE, OFFSET_OF(newcloak)}, | |
363 {"BRONCORANKS", FT_BYTE, OFFSET_OF(bronco_ranks)}, | |
364 {"NEWARMYGROWTH", FT_BYTE, OFFSET_OF(new_army_growth)}, | |
365 {"WARPDECEL", FT_BYTE, OFFSET_OF(warpdecel)}, | |
366 {"AFFECTSHIPTIMERSOUTSIDET", FT_BYTE, OFFSET_OF(affect_shiptimers_outside_T)}, | |
367 {"DURABLESCOUTING", FT_BYTE, OFFSET_OF(durablescouting)}, | |
368 {"FACILITYGROWTH", FT_BYTE, OFFSET_OF(facilitygrowth)}, | |
369 {"FIREDURINGWARPPREP", FT_BYTE, OFFSET_OF(fireduringwarpprep)}, | |
370 {"FIREDURINGWARP", FT_BYTE, OFFSET_OF(fireduringwarp)}, | |
371 {"FIREWHILEDOCKED", FT_BYTE, OFFSET_OF(firewhiledocked)}, | |
372 {"WARPPREPSTYLE", FT_BYTE, OFFSET_OF(warpprepstyle)}, | |
373 {"BASERANKSTYLE", FT_BYTE, OFFSET_OF(baserankstyle)}, | |
374 {"CLOAKDURINGWARPPREP", FT_BYTE, OFFSET_OF(cloakduringwarpprep)}, | |
375 {"CLOAKWHILEWARPING", FT_BYTE, OFFSET_OF(cloakwhilewarping)}, | |
376 {"TRACTABORTWARP", FT_BYTE, OFFSET_OF(tractabortwarp)}, | |
377 {"ORBITDIRPROB", FT_FLOAT, OFFSET_OF(orbitdirprob)}, | |
378 {"NEWORBITS", FT_BYTE, OFFSET_OF(neworbits)}, | |
379 {"PLANETSINPLAY", FT_INT, OFFSET_OF(planetsinplay)}, | |
380 {"PLANETLIMITTYPE", FT_INT, OFFSET_OF(planetlimittype)}, | |
381 {"BEAMLASTARMIES", FT_BYTE, OFFSET_OF(beamlastarmies)}, | |
382 #ifdef LEAGUE_SUPPORT | |
383 {"TIMEOUTS", FT_INT, OFFSET_OF(timeouts)}, | |
384 {"REGULATIONMINUTES", FT_INT, OFFSET_OF(regulation_minutes)}, | |
385 {"OVERTIMEMINUTES", FT_INT, OFFSET_OF(overtime_minutes)}, | |
386 #endif | |
387 {"PING_PERIOD", FT_INT, OFFSET_OF(ping_period)}, | |
388 {"PING_ILOSS_INTERVAL", FT_INT, OFFSET_OF(ping_iloss_interval)}, | |
389 {"PING_GHOSTBUST", FT_INT, OFFSET_OF(ping_allow_ghostbust)}, | |
390 {"PING_GHOSTBUST_INTERVAL", FT_INT, OFFSET_OF(ping_ghostbust_interval)}, | |
391 {"CLUECHECK", FT_BYTE, OFFSET_OF(cluecheck)}, | |
392 {"CLUEDELAY", FT_INT, OFFSET_OF(cluedelay)}, | |
393 {"CLUETIME", FT_INT, OFFSET_OF(cluetime)}, | |
394 {"CLUESOURCE", FT_INT, OFFSET_OF(cluesource)}, | |
395 {"VARIABLE_WARP", FT_INT, OFFSET_OF(variable_warp)}, | |
396 {"WARPPREP_SUSPENDABLE", FT_INT, OFFSET_OF(warpprep_suspendable)}, | |
397 {"NOPREGAMEBEAMUP", FT_INT, OFFSET_OF(nopregamebeamup)}, | |
398 {"GAMESTARTNUKE", FT_INT, OFFSET_OF(gamestartnuke)}, | |
399 {"NOTTIMEOUT", FT_INT, OFFSET_OF(nottimeout)}, | |
400 {"WARPZONE", FT_INT, OFFSET_OF(warpzone)}, | |
401 {"HELPFULPLANETS", FT_INT, OFFSET_OF(helpfulplanets)}, | |
402 {0} | |
403 }; | |
404 | |
405 #undef OFFSET_OF | |
406 | |
407 | |
408 | |
409 /*----------------------------VISIBLE FUNCTIONS----------------------------*/ | |
410 | |
411 /*------------------------------READSYSDEFAULTS----------------------------*/ | |
412 /* | |
413 * This function reads in the system defaults from a file. A number of | |
414 * defaults are set and if the file contains keywords with different settings | |
415 * then they are changed. | |
416 */ | |
417 | |
418 void | |
419 readsysdefaults() | |
420 { | |
421 int i; /* looping var */ | |
422 FILE *f; /* to open sysdefaults file */ | |
423 char buf[200]; /* to get a line of text */ | |
424 char *s; /* to point to fields in text */ | |
425 char *paths; /* to hold path name of dot dir */ | |
426 | |
427 load_clue_phrases(); | |
428 | |
429 /* | |
430 * put default values in the configuration values for readsysdefaults() to | |
431 * override | |
432 */ | |
433 configvals->tournplayers = 5; | |
434 configvals->ntesters = | |
435 #ifdef LEAGUE_SUPPORT | |
436 status2->league ? 2 : | |
437 #endif | |
438 12; | |
439 | |
440 configvals->binconfirm = 0; | |
441 configvals->maxload = 100.0; | |
442 configvals->udpAllowed = 1; | |
443 configvals->min_upd_delay = 200000; /* 5 updates/sec */ | |
444 configvals->min_observer_upd_delay = 333000; /* 3 updates/sec */ | |
445 | |
446 configvals->plkills = 2; | |
447 configvals->mskills = 2; /* was 2.5, changed 5-Nov-94 by PLC */ | |
448 configvals->erosion = 0.0; | |
449 configvals->penetration = 0.0; | |
450 configvals->newturn = 0; | |
451 configvals->hiddenenemy = 1; | |
452 configvals->planupdspd = 0; | |
453 configvals->justify_galaxy = 1; /* changed 5-Nov-94 by PLC */ | |
454 | |
455 #ifdef BRONCO | |
456 configvals->galaxygenerator = 4; /* Bronco emulator */ | |
457 configvals->resource_bombing = 0; | |
458 configvals->revolts = 0; | |
459 configvals->afterburners = 0; | |
460 configvals->warpdrive = 0; | |
461 configvals->fuel_explosions = 0; | |
462 configvals->bronco_shipvals = 1; | |
463 configvals->evacuation = 0; /* evacuation is allowed in paradise */ | |
464 configvals->newcloak = 0; /* old formula is not based on speed */ | |
465 configvals->new_army_growth = 0; /* WAY faster than bronco in many | |
466 * cases */ | |
467 configvals->warpdecel = 0; | |
468 configvals->affect_shiptimers_outside_T = 0; | |
469 | |
470 configvals->durablescouting = 1; | |
471 configvals->facilitygrowth = 0; | |
472 configvals->orbitdirprob = 1.0; | |
473 configvals->planetsinplay = 40; | |
474 #else | |
475 configvals->galaxygenerator = 3; /* Heath's galaxy generator */ | |
476 /* changed 5-Nov-94 by PLC */ | |
477 configvals->num_wormpairs = 0; | |
478 configvals->resource_bombing = 1; | |
479 configvals->revolts = 1; | |
480 configvals->afterburners = 1; | |
481 configvals->warpdrive = 1; | |
482 configvals->fuel_explosions = 1; | |
483 configvals->bronco_shipvals = 0; | |
484 configvals->evacuation = 1; /* evacuation is allowed in paradise */ | |
485 configvals->newcloak = 1; | |
486 configvals->new_army_growth = 1; /* WAY faster than bronco in many | |
487 * cases */ | |
488 configvals->warpdecel = 0; | |
489 configvals->affect_shiptimers_outside_T = 0; | |
490 | |
491 configvals->durablescouting = 0; | |
492 configvals->facilitygrowth = 1; | |
493 configvals->orbitdirprob = 1; /* changed 5-Nov-94 by PLC */ | |
494 configvals->neworbits = 1; | |
495 configvals->planetsinplay = 17; /* changed 5-Nov-94 by PLC */ | |
496 configvals->planetlimittype = 0; | |
497 configvals->popscheme = 1; | |
498 configvals->popchoice = 1; | |
499 configvals->popspeed = 14; /* was 9, changed 5-Nov-94 by PLC */ | |
500 #endif | |
501 configvals->fireduringwarpprep = 0; | |
502 configvals->fireduringwarp = 0; | |
503 configvals->firewhiledocked = 0; | |
504 configvals->tractabortwarp = 0; /* changed 5-Nov-94 by PLC */ | |
505 | |
506 configvals->warpprepstyle = WPS_TABORT; | |
507 configvals->baserankstyle = 0; | |
508 configvals->cloakduringwarpprep = 0; | |
509 configvals->cloakwhilewarping = 1; | |
510 | |
511 configvals->num_nebula = 0; | |
512 configvals->nebula_density = 240; /* temporily used as size */ | |
513 configvals->nebula_subclouds = 0; | |
514 configvals->num_asteroid = 0; | |
515 configvals->asteroid_thickness = 1.0; /* small to medium sized */ | |
516 configvals->asteroid_radius = 12; /* the distance from the "owning" | |
517 * star */ | |
518 configvals->asteroid_density = 60; /* density is % chance an eligible | |
519 * tgrid locale will have asteroids */ | |
520 configvals->asteroid_thick_variance = 3.0; | |
521 configvals->asteroid_rad_variance = 8; | |
522 configvals->asteroid_dens_variance = 40; | |
523 | |
524 configvals->beamlastarmies = 0; | |
525 | |
526 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
527 configvals->sun_effect[i] = (i == SS_PHOTON || | |
528 i == SS_PLASMA || | |
529 i == SS_MISSILE || | |
530 i == SS_FIGHTER); | |
531 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
532 configvals->ast_effect[i] = (i == SS_PHOTON || | |
533 i == SS_PLASMA || | |
534 i == SS_MISSILE || | |
535 i == SS_FIGHTER || | |
536 i == SS_IMPULSE); | |
537 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
538 configvals->neb_effect[i] = 0; | |
539 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
540 configvals->wh_effect[i] = (i == SS_PHOTON || | |
541 i == SS_PLASMA || | |
542 i == SS_MISSILE || | |
543 i == SS_FIGHTER || | |
544 i == SS_WARP || | |
545 i == SS_IMPULSE); | |
546 | |
547 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
548 configvals->improved_tracking[i] = | |
549 ( | |
550 #if 0 | |
551 /* I recommend improved tracking for these - RF */ | |
552 i == SS_MISSILE || | |
553 i == SS_FIGHTER || /* except this doesn't work just yet */ | |
554 /* fighter torps REALLY need this - MDM */ | |
555 i == SS_PHOTON || | |
556 #endif | |
557 0); | |
558 | |
559 for (i = 0; i < NUM_TYPES; i++) | |
560 configvals->shipsallowed[i] = (i == SCOUT || | |
561 i == DESTROYER || | |
562 i == CRUISER || | |
563 i == BATTLESHIP || | |
564 i == ASSAULT || | |
565 i == STARBASE || | |
566 i == JUMPSHIP || | |
567 i == FRIGATE || | |
568 i == WARBASE); | |
569 for (i = 0; i < WP_MAX; i++) | |
570 configvals->weaponsallowed[i] = (i == WP_PLASMA || | |
571 i == WP_TRACTOR || | |
572 #ifndef BRONCO | |
573 i == WP_MISSILE || | |
574 #endif | |
575 0); | |
576 | |
577 #ifdef LEAGUE_SUPPORT | |
578 configvals->timeouts = 0; /* NYI */ | |
579 configvals->regulation_minutes = 60; | |
580 configvals->overtime_minutes = 0; /* NYI */ | |
581 configvals->playersperteam = 8; | |
582 #endif | |
583 | |
584 configvals->nopregamebeamup = 0; | |
585 configvals->gamestartnuke = 0; | |
586 configvals->nottimeout = 0; | |
587 | |
588 configvals->ping_period = 2; /* every 2 seconds */ | |
589 configvals->ping_iloss_interval = 10; | |
590 configvals->ping_allow_ghostbust = 0; | |
591 configvals->ping_ghostbust_interval = 10; | |
592 | |
593 configvals->cluecheck = 0; /* don't check clue */ | |
594 configvals->cluetime = 5 * 60;/* 5 minutes */ | |
595 configvals->cluedelay = 2 * 60 * 60; /* 2 hours */ | |
596 configvals->cluesource = CC_PHRASE_LIST_FILE; | |
597 configvals->variable_warp = 1;/* warp speed is variable [BDyess] */ | |
598 /* changed 5-Nov-94 by PLC */ | |
599 configvals->warpprep_suspendable = 1; /* warp prep is suspendable [BDyess] */ | |
600 /* changed 5-Nov-94 by PLC */ | |
601 configvals->warpzone = 0; /* warp zone default off [BDyess] */ | |
602 | |
603 configvals->plgrow.fuel = 100; | |
604 configvals->plgrow.agri = 350; | |
605 configvals->plgrow.repair = 150; | |
606 configvals->plgrow.shipyard = 400; | |
607 | |
608 getshipdefaults(); | |
609 initteamvals(); | |
610 | |
611 /* set server defaults */ | |
612 testtime = -1; /* not in testing mode */ | |
613 | |
614 #ifdef LEAGUE_SUPPORT | |
615 if (status2->league) | |
616 return; /* don't read .sysdef during league game */ | |
617 #endif | |
618 paths = build_path(SYSDEF_FILE); /* cat on sysdef filename */ | |
619 f = fopen(paths, "r"); /* attempt to open file */ | |
620 if (f == NULL) | |
621 { /* if failure to open file */ | |
622 fprintf(stderr, "No system defaults file!\n"); | |
623 return; /* error message then out of here */ | |
624 } | |
625 stat(paths, &oldstat); /* record info about file */ | |
626 | |
627 while (fgets(buf, 199, f) != NULL) | |
628 { /* read strings until end of file */ | |
629 if (buf[0] == '!') | |
630 continue; /* skip lines that begin with ! */ | |
631 s = strchr(buf, '='); /* find the equals sign in string */ | |
632 if (s == NULL) /* if no equals sign then */ | |
633 continue; /* go to next string */ | |
634 *s = '\0'; /* break buf into rhs and lhs */ | |
635 s++; | |
636 if (strcmp(buf, "SHIPS") == 0) | |
637 { /* if ship enabling then */ | |
638 for (i = 0; i < NUM_TYPES; i++) /* go through ships */ | |
639 shipsallowed[i] = 0; /* turn off all ships */ | |
640 readstrings("SHIPS", s, shiptypes, shipsallowed, NUM_TYPES); | |
641 } | |
642 else if (strcmp(buf, "WEAPONS") == 0) | |
643 { /* if weapon enabling */ | |
644 for (i = 0; i < WP_MAX; i++) /* set all weapons as off */ | |
645 weaponsallowed[i] = 0; /* then read in weapons */ | |
646 readstrings("WEAPONS", s, weapontypes, weaponsallowed, WP_MAX); | |
647 } | |
648 else if (strcmp(buf, "SUN_EFFECT") == 0) | |
649 { | |
650 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
651 sun_effect[i] = 0; | |
652 readstrings("SUN_EFFECT", s, systemtypes, sun_effect, SHIPS_SYSTEMS); | |
653 } | |
654 else if (strcmp(buf, "ASTEROID_EFFECT") == 0) | |
655 { | |
656 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
657 ast_effect[i] = 0; | |
658 readstrings("ASTEROID_EFFECT", s, systemtypes, ast_effect, SHIPS_SYSTEMS); | |
659 } | |
660 else if (strcmp(buf, "NEBULA_EFFECT") == 0) | |
661 { | |
662 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
663 neb_effect[i] = 0; | |
664 readstrings("NEBULA_EFFECT", s, systemtypes, neb_effect, SHIPS_SYSTEMS); | |
665 } | |
666 else if (strcmp(buf, "WORMHOLE_EFFECT") == 0) | |
667 { | |
668 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
669 wh_effect[i] = 0; | |
670 readstrings("WORMHOLE_EFFECT", s, systemtypes, wh_effect, SHIPS_SYSTEMS); | |
671 } | |
672 else if (strcmp(buf, "IMPROVED_TRACKING") == 0) | |
673 { | |
674 for (i = 0; i < SHIPS_SYSTEMS; i++) | |
675 improved_tracking[i] = 0; | |
676 readstrings("IMPROVED_TRACKING", s, systemtypes, improved_tracking, SHIPS_SYSTEMS); | |
677 #if 0 | |
678 } | |
679 else if (strcmp(buf, "PING_FREQ") == 0) | |
680 { | |
681 ping_freq = atoi(s); | |
682 } | |
683 else if (strcmp(buf, "PING_ILOSS_INTERVAL") == 0) | |
684 { | |
685 ping_iloss_interval = atoi(s); | |
686 } | |
687 else if (strcmp(buf, "PING_GHOSTBUST") == 0) | |
688 { | |
689 ping_allow_ghostbust = atoi(s); | |
690 } | |
691 else if (strcmp(buf, "PING_GHOSTBUST_INTERVAL") == 0) | |
692 { | |
693 ping_ghostbust_interval = atoi(s); | |
694 #endif | |
695 } | |
696 else if (strcmp(buf, "SHIP") == 0) | |
697 { /* if ship being entered */ | |
698 shipdefs(atoi(s), f); | |
699 } | |
700 else if (strcmp(buf, "RELOAD_SHIPDEFAULTS") == 0) | |
701 { | |
702 getshipdefaults(); | |
703 } | |
704 else | |
705 { | |
706 for (i = 0; config_fields[i].name; i++) | |
707 { | |
708 if (strcmp(buf, config_fields[i].name) == 0) | |
709 break; | |
710 } | |
711 if (!config_fields[i].name) | |
712 { | |
713 fprintf(stderr, "System default %s unknown\n", buf); | |
714 } | |
715 else | |
716 { | |
717 int offset = config_fields[i].offset; | |
718 char *curr = (char *) configvals; | |
719 switch (config_fields[i].type) | |
720 { /* parse the right type */ | |
721 case FT_BYTE: | |
722 *(offset + curr) = atoi(s); | |
723 break; | |
724 case FT_SHORT: | |
725 sscanf(s, "%hi", (short *) (offset + curr)); | |
726 break; | |
727 case FT_INT: | |
728 sscanf(s, "%i", (int *) (offset + curr)); | |
729 break; | |
730 case FT_LONG: | |
731 sscanf(s, "%li", (long *) (offset + curr)); | |
732 break; | |
733 case FT_FLOAT: | |
734 sscanf(s, "%f", (float *) (offset + curr)); | |
735 break; | |
736 case FT_STRING: | |
737 sscanf(s, "%s", offset + curr); | |
738 break; | |
739 case FT_LONGFLAGS: | |
740 read_longflags((long *) (offset + curr), s, | |
741 (char **) config_fields[i].aux); | |
742 break; | |
743 default: | |
744 fprintf(stderr, "Internal error, unknown config field type %d\n", | |
745 config_fields[i].type); | |
746 } | |
747 } | |
748 } | |
749 } | |
750 | |
751 if (configvals->tournplayers < 1) /* get number of players needed */ | |
752 configvals->tournplayers = 5; /* cannot set tournplayers to 0 */ | |
753 | |
754 if (configvals->erosion > 1) | |
755 configvals->erosion = 1; | |
756 if (configvals->penetration > 1) | |
757 configvals->penetration = 1; | |
758 if (configvals->penetration < 0) | |
759 configvals->penetration = 0; | |
760 | |
761 if (configvals->ping_period <= 0) | |
762 configvals->ping_period = 1; | |
763 if (configvals->ping_iloss_interval <= 0) | |
764 configvals->ping_iloss_interval = 1; | |
765 if (configvals->ping_ghostbust_interval <= 0) | |
766 configvals->ping_ghostbust_interval = 1; | |
767 | |
768 fclose(f); /* close sysdefaults file */ | |
769 } | |
770 | |
771 | |
772 | |
773 | |
774 /*--------------------------UPDATE_SYS_DEFAULTS---------------------------*/ | |
775 /* | |
776 * This function will update all of the defaults if the default file changed. | |
777 * It is called often, and assuming the OS caches the file inode info well, | |
778 * this isn't a problem. This function returns a 1 if new sysdefaults were | |
779 * loaded. Otherwise a zero is returned. | |
780 */ | |
781 | |
782 int | |
783 update_sys_defaults() | |
784 { | |
785 struct stat newstat; | |
786 static char *paths = NULL; /* to hold full pathname */ | |
787 | |
788 #ifdef LEAGUE_SUPPORT | |
789 if (status2->league) | |
790 return 0; /* don't read .sysdef during league game */ | |
791 #endif | |
792 | |
793 if (!paths) /* just do the build_path once */ | |
794 paths = strdup(build_path(SYSDEF_FILE)); | |
795 | |
796 if (stat(paths, &newstat) == 0) | |
797 { /* get info about sysdef file */ | |
798 if (newstat.st_ino != oldstat.st_ino || /* if the file has */ | |
799 newstat.st_mtime != oldstat.st_mtime) | |
800 { /* changed then */ | |
801 readsysdefaults(); /* load new defaults and */ | |
802 | |
803 /* | |
804 * touch the motd file so the clients will re-load the sysdef screen | |
805 */ | |
806 touch(build_path(MOTD)); | |
807 | |
808 return (1); /* return that they were loaded */ | |
809 } | |
810 } | |
811 return (0); /* return 0 for no new stats */ | |
812 } | |
813 | |
814 /*--------------------------------------------------------------------------*/ | |
815 | |
816 | |
817 | |
818 | |
819 | |
820 /*--------END OF FILE-------*/ |