From 5dec903d5cf15e76c2eeed41add357d49e591f71 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 20 Mar 2010 17:10:14 +0000 Subject: [PATCH] (svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot(). --- src/vehicle_cmd.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 974b83bab8..d42467c92b 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -586,20 +586,23 @@ CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool s GenerateVehicleSortList(&list, type, owner, id, vlw_flag); /* Send all the vehicles to a depot */ + bool had_success = false; for (uint i = 0; i < list.Length(); i++) { const Vehicle *v = list[i]; CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type)); - /* 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 - * and we will issue the command. We can now safely quit the loop, knowing - * it will succeed at least once. With DC_EXEC we really need to send them to the depot */ - if (ret.Succeeded() && !(flags & DC_EXEC)) { - return CommandCost(); + 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 + * and we will issue the command. We can now safely quit the loop, knowing + * it will succeed at least once. With DC_EXEC we really need to send them to the depot */ + if (!(flags & DC_EXEC)) break; } } - return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR; + return had_success ? CommandCost() : CMD_ERROR; } /** Give a custom name to your vehicle