OpenTTD Source  1.11.2
settings.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
24 #include "stdafx.h"
25 #include <limits>
26 #include "currency.h"
27 #include "screenshot.h"
28 #include "network/network.h"
29 #include "network/network_func.h"
30 #include "settings_internal.h"
31 #include "command_func.h"
32 #include "console_func.h"
34 #include "genworld.h"
35 #include "train.h"
36 #include "news_func.h"
37 #include "window_func.h"
38 #include "sound_func.h"
39 #include "company_func.h"
40 #include "rev.h"
41 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
42 #include "fontcache.h"
43 #endif
44 #include "textbuf_gui.h"
45 #include "rail_gui.h"
46 #include "elrail_func.h"
47 #include "error.h"
48 #include "town.h"
49 #include "video/video_driver.hpp"
50 #include "sound/sound_driver.hpp"
51 #include "music/music_driver.hpp"
52 #include "blitter/factory.hpp"
53 #include "base_media_base.h"
54 #include "gamelog.h"
55 #include "settings_func.h"
56 #include "ini_type.h"
57 #include "ai/ai_config.hpp"
58 #include "ai/ai.hpp"
59 #include "game/game_config.hpp"
60 #include "game/game.hpp"
61 #include "ship.h"
62 #include "smallmap_gui.h"
63 #include "roadveh.h"
64 #include "fios.h"
65 #include "strings_func.h"
66 
67 #include "void_map.h"
68 #include "station_base.h"
69 
70 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
71 #define HAS_TRUETYPE_FONT
72 #endif
73 
74 #include "table/strings.h"
75 #include "table/settings.h"
76 
77 #include "safeguards.h"
78 
83 std::string _config_file;
84 
85 typedef std::list<ErrorMessageData> ErrorList;
87 
88 
89 typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object, bool only_startup);
90 typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
91 
92 static bool IsSignedVarMemType(VarType vt);
93 
97 static const char * const _list_group_names[] = {
98  "bans",
99  "newgrf",
100  "servers",
101  "server_bind_addresses",
102  nullptr
103 };
104 
112 static size_t LookupOneOfMany(const char *many, const char *one, size_t onelen = 0)
113 {
114  const char *s;
115  size_t idx;
116 
117  if (onelen == 0) onelen = strlen(one);
118 
119  /* check if it's an integer */
120  if (*one >= '0' && *one <= '9') return strtoul(one, nullptr, 0);
121 
122  idx = 0;
123  for (;;) {
124  /* find end of item */
125  s = many;
126  while (*s != '|' && *s != 0) s++;
127  if ((size_t)(s - many) == onelen && !memcmp(one, many, onelen)) return idx;
128  if (*s == 0) return (size_t)-1;
129  many = s + 1;
130  idx++;
131  }
132 }
133 
141 static size_t LookupManyOfMany(const char *many, const char *str)
142 {
143  const char *s;
144  size_t r;
145  size_t res = 0;
146 
147  for (;;) {
148  /* skip "whitespace" */
149  while (*str == ' ' || *str == '\t' || *str == '|') str++;
150  if (*str == 0) break;
151 
152  s = str;
153  while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++;
154 
155  r = LookupOneOfMany(many, str, s - str);
156  if (r == (size_t)-1) return r;
157 
158  SetBit(res, (uint8)r); // value found, set it
159  if (*s == 0) break;
160  str = s + 1;
161  }
162  return res;
163 }
164 
173 template<typename T>
174 static int ParseIntList(const char *p, T *items, int maxitems)
175 {
176  int n = 0; // number of items read so far
177  bool comma = false; // do we accept comma?
178 
179  while (*p != '\0') {
180  switch (*p) {
181  case ',':
182  /* Do not accept multiple commas between numbers */
183  if (!comma) return -1;
184  comma = false;
185  FALLTHROUGH;
186 
187  case ' ':
188  p++;
189  break;
190 
191  default: {
192  if (n == maxitems) return -1; // we don't accept that many numbers
193  char *end;
194  unsigned long v = strtoul(p, &end, 0);
195  if (p == end) return -1; // invalid character (not a number)
196  if (sizeof(T) < sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
197  items[n++] = v;
198  p = end; // first non-number
199  comma = true; // we accept comma now
200  break;
201  }
202  }
203  }
204 
205  /* If we have read comma but no number after it, fail.
206  * We have read comma when (n != 0) and comma is not allowed */
207  if (n != 0 && !comma) return -1;
208 
209  return n;
210 }
211 
220 static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
221 {
222  unsigned long items[64];
223  int i, nitems;
224 
225  if (str == nullptr) {
226  memset(items, 0, sizeof(items));
227  nitems = nelems;
228  } else {
229  nitems = ParseIntList(str, items, lengthof(items));
230  if (nitems != nelems) return false;
231  }
232 
233  switch (type) {
234  case SLE_VAR_BL:
235  case SLE_VAR_I8:
236  case SLE_VAR_U8:
237  for (i = 0; i != nitems; i++) ((byte*)array)[i] = items[i];
238  break;
239 
240  case SLE_VAR_I16:
241  case SLE_VAR_U16:
242  for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i];
243  break;
244 
245  case SLE_VAR_I32:
246  case SLE_VAR_U32:
247  for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i];
248  break;
249 
250  default: NOT_REACHED();
251  }
252 
253  return true;
254 }
255 
265 static void MakeIntList(char *buf, const char *last, const void *array, int nelems, VarType type)
266 {
267  int i, v = 0;
268  const byte *p = (const byte *)array;
269 
270  for (i = 0; i != nelems; i++) {
271  switch (GetVarMemType(type)) {
272  case SLE_VAR_BL:
273  case SLE_VAR_I8: v = *(const int8 *)p; p += 1; break;
274  case SLE_VAR_U8: v = *(const uint8 *)p; p += 1; break;
275  case SLE_VAR_I16: v = *(const int16 *)p; p += 2; break;
276  case SLE_VAR_U16: v = *(const uint16 *)p; p += 2; break;
277  case SLE_VAR_I32: v = *(const int32 *)p; p += 4; break;
278  case SLE_VAR_U32: v = *(const uint32 *)p; p += 4; break;
279  default: NOT_REACHED();
280  }
281  if (IsSignedVarMemType(type)) {
282  buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
283  } else if (type & SLF_HEX) {
284  buf += seprintf(buf, last, (i == 0) ? "0x%X" : ",0x%X", v);
285  } else {
286  buf += seprintf(buf, last, (i == 0) ? "%u" : ",%u", v);
287  }
288  }
289 }
290 
298 static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
299 {
300  int orig_id = id;
301 
302  /* Look for the id'th element */
303  while (--id >= 0) {
304  for (; *many != '|'; many++) {
305  if (*many == '\0') { // not found
306  seprintf(buf, last, "%d", orig_id);
307  return;
308  }
309  }
310  many++; // pass the |-character
311  }
312 
313  /* copy string until next item (|) or the end of the list if this is the last one */
314  while (*many != '\0' && *many != '|' && buf < last) *buf++ = *many++;
315  *buf = '\0';
316 }
317 
326 static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
327 {
328  const char *start;
329  int i = 0;
330  bool init = true;
331 
332  for (; x != 0; x >>= 1, i++) {
333  start = many;
334  while (*many != 0 && *many != '|') many++; // advance to the next element
335 
336  if (HasBit(x, 0)) { // item found, copy it
337  if (!init) buf += seprintf(buf, last, "|");
338  init = false;
339  if (start == many) {
340  buf += seprintf(buf, last, "%d", i);
341  } else {
342  memcpy(buf, start, many - start);
343  buf += many - start;
344  }
345  }
346 
347  if (*many == '|') many++;
348  }
349 
350  *buf = '\0';
351 }
352 
359 static const void *StringToVal(const SettingDescBase *desc, const char *orig_str)
360 {
361  const char *str = orig_str == nullptr ? "" : orig_str;
362 
363  switch (desc->cmd) {
364  case SDT_NUMX: {
365  char *end;
366  size_t val = strtoul(str, &end, 0);
367  if (end == str) {
368  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
369  msg.SetDParamStr(0, str);
370  msg.SetDParamStr(1, desc->name);
371  _settings_error_list.push_back(msg);
372  return desc->def;
373  }
374  if (*end != '\0') {
375  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
376  msg.SetDParamStr(0, desc->name);
377  _settings_error_list.push_back(msg);
378  }
379  return (void*)val;
380  }
381 
382  case SDT_ONEOFMANY: {
383  size_t r = LookupOneOfMany(desc->many, str);
384  /* if the first attempt of conversion from string to the appropriate value fails,
385  * look if we have defined a converter from old value to new value. */
386  if (r == (size_t)-1 && desc->proc_cnvt != nullptr) r = desc->proc_cnvt(str);
387  if (r != (size_t)-1) return (void*)r; // and here goes converted value
388 
389  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
390  msg.SetDParamStr(0, str);
391  msg.SetDParamStr(1, desc->name);
392  _settings_error_list.push_back(msg);
393  return desc->def;
394  }
395 
396  case SDT_MANYOFMANY: {
397  size_t r = LookupManyOfMany(desc->many, str);
398  if (r != (size_t)-1) return (void*)r;
399  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
400  msg.SetDParamStr(0, str);
401  msg.SetDParamStr(1, desc->name);
402  _settings_error_list.push_back(msg);
403  return desc->def;
404  }
405 
406  case SDT_BOOLX: {
407  if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return (void*)true;
408  if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return (void*)false;
409 
410  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
411  msg.SetDParamStr(0, str);
412  msg.SetDParamStr(1, desc->name);
413  _settings_error_list.push_back(msg);
414  return desc->def;
415  }
416 
417  case SDT_STDSTRING:
418  case SDT_STRING: return orig_str;
419  case SDT_INTLIST: return str;
420  default: break;
421  }
422 
423  return nullptr;
424 }
425 
435 static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
436 {
437  const SettingDescBase *sdb = &sd->desc;
438 
439  if (sdb->cmd != SDT_BOOLX &&
440  sdb->cmd != SDT_NUMX &&
441  sdb->cmd != SDT_ONEOFMANY &&
442  sdb->cmd != SDT_MANYOFMANY) {
443  return;
444  }
445 
446  /* We cannot know the maximum value of a bitset variable, so just have faith */
447  if (sdb->cmd != SDT_MANYOFMANY) {
448  /* We need to take special care of the uint32 type as we receive from the function
449  * a signed integer. While here also bail out on 64-bit settings as those are not
450  * supported. Unsigned 8 and 16-bit variables are safe since they fit into a signed
451  * 32-bit variable
452  * TODO: Support 64-bit settings/variables */
453  switch (GetVarMemType(sd->save.conv)) {
454  case SLE_VAR_NULL: return;
455  case SLE_VAR_BL:
456  case SLE_VAR_I8:
457  case SLE_VAR_U8:
458  case SLE_VAR_I16:
459  case SLE_VAR_U16:
460  case SLE_VAR_I32: {
461  /* Override the minimum value. No value below sdb->min, except special value 0 */
462  if (!(sdb->flags & SGF_0ISDISABLED) || val != 0) {
463  if (!(sdb->flags & SGF_MULTISTRING)) {
464  /* Clamp value-type setting to its valid range */
465  val = Clamp(val, sdb->min, sdb->max);
466  } else if (val < sdb->min || val > (int32)sdb->max) {
467  /* Reset invalid discrete setting (where different values change gameplay) to its default value */
468  val = (int32)(size_t)sdb->def;
469  }
470  }
471  break;
472  }
473  case SLE_VAR_U32: {
474  /* Override the minimum value. No value below sdb->min, except special value 0 */
475  uint32 uval = (uint32)val;
476  if (!(sdb->flags & SGF_0ISDISABLED) || uval != 0) {
477  if (!(sdb->flags & SGF_MULTISTRING)) {
478  /* Clamp value-type setting to its valid range */
479  uval = ClampU(uval, sdb->min, sdb->max);
480  } else if (uval < (uint)sdb->min || uval > sdb->max) {
481  /* Reset invalid discrete setting to its default value */
482  uval = (uint32)(size_t)sdb->def;
483  }
484  }
485  WriteValue(ptr, SLE_VAR_U32, (int64)uval);
486  return;
487  }
488  case SLE_VAR_I64:
489  case SLE_VAR_U64:
490  default: NOT_REACHED();
491  }
492  }
493 
494  WriteValue(ptr, sd->save.conv, (int64)val);
495 }
496 
506 static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool only_startup)
507 {
508  IniGroup *group;
509  IniGroup *group_def = ini->GetGroup(grpname);
510 
511  for (; sd->save.cmd != SL_END; sd++) {
512  const SettingDescBase *sdb = &sd->desc;
513  const SaveLoad *sld = &sd->save;
514 
515  if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
516  if (sd->desc.startup != only_startup) continue;
517 
518  /* For settings.xx.yy load the settings from [xx] yy = ? */
519  std::string s{ sdb->name };
520  auto sc = s.find('.');
521  if (sc != std::string::npos) {
522  group = ini->GetGroup(s.substr(0, sc));
523  s = s.substr(sc + 1);
524  } else {
525  group = group_def;
526  }
527 
528  IniItem *item = group->GetItem(s, false);
529  if (item == nullptr && group != group_def) {
530  /* For settings.xx.yy load the settings from [settings] yy = ? in case the previous
531  * did not exist (e.g. loading old config files with a [settings] section */
532  item = group_def->GetItem(s, false);
533  }
534  if (item == nullptr) {
535  /* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
536  * did not exist (e.g. loading old config files with a [yapf] section */
537  sc = s.find('.');
538  if (sc != std::string::npos) item = ini->GetGroup(s.substr(0, sc))->GetItem(s.substr(sc + 1), false);
539  }
540 
541  const void *p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value.has_value() ? item->value->c_str() : nullptr);
542  void *ptr = GetVariableAddress(object, sld);
543 
544  switch (sdb->cmd) {
545  case SDT_BOOLX: // All four are various types of (integer) numbers
546  case SDT_NUMX:
547  case SDT_ONEOFMANY:
548  case SDT_MANYOFMANY:
549  Write_ValidateSetting(ptr, sd, (int32)(size_t)p);
550  break;
551 
552  case SDT_STRING:
553  switch (GetVarMemType(sld->conv)) {
554  case SLE_VAR_STRB:
555  case SLE_VAR_STRBQ:
556  if (p != nullptr) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1);
557  break;
558 
559  case SLE_VAR_STR:
560  case SLE_VAR_STRQ:
561  free(*(char**)ptr);
562  *(char**)ptr = p == nullptr ? nullptr : stredup((const char*)p);
563  break;
564 
565  case SLE_VAR_CHAR: if (p != nullptr) *(char *)ptr = *(const char *)p; break;
566 
567  default: NOT_REACHED();
568  }
569  break;
570 
571  case SDT_STDSTRING:
572  switch (GetVarMemType(sld->conv)) {
573  case SLE_VAR_STR:
574  case SLE_VAR_STRQ:
575  if (p != nullptr) {
576  reinterpret_cast<std::string *>(ptr)->assign((const char *)p);
577  } else {
578  reinterpret_cast<std::string *>(ptr)->clear();
579  }
580  break;
581 
582  default: NOT_REACHED();
583  }
584 
585  break;
586 
587  case SDT_INTLIST: {
588  if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
589  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
590  msg.SetDParamStr(0, sdb->name);
591  _settings_error_list.push_back(msg);
592 
593  /* Use default */
594  LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
595  } else if (sd->desc.proc_cnvt != nullptr) {
596  sd->desc.proc_cnvt((const char*)p);
597  }
598  break;
599  }
600  default: NOT_REACHED();
601  }
602  }
603 }
604 
617 static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool)
618 {
619  IniGroup *group_def = nullptr, *group;
620  IniItem *item;
621  char buf[512];
622  void *ptr;
623 
624  for (; sd->save.cmd != SL_END; sd++) {
625  const SettingDescBase *sdb = &sd->desc;
626  const SaveLoad *sld = &sd->save;
627 
628  /* If the setting is not saved to the configuration
629  * file, just continue with the next setting */
630  if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
631  if (sld->conv & SLF_NOT_IN_CONFIG) continue;
632 
633  /* XXX - wtf is this?? (group override?) */
634  std::string s{ sdb->name };
635  auto sc = s.find('.');
636  if (sc != std::string::npos) {
637  group = ini->GetGroup(s.substr(0, sc));
638  s = s.substr(sc + 1);
639  } else {
640  if (group_def == nullptr) group_def = ini->GetGroup(grpname);
641  group = group_def;
642  }
643 
644  item = group->GetItem(s, true);
645  ptr = GetVariableAddress(object, sld);
646 
647  if (item->value.has_value()) {
648  /* check if the value is the same as the old value */
649  const void *p = StringToVal(sdb, item->value->c_str());
650 
651  /* The main type of a variable/setting is in bytes 8-15
652  * The subtype (what kind of numbers do we have there) is in 0-7 */
653  switch (sdb->cmd) {
654  case SDT_BOOLX:
655  case SDT_NUMX:
656  case SDT_ONEOFMANY:
657  case SDT_MANYOFMANY:
658  switch (GetVarMemType(sld->conv)) {
659  case SLE_VAR_BL:
660  if (*(bool*)ptr == (p != nullptr)) continue;
661  break;
662 
663  case SLE_VAR_I8:
664  case SLE_VAR_U8:
665  if (*(byte*)ptr == (byte)(size_t)p) continue;
666  break;
667 
668  case SLE_VAR_I16:
669  case SLE_VAR_U16:
670  if (*(uint16*)ptr == (uint16)(size_t)p) continue;
671  break;
672 
673  case SLE_VAR_I32:
674  case SLE_VAR_U32:
675  if (*(uint32*)ptr == (uint32)(size_t)p) continue;
676  break;
677 
678  default: NOT_REACHED();
679  }
680  break;
681 
682  default: break; // Assume the other types are always changed
683  }
684  }
685 
686  /* Value has changed, get the new value and put it into a buffer */
687  switch (sdb->cmd) {
688  case SDT_BOOLX:
689  case SDT_NUMX:
690  case SDT_ONEOFMANY:
691  case SDT_MANYOFMANY: {
692  uint32 i = (uint32)ReadValue(ptr, sld->conv);
693 
694  switch (sdb->cmd) {
695  case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break;
696  case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : (sld->conv & SLF_HEX) ? "%X" : "%u", i); break;
697  case SDT_ONEOFMANY: MakeOneOfMany(buf, lastof(buf), sdb->many, i); break;
698  case SDT_MANYOFMANY: MakeManyOfMany(buf, lastof(buf), sdb->many, i); break;
699  default: NOT_REACHED();
700  }
701  break;
702  }
703 
704  case SDT_STRING:
705  switch (GetVarMemType(sld->conv)) {
706  case SLE_VAR_STRB: strecpy(buf, (char*)ptr, lastof(buf)); break;
707  case SLE_VAR_STRBQ:seprintf(buf, lastof(buf), "\"%s\"", (char*)ptr); break;
708  case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break;
709 
710  case SLE_VAR_STRQ:
711  if (*(char**)ptr == nullptr) {
712  buf[0] = '\0';
713  } else {
714  seprintf(buf, lastof(buf), "\"%s\"", *(char**)ptr);
715  }
716  break;
717 
718  case SLE_VAR_CHAR: buf[0] = *(char*)ptr; buf[1] = '\0'; break;
719  default: NOT_REACHED();
720  }
721  break;
722 
723  case SDT_STDSTRING:
724  switch (GetVarMemType(sld->conv)) {
725  case SLE_VAR_STR: strecpy(buf, reinterpret_cast<std::string *>(ptr)->c_str(), lastof(buf)); break;
726 
727  case SLE_VAR_STRQ:
728  if (reinterpret_cast<std::string *>(ptr)->empty()) {
729  buf[0] = '\0';
730  } else {
731  seprintf(buf, lastof(buf), "\"%s\"", reinterpret_cast<std::string *>(ptr)->c_str());
732  }
733  break;
734 
735  default: NOT_REACHED();
736  }
737  break;
738 
739  case SDT_INTLIST:
740  MakeIntList(buf, lastof(buf), ptr, sld->length, sld->conv);
741  break;
742 
743  default: NOT_REACHED();
744  }
745 
746  /* The value is different, that means we have to write it to the ini */
747  item->value.emplace(buf);
748  }
749 }
750 
760 static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
761 {
762  IniGroup *group = ini->GetGroup(grpname);
763 
764  if (group == nullptr) return;
765 
766  list.clear();
767 
768  for (const IniItem *item = group->item; item != nullptr; item = item->next) {
769  if (!item->name.empty()) list.push_back(item->name);
770  }
771 }
772 
782 static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
783 {
784  IniGroup *group = ini->GetGroup(grpname);
785 
786  if (group == nullptr) return;
787  group->Clear();
788 
789  for (const auto &iter : list) {
790  group->GetItem(iter.c_str(), true)->SetValue("");
791  }
792 }
793 
800 void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
801 {
802  IniLoadSettings(ini, _window_settings, grpname, desc, false);
803 }
804 
811 void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
812 {
813  IniSaveSettings(ini, _window_settings, grpname, desc, false);
814 }
815 
821 bool SettingDesc::IsEditable(bool do_command) const
822 {
823  if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->desc.flags & SGF_PER_COMPANY)) return false;
824  if ((this->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
825  if ((this->desc.flags & SGF_NO_NETWORK) && _networking) return false;
826  if ((this->desc.flags & SGF_NEWGAME_ONLY) &&
827  (_game_mode == GM_NORMAL ||
828  (_game_mode == GM_EDITOR && !(this->desc.flags & SGF_SCENEDIT_TOO)))) return false;
829  if ((this->desc.flags & SGF_SCENEDIT_ONLY) && _game_mode != GM_EDITOR) return false;
830  return true;
831 }
832 
838 {
839  if (this->desc.flags & SGF_PER_COMPANY) return ST_COMPANY;
840  return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
841 }
842 
843 /* Begin - Callback Functions for the various settings. */
844 
846 static bool v_PositionMainToolbar(int32 p1)
847 {
848  if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
849  return true;
850 }
851 
853 static bool v_PositionStatusbar(int32 p1)
854 {
855  if (_game_mode != GM_MENU) {
856  PositionStatusbar(nullptr);
857  PositionNewsMessage(nullptr);
858  PositionNetworkChatWindow(nullptr);
859  }
860  return true;
861 }
862 
863 static bool PopulationInLabelActive(int32 p1)
864 {
866  return true;
867 }
868 
869 static bool RedrawScreen(int32 p1)
870 {
872  return true;
873 }
874 
880 static bool RedrawSmallmap(int32 p1)
881 {
882  BuildLandLegend();
885  return true;
886 }
887 
888 static bool InvalidateDetailsWindow(int32 p1)
889 {
891  return true;
892 }
893 
894 static bool StationSpreadChanged(int32 p1)
895 {
898  return true;
899 }
900 
901 static bool InvalidateBuildIndustryWindow(int32 p1)
902 {
904  return true;
905 }
906 
907 static bool CloseSignalGUI(int32 p1)
908 {
909  if (p1 == 0) {
911  }
912  return true;
913 }
914 
915 static bool InvalidateTownViewWindow(int32 p1)
916 {
918  return true;
919 }
920 
921 static bool DeleteSelectStationWindow(int32 p1)
922 {
924  return true;
925 }
926 
927 static bool UpdateConsists(int32 p1)
928 {
929  for (Train *t : Train::Iterate()) {
930  /* Update the consist of all trains so the maximum speed is set correctly. */
931  if (t->IsFrontEngine() || t->IsFreeWagon()) t->ConsistChanged(CCF_TRACK);
932  }
934  return true;
935 }
936 
937 /* Check service intervals of vehicles, p1 is value of % or day based servicing */
938 static bool CheckInterval(int32 p1)
939 {
940  bool update_vehicles;
942  if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
944  update_vehicles = false;
945  } else {
946  vds = &Company::Get(_current_company)->settings.vehicle;
947  update_vehicles = true;
948  }
949 
950  if (p1 != 0) {
951  vds->servint_trains = 50;
952  vds->servint_roadveh = 50;
953  vds->servint_aircraft = 50;
954  vds->servint_ships = 50;
955  } else {
956  vds->servint_trains = 150;
957  vds->servint_roadveh = 150;
958  vds->servint_aircraft = 100;
959  vds->servint_ships = 360;
960  }
961 
962  if (update_vehicles) {
964  for (Vehicle *v : Vehicle::Iterate()) {
965  if (v->owner == _current_company && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
966  v->SetServiceInterval(CompanyServiceInterval(c, v->type));
967  v->SetServiceIntervalIsPercent(p1 != 0);
968  }
969  }
970  }
971 
972  InvalidateDetailsWindow(0);
973 
974  return true;
975 }
976 
977 static bool UpdateInterval(VehicleType type, int32 p1)
978 {
979  bool update_vehicles;
981  if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
983  update_vehicles = false;
984  } else {
985  vds = &Company::Get(_current_company)->settings.vehicle;
986  update_vehicles = true;
987  }
988 
989  /* Test if the interval is valid */
990  uint16 interval = GetServiceIntervalClamped(p1, vds->servint_ispercent);
991  if (interval != p1) return false;
992 
993  if (update_vehicles) {
994  for (Vehicle *v : Vehicle::Iterate()) {
995  if (v->owner == _current_company && v->type == type && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
996  v->SetServiceInterval(p1);
997  }
998  }
999  }
1000 
1001  InvalidateDetailsWindow(0);
1002 
1003  return true;
1004 }
1005 
1006 static bool UpdateIntervalTrains(int32 p1)
1007 {
1008  return UpdateInterval(VEH_TRAIN, p1);
1009 }
1010 
1011 static bool UpdateIntervalRoadVeh(int32 p1)
1012 {
1013  return UpdateInterval(VEH_ROAD, p1);
1014 }
1015 
1016 static bool UpdateIntervalShips(int32 p1)
1017 {
1018  return UpdateInterval(VEH_SHIP, p1);
1019 }
1020 
1021 static bool UpdateIntervalAircraft(int32 p1)
1022 {
1023  return UpdateInterval(VEH_AIRCRAFT, p1);
1024 }
1025 
1026 static bool TrainAccelerationModelChanged(int32 p1)
1027 {
1028  for (Train *t : Train::Iterate()) {
1029  if (t->IsFrontEngine()) {
1030  t->tcache.cached_max_curve_speed = t->GetCurveSpeedLimit();
1031  t->UpdateAcceleration();
1032  }
1033  }
1034 
1035  /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
1039 
1040  return true;
1041 }
1042 
1048 static bool TrainSlopeSteepnessChanged(int32 p1)
1049 {
1050  for (Train *t : Train::Iterate()) {
1051  if (t->IsFrontEngine()) t->CargoChanged();
1052  }
1053 
1054  return true;
1055 }
1056 
1062 static bool RoadVehAccelerationModelChanged(int32 p1)
1063 {
1064  if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
1065  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1066  if (rv->IsFrontEngine()) {
1067  rv->CargoChanged();
1068  }
1069  }
1070  }
1071 
1072  /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
1076 
1077  return true;
1078 }
1079 
1085 static bool RoadVehSlopeSteepnessChanged(int32 p1)
1086 {
1087  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1088  if (rv->IsFrontEngine()) rv->CargoChanged();
1089  }
1090 
1091  return true;
1092 }
1093 
1094 static bool DragSignalsDensityChanged(int32)
1095 {
1097 
1098  return true;
1099 }
1100 
1101 static bool TownFoundingChanged(int32 p1)
1102 {
1103  if (_game_mode != GM_EDITOR && _settings_game.economy.found_town == TF_FORBIDDEN) {
1105  return true;
1106  }
1108  return true;
1109 }
1110 
1111 static bool InvalidateVehTimetableWindow(int32 p1)
1112 {
1114  return true;
1115 }
1116 
1117 static bool ZoomMinMaxChanged(int32 p1)
1118 {
1119  extern void ConstrainAllViewportsZoom();
1120  ConstrainAllViewportsZoom();
1123  /* Restrict GUI zoom if it is no longer available. */
1125  UpdateCursorSize();
1127  }
1128  return true;
1129 }
1130 
1131 static bool SpriteZoomMinChanged(int32 p1) {
1133  /* Force all sprites to redraw at the new chosen zoom level */
1135  return true;
1136 }
1137 
1145 static bool InvalidateNewGRFChangeWindows(int32 p1)
1146 {
1149  ReInitAllWindows();
1150  return true;
1151 }
1152 
1153 static bool InvalidateCompanyLiveryWindow(int32 p1)
1154 {
1156  return RedrawScreen(p1);
1157 }
1158 
1159 static bool InvalidateIndustryViewWindow(int32 p1)
1160 {
1162  return true;
1163 }
1164 
1165 static bool InvalidateAISettingsWindow(int32 p1)
1166 {
1168  return true;
1169 }
1170 
1176 static bool RedrawTownAuthority(int32 p1)
1177 {
1179  return true;
1180 }
1181 
1188 {
1190  return true;
1191 }
1192 
1198 static bool InvalidateCompanyWindow(int32 p1)
1199 {
1201  return true;
1202 }
1203 
1205 static void ValidateSettings()
1206 {
1207  /* Do not allow a custom sea level with the original land generator. */
1211  }
1212 }
1213 
1214 static bool DifficultyNoiseChange(int32 i)
1215 {
1216  if (_game_mode == GM_NORMAL) {
1220  }
1221  }
1222 
1223  return true;
1224 }
1225 
1226 static bool MaxNoAIsChange(int32 i)
1227 {
1228  if (GetGameSettings().difficulty.max_no_competitors != 0 &&
1229  AI::GetInfoList()->size() == 0 &&
1230  (!_networking || _network_server)) {
1231  ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
1232  }
1233 
1235  return true;
1236 }
1237 
1243 static bool CheckRoadSide(int p1)
1244 {
1245  extern bool RoadVehiclesAreBuilt();
1246  return _game_mode == GM_MENU || !RoadVehiclesAreBuilt();
1247 }
1248 
1256 static size_t ConvertLandscape(const char *value)
1257 {
1258  /* try with the old values */
1259  return LookupOneOfMany("normal|hilly|desert|candy", value);
1260 }
1261 
1262 static bool CheckFreeformEdges(int32 p1)
1263 {
1264  if (_game_mode == GM_MENU) return true;
1265  if (p1 != 0) {
1266  for (Ship *s : Ship::Iterate()) {
1267  /* Check if there is a ship on the northern border. */
1268  if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
1269  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
1270  return false;
1271  }
1272  }
1273  for (const BaseStation *st : BaseStation::Iterate()) {
1274  /* Check if there is a non-deleted buoy on the northern border. */
1275  if (st->IsInUse() && (TileX(st->xy) == 0 || TileY(st->xy) == 0)) {
1276  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
1277  return false;
1278  }
1279  }
1280  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
1281  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
1282  } else {
1283  for (uint i = 0; i < MapMaxX(); i++) {
1284  if (TileHeight(TileXY(i, 1)) != 0) {
1285  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1286  return false;
1287  }
1288  }
1289  for (uint i = 1; i < MapMaxX(); i++) {
1290  if (!IsTileType(TileXY(i, MapMaxY() - 1), MP_WATER) || TileHeight(TileXY(1, MapMaxY())) != 0) {
1291  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1292  return false;
1293  }
1294  }
1295  for (uint i = 0; i < MapMaxY(); i++) {
1296  if (TileHeight(TileXY(1, i)) != 0) {
1297  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1298  return false;
1299  }
1300  }
1301  for (uint i = 1; i < MapMaxY(); i++) {
1302  if (!IsTileType(TileXY(MapMaxX() - 1, i), MP_WATER) || TileHeight(TileXY(MapMaxX(), i)) != 0) {
1303  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1304  return false;
1305  }
1306  }
1307  /* Make tiles at the border water again. */
1308  for (uint i = 0; i < MapMaxX(); i++) {
1309  SetTileHeight(TileXY(i, 0), 0);
1310  SetTileType(TileXY(i, 0), MP_WATER);
1311  }
1312  for (uint i = 0; i < MapMaxY(); i++) {
1313  SetTileHeight(TileXY(0, i), 0);
1314  SetTileType(TileXY(0, i), MP_WATER);
1315  }
1316  }
1318  return true;
1319 }
1320 
1325 static bool ChangeDynamicEngines(int32 p1)
1326 {
1327  if (_game_mode == GM_MENU) return true;
1328 
1330  ShowErrorMessage(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES, INVALID_STRING_ID, WL_ERROR);
1331  return false;
1332  }
1333 
1334  return true;
1335 }
1336 
1337 static bool ChangeMaxHeightLevel(int32 p1)
1338 {
1339  if (_game_mode == GM_NORMAL) return false;
1340  if (_game_mode != GM_EDITOR) return true;
1341 
1342  /* Check if at least one mountain on the map is higher than the new value.
1343  * If yes, disallow the change. */
1344  for (TileIndex t = 0; t < MapSize(); t++) {
1345  if ((int32)TileHeight(t) > p1) {
1346  ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
1347  /* Return old, unchanged value */
1348  return false;
1349  }
1350  }
1351 
1352  /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
1354 
1355  return true;
1356 }
1357 
1358 static bool StationCatchmentChanged(int32 p1)
1359 {
1362  return true;
1363 }
1364 
1365 static bool MaxVehiclesChanged(int32 p1)
1366 {
1369  return true;
1370 }
1371 
1372 static bool InvalidateShipPathCache(int32 p1)
1373 {
1374  for (Ship *s : Ship::Iterate()) {
1375  s->path.clear();
1376  }
1377  return true;
1378 }
1379 
1380 static bool UpdateClientName(int32 p1)
1381 {
1383  return true;
1384 }
1385 
1386 static bool UpdateServerPassword(int32 p1)
1387 {
1388  if (strcmp(_settings_client.network.server_password, "*") == 0) {
1390  }
1391 
1392  return true;
1393 }
1394 
1395 static bool UpdateRconPassword(int32 p1)
1396 {
1397  if (strcmp(_settings_client.network.rcon_password, "*") == 0) {
1399  }
1400 
1401  return true;
1402 }
1403 
1404 static bool UpdateClientConfigValues(int32 p1)
1405 {
1407 
1408  return true;
1409 }
1410 
1411 /* End - Callback Functions */
1412 
1417 {
1418  memset(_old_diff_custom, 0, sizeof(_old_diff_custom));
1419 }
1420 
1427 static void HandleOldDiffCustom(bool savegame)
1428 {
1429  uint options_to_load = GAME_DIFFICULTY_NUM - ((savegame && IsSavegameVersionBefore(SLV_4)) ? 1 : 0);
1430 
1431  if (!savegame) {
1432  /* If we did read to old_diff_custom, then at least one value must be non 0. */
1433  bool old_diff_custom_used = false;
1434  for (uint i = 0; i < options_to_load && !old_diff_custom_used; i++) {
1435  old_diff_custom_used = (_old_diff_custom[i] != 0);
1436  }
1437 
1438  if (!old_diff_custom_used) return;
1439  }
1440 
1441  for (uint i = 0; i < options_to_load; i++) {
1442  const SettingDesc *sd = &_settings[i];
1443  /* Skip deprecated options */
1444  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1445  void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
1446  Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
1447  }
1448 }
1449 
1450 static void AILoadConfig(IniFile *ini, const char *grpname)
1451 {
1452  IniGroup *group = ini->GetGroup(grpname);
1453  IniItem *item;
1454 
1455  /* Clean any configured AI */
1456  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1458  }
1459 
1460  /* If no group exists, return */
1461  if (group == nullptr) return;
1462 
1464  for (item = group->item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
1466 
1467  config->Change(item->name.c_str());
1468  if (!config->HasScript()) {
1469  if (item->name != "none") {
1470  DEBUG(script, 0, "The AI by the name '%s' was no longer found, and removed from the list.", item->name.c_str());
1471  continue;
1472  }
1473  }
1474  if (item->value.has_value()) config->StringToSettings(item->value->c_str());
1475  }
1476 }
1477 
1478 static void GameLoadConfig(IniFile *ini, const char *grpname)
1479 {
1480  IniGroup *group = ini->GetGroup(grpname);
1481  IniItem *item;
1482 
1483  /* Clean any configured GameScript */
1485 
1486  /* If no group exists, return */
1487  if (group == nullptr) return;
1488 
1489  item = group->item;
1490  if (item == nullptr) return;
1491 
1493 
1494  config->Change(item->name.c_str());
1495  if (!config->HasScript()) {
1496  if (item->name != "none") {
1497  DEBUG(script, 0, "The GameScript by the name '%s' was no longer found, and removed from the list.", item->name.c_str());
1498  return;
1499  }
1500  }
1501  if (item->value.has_value()) config->StringToSettings(item->value->c_str());
1502 }
1503 
1509 static int DecodeHexNibble(char c)
1510 {
1511  if (c >= '0' && c <= '9') return c - '0';
1512  if (c >= 'A' && c <= 'F') return c + 10 - 'A';
1513  if (c >= 'a' && c <= 'f') return c + 10 - 'a';
1514  return -1;
1515 }
1516 
1525 static bool DecodeHexText(const char *pos, uint8 *dest, size_t dest_size)
1526 {
1527  while (dest_size > 0) {
1528  int hi = DecodeHexNibble(pos[0]);
1529  int lo = (hi >= 0) ? DecodeHexNibble(pos[1]) : -1;
1530  if (lo < 0) return false;
1531  *dest++ = (hi << 4) | lo;
1532  pos += 2;
1533  dest_size--;
1534  }
1535  return *pos == '|';
1536 }
1537 
1544 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
1545 {
1546  IniGroup *group = ini->GetGroup(grpname);
1547  IniItem *item;
1548  GRFConfig *first = nullptr;
1549  GRFConfig **curr = &first;
1550 
1551  if (group == nullptr) return nullptr;
1552 
1553  for (item = group->item; item != nullptr; item = item->next) {
1554  GRFConfig *c = nullptr;
1555 
1556  uint8 grfid_buf[4], md5sum[16];
1557  const char *filename = item->name.c_str();
1558  bool has_grfid = false;
1559  bool has_md5sum = false;
1560 
1561  /* Try reading "<grfid>|" and on success, "<md5sum>|". */
1562  has_grfid = DecodeHexText(filename, grfid_buf, lengthof(grfid_buf));
1563  if (has_grfid) {
1564  filename += 1 + 2 * lengthof(grfid_buf);
1565  has_md5sum = DecodeHexText(filename, md5sum, lengthof(md5sum));
1566  if (has_md5sum) filename += 1 + 2 * lengthof(md5sum);
1567 
1568  uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1569  if (has_md5sum) {
1570  const GRFConfig *s = FindGRFConfig(grfid, FGCM_EXACT, md5sum);
1571  if (s != nullptr) c = new GRFConfig(*s);
1572  }
1573  if (c == nullptr && !FioCheckFileExists(filename, NEWGRF_DIR)) {
1574  const GRFConfig *s = FindGRFConfig(grfid, FGCM_NEWEST_VALID);
1575  if (s != nullptr) c = new GRFConfig(*s);
1576  }
1577  }
1578  if (c == nullptr) c = new GRFConfig(filename);
1579 
1580  /* Parse parameters */
1581  if (item->value.has_value() && !item->value->empty()) {
1582  int count = ParseIntList(item->value->c_str(), c->param, lengthof(c->param));
1583  if (count < 0) {
1584  SetDParamStr(0, filename);
1585  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
1586  count = 0;
1587  }
1588  c->num_params = count;
1589  }
1590 
1591  /* Check if item is valid */
1592  if (!FillGRFDetails(c, is_static) || HasBit(c->flags, GCF_INVALID)) {
1593  if (c->status == GCS_NOT_FOUND) {
1594  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1595  } else if (HasBit(c->flags, GCF_UNSAFE)) {
1596  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1597  } else if (HasBit(c->flags, GCF_SYSTEM)) {
1598  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1599  } else if (HasBit(c->flags, GCF_INVALID)) {
1600  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1601  } else {
1602  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1603  }
1604 
1605  SetDParamStr(0, StrEmpty(filename) ? item->name.c_str() : filename);
1606  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_GRF, WL_CRITICAL);
1607  delete c;
1608  continue;
1609  }
1610 
1611  /* Check for duplicate GRFID (will also check for duplicate filenames) */
1612  bool duplicate = false;
1613  for (const GRFConfig *gc = first; gc != nullptr; gc = gc->next) {
1614  if (gc->ident.grfid == c->ident.grfid) {
1615  SetDParamStr(0, c->filename);
1616  SetDParamStr(1, gc->filename);
1617  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_DUPLICATE_GRFID, WL_CRITICAL);
1618  duplicate = true;
1619  break;
1620  }
1621  }
1622  if (duplicate) {
1623  delete c;
1624  continue;
1625  }
1626 
1627  /* Mark file as static to avoid saving in savegame. */
1628  if (is_static) SetBit(c->flags, GCF_STATIC);
1629 
1630  /* Add item to list */
1631  *curr = c;
1632  curr = &c->next;
1633  }
1634 
1635  return first;
1636 }
1637 
1638 static void AISaveConfig(IniFile *ini, const char *grpname)
1639 {
1640  IniGroup *group = ini->GetGroup(grpname);
1641 
1642  if (group == nullptr) return;
1643  group->Clear();
1644 
1645  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1647  const char *name;
1648  char value[1024];
1649  config->SettingsToString(value, lastof(value));
1650 
1651  if (config->HasScript()) {
1652  name = config->GetName();
1653  } else {
1654  name = "none";
1655  }
1656 
1657  IniItem *item = new IniItem(group, name);
1658  item->SetValue(value);
1659  }
1660 }
1661 
1662 static void GameSaveConfig(IniFile *ini, const char *grpname)
1663 {
1664  IniGroup *group = ini->GetGroup(grpname);
1665 
1666  if (group == nullptr) return;
1667  group->Clear();
1668 
1670  const char *name;
1671  char value[1024];
1672  config->SettingsToString(value, lastof(value));
1673 
1674  if (config->HasScript()) {
1675  name = config->GetName();
1676  } else {
1677  name = "none";
1678  }
1679 
1680  IniItem *item = new IniItem(group, name);
1681  item->SetValue(value);
1682 }
1683 
1688 static void SaveVersionInConfig(IniFile *ini)
1689 {
1690  IniGroup *group = ini->GetGroup("version");
1691 
1692  char version[9];
1693  seprintf(version, lastof(version), "%08X", _openttd_newgrf_version);
1694 
1695  const char * const versions[][2] = {
1696  { "version_string", _openttd_revision },
1697  { "version_number", version }
1698  };
1699 
1700  for (uint i = 0; i < lengthof(versions); i++) {
1701  group->GetItem(versions[i][0], true)->SetValue(versions[i][1]);
1702  }
1703 }
1704 
1705 /* Save a GRF configuration to the given group name */
1706 static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list)
1707 {
1708  ini->RemoveGroup(grpname);
1709  IniGroup *group = ini->GetGroup(grpname);
1710  const GRFConfig *c;
1711 
1712  for (c = list; c != nullptr; c = c->next) {
1713  /* Hex grfid (4 bytes in nibbles), "|", hex md5sum (16 bytes in nibbles), "|", file system path. */
1714  char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1715  char params[512];
1716  GRFBuildParamList(params, c, lastof(params));
1717 
1718  char *pos = key + seprintf(key, lastof(key), "%08X|", BSWAP32(c->ident.grfid));
1719  pos = md5sumToString(pos, lastof(key), c->ident.md5sum);
1720  seprintf(pos, lastof(key), "|%s", c->filename);
1721  group->GetItem(key, true)->SetValue(params);
1722  }
1723 }
1724 
1725 /* Common handler for saving/loading variables to the configuration file */
1726 static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool only_startup = false)
1727 {
1728  proc(ini, (const SettingDesc*)_misc_settings, "misc", nullptr, only_startup);
1729 #if defined(_WIN32) && !defined(DEDICATED)
1730  proc(ini, (const SettingDesc*)_win32_settings, "win32", nullptr, only_startup);
1731 #endif /* _WIN32 */
1732 
1733  proc(ini, _settings, "patches", &_settings_newgame, only_startup);
1734  proc(ini, _currency_settings,"currency", &_custom_currency, only_startup);
1735  proc(ini, _company_settings, "company", &_settings_client.company, only_startup);
1736 
1737  if (!only_startup) {
1738  proc_list(ini, "server_bind_addresses", _network_bind_list);
1739  proc_list(ini, "servers", _network_host_list);
1740  proc_list(ini, "bans", _network_ban_list);
1741  }
1742 }
1743 
1744 static IniFile *IniLoadConfig()
1745 {
1746  IniFile *ini = new IniFile(_list_group_names);
1748  return ini;
1749 }
1750 
1755 void LoadFromConfig(bool startup)
1756 {
1757  IniFile *ini = IniLoadConfig();
1758  if (!startup) ResetCurrencies(false); // Initialize the array of currencies, without preserving the custom one
1759 
1760  /* Load basic settings only during bootstrap, load other settings not during bootstrap */
1761  HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList, startup);
1762 
1763  if (!startup) {
1764  _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
1765  _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
1766  AILoadConfig(ini, "ai_players");
1767  GameLoadConfig(ini, "game_scripts");
1768 
1770  IniLoadSettings(ini, _gameopt_settings, "gameopt", &_settings_newgame, false);
1771  HandleOldDiffCustom(false);
1772 
1773  ValidateSettings();
1774 
1775  /* Display scheduled errors */
1776  extern void ScheduleErrorMessage(ErrorList &datas);
1778  if (FindWindowById(WC_ERRMSG, 0) == nullptr) ShowFirstError();
1779  }
1780 
1781  delete ini;
1782 }
1783 
1786 {
1787  IniFile *ini = IniLoadConfig();
1788 
1789  /* Remove some obsolete groups. These have all been loaded into other groups. */
1790  ini->RemoveGroup("patches");
1791  ini->RemoveGroup("yapf");
1792  ini->RemoveGroup("gameopt");
1793 
1794  HandleSettingDescs(ini, IniSaveSettings, IniSaveSettingList);
1795  GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
1796  GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
1797  AISaveConfig(ini, "ai_players");
1798  GameSaveConfig(ini, "game_scripts");
1799  SaveVersionInConfig(ini);
1800  ini->SaveToDisk(_config_file);
1801  delete ini;
1802 }
1803 
1809 {
1810  StringList list;
1811 
1812  std::unique_ptr<IniFile> ini(IniLoadConfig());
1813  for (IniGroup *group = ini->group; group != nullptr; group = group->next) {
1814  if (group->name.compare(0, 7, "preset-") == 0) {
1815  list.push_back(group->name.substr(7));
1816  }
1817  }
1818 
1819  return list;
1820 }
1821 
1828 GRFConfig *LoadGRFPresetFromConfig(const char *config_name)
1829 {
1830  size_t len = strlen(config_name) + 8;
1831  char *section = (char*)alloca(len);
1832  seprintf(section, section + len - 1, "preset-%s", config_name);
1833 
1834  IniFile *ini = IniLoadConfig();
1835  GRFConfig *config = GRFLoadConfig(ini, section, false);
1836  delete ini;
1837 
1838  return config;
1839 }
1840 
1847 void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
1848 {
1849  size_t len = strlen(config_name) + 8;
1850  char *section = (char*)alloca(len);
1851  seprintf(section, section + len - 1, "preset-%s", config_name);
1852 
1853  IniFile *ini = IniLoadConfig();
1854  GRFSaveConfig(ini, section, config);
1855  ini->SaveToDisk(_config_file);
1856  delete ini;
1857 }
1858 
1863 void DeleteGRFPresetFromConfig(const char *config_name)
1864 {
1865  size_t len = strlen(config_name) + 8;
1866  char *section = (char*)alloca(len);
1867  seprintf(section, section + len - 1, "preset-%s", config_name);
1868 
1869  IniFile *ini = IniLoadConfig();
1870  ini->RemoveGroup(section);
1871  ini->SaveToDisk(_config_file);
1872  delete ini;
1873 }
1874 
1875 const SettingDesc *GetSettingDescription(uint index)
1876 {
1877  if (index >= lengthof(_settings)) return nullptr;
1878  return &_settings[index];
1879 }
1880 
1892 CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1893 {
1894  const SettingDesc *sd = GetSettingDescription(p1);
1895 
1896  if (sd == nullptr) return CMD_ERROR;
1898 
1899  if (!sd->IsEditable(true)) return CMD_ERROR;
1900 
1901  if (flags & DC_EXEC) {
1902  void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
1903 
1904  int32 oldval = (int32)ReadValue(var, sd->save.conv);
1905  int32 newval = (int32)p2;
1906 
1907  Write_ValidateSetting(var, sd, newval);
1908  newval = (int32)ReadValue(var, sd->save.conv);
1909 
1910  if (oldval == newval) return CommandCost();
1911 
1912  if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
1913  WriteValue(var, sd->save.conv, (int64)oldval);
1914  return CommandCost();
1915  }
1916 
1917  if (sd->desc.flags & SGF_NO_NETWORK) {
1919  GamelogSetting(sd->desc.name, oldval, newval);
1921  }
1922 
1924 
1925  if (_save_config) SaveToConfig();
1926  }
1927 
1928  return CommandCost();
1929 }
1930 
1941 CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1942 {
1943  if (p1 >= lengthof(_company_settings)) return CMD_ERROR;
1944  const SettingDesc *sd = &_company_settings[p1];
1945 
1946  if (flags & DC_EXEC) {
1948 
1949  int32 oldval = (int32)ReadValue(var, sd->save.conv);
1950  int32 newval = (int32)p2;
1951 
1952  Write_ValidateSetting(var, sd, newval);
1953  newval = (int32)ReadValue(var, sd->save.conv);
1954 
1955  if (oldval == newval) return CommandCost();
1956 
1957  if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
1958  WriteValue(var, sd->save.conv, (int64)oldval);
1959  return CommandCost();
1960  }
1961 
1963  }
1964 
1965  return CommandCost();
1966 }
1967 
1975 bool SetSettingValue(uint index, int32 value, bool force_newgame)
1976 {
1977  const SettingDesc *sd = &_settings[index];
1978  /* If an item is company-based, we do not send it over the network
1979  * (if any) to change. Also *hack*hack* we update the _newgame version
1980  * of settings because changing a company-based setting in a game also
1981  * changes its defaults. At least that is the convention we have chosen */
1982  if (sd->save.conv & SLF_NO_NETWORK_SYNC) {
1983  void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
1984  Write_ValidateSetting(var, sd, value);
1985 
1986  if (_game_mode != GM_MENU) {
1987  void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
1988  Write_ValidateSetting(var2, sd, value);
1989  }
1990  if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
1991 
1993 
1994  if (_save_config) SaveToConfig();
1995  return true;
1996  }
1997 
1998  if (force_newgame) {
1999  void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
2000  Write_ValidateSetting(var2, sd, value);
2001 
2002  if (_save_config) SaveToConfig();
2003  return true;
2004  }
2005 
2006  /* send non-company-based settings over the network */
2007  if (!_networking || (_networking && _network_server)) {
2008  return DoCommandP(0, index, value, CMD_CHANGE_SETTING);
2009  }
2010  return false;
2011 }
2012 
2019 void SetCompanySetting(uint index, int32 value)
2020 {
2021  const SettingDesc *sd = &_company_settings[index];
2022  if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
2023  DoCommandP(0, index, value, CMD_CHANGE_COMPANY_SETTING);
2024  } else {
2025  void *var = GetVariableAddress(&_settings_client.company, &sd->save);
2026  Write_ValidateSetting(var, sd, value);
2027  if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
2028  }
2029 }
2030 
2035 {
2036  Company *c = Company::Get(cid);
2037  const SettingDesc *sd;
2038  for (sd = _company_settings; sd->save.cmd != SL_END; sd++) {
2039  void *var = GetVariableAddress(&c->settings, &sd->save);
2040  Write_ValidateSetting(var, sd, (int32)(size_t)sd->desc.def);
2041  }
2042 }
2043 
2048 {
2049  const SettingDesc *sd;
2050  uint i = 0;
2051  for (sd = _company_settings; sd->save.cmd != SL_END; sd++, i++) {
2052  const void *old_var = GetVariableAddress(&Company::Get(_current_company)->settings, &sd->save);
2053  const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
2054  uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
2055  uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
2056  if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, nullptr, nullptr, _local_company);
2057  }
2058 }
2059 
2065 uint GetCompanySettingIndex(const char *name)
2066 {
2067  uint i;
2068  const SettingDesc *sd = GetSettingFromName(name, &i);
2069  (void)sd; // Unused without asserts
2070  assert(sd != nullptr && (sd->desc.flags & SGF_PER_COMPANY) != 0);
2071  return i;
2072 }
2073 
2081 bool SetSettingValue(uint index, const char *value, bool force_newgame)
2082 {
2083  const SettingDesc *sd = &_settings[index];
2084  assert(sd->save.conv & SLF_NO_NETWORK_SYNC);
2085 
2086  if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
2087  char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
2088  free(*var);
2089  *var = strcmp(value, "(null)") == 0 ? nullptr : stredup(value);
2090  } else {
2091  char *var = (char*)GetVariableAddress(nullptr, &sd->save);
2092  strecpy(var, value, &var[sd->save.length - 1]);
2093  }
2094  if (sd->desc.proc != nullptr) sd->desc.proc(0);
2095 
2096  if (_save_config) SaveToConfig();
2097  return true;
2098 }
2099 
2107 const SettingDesc *GetSettingFromName(const char *name, uint *i)
2108 {
2109  const SettingDesc *sd;
2110 
2111  /* First check all full names */
2112  for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2113  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2114  if (strcmp(sd->desc.name, name) == 0) return sd;
2115  }
2116 
2117  /* Then check the shortcut variant of the name. */
2118  for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2119  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2120  const char *short_name = strchr(sd->desc.name, '.');
2121  if (short_name != nullptr) {
2122  short_name++;
2123  if (strcmp(short_name, name) == 0) return sd;
2124  }
2125  }
2126 
2127  if (strncmp(name, "company.", 8) == 0) name += 8;
2128  /* And finally the company-based settings */
2129  for (*i = 0, sd = _company_settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2130  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2131  if (strcmp(sd->desc.name, name) == 0) return sd;
2132  }
2133 
2134  return nullptr;
2135 }
2136 
2137 /* Those 2 functions need to be here, else we have to make some stuff non-static
2138  * and besides, it is also better to keep stuff like this at the same place */
2139 void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
2140 {
2141  uint index;
2142  const SettingDesc *sd = GetSettingFromName(name, &index);
2143 
2144  if (sd == nullptr) {
2145  IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
2146  return;
2147  }
2148 
2149  bool success;
2150  if (sd->desc.cmd == SDT_STRING) {
2151  success = SetSettingValue(index, value, force_newgame);
2152  } else {
2153  uint32 val;
2154  extern bool GetArgumentInteger(uint32 *value, const char *arg);
2155  success = GetArgumentInteger(&val, value);
2156  if (!success) {
2157  IConsolePrintF(CC_ERROR, "'%s' is not an integer.", value);
2158  return;
2159  }
2160 
2161  success = SetSettingValue(index, val, force_newgame);
2162  }
2163 
2164  if (!success) {
2165  if (_network_server) {
2166  IConsoleError("This command/variable is not available during network games.");
2167  } else {
2168  IConsoleError("This command/variable is only available to a network server.");
2169  }
2170  }
2171 }
2172 
2173 void IConsoleSetSetting(const char *name, int value)
2174 {
2175  uint index;
2176  const SettingDesc *sd = GetSettingFromName(name, &index);
2177  (void)sd; // Unused without asserts
2178  assert(sd != nullptr);
2179  SetSettingValue(index, value);
2180 }
2181 
2187 void IConsoleGetSetting(const char *name, bool force_newgame)
2188 {
2189  char value[20];
2190  uint index;
2191  const SettingDesc *sd = GetSettingFromName(name, &index);
2192  const void *ptr;
2193 
2194  if (sd == nullptr) {
2195  IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
2196  return;
2197  }
2198 
2199  ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
2200 
2201  if (sd->desc.cmd == SDT_STRING) {
2202  IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
2203  } else {
2204  if (sd->desc.cmd == SDT_BOOLX) {
2205  seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off");
2206  } else {
2207  seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
2208  }
2209 
2210  IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)",
2211  name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max);
2212  }
2213 }
2214 
2220 void IConsoleListSettings(const char *prefilter)
2221 {
2222  IConsolePrintF(CC_WARNING, "All settings with their current value:");
2223 
2224  for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
2225  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2226  if (prefilter != nullptr && strstr(sd->desc.name, prefilter) == nullptr) continue;
2227  char value[80];
2228  const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
2229 
2230  if (sd->desc.cmd == SDT_BOOLX) {
2231  seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off");
2232  } else if (sd->desc.cmd == SDT_STRING) {
2233  seprintf(value, lastof(value), "%s", (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
2234  } else {
2235  seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
2236  }
2237  IConsolePrintF(CC_DEFAULT, "%s = %s", sd->desc.name, value);
2238  }
2239 
2240  IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
2241 }
2242 
2249 static void LoadSettings(const SettingDesc *osd, void *object)
2250 {
2251  for (; osd->save.cmd != SL_END; osd++) {
2252  const SaveLoad *sld = &osd->save;
2253  void *ptr = GetVariableAddress(object, sld);
2254 
2255  if (!SlObjectMember(ptr, sld)) continue;
2256  if (IsNumericType(sld->conv)) Write_ValidateSetting(ptr, osd, ReadValue(ptr, sld->conv));
2257  }
2258 }
2259 
2266 static void SaveSettings(const SettingDesc *sd, void *object)
2267 {
2268  /* We need to write the CH_RIFF header, but unfortunately can't call
2269  * SlCalcLength() because we have a different format. So do this manually */
2270  const SettingDesc *i;
2271  size_t length = 0;
2272  for (i = sd; i->save.cmd != SL_END; i++) {
2273  length += SlCalcObjMemberLength(object, &i->save);
2274  }
2275  SlSetLength(length);
2276 
2277  for (i = sd; i->save.cmd != SL_END; i++) {
2278  void *ptr = GetVariableAddress(object, &i->save);
2279  SlObjectMember(ptr, &i->save);
2280  }
2281 }
2282 
2283 static void Load_OPTS()
2284 {
2285  /* Copy over default setting since some might not get loaded in
2286  * a networking environment. This ensures for example that the local
2287  * autosave-frequency stays when joining a network-server */
2289  LoadSettings(_gameopt_settings, &_settings_game);
2290  HandleOldDiffCustom(true);
2291 }
2292 
2293 static void Load_PATS()
2294 {
2295  /* Copy over default setting since some might not get loaded in
2296  * a networking environment. This ensures for example that the local
2297  * currency setting stays when joining a network-server */
2298  LoadSettings(_settings, &_settings_game);
2299 }
2300 
2301 static void Check_PATS()
2302 {
2303  LoadSettings(_settings, &_load_check_data.settings);
2304 }
2305 
2306 static void Save_PATS()
2307 {
2308  SaveSettings(_settings, &_settings_game);
2309 }
2310 
2311 extern const ChunkHandler _setting_chunk_handlers[] = {
2312  { 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_RIFF},
2313  { 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF | CH_LAST},
2314 };
2315 
2316 static bool IsSignedVarMemType(VarType vt)
2317 {
2318  switch (GetVarMemType(vt)) {
2319  case SLE_VAR_I8:
2320  case SLE_VAR_I16:
2321  case SLE_VAR_I32:
2322  case SLE_VAR_I64:
2323  return true;
2324  }
2325  return false;
2326 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
ScriptConfig::StringToSettings
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
Definition: script_config.cpp:179
game.hpp
IniLoadFile::RemoveGroup
void RemoveGroup(const char *name)
Remove the group with the given name.
Definition: ini_load.cpp:162
LoadStringWidthTable
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Definition: gfx.cpp:1276
ShowFirstError
void ShowFirstError()
Show the first error of the queue.
Definition: error_gui.cpp:337
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition: window_type.h:137
NetworkSettings::rcon_password
char rcon_password[NETWORK_PASSWORD_LENGTH]
password for rconsole (server side)
Definition: settings_type.h:267
ErrorList
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
Definition: error_gui.cpp:168
SaveLoad::version_to
SaveLoadVersion version_to
save/load the variable until this savegame version
Definition: saveload.h:522
BuildOwnerLegend
void BuildOwnerLegend()
Completes the array for the owned property legend.
Definition: smallmap_gui.cpp:325
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3321
sound_func.h
factory.hpp
SDT_STRING
@ SDT_STRING
string with a pre-allocated buffer
Definition: settings_internal.h:29
ClientSettings
All settings that are only important for the local client.
Definition: settings_type.h:580
AIConfig
Definition: ai_config.hpp:16
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:524
ReInitAllWindows
void ReInitAllWindows()
Re-initialize all windows.
Definition: window.cpp:3456
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition: window_type.h:66
ScriptConfig::SettingsToString
void SettingsToString(char *string, const char *last) const
Convert the custom settings to a string that can be stored in the config file or savegames.
Definition: script_config.cpp:205
SLF_NOT_IN_SAVE
@ SLF_NOT_IN_SAVE
do not save with savegame, basically client-based
Definition: saveload.h:487
GetServiceIntervalClamped
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
Definition: order_cmd.cpp:1918
SLE_VAR_STR
@ SLE_VAR_STR
string pointer
Definition: saveload.h:449
train.h
command_func.h
FindGRFConfig
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
Definition: newgrf_config.cpp:738
InvalidateCompanyWindow
static bool InvalidateCompanyWindow(int32 p1)
Invalidate the company details window after the shares setting changed.
Definition: settings.cpp:1198
ErrorMessageData::SetDParamStr
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition: error_gui.cpp:161
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
PositionMainToolbar
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition: window.cpp:3507
IniItem::next
IniItem * next
The next item in this group.
Definition: ini_type.h:26
_list_group_names
static const char *const _list_group_names[]
Groups in openttd.cfg that are actually lists.
Definition: settings.cpp:97
smallmap_gui.h
TrainSlopeSteepnessChanged
static bool TrainSlopeSteepnessChanged(int32 p1)
This function updates the train acceleration cache after a steepness change.
Definition: settings.cpp:1048
SaveSettings
static void SaveSettings(const SettingDesc *sd, void *object)
Save and load handler for settings.
Definition: settings.cpp:2266
ValidateSettings
static void ValidateSettings()
Checks if any settings are set to incorrect values, and sets them to correct values in that case.
Definition: settings.cpp:1205
SetDefaultCompanySettings
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Definition: settings.cpp:2034
SetTileType
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition: genworld.h:48
WC_COMPANY_COLOUR
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
Definition: window_type.h:223
WC_FOUND_TOWN
@ WC_FOUND_TOWN
Found a town; Window numbers:
Definition: window_type.h:422
SGF_PER_COMPANY
@ SGF_PER_COMPANY
this setting can be different for each company (saved in company struct)
Definition: settings_internal.h:48
currency.h
elrail_func.h
TF_FORBIDDEN
@ TF_FORBIDDEN
Forbidden.
Definition: town_type.h:94
GRFConfig::num_params
uint8 num_params
Number of used parameters.
Definition: newgrf_config.h:171
ST_GAME
@ ST_GAME
Game setting.
Definition: settings_internal.h:81
_network_server
bool _network_server
network-server is active
Definition: network.cpp:53
IniItem
A single "line" in an ini file.
Definition: ini_type.h:25
WC_ENGINE_PREVIEW
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
Definition: window_type.h:583
SettingDesc::save
SaveLoad save
Internal structure (going to savegame, parts to config)
Definition: settings_internal.h:112
SettingDesc::GetType
SettingType GetType() const
Return the type of the setting.
Definition: settings.cpp:837
WC_INDUSTRY_VIEW
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Definition: window_type.h:356
SaveToConfig
void SaveToConfig()
Save the values to the configuration file.
Definition: settings.cpp:1785
StringToVal
static const void * StringToVal(const SettingDescBase *desc, const char *orig_str)
Convert a string representation (external) of a setting to the internal rep.
Definition: settings.cpp:359
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:38
_old_vds
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition: settings.cpp:82
SettingDesc::IsEditable
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition: settings.cpp:821
RedrawSmallmap
static bool RedrawSmallmap(int32 p1)
Redraw the smallmap after a colour scheme change.
Definition: settings.cpp:880
IniGroup
A group within an ini file.
Definition: ini_type.h:38
SDT_BOOLX
@ SDT_BOOLX
a boolean number
Definition: settings_internal.h:25
ST_CLIENT
@ ST_CLIENT
Client setting.
Definition: settings_internal.h:83
LG_ORIGINAL
@ LG_ORIGINAL
The original landscape generator.
Definition: genworld.h:20
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:122
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:563
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
ship.h
SLE_VAR_STRBQ
@ SLE_VAR_STRBQ
string enclosed in quotes (with pre-allocated buffer)
Definition: saveload.h:448
void_map.h
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:558
SGF_NEWGAME_ONLY
@ SGF_NEWGAME_ONLY
this setting cannot be changed in a game
Definition: settings_internal.h:46
SLE_VAR_NULL
@ SLE_VAR_NULL
useful to write zeros in savegame.
Definition: saveload.h:446
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:411
NetworkUpdateClientName
void NetworkUpdateClientName()
Send the server our name.
Definition: network_client.cpp:1257
WC_BUILD_INDUSTRY
@ WC_BUILD_INDUSTRY
Build industry; Window numbers:
Definition: window_type.h:428
ST_COMPANY
@ ST_COMPANY
Company setting.
Definition: settings_internal.h:82
GCS_NOT_FOUND
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
Definition: newgrf_config.h:37
base_media_base.h
SaveLoad::length
uint16 length
(conditional) length of the variable (eg. arrays) (max array size is 65536 elements)
Definition: saveload.h:520
GRFConfig::ident
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Definition: newgrf_config.h:157
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
_network_bind_list
StringList _network_bind_list
The addresses to bind on.
Definition: network.cpp:62
GRFConfig::status
GRFStatus status
NOSAVE: GRFStatus, enum.
Definition: newgrf_config.h:168
WC_VEHICLE_TIMETABLE
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:217
DeleteWindowByClass
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1178
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
SettingDescBase::many
const char * many
ONE/MANY_OF_MANY: string of possible values for this type.
Definition: settings_internal.h:100
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition: window_type.h:362
WC_BUILD_STATION
@ WC_BUILD_STATION
Build station; Window numbers:
Definition: window_type.h:390
settings_internal.h
SDT_NUMX
@ SDT_NUMX
any number-type
Definition: settings_internal.h:24
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:380
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
SaveLoad::conv
VarType conv
type of the variable to be saved, int
Definition: saveload.h:519
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:59
VehicleDefaultSettings::servint_ships
uint16 servint_ships
service interval for ships
Definition: settings_type.h:549
SLF_NO_NETWORK_SYNC
@ SLF_NO_NETWORK_SYNC
do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
Definition: saveload.h:489
gamelog.h
fios.h
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:348
IniSaveWindowSettings
void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
Save a WindowDesc to config.
Definition: settings.cpp:811
SLF_HEX
@ SLF_HEX
print numbers as hex in the config file (only useful for unsigned)
Definition: saveload.h:492
GRFIdentifier::md5sum
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Definition: newgrf_config.h:85
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:346
genworld.h
SlSetLength
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
Definition: saveload.cpp:676
CC_DEFAULT
static const TextColour CC_DEFAULT
Default colour of the console.
Definition: console_type.h:23
SettingDescBase::min
int32 min
minimum values
Definition: settings_internal.h:97
SettingDescBase::startup
bool startup
setting has to be loaded directly at startup?
Definition: settings_internal.h:107
GRFIdentifier::grfid
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:84
IniGroup::Clear
void Clear()
Clear all items in the group.
Definition: ini_load.cpp:110
SDT_STDSTRING
@ SDT_STDSTRING
std::string
Definition: settings_internal.h:30
textbuf_gui.h
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
Write_ValidateSetting
static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
Set the value of a setting and if needed clamp the value to the preset minimum and maximum.
Definition: settings.cpp:435
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:372
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:564
GCF_INVALID
@ GCF_INVALID
GRF is unusable with this version of OpenTTD.
Definition: newgrf_config.h:30
ai.hpp
screenshot.h
UpdateCursorSize
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1666
GetGameSettings
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition: settings_type.h:605
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
GRFBuildParamList
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
Definition: newgrf_config.cpp:824
LoadSettings
static void LoadSettings(const SettingDesc *osd, void *object)
Save and load handler for settings.
Definition: settings.cpp:2249
SLE_VAR_STRB
@ SLE_VAR_STRB
string (with pre-allocated buffer)
Definition: saveload.h:447
IsNumericType
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
Definition: saveload.h:878
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
SettingType
SettingType
Type of settings for filtering.
Definition: settings_internal.h:80
PositionStatusbar
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Definition: window.cpp:3518
RoadVehiclesAreBuilt
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
Definition: road_cmd.cpp:183
SettingDescBase::cmd
SettingDescType cmd
various flags for the variable
Definition: settings_internal.h:95
DecodeHexText
static bool DecodeHexText(const char *pos, uint8 *dest, size_t dest_size)
Parse a sequence of characters (supposedly hex digits) into a sequence of bytes.
Definition: settings.cpp:1525
UpdateAllTownVirtCoords
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
Definition: town_cmd.cpp:413
GetGRFPresetList
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
Definition: settings.cpp:1808
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3529
EconomySettings::station_noise_level
bool station_noise_level
build new airports when the town noise level is still within accepted limits
Definition: settings_type.h:507
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
NetworkSettings::server_password
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
Definition: settings_type.h:266
CommandCost
Common return value for all commands.
Definition: command_type.h:23
SettingDescBase
Properties of config file settings.
Definition: settings_internal.h:92
InvalidateCompanyInfrastructureWindow
static bool InvalidateCompanyInfrastructureWindow(int32 p1)
Invalidate the company infrastructure details window after a infrastructure maintenance setting chang...
Definition: settings.cpp:1187
IniSaveSettingList
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
Saves all items from a list into the 'grpname' section The list parameter can be a nullptr pointer,...
Definition: settings.cpp:782
MakeIntList
static void MakeIntList(char *buf, const char *last, const void *array, int nelems, VarType type)
Convert an integer-array (intlist) to a string representation.
Definition: settings.cpp:265
settings_func.h
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
GCF_UNSAFE
@ GCF_UNSAFE
GRF file is unsafe for static usage.
Definition: newgrf_config.h:24
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:152
ParseIntList
static int ParseIntList(const char *p, T *items, int maxitems)
Parse an integerlist string and set each found value.
Definition: settings.cpp:174
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
WC_TOWN_AUTHORITY
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
Definition: window_type.h:187
SettingDescBase::max
uint32 max
maximum values
Definition: settings_internal.h:98
GfxClearSpriteCache
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Definition: spritecache.cpp:976
SGF_NETWORK_ONLY
@ SGF_NETWORK_ONLY
this setting only applies to network games
Definition: settings_internal.h:43
Station::RecomputeCatchmentForAll
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition: station.cpp:474
GCF_SYSTEM
@ GCF_SYSTEM
GRF file is an openttd-internal system grf.
Definition: newgrf_config.h:23
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
PrepareOldDiffCustom
static void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
Definition: settings.cpp:1416
IniItem::value
std::optional< std::string > value
The value of this item.
Definition: ini_type.h:28
GRFConfig::flags
uint8 flags
NOSAVE: GCF_Flags, bitset.
Definition: newgrf_config.h:167
SDT_MANYOFMANY
@ SDT_MANYOFMANY
bitmasked number where MULTIPLE bits may be set
Definition: settings_internal.h:27
GameConfig
Definition: game_config.hpp:15
ScriptConfig::GetName
const char * GetName() const
Get the name of the Script.
Definition: script_config.cpp:169
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:52
GetCompanySettingIndex
uint GetCompanySettingIndex(const char *name)
Get the index in the _company_settings array of a setting.
Definition: settings.cpp:2065
UpdateAirportsNoise
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
Definition: station_cmd.cpp:2216
IniFile::SaveToDisk
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
Definition: ini.cpp:46
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:45
IConsoleError
void IConsoleError(const char *string)
It is possible to print error information to the console.
Definition: console.cpp:168
MakeVoid
static void MakeVoid(TileIndex t)
Make a nice void tile ;)
Definition: void_map.h:19
SDT_ONEOFMANY
@ SDT_ONEOFMANY
bitmasked number where only ONE bit may be set
Definition: settings_internal.h:26
v_PositionStatusbar
static bool v_PositionStatusbar(int32 p1)
Reposition the statusbar as the setting changed.
Definition: settings.cpp:853
SaveLoad::cmd
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
Definition: saveload.h:518
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
GamelogStartAction
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
Definition: gamelog.cpp:69
GetArgumentInteger
bool GetArgumentInteger(uint32 *value, const char *arg)
Change a string into its number representation.
Definition: console.cpp:180
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition: window_type.h:193
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:573
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:58
SyncCompanySettings
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
Definition: settings.cpp:2047
SettingDescBase::def
const void * def
default value given when none is present
Definition: settings_internal.h:94
safeguards.h
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:328
music_driver.hpp
Train
'Train' is either a loco or a wagon.
Definition: train.h:85
HandleOldDiffCustom
static void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
Definition: settings.cpp:1427
SetCompanySetting
void SetCompanySetting(uint index, int32 value)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:2019
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
DifficultySettings::quantity_sea_lakes
byte quantity_sea_lakes
the amount of seas/lakes
Definition: settings_type.h:75
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:21
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:816
GameSettings
All settings together for the game.
Definition: settings_type.h:562
GetSettingFromName
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2107
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:52
InvalidateNewGRFChangeWindows
static bool InvalidateNewGRFChangeWindows(int32 p1)
Update any possible saveload window and delete any newgrf dialogue as its widget parts might change.
Definition: settings.cpp:1145
DeleteGRFPresetFromConfig
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
Definition: settings.cpp:1863
ErrorMessageData
The data of the error message.
Definition: error.h:29
VehicleDefaultSettings
Default settings for vehicles.
Definition: settings_type.h:544
EconomySettings::found_town
TownFounding found_town
town founding.
Definition: settings_type.h:506
error.h
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
ResetCurrencies
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
Definition: currency.cpp:157
SDT_INTLIST
@ SDT_INTLIST
list of integers separated by a comma ','
Definition: settings_internal.h:28
stdafx.h
LookupOneOfMany
static size_t LookupOneOfMany(const char *many, const char *one, size_t onelen=0)
Find the index value of a ONEofMANY type in a string separated by |.
Definition: settings.cpp:112
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
BSWAP32
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:380
NEWGRF_DIR
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
Definition: fileio_type.h:117
RedrawTownAuthority
static bool RedrawTownAuthority(int32 p1)
Update the town authority window after a town authority setting change.
Definition: settings.cpp:1176
SetTileHeight
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
Definition: tile_map.h:57
MakeOneOfMany
static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
Convert a ONEofMANY structure to a string representation.
Definition: settings.cpp:298
_grfconfig_static
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
Definition: newgrf_config.cpp:173
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
GamelogSetting
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
Definition: gamelog.cpp:486
GamelogStopAction
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:78
SlIsObjectCurrentlyValid
static bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version.
Definition: saveload.h:843
LoadGRFPresetFromConfig
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
Definition: settings.cpp:1828
pathfinder_type.h
SettingDescBase::flags
SettingGuiFlag flags
handles how a setting would show up in the GUI (text/currency, etc.)
Definition: settings_internal.h:96
WriteValue
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
Definition: saveload.cpp:773
sound_driver.hpp
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:118
LookupManyOfMany
static size_t LookupManyOfMany(const char *many, const char *str)
Find the set-integer value MANYofMANY type in a string.
Definition: settings.cpp:141
rail_gui.h
Ship
All ships have this type.
Definition: ship.h:26
SGF_MULTISTRING
@ SGF_MULTISTRING
the value represents a limited number of string-options (internally integer)
Definition: settings_internal.h:42
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
CheckRoadSide
static bool CheckRoadSide(int p1)
Check whether the road side may be changed.
Definition: settings.cpp:1243
SGF_0ISDISABLED
@ SGF_0ISDISABLED
a value of zero means the feature is disabled
Definition: settings_internal.h:40
rev.h
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition: window_type.h:235
station_base.h
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
strings_func.h
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
IConsoleListSettings
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
Definition: settings.cpp:2220
ConvertLandscape
static size_t ConvertLandscape(const char *value)
Conversion callback for _gameopt_settings_game.landscape It converts (or try) between old values and ...
Definition: settings.cpp:1256
FioCheckFileExists
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
Definition: fileio.cpp:266
IniGroup::name
std::string name
name of group
Definition: ini_type.h:43
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:88
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
NetworkServerSendConfigUpdate
void NetworkServerSendConfigUpdate()
Send Config Update.
Definition: network_server.cpp:2032
VehicleDefaultSettings::servint_trains
uint16 servint_trains
service interval for trains
Definition: settings_type.h:546
SGF_NO_NETWORK
@ SGF_NO_NETWORK
this setting does not apply to network games; it may not be changed during the game
Definition: settings_internal.h:45
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition: window_type.h:376
SettingDesc
Definition: settings_internal.h:110
GLAT_SETTING
@ GLAT_SETTING
Setting changed.
Definition: gamelog.h:21
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:467
NetworkSendCommand
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
Prepare a DoCommand to be send over the network.
Definition: network_command.cpp:136
GameCreationSettings::land_generator
byte land_generator
the landscape generator
Definition: settings_type.h:297
video_driver.hpp
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:125
GetVarMemType
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
Definition: saveload.h:857
MakeManyOfMany
static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
Convert a MANYofMANY structure to a string representation.
Definition: settings.cpp:326
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition: company_cmd.cpp:1153
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3339
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:177
GameConfig::GetConfig
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: game_config.cpp:18
WC_AI_SETTINGS
@ WC_AI_SETTINGS
AI settings; Window numbers:
Definition: window_type.h:168
ScheduleErrorMessage
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
Definition: error_gui.cpp:447
SaveVersionInConfig
static void SaveVersionInConfig(IniFile *ini)
Save the version of OpenTTD to the ini file.
Definition: settings.cpp:1688
DecodeHexNibble
static int DecodeHexNibble(char c)
Convert a character to a hex nibble value, or -1 otherwise.
Definition: settings.cpp:1509
ScriptConfig::SSS_FORCE_NEWGAME
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
Definition: script_config.hpp:104
WC_COMPANY_INFRASTRUCTURE
@ WC_COMPANY_INFRASTRUCTURE
Company infrastructure overview; Window numbers:
Definition: window_type.h:570
VehicleDefaultSettings::servint_aircraft
uint16 servint_aircraft
service interval for aircraft
Definition: settings_type.h:548
FGCM_NEWEST_VALID
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GCF_INVALID set.
Definition: newgrf_config.h:196
ChangeDynamicEngines
static bool ChangeDynamicEngines(int32 p1)
Changing the setting "allow multiple NewGRF sets" is not allowed if there are vehicles.
Definition: settings.cpp:1325
SLF_NOT_IN_CONFIG
@ SLF_NOT_IN_CONFIG
do not save to config file
Definition: saveload.h:488
RoadVehSlopeSteepnessChanged
static bool RoadVehSlopeSteepnessChanged(int32 p1)
This function updates the road vehicle acceleration cache after a steepness change.
Definition: settings.cpp:1085
SettingDesc::desc
SettingDescBase desc
Settings structure (going to configuration file)
Definition: settings_internal.h:111
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:460
SaveLoad::version_from
SaveLoadVersion version_from
save/load the variable starting from this savegame version
Definition: saveload.h:521
IniItem::SetValue
void SetValue(const char *value)
Replace the current value with another value.
Definition: ini_load.cpp:41
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:52
company_func.h
CC_ERROR
static const TextColour CC_ERROR
Colour for error lines.
Definition: console_type.h:24
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
SLE_VAR_STRQ
@ SLE_VAR_STRQ
string pointer enclosed in quotes
Definition: saveload.h:450
SpecializedVehicle< Train, Type >::Iterate
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1231
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
CmdChangeCompanySetting
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change one of the per-company settings.
Definition: settings.cpp:1941
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
IConsoleGetSetting
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
Definition: settings.cpp:2187
network.h
VehicleDefaultSettings::servint_ispercent
bool servint_ispercent
service intervals are in percents
Definition: settings_type.h:545
window_func.h
IniItem::name
std::string name
The name of this item.
Definition: ini_type.h:27
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:369
_network_ban_list
StringList _network_ban_list
The banned clients.
Definition: network.cpp:64
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1597
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:582
v_PositionMainToolbar
static bool v_PositionMainToolbar(int32 p1)
Reposition the main toolbar as the setting changed.
Definition: settings.cpp:846
CMD_CHANGE_SETTING
@ CMD_CHANGE_SETTING
change a setting
Definition: command_type.h:309
IniGroup::item
IniItem * item
the first item in the group
Definition: ini_type.h:41
CmdChangeSetting
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Network-safe changing of settings (server-only).
Definition: settings.cpp:1892
VehicleDefaultSettings::servint_roadveh
uint16 servint_roadveh
service interval for road vehicles
Definition: settings_type.h:547
SettingDescBase::name
const char * name
name of the setting. Used in configuration file and for console
Definition: settings_internal.h:93
SettingDescBase::proc
OnChange * proc
callback procedure for when the value is changed
Definition: settings_internal.h:104
fontcache.h
ScriptConfig::Change
void Change(const char *name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
Definition: script_config.cpp:19
WC_TOWN_VIEW
@ WC_TOWN_VIEW
Town view; Window numbers:
Definition: window_type.h:326
ReadValue
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:749
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition: settings_type.h:583
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3540
IniLoadSettingList
static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
Loads all items from a 'grpname' section into a list The list parameter can be a nullptr pointer,...
Definition: settings.cpp:760
CCF_TRACK
@ CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:48
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:572
WC_BUILD_SIGNAL
@ WC_BUILD_SIGNAL
Build signal toolbar; Window numbers:
Definition: window_type.h:91
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:478
SetSettingValue
bool SetSettingValue(uint index, int32 value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:1975
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
SettingDescBase::proc_cnvt
OnConvert * proc_cnvt
callback procedure when loading value mechanism fails
Definition: settings_internal.h:105
FGCM_EXACT
@ FGCM_EXACT
Only find Grfs matching md5sum.
Definition: newgrf_config.h:193
IniGroup::GetItem
IniItem * GetItem(const std::string &name, bool create)
Get the item with the given name, and if it doesn't exist and create is true it creates a new item.
Definition: ini_load.cpp:95
IniSaveSettings
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool)
Save the values of settings to the inifile.
Definition: settings.cpp:617
_network_host_list
StringList _network_host_list
The servers we know.
Definition: network.cpp:63
GRFConfig::filename
char * filename
Filename - either with or without full path.
Definition: newgrf_config.h:159
VIWD_MODIFY_ORDERS
@ VIWD_MODIFY_ORDERS
Other order modifications.
Definition: vehicle_gui.h:33
console_func.h
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
_config_file
std::string _config_file
Configuration file of OpenTTD.
Definition: settings.cpp:83
WC_ERRMSG
@ WC_ERRMSG
Error message; Window numbers:
Definition: window_type.h:103
CC_WARNING
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition: genworld.h:47
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:456
SLV_4
@ SLV_4
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
Definition: saveload.h:37
SaveLoad
SaveLoad type struct.
Definition: saveload.h:517
IniLoadFile::LoadFromDisk
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
Definition: ini_load.cpp:195
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:110
game_config.hpp
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3248
IniLoadSettings
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool only_startup)
Load values from a group of an IniFile structure into the internal representation.
Definition: settings.cpp:506
SGF_SCENEDIT_TOO
@ SGF_SCENEDIT_TOO
this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set)
Definition: settings_internal.h:47
FillGRFDetails
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
Definition: newgrf_config.cpp:370
ini_type.h
GetVariableAddress
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Definition: saveload.h:888
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:385
_settings_error_list
static ErrorList _settings_error_list
Errors while loading minimal settings.
Definition: settings.cpp:86
LoadFromConfig
void LoadFromConfig(bool startup)
Load the values from the configuration files.
Definition: settings.cpp:1755
Company::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:122
CMD_CHANGE_COMPANY_SETTING
@ CMD_CHANGE_COMPANY_SETTING
change a company setting
Definition: command_type.h:310
SaveGRFPresetToConfig
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
Definition: settings.cpp:1847
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition: window_type.h:97
network_func.h
ScriptConfig::HasScript
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
Definition: script_config.cpp:159
IConsolePrintF
void CDECL IConsolePrintF(TextColour colour_code, const char *format,...)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console.cpp:125
LoadIntList
static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
Load parsed string-values into an integer-array (intlist)
Definition: settings.cpp:220
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:81
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
GCF_STATIC
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:25
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:581
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:25
SGF_SCENEDIT_ONLY
@ SGF_SCENEDIT_ONLY
this setting can only be changed in the scenario editor
Definition: settings_internal.h:49
GRFConfig::param
uint32 param[0x80]
GRF parameters.
Definition: newgrf_config.h:170
RoadVehAccelerationModelChanged
static bool RoadVehAccelerationModelChanged(int32 p1)
This function updates realistic acceleration caches when the setting "Road vehicle acceleration model...
Definition: settings.cpp:1062
_grfconfig_newgame
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
Definition: newgrf_config.cpp:172
GRFLoadConfig
static GRFConfig * GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
Load a GRF configuration.
Definition: settings.cpp:1544
BuildLandLegend
void BuildLandLegend()
(Re)build the colour tables for the legends.
Definition: smallmap_gui.cpp:274
ai_config.hpp
news_func.h
IniLoadFile::GetGroup
IniGroup * GetGroup(const std::string &name, bool create_new=true)
Get the group with the given name.
Definition: ini_load.cpp:143
roadveh.h
IniGroup::next
IniGroup * next
the next group within this file
Definition: ini_type.h:39
IniLoadWindowSettings
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
Load a WindowDesc from config.
Definition: settings.cpp:800