]> git.pond.sub.org Git - empserver/blob - src/lib/gen/emp_config.c
(mult, player_coms): Command `mult' is disabled since 4.0.0 ('96), and
[empserver] / src / lib / gen / emp_config.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  emp_config.c: Allows config file to control server config. from a file
29  * 
30  *  Known contributors to this file:
31  *     Julian Onions, 1995
32  *     Steve McClure, 1998-2000
33  */
34
35 /*
36  * STILL TO DO
37  *
38  * 1. Change other constants - such as Num Countries etc.
39  *    Just requires variables to be assigned, then dynamic allocation in
40  *    a few places. Some checks needed in the server to check the world
41  *    hasn't changed size etc.
42  * 2. Could look at loading in planes, units etc. Should be easy enough.
43  *
44  */
45
46 #include <stdio.h>
47 #include <stdlib.h>             /* atoi free atol */
48 #include <string.h>
49
50 #include "misc.h"
51 #include "com.h"
52 #include "match.h"
53 #include "file.h"
54 #include "optlist.h"
55 #include "tel.h"
56 #include "gen.h"                /* parse */
57
58 /* for systems without strdup  */
59 #ifdef NOSTRDUP
60 extern char *strdup();
61 #endif /* NOSTRDUP */
62
63 /* Dummy one */
64 static int emp_config_dummy;
65
66 static void optstrset(struct keymatch *kp, s_char **av);
67 static void intset(struct keymatch *kp, s_char **av);
68 static void floatset(struct keymatch *kp, s_char **av);
69 static void doubleset(struct keymatch *kp, s_char **av);
70 static void longset(struct keymatch *kp, s_char **av);
71 static void optionset(struct keymatch *kp, s_char **av);
72 static void optiondel(struct keymatch *kp, s_char **av);
73 static void worldxset(struct keymatch *kp, s_char **av);
74
75 /* things that can be changed */
76 struct keymatch configkeys[] = {
77     {"", intset, (caddr_t)&emp_config_dummy, 0,
78      "\n### Server configuration and information"},
79     {"data", optstrset, (caddr_t)&datadir, 0,
80      "Directory the data is stored in"},
81     {"info", optstrset, (caddr_t)&infodir, 0,
82      "Directory the info pages are stored in"},
83     {"port", optstrset, (caddr_t)&loginport, 0,
84      "TCP/IP port the server will start up on"},
85     {"privname", optstrset, (caddr_t)&privname, 0,
86      "Name of the deity"},
87     {"privlog", optstrset, (caddr_t)&privlog, 0,
88      "E-mail of the deity"},
89     {"WORLD_X", worldxset, (caddr_t)&WORLD_X, 0,
90      "World size X dimension (enforced to be even by subtracting 1 if necessary)"},
91     {"WORLD_Y", intset, (caddr_t)&WORLD_Y, 0,
92      "World size Y dimension"},
93
94     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Update policy"},
95     {"update_policy", intset, (caddr_t)&update_policy, 0,
96      "0 - normal, 1 - update_times, 2 - blitz, 3 - demand only"},
97     {"etu_per_update", intset, (caddr_t)&etu_per_update, 0,
98      "Number of ETUs per update"},
99     {"s_p_etu", longset, (caddr_t)&s_p_etu, 0,
100      "Seconds per etu, updates will occur every s_p_etu * etu_per_update seconds"},
101     {"adj_update", longset, (caddr_t)&adj_update, 0,
102      "Move the update forward or backward (in seconds)"},
103     {"update_window", intset, (caddr_t)&update_window, 0,
104      "Window the update will occur in (in seconds) before and after the update time"},
105     {"update_times", optstrset, (caddr_t)&update_times, 0,
106      "Times when updates occur under policy #1.  Must coincide with schedule."},
107     {"hourslop", intset, (caddr_t)&hourslop, 0,
108      "Number of minutes update check can slip to match update_times"},
109     {"blitz_time", intset, (caddr_t)&blitz_time, 0,
110      "Number of minutes between updates under policy #2."},
111
112     {"", intset, (caddr_t)&emp_config_dummy, 0,
113      "\n\n### Demand update policy"},
114     {"update_demandpolicy", intset, (caddr_t)&update_demandpolicy, 0,
115      "0 - emp_tm checks, 1 - after setting, 2 - demand updates disabled"},
116     {"update_wantmin", intset, (caddr_t)&update_wantmin, 0,
117      "number of requests needed for demand update"},
118     {"update_missed", intset, (caddr_t)&update_missed, 0,
119      "number of demand updates country can miss before veto update"},
120     {"update_demandtimes", optstrset, (caddr_t)&update_demandtimes, 0,
121      "Times when demand updates can occur.  Ranges CANNOT cross midnight."},
122
123     {"", intset, (caddr_t)&emp_config_dummy, 0,
124      "\n\n### Game hours restrictions"},
125     {"game_days", optstrset, (caddr_t)&game_days, 0,
126      "Days game is up and running (Su Mo Tu We Th Fr Sa)"},
127     {"game_hours", optstrset, (caddr_t)&game_hours, 0,
128      "Hours game is up and running (6:00-18:00)"},
129
130     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Options\n"},
131     {"option", optionset, (caddr_t)NULL, 0, NULL},
132     {"nooption", optiondel, (caddr_t)NULL, 0, NULL},
133
134
135     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Countries"},
136     {"btu_build_rate", floatset, (caddr_t)&btu_build_rate, 0,
137      "Rate at which BTUs accumulate (etu * civ * eff * btu_build_rate)"},
138     {"m_m_p_d", intset, (caddr_t)&m_m_p_d, 0,
139      "Maximum minutes per day a country is allowed to be logged in"},
140     {"max_btus", intset, (caddr_t)&max_btus, 0,
141      "Maximum number of BTUs a country can have"},
142     {"max_idle", intset, (caddr_t)&max_idle, 0,
143      "Maximum number of minutes a player can sit idle while logged in"},
144     {"players_at_00", intset, (caddr_t)&players_at_00, 0,
145      "Players have their coordinate system at deity 0,0 (0 - no, 1 - yes)"},
146     {"at_least_one_100", intset, (caddr_t)&at_least_one_100, 0,
147      "Initialize new countries with at least one sector with 100 of all resource"},
148     {"powe_cost", doubleset, (caddr_t)&powe_cost, 0,
149      "Number of BTUs needed to generate a new power report"},
150     {"war_cost", intset, (caddr_t)&War_Cost, 0,
151      "Cost to declare war (if SLOW_WAR is on)"},
152
153     {"", intset, (caddr_t)&emp_config_dummy, 0,
154      "\n\n### Technology/Research/Education/Happiness"},
155     {"easy_tech", floatset, (caddr_t)&easy_tech, 0,
156      "Amount of tech built with no penalty"},
157     {"hard_tech", floatset, (caddr_t)&hard_tech, 0,
158      "Amount of in-efficiently built tech"},
159     {"start_tech", floatset, (caddr_t)&start_technology, 0,
160      "Starting technology for new countries"},
161     {"start_happy", floatset, (caddr_t)&start_happiness, 0,
162      "Starting happiness for new countries"},
163     {"start_research", floatset, (caddr_t)&start_research, 0,
164      "Starting research for new countries"},
165     {"start_edu", floatset, (caddr_t)&start_education, 0,
166      "Starting education for new countries"},
167     {"level_age_rate", floatset, (caddr_t)&level_age_rate, 0,
168      "ETU rate at which tech decays (0 -> no decline)"},
169     {"tech_log_base", floatset, (caddr_t)&tech_log_base, 0,
170      "Log base to apply to tech breakthroughs above the easy tech level"},
171     {"ally_factor", floatset, (caddr_t)&ally_factor, 0,
172      "Shared tech with allies (1 / ally_factor)"},
173     {"edu_avg", floatset, (caddr_t)&edu_avg, 0,
174      "Number of ETUs education is averaged over"},
175     {"hap_avg", floatset, (caddr_t)&hap_avg, 0,
176      "Number of ETUs happiness is averaged over"},
177     {"edu_cons", doubleset, (caddr_t)&edu_cons, 0,
178      "Education consumption (1 breakthrough per edu_cons)"},
179     {"hap_cons", doubleset, (caddr_t)&hap_cons, 0,
180      "Happiness consumption (1 breakthrough per hap_cons)"},
181
182     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Sectors"},
183     {"startmob", intset, (caddr_t)&startmob, 0,
184      "Starting mobility for sanctuaries"},
185     {"sect_mob_scale", floatset, (caddr_t)&sect_mob_scale, 0,
186      "Sector mobility accumulation (sect_mob_scale * ETUs per update)"},
187     {"sect_mob_max", intset, (caddr_t)&sect_mob_max, 0,
188      "Maximum mobility for sectors"},
189     {"buil_bh", intset, (caddr_t)&buil_bh, 0,
190      "Number of hcms required to build a bridge span"},
191     {"buil_bc", doubleset, (caddr_t)&buil_bc, 0,
192      "Cash required to build a bridge span"},
193     {"buil_bt", doubleset, (caddr_t)&buil_bt, 0,
194      "Technology required to build a bridge span"},
195     {"buil_tower_bh", intset, (caddr_t)&buil_tower_bh, 0,
196      "Number of hcms required to build a bridge tower"},
197     {"buil_tower_bc", doubleset, (caddr_t)&buil_tower_bc, 0,
198      "Cash required to build a bridge tower"},
199     {"buil_tower_bt", doubleset, (caddr_t)&buil_tower_bt, 0,
200      "Technology required to build a bridge tower"},
201
202     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Land Units"},
203     {"land_mob_scale", floatset, (caddr_t)&land_mob_scale, 0,
204      "Land unit mobility accumulation (land_mob_scale * ETUs per update)"},
205     {"land_grow_scale", intset, (caddr_t)&land_grow_scale, 0,
206      "How fast efficiency grows for land units each update (* ETUs)"},
207     {"land_mob_max", intset, (caddr_t)&land_mob_max, 0,
208      "Maximum mobility for land units"},
209     {"money_land", doubleset, (caddr_t)&money_land, 0,
210      "Cost per ETU to maintain land units (percentage of unit price)"},
211     {"morale_base", intset, (caddr_t)&morale_base, 0,
212      "Base level for setting morale of land units"},
213
214     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Planes"},
215     {"plane_mob_scale", floatset, (caddr_t)&plane_mob_scale, 0,
216      "Plane mobility accumulation (plane_mob_scale * ETUs per update)"},
217     {"plane_grow_scale", intset, (caddr_t)&plane_grow_scale, 0,
218      "How fast efficiency grows for planes each update (* ETUs)"},
219     {"plane_mob_max", intset, (caddr_t)&plane_mob_max, 0,
220      "Maximum mobility for planes"},
221     {"money_plane", doubleset, (caddr_t)&money_plane, 0,
222      "Cost per ETU to maintain planes (percentage of plane price)"},
223
224     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Ships"},
225     {"ship_mob_scale", floatset, (caddr_t)&ship_mob_scale, 0,
226      "Ship mobility accumulation (ship_mob_scale * ETUs per update)"},
227     {"ship_grow_scale", intset, (caddr_t)&ship_grow_scale, 0,
228      "How fast efficiency grows for ships each update (* ETUs)"},
229     {"ship_mob_max", intset, (caddr_t)&ship_mob_max, 0,
230      "Maximum mobility for ships"},
231     {"money_ship", doubleset, (caddr_t)&money_ship, 0,
232      "Cost per ETU to maintain ships (percentage of ship price)"},
233     {"torpedo_damage", intset, (caddr_t)&torpedo_damage, 0,
234      "Torpedo damage (damage is X + 1dX + 1dX)"},
235
236     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Combat/Damage"},
237     {"fort_max_interdiction_range", intset,
238      (caddr_t)&fort_max_interdiction_range, 0,
239      "Maximum range (in sectors) a fort will try to interdict another country"},
240     {"land_max_interdiction_range", intset,
241      (caddr_t)&land_max_interdiction_range, 0,
242      "Maximum range (in sectors) a land unit will try to interdict another country"},
243     {"ship_max_interdiction_range", intset,
244      (caddr_t)&ship_max_interdiction_range, 0,
245      "Maximum range (in sectors) a ship will try to interdict another country"},
246     {"flakscale", doubleset, (caddr_t)&flakscale, 0,
247      "Scale factor for flak damage"},
248     {"combat_mob", doubleset, (caddr_t)&combat_mob, 0,
249      "How much mobility do units spend for combat (* casualties/bodies)"},
250     {"people_damage", doubleset, (caddr_t)&people_damage, 0,
251      "People take this amount of normal damage"},
252     {"unit_damage", doubleset, (caddr_t)&unit_damage, 0,
253      "Land units take this amount of normal damage"},
254     {"collateral_dam", doubleset, (caddr_t)&collateral_dam, 0,
255      "Side effect damage amount done to sector"},
256     {"assault_penalty", doubleset, (caddr_t)&assault_penalty, 0,
257      "Amount of normal attacking efficiency for paratroopers and assaulting"},
258     {"fire_range_factor", floatset, (caddr_t)&fire_range_factor, 0,
259      "Scale normal firing ranges by this amount"},
260     {"sect_mob_neg_factor", intset, (caddr_t)&sect_mob_neg_factor, 0,
261      "Amount of negative mobility a sector has after takeover (ETU / x) (MOB_ACCESS)"},
262     {"mission_mob_cost", doubleset, (caddr_t)&mission_mob_cost, 0,
263      "Cost to put something on a mission (percentage of max mob)"},
264
265     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Populace"},
266     {"uwbrate", doubleset, (caddr_t)&uwbrate, 0,
267      "Birth rate for uw's"},
268     {"money_civ", doubleset, (caddr_t)&money_civ, 0,
269      "Money gained from taxes on a civilian in one ETU"},
270     {"money_mil", doubleset, (caddr_t)&money_mil, 0,
271      "Money gained from taxes on an active soldier in one ETU"},
272     {"money_res", doubleset, (caddr_t)&money_res, 0,
273      "Money gained from taxes on a soldier on active reserve in one ETU"},
274     {"money_uw", doubleset, (caddr_t)&money_uw, 0,
275      "Money gained from taxes on an uncompensated worker in one ETU"},
276     {"babyeat", doubleset, (caddr_t)&babyeat, 0,
277      "Amount of food to mature 1 baby into a civilian"},
278     {"bankint", doubleset, (caddr_t)&bankint, 0,
279      "Bank dollar gain (per bar per etu)"},
280     {"eatrate", doubleset, (caddr_t)&eatrate, 0,
281      "Food eating rate for mature people"},
282     {"fcrate", doubleset, (caddr_t)&fcrate, 0,
283      "Food cultivation rate (* workforce in sector)"},
284     {"fgrate", doubleset, (caddr_t)&fgrate, 0,
285      "Food growth rate (* fertility of sector)"},
286     {"obrate", doubleset, (caddr_t)&obrate, 0,
287      "Civilian birth rate"},
288
289     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Nukes"},
290     {"decay_per_etu", doubleset, (caddr_t)&decay_per_etu, 0,
291      "Decay of fallout per ETU"},
292     {"fallout_spread", doubleset, (caddr_t)&fallout_spread, 0,
293      "Amount of fallout that leaks into surrounding sectors"},
294     {"drnuke_const", floatset, (caddr_t)&drnuke_const, 0,
295      "Amount of research to tech needed to build a nuke (if DR_NUKE is on)"},
296
297     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Market/Trade"},
298     {"MARK_DELAY", intset, (caddr_t)&MARK_DELAY, 0,
299      "Number of seconds commodities stay on the market for bidding"},
300     {"TRADE_DELAY", intset, (caddr_t)&TRADE_DELAY, 0,
301      "Number of seconds ships, planes, and units stay on the market for bidding"},
302     {"buytax", doubleset, (caddr_t)&buytax, 0,
303      "Tax (in percentage points) charged to the buyer on market purchases"},
304     {"tradetax", doubleset, (caddr_t)&tradetax, 0,
305      "Amount of a trade transaction the seller makes (the rest is tax)"},
306
307     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Trade ships"},
308     {"trade_1_dist", intset, (caddr_t)&trade_1_dist, 0,
309      "Less than this distance no money for cashing in"},
310     {"trade_2_dist", intset, (caddr_t)&trade_2_dist, 0,
311      "Less than this distance gets trade_1 money for cashing in"},
312     {"trade_3_dist", intset, (caddr_t)&trade_3_dist, 0,
313      "Less than this distance gets trade_2 money for cashing in (>= gets trade_3"},
314     {"trade_1", floatset, (caddr_t)&trade_1, 0,
315      "Return per sector on trade_1 distance amount"},
316     {"trade_2", floatset, (caddr_t)&trade_2, 0,
317      "Return per sector on trade_2 distance amount"},
318     {"trade_3", floatset, (caddr_t)&trade_3, 0,
319      "Return per sector on trade_3 distance amount"},
320     {"trade_ally_bonus", floatset, (caddr_t)&trade_ally_bonus, 0,
321      "Bonus you get for cashing in with an ally"},
322     {"trade_ally_cut", floatset, (caddr_t)&trade_ally_cut, 0,
323      "Bonus your ally gets for you cashing in with them"},
324
325     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Misc."},
326     {"fuel_mult", intset, (caddr_t)&fuel_mult, 0,
327      "Multiplier for fuel to mobility calculation"},
328     {"lost_items_timeout", intset, (caddr_t)&lost_items_timeout, 0,
329      "Seconds before a lost item is timed out of the database"},
330     {"last_demand_update", longset, (caddr_t)&last_demand_update, 0,
331      "When was the last demand update occured"},
332
333     {NULL, NULL, (caddr_t)0, 0, NULL}
334 };
335
336 static void fixup_files(void);
337 static struct keymatch *keylookup(s_char *key, struct keymatch tbl[]);
338
339
340 /*
341  * read in empire configuration
342  */
343 int
344 emp_config(char *file)
345 {
346     FILE *fp;
347     s_char scanspace[1024];
348     s_char *av[65];
349     char buf[BUFSIZ];
350     struct keymatch *kp;
351
352     if (file == NULL || (fp = fopen(file, "r")) == NULL) {
353         fixup_files();
354         return RET_OK;
355     }
356     while (fgets(buf, sizeof buf, fp) != NULL) {
357         if (buf[0] == '#' || buf[0] == '\n')
358             continue;
359         if (parse(buf, av, 0, scanspace, 0) < 0) {
360             fprintf(stderr, "Can't parse line %s", buf);
361             continue;
362         }
363         if ((kp = keylookup(av[0], configkeys)) != NULL) {
364             (*kp->km_func) (kp, av + 1);
365         } else {
366             fprintf(stderr, "Unknown config key %s\n", av[0]);
367         }
368     }
369     fclose(fp);
370     fixup_files();
371
372     return RET_OK;
373 }
374
375 struct otherfiles {
376     s_char **files;
377     char *name;
378 };
379
380 /* list of other well known files... -maybe tailor these oneday
381  * anyway - meantime they are all relative to datadir */
382 static struct otherfiles ofiles[] = {
383     {&upfil, "up"},
384     {&downfil, "down"},
385     {&disablefil, "disable"},
386     {&banfil, "ban"},
387     {&authfil, "auth"},
388     {&commfil, "comm"},
389     {&annfil, "ann"},
390     {&timestampfil, "timestamp"},
391     {&teldir, "tel"},
392 #if !defined(_WIN32)
393     {&telfil, "tel/tel"},
394 #else
395     {&telfil, "tel\\tel"},
396 #endif
397     {NULL, NULL}
398 };
399
400 /* fix up the empfile struct to reference full path names */
401 static void
402 fixup_files(void)
403 {
404     struct empfile *ep;
405     struct otherfiles *op;
406     s_char buf[1024];
407
408     for (ep = empfile; ep < &empfile[EF_MAX]; ep++) {
409 #if !defined(_WIN32)
410         sprintf(buf, "%s/%s", datadir, ep->name);
411 #else
412         sprintf(buf, "%s\\%s", datadir, ep->name);
413 #endif
414         ep->file = strdup(buf);
415     }
416
417     for (op = ofiles; op->files; op++) {
418 #if !defined(_WIN32)
419         sprintf(buf, "%s/%s", datadir, op->name);
420 #else
421         sprintf(buf, "%s\\%s", datadir, op->name);
422 #endif
423         *op->files = strdup(buf);
424     }
425 }
426
427 /* find the key in the table */
428 static struct keymatch *
429 keylookup(register s_char *command, struct keymatch *tbl)
430 {
431     register struct keymatch *kp;
432
433     if (command == 0 || *command == 0)
434         return 0;
435     for (kp = tbl; kp->km_key != 0; kp++) {
436         if (strcmp(kp->km_key, command) == 0)
437             return kp;
438     }
439     return NULL;
440 }
441
442 /* worldx int setting function */
443 static void
444 worldxset(struct keymatch *kp, s_char **av)
445 {
446     int *intptr = (int *)kp->km_data;
447
448     if (*av == NULL || intptr == NULL)
449         return;
450     *intptr = atoi(*av);
451     if (!((*intptr % 2) == 0)) {
452         /* Must be div / 2, so subtract one */
453         *intptr = *intptr - 1;
454     }
455 }
456
457 /* generic int setting function */
458 static void
459 intset(struct keymatch *kp, s_char **av)
460 {
461     int *intptr = (int *)kp->km_data;
462
463     if (*av == NULL || intptr == NULL)
464         return;
465     *intptr = atoi(*av);
466 }
467
468 /* generic float set function */
469 static void
470 floatset(struct keymatch *kp, s_char **av)
471 {
472     float *floatptr = (float *)kp->km_data;
473
474     if (*av == NULL || floatptr == NULL)
475         return;
476     *floatptr = atof(*av);
477 }
478
479
480
481 /* generic string set function */
482 static void
483 optstrset(struct keymatch *kp, s_char **av)
484 {
485     s_char **confstrp = (s_char **)kp->km_data;
486
487     if (*av == NULL || confstrp == NULL)
488         return;
489     if (kp->km_flags & KM_ALLOC)
490         free(*confstrp);
491     *confstrp = strdup(*av);
492     kp->km_flags |= KM_ALLOC;
493 }
494
495 /* generic double set function */
496 static void
497 doubleset(struct keymatch *kp, s_char **av)
498 {
499     double *doublep = (double *)kp->km_data;
500
501     if (*av == NULL || doublep == NULL)
502         return;
503     *doublep = atof(*av);
504 }
505
506 /* generic long set function */
507 static void
508 longset(struct keymatch *kp, s_char **av)
509 {
510     long int *longp = (long int *)kp->km_data;
511
512     if (*av == NULL || longp == NULL)
513         return;
514     *longp = atol(*av);
515 }
516
517 void
518 print_config(FILE * fp)
519 {
520     struct empfile *ep;
521     struct otherfiles *op;
522     struct keymatch *kp;
523
524     fprintf(fp, "# Empire Configuration File:\n");
525     for (kp = configkeys; kp->km_key; kp++) {
526         /* We print a few special things here */
527         if (kp->km_comment) {
528             if (kp->km_comment[0]) {
529                 if (kp->km_comment[0] != '\n')
530                     fprintf(fp, "\n# ");
531                 fprintf(fp, "%s\n", kp->km_comment);
532             }
533         }
534         if (!kp->km_key[0])
535             continue;
536         if (kp->km_func == optstrset) {
537             fprintf(fp, "%s \"%s\"\n", kp->km_key,
538                     *(s_char **)kp->km_data);
539         } else if (kp->km_func == intset) {
540             fprintf(fp, "%s %d\n", kp->km_key, *(int *)kp->km_data);
541         } else if (kp->km_func == worldxset) {
542             fprintf(fp, "%s %d\n", kp->km_key, *(int *)kp->km_data);
543         } else if (kp->km_func == floatset) {
544             fprintf(fp, "%s %g\n", kp->km_key, *(float *)kp->km_data);
545         } else if (kp->km_func == doubleset) {
546             fprintf(fp, "%s %g\n", kp->km_key, *(double *)kp->km_data);
547         } else if (kp->km_func == longset) {
548             fprintf(fp, "%s %ld\n", kp->km_key, *(long *)kp->km_data);
549         } else if (kp->km_func == optionset) {
550             struct option_list *op;
551
552             for (op = Options; op->opt_key; op++) {
553                 if (*op->opt_valuep)
554                     fprintf(fp, "%s %s\n", kp->km_key, op->opt_key);
555             }
556         } else if (kp->km_func == optiondel) {
557             struct option_list *op;
558
559             for (op = Options; op->opt_key; op++) {
560                 if (*op->opt_valuep == 0)
561                     fprintf(fp, "%s %s\n", kp->km_key, op->opt_key);
562             }
563         } else
564             fprintf(fp, "# Unknown format %s\n", kp->km_key);
565     }
566
567     fprintf(fp, "\n");
568     for (ep = empfile; ep < &empfile[EF_MAX]; ep++)
569         fprintf(fp, "# File %s -> %s\n", ep->name, ep->file);
570     for (op = ofiles; op->files; op++)
571         fprintf(fp, "# File %s -> %s\n", op->name, *(op->files));
572
573 }
574
575
576 /* add an option to the list */
577 static void
578 set_option(const char *s)
579 {
580     struct option_list *op;
581
582     for (op = Options; op->opt_key; op++) {
583         if (strcmp(op->opt_key, s) == 0)
584             *op->opt_valuep = 1;
585     }
586 }
587
588 /* delete an option from the list */
589 static void
590 delete_option(const char *s)
591 {
592     struct option_list *op;
593
594     for (op = Options; op->opt_key; op++) {
595         if (strcmp(op->opt_key, s) == 0)
596             *op->opt_valuep = 0;
597     }
598 }
599
600 /* config interface */
601 static void
602 optionset(struct keymatch *kp, s_char **av)
603                                 /* unused - we have a well known global */
604 {
605     char **cpp;
606
607     for (cpp = (char **)av; *cpp; cpp++)
608         set_option(*cpp);
609 }
610
611 /* config interface */
612 static void
613 optiondel(struct keymatch *kp, s_char **av)
614                                 /* unused - we have a well known global */
615 {
616     char **cpp;
617
618     for (cpp = (char **)av; *cpp; cpp++)
619         delete_option(*cpp);
620 }