summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-05-15 13:39:36 +0000
committerrubidium <rubidium@openttd.org>2008-05-15 13:39:36 +0000
commit373343cef606e940bfc99aa813cd05d36b15cb45 (patch)
treedbf82a81f389a63eb11a06152870ba44cc07d456
parentc709b8a711039a12c4e105e9ec9c768f20cbf4a8 (diff)
downloadopenttd-373343cef606e940bfc99aa813cd05d36b15cb45.tar.xz
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
-rw-r--r--src/aircraft_cmd.cpp4
-rw-r--r--src/autoreplace_cmd.cpp4
-rw-r--r--src/currency.cpp2
-rw-r--r--src/disaster_cmd.cpp12
-rw-r--r--src/economy.cpp20
-rw-r--r--src/engine.cpp2
-rw-r--r--src/industry_cmd.cpp26
-rw-r--r--src/news_func.h2
-rw-r--r--src/news_gui.cpp59
-rw-r--r--src/news_type.h29
-rw-r--r--src/order_cmd.cpp2
-rw-r--r--src/players.cpp4
-rw-r--r--src/roadveh_cmd.cpp6
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/town_cmd.cpp2
-rw-r--r--src/train_cmd.cpp8
-rw-r--r--src/vehicle.cpp6
-rw-r--r--src/water_cmd.cpp2
19 files changed, 126 insertions, 68 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 197bb24b0..492689a07 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -1398,7 +1398,7 @@ static void CrashAirplane(Vehicle *v)
SetDParam(1, st->index);
AddNewsItem(newsitem,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, DNC_NONE,
+ NS_ACCIDENT_VEHICLE,
v->index,
0);
@@ -1443,7 +1443,7 @@ static void AircraftEntersTerminal(Vehicle *v)
/* show newsitem of celebrating citizens */
AddNewsItem(
STR_A033_CITIZENS_CELEBRATE_FIRST,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, (v->owner == _local_player) ? NT_ARRIVAL_PLAYER : NT_ARRIVAL_OTHER, DNC_NONE,
+ (v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
v->index,
0);
}
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index fb5ad11f9..8b7688107 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -323,7 +323,7 @@ static CommandCost WagonRemoval(Vehicle *v, uint16 old_total_length)
if (v == NULL) {
/* We sold all the wagons and the train is still not short enough */
SetDParam(0, front->unitnumber);
- AddNewsItem(STR_TRAIN_TOO_LONG_AFTER_REPLACEMENT, NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE, front->index, 0);
+ AddNewsItem(STR_TRAIN_TOO_LONG_AFTER_REPLACEMENT, NS_ADVICE, front->index, 0);
return cost;
}
@@ -480,7 +480,7 @@ CommandCost MaybeReplaceVehicle(Vehicle *v, uint32 flags, bool display_costs)
default: NOT_REACHED(); message = 0; break;
}
- AddNewsItem(message, NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, DNC_NONE, v->index, 0);
+ AddNewsItem(message, NS_ADVICE, v->index, 0);
}
}
}
diff --git a/src/currency.cpp b/src/currency.cpp
index 816dbe7c4..b26de04bb 100644
--- a/src/currency.cpp
+++ b/src/currency.cpp
@@ -154,7 +154,7 @@ void CheckSwitchToEuro()
_currency_specs[_opt.currency].to_euro != CF_ISEURO &&
_cur_year >= _currency_specs[_opt.currency].to_euro) {
_opt.currency = 2; // this is the index of euro above.
- AddNewsItem(STR_EURO_INTRODUCE, NM_NORMAL, NF_NONE, NT_ECONOMY, DNC_NONE, 0, 0);
+ AddNewsItem(STR_EURO_INTRODUCE, NS_ECONOMY, 0, 0);
}
}
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 5dde38145..848f97144 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -234,7 +234,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
SetDParam(0, GetStationIndex(tile));
AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, DNC_NONE,
+ NS_ACCIDENT_VEHICLE,
v->index,
0);
}
@@ -367,7 +367,7 @@ static void DisasterTick_Ufo(Vehicle *v)
u->vehstatus |= VS_CRASHED;
AddNewsItem(STR_B001_ROAD_VEHICLE_DESTROYED,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, DNC_NONE,
+ NS_ACCIDENT_VEHICLE,
u->index,
0);
}
@@ -442,7 +442,7 @@ static void DisasterTick_Airplane(Vehicle *v)
DestructIndustry(i);
SetDParam(0, i->town->index);
- AddNewsItem(STR_B002_OIL_REFINERY_EXPLOSION, NM_THIN, NF_VIEWPORT | NF_TILE, NT_ACCIDENT, DNC_NONE, i->xy, 0);
+ AddNewsItem(STR_B002_OIL_REFINERY_EXPLOSION, NS_ACCIDENT_TILE, i->xy, 0);
SndPlayTileFx(SND_12_EXPLOSION, i->xy);
}
} else if (v->current_order.GetDestination() == 0) {
@@ -515,7 +515,7 @@ static void DisasterTick_Helicopter(Vehicle *v)
DestructIndustry(i);
SetDParam(0, i->town->index);
- AddNewsItem(STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS, NM_THIN, NF_VIEWPORT | NF_TILE, NT_ACCIDENT, DNC_NONE, i->xy, 0);
+ AddNewsItem(STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS, NS_ACCIDENT_TILE, i->xy, 0);
SndPlayTileFx(SND_12_EXPLOSION, i->xy);
}
} else if (v->current_order.GetDestination() == 0) {
@@ -600,7 +600,7 @@ static void DisasterTick_Big_Ufo(Vehicle *v)
t = ClosestTownFromTile(v->dest_tile, (uint)-1);
SetDParam(0, t->index);
AddNewsItem(STR_B004_UFO_LANDS_NEAR,
- NM_THIN, NF_VIEWPORT | NF_TILE, NT_ACCIDENT, DNC_NONE,
+ NS_ACCIDENT_TILE,
v->tile,
0);
@@ -978,7 +978,7 @@ static void Disaster_CoalMine_Init()
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) {
SetDParam(0, i->town->index);
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
- NM_THIN, NF_VIEWPORT | NF_TILE, NT_ACCIDENT, DNC_NONE, i->xy + TileDiffXY(1, 1), 0);
+ NS_ACCIDENT_TILE, i->xy + TileDiffXY(1, 1), 0);
{
TileIndex tile = i->xy;
diff --git a/src/economy.cpp b/src/economy.cpp
index c2f321f17..395d92a86 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -531,7 +531,7 @@ static void PlayersCheckBankrupt(Player *p)
SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED);
SetDParam(2, owner);
AddNewsItem(STR_02B6,
- NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, owner | NB_BTROUBLE);
+ NS_COMPANY_TROUBLE, 0, owner | NB_BTROUBLE);
break;
case 3: {
/* XXX - In multiplayer, should we ask other players if it wants to take
@@ -541,7 +541,7 @@ static void PlayersCheckBankrupt(Player *p)
SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED);
SetDParam(2, owner);
AddNewsItem(STR_02B6,
- NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, owner | NB_BTROUBLE);
+ NS_COMPANY_TROUBLE, 0, owner | NB_BTROUBLE);
break;
}
@@ -564,7 +564,7 @@ static void PlayersCheckBankrupt(Player *p)
SetDParam(0, STR_705C_BANKRUPT);
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY);
SetDParam(2, p->index);
- AddNewsItem(STR_02B6, NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, owner | NB_BBANKRUPT);
+ AddNewsItem(STR_02B6, NS_COMPANY_BANKRUPT, 0, owner | NB_BBANKRUPT);
if (IsHumanPlayer(owner)) {
/* XXX - If we are in offline mode, leave the player playing. Eg. there
@@ -774,10 +774,10 @@ static void HandleEconomyFluctuations()
if (--_economy.fluct == 0) {
_economy.fluct = -(int)GB(Random(), 0, 2);
- AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NM_NORMAL, NF_NONE, NT_ECONOMY, DNC_NONE, 0, 0);
+ AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NS_ECONOMY, 0, 0);
} else if (_economy.fluct == -12) {
_economy.fluct = GB(Random(), 0, 8) + 312;
- AddNewsItem(STR_7074_RECESSION_OVER_UPTURN_IN, NM_NORMAL, NF_NONE, NT_ECONOMY, DNC_NONE, 0, 0);
+ AddNewsItem(STR_7074_RECESSION_OVER_UPTURN_IN, NS_ECONOMY, 0, 0);
}
}
@@ -1117,14 +1117,14 @@ static void SubsidyMonthlyHandler()
if (s->age == 12-1) {
pair = SetupSubsidyDecodeParam(s, 1);
- AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NM_NORMAL, NF_TILE | NF_TILE2, NT_SUBSIDIES, DNC_NONE, pair.a, pair.b);
+ AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, pair.a, pair.b);
s->cargo_type = CT_INVALID;
modified = true;
} else if (s->age == 2*12-1) {
st = GetStation(s->to);
if (st->owner == _local_player) {
pair = SetupSubsidyDecodeParam(s, 1);
- AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NM_NORMAL, NF_TILE | NF_TILE2, NT_SUBSIDIES, DNC_NONE, pair.a, pair.b);
+ AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, pair.a, pair.b);
}
s->cargo_type = CT_INVALID;
modified = true;
@@ -1163,7 +1163,7 @@ static void SubsidyMonthlyHandler()
if (!CheckSubsidyDuplicate(s)) {
s->age = 0;
pair = SetupSubsidyDecodeParam(s, 0);
- AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NM_NORMAL, NF_TILE | NF_TILE2, NT_SUBSIDIES, DNC_NONE, pair.a, pair.b);
+ AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, pair.a, pair.b);
modified = true;
break;
}
@@ -1380,7 +1380,7 @@ static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type)
SetDParam(0, _current_player);
AddNewsItem(
STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier,
- NM_NORMAL, NF_TILE | NF_TILE2, NT_SUBSIDIES, DNC_NONE,
+ NS_SUBSIDIES,
pair.a, pair.b
);
@@ -1822,7 +1822,7 @@ static void DoAcquireCompany(Player *p)
SetDParam(2, p->index);
SetDParam(3, _current_player);
SetDParam(4, p->bankrupt_value);
- AddNewsItem(STR_02B6, NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, _current_player | NB_BMERGER);
+ AddNewsItem(STR_02B6, NS_COMPANY_MERGER, 0, _current_player | NB_BMERGER);
/* original code does this a little bit differently */
PlayerID pi = p->index;
diff --git a/src/engine.cpp b/src/engine.cpp
index 0827a74df..096721137 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -468,7 +468,7 @@ static void NewVehicleAvailable(Engine *e)
SetDParam(0, GetEngineCategoryName(index));
SetDParam(1, index);
- AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NM_CALLBACK, NF_NONE, NT_NEW_VEHICLES, DNC_VEHICLEAVAIL, index, 0);
+ AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, index, 0);
}
void EnginesMonthlyLoop()
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index ea233a230..66f7c840b 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1651,7 +1651,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
SetDParam(1, ind->town->index);
}
AddNewsItem(indspec->new_industry_text,
- NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, DNC_NONE, ind->xy, 0);
+ NS_OPENCLOSE, ind->xy, 0);
break;
}
}
@@ -1870,7 +1870,7 @@ static void MaybeNewIndustry(void)
SetDParam(1, ind->town->index);
}
AddNewsItem(ind_spc->new_industry_text,
- NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, DNC_NONE, ind->xy, 0);
+ NS_OPENCLOSE, ind->xy, 0);
}
/**
@@ -2002,12 +2002,12 @@ int WhoCanServiceIndustry(Industry* ind)
*/
static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent)
{
- NewsType nt;
+ NewsSubtype ns;
switch (WhoCanServiceIndustry(ind)) {
- case 0: nt = NT_INDUSTRY_NOBODY; break;
- case 1: nt = NT_INDUSTRY_OTHER; break;
- case 2: nt = NT_INDUSTRY_PLAYER; break;
+ case 0: ns = NS_INDUSTRY_NOBODY; break;
+ case 1: ns = NS_INDUSTRY_OTHER; break;
+ case 2: ns = NS_INDUSTRY_PLAYER; break;
default: NOT_REACHED(); break;
}
SetDParam(2, abs(percent));
@@ -2015,7 +2015,7 @@ static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int
SetDParam(1, ind->index);
AddNewsItem(
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
- NM_THIN, NF_VIEWPORT | NF_TILE, nt, DNC_NONE,
+ ns,
ind->xy + TileDiffXY(1, 1), 0
);
}
@@ -2183,15 +2183,15 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
}
if (!suppress_message && str != STR_NULL) {
- NewsType nt;
+ NewsSubtype ns;
/* Compute news category */
if (closeit) {
- nt = NT_OPENCLOSE;
+ ns = NS_OPENCLOSE;
} else {
switch (WhoCanServiceIndustry(i)) {
- case 0: nt = NT_INDUSTRY_NOBODY; break;
- case 1: nt = NT_INDUSTRY_OTHER; break;
- case 2: nt = NT_INDUSTRY_PLAYER; break;
+ case 0: ns = NS_INDUSTRY_NOBODY; break;
+ case 1: ns = NS_INDUSTRY_OTHER; break;
+ case 2: ns = NS_INDUSTRY_PLAYER; break;
default: NOT_REACHED(); break;
}
}
@@ -2209,7 +2209,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
}
/* and report the news to the user */
AddNewsItem(str,
- NM_THIN, NF_VIEWPORT | NF_TILE, nt, DNC_NONE,
+ ns,
i->xy + TileDiffXY(1, 1), 0);
}
}
diff --git a/src/news_func.h b/src/news_func.h
index 5ccbbef4d..c43030375 100644
--- a/src/news_func.h
+++ b/src/news_func.h
@@ -8,7 +8,7 @@
#include "news_type.h"
#include "vehicle_type.h"
-void AddNewsItem(StringID string, NewsMode mode, NewsFlag flag, NewsType type, NewsCallback callback, uint data_a, uint data_b);
+void AddNewsItem(StringID string, NewsSubtype subtype, uint data_a, uint data_b);
void NewsLoop();
void DrawNewsBorder(const Window *w);
void InitNewsItemStructs();
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 509d058b9..fb076eb9d 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -83,6 +83,41 @@ static DrawNewsCallbackProc * const _draw_news_callback[] = {
DrawNewsBankrupcy, ///< DNC_BANKRUPCY
};
+/**
+ * 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
+ NewsCallback 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] = {
+ /* type, display_mode, flags, callback */
+ { NT_ARRIVAL_PLAYER, NM_THIN, NF_VIEWPORT|NF_VEHICLE, DNC_NONE }, ///< NS_ARRIVAL_PLAYER
+ { NT_ARRIVAL_OTHER, NM_THIN, NF_VIEWPORT|NF_VEHICLE, DNC_NONE }, ///< NS_ARRIVAL_OTHER
+ { NT_ACCIDENT, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_ACCIDENT_TILE
+ { NT_ACCIDENT, NM_THIN, NF_VIEWPORT|NF_VEHICLE, DNC_NONE }, ///< NS_ACCIDENT_VEHICLE
+ { NT_COMPANY_INFO, NM_CALLBACK, NF_NONE, DNC_BANKRUPCY }, ///< NS_COMPANY_TROUBLE
+ { NT_COMPANY_INFO, NM_CALLBACK, NF_NONE, DNC_BANKRUPCY }, ///< NS_COMPANY_MERGER
+ { NT_COMPANY_INFO, NM_CALLBACK, NF_NONE, DNC_BANKRUPCY }, ///< NS_COMPANY_BANKRUPT
+ { NT_COMPANY_INFO, NM_CALLBACK, NF_TILE, DNC_BANKRUPCY }, ///< NS_COMPANY_NEW
+ { NT_OPENCLOSE, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_OPENCLOSE
+ { NT_ECONOMY, NM_NORMAL, NF_NONE, DNC_NONE }, ///< NS_ECONOMY
+ { NT_INDUSTRY_PLAYER, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_INDUSTRY_PLAYER
+ { NT_INDUSTRY_OTHER, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_INDUSTRY_OTHER
+ { NT_INDUSTRY_NOBODY, NM_THIN, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_INDUSTRY_NOBODY
+ { NT_ADVICE, NM_SMALL, NF_VIEWPORT|NF_VEHICLE, DNC_NONE }, ///< NS_ADVICE
+ { NT_NEW_VEHICLES, NM_CALLBACK, NF_NONE, DNC_VEHICLEAVAIL }, ///< NS_NEW_VEHICLES
+ { NT_ACCEPTANCE, NM_SMALL, NF_VIEWPORT|NF_TILE, DNC_NONE }, ///< NS_ACCEPTANCE
+ { NT_SUBSIDIES, NM_NORMAL, NF_TILE|NF_TILE2, DNC_NONE }, ///< NS_SUBSIDIES
+ { NT_GENERAL, NM_NORMAL, NF_TILE, DNC_NONE }, ///< NS_GENERAL
+};
+
/** Initialize the news-items data structures */
void InitNewsItemStructs()
{
@@ -124,8 +159,9 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
case WE_PAINT: {
const NewsItem *ni = WP(w, news_d).ni;
+ const NewsMode display_mode = _news_subtype_data[ni->subtype].display_mode;
- switch (ni->display_mode) {
+ switch (display_mode) {
case NM_NORMAL:
case NM_THIN: {
DrawNewsBorder(w);
@@ -137,7 +173,7 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
if (!(ni->flags & NF_VIEWPORT)) {
CopyInDParam(0, ni->params, lengthof(ni->params));
- DrawStringMultiCenter(215, ni->display_mode == NM_NORMAL ? 76 : 56,
+ DrawStringMultiCenter(215, display_mode == NM_NORMAL ? 76 : 56,
ni->string_id, w->width - 4);
} else {
/* Back up transparency options to draw news view */
@@ -160,7 +196,7 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
}
case NM_CALLBACK:
- _draw_news_callback[ni->callback](w, ni);
+ _draw_news_callback[_news_subtype_data[ni->subtype].callback](w, ni);
break;
default:
@@ -283,7 +319,7 @@ static inline NewsID DecreaseIndex(NewsID i)
* @see NewsType
* @see NewsCallback
*/
-void AddNewsItem(StringID string, NewsMode display_mode, NewsFlag flags, NewsType type, NewsCallback callback, uint data_a, uint data_b)
+void AddNewsItem(StringID string, NewsSubtype subtype, uint data_a, uint data_b)
{
if (_game_mode == GM_MENU) return;
@@ -314,14 +350,12 @@ void AddNewsItem(StringID string, NewsMode display_mode, NewsFlag flags, NewsTyp
memset(ni, 0, sizeof(*ni));
ni->string_id = string;
- ni->display_mode = display_mode;
- ni->flags = flags;
+ ni->subtype = subtype;
+ ni->flags = _news_subtype_data[subtype].flags;
/* show this news message in color? */
if (_cur_year >= _patches.colored_news_year) ni->flags |= NF_INCOLOR;
- ni->type = type;
- ni->callback = callback;
ni->data_a = data_a;
ni->data_b = data_b;
ni->date = _date;
@@ -407,12 +441,12 @@ static void ShowNewspaper(NewsItem *ni)
ni->flags &= ~NF_FORCE_BIG;
ni->duration = 555;
- SoundFx sound = _news_type_data[ni->type].sound;
+ SoundFx sound = _news_type_data[_news_subtype_data[ni->subtype].type].sound;
if (sound != 0) SndPlayFx(sound);
int top = _screen.height;
Window *w;
- switch (ni->display_mode) {
+ switch (_news_subtype_data[ni->subtype].display_mode) {
case NM_NORMAL:
case NM_CALLBACK:
_news_type13_desc.top = top;
@@ -493,11 +527,12 @@ static void MoveToNextItem()
if (_current_news != _latest_news) {
_current_news = (_current_news == INVALID_NEWS) ? _oldest_news : IncreaseIndex(_current_news);
NewsItem *ni = &_news_items[_current_news];
+ const NewsType type = _news_subtype_data[ni->subtype].type;
/* check the date, don't show too old items */
- if (_date - _news_type_data[ni->type].age > ni->date) return;
+ if (_date - _news_type_data[type].age > ni->date) return;
- switch (_news_type_data[ni->type].display) {
+ switch (_news_type_data[type].display) {
default: NOT_REACHED();
case ND_OFF: { // Off - show nothing only a small reminder in the status bar
Window *w = FindWindowById(WC_STATUS_BAR, 0);
diff --git a/src/news_type.h b/src/news_type.h
index cc25835c7..1f98d40c7 100644
--- a/src/news_type.h
+++ b/src/news_type.h
@@ -32,6 +32,31 @@ enum NewsType {
};
/**
+ * News subtypes.
+ */
+enum NewsSubtype {
+ NS_ARRIVAL_PLAYER, ///< NT_ARRIVAL_PLAYER
+ NS_ARRIVAL_OTHER, ///< NT_ARRIVAL_OTHER
+ NS_ACCIDENT_TILE, ///< NT_ACCIDENT (tile)
+ NS_ACCIDENT_VEHICLE, ///< NT_ACCIDENT (vehicle)
+ NS_COMPANY_TROUBLE, ///< NT_COMPANY_INFO (trouble)
+ NS_COMPANY_MERGER, ///< NT_COMPANY_INFO (merger)
+ NS_COMPANY_BANKRUPT, ///< NT_COMPANY_INFO (bankrupt)
+ NS_COMPANY_NEW, ///< NT_COMPANY_INFO (new company)
+ NS_OPENCLOSE, ///< NT_OPENCLOSE
+ NS_ECONOMY, ///< NT_ECONOMY
+ NS_INDUSTRY_PLAYER, ///< NT_INDUSTRY_PLAYER
+ NS_INDUSTRY_OTHER, ///< NT_INDUSTRY_OTHER
+ NS_INDUSTRY_NOBODY, ///< NT_INDUSTRY_NOBODY
+ NS_ADVICE, ///< NT_ADVICE
+ NS_NEW_VEHICLES, ///< NT_NEW_VEHICLES
+ NS_ACCEPTANCE, ///< NT_ACCEPTANCE
+ NS_SUBSIDIES, ///< NT_SUBSIDIES
+ NS_GENERAL, ///< NT_GENERAL
+ NS_END, ///< end-of-array marker
+};
+
+/**
* News mode.
*/
enum NewsMode {
@@ -100,10 +125,8 @@ struct NewsItem {
StringID string_id; ///< Message text
uint16 duration; ///< Remaining time for showing this news message
Date date; ///< Date of the news
+ NewsSubtype subtype; ///< News subtype @see NewsSubtype
NewsFlag flags; ///< NewsFlags bits @see NewsFlag
- NewsMode display_mode; ///< Display mode value @see NewsMode
- NewsType type; ///< News category @see NewsType
- NewsCallback callback; ///< Call-back function
uint data_a; ///< Custom data 1 (usually tile or vehicle)
uint data_b; ///< Custom data 2
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 36f804386..9d3cf3cab 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -1444,7 +1444,7 @@ void CheckOrders(const Vehicle* v)
SetDParam(0, v->unitnumber);
AddNewsItem(
message,
- NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE,
+ NS_ADVICE,
v->index,
0
);
diff --git a/src/players.cpp b/src/players.cpp
index 1026088ca..c51dacd06 100644
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -360,7 +360,7 @@ set_name:;
SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR);
SetDParam(2, p->index);
SetDParam(3, t->index);
- AddNewsItem(STR_02B6, NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY, p->last_build_coordinate, p->index | NB_BNEWCOMPANY);
+ AddNewsItem(STR_02B6, NS_COMPANY_NEW, p->last_build_coordinate, p->index | NB_BNEWCOMPANY);
}
return;
}
@@ -939,7 +939,7 @@ CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
SetDParam(0, STR_705C_BANKRUPT);
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY);
SetDParam(2, p->index);
- AddNewsItem(STR_02B6, NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, p->index | NB_BBANKRUPT);
+ AddNewsItem(STR_02B6, NS_COMPANY_BANKRUPT, 0, p->index | NB_BBANKRUPT);
/* Remove the company */
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index cf6d011db..5b8097080 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -664,7 +664,7 @@ static void RoadVehCrash(Vehicle *v)
AddNewsItem(
(pass == 1) ?
STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, DNC_NONE,
+ NS_ACCIDENT_VEHICLE,
v->index,
0
);
@@ -830,7 +830,7 @@ static void RoadVehArrivesAt(const Vehicle* v, Station* st)
SetDParam(0, st->index);
AddNewsItem(
v->u.road.roadtype == ROADTYPE_ROAD ? STR_902F_CITIZENS_CELEBRATE_FIRST : STR_CITIZENS_CELEBRATE_FIRST_PASSENGER_TRAM,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, (v->owner == _local_player) ? NT_ARRIVAL_PLAYER : NT_ARRIVAL_OTHER, DNC_NONE,
+ (v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
v->index,
0);
}
@@ -841,7 +841,7 @@ static void RoadVehArrivesAt(const Vehicle* v, Station* st)
SetDParam(0, st->index);
AddNewsItem(
v->u.road.roadtype == ROADTYPE_ROAD ? STR_9030_CITIZENS_CELEBRATE_FIRST : STR_CITIZENS_CELEBRATE_FIRST_CARGO_TRAM,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, (v->owner == _local_player) ? NT_ARRIVAL_PLAYER : NT_ARRIVAL_OTHER, DNC_NONE,
+ (v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
v->index,
0
);
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 31d76e17d..f1a7e9bc9 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -349,7 +349,7 @@ static void ShipArrivesAt(const Vehicle* v, Station* st)
SetDParam(0, st->index);
AddNewsItem(
STR_9833_CITIZENS_CELEBRATE_FIRST,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, (v->owner == _local_player) ? NT_ARRIVAL_PLAYER : NT_ARRIVAL_OTHER, DNC_NONE,
+ (v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
v->index,
0);
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index f97ac5d2b..eb7054ec3 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -409,7 +409,7 @@ static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *c
}
SetDParam(0, st->index);
- AddNewsItem(msg, NM_SMALL, NF_VIEWPORT | NF_TILE, NT_ACCEPTANCE, DNC_NONE, st->xy, 0);
+ AddNewsItem(msg, NS_ACCEPTANCE, st->xy, 0);
}
/**
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 1b65f3e8f..c0e5885d9 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2152,7 +2152,7 @@ static void TownActionRoadRebuild(Town *t)
SetDParam(1, _current_player);
AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING,
- NM_NORMAL, NF_TILE, NT_GENERAL, DNC_NONE, t->xy, 0);
+ NS_GENERAL, t->xy, 0);
}
static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id)
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index e788a16de..b377bfb5c 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2450,7 +2450,7 @@ static Track ChooseTrainTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir
SetDParam(0, v->unitnumber);
AddNewsItem(
STR_TRAIN_IS_LOST,
- NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE,
+ NS_ADVICE,
v->index,
0);
}
@@ -2647,7 +2647,7 @@ static void TrainEnterStation(Vehicle *v, StationID station)
SetDParam(0, st->index);
AddNewsItem(
STR_8801_CITIZENS_CELEBRATE_FIRST,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, v->owner == _local_player ? NT_ARRIVAL_PLAYER : NT_ARRIVAL_OTHER, DNC_NONE,
+ v->owner == _local_player ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
v->index,
0
);
@@ -2893,7 +2893,7 @@ static void CheckTrainCollision(Vehicle *v)
SetDParam(0, tcc.num);
AddNewsItem(STR_8868_TRAIN_CRASH_DIE_IN_FIREBALL,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, DNC_NONE,
+ NS_ACCIDENT_VEHICLE,
v->index,
0
);
@@ -3617,7 +3617,7 @@ void TrainsYearlyLoop()
SetDParam(0, v->unitnumber);
AddNewsItem(
STR_TRAIN_IS_UNPROFITABLE,
- NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE,
+ NS_ADVICE,
v->index,
0);
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 1ad06f503..93a6ef5b5 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -952,7 +952,7 @@ static void ShowVehicleGettingOld(Vehicle *v, StringID msg)
SetDParam(0, _vehicle_type_names[v->type]);
SetDParam(1, v->unitnumber);
- AddNewsItem(msg, NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE, v->index, 0);
+ AddNewsItem(msg, NS_ADVICE, v->index, 0);
}
void AgeVehicle(Vehicle *v)
@@ -1651,7 +1651,7 @@ void VehicleEnterDepot(Vehicle *v)
/* Notify the user that we stopped the vehicle */
SetDParam(0, _vehicle_type_names[v->type]);
SetDParam(1, v->unitnumber);
- AddNewsItem(STR_ORDER_REFIT_FAILED, NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE, v->index, 0);
+ AddNewsItem(STR_ORDER_REFIT_FAILED, NS_ADVICE, v->index, 0);
}
} else if (v->owner == _local_player && cost.GetCost() != 0) {
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost.GetCost());
@@ -1677,7 +1677,7 @@ void VehicleEnterDepot(Vehicle *v)
}
SetDParam(0, v->unitnumber);
- AddNewsItem(string, NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE, v->index, 0);
+ AddNewsItem(string, NS_ADVICE, v->index, 0);
}
}
}
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 5faee5264..43813b60b 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -861,7 +861,7 @@ static void FloodVehicle(Vehicle *v)
SetDParam(0, pass);
AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
- NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, DNC_NONE,
+ NS_ACCIDENT_VEHICLE,
v->index,
0);
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);