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; |
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 } |
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); |
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 |
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 } |