From 5059054f0a86ac7a6b31a9fd823e6c70f6cdcdf1 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 25 Jun 2022 20:33:21 +0100 Subject: [PATCH] Sending a vehicle to a depot for sale can now sell immediately If the vehicle is already stopped in a suitable depot --- src/vehicle.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index b1ea521057..90d7fa0f60 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3614,7 +3614,29 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command, Tile if (ret.Failed()) return ret; if (this->vehstatus & VS_CRASHED) return CMD_ERROR; - if (this->IsStoppedInDepot()) return CMD_ERROR; + if (this->IsStoppedInDepot()) { + if ((command & DEPOT_SELL) && !(command & DEPOT_CANCEL) && (!(command & DEPOT_SPECIFIC) || specific_depot == this->tile)) { + /* Sell vehicle immediately */ + + if (flags & DC_EXEC) { + int x = this->x_pos; + int y = this->y_pos; + int z = this->z_pos; + + CommandCost cost = DoCommand(this->tile, this->index | (1 << 20), 0, flags, CMD_SELL_VEHICLE); + if (cost.Succeeded()) { + if (IsLocalCompany()) { + if (cost.GetCost() != 0) { + ShowCostOrIncomeAnimation(x, y, z, cost.GetCost()); + } + } + SubtractMoneyFromCompany(cost); + } + } + return CommandCost(); + } + return CMD_ERROR; + } auto cancel_order = [&]() { if (flags & DC_EXEC) {