1
0
Fork 0

(svn r23096) -Codechange: remove useless divisions and multiplications by TILE_HEIGHT for the snow line code

release/1.2
rubidium 2011-11-04 10:25:58 +00:00
parent b167c0a396
commit 69162621d8
11 changed files with 33 additions and 32 deletions

View File

@ -158,7 +158,7 @@ void TileLoopClearHelper(TileIndex tile)
/** Convert to or from snowy tiles. */ /** Convert to or from snowy tiles. */
static void TileLoopClearAlps(TileIndex tile) static void TileLoopClearAlps(TileIndex tile)
{ {
int k = GetTilePixelZ(tile) - GetSnowLine() + TILE_HEIGHT; int k = GetTileZ(tile) - GetSnowLine() + 1;
if (k < 0) { if (k < 0) {
/* Below the snow line, do nothing if no snow. */ /* Below the snow line, do nothing if no snow. */
@ -173,7 +173,7 @@ static void TileLoopClearAlps(TileIndex tile)
} }
/* Update snow density. */ /* Update snow density. */
uint curent_density = GetClearDensity(tile); 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) { if (curent_density < req_density) {
AddClearDensity(tile, 1); AddClearDensity(tile, 1);

View File

@ -979,7 +979,7 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direct
static void PlantFarmField(TileIndex tile, IndustryID industry) static void PlantFarmField(TileIndex tile, IndustryID industry)
{ {
if (_settings_game.game_creation.landscape == LT_ARCTIC) { 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 */ /* determine field size */
@ -1165,7 +1165,7 @@ static CommandCost CheckNewIndustry_NULL(TileIndex tile)
static CommandCost CheckNewIndustry_Forest(TileIndex tile) static CommandCost CheckNewIndustry_Forest(TileIndex tile)
{ {
if (_settings_game.game_creation.landscape == LT_ARCTIC) { 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); 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) static CommandCost CheckNewIndustry_Farm(TileIndex tile)
{ {
if (_settings_game.game_creation.landscape == LT_ARCTIC) { 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); return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
} }
} }

View File

@ -561,7 +561,7 @@ void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
*/ */
byte GetSnowLine() 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; YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd); ConvertDateToYMD(_date, &ymd);
@ -575,7 +575,7 @@ byte GetSnowLine()
*/ */
byte HighestSnowLine() 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() 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;
} }
/** /**

View File

@ -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 i = 0; i < SNOW_LINE_MONTHS; i++) {
for (uint j = 0; j < SNOW_LINE_DAYS; j++) { for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
table[i][j] = buf->ReadByte(); table[i][j] = buf->ReadByte();
if (table[i][j] != 0xFF) table[i][j] /= TILE_HEIGHT;
} }
} }
SetSnowLine(table); SetSnowLine(table);
@ -5512,7 +5513,7 @@ bool GetGlobalVariable(byte param, uint32 *value)
/* case 0x1F: // locale dependent settings not implemented to avoid desync */ /* case 0x1F: // locale dependent settings not implemented to avoid desync */
case 0x20: // snow line height 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; return true;
case 0x21: // OpenTTD version case 0x21: // OpenTTD version

View File

@ -380,7 +380,7 @@ uint32 GetTerrainType(TileIndex tile, TileContext context)
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if (context == TCX_ON_BRIDGE) { if (context == TCX_ON_BRIDGE) {
has_snow = (GetBridgePixelHeight(tile) > GetSnowLine()); has_snow = (GetBridgeHeight(tile) > GetSnowLine());
} else { } else {
/* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */ /* 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 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_INDUSTRY:
case MP_OBJECT: case MP_OBJECT:
/* These tiles usually have a levelling foundation. So use max Z */ /* These tiles usually have a levelling foundation. So use max Z */
has_snow = (GetTileMaxPixelZ(tile) > GetSnowLine()); has_snow = (GetTileMaxZ(tile) > GetSnowLine());
break; break;
case MP_VOID: case MP_VOID:
case MP_WATER: case MP_WATER:
genworld: genworld:
has_snow = (GetTilePixelZ(tile) > GetSnowLine()); has_snow = (GetTileZ(tile) > GetSnowLine());
break; break;
default: NOT_REACHED(); default: NOT_REACHED();

View File

@ -2367,7 +2367,7 @@ static void TileLoop_Track(TileIndex tile)
switch (_settings_game.game_creation.landscape) { switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC: { case LT_ARCTIC: {
uint z; uint z;
Slope slope = GetTilePixelSlope(tile, &z); Slope slope = GetTileSlope(tile, &z);
bool half = false; bool half = false;
/* for non-flat track, use lower part of track /* for non-flat track, use lower part of track
@ -2379,31 +2379,31 @@ static void TileLoop_Track(TileIndex tile)
switch (f) { switch (f) {
case FOUNDATION_NONE: case FOUNDATION_NONE:
/* no foundation - is the track on the upper side of three corners raised tile? */ /* 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; break;
case FOUNDATION_INCLINED_X: case FOUNDATION_INCLINED_X:
case FOUNDATION_INCLINED_Y: case FOUNDATION_INCLINED_Y:
/* sloped track - is it on a steep slope? */ /* sloped track - is it on a steep slope? */
if (IsSteepSlope(slope)) z += TILE_HEIGHT; if (IsSteepSlope(slope)) z++;
break; break;
case FOUNDATION_STEEP_LOWER: case FOUNDATION_STEEP_LOWER:
/* only lower part of steep slope */ /* only lower part of steep slope */
z += TILE_HEIGHT; z++;
break; break;
default: default:
/* if it is a steep slope, then there is a track on higher part */ /* if it is a steep slope, then there is a track on higher part */
if (IsSteepSlope(slope)) z += TILE_HEIGHT; if (IsSteepSlope(slope)) z++;
z += TILE_HEIGHT; z++;
break; break;
} }
half = IsInsideMM(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1); half = IsInsideMM(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1);
} else { } else {
/* is the depot on a non-flat tile? */ /* 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 - /* '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 two track bits, it is 'z' of higher track bit
* For non-continuous foundations (and STEEP_BOTH), 'half' is set */ * For non-continuous foundations (and STEEP_BOTH), 'half' is set */
if (z > GetSnowLine()) { 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 */ /* track on non-continuous foundation, lower part is not under snow */
new_ground = RAIL_GROUND_HALF_SNOW; new_ground = RAIL_GROUND_HALF_SNOW;
} else { } else {

View File

@ -1383,7 +1383,7 @@ static void TileLoop_Road(TileIndex tile)
{ {
switch (_settings_game.game_creation.landscape) { switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC: case LT_ARCTIC:
if (IsOnSnow(tile) != (GetTilePixelZ(tile) > GetSnowLine())) { if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
ToggleSnow(tile); ToggleSnow(tile);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }

View File

@ -2096,7 +2096,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
if (!CanBuildHouseHere(tile, t->index, false)) return false; if (!CanBuildHouseHere(tile, t->index, false)) return false;
uint z; 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. /* 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 */ * 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 (_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) { } 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; if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food == 0 || t->act_water == 0) && t->population > 60) return;

View File

@ -380,8 +380,8 @@ public:
uint cargo_needed_for_growth = 0; uint cargo_needed_for_growth = 0;
switch (_settings_game.game_creation.landscape) { switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC: case LT_ARCTIC:
if (TilePixelHeight(this->town->xy) >= LowestSnowLine()) cargo_needed_for_growth = 1; if (TileHeight(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) < GetSnowLine()) required_text = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
break; break;
case LT_TROPIC: case LT_TROPIC:
@ -493,7 +493,7 @@ public:
switch (_settings_game.game_creation.landscape) { switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC: 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; break;
case LT_TROPIC: case LT_TROPIC:

View File

@ -232,7 +232,7 @@ static void PlaceTreeAtSameHeight(TileIndex tile, uint height)
if (!CanPlantTreesOnTile(cur_tile, true)) continue; if (!CanPlantTreesOnTile(cur_tile, true)) continue;
/* Not too much height difference */ /* 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 */ /* Place one tree and quit */
PlaceTree(cur_tile, r); PlaceTree(cur_tile, r);
@ -264,9 +264,9 @@ void PlaceTreesRandomly()
/* Place a number of trees based on the tile height. /* Place a number of trees based on the tile height.
* This gives a cool effect of multiple trees close together. * This gives a cool effect of multiple trees close together.
* It is almost real life ;) */ * It is almost real life ;) */
ht = GetTilePixelZ(tile); ht = GetTileZ(tile);
/* The higher we get, the more trees we plant */ /* The higher we get, the more trees we plant */
j = GetTilePixelZ(tile) / TILE_HEIGHT * 2; j = GetTileZ(tile) * 2;
/* Above snowline more trees! */ /* Above snowline more trees! */
if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) j *= 3; if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) j *= 3;
while (j--) { while (j--) {
@ -588,7 +588,7 @@ static void TileLoopTreesDesert(TileIndex tile)
static void TileLoopTreesAlps(TileIndex tile) static void TileLoopTreesAlps(TileIndex tile)
{ {
int k = GetTilePixelZ(tile) - GetSnowLine() + TILE_HEIGHT; int k = GetTileZ(tile) - GetSnowLine() + 1;
if (k < 0) { if (k < 0) {
switch (GetTreeGround(tile)) { switch (GetTreeGround(tile)) {
@ -597,7 +597,7 @@ static void TileLoopTreesAlps(TileIndex tile)
default: return; default: return;
} }
} else { } 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) { 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; TreeGround tg = GetTreeGround(tile) == TREE_GROUND_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT;

View File

@ -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 /* 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. * from the entry endge. For tunnels this is the lowest point for bridges the highest point.
* (Independent of foundations) */ * (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())) { if (snow_or_desert != (z > GetSnowLine())) {
SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert); SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);