Fix division by zero when unit activity rate is zero
[freeciv.git] / server / settings.c
blobfb9cd63f2dfe6998f6f024c8bca518b7820a605f
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996-2004 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "astring.h"
20 #include "fcintl.h"
21 #include "game.h"
22 #include "ioz.h"
23 #include "log.h"
24 #include "registry.h"
25 #include "shared.h"
26 #include "string_vector.h"
28 /* common */
29 #include "map.h"
31 /* server */
32 #include "gamehand.h"
33 #include "maphand.h"
34 #include "notify.h"
35 #include "plrhand.h"
36 #include "report.h"
37 #include "rssanity.h"
38 #include "settings.h"
39 #include "srv_main.h"
40 #include "stdinhand.h"
42 /* The following classes determine what can be changed when.
43 * Actually, some of them have the same "changeability", but
44 * different types are separated here in case they have
45 * other uses.
46 * Also, SSET_GAME_INIT/SSET_RULES separate the two sections
47 * of server settings sent to the client.
48 * See the settings[] array and setting_is_changeable() for what
49 * these correspond to and explanations.
51 enum sset_class {
52 SSET_MAP_SIZE,
53 SSET_MAP_GEN,
54 SSET_MAP_ADD,
55 SSET_PLAYERS,
56 SSET_GAME_INIT,
57 SSET_RULES,
58 SSET_RULES_SCENARIO,
59 SSET_RULES_FLEXIBLE,
60 SSET_META
63 typedef bool (*bool_validate_func_t) (bool value, struct connection *pconn,
64 char *reject_msg,
65 size_t reject_msg_len);
66 typedef bool (*int_validate_func_t) (int value, struct connection *pconn,
67 char *reject_msg,
68 size_t reject_msg_len);
69 typedef bool (*string_validate_func_t) (const char * value,
70 struct connection *pconn,
71 char *reject_msg,
72 size_t reject_msg_len);
73 typedef bool (*enum_validate_func_t) (int value, struct connection *pconn,
74 char *reject_msg,
75 size_t reject_msg_len);
76 typedef bool (*bitwise_validate_func_t) (unsigned value,
77 struct connection *pconn,
78 char *reject_msg,
79 size_t reject_msg_len);
81 typedef void (*action_callback_func_t) (const struct setting *pset);
82 typedef const char *(*help_callback_func_t) (const struct setting *pset);
83 typedef const struct sset_val_name * (*val_name_func_t) (int value);
85 struct setting {
86 const char *name;
87 enum sset_class sclass;
88 bool to_client;
91 * Should be less than 42 chars (?), or shorter if the values may
92 * have more than about 4 digits. Don't put "." on the end.
94 const char *short_help;
97 * May be empty string, if short_help is sufficient. Need not
98 * include embedded newlines (but may, for formatting); lines will
99 * be wrapped (and indented) automatically. Should have punctuation
100 * etc, and should end with a "."
102 const char *extra_help;
104 /* help function */
105 const help_callback_func_t help_func;
107 enum sset_type stype;
108 enum sset_category scategory;
109 enum sset_level slevel;
112 * About the *_validate functions: If the function is non-NULL, it
113 * is called with the new value, and returns whether the change is
114 * legal. The char * is an error message in the case of reject.
117 union {
118 /*** bool part ***/
119 struct {
120 bool *const pvalue;
121 const bool default_value;
122 const bool_validate_func_t validate;
123 const val_name_func_t name;
124 bool game_value;
125 } boolean;
126 /*** int part ***/
127 struct {
128 int *const pvalue;
129 const int default_value;
130 const int min_value;
131 const int max_value;
132 const int_validate_func_t validate;
133 int game_value;
134 } integer;
135 /*** string part ***/
136 struct {
137 char *const value;
138 const char *const default_value;
139 const size_t value_size;
140 const string_validate_func_t validate;
141 char *game_value;
142 } string;
143 /*** enumerator part ***/
144 struct {
145 void *const pvalue;
146 const int store_size;
147 const int default_value;
148 const enum_validate_func_t validate;
149 const val_name_func_t name;
150 int game_value;
151 } enumerator;
152 /*** bitwise part ***/
153 struct {
154 unsigned *const pvalue;
155 const unsigned default_value;
156 const bitwise_validate_func_t validate;
157 const val_name_func_t name;
158 unsigned game_value;
159 } bitwise;
162 /* action function */
163 const action_callback_func_t action;
165 /* ruleset lock for game settings */
166 bool locked;
168 /* It's not "default", even if value is the same as default */
169 enum setting_default_level setdef;
172 static struct {
173 bool init;
174 struct setting_list *level[OLEVELS_NUM];
175 } setting_sorted = { .init = FALSE };
177 static bool setting_ruleset_one(struct section_file *file,
178 const char *name, const char *path);
179 static void setting_game_set(struct setting *pset, bool init);
180 static void setting_game_free(struct setting *pset);
181 static void setting_game_restore(struct setting *pset);
183 static void settings_list_init(void);
184 static void settings_list_free(void);
185 int settings_list_cmp(const struct setting *const *pset1,
186 const struct setting *const *pset2);
188 #define settings_snprintf(_buf, _buf_len, format, ...) \
189 if (_buf != NULL) { \
190 fc_snprintf(_buf, _buf_len, format, ## __VA_ARGS__); \
193 static bool set_enum_value(struct setting *pset, int val);
195 /****************************************************************************
196 Enumerator name accessors.
198 Important note about compatibility:
199 1) you cannot modify the support name of an existant value. However, in a
200 developpement, you can modify it if it wasn't included in any stable
201 branch before.
202 2) Take care of modifiying the pretty name of an existant value: make sure
203 to modify the help texts which are using it.
204 ****************************************************************************/
206 #define NAME_CASE(_val, _support, _pretty) \
207 case _val: \
209 static const struct sset_val_name name = { _support, _pretty }; \
210 return &name; \
213 /****************************************************************************
214 Map size definition setting names accessor. This setting has an
215 hard-coded depedence in "server/meta.c".
216 ****************************************************************************/
217 static const struct sset_val_name *mapsize_name(int mapsize)
219 switch (mapsize) {
220 NAME_CASE(MAPSIZE_FULLSIZE, "FULLSIZE", N_("Number of tiles"));
221 NAME_CASE(MAPSIZE_PLAYER, "PLAYER", N_("Tiles per player"));
222 NAME_CASE(MAPSIZE_XYSIZE, "XYSIZE", N_("Width and height"));
224 return NULL;
227 /****************************************************************************
228 Topology setting names accessor.
229 ****************************************************************************/
230 static const struct sset_val_name *topology_name(int topology_bit)
232 switch (1 << topology_bit) {
233 NAME_CASE(TF_WRAPX, "WRAPX", N_("Wrap East-West"));
234 NAME_CASE(TF_WRAPY, "WRAPY", N_("Wrap North-South"));
235 NAME_CASE(TF_ISO, "ISO", N_("Isometric"));
236 NAME_CASE(TF_HEX, "HEX", N_("Hexagonal"));
238 return NULL;
241 /****************************************************************************
242 Generator setting names accessor.
243 ****************************************************************************/
244 static const struct sset_val_name *generator_name(int generator)
246 switch (generator) {
247 NAME_CASE(MAPGEN_SCENARIO, "SCENARIO", N_("Scenario map"));
248 NAME_CASE(MAPGEN_RANDOM, "RANDOM", N_("Fully random height"));
249 NAME_CASE(MAPGEN_FRACTAL, "FRACTAL", N_("Pseudo-fractal height"));
250 NAME_CASE(MAPGEN_ISLAND, "ISLAND", N_("Island-based"));
251 NAME_CASE(MAPGEN_FAIR, "FAIR", N_("Fair islands"));
253 return NULL;
256 /****************************************************************************
257 Start position setting names accessor.
258 ****************************************************************************/
259 static const struct sset_val_name *startpos_name(int startpos)
261 switch (startpos) {
262 NAME_CASE(MAPSTARTPOS_DEFAULT, "DEFAULT",
263 N_("Generator's choice"));
264 NAME_CASE(MAPSTARTPOS_SINGLE, "SINGLE",
265 N_("One player per continent"));
266 NAME_CASE(MAPSTARTPOS_2or3, "2or3",
267 N_("Two or three players per continent"));
268 NAME_CASE(MAPSTARTPOS_ALL, "ALL",
269 N_("All players on a single continent"));
270 NAME_CASE(MAPSTARTPOS_VARIABLE, "VARIABLE",
271 N_("Depending on size of continents"));
273 return NULL;
276 /****************************************************************************
277 Team placement setting names accessor.
278 ****************************************************************************/
279 static const struct sset_val_name *teamplacement_name(int team_placement)
281 switch (team_placement) {
282 NAME_CASE(TEAM_PLACEMENT_DISABLED, "DISABLED",
283 N_("Disabled"));
284 NAME_CASE(TEAM_PLACEMENT_CLOSEST, "CLOSEST",
285 N_("As close as possible"));
286 NAME_CASE(TEAM_PLACEMENT_CONTINENT, "CONTINENT",
287 N_("On the same continent"));
288 NAME_CASE(TEAM_PLACEMENT_HORIZONTAL, "HORIZONTAL",
289 N_("Horizontal placement"));
290 NAME_CASE(TEAM_PLACEMENT_VERTICAL, "VERTICAL",
291 N_("Vertical placement"));
293 return NULL;
296 /****************************************************************************
297 Persistentready setting names accessor.
298 ****************************************************************************/
299 static const struct sset_val_name *persistentready_name(int persistent_ready)
301 switch (persistent_ready) {
302 NAME_CASE(PERSISTENTR_DISABLED, "DISABLED",
303 N_("Disabled"));
304 NAME_CASE(PERSISTENTR_CONNECTED, "CONNECTED",
305 N_("As long as connected"));
308 return NULL;
311 /****************************************************************************
312 Victory conditions setting names accessor.
313 ****************************************************************************/
314 static const struct sset_val_name *victory_conditions_name(int condition_bit)
316 switch (condition_bit) {
317 NAME_CASE(VC_SPACERACE, "SPACERACE", N_("Spacerace"));
318 NAME_CASE(VC_ALLIED, "ALLIED", N_("Allied victory"));
319 NAME_CASE(VC_CULTURE, "CULTURE", N_("Culture victory"));
322 return NULL;
325 /****************************************************************************
326 Autosaves setting names accessor.
327 ****************************************************************************/
328 static const struct sset_val_name *autosaves_name(int autosaves_bit)
330 switch (autosaves_bit) {
331 NAME_CASE(AS_TURN, "TURN", N_("New turn"));
332 NAME_CASE(AS_GAME_OVER, "GAMEOVER", N_("Game over"));
333 NAME_CASE(AS_QUITIDLE, "QUITIDLE", N_("No player connections"));
334 NAME_CASE(AS_INTERRUPT, "INTERRUPT", N_("Server interrupted"));
335 NAME_CASE(AS_TIMER, "TIMER", N_("Timer"));
338 return NULL;
341 /****************************************************************************
342 Borders setting names accessor.
343 ****************************************************************************/
344 static const struct sset_val_name *borders_name(int borders)
346 switch (borders) {
347 NAME_CASE(BORDERS_DISABLED, "DISABLED", N_("Disabled"));
348 NAME_CASE(BORDERS_ENABLED, "ENABLED", N_("Enabled"));
349 NAME_CASE(BORDERS_SEE_INSIDE, "SEE_INSIDE",
350 N_("See everything inside borders"));
351 NAME_CASE(BORDERS_EXPAND, "EXPAND",
352 N_("Borders expand to unknown, revealing tiles"));
354 return NULL;
357 /****************************************************************************
358 Trait distribution setting names accessor.
359 ****************************************************************************/
360 static const struct sset_val_name *trait_dist_name(int trait_dist)
362 switch (trait_dist) {
363 NAME_CASE(TDM_FIXED, "FIXED", N_("Fixed"));
364 NAME_CASE(TDM_EVEN, "EVEN", N_("Even"));
366 return NULL;
369 /****************************************************************************
370 Player colors configuration setting names accessor.
371 ****************************************************************************/
372 static const struct sset_val_name *plrcol_name(int plrcol)
374 switch (plrcol) {
375 NAME_CASE(PLRCOL_PLR_ORDER, "PLR_ORDER", N_("Per-player, in order"));
376 NAME_CASE(PLRCOL_PLR_RANDOM, "PLR_RANDOM", N_("Per-player, random"));
377 NAME_CASE(PLRCOL_PLR_SET, "PLR_SET", N_("Set manually"));
378 NAME_CASE(PLRCOL_TEAM_ORDER, "TEAM_ORDER", N_("Per-team, in order"));
379 NAME_CASE(PLRCOL_NATION_ORDER, "NATION_ORDER", N_("Per-nation, in order"));
381 return NULL;
384 /****************************************************************************
385 Happyborders setting names accessor.
386 ****************************************************************************/
387 static const struct sset_val_name *happyborders_name(int happyborders)
389 switch (happyborders) {
390 NAME_CASE(HB_DISABLED, "DISABLED", N_("Borders are not helping"));
391 NAME_CASE(HB_NATIONAL, "NATIONAL", N_("Happy within own borders"));
392 NAME_CASE(HB_ALLIANCE, "ALLIED", N_("Happy within allied borders"));
394 return NULL;
397 /****************************************************************************
398 Diplomacy setting names accessor.
399 ****************************************************************************/
400 static const struct sset_val_name *diplomacy_name(int diplomacy)
402 switch (diplomacy) {
403 NAME_CASE(DIPLO_FOR_ALL, "ALL", N_("Enabled for everyone"));
404 NAME_CASE(DIPLO_FOR_HUMANS, "HUMAN",
405 N_("Only allowed between human players"));
406 NAME_CASE(DIPLO_FOR_AIS, "AI", N_("Only allowed between AI players"));
407 NAME_CASE(DIPLO_NO_AIS, "NOAI", N_("Only allowed when human involved"));
408 NAME_CASE(DIPLO_NO_MIXED, "NOMIXED", N_("Only allowed between two humans, or two AI players"));
409 NAME_CASE(DIPLO_FOR_TEAMS, "TEAM", N_("Restricted to teams"));
410 NAME_CASE(DIPLO_DISABLED, "DISABLED", N_("Disabled for everyone"));
412 return NULL;
415 /****************************************************************************
416 City names setting names accessor.
417 ****************************************************************************/
418 static const struct sset_val_name *citynames_name(int citynames)
420 switch (citynames) {
421 NAME_CASE(CNM_NO_RESTRICTIONS, "NO_RESTRICTIONS", N_("No restrictions"));
422 NAME_CASE(CNM_PLAYER_UNIQUE, "PLAYER_UNIQUE", N_("Unique to a player"));
423 NAME_CASE(CNM_GLOBAL_UNIQUE, "GLOBAL_UNIQUE", N_("Globally unique"));
424 NAME_CASE(CNM_NO_STEALING, "NO_STEALING", N_("No city name stealing"));
426 return NULL;
429 /****************************************************************************
430 Barbarian setting names accessor.
431 ****************************************************************************/
432 static const struct sset_val_name *barbarians_name(int barbarians)
434 switch (barbarians) {
435 NAME_CASE(BARBS_DISABLED, "DISABLED", N_("No barbarians"));
436 NAME_CASE(BARBS_HUTS_ONLY, "HUTS_ONLY", N_("Only in huts"));
437 NAME_CASE(BARBS_NORMAL, "NORMAL", N_("Normal rate of appearance"));
438 NAME_CASE(BARBS_FREQUENT, "FREQUENT", N_("Frequent barbarian uprising"));
439 NAME_CASE(BARBS_HORDES, "HORDES", N_("Raging hordes"));
441 return NULL;
444 /****************************************************************************
445 Revolution length type setting names accessor.
446 ****************************************************************************/
447 static const struct sset_val_name *revolentype_name(int revolentype)
449 switch (revolentype) {
450 NAME_CASE(REVOLEN_FIXED, "FIXED", N_("Fixed to 'revolen' turns"));
451 NAME_CASE(REVOLEN_RANDOM, "RANDOM", N_("Randomly 1-'revolen' turns"));
452 NAME_CASE(REVOLEN_QUICKENING, "QUICKENING", N_("First time 'revolen', then always quicker"));
453 NAME_CASE(REVOLEN_RANDQUICK, "RANDQUICK", N_("Random, max always quicker"));
455 return NULL;
458 /****************************************************************************
459 Revealmap setting names accessor.
460 ****************************************************************************/
461 static const struct sset_val_name *revealmap_name(int bit)
463 switch (1 << bit) {
464 NAME_CASE(REVEAL_MAP_START, "START", N_("Reveal map at game start"));
465 NAME_CASE(REVEAL_MAP_DEAD, "DEAD", N_("Unfog map for dead players"));
467 return NULL;
470 /****************************************************************************
471 Airlifting style setting names accessor.
472 ****************************************************************************/
473 static const struct sset_val_name *airliftingstyle_name(int bit)
475 switch (1 << bit) {
476 NAME_CASE(AIRLIFTING_ALLIED_SRC, "FROM_ALLIES",
477 N_("Allows units to be airlifted from allied cities"));
478 NAME_CASE(AIRLIFTING_ALLIED_DEST, "TO_ALLIES",
479 N_("Allows units to be airlifted to allied cities"));
480 NAME_CASE(AIRLIFTING_UNLIMITED_SRC, "SRC_UNLIMITED",
481 N_("Unlimited units from source city"));
482 NAME_CASE(AIRLIFTING_UNLIMITED_DEST, "DEST_UNLIMITED",
483 N_("Unlimited units to destination city"));
485 return NULL;
488 /****************************************************************************
489 Phase mode names accessor.
490 ****************************************************************************/
491 static const struct sset_val_name *phasemode_name(int phasemode)
493 switch (phasemode) {
494 NAME_CASE(PMT_CONCURRENT, "ALL", N_("All players move concurrently"));
495 NAME_CASE(PMT_PLAYERS_ALTERNATE,
496 "PLAYER", N_("All players alternate movement"));
497 NAME_CASE(PMT_TEAMS_ALTERNATE, "TEAM", N_("Team alternate movement"));
499 return NULL;
502 /****************************************************************************
503 Scorelog level names accessor.
504 ****************************************************************************/
505 static const struct sset_val_name *
506 scoreloglevel_name(enum scorelog_level sl_level)
508 switch (sl_level) {
509 NAME_CASE(SL_ALL, "ALL", N_("All players"));
510 NAME_CASE(SL_HUMANS, "HUMANS", N_("Human players only"));
512 return NULL;
515 /****************************************************************************
516 Savegame compress type names accessor.
517 ****************************************************************************/
518 static const struct sset_val_name *
519 compresstype_name(enum fz_method compresstype)
521 switch (compresstype) {
522 NAME_CASE(FZ_PLAIN, "PLAIN", N_("No compression"));
523 #ifdef FREECIV_HAVE_LIBZ
524 NAME_CASE(FZ_ZLIB, "LIBZ", N_("Using zlib (gzip format)"));
525 #endif
526 #ifdef FREECIV_HAVE_LIBBZ2
527 NAME_CASE(FZ_BZIP2, "BZIP2", N_("Using bzip2"));
528 #endif
529 #ifdef FREECIV_HAVE_LIBLZMA
530 NAME_CASE(FZ_XZ, "XZ", N_("Using xz"));
531 #endif
533 return NULL;
536 /****************************************************************************
537 Names accessor for boolean settings (disable/enable).
538 ****************************************************************************/
539 static const struct sset_val_name *bool_name(int enable)
541 switch (enable) {
542 NAME_CASE(FALSE, "DISABLED", N_("disabled"));
543 NAME_CASE(TRUE, "ENABLED", N_("enabled"));
545 return NULL;
548 #undef NAME_CASE
550 /*************************************************************************
551 Help callback functions.
552 *************************************************************************/
554 /*************************************************************************
555 Help about phasemode setting
556 *************************************************************************/
557 static const char *phasemode_help(const struct setting *pset)
559 static char pmhelp[512];
561 /* Translated here */
562 fc_snprintf(pmhelp, sizeof(pmhelp),
563 _("This setting controls whether players may make "
564 "moves at the same time during a turn. Change "
565 "in setting takes effect next turn. Currently, at least "
566 "to the end of this turn, mode is \"%s\"."),
567 phasemode_name(game.info.phase_mode)->pretty);
569 return pmhelp;
572 /*************************************************************************
573 Help about huts setting
574 *************************************************************************/
575 static const char *huts_help(const struct setting *pset)
577 if (game.map.server.huts_absolute >= 0) {
578 static char hutshelp[512];
580 /* Translated here */
581 fc_snprintf(hutshelp, sizeof(hutshelp),
582 _("%s\n"
583 "Currently this is being overridden by absolute "
584 "number of huts set to %d. Explicitly set this "
585 "setting again to make it take effect instead."),
586 _(pset->extra_help), game.map.server.huts_absolute);
588 return hutshelp;
591 return pset->extra_help;
594 /*************************************************************************
595 Action callback functions.
596 *************************************************************************/
598 /*************************************************************************
599 (De)initialze the score log.
600 *************************************************************************/
601 static void scorelog_action(const struct setting *pset)
603 if (*pset->boolean.pvalue) {
604 log_civ_score_init();
605 } else {
606 log_civ_score_free();
610 /*************************************************************************
611 Create the selected number of AI's.
612 *************************************************************************/
613 static void aifill_action(const struct setting *pset)
615 const char *msg = aifill(*pset->integer.pvalue);
616 if (msg) {
617 log_normal(_("Warning: aifill not met: %s."), msg);
618 notify_conn(NULL, NULL, E_SETTING, ftc_server,
619 _("Warning: aifill not met: %s."), msg);
623 /*************************************************************************
624 Restrict to the selected nation set.
625 *************************************************************************/
626 static void nationset_action(const struct setting *pset)
628 /* If any player's existing selection is invalid, abort it */
629 players_iterate(pplayer) {
630 if (pplayer->nation != NULL) {
631 if (!nation_is_in_current_set(pplayer->nation)) {
632 (void) player_set_nation(pplayer, NO_NATION_SELECTED);
633 send_player_info_c(pplayer, game.est_connections);
636 } players_iterate_end;
637 count_playable_nations();
638 (void) aifill(game.info.aifill);
640 /* There might now be too many players for the available nations.
641 * Rather than getting rid of some players arbitrarily, we let the
642 * situation persist for all already-connected players; the server
643 * will simply refuse to start until someone reduces the number of
644 * players. This policy also avoids annoyance if nationset is
645 * accidentally and transiently set to an unintended value.
646 * (However, new connections will start out detached.) */
647 if (normal_player_count() > server.playable_nations) {
648 notify_conn(NULL, NULL, E_SETTING, ftc_server, "%s",
649 _("Warning: not enough nations in this nation set "
650 "for all current players."));
653 send_nation_availability(game.est_connections, TRUE);
656 /*************************************************************************
657 Clear any user-set player colors in modes other than PLRCOL_PLR_SET.
658 *************************************************************************/
659 static void plrcol_action(const struct setting *pset)
661 if (!game_was_started()) {
662 if (read_enum_value(pset) != PLRCOL_PLR_SET) {
663 players_iterate(pplayer) {
664 server_player_set_color(pplayer, NULL);
665 } players_iterate_end;
667 /* Update clients with new color scheme. */
668 send_player_info_c(NULL, NULL);
672 /*************************************************************************
673 Toggle player AI status.
674 *************************************************************************/
675 static void autotoggle_action(const struct setting *pset)
677 if (*pset->boolean.pvalue) {
678 players_iterate(pplayer) {
679 if (!pplayer->ai_controlled && !pplayer->is_connected) {
680 toggle_ai_player_direct(NULL, pplayer);
681 send_player_info_c(pplayer, game.est_connections);
683 } players_iterate_end;
687 /*************************************************************************
688 Enact a change in the 'timeout' server setting immediately, if the game
689 is afoot.
690 *************************************************************************/
691 static void timeout_action(const struct setting *pset)
693 if (S_S_RUNNING == server_state()) {
694 int timeout = *pset->integer.pvalue;
696 if (game.info.turn != 0 || game.info.first_timeout == -1) {
697 /* This may cause the current turn to end immediately. */
698 game.tinfo.seconds_to_phasedone = timeout;
700 send_game_info(NULL);
704 /*************************************************************************
705 Enact a change in the 'first_timeout' server setting immediately, if the game
706 is afoot.
707 *************************************************************************/
708 static void first_timeout_action(const struct setting *pset)
710 if (S_S_RUNNING == server_state()) {
711 int timeout = *pset->integer.pvalue;
713 if (game.info.turn == 0) {
714 /* This may cause the current turn to end immediately. */
715 if (timeout != -1) {
716 game.tinfo.seconds_to_phasedone = timeout;
717 } else {
718 game.tinfo.seconds_to_phasedone = game.info.timeout;
721 send_game_info(NULL);
725 /*************************************************************************
726 Clean out absolute number of huts when relative setting set.
727 *************************************************************************/
728 static void huts_action(const struct setting *pset)
730 game.map.server.huts_absolute = -1;
733 /*************************************************************************
734 Topology setting changed.
735 *************************************************************************/
736 static void topology_action(const struct setting *pset)
738 struct packet_set_topology packet;
740 packet.topology_id = *pset->integer.pvalue;
742 conn_list_iterate(game.est_connections, pconn) {
743 send_packet_set_topology(pconn, &packet);
744 } conn_list_iterate_end;
747 /*************************************************************************
748 Validation callback functions.
749 *************************************************************************/
751 /****************************************************************************
752 Verify the selected savename definition.
753 ****************************************************************************/
754 static bool savename_validate(const char *value, struct connection *caller,
755 char *reject_msg, size_t reject_msg_len)
757 char buf[MAX_LEN_PATH];
759 generate_save_name(value, buf, sizeof(buf), NULL);
761 if (!is_safe_filename(buf)) {
762 settings_snprintf(reject_msg, reject_msg_len,
763 _("Invalid save name definition: '%s' "
764 "(resolves to '%s')."), value, buf);
765 return FALSE;
768 return TRUE;
771 /****************************************************************************
772 Verify the value of the generator option (notably the MAPGEN_SCENARIO
773 case).
774 ****************************************************************************/
775 static bool generator_validate(int value, struct connection *caller,
776 char *reject_msg, size_t reject_msg_len)
778 if (map_is_empty()) {
779 if (MAPGEN_SCENARIO == value
780 && (NULL != caller || !game.scenario.is_scenario)) {
781 settings_snprintf(reject_msg, reject_msg_len,
782 _("You cannot disable the map generator."));
783 return FALSE;
785 return TRUE;
786 } else {
787 if (MAPGEN_SCENARIO != value) {
788 settings_snprintf(reject_msg, reject_msg_len,
789 _("You cannot require a map generator "
790 "when a map is loaded."));
791 return FALSE;
794 return TRUE;
797 /****************************************************************************
798 Verify the name for the score log file.
799 ****************************************************************************/
800 static bool scorefile_validate(const char *value, struct connection *caller,
801 char *reject_msg, size_t reject_msg_len)
803 if (!is_safe_filename(value)) {
804 settings_snprintf(reject_msg, reject_msg_len,
805 _("Invalid score name definition: '%s'."), value);
806 return FALSE;
809 return TRUE;
812 /*************************************************************************
813 Verify that a given demography string is valid. See
814 game.demography.
815 *************************************************************************/
816 static bool demography_callback(const char *value,
817 struct connection *caller,
818 char *reject_msg,
819 size_t reject_msg_len)
821 int error;
823 if (is_valid_demography(value, &error)) {
824 return TRUE;
825 } else {
826 settings_snprintf(reject_msg, reject_msg_len,
827 _("Demography string validation failed at character: "
828 "'%c'. Try \"/help demography\"."), value[error]);
829 return FALSE;
833 /*************************************************************************
834 Autosaves setting callback
835 *************************************************************************/
836 static bool autosaves_callback(unsigned value, struct connection *caller,
837 char *reject_msg, size_t reject_msg_len)
839 if (S_S_RUNNING == server_state()) {
840 if ((value & (1 << AS_TIMER))
841 && !(game.server.autosaves & (1 << AS_TIMER))) {
842 game.server.save_timer = timer_renew(game.server.save_timer,
843 TIMER_USER, TIMER_ACTIVE);
844 timer_start(game.server.save_timer);
845 } else if (!(value & (1 << AS_TIMER))
846 && (game.server.autosaves & (1 << AS_TIMER))) {
847 timer_stop(game.server.save_timer);
848 timer_destroy(game.server.save_timer);
849 game.server.save_timer = NULL;
853 return TRUE;
856 /*************************************************************************
857 Verify that a given allowtake string is valid. See
858 game.allow_take.
859 *************************************************************************/
860 static bool allowtake_callback(const char *value,
861 struct connection *caller,
862 char *reject_msg,
863 size_t reject_msg_len)
865 int len = strlen(value), i;
866 bool havecharacter_state = FALSE;
868 /* We check each character individually to see if it's valid. This
869 * does not check for duplicate entries.
871 * We also track the state of the machine. havecharacter_state is
872 * true if the preceeding character was a primary label, e.g.
873 * NHhAadb. It is false if the preceeding character was a modifier
874 * or if this is the first character. */
876 for (i = 0; i < len; i++) {
877 /* Check to see if the character is a primary label. */
878 if (strchr("HhAadbOo", value[i])) {
879 havecharacter_state = TRUE;
880 continue;
883 /* If we've already passed a primary label, check to see if the
884 * character is a modifier. */
885 if (havecharacter_state && strchr("1234", value[i])) {
886 havecharacter_state = FALSE;
887 continue;
890 /* Looks like the character was invalid. */
891 settings_snprintf(reject_msg, reject_msg_len,
892 _("Allowed take string validation failed at "
893 "character: '%c'. Try \"/help allowtake\"."),
894 value[i]);
895 return FALSE;
898 /* All characters were valid. */
899 return TRUE;
902 /*************************************************************************
903 Verify that a given startunits string is valid. See
904 game.server.start_units.
905 *************************************************************************/
906 static bool startunits_callback(const char *value,
907 struct connection *caller,
908 char *reject_msg,
909 size_t reject_msg_len)
911 int len = strlen(value), i;
912 Unit_Class_id first_role;
913 bool firstnative = FALSE;
915 /* We check each character individually to see if it's valid. */
916 for (i = 0; i < len; i++) {
917 if (strchr("cwxksfdDaA", value[i])) {
918 continue;
921 /* Looks like the character was invalid. */
922 settings_snprintf(reject_msg, reject_msg_len,
923 _("Starting units string validation failed at "
924 "character '%c'. Try \"/help startunits\"."),
925 value[i]);
926 return FALSE;
929 /* Check the first character to make sure it can use a startpos. */
930 first_role = uclass_index(utype_class(get_role_unit(
931 crole_to_role_id(value[0]), 0)));
932 terrain_type_iterate(pterrain) {
933 if (terrain_has_flag(pterrain, TER_STARTER)
934 && BV_ISSET(pterrain->native_to, first_role)) {
935 firstnative = TRUE;
936 break;
938 } terrain_type_iterate_end;
940 if (!firstnative) {
941 /* Loading would cause an infinite loop hunting for a valid startpos. */
942 settings_snprintf(reject_msg, reject_msg_len,
943 _("The first starting unit must be native to at "
944 "least one \"Starter\" terrain. "
945 "Try \"/help startunits\"."));
946 return FALSE;
949 /* Everything seems fine. */
950 return TRUE;
953 /*************************************************************************
954 Verify that a given endturn is valid.
955 *************************************************************************/
956 static bool endturn_callback(int value, struct connection *caller,
957 char *reject_msg, size_t reject_msg_len)
959 if (value < game.info.turn) {
960 /* Tried to set endturn earlier than current turn */
961 settings_snprintf(reject_msg, reject_msg_len,
962 _("Cannot set endturn earlier than current turn."));
963 return FALSE;
965 return TRUE;
968 /*************************************************************************
969 Verify that a given maxplayers is valid.
970 *************************************************************************/
971 static bool maxplayers_callback(int value, struct connection *caller,
972 char *reject_msg, size_t reject_msg_len)
974 if (value < player_count()) {
975 settings_snprintf(reject_msg, reject_msg_len,
976 _("Number of players (%d) is higher than requested "
977 "value (%d). Keeping old value."), player_count(),
978 value);
979 return FALSE;
981 /* If any start positions are defined by a scenario, we can only
982 * accommodate as many players as we have start positions. */
983 if (0 < map_startpos_count() && value > map_startpos_count()) {
984 settings_snprintf(reject_msg, reject_msg_len,
985 _("Requested value (%d) is greater than number of "
986 "available start positions (%d). Keeping old value."),
987 value, map_startpos_count());
988 return FALSE;
991 return TRUE;
994 /*************************************************************************
995 Validate the 'nationset' server setting.
996 *************************************************************************/
997 static bool nationset_callback(const char *value,
998 struct connection *caller,
999 char *reject_msg,
1000 size_t reject_msg_len)
1002 if (strlen(value) == 0) {
1003 return TRUE;
1004 } else if (nation_set_by_rule_name(value)) {
1005 return TRUE;
1006 } else {
1007 settings_snprintf(reject_msg, reject_msg_len,
1008 /* TRANS: do not translate 'list nationsets' */
1009 _("Unknown nation set \"%s\". See '%slist nationsets' "
1010 "for possible values."), value, caller ? "/" : "");
1011 return FALSE;
1015 /*************************************************************************
1016 Validate the 'timeout' server setting.
1017 *************************************************************************/
1018 static bool timeout_callback(int value, struct connection *caller,
1019 char *reject_msg, size_t reject_msg_len)
1021 /* Disallow low timeout values for non-hack connections. */
1022 if (caller && caller->access_level < ALLOW_HACK && value < 30) {
1023 settings_snprintf(reject_msg, reject_msg_len,
1024 _("You are not allowed to set timeout values less "
1025 "than 30 seconds."));
1026 return FALSE;
1029 if (value == -1 && game.server.unitwaittime != 0) {
1030 /* autogame only with 'unitwaittime' = 0 */
1031 settings_snprintf(reject_msg, reject_msg_len,
1032 /* TRANS: Do not translate setting names in ''. */
1033 _("For autogames ('timeout' = -1) 'unitwaittime' "
1034 "should be deactivated (= 0)."));
1035 return FALSE;
1038 if (value > 0 && value < game.server.unitwaittime * 3 / 2) {
1039 /* for normal games 'timeout' should be at least 3/2 times the value
1040 * of 'unitwaittime' */
1041 settings_snprintf(reject_msg, reject_msg_len,
1042 /* TRANS: Do not translate setting names in ''. */
1043 _("'timeout' can not be lower than 3/2 of the "
1044 "'unitwaittime' setting (= %d). Please change "
1045 "'unitwaittime' first."), game.server.unitwaittime);
1046 return FALSE;
1049 return TRUE;
1052 /*************************************************************************
1053 Validate the 'first_timeout' server setting.
1054 *************************************************************************/
1055 static bool first_timeout_callback(int value, struct connection *caller,
1056 char *reject_msg, size_t reject_msg_len)
1058 /* Disallow low timeout values for non-hack connections. */
1059 if (caller && caller->access_level < ALLOW_HACK && value < 30) {
1060 settings_snprintf(reject_msg, reject_msg_len,
1061 _("You are not allowed to set timeout values less "
1062 "than 30 seconds."));
1063 return FALSE;
1066 return TRUE;
1069 /*************************************************************************
1070 Check 'timeout' setting if 'unitwaittime' is changed.
1071 *************************************************************************/
1072 static bool unitwaittime_callback(int value, struct connection *caller,
1073 char *reject_msg, size_t reject_msg_len)
1075 if (game.info.timeout == -1 && value != 0) {
1076 settings_snprintf(reject_msg, reject_msg_len,
1077 /* TRANS: Do not translate setting names in ''. */
1078 _("For autogames ('timeout' = -1) 'unitwaittime' "
1079 "should be deactivated (= 0)."));
1080 return FALSE;
1083 if (game.info.timeout > 0 && value > game.info.timeout * 2 / 3) {
1084 settings_snprintf(reject_msg, reject_msg_len,
1085 /* TRANS: Do not translate setting names in ''. */
1086 _("'unitwaittime' has to be lower than 2/3 of the "
1087 "'timeout' setting (= %d). Please change 'timeout' "
1088 "first."), game.info.timeout);
1089 return FALSE;
1092 return TRUE;
1095 /*************************************************************************
1096 Mapsize setting validation callback.
1097 *************************************************************************/
1098 static bool mapsize_callback(int value, struct connection *caller,
1099 char *reject_msg, size_t reject_msg_len)
1101 if (value == MAPSIZE_XYSIZE && MAP_IS_ISOMETRIC &&
1102 game.map.ysize % 2 != 0) {
1103 /* An isometric map needs a even ysize. Is is calculated automatically
1104 * for all settings but mapsize=XYSIZE. */
1105 settings_snprintf(reject_msg, reject_msg_len,
1106 _("For an isometric or hexagonal map the ysize must be "
1107 "even."));
1108 return FALSE;
1111 return TRUE;
1114 /*************************************************************************
1115 xsize setting validation callback.
1116 *************************************************************************/
1117 static bool xsize_callback(int value, struct connection *caller,
1118 char *reject_msg, size_t reject_msg_len)
1120 int size = value * game.map.ysize;
1122 if (size < MAP_MIN_SIZE * 1000) {
1123 settings_snprintf(reject_msg, reject_msg_len,
1124 _("The map size (%d * %d = %d) must be larger than "
1125 "%d tiles."), value, game.map.ysize, size,
1126 MAP_MIN_SIZE * 1000);
1127 return FALSE;
1128 } else if (size > MAP_MAX_SIZE * 1000) {
1129 settings_snprintf(reject_msg, reject_msg_len,
1130 _("The map size (%d * %d = %d) must be lower than "
1131 "%d tiles."), value, game.map.ysize, size,
1132 MAP_MAX_SIZE * 1000);
1133 return FALSE;
1136 return TRUE;
1139 /*************************************************************************
1140 ysize setting validation callback.
1141 *************************************************************************/
1142 static bool ysize_callback(int value, struct connection *caller,
1143 char *reject_msg, size_t reject_msg_len)
1145 int size = game.map.xsize * value;
1147 if (size < MAP_MIN_SIZE * 1000) {
1148 settings_snprintf(reject_msg, reject_msg_len,
1149 _("The map size (%d * %d = %d) must be larger than "
1150 "%d tiles."), game.map.xsize, value, size,
1151 MAP_MIN_SIZE * 1000);
1152 return FALSE;
1153 } else if (size > MAP_MAX_SIZE * 1000) {
1154 settings_snprintf(reject_msg, reject_msg_len,
1155 _("The map size (%d * %d = %d) must be lower than "
1156 "%d tiles."), game.map.xsize, value, size,
1157 MAP_MAX_SIZE * 1000);
1158 return FALSE;
1159 } else if (game.map.server.mapsize == MAPSIZE_XYSIZE && MAP_IS_ISOMETRIC &&
1160 value % 2 != 0) {
1161 /* An isometric map needs a even ysize. Is is calculated automatically
1162 * for all settings but mapsize=XYSIZE. */
1163 settings_snprintf(reject_msg, reject_msg_len,
1164 _("For an isometric or hexagonal map the ysize must be "
1165 "even."));
1166 return FALSE;
1169 return TRUE;
1172 /*************************************************************************
1173 Topology setting validation callback.
1174 *************************************************************************/
1175 static bool topology_callback(unsigned value, struct connection *caller,
1176 char *reject_msg, size_t reject_msg_len)
1178 if (game.map.server.mapsize == MAPSIZE_XYSIZE &&
1179 ((value & (TF_ISO)) != 0 || (value & (TF_HEX)) != 0) &&
1180 game.map.ysize % 2 != 0) {
1181 /* An isometric map needs a even ysize. Is is calculated automatically
1182 * for all settings but mapsize=XYSIZE. */
1183 settings_snprintf(reject_msg, reject_msg_len,
1184 _("For an isometric or hexagonal map the ysize must be "
1185 "even."));
1186 return FALSE;
1189 return TRUE;
1192 /*************************************************************************
1193 Validate that the player color mode can be used.
1194 *************************************************************************/
1195 static bool plrcol_validate(int value, struct connection *caller,
1196 char *reject_msg, size_t reject_msg_len)
1198 enum plrcolor_mode mode = value;
1199 if (mode == PLRCOL_NATION_ORDER) {
1200 nations_iterate(pnation) {
1201 if (nation_color(pnation)) {
1202 /* At least one nation has a color. Allow this mode. */
1203 return TRUE;
1205 } nations_iterate_end;
1206 settings_snprintf(reject_msg, reject_msg_len,
1207 _("No nations in the currently loaded ruleset have "
1208 "associated colors."));
1209 return FALSE;
1211 return TRUE;
1214 #define GEN_BOOL(name, value, sclass, scateg, slevel, to_client, \
1215 short_help, extra_help, func_validate, func_action, \
1216 _default) \
1217 {name, sclass, to_client, short_help, extra_help, NULL, SSET_BOOL, \
1218 scateg, slevel, \
1219 INIT_BRACE_BEGIN \
1220 .boolean = {&value, _default, func_validate, bool_name, \
1221 FALSE} INIT_BRACE_END , func_action, FALSE},
1223 #define GEN_INT(name, value, sclass, scateg, slevel, to_client, \
1224 short_help, extra_help, func_help, \
1225 func_validate, func_action, \
1226 _min, _max, _default) \
1227 {name, sclass, to_client, short_help, extra_help, func_help, SSET_INT, \
1228 scateg, slevel, \
1229 INIT_BRACE_BEGIN \
1230 .integer = {(int *) &value, _default, _min, _max, func_validate, \
1231 0} INIT_BRACE_END, \
1232 func_action, FALSE},
1234 #define GEN_STRING(name, value, sclass, scateg, slevel, to_client, \
1235 short_help, extra_help, func_validate, func_action, \
1236 _default) \
1237 {name, sclass, to_client, short_help, extra_help, NULL, SSET_STRING, \
1238 scateg, slevel, \
1239 INIT_BRACE_BEGIN \
1240 .string = {value, _default, sizeof(value), func_validate, ""} \
1241 INIT_BRACE_END, \
1242 func_action, FALSE},
1244 #define GEN_ENUM(name, value, sclass, scateg, slevel, to_client, \
1245 short_help, extra_help, func_help, func_validate, \
1246 func_action, func_name, _default) \
1247 { name, sclass, to_client, short_help, extra_help, func_help, SSET_ENUM, \
1248 scateg, slevel, \
1249 INIT_BRACE_BEGIN \
1250 .enumerator = { &value, sizeof(value), _default, \
1251 func_validate, \
1252 (val_name_func_t) func_name, 0 } INIT_BRACE_END, \
1253 func_action, FALSE},
1255 #define GEN_BITWISE(name, value, sclass, scateg, slevel, to_client, \
1256 short_help, extra_help, func_validate, func_action, \
1257 func_name, _default) \
1258 { name, sclass, to_client, short_help, extra_help, NULL, SSET_BITWISE, \
1259 scateg, slevel, \
1260 INIT_BRACE_BEGIN \
1261 .bitwise = { (unsigned *) (void *) &value, _default, func_validate, \
1262 func_name, 0 } INIT_BRACE_END, func_action, FALSE},
1264 /* game settings */
1265 static struct setting settings[] = {
1267 /* These should be grouped by sclass */
1269 /* Map size parameters: adjustable if we don't yet have a map */
1270 GEN_ENUM("mapsize", game.map.server.mapsize, SSET_MAP_SIZE,
1271 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1272 N_("Map size definition"),
1273 /* TRANS: The strings between double quotes are also translated
1274 * separately (they must match!). The strings between single
1275 * quotes are setting names and shouldn't be translated. The
1276 * strings between parentheses and in uppercase must stay as
1277 * untranslated. */
1278 N_("Chooses the method used to define the map size. Other options "
1279 "specify the parameters for each method.\n"
1280 "- \"Number of tiles\" (FULLSIZE): Map area (option 'size').\n"
1281 "- \"Tiles per player\" (PLAYER): Number of (land) tiles per "
1282 "player (option 'tilesperplayer').\n"
1283 "- \"Width and height\" (XYSIZE): Map width and height in "
1284 "tiles (options 'xsize' and 'ysize')."), NULL,
1285 mapsize_callback, NULL, mapsize_name, MAP_DEFAULT_MAPSIZE)
1287 GEN_INT("size", game.map.server.size, SSET_MAP_SIZE,
1288 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1289 N_("Map area (in thousands of tiles)"),
1290 /* TRANS: The strings between double quotes are also translated
1291 * separately (they must match!). The strings between single
1292 * quotes are setting names and shouldn't be translated. The
1293 * strings between parentheses and in uppercase must stay as
1294 * untranslated. */
1295 N_("This value is used to determine the map area.\n"
1296 " size = 4 is a normal map of 4,000 tiles (default)\n"
1297 " size = 20 is a huge map of 20,000 tiles\n"
1298 "For this option to take effect, the \"Map size definition\" "
1299 "option ('mapsize') must be set to \"Number of tiles\" "
1300 "(FULLSIZE)."), NULL, NULL, NULL,
1301 MAP_MIN_SIZE, MAP_MAX_SIZE, MAP_DEFAULT_SIZE)
1303 GEN_INT("tilesperplayer", game.map.server.tilesperplayer, SSET_MAP_SIZE,
1304 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1305 N_("Number of (land) tiles per player"),
1306 /* TRANS: The strings between double quotes are also translated
1307 * separately (they must match!). The strings between single
1308 * quotes are setting names and shouldn't be translated. The
1309 * strings between parentheses and in uppercase must stay as
1310 * untranslated. */
1311 N_("This value is used to determine the map dimensions. It "
1312 "calculates the map size at game start based on the number "
1313 "of players and the value of the setting 'landmass'.\n"
1314 "For this option to take effect, the \"Map size definition\" "
1315 "option ('mapsize') must be set to \"Tiles per player\" "
1316 "(PLAYER)."),
1317 NULL, NULL, NULL, MAP_MIN_TILESPERPLAYER,
1318 MAP_MAX_TILESPERPLAYER, MAP_DEFAULT_TILESPERPLAYER)
1320 GEN_INT("xsize", game.map.xsize, SSET_MAP_SIZE,
1321 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1322 N_("Map width in tiles"),
1323 /* TRANS: The strings between double quotes are also translated
1324 * separately (they must match!). The strings between single
1325 * quotes are setting names and shouldn't be translated. The
1326 * strings between parentheses and in uppercase must stay as
1327 * untranslated. */
1328 N_("Defines the map width.\n"
1329 "For this option to take effect, the \"Map size definition\" "
1330 "option ('mapsize') must be set to \"Width and height\" "
1331 "(XYSIZE)."),
1332 NULL, xsize_callback, NULL,
1333 MAP_MIN_LINEAR_SIZE, MAP_MAX_LINEAR_SIZE, MAP_DEFAULT_LINEAR_SIZE)
1334 GEN_INT("ysize", game.map.ysize, SSET_MAP_SIZE,
1335 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1336 N_("Map height in tiles"),
1337 /* TRANS: The strings between double quotes are also translated
1338 * separately (they must match!). The strings between single
1339 * quotes are setting names and shouldn't be translated. The
1340 * strings between parentheses and in uppercase must stay as
1341 * untranslated. */
1342 N_("Defines the map height.\n"
1343 "For this option to take effect, the \"Map size definition\" "
1344 "option ('mapsize') must be set to \"Width and height\" "
1345 "(XYSIZE)."),
1346 NULL, ysize_callback, NULL,
1347 MAP_MIN_LINEAR_SIZE, MAP_MAX_LINEAR_SIZE, MAP_DEFAULT_LINEAR_SIZE)
1349 GEN_BITWISE("topology", game.map.topology_id, SSET_MAP_SIZE,
1350 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1351 N_("Map topology index"),
1352 /* TRANS: do not edit the ugly ASCII art */
1353 N_("Freeciv maps are always two-dimensional. They may wrap at "
1354 "the north-south and east-west directions to form a flat "
1355 "map, a cylinder, or a torus (donut). Individual tiles may "
1356 "be rectangular or hexagonal, with either a classic or "
1357 "isometric alignment - this should be set based on the "
1358 "tileset being used.\n"
1359 "Classic rectangular: Isometric rectangular:\n"
1360 " _________ /\\/\\/\\/\\/\\\n"
1361 " |_|_|_|_|_| /\\/\\/\\/\\/\\/\n"
1362 " |_|_|_|_|_| \\/\\/\\/\\/\\/\\\n"
1363 " |_|_|_|_|_| /\\/\\/\\/\\/\\/\n"
1364 " \\/\\/\\/\\/\\/\n"
1365 "Hex tiles: Iso-hex:\n"
1366 " /\\/\\/\\/\\/\\/\\ _ _ _ _ _\n"
1367 " | | | | | | | / \\_/ \\_/ \\_/ \\_/ \\\n"
1368 " \\/\\/\\/\\/\\/\\/\\"
1369 " \\_/ \\_/ \\_/ \\_/ \\_/\n"
1370 " | | | | | | | / \\_/ \\_/ \\_/ \\_/ \\\n"
1371 " \\/\\/\\/\\/\\/\\/"
1372 " \\_/ \\_/ \\_/ \\_/ \\_/\n"),
1373 topology_callback, topology_action, topology_name, MAP_DEFAULT_TOPO)
1375 GEN_ENUM("generator", game.map.server.generator,
1376 SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1377 N_("Method used to generate map"),
1378 /* TRANS: The strings between double quotes are also translated
1379 * separately (they must match!). The strings between single
1380 * quotes (except 'fair') are setting names and shouldn't be
1381 * translated. The strings between parentheses and in uppercase
1382 * must stay as untranslated. */
1383 N_("Specifies the algorithm used to generate the map. If the "
1384 "default value of the 'startpos' option is used, then the "
1385 "chosen generator chooses an appropriate 'startpos' setting; "
1386 "otherwise, the generated map tries to accommodate the "
1387 "chosen 'startpos' setting.\n"
1388 "- \"Scenario map\" (SCENARIO): indicates a pre-generated map. "
1389 "By default, if the scenario does not specify start positions, "
1390 "they will be allocated depending on the size of continents.\n"
1391 "- \"Fully random height\" (RANDOM): generates maps with a "
1392 "number of equally spaced, relatively small islands. By default, "
1393 "start positions are allocated depending on continent size.\n"
1394 "- \"Pseudo-fractal height\" (FRACTAL): generates Earthlike "
1395 "worlds with one or more large continents and a scattering of "
1396 "smaller islands. By default, players are all placed on a "
1397 "single continent.\n"
1398 "- \"Island-based\" (ISLAND): generates 'fair' maps with a "
1399 "number of similarly-sized and -shaped islands, each with "
1400 "approximately the same ratios of terrain types. By default, "
1401 "each player gets their own island.\n"
1402 "- \"Fair islands\" (FAIR): generates the exact copy of the "
1403 "same island for every player or every team.\n"
1404 "If the requested generator is incompatible with other server "
1405 "settings, the server may fall back to another generator."),
1406 NULL, generator_validate, NULL, generator_name, MAP_DEFAULT_GENERATOR)
1408 GEN_ENUM("startpos", game.map.server.startpos,
1409 SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1410 N_("Method used to choose start positions"),
1411 /* TRANS: The strings between double quotes are also translated
1412 * separately (they must match!). The strings between single
1413 * quotes (except 'best') are setting names and shouldn't be
1414 * translated. The strings between parentheses and in uppercase
1415 * must stay as untranslated. */
1416 N_("The method used to choose where each player's initial units "
1417 "start on the map. (For scenarios which include pre-set "
1418 "start positions, this setting is ignored.)\n"
1419 "- \"Generator's choice\" (DEFAULT): the start position "
1420 "placement will depend on the map generator chosen. See the "
1421 "'generator' setting.\n"
1422 "- \"One player per continent\" (SINGLE): one player is "
1423 "placed on each of a set of continents of approximately "
1424 "equivalent value (if possible).\n"
1425 "- \"Two or three players per continent\" (2or3): similar "
1426 "to SINGLE except that two players will be placed on each "
1427 "continent, with three on the 'best' continent if there is an "
1428 "odd number of players.\n"
1429 "- \"All players on a single continent\" (ALL): all players "
1430 "will start on the 'best' available continent.\n"
1431 "- \"Depending on size of continents\" (VARIABLE): players "
1432 "will be placed on the 'best' available continents such that, "
1433 "as far as possible, the number of players on each continent "
1434 "is proportional to its value.\n"
1435 "If the server cannot satisfy the requested setting due to "
1436 "there being too many players for continents, it may fall "
1437 "back to one of the others. (However, map generators try to "
1438 "create the right number of continents for the choice of this "
1439 "'startpos' setting and the number of players, so this is "
1440 "unlikely to occur.)"),
1441 NULL, NULL, NULL, startpos_name, MAP_DEFAULT_STARTPOS)
1443 GEN_ENUM("teamplacement", game.map.server.team_placement,
1444 SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1445 N_("Method used for placement of team mates"),
1446 /* TRANS: The strings between double quotes are also translated
1447 * separately (they must match!). The strings between single
1448 * quotes are setting names and shouldn't be translated. The
1449 * strings between parentheses and in uppercase must stay as
1450 * untranslated. */
1451 N_("After start positions have been generated thanks to the "
1452 "'startpos' setting, this setting controls how the start "
1453 "positions will be assigned to the different players of the "
1454 "same team.\n"
1455 "- \"Disabled\" (DISABLED): the start positions will be "
1456 "randomly assigned to players, regardless of teams.\n"
1457 "- \"As close as possible\" (CLOSEST): players will be "
1458 "placed as close as possible, regardless of continents.\n"
1459 "- \"On the same continent\" (CONTINENT): if possible, place "
1460 "all players of the same team onto the same "
1461 "island/continent.\n"
1462 "- \"Horizontal placement\" (HORIZONTAL): players of the same "
1463 "team will be placed horizontally.\n"
1464 "- \"Vertical placement\" (VERTICAL): players of the same "
1465 "team will be placed vertically."),
1466 NULL, NULL, NULL, teamplacement_name, MAP_DEFAULT_TEAM_PLACEMENT)
1468 GEN_BOOL("tinyisles", game.map.server.tinyisles,
1469 SSET_MAP_GEN, SSET_GEOLOGY, SSET_RARE, SSET_TO_CLIENT,
1470 N_("Presence of 1x1 islands"),
1471 N_("This setting controls whether the map generator is allowed "
1472 "to make islands of one only tile size."), NULL, NULL,
1473 MAP_DEFAULT_TINYISLES)
1475 GEN_BOOL("separatepoles", game.map.server.separatepoles,
1476 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1477 N_("Whether the poles are separate continents"),
1478 N_("If this setting is disabled, the continents may attach to "
1479 "poles."), NULL, NULL, MAP_DEFAULT_SEPARATE_POLES)
1481 GEN_INT("flatpoles", game.map.server.flatpoles,
1482 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1483 N_("How much the land at the poles is flattened"),
1484 /* TRANS: The strings in quotes shouldn't be translated. */
1485 N_("Controls how much the height of the poles is flattened "
1486 "during map generation, preventing a diversity of land "
1487 "terrain there. 0 is no flattening, 100 is maximum "
1488 "flattening. Only affects the 'RANDOM' and 'FRACTAL' "
1489 "map generators."), NULL,
1490 NULL, NULL,
1491 MAP_MIN_FLATPOLES, MAP_MAX_FLATPOLES, MAP_DEFAULT_FLATPOLES)
1493 GEN_BOOL("singlepole", game.map.server.single_pole,
1494 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1495 N_("Whether there's just one pole generated"),
1496 N_("If this setting is enabled, only one side of the map will have "
1497 "a pole. This setting has no effect if the map wraps both "
1498 "directions."), NULL, NULL, MAP_DEFAULT_SINGLE_POLE)
1500 GEN_BOOL("alltemperate", game.map.server.alltemperate,
1501 SSET_MAP_GEN, SSET_GEOLOGY, SSET_RARE, SSET_TO_CLIENT,
1502 N_("All the map is temperate"),
1503 N_("If this setting is enabled, the temperature will be "
1504 "equivalent everywhere on the map. As a result, the "
1505 "poles won't be generated."),
1506 NULL, NULL, MAP_DEFAULT_ALLTEMPERATE)
1508 GEN_INT("temperature", game.map.server.temperature,
1509 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1510 N_("Average temperature of the planet"),
1511 N_("Small values will give a cold map, while larger values will "
1512 "give a hotter map.\n"
1513 "\n"
1514 "100 means a very dry and hot planet with no polar arctic "
1515 "zones, only tropical and dry zones.\n"
1516 " 70 means a hot planet with little polar ice.\n"
1517 " 50 means a temperate planet with normal polar, cold, "
1518 "temperate, and tropical zones; a desert zone overlaps "
1519 "tropical and temperate zones.\n"
1520 " 30 means a cold planet with small tropical zones.\n"
1521 " 0 means a very cold planet with large polar zones and no "
1522 "tropics."),
1523 NULL, NULL, NULL,
1524 MAP_MIN_TEMPERATURE, MAP_MAX_TEMPERATURE, MAP_DEFAULT_TEMPERATURE)
1526 GEN_INT("landmass", game.map.server.landpercent,
1527 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1528 N_("Percentage of the map that is land"),
1529 N_("This setting gives the approximate percentage of the map "
1530 "that will be made into land."), NULL, NULL, NULL,
1531 MAP_MIN_LANDMASS, MAP_MAX_LANDMASS, MAP_DEFAULT_LANDMASS)
1533 GEN_INT("steepness", game.map.server.steepness,
1534 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1535 N_("Amount of hills/mountains"),
1536 N_("Small values give flat maps, while higher values give a "
1537 "steeper map with more hills and mountains."),
1538 NULL, NULL, NULL,
1539 MAP_MIN_STEEPNESS, MAP_MAX_STEEPNESS, MAP_DEFAULT_STEEPNESS)
1541 GEN_INT("wetness", game.map.server.wetness,
1542 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1543 N_("Amount of water on landmasses"),
1544 N_("Small values mean lots of dry, desert-like land; "
1545 "higher values give a wetter map with more swamps, "
1546 "jungles, and rivers."), NULL, NULL, NULL,
1547 MAP_MIN_WETNESS, MAP_MAX_WETNESS, MAP_DEFAULT_WETNESS)
1549 GEN_BOOL("globalwarming", game.info.global_warming,
1550 SSET_RULES, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1551 N_("Global warming"),
1552 N_("If turned off, global warming will not occur "
1553 "as a result of pollution. This setting does not "
1554 "affect pollution."), NULL, NULL,
1555 GAME_DEFAULT_GLOBAL_WARMING)
1557 GEN_BOOL("nuclearwinter", game.info.nuclear_winter,
1558 SSET_RULES, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1559 N_("Nuclear winter"),
1560 N_("If turned off, nuclear winter will not occur "
1561 "as a result of nuclear war."), NULL, NULL,
1562 GAME_DEFAULT_NUCLEAR_WINTER)
1564 GEN_INT("mapseed", game.map.server.seed_setting,
1565 SSET_MAP_GEN, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
1566 N_("Map generation random seed"),
1567 N_("The same seed will always produce the same map; "
1568 "for zero (the default) a seed will be chosen based on "
1569 "the time to give a random map."),
1570 NULL, NULL, NULL,
1571 MAP_MIN_SEED, MAP_MAX_SEED, MAP_DEFAULT_SEED)
1573 /* Map additional stuff: huts and specials. gameseed also goes here
1574 * because huts and specials are the first time the gameseed gets used (?)
1575 * These are done when the game starts, so these are historical and
1576 * fixed after the game has started.
1578 GEN_INT("gameseed", game.server.seed_setting,
1579 SSET_MAP_ADD, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
1580 N_("Game random seed"),
1581 N_("For zero (the default) a seed will be chosen based "
1582 "on the current time."),
1583 NULL, NULL, NULL,
1584 GAME_MIN_SEED, GAME_MAX_SEED, GAME_DEFAULT_SEED)
1586 GEN_INT("specials", game.map.server.riches,
1587 SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1588 N_("Amount of \"special\" resource tiles"),
1589 N_("Special resources improve the basic terrain type they "
1590 "are on. The server variable's scale is parts per "
1591 "thousand."), NULL, NULL, NULL,
1592 MAP_MIN_RICHES, MAP_MAX_RICHES, MAP_DEFAULT_RICHES)
1594 GEN_INT("huts", game.map.server.huts,
1595 SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1596 N_("Amount of huts (bonus extras)"),
1597 N_("This setting gives number of huts that will be "
1598 "placed on every one thousand tiles. Huts are "
1599 "tile extras that may be investigated by units."),
1600 huts_help, NULL, huts_action,
1601 MAP_MIN_HUTS, MAP_MAX_HUTS, MAP_DEFAULT_HUTS)
1603 GEN_INT("animals", game.map.server.animals,
1604 SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1605 N_("Amount of animals"),
1606 N_("Amount of animals initially created to terrains "
1607 "defined for them in the ruleset. "
1608 "The server variable's scale is animals per "
1609 "thousand tiles."), NULL, NULL, NULL,
1610 MAP_MIN_ANIMALS, MAP_MAX_ANIMALS, MAP_DEFAULT_ANIMALS)
1612 /* Options affecting numbers of players and AI players. These only
1613 * affect the start of the game and can not be adjusted after that.
1615 GEN_INT("minplayers", game.server.min_players,
1616 SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL,
1617 SSET_TO_CLIENT,
1618 N_("Minimum number of players"),
1619 N_("There must be at least this many players (connected "
1620 "human players) before the game can start."),
1621 NULL, NULL, NULL,
1622 GAME_MIN_MIN_PLAYERS, GAME_MAX_MIN_PLAYERS, GAME_DEFAULT_MIN_PLAYERS)
1624 GEN_INT("maxplayers", game.server.max_players,
1625 SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
1626 N_("Maximum number of players"),
1627 N_("The maximal number of human and AI players who can be in "
1628 "the game. When this number of players are connected in "
1629 "the pregame state, any new players who try to connect "
1630 "will be rejected.\n"
1631 "When playing a scenario which defines player start positions, "
1632 "this setting cannot be set to greater than the number of "
1633 "defined start positions."),
1634 NULL, maxplayers_callback, NULL,
1635 GAME_MIN_MAX_PLAYERS, GAME_MAX_MAX_PLAYERS, GAME_DEFAULT_MAX_PLAYERS)
1637 GEN_INT("aifill", game.info.aifill,
1638 SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
1639 N_("Limited number of AI players"),
1640 N_("If set to a positive value, then AI players will be "
1641 "automatically created or removed to keep the total "
1642 "number of players at this amount. As more players join, "
1643 "these AI players will be replaced. When set to zero, "
1644 "all AI players will be removed."),
1645 NULL, NULL, aifill_action,
1646 GAME_MIN_AIFILL, GAME_MAX_AIFILL, GAME_DEFAULT_AIFILL)
1648 GEN_ENUM("persistentready", game.info.persistent_ready,
1649 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
1650 N_("When the Readiness of a player gets autotoggled off"),
1651 N_("In pre-game, usually when new players join or old ones leave, "
1652 "those who have already accepted game to start by toggling \"Ready\" "
1653 "get that autotoggled off in the changed situation. This setting "
1654 "can be used to make readiness more persistent."),
1655 NULL, NULL, NULL, persistentready_name, GAME_DEFAULT_PERSISTENTREADY)
1657 GEN_STRING("nationset", game.server.nationset,
1658 SSET_PLAYERS, SSET_INTERNAL, SSET_RARE, SSET_TO_CLIENT,
1659 N_("Set of nations to choose from"),
1660 /* TRANS: do not translate '/list nationsets' */
1661 N_("Controls the set of nations allowed in the game. The "
1662 "choices are defined by the ruleset.\n"
1663 "Only nations in the set selected here will be allowed in "
1664 "any circumstances, including new players and civil war; "
1665 "small sets may thus limit the number of players in a game.\n"
1666 "If this is left blank, the ruleset's default nation set is "
1667 "used.\n"
1668 "See '/list nationsets' for possible choices for the "
1669 "currently loaded ruleset."),
1670 nationset_callback, nationset_action, GAME_DEFAULT_NATIONSET)
1672 GEN_INT("ec_turns", game.server.event_cache.turns,
1673 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_SITUATIONAL,
1674 SSET_TO_CLIENT,
1675 N_("Event cache for this number of turns"),
1676 N_("Event messages are saved for this number of turns. A value of "
1677 "0 deactivates the event cache."),
1678 NULL, NULL, NULL, GAME_MIN_EVENT_CACHE_TURNS, GAME_MAX_EVENT_CACHE_TURNS,
1679 GAME_DEFAULT_EVENT_CACHE_TURNS)
1681 GEN_INT("ec_max_size", game.server.event_cache.max_size,
1682 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_SITUATIONAL,
1683 SSET_TO_CLIENT,
1684 N_("Size of the event cache"),
1685 N_("This defines the maximal number of events in the event cache."),
1686 NULL, NULL, NULL, GAME_MIN_EVENT_CACHE_MAX_SIZE,
1687 GAME_MAX_EVENT_CACHE_MAX_SIZE, GAME_DEFAULT_EVENT_CACHE_MAX_SIZE)
1689 GEN_BOOL("ec_chat", game.server.event_cache.chat,
1690 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_SITUATIONAL,
1691 SSET_TO_CLIENT,
1692 N_("Save chat messages in the event cache"),
1693 N_("If turned on, chat messages will be saved in the event "
1694 "cache."), NULL, NULL, GAME_DEFAULT_EVENT_CACHE_CHAT)
1696 GEN_BOOL("ec_info", game.server.event_cache.info,
1697 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
1698 N_("Print turn and time for each cached event"),
1699 /* TRANS: Don't translate the text between single quotes. */
1700 N_("If turned on, all cached events will be marked by the turn "
1701 "and time of the event like '(T2 - 15:29:52)'."),
1702 NULL, NULL, GAME_DEFAULT_EVENT_CACHE_INFO)
1704 /* Game initialization parameters (only affect the first start of the game,
1705 * and not reloads). Can not be changed after first start of game.
1707 GEN_STRING("startunits", game.server.start_units,
1708 SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1709 N_("List of players' initial units"),
1710 N_("This should be a string of characters, each of which "
1711 "specifies a unit role. The first character must be native to "
1712 "at least one \"Starter\" terrain. The characters and their "
1713 "meanings are:\n"
1714 " c = City founder (eg., Settlers)\n"
1715 " w = Terrain worker (eg., Engineers)\n"
1716 " x = Explorer (eg., Explorer)\n"
1717 " k = Gameloss (eg., King)\n"
1718 " s = Diplomat (eg., Diplomat)\n"
1719 " f = Ferryboat (eg., Trireme)\n"
1720 " d = Ok defense unit (eg., Warriors)\n"
1721 " D = Good defense unit (eg., Phalanx)\n"
1722 " a = Fast attack unit (eg., Horsemen)\n"
1723 " A = Strong attack unit (eg., Catapult)\n"),
1724 startunits_callback, NULL, GAME_DEFAULT_START_UNITS)
1726 GEN_BOOL("startcity", game.server.start_city,
1727 SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1728 N_("Whether player starts with a city"),
1729 N_("If this is set, game will start with player's first "
1730 "city already founded to starting location."),
1731 NULL, NULL, GAME_DEFAULT_START_CITY)
1733 GEN_INT("dispersion", game.server.dispersion,
1734 SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1735 N_("Area where initial units are located"),
1736 N_("This is the radius within "
1737 "which the initial units are dispersed."),
1738 NULL, NULL, NULL,
1739 GAME_MIN_DISPERSION, GAME_MAX_DISPERSION, GAME_DEFAULT_DISPERSION)
1741 GEN_INT("gold", game.info.gold,
1742 SSET_GAME_INIT, SSET_ECONOMICS, SSET_VITAL, SSET_TO_CLIENT,
1743 N_("Starting gold per player"),
1744 N_("At the beginning of the game, each player is given this "
1745 "much gold."), NULL, NULL, NULL,
1746 GAME_MIN_GOLD, GAME_MAX_GOLD, GAME_DEFAULT_GOLD)
1748 GEN_INT("techlevel", game.info.tech,
1749 SSET_GAME_INIT, SSET_SCIENCE, SSET_VITAL, SSET_TO_CLIENT,
1750 N_("Number of initial techs per player"),
1751 /* TRANS: The string between single quotes is a setting name and
1752 * should not be translated. */
1753 N_("At the beginning of the game, each player is given this "
1754 "many technologies. The technologies chosen are random for "
1755 "each player. Depending on the value of tech_cost_style in "
1756 "the ruleset, a big value for 'techlevel' can make the next "
1757 "techs really expensive."), NULL, NULL, NULL,
1758 GAME_MIN_TECHLEVEL, GAME_MAX_TECHLEVEL, GAME_DEFAULT_TECHLEVEL)
1760 GEN_INT("sciencebox", game.info.sciencebox,
1761 SSET_RULES_SCENARIO, SSET_SCIENCE, SSET_SITUATIONAL,
1762 SSET_TO_CLIENT,
1763 N_("Technology cost multiplier percentage"),
1764 N_("This affects how quickly players can research new "
1765 "technology. All tech costs are multiplied by this amount "
1766 "(as a percentage). The base tech costs are determined by "
1767 "the ruleset or other game settings."),
1768 NULL, NULL, NULL, GAME_MIN_SCIENCEBOX, GAME_MAX_SCIENCEBOX,
1769 GAME_DEFAULT_SCIENCEBOX)
1771 GEN_INT("techpenalty", game.server.techpenalty,
1772 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1773 N_("Percentage penalty when changing tech"),
1774 N_("If you change your current research technology, and you have "
1775 "positive research points, you lose this percentage of those "
1776 "research points. This does not apply when you have just gained "
1777 "a technology this turn."), NULL, NULL, NULL,
1778 GAME_MIN_TECHPENALTY, GAME_MAX_TECHPENALTY,
1779 GAME_DEFAULT_TECHPENALTY)
1781 GEN_INT("techlost_recv", game.server.techlost_recv,
1782 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1783 N_("Chance to lose a technology while receiving it"),
1784 N_("The chance that learning a technology by treaty or theft "
1785 "will fail."),
1786 NULL, NULL, NULL, GAME_MIN_TECHLOST_RECV, GAME_MAX_TECHLOST_RECV,
1787 GAME_DEFAULT_TECHLOST_RECV)
1789 GEN_INT("techlost_donor", game.server.techlost_donor,
1790 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1791 N_("Chance to lose a technology while giving it"),
1792 N_("The chance that your civilization will lose a technology if "
1793 "you teach it to someone else by treaty, or if it is stolen "
1794 "from you."),
1795 NULL, NULL, NULL, GAME_MIN_TECHLOST_DONOR, GAME_MAX_TECHLOST_DONOR,
1796 GAME_DEFAULT_TECHLOST_DONOR)
1798 GEN_BOOL("team_pooled_research", game.info.team_pooled_research,
1799 SSET_RULES, SSET_SCIENCE, SSET_VITAL, SSET_TO_CLIENT,
1800 N_("Team pooled research"),
1801 N_("If this setting is turned on, then the team mates will share "
1802 "the science research. Else, every player of the team will "
1803 "have to make its own."),
1804 NULL, NULL, GAME_DEFAULT_TEAM_POOLED_RESEARCH)
1806 GEN_INT("diplbulbcost", game.server.diplbulbcost,
1807 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1808 N_("Penalty when getting tech from treaty"),
1809 N_("For each technology you gain from a diplomatic treaty, you "
1810 "lose research points equal to this percentage of the cost to "
1811 "research a new technology. If this is non-zero, you can end up "
1812 "with negative research points."),
1813 NULL, NULL, NULL,
1814 GAME_MIN_DIPLBULBCOST, GAME_MAX_DIPLBULBCOST, GAME_DEFAULT_DIPLBULBCOST)
1816 GEN_INT("diplgoldcost", game.server.diplgoldcost,
1817 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1818 N_("Penalty when getting gold from treaty"),
1819 N_("When transferring gold in diplomatic treaties, this percentage "
1820 "of the agreed sum is lost to both parties; it is deducted from "
1821 "the donor but not received by the recipient."),
1822 NULL, NULL, NULL,
1823 GAME_MIN_DIPLGOLDCOST, GAME_MAX_DIPLGOLDCOST, GAME_DEFAULT_DIPLGOLDCOST)
1825 GEN_INT("conquercost", game.server.conquercost,
1826 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1827 N_("Penalty when getting tech from conquering"),
1828 N_("For each technology you gain by conquering an enemy city, you "
1829 "lose research points equal to this percentage of the cost to "
1830 "research a new technology. If this is non-zero, you can end up "
1831 "with negative research points."),
1832 NULL, NULL, NULL,
1833 GAME_MIN_CONQUERCOST, GAME_MAX_CONQUERCOST,
1834 GAME_DEFAULT_CONQUERCOST)
1836 GEN_INT("freecost", game.server.freecost,
1837 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1838 N_("Penalty when getting a free tech"),
1839 /* TRANS: The strings between single quotes are setting names and
1840 * shouldn't be translated. */
1841 N_("For each technology you gain \"for free\" (other than "
1842 "covered by 'diplcost' or 'conquercost': for instance, from huts "
1843 "or from Great Library effects), you lose research points "
1844 "equal to this percentage of the cost to research a new "
1845 "technology. If this is non-zero, you can end up "
1846 "with negative research points."),
1847 NULL, NULL, NULL,
1848 GAME_MIN_FREECOST, GAME_MAX_FREECOST, GAME_DEFAULT_FREECOST)
1850 GEN_INT("techlossforgiveness", game.server.techloss_forgiveness,
1851 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1852 N_("Research point debt threshold for losing tech"),
1853 N_("When you have negative research points, and your shortfall is "
1854 "greater than this percentage of the cost of your current "
1855 "research, you forget a technology you already knew.\n"
1856 "The special value -1 prevents loss of technology regardless of "
1857 "research points."),
1858 NULL, NULL, NULL,
1859 GAME_MIN_TECHLOSSFG, GAME_MAX_TECHLOSSFG,
1860 GAME_DEFAULT_TECHLOSSFG)
1862 GEN_INT("techlossrestore", game.server.techloss_restore,
1863 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1864 N_("Research points restored after losing a tech"),
1865 N_("When you lose a technology due to a negative research balance "
1866 "(see 'techlossforgiveness'), this percentage of its research "
1867 "cost is credited to your research balance (this may not be "
1868 "sufficient to make it positive).\n"
1869 "The special value -1 means that your research balance is always "
1870 "restored to zero, regardless of your previous shortfall."),
1871 NULL, NULL, NULL,
1872 GAME_MIN_TECHLOSSREST, GAME_MAX_TECHLOSSREST,
1873 GAME_DEFAULT_TECHLOSSREST)
1875 GEN_INT("foodbox", game.info.foodbox,
1876 SSET_RULES, SSET_ECONOMICS, SSET_SITUATIONAL, SSET_TO_CLIENT,
1877 N_("Food required for a city to grow"),
1878 N_("This is the base amount of food required to grow a city. "
1879 "This value is multiplied by another factor that comes from "
1880 "the ruleset and is dependent on the size of the city."),
1881 NULL, NULL, NULL,
1882 GAME_MIN_FOODBOX, GAME_MAX_FOODBOX, GAME_DEFAULT_FOODBOX)
1884 GEN_INT("aqueductloss", game.server.aqueductloss,
1885 SSET_RULES, SSET_ECONOMICS, SSET_RARE, SSET_TO_CLIENT,
1886 N_("Percentage food lost when city can't grow"),
1887 N_("If a city would expand, but it can't because it lacks some "
1888 "prerequisite (traditionally an Aqueduct or Sewer System), "
1889 "this is the base percentage of its foodbox that is lost "
1890 "each turn; the penalty may be reduced by buildings or other "
1891 "circumstances, depending on the ruleset."),
1892 NULL, NULL, NULL,
1893 GAME_MIN_AQUEDUCTLOSS, GAME_MAX_AQUEDUCTLOSS,
1894 GAME_DEFAULT_AQUEDUCTLOSS)
1896 GEN_INT("shieldbox", game.info.shieldbox,
1897 SSET_RULES, SSET_ECONOMICS, SSET_SITUATIONAL, SSET_TO_CLIENT,
1898 N_("Multiplier percentage for production costs"),
1899 N_("This affects how quickly units and buildings can be "
1900 "produced. The base costs are multiplied by this value (as "
1901 "a percentage)."),
1902 NULL, NULL, NULL,
1903 GAME_MIN_SHIELDBOX, GAME_MAX_SHIELDBOX, GAME_DEFAULT_SHIELDBOX)
1905 /* Notradesize and fulltradesize used to have callbacks to prevent them
1906 * from being set illegally (notradesize > fulltradesize). However this
1907 * provided a problem when setting them both through the client's settings
1908 * dialog, since they cannot both be set atomically. So the callbacks were
1909 * removed and instead the game now knows how to deal with invalid
1910 * settings. */
1911 GEN_INT("fulltradesize", game.info.fulltradesize,
1912 SSET_RULES, SSET_ECONOMICS, SSET_RARE, SSET_TO_CLIENT,
1913 N_("Minimum city size to get full trade"),
1914 /* TRANS: The strings between single quotes are setting names and
1915 * shouldn't be translated. */
1916 N_("There is a trade penalty in all cities smaller than this. "
1917 "The penalty is 100% (no trade at all) for sizes up to "
1918 "'notradesize', and decreases gradually to 0% (no penalty "
1919 "except the normal corruption) for size='fulltradesize'. "
1920 "See also 'notradesize'."), NULL, NULL, NULL,
1921 GAME_MIN_FULLTRADESIZE, GAME_MAX_FULLTRADESIZE,
1922 GAME_DEFAULT_FULLTRADESIZE)
1924 GEN_INT("notradesize", game.info.notradesize,
1925 SSET_RULES, SSET_ECONOMICS, SSET_RARE, SSET_TO_CLIENT,
1926 N_("Maximum size of a city without trade"),
1927 /* TRANS: The strings between single quotes are setting names and
1928 * shouldn't be translated. */
1929 N_("Cities do not produce any trade at all unless their size "
1930 "is larger than this amount. The produced trade increases "
1931 "gradually for cities larger than 'notradesize' and smaller "
1932 "than 'fulltradesize'. See also 'fulltradesize'."),
1933 NULL, NULL, NULL,
1934 GAME_MIN_NOTRADESIZE, GAME_MAX_NOTRADESIZE,
1935 GAME_DEFAULT_NOTRADESIZE)
1937 GEN_INT("citymindist", game.info.citymindist,
1938 SSET_RULES, SSET_SOCIOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1939 N_("Minimum distance between cities"),
1940 N_("When a player attempts to found a new city, it is prevented "
1941 "if the distance from any existing city is less than this "
1942 "setting. For example, when this setting is 3, there must be "
1943 "at least two clear tiles in any direction between all existing "
1944 "cities and the new city site. A value of 1 removes any such "
1945 "restriction on city placement."),
1946 NULL, NULL, NULL,
1947 GAME_MIN_CITYMINDIST, GAME_MAX_CITYMINDIST,
1948 GAME_DEFAULT_CITYMINDIST)
1950 GEN_BOOL("trading_tech", game.info.trading_tech,
1951 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
1952 N_("Technology trading"),
1953 N_("If turned off, trading technologies in the diplomacy dialog "
1954 "is not allowed."), NULL, NULL,
1955 GAME_DEFAULT_TRADING_TECH)
1957 GEN_BOOL("trading_gold", game.info.trading_gold,
1958 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
1959 N_("Gold trading"),
1960 N_("If turned off, trading gold in the diplomacy dialog "
1961 "is not allowed."), NULL, NULL,
1962 GAME_DEFAULT_TRADING_GOLD)
1964 GEN_BOOL("trading_city", game.info.trading_city,
1965 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
1966 N_("City trading"),
1967 N_("If turned off, trading cities in the diplomacy dialog "
1968 "is not allowed."), NULL, NULL,
1969 GAME_DEFAULT_TRADING_CITY)
1971 GEN_INT("trademindist", game.info.trademindist,
1972 SSET_RULES, SSET_ECONOMICS, SSET_RARE, SSET_TO_CLIENT,
1973 N_("Minimum distance for trade routes"),
1974 N_("In order for two cities in the same civilization to establish "
1975 "a trade route, they must be at least this far apart on the "
1976 "map. For square grids, the distance is calculated as "
1977 "\"Manhattan distance\", that is, the sum of the displacements "
1978 "along the x and y directions."), NULL, NULL, NULL,
1979 GAME_MIN_TRADEMINDIST, GAME_MAX_TRADEMINDIST,
1980 GAME_DEFAULT_TRADEMINDIST)
1982 GEN_INT("rapturedelay", game.info.rapturedelay,
1983 SSET_RULES, SSET_SOCIOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1984 N_("Number of turns between rapture effect"),
1985 N_("Sets the number of turns between rapture growth of a city. "
1986 "If set to n a city will grow after celebrating for n+1 "
1987 "turns."),
1988 NULL, NULL, NULL,
1989 GAME_MIN_RAPTUREDELAY, GAME_MAX_RAPTUREDELAY,
1990 GAME_DEFAULT_RAPTUREDELAY)
1992 GEN_INT("disasters", game.info.disasters,
1993 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1994 N_("Frequency of disasters"),
1995 N_("Affects how often random disasters happen to cities, "
1996 "if any are defined by the ruleset. The relative frequency "
1997 "of disaster types is set by the ruleset. Zero prevents "
1998 "any random disasters from occurring."),
1999 NULL, NULL, NULL,
2000 GAME_MIN_DISASTERS, GAME_MAX_DISASTERS,
2001 GAME_DEFAULT_DISASTERS)
2003 GEN_ENUM("traitdistribution", game.server.trait_dist,
2004 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2005 N_("AI trait distribution method"),
2006 N_("How trait values are given to AI players."),
2007 NULL, NULL, NULL, trait_dist_name, GAME_DEFAULT_TRAIT_DIST_MODE)
2009 GEN_INT("razechance", game.server.razechance,
2010 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2011 N_("Chance for conquered building destruction"),
2012 N_("When a player conquers a city, each city improvement has this "
2013 "percentage chance to be destroyed."), NULL, NULL, NULL,
2014 GAME_MIN_RAZECHANCE, GAME_MAX_RAZECHANCE, GAME_DEFAULT_RAZECHANCE)
2016 GEN_INT("occupychance", game.server.occupychance,
2017 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2018 N_("Chance of moving into tile after attack"),
2019 N_("If set to 0, combat is Civ1/2-style (when you attack, "
2020 "you remain in place). If set to 100, attacking units "
2021 "will always move into the tile they attacked when they win "
2022 "the combat (and no enemy units remain in the tile). If "
2023 "set to a value between 0 and 100, this will be used as "
2024 "the percent chance of \"occupying\" territory."),
2025 NULL, NULL, NULL,
2026 GAME_MIN_OCCUPYCHANCE, GAME_MAX_OCCUPYCHANCE,
2027 GAME_DEFAULT_OCCUPYCHANCE)
2029 GEN_BOOL("autoattack", game.server.autoattack, SSET_RULES_FLEXIBLE, SSET_MILITARY,
2030 SSET_SITUATIONAL, SSET_TO_CLIENT,
2031 N_("Turn on/off server-side autoattack"),
2032 N_("If set to on, units with moves left will automatically "
2033 "consider attacking enemy units that move adjacent to them."),
2034 NULL, NULL, GAME_DEFAULT_AUTOATTACK)
2036 GEN_BOOL("killstack", game.info.killstack,
2037 SSET_RULES_SCENARIO, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2038 N_("Do all units in tile die with defender"),
2039 N_("If this is enabled, each time a defender unit loses in combat, "
2040 "and is not inside a city or suitable base, all units in the same "
2041 "tile are destroyed along with the defender. If this is disabled, "
2042 "only the defender unit is destroyed."),
2043 NULL, NULL, GAME_DEFAULT_KILLSTACK)
2045 GEN_BOOL("killcitizen", game.info.killcitizen,
2046 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2047 N_("Reduce city population after attack"),
2048 N_("This flag indicates whether a city's population is reduced "
2049 "after a successful attack by an enemy unit. If this is "
2050 "disabled, population is never reduced. Even when this is "
2051 "enabled, only some units may kill citizens."),
2052 NULL, NULL, GAME_DEFAULT_KILLCITIZEN)
2054 GEN_INT("killunhomed", game.server.killunhomed,
2055 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2056 N_("Slowly kill units without home cities (e.g., starting units)"),
2057 N_("If greater than 0, then every unit without a homecity will "
2058 "lose hitpoints each turn. The number of hitpoints lost is "
2059 "given by 'killunhomed' percent of the hitpoints of the unit "
2060 "type. At least one hitpoint is lost every turn until the "
2061 "death of the unit."),
2062 NULL, NULL, NULL, GAME_MIN_KILLUNHOMED, GAME_MAX_KILLUNHOMED,
2063 GAME_DEFAULT_KILLUNHOMED)
2065 GEN_ENUM("borders", game.info.borders,
2066 SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL, SSET_TO_CLIENT,
2067 N_("National borders"),
2068 N_("If this is not disabled, then any land tiles around a "
2069 "city or border-claiming extra (like the classic ruleset's "
2070 "Fortress base) will be owned by that nation."),
2071 NULL, NULL, NULL, borders_name, GAME_DEFAULT_BORDERS)
2073 GEN_ENUM("happyborders", game.info.happyborders,
2074 SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL,
2075 SSET_TO_CLIENT,
2076 N_("Units inside borders cause no unhappiness"),
2077 N_("If this is set, units will not cause unhappiness when "
2078 "inside your borders, or even allies borders, depending "
2079 "on value."), NULL, NULL, NULL,
2080 happyborders_name, GAME_DEFAULT_HAPPYBORDERS)
2082 GEN_ENUM("diplomacy", game.info.diplomacy,
2083 SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL, SSET_TO_CLIENT,
2084 N_("Ability to do diplomacy with other players"),
2085 N_("This setting controls the ability to do diplomacy with "
2086 "other players."),
2087 NULL, NULL, NULL, diplomacy_name, GAME_DEFAULT_DIPLOMACY)
2089 GEN_ENUM("citynames", game.server.allowed_city_names,
2090 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2091 N_("Allowed city names"),
2092 /* TRANS: The strings between double quotes are also translated
2093 * separately (they must match!). The strings between parentheses
2094 * and in uppercase must not be translated. */
2095 N_("- \"No restrictions\" (NO_RESTRICTIONS): players can have "
2096 "multiple cities with the same names.\n"
2097 "- \"Unique to a player\" (PLAYER_UNIQUE): one player can't "
2098 "have multiple cities with the same name.\n"
2099 "- \"Globally unique\" (GLOBAL_UNIQUE): all cities in a game "
2100 "have to have different names.\n"
2101 "- \"No city name stealing\" (NO_STEALING): like "
2102 "\"Globally unique\", but a player isn't allowed to use a "
2103 "default city name of another nation unless it is a default "
2104 "for their nation also."),
2105 NULL, NULL, NULL, citynames_name, GAME_DEFAULT_ALLOWED_CITY_NAMES)
2107 GEN_ENUM("plrcolormode", game.server.plrcolormode,
2108 SSET_RULES, SSET_INTERNAL, SSET_RARE, SSET_TO_CLIENT,
2109 N_("How to pick player colors"),
2110 /* TRANS: The strings between double quotes are also translated
2111 * separately (they must match!). The strings between single quotes
2112 * are setting names and shouldn't be translated. The strings
2113 * between parentheses and in uppercase must not be translated. */
2114 N_("This setting determines how player colors are chosen. Player "
2115 "colors are used in the Nations report, for national borders on "
2116 "the map, and so on.\n"
2117 "- \"Per-player, in order\" (PLR_ORDER): colors are assigned to "
2118 "individual players in order from a list defined by the "
2119 "ruleset.\n"
2120 "- \"Per-player, random\" (PLR_RANDOM): colors are assigned "
2121 "to individual players randomly from the set defined by the "
2122 "ruleset.\n"
2123 "- \"Set manually\" (PLR_SET): colors can be set with the "
2124 "'playercolor' command before the game starts; these are not "
2125 "restricted to the ruleset colors. Any players for which no "
2126 "color is set when the game starts get a random color from the "
2127 "ruleset.\n"
2128 "- \"Per-team, in order\" (TEAM_ORDER): colors are assigned to "
2129 "teams from the list in the ruleset. Every player on the same "
2130 "team gets the same color.\n"
2131 "- \"Per-nation, in order\" (NATION_ORDER): if the ruleset "
2132 "defines a color for a player's nation, the player takes that "
2133 "color. Any players whose nations don't have associated colors "
2134 "get a random color from the list in the ruleset.\n"
2135 "Regardless of this setting, individual player colors can be "
2136 "changed after the game starts with the 'playercolor' command."),
2137 NULL, plrcol_validate, plrcol_action, plrcol_name,
2138 GAME_DEFAULT_PLRCOLORMODE)
2140 /* Flexible rules: these can be changed after the game has started.
2142 * The distinction between "rules" and "flexible rules" is not always
2143 * clearcut, and some existing cases may be largely historical or
2144 * accidental. However some generalizations can be made:
2146 * -- Low-level game mechanics should not be flexible (eg, rulesets).
2147 * -- Options which would affect the game "state" (city production etc)
2148 * should not be flexible (eg, foodbox).
2149 * -- Options which are explicitly sent to the client (eg, in
2150 * packet_game_info) should probably not be flexible, or at
2151 * least need extra care to be flexible.
2153 GEN_ENUM("barbarians", game.server.barbarianrate,
2154 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_VITAL, SSET_TO_CLIENT,
2155 N_("Barbarian appearance frequency"),
2156 /* TRANS: The string between single quotes is a setting name and
2157 * should not be translated. */
2158 N_("This setting controls how frequently the barbarians appear "
2159 "in the game. See also the 'onsetbarbs' setting."),
2160 NULL, NULL, NULL, barbarians_name, GAME_DEFAULT_BARBARIANRATE)
2162 GEN_INT("onsetbarbs", game.server.onsetbarbarian,
2163 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_VITAL, SSET_TO_CLIENT,
2164 N_("Barbarian onset turn"),
2165 N_("Barbarians will not appear before this turn."),
2166 NULL, NULL, NULL,
2167 GAME_MIN_ONSETBARBARIAN, GAME_MAX_ONSETBARBARIAN,
2168 GAME_DEFAULT_ONSETBARBARIAN)
2170 GEN_ENUM("revolentype", game.info.revolentype,
2171 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2172 N_("Way to determine revolution length"),
2173 N_("Which method is used in determining how long period of anarchy "
2174 "lasts when changing government. The actual value is set with "
2175 "'revolen' setting. The 'quickening' methods depend on how "
2176 "many times any player has changed to this type of government "
2177 "before, so it becomes easier to establish a new system of "
2178 "government if it has been done before."),
2179 NULL, NULL, NULL, revolentype_name, GAME_DEFAULT_REVOLENTYPE)
2181 GEN_INT("revolen", game.server.revolution_length,
2182 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2183 N_("Length of revolution"),
2184 N_("When changing governments, a period of anarchy will occur. "
2185 "Value of this setting, used the way 'revolentype' setting "
2186 "dictates, defines the length of the anarchy."),
2187 NULL, NULL, NULL,
2188 GAME_MIN_REVOLUTION_LENGTH, GAME_MAX_REVOLUTION_LENGTH,
2189 GAME_DEFAULT_REVOLUTION_LENGTH)
2191 GEN_BOOL("fogofwar", game.info.fogofwar,
2192 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2193 N_("Whether to enable fog of war"),
2194 N_("If this is enabled, only those units and cities within "
2195 "the vision range of your own units and cities will be "
2196 "revealed to you. You will not see new cities or terrain "
2197 "changes in tiles not observed."),
2198 NULL, NULL, GAME_DEFAULT_FOGOFWAR)
2200 GEN_BOOL("foggedborders", game.server.foggedborders,
2201 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2202 N_("Whether fog of war applies to border changes"),
2203 N_("If this setting is enabled, players will not be able "
2204 "to see changes in tile ownership if they do not have "
2205 "direct sight of the affected tiles. Otherwise, players "
2206 "can see any or all changes to borders as long as they "
2207 "have previously seen the tiles."),
2208 NULL, NULL, GAME_DEFAULT_FOGGEDBORDERS)
2210 GEN_BITWISE("airliftingstyle", game.info.airlifting_style,
2211 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_SITUATIONAL,
2212 SSET_TO_CLIENT, N_("Airlifting style"),
2213 /* TRANS: The strings between double quotes are also
2214 * translated separately (they must match!). The strings
2215 * between parenthesis and in uppercase must not be
2216 * translated. */
2217 N_("This setting affects airlifting units between cities. It "
2218 "can be a set of the following values:\n"
2219 "- \"Allows units to be airlifted from allied cities\" "
2220 "(FROM_ALLIES).\n"
2221 "- \"Allows units to be airlifted to allied cities\" "
2222 "(TO_ALLIES).\n"
2223 "- \"Unlimited units from source city\" (SRC_UNLIMITED): "
2224 "note that airlifting from a city doesn't reduce the "
2225 "airlifted counter, but still needs at least 1.\n"
2226 "- \"Unlimited units to destination city\" "
2227 "(DEST_UNLIMITED): note that airlifting to a city doesn't "
2228 "reduce the airlifted counter, and doesn't need any."),
2229 NULL, NULL, airliftingstyle_name, GAME_DEFAULT_AIRLIFTINGSTYLE)
2231 GEN_INT("diplchance", game.server.diplchance,
2232 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_SITUATIONAL,
2233 SSET_TO_CLIENT,
2234 N_("Base chance for diplomats and spies to succeed"),
2235 N_("The base chance of a spy returning from a successful mission and "
2236 "the base chance of success for diplomats and spies."),
2237 NULL, NULL, NULL,
2238 GAME_MIN_DIPLCHANCE, GAME_MAX_DIPLCHANCE, GAME_DEFAULT_DIPLCHANCE)
2240 GEN_BITWISE("victories", game.info.victory_conditions,
2241 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2242 N_("What kinds of victories are possible"),
2243 /* TRANS: The strings between double quotes are also translated
2244 * separately (they must match!). The strings between single
2245 * quotes are setting names and shouldn't be translated. The
2246 * strings between parentheses and in uppercase must stay as
2247 * untranslated. */
2248 N_("This setting controls how game can be won. One can always "
2249 "win by conquering entire planet, but other victory conditions "
2250 "can be enabled or disabled:\n"
2251 "- \"Spacerace\" (SPACERACE): Spaceship is built and travels to "
2252 "Alpha Centauri.\n"
2253 "- \"Allied\" (ALLIED): After defeating enemies, all remaining "
2254 "players are allied.\n"
2255 "- \"Culture\" (CULTURE): Player meets ruleset defined cultural "
2256 "domination criteria.\n"),
2257 NULL, NULL, victory_conditions_name, GAME_DEFAULT_VICTORY_CONDITIONS)
2259 GEN_BOOL("endspaceship", game.server.endspaceship, SSET_RULES_FLEXIBLE,
2260 SSET_SCIENCE, SSET_VITAL, SSET_TO_CLIENT,
2261 N_("Should the game end if the spaceship arrives?"),
2262 N_("If this option is turned on, the game will end with the "
2263 "arrival of a spaceship at Alpha Centauri."),
2264 NULL, NULL, GAME_DEFAULT_END_SPACESHIP)
2266 GEN_INT("civilwarsize", game.server.civilwarsize,
2267 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2268 N_("Minimum number of cities for civil war"),
2269 N_("A civil war is triggered when a player has at least this "
2270 "many cities and the player's capital is captured. If "
2271 "this option is set to the maximum value, civil wars are "
2272 "turned off altogether."), NULL, NULL, NULL,
2273 GAME_MIN_CIVILWARSIZE, GAME_MAX_CIVILWARSIZE,
2274 GAME_DEFAULT_CIVILWARSIZE)
2276 GEN_BOOL("restrictinfra", game.info.restrictinfra,
2277 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2278 N_("Restrict the use of the infrastructure for enemy units"),
2279 N_("If this option is enabled, the use of roads and rails "
2280 "will be restricted for enemy units."), NULL, NULL,
2281 GAME_DEFAULT_RESTRICTINFRA)
2283 GEN_BOOL("unreachableprotects", game.info.unreachable_protects,
2284 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2285 N_("Does unreachable unit protect reachable ones"),
2286 N_("This option controls whether tiles with both unreachable "
2287 "and reachable units can be attacked. If disabled, any "
2288 "tile with reachable units can be attacked. If enabled, "
2289 "tiles with an unreachable unit in them cannot be attacked."),
2290 NULL, NULL, GAME_DEFAULT_UNRPROTECTS)
2292 GEN_INT("contactturns", game.server.contactturns,
2293 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2294 N_("Turns until player contact is lost"),
2295 N_("Players may meet for diplomacy this number of turns "
2296 "after their units have last met, even when they do not have "
2297 "an embassy. If set to zero, then players cannot meet unless "
2298 "they have an embassy."),
2299 NULL, NULL, NULL,
2300 GAME_MIN_CONTACTTURNS, GAME_MAX_CONTACTTURNS,
2301 GAME_DEFAULT_CONTACTTURNS)
2303 GEN_BOOL("savepalace", game.server.savepalace,
2304 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2305 N_("Rebuild palace whenever capital is conquered"),
2306 N_("If this is turned on, when the capital is conquered the "
2307 "palace is automatically rebuilt for free in another randomly "
2308 "chosen city. This is significant because the technology "
2309 "requirement for building a palace will be ignored. (In "
2310 "some rulesets, buildings other than the palace are affected "
2311 "by this setting.)"),
2312 NULL, NULL, GAME_DEFAULT_SAVEPALACE)
2314 GEN_BOOL("homecaughtunits", game.server.homecaughtunits,
2315 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2316 N_("Give caught units a homecity"),
2317 /* TRANS: The string between single quotes is a setting name and
2318 * should not be translated. */
2319 N_("If unset, caught units will have no homecity and will be "
2320 "subject to the 'killunhomed' option."),
2321 NULL, NULL, GAME_DEFAULT_HOMECAUGHTUNITS)
2323 GEN_BOOL("naturalcitynames", game.server.natural_city_names,
2324 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2325 N_("Whether to use natural city names"),
2326 N_("If enabled, the default city names will be determined based "
2327 "on the surrounding terrain."),
2328 NULL, NULL, GAME_DEFAULT_NATURALCITYNAMES)
2330 GEN_BOOL("migration", game.server.migration,
2331 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2332 N_("Whether to enable citizen migration"),
2333 /* TRANS: The strings between single quotes are setting names
2334 * and should not be translated. */
2335 N_("This is the master setting that controls whether citizen "
2336 "migration is active in the game. If enabled, citizens may "
2337 "automatically move from less desirable cities to more "
2338 "desirable ones. The \"desirability\" of a given city is "
2339 "calculated from a number of factors. In general larger "
2340 "cities with more income and improvements will be preferred. "
2341 "Citizens will never migrate out of the capital, or cause "
2342 "a wonder to be lost by disbanding a city. A number of other "
2343 "settings control how migration behaves:\n"
2344 " 'mgr_turninterval' - How often citizens try to migrate.\n"
2345 " 'mgr_foodneeded' - Whether destination food is checked.\n"
2346 " 'mgr_distance' - How far citizens will migrate.\n"
2347 " 'mgr_worldchance' - Chance for inter-nation migration.\n"
2348 " 'mgr_nationchance' - Chance for intra-nation migration."),
2349 NULL, NULL, GAME_DEFAULT_MIGRATION)
2351 GEN_INT("mgr_turninterval", game.server.mgr_turninterval,
2352 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2353 N_("Number of turns between migrations from a city"),
2354 /* TRANS: Do not translate 'migration' setting name. */
2355 N_("This setting controls the number of turns between migration "
2356 "checks for a given city. The interval is calculated from "
2357 "the founding turn of the city. So for example if this "
2358 "setting is 5, citizens will look for a suitable migration "
2359 "destination every five turns from the founding of their "
2360 "current city. Migration will never occur the same turn "
2361 "that a city is built. This setting has no effect unless "
2362 "migration is enabled by the 'migration' setting."),
2363 NULL, NULL, NULL,
2364 GAME_MIN_MGR_TURNINTERVAL, GAME_MAX_MGR_TURNINTERVAL,
2365 GAME_DEFAULT_MGR_TURNINTERVAL)
2367 GEN_BOOL("mgr_foodneeded", game.server.mgr_foodneeded,
2368 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2369 N_("Whether migration is limited by food"),
2370 /* TRANS: Do not translate 'migration' setting name. */
2371 N_("If this setting is enabled, citizens will not migrate to "
2372 "cities which would not have enough food to support them. "
2373 "This setting has no effect unless migration is enabled by "
2374 "the 'migration' setting."), NULL, NULL,
2375 GAME_DEFAULT_MGR_FOODNEEDED)
2377 GEN_INT("mgr_distance", game.server.mgr_distance,
2378 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2379 N_("Maximum distance citizens may migrate"),
2380 /* TRANS: Do not translate 'migration' setting name. */
2381 N_("This setting controls how far citizens may look for a "
2382 "suitable migration destination when deciding which city "
2383 "to migrate to. The value is added to the current city radius "
2384 "and compared to the distance between the two cities. If "
2385 "the distance is lower or equal, migration is possible. This "
2386 "setting has no effect unless migration is activated by the "
2387 "'migration' setting."),
2388 NULL, NULL, NULL, GAME_MIN_MGR_DISTANCE, GAME_MAX_MGR_DISTANCE,
2389 GAME_DEFAULT_MGR_DISTANCE)
2391 GEN_INT("mgr_nationchance", game.server.mgr_nationchance,
2392 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2393 N_("Percent probability for migration within the same nation"),
2394 /* TRANS: Do not translate 'migration' setting name. */
2395 N_("This setting controls how likely it is for citizens to "
2396 "migrate between cities owned by the same player. Zero "
2397 "indicates migration will never occur, 100 means that "
2398 "migration will always occur if the citizens find a suitable "
2399 "destination. This setting has no effect unless migration "
2400 "is activated by the 'migration' setting."),
2401 NULL, NULL, NULL,
2402 GAME_MIN_MGR_NATIONCHANCE, GAME_MAX_MGR_NATIONCHANCE,
2403 GAME_DEFAULT_MGR_NATIONCHANCE)
2405 GEN_INT("mgr_worldchance", game.server.mgr_worldchance,
2406 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2407 N_("Percent probability for migration between foreign cities"),
2408 /* TRANS: Do not translate 'migration' setting name. */
2409 N_("This setting controls how likely it is for migration "
2410 "to occur between cities owned by different players. "
2411 "Zero indicates migration will never occur, 100 means "
2412 "that citizens will always migrate if they find a suitable "
2413 "destination. This setting has no effect if migration is "
2414 "not enabled by the 'migration' setting."),
2415 NULL, NULL, NULL,
2416 GAME_MIN_MGR_WORLDCHANCE, GAME_MAX_MGR_WORLDCHANCE,
2417 GAME_DEFAULT_MGR_WORLDCHANCE)
2419 /* Meta options: these don't affect the internal rules of the game, but
2420 * do affect players. Also options which only produce extra server
2421 * "output" and don't affect the actual game.
2422 * ("endturn" is here, and not RULES_FLEXIBLE, because it doesn't
2423 * affect what happens in the game, it just determines when the
2424 * players stop playing and look at the score.)
2426 GEN_STRING("allowtake", game.server.allow_take,
2427 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2428 N_("Players that users are allowed to take"),
2429 /* TRANS: the strings in double quotes are server command names
2430 * and should not be translated. */
2431 N_("This should be a string of characters, each of which "
2432 "specifies a type or status of a civilization (player).\n"
2433 "Clients will only be permitted to take or observe those "
2434 "players which match one of the specified letters. This "
2435 "only affects future uses of the \"take\" or \"observe\" "
2436 "commands; it is not retroactive. The characters and their "
2437 "meanings are:\n"
2438 " o,O = Global observer\n"
2439 " b = Barbarian players\n"
2440 " d = Dead players\n"
2441 " a,A = AI players\n"
2442 " h,H = Human players\n"
2443 "The first description on this list which matches a "
2444 "player is the one which applies. Thus 'd' does not "
2445 "include dead barbarians, 'a' does not include dead AI "
2446 "players, and so on. Upper case letters apply before "
2447 "the game has started, lower case letters afterwards.\n"
2448 "Each character above may be followed by one of the "
2449 "following numbers to allow or restrict the manner "
2450 "of connection:\n"
2451 "(none) = Controller allowed, observers allowed, "
2452 "can displace connections. (Displacing a connection means "
2453 "that you may take over a player, even when another user "
2454 "already controls that player.)\n"
2455 " 1 = Controller allowed, observers allowed, "
2456 "can't displace connections;\n"
2457 " 2 = Controller allowed, no observers allowed, "
2458 "can displace connections;\n"
2459 " 3 = Controller allowed, no observers allowed, "
2460 "can't displace connections;\n"
2461 " 4 = No controller allowed, observers allowed"),
2462 allowtake_callback, NULL, GAME_DEFAULT_ALLOW_TAKE)
2464 GEN_BOOL("autotoggle", game.server.auto_ai_toggle,
2465 SSET_META, SSET_NETWORK, SSET_SITUATIONAL, SSET_TO_CLIENT,
2466 N_("Whether AI-status toggles with connection"),
2467 N_("If enabled, AI status is turned off when a player "
2468 "connects, and on when a player disconnects."),
2469 NULL, autotoggle_action, GAME_DEFAULT_AUTO_AI_TOGGLE)
2471 GEN_INT("endturn", game.server.end_turn,
2472 SSET_META, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
2473 N_("Turn the game ends"),
2474 N_("The game will end at the end of the given turn."),
2475 NULL, endturn_callback, NULL,
2476 GAME_MIN_END_TURN, GAME_MAX_END_TURN, GAME_DEFAULT_END_TURN)
2478 GEN_BITWISE("revealmap", game.server.revealmap, SSET_GAME_INIT,
2479 SSET_MILITARY, SSET_SITUATIONAL, SSET_TO_CLIENT,
2480 N_("Reveal the map"),
2481 /* TRANS: The strings between double quotes are also translated
2482 * separately (they must match!). The strings between single
2483 * quotes are setting names and shouldn't be translated. The
2484 * strings between parentheses and in uppercase must not be
2485 * translated. */
2486 N_("If \"Reveal map at game start\" (START) is set, the "
2487 "initial state of the entire map will be known to all "
2488 "players from the start of the game, although it may "
2489 "still be fogged (depending on the 'fogofwar' setting). "
2490 "If \"Unfog map for dead players\" (DEAD) is set, dead "
2491 "players can see the entire map, if they are alone in "
2492 "their team."),
2493 NULL, NULL, revealmap_name, GAME_DEFAULT_REVEALMAP)
2495 GEN_INT("timeout", game.info.timeout,
2496 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2497 N_("Maximum seconds per turn"),
2498 /* TRANS: \"Turn Done\" refers to the client button; it is also
2499 * translated separately, the translation should be the same.
2500 * \"timeoutincrease\" is a command name and must not to be
2501 * translated. */
2502 N_("If all players have not hit \"Turn Done\" before this "
2503 "time is up, then the turn ends automatically. Zero "
2504 "means there is no timeout. In servers compiled with "
2505 "debugging, a timeout of -1 sets the autogame test mode. "
2506 "Only connections with hack level access may set the "
2507 "timeout to lower than 30 seconds. Use this with the "
2508 "command \"timeoutincrease\" to have a dynamic timer. "
2509 "The first turn is treated as a special case and is controlled "
2510 "by the 'first_timeout' setting."),
2511 NULL, timeout_callback, timeout_action,
2512 GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUT)
2514 GEN_INT("first_timeout", game.info.first_timeout,
2515 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2516 N_("First turn timeout"),
2517 /* TRANS: The strings between single quotes are setting names and
2518 * should not be translated. */
2519 N_("If greater than 0, T0 will last for 'first_timeout' seconds.\n"
2520 "If set to 0, T0 will not have a timeout.\n"
2521 "If set to -1, the special treatment of T0 will be disabled.\n"
2522 "See also 'timeout'."),
2523 NULL, first_timeout_callback, first_timeout_action,
2524 GAME_MIN_FIRST_TIMEOUT, GAME_MAX_FIRST_TIMEOUT,
2525 GAME_DEFAULT_FIRST_TIMEOUT)
2527 GEN_INT("timeaddenemymove", game.server.timeoutaddenemymove,
2528 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2529 N_("Timeout at least n seconds when enemy moved"),
2530 N_("Any time a unit moves while in sight of an enemy player, "
2531 "the remaining timeout is increased to this value."),
2532 NULL, NULL, NULL,
2533 0, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUTADDEMOVE)
2535 GEN_INT("unitwaittime", game.server.unitwaittime,
2536 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2537 N_("Minimum time between unit actions over turn change"),
2538 /* TRANS: The string between single quotes is a setting name and
2539 * should not be translated. */
2540 N_("This setting gives the minimum amount of time in seconds "
2541 "between unit moves and other significant actions (such as "
2542 "building cities) after a turn change occurs. For example, "
2543 "if this setting is set to 20 and a unit moves 5 seconds "
2544 "before the turn change, it will not be able to move or act "
2545 "in the next turn for at least 15 seconds. This value is "
2546 "limited to a maximum value of 2/3 'timeout'."),
2547 NULL, unitwaittime_callback, NULL, GAME_MIN_UNITWAITTIME,
2548 GAME_MAX_UNITWAITTIME, GAME_DEFAULT_UNITWAITTIME)
2550 /* This setting points to the "stored" value; changing it won't have
2551 * an effect until the next synchronization point (i.e., the start of
2552 * the next turn). */
2553 GEN_ENUM("phasemode", game.server.phase_mode_stored,
2554 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
2555 N_("Control of simultaneous player/team phases"),
2556 N_("This setting controls whether players may make "
2557 "moves at the same time during a turn. Change "
2558 "in setting takes effect next turn."),
2559 phasemode_help, NULL, NULL, phasemode_name, GAME_DEFAULT_PHASE_MODE)
2561 GEN_INT("nettimeout", game.server.tcptimeout,
2562 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2563 N_("Seconds to let a client's network connection block"),
2564 N_("If a network connection is blocking for a time greater than "
2565 "this value, then the connection is closed. Zero "
2566 "means there is no timeout (although connections will be "
2567 "automatically disconnected eventually)."),
2568 NULL, NULL, NULL,
2569 GAME_MIN_TCPTIMEOUT, GAME_MAX_TCPTIMEOUT, GAME_DEFAULT_TCPTIMEOUT)
2571 GEN_INT("netwait", game.server.netwait,
2572 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2573 N_("Max seconds for network buffers to drain"),
2574 N_("The server will wait for up to the value of this "
2575 "parameter in seconds, for all client connection network "
2576 "buffers to unblock. Zero means the server will not "
2577 "wait at all."), NULL, NULL, NULL,
2578 GAME_MIN_NETWAIT, GAME_MAX_NETWAIT, GAME_DEFAULT_NETWAIT)
2580 GEN_INT("pingtime", game.server.pingtime,
2581 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2582 N_("Seconds between PINGs"),
2583 N_("The server will poll the clients with a PING request "
2584 "each time this period elapses."), NULL, NULL, NULL,
2585 GAME_MIN_PINGTIME, GAME_MAX_PINGTIME, GAME_DEFAULT_PINGTIME)
2587 GEN_INT("pingtimeout", game.server.pingtimeout,
2588 SSET_META, SSET_NETWORK, SSET_RARE,
2589 SSET_TO_CLIENT,
2590 N_("Time to cut a client"),
2591 N_("If a client doesn't reply to a PING in this time the "
2592 "client is disconnected."), NULL, NULL, NULL,
2593 GAME_MIN_PINGTIMEOUT, GAME_MAX_PINGTIMEOUT, GAME_DEFAULT_PINGTIMEOUT)
2595 GEN_BOOL("turnblock", game.server.turnblock,
2596 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
2597 N_("Turn-blocking game play mode"),
2598 N_("If this is turned on, the game turn is not advanced "
2599 "until all players have finished their turn, including "
2600 "disconnected players."),
2601 NULL, NULL, GAME_DEFAULT_TURNBLOCK)
2603 GEN_BOOL("fixedlength", game.server.fixedlength,
2604 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
2605 N_("Fixed-length turns play mode"),
2606 /* TRANS: \"Turn Done\" refers to the client button; it is also
2607 * translated separately, the translation should be the same. */
2608 N_("If this is turned on the game turn will not advance "
2609 "until the timeout has expired, even after all players "
2610 "have clicked on \"Turn Done\"."),
2611 NULL, NULL, FALSE)
2613 GEN_STRING("demography", game.server.demography,
2614 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
2615 N_("What is in the Demographics report"),
2616 /* TRANS: The strings between double quotes should be
2617 * translated. */
2618 N_("This should be a string of characters, each of which "
2619 "specifies the inclusion of a line of information "
2620 "in the Demographics report.\n"
2621 "The characters and their meanings are:\n"
2622 " N = include Population\n"
2623 " P = include Production\n"
2624 " A = include Land Area\n"
2625 " L = include Literacy\n"
2626 " R = include Research Speed\n"
2627 " S = include Settled Area\n"
2628 " E = include Economics\n"
2629 " M = include Military Service\n"
2630 " O = include Pollution\n"
2631 " C = include Culture\n"
2632 "Additionally, the following characters control whether "
2633 "or not certain columns are displayed in the report:\n"
2634 " q = display \"quantity\" column\n"
2635 " r = display \"rank\" column\n"
2636 " b = display \"best nation\" column\n"
2637 "The order of characters is not significant, but "
2638 "their capitalization is."),
2639 demography_callback, NULL, GAME_DEFAULT_DEMOGRAPHY)
2641 GEN_INT("saveturns", game.server.save_nturns,
2642 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
2643 N_("Turns per auto-save"),
2644 /* TRANS: The string between double quotes is also translated
2645 * separately (it must match!). The string between single
2646 * quotes is a setting name and shouldn't be translated. */
2647 N_("How many turns elapse between automatic game saves. This "
2648 "setting only has an effect when the 'autosaves' setting "
2649 "includes \"New turn\"."), NULL, NULL, NULL,
2650 GAME_MIN_SAVETURNS, GAME_MAX_SAVETURNS, GAME_DEFAULT_SAVETURNS)
2652 GEN_INT("savefrequency", game.server.save_frequency,
2653 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
2654 N_("Minutes per auto-save"),
2655 /* TRANS: The string between double quotes is also translated
2656 * separately (it must match!). The string between single
2657 * quotes is a setting name and shouldn't be translated. */
2658 N_("How many minutes elapse between automatic game saves. "
2659 "Unlike other save types, this save is only meant as backup "
2660 "for computer memory, and it always uses the same name, older "
2661 "saves are not kept. This setting only has an effect when the "
2662 "'autosaves' setting includes \"Timer\"."), NULL, NULL, NULL,
2663 GAME_MIN_SAVEFREQUENCY, GAME_MAX_SAVEFREQUENCY, GAME_DEFAULT_SAVEFREQUENCY)
2665 GEN_BITWISE("autosaves", game.server.autosaves,
2666 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
2667 N_("Which savegames are generated automatically"),
2668 /* TRANS: The strings between double quotes are also translated
2669 * separately (they must match!). The strings between single
2670 * quotes are setting names and shouldn't be translated. The
2671 * strings between parentheses and in uppercase must stay as
2672 * untranslated. */
2673 N_("This setting controls which autosave types get generated:\n"
2674 "- \"New turn\" (TURN): Save when turn begins, once every "
2675 "'saveturns' turns.\n"
2676 "- \"Game over\" (GAMEOVER): Final save when game ends.\n"
2677 "- \"No player connections\" (QUITIDLE): "
2678 "Save before server restarts due to lack of players.\n"
2679 "- \"Server interrupted\" (INTERRUPT): Save when server "
2680 "quits due to interrupt.\n"
2681 "- \"Timer\" (TIMER): Save every 'savefrequency' minutes."),
2682 autosaves_callback, NULL, autosaves_name, GAME_DEFAULT_AUTOSAVES)
2684 GEN_INT("compress", game.server.save_compress_level,
2685 SSET_META, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
2686 N_("Savegame compression level"),
2687 /* TRANS: 'compresstype' setting name should not be translated. */
2688 N_("If non-zero, saved games will be compressed depending on the "
2689 "'compresstype' setting. Larger values will give better "
2690 "compression but take longer."),
2691 NULL, NULL, NULL,
2692 GAME_MIN_COMPRESS_LEVEL, GAME_MAX_COMPRESS_LEVEL, GAME_DEFAULT_COMPRESS_LEVEL)
2694 GEN_ENUM("compresstype", game.server.save_compress_type,
2695 SSET_META, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
2696 N_("Savegame compression algorithm"),
2697 N_("Compression library to use for savegames."),
2698 NULL, NULL, NULL, compresstype_name, GAME_DEFAULT_COMPRESS_TYPE)
2700 GEN_STRING("savename", game.server.save_name,
2701 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
2702 N_("Definition of the save file name"),
2703 /* TRANS: %R, %S, %T and %Y must not be translated. The
2704 * strings (examples and setting names) between single quotes
2705 * neither. The strings between <> should be translated.
2706 * xgettext:no-c-format */
2707 N_("Within the string the following custom formats are "
2708 "allowed:\n"
2709 " %R = <reason>\n"
2710 " %S = <suffix>\n"
2711 " %T = <turn-number>\n"
2712 " %Y = <game-year>\n"
2713 "\n"
2714 "Example: 'freeciv-T%04T-Y%+05Y-%R' => "
2715 "'freeciv-T0100-Y00001-manual'\n"
2716 "\n"
2717 "Be careful to use at least one of %T and %Y, else newer "
2718 "savegames will overwrite old ones. If none of the formats "
2719 "is used '-T%04T-Y%05Y-%R' is appended to the value of "
2720 "'savename'."),
2721 savename_validate, NULL, GAME_DEFAULT_SAVE_NAME)
2723 GEN_BOOL("scorelog", game.server.scorelog,
2724 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_SERVER_ONLY,
2725 N_("Whether to log player statistics"),
2726 /* TRANS: The string between single quotes is a setting name and
2727 * should not be translated. */
2728 N_("If this is turned on, player statistics are appended to "
2729 "the file defined by the option 'scorefile' every turn. "
2730 "These statistics can be used to create power graphs after "
2731 "the game."), NULL, scorelog_action, GAME_DEFAULT_SCORELOG)
2733 GEN_ENUM("scoreloglevel", game.server.scoreloglevel,
2734 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_SERVER_ONLY,
2735 N_("Scorelog level"),
2736 N_("Whether scores are logged for all players including AIs, "
2737 "or only for human players."), NULL, NULL, NULL,
2738 scoreloglevel_name, GAME_DEFAULT_SCORELOGLEVEL)
2740 GEN_STRING("scorefile", game.server.scorefile,
2741 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_SERVER_ONLY,
2742 N_("Name for the score log file"),
2743 /* TRANS: Don't translate the string in single quotes. */
2744 N_("The default name for the score log file is "
2745 "'freeciv-score.log'."),
2746 scorefile_validate, NULL, GAME_DEFAULT_SCOREFILE)
2748 GEN_INT("maxconnectionsperhost", game.server.maxconnectionsperhost,
2749 SSET_RULES_FLEXIBLE, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2750 N_("Maximum number of connections to the server per host"),
2751 N_("New connections from a given host will be rejected if "
2752 "the total number of connections from the very same host "
2753 "equals or exceeds this value. A value of 0 means that "
2754 "there is no limit, at least up to the maximum number of "
2755 "connections supported by the server."), NULL, NULL, NULL,
2756 GAME_MIN_MAXCONNECTIONSPERHOST, GAME_MAX_MAXCONNECTIONSPERHOST,
2757 GAME_DEFAULT_MAXCONNECTIONSPERHOST)
2759 GEN_INT("kicktime", game.server.kick_time,
2760 SSET_RULES_FLEXIBLE, SSET_NETWORK, SSET_RARE, SSET_SERVER_ONLY,
2761 N_("Time before a kicked user can reconnect"),
2762 /* TRANS: the string in double quotes is a server command name and
2763 * should not be translated */
2764 N_("Gives the time in seconds before a user kicked using the "
2765 "\"kick\" command may reconnect. Changing this setting will "
2766 "affect users kicked in the past."), NULL, NULL, NULL,
2767 GAME_MIN_KICK_TIME, GAME_MAX_KICK_TIME, GAME_DEFAULT_KICK_TIME)
2770 #undef GEN_BOOL
2771 #undef GEN_INT
2772 #undef GEN_STRING
2773 #undef GEN_ENUM
2774 #undef GEN_BITWISE
2776 /* The number of settings, not including the END. */
2777 static const int SETTINGS_NUM = ARRAY_SIZE(settings);
2779 /****************************************************************************
2780 Returns the setting to the given id.
2781 ****************************************************************************/
2782 struct setting *setting_by_number(int id)
2784 return (0 <= id && id < SETTINGS_NUM ? settings + id : NULL);
2787 /****************************************************************************
2788 Returns the setting to the given name.
2789 ****************************************************************************/
2790 struct setting *setting_by_name(const char *name)
2792 fc_assert_ret_val(name, NULL);
2794 settings_iterate(SSET_ALL, pset) {
2795 if (0 == strcmp(name, pset->name)) {
2796 return pset;
2798 } settings_iterate_end;
2799 return NULL;
2802 /****************************************************************************
2803 Returns the id to the given setting.
2804 ****************************************************************************/
2805 int setting_number(const struct setting *pset)
2807 fc_assert_ret_val(pset != NULL, -1);
2808 return pset - settings;
2811 /****************************************************************************
2812 Access function for the setting name.
2813 ****************************************************************************/
2814 const char *setting_name(const struct setting *pset)
2816 return pset->name;
2819 /****************************************************************************
2820 Access function for the short help (not translated yet) of the setting.
2821 ****************************************************************************/
2822 const char *setting_short_help(const struct setting *pset)
2824 return pset->short_help;
2827 /****************************************************************************
2828 Access function for the long (extra) help of the setting.
2829 If 'constant' is TRUE, static, not-yet-translated string is always returned.
2830 ****************************************************************************/
2831 const char *setting_extra_help(const struct setting *pset, bool constant)
2833 if (!constant && pset->help_func != NULL) {
2834 return pset->help_func(pset);
2837 return _(pset->extra_help);
2840 /****************************************************************************
2841 Access function for the setting type.
2842 ****************************************************************************/
2843 enum sset_type setting_type(const struct setting *pset)
2845 return pset->stype;
2848 /****************************************************************************
2849 Access function for the setting level (used by the /show command).
2850 ****************************************************************************/
2851 enum sset_level setting_level(const struct setting *pset)
2853 return pset->slevel;
2856 /****************************************************************************
2857 Access function for the setting category.
2858 ****************************************************************************/
2859 enum sset_category setting_category(const struct setting *pset)
2861 return pset->scategory;
2864 /****************************************************************************
2865 Returns whether the specified server setting (option) can currently
2866 be changed without breaking data consistency (map dimension options
2867 can't change when map has already been created with certain dimensions)
2868 ****************************************************************************/
2869 static bool setting_is_free_to_change(const struct setting *pset,
2870 char *reject_msg,
2871 size_t reject_msg_len)
2873 switch (pset->sclass) {
2874 case SSET_MAP_SIZE:
2875 case SSET_MAP_GEN:
2876 /* Only change map options if we don't yet have a map: */
2877 if (map_is_empty()) {
2878 return TRUE;
2881 settings_snprintf(reject_msg, reject_msg_len,
2882 _("The setting '%s' can't be modified after the map "
2883 "is fixed."), setting_name(pset));
2884 return FALSE;
2886 case SSET_RULES_SCENARIO:
2887 /* Like SSET_RULES except that it can be changed before the game starts
2888 * for heavy scenarios. A heavy scenario comes with players. It can
2889 * include cities, units, diplomatic relations and other complex
2890 * state. Make sure that changing a setting can't make the state of a
2891 * heavy scenario illegal if you want to change it from SSET_RULES to
2892 * SSET_RULES_SCENARIO. */
2894 if (game.scenario.is_scenario && game.scenario.players
2895 && server_state() == S_S_INITIAL) {
2896 /* Special case detected. */
2897 return TRUE;
2900 /* The special case didn't make it legal to change the setting. Don't
2901 * give up. It could still be legal. Fall through so the non special
2902 * cases are checked too. */
2904 case SSET_MAP_ADD:
2905 case SSET_PLAYERS:
2906 case SSET_GAME_INIT:
2907 case SSET_RULES:
2908 /* Only change start params and most rules if we don't yet have a map,
2909 * or if we do have a map but its a scenario one (ie, the game has
2910 * never actually been started).
2912 if (map_is_empty() || game.info.is_new_game) {
2913 return TRUE;
2916 settings_snprintf(reject_msg, reject_msg_len,
2917 _("The setting '%s' can't be modified after the game "
2918 "has started."), setting_name(pset));
2919 return FALSE;
2921 case SSET_RULES_FLEXIBLE:
2922 case SSET_META:
2923 /* These can always be changed: */
2924 return TRUE;
2927 log_error("Wrong class variant for setting %s (%d): %d.",
2928 setting_name(pset), setting_number(pset), pset->sclass);
2929 settings_snprintf(reject_msg, reject_msg_len, _("Internal error."));
2931 return FALSE;
2934 /****************************************************************************
2935 Returns whether the specified server setting (option) can currently
2936 be changed by the caller. If it returns FALSE, the reason of the failure
2937 is available by the function setting_error().
2938 ****************************************************************************/
2939 bool setting_is_changeable(const struct setting *pset,
2940 struct connection *caller, char *reject_msg,
2941 size_t reject_msg_len)
2943 if (caller
2944 && (caller->access_level < ALLOW_BASIC
2945 || (caller->access_level < ALLOW_HACK && !pset->to_client))) {
2946 settings_snprintf(reject_msg, reject_msg_len,
2947 _("You are not allowed to change the setting '%s'."),
2948 setting_name(pset));
2949 return FALSE;
2952 if (setting_locked(pset)) {
2953 /* setting is locked by the ruleset */
2954 settings_snprintf(reject_msg, reject_msg_len,
2955 _("The setting '%s' is locked by the ruleset."),
2956 setting_name(pset));
2957 return FALSE;
2960 return setting_is_free_to_change(pset, reject_msg, reject_msg_len);
2963 /****************************************************************************
2964 Returns whether the specified server setting (option) can be seen by the
2965 caller.
2966 ****************************************************************************/
2967 bool setting_is_visible(const struct setting *pset,
2968 struct connection *caller)
2970 return (!caller
2971 || pset->to_client
2972 || caller->access_level >= ALLOW_HACK);
2975 /****************************************************************************
2976 Convert the string prefix to an integer representation.
2977 NB: This function is used for SSET_ENUM *and* SSET_BITWISE.
2979 FIXME: this mostly duplicate match_prefix_full().
2980 ****************************************************************************/
2981 static enum m_pre_result
2982 setting_match_prefix_base(const val_name_func_t name_fn,
2983 const char *prefix, int *ind_result,
2984 const char **matches, size_t max_matches,
2985 size_t *pnum_matches)
2987 const struct sset_val_name *name;
2988 size_t len = strlen(prefix);
2989 size_t num_matches;
2990 int i;
2992 *pnum_matches = 0;
2994 if (0 == len) {
2995 return M_PRE_EMPTY;
2998 for (i = 0, num_matches = 0; (name = name_fn(i)); i++) {
2999 if (0 == fc_strncasecmp(name->support, prefix, len)) {
3000 if (strlen(name->support) == len) {
3001 *ind_result = i;
3002 return M_PRE_EXACT;
3004 if (num_matches < max_matches) {
3005 matches[num_matches] = name->support;
3006 (*pnum_matches)++;
3008 if (0 == num_matches++) {
3009 *ind_result = i;
3014 if (1 == num_matches) {
3015 return M_PRE_ONLY;
3016 } else if (1 < num_matches) {
3017 return M_PRE_AMBIGUOUS;
3018 } else {
3019 return M_PRE_FAIL;
3023 /****************************************************************************
3024 Convert the string prefix to an integer representation.
3025 NB: This function is used for SSET_ENUM *and* SSET_BITWISE.
3026 ****************************************************************************/
3027 static bool setting_match_prefix(const val_name_func_t name_fn,
3028 const char *prefix, int *pvalue,
3029 char *reject_msg,
3030 size_t reject_msg_len)
3032 const char *matches[16];
3033 size_t num_matches;
3035 switch (setting_match_prefix_base(name_fn, prefix, pvalue, matches,
3036 ARRAY_SIZE(matches), &num_matches)) {
3037 case M_PRE_EXACT:
3038 case M_PRE_ONLY:
3039 return TRUE; /* Ok. */
3040 case M_PRE_AMBIGUOUS:
3042 struct astring astr = ASTRING_INIT;
3044 fc_assert(2 <= num_matches);
3045 settings_snprintf(reject_msg, reject_msg_len,
3046 _("\"%s\" prefix is ambiguous. Candidates are: %s."),
3047 prefix,
3048 astr_build_and_list(&astr, matches, num_matches));
3049 astr_free(&astr);
3051 return FALSE;
3052 case M_PRE_EMPTY:
3053 settings_snprintf(reject_msg, reject_msg_len, _("Missing value."));
3054 return FALSE;
3055 case M_PRE_LONG:
3056 case M_PRE_FAIL:
3057 case M_PRE_LAST:
3058 break;
3061 settings_snprintf(reject_msg, reject_msg_len,
3062 _("No match for \"%s\"."), prefix);
3063 return FALSE;
3066 /****************************************************************************
3067 Compute the string representation of the value for this boolean setting.
3068 ****************************************************************************/
3069 static const char *setting_bool_to_str(const struct setting *pset,
3070 bool value, bool pretty,
3071 char *buf, size_t buf_len)
3073 const struct sset_val_name *name = pset->boolean.name(value);
3075 if (pretty) {
3076 fc_snprintf(buf, buf_len, "%s", Q_(name->pretty));
3077 } else {
3078 fc_strlcpy(buf, name->support, buf_len);
3080 return buf;
3083 /****************************************************************************
3084 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3085 the reason of the failure is available in the optionnal parameter
3086 'reject_msg'.
3088 FIXME: also check the access level of pconn.
3089 ****************************************************************************/
3090 static bool setting_bool_validate_base(const struct setting *pset,
3091 const char *val, int *pint_val,
3092 struct connection *caller,
3093 char *reject_msg,
3094 size_t reject_msg_len)
3096 char buf[256];
3098 if (SSET_BOOL != pset->stype) {
3099 settings_snprintf(reject_msg, reject_msg_len,
3100 _("This setting is not a boolean."));
3101 return FALSE;
3104 sz_strlcpy(buf, val);
3105 remove_leading_trailing_spaces(buf);
3107 return (setting_match_prefix(pset->boolean.name, buf, pint_val,
3108 reject_msg, reject_msg_len)
3109 && (NULL == pset->boolean.validate
3110 || pset->boolean.validate(0 != *pint_val, caller, reject_msg,
3111 reject_msg_len)));
3114 /****************************************************************************
3115 Set the setting to 'val'. Returns TRUE on success. If it's not,
3116 the reason of the failure is available in the optionnal parameter
3117 'reject_msg'.
3118 ****************************************************************************/
3119 bool setting_bool_set(struct setting *pset, const char *val,
3120 struct connection *caller, char *reject_msg,
3121 size_t reject_msg_len)
3123 int int_val;
3125 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
3126 || !setting_bool_validate_base(pset, val, &int_val, caller,
3127 reject_msg, reject_msg_len)) {
3128 return FALSE;
3131 *pset->boolean.pvalue = (0 != int_val);
3132 return TRUE;
3135 /****************************************************************************
3136 Get value of boolean setting
3137 ****************************************************************************/
3138 bool setting_bool_get(struct setting *pset)
3140 fc_assert(setting_type(pset) == SSET_BOOL);
3142 return *pset->boolean.pvalue;
3145 /****************************************************************************
3146 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3147 the reason of the failure is available in the optionnal parameter
3148 'reject_msg'.
3149 ****************************************************************************/
3150 bool setting_bool_validate(const struct setting *pset, const char *val,
3151 struct connection *caller, char *reject_msg,
3152 size_t reject_msg_len)
3154 int int_val;
3156 return setting_bool_validate_base(pset, val, &int_val, caller,
3157 reject_msg, reject_msg_len);
3160 /****************************************************************************
3161 Convert the integer to the long support string representation of a boolean
3162 setting. This function must match the secfile_enum_name_data_fn_t type.
3163 ****************************************************************************/
3164 static const char *setting_bool_secfile_str(secfile_data_t data, int val)
3166 const struct sset_val_name *name =
3167 ((const struct setting *) data)->boolean.name(val);
3169 return (NULL != name ? name->support : NULL);
3172 /****************************************************************************
3173 Compute the string representation of the value for this integer setting.
3174 ****************************************************************************/
3175 static const char *setting_int_to_str(const struct setting *pset,
3176 int value, bool pretty,
3177 char *buf, size_t buf_len)
3179 fc_snprintf(buf, buf_len, "%d", value);
3180 return buf;
3183 /****************************************************************************
3184 Returns the minimal integer value for this setting.
3185 ****************************************************************************/
3186 int setting_int_min(const struct setting *pset)
3188 fc_assert_ret_val(pset->stype == SSET_INT, 0);
3189 return pset->integer.min_value;
3192 /****************************************************************************
3193 Returns the maximal integer value for this setting.
3194 ****************************************************************************/
3195 int setting_int_max(const struct setting *pset)
3197 fc_assert_ret_val(pset->stype == SSET_INT, 0);
3198 return pset->integer.max_value;
3201 /****************************************************************************
3202 Set the setting to 'val'. Returns TRUE on success. If it fails, the
3203 reason of the failure is available by the function setting_error().
3204 ****************************************************************************/
3205 bool setting_int_set(struct setting *pset, int val,
3206 struct connection *caller, char *reject_msg,
3207 size_t reject_msg_len)
3209 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
3210 || !setting_int_validate(pset, val, caller, reject_msg,
3211 reject_msg_len)) {
3212 return FALSE;
3215 *pset->integer.pvalue = val;
3216 return TRUE;
3219 /****************************************************************************
3220 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3221 the reason of the failure is available by the function setting_error().
3223 FIXME: also check the access level of pconn.
3224 ****************************************************************************/
3225 bool setting_int_validate(const struct setting *pset, int val,
3226 struct connection *caller, char *reject_msg,
3227 size_t reject_msg_len)
3229 if (SSET_INT != pset->stype) {
3230 settings_snprintf(reject_msg, reject_msg_len,
3231 _("This setting is not an integer."));
3232 return FALSE;
3235 if (val < pset->integer.min_value || val > pset->integer.max_value) {
3236 settings_snprintf(reject_msg, reject_msg_len,
3237 _("Value out of range: %d (min: %d; max: %d)."),
3238 val, pset->integer.min_value, pset->integer.max_value);
3239 return FALSE;
3242 return (!pset->integer.validate
3243 || pset->integer.validate(val, caller, reject_msg,
3244 reject_msg_len));
3247 /****************************************************************************
3248 Get value of integer setting
3249 ****************************************************************************/
3250 int setting_int_get(struct setting *pset)
3252 fc_assert(setting_type(pset) == SSET_INT);
3254 return *pset->integer.pvalue;
3257 /****************************************************************************
3258 Compute the string representation of the value for this string setting.
3259 ****************************************************************************/
3260 static const char *setting_str_to_str(const struct setting *pset,
3261 const char *value, bool pretty,
3262 char *buf, size_t buf_len)
3264 if (pretty) {
3265 fc_snprintf(buf, buf_len, "\"%s\"", value);
3266 } else {
3267 fc_strlcpy(buf, value, buf_len);
3269 return buf;
3272 /****************************************************************************
3273 Set the setting to 'val'. Returns TRUE on success. If it fails, the
3274 reason of the failure is available by the function setting_error().
3275 ****************************************************************************/
3276 bool setting_str_set(struct setting *pset, const char *val,
3277 struct connection *caller, char *reject_msg,
3278 size_t reject_msg_len)
3280 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
3281 || !setting_str_validate(pset, val, caller, reject_msg,
3282 reject_msg_len)) {
3283 return FALSE;
3286 fc_strlcpy(pset->string.value, val, pset->string.value_size);
3287 return TRUE;
3290 /****************************************************************************
3291 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3292 the reason of the failure is available by the function setting_error().
3294 FIXME: also check the access level of pconn.
3295 ****************************************************************************/
3296 bool setting_str_validate(const struct setting *pset, const char *val,
3297 struct connection *caller, char *reject_msg,
3298 size_t reject_msg_len)
3300 if (SSET_STRING != pset->stype) {
3301 settings_snprintf(reject_msg, reject_msg_len,
3302 _("This setting is not a string."));
3303 return FALSE;
3306 if (strlen(val) >= pset->string.value_size) {
3307 settings_snprintf(reject_msg, reject_msg_len,
3308 _("String value too long (max length: %lu)."),
3309 (unsigned long) pset->string.value_size);
3310 return FALSE;
3313 return (!pset->string.validate
3314 || pset->string.validate(val, caller, reject_msg,
3315 reject_msg_len));
3318 /****************************************************************************
3319 Get value of string setting
3320 ****************************************************************************/
3321 char *setting_str_get(struct setting *pset)
3323 fc_assert(setting_type(pset) == SSET_STRING);
3325 return pset->string.value;
3328 /****************************************************************************
3329 Convert the integer to the long support string representation of an
3330 enumerator. This function must match the secfile_enum_name_data_fn_t type.
3331 ****************************************************************************/
3332 const char *setting_enum_secfile_str(secfile_data_t data, int val)
3334 const struct sset_val_name *name =
3335 ((const struct setting *) data)->enumerator.name(val);
3337 return (NULL != name ? name->support : NULL);
3340 /****************************************************************************
3341 Convert the integer to the string representation of an enumerator.
3342 Return NULL if 'val' is not a valid enumerator.
3343 ****************************************************************************/
3344 const char *setting_enum_val(const struct setting *pset, int val,
3345 bool pretty)
3347 const struct sset_val_name *name;
3349 fc_assert_ret_val(SSET_ENUM == pset->stype, NULL);
3350 name = pset->enumerator.name(val);
3351 if (NULL == name) {
3352 return NULL;
3353 } else if (pretty) {
3354 return _(name->pretty);
3355 } else {
3356 return name->support;
3360 /****************************************************************************
3361 Compute the string representation of the value for this enumerator
3362 setting.
3363 ****************************************************************************/
3364 static const char *setting_enum_to_str(const struct setting *pset,
3365 int value, bool pretty,
3366 char *buf, size_t buf_len)
3368 const struct sset_val_name *name = pset->enumerator.name(value);
3370 if (pretty) {
3371 fc_snprintf(buf, buf_len, "\"%s\" (%s)",
3372 Q_(name->pretty), name->support);
3373 } else {
3374 fc_strlcpy(buf, name->support, buf_len);
3376 return buf;
3379 /****************************************************************************
3380 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3381 the reason of the failure is available in the optionnal parameter
3382 'reject_msg'.
3384 FIXME: also check the access level of pconn.
3385 ****************************************************************************/
3386 static bool setting_enum_validate_base(const struct setting *pset,
3387 const char *val, int *pint_val,
3388 struct connection *caller,
3389 char *reject_msg,
3390 size_t reject_msg_len)
3392 char buf[256];
3394 if (SSET_ENUM != pset->stype) {
3395 settings_snprintf(reject_msg, reject_msg_len,
3396 _("This setting is not an enumerator."));
3397 return FALSE;
3400 sz_strlcpy(buf, val);
3401 remove_leading_trailing_spaces(buf);
3403 return (setting_match_prefix(pset->enumerator.name, buf, pint_val,
3404 reject_msg, reject_msg_len)
3405 && (NULL == pset->enumerator.validate
3406 || pset->enumerator.validate(*pint_val, caller, reject_msg,
3407 reject_msg_len)));
3410 /****************************************************************************
3411 Helper function to write value to enumerator setting
3412 ****************************************************************************/
3413 static bool set_enum_value(struct setting *pset, int val)
3415 switch(pset->enumerator.store_size) {
3416 case sizeof(int):
3418 int *to_int = pset->enumerator.pvalue;
3420 *to_int = val;
3422 break;
3423 case sizeof(char):
3425 char *to_char = pset->enumerator.pvalue;
3427 *to_char = (char) val;
3429 break;
3430 case sizeof(short):
3432 short *to_short = pset->enumerator.pvalue;
3434 *to_short = (short) val;
3436 break;
3437 default:
3438 return FALSE;
3441 return TRUE;
3444 /****************************************************************************
3445 Helper function to read value from enumerator setting
3446 ****************************************************************************/
3447 int read_enum_value(const struct setting *pset)
3449 int val;
3451 switch(pset->enumerator.store_size) {
3452 case sizeof(int):
3453 val = *((int *)pset->enumerator.pvalue);
3454 break;
3455 case sizeof(char):
3456 val = *((char *)pset->enumerator.pvalue);
3457 break;
3458 case sizeof(short):
3459 val = *((short *)pset->enumerator.pvalue);
3460 break;
3461 default:
3462 log_error("Illegal enum store size %d, can't read value", pset->enumerator.store_size);
3463 return 0;
3466 return val;
3469 /****************************************************************************
3470 Set the setting to 'val'. Returns TRUE on success. If it fails, the
3471 reason of the failure is available in the optionnal parameter
3472 'reject_msg'.
3473 ****************************************************************************/
3474 bool setting_enum_set(struct setting *pset, const char *val,
3475 struct connection *caller, char *reject_msg,
3476 size_t reject_msg_len)
3478 int int_val;
3480 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)) {
3481 return FALSE;
3484 if (!setting_enum_validate_base(pset, val, &int_val, caller,
3485 reject_msg, reject_msg_len)) {
3486 return FALSE;
3489 if (!set_enum_value(pset, int_val)) {
3490 log_error("Illegal enumerator value size %d for %s",
3491 pset->enumerator.store_size, val);
3492 return FALSE;
3495 return TRUE;
3498 /****************************************************************************
3499 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3500 the reason of the failure is available in the optionnal parameter
3501 'reject_msg'.
3502 ****************************************************************************/
3503 bool setting_enum_validate(const struct setting *pset, const char *val,
3504 struct connection *caller, char *reject_msg,
3505 size_t reject_msg_len)
3507 int int_val;
3509 return setting_enum_validate_base(pset, val, &int_val, caller,
3510 reject_msg, reject_msg_len);
3513 /****************************************************************************
3514 Convert the integer to the long support string representation of an
3515 enumerator. This function must match the secfile_enum_name_data_fn_t type.
3516 ****************************************************************************/
3517 const char *setting_bitwise_secfile_str(secfile_data_t data, int bit)
3519 const struct sset_val_name *name =
3520 ((const struct setting *) data)->bitwise.name(bit);
3522 return (NULL != name ? name->support : NULL);
3525 /****************************************************************************
3526 Convert the bit number to its string representation.
3527 Return NULL if 'bit' is not a valid bit.
3528 ****************************************************************************/
3529 const char *setting_bitwise_bit(const struct setting *pset,
3530 int bit, bool pretty)
3532 const struct sset_val_name *name;
3534 fc_assert_ret_val(SSET_BITWISE == pset->stype, NULL);
3535 name = pset->bitwise.name(bit);
3536 if (NULL == name) {
3537 return NULL;
3538 } else if (pretty) {
3539 return _(name->pretty);
3540 } else {
3541 return name->support;
3545 /****************************************************************************
3546 Compute the string representation of the value for this bitwise setting.
3547 ****************************************************************************/
3548 static const char *setting_bitwise_to_str(const struct setting *pset,
3549 unsigned value, bool pretty,
3550 char *buf, size_t buf_len)
3552 const struct sset_val_name *name;
3553 char *old_buf = buf;
3554 int bit;
3556 if (pretty) {
3557 char buf2[256];
3558 struct astring astr = ASTRING_INIT;
3559 struct strvec *vec = strvec_new();
3560 size_t len;
3562 for (bit = 0; (name = pset->bitwise.name(bit)); bit++) {
3563 if ((1 << bit) & value) {
3564 /* TRANS: only emphasizing a string. */
3565 fc_snprintf(buf2, sizeof(buf2), _("\"%s\""), Q_(name->pretty));
3566 strvec_append(vec, buf2);
3570 if (0 == strvec_size(vec)) {
3571 /* No value. */
3572 fc_assert(0 == value);
3573 /* TRANS: Bitwise setting has no bits set. */
3574 fc_strlcpy(buf, _("empty value"), buf_len);
3575 strvec_destroy(vec);
3576 return buf;
3579 strvec_to_and_list(vec, &astr);
3580 strvec_destroy(vec);
3581 fc_strlcpy(buf, astr_str(&astr), buf_len);
3582 astr_free(&astr);
3583 fc_strlcat(buf, " (", buf_len);
3584 len = strlen(buf);
3585 buf += len;
3586 buf_len -= len;
3589 /* Long support part. */
3590 buf[0] = '\0';
3591 for (bit = 0; (name = pset->bitwise.name(bit)); bit++) {
3592 if ((1 << bit) & value) {
3593 if ('\0' != buf[0]) {
3594 fc_strlcat(buf, "|", buf_len);
3596 fc_strlcat(buf, name->support, buf_len);
3600 if (pretty) {
3601 fc_strlcat(buf, ")", buf_len);
3603 return old_buf;
3606 /****************************************************************************
3607 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3608 the reason of the failure is available in the optionnal parameter
3609 'reject_msg'.
3611 FIXME: also check the access level of pconn.
3612 ****************************************************************************/
3613 static bool setting_bitwise_validate_base(const struct setting *pset,
3614 const char *val,
3615 unsigned *pint_val,
3616 struct connection *caller,
3617 char *reject_msg,
3618 size_t reject_msg_len)
3620 char buf[256];
3621 const char *p;
3622 int bit;
3624 if (SSET_BITWISE != pset->stype) {
3625 settings_snprintf(reject_msg, reject_msg_len,
3626 _("This setting is not a bitwise."));
3627 return FALSE;
3630 *pint_val = 0;
3632 /* Value names are separated by '|'. */
3633 do {
3634 p = strchr(val, '|');
3635 if (NULL != p) {
3636 p++;
3637 fc_strlcpy(buf, val, MIN(p - val, sizeof(buf)));
3638 } else {
3639 /* Last segment, full copy. */
3640 sz_strlcpy(buf, val);
3642 remove_leading_trailing_spaces(buf);
3643 if (NULL == p && '\0' == buf[0] && 0 == *pint_val) {
3644 /* Empty string = value 0. */
3645 break;
3646 } else if (!setting_match_prefix(pset->bitwise.name, buf, &bit,
3647 reject_msg, reject_msg_len)) {
3648 return FALSE;
3650 *pint_val |= 1 << bit;
3651 val = p;
3652 } while (NULL != p);
3654 return (NULL == pset->bitwise.validate
3655 || pset->bitwise.validate(*pint_val, caller,
3656 reject_msg, reject_msg_len));
3659 /****************************************************************************
3660 Set the setting to 'val'. Returns TRUE on success. If it fails, the
3661 reason of the failure is available in the optionnal parameter
3662 'reject_msg'.
3663 ****************************************************************************/
3664 bool setting_bitwise_set(struct setting *pset, const char *val,
3665 struct connection *caller, char *reject_msg,
3666 size_t reject_msg_len)
3668 unsigned int_val;
3670 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
3671 || !setting_bitwise_validate_base(pset, val, &int_val, caller,
3672 reject_msg, reject_msg_len)) {
3673 return FALSE;
3676 *pset->bitwise.pvalue = int_val;
3677 return TRUE;
3680 /****************************************************************************
3681 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3682 the reason of the failure is available in the optionnal parameter
3683 'reject_msg'.
3684 ****************************************************************************/
3685 bool setting_bitwise_validate(const struct setting *pset, const char *val,
3686 struct connection *caller, char *reject_msg,
3687 size_t reject_msg_len)
3689 unsigned int_val;
3691 return setting_bitwise_validate_base(pset, val, &int_val, caller,
3692 reject_msg, reject_msg_len);
3695 /****************************************************************************
3696 Get value of bitwise setting
3697 ****************************************************************************/
3698 int setting_bitwise_get(struct setting *pset)
3700 fc_assert(setting_type(pset) == SSET_BITWISE);
3702 return *pset->bitwise.pvalue;
3705 /****************************************************************************
3706 Compute the name of the current value of the setting.
3707 ****************************************************************************/
3708 const char *setting_value_name(const struct setting *pset, bool pretty,
3709 char *buf, size_t buf_len)
3711 fc_assert_ret_val(NULL != pset, NULL);
3712 fc_assert_ret_val(NULL != buf, NULL);
3713 fc_assert_ret_val(0 < buf_len, NULL);
3715 switch (pset->stype) {
3716 case SSET_BOOL:
3717 return setting_bool_to_str(pset, *pset->boolean.pvalue,
3718 pretty, buf, buf_len);
3719 case SSET_INT:
3720 return setting_int_to_str(pset, *pset->integer.pvalue,
3721 pretty, buf, buf_len);
3722 case SSET_STRING:
3723 return setting_str_to_str(pset, pset->string.value,
3724 pretty, buf, buf_len);
3725 case SSET_ENUM:
3726 return setting_enum_to_str(pset, read_enum_value(pset),
3727 pretty, buf, buf_len);
3728 case SSET_BITWISE:
3729 return setting_bitwise_to_str(pset, *pset->bitwise.pvalue,
3730 pretty, buf, buf_len);
3733 log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
3734 __FUNCTION__, setting_name(pset), setting_number(pset));
3735 return NULL;
3738 /****************************************************************************
3739 Compute the name of the default value of the setting.
3740 ****************************************************************************/
3741 const char *setting_default_name(const struct setting *pset, bool pretty,
3742 char *buf, size_t buf_len)
3744 fc_assert_ret_val(NULL != pset, NULL);
3745 fc_assert_ret_val(NULL != buf, NULL);
3746 fc_assert_ret_val(0 < buf_len, NULL);
3748 switch (pset->stype) {
3749 case SSET_BOOL:
3750 return setting_bool_to_str(pset, pset->boolean.default_value,
3751 pretty, buf, buf_len);
3752 case SSET_INT:
3753 return setting_int_to_str(pset, pset->integer.default_value,
3754 pretty, buf, buf_len);
3755 case SSET_STRING:
3756 return setting_str_to_str(pset, pset->string.default_value,
3757 pretty, buf, buf_len);
3758 case SSET_ENUM:
3759 return setting_enum_to_str(pset, pset->enumerator.default_value,
3760 pretty, buf, buf_len);
3761 case SSET_BITWISE:
3762 return setting_bitwise_to_str(pset, pset->bitwise.default_value,
3763 pretty, buf, buf_len);
3766 log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
3767 __FUNCTION__, setting_name(pset), setting_number(pset));
3768 return NULL;
3771 /****************************************************************************
3772 Update the setting to the default value
3773 ****************************************************************************/
3774 void setting_set_to_default(struct setting *pset)
3776 switch (pset->stype) {
3777 case SSET_BOOL:
3778 (*pset->boolean.pvalue) = pset->boolean.default_value;
3779 break;
3780 case SSET_INT:
3781 (*pset->integer.pvalue) = pset->integer.default_value;
3782 break;
3783 case SSET_STRING:
3784 fc_strlcpy(pset->string.value, pset->string.default_value,
3785 pset->string.value_size);
3786 break;
3787 case SSET_ENUM:
3788 set_enum_value(pset, pset->enumerator.default_value);
3789 break;
3790 case SSET_BITWISE:
3791 (*pset->bitwise.pvalue) = pset->bitwise.default_value;
3792 break;
3795 pset->setdef = SETDEF_INTERNAL;
3798 /********************************************************************
3799 Execute the action callback if needed.
3800 *********************************************************************/
3801 void setting_action(const struct setting *pset)
3803 if (pset->action != NULL) {
3804 pset->action(pset);
3808 /**************************************************************************
3809 Load game settings from ruleset file 'game.ruleset'.
3810 **************************************************************************/
3811 bool settings_ruleset(struct section_file *file, const char *section,
3812 bool act)
3814 const char *name;
3815 int j;
3817 /* Unlock all settings. */
3818 settings_iterate(SSET_ALL, pset) {
3819 setting_lock_set(pset, FALSE);
3820 setting_set_to_default(pset);
3821 } settings_iterate_end;
3823 /* settings */
3824 if (NULL == secfile_section_by_name(file, section)) {
3825 /* no settings in ruleset file */
3826 log_verbose("no [%s] section for game settings in %s", section,
3827 secfile_name(file));
3828 } else {
3829 for (j = 0; (name = secfile_lookup_str_default(file, NULL, "%s.set%d.name",
3830 section, j)); j++) {
3831 char path[256];
3832 fc_snprintf(path, sizeof(path), "%s.set%d", section, j);
3834 if (!setting_ruleset_one(file, name, path)) {
3835 log_error("unknown setting in '%s': %s", secfile_name(file), name);
3840 /* Execute all setting actions to consider actions due to the
3841 * default values. */
3842 if (act) {
3843 settings_iterate(SSET_ALL, pset) {
3844 setting_action(pset);
3845 } settings_iterate_end;
3848 autolock_settings();
3850 /* send game settings */
3851 send_server_settings(NULL);
3853 return TRUE;
3856 /**************************************************************************
3857 Set one setting from the game.ruleset file.
3858 **************************************************************************/
3859 static bool setting_ruleset_one(struct section_file *file,
3860 const char *name, const char *path)
3862 struct setting *pset = NULL;
3863 char reject_msg[256], buf[256];
3864 bool lock;
3866 settings_iterate(SSET_ALL, pset_check) {
3867 if (0 == fc_strcasecmp(setting_name(pset_check), name)) {
3868 pset = pset_check;
3869 break;
3871 } settings_iterate_end;
3873 if (pset == NULL) {
3874 /* no setting found */
3875 return FALSE;
3878 switch (pset->stype) {
3879 case SSET_BOOL:
3881 int ival;
3882 bool val;
3884 /* Allow string with same boolean representation as accepted on
3885 * server command line */
3886 if (secfile_lookup_enum_data(file, &ival, FALSE,
3887 setting_bool_secfile_str, pset,
3888 "%s.value", path)) {
3889 val = (ival != 0);
3890 } else if (!secfile_lookup_bool(file, &val, "%s.value", path)) {
3891 log_error("Can't read value for setting '%s': %s", name,
3892 secfile_error());
3893 break;
3895 if (val != *pset->boolean.pvalue) {
3896 if (NULL == pset->boolean.validate
3897 || pset->boolean.validate(val, NULL, reject_msg,
3898 sizeof(reject_msg))) {
3899 *pset->boolean.pvalue = val;
3900 log_normal(_("Ruleset: '%s' has been set to %s."),
3901 setting_name(pset),
3902 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3903 } else {
3904 log_error("%s", reject_msg);
3908 break;
3910 case SSET_INT:
3912 int val;
3914 if (!secfile_lookup_int(file, &val, "%s.value", path)) {
3915 log_error("Can't read value for setting '%s': %s", name,
3916 secfile_error());
3917 } else if (val != *pset->integer.pvalue) {
3918 if (setting_int_set(pset, val, NULL, reject_msg,
3919 sizeof(reject_msg))) {
3920 log_normal(_("Ruleset: '%s' has been set to %s."),
3921 setting_name(pset),
3922 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3923 } else {
3924 log_error("%s", reject_msg);
3928 break;
3930 case SSET_STRING:
3932 const char *val = secfile_lookup_str(file, "%s.value", path);
3934 if (NULL == val) {
3935 log_error("Can't read value for setting '%s': %s", name,
3936 secfile_error());
3937 } else if (0 != strcmp(val, pset->string.value)) {
3938 if (setting_str_set(pset, val, NULL, reject_msg,
3939 sizeof(reject_msg))) {
3940 log_normal(_("Ruleset: '%s' has been set to %s."),
3941 setting_name(pset),
3942 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3943 } else {
3944 log_error("%s", reject_msg);
3948 break;
3950 case SSET_ENUM:
3952 int val;
3954 if (!secfile_lookup_enum_data(file, &val, FALSE,
3955 setting_enum_secfile_str, pset,
3956 "%s.value", path)) {
3957 log_error("Can't read value for setting '%s': %s",
3958 name, secfile_error());
3959 } else if (val != read_enum_value(pset)) {
3960 if (NULL == pset->enumerator.validate
3961 || pset->enumerator.validate(val, NULL, reject_msg,
3962 sizeof(reject_msg))) {
3963 set_enum_value(pset, val);
3964 log_normal(_("Ruleset: '%s' has been set to %s."),
3965 setting_name(pset),
3966 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3967 } else {
3968 log_error("%s", reject_msg);
3972 break;
3974 case SSET_BITWISE:
3976 int val;
3978 if (!secfile_lookup_enum_data(file, &val, TRUE,
3979 setting_bitwise_secfile_str, pset,
3980 "%s.value", path)) {
3981 log_error("Can't read value for setting '%s': %s",
3982 name, secfile_error());
3983 } else if (val != *pset->bitwise.pvalue) {
3984 if (NULL == pset->bitwise.validate
3985 || pset->bitwise.validate((unsigned) val, NULL,
3986 reject_msg, sizeof(reject_msg))) {
3987 *pset->bitwise.pvalue = val;
3988 log_normal(_("Ruleset: '%s' has been set to %s."),
3989 setting_name(pset),
3990 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3991 } else {
3992 log_error("%s", reject_msg);
3996 break;
3999 pset->setdef = SETDEF_RULESET;
4001 /* set lock */
4002 lock = secfile_lookup_bool_default(file, FALSE, "%s.lock", path);
4004 if (lock) {
4005 /* set lock */
4006 setting_lock_set(pset, lock);
4007 log_normal(_("Ruleset: '%s' has been locked by the ruleset."),
4008 setting_name(pset));
4011 return TRUE;
4014 /**************************************************************************
4015 Returns whether the setting has non-default value.
4016 **************************************************************************/
4017 bool setting_non_default(const struct setting *pset)
4019 switch (setting_type(pset)) {
4020 case SSET_BOOL:
4021 return (*pset->boolean.pvalue != pset->boolean.default_value);
4022 case SSET_INT:
4023 return (*pset->integer.pvalue != pset->integer.default_value);
4024 case SSET_STRING:
4025 return (0 != strcmp(pset->string.value, pset->string.default_value));
4026 case SSET_ENUM:
4027 return (read_enum_value(pset) != pset->enumerator.default_value);
4028 case SSET_BITWISE:
4029 return (*pset->bitwise.pvalue != pset->bitwise.default_value);
4032 log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
4033 __FUNCTION__, setting_name(pset), setting_number(pset));
4034 return FALSE;
4037 /**************************************************************************
4038 Returns if the setting is locked by the ruleset.
4039 **************************************************************************/
4040 bool setting_locked(const struct setting *pset)
4042 return pset->locked;
4045 /**************************************************************************
4046 Set the value for the lock of a setting.
4047 **************************************************************************/
4048 void setting_lock_set(struct setting *pset, bool lock)
4050 pset->locked = lock;
4053 /**************************************************************************
4054 Save the setting value of the current game.
4055 **************************************************************************/
4056 static void setting_game_set(struct setting *pset, bool init)
4058 switch (setting_type(pset)) {
4059 case SSET_BOOL:
4060 pset->boolean.game_value = *pset->boolean.pvalue;
4061 break;
4063 case SSET_INT:
4064 pset->integer.game_value = *pset->integer.pvalue;
4065 break;
4067 case SSET_STRING:
4068 if (init) {
4069 pset->string.game_value
4070 = fc_calloc(1, pset->string.value_size
4071 * sizeof(pset->string.game_value));
4073 fc_strlcpy(pset->string.game_value, pset->string.value,
4074 pset->string.value_size);
4075 break;
4077 case SSET_ENUM:
4078 pset->enumerator.game_value = read_enum_value(pset);
4079 break;
4081 case SSET_BITWISE:
4082 pset->bitwise.game_value = *pset->bitwise.pvalue;
4083 break;
4087 /**************************************************************************
4088 Free the memory used for the settings at game start.
4089 **************************************************************************/
4090 static void setting_game_free(struct setting *pset)
4092 if (setting_type(pset) == SSET_STRING) {
4093 FC_FREE(pset->string.game_value);
4097 /**************************************************************************
4098 Restore the setting to the value used at the start of the current game.
4099 **************************************************************************/
4100 static void setting_game_restore(struct setting *pset)
4102 char reject_msg[256] = "", buf[256];
4103 bool res = FALSE;
4105 if (!setting_is_changeable(pset, NULL, reject_msg, sizeof(reject_msg))) {
4106 log_debug("Can't restore '%s': %s", setting_name(pset),
4107 reject_msg);
4108 return;
4111 switch (setting_type(pset)) {
4112 case SSET_BOOL:
4113 res = (NULL != setting_bool_to_str(pset, pset->boolean.game_value,
4114 FALSE, buf, sizeof(buf))
4115 && setting_bool_set(pset, buf, NULL, reject_msg,
4116 sizeof(reject_msg)));
4117 break;
4119 case SSET_INT:
4120 res = setting_int_set(pset, pset->integer.game_value, NULL, reject_msg,
4121 sizeof(reject_msg));
4122 break;
4124 case SSET_STRING:
4125 res = setting_str_set(pset, pset->string.game_value, NULL, reject_msg,
4126 sizeof(reject_msg));
4127 break;
4129 case SSET_ENUM:
4130 res = (NULL != setting_enum_to_str(pset, pset->enumerator.game_value,
4131 FALSE, buf, sizeof(buf))
4132 && setting_enum_set(pset, buf, NULL, reject_msg,
4133 sizeof(reject_msg)));
4134 break;
4136 case SSET_BITWISE:
4137 res = (NULL != setting_bitwise_to_str(pset, pset->bitwise.game_value,
4138 FALSE, buf, sizeof(buf))
4139 && setting_bitwise_set(pset, buf, NULL, reject_msg,
4140 sizeof(reject_msg)));
4141 break;
4144 if (!res) {
4145 log_error("Error restoring setting '%s' to the value from game start: "
4146 "%s", setting_name(pset), reject_msg);
4150 /**************************************************************************
4151 Save setting values at the start of the game.
4152 **************************************************************************/
4153 void settings_game_start(void)
4155 settings_iterate(SSET_ALL, pset) {
4156 setting_game_set(pset, FALSE);
4157 } settings_iterate_end;
4159 /* Settings from the start of the game are saved. */
4160 game.server.settings_gamestart_valid = TRUE;
4163 /********************************************************************
4164 Save game settings.
4165 *********************************************************************/
4166 void settings_game_save(struct section_file *file, const char *section)
4168 int set_count = 0;
4170 settings_iterate(SSET_ALL, pset) {
4171 char errbuf[200];
4173 if (/* It's explicitly set to some value to save */
4174 setting_get_setdef(pset) == SETDEF_CHANGED
4175 /* It must be same at loading time as it was saving time, even if
4176 * freeciv's default has changed. */
4177 || !setting_is_free_to_change(pset, errbuf, sizeof(errbuf))) {
4178 secfile_insert_str(file, setting_name(pset),
4179 "%s.set%d.name", section, set_count);
4180 switch (setting_type(pset)) {
4181 case SSET_BOOL:
4182 secfile_insert_bool(file, *pset->boolean.pvalue,
4183 "%s.set%d.value", section, set_count);
4184 secfile_insert_bool(file, pset->boolean.game_value,
4185 "%s.set%d.gamestart", section, set_count);
4186 break;
4187 case SSET_INT:
4188 secfile_insert_int(file, *pset->integer.pvalue,
4189 "%s.set%d.value", section, set_count);
4190 secfile_insert_int(file, pset->integer.game_value,
4191 "%s.set%d.gamestart", section, set_count);
4192 break;
4193 case SSET_STRING:
4194 secfile_insert_str(file, pset->string.value,
4195 "%s.set%d.value", section, set_count);
4196 secfile_insert_str(file, pset->string.game_value,
4197 "%s.set%d.gamestart", section, set_count);
4198 break;
4199 case SSET_ENUM:
4200 secfile_insert_enum_data(file, read_enum_value(pset), FALSE,
4201 setting_enum_secfile_str, pset,
4202 "%s.set%d.value", section, set_count);
4203 secfile_insert_enum_data(file, pset->enumerator.game_value, FALSE,
4204 setting_enum_secfile_str, pset,
4205 "%s.set%d.gamestart", section, set_count);
4206 break;
4207 case SSET_BITWISE:
4208 secfile_insert_enum_data(file, *pset->bitwise.pvalue, TRUE,
4209 setting_bitwise_secfile_str, pset,
4210 "%s.set%d.value", section, set_count);
4211 secfile_insert_enum_data(file, pset->bitwise.game_value, TRUE,
4212 setting_bitwise_secfile_str, pset,
4213 "%s.set%d.gamestart", section, set_count);
4214 break;
4216 set_count++;
4218 } settings_iterate_end;
4220 secfile_insert_int(file, set_count, "%s.set_count", section);
4221 secfile_insert_bool(file, game.server.settings_gamestart_valid,
4222 "%s.gamestart_valid", section);
4225 /********************************************************************
4226 Restore all settings from a savegame.
4227 *********************************************************************/
4228 void settings_game_load(struct section_file *file, const char *section)
4230 const char *name;
4231 char reject_msg[256], buf[256];
4232 int i, set_count;
4233 int oldcitymindist = game.info.citymindist; /* backwards compat, see below */
4235 /* Compatibility with savegames created with older versions is usually
4236 * handled as conversions in savecompat.c compat_load_<version>() */
4238 if (!secfile_lookup_int(file, &set_count, "%s.set_count", section)) {
4239 /* Old savegames and scenarios doesn't contain this, not an error. */
4240 log_verbose("Can't read the number of settings in the save file.");
4241 return;
4244 /* Check if the saved settings are valid settings from game start. */
4245 game.server.settings_gamestart_valid
4246 = secfile_lookup_bool_default(file, FALSE, "%s.gamestart_valid",
4247 section);
4249 for (i = 0; i < set_count; i++) {
4250 name = secfile_lookup_str(file, "%s.set%d.name", section, i);
4252 settings_iterate(SSET_ALL, pset) {
4253 if (fc_strcasecmp(setting_name(pset), name) != 0) {
4254 continue;
4257 /* Load the current value of the setting. */
4258 switch (pset->stype) {
4259 case SSET_BOOL:
4261 bool val;
4263 if (!secfile_lookup_bool(file, &val, "%s.set%d.value", section,
4264 i)) {
4265 log_verbose("Option '%s' not defined in the savegame: %s", name,
4266 secfile_error());
4267 } else {
4268 pset->setdef = SETDEF_CHANGED;
4270 if (val != *pset->boolean.pvalue) {
4271 if (setting_is_changeable(pset, NULL, reject_msg,
4272 sizeof(reject_msg))
4273 && (NULL == pset->boolean.validate
4274 || pset->boolean.validate(val, NULL, reject_msg,
4275 sizeof(reject_msg)))) {
4276 *pset->boolean.pvalue = val;
4277 log_normal(_("Savegame: '%s' has been set to %s."),
4278 setting_name(pset),
4279 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4280 } else {
4281 log_error("Savegame: error restoring '%s' . (%s)",
4282 setting_name(pset), reject_msg);
4284 } else {
4285 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4286 setting_name(pset));
4290 break;
4292 case SSET_INT:
4294 int val;
4296 if (!secfile_lookup_int(file, &val, "%s.set%d.value", section, i)) {
4297 log_verbose("Option '%s' not defined in the savegame: %s", name,
4298 secfile_error());
4299 } else {
4300 pset->setdef = SETDEF_CHANGED;
4302 if (val != *pset->integer.pvalue) {
4303 if (setting_is_changeable(pset, NULL, reject_msg,
4304 sizeof(reject_msg))
4305 && (NULL == pset->integer.validate
4306 || pset->integer.validate(val, NULL, reject_msg,
4307 sizeof(reject_msg)))) {
4308 *pset->integer.pvalue = val;
4309 log_normal(_("Savegame: '%s' has been set to %s."),
4310 setting_name(pset),
4311 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4312 } else {
4313 log_error("Savegame: error restoring '%s' . (%s)",
4314 setting_name(pset), reject_msg);
4316 } else {
4317 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4318 setting_name(pset));
4322 break;
4324 case SSET_STRING:
4326 const char *val = secfile_lookup_str(file, "%s.set%d.value",
4327 section, i);
4329 if (NULL == val) {
4330 log_verbose("Option '%s' not defined in the savegame: %s", name,
4331 secfile_error());
4332 } else {
4333 pset->setdef = SETDEF_CHANGED;
4335 if (0 != strcmp(val, pset->string.value)) {
4336 if (setting_str_set(pset, val, NULL, reject_msg,
4337 sizeof(reject_msg))) {
4338 log_normal(_("Savegame: '%s' has been set to %s."),
4339 setting_name(pset),
4340 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4341 } else {
4342 log_error("Savegame: error restoring '%s' . (%s)",
4343 setting_name(pset), reject_msg);
4345 } else {
4346 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4347 setting_name(pset));
4351 break;
4353 case SSET_ENUM:
4355 int val;
4357 if (!secfile_lookup_enum_data(file, &val, FALSE,
4358 setting_enum_secfile_str, pset,
4359 "%s.set%d.value", section, i)) {
4360 log_verbose("Option '%s' not defined in the savegame: %s", name,
4361 secfile_error());
4362 } else {
4363 pset->setdef = SETDEF_CHANGED;
4365 if (val != read_enum_value(pset)) {
4366 if (setting_is_changeable(pset, NULL, reject_msg,
4367 sizeof(reject_msg))
4368 && (NULL == pset->enumerator.validate
4369 || pset->enumerator.validate(val, NULL, reject_msg,
4370 sizeof(reject_msg)))) {
4371 set_enum_value(pset, val);
4372 log_normal(_("Savegame: '%s' has been set to %s."),
4373 setting_name(pset),
4374 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4375 } else {
4376 log_error("Savegame: error restoring '%s' . (%s)",
4377 setting_name(pset), reject_msg);
4379 } else {
4380 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4381 setting_name(pset));
4385 break;
4387 case SSET_BITWISE:
4389 int val;
4391 if (!secfile_lookup_enum_data(file, &val, TRUE,
4392 setting_bitwise_secfile_str, pset,
4393 "%s.set%d.value", section, i)) {
4394 log_verbose("Option '%s' not defined in the savegame: %s", name,
4395 secfile_error());
4396 } else {
4397 pset->setdef = SETDEF_CHANGED;
4399 if (val != *pset->bitwise.pvalue) {
4400 if (setting_is_changeable(pset, NULL, reject_msg,
4401 sizeof(reject_msg))
4402 && (NULL == pset->bitwise.validate
4403 || pset->bitwise.validate(val, NULL, reject_msg,
4404 sizeof(reject_msg)))) {
4405 *pset->bitwise.pvalue = val;
4406 log_normal(_("Savegame: '%s' has been set to %s."),
4407 setting_name(pset),
4408 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4409 } else {
4410 log_error("Savegame: error restoring '%s' . (%s)",
4411 setting_name(pset), reject_msg);
4413 } else {
4414 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4415 setting_name(pset));
4419 break;
4422 if (game.server.settings_gamestart_valid) {
4423 /* Load the value of the setting at the start of the game. */
4424 switch (pset->stype) {
4425 case SSET_BOOL:
4426 pset->boolean.game_value =
4427 secfile_lookup_bool_default(file, *pset->boolean.pvalue,
4428 "%s.set%d.gamestart", section, i);
4429 break;
4431 case SSET_INT:
4432 pset->integer.game_value =
4433 secfile_lookup_int_default(file, *pset->integer.pvalue,
4434 "%s.set%d.gamestart", section, i);
4435 break;
4437 case SSET_STRING:
4438 fc_strlcpy(pset->string.game_value,
4439 secfile_lookup_str_default(file, pset->string.value,
4440 "%s.set%d.gamestart",
4441 section, i),
4442 pset->string.value_size);
4443 break;
4445 case SSET_ENUM:
4446 pset->enumerator.game_value =
4447 secfile_lookup_enum_default_data(file,
4448 read_enum_value(pset), FALSE, setting_enum_secfile_str,
4449 pset, "%s.set%d.gamestart", section, i);
4450 break;
4452 case SSET_BITWISE:
4453 pset->bitwise.game_value =
4454 secfile_lookup_enum_default_data(file,
4455 *pset->bitwise.pvalue, TRUE, setting_bitwise_secfile_str,
4456 pset, "%s.set%d.gamestart", section, i);
4457 break;
4460 pset->setdef = SETDEF_CHANGED;
4462 } settings_iterate_end;
4465 /* Backwards compatibility for pre-2.4 savegames: citymindist=0 used to mean
4466 * take from ruleset min_dist_bw_cities, but that no longer exists.
4467 * This is here rather than in savegame2.c compat functions, as we need
4468 * to have loaded the relevant ruleset to know what to set it to (the
4469 * ruleset and any 'citymindist' setting it contains will have been loaded
4470 * before this function was called). */
4471 if (game.info.citymindist == 0) {
4472 game.info.citymindist = oldcitymindist;
4475 settings_iterate(SSET_ALL, pset) {
4476 /* Have to do this at the end due to dependencies ('aifill' and
4477 * 'maxplayer'). */
4478 setting_action(pset);
4479 } settings_iterate_end;
4482 /**************************************************************************
4483 Reset all settings to the values at game start.
4484 **************************************************************************/
4485 bool settings_game_reset(void)
4487 if (!game.server.settings_gamestart_valid) {
4488 log_debug("No saved settings from the game start available.");
4489 return FALSE;
4492 settings_iterate(SSET_ALL, pset) {
4493 setting_game_restore(pset);
4494 } settings_iterate_end;
4496 return TRUE;
4499 /**************************************************************************
4500 Initialize stuff related to this code module.
4501 **************************************************************************/
4502 void settings_init(bool act)
4504 settings_list_init();
4506 settings_iterate(SSET_ALL, pset) {
4507 setting_lock_set(pset, FALSE);
4508 setting_set_to_default(pset);
4509 setting_game_set(pset, TRUE);
4510 if (act) {
4511 setting_action(pset);
4513 } settings_iterate_end;
4515 settings_list_update();
4518 /********************************************************************
4519 Reset all settings iff they are changeable.
4520 *********************************************************************/
4521 void settings_reset(void)
4523 settings_iterate(SSET_ALL, pset) {
4524 if (setting_is_changeable(pset, NULL, NULL, 0)) {
4525 setting_set_to_default(pset);
4526 setting_action(pset);
4528 } settings_iterate_end;
4531 /**************************************************************************
4532 Update stuff every turn that is related to this code module. Run this
4533 on turn end.
4534 **************************************************************************/
4535 void settings_turn(void)
4537 /* Nothing at the moment. */
4540 /**************************************************************************
4541 Deinitialize stuff related to this code module.
4542 **************************************************************************/
4543 void settings_free(void)
4545 settings_iterate(SSET_ALL, pset) {
4546 setting_game_free(pset);
4547 } settings_iterate_end;
4549 settings_list_free();
4552 /****************************************************************************
4553 Returns the total number of settings.
4554 ****************************************************************************/
4555 int settings_number(void)
4557 return SETTINGS_NUM;
4560 /****************************************************************************
4561 Tell the client about just one server setting. Call this after a setting
4562 is saved.
4563 ****************************************************************************/
4564 void send_server_setting(struct conn_list *dest, const struct setting *pset)
4566 if (!dest) {
4567 dest = game.est_connections;
4570 #define PACKET_COMMON_INIT(packet, pset, pconn) \
4571 memset(&packet, 0, sizeof(packet)); \
4572 packet.id = setting_number(pset); \
4573 packet.is_visible = setting_is_visible(pset, pconn); \
4574 packet.is_changeable = setting_is_changeable(pset, pconn, NULL, 0); \
4575 packet.initial_setting = game.info.is_new_game;
4577 switch (setting_type(pset)) {
4578 case SSET_BOOL:
4580 struct packet_server_setting_bool packet;
4582 conn_list_iterate(dest, pconn) {
4583 PACKET_COMMON_INIT(packet, pset, pconn);
4584 if (packet.is_visible) {
4585 packet.val = *pset->boolean.pvalue;
4586 packet.default_val = pset->boolean.default_value;
4588 send_packet_server_setting_bool(pconn, &packet);
4589 } conn_list_iterate_end;
4591 break;
4592 case SSET_INT:
4594 struct packet_server_setting_int packet;
4596 conn_list_iterate(dest, pconn) {
4597 PACKET_COMMON_INIT(packet, pset, pconn);
4598 if (packet.is_visible) {
4599 packet.val = *pset->integer.pvalue;
4600 packet.default_val = pset->integer.default_value;
4601 packet.min_val = pset->integer.min_value;
4602 packet.max_val = pset->integer.max_value;
4604 send_packet_server_setting_int(pconn, &packet);
4605 } conn_list_iterate_end;
4607 break;
4608 case SSET_STRING:
4610 struct packet_server_setting_str packet;
4612 conn_list_iterate(dest, pconn) {
4613 PACKET_COMMON_INIT(packet, pset, pconn);
4614 if (packet.is_visible) {
4615 sz_strlcpy(packet.val, pset->string.value);
4616 sz_strlcpy(packet.default_val, pset->string.default_value);
4618 send_packet_server_setting_str(pconn, &packet);
4619 } conn_list_iterate_end;
4621 break;
4622 case SSET_ENUM:
4624 struct packet_server_setting_enum packet;
4625 const struct sset_val_name *val_name;
4626 int i;
4628 conn_list_iterate(dest, pconn) {
4629 PACKET_COMMON_INIT(packet, pset, pconn);
4630 if (packet.is_visible) {
4631 packet.val = read_enum_value(pset);
4632 packet.default_val = pset->enumerator.default_value;
4633 for (i = 0; (val_name = pset->enumerator.name(i)); i++) {
4634 sz_strlcpy(packet.support_names[i], val_name->support);
4635 /* Send untranslated string */
4636 sz_strlcpy(packet.pretty_names[i], val_name->pretty);
4638 packet.values_num = i;
4639 fc_assert(i <= ARRAY_SIZE(packet.support_names));
4640 fc_assert(i <= ARRAY_SIZE(packet.pretty_names));
4642 send_packet_server_setting_enum(pconn, &packet);
4643 } conn_list_iterate_end;
4645 break;
4646 case SSET_BITWISE:
4648 struct packet_server_setting_bitwise packet;
4649 const struct sset_val_name *val_name;
4650 int i;
4652 conn_list_iterate(dest, pconn) {
4653 PACKET_COMMON_INIT(packet, pset, pconn);
4654 if (packet.is_visible) {
4655 packet.val = *pset->bitwise.pvalue;
4656 packet.default_val = pset->bitwise.default_value;
4657 for (i = 0; (val_name = pset->bitwise.name(i)); i++) {
4658 sz_strlcpy(packet.support_names[i], val_name->support);
4659 /* Send untranslated string */
4660 sz_strlcpy(packet.pretty_names[i], val_name->pretty);
4662 packet.bits_num = i;
4663 fc_assert(i <= ARRAY_SIZE(packet.support_names));
4664 fc_assert(i <= ARRAY_SIZE(packet.pretty_names));
4666 send_packet_server_setting_bitwise(pconn, &packet);
4667 } conn_list_iterate_end;
4669 break;
4672 #undef PACKET_INIT
4675 /****************************************************************************
4676 Tell the client about all server settings.
4677 ****************************************************************************/
4678 void send_server_settings(struct conn_list *dest)
4680 settings_iterate(SSET_ALL, pset) {
4681 send_server_setting(dest, pset);
4682 } settings_iterate_end;
4685 /****************************************************************************
4686 Send the ALLOW_HACK server settings. Usually called when the access level
4687 of the user changes.
4688 ****************************************************************************/
4689 void send_server_hack_level_settings(struct conn_list *dest)
4691 settings_iterate(SSET_ALL, pset) {
4692 if (!pset->to_client) {
4693 send_server_setting(dest, pset);
4695 } settings_iterate_end;
4698 /****************************************************************************
4699 Tell the client about all server settings.
4700 ****************************************************************************/
4701 void send_server_setting_control(struct connection *pconn)
4703 struct packet_server_setting_control control;
4704 struct packet_server_setting_const setting;
4705 int i;
4707 control.settings_num = SETTINGS_NUM;
4709 /* Fill in the category strings. */
4710 fc_assert(SSET_NUM_CATEGORIES <= ARRAY_SIZE(control.category_names));
4711 control.categories_num = SSET_NUM_CATEGORIES;
4712 for (i = 0; i < SSET_NUM_CATEGORIES; i++) {
4713 /* Send untranslated name */
4714 sz_strlcpy(control.category_names[i], sset_category_name(i));
4717 /* Send off the control packet. */
4718 send_packet_server_setting_control(pconn, &control);
4720 /* Send the constant and common part of the settings. */
4721 settings_iterate(SSET_ALL, pset) {
4722 setting.id = setting_number(pset);
4723 sz_strlcpy(setting.name, setting_name(pset));
4724 /* Send untranslated strings to client */
4725 sz_strlcpy(setting.short_help, setting_short_help(pset));
4726 sz_strlcpy(setting.extra_help, setting_extra_help(pset, TRUE));
4727 setting.category = pset->scategory;
4729 send_packet_server_setting_const(pconn, &setting);
4730 } settings_iterate_end;
4733 /*****************************************************************************
4734 Initialise sorted settings.
4735 *****************************************************************************/
4736 static void settings_list_init(void)
4738 struct setting *pset;
4739 int i;
4741 fc_assert_ret(setting_sorted.init == FALSE);
4743 /* Do it for all values of enum sset_level. */
4744 for (i = 0; i < OLEVELS_NUM; i++) {
4745 setting_sorted.level[i] = setting_list_new();
4748 for (i = 0; (pset = setting_by_number(i)); i++) {
4749 /* Add the setting to the list of all settings. */
4750 setting_list_append(setting_sorted.level[SSET_ALL], pset);
4752 switch (setting_level(pset)) {
4753 case SSET_NONE:
4754 /* No setting should be in this level. */
4755 fc_assert_msg(setting_level(pset) != SSET_NONE,
4756 "No setting level defined for '%s'.", setting_name(pset));
4757 break;
4758 case SSET_ALL:
4759 /* Done above - list of all settings. */
4760 break;
4761 case SSET_VITAL:
4762 setting_list_append(setting_sorted.level[SSET_VITAL], pset);
4763 break;
4764 case SSET_SITUATIONAL:
4765 setting_list_append(setting_sorted.level[SSET_SITUATIONAL], pset);
4766 break;
4767 case SSET_RARE:
4768 setting_list_append(setting_sorted.level[SSET_RARE], pset);
4769 break;
4770 case SSET_CHANGED:
4771 case SSET_LOCKED:
4772 /* This is done in settings_list_update. */
4773 break;
4774 case OLEVELS_NUM:
4775 /* No setting should be in this level. */
4776 fc_assert_msg(setting_level(pset) != OLEVELS_NUM,
4777 "Invalid setting level for '%s' (%s).",
4778 setting_name(pset), sset_level_name(setting_level(pset)));
4779 break;
4783 /* Sort the lists. */
4784 for (i = 0; i < OLEVELS_NUM; i++) {
4785 setting_list_sort(setting_sorted.level[i], settings_list_cmp);
4788 setting_sorted.init = TRUE;
4791 /*****************************************************************************
4792 Update sorted settings (changed and locked values).
4793 *****************************************************************************/
4794 void settings_list_update(void)
4796 struct setting *pset;
4797 int i;
4799 fc_assert_ret(setting_sorted.init == TRUE);
4801 /* Clear the lists for changed and locked values. */
4802 setting_list_clear(setting_sorted.level[SSET_CHANGED]);
4803 setting_list_clear(setting_sorted.level[SSET_LOCKED]);
4805 /* Refill them. */
4806 for (i = 0; (pset = setting_by_number(i)); i++) {
4807 if (setting_non_default(pset)) {
4808 setting_list_append(setting_sorted.level[SSET_CHANGED], pset);
4810 if (setting_locked(pset)) {
4811 setting_list_append(setting_sorted.level[SSET_LOCKED], pset);
4815 /* Sort them. */
4816 setting_list_sort(setting_sorted.level[SSET_CHANGED], settings_list_cmp);
4817 setting_list_sort(setting_sorted.level[SSET_LOCKED], settings_list_cmp);
4820 /*****************************************************************************
4821 Update sorted settings (changed and locked values).
4822 *****************************************************************************/
4823 int settings_list_cmp(const struct setting *const *ppset1,
4824 const struct setting *const *ppset2)
4826 const struct setting *pset1 = *ppset1;
4827 const struct setting *pset2 = *ppset2;
4829 return fc_strcasecmp(setting_name(pset1), setting_name(pset2));
4832 /*****************************************************************************
4833 Get a settings list of a certain level. Call settings_list_update() before
4834 if something was changed.
4835 *****************************************************************************/
4836 struct setting_list *settings_list_get(enum sset_level level)
4838 fc_assert_ret_val(setting_sorted.init == TRUE, NULL);
4839 fc_assert_ret_val(setting_sorted.level[level] != NULL, NULL);
4840 fc_assert_ret_val(sset_level_is_valid(level), NULL);
4842 return setting_sorted.level[level];
4845 /*****************************************************************************
4846 Free sorted settings.
4847 *****************************************************************************/
4848 static void settings_list_free(void)
4850 int i;
4852 fc_assert_ret(setting_sorted.init == TRUE);
4854 /* Free the lists. */
4855 for (i = 0; i < OLEVELS_NUM; i++) {
4856 setting_list_destroy(setting_sorted.level[i]);
4859 setting_sorted.init = FALSE;
4862 /*****************************************************************************
4863 Mark setting changed
4864 *****************************************************************************/
4865 void setting_changed(struct setting *pset)
4867 pset->setdef = SETDEF_CHANGED;
4870 /*****************************************************************************
4871 Is the setting in changed state, or the default
4872 *****************************************************************************/
4873 enum setting_default_level setting_get_setdef(struct setting *pset)
4875 return pset->setdef;
4878 /*****************************************************************************
4879 Compatibility function. In the very old times there was no concept of
4880 'default' value outside setting initialization, all values were handled
4881 like we now want to handle non-default ones.
4882 *****************************************************************************/
4883 void settings_consider_all_changed(void)
4885 settings_iterate(SSET_ALL, pset) {
4886 pset->setdef = SETDEF_CHANGED;
4887 } settings_iterate_end;