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 script_news.hpp Everything to handle news messages. */
9 
10 #ifndef SCRIPT_NEWS_HPP
11 #define SCRIPT_NEWS_HPP
12 
13 #include "script_company.hpp"
14 #include "../../news_type.h"
15 
16 /**
17  * Class that handles news messages.
18  * @api game
19  */
20 class ScriptNews : public ScriptObject {
21 public:
22 	/**
23 	 * Enumeration for the news types that a script can create news for.
24 	 */
25 	enum NewsType {
26 		/* Arbitrary selection of NewsTypes which might make sense for scripts */
27 		NT_ACCIDENT          = ::NT_ACCIDENT,         ///< Category accidents.
28 		NT_COMPANY_INFO      = ::NT_COMPANY_INFO,     ///< Category company info.
29 		NT_ECONOMY           = ::NT_ECONOMY,          ///< Category economy.
30 		NT_ADVICE            = ::NT_ADVICE,           ///< Category vehicle advice.
31 		NT_ACCEPTANCE        = ::NT_ACCEPTANCE,       ///< Category acceptance changes.
32 		NT_SUBSIDIES         = ::NT_SUBSIDIES,        ///< Category subsidies.
33 		NT_GENERAL           = ::NT_GENERAL,          ///< Category general.
34 	};
35 
36 	/**
37 	 * Reference to a game element.
38 	 */
39 	enum NewsReferenceType {
40 		/* Selection of useful game elements to refer to. */
41 		NR_NONE     = ::NR_NONE,     ///< No reference supplied.
42 		NR_TILE     = ::NR_TILE,     ///< Reference location, scroll to the location when clicking on the news.
43 		NR_STATION  = ::NR_STATION,  ///< Reference station, scroll to the station when clicking on the news. Delete news when the station is deleted.
44 		NR_INDUSTRY = ::NR_INDUSTRY, ///< Reference industry, scrolls to the industry when clicking on the news. Delete news when the industry is deleted.
45 		NR_TOWN     = ::NR_TOWN,     ///< Reference town, scroll to the town when clicking on the news.
46 	};
47 
48 	/**
49 	 * Create a news message for everybody, or for one company.
50 	 * @param type The type of the news.
51 	 * @param text The text message to show (can be either a raw string, or a ScriptText object).
52 	 * @param company The company, or COMPANY_INVALID for all companies.
53 	 * @param ref_type Type of referred game element.
54 	 * @param reference The referenced game element of \a ref_type.
55 	 *  - For #NR_NONE this parameter is ignored.
56 	 *  - For #NR_TILE this parameter should be a valid location (ScriptMap::IsValidTile).
57 	 *  - For #NR_STATION this parameter should be a valid stationID (ScriptStation::IsValidStation).
58 	 *  - For #NR_INDUSTRY this parameter should be a valid industryID (ScriptIndustry::IsValidIndustry).
59 	 *  - For #NR_TOWN this parameter should be a valid townID (ScriptTown::IsValidTown).
60 	 * @return True if the action succeeded.
61 	 * @pre type must be #NT_ECONOMY, #NT_SUBSIDIES, or #NT_GENERAL.
62 	 * @pre text != nullptr.
63 	 * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
64 	 * @pre The \a reference condition must be fulfilled.
65 	 */
66 	static bool Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, uint32 reference);
67 };
68 
69 #endif /* SCRIPT_NEWS_HPP */
70