summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-10-16 19:48:58 +0000
committerrubidium <rubidium@openttd.org>2007-10-16 19:48:58 +0000
commitba7c595d846245659c569e0510c3642e88d6992c (patch)
tree45653866becd6ad493d17cf4b6e65801597a47b5 /src
parent4f512a70c360e2aa45e80aacdbcc95d2a754b987 (diff)
downloadopenttd-ba7c595d846245659c569e0510c3642e88d6992c.tar.xz
(svn r11276) -Codechange: be more consistent with naming of some accessors.
-Fix: make sure canals are never owned by water. Based on a patch by boekabart.
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp4
-rw-r--r--src/openttd.cpp15
-rw-r--r--src/station_cmd.cpp4
-rw-r--r--src/station_map.h9
-rw-r--r--src/town_cmd.cpp6
-rw-r--r--src/tunnelbridge_cmd.cpp2
-rw-r--r--src/water_cmd.cpp14
-rw-r--r--src/water_map.h15
8 files changed, 52 insertions, 17 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 788396d4b..7dfb5e38b 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1236,11 +1236,11 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable
/* As soon as the tile is not water, bail out.
* But that does not mean the search is over. You have
* to make sure every tile of the industry will be only water*/
- if (!IsClearWaterTile(cur_tile)) return false;
+ if (!IsWaterTile(cur_tile)) return false;
} else {
Slope tileh;
- if (IsClearWaterTile(cur_tile)) return false;
+ if (IsWaterTile(cur_tile)) return false;
tileh = GetTileSlope(cur_tile, NULL);
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 1b6407720..af3360b78 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1626,7 +1626,7 @@ bool AfterLoadGame()
if (GB(_m[t].m5, 3, 2) == 0) {
MakeClear(t, CLEAR_GRASS, 3);
} else {
- MakeCanal(t, GetTileOwner(t));
+ MakeCanal(t, (GetTileOwner(t) == OWNER_WATER) ? OWNER_NONE : GetTileOwner(t));
}
}
SetBridgeMiddle(t, axis);
@@ -2160,6 +2160,19 @@ bool AfterLoadGame()
FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE;
}
+ /* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
+ Replace the owner for those by OWNER_NONE. */
+ if (CheckSavegameVersion(82)) {
+ for (TileIndex t = 0; t < map_size; t++) {
+ if (IsTileType(t, MP_WATER) &&
+ GetWaterTileType(t) == WATER_TILE_CLEAR &&
+ GetTileOwner(t) == OWNER_WATER &&
+ TileHeight(t) != 0) {
+ SetTileOwner(t, OWNER_NONE);
+ }
+ }
+ }
+
/* Recalculate */
Group *g;
FOR_ALL_GROUPS(g) {
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 838e89200..5e83674b4 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1769,7 +1769,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
- if (!IsClearWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
+ if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
/* allocate and initialize new station */
@@ -2088,7 +2088,7 @@ static void DrawTile_Station(TileInfo *ti)
DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
}
- if (IsBuoyTile(ti->tile) && (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER))) DrawCanalWater(ti->tile);
+ if (IsCanalBuoyTile(ti->tile)) DrawCanalWater(ti->tile);
const DrawTileSeqStruct *dtss;
foreach_draw_tile_seq(dtss, t->seq) {
diff --git a/src/station_map.h b/src/station_map.h
index dd81c3f08..05d3abcba 100644
--- a/src/station_map.h
+++ b/src/station_map.h
@@ -154,6 +154,15 @@ static inline bool IsBuoyTile(TileIndex t)
return IsTileType(t, MP_STATION) && IsBuoy(t);
}
+static inline bool IsCanalBuoyTile(TileIndex t)
+{
+ return IsBuoyTile(t) && !IsTileOwner(t, OWNER_WATER);
+}
+
+static inline bool IsSeaBuoyTile(TileIndex t)
+{
+ return IsBuoyTile(t) && IsTileOwner(t, OWNER_WATER);
+}
static inline bool IsHangarTile(TileIndex t)
{
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 7771e541b..aaeb518cb 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -933,7 +933,7 @@ static bool GrowTownWithBridge(const Town *t, TileIndex tile, RoadBits rcmd)
return false;
}
bridge_tile = TILE_MASK(bridge_tile + TileOffsByDiagDir(bridge_dir));
- } while (IsClearWaterTile(bridge_tile));
+ } while (IsWaterTile(bridge_tile));
/* no water tiles in between? */
if (bridge_length == 1) return false;
@@ -1072,7 +1072,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
TileIndex house_tile = TileAddByDiagDir(tile, target_dir); // position of a possible house
/* Don't walk into water. */
- if (IsClearWaterTile(house_tile)) return;
+ if (IsWaterTile(house_tile)) return;
switch (_patches.town_layout) {
default: NOT_REACHED();
@@ -1121,7 +1121,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
}
/* Return if a water tile */
- if (IsClearWaterTile(tile)) return;
+ if (IsWaterTile(tile)) return;
/* Make the roads look nicer */
rcmd = CleanUpRoadBits(tile, rcmd);
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 8a3ea905e..334898a7c 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -243,7 +243,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p
/* retrieve landscape height and ensure it's on land */
tile_start = TileXY(x, y);
tile_end = TileXY(sx, sy);
- if (IsClearWaterTile(tile_start) || IsClearWaterTile(tile_end)) {
+ if (IsWaterTile(tile_start) || IsWaterTile(tile_end)) {
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
}
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 387cfe6f1..d58003fab 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -72,7 +72,7 @@ CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
- if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2))
+ if (!IsWaterTile(tile) || !IsWaterTile(tile2))
return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
@@ -458,7 +458,7 @@ static void DrawTile_Water(TileInfo *ti)
switch (GetWaterTileType(ti->tile)) {
case WATER_TILE_CLEAR:
DrawGroundSprite(SPR_FLAT_WATER_TILE, PAL_NONE);
- if (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER)) DrawCanalWater(ti->tile);
+ if (IsCanal(ti->tile)) DrawCanalWater(ti->tile);
DrawBridgeMiddle(ti);
break;
@@ -518,7 +518,7 @@ static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
{
switch (GetWaterTileType(tile)) {
case WATER_TILE_CLEAR:
- if (TilePixelHeight(tile) == 0 || IsTileOwner(tile, OWNER_WATER)) {
+ if (!IsCanal(tile)) {
td->str = STR_3804_WATER;
} else {
td->str = STR_LANDINFO_CANAL;
@@ -725,8 +725,10 @@ void TileLoop_Water(TileIndex tile)
{{ 0, -1}, {0, 0}, {1, 0}, { 0, -1}, { 1, -1}}
};
- /* Ensure sea-level canals and buoys on canal borders do not flood */
- if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && !IsTileOwner(tile, OWNER_WATER)) return;
+ /* Ensure buoys on canal borders do not flood */
+ if (IsCanalBuoyTile(tile)) return;
+ /* Ensure only sea and coast floods, not canals or rivers */
+ if (IsTileType(tile, MP_WATER) && !(IsSea(tile) || IsCoast(tile))) return;
/* floods in all four diagonal directions with the exception of the edges */
if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) &&
@@ -815,7 +817,7 @@ static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y)
static CommandCost TerraformTile_Water(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
{
/* Canals can't be terraformed */
- if (IsClearWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST);
+ if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST);
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
}
diff --git a/src/water_map.h b/src/water_map.h
index 77fce0a17..b1c8f4c16 100644
--- a/src/water_map.h
+++ b/src/water_map.h
@@ -27,6 +27,8 @@ enum LockPart {
static inline WaterTileType GetWaterTileType(TileIndex t)
{
+ assert(IsTileType(t, MP_WATER));
+
if (_m[t].m5 == 0) return WATER_TILE_CLEAR;
if (_m[t].m5 == 1) return WATER_TILE_COAST;
if (IS_INT_INSIDE(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_TILE_LOCK;
@@ -35,11 +37,19 @@ static inline WaterTileType GetWaterTileType(TileIndex t)
return WATER_TILE_DEPOT;
}
+/** IsWater return true if any type of clear water like ocean, river, canal */
static inline bool IsWater(TileIndex t)
{
return GetWaterTileType(t) == WATER_TILE_CLEAR;
}
+static inline bool IsSea(TileIndex t)
+{
+ if (GetWaterTileType(t) != WATER_TILE_CLEAR) return false;
+ if (!IsTileOwner(t, OWNER_WATER)) return false; // 'Human' built water = canal, not sea
+ return true;
+}
+
static inline bool IsCoast(TileIndex t)
{
return GetWaterTileType(t) == WATER_TILE_COAST;
@@ -50,9 +60,9 @@ static inline bool IsCanal(TileIndex t)
return GetWaterTileType(t) == WATER_TILE_CLEAR && GetTileOwner(t) != OWNER_WATER;
}
-static inline bool IsClearWaterTile(TileIndex t)
+static inline bool IsWaterTile(TileIndex t)
{
- return IsTileType(t, MP_WATER) && IsWater(t) && GetTileSlope(t, NULL) == SLOPE_FLAT;
+ return IsTileType(t, MP_WATER) && IsWater(t);
}
static inline TileIndex GetOtherShipDepotTile(TileIndex t)
@@ -109,6 +119,7 @@ static inline void MakeShore(TileIndex t)
static inline void MakeCanal(TileIndex t, Owner o)
{
+ assert(o != OWNER_WATER);
SetTileType(t, MP_WATER);
SetTileOwner(t, o);
_m[t].m2 = 0;