Make GetWaterHeight return big Z (#10579)

* Make GetWaterHeight return big Z

* Restore > 0 [ci skip]
This commit is contained in:
Michael Steenbeek 2020-01-19 16:12:48 +01:00 committed by Duncan
parent 8abb9e5515
commit d798811c4a
27 changed files with 80 additions and 96 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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)
@ -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);
}

View File

@ -321,7 +321,7 @@ private:
zCorner += 2;
}
}
if (zCorner > waterHeight * 2 - 2)
if (zCorner > (waterHeight / COORDS_Z_STEP) - 2)
{
return ++surfaceElement;
}
@ -381,8 +381,8 @@ private:
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);
}

View File

@ -189,7 +189,7 @@ public:
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);
@ -205,7 +205,7 @@ public:
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);
@ -227,7 +227,7 @@ public:
{
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);
}

View File

@ -315,7 +315,8 @@ public:
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);

View File

@ -166,7 +166,7 @@ public:
if (surfaceElement->GetWaterHeight() > 0)
{
uint16_t waterHeight = surfaceElement->GetWaterHeight() * 16;
uint16_t waterHeight = surfaceElement->GetWaterHeight();
if (targetHeight < waterHeight && !gCheatsDisableClearanceChecks)
{

View File

@ -82,11 +82,10 @@ private:
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;
@ -131,11 +130,10 @@ private:
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;

View File

@ -82,14 +82,13 @@ private:
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;
@ -141,7 +140,7 @@ private:
uint8_t height = surfaceElement->base_height;
if (surfaceElement->GetWaterHeight() > 0)
{
height = surfaceElement->GetWaterHeight() * 2;
height = surfaceElement->GetWaterHeight() / COORDS_Z_STEP;
}
if (maxHeight > height)

View File

@ -82,7 +82,7 @@ public:
int32_t zLow = _height;
if (surfaceElement->GetWaterHeight() > 0)
{
zHigh = surfaceElement->GetWaterHeight() * 2;
zHigh = surfaceElement->GetWaterHeight() / COORDS_Z_STEP;
}
if (zLow > zHigh)
{
@ -127,7 +127,7 @@ public:
if (_height > surfaceElement->base_height)
{
surfaceElement->SetWaterHeight(_height / 2);
surfaceElement->SetWaterHeight(_height * COORDS_Z_STEP);
}
else
{

View File

@ -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;

View File

@ -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
@ -749,7 +749,7 @@ 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 };
@ -757,22 +757,22 @@ static void viewport_surface_draw_tile_side_top(
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;
@ -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;
}
@ -827,26 +826,26 @@ 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);
@ -854,7 +853,7 @@ static void viewport_surface_draw_tile_side_top(
}
}
ah = cl;
neighbourCornerHeight1 = cornerHeight2;
if (isWater)
{
@ -862,18 +861,18 @@ static void viewport_surface_draw_tile_side_top(
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;
}
@ -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;
@ -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)
{

View File

@ -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)
{

View File

@ -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;

View File

@ -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)
{
@ -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;

View File

@ -1944,9 +1944,8 @@ void Staff::UpdatePatrolling()
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;

View File

@ -72,7 +72,7 @@ uint8_t RCT12SurfaceElement::GetOwnership() const
uint32_t RCT12SurfaceElement::GetWaterHeight() const
{
return terrain & TILE_ELEMENT_SURFACE_WATER_HEIGHT_MASK;
return (terrain & TILE_ELEMENT_SURFACE_WATER_HEIGHT_MASK) * 16;
}
uint8_t RCT12SurfaceElement::GetParkFences() const
@ -572,6 +572,7 @@ void RCT12SurfaceElement::SetEdgeStyle(uint32_t newStyle)
void RCT12SurfaceElement::SetWaterHeight(uint32_t newWaterHeight)
{
newWaterHeight >>= 4;
newWaterHeight &= 0x1F;
terrain &= ~TILE_ELEMENT_SURFACE_WATER_HEIGHT_MASK;
terrain |= newWaterHeight;

View File

@ -578,7 +578,7 @@ static void ride_ratings_score_close_proximity(TileElement* inputTileElement)
waterHeight = tileElement->AsSurface()->GetWaterHeight();
if (waterHeight != 0)
{
int32_t z = waterHeight * 16;
auto z = waterHeight;
if (z <= gRideRatingsCalcData.proximity_z)
{
proximity_score_increment(PROXIMITY_WATER_OVER);

View File

@ -1439,7 +1439,7 @@ static int32_t track_design_place_maze(TrackDesign* td6, int16_t x, int16_t y, i
}
}
int16_t waterZ = surfaceElement->GetWaterHeight() * 16;
int16_t waterZ = surfaceElement->GetWaterHeight();
if (waterZ > 0 && waterZ > surfaceZ)
{
surfaceZ = waterZ;
@ -1603,7 +1603,7 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1
}
}
uint8_t waterZ = surfaceElement->GetWaterHeight() * 16;
uint8_t waterZ = surfaceElement->GetWaterHeight();
if (waterZ > 0 && waterZ > surfaceZ)
{
surfaceZ = waterZ;

View File

@ -4659,7 +4659,7 @@ static bool vehicle_boat_is_location_accessible(const TileCoordsXYZ& location)
if (tileElement->GetType() == TILE_ELEMENT_TYPE_SURFACE)
{
int32_t waterZ = tileElement->AsSurface()->GetWaterHeight() * 2;
int32_t waterZ = tileElement->AsSurface()->GetWaterHeight() / COORDS_Z_STEP;
if (location.z != waterZ)
{
return false;

View File

@ -132,7 +132,6 @@ void rct_duck::UpdateFlyToWater()
}
else
{
waterHeight <<= 4;
int32_t newZ = abs(z - waterHeight);
if (manhattanDistanceN <= manhattanDistance)

View File

@ -562,9 +562,7 @@ int16_t tile_element_water_height(const CoordsXY& loc)
return 0;
}
uint16_t height = (surfaceElement->GetWaterHeight() << 4);
return height;
return surfaceElement->GetWaterHeight();
}
/**
@ -1308,7 +1306,7 @@ static GameActionResult::Ptr map_can_construct_with_clear_at(
}
continue;
}
water_height = tileElement->AsSurface()->GetWaterHeight() * 2 * 8;
water_height = tileElement->AsSurface()->GetWaterHeight();
if (water_height && water_height > pos.baseZ && tileElement->GetBaseZ() < pos.clearanceZ)
{
res->GroundFlags |= ELEMENT_IS_UNDERWATER;
@ -1755,21 +1753,19 @@ static void clear_elements_at(const CoordsXY& loc)
int32_t map_get_highest_z(const CoordsXY& loc)
{
uint32_t z;
auto surfaceElement = map_get_surface_element_at(loc);
if (surfaceElement == nullptr)
return -1;
z = surfaceElement->GetBaseZ();
auto z = surfaceElement->GetBaseZ();
// Raise z so that is above highest point of land and water on tile
if ((surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_ALL_CORNERS_UP) != TILE_ELEMENT_SLOPE_FLAT)
z += 16;
z += LAND_HEIGHT_STEP;
if ((surfaceElement->GetSlope() & TILE_ELEMENT_SLOPE_DOUBLE_HEIGHT) != 0)
z += 16;
z += LAND_HEIGHT_STEP;
z = std::max(z, surfaceElement->GetWaterHeight() * 16);
z = std::max(z, surfaceElement->GetWaterHeight());
return z;
}
@ -2098,9 +2094,7 @@ bool map_surface_is_blocked(CoordsXY mapCoords)
return true;
}
int16_t water_height = surfaceElement->GetWaterHeight();
water_height *= 2;
if (water_height > surfaceElement->base_height)
if (surfaceElement->GetWaterHeight() > surfaceElement->GetBaseZ())
return true;
int16_t base_z = surfaceElement->base_height;

View File

@ -401,7 +401,7 @@ static void mapgen_set_water_level(int32_t waterLevel)
{
auto surfaceElement = map_get_surface_element_at(TileCoordsXY{ x, y }.ToCoordsXY());
if (surfaceElement != nullptr && surfaceElement->base_height < waterLevel)
surfaceElement->SetWaterHeight(waterLevel / 2);
surfaceElement->SetWaterHeight(waterLevel * COORDS_Z_STEP);
}
}
}
@ -840,7 +840,7 @@ void mapgen_generate_from_heightmap(mapgen_settings* settings)
// Set water level
if (surfaceElement->base_height < settings->water_level)
{
surfaceElement->SetWaterHeight(settings->water_level / 2);
surfaceElement->SetWaterHeight(settings->water_level * COORDS_Z_STEP);
}
}
}

View File

@ -289,8 +289,7 @@ int32_t tile_smooth(int32_t x, int32_t y)
// All corners are raised, raise the entire tile instead.
surfaceElement->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
surfaceElement->base_height = (surfaceElement->clearance_height += 2);
uint8_t waterHeight = surfaceElement->GetWaterHeight() * 2;
if (waterHeight <= surfaceElement->base_height)
if (surfaceElement->GetWaterHeight() <= surfaceElement->GetBaseZ())
{
surfaceElement->SetWaterHeight(0);
}

View File

@ -36,14 +36,14 @@ void SurfaceElement::SetEdgeStyle(uint32_t newStyle)
EdgeStyle = newStyle;
}
uint32_t SurfaceElement::GetWaterHeight() const
int32_t SurfaceElement::GetWaterHeight() const
{
return WaterHeight;
return WaterHeight * 16;
}
void SurfaceElement::SetWaterHeight(uint32_t newWaterHeight)
void SurfaceElement::SetWaterHeight(int32_t newWaterHeight)
{
WaterHeight = newWaterHeight;
WaterHeight = newWaterHeight / 16;
}
bool SurfaceElement::CanGrassGrow() const
@ -109,8 +109,7 @@ void SurfaceElement::UpdateGrassLength(CoordsXY coords)
uint8_t grassLengthTmp = GrassLength & 7;
// Check if grass is underwater or outside park
uint32_t waterHeight = GetWaterHeight() * 2;
if (waterHeight > base_height || !map_is_location_in_park(coords))
if (GetWaterHeight() > GetBaseZ() || !map_is_location_in_park(coords))
{
if (grassLengthTmp != GRASS_LENGTH_CLEAR_0)
SetGrassLengthAndInvalidate(GRASS_LENGTH_CLEAR_0, coords);

View File

@ -168,8 +168,8 @@ public:
uint8_t GetOwnership() const;
void SetOwnership(uint8_t newOwnership);
uint32_t GetWaterHeight() const;
void SetWaterHeight(uint32_t newWaterHeight);
int32_t GetWaterHeight() const;
void SetWaterHeight(int32_t newWaterHeight);
uint8_t GetParkFences() const;
void SetParkFences(uint8_t newParkFences);

View File

@ -427,9 +427,9 @@ uint8_t SurfaceElement::GetSlope() const
return Slope;
}
uint32_t SurfaceElement::GetWaterHeight() const
int32_t SurfaceElement::GetWaterHeight() const
{
return WaterHeight;
return WaterHeight * 16;
}
bool TrackElement::IsHighlighted() const