Mercurial > hg > openttd
changeset 9199:dbe675dc54c4 draft
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Tue, 13 May 2008 10:17:04 +0000 |
parents | a9bfd7e37e3f |
children | 6de115102b95 |
files | src/economy.cpp src/engine.cpp src/engine_gui.cpp src/news_gui.cpp src/news_type.h src/players.cpp src/statusbar_gui.cpp |
diffstat | 7 files changed, 51 insertions(+), 93 deletions(-) [+] |
line wrap: on
line diff
--- a/src/economy.cpp +++ b/src/economy.cpp @@ -527,15 +527,21 @@ 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 @@ 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ } } -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 @@ 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;
--- a/src/engine.cpp +++ b/src/engine.cpp @@ -367,6 +367,8 @@ 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 @@ 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()
--- 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 @@ 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));
--- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -78,20 +78,11 @@ 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 @@ 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
--- a/src/news_type.h +++ b/src/news_type.h @@ -97,7 +97,7 @@ }; 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 @@ 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 */
--- a/src/players.cpp +++ b/src/players.cpp @@ -356,8 +356,11 @@ 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 @@ 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);
--- 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));