Changeset - r18250:596efadc4b6d
[Not reviewed]
master
0 11 0
rubidium - 13 years ago 2011-11-04 10:25:58
rubidium@openttd.org
(svn r23096) -Codechange: remove useless divisions and multiplications by TILE_HEIGHT for the snow line code
11 files changed with 33 insertions and 32 deletions:
0 comments (0 inline, 0 general)
src/clear_cmd.cpp
Show inline comments
 
@@ -158,7 +158,7 @@ void TileLoopClearHelper(TileIndex tile)
 
/** Convert to or from snowy tiles. */
 
static void TileLoopClearAlps(TileIndex tile)
 
{
 
	int k = GetTilePixelZ(tile) - GetSnowLine() + TILE_HEIGHT;
 
	int k = GetTileZ(tile) - GetSnowLine() + 1;
 

	
 
	if (k < 0) {
 
		/* Below the snow line, do nothing if no snow. */
 
@@ -173,7 +173,7 @@ static void TileLoopClearAlps(TileIndex 
 
	}
 
	/* Update snow density. */
 
	uint curent_density = GetClearDensity(tile);
 
	uint req_density = (k < 0) ? 0u : min((uint)k / TILE_HEIGHT, 3);
 
	uint req_density = (k < 0) ? 0u : min((uint)k, 3);
 

	
 
	if (curent_density < req_density) {
 
		AddClearDensity(tile, 1);
src/industry_cmd.cpp
Show inline comments
 
@@ -979,7 +979,7 @@ static void SetupFarmFieldFence(TileInde
 
static void PlantFarmField(TileIndex tile, IndustryID industry)
 
{
 
	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
 
		if (GetTilePixelZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine()) return;
 
		if (GetTileZ(tile) + 2 >= GetSnowLine()) return;
 
	}
 

	
 
	/* determine field size */
 
@@ -1165,7 +1165,7 @@ static CommandCost CheckNewIndustry_NULL
 
static CommandCost CheckNewIndustry_Forest(TileIndex tile)
 
{
 
	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
 
		if (GetTilePixelZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) {
 
		if (GetTileZ(tile) < HighestSnowLine() + 2U) {
 
			return_cmd_error(STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED);
 
		}
 
	}
 
@@ -1209,7 +1209,7 @@ static CommandCost CheckNewIndustry_OilR
 
static CommandCost CheckNewIndustry_Farm(TileIndex tile)
 
{
 
	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
 
		if (GetTilePixelZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) {
 
		if (GetTileZ(tile) + 2 >= HighestSnowLine()) {
 
			return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
		}
 
	}
src/landscape.cpp
Show inline comments
 
@@ -561,7 +561,7 @@ void SetSnowLine(byte table[SNOW_LINE_MO
 
 */
 
byte GetSnowLine()
 
{
 
	if (_snow_line == NULL) return _settings_game.game_creation.snow_line_height * TILE_HEIGHT;
 
	if (_snow_line == NULL) return _settings_game.game_creation.snow_line_height;
 

	
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(_date, &ymd);
 
@@ -575,7 +575,7 @@ byte GetSnowLine()
 
 */
 
byte HighestSnowLine()
 
{
 
	return _snow_line == NULL ? _settings_game.game_creation.snow_line_height * TILE_HEIGHT : _snow_line->highest_value;
 
	return _snow_line == NULL ? _settings_game.game_creation.snow_line_height : _snow_line->highest_value;
 
}
 

	
 
/**
 
@@ -585,7 +585,7 @@ byte HighestSnowLine()
 
 */
 
byte LowestSnowLine()
 
{
 
	return _snow_line == NULL ? _settings_game.game_creation.snow_line_height * TILE_HEIGHT : _snow_line->lowest_value;
 
	return _snow_line == NULL ? _settings_game.game_creation.snow_line_height : _snow_line->lowest_value;
 
}
 

	
 
/**
src/newgrf.cpp
Show inline comments
 
@@ -2411,6 +2411,7 @@ static ChangeInfoResult GlobalVarChangeI
 
					for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
 
						for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
 
							table[i][j] = buf->ReadByte();
 
							if (table[i][j] != 0xFF) table[i][j] /= TILE_HEIGHT;
 
						}
 
					}
 
					SetSnowLine(table);
 
@@ -5512,7 +5513,7 @@ bool GetGlobalVariable(byte param, uint3
 
		/* case 0x1F: // locale dependent settings not implemented to avoid desync */
 

	
 
		case 0x20: // snow line height
 
			*value = _settings_game.game_creation.landscape == LT_ARCTIC ? GetSnowLine() : 0xFF;
 
			*value = _settings_game.game_creation.landscape == LT_ARCTIC ? GetSnowLine() * TILE_HEIGHT : 0xFF;
 
			return true;
 

	
 
		case 0x21: // OpenTTD version
src/newgrf_commons.cpp
Show inline comments
 
@@ -380,7 +380,7 @@ uint32 GetTerrainType(TileIndex tile, Ti
 

	
 
				case MP_TUNNELBRIDGE:
 
					if (context == TCX_ON_BRIDGE) {
 
						has_snow = (GetBridgePixelHeight(tile) > GetSnowLine());
 
						has_snow = (GetBridgeHeight(tile) > GetSnowLine());
 
					} else {
 
						/* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
 
						if (_generating_world) goto genworld; // we do not care about foundations here
 
@@ -393,13 +393,13 @@ uint32 GetTerrainType(TileIndex tile, Ti
 
				case MP_INDUSTRY:
 
				case MP_OBJECT:
 
					/* These tiles usually have a levelling foundation. So use max Z */
 
					has_snow = (GetTileMaxPixelZ(tile) > GetSnowLine());
 
					has_snow = (GetTileMaxZ(tile) > GetSnowLine());
 
					break;
 

	
 
				case MP_VOID:
 
				case MP_WATER:
 
				genworld:
 
					has_snow = (GetTilePixelZ(tile) > GetSnowLine());
 
					has_snow = (GetTileZ(tile) > GetSnowLine());
 
					break;
 

	
 
				default: NOT_REACHED();
src/rail_cmd.cpp
Show inline comments
 
@@ -2367,7 +2367,7 @@ static void TileLoop_Track(TileIndex til
 
	switch (_settings_game.game_creation.landscape) {
 
		case LT_ARCTIC: {
 
			uint z;
 
			Slope slope = GetTilePixelSlope(tile, &z);
 
			Slope slope = GetTileSlope(tile, &z);
 
			bool half = false;
 

	
 
			/* for non-flat track, use lower part of track
 
@@ -2379,31 +2379,31 @@ static void TileLoop_Track(TileIndex til
 
				switch (f) {
 
					case FOUNDATION_NONE:
 
						/* no foundation - is the track on the upper side of three corners raised tile? */
 
						if (IsSlopeWithThreeCornersRaised(slope)) z += TILE_HEIGHT;
 
						if (IsSlopeWithThreeCornersRaised(slope)) z++;
 
						break;
 

	
 
					case FOUNDATION_INCLINED_X:
 
					case FOUNDATION_INCLINED_Y:
 
						/* sloped track - is it on a steep slope? */
 
						if (IsSteepSlope(slope)) z += TILE_HEIGHT;
 
						if (IsSteepSlope(slope)) z++;
 
						break;
 

	
 
					case FOUNDATION_STEEP_LOWER:
 
						/* only lower part of steep slope */
 
						z += TILE_HEIGHT;
 
						z++;
 
						break;
 

	
 
					default:
 
						/* if it is a steep slope, then there is a track on higher part */
 
						if (IsSteepSlope(slope)) z += TILE_HEIGHT;
 
						z += TILE_HEIGHT;
 
						if (IsSteepSlope(slope)) z++;
 
						z++;
 
						break;
 
				}
 

	
 
				half = IsInsideMM(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1);
 
			} else {
 
				/* is the depot on a non-flat tile? */
 
				if (slope != SLOPE_FLAT) z += TILE_HEIGHT;
 
				if (slope != SLOPE_FLAT) z++;
 
			}
 

	
 
			/* 'z' is now the lowest part of the highest track bit -
 
@@ -2411,7 +2411,7 @@ static void TileLoop_Track(TileIndex til
 
			 * for two track bits, it is 'z' of higher track bit
 
			 * For non-continuous foundations (and STEEP_BOTH), 'half' is set */
 
			if (z > GetSnowLine()) {
 
				if (half && z - GetSnowLine() == TILE_HEIGHT) {
 
				if (half && z - GetSnowLine() == 1) {
 
					/* track on non-continuous foundation, lower part is not under snow */
 
					new_ground = RAIL_GROUND_HALF_SNOW;
 
				} else {
src/road_cmd.cpp
Show inline comments
 
@@ -1383,7 +1383,7 @@ static void TileLoop_Road(TileIndex tile
 
{
 
	switch (_settings_game.game_creation.landscape) {
 
		case LT_ARCTIC:
 
			if (IsOnSnow(tile) != (GetTilePixelZ(tile) > GetSnowLine())) {
 
			if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
 
				ToggleSnow(tile);
 
				MarkTileDirtyByTile(tile);
 
			}
src/town_cmd.cpp
Show inline comments
 
@@ -2096,7 +2096,7 @@ static bool BuildTownHouse(Town *t, Tile
 
	if (!CanBuildHouseHere(tile, t->index, false)) return false;
 

	
 
	uint z;
 
	Slope slope = GetTilePixelSlope(tile, &z);
 
	Slope slope = GetTileSlope(tile, &z);
 

	
 
	/* Get the town zone type of the current tile, as well as the climate.
 
	 * This will allow to easily compare with the specs of the new house to build */
 
@@ -2779,7 +2779,7 @@ static void UpdateTownGrowRate(Town *t)
 
	}
 

	
 
	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
 
		if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90) return;
 
		if (TileHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90) return;
 

	
 
	} else if (_settings_game.game_creation.landscape == LT_TROPIC) {
 
		if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food == 0 || t->act_water == 0) && t->population > 60) return;
src/town_gui.cpp
Show inline comments
 
@@ -380,8 +380,8 @@ public:
 
		uint cargo_needed_for_growth = 0;
 
		switch (_settings_game.game_creation.landscape) {
 
			case LT_ARCTIC:
 
				if (TilePixelHeight(this->town->xy) >= LowestSnowLine()) cargo_needed_for_growth = 1;
 
				if (TilePixelHeight(this->town->xy) < GetSnowLine()) required_text = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
 
				if (TileHeight(this->town->xy) >= LowestSnowLine()) cargo_needed_for_growth = 1;
 
				if (TileHeight(this->town->xy) < GetSnowLine()) required_text = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
 
				break;
 

	
 
			case LT_TROPIC:
 
@@ -493,7 +493,7 @@ public:
 

	
 
		switch (_settings_game.game_creation.landscape) {
 
			case LT_ARCTIC:
 
				if (TilePixelHeight(this->town->xy) >= LowestSnowLine()) aimed_height += 2 * FONT_HEIGHT_NORMAL;
 
				if (TileHeight(this->town->xy) >= LowestSnowLine()) aimed_height += 2 * FONT_HEIGHT_NORMAL;
 
				break;
 

	
 
			case LT_TROPIC:
src/tree_cmd.cpp
Show inline comments
 
@@ -232,7 +232,7 @@ static void PlaceTreeAtSameHeight(TileIn
 
		if (!CanPlantTreesOnTile(cur_tile, true)) continue;
 

	
 
		/* Not too much height difference */
 
		if (Delta(GetTilePixelZ(cur_tile), height) > 2) continue;
 
		if (Delta(GetTileZ(cur_tile), height) > 2) continue;
 

	
 
		/* Place one tree and quit */
 
		PlaceTree(cur_tile, r);
 
@@ -264,9 +264,9 @@ void PlaceTreesRandomly()
 
			/* Place a number of trees based on the tile height.
 
			 *  This gives a cool effect of multiple trees close together.
 
			 *  It is almost real life ;) */
 
			ht = GetTilePixelZ(tile);
 
			ht = GetTileZ(tile);
 
			/* The higher we get, the more trees we plant */
 
			j = GetTilePixelZ(tile) / TILE_HEIGHT * 2;
 
			j = GetTileZ(tile) * 2;
 
			/* Above snowline more trees! */
 
			if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) j *= 3;
 
			while (j--) {
 
@@ -588,7 +588,7 @@ static void TileLoopTreesDesert(TileInde
 

	
 
static void TileLoopTreesAlps(TileIndex tile)
 
{
 
	int k = GetTilePixelZ(tile) - GetSnowLine() + TILE_HEIGHT;
 
	int k = GetTileZ(tile) - GetSnowLine() + 1;
 

	
 
	if (k < 0) {
 
		switch (GetTreeGround(tile)) {
 
@@ -597,7 +597,7 @@ static void TileLoopTreesAlps(TileIndex 
 
			default: return;
 
		}
 
	} else {
 
		uint density = min((uint)k / TILE_HEIGHT, 3);
 
		uint density = min<uint>(k, 3);
 

	
 
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT && GetTreeGround(tile) != TREE_GROUND_ROUGH_SNOW) {
 
			TreeGround tg = GetTreeGround(tile) == TREE_GROUND_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT;
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -1457,7 +1457,7 @@ static void TileLoop_TunnelBridge(TileIn
 
			/* As long as we do not have a snow density, we want to use the density
 
			 * from the entry endge. For tunnels this is the lowest point for bridges the highest point.
 
			 * (Independent of foundations) */
 
			uint z = IsBridge(tile) ? GetTileMaxPixelZ(tile) : GetTilePixelZ(tile);
 
			uint z = IsBridge(tile) ? GetTileMaxZ(tile) : GetTileZ(tile);
 
			if (snow_or_desert != (z > GetSnowLine())) {
 
				SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
 
				MarkTileDirtyByTile(tile);
0 comments (0 inline, 0 general)