summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-02-28 20:28:08 +0000
committeryexo <yexo@openttd.org>2010-02-28 20:28:08 +0000
commit404df87b1f2e0c6ae8d71dd0ea83b55294f53af3 (patch)
tree868c12ba0cf41427a4c00eff31601f6e45398be4
parent333249ce501085405afabac8eb61a2c3ed599c0f (diff)
downloadopenttd-404df87b1f2e0c6ae8d71dd0ea83b55294f53af3.tar.xz
(svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
-rw-r--r--src/industry_cmd.cpp2
-rw-r--r--src/network/network_udp.cpp6
-rw-r--r--src/newgrf.cpp2
-rw-r--r--src/newgrf_config.cpp25
-rw-r--r--src/newgrf_config.h3
-rw-r--r--src/newgrf_gui.cpp22
-rw-r--r--src/station_cmd.cpp4
-rw-r--r--src/town_cmd.cpp2
-rw-r--r--src/vehicle.cpp4
9 files changed, 43 insertions, 27 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 36c8eccd4..b9574a8ab 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -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();
}
}
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 29ecebe37..14cab7647 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -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++;
}
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index c3e0de903..512c949a6 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -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));
}
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index a942279c8..16cb8b8ac 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -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 */
diff --git a/src/newgrf_config.h b/src/newgrf_config.h
index 9683340dd..0d97f0e44 100644
--- a/src/newgrf_config.h
+++ b/src/newgrf_config.h
@@ -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
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index ce7792405..4838623cf 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -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);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 337c7bad8..e2e62b91b 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -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();
}
}
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 28c2fe032..67d6c7546 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -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;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 9c32c14a6..bba6a5219 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -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);