Files
@ r28486:aff297ed5a05
Branch filter:
Location: cpp/openttd-patchpack/source/src/news_type.h - annotation
r28486:aff297ed5a05
7.4 KiB
text/x-c
Codechange: Allow constexpr NWidgetPart construction.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r11932:f2bc1b879057 r27166:64e04a3ef9b1 r8763:c2c776621d56 r8990:18a889871a45 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r26120:15c912177c88 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r8763:c2c776621d56 r26058:9afbed473ec3 r12843:3cf702197a97 r9739:7dab005ce005 r9739:7dab005ce005 r8763:c2c776621d56 r10207:a1fc2f2a33db r8763:c2c776621d56 r8763:c2c776621d56 r10207:a1fc2f2a33db r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r12005:1096fe8178fd r12680:58e06ff4bbd2 r12680:58e06ff4bbd2 r12680:58e06ff4bbd2 r12680:58e06ff4bbd2 r12680:58e06ff4bbd2 r12680:58e06ff4bbd2 r12005:1096fe8178fd r26120:15c912177c88 r12005:1096fe8178fd r12005:1096fe8178fd r12005:1096fe8178fd r12005:1096fe8178fd r12005:1096fe8178fd r12005:1096fe8178fd r18737:1ee35da7fa2f r12005:1096fe8178fd r12005:1096fe8178fd r12005:1096fe8178fd r8763:c2c776621d56 r12723:c1156e536258 r8763:c2c776621d56 r8763:c2c776621d56 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19370:36325f02eb9c r12892:483f6ed01d67 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19370:36325f02eb9c r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r19369:05b3aefe07b5 r8763:c2c776621d56 r14900:c679fdaeebe6 r8763:c2c776621d56 r8763:c2c776621d56 r8763:c2c776621d56 r9010:56ff6c523703 r9010:56ff6c523703 r9010:56ff6c523703 r9010:56ff6c523703 r9010:56ff6c523703 r9010:56ff6c523703 r9010:56ff6c523703 r9010:56ff6c523703 r9010:56ff6c523703 r8990:18a889871a45 r8990:18a889871a45 r8990:18a889871a45 r11892:098f7f1cca8f r11892:098f7f1cca8f r11892:098f7f1cca8f r11892:098f7f1cca8f r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r19888:a6490abb0294 r11892:098f7f1cca8f r11892:098f7f1cca8f r19888:a6490abb0294 r11892:098f7f1cca8f r11892:098f7f1cca8f r19888:a6490abb0294 r19888:a6490abb0294 r8990:18a889871a45 r8990:18a889871a45 r25743:0be6a18df69a r25743:0be6a18df69a r27372:06d384d76bd2 r25743:0be6a18df69a r25743:0be6a18df69a r25743:0be6a18df69a r17629:21e9dfd343cd r8763:c2c776621d56 r27166:64e04a3ef9b1 r27166:64e04a3ef9b1 r27166:64e04a3ef9b1 r27166:64e04a3ef9b1 r27166:64e04a3ef9b1 r27166:64e04a3ef9b1 r8763:c2c776621d56 r27166:64e04a3ef9b1 r27166:64e04a3ef9b1 r27737:728d55b97775 r27737:728d55b97775 r8763:c2c776621d56 r25745:0d21ca5f3c29 r14524:d130da03f880 r27680:4da89a3b46b7 r25745:0d21ca5f3c29 r27737:728d55b97775 r8763:c2c776621d56 r8763:c2c776621d56 r25743:0be6a18df69a r25743:0be6a18df69a r25743:0be6a18df69a r25743:0be6a18df69a r25743:0be6a18df69a r25743:0be6a18df69a r9658:ead5a2d1816a r9658:ead5a2d1816a r9658:ead5a2d1816a r9658:ead5a2d1816a r9658:ead5a2d1816a r9658:ead5a2d1816a r25743:0be6a18df69a r25744:540e044a54a1 r25744:540e044a54a1 r25744:540e044a54a1 r9658:ead5a2d1816a r27737:728d55b97775 r9658:ead5a2d1816a r9658:ead5a2d1816a r25744:540e044a54a1 r9658:ead5a2d1816a r9658:ead5a2d1816a r8763:c2c776621d56 | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file news_type.h Types related to news. */
#ifndef NEWS_TYPE_H
#define NEWS_TYPE_H
#include "core/enum_type.hpp"
#include "timer/timer_game_calendar.h"
#include "strings_type.h"
#include "sound_type.h"
/**
* Type of news.
*/
enum NewsType : byte {
NT_ARRIVAL_COMPANY, ///< First vehicle arrived for company
NT_ARRIVAL_OTHER, ///< First vehicle arrived for competitor
NT_ACCIDENT, ///< An accident or disaster has occurred
NT_ACCIDENT_OTHER, ///< An accident or disaster has occurred
NT_COMPANY_INFO, ///< Company info (new companies, bankruptcy messages)
NT_INDUSTRY_OPEN, ///< Opening of industries
NT_INDUSTRY_CLOSE, ///< Closing of industries
NT_ECONOMY, ///< Economic changes (recession, industry up/dowm)
NT_INDUSTRY_COMPANY,///< Production changes of industry serviced by local company
NT_INDUSTRY_OTHER, ///< Production changes of industry serviced by competitor(s)
NT_INDUSTRY_NOBODY, ///< Other industry production changes
NT_ADVICE, ///< Bits of news about vehicles of the company
NT_NEW_VEHICLES, ///< New vehicle has become available
NT_ACCEPTANCE, ///< A type of cargo is (no longer) accepted
NT_SUBSIDIES, ///< News about subsidies (announcements, expirations, acceptance)
NT_GENERAL, ///< General news (from towns)
NT_END, ///< end-of-array marker
};
/**
* References to objects in news.
*
* @warning
* Be careful!
* Vehicles are a special case, as news are kept when vehicles are autoreplaced/renewed.
* You have to make sure, #ChangeVehicleNews catches the DParams of your message.
* This is NOT ensured by the references.
*/
enum NewsReferenceType : byte {
NR_NONE, ///< Empty reference
NR_TILE, ///< Reference tile. Scroll to tile when clicking on the news.
NR_VEHICLE, ///< Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted.
NR_STATION, ///< Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
NR_INDUSTRY, ///< Reference industry. Scroll to industry when clicking on the news. Delete news when industry is deleted.
NR_TOWN, ///< Reference town. Scroll to town when clicking on the news.
NR_ENGINE, ///< Reference engine.
};
/**
* Various OR-able news-item flags.
* @note #NF_INCOLOUR is set automatically if needed.
*/
enum NewsFlag {
NFB_INCOLOUR = 0, ///< News item is shown in colour (otherwise it is shown in black & white).
NFB_NO_TRANSPARENT = 1, ///< News item disables transparency in the viewport.
NFB_SHADE = 2, ///< News item uses shaded colours.
NFB_WINDOW_LAYOUT = 3, ///< First bit for window layout.
NFB_WINDOW_LAYOUT_COUNT = 3, ///< Number of bits for window layout.
NFB_VEHICLE_PARAM0 = 6, ///< String param 0 contains a vehicle ID. (special autoreplace behaviour)
NF_INCOLOUR = 1 << NFB_INCOLOUR, ///< Bit value for coloured news.
NF_NO_TRANSPARENT = 1 << NFB_NO_TRANSPARENT, ///< Bit value for disabling transparency.
NF_SHADE = 1 << NFB_SHADE, ///< Bit value for enabling shading.
NF_VEHICLE_PARAM0 = 1 << NFB_VEHICLE_PARAM0, ///< Bit value for specifying that string param 0 contains a vehicle ID. (special autoreplace behaviour)
NF_THIN = 0 << NFB_WINDOW_LAYOUT, ///< Thin news item. (Newspaper with headline and viewport)
NF_SMALL = 1 << NFB_WINDOW_LAYOUT, ///< Small news item. (Information window with text and viewport)
NF_NORMAL = 2 << NFB_WINDOW_LAYOUT, ///< Normal news item. (Newspaper with text only)
NF_VEHICLE = 3 << NFB_WINDOW_LAYOUT, ///< Vehicle news item. (new engine available)
NF_COMPANY = 4 << NFB_WINDOW_LAYOUT, ///< Company news item. (Newspaper with face)
};
DECLARE_ENUM_AS_BIT_SET(NewsFlag)
/**
* News display options
*/
enum NewsDisplay {
ND_OFF, ///< Only show a reminder in the status bar
ND_SUMMARY, ///< Show ticker
ND_FULL, ///< Show newspaper
};
/**
* Per-NewsType data
*/
struct NewsTypeData {
const char * const name; ///< Name
const byte age; ///< Maximum age of news items (in days)
const SoundFx sound; ///< Sound
/**
* Construct this entry.
* @param name The name of the type.
* @param age The maximum age for these messages.
* @param sound The sound to play.
*/
NewsTypeData(const char *name, byte age, SoundFx sound) :
name(name),
age(age),
sound(sound)
{
}
NewsDisplay GetDisplay() const;
};
/** Container for any custom data that must be deleted after the news item has reached end-of-life. */
struct NewsAllocatedData {
virtual ~NewsAllocatedData() = default;
};
/** Information about a single item of news. */
struct NewsItem {
NewsItem *prev; ///< Previous news item
NewsItem *next; ///< Next news item
StringID string_id; ///< Message text
TimerGameCalendar::Date date; ///< Date of the news
NewsType type; ///< Type of the news
NewsFlag flags; ///< NewsFlags bits @see NewsFlag
NewsReferenceType reftype1; ///< Type of ref1
NewsReferenceType reftype2; ///< Type of ref2
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.
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.
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.
std::vector<StringParameterBackup> params; ///< Parameters for string resolving.
NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32_t ref1, NewsReferenceType reftype2, uint32_t ref2, const NewsAllocatedData *data);
};
/** Container for a single string to be passed as NewsAllocatedData. */
struct NewsStringData : NewsAllocatedData {
std::string string; ///< The string to retain.
NewsStringData(const std::string &str) : string(str) {}
};
/**
* Data that needs to be stored for company news messages.
* The problem with company news messages are the custom name
* of the companies and the fact that the company data is reset,
* resulting in wrong names and such.
*/
struct CompanyNewsInformation : NewsAllocatedData {
std::string company_name; ///< The name of the company
std::string president_name; ///< The name of the president
std::string other_company_name; ///< The name of the company taking over this one
uint32_t face; ///< The face of the president
byte colour; ///< The colour related to the company
CompanyNewsInformation(const struct Company *c, const struct Company *other = nullptr);
};
#endif /* NEWS_TYPE_H */
|