(svn r15789) -Codechange: Add DiagdirBetweenTiles() and use it.

This commit is contained in:
frosch
2009-03-21 21:43:23 +00:00
parent fd0f0bda72
commit d452a0a0ec
5 changed files with 26 additions and 16 deletions

View File

@@ -374,6 +374,26 @@ static inline TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
return TILE_ADD(tile, TileOffsByDiagDir(dir));
}
/**
* Determines the DiagDirection to get from one tile to another.
* The tiles do not necessarily have to be adjacent.
* @param tile_from Origin tile
* @param tile_to Destination tile
* @return DiagDirection from tile_from towards tile_to, or INVALID_DIAGDIR if the tiles are not on an axis
*/
static inline DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to)
{
int dx = (int)TileX(tile_to) - (int)TileX(tile_from);
int dy = (int)TileY(tile_to) - (int)TileY(tile_from);
if (dx == 0) {
if (dy == 0) return INVALID_DIAGDIR;
return (dy < 0 ? DIAGDIR_NW : DIAGDIR_SE);
} else {
if (dy != 0) return INVALID_DIAGDIR;
return (dx < 0 ? DIAGDIR_NE : DIAGDIR_SW);
}
}
/**
* A callback function type for searching tiles.
*