Codefix: Documentation comment in IndustryDirectoryWindow (#13059)
[openttd-github.git] / src / news_type.h
blobcd350faf2f5c263f06c49becdcfc35fa2ada347d
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file news_type.h Types related to news. */
10 #ifndef NEWS_TYPE_H
11 #define NEWS_TYPE_H
13 #include "core/enum_type.hpp"
14 #include "gfx_type.h"
15 #include "timer/timer_game_calendar.h"
16 #include "timer/timer_game_economy.h"
17 #include "strings_type.h"
18 #include "sound_type.h"
20 /**
21 * Type of news.
23 enum NewsType : uint8_t {
24 NT_ARRIVAL_COMPANY, ///< First vehicle arrived for company
25 NT_ARRIVAL_OTHER, ///< First vehicle arrived for competitor
26 NT_ACCIDENT, ///< An accident or disaster has occurred
27 NT_ACCIDENT_OTHER, ///< An accident or disaster has occurred
28 NT_COMPANY_INFO, ///< Company info (new companies, bankruptcy messages)
29 NT_INDUSTRY_OPEN, ///< Opening of industries
30 NT_INDUSTRY_CLOSE, ///< Closing of industries
31 NT_ECONOMY, ///< Economic changes (recession, industry up/dowm)
32 NT_INDUSTRY_COMPANY,///< Production changes of industry serviced by local company
33 NT_INDUSTRY_OTHER, ///< Production changes of industry serviced by competitor(s)
34 NT_INDUSTRY_NOBODY, ///< Other industry production changes
35 NT_ADVICE, ///< Bits of news about vehicles of the company
36 NT_NEW_VEHICLES, ///< New vehicle has become available
37 NT_ACCEPTANCE, ///< A type of cargo is (no longer) accepted
38 NT_SUBSIDIES, ///< News about subsidies (announcements, expirations, acceptance)
39 NT_GENERAL, ///< General news (from towns)
40 NT_END, ///< end-of-array marker
43 /**
44 * References to objects in news.
46 * @warning
47 * Be careful!
48 * Vehicles are a special case, as news are kept when vehicles are autoreplaced/renewed.
49 * You have to make sure, #ChangeVehicleNews catches the DParams of your message.
50 * This is NOT ensured by the references.
52 enum NewsReferenceType : uint8_t {
53 NR_NONE, ///< Empty reference
54 NR_TILE, ///< Reference tile. Scroll to tile when clicking on the news.
55 NR_VEHICLE, ///< Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
56 NR_STATION, ///< Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
57 NR_INDUSTRY, ///< Reference industry. Scroll to industry when clicking on the news. Delete news when industry is deleted.
58 NR_TOWN, ///< Reference town. Scroll to town when clicking on the news.
59 NR_ENGINE, ///< Reference engine.
62 /**
63 * Various OR-able news-item flags.
64 * @note #NF_INCOLOUR is set automatically if needed.
66 enum NewsFlag {
67 NFB_INCOLOUR = 0, ///< News item is shown in colour (otherwise it is shown in black & white).
68 NFB_NO_TRANSPARENT = 1, ///< News item disables transparency in the viewport.
69 NFB_SHADE = 2, ///< News item uses shaded colours.
70 NFB_WINDOW_LAYOUT = 3, ///< First bit for window layout.
71 NFB_WINDOW_LAYOUT_COUNT = 3, ///< Number of bits for window layout.
72 NFB_VEHICLE_PARAM0 = 6, ///< String param 0 contains a vehicle ID. (special autoreplace behaviour)
74 NF_INCOLOUR = 1 << NFB_INCOLOUR, ///< Bit value for coloured news.
75 NF_NO_TRANSPARENT = 1 << NFB_NO_TRANSPARENT, ///< Bit value for disabling transparency.
76 NF_SHADE = 1 << NFB_SHADE, ///< Bit value for enabling shading.
77 NF_VEHICLE_PARAM0 = 1 << NFB_VEHICLE_PARAM0, ///< Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour)
79 NF_THIN = 0 << NFB_WINDOW_LAYOUT, ///< Thin news item. (Newspaper with headline and viewport)
80 NF_SMALL = 1 << NFB_WINDOW_LAYOUT, ///< Small news item. (Information window with text and viewport)
81 NF_NORMAL = 2 << NFB_WINDOW_LAYOUT, ///< Normal news item. (Newspaper with text only)
82 NF_VEHICLE = 3 << NFB_WINDOW_LAYOUT, ///< Vehicle news item. (new engine available)
83 NF_COMPANY = 4 << NFB_WINDOW_LAYOUT, ///< Company news item. (Newspaper with face)
85 DECLARE_ENUM_AS_BIT_SET(NewsFlag)
88 /**
89 * News display options
91 enum NewsDisplay {
92 ND_OFF, ///< Only show a reminder in the status bar
93 ND_SUMMARY, ///< Show ticker
94 ND_FULL, ///< Show newspaper
97 /**
98 * Per-NewsType data
100 struct NewsTypeData {
101 const char * const name; ///< Name
102 const uint8_t age; ///< Maximum age of news items (in days)
103 const SoundFx sound; ///< Sound
106 * Construct this entry.
107 * @param name The name of the type.
108 * @param age The maximum age for these messages.
109 * @param sound The sound to play.
111 NewsTypeData(const char *name, uint8_t age, SoundFx sound) :
112 name(name),
113 age(age),
114 sound(sound)
118 NewsDisplay GetDisplay() const;
121 /** Container for any custom data that must be deleted after the news item has reached end-of-life. */
122 struct NewsAllocatedData {
123 virtual ~NewsAllocatedData() = default;
127 /** Information about a single item of news. */
128 struct NewsItem {
129 StringID string_id; ///< Message text
130 TimerGameCalendar::Date date; ///< Calendar date to show for the news
131 TimerGameEconomy::Date economy_date; ///< Economy date of the news item, never shown but used to calculate age
132 NewsType type; ///< Type of the news
133 NewsFlag flags; ///< NewsFlags bits @see NewsFlag
135 NewsReferenceType reftype1; ///< Type of ref1
136 NewsReferenceType reftype2; ///< Type of ref2
137 uint32_t 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.
138 uint32_t ref2; ///< Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
140 std::unique_ptr<const NewsAllocatedData> data; ///< Custom data for the news item that will be deallocated (deleted) when the news item has reached its end.
142 std::vector<StringParameterData> params; ///< Parameters for string resolving.
144 NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data);
148 * Data that needs to be stored for company news messages.
149 * The problem with company news messages are the custom name
150 * of the companies and the fact that the company data is reset,
151 * resulting in wrong names and such.
153 struct CompanyNewsInformation : NewsAllocatedData {
154 std::string company_name; ///< The name of the company
155 std::string president_name; ///< The name of the president
156 std::string other_company_name; ///< The name of the company taking over this one
158 uint32_t face; ///< The face of the president
159 Colours colour; ///< The colour related to the company
161 CompanyNewsInformation(const struct Company *c, const struct Company *other = nullptr);
164 using NewsContainer = std::list<NewsItem>; ///< Container type for storing news items.
165 using NewsIterator = NewsContainer::const_iterator; ///< Iterator type for news items.
167 #endif /* NEWS_TYPE_H */