settings.cpp

Go to the documentation of this file.
00001 /* $Id: settings.cpp 14311 2008-09-13 12:57:17Z rubidium $ */
00002 
00022 #include "stdafx.h"
00023 #include "openttd.h"
00024 #include "currency.h"
00025 #include "screenshot.h"
00026 #include "variables.h"
00027 #include "network/network.h"
00028 #include "network/network_internal.h"
00029 #include "settings_internal.h"
00030 #include "command_func.h"
00031 #include "console.h"
00032 #include "saveload.h"
00033 #include "npf.h"
00034 #include "yapf/yapf.h"
00035 #include "newgrf.h"
00036 #include "newgrf_config.h"
00037 #include "genworld.h"
00038 #include "rail.h"
00039 #include "train.h"
00040 #include "news.h"
00041 #include "window_func.h"
00042 #include "strings_func.h"
00043 #include "vehicle_func.h"
00044 #include "sound_func.h"
00045 #include "core/alloc_func.hpp"
00046 #include "player_func.h"
00047 #ifdef WITH_FREETYPE
00048 #include "fontcache.h"
00049 #endif
00050 #include "spritecache.h"
00051 #include "transparency.h"
00052 #include "string_func.h"
00053 #include "gui.h"
00054 #include "town.h"
00055 #include "video/video_driver.hpp"
00056 #include "sound/sound_driver.hpp"
00057 #include "music/music_driver.hpp"
00058 #include "blitter/factory.hpp"
00059 
00060 #include "table/strings.h"
00061 
00062 GameOptions _opt;
00063 GameOptions _opt_newgame;
00064 GameOptions *_opt_ptr;
00065 Patches _patches;
00066 Patches _patches_newgame;
00067 
00068 struct IniFile;
00069 struct IniItem;
00070 struct IniGroup;
00071 struct SettingsMemoryPool;
00072 
00073 typedef const char *SettingListCallbackProc(const IniItem *item, uint index);
00074 typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
00075 typedef void SettingDescProcList(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc);
00076 
00077 static void pool_init(SettingsMemoryPool **pool);
00078 static void *pool_alloc(SettingsMemoryPool **pool, uint size);
00079 static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, uint size);
00080 static void pool_free(SettingsMemoryPool **pool);
00081 static bool IsSignedVarMemType(VarType vt);
00082 
00083 struct SettingsMemoryPool {
00084   uint pos,size;
00085   SettingsMemoryPool *next;
00086   byte mem[1];
00087 };
00088 
00089 static SettingsMemoryPool *pool_new(uint minsize)
00090 {
00091   SettingsMemoryPool *p;
00092   if (minsize < 4096 - 12) minsize = 4096 - 12;
00093 
00094   p = (SettingsMemoryPool*)MallocT<byte>(sizeof(SettingsMemoryPool) - 1 + minsize);
00095   p->pos = 0;
00096   p->size = minsize;
00097   p->next = NULL;
00098   return p;
00099 }
00100 
00101 static void pool_init(SettingsMemoryPool **pool)
00102 {
00103   *pool = pool_new(0);
00104 }
00105 
00106 static void *pool_alloc(SettingsMemoryPool **pool, uint size)
00107 {
00108   uint pos;
00109   SettingsMemoryPool *p = *pool;
00110 
00111   size = Align(size, sizeof(void*));
00112 
00113   /* first check if there's memory in the next pool */
00114   if (p->next && p->next->pos + size <= p->next->size) {
00115     p = p->next;
00116   /* then check if there's not memory in the cur pool */
00117   } else if (p->pos + size > p->size) {
00118     SettingsMemoryPool *n = pool_new(size);
00119     *pool = n;
00120     n->next = p;
00121     p = n;
00122   }
00123 
00124   pos = p->pos;
00125   p->pos += size;
00126   return p->mem + pos;
00127 }
00128 
00129 static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, uint size)
00130 {
00131   byte *p = (byte*)pool_alloc(pool, size + 1);
00132   p[size] = 0;
00133   memcpy(p, mem, size);
00134   return p;
00135 }
00136 
00137 static void pool_free(SettingsMemoryPool **pool)
00138 {
00139   SettingsMemoryPool *p = *pool, *n;
00140   *pool = NULL;
00141   while (p) {
00142     n = p->next;
00143     free(p);
00144     p = n;
00145   }
00146 }
00147 
00149 struct IniItem {
00150   char *name;
00151   char *value;
00152   char *comment;
00153   IniItem *next;
00154 };
00155 
00156 struct IniGroup {
00157   char *name;        
00158   char *comment;     
00159   IniItem *item, **last_item;
00160   IniGroup *next;
00161   IniFile *ini;
00162   IniGroupType type; 
00163 };
00164 
00165 struct IniFile {
00166   SettingsMemoryPool *pool;
00167   IniGroup *group, **last_group;
00168   char *comment;     
00169 };
00170 
00172 static IniFile *ini_alloc()
00173 {
00174   IniFile *ini;
00175   SettingsMemoryPool *pool;
00176   pool_init(&pool);
00177   ini = (IniFile*)pool_alloc(&pool, sizeof(IniFile));
00178   ini->pool = pool;
00179   ini->group = NULL;
00180   ini->last_group = &ini->group;
00181   ini->comment = NULL;
00182   return ini;
00183 }
00184 
00186 static IniGroup *ini_group_alloc(IniFile *ini, const char *grpt, int len)
00187 {
00188   IniGroup *grp = (IniGroup*)pool_alloc(&ini->pool, sizeof(IniGroup));
00189   grp->ini = ini;
00190   grp->name = (char*)pool_strdup(&ini->pool, grpt, len);
00191   if (!strcmp(grp->name, "newgrf") || !strcmp(grp->name, "servers") || !strcmp(grp->name, "bans")) {
00192     grp->type = IGT_LIST;
00193   } else {
00194     grp->type = IGT_VARIABLES;
00195   }
00196   grp->next = NULL;
00197   grp->item = NULL;
00198   grp->comment = NULL;
00199   grp->last_item = &grp->item;
00200   *ini->last_group = grp;
00201   ini->last_group = &grp->next;
00202   return grp;
00203 }
00204 
00205 static IniItem *ini_item_alloc(IniGroup *group, const char *name, int len)
00206 {
00207   IniItem *item = (IniItem*)pool_alloc(&group->ini->pool, sizeof(IniItem));
00208   item->name = (char*)pool_strdup(&group->ini->pool, name, len);
00209   item->next = NULL;
00210   item->comment = NULL;
00211   item->value = NULL;
00212   *group->last_item = item;
00213   group->last_item = &item->next;
00214   return item;
00215 }
00216 
00218 static IniFile *ini_load(const char *filename)
00219 {
00220   char buffer[1024], c, *s, *t, *e;
00221   FILE *in;
00222   IniFile *ini;
00223   IniGroup *group = NULL;
00224   IniItem *item;
00225 
00226   char *comment = NULL;
00227   uint comment_size = 0;
00228   uint comment_alloc = 0;
00229 
00230   ini = ini_alloc();
00231 
00232   in = fopen(filename, "r");
00233   if (in == NULL) return ini;
00234 
00235   /* for each line in the file */
00236   while (fgets(buffer, sizeof(buffer), in)) {
00237 
00238     /* trim whitespace from the left side */
00239     for (s = buffer; *s == ' ' || *s == '\t'; s++) {}
00240 
00241     /* trim whitespace from right side. */
00242     e = s + strlen(s);
00243     while (e > s && ((c=e[-1]) == '\n' || c == '\r' || c == ' ' || c == '\t')) e--;
00244     *e = '\0';
00245 
00246     /* skip comments and empty lines */
00247     if (*s == '#' || *s == ';' || *s == '\0') {
00248       uint ns = comment_size + (e - s + 1);
00249       uint a = comment_alloc;
00250       uint pos;
00251       /* add to comment */
00252       if (ns > a) {
00253         a = max(a, 128U);
00254         do a*=2; while (a < ns);
00255         comment = ReallocT(comment, comment_alloc = a);
00256       }
00257       pos = comment_size;
00258       comment_size += (e - s + 1);
00259       comment[pos + e - s] = '\n'; // comment newline
00260       memcpy(comment + pos, s, e - s); // copy comment contents
00261       continue;
00262     }
00263 
00264     /* it's a group? */
00265     if (s[0] == '[') {
00266       if (e[-1] != ']') {
00267         ShowInfoF("ini: invalid group name '%s'", buffer);
00268       } else {
00269         e--;
00270       }
00271       s++; // skip [
00272       group = ini_group_alloc(ini, s, e - s);
00273       if (comment_size) {
00274         group->comment = (char*)pool_strdup(&ini->pool, comment, comment_size);
00275         comment_size = 0;
00276       }
00277     } else if (group) {
00278       /* find end of keyname */
00279       if (*s == '\"') {
00280         s++;
00281         for (t = s; *t != '\0' && *t != '\"'; t++) {}
00282         if (*t == '\"') *t = ' ';
00283       } else {
00284         for (t = s; *t != '\0' && *t != '=' && *t != '\t' && *t != ' '; t++) {}
00285       }
00286 
00287       /* it's an item in an existing group */
00288       item = ini_item_alloc(group, s, t-s);
00289       if (comment_size) {
00290         item->comment = (char*)pool_strdup(&ini->pool, comment, comment_size);
00291         comment_size = 0;
00292       }
00293 
00294       /* find start of parameter */
00295       while (*t == '=' || *t == ' ' || *t == '\t') t++;
00296 
00297 
00298       /* remove starting quotation marks */
00299       if (*t == '\"') t++;
00300       /* remove ending quotation marks */
00301       e = t + strlen(t);
00302       if (e > t && e[-1] == '\"') e--;
00303       *e = '\0';
00304 
00305       item->value = (char*)pool_strdup(&ini->pool, t, e - t);
00306     } else {
00307       /* it's an orphan item */
00308       ShowInfoF("ini: '%s' outside of group", buffer);
00309     }
00310   }
00311 
00312   if (comment_size > 0) {
00313     ini->comment = (char*)pool_strdup(&ini->pool, comment, comment_size);
00314     comment_size = 0;
00315   }
00316 
00317   free(comment);
00318   fclose(in);
00319 
00320   return ini;
00321 }
00322 
00324 static IniGroup *ini_getgroup(IniFile *ini, const char *name, int len)
00325 {
00326   IniGroup *group;
00327 
00328   if (len == -1) len = strlen(name);
00329 
00330   /* does it exist already? */
00331   for (group = ini->group; group; group = group->next)
00332     if (!memcmp(group->name, name, len) && group->name[len] == 0)
00333       return group;
00334 
00335   /* otherwise make a new one */
00336   group = ini_group_alloc(ini, name, len);
00337   group->comment = (char*)pool_strdup(&ini->pool, "\n", 1);
00338   return group;
00339 }
00340 
00342 static IniItem *ini_getitem(IniGroup *group, const char *name, bool create)
00343 {
00344   IniItem *item;
00345   uint len = strlen(name);
00346 
00347   for (item = group->item; item; item = item->next)
00348     if (strcmp(item->name, name) == 0) return item;
00349 
00350   if (!create) return NULL;
00351 
00352   /* otherwise make a new one */
00353   return ini_item_alloc(group, name, len);
00354 }
00355 
00357 static bool ini_save(const char *filename, IniFile *ini)
00358 {
00359   FILE *f;
00360   IniGroup *group;
00361   IniItem *item;
00362 
00363   f = fopen(filename, "w");
00364   if (f == NULL) return false;
00365 
00366   for (group = ini->group; group != NULL; group = group->next) {
00367     if (group->comment) fputs(group->comment, f);
00368     fprintf(f, "[%s]\n", group->name);
00369     for (item = group->item; item != NULL; item = item->next) {
00370       assert(item->value != NULL);
00371       if (item->comment != NULL) fputs(item->comment, f);
00372 
00373       /* protect item->name with quotes if needed */
00374       if (strchr(item->name, ' ') != NULL) {
00375         fprintf(f, "\"%s\"", item->name);
00376       } else {
00377         fprintf(f, "%s", item->name);
00378       }
00379 
00380       /* Don't give an equal sign to list items that don't have a parameter */
00381       if (group->type == IGT_LIST && *item->value == '\0') {
00382         fprintf(f, "\n");
00383       } else {
00384         fprintf(f, " = %s\n", item->value);
00385       }
00386     }
00387   }
00388   if (ini->comment) fputs(ini->comment, f);
00389 
00390   fclose(f);
00391   return true;
00392 }
00393 
00394 static void ini_free(IniFile *ini)
00395 {
00396   pool_free(&ini->pool);
00397 }
00398 
00404 static int lookup_oneofmany(const char *many, const char *one, int onelen)
00405 {
00406   const char *s;
00407   int idx;
00408 
00409   if (onelen == -1) onelen = strlen(one);
00410 
00411   /* check if it's an integer */
00412   if (*one >= '0' && *one <= '9')
00413     return strtoul(one, NULL, 0);
00414 
00415   idx = 0;
00416   for (;;) {
00417     /* find end of item */
00418     s = many;
00419     while (*s != '|' && *s != 0) s++;
00420     if (s - many == onelen && !memcmp(one, many, onelen)) return idx;
00421     if (*s == 0) return -1;
00422     many = s + 1;
00423     idx++;
00424   }
00425 }
00426 
00432 static uint32 lookup_manyofmany(const char *many, const char *str)
00433 {
00434   const char *s;
00435   int r;
00436   uint32 res = 0;
00437 
00438   for (;;) {
00439     /* skip "whitespace" */
00440     while (*str == ' ' || *str == '\t' || *str == '|') str++;
00441     if (*str == 0) break;
00442 
00443     s = str;
00444     while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++;
00445 
00446     r = lookup_oneofmany(many, str, s - str);
00447     if (r == -1) return (uint32)-1;
00448 
00449     SetBit(res, r); // value found, set it
00450     if (*s == 0) break;
00451     str = s + 1;
00452   }
00453   return res;
00454 }
00455 
00462 static int parse_intlist(const char *p, int *items, int maxitems)
00463 {
00464   int n = 0, v;
00465   char *end;
00466 
00467   for (;;) {
00468     v = strtol(p, &end, 0);
00469     if (p == end || n == maxitems) return -1;
00470     p = end;
00471     items[n++] = v;
00472     if (*p == '\0') break;
00473     if (*p != ',' && *p != ' ') return -1;
00474     p++;
00475   }
00476 
00477   return n;
00478 }
00479 
00486 static bool load_intlist(const char *str, void *array, int nelems, VarType type)
00487 {
00488   int items[64];
00489   int i, nitems;
00490 
00491   if (str == NULL) {
00492     memset(items, 0, sizeof(items));
00493     nitems = nelems;
00494   } else {
00495     nitems = parse_intlist(str, items, lengthof(items));
00496     if (nitems != nelems) return false;
00497   }
00498 
00499   switch (type) {
00500   case SLE_VAR_BL:
00501   case SLE_VAR_I8:
00502   case SLE_VAR_U8:
00503     for (i = 0; i != nitems; i++) ((byte*)array)[i] = items[i];
00504     break;
00505   case SLE_VAR_I16:
00506   case SLE_VAR_U16:
00507     for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i];
00508     break;
00509   case SLE_VAR_I32:
00510   case SLE_VAR_U32:
00511     for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i];
00512     break;
00513   default: NOT_REACHED();
00514   }
00515 
00516   return true;
00517 }
00518 
00525 static void make_intlist(char *buf, const void *array, int nelems, VarType type)
00526 {
00527   int i, v = 0;
00528   const byte *p = (const byte*)array;
00529 
00530   for (i = 0; i != nelems; i++) {
00531     switch (type) {
00532     case SLE_VAR_BL:
00533     case SLE_VAR_I8:  v = *(int8*)p;   p += 1; break;
00534     case SLE_VAR_U8:  v = *(byte*)p;   p += 1; break;
00535     case SLE_VAR_I16: v = *(int16*)p;  p += 2; break;
00536     case SLE_VAR_U16: v = *(uint16*)p; p += 2; break;
00537     case SLE_VAR_I32: v = *(int32*)p;  p += 4; break;
00538     case SLE_VAR_U32: v = *(uint32*)p; p += 4; break;
00539     default: NOT_REACHED();
00540     }
00541     buf += sprintf(buf, (i == 0) ? "%d" : ",%d", v);
00542   }
00543 }
00544 
00549 static void make_oneofmany(char *buf, const char *many, int id)
00550 {
00551   int orig_id = id;
00552 
00553   /* Look for the id'th element */
00554   while (--id >= 0) {
00555     for (; *many != '|'; many++) {
00556       if (*many == '\0') { // not found
00557         sprintf(buf, "%d", orig_id);
00558         return;
00559       }
00560     }
00561     many++; // pass the |-character
00562   }
00563 
00564   /* copy string until next item (|) or the end of the list if this is the last one */
00565   while (*many != '\0' && *many != '|') *buf++ = *many++;
00566   *buf = '\0';
00567 }
00568 
00574 static void make_manyofmany(char *buf, const char *many, uint32 x)
00575 {
00576   const char *start;
00577   int i = 0;
00578   bool init = true;
00579 
00580   for (; x != 0; x >>= 1, i++) {
00581     start = many;
00582     while (*many != 0 && *many != '|') many++; // advance to the next element
00583 
00584     if (HasBit(x, 0)) { // item found, copy it
00585       if (!init) *buf++ = '|';
00586       init = false;
00587       if (start == many) {
00588         buf += sprintf(buf, "%d", i);
00589       } else {
00590         memcpy(buf, start, many - start);
00591         buf += many - start;
00592       }
00593     }
00594 
00595     if (*many == '|') many++;
00596   }
00597 
00598   *buf = '\0';
00599 }
00600 
00605 static const void *string_to_val(const SettingDescBase *desc, const char *str)
00606 {
00607   switch (desc->cmd) {
00608   case SDT_NUMX: {
00609     char *end;
00610     unsigned long val = strtoul(str, &end, 0);
00611     if (*end != '\0') ShowInfoF("ini: trailing characters at end of setting '%s'", desc->name);
00612     return (void*)val;
00613   }
00614   case SDT_ONEOFMANY: {
00615     long r = lookup_oneofmany(desc->many, str, -1);
00616     /* if the first attempt of conversion from string to the appropriate value fails,
00617      * look if we have defined a converter from old value to new value. */
00618     if (r == -1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str);
00619     if (r != -1) return (void*)r; //and here goes converted value
00620     ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name); //sorry, we failed
00621     return 0;
00622   }
00623   case SDT_MANYOFMANY: {
00624     unsigned long r = lookup_manyofmany(desc->many, str);
00625     if (r != (unsigned long)-1) return (void*)r;
00626     ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name);
00627     return 0;
00628   }
00629   case SDT_BOOLX:
00630     if (strcmp(str, "true")  == 0 || strcmp(str, "on")  == 0 || strcmp(str, "1") == 0)
00631       return (void*)true;
00632     if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0)
00633       return (void*)false;
00634     ShowInfoF("ini: invalid setting value '%s' for '%s'", str, desc->name);
00635     break;
00636 
00637   case SDT_STRING:
00638   case SDT_INTLIST: return str;
00639   default: break;
00640   }
00641 
00642   return NULL;
00643 }
00644 
00652 static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
00653 {
00654   const SettingDescBase *sdb = &sd->desc;
00655 
00656   if (sdb->cmd != SDT_BOOLX &&
00657       sdb->cmd != SDT_NUMX &&
00658       sdb->cmd != SDT_ONEOFMANY &&
00659       sdb->cmd != SDT_MANYOFMANY) {
00660     return;
00661   }
00662 
00663   /* We cannot know the maximum value of a bitset variable, so just have faith */
00664   if (sdb->cmd != SDT_MANYOFMANY) {
00665     /* We need to take special care of the uint32 type as we receive from the function
00666      * a signed integer. While here also bail out on 64-bit settings as those are not
00667      * supported. Unsigned 8 and 16-bit variables are safe since they fit into a signed
00668      * 32-bit variable
00669      * TODO: Support 64-bit settings/variables */
00670     switch (GetVarMemType(sd->save.conv)) {
00671       case SLE_VAR_BL:
00672       case SLE_VAR_I8:
00673       case SLE_VAR_U8:
00674       case SLE_VAR_I16:
00675       case SLE_VAR_U16:
00676       case SLE_VAR_I32: {
00677         /* Override the minimum value. No value below sdb->min, except special value 0 */
00678         int32 min = ((sdb->flags & SGF_0ISDISABLED) && val <= sdb->min) ? 0 : sdb->min;
00679         val = Clamp(val, min, sdb->max);
00680       } break;
00681       case SLE_VAR_U32: {
00682         /* Override the minimum value. No value below sdb->min, except special value 0 */
00683         uint min = ((sdb->flags & SGF_0ISDISABLED) && (uint)val <= (uint)sdb->min) ? 0 : sdb->min;
00684         WriteValue(ptr, SLE_VAR_U32, (int64)ClampU(val, min, sdb->max));
00685         return;
00686       }
00687       case SLE_VAR_I64:
00688       case SLE_VAR_U64:
00689       default: NOT_REACHED(); break;
00690     }
00691   }
00692 
00693   WriteValue(ptr, sd->save.conv, (int64)val);
00694 }
00695 
00702 static void ini_load_settings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
00703 {
00704   IniGroup *group;
00705   IniGroup *group_def = ini_getgroup(ini, grpname, -1);
00706   IniItem *item;
00707   const void *p;
00708   void *ptr;
00709   const char *s;
00710 
00711   for (; sd->save.cmd != SL_END; sd++) {
00712     const SettingDescBase *sdb = &sd->desc;
00713     const SaveLoad        *sld = &sd->save;
00714 
00715     if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
00716 
00717     /* XXX - wtf is this?? (group override?) */
00718     s = strchr(sdb->name, '.');
00719     if (s != NULL) {
00720       group = ini_getgroup(ini, sdb->name, s - sdb->name);
00721       s++;
00722     } else {
00723       s = sdb->name;
00724       group = group_def;
00725     }
00726 
00727     item = ini_getitem(group, s, false);
00728     p = (item == NULL) ? sdb->def : string_to_val(sdb, item->value);
00729     ptr = GetVariableAddress(object, sld);
00730 
00731     switch (sdb->cmd) {
00732     case SDT_BOOLX: /* All four are various types of (integer) numbers */
00733     case SDT_NUMX:
00734     case SDT_ONEOFMANY:
00735     case SDT_MANYOFMANY:
00736       Write_ValidateSetting(ptr, sd, (unsigned long)p); break;
00737 
00738     case SDT_STRING:
00739       switch (GetVarMemType(sld->conv)) {
00740         case SLE_VAR_STRB:
00741         case SLE_VAR_STRBQ:
00742           if (p != NULL) ttd_strlcpy((char*)ptr, (const char*)p, sld->length);
00743           break;
00744         case SLE_VAR_STR:
00745         case SLE_VAR_STRQ:
00746           if (p != NULL) {
00747             free(*(char**)ptr);
00748             *(char**)ptr = strdup((const char*)p);
00749           }
00750           break;
00751         case SLE_VAR_CHAR: *(char*)ptr = *(char*)p; break;
00752         default: NOT_REACHED(); break;
00753       }
00754       break;
00755 
00756     case SDT_INTLIST: {
00757       if (!load_intlist((const char*)p, ptr, sld->length, GetVarMemType(sld->conv)))
00758         ShowInfoF("ini: error in array '%s'", sdb->name);
00759       break;
00760     }
00761     default: NOT_REACHED(); break;
00762     }
00763   }
00764 }
00765 
00777 static void ini_save_settings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
00778 {
00779   IniGroup *group_def = NULL, *group;
00780   IniItem *item;
00781   char buf[512];
00782   const char *s;
00783   void *ptr;
00784 
00785   for (; sd->save.cmd != SL_END; sd++) {
00786     const SettingDescBase *sdb = &sd->desc;
00787     const SaveLoad        *sld = &sd->save;
00788 
00789     /* If the setting is not saved to the configuration
00790      * file, just continue with the next setting */
00791     if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
00792     if (sld->conv & SLF_CONFIG_NO) continue;
00793 
00794     /* XXX - wtf is this?? (group override?) */
00795     s = strchr(sdb->name, '.');
00796     if (s != NULL) {
00797       group = ini_getgroup(ini, sdb->name, s - sdb->name);
00798       s++;
00799     } else {
00800       if (group_def == NULL) group_def = ini_getgroup(ini, grpname, -1);
00801       s = sdb->name;
00802       group = group_def;
00803     }
00804 
00805     item = ini_getitem(group, s, true);
00806     ptr = GetVariableAddress(object, sld);
00807 
00808     if (item->value != NULL) {
00809       /* check if the value is the same as the old value */
00810       const void *p = string_to_val(sdb, item->value);
00811 
00812       /* The main type of a variable/setting is in bytes 8-15
00813        * The subtype (what kind of numbers do we have there) is in 0-7 */
00814       switch (sdb->cmd) {
00815       case SDT_BOOLX:
00816       case SDT_NUMX:
00817       case SDT_ONEOFMANY:
00818       case SDT_MANYOFMANY:
00819         switch (GetVarMemType(sld->conv)) {
00820         case SLE_VAR_BL:
00821           if (*(bool*)ptr == (p != NULL)) continue;
00822           break;
00823         case SLE_VAR_I8:
00824         case SLE_VAR_U8:
00825           if (*(byte*)ptr == (byte)(unsigned long)p) continue;
00826           break;
00827         case SLE_VAR_I16:
00828         case SLE_VAR_U16:
00829           if (*(uint16*)ptr == (uint16)(unsigned long)p) continue;
00830           break;
00831         case SLE_VAR_I32:
00832         case SLE_VAR_U32:
00833           if (*(uint32*)ptr == (uint32)(unsigned long)p) continue;
00834           break;
00835         default: NOT_REACHED();
00836         }
00837         break;
00838       default: break; /* Assume the other types are always changed */
00839       }
00840     }
00841 
00842     /* Value has changed, get the new value and put it into a buffer */
00843     switch (sdb->cmd) {
00844     case SDT_BOOLX:
00845     case SDT_NUMX:
00846     case SDT_ONEOFMANY:
00847     case SDT_MANYOFMANY: {
00848       uint32 i = (uint32)ReadValue(ptr, sld->conv);
00849 
00850       switch (sdb->cmd) {
00851       case SDT_BOOLX:      strcpy(buf, (i != 0) ? "true" : "false"); break;
00852       case SDT_NUMX:       sprintf(buf, IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break;
00853       case SDT_ONEOFMANY:  make_oneofmany(buf, sdb->many, i); break;
00854       case SDT_MANYOFMANY: make_manyofmany(buf, sdb->many, i); break;
00855       default: NOT_REACHED();
00856       }
00857     } break;
00858 
00859     case SDT_STRING:
00860       switch (GetVarMemType(sld->conv)) {
00861       case SLE_VAR_STRB: strcpy(buf, (char*)ptr); break;
00862       case SLE_VAR_STRBQ:sprintf(buf, "\"%s\"", (char*)ptr); break;
00863       case SLE_VAR_STR:  strcpy(buf, *(char**)ptr); break;
00864       case SLE_VAR_STRQ: sprintf(buf, "\"%s\"", *(char**)ptr); break;
00865       case SLE_VAR_CHAR: sprintf(buf, "\"%c\"", *(char*)ptr); break;
00866       default: NOT_REACHED();
00867       }
00868       break;
00869 
00870     case SDT_INTLIST:
00871       make_intlist(buf, ptr, sld->length, GetVarMemType(sld->conv));
00872       break;
00873     default: NOT_REACHED();
00874     }
00875 
00876     /* The value is different, that means we have to write it to the ini */
00877     item->value = (char*)pool_strdup(&ini->pool, buf, strlen(buf));
00878   }
00879 }
00880 
00893 static void ini_load_setting_list(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc)
00894 {
00895   IniGroup *group = ini_getgroup(ini, grpname, -1);
00896   IniItem *item;
00897   const char *entry;
00898   uint i, j;
00899 
00900   if (group == NULL) return;
00901 
00902   for (i = j = 0, item = group->item; item != NULL; item = item->next) {
00903     entry = (proc != NULL) ? proc(item, i++) : item->name;
00904 
00905     if (entry == NULL || list == NULL) continue;
00906 
00907     if (j == len) break;
00908     list[j++] = strdup(entry);
00909   }
00910 }
00911 
00921 static void ini_save_setting_list(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc)
00922 {
00923   IniGroup *group = ini_getgroup(ini, grpname, -1);
00924   IniItem *item = NULL;
00925   const char *entry;
00926   uint i;
00927   bool first = true;
00928 
00929   if (proc == NULL && list == NULL) return;
00930   if (group == NULL) return;
00931   group->item = NULL;
00932 
00933   for (i = 0; i != len; i++) {
00934     entry = (proc != NULL) ? proc(NULL, i) : list[i];
00935 
00936     if (entry == NULL || *entry == '\0') continue;
00937 
00938     if (first) { // add first item to the head of the group
00939       item = ini_item_alloc(group, entry, strlen(entry));
00940       item->value = item->name;
00941       group->item = item;
00942       first = false;
00943     } else { // all other items are attached to the previous one
00944       item->next = ini_item_alloc(group, entry, strlen(entry));
00945       item = item->next;
00946       item->value = item->name;
00947     }
00948   }
00949 }
00950 
00951 //***************************
00952 // OTTD specific INI stuff
00953 //***************************
00954 
00991 #define NSD_GENERAL(name, def, cmd, guiflags, min, max, interval, many, str, proc, load)\
00992   {name, (const void*)(def), {cmd}, {guiflags}, min, max, interval, many, str, proc, load}
00993 
00994 /* Macros for various objects to go in the configuration file.
00995  * This section is for global variables */
00996 #define SDTG_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, var, length, def, min, max, interval, full, str, proc, from, to)\
00997   {NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, proc, NULL), SLEG_GENERAL(sle_cmd, var, type | flags, length, from, to)}
00998 
00999 #define SDTG_CONDVAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc, from, to)\
01000   SDTG_GENERAL(name, SDT_NUMX, SL_VAR, type, flags, guiflags, var, 0, def, min, max, interval, NULL, str, proc, from, to)
01001 #define SDTG_VAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc)\
01002   SDTG_CONDVAR(name, type, flags, guiflags, var, def, min, max, interval, str, proc, 0, SL_MAX_VERSION)
01003 
01004 #define SDTG_CONDBOOL(name, flags, guiflags, var, def, str, proc, from, to)\
01005   SDTG_GENERAL(name, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, var, 0, def, 0, 1, 0, NULL, str, proc, from, to)
01006 #define SDTG_BOOL(name, flags, guiflags, var, def, str, proc)\
01007   SDTG_CONDBOOL(name, flags, guiflags, var, def, str, proc, 0, SL_MAX_VERSION)
01008 
01009 #define SDTG_CONDLIST(name, type, length, flags, guiflags, var, def, str, proc, from, to)\
01010   SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, proc, from, to)
01011 #define SDTG_LIST(name, type, flags, guiflags, var, def, str, proc)\
01012   SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, proc, 0, SL_MAX_VERSION)
01013 
01014 #define SDTG_CONDSTR(name, type, length, flags, guiflags, var, def, str, proc, from, to)\
01015   SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, proc, from, to)
01016 #define SDTG_STR(name, type, flags, guiflags, var, def, str, proc)\
01017   SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, proc, 0, SL_MAX_VERSION)
01018 
01019 #define SDTG_CONDOMANY(name, type, flags, guiflags, var, def, max, full, str, proc, from, to)\
01020   SDTG_GENERAL(name, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, max, 0, full, str, proc, from, to)
01021 #define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, proc)\
01022   SDTG_CONDOMANY(name, type, flags, guiflags, var, def, max, full, str, proc, 0, SL_MAX_VERSION)
01023 
01024 #define SDTG_CONDMMANY(name, type, flags, guiflags, var, def, full, str, proc, from, to)\
01025   SDTG_GENERAL(name, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, 0, 0, full, str, proc, from, to)
01026 #define SDTG_MMANY(name, type, flags, guiflags, var, def, full, str, proc)\
01027   SDTG_CONDMMANY(name, type, flags, guiflags, var, def, full, str, proc, 0, SL_MAX_VERSION)
01028 
01029 #define SDTG_CONDNULL(length, from, to)\
01030   {{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLEG_CONDNULL(length, from, to)}
01031 
01032 #define SDTG_END() {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLEG_END()}
01033 
01034 /* Macros for various objects to go in the configuration file.
01035  * This section is for structures where their various members are saved */
01036 #define SDT_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, base, var, length, def, min, max, interval, full, str, proc, load, from, to)\
01037   {NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, proc, load), SLE_GENERAL(sle_cmd, base, var, type | flags, length, from, to)}
01038 
01039 #define SDT_CONDVAR(base, var, type, from, to, flags, guiflags, def, min, max, interval, str, proc)\
01040   SDT_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, base, var, 1, def, min, max, interval, NULL, str, proc, NULL, from, to)
01041 #define SDT_VAR(base, var, type, flags, guiflags, def, min, max, interval, str, proc)\
01042   SDT_CONDVAR(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, min, max, interval, str, proc)
01043 
01044 #define SDT_CONDBOOL(base, var, from, to, flags, guiflags, def, str, proc)\
01045   SDT_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, base, var, 1, def, 0, 1, 0, NULL, str, proc, NULL, from, to)
01046 #define SDT_BOOL(base, var, flags, guiflags, def, str, proc)\
01047   SDT_CONDBOOL(base, var, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc)
01048 
01049 #define SDT_CONDLIST(base, var, type, from, to, flags, guiflags, def, str, proc)\
01050   SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, proc, NULL, from, to)
01051 #define SDT_LIST(base, var, type, flags, guiflags, def, str, proc)\
01052   SDT_CONDLIST(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc)
01053 #define SDT_CONDLISTO(base, var, length, type, from, to, flags, guiflags, def, str, proc)\
01054   SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, length, def, 0, 0, 0, NULL, str, proc, NULL, from, to)
01055 
01056 #define SDT_CONDSTR(base, var, type, from, to, flags, guiflags, def, str, proc)\
01057   SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, proc, NULL, from, to)
01058 #define SDT_STR(base, var, type, flags, guiflags, def, str, proc)\
01059   SDT_CONDSTR(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc)
01060 #define SDT_CONDSTRO(base, var, length, type, from, to, flags, def, str, proc)\
01061   SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, 0, base, var, length, def, 0, 0, NULL, str, proc, from, to)
01062 
01063 #define SDT_CONDCHR(base, var, from, to, flags, guiflags, def, str, proc)\
01064   SDT_GENERAL(#var, SDT_STRING, SL_VAR, SLE_CHAR, flags, guiflags, base, var, 1, def, 0, 0, 0, NULL, str, proc, NULL, from, to)
01065 #define SDT_CHR(base, var, flags, guiflags, def, str, proc)\
01066   SDT_CONDCHR(base, var, 0, SL_MAX_VERSION, flags, guiflags, def, str, proc)
01067 
01068 #define SDT_CONDOMANY(base, var, type, from, to, flags, guiflags, def, max, full, str, proc, load)\
01069   SDT_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, max, 0, full, str, proc, load, from, to)
01070 #define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, proc, load)\
01071   SDT_CONDOMANY(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, max, full, str, proc, load)
01072 
01073 #define SDT_CONDMMANY(base, var, type, from, to, flags, guiflags, def, full, str, proc)\
01074   SDT_GENERAL(#var, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, 0, 0, full, str, proc, NULL, from, to)
01075 #define SDT_MMANY(base, var, type, flags, guiflags, def, full, str, proc)\
01076   SDT_CONDMMANY(base, var, type, 0, SL_MAX_VERSION, flags, guiflags, def, full, str, proc)
01077 
01078 #define SDT_CONDNULL(length, from, to)\
01079   {{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLE_CONDNULL(length, from, to)}
01080 
01081 #define SDT_END() {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, NULL, NULL}, SLE_END()}
01082 
01083 /* Shortcuts for macros below. Logically if we don't save the value
01084  * we also don't sync it in a network game */
01085 #define S SLF_SAVE_NO | SLF_NETWORK_NO
01086 #define C SLF_CONFIG_NO
01087 #define N SLF_NETWORK_NO
01088 
01089 #define D0 SGF_0ISDISABLED
01090 #define NC SGF_NOCOMMA
01091 #define MS SGF_MULTISTRING
01092 #define NO SGF_NETWORK_ONLY
01093 #define CR SGF_CURRENCY
01094 #define NN SGF_NO_NETWORK
01095 
01096 /* Begin - Callback Functions for the various settings */
01097 /* virtual PositionMainToolbar function, calls the right one.*/
01098 static int32 v_PositionMainToolbar(int32 p1)
01099 {
01100   if (_game_mode != GM_MENU) PositionMainToolbar(NULL);
01101   return 0;
01102 }
01103 
01104 static int32 AiNew_PatchActive_Warning(int32 p1)
01105 {
01106   if (p1 == 1) ShowErrorMessage(INVALID_STRING_ID, TEMP_AI_ACTIVATED, 0, 0);
01107   return 0;
01108 }
01109 
01110 static int32 Ai_In_Multiplayer_Warning(int32 p1)
01111 {
01112   if (p1 == 1) {
01113     ShowErrorMessage(INVALID_STRING_ID, TEMP_AI_MULTIPLAYER, 0, 0);
01114     _patches.ainew_active = true;
01115   }
01116   return 0;
01117 }
01118 
01119 static int32 PopulationInLabelActive(int32 p1)
01120 {
01121   Town* t;
01122 
01123   FOR_ALL_TOWNS(t) UpdateTownVirtCoord(t);
01124 
01125   return 0;
01126 }
01127 
01128 static int32 RedrawScreen(int32 p1)
01129 {
01130   MarkWholeScreenDirty();
01131   return 0;
01132 }
01133 
01134 static int32 InValidateDetailsWindow(int32 p1)
01135 {
01136   InvalidateWindowClasses(WC_VEHICLE_DETAILS);
01137   return 0;
01138 }
01139 
01140 static int32 InvalidateStationBuildWindow(int32 p1)
01141 {
01142   InvalidateWindow(WC_BUILD_STATION, 0);
01143   return 0;
01144 }
01145 
01146 static int32 InvalidateBuildIndustryWindow(int32 p1)
01147 {
01148   InvalidateWindowData(WC_BUILD_INDUSTRY, 0);
01149   return 0;
01150 }
01151 
01152 static int32 UpdateConsists(int32 p1)
01153 {
01154   Vehicle *v;
01155   FOR_ALL_VEHICLES(v) {
01156     /* Update the consist of all trains so the maximum speed is set correctly. */
01157     if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) TrainConsistChanged(v, true);
01158   }
01159   return 0;
01160 }
01161 
01162 /* Check service intervals of vehicles, p1 is value of % or day based servicing */
01163 static int32 CheckInterval(int32 p1)
01164 {
01165   bool warning;
01166   const Patches *ptc = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
01167 
01168   if (p1) {
01169     warning = ( (IsInsideMM(ptc->servint_trains,   5, 90 + 1) || ptc->servint_trains   == 0) &&
01170                 (IsInsideMM(ptc->servint_roadveh,  5, 90 + 1) || ptc->servint_roadveh  == 0) &&
01171                 (IsInsideMM(ptc->servint_aircraft, 5, 90 + 1) || ptc->servint_aircraft == 0) &&
01172                 (IsInsideMM(ptc->servint_ships,    5, 90 + 1) || ptc->servint_ships    == 0) );
01173   } else {
01174     warning = ( (IsInsideMM(ptc->servint_trains,   30, 800 + 1) || ptc->servint_trains   == 0) &&
01175                 (IsInsideMM(ptc->servint_roadveh,  30, 800 + 1) || ptc->servint_roadveh  == 0) &&
01176                 (IsInsideMM(ptc->servint_aircraft, 30, 800 + 1) || ptc->servint_aircraft == 0) &&
01177                 (IsInsideMM(ptc->servint_ships,    30, 800 + 1) || ptc->servint_ships    == 0) );
01178   }
01179 
01180   if (!warning)
01181     ShowErrorMessage(INVALID_STRING_ID, STR_CONFIG_PATCHES_SERVICE_INTERVAL_INCOMPATIBLE, 0, 0);
01182 
01183   return InValidateDetailsWindow(0);
01184 }
01185 
01186 static int32 EngineRenewUpdate(int32 p1)
01187 {
01188   DoCommandP(0, 0, _patches.autorenew, NULL, CMD_SET_AUTOREPLACE);
01189   return 0;
01190 }
01191 
01192 static int32 EngineRenewMonthsUpdate(int32 p1)
01193 {
01194   DoCommandP(0, 1, _patches.autorenew_months, NULL, CMD_SET_AUTOREPLACE);
01195   return 0;
01196 }
01197 
01198 static int32 EngineRenewMoneyUpdate(int32 p1)
01199 {
01200   DoCommandP(0, 2, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
01201   return 0;
01202 }
01203 
01204 static int32 RealisticAccelerationChanged(int32 p1)
01205 {
01206   Vehicle *v;
01207 
01208   FOR_ALL_VEHICLES(v) {
01209     if (v->type == VEH_TRAIN && IsFrontEngine(v)) UpdateTrainAcceleration(v);
01210   }
01211 
01212   return 0;
01213 }
01214 
01215 static int32 DragSignalsDensityChanged(int32)
01216 {
01217   const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
01218 
01219   if (w != NULL) SetWindowDirty(w);
01220 
01221   return 0;
01222 }
01223 
01232 static int32 CheckTownLayout(int32 p1)
01233 {
01234   if (_patches.town_layout == TL_NO_ROADS && _game_mode == GM_EDITOR) {
01235     ShowErrorMessage(INVALID_STRING_ID, STR_CONFIG_PATCHES_TOWN_LAYOUT_INVALID, 0, 0);
01236     _patches.town_layout = TL_ORIGINAL;
01237   }
01238   return 0;
01239 }
01240 
01247 static int32 ConvertLandscape(const char *value)
01248 {
01249   /* try with the old values */
01250   return lookup_oneofmany("normal|hilly|desert|candy", value, -1);
01251 }
01252 
01253 /* End - Callback Functions */
01254 
01255 #ifndef EXTERNAL_PLAYER
01256 #define EXTERNAL_PLAYER "timidity"
01257 #endif
01258 
01259 static const SettingDesc _music_settings[] = {
01260    SDT_VAR(MusicFileSettings, playlist,   SLE_UINT8, S, 0,   0, 0,   5, 1,  STR_NULL, NULL),
01261    SDT_VAR(MusicFileSettings, music_vol,  SLE_UINT8, S, 0, 127, 0, 127, 1,  STR_NULL, NULL),
01262    SDT_VAR(MusicFileSettings, effect_vol, SLE_UINT8, S, 0, 127, 0, 127, 1,  STR_NULL, NULL),
01263   SDT_LIST(MusicFileSettings, custom_1,   SLE_UINT8, S, 0, NULL,            STR_NULL, NULL),
01264   SDT_LIST(MusicFileSettings, custom_2,   SLE_UINT8, S, 0, NULL,            STR_NULL, NULL),
01265   SDT_BOOL(MusicFileSettings, playing,               S, 0, true,            STR_NULL, NULL),
01266   SDT_BOOL(MusicFileSettings, shuffle,               S, 0, false,           STR_NULL, NULL),
01267    SDT_STR(MusicFileSettings, extmidi,     SLE_STRB, S, 0, EXTERNAL_PLAYER, STR_NULL, NULL),
01268    SDT_END()
01269 };
01270 
01271 /* win32_v.c only settings */
01272 #ifdef WIN32
01273 extern bool _force_full_redraw, _window_maximize;
01274 extern uint _display_hz, _fullscreen_bpp;
01275 
01276 static const SettingDescGlobVarList _win32_settings[] = {
01277    SDTG_VAR("display_hz",     SLE_UINT, S, 0, _display_hz,       0, 0, 120, 0, STR_NULL, NULL),
01278   SDTG_BOOL("force_full_redraw",        S, 0, _force_full_redraw,false,        STR_NULL, NULL),
01279    SDTG_VAR("fullscreen_bpp", SLE_UINT, S, 0, _fullscreen_bpp,   8, 8,  32, 0, STR_NULL, NULL),
01280   SDTG_BOOL("window_maximize",          S, 0, _window_maximize,  false,        STR_NULL, NULL),
01281    SDTG_END()
01282 };
01283 #endif /* WIN32 */
01284 
01285 static const SettingDescGlobVarList _misc_settings[] = {
01286   SDTG_MMANY("display_opt",     SLE_UINT8, S, 0, _display_opt,       (1 << DO_SHOW_TOWN_NAMES | 1 << DO_SHOW_STATION_NAMES | 1 << DO_SHOW_SIGNS | 1 << DO_FULL_ANIMATION | 1 << DO_FULL_DETAIL | 1 << DO_WAYPOINTS), "SHOW_TOWN_NAMES|SHOW_STATION_NAMES|SHOW_SIGNS|FULL_ANIMATION||FULL_DETAIL|WAYPOINTS", STR_NULL, NULL),
01287    SDTG_BOOL("news_ticker_sound",          S, 0, _news_ticker_sound,     true,    STR_NULL, NULL),
01288    SDTG_BOOL("fullscreen",                 S, 0, _fullscreen,           false,    STR_NULL, NULL),
01289     SDTG_STR("videodriver",      SLE_STRB,C|S,0, _ini_videodriver,       NULL,    STR_NULL, NULL),
01290     SDTG_STR("musicdriver",      SLE_STRB,C|S,0, _ini_musicdriver,       NULL,    STR_NULL, NULL),
01291     SDTG_STR("sounddriver",      SLE_STRB,C|S,0, _ini_sounddriver,       NULL,    STR_NULL, NULL),
01292     SDTG_STR("blitter",          SLE_STRB,C|S,0, _ini_blitter,           NULL,    STR_NULL, NULL),
01293     SDTG_STR("language",         SLE_STRB, S, 0, _dynlang.curr_file,     NULL,    STR_NULL, NULL),
01294    SDTG_LIST("resolution",     SLE_UINT16, S, 0, _cur_resolution,   "640,480",    STR_NULL, NULL),
01295     SDTG_STR("screenshot_format",SLE_STRB, S, 0, _screenshot_format_name,NULL,    STR_NULL, NULL),
01296     SDTG_STR("savegame_format",  SLE_STRB, S, 0, _savegame_format,       NULL,    STR_NULL, NULL),
01297    SDTG_BOOL("rightclick_emulate",         S, 0, _rightclick_emulate,   false,    STR_NULL, NULL),
01298 #ifdef WITH_FREETYPE
01299     SDTG_STR("small_font",       SLE_STRB, S, 0, _freetype.small_font,   NULL,    STR_NULL, NULL),
01300     SDTG_STR("medium_font",      SLE_STRB, S, 0, _freetype.medium_font,  NULL,    STR_NULL, NULL),
01301     SDTG_STR("large_font",       SLE_STRB, S, 0, _freetype.large_font,   NULL,    STR_NULL, NULL),
01302     SDTG_VAR("small_size",       SLE_UINT, S, 0, _freetype.small_size,   6, 0, 72, 0, STR_NULL, NULL),
01303     SDTG_VAR("medium_size",      SLE_UINT, S, 0, _freetype.medium_size, 10, 0, 72, 0, STR_NULL, NULL),
01304     SDTG_VAR("large_size",       SLE_UINT, S, 0, _freetype.large_size,  16, 0, 72, 0, STR_NULL, NULL),
01305    SDTG_BOOL("small_aa",                   S, 0, _freetype.small_aa,    false,    STR_NULL, NULL),
01306    SDTG_BOOL("medium_aa",                  S, 0, _freetype.medium_aa,   false,    STR_NULL, NULL),
01307    SDTG_BOOL("large_aa",                   S, 0, _freetype.large_aa,    false,    STR_NULL, NULL),
01308 #endif
01309     SDTG_VAR("sprite_cache_size",SLE_UINT, S, 0, _sprite_cache_size,     4, 1, 64, 0, STR_NULL, NULL),
01310     SDTG_VAR("player_face",    SLE_UINT32, S, 0, _player_face,      0,0,0xFFFFFFFF,0, STR_NULL, NULL),
01311     SDTG_VAR("transparency_options", SLE_UINT, S, 0, _transparency_opt,  0,0,0x1FF,0, STR_NULL, NULL),
01312     SDTG_VAR("transparency_locks", SLE_UINT, S, 0, _transparency_lock,   0,0,0x1FF,0, STR_NULL, NULL),
01313     SDTG_END()
01314 };
01315 
01316 #ifdef ENABLE_NETWORK
01317 static const SettingDescGlobVarList _network_settings[] = {
01318     SDTG_VAR("sync_freq",           SLE_UINT16,C|S,0, _network_sync_freq,            100, 0,   100,   0, STR_NULL, NULL),
01319     SDTG_VAR("frame_freq",           SLE_UINT8,C|S,0, _network_frame_freq,             0, 0,   100,   0, STR_NULL, NULL),
01320     SDTG_VAR("max_join_time",       SLE_UINT16, S, 0, _network_max_join_time,        500, 0, 32000,   0, STR_NULL, NULL),
01321    SDTG_BOOL("pause_on_join",                   S, 0, _network_pause_on_join,        true,               STR_NULL, NULL),
01322     SDTG_STR("server_bind_ip",        SLE_STRB, S, 0, _network_server_bind_ip_host,  "0.0.0.0",          STR_NULL, NULL),
01323     SDTG_VAR("server_port",         SLE_UINT16, S, 0, _network_server_port,          NETWORK_DEFAULT_PORT, 0, 65535, 0, STR_NULL, NULL),
01324    SDTG_BOOL("server_advertise",                S, 0, _network_advertise,            false,              STR_NULL, NULL),
01325     SDTG_VAR("lan_internet",         SLE_UINT8, S, 0, _network_lan_internet,           0, 0,     1,   0, STR_NULL, NULL),
01326     SDTG_STR("player_name",           SLE_STRB, S, 0, _network_player_name,          NULL,               STR_NULL, NULL),
01327     SDTG_STR("server_password",       SLE_STRB, S, 0, _network_server_password,      NULL,               STR_NULL, NULL),
01328     SDTG_STR("rcon_password",         SLE_STRB, S, 0, _network_rcon_password,        NULL,               STR_NULL, NULL),
01329     SDTG_STR("default_company_pass",  SLE_STRB, S, 0, _network_default_company_pass, NULL,               STR_NULL, NULL),
01330     SDTG_STR("server_name",           SLE_STRB, S, 0, _network_server_name,          NULL,               STR_NULL, NULL),
01331     SDTG_STR("connect_to_ip",         SLE_STRB, S, 0, _network_default_ip,           NULL,               STR_NULL, NULL),
01332     SDTG_STR("network_id",            SLE_STRB, S, 0, _network_unique_id,            NULL,               STR_NULL, NULL),
01333    SDTG_BOOL("autoclean_companies",             S, 0, _network_autoclean_companies,  false,              STR_NULL, NULL),
01334     SDTG_VAR("autoclean_unprotected",SLE_UINT8, S, 0, _network_autoclean_unprotected,12, 0,     60,   0, STR_NULL, NULL),
01335     SDTG_VAR("autoclean_protected",  SLE_UINT8, S, 0, _network_autoclean_protected,  36, 0,    180,   0, STR_NULL, NULL),
01336     SDTG_VAR("max_companies",        SLE_UINT8, S, 0, _network_game_info.companies_max,   8, 1, MAX_PLAYERS, 0, STR_NULL, NULL),
01337     SDTG_VAR("max_clients",          SLE_UINT8, S, 0, _network_game_info.clients_max,    10, 2, MAX_CLIENTS, 0, STR_NULL, NULL),
01338     SDTG_VAR("max_spectators",       SLE_UINT8, S, 0, _network_game_info.spectators_max, 10, 0, MAX_CLIENTS, 0, STR_NULL, NULL),
01339     SDTG_VAR("restart_game_year",    SLE_INT32, S,D0, _network_restart_game_year,    0, MIN_YEAR, MAX_YEAR, 1, STR_NULL, NULL),
01340     SDTG_VAR("min_players",          SLE_UINT8, S, 0, _network_min_players,               0, 0, 10,   0, STR_NULL, NULL),
01341   SDTG_OMANY("server_lang",          SLE_UINT8, S, 0, _network_game_info.server_lang,     0, 28, "ANY|ENGLISH|GERMAN|FRENCH|BRAZILIAN|BULGARIAN|CHINESE|CZECH|DANISH|DUTCH|ESPERANTO|FINNISH|HUNGARIAN|ICELANDIC|ITALIAN|JAPANESE|KOREAN|LITHUANIAN|NORWEGIAN|POLISH|PORTUGUESE|ROMANIAN|RUSSIAN|SLOVAK|SLOVENIAN|SPANISH|SWEDISH|TURKISH|UKRAINIAN", STR_NULL, NULL),
01342    SDTG_BOOL("reload_cfg",                      S, 0, _network_reload_cfg,           false,              STR_NULL, NULL),
01343     SDTG_END()
01344 };
01345 #endif /* ENABLE_NETWORK */
01346 
01347 static const SettingDesc _gameopt_settings[] = {
01348   /* In version 4 a new difficulty setting has been added to the difficulty settings,
01349    * town attitude towards demolishing. Needs special handling because some dimwit thought
01350    * it funny to have the GameDifficulty struct be an array while it is a struct of
01351    * same-sized members
01352    * XXX - To save file-space and since values are never bigger than about 10? only
01353    * save the first 16 bits in the savegame. Question is why the values are still int32
01354    * and why not byte for example?
01355    * 'SLE_FILE_I16 | SLE_VAR_U16' in "diff_custom" is needed to get around SlArray() hack
01356    * for savegames version 0 - though it is an array, it has to go through the byteswap process */
01357   SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_FILE_I16 | SLE_VAR_U16, 0, 0, GameOptions, diff, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 0, 3),
01358   SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_UINT16, 0, 0, GameOptions, diff, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 4, SL_MAX_VERSION),
01359       SDT_VAR(GameOptions, diff_level, SLE_UINT8, 0, 0, 0, 0,  3, 0, STR_NULL, NULL),
01360     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|SKK|BRR|custom", STR_NULL, NULL, NULL),
01361     SDT_OMANY(GameOptions, units,     SLE_UINT8, N, 0, 1,     2, "imperial|metric|si", STR_NULL, NULL, NULL),
01362   /* There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. */
01363     SDT_OMANY(GameOptions, town_name, SLE_UINT8, 0, 0, 0,   255, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL, NULL),
01364     SDT_OMANY(GameOptions, landscape, SLE_UINT8, 0, 0, 0,     3, "temperate|arctic|tropic|toyland", STR_NULL, NULL, ConvertLandscape),
01365       SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 7 * TILE_HEIGHT, 2 * TILE_HEIGHT, 13 * TILE_HEIGHT, 0, STR_NULL, NULL),
01366   SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8, 0, 22,             N, 0, 0, 0, "", STR_NULL, NULL, NULL),
01367   SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8,23, SL_MAX_VERSION, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL, NULL),
01368     SDT_OMANY(GameOptions, road_side, SLE_UINT8, 0, 0, 1,   1, "left|right", STR_NULL, NULL, NULL),
01369       SDT_END()
01370 };
01371 
01372 /* Some patches do not need to be synchronised when playing in multiplayer.
01373  * These include for example the GUI settings and will not be saved with the
01374  * savegame.
01375  * It is also a bit tricky since you would think that service_interval
01376  * for example doesn't need to be synched. Every client assigns the
01377  * service_interval value to the v->service_interval, meaning that every client
01378  * assigns his value. If the setting was player-based, that would mean that
01379  * vehicles could decide on different moments that they are heading back to a
01380  * service depot, causing desyncs on a massive scale. */
01381 const SettingDesc _patch_settings[] = {
01382   /***************************************************************************/
01383   /* User-interface section of the GUI-configure patches window */
01384   SDT_BOOL(Patches, vehicle_speed,                 S, 0,  true,        STR_CONFIG_PATCHES_VEHICLESPEED,          NULL),
01385   SDT_BOOL(Patches, status_long_date,              S, 0,  true,        STR_CONFIG_PATCHES_LONGDATE,              NULL),
01386   SDT_BOOL(Patches, show_finances,                 S, 0,  true,        STR_CONFIG_PATCHES_SHOWFINANCES,          NULL),
01387   SDT_BOOL(Patches, autoscroll,                    S, 0, false,        STR_CONFIG_PATCHES_AUTOSCROLL,            NULL),
01388   SDT_BOOL(Patches, reverse_scroll,                S, 0, false,        STR_CONFIG_PATCHES_REVERSE_SCROLLING,     NULL),
01389   SDT_BOOL(Patches, smooth_scroll,                 S, 0, false,        STR_CONFIG_PATCHES_SMOOTH_SCROLLING,      NULL),
01390   SDT_BOOL(Patches, measure_tooltip,               S, 0, false,        STR_CONFIG_PATCHES_MEASURE_TOOLTIP,       NULL),
01391    SDT_VAR(Patches, errmsg_duration,    SLE_UINT8, S, 0,  5, 0, 20, 0, STR_CONFIG_PATCHES_ERRMSG_DURATION,       NULL),
01392    SDT_VAR(Patches, toolbar_pos,        SLE_UINT8, S,MS,  0, 0,  2, 0, STR_CONFIG_PATCHES_TOOLBAR_POS,           v_PositionMainToolbar),
01393    SDT_VAR(Patches, window_snap_radius, SLE_UINT8, S,D0, 10, 1, 32, 0, STR_CONFIG_PATCHES_SNAP_RADIUS,           NULL),
01394   SDT_BOOL(Patches, invisible_trees,               S, 0, false,        STR_CONFIG_PATCHES_INVISIBLE_TREES,       RedrawScreen),
01395   SDT_BOOL(Patches, population_in_label,           S, 0,  true,        STR_CONFIG_PATCHES_POPULATION_IN_LABEL,   PopulationInLabelActive),
01396    SDT_VAR(Patches, map_x,              SLE_UINT8, S, 0,  8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_X,                 NULL),
01397    SDT_VAR(Patches, map_y,              SLE_UINT8, S, 0,  8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_Y,                 NULL),
01398   SDT_BOOL(Patches, link_terraform_toolbar,        S, 0, false,        STR_CONFIG_PATCHES_LINK_TERRAFORM_TOOLBAR,NULL),
01399    SDT_VAR(Patches, liveries,           SLE_UINT8, S,MS,  2, 0,  2, 0, STR_CONFIG_PATCHES_LIVERIES,              RedrawScreen),
01400   SDT_BOOL(Patches, prefer_teamchat,               S, 0, false,        STR_CONFIG_PATCHES_PREFER_TEAMCHAT,       NULL),
01401   SDT_VAR(Patches, scrollwheel_scrolling,SLE_UINT8,S,MS, 0,  0,  2, 0, STR_CONFIG_PATCHES_SCROLLWHEEL_SCROLLING, NULL),
01402   SDT_VAR(Patches,scrollwheel_multiplier,SLE_UINT8,S, 0, 5,  1, 15, 1, STR_CONFIG_PATCHES_SCROLLWHEEL_MULTIPLIER,NULL),
01403   SDT_BOOL(Patches, pause_on_newgame,              S, 0, false,        STR_CONFIG_PATCHES_PAUSE_ON_NEW_GAME,     NULL),
01404    SDT_VAR(Patches,advanced_vehicle_list,SLE_UINT8,S,MS, 1,  0,  2, 0, STR_CONFIG_PATCHES_ADVANCED_VEHICLE_LISTS,NULL),
01405   SDT_BOOL(Patches, timetable_in_ticks,            S, 0, false,        STR_CONFIG_PATCHES_TIMETABLE_IN_TICKS,    NULL),
01406    SDT_VAR(Patches, loading_indicators, SLE_UINT8, S,MS,  1, 0,  2, 0, STR_CONFIG_PATCHES_LOADING_INDICATORS,    RedrawScreen),
01407    SDT_VAR(Patches, default_rail_type,  SLE_UINT8, S,MS,  4, 0,  6, 0, STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE,     NULL),
01408 
01409   /***************************************************************************/
01410   /* Construction section of the GUI-configure patches window */
01411   SDT_BOOL(Patches, build_on_slopes,               0,NN,  true,        STR_CONFIG_PATCHES_BUILDONSLOPES,       NULL),
01412   SDT_CONDBOOL(Patches, autoslope,                75, SL_MAX_VERSION, 0, 0, true,  STR_CONFIG_PATCHES_AUTOSLOPE,            NULL),
01413   SDT_BOOL(Patches, extra_dynamite,                0, 0, false,        STR_CONFIG_PATCHES_EXTRADYNAMITE,       NULL),
01414   SDT_BOOL(Patches, longbridges,                   0,NN,  true,        STR_CONFIG_PATCHES_LONGBRIDGES,         NULL),
01415   SDT_BOOL(Patches, signal_side,                   N,NN,  true,        STR_CONFIG_PATCHES_SIGNALSIDE,          RedrawScreen),
01416   SDT_BOOL(Patches, always_small_airport,          0,NN, false,        STR_CONFIG_PATCHES_SMALL_AIRPORTS,      NULL),
01417   SDT_BOOL(Patches, enable_signal_gui,             S, 0, false,        STR_CONFIG_PATCHES_ENABLE_SIGNAL_GUI,   NULL),
01418    SDT_VAR(Patches, drag_signals_density,SLE_UINT8,S, 0,  4, 1, 20, 0, STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY,DragSignalsDensityChanged),
01419    SDT_VAR(Patches, semaphore_build_before,SLE_INT32, S, NC, 1975, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_SEMAPHORE_BUILD_BEFORE_DATE, NULL),
01420   SDT_CONDVAR(Patches, town_layout, SLE_UINT8, 59, SL_MAX_VERSION, 0, MS, TL_ORIGINAL, TL_NO_ROADS, NUM_TLS - 1, 1, STR_CONFIG_PATCHES_TOWN_LAYOUT, CheckTownLayout),
01421 
01422   /***************************************************************************/
01423   /* Vehicle section of the GUI-configure patches window */
01424   SDT_BOOL(Patches, realistic_acceleration,        0, 0, false,                    STR_CONFIG_PATCHES_REALISTICACCEL,       RealisticAccelerationChanged),
01425   SDT_BOOL(Patches, forbid_90_deg,                 0, 0, false,                    STR_CONFIG_PATCHES_FORBID_90_DEG,        NULL),
01426   SDT_BOOL(Patches, mammoth_trains,                0,NN,  true,                    STR_CONFIG_PATCHES_MAMMOTHTRAINS,        NULL),
01427   SDT_BOOL(Patches, gotodepot,                     0, 0,  true,                    STR_CONFIG_PATCHES_GOTODEPOT,            NULL),
01428   SDT_BOOL(Patches, roadveh_queue,                 0, 0,  true,                    STR_CONFIG_PATCHES_ROADVEH_QUEUE,        NULL),
01429 
01430   SDT_CONDBOOL(Patches, new_pathfinding_all, 0,86, 0, 0, false,                    STR_NULL,                                NULL),
01431   SDT_CONDBOOL(Patches, yapf.ship_use_yapf, 28,86, 0, 0, false,                    STR_NULL,                                NULL),
01432   SDT_CONDBOOL(Patches, yapf.road_use_yapf, 28,86, 0, 0,  true,                    STR_NULL,                                NULL),
01433   SDT_CONDBOOL(Patches, yapf.rail_use_yapf, 28,86, 0, 0,  true,                    STR_NULL,                                NULL),
01434 
01435   SDT_CONDVAR(Patches, pathfinder_for_trains,   SLE_UINT8, 87, SL_MAX_VERSION, 0, MS, 2, 0, 2, 1, STR_CONFIG_PATCHES_PATHFINDER_FOR_TRAINS,  NULL),
01436   SDT_CONDVAR(Patches, pathfinder_for_roadvehs, SLE_UINT8, 87, SL_MAX_VERSION, 0, MS, 2, 0, 2, 1, STR_CONFIG_PATCHES_PATHFINDER_FOR_ROADVEH, NULL),
01437   SDT_CONDVAR(Patches, pathfinder_for_ships,    SLE_UINT8, 87, SL_MAX_VERSION, 0, MS, 0, 0, 2, 1, STR_CONFIG_PATCHES_PATHFINDER_FOR_SHIPS,   NULL),
01438 
01439   SDT_BOOL(Patches, train_income_warn,             S, 0,  true,                    STR_CONFIG_PATCHES_WARN_INCOME_LESS,     NULL),
01440    SDT_VAR(Patches, order_review_system,SLE_UINT8, S,MS,     2,     0,       2, 0, STR_CONFIG_PATCHES_ORDER_REVIEW,         NULL),
01441   SDT_BOOL(Patches, never_expire_vehicles,         0,NN, false,                    STR_CONFIG_PATCHES_NEVER_EXPIRE_VEHICLES,NULL),
01442   SDT_BOOL(Patches, lost_train_warn,               S, 0,  true,                    STR_CONFIG_PATCHES_WARN_LOST_TRAIN,      NULL),
01443   SDT_BOOL(Patches, autorenew,                     S, 0, false,                    STR_CONFIG_PATCHES_AUTORENEW_VEHICLE,    EngineRenewUpdate),
01444    SDT_VAR(Patches, autorenew_months,   SLE_INT16, S, 0,     6,   -12,      12, 0, STR_CONFIG_PATCHES_AUTORENEW_MONTHS,     EngineRenewMonthsUpdate),
01445    SDT_VAR(Patches, autorenew_money,     SLE_UINT, S,CR,100000,     0, 2000000, 0, STR_CONFIG_PATCHES_AUTORENEW_MONEY,      EngineRenewMoneyUpdate),
01446   SDT_BOOL(Patches, always_build_infrastructure,   S, 0, false,                    STR_CONFIG_PATCHES_ALWAYS_BUILD_INFRASTRUCTURE, RedrawScreen),
01447    SDT_VAR(Patches, max_trains,        SLE_UINT16, 0, 0,   500,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_TRAINS,           RedrawScreen),
01448    SDT_VAR(Patches, max_roadveh,       SLE_UINT16, 0, 0,   500,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_ROADVEH,          RedrawScreen),
01449    SDT_VAR(Patches, max_aircraft,      SLE_UINT16, 0, 0,   200,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_AIRCRAFT,         RedrawScreen),
01450    SDT_VAR(Patches, max_ships,         SLE_UINT16, 0, 0,   300,     0,    5000, 0, STR_CONFIG_PATCHES_MAX_SHIPS,            RedrawScreen),
01451   SDT_BOOL(Patches, servint_ispercent,             0, 0, false,                    STR_CONFIG_PATCHES_SERVINT_ISPERCENT,    CheckInterval),
01452    SDT_VAR(Patches, servint_trains,    SLE_UINT16, 0,D0,   150,     5,     800, 0, STR_CONFIG_PATCHES_SERVINT_TRAINS,       InValidateDetailsWindow),
01453    SDT_VAR(Patches, servint_roadveh,   SLE_UINT16, 0,D0,   150,     5,     800, 0, STR_CONFIG_PATCHES_SERVINT_ROADVEH,      InValidateDetailsWindow),
01454    SDT_VAR(Patches, servint_ships,     SLE_UINT16, 0,D0,   360,     5,     800, 0, STR_CONFIG_PATCHES_SERVINT_SHIPS,        InValidateDetailsWindow),
01455    SDT_VAR(Patches, servint_aircraft,  SLE_UINT16, 0,D0,   100,     5,     800, 0, STR_CONFIG_PATCHES_SERVINT_AIRCRAFT,     InValidateDetailsWindow),
01456   SDT_BOOL(Patches, no_servicing_if_no_breakdowns, 0, 0, false,                    STR_CONFIG_PATCHES_NOSERVICE,            NULL),
01457   SDT_BOOL(Patches, wagon_speed_limits,            0,NN,  true,                    STR_CONFIG_PATCHES_WAGONSPEEDLIMITS,     UpdateConsists),
01458   SDT_CONDBOOL(Patches, disable_elrails, 38, SL_MAX_VERSION, 0, NN, false,         STR_CONFIG_PATCHES_DISABLE_ELRAILS,      SettingsDisableElrail),
01459   SDT_CONDVAR(Patches, freight_trains, SLE_UINT8, 39, SL_MAX_VERSION, 0,NN, 1, 1, 255, 1, STR_CONFIG_PATCHES_FREIGHT_TRAINS, NULL),
01460   SDT_CONDBOOL(Patches, timetabling,              67, SL_MAX_VERSION, 0, 0, true,  STR_CONFIG_PATCHES_TIMETABLE_ALLOW,      NULL),
01461   SDT_CONDVAR(Patches, plane_speed,    SLE_UINT8, 90, SL_MAX_VERSION, 0, 0, 4, 1,   4, 0, STR_CONFIG_PATCHES_PLANE_SPEED,   NULL),
01462 
01463   /***************************************************************************/
01464   /* Station section of the GUI-configure patches window */
01465   SDT_BOOL(Patches, join_stations,           0, 0,  true,        STR_CONFIG_PATCHES_JOINSTATIONS,       NULL),
01466   SDT_BOOL(Patches, full_load_any,           0,NN,  true,        STR_CONFIG_PATCHES_FULLLOADANY,        NULL),
01467   SDT_BOOL(Patches, improved_load,           0,NN, false,        STR_CONFIG_PATCHES_IMPROVEDLOAD,       NULL),
01468   SDT_BOOL(Patches, selectgoods,             0, 0,  true,        STR_CONFIG_PATCHES_SELECTGOODS,        NULL),
01469   SDT_BOOL(Patches, new_nonstop,             0, 0, false,        STR_CONFIG_PATCHES_NEW_NONSTOP,        NULL),
01470   SDT_BOOL(Patches, nonuniform_stations,     0,NN,  true,        STR_CONFIG_PATCHES_NONUNIFORM_STATIONS,NULL),
01471    SDT_VAR(Patches, station_spread,SLE_UINT8,0, 0, 12, 4, 64, 0, STR_CONFIG_PATCHES_STATION_SPREAD,     InvalidateStationBuildWindow),
01472   SDT_BOOL(Patches, serviceathelipad,        0, 0,  true,        STR_CONFIG_PATCHES_SERVICEATHELIPAD,   NULL),
01473   SDT_BOOL(Patches, modified_catchment,      0, 0,  true,        STR_CONFIG_PATCHES_CATCHMENT,          NULL),
01474   SDT_CONDBOOL(Patches, gradual_loading, 40, SL_MAX_VERSION, 0, 0,  true, STR_CONFIG_PATCHES_GRADUAL_LOADING,    NULL),
01475   SDT_CONDBOOL(Patches, road_stop_on_town_road, 47, SL_MAX_VERSION, 0, 0, false, STR_CONFIG_PATCHES_STOP_ON_TOWN_ROAD, NULL),
01476   SDT_CONDBOOL(Patches, adjacent_stations,      62, SL_MAX_VERSION, 0, 0, true,  STR_CONFIG_PATCHES_ADJACENT_STATIONS, NULL),
01477 
01478   /***************************************************************************/
01479   /* Economy section of the GUI-configure patches window */
01480   SDT_BOOL(Patches, inflation,                  0, 0,  true,            STR_CONFIG_PATCHES_INFLATION,        NULL),
01481    SDT_VAR(Patches, raw_industry_construction,SLE_UINT8,0,MS,0,0, 2, 0, STR_CONFIG_PATCHES_RAW_INDUSTRY_CONSTRUCTION_METHOD, InvalidateBuildIndustryWindow),
01482   SDT_BOOL(Patches, multiple_industry_per_town, 0, 0, false,            STR_CONFIG_PATCHES_MULTIPINDTOWN,    NULL),
01483   SDT_BOOL(Patches, same_industry_close,        0, 0, false,            STR_CONFIG_PATCHES_SAMEINDCLOSE,     NULL),
01484   SDT_BOOL(Patches, bribe,                      0, 0,  true,            STR_CONFIG_PATCHES_BRIBE,            NULL),
01485   SDT_CONDBOOL(Patches, exclusive_rights,           79, SL_MAX_VERSION, 0, 0, true,           STR_CONFIG_PATCHES_ALLOW_EXCLUSIVE, NULL),
01486   SDT_CONDBOOL(Patches, give_money,                 79, SL_MAX_VERSION, 0, 0, true,           STR_CONFIG_PATCHES_ALLOW_GIVE_MONEY, NULL),
01487    SDT_VAR(Patches, snow_line_height,SLE_UINT8, 0, 0,     7,  2, 13, 0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT,  NULL),
01488    SDT_VAR(Patches, colored_news_year,SLE_INT32, 0,NC,  2000, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_COLORED_NEWS_YEAR,NULL),
01489    SDT_VAR(Patches, starting_year,    SLE_INT32, 0,NC,  1950, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_STARTING_YEAR,NULL),
01490    SDT_VAR(Patches, ending_year,      SLE_INT32,0,NC|NO,2051, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_ENDING_YEAR,  NULL),
01491   SDT_BOOL(Patches, smooth_economy,             0, 0,  true,            STR_CONFIG_PATCHES_SMOOTH_ECONOMY,   NULL),
01492   SDT_BOOL(Patches, allow_shares,               0, 0, false,            STR_CONFIG_PATCHES_ALLOW_SHARES,     NULL),
01493   SDT_CONDVAR(Patches, town_growth_rate,  SLE_UINT8, 54, SL_MAX_VERSION, 0, MS, 2, 0,   4, 0, STR_CONFIG_PATCHES_TOWN_GROWTH,          NULL),
01494   SDT_CONDVAR(Patches, larger_towns,      SLE_UINT8, 54, SL_MAX_VERSION, 0, D0, 4, 0, 255, 1, STR_CONFIG_PATCHES_LARGER_TOWNS,         NULL),
01495   SDT_CONDVAR(Patches, initial_city_size, SLE_UINT8, 56, SL_MAX_VERSION, 0, 0,  2, 1,  10, 1, STR_CONFIG_PATCHES_CITY_SIZE_MULTIPLIER, NULL),
01496   SDT_CONDBOOL(Patches, mod_road_rebuild,            77, SL_MAX_VERSION, 0, 0, false,         STR_CONFIG_MODIFIED_ROAD_REBUILD,        NULL),
01497 
01498   /***************************************************************************/
01499   /* AI section of the GUI-configure patches window */
01500   SDT_BOOL(Patches, ainew_active,           0, 0, false, STR_CONFIG_PATCHES_AINEW_ACTIVE,      AiNew_PatchActive_Warning),
01501   SDT_BOOL(Patches, ai_in_multiplayer,      0, 0, false, STR_CONFIG_PATCHES_AI_IN_MULTIPLAYER, Ai_In_Multiplayer_Warning),
01502   SDT_BOOL(Patches, ai_disable_veh_train,   0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_TRAINS,  NULL),
01503   SDT_BOOL(Patches, ai_disable_veh_roadveh, 0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_ROADVEH, NULL),
01504   SDT_BOOL(Patches, ai_disable_veh_aircraft,0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_AIRCRAFT,NULL),
01505   SDT_BOOL(Patches, ai_disable_veh_ship,    0, 0, false, STR_CONFIG_PATCHES_AI_BUILDS_SHIPS,   NULL),
01506 
01507   /***************************************************************************/
01508   /* Patches without any GUI representation */
01509   SDT_BOOL(Patches, keep_all_autosave,              S, 0, false,         STR_NULL, NULL),
01510   SDT_BOOL(Patches, autosave_on_exit,               S, 0, false,         STR_NULL, NULL),
01511    SDT_VAR(Patches, max_num_autosaves,   SLE_UINT8, S, 0, 16, 0, 255, 0, STR_NULL, NULL),
01512   SDT_BOOL(Patches, bridge_pillars,                 S, 0,  true,         STR_NULL, NULL),
01513    SDT_VAR(Patches, extend_vehicle_life, SLE_UINT8, 0, 0,  0, 0, 100, 0, STR_NULL, NULL),
01514   SDT_BOOL(Patches, auto_euro,                      S, 0,  true,         STR_NULL, NULL),
01515    SDT_VAR(Patches, dist_local_authority,SLE_UINT8, 0, 0, 20, 5,  60, 0, STR_NULL, NULL),
01516    SDT_VAR(Patches, wait_oneway_signal,  SLE_UINT8, 0, 0, 15, 2, 100, 0, STR_NULL, NULL),
01517    SDT_VAR(Patches, wait_twoway_signal,  SLE_UINT8, 0, 0, 41, 2, 100, 0, STR_NULL, NULL),
01518 
01519   /***************************************************************************/
01520   /* New Pathfinding patch settings */
01521   SDT_VAR(Patches, pf_maxlength,      SLE_UINT16, 0, 0,  4096,  64,  65535, 0, STR_NULL, NULL),
01522   SDT_VAR(Patches, pf_maxdepth,        SLE_UINT8, 0, 0,    48,   4,    255, 0, STR_NULL, NULL),
01523   /* The maximum number of nodes to search */
01524   SDT_VAR(Patches, npf_max_search_nodes,SLE_UINT, 0, 0, 10000, 500, 100000, 0, STR_NULL, NULL),
01525 
01526   /* When a red signal is encountered, a small detour can be made around
01527    * it. This specifically occurs when a track is doubled, in which case
01528    * the detour is typically 2 tiles. It is also often used at station
01529    * entrances, when there is a choice of multiple platforms. If we take
01530    * a typical 4 platform station, the detour is 4 tiles. To properly
01531    * support larger stations we increase this value.
01532    * We want to prevent that trains that want to leave at one side of a
01533    * station, leave through the other side, turn around, enter the
01534    * station on another platform and exit the station on the right side
01535    * again, just because the sign at the right side was red. If we take
01536    * a typical 5 length station, this detour is 10 or 11 tiles (not
01537    * sure), so we set the default penalty at 10 (the station tile
01538    * penalty will further prevent this.
01539    * We give presignal exits (and combo's) a different (larger) penalty, because
01540    * we really don't want trains waiting in front of a presignal exit. */
01541   SDT_VAR(Patches, npf_rail_firstred_penalty,     SLE_UINT, 0, 0, (10 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
01542   SDT_VAR(Patches, npf_rail_firstred_exit_penalty,SLE_UINT, 0, 0, (100 * NPF_TILE_LENGTH),0, 100000, 0, STR_NULL, NULL),
01543   /* This penalty is for when the last signal before the target is red.
01544    * This is useful for train stations, where there are multiple
01545    * platforms to choose from, which lie in different signal blocks.
01546    * Every target in a occupied signal block (ie an occupied platform)
01547    * will get this penalty. */
01548   SDT_VAR(Patches, npf_rail_lastred_penalty, SLE_UINT, 0, 0, (10 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
01549   /* When a train plans a route over a station tile, this penalty is
01550    * applied. We want that trains plan a route around a typical, 4x5
01551    * station, which means two tiles to the right, and two tiles back to
01552    * the left around it, or 5 tiles of station through it. If we assign
01553    * a penalty of 1 tile for every station tile passed, the route will
01554    * be around it. */
01555   SDT_VAR(Patches, npf_rail_station_penalty, SLE_UINT, 0, 0, (1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
01556   SDT_VAR(Patches, npf_rail_slope_penalty,   SLE_UINT, 0, 0, (1 * NPF_TILE_LENGTH), 0, 100000, 0, STR_NULL, NULL),
01557   /* This penalty is applied when a train makes a turn. Its value of 1 makes
01558    * sure that it has a minimal impact on the pathfinding, only when two
01559    * paths have equal length it will make a difference */
01560   SDT_VAR(Patches, npf_rail_curve_penalty,        SLE_UINT, 0, 0, 1,                      0, 100000, 0, STR_NULL, NULL),
01561   /* Ths penalty is applied when a vehicle reverses inside a depot (doesn't
01562    * apply to ships, as they can just come out the other end). XXX: Is this a
01563    * good value? */
01564   SDT_VAR(Patches, npf_rail_depot_reverse_penalty,SLE_UINT, 0, 0, (NPF_TILE_LENGTH * 50), 0, 100000, 0, STR_NULL, NULL),
01565   SDT_VAR(Patches, npf_buoy_penalty,              SLE_UINT, 0, 0, (2 * NPF_TILE_LENGTH),  0, 100000, 0, STR_NULL, NULL),
01566   /* This penalty is applied when a ship makes a turn. It is bigger than the
01567    * rail curve penalty, since ships (realisticly) have more trouble with
01568    * making turns */
01569   SDT_VAR(Patches, npf_water_curve_penalty,       SLE_UINT, 0, 0, (NPF_TILE_LENGTH / 4),  0, 100000, 0, STR_NULL, NULL),
01570   /* This is the penalty for road, same as for rail. */
01571   SDT_VAR(Patches, npf_road_curve_penalty,        SLE_UINT, 0, 0, 1,                      0, 100000, 0, STR_NULL, NULL),
01572   /* This is the penalty for level crossings, for both road and rail vehicles */
01573   SDT_VAR(Patches, npf_crossing_penalty,          SLE_UINT, 0, 0, (3 * NPF_TILE_LENGTH),  0, 100000, 0, STR_NULL, NULL),
01574   /* This is the penalty for drive-through road, stops. */
01575   SDT_CONDVAR (Patches, npf_road_drive_through_penalty, SLE_UINT, 47, SL_MAX_VERSION, 0, 0,  8 * NPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
01576 
01577 
01578   /* The maximum number of nodes to search */
01579   SDT_CONDBOOL(Patches, yapf.disable_node_optimization  ,           28, SL_MAX_VERSION, 0, 0, false                   ,                       STR_NULL, NULL),
01580   SDT_CONDVAR (Patches, yapf.max_search_nodes           , SLE_UINT, 28, SL_MAX_VERSION, 0, 0, 10000                   ,      500, 1000000, 0, STR_NULL, NULL),
01581   SDT_CONDBOOL(Patches, yapf.rail_firstred_twoway_eol   ,           28, SL_MAX_VERSION, 0, 0,  true                   ,                       STR_NULL, NULL),
01582   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),
01583   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),
01584   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),
01585   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),
01586   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),
01587   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),
01588   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),
01589   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),
01590   /* This penalty is applied when a train reverses inside a depot */
01591   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),
01592   /* This is the penalty for level crossings (for trains only) */
01593   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),
01594   /* look-ahead how many signals are checked */
01595   SDT_CONDVAR (Patches, yapf.rail_look_ahead_max_signals, SLE_UINT, 28, SL_MAX_VERSION, 0, 0,    10                   ,        1,     100, 0, STR_NULL, NULL),
01596   /* look-ahead n-th red signal penalty polynomial: penalty = p2 * n^2 + p1 * n + p0 */
01597   SDT_CONDVAR (Patches, yapf.rail_look_ahead_signal_p0  , SLE_INT , 28, SL_MAX_VERSION, 0, 0,   500                   , -1000000, 1000000, 0, STR_NULL, NULL),
01598   SDT_CONDVAR (Patches, yapf.rail_look_ahead_signal_p1  , SLE_INT , 28, SL_MAX_VERSION, 0, 0,  -100                   , -1000000, 1000000, 0, STR_NULL, NULL),
01599   SDT_CONDVAR (Patches, yapf.rail_look_ahead_signal_p2  , SLE_INT , 28, SL_MAX_VERSION, 0, 0,     5                   , -1000000, 1000000, 0, STR_NULL, NULL),
01600   /* penalties for too long or too short station platforms */
01601   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),
01602   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),
01603   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),
01604   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),
01605   /* road vehicles - penalties */
01606   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),
01607   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),
01608   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),
01609   SDT_CONDVAR (Patches, yapf.road_stop_penalty                     , SLE_UINT, 47, SL_MAX_VERSION, 0, 0,  8 * YAPF_TILE_LENGTH, 0, 1000000, 0, STR_NULL, NULL),
01610 
01611   /***************************************************************************/
01612   /* Terrain genation related patch options */
01613   SDT_CONDVAR(Patches,      land_generator,           SLE_UINT8,  30, SL_MAX_VERSION, 0, MS,   1,                   0,    1,               0, STR_CONFIG_PATCHES_LAND_GENERATOR,           NULL),
01614   SDT_CONDVAR(Patches,      oil_refinery_limit,       SLE_UINT8,  30, SL_MAX_VERSION, 0, 0,   32,                  12,   48,               0, STR_CONFIG_PATCHES_OIL_REF_EDGE_DISTANCE,    NULL),
01615   SDT_CONDVAR(Patches,      tgen_smoothness,          SLE_UINT8,  30, SL_MAX_VERSION, 0, MS,   1,                   0,    3,               0, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN,     NULL),
01616   SDT_CONDVAR(Patches,      generation_seed,          SLE_UINT32, 30, SL_MAX_VERSION, 0, 0,    GENERATE_NEW_SEED,   0, MAX_UVALUE(uint32), 0, STR_NULL,                                    NULL),
01617   SDT_CONDVAR(Patches,      tree_placer,              SLE_UINT8,  30, SL_MAX_VERSION, 0, MS,   2,                   0,    2,               0, STR_CONFIG_PATCHES_TREE_PLACER,              NULL),
01618   SDT_VAR    (Patches,      heightmap_rotation,       SLE_UINT8,                      S, MS,   0,                   0,    1,               0, STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION,       NULL),
01619   SDT_VAR    (Patches,      se_flat_world_height,     SLE_UINT8,                      S, 0,    0,                   0,   15,               0, STR_CONFIG_PATCHES_SE_FLAT_WORLD_HEIGHT,     NULL),
01620 
01621   /*
01622    * Since the network code (CmdChangePatchSetting and friends) use the index in this array to decide
01623    * which patch the server is talking about all conditional compilation of this array must be at the
01624    * end. This isn't really the best solution, the patches the server can tell the client about should
01625    * either use a seperate array or some other form of identifier.
01626    */
01627 
01628 #ifdef __APPLE__
01629   /* We might need to emulate a right mouse button on mac */
01630   SDT_VAR(Patches,right_mouse_btn_emulation,SLE_UINT8,S,MS,0, 0, 2, 0, STR_CONFIG_PATCHES_RIGHT_MOUSE_BTN_EMU,   NULL),
01631 #endif
01632 
01633   SDT_END()
01634 };
01635 
01636 static const SettingDesc _currency_settings[] = {
01637   SDT_VAR(CurrencySpec, rate,    SLE_UINT16, S, 0,  1, 0, 100, 0, STR_NULL, NULL),
01638   SDT_CHR(CurrencySpec, separator,           S, 0,        ".",    STR_NULL, NULL),
01639   SDT_VAR(CurrencySpec, to_euro,  SLE_INT32, S, 0,  0, 0, 3000, 0, STR_NULL, NULL),
01640   SDT_STR(CurrencySpec, prefix,   SLE_STRBQ, S, 0,       NULL,    STR_NULL, NULL),
01641   SDT_STR(CurrencySpec, suffix,   SLE_STRBQ, S, 0, " credits",    STR_NULL, NULL),
01642   SDT_END()
01643 };
01644 
01645 /* Undefine for the shortcut macros above */
01646 #undef S
01647 #undef C
01648 #undef N
01649 
01650 #undef D0
01651 #undef NC
01652 #undef MS
01653 #undef NO
01654 #undef CR
01655 
01656 static uint NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
01657 {
01658   IniGroup *group = ini_getgroup(ini, grpname, -1);
01659   IniItem *item;
01660   /* By default, set everything to full (0xAAAAAAAA = 1010101010101010) */
01661   uint res = 0xAAAAAAAA;
01662 
01663   /* If no group exists, return everything full */
01664   if (group == NULL) return res;
01665 
01666   for (item = group->item; item != NULL; item = item->next) {
01667     int news_item = -1;
01668     for (int i = 0; i < NT_END; i++) {
01669       if (strcasecmp(item->name, _news_display_name[i]) == 0) {
01670         news_item = i;
01671         break;
01672       }
01673     }
01674     if (news_item == -1) {
01675       DEBUG(misc, 0, "Invalid display option: %s", item->name);
01676       continue;
01677     }
01678 
01679     if (strcasecmp(item->value, "full") == 0) {
01680       SB(res, news_item * 2, 2, 2);
01681     } else if (strcasecmp(item->value, "off") == 0) {
01682       SB(res, news_item * 2, 2, 0);
01683     } else if (strcasecmp(item->value, "summarized") == 0) {
01684       SB(res, news_item * 2, 2, 1);
01685     } else {
01686       DEBUG(misc, 0, "Invalid display value: %s", item->value);
01687       continue;
01688     }
01689   }
01690 
01691   return res;
01692 }
01693 
01694 /* Load a GRF configuration from the given group name */
01695 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
01696 {
01697   IniGroup *group = ini_getgroup(ini, grpname, -1);
01698   IniItem *item;
01699   GRFConfig *first = NULL;
01700   GRFConfig **curr = &first;
01701 
01702   if (group == NULL) return NULL;
01703 
01704   for (item = group->item; item != NULL; item = item->next) {
01705     GRFConfig *c = CallocT<GRFConfig>(1);
01706     c->filename = strdup(item->name);
01707 
01708     /* Parse parameters */
01709     if (*item->value != '\0') {
01710       c->num_params = parse_intlist(item->value, (int*)c->param, lengthof(c->param));
01711       if (c->num_params == (byte)-1) {
01712         ShowInfoF("ini: error in array '%s'", item->name);
01713         c->num_params = 0;
01714       }
01715     }
01716 
01717     /* Check if item is valid */
01718     if (!FillGRFDetails(c, is_static)) {
01719       const char *msg;
01720 
01721       if (c->status == GCS_NOT_FOUND) {
01722         msg = "not found";
01723       } else if (HasBit(c->flags, GCF_UNSAFE)) {
01724         msg = "unsafe for static use";
01725       } else if (HasBit(c->flags, GCF_SYSTEM)) {
01726         msg = "system NewGRF";
01727       } else {
01728         msg = "unknown";
01729       }
01730 
01731       ShowInfoF("ini: ignoring invalid NewGRF '%s': %s", item->name, msg);
01732       ClearGRFConfig(&c);
01733       continue;
01734     }
01735 
01736     /* Mark file as static to avoid saving in savegame. */
01737     if (is_static) SetBit(c->flags, GCF_STATIC);
01738 
01739     /* Add item to list */
01740     *curr = c;
01741     curr = &c->next;
01742   }
01743 
01744   return first;
01745 }
01746 
01747 static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname, uint news_display)
01748 {
01749   IniGroup *group = ini_getgroup(ini, grpname, -1);
01750   IniItem **item;
01751 
01752   if (group == NULL) return;
01753   group->item = NULL;
01754   item = &group->item;
01755 
01756   for (int i = 0; i < NT_END; i++) {
01757     const char *value;
01758     int v = GB(news_display, i * 2, 2);
01759 
01760     value = (v == 0 ? "off" : (v == 1 ? "summarized" : "full"));
01761 
01762     *item = ini_item_alloc(group, _news_display_name[i], strlen(_news_display_name[i]));
01763     (*item)->value = (char*)pool_strdup(&ini->pool, value, strlen(value));
01764     item = &(*item)->next;
01765   }
01766 }
01767 
01772 static void SaveVersionInConfig(IniFile *ini)
01773 {
01774   extern const char _openttd_revision[];
01775   extern uint32 _openttd_newgrf_version;
01776 
01777   IniGroup *group = ini_getgroup(ini, "version", -1);
01778 
01779   if (group == NULL) return;
01780   group->item = NULL;
01781   IniItem **item = &group->item;
01782 
01783   char version[9];
01784   snprintf(version, lengthof(version), "%08X", _openttd_newgrf_version);
01785 
01786   const char *versions[][2] = {
01787     { "version_string", _openttd_revision },
01788     { "version_number", version }
01789   };
01790 
01791   for (uint i = 0; i < lengthof(versions); i++) {
01792     *item = ini_item_alloc(group, versions[i][0], strlen(versions[i][0]));
01793     (*item)->value = (char*)pool_strdup(&ini->pool, versions[i][1], strlen(versions[i][1]));
01794     item = &(*item)->next;
01795   }
01796 }
01797 
01798 /* Save a GRF configuration to the given group name */
01799 static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list)
01800 {
01801   IniGroup *group = ini_getgroup(ini, grpname, -1);
01802   IniItem **item;
01803   const GRFConfig *c;
01804 
01805   if (group == NULL) return;
01806   group->item = NULL;
01807   item = &group->item;
01808 
01809   for (c = list; c != NULL; c = c->next) {
01810     char params[512];
01811     GRFBuildParamList(params, c, lastof(params));
01812 
01813     *item = ini_item_alloc(group, c->filename, strlen(c->filename));
01814     (*item)->value = (char*)pool_strdup(&ini->pool, params, strlen(params));
01815     item = &(*item)->next;
01816   }
01817 }
01818 
01819 /* Common handler for saving/loading variables to the configuration file */
01820 static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list)
01821 {
01822   proc(ini, (const SettingDesc*)_misc_settings,    "misc",  NULL);
01823   proc(ini, (const SettingDesc*)_music_settings,   "music", &msf);
01824 #ifdef WIN32
01825   proc(ini, (const SettingDesc*)_win32_settings,   "win32", NULL);
01826 #endif /* WIN32 */
01827 
01828   proc(ini, _gameopt_settings, "gameopt",  &_opt_newgame);
01829   proc(ini, _patch_settings,   "patches",  &_patches_newgame);
01830   proc(ini, _currency_settings,"currency", &_custom_currency);
01831 
01832 #ifdef ENABLE_NETWORK
01833   proc(ini, (const SettingDesc*)_network_settings, "network", NULL);
01834   proc_list(ini, "servers", _network_host_list, lengthof(_network_host_list), NULL);
01835   proc_list(ini, "bans",    _network_ban_list,  lengthof(_network_ban_list), NULL);
01836 #endif /* ENABLE_NETWORK */
01837 }
01838 
01839 extern void CheckDifficultyLevels();
01840 
01842 void LoadFromConfig()
01843 {
01844   IniFile *ini = ini_load(_config_file);
01845   ResetCurrencies(false); // Initialize the array of curencies, without preserving the custom one
01846   HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
01847   _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
01848   _grfconfig_static  = GRFLoadConfig(ini, "newgrf-static", true);
01849   _news_display_opt  = NewsDisplayLoadConfig(ini, "news_display");
01850   CheckDifficultyLevels();
01851   ini_free(ini);
01852 }
01853 
01855 void SaveToConfig()
01856 {
01857   IniFile *ini = ini_load(_config_file);
01858   HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
01859   GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
01860   GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
01861   NewsDisplaySaveConfig(ini, "news_display", _news_display_opt);
01862   SaveVersionInConfig(ini);
01863   ini_save(_config_file, ini);
01864   ini_free(ini);
01865 }
01866 
01867 static const SettingDesc *GetSettingDescription(uint index)
01868 {
01869   if (index >= lengthof(_patch_settings)) return NULL;
01870   return &_patch_settings[index];
01871 }
01872 
01881 CommandCost CmdChangePatchSetting(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
01882 {
01883   const SettingDesc *sd = GetSettingDescription(p1);
01884 
01885   if (sd == NULL) return CMD_ERROR;
01886   if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
01887 
01888   if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return CMD_ERROR;
01889   if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return CMD_ERROR;
01890 
01891   if (flags & DC_EXEC) {
01892     Patches *patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
01893     void *var = GetVariableAddress(patches_ptr, &sd->save);
01894     Write_ValidateSetting(var, sd, (int32)p2);
01895     if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
01896 
01897     InvalidateWindow(WC_GAME_OPTIONS, 0);
01898   }
01899 
01900   return CommandCost();
01901 }
01902 
01910 bool SetPatchValue(uint index, const Patches *object, int32 value)
01911 {
01912   const SettingDesc *sd = &_patch_settings[index];
01913   /* If an item is player-based, we do not send it over the network
01914    * (if any) to change. Also *hack*hack* we update the _newgame version
01915    * of patches because changing a player-based setting in a game also
01916    * changes its defaults. At least that is the convention we have chosen */
01917   if (sd->save.conv & SLF_NETWORK_NO) {
01918     void *var = GetVariableAddress(object, &sd->save);
01919     Write_ValidateSetting(var, sd, value);
01920 
01921     if (_game_mode != GM_MENU) {
01922       void *var2 = GetVariableAddress(&_patches_newgame, &sd->save);
01923       Write_ValidateSetting(var2, sd, value);
01924     }
01925     if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
01926     InvalidateWindow(WC_GAME_OPTIONS, 0);
01927     return true;
01928   }
01929 
01930   /* send non-player-based settings over the network */
01931   if (!_networking || (_networking && _network_server)) {
01932     return DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING);
01933   }
01934   return false;
01935 }
01936 
01937 const SettingDesc *GetPatchFromName(const char *name, uint *i)
01938 {
01939   const SettingDesc *sd;
01940 
01941   for (*i = 0, sd = _patch_settings; sd->save.cmd != SL_END; sd++, (*i)++) {
01942     if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
01943     if (strcmp(sd->desc.name, name) == 0) return sd;
01944   }
01945 
01946   return NULL;
01947 }
01948 
01949 /* Those 2 functions need to be here, else we have to make some stuff non-static
01950  * and besides, it is also better to keep stuff like this at the same place */
01951 bool IConsoleSetPatchSetting(const char *name, int32 value)
01952 {
01953   bool success;
01954   uint index;
01955   const SettingDesc *sd = GetPatchFromName(name, &index);
01956   const Patches *patches_ptr;
01957   void *ptr;
01958 
01959   if (sd == NULL) {
01960     IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name);
01961     return true;
01962   }
01963 
01964   patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
01965   ptr = GetVariableAddress(patches_ptr, &sd->save);
01966 
01967   success = SetPatchValue(index, patches_ptr, value);
01968   return success;
01969 }
01970 
01971 void IConsoleGetPatchSetting(const char *name)
01972 {
01973   char value[20];
01974   uint index;
01975   const SettingDesc *sd = GetPatchFromName(name, &index);
01976   const void *ptr;
01977 
01978   if (sd == NULL) {
01979     IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name);
01980     return;
01981   }
01982 
01983   ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_patches_newgame : &_patches, &sd->save);
01984 
01985   if (sd->desc.cmd == SDT_BOOLX) {
01986     snprintf(value, sizeof(value), (*(bool*)ptr == 1) ? "on" : "off");
01987   } else {
01988     snprintf(value, sizeof(value), "%d", (int32)ReadValue(ptr, sd->save.conv));
01989   }
01990 
01991   IConsolePrintF(_icolour_warn, "Current value for '%s' is: '%s' (min: %s%d, max: %d)",
01992     name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max);
01993 }
01994 
01995 void IConsoleListPatches()
01996 {
01997   IConsolePrintF(_icolour_warn, "All patches with their current value:");
01998 
01999   for (const SettingDesc *sd = _patch_settings; sd->save.cmd != SL_END; sd++) {
02000     char value[80];
02001     const void *ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_patches_newgame : &_patches, &sd->save);
02002 
02003     if (sd->desc.cmd == SDT_BOOLX) {
02004       snprintf(value, lengthof(value), (*(bool*)ptr == 1) ? "on" : "off");
02005     } else {
02006       snprintf(value, lengthof(value), "%d", (uint32)ReadValue(ptr, sd->save.conv));
02007     }
02008     IConsolePrintF(_icolour_def, "%s = %s", sd->desc.name, value);
02009   }
02010 
02011   IConsolePrintF(_icolour_warn, "Use 'patch' command to change a value");
02012 }
02013 
02018 static void LoadSettings(const SettingDesc *osd, void *object)
02019 {
02020   for (; osd->save.cmd != SL_END; osd++) {
02021     const SaveLoad *sld = &osd->save;
02022     void *ptr = GetVariableAddress(object, sld);
02023 
02024     if (!SlObjectMember(ptr, sld)) continue;
02025   }
02026 }
02027 
02032 static inline void LoadSettingsGlobList(const SettingDescGlobVarList *sdg)
02033 {
02034   LoadSettings((const SettingDesc*)sdg, NULL);
02035 }
02036 
02041 static void SaveSettings(const SettingDesc *sd, void *object)
02042 {
02043   /* We need to write the CH_RIFF header, but unfortunately can't call
02044    * SlCalcLength() because we have a different format. So do this manually */
02045   const SettingDesc *i;
02046   size_t length = 0;
02047   for (i = sd; i->save.cmd != SL_END; i++) {
02048     const void *ptr = GetVariableAddress(object, &i->save);
02049     length += SlCalcObjMemberLength(ptr, &i->save);
02050   }
02051   SlSetLength(length);
02052 
02053   for (i = sd; i->save.cmd != SL_END; i++) {
02054     void *ptr = GetVariableAddress(object, &i->save);
02055     SlObjectMember(ptr, &i->save);
02056   }
02057 }
02058 
02062 static inline void SaveSettingsGlobList(const SettingDescGlobVarList *sdg)
02063 {
02064   SaveSettings((const SettingDesc*)sdg, NULL);
02065 }
02066 
02067 static void Load_OPTS()
02068 {
02069   /* Copy over default setting since some might not get loaded in
02070    * a networking environment. This ensures for example that the local
02071    * autosave-frequency stays when joining a network-server */
02072   _opt = _opt_newgame;
02073   LoadSettings(_gameopt_settings, &_opt);
02074 }
02075 
02076 static void Save_OPTS()
02077 {
02078   SaveSettings(_gameopt_settings, &_opt);
02079 }
02080 
02081 static void Load_PATS()
02082 {
02083   /* Copy over default setting since some might not get loaded in
02084    * a networking environment. This ensures for example that the local
02085    * signal_side stays when joining a network-server */
02086   _patches = _patches_newgame;
02087   LoadSettings(_patch_settings, &_patches);
02088 }
02089 
02090 static void Save_PATS()
02091 {
02092   SaveSettings(_patch_settings, &_patches);
02093 }
02094 
02095 void CheckConfig()
02096 {
02097   // Increase old default values for pf_maxdepth and pf_maxlength
02098   // to support big networks.
02099   if (_patches_newgame.pf_maxdepth == 16 && _patches_newgame.pf_maxlength == 512) {
02100     _patches_newgame.pf_maxdepth = 48;
02101     _patches_newgame.pf_maxlength = 4096;
02102   }
02103 }
02104 
02105 void UpdatePatches()
02106 {
02107   /* Since old(er) savegames don't have any patches saved, we initialise
02108    * them with the default values just as it was in the old days.
02109    * Also new games need this copying-over */
02110   _patches = _patches_newgame; /* backwards compatibility */
02111 }
02112 
02113 extern const ChunkHandler _setting_chunk_handlers[] = {
02114   { 'OPTS', Save_OPTS, Load_OPTS, CH_RIFF},
02115   { 'PATS', Save_PATS, Load_PATS, CH_RIFF | CH_LAST},
02116 };
02117 
02118 static bool IsSignedVarMemType(VarType vt)
02119 {
02120   switch (GetVarMemType(vt)) {
02121     case SLE_VAR_I8:
02122     case SLE_VAR_I16:
02123     case SLE_VAR_I32:
02124     case SLE_VAR_I64:
02125       return true;
02126   }
02127   return false;
02128 }

Generated on Mon Sep 22 20:34:18 2008 for openttd by  doxygen 1.5.6