public static bool CanConnectHooks(long hookIdFrom, long hookIdTo, MyRopeDefinition ropeDefinition)
        {
            bool result = true;
            RopeDrumLimits limitsA, limitsB;
            m_hookIdToRopeLimits.TryGetValue(hookIdFrom, out limitsA);
            m_hookIdToRopeLimits.TryGetValue(hookIdTo, out limitsB);
            if (limitsA != null && limitsB != null)
            {
                result = false;
            }
            else if (limitsA != null || limitsB != null)
            {
                var from = MyEntities.GetEntityById(hookIdFrom);
                var to = MyEntities.GetEntityById(hookIdTo);
                var distanceSqr = (to.PositionComp.GetPosition() - from.PositionComp.GetPosition()).LengthSquared();
                if (limitsA != null) result = result && (distanceSqr < (limitsA.MaxLength * limitsA.MaxLength));
                if (limitsB != null) result = result && (distanceSqr < (limitsB.MaxLength * limitsB.MaxLength));
            }

            return result;
        }
 public MyRopeAttacher(MyRopeDefinition ropeDefinition)
 {
     m_ropeDefinition = ropeDefinition;
     m_selectedHook_OnClosing = delegate(MyEntity entity)
     {
         Debug.Assert(m_hookIdFrom == entity.EntityId);
         m_hookIdFrom = 0;
     };
 }
        public static long AddRopeData(long hookEntityIdA, long hookEntityIdB, MyRopeDefinition ropeDefinition, long ropeId)
        {
            MyEntity entityA, entityB;
            if (!MyEntities.TryGetEntityById(hookEntityIdA, out entityA))
                return 0;

            if (!MyEntities.TryGetEntityById(hookEntityIdB, out entityB))
                return 0;

            var hookA = m_hookIdToHook[hookEntityIdA];
            var hookB = m_hookIdToHook[hookEntityIdB];
            var posA = Vector3D.Transform(hookA.LocalPivot, entityA.WorldMatrix);
            var posB = Vector3D.Transform(hookB.LocalPivot, entityB.WorldMatrix);
            var maxRopeLength = (float)(posA - posB).Length();
            var ropeData = new MyRopeData
            {
                HookEntityIdA = hookEntityIdA,
                HookEntityIdB = hookEntityIdB,
                MaxRopeLength = maxRopeLength,
                CurrentRopeLength = maxRopeLength,
                Definition = ropeDefinition,
            };
            return AddRopeData(ropeData, ropeId);
        }
        private static void ActivateWinding(long hookEntityId, WindingData winding, MyRopeDefinition attachedRope)
        {
            Debug.Assert(winding != null);
            Debug.Assert(!m_hookIdToActiveWinding.ContainsKey(hookEntityId), "Winding already added");
            Debug.Assert(m_hookIdToRopeId.ContainsKey(hookEntityId));

            m_hookIdToActiveWinding[hookEntityId] = winding;
            var hookEntity = MyEntities.GetEntityById(hookEntityId);
            UpdateDummyWorld(hookEntity.PositionComp, winding);
            if (attachedRope.WindingSound != null)
            {
                winding.Sound = attachedRope.WindingSound;
                winding.Emitter = new MyEntity3DSoundEmitter(hookEntity);
            }
        }