1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 17:32:45 +01:00

Codechange: Remove redundant NewsStringData data. (#12983)

Since SetDParamStr() always owns a copy of the string, there is no need to make another copy of it to keep it around while the news item exists.

This also fixes a leak in `CmdIndustrySetProduction` as the allocated data wasn't passed to AddIndustryNewsItem.
This commit is contained in:
Peter Nelson
2024-10-08 19:48:55 +01:00
committed by GitHub
parent d53b681cf7
commit 446db2c826
5 changed files with 14 additions and 23 deletions

View File

@@ -48,17 +48,16 @@ void Subsidy::AwardTo(CompanyID company)
this->remaining = _settings_game.difficulty.subsidy_duration * CalendarTime::MONTHS_IN_YEAR;
SetDParam(0, company);
NewsStringData *company_name = new NewsStringData(GetString(STR_COMPANY_NAME));
std::string company_name = GetString(STR_COMPANY_NAME);
/* Add a news item */
std::pair<NewsReferenceType, NewsReferenceType> reftype = SetupSubsidyDecodeParam(this, SubsidyDecodeParamType::NewsAwarded, 1);
SetDParamStr(0, company_name->string);
SetDParamStr(0, company_name);
AddNewsItem(
STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF + _settings_game.difficulty.subsidy_multiplier,
NT_SUBSIDIES, NF_NORMAL,
reftype.first, this->src, reftype.second, this->dst,
company_name
reftype.first, this->src, reftype.second, this->dst
);
AI::BroadcastNewEvent(new ScriptEventSubsidyAwarded(this->index));
Game::NewEvent(new ScriptEventSubsidyAwarded(this->index));