2006-12-04 08:30:04 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file newgrf_config.h Functions to find and configure NewGRFs. */
|
2007-03-21 03:06:21 +00:00
|
|
|
|
2006-12-04 08:30:04 +00:00
|
|
|
#ifndef NEWGRF_CONFIG_H
|
|
|
|
#define NEWGRF_CONFIG_H
|
|
|
|
|
2007-12-26 23:04:26 +00:00
|
|
|
#include "strings_type.h"
|
2010-02-25 15:54:40 +00:00
|
|
|
#include "core/alloc_type.hpp"
|
2010-07-31 09:51:04 +00:00
|
|
|
#include "core/smallmap_type.hpp"
|
2011-03-03 18:47:46 +00:00
|
|
|
#include "misc/countedptr.hpp"
|
2011-08-24 13:48:29 +00:00
|
|
|
#include "fileio_type.h"
|
2007-02-24 16:34:37 +00:00
|
|
|
|
2008-04-02 00:13:44 +00:00
|
|
|
/** GRF config bit flags */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum GCF_Flags {
|
2008-04-02 00:13:44 +00:00
|
|
|
GCF_SYSTEM, ///< GRF file is an openttd-internal system grf
|
|
|
|
GCF_UNSAFE, ///< GRF file is unsafe for static usage
|
|
|
|
GCF_STATIC, ///< GRF file is used statically (can be used in any MP game)
|
|
|
|
GCF_COMPATIBLE, ///< GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
|
|
|
|
GCF_COPY, ///< The data is copied from a grf in _all_grfs
|
|
|
|
GCF_INIT_ONLY, ///< GRF file is processed up to GLS_INIT
|
|
|
|
GCF_RESERVED, ///< GRF file passed GLS_RESERVE stage
|
2011-01-15 21:13:47 +00:00
|
|
|
GCF_INVALID, ///< GRF is unusable with this version of OpenTTD
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-12-04 08:30:04 +00:00
|
|
|
|
2008-04-02 00:13:44 +00:00
|
|
|
/** Status of GRF */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum GRFStatus {
|
2007-03-06 19:33:28 +00:00
|
|
|
GCS_UNKNOWN, ///< The status of this grf file is unknown
|
|
|
|
GCS_DISABLED, ///< GRF file is disabled
|
|
|
|
GCS_NOT_FOUND, ///< GRF file was not found in the local cache
|
|
|
|
GCS_INITIALISED, ///< GRF file has been initialised
|
|
|
|
GCS_ACTIVATED ///< GRF file has been activated
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2007-03-06 19:33:28 +00:00
|
|
|
|
2008-07-24 15:19:26 +00:00
|
|
|
/** Encountered GRF bugs */
|
|
|
|
enum GRFBugs {
|
2010-08-15 19:59:48 +00:00
|
|
|
GBUG_VEH_LENGTH, ///< Length of rail vehicle changes when not inside a depot
|
|
|
|
GBUG_VEH_REFIT, ///< Articulated vehicles carry different cargos resp. are differently refittable than specified in purchase list
|
|
|
|
GBUG_VEH_POWERED_WAGON, ///< Powered wagon changed poweredness state when not inside a depot
|
2011-11-08 17:24:15 +00:00
|
|
|
GBUG_UNKNOWN_CB_RESULT, ///< A callback returned an unknown/invalid result
|
2008-07-24 15:19:26 +00:00
|
|
|
};
|
|
|
|
|
2008-04-02 00:13:44 +00:00
|
|
|
/** Status of post-gameload GRF compatibility check */
|
2008-07-24 15:19:26 +00:00
|
|
|
enum GRFListCompatibility {
|
2008-04-02 00:13:44 +00:00
|
|
|
GLC_ALL_GOOD, ///< All GRF needed by game are present
|
|
|
|
GLC_COMPATIBLE, ///< Compatible (eg. the same ID, but different chacksum) GRF found in at least one case
|
|
|
|
GLC_NOT_FOUND ///< At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2007-03-06 19:33:28 +00:00
|
|
|
|
2010-07-31 09:40:43 +00:00
|
|
|
/** Information that can/has to be stored about a GRF's palette. */
|
|
|
|
enum GRFPalette {
|
|
|
|
GRFP_USE_BIT = 0, ///< The bit used for storing the palette to use.
|
2010-07-31 09:44:38 +00:00
|
|
|
GRFP_GRF_OFFSET = 2, ///< The offset of the GRFP_GRF data.
|
|
|
|
GRFP_GRF_SIZE = 2, ///< The size of the GRFP_GRF data.
|
2011-10-04 21:35:52 +00:00
|
|
|
GRFP_BLT_OFFSET = 4, ///< The offset of the GRFP_BLT data.
|
|
|
|
GRFP_BLT_SIZE = 1, ///< The size of the GRFP_BLT data.
|
2010-07-31 09:40:43 +00:00
|
|
|
|
|
|
|
GRFP_USE_DOS = 0x0, ///< The palette state is set to use the DOS palette.
|
|
|
|
GRFP_USE_WINDOWS = 0x1, ///< The palette state is set to use the Windows palette.
|
|
|
|
GRFP_USE_MASK = 0x1, ///< Bitmask to get only the use palette use states.
|
2010-07-31 09:44:38 +00:00
|
|
|
|
|
|
|
GRFP_GRF_UNSET = 0x0 << GRFP_GRF_OFFSET, ///< The NewGRF provided no information.
|
|
|
|
GRFP_GRF_DOS = 0x1 << GRFP_GRF_OFFSET, ///< The NewGRF says the DOS palette can be used.
|
|
|
|
GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET, ///< The NewGRF says the Windows palette can be used.
|
|
|
|
GRFP_GRF_ANY = GRFP_GRF_DOS | GRFP_GRF_WINDOWS, ///< The NewGRF says any palette can be used.
|
|
|
|
GRFP_GRF_MASK = GRFP_GRF_ANY, ///< Bitmask to get only the NewGRF supplied information.
|
2011-10-04 21:35:52 +00:00
|
|
|
|
|
|
|
GRFP_BLT_UNSET = 0x0 << GRFP_BLT_OFFSET, ///< The NewGRF provided no information or doesn't care about a 32 bpp blitter.
|
|
|
|
GRFP_BLT_32BPP = 0x1 << GRFP_BLT_OFFSET, ///< The NewGRF prefers a 32 bpp blitter.
|
|
|
|
GRFP_BLT_MASK = GRFP_BLT_32BPP, ///< Bitmask to only get the blitter information.
|
2010-07-31 09:40:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-02 00:13:44 +00:00
|
|
|
/** Basic data to distinguish a GRF. Used in the server list window */
|
2007-03-07 12:11:48 +00:00
|
|
|
struct GRFIdentifier {
|
2008-04-02 00:13:44 +00:00
|
|
|
uint32 grfid; ///< GRF ID (defined by Action 0x08)
|
|
|
|
uint8 md5sum[16]; ///< MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
|
2010-05-16 18:50:37 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Does the identification match the provided values?
|
2010-05-16 18:50:37 +00:00
|
|
|
* @param grfid Expected grfid.
|
|
|
|
* @param md5sum Expected md5sum, may be \c NULL (in which case, do not check it).
|
|
|
|
* @return the object has the provided grfid and md5sum.
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
|
|
|
|
{
|
|
|
|
if (this->grfid != grfid) return false;
|
|
|
|
if (md5sum == NULL) return true;
|
|
|
|
return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
|
|
|
|
}
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2007-01-21 17:29:38 +00:00
|
|
|
|
2008-04-02 00:13:44 +00:00
|
|
|
/** Information about why GRF had problems during initialisation */
|
2010-02-25 15:54:40 +00:00
|
|
|
struct GRFError : ZeroedMemoryAllocator {
|
|
|
|
GRFError(StringID severity, StringID message = 0);
|
2010-07-31 09:32:44 +00:00
|
|
|
GRFError(const GRFError &error);
|
2010-02-25 15:54:40 +00:00
|
|
|
~GRFError();
|
|
|
|
|
2008-04-02 00:13:44 +00:00
|
|
|
char *custom_message; ///< Custom message (if present)
|
|
|
|
char *data; ///< Additional data for message and custom_message
|
|
|
|
StringID message; ///< Default message
|
|
|
|
StringID severity; ///< Info / Warning / Error / Fatal
|
2009-05-04 11:23:21 +00:00
|
|
|
uint8 num_params; ///< Number of additinal parameters for message and custom_message (0, 1 or 2)
|
|
|
|
uint32 param_value[2]; ///< Values of GRF parameters to show for message and custom_message
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2007-02-24 16:34:37 +00:00
|
|
|
|
2010-07-31 09:51:04 +00:00
|
|
|
/** The possible types of a newgrf parameter. */
|
|
|
|
enum GRFParameterType {
|
|
|
|
PTYPE_UINT_ENUM, ///< The parameter allows a range of numbers, each of which can have a special name
|
|
|
|
PTYPE_BOOL, ///< The parameter is either 0 or 1
|
|
|
|
PTYPE_END, ///< Invalid parameter type
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Information about one grf parameter. */
|
|
|
|
struct GRFParameterInfo {
|
|
|
|
GRFParameterInfo(uint nr);
|
|
|
|
GRFParameterInfo(GRFParameterInfo &info);
|
|
|
|
~GRFParameterInfo();
|
|
|
|
struct GRFText *name; ///< The name of this parameter
|
|
|
|
struct GRFText *desc; ///< The description of this parameter
|
|
|
|
GRFParameterType type; ///< The type of this parameter
|
|
|
|
uint32 min_value; ///< The minimal value this parameter can have
|
|
|
|
uint32 max_value; ///< The maximal value of this parameter
|
2010-08-23 21:47:07 +00:00
|
|
|
uint32 def_value; ///< Default value of this parameter
|
2010-07-31 09:51:04 +00:00
|
|
|
byte param_nr; ///< GRF parameter to store content in
|
|
|
|
byte first_bit; ///< First bit to use in the GRF parameter
|
|
|
|
byte num_bit; ///< Number of bits to use for this parameter
|
|
|
|
SmallMap<uint32, struct GRFText *, 8> value_names; ///< Names for each value.
|
2010-07-31 12:15:12 +00:00
|
|
|
|
|
|
|
uint32 GetValue(struct GRFConfig *config) const;
|
|
|
|
void SetValue(struct GRFConfig *config, uint32 value);
|
2010-07-31 09:51:04 +00:00
|
|
|
};
|
|
|
|
|
2011-03-03 18:47:46 +00:00
|
|
|
/** Reference counted wrapper around a GRFText pointer. */
|
|
|
|
struct GRFTextWrapper : public SimpleCountedObject {
|
|
|
|
struct GRFText *text; ///< The actual text
|
|
|
|
|
|
|
|
GRFTextWrapper();
|
|
|
|
~GRFTextWrapper();
|
|
|
|
};
|
|
|
|
|
2011-11-18 14:40:57 +00:00
|
|
|
/** Additional text files accompanying NewGRFs */
|
|
|
|
enum TextfileType {
|
|
|
|
TFT_BEGIN,
|
|
|
|
|
|
|
|
TFT_README = TFT_BEGIN, ///< NewGRF readme
|
|
|
|
TFT_CHANGELOG, ///< NewGRF changelog
|
|
|
|
TFT_LICENSE, ///< NewGRF license
|
|
|
|
|
|
|
|
TFT_END
|
|
|
|
};
|
|
|
|
DECLARE_POSTFIX_INCREMENT(TextfileType)
|
|
|
|
|
2008-04-02 00:13:44 +00:00
|
|
|
/** Information about GRF, used in the game and (part of it) in savegames */
|
2010-02-25 20:06:11 +00:00
|
|
|
struct GRFConfig : ZeroedMemoryAllocator {
|
|
|
|
GRFConfig(const char *filename = NULL);
|
2010-07-31 09:32:44 +00:00
|
|
|
GRFConfig(const GRFConfig &config);
|
2010-02-25 20:06:11 +00:00
|
|
|
~GRFConfig();
|
|
|
|
|
2010-10-17 12:13:35 +00:00
|
|
|
GRFIdentifier ident; ///< grfid and md5sum to uniquely identify newgrfs
|
|
|
|
uint8 original_md5sum[16]; ///< MD5 checksum of original file if only a 'compatible' file was loaded
|
|
|
|
char *filename; ///< Filename - either with or without full path
|
2011-03-03 18:47:46 +00:00
|
|
|
GRFTextWrapper *name; ///< NOSAVE: GRF name (Action 0x08)
|
|
|
|
GRFTextWrapper *info; ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
|
2010-10-17 12:13:35 +00:00
|
|
|
GRFError *error; ///< NOSAVE: Error/Warning during GRF loading (Action 0x0B)
|
|
|
|
|
|
|
|
uint32 version; ///< NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown
|
2010-10-17 12:12:52 +00:00
|
|
|
uint32 min_loadable_version; ///< NOSAVE: Minimum compatible version a NewGRF can define
|
2010-10-17 12:13:35 +00:00
|
|
|
uint8 flags; ///< NOSAVE: GCF_Flags, bitset
|
|
|
|
GRFStatus status; ///< NOSAVE: GRFStatus, enum
|
|
|
|
uint32 grf_bugs; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
|
|
|
|
uint32 param[0x80]; ///< GRF parameters
|
|
|
|
uint8 num_params; ///< Number of used parameters
|
|
|
|
uint8 num_valid_params; ///< NOSAVE: Number of valid parameters (action 0x14)
|
|
|
|
uint8 palette; ///< GRFPalette, bitset
|
2010-07-31 09:51:04 +00:00
|
|
|
SmallVector<GRFParameterInfo *, 4> param_info; ///< NOSAVE: extra information about the parameters
|
2010-10-17 12:13:35 +00:00
|
|
|
bool has_param_defaults; ///< NOSAVE: did this newgrf specify any defaults for it's parameters
|
2006-12-04 08:30:04 +00:00
|
|
|
|
2010-10-17 12:13:35 +00:00
|
|
|
struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
|
2007-11-15 07:42:25 +00:00
|
|
|
|
|
|
|
bool IsOpenTTDBaseGRF() const;
|
2010-02-28 20:28:08 +00:00
|
|
|
|
2011-11-18 14:40:57 +00:00
|
|
|
const char *GetTextfile(TextfileType type) const;
|
2010-02-28 20:28:08 +00:00
|
|
|
const char *GetName() const;
|
|
|
|
const char *GetDescription() const;
|
2010-07-31 09:36:09 +00:00
|
|
|
|
2010-08-23 21:47:07 +00:00
|
|
|
void SetParameterDefaults();
|
2010-07-31 09:36:09 +00:00
|
|
|
void SetSuitablePalette();
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-12-04 08:30:04 +00:00
|
|
|
|
2010-10-17 12:12:13 +00:00
|
|
|
/** Method to find GRFs using FindGRFConfig */
|
|
|
|
enum FindGRFConfigMode {
|
|
|
|
FGCM_EXACT, ///< Only find Grfs matching md5sum
|
2010-10-17 12:12:52 +00:00
|
|
|
FGCM_COMPATIBLE, ///< Find best compatible Grf wrt. desired_version
|
2010-10-17 12:12:13 +00:00
|
|
|
FGCM_NEWEST, ///< Find newest Grf
|
2011-01-15 21:13:47 +00:00
|
|
|
FGCM_NEWEST_VALID,///< Find newest Grf, ignoring Grfs with GCF_INVALID set
|
2010-10-17 12:12:13 +00:00
|
|
|
FGCM_ANY, ///< Use first found
|
|
|
|
};
|
|
|
|
|
2008-04-02 00:13:44 +00:00
|
|
|
extern GRFConfig *_all_grfs; ///< First item in list of all scanned NewGRFs
|
|
|
|
extern GRFConfig *_grfconfig; ///< First item in list of current GRF set up
|
|
|
|
extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set up
|
|
|
|
extern GRFConfig *_grfconfig_static; ///< First item in list of static GRF set up
|
2006-12-12 19:38:41 +00:00
|
|
|
|
2011-08-21 12:49:51 +00:00
|
|
|
/** Callback for NewGRF scanning. */
|
|
|
|
struct NewGRFScanCallback {
|
|
|
|
/** Make sure the right destructor gets called. */
|
|
|
|
virtual ~NewGRFScanCallback() {}
|
|
|
|
/** Called whenever the NewGRF scan completed. */
|
|
|
|
virtual void OnNewGRFsScanned() = 0;
|
|
|
|
};
|
|
|
|
|
2011-08-21 12:51:18 +00:00
|
|
|
void ScanNewGRFFiles(NewGRFScanCallback *callback);
|
2010-08-19 19:23:38 +00:00
|
|
|
void CheckForMissingSprites();
|
2010-10-17 12:12:52 +00:00
|
|
|
const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0);
|
2009-01-16 19:53:52 +00:00
|
|
|
GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
|
2007-06-18 23:00:55 +00:00
|
|
|
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
|
2006-12-27 18:25:17 +00:00
|
|
|
void AppendStaticGRFConfigs(GRFConfig **dst);
|
2007-02-22 16:16:44 +00:00
|
|
|
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
|
2006-12-20 21:17:33 +00:00
|
|
|
void ClearGRFConfigList(GRFConfig **config);
|
2006-12-04 08:30:04 +00:00
|
|
|
void ResetGRFConfig(bool defaults);
|
2010-06-13 14:07:49 +00:00
|
|
|
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
|
2011-08-24 13:48:29 +00:00
|
|
|
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR);
|
2006-12-10 11:29:14 +00:00
|
|
|
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
|
2006-12-04 08:30:04 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* In newgrf_gui.cpp */
|
2006-12-21 10:29:16 +00:00
|
|
|
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2006-12-31 11:12:49 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2011-05-02 16:14:23 +00:00
|
|
|
/** For communication about GRFs over the network */
|
2006-12-18 12:26:55 +00:00
|
|
|
#define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
|
2011-03-03 18:47:46 +00:00
|
|
|
GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
|
2006-12-31 11:12:49 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2006-12-18 12:26:55 +00:00
|
|
|
|
2011-08-21 12:53:13 +00:00
|
|
|
void UpdateNewGRFScanStatus(uint num, const char *name);
|
|
|
|
|
2006-12-04 08:30:04 +00:00
|
|
|
#endif /* NEWGRF_CONFIG_H */
|