summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-10-23 21:39:15 +0000
committerpeter1138 <peter1138@openttd.org>2006-10-23 21:39:15 +0000
commit735c636f6ffdec71797b2685a8f19b4e81cbdb0d (patch)
tree75eaf1df54a52006319c0408f2bef1d5159a3197
parent552e6de4ceca495b292cf7d068c5d18c8d6489d6 (diff)
downloadopenttd-735c636f6ffdec71797b2685a8f19b4e81cbdb0d.tar.xz
(svn r6912) - Feature: Show a list of cargo types that a vehicle is refittable to in the purchase information window. (mart3p)
-rw-r--r--build_vehicle_gui.c1
-rw-r--r--lang/english.txt3
-rw-r--r--roadveh_gui.c1
-rw-r--r--ship_gui.c1
-rw-r--r--train_gui.c2
-rw-r--r--vehicle_gui.c51
-rw-r--r--vehicle_gui.h3
7 files changed, 60 insertions, 2 deletions
diff --git a/build_vehicle_gui.c b/build_vehicle_gui.c
index 1708a5c5d..11caed6e3 100644
--- a/build_vehicle_gui.c
+++ b/build_vehicle_gui.c
@@ -256,6 +256,7 @@ void DrawAircraftPurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
+ y += ShowRefitOptionsList(x, y, w, engine_number);
}
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
diff --git a/lang/english.txt b/lang/english.txt
index 383e3c213..cb8826eec 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -3021,6 +3021,9 @@ STR_PURCHASE_INFO_WEIGHT_CWEIGHT :{BLACK}Weight:
STR_PURCHASE_INFO_COST_SPEED :{BLACK}Cost: {GOLD}{CURRENCY}{BLACK} Speed: {GOLD}{VELOCITY}
STR_PURCHASE_INFO_AIRCRAFT_CAPACITY :{BLACK}Capacity: {GOLD}{COMMA} passengers, {COMMA} bags of mail
STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT :{BLACK}Powered Wagons: {GOLD}+{POWER}{BLACK} Weight: {GOLD}+{WEIGHT_S}
+STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Refittable to: {GOLD}
+STR_PURCHASE_INFO_ALL_TYPES :All cargo types
+STR_PURCHASE_INFO_ALL_BUT :All but {GOLD}
########### String for New Landscape Generator
diff --git a/roadveh_gui.c b/roadveh_gui.c
index ba0657960..5a25fbab7 100644
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -66,6 +66,7 @@ void DrawRoadVehPurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
+ y += ShowRefitOptionsList(x, y, w, engine_number);
}
void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
diff --git a/ship_gui.c b/ship_gui.c
index 9b10ff3d4..0a501c789 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -66,6 +66,7 @@ void DrawShipPurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
+ if (svi->refittable) y += ShowRefitOptionsList(x, y, w, engine_number);
}
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
diff --git a/train_gui.c b/train_gui.c
index 1ae25c329..3b36d82dd 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -293,6 +293,7 @@ void DrawTrainEnginePurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
+ y += ShowRefitOptionsList(x, y, w, engine_number);
}
/**
@@ -337,6 +338,7 @@ void DrawTrainWagonPurchaseInfo(int x, int y, uint w, EngineID engine_number)
/* Additional text from NewGRF */
y += ShowAdditionalText(x, y, w, engine_number);
+ y += ShowRefitOptionsList(x, y, w, engine_number);
}
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 2f74ab2b7..5c9888134 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -482,7 +482,7 @@ void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order)
}
/* Display additional text from NewGRF in the purchase information window */
-uint ShowAdditionalText(int x, int y, int w, EngineID engine)
+uint ShowAdditionalText(int x, int y, uint w, EngineID engine)
{
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, NULL);
if (callback == CALLBACK_FAILED) return 0;
@@ -492,6 +492,55 @@ uint ShowAdditionalText(int x, int y, int w, EngineID engine)
return DrawStringMultiLine(x, y, STR_02BD, w);
}
+/* Count the number of bits that are set in a mask */
+static uint CountBits(uint32 mask)
+{
+ uint c = 0;
+ for (; mask != 0; mask >>= 1) if (HASBIT(mask, 0)) c++;
+ return c;
+}
+
+/* Display list of cargo types of the engine, for the purchase information window */
+uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine)
+{
+ /* List of cargo types of this engine */
+ uint32 cmask = EngInfo(engine)->refit_mask;
+ /* List of cargo types available in this climate */
+ uint32 lmask = _landscape_global_cargo_mask[_opt.landscape];
+ char *b = _userstring;
+
+ /* Draw nothing if the engine is not refittable */
+ if (CountBits(cmask) <= 1) return 0;
+
+ b = InlineString(b, STR_PURCHASE_INFO_REFITTABLE_TO);
+
+ if (cmask == lmask) {
+ /* Engine can be refitted to all types in this climate */
+ b = InlineString(b, STR_PURCHASE_INFO_ALL_TYPES);
+ } else {
+ CargoID cid;
+
+ /* Check if we are able to refit to more cargo types and unable to. If
+ * so, invert the cargo types to list those that we can't refit to. */
+ if (CountBits(cmask ^ lmask) < CountBits(cmask)) {
+ cmask ^= lmask;
+ b = InlineString(b, STR_PURCHASE_INFO_ALL_BUT);
+ }
+
+ /* Add each cargo type to the list */
+ for (cid = 0; cmask != 0; cmask >>= 1, cid++) {
+ if (!HASBIT(cmask, 0)) continue;
+
+ b = InlineString(b, _cargoc.names_s[_local_cargo_id_ctype[cid]]);
+ if (cmask > 1) b = strecpy(b, ", ", lastof(_userstring));
+ }
+ }
+
+ /* Terminate and display the completed string */
+ *b = '\0';
+ return DrawStringMultiLine(x, y, STR_SPEC_USERSTRING, w);
+}
+
// if the sorting criteria had the same value, sort vehicle by unitnumber
#define VEHICLEUNITNUMBERSORTER(r, a, b) {if (r == 0) {r = a->unitnumber - b->unitnumber;}}
diff --git a/vehicle_gui.h b/vehicle_gui.h
index 7cc25ae3c..76f6a5bcc 100644
--- a/vehicle_gui.h
+++ b/vehicle_gui.h
@@ -50,7 +50,8 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type);
void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v);
-uint ShowAdditionalText(int x, int y, int w, EngineID engine);
+uint ShowAdditionalText(int x, int y, uint w, EngineID engine);
+uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine);
void ShowVehicleListWindow(PlayerID player, StationID station, byte vehicle_type);
void ShowVehWithSharedOrders(Vehicle *v, byte vehicle_type);