Changeset - r28825:9fe6b1220bd7
[Not reviewed]
master
0 1 0
Peter Nelson - 9 months ago 2024-02-27 18:18:57
peter1138@openttd.org
Codechange: Use range-for instead of indexed loop. (#12191)
1 file changed with 4 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/vehicle_cmd.cpp
Show inline comments
 
@@ -661,27 +661,25 @@ CommandCost CmdMassStartStopVehicle(DoCo
 

	
 
	if (!vli.Valid()) return CMD_ERROR;
 
	if (!IsCompanyBuildableVehicleType(vli.vtype)) return CMD_ERROR;
 

	
 
	if (vehicle_list_window) {
 
		if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
 
	} else {
 
		if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
 
		/* Get the list of vehicles in the depot */
 
		BuildDepotVehicleList(vli.vtype, tile, &list, nullptr);
 
	}
 

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

	
 
	for (const Vehicle *v : list) {
 
		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. */
 
		Command<CMD_START_STOP_VEHICLE>::Do(flags, v->index, false);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
@@ -696,26 +694,26 @@ CommandCost CmdDepotSellAllVehicles(DoCo
 
	VehicleList list;
 

	
 
	CommandCost cost(EXPENSES_NEW_VEHICLES);
 

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

	
 
	/* 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 = Command<CMD_SELL_VEHICLE>::Do(flags, list[i]->index, true, false, INVALID_CLIENT_ID);
 
	for (const Vehicle *v : list) {
 
		CommandCost ret = Command<CMD_SELL_VEHICLE>::Do(flags, v->index, true, false, INVALID_CLIENT_ID);
 
		if (ret.Succeeded()) {
 
			cost.AddCost(ret);
 
			had_success = true;
 
		} else {
 
			last_error = ret;
 
		}
 
	}
 

	
 
	return had_success ? cost : last_error;
 
}
 

	
 
/**
 
@@ -727,27 +725,25 @@ CommandCost CmdDepotSellAllVehicles(DoCo
 
 */
 
CommandCost CmdDepotMassAutoReplace(DoCommandFlag flags, TileIndex tile, VehicleType vehicle_type)
 
{
 
	VehicleList list;
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES);
 

	
 
	if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
 
	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);
 

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

	
 
	for (const Vehicle *v : list) {
 
		/* Ensure that the vehicle completely in the depot */
 
		if (!v->IsChainInDepot()) continue;
 

	
 
		CommandCost ret = Command<CMD_AUTOREPLACE_VEHICLE>::Do(flags, v->index);
 

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

	
 
/**
 
 * Test if a name is unique among vehicle names.
0 comments (0 inline, 0 general)