OpenTTD
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 {
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  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 
201 };
202 
203 extern GRFConfig *_all_grfs;
204 extern GRFConfig *_grfconfig;
207 
211  virtual ~NewGRFScanCallback() {}
213  virtual void OnNewGRFsScanned() = 0;
214 };
215 
216 size_t GRFGetSizeOfDataSection(FILE *f);
217 
218 void ScanNewGRFFiles(NewGRFScanCallback *callback);
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);
224 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
225 void ClearGRFConfigList(GRFConfig **config);
226 void ResetGRFConfig(bool defaults);
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 */