Changeset - r15196:77940844856f
[Not reviewed]
master
0 2 0
alberth - 14 years ago 2010-05-16 18:50:37
alberth@openttd.org
(svn r19835) -Codechange: Extract grfident equality check to its own method.
2 files changed with 13 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/newgrf_config.cpp
Show inline comments
 
@@ -431,53 +431,49 @@ void ScanNewGRFFiles()
 
	QSortT(to_sort, num, &GRFSorter);
 

	
 
	for (i = 1; i < num; i++) {
 
		to_sort[i - 1]->next = to_sort[i];
 
	}
 
	to_sort[num - 1]->next = NULL;
 
	_all_grfs = to_sort[0];
 

	
 
	free(to_sort);
 

	
 
#ifdef ENABLE_NETWORK
 
	NetworkAfterNewGRFScan();
 
#endif
 
}
 

	
 

	
 
/** Find a NewGRF in the scanned list.
 
 * @param grfid GRFID to look for,
 
 * @param md5sum Expected MD5 sum (set to \c NULL if not relevant).
 
 * @return The matching grf, if it exists in #_all_grfs, else \c NULL.
 
 */
 
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
 
{
 
	for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
 
		if (c->ident.grfid == grfid) {
 
			if (md5sum == NULL) return c;
 

	
 
			if (memcmp(md5sum, c->ident.md5sum, sizeof(c->ident.md5sum)) == 0) return c;
 
		}
 
		if (c->ident.HasGrfIdentifier(grfid, md5sum)) return c;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */
 
struct UnknownGRF : public GRFIdentifier {
 
	UnknownGRF *next;
 
	char   name[NETWORK_GRF_NAME_LENGTH];
 
};
 

	
 
/**
 
 * Finds the name of a NewGRF in the list of names for unknown GRFs. An
 
 * unknown GRF is a GRF where the .grf is not found during scanning.
 
 *
 
 * The names are resolved via UDP calls to servers that should know the name,
 
 * though the replies may not come. This leaves "<Unknown>" as name, though
 
 * that shouldn't matter _very_ much as they need GRF crawler or so to look
 
 * up the GRF anyway and that works better with the GRF ID.
 
 *
 
 * @param grfid  the GRF ID part of the 'unique' GRF identifier
 
 * @param md5sum the MD5 checksum part of the 'unique' GRF identifier
src/newgrf_config.h
Show inline comments
 
@@ -32,48 +32,60 @@ enum GRFStatus {
 
	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
 
};
 

	
 
/** Encountered GRF bugs */
 
enum GRFBugs {
 
	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
 
};
 

	
 
/** Status of post-gameload GRF compatibility check */
 
enum GRFListCompatibility {
 
	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)
 
};
 

	
 
/** Basic data to distinguish a GRF. Used in the server list window */
 
struct GRFIdentifier {
 
	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)
 

	
 
	/** Does the identification match the provided values?
 
	 * @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;
 
	}
 
};
 

	
 
/** Information about why GRF had problems during initialisation */
 
struct GRFError : ZeroedMemoryAllocator {
 
	GRFError(StringID severity, StringID message = 0);
 
	~GRFError();
 

	
 
	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
 
	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
 
};
 

	
 
/** Information about GRF, used in the game and (part of it) in savegames */
 
struct GRFConfig : ZeroedMemoryAllocator {
 
	GRFConfig(const char *filename = NULL);
 
	~GRFConfig();
 

	
 
	GRFIdentifier ident; ///< grfid and md5sum to uniquely identify newgrfs
 
	char *filename;     ///< Filename - either with or without full path
 
	char *name;         ///< NOSAVE: GRF name (Action 0x08)
 
	char *info;         ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
0 comments (0 inline, 0 general)