From e4d72cefaa5737bf1d16794151c5fbbd877230ab Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Fri, 2 Oct 2020 00:34:54 -0300 Subject: [PATCH] Fix #5904: Empty errors on tile inspector base height change --- data/language/en-GB.txt | 3 +++ distribution/changelog.txt | 1 + src/openrct2/localisation/StringIds.h | 4 ++++ src/openrct2/world/TileInspector.cpp | 33 +++++++++++++++++++++------ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 6a73a1ada2..8e8dd3610f 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -3642,6 +3642,9 @@ STR_6383 :Open download page STR_6384 :Snow STR_6385 :Heavy Snow STR_6386 :Blizzard +STR_6387 :Can't lower element here... +STR_6388 :Can't raise element here... +STR_6389 :No clearance ############# # Scenarios # diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 812c3f5ee1..da944c4306 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -3,6 +3,7 @@ - Feature: [#12999] .sea (RCT Classic) scenarios are now listed in the “New Scenario” dialog. - Feature: [#13000] objective_options command for console. - Fix: [#3200] Close Construction window upon selecting vehicle page. +- Fix: [#5904] Empty errors on tile inspector base height change. - Fix: [#8015] RCT2 files are not found when put into the OpenRCT2 folder. - Fix: [#8957] Error title missing when building with insufficient funds - Fix: [#13021] Mowed grass and weeds don't show up in extra zoom levels. diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index 741c828cf4..843bfce007 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -3887,6 +3887,10 @@ enum STR_HEAVY_SNOW = 6385, STR_BLIZZARD = 6386, + STR_CANT_LOWER_ELEMENT_HERE = 6387, + STR_CANT_RAISE_ELEMENT_HERE = 6388, + STR_NO_CLEARANCE = 6389, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working /* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings }; diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index ca380e402d..8099d2b512 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -474,6 +474,29 @@ GameActionResult::Ptr tile_inspector_sort_elements_at(const CoordsXY& loc, bool return std::make_unique(); } +static GameActionResult::Ptr ValidateTileHeight(TileElement* const tileElement, int8_t heightOffset) +{ + int16_t newBaseHeight = static_cast(tileElement->base_height + heightOffset); + int16_t newClearanceHeight = static_cast(tileElement->clearance_height + heightOffset); + if (newBaseHeight < 0) + { + return std::make_unique(GA_ERROR::TOO_LOW, STR_CANT_LOWER_ELEMENT_HERE, STR_TOO_LOW); + } + else if (newBaseHeight > MAX_ELEMENT_HEIGHT) + { + return std::make_unique(GA_ERROR::TOO_HIGH, STR_CANT_RAISE_ELEMENT_HERE, STR_TOO_HIGH); + } + else if (newClearanceHeight < 0) + { + return std::make_unique(GA_ERROR::NO_CLEARANCE, STR_CANT_LOWER_ELEMENT_HERE, STR_NO_CLEARANCE); + } + else if (newClearanceHeight > MAX_ELEMENT_HEIGHT) + { + return std::make_unique(GA_ERROR::NO_CLEARANCE, STR_CANT_RAISE_ELEMENT_HERE, STR_NO_CLEARANCE); + } + return std::make_unique(); +} + GameActionResult::Ptr tile_inspector_any_base_height_offset( const CoordsXY& loc, int16_t elementIndex, int8_t heightOffset, bool isExecuting) { @@ -481,13 +504,9 @@ GameActionResult::Ptr tile_inspector_any_base_height_offset( if (tileElement == nullptr) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); - int16_t newBaseHeight = static_cast(tileElement->base_height + heightOffset); - int16_t newClearanceHeight = static_cast(tileElement->clearance_height + heightOffset); - if (newBaseHeight < 0 || newBaseHeight > MAX_ELEMENT_HEIGHT || newClearanceHeight < 0 - || newClearanceHeight > MAX_ELEMENT_HEIGHT) - { - return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); - } + auto heightValidationResult = ValidateTileHeight(tileElement, heightOffset); + if (heightValidationResult->Error != GA_ERROR::OK) + return heightValidationResult; if (isExecuting) {