summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-01-24 13:05:04 +0000
committerfrosch <frosch@openttd.org>2009-01-24 13:05:04 +0000
commit7e6049ba0228894b15bedec70d9056e4d1e6af3c (patch)
treec107bda544a397281ed922e3a9612104eb8f002d
parent12bcc254c8c63311a4ce483fef23e8b7f7f7d611 (diff)
downloadopenttd-7e6049ba0228894b15bedec70d9056e4d1e6af3c.tar.xz
(svn r15252) -Fix (r15027): AIMarine::AreWaterTilesConnected() reported aqueducts being connected with all surrounding tiles. Also add some type safety.
-rw-r--r--src/ai/api/ai_marine.cpp14
-rw-r--r--src/ai/api/ai_tile.cpp2
2 files changed, 8 insertions, 8 deletions
diff --git a/src/ai/api/ai_marine.cpp b/src/ai/api/ai_marine.cpp
index 274ab5f6b..d2160b4ca 100644
--- a/src/ai/api/ai_marine.cpp
+++ b/src/ai/api/ai_marine.cpp
@@ -55,16 +55,16 @@
if (::DistanceManhattan(t1, t2) != 1) return false;
if (t1 > t2) Swap(t1, t2);
- uint32 gtts1 = ::GetTileTrackStatus(t1, TRANSPORT_WATER, 0);
- uint32 gtts2 = ::GetTileTrackStatus(t2, TRANSPORT_WATER, 0);
+ DiagDirection to_other_tile = (TileX(t1) == TileX(t2)) ? DIAGDIR_SE : DIAGDIR_SW;
- /* Ship can't travel on one of the tiles. */
- if (gtts1 == 0 || gtts2 == 0) return false;
+ /* Determine the reachable tracks from the shared edge */
+ TrackBits gtts2 = ::TrackStatusToTrackBits(::GetTileTrackStatus(t2, TRANSPORT_WATER, 0, to_other_tile)) & ::DiagdirReachesTracks(to_other_tile);
+ if (gtts2 == TRACK_BIT_NONE) return false;
- DiagDirection to_other_tile = (TileX(t1) == TileX(t2)) ? DIAGDIR_SE : DIAGDIR_SW;
+ to_other_tile = ReverseDiagDir(to_other_tile);
+ TrackBits gtts1 = ::TrackStatusToTrackBits(::GetTileTrackStatus(t1, TRANSPORT_WATER, 0, to_other_tile)) & ::DiagdirReachesTracks(to_other_tile);
- /* Check whether we can 'leave' the tile at the border and 'enter' the other tile at the border */
- return (gtts1 & DiagdirReachesTrackdirs(ReverseDiagDir(to_other_tile))) != 0 && (gtts2 & DiagdirReachesTrackdirs(to_other_tile)) != 0;
+ return gtts1 != TRACK_BIT_NONE;
}
/* static */ bool AIMarine::BuildWaterDepot(TileIndex tile, bool vertical)
diff --git a/src/ai/api/ai_tile.cpp b/src/ai/api/ai_tile.cpp
index 6426c9374..04b8c0290 100644
--- a/src/ai/api/ai_tile.cpp
+++ b/src/ai/api/ai_tile.cpp
@@ -157,7 +157,7 @@
{
if (!::IsValidTile(tile)) return false;
- return GB(::GetTileTrackStatus(tile, (::TransportType)transport_type, UINT32_MAX), 0, 16) != 0;
+ return ::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, UINT32_MAX)) != TRACKDIR_BIT_NONE;
}
/* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)