OpenTTD
newgrf_config.h
Go to the documentation of this file.
1 /* $Id: newgrf_config.h 27732 2017-01-14 18:30:26Z frosch $ */
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 {
32 };
33 
35 enum GRFStatus {
41 };
42 
44 enum GRFBugs {
50 };
51 
57 };
58 
60 enum GRFPalette {
66 
67  GRFP_USE_DOS = 0x0,
69  GRFP_USE_MASK = 0x1,
70 
76 
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 
105  GRFError(const GRFError &error);
106  ~GRFError();
107 
109  char *data;
112  uint32 param_value[2];
113 };
114 
120 };
121 
124  GRFParameterInfo(uint nr);
127  struct GRFText *name;
128  struct GRFText *desc;
130  uint32 min_value;
131  uint32 max_value;
132  uint32 def_value;
133  byte param_nr;
134  byte first_bit;
135  byte num_bit;
138 
139  uint32 GetValue(struct GRFConfig *config) const;
140  void SetValue(struct GRFConfig *config, uint32 value);
141  void Finalize();
142 };
143 
146  struct GRFText *text;
147 
148  GRFTextWrapper();
149  ~GRFTextWrapper();
150 };
151 
154  GRFConfig(const char *filename = NULL);
155  GRFConfig(const GRFConfig &config);
156  ~GRFConfig();
157 
159  uint8 original_md5sum[16];
160  char *filename;
165 
166  uint32 version;
168  uint8 flags;
170  uint32 grf_bugs;
171  uint32 param[0x80];
172  uint8 num_params;
174  uint8 palette;
177 
178  struct GRFConfig *next;
179 
180  void CopyParams(const GRFConfig &src);
181 
182  const char *GetTextfile(TextfileType type) const;
183  const char *GetName() const;
184  const char *GetDescription() const;
185  const char *GetURL() const;
186 
187  void SetParameterDefaults();
188  void SetSuitablePalette();
189  void FinalizeParameterInfo();
190 };
191 
199 };
200 
201 extern GRFConfig *_all_grfs;
202 extern GRFConfig *_grfconfig;
205 extern uint _missing_extra_graphics;
206 
210  virtual ~NewGRFScanCallback() {}
212  virtual void OnNewGRFsScanned() = 0;
213 };
214 
215 size_t GRFGetSizeOfDataSection(FILE *f);
216 
217 void ScanNewGRFFiles(NewGRFScanCallback *callback);
218 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
219 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
220 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
222 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
223 void ClearGRFConfigList(GRFConfig **config);
224 void ResetGRFConfig(bool defaults);
226 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
227 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
228 
229 /* In newgrf_gui.cpp */
230 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
231 
232 #ifdef ENABLE_NETWORK
233 
234 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
235 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
236 #endif /* ENABLE_NETWORK */
237 
238 void UpdateNewGRFScanStatus(uint num, const char *name);
239 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
240 
241 #endif /* NEWGRF_CONFIG_H */