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 FORCEINLINE 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 uint8 num_params;
00111 uint32 param_value[2];
00112 };
00113
00115 enum GRFParameterType {
00116 PTYPE_UINT_ENUM,
00117 PTYPE_BOOL,
00118 PTYPE_END,
00119 };
00120
00122 struct GRFParameterInfo {
00123 GRFParameterInfo(uint nr);
00124 GRFParameterInfo(GRFParameterInfo &info);
00125 ~GRFParameterInfo();
00126 struct GRFText *name;
00127 struct GRFText *desc;
00128 GRFParameterType type;
00129 uint32 min_value;
00130 uint32 max_value;
00131 uint32 def_value;
00132 byte param_nr;
00133 byte first_bit;
00134 byte num_bit;
00135 SmallMap<uint32, struct GRFText *, 8> value_names;
00136
00137 uint32 GetValue(struct GRFConfig *config) const;
00138 void SetValue(struct GRFConfig *config, uint32 value);
00139 };
00140
00142 struct GRFTextWrapper : public SimpleCountedObject {
00143 struct GRFText *text;
00144
00145 GRFTextWrapper();
00146 ~GRFTextWrapper();
00147 };
00148
00150 enum TextfileType {
00151 TFT_BEGIN,
00152
00153 TFT_README = TFT_BEGIN,
00154 TFT_CHANGELOG,
00155 TFT_LICENSE,
00156
00157 TFT_END
00158 };
00159 DECLARE_POSTFIX_INCREMENT(TextfileType)
00160
00161
00162 struct GRFConfig : ZeroedMemoryAllocator {
00163 GRFConfig(const char *filename = NULL);
00164 GRFConfig(const GRFConfig &config);
00165 ~GRFConfig();
00166
00167 GRFIdentifier ident;
00168 uint8 original_md5sum[16];
00169 char *filename;
00170 GRFTextWrapper *name;
00171 GRFTextWrapper *info;
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
00194 void SetParameterDefaults();
00195 void SetSuitablePalette();
00196 };
00197
00199 enum FindGRFConfigMode {
00200 FGCM_EXACT,
00201 FGCM_COMPATIBLE,
00202 FGCM_NEWEST,
00203 FGCM_NEWEST_VALID,
00204 FGCM_ANY,
00205 };
00206
00207 extern GRFConfig *_all_grfs;
00208 extern GRFConfig *_grfconfig;
00209 extern GRFConfig *_grfconfig_newgame;
00210 extern GRFConfig *_grfconfig_static;
00211
00213 struct NewGRFScanCallback {
00215 virtual ~NewGRFScanCallback() {}
00217 virtual void OnNewGRFsScanned() = 0;
00218 };
00219
00220 void ScanNewGRFFiles(NewGRFScanCallback *callback);
00221 void CheckForMissingSprites();
00222 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
00223 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
00224 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
00225 void AppendStaticGRFConfigs(GRFConfig **dst);
00226 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
00227 void ClearGRFConfigList(GRFConfig **config);
00228 void ResetGRFConfig(bool defaults);
00229 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
00230 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
00231 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
00232
00233
00234 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
00235
00236 #ifdef ENABLE_NETWORK
00237
00238 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
00239 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
00240 #endif
00241
00242 void UpdateNewGRFScanStatus(uint num, const char *name);
00243 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
00244
00245 #endif