From dff747ce0fcfdc2cff982844fd877d705f198eaa Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Fri, 3 Jan 2020 22:41:34 -0300 Subject: [PATCH 1/2] Improve variable names in map_can_construct_with_clear_at() --- src/openrct2/world/Map.cpp | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 1eb5fccbce..f0c1bfaf9c 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1266,8 +1266,8 @@ bool map_can_construct_with_clear_at( const CoordsXYRangedZ& pos, CLEAR_FUNC clearFunc, QuarterTile quarterTile, uint8_t flags, money32* price, uint8_t crossingMode) { - int32_t al, ah, bh, cl, ch, water_height; - al = ah = bh = cl = ch = water_height = 0; + int32_t northZ, eastZ, baseHeight, southZ, westZ, water_height; + northZ = eastZ = baseHeight = southZ = westZ = water_height = 0; uint8_t slope = 0; gMapGroundFlags = ELEMENT_IS_ABOVE_GROUND; @@ -1312,10 +1312,10 @@ bool map_can_construct_with_clear_at( loc_68B9B7: if (gParkFlags & PARK_FLAGS_FORBID_HIGH_CONSTRUCTION) { - al = pos.clearanceZ / 8 - tileElement->base_height; - if (al >= 0) + auto heightFromGround = pos.clearanceZ / 8 - tileElement->base_height; + if (heightFromGround >= 0) { - if (al > 18) + if (heightFromGround > 18) { gGameCommandErrorText = STR_LOCAL_AUTHORITY_WONT_ALLOW_CONSTRUCTION_ABOVE_TREE_HEIGHT; return false; @@ -1340,43 +1340,43 @@ bool map_can_construct_with_clear_at( } else { - al = tileElement->base_height; - ah = al; - cl = al; - ch = al; + northZ = tileElement->base_height; + eastZ = northZ; + southZ = northZ; + westZ = northZ; slope = tileElement->AsSurface()->GetSlope(); if (slope & TILE_ELEMENT_SLOPE_N_CORNER_UP) { - al += 2; + northZ += 2; if (slope == (TILE_ELEMENT_SLOPE_S_CORNER_DN | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)) - al += 2; + northZ += 2; } if (slope & TILE_ELEMENT_SLOPE_E_CORNER_UP) { - ah += 2; + eastZ += 2; if (slope == (TILE_ELEMENT_SLOPE_W_CORNER_DN | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)) - ah += 2; + eastZ += 2; } if (slope & TILE_ELEMENT_SLOPE_S_CORNER_UP) { - cl += 2; + southZ += 2; if (slope == (TILE_ELEMENT_SLOPE_N_CORNER_DN | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)) - cl += 2; + southZ += 2; } if (slope & TILE_ELEMENT_SLOPE_W_CORNER_UP) { - ch += 2; + westZ += 2; if (slope == (TILE_ELEMENT_SLOPE_E_CORNER_DN | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)) - ch += 2; + westZ += 2; } - bh = pos.baseZ / 8 + 4; + baseHeight = pos.baseZ / 8 + 4; { auto baseQuarter = quarterTile.GetBaseQuarterOccupied(); auto zQuarter = quarterTile.GetZQuarterOccupied(); - if ((!(baseQuarter & 0b0001) || ((zQuarter & 0b0001 || pos.baseZ / 8 >= al) && bh >= al)) - && (!(baseQuarter & 0b0010) || ((zQuarter & 0b0010 || pos.baseZ / 8 >= ah) && bh >= ah)) - && (!(baseQuarter & 0b0100) || ((zQuarter & 0b0100 || pos.baseZ / 8 >= cl) && bh >= cl)) - && (!(baseQuarter & 0b1000) || ((zQuarter & 0b1000 || pos.baseZ / 8 >= ch) && bh >= ch))) + if ((!(baseQuarter & 0b0001) || ((zQuarter & 0b0001 || pos.baseZ / 8 >= northZ) && baseHeight >= northZ)) + && (!(baseQuarter & 0b0010) || ((zQuarter & 0b0010 || pos.baseZ / 8 >= eastZ) && baseHeight >= eastZ)) + && (!(baseQuarter & 0b0100) || ((zQuarter & 0b0100 || pos.baseZ / 8 >= southZ) && baseHeight >= southZ)) + && (!(baseQuarter & 0b1000) || ((zQuarter & 0b1000 || pos.baseZ / 8 >= westZ) && baseHeight >= westZ))) { continue; } From d3579e472b8d6c0832298a2443761d63959c4514 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Fri, 3 Jan 2020 22:43:47 -0300 Subject: [PATCH 2/2] Use Big Z coordinates for map_can_construct_with_clear_at() vars --- src/openrct2/world/Map.cpp | 39 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index f0c1bfaf9c..b35466dc14 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1312,14 +1312,11 @@ bool map_can_construct_with_clear_at( loc_68B9B7: if (gParkFlags & PARK_FLAGS_FORBID_HIGH_CONSTRUCTION) { - auto heightFromGround = pos.clearanceZ / 8 - tileElement->base_height; - if (heightFromGround >= 0) + auto heightFromGround = pos.clearanceZ - tileElement->GetBaseZ(); + if (heightFromGround > (18 * COORDS_Z_STEP)) { - if (heightFromGround > 18) - { - gGameCommandErrorText = STR_LOCAL_AUTHORITY_WONT_ALLOW_CONSTRUCTION_ABOVE_TREE_HEIGHT; - return false; - } + gGameCommandErrorText = STR_LOCAL_AUTHORITY_WONT_ALLOW_CONSTRUCTION_ABOVE_TREE_HEIGHT; + return false; } } @@ -1340,43 +1337,43 @@ bool map_can_construct_with_clear_at( } else { - northZ = tileElement->base_height; + northZ = tileElement->GetBaseZ(); eastZ = northZ; southZ = northZ; westZ = northZ; slope = tileElement->AsSurface()->GetSlope(); if (slope & TILE_ELEMENT_SLOPE_N_CORNER_UP) { - northZ += 2; + northZ += LAND_HEIGHT_STEP; if (slope == (TILE_ELEMENT_SLOPE_S_CORNER_DN | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)) - northZ += 2; + northZ += LAND_HEIGHT_STEP; } if (slope & TILE_ELEMENT_SLOPE_E_CORNER_UP) { - eastZ += 2; + eastZ += LAND_HEIGHT_STEP; if (slope == (TILE_ELEMENT_SLOPE_W_CORNER_DN | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)) - eastZ += 2; + eastZ += LAND_HEIGHT_STEP; } if (slope & TILE_ELEMENT_SLOPE_S_CORNER_UP) { - southZ += 2; + southZ += LAND_HEIGHT_STEP; if (slope == (TILE_ELEMENT_SLOPE_N_CORNER_DN | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)) - southZ += 2; + southZ += LAND_HEIGHT_STEP; } if (slope & TILE_ELEMENT_SLOPE_W_CORNER_UP) { - westZ += 2; + westZ += LAND_HEIGHT_STEP; if (slope == (TILE_ELEMENT_SLOPE_E_CORNER_DN | TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT)) - westZ += 2; + westZ += LAND_HEIGHT_STEP; } - baseHeight = pos.baseZ / 8 + 4; + baseHeight = pos.baseZ + (4 * COORDS_Z_STEP); { auto baseQuarter = quarterTile.GetBaseQuarterOccupied(); auto zQuarter = quarterTile.GetZQuarterOccupied(); - if ((!(baseQuarter & 0b0001) || ((zQuarter & 0b0001 || pos.baseZ / 8 >= northZ) && baseHeight >= northZ)) - && (!(baseQuarter & 0b0010) || ((zQuarter & 0b0010 || pos.baseZ / 8 >= eastZ) && baseHeight >= eastZ)) - && (!(baseQuarter & 0b0100) || ((zQuarter & 0b0100 || pos.baseZ / 8 >= southZ) && baseHeight >= southZ)) - && (!(baseQuarter & 0b1000) || ((zQuarter & 0b1000 || pos.baseZ / 8 >= westZ) && baseHeight >= westZ))) + if ((!(baseQuarter & 0b0001) || ((zQuarter & 0b0001 || pos.baseZ >= northZ) && baseHeight >= northZ)) + && (!(baseQuarter & 0b0010) || ((zQuarter & 0b0010 || pos.baseZ >= eastZ) && baseHeight >= eastZ)) + && (!(baseQuarter & 0b0100) || ((zQuarter & 0b0100 || pos.baseZ >= southZ) && baseHeight >= southZ)) + && (!(baseQuarter & 0b1000) || ((zQuarter & 0b1000 || pos.baseZ >= westZ) && baseHeight >= westZ))) { continue; }