summaryrefslogtreecommitdiff
path: root/src/news_type.h
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_type.h
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_type.h')
-rw-r--r--src/news_type.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/news_type.h b/src/news_type.h
index 1929804e4..bed8f16e7 100644
--- a/src/news_type.h
+++ b/src/news_type.h
@@ -115,6 +115,12 @@ struct NewsTypeData {
NewsDisplay GetDisplay() const;
};
+/** Container for any custom data that must be deleted after the news item has reached end-of-life. */
+struct NewsAllocatedData {
+ virtual ~NewsAllocatedData() {}
+};
+
+
/** Information about a single item of news. */
struct NewsItem {
NewsItem *prev; ///< Previous news item
@@ -129,23 +135,29 @@ struct NewsItem {
uint32 ref1; ///< Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleting the news when the object is deleted.
uint32 ref2; ///< Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
- void *free_data; ///< Data to be freed when the news item has reached its end.
+ const NewsAllocatedData *data; ///< Custom data for the news item that have to be deallocated (deleted) when the news item has reached its end.
~NewsItem()
{
- free(this->free_data);
+ delete this->data;
}
uint64 params[10]; ///< Parameters for string resolving.
};
+/** Container for a single string to be passed as NewsAllocatedData. */
+struct NewsStringData : NewsAllocatedData {
+ std::string string; ///< The string to retain.
+ NewsStringData(const std::string &str) : string(str) {}
+};
+
/**
* Data that needs to be stored for company news messages.
* The problem with company news messages are the custom name
* of the companies and the fact that the company data is reset,
* resulting in wrong names and such.
*/
-struct CompanyNewsInformation {
+struct CompanyNewsInformation : NewsAllocatedData {
char company_name[64]; ///< The name of the company
char president_name[64]; ///< The name of the president
char other_company_name[64]; ///< The name of the company taking over this one