Changeset - r10781:758b3ae29fdd
[Not reviewed]
master
0 3 0
peter1138 - 15 years ago 2009-01-16 19:53:52
peter1138@openttd.org
(svn r15114) -Codechange: Add support for 8 byte action7/9 data, used as a mask for GRFID checks.
3 files changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -3942,74 +3942,75 @@ static void SkipIf(byte *buf, size_t len
 
	/* <07/09> <param-num> <param-size> <condition-type> <value> <num-sprites>
 
	 *
 
	 * B param-num
 
	 * B param-size
 
	 * B condition-type
 
	 * V value
 
	 * B num-sprites */
 
	/* TODO: More params. More condition types. */
 
	uint32 cond_val = 0;
 
	uint32 mask = 0;
 
	bool result;
 

	
 
	if (!check_length(len, 6, "SkipIf")) return;
 
	buf++;
 
	uint8 param     = grf_load_byte(&buf);
 
	uint8 paramsize = grf_load_byte(&buf);
 
	uint8 condtype  = grf_load_byte(&buf);
 

	
 
	if (condtype < 2) {
 
		/* Always 1 for bit tests, the given value should be ignored. */
 
		paramsize = 1;
 
	}
 

	
 
	switch (paramsize) {
 
		case 8: cond_val = grf_load_dword(&buf); mask = grf_load_dword(&buf); break;
 
		case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
 
		case 2: cond_val = grf_load_word(&buf);  mask = 0x0000FFFF; break;
 
		case 1: cond_val = grf_load_byte(&buf);  mask = 0x000000FF; break;
 
		default: break;
 
	}
 

	
 
	if (param < 0x80 && _cur_grffile->param_end <= param) {
 
		grfmsg(7, "SkipIf: Param %d undefined, skipping test", param);
 
		return;
 
	}
 

	
 
	uint32 param_val = GetParamVal(param, &cond_val);
 

	
 
	grfmsg(7, "SkipIf: Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
 

	
 
	/*
 
	 * Parameter (variable in specs) 0x88 can only have GRF ID checking
 
	 * conditions, except conditions 0x0B and 0x0C (cargo availability)
 
	 * as those ignore the parameter. So, when the condition type is
 
	 * either of those, the specific variable 0x88 code is skipped, so
 
	 * the "general" code for the cargo availability conditions kicks in.
 
	 */
 
	if (param == 0x88 && condtype != 0x0B && condtype != 0x0C) {
 
		/* GRF ID checks */
 

	
 
		GRFConfig *c = GetGRFConfig(cond_val);
 
		GRFConfig *c = GetGRFConfig(cond_val, mask);
 

	
 
		if (c != NULL && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur_grfconfig->flags, GCF_STATIC) && c->status != GCS_DISABLED && _networking) {
 
			DisableStaticNewGRFInfluencingNonStaticNewGRFs(c);
 
			c = NULL;
 
		}
 

	
 
		if (condtype != 10 && c == NULL) {
 
			grfmsg(7, "SkipIf: GRFID 0x%08X unknown, skipping test", BSWAP32(cond_val));
 
			return;
 
		}
 

	
 
		switch (condtype) {
 
			/* Tests 0x06 to 0x0A are only for param 0x88, GRFID checks */
 
			case 0x06: // Is GRFID active?
 
				result = c->status == GCS_ACTIVATED;
 
				break;
 

	
 
			case 0x07: // Is GRFID non-active?
 
				result = c->status != GCS_ACTIVATED;
 
				break;
 

	
 
			case 0x08: // GRFID is not but will be active?
 
				result = c->status == GCS_INITIALISED;
 
				break;
src/newgrf_config.cpp
Show inline comments
 
@@ -435,54 +435,54 @@ char *FindUnknownGRFName(uint32 grfid, u
 
	static UnknownGRF *unknown_grfs = NULL;
 

	
 
	for (grf = unknown_grfs; grf != NULL; grf = grf->next) {
 
		if (grf->grfid == grfid) {
 
			if (memcmp(md5sum, grf->md5sum, sizeof(grf->md5sum)) == 0) return grf->name;
 
		}
 
	}
 

	
 
	if (!create) return NULL;
 

	
 
	grf = CallocT<UnknownGRF>(1);
 
	grf->grfid = grfid;
 
	grf->next  = unknown_grfs;
 
	strecpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, lastof(grf->name));
 
	memcpy(grf->md5sum, md5sum, sizeof(grf->md5sum));
 

	
 
	unknown_grfs = grf;
 
	return grf->name;
 
}
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 

	
 
/* Retrieve a NewGRF from the current config by its grfid */
 
GRFConfig *GetGRFConfig(uint32 grfid)
 
GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask)
 
{
 
	GRFConfig *c;
 

	
 
	for (c = _grfconfig; c != NULL; c = c->next) {
 
		if (c->grfid == grfid) return c;
 
		if ((c->grfid & mask) == (grfid & mask)) return c;
 
	}
 

	
 
	return NULL;
 
}
 

	
 

	
 
/* Build a space separated list of parameters, and terminate */
 
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
 
{
 
	uint i;
 

	
 
	/* Return an empty string if there are no parameters */
 
	if (c->num_params == 0) return strecpy(dst, "", last);
 

	
 
	for (i = 0; i < c->num_params; i++) {
 
		if (i > 0) dst = strecpy(dst, " ", last);
 
		dst += seprintf(dst, last, "%d", c->param[i]);
 
	}
 
	return dst;
 
}
 

	
 
/** Base GRF ID for OpenTTD's base graphics GRFs. */
 
static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400);
 

	
src/newgrf_config.h
Show inline comments
 
@@ -61,45 +61,45 @@ struct GRFConfig : public GRFIdentifier 
 
	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)
 
	GRFError *error;    ///< NOSAVE: Error/Warning during GRF loading (Action 0x0B)
 

	
 
	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
 
	bool windows_paletted;  ///< Whether the NewGRF is Windows paletted or not
 

	
 
	struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
 

	
 
	bool IsOpenTTDBaseGRF() const;
 
};
 

	
 
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
 

	
 
void ScanNewGRFFiles();
 
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum = NULL);
 
GRFConfig *GetGRFConfig(uint32 grfid);
 
GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
 
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
 
void AppendStaticGRFConfigs(GRFConfig **dst);
 
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
 
void ClearGRFConfig(GRFConfig **config);
 
void ClearGRFConfigList(GRFConfig **config);
 
void ResetGRFConfig(bool defaults);
 
GRFListCompatibility IsGoodGRFConfigList();
 
bool FillGRFDetails(GRFConfig *config, bool is_static);
 
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
 

	
 
/* In newgrf_gui.cpp */
 
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
 

	
 
#ifdef ENABLE_NETWORK
 
/* For communication about GRFs over the network */
 
#define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
 
char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
 
#endif /* ENABLE_NETWORK */
 

	
 
#endif /* NEWGRF_CONFIG_H */
0 comments (0 inline, 0 general)