tron@2186: /* $Id$ */ tron@2186: belugas@6916: /** @file settings.cpp Darkvater@3615: * All actions handling saving and loading of the settings/configuration goes on in this file. Darkvater@3615: * The file consists of four parts: Darkvater@3615: *
    Darkvater@3615: *
  1. Parsing the configuration file (openttd.cfg). This is achieved with the ini_ functions which Darkvater@3615: * handle various types, such as normal 'key = value' pairs, lists and value combinations of Darkvater@3615: * lists, strings, integers, 'bit'-masks and element selections. Darkvater@3615: *
  2. Defining the data structures that go into the configuration. These include for example Darkvater@3615: * the _patches struct, but also network-settings, banlists, newgrf, etc. There are a lot Darkvater@3615: * of helper macros available for the various types, and also saving/loading of these settings Darkvater@3615: * in a savegame is handled inside these structures. Darkvater@3615: *
  3. Handle reading and writing to the setting-structures from inside the game either from Darkvater@3615: * the console for example or through the gui with CMD_ functions. Darkvater@3615: *
  4. Handle saving/loading of the PATS chunk inside the savegame. Darkvater@3615: *
Darkvater@3615: * @see SettingDesc Darkvater@3615: * @see SaveLoad Darkvater@3615: */ Darkvater@3615: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@2291: #include "currency.h" tron@2121: #include "screenshot.h" tron@2153: #include "variables.h" rubidium@5720: #include "network/network.h" rubidium@10792: #include "network/network_func.h" rubidium@8704: #include "settings_internal.h" rubidium@8612: #include "command_func.h" rubidium@10684: #include "console_func.h" Darkvater@3112: #include "saveload.h" celestar@3358: #include "npf.h" KUDr@3900: #include "yapf/yapf.h" Darkvater@3628: #include "newgrf.h" peter1138@5228: #include "newgrf_config.h" truelight@4300: #include "genworld.h" KUDr@5116: #include "rail.h" rubidium@8249: #include "train.h" rubidium@9259: #include "news_func.h" rubidium@8603: #include "window_func.h" rubidium@8610: #include "strings_func.h" rubidium@8640: #include "vehicle_func.h" rubidium@8653: #include "sound_func.h" rubidium@8709: #include "core/alloc_func.hpp" rubidium@8750: #include "player_func.h" smatz@10402: #include "rev.h" peter1138@5108: #ifdef WITH_FREETYPE peter1138@5108: #include "fontcache.h" peter1138@5108: #endif peter1138@7299: #include "spritecache.h" belugas@8345: #include "transparency.h" rubidium@9233: #include "textbuf_gui.h" rubidium@8710: #include "string_func.h" smatz@9305: #include "rail_gui.h" smatz@10473: #include "elrail_func.h" rubidium@8760: #include "gui.h" rubidium@8760: #include "town.h" rubidium@8771: #include "video/video_driver.hpp" rubidium@8771: #include "sound/sound_driver.hpp" rubidium@8771: #include "music/music_driver.hpp" rubidium@8771: #include "blitter/factory.hpp" smatz@10824: #include "gamelog.h" rubidium@10708: #include "station_func.h" rubidium@8760: rubidium@8760: #include "table/strings.h" truelight@0: rubidium@10775: ClientSettings _settings_client; rubidium@10775: GameSettings _settings_game; rubidium@10775: GameSettings _settings_newgame; Darkvater@3121: rubidium@6574: struct IniFile; rubidium@6574: struct IniItem; rubidium@6574: struct IniGroup; rubidium@6574: struct SettingsMemoryPool; truelight@0: Darkvater@3628: typedef const char *SettingListCallbackProc(const IniItem *item, uint index); Darkvater@3628: typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object); Darkvater@3628: typedef void SettingDescProcList(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc); Darkvater@3628: truelight@1258: static void pool_init(SettingsMemoryPool **pool); glx@10465: static void *pool_alloc(SettingsMemoryPool **pool, size_t size); glx@10465: static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, size_t size); truelight@1258: static void pool_free(SettingsMemoryPool **pool); KUDr@3900: static bool IsSignedVarMemType(VarType vt); truelight@0: truelight@1258: struct SettingsMemoryPool { glx@10465: size_t pos, size; truelight@1258: SettingsMemoryPool *next; truelight@0: byte mem[1]; truelight@0: }; truelight@0: glx@10465: static SettingsMemoryPool *pool_new(size_t minsize) truelight@0: { truelight@1258: SettingsMemoryPool *p; truelight@0: if (minsize < 4096 - 12) minsize = 4096 - 12; truelight@193: rubidium@8533: p = (SettingsMemoryPool*)MallocT(sizeof(SettingsMemoryPool) - 1 + minsize); truelight@0: p->pos = 0; truelight@0: p->size = minsize; truelight@0: p->next = NULL; truelight@0: return p; truelight@0: } truelight@0: truelight@1258: static void pool_init(SettingsMemoryPool **pool) truelight@0: { truelight@0: *pool = pool_new(0); truelight@0: } truelight@0: glx@10465: static void *pool_alloc(SettingsMemoryPool **pool, size_t size) truelight@0: { glx@10465: size_t pos; truelight@1258: SettingsMemoryPool *p = *pool; truelight@0: skidd13@8423: size = Align(size, sizeof(void*)); truelight@0: belugas@6916: /* first check if there's memory in the next pool */ truelight@0: if (p->next && p->next->pos + size <= p->next->size) { truelight@0: p = p->next; belugas@6916: /* then check if there's not memory in the cur pool */ truelight@0: } else if (p->pos + size > p->size) { truelight@1258: SettingsMemoryPool *n = pool_new(size); truelight@0: *pool = n; truelight@0: n->next = p; truelight@193: p = n; truelight@0: } truelight@0: truelight@0: pos = p->pos; truelight@0: p->pos += size; truelight@0: return p->mem + pos; truelight@0: } truelight@0: glx@10465: static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, size_t size) truelight@0: { rubidium@5838: byte *p = (byte*)pool_alloc(pool, size + 1); truelight@0: p[size] = 0; truelight@0: memcpy(p, mem, size); truelight@0: return p; truelight@0: } truelight@0: truelight@1258: static void pool_free(SettingsMemoryPool **pool) truelight@0: { truelight@1258: SettingsMemoryPool *p = *pool, *n; truelight@0: *pool = NULL; truelight@0: while (p) { truelight@0: n = p->next; truelight@0: free(p); truelight@0: p = n; truelight@0: } truelight@0: } truelight@0: belugas@6916: /** structs describing the ini format. */ truelight@0: struct IniItem { truelight@0: char *name; truelight@0: char *value; truelight@0: char *comment; truelight@0: IniItem *next; truelight@0: }; truelight@0: truelight@0: struct IniGroup { belugas@6916: char *name; ///< name of group belugas@6916: char *comment; ///pool = pool; truelight@0: ini->group = NULL; truelight@0: ini->last_group = &ini->group; truelight@0: ini->comment = NULL; truelight@0: return ini; truelight@0: } truelight@0: belugas@6916: /** allocate an ini group object */ glx@10465: static IniGroup *ini_group_alloc(IniFile *ini, const char *grpt, size_t len) truelight@0: { rubidium@5838: IniGroup *grp = (IniGroup*)pool_alloc(&ini->pool, sizeof(IniGroup)); truelight@0: grp->ini = ini; rubidium@5838: grp->name = (char*)pool_strdup(&ini->pool, grpt, len); peter1138@2953: if (!strcmp(grp->name, "newgrf") || !strcmp(grp->name, "servers") || !strcmp(grp->name, "bans")) { dominik@705: grp->type = IGT_LIST; peter1138@2953: } else { dominik@705: grp->type = IGT_VARIABLES; peter1138@2953: } truelight@0: grp->next = NULL; truelight@0: grp->item = NULL; truelight@0: grp->comment = NULL; truelight@0: grp->last_item = &grp->item; truelight@0: *ini->last_group = grp; truelight@0: ini->last_group = &grp->next; truelight@0: return grp; truelight@0: } truelight@0: glx@10465: static IniItem *ini_item_alloc(IniGroup *group, const char *name, size_t len) truelight@0: { rubidium@5838: IniItem *item = (IniItem*)pool_alloc(&group->ini->pool, sizeof(IniItem)); rubidium@5838: item->name = (char*)pool_strdup(&group->ini->pool, name, len); truelight@0: item->next = NULL; truelight@0: item->comment = NULL; truelight@0: item->value = NULL; truelight@0: *group->last_item = item; truelight@0: group->last_item = &item->next; truelight@0: return item; truelight@0: } truelight@0: belugas@6916: /** load an ini file into the "abstract" format */ truelight@0: static IniFile *ini_load(const char *filename) truelight@0: { truelight@0: char buffer[1024], c, *s, *t, *e; truelight@0: FILE *in; truelight@0: IniFile *ini; truelight@0: IniGroup *group = NULL; truelight@0: IniItem *item; truelight@0: tron@1329: char *comment = NULL; truelight@0: uint comment_size = 0; truelight@0: uint comment_alloc = 0; truelight@0: truelight@0: ini = ini_alloc(); truelight@0: truelight@0: in = fopen(filename, "r"); truelight@0: if (in == NULL) return ini; truelight@0: belugas@6916: /* for each line in the file */ truelight@0: while (fgets(buffer, sizeof(buffer), in)) { truelight@193: belugas@6916: /* trim whitespace from the left side */ smatz@9191: for (s = buffer; *s == ' ' || *s == '\t'; s++) {} truelight@0: belugas@6916: /* trim whitespace from right side. */ truelight@0: e = s + strlen(s); rubidium@10229: while (e > s && ((c = e[-1]) == '\n' || c == '\r' || c == ' ' || c == '\t')) e--; Darkvater@3598: *e = '\0'; truelight@0: belugas@6916: /* skip comments and empty lines */ peter1138@4969: if (*s == '#' || *s == ';' || *s == '\0') { truelight@0: uint ns = comment_size + (e - s + 1); truelight@0: uint a = comment_alloc; truelight@0: uint pos; belugas@6916: /* add to comment */ truelight@0: if (ns > a) { celestar@5852: a = max(a, 128U); rubidium@10229: do a *= 2; while (a < ns); KUDr@5860: comment = ReallocT(comment, comment_alloc = a); truelight@0: } truelight@0: pos = comment_size; truelight@0: comment_size += (e - s + 1); truelight@0: comment[pos + e - s] = '\n'; // comment newline truelight@0: memcpy(comment + pos, s, e - s); // copy comment contents truelight@0: continue; truelight@0: } truelight@0: belugas@6916: /* it's a group? */ truelight@0: if (s[0] == '[') { tron@4077: if (e[-1] != ']') { Darkvater@5827: ShowInfoF("ini: invalid group name '%s'", buffer); tron@4077: } else { truelight@0: e--; tron@4077: } truelight@0: s++; // skip [ truelight@0: group = ini_group_alloc(ini, s, e - s); truelight@0: if (comment_size) { rubidium@5838: group->comment = (char*)pool_strdup(&ini->pool, comment, comment_size); truelight@0: comment_size = 0; truelight@0: } truelight@0: } else if (group) { belugas@6916: /* find end of keyname */ glx@6933: if (*s == '\"') { glx@6933: s++; smatz@9191: for (t = s; *t != '\0' && *t != '\"'; t++) {} glx@6933: if (*t == '\"') *t = ' '; glx@6933: } else { smatz@9191: for (t = s; *t != '\0' && *t != '=' && *t != '\t' && *t != ' '; t++) {} glx@6933: } truelight@193: belugas@6916: /* it's an item in an existing group */ truelight@0: item = ini_item_alloc(group, s, t-s); truelight@0: if (comment_size) { rubidium@5838: item->comment = (char*)pool_strdup(&ini->pool, comment, comment_size); truelight@0: comment_size = 0; truelight@0: } truelight@0: belugas@6916: /* find start of parameter */ truelight@0: while (*t == '=' || *t == ' ' || *t == '\t') t++; dominik@759: dominik@759: belugas@6916: /* remove starting quotation marks */ tron@2952: if (*t == '\"') t++; belugas@6916: /* remove ending quotation marks */ dominik@759: e = t + strlen(t); Darkvater@3598: if (e > t && e[-1] == '\"') e--; Darkvater@3598: *e = '\0'; dominik@759: rubidium@5838: item->value = (char*)pool_strdup(&ini->pool, t, e - t); truelight@0: } else { belugas@6916: /* it's an orphan item */ Darkvater@5827: ShowInfoF("ini: '%s' outside of group", buffer); truelight@0: } truelight@0: } truelight@0: Darkvater@3615: if (comment_size > 0) { rubidium@5838: ini->comment = (char*)pool_strdup(&ini->pool, comment, comment_size); truelight@0: comment_size = 0; truelight@0: } truelight@0: truelight@0: free(comment); truelight@0: fclose(in); truelight@0: truelight@0: return ini; truelight@0: } truelight@0: belugas@6916: /** lookup a group or make a new one */ glx@10471: static IniGroup *ini_getgroup(IniFile *ini, const char *name, size_t len = 0) truelight@0: { truelight@0: IniGroup *group; truelight@0: glx@10471: if (len == 0) len = strlen(name); truelight@0: belugas@6916: /* does it exist already? */ rubidium@10699: for (group = ini->group; group != NULL; group = group->next) { rubidium@10699: if (!memcmp(group->name, name, len) && group->name[len] == 0) { truelight@0: return group; rubidium@10699: } rubidium@10699: } truelight@0: belugas@6916: /* otherwise make a new one */ truelight@0: group = ini_group_alloc(ini, name, len); rubidium@5838: group->comment = (char*)pool_strdup(&ini->pool, "\n", 1); truelight@0: return group; truelight@0: } truelight@0: rubidium@10703: static void ini_removegroup(IniFile *ini, const char *name) rubidium@10703: { rubidium@10703: size_t len = strlen(name); rubidium@10703: IniGroup *prev = NULL; rubidium@10703: IniGroup *group; rubidium@10703: rubidium@10703: /* does it exist already? */ rubidium@10703: for (group = ini->group; group != NULL; prev = group, group = group->next) { rubidium@10703: if (memcmp(group->name, name, len) == 0) { rubidium@10703: break; rubidium@10703: } rubidium@10703: } rubidium@10703: rubidium@10703: if (group == NULL) return; rubidium@10703: rubidium@10703: if (prev != NULL) { rubidium@10703: prev->next = prev->next->next; rubidium@10703: } else { rubidium@10703: ini->group = ini->group->next; rubidium@10703: } rubidium@10703: } rubidium@10703: belugas@6916: /** lookup an item or make a new one */ truelight@0: static IniItem *ini_getitem(IniGroup *group, const char *name, bool create) truelight@0: { truelight@0: IniItem *item; glx@10465: size_t len = strlen(name); truelight@0: rubidium@10699: for (item = group->item; item != NULL; item = item->next) { Darkvater@2972: if (strcmp(item->name, name) == 0) return item; rubidium@10699: } truelight@193: truelight@0: if (!create) return NULL; truelight@0: belugas@6916: /* otherwise make a new one */ Darkvater@2972: return ini_item_alloc(group, name, len); truelight@0: } truelight@0: belugas@6916: /** save ini file from the "abstract" format. */ truelight@0: static bool ini_save(const char *filename, IniFile *ini) truelight@0: { truelight@0: FILE *f; truelight@0: IniGroup *group; truelight@0: IniItem *item; truelight@193: truelight@0: f = fopen(filename, "w"); truelight@0: if (f == NULL) return false; truelight@0: Darkvater@2919: for (group = ini->group; group != NULL; group = group->next) { truelight@0: if (group->comment) fputs(group->comment, f); truelight@0: fprintf(f, "[%s]\n", group->name); Darkvater@2919: for (item = group->item; item != NULL; item = item->next) { Darkvater@3600: assert(item->value != NULL); Darkvater@3600: if (item->comment != NULL) fputs(item->comment, f); Darkvater@3600: glx@6933: /* protect item->name with quotes if needed */ glx@6933: if (strchr(item->name, ' ') != NULL) { glx@6933: fprintf(f, "\"%s\"", item->name); glx@6933: } else { glx@6933: fprintf(f, "%s", item->name); glx@6933: } glx@6933: rubidium@4434: /* Don't give an equal sign to list items that don't have a parameter */ Darkvater@3600: if (group->type == IGT_LIST && *item->value == '\0') { glx@6933: fprintf(f, "\n"); tron@4077: } else { glx@6933: fprintf(f, " = %s\n", item->value); tron@4077: } truelight@0: } truelight@0: } truelight@0: if (ini->comment) fputs(ini->comment, f); truelight@0: truelight@0: fclose(f); truelight@0: return true; truelight@0: } truelight@0: truelight@0: static void ini_free(IniFile *ini) truelight@0: { truelight@0: pool_free(&ini->pool); truelight@0: } truelight@0: Darkvater@3615: /** Find the index value of a ONEofMANY type in a string seperated by | Darkvater@2972: * @param many full domain of values the ONEofMANY setting can have Darkvater@2972: * @param one the current value of the setting for which a value needs found Darkvater@2972: * @param onelen force calculation of the *one parameter Darkvater@2972: * @return the integer index of the full-list, or -1 if not found */ glx@10471: static int lookup_oneofmany(const char *many, const char *one, size_t onelen = 0) truelight@0: { truelight@0: const char *s; truelight@0: int idx; truelight@0: glx@10471: if (onelen == 0) onelen = strlen(one); truelight@0: belugas@6916: /* check if it's an integer */ truelight@0: if (*one >= '0' && *one <= '9') truelight@0: return strtoul(one, NULL, 0); truelight@193: truelight@0: idx = 0; tron@2952: for (;;) { belugas@6916: /* find end of item */ truelight@0: s = many; truelight@0: while (*s != '|' && *s != 0) s++; glx@10471: if ((size_t)(s - many) == onelen && !memcmp(one, many, onelen)) return idx; truelight@0: if (*s == 0) return -1; truelight@0: many = s + 1; truelight@0: idx++; truelight@0: } truelight@0: } truelight@0: Darkvater@3615: /** Find the set-integer value MANYofMANY type in a string Darkvater@2972: * @param many full domain of values the MANYofMANY setting can have Darkvater@2972: * @param str the current string value of the setting, each individual belugas@6979: * of seperated by a whitespace,tab or | character Darkvater@2972: * @return the 'fully' set integer, or -1 if a set is not found */ truelight@0: static uint32 lookup_manyofmany(const char *many, const char *str) truelight@0: { truelight@0: const char *s; truelight@0: int r; truelight@0: uint32 res = 0; truelight@0: tron@2952: for (;;) { belugas@6916: /* skip "whitespace" */ truelight@0: while (*str == ' ' || *str == '\t' || *str == '|') str++; truelight@0: if (*str == 0) break; truelight@0: truelight@0: s = str; truelight@0: while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++; truelight@0: truelight@0: r = lookup_oneofmany(many, str, s - str); truelight@0: if (r == -1) return (uint32)-1; truelight@0: skidd13@8427: SetBit(res, r); // value found, set it truelight@0: if (*s == 0) break; truelight@0: str = s + 1; truelight@0: } truelight@0: return res; truelight@0: } truelight@0: Darkvater@2972: /** Parse an integerlist string and set each found value Darkvater@3615: * @param p the string to be parsed. Each element in the list is seperated by a Darkvater@3615: * comma or a space character Darkvater@2972: * @param items pointer to the integerlist-array that will be filled with values Darkvater@2972: * @param maxitems the maximum number of elements the integerlist-array has Darkvater@2972: * @return returns the number of items found, or -1 on an error */ truelight@0: static int parse_intlist(const char *p, int *items, int maxitems) truelight@0: { truelight@0: int n = 0, v; truelight@0: char *end; truelight@0: tron@2952: for (;;) { truelight@0: v = strtol(p, &end, 0); truelight@0: if (p == end || n == maxitems) return -1; truelight@0: p = end; truelight@0: items[n++] = v; Darkvater@3598: if (*p == '\0') break; Darkvater@3599: if (*p != ',' && *p != ' ') return -1; truelight@0: p++; truelight@0: } truelight@0: truelight@0: return n; truelight@0: } truelight@0: Darkvater@3615: /** Load parsed string-values into an integer-array (intlist) Darkvater@2972: * @param str the string that contains the values (and will be parsed) Darkvater@2972: * @param array pointer to the integer-arrays that will be filled Darkvater@2972: * @param nelems the number of elements the array holds. Maximum is 64 elements Darkvater@2972: * @param type the type of elements the array holds (eg INT8, UINT16, etc.) Darkvater@2972: * @return return true on success and false on error */ Darkvater@3115: static bool load_intlist(const char *str, void *array, int nelems, VarType type) truelight@0: { truelight@0: int items[64]; Darkvater@2972: int i, nitems; truelight@193: truelight@0: if (str == NULL) { truelight@0: memset(items, 0, sizeof(items)); truelight@0: nitems = nelems; truelight@0: } else { truelight@0: nitems = parse_intlist(str, items, lengthof(items)); Darkvater@2972: if (nitems != nelems) return false; truelight@0: } truelight@0: tron@2952: switch (type) { Darkvater@3115: case SLE_VAR_BL: Darkvater@3115: case SLE_VAR_I8: Darkvater@3115: case SLE_VAR_U8: tron@2952: for (i = 0; i != nitems; i++) ((byte*)array)[i] = items[i]; truelight@0: break; Darkvater@3115: case SLE_VAR_I16: Darkvater@3115: case SLE_VAR_U16: tron@2952: for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i]; truelight@0: break; Darkvater@3115: case SLE_VAR_I32: Darkvater@3115: case SLE_VAR_U32: tron@2952: for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i]; truelight@0: break; Darkvater@2972: default: NOT_REACHED(); truelight@0: } truelight@0: truelight@0: return true; truelight@0: } truelight@0: Darkvater@3615: /** Convert an integer-array (intlist) to a string representation. Each value Darkvater@3615: * is seperated by a comma or a space character Darkvater@2972: * @param buf output buffer where the string-representation will be stored Darkvater@2972: * @param array pointer to the integer-arrays that is read from Darkvater@2972: * @param nelems the number of elements the array holds. Darkvater@2972: * @param type the type of elements the array holds (eg INT8, UINT16, etc.) */ Darkvater@3115: static void make_intlist(char *buf, const void *array, int nelems, VarType type) truelight@0: { truelight@0: int i, v = 0; Darkvater@2972: const byte *p = (const byte*)array; tron@2952: tron@2952: for (i = 0; i != nelems; i++) { tron@2952: switch (type) { Darkvater@3115: case SLE_VAR_BL: Darkvater@3115: case SLE_VAR_I8: v = *(int8*)p; p += 1; break; Darkvater@3115: case SLE_VAR_U8: v = *(byte*)p; p += 1; break; Darkvater@3115: case SLE_VAR_I16: v = *(int16*)p; p += 2; break; Darkvater@3115: case SLE_VAR_U16: v = *(uint16*)p; p += 2; break; Darkvater@3115: case SLE_VAR_I32: v = *(int32*)p; p += 4; break; Darkvater@3115: case SLE_VAR_U32: v = *(uint32*)p; p += 4; break; truelight@0: default: NOT_REACHED(); truelight@0: } Darkvater@2972: buf += sprintf(buf, (i == 0) ? "%d" : ",%d", v); truelight@0: } truelight@0: } truelight@0: Darkvater@3615: /** Convert a ONEofMANY structure to a string representation. Darkvater@2972: * @param buf output buffer where the string-representation will be stored Darkvater@2972: * @param many the full-domain string of possible values Darkvater@2972: * @param id the value of the variable and whose string-representation must be found */ Darkvater@2973: static void make_oneofmany(char *buf, const char *many, int id) truelight@0: { Darkvater@2973: int orig_id = id; truelight@0: belugas@6916: /* Look for the id'th element */ Darkvater@2973: while (--id >= 0) { Darkvater@2973: for (; *many != '|'; many++) { Darkvater@2973: if (*many == '\0') { // not found Darkvater@2973: sprintf(buf, "%d", orig_id); truelight@0: return; truelight@0: } Darkvater@2973: } Darkvater@2973: many++; // pass the |-character truelight@0: } truelight@0: belugas@6916: /* copy string until next item (|) or the end of the list if this is the last one */ Darkvater@2973: while (*many != '\0' && *many != '|') *buf++ = *many++; Darkvater@2973: *buf = '\0'; truelight@0: } truelight@0: Darkvater@3615: /** Convert a MANYofMANY structure to a string representation. Darkvater@2972: * @param buf output buffer where the string-representation will be stored Darkvater@2972: * @param many the full-domain string of possible values Darkvater@2972: * @param x the value of the variable and whose string-representation must Darkvater@2972: * be found in the bitmasked many string */ truelight@0: static void make_manyofmany(char *buf, const char *many, uint32 x) truelight@0: { truelight@0: const char *start; truelight@0: int i = 0; truelight@0: bool init = true; truelight@0: Darkvater@2973: for (; x != 0; x >>= 1, i++) { truelight@0: start = many; Darkvater@2973: while (*many != 0 && *many != '|') many++; // advance to the next element Darkvater@2973: skidd13@8424: if (HasBit(x, 0)) { // item found, copy it truelight@0: if (!init) *buf++ = '|'; truelight@0: init = false; truelight@0: if (start == many) { truelight@0: buf += sprintf(buf, "%d", i); truelight@0: } else { truelight@0: memcpy(buf, start, many - start); truelight@0: buf += many - start; truelight@0: } truelight@0: } Darkvater@2973: truelight@0: if (*many == '|') many++; Darkvater@2973: } Darkvater@2973: Darkvater@2973: *buf = '\0'; truelight@0: } truelight@0: Darkvater@2972: /** Convert a string representation (external) of a setting to the internal rep. Darkvater@2972: * @param desc SettingDesc struct that holds all information about the variable Darkvater@2972: * @param str input string that will be parsed based on the type of desc Darkvater@2972: * @return return the parsed value of the setting */ Darkvater@3115: static const void *string_to_val(const SettingDescBase *desc, const char *str) truelight@0: { Darkvater@3115: switch (desc->cmd) { Darkvater@2972: case SDT_NUMX: { Darkvater@2972: char *end; truelight@2991: unsigned long val = strtoul(str, &end, 0); Darkvater@2972: if (*end != '\0') ShowInfoF("ini: trailing characters at end of setting '%s'", desc->name); truelight@0: return (void*)val; Darkvater@2972: } truelight@0: case SDT_ONEOFMANY: { glx@10471: long r = lookup_oneofmany(desc->many, str); belugas@6682: /* if the first attempt of conversion from string to the appropriate value fails, belugas@6682: * look if we have defined a converter from old value to new value. */ belugas@6682: if (r == -1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str); belugas@6682: if (r != -1) return (void*)r; //and here goes converted value belugas@6682: ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name); //sorry, we failed truelight@0: return 0; truelight@0: } truelight@0: case SDT_MANYOFMANY: { Darkvater@2972: unsigned long r = lookup_manyofmany(desc->many, str); truelight@2923: if (r != (unsigned long)-1) return (void*)r; truelight@0: ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name); truelight@0: return 0; truelight@0: } truelight@0: case SDT_BOOLX: Darkvater@2972: if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) truelight@0: return (void*)true; Darkvater@2972: if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) truelight@0: return (void*)false; truelight@0: ShowInfoF("ini: invalid setting value '%s' for '%s'", str, desc->name); truelight@0: break; truelight@193: Darkvater@3115: case SDT_STRING: Darkvater@3115: case SDT_INTLIST: return str; rubidium@5838: default: break; truelight@0: } truelight@0: truelight@0: return NULL; truelight@0: } truelight@0: Darkvater@3115: /** Set the value of a setting and if needed clamp the value to Darkvater@3115: * the preset minimum and maximum. Darkvater@3115: * @param ptr the variable itself Darkvater@3115: * @param sd pointer to the 'information'-database of the variable Darkvater@3115: * @param val signed long version of the new value Darkvater@3115: * @pre SettingDesc is of type SDT_BOOLX, SDT_NUMX, Darkvater@3115: * SDT_ONEOFMANY or SDT_MANYOFMANY. Other types are not supported as of now */ Darkvater@3115: static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val) Darkvater@3115: { Darkvater@3115: const SettingDescBase *sdb = &sd->desc; Darkvater@3115: tron@4077: if (sdb->cmd != SDT_BOOLX && tron@4077: sdb->cmd != SDT_NUMX && tron@4077: sdb->cmd != SDT_ONEOFMANY && tron@4077: sdb->cmd != SDT_MANYOFMANY) { tron@4077: return; tron@4077: } Darkvater@3115: Darkvater@3115: /* We cannot know the maximum value of a bitset variable, so just have faith */ Darkvater@3352: if (sdb->cmd != SDT_MANYOFMANY) { Darkvater@3352: /* We need to take special care of the uint32 type as we receive from the function Darkvater@3352: * a signed integer. While here also bail out on 64-bit settings as those are not Darkvater@3352: * supported. Unsigned 8 and 16-bit variables are safe since they fit into a signed Darkvater@3352: * 32-bit variable Darkvater@3352: * TODO: Support 64-bit settings/variables */ Darkvater@3352: switch (GetVarMemType(sd->save.conv)) { Darkvater@3352: case SLE_VAR_BL: Darkvater@3352: case SLE_VAR_I8: Darkvater@3352: case SLE_VAR_U8: Darkvater@3352: case SLE_VAR_I16: Darkvater@3352: case SLE_VAR_U16: Darkvater@3352: case SLE_VAR_I32: { Darkvater@3352: /* Override the minimum value. No value below sdb->min, except special value 0 */ Darkvater@3352: int32 min = ((sdb->flags & SGF_0ISDISABLED) && val <= sdb->min) ? 0 : sdb->min; skidd13@8418: val = Clamp(val, min, sdb->max); Darkvater@3352: } break; Darkvater@3352: case SLE_VAR_U32: { Darkvater@3352: /* Override the minimum value. No value below sdb->min, except special value 0 */ Darkvater@3352: uint min = ((sdb->flags & SGF_0ISDISABLED) && (uint)val <= (uint)sdb->min) ? 0 : sdb->min; skidd13@8418: WriteValue(ptr, SLE_VAR_U32, (int64)ClampU(val, min, sdb->max)); Darkvater@3352: return; Darkvater@3352: } Darkvater@3352: case SLE_VAR_I64: Darkvater@3352: case SLE_VAR_U64: Darkvater@3352: default: NOT_REACHED(); break; Darkvater@3352: } Darkvater@3352: } Darkvater@3115: Darkvater@3115: WriteValue(ptr, sd->save.conv, (int64)val); Darkvater@3115: } Darkvater@3115: Darkvater@2972: /** Load values from a group of an IniFile structure into the internal representation Darkvater@2972: * @param ini pointer to IniFile structure that holds administrative information Darkvater@3615: * @param sd pointer to SettingDesc structure whose internally pointed variables will Darkvater@2972: * be given values belugas@6979: * @param grpname the group of the IniFile to search in for the new values belugas@6979: * @param object pointer to the object been loaded */ Darkvater@3115: static void ini_load_settings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object) truelight@0: { Darkvater@3115: IniGroup *group; glx@10471: IniGroup *group_def = ini_getgroup(ini, grpname); truelight@0: IniItem *item; darkvater@222: const void *p; truelight@0: void *ptr; Darkvater@3115: const char *s; truelight@0: Darkvater@3115: for (; sd->save.cmd != SL_END; sd++) { Darkvater@3115: const SettingDescBase *sdb = &sd->desc; Darkvater@3115: const SaveLoad *sld = &sd->save; Darkvater@3115: Darkvater@3117: if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue; Darkvater@3117: rubidium@10703: /* For patches.xx.yy load the settings from [xx] yy = ? */ Darkvater@3115: s = strchr(sdb->name, '.'); Darkvater@2972: if (s != NULL) { Darkvater@3115: group = ini_getgroup(ini, sdb->name, s - sdb->name); truelight@0: s++; truelight@0: } else { Darkvater@3115: s = sdb->name; truelight@0: group = group_def; truelight@0: } truelight@193: truelight@0: item = ini_getitem(group, s, false); rubidium@10703: if (item == NULL && group != group_def) { rubidium@10703: /* For patches.xx.yy load the settings from [patches] yy = ? in case the previous rubidium@10703: * did not exist (e.g. loading old config files with a [patches] section */ rubidium@10703: item = ini_getitem(group_def, s, false); rubidium@10703: } rubidium@10703: if (item == NULL) { rubidium@10703: /* For patches.xx.zz.yy load the settings from [zz] yy = ? in case the previous rubidium@10703: * did not exist (e.g. loading old config files with a [yapf] section */ rubidium@10703: const char *sc = strchr(s, '.'); rubidium@10703: if (sc != NULL) item = ini_getitem(ini_getgroup(ini, s, sc - s), sc + 1, false); rubidium@10703: } rubidium@10703: Darkvater@3115: p = (item == NULL) ? sdb->def : string_to_val(sdb, item->value); rubidium@10775: ptr = GetVariableAddress(object, sld); truelight@193: Darkvater@3115: switch (sdb->cmd) { Darkvater@2972: case SDT_BOOLX: /* All four are various types of (integer) numbers */ Darkvater@2972: case SDT_NUMX: truelight@0: case SDT_ONEOFMANY: truelight@0: case SDT_MANYOFMANY: Darkvater@3115: Write_ValidateSetting(ptr, sd, (unsigned long)p); break; Darkvater@3115: Darkvater@3115: case SDT_STRING: Darkvater@3115: switch (GetVarMemType(sld->conv)) { Darkvater@3115: case SLE_VAR_STRB: Darkvater@4255: case SLE_VAR_STRBQ: rubidium@5838: if (p != NULL) ttd_strlcpy((char*)ptr, (const char*)p, sld->length); Darkvater@4255: break; Darkvater@4255: case SLE_VAR_STR: Darkvater@3115: case SLE_VAR_STRQ: Darkvater@4255: if (p != NULL) { Darkvater@4255: free(*(char**)ptr); Darkvater@4255: *(char**)ptr = strdup((const char*)p); Darkvater@4255: } Darkvater@3115: break; Darkvater@3192: case SLE_VAR_CHAR: *(char*)ptr = *(char*)p; break; Darkvater@3115: default: NOT_REACHED(); break; truelight@0: } truelight@0: break; Darkvater@2972: truelight@0: case SDT_INTLIST: { belugas@10682: if (!load_intlist((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) { Darkvater@3115: ShowInfoF("ini: error in array '%s'", sdb->name); belugas@10682: } else if (sd->desc.proc_cnvt != NULL) { belugas@10682: sd->desc.proc_cnvt((const char*)p); belugas@10682: } truelight@0: break; truelight@0: } Darkvater@2972: default: NOT_REACHED(); break; truelight@0: } truelight@193: } truelight@0: } truelight@0: Darkvater@3615: /** Save the values of settings to the inifile. Darkvater@2972: * @param ini pointer to IniFile structure Darkvater@3615: * @param sd read-only SettingDesc structure which contains the unmodified, Darkvater@2972: * loaded values of the configuration file and various information about it Darkvater@2972: * @param grpname holds the name of the group (eg. [network]) where these will be saved belugas@6979: * @param object pointer to the object been saved tron@4000: * The function works as follows: for each item in the SettingDesc structure we tron@4000: * have a look if the value has changed since we started the game (the original tron@4000: * values are reloaded when saving). If settings indeed have changed, we get tron@4000: * these and save them. tron@4000: */ Darkvater@3115: static void ini_save_settings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object) truelight@0: { truelight@0: IniGroup *group_def = NULL, *group; truelight@0: IniItem *item; Darkvater@3115: char buf[512]; Darkvater@3115: const char *s; darkvater@222: void *ptr; truelight@0: Darkvater@3115: for (; sd->save.cmd != SL_END; sd++) { Darkvater@3115: const SettingDescBase *sdb = &sd->desc; Darkvater@3115: const SaveLoad *sld = &sd->save; Darkvater@3115: Darkvater@3115: /* If the setting is not saved to the configuration Darkvater@3115: * file, just continue with the next setting */ Darkvater@3117: if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue; Darkvater@3115: if (sld->conv & SLF_CONFIG_NO) continue; truelight@193: belugas@6916: /* XXX - wtf is this?? (group override?) */ Darkvater@3115: s = strchr(sdb->name, '.'); Darkvater@2972: if (s != NULL) { Darkvater@3115: group = ini_getgroup(ini, sdb->name, s - sdb->name); truelight@0: s++; truelight@0: } else { glx@10471: if (group_def == NULL) group_def = ini_getgroup(ini, grpname); Darkvater@3115: s = sdb->name; truelight@0: group = group_def; truelight@0: } truelight@193: truelight@0: item = ini_getitem(group, s, true); Darkvater@5141: ptr = GetVariableAddress(object, sld); truelight@193: truelight@0: if (item->value != NULL) { belugas@6916: /* check if the value is the same as the old value */ Darkvater@3115: const void *p = string_to_val(sdb, item->value); truelight@0: Darkvater@2972: /* The main type of a variable/setting is in bytes 8-15 rubidium@4549: * The subtype (what kind of numbers do we have there) is in 0-7 */ Darkvater@3115: switch (sdb->cmd) { Darkvater@2972: case SDT_BOOLX: Darkvater@2972: case SDT_NUMX: truelight@0: case SDT_ONEOFMANY: truelight@0: case SDT_MANYOFMANY: Darkvater@3115: switch (GetVarMemType(sld->conv)) { Darkvater@3115: case SLE_VAR_BL: rubidium@5838: if (*(bool*)ptr == (p != NULL)) continue; Darkvater@5066: break; Darkvater@3115: case SLE_VAR_I8: Darkvater@3115: case SLE_VAR_U8: Darkvater@2972: if (*(byte*)ptr == (byte)(unsigned long)p) continue; truelight@0: break; Darkvater@3115: case SLE_VAR_I16: Darkvater@3115: case SLE_VAR_U16: Darkvater@2972: if (*(uint16*)ptr == (uint16)(unsigned long)p) continue; truelight@0: break; Darkvater@3115: case SLE_VAR_I32: Darkvater@3115: case SLE_VAR_U32: Darkvater@2972: if (*(uint32*)ptr == (uint32)(unsigned long)p) continue; truelight@0: break; Darkvater@2972: default: NOT_REACHED(); truelight@0: } truelight@0: break; Darkvater@2972: default: break; /* Assume the other types are always changed */ truelight@0: } truelight@0: } truelight@0: Darkvater@2972: /* Value has changed, get the new value and put it into a buffer */ Darkvater@3115: switch (sdb->cmd) { Darkvater@2972: case SDT_BOOLX: Darkvater@2972: case SDT_NUMX: truelight@0: case SDT_ONEOFMANY: Darkvater@3115: case SDT_MANYOFMANY: { Darkvater@3115: uint32 i = (uint32)ReadValue(ptr, sld->conv); Darkvater@3115: Darkvater@3115: switch (sdb->cmd) { Darkvater@3115: case SDT_BOOLX: strcpy(buf, (i != 0) ? "true" : "false"); break; KUDr@3900: case SDT_NUMX: sprintf(buf, IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break; Darkvater@3115: case SDT_ONEOFMANY: make_oneofmany(buf, sdb->many, i); break; Darkvater@3115: case SDT_MANYOFMANY: make_manyofmany(buf, sdb->many, i); break; Darkvater@2972: default: NOT_REACHED(); truelight@0: } Darkvater@3115: } break; Darkvater@2972: Darkvater@3115: case SDT_STRING: Darkvater@3115: switch (GetVarMemType(sld->conv)) { Darkvater@3115: case SLE_VAR_STRB: strcpy(buf, (char*)ptr); break; Darkvater@4255: case SLE_VAR_STRBQ:sprintf(buf, "\"%s\"", (char*)ptr); break; Darkvater@4255: case SLE_VAR_STR: strcpy(buf, *(char**)ptr); break; Darkvater@4255: case SLE_VAR_STRQ: sprintf(buf, "\"%s\"", *(char**)ptr); break; Darkvater@3115: case SLE_VAR_CHAR: sprintf(buf, "\"%c\"", *(char*)ptr); break; Darkvater@2972: default: NOT_REACHED(); truelight@0: } truelight@0: break; Darkvater@2972: Darkvater@3115: case SDT_INTLIST: Darkvater@3115: make_intlist(buf, ptr, sld->length, GetVarMemType(sld->conv)); truelight@0: break; Darkvater@3115: default: NOT_REACHED(); truelight@0: } Darkvater@2972: Darkvater@2972: /* The value is different, that means we have to write it to the ini */ rubidium@5838: item->value = (char*)pool_strdup(&ini->pool, buf, strlen(buf)); truelight@193: } truelight@0: } truelight@0: Darkvater@3615: /** Loads all items from a 'grpname' section into a list Darkvater@3615: * The list parameter can be a NULL pointer, in this case nothing will be Darkvater@3615: * saved and a callback function should be defined that will take over the Darkvater@3615: * list-handling and store the data itself somewhere. belugas@6979: * @param ini IniFile handle to the ini file with the source data Darkvater@3615: * @param grpname character string identifying the section-header of the ini Darkvater@3615: * file that will be parsed Darkvater@3615: * @param list pointer to an string(pointer) array that will store the parsed Darkvater@3615: * entries of the given section Darkvater@3628: * @param len the maximum number of items available for the above list Darkvater@3628: * @param proc callback function that can override how the values are stored Darkvater@3628: * inside the list */ Darkvater@3628: static void ini_load_setting_list(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc) Darkvater@3115: { glx@10471: IniGroup *group = ini_getgroup(ini, grpname); Darkvater@3115: IniItem *item; Darkvater@3628: const char *entry; Darkvater@3628: uint i, j; Darkvater@3115: Darkvater@3115: if (group == NULL) return; Darkvater@3115: Darkvater@3628: for (i = j = 0, item = group->item; item != NULL; item = item->next) { Darkvater@3628: entry = (proc != NULL) ? proc(item, i++) : item->name; Darkvater@3628: Darkvater@3628: if (entry == NULL || list == NULL) continue; Darkvater@3628: Darkvater@3628: if (j == len) break; Darkvater@3628: list[j++] = strdup(entry); Darkvater@3115: } Darkvater@3115: } Darkvater@3115: Darkvater@3615: /** Saves all items from a list into the 'grpname' section Darkvater@3615: * The list parameter can be a NULL pointer, in this case a callback function Darkvater@3615: * should be defined that will provide the source data to be saved. belugas@6984: * @param ini IniFile handle to the ini file where the destination data is saved Darkvater@3615: * @param grpname character string identifying the section-header of the ini file Darkvater@3615: * @param list pointer to an string(pointer) array that will be used as the belugas@6984: * source to be saved into the relevant ini section Darkvater@3615: * @param len the maximum number of items available for the above list Darkvater@3615: * @param proc callback function that can will provide the source data if defined */ Darkvater@3628: static void ini_save_setting_list(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc) Darkvater@3115: { glx@10471: IniGroup *group = ini_getgroup(ini, grpname); Darkvater@3115: IniItem *item = NULL; Darkvater@3628: const char *entry; Darkvater@3115: uint i; Darkvater@3115: bool first = true; Darkvater@3115: Darkvater@3628: if (proc == NULL && list == NULL) return; Darkvater@3115: if (group == NULL) return; Darkvater@3115: group->item = NULL; Darkvater@3115: Darkvater@3115: for (i = 0; i != len; i++) { Darkvater@3628: entry = (proc != NULL) ? proc(NULL, i) : list[i]; Darkvater@3628: Darkvater@3628: if (entry == NULL || *entry == '\0') continue; Darkvater@3115: Darkvater@3115: if (first) { // add first item to the head of the group Darkvater@3628: item = ini_item_alloc(group, entry, strlen(entry)); Darkvater@3115: item->value = item->name; Darkvater@3115: group->item = item; Darkvater@3115: first = false; Darkvater@3115: } else { // all other items are attached to the previous one Darkvater@3628: item->next = ini_item_alloc(group, entry, strlen(entry)); Darkvater@3115: item = item->next; Darkvater@3115: item->value = item->name; Darkvater@3115: } Darkvater@3115: } Darkvater@3115: } Darkvater@3115: truelight@0: //*************************** Darkvater@2972: // OTTD specific INI stuff truelight@0: //*************************** truelight@0: Darkvater@3116: /** Settings-macro usage: Darkvater@3116: * The list might look daunting at first, but is in general easy to understand. Darkvater@3116: * We have two types of list: Darkvater@3116: * 1. SDTG_something Darkvater@3116: * 2. SDT_something tron@4000: * The 'G' stands for global, so this is the one you will use for a tron@4000: * SettingDescGlobVarList section meaning global variables. The other uses a maedhros@6953: * Base/Offset and runtime variable selection mechanism, known from the saveload maedhros@6953: * convention (it also has global so it should not be hard). tron@4000: * Of each type there are again two versions, the normal one and one prefixed tron@4000: * with 'COND'. tron@4000: * COND means that the setting is only valid in certain savegame versions tron@4000: * (since patches are saved to the savegame, this bookkeeping is necessary. Darkvater@3116: * Now there are a lot of types. Easy ones are: Darkvater@3116: * - VAR: any number type, 'type' field specifies what number. eg int8 or uint32 Darkvater@3116: * - BOOL: a boolean number type Darkvater@3116: * - STR: a string or character. 'type' field specifies what string. Normal, string, or quoted Darkvater@3116: * A bit more difficult to use are MMANY (meaning ManyOfMany) and OMANY (OneOfMany) tron@4000: * These are actually normal numbers, only bitmasked. In MMANY several bits can tron@4000: * be set, in the other only one. Darkvater@3116: * The most complex type is INTLIST. This is basically an array of numbers. If Darkvater@3116: * the intlist is only valid in certain savegame versions because for example Darkvater@3116: * it has grown in size its length cannot be automatically be calculated so Darkvater@3116: * use SDT(G)_CONDLISTO() meaning Old. tron@4000: * If nothing fits you, you can use the GENERAL macros, but it exposes the tron@4000: * internal structure somewhat so it needs a little looking. There are _NULL() tron@4000: * macros as well, these fill up space so you can add more patches there (in belugas@6681: * place) and you DON'T have to increase the savegame version. belugas@6681: * belugas@6681: * While reading values from openttd.cfg, some values may not be converted belugas@6681: * properly, for any kind of reasons. In order to allow a process of self-cleaning belugas@6681: * mechanism, a callback procedure is made available. You will have to supply the function, which belugas@6681: * will work on a string, one function per patch. And of course, enable the callback param belugas@6681: * on the appropriate macro. belugas@6681: */ Darkvater@3116: belugas@6681: #define NSD_GENERAL(name, def, cmd, guiflags, min, max, interval, many, str, proc, load)\ belugas@6681: {name, (const void*)(def), {cmd}, {guiflags}, min, max, interval, many, str, proc, load} Darkvater@3116: Darkvater@3116: /* Macros for various objects to go in the configuration file. Darkvater@3116: * This section is for global variables */ rubidium@4431: #define SDTG_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, var, length, def, min, max, interval, full, str, proc, from, to)\ belugas@6681: {NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, proc, NULL), SLEG_GENERAL(sle_cmd, var, type | flags, length, from, to)} Darkvater@3116: rubidium@4431: #define SDTG_CONDVAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc, from, to)\ rubidium@4431: SDTG_GENERAL(name, SDT_NUMX, SL_VAR, type, flags, guiflags, var, 0, def, min, max, interval, NULL, str, proc, from, to) rubidium@4431: #define SDTG_VAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc)\ rubidium@4431: SDTG_CONDVAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc, 0, SL_MAX_VERSION) Darkvater@3116: Darkvater@3116: #define SDTG_CONDBOOL(name, flags, guiflags, var, def, str, proc, from, to)\ rubidium@6309: SDTG_GENERAL(name, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, var, 0, def, 0, 1, 0, NULL, str, proc, from, to) Darkvater@3116: #define SDTG_BOOL(name, flags, guiflags, var, def, str, proc)\ Darkvater@3116: SDTG_CONDBOOL(name, flags, guiflags, var, def, str, proc, 0, SL_MAX_VERSION) Darkvater@3116: Darkvater@3116: #define SDTG_CONDLIST(name, type, length, flags, guiflags, var, def, str, proc, from, to)\ rubidium@4431: SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, proc, from, to) Darkvater@3116: #define SDTG_LIST(name, type, flags, guiflags, var, def, str, proc)\ rubidium@4431: SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, proc, 0, SL_MAX_VERSION) Darkvater@3116: Darkvater@3116: #define SDTG_CONDSTR(name, type, length, flags, guiflags, var, def, str, proc, from, to)\ rubidium@4431: SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, proc, from, to) Darkvater@3116: #define SDTG_STR(name, type, flags, guiflags, var, def, str, proc)\ rubidium@4431: SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, proc, 0, SL_MAX_VERSION) Darkvater@3116: Darkvater@3116: #define SDTG_CONDOMANY(name, type, flags, guiflags, var, def, max, full, str, proc, from, to)\ rubidium@4431: SDTG_GENERAL(name, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, max, 0, full, str, proc, from, to) Darkvater@3116: #define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, proc)\ glx@7024: SDTG_CONDOMANY(name, type, flags, guiflags, var, def, max, full, str, proc, 0, SL_MAX_VERSION) Darkvater@3116: Darkvater@3116: #define SDTG_CONDMMANY(name, type, flags, guiflags, var, def, full, str, proc, from, to)\ rubidium@4431: SDTG_GENERAL(name, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, 0, 0, full, str, proc, from, to) Darkvater@3116: #define SDTG_MMANY(name, type, flags, guiflags, var, def, full, str, proc)\ Darkvater@3116: SDTG_CONDMMANY(name, type, flags, guiflags, var, def, full, str, proc, 0, SL_MAX_VERSION) Darkvater@3116: Darkvater@3222: #define SDTG_CONDNULL(length, from, to)\ belugas@6681: {{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLEG_CONDNULL(length, from, to)} Darkvater@3222: belugas@6681: #define SDTG_END() {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLEG_END()} Darkvater@3116: Darkvater@3116: /* Macros for various objects to go in the configuration file. Darkvater@3116: * This section is for structures where their various members are saved */ belugas@6682: #define SDT_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, base, var, length, def, min, max, interval, full, str, proc, load, from, to)\ belugas@6682: {NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, proc, load), SLE_GENERAL(sle_cmd, base, var, type | flags, length, from, to)} Darkvater@3116: rubidium@4431: #define SDT_CONDVAR(base, var, type, from, to, flags, guiflags, def, min, max, interval, str, proc)\ belugas@6682: SDT_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, base, var, 1, def, min, max, interval, NULL, str, proc, NULL, from, to) rubidium@4431: #define SDT_VAR(base, var, type, flags, guiflags, def, min, max, interval, str, proc)\ rubidium@4431: SDT_CONDVAR(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, min, max, interval, str, proc) Darkvater@3116: Darkvater@3116: #define SDT_CONDBOOL(base, var, from, to, flags, guiflags, def, str, proc)\ belugas@6682: SDT_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, base, var, 1, def, 0, 1, 0, NULL, str, proc, NULL, from, to) Darkvater@3116: #define SDT_BOOL(base, var, flags, guiflags, def, str, proc)\ Darkvater@3116: SDT_CONDBOOL(base, var, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc) Darkvater@3116: Darkvater@3116: #define SDT_CONDLIST(base, var, type, from, to, flags, guiflags, def, str, proc)\ belugas@6682: SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, proc, NULL, from, to) Darkvater@3116: #define SDT_LIST(base, var, type, flags, guiflags, def, str, proc)\ Darkvater@3116: SDT_CONDLIST(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc) belugas@10682: #define SDT_CONDLISTO(base, var, length, type, from, to, flags, guiflags, def, str, proc, load)\ belugas@10682: SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, length, def, 0, 0, 0, NULL, str, proc, load, from, to) Darkvater@3116: Darkvater@3116: #define SDT_CONDSTR(base, var, type, from, to, flags, guiflags, def, str, proc)\ belugas@6682: SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, proc, NULL, from, to) Darkvater@3116: #define SDT_STR(base, var, type, flags, guiflags, def, str, proc)\ Darkvater@3116: SDT_CONDSTR(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc) Darkvater@3116: #define SDT_CONDSTRO(base, var, length, type, from, to, flags, def, str, proc)\ Darkvater@3116: SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, 0, base, var, length, def, 0, 0, NULL, str, proc, from, to) Darkvater@3116: Darkvater@3116: #define SDT_CONDCHR(base, var, from, to, flags, guiflags, def, str, proc)\ belugas@6682: SDT_GENERAL(#var, SDT_STRING, SL_VAR, SLE_CHAR, flags, guiflags, base, var, 1, def, 0, 0, 0, NULL, str, proc, NULL, from, to) Darkvater@3116: #define SDT_CHR(base, var, flags, guiflags, def, str, proc)\ Darkvater@3116: SDT_CONDCHR(base, var, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc) Darkvater@3116: belugas@6682: #define SDT_CONDOMANY(base, var, type, from, to, flags, guiflags, def, max, full, str, proc, load)\ belugas@6682: SDT_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, max, 0, full, str, proc, load, from, to) belugas@6682: #define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, proc, load)\ belugas@6682: SDT_CONDOMANY(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, max, full, str, proc, load) Darkvater@3116: Darkvater@3116: #define SDT_CONDMMANY(base, var, type, from, to, flags, guiflags, def, full, str, proc)\ belugas@6682: SDT_GENERAL(#var, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, 0, 0, full, str, proc, NULL, from, to) Darkvater@3116: #define SDT_MMANY(base, var, type, flags, guiflags, def, full, str, proc)\ Darkvater@3116: SDT_CONDMMANY(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, full, str, proc) Darkvater@3116: Darkvater@3222: #define SDT_CONDNULL(length, from, to)\ belugas@6681: {{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLE_CONDNULL(length, from, to)} Darkvater@3222: rubidium@10775: rubidium@10775: #define SDTC_CONDVAR(var, type, from, to, flags, guiflags, def, min, max, interval, str, proc)\ rubidium@10782: SDTG_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, min, max, interval, NULL, str, proc, from, to) rubidium@10775: #define SDTC_VAR(var, type, flags, guiflags, def, min, max, interval, str, proc)\ rubidium@10775: SDTC_CONDVAR(var, type, 0, SL_MAX_VERSION, flags, guiflags, def, min, max, interval, str, proc) rubidium@10775: rubidium@10775: #define SDTC_CONDBOOL(var, from, to, flags, guiflags, def, str, proc)\ rubidium@10782: SDTG_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, _settings_client.var, 1, def, 0, 1, 0, NULL, str, proc, from, to) rubidium@10775: #define SDTC_BOOL(var, flags, guiflags, def, str, proc)\ rubidium@10775: SDTC_CONDBOOL(var, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc) rubidium@10775: rubidium@10775: #define SDTC_CONDLIST(var, type, length, flags, guiflags, def, str, proc, from, to)\ rubidium@10775: SDTG_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, _settings_client.var, length, def, 0, 0, 0, NULL, str, proc, from, to) rubidium@10775: #define SDTC_LIST(var, type, flags, guiflags, def, str, proc)\ rubidium@10790: SDTG_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, proc, 0, SL_MAX_VERSION) rubidium@10775: rubidium@10775: #define SDTC_CONDSTR(var, type, length, flags, guiflags, def, str, proc, from, to)\ rubidium@10775: SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, length, def, 0, 0, 0, NULL, str, proc, from, to) rubidium@10775: #define SDTC_STR(var, type, flags, guiflags, def, str, proc)\ rubidium@10790: SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, proc, 0, SL_MAX_VERSION) rubidium@10775: rubidium@10775: #define SDTC_CONDOMANY(var, type, from, to, flags, guiflags, def, max, full, str, proc)\ rubidium@10782: SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, proc, from, to) rubidium@10775: #define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, proc)\ rubidium@10775: SDTC_CONDOMANY(var, type, 0, SL_MAX_VERSION, flags, guiflags, def, max, full, str, proc) rubidium@10775: belugas@6681: #define SDT_END() {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLE_END()} Darkvater@3116: Darkvater@3116: /* Shortcuts for macros below. Logically if we don't save the value Darkvater@3116: * we also don't sync it in a network game */ Darkvater@3116: #define S SLF_SAVE_NO | SLF_NETWORK_NO Darkvater@3116: #define C SLF_CONFIG_NO Darkvater@3116: #define N SLF_NETWORK_NO Darkvater@3116: Darkvater@3116: #define D0 SGF_0ISDISABLED Darkvater@3116: #define NC SGF_NOCOMMA Darkvater@3116: #define MS SGF_MULTISTRING Darkvater@3116: #define NO SGF_NETWORK_ONLY Darkvater@3116: #define CR SGF_CURRENCY rubidium@8397: #define NN SGF_NO_NETWORK rubidium@10708: #define NG SGF_NEWGAME_ONLY Darkvater@3116: Darkvater@3131: /* Begin - Callback Functions for the various settings */ belugas@6916: /* virtual PositionMainToolbar function, calls the right one.*/ Darkvater@3131: static int32 v_PositionMainToolbar(int32 p1) Darkvater@3131: { Darkvater@3131: if (_game_mode != GM_MENU) PositionMainToolbar(NULL); Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: Darkvater@3131: static int32 AiNew_PatchActive_Warning(int32 p1) Darkvater@3131: { Darkvater@3131: if (p1 == 1) ShowErrorMessage(INVALID_STRING_ID, TEMP_AI_ACTIVATED, 0, 0); Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: Darkvater@3131: static int32 Ai_In_Multiplayer_Warning(int32 p1) Darkvater@3131: { Darkvater@3131: if (p1 == 1) { Darkvater@3131: ShowErrorMessage(INVALID_STRING_ID, TEMP_AI_MULTIPLAYER, 0, 0); rubidium@10775: _settings_game.ai.ainew_active = true; Darkvater@3131: } Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: Darkvater@3131: static int32 PopulationInLabelActive(int32 p1) Darkvater@3131: { Darkvater@3131: Town* t; Darkvater@3131: truelight@4346: FOR_ALL_TOWNS(t) UpdateTownVirtCoord(t); truelight@4346: Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: tron@4082: static int32 RedrawScreen(int32 p1) Darkvater@3131: { Darkvater@3131: MarkWholeScreenDirty(); Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: Darkvater@3131: static int32 InValidateDetailsWindow(int32 p1) Darkvater@3131: { Darkvater@3131: InvalidateWindowClasses(WC_VEHICLE_DETAILS); Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: Darkvater@3131: static int32 InvalidateStationBuildWindow(int32 p1) Darkvater@3131: { Darkvater@3131: InvalidateWindow(WC_BUILD_STATION, 0); Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: glx@10516: static int32 InvalidateBuildIndustryWindow(int32 p1) glx@10516: { glx@10516: InvalidateWindowData(WC_BUILD_INDUSTRY, 0); glx@10516: return 0; glx@10516: } glx@10516: belugas@10495: static int32 CloseSignalGUI(int32 p1) belugas@10495: { belugas@10495: if (p1 == 0) { belugas@10495: DeleteWindowByClass(WC_BUILD_SIGNAL); belugas@10495: } belugas@10495: return 0; belugas@10495: } belugas@10495: belugas@10682: static int32 InvalidateTownViewWindow(int32 p1) belugas@10682: { belugas@10682: InvalidateWindowClassesData(WC_TOWN_VIEW, p1); belugas@10682: return 0; belugas@10682: } belugas@10682: rubidium@8249: static int32 UpdateConsists(int32 p1) rubidium@8249: { rubidium@8249: Vehicle *v; rubidium@8249: FOR_ALL_VEHICLES(v) { rubidium@8249: /* Update the consist of all trains so the maximum speed is set correctly. */ rubidium@8249: if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) TrainConsistChanged(v); rubidium@8249: } rubidium@8249: return 0; rubidium@8249: } rubidium@8249: Darkvater@3131: /* Check service intervals of vehicles, p1 is value of % or day based servicing */ Darkvater@3131: static int32 CheckInterval(int32 p1) Darkvater@3131: { Darkvater@3131: bool warning; rubidium@10775: const VehicleSettings *ptc = (_game_mode == GM_MENU) ? &_settings_newgame.vehicle : &_settings_game.vehicle; Darkvater@3131: Darkvater@3131: if (p1) { skidd13@8450: warning = ( (IsInsideMM(ptc->servint_trains, 5, 90 + 1) || ptc->servint_trains == 0) && skidd13@8450: (IsInsideMM(ptc->servint_roadveh, 5, 90 + 1) || ptc->servint_roadveh == 0) && skidd13@8450: (IsInsideMM(ptc->servint_aircraft, 5, 90 + 1) || ptc->servint_aircraft == 0) && skidd13@8450: (IsInsideMM(ptc->servint_ships, 5, 90 + 1) || ptc->servint_ships == 0) ); Darkvater@3131: } else { skidd13@8450: warning = ( (IsInsideMM(ptc->servint_trains, 30, 800 + 1) || ptc->servint_trains == 0) && skidd13@8450: (IsInsideMM(ptc->servint_roadveh, 30, 800 + 1) || ptc->servint_roadveh == 0) && skidd13@8450: (IsInsideMM(ptc->servint_aircraft, 30, 800 + 1) || ptc->servint_aircraft == 0) && skidd13@8450: (IsInsideMM(ptc->servint_ships, 30, 800 + 1) || ptc->servint_ships == 0) ); Darkvater@3131: } Darkvater@3131: Darkvater@3131: if (!warning) Darkvater@3131: ShowErrorMessage(INVALID_STRING_ID, STR_CONFIG_PATCHES_SERVICE_INTERVAL_INCOMPATIBLE, 0, 0); Darkvater@3131: Darkvater@3131: return InValidateDetailsWindow(0); Darkvater@3131: } Darkvater@3131: Darkvater@3131: static int32 EngineRenewUpdate(int32 p1) Darkvater@3131: { rubidium@10775: DoCommandP(0, 0, _settings_client.gui.autorenew, NULL, CMD_SET_AUTOREPLACE); Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: Darkvater@3131: static int32 EngineRenewMonthsUpdate(int32 p1) Darkvater@3131: { rubidium@10775: DoCommandP(0, 1, _settings_client.gui.autorenew_months, NULL, CMD_SET_AUTOREPLACE); Darkvater@3131: return 0; Darkvater@3131: } Darkvater@3131: Darkvater@3131: static int32 EngineRenewMoneyUpdate(int32 p1) Darkvater@3131: { rubidium@10775: DoCommandP(0, 2, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE); Darkvater@3131: return 0; Darkvater@3131: } belugas@7067: smatz@9192: static int32 RealisticAccelerationChanged(int32 p1) smatz@9192: { smatz@9192: Vehicle *v; smatz@9192: smatz@9192: FOR_ALL_VEHICLES(v) { smatz@9192: if (v->type == VEH_TRAIN && IsFrontEngine(v)) UpdateTrainAcceleration(v); smatz@9192: } smatz@9192: smatz@9192: return 0; smatz@9192: } smatz@9192: smatz@9306: static int32 DragSignalsDensityChanged(int32) smatz@9306: { rubidium@10434: SetWindowDirty(FindWindowById(WC_BUILD_SIGNAL, 0)); smatz@9306: smatz@9306: return 0; smatz@9306: } smatz@9306: rubidium@10708: /* rubidium@10708: * A: competitors rubidium@10708: * B: start time in months / 3 rubidium@10708: * C: town count (3 = high, 0 = very low) rubidium@10708: * D: industry count (4 = high, 0 = none) rubidium@10708: * E: inital loan (in GBP) rubidium@10708: * F: interest rate rubidium@10708: * G: running costs (0 = low, 2 = high) rubidium@10708: * H: construction speed of competitors (0 = very slow, 4 = very fast) rubidium@10708: * I: intelligence (0-2) rubidium@10708: * J: breakdowns (0 = off, 2 = normal) rubidium@10708: * K: subsidy multiplier (0 = 1.5, 3 = 4.0) rubidium@10708: * L: construction cost (0-2) rubidium@10708: * M: terrain type (0 = very flat, 3 = mountainous) rubidium@10708: * N: amount of water (0 = very low, 3 = high) rubidium@10708: * O: economy (0 = steady, 1 = fluctuating) rubidium@10708: * P: Train reversing (0 = end of line + stations, 1 = end of line) rubidium@10708: * Q: disasters rubidium@10708: * R: area restructuring (0 = permissive, 2 = hostile) rubidium@10708: * S: the difficulty level rubidium@10708: */ rubidium@10708: static const DifficultySettings _default_game_diff[3] = { /* rubidium@10708: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S*/ rubidium@10708: {2, 2, 2, 4, 300000, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0}, ///< easy rubidium@10708: {4, 1, 2, 3, 150000, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1}, ///< medium rubidium@10708: {7, 0, 3, 3, 100000, 4, 1, 3, 2, 2, 0, 2, 3, 2, 1, 1, 1, 2, 2}, ///< hard rubidium@10708: }; rubidium@10708: rubidium@10708: void SetDifficultyLevel(int mode, DifficultySettings *gm_opt) rubidium@10708: { rubidium@10708: assert(mode <= 3); rubidium@10708: rubidium@10708: if (mode != 3) { rubidium@10708: *gm_opt = _default_game_diff[mode]; rubidium@10708: } else { rubidium@10708: gm_opt->diff_level = 3; rubidium@10708: } rubidium@10708: } rubidium@10708: rubidium@10708: /** rubidium@10708: * Checks the difficulty levels read from the configuration and rubidium@10708: * forces them to be correct when invalid. rubidium@10708: */ rubidium@10708: void CheckDifficultyLevels() rubidium@10708: { rubidium@10708: if (_settings_newgame.difficulty.diff_level != 3) { rubidium@10708: SetDifficultyLevel(_settings_newgame.difficulty.diff_level, &_settings_newgame.difficulty); rubidium@10708: } rubidium@10708: } rubidium@10708: rubidium@10708: static int32 DifficultyReset(int32 level) rubidium@10708: { rubidium@10775: SetDifficultyLevel(level, (_game_mode == GM_MENU) ? &_settings_newgame.difficulty : &_settings_game.difficulty); rubidium@10708: return 0; rubidium@10708: } rubidium@10708: rubidium@10708: static int32 DifficultyChange(int32) rubidium@10708: { rubidium@10708: if (_game_mode == GM_MENU) { rubidium@10708: _settings_newgame.difficulty.diff_level = 3; rubidium@10708: } else { rubidium@10775: _settings_game.difficulty.diff_level = 3; rubidium@10708: } rubidium@10708: rubidium@10708: /* If we are a network-client, update the difficult setting (if it is open). rubidium@10708: * Use this instead of just dirtying the window because we need to load in rubidium@10708: * the new difficulty settings */ rubidium@10708: if (_networking && FindWindowById(WC_GAME_OPTIONS, 0) != NULL) { rubidium@10708: ShowGameDifficulty(); rubidium@10708: } rubidium@10708: rubidium@10708: return 0; rubidium@10708: } rubidium@10708: rubidium@10708: static int32 DifficultyNoiseChange(int32 i) rubidium@10708: { rubidium@10708: if (_game_mode == GM_NORMAL) { rubidium@10708: UpdateAirportsNoise(); rubidium@10775: if (_settings_game.economy.station_noise_level) { rubidium@10708: InvalidateWindowClassesData(WC_TOWN_VIEW, 0); rubidium@10708: } rubidium@10708: } rubidium@10708: rubidium@10708: return DifficultyChange(i); rubidium@10708: } rubidium@10708: belugas@7067: /** belugas@7067: * Check for right TownLayout usage in editor mode. belugas@7067: * The No Road mode is not desirable since towns have to be belugas@7067: * able to grow. If a user desires to have a town with no road, belugas@7067: * he can easily remove them himself. This would create less confusion belugas@7067: * @param p1 unused belugas@7067: * @return always 0 belugas@7067: */ belugas@7067: static int32 CheckTownLayout(int32 p1) belugas@7067: { rubidium@10775: if (_settings_game.economy.town_layout == TL_NO_ROADS && _game_mode == GM_EDITOR) { belugas@7067: ShowErrorMessage(INVALID_STRING_ID, STR_CONFIG_PATCHES_TOWN_LAYOUT_INVALID, 0, 0); rubidium@10775: _settings_game.economy.town_layout = TL_ORIGINAL; belugas@7067: } belugas@7067: return 0; belugas@7067: } belugas@7067: rubidium@10775: /** Conversion callback for _gameopt_settings_game.landscape belugas@6682: * It converts (or try) between old values and the new ones, belugas@6682: * without loosing initial setting of the user belugas@6682: * @param value that was read from config file belugas@6682: * @return the "hopefully" converted value belugas@6682: */ belugas@6682: static int32 ConvertLandscape(const char *value) belugas@6682: { belugas@6682: /* try with the old values */ glx@10471: return lookup_oneofmany("normal|hilly|desert|candy", value); belugas@6682: } belugas@6682: belugas@10682: /** belugas@10682: * Check for decent values been supplied by the user for the noise tolerance setting. belugas@10682: * The primary idea is to avoid division by zero in game mode. belugas@10682: * The secondary idea is to make it so the values will be somewhat sane and that towns will belugas@10682: * not be overcrowed with airports. It would be easy to abuse such a feature belugas@10682: * So basically, 200, 400, 800 are the lowest allowed values */ belugas@10682: static int32 CheckNoiseToleranceLevel(const char *value) belugas@10682: { rubidium@10775: GameSettings *s = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game; rubidium@10703: for (uint16 i = 0; i < lengthof(s->economy.town_noise_population); i++) { rubidium@10703: s->economy.town_noise_population[i] = max(uint16(200 * (i + 1)), s->economy.town_noise_population[i]); belugas@10682: } belugas@10682: return 0; belugas@10682: } belugas@10682: rubidium@10790: #ifdef ENABLE_NETWORK rubidium@10790: rubidium@10790: static int32 UpdateMinPlayers(int32 p1) rubidium@10790: { rubidium@10790: CheckMinPlayers(); rubidium@10790: return 0; rubidium@10790: } rubidium@10790: rubidium@10790: static int32 UpdatePlayerName(int32 p1) rubidium@10790: { rubidium@10792: NetworkUpdatePlayerName(); rubidium@10790: return 0; rubidium@10790: } rubidium@10790: rubidium@10790: static int32 UpdateServerPassword(int32 p1) rubidium@10790: { rubidium@10790: if (strcmp(_settings_client.network.server_password, "*") == 0) { rubidium@10790: _settings_client.network.server_password[0] = '\0'; rubidium@10790: } rubidium@10790: rubidium@10790: return 0; rubidium@10790: } rubidium@10790: rubidium@10790: static int32 UpdateRconPassword(int32 p1) rubidium@10790: { rubidium@10790: if (strcmp(_settings_client.network.rcon_password, "*") == 0) { rubidium@10790: _settings_client.network.rcon_password[0] = '\0'; rubidium@10790: } rubidium@10790: rubidium@10790: return 0; rubidium@10790: } rubidium@10790: rubidium@10790: #endif /* ENABLE_NETWORK */ rubidium@10790: rubidium@10790: Darkvater@3131: /* End - Callback Functions */ Darkvater@3131: pasky@1584: #ifndef EXTERNAL_PLAYER pasky@1584: #define EXTERNAL_PLAYER "timidity" pasky@1584: #endif pasky@1584: Darkvater@3116: static const SettingDesc _music_settings[] = { rubidium@4431: SDT_VAR(MusicFileSettings, playlist, SLE_UINT8, S, 0, 0, 0, 5, 1, STR_NULL, NULL), rubidium@4431: SDT_VAR(MusicFileSettings, music_vol, SLE_UINT8, S, 0, 128, 0, 100, 1, STR_NULL, NULL), rubidium@4431: SDT_VAR(MusicFileSettings, effect_vol, SLE_UINT8, S, 0, 128, 0, 100, 1, STR_NULL, NULL), rubidium@4344: SDT_LIST(MusicFileSettings, custom_1, SLE_UINT8, S, 0, NULL, STR_NULL, NULL), rubidium@4344: SDT_LIST(MusicFileSettings, custom_2, SLE_UINT8, S, 0, NULL, STR_NULL, NULL), rubidium@4344: SDT_BOOL(MusicFileSettings, playing, S, 0, true, STR_NULL, NULL), rubidium@4344: SDT_BOOL(MusicFileSettings, shuffle, S, 0, false, STR_NULL, NULL), rubidium@4344: SDT_STR(MusicFileSettings, extmidi, SLE_STRB, S, 0, EXTERNAL_PLAYER, STR_NULL, NULL), Darkvater@3116: SDT_END() truelight@0: }; truelight@0: Darkvater@3051: /* win32_v.c only settings */ Darkvater@3051: #ifdef WIN32 truelight@7374: extern bool _force_full_redraw, _window_maximize; Darkvater@3051: extern uint _display_hz, _fullscreen_bpp; Darkvater@3051: Darkvater@3124: static const SettingDescGlobVarList _win32_settings[] = { rubidium@4431: SDTG_VAR("display_hz", SLE_UINT, S, 0, _display_hz, 0, 0, 120, 0, STR_NULL, NULL), rubidium@4431: SDTG_BOOL("force_full_redraw", S, 0, _force_full_redraw,false, STR_NULL, NULL), rubidium@4431: SDTG_VAR("fullscreen_bpp", SLE_UINT, S, 0, _fullscreen_bpp, 8, 8, 32, 0, STR_NULL, NULL), rubidium@4431: SDTG_BOOL("window_maximize", S, 0, _window_maximize, false, STR_NULL, NULL), Darkvater@3116: SDTG_END() truelight@0: }; Darkvater@3051: #endif /* WIN32 */ truelight@0: Darkvater@3116: static const SettingDescGlobVarList _misc_settings[] = { peter1138@7192: SDTG_MMANY("display_opt", SLE_UINT8, S, 0, _display_opt, (1 << DO_SHOW_TOWN_NAMES | 1 << DO_SHOW_STATION_NAMES | 1 << DO_SHOW_SIGNS | 1 << DO_FULL_ANIMATION | 1 << DO_FULL_DETAIL | 1 << DO_WAYPOINTS), "SHOW_TOWN_NAMES|SHOW_STATION_NAMES|SHOW_SIGNS|FULL_ANIMATION||FULL_DETAIL|WAYPOINTS", STR_NULL, NULL), Darkvater@3116: SDTG_BOOL("news_ticker_sound", S, 0, _news_ticker_sound, true, STR_NULL, NULL), Darkvater@3116: SDTG_BOOL("fullscreen", S, 0, _fullscreen, false, STR_NULL, NULL), Darkvater@3116: SDTG_STR("videodriver", SLE_STRB,C|S,0, _ini_videodriver, NULL, STR_NULL, NULL), Darkvater@3116: SDTG_STR("musicdriver", SLE_STRB,C|S,0, _ini_musicdriver, NULL, STR_NULL, NULL), Darkvater@3116: SDTG_STR("sounddriver", SLE_STRB,C|S,0, _ini_sounddriver, NULL, STR_NULL, NULL), truelight@8063: SDTG_STR("blitter", SLE_STRB,C|S,0, _ini_blitter, NULL, STR_NULL, NULL), Darkvater@3116: SDTG_STR("language", SLE_STRB, S, 0, _dynlang.curr_file, NULL, STR_NULL, NULL), smatz@10983: SDTG_CONDLIST("resolution", SLE_INT, 2, S, 0, _cur_resolution, "640,480", STR_NULL, NULL, 0, SL_MAX_VERSION), // workaround for implicit lengthof() in SDTG_LIST Darkvater@3116: SDTG_STR("screenshot_format",SLE_STRB, S, 0, _screenshot_format_name,NULL, STR_NULL, NULL), Darkvater@3116: SDTG_STR("savegame_format", SLE_STRB, S, 0, _savegame_format, NULL, STR_NULL, NULL), Darkvater@3116: SDTG_BOOL("rightclick_emulate", S, 0, _rightclick_emulate, false, STR_NULL, NULL), peter1138@5108: #ifdef WITH_FREETYPE peter1138@5108: SDTG_STR("small_font", SLE_STRB, S, 0, _freetype.small_font, NULL, STR_NULL, NULL), peter1138@5108: SDTG_STR("medium_font", SLE_STRB, S, 0, _freetype.medium_font, NULL, STR_NULL, NULL), peter1138@5108: SDTG_STR("large_font", SLE_STRB, S, 0, _freetype.large_font, NULL, STR_NULL, NULL), peter1138@5108: SDTG_VAR("small_size", SLE_UINT, S, 0, _freetype.small_size, 6, 0, 72, 0, STR_NULL, NULL), peter1138@5108: SDTG_VAR("medium_size", SLE_UINT, S, 0, _freetype.medium_size, 10, 0, 72, 0, STR_NULL, NULL), peter1138@5108: SDTG_VAR("large_size", SLE_UINT, S, 0, _freetype.large_size, 16, 0, 72, 0, STR_NULL, NULL), peter1138@7409: SDTG_BOOL("small_aa", S, 0, _freetype.small_aa, false, STR_NULL, NULL), peter1138@7409: SDTG_BOOL("medium_aa", S, 0, _freetype.medium_aa, false, STR_NULL, NULL), peter1138@7409: SDTG_BOOL("large_aa", S, 0, _freetype.large_aa, false, STR_NULL, NULL), peter1138@5108: #endif truelight@7348: SDTG_VAR("sprite_cache_size",SLE_UINT, S, 0, _sprite_cache_size, 4, 1, 64, 0, STR_NULL, NULL), rubidium@8230: SDTG_VAR("player_face", SLE_UINT32, S, 0, _player_face, 0,0,0xFFFFFFFF,0, STR_NULL, NULL), smatz@9025: SDTG_VAR("transparency_options", SLE_UINT, S, 0, _transparency_opt, 0,0,0x1FF,0, STR_NULL, NULL), smatz@9025: SDTG_VAR("transparency_locks", SLE_UINT, S, 0, _transparency_lock, 0,0,0x1FF,0, STR_NULL, NULL), smatz@9302: SDTG_VAR("invisibility_options", SLE_UINT, S, 0, _invisibility_opt, 0,0, 0xFF,0, STR_NULL, NULL), rubidium@9233: SDTG_STR("keyboard", SLE_STRB, S, 0, _keyboard_opt[0], NULL, STR_NULL, NULL), rubidium@9233: SDTG_STR("keyboard_caps", SLE_STRB, S, 0, _keyboard_opt[1], NULL, STR_NULL, NULL), Darkvater@3116: SDTG_END() truelight@0: }; truelight@0: rubidium@10708: static const uint GAME_DIFFICULTY_NUM = 18; rubidium@10708: uint16 _old_diff_custom[GAME_DIFFICULTY_NUM]; rubidium@10708: Darkvater@3116: static const SettingDesc _gameopt_settings[] = { Darkvater@3116: /* In version 4 a new difficulty setting has been added to the difficulty settings, Darkvater@3116: * town attitude towards demolishing. Needs special handling because some dimwit thought Darkvater@3116: * it funny to have the GameDifficulty struct be an array while it is a struct of Darkvater@3116: * same-sized members Darkvater@3116: * XXX - To save file-space and since values are never bigger than about 10? only Darkvater@3116: * save the first 16 bits in the savegame. Question is why the values are still int32 smatz@8878: * and why not byte for example? smatz@8878: * 'SLE_FILE_I16 | SLE_VAR_U16' in "diff_custom" is needed to get around SlArray() hack smatz@8878: * for savegames version 0 - though it is an array, it has to go through the byteswap process */ rubidium@10708: SDTG_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_FILE_I16 | SLE_VAR_U16, C, 0, _old_diff_custom, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, 0, 3), rubidium@10708: SDTG_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_UINT16, C, 0, _old_diff_custom, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, 4, 96), rubidium@10708: rubidium@10775: SDT_VAR(GameSettings, difficulty.diff_level, SLE_UINT8, 0, 0, 0, 0, 3, 0, STR_NULL, NULL), rubidium@10835: SDT_OMANY(GameSettings, locale.currency, SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL), rubidium@10835: SDT_OMANY(GameSettings, locale.units, SLE_UINT8, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL, NULL), glx@7452: /* There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. */ rubidium@10775: SDT_OMANY(GameSettings, game_creation.town_name, SLE_UINT8, 0, 0, 0, 255, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL, NULL), rubidium@10775: SDT_OMANY(GameSettings, game_creation.landscape, SLE_UINT8, 0, 0, 0, 3, "temperate|arctic|tropic|toyland", STR_NULL, NULL, ConvertLandscape), rubidium@10775: SDT_VAR(GameSettings, game_creation.snow_line, SLE_UINT8, 0, 0, 7 * TILE_HEIGHT, 2 * TILE_HEIGHT, 13 * TILE_HEIGHT, 0, STR_NULL, NULL), rubidium@10786: SDT_CONDNULL( 1, 0, 22), rubidium@10775: SDTC_CONDOMANY( gui.autosave, SLE_UINT8, 23, SL_MAX_VERSION, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL), rubidium@10775: SDT_OMANY(GameSettings, vehicle.road_side, SLE_UINT8, 0, 0, 1, 1, "left|right", STR_NULL, NULL, NULL), Darkvater@3116: SDT_END() truelight@0: }; truelight@0: Darkvater@3116: /* Some patches do not need to be synchronised when playing in multiplayer. Darkvater@3116: * These include for example the GUI settings and will not be saved with the Darkvater@3116: * savegame. Darkvater@3116: * It is also a bit tricky since you would think that service_interval tron@4000: * for example doesn't need to be synched. Every client assigns the tron@4000: * service_interval value to the v->service_interval, meaning that every client tron@4000: * assigns his value. If the setting was player-based, that would mean that tron@4000: * vehicles could decide on different moments that they are heading back to a tron@4000: * service depot, causing desyncs on a massive scale. */ Darkvater@3116: const SettingDesc _patch_settings[] = { Darkvater@3116: /***************************************************************************/ rubidium@10703: /* Saved patch variables. */ rubidium@10708: /* Do not ADD or REMOVE something in this "difficulty.XXX" table or before it. It breaks savegame compatability. */ rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.max_no_competitors, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 2, 0, 7, 1, STR_NULL, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.competitor_start_time, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 2, 0, 3, 1, STR_6830_IMMEDIATE, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.number_towns, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 2, 0, 3, 1, STR_NUM_VERY_LOW, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.number_industries, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 4, 0, 4, 1, STR_NONE, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.max_loan, SLE_UINT32, 97, SL_MAX_VERSION, 0,NG|CR,300000,100000,500000,50000,STR_NULL, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.initial_interest, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 2, 2, 4, 1, STR_NULL, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.vehicle_costs, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 2, 1, STR_6820_LOW, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.competitor_speed, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 2, 0, 4, 1, STR_681B_VERY_SLOW, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.competitor_intelligence, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 2, 1, STR_6820_LOW, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.vehicle_breakdowns, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 1, 0, 2, 1, STR_6823_NONE, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.subsidy_multiplier, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 2, 0, 3, 1, STR_6826_X1_5, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.construction_cost, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 0, 0, 2, 1, STR_6820_LOW, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.terrain_type, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 1, 0, 3, 1, STR_682A_VERY_FLAT, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.quantity_sea_lakes, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 0, 0, 3, 1, STR_VERY_LOW, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.economy, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 1, 1, STR_682E_STEADY, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.line_reverse_mode, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 1, 1, STR_6834_AT_END_OF_LINE_AND_AT_STATIONS, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.disasters, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 1, 1, STR_6836_OFF, DifficultyChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.town_council_tolerance, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 2, 1, STR_PERMISSIVE, DifficultyNoiseChange), rubidium@10775: SDT_CONDVAR(GameSettings, difficulty.diff_level, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 0, 0, 3, 0, STR_NULL, DifficultyReset), rubidium@10708: rubidium@10708: /* There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. */ rubidium@10775: SDT_CONDOMANY(GameSettings, game_creation.town_name, SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 0, 255, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL, NULL), rubidium@10775: SDT_CONDOMANY(GameSettings, game_creation.landscape, SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 0, 3, "temperate|arctic|tropic|toyland", STR_NULL, NULL, ConvertLandscape), rubidium@10775: SDT_CONDVAR(GameSettings, game_creation.snow_line, SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 7 * TILE_HEIGHT, 2 * TILE_HEIGHT, 13 * TILE_HEIGHT, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDOMANY(GameSettings, vehicle.road_side, SLE_UINT8, 97, SL_MAX_VERSION, 0,NN, 1, 1, "left|right", STR_NULL, NULL, NULL), rubidium@10703: rubidium@10775: SDT_BOOL(GameSettings, construction.build_on_slopes, 0,NN, true, STR_CONFIG_PATCHES_BUILDONSLOPES, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, construction.autoslope, 75, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_AUTOSLOPE, NULL), rubidium@10775: SDT_BOOL(GameSettings, construction.extra_dynamite, 0, 0, false, STR_CONFIG_PATCHES_EXTRADYNAMITE, NULL), rubidium@10775: SDT_BOOL(GameSettings, construction.longbridges, 0,NN, true, STR_CONFIG_PATCHES_LONGBRIDGES, NULL), rubidium@10775: SDT_BOOL(GameSettings, construction.signal_side, N,NN, true, STR_CONFIG_PATCHES_SIGNALSIDE, RedrawScreen), rubidium@10775: SDT_BOOL(GameSettings, station.always_small_airport, 0,NN, false, STR_CONFIG_PATCHES_SMALL_AIRPORTS, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, economy.town_layout, SLE_UINT8, 59, SL_MAX_VERSION, 0,MS,TL_ORIGINAL,TL_NO_ROADS,NUM_TLS-1,1, STR_CONFIG_PATCHES_TOWN_LAYOUT, CheckTownLayout), rubidium@10703: rubidium@10775: SDT_BOOL(GameSettings, vehicle.realistic_acceleration, 0, 0, false, STR_CONFIG_PATCHES_REALISTICACCEL, RealisticAccelerationChanged), rubidium@10775: SDT_BOOL(GameSettings, pf.forbid_90_deg, 0, 0, false, STR_CONFIG_PATCHES_FORBID_90_DEG, NULL), rubidium@10775: SDT_BOOL(GameSettings, vehicle.mammoth_trains, 0,NN, true, STR_CONFIG_PATCHES_MAMMOTHTRAINS, NULL), rubidium@10775: SDT_BOOL(GameSettings, order.gotodepot, 0, 0, true, STR_CONFIG_PATCHES_GOTODEPOT, NULL), rubidium@10775: SDT_BOOL(GameSettings, pf.roadveh_queue, 0, 0, true, STR_CONFIG_PATCHES_ROADVEH_QUEUE, NULL), rubidium@10703: rubidium@10775: SDT_CONDBOOL(GameSettings, pf.new_pathfinding_all, 0, 86, 0, 0, false, STR_NULL, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, pf.yapf.ship_use_yapf, 28, 86, 0, 0, false, STR_NULL, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, pf.yapf.road_use_yapf, 28, 86, 0, 0, true, STR_NULL, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, pf.yapf.rail_use_yapf, 28, 86, 0, 0, true, STR_NULL, NULL), rubidium@10703: rubidium@10775: SDT_CONDVAR(GameSettings, pf.pathfinder_for_trains, SLE_UINT8, 87, SL_MAX_VERSION, 0, MS, 2, 0, 2, 1, STR_CONFIG_PATCHES_PATHFINDER_FOR_TRAINS, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.pathfinder_for_roadvehs, SLE_UINT8, 87, SL_MAX_VERSION, 0, MS, 2, 0, 2, 1, STR_CONFIG_PATCHES_PATHFINDER_FOR_ROADVEH, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.pathfinder_for_ships, SLE_UINT8, 87, SL_MAX_VERSION, 0, MS, 0, 0, 2, 1, STR_CONFIG_PATCHES_PATHFINDER_FOR_SHIPS, NULL), rubidium@10703: rubidium@10775: SDT_BOOL(GameSettings, vehicle.never_expire_vehicles, 0,NN, false, STR_CONFIG_PATCHES_NEVER_EXPIRE_VEHICLES, NULL), rubidium@10775: SDT_VAR(GameSettings, vehicle.max_trains, SLE_UINT16, 0, 0, 500, 0, 5000, 0, STR_CONFIG_PATCHES_MAX_TRAINS, RedrawScreen), rubidium@10775: SDT_VAR(GameSettings, vehicle.max_roadveh, SLE_UINT16, 0, 0, 500, 0, 5000, 0, STR_CONFIG_PATCHES_MAX_ROADVEH, RedrawScreen), rubidium@10775: SDT_VAR(GameSettings, vehicle.max_aircraft, SLE_UINT16, 0, 0, 200, 0, 5000, 0, STR_CONFIG_PATCHES_MAX_AIRCRAFT, RedrawScreen), rubidium@10775: SDT_VAR(GameSettings, vehicle.max_ships, SLE_UINT16, 0, 0, 300, 0, 5000, 0, STR_CONFIG_PATCHES_MAX_SHIPS, RedrawScreen), rubidium@10775: SDT_BOOL(GameSettings, vehicle.servint_ispercent, 0, 0, false, STR_CONFIG_PATCHES_SERVINT_ISPERCENT, CheckInterval), rubidium@10775: SDT_VAR(GameSettings, vehicle.servint_trains, SLE_UINT16, 0,D0, 150, 5, 800, 0, STR_CONFIG_PATCHES_SERVINT_TRAINS, InValidateDetailsWindow), rubidium@10775: SDT_VAR(GameSettings, vehicle.servint_roadveh, SLE_UINT16, 0,D0, 150, 5, 800, 0, STR_CONFIG_PATCHES_SERVINT_ROADVEH, InValidateDetailsWindow), rubidium@10775: SDT_VAR(GameSettings, vehicle.servint_ships, SLE_UINT16, 0,D0, 360, 5, 800, 0, STR_CONFIG_PATCHES_SERVINT_SHIPS, InValidateDetailsWindow), rubidium@10775: SDT_VAR(GameSettings, vehicle.servint_aircraft, SLE_UINT16, 0,D0, 100, 5, 800, 0, STR_CONFIG_PATCHES_SERVINT_AIRCRAFT, InValidateDetailsWindow), rubidium@10775: SDT_BOOL(GameSettings, order.no_servicing_if_no_breakdowns, 0, 0, false, STR_CONFIG_PATCHES_NOSERVICE, NULL), rubidium@10775: SDT_BOOL(GameSettings, vehicle.wagon_speed_limits, 0,NN, true, STR_CONFIG_PATCHES_WAGONSPEEDLIMITS, UpdateConsists), rubidium@10775: SDT_CONDBOOL(GameSettings, vehicle.disable_elrails, 38, SL_MAX_VERSION, 0,NN, false, STR_CONFIG_PATCHES_DISABLE_ELRAILS, SettingsDisableElrail), rubidium@10775: SDT_CONDVAR(GameSettings, vehicle.freight_trains, SLE_UINT8, 39, SL_MAX_VERSION, 0,NN, 1, 1, 255, 1, STR_CONFIG_PATCHES_FREIGHT_TRAINS, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, order.timetabling, 67, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_TIMETABLE_ALLOW, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, vehicle.plane_speed, SLE_UINT8, 90, SL_MAX_VERSION, 0, 0, 4, 1, 4, 0, STR_CONFIG_PATCHES_PLANE_SPEED, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, vehicle.dynamic_engines, 95, SL_MAX_VERSION, 0,NN, false, STR_CONFIG_PATCHES_DYNAMIC_ENGINES, NULL), rubidium@10775: rubidium@10775: SDT_BOOL(GameSettings, station.join_stations, 0, 0, true, STR_CONFIG_PATCHES_JOINSTATIONS, NULL), rubidium@10775: SDTC_CONDBOOL( gui.sg_full_load_any, 0, 92, 0, 0 , true, STR_NULL, NULL), rubidium@10775: SDT_BOOL(GameSettings, order.improved_load, 0,NN, true, STR_CONFIG_PATCHES_IMPROVEDLOAD, NULL), rubidium@10775: SDT_BOOL(GameSettings, order.selectgoods, 0, 0, true, STR_CONFIG_PATCHES_SELECTGOODS, NULL), rubidium@10775: SDTC_CONDBOOL( gui.sg_new_nonstop, 0, 92, 0, 0, false, STR_NULL, NULL), rubidium@10775: SDT_BOOL(GameSettings, station.nonuniform_stations, 0,NN, true, STR_CONFIG_PATCHES_NONUNIFORM_STATIONS, NULL), rubidium@10775: SDT_VAR(GameSettings, station.station_spread, SLE_UINT8, 0, 0, 12, 4, 64, 0, STR_CONFIG_PATCHES_STATION_SPREAD, InvalidateStationBuildWindow), rubidium@10775: SDT_BOOL(GameSettings, order.serviceathelipad, 0, 0, true, STR_CONFIG_PATCHES_SERVICEATHELIPAD, NULL), rubidium@10775: SDT_BOOL(GameSettings, station.modified_catchment, 0, 0, true, STR_CONFIG_PATCHES_CATCHMENT, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, order.gradual_loading, 40, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_GRADUAL_LOADING, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, construction.road_stop_on_town_road, 47, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_STOP_ON_TOWN_ROAD, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, station.adjacent_stations, 62, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_ADJACENT_STATIONS, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, economy.station_noise_level, 96, SL_MAX_VERSION, 0, 0, false, STR_CONFIG_PATCHES_NOISE_LEVEL, InvalidateTownViewWindow), rubidium@10775: rubidium@10775: SDT_BOOL(GameSettings, economy.inflation, 0, 0, true, STR_CONFIG_PATCHES_INFLATION, NULL), rubidium@10775: SDT_VAR(GameSettings, construction.raw_industry_construction, SLE_UINT8, 0,MS, 0, 0, 2, 0, STR_CONFIG_PATCHES_RAW_INDUSTRY_CONSTRUCTION_METHOD, InvalidateBuildIndustryWindow), rubidium@10775: SDT_BOOL(GameSettings, economy.multiple_industry_per_town, 0, 0, false, STR_CONFIG_PATCHES_MULTIPINDTOWN, NULL), rubidium@10775: SDT_BOOL(GameSettings, economy.same_industry_close, 0, 0, false, STR_CONFIG_PATCHES_SAMEINDCLOSE, NULL), rubidium@10775: SDT_BOOL(GameSettings, economy.bribe, 0, 0, true, STR_CONFIG_PATCHES_BRIBE, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, economy.exclusive_rights, 79, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_ALLOW_EXCLUSIVE, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, economy.give_money, 79, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_ALLOW_GIVE_MONEY, NULL), rubidium@10775: SDT_VAR(GameSettings, game_creation.snow_line_height, SLE_UINT8, 0, 0, 7, 2, 13, 0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT, NULL), rubidium@10775: SDTC_VAR( gui.colored_news_year, SLE_INT32, 0,NC, 2000,MIN_YEAR,MAX_YEAR,1,STR_CONFIG_PATCHES_COLORED_NEWS_YEAR, NULL), rubidium@10775: SDT_VAR(GameSettings, game_creation.starting_year, SLE_INT32, 0,NC, 1950,MIN_YEAR,MAX_YEAR,1,STR_CONFIG_PATCHES_STARTING_YEAR, NULL), rubidium@10775: SDTC_VAR( gui.ending_year, SLE_INT32, 0,NC|NO,2051,MIN_YEAR,MAX_YEAR,1,STR_CONFIG_PATCHES_ENDING_YEAR, NULL), rubidium@10775: SDT_BOOL(GameSettings, economy.smooth_economy, 0, 0, true, STR_CONFIG_PATCHES_SMOOTH_ECONOMY, NULL), rubidium@10775: SDT_BOOL(GameSettings, economy.allow_shares, 0, 0, false, STR_CONFIG_PATCHES_ALLOW_SHARES, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, economy.town_growth_rate, SLE_UINT8, 54, SL_MAX_VERSION, 0, MS, 2, 0, 4, 0, STR_CONFIG_PATCHES_TOWN_GROWTH, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, economy.larger_towns, SLE_UINT8, 54, SL_MAX_VERSION, 0, D0, 4, 0, 255, 1, STR_CONFIG_PATCHES_LARGER_TOWNS, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, economy.initial_city_size, SLE_UINT8, 56, SL_MAX_VERSION, 0, 0, 2, 1, 10, 1, STR_CONFIG_PATCHES_CITY_SIZE_MULTIPLIER, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, economy.mod_road_rebuild, 77, SL_MAX_VERSION, 0, 0, false, STR_CONFIG_MODIFIED_ROAD_REBUILD, NULL), rubidium@10775: rubidium@10775: SDT_BOOL(GameSettings, ai.ainew_active, 0, 0, false, STR_CONFIG_PATCHES_AINEW_ACTIVE, AiNew_PatchActive_Warning), rubidium@10775: SDT_BOOL(GameSettings, ai.ai_in_multiplayer, 0, 0, false, STR_CONFIG_PATCHES_AI_IN_MULTIPLAYER, Ai_In_Multiplayer_Warning), rubidium@10775: SDT_BOOL(GameSettings, ai.ai_disable_veh_train, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_TRAINS, NULL), rubidium@10775: SDT_BOOL(GameSettings, ai.ai_disable_veh_roadveh, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_ROADVEH, NULL), rubidium@10775: SDT_BOOL(GameSettings, ai.ai_disable_veh_aircraft, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_AIRCRAFT, NULL), rubidium@10775: SDT_BOOL(GameSettings, ai.ai_disable_veh_ship, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_SHIPS, NULL), rubidium@10775: rubidium@10775: SDT_VAR(GameSettings, vehicle.extend_vehicle_life, SLE_UINT8, 0, 0, 0, 0, 100, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, economy.dist_local_authority, SLE_UINT8, 0, 0, 20, 5, 60, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.wait_oneway_signal, SLE_UINT8, 0, 0, 15, 2, 100, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.wait_twoway_signal, SLE_UINT8, 0, 0, 41, 2, 100, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDLISTO(GameSettings, economy.town_noise_population, 3, SLE_UINT16, 96, SL_MAX_VERSION, 0,D0, "800,2000,4000", STR_NULL, NULL, CheckNoiseToleranceLevel), rubidium@10775: rubidium@10775: SDT_VAR(GameSettings, pf.opf.pf_maxlength, SLE_UINT16, 0, 0, 4096, 64, 65535, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.opf.pf_maxdepth, SLE_UINT8, 0, 0, 48, 4, 255, 0, STR_NULL, NULL), rubidium@10775: rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_max_search_nodes, SLE_UINT, 0, 0, 10000, 500, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_rail_firstred_penalty, SLE_UINT, 0, 0, ( 10 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_rail_firstred_exit_penalty, SLE_UINT, 0, 0, (100 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_rail_lastred_penalty, SLE_UINT, 0, 0, ( 10 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_rail_station_penalty, SLE_UINT, 0, 0, ( 1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_rail_slope_penalty, SLE_UINT, 0, 0, ( 1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_rail_curve_penalty, SLE_UINT, 0, 0, 1, 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_rail_depot_reverse_penalty, SLE_UINT, 0, 0, ( 50 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_buoy_penalty, SLE_UINT, 0, 0, ( 2 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_water_curve_penalty, SLE_UINT, 0, 0, (NPF_TILE_LENGTH / 4), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_road_curve_penalty, SLE_UINT, 0, 0, 1, 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_VAR(GameSettings, pf.npf.npf_crossing_penalty, SLE_UINT, 0, 0, ( 3 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.npf.npf_road_drive_through_penalty, SLE_UINT, 47, SL_MAX_VERSION, 0, 0, ( 8 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL), rubidium@10703: rubidium@10703: rubidium@10775: SDT_CONDBOOL(GameSettings, pf.yapf.disable_node_optimization, 28, SL_MAX_VERSION, 0, 0, false, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.max_search_nodes, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10000, 500, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDBOOL(GameSettings, pf.yapf.rail_firstred_twoway_eol, 28, SL_MAX_VERSION, 0, 0, true, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_firstred_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_firstred_exit_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 100 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_lastred_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_lastred_exit_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 100 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_station_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 30 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_slope_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 2 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_curve45_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 1 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_curve90_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 6 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_depot_reverse_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 50 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_crossing_penalty, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 3 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_look_ahead_max_signals, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10, 1, 100, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_look_ahead_signal_p0, SLE_INT, 28, SL_MAX_VERSION, 0, 0, 500, -1000000, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_look_ahead_signal_p1, SLE_INT, 28, SL_MAX_VERSION, 0, 0, -100, -1000000, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_look_ahead_signal_p2, SLE_INT, 28, SL_MAX_VERSION, 0, 0, 5, -1000000, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_longer_platform_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 8 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_longer_platform_per_tile_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 0 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_shorter_platform_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 40 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.rail_shorter_platform_per_tile_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 0 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.road_slope_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 2 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.road_curve_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 1 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.road_crossing_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 3 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, pf.yapf.road_stop_penalty, SLE_UINT, 47, SL_MAX_VERSION, 0, 0, 8 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL), rubidium@10703: rubidium@10775: SDT_CONDVAR(GameSettings, game_creation.land_generator, SLE_UINT8, 30, SL_MAX_VERSION, 0,MS, 1, 0, 1, 0, STR_CONFIG_PATCHES_LAND_GENERATOR, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, game_creation.oil_refinery_limit, SLE_UINT8, 30, SL_MAX_VERSION, 0, 0, 32, 12, 48, 0, STR_CONFIG_PATCHES_OIL_REF_EDGE_DISTANCE, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, game_creation.tgen_smoothness, SLE_UINT8, 30, SL_MAX_VERSION, 0,MS, 1, 0, 3, 0, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, game_creation.generation_seed, SLE_UINT32, 30, SL_MAX_VERSION, 0, 0, GENERATE_NEW_SEED, 0, UINT32_MAX, 0, STR_NULL, NULL), rubidium@10775: SDT_CONDVAR(GameSettings, game_creation.tree_placer, SLE_UINT8, 30, SL_MAX_VERSION, 0,MS, 2, 0, 2, 0, STR_CONFIG_PATCHES_TREE_PLACER, NULL), rubidium@10775: SDT_VAR(GameSettings, game_creation.heightmap_rotation, SLE_UINT8, S,MS, 0, 0, 1, 0, STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION, NULL), rubidium@10775: SDT_VAR(GameSettings, game_creation.se_flat_world_height, SLE_UINT8, S, 0, 0, 0, 15, 0, STR_CONFIG_PATCHES_SE_FLAT_WORLD_HEIGHT, NULL), tron@1218: rubidium@10775: SDT_VAR(GameSettings, game_creation.map_x, SLE_UINT8, S, 0, 8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_X, NULL), rubidium@10775: SDT_VAR(GameSettings, game_creation.map_y, SLE_UINT8, S, 0, 8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_Y, NULL), rubidium@10775: rubidium@10835: SDT_CONDOMANY(GameSettings, locale.currency, SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL), rubidium@10835: SDT_CONDOMANY(GameSettings, locale.units, SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL, NULL), rubidium@10708: Darkvater@3116: /***************************************************************************/ rubidium@10703: /* Unsaved patch variables. */ rubidium@10790: SDTC_OMANY(gui.autosave, SLE_UINT8, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL), rubidium@10790: SDTC_BOOL(gui.vehicle_speed, S, 0, true, STR_CONFIG_PATCHES_VEHICLESPEED, NULL), rubidium@10790: SDTC_BOOL(gui.status_long_date, S, 0, true, STR_CONFIG_PATCHES_LONGDATE, NULL), rubidium@10790: SDTC_BOOL(gui.show_finances, S, 0, true, STR_CONFIG_PATCHES_SHOWFINANCES, NULL), rubidium@10790: SDTC_BOOL(gui.autoscroll, S, 0, false, STR_CONFIG_PATCHES_AUTOSCROLL, NULL), rubidium@10790: SDTC_BOOL(gui.reverse_scroll, S, 0, false, STR_CONFIG_PATCHES_REVERSE_SCROLLING, NULL), rubidium@10790: SDTC_BOOL(gui.smooth_scroll, S, 0, false, STR_CONFIG_PATCHES_SMOOTH_SCROLLING, NULL), rubidium@10790: SDTC_BOOL(gui.measure_tooltip, S, 0, false, STR_CONFIG_PATCHES_MEASURE_TOOLTIP, NULL), rubidium@10790: SDTC_VAR(gui.errmsg_duration, SLE_UINT8, S, 0, 5, 0, 20, 0, STR_CONFIG_PATCHES_ERRMSG_DURATION, NULL), rubidium@10790: SDTC_VAR(gui.toolbar_pos, SLE_UINT8, S, MS, 0, 0, 2, 0, STR_CONFIG_PATCHES_TOOLBAR_POS, v_PositionMainToolbar), rubidium@10790: SDTC_VAR(gui.window_snap_radius, SLE_UINT8, S, D0, 10, 1, 32, 0, STR_CONFIG_PATCHES_SNAP_RADIUS, NULL), rubidium@10790: SDTC_BOOL(gui.population_in_label, S, 0, true, STR_CONFIG_PATCHES_POPULATION_IN_LABEL, PopulationInLabelActive), rubidium@10790: SDTC_BOOL(gui.link_terraform_toolbar, S, 0, false, STR_CONFIG_PATCHES_LINK_TERRAFORM_TOOLBAR, NULL), rubidium@10790: SDTC_VAR(gui.liveries, SLE_UINT8, S, MS, 2, 0, 2, 0, STR_CONFIG_PATCHES_LIVERIES, RedrawScreen), rubidium@10790: SDTC_BOOL(gui.prefer_teamchat, S, 0, false, STR_CONFIG_PATCHES_PREFER_TEAMCHAT, NULL), rubidium@10790: SDTC_VAR(gui.scrollwheel_scrolling, SLE_UINT8, S, MS, 0, 0, 2, 0, STR_CONFIG_PATCHES_SCROLLWHEEL_SCROLLING, NULL), rubidium@10790: SDTC_VAR(gui.scrollwheel_multiplier, SLE_UINT8, S, 0, 5, 1, 15, 1, STR_CONFIG_PATCHES_SCROLLWHEEL_MULTIPLIER, NULL), rubidium@10790: SDTC_BOOL(gui.pause_on_newgame, S, 0, false, STR_CONFIG_PATCHES_PAUSE_ON_NEW_GAME, NULL), rubidium@10790: SDTC_VAR(gui.advanced_vehicle_list, SLE_UINT8, S, MS, 1, 0, 2, 0, STR_CONFIG_PATCHES_ADVANCED_VEHICLE_LISTS, NULL), rubidium@10790: SDTC_BOOL(gui.timetable_in_ticks, S, 0, false, STR_CONFIG_PATCHES_TIMETABLE_IN_TICKS, NULL), rubidium@10790: SDTC_VAR(gui.loading_indicators, SLE_UINT8, S, MS, 1, 0, 2, 0, STR_CONFIG_PATCHES_LOADING_INDICATORS, RedrawScreen), rubidium@10790: SDTC_VAR(gui.default_rail_type, SLE_UINT8, S, MS, 4, 0, 6, 0, STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE, NULL), rubidium@10790: SDTC_BOOL(gui.enable_signal_gui, S, 0, false, STR_CONFIG_PATCHES_ENABLE_SIGNAL_GUI, CloseSignalGUI), rubidium@10790: SDTC_VAR(gui.drag_signals_density, SLE_UINT8, S, 0, 4, 1, 20, 0, STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY, DragSignalsDensityChanged), rubidium@10790: SDTC_VAR(gui.semaphore_build_before, SLE_INT32, S, NC, 1975, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_SEMAPHORE_BUILD_BEFORE_DATE, ResetSignalVariant), rubidium@10790: SDTC_BOOL(gui.train_income_warn, S, 0, true, STR_CONFIG_PATCHES_WARN_INCOME_LESS, NULL), rubidium@10790: SDTC_VAR(gui.order_review_system, SLE_UINT8, S, MS, 2, 0, 2, 0, STR_CONFIG_PATCHES_ORDER_REVIEW, NULL), rubidium@10790: SDTC_BOOL(gui.lost_train_warn, S, 0, true, STR_CONFIG_PATCHES_WARN_LOST_TRAIN, NULL), rubidium@10790: SDTC_BOOL(gui.autorenew, S, 0, false, STR_CONFIG_PATCHES_AUTORENEW_VEHICLE, EngineRenewUpdate), rubidium@10790: SDTC_VAR(gui.autorenew_months, SLE_INT16, S, 0, 6, -12, 12, 0, STR_CONFIG_PATCHES_AUTORENEW_MONTHS, EngineRenewMonthsUpdate), rubidium@10790: SDTC_VAR(gui.autorenew_money, SLE_UINT, S, CR,100000, 0, 2000000, 0, STR_CONFIG_PATCHES_AUTORENEW_MONEY, EngineRenewMoneyUpdate), rubidium@10790: SDTC_BOOL(gui.always_build_infrastructure, S, 0, false, STR_CONFIG_PATCHES_ALWAYS_BUILD_INFRASTRUCTURE, RedrawScreen), rubidium@10790: SDTC_BOOL(gui.new_nonstop, S, 0, false, STR_CONFIG_PATCHES_NEW_NONSTOP, NULL), rubidium@10790: SDTC_BOOL(gui.keep_all_autosave, S, 0, false, STR_NULL, NULL), rubidium@10790: SDTC_BOOL(gui.autosave_on_exit, S, 0, false, STR_NULL, NULL), rubidium@10790: SDTC_VAR(gui.max_num_autosaves, SLE_UINT8, S, 0, 16, 0, 255, 0, STR_NULL, NULL), rubidium@10790: SDTC_BOOL(gui.bridge_pillars, S, 0, true, STR_NULL, NULL), rubidium@10790: SDTC_BOOL(gui.auto_euro, S, 0, true, STR_NULL, NULL), rubidium@10790: SDTC_VAR(gui.news_message_timeout, SLE_UINT8, S, 0, 2, 1, 255, 0, STR_NULL, NULL), rubidium@10790: rubidium@10790: #ifdef ENABLE_NETWORK rubidium@10790: SDTC_VAR(network.sync_freq, SLE_UINT16,C|S,NO, 100, 0, 100, 0, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.frame_freq, SLE_UINT8,C|S,NO, 0, 0, 100, 0, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.max_join_time, SLE_UINT16, S, NO, 500, 0, 32000, 0, STR_NULL, NULL), rubidium@10790: SDTC_BOOL(network.pause_on_join, S, NO, true, STR_NULL, NULL), rubidium@10790: SDTC_STR(network.server_bind_ip, SLE_STRB, S, NO, "0.0.0.0", STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.server_port, SLE_UINT16, S, NO,NETWORK_DEFAULT_PORT,0,65535,0,STR_NULL, NULL), rubidium@10790: SDTC_BOOL(network.server_advertise, S, NO, false, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.lan_internet, SLE_UINT8, S, NO, 0, 0, 1, 0, STR_NULL, NULL), rubidium@10790: SDTC_STR(network.player_name, SLE_STRB, S, 0, NULL, STR_NULL, UpdatePlayerName), rubidium@10790: SDTC_STR(network.server_password, SLE_STRB, S, NO, NULL, STR_NULL, UpdateServerPassword), rubidium@10790: SDTC_STR(network.rcon_password, SLE_STRB, S, NO, NULL, STR_NULL, UpdateRconPassword), rubidium@10790: SDTC_STR(network.default_company_pass, SLE_STRB, S, 0, NULL, STR_NULL, NULL), rubidium@10818: SDTC_STR(network.server_name, SLE_STRB, S, NO, NULL, STR_NULL, NULL), rubidium@10790: SDTC_STR(network.connect_to_ip, SLE_STRB, S, 0, NULL, STR_NULL, NULL), rubidium@10790: SDTC_STR(network.network_id, SLE_STRB, S, NO, NULL, STR_NULL, NULL), rubidium@10790: SDTC_BOOL(network.autoclean_companies, S, NO, false, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.autoclean_unprotected, SLE_UINT8, S, NO, 12, 0, 60, 0, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.autoclean_protected, SLE_UINT8, S, NO, 36, 0, 180, 0, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.max_companies, SLE_UINT8, S, NO, 8, 1, MAX_PLAYERS, 0, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.max_clients, SLE_UINT8, S, NO, 10, 2, MAX_CLIENTS, 0, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.max_spectators, SLE_UINT8, S, NO, 10, 0, MAX_CLIENTS, 0, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.restart_game_year, SLE_INT32, S,D0|NO|NC,0, MIN_YEAR, MAX_YEAR, 1, STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.min_players, SLE_UINT8, S, NO, 0, 0, 10, 0, STR_NULL, UpdateMinPlayers), rubidium@10790: SDTC_OMANY(network.server_lang, SLE_UINT8, S, NO, 0, 35, "ANY|ENGLISH|GERMAN|FRENCH|BRAZILIAN|BULGARIAN|CHINESE|CZECH|DANISH|DUTCH|ESPERANTO|FINNISH|HUNGARIAN|ICELANDIC|ITALIAN|JAPANESE|KOREAN|LITHUANIAN|NORWEGIAN|POLISH|PORTUGUESE|ROMANIAN|RUSSIAN|SLOVAK|SLOVENIAN|SPANISH|SWEDISH|TURKISH|UKRAINIAN|AFRIKAANS|CROATIAN|CATALAN|ESTONIAN|GALICIAN|GREEK|LATVIAN", STR_NULL, NULL), rubidium@10790: SDTC_BOOL(network.reload_cfg, S, NO, false, STR_NULL, NULL), rubidium@10790: SDTC_STR(network.last_host, SLE_STRB, S, 0, "0.0.0.0", STR_NULL, NULL), rubidium@10790: SDTC_VAR(network.last_port, SLE_UINT16, S, 0, 0, 0, UINT16_MAX, 0, STR_NULL, NULL), rubidium@10790: #endif /* ENABLE_NETWORK */ truelight@4300: egladil@8625: /* egladil@8625: * Since the network code (CmdChangePatchSetting and friends) use the index in this array to decide egladil@8625: * which patch the server is talking about all conditional compilation of this array must be at the egladil@8625: * end. This isn't really the best solution, the patches the server can tell the client about should egladil@8625: * either use a seperate array or some other form of identifier. egladil@8625: */ egladil@8625: egladil@8625: #ifdef __APPLE__ egladil@8625: /* We might need to emulate a right mouse button on mac */ rubidium@10775: SDTC_VAR(gui.right_mouse_btn_emulation, SLE_UINT8, S, MS, 0, 0, 2, 0, STR_CONFIG_PATCHES_RIGHT_MOUSE_BTN_EMU, NULL), egladil@8625: #endif egladil@8625: Darkvater@3116: SDT_END() truelight@543: }; truelight@543: Darkvater@3116: static const SettingDesc _currency_settings[] = { rubidium@4431: SDT_VAR(CurrencySpec, rate, SLE_UINT16, S, 0, 1, 0, 100, 0, STR_NULL, NULL), rubidium@4431: SDT_CHR(CurrencySpec, separator, S, 0, ".", STR_NULL, NULL), rubidium@6987: SDT_VAR(CurrencySpec, to_euro, SLE_INT32, S, 0, 0, 0, 3000, 0, STR_NULL, NULL), rubidium@4431: SDT_STR(CurrencySpec, prefix, SLE_STRBQ, S, 0, NULL, STR_NULL, NULL), rubidium@4431: SDT_STR(CurrencySpec, suffix, SLE_STRBQ, S, 0, " credits", STR_NULL, NULL), Darkvater@3116: SDT_END() dominik@759: }; dominik@759: Darkvater@3116: /* Undefine for the shortcut macros above */ Darkvater@3116: #undef S Darkvater@3116: #undef C Darkvater@3116: #undef N Darkvater@3116: Darkvater@3116: #undef D0 Darkvater@3116: #undef NC Darkvater@3116: #undef MS Darkvater@3116: #undef NO Darkvater@3116: #undef CR Darkvater@3116: rubidium@10759: /** rubidium@10759: * Prepare for reading and old diff_custom by zero-ing the memory. rubidium@10759: */ rubidium@10708: static void PrepareOldDiffCustom() rubidium@10708: { rubidium@10708: memset(_old_diff_custom, 0, sizeof(_old_diff_custom)); rubidium@10708: } rubidium@10708: rubidium@10759: /** rubidium@10759: * Reading of the old diff_custom array and transforming it to the new format. rubidium@10759: * @param savegame is it read from the config or savegame. In the latter case rubidium@10759: * we are sure there is an array; in the former case we have rubidium@10759: * to check that. rubidium@10759: */ rubidium@10759: static void HandleOldDiffCustom(bool savegame) rubidium@10708: { rubidium@10759: uint options_to_load = GAME_DIFFICULTY_NUM - ((savegame && CheckSavegameVersion(4)) ? 1 : 0); rubidium@10708: rubidium@10759: if (!savegame) { rubidium@10759: /* If we did read to old_diff_custom, then at least one value must be non 0. */ rubidium@10759: bool old_diff_custom_used = false; rubidium@10759: for (uint i = 0; i < options_to_load && !old_diff_custom_used; i++) { rubidium@10759: old_diff_custom_used = (_old_diff_custom[i] != 0); rubidium@10759: } rubidium@10759: rubidium@10759: if (!old_diff_custom_used) return; rubidium@10708: } rubidium@10708: rubidium@10708: for (uint i = 0; i < options_to_load; i++) { rubidium@10708: const SettingDesc *sd = &_patch_settings[i]; rubidium@10775: void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save); rubidium@10708: Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i])); rubidium@10708: } rubidium@10708: } rubidium@10708: rubidium@10708: rubidium@10273: static void NewsDisplayLoadConfig(IniFile *ini, const char *grpname) truelight@6609: { glx@10471: IniGroup *group = ini_getgroup(ini, grpname); truelight@6609: IniItem *item; truelight@6609: rubidium@10273: /* If no group exists, return */ rubidium@10273: if (group == NULL) return; truelight@6609: truelight@6609: for (item = group->item; item != NULL; item = item->next) { truelight@6609: int news_item = -1; truelight@6609: for (int i = 0; i < NT_END; i++) { rubidium@10253: if (strcasecmp(item->name, _news_type_data[i].name) == 0) { truelight@6609: news_item = i; truelight@6609: break; truelight@6609: } truelight@6609: } truelight@6609: if (news_item == -1) { truelight@6609: DEBUG(misc, 0, "Invalid display option: %s", item->name); truelight@6609: continue; truelight@6609: } truelight@6609: truelight@6609: if (strcasecmp(item->value, "full") == 0) { rubidium@10273: _news_type_data[news_item].display = ND_FULL; truelight@6609: } else if (strcasecmp(item->value, "off") == 0) { rubidium@10273: _news_type_data[news_item].display = ND_OFF; truelight@6609: } else if (strcasecmp(item->value, "summarized") == 0) { rubidium@10273: _news_type_data[news_item].display = ND_SUMMARY; truelight@6609: } else { truelight@6609: DEBUG(misc, 0, "Invalid display value: %s", item->value); truelight@6609: continue; truelight@6609: } truelight@6609: } truelight@6609: } Darkvater@3628: peter1138@5329: /* Load a GRF configuration from the given group name */ peter1138@5329: static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static) peter1138@5329: { glx@10471: IniGroup *group = ini_getgroup(ini, grpname); peter1138@5329: IniItem *item; peter1138@5329: GRFConfig *first = NULL; peter1138@5329: GRFConfig **curr = &first; Darkvater@3628: peter1138@5329: if (group == NULL) return NULL; peter1138@5329: peter1138@5329: for (item = group->item; item != NULL; item = item->next) { KUDr@5860: GRFConfig *c = CallocT(1); rubidium@7530: c->filename = strdup(item->name); peter1138@5329: peter1138@5329: /* Parse parameters */ peter1138@5329: if (*item->value != '\0') { peter1138@5329: c->num_params = parse_intlist(item->value, (int*)c->param, lengthof(c->param)); peter1138@5329: if (c->num_params == (byte)-1) { peter1138@5329: ShowInfoF("ini: error in array '%s'", item->name); peter1138@5329: c->num_params = 0; peter1138@5329: } peter1138@5329: } peter1138@5329: peter1138@5329: /* Check if item is valid */ peter1138@5329: if (!FillGRFDetails(c, is_static)) { peter1138@5329: const char *msg; peter1138@5329: maedhros@6555: if (c->status == GCS_NOT_FOUND) { peter1138@5329: msg = "not found"; skidd13@8424: } else if (HasBit(c->flags, GCF_UNSAFE)) { peter1138@5329: msg = "unsafe for static use"; skidd13@8424: } else if (HasBit(c->flags, GCF_SYSTEM)) { peter1138@5329: msg = "system NewGRF"; peter1138@5329: } else { peter1138@5329: msg = "unknown"; peter1138@5329: } peter1138@5329: peter1138@5329: ShowInfoF("ini: ignoring invalid NewGRF '%s': %s", item->name, msg); Darkvater@5346: ClearGRFConfig(&c); peter1138@5329: continue; peter1138@5329: } peter1138@5329: peter1138@5329: /* Mark file as static to avoid saving in savegame. */ skidd13@8427: if (is_static) SetBit(c->flags, GCF_STATIC); peter1138@5329: peter1138@5329: /* Add item to list */ peter1138@5329: *curr = c; peter1138@5329: curr = &c->next; peter1138@5307: } Darkvater@3631: peter1138@5329: return first; Darkvater@3628: } truelight@0: rubidium@10273: static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname) truelight@6609: { glx@10471: IniGroup *group = ini_getgroup(ini, grpname); truelight@6609: IniItem **item; truelight@6609: truelight@6609: if (group == NULL) return; truelight@6609: group->item = NULL; truelight@6609: item = &group->item; truelight@6609: truelight@6609: for (int i = 0; i < NT_END; i++) { truelight@6609: const char *value; rubidium@10273: int v = _news_type_data[i].display; truelight@6609: rubidium@10273: value = (v == ND_OFF ? "off" : (v == ND_SUMMARY ? "summarized" : "full")); truelight@6609: rubidium@10253: *item = ini_item_alloc(group, _news_type_data[i].name, strlen(_news_type_data[i].name)); truelight@6609: (*item)->value = (char*)pool_strdup(&ini->pool, value, strlen(value)); truelight@6609: item = &(*item)->next; truelight@6609: } truelight@6609: } peter1138@5329: rubidium@9243: /** rubidium@9243: * Save the version of OpenTTD to the ini file. rubidium@9243: * @param ini the ini to write to rubidium@9243: */ rubidium@9243: static void SaveVersionInConfig(IniFile *ini) rubidium@9243: { glx@10471: IniGroup *group = ini_getgroup(ini, "version"); rubidium@9243: rubidium@9243: if (group == NULL) return; rubidium@9243: group->item = NULL; rubidium@9243: IniItem **item = &group->item; rubidium@9243: rubidium@9243: char version[9]; rubidium@9243: snprintf(version, lengthof(version), "%08X", _openttd_newgrf_version); rubidium@9243: rubidium@9243: const char *versions[][2] = { rubidium@9243: { "version_string", _openttd_revision }, rubidium@9243: { "version_number", version } rubidium@9243: }; rubidium@9243: rubidium@9243: for (uint i = 0; i < lengthof(versions); i++) { rubidium@9243: *item = ini_item_alloc(group, versions[i][0], strlen(versions[i][0])); rubidium@9243: (*item)->value = (char*)pool_strdup(&ini->pool, versions[i][1], strlen(versions[i][1])); rubidium@9243: item = &(*item)->next; rubidium@9243: } rubidium@9243: } rubidium@9243: peter1138@5329: /* Save a GRF configuration to the given group name */ peter1138@5309: static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list) peter1138@5309: { glx@10471: IniGroup *group = ini_getgroup(ini, grpname); peter1138@5309: IniItem **item; peter1138@5309: const GRFConfig *c; peter1138@5309: peter1138@5309: if (group == NULL) return; peter1138@5309: group->item = NULL; peter1138@5309: item = &group->item; peter1138@5309: peter1138@5309: for (c = list; c != NULL; c = c->next) { peter1138@5309: char params[512]; peter1138@5309: GRFBuildParamList(params, c, lastof(params)); peter1138@5309: rubidium@7530: *item = ini_item_alloc(group, c->filename, strlen(c->filename)); rubidium@5838: (*item)->value = (char*)pool_strdup(&ini->pool, params, strlen(params)); peter1138@5309: item = &(*item)->next; peter1138@5309: } peter1138@5309: } peter1138@5309: Darkvater@3116: /* Common handler for saving/loading variables to the configuration file */ Darkvater@3116: static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list) truelight@0: { Darkvater@3116: proc(ini, (const SettingDesc*)_misc_settings, "misc", NULL); Darkvater@3116: proc(ini, (const SettingDesc*)_music_settings, "music", &msf); Darkvater@3051: #ifdef WIN32 Darkvater@3116: proc(ini, (const SettingDesc*)_win32_settings, "win32", NULL); Darkvater@3051: #endif /* WIN32 */ Darkvater@3116: rubidium@10703: proc(ini, _patch_settings, "patches", &_settings_newgame); Darkvater@3116: proc(ini, _currency_settings,"currency", &_custom_currency); Darkvater@3116: truelight@543: #ifdef ENABLE_NETWORK Darkvater@3628: proc_list(ini, "servers", _network_host_list, lengthof(_network_host_list), NULL); Darkvater@3628: proc_list(ini, "bans", _network_ban_list, lengthof(_network_ban_list), NULL); truelight@543: #endif /* ENABLE_NETWORK */ truelight@0: } truelight@0: Darkvater@3116: /** Load the values from the configuration files */ rubidium@6573: void LoadFromConfig() truelight@0: { truelight@0: IniFile *ini = ini_load(_config_file); belugas@6705: ResetCurrencies(false); // Initialize the array of curencies, without preserving the custom one rubidium@10759: rubidium@10759: PrepareOldDiffCustom(); rubidium@10759: ini_load_settings(ini, _gameopt_settings, "gameopt", &_settings_newgame); rubidium@10759: HandleOldDiffCustom(false); rubidium@10759: Darkvater@3116: HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list); peter1138@5329: _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false); peter1138@5329: _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true); rubidium@10273: NewsDisplayLoadConfig(ini, "news_display"); rubidium@6704: CheckDifficultyLevels(); truelight@0: ini_free(ini); truelight@0: } truelight@0: Darkvater@3116: /** Save the values to the configuration file */ rubidium@6573: void SaveToConfig() truelight@0: { truelight@0: IniFile *ini = ini_load(_config_file); rubidium@10703: rubidium@10703: /* Remove some obsolete groups. These have all been loaded into other groups. */ rubidium@10703: ini_removegroup(ini, "patches"); rubidium@10703: ini_removegroup(ini, "yapf"); rubidium@10708: ini_removegroup(ini, "gameopt"); rubidium@10703: Darkvater@3116: HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list); peter1138@5309: GRFSaveConfig(ini, "newgrf", _grfconfig_newgame); peter1138@5329: GRFSaveConfig(ini, "newgrf-static", _grfconfig_static); rubidium@10273: NewsDisplaySaveConfig(ini, "news_display"); rubidium@9243: SaveVersionInConfig(ini); truelight@0: ini_save(_config_file, ini); truelight@0: ini_free(ini); truelight@0: } Darkvater@1688: Darkvater@3247: static const SettingDesc *GetSettingDescription(uint index) Darkvater@3118: { Darkvater@3118: if (index >= lengthof(_patch_settings)) return NULL; Darkvater@3118: return &_patch_settings[index]; Darkvater@3118: } Darkvater@3118: Darkvater@3119: /** Network-safe changing of patch-settings (server-only). belugas@6979: * @param tile unused belugas@6979: * @param flags operation to perform Darkvater@3119: * @param p1 the index of the patch in the SettingDesc array which identifies it Darkvater@3119: * @param p2 the new value for the patch Darkvater@3119: * The new value is properly clamped to its minimum/maximum when setting Darkvater@3119: * @see _patch_settings Darkvater@3119: */ rubidium@7439: CommandCost CmdChangePatchSetting(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) Darkvater@3119: { Darkvater@3119: const SettingDesc *sd = GetSettingDescription(p1); Darkvater@3119: Darkvater@3119: if (sd == NULL) return CMD_ERROR; Darkvater@3223: if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR; Darkvater@3119: rubidium@10790: if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return CMD_ERROR; rubidium@8397: if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return CMD_ERROR; rubidium@10708: if ((sd->desc.flags & SGF_NEWGAME_ONLY) && _game_mode != GM_MENU) return CMD_ERROR; rubidium@8397: Darkvater@3119: if (flags & DC_EXEC) { rubidium@10775: GameSettings *s = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game; rubidium@10703: void *var = GetVariableAddress(s, &sd->save); smatz@10824: smatz@10824: int32 oldval = (int32)ReadValue(var, sd->save.conv); smatz@10824: int32 newval = (int32)p2; smatz@10824: smatz@10824: Write_ValidateSetting(var, sd, newval); smatz@10824: newval = (int32)ReadValue(var, sd->save.conv); smatz@10824: smatz@10824: if (sd->desc.proc != NULL) sd->desc.proc(newval); smatz@10824: smatz@10824: if ((sd->desc.flags & SGF_NO_NETWORK) && oldval != newval) { smatz@10824: GamelogStartAction(GLAT_PATCH); smatz@10824: GamelogPatch(sd->desc.name, oldval, newval); smatz@10824: GamelogStopAction(); smatz@10824: } Darkvater@3119: Darkvater@3119: InvalidateWindow(WC_GAME_OPTIONS, 0); Darkvater@3119: } Darkvater@3119: rubidium@7446: return CommandCost(); Darkvater@3119: } Darkvater@3119: Darkvater@3615: /** Top function to save the new value of an element of the Patches struct Darkvater@3118: * @param index offset in the SettingDesc array of the Patches struct which Darkvater@3118: * identifies the patch member we want to change Darkvater@3118: * @param object pointer to a valid patches struct that has its settings change. Darkvater@3118: * This only affects patch-members that are not needed to be the same on all Darkvater@3118: * clients in a network game. Darkvater@3118: * @param value new value of the patch */ rubidium@10775: bool SetPatchValue(uint index, int32 value) Darkvater@3118: { Darkvater@3118: const SettingDesc *sd = &_patch_settings[index]; Darkvater@3118: /* If an item is player-based, we do not send it over the network Darkvater@3118: * (if any) to change. Also *hack*hack* we update the _newgame version Darkvater@3118: * of patches because changing a player-based setting in a game also Darkvater@3118: * changes its defaults. At least that is the convention we have chosen */ Darkvater@3118: if (sd->save.conv & SLF_NETWORK_NO) { rubidium@10775: void *var = GetVariableAddress((_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game, &sd->save); Darkvater@3118: Write_ValidateSetting(var, sd, value); Darkvater@3121: Darkvater@3121: if (_game_mode != GM_MENU) { rubidium@10703: void *var2 = GetVariableAddress(&_settings_newgame, &sd->save); tron@4077: Write_ValidateSetting(var2, sd, value); Darkvater@3121: } KUDr@5113: if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv)); Darkvater@4600: InvalidateWindow(WC_GAME_OPTIONS, 0); Darkvater@4600: return true; Darkvater@3118: } Darkvater@4600: Darkvater@4600: /* send non-player-based settings over the network */ Darkvater@4600: if (!_networking || (_networking && _network_server)) { Darkvater@4600: return DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING); Darkvater@4600: } Darkvater@4600: return false; Darkvater@3118: } Darkvater@3118: rubidium@10790: /** rubidium@10790: * Set a patch value with a string. rubidium@10790: * @param index the patch settings index. rubidium@10790: * @param value the value to write rubidium@10790: * @note CANNOT BE SAVED IN THE SAVEGAME. rubidium@10790: */ rubidium@10790: bool SetPatchValue(uint index, const char *value) rubidium@10790: { rubidium@10790: const SettingDesc *sd = &_patch_settings[index]; rubidium@10790: assert(sd->save.conv & SLF_NETWORK_NO); rubidium@10790: rubidium@10790: char *var = (char*)GetVariableAddress(NULL, &sd->save); rubidium@10790: ttd_strlcpy(var, value, sd->save.length); rubidium@10818: if (sd->desc.proc != NULL) sd->desc.proc(0); rubidium@10790: rubidium@10790: return true; rubidium@10790: } rubidium@10790: Darkvater@3247: const SettingDesc *GetPatchFromName(const char *name, uint *i) Darkvater@3119: { Darkvater@3119: const SettingDesc *sd; Darkvater@3119: rubidium@10710: /* First check all full names */ Darkvater@3131: for (*i = 0, sd = _patch_settings; sd->save.cmd != SL_END; sd++, (*i)++) { Darkvater@3223: if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; Darkvater@3210: if (strcmp(sd->desc.name, name) == 0) return sd; Darkvater@3119: } Darkvater@3119: rubidium@10710: /* Then check the shortcut variant of the name. */ rubidium@10710: for (*i = 0, sd = _patch_settings; sd->save.cmd != SL_END; sd++, (*i)++) { rubidium@10710: if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; rubidium@10710: const char *short_name = strchr(sd->desc.name, '.'); rubidium@10710: if (short_name != NULL) { rubidium@10710: short_name++; rubidium@10710: if (strcmp(short_name, name) == 0) return sd; rubidium@10710: } rubidium@10710: } rubidium@10710: Darkvater@3119: return NULL; Darkvater@3119: } Darkvater@3119: Darkvater@3119: /* Those 2 functions need to be here, else we have to make some stuff non-static Darkvater@4278: * and besides, it is also better to keep stuff like this at the same place */ rubidium@10790: void IConsoleSetPatchSetting(const char *name, const char *value) Darkvater@3119: { Darkvater@3119: uint index; Darkvater@3119: const SettingDesc *sd = GetPatchFromName(name, &index); Darkvater@3119: Darkvater@3119: if (sd == NULL) { rubidium@10685: IConsolePrintF(CC_WARNING, "'%s' is an unknown patch setting.", name); rubidium@10814: return; Darkvater@3119: } Darkvater@3119: rubidium@10790: bool success; rubidium@10790: if (sd->desc.cmd == SDT_STRING) { rubidium@10790: success = SetPatchValue(index, value); rubidium@10790: } else { rubidium@10790: uint32 val; rubidium@10790: extern bool GetArgumentInteger(uint32 *value, const char *arg); rubidium@10790: success = GetArgumentInteger(&val, value); rubidium@10790: if (success) success = SetPatchValue(index, val); rubidium@10790: } Darkvater@3119: rubidium@10790: if (!success) { rubidium@10790: if (_network_server) { rubidium@10790: IConsoleError("This command/variable is not available during network games."); rubidium@10790: } else { rubidium@10790: IConsoleError("This command/variable is only available to a network server."); rubidium@10790: } rubidium@10790: } rubidium@10790: } rubidium@10790: rubidium@10790: void IConsoleSetPatchSetting(const char *name, int value) rubidium@10790: { rubidium@10790: uint index; rubidium@10790: const SettingDesc *sd = GetPatchFromName(name, &index); rubidium@10790: assert(sd != NULL); rubidium@10790: SetPatchValue(index, value); Darkvater@3119: } Darkvater@3119: Darkvater@3119: void IConsoleGetPatchSetting(const char *name) Darkvater@3119: { Darkvater@3119: char value[20]; Darkvater@3119: uint index; Darkvater@3119: const SettingDesc *sd = GetPatchFromName(name, &index); Darkvater@3119: const void *ptr; Darkvater@3119: Darkvater@3119: if (sd == NULL) { rubidium@10685: IConsolePrintF(CC_WARNING, "'%s' is an unknown patch setting.", name); Darkvater@3119: return; Darkvater@3119: } Darkvater@3119: rubidium@10775: ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game, &sd->save); Darkvater@3119: rubidium@10790: if (sd->desc.cmd == SDT_STRING) { rubidium@10790: IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (const char *)ptr); Darkvater@3119: } else { rubidium@10790: if (sd->desc.cmd == SDT_BOOLX) { rubidium@10790: snprintf(value, sizeof(value), (*(bool*)ptr == 1) ? "on" : "off"); rubidium@10790: } else { rubidium@10790: snprintf(value, sizeof(value), "%d", (int32)ReadValue(ptr, sd->save.conv)); rubidium@10790: } rubidium@10790: rubidium@10790: IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %d)", rubidium@10790: name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max); Darkvater@3119: } Darkvater@3119: } Darkvater@3119: peter1138@6925: void IConsoleListPatches() peter1138@6925: { rubidium@10685: IConsolePrintF(CC_WARNING, "All patches with their current value:"); peter1138@6925: peter1138@6925: for (const SettingDesc *sd = _patch_settings; sd->save.cmd != SL_END; sd++) { peter1138@6925: char value[80]; rubidium@10775: const void *ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game, &sd->save); peter1138@6925: peter1138@6925: if (sd->desc.cmd == SDT_BOOLX) { peter1138@6925: snprintf(value, lengthof(value), (*(bool*)ptr == 1) ? "on" : "off"); rubidium@10790: } else if (sd->desc.cmd == SDT_STRING) { rubidium@10790: snprintf(value, sizeof(value), "%s", (const char *)ptr); peter1138@6925: } else { peter1138@6925: snprintf(value, lengthof(value), "%d", (uint32)ReadValue(ptr, sd->save.conv)); peter1138@6925: } rubidium@10685: IConsolePrintF(CC_DEFAULT, "%s = %s", sd->desc.name, value); peter1138@6925: } peter1138@6925: rubidium@10685: IConsolePrintF(CC_WARNING, "Use 'patch' command to change a value"); peter1138@6925: } peter1138@6925: Darkvater@3117: /** Save and load handler for patches/settings Darkvater@3117: * @param osd SettingDesc struct containing all information Darkvater@3117: * @param object can be either NULL in which case we load global variables or Darkvater@3117: * a pointer to a struct which is getting saved */ Darkvater@3117: static void LoadSettings(const SettingDesc *osd, void *object) Darkvater@3117: { Darkvater@3117: for (; osd->save.cmd != SL_END; osd++) { Darkvater@3117: const SaveLoad *sld = &osd->save; rubidium@10775: void *ptr = GetVariableAddress(object, sld); Darkvater@3117: Darkvater@3117: if (!SlObjectMember(ptr, sld)) continue; Darkvater@3117: } Darkvater@3117: } Darkvater@3117: Darkvater@3117: /** Loadhandler for a list of global variables belugas@6979: * @param sdg pointer for the global variable list SettingDescGlobVarList Darkvater@3117: * @note this is actually a stub for LoadSettings with the Darkvater@3117: * object pointer set to NULL */ Darkvater@3117: static inline void LoadSettingsGlobList(const SettingDescGlobVarList *sdg) Darkvater@3117: { Darkvater@3117: LoadSettings((const SettingDesc*)sdg, NULL); Darkvater@3117: } Darkvater@3117: Darkvater@3117: /** Save and load handler for patches/settings belugas@6979: * @param sd SettingDesc struct containing all information Darkvater@3117: * @param object can be either NULL in which case we load global variables or Darkvater@3117: * a pointer to a struct which is getting saved */ Darkvater@3117: static void SaveSettings(const SettingDesc *sd, void *object) Darkvater@3117: { Darkvater@3117: /* We need to write the CH_RIFF header, but unfortunately can't call Darkvater@3117: * SlCalcLength() because we have a different format. So do this manually */ Darkvater@3117: const SettingDesc *i; Darkvater@3117: size_t length = 0; Darkvater@3117: for (i = sd; i->save.cmd != SL_END; i++) { Darkvater@5142: const void *ptr = GetVariableAddress(object, &i->save); Darkvater@5142: length += SlCalcObjMemberLength(ptr, &i->save); Darkvater@3117: } Darkvater@3117: SlSetLength(length); Darkvater@3117: Darkvater@3117: for (i = sd; i->save.cmd != SL_END; i++) { Darkvater@5141: void *ptr = GetVariableAddress(object, &i->save); Darkvater@3117: SlObjectMember(ptr, &i->save); Darkvater@3117: } Darkvater@3117: } Darkvater@3117: Darkvater@3117: /** Savehandler for a list of global variables Darkvater@3117: * @note this is actually a stub for SaveSettings with the Darkvater@3117: * object pointer set to NULL */ Darkvater@3117: static inline void SaveSettingsGlobList(const SettingDescGlobVarList *sdg) Darkvater@3117: { Darkvater@3117: SaveSettings((const SettingDesc*)sdg, NULL); Darkvater@3117: } Darkvater@3117: rubidium@6573: static void Load_OPTS() Darkvater@3117: { Darkvater@3117: /* Copy over default setting since some might not get loaded in Darkvater@3117: * a networking environment. This ensures for example that the local Darkvater@3117: * autosave-frequency stays when joining a network-server */ rubidium@10708: PrepareOldDiffCustom(); rubidium@10775: LoadSettings(_gameopt_settings, &_settings_game); rubidium@10759: HandleOldDiffCustom(true); Darkvater@3117: } Darkvater@3117: rubidium@6573: static void Load_PATS() Darkvater@3121: { Darkvater@3121: /* Copy over default setting since some might not get loaded in Darkvater@3121: * a networking environment. This ensures for example that the local Darkvater@3121: * signal_side stays when joining a network-server */ rubidium@10775: LoadSettings(_patch_settings, &_settings_game); Darkvater@3121: } Darkvater@3121: rubidium@6573: static void Save_PATS() Darkvater@3121: { rubidium@10775: SaveSettings(_patch_settings, &_settings_game); Darkvater@3121: } Darkvater@3121: rubidium@6573: void CheckConfig() Darkvater@1688: { rubidium@10727: /* rubidium@10727: * Increase old default values for pf_maxdepth and pf_maxlength rubidium@10727: * to support big networks. rubidium@10727: */ rubidium@10703: if (_settings_newgame.pf.opf.pf_maxdepth == 16 && _settings_newgame.pf.opf.pf_maxlength == 512) { rubidium@10703: _settings_newgame.pf.opf.pf_maxdepth = 48; rubidium@10703: _settings_newgame.pf.opf.pf_maxlength = 4096; ludde@2044: } Darkvater@1688: } Darkvater@3112: rubidium@5838: extern const ChunkHandler _setting_chunk_handlers[] = { rubidium@10708: { 'OPTS', NULL, Load_OPTS, CH_RIFF}, Darkvater@3121: { 'PATS', Save_PATS, Load_PATS, CH_RIFF | CH_LAST}, Darkvater@3112: }; KUDr@3900: KUDr@3900: static bool IsSignedVarMemType(VarType vt) KUDr@3900: { KUDr@3900: switch (GetVarMemType(vt)) { KUDr@3900: case SLE_VAR_I8: KUDr@3900: case SLE_VAR_I16: KUDr@3900: case SLE_VAR_I32: KUDr@3900: case SLE_VAR_I64: KUDr@3900: return true; KUDr@3900: } KUDr@3900: return false; KUDr@3900: }