(svn r1560) Introduce SetTileType() and SetTileHeight()
authortron
Tue, 18 Jan 2005 18:41:56 +0000
changeset 1059 c28c6be74291
parent 1058 0a1a77da0a03
child 1060 e8c44e426175
(svn r1560) Introduce SetTileType() and SetTileHeight()
Replace direct references to _map_type_and_height with these
clear_cmd.c
industry_cmd.c
landscape.c
map.h
rail_cmd.c
road_cmd.c
station_cmd.c
tree_cmd.c
tunnelbridge_cmd.c
unmovable_cmd.c
--- a/clear_cmd.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/clear_cmd.c	Tue Jan 18 18:41:56 2005 +0000
@@ -303,9 +303,7 @@
 			for(count = ts.modheight_count; count != 0; count--, mod++) {
 				til = mod->tile;
 
-				// Change tile height
-				_map_type_and_height[til] = (_map_type_and_height[til]&~0x0F)|mod->height;
-
+				SetTileHeight(til, mod->height);
 				TerraformAddDirtyTileAround(&ts, til);
 			}
 		}
--- a/industry_cmd.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/industry_cmd.c	Tue Jan 18 18:41:56 2005 +0000
@@ -1479,7 +1479,7 @@
 
 			DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
-			_map_type_and_height[cur_tile] = (_map_type_and_height[cur_tile]&~0xF0) | (MP_INDUSTRY<<4);
+			SetTileType(cur_tile, MP_INDUSTRY);
 			_map5[cur_tile] = it->map5;
 			_map2[cur_tile] = i->index;
 			_map_owner[cur_tile] = _generating_world ? 0x1E : 0; /* maturity */
--- a/landscape.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/landscape.c	Tue Jan 18 18:41:56 2005 +0000
@@ -400,7 +400,7 @@
 	va_start(va, flags);
 
 	if ((i = (flags >> 8) & 0xF) != 0) {
-		_map_type_and_height[tile] = (_map_type_and_height[tile]&~0xF0)|((i-1) << 4);
+		SetTileType(tile, i - 1);
 	}
 
 	if (flags & (MP_MAP2_CLEAR | MP_MAP2)) {
@@ -510,7 +510,7 @@
 
 	while(true) {
 		if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) {
-			_map_type_and_height[tile] = MP_WATER << 4;
+			SetTileType(tile, MP_WATER);
 			_map5[tile] = 0;
 			_map_owner[tile] = OWNER_WATER;
 		}
--- a/map.h	Tue Jan 18 17:19:34 2005 +0000
+++ b/map.h	Tue Jan 18 18:41:56 2005 +0000
@@ -79,6 +79,14 @@
 	return _map_type_and_height[tile] & 0xf;
 }
 
+static inline void SetTileHeight(TileIndex tile, uint height)
+{
+	assert(tile < MapSize());
+	assert(height < 16);
+	_map_type_and_height[tile] &= ~0x0F;
+	_map_type_and_height[tile] |= height;
+}
+
 static inline uint TilePixelHeight(TileIndex tile)
 {
 	return TileHeight(tile) * 8;
@@ -90,6 +98,13 @@
 	return _map_type_and_height[tile] >> 4;
 }
 
+static inline void SetTileType(TileIndex tile, uint type)
+{
+	assert(tile < MapSize());
+	_map_type_and_height[tile] &= ~0xF0;
+	_map_type_and_height[tile] |= type << 4;
+}
+
 static inline bool IsTileType(TileIndex tile, int type)
 {
 	return TileType(tile) == type;
--- a/rail_cmd.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/rail_cmd.c	Tue Jan 18 18:41:56 2005 +0000
@@ -369,8 +369,7 @@
 	}
 
 	if (flags & DC_EXEC) {
-		_map_type_and_height[tile] &= 0xF;
-		_map_type_and_height[tile] |= MP_RAILWAY << 4;
+		SetTileType(tile, MP_RAILWAY);
 		_map5[tile] |= rail_bit;
 		_map2[tile] &= ~RAIL_MAP2LO_GROUND_MASK;
 
--- a/road_cmd.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/road_cmd.c	Tue Jan 18 18:41:56 2005 +0000
@@ -448,8 +448,7 @@
 
 	if (flags & DC_EXEC) {
 		if (ti.type != MP_STREET) {
-			_map_type_and_height[tile] &= 0xF;
-			_map_type_and_height[tile] |= MP_STREET << 4;
+			SetTileType(tile, MP_STREET);
 			_map5[tile] = 0;
 			_map_owner[tile] = _current_player;
 		}
--- a/station_cmd.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/station_cmd.c	Tue Jan 18 18:41:56 2005 +0000
@@ -2643,8 +2643,7 @@
 			if (!GenerateStationName(st, tile, 2))
 				return;
 
-			_map_type_and_height[tile] &= 0xF;
-			_map_type_and_height[tile] |= MP_STATION << 4;
+			SetTileType(tile, MP_STATION);
 			_map5[tile] = 0x4B;
 			_map_owner[tile] = OWNER_NONE;
 			_map3_lo[tile] = 0;
--- a/tree_cmd.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/tree_cmd.c	Tue Jan 18 18:41:56 2005 +0000
@@ -59,7 +59,7 @@
 
 
 		// make it tree class
-		_map_type_and_height[tile] |= MP_TREES << 4;
+		SetTileType(tile, MP_TREES);
 	}
 }
 
@@ -531,8 +531,7 @@
 
 				_map3_lo[tile] = m3;
 				_map3_hi[tile] = 0;
-				_map_type_and_height[tile] &= 0xF;
-				_map_type_and_height[tile] |= MP_TREES << 4;
+				SetTileType(tile, MP_TREES);
 
 				m5 = 0;
 				break;
@@ -549,7 +548,7 @@
 			m5 = ((m5 - 6) - 0x40) + 3;
 		} else {
 			/* just one tree, change type into MP_CLEAR */
-			_map_type_and_height[tile] = (_map_type_and_height[tile]&~0xF0) | (MP_CLEAR<<4);
+			SetTileType(tile, MP_CLEAR);
 
 			m5 = 3;
 			m2 = _map2[tile];
--- a/tunnelbridge_cmd.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/tunnelbridge_cmd.c	Tue Jan 18 18:41:56 2005 +0000
@@ -338,8 +338,7 @@
 		/* do middle part of bridge */
 		if (flags & DC_EXEC) {
 			_map5[ti.tile] = (byte)(m5 | direction | rail_or_road);
-			_map_type_and_height[ti.tile] &= ~0xF0;
-			_map_type_and_height[ti.tile] |= MP_TUNNELBRIDGE << 4;
+			SetTileType(ti.tile, MP_TUNNELBRIDGE);
 
 			//bridges pieces sequence (middle parts)
 			// bridge len 1: 0
@@ -783,8 +782,7 @@
 					new_data = 0x6000;
 				}
 
-				_map_type_and_height[c] &= 0x0F;
-				_map_type_and_height[c] |= new_data >> 8;
+				SetTileType(c, new_data >> 12);
 				_map5[c] = (byte)new_data;
 				_map2[c] = 0;
 
--- a/unmovable_cmd.c	Tue Jan 18 17:19:34 2005 +0000
+++ b/unmovable_cmd.c	Tue Jan 18 18:41:56 2005 +0000
@@ -268,7 +268,7 @@
 		if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
 			if(!checkRadioTowerNearby(tile))
 				continue;
-			_map_type_and_height[tile] |= MP_UNMOVABLE << 4;
+			SetTileType(tile, MP_UNMOVABLE);
 			_map5[tile] = 0;
 			_map_owner[tile] = OWNER_NONE;
 			if (--j == 0)
@@ -300,7 +300,7 @@
 
 		assert(tile == TILE_MASK(tile));
 
-		_map_type_and_height[tile] |= MP_UNMOVABLE << 4;
+		SetTileType(tile, MP_UNMOVABLE);
 		_map5[tile] = 1;
 		_map_owner[tile] = OWNER_NONE;
 	} while (--i);