OpenTTD Source: src/settings.cpp Source File

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