File diff r26089:2283e9229bb0 → r26090:5a592dbf1c28
src/vehicle_cmd.cpp
Show inline comments
 
@@ -179,13 +179,13 @@ CommandCost CmdBuildVehicle(TileIndex ti
 
			}
 
		}
 

	
 

	
 
		/* If we are not in DC_EXEC undo everything */
 
		if (flags != subflags) {
 
			DoCommand(0, v->index, 0, DC_EXEC, GetCmdSellVeh(v));
 
			DoCommand(DC_EXEC, GetCmdSellVeh(v), 0, v->index, 0);
 
		}
 
	}
 

	
 
	/* Only restore if we actually did some refitting */
 
	if (flags != subflags) RestoreRandomSeeds(saved_seeds);
 

	
 
@@ -662,13 +662,13 @@ CommandCost CmdMassStartStopVehicle(Tile
 

	
 
		if (!!(v->vehstatus & VS_STOPPED) != do_start) continue;
 

	
 
		if (!vehicle_list_window && !v->IsChainInDepot()) continue;
 

	
 
		/* Just try and don't care if some vehicle's can't be stopped. */
 
		DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE);
 
		DoCommand(flags, CMD_START_STOP_VEHICLE, tile, v->index, 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
@@ -694,13 +694,13 @@ CommandCost CmdDepotSellAllVehicles(Tile
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list);
 

	
 
	CommandCost last_error = CMD_ERROR;
 
	bool had_success = false;
 
	for (uint i = 0; i < list.size(); i++) {
 
		CommandCost ret = DoCommand(tile, list[i]->index | (1 << 20), 0, flags, sell_command);
 
		CommandCost ret = DoCommand(flags, sell_command, tile, list[i]->index | (1 << 20), 0);
 
		if (ret.Succeeded()) {
 
			cost.AddCost(ret);
 
			had_success = true;
 
		} else {
 
			last_error = ret;
 
		}
 
@@ -733,13 +733,13 @@ CommandCost CmdDepotMassAutoReplace(Tile
 
	for (uint i = 0; i < list.size(); i++) {
 
		const Vehicle *v = list[i];
 

	
 
		/* Ensure that the vehicle completely in the depot */
 
		if (!v->IsChainInDepot()) continue;
 

	
 
		CommandCost ret = DoCommand(0, v->index, 0, flags, CMD_AUTOREPLACE_VEHICLE);
 
		CommandCost ret = DoCommand(flags, CMD_AUTOREPLACE_VEHICLE, 0, v->index, 0);
 

	
 
		if (ret.Succeeded()) cost.AddCost(ret);
 
	}
 
	return cost;
 
}
 

	
 
@@ -872,17 +872,17 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
		 * 'new' vehicles whereas they would immediately be joined with a primary
 
		 * engine. This caused the vehicle to be not build as 'the limit' had been
 
		 * reached, resulting in partially build vehicles and such. */
 
		DoCommandFlag build_flags = flags;
 
		if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
 

	
 
		CommandCost cost = DoCommand(tile, v->engine_type | (1 << 16) | (CT_INVALID << 24), 0, build_flags, GetCmdBuildVeh(v));
 
		CommandCost cost = DoCommand(build_flags, GetCmdBuildVeh(v), tile, v->engine_type | (1 << 16) | (CT_INVALID << 24), 0);
 

	
 
		if (cost.Failed()) {
 
			/* Can't build a part, then sell the stuff we already made; clear up the mess */
 
			if (w_front != nullptr) DoCommand(w_front->tile, w_front->index | (1 << 20), 0, flags, GetCmdSellVeh(w_front));
 
			if (w_front != nullptr) DoCommand(flags, GetCmdSellVeh(w_front), w_front->tile, w_front->index | (1 << 20), 0);
 
			return cost;
 
		}
 

	
 
		total_cost.AddCost(cost);
 

	
 
		if (flags & DC_EXEC) {
 
@@ -892,18 +892,18 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
				SetBit(Train::From(w)->flags, VRF_REVERSE_DIRECTION);
 
			}
 

	
 
			if (v->type == VEH_TRAIN && !v->IsFrontEngine()) {
 
				/* this s a train car
 
				 * add this unit to the end of the train */
 
				CommandCost result = DoCommand(0, w->index | 1 << 20, w_rear->index, flags, CMD_MOVE_RAIL_VEHICLE);
 
				CommandCost result = DoCommand(flags, CMD_MOVE_RAIL_VEHICLE, 0, w->index | 1 << 20, w_rear->index);
 
				if (result.Failed()) {
 
					/* The train can't be joined to make the same consist as the original.
 
					 * Sell what we already made (clean up) and return an error.           */
 
					DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
 
					DoCommand(w_front->tile, w->index       | 1 << 20, 0, flags, GetCmdSellVeh(w));
 
					DoCommand(flags, GetCmdSellVeh(w_front), w_front->tile, w_front->index | 1 << 20, 0);
 
					DoCommand(flags, GetCmdSellVeh(w)      , w_front->tile, w->index       | 1 << 20, 0);
 
					return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
 
				}
 
			} else {
 
				/* this is a front engine or not a train. */
 
				w_front = w;
 
				w->service_interval = v->service_interval;
 
@@ -918,13 +918,13 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
		/* for trains this needs to be the front engine due to the callback function */
 
		_new_vehicle_id = w_front->index;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Cloned vehicles belong to the same group */
 
		DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP);
 
		DoCommand(flags, CMD_ADD_VEHICLE_GROUP, 0, v_front->group_id, w_front->index);
 
	}
 

	
 

	
 
	/* Take care of refitting. */
 
	w = w_front;
 
	v = v_front;
 
@@ -940,13 +940,13 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
			if (flags & DC_EXEC) {
 
				assert(w != nullptr);
 

	
 
				/* Find out what's the best sub type */
 
				byte subtype = GetBestFittingSubType(v, w, v->cargo_type);
 
				if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
 
					CommandCost cost = DoCommand(0, w->index, v->cargo_type | 1U << 25 | (subtype << 8), flags, GetCmdRefitVeh(v));
 
					CommandCost cost = DoCommand(flags, GetCmdRefitVeh(v), 0, w->index, v->cargo_type | 1U << 25 | (subtype << 8));
 
					if (cost.Succeeded()) total_cost.AddCost(cost);
 
				}
 

	
 
				if (w->IsGroundVehicle() && w->HasArticulatedPart()) {
 
					w = w->GetNextArticulatedPart();
 
				} else {
 
@@ -975,27 +975,27 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
	if (flags & DC_EXEC) {
 
		/*
 
		 * Set the orders of the vehicle. Cannot do it earlier as we need
 
		 * the vehicle refitted before doing this, otherwise the moved
 
		 * cargo types might not match (passenger vs non-passenger)
 
		 */
 
		CommandCost result = DoCommand(0, w_front->index | (p2 & 1 ? CO_SHARE : CO_COPY) << 30, v_front->index, flags, CMD_CLONE_ORDER);
 
		CommandCost result = DoCommand(flags, CMD_CLONE_ORDER, 0, w_front->index | (p2 & 1 ? CO_SHARE : CO_COPY) << 30, v_front->index);
 
		if (result.Failed()) {
 
			/* The vehicle has already been bought, so now it must be sold again. */
 
			DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
 
			DoCommand(flags, GetCmdSellVeh(w_front), w_front->tile, w_front->index | 1 << 20, 0);
 
			return result;
 
		}
 

	
 
		/* Now clone the vehicle's name, if it has one. */
 
		if (!v_front->name.empty()) CloneVehicleName(v_front, w_front);
 

	
 
		/* Since we can't estimate the cost of cloning a vehicle accurately we must
 
		 * check whether the company has enough money manually. */
 
		if (!CheckCompanyHasMoney(total_cost)) {
 
			/* The vehicle has already been bought, so now it must be sold again. */
 
			DoCommand(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
 
			DoCommand(flags, GetCmdSellVeh(w_front), w_front->tile, w_front->index | 1 << 20, 0);
 
			return total_cost;
 
		}
 
	}
 

	
 
	return total_cost;
 
}
 
@@ -1014,13 +1014,13 @@ static CommandCost SendAllVehiclesToDepo
 
	if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
 

	
 
	/* Send all the vehicles to a depot */
 
	bool had_success = false;
 
	for (uint i = 0; i < list.size(); i++) {
 
		const Vehicle *v = list[i];
 
		CommandCost ret = DoCommand(v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, flags, GetCmdSendToDepot(vli.vtype));
 
		CommandCost ret = DoCommand(flags, GetCmdSendToDepot(vli.vtype), v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0);
 

	
 
		if (ret.Succeeded()) {
 
			had_success = true;
 

	
 
			/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
 
			 * In this case we know that at least one vehicle can be sent to a depot