summaryrefslogtreecommitdiff
path: root/src/map_func.h
diff options
context:
space:
mode:
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