00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef NEWGRF_CONFIG_H
00013 #define NEWGRF_CONFIG_H
00014
00015 #include "strings_type.h"
00016 #include "core/alloc_type.hpp"
00017 #include "core/smallmap_type.hpp"
00018 #include "misc/countedptr.hpp"
00019 #include "fileio_type.h"
00020
00022 enum GCF_Flags {
00023 GCF_SYSTEM,
00024 GCF_UNSAFE,
00025 GCF_STATIC,
00026 GCF_COMPATIBLE,
00027 GCF_COPY,
00028 GCF_INIT_ONLY,
00029 GCF_RESERVED,
00030 GCF_INVALID,
00031 };
00032
00034 enum GRFStatus {
00035 GCS_UNKNOWN,
00036 GCS_DISABLED,
00037 GCS_NOT_FOUND,
00038 GCS_INITIALISED,
00039 GCS_ACTIVATED,
00040 };
00041
00043 enum GRFBugs {
00044 GBUG_VEH_LENGTH,
00045 GBUG_VEH_REFIT,
00046 GBUG_VEH_POWERED_WAGON,
00047 GBUG_UNKNOWN_CB_RESULT,
00048 };
00049
00051 enum GRFListCompatibility {
00052 GLC_ALL_GOOD,
00053 GLC_COMPATIBLE,
00054 GLC_NOT_FOUND,
00055 };
00056
00058 enum GRFPalette {
00059 GRFP_USE_BIT = 0,
00060 GRFP_GRF_OFFSET = 2,
00061 GRFP_GRF_SIZE = 2,
00062 GRFP_BLT_OFFSET = 4,
00063 GRFP_BLT_SIZE = 1,
00064
00065 GRFP_USE_DOS = 0x0,
00066 GRFP_USE_WINDOWS = 0x1,
00067 GRFP_USE_MASK = 0x1,
00068
00069 GRFP_GRF_UNSET = 0x0 << GRFP_GRF_OFFSET,
00070 GRFP_GRF_DOS = 0x1 << GRFP_GRF_OFFSET,
00071 GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET,
00072 GRFP_GRF_ANY = GRFP_GRF_DOS | GRFP_GRF_WINDOWS,
00073 GRFP_GRF_MASK = GRFP_GRF_ANY,
00074
00075 GRFP_BLT_UNSET = 0x0 << GRFP_BLT_OFFSET,
00076 GRFP_BLT_32BPP = 0x1 << GRFP_BLT_OFFSET,
00077 GRFP_BLT_MASK = GRFP_BLT_32BPP,
00078 };
00079
00080
00082 struct GRFIdentifier {
00083 uint32 grfid;
00084 uint8 md5sum[16];
00085
00092 inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
00093 {
00094 if (this->grfid != grfid) return false;
00095 if (md5sum == NULL) return true;
00096 return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
00097 }
00098 };
00099
00101 struct GRFError : ZeroedMemoryAllocator {
00102 GRFError(StringID severity, StringID message = 0);
00103 GRFError(const GRFError &error);
00104 ~GRFError();
00105
00106 char *custom_message;
00107 char *data;
00108 StringID message;
00109 StringID severity;
00110 uint32 param_value[2];
00111 };
00112
00114 enum GRFParameterType {
00115 PTYPE_UINT_ENUM,
00116 PTYPE_BOOL,
00117 PTYPE_END,
00118 };
00119
00121 struct GRFParameterInfo {
00122 GRFParameterInfo(uint nr);
00123 GRFParameterInfo(GRFParameterInfo &info);
00124 ~GRFParameterInfo();
00125 struct GRFText *name;
00126 struct GRFText *desc;
00127 GRFParameterType type;
00128 uint32 min_value;
00129 uint32 max_value;
00130 uint32 def_value;
00131 byte param_nr;
00132 byte first_bit;
00133 byte num_bit;
00134 SmallMap<uint32, struct GRFText *, 8> value_names;
00135
00136 uint32 GetValue(struct GRFConfig *config) const;
00137 void SetValue(struct GRFConfig *config, uint32 value);
00138 };
00139
00141 struct GRFTextWrapper : public SimpleCountedObject {
00142 struct GRFText *text;
00143
00144 GRFTextWrapper();
00145 ~GRFTextWrapper();
00146 };
00147
00149 enum TextfileType {
00150 TFT_BEGIN,
00151
00152 TFT_README = TFT_BEGIN,
00153 TFT_CHANGELOG,
00154 TFT_LICENSE,
00155
00156 TFT_END,
00157 };
00158 DECLARE_POSTFIX_INCREMENT(TextfileType)
00159
00160
00161 struct GRFConfig : ZeroedMemoryAllocator {
00162 GRFConfig(const char *filename = NULL);
00163 GRFConfig(const GRFConfig &config);
00164 ~GRFConfig();
00165
00166 GRFIdentifier ident;
00167 uint8 original_md5sum[16];
00168 char *filename;
00169 GRFTextWrapper *name;
00170 GRFTextWrapper *info;
00171 GRFTextWrapper *url;
00172 GRFError *error;
00173
00174 uint32 version;
00175 uint32 min_loadable_version;
00176 uint8 flags;
00177 GRFStatus status;
00178 uint32 grf_bugs;
00179 uint32 param[0x80];
00180 uint8 num_params;
00181 uint8 num_valid_params;
00182 uint8 palette;
00183 SmallVector<GRFParameterInfo *, 4> param_info;
00184 bool has_param_defaults;
00185
00186 struct GRFConfig *next;
00187
00188 bool IsOpenTTDBaseGRF() const;
00189
00190 const char *GetTextfile(TextfileType type) const;
00191 const char *GetName() const;
00192 const char *GetDescription() const;
00193 const char *GetURL() const;
00194
00195 void SetParameterDefaults();
00196 void SetSuitablePalette();
00197 };
00198
00200 enum FindGRFConfigMode {
00201 FGCM_EXACT,
00202 FGCM_COMPATIBLE,
00203 FGCM_NEWEST,
00204 FGCM_NEWEST_VALID,
00205 FGCM_ANY,
00206 };
00207
00208 extern GRFConfig *_all_grfs;
00209 extern GRFConfig *_grfconfig;
00210 extern GRFConfig *_grfconfig_newgame;
00211 extern GRFConfig *_grfconfig_static;
00212
00214 struct NewGRFScanCallback {
00216 virtual ~NewGRFScanCallback() {}
00218 virtual void OnNewGRFsScanned() = 0;
00219 };
00220
00221 size_t GRFGetSizeOfDataSection(FILE *f);
00222
00223 void ScanNewGRFFiles(NewGRFScanCallback *callback);
00224 void CheckForMissingSprites();
00225 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
00226 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
00227 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
00228 void AppendStaticGRFConfigs(GRFConfig **dst);
00229 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
00230 void ClearGRFConfigList(GRFConfig **config);
00231 void ResetGRFConfig(bool defaults);
00232 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
00233 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
00234 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
00235
00236
00237 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
00238
00239 #ifdef ENABLE_NETWORK
00240
00241 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
00242 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
00243 #endif
00244
00245 void UpdateNewGRFScanStatus(uint num, const char *name);
00246 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
00247
00248 #endif