diff options
author | rubidium <rubidium@openttd.org> | 2007-10-20 16:50:48 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-10-20 16:50:48 +0000 |
commit | 5289aa2010b5fb249ba316f6e4b67ad5f7159120 (patch) | |
tree | 30e50cebc542be694f72726e770ef47ea943f6d0 /src/npf.cpp | |
parent | 8212088c03c0a0af451f734391699e5dab8d8608 (diff) | |
download | openttd-5289aa2010b5fb249ba316f6e4b67ad5f7159120.tar.xz |
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
Diffstat (limited to 'src/npf.cpp')
-rw-r--r-- | src/npf.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
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 */ |