diff --git a/src/openrct2/actions/LandLowerAction.hpp b/src/openrct2/actions/LandLowerAction.hpp index 665a13e0ac..0ef06089ca 100644 --- a/src/openrct2/actions/LandLowerAction.hpp +++ b/src/openrct2/actions/LandLowerAction.hpp @@ -100,39 +100,39 @@ private: for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32) { TileElement* tileElement = map_get_surface_element_at(x / 32, y / 32); - if (tileElement != nullptr) + if (tileElement == nullptr) + continue; + + SurfaceElement* surfaceElement = tileElement->AsSurface(); + uint8_t height = surfaceElement->base_height; + if (surfaceElement->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK) + height += 2; + if (surfaceElement->GetSlope() & TILE_ELEMENT_SURFACE_DIAGONAL_FLAG) + height += 2; + + if (height < maxHeight) + continue; + + height = surfaceElement->base_height; + uint8_t currentSlope = surfaceElement->GetSlope(); + uint8_t newSlope = tile_element_lower_styles[tableRow][currentSlope]; + if (newSlope & SURFACE_STYLE_FLAG_RAISE_OR_LOWER_BASE_HEIGHT) + height -= 2; + + newSlope &= TILE_ELEMENT_SURFACE_SLOPE_MASK; + + auto landSetHeightAction = LandSetHeightAction({ x, y }, height, newSlope); + landSetHeightAction.SetFlags(GetFlags()); + auto result = isExecuting ? GameActions::ExecuteNested(&landSetHeightAction) + : GameActions::QueryNested(&landSetHeightAction); + if (result->Error == GA_ERROR::OK) { - SurfaceElement* surfaceElement = tileElement->AsSurface(); - uint8_t height = surfaceElement->base_height; - if (surfaceElement->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK) - height += 2; - if (surfaceElement->GetSlope() & TILE_ELEMENT_SURFACE_DIAGONAL_FLAG) - height += 2; - - if (height >= maxHeight) - { - height = surfaceElement->base_height; - uint8_t currentSlope = surfaceElement->GetSlope(); - uint8_t newSlope = tile_element_lower_styles[tableRow][currentSlope]; - if (newSlope & SURFACE_STYLE_FLAG_RAISE_OR_LOWER_BASE_HEIGHT) - height -= 2; - - newSlope &= TILE_ELEMENT_SURFACE_SLOPE_MASK; - - auto landSetHeightAction = LandSetHeightAction({ x, y }, height, newSlope); - landSetHeightAction.SetFlags(GetFlags()); - auto result = isExecuting ? GameActions::ExecuteNested(&landSetHeightAction) - : GameActions::QueryNested(&landSetHeightAction); - if (result->Error == GA_ERROR::OK) - { - res->Cost += result->Cost; - } - else - { - result->ErrorTitle = STR_CANT_LOWER_LAND_HERE; - return result; - } - } + res->Cost += result->Cost; + } + else + { + result->ErrorTitle = STR_CANT_LOWER_LAND_HERE; + return result; } } } diff --git a/src/openrct2/actions/LandRaiseAction.hpp b/src/openrct2/actions/LandRaiseAction.hpp index 3a863e77a5..fb2ddd40a2 100644 --- a/src/openrct2/actions/LandRaiseAction.hpp +++ b/src/openrct2/actions/LandRaiseAction.hpp @@ -100,34 +100,34 @@ private: for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32) { TileElement* tileElement = map_get_surface_element_at(x / 32, y / 32); - if (tileElement != nullptr) + if (tileElement == nullptr) + continue; + + SurfaceElement* surfaceElement = tileElement->AsSurface(); + uint8_t height = surfaceElement->base_height; + + if (height > minHeight) + continue; + + uint8_t currentSlope = surfaceElement->GetSlope(); + uint8_t newSlope = tile_element_raise_styles[tableRow][currentSlope]; + if (newSlope & SURFACE_STYLE_FLAG_RAISE_OR_LOWER_BASE_HEIGHT) + height += 2; + + newSlope &= TILE_ELEMENT_SURFACE_SLOPE_MASK; + + auto landSetHeightAction = LandSetHeightAction({ x, y }, height, newSlope); + landSetHeightAction.SetFlags(GetFlags()); + auto result = isExecuting ? GameActions::ExecuteNested(&landSetHeightAction) + : GameActions::QueryNested(&landSetHeightAction); + if (result->Error == GA_ERROR::OK) { - SurfaceElement* surfaceElement = tileElement->AsSurface(); - uint8_t height = surfaceElement->base_height; - - if (height <= minHeight) - { - uint8_t currentSlope = surfaceElement->GetSlope(); - uint8_t newSlope = tile_element_raise_styles[tableRow][currentSlope]; - if (newSlope & SURFACE_STYLE_FLAG_RAISE_OR_LOWER_BASE_HEIGHT) - height += 2; - - newSlope &= TILE_ELEMENT_SURFACE_SLOPE_MASK; - - auto landSetHeightAction = LandSetHeightAction({ x, y }, height, newSlope); - landSetHeightAction.SetFlags(GetFlags()); - auto result = isExecuting ? GameActions::ExecuteNested(&landSetHeightAction) - : GameActions::QueryNested(&landSetHeightAction); - if (result->Error == GA_ERROR::OK) - { - res->Cost += result->Cost; - } - else - { - result->ErrorTitle = STR_CANT_RAISE_LAND_HERE; - return result; - } - } + res->Cost += result->Cost; + } + else + { + result->ErrorTitle = STR_CANT_RAISE_LAND_HERE; + return result; } } } diff --git a/src/openrct2/actions/WaterLowerAction.hpp b/src/openrct2/actions/WaterLowerAction.hpp index aea73e8815..5671f49938 100644 --- a/src/openrct2/actions/WaterLowerAction.hpp +++ b/src/openrct2/actions/WaterLowerAction.hpp @@ -81,31 +81,32 @@ private: for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32) { TileElement* tileElement = map_get_surface_element_at(x / 32, y / 32); - if (tileElement != nullptr) + if (tileElement == nullptr) + continue; + + SurfaceElement* surfaceElement = tileElement->AsSurface(); + uint8_t height = surfaceElement->GetWaterHeight(); + if (height == 0) + continue; + + height *= 2; + if (height < minHeight) + continue; + + height -= 2; + auto waterSetHeightAction = WaterSetHeightAction({ x, y }, height); + waterSetHeightAction.SetFlags(GetFlags()); + auto result = isExecuting ? GameActions::ExecuteNested(&waterSetHeightAction) + : GameActions::QueryNested(&waterSetHeightAction); + if (result->Error == GA_ERROR::OK) { - SurfaceElement* surfaceElement = tileElement->AsSurface(); - uint8_t height = surfaceElement->GetWaterHeight(); - if (height != 0) - { - height *= 2; - if (height < minHeight) - continue; - height -= 2; - auto waterSetHeightAction = WaterSetHeightAction({ x, y }, height); - waterSetHeightAction.SetFlags(GetFlags()); - auto result = isExecuting ? GameActions::ExecuteNested(&waterSetHeightAction) - : GameActions::QueryNested(&waterSetHeightAction); - if (result->Error == GA_ERROR::OK) - { - res->Cost += result->Cost; - hasChanged = true; - } - else - { - result->ErrorTitle = STR_CANT_LOWER_WATER_LEVEL_HERE; - return result; - } - } + res->Cost += result->Cost; + hasChanged = true; + } + else + { + result->ErrorTitle = STR_CANT_LOWER_WATER_LEVEL_HERE; + return result; } } } @@ -129,15 +130,17 @@ private: for (int32_t x = _range.GetLeft(); x <= _range.GetRight(); x += 32) { TileElement* tile_element = map_get_surface_element_at({ x, y }); - if (tile_element != nullptr) + if (tile_element == nullptr) + continue; + + uint8_t height = tile_element->AsSurface()->GetWaterHeight(); + if (height == 0) + continue; + + height *= 2; + if (height > minHeight) { - uint8_t height = tile_element->AsSurface()->GetWaterHeight(); - if (height != 0) - { - height *= 2; - if (height > minHeight) - minHeight = height; - } + minHeight = height; } } } diff --git a/src/openrct2/actions/WaterRaiseAction.hpp b/src/openrct2/actions/WaterRaiseAction.hpp index 35aa094540..65b4104859 100644 --- a/src/openrct2/actions/WaterRaiseAction.hpp +++ b/src/openrct2/actions/WaterRaiseAction.hpp @@ -81,35 +81,35 @@ private: for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32) { TileElement* tileElement = map_get_surface_element_at(x / 32, y / 32); - if (tileElement != nullptr) + if (tileElement == nullptr) + continue; + + SurfaceElement* surfaceElement = tileElement->AsSurface(); + uint8_t height = surfaceElement->GetWaterHeight(); + if (height != 0) { - SurfaceElement* surfaceElement = tileElement->AsSurface(); - uint8_t height = surfaceElement->GetWaterHeight(); - if (height != 0) - { - height *= 2; - if (height > maxHeight) - continue; - height += 2; - } - else - { - height = surfaceElement->base_height + 2; - } - auto waterSetHeightAction = WaterSetHeightAction({ x, y }, height); - waterSetHeightAction.SetFlags(GetFlags()); - auto result = isExecuting ? GameActions::ExecuteNested(&waterSetHeightAction) - : GameActions::QueryNested(&waterSetHeightAction); - if (result->Error == GA_ERROR::OK) - { - res->Cost += result->Cost; - hasChanged = true; - } - else - { - result->ErrorTitle = STR_CANT_RAISE_WATER_LEVEL_HERE; - return result; - } + height *= 2; + if (height > maxHeight) + continue; + height += 2; + } + else + { + height = surfaceElement->base_height + 2; + } + auto waterSetHeightAction = WaterSetHeightAction({ x, y }, height); + waterSetHeightAction.SetFlags(GetFlags()); + auto result = isExecuting ? GameActions::ExecuteNested(&waterSetHeightAction) + : GameActions::QueryNested(&waterSetHeightAction); + if (result->Error == GA_ERROR::OK) + { + res->Cost += result->Cost; + hasChanged = true; + } + else + { + result->ErrorTitle = STR_CANT_RAISE_WATER_LEVEL_HERE; + return result; } } } @@ -133,16 +133,16 @@ private: for (int32_t x = _range.GetLeft(); x <= _range.GetRight(); x += 32) { TileElement* tile_element = map_get_surface_element_at({ x, y }); - if (tile_element != nullptr) + if (tile_element == nullptr) + continue; + + uint8_t height = tile_element->AsSurface()->GetWaterHeight(); + if (height != 0) { - uint8_t height = tile_element->AsSurface()->GetWaterHeight(); - if (height != 0) + height *= 2; + if (maxHeight > height) { - height *= 2; - if (maxHeight > height) - { - maxHeight = height; - } + maxHeight = height; } } }