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