Skip to content

Commit

Permalink
Fix raise/lowering water at edge of map (OpenRCT2#9979)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacerat authored and Gymnasiast committed Sep 22, 2019
1 parent a11762b commit 2e5f46f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Fix: [#9625] Show correct cost in scenery selection.
- Fix: [#9669] The tile inspector shortcut key does not work with debugging tools disabled.
- Fix: [#9675] Guest entry point limit can be bypassed in scenario editor.
- Fix: [#9683] Cannot raise water level if part of the tool's area of effect is off of the map.
- Fix: [#9717] Scroll bars do not render correctly when using OpenGL renderer.
- Fix: [#9729] Peeps do not take into account height difference when deciding to pathfind to a ride entrance (original bug).
- Fix: [#9902] Doors/Portcullis do not check to make sure doors are open causing double opens.
Expand Down
9 changes: 5 additions & 4 deletions src/openrct2/actions/WaterLowerAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ DEFINE_GAME_ACTION(WaterLowerAction, GAME_COMMAND_LOWER_WATER, GameActionResult)
res->Position.z = z;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;

uint8_t minHeight = GetLowestHeight();
uint8_t minHeight = GetLowestHeight(validRange);
bool hasChanged = false;
for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += 32)
{
Expand Down Expand Up @@ -119,12 +119,13 @@ DEFINE_GAME_ACTION(WaterLowerAction, GAME_COMMAND_LOWER_WATER, GameActionResult)
}

private:
uint8_t GetLowestHeight() const
uint8_t GetLowestHeight(MapRange validRange) const
{
// The lowest height to lower the water to is the highest water level in the selection
uint8_t minHeight{ 0 };
for (int32_t y = _range.GetTop(); y <= _range.GetBottom(); y += 32)
for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += 32)
{
for (int32_t x = _range.GetLeft(); x <= _range.GetRight(); x += 32)
for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32)
{
auto* surfaceElement = map_get_surface_element_at({ x, y });
if (surfaceElement == nullptr)
Expand Down
9 changes: 5 additions & 4 deletions src/openrct2/actions/WaterRaiseAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ DEFINE_GAME_ACTION(WaterRaiseAction, GAME_COMMAND_RAISE_WATER, GameActionResult)
res->Position.z = z;
res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING;

uint8_t maxHeight = GetHighestHeight();
uint8_t maxHeight = GetHighestHeight(validRange);
bool hasChanged = false;
for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += 32)
{
Expand Down Expand Up @@ -126,12 +126,13 @@ DEFINE_GAME_ACTION(WaterRaiseAction, GAME_COMMAND_RAISE_WATER, GameActionResult)
}

private:
uint8_t GetHighestHeight() const
uint8_t GetHighestHeight(MapRange validRange) const
{
// The highest height to raise the water to is the lowest water level in the selection
uint8_t maxHeight{ 255 };
for (int32_t y = _range.GetTop(); y <= _range.GetBottom(); y += 32)
for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += 32)
{
for (int32_t x = _range.GetLeft(); x <= _range.GetRight(); x += 32)
for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += 32)
{
auto* surfaceElement = map_get_surface_element_at({ x, y });
if (surfaceElement == nullptr)
Expand Down

0 comments on commit 2e5f46f

Please sign in to comment.