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