From 7cf40e5d250bc07e5e0f3cacafc8b0b659889a37 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 11 Dec 2010 19:48:31 +0000 Subject: (svn r21470) -Codechange: add method to get the distance from the edge in a given direction --- src/map.cpp | 17 +++++++++++++++++ src/map_func.h | 1 + 2 files changed, 18 insertions(+) (limited to 'src') diff --git a/src/map.cpp b/src/map.cpp index ae05a6cd3..70d9cce83 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -224,6 +224,23 @@ uint DistanceFromEdge(TileIndex tile) return min(minl, minh); } +/*! + * Gets the distance to the edge of the map in given direction. + * @param tile the tile to get the distance from + * @param diagdir the direction of interest + * @return the distance from the edge in tiles + */ +uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir) +{ + switch (dir) { + case DIAGDIR_NE: return TileX(tile) - (_settings_game.construction.freeform_edges ? 1 : 0); + case DIAGDIR_NW: return TileY(tile) - (_settings_game.construction.freeform_edges ? 1 : 0); + case DIAGDIR_SW: return MapMaxX() - TileX(tile) - 1; + case DIAGDIR_SE: return MapMaxY() - TileY(tile) - 1; + default: NOT_REACHED(); + } +} + /*! * Function performing a search around a center tile and going outward, thus in circle. * Although it really is a square search... diff --git a/src/map_func.h b/src/map_func.h index 68c555e6d..42d6dd142 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -331,6 +331,7 @@ uint DistanceSquare(TileIndex, TileIndex); ///< euclidian- or L2-Norm squared uint DistanceMax(TileIndex, TileIndex); ///< also known as L-Infinity-Norm uint DistanceMaxPlusManhattan(TileIndex, TileIndex); ///< Max + Manhattan uint DistanceFromEdge(TileIndex); ///< shortest distance from any edge of the map +uint DistanceFromEdgeDir(TileIndex, DiagDirection); ///< distance from the map edge in given direction /** * A loop which iterates to a square of tiles -- cgit v1.2.3-54-g00ecf