Skip to content

Commit

Permalink
Make GetWaterHeight return big Z (#10579)
Browse files Browse the repository at this point in the history
* Make GetWaterHeight return big Z

* Restore > 0 [ci skip]
  • Loading branch information
Gymnasiast authored and duncanspumpkin committed Jan 19, 2020
1 parent 8abb9e5 commit d798811
Show file tree
Hide file tree
Showing 27 changed files with 80 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/openrct2-ui/interface/ViewportInteraction.cpp
Expand Up @@ -677,7 +677,7 @@ CoordsXY sub_68A15E(ScreenCoordsXY screenCoords)
int16_t waterHeight = 0;
if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER)
{
waterHeight = tileElement->AsSurface()->GetWaterHeight() << 4;
waterHeight = tileElement->AsSurface()->GetWaterHeight();
}

auto initialVPPos = screen_coord_to_viewport_coord(viewport, screenCoords);
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2-ui/windows/Map.cpp
Expand Up @@ -1204,7 +1204,7 @@ static CoordsXYZD place_park_entrance_get_map_position(ScreenCoordsXY screenCoor
return parkEntranceMapPosition;
}

parkEntranceMapPosition.z = surfaceElement->GetWaterHeight() * 8;
parkEntranceMapPosition.z = surfaceElement->GetWaterHeight();
if (parkEntranceMapPosition.z == 0)
{
parkEntranceMapPosition.z = surfaceElement->GetBaseZ();
Expand Down
7 changes: 3 additions & 4 deletions src/openrct2-ui/windows/TrackDesignPlace.cpp
Expand Up @@ -474,12 +474,11 @@ void TrackPlaceRestoreProvisional()
*/
static int32_t window_track_place_get_base_z(int32_t x, int32_t y)
{
uint32_t z;

auto surfaceElement = map_get_surface_element_at(CoordsXY{ x, y });
if (surfaceElement == nullptr)
return 0;
z = surfaceElement->GetBaseZ();

auto z = surfaceElement->GetBaseZ();

// Increase Z above slope
if (surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP)
Expand All @@ -493,7 +492,7 @@ static int32_t window_track_place_get_base_z(int32_t x, int32_t y)

// Increase Z above water
if (surfaceElement->GetWaterHeight() > 0)
z = std::max(z, surfaceElement->GetWaterHeight() << 4);
z = std::max(z, surfaceElement->GetWaterHeight());

return z + place_virtual_track(_trackDesign.get(), PTD_OPERATION_GET_PLACE_Z, true, GetOrAllocateRide(0), x, y, z);
}
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/actions/LandSetHeightAction.hpp
Expand Up @@ -321,7 +321,7 @@ DEFINE_GAME_ACTION(LandSetHeightAction, GAME_COMMAND_SET_LAND_HEIGHT, GameAction
zCorner += 2;
}
}
if (zCorner > waterHeight * 2 - 2)
if (zCorner > (waterHeight / COORDS_Z_STEP) - 2)
{
return ++surfaceElement;
}
Expand Down Expand Up @@ -381,8 +381,8 @@ DEFINE_GAME_ACTION(LandSetHeightAction, GAME_COMMAND_SET_LAND_HEIGHT, GameAction
surfaceElement->base_height = _height;
surfaceElement->clearance_height = _height;
surfaceElement->AsSurface()->SetSlope(_style);
int32_t waterHeight = surfaceElement->AsSurface()->GetWaterHeight();
if (waterHeight != 0 && waterHeight <= _height / 2)
int32_t waterHeight = surfaceElement->AsSurface()->GetWaterHeight() / COORDS_Z_STEP;
if (waterHeight != 0 && waterHeight <= _height)
{
surfaceElement->AsSurface()->SetWaterHeight(0);
}
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/actions/SmallSceneryPlaceAction.hpp
Expand Up @@ -189,7 +189,7 @@ DEFINE_GAME_ACTION(SmallSceneryPlaceAction, GAME_COMMAND_PLACE_SCENERY, SmallSce

if (surfaceElement != nullptr && !gCheatsDisableClearanceChecks && surfaceElement->GetWaterHeight() > 0)
{
int32_t water_height = (surfaceElement->GetWaterHeight() * 16) - 1;
int32_t water_height = surfaceElement->GetWaterHeight() - 1;
if (water_height > targetHeight)
{
return std::make_unique<SmallSceneryPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CANT_BUILD_THIS_UNDERWATER);
Expand All @@ -205,7 +205,7 @@ DEFINE_GAME_ACTION(SmallSceneryPlaceAction, GAME_COMMAND_PLACE_SCENERY, SmallSce

if (surfaceElement != nullptr && surfaceElement->GetWaterHeight() > 0)
{
if (static_cast<int32_t>((surfaceElement->GetWaterHeight() * 16)) > targetHeight)
if (surfaceElement->GetWaterHeight() > targetHeight)
{
return std::make_unique<SmallSceneryPlaceActionResult>(
GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ON_LAND);
Expand All @@ -227,7 +227,7 @@ DEFINE_GAME_ACTION(SmallSceneryPlaceAction, GAME_COMMAND_PLACE_SCENERY, SmallSce
{
if (surfaceElement != nullptr)
{
if (surfaceElement->GetWaterHeight() || (surfaceElement->GetBaseZ()) != targetHeight)
if (surfaceElement->GetWaterHeight() > 0 || (surfaceElement->GetBaseZ()) != targetHeight)
{
return std::make_unique<SmallSceneryPlaceActionResult>(GA_ERROR::DISALLOWED, STR_LEVEL_LAND_REQUIRED);
}
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/actions/TrackPlaceAction.hpp
Expand Up @@ -315,7 +315,8 @@ DEFINE_GAME_ACTION(TrackPlaceAction, GAME_COMMAND_PLACE_TRACK, TrackPlaceActionR
if (surfaceElement == nullptr)
return std::make_unique<TrackPlaceActionResult>(GA_ERROR::UNKNOWN, STR_NONE);

uint8_t waterHeight = surfaceElement->GetWaterHeight() * 2;
// TODO: Make everything use big Z coordinates so we can stop dividing and multiplying by COORDS_Z_STEP.
uint8_t waterHeight = surfaceElement->GetWaterHeight() / COORDS_Z_STEP;
if (waterHeight == 0)
{
return std::make_unique<TrackPlaceActionResult>(GA_ERROR::DISALLOWED, STR_CAN_ONLY_BUILD_THIS_ON_WATER);
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/actions/WallPlaceAction.hpp
Expand Up @@ -166,7 +166,7 @@ DEFINE_GAME_ACTION(WallPlaceAction, GAME_COMMAND_PLACE_WALL, WallPlaceActionResu

if (surfaceElement->GetWaterHeight() > 0)
{
uint16_t waterHeight = surfaceElement->GetWaterHeight() * 16;
uint16_t waterHeight = surfaceElement->GetWaterHeight();

if (targetHeight < waterHeight && !gCheatsDisableClearanceChecks)
{
Expand Down
6 changes: 2 additions & 4 deletions src/openrct2/actions/WaterLowerAction.hpp
Expand Up @@ -82,11 +82,10 @@ DEFINE_GAME_ACTION(WaterLowerAction, GAME_COMMAND_LOWER_WATER, GameActionResult)
if (surfaceElement == nullptr)
continue;

uint8_t height = surfaceElement->GetWaterHeight();
uint8_t height = surfaceElement->GetWaterHeight() / COORDS_Z_STEP;
if (height == 0)
continue;

height *= 2;
if (height < minHeight)
continue;

Expand Down Expand Up @@ -131,11 +130,10 @@ DEFINE_GAME_ACTION(WaterLowerAction, GAME_COMMAND_LOWER_WATER, GameActionResult)
if (surfaceElement == nullptr)
continue;

uint8_t height = surfaceElement->GetWaterHeight();
uint8_t height = surfaceElement->GetWaterHeight() / COORDS_Z_STEP;
if (height == 0)
continue;

height *= 2;
if (height > minHeight)
{
minHeight = height;
Expand Down
5 changes: 2 additions & 3 deletions src/openrct2/actions/WaterRaiseAction.hpp
Expand Up @@ -82,14 +82,13 @@ DEFINE_GAME_ACTION(WaterRaiseAction, GAME_COMMAND_RAISE_WATER, GameActionResult)
auto surfaceElement = map_get_surface_element_at(CoordsXY{ x, y });
if (surfaceElement == nullptr)
continue;
uint8_t height = surfaceElement->GetWaterHeight();
uint8_t height = surfaceElement->GetWaterHeight() / COORDS_Z_STEP;

if (surfaceElement->base_height > maxHeight)
continue;

if (height != 0)
{
height *= 2;
if (height > maxHeight)
continue;
height += 2;
Expand Down Expand Up @@ -141,7 +140,7 @@ DEFINE_GAME_ACTION(WaterRaiseAction, GAME_COMMAND_RAISE_WATER, GameActionResult)
uint8_t height = surfaceElement->base_height;
if (surfaceElement->GetWaterHeight() > 0)
{
height = surfaceElement->GetWaterHeight() * 2;
height = surfaceElement->GetWaterHeight() / COORDS_Z_STEP;
}

if (maxHeight > height)
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/WaterSetHeightAction.hpp
Expand Up @@ -82,7 +82,7 @@ DEFINE_GAME_ACTION(WaterSetHeightAction, GAME_COMMAND_SET_WATER_HEIGHT, GameActi
int32_t zLow = _height;
if (surfaceElement->GetWaterHeight() > 0)
{
zHigh = surfaceElement->GetWaterHeight() * 2;
zHigh = surfaceElement->GetWaterHeight() / COORDS_Z_STEP;
}
if (zLow > zHigh)
{
Expand Down Expand Up @@ -127,7 +127,7 @@ DEFINE_GAME_ACTION(WaterSetHeightAction, GAME_COMMAND_SET_WATER_HEIGHT, GameActi

if (_height > surfaceElement->base_height)
{
surfaceElement->SetWaterHeight(_height / 2);
surfaceElement->SetWaterHeight(_height * COORDS_Z_STEP);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/network/Network.cpp
Expand Up @@ -31,7 +31,7 @@
// This string specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "10"
#define NETWORK_STREAM_VERSION "11"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION

static Peep* _pickup_peep = nullptr;
Expand Down
57 changes: 28 additions & 29 deletions src/openrct2/paint/tile_element/Paint.Surface.cpp
Expand Up @@ -587,7 +587,7 @@ static void viewport_surface_draw_tile_side_bottom(

if (isWater && neighbour.tile_element != nullptr)
{
uint8_t waterHeight = neighbour.tile_element->AsSurface()->GetWaterHeight();
auto waterHeight = neighbour.tile_element->AsSurface()->GetWaterHeight() / COORDS_Z_STEP;
if (waterHeight == height && !neighbourIsClippedAway)
{
// Don't draw the edge when the neighbour's water level is the same
Expand Down Expand Up @@ -749,30 +749,30 @@ static void viewport_surface_draw_tile_side_top(
if (!is_csg_loaded() && terrain >= TERRAIN_EDGE_RCT2_COUNT)
terrain = TERRAIN_EDGE_ROCK;

int16_t al, ah, cl, ch, dl = 0, waterHeight;
int16_t cornerHeight1, neighbourCornerHeight1, cornerHeight2, neighbourCornerHeight2, dl = 0;

CoordsXY offset = { 0, 0 };
CoordsXY bounds = { 0, 0 };

switch (edge)
{
case EDGE_TOPLEFT:
al = self.corner_heights.top;
cl = self.corner_heights.left;
cornerHeight1 = self.corner_heights.top;
cornerHeight2 = self.corner_heights.left;

ah = neighbour.corner_heights.right;
ch = neighbour.corner_heights.bottom;
neighbourCornerHeight1 = neighbour.corner_heights.right;
neighbourCornerHeight2 = neighbour.corner_heights.bottom;

offset.y = -2;
bounds.x = 30;
break;

case EDGE_TOPRIGHT:
al = self.corner_heights.top;
cl = self.corner_heights.right;
cornerHeight1 = self.corner_heights.top;
cornerHeight2 = self.corner_heights.right;

ah = neighbour.corner_heights.left;
ch = neighbour.corner_heights.bottom;
neighbourCornerHeight1 = neighbour.corner_heights.left;
neighbourCornerHeight2 = neighbour.corner_heights.bottom;

offset.x = -2;
bounds.y = 30;
Expand All @@ -788,26 +788,25 @@ static void viewport_surface_draw_tile_side_top(
// save ecx
if (neighbour.tile_element == nullptr)
{
ah = 1;
ch = 1;
neighbourCornerHeight1 = 1;
neighbourCornerHeight2 = 1;
}
else
{
if (isWater)
{
waterHeight = neighbour.tile_element->AsSurface()->GetWaterHeight();
auto waterHeight = neighbour.tile_element->AsSurface()->GetWaterHeight() / COORDS_Z_STEP;
if (dl == waterHeight)
{
return;
}

al = dl;
cl = dl;
cornerHeight1 = dl;
cornerHeight2 = dl;
}
}

// al + cl probably are self tile corners, while ah/ch are neighbour tile corners
if (al <= ah && cl <= ch)
if (cornerHeight1 <= neighbourCornerHeight1 && cornerHeight2 <= neighbourCornerHeight2)
{
return;
}
Expand All @@ -827,53 +826,53 @@ static void viewport_surface_draw_tile_side_top(
{
if (!(session->ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE))
{
const uint8_t incline = (cl - al) + 1;
const uint8_t incline = (cornerHeight2 - cornerHeight1) + 1;
const uint32_t image_id = get_edge_image(terrain, 3) + (edge == EDGE_TOPLEFT ? 3 : 0) + incline; // var_c;
const int16_t y = (dl - al) * 16;
const int16_t y = (dl - cornerHeight1) * 16;
paint_attach_to_previous_ps(session, image_id, 0, y);
return;
}
base_image_id = get_edge_image(terrain, 1) + (edge == EDGE_TOPLEFT ? 5 : 0); // var_04
}

uint8_t cur_height = std::min(ch, ah);
if (ch != ah)
uint8_t cur_height = std::min(neighbourCornerHeight2, neighbourCornerHeight1);
if (neighbourCornerHeight2 != neighbourCornerHeight1)
{
// neighbour tile corners aren't level
uint32_t image_offset = 3;
if (ch > ah)
if (neighbourCornerHeight2 > neighbourCornerHeight1)
{
image_offset = 4;
}

if (cur_height != al && cur_height != cl)
if (cur_height != cornerHeight1 && cur_height != cornerHeight2)
{
const uint32_t image_id = base_image_id + image_offset;
sub_98196C(session, image_id, offset.x, offset.y, bounds.x, bounds.y, 15, cur_height * 16);
cur_height++;
}
}

ah = cl;
neighbourCornerHeight1 = cornerHeight2;

if (isWater)
{
offset.x = 0;
offset.y = 0;
}

while (cur_height < al && cur_height < ah)
while (cur_height < cornerHeight1 && cur_height < neighbourCornerHeight1)
{
sub_98196C(session, base_image_id, offset.x, offset.y, bounds.x, bounds.y, 15, cur_height * 16);
cur_height++;
}

uint32_t image_offset = 1;
if (cur_height >= al)
if (cur_height >= cornerHeight1)
{
image_offset = 2;

if (cur_height >= ah)
if (cur_height >= neighbourCornerHeight1)
{
return;
}
Expand Down Expand Up @@ -1161,7 +1160,7 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
// Water tool
if (tileElement->AsSurface()->GetWaterHeight() > 0)
{
int32_t waterHeight = tileElement->AsSurface()->GetWaterHeight() * 16;
int32_t waterHeight = tileElement->AsSurface()->GetWaterHeight();
if (waterHeight > height)
{
local_height += 16;
Expand Down Expand Up @@ -1264,7 +1263,7 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
session->InteractionType = VIEWPORT_INTERACTION_ITEM_WATER;

const uint16_t localHeight = height + 16;
const uint16_t waterHeight = tileElement->AsSurface()->GetWaterHeight() * 16;
const uint16_t waterHeight = tileElement->AsSurface()->GetWaterHeight();

if (!gTrackDesignSaveMode)
{
Expand Down
6 changes: 2 additions & 4 deletions src/openrct2/paint/tile_element/Paint.TileElement.cpp
Expand Up @@ -213,18 +213,16 @@ static void sub_68B3FB(paint_session* session, int32_t x, int32_t y)
uint16_t max_height = 0;
do
{
max_height = std::max(max_height, (uint16_t)element->clearance_height);
max_height = std::max(max_height, (uint16_t)element->GetClearanceZ());
} while (!(element++)->IsLastForTile());

element--;

if (element->GetType() == TILE_ELEMENT_TYPE_SURFACE && (element->AsSurface()->GetWaterHeight() > 0))
{
max_height = element->AsSurface()->GetWaterHeight() * 2;
max_height = element->AsSurface()->GetWaterHeight();
}

max_height *= 8;

#ifndef __TESTPAINT__
if (partOfVirtualFloor)
{
Expand Down
3 changes: 1 addition & 2 deletions src/openrct2/peep/Guest.cpp
Expand Up @@ -5412,9 +5412,8 @@ void Guest::UpdateWalking()
if (surfaceElement != nullptr)
{
int32_t water_height = surfaceElement->GetWaterHeight();
if (water_height)
if (water_height > 0)
{
water_height *= 16;
MoveTo(x, y, water_height);
SetState(PEEP_STATE_FALLING);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/peep/Peep.cpp
Expand Up @@ -926,7 +926,7 @@ void Peep::UpdateFalling()
// If the surface is water check to see if we could be drowning
if (tile_element->AsSurface()->GetWaterHeight() > 0)
{
int32_t height = tile_element->AsSurface()->GetWaterHeight() * 16;
int32_t height = tile_element->AsSurface()->GetWaterHeight();

if (height - 4 >= z && height < z + 20)
{
Expand Down Expand Up @@ -3157,7 +3157,7 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
}

int16_t water_height = surfaceElement->GetWaterHeight();
if (water_height)
if (water_height > 0)
{
peep_return_to_centre_of_tile(this);
return;
Expand Down

0 comments on commit d798811

Please sign in to comment.