diff options
author | frosch <frosch@openttd.org> | 2009-03-21 21:43:23 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-03-21 21:43:23 +0000 |
commit | d452a0a0ecaad276c893b62ab8f008a5af85ba82 (patch) | |
tree | 2816e5ec1ae12fd5f4cd0391c375c34b91225291 /src/map_func.h | |
parent | fd0f0bda721269e27950431db44886b309ef4596 (diff) | |
download | openttd-d452a0a0ecaad276c893b62ab8f008a5af85ba82.tar.xz |
(svn r15789) -Codechange: Add DiagdirBetweenTiles() and use it.
Diffstat (limited to 'src/map_func.h')
-rw-r--r-- | src/map_func.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/map_func.h b/src/map_func.h index 1d2eec8eb..932e2f8fd 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -375,6 +375,26 @@ static inline TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection 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. * * @param tile The tile to test |