OpenTTD: src/newgrf_config.h Source File

OpenTTD

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

- File List
- Globals

newgrf_config.h
Go to the documentation of this file.
1 /* $Id: newgrf_config.h 26612 2014-05-24 19:13:34Z alberth $ */
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 #ifndef NEWGRF_CONFIG_H
13 #define NEWGRF_CONFIG_H
14
15 #include "strings_type.h"
16 #include "core/alloc_type.hpp"
17 #include "core/smallmap_type.hpp"
18 #include "misc/countedptr.hpp"
19 #include "fileio_type.h"
20 #include "textfile_type.h"
21
23 enum GCF_Flags {
24 GCF_SYSTEM,
25 GCF_UNSAFE,
26 GCF_STATIC,
27 GCF_COMPATIBLE,
28 GCF_COPY,
29 GCF_INIT_ONLY,
30 GCF_RESERVED,
31 GCF_INVALID,
32 };
33
35 enum GRFStatus {
36 GCS_UNKNOWN,
37 GCS_DISABLED,
38 GCS_NOT_FOUND,
39 GCS_INITIALISED,
40 GCS_ACTIVATED,
41 };
42
44 enum GRFBugs {
45 GBUG_VEH_LENGTH,
46 GBUG_VEH_REFIT,
47 GBUG_VEH_POWERED_WAGON,
48 GBUG_UNKNOWN_CB_RESULT,
49 GBUG_VEH_CAPACITY,
50 };
51
53 enum GRFListCompatibility {
54 GLC_ALL_GOOD,
55 GLC_COMPATIBLE,
56 GLC_NOT_FOUND,
57 };
58
60 enum GRFPalette {
61 GRFP_USE_BIT = 0,
62 GRFP_GRF_OFFSET = 2,
63 GRFP_GRF_SIZE = 2,
64 GRFP_BLT_OFFSET = 4,
65 GRFP_BLT_SIZE = 1,
66
67 GRFP_USE_DOS = 0x0,
68 GRFP_USE_WINDOWS = 0x1,
69 GRFP_USE_MASK = 0x1,
70
71 GRFP_GRF_UNSET = 0x0 << GRFP_GRF_OFFSET,
72 GRFP_GRF_DOS = 0x1 << GRFP_GRF_OFFSET,
73 GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET,
74 GRFP_GRF_ANY = GRFP_GRF_DOS | GRFP_GRF_WINDOWS,
75 GRFP_GRF_MASK = GRFP_GRF_ANY,
76
77 GRFP_BLT_UNSET = 0x0 << GRFP_BLT_OFFSET,
78 GRFP_BLT_32BPP = 0x1 << GRFP_BLT_OFFSET,
79 GRFP_BLT_MASK = GRFP_BLT_32BPP,
80 };
81
82
84 struct GRFIdentifier {
85 uint32 grfid;
86 uint8 md5sum[16];
87
94 inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
95 {
96 if (this->grfid != grfid) return false;
97 if (md5sum == NULL) return true;
98 return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
99 }
100 };
101
103 struct GRFError : ZeroedMemoryAllocator {
104 GRFError(StringID severity, StringID message = 0);
105 GRFError(const GRFError &error);
106 ~GRFError();
107
108 char *custom_message;
109 char *data;
110 StringID message;
111 StringID severity;
112 uint32 param_value[2];
113 };
114
116 enum GRFParameterType {
117 PTYPE_UINT_ENUM,
118 PTYPE_BOOL,
119 PTYPE_END,
120 };
121
123 struct GRFParameterInfo {
124 GRFParameterInfo(uint nr);
125 GRFParameterInfo(GRFParameterInfo &info);
126 ~GRFParameterInfo();
127 struct GRFText *name;
128 struct GRFText *desc;
129 GRFParameterType type;
130 uint32 min_value;
131 uint32 max_value;
132 uint32 def_value;
133 byte param_nr;
134 byte first_bit;
135 byte num_bit;
136 SmallMap<uint32, struct GRFText *, 8> value_names;
137 bool complete_labels;
138
139 uint32 GetValue(struct GRFConfig *config) const;
140 void SetValue(struct GRFConfig *config, uint32 value);
141 void Finalize();
142 };
143
145 struct GRFTextWrapper : public SimpleCountedObject {
146 struct GRFText *text;
147
148 GRFTextWrapper();
149 ~GRFTextWrapper();
150 };
151
153 struct GRFConfig : ZeroedMemoryAllocator {
154 GRFConfig(const char *filename = NULL);
155 GRFConfig(const GRFConfig &config);
156 ~GRFConfig();
157
158 GRFIdentifier ident;
159 uint8 original_md5sum[16];
160 char *filename;
161 GRFTextWrapper *name;
162 GRFTextWrapper *info;
163 GRFTextWrapper *url;
164 GRFError *error;
165
166 uint32 version;
167 uint32 min_loadable_version;
168 uint8 flags;
169 GRFStatus status;
170 uint32 grf_bugs;
171 uint32 param[0x80];
172 uint8 num_params;
173 uint8 num_valid_params;
174 uint8 palette;
175 SmallVector<GRFParameterInfo *, 4> param_info;
176 bool has_param_defaults;
177
178 struct GRFConfig *next;
179
180 void CopyParams(const GRFConfig &src);
181
182 bool IsOpenTTDBaseGRF() const;
183
184 const char *GetTextfile(TextfileType type) const;
185 const char *GetName() const;
186 const char *GetDescription() const;
187 const char *GetURL() const;
188
189 void SetParameterDefaults();
190 void SetSuitablePalette();
191 void FinalizeParameterInfo();
192 };
193
195 enum FindGRFConfigMode {
196 FGCM_EXACT,
197 FGCM_COMPATIBLE,
198 FGCM_NEWEST,
199 FGCM_NEWEST_VALID,
200 FGCM_ANY,
201 };
202
203 extern GRFConfig *_all_grfs;
204 extern GRFConfig *_grfconfig;
205 extern GRFConfig *_grfconfig_newgame;
206 extern GRFConfig *_grfconfig_static;
207
209 struct NewGRFScanCallback {
211 virtual ~NewGRFScanCallback() {}
213 virtual void OnNewGRFsScanned() = 0;
214 };
215
216 size_t GRFGetSizeOfDataSection(FILE *f);
217
218 void ScanNewGRFFiles(NewGRFScanCallback *callback);
219 void CheckForMissingSprites();
220 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
221 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
222 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
223 void AppendStaticGRFConfigs(GRFConfig **dst);
224 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
225 void ClearGRFConfigList(GRFConfig **config);
226 void ResetGRFConfig(bool defaults);
227 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
228 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
229 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
230
231 /* In newgrf_gui.cpp */
232 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
233
234 #ifdef ENABLE_NETWORK
235
236 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
237 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
238 #endif /* ENABLE_NETWORK */
239
240 void UpdateNewGRFScanStatus(uint num, const char *name);
241 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
242
243 #endif /* NEWGRF_CONFIG_H */