OpenTTD Source 20260206-master-g4d4e37dbf1
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
9
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"
23#include "town_type.h"
24#include "vehicle_type.h"
25
49
64
74using NewsReference = std::variant<std::monostate, TileIndex, VehicleID, StationID, IndustryID, TownID, EngineID>;
75
77enum class NewsStyle : uint8_t {
83};
84
95using NewsFlags = EnumBitSet<NewsFlag, uint8_t>;
96
100enum class NewsDisplay : uint8_t {
104};
105
110 const std::string_view name;
111 const uint8_t age;
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
132 virtual ~NewsAllocatedData() = default;
133};
134
135
137struct NewsItem {
139 TimerGameCalendar::Date date;
140 TimerGameEconomy::Date economy_date;
143 NewsStyle style;
144 NewsFlags flags;
145
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
163 std::string company_name;
164 std::string president_name;
165 std::string other_company_name;
166
167 StringID title;
169 Colours colour;
170
171 CompanyNewsInformation(StringID title, const struct Company *c, const struct Company *other = nullptr);
172};
173
174using NewsContainer = std::list<NewsItem>;
175using NewsIterator = NewsContainer::const_iterator;
176
177#endif /* NEWS_TYPE_H */
Container for an encoded string, created by GetEncodedString.
Enum-as-bit-set wrapper.
Types related to companies.
Types related to engines.
Type (helpers) for enums.
Types related to the graphics and/or input devices.
Types related to the industry.
NewsType
Type of news.
Definition news_type.h:29
@ Advice
Bits of news about vehicles of the company.
Definition news_type.h:41
@ General
General news (from towns).
Definition news_type.h:45
@ ArrivalCompany
First vehicle arrived for company.
Definition news_type.h:30
@ CompanyInfo
Company info (new companies, bankruptcy messages).
Definition news_type.h:34
@ AccidentOther
An accident or disaster has occurred.
Definition news_type.h:33
@ IndustryCompany
Production changes of industry serviced by local company.
Definition news_type.h:38
@ IndustryClose
Closing of industries.
Definition news_type.h:36
@ IndustryOpen
Opening of industries.
Definition news_type.h:35
@ NewVehicles
New vehicle has become available.
Definition news_type.h:42
@ End
end-of-array marker
Definition news_type.h:47
@ IndustryNobody
Other industry production changes.
Definition news_type.h:40
@ Subsidies
News about subsidies (announcements, expirations, acceptance).
Definition news_type.h:44
@ ArrivalOther
First vehicle arrived for competitor.
Definition news_type.h:31
@ Accident
An accident or disaster has occurred.
Definition news_type.h:32
@ Acceptance
A type of cargo is (no longer) accepted.
Definition news_type.h:43
@ IndustryOther
Production changes of industry serviced by competitor(s).
Definition news_type.h:39
NewsContainer::const_iterator NewsIterator
Iterator type for news items.
Definition news_type.h:175
std::list< NewsItem > NewsContainer
Container type for storing news items.
Definition news_type.h:174
NewsStyle
News Window Styles.
Definition news_type.h:77
@ Small
Small news item. (Information window with text and viewport).
Definition news_type.h:79
@ Normal
Normal news item. (Newspaper with text only).
Definition news_type.h:80
@ Thin
Thin news item. (Newspaper with headline and viewport).
Definition news_type.h:78
AdviceType
Sub type of the NewsType::Advice to be able to remove specific news items.
Definition news_type.h:51
@ TrainStuck
The train got stuck and needs to be unstuck manually.
Definition news_type.h:56
@ VehicleLost
The vehicle has become lost.
Definition news_type.h:57
@ VehicleWaiting
The vehicle is waiting in the depot.
Definition news_type.h:60
@ Invalid
Invalid marker.
Definition news_type.h:62
@ AutorenewFailed
Autorenew or autoreplace failed.
Definition news_type.h:53
@ VehicleOld
The vehicle is starting to get old.
Definition news_type.h:58
@ VehicleUnprofitable
The vehicle is costing you money.
Definition news_type.h:59
@ AircraftDestinationTooFar
Next (order) destination is too far for the aircraft type.
Definition news_type.h:52
@ RefitFailed
The refit order failed to execute.
Definition news_type.h:55
std::variant< std::monostate, TileIndex, VehicleID, StationID, IndustryID, TownID, EngineID > NewsReference
References to objects in news.
Definition news_type.h:74
NewsFlag
Various OR-able news-item flags.
Definition news_type.h:89
@ VehicleParam0
String param 0 contains a vehicle ID. (special autoreplace behaviour).
Definition news_type.h:93
@ Shaded
News item uses shaded colours.
Definition news_type.h:92
@ InColour
News item is shown in colour (otherwise it is shown in black & white).
Definition news_type.h:90
NewsDisplay
News display options.
Definition news_type.h:100
@ Summary
Show ticker.
Definition news_type.h:102
@ Full
Show newspaper.
Definition news_type.h:103
@ Off
Only show a reminder in the status bar.
Definition news_type.h:101
Types related to sounds.
SoundFx
Sound effects from baseset.
Definition sound_type.h:46
Types related to stations.
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
CompanyManagerFace face
The face of the president.
Definition news_type.h:168
Colours colour
The colour related to the company.
Definition news_type.h:169
CompanyNewsInformation(StringID title, const struct Company *c, const struct Company *other=nullptr)
Fill the CompanyNewsInformation struct with the required data.
std::string president_name
The name of the president.
Definition news_type.h:164
std::string company_name
The name of the company.
Definition news_type.h:163
std::string other_company_name
The name of the company taking over this one.
Definition news_type.h:165
Data of the economy.
Container for any custom data that must be deleted after the news item has reached end-of-life.
Definition news_type.h:131
TimerGameCalendar::Date date
Calendar date to show for the news.
Definition news_type.h:139
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
NewsType type
Type of the news.
Definition news_type.h:141
EncodedString headline
Headline of news.
Definition news_type.h:138
AdviceType advice_type
The type of advice, to be able to remove specific advices later on.
Definition news_type.h:142
TimerGameEconomy::Date economy_date
Economy date of the news item, never shown but used to calculate age.
Definition news_type.h:140
NewsItem(EncodedString &&headline, NewsType type, NewsStyle style, NewsFlags flags, NewsReference ref1, NewsReference ref2, std::unique_ptr< NewsAllocatedData > &&data, AdviceType advice_type)
Create a new newsitem to be shown.
Definition news_gui.cpp:871
NewsFlags flags
Window style for the news.
Definition news_type.h:144
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
NewsReference ref1
Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news,...
Definition news_type.h:146
NewsDisplay GetDisplay() const
Return the news display option.
Definition news_gui.cpp:348
NewsTypeData(std::string_view name, uint8_t age, SoundFx sound)
Construct this entry.
Definition news_type.h:120
const std::string_view name
Name.
Definition news_type.h:110
const SoundFx sound
Sound.
Definition news_type.h:112
const uint8_t age
Maximum age of news items (in days).
Definition news_type.h:111
Vehicle data structure.
Definition of the game-calendar-timer.
Definition of the game-economy-timer.
Types related to towns.
Types related to vehicles.
@ NoTransparency
Viewport is never transparent.