summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-03-03 22:03:15 +0000
committerrubidium <rubidium@openttd.org>2007-03-03 22:03:15 +0000
commit35fde14a527e0381769d08422513e6746704e1fc (patch)
tree419b44d6e3973f9233c668259ab6c7a64273f449 /src
parentcf47f2a856d3365cd42eaa4b5e9f5e2095586172 (diff)
downloadopenttd-35fde14a527e0381769d08422513e6746704e1fc.tar.xz
(svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp9
-rw-r--r--src/engine_gui.cpp158
-rw-r--r--src/lang/english.txt14
-rw-r--r--src/news.h7
-rw-r--r--src/news_gui.cpp20
5 files changed, 48 insertions, 160 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 69f0136ae..3047fa40e 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -317,15 +317,8 @@ static void NewVehicleAvailable(Engine *e)
FOR_ALL_PLAYERS(p) {
if (p->is_active) SETBIT(p->avail_railtypes, railtype);
}
-
- AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0);
- } else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) {
- AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0);
- } else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) {
- AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0);
- } else {
- AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0);
}
+ AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_VEHICLEAVAIL), 0, 0);
}
void EnginesMonthlyLoop(void)
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 0975cc3d1..c63515826 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -20,23 +20,20 @@
static StringID GetEngineCategoryName(EngineID engine)
{
- if (engine < NUM_TRAIN_ENGINES) {
- switch (RailVehInfo(engine)->railtype) {
- case RAILTYPE_RAIL: return STR_8102_RAILROAD_LOCOMOTIVE;
- case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE;
- case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE;
- case RAILTYPE_MAGLEV: return STR_8107_MAGLEV_LOCOMOTIVE;
- default: NOT_REACHED();
- }
+ switch (GetEngine(engine)->type) {
+ default: NOT_REACHED();
+ case VEH_Road: return STR_8103_ROAD_VEHICLE;
+ case VEH_Aircraft: return STR_8104_AIRCRAFT;
+ case VEH_Ship: return STR_8105_SHIP;
+ case VEH_Train:
+ switch (RailVehInfo(engine)->railtype) {
+ default: NOT_REACHED();
+ case RAILTYPE_RAIL: return STR_8102_RAILROAD_LOCOMOTIVE;
+ case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE;
+ case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE;
+ case RAILTYPE_MAGLEV: return STR_8107_MAGLEV_LOCOMOTIVE;
+ }
}
-
- if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES)
- return STR_8103_ROAD_VEHICLE;
-
- if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES)
- return STR_8105_SHIP;
-
- return STR_8104_AIRCRAFT;
}
static const Widget _engine_preview_widgets[] = {
@@ -62,10 +59,10 @@ static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw);
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw);
static const DrawEngineInfo _draw_engine_list[4] = {
- {DrawTrainEngine,DrawTrainEngineInfo},
- {DrawRoadVehEngine,DrawRoadVehEngineInfo},
- {DrawShipEngine,DrawShipEngineInfo},
- {DrawAircraftEngine,DrawAircraftEngineInfo},
+ { DrawTrainEngine, DrawTrainEngineInfo },
+ { DrawRoadVehEngine, DrawRoadVehEngineInfo },
+ { DrawShipEngine, DrawShipEngineInfo },
+ { DrawAircraftEngine, DrawAircraftEngineInfo },
};
static void EnginePreviewWndProc(Window *w, WindowEvent *e)
@@ -83,10 +80,7 @@ static void EnginePreviewWndProc(Window *w, WindowEvent *e)
DrawStringCentered(w->width >> 1, 80, GetCustomEngineName(engine), 0x10);
- (dei = _draw_engine_list,engine < NUM_TRAIN_ENGINES) ||
- (dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) ||
- (dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) ||
- (dei++, true);
+ dei = &_draw_engine_list[GetEngine(engine)->type];
width = w->width;
dei->engine_proc(width >> 1, 100, engine, 0);
@@ -142,35 +136,6 @@ static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
DrawStringMultiCenter(x, y, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, maxw);
}
-void DrawNewsNewTrainAvail(Window *w)
-{
- EngineID engine;
-
- DrawNewsBorder(w);
-
- engine = WP(w,news_d).ni->string_id;
- SetDParam(0, GetEngineCategoryName(engine));
- DrawStringMultiCenter(w->width >> 1, 20, STR_8859_NEW_NOW_AVAILABLE, w->width - 2);
-
- GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
-
- SetDParam(0, GetCustomEngineName(engine));
- DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2);
-
- DrawTrainEngine(w->width >> 1, 88, engine, 0);
- GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
- DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52);
-}
-
-StringID GetNewsStringNewTrainAvail(const NewsItem *ni)
-{
- EngineID engine = ni->string_id;
- SetDParam(0, STR_8859_NEW_NOW_AVAILABLE);
- SetDParam(1, GetEngineCategoryName(engine));
- SetDParam(2, GetCustomEngineName(engine));
- return STR_02B6;
-}
-
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
{
const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
@@ -183,33 +148,6 @@ static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
}
-void DrawNewsNewAircraftAvail(Window *w)
-{
- EngineID engine;
-
- DrawNewsBorder(w);
-
- engine = WP(w,news_d).ni->string_id;
-
- DrawStringMultiCenter(w->width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, w->width - 2);
- GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
-
- SetDParam(0, GetCustomEngineName(engine));
- DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2);
-
- DrawAircraftEngine(w->width >> 1, 93, engine, 0);
- GfxFillRect(25, 56, w->width - 56, 110, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
- DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52);
-}
-
-StringID GetNewsStringNewAircraftAvail(const NewsItem *ni)
-{
- EngineID engine = ni->string_id;
- SetDParam(0, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE);
- SetDParam(2, GetCustomEngineName(engine));
- return STR_02B6;
-}
-
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
{
const RoadVehicleInfo *rvi = RoadVehInfo(engine);
@@ -223,32 +161,6 @@ static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
}
-void DrawNewsNewRoadVehAvail(Window *w)
-{
- EngineID engine;
-
- DrawNewsBorder(w);
-
- engine = WP(w,news_d).ni->string_id;
- DrawStringMultiCenter(w->width >> 1, 20, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE, w->width - 2);
- GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
-
- SetDParam(0, GetCustomEngineName(engine));
- DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2);
-
- DrawRoadVehEngine(w->width >> 1, 88, engine, 0);
- GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
- DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52);
-}
-
-StringID GetNewsStringNewRoadVehAvail(const NewsItem *ni)
-{
- EngineID engine = ni->string_id;
- SetDParam(0, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE);
- SetDParam(2, GetCustomEngineName(engine));
- return STR_02B6;
-}
-
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
{
const ShipVehicleInfo *svi = ShipVehInfo(engine);
@@ -260,29 +172,31 @@ static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
}
-void DrawNewsNewShipAvail(Window *w)
+
+StringID GetNewsStringNewVehicleAvail(const NewsItem *ni)
{
- EngineID engine;
+ EngineID engine = ni->string_id;
+ SetDParam(0, GetEngineCategoryName(engine));
+ SetDParam(1, GetCustomEngineName(engine));
+ return STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE;
+}
+void DrawNewsNewVehicleAvail(Window *w)
+{
DrawNewsBorder(w);
- engine = WP(w,news_d).ni->string_id;
+ EngineID engine = WP(w, news_d).ni->string_id;
+ const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
+
+ SetDParam(0, GetEngineCategoryName(engine));
+ DrawStringMultiCenter(w->width >> 1, 20, STR_NEW_VEHICLE_NOW_AVAILABLE, w->width - 2);
- DrawStringMultiCenter(w->width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, w->width - 2);
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
SetDParam(0, GetCustomEngineName(engine));
- DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2);
-
- DrawShipEngine(w->width >> 1, 93, engine, 0);
- GfxFillRect(25, 56, w->width - 56, 110, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
- DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52);
-}
+ DrawStringMultiCenter(w->width >> 1, 57, STR_NEW_VEHICLE_TYPE, w->width - 2);
-StringID GetNewsStringNewShipAvail(const NewsItem *ni)
-{
- EngineID engine = ni->string_id;
- SetDParam(0, STR_982C_NEW_SHIP_NOW_AVAILABLE);
- SetDParam(2, GetCustomEngineName(engine));
- return STR_02B6;
+ dei->engine_proc(w->width >> 1, 88, engine, 0);
+ GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
+ dei->info_proc(engine, w->width >> 1, 129, w->width - 52);
}
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 8e02aa7fa..02adffc4c 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -752,7 +752,7 @@ STR_02A3_LARGE :{BLACK}Large
STR_02A4_SELECT_TOWN_SIZE :{BLACK}Select town size
STR_02A5_TOWN_SIZE :{YELLOW}Town size:
-STR_02B6 :{STRING1} - {STRING5}
+STR_02B6 :{STRING} - {STRING5}
STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS :{BLACK}Show last message or news report
STR_OFF :Off
STR_SUMMARY :Summary
@@ -2606,8 +2606,6 @@ STR_8856_INSERT_A_NEW_ORDER_BEFORE :{BLACK}Insert a
STR_8857_MAKE_THE_HIGHLIGHTED_ORDER :{BLACK}Make the highlighted order force the vehicle to wait for a full load
STR_8858_MAKE_THE_HIGHLIGHTED_ORDER :{BLACK}Make the highlighted order force the vehicle to unload
STR_SERVICE_HINT :{BLACK}Skip this order unless a service is needed
-STR_8859_NEW_NOW_AVAILABLE :{BLACK}{BIGFONT}New {STRING} now available!
-STR_885A :{BLACK}{BIGFONT}{STRING}
STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER :{BLACK}Cost: {CURRENCY} Weight: {WEIGHT_S}{}Speed: {VELOCITY} Power: {POWER}{}Running Cost: {CURRENCY}/yr{}Capacity: {CARGO}
STR_885C_BROKEN_DOWN :{RED}Broken down
STR_885D_AGE_RUNNING_COST_YR :{BLACK}Age: {LTBLUE}{STRING2}{BLACK} Running Cost: {LTBLUE}{CURRENCY}/yr
@@ -2635,6 +2633,10 @@ STR_INCOMPATIBLE_RAIL_TYPES :Incompatible ra
STR_TRAIN_NO_POWER :{RED}No power
STR_TRAIN_START_NO_CATENARY :This track lacks catenary, so the train can't start
+STR_NEW_VEHICLE_NOW_AVAILABLE :{BLACK}{BIGFONT}New {STRING} now available!
+STR_NEW_VEHICLE_TYPE :{BLACK}{BIGFONT}{STRING}
+STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE :{BLACK}New {STRING} now available! - {STRING}
+
##id 0x9000
STR_9000_ROAD_VEHICLE_IN_THE_WAY :{WHITE}Road vehicle in the way
STR_9001_ROAD_VEHICLES :{WHITE}{COMPANY} - {COMMA} Road Vehicle{P "" s}
@@ -2675,8 +2677,6 @@ STR_9024_DRAG_ROAD_VEHICLE_TO_HERE :{BLACK}Drag roa
STR_9025_CENTER_MAIN_VIEW_ON_ROAD :{BLACK}Centre main view on road vehicle depot location
STR_9026_ROAD_VEHICLE_SELECTION :{BLACK}Road vehicle selection list - click on vehicle for information
STR_9027_BUILD_THE_HIGHLIGHTED_ROAD :{BLACK}Build the highlighted road vehicle
-STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE :{BLACK}{BIGFONT}New road vehicle now available!
-STR_9029 :{BLACK}{BIGFONT}{STRING}
STR_902A_COST_SPEED_RUNNING_COST :{BLACK}Cost: {CURRENCY}{}Speed: {VELOCITY}{}Running Cost: {CURRENCY}/yr{}Capacity: {CARGO}
STR_902C_NAME_ROAD_VEHICLE :{WHITE}Name road vehicle
@@ -2748,8 +2748,6 @@ STR_9828_SHOW_SHIP_S_ORDERS :{BLACK}Show shi
STR_9829_CENTER_MAIN_VIEW_ON_SHIP :{BLACK}Centre main view on ship's location
STR_982A_SEND_SHIP_TO_DEPOT :{BLACK}Send ship to depot. CTRL+click will only service
STR_982B_SHOW_SHIP_DETAILS :{BLACK}Show ship details
-STR_982C_NEW_SHIP_NOW_AVAILABLE :{BLACK}{BIGFONT}New ship now available!
-STR_982D :{BLACK}{BIGFONT}{STRING}
STR_982E_COST_MAX_SPEED_CAPACITY :{BLACK}Cost: {CURRENCY} Max. Speed: {VELOCITY}{}Capacity: {CARGO}{}Running Cost: {CURRENCY}/yr
STR_982F_NAME_SHIP :{BLACK}Name ship
@@ -2822,8 +2820,6 @@ STR_A028_SHOW_AIRCRAFT_S_ORDERS :{BLACK}Show air
STR_A029_CENTER_MAIN_VIEW_ON_AIRCRAFT :{BLACK}Centre main view on aircraft's location
STR_A02A_SEND_AIRCRAFT_TO_HANGAR :{BLACK}Send aircraft to hangar. CTRL+click will only service
STR_A02B_SHOW_AIRCRAFT_DETAILS :{BLACK}Show aircraft details
-STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE :{BLACK}{BIGFONT}New aircraft now available!
-STR_A02D :{BLACK}{BIGFONT}{STRING}
STR_A02E_COST_MAX_SPEED_CAPACITY :{BLACK}Cost: {CURRENCY} Max. Speed: {VELOCITY}{}Capacity: {COMMA} passengers, {COMMA} bags of mail{}Running Cost: {CURRENCY}/yr
STR_A030_NAME_AIRCRAFT :{WHITE}Name aircraft
diff --git a/src/news.h b/src/news.h
index 72f7e842a..8ebf46a33 100644
--- a/src/news.h
+++ b/src/news.h
@@ -59,11 +59,8 @@ enum NewsFlags {
};
enum NewsCallback {
- DNC_TRAINAVAIL = 0, ///< Show new train available message. StringID is EngineID
- DNC_ROADAVAIL = 1, ///< Show new road vehicle available message. StringID is EngineID
- DNC_SHIPAVAIL = 2, ///< Show new ship available message. StringID is EngineID
- DNC_AIRCRAFTAVAIL = 3, ///< Show new aircraft available message. StringID is EngineID
- DNC_BANKRUPCY = 4, ///< Show bankrupcy message. StringID is PlayerID (0-3) and NewsBankrupcy (4-7)
+ DNC_VEHICLEAVAIL = 0, ///< Show new vehicle available message. StringID is EngineID
+ DNC_BANKRUPCY = 1, ///< Show bankrupcy message. StringID is PlayerID (0-3) and NewsBankrupcy (4-7)
};
enum NewsBankrupcy {
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index fce196197..2aa944f88 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -53,33 +53,21 @@ static NewsID _forced_news = INVALID_NEWS;
static byte _total_news = 0; // total news count
-void DrawNewsNewTrainAvail(Window *w);
-void DrawNewsNewRoadVehAvail(Window *w);
-void DrawNewsNewShipAvail(Window *w);
-void DrawNewsNewAircraftAvail(Window *w);
+void DrawNewsNewVehicleAvail(Window *w);
void DrawNewsBankrupcy(Window *w);
static void MoveToNextItem(void);
-StringID GetNewsStringNewTrainAvail(const NewsItem *ni);
-StringID GetNewsStringNewRoadVehAvail(const NewsItem *ni);
-StringID GetNewsStringNewShipAvail(const NewsItem *ni);
-StringID GetNewsStringNewAircraftAvail(const NewsItem *ni);
+StringID GetNewsStringNewVehicleAvail(const NewsItem *ni);
StringID GetNewsStringBankrupcy(const NewsItem *ni);
static DrawNewsCallbackProc * const _draw_news_callback[] = {
- DrawNewsNewTrainAvail, /* DNC_TRAINAVAIL */
- DrawNewsNewRoadVehAvail, /* DNC_ROADAVAIL */
- DrawNewsNewShipAvail, /* DNC_SHIPAVAIL */
- DrawNewsNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */
+ DrawNewsNewVehicleAvail, /* DNC_VEHICLEAVAIL */
DrawNewsBankrupcy, /* DNC_BANKRUPCY */
};
extern GetNewsStringCallbackProc * const _get_news_string_callback[];
GetNewsStringCallbackProc * const _get_news_string_callback[] = {
- GetNewsStringNewTrainAvail, /* DNC_TRAINAVAIL */
- GetNewsStringNewRoadVehAvail, /* DNC_ROADAVAIL */
- GetNewsStringNewShipAvail, /* DNC_SHIPAVAIL */
- GetNewsStringNewAircraftAvail, /* DNC_AIRCRAFTAVAIL */
+ GetNewsStringNewVehicleAvail, /* DNC_VEHICLEAVAIL */
GetNewsStringBankrupcy, /* DNC_BANKRUPCY */
};