summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-08-30 23:01:45 +0000
committerbjarni <bjarni@openttd.org>2006-08-30 23:01:45 +0000
commit7922c9ff8496db84a24a62665437389fdaade34a (patch)
tree6a3d86da825371df4091d7d15c07bafed940be72 /vehicle.c
parentf91fce66cb78e5ab67e77a47c72242c0048e6514 (diff)
downloadopenttd-7922c9ff8496db84a24a62665437389fdaade34a.tar.xz
(svn r6249) -Fix: fixed assert when pressing goto depot in an empty list (forgot to disable the button in this condition)
-Code cleanup r6246: simplified SendAllVehiclesToDepot() and moved an { in PlayerVehWndProc()
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/vehicle.c b/vehicle.c
index 0913c701c..38fae976e 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1908,31 +1908,22 @@ static void MaybeReplaceVehicle(Vehicle *v)
int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner)
{
const uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
- if (flags & DC_EXEC) {
+ const Vehicle *v;
+
/* Send all the vehicles to a depot */
- const Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == type && v->owner == owner && (
- (type == VEH_Train && IsFrontEngine(v)) ||
- (type != VEH_Train && v->subtype <= subtype))) {
- DoCommand(v->tile, v->index, service, flags, CMD_SEND_TO_DEPOT(type));
- }
- }
- } else {
- /* See if we can find a vehicle to send to a depot */
- const Vehicle *v;
- FOR_ALL_VEHICLES(v) {
- if (v->type == type && v->owner == owner && (
- (type == VEH_Train && IsFrontEngine(v)) ||
- (type != VEH_Train && v->subtype <= subtype))) {
- /* We found one vehicle to send to a depot. No need to search for more. The command is valid */
- if (!DoCommand(v->tile, v->index, service, flags, CMD_SEND_TO_DEPOT(type))) return 0;
- }
+ FOR_ALL_VEHICLES(v) {
+ if (v->type == type && v->owner == owner && (
+ (type == VEH_Train && IsFrontEngine(v)) ||
+ (type != VEH_Train && v->subtype <= subtype))) {
+ /* Return 0 if DC_EXEC is not set and a DoCommand() returns 0 (valid goto depot command) */
+ /* In this case we know that at least one vehicle can be send to a depot and we will issue the command */
+ /* Since we will issue the command nomatter how many vehicles more than one it's valid for, we skip checking the rest */
+ /* When DC_EXEC is set, we need to run this loop for all vehicles nomatter return values from each vehicle */
+ if (!DoCommand(v->tile, v->index, service, flags, CMD_SEND_TO_DEPOT(type)) && !(flags & DC_EXEC)) return 0;
}
-
- return CMD_ERROR;
}
- return 0;
+
+ return (flags & DC_EXEC) ? 0 : CMD_ERROR;
}