(svn r3665) Add a function to turn a tile into a clear tile
authortron
Fri, 24 Feb 2006 19:56:24 +0000
changeset 3076 9584f34a83dc
parent 3075 f0d692c60465
child 3077 65bee046f79b
(svn r3665) Add a function to turn a tile into a clear tile
clear.h
landscape.c
terraform_gui.c
tree_cmd.c
--- a/clear.h	Fri Feb 24 19:52:26 2006 +0000
+++ b/clear.h	Fri Feb 24 19:56:24 2006 +0000
@@ -4,6 +4,7 @@
 #define CLEAR_H
 
 #include "macros.h"
+#include "tile.h"
 
 /* ground type, m5 bits 2...4
  * valid densities (bits 0...1) in comments after the enum
@@ -43,4 +44,15 @@
 static inline uint GetFenceSW(TileIndex t) { return GB(_m[t].m4, 5, 3); }
 static inline void SetFenceSW(TileIndex t, uint h) { SB(_m[t].m4, 5, 3, h); }
 
+
+static inline void MakeClear(TileIndex t, ClearGround g, uint density)
+{
+	SetTileType(t, MP_CLEAR);
+	SetTileOwner(t, OWNER_NONE);
+	_m[t].m2 = 0;
+	_m[t].m3 = 0;
+	_m[t].m4 = 0 << 5 | 0 << 2;
+	_m[t].m5 = 0 << 5 | g << 2 | density;
+}
+
 #endif
--- a/landscape.c	Fri Feb 24 19:52:26 2006 +0000
+++ b/landscape.c	Fri Feb 24 19:56:24 2006 +0000
@@ -239,12 +239,7 @@
 
 void DoClearSquare(TileIndex tile)
 {
-	SetTileType(tile, MP_CLEAR);
-	SetTileOwner(tile, OWNER_NONE);
-	_m[tile].m2 = 0;
-	_m[tile].m3 = 0;
-	_m[tile].m4 = 0;
-	SetClearGroundDensity(tile, CL_GRASS, _generating_world ? 3 : 0);
+	MakeClear(tile, CL_GRASS, _generating_world ? 3 : 0);
 	MarkTileDirtyByTile(tile);
 }
 
@@ -438,12 +433,7 @@
 
 	map_size = MapSize();
 	for (i = 0; i < map_size; i++) {
-		_m[i].type_height = MP_CLEAR << 4;
-		_m[i].m1          = OWNER_NONE;
-		_m[i].m2          = 0;
-		_m[i].m3          = 0;
-		_m[i].m4          = 0;
-		_m[i].m5          = 3;
+		MakeClear(i, CL_GRASS, 3);
 		_m[i].extra       = 0;
 	}
 
--- a/terraform_gui.c	Fri Feb 24 19:52:26 2006 +0000
+++ b/terraform_gui.c	Fri Feb 24 19:56:24 2006 +0000
@@ -82,8 +82,7 @@
 
 	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 		if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
-			SetTileType(tile, MP_CLEAR);
-			SetClearGroundDensity(tile, CL_ROCKS, 3);
+			MakeClear(tile, CL_ROCKS, 3);
 			MarkTileDirtyByTile(tile);
 			success = true;
 		}
--- a/tree_cmd.c	Fri Feb 24 19:52:26 2006 +0000
+++ b/tree_cmd.c	Fri Feb 24 19:56:24 2006 +0000
@@ -515,12 +515,10 @@
 				SetTreeGrowth(tile, 3);
 			} else {
 				/* just one tree, change type into MP_CLEAR */
-				SetTileType(tile, MP_CLEAR);
-				SetTileOwner(tile, OWNER_NONE);
 				switch (GetTreeGround(tile)) {
-					case TR_GRASS: SetClearGroundDensity(tile, CL_GRASS, 3); break;
-					case TR_ROUGH: SetClearGroundDensity(tile, CL_ROUGH, 3); break;
-					default:       SetClearGroundDensity(tile, CL_SNOW, GetTreeDensity(tile)); break;
+					case TR_GRASS: MakeClear(tile, CL_GRASS, 3); break;
+					case TR_ROUGH: MakeClear(tile, CL_ROUGH, 3); break;
+					default:       MakeClear(tile, CL_SNOW, GetTreeDensity(tile)); break;
 				}
 			}
 			break;