예제 #1
0
        public void Init(MyPlanetInitArguments arguments)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            m_planetInitValues    = arguments;
            m_hasSpawningMaterial = arguments.Storage.DataProvider.HasMaterialSpawningFlora();

            base.Init(m_planetInitValues.StorageName, m_planetInitValues.Storage, m_planetInitValues.PositionMinCorner);

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            m_storage.RangeChanged += storage_RangeChangedPlanet;

            if (Physics != null)
            {
                Physics.Enabled = false;
                Physics.Close();
                Physics = null;
            }

            Vector3I storageSize = m_planetInitValues.Storage.Size;

            m_numCells = new Vector3I(storageSize.X / PHYSICS_SECTOR_SIZE_METERS, storageSize.Y / PHYSICS_SECTOR_SIZE_METERS, storageSize.Z / PHYSICS_SECTOR_SIZE_METERS);

            m_numCells -= 1;

            StorageName  = m_planetInitValues.StorageName;
            m_storageMax = m_planetInitValues.Storage.Size;

            MyGravityProviderSystem.AddPlanet(this);
            MyOxygenProviderSystem.AddOxygenGenerator(this);

            if (m_planetInitValues.MarkAreaEmpty)
            {
                MyProceduralWorldGenerator.Static.MarkEmptyArea(PositionComp.GetPosition());
            }
        }
예제 #2
0
        public void Init(MyPlanetInitArguments arguments)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            m_planetInitValues = arguments;

            // MZ: if any crashes are related to MP planet init in the future, i added logging of MyPlanetInitArguments and other sanity checks.
            //     we are currently having crashes without this additional info and it is likely that even after my hotfixes it is going to crash again
            //     ...but we can check the logs and know the setup of the player :)
            MyLog.Default.Log(MyLogSeverity.Info, "Planet init values: {0}", m_planetInitValues.ToString());   // m_planetInitValues is struct and therefore never null

            // Parameteres from storage
            if (m_planetInitValues.Storage == null)
            {
                MyLog.Default.Log(MyLogSeverity.Error, "MyPlanet.Init: Planet storage is null! Init of the planet was cancelled.");
                return;
            }

            Provider = m_planetInitValues.Storage.DataProvider as MyPlanetStorageProvider;
            System.Diagnostics.Debug.Assert(Provider != null, "Invalid provider!");
            if (Provider == null)
            {
                MyLog.Default.Error("Invalid plane provider!");
                return;
            }

            if (Provider == null)
            {
                MyLog.Default.Log(MyLogSeverity.Error, "MyPlanet.Init: Planet storage provider is null! Init of the planet was cancelled.");
                return;
            }

            if (arguments.Generator == null)
            {
                MyLog.Default.Log(MyLogSeverity.Error, "MyPlanet.Init: Planet generator is null! Init of the planet was cancelled.");
                return;
            }

            m_planetInitValues.Radius    = Provider.Radius;
            m_planetInitValues.MaxRadius = Provider.Shape.OuterRadius;
            m_planetInitValues.MinRadius = Provider.Shape.InnerRadius;

            Generator = arguments.Generator;

            AtmosphereAltitude = Provider.Shape.MaxHillHeight * (Generator != null ? Generator.Atmosphere.LimitAltitude : 1);

            base.Init(m_planetInitValues.StorageName, m_planetInitValues.Storage, m_planetInitValues.PositionMinCorner);

            // Set storage as caching:
            ((MyStorageBase)Storage).InitWriteCache();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            m_storage.RangeChanged += storage_RangeChangedPlanet;

            if (m_planetInitValues.MarkAreaEmpty && MyProceduralWorldGenerator.Static != null)
            {
                MyProceduralWorldGenerator.Static.MarkEmptyArea(PositionComp.GetPosition(), m_planetInitValues.MaxRadius);
            }

            if (Physics != null)
            {
                Physics.Enabled = false;
                Physics.Close();
                Physics = null;
            }

            if (Name == null)
            {
                Name = StorageName;
            }

            /* Prepare sectors */
            Vector3I storageSize = m_planetInitValues.Storage.Size;

            m_numCells  = new Vector3I(storageSize.X / PHYSICS_SECTOR_SIZE_METERS, storageSize.Y / PHYSICS_SECTOR_SIZE_METERS, storageSize.Z / PHYSICS_SECTOR_SIZE_METERS);
            m_numCells -= 1;
            m_numCells  = Vector3I.Max(Vector3I.Zero, m_numCells);

            CanSpawnFlora = Generator != null && Generator.MaterialEnvironmentMappings.Count != 0 && MySession.Static.EnableFlora && MyFakes.ENABLE_ENVIRONMENT_ITEMS && Storage.DataProvider is MyPlanetStorageProvider;

            StorageName  = m_planetInitValues.StorageName;
            m_storageMax = m_planetInitValues.Storage.Size;

            // Init sector metadata
            PrepareSectors();

            // Prepare components
            // TODO: breaks loading of worlds. Overrides loaded deserialization of ownership components replacing them with clean one. Will be fixed after Daniel fixes generation of components on planet when new world is created. Also remove bool from arguments.
            if (arguments.InitializeComponents && Generator != null)
            {
                HackyComponentInitByMiroPleaseDontUseEver(new MyDefinitionId(typeof(MyObjectBuilder_Planet), Generator.Id.SubtypeId));
            }

            if (Generator != null && Generator.EnvironmentDefinition != null)
            {
                if (!Components.Contains(typeof(MyPlanetEnvironmentComponent)))
                {
                    Components.Add(new MyPlanetEnvironmentComponent());
                }
                Components.Get <MyPlanetEnvironmentComponent>().InitEnvironment();
            }

            Components.Add <MyGravityProviderComponent>(new MySphericalNaturalGravityComponent(m_planetInitValues.MinRadius, m_planetInitValues.MaxRadius, m_planetInitValues.GravityFalloff, m_planetInitValues.SurfaceGravity));

            if (m_planetInitValues.UserCreated)
            {
                ContentChanged = true;
            }
        }
예제 #3
0
        public void Init(MyPlanetInitArguments arguments)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            m_planetInitValues = arguments;

            // Parameteres from storage
            Provider = m_planetInitValues.Storage.DataProvider as MyPlanetStorageProvider;

            m_planetInitValues.Radius    = Provider.Radius;
            m_planetInitValues.MaxRadius = Provider.Shape.OuterRadius;
            m_planetInitValues.MinRadius = Provider.Shape.InnerRadius;

            Generator = arguments.Generator;

            AtmosphereAltitude = Provider.Shape.MaxHillHeight * Generator.Atmosphere.LimitAltitude;

            base.Init(m_planetInitValues.StorageName, m_planetInitValues.Storage, m_planetInitValues.PositionMinCorner);

            // Set storage as caching:
            ((MyStorageBase)Storage).InitWriteCache();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            m_storage.RangeChanged += storage_RangeChangedPlanet;

            if (m_planetInitValues.MarkAreaEmpty && MyProceduralWorldGenerator.Static != null)
            {
                MyProceduralWorldGenerator.Static.MarkEmptyArea(PositionComp.GetPosition(), m_planetInitValues.MaxRadius);
            }

            if (Physics != null)
            {
                Physics.Enabled = false;
                Physics.Close();
                Physics = null;
            }

            if (Name == null)
            {
                Name = StorageName;
            }

            /* Prepare sectors */
            Vector3I storageSize = m_planetInitValues.Storage.Size;

            m_numCells  = new Vector3I(storageSize.X / PHYSICS_SECTOR_SIZE_METERS, storageSize.Y / PHYSICS_SECTOR_SIZE_METERS, storageSize.Z / PHYSICS_SECTOR_SIZE_METERS);
            m_numCells -= 1;
            m_numCells  = Vector3I.Max(Vector3I.Zero, m_numCells);

            CanSpawnFlora = Generator.MaterialEnvironmentMappings.Count != 0 && MySession.Static.EnableFlora && MyFakes.ENABLE_ENVIRONMENT_ITEMS && Storage.DataProvider is MyPlanetStorageProvider;

            StorageName  = m_planetInitValues.StorageName;
            m_storageMax = m_planetInitValues.Storage.Size;

            // Init sector metadata
            PrepareSectors();

            // Prepare components
            HackyComponentInitByMiroPleaseDontUseEver(new MyDefinitionId(typeof(MyObjectBuilder_Planet), Generator.Id.SubtypeId));

            if (Generator.EnvironmentDefinition != null)
            {
                if (!Components.Contains(typeof(MyPlanetEnvironmentComponent)))
                {
                    Components.Add(new MyPlanetEnvironmentComponent());
                }
                Components.Get <MyPlanetEnvironmentComponent>().InitEnvironment();
            }

            Components.Add <MyGravityProviderComponent>(new MySphericalNaturalGravityComponent(m_planetInitValues.MinRadius, m_planetInitValues.MaxRadius, m_planetInitValues.GravityFalloff, m_planetInitValues.SurfaceGravity));

            if (m_planetInitValues.UserCreated)
            {
                ContentChanged = true;
            }
        }
예제 #4
0
        public void Init(MyPlanetInitArguments arguments)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            m_planetInitValues = arguments;
            m_hasSpawningMaterial = arguments.Storage.DataProvider.HasMaterialSpawningFlora();

            base.Init(m_planetInitValues.StorageName, m_planetInitValues.Storage, m_planetInitValues.PositionMinCorner);

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            m_storage.RangeChanged += storage_RangeChangedPlanet;

            if (Physics != null)
            {
                Physics.Enabled = false;
                Physics.Close();
                Physics = null;
            }

            Vector3I storageSize = m_planetInitValues.Storage.Size;
            m_numCells = new Vector3I(storageSize.X / PHYSICS_SECTOR_SIZE_METERS, storageSize.Y / PHYSICS_SECTOR_SIZE_METERS, storageSize.Z / PHYSICS_SECTOR_SIZE_METERS);
         
            m_numCells -= 1;

           StorageName = m_planetInitValues.StorageName;
           m_storageMax = m_planetInitValues.Storage.Size;
          
           MyGravityProviderSystem.AddPlanet(this);
           MyOxygenProviderSystem.AddOxygenGenerator(this);

           if (m_planetInitValues.MarkAreaEmpty)
            {
                MyProceduralWorldGenerator.Static.MarkEmptyArea(PositionComp.GetPosition());
            }

        }
예제 #5
0
        public void Init(MyPlanetInitArguments arguments)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            m_planetInitValues = arguments;

            // Parameteres from storage
            Provider = m_planetInitValues.Storage.DataProvider as MyPlanetStorageProvider;

            m_planetInitValues.Radius    = Provider.Radius;
            m_planetInitValues.MaxRadius = Provider.Shape.OuterRadius;
            m_planetInitValues.MinRadius = Provider.Shape.InnerRadius;

            Generator = arguments.Generator;

            AtmosphereAltitude = Provider.Shape.MaxHillHeight * Generator.Atmosphere.LimitAltitude;

            // Calculate the distance from the planet center where the gravity will be equal to GRAVITY_LIMIT_STRENGTH
            {
                double s          = (double)m_planetInitValues.SurfaceGravity;
                double radius     = m_planetInitValues.MaxRadius;
                double invFalloff = 1.0 / (double)m_planetInitValues.GravityFalloff;
                GravityLimit = (float)(radius * Math.Pow(s / GRAVITY_LIMIT_STRENGTH, invFalloff));
            }

            base.Init(m_planetInitValues.StorageName, m_planetInitValues.Storage, m_planetInitValues.PositionMinCorner);

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            m_storage.RangeChanged += storage_RangeChangedPlanet;

            if (m_planetInitValues.MarkAreaEmpty)
            {
                MyProceduralWorldGenerator.Static.MarkEmptyArea(PositionComp.GetPosition(), m_planetInitValues.MaxRadius);
            }

            if (Physics != null)
            {
                Physics.Enabled = false;
                Physics.Close();
                Physics = null;
            }


            /* Prepare sectors */
            Vector3I storageSize = m_planetInitValues.Storage.Size;

            m_numCells  = new Vector3I(storageSize.X / PHYSICS_SECTOR_SIZE_METERS, storageSize.Y / PHYSICS_SECTOR_SIZE_METERS, storageSize.Z / PHYSICS_SECTOR_SIZE_METERS);
            m_numCells -= 1;
            m_numCells  = Vector3I.Max(Vector3I.Zero, m_numCells);

            CanSpawnFlora = Generator.MaterialEnvironmentMappings.Count != 0 && MySession.Static.Settings.EnableFlora && MyFakes.ENABLE_ENVIRONMENT_ITEMS && Storage.DataProvider is MyPlanetStorageProvider;

            StorageName  = m_planetInitValues.StorageName;
            m_storageMax = m_planetInitValues.Storage.Size;

            // Init sector metadata
            PrepareSectors();

            if (m_planetInitValues.UserCreated)
            {
                ContentChanged = true;
            }
        }
예제 #6
0
        public void Init(MyPlanetInitArguments arguments)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            m_planetInitValues = arguments;

            // Parameteres from storage
            Provider = m_planetInitValues.Storage.DataProvider as MyPlanetStorageProvider;

            m_planetInitValues.Radius = Provider.Radius;
            m_planetInitValues.MaxRadius = Provider.Shape.OuterRadius;
            m_planetInitValues.MinRadius = Provider.Shape.InnerRadius;

            Generator = arguments.Generator;

            AtmosphereAltitude = Provider.Shape.MaxHillHeight * Generator.Atmosphere.LimitAltitude;

            base.Init(m_planetInitValues.StorageName, m_planetInitValues.Storage, m_planetInitValues.PositionMinCorner);

            // Set storage as caching:
            ((MyStorageBase)Storage).InitWriteCache();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            m_storage.RangeChanged += storage_RangeChangedPlanet;

            if (m_planetInitValues.MarkAreaEmpty && MyProceduralWorldGenerator.Static != null)
            {
                MyProceduralWorldGenerator.Static.MarkEmptyArea(PositionComp.GetPosition(), m_planetInitValues.MaxRadius);
            }

            if (Physics != null)
            {
                Physics.Enabled = false;
                Physics.Close();
                Physics = null;
            }

            if (Name == null)
                Name = StorageName;

            /* Prepare sectors */
            Vector3I storageSize = m_planetInitValues.Storage.Size;
            m_numCells = new Vector3I(storageSize.X / PHYSICS_SECTOR_SIZE_METERS, storageSize.Y / PHYSICS_SECTOR_SIZE_METERS, storageSize.Z / PHYSICS_SECTOR_SIZE_METERS);
            m_numCells -= 1;
            m_numCells = Vector3I.Max(Vector3I.Zero, m_numCells);

            CanSpawnFlora = Generator.MaterialEnvironmentMappings.Count != 0 && MySession.Static.EnableFlora && MyFakes.ENABLE_ENVIRONMENT_ITEMS && Storage.DataProvider is MyPlanetStorageProvider;

            StorageName = m_planetInitValues.StorageName;
            m_storageMax = m_planetInitValues.Storage.Size;

            // Init sector metadata
            PrepareSectors();

            // Prepare components
            // TODO: breaks loading of worlds. Overrides loaded deserialization of ownership components replacing them with clean one. Will be fixed after Daniel fixes generation of components on planet when new world is created. Also remove bool from arguments.
            if (arguments.InitializeComponents)
                HackyComponentInitByMiroPleaseDontUseEver(new MyDefinitionId(typeof(MyObjectBuilder_Planet), Generator.Id.SubtypeId));

            if (Generator.EnvironmentDefinition != null)
            {
                if (!Components.Contains(typeof(MyPlanetEnvironmentComponent)))
                    Components.Add(new MyPlanetEnvironmentComponent());
                Components.Get<MyPlanetEnvironmentComponent>().InitEnvironment();
            }

            Components.Add<MyGravityProviderComponent>(new MySphericalNaturalGravityComponent(m_planetInitValues.MinRadius, m_planetInitValues.MaxRadius, m_planetInitValues.GravityFalloff, m_planetInitValues.SurfaceGravity));

            if (m_planetInitValues.UserCreated)
            {
                ContentChanged = true;
            }
        }
예제 #7
0
        public void Init(MyPlanetInitArguments arguments)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            m_planetInitValues = arguments;

            // Parameteres from storage
            Provider = m_planetInitValues.Storage.DataProvider as MyPlanetStorageProvider;

            m_planetInitValues.Radius = Provider.Radius;
            m_planetInitValues.MaxRadius = Provider.Shape.OuterRadius;
            m_planetInitValues.MinRadius = Provider.Shape.InnerRadius;

            Generator = arguments.Generator;

            AtmosphereAltitude = Provider.Shape.MaxHillHeight * Generator.Atmosphere.LimitAltitude;

            // Calculate the distance from the planet center where the gravity will be equal to GRAVITY_LIMIT_STRENGTH
            {
                double s = (double)m_planetInitValues.SurfaceGravity;
                double radius = m_planetInitValues.MaxRadius;
                double invFalloff = 1.0 / (double)m_planetInitValues.GravityFalloff;
                GravityLimit = (float)(radius * Math.Pow(s / GRAVITY_LIMIT_STRENGTH, invFalloff));
            }

            base.Init(m_planetInitValues.StorageName, m_planetInitValues.Storage, m_planetInitValues.PositionMinCorner);

            // Set storage as caching:
            ((MyStorageBase)Storage).InitWriteCache();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            m_storage.RangeChanged += storage_RangeChangedPlanet;

            if (m_planetInitValues.MarkAreaEmpty)
            {
                MyProceduralWorldGenerator.Static.MarkEmptyArea(PositionComp.GetPosition(), m_planetInitValues.MaxRadius);
            }

            if (Physics != null)
            {
                Physics.Enabled = false;
                Physics.Close();
                Physics = null;
            }


            /* Prepare sectors */
            Vector3I storageSize = m_planetInitValues.Storage.Size;
            m_numCells = new Vector3I(storageSize.X / PHYSICS_SECTOR_SIZE_METERS, storageSize.Y / PHYSICS_SECTOR_SIZE_METERS, storageSize.Z / PHYSICS_SECTOR_SIZE_METERS);
            m_numCells -= 1;
            m_numCells = Vector3I.Max(Vector3I.Zero, m_numCells);

            CanSpawnFlora = Generator.MaterialEnvironmentMappings.Count != 0 && MySession.Static.Settings.EnableFlora && MyFakes.ENABLE_ENVIRONMENT_ITEMS && Storage.DataProvider is MyPlanetStorageProvider;

            StorageName = m_planetInitValues.StorageName;
            m_storageMax = m_planetInitValues.Storage.Size;

            // Init sector metadata
            PrepareSectors();

            if(m_planetInitValues.UserCreated)
            {
                ContentChanged = true;
            }
        }