src/npf.cpp
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6743 cabfaa4a0295
child 6872 1c4a4a609f85
--- a/src/npf.cpp	Sat Oct 06 21:16:00 2007 +0000
+++ b/src/npf.cpp	Mon Dec 03 23:39:38 2007 +0000
@@ -40,8 +40,8 @@
  */
 static uint NPFDistanceTrack(TileIndex t0, TileIndex t1)
 {
-	const uint dx = delta(TileX(t0), TileX(t1));
-	const uint dy = delta(TileY(t0), TileY(t1));
+	const uint dx = Delta(TileX(t0), TileX(t1));
+	const uint dy = Delta(TileY(t0), TileY(t1));
 
 	const uint straightTracks = 2 * min(dx, dy); /* The number of straight (not full length) tracks */
 	/* OPTIMISATION:
@@ -104,10 +104,10 @@
 
 	/* we are going the aim for the x coordinate of the closest corner
 	 * but if we are between those coordinates, we will aim for our own x coordinate */
-	x = clamp(TileX(tile), minx, maxx);
+	x = Clamp(TileX(tile), minx, maxx);
 
 	/* same for y coordinate, see above comment */
-	y = clamp(TileY(tile), miny, maxy);
+	y = Clamp(TileY(tile), miny, maxy);
 
 	/* return the tile of our target coordinates */
 	return TileXY(x, y);
@@ -192,18 +192,21 @@
 static uint NPFSlopeCost(AyStarNode* current)
 {
 	TileIndex next = current->tile + TileOffsByDiagDir(TrackdirToExitdir((Trackdir)current->direction));
-	int x,y;
-	int8 z1,z2;
 
-	x = TileX(current->tile) * TILE_SIZE;
-	y = TileY(current->tile) * TILE_SIZE;
-	/* get the height of the center of the current tile */
-	z1 = GetSlopeZ(x + TILE_SIZE / 2, y + TILE_SIZE / 2);
+	/* Get center of tiles */
+	int x1 = TileX(current->tile) * TILE_SIZE + TILE_SIZE / 2;
+	int y1 = TileY(current->tile) * TILE_SIZE + TILE_SIZE / 2;
+	int x2 = TileX(next) * TILE_SIZE + TILE_SIZE / 2;
+	int y2 = TileY(next) * TILE_SIZE + TILE_SIZE / 2;
 
-	x = TileX(next) * TILE_SIZE;
-	y = TileY(next) * TILE_SIZE;
-	/* get the height of the center of the next tile */
-	z2 = GetSlopeZ(x + TILE_SIZE / 2, y + TILE_SIZE / 2);
+	int dx4 = (x2 - x1) / 4;
+	int dy4 = (y2 - y1) / 4;
+
+	/* Get the height on both sides of the tile edge.
+	 * Avoid testing the height on the tile-center. This will fail for halftile-foundations.
+	 */
+	int z1 = GetSlopeZ(x1 + dx4, y1 + dy4);
+	int z2 = GetSlopeZ(x2 - dx4, y2 - dy4);
 
 	if (z2 - z1 > 1) {
 		/* Slope up */
@@ -599,7 +602,7 @@
 	/* check correct rail type (mono, maglev, etc) */
 	if (type == TRANSPORT_RAIL) {
 		RailType dst_type = GetTileRailType(dst_tile);
-		if (!HASBIT(aystar->user_data[NPF_RAILTYPES], dst_type))
+		if (!HasBit(aystar->user_data[NPF_RAILTYPES], dst_type))
 			return;
 	}