Changeset - r16727:20d5ef5fc220
[Not reviewed]
master
0 2 0
rubidium - 14 years ago 2010-12-11 19:48:31
rubidium@openttd.org
(svn r21470) -Codechange: add method to get the distance from the edge in a given direction
2 files changed with 18 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/map.cpp
Show inline comments
 
@@ -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,
src/map_func.h
Show inline comments
 
@@ -331,6 +331,7 @@ uint DistanceSquare(TileIndex, TileIndex
 
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
0 comments (0 inline, 0 general)