(svn r1549) Clean up some functions:
authortron
Mon, 17 Jan 2005 09:41:46 +0000
changeset 1048 8611c5c02dcb
parent 1047 df93a1386892
child 1049 6573f8a2fb1d
(svn r1549) Clean up some functions:
uint tile -> TileIndex tile
if () cascade -> switch ()
disaster_cmd.c
industry_cmd.c
train_cmd.c
water_cmd.c
--- a/disaster_cmd.c	Mon Jan 17 09:16:43 2005 +0000
+++ b/disaster_cmd.c	Mon Jan 17 09:41:46 2005 +0000
@@ -13,25 +13,31 @@
 #include "airport_movement.h"
 #include "sound.h"
 
-static void DisasterClearSquare(uint tile)
+static void DisasterClearSquare(TileIndex tile)
 {
-	int type;
-
 	if (!EnsureNoVehicle(tile))
 		return;
 
-	type = TileType(tile);
+	switch (TileType(tile)) {
+		case MP_RAILWAY:
+			if (IS_HUMAN_PLAYER(_map_owner[tile])) DoClearSquare(tile);
+			break;
 
-	if (type == MP_RAILWAY) {
-		if (IS_HUMAN_PLAYER(_map_owner[tile]))
+		case MP_HOUSE: {
+			byte p = _current_player;
+			_current_player = OWNER_NONE;
+			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+			_current_player = p;
+			break;
+		}
+
+		case MP_TREES:
+		case MP_CLEAR:
 			DoClearSquare(tile);
-	} else if (type == MP_HOUSE) {
-		byte p = _current_player;
-		_current_player = OWNER_NONE;
-		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
-		_current_player = p;
-	} else if (type == MP_TREES || type == MP_CLEAR) {
-		DoClearSquare(tile);
+			break;
+
+		default:
+			break;
 	}
 }
 
--- a/industry_cmd.c	Mon Jan 17 09:16:43 2005 +0000
+++ b/industry_cmd.c	Mon Jan 17 09:41:46 2005 +0000
@@ -854,31 +854,35 @@
 
 static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
 
-static bool IsBadFarmFieldTile(uint tile)
+static bool IsBadFarmFieldTile(TileIndex tile)
 {
-	if (IsTileType(tile, MP_CLEAR)) {
-		byte m5 = _map5[tile] & 0x1C;
-		if (m5 == 0xC || m5 == 0x10)
+	switch (TileType(tile)) {
+		case MP_CLEAR: {
+			byte m5 = _map5[tile] & 0x1C;
+			return m5 == 0xC || m5 == 0x10;
+		}
+
+		case MP_TREES:
+			return false;
+
+		default:
 			return true;
-		return false;
-	} else if (IsTileType(tile, MP_TREES)) {
-		return false;
-	} else {
-		return true;
 	}
 }
 
-static bool IsBadFarmFieldTile2(uint tile)
+static bool IsBadFarmFieldTile2(TileIndex tile)
 {
-	if (IsTileType(tile, MP_CLEAR)) {
-		byte m5 = _map5[tile] & 0x1C;
-		if (m5 == 0x10)
+	switch (TileType(tile)) {
+		case MP_CLEAR: {
+			byte m5 = _map5[tile] & 0x1C;
+			return m5 == 0x10;
+		}
+
+		case MP_TREES:
+			return false;
+
+		default:
 			return true;
-		return false;
-	} else if (IsTileType(tile, MP_TREES)) {
-		return false;
-	} else {
-		return true;
 	}
 }
 
--- a/train_cmd.c	Mon Jan 17 09:16:43 2005 +0000
+++ b/train_cmd.c	Mon Jan 17 09:41:46 2005 +0000
@@ -1893,36 +1893,39 @@
 }
 
 /* Check if the vehicle is compatible with the specified tile */
-static bool CheckCompatibleRail(Vehicle *v, uint tile)
+static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
 {
-	if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION)) {
-		// normal tracks, jump to owner check
-	} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
-		if ((_map5[tile] & 0xC0) == 0xC0) {// is bridge middle part?
-			TileInfo ti;
-			FindLandscapeHeightByTile(&ti, tile);
-
-			// correct Z position of a train going under a bridge on slopes
-			if (CORRECT_Z(ti.tileh))
-				ti.z += 8;
-
-			if(v->z_pos != ti.z) // train is going over bridge
-				return true;
-		}
-	} else if (IsTileType(tile, MP_STREET)) { // train is going over a road-crossing
-		// tracks over roads, do owner check of tracks (_map_owner[tile])
-		if (_map_owner[tile] != v->owner || (v->subtype == 0 && (_map3_hi[tile] & 0xF) != v->u.rail.railtype))
-			return false;
-
-		return true;
-	} else
-		return true;
-
-	if (_map_owner[tile] != v->owner ||
-			(v->subtype == 0 && (_map3_lo[tile] & 0xF) != v->u.rail.railtype))
-		return false;
-
-	return true;
+	switch (TileType(tile)) {
+		case MP_RAILWAY:
+		case MP_STATION:
+			// normal tracks, jump to owner check
+			break;
+
+		case MP_TUNNELBRIDGE:
+			if ((_map5[tile] & 0xC0) == 0xC0) { // is bridge middle part?
+				TileInfo ti;
+				FindLandscapeHeightByTile(&ti, tile);
+
+				// correct Z position of a train going under a bridge on slopes
+				if (CORRECT_Z(ti.tileh)) ti.z += 8;
+
+				if (v->z_pos != ti.z) return true; // train is going over bridge
+			}
+			break;
+
+		case MP_STREET:
+			// tracks over roads, do owner check of tracks (_map_owner[tile])
+			return
+				_map_owner[tile] == v->owner &&
+				(v->subtype != 0 || (_map3_hi[tile] & 0xF) == v->u.rail.railtype);
+
+		default:
+			return true;
+	}
+
+	return
+		_map_owner[tile] == v->owner &&
+		(v->subtype != 0 || (_map3_lo[tile] & 0xF) == v->u.rail.railtype);
 }
 
 typedef struct {
--- a/water_cmd.c	Mon Jan 17 09:16:43 2005 +0000
+++ b/water_cmd.c	Mon Jan 17 09:41:46 2005 +0000
@@ -315,19 +315,27 @@
 }
 
 // return true if a tile is a water tile.
-static bool IsWateredTile(uint tile)
+static bool IsWateredTile(TileIndex tile)
 {
 	byte m5 = _map5[tile];
-	if (IsTileType(tile, MP_WATER)) {
-		return m5 != 1;
-	} else if (IsTileType(tile, MP_STATION)) {
-		// returns true if it is a dock-station (m5 inside values is m5<75 all stations,
-		// 83<=m5<=114 new airports
-		return !(m5 < 75 || (m5 >= 83 && m5 <= 114));
-	} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
-		return (m5 & 0xF8) == 0xC8;
-	} else
-		return false;
+
+	switch (TileType(tile)) {
+		case MP_WATER:
+			// true, if not coast/riverbank
+			return m5 != 1;
+
+		case MP_STATION:
+			// returns true if it is a dock-station
+			// m5 inside values is m5 < 75 all stations, 83 <= m5 <= 114 new airports
+			return !(m5 < 75 || (m5 >= 83 && m5 <= 114));
+
+		case MP_TUNNELBRIDGE:
+			// true, if tile is middle part of bridge with water underneath
+			return (m5 & 0xF8) == 0xC8;
+
+		default:
+			return false;
+	}
 }
 
 // draw a canal styled water tile with dikes around