changeset 16489:7c956d217b83 draft

(svn r21214) -Add: Display mail capacity when refitting an aircraft to passengers.
author terkhen <terkhen@openttd.org>
date Tue, 16 Nov 2010 20:56:04 +0000
parents 35d5a17161bd
children 627c03dc907f
files src/lang/english.txt src/vehicle.cpp src/vehicle_cmd.cpp src/vehicle_func.h src/vehicle_gui.cpp
diffstat 5 files changed, 43 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -3125,6 +3125,7 @@
 STR_REFIT_CAPTION                                               :{WHITE}{VEHICLE} (Refit)
 STR_REFIT_TITLE                                                 :{GOLD}Select cargo type to carry:
 STR_REFIT_NEW_CAPACITY_COST_OF_REFIT                            :{BLACK}New capacity: {GOLD}{CARGO}{}{BLACK}Cost of refit: {GOLD}{CURRENCY}
+STR_REFIT_NEW_CAPACITY_COST_OF_AIRCRAFT_REFIT                   :{BLACK}New capacity: {GOLD}{CARGO}, {GOLD}{CARGO}{}{BLACK}Cost of refit: {GOLD}{CURRENCY}
 
 STR_REFIT_TRAIN_LIST_TOOLTIP                                    :{BLACK}Select type of cargo for train to carry
 STR_REFIT_ROAD_VEHICLE_LIST_TOOLTIP                             :{BLACK}Select type of cargo for road vehicle to carry
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -57,8 +57,9 @@
 
 VehicleID _vehicle_id_ctr_day;
 VehicleID _new_vehicle_id;
-uint16 _returned_refit_capacity;
-byte _age_cargo_skip_counter; ///< Skip aging of cargo?
+uint16 _returned_refit_capacity;      ///< Stores the capacity after a refit operation.
+uint16 _returned_mail_refit_capacity; ///< Stores the mail capacity after a refit operation (Aircraft only).
+byte _age_cargo_skip_counter;         ///< Skip aging of cargo?
 
 
 /* Initialize the vehicle-pool */
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -254,6 +254,7 @@
 {
 	CommandCost cost(v->GetExpenseType(false));
 	uint total_capacity = 0;
+	uint total_mail_capacity = 0;
 
 	v->InvalidateNewGRFCacheOfChain();
 	for (; v != NULL; v = (only_this ? NULL : v->Next())) {
@@ -266,9 +267,11 @@
 		v->cargo_type = new_cid;
 		v->cargo_subtype = new_subtype;
 
-		uint16 mail_capacity;
+		uint16 mail_capacity = 0;
 		uint amount = GetVehicleCapacity(v, &mail_capacity);
 		total_capacity += amount;
+		/* mail_capacity will always be zero if the vehicle is not an aircraft. */
+		total_mail_capacity += mail_capacity;
 
 		/* Restore the original cargo type */
 		v->cargo_type = temp_cid;
@@ -292,6 +295,7 @@
 	}
 
 	_returned_refit_capacity = total_capacity;
+	_returned_mail_refit_capacity = total_mail_capacity;
 	return cost;
 }
 
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -175,6 +175,7 @@
 extern VehicleID _vehicle_id_ctr_day;
 extern VehicleID _new_vehicle_id;
 extern uint16 _returned_refit_capacity;
+extern uint16 _returned_mail_refit_capacity;
 extern byte _age_cargo_skip_counter;
 
 bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -537,6 +537,33 @@
 		if (widget == VRW_CAPTION) SetDParam(0, Vehicle::Get(this->window_number)->index);
 	}
 
+	/**
+	 * Gets the #StringID to use for displaying capacity.
+	 * @param Cargo and cargo subtype to check for capacity.
+	 * @return INVALID_STRING_ID if there is no capacity. StringID to use in any other case.
+	 * @post String parameters have been set.
+	 */
+	StringID GetCapacityString(RefitOption *option) const
+	{
+		Vehicle *v = Vehicle::Get(this->window_number);
+		CommandCost cost = DoCommand(v->tile, v->index, option->cargo | option->subtype << 8, DC_QUERY_COST, GetCmdRefitVeh(v->type));
+
+		if (cost.Failed()) return INVALID_STRING_ID;
+
+		SetDParam(0, option->cargo);
+		SetDParam(1, _returned_refit_capacity);
+
+		if (_returned_mail_refit_capacity > 0) {
+			SetDParam(2, CT_MAIL);
+			SetDParam(3, _returned_mail_refit_capacity);
+			SetDParam(4, cost.GetCost());
+			return STR_REFIT_NEW_CAPACITY_COST_OF_AIRCRAFT_REFIT;
+		} else {
+			SetDParam(2, cost.GetCost());
+			return STR_REFIT_NEW_CAPACITY_COST_OF_REFIT;
+		}
+	}
+
 	virtual void DrawWidget(const Rect &r, int widget) const
 	{
 		switch (widget) {
@@ -546,14 +573,10 @@
 
 			case VRW_INFOPANEL:
 				if (this->cargo != NULL) {
-					Vehicle *v = Vehicle::Get(this->window_number);
-					CommandCost cost = DoCommand(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8, DC_QUERY_COST, GetCmdRefitVeh(v->type));
-					if (cost.Succeeded()) {
-						SetDParam(0, this->cargo->cargo);
-						SetDParam(1, _returned_refit_capacity);
-						SetDParam(2, cost.GetCost());
+					StringID string = this->GetCapacityString(this->cargo);
+					if (string != INVALID_STRING_ID) {
 						DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT,
-								r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, STR_REFIT_NEW_CAPACITY_COST_OF_REFIT);
+								r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, string);
 					}
 				}
 				break;
@@ -566,17 +589,13 @@
 			case 0: { // The consist lenght of the vehicle has changed; rebuild the entire list.
 				this->BuildRefitList();
 				uint max_width = 0;
-				Vehicle *v = Vehicle::Get(this->window_number);
 
 				/* Check the width of all cargo information strings. */
 				for (uint i = 0; i < NUM_CARGO; i++) {
 					for (uint j = 0; j < this->list[i].Length(); j++) {
-						CommandCost cost = DoCommand(v->tile, v->index, list[i][j].cargo | list[i][j].subtype << 8, DC_QUERY_COST, GetCmdRefitVeh(v->type));
-						if (cost.Succeeded()) {
-							SetDParam(0, list[i][j].cargo);
-							SetDParam(1, _returned_refit_capacity);
-							SetDParam(2, cost.GetCost());
-							Dimension dim = GetStringBoundingBox(STR_REFIT_NEW_CAPACITY_COST_OF_REFIT);
+						StringID string = this->GetCapacityString(&list[i][j]);
+						if (string != INVALID_STRING_ID) {
+							Dimension dim = GetStringBoundingBox(string);
 							max_width = max(dim.width, max_width);
 						}
 					}