Codechange: Use unique_ptr throughout instead of new raw pointer for company news data. (#13148)

The pointer was already captured and converted to a unqiue_ptr, but hidden within the call stack.

This now makes it clearer that the object passed to Add.*NewsItem will become owned by the news item.
This commit is contained in:
2024-12-04 12:18:34 +00:00
committed by GitHub
parent 2ff18a4f05
commit 6f8e30c55d
6 changed files with 23 additions and 23 deletions

View File

@@ -3530,12 +3530,12 @@ static CommandCost TownActionBuyRights(Town *t, DoCommandFlag flags)
SetWindowClassesDirty(WC_STATION_VIEW);
/* Spawn news message */
CompanyNewsInformation *cni = new CompanyNewsInformation(Company::Get(_current_company));
auto cni = std::make_unique<CompanyNewsInformation>(Company::Get(_current_company));
SetDParam(0, STR_NEWS_EXCLUSIVE_RIGHTS_TITLE);
SetDParam(1, TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MINUTES : STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MONTHS);
SetDParam(2, t->index);
SetDParamStr(3, cni->company_name);
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_GENERAL, NF_COMPANY, NR_TOWN, t->index, NR_NONE, UINT32_MAX, cni);
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_GENERAL, NF_COMPANY, NR_TOWN, t->index, NR_NONE, UINT32_MAX, std::move(cni));
AI::BroadcastNewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
Game::NewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
}