public override void OnAddedToContainer()
        {
            base.OnAddedToContainer();
            m_planet = Entity as MyPlanet;
			m_oldNeedsDraw = NeedsDraw;
			NeedsDraw = true;
        }
        public static void AddPlanetPrefab(string prefabName, string name)
        {
            DictionaryValuesReader<MyDefinitionId, MyPlanetPrefabDefinition> planetDefinitions = MyDefinitionManager.Static.GetPlanetsPrefabsDefinitions();
            foreach (var planetPrebabDefinition in planetDefinitions)
            {
                if(planetPrebabDefinition.Id.SubtypeName == prefabName)
                {
                    var voxelMap = new MyPlanet();
                    var ob = planetPrebabDefinition.PlanetBuilder;
             
                    string storageName = MyFileSystem.ContentPath + "\\VoxelMaps\\" + ob.StorageName + MyVoxelConstants.FILE_EXTENSION;
                    voxelMap.EntityId = ob.EntityId;

                    MyPlanetInitArguments planetInitArguments;
                    planetInitArguments.StorageName = ob.StorageName;
                    planetInitArguments.Storage = MyStorageBase.LoadFromFile(storageName);
                    planetInitArguments.PositionMinCorner = ob.PositionAndOrientation.Value.Position;
                    planetInitArguments.AveragePlanetRadius = ob.Radius;
                    planetInitArguments.AtmosphereRadius = ob.AtmosphereRadius;
                    planetInitArguments.MaximumHillRadius = ob.MaximumHillRadius;
                    planetInitArguments.MinimumSurfaceRadius = ob.MinimumSurfaceRadius;
                    planetInitArguments.HasAtmosphere = ob.HasAtmosphere;
                    planetInitArguments.AtmosphereWavelengths = ob.AtmosphereWavelengths;
                    planetInitArguments.MaxOxygen = ob.MaximumOxygen;
                    planetInitArguments.GravityFalloff = ob.GravityFalloff;
                    planetInitArguments.MarkAreaEmpty = true;

                    voxelMap.Init(planetInitArguments);
                    MyEntities.Add(voxelMap);
                }
            }

        }
示例#3
0
        private static void SectorPhysicsCallback(MyPlanet me, ref MyPlanetSectorId id, ref Vector3D position)
        {
            double   distance;
            Vector3D pos;
            MyPlanetEnvironmentSector sector;

            if (!GetOrCreateSector(me, ref id, ref position, me.Ranges.SECTOR_LOD0_SQUARED, out pos, out distance, out sector))
            {
                return;
            }

            me.SectorsScanned.Hit();
            if (distance <= me.Ranges.SECTOR_LOD0_KEEP_SQUARED)
            {
                using (sector.AcquireStatusLock())
                {
                    MyPlanetSectorOperation ops = sector.PendingOperations;

                    if (sector.HasPhysics || ops.HasFlags(MyPlanetSectorOperation.SpawnPhysics))
                    {
                        ops &= ~(MyPlanetSectorOperation.Close | MyPlanetSectorOperation.ClosePhysics | MyPlanetSectorOperation.CloseDetails);
                    }
                    else if (distance <= me.Ranges.SECTOR_LOD0_SQUARED)
                    {
                        ops |= MyPlanetSectorOperation.SpawnPhysics | MyPlanetSectorOperation.SpawnDetails;
                        if (!sector.Loaded)
                        {
                            ops |= MyPlanetSectorOperation.Spawn;
                        }
                        ops &= ~(MyPlanetSectorOperation.Close | MyPlanetSectorOperation.ClosePhysics | MyPlanetSectorOperation.CloseDetails);
                    }
                    sector.PendingOperations = ops;
                }
            }
        }
 public SpawnInfo(MyObjectBuilder_SpaceFaunaComponent.SpawnInfo info, int currentTime)
 {
     SpawnTime = currentTime + info.SpawnTime;
     AbandonTime = currentTime + info.SpawnTime;
     Position = new Vector3D(info.X, info.Y, info.Z);
     Planet = MyGamePruningStructure.GetClosestPlanet(Position);
     SpawnDone = false;
 }
 public void Init(ref Vector3I pos, MyPlanet planet)
 {
     m_pos          = pos;
     m_cellHashCode = pos.GetHashCode() + planet.PositionLeftBottomCorner.GetHashCode();
     m_planet       = planet;
     SectorBox      = new BoundingBoxD(m_planet.PositionLeftBottomCorner + pos * SECTOR_SIZE_METERS, m_planet.PositionLeftBottomCorner + pos * SECTOR_SIZE_METERS + SECTOR_SIZE_METERS);
     m_sectorCenter = SectorBox.Center;
 }
 public SpawnInfo(MyObjectBuilder_SpaceFaunaComponent.SpawnInfo info, int currentTime)
 {
     SpawnTime = currentTime + info.SpawnTime;
     AbandonTime = currentTime + info.SpawnTime;
     Position = new Vector3D(info.X, info.Y, info.Z);
     Planet = MyGravityProviderSystem.GetNearestPlanet(Position);
     SpawnDone = false;
 }
 public void Init(ref Vector3I pos, MyPlanet planet)
 {
     m_pos = pos;
     m_cellHashCode = pos.GetHashCode() + planet.PositionLeftBottomCorner.GetHashCode();
     m_planet = planet;
     SectorBox = new BoundingBoxD(m_planet.PositionLeftBottomCorner + pos * SECTOR_SIZE_METERS, m_planet.PositionLeftBottomCorner + pos * SECTOR_SIZE_METERS + SECTOR_SIZE_METERS);
     m_sectorCenter = SectorBox.Center;
 }
        protected override void UnloadData()
        {
            base.UnloadData();
            if (m_sound != null)
                m_sound.Stop();

            m_nearestPlanet = null;
            m_nearestSoundRules = null;
        }
 public SpawnInfo(Vector3D position, int gameTime, MyPlanet planet)
 {
     var animalSpawnInfo = MySpaceBotFactory.GetDayOrNightAnimalSpawnInfo(planet, position);
     Debug.Assert(animalSpawnInfo != null);
     SpawnTime = gameTime + MyUtils.GetRandomInt(animalSpawnInfo.SpawnDelayMin, animalSpawnInfo.SpawnDelayMax);
     AbandonTime = gameTime + ABANDON_DELAY;
     Position = position;
     Planet = planet;
     SpawnDone = false;
 }
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            if (MySandboxGame.IsDedicated)
                return;

            if (m_volumeModifier != m_volumeModifierTarget)
            {
                if (m_volumeModifier < m_volumeModifierTarget)
                    m_volumeModifier = MyMath.Clamp(m_volumeModifier + MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * VOLUME_CHANGE_SPEED, 0f, m_volumeModifierTarget);
                else
                    m_volumeModifier = MyMath.Clamp(m_volumeModifier - MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * VOLUME_CHANGE_SPEED, m_volumeModifierTarget, 1f);
                if (m_sound != null && m_sound.IsPlaying)
                    m_sound.SetVolume(m_volumeOriginal * m_volumeModifier * VolumeModifierGlobal);
            }

            long currentFrame = MySession.Static.GameplayFrameCounter;
            if (currentFrame >= m_nextPlanetRecalculation)
            {
                Planet = FindNearestPlanet(MySector.MainCamera.Position);
                if(Planet == null)
                    m_nextPlanetRecalculation = currentFrame + m_planetRecalculationIntervalInSpace;
                else
                    m_nextPlanetRecalculation = currentFrame + m_planetRecalculationIntervalOnPlanet;
            }

            if (Planet == null || Planet.Provider == null || (MyFakes.ENABLE_NEW_SOUNDS && MySession.Static.Settings.RealisticSound && Planet.HasAtmosphere == false))
            {
                if (m_sound != null)
                    m_sound.Stop(true);
                return;
            }
            Vector3D localPosition = MySector.MainCamera.Position - Planet.PositionComp.GetPosition();
            double distanceToCenter = localPosition.Length();

            float height = Planet.Provider.Shape.DistanceToRatio((float)distanceToCenter);

            if (height < 0)
                return;

            Vector3D gravity = -localPosition / distanceToCenter;

            float angleFromEquator = (float)-gravity.Y;
            float sunAngleFromZenith = (float)MySector.DirectionToSunNormalized.Dot(-gravity);

            int ruleIndex;
            if (!FindSoundRuleIndex(angleFromEquator, height, sunAngleFromZenith, m_nearestSoundRules, out ruleIndex))
            {
                PlaySound(new MyCueId());
                return;
            }

            PlaySound(new MyCueId(m_nearestSoundRules[ruleIndex].EnvironmentSound));
        }
示例#11
0
        public MyRDPath(MyRDPathfinding pathfinding, Vector3D begin, IMyDestinationShape destination)
        {
            m_pathPoints = new List<Vector3D>();

            m_pathfinding = pathfinding;
            m_destination = destination;
            m_isValid = true;
            m_currentPointIndex = 0;

            m_planet = GetClosestPlanet(begin);
        }
示例#12
0
        public void Init(IMyStorage storage, Vector3D positionMinCorner, Vector3I storageMin, Vector3I storageMax,MyPlanet parent)
        {
            m_parent = parent;

            base.Init(null);

            m_storageMax = storageMax;
            m_storageMin = storageMin;

            m_storage = storage;
            InitVoxelMap(positionMinCorner, Size, false);
        }
示例#13
0
        public void Init(IMyStorage storage, Vector3D positionMinCorner, Vector3I storageMin, Vector3I storageMax, MyPlanet parent)
        {
            m_parent = parent;

            base.Init(null);

            m_storageMax = storageMax;
            m_storageMin = storageMin;

            m_storage = storage;
            InitVoxelMap(positionMinCorner, Size, false);
        }
示例#14
0
        public void Init(IMyStorage storage, MatrixD worldMatrix, Vector3I storageMin, Vector3I storageMax, MyPlanet parent)
        {
            m_parent = parent;

            long hash = storageMin.X;
            hash = (hash * 397L) ^ (long)storageMin.Y;
            hash = (hash * 397L) ^ (long)storageMin.Z;
            hash = (hash * 397L) ^ (long)parent.EntityId;

            EntityId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.VOXEL_PHYSICS, hash & 0x00FFFFFFFFFFFFFF);

            base.Init(null);
            InitVoxelMap(worldMatrix, Size, false);
        }
示例#15
0
        public void Init(IMyStorage storage, MatrixD worldMatrix, Vector3I storageMin, Vector3I storageMax, MyPlanet parent)
        {
            m_parent = parent;

            long hash = storageMin.X;

            hash = (hash * 397L) ^ (long)storageMin.Y;
            hash = (hash * 397L) ^ (long)storageMin.Z;
            hash = (hash * 397L) ^ (long)parent.EntityId;

            EntityId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.VOXEL_PHYSICS, hash & 0x00FFFFFFFFFFFFFF);

            base.Init(null);
            InitVoxelMap(worldMatrix, Size, false);
        }
        public void Init(IMyStorage storage, Vector3D positionMinCorner, Vector3I storageMin, Vector3I storageMax, MyPlanet parent)
        {
            PositionLeftBottomCorner = positionMinCorner;

            m_storageMax = storageMax;
            m_storageMin = storageMin;

            m_storage = storage;

            SizeInMetres = Size * MyVoxelConstants.VOXEL_SIZE_IN_METRES;
            SizeInMetresHalf = SizeInMetres / 2.0f;

            MatrixD worldMatrix = MatrixD.CreateTranslation(positionMinCorner + SizeInMetresHalf);
            Init(storage, worldMatrix, storageMin, storageMax, parent);
        }
 public void CloseSector()
 {
     m_spawnPositions.Clear();
     if (m_spawners == null)
     {
         return;
     }
     foreach (var spawner in m_spawners)
     {
         spawner.Value.EnvironmentItems.Close();
     }
     m_spawners.Clear();
     m_spawners  = null;
     m_planet    = null;
     HasGraphics = false;
 }
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            if (MySandboxGame.IsDedicated)
                return;

            long currentFrame = MySession.Static.GameplayFrameCounter;
            if (currentFrame >= m_nextPlanetRecalculation)
            {
                Planet = FindNearestPlanet(MySector.MainCamera.Position);
                if (Planet == null)
                {
                    m_nextPlanetRecalculation = currentFrame + m_planetRecalculationIntervalInSpace;
                    return;
                }
                m_nextPlanetRecalculation = currentFrame + m_planetRecalculationIntervalOnPlanet;
            }

            if (currentFrame%7 != 0 || Planet == null || Planet.Provider == null)
            {
                if(Planet == null && m_sound != null)
                    PlaySound(new MyCueId());
                return;
            }

            Vector3D localPosition = MySector.MainCamera.Position - Planet.PositionComp.GetPosition();
            double distanceToCenter = localPosition.Length();

            float height = Planet.Provider.Shape.DistanceToRatio((float) distanceToCenter);

            if (height < 0) return;

            Vector3D gravity = -localPosition / distanceToCenter;

            float angleFromEquator = (float)-gravity.Y;
            float sunAngleFromZenith = (float)MySector.DirectionToSunNormalized.Dot(-gravity);

            int ruleIndex;
            if (!FindSoundRuleIndex(angleFromEquator, height, sunAngleFromZenith, m_nearestSoundRules, out ruleIndex))
            {
                PlaySound(new MyCueId());
                return;
            }

            PlaySound(new MyCueId(m_nearestSoundRules[ruleIndex].EnvironmentSound));
        }
示例#19
0
        private static readonly int PLANET_SECTOR_IDLE_WORK_CYCLE = 50; // maximum number of cancelled sector requests to process


        /**
         * Find or create sector for scanning
         */
        private static bool GetOrCreateSector(MyPlanet me, ref MyPlanetSectorId id, ref Vector3D position, double minDistance, out Vector3D pos, out double distance, out MyPlanetEnvironmentSector sector)
        {
            if (!me.m_planetEnvironmentSectors.TryGetValue(id, out sector))
            {
                BoundingBoxD box;
                me.SectorIdToBoundingBox(ref id, out box);
                pos = box.Center;
                var posf = (Vector3)pos;

                pos = me.GetClosestSurfacePointLocal(ref posf);
                Vector3D.DistanceSquared(ref position, ref pos, out distance);

                if (distance > minDistance)
                {
                    return(false);
                }

                // Build allocator if necessary
                if (me.m_planetSectorsPool == null)
                {
                    me.m_planetSectorsPool = new MyDynamicObjectPool <MyPlanetEnvironmentSector>(SECTOR_POOL_SIZE);
                }

                // Try to get from cache if possible
                sector = me.m_planetSectorsPool.Allocate();
                sector.Init(ref id, me);

                me.m_planetEnvironmentSectors.Add(id, sector);
                me.SectorsCreated.Hit();
            }
            else
            {
                if (sector.IsClosed)
                {
                    sector.Init(ref id, me);
                }

                pos = sector.LocalSurfaceCenter;
                Vector3D.DistanceSquared(ref position, ref pos, out distance);
            }
            return(true);
        }
        public static void AddPlanetPrefab(string planetName,string definitionName,Vector3D position, bool addGPS)
        {
            DictionaryValuesReader<MyDefinitionId, MyPlanetPrefabDefinition> planetPrefabDefinitions = MyDefinitionManager.Static.GetPlanetsPrefabsDefinitions();
            foreach (var planetPrefabDefinition in planetPrefabDefinitions)
            {
                if (planetPrefabDefinition.Id.SubtypeName == planetName)
                {
                    MyPlanetGeneratorDefinition planetDefinition = MyDefinitionManager.Static.GetDefinition<MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(definitionName));

                    var planet = new MyPlanet();
                    var ob = planetPrefabDefinition.PlanetBuilder;
             
                    string storageName = MyFileSystem.ContentPath + "\\VoxelMaps\\" + ob.StorageName + MyVoxelConstants.FILE_EXTENSION;
                    planet.EntityId = ob.EntityId;

                    MyPlanetInitArguments planetInitArguments;
                    planetInitArguments.StorageName = ob.StorageName;
                    planetInitArguments.Storage = MyStorageBase.LoadFromFile(storageName);
                    planetInitArguments.PositionMinCorner = position;
                    planetInitArguments.Radius = ob.Radius;
                    planetInitArguments.AtmosphereRadius = ob.AtmosphereRadius;
                    planetInitArguments.MaxRadius = ob.MaximumHillRadius;
                    planetInitArguments.MinRadius = ob.MinimumSurfaceRadius;
                    planetInitArguments.HasAtmosphere = planetDefinition.HasAtmosphere;
                    planetInitArguments.AtmosphereWavelengths = ob.AtmosphereWavelengths;
                    planetInitArguments.GravityFalloff = planetDefinition.GravityFalloffPower;
                    planetInitArguments.MarkAreaEmpty = true;
                    planetInitArguments.AtmosphereSettings = ob.AtmosphereSettings.HasValue ? ob.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults();
                    planetInitArguments.SurfaceGravity = planetDefinition.SurfaceGravity;
                    planetInitArguments.AddGps = addGPS;
                    planetInitArguments.SpherizeWithDistance = true;
                    planetInitArguments.Generator = planetDefinition;
                    planetInitArguments.UserCreated = false;
                    planetInitArguments.InitializeComponents = true;

                    planet.Init(planetInitArguments);
                    MyEntities.Add(planet);
                    MyEntities.RaiseEntityCreated(planet);
                }
            }

        }
示例#21
0
        public static MyPlanet GetClosestPlanet(ref BoundingBoxD box)
        {
            if (m_cachedVoxelList == null)
            {
                m_cachedVoxelList = new List <MyVoxelBase>();
            }

            try
            {
                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGamePruningStructure::GetClosestPlanet");

                m_voxelMapsTree.OverlapAllBoundingBox <MyVoxelBase>(ref box, m_cachedVoxelList, 0, false);

                MyPlanet planet = null;

                Vector3D center = box.Center;

                double dist = double.PositiveInfinity;
                foreach (var voxel in m_cachedVoxelList)
                {
                    if (voxel is MyPlanet)
                    {
                        var dd = (center - voxel.WorldMatrix.Translation).LengthSquared();
                        if (dd < dist)
                        {
                            dist   = dd;
                            planet = (MyPlanet)voxel;
                        }
                    }
                }

                VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

                return(planet);
            }
            finally
            {
                m_cachedVoxelList.Clear();
            }
        }
示例#22
0
        public MyNavmeshOBBs(MyPlanet planet, Vector3D centerPoint, Vector3D forwardDirection, int obbsPerLine, int tileSize, int tileHeight)
        {
            m_planet = planet;

            // There will always be an odd number of obbs in a line
            OBBsPerLine = obbsPerLine;
            if (OBBsPerLine % 2 == 0)
                OBBsPerLine += 1;

            m_middleCoord = (OBBsPerLine - 1) / 2;

            m_tileHalfSize = tileSize * 0.5f;
            m_tileHalfHeight = tileHeight * 0.5f;

            m_obbs = new MyOrientedBoundingBoxD?[OBBsPerLine][];
            for (int i = 0; i < OBBsPerLine; i++)
                m_obbs[i] = new MyOrientedBoundingBoxD?[OBBsPerLine];

            Initialize(centerPoint, forwardDirection);

            BaseOBB = GetBaseOBB();
        }
 public void CloseSector()
 {
     m_spawnPositions.Clear();
     if (m_spawners == null)
     {
         return;
     }
     foreach (var spawner in m_spawners)
     {
         spawner.Value.EnvironmentItems.Close();
     }
     m_spawners.Clear();
     m_spawners = null;
     m_planet = null;
     HasGraphics = false;
 }
        private float FindDistanceToNearestPlanetSeaLevel(BoundingBoxD worldBB, out MyPlanet closestPlanet)
        {
            ProfilerShort.Begin("FindNearestPointOnPlanet");
            closestPlanet = MyGamePruningStructure.GetClosestPlanet(ref worldBB);
            double closestDistance = double.MaxValue;
            if (closestPlanet != null)
            {
                closestDistance = ((worldBB.Center - closestPlanet.PositionComp.GetPosition()).Length() - closestPlanet.AverageRadius);
            }
            ProfilerShort.End();

            return (float)closestDistance;
        }
示例#25
0
        // Is there night on the given place on planet? Position is in global space.
        static bool IsThereNight(MyPlanet planet, ref Vector3D position)
        {
            // gravitation vector and vector to sun are facing same direction

            // We don't even have to normalize :D
            Vector3 grav = position - planet.PositionComp.GetPosition();
            return Vector3.Dot(MySector.DirectionToSunNormalized, grav) > 0;
        }
示例#26
0
        // Obtain day or night spawning info based on given planet and position. Position is in global space.
        public static MyPlanetAnimalSpawnInfo GetDayOrNightAnimalSpawnInfo(MyPlanet planet, Vector3D position)
        {
            if (planet == null)
            {
                return null;
            }

            if (planet.Generator.NightAnimalSpawnInfo != null
                && planet.Generator.NightAnimalSpawnInfo.Animals != null
                && planet.Generator.NightAnimalSpawnInfo.Animals.Length > 0
                && IsThereNight(planet, ref position))
            {
                return planet.Generator.NightAnimalSpawnInfo;
            }
            else if (planet.Generator.AnimalSpawnInfo != null
                && planet.Generator.AnimalSpawnInfo.Animals != null
                && planet.Generator.AnimalSpawnInfo.Animals.Length > 0)
            {
                return planet.Generator.AnimalSpawnInfo;
            }
            else
            {
                return null;
            }
        }
示例#27
0
        public void Init(IMyStorage storage, Vector3D positionMinCorner, Vector3I storageMin, Vector3I storageMax, MyPlanet parent)
        {
            PositionLeftBottomCorner = positionMinCorner;

            m_storageMax = storageMax;
            m_storageMin = storageMin;

            m_storage = storage;

            SizeInMetres     = Size * MyVoxelConstants.VOXEL_SIZE_IN_METRES;
            SizeInMetresHalf = SizeInMetres / 2.0f;

            MatrixD worldMatrix = MatrixD.CreateTranslation(positionMinCorner + SizeInMetresHalf);

            Init(storage, worldMatrix, storageMin, storageMax, parent);
        }
        private void SetNearestPlanet(MyPlanet planet)
        {
            m_nearestPlanet = planet;

            if (m_nearestPlanet != null && m_nearestPlanet.Generator != null)
            {
                m_nearestSoundRules = m_nearestPlanet.Generator.SoundRules ?? m_emptySoundRules;
            }
        }
            private void UpdateViewRange(MyPlanet planet)
            {
                var pos = MySector.MainCamera.Position;

                double dist = double.MaxValue;

                foreach (var p in MyPlanets.GetPlanets())
                {
                    double dsq = Vector3D.DistanceSquared(pos, p.WorldMatrix.Translation);
                    if (dsq < dist)
                    {
                        planet = p;
                        dist = dsq;
                    }
                }

                var radius = planet.MinimumRadius;
                double altitude;

                m_height = planet.MaximumRadius - radius;

                var center = planet.WorldMatrix.Translation;


                m_radius = HyperSphereHelpers.DistanceToTangentProjected(ref center, ref pos, radius, out altitude);

                var up = center - pos;
                up.Normalize();

                m_center = pos + up * altitude;

                var forward = Vector3D.CalculatePerpendicularVector(up);

                m_orientation = QuaternionD.CreateFromForwardUp(forward, up);
            }
示例#30
0
        private void CalculateNextCue()
        {
            if (MySession.Static == null || MySession.Static.LocalCharacter == null)
                return;
            m_noMusicTimer = m_random.Next(DEFAULT_NO_MUSIC_TIME_MIN, DEFAULT_NO_MUSIC_TIME_MAX);

            //planet or space
            Vector3D pos = MySession.Static.LocalCharacter.PositionComp.GetPosition();
            MyPlanet planet = MyGamePruningStructure.GetClosestPlanet(pos);
            var grav = planet!= null ? planet.Components.Get<MyGravityProviderComponent>() as MySphericalNaturalGravityComponent : null;
            if (planet != null && (grav != null) && Vector3D.Distance(pos, planet.PositionComp.GetPosition()) <= grav.GravityLimit * 0.65f)
            {
                if (planet != m_lastVisitedPlanet)
                {
                    m_lastVisitedPlanet = planet;
                    if (planet.Generator.MusicCategories != null && planet.Generator.MusicCategories.Count > 0)
                    {
                        m_actualMusicOptions.Clear();
                        foreach (var option in planet.Generator.MusicCategories)
                            m_actualMusicOptions.Add(new MusicOption(option.Category, option.Frequency));
                    }
                    else
                        m_actualMusicOptions = m_defaultPlanetCategory;
                }
            }
            else
            {
                m_lastVisitedPlanet = null;
                m_actualMusicOptions = m_defaultSpaceCategories;
            }

            //choose category based on frequency
            float sum = 0f;
            foreach (var option in m_actualMusicOptions)
            {
                sum += Math.Max(option.Frequency, 0f);
            }
            float r = (float)m_random.NextDouble() * sum;
            MyStringId selected = m_actualMusicOptions[0].Category;
            for (int i = 0; i < m_actualMusicOptions.Count; i++)
            {
                if (r <= m_actualMusicOptions[i].Frequency)
                {
                    selected = m_actualMusicOptions[i].Category;
                    break;
                }
                else
                    r -= m_actualMusicOptions[i].Frequency;
            }

            //pick from cue list and play
            CueIdPlaying = SelectCueFromCategory(selected);
            CategoryPlaying = selected;

            if (CueIdPlaying == m_cueEmpty)
                return;

            PlayMusic(CueIdPlaying, MyStringHash.NullOrEmpty);
            m_currentMusicCategory = MusicCategory.location;
        }
 public override void OnAddedToContainer()
 {
     base.OnAddedToContainer();
     m_planet = Entity as MyPlanet;
 }
示例#32
0
            public Vector3D GravityWorld; // Direction of the gravity in the destination coord

            internal void Clear()
            {
                Planet = null;
                Elevation = 0.0f;
                Height = 0.0f;
                PlanetVector = Vector3D.Up;
                GravityWorld = Vector3D.Down;
            }
 public MyDebugRenderComponentPlanet(MyPlanet voxelMap)
     : base(voxelMap)
 {
     m_planet = voxelMap;
 }
        public MyNavigationInputMesh(MyRDPathfinding rdPathfinding, MyPlanet planet, Vector3D center)
        {
            m_rdPathfinding = rdPathfinding;
            m_planet = planet;
            m_center = center;

            Vector3D gravityVector = -Vector3D.Normalize(GameSystems.MyGravityProviderSystem.CalculateTotalGravityInPoint(m_center));
            Vector3D fwd = Vector3D.CalculatePerpendicularVector(gravityVector);
            rdWorldQuaternion = Quaternion.Inverse(Quaternion.CreateFromForwardUp(fwd, gravityVector));
        }
        public static MyPlanet AddPlanet(string storageName, Vector3D positionMinCorner, int seed, float size, long entityId = 0)
        {
            m_materialsByOreType.Clear();
            m_oreProbalities.Clear();
            m_spawningMaterials.Clear();
            m_organicMaterials.Clear();

            DictionaryValuesReader<MyDefinitionId, MyPlanetDefinition> planetDefinitions = MyDefinitionManager.Static.GetPlanetsDefinitions();

            foreach (var planetDefinition in planetDefinitions)
            {
                if (planetDefinition.Diameter.Min <= size && size <= planetDefinition.Diameter.Max)
                {

                    var random = MyRandom.Instance;
                    using (var stateToken = random.PushSeed(seed))
                    {
                        BuildOreProbabilities(planetDefinition);
                        FillMaterialCollections();

                        MyCsgShapePlanetShapeAttributes shapeAttributes = new MyCsgShapePlanetShapeAttributes();

                        shapeAttributes.Seed = seed;
                        shapeAttributes.Diameter = size;
                        shapeAttributes.Radius = size / 2.0f;
                        shapeAttributes.LayerDeviationSeed = random.Next();
                        shapeAttributes.LayerDeviationNoiseFrequency = random.NextFloat(100.0f, 500.0f);
                        shapeAttributes.NoiseFrequency = random.NextFloat(planetDefinition.StructureRatio.Min, planetDefinition.StructureRatio.Max);
                        shapeAttributes.NormalNoiseFrequency = random.NextFloat(planetDefinition.NormalNoiseValue.Min, planetDefinition.NormalNoiseValue.Max);
                        shapeAttributes.DeviationScale = random.NextFloat(planetDefinition.Deviation.Min, planetDefinition.Deviation.Max);

                        MyCsgShapePlanetHillAttributes hillAttributes = FillValues(planetDefinition.HillParams, random);
                        MyCsgShapePlanetHillAttributes canyonAttributes = FillValues(planetDefinition.CanyonParams, random);

                        float planetHalfDeviation = (shapeAttributes.Diameter * shapeAttributes.DeviationScale) / 2.0f;
                        float averagePlanetRadius = shapeAttributes.Diameter * (1 - shapeAttributes.DeviationScale * hillAttributes.SizeRatio) / 2.0f;

                        float hillHalfDeviation = planetHalfDeviation * hillAttributes.SizeRatio;
                        float canyonHalfDeviation = planetHalfDeviation * canyonAttributes.SizeRatio;

                        float outerRadius = averagePlanetRadius + hillHalfDeviation * 1.5f;
                        float innerRadius = averagePlanetRadius - canyonHalfDeviation * 2.5f;

                        float atmosphereRadius = MathHelper.Max(outerRadius, averagePlanetRadius * 1.06f);
                        float minPlanetRadius = MathHelper.Min(innerRadius, averagePlanetRadius - planetHalfDeviation * 2 * 2.5f);

                        bool isHostile = random.NextFloat(0, 1) < planetDefinition.HostilityProbability;
                        MyMaterialLayer[] materialLayers = CreateMaterialLayers(planetDefinition, isHostile, random, averagePlanetRadius, hillHalfDeviation, canyonHalfDeviation, ref outerRadius, ref innerRadius);

                        IMyStorage storage = new MyOctreeStorage(MyCompositeShapeProvider.CreatePlanetShape(0, ref shapeAttributes, ref hillAttributes, ref canyonAttributes, materialLayers), FindBestOctreeSize(size));

                        float redAtmosphereShift = isHostile ? random.NextFloat(planetDefinition.HostileAtmosphereColorShift.R.Min, planetDefinition.HostileAtmosphereColorShift.R.Max) : 0;
                        float greenAtmosphereShift = isHostile ? random.NextFloat(planetDefinition.HostileAtmosphereColorShift.G.Min, planetDefinition.HostileAtmosphereColorShift.G.Max) : 0;
                        float blueAtmosphereShift = isHostile ? random.NextFloat(planetDefinition.HostileAtmosphereColorShift.B.Min, planetDefinition.HostileAtmosphereColorShift.B.Max) : 0;

                        Vector3 atmosphereWavelengths = new Vector3(0.650f + redAtmosphereShift, 0.570f + greenAtmosphereShift, 0.475f + blueAtmosphereShift);

                        atmosphereWavelengths.X = MathHelper.Clamp(atmosphereWavelengths.X, 0.1f, 1.0f);
                        atmosphereWavelengths.Y = MathHelper.Clamp(atmosphereWavelengths.Y, 0.1f, 1.0f);
                        atmosphereWavelengths.Z = MathHelper.Clamp(atmosphereWavelengths.Z, 0.1f, 1.0f);

                        float gravityFalloff = random.NextFloat(planetDefinition.GravityFalloffPower.Min, planetDefinition.GravityFalloffPower.Max);

                        var voxelMap = new MyPlanet();
                        voxelMap.EntityId = entityId;

                        voxelMap.Init(storageName, storage, positionMinCorner, averagePlanetRadius, atmosphereRadius,
                            averagePlanetRadius + hillHalfDeviation, minPlanetRadius, planetDefinition.HasAtmosphere, atmosphereWavelengths, isHostile ? 0.0f : 1.0f, gravityFalloff);
                        MyEntities.Add(voxelMap);
                        return voxelMap;
                    }


                }
            }
            return null;
        }
示例#36
0
        public static MyDetectedEntityInfo Create(MyEntity entity, long sensorOwner, Vector3D?hitPosition = new Vector3D?())
        {
            MyDetectedEntityType             type;
            MyRelationsBetweenPlayerAndBlock neutral;
            string displayName;

            if (entity == null)
            {
                return(new MyDetectedEntityInfo());
            }
            MatrixD      zero     = MatrixD.Zero;
            Vector3      velocity = (Vector3)Vector3D.Zero;
            int          totalGamePlayTimeInMilliseconds = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            BoundingBoxD worldAABB = entity.PositionComp.WorldAABB;

            if (entity.Physics != null)
            {
                zero     = entity.Physics.GetWorldMatrix().GetOrientation();
                velocity = entity.Physics.LinearVelocity;
            }
            MyCubeGrid topMostParent = entity.GetTopMostParent(null) as MyCubeGrid;

            if (topMostParent != null)
            {
                type    = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyDetectedEntityType.LargeGrid : MyDetectedEntityType.SmallGrid;
                neutral = (topMostParent.BigOwners.Count != 0) ? MyIDModule.GetRelation(sensorOwner, topMostParent.BigOwners[0], MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare) : MyRelationsBetweenPlayerAndBlock.NoOwnership;
                if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare))
                {
                    displayName = topMostParent.DisplayName;
                }
                else
                {
                    displayName = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyTexts.GetString(MySpaceTexts.DetectedEntity_LargeGrid) : MyTexts.GetString(MySpaceTexts.DetectedEntity_SmallGrid);
                }
                zero = topMostParent.WorldMatrix.GetOrientation();
                return(new MyDetectedEntityInfo(topMostParent.EntityId, displayName, type, hitPosition, zero, topMostParent.Physics.LinearVelocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyCharacter character = entity as MyCharacter;

            if (character != null)
            {
                type    = !character.IsPlayer ? MyDetectedEntityType.CharacterOther : MyDetectedEntityType.CharacterHuman;
                neutral = MyIDModule.GetRelation(sensorOwner, character.GetPlayerIdentityId(), MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare);
                if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare))
                {
                    displayName = character.DisplayNameText;
                }
                else
                {
                    displayName = !character.IsPlayer ? MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterOther) : MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterHuman);
                }
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, type, hitPosition, zero, velocity, neutral, character.Model.BoundingBox.Transform(character.WorldMatrix), (long)totalGamePlayTimeInMilliseconds));
            }
            neutral = MyRelationsBetweenPlayerAndBlock.Neutral;
            MyFloatingObject obj2 = entity as MyFloatingObject;

            if (obj2 != null)
            {
                displayName = obj2.Item.Content.SubtypeName;
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyInventoryBagEntity entity2 = entity as MyInventoryBagEntity;

            if (entity2 != null)
            {
                displayName = entity2.DisplayName;
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyPlanet planet = entity as MyPlanet;

            if (planet != null)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(planet.PositionComp.GetPosition(), (double)planet.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds));
            }
            MyVoxelPhysics physics = entity as MyVoxelPhysics;

            if (physics != null)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(physics.Parent.PositionComp.GetPosition(), (double)physics.Parent.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyVoxelMap)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Asteroid);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Asteroid, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyMeteor)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Meteor);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Meteor, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyMissile)
            {
                return(new MyDetectedEntityInfo(entity.EntityId, entity.DisplayName, MyDetectedEntityType.Missile, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            Vector3D?nullable    = null;
            MatrixD  orientation = new MatrixD();
            Vector3  vector2     = new Vector3();

            return(new MyDetectedEntityInfo(0L, string.Empty, MyDetectedEntityType.Unknown, nullable, orientation, vector2, MyRelationsBetweenPlayerAndBlock.NoOwnership, new BoundingBoxD(), (long)MySandboxGame.TotalGamePlayTimeInMilliseconds));
        }
示例#37
0
            internal void Calculate(Vector3D worldPoint)
            {
                Clear();
                var planet = MyGamePruningStructure.GetClosestPlanet(worldPoint);
                if (planet != null)
                {
                    var planetVector = worldPoint - planet.PositionComp.GetPosition();
                    var gravityLimit = ((MySphericalNaturalGravityComponent)planet.Components.Get<MyGravityProviderComponent>()).GravityLimit;
                    if (planetVector.Length() > gravityLimit)
                    {
                        return;
                    }

                    Planet = planet;
                    PlanetVector = planetVector;
                    if (!Vector3D.IsZero(PlanetVector))
                    {
                        GravityWorld = Vector3D.Normalize(Planet.Components.Get<MyGravityProviderComponent>().GetWorldGravity(worldPoint));

                        Vector3 localPoint = (Vector3)(worldPoint - Planet.WorldMatrix.Translation);
                        Vector3D closestPoint = Planet.GetClosestSurfacePointLocal(ref localPoint);
                        Height = Vector3D.Distance(localPoint, closestPoint);

                        Elevation = PlanetVector.Length();
                        PlanetVector *= 1.0 / Elevation;
                    }
                }
            }
示例#38
0
        public void Update()
        {
            if (Globals.UpdateCount < m_nextUpdate)
                return;
            m_nextUpdate = Globals.UpdateCount + ShipAutopilot.UpdateFrequency;

            m_totalThrustForce.Clear();

            Vector3D position = myGrid.GetPosition();
            bool first = true;
            Vector3 worldGravity = Vector3.Zero;
            m_planetAtmos = null;
            m_airDensity = 0f;
            List<IMyVoxelBase> allPlanets = ResourcePool<List<IMyVoxelBase>>.Pool.Get();
            MyAPIGateway.Session.VoxelMaps.GetInstances_Safe(allPlanets, voxel => voxel is MyPlanet);

            foreach (MyPlanet planet in allPlanets)
                if (planet.IsPositionInGravityWell(position))
                {
                    if (first)
                    {
                        first = false;
                        m_gravStrength = planet.GetGravityMultiplier(position) * 9.81f;
                        Vector3 direction = planet.GetWorldGravityNormalized(ref position);
                        worldGravity = m_gravStrength.Value * direction;
                    }
                    else
                    {
                        worldGravity += planet.GetWorldGravity(position);
                        m_gravStrength = null;
                    }
                    if (planet.HasAtmosphere)
                    {
                        m_airDensity += planet.GetAirDensity(position);
                        m_planetAtmos = planet;
                    }
                }

            allPlanets.Clear();
            ResourcePool<List<IMyVoxelBase>>.Pool.Return(allPlanets);

            if (m_primaryDirty)
            {
                m_primaryDirty = false;

                CalcForceInDirection(Base6Directions.Direction.Forward);
                CalcForceInDirection(Base6Directions.Direction.Backward);
                CalcForceInDirection(Base6Directions.Direction.Up);
                CalcForceInDirection(Base6Directions.Direction.Down);
                CalcForceInDirection(Base6Directions.Direction.Left);
                CalcForceInDirection(Base6Directions.Direction.Right);

                if (m_primaryForce.Force < 1f)
                    throw new Exception("Ship has no thrusters");
            }

            if (worldGravity.LengthSquared() < 0.01f)
            {
                //myLogger.debugLog("Not in gravity well", "Update()");
                WorldGravity = Vector3.Zero;
                LocalGravity = Vector3.Zero;
                m_gravStrength = 0f;
                return;
            }
            WorldGravity = worldGravity;
            LocalGravity = new DirectionGrid() { vector = Vector3.Transform(worldGravity, myGrid.WorldMatrixNormalizedInv.GetOrientation()) };

            Vector3 gravityReactRatio = Vector3.Zero;
            if (LocalGravity.vector.X > 0)
                gravityReactRatio.X = -LocalGravity.vector.X * myGrid.Physics.Mass / GetForceInDirection(Base6Directions.Direction.Left);
            else
                gravityReactRatio.X = -LocalGravity.vector.X * myGrid.Physics.Mass / GetForceInDirection(Base6Directions.Direction.Right);
            if (LocalGravity.vector.Y > 0)
                gravityReactRatio.Y = -LocalGravity.vector.Y * myGrid.Physics.Mass / GetForceInDirection(Base6Directions.Direction.Down);
            else
                gravityReactRatio.Y = -LocalGravity.vector.Y * myGrid.Physics.Mass / GetForceInDirection(Base6Directions.Direction.Up);
            if (LocalGravity.vector.Z > 0)
                gravityReactRatio.Z = -LocalGravity.vector.Z * myGrid.Physics.Mass / GetForceInDirection(Base6Directions.Direction.Forward);
            else
                gravityReactRatio.Z = -LocalGravity.vector.Z * myGrid.Physics.Mass / GetForceInDirection(Base6Directions.Direction.Backward);
            GravityReactRatio = gravityReactRatio;

            myLogger.debugLog("Gravity: " + WorldGravity + ", local: " + LocalGravity + ", react: " + gravityReactRatio + ", air density: " + m_airDensity);
        }
        private void CreatePlanet(int seed, float size)
        {
            Vector3D pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * size * 3 - new Vector3D(size);

            MyPlanetGeneratorDefinition planetDefinition = MyDefinitionManager.Static.GetDefinition<MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(m_selectedPlanetName));
            MyPlanetStorageProvider provider = new MyPlanetStorageProvider();

            provider.Init(seed, planetDefinition, size / 2f);

            IMyStorage storage = new MyOctreeStorage(provider, provider.StorageSize);

            float minHillSize = provider.Radius * planetDefinition.HillParams.Min;
            float maxHillSize = provider.Radius * planetDefinition.HillParams.Max;

            float averagePlanetRadius = provider.Radius;

            float outerRadius = averagePlanetRadius + maxHillSize;
            float innerRadius = averagePlanetRadius + minHillSize;

            float atmosphereRadius = planetDefinition.AtmosphereSettings.HasValue && planetDefinition.AtmosphereSettings.Value.Scale > 1f ? 1 + planetDefinition.AtmosphereSettings.Value.Scale : 1.75f;
            atmosphereRadius *= provider.Radius;

            var planet = new MyPlanet();
            planet.EntityId = MyRandom.Instance.NextLong();

            MyPlanetInitArguments planetInitArguments;
            planetInitArguments.StorageName = "test";
            planetInitArguments.Storage = storage;
            planetInitArguments.PositionMinCorner = pos;
            planetInitArguments.Radius = provider.Radius;
            planetInitArguments.AtmosphereRadius = atmosphereRadius;
            planetInitArguments.MaxRadius = outerRadius;
            planetInitArguments.MinRadius = innerRadius;
            planetInitArguments.HasAtmosphere = planetDefinition.HasAtmosphere;
            planetInitArguments.AtmosphereWavelengths = Vector3.Zero;
            planetInitArguments.GravityFalloff = planetDefinition.GravityFalloffPower;
            planetInitArguments.MarkAreaEmpty = true;
            planetInitArguments.AtmosphereSettings = planetDefinition.AtmosphereSettings.HasValue ? planetDefinition.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults();
            planetInitArguments.SurfaceGravity = planetDefinition.SurfaceGravity;
            planetInitArguments.AddGps = false;
            planetInitArguments.SpherizeWithDistance = true;
            planetInitArguments.Generator = planetDefinition;
            planetInitArguments.UserCreated = true;

            planet.Init(planetInitArguments);

            m_lastAsteroidInfo = new SpawnAsteroidInfo()
            {
                Asteroid = null,
                RandomSeed = seed,
                Position = Vector3D.Zero,
                IsProcedural = true,
                ProceduralRadius = size,
            };

            MyClipboardComponent.Static.ActivateVoxelClipboard(planet.GetObjectBuilder(), storage, MySector.MainCamera.ForwardVector, (storage.Size * 0.5f).Length());
        }
示例#40
0
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var currentPlanetList = new List <IMyVoxelBase>();

            MyAPIGateway.Session.VoxelMaps.GetInstances(currentPlanetList, v => v is Sandbox.Game.Entities.MyPlanet);

            Vector3D playerPosition  = MyAPIGateway.Session.Player.GetPosition();
            var      closestDistance = Double.MaxValue;

            Sandbox.Game.Entities.MyPlanet closestPlanet = null;

            foreach (var planet in currentPlanetList)
            {
                var center   = planet.WorldMatrix.Translation;
                var distance = Vector3D.Distance(playerPosition, center); // use distance to center of planet.
                if (distance < closestDistance)
                {
                    closestPlanet   = (Sandbox.Game.Entities.MyPlanet)planet;
                    closestDistance = distance;
                }
            }

            if (closestPlanet != null)
            {
                Vector3D zeroGravity  = Vector3D.MinValue;
                var      playerVector = closestPlanet.WorldMatrix.Translation - playerPosition;
                playerVector.Normalize();
                bool playerInGravity = false;

                MySphericalNaturalGravityComponent naturalGravity = closestPlanet.Components.Get <MyGravityProviderComponent>() as MySphericalNaturalGravityComponent;
                if (naturalGravity != null)
                {
                    //float gravityLimit = (float)(closestPlanet.MaximumRadius * Math.Pow(closestPlanet.GetInitArguments.SurfaceGravity / 0.05f, 1 / closestPlanet.GetInitArguments.GravityFalloff));
                    zeroGravity     = closestPlanet.WorldMatrix.Translation + (playerVector * -naturalGravity.GravityLimit);
                    playerInGravity = playerPosition.IsBetween(zeroGravity, closestPlanet.WorldMatrix.Translation);
                }

                if (messageText.StartsWith("/laserup", StringComparison.InvariantCultureIgnoreCase) ||
                    messageText.StartsWith("/up", StringComparison.InvariantCultureIgnoreCase))
                {
                    MyAPIGateway.Session.GPS.AddGps(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.GPS.Create("Laser Up", "", playerPosition + (playerVector * -1000), true, false));

                    if (playerInGravity && zeroGravity != Vector3D.MinValue)
                    {
                        MyAPIGateway.Session.GPS.AddGps(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.GPS.Create("Laser Zero Gravity", "", zeroGravity, true, false));
                    }
                }
                if (messageText.StartsWith("/laserdown", StringComparison.InvariantCultureIgnoreCase) ||
                    messageText.StartsWith("/down", StringComparison.InvariantCultureIgnoreCase))
                {
                    MyAPIGateway.Session.GPS.AddGps(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.GPS.Create("Laser Down", "", playerPosition + (playerVector * 1000), true, false));

                    var groundPosition = closestPlanet.GetClosestSurfacePointGlobal(ref playerPosition);
                    MyAPIGateway.Session.GPS.AddGps(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.GPS.Create("Laser Ground", "", groundPosition, true, false));

                    if (!playerInGravity && zeroGravity != Vector3D.MinValue)
                    {
                        MyAPIGateway.Session.GPS.AddGps(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.GPS.Create("Laser Zero Gravity", "", zeroGravity, true, false));
                    }
                }

                return(true);
            }

            MyAPIGateway.Utilities.ShowMessage("Range", "No planets detected in range.");
            return(true);
        }