diff options
author | rubidium42 <rubidium@openttd.org> | 2021-06-16 17:50:18 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-07-01 19:04:38 +0200 |
commit | aa9818db90b910b1b3d62d080f4a670a6a9d14af (patch) | |
tree | d3e76cefe6872f5c0b0b8edebef6cfed99f6bcab /src/town_cmd.cpp | |
parent | df601b8559b3d5de179b5b9e65ab9674fbd8bf5e (diff) | |
download | openttd-aa9818db90b910b1b3d62d080f4a670a6a9d14af.tar.xz |
Codechange: create a type for the "free_data" of NewsItems and (de)allocate it with new and delete
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r-- | src/town_cmd.cpp | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d397825af..b21d0ab71 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2020,15 +2020,13 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 SetDParam(0, t->index); AddTileNewsItem(STR_NEWS_NEW_TOWN_UNSPONSORED, NT_INDUSTRY_OPEN, tile); } else { - char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH]; SetDParam(0, _current_company); - GetString(company_name, STR_COMPANY_NAME, lastof(company_name)); + NewsStringData *company_name = new NewsStringData(GetString(STR_COMPANY_NAME)); - char *cn = stredup(company_name); - SetDParamStr(0, cn); + SetDParamStr(0, company_name->string); SetDParam(1, t->index); - AddTileNewsItem(STR_NEWS_NEW_TOWN, NT_INDUSTRY_OPEN, tile, cn); + AddTileNewsItem(STR_NEWS_NEW_TOWN, NT_INDUSTRY_OPEN, tile, company_name); } AI::BroadcastNewEvent(new ScriptEventTownFounded(t->index)); Game::NewEvent(new ScriptEventTownFounded(t->index)); @@ -3090,15 +3088,13 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags) if (flags & DC_EXEC) { t->road_build_months = 6; - char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH]; SetDParam(0, _current_company); - GetString(company_name, STR_COMPANY_NAME, lastof(company_name)); + NewsStringData *company_name = new NewsStringData(GetString(STR_COMPANY_NAME)); - char *cn = stredup(company_name); SetDParam(0, t->index); - SetDParamStr(1, cn); + SetDParamStr(1, company_name->string); - AddNewsItem(STR_NEWS_ROAD_REBUILDING, NT_GENERAL, NF_NORMAL, NR_TOWN, t->index, NR_NONE, UINT32_MAX, cn); + AddNewsItem(STR_NEWS_ROAD_REBUILDING, NT_GENERAL, NF_NORMAL, NR_TOWN, t->index, NR_NONE, UINT32_MAX, company_name); AI::BroadcastNewEvent(new ScriptEventRoadReconstruction((ScriptCompany::CompanyID)(Owner)_current_company, t->index)); Game::NewEvent(new ScriptEventRoadReconstruction((ScriptCompany::CompanyID)(Owner)_current_company, t->index)); } @@ -3235,7 +3231,7 @@ static CommandCost TownActionBuyRights(Town *t, DoCommandFlag flags) SetWindowClassesDirty(WC_STATION_VIEW); /* Spawn news message */ - CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); + CompanyNewsInformation *cni = new CompanyNewsInformation(); cni->FillData(Company::Get(_current_company)); SetDParam(0, STR_NEWS_EXCLUSIVE_RIGHTS_TITLE); SetDParam(1, STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION); |