mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r21214) -Add: Display mail capacity when refitting an aircraft to passengers.
This commit is contained in:
parent
07ad8851cc
commit
c96cb9ce37
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue