public override void GenerateObjects(List <MyObjectSeed> objectsList)
        {
            ProfilerShort.Begin("GenerateObjects");
            foreach (var objectSeed in objectsList)
            {
                if (objectSeed.Generated)
                {
                    continue;
                }

                objectSeed.Generated = true;

                using (MyRandom.Instance.PushSeed(GetObjectIdSeed(objectSeed)))
                {
                    ProfilerShort.Begin("Planet");

                    var bbox = objectSeed.BoundingVolume;
                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

                    String storageName = string.Format("Planet_{0}_{1}_{2}_{3}_{4}", objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Index, objectSeed.Seed);

                    bool exists = false;
                    foreach (var voxelMap in m_tmpVoxelMapsList)
                    {
                        if (voxelMap.StorageName == storageName)
                        {
                            exists = true;
                            break;
                        }
                    }
                    m_tmpVoxelMapsList.Clear();

                    if (!exists)
                    {
                        var planet = MyWorldGenerator.AddPlanet(storageName, objectSeed.BoundingVolume.Center - VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(objectSeed.Size) / 2, objectSeed.Seed, objectSeed.Size, GetPlanetEntityId(objectSeed));

                        if (planet == null)
                        {
                            continue;
                        }
                        planet.Save = false;
                        RangeChangedDelegate OnStorageRangeChanged = null;
                        OnStorageRangeChanged = delegate(Vector3I minVoxelChanged, Vector3I maxVoxelChanged, MyStorageDataTypeFlags changedData)
                        {
                            planet.Save = true;
                            planet.Storage.RangeChanged -= OnStorageRangeChanged;
                        };
                        planet.Storage.RangeChanged += OnStorageRangeChanged;
                    }
                    ProfilerShort.End();
                }
            }
            ProfilerShort.End();
        }
        static void SpawnPlanet_Server(string planetName, float size, int seed, Vector3D pos)
        {
            var storageNameBase = planetName + "-" + seed + "d" + size;

            var storageName = MakeStorageName(storageNameBase);

            MyWorldGenerator.AddPlanet(storageNameBase, planetName, planetName, pos, seed, size, MyRandom.Instance.NextLong(), userCreated: true);

            if (MySession.Static.RequiresDX < 11)
            {
                MySession.Static.RequiresDX = 11;
            }
        }
Exemplo n.º 3
0
        private void SpawnPlanet(int seed, float size, Vector3D?pos = null)
        {
            var storageNameBase = "Planet" + "-" + seed + "d" + size;

            var storageName = MakeStorageName(storageNameBase);

            if (pos.HasValue == false)
            {
                pos = MySession.LocalHumanPlayer.GetPosition();
            }

            MyWorldGenerator.AddPlanet(storageNameBase, MySession.LocalHumanPlayer.GetPosition(), seed, size, MyRandom.Instance.NextLong(), false);
        }
        public override void GenerateObjects()
        {
            var system = MyStarSystemGenerator.Static.StarSystem;

            if (system == null || system.CenterObject == null)
            {
                return;
            }

            var objs = system.GetAllObjects();

            foreach (var obj in objs)
            {
                if (obj == null)
                {
                    continue;
                }
                if (obj.Type != MySystemObjectType.PLANET && obj.Type != MySystemObjectType.MOON)
                {
                    continue;
                }

                MySystemPlanet planet = obj as MySystemPlanet;

                if (planet.Generated)
                {
                    continue;
                }

                var definition = MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(planet.SubtypeId));

                if (definition == null)
                {
                    continue;
                }

                long   id   = MyRandom.Instance.NextLong();
                string name = GetPlanetStorageName(planet);

                MyPlanet generatedPlanet = MyWorldGenerator.AddPlanet(name, planet.DisplayName, planet.SubtypeId, planet.CenterPosition - GetPlanetOffset(definition, planet.Diameter), m_seed, (float)planet.Diameter, true, id, false, true);
                if (generatedPlanet != null)
                {
                    generatedPlanet.DisplayNameText = planet.DisplayName;
                    generatedPlanet.AsteroidName    = planet.DisplayName;

                    planet.Generated = true;
                    planet.EntityId  = generatedPlanet.EntityId;
                }
            }
        }
        static void SpawnPlanet_Server(string planetName, float size, int seed, Vector3D pos)
        {
            if (MySession.Static.CreativeMode || MyEventContext.Current.IsLocallyInvoked || MySession.Static.HasPlayerCreativeRights(MyEventContext.Current.Sender.Value))
            {
                var storageNameBase = planetName + "-" + seed + "d" + size;

                var storageName = MakeStorageName(storageNameBase);

                MyWorldGenerator.AddPlanet(storageNameBase, planetName, planetName, pos, seed, size, MyRandom.Instance.NextLong(), userCreated: true);

                if (MySession.Static.RequiresDX < 11)
                {
                    MySession.Static.RequiresDX = 11;
                }
            }
        }
Exemplo n.º 6
0
        public void GeneratePlanets()
        {
            foreach (var obj in SystemGenerator.Static.m_objects)
            {
                if (obj == null)
                {
                    continue;
                }
                if (obj.Type != SystemObjectType.PLANET)
                {
                    continue;
                }

                MyPlanetItem planet = (MyPlanetItem)obj;

                if (planet.Generated)
                {
                    continue;
                }
                MyPlanetGeneratorDefinition definition = GetDefinition(planet.DefName);
                if (definition == null)
                {
                    continue;
                }
                long   id   = MyRandom.Instance.NextLong();
                string name = (planet.DisplayName + " - " + definition.Id.SubtypeId).Replace(" ", "_");
                if (planet.CenterPosition.Equals(Vector3D.Zero))
                {
                    planet.CenterPosition = planet.OffsetPosition;
                }
                MyPlanet generatedPlanet = MyWorldGenerator.AddPlanet(name, planet.DisplayName, planet.DefName, planet.CenterPosition - GetPlanetOffset(definition, planet.Size), m_seed, planet.Size, true, id, false, true);

                if (generatedPlanet == null)
                {
                    continue;
                }

                planet.CenterPosition           = generatedPlanet.PositionComp.GetPosition();
                generatedPlanet.DisplayNameText = planet.DisplayName;
                generatedPlanet.AsteroidName    = planet.DisplayName;

                if (planet.PlanetRing != null)
                {
                    planet.PlanetRing.Center = planet.CenterPosition;
                }
                List <Vector3D> spawnedMoons = new List <Vector3D>();

                for (int i = 0; i < planet.PlanetMoons.Length; i++)
                {
                    MyPlanetMoonItem moon = planet.PlanetMoons[i];
                    if (moon == null)
                    {
                        continue;
                    }
                    MyPlanetGeneratorDefinition moonDef = GetDefinition(moon.DefName);
                    if (moonDef == null)
                    {
                        continue;
                    }
                    var    position        = new Vector3D(0, 0, 0);
                    long   mId             = MyRandom.Instance.NextLong();
                    string storageNameMoon = ("Moon " + moon.DisplayName + " - " + moonDef.Id.SubtypeId).Replace(" ", "_");
                    var    threshold       = 0;
                    do
                    {
                        double angle = MyRandom.Instance.GetRandomFloat(0, (float)Math.PI * 2f);
                        position = new Vector3D(moon.Distance * Math.Sin(angle), moon.Distance * Math.Cos(angle), moon.Distance * Math.Sin(MyRandom.Instance.GetRandomFloat((float)-Math.PI / 2, (float)Math.PI / 2)));
                        position = Vector3D.Add(planet.CenterPosition, position);
                        threshold++;
                    } while (ObstructedPlace(position, spawnedMoons, planet.Size, planet.PlanetRing) && threshold < 10000);
                    MyPlanet spawnedMoon = MyWorldGenerator.AddPlanet(storageNameMoon, moon.DisplayName, moon.DefName, position, m_seed, moon.Size, true, mId, false, true);
                    spawnedMoons.Add(spawnedMoon.PositionComp.GetPosition());

                    if (SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.ShowMoonGPS)
                    {
                        GlobalGpsManager.Static.AddGps(moon.DisplayName, Color.Aqua, spawnedMoon.PositionComp.GetPosition());
                    }
                }

                planet.Generated = true;
                if (SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.ShowPlanetGPS)
                {
                    GlobalGpsManager.Static.AddGps(planet.DisplayName, Color.Aqua, generatedPlanet.PositionComp.GetPosition());
                }
            }
        }