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:
Peter Nelson
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

@@ -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);