--- a/bin/ai/library/pathfinder/road/main.nut Fri Jun 20 23:12:21 2008 +0000
+++ b/bin/ai/library/pathfinder/road/main.nut Sat Jun 21 01:16:33 2008 +0000
@@ -231,15 +231,15 @@
local other_end = AIBridge.IsBridgeTile(cur_node) ? AIBridge.GetOtherBridgeEnd(cur_node) : AITunnel.GetOtherTunnelEnd(cur_node);
local next_tile = cur_node + (cur_node - other_end) / AIMap.DistanceManhattan(cur_node, other_end);
if (AIRoad.AreRoadTilesConnected(cur_node, next_tile) || AITile.IsBuildable(next_tile) || AIRoad.IsRoadTile(next_tile)) {
- tiles.push([next_tile, self._GetDirection(cur_node, next_tile)]);
+ tiles.push([next_tile, self._GetDirection(cur_node, next_tile, false)]);
}
/* The other end of the bridge / tunnel is a neighbour. */
- tiles.push([other_end, self._GetDirection(next_tile, cur_node) << 4]);
+ tiles.push([other_end, self._GetDirection(next_tile, cur_node, true) << 4]);
} else if (path.GetParent() != null && AIMap.DistanceManhattan(cur_node, path.GetParent().GetTile()) > 1) {
local other_end = path.GetParent().GetTile();
local next_tile = cur_node + (cur_node - other_end) / AIMap.DistanceManhattan(cur_node, other_end);
if (AIRoad.AreRoadTilesConnected(cur_node, next_tile) || AIRoad.BuildRoad(cur_node, next_tile)) {
- tiles.push([next_tile, self._GetDirection(cur_node, next_tile)]);
+ tiles.push([next_tile, self._GetDirection(cur_node, next_tile, false)]);
}
} else {
local offsets = [AIMap.GetTileIndex(0, 1), AIMap.GetTileIndex(0, -1),
@@ -252,17 +252,17 @@
* 2) We can build a road to the next tile.
* 3) The next tile is the entrance of a tunnel / bridge in the correct direction. */
if (AIRoad.AreRoadTilesConnected(cur_node, next_tile)) {
- tiles.push([next_tile, self._GetDirection(cur_node, next_tile)]);
+ tiles.push([next_tile, self._GetDirection(cur_node, next_tile, false)]);
} else if ((AITile.IsBuildable(next_tile) || AIRoad.IsRoadTile(next_tile)) &&
(path.GetParent() == null || AIRoad.CanBuildConnectedRoadPartsHere(cur_node, path.GetParent().GetTile(), next_tile)) &&
AIRoad.BuildRoad(cur_node, next_tile)) {
- tiles.push([next_tile, self._GetDirection(cur_node, next_tile)]);
+ tiles.push([next_tile, self._GetDirection(cur_node, next_tile, false)]);
} else if (self._CheckTunnelBridge(cur_node, next_tile)) {
- tiles.push([next_tile, self._GetDirection(cur_node, next_tile)]);
+ tiles.push([next_tile, self._GetDirection(cur_node, next_tile, false)]);
}
}
if (path.GetParent() != null) {
- local bridges = self._GetTunnelsBridges(path.GetParent().GetTile(), cur_node, self._GetDirection(path.GetParent().GetTile(), cur_node) << 4);
+ local bridges = self._GetTunnelsBridges(path.GetParent().GetTile(), cur_node, self._GetDirection(path.GetParent().GetTile(), cur_node, true) << 4);
foreach (tile in bridges) {
tiles.push(tile);
}
@@ -276,8 +276,9 @@
return false;
}
-function Road::_GetDirection(from, to)
+function Road::_GetDirection(from, to, is_bridge)
{
+ if (!is_bridge && AITile.GetSlope(to) == AITile.SLOPE_FLAT) return 0xFF;
if (from - to == 1) return 1;
if (from - to == -1) return 2;
if (from - to == AIMap.GetMapSizeX()) return 4;