summaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-31 07:23:15 +0000
committertron <tron@openttd.org>2005-01-31 07:23:15 +0000
commit7bbcf5875c2fc6a8fa80e417d65e1094947d78b8 (patch)
treec97da17a330889a788b8654dddbc7507d01b3b38 /map.c
parente1c19367f0cebbe90596319e9f82d959fa54621c (diff)
downloadopenttd-7bbcf5875c2fc6a8fa80e417d65e1094947d78b8.tar.xz
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
Diffstat (limited to 'map.c')
-rw-r--r--map.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/map.c b/map.c
index 37f1e22dc..2481843d2 100644
--- a/map.c
+++ b/map.c
@@ -108,6 +108,50 @@ uint ScaleByMapSize1D(uint n)
}
+uint DistanceManhattan(TileIndex t0, TileIndex t1)
+{
+ return
+ abs(TileX(t0) - TileX(t1)) +
+ abs(TileY(t0) - TileY(t1));
+}
+
+
+uint DistanceSquare(TileIndex t0, TileIndex t1)
+{
+ const int x = TileX(t0) - TileX(t1);
+ const int y = TileY(t0) - TileY(t1);
+ return x * x + y * y;
+}
+
+
+uint DistanceMax(TileIndex t0, TileIndex t1)
+{
+ const uint x = abs(TileX(t0) - TileX(t1));
+ const uint y = abs(TileY(t0) - TileY(t1));
+ return x > y ? x : y;
+}
+
+
+uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1)
+{
+ const uint x = abs(TileX(t0) - TileX(t1));
+ const uint y = abs(TileY(t0) - TileY(t1));
+ return x > y ? 2 * x + y : 2 * y + x;
+}
+
+
+uint DistanceFromEdge(TileIndex tile)
+{
+ const uint xl = TileX(tile);
+ const uint yl = TileY(tile);
+ const uint xh = MapSizeX() - 1 - xl;
+ const uint yh = MapSizeY() - 1 - yl;
+ const uint minl = xl < yl ? xl : yl;
+ const uint minh = xh < yh ? xh : yh;
+ return minl < minh ? minl : minh;
+}
+
+
const TileIndexDiffC _tileoffs_by_dir[] = {
{-1, 0},
{ 0, 1},