Changeset - r12477:069be9651c2d
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-07-23 08:47:14
rubidium@openttd.org
(svn r16924) -Fix (r16922): selling or sending to depot, what's the difference? :)
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/vehicle_cmd.cpp
Show inline comments
 
@@ -127,97 +127,97 @@ CommandCost CmdMassStartStopVehicle(Tile
 
	if (vehicle_list_window) {
 
		uint32 id = p1;
 
		uint16 window_type = p2 & VLW_MASK;
 

	
 
		GenerateVehicleSortList(&list, vehicle_type, _current_company, id, window_type);
 
	} else {
 
		/* Get the list of vehicles in the depot */
 
		BuildDepotVehicleList(vehicle_type, tile, &list, NULL);
 
	}
 

	
 
	for (uint i = 0; i < list.Length(); i++) {
 
		const Vehicle *v = list[i];
 

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

	
 
		if (!vehicle_list_window) {
 
			if (vehicle_type == VEH_TRAIN) {
 
				if (CheckTrainInDepot(Train::From(v), false) == -1) continue;
 
			} else {
 
				if (!(v->vehstatus & VS_HIDDEN)) continue;
 
			}
 
		}
 

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

	
 
		if (CmdSucceeded(ret)) {
 
			return_value = CommandCost();
 
			/* We know that the command is valid for at least one vehicle.
 
			 * If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */
 
			if (!(flags & DC_EXEC)) break;
 
		}
 
	}
 

	
 
	return return_value;
 
}
 

	
 
/** Sells all vehicles in a depot
 
 * @param tile Tile of the depot where the depot is
 
 * @param flags type of operation
 
 * @param p1 Vehicle type
 
 * @param p2 unused
 
 */
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 

	
 
	CommandCost cost(EXPENSES_NEW_VEHICLES);
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
	uint sell_command = GetCmdSendToDepot(vehicle_type);;
 
	uint sell_command = GetCmdSellVeh(vehicle_type);;
 

	
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list);
 

	
 
	for (uint i = 0; i < list.Length(); i++) {
 
		CommandCost ret = DoCommand(tile, list[i]->index, 1, flags, sell_command);
 
		if (CmdSucceeded(ret)) cost.AddCost(ret);
 
	}
 

	
 
	if (cost.GetCost() == 0) return CMD_ERROR; // no vehicles to sell
 
	return cost;
 
}
 

	
 
/** Autoreplace all vehicles in the depot
 
 * Note: this command can make incorrect cost estimations
 
 * Luckily the final price can only drop, not increase. This is due to the fact that
 
 * estimation can't predict wagon removal so it presumes worst case which is no income from selling wagons.
 
 * @param tile Tile of the depot where the vehicles are
 
 * @param flags type of operation
 
 * @param p1 Type of vehicle
 
 * @param p2 If bit 0 is set, then either replace all or nothing (instead of replacing until money runs out)
 
 */
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES);
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
	bool all_or_nothing = HasBit(p2, 0);
 

	
 
	if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
 

	
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list, true);
 

	
 
	bool did_something = false;
 

	
 
	for (uint i = 0; i < list.Length(); i++) {
 
		const Vehicle *v = list[i];
 

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

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

	
 
		if (CmdSucceeded(ret)) {
 
			did_something = true;
 
			cost.AddCost(ret);
 
		} else {
0 comments (0 inline, 0 general)