(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
authorcelestar
Thu, 30 Mar 2006 11:11:35 +0000
changeset 3372 e9eaf986b264
parent 3371 919a6f9f4ed8
child 3373 f95cf3549591
(svn r4171) -Codechange: Create map accessor functions for creating ship depots and locks. Make use of them
water_cmd.c
water_map.h
--- a/water_cmd.c	Thu Mar 30 11:05:05 2006 +0000
+++ b/water_cmd.c	Thu Mar 30 11:11:35 2006 +0000
@@ -90,15 +90,10 @@
 		_last_built_ship_depot_tile = tile;
 		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
 
-		ModifyTile(tile,
-			MP_SETTYPE(MP_WATER) | MP_MAPOWNER_CURRENT | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,
-			(0x80 + p1*2)
-		);
-
-		ModifyTile(tile2,
-			MP_SETTYPE(MP_WATER) | MP_MAPOWNER_CURRENT | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,
-			(0x81 + p1*2)
-		);
+		MakeShipDepot(tile,_current_player, DEPOT_NORTH, p1);
+		MakeShipDepot(tile2,_current_player, DEPOT_SOUTH, p1);
+		MarkTileDirtyByTile(tile);
+		MarkTileDirtyByTile(tile2);
 	}
 
 	return cost + _price.build_ship_depot;
@@ -150,9 +145,10 @@
 	if (GetTileSlope(tile + delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 
 	if (flags & DC_EXEC) {
-		ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x10 + dir);
-		ModifyTile(tile - delta, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x14 + dir);
-		ModifyTile(tile + delta, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0x18 + dir);
+		MakeLock(tile, dir);
+		MarkTileDirtyByTile(tile);
+		MarkTileDirtyByTile(tile - delta);
+		MarkTileDirtyByTile(tile + delta);
 	}
 
 	return _price.clear_water * 22 >> 3;
--- a/water_map.h	Thu Mar 30 11:05:05 2006 +0000
+++ b/water_map.h	Thu Mar 30 11:11:35 2006 +0000
@@ -3,6 +3,17 @@
 #ifndef WATER_MAP_H
 #define WATER_MAP_H
 
+typedef enum DepotPart {
+	DEPOT_NORTH = 0x80,
+	DEPOT_SOUTH = 0x81
+} DepotPart;
+
+typedef enum LockPart {
+	LOCK_MIDDLE = 0x10,
+	LOCK_LOWER  = 0x14,
+	LOCK_UPPER  = 0x18
+} LockPart;
+
 static inline void MakeWater(TileIndex t)
 {
 	SetTileType(t, MP_WATER);
@@ -24,4 +35,33 @@
 	_m[t].m5 = 1;
 }
 
+static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a)
+{
+	SetTileType(t, MP_WATER);
+	SetTileOwner(t, o);
+	_m[t].m2 = 0;
+	_m[t].m3 = 0;
+	_m[t].m4 = 0;
+	_m[t].m5 = base + a * 2;
+}
+
+static inline void MakeLockTile(TileIndex t, byte section)
+{
+	SetTileType(t, MP_WATER);
+	SetTileOwner(t, OWNER_WATER);
+	_m[t].m2 = 0;
+	_m[t].m3 = 0;
+	_m[t].m4 = 0;
+	_m[t].m5 = section;
+}
+
+static inline void MakeLock(TileIndex t, DiagDirection d)
+{
+	TileIndexDiff delta = TileOffsByDir(d);
+
+	MakeLockTile(t, LOCK_MIDDLE + d);
+	MakeLockTile(t - delta, LOCK_LOWER + d);
+	MakeLockTile(t + delta, LOCK_UPPER + d);
+}
+
 #endif