Changeset - r14701:3d820af7badc
[Not reviewed]
master
0 9 0
yexo - 14 years ago 2010-02-28 20:28:08
yexo@openttd.org
(svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
9 files changed with 43 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -457,7 +457,7 @@ static void GetTileDesc_Industry(TileInd
 
	}
 

	
 
	if (is->grf_prop.grffile != NULL) {
 
		td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->name;
 
		td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->GetName();
 
	}
 
}
 

	
src/network/network_udp.cpp
Show inline comments
 
@@ -190,7 +190,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_U
 
		 * the current list and do not send the other data.
 
		 * The name could be an empty string, if so take the filename. */
 
		packet_len += sizeof(c.grfid) + sizeof(c.md5sum) +
 
				min(strlen((!StrEmpty(f->name)) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
 
				min(strlen(f->GetName()) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
 
		if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
 
			break;
 
		}
 
@@ -206,7 +206,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_U
 
		char name[NETWORK_GRF_NAME_LENGTH];
 

	
 
		/* The name could be an empty string, if so take the filename */
 
		strecpy(name, (!StrEmpty(in_reply[i]->name)) ? in_reply[i]->name : in_reply[i]->filename, lastof(name));
 
		strecpy(name, in_reply[i]->GetName(), lastof(name));
 
		this->Send_GRFIdentifier(&packet, &in_reply[i]->ident);
 
		packet.Send_string(name);
 
	}
 
@@ -256,7 +256,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_U
 

	
 
		for (c = item->info.grfconfig; c != NULL; c = c->next) {
 
			if (c->status == GCS_NOT_FOUND) item->info.compatible = false;
 
			if (c->status != GCS_NOT_FOUND || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
 
			if (c->status != GCS_NOT_FOUND || strcmp(c->GetName(), UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
 
			in_request[in_request_count] = c;
 
			in_request_count++;
 
		}
src/newgrf.cpp
Show inline comments
 
@@ -4334,7 +4334,7 @@ static void DisableStaticNewGRFInfluenci
 
	delete c->error;
 
	c->status = GCS_DISABLED;
 
	c->error  = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC);
 
	c->error->data = strdup(_cur_grfconfig->name);
 
	c->error->data = strdup(_cur_grfconfig->GetName());
 

	
 
	ClearTemporaryNewGRFData(GetFileByGRFID(c->ident.grfid));
 
}
src/newgrf_config.cpp
Show inline comments
 
@@ -36,6 +36,26 @@ GRFConfig::~GRFConfig()
 
	}
 
}
 

	
 
/**
 
 * Get the name of this grf. In case the name isn't known
 
 * the filename is returned.
 
 * @return The name of filename of this grf.
 
 */
 
const char *GRFConfig::GetName() const
 
{
 
	if (this->name == NULL) return this->filename;
 
	return this->name;
 
}
 

	
 
/**
 
 * Get the grf info.
 
 * @return A string with a description of this grf.
 
 */
 
const char *GRFConfig::GetDescription() const
 
{
 
	return this->info;
 
}
 

	
 
GRFConfig *_all_grfs;
 
GRFConfig *_grfconfig;
 
GRFConfig *_grfconfig_newgame;
 
@@ -337,7 +357,7 @@ bool GRFFileScanner::AddFile(const char 
 
				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
 
				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
 
				 *  just after the first with the same name. Avoids doubles in the list. */
 
				if (strcasecmp(c->name, d->name) <= 0) {
 
				if (strcasecmp(c->GetName(), d->GetName()) <= 0) {
 
					stop = true;
 
				} else if (stop) {
 
					break;
 
@@ -372,8 +392,7 @@ static int CDECL GRFSorter(GRFConfig * c
 
	const GRFConfig *c1 = *p1;
 
	const GRFConfig *c2 = *p2;
 

	
 
	return strcasecmp(c1->name != NULL ? c1->name : c1->filename,
 
		c2->name != NULL ? c2->name : c2->filename);
 
	return strcasecmp(c1->GetName(), c2->GetName());
 
}
 

	
 
/* Scan for all NewGRFs */
src/newgrf_config.h
Show inline comments
 
@@ -89,6 +89,9 @@ struct GRFConfig : ZeroedMemoryAllocator
 
	struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
 

	
 
	bool IsOpenTTDBaseGRF() const;
 

	
 
	const char *GetName() const;
 
	const char *GetDescription() const;
 
};
 

	
 
extern GRFConfig *_all_grfs;          ///< First item in list of all scanned NewGRFs
src/newgrf_gui.cpp
Show inline comments
 
@@ -131,9 +131,9 @@ static void ShowNewGRFInfo(const GRFConf
 
	if (HasBit(c->flags, GCF_COMPATIBLE)) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_COMPATIBLE_LOADED);
 

	
 
	/* Draw GRF info if it exists */
 
	if (!StrEmpty(c->info)) {
 
	if (!StrEmpty(c->GetDescription())) {
 
		SetDParam(0, STR_JUST_RAW_STRING);
 
		SetDParamStr(1, c->info);
 
		SetDParamStr(1, c->GetDescription());
 
		y = DrawStringMultiLine(x, right, y, bottom, STR_BLACK_STRING);
 
	} else {
 
		y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NO_INFO);
 
@@ -203,13 +203,7 @@ private:
 
	/** Sort grfs by name. */
 
	static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b)
 
	{
 
		const char *name_a = ((*a)->name != NULL) ? (*a)->name : "";
 
		const char *name_b = ((*b)->name != NULL) ? (*b)->name : "";
 
		int result = strcasecmp(name_a, name_b);
 
		if (result == 0) {
 
			result = strcasecmp((*a)->filename, (*b)->filename);
 
		}
 
		return result;
 
		return strcasecmp((*a)->GetName(), (*b)->GetName());
 
	}
 

	
 
	/** Sort the grf list */
 
@@ -234,9 +228,9 @@ private:
 
	/** Filter grfs by tags/name */
 
	static bool CDECL TagNameFilter(const GRFConfig * const *a, const char *filter_string)
 
	{
 
		if ((*a)->name     != NULL && strcasestr((*a)->name,     filter_string) != NULL) return true;
 
		if (strcasestr((*a)->GetName(), filter_string) != NULL) return true;
 
		if ((*a)->filename != NULL && strcasestr((*a)->filename, filter_string) != NULL) return true;
 
		if ((*a)->info     != NULL && strcasestr((*a)->info,     filter_string) != NULL) return true;
 
		if ((*a)->GetDescription() != NULL && strcasestr((*a)->GetDescription(), filter_string) != NULL) return true;
 
		return false;
 
	}
 

	
 
@@ -326,7 +320,7 @@ public:
 
				{
 
					const GRFConfig *c = this->grfs[i];
 
					bool h = c == this->sel;
 
					const char *text = (!StrEmpty(c->name)) ? c->name : c->filename;
 
					const char *text = c->GetName();
 

	
 
					/* Draw selection background */
 
					if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + this->resize.step_height - 1, 156);
 
@@ -657,7 +651,7 @@ struct NewGRFWindow : public Window {
 
				int i = 0;
 
				for (const GRFConfig *c = this->list; c != NULL; c = c->next, i++) {
 
					if (this->vscroll.IsVisible(i)) {
 
						const char *text = (!StrEmpty(c->name)) ? c->name : c->filename;
 
						const char *text = c->GetName();
 
						PaletteID pal;
 

	
 
						/* Pick a colour */
 
@@ -861,7 +855,7 @@ struct NewGRFWindow : public Window {
 
						ContentInfo *ci = new ContentInfo();
 
						ci->type = CONTENT_TYPE_NEWGRF;
 
						ci->state = ContentInfo::DOES_NOT_EXIST;
 
						ttd_strlcpy(ci->name, c->name != NULL ? c->name : c->filename, lengthof(ci->name));
 
						ttd_strlcpy(ci->name, c->GetName(), lengthof(ci->name));
 
						ci->unique_id = BSWAP32(c->ident.grfid);
 
						memcpy(ci->md5sum, c->ident.md5sum, sizeof(ci->md5sum));
 
						if (HasBit(c->flags, GCF_COMPATIBLE)) GamelogGetOriginalGRFMD5Checksum(c->ident.grfid, ci->md5sum);
src/station_cmd.cpp
Show inline comments
 
@@ -2741,7 +2741,7 @@ static void GetTileDesc_Station(TileInde
 

	
 
			if (spec->grffile != NULL) {
 
				const GRFConfig *gc = GetGRFConfig(spec->grffile->grfid);
 
				td->grf = gc->name;
 
				td->grf = gc->GetName();
 
			}
 
		}
 
	}
 
@@ -2752,7 +2752,7 @@ static void GetTileDesc_Station(TileInde
 

	
 
		if (ats->grf_prop.grffile != NULL) {
 
			const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
 
			td->grf = gc->name;
 
			td->grf = gc->GetName();
 
		}
 
	}
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -660,7 +660,7 @@ static void GetTileDesc_Town(TileIndex t
 

	
 
	if (hs->grffile != NULL) {
 
		const GRFConfig *gc = GetGRFConfig(hs->grffile->grfid);
 
		td->grf = gc->name;
 
		td->grf = gc->GetName();
 
	}
 

	
 
	td->owner[0] = OWNER_TOWN;
src/vehicle.cpp
Show inline comments
 
@@ -200,7 +200,7 @@ void ShowNewGrfVehicleError(EngineID eng
 

	
 
	if (!HasBit(grfconfig->grf_bugs, bug_type)) {
 
		SetBit(grfconfig->grf_bugs, bug_type);
 
		SetDParamStr(0, grfconfig->name);
 
		SetDParamStr(0, grfconfig->GetName());
 
		SetDParam(1, engine);
 
		ShowErrorMessage(part1, part2, WL_CRITICAL);
 
		if (!_networking) DoCommand(0, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, 1, DC_EXEC, CMD_PAUSE);
 
@@ -209,7 +209,7 @@ void ShowNewGrfVehicleError(EngineID eng
 
	/* debug output */
 
	char buffer[512];
 

	
 
	SetDParamStr(0, grfconfig->name);
 
	SetDParamStr(0, grfconfig->GetName());
 
	GetString(buffer, part1, lastof(buffer));
 
	DEBUG(grf, 0, "%s", buffer + 3);
 

	
0 comments (0 inline, 0 general)