changeset 18260:73a8e1d13059 draft

(svn r23096) -Codechange: remove useless divisions and multiplications by TILE_HEIGHT for the snow line code
author rubidium <rubidium@openttd.org>
date Fri, 04 Nov 2011 10:25:58 +0000
parents 362cc64dda9f
children 9cdb7965ac4a
files src/clear_cmd.cpp src/industry_cmd.cpp src/landscape.cpp src/newgrf.cpp src/newgrf_commons.cpp src/rail_cmd.cpp src/road_cmd.cpp src/town_cmd.cpp src/town_gui.cpp src/tree_cmd.cpp src/tunnelbridge_cmd.cpp
diffstat 11 files changed, 33 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/clear_cmd.cpp
+++ b/src/clear_cmd.cpp
@@ -158,7 +158,7 @@
 /** 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 @@
 	}
 	/* 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);
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -979,7 +979,7 @@
 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_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_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);
 		}
 	}
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -561,7 +561,7 @@
  */
 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 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 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;
 }
 
 /**
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -2411,6 +2411,7 @@
 					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 @@
 		/* 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
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -380,7 +380,7 @@
 
 				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 @@
 				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();
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -2367,7 +2367,7 @@
 	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 @@
 				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 @@
 			 * 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 {
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -1383,7 +1383,7 @@
 {
 	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);
 			}
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2096,7 +2096,7 @@
 	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 @@
 	}
 
 	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;
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -380,8 +380,8 @@
 		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 @@
 
 		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:
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -232,7 +232,7 @@
 		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 @@
 			/* 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 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 @@
 			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;
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -1457,7 +1457,7 @@
 			/* 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);