summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2017-02-26 15:30:25 +0000
committeralberth <alberth@openttd.org>2017-02-26 15:30:25 +0000
commite8635aca1af6a2481070681a879fce26c973aecb (patch)
tree21033f158f316eb9c19ce147d85c88206d40b297
parent8d5fae919ccafbbf611ccbd24ba9f1f605a8addc (diff)
downloadopenttd-e8635aca1af6a2481070681a879fce26c973aecb.tar.xz
(svn r27749) -Codechange: Fold cb37 cargo suffix text in a structure.
-rw-r--r--src/industry_gui.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index c16014224..5eae0b4c8 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -56,6 +56,11 @@ enum CargoSuffixType {
CST_DIR, ///< Industry-directory window
};
+/** Transfer storage of cargo suffix information. */
+struct CargoSuffix {
+ char text[512]; ///< Storage of the cargo suffix to print.
+};
+
static void ShowIndustryCargoesWindow(IndustryType id);
/**
@@ -71,11 +76,10 @@ static void ShowIndustryCargoesWindow(IndustryType id);
* @param ind_type the industry type
* @param indspec the industry spec
* @param suffix is filled with the string to display
- * @param suffix_last lastof(suffix)
*/
-static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, char *suffix, const char *suffix_last)
+static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoSuffix &suffix)
{
- suffix[0] = '\0';
+ suffix.text[0] = '\0';
if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) {
uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, (cst != CST_FUND) ? ind->location.tile : INVALID_TILE);
if (callback == CALLBACK_FAILED || callback == 0x400) return;
@@ -83,7 +87,7 @@ static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind,
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_CARGO_SUFFIX, callback);
} else if (indspec->grf_prop.grffile->grf_version >= 8 || GB(callback, 0, 8) != 0xFF) {
StartTextRefStackUsage(indspec->grf_prop.grffile, 6);
- GetString(suffix, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), suffix_last);
+ GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), lastof(suffix.text));
StopTextRefStackUsage();
}
}
@@ -105,9 +109,9 @@ static inline void GetAllCargoSuffixes(uint cb_offset, CargoSuffixType cst, cons
assert_compile(lengthof(cargoes) <= lengthof(suffixes));
for (uint j = 0; j < lengthof(cargoes); j++) {
if (cargoes[j] != CT_INVALID) {
- GetCargoSuffix(cb_offset + j, cst, ind, ind_type, indspec, suffixes[j], lastof(suffixes[j]));
+ GetCargoSuffix(cb_offset + j, cst, ind, ind_type, indspec, suffixes[j]);
} else {
- suffixes[j][0] = '\0';
+ suffixes[j].text[0] = '\0';
}
}
}
@@ -313,7 +317,7 @@ public:
const IndustrySpec *indsp = GetIndustrySpec(this->index[i]);
- char cargo_suffix[3][512];
+ CargoSuffix cargo_suffix[3];
GetAllCargoSuffixes(0, CST_FUND, NULL, this->index[i], indsp, indsp->accepts_cargo, cargo_suffix);
StringID str = STR_INDUSTRY_VIEW_REQUIRES_CARGO;
byte p = 0;
@@ -323,7 +327,7 @@ public:
if (indsp->accepts_cargo[j] == CT_INVALID) continue;
if (p > 0) str++;
SetDParam(p++, CargoSpec::Get(indsp->accepts_cargo[j])->name);
- SetDParamStr(p++, cargo_suffix[j]);
+ SetDParamStr(p++, cargo_suffix[j].text);
}
d = maxdim(d, GetStringBoundingBox(str));
@@ -337,7 +341,7 @@ public:
if (indsp->produced_cargo[j] == CT_INVALID) continue;
if (p > 0) str++;
SetDParam(p++, CargoSpec::Get(indsp->produced_cargo[j])->name);
- SetDParamStr(p++, cargo_suffix[j]);
+ SetDParamStr(p++, cargo_suffix[j].text);
}
d = maxdim(d, GetStringBoundingBox(str));
}
@@ -432,7 +436,7 @@ public:
}
/* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
- char cargo_suffix[3][512];
+ CargoSuffix cargo_suffix[3];
GetAllCargoSuffixes(0, CST_FUND, NULL, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
StringID str = STR_INDUSTRY_VIEW_REQUIRES_CARGO;
byte p = 0;
@@ -442,7 +446,7 @@ public:
if (indsp->accepts_cargo[j] == CT_INVALID) continue;
if (p > 0) str++;
SetDParam(p++, CargoSpec::Get(indsp->accepts_cargo[j])->name);
- SetDParamStr(p++, cargo_suffix[j]);
+ SetDParamStr(p++, cargo_suffix[j].text);
}
DrawString(left, right, y, str);
y += FONT_HEIGHT_NORMAL;
@@ -457,7 +461,7 @@ public:
if (indsp->produced_cargo[j] == CT_INVALID) continue;
if (p > 0) str++;
SetDParam(p++, CargoSpec::Get(indsp->produced_cargo[j])->name);
- SetDParamStr(p++, cargo_suffix[j]);
+ SetDParamStr(p++, cargo_suffix[j].text);
}
DrawString(left, right, y, str);
y += FONT_HEIGHT_NORMAL;
@@ -713,15 +717,15 @@ public:
int y = top + WD_FRAMERECT_TOP;
bool first = true;
bool has_accept = false;
- char cargo_suffix[3][512];
if (i->prod_level == PRODLEVEL_CLOSURE) {
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
y += 2 * FONT_HEIGHT_NORMAL;
}
+ CargoSuffix cargo_suffix[3];
+ GetAllCargoSuffixes(0, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
if (HasBit(ind->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) {
- GetAllCargoSuffixes(0, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
if (i->accepts_cargo[j] == CT_INVALID) continue;
has_accept = true;
@@ -732,12 +736,11 @@ public:
}
SetDParam(0, i->accepts_cargo[j]);
SetDParam(1, i->incoming_cargo_waiting[j]);
- SetDParamStr(2, cargo_suffix[j]);
+ SetDParamStr(2, cargo_suffix[j].text);
DrawString(left + WD_FRAMETEXT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_WAITING_STOCKPILE_CARGO);
y += FONT_HEIGHT_NORMAL;
}
} else {
- GetAllCargoSuffixes(0, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
StringID str = STR_INDUSTRY_VIEW_REQUIRES_CARGO;
byte p = 0;
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
@@ -745,7 +748,7 @@ public:
has_accept = true;
if (p > 0) str++;
SetDParam(p++, CargoSpec::Get(i->accepts_cargo[j])->name);
- SetDParamStr(p++, cargo_suffix[j]);
+ SetDParamStr(p++, cargo_suffix[j].text);
}
if (has_accept) {
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, str);
@@ -767,7 +770,7 @@ public:
SetDParam(0, i->produced_cargo[j]);
SetDParam(1, i->last_month_production[j]);
- SetDParamStr(2, cargo_suffix[j]);
+ SetDParamStr(2, cargo_suffix[j].text);
SetDParam(3, ToPercent8(i->last_month_pct_transported[j]));
uint x = left + WD_FRAMETEXT_LEFT + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + 10 : 0);
DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_TRANSPORTED);
@@ -1204,7 +1207,7 @@ protected:
/* Industry name */
SetDParam(p++, i->index);
- static char cargo_suffix[lengthof(i->produced_cargo)][512];
+ static CargoSuffix cargo_suffix[lengthof(i->produced_cargo)];
GetAllCargoSuffixes(3, CST_DIR, i, i->type, indsp, i->produced_cargo, cargo_suffix);
/* Industry productions */
@@ -1212,7 +1215,7 @@ protected:
if (i->produced_cargo[j] == CT_INVALID) continue;
SetDParam(p++, i->produced_cargo[j]);
SetDParam(p++, i->last_month_production[j]);
- SetDParamStr(p++, cargo_suffix[j]);
+ SetDParamStr(p++, cargo_suffix[j].text);
}
/* Transported productions */