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
00021 enum GCF_Flags {
00022 GCF_SYSTEM,
00023 GCF_UNSAFE,
00024 GCF_STATIC,
00025 GCF_COMPATIBLE,
00026 GCF_COPY,
00027 GCF_INIT_ONLY,
00028 GCF_RESERVED,
00029 GCF_INVALID,
00030 };
00031
00033 enum GRFStatus {
00034 GCS_UNKNOWN,
00035 GCS_DISABLED,
00036 GCS_NOT_FOUND,
00037 GCS_INITIALISED,
00038 GCS_ACTIVATED
00039 };
00040
00042 enum GRFBugs {
00043 GBUG_VEH_LENGTH,
00044 GBUG_VEH_REFIT,
00045 GBUG_VEH_POWERED_WAGON,
00046 };
00047
00049 enum GRFListCompatibility {
00050 GLC_ALL_GOOD,
00051 GLC_COMPATIBLE,
00052 GLC_NOT_FOUND
00053 };
00054
00056 enum GRFPalette {
00057 GRFP_USE_BIT = 0,
00058 GRFP_GRF_OFFSET = 2,
00059 GRFP_GRF_SIZE = 2,
00060
00061 GRFP_USE_DOS = 0x0,
00062 GRFP_USE_WINDOWS = 0x1,
00063 GRFP_USE_MASK = 0x1,
00064
00065 GRFP_GRF_UNSET = 0x0 << GRFP_GRF_OFFSET,
00066 GRFP_GRF_DOS = 0x1 << GRFP_GRF_OFFSET,
00067 GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET,
00068 GRFP_GRF_ANY = GRFP_GRF_DOS | GRFP_GRF_WINDOWS,
00069 GRFP_GRF_MASK = GRFP_GRF_ANY,
00070 };
00071
00072
00074 struct GRFIdentifier {
00075 uint32 grfid;
00076 uint8 md5sum[16];
00077
00084 FORCEINLINE bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
00085 {
00086 if (this->grfid != grfid) return false;
00087 if (md5sum == NULL) return true;
00088 return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
00089 }
00090 };
00091
00093 struct GRFError : ZeroedMemoryAllocator {
00094 GRFError(StringID severity, StringID message = 0);
00095 GRFError(const GRFError &error);
00096 ~GRFError();
00097
00098 char *custom_message;
00099 char *data;
00100 StringID message;
00101 StringID severity;
00102 uint8 num_params;
00103 uint32 param_value[2];
00104 };
00105
00107 enum GRFParameterType {
00108 PTYPE_UINT_ENUM,
00109 PTYPE_BOOL,
00110 PTYPE_END,
00111 };
00112
00114 struct GRFParameterInfo {
00115 GRFParameterInfo(uint nr);
00116 GRFParameterInfo(GRFParameterInfo &info);
00117 ~GRFParameterInfo();
00118 struct GRFText *name;
00119 struct GRFText *desc;
00120 GRFParameterType type;
00121 uint32 min_value;
00122 uint32 max_value;
00123 uint32 def_value;
00124 byte param_nr;
00125 byte first_bit;
00126 byte num_bit;
00127 SmallMap<uint32, struct GRFText *, 8> value_names;
00128
00129 uint32 GetValue(struct GRFConfig *config) const;
00130 void SetValue(struct GRFConfig *config, uint32 value);
00131 };
00132
00134 struct GRFTextWrapper : public SimpleCountedObject {
00135 struct GRFText *text;
00136
00137 GRFTextWrapper();
00138 ~GRFTextWrapper();
00139 };
00140
00142 struct GRFConfig : ZeroedMemoryAllocator {
00143 GRFConfig(const char *filename = NULL);
00144 GRFConfig(const GRFConfig &config);
00145 ~GRFConfig();
00146
00147 GRFIdentifier ident;
00148 uint8 original_md5sum[16];
00149 char *filename;
00150 GRFTextWrapper *name;
00151 GRFTextWrapper *info;
00152 GRFError *error;
00153
00154 uint32 version;
00155 uint32 min_loadable_version;
00156 uint8 flags;
00157 GRFStatus status;
00158 uint32 grf_bugs;
00159 uint32 param[0x80];
00160 uint8 num_params;
00161 uint8 num_valid_params;
00162 uint8 palette;
00163 SmallVector<GRFParameterInfo *, 4> param_info;
00164 bool has_param_defaults;
00165
00166 struct GRFConfig *next;
00167
00168 bool IsOpenTTDBaseGRF() const;
00169
00170 const char *GetName() const;
00171 const char *GetDescription() const;
00172
00173 void SetParameterDefaults();
00174 void SetSuitablePalette();
00175 };
00176
00178 enum FindGRFConfigMode {
00179 FGCM_EXACT,
00180 FGCM_COMPATIBLE,
00181 FGCM_NEWEST,
00182 FGCM_NEWEST_VALID,
00183 FGCM_ANY,
00184 };
00185
00186 extern GRFConfig *_all_grfs;
00187 extern GRFConfig *_grfconfig;
00188 extern GRFConfig *_grfconfig_newgame;
00189 extern GRFConfig *_grfconfig_static;
00190
00191 void ScanNewGRFFiles();
00192 void CheckForMissingSprites();
00193 const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
00194 GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
00195 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
00196 void AppendStaticGRFConfigs(GRFConfig **dst);
00197 void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
00198 void ClearGRFConfigList(GRFConfig **config);
00199 void ResetGRFConfig(bool defaults);
00200 GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
00201 bool FillGRFDetails(GRFConfig *config, bool is_static);
00202 char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
00203
00204
00205 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
00206
00207 #ifdef ENABLE_NETWORK
00208
00209 #define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
00210 GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
00211 #endif
00212
00213 #endif