OpenTTD
newgrf_config.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef NEWGRF_CONFIG_H
11 #define NEWGRF_CONFIG_H
12 
13 #include "strings_type.h"
14 #include "core/alloc_type.hpp"
15 #include "core/smallmap_type.hpp"
16 #include "misc/countedptr.hpp"
17 #include "fileio_type.h"
18 #include "textfile_type.h"
19 
21 enum GCF_Flags {
30 };
31 
33 enum GRFStatus {
39 };
40 
42 enum GRFBugs {
48 };
49 
55 };
56 
58 enum GRFPalette {
64 
65  GRFP_USE_DOS = 0x0,
67  GRFP_USE_MASK = 0x1,
68 
74 
78 };
79 
80 
82 struct GRFIdentifier {
83  uint32 grfid;
84  uint8 md5sum[16];
85 
92  inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
93  {
94  if (this->grfid != grfid) return false;
95  if (md5sum == nullptr) return true;
96  return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
97  }
98 };
99 
102  GRFError(StringID severity, StringID message = 0);
103  GRFError(const GRFError &error);
104  ~GRFError();
105 
107  char *data;
110  uint32 param_value[2];
111 };
112 
118 };
119 
122  GRFParameterInfo(uint nr);
124  ~GRFParameterInfo();
125  struct GRFText *name;
126  struct GRFText *desc;
128  uint32 min_value;
129  uint32 max_value;
130  uint32 def_value;
131  byte param_nr;
132  byte first_bit;
133  byte num_bit;
136 
137  uint32 GetValue(struct GRFConfig *config) const;
138  void SetValue(struct GRFConfig *config, uint32 value);
139  void Finalize();
140 };
141 
144  struct GRFText *text;
145 
146  GRFTextWrapper();
147  ~GRFTextWrapper();
148 };
149 
152  GRFConfig(const char *filename = nullptr);
153  GRFConfig(const GRFConfig &config);
154  ~GRFConfig();
155 
157  uint8 original_md5sum[16];
158  char *filename;
163 
164  uint32 version;
166  uint8 flags;
168  uint32 grf_bugs;
169  uint32 param[0x80];
170  uint8 num_params;
172  uint8 palette;
173  std::vector<GRFParameterInfo *> param_info;
175 
176  struct GRFConfig *next;
177 
178  void CopyParams(const GRFConfig &src);
179 
180  const char *GetTextfile(TextfileType type) const;
181  const char *GetName() const;
182  const char *GetDescription() const;
183  const char *GetURL() const;
184 
185  void SetParameterDefaults();
186  void SetSuitablePalette();
187  void FinalizeParameterInfo();
188 };
189 
197 };
198 
199 extern GRFConfig *_all_grfs;
200 extern GRFConfig *_grfconfig;
203 extern uint _missing_extra_graphics;
204 
208  virtual ~NewGRFScanCallback() {}
210  virtual void OnNewGRFsScanned() = 0;
211 };
212 
213 size_t GRFGetSizeOfDataSection(FILE *f);
214 
215 void ScanNewGRFFiles(NewGRFScanCallback *callback);
216 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = nullptr, uint32 desired_version = 0);
217 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
218 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
220 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
221 void ClearGRFConfigList(GRFConfig **config);
222 void ResetGRFConfig(bool defaults);
224 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
225 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
226 
227 /* In newgrf_gui.cpp */
228 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
229 
231 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
232 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
233 
234 void UpdateNewGRFScanStatus(uint num, const char *name);
235 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
236 
237 #endif /* NEWGRF_CONFIG_H */
SmallMap< uint32, struct GRFText * > value_names
Names for each value.
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
GRFConfig ** CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
Copy a GRF Config list.
The parameter allows a range of numbers, each of which can have a special name.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
CCountedPtr - smart pointer implementation.
GRF file is processed up to GLS_INIT.
Definition: newgrf_config.h:27
All GRF needed by game are present.
Definition: newgrf_config.h:52
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
Compatible (eg. the same ID, but different checksum) GRF found in at least one case.
Definition: newgrf_config.h:53
Capacity of vehicle changes when not refitting or arranging.
Definition: newgrf_config.h:47
GRFParameterType type
The type of this parameter.
GRFPalette
Information that can/has to be stored about a GRF&#39;s palette.
Definition: newgrf_config.h:58
GRFConfig * _grfconfig
First item in list of current GRF set up.
The NewGRF prefers a 32 bpp blitter.
Definition: newgrf_config.h:76
GRF file has been initialised.
Definition: newgrf_config.h:37
uint32 def_value
Default value of this parameter.
Implementation of simple mapping class.
GRFStatus status
NOSAVE: GRFStatus, enum.
struct GRFText * text
The actual text.
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:24
uint8 num_valid_params
NOSAVE: Number of valid parameters (action 0x14)
char * custom_message
Custom message (if present)
GRFError * error
NOSAVE: Error/Warning during GRF loading (Action 0x0B)
The NewGRF provided no information.
Definition: newgrf_config.h:69
byte param_nr
GRF parameter to store content in.
void AppendStaticGRFConfigs(GRFConfig **dst)
Appends the static GRFs to a list of GRFs.
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
StringID severity
Info / Warning / Error / Fatal.
GRF file was not found in the local cache.
Definition: newgrf_config.h:36
Helper types related to the allocation of memory.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
size_t GRFGetSizeOfDataSection(FILE *f)
Get the data section size of a GRF.
Basic data to distinguish a GRF.
Definition: newgrf_config.h:82
GRF file is disabled.
Definition: newgrf_config.h:35
GRFParameterType
The possible types of a newgrf parameter.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
GRFConfig * _all_grfs
First item in list of all scanned NewGRFs.
Simple mapping class targeted for small sets of data.
Types for Standard In/Out file operations.
The offset of the GRFP_GRF data.
Definition: newgrf_config.h:60
struct GRFText * desc
The description of this parameter.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask=0xFFFFFFFF)
Retrieve a NewGRF from the current config by its grfid.
uint32 grf_bugs
NOSAVE: bugs in this GRF in this run,.
uint8 num_params
Number of used parameters.
The NewGRF says any palette can be used.
Definition: newgrf_config.h:72
GRF file is an openttd-internal system grf.
Definition: newgrf_config.h:22
The size of the GRFP_BLT data.
Definition: newgrf_config.h:63
Information about GRF, used in the game and (part of it) in savegames.
Bitmask to get only the use palette use states.
Definition: newgrf_config.h:67
bool has_param_defaults
NOSAVE: did this newgrf specify any defaults for it&#39;s parameters.
const char * GetDescription() const
Get the grf info.
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
byte num_bit
Number of bits to use for this parameter.
The palette state is set to use the Windows palette.
Definition: newgrf_config.h:66
The data is copied from a grf in _all_grfs.
Definition: newgrf_config.h:26
Information about why GRF had problems during initialisation.
uint32 max_value
The maximal value of this parameter.
GCF_Flags
GRF config bit flags.
Definition: newgrf_config.h:21
uint8 flags
NOSAVE: GCF_Flags, bitset.
GRF is unusable with this version of OpenTTD.
Definition: newgrf_config.h:29
GRFBugs
Encountered GRF bugs.
Definition: newgrf_config.h:42
The NewGRF provided no information or doesn&#39;t care about a 32 bpp blitter.
Definition: newgrf_config.h:75
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
Find newest Grf, ignoring Grfs with GCF_INVALID set.
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
Appends an element to a list of GRFs.
A callback returned an unknown/invalid result.
Definition: newgrf_config.h:46
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
StringID message
Default message.
Reference counted wrapper around a GRFText pointer.
Simple counted object.
Definition: countedptr.hpp:204
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum=nullptr, uint32 desired_version=0)
Find a NewGRF in the scanned list.
void FinalizeParameterInfo()
Finalize Action 14 info after file scan is finished.
Element of the linked list.
Definition: newgrf_text.cpp:68
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
Does the identification match the provided values?
Definition: newgrf_config.h:92
The offset of the GRFP_BLT data.
Definition: newgrf_config.h:62
Subdirectory for all NewGRFs.
Definition: fileio_type.h:117
The status of this grf file is unknown.
Definition: newgrf_config.h:34
Articulated vehicles carry different cargoes resp. are differently refittable than specified in purch...
Definition: newgrf_config.h:44
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
uint32 version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
The palette state is set to use the DOS palette.
Definition: newgrf_config.h:65
GRFTextWrapper * url
NOSAVE: URL belonging to this GRF.
GRF file passed GLS_RESERVE stage.
Definition: newgrf_config.h:28
The NewGRF says the Windows palette can be used.
Definition: newgrf_config.h:71
Callback for NewGRF scanning.
const char * GetURL() const
Get the grf url.
byte first_bit
First bit to use in the GRF parameter.
void UpdateNewGRFScanStatus(uint num, const char *name)
Update the NewGRF scan status.
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
Information about one grf parameter.
GRFListCompatibility
Status of post-gameload GRF compatibility check.
Definition: newgrf_config.h:51
uint8 palette
GRFPalette, bitset.
bool complete_labels
True if all values have a label.
At least one GRF couldn&#39;t be found (higher priority than GLC_COMPATIBLE)
Definition: newgrf_config.h:54
GRF file is unsafe for static usage.
Definition: newgrf_config.h:23
Powered wagon changed poweredness state when not inside a depot.
Definition: newgrf_config.h:45
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:112
GRFTextWrapper * FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
Finds the name of a NewGRF in the list of names for unknown GRFs.
Find newest Grf.
char * filename
Filename - either with or without full path.
Bitmask to only get the blitter information.
Definition: newgrf_config.h:77
FindGRFConfigMode
Method to find GRFs using FindGRFConfig.
void SetSuitablePalette()
Set the palette of this GRFConfig to something suitable.
GRFTextWrapper * name
NOSAVE: GRF name (Action 0x08)
The NewGRF says the DOS palette can be used.
Definition: newgrf_config.h:70
GRFStatus
Status of GRF.
Definition: newgrf_config.h:33
uint32 min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
std::vector< GRFParameterInfo * > param_info
NOSAVE: extra information about the parameters.
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
Types related to strings.
The parameter is either 0 or 1.
uint32 min_value
The minimal value this parameter can have.
const char * GetName() const
Get the name of this grf.
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:83
char * data
Additional data for message and custom_message.
struct GRFText * name
The name of this parameter.
The size of the GRFP_GRF data.
Definition: newgrf_config.h:61
GRF file has been activated.
Definition: newgrf_config.h:38
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
Check if all GRFs in the GRF config from a savegame can be loaded.
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches) ...
Definition: newgrf_config.h:25
Bitmask to get only the NewGRF supplied information.
Definition: newgrf_config.h:73
The bit used for storing the palette to use.
Definition: newgrf_config.h:59
Length of rail vehicle changes when not inside a depot.
Definition: newgrf_config.h:43
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
Definition: newgrf_config.h:84
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Only find Grfs matching md5sum.
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir=NEWGRF_DIR)
Find the GRFID of a given grf, and calculate its md5sum.
virtual ~NewGRFScanCallback()
Make sure the right destructor gets called.
Types related to textfiles.
Find best compatible Grf wrt. desired_version.
Use first found.
bool UpdateNewGRFConfigPalette(int32 p1=0)
Update the palettes of the graphics from the config file.
Invalid parameter type.
GRFTextWrapper * info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)