OpenTTD
settings.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
26 #include "stdafx.h"
27 #include "currency.h"
28 #include "screenshot.h"
29 #include "network/network.h"
30 #include "network/network_func.h"
31 #include "settings_internal.h"
32 #include "command_func.h"
33 #include "console_func.h"
35 #include "genworld.h"
36 #include "train.h"
37 #include "news_func.h"
38 #include "window_func.h"
39 #include "sound_func.h"
40 #include "company_func.h"
41 #include "rev.h"
42 #if defined(WITH_FREETYPE) || defined(_WIN32)
43 #include "fontcache.h"
44 #endif
45 #include "textbuf_gui.h"
46 #include "rail_gui.h"
47 #include "elrail_func.h"
48 #include "error.h"
49 #include "town.h"
50 #include "video/video_driver.hpp"
51 #include "sound/sound_driver.hpp"
52 #include "music/music_driver.hpp"
53 #include "blitter/factory.hpp"
54 #include "base_media_base.h"
55 #include "gamelog.h"
56 #include "settings_func.h"
57 #include "ini_type.h"
58 #include "ai/ai_config.hpp"
59 #include "ai/ai.hpp"
60 #include "game/game_config.hpp"
61 #include "game/game.hpp"
62 #include "ship.h"
63 #include "smallmap_gui.h"
64 #include "roadveh.h"
65 #include "fios.h"
66 #include "strings_func.h"
67 
68 #include "void_map.h"
69 #include "station_base.h"
70 
71 #if defined(WITH_FREETYPE) || defined(_WIN32)
72 #define HAS_TRUETYPE_FONT
73 #endif
74 
75 #include "table/strings.h"
76 #include "table/settings.h"
77 
78 #include "safeguards.h"
79 
84 char *_config_file;
85 
86 typedef std::list<ErrorMessageData> ErrorList;
88 
89 
90 typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
91 typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
92 
93 static bool IsSignedVarMemType(VarType vt);
94 
98 static const char * const _list_group_names[] = {
99  "bans",
100  "newgrf",
101  "servers",
102  "server_bind_addresses",
103  nullptr
104 };
105 
113 static size_t LookupOneOfMany(const char *many, const char *one, size_t onelen = 0)
114 {
115  const char *s;
116  size_t idx;
117 
118  if (onelen == 0) onelen = strlen(one);
119 
120  /* check if it's an integer */
121  if (*one >= '0' && *one <= '9') return strtoul(one, nullptr, 0);
122 
123  idx = 0;
124  for (;;) {
125  /* find end of item */
126  s = many;
127  while (*s != '|' && *s != 0) s++;
128  if ((size_t)(s - many) == onelen && !memcmp(one, many, onelen)) return idx;
129  if (*s == 0) return (size_t)-1;
130  many = s + 1;
131  idx++;
132  }
133 }
134 
142 static size_t LookupManyOfMany(const char *many, const char *str)
143 {
144  const char *s;
145  size_t r;
146  size_t res = 0;
147 
148  for (;;) {
149  /* skip "whitespace" */
150  while (*str == ' ' || *str == '\t' || *str == '|') str++;
151  if (*str == 0) break;
152 
153  s = str;
154  while (*s != 0 && *s != ' ' && *s != '\t' && *s != '|') s++;
155 
156  r = LookupOneOfMany(many, str, s - str);
157  if (r == (size_t)-1) return r;
158 
159  SetBit(res, (uint8)r); // value found, set it
160  if (*s == 0) break;
161  str = s + 1;
162  }
163  return res;
164 }
165 
174 static int ParseIntList(const char *p, int *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  long v = strtol(p, &end, 0);
195  if (p == end) return -1; // invalid character (not a number)
196  if (sizeof(int) < sizeof(long)) v = ClampToI32(v);
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  int 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 (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  buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
282  }
283 }
284 
292 static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
293 {
294  int orig_id = id;
295 
296  /* Look for the id'th element */
297  while (--id >= 0) {
298  for (; *many != '|'; many++) {
299  if (*many == '\0') { // not found
300  seprintf(buf, last, "%d", orig_id);
301  return;
302  }
303  }
304  many++; // pass the |-character
305  }
306 
307  /* copy string until next item (|) or the end of the list if this is the last one */
308  while (*many != '\0' && *many != '|' && buf < last) *buf++ = *many++;
309  *buf = '\0';
310 }
311 
320 static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
321 {
322  const char *start;
323  int i = 0;
324  bool init = true;
325 
326  for (; x != 0; x >>= 1, i++) {
327  start = many;
328  while (*many != 0 && *many != '|') many++; // advance to the next element
329 
330  if (HasBit(x, 0)) { // item found, copy it
331  if (!init) buf += seprintf(buf, last, "|");
332  init = false;
333  if (start == many) {
334  buf += seprintf(buf, last, "%d", i);
335  } else {
336  memcpy(buf, start, many - start);
337  buf += many - start;
338  }
339  }
340 
341  if (*many == '|') many++;
342  }
343 
344  *buf = '\0';
345 }
346 
353 static const void *StringToVal(const SettingDescBase *desc, const char *orig_str)
354 {
355  const char *str = orig_str == nullptr ? "" : orig_str;
356 
357  switch (desc->cmd) {
358  case SDT_NUMX: {
359  char *end;
360  size_t val = strtoul(str, &end, 0);
361  if (end == str) {
362  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
363  msg.SetDParamStr(0, str);
364  msg.SetDParamStr(1, desc->name);
365  _settings_error_list.push_back(msg);
366  return desc->def;
367  }
368  if (*end != '\0') {
369  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
370  msg.SetDParamStr(0, desc->name);
371  _settings_error_list.push_back(msg);
372  }
373  return (void*)val;
374  }
375 
376  case SDT_ONEOFMANY: {
377  size_t r = LookupOneOfMany(desc->many, str);
378  /* if the first attempt of conversion from string to the appropriate value fails,
379  * look if we have defined a converter from old value to new value. */
380  if (r == (size_t)-1 && desc->proc_cnvt != nullptr) r = desc->proc_cnvt(str);
381  if (r != (size_t)-1) return (void*)r; // and here goes converted value
382 
383  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
384  msg.SetDParamStr(0, str);
385  msg.SetDParamStr(1, desc->name);
386  _settings_error_list.push_back(msg);
387  return desc->def;
388  }
389 
390  case SDT_MANYOFMANY: {
391  size_t r = LookupManyOfMany(desc->many, str);
392  if (r != (size_t)-1) return (void*)r;
393  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
394  msg.SetDParamStr(0, str);
395  msg.SetDParamStr(1, desc->name);
396  _settings_error_list.push_back(msg);
397  return desc->def;
398  }
399 
400  case SDT_BOOLX: {
401  if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return (void*)true;
402  if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return (void*)false;
403 
404  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
405  msg.SetDParamStr(0, str);
406  msg.SetDParamStr(1, desc->name);
407  _settings_error_list.push_back(msg);
408  return desc->def;
409  }
410 
411  case SDT_STRING: return orig_str;
412  case SDT_INTLIST: return str;
413  default: break;
414  }
415 
416  return nullptr;
417 }
418 
428 static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
429 {
430  const SettingDescBase *sdb = &sd->desc;
431 
432  if (sdb->cmd != SDT_BOOLX &&
433  sdb->cmd != SDT_NUMX &&
434  sdb->cmd != SDT_ONEOFMANY &&
435  sdb->cmd != SDT_MANYOFMANY) {
436  return;
437  }
438 
439  /* We cannot know the maximum value of a bitset variable, so just have faith */
440  if (sdb->cmd != SDT_MANYOFMANY) {
441  /* We need to take special care of the uint32 type as we receive from the function
442  * a signed integer. While here also bail out on 64-bit settings as those are not
443  * supported. Unsigned 8 and 16-bit variables are safe since they fit into a signed
444  * 32-bit variable
445  * TODO: Support 64-bit settings/variables */
446  switch (GetVarMemType(sd->save.conv)) {
447  case SLE_VAR_NULL: return;
448  case SLE_VAR_BL:
449  case SLE_VAR_I8:
450  case SLE_VAR_U8:
451  case SLE_VAR_I16:
452  case SLE_VAR_U16:
453  case SLE_VAR_I32: {
454  /* Override the minimum value. No value below sdb->min, except special value 0 */
455  if (!(sdb->flags & SGF_0ISDISABLED) || val != 0) {
456  if (!(sdb->flags & SGF_MULTISTRING)) {
457  /* Clamp value-type setting to its valid range */
458  val = Clamp(val, sdb->min, sdb->max);
459  } else if (val < sdb->min || val > (int32)sdb->max) {
460  /* Reset invalid discrete setting (where different values change gameplay) to its default value */
461  val = (int32)(size_t)sdb->def;
462  }
463  }
464  break;
465  }
466  case SLE_VAR_U32: {
467  /* Override the minimum value. No value below sdb->min, except special value 0 */
468  uint32 uval = (uint32)val;
469  if (!(sdb->flags & SGF_0ISDISABLED) || uval != 0) {
470  if (!(sdb->flags & SGF_MULTISTRING)) {
471  /* Clamp value-type setting to its valid range */
472  uval = ClampU(uval, sdb->min, sdb->max);
473  } else if (uval < (uint)sdb->min || uval > sdb->max) {
474  /* Reset invalid discrete setting to its default value */
475  uval = (uint32)(size_t)sdb->def;
476  }
477  }
478  WriteValue(ptr, SLE_VAR_U32, (int64)uval);
479  return;
480  }
481  case SLE_VAR_I64:
482  case SLE_VAR_U64:
483  default: NOT_REACHED();
484  }
485  }
486 
487  WriteValue(ptr, sd->save.conv, (int64)val);
488 }
489 
498 static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
499 {
500  IniGroup *group;
501  IniGroup *group_def = ini->GetGroup(grpname);
502  IniItem *item;
503  const void *p;
504  void *ptr;
505  const char *s;
506 
507  for (; sd->save.cmd != SL_END; sd++) {
508  const SettingDescBase *sdb = &sd->desc;
509  const SaveLoad *sld = &sd->save;
510 
511  if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
512 
513  /* For settings.xx.yy load the settings from [xx] yy = ? */
514  s = strchr(sdb->name, '.');
515  if (s != nullptr) {
516  group = ini->GetGroup(sdb->name, s - sdb->name);
517  s++;
518  } else {
519  s = sdb->name;
520  group = group_def;
521  }
522 
523  item = group->GetItem(s, false);
524  if (item == nullptr && group != group_def) {
525  /* For settings.xx.yy load the settings from [settingss] yy = ? in case the previous
526  * did not exist (e.g. loading old config files with a [settings] section */
527  item = group_def->GetItem(s, false);
528  }
529  if (item == nullptr) {
530  /* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
531  * did not exist (e.g. loading old config files with a [yapf] section */
532  const char *sc = strchr(s, '.');
533  if (sc != nullptr) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
534  }
535 
536  p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value);
537  ptr = GetVariableAddress(object, sld);
538 
539  switch (sdb->cmd) {
540  case SDT_BOOLX: // All four are various types of (integer) numbers
541  case SDT_NUMX:
542  case SDT_ONEOFMANY:
543  case SDT_MANYOFMANY:
544  Write_ValidateSetting(ptr, sd, (int32)(size_t)p);
545  break;
546 
547  case SDT_STRING:
548  switch (GetVarMemType(sld->conv)) {
549  case SLE_VAR_STRB:
550  case SLE_VAR_STRBQ:
551  if (p != nullptr) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1);
552  break;
553 
554  case SLE_VAR_STR:
555  case SLE_VAR_STRQ:
556  free(*(char**)ptr);
557  *(char**)ptr = p == nullptr ? nullptr : stredup((const char*)p);
558  break;
559 
560  case SLE_VAR_CHAR: if (p != nullptr) *(char *)ptr = *(const char *)p; break;
561 
562  default: NOT_REACHED();
563  }
564  break;
565 
566  case SDT_INTLIST: {
567  if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
568  ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
569  msg.SetDParamStr(0, sdb->name);
570  _settings_error_list.push_back(msg);
571 
572  /* Use default */
573  LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
574  } else if (sd->desc.proc_cnvt != nullptr) {
575  sd->desc.proc_cnvt((const char*)p);
576  }
577  break;
578  }
579  default: NOT_REACHED();
580  }
581  }
582 }
583 
596 static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
597 {
598  IniGroup *group_def = nullptr, *group;
599  IniItem *item;
600  char buf[512];
601  const char *s;
602  void *ptr;
603 
604  for (; sd->save.cmd != SL_END; sd++) {
605  const SettingDescBase *sdb = &sd->desc;
606  const SaveLoad *sld = &sd->save;
607 
608  /* If the setting is not saved to the configuration
609  * file, just continue with the next setting */
610  if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
611  if (sld->conv & SLF_NOT_IN_CONFIG) continue;
612 
613  /* XXX - wtf is this?? (group override?) */
614  s = strchr(sdb->name, '.');
615  if (s != nullptr) {
616  group = ini->GetGroup(sdb->name, s - sdb->name);
617  s++;
618  } else {
619  if (group_def == nullptr) group_def = ini->GetGroup(grpname);
620  s = sdb->name;
621  group = group_def;
622  }
623 
624  item = group->GetItem(s, true);
625  ptr = GetVariableAddress(object, sld);
626 
627  if (item->value != nullptr) {
628  /* check if the value is the same as the old value */
629  const void *p = StringToVal(sdb, item->value);
630 
631  /* The main type of a variable/setting is in bytes 8-15
632  * The subtype (what kind of numbers do we have there) is in 0-7 */
633  switch (sdb->cmd) {
634  case SDT_BOOLX:
635  case SDT_NUMX:
636  case SDT_ONEOFMANY:
637  case SDT_MANYOFMANY:
638  switch (GetVarMemType(sld->conv)) {
639  case SLE_VAR_BL:
640  if (*(bool*)ptr == (p != nullptr)) continue;
641  break;
642 
643  case SLE_VAR_I8:
644  case SLE_VAR_U8:
645  if (*(byte*)ptr == (byte)(size_t)p) continue;
646  break;
647 
648  case SLE_VAR_I16:
649  case SLE_VAR_U16:
650  if (*(uint16*)ptr == (uint16)(size_t)p) continue;
651  break;
652 
653  case SLE_VAR_I32:
654  case SLE_VAR_U32:
655  if (*(uint32*)ptr == (uint32)(size_t)p) continue;
656  break;
657 
658  default: NOT_REACHED();
659  }
660  break;
661 
662  default: break; // Assume the other types are always changed
663  }
664  }
665 
666  /* Value has changed, get the new value and put it into a buffer */
667  switch (sdb->cmd) {
668  case SDT_BOOLX:
669  case SDT_NUMX:
670  case SDT_ONEOFMANY:
671  case SDT_MANYOFMANY: {
672  uint32 i = (uint32)ReadValue(ptr, sld->conv);
673 
674  switch (sdb->cmd) {
675  case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break;
676  case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break;
677  case SDT_ONEOFMANY: MakeOneOfMany(buf, lastof(buf), sdb->many, i); break;
678  case SDT_MANYOFMANY: MakeManyOfMany(buf, lastof(buf), sdb->many, i); break;
679  default: NOT_REACHED();
680  }
681  break;
682  }
683 
684  case SDT_STRING:
685  switch (GetVarMemType(sld->conv)) {
686  case SLE_VAR_STRB: strecpy(buf, (char*)ptr, lastof(buf)); break;
687  case SLE_VAR_STRBQ:seprintf(buf, lastof(buf), "\"%s\"", (char*)ptr); break;
688  case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break;
689 
690  case SLE_VAR_STRQ:
691  if (*(char**)ptr == nullptr) {
692  buf[0] = '\0';
693  } else {
694  seprintf(buf, lastof(buf), "\"%s\"", *(char**)ptr);
695  }
696  break;
697 
698  case SLE_VAR_CHAR: buf[0] = *(char*)ptr; buf[1] = '\0'; break;
699  default: NOT_REACHED();
700  }
701  break;
702 
703  case SDT_INTLIST:
704  MakeIntList(buf, lastof(buf), ptr, sld->length, GetVarMemType(sld->conv));
705  break;
706 
707  default: NOT_REACHED();
708  }
709 
710  /* The value is different, that means we have to write it to the ini */
711  free(item->value);
712  item->value = stredup(buf);
713  }
714 }
715 
725 static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
726 {
727  IniGroup *group = ini->GetGroup(grpname);
728 
729  if (group == nullptr) return;
730 
731  list.clear();
732 
733  for (const IniItem *item = group->item; item != nullptr; item = item->next) {
734  if (item->name != nullptr) list.emplace_back(item->name);
735  }
736 }
737 
747 static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
748 {
749  IniGroup *group = ini->GetGroup(grpname);
750 
751  if (group == nullptr) return;
752  group->Clear();
753 
754  for (const auto &iter : list) {
755  group->GetItem(iter.c_str(), true)->SetValue("");
756  }
757 }
758 
765 void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
766 {
767  IniLoadSettings(ini, _window_settings, grpname, desc);
768 }
769 
776 void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
777 {
778  IniSaveSettings(ini, _window_settings, grpname, desc);
779 }
780 
786 bool SettingDesc::IsEditable(bool do_command) const
787 {
788  if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->desc.flags & SGF_PER_COMPANY)) return false;
789  if ((this->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
790  if ((this->desc.flags & SGF_NO_NETWORK) && _networking) return false;
791  if ((this->desc.flags & SGF_NEWGAME_ONLY) &&
792  (_game_mode == GM_NORMAL ||
793  (_game_mode == GM_EDITOR && !(this->desc.flags & SGF_SCENEDIT_TOO)))) return false;
794  return true;
795 }
796 
802 {
803  if (this->desc.flags & SGF_PER_COMPANY) return ST_COMPANY;
804  return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
805 }
806 
807 /* Begin - Callback Functions for the various settings. */
808 
810 static bool v_PositionMainToolbar(int32 p1)
811 {
812  if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
813  return true;
814 }
815 
817 static bool v_PositionStatusbar(int32 p1)
818 {
819  if (_game_mode != GM_MENU) {
820  PositionStatusbar(nullptr);
821  PositionNewsMessage(nullptr);
822  PositionNetworkChatWindow(nullptr);
823  }
824  return true;
825 }
826 
827 static bool PopulationInLabelActive(int32 p1)
828 {
830  return true;
831 }
832 
833 static bool RedrawScreen(int32 p1)
834 {
836  return true;
837 }
838 
844 static bool RedrawSmallmap(int32 p1)
845 {
846  BuildLandLegend();
849  return true;
850 }
851 
852 static bool InvalidateDetailsWindow(int32 p1)
853 {
855  return true;
856 }
857 
858 static bool StationSpreadChanged(int32 p1)
859 {
862  return true;
863 }
864 
865 static bool InvalidateBuildIndustryWindow(int32 p1)
866 {
868  return true;
869 }
870 
871 static bool CloseSignalGUI(int32 p1)
872 {
873  if (p1 == 0) {
875  }
876  return true;
877 }
878 
879 static bool InvalidateTownViewWindow(int32 p1)
880 {
882  return true;
883 }
884 
885 static bool DeleteSelectStationWindow(int32 p1)
886 {
888  return true;
889 }
890 
891 static bool UpdateConsists(int32 p1)
892 {
893  Train *t;
894  FOR_ALL_TRAINS(t) {
895  /* Update the consist of all trains so the maximum speed is set correctly. */
896  if (t->IsFrontEngine() || t->IsFreeWagon()) t->ConsistChanged(CCF_TRACK);
897  }
899  return true;
900 }
901 
902 /* Check service intervals of vehicles, p1 is value of % or day based servicing */
903 static bool CheckInterval(int32 p1)
904 {
905  bool update_vehicles;
907  if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
908  vds = &_settings_client.company.vehicle;
909  update_vehicles = false;
910  } else {
911  vds = &Company::Get(_current_company)->settings.vehicle;
912  update_vehicles = true;
913  }
914 
915  if (p1 != 0) {
916  vds->servint_trains = 50;
917  vds->servint_roadveh = 50;
918  vds->servint_aircraft = 50;
919  vds->servint_ships = 50;
920  } else {
921  vds->servint_trains = 150;
922  vds->servint_roadveh = 150;
923  vds->servint_aircraft = 100;
924  vds->servint_ships = 360;
925  }
926 
927  if (update_vehicles) {
929  Vehicle *v;
930  FOR_ALL_VEHICLES(v) {
931  if (v->owner == _current_company && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
932  v->SetServiceInterval(CompanyServiceInterval(c, v->type));
933  v->SetServiceIntervalIsPercent(p1 != 0);
934  }
935  }
936  }
937 
938  InvalidateDetailsWindow(0);
939 
940  return true;
941 }
942 
943 static bool UpdateInterval(VehicleType type, int32 p1)
944 {
945  bool update_vehicles;
947  if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
948  vds = &_settings_client.company.vehicle;
949  update_vehicles = false;
950  } else {
951  vds = &Company::Get(_current_company)->settings.vehicle;
952  update_vehicles = true;
953  }
954 
955  /* Test if the interval is valid */
956  uint16 interval = GetServiceIntervalClamped(p1, vds->servint_ispercent);
957  if (interval != p1) return false;
958 
959  if (update_vehicles) {
960  Vehicle *v;
961  FOR_ALL_VEHICLES(v) {
962  if (v->owner == _current_company && v->type == type && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
963  v->SetServiceInterval(p1);
964  }
965  }
966  }
967 
968  InvalidateDetailsWindow(0);
969 
970  return true;
971 }
972 
973 static bool UpdateIntervalTrains(int32 p1)
974 {
975  return UpdateInterval(VEH_TRAIN, p1);
976 }
977 
978 static bool UpdateIntervalRoadVeh(int32 p1)
979 {
980  return UpdateInterval(VEH_ROAD, p1);
981 }
982 
983 static bool UpdateIntervalShips(int32 p1)
984 {
985  return UpdateInterval(VEH_SHIP, p1);
986 }
987 
988 static bool UpdateIntervalAircraft(int32 p1)
989 {
990  return UpdateInterval(VEH_AIRCRAFT, p1);
991 }
992 
993 static bool TrainAccelerationModelChanged(int32 p1)
994 {
995  Train *t;
996  FOR_ALL_TRAINS(t) {
997  if (t->IsFrontEngine()) {
999  t->UpdateAcceleration();
1000  }
1001  }
1002 
1003  /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
1007 
1008  return true;
1009 }
1010 
1016 static bool TrainSlopeSteepnessChanged(int32 p1)
1017 {
1018  Train *t;
1019  FOR_ALL_TRAINS(t) {
1020  if (t->IsFrontEngine()) t->CargoChanged();
1021  }
1022 
1023  return true;
1024 }
1025 
1031 static bool RoadVehAccelerationModelChanged(int32 p1)
1032 {
1033  if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
1034  RoadVehicle *rv;
1035  FOR_ALL_ROADVEHICLES(rv) {
1036  if (rv->IsFrontEngine()) {
1037  rv->CargoChanged();
1038  }
1039  }
1040  }
1041 
1042  /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
1046 
1047  return true;
1048 }
1049 
1055 static bool RoadVehSlopeSteepnessChanged(int32 p1)
1056 {
1057  RoadVehicle *rv;
1058  FOR_ALL_ROADVEHICLES(rv) {
1059  if (rv->IsFrontEngine()) rv->CargoChanged();
1060  }
1061 
1062  return true;
1063 }
1064 
1065 static bool DragSignalsDensityChanged(int32)
1066 {
1068 
1069  return true;
1070 }
1071 
1072 static bool TownFoundingChanged(int32 p1)
1073 {
1074  if (_game_mode != GM_EDITOR && _settings_game.economy.found_town == TF_FORBIDDEN) {
1076  return true;
1077  }
1079  return true;
1080 }
1081 
1082 static bool InvalidateVehTimetableWindow(int32 p1)
1083 {
1085  return true;
1086 }
1087 
1088 static bool ZoomMinMaxChanged(int32 p1)
1089 {
1090  extern void ConstrainAllViewportsZoom();
1091  ConstrainAllViewportsZoom();
1093  if (_settings_client.gui.zoom_min > _gui_zoom) {
1094  /* Restrict GUI zoom if it is no longer available. */
1095  _gui_zoom = _settings_client.gui.zoom_min;
1096  UpdateCursorSize();
1098  }
1099  return true;
1100 }
1101 
1109 static bool InvalidateNewGRFChangeWindows(int32 p1)
1110 {
1113  ReInitAllWindows();
1114  return true;
1115 }
1116 
1117 static bool InvalidateCompanyLiveryWindow(int32 p1)
1118 {
1120  return RedrawScreen(p1);
1121 }
1122 
1123 static bool InvalidateIndustryViewWindow(int32 p1)
1124 {
1126  return true;
1127 }
1128 
1129 static bool InvalidateAISettingsWindow(int32 p1)
1130 {
1132  return true;
1133 }
1134 
1140 static bool RedrawTownAuthority(int32 p1)
1141 {
1143  return true;
1144 }
1145 
1152 {
1154  return true;
1155 }
1156 
1162 static bool InvalidateCompanyWindow(int32 p1)
1163 {
1165  return true;
1166 }
1167 
1169 static void ValidateSettings()
1170 {
1171  /* Do not allow a custom sea level with the original land generator. */
1172  if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL &&
1175  }
1176 }
1177 
1178 static bool DifficultyNoiseChange(int32 i)
1179 {
1180  if (_game_mode == GM_NORMAL) {
1182  if (_settings_game.economy.station_noise_level) {
1184  }
1185  }
1186 
1187  return true;
1188 }
1189 
1190 static bool MaxNoAIsChange(int32 i)
1191 {
1192  if (GetGameSettings().difficulty.max_no_competitors != 0 &&
1193  AI::GetInfoList()->size() == 0 &&
1194  (!_networking || _network_server)) {
1195  ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
1196  }
1197 
1199  return true;
1200 }
1201 
1207 static bool CheckRoadSide(int p1)
1208 {
1209  extern bool RoadVehiclesAreBuilt();
1210  return _game_mode == GM_MENU || !RoadVehiclesAreBuilt();
1211 }
1212 
1220 static size_t ConvertLandscape(const char *value)
1221 {
1222  /* try with the old values */
1223  return LookupOneOfMany("normal|hilly|desert|candy", value);
1224 }
1225 
1226 static bool CheckFreeformEdges(int32 p1)
1227 {
1228  if (_game_mode == GM_MENU) return true;
1229  if (p1 != 0) {
1230  Ship *s;
1231  FOR_ALL_SHIPS(s) {
1232  /* Check if there is a ship on the northern border. */
1233  if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
1234  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
1235  return false;
1236  }
1237  }
1238  BaseStation *st;
1239  FOR_ALL_BASE_STATIONS(st) {
1240  /* Check if there is a non-deleted buoy on the northern border. */
1241  if (st->IsInUse() && (TileX(st->xy) == 0 || TileY(st->xy) == 0)) {
1242  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
1243  return false;
1244  }
1245  }
1246  for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
1247  for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
1248  } else {
1249  for (uint i = 0; i < MapMaxX(); i++) {
1250  if (TileHeight(TileXY(i, 1)) != 0) {
1251  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1252  return false;
1253  }
1254  }
1255  for (uint i = 1; i < MapMaxX(); i++) {
1256  if (!IsTileType(TileXY(i, MapMaxY() - 1), MP_WATER) || TileHeight(TileXY(1, MapMaxY())) != 0) {
1257  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1258  return false;
1259  }
1260  }
1261  for (uint i = 0; i < MapMaxY(); i++) {
1262  if (TileHeight(TileXY(1, i)) != 0) {
1263  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1264  return false;
1265  }
1266  }
1267  for (uint i = 1; i < MapMaxY(); i++) {
1268  if (!IsTileType(TileXY(MapMaxX() - 1, i), MP_WATER) || TileHeight(TileXY(MapMaxX(), i)) != 0) {
1269  ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
1270  return false;
1271  }
1272  }
1273  /* Make tiles at the border water again. */
1274  for (uint i = 0; i < MapMaxX(); i++) {
1275  SetTileHeight(TileXY(i, 0), 0);
1276  SetTileType(TileXY(i, 0), MP_WATER);
1277  }
1278  for (uint i = 0; i < MapMaxY(); i++) {
1279  SetTileHeight(TileXY(0, i), 0);
1280  SetTileType(TileXY(0, i), MP_WATER);
1281  }
1282  }
1284  return true;
1285 }
1286 
1291 static bool ChangeDynamicEngines(int32 p1)
1292 {
1293  if (_game_mode == GM_MENU) return true;
1294 
1296  ShowErrorMessage(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES, INVALID_STRING_ID, WL_ERROR);
1297  return false;
1298  }
1299 
1300  return true;
1301 }
1302 
1303 static bool ChangeMaxHeightLevel(int32 p1)
1304 {
1305  if (_game_mode == GM_NORMAL) return false;
1306  if (_game_mode != GM_EDITOR) return true;
1307 
1308  /* Check if at least one mountain on the map is higher than the new value.
1309  * If yes, disallow the change. */
1310  for (TileIndex t = 0; t < MapSize(); t++) {
1311  if ((int32)TileHeight(t) > p1) {
1312  ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
1313  /* Return old, unchanged value */
1314  return false;
1315  }
1316  }
1317 
1318  /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
1320 
1321  return true;
1322 }
1323 
1324 static bool StationCatchmentChanged(int32 p1)
1325 {
1328  return true;
1329 }
1330 
1331 static bool MaxVehiclesChanged(int32 p1)
1332 {
1335  return true;
1336 }
1337 
1338 static bool InvalidateShipPathCache(int32 p1)
1339 {
1340  Ship *s;
1341  FOR_ALL_SHIPS(s) {
1342  s->path.clear();
1343  }
1344  return true;
1345 }
1346 
1347 static bool UpdateClientName(int32 p1)
1348 {
1350  return true;
1351 }
1352 
1353 static bool UpdateServerPassword(int32 p1)
1354 {
1355  if (strcmp(_settings_client.network.server_password, "*") == 0) {
1356  _settings_client.network.server_password[0] = '\0';
1357  }
1358 
1359  return true;
1360 }
1361 
1362 static bool UpdateRconPassword(int32 p1)
1363 {
1364  if (strcmp(_settings_client.network.rcon_password, "*") == 0) {
1365  _settings_client.network.rcon_password[0] = '\0';
1366  }
1367 
1368  return true;
1369 }
1370 
1371 static bool UpdateClientConfigValues(int32 p1)
1372 {
1374 
1375  return true;
1376 }
1377 
1378 /* End - Callback Functions */
1379 
1384 {
1385  memset(_old_diff_custom, 0, sizeof(_old_diff_custom));
1386 }
1387 
1394 static void HandleOldDiffCustom(bool savegame)
1395 {
1396  uint options_to_load = GAME_DIFFICULTY_NUM - ((savegame && IsSavegameVersionBefore(SLV_4)) ? 1 : 0);
1397 
1398  if (!savegame) {
1399  /* If we did read to old_diff_custom, then at least one value must be non 0. */
1400  bool old_diff_custom_used = false;
1401  for (uint i = 0; i < options_to_load && !old_diff_custom_used; i++) {
1402  old_diff_custom_used = (_old_diff_custom[i] != 0);
1403  }
1404 
1405  if (!old_diff_custom_used) return;
1406  }
1407 
1408  for (uint i = 0; i < options_to_load; i++) {
1409  const SettingDesc *sd = &_settings[i];
1410  /* Skip deprecated options */
1411  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1412  void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
1413  Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
1414  }
1415 }
1416 
1417 static void AILoadConfig(IniFile *ini, const char *grpname)
1418 {
1419  IniGroup *group = ini->GetGroup(grpname);
1420  IniItem *item;
1421 
1422  /* Clean any configured AI */
1423  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1425  }
1426 
1427  /* If no group exists, return */
1428  if (group == nullptr) return;
1429 
1431  for (item = group->item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
1433 
1434  config->Change(item->name);
1435  if (!config->HasScript()) {
1436  if (strcmp(item->name, "none") != 0) {
1437  DEBUG(script, 0, "The AI by the name '%s' was no longer found, and removed from the list.", item->name);
1438  continue;
1439  }
1440  }
1441  if (item->value != nullptr) config->StringToSettings(item->value);
1442  }
1443 }
1444 
1445 static void GameLoadConfig(IniFile *ini, const char *grpname)
1446 {
1447  IniGroup *group = ini->GetGroup(grpname);
1448  IniItem *item;
1449 
1450  /* Clean any configured GameScript */
1452 
1453  /* If no group exists, return */
1454  if (group == nullptr) return;
1455 
1456  item = group->item;
1457  if (item == nullptr) return;
1458 
1460 
1461  config->Change(item->name);
1462  if (!config->HasScript()) {
1463  if (strcmp(item->name, "none") != 0) {
1464  DEBUG(script, 0, "The GameScript by the name '%s' was no longer found, and removed from the list.", item->name);
1465  return;
1466  }
1467  }
1468  if (item->value != nullptr) config->StringToSettings(item->value);
1469 }
1470 
1476 static int DecodeHexNibble(char c)
1477 {
1478  if (c >= '0' && c <= '9') return c - '0';
1479  if (c >= 'A' && c <= 'F') return c + 10 - 'A';
1480  if (c >= 'a' && c <= 'f') return c + 10 - 'a';
1481  return -1;
1482 }
1483 
1492 static bool DecodeHexText(char *pos, uint8 *dest, size_t dest_size)
1493 {
1494  while (dest_size > 0) {
1495  int hi = DecodeHexNibble(pos[0]);
1496  int lo = (hi >= 0) ? DecodeHexNibble(pos[1]) : -1;
1497  if (lo < 0) return false;
1498  *dest++ = (hi << 4) | lo;
1499  pos += 2;
1500  dest_size--;
1501  }
1502  return *pos == '|';
1503 }
1504 
1511 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
1512 {
1513  IniGroup *group = ini->GetGroup(grpname);
1514  IniItem *item;
1515  GRFConfig *first = nullptr;
1516  GRFConfig **curr = &first;
1517 
1518  if (group == nullptr) return nullptr;
1519 
1520  for (item = group->item; item != nullptr; item = item->next) {
1521  GRFConfig *c = nullptr;
1522 
1523  uint8 grfid_buf[4], md5sum[16];
1524  char *filename = item->name;
1525  bool has_grfid = false;
1526  bool has_md5sum = false;
1527 
1528  /* Try reading "<grfid>|" and on success, "<md5sum>|". */
1529  has_grfid = DecodeHexText(filename, grfid_buf, lengthof(grfid_buf));
1530  if (has_grfid) {
1531  filename += 1 + 2 * lengthof(grfid_buf);
1532  has_md5sum = DecodeHexText(filename, md5sum, lengthof(md5sum));
1533  if (has_md5sum) filename += 1 + 2 * lengthof(md5sum);
1534 
1535  uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
1536  if (has_md5sum) {
1537  const GRFConfig *s = FindGRFConfig(grfid, FGCM_EXACT, md5sum);
1538  if (s != nullptr) c = new GRFConfig(*s);
1539  }
1540  if (c == nullptr && !FioCheckFileExists(filename, NEWGRF_DIR)) {
1541  const GRFConfig *s = FindGRFConfig(grfid, FGCM_NEWEST_VALID);
1542  if (s != nullptr) c = new GRFConfig(*s);
1543  }
1544  }
1545  if (c == nullptr) c = new GRFConfig(filename);
1546 
1547  /* Parse parameters */
1548  if (!StrEmpty(item->value)) {
1549  int count = ParseIntList(item->value, (int*)c->param, lengthof(c->param));
1550  if (count < 0) {
1551  SetDParamStr(0, filename);
1552  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
1553  count = 0;
1554  }
1555  c->num_params = count;
1556  }
1557 
1558  /* Check if item is valid */
1559  if (!FillGRFDetails(c, is_static) || HasBit(c->flags, GCF_INVALID)) {
1560  if (c->status == GCS_NOT_FOUND) {
1561  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
1562  } else if (HasBit(c->flags, GCF_UNSAFE)) {
1563  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
1564  } else if (HasBit(c->flags, GCF_SYSTEM)) {
1565  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
1566  } else if (HasBit(c->flags, GCF_INVALID)) {
1567  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
1568  } else {
1569  SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
1570  }
1571 
1572  SetDParamStr(0, StrEmpty(filename) ? item->name : filename);
1573  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_GRF, WL_CRITICAL);
1574  delete c;
1575  continue;
1576  }
1577 
1578  /* Check for duplicate GRFID (will also check for duplicate filenames) */
1579  bool duplicate = false;
1580  for (const GRFConfig *gc = first; gc != nullptr; gc = gc->next) {
1581  if (gc->ident.grfid == c->ident.grfid) {
1582  SetDParamStr(0, c->filename);
1583  SetDParamStr(1, gc->filename);
1584  ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_DUPLICATE_GRFID, WL_CRITICAL);
1585  duplicate = true;
1586  break;
1587  }
1588  }
1589  if (duplicate) {
1590  delete c;
1591  continue;
1592  }
1593 
1594  /* Mark file as static to avoid saving in savegame. */
1595  if (is_static) SetBit(c->flags, GCF_STATIC);
1596 
1597  /* Add item to list */
1598  *curr = c;
1599  curr = &c->next;
1600  }
1601 
1602  return first;
1603 }
1604 
1605 static void AISaveConfig(IniFile *ini, const char *grpname)
1606 {
1607  IniGroup *group = ini->GetGroup(grpname);
1608 
1609  if (group == nullptr) return;
1610  group->Clear();
1611 
1612  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1614  const char *name;
1615  char value[1024];
1616  config->SettingsToString(value, lastof(value));
1617 
1618  if (config->HasScript()) {
1619  name = config->GetName();
1620  } else {
1621  name = "none";
1622  }
1623 
1624  IniItem *item = new IniItem(group, name);
1625  item->SetValue(value);
1626  }
1627 }
1628 
1629 static void GameSaveConfig(IniFile *ini, const char *grpname)
1630 {
1631  IniGroup *group = ini->GetGroup(grpname);
1632 
1633  if (group == nullptr) return;
1634  group->Clear();
1635 
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 
1655 static void SaveVersionInConfig(IniFile *ini)
1656 {
1657  IniGroup *group = ini->GetGroup("version");
1658 
1659  char version[9];
1660  seprintf(version, lastof(version), "%08X", _openttd_newgrf_version);
1661 
1662  const char * const versions[][2] = {
1663  { "version_string", _openttd_revision },
1664  { "version_number", version }
1665  };
1666 
1667  for (uint i = 0; i < lengthof(versions); i++) {
1668  group->GetItem(versions[i][0], true)->SetValue(versions[i][1]);
1669  }
1670 }
1671 
1672 /* Save a GRF configuration to the given group name */
1673 static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list)
1674 {
1675  ini->RemoveGroup(grpname);
1676  IniGroup *group = ini->GetGroup(grpname);
1677  const GRFConfig *c;
1678 
1679  for (c = list; c != nullptr; c = c->next) {
1680  /* Hex grfid (4 bytes in nibbles), "|", hex md5sum (16 bytes in nibbles), "|", file system path. */
1681  char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
1682  char params[512];
1683  GRFBuildParamList(params, c, lastof(params));
1684 
1685  char *pos = key + seprintf(key, lastof(key), "%08X|", BSWAP32(c->ident.grfid));
1686  pos = md5sumToString(pos, lastof(key), c->ident.md5sum);
1687  seprintf(pos, lastof(key), "|%s", c->filename);
1688  group->GetItem(key, true)->SetValue(params);
1689  }
1690 }
1691 
1692 /* Common handler for saving/loading variables to the configuration file */
1693 static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool basic_settings = true, bool other_settings = true)
1694 {
1695  if (basic_settings) {
1696  proc(ini, (const SettingDesc*)_misc_settings, "misc", nullptr);
1697 #if defined(_WIN32) && !defined(DEDICATED)
1698  proc(ini, (const SettingDesc*)_win32_settings, "win32", nullptr);
1699 #endif /* _WIN32 */
1700  }
1701 
1702  if (other_settings) {
1703  proc(ini, _settings, "patches", &_settings_newgame);
1704  proc(ini, _currency_settings,"currency", &_custom_currency);
1705  proc(ini, _company_settings, "company", &_settings_client.company);
1706 
1707  proc_list(ini, "server_bind_addresses", _network_bind_list);
1708  proc_list(ini, "servers", _network_host_list);
1709  proc_list(ini, "bans", _network_ban_list);
1710  }
1711 }
1712 
1713 static IniFile *IniLoadConfig()
1714 {
1715  IniFile *ini = new IniFile(_list_group_names);
1717  return ini;
1718 }
1719 
1724 void LoadFromConfig(bool minimal)
1725 {
1726  IniFile *ini = IniLoadConfig();
1727  if (!minimal) ResetCurrencies(false); // Initialize the array of currencies, without preserving the custom one
1728 
1729  /* Load basic settings only during bootstrap, load other settings not during bootstrap */
1730  HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList, minimal, !minimal);
1731 
1732  if (!minimal) {
1733  _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
1734  _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
1735  AILoadConfig(ini, "ai_players");
1736  GameLoadConfig(ini, "game_scripts");
1737 
1739  IniLoadSettings(ini, _gameopt_settings, "gameopt", &_settings_newgame);
1740  HandleOldDiffCustom(false);
1741 
1742  ValidateSettings();
1743 
1744  /* Display scheduled errors */
1745  extern void ScheduleErrorMessage(ErrorList &datas);
1747  if (FindWindowById(WC_ERRMSG, 0) == nullptr) ShowFirstError();
1748  }
1749 
1750  delete ini;
1751 }
1752 
1755 {
1756  IniFile *ini = IniLoadConfig();
1757 
1758  /* Remove some obsolete groups. These have all been loaded into other groups. */
1759  ini->RemoveGroup("patches");
1760  ini->RemoveGroup("yapf");
1761  ini->RemoveGroup("gameopt");
1762 
1763  HandleSettingDescs(ini, IniSaveSettings, IniSaveSettingList);
1764  GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
1765  GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
1766  AISaveConfig(ini, "ai_players");
1767  GameSaveConfig(ini, "game_scripts");
1768  SaveVersionInConfig(ini);
1769  ini->SaveToDisk(_config_file);
1770  delete ini;
1771 }
1772 
1778 {
1779  StringList list;
1780 
1781  std::unique_ptr<IniFile> ini(IniLoadConfig());
1782  for (IniGroup *group = ini->group; group != nullptr; group = group->next) {
1783  if (strncmp(group->name, "preset-", 7) == 0) {
1784  list.emplace_back(group->name + 7);
1785  }
1786  }
1787 
1788  return list;
1789 }
1790 
1797 GRFConfig *LoadGRFPresetFromConfig(const char *config_name)
1798 {
1799  size_t len = strlen(config_name) + 8;
1800  char *section = (char*)alloca(len);
1801  seprintf(section, section + len - 1, "preset-%s", config_name);
1802 
1803  IniFile *ini = IniLoadConfig();
1804  GRFConfig *config = GRFLoadConfig(ini, section, false);
1805  delete ini;
1806 
1807  return config;
1808 }
1809 
1816 void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
1817 {
1818  size_t len = strlen(config_name) + 8;
1819  char *section = (char*)alloca(len);
1820  seprintf(section, section + len - 1, "preset-%s", config_name);
1821 
1822  IniFile *ini = IniLoadConfig();
1823  GRFSaveConfig(ini, section, config);
1824  ini->SaveToDisk(_config_file);
1825  delete ini;
1826 }
1827 
1832 void DeleteGRFPresetFromConfig(const char *config_name)
1833 {
1834  size_t len = strlen(config_name) + 8;
1835  char *section = (char*)alloca(len);
1836  seprintf(section, section + len - 1, "preset-%s", config_name);
1837 
1838  IniFile *ini = IniLoadConfig();
1839  ini->RemoveGroup(section);
1840  ini->SaveToDisk(_config_file);
1841  delete ini;
1842 }
1843 
1844 const SettingDesc *GetSettingDescription(uint index)
1845 {
1846  if (index >= lengthof(_settings)) return nullptr;
1847  return &_settings[index];
1848 }
1849 
1861 CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1862 {
1863  const SettingDesc *sd = GetSettingDescription(p1);
1864 
1865  if (sd == nullptr) return CMD_ERROR;
1867 
1868  if (!sd->IsEditable(true)) return CMD_ERROR;
1869 
1870  if (flags & DC_EXEC) {
1871  void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
1872 
1873  int32 oldval = (int32)ReadValue(var, sd->save.conv);
1874  int32 newval = (int32)p2;
1875 
1876  Write_ValidateSetting(var, sd, newval);
1877  newval = (int32)ReadValue(var, sd->save.conv);
1878 
1879  if (oldval == newval) return CommandCost();
1880 
1881  if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
1882  WriteValue(var, sd->save.conv, (int64)oldval);
1883  return CommandCost();
1884  }
1885 
1886  if (sd->desc.flags & SGF_NO_NETWORK) {
1888  GamelogSetting(sd->desc.name, oldval, newval);
1890  }
1891 
1893  }
1894 
1895  return CommandCost();
1896 }
1897 
1908 CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1909 {
1910  if (p1 >= lengthof(_company_settings)) return CMD_ERROR;
1911  const SettingDesc *sd = &_company_settings[p1];
1912 
1913  if (flags & DC_EXEC) {
1915 
1916  int32 oldval = (int32)ReadValue(var, sd->save.conv);
1917  int32 newval = (int32)p2;
1918 
1919  Write_ValidateSetting(var, sd, newval);
1920  newval = (int32)ReadValue(var, sd->save.conv);
1921 
1922  if (oldval == newval) return CommandCost();
1923 
1924  if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
1925  WriteValue(var, sd->save.conv, (int64)oldval);
1926  return CommandCost();
1927  }
1928 
1930  }
1931 
1932  return CommandCost();
1933 }
1934 
1942 bool SetSettingValue(uint index, int32 value, bool force_newgame)
1943 {
1944  const SettingDesc *sd = &_settings[index];
1945  /* If an item is company-based, we do not send it over the network
1946  * (if any) to change. Also *hack*hack* we update the _newgame version
1947  * of settings because changing a company-based setting in a game also
1948  * changes its defaults. At least that is the convention we have chosen */
1949  if (sd->save.conv & SLF_NO_NETWORK_SYNC) {
1950  void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
1951  Write_ValidateSetting(var, sd, value);
1952 
1953  if (_game_mode != GM_MENU) {
1954  void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
1955  Write_ValidateSetting(var2, sd, value);
1956  }
1957  if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
1958 
1960 
1961  return true;
1962  }
1963 
1964  if (force_newgame) {
1965  void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
1966  Write_ValidateSetting(var2, sd, value);
1967  return true;
1968  }
1969 
1970  /* send non-company-based settings over the network */
1971  if (!_networking || (_networking && _network_server)) {
1972  return DoCommandP(0, index, value, CMD_CHANGE_SETTING);
1973  }
1974  return false;
1975 }
1976 
1983 void SetCompanySetting(uint index, int32 value)
1984 {
1985  const SettingDesc *sd = &_company_settings[index];
1986  if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
1987  DoCommandP(0, index, value, CMD_CHANGE_COMPANY_SETTING);
1988  } else {
1989  void *var = GetVariableAddress(&_settings_client.company, &sd->save);
1990  Write_ValidateSetting(var, sd, value);
1991  if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
1992  }
1993 }
1994 
1999 {
2000  Company *c = Company::Get(cid);
2001  const SettingDesc *sd;
2002  for (sd = _company_settings; sd->save.cmd != SL_END; sd++) {
2003  void *var = GetVariableAddress(&c->settings, &sd->save);
2004  Write_ValidateSetting(var, sd, (int32)(size_t)sd->desc.def);
2005  }
2006 }
2007 
2012 {
2013  const SettingDesc *sd;
2014  uint i = 0;
2015  for (sd = _company_settings; sd->save.cmd != SL_END; sd++, i++) {
2016  const void *old_var = GetVariableAddress(&Company::Get(_current_company)->settings, &sd->save);
2017  const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
2018  uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
2019  uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
2020  if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, nullptr, nullptr, _local_company);
2021  }
2022 }
2023 
2029 uint GetCompanySettingIndex(const char *name)
2030 {
2031  uint i;
2032  const SettingDesc *sd = GetSettingFromName(name, &i);
2033  assert(sd != nullptr && (sd->desc.flags & SGF_PER_COMPANY) != 0);
2034  return i;
2035 }
2036 
2044 bool SetSettingValue(uint index, const char *value, bool force_newgame)
2045 {
2046  const SettingDesc *sd = &_settings[index];
2047  assert(sd->save.conv & SLF_NO_NETWORK_SYNC);
2048 
2049  if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
2050  char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
2051  free(*var);
2052  *var = strcmp(value, "(null)") == 0 ? nullptr : stredup(value);
2053  } else {
2054  char *var = (char*)GetVariableAddress(nullptr, &sd->save);
2055  strecpy(var, value, &var[sd->save.length - 1]);
2056  }
2057  if (sd->desc.proc != nullptr) sd->desc.proc(0);
2058 
2059  return true;
2060 }
2061 
2069 const SettingDesc *GetSettingFromName(const char *name, uint *i)
2070 {
2071  const SettingDesc *sd;
2072 
2073  /* First check all full names */
2074  for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2075  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2076  if (strcmp(sd->desc.name, name) == 0) return sd;
2077  }
2078 
2079  /* Then check the shortcut variant of the name. */
2080  for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2081  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2082  const char *short_name = strchr(sd->desc.name, '.');
2083  if (short_name != nullptr) {
2084  short_name++;
2085  if (strcmp(short_name, name) == 0) return sd;
2086  }
2087  }
2088 
2089  if (strncmp(name, "company.", 8) == 0) name += 8;
2090  /* And finally the company-based settings */
2091  for (*i = 0, sd = _company_settings; sd->save.cmd != SL_END; sd++, (*i)++) {
2092  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2093  if (strcmp(sd->desc.name, name) == 0) return sd;
2094  }
2095 
2096  return nullptr;
2097 }
2098 
2099 /* Those 2 functions need to be here, else we have to make some stuff non-static
2100  * and besides, it is also better to keep stuff like this at the same place */
2101 void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
2102 {
2103  uint index;
2104  const SettingDesc *sd = GetSettingFromName(name, &index);
2105 
2106  if (sd == nullptr) {
2107  IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
2108  return;
2109  }
2110 
2111  bool success;
2112  if (sd->desc.cmd == SDT_STRING) {
2113  success = SetSettingValue(index, value, force_newgame);
2114  } else {
2115  uint32 val;
2116  extern bool GetArgumentInteger(uint32 *value, const char *arg);
2117  success = GetArgumentInteger(&val, value);
2118  if (!success) {
2119  IConsolePrintF(CC_ERROR, "'%s' is not an integer.", value);
2120  return;
2121  }
2122 
2123  success = SetSettingValue(index, val, force_newgame);
2124  }
2125 
2126  if (!success) {
2127  if (_network_server) {
2128  IConsoleError("This command/variable is not available during network games.");
2129  } else {
2130  IConsoleError("This command/variable is only available to a network server.");
2131  }
2132  }
2133 }
2134 
2135 void IConsoleSetSetting(const char *name, int value)
2136 {
2137  uint index;
2138  const SettingDesc *sd = GetSettingFromName(name, &index);
2139  assert(sd != nullptr);
2140  SetSettingValue(index, value);
2141 }
2142 
2148 void IConsoleGetSetting(const char *name, bool force_newgame)
2149 {
2150  char value[20];
2151  uint index;
2152  const SettingDesc *sd = GetSettingFromName(name, &index);
2153  const void *ptr;
2154 
2155  if (sd == nullptr) {
2156  IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
2157  return;
2158  }
2159 
2160  ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
2161 
2162  if (sd->desc.cmd == SDT_STRING) {
2163  IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
2164  } else {
2165  if (sd->desc.cmd == SDT_BOOLX) {
2166  seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off");
2167  } else {
2168  seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
2169  }
2170 
2171  IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)",
2172  name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max);
2173  }
2174 }
2175 
2181 void IConsoleListSettings(const char *prefilter)
2182 {
2183  IConsolePrintF(CC_WARNING, "All settings with their current value:");
2184 
2185  for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
2186  if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
2187  if (prefilter != nullptr && strstr(sd->desc.name, prefilter) == nullptr) continue;
2188  char value[80];
2189  const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
2190 
2191  if (sd->desc.cmd == SDT_BOOLX) {
2192  seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off");
2193  } else if (sd->desc.cmd == SDT_STRING) {
2194  seprintf(value, lastof(value), "%s", (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr);
2195  } else {
2196  seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
2197  }
2198  IConsolePrintF(CC_DEFAULT, "%s = %s", sd->desc.name, value);
2199  }
2200 
2201  IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
2202 }
2203 
2210 static void LoadSettings(const SettingDesc *osd, void *object)
2211 {
2212  for (; osd->save.cmd != SL_END; osd++) {
2213  const SaveLoad *sld = &osd->save;
2214  void *ptr = GetVariableAddress(object, sld);
2215 
2216  if (!SlObjectMember(ptr, sld)) continue;
2217  if (IsNumericType(sld->conv)) Write_ValidateSetting(ptr, osd, ReadValue(ptr, sld->conv));
2218  }
2219 }
2220 
2227 static void SaveSettings(const SettingDesc *sd, void *object)
2228 {
2229  /* We need to write the CH_RIFF header, but unfortunately can't call
2230  * SlCalcLength() because we have a different format. So do this manually */
2231  const SettingDesc *i;
2232  size_t length = 0;
2233  for (i = sd; i->save.cmd != SL_END; i++) {
2234  length += SlCalcObjMemberLength(object, &i->save);
2235  }
2236  SlSetLength(length);
2237 
2238  for (i = sd; i->save.cmd != SL_END; i++) {
2239  void *ptr = GetVariableAddress(object, &i->save);
2240  SlObjectMember(ptr, &i->save);
2241  }
2242 }
2243 
2244 static void Load_OPTS()
2245 {
2246  /* Copy over default setting since some might not get loaded in
2247  * a networking environment. This ensures for example that the local
2248  * autosave-frequency stays when joining a network-server */
2250  LoadSettings(_gameopt_settings, &_settings_game);
2251  HandleOldDiffCustom(true);
2252 }
2253 
2254 static void Load_PATS()
2255 {
2256  /* Copy over default setting since some might not get loaded in
2257  * a networking environment. This ensures for example that the local
2258  * currency setting stays when joining a network-server */
2259  LoadSettings(_settings, &_settings_game);
2260 }
2261 
2262 static void Check_PATS()
2263 {
2264  LoadSettings(_settings, &_load_check_data.settings);
2265 }
2266 
2267 static void Save_PATS()
2268 {
2269  SaveSettings(_settings, &_settings_game);
2270 }
2271 
2272 extern const ChunkHandler _setting_chunk_handlers[] = {
2273  { 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_RIFF},
2274  { 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF | CH_LAST},
2275 };
2276 
2277 static bool IsSignedVarMemType(VarType vt)
2278 {
2279  switch (GetVarMemType(vt)) {
2280  case SLE_VAR_I8:
2281  case SLE_VAR_I16:
2282  case SLE_VAR_I32:
2283  case SLE_VAR_I64:
2284  return true;
2285  }
2286  return false;
2287 }
Functions related to OTTD&#39;s strings.
Owner
Enum for all companies/owners.
Definition: company_type.h:20
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:1169
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:74
A group within an ini file.
Definition: ini_type.h:38
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:81
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
Definition: settings.cpp:2148
bool _networking
are we in networking mode?
Definition: network.cpp:54
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:2029
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:332
Select station (when joining stations); Window numbers:
Definition: window_type.h:237
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:84
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:765
static void MakeVoid(TileIndex t)
Make a nice void tile ;)
Definition: void_map.h:21
SaveLoadVersion version_from
save/load the variable starting from this savegame version
Definition: saveload.h:503
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
Definition: currency.cpp:156
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition: error_gui.cpp:162
ShipPathCache path
Cached path.
Definition: ship.h:30
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:1492
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:1920
Saveload window; Window numbers:
Definition: window_type.h:139
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:1511
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:1816
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:1394
bitmasked number where only ONE bit may be set
Train vehicle type.
Definition: vehicle_type.h:26
All settings together for the game.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
string (with pre-allocated buffer)
Definition: saveload.h:430
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:409
Base for the train class.
Other order modifications.
Definition: vehicle_gui.h:35
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:1114
this setting only applies to network games
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition: window.cpp:3486
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
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:472
Ship vehicle type.
Definition: vehicle_type.h:28
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:1162
static void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
Definition: settings.cpp:1383
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:47
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:22
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
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:71
static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32 x)
Convert a MANYofMANY structure to a string representation.
Definition: settings.cpp:320
IniItem * item
the first item in the group
Definition: ini_type.h:41
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
Definition: settings.cpp:1797
static bool ChangeDynamicEngines(int32 p1)
Changing the setting "allow multiple NewGRF sets" is not allowed if there are vehicles.
Definition: settings.cpp:1291
GRFStatus status
NOSAVE: GRFStatus, enum.
static bool RedrawTownAuthority(int32 p1)
Update the town authority window after a town authority setting change.
Definition: settings.cpp:1140
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:427
static bool InvalidateCompanyInfrastructureWindow(int32 p1)
Invalidate the company infrastructure details window after a infrastructure maintenance setting chang...
Definition: settings.cpp:1151
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
Definition: settings.cpp:2181
Base for all sound drivers.
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
change a company setting
Definition: command_type.h:308
Build vehicle; Window numbers:
Definition: window_type.h:378
Vehicle data structure.
Definition: vehicle_base.h:212
TownFounding found_town
town founding.
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
Definition: town_cmd.cpp:409
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:26
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:725
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:757
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:382
void RemoveGroup(const char *name)
Remove the group with the given name.
Definition: ini_load.cpp:179
Properties of config file settings.
do not save to config file
Definition: saveload.h:471
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
static const TextColour CC_DEFAULT
Default colour of the console.
Definition: console_type.h:25
IniGroup * GetGroup(const char *name, size_t len=0, bool create_new=true)
Get the group with the given name.
Definition: ini_load.cpp:156
GRF file was not found in the local cache.
Definition: newgrf_config.h:38
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:20
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;
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
Common return value for all commands.
Definition: command_type.h:25
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
void SaveToConfig()
Save the values to the configuration file.
Definition: settings.cpp:1754
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:353
IniItem * next
The next item in this group.
Definition: ini_type.h:26
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Network-safe changing of settings (server-only).
Definition: settings.cpp:1861
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:428
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:129
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:96
Functions/types etc.
A single "line" in an ini file.
Definition: ini_type.h:25
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:184
uint16 servint_ships
service interval for ships
static bool RedrawSmallmap(int32 p1)
Redraw the smallmap after a colour scheme change.
Definition: settings.cpp:844
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
static void SetTileHeight(TileIndex tile, uint height)
Sets the height of a tile.
Definition: tile_map.h:59
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:502
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:3318
Buses, trucks and trams belong to this class.
Definition: roadveh.h:109
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Definition: window.cpp:3497
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:26
char * _config_file
Configuration file of OpenTTD.
Definition: settings.cpp:84
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:281
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:40
NetworkSettings network
settings related to the network
void GamelogSetting(const char *name, int32 oldval, int32 newval)
Logs change in game settings.
Definition: gamelog.cpp:483
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Definition: settings.cpp:1998
Engine preview window; Window numbers:
Definition: window_type.h:585
uint8 num_params
Number of used parameters.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:433
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
VarType conv
type of the variable to be saved, int
Definition: saveload.h:501
static void SaveVersionInConfig(IniFile *ini)
Save the version of OpenTTD to the ini file.
Definition: settings.cpp:1655
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:596
Error message; Window numbers:
Definition: window_type.h:105
GRF file is an openttd-internal system grf.
Definition: newgrf_config.h:24
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition: window.cpp:3508
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:470
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition: train_cmd.cpp:109
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
Load a WindowDesc from config.
Definition: settings.cpp:765
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:99
bool SaveToDisk(const char *filename)
Save the Ini file&#39;s data to the disk.
Definition: ini.cpp:43
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
Definition: settings.cpp:2011
DoCommandFlag
List of flags for a command.
Definition: command_type.h:344
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:49
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:80
static const char *const _list_group_names[]
Groups in openttd.cfg that are actually lists.
Definition: settings.cpp:98
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:126
void LoadFromDisk(const char *filename, Subdirectory subdir)
Load the Ini file&#39;s data from the disk.
Definition: ini_load.cpp:212
A path without any base directory.
Definition: fileio_type.h:127
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:1130
static size_t LookupManyOfMany(const char *many, const char *str)
Find the set-integer value MANYofMANY type in a string.
Definition: settings.cpp:142
A number of safeguards to prevent using unsafe methods.
Water tile.
Definition: tile_type.h:49
void NetworkUpdateClientName()
Send the server our name.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:82
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition: window.cpp:3519
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2069
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:47
uint8 flags
NOSAVE: GCF_Flags, bitset.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:138
void LoadFromConfig(bool minimal)
Load the values from the configuration files.
Definition: settings.cpp:1724
Console functions used outside of the console code.
GRF is unusable with this version of OpenTTD.
Definition: newgrf_config.h:31
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
Definition: error_gui.cpp:444
Company colour selection; Window numbers:
Definition: window_type.h:225
char * value
The value of this item.
Definition: ini_type.h:28
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:883
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
Find newest Grf, ignoring Grfs with GCF_INVALID set.
static ErrorList _settings_error_list
Errors while loading minimal settings.
Definition: settings.cpp:87
static bool RoadVehSlopeSteepnessChanged(int32 p1)
This function updates the road vehicle acceleration cache after a steepness change.
Definition: settings.cpp:1055
Vehicle timetable; Window numbers:
Definition: window_type.h:219
Found a town; Window numbers:
Definition: window_type.h:424
Basic functions/variables used all over the place.
Build station; Window numbers:
Definition: window_type.h:392
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:534
Industry view; Window numbers:
Definition: window_type.h:358
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
Definition: road_cmd.cpp:185
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:42
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:120
static int ParseIntList(const char *p, int *items, int maxitems)
Parse an integerlist string and set each found value.
Definition: settings.cpp:174
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
Check whether the given file exists.
Definition: fileio.cpp:312
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:1220
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
Definition: saveload.h:793
static void LoadSettings(const SettingDesc *osd, void *object)
Save and load handler for settings.
Definition: settings.cpp:2210
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1159
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
Definition: saveload.h:814
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition: station.cpp:483
All ships have this type.
Definition: ship.h:28
Handlers and description of chunk.
Definition: saveload.h:358
void SetCompanySetting(uint index, int32 value)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:1983
Subdirectory for all NewGRFs.
Definition: fileio_type.h:119
#define FOR_ALL_SHIPS(var)
Iterate over all ships.
Definition: ship.h:66
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:80
Build industry; Window numbers:
Definition: window_type.h:430
Build toolbar; Window numbers:
Definition: window_type.h:68
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
Definition: settings.cpp:1832
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:37
&#39;Train&#39; is either a loco or a wagon.
Definition: train.h:87
Build signal toolbar; Window numbers:
Definition: window_type.h:93
string enclosed in quotes (with pre-allocated buffer)
Definition: saveload.h:431
static bool CheckRoadSide(int p1)
Check whether the road side may be changed.
Definition: settings.cpp:1207
StringList _network_host_list
The servers we know.
Definition: network.cpp:66
static bool v_PositionStatusbar(int32 p1)
Reposition the statusbar as the setting changed.
Definition: settings.cpp:817
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1146
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition: settings.cpp:786
static int DecodeHexNibble(char c)
Convert a character to a hex nibble value, or -1 otherwise.
Definition: settings.cpp:1476
void BuildLandLegend()
(Re)build the colour tables for the legends.
byte quantity_sea_lakes
the amount of seas/lakes
Definition: settings_type.h:67
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:498
change a setting
Definition: command_type.h:307
Setting changed.
Definition: gamelog.h:23
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:747
execute the given command
Definition: command_type.h:346
Company infrastructure overview; Window numbers:
Definition: window_type.h:572
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:825
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:203
Functions related to companies.
static uint MapSize()
Get the size of the map.
Definition: map_func.h:94
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
void ReInitAllWindows()
Re-initialize all windows.
Definition: window.cpp:3435
The data of the error message.
Definition: error.h:30
Ini file that supports both loading and saving.
Definition: ini_type.h:88
static bool RoadVehAccelerationModelChanged(int32 p1)
This function updates realistic acceleration caches when the setting "Road vehicle acceleration model...
Definition: settings.cpp:1031
void NetworkServerSendConfigUpdate()
Send Config Update.
Town authority; Window numbers:
Definition: window_type.h:189
GUISettings gui
settings related to the GUI
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:529
bool station_noise_level
build new airports when the town noise level is still within accepted limits
int cached_max_curve_speed
max consist speed limited by curves
Definition: train.h:81
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1528
Declarations for savegames operations.
SaveLoadVersion version_to
save/load the variable until this savegame version
Definition: saveload.h:504
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
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:779
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:27
static void MakeOneOfMany(char *buf, const char *last, const char *many, int id)
Convert a ONEofMANY structure to a string representation.
Definition: settings.cpp:292
Map accessors for void tiles.
First company, same as owner.
Definition: company_type.h:24
useful to write zeros in savegame.
Definition: saveload.h:429
string pointer enclosed in quotes
Definition: saveload.h:433
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:25
this setting cannot be changed in a game
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
bool servint_ispercent
service intervals are in percents
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:60
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:1942
TileIndex xy
Base tile of the station.
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition: genworld.h:48
void IConsoleError(const char *string)
It is possible to print error information to the console.
Definition: console.cpp:169
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:105
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
Definition: saveload.h:500
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:68
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:54
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:133
Town view; Window numbers:
Definition: window_type.h:328
char * filename
Filename - either with or without full path.
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition: settings.cpp:83
string with a pre-allocated buffer
Maximum number of companies.
Definition: company_type.h:25
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:113
StringList _network_ban_list
The banned clients.
Definition: network.cpp:67
int GetCurveSpeedLimit() const
Computes train speed limit caused by curves.
Definition: train_cmd.cpp:303
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:61
uint16 servint_aircraft
service interval for aircraft
SettingType GetType() const
Return the type of the setting.
Definition: settings.cpp:801
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:195
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:55
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:235
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:31
header file for electrified rail specific functions
static const TextColour CC_ERROR
Colour for error lines.
Definition: console_type.h:26
Base for ships.
The original landscape generator.
Definition: genworld.h:22
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
AI settings; Window numbers:
Definition: window_type.h:170
Company setting.
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:85
Aircraft vehicle type.
Definition: vehicle_type.h:29
int32 min
minimum values
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:131
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
IniGroup * next
the next group within this file
Definition: ini_type.h:39
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
declaration of OTTD revision dependent variables
SaveLoad type struct.
Definition: saveload.h:498
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.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
Definition: vehicle_base.h:987
string pointer
Definition: saveload.h:432
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:684
static bool TrainSlopeSteepnessChanged(int32 p1)
This function updates the train acceleration cache after a steepness change.
Definition: settings.cpp:1016
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:113
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:104
StringList _network_bind_list
The addresses to bind on.
Definition: network.cpp:65
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:86
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:1908
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:776
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3227
Functions related to news.
Base classes/functions for stations.
Errors (eg. saving/loading failed)
Definition: error.h:25
std::list< ErrorMessageData > ErrorList
Define a queue with errors.
Definition: error_gui.cpp:169
Company view; Window numbers:
Definition: window_type.h:364
uint32 max
maximum values
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:27
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
Definition: saveload.cpp:781
SettingDescBase desc
Settings structure (going to configuration file)
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:50
static bool v_PositionMainToolbar(int32 p1)
Reposition the main toolbar as the setting changed.
Definition: settings.cpp:810
static bool InvalidateNewGRFChangeWindows(int32 p1)
Update any possible saveload window and delete any newgrf dialogue as its widget parts might change...
Definition: settings.cpp:1109
Base class for all station-ish types.
Factory to &#39;query&#39; all available blitters.
Game options window; Window numbers:
Definition: window_type.h:608
bool GetArgumentInteger(uint32 *value, const char *arg)
Change a string into its number representation.
Definition: console.cpp:181
All settings that are only important for the local client.
Road vehicle type.
Definition: vehicle_type.h:27
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:165
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:3300
void UpdateAcceleration()
Update acceleration of the train from the cached power and weight.
Definition: train_cmd.cpp:420
Last chunk in this array.
Definition: saveload.h:393
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:38
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1459
static void SaveSettings(const SettingDesc *sd, void *object)
Save and load handler for settings.
Definition: settings.cpp:2227
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
Definition: settings.cpp:1777
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:201
void ShowFirstError()
Show the first error of the queue.
Definition: error_gui.cpp:347