mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 06:15:04 +00:00
(svn r12785) -Codechange: put all news-type related constants in the same array. Patch by cirdan.
This commit is contained in:
parent
161b588631
commit
222988603f
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user