(svn r27770) -Fix [FS#6540]: Initialize variables in station_sl.cpp (JGR)
[openttd.git] / src / saveload / newgrf_sl.cpp
blobdacc127ea0a50eff1bd1291c03cc863cffe2526b
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file newgrf_sl.cpp Code handling saving and loading of newgrf config */
12 #include "../stdafx.h"
13 #include "../fios.h"
15 #include "saveload.h"
16 #include "newgrf_sl.h"
18 #include "../safeguards.h"
20 /** Save and load the mapping between a spec and the NewGRF it came from. */
21 static const SaveLoad _newgrf_mapping_desc[] = {
22 SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
23 SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
24 SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
25 SLE_END()
28 /**
29 * Save a GRF ID + local id -> OpenTTD's id mapping.
30 * @param mapping The mapping to save.
32 void Save_NewGRFMapping(const OverrideManagerBase &mapping)
34 for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
35 SlSetArrayIndex(i);
36 SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc);
40 /**
41 * Load a GRF ID + local id -> OpenTTD's id mapping.
42 * @param mapping The mapping to load.
44 void Load_NewGRFMapping(OverrideManagerBase &mapping)
46 /* Clear the current mapping stored.
47 * This will create the manager if ever it is not yet done */
48 mapping.ResetMapping();
50 uint max_id = mapping.GetMaxMapping();
52 int index;
53 while ((index = SlIterateArray()) != -1) {
54 if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
55 SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc);
60 static const SaveLoad _grfconfig_desc[] = {
61 SLE_STR(GRFConfig, filename, SLE_STR, 0x40),
62 SLE_VAR(GRFConfig, ident.grfid, SLE_UINT32),
63 SLE_ARR(GRFConfig, ident.md5sum, SLE_UINT8, 16),
64 SLE_CONDVAR(GRFConfig, version, SLE_UINT32, 151, SL_MAX_VERSION),
65 SLE_ARR(GRFConfig, param, SLE_UINT32, 0x80),
66 SLE_VAR(GRFConfig, num_params, SLE_UINT8),
67 SLE_CONDVAR(GRFConfig, palette, SLE_UINT8, 101, SL_MAX_VERSION),
68 SLE_END()
72 static void Save_NGRF()
74 int index = 0;
76 for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
77 if (HasBit(c->flags, GCF_STATIC)) continue;
78 SlSetArrayIndex(index++);
79 SlObject(c, _grfconfig_desc);
84 static void Load_NGRF_common(GRFConfig *&grfconfig)
86 ClearGRFConfigList(&grfconfig);
87 while (SlIterateArray() != -1) {
88 GRFConfig *c = new GRFConfig();
89 SlObject(c, _grfconfig_desc);
90 if (IsSavegameVersionBefore(101)) c->SetSuitablePalette();
91 AppendToGRFConfigList(&grfconfig, c);
95 static void Load_NGRF()
97 Load_NGRF_common(_grfconfig);
99 /* Append static NewGRF configuration, but only if there are some NewGRFs. */
100 if (_game_mode != GM_MENU || _all_grfs != NULL) AppendStaticGRFConfigs(&_grfconfig);
103 static void Check_NGRF()
105 Load_NGRF_common(_load_check_data.grfconfig);
108 extern const ChunkHandler _newgrf_chunk_handlers[] = {
109 { 'NGRF', Save_NGRF, Load_NGRF, NULL, Check_NGRF, CH_ARRAY | CH_LAST }