tron@2186: /* $Id$ */
tron@2186:
Darkvater@3615: /** @file
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: * - 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: *
- 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: *
- 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: *
- 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@2163: #include "functions.h"
tron@2191: #include "macros.h"
tron@2121: #include "screenshot.h"
truelight@0: #include "sound.h"
tron@1317: #include "string.h"
tron@2153: #include "variables.h"
truelight@543: #include "network.h"
truelight@543: #include "settings.h"
Darkvater@3119: #include "command.h"
Darkvater@3119: #include "console.h"
Darkvater@3112: #include "saveload.h"
celestar@3358: #include "npf.h"
KUDr@3900: #include "yapf/yapf.h"
Darkvater@3628: #include "newgrf.h"
truelight@4300: #include "genworld.h"
rubidium@4261: #include "date.h"
truelight@0:
Darkvater@3121: /** The patch values that are used for new games and/or modified in config file */
Darkvater@3121: Patches _patches_newgame;
Darkvater@3121:
truelight@0: typedef struct IniFile IniFile;
truelight@0: typedef struct IniItem IniItem;
truelight@0: typedef struct IniGroup IniGroup;
truelight@1258: typedef struct SettingsMemoryPool 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);
truelight@1258: static void *pool_alloc(SettingsMemoryPool **pool, uint size);
truelight@1258: static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, uint size);
truelight@1258: static void pool_free(SettingsMemoryPool **pool);
KUDr@3900: static bool IsSignedVarMemType(VarType vt);
truelight@0:
truelight@1258: struct SettingsMemoryPool {
truelight@0: uint pos,size;
truelight@1258: SettingsMemoryPool *next;
truelight@0: byte mem[1];
truelight@0: };
truelight@0:
truelight@1258: static SettingsMemoryPool *pool_new(uint minsize)
truelight@0: {
truelight@1258: SettingsMemoryPool *p;
truelight@0: if (minsize < 4096 - 12) minsize = 4096 - 12;
truelight@193:
truelight@1258: p = malloc(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:
truelight@1258: static void *pool_alloc(SettingsMemoryPool **pool, uint size)
truelight@0: {
truelight@0: uint pos;
truelight@1258: SettingsMemoryPool *p = *pool;
truelight@0:
tron@2450: size = ALIGN(size, sizeof(void*));
truelight@0:
truelight@0: // 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;
truelight@0: // 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:
truelight@1258: static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, uint size)
truelight@0: {
truelight@0: byte *p = 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:
truelight@0: // 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 {
truelight@0: char *name; // name of group
truelight@0: char *comment; //comment for group
truelight@0: IniItem *item, **last_item;
truelight@0: IniGroup *next;
truelight@0: IniFile *ini;
dominik@705: IniGroupType type; // type of group
truelight@0: };
truelight@0:
truelight@0: struct IniFile {
truelight@1258: SettingsMemoryPool *pool;
truelight@0: IniGroup *group, **last_group;
truelight@0: char *comment; // last comment in file
truelight@0: };
truelight@0:
truelight@0: // allocate an inifile object
tron@1093: static IniFile *ini_alloc(void)
truelight@0: {
truelight@0: IniFile *ini;
truelight@1258: SettingsMemoryPool *pool;
truelight@0: pool_init(&pool);
truelight@0: ini = (IniFile*)pool_alloc(&pool, sizeof(IniFile));
truelight@0: ini->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:
truelight@0: // allocate an ini group object
truelight@0: static IniGroup *ini_group_alloc(IniFile *ini, const char *grpt, int len)
truelight@0: {
truelight@0: IniGroup *grp = pool_alloc(&ini->pool, sizeof(IniGroup));
truelight@0: grp->ini = ini;
truelight@0: grp->name = 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:
truelight@0: static IniItem *ini_item_alloc(IniGroup *group, const char *name, int len)
truelight@0: {
truelight@0: IniItem *item = pool_alloc(&group->ini->pool, sizeof(IniItem));
truelight@0: item->name = 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:
truelight@0: // 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:
truelight@0: // for each line in the file
truelight@0: while (fgets(buffer, sizeof(buffer), in)) {
truelight@193:
truelight@0: // trim whitespace from the left side
Darkvater@3598: for (s = buffer; *s == ' ' || *s == '\t'; s++);
truelight@0:
truelight@0: // trim whitespace from right side.
truelight@0: e = s + strlen(s);
truelight@0: while (e > s && ((c=e[-1]) == '\n' || c == '\r' || c == ' ' || c == '\t')) e--;
Darkvater@3598: *e = '\0';
truelight@0:
truelight@0: // skip comments and empty lines
Darkvater@3598: if (*s == '#' || *s == '\0') {
truelight@0: uint ns = comment_size + (e - s + 1);
truelight@0: uint a = comment_alloc;
truelight@0: uint pos;
truelight@0: // add to comment
truelight@0: if (ns > a) {
truelight@0: a = max(a, 128);
truelight@0: do a*=2; while (a < ns);
truelight@0: comment = realloc(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:
truelight@0: // it's a group?
truelight@0: if (s[0] == '[') {
tron@4077: if (e[-1] != ']') {
truelight@0: ShowInfoF("ini: invalid group name '%s'\n", 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) {
truelight@0: group->comment = pool_strdup(&ini->pool, comment, comment_size);
truelight@0: comment_size = 0;
truelight@0: }
truelight@0: } else if (group) {
truelight@0: // find end of keyname
Darkvater@3598: for (t = s; *t != '\0' && *t != '=' && *t != '\t' && *t != ' '; t++);
truelight@193:
truelight@0: // it's an item in an existing group
truelight@0: item = ini_item_alloc(group, s, t-s);
truelight@0: if (comment_size) {
truelight@0: item->comment = pool_strdup(&ini->pool, comment, comment_size);
truelight@0: comment_size = 0;
truelight@0: }
truelight@0:
truelight@0: // find start of parameter
truelight@0: while (*t == '=' || *t == ' ' || *t == '\t') t++;
dominik@759:
dominik@759:
dominik@759: // remove starting quotation marks
tron@2952: if (*t == '\"') t++;
dominik@759: // remove ending quotation marks
dominik@759: e = t + strlen(t);
Darkvater@3598: if (e > t && e[-1] == '\"') e--;
Darkvater@3598: *e = '\0';
dominik@759:
truelight@0: item->value = pool_strdup(&ini->pool, t, e - t);
truelight@0: } else {
truelight@0: // it's an orphan item
truelight@0: ShowInfoF("ini: '%s' outside of group\n", buffer);
truelight@0: }
truelight@0: }
truelight@0:
Darkvater@3615: if (comment_size > 0) {
truelight@0: ini->comment = 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:
truelight@0: // lookup a group or make a new one
truelight@0: static IniGroup *ini_getgroup(IniFile *ini, const char *name, int len)
truelight@0: {
truelight@0: IniGroup *group;
truelight@0:
truelight@0: if (len == -1) len = strlen(name);
truelight@0:
truelight@0: // does it exist already?
tron@2952: for (group = ini->group; group; group = group->next)
truelight@0: if (!memcmp(group->name, name, len) && group->name[len] == 0)
truelight@0: return group;
truelight@0:
truelight@0: // otherwise make a new one
truelight@0: group = ini_group_alloc(ini, name, len);
truelight@0: group->comment = pool_strdup(&ini->pool, "\n", 1);
truelight@0: return group;
truelight@0: }
truelight@0:
truelight@0: // 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;
truelight@0: uint len = strlen(name);
truelight@0:
tron@2952: for (item = group->item; item; item = item->next)
Darkvater@2972: if (strcmp(item->name, name) == 0) return item;
truelight@193:
truelight@0: if (!create) return NULL;
truelight@0:
truelight@0: // otherwise make a new one
Darkvater@2972: return ini_item_alloc(group, name, len);
truelight@0: }
truelight@0:
truelight@0: // 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:
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') {
Darkvater@3600: fprintf(f, "%s\n", item->name);
tron@4077: } else {
Darkvater@3600: fprintf(f, "%s = %s\n", item->name, 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 */
truelight@0: static int lookup_oneofmany(const char *many, const char *one, int onelen)
truelight@0: {
truelight@0: const char *s;
truelight@0: int idx;
truelight@0:
truelight@0: if (onelen == -1) onelen = strlen(one);
truelight@0:
truelight@0: // 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 (;;) {
truelight@0: // find end of item
truelight@0: s = many;
truelight@0: while (*s != '|' && *s != 0) s++;
truelight@0: if (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
Darkvater@2972: * 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 (;;) {
truelight@0: // 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:
Darkvater@2972: 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:
Darkvater@2973: // 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:
Darkvater@2973: // 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:
Darkvater@2973: 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: {
Darkvater@2972: long r = lookup_oneofmany(desc->many, str, -1);
truelight@0: if (r != -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_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;
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;
Darkvater@3352: 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;
Darkvater@3352: 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
Darkvater@2972: * @param grpname the group of the IniFile to search in for the new values */
Darkvater@3115: static void ini_load_settings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
truelight@0: {
Darkvater@3115: IniGroup *group;
Darkvater@3115: IniGroup *group_def = ini_getgroup(ini, grpname, -1);
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:
Darkvater@2972: // 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 {
Darkvater@3115: s = sdb->name;
truelight@0: group = group_def;
truelight@0: }
truelight@193:
truelight@0: item = ini_getitem(group, s, false);
Darkvater@3115: p = (item == NULL) ? sdb->def : string_to_val(sdb, item->value);
Darkvater@3115: ptr = ini_get_variable(sld, object);
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:
Darkvater@4255: if (p != NULL) ttd_strlcpy((char*)ptr, 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: {
Darkvater@3115: if (!load_intlist(p, ptr, sld->length, GetVarMemType(sld->conv)))
Darkvater@3115: ShowInfoF("ini: error in array '%s'", sdb->name);
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
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:
Darkvater@2972: // 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 {
Darkvater@2972: if (group_def == NULL) group_def = ini_getgroup(ini, grpname, -1);
Darkvater@3115: s = sdb->name;
truelight@0: group = group_def;
truelight@0: }
truelight@193:
truelight@0: item = ini_getitem(group, s, true);
Darkvater@3115: ptr = ini_get_variable(sld, object);
truelight@193:
truelight@0: if (item->value != NULL) {
truelight@193: // 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:
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 */
truelight@0: item->value = 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.
Darkvater@3615: * @param 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: {
Darkvater@3115: IniGroup *group = ini_getgroup(ini, grpname, -1);
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.
Darkvater@3615: * @param 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
Darkvater@3615: * 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: {
Darkvater@3115: IniGroup *group = ini_getgroup(ini, grpname, -1);
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
tron@4000: * Base/Offset and runtime variable selection mechanism, known from the saveload * 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
tron@4000: * place) and you DON'T have to increase the savegame version. */
Darkvater@3116:
rubidium@4431: #define NSD_GENERAL(name, def, cmd, guiflags, min, max, interval, many, str, proc)\
rubidium@4431: {name, (const void*)(def), cmd, guiflags, min, max, interval, many, str, proc}
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)\
rubidium@4431: {NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, proc), 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@4431: SDTG_GENERAL(name, SDT_BOOLX, SL_VAR, SLE_UINT8, 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)\
Darkvater@3116: 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)\
rubidium@4431: {{"", NULL, 0, 0, 0, 0, 0, NULL, STR_NULL, NULL}, SLEG_CONDNULL(length, from, to)}
Darkvater@3222:
rubidium@4431: #define SDTG_END() {{NULL, NULL, 0, 0, 0, 0, 0, NULL, STR_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 */
rubidium@4431: #define SDT_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, base, var, length, def, min, max, interval, full, str, proc, from, to)\
rubidium@4431: {NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, proc), 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)\
rubidium@4431: SDT_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, base, var, 1, def, min, max, interval, NULL, str, proc, 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)\
rubidium@4431: SDT_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, base, var, 1, def, 0, 1, 0, NULL, str, proc, 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)\
rubidium@4431: SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, proc, 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)
Darkvater@3116: #define SDT_CONDLISTO(base, var, length, type, from, to, flags, guiflags, def, str, proc)\
rubidium@4431: SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, length, def, 0, 0, 0, NULL, str, proc, from, to)
Darkvater@3116:
Darkvater@3116: #define SDT_CONDSTR(base, var, type, from, to, flags, guiflags, def, str, proc)\
rubidium@4431: SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, proc, 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)\
rubidium@4431: SDT_GENERAL(#var, SDT_STRING, SL_VAR, SLE_CHAR, flags, guiflags, base, var, 1, def, 0, 0, 0, NULL, str, proc, 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:
Darkvater@3116: #define SDT_CONDOMANY(base, var, type, from, to, flags, guiflags, def, max, full, str, proc)\
rubidium@4431: SDT_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, max, 0, full, str, proc, from, to)
Darkvater@3116: #define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, proc)\
Darkvater@3116: SDT_CONDOMANY(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, max, full, str, proc)
Darkvater@3116:
Darkvater@3116: #define SDT_CONDMMANY(base, var, type, from, to, flags, guiflags, def, full, str, proc)\
rubidium@4431: SDT_GENERAL(#var, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, 0, 0, full, str, proc, 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)\
rubidium@4431: {{"", NULL, 0, 0, 0, 0, 0, NULL, STR_NULL, NULL}, SLE_CONDNULL(length, from, to)}
Darkvater@3222:
rubidium@4431: #define SDT_END() {{NULL, NULL, 0, 0, 0, 0, 0, NULL, STR_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
KUDr@3900: #define NS SLF_SAVE_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
Darkvater@3116:
Darkvater@3116: #include "table/strings.h"
Darkvater@3131:
Darkvater@3131: /* Begin - Callback Functions for the various settings */
Darkvater@3131: #include "window.h"
Darkvater@3131: #include "gui.h"
Darkvater@3131: #include "town.h"
Darkvater@3131: #include "gfx.h"
Darkvater@3131: // 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);
Darkvater@3131: _patches.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:
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;
Darkvater@3131: const Patches *ptc = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
Darkvater@3131:
Darkvater@3131: if (p1) {
Darkvater@3131: warning = ( (IS_INT_INSIDE(ptc->servint_trains, 5, 90+1) || ptc->servint_trains == 0) &&
Darkvater@3131: (IS_INT_INSIDE(ptc->servint_roadveh, 5, 90+1) || ptc->servint_roadveh == 0) &&
Darkvater@3131: (IS_INT_INSIDE(ptc->servint_aircraft, 5, 90+1) || ptc->servint_aircraft == 0) &&
Darkvater@3131: (IS_INT_INSIDE(ptc->servint_ships, 5, 90+1) || ptc->servint_ships == 0) );
Darkvater@3131: } else {
Darkvater@3131: warning = ( (IS_INT_INSIDE(ptc->servint_trains, 30, 800+1) || ptc->servint_trains == 0) &&
Darkvater@3131: (IS_INT_INSIDE(ptc->servint_roadveh, 30, 800+1) || ptc->servint_roadveh == 0) &&
Darkvater@3131: (IS_INT_INSIDE(ptc->servint_aircraft, 30, 800+1) || ptc->servint_aircraft == 0) &&
Darkvater@3131: (IS_INT_INSIDE(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: {
peter1138@4661: DoCommandP(0, 0, _patches.autorenew, NULL, CMD_SET_AUTOREPLACE);
Darkvater@3131: return 0;
Darkvater@3131: }
Darkvater@3131:
Darkvater@3131: static int32 EngineRenewMonthsUpdate(int32 p1)
Darkvater@3131: {
peter1138@4661: DoCommandP(0, 1, _patches.autorenew_months, NULL, CMD_SET_AUTOREPLACE);
Darkvater@3131: return 0;
Darkvater@3131: }
Darkvater@3131:
Darkvater@3131: static int32 EngineRenewMoneyUpdate(int32 p1)
Darkvater@3131: {
peter1138@4661: DoCommandP(0, 2, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
Darkvater@3131: return 0;
Darkvater@3131: }
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
Darkvater@4258: extern bool _force_full_redraw, _double_size, _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("double_size", S, 0, _double_size, false, 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[] = {
Darkvater@3116: SDTG_MMANY("display_opt", SLE_UINT8, S, 0, _display_opt, (DO_SHOW_TOWN_NAMES|DO_SHOW_STATION_NAMES|DO_SHOW_SIGNS|DO_FULL_ANIMATION|DO_FULL_DETAIL|DO_TRANS_BUILDINGS|DO_WAYPOINTS), "SHOW_TOWN_NAMES|SHOW_STATION_NAMES|SHOW_SIGNS|FULL_ANIMATION|TRANS_BUILDINGS|FULL_DETAIL|WAYPOINTS", STR_NULL, NULL),
rubidium@4431: SDTG_VAR("news_display_opt", SLE_UINT, S, 0, _news_display_opt,0xAAAAAAAA,0,0xAAAAAAAA,0,STR_NULL, NULL), // default to all full messages: 10101010101010101010 = 0xAAAAAAAA
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),
Darkvater@3116: SDTG_STR("language", SLE_STRB, S, 0, _dynlang.curr_file, NULL, STR_NULL, NULL),
Darkvater@3116: SDTG_LIST("resolution", SLE_UINT16, S, 0, _cur_resolution, "640,480", STR_NULL, NULL),
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),
Darkvater@3116: SDTG_END()
truelight@0: };
truelight@0:
truelight@543: #ifdef ENABLE_NETWORK
Darkvater@3116: static const SettingDescGlobVarList _network_settings[] = {
rubidium@4431: SDTG_VAR("sync_freq", SLE_UINT16,C|S,0, _network_sync_freq, 100, 0, 100, 0, STR_NULL, NULL),
rubidium@4431: SDTG_VAR("frame_freq", SLE_UINT8,C|S,0, _network_frame_freq, 0, 0, 100, 0, STR_NULL, NULL),
rubidium@4431: SDTG_VAR("max_join_time", SLE_UINT16, S, 0, _network_max_join_time, 500, 0, 32000, 0, STR_NULL, NULL),
rubidium@4431: SDTG_BOOL("pause_on_join", S, 0, _network_pause_on_join, true, STR_NULL, NULL),
rubidium@4431: SDTG_STR("server_bind_ip", SLE_STRB, S, 0, _network_server_bind_ip_host, "0.0.0.0", STR_NULL, NULL),
rubidium@4431: SDTG_VAR("server_port", SLE_UINT16, S, 0, _network_server_port, NETWORK_DEFAULT_PORT, 0, 65535, 0, STR_NULL, NULL),
rubidium@4431: SDTG_BOOL("server_advertise", S, 0, _network_advertise, false, STR_NULL, NULL),
rubidium@4431: SDTG_VAR("lan_internet", SLE_UINT8, S, 0, _network_lan_internet, 0, 0, 1, 0, STR_NULL, NULL),
rubidium@4431: SDTG_STR("player_name", SLE_STRB, S, 0, _network_player_name, NULL, STR_NULL, NULL),
rubidium@4431: SDTG_STR("server_password", SLE_STRB, S, 0, _network_server_password, NULL, STR_NULL, NULL),
rubidium@4431: SDTG_STR("rcon_password", SLE_STRB, S, 0, _network_rcon_password, NULL, STR_NULL, NULL),
rubidium@4431: SDTG_STR("server_name", SLE_STRB, S, 0, _network_server_name, NULL, STR_NULL, NULL),
rubidium@4431: SDTG_STR("connect_to_ip", SLE_STRB, S, 0, _network_default_ip, NULL, STR_NULL, NULL),
rubidium@4431: SDTG_STR("network_id", SLE_STRB, S, 0, _network_unique_id, NULL, STR_NULL, NULL),
rubidium@4431: SDTG_BOOL("autoclean_companies", S, 0, _network_autoclean_companies, false, STR_NULL, NULL),
rubidium@4431: SDTG_VAR("autoclean_unprotected",SLE_UINT8, S, 0, _network_autoclean_unprotected,12, 0, 60, 0, STR_NULL, NULL),
rubidium@4431: SDTG_VAR("autoclean_protected", SLE_UINT8, S, 0, _network_autoclean_protected, 36, 0, 180, 0, STR_NULL, NULL),
rubidium@4496: SDTG_VAR("max_companies", SLE_UINT8, S, 0, _network_game_info.companies_max, 8, 0, 8, 0, STR_NULL, NULL),
rubidium@4496: SDTG_VAR("max_clients", SLE_UINT8, S, 0, _network_game_info.clients_max, 10, 0, 10, 0, STR_NULL, NULL),
rubidium@4496: SDTG_VAR("max_spectators", SLE_UINT8, S, 0, _network_game_info.spectators_max, 10, 0, 10, 0, STR_NULL, NULL),
rubidium@4431: SDTG_VAR("restart_game_year", SLE_INT32, S,D0, _network_restart_game_year, 0, MIN_YEAR, MAX_YEAR, 1, STR_NULL, NULL),
peter1138@4716: SDTG_VAR("min_players", SLE_UINT8, S, 0, _network_min_players, 0, 0, 10, 0, STR_NULL, NULL),
Darkvater@3116: SDTG_END()
truelight@0: };
truelight@543: #endif /* ENABLE_NETWORK */
truelight@0:
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
Darkvater@3116: * and why not byte for example? */
rubidium@4431: SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, 0, 3),
rubidium@4431: SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, 4, SL_MAX_VERSION),
rubidium@4431: SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 9, 0, 9, 0, STR_NULL, NULL),
belugas@4601: SDT_OMANY(GameOptions, 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|custom", STR_NULL, NULL),
rubidium@4431: SDT_OMANY(GameOptions, units, SLE_UINT8, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL),
rubidium@4431: SDT_OMANY(GameOptions, town_name, SLE_UINT8, 0, 0, 0, 20, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL),
rubidium@4431: SDT_OMANY(GameOptions, landscape, SLE_UINT8, 0, 0, 0, 3, "normal|hilly|desert|candy", STR_NULL, NULL),
rubidium@4431: SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 1, 0, 56, 0, STR_NULL, NULL),
Darkvater@3241: SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8, 0, 22, N, 0, 0, 0, "", STR_NULL, NULL),
Darkvater@3241: SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8,23, SL_MAX_VERSION, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL),
Darkvater@3116: SDT_OMANY(GameOptions, road_side, SLE_UINT8, 0, 0, 1, 1, "left|right", STR_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: /***************************************************************************/
Darkvater@3247: /* User-interface section of the GUI-configure patches window */
rubidium@4431: SDT_BOOL(Patches, vehicle_speed, S, 0, true, STR_CONFIG_PATCHES_VEHICLESPEED, NULL),
rubidium@4431: SDT_BOOL(Patches, status_long_date, S, 0, true, STR_CONFIG_PATCHES_LONGDATE, NULL),
rubidium@4431: SDT_BOOL(Patches, show_finances, S, 0, true, STR_CONFIG_PATCHES_SHOWFINANCES, NULL),
rubidium@4431: SDT_BOOL(Patches, autoscroll, S, 0, false, STR_CONFIG_PATCHES_AUTOSCROLL, NULL),
rubidium@4431: SDT_BOOL(Patches, reverse_scroll, S, 0, false, STR_CONFIG_PATCHES_REVERSE_SCROLLING, NULL),
Darkvater@4834: SDT_BOOL(Patches, measure_tooltip, S, 0, false, STR_CONFIG_PATCHES_MEASURE_TOOLTIP, NULL),
rubidium@4431: SDT_VAR(Patches, errmsg_duration, SLE_UINT8, S, 0, 5, 0, 20, 0, STR_CONFIG_PATCHES_ERRMSG_DURATION, NULL),
rubidium@4431: SDT_VAR(Patches, toolbar_pos, SLE_UINT8, S,MS, 0, 0, 2, 0, STR_CONFIG_PATCHES_TOOLBAR_POS, v_PositionMainToolbar),
rubidium@4431: SDT_VAR(Patches, window_snap_radius, SLE_UINT8, S,D0, 10, 1, 32, 0, STR_CONFIG_PATCHES_SNAP_RADIUS, NULL),
rubidium@4431: SDT_BOOL(Patches, invisible_trees, S, 0, false, STR_CONFIG_PATCHES_INVISIBLE_TREES, RedrawScreen),
rubidium@4431: SDT_BOOL(Patches, population_in_label, S, 0, true, STR_CONFIG_PATCHES_POPULATION_IN_LABEL, PopulationInLabelActive),
rubidium@4431: SDT_VAR(Patches, map_x, SLE_UINT8, S, 0, 8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_X, NULL),
rubidium@4431: SDT_VAR(Patches, map_y, SLE_UINT8, S, 0, 8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_Y, NULL),
rubidium@4431: SDT_BOOL(Patches, link_terraform_toolbar, S, 0, false, STR_CONFIG_PATCHES_LINK_TERRAFORM_TOOLBAR,NULL),
peter1138@4616: SDT_VAR(Patches, liveries, SLE_UINT8, S,MS, 2, 0, 2, 0, STR_CONFIG_PATCHES_LIVERIES, RedrawScreen),
truelight@543:
Darkvater@3116: /***************************************************************************/
Darkvater@3247: /* Construction section of the GUI-configure patches window */
rubidium@4431: SDT_BOOL(Patches, build_on_slopes, 0, 0, true, STR_CONFIG_PATCHES_BUILDONSLOPES, NULL),
rubidium@4431: SDT_BOOL(Patches, extra_dynamite, 0, 0, false, STR_CONFIG_PATCHES_EXTRADYNAMITE, NULL),
rubidium@4431: SDT_BOOL(Patches, longbridges, 0, 0, true, STR_CONFIG_PATCHES_LONGBRIDGES, NULL),
rubidium@4431: SDT_BOOL(Patches, signal_side, N, 0, true, STR_CONFIG_PATCHES_SIGNALSIDE, RedrawScreen),
rubidium@4431: SDT_BOOL(Patches, always_small_airport, 0, 0, false, STR_CONFIG_PATCHES_SMALL_AIRPORTS, NULL),
rubidium@4431: SDT_VAR(Patches, drag_signals_density,SLE_UINT8,S, 0, 4, 1, 20, 0, STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY,NULL),
truelight@543:
Darkvater@3116: /***************************************************************************/
Darkvater@3247: /* Vehicle section of the GUI-configure patches window */
rubidium@4431: SDT_BOOL(Patches, realistic_acceleration, 0, 0, false, STR_CONFIG_PATCHES_REALISTICACCEL, NULL),
rubidium@4431: SDT_BOOL(Patches, forbid_90_deg, 0, 0, false, STR_CONFIG_PATCHES_FORBID_90_DEG, NULL),
rubidium@4431: SDT_BOOL(Patches, mammoth_trains, 0, 0, true, STR_CONFIG_PATCHES_MAMMOTHTRAINS, NULL),
rubidium@4431: SDT_BOOL(Patches, gotodepot, 0, 0, true, STR_CONFIG_PATCHES_GOTODEPOT, NULL),
rubidium@4431: SDT_BOOL(Patches, roadveh_queue, 0, 0, true, STR_CONFIG_PATCHES_ROADVEH_QUEUE, NULL),
rubidium@4431: SDT_BOOL(Patches, new_pathfinding_all, 0, 0, false, STR_CONFIG_PATCHES_NEW_PATHFINDING_ALL, NULL),
KUDr@3900:
rubidium@4431: SDT_CONDBOOL(Patches, yapf.ship_use_yapf, 28, SL_MAX_VERSION, 0, 0, false, STR_CONFIG_PATCHES_YAPF_SHIPS, NULL),
rubidium@4431: SDT_CONDBOOL(Patches, yapf.road_use_yapf, 28, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_YAPF_ROAD, NULL),
rubidium@4431: SDT_CONDBOOL(Patches, yapf.rail_use_yapf, 28, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_YAPF_RAIL, NULL),
rubidium@4431:
rubidium@4431: SDT_BOOL(Patches, train_income_warn, S, 0, true, STR_CONFIG_PATCHES_WARN_INCOME_LESS, NULL),
rubidium@4431: SDT_VAR(Patches, order_review_system,SLE_UINT8, S,MS, 2, 0, 2, 0, STR_CONFIG_PATCHES_ORDER_REVIEW, NULL),
rubidium@4431: SDT_BOOL(Patches, never_expire_vehicles, 0, 0, false, STR_CONFIG_PATCHES_NEVER_EXPIRE_VEHICLES,NULL),
KUDr@4870: SDT_BOOL(Patches, lost_train_warn, S, 0, true, STR_CONFIG_PATCHES_WARN_LOST_TRAIN, NULL),
rubidium@4431: SDT_BOOL(Patches, autorenew, S, 0, false, STR_CONFIG_PATCHES_AUTORENEW_VEHICLE, EngineRenewUpdate),
rubidium@4431: SDT_VAR(Patches, autorenew_months, SLE_INT16, S, 0, 6, -12, 12, 0, STR_CONFIG_PATCHES_AUTORENEW_MONTHS, EngineRenewMonthsUpdate),
rubidium@4431: SDT_VAR(Patches, autorenew_money, SLE_UINT, S,CR,100000, 0, 2000000, 0, STR_CONFIG_PATCHES_AUTORENEW_MONEY, EngineRenewMoneyUpdate),
rubidium@4431: SDT_VAR(Patches, max_trains, SLE_UINT16, 0, 0, 500, 0, 5000, 0, STR_CONFIG_PATCHES_MAX_TRAINS, NULL),
rubidium@4431: SDT_VAR(Patches, max_roadveh, SLE_UINT16, 0, 0, 500, 0, 5000, 0, STR_CONFIG_PATCHES_MAX_ROADVEH, NULL),
rubidium@4431: SDT_VAR(Patches, max_aircraft, SLE_UINT16, 0, 0, 200, 0, 5000, 0, STR_CONFIG_PATCHES_MAX_AIRCRAFT, NULL),
rubidium@4431: SDT_VAR(Patches, max_ships, SLE_UINT16, 0, 0, 300, 0, 5000, 0, STR_CONFIG_PATCHES_MAX_SHIPS, NULL),
rubidium@4431: SDT_BOOL(Patches, servint_ispercent, 0, 0, false, STR_CONFIG_PATCHES_SERVINT_ISPERCENT, CheckInterval),
rubidium@4431: SDT_VAR(Patches, servint_trains, SLE_UINT16, 0,D0, 150, 5, 800, 0, STR_CONFIG_PATCHES_SERVINT_TRAINS, InValidateDetailsWindow),
rubidium@4431: SDT_VAR(Patches, servint_roadveh, SLE_UINT16, 0,D0, 150, 5, 800, 0, STR_CONFIG_PATCHES_SERVINT_ROADVEH, InValidateDetailsWindow),
rubidium@4431: SDT_VAR(Patches, servint_ships, SLE_UINT16, 0,D0, 360, 5, 800, 0, STR_CONFIG_PATCHES_SERVINT_SHIPS, InValidateDetailsWindow),
rubidium@4431: SDT_VAR(Patches, servint_aircraft, SLE_UINT16, 0,D0, 100, 5, 800, 0, STR_CONFIG_PATCHES_SERVINT_AIRCRAFT, InValidateDetailsWindow),
rubidium@4431: SDT_BOOL(Patches, no_servicing_if_no_breakdowns, 0, 0, false, STR_CONFIG_PATCHES_NOSERVICE, NULL),
rubidium@4431: SDT_BOOL(Patches, wagon_speed_limits, 0, 0, true, STR_CONFIG_PATCHES_WAGONSPEEDLIMITS, NULL),
truelight@543:
Darkvater@3116: /***************************************************************************/
Darkvater@3247: /* Station section of the GUI-configure patches window */
rubidium@4431: SDT_BOOL(Patches, join_stations, 0, 0, true, STR_CONFIG_PATCHES_JOINSTATIONS, NULL),
rubidium@4431: SDT_BOOL(Patches, full_load_any, 0, 0, true, STR_CONFIG_PATCHES_FULLLOADANY, NULL),
rubidium@4431: SDT_BOOL(Patches, improved_load, 0, 0, false, STR_CONFIG_PATCHES_IMPROVEDLOAD, NULL),
rubidium@4431: SDT_BOOL(Patches, selectgoods, 0, 0, true, STR_CONFIG_PATCHES_SELECTGOODS, NULL),
rubidium@4431: SDT_BOOL(Patches, new_nonstop, 0, 0, false, STR_CONFIG_PATCHES_NEW_NONSTOP, NULL),
rubidium@4431: SDT_BOOL(Patches, nonuniform_stations, 0, 0, true, STR_CONFIG_PATCHES_NONUNIFORM_STATIONS,NULL),
rubidium@4431: SDT_VAR(Patches, station_spread,SLE_UINT8,0, 0, 12, 4, 64, 0, STR_CONFIG_PATCHES_STATION_SPREAD, InvalidateStationBuildWindow),
rubidium@4431: SDT_BOOL(Patches, serviceathelipad, 0, 0, true, STR_CONFIG_PATCHES_SERVICEATHELIPAD, NULL),
rubidium@4431: SDT_BOOL(Patches, modified_catchment, 0, 0, true, STR_CONFIG_PATCHES_CATCHMENT, NULL),
truelight@543:
Darkvater@3116: /***************************************************************************/
Darkvater@3247: /* Economy section of the GUI-configure patches window */
Darkvater@3116: SDT_BOOL(Patches, inflation, 0, 0, true, STR_CONFIG_PATCHES_INFLATION, NULL),
Darkvater@3116: SDT_BOOL(Patches, build_rawmaterial_ind, 0, 0, false, STR_CONFIG_PATCHES_BUILDXTRAIND, NULL),
Darkvater@3116: SDT_BOOL(Patches, multiple_industry_per_town, 0, 0, false, STR_CONFIG_PATCHES_MULTIPINDTOWN, NULL),
Darkvater@3116: SDT_BOOL(Patches, same_industry_close, 0, 0, false, STR_CONFIG_PATCHES_SAMEINDCLOSE, NULL),
Darkvater@3116: SDT_BOOL(Patches, bribe, 0, 0, true, STR_CONFIG_PATCHES_BRIBE, NULL),
rubidium@4431: SDT_VAR(Patches, snow_line_height,SLE_UINT8, 0, 0, 7, 2, 13, 0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT, NULL),
rubidium@4431: SDT_VAR(Patches, colored_news_year,SLE_INT32, 0,NC, 2000, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_COLORED_NEWS_YEAR,NULL),
rubidium@4431: SDT_VAR(Patches, starting_year, SLE_INT32, 0,NC, 1950, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_STARTING_YEAR,NULL),
rubidium@4431: SDT_VAR(Patches, ending_year, SLE_INT32,0,NC|NO,2051, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_ENDING_YEAR, NULL),
Darkvater@3116: SDT_BOOL(Patches, smooth_economy, 0, 0, true, STR_CONFIG_PATCHES_SMOOTH_ECONOMY, NULL),
Darkvater@3116: SDT_BOOL(Patches, allow_shares, 0, 0, true, STR_CONFIG_PATCHES_ALLOW_SHARES, NULL),
tron@1218:
Darkvater@3116: /***************************************************************************/
Darkvater@3247: /* AI section of the GUI-configure patches window */
Darkvater@3131: SDT_BOOL(Patches, ainew_active, 0, 0, false, STR_CONFIG_PATCHES_AINEW_ACTIVE, AiNew_PatchActive_Warning),
Darkvater@3131: SDT_BOOL(Patches, ai_in_multiplayer, 0, 0, false, STR_CONFIG_PATCHES_AI_IN_MULTIPLAYER, Ai_In_Multiplayer_Warning),
Darkvater@3116: SDT_BOOL(Patches, ai_disable_veh_train, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_TRAINS, NULL),
Darkvater@3116: SDT_BOOL(Patches, ai_disable_veh_roadveh, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_ROADVEH, NULL),
Darkvater@3116: SDT_BOOL(Patches, ai_disable_veh_aircraft,0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_AIRCRAFT,NULL),
Darkvater@3116: SDT_BOOL(Patches, ai_disable_veh_ship, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_SHIPS, NULL),
truelight@1271:
Darkvater@3116: /***************************************************************************/
Darkvater@3247: /* Patches without any GUI representation */
rubidium@4431: SDT_BOOL(Patches, keep_all_autosave, S, 0, false, STR_NULL, NULL),
rubidium@4431: SDT_BOOL(Patches, autosave_on_exit, S, 0, false, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, max_num_autosaves, SLE_UINT8, S, 0, 16, 0, 255, 0, STR_NULL, NULL),
rubidium@4431: SDT_BOOL(Patches, bridge_pillars, S, 0, true, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, extend_vehicle_life, SLE_UINT8, 0, 0, 0, 0, 100, 0, STR_NULL, NULL),
rubidium@4431: SDT_BOOL(Patches, auto_euro, S, 0, true, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, dist_local_authority,SLE_UINT8, 0, 0, 20, 5, 60, 0, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, wait_oneway_signal, SLE_UINT8, 0, 0, 15, 2, 100, 0, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, wait_twoway_signal, SLE_UINT8, 0, 0, 41, 2, 100, 0, STR_NULL, NULL),
Darkvater@3116:
Darkvater@3116: /***************************************************************************/
Darkvater@3247: /* New Pathfinding patch settings */
rubidium@4431: SDT_VAR(Patches, pf_maxlength, SLE_UINT16, 0, 0, 4096, 64, 65535, 0, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, pf_maxdepth, SLE_UINT8, 0, 0, 48, 4, 255, 0, STR_NULL, NULL),
matthijs@1700: /* The maximum number of nodes to search */
rubidium@4431: SDT_VAR(Patches, npf_max_search_nodes,SLE_UINT, 0, 0, 10000, 500, 100000, 0, STR_NULL, NULL),
matthijs@1700:
truelight@1271: /* When a red signal is encountered, a small detour can be made around
tron@4000: * it. This specifically occurs when a track is doubled, in which case
tron@4000: * the detour is typically 2 tiles. It is also often used at station
tron@4000: * entrances, when there is a choice of multiple platforms. If we take
tron@4000: * a typical 4 platform station, the detour is 4 tiles. To properly
tron@4000: * support larger stations we increase this value.
tron@4000: * We want to prevent that trains that want to leave at one side of a
tron@4000: * station, leave through the other side, turn around, enter the
tron@4000: * station on another platform and exit the station on the right side
tron@4000: * again, just because the sign at the right side was red. If we take
tron@4000: * a typical 5 length station, this detour is 10 or 11 tiles (not
tron@4000: * sure), so we set the default penalty at 10 (the station tile
tron@4000: * penalty will further prevent this.
tron@4000: * We give presignal exits (and combo's) a different (larger) penalty, because
tron@4000: * we really don't want trains waiting in front of a presignal exit. */
rubidium@4431: SDT_VAR(Patches, npf_rail_firstred_penalty, SLE_UINT, 0, 0, (10 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, npf_rail_firstred_exit_penalty,SLE_UINT, 0, 0, (100 * NPF_TILE_LENGTH),0, 100000, 0, STR_NULL, NULL),
matthijs@1459: /* This penalty is for when the last signal before the target is red.
matthijs@1459: * This is useful for train stations, where there are multiple
matthijs@1459: * platforms to choose from, which lie in different signal blocks.
matthijs@1459: * Every target in a occupied signal block (ie an occupied platform)
Darkvater@3116: * will get this penalty. */
rubidium@4431: SDT_VAR(Patches, npf_rail_lastred_penalty, SLE_UINT, 0, 0, (10 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
truelight@1271: /* When a train plans a route over a station tile, this penalty is
Darkvater@3116: * applied. We want that trains plan a route around a typical, 4x5
Darkvater@3116: * station, which means two tiles to the right, and two tiles back to
Darkvater@3116: * the left around it, or 5 tiles of station through it. If we assign
Darkvater@3116: * a penalty of 1 tile for every station tile passed, the route will
Darkvater@3116: * be around it. */
rubidium@4431: SDT_VAR(Patches, npf_rail_station_penalty, SLE_UINT, 0, 0, (1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, npf_rail_slope_penalty, SLE_UINT, 0, 0, (1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
matthijs@1751: /* This penalty is applied when a train makes a turn. Its value of 1 makes
matthijs@1751: * sure that it has a minimal impact on the pathfinding, only when two
matthijs@1751: * paths have equal length it will make a difference */
rubidium@4431: SDT_VAR(Patches, npf_rail_curve_penalty, SLE_UINT, 0, 0, 1, 0, 100000, 0, STR_NULL, NULL),
matthijs@1777: /* Ths penalty is applied when a vehicle reverses inside a depot (doesn't
matthijs@1777: * apply to ships, as they can just come out the other end). XXX: Is this a
matthijs@1777: * good value? */
rubidium@4431: SDT_VAR(Patches, npf_rail_depot_reverse_penalty,SLE_UINT, 0, 0, (NPF_TILE_LENGTH * 50), 0, 100000, 0, STR_NULL, NULL),
rubidium@4431: SDT_VAR(Patches, npf_buoy_penalty, SLE_UINT, 0, 0, (2 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
matthijs@1751: /* This penalty is applied when a ship makes a turn. It is bigger than the
matthijs@1751: * rail curve penalty, since ships (realisticly) have more trouble with
matthijs@1751: * making turns */
rubidium@4431: SDT_VAR(Patches, npf_water_curve_penalty, SLE_UINT, 0, 0, (NPF_TILE_LENGTH / 4), 0, 100000, 0, STR_NULL, NULL),
matthijs@1941: /* This is the penalty for road, same as for rail. */
rubidium@4431: SDT_VAR(Patches, npf_road_curve_penalty, SLE_UINT, 0, 0, 1, 0, 100000, 0, STR_NULL, NULL),
matthijs@2006: /* This is the penalty for level crossings, for both road and rail vehicles */
rubidium@4431: SDT_VAR(Patches, npf_crossing_penalty, SLE_UINT, 0, 0, (3 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
truelight@1271:
KUDr@3900:
KUDr@3900: // The maximum number of nodes to search
rubidium@4431: SDT_CONDBOOL(Patches, yapf.disable_node_optimization , 28, SL_MAX_VERSION, 0, 0, false , STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.max_search_nodes , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10000 , 500, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDBOOL(Patches, yapf.rail_firstred_twoway_eol , 28, SL_MAX_VERSION, 0, 0, true , STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_firstred_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_firstred_exit_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 100 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_lastred_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_lastred_exit_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 100 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_station_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 30 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_slope_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 2 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_curve45_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 1 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_curve90_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 6 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
KUDr@3900: // This penalty is applied when a train reverses inside a depot
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_depot_reverse_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 50 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
KUDr@3900: // This is the penalty for level crossings (for trains only)
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_crossing_penalty , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 3 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
KUDr@3900: // look-ahead how many signals are checked
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_look_ahead_max_signals, SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10 , 0, 100, 0, STR_NULL, NULL),
KUDr@3900: // look-ahead n-th red signal penalty polynomial: penalty = p2 * n^2 + p1 * n + p0
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_look_ahead_signal_p0 , SLE_INT , 28, SL_MAX_VERSION, 0, 0, 500 , -1000000, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_look_ahead_signal_p1 , SLE_INT , 28, SL_MAX_VERSION, 0, 0, -100 , -1000000, 1000000, 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR (Patches, yapf.rail_look_ahead_signal_p2 , SLE_INT , 28, SL_MAX_VERSION, 0, 0, 5 , -1000000, 1000000, 0, STR_NULL, NULL),
KUDr@4590: // penalties for too long or too short station platforms
KUDr@4590: SDT_CONDVAR (Patches, yapf.rail_longer_platform_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 8 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL),
KUDr@4590: SDT_CONDVAR (Patches, 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),
KUDr@4590: SDT_CONDVAR (Patches, yapf.rail_shorter_platform_penalty, SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 40 * YAPF_TILE_LENGTH, 0, 20000, 0, STR_NULL, NULL),
KUDr@4590: SDT_CONDVAR (Patches, 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),
KUDr@3981: // road vehicles - penalties
KUDr@4590: SDT_CONDVAR (Patches, yapf.road_slope_penalty , SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 2 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
KUDr@4590: SDT_CONDVAR (Patches, yapf.road_curve_penalty , SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 1 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
KUDr@4590: SDT_CONDVAR (Patches, yapf.road_crossing_penalty , SLE_UINT, 33, SL_MAX_VERSION, 0, 0, 3 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
KUDr@3900:
truelight@4300: /***************************************************************************/
truelight@4300: /* Terrain genation related patch options */
rubidium@4431: SDT_CONDVAR(Patches, land_generator, SLE_UINT8, 30, SL_MAX_VERSION, 0, MS, 1, 0, 1, 0, STR_CONFIG_PATCHES_LAND_GENERATOR, NULL),
rubidium@4431: SDT_CONDVAR(Patches, oil_refinery_limit, SLE_UINT8, 30, SL_MAX_VERSION, 0, 0, 16, 12, 48, 0, STR_CONFIG_PATCHES_OIL_REF_EDGE_DISTANCE, NULL),
rubidium@4431: SDT_CONDVAR(Patches, tgen_smoothness, SLE_UINT8, 30, SL_MAX_VERSION, 0, MS, 1, 0, 3, 0, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN, NULL),
rubidium@4431: SDT_CONDVAR(Patches, generation_seed, SLE_UINT32, 30, SL_MAX_VERSION, 0, 0, GENERATE_NEW_SEED, 0, MAX_UVALUE(uint32), 0, STR_NULL, NULL),
rubidium@4431: SDT_CONDVAR(Patches, tree_placer, SLE_UINT8, 30, SL_MAX_VERSION, 0, MS, 2, 0, 2, 0, STR_CONFIG_PATCHES_TREE_PLACER, NULL),
rubidium@4431: SDT_VAR (Patches, heightmap_rotation, SLE_UINT8, S, MS, 0, 0, 1, 0, STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION, NULL),
rubidium@4431: SDT_VAR (Patches, progress_update_interval, SLE_UINT16, S, 0, 200, 0, 5000, 0, STR_CONFIG_PATCHES_PROGRESS_UPDATE_INTERVAL, NULL),
rubidium@4431: SDT_VAR (Patches, se_flat_world_height, SLE_UINT8, S, 0, 0, 0, 15, 0, STR_CONFIG_PATCHES_SE_FLAT_WORLD_HEIGHT, NULL),
truelight@4300:
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@4431: SDT_VAR(CurrencySpec, to_euro, SLE_INT32, S, 0, 0, 0,1000, 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:
Darkvater@3628: const char *GRFProcessParams(const IniItem *item, uint index)
Darkvater@3628: {
Darkvater@3628: GRFConfig *c;
Darkvater@3628:
Darkvater@3628: /* Saving newgrf stuff to configuration, not done since it is kept the same */
Darkvater@3628: if (item == NULL) return NULL;
Darkvater@3628:
Darkvater@3628: /* Loading newgrf stuff from configuration file */
Darkvater@3628: c = calloc(1, sizeof(*c));
Darkvater@3628: c->filename = strdup(item->name);
Darkvater@3631:
Darkvater@3631: if (*item->value != '\0') {
Darkvater@3631: c->num_params = parse_intlist(item->value, (int*)c->param, lengthof(c->param));
Darkvater@3632: if (c->num_params == (byte)-1) {
Darkvater@3632: ShowInfoF("ini: error in array '%s'", item->name);
Darkvater@3632: c->num_params = 0;
Darkvater@3632: }
Darkvater@3628: }
Darkvater@3628:
Darkvater@3628: if (_first_grfconfig == NULL) {
Darkvater@3628: _first_grfconfig = c;
Darkvater@3628: } else {
Darkvater@3628: GRFConfig *c2;
Darkvater@3628: /* Attach the label to the end of the list */
Darkvater@3628: for (c2 = _first_grfconfig; c2->next != NULL; c2 = c2->next);
Darkvater@3628: c2->next = c;
Darkvater@3628: }
Darkvater@3628:
Darkvater@3628: return c->filename;
Darkvater@3628: }
truelight@0:
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:
Darkvater@3116: proc(ini, _gameopt_settings, "gameopt", &_opt_newgame);
Darkvater@3121: proc(ini, _patch_settings, "patches", &_patches_newgame);
Darkvater@3116: proc(ini, _currency_settings,"currency", &_custom_currency);
Darkvater@3116:
truelight@543: #ifdef ENABLE_NETWORK
Darkvater@3116: proc(ini, (const SettingDesc*)_network_settings, "network", NULL);
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 */
tron@1093: void LoadFromConfig(void)
truelight@0: {
truelight@0: IniFile *ini = ini_load(_config_file);
Darkvater@3116: HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
Darkvater@3628: ini_load_setting_list(ini, "newgrf", NULL, 0, GRFProcessParams);
truelight@0: ini_free(ini);
truelight@0: }
truelight@0:
Darkvater@3116: /** Save the values to the configuration file */
tron@1093: void SaveToConfig(void)
truelight@0: {
truelight@0: IniFile *ini = ini_load(_config_file);
Darkvater@3116: HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
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).
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: */
tron@3491: int32 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:
Darkvater@3119: if (flags & DC_EXEC) {
Darkvater@3121: Patches *patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
Darkvater@3119: void *var = ini_get_variable(&sd->save, patches_ptr);
Darkvater@3119: Write_ValidateSetting(var, sd, (int32)p2);
Darkvater@3119:
Darkvater@3119: InvalidateWindow(WC_GAME_OPTIONS, 0);
Darkvater@3119: }
Darkvater@3119:
Darkvater@3119: return 0;
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 */
Darkvater@4600: bool SetPatchValue(uint index, const Patches *object, 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) {
Darkvater@3118: void *var = ini_get_variable(&sd->save, object);
Darkvater@3118: Write_ValidateSetting(var, sd, value);
Darkvater@3121:
Darkvater@3121: if (_game_mode != GM_MENU) {
Darkvater@4600: void *var2 = ini_get_variable(&sd->save, &_patches_newgame);
tron@4077: Write_ValidateSetting(var2, sd, value);
Darkvater@3121: }
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:
Darkvater@3247: const SettingDesc *GetPatchFromName(const char *name, uint *i)
Darkvater@3119: {
Darkvater@3119: const SettingDesc *sd;
Darkvater@3119:
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:
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 */
Darkvater@4600: bool IConsoleSetPatchSetting(const char *name, int32 value)
Darkvater@3119: {
Darkvater@4600: bool success;
Darkvater@3119: uint index;
Darkvater@3119: const SettingDesc *sd = GetPatchFromName(name, &index);
Darkvater@3119: const Patches *patches_ptr;
Darkvater@3119: void *ptr;
Darkvater@3119:
Darkvater@3119: if (sd == NULL) {
Darkvater@3119: IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name);
Darkvater@4600: return true;
Darkvater@3119: }
Darkvater@3119:
Darkvater@3121: patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
Darkvater@3119: ptr = ini_get_variable(&sd->save, patches_ptr);
Darkvater@3119:
Darkvater@4600: success = SetPatchValue(index, patches_ptr, value);
Darkvater@4600: if (success && sd->desc.proc != NULL) sd->desc.proc(value);
Darkvater@4600: return success;
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) {
Darkvater@3119: IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name);
Darkvater@3119: return;
Darkvater@3119: }
Darkvater@3119:
Darkvater@3121: ptr = ini_get_variable(&sd->save, (_game_mode == GM_MENU) ? &_patches_newgame : &_patches);
Darkvater@3119:
Darkvater@3119: if (sd->desc.cmd == SDT_BOOLX) {
Darkvater@3119: snprintf(value, sizeof(value), (*(bool*)ptr == 1) ? "on" : "off");
Darkvater@3119: } else {
Darkvater@3119: snprintf(value, sizeof(value), "%d", (int32)ReadValue(ptr, sd->save.conv));
Darkvater@3119: }
Darkvater@3119:
Darkvater@3119: IConsolePrintF(_icolour_warn, "Current value for '%s' is: '%s' (min: %s%d, max: %d)",
Darkvater@3119: name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max);
Darkvater@3119: }
Darkvater@3119:
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;
Darkvater@3117: void *ptr = ini_get_variable(sld, object);
Darkvater@3117:
Darkvater@3117: if (!SlObjectMember(ptr, sld)) continue;
Darkvater@3117: }
Darkvater@3117: }
Darkvater@3117:
Darkvater@3117: /** Loadhandler for a list of global variables
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
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 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@3117: length += SlCalcObjMemberLength(&i->save);
Darkvater@3117: }
Darkvater@3117: SlSetLength(length);
Darkvater@3117:
Darkvater@3117: for (i = sd; i->save.cmd != SL_END; i++) {
Darkvater@3117: void *ptr = ini_get_variable(&i->save, object);
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:
Darkvater@3117: static void Load_OPTS(void)
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 */
Darkvater@3117: _opt = _opt_newgame;
Darkvater@3117: LoadSettings(_gameopt_settings, &_opt);
Darkvater@3117: }
Darkvater@3117:
Darkvater@3117: static void Save_OPTS(void)
Darkvater@3117: {
Darkvater@3117: SaveSettings(_gameopt_settings, &_opt);
Darkvater@3117: }
Darkvater@3117:
Darkvater@3121: static void Load_PATS(void)
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 */
Darkvater@3121: _patches = _patches_newgame;
Darkvater@3121: LoadSettings(_patch_settings, &_patches);
Darkvater@3121: }
Darkvater@3121:
Darkvater@3121: static void Save_PATS(void)
Darkvater@3121: {
Darkvater@3121: SaveSettings(_patch_settings, &_patches);
Darkvater@3121: }
Darkvater@3121:
Darkvater@1688: void CheckConfig(void)
Darkvater@1688: {
Darkvater@1688: // fix up news_display_opt from old to new
Darkvater@1688: int i;
Darkvater@1688: uint32 tmp;
Darkvater@1723: for (i = 0, tmp = _news_display_opt; i != 10; i++, tmp >>= 2) {
Darkvater@1688: if ((tmp & 0x3) == 0x3) { // old settings
Darkvater@1688: _news_display_opt = 0xAAAAAAAA; // set all news-messages to full 1010101010...
Darkvater@1688: break;
Darkvater@1688: }
Darkvater@1688: }
ludde@2044:
ludde@2044: // Increase old default values for pf_maxdepth and pf_maxlength
ludde@2044: // to support big networks.
Darkvater@3121: if (_patches_newgame.pf_maxdepth == 16 && _patches_newgame.pf_maxlength == 512) {
Darkvater@3121: _patches_newgame.pf_maxdepth = 48;
Darkvater@3121: _patches_newgame.pf_maxlength = 4096;
ludde@2044: }
Darkvater@1688: }
Darkvater@3112:
Darkvater@3121: void UpdatePatches(void)
Darkvater@3121: {
Darkvater@3121: /* Since old(er) savegames don't have any patches saved, we initialise
Darkvater@3121: * them with the default values just as it was in the old days.
Darkvater@3121: * Also new games need this copying-over */
Darkvater@3121: _patches = _patches_newgame; /* backwards compatibility */
Darkvater@3121: }
Darkvater@3121:
Darkvater@3112: const ChunkHandler _setting_chunk_handlers[] = {
Darkvater@3121: { 'OPTS', Save_OPTS, 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: }