src/npf.cpp
changeset 8260 c7d75cebe3f6
parent 7866 e19fda04e8d3
child 8418 b49fc6be1ab9
equal deleted inserted replaced
8259:127e5d73637d 8260:c7d75cebe3f6
   190 }
   190 }
   191 
   191 
   192 static uint NPFSlopeCost(AyStarNode* current)
   192 static uint NPFSlopeCost(AyStarNode* current)
   193 {
   193 {
   194 	TileIndex next = current->tile + TileOffsByDiagDir(TrackdirToExitdir((Trackdir)current->direction));
   194 	TileIndex next = current->tile + TileOffsByDiagDir(TrackdirToExitdir((Trackdir)current->direction));
   195 	int x,y;
   195 
   196 	int8 z1,z2;
   196 	/* Get center of tiles */
   197 
   197 	int x1 = TileX(current->tile) * TILE_SIZE + TILE_SIZE / 2;
   198 	x = TileX(current->tile) * TILE_SIZE;
   198 	int y1 = TileY(current->tile) * TILE_SIZE + TILE_SIZE / 2;
   199 	y = TileY(current->tile) * TILE_SIZE;
   199 	int x2 = TileX(next) * TILE_SIZE + TILE_SIZE / 2;
   200 	/* get the height of the center of the current tile */
   200 	int y2 = TileY(next) * TILE_SIZE + TILE_SIZE / 2;
   201 	z1 = GetSlopeZ(x + TILE_SIZE / 2, y + TILE_SIZE / 2);
   201 
   202 
   202 	int dx4 = (x2 - x1) / 4;
   203 	x = TileX(next) * TILE_SIZE;
   203 	int dy4 = (y2 - y1) / 4;
   204 	y = TileY(next) * TILE_SIZE;
   204 
   205 	/* get the height of the center of the next tile */
   205 	/* Get the height on both sides of the tile edge.
   206 	z2 = GetSlopeZ(x + TILE_SIZE / 2, y + TILE_SIZE / 2);
   206 	 * Avoid testing the height on the tile-center. This will fail for halftile-foundations.
       
   207 	 */
       
   208 	int z1 = GetSlopeZ(x1 + dx4, y1 + dy4);
       
   209 	int z2 = GetSlopeZ(x2 - dx4, y2 - dy4);
   207 
   210 
   208 	if (z2 - z1 > 1) {
   211 	if (z2 - z1 > 1) {
   209 		/* Slope up */
   212 		/* Slope up */
   210 		return _patches.npf_rail_slope_penalty;
   213 		return _patches.npf_rail_slope_penalty;
   211 	}
   214 	}