Example #1
0
        public static IMyVoxelMap SpawnAsteroid(MyPositionAndOrientation pos, CompositeShapeProviderBuilder provider)
        {
            var       storage     = new OctreeStorageBuilder(provider, MyVoxelCoordSystems.FindBestOctreeSize(provider.Size));
            var       storageName = $"proc_astr_{provider.Seed}_{provider.Size}_{(long) pos.Position.X}_{(long) pos.Position.Y}_{(long) pos.Position.Z}";
            var       entityID    = GetAsteroidEntityId(storageName);
            IMyEntity currEntity;

            if (MyAPIGateway.Entities.TryGetEntityById(entityID, out currEntity))
            {
                return(currEntity as IMyVoxelMap);
            }
            var data = storage.GetCompressedData();

            var storageInstance = MyAPIGateway.Session.VoxelMaps.CreateStorage(data);
            var entity          = MyAPIGateway.Session.VoxelMaps.CreateVoxelMap(storageName, storageInstance, pos.Position, entityID);

            entity.Save = false;
            var realEntity = entity as MyEntity;

            if (realEntity == null)
            {
                return(entity);
            }
            MyEntities.RaiseEntityCreated(realEntity);
            MyEntities.Add(realEntity);
            return(entity);
        }
Example #2
0
        public static MyPlanet SpawnPlanet(Vector3D pos, MyPlanetGeneratorDefinition generatorDef, long seed, float size, string storageName)
        {
            var provider = new PlanetStorageProviderBuilder();

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

            var storageBuilder = new OctreeStorageBuilder(provider, provider.StorageSize);
            var storage        = MyAPIGateway.Session.VoxelMaps.CreateStorage(storageBuilder.GetCompressedData());

            var minHillSize = provider.Radius * generatorDef.HillParams.Min;
            var maxHillSize = provider.Radius * generatorDef.HillParams.Max;

            var averagePlanetRadius = provider.Radius;

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

            var atmosphereRadius = AtmosphereRadius(generatorDef.AtmosphereSettings);

            atmosphereRadius *= (float)provider.Radius;

            var random               = new Random((int)seed);
            var redAtmosphereShift   = random.NextFloat(generatorDef.HostileAtmosphereColorShift.R.Min, generatorDef.HostileAtmosphereColorShift.R.Max);
            var greenAtmosphereShift = random.NextFloat(generatorDef.HostileAtmosphereColorShift.G.Min, generatorDef.HostileAtmosphereColorShift.G.Max);
            var blueAtmosphereShift  = random.NextFloat(generatorDef.HostileAtmosphereColorShift.B.Min, generatorDef.HostileAtmosphereColorShift.B.Max);

            var 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);

            var entityId = GetPlanetEntityId($"proc_planet_{provider.Seed}_{(int) provider.Radius}_{(long) pos.X}_{(long) pos.Y}_{(long) pos.Z}");
            var result   = MyAPIGateway.Entities.GetEntityById(entityId);

            if (result != null)
            {
                return(result as MyPlanet);
            }
            var planet = new MyPlanet();

            planet.EntityId = entityId;
            MyPlanetInitArguments planetInitArguments = new MyPlanetInitArguments();

            planetInitArguments.StorageName = storageName;
            CastProhibit(storage, out planetInitArguments.Storage);
            var posMinCorner = pos - provider.Radius;

            planetInitArguments.PositionMinCorner     = posMinCorner;
            planetInitArguments.Radius                = (float)provider.Radius;
            planetInitArguments.AtmosphereRadius      = atmosphereRadius;
            planetInitArguments.MaxRadius             = (float)outerRadius;
            planetInitArguments.MinRadius             = (float)innerRadius;
            planetInitArguments.HasAtmosphere         = generatorDef.HasAtmosphere;
            planetInitArguments.AtmosphereWavelengths = atmosphereWavelengths;
            planetInitArguments.GravityFalloff        = generatorDef.GravityFalloffPower;
            planetInitArguments.MarkAreaEmpty         = true;
            MoveAtmosphereSettings(generatorDef.AtmosphereSettings, out planetInitArguments.AtmosphereSettings);
            planetInitArguments.SurfaceGravity       = generatorDef.SurfaceGravity;
            planetInitArguments.AddGps               = false;
            planetInitArguments.SpherizeWithDistance = true;
            planetInitArguments.Generator            = generatorDef;
            planetInitArguments.UserCreated          = false;
            planetInitArguments.InitializeComponents = true;

            planet.Init(planetInitArguments);

            MyEntities.Add(planet);
            MyEntities.RaiseEntityCreated(planet);

            return(planet);
        }