changeset 8990:c0b047cd829c draft

(svn r12785) -Codechange: put all news-type related constants in the same array. Patch by cirdan.
author rubidium <rubidium@openttd.org>
date Sat, 19 Apr 2008 12:50:02 +0000
parents 4ecc117ebb22
children 4a6bf04ea450
files src/news_func.h src/news_gui.cpp src/news_type.h src/settings.cpp
diffstat 4 files changed, 32 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/src/news_func.h
+++ b/src/news_func.h
@@ -17,7 +17,7 @@
 extern uint32 _news_display_opt;
 extern bool _news_ticker_sound;
 
-extern const char *_news_display_name[NT_END];
+extern const NewsTypeData _news_type_data[NT_END];
 
 /**
  * Delete a news item type about a vehicle
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -335,25 +335,24 @@
 
 
 /**
- * Maximum age of news items.
- * Don't show item if it's older than x days, corresponds with NewsType in news_type.h
- * @see NewsType
+ * Per-NewsType data
  */
-static const byte _news_items_age[NT_END] = {
-	60,  ///< NT_ARRIVAL_PLAYER
-	60,  ///< NT_ARRIVAL_OTHER
-	90,  ///< NT_ACCIDENT
-	60,  ///< NT_COMPANY_INFO
-	90,  ///< NT_OPENCLOSE
-	30,  ///< NT_ECONOMY
-	30,  ///< NT_INDUSTRY_PLAYER
-	30,  ///< NT_INDUSTRY_OTHER
-	30,  ///< NT_INDUSTRY_NOBODY
-	150, ///< NT_ADVICE
-	30,  ///< NT_NEW_VEHICLES
-	90,  ///< NT_ACCEPTANCE
-	180, ///< NT_SUBSIDIES
-	60   ///< NT_GENERAL
+const NewsTypeData _news_type_data[NT_END] = {
+	/* name,              age, sound           */
+	{ "arrival_player",    60, SND_1D_APPLAUSE },  ///< NT_ARRIVAL_PLAYER
+	{ "arrival_other",     60, SND_1D_APPLAUSE },  ///< NT_ARRIVAL_OTHER
+	{ "accident",          90, SND_BEGIN       },  ///< NT_ACCIDENT
+	{ "company_info",      60, SND_BEGIN       },  ///< NT_COMPANY_INFO
+	{ "openclose",         90, SND_BEGIN       },  ///< NT_OPENCLOSE
+	{ "economy",           30, SND_BEGIN       },  ///< NT_ECONOMY
+	{ "production_player", 30, SND_BEGIN       },  ///< NT_INDUSTRY_PLAYER
+	{ "production_other",  30, SND_BEGIN       },  ///< NT_INDUSTRY_OTHER
+	{ "production_nobody", 30, SND_BEGIN       },  ///< NT_INDUSTRY_NOBODY
+	{ "advice",           150, SND_BEGIN       },  ///< NT_ADVICE
+	{ "new_vehicles",      30, SND_1E_OOOOH    },  ///< NT_NEW_VEHICLES
+	{ "acceptance",        90, SND_BEGIN       },  ///< NT_ACCEPTANCE
+	{ "subsidies",        180, SND_BEGIN       },  ///< NT_SUBSIDIES
+	{ "general",           60, SND_BEGIN       },  ///< NT_GENERAL
 };
 
 
@@ -401,39 +400,6 @@
 	NewsWindowProc
 };
 
-static const SoundFx _news_sounds[NT_END] = {
-	SND_1D_APPLAUSE, ///< NT_ARRIVAL_PLAYER
-	SND_1D_APPLAUSE, ///< NT_ARRIVAL_OTHER
-	SND_BEGIN,       ///< NT_ACCIDENT
-	SND_BEGIN,       ///< NT_COMPANY_INFO
-	SND_BEGIN,       ///< NT_OPENCLOSE
-	SND_BEGIN,       ///< NT_ECONOMY
-	SND_BEGIN,       ///< NT_INDUSTRY_PLAYER
-	SND_BEGIN,       ///< NT_INDUSTRY_OTHER
-	SND_BEGIN,       ///< NT_INDUSTRY_NOBODY
-	SND_BEGIN,       ///< NT_ADVICE
-	SND_1E_OOOOH,    ///< NT_NEW_VEHICLES
-	SND_BEGIN,       ///< NT_ACCEPTANCE
-	SND_BEGIN,       ///< NT_SUBSIDIES
-	SND_BEGIN,       ///< NT_GENERAL
-};
-
-const char *_news_display_name[NT_END] = {
-	"arrival_player",
-	"arrival_other",
-	"accident",
-	"company_info",
-	"openclose",
-	"economy",
-	"production_player",
-	"production_other",
-	"production_nobody",
-	"advice",
-	"new_vehicles",
-	"acceptance",
-	"subsidies",
-	"general",
-};
 
 /**
  * Get the value of an item of the news-display settings. This is
@@ -465,7 +431,7 @@
 	ni->flags &= ~NF_FORCE_BIG;
 	ni->duration = 555;
 
-	SoundFx sound = _news_sounds[ni->type];
+	SoundFx sound = _news_type_data[ni->type].sound;
 	if (sound != 0) SndPlayFx(sound);
 
 	int top = _screen.height;
@@ -553,7 +519,7 @@
 		NewsItem *ni = &_news_items[_current_news];
 
 		/* check the date, don't show too old items */
-		if (_date - _news_items_age[ni->type] > ni->date) return;
+		if (_date - _news_type_data[ni->type].age > ni->date) return;
 
 		switch (GetNewsDisplayValue(ni->type)) {
 			default: NOT_REACHED();
--- a/src/news_type.h
+++ b/src/news_type.h
@@ -8,6 +8,7 @@
 #include "window_type.h"
 #include "date_type.h"
 #include "strings_type.h"
+#include "sound_type.h"
 
 /**
  * Type of news.
@@ -75,6 +76,15 @@
 	NB_BNEWCOMPANY = (4 << 4), ///< A new company has been started
 };
 
+/**
+ * Per-NewsType data
+ */
+struct NewsTypeData {
+	const char *const name; ///< Name
+	const byte age;         ///< Maximum age of news items (in days)
+	const SoundFx sound;    ///< Sound
+};
+
 struct NewsItem {
 	StringID string_id;    ///< Message text (sometimes also used for storing other info)
 	uint16 duration;       ///< Remaining time for showing this news message
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1667,7 +1667,7 @@
 	for (item = group->item; item != NULL; item = item->next) {
 		int news_item = -1;
 		for (int i = 0; i < NT_END; i++) {
-			if (strcasecmp(item->name, _news_display_name[i]) == 0) {
+			if (strcasecmp(item->name, _news_type_data[i].name) == 0) {
 				news_item = i;
 				break;
 			}
@@ -1760,7 +1760,7 @@
 
 		value = (v == 0 ? "off" : (v == 1 ? "summarized" : "full"));
 
-		*item = ini_item_alloc(group, _news_display_name[i], strlen(_news_display_name[i]));
+		*item = ini_item_alloc(group, _news_type_data[i].name, strlen(_news_type_data[i].name));
 		(*item)->value = (char*)pool_strdup(&ini->pool, value, strlen(value));
 		item = &(*item)->next;
 	}