tunnelbridge_cmd.c
changeset 4273 6467c2c54d58
parent 4261 2ec8f5a9747b
child 4276 86604f15f27f
--- a/tunnelbridge_cmd.c	Mon Aug 14 23:27:06 2006 +0000
+++ b/tunnelbridge_cmd.c	Tue Aug 15 00:14:57 2006 +0000
@@ -465,8 +465,12 @@
 
 	ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 	if (CmdFailed(ret)) return ret;
-	cost = _price.build_tunnel + ret;
 
+	/* XXX - do NOT change 'ret' in the loop, as it is used as the price
+	 * for the clearing of the entrance of the tunnel. Assigning it to
+	 * cost before the loop will yield different costs depending on start-
+	 * position, because of increased-cost-by-length: 'cost += cost >> 3' */
+	cost = 0;
 	delta = TileOffsByDir(direction);
 	end_tile = start_tile;
 	for (;;) {
@@ -480,10 +484,13 @@
 		}
 
 		cost += _price.build_tunnel;
-		cost += cost >> 3;
+		cost += cost >> 3; // add a multiplier for longer tunnels
 		if (cost >= 400000000) cost = 400000000;
 	}
 
+	/* Add the cost of the entrance */
+	cost += _price.build_tunnel + ret;
+
 	// if the command fails from here on we want the end tile to be highlighted
 	_build_tunnel_endtile = end_tile;