diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index c2ab41847d..ccd8d758a4 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -2262,34 +2262,28 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) pathList[7] = footpath_can_be_wide(x, y, height); y += 0x20; - uint8_t F3EFA5 = 0; + uint8_t pathConnections = 0; if (tileElement->AsPath()->GetEdges() & EDGE_NW) { - F3EFA5 |= 0x80; - if (pathList[7] != nullptr) + pathConnections |= FOOTPATH_CONNECTION_NW; + if (pathList[7] != nullptr && pathList[7]->AsPath()->IsWide()) { - if ((pathList[7])->AsPath()->IsWide()) - { - F3EFA5 &= ~0x80; - } + pathConnections &= ~FOOTPATH_CONNECTION_NW; } } if (tileElement->AsPath()->GetEdges() & EDGE_NE) { - F3EFA5 |= 0x2; - if (pathList[1] != nullptr) + pathConnections |= FOOTPATH_CONNECTION_NE; + if (pathList[1] != nullptr && pathList[1]->AsPath()->IsWide()) { - if ((pathList[1])->AsPath()->IsWide()) - { - F3EFA5 &= ~0x2; - } + pathConnections &= ~FOOTPATH_CONNECTION_NE; } } if (tileElement->AsPath()->GetEdges() & EDGE_SE) { - F3EFA5 |= 0x8; + pathConnections |= FOOTPATH_CONNECTION_SE; /* In the following: * footpath_element_is_wide(pathList[3]) * is always false due to the tile update order @@ -2297,14 +2291,14 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) * Commented out since it will never occur. */ // if (pathList[3] != nullptr) { // if (footpath_element_is_wide(pathList[3])) { - // F3EFA5 &= ~0x8; + // pathConnections &= ~FOOTPATH_CONNECTION_SE; // } //} } if (tileElement->AsPath()->GetEdges() & EDGE_SW) { - F3EFA5 |= 0x20; + pathConnections |= FOOTPATH_CONNECTION_SW; /* In the following: * footpath_element_is_wide(pathList[5]) * is always false due to the tile update order @@ -2312,18 +2306,19 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) * Commented out since it will never occur. */ // if (pathList[5] != nullptr) { // if (footpath_element_is_wide(pathList[5])) { - // F3EFA5 &= ~0x20; + // pathConnections &= ~FOOTPATH_CONNECTION_SW; // } //} } - if ((F3EFA5 & 0x80) && (pathList[7] != nullptr) && !(pathList[7])->AsPath()->IsWide()) + if ((pathConnections & FOOTPATH_CONNECTION_NW) && pathList[7] != nullptr && !pathList[7]->AsPath()->IsWide()) { - if ((F3EFA5 & 2) && (pathList[0] != nullptr) && !(pathList[0])->AsPath()->IsWide() - && ((pathList[0]->AsPath()->GetEdges() & 6) == 6) && // N E - (pathList[1] != nullptr) && !(pathList[1])->AsPath()->IsWide()) + constexpr uint8_t edgeMask1 = EDGE_SE | EDGE_SW; + if ((pathConnections & FOOTPATH_CONNECTION_NE) && pathList[0] != nullptr && !pathList[0]->AsPath()->IsWide() + && (pathList[0]->AsPath()->GetEdges() & edgeMask1) == edgeMask1 && pathList[1] != nullptr + && !pathList[1]->AsPath()->IsWide()) { - F3EFA5 |= 0x1; + pathConnections |= FOOTPATH_CONNECTION_S; } /* In the following: @@ -2331,11 +2326,12 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) * is always false due to the tile update order * in combination with reset tiles. * Short circuit the logic appropriately. */ - if ((F3EFA5 & 0x20) && (pathList[6] != nullptr) && !(pathList[6])->AsPath()->IsWide() - && ((pathList[6]->AsPath()->GetEdges() & 3) == 3) && // N W - (pathList[5] != nullptr) && (true || !(pathList[5])->AsPath()->IsWide())) + constexpr uint8_t edgeMask2 = EDGE_NE | EDGE_SE; + if ((pathConnections & FOOTPATH_CONNECTION_SW) && pathList[6] != nullptr && !pathList[6]->AsPath()->IsWide() + && (pathList[6]->AsPath()->GetEdges() & edgeMask2) == edgeMask2 && pathList[5] != nullptr + && !(pathList[5])->AsPath()->IsWide()) { - F3EFA5 |= 0x40; + pathConnections |= FOOTPATH_CONNECTION_E; } } @@ -2345,13 +2341,14 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) * are always false due to the tile update order * in combination with reset tiles. * Short circuit the logic appropriately. */ - if ((F3EFA5 & 0x8) && (pathList[3] != nullptr) && (true || !(pathList[3])->AsPath()->IsWide())) + if ((pathConnections & FOOTPATH_CONNECTION_SE) && pathList[3] != nullptr && !pathList[3]->AsPath()->IsWide()) { - if ((F3EFA5 & 2) && (pathList[2] != nullptr) && (true || !(pathList[2])->AsPath()->IsWide()) - && ((pathList[2]->AsPath()->GetEdges() & 0xC) == 0xC) && (pathList[1] != nullptr) - && (!(pathList[1])->AsPath()->IsWide())) + constexpr uint8_t edgeMask1 = EDGE_SW | EDGE_NW; + if ((pathConnections & FOOTPATH_CONNECTION_NE) && (pathList[2] != nullptr) && !pathList[2]->AsPath()->IsWide() + && (pathList[2]->AsPath()->GetEdges() & edgeMask1) == edgeMask1 && pathList[1] != nullptr + && !pathList[1]->AsPath()->IsWide()) { - F3EFA5 |= 0x4; + pathConnections |= FOOTPATH_CONNECTION_W; } /* In the following: @@ -2360,27 +2357,37 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y) * are always false due to the tile update order * in combination with reset tiles. * Short circuit the logic appropriately. */ - if ((F3EFA5 & 0x20) && (pathList[4] != nullptr) && (true || !(pathList[4])->AsPath()->IsWide()) - && ((pathList[4]->AsPath()->GetEdges() & 9) == 9) && (pathList[5] != nullptr) - && (true || !(pathList[5])->AsPath()->IsWide())) + constexpr uint8_t edgeMask2 = EDGE_NE | EDGE_NW; + if ((pathConnections & FOOTPATH_CONNECTION_SW) && pathList[4] != nullptr && !pathList[4]->AsPath()->IsWide() + && (pathList[4]->AsPath()->GetEdges() & edgeMask2) == edgeMask2 && pathList[5] != nullptr + && !pathList[5]->AsPath()->IsWide()) { - F3EFA5 |= 0x10; + pathConnections |= FOOTPATH_CONNECTION_N; } } - if ((F3EFA5 & 0x80) && (F3EFA5 & (0x40 | 0x1))) - F3EFA5 &= ~0x80; + if ((pathConnections & FOOTPATH_CONNECTION_NW) && (pathConnections & (FOOTPATH_CONNECTION_E | FOOTPATH_CONNECTION_S))) + { + pathConnections &= ~FOOTPATH_CONNECTION_NW; + } - if ((F3EFA5 & 0x2) && (F3EFA5 & (0x4 | 0x1))) - F3EFA5 &= ~0x2; + if ((pathConnections & FOOTPATH_CONNECTION_NE) && (pathConnections & (FOOTPATH_CONNECTION_W | FOOTPATH_CONNECTION_S))) + { + pathConnections &= ~FOOTPATH_CONNECTION_NE; + } - if ((F3EFA5 & 0x8) && (F3EFA5 & (0x10 | 0x4))) - F3EFA5 &= ~0x8; + if ((pathConnections & FOOTPATH_CONNECTION_SE) && (pathConnections & (FOOTPATH_CONNECTION_N | FOOTPATH_CONNECTION_W))) + { + pathConnections &= ~FOOTPATH_CONNECTION_SE; + } - if ((F3EFA5 & 0x20) && (F3EFA5 & (0x40 | 0x10))) - F3EFA5 &= ~0x20; + if ((pathConnections & FOOTPATH_CONNECTION_SW) && (pathConnections & (FOOTPATH_CONNECTION_E | FOOTPATH_CONNECTION_N))) + { + pathConnections &= ~FOOTPATH_CONNECTION_SW; + } - if (!(F3EFA5 & (0x2 | 0x8 | 0x20 | 0x80))) + if (!(pathConnections + & (FOOTPATH_CONNECTION_NE | FOOTPATH_CONNECTION_SE | FOOTPATH_CONNECTION_SW | FOOTPATH_CONNECTION_NW))) { uint8_t e = tileElement->AsPath()->GetEdgesAndCorners(); if ((e != 0b10101111) && (e != 0b01011111) && (e != 0b11101111)) diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 2c14ba4f20..9e209bc25d 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -139,6 +139,18 @@ enum FOOTPATH_CORNER_3 = (1 << 3), }; +enum +{ + FOOTPATH_CONNECTION_S = (1 << 0), + FOOTPATH_CONNECTION_NE = (1 << 1), + FOOTPATH_CONNECTION_W = (1 << 2), + FOOTPATH_CONNECTION_SE = (1 << 3), + FOOTPATH_CONNECTION_N = (1 << 4), + FOOTPATH_CONNECTION_SW = (1 << 5), + FOOTPATH_CONNECTION_E = (1 << 6), + FOOTPATH_CONNECTION_NW = (1 << 7), +}; + extern uint8_t gFootpathProvisionalFlags; extern LocationXYZ16 gFootpathProvisionalPosition; extern uint8_t gFootpathProvisionalType;