Changeset - r11464:d0a348843230
[Not reviewed]
master
0 3 0
smatz - 15 years ago 2009-03-23 11:48:05
smatz@openttd.org
(svn r15830) -Codechange: don't use fixed size of array in news_gui.cpp and news_func.h
3 files changed with 10 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/news_func.h
Show inline comments
 
@@ -7,25 +7,25 @@
 

	
 
#include "news_type.h"
 
#include "vehicle_type.h"
 
#include "station_type.h"
 

	
 
void AddNewsItem(StringID string, NewsSubtype subtype, uint data_a, uint data_b, void *free_data = NULL);
 
void NewsLoop();
 
void InitNewsItemStructs();
 

	
 
extern NewsItem _statusbar_news_item;
 
extern bool _news_ticker_sound;
 

	
 
extern NewsTypeData _news_type_data[NT_END];
 
extern NewsTypeData _news_type_data[];
 

	
 
/**
 
 * Delete a news item type about a vehicle
 
 * if the news item type is INVALID_STRING_ID all news about the vehicle get
 
 * deleted
 
 */
 
void DeleteVehicleNews(VehicleID, StringID news);
 

	
 
/** Delete news associated with given station */
 
void DeleteStationNews(StationID);
 

	
 
#endif /* NEWS_FUNC_H */
src/news_gui.cpp
Show inline comments
 
@@ -95,69 +95,73 @@ static void DrawNewsBankrupcy(Window *w,
 
 * Data common to all news items of a given subtype (structure)
 
 */
 
struct NewsSubtypeData {
 
	NewsType type;         ///< News category @see NewsType
 
	NewsMode display_mode; ///< Display mode value @see NewsMode
 
	NewsFlag flags;        ///< Initial NewsFlags bits @see NewsFlag
 
	DrawNewsCallbackProc *callback; ///< Call-back function
 
};
 

	
 
/**
 
 * Data common to all news items of a given subtype (actual data)
 
 */
 
static const struct NewsSubtypeData _news_subtype_data[NS_END] = {
 
static const NewsSubtypeData _news_subtype_data[] = {
 
	/* type,               display_mode, flags,                  callback */
 
	{ NT_ARRIVAL_COMPANY,  NM_THIN,     NF_VIEWPORT|NF_VEHICLE, NULL                    }, ///< NS_ARRIVAL_COMPANY
 
	{ NT_ARRIVAL_OTHER,    NM_THIN,     NF_VIEWPORT|NF_VEHICLE, NULL                    }, ///< NS_ARRIVAL_OTHER
 
	{ NT_ACCIDENT,         NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_ACCIDENT_TILE
 
	{ NT_ACCIDENT,         NM_THIN,     NF_VIEWPORT|NF_VEHICLE, NULL                    }, ///< NS_ACCIDENT_VEHICLE
 
	{ NT_COMPANY_INFO,     NM_NORMAL,   NF_NONE,                DrawNewsBankrupcy       }, ///< NS_COMPANY_TROUBLE
 
	{ NT_COMPANY_INFO,     NM_NORMAL,   NF_NONE,                DrawNewsBankrupcy       }, ///< NS_COMPANY_MERGER
 
	{ NT_COMPANY_INFO,     NM_NORMAL,   NF_NONE,                DrawNewsBankrupcy       }, ///< NS_COMPANY_BANKRUPT
 
	{ NT_COMPANY_INFO,     NM_NORMAL,   NF_TILE,                DrawNewsBankrupcy       }, ///< NS_COMPANY_NEW
 
	{ NT_INDUSTRY_OPEN,    NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_INDUSTRY_OPEN
 
	{ NT_INDUSTRY_CLOSE,   NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_INDUSTRY_CLOSE
 
	{ NT_ECONOMY,          NM_NORMAL,   NF_NONE,                NULL                    }, ///< NS_ECONOMY
 
	{ NT_INDUSTRY_COMPANY, NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_INDUSTRY_COMPANY
 
	{ NT_INDUSTRY_OTHER,   NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_INDUSTRY_OTHER
 
	{ NT_INDUSTRY_NOBODY,  NM_THIN,     NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_INDUSTRY_NOBODY
 
	{ NT_ADVICE,           NM_SMALL,    NF_VIEWPORT|NF_VEHICLE, NULL                    }, ///< NS_ADVICE
 
	{ NT_NEW_VEHICLES,     NM_NORMAL,   NF_NONE,                DrawNewsNewVehicleAvail }, ///< NS_NEW_VEHICLES
 
	{ NT_ACCEPTANCE,       NM_SMALL,    NF_VIEWPORT|NF_TILE,    NULL                    }, ///< NS_ACCEPTANCE
 
	{ NT_SUBSIDIES,        NM_NORMAL,   NF_TILE|NF_TILE2,       NULL                    }, ///< NS_SUBSIDIES
 
	{ NT_GENERAL,          NM_NORMAL,   NF_TILE,                NULL                    }, ///< NS_GENERAL
 
};
 

	
 
assert_compile(lengthof(_news_subtype_data) == NS_END);
 

	
 
/**
 
 * Per-NewsType data
 
 */
 
NewsTypeData _news_type_data[NT_END] = {
 
NewsTypeData _news_type_data[] = {
 
	/* name,              age, sound,           display */
 
	{ "arrival_player",    60, SND_1D_APPLAUSE, ND_FULL },  ///< NT_ARRIVAL_COMPANY
 
	{ "arrival_other",     60, SND_1D_APPLAUSE, ND_FULL },  ///< NT_ARRIVAL_OTHER
 
	{ "accident",          90, SND_BEGIN,       ND_FULL },  ///< NT_ACCIDENT
 
	{ "company_info",      60, SND_BEGIN,       ND_FULL },  ///< NT_COMPANY_INFO
 
	{ "open",              90, SND_BEGIN,       ND_FULL },  ///< NT_INDUSTRY_OPEN
 
	{ "close",             90, SND_BEGIN,       ND_FULL },  ///< NT_INDUSTRY_CLOSE
 
	{ "economy",           30, SND_BEGIN,       ND_FULL },  ///< NT_ECONOMY
 
	{ "production_player", 30, SND_BEGIN,       ND_FULL },  ///< NT_INDUSTRY_COMPANY
 
	{ "production_other",  30, SND_BEGIN,       ND_FULL },  ///< NT_INDUSTRY_OTHER
 
	{ "production_nobody", 30, SND_BEGIN,       ND_FULL },  ///< NT_INDUSTRY_NOBODY
 
	{ "advice",           150, SND_BEGIN,       ND_FULL },  ///< NT_ADVICE
 
	{ "new_vehicles",      30, SND_1E_OOOOH,    ND_FULL },  ///< NT_NEW_VEHICLES
 
	{ "acceptance",        90, SND_BEGIN,       ND_FULL },  ///< NT_ACCEPTANCE
 
	{ "subsidies",        180, SND_BEGIN,       ND_FULL },  ///< NT_SUBSIDIES
 
	{ "general",           60, SND_BEGIN,       ND_FULL },  ///< NT_GENERAL
 
};
 

	
 
assert_compile(lengthof(_news_type_data) == NT_END);
 

	
 
struct NewsWindow : Window {
 
	uint16 chat_height;
 
	NewsItem *ni;
 
	static uint duration;
 

	
 
	NewsWindow(const WindowDesc *desc, NewsItem *ni) : Window(desc), ni(ni)
 
	{
 
		NewsWindow::duration = 555;
 
		const Window *w = FindWindowById(WC_SEND_NETWORK_MSG, 0);
 
		this->chat_height = (w != NULL) ? w->height : 0;
 

	
 
		this->ni = _forced_news == NULL ? _current_news : _forced_news;
src/news_type.h
Show inline comments
 
@@ -86,27 +86,27 @@ DECLARE_ENUM_AS_BIT_SET(NewsFlag);
 
 */
 
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
 
	NewsDisplay display;    ///< Display mode (off, summary, full)
 
	const byte age;          ///< Maximum age of news items (in days)
 
	const SoundFx sound;     ///< Sound
 
	NewsDisplay display;     ///< Display mode (off, summary, full)
 
};
 

	
 
struct NewsItem {
 
	NewsItem *prev;        ///< Previous news item
 
	NewsItem *next;        ///< Next news item
 
	StringID string_id;    ///< Message text
 
	Date date;             ///< Date of the news
 
	NewsSubtype subtype;   ///< News subtype @see NewsSubtype
 
	NewsFlag flags;        ///< NewsFlags bits @see NewsFlag
 

	
 
	uint data_a;           ///< Custom data 1 (usually tile or vehicle)
 
	uint data_b;           ///< Custom data 2
0 comments (0 inline, 0 general)