src/build_vehicle_gui.cpp
branchgamebalance
changeset 9911 0b8b245a2391
parent 9910 0b2aebc8283e
child 9912 1ac8aac92385
equal deleted inserted replaced
9910:0b2aebc8283e 9911:0b8b245a2391
    25 #include "vehicle_gui.h"
    25 #include "vehicle_gui.h"
    26 #include "newgrf_engine.h"
    26 #include "newgrf_engine.h"
    27 #include "date.h"
    27 #include "date.h"
    28 #include "strings.h"
    28 #include "strings.h"
    29 #include "cargotype.h"
    29 #include "cargotype.h"
       
    30 #include "group.h"
    30 
    31 
    31 
    32 
    32 enum BuildVehicleWidgets {
    33 enum BuildVehicleWidgets {
    33 	BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
    34 	BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
    34 	BUILD_VEHICLE_WIDGET_CAPTION,
    35 	BUILD_VEHICLE_WIDGET_CAPTION,
   407 
   408 
   408 /* Draw rail wagon specific details */
   409 /* Draw rail wagon specific details */
   409 static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   410 static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   410 {
   411 {
   411 	/* Purchase cost */
   412 	/* Purchase cost */
   412 	SetDParam(0, (rvi->base_cost * _eco->GetPrice(CEconomy::BUILD_RAILWAGON)) >> 8);
   413 	SetDParam(0, (GetEngineProperty(engine_number, 0x17, rvi->base_cost) * _eco->GetPrice(CEconomy::BUILD_RAILWAGON)) >> 8);
   413 	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
   414 	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
   414 	y += 10;
   415 	y += 10;
   415 
   416 
   416 	/* Wagon weight - (including cargo) */
   417 	/* Wagon weight - (including cargo) */
   417 	SetDParam(0, rvi->weight);
   418 	uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
   418 	SetDParam(1, (GetCargo(rvi->cargo_type)->weight * rvi->capacity >> 4) + rvi->weight);
   419 	SetDParam(0, weight);
       
   420 	SetDParam(1, (GetCargo(rvi->cargo_type)->weight * GetEngineProperty(engine_number, 0x14, rvi->capacity) >> 4) + weight);
   419 	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
   421 	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
   420 	y += 10;
   422 	y += 10;
   421 
   423 
   422 	/* Wagon speed limit, displayed if above zero */
   424 	/* Wagon speed limit, displayed if above zero */
   423 	if (rvi->max_speed > 0 && _patches.wagon_speed_limits) {
   425 	if (_patches.wagon_speed_limits) {
   424 		SetDParam(0, rvi->max_speed * 10 / 16);
   426 		uint max_speed = GetEngineProperty(engine_number, 0x09, rvi->max_speed);
   425 		DrawString(x, y, STR_PURCHASE_INFO_SPEED, 0);
   427 		if (max_speed > 0) {
   426 		y += 10;
   428 			SetDParam(0, max_speed * 10 / 16);
       
   429 			DrawString(x, y, STR_PURCHASE_INFO_SPEED, 0);
       
   430 			y += 10;
       
   431 		}
   427 	}
   432 	}
   428 	return y;
   433 	return y;
   429 }
   434 }
   430 
   435 
   431 /* Draw locomotive specific details */
   436 /* Draw locomotive specific details */
   432 static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   437 static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   433 {
   438 {
   434 	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   439 	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
       
   440 	uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
   435 
   441 
   436 	/* Purchase Cost - Engine weight */
   442 	/* Purchase Cost - Engine weight */
   437 	SetDParam(0, rvi->base_cost * (_eco->GetPrice(CEconomy::BUILD_RAILVEHICLE) >> 3) >> 5);
   443 	SetDParam(0, GetEngineProperty(engine_number, 0x17, rvi->base_cost) * (_eco->GetPrice(CEconomy::BUILD_RAILVEHICLE) >> 3) >> 5);
   438 	SetDParam(1, rvi->weight << multihead);
   444 	SetDParam(1, weight << multihead);
   439 	DrawString(x, y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
   445 	DrawString(x, y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
   440 	y += 10;
   446 	y += 10;
   441 
   447 
   442 	/* Max speed - Engine power */
   448 	/* Max speed - Engine power */
   443 	SetDParam(0, rvi->max_speed * 10 / 16);
   449 	SetDParam(0, GetEngineProperty(engine_number, 0x09, rvi->max_speed) * 10 / 16);
   444 	SetDParam(1, rvi->power << multihead);
   450 	SetDParam(1, GetEngineProperty(engine_number, 0x0B, rvi->power) << multihead);
   445 	DrawString(x, y, STR_PURCHASE_INFO_SPEED_POWER, 0);
   451 	DrawString(x, y, STR_PURCHASE_INFO_SPEED_POWER, 0);
   446 	y += 10;
   452 	y += 10;
   447 
   453 
   448 	/* Max tractive effort - not applicable if old acceleration or maglev */
   454 	/* Max tractive effort - not applicable if old acceleration or maglev */
   449 	if (_patches.realistic_acceleration && rvi->railtype != RAILTYPE_MAGLEV) {
   455 	if (_patches.realistic_acceleration && rvi->railtype != RAILTYPE_MAGLEV) {
   450 		SetDParam(0, ((rvi->weight << multihead) * 10 * rvi->tractive_effort) / 256);
   456 		SetDParam(0, ((weight << multihead) * 10 * GetEngineProperty(engine_number, 0x1F, rvi->tractive_effort)) / 256);
   451 		DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0);
   457 		DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0);
   452 		y += 10;
   458 		y += 10;
   453 	}
   459 	}
   454 
   460 
   455 	uint32 cost_class;
   461 	uint32 cost_class;
   460 		case 1: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
   466 		case 1: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
   461 		case 2: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
   467 		case 2: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
   462 	}
   468 	}
   463 
   469 
   464 	/* Running cost */
   470 	/* Running cost */
   465 	SetDParam(0, (rvi->running_cost_base * cost_class >> 8) << multihead);
   471 	SetDParam(0, (GetEngineProperty(engine_number, 0x0D, rvi->running_cost_base) * cost_class >> 8) << multihead);
   466 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   472 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   467 	y += 10;
   473 	y += 10;
   468 
   474 
   469 	/* Powered wagons power - Powered wagons extra weight */
   475 	/* Powered wagons power - Powered wagons extra weight */
   470 	if (rvi->pow_wag_power != 0) {
   476 	if (rvi->pow_wag_power != 0) {
   481 static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi)
   487 static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi)
   482 {
   488 {
   483 	bool refittable = (_engine_info[engine_number].refit_mask != 0);
   489 	bool refittable = (_engine_info[engine_number].refit_mask != 0);
   484 
   490 
   485 	/* Purchase cost - Max speed */
   491 	/* Purchase cost - Max speed */
   486 	SetDParam(0, rvi->base_cost * (_eco->GetPrice(CEconomy::ROADVEH_BASE) >> 3) >> 5);
   492 	SetDParam(0, GetEngineProperty(engine_number, 0x11, rvi->base_cost) * (_eco->GetPrice(CEconomy::ROADVEH_BASE) >> 3) >> 5);
   487 	SetDParam(1, rvi->max_speed * 10 / 32);
   493 	SetDParam(1, rvi->max_speed * 10 / 32);
   488 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   494 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   489 	y += 10;
   495 	y += 10;
   490 
   496 
   491 	/* Running cost */
   497 	/* Running cost */
   493 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   499 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   494 	y += 10;
   500 	y += 10;
   495 
   501 
   496 	/* Cargo type + capacity */
   502 	/* Cargo type + capacity */
   497 	SetDParam(0, rvi->cargo_type);
   503 	SetDParam(0, rvi->cargo_type);
   498 	SetDParam(1, rvi->capacity);
   504 	SetDParam(1, GetEngineProperty(engine_number, 0x0F, rvi->capacity));
   499 	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
   505 	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
   500 	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   506 	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   501 	y += 10;
   507 	y += 10;
   502 
   508 
   503 	return y;
   509 	return y;
   505 
   511 
   506 /* Draw ship specific details */
   512 /* Draw ship specific details */
   507 static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
   513 static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
   508 {
   514 {
   509 	/* Purchase cost - Max speed */
   515 	/* Purchase cost - Max speed */
   510 	SetDParam(0, svi->base_cost * (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5);
   516 	SetDParam(0, GetEngineProperty(engine_number, 0x0A, svi->base_cost)
   511 	SetDParam(1, svi->max_speed * 10 / 32);
   517 			* (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5);
       
   518 	SetDParam(1, GetEngineProperty(engine_number, 0x0B, svi->max_speed) * 10 / 32);
   512 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   519 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   513 	y += 10;
   520 	y += 10;
   514 
   521 
   515 	/* Cargo type + capacity */
   522 	/* Cargo type + capacity */
   516 	SetDParam(0, svi->cargo_type);
   523 	SetDParam(0, svi->cargo_type);
   517 	SetDParam(1, svi->capacity);
   524 	SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity));
   518 	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
   525 	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
   519 	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   526 	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   520 	y += 10;
   527 	y += 10;
   521 
   528 
   522 	/* Running cost */
   529 	/* Running cost */
   523 	SetDParam(0, svi->running_cost * _eco->GetPrice(CEconomy::SHIP_RUNNING) >> 8);
   530 	SetDParam(0, GetEngineProperty(engine_number, 0x0F, svi->running_cost) * _eco->GetPrice(CEconomy::SHIP_RUNNING) >> 8);
   524 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   531 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   525 	y += 10;
   532 	y += 10;
   526 
   533 
   527 	return y;
   534 	return y;
   528 }
   535 }
   531 static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi)
   538 static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi)
   532 {
   539 {
   533 	CargoID cargo;
   540 	CargoID cargo;
   534 
   541 
   535 	/* Purchase cost - Max speed */
   542 	/* Purchase cost - Max speed */
   536 	SetDParam(0, avi->base_cost * (_eco->GetPrice(CEconomy::AIRCRAFT_BASE) >> 3) >> 5);
   543 	SetDParam(0, GetEngineProperty(engine_number, 0x0B, avi->base_cost) * (_eco->GetPrice(CEconomy::AIRCRAFT_BASE) >> 3) >> 5);
   537 	SetDParam(1, avi->max_speed * 10 / 16);
   544 	SetDParam(1, avi->max_speed * 10 / 16);
   538 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   545 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   539 	y += 10;
   546 	y += 10;
   540 
   547 
   541 	/* Cargo capacity */
   548 	/* Cargo capacity */
   553 		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   560 		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   554 	}
   561 	}
   555 	y += 10;
   562 	y += 10;
   556 
   563 
   557 	/* Running cost */
   564 	/* Running cost */
   558 	SetDParam(0, avi->running_cost * _eco->GetPrice(CEconomy::AIRCRAFT_RUNNING) >> 8);
   565 	SetDParam(0, GetEngineProperty(engine_number, 0x0E, avi->running_cost) * _eco->GetPrice(CEconomy::AIRCRAFT_RUNNING) >> 8);
   559 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   566 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   560 	y += 10;
   567 	y += 10;
   561 
   568 
   562 	return y;
   569 	return y;
   563 }
   570 }
   575 	YearMonthDay ymd;
   582 	YearMonthDay ymd;
   576 	ConvertDateToYMD(e->intro_date, &ymd);
   583 	ConvertDateToYMD(e->intro_date, &ymd);
   577 	bool refitable = false;
   584 	bool refitable = false;
   578 
   585 
   579 	switch (e->type) {
   586 	switch (e->type) {
       
   587 		default: NOT_REACHED();
   580 		case VEH_TRAIN: {
   588 		case VEH_TRAIN: {
   581 			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
   589 			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
   582 
   590 			uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity);
   583 			refitable = (EngInfo(engine_number)->refit_mask != 0) && (rvi->capacity > 0);
   591 
       
   592 			refitable = (EngInfo(engine_number)->refit_mask != 0) && (capacity > 0);
   584 
   593 
   585 			if (rvi->railveh_type == RAILVEH_WAGON) {
   594 			if (rvi->railveh_type == RAILVEH_WAGON) {
   586 				y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
   595 				y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
   587 			} else {
   596 			} else {
   588 				y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi);
   597 				y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi);
   594 				SetDParam(2, STR_EMPTY);
   603 				SetDParam(2, STR_EMPTY);
   595 			} else {
   604 			} else {
   596 				int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   605 				int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   597 
   606 
   598 				SetDParam(0, rvi->cargo_type);
   607 				SetDParam(0, rvi->cargo_type);
   599 				SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
   608 				SetDParam(1, (capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
   600 				SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
   609 				SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
   601 			}
   610 			}
   602 			DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   611 			DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   603 			y += 10;
   612 			y += 10;
   604 		}
   613 		}
   751 static void GenerateBuildList(Window *w)
   760 static void GenerateBuildList(Window *w)
   752 {
   761 {
   753 	buildvehicle_d *bv = &WP(w, buildvehicle_d);
   762 	buildvehicle_d *bv = &WP(w, buildvehicle_d);
   754 
   763 
   755 	switch (bv->vehicle_type) {
   764 	switch (bv->vehicle_type) {
       
   765 		default: NOT_REACHED();
   756 		case VEH_TRAIN:
   766 		case VEH_TRAIN:
   757 			GenerateBuildTrainList(w);
   767 			GenerateBuildTrainList(w);
   758 			return; // trains should not reach the last sorting
   768 			return; // trains should not reach the last sorting
   759 		case VEH_ROAD:
   769 		case VEH_ROAD:
   760 			GenerateBuildRoadVehList(w);
   770 			GenerateBuildRoadVehList(w);
   788  * @param min where to start in the list
   798  * @param min where to start in the list
   789  * @param max where in the list to end
   799  * @param max where in the list to end
   790  * @param selected_id what engine to highlight as selected, if any
   800  * @param selected_id what engine to highlight as selected, if any
   791  * @param show_count Display the number of vehicles (used by autoreplace)
   801  * @param show_count Display the number of vehicles (used by autoreplace)
   792  */
   802  */
   793 void DrawEngineList(byte type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count)
   803 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)
   794 {
   804 {
   795 	byte step_size = GetVehicleListHeight(type);
   805 	byte step_size = GetVehicleListHeight(type);
   796 	byte x_offset = 0;
   806 	byte x_offset = 0;
   797 	byte y_offset = 0;
   807 	byte y_offset = 0;
   798 	Player *p = GetPlayer(_local_player);
   808 	Player *p = GetPlayer(_local_player);
   824 		default: NOT_REACHED();
   834 		default: NOT_REACHED();
   825 	}
   835 	}
   826 
   836 
   827 	for (; min < max; min++, y += step_size) {
   837 	for (; min < max; min++, y += step_size) {
   828 		const EngineID engine = eng_list[min];
   838 		const EngineID engine = eng_list[min];
       
   839 		const uint num_engines = IsDefaultGroupID(selected_group) ? p->num_engines[engine] : GetGroup(selected_group)->num_engines[engine];
   829 
   840 
   830 		DrawString(x + x_offset, y, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
   841 		DrawString(x + x_offset, y, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
   831 		DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && p->num_engines[engine] == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
   842 		DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
   832 		if (show_count) {
   843 		if (show_count) {
   833 			SetDParam(0, p->num_engines[engine]);
   844 			SetDParam(0, num_engines);
   834 			DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
   845 			DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
   835 		}
   846 		}
   836 	}
   847 	}
   837 }
   848 }
   838 
   849 
   862 
   873 
   863 	SetVScrollCount(w, EngList_Count(&bv->eng_list));
   874 	SetVScrollCount(w, EngList_Count(&bv->eng_list));
   864 	SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
   875 	SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
   865 	DrawWindowWidgets(w);
   876 	DrawWindowWidgets(w);
   866 
   877 
   867 	DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false);
   878 	DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false, DEFAULT_GROUP);
   868 
   879 
   869 	if (bv->sel_engine != INVALID_ENGINE) {
   880 	if (bv->sel_engine != INVALID_ENGINE) {
   870 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
   881 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
   871 		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
   882 		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
   872 
   883 
   903 
   914 
   904 		case BUILD_VEHICLE_WIDGET_BUILD: {
   915 		case BUILD_VEHICLE_WIDGET_BUILD: {
   905 			EngineID sel_eng = bv->sel_engine;
   916 			EngineID sel_eng = bv->sel_engine;
   906 			if (sel_eng != INVALID_ENGINE) {
   917 			if (sel_eng != INVALID_ENGINE) {
   907 				switch (bv->vehicle_type) {
   918 				switch (bv->vehicle_type) {
       
   919 					default: NOT_REACHED();
   908 					case VEH_TRAIN:
   920 					case VEH_TRAIN:
   909 						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
   921 						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
   910 								   CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
   922 								   CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
   911 						break;
   923 						break;
   912 					case VEH_ROAD:
   924 					case VEH_ROAD:
   928 			if (sel_eng != INVALID_ENGINE) {
   940 			if (sel_eng != INVALID_ENGINE) {
   929 				StringID str = STR_NULL;
   941 				StringID str = STR_NULL;
   930 
   942 
   931 				bv->rename_engine = sel_eng;
   943 				bv->rename_engine = sel_eng;
   932 				switch (bv->vehicle_type) {
   944 				switch (bv->vehicle_type) {
       
   945 					default: NOT_REACHED();
   933 					case VEH_TRAIN:    str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break;
   946 					case VEH_TRAIN:    str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break;
   934 					case VEH_ROAD:     str = STR_9036_RENAME_ROAD_VEHICLE_TYPE;  break;
   947 					case VEH_ROAD:     str = STR_9036_RENAME_ROAD_VEHICLE_TYPE;  break;
   935 					case VEH_SHIP:     str = STR_9838_RENAME_SHIP_TYPE;          break;
   948 					case VEH_SHIP:     str = STR_9838_RENAME_SHIP_TYPE;          break;
   936 					case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE;      break;
   949 					case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE;      break;
   937 				}
   950 				}
   971 		case WE_ON_EDIT_TEXT: {
   984 		case WE_ON_EDIT_TEXT: {
   972 			if (e->we.edittext.str[0] != '\0') {
   985 			if (e->we.edittext.str[0] != '\0') {
   973 				StringID str = STR_NULL;
   986 				StringID str = STR_NULL;
   974 				_cmd_text = e->we.edittext.str;
   987 				_cmd_text = e->we.edittext.str;
   975 				switch (bv->vehicle_type) {
   988 				switch (bv->vehicle_type) {
       
   989 					default: NOT_REACHED();
   976 					case VEH_TRAIN:    str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
   990 					case VEH_TRAIN:    str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
   977 					case VEH_ROAD:     str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE;  break;
   991 					case VEH_ROAD:     str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE;  break;
   978 					case VEH_SHIP:     str = STR_9839_CAN_T_RENAME_SHIP_TYPE;     break;
   992 					case VEH_SHIP:     str = STR_9839_CAN_T_RENAME_SHIP_TYPE;     break;
   979 					case VEH_AIRCRAFT: str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break;
   993 					case VEH_AIRCRAFT: str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break;
   980 				}
   994 				}
  1008 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
  1022 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
  1009 	_build_vehicle_widgets,
  1023 	_build_vehicle_widgets,
  1010 	NewVehicleWndProc
  1024 	NewVehicleWndProc
  1011 };
  1025 };
  1012 
  1026 
  1013 void ShowBuildVehicleWindow(TileIndex tile, byte type)
  1027 void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
  1014 {
  1028 {
  1015 	buildvehicle_d *bv;
  1029 	buildvehicle_d *bv;
  1016 	Window *w;
  1030 	Window *w;
  1017 
  1031 
  1018 	assert(IsPlayerBuildableVehicleType(type));
  1032 	assert(IsPlayerBuildableVehicleType(type));
  1037 
  1051 
  1038 	bv->sort_criteria         = _last_sort_criteria[type];
  1052 	bv->sort_criteria         = _last_sort_criteria[type];
  1039 	bv->descending_sort_order = _last_sort_order[type];
  1053 	bv->descending_sort_order = _last_sort_order[type];
  1040 
  1054 
  1041 	switch (type) {
  1055 	switch (type) {
       
  1056 		default: NOT_REACHED();
  1042 		case VEH_TRAIN:
  1057 		case VEH_TRAIN:
  1043 			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
  1058 			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
  1044 			ResizeWindow(w, 0, 16);
  1059 			ResizeWindow(w, 0, 16);
  1045 			break;
  1060 			break;
  1046 		case VEH_ROAD:
  1061 		case VEH_ROAD: