コード例 #1
0
 public ProceduralAsteroid(AsteroidFieldModule field, Vector4I seed, Vector3D worldPos, double size, AsteroidLayer layer) : base(field)
 {
     Seed          = seed;
     WorldPosition = worldPos;
     Rotation      = new Quaternion((float)(worldPos.X % 1), (float)(worldPos.Y % 1), (float)(worldPos.Z % 1), 1);
     Rotation.Normalize();
     Size          = (float)size;
     m_boundingBox = new BoundingBoxD(WorldPosition - Size, WorldPosition + Size);
     SeedSpecs     = layer;
     RaiseMoved();
     base.OnRemoved += HandleRemove;
 }
コード例 #2
0
        private void OnEntityAdd(IMyEntity myEntity)
        {
            var planet = myEntity as MyPlanet;

            if (planet == null)
            {
                return;
            }

            List <Ob_AsteroidField> fieldsHere;

            if (!m_fieldsByPlanet.TryGetValue(planet.Generator.Id, out fieldsHere))
            {
                return;
            }
            foreach (var field in fieldsHere)
            {
                var structure = new Ob_AsteroidField();
                structure.Seed   = (int)(field.Seed ^ planet.EntityId);
                structure.Layers = new AsteroidLayer[field.Layers.Length];
                for (var i = 0; i < structure.Layers.Length; i++)
                {
                    var dst = structure.Layers[i] = new AsteroidLayer();
                    var src = field.Layers[i];
                    dst.AsteroidDensity = src.AsteroidDensity;
                    dst.AsteroidMaxSize = src.AsteroidMaxSize;
                    dst.AsteroidMinSize = src.AsteroidMinSize;
                    dst.AsteroidSpacing = src.AsteroidSpacing;
                    dst.UsableRegion    = src.UsableRegion;
                    dst.ProhibitsOre.Clear();
                    foreach (var x in src.ProhibitsOre)
                    {
                        dst.ProhibitsOre.Add(x);
                    }
                    dst.RequiresOre.Clear();
                    foreach (var x in src.RequiresOre)
                    {
                        dst.RequiresOre.Add(x);
                    }
                }
                structure.ShapeRing   = CloneUtilities.Clone(field.ShapeRing);
                structure.ShapeSphere = CloneUtilities.Clone(field.ShapeSphere);
                var rootTransform = MatrixD.CreateWorld(planet.PositionComp.WorldAABB.Center, planet.WorldMatrix.Forward, planet.WorldMatrix.Up);
                rootTransform       = rootTransform * field.Transform;
                structure.Transform = rootTransform;
                var scalingFactor = (float)planet.PositionComp.WorldAABB.HalfExtents.Max();
                if (structure.ShapeRing != null)
                {
                    structure.ShapeRing.InnerRadius *= scalingFactor;
                    structure.ShapeRing.OuterRadius *= scalingFactor;
                }
                if (structure.ShapeSphere != null)
                {
                    structure.ShapeSphere.InnerRadius *= scalingFactor;
                    structure.ShapeSphere.OuterRadius *= scalingFactor;
                }

                var module = new AsteroidFieldModule();
                module.SaveToStorage = false;
                Log(MyLogSeverity.Debug, "Adding a new asteroid field for {0}", planet.Generator.Id);
                using (this.IndentUsing())
                {
                    Log(MyLogSeverity.Debug, "Planet radius is {0}", scalingFactor);
                }
                Manager?.Register(module, structure);

                List <AsteroidFieldModule> fields;
                if (!m_fieldsByEntity.TryGetValue(planet.EntityId, out fields))
                {
                    fields = m_fieldsByEntity[planet.EntityId] = new List <AsteroidFieldModule>();
                }
                fields.Add(module);
            }
        }