summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-05-13 10:17:04 +0000
committerrubidium <rubidium@openttd.org>2008-05-13 10:17:04 +0000
commit5d7851e8d63766b15881bafd4940bf89f37b2bdc (patch)
tree5c7ccb204d4278fc86a352be079b38923bb69dab
parenta3d037956f4f1dcde98c30cd8b30f3c9cc626a1b (diff)
downloadopenttd-5d7851e8d63766b15881bafd4940bf89f37b2bdc.tar.xz
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
-rw-r--r--src/economy.cpp76
-rw-r--r--src/engine.cpp7
-rw-r--r--src/engine_gui.cpp13
-rw-r--r--src/news_gui.cpp17
-rw-r--r--src/news_type.h7
-rw-r--r--src/players.cpp13
-rw-r--r--src/statusbar_gui.cpp11
7 files changed, 51 insertions, 93 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index f8ed5d4e2..c2f321f17 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -527,15 +527,21 @@ static void PlayersCheckBankrupt(Player *p)
switch (p->quarters_of_bankrupcy) {
case 2:
- AddNewsItem((StringID)(owner | NB_BTROUBLE),
- NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, 0);
+ SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE);
+ 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);
break;
case 3: {
/* XXX - In multiplayer, should we ask other players if it wants to take
over when it is a human company? -- TrueLight */
if (IsHumanPlayer(owner)) {
- AddNewsItem((StringID)(owner | NB_BTROUBLE),
- NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, 0);
+ SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE);
+ 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);
break;
}
@@ -555,8 +561,10 @@ static void PlayersCheckBankrupt(Player *p)
DeletePlayerWindows(owner);
/* Show bankrupt news */
- SetDParam(0, p->index);
- AddNewsItem((StringID)(owner | NB_BBANKRUPT), NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, 0);
+ 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);
if (IsHumanPlayer(owner)) {
/* XXX - If we are in offline mode, leave the player playing. Eg. there
@@ -586,7 +594,7 @@ void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
{
DrawNewsBorder(w);
- Player *p = GetPlayer((PlayerID)GB(ni->string_id, 0, 4));
+ Player *p = GetPlayer((PlayerID)GB(ni->data_b, 0, 4));
DrawPlayerFace(p->face, p->player_color, 2, 23);
GfxFillRect(3, 23, 3 + 91, 23 + 118, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
@@ -594,7 +602,7 @@ void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
DrawStringMultiCenter(49, 148, STR_7058_PRESIDENT, 94);
- switch (ni->string_id & 0xF0) {
+ switch (ni->data_b & 0xF0) {
case NB_BTROUBLE:
DrawStringCentered(w->width >> 1, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, TC_FROMSTRING);
@@ -609,19 +617,19 @@ void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
case NB_BMERGER:
DrawStringCentered(w->width >> 1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, TC_FROMSTRING);
- SetDParam(0, ni->params[0]);
+ SetDParam(0, ni->params[2]);
SetDParam(1, p->index);
- SetDParam(2, ni->params[1]);
+ SetDParam(2, ni->params[4]);
DrawStringMultiCenter(
((w->width - 101) >> 1) + 98,
90,
- ni->params[1] == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR,
+ ni->params[4] == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR,
w->width - 101);
break;
case NB_BBANKRUPT:
DrawStringCentered(w->width >> 1, 1, STR_705C_BANKRUPT, TC_FROMSTRING);
- SetDParam(0, ni->params[0]);
+ SetDParam(0, p->index);
DrawStringMultiCenter(
((w->width - 101) >> 1) + 98,
90,
@@ -632,7 +640,7 @@ void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
case NB_BNEWCOMPANY:
DrawStringCentered(w->width >> 1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, TC_FROMSTRING);
SetDParam(0, p->index);
- SetDParam(1, ni->params[0]);
+ SetDParam(1, ni->params[3]);
DrawStringMultiCenter(
((w->width - 101) >> 1) + 98,
90,
@@ -645,39 +653,6 @@ void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
}
}
-StringID GetNewsStringBankrupcy(const NewsItem *ni)
-{
- const Player *p = GetPlayer((PlayerID)GB(ni->string_id, 0, 4));
-
- switch (ni->string_id & 0xF0) {
- case NB_BTROUBLE:
- SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE);
- SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED);
- SetDParam(2, p->index);
- return STR_02B6;
- case NB_BMERGER:
- SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER);
- SetDParam(1, ni->params[1] == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR);
- SetDParam(2, ni->params[0]);
- SetDParam(3, p->index);
- SetDParam(4, ni->params[1]);
- return STR_02B6;
- case NB_BBANKRUPT:
- SetDParam(0, STR_705C_BANKRUPT);
- SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY);
- SetDParam(2, ni->params[0]);
- return STR_02B6;
- case NB_BNEWCOMPANY:
- SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED);
- SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR);
- SetDParam(2, p->index);
- SetDParam(3, ni->params[0]);
- return STR_02B6;
- default:
- NOT_REACHED();
- }
-}
-
static void PlayersGenStatistics()
{
Station *st;
@@ -1842,9 +1817,12 @@ static void DoAcquireCompany(Player *p)
int i;
Money value;
- SetDParam(0, p->index);
- SetDParam(1, p->bankrupt_value);
- AddNewsItem((StringID)(_current_player | NB_BMERGER), NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, 0);
+ SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER);
+ SetDParam(1, p->bankrupt_value == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR);
+ 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);
/* original code does this a little bit differently */
PlayerID pi = p->index;
diff --git a/src/engine.cpp b/src/engine.cpp
index c28b096cb..ac50f811b 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -367,6 +367,8 @@ static bool IsWagon(EngineID index)
return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON;
}
+StringID GetEngineCategoryName(EngineID engine);
+
static void NewVehicleAvailable(Engine *e)
{
Vehicle *v;
@@ -419,7 +421,10 @@ static void NewVehicleAvailable(Engine *e)
if (p->is_active) SetBit(p->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
}
}
- AddNewsItem(index, NM_CALLBACK, NF_NONE, NT_NEW_VEHICLES, DNC_VEHICLEAVAIL, 0, 0);
+
+ 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);
}
void EnginesMonthlyLoop()
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 819921587..9b24ba533 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -19,7 +19,7 @@
#include "table/strings.h"
#include "table/sprites.h"
-static StringID GetEngineCategoryName(EngineID engine)
+StringID GetEngineCategoryName(EngineID engine)
{
switch (GetEngine(engine)->type) {
default: NOT_REACHED();
@@ -174,20 +174,11 @@ static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
}
-
-StringID GetNewsStringNewVehicleAvail(const NewsItem *ni)
-{
- EngineID engine = ni->string_id;
- SetDParam(0, GetEngineCategoryName(engine));
- SetDParam(1, engine);
- return STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE;
-}
-
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
{
DrawNewsBorder(w);
- EngineID engine = ni->string_id;
+ EngineID engine = ni->data_a;
const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
SetDParam(0, GetEngineCategoryName(engine));
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 7a9ecb289..509d058b9 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -78,20 +78,11 @@ void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni);
void DrawNewsBankrupcy(Window *w, const NewsItem *ni);
static void MoveToNextItem();
-StringID GetNewsStringNewVehicleAvail(const NewsItem *ni);
-StringID GetNewsStringBankrupcy(const NewsItem *ni);
-
static DrawNewsCallbackProc * const _draw_news_callback[] = {
DrawNewsNewVehicleAvail, ///< DNC_VEHICLEAVAIL
DrawNewsBankrupcy, ///< DNC_BANKRUPCY
};
-extern GetNewsStringCallbackProc * const _get_news_string_callback[];
-GetNewsStringCallbackProc * const _get_news_string_callback[] = {
- GetNewsStringNewVehicleAvail, ///< DNC_VEHICLEAVAIL
- GetNewsStringBankrupcy, ///< DNC_BANKRUPCY
-};
-
/** Initialize the news-items data structures */
void InitNewsItemStructs()
{
@@ -607,12 +598,8 @@ static void DrawNewsString(int x, int y, uint16 color, const NewsItem *ni, uint
char buffer[512], buffer2[512];
StringID str;
- if (ni->display_mode == NM_CALLBACK) {
- str = _get_news_string_callback[ni->callback](ni);
- } else {
- CopyInDParam(0, ni->params, lengthof(ni->params));
- str = ni->string_id;
- }
+ CopyInDParam(0, ni->params, lengthof(ni->params));
+ str = ni->string_id;
GetString(buffer, str, lastof(buffer));
/* Copy the just gotten string to another buffer to remove any formatting
diff --git a/src/news_type.h b/src/news_type.h
index aa220a83f..cc25835c7 100644
--- a/src/news_type.h
+++ b/src/news_type.h
@@ -97,7 +97,7 @@ struct NewsTypeData {
};
struct NewsItem {
- StringID string_id; ///< Message text (sometimes also used for storing other info)
+ StringID string_id; ///< Message text
uint16 duration; ///< Remaining time for showing this news message
Date date; ///< Date of the news
NewsFlag flags; ///< NewsFlags bits @see NewsFlag
@@ -105,14 +105,13 @@ struct NewsItem {
NewsType type; ///< News category @see NewsType
NewsCallback callback; ///< Call-back function
- uint data_a; ///< Reference to tile or vehicle
- uint data_b; ///< Reference to second tile or vehicle
+ uint data_a; ///< Custom data 1 (usually tile or vehicle)
+ uint data_b; ///< Custom data 2
uint64 params[10];
};
typedef bool ValidationProc(uint data_a, uint data_b);
typedef void DrawNewsCallbackProc(Window *w, const NewsItem *ni);
-typedef StringID GetNewsStringCallbackProc(const NewsItem *ni);
#endif /* NEWS_TYPE_H */
diff --git a/src/players.cpp b/src/players.cpp
index 4a297936c..1026088ca 100644
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -356,8 +356,11 @@ set_name:;
MarkWholeScreenDirty();
if (!IsHumanPlayer(p->index)) {
- SetDParam(0, t->index);
- AddNewsItem((StringID)(p->index | NB_BNEWCOMPANY), NM_CALLBACK, NF_TILE, NT_COMPANY_INFO, DNC_BANKRUPCY, p->last_build_coordinate, 0);
+ SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED);
+ 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);
}
return;
}
@@ -933,8 +936,10 @@ CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
DeletePlayerWindows(p->index);
/* Show the bankrupt news */
- SetDParam(0, p->index);
- AddNewsItem((StringID)(p->index | NB_BBANKRUPT), NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, 0);
+ 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);
/* Remove the company */
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp
index 61fd57df0..535636e4c 100644
--- a/src/statusbar_gui.cpp
+++ b/src/statusbar_gui.cpp
@@ -22,17 +22,10 @@
#include "table/strings.h"
#include "table/sprites.h"
-extern GetNewsStringCallbackProc * const _get_news_string_callback[];
-
static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width)
{
- StringID str;
- if (ni->display_mode == NM_CALLBACK) {
- str = _get_news_string_callback[ni->callback](ni);
- } else {
- CopyInDParam(0, ni->params, lengthof(ni->params));
- str = ni->string_id;
- }
+ CopyInDParam(0, ni->params, lengthof(ni->params));
+ StringID str = ni->string_id;
char buf[512];
GetString(buf, str, lastof(buf));