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:
@@ -426,12 +426,12 @@ set_name:;
|
||||
MarkWholeScreenDirty();
|
||||
|
||||
if (c->is_ai) {
|
||||
CompanyNewsInformation *cni = new CompanyNewsInformation(c);
|
||||
auto cni = std::make_unique<CompanyNewsInformation>(c);
|
||||
SetDParam(0, STR_NEWS_COMPANY_LAUNCH_TITLE);
|
||||
SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION);
|
||||
SetDParamStr(2, cni->company_name);
|
||||
SetDParam(3, t->index);
|
||||
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate.base(), NR_NONE, UINT32_MAX, cni);
|
||||
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate.base(), NR_NONE, UINT32_MAX, std::move(cni));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -946,13 +946,13 @@ CommandCost CmdCompanyCtrl(DoCommandFlag flags, CompanyCtrlAction cca, CompanyID
|
||||
|
||||
if (!(flags & DC_EXEC)) return CommandCost();
|
||||
|
||||
CompanyNewsInformation *cni = new CompanyNewsInformation(c);
|
||||
auto cni = std::make_unique<CompanyNewsInformation>(c);
|
||||
|
||||
/* Show the bankrupt news */
|
||||
SetDParam(0, STR_NEWS_COMPANY_BANKRUPT_TITLE);
|
||||
SetDParam(1, STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION);
|
||||
SetDParamStr(2, cni->company_name);
|
||||
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, cni);
|
||||
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, std::move(cni));
|
||||
|
||||
/* Remove the company */
|
||||
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
|
||||
|
||||
Reference in New Issue
Block a user