0x00428237
| 3747 | |
| 3748 | // 0x00428237 |
| 3749 | static PathFindingResult waterPathfindToTarget(const World::TilePos2 tilePos, const MicroZ waterMicroZ, const World::TilePos2 targetOrderPos, const NearbyBoats& nearbyVehicles, uint8_t cost, const PathFindingResult& bestResult) |
| 3750 | { |
| 3751 | PathFindingResult result = bestResult; |
| 3752 | if (!validCoords(tilePos)) |
| 3753 | { |
| 3754 | return result; |
| 3755 | } |
| 3756 | auto tile = TileManager::get(tilePos); |
| 3757 | auto* elSurface = tile.surface(); |
| 3758 | if (elSurface->water() != waterMicroZ) |
| 3759 | { |
| 3760 | return result; |
| 3761 | } |
| 3762 | if (!elSurface->isLast()) |
| 3763 | { |
| 3764 | auto* elObsticle = elSurface->next(); |
| 3765 | if (elObsticle != nullptr && !elObsticle->isGhost() && !elObsticle->isAiAllocated()) |
| 3766 | { |
| 3767 | if (elObsticle->baseZ() / kMicroToSmallZStep - waterMicroZ < 1) |
| 3768 | { |
| 3769 | return result; |
| 3770 | } |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | const auto nearbyIndex = tilePos - nearbyVehicles.startTile; |
| 3775 | // Vanilla made a mistake here so we only check nearby tiles if in range |
| 3776 | // TODO: When we diverge just change the cost check to >= 6 or increase the search result to 18x18 |
| 3777 | if (nearbyIndex.x >= 0 && nearbyIndex.x < 16 && nearbyIndex.y >= 0 && nearbyIndex.y < 16) |
| 3778 | { |
| 3779 | if (nearbyVehicles.searchResult[nearbyIndex.x][nearbyIndex.y]) |
| 3780 | { |
| 3781 | return result; |
| 3782 | } |
| 3783 | } |
| 3784 | auto distToTarget = toWorldSpace(tilePos - targetOrderPos); |
| 3785 | distToTarget.x = std::abs(distToTarget.x); |
| 3786 | distToTarget.y = std::abs(distToTarget.y); |
| 3787 | // Lower is better |
| 3788 | const uint16_t score = std::max(distToTarget.x, distToTarget.y) + std::min(distToTarget.x, distToTarget.y) / 16; |
| 3789 | auto newResult = PathFindingResult{ score, cost }; |
| 3790 | result = std::min(result, newResult); |
| 3791 | if (score != 0) |
| 3792 | { |
| 3793 | if (cost >= 7) |
| 3794 | { |
| 3795 | return result; |
| 3796 | } |
| 3797 | cost++; |
| 3798 | for (auto i = 0U; i < 4; ++i) |
| 3799 | { |
| 3800 | result = waterPathfindToTarget(tilePos + toTileSpace(kRotationOffset[i]), waterMicroZ, targetOrderPos, nearbyVehicles, cost, result); |
| 3801 | } |
| 3802 | } |
| 3803 | return result; |
| 3804 | } |
| 3805 | |
| 3806 | // 0x00427FC9 |
no test coverage detected