File diff r23022:731ae1300799 → r23023:7b8669afd1db
src/heightmap.cpp
Show inline comments
 
@@ -404,97 +404,97 @@ void FixSlopes()
 
			if (col != 0) {
 
				/* Find lowest tile; either the top or left one */
 
				current_tile = TileHeight(TileXY(col - 1, row)); // top edge
 
			}
 
			if (row != 0) {
 
				if (TileHeight(TileXY(col, row - 1)) < current_tile) {
 
					current_tile = TileHeight(TileXY(col, row - 1)); // left edge
 
				}
 
			}
 

	
 
			/* Does the height differ more than one? */
 
			if (TileHeight(TileXY(col, row)) >= (uint)current_tile + 2) {
 
				/* Then change the height to be no more than one */
 
				SetTileHeight(TileXY(col, row), current_tile + 1);
 
			}
 
		}
 
	}
 

	
 
	/* Bottom and right edge */
 
	for (row = height - 1; row >= 0; row--) {
 
		for (col = width - 1; col >= 0; col--) {
 
			current_tile = MAX_TILE_HEIGHT;
 
			if ((uint)col != width - 1) {
 
				/* Find lowest tile; either the bottom and right one */
 
				current_tile = TileHeight(TileXY(col + 1, row)); // bottom edge
 
			}
 

	
 
			if ((uint)row != height - 1) {
 
				if (TileHeight(TileXY(col, row + 1)) < current_tile) {
 
					current_tile = TileHeight(TileXY(col, row + 1)); // right edge
 
				}
 
			}
 

	
 
			/* Does the height differ more than one? */
 
			if (TileHeight(TileXY(col, row)) >= (uint)current_tile + 2) {
 
				/* Then change the height to be no more than one */
 
				SetTileHeight(TileXY(col, row), current_tile + 1);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Reads the heightmap with the correct file reader.
 
 * @param dft Type of image file.
 
 * @param filename Name of the file to load.
 
 * @param [out] x Length of the image.
 
 * @param [out] y Height of the image.
 
 * @param [inout] map If not \c NULL, destination to store the loaded block of image data.
 
 * @param[in,out] map If not \c NULL, destination to store the loaded block of image data.
 
 * @return Whether loading was successful.
 
 */
 
static bool ReadHeightMap(DetailedFileType dft, const char *filename, uint *x, uint *y, byte **map)
 
{
 
	switch (dft) {
 
		default:
 
			NOT_REACHED();
 

	
 
#ifdef WITH_PNG
 
		case DFT_HEIGHTMAP_PNG:
 
			return ReadHeightmapPNG(filename, x, y, map);
 
#endif /* WITH_PNG */
 

	
 
		case DFT_HEIGHTMAP_BMP:
 
			return ReadHeightmapBMP(filename, x, y, map);
 
	}
 
}
 

	
 
/**
 
 * Get the dimensions of a heightmap.
 
 * @param dft Type of image file.
 
 * @param filename to query
 
 * @param x dimension x
 
 * @param y dimension y
 
 * @return Returns false if loading of the image failed.
 
 */
 
bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y)
 
{
 
	return ReadHeightMap(dft, filename, x, y, NULL);
 
}
 

	
 
/**
 
 * Load a heightmap from file and change the map in his current dimensions
 
 *  to a landscape representing the heightmap.
 
 * It converts pixels to height. The brighter, the higher.
 
 * @param dft Type of image file.
 
 * @param filename of the heightmap file to be imported
 
 */
 
void LoadHeightmap(DetailedFileType dft, const char *filename)
 
{
 
	uint x, y;
 
	byte *map = NULL;
 

	
 
	if (!ReadHeightMap(dft, filename, &x, &y, &map)) {
 
		free(map);
 
		return;
 
	}