OpenTTD Source: src/news_type.h Source File

OpenTTD Source 14.0-beta3

news_type.h
Go to the documentation of this file.
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 */
7
10 #ifndef NEWS_TYPE_H
11 #define NEWS_TYPE_H
12
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"
19
23 enum NewsType : byte {
24 NT_ARRIVAL_COMPANY,
25 NT_ARRIVAL_OTHER,
26 NT_ACCIDENT,
27 NT_ACCIDENT_OTHER,
28 NT_COMPANY_INFO,
29 NT_INDUSTRY_OPEN,
30 NT_INDUSTRY_CLOSE,
31 NT_ECONOMY,
32 NT_INDUSTRY_COMPANY,
33 NT_INDUSTRY_OTHER,
34 NT_INDUSTRY_NOBODY,
35 NT_ADVICE,
36 NT_NEW_VEHICLES,
37 NT_ACCEPTANCE,
38 NT_SUBSIDIES,
39 NT_GENERAL,
40 NT_END,
41 };
42
52 enum NewsReferenceType : byte {
53 NR_NONE,
54 NR_TILE,
55 NR_VEHICLE,
56 NR_STATION,
57 NR_INDUSTRY,
58 NR_TOWN,
59 NR_ENGINE,
60 };
61
66 enum NewsFlag {
67 NFB_INCOLOUR = 0,
68 NFB_NO_TRANSPARENT = 1,
69 NFB_SHADE = 2,
70 NFB_WINDOW_LAYOUT = 3,
71 NFB_WINDOW_LAYOUT_COUNT = 3,
72 NFB_VEHICLE_PARAM0 = 6,
73
74 NF_INCOLOUR = 1 << NFB_INCOLOUR,
75 NF_NO_TRANSPARENT = 1 << NFB_NO_TRANSPARENT,
76 NF_SHADE = 1 << NFB_SHADE,
77 NF_VEHICLE_PARAM0 = 1 << NFB_VEHICLE_PARAM0,
78
79 NF_THIN = 0 << NFB_WINDOW_LAYOUT,
80 NF_SMALL = 1 << NFB_WINDOW_LAYOUT,
81 NF_NORMAL = 2 << NFB_WINDOW_LAYOUT,
82 NF_VEHICLE = 3 << NFB_WINDOW_LAYOUT,
83 NF_COMPANY = 4 << NFB_WINDOW_LAYOUT,
84 };
85 DECLARE_ENUM_AS_BIT_SET(NewsFlag)
86
87
88
91 enum NewsDisplay {
92 ND_OFF,
93 ND_SUMMARY,
94 ND_FULL,
95 };
96
100 struct NewsTypeData {
101 const char * const name;
102 const byte age;
103 const SoundFx sound;
104
111 NewsTypeData(const char *name, byte age, SoundFx sound) :
112 name(name),
113 age(age),
114 sound(sound)
115 {
116 }
117
118 NewsDisplay GetDisplay() const;
119 };
120
122 struct NewsAllocatedData {
123 virtual ~NewsAllocatedData() = default;
124 };
125
126
128 struct NewsItem {
129 NewsItem *prev;
130 NewsItem *next;
131 StringID string_id;
132 TimerGameCalendar::Date date;
133 TimerGameEconomy::Date economy_date;
134 NewsType type;
135 NewsFlag flags;
136
137 NewsReferenceType reftype1;
138 NewsReferenceType reftype2;
139 uint32_t ref1;
140 uint32_t ref2;
141
142 std::unique_ptr<const NewsAllocatedData> data;
143
144 std::vector<StringParameterBackup> params;
145
146 NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data);
147 };
148
150 struct NewsStringData : NewsAllocatedData {
151 std::string string;
152 NewsStringData(const std::string &str) : string(str) {}
153 };
154
161 struct CompanyNewsInformation : NewsAllocatedData {
162 std::string company_name;
163 std::string president_name;
164 std::string other_company_name;
165
166 uint32_t face;
167 Colours colour;
168
169 CompanyNewsInformation(const struct Company *c, const struct Company *other = nullptr);
170 };
171
172 #endif /* NEWS_TYPE_H */
NewsItem::NewsItem
NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data)
Create a new newsitem to be shown.
Definition: news_gui.cpp:806
NewsItem::data
std::unique_ptr< const NewsAllocatedData > data
Custom data for the news item that will be deallocated (deleted) when the news item has reached its e...
Definition: news_type.h:142
NR_TILE
@ NR_TILE
Reference tile. Scroll to tile when clicking on the news.
Definition: news_type.h:54
NT_ARRIVAL_OTHER
@ NT_ARRIVAL_OTHER
First vehicle arrived for competitor.
Definition: news_type.h:25
NF_THIN
@ NF_THIN
Thin news item. (Newspaper with headline and viewport)
Definition: news_type.h:79
NFB_SHADE
@ NFB_SHADE
News item uses shaded colours.
Definition: news_type.h:69
NewsItem
Information about a single item of news.
Definition: news_type.h:128
CompanyNewsInformation::president_name
std::string president_name
The name of the president.
Definition: news_type.h:163
timer_game_calendar.h
NewsAllocatedData
Container for any custom data that must be deleted after the news item has reached end-of-life.
Definition: news_type.h:122
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NewsTypeData
Per-NewsType data.
Definition: news_type.h:100
NewsTypeData::NewsTypeData
NewsTypeData(const char *name, byte age, SoundFx sound)
Construct this entry.
Definition: news_type.h:111
sound_type.h
NT_INDUSTRY_COMPANY
@ NT_INDUSTRY_COMPANY
Production changes of industry serviced by local company.
Definition: news_type.h:32
NewsItem::params
std::vector< StringParameterBackup > params
Parameters for string resolving.
Definition: news_type.h:144
CompanyNewsInformation::colour
Colours colour
The colour related to the company.
Definition: news_type.h:167
ND_FULL
@ ND_FULL
Show newspaper.
Definition: news_type.h:94
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition: strong_typedef_type.hpp:150
NFB_WINDOW_LAYOUT
@ NFB_WINDOW_LAYOUT
First bit for window layout.
Definition: news_type.h:70
NewsItem::reftype2
NewsReferenceType reftype2
Type of ref2.
Definition: news_type.h:138
NF_VEHICLE_PARAM0
@ NF_VEHICLE_PARAM0
Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour)
Definition: news_type.h:77
NewsItem::date
TimerGameCalendar::Date date
Calendar date to show for the news.
Definition: news_type.h:132
NT_INDUSTRY_NOBODY
@ NT_INDUSTRY_NOBODY
Other industry production changes.
Definition: news_type.h:34
strings_type.h
NT_INDUSTRY_CLOSE
@ NT_INDUSTRY_CLOSE
Closing of industries.
Definition: news_type.h:30
NR_ENGINE
@ NR_ENGINE
Reference engine.
Definition: news_type.h:59
NR_NONE
@ NR_NONE
Empty reference.
Definition: news_type.h:53
NewsItem::flags
NewsFlag flags
NewsFlags bits.
Definition: news_type.h:135
NF_NO_TRANSPARENT
@ NF_NO_TRANSPARENT
Bit value for disabling transparency.
Definition: news_type.h:75
NewsTypeData::age
const byte age
Maximum age of news items (in days)
Definition: news_type.h:102
NewsTypeData::sound
const SoundFx sound
Sound.
Definition: news_type.h:103
NR_TOWN
@ NR_TOWN
Reference town. Scroll to town when clicking on the news.
Definition: news_type.h:58
NT_ADVICE
@ NT_ADVICE
Bits of news about vehicles of the company.
Definition: news_type.h:35
NT_ARRIVAL_COMPANY
@ NT_ARRIVAL_COMPANY
First vehicle arrived for company.
Definition: news_type.h:24
CompanyNewsInformation::other_company_name
std::string other_company_name
The name of the company taking over this one.
Definition: news_type.h:164
NT_END
@ NT_END
end-of-array marker
Definition: news_type.h:40
NewsItem::type
NewsType type
Type of the news.
Definition: news_type.h:134
CompanyNewsInformation::company_name
std::string company_name
The name of the company.
Definition: news_type.h:162
NT_NEW_VEHICLES
@ NT_NEW_VEHICLES
New vehicle has become available.
Definition: news_type.h:36
NT_ACCEPTANCE
@ NT_ACCEPTANCE
A type of cargo is (no longer) accepted.
Definition: news_type.h:37
NF_INCOLOUR
@ NF_INCOLOUR
Bit value for coloured news.
Definition: news_type.h:74
NT_GENERAL
@ NT_GENERAL
General news (from towns)
Definition: news_type.h:39
NT_INDUSTRY_OTHER
@ NT_INDUSTRY_OTHER
Production changes of industry serviced by competitor(s)
Definition: news_type.h:33
NewsType
NewsType
Type of news.
Definition: news_type.h:23
NewsReferenceType
NewsReferenceType
References to objects in news.
Definition: news_type.h:52
NewsTypeData::name
const char *const name
Name.
Definition: news_type.h:101
NewsStringData
Container for a single string to be passed as NewsAllocatedData.
Definition: news_type.h:150
NewsTypeData::GetDisplay
NewsDisplay GetDisplay() const
Return the news display option.
Definition: news_gui.cpp:257
NewsItem::string_id
StringID string_id
Message text.
Definition: news_type.h:131
NewsItem::prev
NewsItem * prev
Previous news item.
Definition: news_type.h:129
ND_OFF
@ ND_OFF
Only show a reminder in the status bar.
Definition: news_type.h:92
NT_SUBSIDIES
@ NT_SUBSIDIES
News about subsidies (announcements, expirations, acceptance)
Definition: news_type.h:38
NT_ACCIDENT_OTHER
@ NT_ACCIDENT_OTHER
An accident or disaster has occurred.
Definition: news_type.h:27
NewsItem::next
NewsItem * next
Next news item.
Definition: news_type.h:130
SoundFx
SoundFx
Sound effects from baseset.
Definition: sound_type.h:37
NF_NORMAL
@ NF_NORMAL
Normal news item. (Newspaper with text only)
Definition: news_type.h:81
NewsDisplay
NewsDisplay
News display options.
Definition: news_type.h:91
NewsItem::ref2
uint32_t ref2
Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news ...
Definition: news_type.h:140
NFB_INCOLOUR
@ NFB_INCOLOUR
News item is shown in colour (otherwise it is shown in black & white).
Definition: news_type.h:67
NT_INDUSTRY_OPEN
@ NT_INDUSTRY_OPEN
Opening of industries.
Definition: news_type.h:29
ND_SUMMARY
@ ND_SUMMARY
Show ticker.
Definition: news_type.h:93
NewsItem::ref1
uint32_t ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news,...
Definition: news_type.h:139
NT_ACCIDENT
@ NT_ACCIDENT
An accident or disaster has occurred.
Definition: news_type.h:26
CompanyNewsInformation
Data that needs to be stored for company news messages.
Definition: news_type.h:161
NR_INDUSTRY
@ NR_INDUSTRY
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
Definition: news_type.h:57
NF_COMPANY
@ NF_COMPANY
Company news item. (Newspaper with face)
Definition: news_type.h:83
CompanyNewsInformation::face
uint32_t face
The face of the president.
Definition: news_type.h:166
NewsItem::economy_date
TimerGameEconomy::Date economy_date
Economy date of the news item, never shown but used to calculate age.
Definition: news_type.h:133
NT_ECONOMY
@ NT_ECONOMY
Economic changes (recession, industry up/dowm)
Definition: news_type.h:31
NFB_WINDOW_LAYOUT_COUNT
@ NFB_WINDOW_LAYOUT_COUNT
Number of bits for window layout.
Definition: news_type.h:71
CompanyNewsInformation::CompanyNewsInformation
CompanyNewsInformation(const struct Company *c, const struct Company *other=nullptr)
Fill the CompanyNewsInformation struct with the required data.
Definition: company_cmd.cpp:814
enum_type.hpp
NFB_VEHICLE_PARAM0
@ NFB_VEHICLE_PARAM0
String param 0 contains a vehicle ID. (special autoreplace behaviour)
Definition: news_type.h:72
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
NR_VEHICLE
@ NR_VEHICLE
Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
Definition: news_type.h:55
NF_VEHICLE
@ NF_VEHICLE
Vehicle news item. (new engine available)
Definition: news_type.h:82
NF_SMALL
@ NF_SMALL
Small news item. (Information window with text and viewport)
Definition: news_type.h:80
NF_SHADE
@ NF_SHADE
Bit value for enabling shading.
Definition: news_type.h:76
NewsStringData::string
std::string string
The string to retain.
Definition: news_type.h:151
NewsFlag
NewsFlag
Various OR-able news-item flags.
Definition: news_type.h:66
NFB_NO_TRANSPARENT
@ NFB_NO_TRANSPARENT
News item disables transparency in the viewport.
Definition: news_type.h:68
gfx_type.h
Company
Definition: company_base.h:116
NR_STATION
@ NR_STATION
Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
Definition: news_type.h:56
NT_COMPANY_INFO
@ NT_COMPANY_INFO
Company info (new companies, bankruptcy messages)
Definition: news_type.h:28
timer_game_economy.h
NewsItem::reftype1
NewsReferenceType reftype1
Type of ref1.
Definition: news_type.h:137