1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-20 19:02:41 +01:00

Fix 6e10584b91: Keep custom news from game scripts in encoded form. (#13741)

This allows the news message to translated as appropriate.
This commit is contained in:
Peter Nelson
2025-03-04 23:15:50 +00:00
committed by GitHub
parent b979f0414c
commit 51fd2853cb
5 changed files with 20 additions and 21 deletions

View File

@@ -2170,20 +2170,12 @@ CommandCost CmdIndustrySetProduction(DoCommandFlags flags, IndustryID ind_id, ui
if (ind == nullptr) return CMD_ERROR;
if (flags.Test(DoCommandFlag::Execute)) {
StringID str = STR_NULL;
if (prod_level > ind->prod_level) {
str = GetIndustrySpec(ind->type)->production_up_text;
} else if (prod_level < ind->prod_level) {
str = GetIndustrySpec(ind->type)->production_down_text;
}
if (prod_level != ind->prod_level && !custom_news.empty()) str = STR_NEWS_CUSTOM_ITEM;
ind->ctlflags.Set(IndustryControlFlag::ExternalProdLevel);
ind->prod_level = prod_level;
ind->RecomputeProductionMultipliers();
/* Show news message if requested. */
if (show_news && str != STR_NULL) {
if (show_news && prod_level != ind->prod_level) {
NewsType nt;
switch (WhoCanServiceIndustry(ind)) {
case 0: nt = NewsType::IndustryNobody; break;
@@ -2194,12 +2186,18 @@ CommandCost CmdIndustrySetProduction(DoCommandFlags flags, IndustryID ind_id, ui
/* Set parameters of news string */
EncodedString headline;
if (str == STR_NEWS_CUSTOM_ITEM) {
headline = GetEncodedString(str, custom_news.GetDecodedString());
} else if (str > STR_LAST_STRINGID) {
headline = GetEncodedString(str, STR_TOWN_NAME, ind->town->index, GetIndustrySpec(ind->type)->name);
if (!custom_news.empty()) {
headline = custom_news;
} else {
headline = GetEncodedString(str, ind->index);
StringID str = (prod_level > ind->prod_level)
? GetIndustrySpec(ind->type)->production_up_text
: GetIndustrySpec(ind->type)->production_down_text;
if (str > STR_LAST_STRINGID) {
headline = GetEncodedString(str, STR_TOWN_NAME, ind->town->index, GetIndustrySpec(ind->type)->name);
} else {
headline = GetEncodedString(str, ind->index);
}
}
AddIndustryNewsItem(std::move(headline), nt, ind->index);