File diff r27165:ea28ecab6159 → r27166:64e04a3ef9b1
src/news_type.h
Show inline comments
 
/*
 
 * 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 "date_type.h"
 
#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
 
@@ -103,59 +103,59 @@ struct NewsTypeData {
 
	/**
 
	 * 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() {}
 
};
 

	
 

	
 
/** Information about a single item of news. */
 
struct NewsItem {
 
	NewsItem *prev;              ///< Previous news item
 
	NewsItem *next;              ///< Next news item
 
	StringID string_id;          ///< Message text
 
	Date date;                   ///< Date of the news
 
	NewsType type;               ///< Type of the news
 
	NewsFlag flags;              ///< NewsFlags bits @see NewsFlag
 
	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 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 ref2;                 ///< Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
 
	NewsReferenceType reftype1;   ///< Type of ref1
 
	NewsReferenceType reftype2;   ///< Type of ref2
 
	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.
 
	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.
 

	
 
	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.
 

	
 
	uint64 params[10]; ///< Parameters for string resolving.
 

	
 
	NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 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