OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

newgrf_sl.cpp
Go to the documentation of this file.
1 /* $Id: newgrf_sl.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #include "../stdafx.h"
13 #include "../fios.h"
14
15 #include "saveload.h"
16 #include "newgrf_sl.h"
17
18 #include "../safeguards.h"
19
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()
26 };
27
32 void Save_NewGRFMapping(const OverrideManagerBase &mapping)
33 {
34 for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
35 SlSetArrayIndex(i);
36 SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc);
37 }
38 }
39
44 void Load_NewGRFMapping(OverrideManagerBase &mapping)
45 {
46 /* Clear the current mapping stored.
47 * This will create the manager if ever it is not yet done */
48 mapping.ResetMapping();
49
50 uint max_id = mapping.GetMaxMapping();
51
52 int index;
53 while ((index = SlIterateArray()) != -1) {
54 if ((uint)index >= max_id) break;
55 SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc);
56 }
57 }
58
59
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()
69 };
70
71
72 static void Save_NGRF()
73 {
74 int index = 0;
75
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);
80 }
81 }
82
83
84 static void Load_NGRF_common(GRFConfig *&grfconfig)
85 {
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);
92 }
93 }
94
95 static void Load_NGRF()
96 {
97 Load_NGRF_common(_grfconfig);
98
99 /* Append static NewGRF configuration, but only if there are some NewGRFs. */
100 if (_game_mode != GM_MENU || _all_grfs != NULL) AppendStaticGRFConfigs(&_grfconfig);
101 }
102
103 static void Check_NGRF()
104 {
105 Load_NGRF_common(_load_check_data.grfconfig);
106 }
107
108 extern const ChunkHandler _newgrf_chunk_handlers[] = {
109 { 'NGRF', Save_NGRF, Load_NGRF, NULL, Check_NGRF, CH_ARRAY | CH_LAST }
110 };