(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
authorcelestar
Fri, 31 Mar 2006 18:36:13 +0000
changeset 3402 812f9dc4baff
parent 3401 3eb83140e401
child 3403 66cfd06c7c6f
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
water_cmd.c
water_map.h
--- a/water_cmd.c	Fri Mar 31 17:40:31 2006 +0000
+++ b/water_cmd.c	Fri Mar 31 18:36:13 2006 +0000
@@ -406,28 +406,26 @@
 
 static void DrawTile_Water(TileInfo *ti)
 {
-	// draw water tile
-	if (ti->map5 == 0) {
-		DrawGroundSprite(SPR_FLAT_WATER_TILE);
-		if (ti->z != 0) DrawCanalWater(ti->tile);
-		return;
-	}
+	switch (GetWaterTileType(ti->tile)) {
+		case WATER_CLEAR:
+			DrawGroundSprite(SPR_FLAT_WATER_TILE);
+			if (ti->z != 0) DrawCanalWater(ti->tile);
+			break;
 
-	// draw shore
-	if (ti->map5 == 1) {
-		assert(ti->tileh < 16);
-		DrawGroundSprite(_water_shore_sprites[ti->tileh]);
-		return;
-	}
+		case WATER_COAST:
+			assert(ti->tileh < 16);
+			DrawGroundSprite(_water_shore_sprites[ti->tileh]);
+			break;
 
-	// draw shiplift
-	if ((ti->map5 & 0xF0) == 0x10) {
-		const WaterDrawTileStruct *t = _shiplift_display_seq[ti->map5 & 0xF];
-		DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
-		return;
+		case WATER_LOCK: {
+			const WaterDrawTileStruct *t = _shiplift_display_seq[ti->map5 & 0xF];
+			DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
+		} break;
+
+		case WATER_DEPOT:
+			DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
+			break;
 	}
-
-	DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
 }
 
 void DrawShipDepotSprite(int x, int y, int image)
@@ -460,16 +458,18 @@
 
 static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
 {
-	if (_m[tile].m5 == 0 && TilePixelHeight(tile) == 0) {
-		td->str = STR_3804_WATER;
-	} else if (_m[tile].m5 == 0) {
-		td->str = STR_LANDINFO_CANAL;
-	} else if (_m[tile].m5 == 1) {
-		td->str = STR_3805_COAST_OR_RIVERBANK;
-	} else if ((_m[tile].m5 & 0xF0) == 0x10) {
-		td->str = STR_LANDINFO_LOCK;
-	} else {
-		td->str = STR_3806_SHIP_DEPOT;
+	switch (GetWaterTileType(tile)) {
+		case WATER_CLEAR:
+			if (TilePixelHeight(tile) == 0) {
+				td->str = STR_3804_WATER;
+			} else {
+				td->str = STR_LANDINFO_CANAL;
+			}
+			break;
+		case WATER_COAST: td->str = STR_3805_COAST_OR_RIVERBANK; break;
+		case WATER_LOCK : td->str = STR_LANDINFO_LOCK; break;
+		case WATER_DEPOT: td->str = STR_3806_SHIP_DEPOT; break;
+		default: assert(0); break;
 	}
 
 	td->owner = GetTileOwner(tile);
--- a/water_map.h	Fri Mar 31 17:40:31 2006 +0000
+++ b/water_map.h	Fri Mar 31 18:36:13 2006 +0000
@@ -3,6 +3,13 @@
 #ifndef WATER_MAP_H
 #define WATER_MAP_H
 
+typedef enum WaterTileType {
+	WATER_CLEAR,
+	WATER_COAST,
+	WATER_LOCK,
+	WATER_DEPOT,
+} WaterTileType;
+
 typedef enum DepotPart {
 	DEPOT_NORTH = 0x80,
 	DEPOT_SOUTH = 0x81,
@@ -12,15 +19,28 @@
 typedef enum LockPart {
 	LOCK_MIDDLE = 0x10,
 	LOCK_LOWER  = 0x14,
-	LOCK_UPPER  = 0x18
+	LOCK_UPPER  = 0x18,
+	LOCK_END    = 0x1C
 } LockPart;
 
-static inline bool IsClearWaterTile(TileIndex tile)
+static inline WaterTileType GetWaterTileType(TileIndex t)
 {
-	return
-		IsTileType(tile, MP_WATER) &&
-		_m[tile].m5 == 0 &&
-		GetTileSlope(tile, NULL) == 0;
+	if (_m[t].m5 == 0) return WATER_CLEAR;
+	if (_m[t].m5 == 1) return WATER_COAST;
+	if (IS_INT_INSIDE(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_LOCK;
+	if (IS_INT_INSIDE(_m[t].m5, DEPOT_NORTH, DEPOT_END)) return WATER_DEPOT;
+
+	assert(0);
+}
+
+static inline bool IsWater(TileIndex t)
+{
+	return GetWaterTileType(t) == WATER_CLEAR;
+}
+
+static inline bool IsClearWaterTile(TileIndex t)
+{
+	return IsTileType(t, MP_WATER) && IsWater(t) && GetTileSlope(t, NULL) == 0;
 }
 
 static inline TileIndex GetOtherShipDepotTile(TileIndex t)