704 * @param engine_type Which engine to refit |
704 * @param engine_type Which engine to refit |
705 * @return Price for refitting |
705 * @return Price for refitting |
706 */ |
706 */ |
707 CommandCost GetRefitCost(EngineID engine_type) |
707 CommandCost GetRefitCost(EngineID engine_type) |
708 { |
708 { |
709 CommandCost base_cost; |
709 Money base_cost; |
710 |
710 ExpensesType expense_type; |
711 switch (GetEngine(engine_type)->type) { |
711 switch (GetEngine(engine_type)->type) { |
712 case VEH_SHIP: base_cost.AddCost(_price.ship_base); break; |
712 case VEH_SHIP: |
713 case VEH_ROAD: base_cost.AddCost(_price.roadveh_base); break; |
713 base_cost = _price.ship_base; |
714 case VEH_AIRCRAFT: base_cost.AddCost(_price.aircraft_base); break; |
714 expense_type = EXPENSES_SHIP_RUN; |
|
715 break; |
|
716 |
|
717 case VEH_ROAD: |
|
718 base_cost = _price.roadveh_base; |
|
719 expense_type = EXPENSES_ROADVEH_RUN; |
|
720 break; |
|
721 |
|
722 case VEH_AIRCRAFT: |
|
723 base_cost = _price.aircraft_base; |
|
724 expense_type = EXPENSES_AIRCRAFT_RUN; |
|
725 break; |
|
726 |
715 case VEH_TRAIN: |
727 case VEH_TRAIN: |
716 base_cost.AddCost(2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ? |
728 base_cost = 2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ? |
717 _price.build_railwagon : _price.build_railvehicle)); |
729 _price.build_railwagon : _price.build_railvehicle); |
|
730 expense_type = EXPENSES_TRAIN_RUN; |
718 break; |
731 break; |
719 default: NOT_REACHED(); break; |
732 |
720 } |
733 default: NOT_REACHED(); |
721 return CommandCost((EngInfo(engine_type)->refit_cost * base_cost.GetCost()) >> 10); |
734 } |
|
735 return CommandCost(expense_type, (EngInfo(engine_type)->refit_cost * base_cost) >> 10); |
722 } |
736 } |
723 |
737 |
724 static void DoDrawVehicle(const Vehicle *v) |
738 static void DoDrawVehicle(const Vehicle *v) |
725 { |
739 { |
726 SpriteID image = v->cur_image; |
740 SpriteID image = v->cur_image; |
1695 /* There is a problem with autoreplace and newgrf |
1709 /* There is a problem with autoreplace and newgrf |
1696 * It's impossible to tell the length of a train after it's being replaced before it's actually done |
1710 * It's impossible to tell the length of a train after it's being replaced before it's actually done |
1697 * Because of this, we can't estimate costs due to wagon removal and we will have to always return 0 and pay manually |
1711 * Because of this, we can't estimate costs due to wagon removal and we will have to always return 0 and pay manually |
1698 * Since we pay after each vehicle is replaced and MaybeReplaceVehicle() check if the player got enough money |
1712 * Since we pay after each vehicle is replaced and MaybeReplaceVehicle() check if the player got enough money |
1699 * we should never reach a condition where the player will end up with negative money from doing this */ |
1713 * we should never reach a condition where the player will end up with negative money from doing this */ |
1700 SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
|
1701 SubtractMoneyFromPlayer(ret); |
1714 SubtractMoneyFromPlayer(ret); |
1702 } |
1715 } |
1703 } |
1716 } |
1704 |
1717 |
1705 if (cost.GetCost() == 0) { |
1718 if (cost.GetCost() == 0) { |
1724 */ |
1737 */ |
1725 CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1738 CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1726 { |
1739 { |
1727 Vehicle *v_front, *v; |
1740 Vehicle *v_front, *v; |
1728 Vehicle *w_front, *w, *w_rear; |
1741 Vehicle *w_front, *w, *w_rear; |
1729 CommandCost cost, total_cost; |
1742 CommandCost cost, total_cost(EXPENSES_NEW_VEHICLES); |
1730 uint32 build_argument = 2; |
1743 uint32 build_argument = 2; |
1731 |
1744 |
1732 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1745 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1733 v = GetVehicle(p1); |
1746 v = GetVehicle(p1); |
1734 v_front = v; |
1747 v_front = v; |
1878 DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
1891 DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
1879 } |
1892 } |
1880 return CMD_ERROR; |
1893 return CMD_ERROR; |
1881 } |
1894 } |
1882 |
1895 |
1883 /* Set the expense type last as refitting will make the cost go towards |
|
1884 * running costs... */ |
|
1885 SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
|
1886 return total_cost; |
1896 return total_cost; |
1887 } |
1897 } |
1888 |
1898 |
1889 |
1899 |
1890 /* Extend the list size for BuildDepotVehicleList() */ |
1900 /* Extend the list size for BuildDepotVehicleList() */ |
3103 } |
3113 } |
3104 |
3114 |
3105 current_order.type = OT_LOADING; |
3115 current_order.type = OT_LOADING; |
3106 GetStation(this->last_station_visited)->loading_vehicles.push_back(this); |
3116 GetStation(this->last_station_visited)->loading_vehicles.push_back(this); |
3107 |
3117 |
3108 SET_EXPENSES_TYPE(this->GetExpenseType(true)); |
|
3109 VehiclePayment(this); |
3118 VehiclePayment(this); |
3110 |
3119 |
3111 InvalidateWindow(this->GetVehicleListWindowClass(), this->owner); |
3120 InvalidateWindow(this->GetVehicleListWindowClass(), this->owner); |
3112 InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR); |
3121 InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR); |
3113 InvalidateWindow(WC_VEHICLE_DETAILS, this->index); |
3122 InvalidateWindow(WC_VEHICLE_DETAILS, this->index); |