summaryrefslogtreecommitdiff
path: root/src/map_func.h
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-03-21 21:43:23 +0000
committerfrosch <frosch@openttd.org>2009-03-21 21:43:23 +0000
commitd452a0a0ecaad276c893b62ab8f008a5af85ba82 (patch)
tree2816e5ec1ae12fd5f4cd0391c375c34b91225291 /src/map_func.h
parentfd0f0bda721269e27950431db44886b309ef4596 (diff)
downloadopenttd-d452a0a0ecaad276c893b62ab8f008a5af85ba82.tar.xz
(svn r15789) -Codechange: Add DiagdirBetweenTiles() and use it.
Diffstat (limited to 'src/map_func.h')
-rw-r--r--src/map_func.h20
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