OpenTTD Source: src/news_type.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef NEWS_TYPE_H
11#define NEWS_TYPE_H
12
13#include "core/enum_type.hpp"
14#include "company_type.h"
15#include "engine_type.h"
16#include "industry_type.h"
17#include "gfx_type.h"
18#include "sound_type.h"
19#include "station_type.h"
20#include "strings_type.h"
21#include "timer/timer_game_calendar.h"
22#include "timer/timer_game_economy.h"
23#include "town_type.h"
24#include "vehicle_type.h"
25
29 enum class NewsType : uint8_t {
30 ArrivalCompany,
31 ArrivalOther,
32 Accident,
33 AccidentOther,
34 CompanyInfo,
35 IndustryOpen,
36 IndustryClose,
37 Economy,
38 IndustryCompany,
39 IndustryOther,
40 IndustryNobody,
41 Advice,
42 NewVehicles,
43 Acceptance,
44 Subsidies,
45 General,
46
47 End,
48};
49
51 enum class AdviceType : uint8_t {
52 AircraftDestinationTooFar,
53 AutorenewFailed,
54 Order,
55 RefitFailed,
56 TrainStuck,
57 VehicleLost,
58 VehicleOld,
59 VehicleUnprofitable,
60 VehicleWaiting,
61
62 Invalid
63};
64
74 using NewsReference = std::variant<std::monostate, TileIndex, VehicleID, StationID, IndustryID, TownID, EngineID>;
75
77 enum class NewsStyle : uint8_t {
78 Thin,
79 Small,
80 Normal,
81 Vehicle,
82 Company,
83};
84
89 enum class NewsFlag : uint8_t {
90 InColour,
91 NoTransparency,
92 Shaded,
93 VehicleParam0,
94};
95using NewsFlags = EnumBitSet<NewsFlag, uint8_t>;
96
100 enum class NewsDisplay : uint8_t {
101 Off,
102 Summary,
103 Full,
104};
105
109 struct NewsTypeData {
110 const std::string_view name;
111 const uint8_t age;
112 const SoundFx sound;
113
120 NewsTypeData(std::string_view name, uint8_t age, SoundFx sound) :
121 name(name),
122 age(age),
123 sound(sound)
124 {
125 }
126
127 NewsDisplay GetDisplay() const;
128};
129
131 struct NewsAllocatedData {
132 virtual ~NewsAllocatedData() = default;
133};
134
135
137 struct NewsItem {
138 EncodedString headline;
139 TimerGameCalendar::Date date;
140 TimerGameEconomy::Date economy_date;
141 NewsType type;
142 AdviceType advice_type;
143 NewsStyle style;
144 NewsFlags flags;
145
146 NewsReference ref1;
147 NewsReference ref2;
148
149 std::unique_ptr<NewsAllocatedData> data;
150
151 NewsItem(EncodedString &&headline, NewsType type, NewsStyle style, NewsFlags flags, NewsReference ref1, NewsReference ref2, std::unique_ptr<NewsAllocatedData> &&data, AdviceType advice_type);
152
153 std::string GetStatusText() const;
154};
155
162 struct CompanyNewsInformation : NewsAllocatedData {
163 std::string company_name;
164 std::string president_name;
165 std::string other_company_name;
166
167 StringID title;
168 CompanyManagerFace face;
169 Colours colour;
170
171 CompanyNewsInformation(StringID title, const struct Company *c, const struct Company *other = nullptr);
172};
173
174 using NewsContainer = std::list<NewsItem>;
175 using NewsIterator = NewsContainer::const_iterator;
176
177#endif /* NEWS_TYPE_H */
EncodedString
Container for an encoded string, created by GetEncodedString.
Definition strings_type.h:98
EnumBitSet< NewsFlag, uint8_t >
company_type.h
Types related to companies.
engine_type.h
Types related to engines.
enum_type.hpp
Type (helpers) for enums.
gfx_type.h
Types related to the graphics and/or input devices.
industry_type.h
Types related to the industry.
Invalid
@ Invalid
GRF is unusable with this version of OpenTTD.
Definition newgrf_config.h:28
NewsType
NewsType
Type of news.
Definition news_type.h:29
NewsType::Advice
@ Advice
Bits of news about vehicles of the company.
NewsType::General
@ General
General news (from towns)
NewsType::ArrivalCompany
@ ArrivalCompany
First vehicle arrived for company.
NewsType::CompanyInfo
@ CompanyInfo
Company info (new companies, bankruptcy messages)
NewsType::AccidentOther
@ AccidentOther
An accident or disaster has occurred.
NewsType::IndustryCompany
@ IndustryCompany
Production changes of industry serviced by local company.
NewsType::IndustryClose
@ IndustryClose
Closing of industries.
NewsType::IndustryOpen
@ IndustryOpen
Opening of industries.
NewsType::NewVehicles
@ NewVehicles
New vehicle has become available.
NewsType::End
@ End
end-of-array marker
NewsType::Economy
@ Economy
Economic changes (recession, industry up/dowm)
NewsType::IndustryNobody
@ IndustryNobody
Other industry production changes.
NewsType::Subsidies
@ Subsidies
News about subsidies (announcements, expirations, acceptance)
NewsType::ArrivalOther
@ ArrivalOther
First vehicle arrived for competitor.
NewsType::Accident
@ Accident
An accident or disaster has occurred.
NewsType::Acceptance
@ Acceptance
A type of cargo is (no longer) accepted.
NewsType::IndustryOther
@ IndustryOther
Production changes of industry serviced by competitor(s)
NewsIterator
NewsContainer::const_iterator NewsIterator
Iterator type for news items.
Definition news_type.h:175
NewsContainer
std::list< NewsItem > NewsContainer
Container type for storing news items.
Definition news_type.h:174
NewsStyle
NewsStyle
News Window Styles.
Definition news_type.h:77
NewsStyle::Company
@ Company
Company news item. (Newspaper with face)
NewsStyle::Small
@ Small
Small news item. (Information window with text and viewport)
NewsStyle::Normal
@ Normal
Normal news item. (Newspaper with text only)
NewsStyle::Thin
@ Thin
Thin news item. (Newspaper with headline and viewport)
NewsStyle::Vehicle
@ Vehicle
Vehicle news item. (new engine available)
AdviceType
AdviceType
Sub type of the NewsType::Advice to be able to remove specific news items.
Definition news_type.h:51
AdviceType::TrainStuck
@ TrainStuck
The train got stuck and needs to be unstuck manually.
AdviceType::VehicleLost
@ VehicleLost
The vehicle has become lost.
AdviceType::VehicleWaiting
@ VehicleWaiting
The vehicle is waiting in the depot.
AdviceType::Order
@ Order
Something wrong with the order, e.g. invalid or duplicate entries, too few entries.
AdviceType::AutorenewFailed
@ AutorenewFailed
Autorenew or autoreplace failed.
AdviceType::VehicleOld
@ VehicleOld
The vehicle is starting to get old.
AdviceType::VehicleUnprofitable
@ VehicleUnprofitable
The vehicle is costing you money.
AdviceType::AircraftDestinationTooFar
@ AircraftDestinationTooFar
Next (order) destination is too far for the aircraft type.
AdviceType::RefitFailed
@ RefitFailed
The refit order failed to execute.
NewsReference
std::variant< std::monostate, TileIndex, VehicleID, StationID, IndustryID, TownID, EngineID > NewsReference
References to objects in news.
Definition news_type.h:74
NewsFlag
NewsFlag
Various OR-able news-item flags.
Definition news_type.h:89
NewsFlag::NoTransparency
@ NoTransparency
News item disables transparency in the viewport.
NewsFlag::VehicleParam0
@ VehicleParam0
String param 0 contains a vehicle ID. (special autoreplace behaviour)
NewsFlag::Shaded
@ Shaded
News item uses shaded colours.
NewsFlag::InColour
@ InColour
News item is shown in colour (otherwise it is shown in black & white).
NewsDisplay
NewsDisplay
News display options.
Definition news_type.h:100
NewsDisplay::Summary
@ Summary
Show ticker.
NewsDisplay::Full
@ Full
Show newspaper.
NewsDisplay::Off
@ Off
Only show a reminder in the status bar.
sound_type.h
Types related to sounds.
SoundFx
SoundFx
Sound effects from baseset.
Definition sound_type.h:45
station_type.h
Types related to stations.
strings_type.h
Types related to strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
CompanyManagerFace
Definition company_type.h:53
CompanyNewsInformation
Data that needs to be stored for company news messages.
Definition news_type.h:162
CompanyNewsInformation::face
CompanyManagerFace face
The face of the president.
Definition news_type.h:168
CompanyNewsInformation::colour
Colours colour
The colour related to the company.
Definition news_type.h:169
CompanyNewsInformation::president_name
std::string president_name
The name of the president.
Definition news_type.h:164
CompanyNewsInformation::company_name
std::string company_name
The name of the company.
Definition news_type.h:163
CompanyNewsInformation::other_company_name
std::string other_company_name
The name of the company taking over this one.
Definition news_type.h:165
Company
Definition company_base.h:127
NewsAllocatedData
Container for any custom data that must be deleted after the news item has reached end-of-life.
Definition news_type.h:131
NewsItem
Information about a single item of news.
Definition news_type.h:137
NewsItem::date
TimerGameCalendar::Date date
Calendar date to show for the news.
Definition news_type.h:139
NewsItem::data
std::unique_ptr< 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:149
NewsItem::type
NewsType type
Type of the news.
Definition news_type.h:141
NewsItem::headline
EncodedString headline
Headline of news.
Definition news_type.h:138
NewsItem::advice_type
AdviceType advice_type
The type of advice, to be able to remove specific advices later on.
Definition news_type.h:142
NewsItem::economy_date
TimerGameEconomy::Date economy_date
Economy date of the news item, never shown but used to calculate age.
Definition news_type.h:140
NewsItem::flags
NewsFlags flags
Window style for the news.
Definition news_type.h:144
NewsItem::ref2
NewsReference ref2
Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news ...
Definition news_type.h:147
NewsItem::ref1
NewsReference ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news,...
Definition news_type.h:146
NewsTypeData
Per-NewsType data.
Definition news_type.h:109
NewsTypeData::GetDisplay
NewsDisplay GetDisplay() const
Return the news display option.
Definition news_gui.cpp:348
NewsTypeData::NewsTypeData
NewsTypeData(std::string_view name, uint8_t age, SoundFx sound)
Construct this entry.
Definition news_type.h:120
NewsTypeData::name
const std::string_view name
Name.
Definition news_type.h:110
NewsTypeData::sound
const SoundFx sound
Sound.
Definition news_type.h:112
NewsTypeData::age
const uint8_t age
Maximum age of news items (in days)
Definition news_type.h:111
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
timer_game_calendar.h
Definition of the game-calendar-timer.
timer_game_economy.h
Definition of the game-economy-timer.
town_type.h
Types related to towns.
vehicle_type.h
Types related to vehicles.