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