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 #include "textfile_type.h"
00021
00023 enum GCF_Flags {
00024 GCF_SYSTEM,
00025 GCF_UNSAFE,
00026 GCF_STATIC,
00027 GCF_COMPATIBLE,
00028 GCF_COPY,
00029 GCF_INIT_ONLY,
00030 GCF_RESERVED,
00031 GCF_INVALID,
00032 };
00033
00035 enum GRFStatus {
00036 GCS_UNKNOWN,
00037 GCS_DISABLED,
00038 GCS_NOT_FOUND,
00039 GCS_INITIALISED,
00040 GCS_ACTIVATED,
00041 };
00042
00044 enum GRFBugs {
00045 GBUG_VEH_LENGTH,
00046 GBUG_VEH_REFIT,
00047 GBUG_VEH_POWERED_WAGON,
00048 GBUG_UNKNOWN_CB_RESULT,
00049 };
00050
00052 enum GRFListCompatibility {
00053 GLC_ALL_GOOD,
00054 GLC_COMPATIBLE,
00055 GLC_NOT_FOUND,
00056 };
00057
00059 enum GRFPalette {
00060 GRFP_USE_BIT = 0,
00061 GRFP_GRF_OFFSET = 2,
00062 GRFP_GRF_SIZE = 2,
00063 GRFP_BLT_OFFSET = 4,
00064 GRFP_BLT_SIZE = 1,
00065
00066 GRFP_USE_DOS = 0x0,
00067 GRFP_USE_WINDOWS = 0x1,
00068 GRFP_USE_MASK = 0x1,
00069
00070 GRFP_GRF_UNSET = 0x0 << GRFP_GRF_OFFSET,
00071 GRFP_GRF_DOS = 0x1 << GRFP_GRF_OFFSET,
00072 GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET,
00073 GRFP_GRF_ANY = GRFP_GRF_DOS | GRFP_GRF_WINDOWS,
00074 GRFP_GRF_MASK = GRFP_GRF_ANY,
00075
00076 GRFP_BLT_UNSET = 0x0 << GRFP_BLT_OFFSET,
00077 GRFP_BLT_32BPP = 0x1 << GRFP_BLT_OFFSET,
00078 GRFP_BLT_MASK = GRFP_BLT_32BPP,
00079 };
00080
00081
00083 struct GRFIdentifier {
00084 uint32 grfid;
00085 uint8 md5sum[16];
00086
00093 inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
00094 {
00095 if (this->grfid != grfid) return false;
00096 if (md5sum == NULL) return true;
00097 return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
00098 }
00099 };
00100
00102 struct GRFError : ZeroedMemoryAllocator {
00103 GRFError(StringID severity, StringID message = 0);
00104 GRFError(const GRFError &error);
00105 ~GRFError();
00106
00107 char *custom_message;
00108 char *data;
00109 StringID message;
00110 StringID severity;
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 struct GRFConfig : ZeroedMemoryAllocator {
00151 GRFConfig(const char *filename = NULL);
00152 GRFConfig(const GRFConfig &config);
00153 ~GRFConfig();
00154
00155 GRFIdentifier ident;
00156 uint8 original_md5sum[16];
00157 char *filename;
00158 GRFTextWrapper *name;
00159 GRFTextWrapper *info;
00160 GRFTextWrapper *url;
00161 GRFError *error;
00162
00163 uint32 version;
00164 uint32 min_loadable_version;
00165 uint8 flags;
00166 GRFStatus status;
00167 uint32 grf_bugs;
00168 uint32 param[0x80];
00169 uint8 num_params;
00170 uint8 num_valid_params;
00171 uint8 palette;
00172 SmallVector<GRFParameterInfo *, 4> param_info;
00173 bool has_param_defaults;
00174
00175 struct GRFConfig *next;
00176
00177 bool IsOpenTTDBaseGRF() const;
00178
00179 const char *GetTextfile(TextfileType type) const;
00180 const char *GetName() const;
00181 const char *GetDescription() const;
00182 const char *GetURL() const;
00183
00184 void SetParameterDefaults();
00185 void SetSuitablePalette();
00186 };
00187
00189 enum FindGRFConfigMode {
00190 FGCM_EXACT,
00191 FGCM_COMPATIBLE,
00192 FGCM_NEWEST,
00193 FGCM_NEWEST_VALID,
00194 FGCM_ANY,
00195 };
00196
00197 extern GRFConfig *_all_grfs;
00198 extern GRFConfig *_grfconfig;
00199 extern GRFConfig *_grfconfig_newgame;
00200 extern GRFConfig *_grfconfig_static;
00201
00203 struct NewGRFScanCallback {
00205 virtual ~NewGRFScanCallback() {}
00207 virtual void OnNewGRFsScanned() = 0;
00208 };
00209
00210 size_t GRFGetSizeOfDataSection(FILE *f);
00211
00212 void ScanNewGRFFiles(NewGRFScanCallback *callback);
00213 void CheckForMissingSprites();
00214 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
00215 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
00216 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
00217 void AppendStaticGRFConfigs(GRFConfig **dst);
00218 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
00219 void ClearGRFConfigList(GRFConfig **config);
00220 void ResetGRFConfig(bool defaults);
00221 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
00222 bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
00223 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
00224
00225
00226 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
00227
00228 #ifdef ENABLE_NETWORK
00229
00230 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
00231 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
00232 #endif
00233
00234 void UpdateNewGRFScanStatus(uint num, const char *name);
00235 bool UpdateNewGRFConfigPalette(int32 p1 = 0);
00236
00237 #endif