diff -r 0b2aebc8283e -r 0b8b245a2391 src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp Wed Jun 13 11:17:30 2007 +0000 +++ b/src/build_vehicle_gui.cpp Wed Jun 13 11:45:14 2007 +0000 @@ -27,6 +27,7 @@ #include "date.h" #include "strings.h" #include "cargotype.h" +#include "group.h" enum BuildVehicleWidgets { @@ -409,21 +410,25 @@ static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi) { /* Purchase cost */ - SetDParam(0, (rvi->base_cost * _eco->GetPrice(CEconomy::BUILD_RAILWAGON)) >> 8); + SetDParam(0, (GetEngineProperty(engine_number, 0x17, rvi->base_cost) * _eco->GetPrice(CEconomy::BUILD_RAILWAGON)) >> 8); DrawString(x, y, STR_PURCHASE_INFO_COST, 0); y += 10; /* Wagon weight - (including cargo) */ - SetDParam(0, rvi->weight); - SetDParam(1, (GetCargo(rvi->cargo_type)->weight * rvi->capacity >> 4) + rvi->weight); + uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight); + SetDParam(0, weight); + SetDParam(1, (GetCargo(rvi->cargo_type)->weight * GetEngineProperty(engine_number, 0x14, rvi->capacity) >> 4) + weight); DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0); y += 10; /* Wagon speed limit, displayed if above zero */ - if (rvi->max_speed > 0 && _patches.wagon_speed_limits) { - SetDParam(0, rvi->max_speed * 10 / 16); - DrawString(x, y, STR_PURCHASE_INFO_SPEED, 0); - y += 10; + if (_patches.wagon_speed_limits) { + uint max_speed = GetEngineProperty(engine_number, 0x09, rvi->max_speed); + if (max_speed > 0) { + SetDParam(0, max_speed * 10 / 16); + DrawString(x, y, STR_PURCHASE_INFO_SPEED, 0); + y += 10; + } } return y; } @@ -432,22 +437,23 @@ static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi) { int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0); + uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight); /* Purchase Cost - Engine weight */ - SetDParam(0, rvi->base_cost * (_eco->GetPrice(CEconomy::BUILD_RAILVEHICLE) >> 3) >> 5); - SetDParam(1, rvi->weight << multihead); + SetDParam(0, GetEngineProperty(engine_number, 0x17, rvi->base_cost) * (_eco->GetPrice(CEconomy::BUILD_RAILVEHICLE) >> 3) >> 5); + SetDParam(1, weight << multihead); DrawString(x, y, STR_PURCHASE_INFO_COST_WEIGHT, 0); y += 10; /* Max speed - Engine power */ - SetDParam(0, rvi->max_speed * 10 / 16); - SetDParam(1, rvi->power << multihead); + SetDParam(0, GetEngineProperty(engine_number, 0x09, rvi->max_speed) * 10 / 16); + SetDParam(1, GetEngineProperty(engine_number, 0x0B, rvi->power) << multihead); DrawString(x, y, STR_PURCHASE_INFO_SPEED_POWER, 0); y += 10; /* Max tractive effort - not applicable if old acceleration or maglev */ if (_patches.realistic_acceleration && rvi->railtype != RAILTYPE_MAGLEV) { - SetDParam(0, ((rvi->weight << multihead) * 10 * rvi->tractive_effort) / 256); + SetDParam(0, ((weight << multihead) * 10 * GetEngineProperty(engine_number, 0x1F, rvi->tractive_effort)) / 256); DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0); y += 10; } @@ -462,7 +468,7 @@ } /* Running cost */ - SetDParam(0, (rvi->running_cost_base * cost_class >> 8) << multihead); + SetDParam(0, (GetEngineProperty(engine_number, 0x0D, rvi->running_cost_base) * cost_class >> 8) << multihead); DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0); y += 10; @@ -483,7 +489,7 @@ bool refittable = (_engine_info[engine_number].refit_mask != 0); /* Purchase cost - Max speed */ - SetDParam(0, rvi->base_cost * (_eco->GetPrice(CEconomy::ROADVEH_BASE) >> 3) >> 5); + SetDParam(0, GetEngineProperty(engine_number, 0x11, rvi->base_cost) * (_eco->GetPrice(CEconomy::ROADVEH_BASE) >> 3) >> 5); SetDParam(1, rvi->max_speed * 10 / 32); DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0); y += 10; @@ -495,7 +501,7 @@ /* Cargo type + capacity */ SetDParam(0, rvi->cargo_type); - SetDParam(1, rvi->capacity); + SetDParam(1, GetEngineProperty(engine_number, 0x0F, rvi->capacity)); SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); y += 10; @@ -507,20 +513,21 @@ static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi) { /* Purchase cost - Max speed */ - SetDParam(0, svi->base_cost * (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5); - SetDParam(1, svi->max_speed * 10 / 32); + SetDParam(0, GetEngineProperty(engine_number, 0x0A, svi->base_cost) + * (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5); + SetDParam(1, GetEngineProperty(engine_number, 0x0B, svi->max_speed) * 10 / 32); DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0); y += 10; /* Cargo type + capacity */ SetDParam(0, svi->cargo_type); - SetDParam(1, svi->capacity); + SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity)); SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY); DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); y += 10; /* Running cost */ - SetDParam(0, svi->running_cost * _eco->GetPrice(CEconomy::SHIP_RUNNING) >> 8); + SetDParam(0, GetEngineProperty(engine_number, 0x0F, svi->running_cost) * _eco->GetPrice(CEconomy::SHIP_RUNNING) >> 8); DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0); y += 10; @@ -533,7 +540,7 @@ CargoID cargo; /* Purchase cost - Max speed */ - SetDParam(0, avi->base_cost * (_eco->GetPrice(CEconomy::AIRCRAFT_BASE) >> 3) >> 5); + SetDParam(0, GetEngineProperty(engine_number, 0x0B, avi->base_cost) * (_eco->GetPrice(CEconomy::AIRCRAFT_BASE) >> 3) >> 5); SetDParam(1, avi->max_speed * 10 / 16); DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0); y += 10; @@ -555,7 +562,7 @@ y += 10; /* Running cost */ - SetDParam(0, avi->running_cost * _eco->GetPrice(CEconomy::AIRCRAFT_RUNNING) >> 8); + SetDParam(0, GetEngineProperty(engine_number, 0x0E, avi->running_cost) * _eco->GetPrice(CEconomy::AIRCRAFT_RUNNING) >> 8); DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0); y += 10; @@ -577,10 +584,12 @@ bool refitable = false; switch (e->type) { + default: NOT_REACHED(); case VEH_TRAIN: { const RailVehicleInfo *rvi = RailVehInfo(engine_number); + uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity); - refitable = (EngInfo(engine_number)->refit_mask != 0) && (rvi->capacity > 0); + refitable = (EngInfo(engine_number)->refit_mask != 0) && (capacity > 0); if (rvi->railveh_type == RAILVEH_WAGON) { y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi); @@ -596,7 +605,7 @@ int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0); SetDParam(0, rvi->cargo_type); - SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead); + SetDParam(1, (capacity * (CountArticulatedParts(engine_number) + 1)) << multihead); SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY); } DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); @@ -753,6 +762,7 @@ buildvehicle_d *bv = &WP(w, buildvehicle_d); switch (bv->vehicle_type) { + default: NOT_REACHED(); case VEH_TRAIN: GenerateBuildTrainList(w); return; // trains should not reach the last sorting @@ -790,7 +800,7 @@ * @param selected_id what engine to highlight as selected, if any * @param show_count Display the number of vehicles (used by autoreplace) */ -void DrawEngineList(byte type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count) +void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group) { byte step_size = GetVehicleListHeight(type); byte x_offset = 0; @@ -826,11 +836,12 @@ for (; min < max; min++, y += step_size) { const EngineID engine = eng_list[min]; + const uint num_engines = IsDefaultGroupID(selected_group) ? p->num_engines[engine] : GetGroup(selected_group)->num_engines[engine]; DrawString(x + x_offset, y, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10); - DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && p->num_engines[engine] == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player)); + DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player)); if (show_count) { - SetDParam(0, p->num_engines[engine]); + SetDParam(0, num_engines); DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0); } } @@ -864,7 +875,7 @@ SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles DrawWindowWidgets(w); - DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false); + DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false, DEFAULT_GROUP); if (bv->sel_engine != INVALID_ENGINE) { const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL]; @@ -905,6 +916,7 @@ EngineID sel_eng = bv->sel_engine; if (sel_eng != INVALID_ENGINE) { switch (bv->vehicle_type) { + default: NOT_REACHED(); case VEH_TRAIN: DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)); @@ -930,6 +942,7 @@ bv->rename_engine = sel_eng; switch (bv->vehicle_type) { + default: NOT_REACHED(); case VEH_TRAIN: str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break; case VEH_ROAD: str = STR_9036_RENAME_ROAD_VEHICLE_TYPE; break; case VEH_SHIP: str = STR_9838_RENAME_SHIP_TYPE; break; @@ -973,6 +986,7 @@ StringID str = STR_NULL; _cmd_text = e->we.edittext.str; switch (bv->vehicle_type) { + default: NOT_REACHED(); case VEH_TRAIN: str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break; case VEH_ROAD: str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE; break; case VEH_SHIP: str = STR_9839_CAN_T_RENAME_SHIP_TYPE; break; @@ -1010,7 +1024,7 @@ NewVehicleWndProc }; -void ShowBuildVehicleWindow(TileIndex tile, byte type) +void ShowBuildVehicleWindow(TileIndex tile, VehicleType type) { buildvehicle_d *bv; Window *w; @@ -1039,6 +1053,7 @@ bv->descending_sort_order = _last_sort_order[type]; switch (type) { + default: NOT_REACHED(); case VEH_TRAIN: WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile); ResizeWindow(w, 0, 16);