src/vehicle.cpp
changeset 9353 9d76aef9fe2b
parent 9351 ecf2fdeb2328
child 9354 845e07db4549
equal deleted inserted replaced
9352:8979e416b2e9 9353:9d76aef9fe2b
  1460  * @param vlw_flag tells what kind of list requested the goto depot
  1460  * @param vlw_flag tells what kind of list requested the goto depot
  1461  * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
  1461  * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
  1462  */
  1462  */
  1463 CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id)
  1463 CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id)
  1464 {
  1464 {
  1465 	const Vehicle **sort_list = NULL;
  1465 	VehicleList list;
  1466 	uint16 array_length = 0;
  1466 
  1467 
  1467 	GenerateVehicleSortList(&list, type, owner, id, vlw_flag);
  1468 	uint n = GenerateVehicleSortList(&sort_list, &array_length, type, owner, id, vlw_flag);
       
  1469 
  1468 
  1470 	/* Send all the vehicles to a depot */
  1469 	/* Send all the vehicles to a depot */
  1471 	for (uint i = 0; i < n; i++) {
  1470 	for (uint i = 0; i < list.Length(); i++) {
  1472 		const Vehicle *v = sort_list[i];
  1471 		const Vehicle *v = list[i];
  1473 		CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type));
  1472 		CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type));
  1474 
  1473 
  1475 		/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
  1474 		/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
  1476 			* In this case we know that at least one vehicle can be sent to a depot
  1475 			* In this case we know that at least one vehicle can be sent to a depot
  1477 			* and we will issue the command. We can now safely quit the loop, knowing
  1476 			* and we will issue the command. We can now safely quit the loop, knowing
  1478 			* it will succeed at least once. With DC_EXEC we really need to send them to the depot */
  1477 			* it will succeed at least once. With DC_EXEC we really need to send them to the depot */
  1479 		if (CmdSucceeded(ret) && !(flags & DC_EXEC)) {
  1478 		if (CmdSucceeded(ret) && !(flags & DC_EXEC)) {
  1480 			free((void*)sort_list);
       
  1481 			return CommandCost();
  1479 			return CommandCost();
  1482 		}
  1480 		}
  1483 	}
  1481 	}
  1484 
  1482 
  1485 	free((void*)sort_list);
       
  1486 	return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR;
  1483 	return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR;
  1487 }
  1484 }
  1488 
  1485 
  1489 /**
  1486 /**
  1490  * Calculates how full a vehicle is.
  1487  * Calculates how full a vehicle is.