(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
authorrubidium
Mon, 18 Jun 2007 16:42:40 +0000
changeset 7442 a4f7989f27d4
parent 7441 4a0c19a92aa9
child 7443 b8c8a0d029fd
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
src/ai/default/default.cpp
src/ai/trolly/build.cpp
src/ai/trolly/pathfinder.cpp
src/ai/trolly/trolly.cpp
src/command.h
src/misc_gui.cpp
src/rail_cmd.cpp
src/road_cmd.cpp
src/station_cmd.cpp
src/town_cmd.cpp
src/vehicle.cpp
src/vehicle_gui.cpp
src/water_cmd.cpp
--- a/src/ai/default/default.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/ai/default/default.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -152,7 +152,7 @@
 		}
 
 		ret = DoCommand(tile, i, 0, 0, CMD_BUILD_RAIL_VEHICLE);
-		if (!CmdFailed(ret) && ret <= money && rvi->ai_rank >= best_veh_score) {
+		if (CmdSucceeded(ret) && ret <= money && rvi->ai_rank >= best_veh_score) {
 			best_veh_score = rvi->ai_rank;
 			best_veh_index = i;
 		}
@@ -216,7 +216,7 @@
 		if ((AircraftVehInfo(i)->subtype & AIR_CTOL) != flag) continue;
 
 		ret = DoCommand(0, i, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT);
-		if (!CmdFailed(ret) && ret <= money && ret >= best_veh_cost) {
+		if (CmdSucceeded(ret) && ret <= money && ret >= best_veh_cost) {
 			best_veh_cost = ret;
 			best_veh_index = i;
 		}
@@ -331,8 +331,8 @@
 		BackupVehicleOrders(v, orderbak);
 		tile = v->tile;
 
-		if (!CmdFailed(DoCommand(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON)) &&
-				!CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE))) {
+		if (CmdSucceeded(DoCommand(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON)) &&
+				CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE))) {
 			VehicleID veh = _new_vehicle_id;
 			AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
 			DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_TRAIN);
@@ -360,8 +360,8 @@
 		BackupVehicleOrders(v, orderbak);
 		tile = v->tile;
 
-		if (!CmdFailed(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH)) &&
-				!CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) {
+		if (CmdSucceeded(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH)) &&
+				CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) {
 			VehicleID veh = _new_vehicle_id;
 
 			AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
@@ -389,8 +389,8 @@
 		BackupVehicleOrders(v, orderbak);
 		tile = v->tile;
 
-		if (!CmdFailed(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT)) &&
-				!CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) {
+		if (CmdSucceeded(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT)) &&
+				CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) {
 			VehicleID veh = _new_vehicle_id;
 			AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
 			DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_AIRCRAFT);
@@ -1743,7 +1743,7 @@
 		if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 &&
 				(p->dir == 0xFF || p->dir == dir || ((p->dir - 1) & 3) == dir)) {
 			*cost = AiDoBuildDefaultRailTrack(tile, p->data, railtype, DC_NO_TOWN_RATING);
-			if (!CmdFailed(*cost) && AiCheckTrackResources(tile, p->data, cargo))
+			if (CmdSucceeded(*cost) && AiCheckTrackResources(tile, p->data, cargo))
 				return i;
 		}
 	}
@@ -2069,7 +2069,7 @@
 	if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
 		CommandCost cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 
-		if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
+		if (CmdSucceeded(cost) && cost <= (arf->player->player_money >> 4)) {
 			AiBuildRailRecursive(arf, _build_tunnel_endtile, p[0] & 3);
 			if (arf->depth == 1) AiCheckRailPathBetter(arf, p);
 		}
@@ -2123,7 +2123,7 @@
 		do {
 			// Make sure the tile is not in the list of banned tiles and that a rail can be built here.
 			if (!AiIsTileBanned(arf->player, tile, p[0]) &&
-					!CmdFailed(DoCommand(tile, arf->player->ai.railtype_to_use, p[0], DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL))) {
+					CmdSucceeded(DoCommand(tile, arf->player->ai.railtype_to_use, p[0], DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL))) {
 				AiBuildRailRecursive(arf, tile, p[1]);
 			}
 
@@ -2211,7 +2211,7 @@
 		for (i = MAX_BRIDGES - 1; i != 0; i--) {
 			if (CheckBridge_Stuff(i, bridge_len)) {
 				int32 cost = DoCommand(arf.bridge_end_tile, p->ai.cur_tile_a, i | (p->ai.railtype_to_use << 8), DC_AUTO, CMD_BUILD_BRIDGE);
-				if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
+				if (CmdSucceeded(cost) && cost < (p->player_money >> 5)) break;
 			}
 		}
 
@@ -2500,7 +2500,7 @@
 		if (++p->ai.state_counter == 1000) {
 			for (i = 0; p->ai.wagon_list[i] != INVALID_VEHICLE; i++) {
 				cost = DoCommand(tile, p->ai.wagon_list[i], 0, DC_EXEC, CMD_SELL_RAIL_WAGON);
-				assert(!CmdFailed(cost));
+				assert(CmdSucceeded(cost));
 			}
 			p->ai.state = AIS_0;
 		}
@@ -2509,7 +2509,7 @@
 
 	// Try to build the locomotive
 	cost = DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE);
-	assert(!CmdFailed(cost));
+	assert(CmdSucceeded(cost));
 	loco_id = _new_vehicle_id;
 
 	// Sell a vehicle if the train is double headed.
@@ -2618,7 +2618,7 @@
 	for (i = 0; (p = _road_default_block_data[i]) != NULL; i++) {
 		if (p->dir == direction) {
 			*cost = AiDoBuildDefaultRoadBlock(tile, p->data, 0);
-			if (!CmdFailed(*cost) && AiCheckRoadResources(tile, p->data, cargo))
+			if (CmdSucceeded(*cost) && AiCheckRoadResources(tile, p->data, cargo))
 				return i;
 		}
 	}
@@ -2768,7 +2768,7 @@
 					_road_default_block_data[rule]->data,
 					DC_EXEC | DC_NO_TOWN_RATING
 				);
-				assert(!CmdFailed(r));
+				assert(CmdSucceeded(r));
 			}
 		} while (++aib, --j);
 	}
@@ -2916,7 +2916,7 @@
 		ROAD_NW | ROAD_SW,
 		ROAD_SE | ROAD_NE
 	};
-	return !CmdFailed(DoCommand(tile, _road_bits[type], 0, flags, CMD_BUILD_ROAD));
+	return CmdSucceeded(DoCommand(tile, _road_bits[type], 0, flags, CMD_BUILD_ROAD));
 }
 
 static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
@@ -2969,7 +2969,7 @@
 	if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
 		CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 
-		if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
+		if (CmdSucceeded(cost) && cost <= (arf->player->player_money >> 4)) {
 			AiBuildRoadRecursive(arf, _build_tunnel_endtile, p[0] & 3);
 			if (arf->depth == 1)  AiCheckRoadPathBetter(arf, p);
 		}
@@ -3102,7 +3102,7 @@
 		for (i = 10; i != 0; i--) {
 			if (CheckBridge_Stuff(i, bridge_len)) {
 				CommandCost cost = DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE);
-				if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
+				if (CmdSucceeded(cost) && cost < (p->player_money >> 5)) break;
 			}
 		}
 
@@ -3435,7 +3435,7 @@
 		if (heli && !(GetAirport(p->attr)->flags & AirportFTAClass::HELICOPTERS)) continue;
 
 		*cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
-		if (!CmdFailed(*cost) && AiCheckAirportResources(tile, p, cargo))
+		if (CmdSucceeded(*cost) && AiCheckAirportResources(tile, p, cargo))
 			return i;
 	}
 	return -1;
@@ -3494,7 +3494,7 @@
 					_airport_default_block_data[rule],
 					DC_EXEC | DC_NO_TOWN_RATING
 				);
-				assert(!CmdFailed(r));
+				assert(CmdSucceeded(r));
 			}
 		} while (++aib, --j);
 	} while (--i);
--- a/src/ai/trolly/build.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/ai/trolly/build.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -206,7 +206,7 @@
 						return 0;
 					}
 
-					if (!CmdFailed(res)) cost += res;
+					if (CmdSucceeded(res)) cost += res;
 				}
 				// Go to the next tile
 				part++;
--- a/src/ai/trolly/pathfinder.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/ai/trolly/pathfinder.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -28,13 +28,13 @@
 		//  should be fixed!!!
 		for (dir = 0; dir < 4; dir++) {
 			ret = AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST);
-			if (!CmdFailed(ret)) return true;
+			if (CmdSucceeded(ret)) return true;
 		}
 		return false;
 	}
 
 	// return true if command succeeded, so the inverse of CmdFailed()
-	return !CmdFailed(AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST));
+	return CmdSucceeded(AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST));
 }
 
 
@@ -352,7 +352,7 @@
 			// Now simply check if a tunnel can be build
 			ret = AI_DoCommand(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL);
 			tileh = GetTileSlope(_build_tunnel_endtile, NULL);
-			if (!CmdFailed(ret) && (tileh == SLOPE_SW || tileh == SLOPE_SE || tileh == SLOPE_NW || tileh == SLOPE_NE)) {
+			if (CmdSucceeded(ret) && (tileh == SLOPE_SW || tileh == SLOPE_SE || tileh == SLOPE_NW || tileh == SLOPE_NE)) {
 				aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile;
 				aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8);
 				aystar->neighbours[aystar->num_neighbours++].direction = 0;
--- a/src/ai/trolly/trolly.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/ai/trolly/trolly.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -1057,11 +1057,11 @@
 				}
 
 				ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
-				if (!CmdFailed(ret)) {
+				if (CmdSucceeded(ret)) {
 					dir1 = TileOffsByDiagDir(dir1);
 					if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) {
 						ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
-						if (!CmdFailed(ret)) {
+						if (CmdSucceeded(ret)) {
 							if (IsTileType(tile + dir1 + dir1, MP_CLEAR) || IsTileType(tile + dir1 + dir1, MP_TREES))
 								AI_DoCommand(tile+dir1+dir1, AiNew_GetRoadDirection(tile+dir1, tile+dir1+dir1, tile+dir1+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 						}
@@ -1069,11 +1069,11 @@
 				}
 
 				ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
-				if (!CmdFailed(ret)) {
+				if (CmdSucceeded(ret)) {
 					dir2 = TileOffsByDiagDir(dir2);
 					if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) {
 						ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
-						if (!CmdFailed(ret)) {
+						if (CmdSucceeded(ret)) {
 							if (IsTileType(tile + dir2 + dir2, MP_CLEAR) || IsTileType(tile + dir2 + dir2, MP_TREES))
 								AI_DoCommand(tile+dir2+dir2, AiNew_GetRoadDirection(tile+dir2, tile+dir2+dir2, tile+dir2+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 						}
@@ -1081,11 +1081,11 @@
 				}
 
 				ret = AI_DoCommand(tile, DiagDirToRoadBits((DiagDirection)dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
-				if (!CmdFailed(ret)) {
+				if (CmdSucceeded(ret)) {
 					dir3 = TileOffsByDiagDir(dir3);
 					if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) {
 						ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
-						if (!CmdFailed(ret)) {
+						if (CmdSucceeded(ret)) {
 							if (IsTileType(tile + dir3 + dir3, MP_CLEAR) || IsTileType(tile + dir3 + dir3, MP_TREES))
 								AI_DoCommand(tile+dir3+dir3, AiNew_GetRoadDirection(tile+dir3, tile+dir3+dir3, tile+dir3+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 						}
--- a/src/command.h	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/command.h	Mon Jun 18 16:42:40 2007 +0000
@@ -205,6 +205,8 @@
 	return res <= (CMD_ERROR | INVALID_STRING_ID);
 }
 
+static inline bool CmdSucceeded(CommandCost res) { return !CmdFailed(res); }
+
 /* command.cpp */
 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
 CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
--- a/src/misc_gui.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/misc_gui.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -122,7 +122,7 @@
 	GetString(_landinfo_data[1], STR_01A7_OWNER, lastof(_landinfo_data[1]));
 
 	str = STR_01A4_COST_TO_CLEAR_N_A;
-	if (!CmdFailed(costclear)) {
+	if (CmdSucceeded(costclear)) {
 		SetDParam(0, costclear);
 		str = STR_01A5_COST_TO_CLEAR;
 	}
--- a/src/rail_cmd.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/rail_cmd.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -810,7 +810,7 @@
 			ret = DoCommand(tile, p1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
 
 			/* Be user-friendly and try placing signals as much as possible */
-			if (!CmdFailed(ret)) {
+			if (CmdSucceeded(ret)) {
 				error = false;
 				total_cost += ret;
 			}
--- a/src/road_cmd.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/road_cmd.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -704,7 +704,7 @@
 		/* try to remove the halves. */
 		if (bits != 0) {
 			ret = DoCommand(tile, rt << 4 | bits, 0, flags, CMD_REMOVE_ROAD);
-			if (!CmdFailed(ret)) cost += ret;
+			if (CmdSucceeded(ret)) cost += ret;
 		}
 
 		if (tile == end_tile) break;
--- a/src/station_cmd.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/station_cmd.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -1441,7 +1441,7 @@
 	CommandCost ret = RemoveRoadStop(st, flags, tile);
 
 	/* If the stop was a drive-through stop replace the road */
-	if ((flags & DC_EXEC) && !CmdFailed(ret) && is_drive_through) {
+	if ((flags & DC_EXEC) && CmdSucceeded(ret) && is_drive_through) {
 		/* Rebuild the drive throuhg road stop. As a road stop can only be
 		 * removed by the owner of the roadstop, _current_player is the
 		 * owner of the road stop. */
--- a/src/town_cmd.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/town_cmd.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -1063,7 +1063,7 @@
 
 		default:
 build_road_and_exit:
-			if (!CmdFailed(DoCommand(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) {
+			if (CmdSucceeded(DoCommand(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) {
 				_grow_town_result = -1;
 			}
 			return;
@@ -1096,7 +1096,7 @@
 		do {
 			byte bridge_type = RandomRange(MAX_BRIDGES - 1);
 			if (CheckBridge_Stuff(bridge_type, bridge_len)) {
-				if (!CmdFailed(DoCommand(tile, tmptile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE)))
+				if (CmdSucceeded(DoCommand(tile, tmptile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE)))
 					_grow_town_result = -1;
 
 				/* obviously, if building any bridge would fail, there is no need to try other bridge-types */
@@ -1235,7 +1235,7 @@
 	for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
 		/* Only work with plain land that not already has a house */
 		if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) {
-			if (!CmdFailed(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) {
+			if (CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) {
 				DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
 				_current_player = old_player;
 				return true;
@@ -1587,7 +1587,7 @@
 	if (b)
 		return false;
 
-	return !CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR));
+	return CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR));
 }
 
 
--- a/src/vehicle.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/vehicle.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -1725,7 +1725,7 @@
 
 		ret = DoCommand(tile, v->index, 0, flags, stop_command);
 
-		if (!CmdFailed(ret)) {
+		if (CmdSucceeded(ret)) {
 			return_value = 0;
 			/* 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 */
@@ -1781,7 +1781,7 @@
 
 		ret = DoCommand(tile, v->index, 1, flags, sell_command);
 
-		if (!CmdFailed(ret)) cost += ret;
+		if (CmdSucceeded(ret)) cost += ret;
 	}
 
 	free(engines);
@@ -1829,7 +1829,7 @@
 		}
 		ret = MaybeReplaceVehicle(v, !(flags & DC_EXEC), false);
 
-		if (!CmdFailed(ret)) {
+		if (CmdSucceeded(ret)) {
 			cost += ret;
 			if (!(flags & DC_EXEC)) break;
 			/* There is a problem with autoreplace and newgrf
@@ -1972,7 +1972,7 @@
 
 				if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_type) {
 					cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v));
-					if (!CmdFailed(cost)) total_cost += cost;
+					if (CmdSucceeded(cost)) total_cost += cost;
 				}
 
 				if (w->type == VEH_TRAIN && EngineHasArticPart(w)) {
@@ -2240,7 +2240,7 @@
 			* 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 (!CmdFailed(ret) && !(flags & DC_EXEC)) {
+		if (CmdSucceeded(ret) && !(flags & DC_EXEC)) {
 			free((void*)sort_list);
 			return 0;
 		}
--- a/src/vehicle_gui.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/vehicle_gui.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -343,7 +343,7 @@
 				cost = DoCommand(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8,
 								 DC_QUERY_COST, GetCmdRefitVeh(GetVehicle(w->window_number)->type));
 
-				if (!CmdFailed(cost)) {
+				if (CmdSucceeded(cost)) {
 					SetDParam(0, WP(w, refit_d).cargo->cargo);
 					SetDParam(1, _returned_refit_capacity);
 					SetDParam(2, cost);
--- a/src/water_cmd.cpp	Mon Jun 18 14:40:07 2007 +0000
+++ b/src/water_cmd.cpp	Mon Jun 18 16:42:40 2007 +0000
@@ -588,7 +588,7 @@
 			case MP_CLEAR:
 			case MP_TREES:
 				_current_player = OWNER_WATER;
-				if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
+				if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 					MakeShore(target);
 					MarkTileDirtyByTile(target);
 				}
@@ -603,7 +603,7 @@
 		Vehicle *v = FindFloodableVehicleOnTile(target);
 		if (v != NULL) FloodVehicle(v);
 
-		if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
+		if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 			MakeWater(target);
 			MarkTileDirtyByTile(target);
 		}