diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyRemoteControl.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyRemoteControl.cs index 4c59fef2a..c630a9fbf 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyRemoteControl.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyRemoteControl.cs @@ -18,5 +18,9 @@ public interface IMyRemoteControl : IMyShipController // CH: TODO: Uncomment later for drones Vector3D GetFreeDestination(Vector3D originalDestination, float checkRadius, float shipRadius); + + float GetDistanceToSeaLevel(); + Vector3D GetNearestCenter(); + bool HasPlanetNearby(); } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyRemoteControl.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyRemoteControl.cs index da94377c1..b9ae86e49 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyRemoteControl.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyRemoteControl.cs @@ -2028,6 +2028,57 @@ Vector3D IMyRemoteControl.GetFreeDestination(Vector3D originalDestination, float return retval; } + + float IMyRemoteControl.GetDistanceToSeaLevel() { + + var controlledEntity = MySession.Static.ControlledEntity as MyCubeBlock; + var controlledEntityPosition = controlledEntity.CubeGrid.Physics.CenterOfMassWorld; + + MyPlanet nearestPlanet; + FindDistanceToNearestPlanetSeaLevel(controlledEntityPosition, out nearestPlanet); + if (nearestPlanet == null) + return -1; + + Vector3D closestPoint = nearestPlanet.GetClosestSurfacePointGlobal(ref controlledEntityPosition); + float distanceToSeaLevel = (float)Vector3D.Distance(closestPoint, controlledEntityPosition); + return distanceToSeaLevel; + } + + Vector3D IMyRemoteControl.GetNearestCenter() { + var controlledEntity = MySession.Static.ControlledEntity as MyCubeBlock; + var controlledEntityPosition = controlledEntity.CubeGrid.Physics.CenterOfMassWorld; + + MyPlanet nearestPlanet = MyGravityProviderSystem.GetNearestPlanet(controlledEntityPosition); + if (nearestPlanet == null) + return Vector3D.Zero; + else + return nearestPlanet.PositionComp.GetPosition(); + } + + bool IMyRemoteControl.HasPlanetNearby() { + + var controlledEntity = MySession.Static.ControlledEntity as MyCubeBlock; + var controlledEntityPosition = controlledEntity.CubeGrid.Physics.CenterOfMassWorld; + + MyPlanet nearestPlanet = MyGravityProviderSystem.GetNearestPlanet(controlledEntityPosition); + if (nearestPlanet == null) + return false; + else + return true; + } + + private float FindDistanceToNearestPlanetSeaLevel(Vector3D worldPoint, out MyPlanet closestPlanet) { + ProfilerShort.Begin("FindNearestPointOnPlanet"); + closestPlanet = MyGravityProviderSystem.GetNearestPlanet(worldPoint); + double closestDistance = double.MaxValue; + if (closestPlanet != null) { + closestDistance = ((worldPoint - closestPlanet.PositionComp.GetPosition()).Length() - closestPlanet.AverageRadius); + } + ProfilerShort.End(); + + return (float)closestDistance; + } + #endregion private bool TryFindSavedEntity()