From f3db7f877aaa3e6cfe362fca3299ea532c7ab09f Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 13 Aug 2019 19:25:39 +0100 Subject: [PATCH] Refactor tile_element_water_height to take CoordsXY --- src/openrct2/actions/SmallSceneryPlaceAction.hpp | 8 ++++---- src/openrct2/actions/WaterLowerAction.hpp | 2 +- src/openrct2/actions/WaterRaiseAction.hpp | 2 +- src/openrct2/ride/Vehicle.cpp | 2 +- src/openrct2/scenario/Scenario.cpp | 4 ++-- src/openrct2/world/Duck.cpp | 4 ++-- src/openrct2/world/Map.cpp | 10 +++------- src/openrct2/world/Map.h | 2 +- src/openrct2/world/Particle.cpp | 2 +- 9 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/openrct2/actions/SmallSceneryPlaceAction.hpp b/src/openrct2/actions/SmallSceneryPlaceAction.hpp index 6636d02e61..603aabd8c8 100644 --- a/src/openrct2/actions/SmallSceneryPlaceAction.hpp +++ b/src/openrct2/actions/SmallSceneryPlaceAction.hpp @@ -100,7 +100,7 @@ public: supportsRequired = true; } int32_t landHeight = tile_element_height({ _loc.x, _loc.y }); - int16_t waterHeight = tile_element_water_height(_loc.x, _loc.y); + int16_t waterHeight = tile_element_water_height({ _loc.x, _loc.y }); int32_t surfaceHeight = landHeight; // If on water @@ -160,7 +160,7 @@ public: y2 += ScenerySubTileOffsets[quadrant & 3].y - 1; } landHeight = tile_element_height({ x2, y2 }); - waterHeight = tile_element_water_height(x2, y2); + waterHeight = tile_element_water_height({ x2, y2 }); surfaceHeight = landHeight; // If on water @@ -303,7 +303,7 @@ public: supportsRequired = true; } int32_t landHeight = tile_element_height({ _loc.x, _loc.y }); - int16_t waterHeight = tile_element_water_height(_loc.x, _loc.y); + int16_t waterHeight = tile_element_water_height({ _loc.x, _loc.y }); int32_t surfaceHeight = landHeight; // If on water @@ -353,7 +353,7 @@ public: y2 += ScenerySubTileOffsets[quadrant & 3].y - 1; } landHeight = tile_element_height({ x2, y2 }); - waterHeight = tile_element_water_height(x2, y2); + waterHeight = tile_element_water_height({ x2, y2 }); surfaceHeight = landHeight; // If on water diff --git a/src/openrct2/actions/WaterLowerAction.hpp b/src/openrct2/actions/WaterLowerAction.hpp index f05d397f04..862c9fd6a7 100644 --- a/src/openrct2/actions/WaterLowerAction.hpp +++ b/src/openrct2/actions/WaterLowerAction.hpp @@ -64,7 +64,7 @@ private: res->Position.x = ((validRange.GetLeft() + validRange.GetRight()) / 2) + 16; res->Position.y = ((validRange.GetTop() + validRange.GetBottom()) / 2) + 16; int16_t z = tile_element_height({ res->Position.x, res->Position.y }); - int16_t waterHeight = tile_element_water_height(res->Position.x, res->Position.y); + int16_t waterHeight = tile_element_water_height({ res->Position.x, res->Position.y }); if (waterHeight != 0) { z = waterHeight; diff --git a/src/openrct2/actions/WaterRaiseAction.hpp b/src/openrct2/actions/WaterRaiseAction.hpp index ec57c53410..7a640821eb 100644 --- a/src/openrct2/actions/WaterRaiseAction.hpp +++ b/src/openrct2/actions/WaterRaiseAction.hpp @@ -65,7 +65,7 @@ private: res->Position.x = ((validRange.GetLeft() + validRange.GetRight()) / 2) + 16; res->Position.y = ((validRange.GetTop() + validRange.GetBottom()) / 2) + 16; int32_t z = tile_element_height({ res->Position.x, res->Position.y }); - int16_t waterHeight = tile_element_water_height(res->Position.x, res->Position.y); + int16_t waterHeight = tile_element_water_height({ res->Position.x, res->Position.y }); if (waterHeight != 0) { z = waterHeight; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index b97d283aee..b8a94a9579 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5432,7 +5432,7 @@ static void vehicle_update_crash(rct_vehicle* vehicle) } int16_t z = tile_element_height({ curVehicle->x, curVehicle->y }); - int16_t waterHeight = tile_element_water_height(curVehicle->x, curVehicle->y); + int16_t waterHeight = tile_element_water_height({ curVehicle->x, curVehicle->y }); int16_t zDiff; if (waterHeight != 0) { diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 92c5ef1d23..96f229f61b 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -433,7 +433,7 @@ static int32_t scenario_create_ducks() if (!map_is_location_in_park({ x, y })) return 0; - centreWaterZ = (tile_element_water_height(x, y)); + centreWaterZ = (tile_element_water_height({ x, y })); if (centreWaterZ == 0) return 0; @@ -445,7 +445,7 @@ static int32_t scenario_create_ducks() { for (j = 0; j < 7; j++) { - waterZ = (tile_element_water_height(x2, y2)); + waterZ = (tile_element_water_height({ x2, y2 })); if (waterZ == centreWaterZ) c++; diff --git a/src/openrct2/world/Duck.cpp b/src/openrct2/world/Duck.cpp index 01753c9536..86c663ceff 100644 --- a/src/openrct2/world/Duck.cpp +++ b/src/openrct2/world/Duck.cpp @@ -202,7 +202,7 @@ void rct_duck::UpdateSwim() { Invalidate(); int16_t landZ = tile_element_height({ x, y }); - int16_t waterZ = tile_element_water_height(x, y); + int16_t waterZ = tile_element_water_height({ x, y }); if (z < landZ || waterZ == 0) { @@ -223,7 +223,7 @@ void rct_duck::UpdateSwim() int32_t newX = x + DuckMoveOffset[direction].x; int32_t newY = y + DuckMoveOffset[direction].y; landZ = tile_element_height({ newX, newY }); - waterZ = tile_element_water_height(newX, newY); + waterZ = tile_element_water_height({ newX, newY }); if (z >= landZ && z == waterZ) { diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index c88cef2cbe..5dd5b6116e 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -607,18 +607,14 @@ int16_t tile_element_height(const CoordsXY loc) return height; } -int16_t tile_element_water_height(int32_t x, int32_t y) +int16_t tile_element_water_height(const CoordsXY loc) { // Off the map - if ((unsigned)x >= 8192 || (unsigned)y >= 8192) + if ((unsigned)loc.x >= 8192 || (unsigned)loc.y >= 8192) return 0; - // Truncate subtile coordinates - int32_t x_tile = x & 0xFFFFFFE0; - int32_t y_tile = y & 0xFFFFFFE0; - // Get the surface element for the tile - auto surfaceElement = map_get_surface_element_at({ x_tile, y_tile }); + auto surfaceElement = map_get_surface_element_at(loc); if (surfaceElement == nullptr) { diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 62d0cf0098..bb56d07ca9 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -152,7 +152,7 @@ EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost); EntranceElement* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost); int16_t tile_element_height(const CoordsXY loc); -int16_t tile_element_water_height(int32_t x, int32_t y); +int16_t tile_element_water_height(const CoordsXY loc); uint8_t map_get_highest_land_height(int32_t xMin, int32_t xMax, int32_t yMin, int32_t yMax); uint8_t map_get_lowest_land_height(int32_t xMin, int32_t xMax, int32_t yMin, int32_t yMax); bool map_coord_is_connected(const TileCoordsXYZ loc, uint8_t faceDirection); diff --git a/src/openrct2/world/Particle.cpp b/src/openrct2/world/Particle.cpp index ae8145aa28..c1eab4af37 100644 --- a/src/openrct2/world/Particle.cpp +++ b/src/openrct2/world/Particle.cpp @@ -81,7 +81,7 @@ void crashed_vehicle_particle_update(rct_crashed_vehicle_particle* particle) // Check collision with land / water int16_t landZ = tile_element_height({ x, y }); - int16_t waterZ = tile_element_water_height(x, y); + int16_t waterZ = tile_element_water_height({ x, y }); if (waterZ != 0 && particle->z >= waterZ && z <= waterZ) {