MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdSellVehicle

Function CmdSellVehicle

src/vehicle_cmd.cpp:236–262  ·  view source on GitHub ↗

* Sell a vehicle. * @param flags for command. * @param v_id vehicle ID being sold. * @param sell_chain sell the vehicle and all vehicles following it in the chain. * @param backup_order make a backup of the vehicle's order (if an engine). * @param client_id User. * @return the cost of this operation or an error. */

Source from the content-addressed store, hash-verified

234 * @return the cost of this operation or an error.
235 */
236CommandCost CmdSellVehicle(DoCommandFlags flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id)
237{
238 Vehicle *v = Vehicle::GetIfValid(v_id);
239 if (v == nullptr) return CMD_ERROR;
240
241 Vehicle *front = v->First();
242
243 CommandCost ret = CheckOwnership(front->owner);
244 if (ret.Failed()) return ret;
245
246 if (front->vehstatus.Test(VehState::Crashed)) return CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED);
247
248 if (!front->IsStoppedInDepot()) return CommandCost(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
249
250 if (v->type == VEH_TRAIN) {
251 ret = CmdSellRailWagon(flags, v, sell_chain, backup_order, client_id);
252 } else {
253 ret = CommandCost(EXPENSES_NEW_VEHICLES, -front->value);
254
255 if (flags.Test(DoCommandFlag::Execute)) {
256 if (front->IsPrimaryVehicle() && backup_order) OrderBackup::Backup(front, client_id);
257 delete front;
258 }
259 }
260
261 return ret;
262}
263
264/**
265 * Helper to run the refit cost callback.

Callers

nothing calls this directly

Calls 9

CheckOwnershipFunction · 0.85
CommandCostClass · 0.85
CmdSellRailWagonFunction · 0.85
BackupClass · 0.85
FailedMethod · 0.80
TestMethod · 0.80
FirstMethod · 0.45
IsStoppedInDepotMethod · 0.45
IsPrimaryVehicleMethod · 0.45

Tested by

no test coverage detected