(svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
authorfrosch
Wed, 06 Feb 2008 15:32:06 +0000
changeset 8991 072c784ccb82
parent 8990 dcaad4072e7b
child 8992 4fa931bf2417
(svn r12070) -Cleanup(r12042): Water-owner of shipdepots is no longer needed. Removed.
docs/landscape.html
docs/landscape_grid.html
src/openttd.cpp
src/water_cmd.cpp
src/water_map.h
--- a/docs/landscape.html	Wed Feb 06 03:01:29 2008 +0000
+++ b/docs/landscape.html	Wed Feb 06 15:32:06 2008 +0000
@@ -908,7 +908,6 @@
     <ul>
      <li>m1: <a href="#OwnershipInfo">owner</a> (for sea, rivers, and coasts normally <tt>11</tt>)</li>
      <li>m3 bits 1..0 : Water class (sea, canal or river)
-     <li>m4: Owner of the water when ship depot</li>
      <li>m4: Random data for canal or river tiles</li>
      <li>m5: tile type:
       <table>
--- a/docs/landscape_grid.html	Wed Feb 06 03:01:29 2008 +0000
+++ b/docs/landscape_grid.html	Wed Feb 06 15:32:06 2008 +0000
@@ -284,7 +284,7 @@
       <td class="bits">-inherit-</td>
       <td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
       <td class="bits"><span class="free">OOOO OO</span>XX</td>
-      <td class="bits">XXXX XXXX</td>
+      <td class="bits"><span class="free">OOOO OOOO</span></td>
       <td class="bits">-inherit-</td>
       <td class="bits">XX<span class="free">OO OO</span>XX</td>
       <td class="bits"><span class="free">OOOO OOOO</span></td>
--- a/src/openttd.cpp	Wed Feb 06 03:01:29 2008 +0000
+++ b/src/openttd.cpp	Wed Feb 06 15:32:06 2008 +0000
@@ -2333,9 +2333,16 @@
 				if (_m[t].m5 == 2) {
 					MakeRiver(t, Random());
 				} else {
-					Owner o = GetTileOwner(t);
-					if (IsWater(t) && o != OWNER_WATER) {
-						MakeCanal(t, o, Random());
+					if (IsWater(t)) {
+						Owner o = GetTileOwner(t);
+						if (o == OWNER_WATER) {
+							MakeWater(t);
+						} else {
+							MakeCanal(t, o, Random());
+						}
+					} else if (IsShipDepot(t)) {
+						Owner o = (Owner)_m[t].m4; // Original water owner
+						SetWaterClass(t, o == OWNER_WATER ? WATER_CLASS_SEA : WATER_CLASS_CANAL);
 					}
 				}
 			}
@@ -2347,7 +2354,7 @@
 		for (TileIndex t = 0; t < map_size; t++) {
 			if (GetTileSlope(t, NULL) != SLOPE_FLAT) continue;
 
-			if (IsTileType(t, MP_WATER) && (GetWaterTileType(t) == WATER_TILE_LOCK || IsShipDepot(t))) SetWaterClassDependingOnSurroundings(t);
+			if (IsTileType(t, MP_WATER) && IsLock(t)) SetWaterClassDependingOnSurroundings(t);
 			if (IsTileType(t, MP_STATION) && (IsDock(t) || IsBuoy(t))) SetWaterClassDependingOnSurroundings(t);
 		}
 	}
--- a/src/water_cmd.cpp	Wed Feb 06 03:01:29 2008 +0000
+++ b/src/water_cmd.cpp	Wed Feb 06 15:32:06 2008 +0000
@@ -96,6 +96,9 @@
 
 /**
  * Makes a tile canal or water depending on the surroundings.
+ *
+ * Must only be used for converting old savegames. Use WaterClass now.
+ *
  * This as for example docks and shipdepots do not store
  * whether the tile used to be canal or 'normal' water.
  * @param t the tile to change.
@@ -116,9 +119,17 @@
 		TileIndex neighbour = TileAddByDiagDir(t, dir);
 		switch (GetTileType(neighbour)) {
 			case MP_WATER:
-				has_water |= IsSea(neighbour) || IsCoast(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) == OWNER_WATER);
-				has_canal |= IsCanal(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) != OWNER_WATER);
-				has_river |= IsRiver(neighbour);
+				/* clear water and shipdepots have already a WaterClass associated */
+				if (IsCoast(neighbour)) {
+					has_water = true;
+				} else if (!IsLock(neighbour)) {
+					switch (GetWaterClass(neighbour)) {
+						case WATER_CLASS_SEA:   has_water = true; break;
+						case WATER_CLASS_CANAL: has_canal = true; break;
+						case WATER_CLASS_RIVER: has_river = true; break;
+						default: NOT_REACHED();
+					}
+				}
 				break;
 
 			case MP_RAILWAY:
@@ -174,8 +185,6 @@
 
 	WaterClass wc1 = GetWaterClass(tile);
 	WaterClass wc2 = GetWaterClass(tile2);
-	Owner o1 = GetTileOwner(tile);
-	Owner o2 = GetTileOwner(tile2);
 	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 	if (CmdFailed(ret)) return CMD_ERROR;
 	ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
@@ -188,8 +197,8 @@
 	if (flags & DC_EXEC) {
 		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
 
-		MakeShipDepot(tile,  _current_player, DEPOT_NORTH, axis, wc1, o1);
-		MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis, wc2, o2);
+		MakeShipDepot(tile,  _current_player, DEPOT_NORTH, axis, wc1);
+		MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis, wc2);
 		MarkTileDirtyByTile(tile);
 		MarkTileDirtyByTile(tile2);
 		d_auto_delete.Detach();
@@ -225,8 +234,8 @@
 		/* Kill the depot, which is registered at the northernmost tile. Use that one */
 		delete GetDepotByTile(tile2 < tile ? tile2 : tile);
 
-		MakeWaterKeepingClass(tile,  GetShipDepotWaterOwner(tile));
-		MakeWaterKeepingClass(tile2, GetShipDepotWaterOwner(tile2));
+		MakeWaterKeepingClass(tile,  GetTileOwner(tile));
+		MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
 		MarkTileDirtyByTile(tile);
 		MarkTileDirtyByTile(tile2);
 	}
--- a/src/water_map.h	Wed Feb 06 03:01:29 2008 +0000
+++ b/src/water_map.h	Wed Feb 06 15:32:06 2008 +0000
@@ -106,9 +106,9 @@
 	return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1));
 }
 
-static inline Owner GetShipDepotWaterOwner(TileIndex t)
+static inline bool IsLock(TileIndex t)
 {
-	return (Owner)_m[t].m4;
+	return IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END);
 }
 
 static inline DiagDirection GetLockDirection(TileIndex t)
@@ -169,13 +169,13 @@
 	_m[t].m5 = 0;
 }
 
-static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, WaterClass original_water_class, Owner original_owner)
+static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, WaterClass original_water_class)
 {
 	SetTileType(t, MP_WATER);
 	SetTileOwner(t, o);
 	_m[t].m2 = 0;
 	_m[t].m3 = original_water_class;
-	_m[t].m4 = original_owner;
+	_m[t].m4 = 0;
 	_m[t].m5 = base + a * 2;
 }