summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-12-07 21:14:54 +0000
committerrubidium <rubidium@openttd.org>2007-12-07 21:14:54 +0000
commitcbb2d39860a847687019ab47095646e593fb5bc8 (patch)
tree564b72840ffd1f1485b52afdcd03fc9e08aaab24 /src
parentc21f588a14f30fed3d683b4686975670adaf7ed5 (diff)
downloadopenttd-cbb2d39860a847687019ab47095646e593fb5bc8.tar.xz
(svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
Diffstat (limited to 'src')
-rw-r--r--src/openttd.cpp14
-rw-r--r--src/saveload.cpp2
-rw-r--r--src/water_cmd.cpp23
-rw-r--r--src/water_map.h9
4 files changed, 39 insertions, 9 deletions
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 6a431e629..6df56e31b 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -2203,6 +2203,20 @@ bool AfterLoadGame()
}
}
+ /*
+ * Add the 'previous' owner to the ship depots so we can reset it with
+ * the correct values when it gets destroyed. This prevents that
+ * someone can remove canals owned by somebody else and it prevents
+ * making floods using the removal of ship depots.
+ */
+ if (CheckSavegameVersion(83)) {
+ for (TileIndex t = 0; t < map_size; t++) {
+ if (IsTileType(t, MP_WATER) && IsShipDepot(t)) {
+ _m[t].m4 = (TileHeight(t) == 0) ? OWNER_WATER : OWNER_NONE;
+ }
+ }
+ }
+
if (CheckSavegameVersion(74)) {
Station *st;
FOR_ALL_STATIONS(st) {
diff --git a/src/saveload.cpp b/src/saveload.cpp
index 5a17a822b..7358f6a32 100644
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -29,7 +29,7 @@
#include "strings.h"
#include <list>
-extern const uint16 SAVEGAME_VERSION = 82;
+extern const uint16 SAVEGAME_VERSION = 83;
uint16 _sl_version; ///< the major savegame version identifier
byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 7b388ae3f..e6d1904bb 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -81,8 +81,8 @@ void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o)
for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
TileIndex neighbour = TileAddByDiagDir(t, dir);
if (IsTileType(neighbour, MP_WATER)) {
- has_water |= IsSea(neighbour) || IsCoast(neighbour);
- has_canal |= IsCanal(neighbour);
+ has_water |= IsSea(neighbour) || IsCoast(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) == OWNER_WATER);
+ has_canal |= IsCanal(neighbour) || (IsShipDepot(neighbour) && GetShipDepotWaterOwner(neighbour) != OWNER_WATER);
}
}
if (has_canal || !has_water) {
@@ -116,6 +116,8 @@ CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
+ 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);
@@ -128,8 +130,8 @@ CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
if (flags & DC_EXEC) {
depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
- MakeShipDepot(tile, _current_player, DEPOT_NORTH, axis);
- MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis);
+ MakeShipDepot(tile, _current_player, DEPOT_NORTH, axis, o1);
+ MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis, o2);
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(tile2);
d_auto_delete.Detach();
@@ -138,6 +140,15 @@ CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
return cost.AddCost(_price.build_ship_depot);
}
+static void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o)
+{
+ if (o == OWNER_WATER) {
+ MakeWater(tile);
+ } else {
+ MakeCanal(tile, o);
+ }
+}
+
static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
{
TileIndex tile2;
@@ -154,8 +165,8 @@ static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
/* Kill the depot, which is registered at the northernmost tile. Use that one */
delete GetDepotByTile(tile2 < tile ? tile2 : tile);
- MakeWater(tile);
- MakeWater(tile2);
+ MakeWaterOrCanalDependingOnOwner(tile, GetShipDepotWaterOwner(tile));
+ MakeWaterOrCanalDependingOnOwner(tile2, GetShipDepotWaterOwner(tile2));
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(tile2);
}
diff --git a/src/water_map.h b/src/water_map.h
index 5d1a60c1d..c4c131173 100644
--- a/src/water_map.h
+++ b/src/water_map.h
@@ -85,6 +85,11 @@ static inline DiagDirection GetShipDepotDirection(TileIndex t)
return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1));
}
+static inline Owner GetShipDepotWaterOwner(TileIndex t)
+{
+ return (Owner)_m[t].m4;
+}
+
static inline DiagDirection GetLockDirection(TileIndex t)
{
return (DiagDirection)GB(_m[t].m5, 0, 2);
@@ -128,13 +133,13 @@ static inline void MakeCanal(TileIndex t, Owner o)
_m[t].m5 = 0;
}
-static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a)
+static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, Owner original_owner)
{
SetTileType(t, MP_WATER);
SetTileOwner(t, o);
_m[t].m2 = 0;
_m[t].m3 = 0;
- _m[t].m4 = 0;
+ _m[t].m4 = original_owner;
_m[t].m5 = base + a * 2;
}