1
0
Fork 0

Change: Show additional cost and refitted capacity in build vehicle window.

pull/7409/head
peter1138 2019-03-23 21:06:46 +00:00 committed by PeterN
parent f8e6cd10ef
commit e6bb90543e
7 changed files with 165 additions and 64 deletions

View File

@ -168,16 +168,16 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine)
* @param engine Model to investigate. * @param engine Model to investigate.
* @param[out] cargoes Total amount of units that can be transported, summed by cargo. * @param[out] cargoes Total amount of units that can be transported, summed by cargo.
* @param[out] refits Whether a (possibly partial) refit for each cargo is possible. * @param[out] refits Whether a (possibly partial) refit for each cargo is possible.
* @param cargo_type Selected refitted cargo type
* @param cargo_capacity Capacity of selected refitted cargo type
*/ */
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits) void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint16 cargo_capacity)
{ {
cargoes->Clear(); cargoes->Clear();
*refits = 0; *refits = 0;
const Engine *e = Engine::Get(engine); const Engine *e = Engine::Get(engine);
CargoID cargo_type;
uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
if (cargo_type < NUM_CARGO && cargo_capacity > 0) { if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
(*cargoes)[cargo_type] += cargo_capacity; (*cargoes)[cargo_type] += cargo_capacity;
if (IsEngineRefittable(engine)) SetBit(*refits, cargo_type); if (IsEngineRefittable(engine)) SetBit(*refits, cargo_type);

View File

@ -423,9 +423,16 @@ public:
/* Draw details panels. */ /* Draw details panels. */
for (int side = 0; side < 2; side++) { for (int side = 0; side < 2; side++) {
if (this->sel_engine[side] != INVALID_ENGINE) { if (this->sel_engine[side] != INVALID_ENGINE) {
/* Use default engine details without refitting */
const Engine *e = Engine::Get(this->sel_engine[side]);
TestedEngineDetails ted;
ted.cost = 0;
ted.cargo = e->GetDefaultCargoType();
ted.capacity = e->GetDisplayDefaultCapacity(&ted.mail_capacity);
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS); NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS);
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT, int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side]); nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side], ted);
needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM); needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
} }
} }

View File

@ -532,11 +532,11 @@ static GUIEngineList::FilterFunction * const _filter_funcs[] = {
&CargoFilter, &CargoFilter,
}; };
static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine) static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, TestedEngineDetails &te)
{ {
CargoArray cap; CargoArray cap;
CargoTypes refits; CargoTypes refits;
GetArticulatedVehicleCargoesAndRefits(engine, &cap, &refits); GetArticulatedVehicleCargoesAndRefits(engine, &cap, &refits, te.cargo, te.capacity);
for (CargoID c = 0; c < NUM_CARGO; c++) { for (CargoID c = 0; c < NUM_CARGO; c++) {
if (cap[c] == 0) continue; if (cap[c] == 0) continue;
@ -552,19 +552,25 @@ static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine)
} }
/* Draw rail wagon specific details */ /* Draw rail wagon specific details */
static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi) static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
{ {
const Engine *e = Engine::Get(engine_number); const Engine *e = Engine::Get(engine_number);
/* Purchase cost */ /* Purchase cost */
SetDParam(0, e->GetCost()); if (te.cost != 0) {
DrawString(left, right, y, STR_PURCHASE_INFO_COST); SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
} else {
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
/* Wagon weight - (including cargo) */ /* Wagon weight - (including cargo) */
uint weight = e->GetDisplayWeight(); uint weight = e->GetDisplayWeight();
SetDParam(0, weight); SetDParam(0, weight);
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(e->GetDefaultCargoType())->weight * GetTotalCapacityOfArticulatedParts(engine_number) / 16 : 0); uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
SetDParam(1, cargo_weight + weight); SetDParam(1, cargo_weight + weight);
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT); DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
@ -590,14 +596,21 @@ static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine
} }
/* Draw locomotive specific details */ /* Draw locomotive specific details */
static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi) static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
{ {
const Engine *e = Engine::Get(engine_number); const Engine *e = Engine::Get(engine_number);
/* Purchase Cost - Engine weight */ /* Purchase Cost - Engine weight */
SetDParam(0, e->GetCost()); if (te.cost != 0) {
SetDParam(1, e->GetDisplayWeight()); SetDParam(0, e->GetCost() + te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT); SetDParam(1, te.cost);
SetDParam(2, e->GetDisplayWeight());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_WEIGHT);
} else {
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayWeight());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
}
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
/* Max speed - Engine power */ /* Max speed - Engine power */
@ -632,20 +645,26 @@ static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engin
} }
/* Draw road vehicle specific details */ /* Draw road vehicle specific details */
static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number) static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
{ {
const Engine *e = Engine::Get(engine_number); const Engine *e = Engine::Get(engine_number);
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) { if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
/* Purchase Cost */ /* Purchase Cost */
SetDParam(0, e->GetCost()); if (te.cost != 0) {
DrawString(left, right, y, STR_PURCHASE_INFO_COST); SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
} else {
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
/* Road vehicle weight - (including cargo) */ /* Road vehicle weight - (including cargo) */
int16 weight = e->GetDisplayWeight(); int16 weight = e->GetDisplayWeight();
SetDParam(0, weight); SetDParam(0, weight);
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(e->GetDefaultCargoType())->weight * GetTotalCapacityOfArticulatedParts(engine_number) / 16 : 0); uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
SetDParam(1, cargo_weight + weight); SetDParam(1, cargo_weight + weight);
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT); DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
@ -662,9 +681,16 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
} else { } else {
/* Purchase cost - Max speed */ /* Purchase cost - Max speed */
SetDParam(0, e->GetCost()); if (te.cost != 0) {
SetDParam(1, e->GetDisplayMaxSpeed()); SetDParam(0, e->GetCost() + te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED); SetDParam(1, te.cost);
SetDParam(2, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
} else {
SetDParam(0, e->GetCost());
SetDParam(2, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
} }
@ -677,7 +703,7 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
} }
/* Draw ship specific details */ /* Draw ship specific details */
static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable) static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
{ {
const Engine *e = Engine::Get(engine_number); const Engine *e = Engine::Get(engine_number);
@ -686,13 +712,27 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
uint ocean_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, true); uint ocean_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, true);
uint canal_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, false); uint canal_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, false);
SetDParam(0, e->GetCost());
if (ocean_speed == canal_speed) { if (ocean_speed == canal_speed) {
SetDParam(1, ocean_speed); if (te.cost != 0) {
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED); SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
SetDParam(2, ocean_speed);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
} else {
SetDParam(0, e->GetCost());
SetDParam(1, ocean_speed);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
} else { } else {
DrawString(left, right, y, STR_PURCHASE_INFO_COST); if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
} else {
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
SetDParam(0, ocean_speed); SetDParam(0, ocean_speed);
@ -705,8 +745,8 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
} }
/* Cargo type + capacity */ /* Cargo type + capacity */
SetDParam(0, e->GetDefaultCargoType()); SetDParam(0, te.cargo);
SetDParam(1, e->GetDisplayDefaultCapacity()); SetDParam(1, te.capacity);
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY); SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY); DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
@ -728,31 +768,35 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
* @param refittable If set, the aircraft can be refitted. * @param refittable If set, the aircraft can be refitted.
* @return Bottom of the used area. * @return Bottom of the used area.
*/ */
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable) static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
{ {
const Engine *e = Engine::Get(engine_number); const Engine *e = Engine::Get(engine_number);
CargoID cargo = e->GetDefaultCargoType();
/* Purchase cost - Max speed */ /* Purchase cost - Max speed */
SetDParam(0, e->GetCost()); if (te.cost != 0) {
SetDParam(1, e->GetDisplayMaxSpeed()); SetDParam(0, e->GetCost() + te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED); SetDParam(1, te.cost);
SetDParam(2, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
} else {
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
/* Cargo capacity */ /* Cargo capacity */
uint16 mail_capacity; if (te.mail_capacity > 0) {
uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity); SetDParam(0, te.cargo);
if (mail_capacity > 0) { SetDParam(1, te.capacity);
SetDParam(0, cargo);
SetDParam(1, capacity);
SetDParam(2, CT_MAIL); SetDParam(2, CT_MAIL);
SetDParam(3, mail_capacity); SetDParam(3, te.mail_capacity);
DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY); DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
} else { } else {
/* Note, if the default capacity is selected by the refit capacity /* Note, if the default capacity is selected by the refit capacity
* callback, then the capacity shown is likely to be incorrect. */ * callback, then the capacity shown is likely to be incorrect. */
SetDParam(0, cargo); SetDParam(0, te.cargo);
SetDParam(1, capacity); SetDParam(1, te.capacity);
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY); SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY); DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
} }
@ -809,7 +853,7 @@ static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
* @param engine_number the engine of which to draw the info of * @param engine_number the engine of which to draw the info of
* @return y after drawing all the text * @return y after drawing all the text
*/ */
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number) int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
{ {
const Engine *e = Engine::Get(engine_number); const Engine *e = Engine::Get(engine_number);
YearMonthDay ymd; YearMonthDay ymd;
@ -821,30 +865,30 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: case VEH_TRAIN:
if (e->u.rail.railveh_type == RAILVEH_WAGON) { if (e->u.rail.railveh_type == RAILVEH_WAGON) {
y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail); y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
} else { } else {
y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail); y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
} }
articulated_cargo = true; articulated_cargo = true;
break; break;
case VEH_ROAD: case VEH_ROAD:
y = DrawRoadVehPurchaseInfo(left, right, y, engine_number); y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
articulated_cargo = true; articulated_cargo = true;
break; break;
case VEH_SHIP: case VEH_SHIP:
y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable); y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
break; break;
case VEH_AIRCRAFT: case VEH_AIRCRAFT:
y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable); y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable, te);
break; break;
} }
if (articulated_cargo) { if (articulated_cargo) {
/* Cargo type + capacity, or N/A */ /* Cargo type + capacity, or N/A */
int new_y = DrawCargoCapacityInfo(left, right, y, engine_number); int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, te);
if (new_y == y) { if (new_y == y) {
SetDParam(0, CT_INVALID); SetDParam(0, CT_INVALID);
@ -988,6 +1032,7 @@ struct BuildVehicleWindow : Window {
byte cargo_filter_criteria; ///< Selected cargo filter byte cargo_filter_criteria; ///< Selected cargo filter
int details_height; ///< Minimal needed height of the details panels (found so far). int details_height; ///< Minimal needed height of the details panels (found so far).
Scrollbar *vscroll; Scrollbar *vscroll;
TestedEngineDetails te; ///< Tested cost and capacity after refit.
void SetBuyVehicleText() void SetBuyVehicleText()
{ {
@ -1065,8 +1110,11 @@ struct BuildVehicleWindow : Window {
this->eng_list.ForceRebuild(); this->eng_list.ForceRebuild();
this->GenerateBuildList(); // generate the list, since we need it in the next line this->GenerateBuildList(); // generate the list, since we need it in the next line
/* Select the first engine in the list as default when opening the window */ /* Select the first engine in the list as default when opening the window */
if (this->eng_list.Length() > 0) this->sel_engine = this->eng_list[0]; if (this->eng_list.Length() > 0) {
this->SetBuyVehicleText(); this->SelectEngine(this->eng_list[0]);
} else {
this->SelectEngine(INVALID_ENGINE);
}
} }
/** Populate the filter list and set the cargo filter criteria. */ /** Populate the filter list and set the cargo filter criteria. */
@ -1113,6 +1161,41 @@ struct BuildVehicleWindow : Window {
this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY); this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
} }
void SelectEngine(EngineID engine)
{
bool refit = this->cargo_filter[this->cargo_filter_criteria] != CF_ANY && this->cargo_filter[this->cargo_filter_criteria] != CF_NONE;
CargoID cargo = refit ? this->cargo_filter[this->cargo_filter_criteria] : CT_INVALID;
this->sel_engine = engine;
this->SetBuyVehicleText();
if (this->sel_engine == INVALID_ENGINE) return;
const Engine *e = Engine::Get(this->sel_engine);
if (!e->CanCarryCargo()) {
this->te.cost = 0;
this->te.cargo = CT_INVALID;
return;
}
if (!this->listview_mode) {
/* Query for cost and refitted capacity */
CommandCost ret = DoCommand(this->window_number, this->sel_engine | (cargo << 24), 0, DC_QUERY_COST, GetCmdBuildVeh(this->vehicle_type), NULL);
if (ret.Succeeded()) {
this->te.cost = ret.GetCost() - e->GetCost();
this->te.capacity = _returned_refit_capacity;
this->te.mail_capacity = _returned_mail_refit_capacity;
this->te.cargo = (cargo == CT_INVALID) ? e->GetDefaultCargoType() : cargo;
return;
}
}
/* Purchase test was not possible or failed, fill in the defaults instead. */
this->te.cost = 0;
this->te.capacity = e->GetDisplayDefaultCapacity(&this->te.mail_capacity);
this->te.cargo = e->GetDefaultCargoType();
}
void OnInit() override void OnInit() override
{ {
this->SetCargoFilterArray(); this->SetCargoFilterArray();
@ -1123,11 +1206,9 @@ struct BuildVehicleWindow : Window {
{ {
this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]); this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
if (0 == this->eng_list.Length()) { // no engine passed through the filter, invalidate the previously selected engine if (0 == this->eng_list.Length()) { // no engine passed through the filter, invalidate the previously selected engine
this->sel_engine = INVALID_ENGINE; this->SelectEngine(INVALID_ENGINE);
this->SetBuyVehicleText();
} else if (!this->eng_list.Contains(this->sel_engine)) { // previously selected engine didn't pass the filter, select the first engine of the list } else if (!this->eng_list.Contains(this->sel_engine)) { // previously selected engine didn't pass the filter, select the first engine of the list
this->sel_engine = this->eng_list[0]; this->SelectEngine(this->eng_list[0]);
this->SetBuyVehicleText();
} }
} }
@ -1176,7 +1257,7 @@ struct BuildVehicleWindow : Window {
if (eid == this->sel_engine) sel_id = eid; if (eid == this->sel_engine) sel_id = eid;
} }
this->sel_engine = sel_id; this->SelectEngine(sel_id);
/* make engines first, and then wagons, sorted by selected sort_criteria */ /* make engines first, and then wagons, sorted by selected sort_criteria */
_engine_sort_direction = false; _engine_sort_direction = false;
@ -1207,7 +1288,7 @@ struct BuildVehicleWindow : Window {
if (eid == this->sel_engine) sel_id = eid; if (eid == this->sel_engine) sel_id = eid;
} }
this->sel_engine = sel_id; this->SelectEngine(sel_id);
} }
/* Figure out what ship EngineIDs to put in the list */ /* Figure out what ship EngineIDs to put in the list */
@ -1225,7 +1306,7 @@ struct BuildVehicleWindow : Window {
if (eid == this->sel_engine) sel_id = eid; if (eid == this->sel_engine) sel_id = eid;
} }
this->sel_engine = sel_id; this->SelectEngine(sel_id);
} }
/* Figure out what aircraft EngineIDs to put in the list */ /* Figure out what aircraft EngineIDs to put in the list */
@ -1253,7 +1334,7 @@ struct BuildVehicleWindow : Window {
if (eid == this->sel_engine) sel_id = eid; if (eid == this->sel_engine) sel_id = eid;
} }
this->sel_engine = sel_id; this->SelectEngine(sel_id);
} }
/* Generate the list of vehicles */ /* Generate the list of vehicles */
@ -1308,8 +1389,7 @@ struct BuildVehicleWindow : Window {
case WID_BV_LIST: { case WID_BV_LIST: {
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BV_LIST); uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BV_LIST);
size_t num_items = this->eng_list.Length(); size_t num_items = this->eng_list.Length();
this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE; this->SelectEngine((i < num_items) ? this->eng_list[i] : INVALID_ENGINE);
this->SetBuyVehicleText();
this->SetDirty(); this->SetDirty();
if (_ctrl_pressed) { if (_ctrl_pressed) {
this->OnClick(pt, WID_BV_SHOW_HIDE, 1); this->OnClick(pt, WID_BV_SHOW_HIDE, 1);
@ -1473,7 +1553,7 @@ struct BuildVehicleWindow : Window {
if (this->sel_engine != INVALID_ENGINE) { if (this->sel_engine != INVALID_ENGINE) {
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_BV_PANEL); NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_BV_PANEL);
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT, int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine); nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine, this->te);
needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM); needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
} }
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them. if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
@ -1510,7 +1590,7 @@ struct BuildVehicleWindow : Window {
/* deactivate filter if criteria is 'Show All', activate it otherwise */ /* deactivate filter if criteria is 'Show All', activate it otherwise */
this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY); this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
this->eng_list.ForceRebuild(); this->eng_list.ForceRebuild();
this->SetBuyVehicleText(); this->SelectEngine(this->sel_engine);
} }
break; break;
} }

View File

@ -26,7 +26,7 @@ extern const uint8 _engine_offsets[4];
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company); bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
bool IsEngineRefittable(EngineID engine); bool IsEngineRefittable(EngineID engine);
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits); void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint16 cargo_capacity);
void SetYearEngineAgingStops(); void SetYearEngineAgingStops();
void StartupOneEngine(Engine *e, Date aging_date); void StartupOneEngine(Engine *e, Date aging_date);

View File

@ -3469,6 +3469,7 @@ STR_BUY_VEHICLE_SHIP_CAPTION :New Ships
STR_BUY_VEHICLE_AIRCRAFT_CAPTION :New Aircraft STR_BUY_VEHICLE_AIRCRAFT_CAPTION :New Aircraft
STR_PURCHASE_INFO_COST_WEIGHT :{BLACK}Cost: {GOLD}{CURRENCY_LONG}{BLACK} Weight: {GOLD}{WEIGHT_SHORT} STR_PURCHASE_INFO_COST_WEIGHT :{BLACK}Cost: {GOLD}{CURRENCY_LONG}{BLACK} Weight: {GOLD}{WEIGHT_SHORT}
STR_PURCHASE_INFO_COST_REFIT_WEIGHT :{BLACK}Cost: {GOLD}{CURRENCY_LONG}{BLACK} (Refit Cost: {GOLD}{CURRENCY_LONG}{BLACK}) Weight: {GOLD}{WEIGHT_SHORT}
STR_PURCHASE_INFO_SPEED_POWER :{BLACK}Speed: {GOLD}{VELOCITY}{BLACK} Power: {GOLD}{POWER} STR_PURCHASE_INFO_SPEED_POWER :{BLACK}Speed: {GOLD}{VELOCITY}{BLACK} Power: {GOLD}{POWER}
STR_PURCHASE_INFO_SPEED :{BLACK}Speed: {GOLD}{VELOCITY} STR_PURCHASE_INFO_SPEED :{BLACK}Speed: {GOLD}{VELOCITY}
STR_PURCHASE_INFO_SPEED_OCEAN :{BLACK}Speed on ocean: {GOLD}{VELOCITY} STR_PURCHASE_INFO_SPEED_OCEAN :{BLACK}Speed on ocean: {GOLD}{VELOCITY}
@ -3479,8 +3480,10 @@ STR_PURCHASE_INFO_REFITTABLE :(refittable)
STR_PURCHASE_INFO_DESIGNED_LIFE :{BLACK}Designed: {GOLD}{NUM}{BLACK} Life: {GOLD}{COMMA} year{P "" s} STR_PURCHASE_INFO_DESIGNED_LIFE :{BLACK}Designed: {GOLD}{NUM}{BLACK} Life: {GOLD}{COMMA} year{P "" s}
STR_PURCHASE_INFO_RELIABILITY :{BLACK}Max. Reliability: {GOLD}{COMMA}% STR_PURCHASE_INFO_RELIABILITY :{BLACK}Max. Reliability: {GOLD}{COMMA}%
STR_PURCHASE_INFO_COST :{BLACK}Cost: {GOLD}{CURRENCY_LONG} STR_PURCHASE_INFO_COST :{BLACK}Cost: {GOLD}{CURRENCY_LONG}
STR_PURCHASE_INFO_COST_REFIT :{BLACK}Cost: {GOLD}{CURRENCY_LONG}{BLACK} (Refit Cost: {GOLD}{CURRENCY_LONG}{BLACK})
STR_PURCHASE_INFO_WEIGHT_CWEIGHT :{BLACK}Weight: {GOLD}{WEIGHT_SHORT} ({WEIGHT_SHORT}) STR_PURCHASE_INFO_WEIGHT_CWEIGHT :{BLACK}Weight: {GOLD}{WEIGHT_SHORT} ({WEIGHT_SHORT})
STR_PURCHASE_INFO_COST_SPEED :{BLACK}Cost: {GOLD}{CURRENCY_LONG}{BLACK} Speed: {GOLD}{VELOCITY} STR_PURCHASE_INFO_COST_SPEED :{BLACK}Cost: {GOLD}{CURRENCY_LONG}{BLACK} Speed: {GOLD}{VELOCITY}
STR_PURCHASE_INFO_COST_REFIT_SPEED :{BLACK}Cost: {GOLD}{CURRENCY_LONG}{BLACK} (Refit Cost: {GOLD}{CURRENCY_LONG}{BLACK}) Speed: {GOLD}{VELOCITY}
STR_PURCHASE_INFO_AIRCRAFT_CAPACITY :{BLACK}Capacity: {GOLD}{CARGO_LONG}, {CARGO_LONG} STR_PURCHASE_INFO_AIRCRAFT_CAPACITY :{BLACK}Capacity: {GOLD}{CARGO_LONG}, {CARGO_LONG}
STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT :{BLACK}Powered Wagons: {GOLD}+{POWER}{BLACK} Weight: {GOLD}+{WEIGHT_SHORT} STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT :{BLACK}Powered Wagons: {GOLD}+{POWER}{BLACK} Weight: {GOLD}+{WEIGHT_SHORT}
STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Refittable to: {GOLD}{STRING2} STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Refittable to: {GOLD}{STRING2}

View File

@ -148,6 +148,9 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (refitting) { if (refitting) {
value.AddCost(CmdRefitVehicle(tile, flags, v->index, cargo, NULL)); value.AddCost(CmdRefitVehicle(tile, flags, v->index, cargo, NULL));
} else {
/* Fill in non-refitted capacities */
_returned_refit_capacity = e->GetDisplayDefaultCapacity(&_returned_mail_refit_capacity);
} }
if (flags & DC_EXEC) { if (flags & DC_EXEC) {

View File

@ -37,7 +37,15 @@ enum VehicleInvalidateWindowData {
VIWD_AUTOREPLACE = -4, ///< Autoreplace replaced the vehicle. VIWD_AUTOREPLACE = -4, ///< Autoreplace replaced the vehicle.
}; };
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number); /** Extra information about refitted cargo and capacity */
struct TestedEngineDetails {
Money cost; ///< Refit cost
CargoID cargo; ///< Cargo type
uint16 capacity; ///< Cargo capacity
uint16 mail_capacity; ///< Mail capacity if available
};
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te);
void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest = INVALID_VEHICLE); void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest = INVALID_VEHICLE);
void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip = 0); void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip = 0);