summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/station_cmd.cpp22
-rw-r--r--src/station_func.h1
-rw-r--r--src/water_cmd.cpp2
4 files changed, 25 insertions, 2 deletions
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 73f2ee97f..7b6be3a41 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -612,7 +612,7 @@ bool IsShipDestinationTile(TileIndex tile, StationID station)
for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
TileIndex t = tile + TileOffsByDiagDir(d);
if (!IsValidTile(t)) continue;
- if (IsDockTile(t) && GetStationIndex(t) == station) return true;
+ if (IsDockTile(t) && GetStationIndex(t) == station && IsValidDockingDirectionForDock(t, d)) return true;
if (IsTileType(t, MP_INDUSTRY)) {
const Industry *i = Industry::GetByTile(t);
if (i->neutral_station != nullptr && i->neutral_station->index == station) return true;
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index a7d986676..546aecc26 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2632,6 +2632,28 @@ void ClearDockingTilesCheckingNeighbours(TileIndex tile)
}
/**
+ * Check if a dock tile can be docked from the given direction.
+ * @param t Tile index of dock.
+ * @param d DiagDirection adjacent to dock being tested.
+ * @return True iff the dock can be docked from the given direction.
+ */
+bool IsValidDockingDirectionForDock(TileIndex t, DiagDirection d)
+{
+ assert(IsDockTile(t));
+
+ /** Bitmap of valid directions for each dock tile part. */
+ static const uint8 _valid_docking_tile[] = {
+ 0, 0, 0, 0, // No docking against the slope part.
+ 1 << DIAGDIR_NE | 1 << DIAGDIR_SW, // Docking permitted at the end
+ 1 << DIAGDIR_NW | 1 << DIAGDIR_SE, // of the flat piers.
+ };
+
+ StationGfx gfx = GetStationGfx(t);
+ assert(gfx < lengthof(_valid_docking_tile));
+ return HasBit(_valid_docking_tile[gfx], d);
+}
+
+/**
* Find the part of a dock that is land-based
* @param t Dock tile to find land part of
* @return tile of land part of dock
diff --git a/src/station_func.h b/src/station_func.h
index 44aec087f..86aae1e56 100644
--- a/src/station_func.h
+++ b/src/station_func.h
@@ -43,6 +43,7 @@ void DeleteOilRig(TileIndex t);
void UpdateStationDockingTiles(Station *st);
void RemoveDockingTile(TileIndex t);
void ClearDockingTilesCheckingNeighbours(TileIndex tile);
+bool IsValidDockingDirectionForDock(TileIndex t, DiagDirection d);
/* Check if a rail station tile is traversable. */
bool IsStationTileBlocked(TileIndex tile);
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 158bd13f0..7091f9f2d 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -187,7 +187,7 @@ void CheckForDockingTile(TileIndex t)
TileIndex tile = t + TileOffsByDiagDir(d);
if (!IsValidTile(tile)) continue;
- if (IsDockTile(tile)) {
+ if (IsDockTile(tile) && IsValidDockingDirectionForDock(tile, d)) {
Station::GetByTile(tile)->docking_station.Add(t);
SetDockingTile(t, true);
}