Changeset - r18637:6db0bce1fa51
[Not reviewed]
master
0 4 0
yexo - 12 years ago 2011-12-11 12:55:04
yexo@openttd.org
(svn r23494) -Feature: [NewGRF] action14 node INFO->URL_ to add an url
4 files changed with 27 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/network/network_udp.cpp
Show inline comments
 
@@ -418,12 +418,15 @@ void ClientNetworkUDPSocketHandler::Hand
 
		config->name->Release();
 
		config->name = f->name;
 
		config->name->AddRef();
 
		config->info->Release();
 
		config->info = f->info;
 
		config->info->AddRef();
 
		config->url->Release();
 
		config->url = f->url;
 
		config->url->AddRef();
 
	}
 
	SetBit(config->flags, GCF_COPY);
 
}
 

	
 
/** Broadcast to all ips */
 
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
src/newgrf.cpp
Show inline comments
 
@@ -7062,12 +7062,19 @@ static bool ChangeGRFName(byte langid, c
 
static bool ChangeGRFDescription(byte langid, const char *str)
 
{
 
	AddGRFTextToList(&_cur.grfconfig->info->text, langid, _cur.grfconfig->ident.grfid, true, str);
 
	return true;
 
}
 

	
 
/** Callback function for 'INFO'->'URL_' to set the newgrf url. */
 
static bool ChangeGRFURL(byte langid, const char *str)
 
{
 
	AddGRFTextToList(&_cur.grfconfig->url->text, langid, _cur.grfconfig->ident.grfid, false, str);
 
	return true;
 
}
 

	
 
/** Callback function for 'INFO'->'NPAR' to set the number of valid parameters. */
 
static bool ChangeGRFNumUsedParams(size_t len, ByteReader *buf)
 
{
 
	if (len != 1) {
 
		grfmsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got " PRINTF_SIZE ", ignoring this field", len);
 
		buf->Skip(len);
 
@@ -7409,12 +7416,13 @@ static bool HandleParameterInfo(ByteRead
 
}
 

	
 
/** Action14 tags for the INFO node */
 
AllowedSubtags _tags_info[] = {
 
	AllowedSubtags('NAME', ChangeGRFName),
 
	AllowedSubtags('DESC', ChangeGRFDescription),
 
	AllowedSubtags('URL_', ChangeGRFURL),
 
	AllowedSubtags('NPAR', ChangeGRFNumUsedParams),
 
	AllowedSubtags('PALS', ChangeGRFPalette),
 
	AllowedSubtags('BLTR', ChangeGRFBlitter),
 
	AllowedSubtags('VRSN', ChangeGRFVersion),
 
	AllowedSubtags('MINV', ChangeGRFMinVersion),
 
	AllowedSubtags('PARA', HandleParameterInfo),
src/newgrf_config.cpp
Show inline comments
 
@@ -41,28 +41,31 @@ GRFTextWrapper::~GRFTextWrapper()
 
 * @param filename Set the filename of this GRFConfig to filename. The argument
 
 *   is copied so the original string isn't needed after the constructor.
 
 */
 
GRFConfig::GRFConfig(const char *filename) :
 
	name(new GRFTextWrapper()),
 
	info(new GRFTextWrapper()),
 
	url(new GRFTextWrapper()),
 
	num_valid_params(lengthof(param))
 
{
 
	if (filename != NULL) this->filename = strdup(filename);
 
	this->name->AddRef();
 
	this->info->AddRef();
 
	this->url->AddRef();
 
}
 

	
 
/**
 
 * Create a new GRFConfig that is a deep copy of an existing config.
 
 * @param config The GRFConfig object to make a copy of.
 
 */
 
GRFConfig::GRFConfig(const GRFConfig &config) :
 
	ZeroedMemoryAllocator(),
 
	ident(config.ident),
 
	name(config.name),
 
	info(config.info),
 
	url(config.url),
 
	version(config.version),
 
	min_loadable_version(config.min_loadable_version),
 
	flags(config.flags & ~(1 << GCF_COPY)),
 
	status(config.status),
 
	grf_bugs(config.grf_bugs),
 
	num_params(config.num_params),
 
@@ -72,12 +75,13 @@ GRFConfig::GRFConfig(const GRFConfig &co
 
{
 
	MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));
 
	MemCpyT<uint32>(this->param, config.param, lengthof(this->param));
 
	if (config.filename != NULL) this->filename = strdup(config.filename);
 
	this->name->AddRef();
 
	this->info->AddRef();
 
	this->url->AddRef();
 
	if (config.error    != NULL) this->error    = new GRFError(*config.error);
 
	for (uint i = 0; i < config.param_info.Length(); i++) {
 
		if (config.param_info[i] == NULL) {
 
			*this->param_info.Append() = NULL;
 
		} else {
 
			*this->param_info.Append() = new GRFParameterInfo(*config.param_info[i]);
 
@@ -92,12 +96,13 @@ GRFConfig::~GRFConfig()
 
	if (!HasBit(this->flags, GCF_COPY)) {
 
		free(this->filename);
 
		delete this->error;
 
	}
 
	this->name->Release();
 
	this->info->Release();
 
	this->url->Release();
 

	
 
	for (uint i = 0; i < this->param_info.Length(); i++) delete this->param_info[i];
 
}
 

	
 
/**
 
 * Get the name of this grf. In case the name isn't known
 
@@ -116,12 +121,21 @@ const char *GRFConfig::GetName() const
 
 */
 
const char *GRFConfig::GetDescription() const
 
{
 
	return GetGRFStringFromGRFText(this->info->text);
 
}
 

	
 
/**
 
 * Get the grf url.
 
 * @return A string with an url of this grf.
 
 */
 
const char *GRFConfig::GetURL() const
 
{
 
	return GetGRFStringFromGRFText(this->url->text);
 
}
 

	
 
/** Set the default value for all parameters as specified by action14. */
 
void GRFConfig::SetParameterDefaults()
 
{
 
	this->num_params = 0;
 
	MemSetT<uint32>(this->param, 0, lengthof(this->param));
 

	
src/newgrf_config.h
Show inline comments
 
@@ -166,12 +166,13 @@ struct GRFConfig : ZeroedMemoryAllocator
 

	
 
	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
 
	GRFTextWrapper *name;                          ///< NOSAVE: GRF name (Action 0x08)
 
	GRFTextWrapper *info;                          ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
 
	GRFTextWrapper *url;                           ///< NOSAVE: URL belonging to this GRF.
 
	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
 
	uint32 min_loadable_version;                   ///< NOSAVE: Minimum compatible version a NewGRF can define
 
	uint8 flags;                                   ///< NOSAVE: GCF_Flags, bitset
 
	GRFStatus status;                              ///< NOSAVE: GRFStatus, enum
 
@@ -187,12 +188,13 @@ struct GRFConfig : ZeroedMemoryAllocator
 

	
 
	bool IsOpenTTDBaseGRF() const;
 

	
 
	const char *GetTextfile(TextfileType type) const;
 
	const char *GetName() const;
 
	const char *GetDescription() const;
 
	const char *GetURL() const;
 

	
 
	void SetParameterDefaults();
 
	void SetSuitablePalette();
 
};
 

	
 
/** Method to find GRFs using FindGRFConfig */
0 comments (0 inline, 0 general)