Made ruleset comments about extra activity graphic value "None" more verbose.
[freeciv.git] / server / settings.c
blob26bfffa14676bcdf0e516649e00337ca505381a8
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 string 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 Topology 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 {.boolean = {&value, _default, func_validate, bool_name, \
1220 FALSE}}, func_action, FALSE},
1222 #define GEN_INT(name, value, sclass, scateg, slevel, to_client, \
1223 short_help, extra_help, func_help, \
1224 func_validate, func_action, \
1225 _min, _max, _default) \
1226 {name, sclass, to_client, short_help, extra_help, func_help, SSET_INT, \
1227 scateg, slevel, \
1228 {.integer = {(int *) &value, _default, _min, _max, func_validate, \
1229 0}}, \
1230 func_action, FALSE},
1232 #define GEN_STRING(name, value, sclass, scateg, slevel, to_client, \
1233 short_help, extra_help, func_validate, func_action, \
1234 _default) \
1235 {name, sclass, to_client, short_help, extra_help, NULL, SSET_STRING, \
1236 scateg, slevel, \
1237 {.string = {value, _default, sizeof(value), func_validate, ""}}, \
1238 func_action, FALSE},
1240 #define GEN_ENUM(name, value, sclass, scateg, slevel, to_client, \
1241 short_help, extra_help, func_help, func_validate, \
1242 func_action, func_name, _default) \
1243 { name, sclass, to_client, short_help, extra_help, func_help, SSET_ENUM, \
1244 scateg, slevel, \
1245 { .enumerator = { &value, sizeof(value), _default, \
1246 func_validate, \
1247 (val_name_func_t) func_name, 0 }}, func_action, FALSE},
1249 #define GEN_BITWISE(name, value, sclass, scateg, slevel, to_client, \
1250 short_help, extra_help, func_validate, func_action, \
1251 func_name, _default) \
1252 { name, sclass, to_client, short_help, extra_help, NULL, SSET_BITWISE, \
1253 scateg, slevel, \
1254 { .bitwise = { (unsigned *) (void *) &value, _default, func_validate, \
1255 func_name, 0 }}, func_action, FALSE},
1257 /* game settings */
1258 static struct setting settings[] = {
1260 /* These should be grouped by sclass */
1262 /* Map size parameters: adjustable if we don't yet have a map */
1263 GEN_ENUM("mapsize", game.map.server.mapsize, SSET_MAP_SIZE,
1264 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1265 N_("Map size definition"),
1266 /* TRANS: The strings between double quotes are also translated
1267 * separately (they must match!). The strings between single
1268 * quotes are setting names and shouldn't be translated. The
1269 * strings between parentheses and in uppercase must stay as
1270 * untranslated. */
1271 N_("Chooses the method used to define the map size. Other options "
1272 "specify the parameters for each method.\n"
1273 "- \"Number of tiles\" (FULLSIZE): Map area (option 'size').\n"
1274 "- \"Tiles per player\" (PLAYER): Number of (land) tiles per "
1275 "player (option 'tilesperplayer').\n"
1276 "- \"Width and height\" (XYSIZE): Map width and height in "
1277 "tiles (options 'xsize' and 'ysize')."), NULL,
1278 mapsize_callback, NULL, mapsize_name, MAP_DEFAULT_MAPSIZE)
1280 GEN_INT("size", game.map.server.size, SSET_MAP_SIZE,
1281 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1282 N_("Map area (in thousands of tiles)"),
1283 /* TRANS: The strings between double quotes are also translated
1284 * separately (they must match!). The strings between single
1285 * quotes are setting names and shouldn't be translated. The
1286 * strings between parentheses and in uppercase must stay as
1287 * untranslated. */
1288 N_("This value is used to determine the map area.\n"
1289 " size = 4 is a normal map of 4,000 tiles (default)\n"
1290 " size = 20 is a huge map of 20,000 tiles\n"
1291 "For this option to take effect, the \"Map size definition\" "
1292 "option ('mapsize') must be set to \"Number of tiles\" "
1293 "(FULLSIZE)."), NULL, NULL, NULL,
1294 MAP_MIN_SIZE, MAP_MAX_SIZE, MAP_DEFAULT_SIZE)
1296 GEN_INT("tilesperplayer", game.map.server.tilesperplayer, SSET_MAP_SIZE,
1297 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1298 N_("Number of (land) tiles per player"),
1299 /* TRANS: The strings between double quotes are also translated
1300 * separately (they must match!). The strings between single
1301 * quotes are setting names and shouldn't be translated. The
1302 * strings between parentheses and in uppercase must stay as
1303 * untranslated. */
1304 N_("This value is used to determine the map dimensions. It "
1305 "calculates the map size at game start based on the number "
1306 "of players and the value of the setting 'landmass'.\n"
1307 "For this option to take effect, the \"Map size definition\" "
1308 "option ('mapsize') must be set to \"Tiles per player\" "
1309 "(PLAYER)."),
1310 NULL, NULL, NULL, MAP_MIN_TILESPERPLAYER,
1311 MAP_MAX_TILESPERPLAYER, MAP_DEFAULT_TILESPERPLAYER)
1313 GEN_INT("xsize", game.map.xsize, SSET_MAP_SIZE,
1314 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1315 N_("Map width in tiles"),
1316 /* TRANS: The strings between double quotes are also translated
1317 * separately (they must match!). The strings between single
1318 * quotes are setting names and shouldn't be translated. The
1319 * strings between parentheses and in uppercase must stay as
1320 * untranslated. */
1321 N_("Defines the map width.\n"
1322 "For this option to take effect, the \"Map size definition\" "
1323 "option ('mapsize') must be set to \"Width and height\" "
1324 "(XYSIZE)."),
1325 NULL, xsize_callback, NULL,
1326 MAP_MIN_LINEAR_SIZE, MAP_MAX_LINEAR_SIZE, MAP_DEFAULT_LINEAR_SIZE)
1327 GEN_INT("ysize", game.map.ysize, SSET_MAP_SIZE,
1328 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1329 N_("Map height in tiles"),
1330 /* TRANS: The strings between double quotes are also translated
1331 * separately (they must match!). The strings between single
1332 * quotes are setting names and shouldn't be translated. The
1333 * strings between parentheses and in uppercase must stay as
1334 * untranslated. */
1335 N_("Defines the map height.\n"
1336 "For this option to take effect, the \"Map size definition\" "
1337 "option ('mapsize') must be set to \"Width and height\" "
1338 "(XYSIZE)."),
1339 NULL, ysize_callback, NULL,
1340 MAP_MIN_LINEAR_SIZE, MAP_MAX_LINEAR_SIZE, MAP_DEFAULT_LINEAR_SIZE)
1342 GEN_BITWISE("topology", game.map.topology_id, SSET_MAP_SIZE,
1343 SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1344 N_("Map topology index"),
1345 /* TRANS: do not edit the ugly ASCII art */
1346 N_("Freeciv maps are always two-dimensional. They may wrap at "
1347 "the north-south and east-west directions to form a flat "
1348 "map, a cylinder, or a torus (donut). Individual tiles may "
1349 "be rectangular or hexagonal, with either a classic or "
1350 "isometric alignment - this should be set based on the "
1351 "tileset being used.\n"
1352 "Classic rectangular: Isometric rectangular:\n"
1353 " _________ /\\/\\/\\/\\/\\\n"
1354 " |_|_|_|_|_| /\\/\\/\\/\\/\\/\n"
1355 " |_|_|_|_|_| \\/\\/\\/\\/\\/\\\n"
1356 " |_|_|_|_|_| /\\/\\/\\/\\/\\/\n"
1357 " \\/\\/\\/\\/\\/\n"
1358 "Hex tiles: Iso-hex:\n"
1359 " /\\/\\/\\/\\/\\/\\ _ _ _ _ _\n"
1360 " | | | | | | | / \\_/ \\_/ \\_/ \\_/ \\\n"
1361 " \\/\\/\\/\\/\\/\\/\\"
1362 " \\_/ \\_/ \\_/ \\_/ \\_/\n"
1363 " | | | | | | | / \\_/ \\_/ \\_/ \\_/ \\\n"
1364 " \\/\\/\\/\\/\\/\\/"
1365 " \\_/ \\_/ \\_/ \\_/ \\_/\n"),
1366 topology_callback, topology_action, topology_name, MAP_DEFAULT_TOPO)
1368 GEN_ENUM("generator", game.map.server.generator,
1369 SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1370 N_("Method used to generate map"),
1371 /* TRANS: The strings between double quotes are also translated
1372 * separately (they must match!). The strings between single
1373 * quotes (except 'fair') are setting names and shouldn't be
1374 * translated. The strings between parentheses and in uppercase
1375 * must stay as untranslated. */
1376 N_("Specifies the algorithm used to generate the map. If the "
1377 "default value of the 'startpos' option is used, then the "
1378 "chosen generator chooses an appropriate 'startpos' setting; "
1379 "otherwise, the generated map tries to accommodate the "
1380 "chosen 'startpos' setting.\n"
1381 "- \"Scenario map\" (SCENARIO): indicates a pre-generated map. "
1382 "By default, if the scenario does not specify start positions, "
1383 "they will be allocated depending on the size of continents.\n"
1384 "- \"Fully random height\" (RANDOM): generates maps with a "
1385 "number of equally spaced, relatively small islands. By default, "
1386 "start positions are allocated depending on continent size.\n"
1387 "- \"Pseudo-fractal height\" (FRACTAL): generates Earthlike "
1388 "worlds with one or more large continents and a scattering of "
1389 "smaller islands. By default, players are all placed on a "
1390 "single continent.\n"
1391 "- \"Island-based\" (ISLAND): generates 'fair' maps with a "
1392 "number of similarly-sized and -shaped islands, each with "
1393 "approximately the same ratios of terrain types. By default, "
1394 "each player gets their own island.\n"
1395 "- \"Fair islands\" (FAIR): generates the exact copy of the "
1396 "same island for every player or every team.\n"
1397 "If the requested generator is incompatible with other server "
1398 "settings, the server may fall back to another generator."),
1399 NULL, generator_validate, NULL, generator_name, MAP_DEFAULT_GENERATOR)
1401 GEN_ENUM("startpos", game.map.server.startpos,
1402 SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1403 N_("Method used to choose start positions"),
1404 /* TRANS: The strings between double quotes are also translated
1405 * separately (they must match!). The strings between single
1406 * quotes (except 'best') are setting names and shouldn't be
1407 * translated. The strings between parentheses and in uppercase
1408 * must stay as untranslated. */
1409 N_("The method used to choose where each player's initial units "
1410 "start on the map. (For scenarios which include pre-set "
1411 "start positions, this setting is ignored.)\n"
1412 "- \"Generator's choice\" (DEFAULT): the start position "
1413 "placement will depend on the map generator chosen. See the "
1414 "'generator' setting.\n"
1415 "- \"One player per continent\" (SINGLE): one player is "
1416 "placed on each of a set of continents of approximately "
1417 "equivalent value (if possible).\n"
1418 "- \"Two or three players per continent\" (2or3): similar "
1419 "to SINGLE except that two players will be placed on each "
1420 "continent, with three on the 'best' continent if there is an "
1421 "odd number of players.\n"
1422 "- \"All players on a single continent\" (ALL): all players "
1423 "will start on the 'best' available continent.\n"
1424 "- \"Depending on size of continents\" (VARIABLE): players "
1425 "will be placed on the 'best' available continents such that, "
1426 "as far as possible, the number of players on each continent "
1427 "is proportional to its value.\n"
1428 "If the server cannot satisfy the requested setting due to "
1429 "there being too many players for continents, it may fall "
1430 "back to one of the others. (However, map generators try to "
1431 "create the right number of continents for the choice of this "
1432 "'startpos' setting and the number of players, so this is "
1433 "unlikely to occur.)"),
1434 NULL, NULL, NULL, startpos_name, MAP_DEFAULT_STARTPOS)
1436 GEN_ENUM("teamplacement", game.map.server.team_placement,
1437 SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1438 N_("Method used for placement of team mates"),
1439 /* TRANS: The strings between double quotes are also translated
1440 * separately (they must match!). The strings between single
1441 * quotes are setting names and shouldn't be translated. The
1442 * strings between parentheses and in uppercase must stay as
1443 * untranslated. */
1444 N_("After start positions have been generated thanks to the "
1445 "'startpos' setting, this setting controls how the start "
1446 "positions will be assigned to the different players of the "
1447 "same team.\n"
1448 "- \"Disabled\" (DISABLED): the start positions will be "
1449 "randomly assigned to players, regardless of teams.\n"
1450 "- \"As close as possible\" (CLOSEST): players will be "
1451 "placed as close as possible, regardless of continents.\n"
1452 "- \"On the same continent\" (CONTINENT): if possible, place "
1453 "all players of the same team onto the same "
1454 "island/continent.\n"
1455 "- \"Horizontal placement\" (HORIZONTAL): players of the same "
1456 "team will be placed horizontally.\n"
1457 "- \"Vertical placement\" (VERTICAL): players of the same "
1458 "team will be placed vertically."),
1459 NULL, NULL, NULL, teamplacement_name, MAP_DEFAULT_TEAM_PLACEMENT)
1461 GEN_BOOL("tinyisles", game.map.server.tinyisles,
1462 SSET_MAP_GEN, SSET_GEOLOGY, SSET_RARE, SSET_TO_CLIENT,
1463 N_("Presence of 1x1 islands"),
1464 N_("This setting controls whether the map generator is allowed "
1465 "to make islands of one only tile size."), NULL, NULL,
1466 MAP_DEFAULT_TINYISLES)
1468 GEN_BOOL("separatepoles", game.map.server.separatepoles,
1469 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1470 N_("Whether the poles are separate continents"),
1471 N_("If this setting is disabled, the continents may attach to "
1472 "poles."), NULL, NULL, MAP_DEFAULT_SEPARATE_POLES)
1474 GEN_INT("flatpoles", game.map.server.flatpoles,
1475 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1476 N_("How much the land at the poles is flattened"),
1477 /* TRANS: The strings in quotes shouldn't be translated. */
1478 N_("Controls how much the height of the poles is flattened "
1479 "during map generation, preventing a diversity of land "
1480 "terrain there. 0 is no flattening, 100 is maximum "
1481 "flattening. Only affects the 'RANDOM' and 'FRACTAL' "
1482 "map generators."), NULL,
1483 NULL, NULL,
1484 MAP_MIN_FLATPOLES, MAP_MAX_FLATPOLES, MAP_DEFAULT_FLATPOLES)
1486 GEN_BOOL("singlepole", game.map.server.single_pole,
1487 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1488 N_("Whether there's just one pole generated"),
1489 N_("If this setting is enabled, only one side of the map will have "
1490 "a pole. This setting has no effect if the map wraps both "
1491 "directions."), NULL, NULL, MAP_DEFAULT_SINGLE_POLE)
1493 GEN_BOOL("alltemperate", game.map.server.alltemperate,
1494 SSET_MAP_GEN, SSET_GEOLOGY, SSET_RARE, SSET_TO_CLIENT,
1495 N_("All the map is temperate"),
1496 N_("If this setting is enabled, the temperature will be "
1497 "equivalent everywhere on the map. As a result, the "
1498 "poles won't be generated."),
1499 NULL, NULL, MAP_DEFAULT_ALLTEMPERATE)
1501 GEN_INT("temperature", game.map.server.temperature,
1502 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1503 N_("Average temperature of the planet"),
1504 N_("Small values will give a cold map, while larger values will "
1505 "give a hotter map.\n"
1506 "\n"
1507 "100 means a very dry and hot planet with no polar arctic "
1508 "zones, only tropical and dry zones.\n"
1509 " 70 means a hot planet with little polar ice.\n"
1510 " 50 means a temperate planet with normal polar, cold, "
1511 "temperate, and tropical zones; a desert zone overlaps "
1512 "tropical and temperate zones.\n"
1513 " 30 means a cold planet with small tropical zones.\n"
1514 " 0 means a very cold planet with large polar zones and no "
1515 "tropics."),
1516 NULL, NULL, NULL,
1517 MAP_MIN_TEMPERATURE, MAP_MAX_TEMPERATURE, MAP_DEFAULT_TEMPERATURE)
1519 GEN_INT("landmass", game.map.server.landpercent,
1520 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1521 N_("Percentage of the map that is land"),
1522 N_("This setting gives the approximate percentage of the map "
1523 "that will be made into land."), NULL, NULL, NULL,
1524 MAP_MIN_LANDMASS, MAP_MAX_LANDMASS, MAP_DEFAULT_LANDMASS)
1526 GEN_INT("steepness", game.map.server.steepness,
1527 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1528 N_("Amount of hills/mountains"),
1529 N_("Small values give flat maps, while higher values give a "
1530 "steeper map with more hills and mountains."),
1531 NULL, NULL, NULL,
1532 MAP_MIN_STEEPNESS, MAP_MAX_STEEPNESS, MAP_DEFAULT_STEEPNESS)
1534 GEN_INT("wetness", game.map.server.wetness,
1535 SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1536 N_("Amount of water on landmasses"),
1537 N_("Small values mean lots of dry, desert-like land; "
1538 "higher values give a wetter map with more swamps, "
1539 "jungles, and rivers."), NULL, NULL, NULL,
1540 MAP_MIN_WETNESS, MAP_MAX_WETNESS, MAP_DEFAULT_WETNESS)
1542 GEN_BOOL("globalwarming", game.info.global_warming,
1543 SSET_RULES, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1544 N_("Global warming"),
1545 N_("If turned off, global warming will not occur "
1546 "as a result of pollution. This setting does not "
1547 "affect pollution."), NULL, NULL,
1548 GAME_DEFAULT_GLOBAL_WARMING)
1550 GEN_BOOL("nuclearwinter", game.info.nuclear_winter,
1551 SSET_RULES, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1552 N_("Nuclear winter"),
1553 N_("If turned off, nuclear winter will not occur "
1554 "as a result of nuclear war."), NULL, NULL,
1555 GAME_DEFAULT_NUCLEAR_WINTER)
1557 GEN_INT("mapseed", game.map.server.seed_setting,
1558 SSET_MAP_GEN, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
1559 N_("Map generation random seed"),
1560 N_("The same seed will always produce the same map; "
1561 "for zero (the default) a seed will be chosen based on "
1562 "the time to give a random map."),
1563 NULL, NULL, NULL,
1564 MAP_MIN_SEED, MAP_MAX_SEED, MAP_DEFAULT_SEED)
1566 /* Map additional stuff: huts and specials. gameseed also goes here
1567 * because huts and specials are the first time the gameseed gets used (?)
1568 * These are done when the game starts, so these are historical and
1569 * fixed after the game has started.
1571 GEN_INT("gameseed", game.server.seed_setting,
1572 SSET_MAP_ADD, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
1573 N_("Game random seed"),
1574 N_("For zero (the default) a seed will be chosen based "
1575 "on the current time."),
1576 NULL, NULL, NULL,
1577 GAME_MIN_SEED, GAME_MAX_SEED, GAME_DEFAULT_SEED)
1579 GEN_INT("specials", game.map.server.riches,
1580 SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1581 N_("Amount of \"special\" resource tiles"),
1582 N_("Special resources improve the basic terrain type they "
1583 "are on. The server variable's scale is parts per "
1584 "thousand."), NULL, NULL, NULL,
1585 MAP_MIN_RICHES, MAP_MAX_RICHES, MAP_DEFAULT_RICHES)
1587 GEN_INT("huts", game.map.server.huts,
1588 SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1589 N_("Amount of huts (bonus extras)"),
1590 N_("This setting gives number of huts that will be "
1591 "placed on every one thousand tiles. Huts are "
1592 "tile extras that may be investigated by units."),
1593 huts_help, NULL, huts_action,
1594 MAP_MIN_HUTS, MAP_MAX_HUTS, MAP_DEFAULT_HUTS)
1596 GEN_INT("animals", game.map.server.animals,
1597 SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1598 N_("Amount of animals"),
1599 N_("Amount of animals initially created to terrains "
1600 "defined for them in the ruleset. "
1601 "The server variable's scale is animals per "
1602 "thousand tiles."), NULL, NULL, NULL,
1603 MAP_MIN_ANIMALS, MAP_MAX_ANIMALS, MAP_DEFAULT_ANIMALS)
1605 /* Options affecting numbers of players and AI players. These only
1606 * affect the start of the game and can not be adjusted after that.
1608 GEN_INT("minplayers", game.server.min_players,
1609 SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL,
1610 SSET_TO_CLIENT,
1611 N_("Minimum number of players"),
1612 N_("There must be at least this many players (connected "
1613 "human players) before the game can start."),
1614 NULL, NULL, NULL,
1615 GAME_MIN_MIN_PLAYERS, GAME_MAX_MIN_PLAYERS, GAME_DEFAULT_MIN_PLAYERS)
1617 GEN_INT("maxplayers", game.server.max_players,
1618 SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
1619 N_("Maximum number of players"),
1620 N_("The maximal number of human and AI players who can be in "
1621 "the game. When this number of players are connected in "
1622 "the pregame state, any new players who try to connect "
1623 "will be rejected.\n"
1624 "When playing a scenario which defines player start positions, "
1625 "this setting cannot be set to greater than the number of "
1626 "defined start positions."),
1627 NULL, maxplayers_callback, NULL,
1628 GAME_MIN_MAX_PLAYERS, GAME_MAX_MAX_PLAYERS, GAME_DEFAULT_MAX_PLAYERS)
1630 GEN_INT("aifill", game.info.aifill,
1631 SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
1632 N_("Limited number of AI players"),
1633 N_("If set to a positive value, then AI players will be "
1634 "automatically created or removed to keep the total "
1635 "number of players at this amount. As more players join, "
1636 "these AI players will be replaced. When set to zero, "
1637 "all AI players will be removed."),
1638 NULL, NULL, aifill_action,
1639 GAME_MIN_AIFILL, GAME_MAX_AIFILL, GAME_DEFAULT_AIFILL)
1641 GEN_ENUM("persistentready", game.info.persistent_ready,
1642 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
1643 N_("When the Readiness of a player gets autotoggled off"),
1644 N_("In pre-game, usually when new players join or old ones leave, "
1645 "those who have already accepted game to start by toggling \"Ready\" "
1646 "get that autotoggled off in the changed situation. This setting "
1647 "can be used to make readiness more persistent."),
1648 NULL, NULL, NULL, persistentready_name, GAME_DEFAULT_PERSISTENTREADY)
1650 GEN_STRING("nationset", game.server.nationset,
1651 SSET_PLAYERS, SSET_INTERNAL, SSET_RARE, SSET_TO_CLIENT,
1652 N_("Set of nations to choose from"),
1653 /* TRANS: do not translate '/list nationsets' */
1654 N_("Controls the set of nations allowed in the game. The "
1655 "choices are defined by the ruleset.\n"
1656 "Only nations in the set selected here will be allowed in "
1657 "any circumstances, including new players and civil war; "
1658 "small sets may thus limit the number of players in a game.\n"
1659 "If this is left blank, the ruleset's default nation set is "
1660 "used.\n"
1661 "See '/list nationsets' for possible choices for the "
1662 "currently loaded ruleset."),
1663 nationset_callback, nationset_action, GAME_DEFAULT_NATIONSET)
1665 GEN_INT("ec_turns", game.server.event_cache.turns,
1666 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_SITUATIONAL,
1667 SSET_TO_CLIENT,
1668 N_("Event cache for this number of turns"),
1669 N_("Event messages are saved for this number of turns. A value of "
1670 "0 deactivates the event cache."),
1671 NULL, NULL, NULL, GAME_MIN_EVENT_CACHE_TURNS, GAME_MAX_EVENT_CACHE_TURNS,
1672 GAME_DEFAULT_EVENT_CACHE_TURNS)
1674 GEN_INT("ec_max_size", game.server.event_cache.max_size,
1675 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_SITUATIONAL,
1676 SSET_TO_CLIENT,
1677 N_("Size of the event cache"),
1678 N_("This defines the maximal number of events in the event cache."),
1679 NULL, NULL, NULL, GAME_MIN_EVENT_CACHE_MAX_SIZE,
1680 GAME_MAX_EVENT_CACHE_MAX_SIZE, GAME_DEFAULT_EVENT_CACHE_MAX_SIZE)
1682 GEN_BOOL("ec_chat", game.server.event_cache.chat,
1683 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_SITUATIONAL,
1684 SSET_TO_CLIENT,
1685 N_("Save chat messages in the event cache"),
1686 N_("If turned on, chat messages will be saved in the event "
1687 "cache."), NULL, NULL, GAME_DEFAULT_EVENT_CACHE_CHAT)
1689 GEN_BOOL("ec_info", game.server.event_cache.info,
1690 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
1691 N_("Print turn and time for each cached event"),
1692 /* TRANS: Don't translate the text between single quotes. */
1693 N_("If turned on, all cached events will be marked by the turn "
1694 "and time of the event like '(T2 - 15:29:52)'."),
1695 NULL, NULL, GAME_DEFAULT_EVENT_CACHE_INFO)
1697 /* Game initialization parameters (only affect the first start of the game,
1698 * and not reloads). Can not be changed after first start of game.
1700 GEN_STRING("startunits", game.server.start_units,
1701 SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1702 N_("List of players' initial units"),
1703 N_("This should be a string of characters, each of which "
1704 "specifies a unit role. The first character must be native to "
1705 "at least one \"Starter\" terrain. The characters and their "
1706 "meanings are:\n"
1707 " c = City founder (eg., Settlers)\n"
1708 " w = Terrain worker (eg., Engineers)\n"
1709 " x = Explorer (eg., Explorer)\n"
1710 " k = Gameloss (eg., King)\n"
1711 " s = Diplomat (eg., Diplomat)\n"
1712 " f = Ferryboat (eg., Trireme)\n"
1713 " d = Ok defense unit (eg., Warriors)\n"
1714 " D = Good defense unit (eg., Phalanx)\n"
1715 " a = Fast attack unit (eg., Horsemen)\n"
1716 " A = Strong attack unit (eg., Catapult)\n"),
1717 startunits_callback, NULL, GAME_DEFAULT_START_UNITS)
1719 GEN_BOOL("startcity", game.server.start_city,
1720 SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1721 N_("Whether player starts with a city"),
1722 N_("If this is set, game will start with player's first "
1723 "city already founded to starting location."),
1724 NULL, NULL, GAME_DEFAULT_START_CITY)
1726 GEN_INT("dispersion", game.server.dispersion,
1727 SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1728 N_("Area where initial units are located"),
1729 N_("This is the radius within "
1730 "which the initial units are dispersed."),
1731 NULL, NULL, NULL,
1732 GAME_MIN_DISPERSION, GAME_MAX_DISPERSION, GAME_DEFAULT_DISPERSION)
1734 GEN_INT("gold", game.info.gold,
1735 SSET_GAME_INIT, SSET_ECONOMICS, SSET_VITAL, SSET_TO_CLIENT,
1736 N_("Starting gold per player"),
1737 N_("At the beginning of the game, each player is given this "
1738 "much gold."), NULL, NULL, NULL,
1739 GAME_MIN_GOLD, GAME_MAX_GOLD, GAME_DEFAULT_GOLD)
1741 GEN_INT("techlevel", game.info.tech,
1742 SSET_GAME_INIT, SSET_SCIENCE, SSET_VITAL, SSET_TO_CLIENT,
1743 N_("Number of initial techs per player"),
1744 /* TRANS: The string between single quotes is a setting name and
1745 * should not be translated. */
1746 N_("At the beginning of the game, each player is given this "
1747 "many technologies. The technologies chosen are random for "
1748 "each player. Depending on the value of tech_cost_style in "
1749 "the ruleset, a big value for 'techlevel' can make the next "
1750 "techs really expensive."), NULL, NULL, NULL,
1751 GAME_MIN_TECHLEVEL, GAME_MAX_TECHLEVEL, GAME_DEFAULT_TECHLEVEL)
1753 GEN_INT("sciencebox", game.info.sciencebox,
1754 SSET_RULES_SCENARIO, SSET_SCIENCE, SSET_SITUATIONAL,
1755 SSET_TO_CLIENT,
1756 N_("Technology cost multiplier percentage"),
1757 N_("This affects how quickly players can research new "
1758 "technology. All tech costs are multiplied by this amount "
1759 "(as a percentage). The base tech costs are determined by "
1760 "the ruleset or other game settings."),
1761 NULL, NULL, NULL, GAME_MIN_SCIENCEBOX, GAME_MAX_SCIENCEBOX,
1762 GAME_DEFAULT_SCIENCEBOX)
1764 GEN_INT("techpenalty", game.server.techpenalty,
1765 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1766 N_("Percentage penalty when changing tech"),
1767 N_("If you change your current research technology, and you have "
1768 "positive research points, you lose this percentage of those "
1769 "research points. This does not apply when you have just gained "
1770 "a technology this turn."), NULL, NULL, NULL,
1771 GAME_MIN_TECHPENALTY, GAME_MAX_TECHPENALTY,
1772 GAME_DEFAULT_TECHPENALTY)
1774 GEN_INT("techlost_recv", game.server.techlost_recv,
1775 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1776 N_("Chance to lose a technology while receiving it"),
1777 N_("The chance that learning a technology by treaty or theft "
1778 "will fail."),
1779 NULL, NULL, NULL, GAME_MIN_TECHLOST_RECV, GAME_MAX_TECHLOST_RECV,
1780 GAME_DEFAULT_TECHLOST_RECV)
1782 GEN_INT("techlost_donor", game.server.techlost_donor,
1783 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1784 N_("Chance to lose a technology while giving it"),
1785 N_("The chance that your civilization will lose a technology if "
1786 "you teach it to someone else by treaty, or if it is stolen "
1787 "from you."),
1788 NULL, NULL, NULL, GAME_MIN_TECHLOST_DONOR, GAME_MAX_TECHLOST_DONOR,
1789 GAME_DEFAULT_TECHLOST_DONOR)
1791 GEN_BOOL("team_pooled_research", game.info.team_pooled_research,
1792 SSET_RULES, SSET_SCIENCE, SSET_VITAL, SSET_TO_CLIENT,
1793 N_("Team pooled research"),
1794 N_("If this setting is turned on, then the team mates will share "
1795 "the science research. Else, every player of the team will "
1796 "have to make its own."),
1797 NULL, NULL, GAME_DEFAULT_TEAM_POOLED_RESEARCH)
1799 GEN_INT("diplbulbcost", game.server.diplbulbcost,
1800 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1801 N_("Penalty when getting tech from treaty"),
1802 N_("For each technology you gain from a diplomatic treaty, you "
1803 "lose research points equal to this percentage of the cost to "
1804 "research a new technology. If this is non-zero, you can end up "
1805 "with negative research points."),
1806 NULL, NULL, NULL,
1807 GAME_MIN_DIPLBULBCOST, GAME_MAX_DIPLBULBCOST, GAME_DEFAULT_DIPLBULBCOST)
1809 GEN_INT("diplgoldcost", game.server.diplgoldcost,
1810 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1811 N_("Penalty when getting gold from treaty"),
1812 N_("When transferring gold in diplomatic treaties, this percentage "
1813 "of the agreed sum is lost to both parties; it is deducted from "
1814 "the donor but not received by the recipient."),
1815 NULL, NULL, NULL,
1816 GAME_MIN_DIPLGOLDCOST, GAME_MAX_DIPLGOLDCOST, GAME_DEFAULT_DIPLGOLDCOST)
1818 GEN_INT("conquercost", game.server.conquercost,
1819 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1820 N_("Penalty when getting tech from conquering"),
1821 N_("For each technology you gain by conquering an enemy city, you "
1822 "lose research points equal to this percentage of the cost to "
1823 "research a new technology. If this is non-zero, you can end up "
1824 "with negative research points."),
1825 NULL, NULL, NULL,
1826 GAME_MIN_CONQUERCOST, GAME_MAX_CONQUERCOST,
1827 GAME_DEFAULT_CONQUERCOST)
1829 GEN_INT("freecost", game.server.freecost,
1830 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1831 N_("Penalty when getting a free tech"),
1832 /* TRANS: The strings between single quotes are setting names and
1833 * shouldn't be translated. */
1834 N_("For each technology you gain \"for free\" (other than "
1835 "covered by 'diplcost' or 'conquercost': for instance, from huts "
1836 "or from Great Library effects), you lose research points "
1837 "equal to this percentage of the cost to research a new "
1838 "technology. If this is non-zero, you can end up "
1839 "with negative research points."),
1840 NULL, NULL, NULL,
1841 GAME_MIN_FREECOST, GAME_MAX_FREECOST, GAME_DEFAULT_FREECOST)
1843 GEN_INT("techlossforgiveness", game.server.techloss_forgiveness,
1844 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1845 N_("Research point debt threshold for losing tech"),
1846 N_("When you have negative research points, and your shortfall is "
1847 "greater than this percentage of the cost of your current "
1848 "research, you forget a technology you already knew.\n"
1849 "The special value -1 prevents loss of technology regardless of "
1850 "research points."),
1851 NULL, NULL, NULL,
1852 GAME_MIN_TECHLOSSFG, GAME_MAX_TECHLOSSFG,
1853 GAME_DEFAULT_TECHLOSSFG)
1855 GEN_INT("techlossrestore", game.server.techloss_restore,
1856 SSET_RULES, SSET_SCIENCE, SSET_RARE, SSET_TO_CLIENT,
1857 N_("Research points restored after losing a tech"),
1858 N_("When you lose a technology due to a negative research balance "
1859 "(see 'techlossforgiveness'), this percentage of its research "
1860 "cost is credited to your research balance (this may not be "
1861 "sufficient to make it positive).\n"
1862 "The special value -1 means that your research balance is always "
1863 "restored to zero, regardless of your previous shortfall."),
1864 NULL, NULL, NULL,
1865 GAME_MIN_TECHLOSSREST, GAME_MAX_TECHLOSSREST,
1866 GAME_DEFAULT_TECHLOSSREST)
1868 GEN_INT("foodbox", game.info.foodbox,
1869 SSET_RULES, SSET_ECONOMICS, SSET_SITUATIONAL, SSET_TO_CLIENT,
1870 N_("Food required for a city to grow"),
1871 N_("This is the base amount of food required to grow a city. "
1872 "This value is multiplied by another factor that comes from "
1873 "the ruleset and is dependent on the size of the city."),
1874 NULL, NULL, NULL,
1875 GAME_MIN_FOODBOX, GAME_MAX_FOODBOX, GAME_DEFAULT_FOODBOX)
1877 GEN_INT("aqueductloss", game.server.aqueductloss,
1878 SSET_RULES, SSET_ECONOMICS, SSET_RARE, SSET_TO_CLIENT,
1879 N_("Percentage food lost when city can't grow"),
1880 N_("If a city would expand, but it can't because it lacks some "
1881 "prerequisite (traditionally an Aqueduct or Sewer System), "
1882 "this is the base percentage of its foodbox that is lost "
1883 "each turn; the penalty may be reduced by buildings or other "
1884 "circumstances, depending on the ruleset."),
1885 NULL, NULL, NULL,
1886 GAME_MIN_AQUEDUCTLOSS, GAME_MAX_AQUEDUCTLOSS,
1887 GAME_DEFAULT_AQUEDUCTLOSS)
1889 GEN_INT("shieldbox", game.info.shieldbox,
1890 SSET_RULES, SSET_ECONOMICS, SSET_SITUATIONAL, SSET_TO_CLIENT,
1891 N_("Multiplier percentage for production costs"),
1892 N_("This affects how quickly units and buildings can be "
1893 "produced. The base costs are multiplied by this value (as "
1894 "a percentage)."),
1895 NULL, NULL, NULL,
1896 GAME_MIN_SHIELDBOX, GAME_MAX_SHIELDBOX, GAME_DEFAULT_SHIELDBOX)
1898 /* Notradesize and fulltradesize used to have callbacks to prevent them
1899 * from being set illegally (notradesize > fulltradesize). However this
1900 * provided a problem when setting them both through the client's settings
1901 * dialog, since they cannot both be set atomically. So the callbacks were
1902 * removed and instead the game now knows how to deal with invalid
1903 * settings. */
1904 GEN_INT("fulltradesize", game.info.fulltradesize,
1905 SSET_RULES, SSET_ECONOMICS, SSET_RARE, SSET_TO_CLIENT,
1906 N_("Minimum city size to get full trade"),
1907 /* TRANS: The strings between single quotes are setting names and
1908 * shouldn't be translated. */
1909 N_("There is a trade penalty in all cities smaller than this. "
1910 "The penalty is 100% (no trade at all) for sizes up to "
1911 "'notradesize', and decreases gradually to 0% (no penalty "
1912 "except the normal corruption) for size='fulltradesize'. "
1913 "See also 'notradesize'."), NULL, NULL, NULL,
1914 GAME_MIN_FULLTRADESIZE, GAME_MAX_FULLTRADESIZE,
1915 GAME_DEFAULT_FULLTRADESIZE)
1917 GEN_INT("notradesize", game.info.notradesize,
1918 SSET_RULES, SSET_ECONOMICS, SSET_RARE, SSET_TO_CLIENT,
1919 N_("Maximum size of a city without trade"),
1920 /* TRANS: The strings between single quotes are setting names and
1921 * shouldn't be translated. */
1922 N_("Cities do not produce any trade at all unless their size "
1923 "is larger than this amount. The produced trade increases "
1924 "gradually for cities larger than 'notradesize' and smaller "
1925 "than 'fulltradesize'. See also 'fulltradesize'."),
1926 NULL, NULL, NULL,
1927 GAME_MIN_NOTRADESIZE, GAME_MAX_NOTRADESIZE,
1928 GAME_DEFAULT_NOTRADESIZE)
1930 GEN_INT("citymindist", game.info.citymindist,
1931 SSET_RULES, SSET_SOCIOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1932 N_("Minimum distance between cities"),
1933 N_("When a player attempts to found a new city, it is prevented "
1934 "if the distance from any existing city is less than this "
1935 "setting. For example, when this setting is 3, there must be "
1936 "at least two clear tiles in any direction between all existing "
1937 "cities and the new city site. A value of 1 removes any such "
1938 "restriction on city placement."),
1939 NULL, NULL, NULL,
1940 GAME_MIN_CITYMINDIST, GAME_MAX_CITYMINDIST,
1941 GAME_DEFAULT_CITYMINDIST)
1943 GEN_BOOL("trading_tech", game.info.trading_tech,
1944 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
1945 N_("Technology trading"),
1946 N_("If turned off, trading technologies in the diplomacy dialog "
1947 "is not allowed."), NULL, NULL,
1948 GAME_DEFAULT_TRADING_TECH)
1950 GEN_BOOL("trading_gold", game.info.trading_gold,
1951 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
1952 N_("Gold trading"),
1953 N_("If turned off, trading gold in the diplomacy dialog "
1954 "is not allowed."), NULL, NULL,
1955 GAME_DEFAULT_TRADING_GOLD)
1957 GEN_BOOL("trading_city", game.info.trading_city,
1958 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
1959 N_("City trading"),
1960 N_("If turned off, trading cities in the diplomacy dialog "
1961 "is not allowed."), NULL, NULL,
1962 GAME_DEFAULT_TRADING_CITY)
1964 GEN_INT("trademindist", game.info.trademindist,
1965 SSET_RULES, SSET_ECONOMICS, SSET_RARE, SSET_TO_CLIENT,
1966 N_("Minimum distance for trade routes"),
1967 N_("In order for two cities in the same civilization to establish "
1968 "a trade route, they must be at least this far apart on the "
1969 "map. For square grids, the distance is calculated as "
1970 "\"Manhattan distance\", that is, the sum of the displacements "
1971 "along the x and y directions."), NULL, NULL, NULL,
1972 GAME_MIN_TRADEMINDIST, GAME_MAX_TRADEMINDIST,
1973 GAME_DEFAULT_TRADEMINDIST)
1975 GEN_INT("rapturedelay", game.info.rapturedelay,
1976 SSET_RULES, SSET_SOCIOLOGY, SSET_SITUATIONAL, SSET_TO_CLIENT,
1977 N_("Number of turns between rapture effect"),
1978 N_("Sets the number of turns between rapture growth of a city. "
1979 "If set to n a city will grow after celebrating for n+1 "
1980 "turns."),
1981 NULL, NULL, NULL,
1982 GAME_MIN_RAPTUREDELAY, GAME_MAX_RAPTUREDELAY,
1983 GAME_DEFAULT_RAPTUREDELAY)
1985 GEN_INT("disasters", game.info.disasters,
1986 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
1987 N_("Frequency of disasters"),
1988 N_("Affects how often random disasters happen to cities, "
1989 "if any are defined by the ruleset. The relative frequency "
1990 "of disaster types is set by the ruleset. Zero prevents "
1991 "any random disasters from occurring."),
1992 NULL, NULL, NULL,
1993 GAME_MIN_DISASTERS, GAME_MAX_DISASTERS,
1994 GAME_DEFAULT_DISASTERS)
1996 GEN_ENUM("traitdistribution", game.server.trait_dist,
1997 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
1998 N_("AI trait distribution method"),
1999 N_("How trait values are given to AI players."),
2000 NULL, NULL, NULL, trait_dist_name, GAME_DEFAULT_TRAIT_DIST_MODE)
2002 GEN_INT("razechance", game.server.razechance,
2003 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2004 N_("Chance for conquered building destruction"),
2005 N_("When a player conquers a city, each city improvement has this "
2006 "percentage chance to be destroyed."), NULL, NULL, NULL,
2007 GAME_MIN_RAZECHANCE, GAME_MAX_RAZECHANCE, GAME_DEFAULT_RAZECHANCE)
2009 GEN_INT("occupychance", game.server.occupychance,
2010 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2011 N_("Chance of moving into tile after attack"),
2012 N_("If set to 0, combat is Civ1/2-style (when you attack, "
2013 "you remain in place). If set to 100, attacking units "
2014 "will always move into the tile they attacked when they win "
2015 "the combat (and no enemy units remain in the tile). If "
2016 "set to a value between 0 and 100, this will be used as "
2017 "the percent chance of \"occupying\" territory."),
2018 NULL, NULL, NULL,
2019 GAME_MIN_OCCUPYCHANCE, GAME_MAX_OCCUPYCHANCE,
2020 GAME_DEFAULT_OCCUPYCHANCE)
2022 GEN_BOOL("autoattack", game.server.autoattack, SSET_RULES_FLEXIBLE, SSET_MILITARY,
2023 SSET_SITUATIONAL, SSET_TO_CLIENT,
2024 N_("Turn on/off server-side autoattack"),
2025 N_("If set to on, units with moves left will automatically "
2026 "consider attacking enemy units that move adjacent to them."),
2027 NULL, NULL, GAME_DEFAULT_AUTOATTACK)
2029 GEN_BOOL("killstack", game.info.killstack,
2030 SSET_RULES_SCENARIO, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2031 N_("Do all units in tile die with defender"),
2032 N_("If this is enabled, each time a defender unit loses in combat, "
2033 "and is not inside a city or suitable base, all units in the same "
2034 "tile are destroyed along with the defender. If this is disabled, "
2035 "only the defender unit is destroyed."),
2036 NULL, NULL, GAME_DEFAULT_KILLSTACK)
2038 GEN_BOOL("killcitizen", game.info.killcitizen,
2039 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2040 N_("Reduce city population after attack"),
2041 N_("This flag indicates whether a city's population is reduced "
2042 "after a successful attack by an enemy unit. If this is "
2043 "disabled, population is never reduced. Even when this is "
2044 "enabled, only some units may kill citizens."),
2045 NULL, NULL, GAME_DEFAULT_KILLCITIZEN)
2047 GEN_INT("killunhomed", game.server.killunhomed,
2048 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2049 N_("Slowly kill units without home cities (e.g., starting units)"),
2050 N_("If greater than 0, then every unit without a homecity will "
2051 "lose hitpoints each turn. The number of hitpoints lost is "
2052 "given by 'killunhomed' percent of the hitpoints of the unit "
2053 "type. At least one hitpoint is lost every turn until the "
2054 "death of the unit."),
2055 NULL, NULL, NULL, GAME_MIN_KILLUNHOMED, GAME_MAX_KILLUNHOMED,
2056 GAME_DEFAULT_KILLUNHOMED)
2058 GEN_ENUM("borders", game.info.borders,
2059 SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL, SSET_TO_CLIENT,
2060 N_("National borders"),
2061 N_("If this is not disabled, then any land tiles around a "
2062 "city or border-claiming extra (like the classic ruleset's "
2063 "Fortress base) will be owned by that nation."),
2064 NULL, NULL, NULL, borders_name, GAME_DEFAULT_BORDERS)
2066 GEN_ENUM("happyborders", game.info.happyborders,
2067 SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL,
2068 SSET_TO_CLIENT,
2069 N_("Units inside borders cause no unhappiness"),
2070 N_("If this is set, units will not cause unhappiness when "
2071 "inside your borders, or even allies borders, depending "
2072 "on value."), NULL, NULL, NULL,
2073 happyborders_name, GAME_DEFAULT_HAPPYBORDERS)
2075 GEN_ENUM("diplomacy", game.info.diplomacy,
2076 SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL, SSET_TO_CLIENT,
2077 N_("Ability to do diplomacy with other players"),
2078 N_("This setting controls the ability to do diplomacy with "
2079 "other players."),
2080 NULL, NULL, NULL, diplomacy_name, GAME_DEFAULT_DIPLOMACY)
2082 GEN_ENUM("citynames", game.server.allowed_city_names,
2083 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2084 N_("Allowed city names"),
2085 /* TRANS: The strings between double quotes are also translated
2086 * separately (they must match!). The strings between parentheses
2087 * and in uppercase must not be translated. */
2088 N_("- \"No restrictions\" (NO_RESTRICTIONS): players can have "
2089 "multiple cities with the same names.\n"
2090 "- \"Unique to a player\" (PLAYER_UNIQUE): one player can't "
2091 "have multiple cities with the same name.\n"
2092 "- \"Globally unique\" (GLOBAL_UNIQUE): all cities in a game "
2093 "have to have different names.\n"
2094 "- \"No city name stealing\" (NO_STEALING): like "
2095 "\"Globally unique\", but a player isn't allowed to use a "
2096 "default city name of another nation unless it is a default "
2097 "for their nation also."),
2098 NULL, NULL, NULL, citynames_name, GAME_DEFAULT_ALLOWED_CITY_NAMES)
2100 GEN_ENUM("plrcolormode", game.server.plrcolormode,
2101 SSET_RULES, SSET_INTERNAL, SSET_RARE, SSET_TO_CLIENT,
2102 N_("How to pick player colors"),
2103 /* TRANS: The strings between double quotes are also translated
2104 * separately (they must match!). The strings between single quotes
2105 * are setting names and shouldn't be translated. The strings
2106 * between parentheses and in uppercase must not be translated. */
2107 N_("This setting determines how player colors are chosen. Player "
2108 "colors are used in the Nations report, for national borders on "
2109 "the map, and so on.\n"
2110 "- \"Per-player, in order\" (PLR_ORDER): colors are assigned to "
2111 "individual players in order from a list defined by the "
2112 "ruleset.\n"
2113 "- \"Per-player, random\" (PLR_RANDOM): colors are assigned "
2114 "to individual players randomly from the set defined by the "
2115 "ruleset.\n"
2116 "- \"Set manually\" (PLR_SET): colors can be set with the "
2117 "'playercolor' command before the game starts; these are not "
2118 "restricted to the ruleset colors. Any players for which no "
2119 "color is set when the game starts get a random color from the "
2120 "ruleset.\n"
2121 "- \"Per-team, in order\" (TEAM_ORDER): colors are assigned to "
2122 "teams from the list in the ruleset. Every player on the same "
2123 "team gets the same color.\n"
2124 "- \"Per-nation, in order\" (NATION_ORDER): if the ruleset "
2125 "defines a color for a player's nation, the player takes that "
2126 "color. Any players whose nations don't have associated colors "
2127 "get a random color from the list in the ruleset.\n"
2128 "Regardless of this setting, individual player colors can be "
2129 "changed after the game starts with the 'playercolor' command."),
2130 NULL, plrcol_validate, plrcol_action, plrcol_name,
2131 GAME_DEFAULT_PLRCOLORMODE)
2133 /* Flexible rules: these can be changed after the game has started.
2135 * The distinction between "rules" and "flexible rules" is not always
2136 * clearcut, and some existing cases may be largely historical or
2137 * accidental. However some generalizations can be made:
2139 * -- Low-level game mechanics should not be flexible (eg, rulesets).
2140 * -- Options which would affect the game "state" (city production etc)
2141 * should not be flexible (eg, foodbox).
2142 * -- Options which are explicitly sent to the client (eg, in
2143 * packet_game_info) should probably not be flexible, or at
2144 * least need extra care to be flexible.
2146 GEN_ENUM("barbarians", game.server.barbarianrate,
2147 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_VITAL, SSET_TO_CLIENT,
2148 N_("Barbarian appearance frequency"),
2149 /* TRANS: The string between single quotes is a setting name and
2150 * should not be translated. */
2151 N_("This setting controls how frequently the barbarians appear "
2152 "in the game. See also the 'onsetbarbs' setting."),
2153 NULL, NULL, NULL, barbarians_name, GAME_DEFAULT_BARBARIANRATE)
2155 GEN_INT("onsetbarbs", game.server.onsetbarbarian,
2156 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_VITAL, SSET_TO_CLIENT,
2157 N_("Barbarian onset turn"),
2158 N_("Barbarians will not appear before this turn."),
2159 NULL, NULL, NULL,
2160 GAME_MIN_ONSETBARBARIAN, GAME_MAX_ONSETBARBARIAN,
2161 GAME_DEFAULT_ONSETBARBARIAN)
2163 GEN_ENUM("revolentype", game.info.revolentype,
2164 SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2165 N_("Way to determine revolution length"),
2166 N_("Which method is used in determining how long period of anarchy "
2167 "lasts when changing government. The actual value is set with "
2168 "'revolen' setting."),
2169 NULL, NULL, NULL, revolentype_name, GAME_DEFAULT_REVOLENTYPE)
2171 GEN_INT("revolen", game.server.revolution_length,
2172 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2173 N_("Length of revolution"),
2174 N_("When changing governments, a period of anarchy will occur. "
2175 "Value of this setting, used the way 'revolentype' setting "
2176 "dictates, defines the length of the anarchy."),
2177 NULL, NULL, NULL,
2178 GAME_MIN_REVOLUTION_LENGTH, GAME_MAX_REVOLUTION_LENGTH,
2179 GAME_DEFAULT_REVOLUTION_LENGTH)
2181 GEN_BOOL("fogofwar", game.info.fogofwar,
2182 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2183 N_("Whether to enable fog of war"),
2184 N_("If this is enabled, only those units and cities within "
2185 "the vision range of your own units and cities will be "
2186 "revealed to you. You will not see new cities or terrain "
2187 "changes in tiles not observed."),
2188 NULL, NULL, GAME_DEFAULT_FOGOFWAR)
2190 GEN_BOOL("foggedborders", game.server.foggedborders,
2191 SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2192 N_("Whether fog of war applies to border changes"),
2193 N_("If this setting is enabled, players will not be able "
2194 "to see changes in tile ownership if they do not have "
2195 "direct sight of the affected tiles. Otherwise, players "
2196 "can see any or all changes to borders as long as they "
2197 "have previously seen the tiles."),
2198 NULL, NULL, GAME_DEFAULT_FOGGEDBORDERS)
2200 GEN_BITWISE("airliftingstyle", game.info.airlifting_style,
2201 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_SITUATIONAL,
2202 SSET_TO_CLIENT, N_("Airlifting style"),
2203 /* TRANS: The strings between double quotes are also
2204 * translated separately (they must match!). The strings
2205 * between parenthesis and in uppercase must not be
2206 * translated. */
2207 N_("This setting affects airlifting units between cities. It "
2208 "can be a set of the following values:\n"
2209 "- \"Allows units to be airlifted from allied cities\" "
2210 "(FROM_ALLIES).\n"
2211 "- \"Allows units to be airlifted to allied cities\" "
2212 "(TO_ALLIES).\n"
2213 "- \"Unlimited units from source city\" (SRC_UNLIMITED): "
2214 "note that airlifting from a city doesn't reduce the "
2215 "airlifted counter, but still needs at least 1.\n"
2216 "- \"Unlimited units to destination city\" "
2217 "(DEST_UNLIMITED): note that airlifting to a city doesn't "
2218 "reduce the airlifted counter, and doesn't need any."),
2219 NULL, NULL, airliftingstyle_name, GAME_DEFAULT_AIRLIFTINGSTYLE)
2221 GEN_INT("diplchance", game.server.diplchance,
2222 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_SITUATIONAL,
2223 SSET_TO_CLIENT,
2224 N_("Base chance for diplomats and spies to succeed"),
2225 N_("The base chance of a spy returning from a successful mission and "
2226 "the base chance of success for diplomats and spies."),
2227 NULL, NULL, NULL,
2228 GAME_MIN_DIPLCHANCE, GAME_MAX_DIPLCHANCE, GAME_DEFAULT_DIPLCHANCE)
2230 GEN_BITWISE("victories", game.info.victory_conditions,
2231 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2232 N_("What kinds of victories are possible"),
2233 /* TRANS: The strings between double quotes are also translated
2234 * separately (they must match!). The strings between single
2235 * quotes are setting names and shouldn't be translated. The
2236 * strings between parentheses and in uppercase must stay as
2237 * untranslated. */
2238 N_("This setting controls how game can be won. One can always "
2239 "win by conquering entire planet, but other victory conditions "
2240 "can be enabled or disabled:\n"
2241 "- \"Spacerace\" (SPACERACE): Spaceship is built and travels to "
2242 "Alpha Centauri.\n"
2243 "- \"Allied\" (ALLIED): After defeating enemies, all remaining "
2244 "players are allied.\n"
2245 "- \"Culture\" (CULTURE): Player meets ruleset defined cultural "
2246 "domination criteria.\n"),
2247 NULL, NULL, victory_conditions_name, GAME_DEFAULT_VICTORY_CONDITIONS)
2249 GEN_BOOL("endspaceship", game.server.endspaceship, SSET_RULES_FLEXIBLE,
2250 SSET_SCIENCE, SSET_VITAL, SSET_TO_CLIENT,
2251 N_("Should the game end if the spaceship arrives?"),
2252 N_("If this option is turned on, the game will end with the "
2253 "arrival of a spaceship at Alpha Centauri."),
2254 NULL, NULL, GAME_DEFAULT_END_SPACESHIP)
2256 GEN_INT("civilwarsize", game.server.civilwarsize,
2257 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2258 N_("Minimum number of cities for civil war"),
2259 N_("A civil war is triggered when a player has at least this "
2260 "many cities and the player's capital is captured. If "
2261 "this option is set to the maximum value, civil wars are "
2262 "turned off altogether."), NULL, NULL, NULL,
2263 GAME_MIN_CIVILWARSIZE, GAME_MAX_CIVILWARSIZE,
2264 GAME_DEFAULT_CIVILWARSIZE)
2266 GEN_BOOL("restrictinfra", game.info.restrictinfra,
2267 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2268 N_("Restrict the use of the infrastructure for enemy units"),
2269 N_("If this option is enabled, the use of roads and rails "
2270 "will be restricted for enemy units."), NULL, NULL,
2271 GAME_DEFAULT_RESTRICTINFRA)
2273 GEN_BOOL("unreachableprotects", game.info.unreachable_protects,
2274 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2275 N_("Does unreachable unit protect reachable ones"),
2276 N_("This option controls whether tiles with both unreachable "
2277 "and reachable units can be attacked. If disabled, any "
2278 "tile with reachable units can be attacked. If enabled, "
2279 "tiles with an unreachable unit in them cannot be attacked."),
2280 NULL, NULL, GAME_DEFAULT_UNRPROTECTS)
2282 GEN_INT("contactturns", game.server.contactturns,
2283 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2284 N_("Turns until player contact is lost"),
2285 N_("Players may meet for diplomacy this number of turns "
2286 "after their units have last met, even when they do not have "
2287 "an embassy. If set to zero, then players cannot meet unless "
2288 "they have an embassy."),
2289 NULL, NULL, NULL,
2290 GAME_MIN_CONTACTTURNS, GAME_MAX_CONTACTTURNS,
2291 GAME_DEFAULT_CONTACTTURNS)
2293 GEN_BOOL("savepalace", game.server.savepalace,
2294 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2295 N_("Rebuild palace whenever capital is conquered"),
2296 N_("If this is turned on, when the capital is conquered the "
2297 "palace is automatically rebuilt for free in another randomly "
2298 "chosen city. This is significant because the technology "
2299 "requirement for building a palace will be ignored. (In "
2300 "some rulesets, buildings other than the palace are affected "
2301 "by this setting.)"),
2302 NULL, NULL, GAME_DEFAULT_SAVEPALACE)
2304 GEN_BOOL("homecaughtunits", game.server.homecaughtunits,
2305 SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,
2306 N_("Give caught units a homecity"),
2307 /* TRANS: The string between single quotes is a setting name and
2308 * should not be translated. */
2309 N_("If unset, caught units will have no homecity and will be "
2310 "subject to the 'killunhomed' option."),
2311 NULL, NULL, GAME_DEFAULT_HOMECAUGHTUNITS)
2313 GEN_BOOL("naturalcitynames", game.server.natural_city_names,
2314 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2315 N_("Whether to use natural city names"),
2316 N_("If enabled, the default city names will be determined based "
2317 "on the surrounding terrain."),
2318 NULL, NULL, GAME_DEFAULT_NATURALCITYNAMES)
2320 GEN_BOOL("migration", game.server.migration,
2321 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2322 N_("Whether to enable citizen migration"),
2323 /* TRANS: The strings between single quotes are setting names
2324 * and should not be translated. */
2325 N_("This is the master setting that controls whether citizen "
2326 "migration is active in the game. If enabled, citizens may "
2327 "automatically move from less desirable cities to more "
2328 "desirable ones. The \"desirability\" of a given city is "
2329 "calculated from a number of factors. In general larger "
2330 "cities with more income and improvements will be preferred. "
2331 "Citizens will never migrate out of the capital, or cause "
2332 "a wonder to be lost by disbanding a city. A number of other "
2333 "settings control how migration behaves:\n"
2334 " 'mgr_turninterval' - How often citizens try to migrate.\n"
2335 " 'mgr_foodneeded' - Whether destination food is checked.\n"
2336 " 'mgr_distance' - How far citizens will migrate.\n"
2337 " 'mgr_worldchance' - Chance for inter-nation migration.\n"
2338 " 'mgr_nationchance' - Chance for intra-nation migration."),
2339 NULL, NULL, GAME_DEFAULT_MIGRATION)
2341 GEN_INT("mgr_turninterval", game.server.mgr_turninterval,
2342 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2343 N_("Number of turns between migrations from a city"),
2344 /* TRANS: Do not translate 'migration' setting name. */
2345 N_("This setting controls the number of turns between migration "
2346 "checks for a given city. The interval is calculated from "
2347 "the founding turn of the city. So for example if this "
2348 "setting is 5, citizens will look for a suitable migration "
2349 "destination every five turns from the founding of their "
2350 "current city. Migration will never occur the same turn "
2351 "that a city is built. This setting has no effect unless "
2352 "migration is enabled by the 'migration' setting."),
2353 NULL, NULL, NULL,
2354 GAME_MIN_MGR_TURNINTERVAL, GAME_MAX_MGR_TURNINTERVAL,
2355 GAME_DEFAULT_MGR_TURNINTERVAL)
2357 GEN_BOOL("mgr_foodneeded", game.server.mgr_foodneeded,
2358 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2359 N_("Whether migration is limited by food"),
2360 /* TRANS: Do not translate 'migration' setting name. */
2361 N_("If this setting is enabled, citizens will not migrate to "
2362 "cities which would not have enough food to support them. "
2363 "This setting has no effect unless migration is enabled by "
2364 "the 'migration' setting."), NULL, NULL,
2365 GAME_DEFAULT_MGR_FOODNEEDED)
2367 GEN_INT("mgr_distance", game.server.mgr_distance,
2368 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2369 N_("Maximum distance citizens may migrate"),
2370 /* TRANS: Do not translate 'migration' setting name. */
2371 N_("This setting controls how far citizens may look for a "
2372 "suitable migration destination when deciding which city "
2373 "to migrate to. The value is added to the current city radius "
2374 "and compared to the distance between the two cities. If "
2375 "the distance is lower or equal, migration is possible. This "
2376 "setting has no effect unless migration is activated by the "
2377 "'migration' setting."),
2378 NULL, NULL, NULL, GAME_MIN_MGR_DISTANCE, GAME_MAX_MGR_DISTANCE,
2379 GAME_DEFAULT_MGR_DISTANCE)
2381 GEN_INT("mgr_nationchance", game.server.mgr_nationchance,
2382 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2383 N_("Percent probability for migration within the same nation"),
2384 /* TRANS: Do not translate 'migration' setting name. */
2385 N_("This setting controls how likely it is for citizens to "
2386 "migrate between cities owned by the same player. Zero "
2387 "indicates migration will never occur, 100 means that "
2388 "migration will always occur if the citizens find a suitable "
2389 "destination. This setting has no effect unless migration "
2390 "is activated by the 'migration' setting."),
2391 NULL, NULL, NULL,
2392 GAME_MIN_MGR_NATIONCHANCE, GAME_MAX_MGR_NATIONCHANCE,
2393 GAME_DEFAULT_MGR_NATIONCHANCE)
2395 GEN_INT("mgr_worldchance", game.server.mgr_worldchance,
2396 SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
2397 N_("Percent probability for migration between foreign cities"),
2398 /* TRANS: Do not translate 'migration' setting name. */
2399 N_("This setting controls how likely it is for migration "
2400 "to occur between cities owned by different players. "
2401 "Zero indicates migration will never occur, 100 means "
2402 "that citizens will always migrate if they find a suitable "
2403 "destination. This setting has no effect if migration is "
2404 "not enabled by the 'migration' setting."),
2405 NULL, NULL, NULL,
2406 GAME_MIN_MGR_WORLDCHANCE, GAME_MAX_MGR_WORLDCHANCE,
2407 GAME_DEFAULT_MGR_WORLDCHANCE)
2409 /* Meta options: these don't affect the internal rules of the game, but
2410 * do affect players. Also options which only produce extra server
2411 * "output" and don't affect the actual game.
2412 * ("endturn" is here, and not RULES_FLEXIBLE, because it doesn't
2413 * affect what happens in the game, it just determines when the
2414 * players stop playing and look at the score.)
2416 GEN_STRING("allowtake", game.server.allow_take,
2417 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2418 N_("Players that users are allowed to take"),
2419 /* TRANS: the strings in double quotes are server command names
2420 * and should not be translated. */
2421 N_("This should be a string of characters, each of which "
2422 "specifies a type or status of a civilization (player).\n"
2423 "Clients will only be permitted to take or observe those "
2424 "players which match one of the specified letters. This "
2425 "only affects future uses of the \"take\" or \"observe\" "
2426 "commands; it is not retroactive. The characters and their "
2427 "meanings are:\n"
2428 " o,O = Global observer\n"
2429 " b = Barbarian players\n"
2430 " d = Dead players\n"
2431 " a,A = AI players\n"
2432 " h,H = Human players\n"
2433 "The first description on this list which matches a "
2434 "player is the one which applies. Thus 'd' does not "
2435 "include dead barbarians, 'a' does not include dead AI "
2436 "players, and so on. Upper case letters apply before "
2437 "the game has started, lower case letters afterwards.\n"
2438 "Each character above may be followed by one of the "
2439 "following numbers to allow or restrict the manner "
2440 "of connection:\n"
2441 "(none) = Controller allowed, observers allowed, "
2442 "can displace connections. (Displacing a connection means "
2443 "that you may take over a player, even when another user "
2444 "already controls that player.)\n"
2445 " 1 = Controller allowed, observers allowed, "
2446 "can't displace connections;\n"
2447 " 2 = Controller allowed, no observers allowed, "
2448 "can displace connections;\n"
2449 " 3 = Controller allowed, no observers allowed, "
2450 "can't displace connections;\n"
2451 " 4 = No controller allowed, observers allowed"),
2452 allowtake_callback, NULL, GAME_DEFAULT_ALLOW_TAKE)
2454 GEN_BOOL("autotoggle", game.server.auto_ai_toggle,
2455 SSET_META, SSET_NETWORK, SSET_SITUATIONAL, SSET_TO_CLIENT,
2456 N_("Whether AI-status toggles with connection"),
2457 N_("If enabled, AI status is turned off when a player "
2458 "connects, and on when a player disconnects."),
2459 NULL, autotoggle_action, GAME_DEFAULT_AUTO_AI_TOGGLE)
2461 GEN_INT("endturn", game.server.end_turn,
2462 SSET_META, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
2463 N_("Turn the game ends"),
2464 N_("The game will end at the end of the given turn."),
2465 NULL, endturn_callback, NULL,
2466 GAME_MIN_END_TURN, GAME_MAX_END_TURN, GAME_DEFAULT_END_TURN)
2468 GEN_BITWISE("revealmap", game.server.revealmap, SSET_GAME_INIT,
2469 SSET_MILITARY, SSET_SITUATIONAL, SSET_TO_CLIENT,
2470 N_("Reveal the map"),
2471 /* TRANS: The strings between double quotes are also translated
2472 * separately (they must match!). The strings between single
2473 * quotes are setting names and shouldn't be translated. The
2474 * strings between parentheses and in uppercase must not be
2475 * translated. */
2476 N_("If \"Reveal map at game start\" (START) is set, the "
2477 "initial state of the entire map will be known to all "
2478 "players from the start of the game, although it may "
2479 "still be fogged (depending on the 'fogofwar' setting). "
2480 "If \"Unfog map for dead players\" (DEAD) is set, dead "
2481 "players can see the entire map, if they are alone in "
2482 "their team."),
2483 NULL, NULL, revealmap_name, GAME_DEFAULT_REVEALMAP)
2485 GEN_INT("timeout", game.info.timeout,
2486 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2487 N_("Maximum seconds per turn"),
2488 /* TRANS: \"Turn Done\" refers to the client button; it is also
2489 * translated separately, the translation should be the same.
2490 * \"timeoutincrease\" is a command name and must not to be
2491 * translated. */
2492 N_("If all players have not hit \"Turn Done\" before this "
2493 "time is up, then the turn ends automatically. Zero "
2494 "means there is no timeout. In servers compiled with "
2495 "debugging, a timeout of -1 sets the autogame test mode. "
2496 "Only connections with hack level access may set the "
2497 "timeout to lower than 30 seconds. Use this with the "
2498 "command \"timeoutincrease\" to have a dynamic timer. "
2499 "The first turn is treated as a special case and is controlled "
2500 "by the 'first_timeout' setting."),
2501 NULL, timeout_callback, timeout_action,
2502 GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUT)
2504 GEN_INT("first_timeout", game.info.first_timeout,
2505 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2506 N_("First turn timeout"),
2507 /* TRANS: The strings between single quotes are setting names and
2508 * should not be translated. */
2509 N_("If greater than 0, T0 will last for 'first_timeout' seconds.\n"
2510 "If set to 0, T0 will not have a timeout.\n"
2511 "If set to -1, the special treatment of T0 will be disabled.\n"
2512 "See also 'timeout'."),
2513 NULL, first_timeout_callback, first_timeout_action,
2514 GAME_MIN_FIRST_TIMEOUT, GAME_MAX_FIRST_TIMEOUT,
2515 GAME_DEFAULT_FIRST_TIMEOUT)
2517 GEN_INT("timeaddenemymove", game.server.timeoutaddenemymove,
2518 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2519 N_("Timeout at least n seconds when enemy moved"),
2520 N_("Any time a unit moves while in sight of an enemy player, "
2521 "the remaining timeout is increased to this value."),
2522 NULL, NULL, NULL,
2523 0, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUTADDEMOVE)
2525 GEN_INT("unitwaittime", game.server.unitwaittime,
2526 SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
2527 N_("Minimum time between unit actions over turn change"),
2528 /* TRANS: The string between single quotes is a setting name and
2529 * should not be translated. */
2530 N_("This setting gives the minimum amount of time in seconds "
2531 "between unit moves and other significant actions (such as "
2532 "building cities) after a turn change occurs. For example, "
2533 "if this setting is set to 20 and a unit moves 5 seconds "
2534 "before the turn change, it will not be able to move or act "
2535 "in the next turn for at least 15 seconds. This value is "
2536 "limited to a maximum value of 2/3 'timeout'."),
2537 NULL, unitwaittime_callback, NULL, GAME_MIN_UNITWAITTIME,
2538 GAME_MAX_UNITWAITTIME, GAME_DEFAULT_UNITWAITTIME)
2540 /* This setting points to the "stored" value; changing it won't have
2541 * an effect until the next synchronization point (i.e., the start of
2542 * the next turn). */
2543 GEN_ENUM("phasemode", game.server.phase_mode_stored,
2544 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
2545 N_("Control of simultaneous player/team phases"),
2546 N_("This setting controls whether players may make "
2547 "moves at the same time during a turn. Change "
2548 "in setting takes effect next turn."),
2549 phasemode_help, NULL, NULL, phasemode_name, GAME_DEFAULT_PHASE_MODE)
2551 GEN_INT("nettimeout", game.server.tcptimeout,
2552 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2553 N_("Seconds to let a client's network connection block"),
2554 N_("If a network connection is blocking for a time greater than "
2555 "this value, then the connection is closed. Zero "
2556 "means there is no timeout (although connections will be "
2557 "automatically disconnected eventually)."),
2558 NULL, NULL, NULL,
2559 GAME_MIN_TCPTIMEOUT, GAME_MAX_TCPTIMEOUT, GAME_DEFAULT_TCPTIMEOUT)
2561 GEN_INT("netwait", game.server.netwait,
2562 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2563 N_("Max seconds for network buffers to drain"),
2564 N_("The server will wait for up to the value of this "
2565 "parameter in seconds, for all client connection network "
2566 "buffers to unblock. Zero means the server will not "
2567 "wait at all."), NULL, NULL, NULL,
2568 GAME_MIN_NETWAIT, GAME_MAX_NETWAIT, GAME_DEFAULT_NETWAIT)
2570 GEN_INT("pingtime", game.server.pingtime,
2571 SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2572 N_("Seconds between PINGs"),
2573 N_("The server will poll the clients with a PING request "
2574 "each time this period elapses."), NULL, NULL, NULL,
2575 GAME_MIN_PINGTIME, GAME_MAX_PINGTIME, GAME_DEFAULT_PINGTIME)
2577 GEN_INT("pingtimeout", game.server.pingtimeout,
2578 SSET_META, SSET_NETWORK, SSET_RARE,
2579 SSET_TO_CLIENT,
2580 N_("Time to cut a client"),
2581 N_("If a client doesn't reply to a PING in this time the "
2582 "client is disconnected."), NULL, NULL, NULL,
2583 GAME_MIN_PINGTIMEOUT, GAME_MAX_PINGTIMEOUT, GAME_DEFAULT_PINGTIMEOUT)
2585 GEN_BOOL("turnblock", game.server.turnblock,
2586 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
2587 N_("Turn-blocking game play mode"),
2588 N_("If this is turned on, the game turn is not advanced "
2589 "until all players have finished their turn, including "
2590 "disconnected players."),
2591 NULL, NULL, GAME_DEFAULT_TURNBLOCK)
2593 GEN_BOOL("fixedlength", game.server.fixedlength,
2594 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
2595 N_("Fixed-length turns play mode"),
2596 /* TRANS: \"Turn Done\" refers to the client button; it is also
2597 * translated separately, the translation should be the same. */
2598 N_("If this is turned on the game turn will not advance "
2599 "until the timeout has expired, even after all players "
2600 "have clicked on \"Turn Done\"."),
2601 NULL, NULL, FALSE)
2603 GEN_STRING("demography", game.server.demography,
2604 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_TO_CLIENT,
2605 N_("What is in the Demographics report"),
2606 /* TRANS: The strings between double quotes should be
2607 * translated. */
2608 N_("This should be a string of characters, each of which "
2609 "specifies the inclusion of a line of information "
2610 "in the Demographics report.\n"
2611 "The characters and their meanings are:\n"
2612 " N = include Population\n"
2613 " P = include Production\n"
2614 " A = include Land Area\n"
2615 " L = include Literacy\n"
2616 " R = include Research Speed\n"
2617 " S = include Settled Area\n"
2618 " E = include Economics\n"
2619 " M = include Military Service\n"
2620 " O = include Pollution\n"
2621 " C = include Culture\n"
2622 "Additionally, the following characters control whether "
2623 "or not certain columns are displayed in the report:\n"
2624 " q = display \"quantity\" column\n"
2625 " r = display \"rank\" column\n"
2626 " b = display \"best nation\" column\n"
2627 "The order of characters is not significant, but "
2628 "their capitalization is."),
2629 demography_callback, NULL, GAME_DEFAULT_DEMOGRAPHY)
2631 GEN_INT("saveturns", game.server.save_nturns,
2632 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
2633 N_("Turns per auto-save"),
2634 /* TRANS: The string between double quotes is also translated
2635 * separately (it must match!). The string between single
2636 * quotes is a setting name and shouldn't be translated. */
2637 N_("How many turns elapse between automatic game saves. This "
2638 "setting only has an effect when the 'autosaves' setting "
2639 "includes \"New turn\"."), NULL, NULL, NULL,
2640 GAME_MIN_SAVETURNS, GAME_MAX_SAVETURNS, GAME_DEFAULT_SAVETURNS)
2642 GEN_INT("savefrequency", game.server.save_frequency,
2643 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
2644 N_("Minutes per auto-save"),
2645 /* TRANS: The string between double quotes is also translated
2646 * separately (it must match!). The string between single
2647 * quotes is a setting name and shouldn't be translated. */
2648 N_("How many minutes elapse between automatic game saves. "
2649 "Unlike other save types, this save is only meant as backup "
2650 "for computer memory, and it always uses the same name, older "
2651 "saves are not kept. This setting only has an effect when the "
2652 "'autosaves' setting includes \"Timer\"."), NULL, NULL, NULL,
2653 GAME_MIN_SAVEFREQUENCY, GAME_MAX_SAVEFREQUENCY, GAME_DEFAULT_SAVEFREQUENCY)
2655 GEN_BITWISE("autosaves", game.server.autosaves,
2656 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
2657 N_("Which savegames are generated automatically"),
2658 /* TRANS: The strings between double quotes are also translated
2659 * separately (they must match!). The strings between single
2660 * quotes are setting names and shouldn't be translated. The
2661 * strings between parentheses and in uppercase must stay as
2662 * untranslated. */
2663 N_("This setting controls which autosave types get generated:\n"
2664 "- \"New turn\" (TURN): Save when turn begins, once every "
2665 "'saveturns' turns.\n"
2666 "- \"Game over\" (GAMEOVER): Final save when game ends.\n"
2667 "- \"No player connections\" (QUITIDLE): "
2668 "Save before server restarts due to lack of players.\n"
2669 "- \"Server interrupted\" (INTERRUPT): Save when server "
2670 "quits due to interrupt.\n"
2671 "- \"Timer\" (TIMER): Save every 'savefrequency' minutes."),
2672 autosaves_callback, NULL, autosaves_name, GAME_DEFAULT_AUTOSAVES)
2674 GEN_INT("compress", game.server.save_compress_level,
2675 SSET_META, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
2676 N_("Savegame compression level"),
2677 /* TRANS: 'compresstype' setting name should not be translated. */
2678 N_("If non-zero, saved games will be compressed depending on the "
2679 "'compresstype' setting. Larger values will give better "
2680 "compression but take longer."),
2681 NULL, NULL, NULL,
2682 GAME_MIN_COMPRESS_LEVEL, GAME_MAX_COMPRESS_LEVEL, GAME_DEFAULT_COMPRESS_LEVEL)
2684 GEN_ENUM("compresstype", game.server.save_compress_type,
2685 SSET_META, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
2686 N_("Savegame compression algorithm"),
2687 N_("Compression library to use for savegames."),
2688 NULL, NULL, NULL, compresstype_name, GAME_DEFAULT_COMPRESS_TYPE)
2690 GEN_STRING("savename", game.server.save_name,
2691 SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
2692 N_("Definition of the save file name"),
2693 /* TRANS: %R, %S, %T and %Y must not be translated. The
2694 * strings (examples and setting names) between single quotes
2695 * neither. The strings between <> should be translated.
2696 * xgettext:no-c-format */
2697 N_("Within the string the following custom formats are "
2698 "allowed:\n"
2699 " %R = <reason>\n"
2700 " %S = <suffix>\n"
2701 " %T = <turn-number>\n"
2702 " %Y = <game-year>\n"
2703 "\n"
2704 "Example: 'freeciv-T%04T-Y%+05Y-%R' => "
2705 "'freeciv-T0100-Y00001-manual'\n"
2706 "\n"
2707 "Be careful to use at least one of %T and %Y, else newer "
2708 "savegames will overwrite old ones. If none of the formats "
2709 "is used '-T%04T-Y%05Y-%R' is appended to the value of "
2710 "'savename'."),
2711 savename_validate, NULL, GAME_DEFAULT_SAVE_NAME)
2713 GEN_BOOL("scorelog", game.server.scorelog,
2714 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_SERVER_ONLY,
2715 N_("Whether to log player statistics"),
2716 /* TRANS: The string between single quotes is a setting name and
2717 * should not be translated. */
2718 N_("If this is turned on, player statistics are appended to "
2719 "the file defined by the option 'scorefile' every turn. "
2720 "These statistics can be used to create power graphs after "
2721 "the game."), NULL, scorelog_action, GAME_DEFAULT_SCORELOG)
2723 GEN_ENUM("scoreloglevel", game.server.scoreloglevel,
2724 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_SERVER_ONLY,
2725 N_("Scorelog level"),
2726 N_("Whether scores are logged for all players including AIs, "
2727 "or only for human players."), NULL, NULL, NULL,
2728 scoreloglevel_name, GAME_DEFAULT_SCORELOGLEVEL)
2730 GEN_STRING("scorefile", game.server.scorefile,
2731 SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_SERVER_ONLY,
2732 N_("Name for the score log file"),
2733 /* TRANS: Don't translate the string in single quotes. */
2734 N_("The default name for the score log file is "
2735 "'freeciv-score.log'."),
2736 scorefile_validate, NULL, GAME_DEFAULT_SCOREFILE)
2738 GEN_INT("maxconnectionsperhost", game.server.maxconnectionsperhost,
2739 SSET_RULES_FLEXIBLE, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
2740 N_("Maximum number of connections to the server per host"),
2741 N_("New connections from a given host will be rejected if "
2742 "the total number of connections from the very same host "
2743 "equals or exceeds this value. A value of 0 means that "
2744 "there is no limit, at least up to the maximum number of "
2745 "connections supported by the server."), NULL, NULL, NULL,
2746 GAME_MIN_MAXCONNECTIONSPERHOST, GAME_MAX_MAXCONNECTIONSPERHOST,
2747 GAME_DEFAULT_MAXCONNECTIONSPERHOST)
2749 GEN_INT("kicktime", game.server.kick_time,
2750 SSET_RULES_FLEXIBLE, SSET_NETWORK, SSET_RARE, SSET_SERVER_ONLY,
2751 N_("Time before a kicked user can reconnect"),
2752 /* TRANS: the string in double quotes is a server command name and
2753 * should not be translated */
2754 N_("Gives the time in seconds before a user kicked using the "
2755 "\"kick\" command may reconnect. Changing this setting will "
2756 "affect users kicked in the past."), NULL, NULL, NULL,
2757 GAME_MIN_KICK_TIME, GAME_MAX_KICK_TIME, GAME_DEFAULT_KICK_TIME)
2760 #undef GEN_BOOL
2761 #undef GEN_INT
2762 #undef GEN_STRING
2763 #undef GEN_ENUM
2764 #undef GEN_BITWISE
2766 /* The number of settings, not including the END. */
2767 static const int SETTINGS_NUM = ARRAY_SIZE(settings);
2769 /****************************************************************************
2770 Returns the setting to the given id.
2771 ****************************************************************************/
2772 struct setting *setting_by_number(int id)
2774 return (0 <= id && id < SETTINGS_NUM ? settings + id : NULL);
2777 /****************************************************************************
2778 Returns the setting to the given name.
2779 ****************************************************************************/
2780 struct setting *setting_by_name(const char *name)
2782 fc_assert_ret_val(name, NULL);
2784 settings_iterate(SSET_ALL, pset) {
2785 if (0 == strcmp(name, pset->name)) {
2786 return pset;
2788 } settings_iterate_end;
2789 return NULL;
2792 /****************************************************************************
2793 Returns the id to the given setting.
2794 ****************************************************************************/
2795 int setting_number(const struct setting *pset)
2797 fc_assert_ret_val(pset != NULL, -1);
2798 return pset - settings;
2801 /****************************************************************************
2802 Access function for the setting name.
2803 ****************************************************************************/
2804 const char *setting_name(const struct setting *pset)
2806 return pset->name;
2809 /****************************************************************************
2810 Access function for the short help (not translated yet) of the setting.
2811 ****************************************************************************/
2812 const char *setting_short_help(const struct setting *pset)
2814 return pset->short_help;
2817 /****************************************************************************
2818 Access function for the long (extra) help of the setting.
2819 If 'constant' is TRUE, static, not-yet-translated string is always returned.
2820 ****************************************************************************/
2821 const char *setting_extra_help(const struct setting *pset, bool constant)
2823 if (!constant && pset->help_func != NULL) {
2824 return pset->help_func(pset);
2827 return _(pset->extra_help);
2830 /****************************************************************************
2831 Access function for the setting type.
2832 ****************************************************************************/
2833 enum sset_type setting_type(const struct setting *pset)
2835 return pset->stype;
2838 /****************************************************************************
2839 Access function for the setting level (used by the /show command).
2840 ****************************************************************************/
2841 enum sset_level setting_level(const struct setting *pset)
2843 return pset->slevel;
2846 /****************************************************************************
2847 Access function for the setting category.
2848 ****************************************************************************/
2849 enum sset_category setting_category(const struct setting *pset)
2851 return pset->scategory;
2854 /****************************************************************************
2855 Returns whether the specified server setting (option) can currently
2856 be changed without breaking data consistency (map dimension options
2857 can't change when map has already been created with certain dimensions)
2858 ****************************************************************************/
2859 static bool setting_is_free_to_change(const struct setting *pset,
2860 char *reject_msg,
2861 size_t reject_msg_len)
2863 switch (pset->sclass) {
2864 case SSET_MAP_SIZE:
2865 case SSET_MAP_GEN:
2866 /* Only change map options if we don't yet have a map: */
2867 if (map_is_empty()) {
2868 return TRUE;
2871 settings_snprintf(reject_msg, reject_msg_len,
2872 _("The setting '%s' can't be modified after the map "
2873 "is fixed."), setting_name(pset));
2874 return FALSE;
2876 case SSET_RULES_SCENARIO:
2877 /* Like SSET_RULES except that it can be changed before the game starts
2878 * for heavy scenarios. A heavy scenario comes with players. It can
2879 * include cities, units, diplomatic relations and other complex
2880 * state. Make sure that changing a setting can't make the state of a
2881 * heavy scenario illegal if you want to change it from SSET_RULES to
2882 * SSET_RULES_SCENARIO. */
2884 if (game.scenario.is_scenario && game.scenario.players
2885 && server_state() == S_S_INITIAL) {
2886 /* Special case detected. */
2887 return TRUE;
2890 /* The special case didn't make it legal to change the setting. Don't
2891 * give up. It could still be legal. Fall through so the non special
2892 * cases are checked too. */
2894 case SSET_MAP_ADD:
2895 case SSET_PLAYERS:
2896 case SSET_GAME_INIT:
2897 case SSET_RULES:
2898 /* Only change start params and most rules if we don't yet have a map,
2899 * or if we do have a map but its a scenario one (ie, the game has
2900 * never actually been started).
2902 if (map_is_empty() || game.info.is_new_game) {
2903 return TRUE;
2906 settings_snprintf(reject_msg, reject_msg_len,
2907 _("The setting '%s' can't be modified after the game "
2908 "has started."), setting_name(pset));
2909 return FALSE;
2911 case SSET_RULES_FLEXIBLE:
2912 case SSET_META:
2913 /* These can always be changed: */
2914 return TRUE;
2917 log_error("Wrong class variant for setting %s (%d): %d.",
2918 setting_name(pset), setting_number(pset), pset->sclass);
2919 settings_snprintf(reject_msg, reject_msg_len, _("Internal error."));
2921 return FALSE;
2924 /****************************************************************************
2925 Returns whether the specified server setting (option) can currently
2926 be changed by the caller. If it returns FALSE, the reason of the failure
2927 is available by the function setting_error().
2928 ****************************************************************************/
2929 bool setting_is_changeable(const struct setting *pset,
2930 struct connection *caller, char *reject_msg,
2931 size_t reject_msg_len)
2933 if (caller
2934 && (caller->access_level < ALLOW_BASIC
2935 || (caller->access_level < ALLOW_HACK && !pset->to_client))) {
2936 settings_snprintf(reject_msg, reject_msg_len,
2937 _("You are not allowed to change the setting '%s'."),
2938 setting_name(pset));
2939 return FALSE;
2942 if (setting_locked(pset)) {
2943 /* setting is locked by the ruleset */
2944 settings_snprintf(reject_msg, reject_msg_len,
2945 _("The setting '%s' is locked by the ruleset."),
2946 setting_name(pset));
2947 return FALSE;
2950 return setting_is_free_to_change(pset, reject_msg, reject_msg_len);
2953 /****************************************************************************
2954 Returns whether the specified server setting (option) can be seen by the
2955 caller.
2956 ****************************************************************************/
2957 bool setting_is_visible(const struct setting *pset,
2958 struct connection *caller)
2960 return (!caller
2961 || pset->to_client
2962 || caller->access_level >= ALLOW_HACK);
2965 /****************************************************************************
2966 Convert the string prefix to an integer representation.
2967 NB: This function is used for SSET_ENUM *and* SSET_BITWISE.
2969 FIXME: this mostly duplicate match_prefix_full().
2970 ****************************************************************************/
2971 static enum m_pre_result
2972 setting_match_prefix_base(const val_name_func_t name_fn,
2973 const char *prefix, int *ind_result,
2974 const char **matches, size_t max_matches,
2975 size_t *pnum_matches)
2977 const struct sset_val_name *name;
2978 size_t len = strlen(prefix);
2979 size_t num_matches;
2980 int i;
2982 *pnum_matches = 0;
2984 if (0 == len) {
2985 return M_PRE_EMPTY;
2988 for (i = 0, num_matches = 0; (name = name_fn(i)); i++) {
2989 if (0 == fc_strncasecmp(name->support, prefix, len)) {
2990 if (strlen(name->support) == len) {
2991 *ind_result = i;
2992 return M_PRE_EXACT;
2994 if (num_matches < max_matches) {
2995 matches[num_matches] = name->support;
2996 (*pnum_matches)++;
2998 if (0 == num_matches++) {
2999 *ind_result = i;
3004 if (1 == num_matches) {
3005 return M_PRE_ONLY;
3006 } else if (1 < num_matches) {
3007 return M_PRE_AMBIGUOUS;
3008 } else {
3009 return M_PRE_FAIL;
3013 /****************************************************************************
3014 Convert the string prefix to an integer representation.
3015 NB: This function is used for SSET_ENUM *and* SSET_BITWISE.
3016 ****************************************************************************/
3017 static bool setting_match_prefix(const val_name_func_t name_fn,
3018 const char *prefix, int *pvalue,
3019 char *reject_msg,
3020 size_t reject_msg_len)
3022 const char *matches[16];
3023 size_t num_matches;
3025 switch (setting_match_prefix_base(name_fn, prefix, pvalue, matches,
3026 ARRAY_SIZE(matches), &num_matches)) {
3027 case M_PRE_EXACT:
3028 case M_PRE_ONLY:
3029 return TRUE; /* Ok. */
3030 case M_PRE_AMBIGUOUS:
3032 struct astring astr = ASTRING_INIT;
3034 fc_assert(2 <= num_matches);
3035 settings_snprintf(reject_msg, reject_msg_len,
3036 _("\"%s\" prefix is ambiguous. Candidates are: %s."),
3037 prefix,
3038 astr_build_and_list(&astr, matches, num_matches));
3039 astr_free(&astr);
3041 return FALSE;
3042 case M_PRE_EMPTY:
3043 settings_snprintf(reject_msg, reject_msg_len, _("Missing value."));
3044 return FALSE;
3045 case M_PRE_LONG:
3046 case M_PRE_FAIL:
3047 case M_PRE_LAST:
3048 break;
3051 settings_snprintf(reject_msg, reject_msg_len,
3052 _("No match for \"%s\"."), prefix);
3053 return FALSE;
3056 /****************************************************************************
3057 Compute the string representation of the value for this boolean setting.
3058 ****************************************************************************/
3059 static const char *setting_bool_to_str(const struct setting *pset,
3060 bool value, bool pretty,
3061 char *buf, size_t buf_len)
3063 const struct sset_val_name *name = pset->boolean.name(value);
3065 if (pretty) {
3066 fc_snprintf(buf, buf_len, "%s", Q_(name->pretty));
3067 } else {
3068 fc_strlcpy(buf, name->support, buf_len);
3070 return buf;
3073 /****************************************************************************
3074 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3075 the reason of the failure is available in the optionnal parameter
3076 'reject_msg'.
3078 FIXME: also check the access level of pconn.
3079 ****************************************************************************/
3080 static bool setting_bool_validate_base(const struct setting *pset,
3081 const char *val, int *pint_val,
3082 struct connection *caller,
3083 char *reject_msg,
3084 size_t reject_msg_len)
3086 char buf[256];
3088 if (SSET_BOOL != pset->stype) {
3089 settings_snprintf(reject_msg, reject_msg_len,
3090 _("This setting is not a boolean."));
3091 return FALSE;
3094 sz_strlcpy(buf, val);
3095 remove_leading_trailing_spaces(buf);
3097 return (setting_match_prefix(pset->boolean.name, buf, pint_val,
3098 reject_msg, reject_msg_len)
3099 && (NULL == pset->boolean.validate
3100 || pset->boolean.validate(0 != *pint_val, caller, reject_msg,
3101 reject_msg_len)));
3104 /****************************************************************************
3105 Set the setting to 'val'. Returns TRUE on success. If it's not,
3106 the reason of the failure is available in the optionnal parameter
3107 'reject_msg'.
3108 ****************************************************************************/
3109 bool setting_bool_set(struct setting *pset, const char *val,
3110 struct connection *caller, char *reject_msg,
3111 size_t reject_msg_len)
3113 int int_val;
3115 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
3116 || !setting_bool_validate_base(pset, val, &int_val, caller,
3117 reject_msg, reject_msg_len)) {
3118 return FALSE;
3121 *pset->boolean.pvalue = (0 != int_val);
3122 return TRUE;
3125 /****************************************************************************
3126 Get value of boolean setting
3127 ****************************************************************************/
3128 bool setting_bool_get(struct setting *pset)
3130 fc_assert(setting_type(pset) == SSET_BOOL);
3132 return *pset->boolean.pvalue;
3135 /****************************************************************************
3136 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3137 the reason of the failure is available in the optionnal parameter
3138 'reject_msg'.
3139 ****************************************************************************/
3140 bool setting_bool_validate(const struct setting *pset, const char *val,
3141 struct connection *caller, char *reject_msg,
3142 size_t reject_msg_len)
3144 int int_val;
3146 return setting_bool_validate_base(pset, val, &int_val, caller,
3147 reject_msg, reject_msg_len);
3150 /****************************************************************************
3151 Convert the integer to the long support string representation of a boolean
3152 setting. This function must match the secfile_enum_name_data_fn_t type.
3153 ****************************************************************************/
3154 static const char *setting_bool_secfile_str(secfile_data_t data, int val)
3156 const struct sset_val_name *name =
3157 ((const struct setting *) data)->boolean.name(val);
3159 return (NULL != name ? name->support : NULL);
3162 /****************************************************************************
3163 Compute the string representation of the value for this integer setting.
3164 ****************************************************************************/
3165 static const char *setting_int_to_str(const struct setting *pset,
3166 int value, bool pretty,
3167 char *buf, size_t buf_len)
3169 fc_snprintf(buf, buf_len, "%d", value);
3170 return buf;
3173 /****************************************************************************
3174 Returns the minimal integer value for this setting.
3175 ****************************************************************************/
3176 int setting_int_min(const struct setting *pset)
3178 fc_assert_ret_val(pset->stype == SSET_INT, 0);
3179 return pset->integer.min_value;
3182 /****************************************************************************
3183 Returns the maximal integer value for this setting.
3184 ****************************************************************************/
3185 int setting_int_max(const struct setting *pset)
3187 fc_assert_ret_val(pset->stype == SSET_INT, 0);
3188 return pset->integer.max_value;
3191 /****************************************************************************
3192 Set the setting to 'val'. Returns TRUE on success. If it fails, the
3193 reason of the failure is available by the function setting_error().
3194 ****************************************************************************/
3195 bool setting_int_set(struct setting *pset, int val,
3196 struct connection *caller, char *reject_msg,
3197 size_t reject_msg_len)
3199 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
3200 || !setting_int_validate(pset, val, caller, reject_msg,
3201 reject_msg_len)) {
3202 return FALSE;
3205 *pset->integer.pvalue = val;
3206 return TRUE;
3209 /****************************************************************************
3210 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3211 the reason of the failure is available by the function setting_error().
3213 FIXME: also check the access level of pconn.
3214 ****************************************************************************/
3215 bool setting_int_validate(const struct setting *pset, int val,
3216 struct connection *caller, char *reject_msg,
3217 size_t reject_msg_len)
3219 if (SSET_INT != pset->stype) {
3220 settings_snprintf(reject_msg, reject_msg_len,
3221 _("This setting is not an integer."));
3222 return FALSE;
3225 if (val < pset->integer.min_value || val > pset->integer.max_value) {
3226 settings_snprintf(reject_msg, reject_msg_len,
3227 _("Value out of range: %d (min: %d; max: %d)."),
3228 val, pset->integer.min_value, pset->integer.max_value);
3229 return FALSE;
3232 return (!pset->integer.validate
3233 || pset->integer.validate(val, caller, reject_msg,
3234 reject_msg_len));
3237 /****************************************************************************
3238 Get value of integer setting
3239 ****************************************************************************/
3240 int setting_int_get(struct setting *pset)
3242 fc_assert(setting_type(pset) == SSET_INT);
3244 return *pset->integer.pvalue;
3247 /****************************************************************************
3248 Compute the string representation of the value for this string setting.
3249 ****************************************************************************/
3250 static const char *setting_str_to_str(const struct setting *pset,
3251 const char *value, bool pretty,
3252 char *buf, size_t buf_len)
3254 if (pretty) {
3255 fc_snprintf(buf, buf_len, "\"%s\"", value);
3256 } else {
3257 fc_strlcpy(buf, value, buf_len);
3259 return buf;
3262 /****************************************************************************
3263 Set the setting to 'val'. Returns TRUE on success. If it fails, the
3264 reason of the failure is available by the function setting_error().
3265 ****************************************************************************/
3266 bool setting_str_set(struct setting *pset, const char *val,
3267 struct connection *caller, char *reject_msg,
3268 size_t reject_msg_len)
3270 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
3271 || !setting_str_validate(pset, val, caller, reject_msg,
3272 reject_msg_len)) {
3273 return FALSE;
3276 fc_strlcpy(pset->string.value, val, pset->string.value_size);
3277 return TRUE;
3280 /****************************************************************************
3281 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3282 the reason of the failure is available by the function setting_error().
3284 FIXME: also check the access level of pconn.
3285 ****************************************************************************/
3286 bool setting_str_validate(const struct setting *pset, const char *val,
3287 struct connection *caller, char *reject_msg,
3288 size_t reject_msg_len)
3290 if (SSET_STRING != pset->stype) {
3291 settings_snprintf(reject_msg, reject_msg_len,
3292 _("This setting is not a string."));
3293 return FALSE;
3296 if (strlen(val) >= pset->string.value_size) {
3297 settings_snprintf(reject_msg, reject_msg_len,
3298 _("String value too long (max length: %lu)."),
3299 (unsigned long) pset->string.value_size);
3300 return FALSE;
3303 return (!pset->string.validate
3304 || pset->string.validate(val, caller, reject_msg,
3305 reject_msg_len));
3308 /****************************************************************************
3309 Get value of string setting
3310 ****************************************************************************/
3311 char *setting_str_get(struct setting *pset)
3313 fc_assert(setting_type(pset) == SSET_STRING);
3315 return pset->string.value;
3318 /****************************************************************************
3319 Convert the integer to the long support string representation of an
3320 enumerator. This function must match the secfile_enum_name_data_fn_t type.
3321 ****************************************************************************/
3322 const char *setting_enum_secfile_str(secfile_data_t data, int val)
3324 const struct sset_val_name *name =
3325 ((const struct setting *) data)->enumerator.name(val);
3327 return (NULL != name ? name->support : NULL);
3330 /****************************************************************************
3331 Convert the integer to the string representation of an enumerator.
3332 Return NULL if 'val' is not a valid enumerator.
3333 ****************************************************************************/
3334 const char *setting_enum_val(const struct setting *pset, int val,
3335 bool pretty)
3337 const struct sset_val_name *name;
3339 fc_assert_ret_val(SSET_ENUM == pset->stype, NULL);
3340 name = pset->enumerator.name(val);
3341 if (NULL == name) {
3342 return NULL;
3343 } else if (pretty) {
3344 return _(name->pretty);
3345 } else {
3346 return name->support;
3350 /****************************************************************************
3351 Compute the string representation of the value for this enumerator
3352 setting.
3353 ****************************************************************************/
3354 static const char *setting_enum_to_str(const struct setting *pset,
3355 int value, bool pretty,
3356 char *buf, size_t buf_len)
3358 const struct sset_val_name *name = pset->enumerator.name(value);
3360 if (pretty) {
3361 fc_snprintf(buf, buf_len, "\"%s\" (%s)",
3362 Q_(name->pretty), name->support);
3363 } else {
3364 fc_strlcpy(buf, name->support, buf_len);
3366 return buf;
3369 /****************************************************************************
3370 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3371 the reason of the failure is available in the optionnal parameter
3372 'reject_msg'.
3374 FIXME: also check the access level of pconn.
3375 ****************************************************************************/
3376 static bool setting_enum_validate_base(const struct setting *pset,
3377 const char *val, int *pint_val,
3378 struct connection *caller,
3379 char *reject_msg,
3380 size_t reject_msg_len)
3382 char buf[256];
3384 if (SSET_ENUM != pset->stype) {
3385 settings_snprintf(reject_msg, reject_msg_len,
3386 _("This setting is not an enumerator."));
3387 return FALSE;
3390 sz_strlcpy(buf, val);
3391 remove_leading_trailing_spaces(buf);
3393 return (setting_match_prefix(pset->enumerator.name, buf, pint_val,
3394 reject_msg, reject_msg_len)
3395 && (NULL == pset->enumerator.validate
3396 || pset->enumerator.validate(*pint_val, caller, reject_msg,
3397 reject_msg_len)));
3400 /****************************************************************************
3401 Helper function to write value to enumerator setting
3402 ****************************************************************************/
3403 static bool set_enum_value(struct setting *pset, int val)
3405 switch(pset->enumerator.store_size) {
3406 case sizeof(int):
3408 int *to_int = pset->enumerator.pvalue;
3410 *to_int = val;
3412 break;
3413 case sizeof(char):
3415 char *to_char = pset->enumerator.pvalue;
3417 *to_char = (char) val;
3419 break;
3420 case sizeof(short):
3422 short *to_short = pset->enumerator.pvalue;
3424 *to_short = (short) val;
3426 break;
3427 default:
3428 return FALSE;
3431 return TRUE;
3434 /****************************************************************************
3435 Helper function to read value from enumerator setting
3436 ****************************************************************************/
3437 int read_enum_value(const struct setting *pset)
3439 int val;
3441 switch(pset->enumerator.store_size) {
3442 case sizeof(int):
3443 val = *((int *)pset->enumerator.pvalue);
3444 break;
3445 case sizeof(char):
3446 val = *((char *)pset->enumerator.pvalue);
3447 break;
3448 case sizeof(short):
3449 val = *((short *)pset->enumerator.pvalue);
3450 break;
3451 default:
3452 log_error("Illegal enum store size %d, can't read value", pset->enumerator.store_size);
3453 return 0;
3456 return val;
3459 /****************************************************************************
3460 Set the setting to 'val'. Returns TRUE on success. If it fails, the
3461 reason of the failure is available in the optionnal parameter
3462 'reject_msg'.
3463 ****************************************************************************/
3464 bool setting_enum_set(struct setting *pset, const char *val,
3465 struct connection *caller, char *reject_msg,
3466 size_t reject_msg_len)
3468 int int_val;
3470 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)) {
3471 return FALSE;
3474 if (!setting_enum_validate_base(pset, val, &int_val, caller,
3475 reject_msg, reject_msg_len)) {
3476 return FALSE;
3479 if (!set_enum_value(pset, int_val)) {
3480 log_error("Illegal enumerator value size %d for %s",
3481 pset->enumerator.store_size, val);
3482 return FALSE;
3485 return TRUE;
3488 /****************************************************************************
3489 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3490 the reason of the failure is available in the optionnal parameter
3491 'reject_msg'.
3492 ****************************************************************************/
3493 bool setting_enum_validate(const struct setting *pset, const char *val,
3494 struct connection *caller, char *reject_msg,
3495 size_t reject_msg_len)
3497 int int_val;
3499 return setting_enum_validate_base(pset, val, &int_val, caller,
3500 reject_msg, reject_msg_len);
3503 /****************************************************************************
3504 Convert the integer to the long support string representation of an
3505 enumerator. This function must match the secfile_enum_name_data_fn_t type.
3506 ****************************************************************************/
3507 const char *setting_bitwise_secfile_str(secfile_data_t data, int bit)
3509 const struct sset_val_name *name =
3510 ((const struct setting *) data)->bitwise.name(bit);
3512 return (NULL != name ? name->support : NULL);
3515 /****************************************************************************
3516 Convert the bit number to its string representation.
3517 Return NULL if 'bit' is not a valid bit.
3518 ****************************************************************************/
3519 const char *setting_bitwise_bit(const struct setting *pset,
3520 int bit, bool pretty)
3522 const struct sset_val_name *name;
3524 fc_assert_ret_val(SSET_BITWISE == pset->stype, NULL);
3525 name = pset->bitwise.name(bit);
3526 if (NULL == name) {
3527 return NULL;
3528 } else if (pretty) {
3529 return _(name->pretty);
3530 } else {
3531 return name->support;
3535 /****************************************************************************
3536 Compute the string representation of the value for this bitwise setting.
3537 ****************************************************************************/
3538 static const char *setting_bitwise_to_str(const struct setting *pset,
3539 unsigned value, bool pretty,
3540 char *buf, size_t buf_len)
3542 const struct sset_val_name *name;
3543 char *old_buf = buf;
3544 int bit;
3546 if (pretty) {
3547 char buf2[256];
3548 struct astring astr = ASTRING_INIT;
3549 struct strvec *vec = strvec_new();
3550 size_t len;
3552 for (bit = 0; (name = pset->bitwise.name(bit)); bit++) {
3553 if ((1 << bit) & value) {
3554 /* TRANS: only emphasizing a string. */
3555 fc_snprintf(buf2, sizeof(buf2), _("\"%s\""), Q_(name->pretty));
3556 strvec_append(vec, buf2);
3560 if (0 == strvec_size(vec)) {
3561 /* No value. */
3562 fc_assert(0 == value);
3563 /* TRANS: Bitwise setting has no bits set. */
3564 fc_strlcpy(buf, _("empty value"), buf_len);
3565 strvec_destroy(vec);
3566 return buf;
3569 strvec_to_and_list(vec, &astr);
3570 strvec_destroy(vec);
3571 fc_strlcpy(buf, astr_str(&astr), buf_len);
3572 astr_free(&astr);
3573 fc_strlcat(buf, " (", buf_len);
3574 len = strlen(buf);
3575 buf += len;
3576 buf_len -= len;
3579 /* Long support part. */
3580 buf[0] = '\0';
3581 for (bit = 0; (name = pset->bitwise.name(bit)); bit++) {
3582 if ((1 << bit) & value) {
3583 if ('\0' != buf[0]) {
3584 fc_strlcat(buf, "|", buf_len);
3586 fc_strlcat(buf, name->support, buf_len);
3590 if (pretty) {
3591 fc_strlcat(buf, ")", buf_len);
3593 return old_buf;
3596 /****************************************************************************
3597 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3598 the reason of the failure is available in the optionnal parameter
3599 'reject_msg'.
3601 FIXME: also check the access level of pconn.
3602 ****************************************************************************/
3603 static bool setting_bitwise_validate_base(const struct setting *pset,
3604 const char *val,
3605 unsigned *pint_val,
3606 struct connection *caller,
3607 char *reject_msg,
3608 size_t reject_msg_len)
3610 char buf[256];
3611 const char *p;
3612 int bit;
3614 if (SSET_BITWISE != pset->stype) {
3615 settings_snprintf(reject_msg, reject_msg_len,
3616 _("This setting is not a bitwise."));
3617 return FALSE;
3620 *pint_val = 0;
3622 /* Value names are separated by '|'. */
3623 do {
3624 p = strchr(val, '|');
3625 if (NULL != p) {
3626 p++;
3627 fc_strlcpy(buf, val, MIN(p - val, sizeof(buf)));
3628 } else {
3629 /* Last segment, full copy. */
3630 sz_strlcpy(buf, val);
3632 remove_leading_trailing_spaces(buf);
3633 if (NULL == p && '\0' == buf[0] && 0 == *pint_val) {
3634 /* Empty string = value 0. */
3635 break;
3636 } else if (!setting_match_prefix(pset->bitwise.name, buf, &bit,
3637 reject_msg, reject_msg_len)) {
3638 return FALSE;
3640 *pint_val |= 1 << bit;
3641 val = p;
3642 } while (NULL != p);
3644 return (NULL == pset->bitwise.validate
3645 || pset->bitwise.validate(*pint_val, caller,
3646 reject_msg, reject_msg_len));
3649 /****************************************************************************
3650 Set the setting to 'val'. Returns TRUE on success. If it fails, the
3651 reason of the failure is available in the optionnal parameter
3652 'reject_msg'.
3653 ****************************************************************************/
3654 bool setting_bitwise_set(struct setting *pset, const char *val,
3655 struct connection *caller, char *reject_msg,
3656 size_t reject_msg_len)
3658 unsigned int_val;
3660 if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
3661 || !setting_bitwise_validate_base(pset, val, &int_val, caller,
3662 reject_msg, reject_msg_len)) {
3663 return FALSE;
3666 *pset->bitwise.pvalue = int_val;
3667 return TRUE;
3670 /****************************************************************************
3671 Returns TRUE if 'val' is a valid value for this setting. If it's not,
3672 the reason of the failure is available in the optionnal parameter
3673 'reject_msg'.
3674 ****************************************************************************/
3675 bool setting_bitwise_validate(const struct setting *pset, const char *val,
3676 struct connection *caller, char *reject_msg,
3677 size_t reject_msg_len)
3679 unsigned int_val;
3681 return setting_bitwise_validate_base(pset, val, &int_val, caller,
3682 reject_msg, reject_msg_len);
3685 /****************************************************************************
3686 Get value of bitwise setting
3687 ****************************************************************************/
3688 int setting_bitwise_get(struct setting *pset)
3690 fc_assert(setting_type(pset) == SSET_BITWISE);
3692 return *pset->bitwise.pvalue;
3695 /****************************************************************************
3696 Compute the name of the current value of the setting.
3697 ****************************************************************************/
3698 const char *setting_value_name(const struct setting *pset, bool pretty,
3699 char *buf, size_t buf_len)
3701 fc_assert_ret_val(NULL != pset, NULL);
3702 fc_assert_ret_val(NULL != buf, NULL);
3703 fc_assert_ret_val(0 < buf_len, NULL);
3705 switch (pset->stype) {
3706 case SSET_BOOL:
3707 return setting_bool_to_str(pset, *pset->boolean.pvalue,
3708 pretty, buf, buf_len);
3709 case SSET_INT:
3710 return setting_int_to_str(pset, *pset->integer.pvalue,
3711 pretty, buf, buf_len);
3712 case SSET_STRING:
3713 return setting_str_to_str(pset, pset->string.value,
3714 pretty, buf, buf_len);
3715 case SSET_ENUM:
3716 return setting_enum_to_str(pset, read_enum_value(pset),
3717 pretty, buf, buf_len);
3718 case SSET_BITWISE:
3719 return setting_bitwise_to_str(pset, *pset->bitwise.pvalue,
3720 pretty, buf, buf_len);
3723 log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
3724 __FUNCTION__, setting_name(pset), setting_number(pset));
3725 return NULL;
3728 /****************************************************************************
3729 Compute the name of the default value of the setting.
3730 ****************************************************************************/
3731 const char *setting_default_name(const struct setting *pset, bool pretty,
3732 char *buf, size_t buf_len)
3734 fc_assert_ret_val(NULL != pset, NULL);
3735 fc_assert_ret_val(NULL != buf, NULL);
3736 fc_assert_ret_val(0 < buf_len, NULL);
3738 switch (pset->stype) {
3739 case SSET_BOOL:
3740 return setting_bool_to_str(pset, pset->boolean.default_value,
3741 pretty, buf, buf_len);
3742 case SSET_INT:
3743 return setting_int_to_str(pset, pset->integer.default_value,
3744 pretty, buf, buf_len);
3745 case SSET_STRING:
3746 return setting_str_to_str(pset, pset->string.default_value,
3747 pretty, buf, buf_len);
3748 case SSET_ENUM:
3749 return setting_enum_to_str(pset, pset->enumerator.default_value,
3750 pretty, buf, buf_len);
3751 case SSET_BITWISE:
3752 return setting_bitwise_to_str(pset, pset->bitwise.default_value,
3753 pretty, buf, buf_len);
3756 log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
3757 __FUNCTION__, setting_name(pset), setting_number(pset));
3758 return NULL;
3761 /****************************************************************************
3762 Update the setting to the default value
3763 ****************************************************************************/
3764 void setting_set_to_default(struct setting *pset)
3766 switch (pset->stype) {
3767 case SSET_BOOL:
3768 (*pset->boolean.pvalue) = pset->boolean.default_value;
3769 break;
3770 case SSET_INT:
3771 (*pset->integer.pvalue) = pset->integer.default_value;
3772 break;
3773 case SSET_STRING:
3774 fc_strlcpy(pset->string.value, pset->string.default_value,
3775 pset->string.value_size);
3776 break;
3777 case SSET_ENUM:
3778 set_enum_value(pset, pset->enumerator.default_value);
3779 break;
3780 case SSET_BITWISE:
3781 (*pset->bitwise.pvalue) = pset->bitwise.default_value;
3782 break;
3785 pset->setdef = SETDEF_INTERNAL;
3788 /********************************************************************
3789 Execute the action callback if needed.
3790 *********************************************************************/
3791 void setting_action(const struct setting *pset)
3793 if (pset->action != NULL) {
3794 pset->action(pset);
3798 /**************************************************************************
3799 Load game settings from ruleset file 'game.ruleset'.
3800 **************************************************************************/
3801 bool settings_ruleset(struct section_file *file, const char *section,
3802 bool act)
3804 const char *name;
3805 int j;
3807 /* Unlock all settings. */
3808 settings_iterate(SSET_ALL, pset) {
3809 setting_lock_set(pset, FALSE);
3810 setting_set_to_default(pset);
3811 } settings_iterate_end;
3813 /* settings */
3814 if (NULL == secfile_section_by_name(file, section)) {
3815 /* no settings in ruleset file */
3816 log_verbose("no [%s] section for game settings in %s", section,
3817 secfile_name(file));
3818 } else {
3819 for (j = 0; (name = secfile_lookup_str_default(file, NULL, "%s.set%d.name",
3820 section, j)); j++) {
3821 char path[256];
3822 fc_snprintf(path, sizeof(path), "%s.set%d", section, j);
3824 if (!setting_ruleset_one(file, name, path)) {
3825 log_error("unknown setting in '%s': %s", secfile_name(file), name);
3830 /* Execute all setting actions to consider actions due to the
3831 * default values. */
3832 if (act) {
3833 settings_iterate(SSET_ALL, pset) {
3834 setting_action(pset);
3835 } settings_iterate_end;
3838 autolock_settings();
3840 /* send game settings */
3841 send_server_settings(NULL);
3843 return TRUE;
3846 /**************************************************************************
3847 Set one setting from the game.ruleset file.
3848 **************************************************************************/
3849 static bool setting_ruleset_one(struct section_file *file,
3850 const char *name, const char *path)
3852 struct setting *pset = NULL;
3853 char reject_msg[256], buf[256];
3854 bool lock;
3856 settings_iterate(SSET_ALL, pset_check) {
3857 if (0 == fc_strcasecmp(setting_name(pset_check), name)) {
3858 pset = pset_check;
3859 break;
3861 } settings_iterate_end;
3863 if (pset == NULL) {
3864 /* no setting found */
3865 return FALSE;
3868 switch (pset->stype) {
3869 case SSET_BOOL:
3871 int ival;
3872 bool val;
3874 /* Allow string with same boolean representation as accepted on
3875 * server command line */
3876 if (secfile_lookup_enum_data(file, &ival, FALSE,
3877 setting_bool_secfile_str, pset,
3878 "%s.value", path)) {
3879 val = (ival != 0);
3880 } else if (!secfile_lookup_bool(file, &val, "%s.value", path)) {
3881 log_error("Can't read value for setting '%s': %s", name,
3882 secfile_error());
3883 break;
3885 if (val != *pset->boolean.pvalue) {
3886 if (NULL == pset->boolean.validate
3887 || pset->boolean.validate(val, NULL, reject_msg,
3888 sizeof(reject_msg))) {
3889 *pset->boolean.pvalue = val;
3890 log_normal(_("Ruleset: '%s' has been set to %s."),
3891 setting_name(pset),
3892 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3893 } else {
3894 log_error("%s", reject_msg);
3898 break;
3900 case SSET_INT:
3902 int val;
3904 if (!secfile_lookup_int(file, &val, "%s.value", path)) {
3905 log_error("Can't read value for setting '%s': %s", name,
3906 secfile_error());
3907 } else if (val != *pset->integer.pvalue) {
3908 if (setting_int_set(pset, val, NULL, reject_msg,
3909 sizeof(reject_msg))) {
3910 log_normal(_("Ruleset: '%s' has been set to %s."),
3911 setting_name(pset),
3912 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3913 } else {
3914 log_error("%s", reject_msg);
3918 break;
3920 case SSET_STRING:
3922 const char *val = secfile_lookup_str(file, "%s.value", path);
3924 if (NULL == val) {
3925 log_error("Can't read value for setting '%s': %s", name,
3926 secfile_error());
3927 } else if (0 != strcmp(val, pset->string.value)) {
3928 if (setting_str_set(pset, val, NULL, reject_msg,
3929 sizeof(reject_msg))) {
3930 log_normal(_("Ruleset: '%s' has been set to %s."),
3931 setting_name(pset),
3932 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3933 } else {
3934 log_error("%s", reject_msg);
3938 break;
3940 case SSET_ENUM:
3942 int val;
3944 if (!secfile_lookup_enum_data(file, &val, FALSE,
3945 setting_enum_secfile_str, pset,
3946 "%s.value", path)) {
3947 log_error("Can't read value for setting '%s': %s",
3948 name, secfile_error());
3949 } else if (val != read_enum_value(pset)) {
3950 if (NULL == pset->enumerator.validate
3951 || pset->enumerator.validate(val, NULL, reject_msg,
3952 sizeof(reject_msg))) {
3953 set_enum_value(pset, val);
3954 log_normal(_("Ruleset: '%s' has been set to %s."),
3955 setting_name(pset),
3956 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3957 } else {
3958 log_error("%s", reject_msg);
3962 break;
3964 case SSET_BITWISE:
3966 int val;
3968 if (!secfile_lookup_enum_data(file, &val, TRUE,
3969 setting_bitwise_secfile_str, pset,
3970 "%s.value", path)) {
3971 log_error("Can't read value for setting '%s': %s",
3972 name, secfile_error());
3973 } else if (val != *pset->bitwise.pvalue) {
3974 if (NULL == pset->bitwise.validate
3975 || pset->bitwise.validate((unsigned) val, NULL,
3976 reject_msg, sizeof(reject_msg))) {
3977 *pset->bitwise.pvalue = val;
3978 log_normal(_("Ruleset: '%s' has been set to %s."),
3979 setting_name(pset),
3980 setting_value_name(pset, TRUE, buf, sizeof(buf)));
3981 } else {
3982 log_error("%s", reject_msg);
3986 break;
3989 pset->setdef = SETDEF_RULESET;
3991 /* set lock */
3992 lock = secfile_lookup_bool_default(file, FALSE, "%s.lock", path);
3994 if (lock) {
3995 /* set lock */
3996 setting_lock_set(pset, lock);
3997 log_normal(_("Ruleset: '%s' has been locked by the ruleset."),
3998 setting_name(pset));
4001 return TRUE;
4004 /**************************************************************************
4005 Returns whether the setting has non-default value.
4006 **************************************************************************/
4007 bool setting_non_default(const struct setting *pset)
4009 switch (setting_type(pset)) {
4010 case SSET_BOOL:
4011 return (*pset->boolean.pvalue != pset->boolean.default_value);
4012 case SSET_INT:
4013 return (*pset->integer.pvalue != pset->integer.default_value);
4014 case SSET_STRING:
4015 return (0 != strcmp(pset->string.value, pset->string.default_value));
4016 case SSET_ENUM:
4017 return (read_enum_value(pset) != pset->enumerator.default_value);
4018 case SSET_BITWISE:
4019 return (*pset->bitwise.pvalue != pset->bitwise.default_value);
4022 log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
4023 __FUNCTION__, setting_name(pset), setting_number(pset));
4024 return FALSE;
4027 /**************************************************************************
4028 Returns if the setting is locked by the ruleset.
4029 **************************************************************************/
4030 bool setting_locked(const struct setting *pset)
4032 return pset->locked;
4035 /**************************************************************************
4036 Set the value for the lock of a setting.
4037 **************************************************************************/
4038 void setting_lock_set(struct setting *pset, bool lock)
4040 pset->locked = lock;
4043 /**************************************************************************
4044 Save the setting value of the current game.
4045 **************************************************************************/
4046 static void setting_game_set(struct setting *pset, bool init)
4048 switch (setting_type(pset)) {
4049 case SSET_BOOL:
4050 pset->boolean.game_value = *pset->boolean.pvalue;
4051 break;
4053 case SSET_INT:
4054 pset->integer.game_value = *pset->integer.pvalue;
4055 break;
4057 case SSET_STRING:
4058 if (init) {
4059 pset->string.game_value
4060 = fc_calloc(1, pset->string.value_size
4061 * sizeof(pset->string.game_value));
4063 fc_strlcpy(pset->string.game_value, pset->string.value,
4064 pset->string.value_size);
4065 break;
4067 case SSET_ENUM:
4068 pset->enumerator.game_value = read_enum_value(pset);
4069 break;
4071 case SSET_BITWISE:
4072 pset->bitwise.game_value = *pset->bitwise.pvalue;
4073 break;
4077 /**************************************************************************
4078 Free the memory used for the settings at game start.
4079 **************************************************************************/
4080 static void setting_game_free(struct setting *pset)
4082 if (setting_type(pset) == SSET_STRING) {
4083 FC_FREE(pset->string.game_value);
4087 /**************************************************************************
4088 Restore the setting to the value used at the start of the current game.
4089 **************************************************************************/
4090 static void setting_game_restore(struct setting *pset)
4092 char reject_msg[256] = "", buf[256];
4093 bool res = FALSE;
4095 if (!setting_is_changeable(pset, NULL, reject_msg, sizeof(reject_msg))) {
4096 log_debug("Can't restore '%s': %s", setting_name(pset),
4097 reject_msg);
4098 return;
4101 switch (setting_type(pset)) {
4102 case SSET_BOOL:
4103 res = (NULL != setting_bool_to_str(pset, pset->boolean.game_value,
4104 FALSE, buf, sizeof(buf))
4105 && setting_bool_set(pset, buf, NULL, reject_msg,
4106 sizeof(reject_msg)));
4107 break;
4109 case SSET_INT:
4110 res = setting_int_set(pset, pset->integer.game_value, NULL, reject_msg,
4111 sizeof(reject_msg));
4112 break;
4114 case SSET_STRING:
4115 res = setting_str_set(pset, pset->string.game_value, NULL, reject_msg,
4116 sizeof(reject_msg));
4117 break;
4119 case SSET_ENUM:
4120 res = (NULL != setting_enum_to_str(pset, pset->enumerator.game_value,
4121 FALSE, buf, sizeof(buf))
4122 && setting_enum_set(pset, buf, NULL, reject_msg,
4123 sizeof(reject_msg)));
4124 break;
4126 case SSET_BITWISE:
4127 res = (NULL != setting_bitwise_to_str(pset, pset->bitwise.game_value,
4128 FALSE, buf, sizeof(buf))
4129 && setting_bitwise_set(pset, buf, NULL, reject_msg,
4130 sizeof(reject_msg)));
4131 break;
4134 if (!res) {
4135 log_error("Error restoring setting '%s' to the value from game start: "
4136 "%s", setting_name(pset), reject_msg);
4140 /**************************************************************************
4141 Save setting values at the start of the game.
4142 **************************************************************************/
4143 void settings_game_start(void)
4145 settings_iterate(SSET_ALL, pset) {
4146 setting_game_set(pset, FALSE);
4147 } settings_iterate_end;
4149 /* Settings from the start of the game are saved. */
4150 game.server.settings_gamestart_valid = TRUE;
4153 /********************************************************************
4154 Save game settings.
4155 *********************************************************************/
4156 void settings_game_save(struct section_file *file, const char *section)
4158 int set_count = 0;
4160 settings_iterate(SSET_ALL, pset) {
4161 char errbuf[200];
4163 if (/* It's explicitly set to some value to save */
4164 setting_get_setdef(pset) == SETDEF_CHANGED
4165 /* It must be same at loading time as it was saving time, even if
4166 * freeciv's default has changed. */
4167 || !setting_is_free_to_change(pset, errbuf, sizeof(errbuf))) {
4168 secfile_insert_str(file, setting_name(pset),
4169 "%s.set%d.name", section, set_count);
4170 switch (setting_type(pset)) {
4171 case SSET_BOOL:
4172 secfile_insert_bool(file, *pset->boolean.pvalue,
4173 "%s.set%d.value", section, set_count);
4174 secfile_insert_bool(file, pset->boolean.game_value,
4175 "%s.set%d.gamestart", section, set_count);
4176 break;
4177 case SSET_INT:
4178 secfile_insert_int(file, *pset->integer.pvalue,
4179 "%s.set%d.value", section, set_count);
4180 secfile_insert_int(file, pset->integer.game_value,
4181 "%s.set%d.gamestart", section, set_count);
4182 break;
4183 case SSET_STRING:
4184 secfile_insert_str(file, pset->string.value,
4185 "%s.set%d.value", section, set_count);
4186 secfile_insert_str(file, pset->string.game_value,
4187 "%s.set%d.gamestart", section, set_count);
4188 break;
4189 case SSET_ENUM:
4190 secfile_insert_enum_data(file, read_enum_value(pset), FALSE,
4191 setting_enum_secfile_str, pset,
4192 "%s.set%d.value", section, set_count);
4193 secfile_insert_enum_data(file, pset->enumerator.game_value, FALSE,
4194 setting_enum_secfile_str, pset,
4195 "%s.set%d.gamestart", section, set_count);
4196 break;
4197 case SSET_BITWISE:
4198 secfile_insert_enum_data(file, *pset->bitwise.pvalue, TRUE,
4199 setting_bitwise_secfile_str, pset,
4200 "%s.set%d.value", section, set_count);
4201 secfile_insert_enum_data(file, pset->bitwise.game_value, TRUE,
4202 setting_bitwise_secfile_str, pset,
4203 "%s.set%d.gamestart", section, set_count);
4204 break;
4206 set_count++;
4208 } settings_iterate_end;
4210 secfile_insert_int(file, set_count, "%s.set_count", section);
4211 secfile_insert_bool(file, game.server.settings_gamestart_valid,
4212 "%s.gamestart_valid", section);
4215 /********************************************************************
4216 Restore all settings from a savegame.
4217 *********************************************************************/
4218 void settings_game_load(struct section_file *file, const char *section)
4220 const char *name;
4221 char reject_msg[256], buf[256];
4222 int i, set_count;
4223 int oldcitymindist = game.info.citymindist; /* backwards compat, see below */
4225 /* Compatibility with savegames created with older versions is usually
4226 * handled as conversions in savecompat.c compat_load_<version>() */
4228 if (!secfile_lookup_int(file, &set_count, "%s.set_count", section)) {
4229 /* Old savegames and scenarios doesn't contain this, not an error. */
4230 log_verbose("Can't read the number of settings in the save file.");
4231 return;
4234 /* Check if the saved settings are valid settings from game start. */
4235 game.server.settings_gamestart_valid
4236 = secfile_lookup_bool_default(file, FALSE, "%s.gamestart_valid",
4237 section);
4239 for (i = 0; i < set_count; i++) {
4240 name = secfile_lookup_str(file, "%s.set%d.name", section, i);
4242 settings_iterate(SSET_ALL, pset) {
4243 if (fc_strcasecmp(setting_name(pset), name) != 0) {
4244 continue;
4247 /* Load the current value of the setting. */
4248 switch (pset->stype) {
4249 case SSET_BOOL:
4251 bool val;
4253 if (!secfile_lookup_bool(file, &val, "%s.set%d.value", section,
4254 i)) {
4255 log_verbose("Option '%s' not defined in the savegame: %s", name,
4256 secfile_error());
4257 } else {
4258 pset->setdef = SETDEF_CHANGED;
4260 if (val != *pset->boolean.pvalue) {
4261 if (setting_is_changeable(pset, NULL, reject_msg,
4262 sizeof(reject_msg))
4263 && (NULL == pset->boolean.validate
4264 || pset->boolean.validate(val, NULL, reject_msg,
4265 sizeof(reject_msg)))) {
4266 *pset->boolean.pvalue = val;
4267 log_normal(_("Savegame: '%s' has been set to %s."),
4268 setting_name(pset),
4269 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4270 } else {
4271 log_error("Savegame: error restoring '%s' . (%s)",
4272 setting_name(pset), reject_msg);
4274 } else {
4275 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4276 setting_name(pset));
4280 break;
4282 case SSET_INT:
4284 int val;
4286 if (!secfile_lookup_int(file, &val, "%s.set%d.value", section, i)) {
4287 log_verbose("Option '%s' not defined in the savegame: %s", name,
4288 secfile_error());
4289 } else {
4290 pset->setdef = SETDEF_CHANGED;
4292 if (val != *pset->integer.pvalue) {
4293 if (setting_is_changeable(pset, NULL, reject_msg,
4294 sizeof(reject_msg))
4295 && (NULL == pset->integer.validate
4296 || pset->integer.validate(val, NULL, reject_msg,
4297 sizeof(reject_msg)))) {
4298 *pset->integer.pvalue = val;
4299 log_normal(_("Savegame: '%s' has been set to %s."),
4300 setting_name(pset),
4301 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4302 } else {
4303 log_error("Savegame: error restoring '%s' . (%s)",
4304 setting_name(pset), reject_msg);
4306 } else {
4307 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4308 setting_name(pset));
4312 break;
4314 case SSET_STRING:
4316 const char *val = secfile_lookup_str(file, "%s.set%d.value",
4317 section, i);
4319 if (NULL == val) {
4320 log_verbose("Option '%s' not defined in the savegame: %s", name,
4321 secfile_error());
4322 } else {
4323 pset->setdef = SETDEF_CHANGED;
4325 if (0 != strcmp(val, pset->string.value)) {
4326 if (setting_str_set(pset, val, NULL, reject_msg,
4327 sizeof(reject_msg))) {
4328 log_normal(_("Savegame: '%s' has been set to %s."),
4329 setting_name(pset),
4330 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4331 } else {
4332 log_error("Savegame: error restoring '%s' . (%s)",
4333 setting_name(pset), reject_msg);
4335 } else {
4336 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4337 setting_name(pset));
4341 break;
4343 case SSET_ENUM:
4345 int val;
4347 if (!secfile_lookup_enum_data(file, &val, FALSE,
4348 setting_enum_secfile_str, pset,
4349 "%s.set%d.value", section, i)) {
4350 log_verbose("Option '%s' not defined in the savegame: %s", name,
4351 secfile_error());
4352 } else {
4353 pset->setdef = SETDEF_CHANGED;
4355 if (val != read_enum_value(pset)) {
4356 if (setting_is_changeable(pset, NULL, reject_msg,
4357 sizeof(reject_msg))
4358 && (NULL == pset->enumerator.validate
4359 || pset->enumerator.validate(val, NULL, reject_msg,
4360 sizeof(reject_msg)))) {
4361 set_enum_value(pset, val);
4362 log_normal(_("Savegame: '%s' has been set to %s."),
4363 setting_name(pset),
4364 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4365 } else {
4366 log_error("Savegame: error restoring '%s' . (%s)",
4367 setting_name(pset), reject_msg);
4369 } else {
4370 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4371 setting_name(pset));
4375 break;
4377 case SSET_BITWISE:
4379 int val;
4381 if (!secfile_lookup_enum_data(file, &val, TRUE,
4382 setting_bitwise_secfile_str, pset,
4383 "%s.set%d.value", section, i)) {
4384 log_verbose("Option '%s' not defined in the savegame: %s", name,
4385 secfile_error());
4386 } else {
4387 pset->setdef = SETDEF_CHANGED;
4389 if (val != *pset->bitwise.pvalue) {
4390 if (setting_is_changeable(pset, NULL, reject_msg,
4391 sizeof(reject_msg))
4392 && (NULL == pset->bitwise.validate
4393 || pset->bitwise.validate(val, NULL, reject_msg,
4394 sizeof(reject_msg)))) {
4395 *pset->bitwise.pvalue = val;
4396 log_normal(_("Savegame: '%s' has been set to %s."),
4397 setting_name(pset),
4398 setting_value_name(pset, TRUE, buf, sizeof(buf)));
4399 } else {
4400 log_error("Savegame: error restoring '%s' . (%s)",
4401 setting_name(pset), reject_msg);
4403 } else {
4404 log_normal(_("Savegame: '%s' explicitly set to value same as default."),
4405 setting_name(pset));
4409 break;
4412 if (game.server.settings_gamestart_valid) {
4413 /* Load the value of the setting at the start of the game. */
4414 switch (pset->stype) {
4415 case SSET_BOOL:
4416 pset->boolean.game_value =
4417 secfile_lookup_bool_default(file, *pset->boolean.pvalue,
4418 "%s.set%d.gamestart", section, i);
4419 break;
4421 case SSET_INT:
4422 pset->integer.game_value =
4423 secfile_lookup_int_default(file, *pset->integer.pvalue,
4424 "%s.set%d.gamestart", section, i);
4425 break;
4427 case SSET_STRING:
4428 fc_strlcpy(pset->string.game_value,
4429 secfile_lookup_str_default(file, pset->string.value,
4430 "%s.set%d.gamestart",
4431 section, i),
4432 pset->string.value_size);
4433 break;
4435 case SSET_ENUM:
4436 pset->enumerator.game_value =
4437 secfile_lookup_enum_default_data(file,
4438 read_enum_value(pset), FALSE, setting_enum_secfile_str,
4439 pset, "%s.set%d.gamestart", section, i);
4440 break;
4442 case SSET_BITWISE:
4443 pset->bitwise.game_value =
4444 secfile_lookup_enum_default_data(file,
4445 *pset->bitwise.pvalue, TRUE, setting_bitwise_secfile_str,
4446 pset, "%s.set%d.gamestart", section, i);
4447 break;
4450 pset->setdef = SETDEF_CHANGED;
4452 } settings_iterate_end;
4455 /* Backwards compatibility for pre-2.4 savegames: citymindist=0 used to mean
4456 * take from ruleset min_dist_bw_cities, but that no longer exists.
4457 * This is here rather than in savegame2.c compat functions, as we need
4458 * to have loaded the relevant ruleset to know what to set it to (the
4459 * ruleset and any 'citymindist' setting it contains will have been loaded
4460 * before this function was called). */
4461 if (game.info.citymindist == 0) {
4462 game.info.citymindist = oldcitymindist;
4465 settings_iterate(SSET_ALL, pset) {
4466 /* Have to do this at the end due to dependencies ('aifill' and
4467 * 'maxplayer'). */
4468 setting_action(pset);
4469 } settings_iterate_end;
4472 /**************************************************************************
4473 Reset all settings to the values at game start.
4474 **************************************************************************/
4475 bool settings_game_reset(void)
4477 if (!game.server.settings_gamestart_valid) {
4478 log_debug("No saved settings from the game start available.");
4479 return FALSE;
4482 settings_iterate(SSET_ALL, pset) {
4483 setting_game_restore(pset);
4484 } settings_iterate_end;
4486 return TRUE;
4489 /**************************************************************************
4490 Initialize stuff related to this code module.
4491 **************************************************************************/
4492 void settings_init(bool act)
4494 settings_list_init();
4496 settings_iterate(SSET_ALL, pset) {
4497 setting_lock_set(pset, FALSE);
4498 setting_set_to_default(pset);
4499 setting_game_set(pset, TRUE);
4500 if (act) {
4501 setting_action(pset);
4503 } settings_iterate_end;
4505 settings_list_update();
4508 /********************************************************************
4509 Reset all settings iff they are changeable.
4510 *********************************************************************/
4511 void settings_reset(void)
4513 settings_iterate(SSET_ALL, pset) {
4514 if (setting_is_changeable(pset, NULL, NULL, 0)) {
4515 setting_set_to_default(pset);
4516 setting_action(pset);
4518 } settings_iterate_end;
4521 /**************************************************************************
4522 Update stuff every turn that is related to this code module. Run this
4523 on turn end.
4524 **************************************************************************/
4525 void settings_turn(void)
4527 /* Nothing at the moment. */
4530 /**************************************************************************
4531 Deinitialize stuff related to this code module.
4532 **************************************************************************/
4533 void settings_free(void)
4535 settings_iterate(SSET_ALL, pset) {
4536 setting_game_free(pset);
4537 } settings_iterate_end;
4539 settings_list_free();
4542 /****************************************************************************
4543 Returns the total number of settings.
4544 ****************************************************************************/
4545 int settings_number(void)
4547 return SETTINGS_NUM;
4550 /****************************************************************************
4551 Tell the client about just one server setting. Call this after a setting
4552 is saved.
4553 ****************************************************************************/
4554 void send_server_setting(struct conn_list *dest, const struct setting *pset)
4556 if (!dest) {
4557 dest = game.est_connections;
4560 #define PACKET_COMMON_INIT(packet, pset, pconn) \
4561 memset(&packet, 0, sizeof(packet)); \
4562 packet.id = setting_number(pset); \
4563 packet.is_visible = setting_is_visible(pset, pconn); \
4564 packet.is_changeable = setting_is_changeable(pset, pconn, NULL, 0); \
4565 packet.initial_setting = game.info.is_new_game;
4567 switch (setting_type(pset)) {
4568 case SSET_BOOL:
4570 struct packet_server_setting_bool packet;
4572 conn_list_iterate(dest, pconn) {
4573 PACKET_COMMON_INIT(packet, pset, pconn);
4574 if (packet.is_visible) {
4575 packet.val = *pset->boolean.pvalue;
4576 packet.default_val = pset->boolean.default_value;
4578 send_packet_server_setting_bool(pconn, &packet);
4579 } conn_list_iterate_end;
4581 break;
4582 case SSET_INT:
4584 struct packet_server_setting_int packet;
4586 conn_list_iterate(dest, pconn) {
4587 PACKET_COMMON_INIT(packet, pset, pconn);
4588 if (packet.is_visible) {
4589 packet.val = *pset->integer.pvalue;
4590 packet.default_val = pset->integer.default_value;
4591 packet.min_val = pset->integer.min_value;
4592 packet.max_val = pset->integer.max_value;
4594 send_packet_server_setting_int(pconn, &packet);
4595 } conn_list_iterate_end;
4597 break;
4598 case SSET_STRING:
4600 struct packet_server_setting_str packet;
4602 conn_list_iterate(dest, pconn) {
4603 PACKET_COMMON_INIT(packet, pset, pconn);
4604 if (packet.is_visible) {
4605 sz_strlcpy(packet.val, pset->string.value);
4606 sz_strlcpy(packet.default_val, pset->string.default_value);
4608 send_packet_server_setting_str(pconn, &packet);
4609 } conn_list_iterate_end;
4611 break;
4612 case SSET_ENUM:
4614 struct packet_server_setting_enum packet;
4615 const struct sset_val_name *val_name;
4616 int i;
4618 conn_list_iterate(dest, pconn) {
4619 PACKET_COMMON_INIT(packet, pset, pconn);
4620 if (packet.is_visible) {
4621 packet.val = read_enum_value(pset);
4622 packet.default_val = pset->enumerator.default_value;
4623 for (i = 0; (val_name = pset->enumerator.name(i)); i++) {
4624 sz_strlcpy(packet.support_names[i], val_name->support);
4625 /* Send untranslated string */
4626 sz_strlcpy(packet.pretty_names[i], val_name->pretty);
4628 packet.values_num = i;
4629 fc_assert(i <= ARRAY_SIZE(packet.support_names));
4630 fc_assert(i <= ARRAY_SIZE(packet.pretty_names));
4632 send_packet_server_setting_enum(pconn, &packet);
4633 } conn_list_iterate_end;
4635 break;
4636 case SSET_BITWISE:
4638 struct packet_server_setting_bitwise packet;
4639 const struct sset_val_name *val_name;
4640 int i;
4642 conn_list_iterate(dest, pconn) {
4643 PACKET_COMMON_INIT(packet, pset, pconn);
4644 if (packet.is_visible) {
4645 packet.val = *pset->bitwise.pvalue;
4646 packet.default_val = pset->bitwise.default_value;
4647 for (i = 0; (val_name = pset->bitwise.name(i)); i++) {
4648 sz_strlcpy(packet.support_names[i], val_name->support);
4649 /* Send untranslated string */
4650 sz_strlcpy(packet.pretty_names[i], val_name->pretty);
4652 packet.bits_num = i;
4653 fc_assert(i <= ARRAY_SIZE(packet.support_names));
4654 fc_assert(i <= ARRAY_SIZE(packet.pretty_names));
4656 send_packet_server_setting_bitwise(pconn, &packet);
4657 } conn_list_iterate_end;
4659 break;
4662 #undef PACKET_INIT
4665 /****************************************************************************
4666 Tell the client about all server settings.
4667 ****************************************************************************/
4668 void send_server_settings(struct conn_list *dest)
4670 settings_iterate(SSET_ALL, pset) {
4671 send_server_setting(dest, pset);
4672 } settings_iterate_end;
4675 /****************************************************************************
4676 Send the ALLOW_HACK server settings. Usually called when the access level
4677 of the user changes.
4678 ****************************************************************************/
4679 void send_server_hack_level_settings(struct conn_list *dest)
4681 settings_iterate(SSET_ALL, pset) {
4682 if (!pset->to_client) {
4683 send_server_setting(dest, pset);
4685 } settings_iterate_end;
4688 /****************************************************************************
4689 Tell the client about all server settings.
4690 ****************************************************************************/
4691 void send_server_setting_control(struct connection *pconn)
4693 struct packet_server_setting_control control;
4694 struct packet_server_setting_const setting;
4695 int i;
4697 control.settings_num = SETTINGS_NUM;
4699 /* Fill in the category strings. */
4700 fc_assert(SSET_NUM_CATEGORIES <= ARRAY_SIZE(control.category_names));
4701 control.categories_num = SSET_NUM_CATEGORIES;
4702 for (i = 0; i < SSET_NUM_CATEGORIES; i++) {
4703 /* Send untranslated name */
4704 sz_strlcpy(control.category_names[i], sset_category_name(i));
4707 /* Send off the control packet. */
4708 send_packet_server_setting_control(pconn, &control);
4710 /* Send the constant and common part of the settings. */
4711 settings_iterate(SSET_ALL, pset) {
4712 setting.id = setting_number(pset);
4713 sz_strlcpy(setting.name, setting_name(pset));
4714 /* Send untranslated strings to client */
4715 sz_strlcpy(setting.short_help, setting_short_help(pset));
4716 sz_strlcpy(setting.extra_help, setting_extra_help(pset, TRUE));
4717 setting.category = pset->scategory;
4719 send_packet_server_setting_const(pconn, &setting);
4720 } settings_iterate_end;
4723 /*****************************************************************************
4724 Initialise sorted settings.
4725 *****************************************************************************/
4726 static void settings_list_init(void)
4728 struct setting *pset;
4729 int i;
4731 fc_assert_ret(setting_sorted.init == FALSE);
4733 /* Do it for all values of enum sset_level. */
4734 for (i = 0; i < OLEVELS_NUM; i++) {
4735 setting_sorted.level[i] = setting_list_new();
4738 for (i = 0; (pset = setting_by_number(i)); i++) {
4739 /* Add the setting to the list of all settings. */
4740 setting_list_append(setting_sorted.level[SSET_ALL], pset);
4742 switch (setting_level(pset)) {
4743 case SSET_NONE:
4744 /* No setting should be in this level. */
4745 fc_assert_msg(setting_level(pset) != SSET_NONE,
4746 "No setting level defined for '%s'.", setting_name(pset));
4747 break;
4748 case SSET_ALL:
4749 /* Done above - list of all settings. */
4750 break;
4751 case SSET_VITAL:
4752 setting_list_append(setting_sorted.level[SSET_VITAL], pset);
4753 break;
4754 case SSET_SITUATIONAL:
4755 setting_list_append(setting_sorted.level[SSET_SITUATIONAL], pset);
4756 break;
4757 case SSET_RARE:
4758 setting_list_append(setting_sorted.level[SSET_RARE], pset);
4759 break;
4760 case SSET_CHANGED:
4761 case SSET_LOCKED:
4762 /* This is done in settings_list_update. */
4763 break;
4764 case OLEVELS_NUM:
4765 /* No setting should be in this level. */
4766 fc_assert_msg(setting_level(pset) != OLEVELS_NUM,
4767 "Invalid setting level for '%s' (%s).",
4768 setting_name(pset), sset_level_name(setting_level(pset)));
4769 break;
4773 /* Sort the lists. */
4774 for (i = 0; i < OLEVELS_NUM; i++) {
4775 setting_list_sort(setting_sorted.level[i], settings_list_cmp);
4778 setting_sorted.init = TRUE;
4781 /*****************************************************************************
4782 Update sorted settings (changed and locked values).
4783 *****************************************************************************/
4784 void settings_list_update(void)
4786 struct setting *pset;
4787 int i;
4789 fc_assert_ret(setting_sorted.init == TRUE);
4791 /* Clear the lists for changed and locked values. */
4792 setting_list_clear(setting_sorted.level[SSET_CHANGED]);
4793 setting_list_clear(setting_sorted.level[SSET_LOCKED]);
4795 /* Refill them. */
4796 for (i = 0; (pset = setting_by_number(i)); i++) {
4797 if (setting_non_default(pset)) {
4798 setting_list_append(setting_sorted.level[SSET_CHANGED], pset);
4800 if (setting_locked(pset)) {
4801 setting_list_append(setting_sorted.level[SSET_LOCKED], pset);
4805 /* Sort them. */
4806 setting_list_sort(setting_sorted.level[SSET_CHANGED], settings_list_cmp);
4807 setting_list_sort(setting_sorted.level[SSET_LOCKED], settings_list_cmp);
4810 /*****************************************************************************
4811 Update sorted settings (changed and locked values).
4812 *****************************************************************************/
4813 int settings_list_cmp(const struct setting *const *ppset1,
4814 const struct setting *const *ppset2)
4816 const struct setting *pset1 = *ppset1;
4817 const struct setting *pset2 = *ppset2;
4819 return fc_strcasecmp(setting_name(pset1), setting_name(pset2));
4822 /*****************************************************************************
4823 Get a settings list of a certain level. Call settings_list_update() before
4824 if something was changed.
4825 *****************************************************************************/
4826 struct setting_list *settings_list_get(enum sset_level level)
4828 fc_assert_ret_val(setting_sorted.init == TRUE, NULL);
4829 fc_assert_ret_val(setting_sorted.level[level] != NULL, NULL);
4830 fc_assert_ret_val(sset_level_is_valid(level), NULL);
4832 return setting_sorted.level[level];
4835 /*****************************************************************************
4836 Free sorted settings.
4837 *****************************************************************************/
4838 static void settings_list_free(void)
4840 int i;
4842 fc_assert_ret(setting_sorted.init == TRUE);
4844 /* Free the lists. */
4845 for (i = 0; i < OLEVELS_NUM; i++) {
4846 setting_list_destroy(setting_sorted.level[i]);
4849 setting_sorted.init = FALSE;
4852 /*****************************************************************************
4853 Mark setting changed
4854 *****************************************************************************/
4855 void setting_changed(struct setting *pset)
4857 pset->setdef = SETDEF_CHANGED;
4860 /*****************************************************************************
4861 Is the setting in changed state, or the default
4862 *****************************************************************************/
4863 enum setting_default_level setting_get_setdef(struct setting *pset)
4865 return pset->setdef;
4868 /*****************************************************************************
4869 Compatibility function. In the very old times there was no concept of
4870 'default' value outside setting initialization, all values were handled
4871 like we now want to handle non-default ones.
4872 *****************************************************************************/
4873 void settings_consider_all_changed(void)
4875 settings_iterate(SSET_ALL, pset) {
4876 pset->setdef = SETDEF_CHANGED;
4877 } settings_iterate_end;