bool IMyShipController.TryGetPlanetElevation(MyPlanetElevation detail, out double elevation)
        {
            var blockPosition = this.PositionComp.GetPosition();

            if (!MyGravityProviderSystem.IsPositionInNaturalGravity(blockPosition))
            {
                elevation = double.PositiveInfinity;
                return(false);
            }
            var boundingBox   = PositionComp.WorldAABB;
            var nearestPlanet = MyGamePruningStructure.GetClosestPlanet(ref boundingBox);

            if (nearestPlanet == null)
            {
                elevation = double.PositiveInfinity;
                return(false);
            }

            switch (detail)
            {
            case MyPlanetElevation.Sealevel:
                elevation = ((boundingBox.Center - nearestPlanet.PositionComp.GetPosition()).Length() - nearestPlanet.AverageRadius);
                return(true);

            case MyPlanetElevation.Surface:
                var      controlledEntityPosition = CubeGrid.Physics.CenterOfMassWorld;
                Vector3D closestPoint             = nearestPlanet.GetClosestSurfacePointGlobal(ref controlledEntityPosition);
                elevation = Vector3D.Distance(closestPoint, controlledEntityPosition);
                return(true);

            default:
                throw new ArgumentOutOfRangeException("detail", detail, null);
            }
        }
Esempio n. 2
0
            public override void UpdateBeforeSimulation100()
            {
                base.UpdateBeforeSimulation100();
                if (m_particleVectorUp == Vector3.Zero)
                {
                    if (Entity.Physics.LinearVelocity != Vector3.Zero)
                    {
                        m_particleVectorUp = -Vector3.Normalize(Entity.Physics.LinearVelocity);
                    }
                    else
                    {
                        m_particleVectorUp = Vector3.Up;
                    }
                    m_particleVectorUp.CalculatePerpendicularVector(out m_particleVectorForward);
                }

                Vector3D pos    = Entity.PositionComp.GetPosition();
                var      planet = MyGamePruningStructure.GetClosestPlanet(pos);

                MeteorStatus orig = m_meteorStatus;

                if (planet != null && planet.HasAtmosphere && planet.GetAirDensity(pos) > 0.5f)
                {
                    m_meteorStatus = MeteorStatus.InAtmosphere;
                }
                else
                {
                    m_meteorStatus = MeteorStatus.InSpace;
                }

                if (orig != m_meteorStatus && m_dustEffect != null)
                {
                    m_dustEffect.Stop();
                    m_dustEffect = null;
                }

                if (m_dustEffect != null && !InParticleVisibleRange)
                {
                    m_dustEffect.Stop();
                    m_dustEffect = null;
                }

                if (m_dustEffect == null && InParticleVisibleRange)
                {
                    if (MyParticlesManager.TryCreateParticleEffect(m_particleEffectNames[(int)m_meteorStatus], out m_dustEffect))
                    {
                        UpdateParticlePosition();
                        m_dustEffect.UserScale = Entity.PositionComp.Scale.Value;
                    }
                }

                m_soundEmitter.Update();

                if (Sync.IsServer && MySandboxGame.TotalGamePlayTimeInMilliseconds - m_timeCreated > Math.Min(MAX_TRAJECTORY_LENGTH / SPEED, MAX_TRAJECTORY_LENGTH / Entity.Physics.LinearVelocity.Length()) * 1000)
                {
                    CloseMeteorInternal();
                }
            }
        bool IMyShipController.TryGetPlanetPosition(out Vector3D position)
        {
            var blockPosition = this.PositionComp.GetPosition();

            if (!MyGravityProviderSystem.IsPositionInNaturalGravity(blockPosition))
            {
                position = Vector3D.Zero;
                return(false);
            }
            var boundingBox   = PositionComp.WorldAABB;
            var nearestPlanet = MyGamePruningStructure.GetClosestPlanet(ref boundingBox);

            if (nearestPlanet == null)
            {
                position = Vector3D.Zero;
                return(false);
            }
            position = nearestPlanet.PositionComp.GetPosition();
            return(true);
        }