src/tunnelbridge_cmd.cpp
changeset 8894 1e5b2d4380b8
parent 8886 9f2c7ebc7fc9
child 8909 fa15e9afad2f
--- a/src/tunnelbridge_cmd.cpp	Wed Jan 23 20:02:30 2008 +0000
+++ b/src/tunnelbridge_cmd.cpp	Wed Jan 23 22:34:04 2008 +0000
@@ -32,6 +32,7 @@
 #include "vehicle_func.h"
 #include "sound_func.h"
 #include "signal_func.h"
+#include "tunnelbridge.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
@@ -160,17 +161,6 @@
 	return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 }
 
-
-uint32 GetBridgeLength(TileIndex begin, TileIndex end)
-{
-	int x1 = TileX(begin);
-	int y1 = TileY(begin);
-	int x2 = TileX(end);
-	int y2 = TileY(end);
-
-	return abs(x2 + y2 - x1 - y1) - 1;
-}
-
 bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
 {
 	const Bridge *b = &_bridge[bridge_type];
@@ -633,7 +623,7 @@
 			DoClearSquare(endtile);
 		}
 	}
-	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (DistanceManhattan(tile, endtile) + 1));
+	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (GetTunnelBridgeLength(tile, endtile) + 2));
 }
 
 
@@ -693,7 +683,7 @@
 		}
 	}
 
-	return CommandCost(EXPENSES_CONSTRUCTION, (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge);
+	return CommandCost(EXPENSES_CONSTRUCTION, (GetTunnelBridgeLength(tile, endtile) + 2) * _price.clear_bridge);
 }
 
 static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
@@ -1018,8 +1008,8 @@
 
 	axis = GetBridgeAxis(ti->tile);
 	piece = CalcBridgePiece(
-		DistanceManhattan(ti->tile, rampnorth),
-		DistanceManhattan(ti->tile, rampsouth)
+		GetTunnelBridgeLength(ti->tile, rampnorth) + 1,
+		GetTunnelBridgeLength(ti->tile, rampsouth) + 1
 	);
 	type = GetBridgeType(rampsouth);