1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Use CoordsXYZD on footpath_is_connected_to_map_edge_recurse()

This commit is contained in:
Tulio Leao
2020-01-04 09:17:01 -03:00
parent 6189d13b2c
commit 57da25cab9

View File

@@ -1285,24 +1285,23 @@ static bool get_next_direction(int32_t edges, int32_t* direction)
* (1 << 7): Ignore no entry signs * (1 << 7): Ignore no entry signs
*/ */
static int32_t footpath_is_connected_to_map_edge_recurse( static int32_t footpath_is_connected_to_map_edge_recurse(
int32_t x, int32_t y, int32_t z, int32_t direction, int32_t flags, int32_t level, int32_t distanceFromJunction, const CoordsXYZ& footpathPos, int32_t direction, int32_t flags, int32_t level, int32_t distanceFromJunction,
int32_t junctionTolerance) int32_t junctionTolerance)
{ {
TileElement* tileElement; TileElement* tileElement;
int32_t edges, slopeDirection; int32_t edges, slopeDirection;
x += CoordsDirectionDelta[direction].x; auto targetPos = CoordsXYZ{ CoordsXY{ footpathPos } + CoordsDirectionDelta[direction], footpathPos.z };
y += CoordsDirectionDelta[direction].y;
if (++level > 250) if (++level > 250)
return FOOTPATH_SEARCH_TOO_COMPLEX; return FOOTPATH_SEARCH_TOO_COMPLEX;
// Check if we are at edge of map // Check if we are at edge of map
if (x < 32 || y < 32) if (targetPos.x < COORDS_XY_STEP || targetPos.y < COORDS_XY_STEP)
return FOOTPATH_SEARCH_SUCCESS; return FOOTPATH_SEARCH_SUCCESS;
if (x >= gMapSizeUnits || y >= gMapSizeUnits) if (targetPos.x >= gMapSizeUnits || targetPos.y >= gMapSizeUnits)
return FOOTPATH_SEARCH_SUCCESS; return FOOTPATH_SEARCH_SUCCESS;
tileElement = map_get_first_element_at({ x, y }); tileElement = map_get_first_element_at(targetPos);
if (tileElement == nullptr) if (tileElement == nullptr)
return level == 1 ? FOOTPATH_SEARCH_NOT_FOUND : FOOTPATH_SEARCH_INCOMPLETE; return level == 1 ? FOOTPATH_SEARCH_NOT_FOUND : FOOTPATH_SEARCH_INCOMPLETE;
do do
@@ -1314,10 +1313,10 @@ static int32_t footpath_is_connected_to_map_edge_recurse(
{ {
if (direction_reverse(slopeDirection) != direction) if (direction_reverse(slopeDirection) != direction)
continue; continue;
if (tileElement->base_height + 2 != z) if (tileElement->GetBaseZ() + PATH_HEIGHT_STEP != targetPos.z)
continue; continue;
} }
else if (tileElement->base_height != z) else if (tileElement->GetBaseZ() != targetPos.z)
{ {
continue; continue;
} }
@@ -1332,7 +1331,7 @@ static int32_t footpath_is_connected_to_map_edge_recurse(
if (flags & (1 << 5)) if (flags & (1 << 5))
{ {
footpath_fix_ownership(x, y); footpath_fix_ownership(targetPos.x, targetPos.y);
} }
edges = tileElement->AsPath()->GetEdges(); edges = tileElement->AsPath()->GetEdges();
direction = direction_reverse(direction); direction = direction_reverse(direction);
@@ -1367,14 +1366,16 @@ static int32_t footpath_is_connected_to_map_edge_recurse(
searchFromFootpath: searchFromFootpath:
// Exclude direction we came from // Exclude direction we came from
z = tileElement->base_height; targetPos.z = tileElement->GetBaseZ();
edges &= ~(1 << direction); edges &= ~(1 << direction);
// Find next direction to go // Find next direction to go
if (!get_next_direction(edges, &direction)) int32_t newDirection{};
if (!get_next_direction(edges, &newDirection))
{ {
return FOOTPATH_SEARCH_INCOMPLETE; return FOOTPATH_SEARCH_INCOMPLETE;
} }
direction = newDirection;
edges &= ~(1 << direction); edges &= ~(1 << direction);
if (edges == 0) if (edges == 0)
@@ -1382,10 +1383,10 @@ searchFromFootpath:
// Only possible direction to go // Only possible direction to go
if (tileElement->AsPath()->IsSloped() && tileElement->AsPath()->GetSlopeDirection() == direction) if (tileElement->AsPath()->IsSloped() && tileElement->AsPath()->GetSlopeDirection() == direction)
{ {
z += 2; targetPos.z += PATH_HEIGHT_STEP;
} }
return footpath_is_connected_to_map_edge_recurse( return footpath_is_connected_to_map_edge_recurse(
x, y, z, direction, flags, level, distanceFromJunction + 1, junctionTolerance); targetPos, direction, flags, level, distanceFromJunction + 1, junctionTolerance);
} }
else else
{ {
@@ -1402,17 +1403,19 @@ searchFromFootpath:
do do
{ {
direction = newDirection;
edges &= ~(1 << direction); edges &= ~(1 << direction);
if (tileElement->AsPath()->IsSloped() && tileElement->AsPath()->GetSlopeDirection() == direction) if (tileElement->AsPath()->IsSloped() && tileElement->AsPath()->GetSlopeDirection() == direction)
{ {
z += 2; targetPos.z += PATH_HEIGHT_STEP;
} }
int32_t result = footpath_is_connected_to_map_edge_recurse(x, y, z, direction, flags, level, 0, junctionTolerance); int32_t result = footpath_is_connected_to_map_edge_recurse(
targetPos, direction, flags, level, 0, junctionTolerance);
if (result == FOOTPATH_SEARCH_SUCCESS) if (result == FOOTPATH_SEARCH_SUCCESS)
{ {
return result; return result;
} }
} while (get_next_direction(edges, &direction)); } while (get_next_direction(edges, &newDirection));
return FOOTPATH_SEARCH_INCOMPLETE; return FOOTPATH_SEARCH_INCOMPLETE;
} }
@@ -1422,8 +1425,7 @@ searchFromFootpath:
int32_t footpath_is_connected_to_map_edge(const CoordsXYZ& footpathPos, int32_t direction, int32_t flags) int32_t footpath_is_connected_to_map_edge(const CoordsXYZ& footpathPos, int32_t direction, int32_t flags)
{ {
flags |= (1 << 0); flags |= (1 << 0);
return footpath_is_connected_to_map_edge_recurse( return footpath_is_connected_to_map_edge_recurse(footpathPos, direction, flags, 0, 0, 16);
footpathPos.x, footpathPos.y, footpathPos.z / COORDS_Z_STEP, direction, flags, 0, 0, 16);
} }
bool PathElement::IsSloped() const bool PathElement::IsSloped() const