From fdc1792932315c084036840c94bf779018355a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Br=C3=B6nneg=C3=A5rd?= <1162652+rasmusgo@users.noreply.github.com> Date: Mon, 7 Mar 2022 00:02:08 +0100 Subject: [PATCH] Let space() find points on the spaceship --- src/level/robotmain.cpp | 89 ++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 50 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 68ecee4f..89e72c68 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -4101,66 +4101,55 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject* } return min; } + +bool BlockedByObject(CObjectManager* objMan, Math::Vector center, float space, CObject* exclu) +{ + for (CObject* obj : objMan->GetAllObjects()) + { + if (!obj->GetDetectable()) continue; // inactive? + if (IsObjectBeingTransported(obj)) continue; + + if (obj == exclu) continue; + + for (const auto &crashSphere : obj->GetAllCrashSpheres()) + { + const Math::Vector oPos = crashSphere.sphere.pos; + const float oRadius = crashSphere.sphere.radius; + const float minDist = oRadius + space; + + if (Math::DistanceSquared(center, oPos) < minDist * minDist) + return true; + } + } + return false; +} } //! Calculates a free space bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadius, float space, CObject *exclu) { - if (minRadius < maxRadius) // from internal to external? + for (float radius = minRadius; radius <= maxRadius; radius += space) { - for (float radius = minRadius; radius <= maxRadius; radius += space) + float ia = space/radius; + for (float angle = 0.0f; angle < Math::PI*2.0f; angle += ia) { - float ia = space/radius; - for (float angle = 0.0f; angle < Math::PI*2.0f; angle += ia) + Math::Point p; + p.x = center.x+radius; + p.y = center.z; + p = Math::RotatePoint(Math::Point(center.x, center.z), angle, p); + Math::Vector pos; + pos.x = p.x; + pos.z = p.y; + pos.y = 0.0f; + m_terrain->AdjustToFloor(pos, true); + if (!BlockedByObject(m_objMan.get(), pos, space, exclu)) { - Math::Point p; - p.x = center.x+radius; - p.y = center.z; - p = Math::RotatePoint(Math::Point(center.x, center.z), angle, p); - Math::Vector pos; - pos.x = p.x; - pos.z = p.y; - pos.y = 0.0f; - m_terrain->AdjustToFloor(pos, true); - float dist = SearchNearestObject(m_objMan.get(), pos, exclu); - if (dist >= space) + float flat = m_terrain->GetFlatZoneRadius(pos, space); + if (flat >= space) { - float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f); - if (flat >= dist/2.0f) - { - center = pos; - return true; - } - } - } - } - } - else // from external to internal? - { - for (float radius=maxRadius; radius >= minRadius; radius -= space) - { - float ia = space/radius; - for (float angle=0.0f ; angleAdjustToFloor(pos, true); - float dist = SearchNearestObject(m_objMan.get(), pos, exclu); - if (dist >= space) - { - float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f); - if (flat >= dist/2.0f) - { - center = pos; - return true; - } + center = pos; + return true; } } }