OpenTTD Source  1.11.0-beta1
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)
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)
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);
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 
505 static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
506 {
507  IniGroup *group;
508  IniGroup *group_def = ini->GetGroup(grpname);
509 
510  for (; sd->save.cmd != SL_END; sd++) {
511  const SettingDescBase *sdb = &sd->desc;
512  const SaveLoad *sld = &sd->save;
513 
514  if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
515 
516  /* For settings.xx.yy load the settings from [xx] yy = ? */
517  std::string s{ sdb->name };
518  auto sc = s.find('.');
519  if (sc != std::string::npos) {
520  group = ini->GetGroup(s.substr(0, sc));
521  s = s.substr(sc + 1);
522  } else {
523  group = group_def;
524  }
525 
526  IniItem *item = group->GetItem(s, false);
527  if (item == nullptr && group != group_def) {
528  /* For settings.xx.yy load the settings from [settings] yy = ? in case the previous
529  * did not exist (e.g. loading old config files with a [settings] section */
530  item = group_def->GetItem(s, false);
531  }
532  if (item == nullptr) {
533  /* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
534  * did not exist (e.g. loading old config files with a [yapf] section */
535  sc = s.find('.');
536  if (sc != std::string::npos) item = ini->GetGroup(s.substr(0, sc))->GetItem(s.substr(sc + 1), false);
537  }
538 
539  const void *p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value.has_value() ? item->value->c_str() : nullptr);
540  void *ptr = GetVariableAddress(object, sld);
541 
542  switch (sdb->cmd) {
543  case SDT_BOOLX: // All four are various types of (integer) numbers
544  case SDT_NUMX:
545  case SDT_ONEOFMANY:
546  case SDT_MANYOFMANY:
547  Write_ValidateSetting(ptr, sd, (int32)(size_t)p);
548  break;
549 
550  case SDT_STRING:
551  switch (GetVarMemType(sld->conv)) {
552  case SLE_VAR_STRB:
553  case SLE_VAR_STRBQ:
554  if (p != nullptr) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1);
555  break;
556 
557  case SLE_VAR_STR:
558  case SLE_VAR_STRQ:
559  free(*(char**)ptr);
560  *(char**)ptr = p == nullptr ? nullptr : stredup((const char*)p);
561  break;
562 
563  case SLE_VAR_CHAR: if (p != nullptr) *(char *)ptr = *(const char *)p; break;
564 
565  default: NOT_REACHED();
566  }
567  break;
568 
569  case SDT_STDSTRING:
570  switch (GetVarMemType(sld->conv)) {
571  case SLE_VAR_STR:
572  case SLE_VAR_STRQ:
573  if (p != nullptr) {
574  reinterpret_cast<std::string *>(ptr)->assign((const char *)p);
575  } else {
576  reinterpret_cast<std::string *>(ptr)->clear();
577  }
578  break;
579 
580  default: NOT_REACHED();
581  }
582 
583  break;
584 
585  case SDT_INTLIST: {
586  if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
587  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
588  msg.SetDParamStr(0, sdb->name);
589  _settings_error_list.push_back(msg);
590 
591  /* Use default */
592  LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
593  } else if (sd->desc.proc_cnvt != nullptr) {
594  sd->desc.proc_cnvt((const char*)p);
595  }
596  break;
597  }
598  default: NOT_REACHED();
599  }
600  }
601 }
602 
615 static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
616 {
617  IniGroup *group_def = nullptr, *group;
618  IniItem *item;
619  char buf[512];
620  void *ptr;
621 
622  for (; sd->save.cmd != SL_END; sd++) {
623  const SettingDescBase *sdb = &sd->desc;
624  const SaveLoad *sld = &sd->save;
625 
626  /* If the setting is not saved to the configuration
627  * file, just continue with the next setting */
628  if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
629  if (sld->conv & SLF_NOT_IN_CONFIG) continue;
630 
631  /* XXX - wtf is this?? (group override?) */
632  std::string s{ sdb->name };
633  auto sc = s.find('.');
634  if (sc != std::string::npos) {
635  group = ini->GetGroup(s.substr(0, sc));
636  s = s.substr(sc + 1);
637  } else {
638  if (group_def == nullptr) group_def = ini->GetGroup(grpname);
639  group = group_def;
640  }
641 
642  item = group->GetItem(s, true);
643  ptr = GetVariableAddress(object, sld);
644 
645  if (item->value.has_value()) {
646  /* check if the value is the same as the old value */
647  const void *p = StringToVal(sdb, item->value->c_str());
648 
649  /* The main type of a variable/setting is in bytes 8-15
650  * The subtype (what kind of numbers do we have there) is in 0-7 */
651  switch (sdb->cmd) {
652  case SDT_BOOLX:
653  case SDT_NUMX:
654  case SDT_ONEOFMANY:
655  case SDT_MANYOFMANY:
656  switch (GetVarMemType(sld->conv)) {
657  case SLE_VAR_BL:
658  if (*(bool*)ptr == (p != nullptr)) continue;
659  break;
660 
661  case SLE_VAR_I8:
662  case SLE_VAR_U8:
663  if (*(byte*)ptr == (byte)(size_t)p) continue;
664  break;
665 
666  case SLE_VAR_I16:
667  case SLE_VAR_U16:
668  if (*(uint16*)ptr == (uint16)(size_t)p) continue;
669  break;
670 
671  case SLE_VAR_I32:
672  case SLE_VAR_U32:
673  if (*(uint32*)ptr == (uint32)(size_t)p) continue;
674  break;
675 
676  default: NOT_REACHED();
677  }
678  break;
679 
680  default: break; // Assume the other types are always changed
681  }
682  }
683 
684  /* Value has changed, get the new value and put it into a buffer */
685  switch (sdb->cmd) {
686  case SDT_BOOLX:
687  case SDT_NUMX:
688  case SDT_ONEOFMANY:
689  case SDT_MANYOFMANY: {
690  uint32 i = (uint32)ReadValue(ptr, sld->conv);
691 
692  switch (sdb->cmd) {
693  case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break;
694  case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : (sld->conv & SLF_HEX) ? "%X" : "%u", i); break;
695  case SDT_ONEOFMANY: MakeOneOfMany(buf, lastof(buf), sdb->many, i); break;
696  case SDT_MANYOFMANY: MakeManyOfMany(buf, lastof(buf), sdb->many, i); break;
697  default: NOT_REACHED();
698  }
699  break;
700  }
701 
702  case SDT_STRING:
703  switch (GetVarMemType(sld->conv)) {
704  case SLE_VAR_STRB: strecpy(buf, (char*)ptr, lastof(buf)); break;
705  case SLE_VAR_STRBQ:seprintf(buf, lastof(buf), "\"%s\"", (char*)ptr); break;
706  case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break;
707 
708  case SLE_VAR_STRQ:
709  if (*(char**)ptr == nullptr) {
710  buf[0] = '\0';
711  } else {
712  seprintf(buf, lastof(buf), "\"%s\"", *(char**)ptr);
713  }
714  break;
715 
716  case SLE_VAR_CHAR: buf[0] = *(char*)ptr; buf[1] = '\0'; break;
717  default: NOT_REACHED();
718  }
719  break;
720 
721  case SDT_STDSTRING:
722  switch (GetVarMemType(sld->conv)) {
723  case SLE_VAR_STR: strecpy(buf, reinterpret_cast<std::string *>(ptr)->c_str(), lastof(buf)); break;
724 
725  case SLE_VAR_STRQ:
726  if (reinterpret_cast<std::string *>(ptr)->empty()) {
727  buf[0] = '\0';
728  } else {
729  seprintf(buf, lastof(buf), "\"%s\"", reinterpret_cast<std::string *>(ptr)->c_str());
730  }
731  break;
732 
733  default: NOT_REACHED();
734  }
735  break;
736 
737  case SDT_INTLIST:
738  MakeIntList(buf, lastof(buf), ptr, sld->length, sld->conv);
739  break;
740 
741  default: NOT_REACHED();
742  }
743 
744  /* The value is different, that means we have to write it to the ini */
745  item->value.emplace(buf);
746  }
747 }
748 
758 static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
759 {
760  IniGroup *group = ini->GetGroup(grpname);
761 
762  if (group == nullptr) return;
763 
764  list.clear();
765 
766  for (const IniItem *item = group->item; item != nullptr; item = item->next) {
767  if (!item->name.empty()) list.push_back(item->name);
768  }
769 }
770 
780 static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
781 {
782  IniGroup *group = ini->GetGroup(grpname);
783 
784  if (group == nullptr) return;
785  group->Clear();
786 
787  for (const auto &iter : list) {
788  group->GetItem(iter.c_str(), true)->SetValue("");
789  }
790 }
791 
798 void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
799 {
800  IniLoadSettings(ini, _window_settings, grpname, desc);
801 }
802 
809 void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
810 {
811  IniSaveSettings(ini, _window_settings, grpname, desc);
812 }
813 
819 bool SettingDesc::IsEditable(bool do_command) const
820 {
821  if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->desc.flags & SGF_PER_COMPANY)) return false;
822  if ((this->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
823  if ((this->desc.flags & SGF_NO_NETWORK) && _networking) return false;
824  if ((this->desc.flags & SGF_NEWGAME_ONLY) &&
825  (_game_mode == GM_NORMAL ||
826  (_game_mode == GM_EDITOR && !(this->desc.flags & SGF_SCENEDIT_TOO)))) return false;
827  return true;
828 }
829 
835 {
836  if (this->desc.flags & SGF_PER_COMPANY) return ST_COMPANY;
837  return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
838 }
839 
840 /* Begin - Callback Functions for the various settings. */
841 
843 static bool v_PositionMainToolbar(int32 p1)
844 {
845  if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
846  return true;
847 }
848 
850 static bool v_PositionStatusbar(int32 p1)
851 {
852  if (_game_mode != GM_MENU) {
853  PositionStatusbar(nullptr);
854  PositionNewsMessage(nullptr);
855  PositionNetworkChatWindow(nullptr);
856  }
857  return true;
858 }
859 
860 static bool PopulationInLabelActive(int32 p1)
861 {
863  return true;
864 }
865 
866 static bool RedrawScreen(int32 p1)
867 {
869  return true;
870 }
871 
877 static bool RedrawSmallmap(int32 p1)
878 {
879  BuildLandLegend();
882  return true;
883 }
884 
885 static bool InvalidateDetailsWindow(int32 p1)
886 {
888  return true;
889 }
890 
891 static bool StationSpreadChanged(int32 p1)
892 {
895  return true;
896 }
897 
898 static bool InvalidateBuildIndustryWindow(int32 p1)
899 {
901  return true;
902 }
903 
904 static bool CloseSignalGUI(int32 p1)
905 {
906  if (p1 == 0) {
908  }
909  return true;
910 }
911 
912 static bool InvalidateTownViewWindow(int32 p1)
913 {
915  return true;
916 }
917 
918 static bool DeleteSelectStationWindow(int32 p1)
919 {
921  return true;
922 }
923 
924 static bool UpdateConsists(int32 p1)
925 {
926  for (Train *t : Train::Iterate()) {
927  /* Update the consist of all trains so the maximum speed is set correctly. */
928  if (t->IsFrontEngine() || t->IsFreeWagon()) t->ConsistChanged(CCF_TRACK);
929  }
931  return true;
932 }
933 
934 /* Check service intervals of vehicles, p1 is value of % or day based servicing */
935 static bool CheckInterval(int32 p1)
936 {
937  bool update_vehicles;
939  if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
941  update_vehicles = false;
942  } else {
943  vds = &Company::Get(_current_company)->settings.vehicle;
944  update_vehicles = true;
945  }
946 
947  if (p1 != 0) {
948  vds->servint_trains = 50;
949  vds->servint_roadveh = 50;
950  vds->servint_aircraft = 50;
951  vds->servint_ships = 50;
952  } else {
953  vds->servint_trains = 150;
954  vds->servint_roadveh = 150;
955  vds->servint_aircraft = 100;
956  vds->servint_ships = 360;
957  }
958 
959  if (update_vehicles) {
961  for (Vehicle *v : Vehicle::Iterate()) {
962  if (v->owner == _current_company && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
963  v->SetServiceInterval(CompanyServiceInterval(c, v->type));
964  v->SetServiceIntervalIsPercent(p1 != 0);
965  }
966  }
967  }
968 
969  InvalidateDetailsWindow(0);
970 
971  return true;
972 }
973 
974 static bool UpdateInterval(VehicleType type, int32 p1)
975 {
976  bool update_vehicles;
978  if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
980  update_vehicles = false;
981  } else {
982  vds = &Company::Get(_current_company)->settings.vehicle;
983  update_vehicles = true;
984  }
985 
986  /* Test if the interval is valid */
987  uint16 interval = GetServiceIntervalClamped(p1, vds->servint_ispercent);
988  if (interval != p1) return false;
989 
990  if (update_vehicles) {
991  for (Vehicle *v : Vehicle::Iterate()) {
992  if (v->owner == _current_company && v->type == type && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
993  v->SetServiceInterval(p1);
994  }
995  }
996  }
997 
998  InvalidateDetailsWindow(0);
999 
1000  return true;
1001 }
1002 
1003 static bool UpdateIntervalTrains(int32 p1)
1004 {
1005  return UpdateInterval(VEH_TRAIN, p1);
1006 }
1007 
1008 static bool UpdateIntervalRoadVeh(int32 p1)
1009 {
1010  return UpdateInterval(VEH_ROAD, p1);
1011 }
1012 
1013 static bool UpdateIntervalShips(int32 p1)
1014 {
1015  return UpdateInterval(VEH_SHIP, p1);
1016 }
1017 
1018 static bool UpdateIntervalAircraft(int32 p1)
1019 {
1020  return UpdateInterval(VEH_AIRCRAFT, p1);
1021 }
1022 
1023 static bool TrainAccelerationModelChanged(int32 p1)
1024 {
1025  for (Train *t : Train::Iterate()) {
1026  if (t->IsFrontEngine()) {
1027  t->tcache.cached_max_curve_speed = t->GetCurveSpeedLimit();
1028  t->UpdateAcceleration();
1029  }
1030  }
1031 
1032  /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
1036 
1037  return true;
1038 }
1039 
1045 static bool TrainSlopeSteepnessChanged(int32 p1)
1046 {
1047  for (Train *t : Train::Iterate()) {
1048  if (t->IsFrontEngine()) t->CargoChanged();
1049  }
1050 
1051  return true;
1052 }
1053 
1059 static bool RoadVehAccelerationModelChanged(int32 p1)
1060 {
1061  if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
1062  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1063  if (rv->IsFrontEngine()) {
1064  rv->CargoChanged();
1065  }
1066  }
1067  }
1068 
1069  /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
1073 
1074  return true;
1075 }
1076 
1082 static bool RoadVehSlopeSteepnessChanged(int32 p1)
1083 {
1084  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1085  if (rv->IsFrontEngine()) rv->CargoChanged();
1086  }
1087 
1088  return true;
1089 }
1090 
1091 static bool DragSignalsDensityChanged(int32)
1092 {
1094 
1095  return true;
1096 }
1097 
1098 static bool TownFoundingChanged(int32 p1)
1099 {
1100  if (_game_mode != GM_EDITOR && _settings_game.economy.found_town == TF_FORBIDDEN) {
1102  return true;
1103  }
1105  return true;
1106 }
1107 
1108 static bool InvalidateVehTimetableWindow(int32 p1)
1109 {
1111  return true;
1112 }
1113 
1114 static bool ZoomMinMaxChanged(int32 p1)
1115 {
1116  extern void ConstrainAllViewportsZoom();
1117  ConstrainAllViewportsZoom();
1120  /* Restrict GUI zoom if it is no longer available. */
1122  UpdateCursorSize();
1124  }
1125  return true;
1126 }
1127 
1135 static bool InvalidateNewGRFChangeWindows(int32 p1)
1136 {
1139  ReInitAllWindows();
1140  return true;
1141 }
1142 
1143 static bool InvalidateCompanyLiveryWindow(int32 p1)
1144 {
1146  return RedrawScreen(p1);
1147 }
1148 
1149 static bool InvalidateIndustryViewWindow(int32 p1)
1150 {
1152  return true;
1153 }
1154 
1155 static bool InvalidateAISettingsWindow(int32 p1)
1156 {
1158  return true;
1159 }
1160 
1166 static bool RedrawTownAuthority(int32 p1)
1167 {
1169  return true;
1170 }
1171 
1178 {
1180  return true;
1181 }
1182 
1188 static bool InvalidateCompanyWindow(int32 p1)
1189 {
1191  return true;
1192 }
1193 
1195 static void ValidateSettings()
1196 {
1197  /* Do not allow a custom sea level with the original land generator. */
1201  }
1202 }
1203 
1204 static bool DifficultyNoiseChange(int32 i)
1205 {
1206  if (_game_mode == GM_NORMAL) {
1210  }
1211  }
1212 
1213  return true;
1214 }
1215 
1216 static bool MaxNoAIsChange(int32 i)
1217 {
1218  if (GetGameSettings().difficulty.max_no_competitors != 0 &&
1219  AI::GetInfoList()->size() == 0 &&
1220  (!_networking || _network_server)) {
1221  ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
1222  }
1223 
1225  return true;
1226 }
1227 
1233 static bool CheckRoadSide(int p1)
1234 {
1235  extern bool RoadVehiclesAreBuilt();
1236  return _game_mode == GM_MENU || !RoadVehiclesAreBuilt();
1237 }
1238 
1246 static size_t ConvertLandscape(const char *value)
1247 {
1248  /* try with the old values */
1249  return LookupOneOfMany("normal|hilly|desert|candy", value);
1250 }
1251 
1252 static bool CheckFreeformEdges(int32 p1)
1253 {
1254  if (_game_mode == GM_MENU) return true;
1255  if (p1 != 0) {
1256  for (Ship *s : Ship::Iterate()) {
1257  /* Check if there is a ship on the northern border. */
1258  if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
1259  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
1260  return false;
1261  }
1262  }
1263  for (const BaseStation *st : BaseStation::Iterate()) {
1264  /* Check if there is a non-deleted buoy on the northern border. */
1265  if (st->IsInUse() && (TileX(st->xy) == 0 || TileY(st->xy) == 0)) {
1266  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
1267  return false;
1268  }
1269  }
1270  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
1271  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
1272  } else {
1273  for (uint i = 0; i < MapMaxX(); i++) {
1274  if (TileHeight(TileXY(i, 1)) != 0) {
1275  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1276  return false;
1277  }
1278  }
1279  for (uint i = 1; i < MapMaxX(); i++) {
1280  if (!IsTileType(TileXY(i, MapMaxY() - 1), MP_WATER) || TileHeight(TileXY(1, MapMaxY())) != 0) {
1281  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1282  return false;
1283  }
1284  }
1285  for (uint i = 0; i < MapMaxY(); i++) {
1286  if (TileHeight(TileXY(1, i)) != 0) {
1287  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1288  return false;
1289  }
1290  }
1291  for (uint i = 1; i < MapMaxY(); i++) {
1292  if (!IsTileType(TileXY(MapMaxX() - 1, i), MP_WATER) || TileHeight(TileXY(MapMaxX(), i)) != 0) {
1293  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1294  return false;
1295  }
1296  }
1297  /* Make tiles at the border water again. */
1298  for (uint i = 0; i < MapMaxX(); i++) {
1299  SetTileHeight(TileXY(i, 0), 0);
1300  SetTileType(TileXY(i, 0), MP_WATER);
1301  }
1302  for (uint i = 0; i < MapMaxY(); i++) {
1303  SetTileHeight(TileXY(0, i), 0);
1304  SetTileType(TileXY(0, i), MP_WATER);
1305  }
1306  }
1308  return true;
1309 }
1310 
1315 static bool ChangeDynamicEngines(int32 p1)
1316 {
1317  if (_game_mode == GM_MENU) return true;
1318 
1320  ShowErrorMessage(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES, INVALID_STRING_ID, WL_ERROR);
1321  return false;
1322  }
1323 
1324  return true;
1325 }
1326 
1327 static bool ChangeMaxHeightLevel(int32 p1)
1328 {
1329  if (_game_mode == GM_NORMAL) return false;
1330  if (_game_mode != GM_EDITOR) return true;
1331 
1332  /* Check if at least one mountain on the map is higher than the new value.
1333  * If yes, disallow the change. */
1334  for (TileIndex t = 0; t < MapSize(); t++) {
1335  if ((int32)TileHeight(t) > p1) {
1336  ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
1337  /* Return old, unchanged value */
1338  return false;
1339  }
1340  }
1341 
1342  /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
1344 
1345  return true;
1346 }
1347 
1348 static bool StationCatchmentChanged(int32 p1)
1349 {
1352  return true;
1353 }
1354 
1355 static bool MaxVehiclesChanged(int32 p1)
1356 {
1359  return true;
1360 }
1361 
1362 static bool InvalidateShipPathCache(int32 p1)
1363 {
1364  for (Ship *s : Ship::Iterate()) {
1365  s->path.clear();
1366  }
1367  return true;
1368 }
1369 
1370 static bool UpdateClientName(int32 p1)
1371 {
1373  return true;
1374 }
1375 
1376 static bool UpdateServerPassword(int32 p1)
1377 {
1378  if (strcmp(_settings_client.network.server_password, "*") == 0) {
1380  }
1381 
1382  return true;
1383 }
1384 
1385 static bool UpdateRconPassword(int32 p1)
1386 {
1387  if (strcmp(_settings_client.network.rcon_password, "*") == 0) {
1389  }
1390 
1391  return true;
1392 }
1393 
1394 static bool UpdateClientConfigValues(int32 p1)
1395 {
1397 
1398  return true;
1399 }
1400 
1401 /* End - Callback Functions */
1402 
1407 {
1408  memset(_old_diff_custom, 0, sizeof(_old_diff_custom));
1409 }
1410 
1417 static void HandleOldDiffCustom(bool savegame)
1418 {
1419  uint options_to_load = GAME_DIFFICULTY_NUM - ((savegame && IsSavegameVersionBefore(SLV_4)) ? 1 : 0);
1420 
1421  if (!savegame) {
1422  /* If we did read to old_diff_custom, then at least one value must be non 0. */
1423  bool old_diff_custom_used = false;
1424  for (uint i = 0; i < options_to_load && !old_diff_custom_used; i++) {
1425  old_diff_custom_used = (_old_diff_custom[i] != 0);
1426  }
1427 
1428  if (!old_diff_custom_used) return;
1429  }
1430 
1431  for (uint i = 0; i < options_to_load; i++) {
1432  const SettingDesc *sd = &_settings[i];
1433  /* Skip deprecated options */
1434  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1435  void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
1436  Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
1437  }
1438 }
1439 
1440 static void AILoadConfig(IniFile *ini, const char *grpname)
1441 {
1442  IniGroup *group = ini->GetGroup(grpname);
1443  IniItem *item;
1444 
1445  /* Clean any configured AI */
1446  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1448  }
1449 
1450  /* If no group exists, return */
1451  if (group == nullptr) return;
1452 
1454  for (item = group->item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
1456 
1457  config->Change(item->name.c_str());
1458  if (!config->HasScript()) {
1459  if (item->name != "none") {
1460  DEBUG(script, 0, "The AI by the name '%s' was no longer found, and removed from the list.", item->name.c_str());
1461  continue;
1462  }
1463  }
1464  if (item->value.has_value()) config->StringToSettings(item->value->c_str());
1465  }
1466 }
1467 
1468 static void GameLoadConfig(IniFile *ini, const char *grpname)
1469 {
1470  IniGroup *group = ini->GetGroup(grpname);
1471  IniItem *item;
1472 
1473  /* Clean any configured GameScript */
1475 
1476  /* If no group exists, return */
1477  if (group == nullptr) return;
1478 
1479  item = group->item;
1480  if (item == nullptr) return;
1481 
1483 
1484  config->Change(item->name.c_str());
1485  if (!config->HasScript()) {
1486  if (item->name != "none") {
1487  DEBUG(script, 0, "The GameScript by the name '%s' was no longer found, and removed from the list.", item->name.c_str());
1488  return;
1489  }
1490  }
1491  if (item->value.has_value()) config->StringToSettings(item->value->c_str());
1492 }
1493 
1499 static int DecodeHexNibble(char c)
1500 {
1501  if (c >= '0' && c <= '9') return c - '0';
1502  if (c >= 'A' && c <= 'F') return c + 10 - 'A';
1503  if (c >= 'a' && c <= 'f') return c + 10 - 'a';
1504  return -1;
1505 }
1506 
1515 static bool DecodeHexText(const char *pos, uint8 *dest, size_t dest_size)
1516 {
1517  while (dest_size > 0) {
1518  int hi = DecodeHexNibble(pos[0]);
1519  int lo = (hi >= 0) ? DecodeHexNibble(pos[1]) : -1;
1520  if (lo < 0) return false;
1521  *dest++ = (hi << 4) | lo;
1522  pos += 2;
1523  dest_size--;
1524  }
1525  return *pos == '|';
1526 }
1527 
1534 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
1535 {
1536  IniGroup *group = ini->GetGroup(grpname);
1537  IniItem *item;
1538  GRFConfig *first = nullptr;
1539  GRFConfig **curr = &first;
1540 
1541  if (group == nullptr) return nullptr;
1542 
1543  for (item = group->item; item != nullptr; item = item->next) {
1544  GRFConfig *c = nullptr;
1545 
1546  uint8 grfid_buf[4], md5sum[16];
1547  const char *filename = item->name.c_str();
1548  bool has_grfid = false;
1549  bool has_md5sum = false;
1550 
1551  /* Try reading "<grfid>|" and on success, "<md5sum>|". */
1552  has_grfid = DecodeHexText(filename, grfid_buf, lengthof(grfid_buf));
1553  if (has_grfid) {
1554  filename += 1 + 2 * lengthof(grfid_buf);
1555  has_md5sum = DecodeHexText(filename, md5sum, lengthof(md5sum));
1556  if (has_md5sum) filename += 1 + 2 * lengthof(md5sum);
1557 
1558  uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1559  if (has_md5sum) {
1560  const GRFConfig *s = FindGRFConfig(grfid, FGCM_EXACT, md5sum);
1561  if (s != nullptr) c = new GRFConfig(*s);
1562  }
1563  if (c == nullptr && !FioCheckFileExists(filename, NEWGRF_DIR)) {
1564  const GRFConfig *s = FindGRFConfig(grfid, FGCM_NEWEST_VALID);
1565  if (s != nullptr) c = new GRFConfig(*s);
1566  }
1567  }
1568  if (c == nullptr) c = new GRFConfig(filename);
1569 
1570  /* Parse parameters */
1571  if (item->value.has_value() && !item->value->empty()) {
1572  int count = ParseIntList(item->value->c_str(), c->param, lengthof(c->param));
1573  if (count < 0) {
1574  SetDParamStr(0, filename);
1575  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
1576  count = 0;
1577  }
1578  c->num_params = count;
1579  }
1580 
1581  /* Check if item is valid */
1582  if (!FillGRFDetails(c, is_static) || HasBit(c->flags, GCF_INVALID)) {
1583  if (c->status == GCS_NOT_FOUND) {
1584  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1585  } else if (HasBit(c->flags, GCF_UNSAFE)) {
1586  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1587  } else if (HasBit(c->flags, GCF_SYSTEM)) {
1588  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1589  } else if (HasBit(c->flags, GCF_INVALID)) {
1590  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1591  } else {
1592  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1593  }
1594 
1595  SetDParamStr(0, StrEmpty(filename) ? item->name.c_str() : filename);
1596  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_GRF, WL_CRITICAL);
1597  delete c;
1598  continue;
1599  }
1600 
1601  /* Check for duplicate GRFID (will also check for duplicate filenames) */
1602  bool duplicate = false;
1603  for (const GRFConfig *gc = first; gc != nullptr; gc = gc->next) {
1604  if (gc->ident.grfid == c->ident.grfid) {
1605  SetDParamStr(0, c->filename);
1606  SetDParamStr(1, gc->filename);
1607  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_DUPLICATE_GRFID, WL_CRITICAL);
1608  duplicate = true;
1609  break;
1610  }
1611  }
1612  if (duplicate) {
1613  delete c;
1614  continue;
1615  }
1616 
1617  /* Mark file as static to avoid saving in savegame. */
1618  if (is_static) SetBit(c->flags, GCF_STATIC);
1619 
1620  /* Add item to list */
1621  *curr = c;
1622  curr = &c->next;
1623  }
1624 
1625  return first;
1626 }
1627 
1628 static void AISaveConfig(IniFile *ini, const char *grpname)
1629 {
1630  IniGroup *group = ini->GetGroup(grpname);
1631 
1632  if (group == nullptr) return;
1633  group->Clear();
1634 
1635  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1637  const char *name;
1638  char value[1024];
1639  config->SettingsToString(value, lastof(value));
1640 
1641  if (config->HasScript()) {
1642  name = config->GetName();
1643  } else {
1644  name = "none";
1645  }
1646 
1647  IniItem *item = new IniItem(group, name);
1648  item->SetValue(value);
1649  }
1650 }
1651 
1652 static void GameSaveConfig(IniFile *ini, const char *grpname)
1653 {
1654  IniGroup *group = ini->GetGroup(grpname);
1655 
1656  if (group == nullptr) return;
1657  group->Clear();
1658 
1660  const char *name;
1661  char value[1024];
1662  config->SettingsToString(value, lastof(value));
1663 
1664  if (config->HasScript()) {
1665  name = config->GetName();
1666  } else {
1667  name = "none";
1668  }
1669 
1670  IniItem *item = new IniItem(group, name);
1671  item->SetValue(value);
1672 }
1673 
1678 static void SaveVersionInConfig(IniFile *ini)
1679 {
1680  IniGroup *group = ini->GetGroup("version");
1681 
1682  char version[9];
1683  seprintf(version, lastof(version), "%08X", _openttd_newgrf_version);
1684 
1685  const char * const versions[][2] = {
1686  { "version_string", _openttd_revision },
1687  { "version_number", version }
1688  };
1689 
1690  for (uint i = 0; i < lengthof(versions); i++) {
1691  group->GetItem(versions[i][0], true)->SetValue(versions[i][1]);
1692  }
1693 }
1694 
1695 /* Save a GRF configuration to the given group name */
1696 static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list)
1697 {
1698  ini->RemoveGroup(grpname);
1699  IniGroup *group = ini->GetGroup(grpname);
1700  const GRFConfig *c;
1701 
1702  for (c = list; c != nullptr; c = c->next) {
1703  /* Hex grfid (4 bytes in nibbles), "|", hex md5sum (16 bytes in nibbles), "|", file system path. */
1704  char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1705  char params[512];
1706  GRFBuildParamList(params, c, lastof(params));
1707 
1708  char *pos = key + seprintf(key, lastof(key), "%08X|", BSWAP32(c->ident.grfid));
1709  pos = md5sumToString(pos, lastof(key), c->ident.md5sum);
1710  seprintf(pos, lastof(key), "|%s", c->filename);
1711  group->GetItem(key, true)->SetValue(params);
1712  }
1713 }
1714 
1715 /* Common handler for saving/loading variables to the configuration file */
1716 static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool basic_settings = true, bool other_settings = true)
1717 {
1718  if (basic_settings) {
1719  proc(ini, (const SettingDesc*)_misc_settings, "misc", nullptr);
1720 #if defined(_WIN32) && !defined(DEDICATED)
1721  proc(ini, (const SettingDesc*)_win32_settings, "win32", nullptr);
1722 #endif /* _WIN32 */
1723  }
1724 
1725  if (other_settings) {
1726  proc(ini, _settings, "patches", &_settings_newgame);
1727  proc(ini, _currency_settings,"currency", &_custom_currency);
1728  proc(ini, _company_settings, "company", &_settings_client.company);
1729 
1730  proc_list(ini, "server_bind_addresses", _network_bind_list);
1731  proc_list(ini, "servers", _network_host_list);
1732  proc_list(ini, "bans", _network_ban_list);
1733  }
1734 }
1735 
1736 static IniFile *IniLoadConfig()
1737 {
1738  IniFile *ini = new IniFile(_list_group_names);
1740  return ini;
1741 }
1742 
1747 void LoadFromConfig(bool minimal)
1748 {
1749  IniFile *ini = IniLoadConfig();
1750  if (!minimal) ResetCurrencies(false); // Initialize the array of currencies, without preserving the custom one
1751 
1752  /* Load basic settings only during bootstrap, load other settings not during bootstrap */
1753  HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList, minimal, !minimal);
1754 
1755  if (!minimal) {
1756  _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
1757  _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
1758  AILoadConfig(ini, "ai_players");
1759  GameLoadConfig(ini, "game_scripts");
1760 
1762  IniLoadSettings(ini, _gameopt_settings, "gameopt", &_settings_newgame);
1763  HandleOldDiffCustom(false);
1764 
1765  ValidateSettings();
1766 
1767  /* Display scheduled errors */
1768  extern void ScheduleErrorMessage(ErrorList &datas);
1770  if (FindWindowById(WC_ERRMSG, 0) == nullptr) ShowFirstError();
1771  }
1772 
1773  delete ini;
1774 }
1775 
1778 {
1779  IniFile *ini = IniLoadConfig();
1780 
1781  /* Remove some obsolete groups. These have all been loaded into other groups. */
1782  ini->RemoveGroup("patches");
1783  ini->RemoveGroup("yapf");
1784  ini->RemoveGroup("gameopt");
1785 
1786  HandleSettingDescs(ini, IniSaveSettings, IniSaveSettingList);
1787  GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
1788  GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
1789  AISaveConfig(ini, "ai_players");
1790  GameSaveConfig(ini, "game_scripts");
1791  SaveVersionInConfig(ini);
1792  ini->SaveToDisk(_config_file);
1793  delete ini;
1794 }
1795 
1801 {
1802  StringList list;
1803 
1804  std::unique_ptr<IniFile> ini(IniLoadConfig());
1805  for (IniGroup *group = ini->group; group != nullptr; group = group->next) {
1806  if (group->name.compare(0, 7, "preset-") == 0) {
1807  list.push_back(group->name.substr(7));
1808  }
1809  }
1810 
1811  return list;
1812 }
1813 
1820 GRFConfig *LoadGRFPresetFromConfig(const char *config_name)
1821 {
1822  size_t len = strlen(config_name) + 8;
1823  char *section = (char*)alloca(len);
1824  seprintf(section, section + len - 1, "preset-%s", config_name);
1825 
1826  IniFile *ini = IniLoadConfig();
1827  GRFConfig *config = GRFLoadConfig(ini, section, false);
1828  delete ini;
1829 
1830  return config;
1831 }
1832 
1839 void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
1840 {
1841  size_t len = strlen(config_name) + 8;
1842  char *section = (char*)alloca(len);
1843  seprintf(section, section + len - 1, "preset-%s", config_name);
1844 
1845  IniFile *ini = IniLoadConfig();
1846  GRFSaveConfig(ini, section, config);
1847  ini->SaveToDisk(_config_file);
1848  delete ini;
1849 }
1850 
1855 void DeleteGRFPresetFromConfig(const char *config_name)
1856 {
1857  size_t len = strlen(config_name) + 8;
1858  char *section = (char*)alloca(len);
1859  seprintf(section, section + len - 1, "preset-%s", config_name);
1860 
1861  IniFile *ini = IniLoadConfig();
1862  ini->RemoveGroup(section);
1863  ini->SaveToDisk(_config_file);
1864  delete ini;
1865 }
1866 
1867 const SettingDesc *GetSettingDescription(uint index)
1868 {
1869  if (index >= lengthof(_settings)) return nullptr;
1870  return &_settings[index];
1871 }
1872 
1884 CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1885 {
1886  const SettingDesc *sd = GetSettingDescription(p1);
1887 
1888  if (sd == nullptr) return CMD_ERROR;
1890 
1891  if (!sd->IsEditable(true)) return CMD_ERROR;
1892 
1893  if (flags & DC_EXEC) {
1894  void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
1895 
1896  int32 oldval = (int32)ReadValue(var, sd->save.conv);
1897  int32 newval = (int32)p2;
1898 
1899  Write_ValidateSetting(var, sd, newval);
1900  newval = (int32)ReadValue(var, sd->save.conv);
1901 
1902  if (oldval == newval) return CommandCost();
1903 
1904  if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
1905  WriteValue(var, sd->save.conv, (int64)oldval);
1906  return CommandCost();
1907  }
1908 
1909  if (sd->desc.flags & SGF_NO_NETWORK) {
1911  GamelogSetting(sd->desc.name, oldval, newval);
1913  }
1914 
1916 
1917  if (_save_config) SaveToConfig();
1918  }
1919 
1920  return CommandCost();
1921 }
1922 
1933 CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1934 {
1935  if (p1 >= lengthof(_company_settings)) return CMD_ERROR;
1936  const SettingDesc *sd = &_company_settings[p1];
1937 
1938  if (flags & DC_EXEC) {
1940 
1941  int32 oldval = (int32)ReadValue(var, sd->save.conv);
1942  int32 newval = (int32)p2;
1943 
1944  Write_ValidateSetting(var, sd, newval);
1945  newval = (int32)ReadValue(var, sd->save.conv);
1946 
1947  if (oldval == newval) return CommandCost();
1948 
1949  if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
1950  WriteValue(var, sd->save.conv, (int64)oldval);
1951  return CommandCost();
1952  }
1953 
1955  }
1956 
1957  return CommandCost();
1958 }
1959 
1967 bool SetSettingValue(uint index, int32 value, bool force_newgame)
1968 {
1969  const SettingDesc *sd = &_settings[index];
1970  /* If an item is company-based, we do not send it over the network
1971  * (if any) to change. Also *hack*hack* we update the _newgame version
1972  * of settings because changing a company-based setting in a game also
1973  * changes its defaults. At least that is the convention we have chosen */
1974  if (sd->save.conv & SLF_NO_NETWORK_SYNC) {
1975  void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
1976  Write_ValidateSetting(var, sd, value);
1977 
1978  if (_game_mode != GM_MENU) {
1979  void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
1980  Write_ValidateSetting(var2, sd, value);
1981  }
1982  if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
1983 
1985 
1986  if (_save_config) SaveToConfig();
1987  return true;
1988  }
1989 
1990  if (force_newgame) {
1991  void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
1992  Write_ValidateSetting(var2, sd, value);
1993 
1994  if (_save_config) SaveToConfig();
1995  return true;
1996  }
1997 
1998  /* send non-company-based settings over the network */
1999  if (!_networking || (_networking && _network_server)) {
2000  return DoCommandP(0, index, value, CMD_CHANGE_SETTING);
2001  }
2002  return false;
2003 }
2004 
2011 void SetCompanySetting(uint index, int32 value)
2012 {
2013  const SettingDesc *sd = &_company_settings[index];
2014  if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
2015  DoCommandP(0, index, value, CMD_CHANGE_COMPANY_SETTING);
2016  } else {
2017  void *var = GetVariableAddress(&_settings_client.company, &sd->save);
2018  Write_ValidateSetting(var, sd, value);
2019  if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
2020  }
2021 }
2022 
2027 {
2028  Company *c = Company::Get(cid);
2029  const SettingDesc *sd;
2030  for (sd = _company_settings; sd->save.cmd != SL_END; sd++) {
2031  void *var = GetVariableAddress(&c->settings, &sd->save);
2032  Write_ValidateSetting(var, sd, (int32)(size_t)sd->desc.def);
2033  }
2034 }
2035 
2040 {
2041  const SettingDesc *sd;
2042  uint i = 0;
2043  for (sd = _company_settings; sd->save.cmd != SL_END; sd++, i++) {
2044  const void *old_var = GetVariableAddress(&Company::Get(_current_company)->settings, &sd->save);
2045  const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
2046  uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
2047  uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
2048  if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, nullptr, nullptr, _local_company);
2049  }
2050 }
2051 
2057 uint GetCompanySettingIndex(const char *name)
2058 {
2059  uint i;
2060  const SettingDesc *sd = GetSettingFromName(name, &i);
2061  (void)sd; // Unused without asserts
2062  assert(sd != nullptr && (sd->desc.flags & SGF_PER_COMPANY) != 0);
2063  return i;
2064 }
2065 
2073 bool SetSettingValue(uint index, const char *value, bool force_newgame)
2074 {
2075  const SettingDesc *sd = &_settings[index];
2076  assert(sd->save.conv & SLF_NO_NETWORK_SYNC);
2077 
2078  if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
2079  char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
2080  free(*var);
2081  *var = strcmp(value, "(null)") == 0 ? nullptr : stredup(value);
2082  } else {
2083  char *var = (char*)GetVariableAddress(nullptr, &sd->save);
2084  strecpy(var, value, &var[sd->save.length - 1]);
2085  }
2086  if (sd->desc.proc != nullptr) sd->desc.proc(0);
2087 
2088  if (_save_config) SaveToConfig();
2089  return true;
2090 }
2091 
2099 const SettingDesc *GetSettingFromName(const char *name, uint *i)
2100 {
2101  const SettingDesc *sd;
2102 
2103  /* First check all full names */
2104  for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2105  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2106  if (strcmp(sd->desc.name, name) == 0) return sd;
2107  }
2108 
2109  /* Then check the shortcut variant of the name. */
2110  for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2111  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2112  const char *short_name = strchr(sd->desc.name, '.');
2113  if (short_name != nullptr) {
2114  short_name++;
2115  if (strcmp(short_name, name) == 0) return sd;
2116  }
2117  }
2118 
2119  if (strncmp(name, "company.", 8) == 0) name += 8;
2120  /* And finally the company-based settings */
2121  for (*i = 0, sd = _company_settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2122  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2123  if (strcmp(sd->desc.name, name) == 0) return sd;
2124  }
2125 
2126  return nullptr;
2127 }
2128 
2129 /* Those 2 functions need to be here, else we have to make some stuff non-static
2130  * and besides, it is also better to keep stuff like this at the same place */
2131 void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
2132 {
2133  uint index;
2134  const SettingDesc *sd = GetSettingFromName(name, &index);
2135 
2136  if (sd == nullptr) {
2137  IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
2138  return;
2139  }
2140 
2141  bool success;
2142  if (sd->desc.cmd == SDT_STRING) {
2143  success = SetSettingValue(index, value, force_newgame);
2144  } else {
2145  uint32 val;
2146  extern bool GetArgumentInteger(uint32 *value, const char *arg);
2147  success = GetArgumentInteger(&val, value);
2148  if (!success) {
2149  IConsolePrintF(CC_ERROR, "'%s' is not an integer.", value);
2150  return;
2151  }
2152 
2153  success = SetSettingValue(index, val, force_newgame);
2154  }
2155 
2156  if (!success) {
2157  if (_network_server) {
2158  IConsoleError("This command/variable is not available during network games.");
2159  } else {
2160  IConsoleError("This command/variable is only available to a network server.");
2161  }
2162  }
2163 }
2164 
2165 void IConsoleSetSetting(const char *name, int value)
2166 {
2167  uint index;
2168  const SettingDesc *sd = GetSettingFromName(name, &index);
2169  (void)sd; // Unused without asserts
2170  assert(sd != nullptr);
2171  SetSettingValue(index, value);
2172 }
2173 
2179 void IConsoleGetSetting(const char *name, bool force_newgame)
2180 {
2181  char value[20];
2182  uint index;
2183  const SettingDesc *sd = GetSettingFromName(name, &index);
2184  const void *ptr;
2185 
2186  if (sd == nullptr) {
2187  IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
2188  return;
2189  }
2190 
2191  ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
2192 
2193  if (sd->desc.cmd == SDT_STRING) {
2194  IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
2195  } else {
2196  if (sd->desc.cmd == SDT_BOOLX) {
2197  seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off");
2198  } else {
2199  seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
2200  }
2201 
2202  IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)",
2203  name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max);
2204  }
2205 }
2206 
2212 void IConsoleListSettings(const char *prefilter)
2213 {
2214  IConsolePrintF(CC_WARNING, "All settings with their current value:");
2215 
2216  for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
2217  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2218  if (prefilter != nullptr && strstr(sd->desc.name, prefilter) == nullptr) continue;
2219  char value[80];
2220  const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
2221 
2222  if (sd->desc.cmd == SDT_BOOLX) {
2223  seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off");
2224  } else if (sd->desc.cmd == SDT_STRING) {
2225  seprintf(value, lastof(value), "%s", (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
2226  } else {
2227  seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
2228  }
2229  IConsolePrintF(CC_DEFAULT, "%s = %s", sd->desc.name, value);
2230  }
2231 
2232  IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
2233 }
2234 
2241 static void LoadSettings(const SettingDesc *osd, void *object)
2242 {
2243  for (; osd->save.cmd != SL_END; osd++) {
2244  const SaveLoad *sld = &osd->save;
2245  void *ptr = GetVariableAddress(object, sld);
2246 
2247  if (!SlObjectMember(ptr, sld)) continue;
2248  if (IsNumericType(sld->conv)) Write_ValidateSetting(ptr, osd, ReadValue(ptr, sld->conv));
2249  }
2250 }
2251 
2258 static void SaveSettings(const SettingDesc *sd, void *object)
2259 {
2260  /* We need to write the CH_RIFF header, but unfortunately can't call
2261  * SlCalcLength() because we have a different format. So do this manually */
2262  const SettingDesc *i;
2263  size_t length = 0;
2264  for (i = sd; i->save.cmd != SL_END; i++) {
2265  length += SlCalcObjMemberLength(object, &i->save);
2266  }
2267  SlSetLength(length);
2268 
2269  for (i = sd; i->save.cmd != SL_END; i++) {
2270  void *ptr = GetVariableAddress(object, &i->save);
2271  SlObjectMember(ptr, &i->save);
2272  }
2273 }
2274 
2275 static void Load_OPTS()
2276 {
2277  /* Copy over default setting since some might not get loaded in
2278  * a networking environment. This ensures for example that the local
2279  * autosave-frequency stays when joining a network-server */
2281  LoadSettings(_gameopt_settings, &_settings_game);
2282  HandleOldDiffCustom(true);
2283 }
2284 
2285 static void Load_PATS()
2286 {
2287  /* Copy over default setting since some might not get loaded in
2288  * a networking environment. This ensures for example that the local
2289  * currency setting stays when joining a network-server */
2290  LoadSettings(_settings, &_settings_game);
2291 }
2292 
2293 static void Check_PATS()
2294 {
2295  LoadSettings(_settings, &_load_check_data.settings);
2296 }
2297 
2298 static void Save_PATS()
2299 {
2300  SaveSettings(_settings, &_settings_game);
2301 }
2302 
2303 extern const ChunkHandler _setting_chunk_handlers[] = {
2304  { 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_RIFF},
2305  { 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF | CH_LAST},
2306 };
2307 
2308 static bool IsSignedVarMemType(VarType vt)
2309 {
2310  switch (GetVarMemType(vt)) {
2311  case SLE_VAR_I8:
2312  case SLE_VAR_I16:
2313  case SLE_VAR_I32:
2314  case SLE_VAR_I64:
2315  return true;
2316  }
2317  return false;
2318 }
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:1272
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:255
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:526
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:78
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:3319
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:564
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:3454
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:490
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:452
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:754
InvalidateCompanyWindow
static bool InvalidateCompanyWindow(int32 p1)
Invalidate the company details window after the shares setting changed.
Definition: settings.cpp:1188
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:3505
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:1045
SaveSettings
static void SaveSettings(const SettingDesc *sd, void *object)
Save and load handler for settings.
Definition: settings.cpp:2258
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:1195
SetDefaultCompanySettings
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Definition: settings.cpp:2026
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:46
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:80
_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:110
SettingDesc::GetType
SettingType GetType() const
Return the type of the setting.
Definition: settings.cpp:834
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:1777
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:819
RedrawSmallmap
static bool RedrawSmallmap(int32 p1)
Redraw the smallmap after a colour scheme change.
Definition: settings.cpp:877
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:82
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:547
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:451
void_map.h
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:542
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:449
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:414
NetworkUpdateClientName
void NetworkUpdateClientName()
Send the server our name.
Definition: network_client.cpp:1260
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:81
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:524
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:63
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:99
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:379
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
SaveLoad::conv
VarType conv
type of the variable to be saved, int
Definition: saveload.h:523
_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:533
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:492
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:809
SLF_HEX
@ SLF_HEX
print numbers as hex in the config file (only useful for unsigned)
Definition: saveload.h:495
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:96
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:548
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:1679
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:589
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:840
LoadSettings
static void LoadSettings(const SettingDesc *osd, void *object)
Save and load handler for settings.
Definition: settings.cpp:2241
SLE_VAR_STRB
@ SLE_VAR_STRB
string (with pre-allocated buffer)
Definition: saveload.h:450
IsNumericType
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
Definition: saveload.h:883
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:79
PositionStatusbar
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Definition: window.cpp:3516
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:94
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:1515
UpdateAllTownVirtCoords
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
Definition: town_cmd.cpp:411
GetGRFPresetList
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
Definition: settings.cpp:1800
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3527
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:491
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:254
CommandCost
Common return value for all commands.
Definition: command_type.h:23
SettingDescBase
Properties of config file settings.
Definition: settings_internal.h:91
InvalidateCompanyInfrastructureWindow
static bool InvalidateCompanyInfrastructureWindow(int32 p1)
Invalidate the company infrastructure details window after a infrastructure maintenance setting chang...
Definition: settings.cpp:1177
LoadFromConfig
void LoadFromConfig(bool minimal)
Load the values from the configuration files.
Definition: settings.cpp:1747
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:780
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:97
GfxClearSpriteCache
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Definition: spritecache.cpp:950
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:1406
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:47
GetCompanySettingIndex
uint GetCompanySettingIndex(const char *name)
Get the index in the _company_settings array of a setting.
Definition: settings.cpp:2057
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:850
SaveLoad::cmd
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
Definition: saveload.h:522
_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:557
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:45
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:2039
SettingDescBase::def
const void * def
default value given when none is present
Definition: settings_internal.h:93
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:1417
SetCompanySetting
void SetCompanySetting(uint index, int32 value)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:2011
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:66
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:821
GameSettings
All settings together for the game.
Definition: settings_type.h:546
GetSettingFromName
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2099
_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:1135
DeleteGRFPresetFromConfig
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
Definition: settings.cpp:1855
ErrorMessageData
The data of the error message.
Definition: error.h:29
VehicleDefaultSettings
Default settings for vehicles.
Definition: settings_type.h:528
EconomySettings::found_town
TownFounding found_town
town founding.
Definition: settings_type.h:490
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:155
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:1166
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:172
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:848
LoadGRFPresetFromConfig
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
Definition: settings.cpp:1820
pathfinder_type.h
SettingDescBase::flags
SettingGuiFlag flags
handles how a setting would show up in the GUI (text/currency, etc.)
Definition: settings_internal.h:95
WriteValue
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
Definition: saveload.cpp:773
IniLoadSettings
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
Load values from a group of an IniFile structure into the internal representation.
Definition: settings.cpp:505
sound_driver.hpp
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:109
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:46
CheckRoadSide
static bool CheckRoadSide(int p1)
Check whether the road side may be changed.
Definition: settings.cpp:1233
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:2212
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:1246
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:1981
VehicleDefaultSettings::servint_trains
uint16 servint_trains
service interval for trains
Definition: settings_type.h:530
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:108
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:451
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:285
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:862
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:1146
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:3337
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:446
SaveVersionInConfig
static void SaveVersionInConfig(IniFile *ini)
Save the version of OpenTTD to the ini file.
Definition: settings.cpp:1678
DecodeHexNibble
static int DecodeHexNibble(char c)
Convert a character to a hex nibble value, or -1 otherwise.
Definition: settings.cpp:1499
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:532
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:1315
SLF_NOT_IN_CONFIG
@ SLF_NOT_IN_CONFIG
do not save to config file
Definition: saveload.h:491
RoadVehSlopeSteepnessChanged
static bool RoadVehSlopeSteepnessChanged(int32 p1)
This function updates the road vehicle acceleration cache after a steepness change.
Definition: settings.cpp:1082
SettingDesc::desc
SettingDescBase desc
Settings structure (going to configuration file)
Definition: settings_internal.h:109
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:442
SaveLoad::version_from
SaveLoadVersion version_from
save/load the variable starting from this savegame version
Definition: saveload.h:525
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:453
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:1933
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:2179
network.h
VehicleDefaultSettings::servint_ispercent
bool servint_ispercent
service intervals are in percents
Definition: settings_type.h:529
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:377
_network_ban_list
StringList _network_ban_list
The banned clients.
Definition: network.cpp:65
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1610
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:566
v_PositionMainToolbar
static bool v_PositionMainToolbar(int32 p1)
Reposition the main toolbar as the setting changed.
Definition: settings.cpp:843
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:1884
VehicleDefaultSettings::servint_roadveh
uint16 servint_roadveh
service interval for road vehicles
Definition: settings_type.h:531
SettingDescBase::name
const char * name
name of the setting. Used in configuration file and for console
Definition: settings_internal.h:92
SettingDescBase::proc
OnChange * proc
callback procedure for when the value is changed
Definition: settings_internal.h:103
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:567
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3538
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:758
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:556
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:460
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:1967
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:104
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
_network_host_list
StringList _network_host_list
The servers we know.
Definition: network.cpp:64
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:45
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:469
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:520
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:3246
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:369
ini_type.h
GetVariableAddress
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Definition: saveload.h:894
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:393
_settings_error_list
static ErrorList _settings_error_list
Errors while loading minimal settings.
Definition: settings.cpp:86
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:1839
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
IniSaveSettings
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
Save the values of settings to the inifile.
Definition: settings.cpp:615
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:565
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:25
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:1059
_grfconfig_newgame
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
Definition: newgrf_config.cpp:171
GRFLoadConfig
static GRFConfig * GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
Load a GRF configuration.
Definition: settings.cpp:1534
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:798