(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
authorbelugas
Thu, 30 Mar 2006 19:16:44 +0000
changeset 3379 50b253bb9819
parent 3378 4057cbcc6b86
child 3380 2d02cfdf6d14
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
clear_cmd.c
industry_cmd.c
landscape.c
rail_cmd.c
road_cmd.c
terraform_gui.c
tile.c
tile.h
town_cmd.c
tree_cmd.c
tunnelbridge_cmd.c
--- a/clear_cmd.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/clear_cmd.c	Thu Mar 30 19:16:44 2006 +0000
@@ -603,13 +603,13 @@
 {
 	if (IsClearGround(tile, CL_DESERT)) return;
 
-	if (GetMapExtraBits(tile) == 1) {
+	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
 		SetClearGroundDensity(tile, CL_DESERT, 3);
 	} else {
-		if (GetMapExtraBits(tile + TileDiffXY( 1,  0)) != 1 &&
-				GetMapExtraBits(tile + TileDiffXY(-1,  0)) != 1 &&
-				GetMapExtraBits(tile + TileDiffXY( 0,  1)) != 1 &&
-				GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1)
+		if (GetTropicZone(tile + TileDiffXY( 1,  0)) != TROPICZONE_DESERT &&
+				GetTropicZone(tile + TileDiffXY(-1,  0)) != TROPICZONE_DESERT &&
+				GetTropicZone(tile + TileDiffXY( 0,  1)) != TROPICZONE_DESERT &&
+				GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT)
 			return;
 		SetClearGroundDensity(tile, CL_DESERT, 1);
 	}
--- a/industry_cmd.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/industry_cmd.c	Thu Mar 30 19:16:44 2006 +0000
@@ -1031,7 +1031,7 @@
 					SndPlayTileFx(SND_38_CHAINSAW, tile);
 
 					DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
-					SetMapExtraBits(tile, 0);
+					SetTropicZone(tile, TROPICZONE_INVALID);
 
 					i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45);
 
@@ -1181,7 +1181,7 @@
 
 static bool CheckNewIndustry_Plantation(TileIndex tile, int type)
 {
-	if (GetMapExtraBits(tile) == 1) {
+	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
 		_error_message = STR_0239_SITE_UNSUITABLE;
 		return false;
 	}
@@ -1191,7 +1191,7 @@
 
 static bool CheckNewIndustry_Water(TileIndex tile, int type)
 {
-	if (GetMapExtraBits(tile) != 1) {
+	if (GetTropicZone(tile) != TROPICZONE_DESERT) {
 		_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT;
 		return false;
 	}
@@ -1201,7 +1201,7 @@
 
 static bool CheckNewIndustry_Lumbermill(TileIndex tile, int type)
 {
-	if (GetMapExtraBits(tile) != 2) {
+	if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
 		_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST;
 		return false;
 	}
--- a/landscape.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/landscape.c	Thu Mar 30 19:16:44 2006 +0000
@@ -590,7 +590,7 @@
 			if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
 		}
 		if (data == endof(_make_desert_or_rainforest_data))
-			SetMapExtraBits(tile, 1);
+			SetTropicZone(tile, TROPICZONE_DESERT);
 	}
 
 	for (i = 0; i != 256; i++)
@@ -603,7 +603,7 @@
 			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CL_DESERT)) break;
 		}
 		if (data == endof(_make_desert_or_rainforest_data))
-			SetMapExtraBits(tile, 2);
+			SetTropicZone(tile, TROPICZONE_RAINFOREST);
 	}
 }
 
--- a/rail_cmd.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/rail_cmd.c	Thu Mar 30 19:16:44 2006 +0000
@@ -1814,7 +1814,7 @@
 			break;
 
 		case LT_DESERT:
-			if (GetMapExtraBits(tile) == 1) { /* convert into desert? */
+			if (GetTropicZone(tile) == TROPICZONE_DESERT) { /* convert into desert? */
 				new_ground = RAIL_GROUND_ICE_DESERT;
 				goto modify_me;
 			}
--- a/road_cmd.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/road_cmd.c	Thu Mar 30 19:16:44 2006 +0000
@@ -920,7 +920,7 @@
 			break;
 
 		case LT_DESERT:
-			if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
+			if (GetTropicZone(tile) == TROPICZONE_DESERT && !(_m[tile].m4 & 0x80)) {
 				_m[tile].m4 |= 0x80;
 				MarkTileDirtyByTile(tile);
 			}
--- a/terraform_gui.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/terraform_gui.c	Thu Mar 30 19:16:44 2006 +0000
@@ -55,7 +55,7 @@
 	_generating_world = true;
 	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 		if (GetTileType(tile) != MP_WATER) {
-			SetMapExtraBits(tile, (_ctrl_pressed) ? 0 : 1);
+			SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_INVALID : TROPICZONE_DESERT);
 			DoCommandP(tile, 0, 0, NULL, CMD_LANDSCAPE_CLEAR);
 			MarkTileDirtyByTile(tile);
 		}
--- a/tile.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/tile.c	Thu Mar 30 19:16:44 2006 +0000
@@ -3,18 +3,6 @@
 #include "stdafx.h"
 #include "tile.h"
 
-void SetMapExtraBits(TileIndex tile, byte bits)
-{
-	assert(tile < MapSize());
-	SB(_m[tile].extra, 0, 2, bits & 3);
-}
-
-uint GetMapExtraBits(TileIndex tile)
-{
-	assert(tile < MapSize());
-	return GB(_m[tile].extra, 0, 2);
-}
-
 /** Converts the heights of 4 corners into a tileh, and returns the minimum height of the tile
   * @param n,w,e,s the four corners
   * @param h uint pointer to write the height to
--- a/tile.h	Thu Mar 30 15:47:18 2006 +0000
+++ b/tile.h	Thu Mar 30 19:16:44 2006 +0000
@@ -20,9 +20,11 @@
 	MP_UNMOVABLE,
 } TileType;
 
-
-void SetMapExtraBits(TileIndex tile, byte flags);
-uint GetMapExtraBits(TileIndex tile);
+typedef enum TropicZones {
+	TROPICZONE_INVALID = 0,
+	TROPICZONE_DESERT = 1,
+	TROPICZONE_RAINFOREST = 2,
+} TropicZone;
 
 uint GetTileh(uint n, uint w, uint e, uint s, uint *h);
 uint GetTileSlope(TileIndex tile, uint *h);
@@ -106,4 +108,27 @@
 	return GetTileOwner(tile) == owner;
 }
 
+/**
+ * Set the tropic zone
+ * @param tile the tile to set the zone of
+ * @param type the new type
+ * @pre assert(tile < MapSize());
+ */
+static inline void SetTropicZone(TileIndex tile, TropicZone type)
+{
+	assert(tile < MapSize());
+	SB(_m[tile].extra, 0, 2, type);
+}
+
+/**
+ * Get the tropic zone
+ * @param tile the tile to get the zone of
+ * @pre assert(tile < MapSize());
+ * @return the zone type
+ */
+static inline TropicZone GetTropicZone(TileIndex tile)
+{
+	assert(tile < MapSize());
+	return (TropicZone)GB(_m[tile].extra, 0, 2);
+}
 #endif /* TILE_H */
--- a/town_cmd.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/town_cmd.c	Thu Mar 30 19:16:44 2006 +0000
@@ -1762,7 +1762,7 @@
  		if (TilePixelHeight(t->xy) >= _opt.snow_line && t->act_food == 0 && t->population > 90)
 			return;
 	} else if (_opt.landscape == LT_DESERT) {
- 		if (GetMapExtraBits(t->xy) == 1 && (t->act_food==0 || t->act_water==0) && t->population > 60)
+ 		if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food==0 || t->act_water==0) && t->population > 60)
 			return;
 	}
 
--- a/tree_cmd.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/tree_cmd.c	Thu Mar 30 19:16:44 2006 +0000
@@ -26,10 +26,10 @@
 			return seed * TR_COUNT_SUB_ARCTIC / 256 + TR_SUB_ARCTIC;
 
 		case LT_DESERT:
-			switch (GetMapExtraBits(tile)) {
-				case 0:  return seed * TR_COUNT_SUB_TROPICAL / 256 + TR_SUB_TROPICAL;
-				case 1:  return (seed > 12) ? TR_INVALID : TR_CACTUS;
-				default: return seed * TR_COUNT_RAINFOREST / 256 + TR_RAINFOREST;
+			switch (GetTropicZone(tile)) {
+				case TROPICZONE_INVALID:       return seed * TR_COUNT_SUB_TROPICAL / 256 + TR_SUB_TROPICAL;
+				case TROPICZONE_DESERT: return (seed > 12) ? TR_INVALID : TR_CACTUS;
+				default:                return seed * TR_COUNT_RAINFOREST / 256 + TR_RAINFOREST;
 			}
 
 		default:
@@ -105,7 +105,7 @@
 		do {
 			uint32 r = Random();
 			TileIndex tile = RandomTileSeed(r);
-			if (IsTileType(tile, MP_CLEAR) && GetMapExtraBits(tile) == 2) {
+			if (IsTileType(tile, MP_CLEAR) && GetTropicZone(tile) == TROPICZONE_RAINFOREST) {
 				PlaceTree(tile, r);
 			}
 		} while (--i);
@@ -208,7 +208,7 @@
 						MarkTileDirtyByTile(tile);
 
 						if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TR_RAINFOREST, TR_CACTUS))
-							SetMapExtraBits(tile, 2);
+							SetTropicZone(tile, TROPICZONE_RAINFOREST);
 					}
 					cost += _price.build_trees;
 					break;
@@ -376,15 +376,15 @@
 
 static void TileLoopTreesDesert(TileIndex tile)
 {
-	switch (GetMapExtraBits(tile)) {
-		case 1:
+	switch (GetTropicZone(tile)) {
+		case TROPICZONE_DESERT:
 			if (GetTreeGround(tile) != TR_SNOW_DESERT) {
 				SetTreeGroundDensity(tile, TR_SNOW_DESERT, 3);
 				MarkTileDirtyByTile(tile);
 			}
 			break;
 
-		case 2: {
+		case TROPICZONE_RAINFOREST: {
 			static const SoundFx forest_sounds[] = {
 				SND_42_LOON_BIRD,
 				SND_43_LION,
@@ -396,6 +396,8 @@
 			if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
 			break;
 		}
+
+		default: break;
 	}
 }
 
@@ -452,7 +454,9 @@
 
 	switch (GetTreeGrowth(tile)) {
 		case 3: /* regular sized tree */
-			if (_opt.landscape == LT_DESERT && GetTreeType(tile) != TR_CACTUS && GetMapExtraBits(tile) == 1) {
+			if (_opt.landscape == LT_DESERT &&
+					GetTreeType(tile) != TR_CACTUS &&
+					GetTropicZone(tile) == TROPICZONE_DESERT) {
 				AddTreeGrowth(tile, 1);
 			} else {
 				switch (GB(Random(), 0, 3)) {
@@ -526,7 +530,7 @@
 
 	/* place a tree at a random rainforest spot */
 	if (_opt.landscape == LT_DESERT &&
-			(r = Random(), tile = RandomTileSeed(r), GetMapExtraBits(tile) == 2) &&
+			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
 			IsTileType(tile, MP_CLEAR) &&
 			(ct = GetClearGround(tile), ct == CL_GRASS || ct == CL_ROUGH) &&
 			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TR_INVALID) {
--- a/tunnelbridge_cmd.c	Thu Mar 30 15:47:18 2006 +0000
+++ b/tunnelbridge_cmd.c	Thu Mar 30 19:16:44 2006 +0000
@@ -1225,7 +1225,7 @@
 			break;
 
 		case LT_DESERT:
-			if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
+			if (GetTropicZone(tile) == TROPICZONE_DESERT && !(_m[tile].m4 & 0x80)) {
 				_m[tile].m4 |= 0x80;
 				MarkTileDirtyByTile(tile);
 			}