(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
authorpeter1138
Sat, 10 Dec 2005 12:05:39 +0000
changeset 2737 f16e0a808897
parent 2736 1ea068235989
child 2738 d8de2d4bee17
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
ai/default/default.c
ai/trolly/trolly.c
bridge_gui.c
industry_cmd.c
misc_gui.c
rail_cmd.c
road_cmd.c
station_cmd.c
town_cmd.c
tunnelbridge_cmd.c
water_cmd.c
--- a/ai/default/default.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/ai/default/default.c	Sat Dec 10 12:05:39 2005 +0000
@@ -1677,7 +1677,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, DC_NO_TOWN_RATING);
-			if (*cost != CMD_ERROR && AiCheckTrackResources(tile, p->data, cargo))
+			if (!CmdFailed(*cost) && AiCheckTrackResources(tile, p->data, cargo))
 				return i;
 		}
 	}
@@ -1804,7 +1804,7 @@
 					_default_rail_track_data[rule]->data,
 					DC_EXEC | DC_NO_TOWN_RATING
 				);
-				assert(r != CMD_ERROR);
+				assert(!CmdFailed(r));
 			}
 		} while (++aib,--j);
 	}
@@ -2529,7 +2529,7 @@
 	for(i=0; (p = _road_default_block_data[i]) != NULL; i++) {
 		if (p->dir == direction) {
 			*cost = AiDoBuildDefaultRoadBlock(tile, p->data, 0);
-			if (*cost != CMD_ERROR && AiCheckRoadResources(tile, p->data, cargo))
+			if (!CmdFailed(*cost) && AiCheckRoadResources(tile, p->data, cargo))
 				return i;
 		}
 	}
@@ -2690,7 +2690,7 @@
 					_road_default_block_data[rule]->data,
 					DC_EXEC | DC_NO_TOWN_RATING
 				);
-				assert(r != CMD_ERROR);
+				assert(!CmdFailed(r));
 			}
 		} while (++aib,--j);
 	} while (--i);
@@ -3392,7 +3392,7 @@
 			continue;
 
 		*cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
-		if (*cost != CMD_ERROR && AiCheckAirportResources(tile, p, cargo))
+		if (!CmdFailed(*cost) && AiCheckAirportResources(tile, p, cargo))
 			return i;
 	}
 	return -1;
@@ -3463,7 +3463,7 @@
 					_airport_default_block_data[rule],
 					DC_EXEC | DC_NO_TOWN_RATING
 				);
-				assert(r != CMD_ERROR);
+				assert(!CmdFailed(r));
 			}
 		} while (++aib,--j);
 	} while (--i);
--- a/ai/trolly/trolly.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/ai/trolly/trolly.c	Sat Dec 10 12:05:39 2005 +0000
@@ -659,7 +659,7 @@
 					if (accepts[p->ainew.cargo] >> 3 == 0) continue;
 					// See if we can build the station
 					r = AiNew_Build_Station(p, p->ainew.tbt, new_tile, 0, 0, 0, DC_QUERY_COST);
-					if (r == CMD_ERROR) continue;
+					if (CmdFailed(r)) continue;
 					// We can build it, so add it to found_spot
 					found_spot[i] = new_tile;
 					found_best[i++] = accepts[p->ainew.cargo];
@@ -846,7 +846,7 @@
 				if (ti.tileh != 0) continue;
 				// Check if everything went okay..
 				r = AiNew_Build_Depot(p, tile + TileOffsByDir(j), j ^ 2, 0);
-				if (r == CMD_ERROR) continue;
+				if (CmdFailed(r)) continue;
 				// Found a spot!
 				p->ainew.new_cost += r;
 				p->ainew.depot_tile = tile + TileOffsByDir(j);
@@ -989,7 +989,7 @@
 			res = AiNew_Build_Station(p, p->ainew.tbt, p->ainew.to_tile, 0, 0, p->ainew.to_direction, DC_EXEC);
 		p->ainew.state = AI_STATE_BUILD_PATH;
 	}
-	if (res == CMD_ERROR) {
+	if (CmdFailed(res)) {
 		DEBUG(ai,0)("[AiNew - BuildStation] Strange but true... station can not be build!");
 		p->ainew.state = AI_STATE_NOTHING;
 		// If the first station _was_ build, destroy it
@@ -1119,7 +1119,7 @@
 		return;
 
 	res = AiNew_Build_Depot(p, p->ainew.depot_tile, p->ainew.depot_direction, DC_EXEC);
-	if (res == CMD_ERROR) {
+	if (CmdFailed(res)) {
 		DEBUG(ai,0)("[AiNew - BuildDepot] Strange but true... depot can not be build!");
 		p->ainew.state = AI_STATE_NOTHING;
 		return;
@@ -1152,7 +1152,7 @@
 
 	// Build the vehicle
 	res = AiNew_Build_Vehicle(p, p->ainew.depot_tile, DC_EXEC);
-	if (res == CMD_ERROR) {
+	if (CmdFailed(res)) {
 		// This happens when the AI can't build any more vehicles!
 		p->ainew.state = AI_STATE_NOTHING;
 		return;
--- a/bridge_gui.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/bridge_gui.c	Sat Dec 10 12:05:39 2005 +0000
@@ -130,7 +130,7 @@
 	// returns CMD_ERROR on failure, and price on success
 	ret = DoCommandByTile(end, start, (bridge_type << 8), DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE);
 
-	if (ret == CMD_ERROR) {
+	if (CmdFailed(ret)) {
 		errmsg = _error_message;
 	} else {
 		// check which bridges can be built
--- a/industry_cmd.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/industry_cmd.c	Sat Dec 10 12:05:39 2005 +0000
@@ -1354,7 +1354,7 @@
 					}
 				} else {
 do_clear:
-					if (DoCommandByTile(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) == CMD_ERROR)
+					if (CmdFailed(DoCommandByTile(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
 						return false;
 				}
 			}
--- a/misc_gui.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/misc_gui.c	Sat Dec 10 12:05:39 2005 +0000
@@ -59,7 +59,7 @@
 		DrawStringCentered(140, 27, STR_01A7_OWNER, 0);
 
 		str = STR_01A4_COST_TO_CLEAR_N_A;
-		if (lid->costclear != CMD_ERROR) {
+		if (!CmdFailed(lid->costclear)) {
 			SetDParam(0, lid->costclear);
 			str = STR_01A5_COST_TO_CLEAR;
 		}
--- a/rail_cmd.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/rail_cmd.c	Sat Dec 10 12:05:39 2005 +0000
@@ -1099,12 +1099,12 @@
 		case RAIL_TYPE_SIGNALS:
 			if (_m[tile].m3 & _signals_table_both[0]) {
 				ret = DoCommandByTile(tile, 0, 0, flags, CMD_REMOVE_SIGNALS);
-				if (ret == CMD_ERROR) return CMD_ERROR;
+				if (CmdFailed(ret)) return CMD_ERROR;
 				cost += ret;
 			}
 			if (_m[tile].m3 & _signals_table_both[3]) {
 				ret = DoCommandByTile(tile, 3, 0, flags, CMD_REMOVE_SIGNALS);
-				if (ret == CMD_ERROR) return CMD_ERROR;
+				if (CmdFailed(ret)) return CMD_ERROR;
 				cost += ret;
 			}
 
@@ -1121,7 +1121,7 @@
 			for (i = 0; m5 != 0; i++, m5 >>= 1) {
 				if (m5 & 1) {
 					ret = DoCommandByTile(tile, 0, i, flags, CMD_REMOVE_SINGLE_RAIL);
-					if (ret == CMD_ERROR) return CMD_ERROR;
+					if (CmdFailed(ret)) return CMD_ERROR;
 					cost += ret;
 				}
 			}
--- a/road_cmd.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/road_cmd.c	Sat Dec 10 12:05:39 2005 +0000
@@ -712,8 +712,7 @@
 			return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
 
 		ret = DoCommandByTile(tile, (m5&8)?5:10, 0, flags, CMD_REMOVE_ROAD);
-		if (ret == CMD_ERROR)
-			return CMD_ERROR;
+		if (CmdFailed(ret)) return CMD_ERROR;
 
 		if (flags & DC_EXEC) {
 			DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
--- a/station_cmd.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/station_cmd.c	Sat Dec 10 12:05:39 2005 +0000
@@ -810,7 +810,7 @@
 			}
 		} else {
 			ret = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
-			if (ret == CMD_ERROR) return CMD_ERROR;
+			if (CmdFailed(ret)) return CMD_ERROR;
 			cost += ret;
 		}
 	END_TILE_LOOP(tile_cur, w, h, tile)
@@ -1390,7 +1390,7 @@
 		return CMD_ERROR;
 
 	cost = CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL);
-	if (cost == CMD_ERROR) return CMD_ERROR;
+	if (CmdFailed(cost)) return CMD_ERROR;
 
 	st = GetStationAround(tile, 1, 1, -1);
 	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
--- a/town_cmd.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/town_cmd.c	Sat Dec 10 12:05:39 2005 +0000
@@ -483,8 +483,8 @@
 			// No, try to build one in the direction.
 			// if that fails clear the land, and if that fails exit.
 			// This is to make sure that we can build a road here later.
-			if (DoCommandByTile(tile, (dir&1)?0xA:0x5, 0, DC_AUTO, CMD_BUILD_ROAD) == CMD_ERROR &&
-					DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) == CMD_ERROR)
+			if (CmdFailed(DoCommandByTile(tile, (dir&1)?0xA:0x5, 0, DC_AUTO, CMD_BUILD_ROAD)) &&
+					CmdFailed(DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
 				return false;
 		}
 
@@ -664,7 +664,7 @@
 			(i++,ti.tileh != 12) &&
 			(i++,ti.tileh != 6)) {
 build_road_and_exit:
-		if (DoCommandByTile(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD) != CMD_ERROR)
+		if (!CmdFailed(DoCommandByTile(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD)))
 			_grow_town_result = -1;
 		return;
 	}
@@ -690,7 +690,7 @@
 		do {
 			byte bridge_type = RandomRange(MAX_BRIDGES - 1);
 			if (CheckBridge_Stuff(bridge_type, bridge_len)) {
-				if (DoCommandByTile(tile, tmptile, 0x8000 + bridge_type, DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE) != CMD_ERROR)
+				if (!CmdFailed(DoCommandByTile(tile, tmptile, 0x8000 + bridge_type, 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
@@ -809,7 +809,7 @@
 
 		// Only work with plain land that not already has a house with map5=0
 		if (ti.tileh == 0 && (ti.type != MP_HOUSE || ti.map5 != 0)) {
-			if (DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) {
+			if (!CmdFailed(DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) {
 				DoCommandByTile(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
 				_current_player = old_player;
 				return true;
@@ -1136,7 +1136,7 @@
 	if (b)
 		return false;
 
-	return DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR) != CMD_ERROR;
+	return !CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR));
 }
 
 int GetTownRadiusGroup(const Town *t, TileIndex tile)
@@ -1174,7 +1174,7 @@
 		if (GetTileSlope(tile, NULL))
 			return false;
 
-		if (DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_FORCETEST, CMD_LANDSCAPE_CLEAR) == CMD_ERROR)
+		if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_FORCETEST, CMD_LANDSCAPE_CLEAR)))
 			return false;
 	}
 
@@ -1361,7 +1361,7 @@
 	if (GetTileSlope(tile, NULL) & 0x10) return false;
 
 	r = DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
-	if (r == CMD_ERROR) return false;
+	if (CmdFailed(r)) return false;
 
 	DoBuildTownHouse(t, tile);
 	return true;
--- a/tunnelbridge_cmd.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/tunnelbridge_cmd.c	Sat Dec 10 12:05:39 2005 +0000
@@ -279,7 +279,7 @@
 
 	// true - bridge-start-tile, false - bridge-end-tile
 	terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true);
-	if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes))
+	if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes))
 		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 	cost += terraformcost;
 
@@ -291,7 +291,7 @@
 
 	// false - end tile slope check
 	terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false);
-	if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes))
+	if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes))
 		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 	cost += terraformcost;
 
--- a/water_cmd.c	Sat Dec 10 11:16:45 2005 +0000
+++ b/water_cmd.c	Sat Dec 10 12:05:39 2005 +0000
@@ -136,17 +136,17 @@
 
 	// middle tile
 	ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
-	if (ret == CMD_ERROR) return CMD_ERROR;
+	if (CmdFailed(ret)) return CMD_ERROR;
 
 	delta = TileOffsByDir(dir);
 	// lower tile
 	ret = DoCommandByTile(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
-	if (ret == CMD_ERROR) return CMD_ERROR;
+	if (CmdFailed(ret)) return CMD_ERROR;
 	if (GetTileSlope(tile - delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 
 	// upper tile
 	ret = DoCommandByTile(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
-	if (ret == CMD_ERROR) return CMD_ERROR;
+	if (CmdFailed(ret)) return CMD_ERROR;
 	if (GetTileSlope(tile + delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 
 	if (flags & DC_EXEC) {
@@ -530,7 +530,7 @@
 			case MP_CLEAR:
 			case MP_TREES:
 				_current_player = OWNER_WATER;
-				if (DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) {
+				if (!CmdFailed(DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 					ModifyTile(
 						target,
 						MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR |
@@ -569,7 +569,7 @@
 			if (v != NULL) FloodVehicle(v);
 		}
 
-		if (DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) {
+		if (!CmdFailed(DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 			ModifyTile(
 				target,
 				MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR |