summaryrefslogtreecommitdiff
path: root/src/news_gui.cpp
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-06-16 17:50:18 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-07-01 19:04:38 +0200
commitaa9818db90b910b1b3d62d080f4a670a6a9d14af (patch)
treed3e76cefe6872f5c0b0b8edebef6cfed99f6bcab /src/news_gui.cpp
parentdf601b8559b3d5de179b5b9e65ab9674fbd8bf5e (diff)
downloadopenttd-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/news_gui.cpp')
-rw-r--r--src/news_gui.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 5c72f8741..fb0320715 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -355,7 +355,7 @@ struct NewsWindow : Window {
break;
case WID_N_MGR_NAME:
- SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->free_data)->president_name);
+ SetDParamStr(0, static_cast<const CompanyNewsInformation *>(this->ni->data)->president_name);
str = STR_JUST_RAW_STRING;
break;
@@ -433,13 +433,13 @@ struct NewsWindow : Window {
break;
case WID_N_MGR_FACE: {
- const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
+ const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data);
DrawCompanyManagerFace(cni->face, cni->colour, r.left, r.top);
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
break;
}
case WID_N_MGR_NAME: {
- const CompanyNewsInformation *cni = (const CompanyNewsInformation*)this->ni->free_data;
+ const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data);
SetDParamStr(0, cni->president_name);
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
break;
@@ -783,7 +783,7 @@ static void DeleteNewsItem(NewsItem *ni)
*
* @see NewsSubtype
*/
-void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data)
+void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, const NewsAllocatedData *data)
{
if (_game_mode == GM_MENU) return;
@@ -801,7 +801,7 @@ void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceTy
ni->reftype2 = reftype2;
ni->ref1 = ref1;
ni->ref2 = ref2;
- ni->free_data = free_data;
+ ni->data = data;
ni->date = _date;
CopyOutDParam(ni->params, 0, lengthof(ni->params));
@@ -882,8 +882,8 @@ CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
if (company != INVALID_OWNER && company != _local_company) return CommandCost();
if (flags & DC_EXEC) {
- char *news = stredup(text.c_str());
- SetDParamStr(0, news);
+ NewsStringData *news = new NewsStringData(text);
+ SetDParamStr(0, news->string);
AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news);
}