(svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info

pull/155/head
yexo 14 years ago
parent 1d145f1070
commit 23af928ce9

@ -457,7 +457,7 @@ static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
}
if (is->grf_prop.grffile != NULL) {
td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->name;
td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->GetName();
}
}

@ -190,7 +190,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS)
* 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_UDP_CLIENT_GET_NEWGRFS)
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_UDP_SERVER_RESPONSE)
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++;
}

@ -4334,7 +4334,7 @@ static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
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));
}

@ -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 *filename, size_t basepath_length)
/* 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 * const *p1, GRFConfig * const *p2)
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 */

@ -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

@ -131,9 +131,9 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint
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);

@ -2741,7 +2741,7 @@ static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
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(TileIndex tile, TileDesc *td)
if (ats->grf_prop.grffile != NULL) {
const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
td->grf = gc->name;
td->grf = gc->GetName();
}
}

@ -660,7 +660,7 @@ static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
if (hs->grffile != NULL) {
const GRFConfig *gc = GetGRFConfig(hs->grffile->grfid);
td->grf = gc->name;
td->grf = gc->GetName();
}
td->owner[0] = OWNER_TOWN;

@ -200,7 +200,7 @@ void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRF
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 engine, StringID part1, StringID part2, GRF
/* debug output */
char buffer[512];
SetDParamStr(0, grfconfig->name);
SetDParamStr(0, grfconfig->GetName());
GetString(buffer, part1, lastof(buffer));
DEBUG(grf, 0, "%s", buffer + 3);

Loading…
Cancel
Save