(svn r4250) -Codechange: Further use of map accessors for water tiles
authorcelestar
Mon, 03 Apr 2006 10:28:16 +0000
changeset 3423 03e0e97abf41
parent 3422 12cdb13ddb56
child 3424 142ded56d7e7
(svn r4250) -Codechange: Further use of map accessors for water tiles
water_cmd.c
water_map.h
--- a/water_cmd.c	Mon Apr 03 09:07:21 2006 +0000
+++ b/water_cmd.c	Mon Apr 03 10:28:16 2006 +0000
@@ -324,8 +324,7 @@
 {
 	switch (GetTileType(tile)) {
 		case MP_WATER:
-			// true, if not coast/riverbank
-			return _m[tile].m5 != 1;
+			return !IsCoast(tile);
 
 		case MP_STATION:
 			return IsOilRig(tile) || IsDock(tile) || IsBuoy_(tile);
@@ -645,47 +644,29 @@
 	}
 }
 
-
-static const byte _coast_tracks[16] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};
-static const byte _shipdepot_tracks[4] = {1,1,2,2};
-static const byte _shiplift_tracks[12] = {1,2,1,2,1,2,1,2,1,2,1,2};
 static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode)
 {
-	uint m5;
-	uint b;
-
+	static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};
+	static const byte water_tracks_by_axis[] = {1, 2};
 	if (mode != TRANSPORT_WATER) return 0;
 
-	m5 = _m[tile].m5;
-	if (m5 == 0) return 0x3F3F;
-
-	if (m5 == 1) {
-		b = _coast_tracks[GetTileSlope(tile, NULL) & 0xF];
-		return b + (b << 8);
+	switch (GetWaterTileType(tile)) {
+		case WATER_CLEAR: return 0x3F * 0x101; /* We can go everywhere */
+		case WATER_COAST: return coast_tracks[GetTileSlope(tile, NULL) & 0xF] * 0x101;
+		case WATER_LOCK: return water_tracks_by_axis[DiagDirToAxis(GetLockDirection(tile))] * 0x101;
+		case WATER_DEPOT: return water_tracks_by_axis[GetShipDepotAxis(tile)] * 0x101;
+		default: return 0;
 	}
-
-	if ((m5 & 0x10) == 0x10) {
-		//
-		b = _shiplift_tracks[m5 & 0xF];
-		return b + (b << 8);
-	}
-
-	if (!(m5 & 0x80)) return 0;
-
-	b = _shipdepot_tracks[m5 & 0x7F];
-	return b + (b << 8);
 }
 
 extern void ShowShipDepotWindow(TileIndex tile);
 
 static void ClickTile_Water(TileIndex tile)
 {
-	byte m5 = _m[tile].m5 - 0x80;
+	if (GetWaterTileType(tile) == WATER_DEPOT) {
+		TileIndex tile2 = GetOtherShipDepotTile(tile);
 
-	if (IS_BYTE_INSIDE(m5, 0, 3+1)) {
-		if (m5 & 1)
-			tile += (m5 == 1) ? TileDiffXY(-1, 0) : TileDiffXY(0, -1);
-		ShowShipDepotWindow(tile);
+		ShowShipDepotWindow(tile < tile2 ? tile : tile2);
 	}
 }
 
--- a/water_map.h	Mon Apr 03 09:07:21 2006 +0000
+++ b/water_map.h	Mon Apr 03 10:28:16 2006 +0000
@@ -38,6 +38,11 @@
 	return GetWaterTileType(t) == WATER_CLEAR;
 }
 
+static inline bool IsCoast(TileIndex t)
+{
+	return GetWaterTileType(t) == WATER_COAST;
+}
+
 static inline bool IsClearWaterTile(TileIndex t)
 {
 	return IsTileType(t, MP_WATER) && IsWater(t) && GetTileSlope(t, NULL) == 0;
@@ -53,6 +58,11 @@
 	return IS_INT_INSIDE(_m[t].m5, DEPOT_NORTH, DEPOT_END);
 }
 
+static inline Axis GetShipDepotAxis(TileIndex t)
+{
+	return (Axis)GB(_m[t].m5, 1, 1);
+}
+
 static inline DiagDirection GetLockDirection(TileIndex t)
 {
 	return (DiagDirection)GB(_m[t].m5, 0, 2);