Translations update
[openttd/fttd.git] / src / news_type.h
bloba0bb526bab138f93e3420319d3124db34fba1c72
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file news_type.h Types related to news. */
12 #ifndef NEWS_TYPE_H
13 #define NEWS_TYPE_H
15 #include "core/pointer.h"
16 #include "core/enum_type.hpp"
17 #include "string.h"
18 #include "date_func.h"
19 #include "strings_type.h"
20 #include "sound_type.h"
21 #include "settings_type.h"
22 #include "cargo_type.h"
23 #include "engine_type.h"
24 #include "vehicle_type.h"
25 #include "industry_type.h"
26 #include "company_type.h"
27 #include "map/coord.h"
29 /** Constants in the message options window. */
30 enum MessageOptionsSpace {
31 MOS_WIDG_PER_SETTING = 4, ///< Number of widgets needed for each news category, starting at widget #WID_MO_START_OPTION.
33 MOS_LEFT_EDGE = 6, ///< Number of pixels between left edge of the window and the options buttons column.
34 MOS_COLUMN_SPACING = 4, ///< Number of pixels between the buttons and the description columns.
35 MOS_RIGHT_EDGE = 6, ///< Number of pixels between right edge of the window and the options descriptions column.
36 MOS_BUTTON_SPACE = 10, ///< Additional space in the button with the option value (for better looks).
38 MOS_ABOVE_GLOBAL_SETTINGS = 6, ///< Number of vertical pixels between the categories and the global options.
39 MOS_BOTTOM_EDGE = 6, ///< Number of pixels between bottom edge of the window and bottom of the global options.
42 /**
43 * Type of news.
45 enum NewsType {
46 NT_ARRIVAL_COMPANY, ///< First vehicle arrived for company
47 NT_ARRIVAL_OTHER, ///< First vehicle arrived for competitor
48 NT_ACCIDENT, ///< An accident or disaster has occurred
49 NT_COMPANY_INFO, ///< Company info (new companies, bankruptcy messages)
50 NT_INDUSTRY_OPEN, ///< Opening of industries
51 NT_INDUSTRY_CLOSE, ///< Closing of industries
52 NT_ECONOMY, ///< Economic changes (recession, industry up/dowm)
53 NT_INDUSTRY_COMPANY,///< Production changes of industry serviced by local company
54 NT_INDUSTRY_OTHER, ///< Production changes of industry serviced by competitor(s)
55 NT_INDUSTRY_NOBODY, ///< Other industry production changes
56 NT_ADVICE, ///< Bits of news about vehicles of the company
57 NT_NEW_VEHICLES, ///< New vehicle has become available
58 NT_ACCEPTANCE, ///< A type of cargo is (no longer) accepted
59 NT_SUBSIDIES, ///< News about subsidies (announcements, expirations, acceptance)
60 NT_GENERAL, ///< General news (from towns)
61 NT_END, ///< end-of-array marker
64 /**
65 * References to objects in news.
67 * @warning
68 * Be careful!
69 * Vehicles are a special case, as news are kept when vehicles are autoreplaced/renewed.
70 * You have to make sure, #ChangeVehicleNews catches the DParams of your message.
71 * This is NOT ensured by the references.
73 enum NewsReferenceType {
74 NR_NONE, ///< Empty reference
75 NR_TILE, ///< Reference tile. Scroll to tile when clicking on the news.
76 NR_VEHICLE, ///< Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
77 NR_STATION, ///< Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
78 NR_INDUSTRY, ///< Reference industry. Scroll to industry when clicking on the news. Delete news when industry is deleted.
79 NR_TOWN, ///< Reference town. Scroll to town when clicking on the news.
80 NR_ENGINE, ///< Reference engine.
83 /**
84 * Various OR-able news-item flags.
85 * @note #NF_INCOLOUR is set automatically if needed.
87 enum NewsFlag {
88 NFB_WINDOW_LAYOUT = 0, ///< First bit for window layout.
89 NFB_WINDOW_LAYOUT_COUNT = 3, ///< Number of bits for window layout.
90 NFB_INCOLOUR = 3, ///< News item is shown in colour (otherwise it is shown in black & white).
91 NFB_SHADE = 4, ///< Disable transparency in the viewport and shade colours.
92 NFB_VEHICLE_PARAM0 = 5, ///< String param 0 contains a vehicle ID. (special autoreplace behaviour)
94 NF_INCOLOUR = 1 << NFB_INCOLOUR, ///< Bit value for coloured news.
95 NF_SHADE = 1 << NFB_SHADE, ///< Bit value for enabling shading.
96 NF_VEHICLE_PARAM0 = 1 << NFB_VEHICLE_PARAM0, ///< Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour)
98 NF_THIN = 0 << NFB_WINDOW_LAYOUT, ///< Thin news item. (Newspaper with headline and viewport)
99 NF_SMALL = 1 << NFB_WINDOW_LAYOUT, ///< Small news item. (Information window with text and viewport)
100 NF_NORMAL = 2 << NFB_WINDOW_LAYOUT, ///< Normal news item. (Newspaper with text only)
101 NF_VEHICLE = 3 << NFB_WINDOW_LAYOUT, ///< Vehicle news item. (new engine available)
102 NF_COMPANY = 4 << NFB_WINDOW_LAYOUT, ///< Company news item. (Newspaper with face)
104 NF_SHADE_THIN = NF_SHADE | NF_THIN, ///< Often-used combination
109 * News display options
111 enum NewsDisplay {
112 ND_OFF, ///< Only show a reminder in the status bar
113 ND_SUMMARY, ///< Show ticker
114 ND_FULL, ///< Show newspaper
118 * Per-NewsType data
120 struct NewsTypeData {
121 const char * const name; ///< Name
122 const byte age; ///< Maximum age of news items (in days)
123 const SoundFx sound; ///< Sound
126 * Construct this entry.
127 * @param name The name of the type.
128 * @param age The maximum age for these messages.
129 * @param sound The sound to play.
131 CONSTEXPR NewsTypeData(const char *name, byte age, SoundFx sound) :
132 name(name),
133 age(age),
134 sound(sound)
138 NewsDisplay GetDisplay() const;
141 /** Information about a single item of news. */
142 struct NewsItem {
143 NewsItem *prev; ///< Previous news item
144 NewsItem *next; ///< Next news item
145 StringID string_id; ///< Message text
146 Date date; ///< Date of the news
147 NewsType type; ///< Type of the news
148 NewsFlag flags; ///< NewsFlags bits @see NewsFlag
150 NewsReferenceType reftype1; ///< Type of ref1
151 NewsReferenceType reftype2; ///< Type of ref2
152 uint32 ref1; ///< Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleteing the news when the object is deleted.
153 uint32 ref2; ///< Reference 2 to some object: Used for scrolling after clicking on the news, and for deleteing the news when the object is deleted.
155 NewsItem (StringID string, NewsType type, NewsFlag flags,
156 NewsReferenceType reftype1 = NR_NONE, uint32 ref1 = UINT32_MAX,
157 NewsReferenceType reftype2 = NR_NONE, uint32 ref2 = UINT32_MAX)
158 : prev(NULL), next(NULL),
159 string_id(string), date(_date), type(type),
160 flags (_cur_year < _settings_client.gui.coloured_news_year ? flags : (NewsFlag)(flags | NF_INCOLOUR)),
161 reftype1(reftype1), reftype2(reftype2),
162 ref1(ref1), ref2(ref2)
166 virtual ~NewsItem() { }
168 uint64 params[10]; ///< Parameters for string resolving.
170 /** Company string (company name or president name). */
171 template <uint N>
172 struct CompanyStr {
173 char data [N * MAX_CHAR_LENGTH];
175 const char *get (void) const
177 return this->data;
180 uint64 get_as_param (void) const
182 return (uint64)(size_t)this->get();
186 /** Company name. */
187 struct CompanyName : CompanyStr <MAX_LENGTH_COMPANY_NAME_CHARS> {
188 CompanyName (CompanyID cid);
192 /** NewsItem derived class template. */
193 template <NewsFlag f, NewsReferenceType reftype, typename T>
194 struct RefNewsItem : NewsItem {
195 RefNewsItem (StringID string, NewsType type, T ref)
196 : NewsItem (string, type, f, reftype, ref)
200 template <typename P0>
201 RefNewsItem (StringID string, NewsType type, T ref, P0 param0)
202 : NewsItem (string, type, f, reftype, ref)
204 this->params[0] = param0;
207 template <typename P0, typename P1>
208 RefNewsItem (StringID string, NewsType type, T ref,
209 P0 param0, P1 param1)
210 : NewsItem (string, type, f, reftype, ref)
212 this->params[0] = param0;
213 this->params[1] = param1;
216 template <typename P0, typename P1, typename P2>
217 RefNewsItem (StringID string, NewsType type, T ref,
218 P0 param0, P1 param1, P2 param2)
219 : NewsItem (string, type, f, reftype, ref)
221 this->params[0] = param0;
222 this->params[1] = param1;
223 this->params[2] = param2;
227 /** News linked to a tile on the map. */
228 typedef RefNewsItem <NF_SHADE_THIN, NR_TILE, TileIndex> TileNewsItem;
230 /** News about an industry. */
231 typedef RefNewsItem <NF_SHADE_THIN, NR_INDUSTRY, IndustryID> IndustryNewsItem;
233 /** Base class for VehicleNewsItem. */
234 struct BaseVehicleNewsItem : NewsItem {
235 BaseVehicleNewsItem (StringID string, NewsType type, VehicleID vid,
236 const struct Station *st = NULL);
240 * News involving a vehicle.
241 * @warning The params may not reference the vehicle due to autoreplacing.
242 * See VehicleAdviceNewsItem below for that.
244 struct VehicleNewsItem : BaseVehicleNewsItem {
245 VehicleNewsItem (StringID string, NewsType type, VehicleID vid)
246 : BaseVehicleNewsItem (string, type, vid)
250 template <typename P>
251 VehicleNewsItem (StringID string, NewsType type, VehicleID vid, P p)
252 : BaseVehicleNewsItem (string, type, vid)
254 this->params[0] = p;
258 /** News about arrival of first vehicle to a station. */
259 struct ArrivalNewsItem : BaseVehicleNewsItem {
260 ArrivalNewsItem (StringID string, const struct Vehicle *v,
261 const struct Station *st);
264 /** News about a plane crash. */
265 struct PlaneCrashNewsItem : BaseVehicleNewsItem {
266 PlaneCrashNewsItem (VehicleID vid, const struct Station *st, uint pass);
269 /** Base class for VehicleAdviceNewsItem. */
270 typedef RefNewsItem <(NewsFlag)(NF_INCOLOUR | NF_SMALL | NF_VEHICLE_PARAM0), NR_VEHICLE, VehicleID> BaseVehicleAdviceNewsItem;
272 /** Advice about a vehicle. */
273 struct VehicleAdviceNewsItem : BaseVehicleAdviceNewsItem {
274 VehicleAdviceNewsItem (StringID string, VehicleID vid)
275 : BaseVehicleAdviceNewsItem (string, NT_ADVICE, vid, vid)
279 template <typename P>
280 VehicleAdviceNewsItem (StringID string, VehicleID vid, P param)
281 : BaseVehicleAdviceNewsItem (string, NT_ADVICE, vid, vid, param)
286 /** News about change of acceptance at a station. */
287 struct AcceptanceNewsItem : NewsItem {
288 AcceptanceNewsItem (const struct Station *st,
289 uint num_items, CargoID *cargo, StringID msg);
292 /** News about founding of a town. */
293 struct FoundTownNewsItem : TileNewsItem {
294 CompanyName cname;
296 FoundTownNewsItem (TownID tid, TileIndex tile, CompanyID cid);
299 /** News about road rebuilding in a town. */
300 struct RoadRebuildNewsItem : NewsItem {
301 CompanyName cname;
303 RoadRebuildNewsItem (TownID tid, CompanyID cid);
306 /** News about availability of a new vehicle (engine). */
307 struct EngineNewsItem : NewsItem {
308 EngineNewsItem (EngineID eid);
311 /** News about a subsidy. */
312 struct SubsidyNewsItem : NewsItem {
313 SubsidyNewsItem (StringID string, const struct Subsidy *s,
314 bool plural, uint offset = 0);
317 /** News about a subsidy award. */
318 struct SubsidyAwardNewsItem : SubsidyNewsItem {
319 CompanyName cname;
321 SubsidyAwardNewsItem (const struct Subsidy *s, CompanyID cid);
324 /** Base NewsItem for news about a company. */
325 struct BaseCompanyNewsItem : NewsItem {
326 CompanyName cname; ///< The name of the company
327 CompanyStr<MAX_LENGTH_PRESIDENT_NAME_CHARS> pname; ///< The name of the president
329 uint32 face; ///< The face of the president
330 byte colour; ///< The colour related to the company
332 BaseCompanyNewsItem (NewsType type, StringID str,
333 const struct Company *c,
334 NewsReferenceType reftype = NR_NONE, uint32 ref = UINT32_MAX);
337 /** Generic news about a company. */
338 struct CompanyNewsItem : BaseCompanyNewsItem {
339 CompanyNewsItem (StringID str1, StringID str2, const struct Company *c);
342 /** News about a company launch. */
343 struct LaunchNewsItem : BaseCompanyNewsItem {
344 LaunchNewsItem (const struct Company *c, TownID tid);
347 /** News about a company merger. */
348 struct MergerNewsItem : BaseCompanyNewsItem {
349 CompanyName cname2; ///< The name of the company taken over
351 MergerNewsItem (const struct Company *c, const struct Company *merger);
354 /** News about exclusive transport rights. */
355 struct ExclusiveRightsNewsItem : BaseCompanyNewsItem {
356 ExclusiveRightsNewsItem (TownID tid, const struct Company *c);
359 #endif /* NEWS_TYPE_H */