From 5289aa2010b5fb249ba316f6e4b67ad5f7159120 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 20 Oct 2007 16:50:48 +0000 Subject: (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch. --- src/npf.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/npf.cpp') diff --git a/src/npf.cpp b/src/npf.cpp index 57b5dad04..06e527402 100644 --- a/src/npf.cpp +++ b/src/npf.cpp @@ -192,18 +192,21 @@ static inline uint NPFBridgeCost(AyStarNode *current) 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); - - 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); + + /* 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; + + 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 */ -- cgit v1.2.3-54-g00ecf