Changeset - r20804:394e50231d55
[Not reviewed]
master
0 4 0
zuu - 11 years ago 2013-10-12 22:03:13
zuu@openttd.org
(svn r25848) -Codechange: Refactor check for if a tile is not an edge tile to new IsInnerTile method (cirdan, LordAro)
4 files changed with 21 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/heightmap.cpp
Show inline comments
 
@@ -355,26 +355,25 @@ static void GrayscaleToMapHeights(uint i
 
					case HM_CLOCKWISE:
 
						img_col = (((col - col_pad) * num_div) / img_scale);
 
						break;
 
				}
 

	
 
				assert(img_row < img_height);
 
				assert(img_col < img_width);
 

	
 
				/* Colour scales from 0 to 255, OpenTTD height scales from 0 to 15 */
 
				SetTileHeight(tile, map[img_row * img_width + img_col] / 16);
 
			}
 
			/* Only clear the tiles within the map area. */
 
			if (TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY() &&
 
					(!_settings_game.construction.freeform_edges || (TileX(tile) != 0 && TileY(tile) != 0))) {
 
			if (IsInnerTile(tile)) {
 
				MakeClear(tile, CLEAR_GRASS, 3);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * This function takes care of the fact that land in OpenTTD can never differ
 
 * more than 1 in height
 
 */
 
void FixSlopes()
 
{
src/tgp.cpp
Show inline comments
 
@@ -941,26 +941,25 @@ static double perlin_coast_noise_2D(cons
 
	}
 

	
 
	return total;
 
}
 

	
 

	
 
/** A small helper function to initialize the terrain */
 
static void TgenSetTileHeight(TileIndex tile, int height)
 
{
 
	SetTileHeight(tile, height);
 

	
 
	/* Only clear the tiles within the map area. */
 
	if (TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY() &&
 
			(!_settings_game.construction.freeform_edges || (TileX(tile) != 0 && TileY(tile) != 0))) {
 
	if (IsInnerTile(tile)) {
 
		MakeClear(tile, CLEAR_GRASS, 3);
 
	}
 
}
 

	
 
/**
 
 * The main new land generator using Perlin noise. Desert landscape is handled
 
 * different to all others to give a desert valley between two high mountains.
 
 * Clearly if a low height terrain (flat/very flat) is chosen, then the tropic
 
 * areas wont be high enough, and there will be very little tropic on the map.
 
 * Thus Tropic works best on Hilly or Mountainous.
 
 */
 
void GenerateTerrainPerlin()
src/tile_map.cpp
Show inline comments
 
@@ -13,29 +13,25 @@
 
#include "tile_map.h"
 

	
 
/**
 
 * Return the slope of a given tile
 
 * @param tile Tile to compute slope of
 
 * @param h    If not \c NULL, pointer to storage of z height
 
 * @return Slope of the tile, except for the HALFTILE part
 
 */
 
Slope GetTileSlope(TileIndex tile, int *h)
 
{
 
	assert(tile < MapSize());
 

	
 
	uint x = TileX(tile);
 
	uint y = TileY(tile);
 

	
 
	if (x == MapMaxX() || y == MapMaxY() ||
 
			((x == 0 || y == 0) && _settings_game.construction.freeform_edges)) {
 
	if (!IsInnerTile(tile)) {
 
		if (h != NULL) *h = TileHeight(tile);
 
		return SLOPE_FLAT;
 
	}
 

	
 
	int a = TileHeight(tile); // Height of the N corner
 
	int min = a; // Minimal height of all corners examined so far
 
	int b = TileHeight(tile + TileDiffXY(1, 0)); // Height of the W corner
 
	if (min > b) min = b;
 
	int c = TileHeight(tile + TileDiffXY(0, 1)); // Height of the E corner
 
	if (min > c) min = c;
 
	int d = TileHeight(tile + TileDiffXY(1, 1)); // Height of the S corner
 
	if (min > d) min = d;
src/tile_map.h
Show inline comments
 
@@ -69,42 +69,59 @@ static inline uint TilePixelHeight(TileI
 
 *
 
 * @param tile The tile to get the TileType
 
 * @return The tiletype of the tile
 
 * @pre tile < MapSize()
 
 */
 
static inline TileType GetTileType(TileIndex tile)
 
{
 
	assert(tile < MapSize());
 
	return (TileType)GB(_m[tile].type_height, 4, 4);
 
}
 

	
 
/**
 
 * Check if a tile is within the map (not a border)
 
 *
 
 * @param tile The tile to check
 
 * @return Whether the tile is in the interior of the map
 
 * @pre tile < MapSize()
 
 */
 
static inline bool IsInnerTile(TileIndex tile)
 
{
 
	assert(tile < MapSize());
 

	
 
	uint x = TileX(tile);
 
	uint y = TileY(tile);
 

	
 
	return x < MapMaxX() && y < MapMaxY() && ((x > 0 && y > 0) || !_settings_game.construction.freeform_edges);
 
}
 

	
 
/**
 
 * Set the type of a tile
 
 *
 
 * This functions sets the type of a tile. If the type
 
 * MP_VOID is selected the tile must be at the south-west or
 
 * south-east edges of the map and vice versa.
 
 *
 
 * @param tile The tile to save the new type
 
 * @param type The type to save
 
 * @pre tile < MapSize()
 
 * @pre type MP_VOID <=> tile is on the south-east or south-west edge.
 
 */
 
static inline void SetTileType(TileIndex tile, TileType type)
 
{
 
	assert(tile < MapSize());
 
	/* VOID tiles (and no others) are exactly allowed at the lower left and right
 
	 * edges of the map. If _settings_game.construction.freeform_edges is true,
 
	 * the upper edges of the map are also VOID tiles. */
 
	assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() || (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) == (type == MP_VOID));
 
	assert(IsInnerTile(tile) == (type != MP_VOID));
 
	SB(_m[tile].type_height, 4, 4, type);
 
}
 

	
 
/**
 
 * Checks if a tile is a give tiletype.
 
 *
 
 * This function checks if a tile got the given tiletype.
 
 *
 
 * @param tile The tile to check
 
 * @param type The type to check against
 
 * @return true If the type matches against the type of the tile
 
 */
0 comments (0 inline, 0 general)