summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-11-16 20:56:04 +0000
committerterkhen <terkhen@openttd.org>2010-11-16 20:56:04 +0000
commitc96cb9ce3757f90384f8cd624eb3f2878db477ff (patch)
tree9f41f296f8683d04a70230d0c8f06323443bc56d /src
parent07ad8851ccd6d1f47a379fe9e19eb257048a9fdf (diff)
downloadopenttd-c96cb9ce3757f90384f8cd624eb3f2878db477ff.tar.xz
(svn r21214) -Add: Display mail capacity when refitting an aircraft to passengers.
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/vehicle.cpp5
-rw-r--r--src/vehicle_cmd.cpp6
-rw-r--r--src/vehicle_func.h1
-rw-r--r--src/vehicle_gui.cpp47
5 files changed, 43 insertions, 17 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 7970ca903..f48d95f47 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -3125,6 +3125,7 @@ STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY :{BLACK}Capacity
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
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index a10f0481d..75ef97ecd 100644
--- 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 */
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 84f960976..4d29ac495 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -254,6 +254,7 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byt
{
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 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byt
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 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byt
}
_returned_refit_capacity = total_capacity;
+ _returned_mail_refit_capacity = total_mail_capacity;
return cost;
}
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index fbca79beb..d7752cfb2 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -175,6 +175,7 @@ void StopAllVehicles();
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);
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 56c043d63..4ba023809 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -537,6 +537,33 @@ struct RefitWindow : public Window {
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 @@ struct RefitWindow : public Window {
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 @@ struct RefitWindow : public Window {
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);
}
}