diff options
author | frosch <frosch@openttd.org> | 2009-03-21 21:43:23 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-03-21 21:43:23 +0000 |
commit | d452a0a0ecaad276c893b62ab8f008a5af85ba82 (patch) | |
tree | 2816e5ec1ae12fd5f4cd0391c375c34b91225291 /src/ai/api | |
parent | fd0f0bda721269e27950431db44886b309ef4596 (diff) | |
download | openttd-d452a0a0ecaad276c893b62ab8f008a5af85ba82.tar.xz |
(svn r15789) -Codechange: Add DiagdirBetweenTiles() and use it.
Diffstat (limited to 'src/ai/api')
-rw-r--r-- | src/ai/api/ai_bridge.cpp | 4 | ||||
-rw-r--r-- | src/ai/api/ai_marine.cpp | 3 | ||||
-rw-r--r-- | src/ai/api/ai_tunnel.cpp | 4 |
3 files changed, 5 insertions, 6 deletions
diff --git a/src/ai/api/ai_bridge.cpp b/src/ai/api/ai_bridge.cpp index 58c52245e..27f5c116e 100644 --- a/src/ai/api/ai_bridge.cpp +++ b/src/ai/api/ai_bridge.cpp @@ -92,7 +92,7 @@ static void _DoCommandReturnBuildBridge1(class AIInstance *instance) TileIndex end = AIObject::GetCallbackVariable(0); TileIndex start = AIObject::GetCallbackVariable(1); - DiagDirection dir_1 = (DiagDirection)((::TileX(start) == ::TileX(end)) ? (::TileY(start) < ::TileY(end) ? DIAGDIR_NW : DIAGDIR_SE) : (::TileX(start) < ::TileX(end) ? DIAGDIR_NE : DIAGDIR_SW)); + DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); if (!AIObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (AIObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &_DoCommandReturnBuildBridge2)) return false; @@ -107,7 +107,7 @@ static void _DoCommandReturnBuildBridge1(class AIInstance *instance) TileIndex end = AIObject::GetCallbackVariable(0); TileIndex start = AIObject::GetCallbackVariable(1); - DiagDirection dir_1 = (DiagDirection)((::TileX(start) == ::TileX(end)) ? (::TileY(start) < ::TileY(end) ? DIAGDIR_NW : DIAGDIR_SE) : (::TileX(start) < ::TileX(end) ? DIAGDIR_NE : DIAGDIR_SW)); + DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); return AIObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (AIObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD); diff --git a/src/ai/api/ai_marine.cpp b/src/ai/api/ai_marine.cpp index fb9bba882..fffa1e3a3 100644 --- a/src/ai/api/ai_marine.cpp +++ b/src/ai/api/ai_marine.cpp @@ -50,9 +50,8 @@ /* Tiles not neighbouring */ if (::DistanceManhattan(t1, t2) != 1) return false; - if (t1 > t2) Swap(t1, t2); - DiagDirection to_other_tile = (TileX(t1) == TileX(t2)) ? DIAGDIR_SE : DIAGDIR_SW; + DiagDirection to_other_tile = ::DiagdirBetweenTiles(t1, t2); /* Determine the reachable tracks from the shared edge */ TrackBits gtts2 = ::TrackStatusToTrackBits(::GetTileTrackStatus(t2, TRANSPORT_WATER, 0, to_other_tile)) & ::DiagdirReachesTracks(to_other_tile); diff --git a/src/ai/api/ai_tunnel.cpp b/src/ai/api/ai_tunnel.cpp index 2b1fb1e31..cc7d95606 100644 --- a/src/ai/api/ai_tunnel.cpp +++ b/src/ai/api/ai_tunnel.cpp @@ -86,7 +86,7 @@ static void _DoCommandReturnBuildTunnel1(class AIInstance *instance) TileIndex end = AIObject::GetCallbackVariable(0); TileIndex start = AITunnel::GetOtherTunnelEnd(end); - DiagDirection dir_1 = (DiagDirection)((::TileX(start) == ::TileX(end)) ? (::TileY(start) < ::TileY(end) ? DIAGDIR_NW : DIAGDIR_SE) : (::TileX(start) < ::TileX(end) ? DIAGDIR_NE : DIAGDIR_SW)); + DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); if (!AIObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (AIObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &_DoCommandReturnBuildTunnel2)) return false; @@ -101,7 +101,7 @@ static void _DoCommandReturnBuildTunnel1(class AIInstance *instance) TileIndex end = AIObject::GetCallbackVariable(0); TileIndex start = AITunnel::GetOtherTunnelEnd(end); - DiagDirection dir_1 = (DiagDirection)((::TileX(start) == ::TileX(end)) ? (::TileY(start) < ::TileY(end) ? DIAGDIR_NW : DIAGDIR_SE) : (::TileX(start) < ::TileX(end) ? DIAGDIR_NE : DIAGDIR_SW)); + DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); return AIObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (AIObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD); |