//alter position based on altitude
        private void HoverMechanic(ref Vector3D pos)
        {
            m_hoverMin = 5;
            m_hoverMax = 25;

            Vector3 gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(pos);

            if (gravity.LengthSquared() > 0f)
            {
                MyPlanet planet = MyGamePruningStructure.GetClosestPlanet(pos);
                if (planet != null)
                {
                    Vector3D closestPoint = planet.GetClosestSurfacePointGlobal(ref pos);
                    float    altitude     = (float)Vector3D.Distance(closestPoint, pos);
                    if (Vector3D.DistanceSquared(planet.PositionComp.GetPosition(), closestPoint) > Vector3D.DistanceSquared(planet.PositionComp.GetPosition(), pos))
                    {
                        altitude *= -1;
                    }
                    if (altitude < m_hoverMin)
                    {
                        pos = closestPoint - Vector3D.Normalize(gravity) * m_hoverMin;
                    }
                    else if (altitude > m_hoverMax)
                    {
                        pos = closestPoint - Vector3D.Normalize(gravity) * m_hoverMax;
                    }
                }
            }
        }
Exemple #2
0
        public void RequestJump(string destinationName, Vector3D destination, long userId)
        {
            if (!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_grid.WorldMatrix.Translation)))
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpFromGravity, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }
            if (!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(destination)))
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpIntoGravity, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }

            if (!IsJumpValid(userId))
            {
                return;
            }

            m_selectedDestination = destination;
            double maxJumpDistance = GetMaxJumpDistance(userId);

            m_jumpDirection = destination - m_grid.WorldMatrix.Translation;
            double jumpDistance   = m_jumpDirection.Length();
            double actualDistance = jumpDistance;

            if (jumpDistance > maxJumpDistance)
            {
                double ratio = maxJumpDistance / jumpDistance;
                actualDistance   = maxJumpDistance;
                m_jumpDirection *= ratio;
            }

            if (actualDistance < MIN_JUMP_DISTANCE)
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType: MyMessageBoxButtonsType.OK,
                                           messageText: GetWarningText(actualDistance),
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWarning)
                                           ));
            }
            else
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType : MyMessageBoxButtonsType.YES_NO,
                                           messageText : GetConfimationText(destinationName, jumpDistance, actualDistance, userId),
                                           messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                                           size : new Vector2(0.839375f, 0.3675f), callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                {
                    if (result == MyGuiScreenMessageBox.ResultEnum.YES && IsJumpValid(userId))
                    {
                        SyncObject.RequestJump(m_selectedDestination, userId);
                    }
                    else
                    {
                        AbortJump();
                    }
                }
                                           ));
            }
        }
Exemple #3
0
        public void RequestJump(string destinationName, Vector3D destination, long userId)
        {
            if (!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_grid.WorldMatrix.Translation)))
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpFromGravity, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }
            if (!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(destination)))
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpIntoGravity, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }

            if (!IsJumpValid(userId))
            {
                return;
            }

            if (MySession.Static.Settings.WorldSizeKm > 0 && destination.Length() > MySession.Static.Settings.WorldSizeKm * 500)
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpOutsideWorld, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }

            m_selectedDestination = destination;
            double maxJumpDistance = GetMaxJumpDistance(userId);

            m_jumpDirection = destination - m_grid.WorldMatrix.Translation;
            double jumpDistance   = m_jumpDirection.Length();
            double actualDistance = jumpDistance;

            if (jumpDistance > maxJumpDistance)
            {
                double ratio = maxJumpDistance / jumpDistance;
                actualDistance   = maxJumpDistance;
                m_jumpDirection *= ratio;
            }

            //By Gregory: Check for obstacle not that fast but happens rarely(on Jump drive enable)
            //TODO: make compatible with GetMaxJumpDistance and refactor to much code checks for actual jump
            var direction = Vector3D.Normalize(destination - m_grid.WorldMatrix.Translation);
            var startPos  = m_grid.WorldMatrix.Translation + m_grid.PositionComp.LocalAABB.Extents.Max() * direction;
            var line      = new LineD(startPos, destination);


            var intersection = MyEntities.GetIntersectionWithLine(ref line, m_grid, null, ignoreObjectsWithoutPhysics: false);

            Vector3D newDestination = Vector3D.Zero;
            Vector3D newDirection   = Vector3D.Zero;

            if (intersection.HasValue)
            {
                MyEntity MyEntity = intersection.Value.Entity as MyEntity;

                var targetPos     = MyEntity.WorldMatrix.Translation;
                var obstaclePoint = MyUtils.GetClosestPointOnLine(ref startPos, ref destination, ref targetPos);

                MyPlanet MyEntityPlanet = intersection.Value.Entity as MyPlanet;
                if (MyEntityPlanet != null)
                {
                    var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpIntoGravity, 1500);
                    MyHud.Notifications.Add(notification);
                    return;
                }

                //var Radius = MyEntityPlanet != null ? MyEntityPlanet.MaximumRadius : MyEntity.PositionComp.LocalAABB.Extents.Length();
                var Radius = MyEntity.PositionComp.LocalAABB.Extents.Length();

                destination           = obstaclePoint - direction * (Radius + m_grid.PositionComp.LocalAABB.HalfExtents.Length());
                m_selectedDestination = destination;
                m_jumpDirection       = m_selectedDestination - startPos;
                actualDistance        = m_jumpDirection.Length();
            }

            if (actualDistance < MIN_JUMP_DISTANCE)
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType: MyMessageBoxButtonsType.OK,
                                           messageText: GetWarningText(actualDistance, intersection.HasValue),
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWarning)
                                           ));
            }
            else
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType : MyMessageBoxButtonsType.YES_NO,
                                           messageText : GetConfimationText(destinationName, jumpDistance, actualDistance, userId, intersection.HasValue),
                                           messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                                           size : new Vector2(0.839375f, 0.3675f), callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                {
                    if (result == MyGuiScreenMessageBox.ResultEnum.YES && IsJumpValid(userId))
                    {
                        RequestJump(m_selectedDestination, userId);
                    }
                    else
                    {
                        AbortJump();
                    }
                }
                                           ));
            }
        }