From 69162621d81c82b832cccc8d59179fc0e4472af2 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 4 Nov 2011 10:25:58 +0000 Subject: (svn r23096) -Codechange: remove useless divisions and multiplications by TILE_HEIGHT for the snow line code --- src/clear_cmd.cpp | 4 ++-- src/industry_cmd.cpp | 6 +++--- src/landscape.cpp | 6 +++--- src/newgrf.cpp | 3 ++- src/newgrf_commons.cpp | 6 +++--- src/rail_cmd.cpp | 16 ++++++++-------- src/road_cmd.cpp | 2 +- src/town_cmd.cpp | 4 ++-- src/town_gui.cpp | 6 +++--- src/tree_cmd.cpp | 10 +++++----- src/tunnelbridge_cmd.cpp | 2 +- 11 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp index 3506ddbff..5f0b32aed 100644 --- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -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 tile) } /* 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); diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index d9e28eb7e..2350ab3d3 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -979,7 +979,7 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direct 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(TileIndex tile) 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_OilRig(TileIndex tile) 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); } } diff --git a/src/landscape.cpp b/src/landscape.cpp index f70cbeda8..f310f39d4 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -561,7 +561,7 @@ void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]) */ 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; } /** diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 571779596..508eb15ba 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2411,6 +2411,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By 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, uint32 *value) /* 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 diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index 0bea74a13..e7ef0a01a 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -380,7 +380,7 @@ uint32 GetTerrainType(TileIndex tile, TileContext context) 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, TileContext context) 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(); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 185a83556..10feedd6e 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2367,7 +2367,7 @@ static void TileLoop_Track(TileIndex tile) 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 tile) 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 tile) * 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 { diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 14f6f43fc..43e51739a 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -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); } diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index bfaee7498..e13bd9daf 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2096,7 +2096,7 @@ static bool BuildTownHouse(Town *t, TileIndex 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; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index f5b5d0fd0..85763f6b1 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -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: diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 238f551c9..e66649dde 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -232,7 +232,7 @@ static void PlaceTreeAtSameHeight(TileIndex tile, uint height) 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(TileIndex tile) 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 tile) default: return; } } else { - uint density = min((uint)k / TILE_HEIGHT, 3); + uint density = min(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; diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 700151560..e9e221bd0 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1457,7 +1457,7 @@ static void TileLoop_TunnelBridge(TileIndex tile) /* 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); -- cgit v1.2.3-54-g00ecf