(svn r23100) -Codechange: remove pointless multiplications by TILE_HEIGHT for the terraform code

This commit is contained in:
rubidium 2011-11-04 10:30:10 +00:00
parent 0b6dbaf664
commit 1dc685aeea
9 changed files with 16 additions and 18 deletions

View File

@ -33,7 +33,7 @@
*/ */
static inline bool AutoslopeCheckForEntranceEdge(TileIndex tile, uint z_new, Slope tileh_new, DiagDirection entrance) static inline bool AutoslopeCheckForEntranceEdge(TileIndex tile, uint z_new, Slope tileh_new, DiagDirection entrance)
{ {
if (GetTileMaxPixelZ(tile) != z_new + GetSlopeMaxPixelZ(tileh_new)) return false; if (GetTileMaxZ(tile) != z_new + GetSlopeMaxZ(tileh_new)) return false;
return ((tileh_new == SLOPE_FLAT) || CanBuildDepotByTileh(entrance, tileh_new)); return ((tileh_new == SLOPE_FLAT) || CanBuildDepotByTileh(entrance, tileh_new));
} }

View File

@ -2726,7 +2726,7 @@ static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, u
*/ */
Slope tileh_old = GetTileSlope(tile); Slope tileh_old = GetTileSlope(tile);
/* TileMaxZ must not be changed. Slopes must not be steep. */ /* TileMaxZ must not be changed. Slopes must not be steep. */
if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxPixelZ(tile) == z_new + GetSlopeMaxPixelZ(tileh_new))) { if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
const IndustryGfx gfx = GetIndustryGfx(tile); const IndustryGfx gfx = GetIndustryGfx(tile);
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);

View File

@ -733,7 +733,7 @@ static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlag flags, uin
*/ */
Slope tileh_old = GetTileSlope(tile); Slope tileh_old = GetTileSlope(tile);
/* TileMaxZ must not be changed. Slopes must not be steep. */ /* TileMaxZ must not be changed. Slopes must not be steep. */
if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxPixelZ(tile) == z_new + GetSlopeMaxPixelZ(tileh_new))) { if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
const ObjectSpec *spec = ObjectSpec::Get(type); const ObjectSpec *spec = ObjectSpec::Get(type);
/* Call callback 'disable autosloping for objects'. */ /* Call callback 'disable autosloping for objects'. */

View File

@ -2795,8 +2795,8 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, uint z_ol
if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK); if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
/* Get the slopes on top of the foundations */ /* Get the slopes on top of the foundations */
z_old += ApplyPixelFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), &tileh_old); z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), &tileh_old);
z_new += ApplyPixelFoundationToSlope(GetRailFoundation(tileh_new, rail_bits), &tileh_new); z_new += ApplyFoundationToSlope(GetRailFoundation(tileh_new, rail_bits), &tileh_new);
Corner track_corner; Corner track_corner;
switch (rail_bits) { switch (rail_bits) {
@ -2812,8 +2812,8 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, uint z_ol
} }
/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */ /* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
z_old += GetSlopePixelZInCorner(RemoveHalftileSlope(tileh_old), track_corner); z_old += GetSlopeZInCorner(RemoveHalftileSlope(tileh_old), track_corner);
z_new += GetSlopePixelZInCorner(RemoveHalftileSlope(tileh_new), track_corner); z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner);
if (z_old != z_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK); if (z_old != z_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
@ -2829,7 +2829,7 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, uint z_ol
static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new) static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
{ {
uint z_old; uint z_old;
Slope tileh_old = GetTilePixelSlope(tile, &z_old); Slope tileh_old = GetTileSlope(tile, &z_old);
if (IsPlainRail(tile)) { if (IsPlainRail(tile)) {
TrackBits rail_bits = GetTrackBits(tile); TrackBits rail_bits = GetTrackBits(tile);
/* Is there flat water on the lower halftile that must be cleared expensively? */ /* Is there flat water on the lower halftile that must be cleared expensively? */
@ -2856,7 +2856,7 @@ static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, uint
/* Everything is valid, which only changes allowed_corner */ /* Everything is valid, which only changes allowed_corner */
for (Corner corner = (Corner)0; corner < CORNER_END; corner = (Corner)(corner + 1)) { for (Corner corner = (Corner)0; corner < CORNER_END; corner = (Corner)(corner + 1)) {
if (allowed_corner == corner) continue; if (allowed_corner == corner) continue;
if (z_old + GetSlopePixelZInCorner(tileh_old, corner) != z_new + GetSlopePixelZInCorner(tileh_new, corner)) return autoslope_result; if (z_old + GetSlopeZInCorner(tileh_old, corner) != z_new + GetSlopeZInCorner(tileh_new, corner)) return autoslope_result;
} }
/* Make the ground dirty */ /* Make the ground dirty */

View File

@ -1682,7 +1682,7 @@ static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlag flags, uint
if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) { if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
switch (GetRoadTileType(tile)) { switch (GetRoadTileType(tile)) {
case ROAD_TILE_CROSSING: case ROAD_TILE_CROSSING:
if (!IsSteepSlope(tileh_new) && (GetTileMaxPixelZ(tile) == z_new + GetSlopeMaxPixelZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
break; break;
case ROAD_TILE_DEPOT: case ROAD_TILE_DEPOT:
@ -1697,11 +1697,11 @@ static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlag flags, uint
/* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */ /* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */
if (bits == bits_copy) { if (bits == bits_copy) {
uint z_old; uint z_old;
Slope tileh_old = GetTilePixelSlope(tile, &z_old); Slope tileh_old = GetTileSlope(tile, &z_old);
/* Get the slope on top of the foundation */ /* Get the slope on top of the foundation */
z_old += ApplyPixelFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old); z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old);
z_new += ApplyPixelFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new); z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new);
/* The surface slope must not be changed */ /* The surface slope must not be changed */
if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);

View File

@ -3595,7 +3595,7 @@ static CommandCost TerraformTile_Station(TileIndex tile, DoCommandFlag flags, ui
/* TODO: If you implement newgrf callback 149 'land slope check', you have to decide what to do with it here. /* TODO: If you implement newgrf callback 149 'land slope check', you have to decide what to do with it here.
* TTDP does not call it. * TTDP does not call it.
*/ */
if (GetTileMaxPixelZ(tile) == z_new + GetSlopeMaxPixelZ(tileh_new)) { if (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) {
switch (GetStationType(tile)) { switch (GetStationType(tile)) {
case STATION_WAYPOINT: case STATION_WAYPOINT:
case STATION_RAIL: { case STATION_RAIL: {

View File

@ -338,7 +338,7 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (indirectly_cleared) { if (indirectly_cleared) {
cost = DoCommand(tile, 0, 0, tile_flags, CMD_LANDSCAPE_CLEAR); cost = DoCommand(tile, 0, 0, tile_flags, CMD_LANDSCAPE_CLEAR);
} else { } else {
cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, tile_flags, z_min * TILE_HEIGHT, tileh); cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, tile_flags, z_min, tileh);
} }
_generating_world = curr_gen; _generating_world = curr_gen;
if (cost.Failed()) { if (cost.Failed()) {

View File

@ -3055,7 +3055,7 @@ static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, uint
/* Here we differ from TTDP by checking TILE_NOT_SLOPED */ /* Here we differ from TTDP by checking TILE_NOT_SLOPED */
if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) && if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
(GetTileMaxPixelZ(tile) == z_new + GetSlopeMaxPixelZ(tileh_new))) { (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
bool allow_terraform = true; bool allow_terraform = true;
/* Call the autosloping callback per tile, not for the whole building at once. */ /* Call the autosloping callback per tile, not for the whole building at once. */

View File

@ -1676,8 +1676,6 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new) static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
{ {
if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && IsBridge(tile) && GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) { if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && IsBridge(tile) && GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) {
z_new /= TILE_HEIGHT;
DiagDirection direction = GetTunnelBridgeDirection(tile); DiagDirection direction = GetTunnelBridgeDirection(tile);
Axis axis = DiagDirToAxis(direction); Axis axis = DiagDirToAxis(direction);
CommandCost res; CommandCost res;