diff options
author | rubidium <rubidium@openttd.org> | 2010-12-11 19:48:31 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-12-11 19:48:31 +0000 |
commit | 7cf40e5d250bc07e5e0f3cacafc8b0b659889a37 (patch) | |
tree | 20ddad1d0f0bb906f79389f8148430565a8f3940 /src/map.cpp | |
parent | ae30f4d010ffe25f3bf2b89d6f15cbed6e956e9f (diff) | |
download | openttd-7cf40e5d250bc07e5e0f3cacafc8b0b659889a37.tar.xz |
(svn r21470) -Codechange: add method to get the distance from the edge in a given direction
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/map.cpp b/src/map.cpp index ae05a6cd3..70d9cce83 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -225,6 +225,23 @@ uint DistanceFromEdge(TileIndex tile) } /*! + * 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... * Every tile will be tested by means of the callback function proc, |