OpenTTD
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 "currency.h"
26 #include "screenshot.h"
27 #include "network/network.h"
28 #include "network/network_func.h"
29 #include "settings_internal.h"
30 #include "command_func.h"
31 #include "console_func.h"
33 #include "genworld.h"
34 #include "train.h"
35 #include "news_func.h"
36 #include "window_func.h"
37 #include "sound_func.h"
38 #include "company_func.h"
39 #include "rev.h"
40 #if defined(WITH_FREETYPE) || defined(_WIN32)
41 #include "fontcache.h"
42 #endif
43 #include "textbuf_gui.h"
44 #include "rail_gui.h"
45 #include "elrail_func.h"
46 #include "error.h"
47 #include "town.h"
48 #include "video/video_driver.hpp"
49 #include "sound/sound_driver.hpp"
50 #include "music/music_driver.hpp"
51 #include "blitter/factory.hpp"
52 #include "base_media_base.h"
53 #include "gamelog.h"
54 #include "settings_func.h"
55 #include "ini_type.h"
56 #include "ai/ai_config.hpp"
57 #include "ai/ai.hpp"
58 #include "game/game_config.hpp"
59 #include "game/game.hpp"
60 #include "ship.h"
61 #include "smallmap_gui.h"
62 #include "roadveh.h"
63 #include "fios.h"
64 #include "strings_func.h"
65 
66 #include "void_map.h"
67 #include "station_base.h"
68 
69 #if defined(WITH_FREETYPE) || defined(_WIN32)
70 #define HAS_TRUETYPE_FONT
71 #endif
72 
73 #include "table/strings.h"
74 #include "table/settings.h"
75 
76 #include "safeguards.h"
77 
82 char *_config_file;
83 
84 typedef std::list<ErrorMessageData> ErrorList;
86 
87 
88 typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
89 typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
90 
91 static bool IsSignedVarMemType(VarType vt);
92 
96 static const char * const _list_group_names[] = {
97  "bans",
98  "newgrf",
99  "servers",
100  "server_bind_addresses",
101  nullptr
102 };
103 
111 static size_t LookupOneOfMany(const char *many, const char *one, size_t onelen = 0)
112 {
113  const char *s;
114  size_t idx;
115 
116  if (onelen == 0) onelen = strlen(one);
117 
118  /* check if it's an integer */
119  if (*one >= '0' && *one <= '9') return strtoul(one, nullptr, 0);
120 
121  idx = 0;
122  for (;;) {
123  /* find end of item */
124  s = many;
125  while (*s != '|' && *s != 0) s++;
126  if ((size_t)(s - many) == onelen && !memcmp(one, many, onelen)) return idx;
127  if (*s == 0) return (size_t)-1;
128  many = s + 1;
129  idx++;
130  }
131 }
132 
140 static size_t LookupManyOfMany(const char *many, const char *str)
141 {
142  const char *s;
143  size_t r;
144  size_t res = 0;
145 
146  for (;;) {
147  /* skip "whitespace" */
148  while (*str == ' ' || *str == '\t' || *str == '|') str++;
149  if (*str == 0) break;
150 
151  s = str;
152  while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++;
153 
154  r = LookupOneOfMany(many, str, s - str);
155  if (r == (size_t)-1) return r;
156 
157  SetBit(res, (uint8)r); // value found, set it
158  if (*s == 0) break;
159  str = s + 1;
160  }
161  return res;
162 }
163 
172 static int ParseIntList(const char *p, int *items, int maxitems)
173 {
174  int n = 0; // number of items read so far
175  bool comma = false; // do we accept comma?
176 
177  while (*p != '\0') {
178  switch (*p) {
179  case ',':
180  /* Do not accept multiple commas between numbers */
181  if (!comma) return -1;
182  comma = false;
183  FALLTHROUGH;
184 
185  case ' ':
186  p++;
187  break;
188 
189  default: {
190  if (n == maxitems) return -1; // we don't accept that many numbers
191  char *end;
192  long v = strtol(p, &end, 0);
193  if (p == end) return -1; // invalid character (not a number)
194  if (sizeof(int) < sizeof(long)) v = ClampToI32(v);
195  items[n++] = v;
196  p = end; // first non-number
197  comma = true; // we accept comma now
198  break;
199  }
200  }
201  }
202 
203  /* If we have read comma but no number after it, fail.
204  * We have read comma when (n != 0) and comma is not allowed */
205  if (n != 0 && !comma) return -1;
206 
207  return n;
208 }
209 
218 static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
219 {
220  int items[64];
221  int i, nitems;
222 
223  if (str == nullptr) {
224  memset(items, 0, sizeof(items));
225  nitems = nelems;
226  } else {
227  nitems = ParseIntList(str, items, lengthof(items));
228  if (nitems != nelems) return false;
229  }
230 
231  switch (type) {
232  case SLE_VAR_BL:
233  case SLE_VAR_I8:
234  case SLE_VAR_U8:
235  for (i = 0; i != nitems; i++) ((byte*)array)[i] = items[i];
236  break;
237 
238  case SLE_VAR_I16:
239  case SLE_VAR_U16:
240  for (i = 0; i != nitems; i++) ((uint16*)array)[i] = items[i];
241  break;
242 
243  case SLE_VAR_I32:
244  case SLE_VAR_U32:
245  for (i = 0; i != nitems; i++) ((uint32*)array)[i] = items[i];
246  break;
247 
248  default: NOT_REACHED();
249  }
250 
251  return true;
252 }
253 
263 static void MakeIntList(char *buf, const char *last, const void *array, int nelems, VarType type)
264 {
265  int i, v = 0;
266  const byte *p = (const byte *)array;
267 
268  for (i = 0; i != nelems; i++) {
269  switch (type) {
270  case SLE_VAR_BL:
271  case SLE_VAR_I8: v = *(const int8 *)p; p += 1; break;
272  case SLE_VAR_U8: v = *(const uint8 *)p; p += 1; break;
273  case SLE_VAR_I16: v = *(const int16 *)p; p += 2; break;
274  case SLE_VAR_U16: v = *(const uint16 *)p; p += 2; break;
275  case SLE_VAR_I32: v = *(const int32 *)p; p += 4; break;
276  case SLE_VAR_U32: v = *(const uint32 *)p; p += 4; break;
277  default: NOT_REACHED();
278  }
279  buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
280  }
281 }
282 
290 static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
291 {
292  int orig_id = id;
293 
294  /* Look for the id'th element */
295  while (--id >= 0) {
296  for (; *many != '|'; many++) {
297  if (*many == '\0') { // not found
298  seprintf(buf, last, "%d", orig_id);
299  return;
300  }
301  }
302  many++; // pass the |-character
303  }
304 
305  /* copy string until next item (|) or the end of the list if this is the last one */
306  while (*many != '\0' && *many != '|' && buf < last) *buf++ = *many++;
307  *buf = '\0';
308 }
309 
318 static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
319 {
320  const char *start;
321  int i = 0;
322  bool init = true;
323 
324  for (; x != 0; x >>= 1, i++) {
325  start = many;
326  while (*many != 0 && *many != '|') many++; // advance to the next element
327 
328  if (HasBit(x, 0)) { // item found, copy it
329  if (!init) buf += seprintf(buf, last, "|");
330  init = false;
331  if (start == many) {
332  buf += seprintf(buf, last, "%d", i);
333  } else {
334  memcpy(buf, start, many - start);
335  buf += many - start;
336  }
337  }
338 
339  if (*many == '|') many++;
340  }
341 
342  *buf = '\0';
343 }
344 
351 static const void *StringToVal(const SettingDescBase *desc, const char *orig_str)
352 {
353  const char *str = orig_str == nullptr ? "" : orig_str;
354 
355  switch (desc->cmd) {
356  case SDT_NUMX: {
357  char *end;
358  size_t val = strtoul(str, &end, 0);
359  if (end == str) {
360  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
361  msg.SetDParamStr(0, str);
362  msg.SetDParamStr(1, desc->name);
363  _settings_error_list.push_back(msg);
364  return desc->def;
365  }
366  if (*end != '\0') {
367  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
368  msg.SetDParamStr(0, desc->name);
369  _settings_error_list.push_back(msg);
370  }
371  return (void*)val;
372  }
373 
374  case SDT_ONEOFMANY: {
375  size_t r = LookupOneOfMany(desc->many, str);
376  /* if the first attempt of conversion from string to the appropriate value fails,
377  * look if we have defined a converter from old value to new value. */
378  if (r == (size_t)-1 && desc->proc_cnvt != nullptr) r = desc->proc_cnvt(str);
379  if (r != (size_t)-1) return (void*)r; // and here goes converted value
380 
381  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
382  msg.SetDParamStr(0, str);
383  msg.SetDParamStr(1, desc->name);
384  _settings_error_list.push_back(msg);
385  return desc->def;
386  }
387 
388  case SDT_MANYOFMANY: {
389  size_t r = LookupManyOfMany(desc->many, str);
390  if (r != (size_t)-1) return (void*)r;
391  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
392  msg.SetDParamStr(0, str);
393  msg.SetDParamStr(1, desc->name);
394  _settings_error_list.push_back(msg);
395  return desc->def;
396  }
397 
398  case SDT_BOOLX: {
399  if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return (void*)true;
400  if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return (void*)false;
401 
402  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
403  msg.SetDParamStr(0, str);
404  msg.SetDParamStr(1, desc->name);
405  _settings_error_list.push_back(msg);
406  return desc->def;
407  }
408 
409  case SDT_STRING: return orig_str;
410  case SDT_INTLIST: return str;
411  default: break;
412  }
413 
414  return nullptr;
415 }
416 
426 static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
427 {
428  const SettingDescBase *sdb = &sd->desc;
429 
430  if (sdb->cmd != SDT_BOOLX &&
431  sdb->cmd != SDT_NUMX &&
432  sdb->cmd != SDT_ONEOFMANY &&
433  sdb->cmd != SDT_MANYOFMANY) {
434  return;
435  }
436 
437  /* We cannot know the maximum value of a bitset variable, so just have faith */
438  if (sdb->cmd != SDT_MANYOFMANY) {
439  /* We need to take special care of the uint32 type as we receive from the function
440  * a signed integer. While here also bail out on 64-bit settings as those are not
441  * supported. Unsigned 8 and 16-bit variables are safe since they fit into a signed
442  * 32-bit variable
443  * TODO: Support 64-bit settings/variables */
444  switch (GetVarMemType(sd->save.conv)) {
445  case SLE_VAR_NULL: return;
446  case SLE_VAR_BL:
447  case SLE_VAR_I8:
448  case SLE_VAR_U8:
449  case SLE_VAR_I16:
450  case SLE_VAR_U16:
451  case SLE_VAR_I32: {
452  /* Override the minimum value. No value below sdb->min, except special value 0 */
453  if (!(sdb->flags & SGF_0ISDISABLED) || val != 0) {
454  if (!(sdb->flags & SGF_MULTISTRING)) {
455  /* Clamp value-type setting to its valid range */
456  val = Clamp(val, sdb->min, sdb->max);
457  } else if (val < sdb->min || val > (int32)sdb->max) {
458  /* Reset invalid discrete setting (where different values change gameplay) to its default value */
459  val = (int32)(size_t)sdb->def;
460  }
461  }
462  break;
463  }
464  case SLE_VAR_U32: {
465  /* Override the minimum value. No value below sdb->min, except special value 0 */
466  uint32 uval = (uint32)val;
467  if (!(sdb->flags & SGF_0ISDISABLED) || uval != 0) {
468  if (!(sdb->flags & SGF_MULTISTRING)) {
469  /* Clamp value-type setting to its valid range */
470  uval = ClampU(uval, sdb->min, sdb->max);
471  } else if (uval < (uint)sdb->min || uval > sdb->max) {
472  /* Reset invalid discrete setting to its default value */
473  uval = (uint32)(size_t)sdb->def;
474  }
475  }
476  WriteValue(ptr, SLE_VAR_U32, (int64)uval);
477  return;
478  }
479  case SLE_VAR_I64:
480  case SLE_VAR_U64:
481  default: NOT_REACHED();
482  }
483  }
484 
485  WriteValue(ptr, sd->save.conv, (int64)val);
486 }
487 
496 static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
497 {
498  IniGroup *group;
499  IniGroup *group_def = ini->GetGroup(grpname);
500  IniItem *item;
501  const void *p;
502  void *ptr;
503  const char *s;
504 
505  for (; sd->save.cmd != SL_END; sd++) {
506  const SettingDescBase *sdb = &sd->desc;
507  const SaveLoad *sld = &sd->save;
508 
509  if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
510 
511  /* For settings.xx.yy load the settings from [xx] yy = ? */
512  s = strchr(sdb->name, '.');
513  if (s != nullptr) {
514  group = ini->GetGroup(sdb->name, s - sdb->name);
515  s++;
516  } else {
517  s = sdb->name;
518  group = group_def;
519  }
520 
521  item = group->GetItem(s, false);
522  if (item == nullptr && group != group_def) {
523  /* For settings.xx.yy load the settings from [settingss] yy = ? in case the previous
524  * did not exist (e.g. loading old config files with a [settings] section */
525  item = group_def->GetItem(s, false);
526  }
527  if (item == nullptr) {
528  /* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
529  * did not exist (e.g. loading old config files with a [yapf] section */
530  const char *sc = strchr(s, '.');
531  if (sc != nullptr) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
532  }
533 
534  p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value);
535  ptr = GetVariableAddress(object, sld);
536 
537  switch (sdb->cmd) {
538  case SDT_BOOLX: // All four are various types of (integer) numbers
539  case SDT_NUMX:
540  case SDT_ONEOFMANY:
541  case SDT_MANYOFMANY:
542  Write_ValidateSetting(ptr, sd, (int32)(size_t)p);
543  break;
544 
545  case SDT_STRING:
546  switch (GetVarMemType(sld->conv)) {
547  case SLE_VAR_STRB:
548  case SLE_VAR_STRBQ:
549  if (p != nullptr) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1);
550  break;
551 
552  case SLE_VAR_STR:
553  case SLE_VAR_STRQ:
554  free(*(char**)ptr);
555  *(char**)ptr = p == nullptr ? nullptr : stredup((const char*)p);
556  break;
557 
558  case SLE_VAR_CHAR: if (p != nullptr) *(char *)ptr = *(const char *)p; break;
559 
560  default: NOT_REACHED();
561  }
562  break;
563 
564  case SDT_INTLIST: {
565  if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
566  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
567  msg.SetDParamStr(0, sdb->name);
568  _settings_error_list.push_back(msg);
569 
570  /* Use default */
571  LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
572  } else if (sd->desc.proc_cnvt != nullptr) {
573  sd->desc.proc_cnvt((const char*)p);
574  }
575  break;
576  }
577  default: NOT_REACHED();
578  }
579  }
580 }
581 
594 static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
595 {
596  IniGroup *group_def = nullptr, *group;
597  IniItem *item;
598  char buf[512];
599  const char *s;
600  void *ptr;
601 
602  for (; sd->save.cmd != SL_END; sd++) {
603  const SettingDescBase *sdb = &sd->desc;
604  const SaveLoad *sld = &sd->save;
605 
606  /* If the setting is not saved to the configuration
607  * file, just continue with the next setting */
608  if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
609  if (sld->conv & SLF_NOT_IN_CONFIG) continue;
610 
611  /* XXX - wtf is this?? (group override?) */
612  s = strchr(sdb->name, '.');
613  if (s != nullptr) {
614  group = ini->GetGroup(sdb->name, s - sdb->name);
615  s++;
616  } else {
617  if (group_def == nullptr) group_def = ini->GetGroup(grpname);
618  s = sdb->name;
619  group = group_def;
620  }
621 
622  item = group->GetItem(s, true);
623  ptr = GetVariableAddress(object, sld);
624 
625  if (item->value != nullptr) {
626  /* check if the value is the same as the old value */
627  const void *p = StringToVal(sdb, item->value);
628 
629  /* The main type of a variable/setting is in bytes 8-15
630  * The subtype (what kind of numbers do we have there) is in 0-7 */
631  switch (sdb->cmd) {
632  case SDT_BOOLX:
633  case SDT_NUMX:
634  case SDT_ONEOFMANY:
635  case SDT_MANYOFMANY:
636  switch (GetVarMemType(sld->conv)) {
637  case SLE_VAR_BL:
638  if (*(bool*)ptr == (p != nullptr)) continue;
639  break;
640 
641  case SLE_VAR_I8:
642  case SLE_VAR_U8:
643  if (*(byte*)ptr == (byte)(size_t)p) continue;
644  break;
645 
646  case SLE_VAR_I16:
647  case SLE_VAR_U16:
648  if (*(uint16*)ptr == (uint16)(size_t)p) continue;
649  break;
650 
651  case SLE_VAR_I32:
652  case SLE_VAR_U32:
653  if (*(uint32*)ptr == (uint32)(size_t)p) continue;
654  break;
655 
656  default: NOT_REACHED();
657  }
658  break;
659 
660  default: break; // Assume the other types are always changed
661  }
662  }
663 
664  /* Value has changed, get the new value and put it into a buffer */
665  switch (sdb->cmd) {
666  case SDT_BOOLX:
667  case SDT_NUMX:
668  case SDT_ONEOFMANY:
669  case SDT_MANYOFMANY: {
670  uint32 i = (uint32)ReadValue(ptr, sld->conv);
671 
672  switch (sdb->cmd) {
673  case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break;
674  case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break;
675  case SDT_ONEOFMANY: MakeOneOfMany(buf, lastof(buf), sdb->many, i); break;
676  case SDT_MANYOFMANY: MakeManyOfMany(buf, lastof(buf), sdb->many, i); break;
677  default: NOT_REACHED();
678  }
679  break;
680  }
681 
682  case SDT_STRING:
683  switch (GetVarMemType(sld->conv)) {
684  case SLE_VAR_STRB: strecpy(buf, (char*)ptr, lastof(buf)); break;
685  case SLE_VAR_STRBQ:seprintf(buf, lastof(buf), "\"%s\"", (char*)ptr); break;
686  case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break;
687 
688  case SLE_VAR_STRQ:
689  if (*(char**)ptr == nullptr) {
690  buf[0] = '\0';
691  } else {
692  seprintf(buf, lastof(buf), "\"%s\"", *(char**)ptr);
693  }
694  break;
695 
696  case SLE_VAR_CHAR: buf[0] = *(char*)ptr; buf[1] = '\0'; break;
697  default: NOT_REACHED();
698  }
699  break;
700 
701  case SDT_INTLIST:
702  MakeIntList(buf, lastof(buf), ptr, sld->length, GetVarMemType(sld->conv));
703  break;
704 
705  default: NOT_REACHED();
706  }
707 
708  /* The value is different, that means we have to write it to the ini */
709  free(item->value);
710  item->value = stredup(buf);
711  }
712 }
713 
723 static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
724 {
725  IniGroup *group = ini->GetGroup(grpname);
726 
727  if (group == nullptr) return;
728 
729  list.clear();
730 
731  for (const IniItem *item = group->item; item != nullptr; item = item->next) {
732  if (item->name != nullptr) list.emplace_back(item->name);
733  }
734 }
735 
745 static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
746 {
747  IniGroup *group = ini->GetGroup(grpname);
748 
749  if (group == nullptr) return;
750  group->Clear();
751 
752  for (const auto &iter : list) {
753  group->GetItem(iter.c_str(), true)->SetValue("");
754  }
755 }
756 
763 void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
764 {
765  IniLoadSettings(ini, _window_settings, grpname, desc);
766 }
767 
774 void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
775 {
776  IniSaveSettings(ini, _window_settings, grpname, desc);
777 }
778 
784 bool SettingDesc::IsEditable(bool do_command) const
785 {
786  if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->desc.flags & SGF_PER_COMPANY)) return false;
787  if ((this->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
788  if ((this->desc.flags & SGF_NO_NETWORK) && _networking) return false;
789  if ((this->desc.flags & SGF_NEWGAME_ONLY) &&
790  (_game_mode == GM_NORMAL ||
791  (_game_mode == GM_EDITOR && !(this->desc.flags & SGF_SCENEDIT_TOO)))) return false;
792  return true;
793 }
794 
800 {
801  if (this->desc.flags & SGF_PER_COMPANY) return ST_COMPANY;
802  return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
803 }
804 
805 /* Begin - Callback Functions for the various settings. */
806 
808 static bool v_PositionMainToolbar(int32 p1)
809 {
810  if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
811  return true;
812 }
813 
815 static bool v_PositionStatusbar(int32 p1)
816 {
817  if (_game_mode != GM_MENU) {
818  PositionStatusbar(nullptr);
819  PositionNewsMessage(nullptr);
820  PositionNetworkChatWindow(nullptr);
821  }
822  return true;
823 }
824 
825 static bool PopulationInLabelActive(int32 p1)
826 {
828  return true;
829 }
830 
831 static bool RedrawScreen(int32 p1)
832 {
834  return true;
835 }
836 
842 static bool RedrawSmallmap(int32 p1)
843 {
844  BuildLandLegend();
847  return true;
848 }
849 
850 static bool InvalidateDetailsWindow(int32 p1)
851 {
853  return true;
854 }
855 
856 static bool StationSpreadChanged(int32 p1)
857 {
860  return true;
861 }
862 
863 static bool InvalidateBuildIndustryWindow(int32 p1)
864 {
866  return true;
867 }
868 
869 static bool CloseSignalGUI(int32 p1)
870 {
871  if (p1 == 0) {
873  }
874  return true;
875 }
876 
877 static bool InvalidateTownViewWindow(int32 p1)
878 {
880  return true;
881 }
882 
883 static bool DeleteSelectStationWindow(int32 p1)
884 {
886  return true;
887 }
888 
889 static bool UpdateConsists(int32 p1)
890 {
891  for (Train *t : Train::Iterate()) {
892  /* Update the consist of all trains so the maximum speed is set correctly. */
893  if (t->IsFrontEngine() || t->IsFreeWagon()) t->ConsistChanged(CCF_TRACK);
894  }
896  return true;
897 }
898 
899 /* Check service intervals of vehicles, p1 is value of % or day based servicing */
900 static bool CheckInterval(int32 p1)
901 {
902  bool update_vehicles;
904  if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
905  vds = &_settings_client.company.vehicle;
906  update_vehicles = false;
907  } else {
908  vds = &Company::Get(_current_company)->settings.vehicle;
909  update_vehicles = true;
910  }
911 
912  if (p1 != 0) {
913  vds->servint_trains = 50;
914  vds->servint_roadveh = 50;
915  vds->servint_aircraft = 50;
916  vds->servint_ships = 50;
917  } else {
918  vds->servint_trains = 150;
919  vds->servint_roadveh = 150;
920  vds->servint_aircraft = 100;
921  vds->servint_ships = 360;
922  }
923 
924  if (update_vehicles) {
926  for (Vehicle *v : Vehicle::Iterate()) {
927  if (v->owner == _current_company && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
928  v->SetServiceInterval(CompanyServiceInterval(c, v->type));
929  v->SetServiceIntervalIsPercent(p1 != 0);
930  }
931  }
932  }
933 
934  InvalidateDetailsWindow(0);
935 
936  return true;
937 }
938 
939 static bool UpdateInterval(VehicleType type, int32 p1)
940 {
941  bool update_vehicles;
943  if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
944  vds = &_settings_client.company.vehicle;
945  update_vehicles = false;
946  } else {
947  vds = &Company::Get(_current_company)->settings.vehicle;
948  update_vehicles = true;
949  }
950 
951  /* Test if the interval is valid */
952  uint16 interval = GetServiceIntervalClamped(p1, vds->servint_ispercent);
953  if (interval != p1) return false;
954 
955  if (update_vehicles) {
956  for (Vehicle *v : Vehicle::Iterate()) {
957  if (v->owner == _current_company && v->type == type && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
958  v->SetServiceInterval(p1);
959  }
960  }
961  }
962 
963  InvalidateDetailsWindow(0);
964 
965  return true;
966 }
967 
968 static bool UpdateIntervalTrains(int32 p1)
969 {
970  return UpdateInterval(VEH_TRAIN, p1);
971 }
972 
973 static bool UpdateIntervalRoadVeh(int32 p1)
974 {
975  return UpdateInterval(VEH_ROAD, p1);
976 }
977 
978 static bool UpdateIntervalShips(int32 p1)
979 {
980  return UpdateInterval(VEH_SHIP, p1);
981 }
982 
983 static bool UpdateIntervalAircraft(int32 p1)
984 {
985  return UpdateInterval(VEH_AIRCRAFT, p1);
986 }
987 
988 static bool TrainAccelerationModelChanged(int32 p1)
989 {
990  for (Train *t : Train::Iterate()) {
991  if (t->IsFrontEngine()) {
992  t->tcache.cached_max_curve_speed = t->GetCurveSpeedLimit();
993  t->UpdateAcceleration();
994  }
995  }
996 
997  /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
1001 
1002  return true;
1003 }
1004 
1010 static bool TrainSlopeSteepnessChanged(int32 p1)
1011 {
1012  for (Train *t : Train::Iterate()) {
1013  if (t->IsFrontEngine()) t->CargoChanged();
1014  }
1015 
1016  return true;
1017 }
1018 
1024 static bool RoadVehAccelerationModelChanged(int32 p1)
1025 {
1026  if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
1027  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1028  if (rv->IsFrontEngine()) {
1029  rv->CargoChanged();
1030  }
1031  }
1032  }
1033 
1034  /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
1038 
1039  return true;
1040 }
1041 
1047 static bool RoadVehSlopeSteepnessChanged(int32 p1)
1048 {
1049  for (RoadVehicle *rv : RoadVehicle::Iterate()) {
1050  if (rv->IsFrontEngine()) rv->CargoChanged();
1051  }
1052 
1053  return true;
1054 }
1055 
1056 static bool DragSignalsDensityChanged(int32)
1057 {
1059 
1060  return true;
1061 }
1062 
1063 static bool TownFoundingChanged(int32 p1)
1064 {
1065  if (_game_mode != GM_EDITOR && _settings_game.economy.found_town == TF_FORBIDDEN) {
1067  return true;
1068  }
1070  return true;
1071 }
1072 
1073 static bool InvalidateVehTimetableWindow(int32 p1)
1074 {
1076  return true;
1077 }
1078 
1079 static bool ZoomMinMaxChanged(int32 p1)
1080 {
1081  extern void ConstrainAllViewportsZoom();
1082  ConstrainAllViewportsZoom();
1084  if (_settings_client.gui.zoom_min > _gui_zoom) {
1085  /* Restrict GUI zoom if it is no longer available. */
1086  _gui_zoom = _settings_client.gui.zoom_min;
1087  UpdateCursorSize();
1089  }
1090  return true;
1091 }
1092 
1100 static bool InvalidateNewGRFChangeWindows(int32 p1)
1101 {
1104  ReInitAllWindows();
1105  return true;
1106 }
1107 
1108 static bool InvalidateCompanyLiveryWindow(int32 p1)
1109 {
1111  return RedrawScreen(p1);
1112 }
1113 
1114 static bool InvalidateIndustryViewWindow(int32 p1)
1115 {
1117  return true;
1118 }
1119 
1120 static bool InvalidateAISettingsWindow(int32 p1)
1121 {
1123  return true;
1124 }
1125 
1131 static bool RedrawTownAuthority(int32 p1)
1132 {
1134  return true;
1135 }
1136 
1143 {
1145  return true;
1146 }
1147 
1153 static bool InvalidateCompanyWindow(int32 p1)
1154 {
1156  return true;
1157 }
1158 
1160 static void ValidateSettings()
1161 {
1162  /* Do not allow a custom sea level with the original land generator. */
1163  if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL &&
1166  }
1167 }
1168 
1169 static bool DifficultyNoiseChange(int32 i)
1170 {
1171  if (_game_mode == GM_NORMAL) {
1173  if (_settings_game.economy.station_noise_level) {
1175  }
1176  }
1177 
1178  return true;
1179 }
1180 
1181 static bool MaxNoAIsChange(int32 i)
1182 {
1183  if (GetGameSettings().difficulty.max_no_competitors != 0 &&
1184  AI::GetInfoList()->size() == 0 &&
1185  (!_networking || _network_server)) {
1186  ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
1187  }
1188 
1190  return true;
1191 }
1192 
1198 static bool CheckRoadSide(int p1)
1199 {
1200  extern bool RoadVehiclesAreBuilt();
1201  return _game_mode == GM_MENU || !RoadVehiclesAreBuilt();
1202 }
1203 
1211 static size_t ConvertLandscape(const char *value)
1212 {
1213  /* try with the old values */
1214  return LookupOneOfMany("normal|hilly|desert|candy", value);
1215 }
1216 
1217 static bool CheckFreeformEdges(int32 p1)
1218 {
1219  if (_game_mode == GM_MENU) return true;
1220  if (p1 != 0) {
1221  for (Ship *s : Ship::Iterate()) {
1222  /* Check if there is a ship on the northern border. */
1223  if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
1224  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
1225  return false;
1226  }
1227  }
1228  for (const BaseStation *st : BaseStation::Iterate()) {
1229  /* Check if there is a non-deleted buoy on the northern border. */
1230  if (st->IsInUse() && (TileX(st->xy) == 0 || TileY(st->xy) == 0)) {
1231  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
1232  return false;
1233  }
1234  }
1235  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
1236  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
1237  } else {
1238  for (uint i = 0; i < MapMaxX(); i++) {
1239  if (TileHeight(TileXY(i, 1)) != 0) {
1240  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1241  return false;
1242  }
1243  }
1244  for (uint i = 1; i < MapMaxX(); i++) {
1245  if (!IsTileType(TileXY(i, MapMaxY() - 1), MP_WATER) || TileHeight(TileXY(1, MapMaxY())) != 0) {
1246  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1247  return false;
1248  }
1249  }
1250  for (uint i = 0; i < MapMaxY(); i++) {
1251  if (TileHeight(TileXY(1, i)) != 0) {
1252  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1253  return false;
1254  }
1255  }
1256  for (uint i = 1; i < MapMaxY(); i++) {
1257  if (!IsTileType(TileXY(MapMaxX() - 1, i), MP_WATER) || TileHeight(TileXY(MapMaxX(), i)) != 0) {
1258  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1259  return false;
1260  }
1261  }
1262  /* Make tiles at the border water again. */
1263  for (uint i = 0; i < MapMaxX(); i++) {
1264  SetTileHeight(TileXY(i, 0), 0);
1265  SetTileType(TileXY(i, 0), MP_WATER);
1266  }
1267  for (uint i = 0; i < MapMaxY(); i++) {
1268  SetTileHeight(TileXY(0, i), 0);
1269  SetTileType(TileXY(0, i), MP_WATER);
1270  }
1271  }
1273  return true;
1274 }
1275 
1280 static bool ChangeDynamicEngines(int32 p1)
1281 {
1282  if (_game_mode == GM_MENU) return true;
1283 
1285  ShowErrorMessage(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES, INVALID_STRING_ID, WL_ERROR);
1286  return false;
1287  }
1288 
1289  return true;
1290 }
1291 
1292 static bool ChangeMaxHeightLevel(int32 p1)
1293 {
1294  if (_game_mode == GM_NORMAL) return false;
1295  if (_game_mode != GM_EDITOR) return true;
1296 
1297  /* Check if at least one mountain on the map is higher than the new value.
1298  * If yes, disallow the change. */
1299  for (TileIndex t = 0; t < MapSize(); t++) {
1300  if ((int32)TileHeight(t) > p1) {
1301  ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
1302  /* Return old, unchanged value */
1303  return false;
1304  }
1305  }
1306 
1307  /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
1309 
1310  return true;
1311 }
1312 
1313 static bool StationCatchmentChanged(int32 p1)
1314 {
1317  return true;
1318 }
1319 
1320 static bool MaxVehiclesChanged(int32 p1)
1321 {
1324  return true;
1325 }
1326 
1327 static bool InvalidateShipPathCache(int32 p1)
1328 {
1329  for (Ship *s : Ship::Iterate()) {
1330  s->path.clear();
1331  }
1332  return true;
1333 }
1334 
1335 static bool UpdateClientName(int32 p1)
1336 {
1338  return true;
1339 }
1340 
1341 static bool UpdateServerPassword(int32 p1)
1342 {
1343  if (strcmp(_settings_client.network.server_password, "*") == 0) {
1344  _settings_client.network.server_password[0] = '\0';
1345  }
1346 
1347  return true;
1348 }
1349 
1350 static bool UpdateRconPassword(int32 p1)
1351 {
1352  if (strcmp(_settings_client.network.rcon_password, "*") == 0) {
1353  _settings_client.network.rcon_password[0] = '\0';
1354  }
1355 
1356  return true;
1357 }
1358 
1359 static bool UpdateClientConfigValues(int32 p1)
1360 {
1362 
1363  return true;
1364 }
1365 
1366 /* End - Callback Functions */
1367 
1372 {
1373  memset(_old_diff_custom, 0, sizeof(_old_diff_custom));
1374 }
1375 
1382 static void HandleOldDiffCustom(bool savegame)
1383 {
1384  uint options_to_load = GAME_DIFFICULTY_NUM - ((savegame && IsSavegameVersionBefore(SLV_4)) ? 1 : 0);
1385 
1386  if (!savegame) {
1387  /* If we did read to old_diff_custom, then at least one value must be non 0. */
1388  bool old_diff_custom_used = false;
1389  for (uint i = 0; i < options_to_load && !old_diff_custom_used; i++) {
1390  old_diff_custom_used = (_old_diff_custom[i] != 0);
1391  }
1392 
1393  if (!old_diff_custom_used) return;
1394  }
1395 
1396  for (uint i = 0; i < options_to_load; i++) {
1397  const SettingDesc *sd = &_settings[i];
1398  /* Skip deprecated options */
1399  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1400  void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
1401  Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
1402  }
1403 }
1404 
1405 static void AILoadConfig(IniFile *ini, const char *grpname)
1406 {
1407  IniGroup *group = ini->GetGroup(grpname);
1408  IniItem *item;
1409 
1410  /* Clean any configured AI */
1411  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1413  }
1414 
1415  /* If no group exists, return */
1416  if (group == nullptr) return;
1417 
1419  for (item = group->item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
1421 
1422  config->Change(item->name);
1423  if (!config->HasScript()) {
1424  if (strcmp(item->name, "none") != 0) {
1425  DEBUG(script, 0, "The AI by the name '%s' was no longer found, and removed from the list.", item->name);
1426  continue;
1427  }
1428  }
1429  if (item->value != nullptr) config->StringToSettings(item->value);
1430  }
1431 }
1432 
1433 static void GameLoadConfig(IniFile *ini, const char *grpname)
1434 {
1435  IniGroup *group = ini->GetGroup(grpname);
1436  IniItem *item;
1437 
1438  /* Clean any configured GameScript */
1440 
1441  /* If no group exists, return */
1442  if (group == nullptr) return;
1443 
1444  item = group->item;
1445  if (item == nullptr) return;
1446 
1448 
1449  config->Change(item->name);
1450  if (!config->HasScript()) {
1451  if (strcmp(item->name, "none") != 0) {
1452  DEBUG(script, 0, "The GameScript by the name '%s' was no longer found, and removed from the list.", item->name);
1453  return;
1454  }
1455  }
1456  if (item->value != nullptr) config->StringToSettings(item->value);
1457 }
1458 
1464 static int DecodeHexNibble(char c)
1465 {
1466  if (c >= '0' && c <= '9') return c - '0';
1467  if (c >= 'A' && c <= 'F') return c + 10 - 'A';
1468  if (c >= 'a' && c <= 'f') return c + 10 - 'a';
1469  return -1;
1470 }
1471 
1480 static bool DecodeHexText(char *pos, uint8 *dest, size_t dest_size)
1481 {
1482  while (dest_size > 0) {
1483  int hi = DecodeHexNibble(pos[0]);
1484  int lo = (hi >= 0) ? DecodeHexNibble(pos[1]) : -1;
1485  if (lo < 0) return false;
1486  *dest++ = (hi << 4) | lo;
1487  pos += 2;
1488  dest_size--;
1489  }
1490  return *pos == '|';
1491 }
1492 
1499 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
1500 {
1501  IniGroup *group = ini->GetGroup(grpname);
1502  IniItem *item;
1503  GRFConfig *first = nullptr;
1504  GRFConfig **curr = &first;
1505 
1506  if (group == nullptr) return nullptr;
1507 
1508  for (item = group->item; item != nullptr; item = item->next) {
1509  GRFConfig *c = nullptr;
1510 
1511  uint8 grfid_buf[4], md5sum[16];
1512  char *filename = item->name;
1513  bool has_grfid = false;
1514  bool has_md5sum = false;
1515 
1516  /* Try reading "<grfid>|" and on success, "<md5sum>|". */
1517  has_grfid = DecodeHexText(filename, grfid_buf, lengthof(grfid_buf));
1518  if (has_grfid) {
1519  filename += 1 + 2 * lengthof(grfid_buf);
1520  has_md5sum = DecodeHexText(filename, md5sum, lengthof(md5sum));
1521  if (has_md5sum) filename += 1 + 2 * lengthof(md5sum);
1522 
1523  uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1524  if (has_md5sum) {
1525  const GRFConfig *s = FindGRFConfig(grfid, FGCM_EXACT, md5sum);
1526  if (s != nullptr) c = new GRFConfig(*s);
1527  }
1528  if (c == nullptr && !FioCheckFileExists(filename, NEWGRF_DIR)) {
1529  const GRFConfig *s = FindGRFConfig(grfid, FGCM_NEWEST_VALID);
1530  if (s != nullptr) c = new GRFConfig(*s);
1531  }
1532  }
1533  if (c == nullptr) c = new GRFConfig(filename);
1534 
1535  /* Parse parameters */
1536  if (!StrEmpty(item->value)) {
1537  int count = ParseIntList(item->value, (int*)c->param, lengthof(c->param));
1538  if (count < 0) {
1539  SetDParamStr(0, filename);
1540  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
1541  count = 0;
1542  }
1543  c->num_params = count;
1544  }
1545 
1546  /* Check if item is valid */
1547  if (!FillGRFDetails(c, is_static) || HasBit(c->flags, GCF_INVALID)) {
1548  if (c->status == GCS_NOT_FOUND) {
1549  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1550  } else if (HasBit(c->flags, GCF_UNSAFE)) {
1551  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1552  } else if (HasBit(c->flags, GCF_SYSTEM)) {
1553  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1554  } else if (HasBit(c->flags, GCF_INVALID)) {
1555  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1556  } else {
1557  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1558  }
1559 
1560  SetDParamStr(0, StrEmpty(filename) ? item->name : filename);
1561  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_GRF, WL_CRITICAL);
1562  delete c;
1563  continue;
1564  }
1565 
1566  /* Check for duplicate GRFID (will also check for duplicate filenames) */
1567  bool duplicate = false;
1568  for (const GRFConfig *gc = first; gc != nullptr; gc = gc->next) {
1569  if (gc->ident.grfid == c->ident.grfid) {
1570  SetDParamStr(0, c->filename);
1571  SetDParamStr(1, gc->filename);
1572  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_DUPLICATE_GRFID, WL_CRITICAL);
1573  duplicate = true;
1574  break;
1575  }
1576  }
1577  if (duplicate) {
1578  delete c;
1579  continue;
1580  }
1581 
1582  /* Mark file as static to avoid saving in savegame. */
1583  if (is_static) SetBit(c->flags, GCF_STATIC);
1584 
1585  /* Add item to list */
1586  *curr = c;
1587  curr = &c->next;
1588  }
1589 
1590  return first;
1591 }
1592 
1593 static void AISaveConfig(IniFile *ini, const char *grpname)
1594 {
1595  IniGroup *group = ini->GetGroup(grpname);
1596 
1597  if (group == nullptr) return;
1598  group->Clear();
1599 
1600  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1602  const char *name;
1603  char value[1024];
1604  config->SettingsToString(value, lastof(value));
1605 
1606  if (config->HasScript()) {
1607  name = config->GetName();
1608  } else {
1609  name = "none";
1610  }
1611 
1612  IniItem *item = new IniItem(group, name);
1613  item->SetValue(value);
1614  }
1615 }
1616 
1617 static void GameSaveConfig(IniFile *ini, const char *grpname)
1618 {
1619  IniGroup *group = ini->GetGroup(grpname);
1620 
1621  if (group == nullptr) return;
1622  group->Clear();
1623 
1625  const char *name;
1626  char value[1024];
1627  config->SettingsToString(value, lastof(value));
1628 
1629  if (config->HasScript()) {
1630  name = config->GetName();
1631  } else {
1632  name = "none";
1633  }
1634 
1635  IniItem *item = new IniItem(group, name);
1636  item->SetValue(value);
1637 }
1638 
1643 static void SaveVersionInConfig(IniFile *ini)
1644 {
1645  IniGroup *group = ini->GetGroup("version");
1646 
1647  char version[9];
1648  seprintf(version, lastof(version), "%08X", _openttd_newgrf_version);
1649 
1650  const char * const versions[][2] = {
1651  { "version_string", _openttd_revision },
1652  { "version_number", version }
1653  };
1654 
1655  for (uint i = 0; i < lengthof(versions); i++) {
1656  group->GetItem(versions[i][0], true)->SetValue(versions[i][1]);
1657  }
1658 }
1659 
1660 /* Save a GRF configuration to the given group name */
1661 static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list)
1662 {
1663  ini->RemoveGroup(grpname);
1664  IniGroup *group = ini->GetGroup(grpname);
1665  const GRFConfig *c;
1666 
1667  for (c = list; c != nullptr; c = c->next) {
1668  /* Hex grfid (4 bytes in nibbles), "|", hex md5sum (16 bytes in nibbles), "|", file system path. */
1669  char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1670  char params[512];
1671  GRFBuildParamList(params, c, lastof(params));
1672 
1673  char *pos = key + seprintf(key, lastof(key), "%08X|", BSWAP32(c->ident.grfid));
1674  pos = md5sumToString(pos, lastof(key), c->ident.md5sum);
1675  seprintf(pos, lastof(key), "|%s", c->filename);
1676  group->GetItem(key, true)->SetValue(params);
1677  }
1678 }
1679 
1680 /* Common handler for saving/loading variables to the configuration file */
1681 static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool basic_settings = true, bool other_settings = true)
1682 {
1683  if (basic_settings) {
1684  proc(ini, (const SettingDesc*)_misc_settings, "misc", nullptr);
1685 #if defined(_WIN32) && !defined(DEDICATED)
1686  proc(ini, (const SettingDesc*)_win32_settings, "win32", nullptr);
1687 #endif /* _WIN32 */
1688  }
1689 
1690  if (other_settings) {
1691  proc(ini, _settings, "patches", &_settings_newgame);
1692  proc(ini, _currency_settings,"currency", &_custom_currency);
1693  proc(ini, _company_settings, "company", &_settings_client.company);
1694 
1695  proc_list(ini, "server_bind_addresses", _network_bind_list);
1696  proc_list(ini, "servers", _network_host_list);
1697  proc_list(ini, "bans", _network_ban_list);
1698  }
1699 }
1700 
1701 static IniFile *IniLoadConfig()
1702 {
1703  IniFile *ini = new IniFile(_list_group_names);
1705  return ini;
1706 }
1707 
1712 void LoadFromConfig(bool minimal)
1713 {
1714  IniFile *ini = IniLoadConfig();
1715  if (!minimal) ResetCurrencies(false); // Initialize the array of currencies, without preserving the custom one
1716 
1717  /* Load basic settings only during bootstrap, load other settings not during bootstrap */
1718  HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList, minimal, !minimal);
1719 
1720  if (!minimal) {
1721  _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
1722  _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
1723  AILoadConfig(ini, "ai_players");
1724  GameLoadConfig(ini, "game_scripts");
1725 
1727  IniLoadSettings(ini, _gameopt_settings, "gameopt", &_settings_newgame);
1728  HandleOldDiffCustom(false);
1729 
1730  ValidateSettings();
1731 
1732  /* Display scheduled errors */
1733  extern void ScheduleErrorMessage(ErrorList &datas);
1735  if (FindWindowById(WC_ERRMSG, 0) == nullptr) ShowFirstError();
1736  }
1737 
1738  delete ini;
1739 }
1740 
1743 {
1744  IniFile *ini = IniLoadConfig();
1745 
1746  /* Remove some obsolete groups. These have all been loaded into other groups. */
1747  ini->RemoveGroup("patches");
1748  ini->RemoveGroup("yapf");
1749  ini->RemoveGroup("gameopt");
1750 
1751  HandleSettingDescs(ini, IniSaveSettings, IniSaveSettingList);
1752  GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
1753  GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
1754  AISaveConfig(ini, "ai_players");
1755  GameSaveConfig(ini, "game_scripts");
1756  SaveVersionInConfig(ini);
1757  ini->SaveToDisk(_config_file);
1758  delete ini;
1759 }
1760 
1766 {
1767  StringList list;
1768 
1769  std::unique_ptr<IniFile> ini(IniLoadConfig());
1770  for (IniGroup *group = ini->group; group != nullptr; group = group->next) {
1771  if (strncmp(group->name, "preset-", 7) == 0) {
1772  list.emplace_back(group->name + 7);
1773  }
1774  }
1775 
1776  return list;
1777 }
1778 
1785 GRFConfig *LoadGRFPresetFromConfig(const char *config_name)
1786 {
1787  size_t len = strlen(config_name) + 8;
1788  char *section = (char*)alloca(len);
1789  seprintf(section, section + len - 1, "preset-%s", config_name);
1790 
1791  IniFile *ini = IniLoadConfig();
1792  GRFConfig *config = GRFLoadConfig(ini, section, false);
1793  delete ini;
1794 
1795  return config;
1796 }
1797 
1804 void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
1805 {
1806  size_t len = strlen(config_name) + 8;
1807  char *section = (char*)alloca(len);
1808  seprintf(section, section + len - 1, "preset-%s", config_name);
1809 
1810  IniFile *ini = IniLoadConfig();
1811  GRFSaveConfig(ini, section, config);
1812  ini->SaveToDisk(_config_file);
1813  delete ini;
1814 }
1815 
1820 void DeleteGRFPresetFromConfig(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  ini->RemoveGroup(section);
1828  ini->SaveToDisk(_config_file);
1829  delete ini;
1830 }
1831 
1832 const SettingDesc *GetSettingDescription(uint index)
1833 {
1834  if (index >= lengthof(_settings)) return nullptr;
1835  return &_settings[index];
1836 }
1837 
1849 CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1850 {
1851  const SettingDesc *sd = GetSettingDescription(p1);
1852 
1853  if (sd == nullptr) return CMD_ERROR;
1855 
1856  if (!sd->IsEditable(true)) return CMD_ERROR;
1857 
1858  if (flags & DC_EXEC) {
1859  void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
1860 
1861  int32 oldval = (int32)ReadValue(var, sd->save.conv);
1862  int32 newval = (int32)p2;
1863 
1864  Write_ValidateSetting(var, sd, newval);
1865  newval = (int32)ReadValue(var, sd->save.conv);
1866 
1867  if (oldval == newval) return CommandCost();
1868 
1869  if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
1870  WriteValue(var, sd->save.conv, (int64)oldval);
1871  return CommandCost();
1872  }
1873 
1874  if (sd->desc.flags & SGF_NO_NETWORK) {
1876  GamelogSetting(sd->desc.name, oldval, newval);
1878  }
1879 
1881  }
1882 
1883  return CommandCost();
1884 }
1885 
1896 CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1897 {
1898  if (p1 >= lengthof(_company_settings)) return CMD_ERROR;
1899  const SettingDesc *sd = &_company_settings[p1];
1900 
1901  if (flags & DC_EXEC) {
1903 
1904  int32 oldval = (int32)ReadValue(var, sd->save.conv);
1905  int32 newval = (int32)p2;
1906 
1907  Write_ValidateSetting(var, sd, newval);
1908  newval = (int32)ReadValue(var, sd->save.conv);
1909 
1910  if (oldval == newval) return CommandCost();
1911 
1912  if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
1913  WriteValue(var, sd->save.conv, (int64)oldval);
1914  return CommandCost();
1915  }
1916 
1918  }
1919 
1920  return CommandCost();
1921 }
1922 
1930 bool SetSettingValue(uint index, int32 value, bool force_newgame)
1931 {
1932  const SettingDesc *sd = &_settings[index];
1933  /* If an item is company-based, we do not send it over the network
1934  * (if any) to change. Also *hack*hack* we update the _newgame version
1935  * of settings because changing a company-based setting in a game also
1936  * changes its defaults. At least that is the convention we have chosen */
1937  if (sd->save.conv & SLF_NO_NETWORK_SYNC) {
1938  void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
1939  Write_ValidateSetting(var, sd, value);
1940 
1941  if (_game_mode != GM_MENU) {
1942  void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
1943  Write_ValidateSetting(var2, sd, value);
1944  }
1945  if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
1946 
1948 
1949  return true;
1950  }
1951 
1952  if (force_newgame) {
1953  void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
1954  Write_ValidateSetting(var2, sd, value);
1955  return true;
1956  }
1957 
1958  /* send non-company-based settings over the network */
1959  if (!_networking || (_networking && _network_server)) {
1960  return DoCommandP(0, index, value, CMD_CHANGE_SETTING);
1961  }
1962  return false;
1963 }
1964 
1971 void SetCompanySetting(uint index, int32 value)
1972 {
1973  const SettingDesc *sd = &_company_settings[index];
1974  if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
1975  DoCommandP(0, index, value, CMD_CHANGE_COMPANY_SETTING);
1976  } else {
1977  void *var = GetVariableAddress(&_settings_client.company, &sd->save);
1978  Write_ValidateSetting(var, sd, value);
1979  if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
1980  }
1981 }
1982 
1987 {
1988  Company *c = Company::Get(cid);
1989  const SettingDesc *sd;
1990  for (sd = _company_settings; sd->save.cmd != SL_END; sd++) {
1991  void *var = GetVariableAddress(&c->settings, &sd->save);
1992  Write_ValidateSetting(var, sd, (int32)(size_t)sd->desc.def);
1993  }
1994 }
1995 
2000 {
2001  const SettingDesc *sd;
2002  uint i = 0;
2003  for (sd = _company_settings; sd->save.cmd != SL_END; sd++, i++) {
2004  const void *old_var = GetVariableAddress(&Company::Get(_current_company)->settings, &sd->save);
2005  const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
2006  uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
2007  uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
2008  if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, nullptr, nullptr, _local_company);
2009  }
2010 }
2011 
2017 uint GetCompanySettingIndex(const char *name)
2018 {
2019  uint i;
2020  const SettingDesc *sd = GetSettingFromName(name, &i);
2021  assert(sd != nullptr && (sd->desc.flags & SGF_PER_COMPANY) != 0);
2022  return i;
2023 }
2024 
2032 bool SetSettingValue(uint index, const char *value, bool force_newgame)
2033 {
2034  const SettingDesc *sd = &_settings[index];
2035  assert(sd->save.conv & SLF_NO_NETWORK_SYNC);
2036 
2037  if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
2038  char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
2039  free(*var);
2040  *var = strcmp(value, "(null)") == 0 ? nullptr : stredup(value);
2041  } else {
2042  char *var = (char*)GetVariableAddress(nullptr, &sd->save);
2043  strecpy(var, value, &var[sd->save.length - 1]);
2044  }
2045  if (sd->desc.proc != nullptr) sd->desc.proc(0);
2046 
2047  return true;
2048 }
2049 
2057 const SettingDesc *GetSettingFromName(const char *name, uint *i)
2058 {
2059  const SettingDesc *sd;
2060 
2061  /* First check all full names */
2062  for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2063  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2064  if (strcmp(sd->desc.name, name) == 0) return sd;
2065  }
2066 
2067  /* Then check the shortcut variant of the name. */
2068  for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2069  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2070  const char *short_name = strchr(sd->desc.name, '.');
2071  if (short_name != nullptr) {
2072  short_name++;
2073  if (strcmp(short_name, name) == 0) return sd;
2074  }
2075  }
2076 
2077  if (strncmp(name, "company.", 8) == 0) name += 8;
2078  /* And finally the company-based settings */
2079  for (*i = 0, sd = _company_settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2080  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2081  if (strcmp(sd->desc.name, name) == 0) return sd;
2082  }
2083 
2084  return nullptr;
2085 }
2086 
2087 /* Those 2 functions need to be here, else we have to make some stuff non-static
2088  * and besides, it is also better to keep stuff like this at the same place */
2089 void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
2090 {
2091  uint index;
2092  const SettingDesc *sd = GetSettingFromName(name, &index);
2093 
2094  if (sd == nullptr) {
2095  IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
2096  return;
2097  }
2098 
2099  bool success;
2100  if (sd->desc.cmd == SDT_STRING) {
2101  success = SetSettingValue(index, value, force_newgame);
2102  } else {
2103  uint32 val;
2104  extern bool GetArgumentInteger(uint32 *value, const char *arg);
2105  success = GetArgumentInteger(&val, value);
2106  if (!success) {
2107  IConsolePrintF(CC_ERROR, "'%s' is not an integer.", value);
2108  return;
2109  }
2110 
2111  success = SetSettingValue(index, val, force_newgame);
2112  }
2113 
2114  if (!success) {
2115  if (_network_server) {
2116  IConsoleError("This command/variable is not available during network games.");
2117  } else {
2118  IConsoleError("This command/variable is only available to a network server.");
2119  }
2120  }
2121 }
2122 
2123 void IConsoleSetSetting(const char *name, int value)
2124 {
2125  uint index;
2126  const SettingDesc *sd = GetSettingFromName(name, &index);
2127  assert(sd != nullptr);
2128  SetSettingValue(index, value);
2129 }
2130 
2136 void IConsoleGetSetting(const char *name, bool force_newgame)
2137 {
2138  char value[20];
2139  uint index;
2140  const SettingDesc *sd = GetSettingFromName(name, &index);
2141  const void *ptr;
2142 
2143  if (sd == nullptr) {
2144  IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
2145  return;
2146  }
2147 
2148  ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
2149 
2150  if (sd->desc.cmd == SDT_STRING) {
2151  IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
2152  } else {
2153  if (sd->desc.cmd == SDT_BOOLX) {
2154  seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off");
2155  } else {
2156  seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
2157  }
2158 
2159  IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)",
2160  name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max);
2161  }
2162 }
2163 
2169 void IConsoleListSettings(const char *prefilter)
2170 {
2171  IConsolePrintF(CC_WARNING, "All settings with their current value:");
2172 
2173  for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
2174  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2175  if (prefilter != nullptr && strstr(sd->desc.name, prefilter) == nullptr) continue;
2176  char value[80];
2177  const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
2178 
2179  if (sd->desc.cmd == SDT_BOOLX) {
2180  seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off");
2181  } else if (sd->desc.cmd == SDT_STRING) {
2182  seprintf(value, lastof(value), "%s", (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
2183  } else {
2184  seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
2185  }
2186  IConsolePrintF(CC_DEFAULT, "%s = %s", sd->desc.name, value);
2187  }
2188 
2189  IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
2190 }
2191 
2198 static void LoadSettings(const SettingDesc *osd, void *object)
2199 {
2200  for (; osd->save.cmd != SL_END; osd++) {
2201  const SaveLoad *sld = &osd->save;
2202  void *ptr = GetVariableAddress(object, sld);
2203 
2204  if (!SlObjectMember(ptr, sld)) continue;
2205  if (IsNumericType(sld->conv)) Write_ValidateSetting(ptr, osd, ReadValue(ptr, sld->conv));
2206  }
2207 }
2208 
2215 static void SaveSettings(const SettingDesc *sd, void *object)
2216 {
2217  /* We need to write the CH_RIFF header, but unfortunately can't call
2218  * SlCalcLength() because we have a different format. So do this manually */
2219  const SettingDesc *i;
2220  size_t length = 0;
2221  for (i = sd; i->save.cmd != SL_END; i++) {
2222  length += SlCalcObjMemberLength(object, &i->save);
2223  }
2224  SlSetLength(length);
2225 
2226  for (i = sd; i->save.cmd != SL_END; i++) {
2227  void *ptr = GetVariableAddress(object, &i->save);
2228  SlObjectMember(ptr, &i->save);
2229  }
2230 }
2231 
2232 static void Load_OPTS()
2233 {
2234  /* Copy over default setting since some might not get loaded in
2235  * a networking environment. This ensures for example that the local
2236  * autosave-frequency stays when joining a network-server */
2238  LoadSettings(_gameopt_settings, &_settings_game);
2239  HandleOldDiffCustom(true);
2240 }
2241 
2242 static void Load_PATS()
2243 {
2244  /* Copy over default setting since some might not get loaded in
2245  * a networking environment. This ensures for example that the local
2246  * currency setting stays when joining a network-server */
2247  LoadSettings(_settings, &_settings_game);
2248 }
2249 
2250 static void Check_PATS()
2251 {
2252  LoadSettings(_settings, &_load_check_data.settings);
2253 }
2254 
2255 static void Save_PATS()
2256 {
2257  SaveSettings(_settings, &_settings_game);
2258 }
2259 
2260 extern const ChunkHandler _setting_chunk_handlers[] = {
2261  { 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_RIFF},
2262  { 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF | CH_LAST},
2263 };
2264 
2265 static bool IsSignedVarMemType(VarType vt)
2266 {
2267  switch (GetVarMemType(vt)) {
2268  case SLE_VAR_I8:
2269  case SLE_VAR_I16:
2270  case SLE_VAR_I32:
2271  case SLE_VAR_I64:
2272  return true;
2273  }
2274  return false;
2275 }
Functions related to OTTD&#39;s strings.
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Road vehicle states.
VehicleSettings vehicle
options for vehicles
static void ValidateSettings()
Checks if any settings are set to incorrect values, and sets them to correct values in that case...
Definition: settings.cpp:1160
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
A group within an ini file.
Definition: ini_type.h:36
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
Definition: settings.cpp:2136
bool _networking
are we in networking mode?
Definition: network.cpp:52
const void * def
default value given when none is present
Base of all video drivers.
Default settings for vehicles.
uint GetCompanySettingIndex(const char *name)
Get the index in the _company_settings array of a setting.
Definition: settings.cpp:2017
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:328
Select station (when joining stations); Window numbers:
Definition: window_type.h:235
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.
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:763
static void MakeVoid(TileIndex t)
Make a nice void tile ;)
Definition: void_map.h:19
SaveLoadVersion version_from
save/load the variable starting from this savegame version
Definition: saveload.h:501
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
Definition: currency.cpp:154
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition: error_gui.cpp:160
static bool DecodeHexText(char *pos, uint8 *dest, size_t dest_size)
Parse a sequence of characters (supposedly hex digits) into a sequence of bytes.
Definition: settings.cpp:1480
void BuildOwnerLegend()
Completes the array for the owned property legend.
byte land_generator
the landscape generator
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
Definition: order_cmd.cpp:1916
Saveload window; Window numbers:
Definition: window_type.h:137
GameConfig stores the configuration settings of every Game.
static GRFConfig * GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
Load a GRF configuration.
Definition: settings.cpp:1499
EconomySettings economy
settings to change the economy
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
Definition: settings.cpp:1804
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
static void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
Definition: settings.cpp:1382
bitmasked number where only ONE bit may be set
Train vehicle type.
Definition: vehicle_type.h:24
All settings together for the game.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
string (with pre-allocated buffer)
Definition: saveload.h:428
Functions to handle different currencies.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:407
Base for the train class.
Other order modifications.
Definition: vehicle_gui.h:33
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
General types related to pathfinders.
bitmasked number where MULTIPLE bits may be set
any number-type
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1130
this setting only applies to network games
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition: window.cpp:3502
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
SettingGuiFlag flags
handles how a setting would show up in the GUI (text/currency, etc.)
do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
Definition: saveload.h:470
Ship vehicle type.
Definition: vehicle_type.h:26
Functions to be called to log possibly unsafe game events.
static bool InvalidateCompanyWindow(int32 p1)
Invalidate the company details window after the shares setting changed.
Definition: settings.cpp:1153
static void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
Definition: settings.cpp:1371
Generic functions for replacing base data (graphics, sounds).
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition: genworld.h:45
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:20
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn&#39;t allocate it Action is allocated only when there is a...
Definition: gamelog.cpp:69
static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
Convert a MANYofMANY structure to a string representation.
Definition: settings.cpp:318
IniItem * item
the first item in the group
Definition: ini_type.h:39
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
Definition: settings.cpp:1785
static bool ChangeDynamicEngines(int32 p1)
Changing the setting "allow multiple NewGRF sets" is not allowed if there are vehicles.
Definition: settings.cpp:1280
GRFStatus status
NOSAVE: GRFStatus, enum.
static bool RedrawTownAuthority(int32 p1)
Update the town authority window after a town authority setting change.
Definition: settings.cpp:1131
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:425
static bool InvalidateCompanyInfrastructureWindow(int32 p1)
Invalidate the company infrastructure details window after a infrastructure maintenance setting chang...
Definition: settings.cpp:1142
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
Definition: settings.cpp:2169
Base for all sound drivers.
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
change a company setting
Definition: command_type.h:306
Build vehicle; Window numbers:
Definition: window_type.h:376
Vehicle data structure.
Definition: vehicle_base.h:210
TownFounding found_town
town founding.
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
Definition: town_cmd.cpp:408
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:24
static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
Loads all items from a &#39;grpname&#39; section into a list The list parameter can be a nullptr pointer...
Definition: settings.cpp:723
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.
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:755
the value represents a limited number of string-options (internally integer)
DifficultySettings difficulty
settings related to the difficulty
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:380
void RemoveGroup(const char *name)
Remove the group with the given name.
Definition: ini_load.cpp:177
Properties of config file settings.
do not save to config file
Definition: saveload.h:469
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:48
static const TextColour CC_DEFAULT
Default colour of the console.
Definition: console_type.h:23
IniGroup * GetGroup(const char *name, size_t len=0, bool create_new=true)
Get the group with the given name.
Definition: ini_load.cpp:154
GRF file was not found in the local cache.
Definition: newgrf_config.h:36
Functions related to world/map generation.
Stuff related to the text buffer GUI.
Functions to make screenshots.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: game_config.cpp:18
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
list of integers separated by a comma &#39;,&#39;
Common return value for all commands.
Definition: command_type.h:23
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
void SaveToConfig()
Save the values to the configuration file.
Definition: settings.cpp:1742
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:351
IniItem * next
The next item in this group.
Definition: ini_type.h:24
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Network-safe changing of settings (server-only).
Definition: settings.cpp:1849
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:426
const char * name
name of the setting. Used in configuration file and for console
OnChange * proc
callback procedure for when the value is changed
CompanySettings settings
settings specific for each company
Definition: company_base.h:127
this setting can be different for each company (saved in company struct)
struct GRFConfig * next
NOSAVE: Next item in the linked list.
this setting does not apply to network games; it may not be changed during the game ...
Forbidden.
Definition: town_type.h:94
Functions/types etc.
A single "line" in an ini file.
Definition: ini_type.h:23
const char * GetName() const
Get the name of the Script.
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:182
uint16 servint_ships
service interval for ships
static bool RedrawSmallmap(int32 p1)
Redraw the smallmap after a colour scheme change.
Definition: settings.cpp:842
static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
Load parsed string-values into an integer-array (intlist)
Definition: settings.cpp:218
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
Definition: tile_map.h:57
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
uint16 length
(conditional) length of the variable (eg. arrays) (max array size is 65536 elements) ...
Definition: saveload.h:500
Functions to read fonts from files and cache them.
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:3334
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Definition: window.cpp:3513
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:24
char * _config_file
Configuration file of OpenTTD.
Definition: settings.cpp:82
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
SaveLoad save
Internal structure (going to savegame, parts to config)
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:279
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:38
NetworkSettings network
settings related to the network
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
Definition: gamelog.cpp:481
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Definition: settings.cpp:1986
Engine preview window; Window numbers:
Definition: window_type.h:583
uint8 num_params
Number of used parameters.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
VarType conv
type of the variable to be saved, int
Definition: saveload.h:499
static void SaveVersionInConfig(IniFile *ini)
Save the version of OpenTTD to the ini file.
Definition: settings.cpp:1643
Functions related to errors.
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
Save the values of settings to the inifile.
Definition: settings.cpp:594
Error message; Window numbers:
Definition: window_type.h:103
GRF file is an openttd-internal system grf.
Definition: newgrf_config.h:22
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3524
CompanySettings company
default values for per-company settings
Information about GRF, used in the game and (part of it) in savegames.
do not save with savegame, basically client-based
Definition: saveload.h:468
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
Load a WindowDesc from config.
Definition: settings.cpp:763
VehicleDefaultSettings vehicle
default settings for vehicles
OnConvert * proc_cnvt
callback procedure when loading value mechanism fails
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
Small map; Window numbers:
Definition: window_type.h:97
bool SaveToDisk(const char *filename)
Save the Ini file&#39;s data to the disk.
Definition: ini.cpp:41
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
Definition: settings.cpp:1999
DoCommandFlag
List of flags for a command.
Definition: command_type.h:342
Functions related to setting/changing the settings.
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
void SetValue(const char *value)
Replace the current value with another value.
Definition: ini_load.cpp:47
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:78
static const char *const _list_group_names[]
Groups in openttd.cfg that are actually lists.
Definition: settings.cpp:96
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:124
void LoadFromDisk(const char *filename, Subdirectory subdir)
Load the Ini file&#39;s data from the disk.
Definition: ini_load.cpp:210
A path without any base directory.
Definition: fileio_type.h:125
Base for all music playback.
Definition of base types and functions in a cross-platform compatible way.
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Definition: gfx.cpp:1133
static size_t LookupManyOfMany(const char *many, const char *str)
Find the set-integer value MANYofMANY type in a string.
Definition: settings.cpp:140
A number of safeguards to prevent using unsafe methods.
Water tile.
Definition: tile_type.h:47
void NetworkUpdateClientName()
Send the server our name.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:80
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3535
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2057
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:45
uint8 flags
NOSAVE: GCF_Flags, bitset.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:136
void LoadFromConfig(bool minimal)
Load the values from the configuration files.
Definition: settings.cpp:1712
Console functions used outside of the console code.
GRF is unusable with this version of OpenTTD.
Definition: newgrf_config.h:29
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
Definition: error_gui.cpp:442
Company colour selection; Window numbers:
Definition: window_type.h:223
char * value
The value of this item.
Definition: ini_type.h:26
Find newest Grf, ignoring Grfs with GCF_INVALID set.
static ErrorList _settings_error_list
Errors while loading minimal settings.
Definition: settings.cpp:85
static bool RoadVehSlopeSteepnessChanged(int32 p1)
This function updates the road vehicle acceleration cache after a steepness change.
Definition: settings.cpp:1047
Vehicle timetable; Window numbers:
Definition: window_type.h:217
Found a town; Window numbers:
Definition: window_type.h:422
Basic functions/variables used all over the place.
Build station; Window numbers:
Definition: window_type.h:390
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:532
Industry view; Window numbers:
Definition: window_type.h:356
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
Definition: road_cmd.cpp:183
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information...
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:40
char rcon_password[NETWORK_PASSWORD_LENGTH]
password for rconsole (server side)
Types related to reading/writing &#39;*.ini&#39; files.
void Clear()
Clear all items in the group.
Definition: ini_load.cpp:118
static int ParseIntList(const char *p, int *items, int maxitems)
Parse an integerlist string and set each found value.
Definition: settings.cpp:172
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
Check whether the given file exists.
Definition: fileio.cpp:310
Functions related to sound.
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:1211
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
Definition: saveload.h:791
static void LoadSettings(const SettingDesc *osd, void *object)
Save and load handler for settings.
Definition: settings.cpp:2198
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1175
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
Definition: saveload.h:812
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition: station.cpp:476
All ships have this type.
Definition: ship.h:26
Handlers and description of chunk.
Definition: saveload.h:356
void SetCompanySetting(uint index, int32 value)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:1971
Subdirectory for all NewGRFs.
Definition: fileio_type.h:117
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:78
Build industry; Window numbers:
Definition: window_type.h:428
Build toolbar; Window numbers:
Definition: window_type.h:66
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
Definition: settings.cpp:1820
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
&#39;Train&#39; is either a loco or a wagon.
Definition: train.h:85
Build signal toolbar; Window numbers:
Definition: window_type.h:91
string enclosed in quotes (with pre-allocated buffer)
Definition: saveload.h:429
static bool CheckRoadSide(int p1)
Check whether the road side may be changed.
Definition: settings.cpp:1198
StringList _network_host_list
The servers we know.
Definition: network.cpp:64
static bool v_PositionStatusbar(int32 p1)
Reposition the statusbar as the setting changed.
Definition: settings.cpp:815
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1162
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition: settings.cpp:784
static int DecodeHexNibble(char c)
Convert a character to a hex nibble value, or -1 otherwise.
Definition: settings.cpp:1464
void BuildLandLegend()
(Re)build the colour tables for the legends.
byte quantity_sea_lakes
the amount of seas/lakes
Definition: settings_type.h:65
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:496
change a setting
Definition: command_type.h:305
Setting changed.
Definition: gamelog.h:21
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
Saves all items from a list into the &#39;grpname&#39; section The list parameter can be a nullptr pointer...
Definition: settings.cpp:745
execute the given command
Definition: command_type.h:344
Company infrastructure overview; Window numbers:
Definition: window_type.h:570
this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set) ...
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Definition: saveload.h:823
Smallmap GUI functions.
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:201
Functions related to companies.
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
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:263
void ReInitAllWindows()
Re-initialize all windows.
Definition: window.cpp:3451
The data of the error message.
Definition: error.h:28
Ini file that supports both loading and saving.
Definition: ini_type.h:86
static bool RoadVehAccelerationModelChanged(int32 p1)
This function updates realistic acceleration caches when the setting "Road vehicle acceleration model...
Definition: settings.cpp:1024
void NetworkServerSendConfigUpdate()
Send Config Update.
Town authority; Window numbers:
Definition: window_type.h:187
GUISettings gui
settings related to the GUI
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:527
bool station_noise_level
build new airports when the town noise level is still within accepted limits
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:57
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1531
Declarations for savegames operations.
SaveLoadVersion version_to
save/load the variable until this savegame version
Definition: saveload.h:502
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
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:777
uint16 servint_trains
service interval for trains
a value of zero means the feature is disabled
char * name
The name of this item.
Definition: ini_type.h:25
static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
Convert a ONEofMANY structure to a string representation.
Definition: settings.cpp:290
Map accessors for void tiles.
First company, same as owner.
Definition: company_type.h:22
useful to write zeros in savegame.
Definition: saveload.h:427
string pointer enclosed in quotes
Definition: saveload.h:431
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we&#39;re in the ...
GRF file is unsafe for static usage.
Definition: newgrf_config.h:23
this setting cannot be changed in a game
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
bool servint_ispercent
service intervals are in percents
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:58
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:1930
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition: genworld.h:46
void IConsoleError(const char *string)
It is possible to print error information to the console.
Definition: console.cpp:167
IniItem * GetItem(const char *name, bool create)
Get the item with the given name, and if it doesn&#39;t exist and create is true it creates a new item...
Definition: ini_load.cpp:103
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
Definition: saveload.h:498
Game setting.
Functions and types used internally for the settings configurations.
Get the newgame Script config.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:66
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
Town view; Window numbers:
Definition: window_type.h:326
char * filename
Filename - either with or without full path.
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition: settings.cpp:81
string with a pre-allocated buffer
Maximum number of companies.
Definition: company_type.h:23
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
StringList _network_ban_list
The banned clients.
Definition: network.cpp:65
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:59
uint16 servint_aircraft
service interval for aircraft
SettingType GetType() const
Return the type of the setting.
Definition: settings.cpp:799
SettingDescType cmd
various flags for the variable
const char * many
ONE/MANY_OF_MANY: string of possible values for this type.
Vehicle details; Window numbers:
Definition: window_type.h:193
Base functions for all Games.
Functions related to commands.
Network functions used by other parts of OpenTTD.
bool _network_server
network-server is active
Definition: network.cpp:53
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:45
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
header file for electrified rail specific functions
static const TextColour CC_ERROR
Colour for error lines.
Definition: console_type.h:24
Base for ships.
The original landscape generator.
Definition: genworld.h:20
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
AI settings; Window numbers:
Definition: window_type.h:168
Company setting.
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:83
Aircraft vehicle type.
Definition: vehicle_type.h:27
int32 min
minimum values
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
IniGroup * next
the next group within this file
Definition: ini_type.h:37
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
declaration of OTTD revision dependent variables
SaveLoad type struct.
Definition: saveload.h:496
uint32 param[0x80]
GRF parameters.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Base functions for all AIs.
string pointer
Definition: saveload.h:430
Base of the town class.
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
Definition: saveload.cpp:682
static bool TrainSlopeSteepnessChanged(int32 p1)
This function updates the train acceleration cache after a steepness change.
Definition: settings.cpp:1010
GameCreationSettings game_creation
settings used during the creation of a game (map)
uint16 servint_roadveh
service interval for road vehicles
Client setting.
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:111
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
StringList _network_bind_list
The addresses to bind on.
Definition: network.cpp:63
a boolean number
AIConfig stores the configuration settings of every AI.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Window functions not directly related to making/drawing windows.
SettingType
Type of settings for filtering.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
Definition: newgrf_config.h:84
Only find Grfs matching md5sum.
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script...
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change one of the per-company settings.
Definition: settings.cpp:1896
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
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.
ZoomLevel zoom_min
minimum zoom out level
void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
Save a WindowDesc to config.
Definition: settings.cpp:774
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3243
Functions related to news.
Base classes/functions for stations.
Errors (eg. saving/loading failed)
Definition: error.h:23
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
Definition: error_gui.cpp:167
Company view; Window numbers:
Definition: window_type.h:362
uint32 max
maximum values
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:44
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
Definition: saveload.cpp:779
SettingDescBase desc
Settings structure (going to configuration file)
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:48
static bool v_PositionMainToolbar(int32 p1)
Reposition the main toolbar as the setting changed.
Definition: settings.cpp:808
static bool InvalidateNewGRFChangeWindows(int32 p1)
Update any possible saveload window and delete any newgrf dialogue as its widget parts might change...
Definition: settings.cpp:1100
Base class for all station-ish types.
Factory to &#39;query&#39; all available blitters.
Game options window; Window numbers:
Definition: window_type.h:606
bool GetArgumentInteger(uint32 *value, const char *arg)
Change a string into its number representation.
Definition: console.cpp:179
All settings that are only important for the local client.
Road vehicle type.
Definition: vehicle_type.h:25
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
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:3316
Last chunk in this array.
Definition: saveload.h:391
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:36
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1462
static void SaveSettings(const SettingDesc *sd, void *object)
Save and load handler for settings.
Definition: settings.cpp:2215
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
Definition: settings.cpp:1765
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
void ShowFirstError()
Show the first error of the queue.
Definition: error_gui.cpp:345