]> git.pond.sub.org Git - empserver/blob - src/lib/gen/emp_config.c
(new_work, do_feed, prod, newe): Factor out calculation of work into
[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", intset, (caddr_t)&s_p_etu, 0,
100      "Seconds per etu, updates will occur every s_p_etu * etu_per_update seconds"},
101     {"adj_update", intset, (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     {"rollover_avail_max", intset, (caddr_t)&rollover_avail_max, 0,
289      "Maximum avail that can roll over an update"},
290
291     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Nukes"},
292     {"decay_per_etu", doubleset, (caddr_t)&decay_per_etu, 0,
293      "Decay of fallout per ETU"},
294     {"fallout_spread", doubleset, (caddr_t)&fallout_spread, 0,
295      "Amount of fallout that leaks into surrounding sectors"},
296     {"drnuke_const", floatset, (caddr_t)&drnuke_const, 0,
297      "Amount of research to tech needed to build a nuke (if DR_NUKE is on)"},
298
299     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Market/Trade"},
300     {"MARK_DELAY", intset, (caddr_t)&MARK_DELAY, 0,
301      "Number of seconds commodities stay on the market for bidding"},
302     {"TRADE_DELAY", intset, (caddr_t)&TRADE_DELAY, 0,
303      "Number of seconds ships, planes, and units stay on the market for bidding"},
304     {"buytax", doubleset, (caddr_t)&buytax, 0,
305      "Tax (in percentage points) charged to the buyer on market purchases"},
306     {"tradetax", doubleset, (caddr_t)&tradetax, 0,
307      "Amount of a trade transaction the seller makes (the rest is tax)"},
308
309     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Trade ships"},
310     {"trade_1_dist", intset, (caddr_t)&trade_1_dist, 0,
311      "Less than this distance no money for cashing in"},
312     {"trade_2_dist", intset, (caddr_t)&trade_2_dist, 0,
313      "Less than this distance gets trade_1 money for cashing in"},
314     {"trade_3_dist", intset, (caddr_t)&trade_3_dist, 0,
315      "Less than this distance gets trade_2 money for cashing in (>= gets trade_3"},
316     {"trade_1", floatset, (caddr_t)&trade_1, 0,
317      "Return per sector on trade_1 distance amount"},
318     {"trade_2", floatset, (caddr_t)&trade_2, 0,
319      "Return per sector on trade_2 distance amount"},
320     {"trade_3", floatset, (caddr_t)&trade_3, 0,
321      "Return per sector on trade_3 distance amount"},
322     {"trade_ally_bonus", floatset, (caddr_t)&trade_ally_bonus, 0,
323      "Bonus you get for cashing in with an ally"},
324     {"trade_ally_cut", floatset, (caddr_t)&trade_ally_cut, 0,
325      "Bonus your ally gets for you cashing in with them"},
326
327     {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Misc."},
328     {"fuel_mult", intset, (caddr_t)&fuel_mult, 0,
329      "Multiplier for fuel to mobility calculation"},
330     {"lost_items_timeout", intset, (caddr_t)&lost_items_timeout, 0,
331      "Seconds before a lost item is timed out of the database"},
332     {"last_demand_update", longset, (caddr_t)&last_demand_update, 0,
333      "When was the last demand update occured"},
334
335     {NULL, NULL, (caddr_t)0, 0, NULL}
336 };
337
338 static void fixup_files(void);
339 static struct keymatch *keylookup(s_char *key, struct keymatch tbl[]);
340
341
342 /*
343  * read in empire configuration
344  */
345 int
346 emp_config(char *file)
347 {
348     FILE *fp;
349     s_char scanspace[1024];
350     s_char *av[65];
351     char buf[BUFSIZ];
352     struct keymatch *kp;
353
354     if (file == NULL || (fp = fopen(file, "r")) == NULL) {
355         fixup_files();
356         return RET_OK;
357     }
358     while (fgets(buf, sizeof buf, fp) != NULL) {
359         if (buf[0] == '#' || buf[0] == '\n')
360             continue;
361         if (parse(buf, av, 0, scanspace, 0) < 0) {
362             fprintf(stderr, "Can't parse line %s", buf);
363             continue;
364         }
365         if ((kp = keylookup(av[0], configkeys)) != NULL) {
366             (*kp->km_func) (kp, av + 1);
367         } else {
368             fprintf(stderr, "Unknown config key %s\n", av[0]);
369         }
370     }
371     fclose(fp);
372     fixup_files();
373
374     return RET_OK;
375 }
376
377 struct otherfiles {
378     s_char **files;
379     char *name;
380 };
381
382 /* list of other well known files... -maybe tailor these oneday
383  * anyway - meantime they are all relative to datadir */
384 static struct otherfiles ofiles[] = {
385     {&upfil, "up"},
386     {&downfil, "down"},
387     {&disablefil, "disable"},
388     {&banfil, "ban"},
389     {&authfil, "auth"},
390     {&annfil, "ann"},
391     {&timestampfil, "timestamp"},
392     {&teldir, "tel"},
393 #if !defined(_WIN32)
394     {&telfil, "tel/tel"},
395 #else
396     {&telfil, "tel\\tel"},
397 #endif
398     {NULL, NULL}
399 };
400
401 /* fix up the empfile struct to reference full path names */
402 static void
403 fixup_files(void)
404 {
405     struct empfile *ep;
406     struct otherfiles *op;
407     s_char buf[1024];
408
409     for (ep = empfile; ep < &empfile[EF_MAX]; ep++) {
410 #if !defined(_WIN32)
411         sprintf(buf, "%s/%s", datadir, ep->name);
412 #else
413         sprintf(buf, "%s\\%s", datadir, ep->name);
414 #endif
415         ep->file = strdup(buf);
416     }
417
418     for (op = ofiles; op->files; op++) {
419 #if !defined(_WIN32)
420         sprintf(buf, "%s/%s", datadir, op->name);
421 #else
422         sprintf(buf, "%s\\%s", datadir, op->name);
423 #endif
424         *op->files = strdup(buf);
425     }
426 }
427
428 /* find the key in the table */
429 static struct keymatch *
430 keylookup(register s_char *command, struct keymatch *tbl)
431 {
432     register struct keymatch *kp;
433
434     if (command == 0 || *command == 0)
435         return 0;
436     for (kp = tbl; kp->km_key != 0; kp++) {
437         if (strcmp(kp->km_key, command) == 0)
438             return kp;
439     }
440     return NULL;
441 }
442
443 /* worldx int setting function */
444 static void
445 worldxset(struct keymatch *kp, s_char **av)
446 {
447     int *intptr = (int *)kp->km_data;
448
449     if (*av == NULL || intptr == NULL)
450         return;
451     *intptr = atoi(*av);
452     if (!((*intptr % 2) == 0)) {
453         /* Must be div / 2, so subtract one */
454         *intptr = *intptr - 1;
455     }
456 }
457
458 /* generic int setting function */
459 static void
460 intset(struct keymatch *kp, s_char **av)
461 {
462     int *intptr = (int *)kp->km_data;
463
464     if (*av == NULL || intptr == NULL)
465         return;
466     *intptr = atoi(*av);
467 }
468
469 /* generic float set function */
470 static void
471 floatset(struct keymatch *kp, s_char **av)
472 {
473     float *floatptr = (float *)kp->km_data;
474
475     if (*av == NULL || floatptr == NULL)
476         return;
477     *floatptr = atof(*av);
478 }
479
480
481
482 /* generic string set function */
483 static void
484 optstrset(struct keymatch *kp, s_char **av)
485 {
486     s_char **confstrp = (s_char **)kp->km_data;
487
488     if (*av == NULL || confstrp == NULL)
489         return;
490     if (kp->km_flags & KM_ALLOC)
491         free(*confstrp);
492     *confstrp = strdup(*av);
493     kp->km_flags |= KM_ALLOC;
494 }
495
496 /* generic double set function */
497 static void
498 doubleset(struct keymatch *kp, s_char **av)
499 {
500     double *doublep = (double *)kp->km_data;
501
502     if (*av == NULL || doublep == NULL)
503         return;
504     *doublep = atof(*av);
505 }
506
507 /* generic long set function */
508 static void
509 longset(struct keymatch *kp, s_char **av)
510 {
511     long int *longp = (long int *)kp->km_data;
512
513     if (*av == NULL || longp == NULL)
514         return;
515     *longp = atol(*av);
516 }
517
518 void
519 print_config(FILE * fp)
520 {
521     struct empfile *ep;
522     struct otherfiles *op;
523     struct keymatch *kp;
524
525     fprintf(fp, "# Empire Configuration File:\n");
526     for (kp = configkeys; kp->km_key; kp++) {
527         /* We print a few special things here */
528         if (kp->km_comment) {
529             if (kp->km_comment[0]) {
530                 if (kp->km_comment[0] != '\n')
531                     fprintf(fp, "\n# ");
532                 fprintf(fp, "%s\n", kp->km_comment);
533             }
534         }
535         if (!kp->km_key[0])
536             continue;
537         if (kp->km_func == optstrset) {
538             fprintf(fp, "%s \"%s\"\n", kp->km_key,
539                     *(s_char **)kp->km_data);
540         } else if (kp->km_func == intset) {
541             fprintf(fp, "%s %d\n", kp->km_key, *(int *)kp->km_data);
542         } else if (kp->km_func == worldxset) {
543             fprintf(fp, "%s %d\n", kp->km_key, *(int *)kp->km_data);
544         } else if (kp->km_func == floatset) {
545             fprintf(fp, "%s %g\n", kp->km_key, *(float *)kp->km_data);
546         } else if (kp->km_func == doubleset) {
547             fprintf(fp, "%s %g\n", kp->km_key, *(double *)kp->km_data);
548         } else if (kp->km_func == longset) {
549             fprintf(fp, "%s %ld\n", kp->km_key, *(long *)kp->km_data);
550         } else if (kp->km_func == optionset) {
551             struct option_list *op;
552
553             for (op = Options; op->opt_key; op++) {
554                 if (*op->opt_valuep)
555                     fprintf(fp, "%s %s\n", kp->km_key, op->opt_key);
556             }
557         } else if (kp->km_func == optiondel) {
558             struct option_list *op;
559
560             for (op = Options; op->opt_key; op++) {
561                 if (*op->opt_valuep == 0)
562                     fprintf(fp, "%s %s\n", kp->km_key, op->opt_key);
563             }
564         } else
565             fprintf(fp, "# Unknown format %s\n", kp->km_key);
566     }
567
568     fprintf(fp, "\n");
569     for (ep = empfile; ep < &empfile[EF_MAX]; ep++)
570         fprintf(fp, "# File %s -> %s\n", ep->name, ep->file);
571     for (op = ofiles; op->files; op++)
572         fprintf(fp, "# File %s -> %s\n", op->name, *(op->files));
573
574 }
575
576
577 /* add an option to the list */
578 static void
579 set_option(const char *s)
580 {
581     struct option_list *op;
582
583     for (op = Options; op->opt_key; op++) {
584         if (strcmp(op->opt_key, s) == 0) {
585             *op->opt_valuep = 1;
586             return;
587         }
588     }
589     fprintf(stderr, "Unknown option %s\n", s);
590 }
591
592 /* delete an option from the list */
593 static void
594 delete_option(const char *s)
595 {
596     struct option_list *op;
597
598     for (op = Options; op->opt_key; op++) {
599         if (strcmp(op->opt_key, s) == 0) {
600             *op->opt_valuep = 0;
601             return;
602         }
603     }
604     fprintf(stderr, "Unknown option %s\n", s);
605 }
606
607 /* config interface */
608 static void
609 optionset(struct keymatch *kp, s_char **av)
610                                 /* unused - we have a well known global */
611 {
612     char **cpp;
613
614     for (cpp = (char **)av; *cpp; cpp++)
615         set_option(*cpp);
616 }
617
618 /* config interface */
619 static void
620 optiondel(struct keymatch *kp, s_char **av)
621                                 /* unused - we have a well known global */
622 {
623     char **cpp;
624
625     for (cpp = (char **)av; *cpp; cpp++)
626         delete_option(*cpp);
627 }