| 3846 | //--------------------------------------------------------------------------- |
| 3847 | |
| 3848 | int GetOverlapSector(const DVector2& pos, sectortype** over, sectortype** under) |
| 3849 | { |
| 3850 | int i, found = 0; |
| 3851 | sectortype* sf[3]= {nullptr,nullptr}; // sectors found |
| 3852 | auto secto = *over; |
| 3853 | auto sectu = *under; |
| 3854 | |
| 3855 | if ((sectu->hasU() && sectu->number >= 30000) || (secto->hasU() && secto->number >= 30000)) |
| 3856 | return GetOverlapSector2(pos, over, under); |
| 3857 | |
| 3858 | // instead of check ALL sectors, just check the two most likely first |
| 3859 | if (inside(pos.X, pos.Y, *over)) |
| 3860 | { |
| 3861 | sf[found] = *over; |
| 3862 | found++; |
| 3863 | } |
| 3864 | |
| 3865 | if (inside(pos.X, pos.Y, *under)) |
| 3866 | { |
| 3867 | sf[found] = *under; |
| 3868 | found++; |
| 3869 | } |
| 3870 | |
| 3871 | // if nothing was found, check them all |
| 3872 | if (found == 0) |
| 3873 | { |
| 3874 | for (auto& sect: sector) |
| 3875 | { |
| 3876 | if (inside(pos.X, pos.Y, §)) |
| 3877 | { |
| 3878 | sf[found] = § |
| 3879 | found++; |
| 3880 | if (found > 2) return 0; |
| 3881 | } |
| 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | if (!found) |
| 3886 | { |
| 3887 | // Contrary to expectations, this *CAN* happen in valid scenarios and therefore should not abort. |
| 3888 | return 0; |
| 3889 | } |
| 3890 | |
| 3891 | PRODUCTION_ASSERT(found <= 2); |
| 3892 | |
| 3893 | // the are overlaping - check the z coord |
| 3894 | if (found == 2) |
| 3895 | { |
| 3896 | if (sf[0]->floorz > sf[1]->floorz) |
| 3897 | { |
| 3898 | *under = sf[0]; |
| 3899 | *over = sf[1]; |
| 3900 | } |
| 3901 | else |
| 3902 | { |
| 3903 | *under = sf[1]; |
| 3904 | *over = sf[0]; |
| 3905 | } |
no test coverage detected