diff options
author | rubidium <rubidium@openttd.org> | 2008-04-19 12:50:02 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-04-19 12:50:02 +0000 |
commit | 222988603fd6f84f62a4ae9b626e4514d7a87f24 (patch) | |
tree | 2a67de4cb8e5e459437c6aee723aacba825c22e8 /src | |
parent | 161b58863144b9677ce8d8cdce0f23be33ddab49 (diff) | |
download | openttd-222988603fd6f84f62a4ae9b626e4514d7a87f24.tar.xz |
(svn r12785) -Codechange: put all news-type related constants in the same array. Patch by cirdan.
Diffstat (limited to 'src')
-rw-r--r-- | src/news_func.h | 2 | ||||
-rw-r--r-- | src/news_gui.cpp | 72 | ||||
-rw-r--r-- | src/news_type.h | 10 | ||||
-rw-r--r-- | src/settings.cpp | 4 |
4 files changed, 32 insertions, 56 deletions
diff --git a/src/news_func.h b/src/news_func.h index 97797db88..bb4ea6e72 100644 --- a/src/news_func.h +++ b/src/news_func.h @@ -17,7 +17,7 @@ extern NewsItem _statusbar_news_item; 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 diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 2d0ccf52c..49a86cbea 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -335,25 +335,24 @@ void AddNewsItem(StringID string, NewsMode display_mode, NewsFlag flags, NewsTyp /** - * 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 @@ static WindowDesc _news_type0_desc = { 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 @@ static void ShowNewspaper(NewsItem *ni) 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 @@ static void MoveToNextItem() 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(); diff --git a/src/news_type.h b/src/news_type.h index d8dc812a5..d96e2171a 100644 --- 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 @@ enum NewsBankrupcy { 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 diff --git a/src/settings.cpp b/src/settings.cpp index 307db3ecc..322b4014b 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1667,7 +1667,7 @@ static uint NewsDisplayLoadConfig(IniFile *ini, const char *grpname) 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 @@ static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname, uint news_d 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; } |