diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 4ff0510889..a0dfd086f0 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -599,10 +599,6 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon if ((flags & DC_EXEC) != 0) TransferCargo(w, new_head, true); - /* Sell the vehicle. - * Note: This might temporarily construct new trains, so use DC_AUTOREPLACE to prevent - * it from failing due to engine limits. */ - cost.AddCost(DoCommand(0, w->index, 0, flags | DC_AUTOREPLACE, GetCmdSellVeh(w))); if ((flags & DC_EXEC) != 0) { old_vehs[i] = nullptr; if (i == 0) { @@ -610,6 +606,10 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon old_head = nullptr; } } + /* Sell the vehicle. + * Note: This might temporarily construct new trains, so use DC_AUTOREPLACE to prevent + * it from failing due to engine limits. */ + cost.AddCost(DoCommand(0, w->index, 0, flags | DC_AUTOREPLACE, GetCmdSellVeh(w))); } if ((flags & DC_EXEC) != 0) CheckCargoCapacity(new_head);