示例#1
0
 MyEntity addStaticAsteroid(StringBuilder hudLabel, MyMwcObjectBuilder_StaticAsteroid_TypesEnum staticEnum, ref Vector3 currentPosition, Vector3 forward, MyMeshDrawTechnique? drawTechnique = null, MyMwcVoxelMaterialsEnum? material = null)
 {
     MyStaticAsteroid staticAsteroid = new MyStaticAsteroid();
     MyMwcObjectBuilder_StaticAsteroid objectBuilder = new MyMwcObjectBuilder_StaticAsteroid(staticEnum, material);
     staticAsteroid.Init(hudLabel.ToString(), objectBuilder, Matrix.Identity);
     return addEntity(staticAsteroid, ref currentPosition, forward);
 }
示例#2
0
        /// <summary>
        /// Inits the specified hud label text.
        /// </summary>
        /// <param name="hudLabelText">The hud label text.</param>
        /// <param name="objectBuilder">The object builder.</param>
        public void Init(string hudLabelText, MyMwcObjectBuilder_StaticAsteroid objectBuilder, Matrix matrix)
        {
            MyStaticAsteroidModels models = GetModelsFromType(objectBuilder.AsteroidType);

            StringBuilder hudLabelTextSb = (hudLabelText == null) ? null : new StringBuilder(hudLabelText);

            if (objectBuilder.Generated)
            {
                Flags &= ~EntityFlags.EditableInEditor;
                Flags &= ~EntityFlags.NeedsId;
            }
            else
            {
                Flags |= EntityFlags.EditableInEditor;
                Flags |= EntityFlags.NeedsId;
            }

            CastShadows = !objectBuilder.Generated;

            if (!objectBuilder.AsteroidMaterial1.HasValue && MySector.Area.HasValue)
            {
                var area = MySolarSystemConstants.Areas[MySector.Area.Value];
                objectBuilder.AsteroidMaterial1 = area.SecondaryStaticAsteroidMaterial;
                objectBuilder.FieldDir          = MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized();
            }

            NeedsUpdate = false;

            Init(hudLabelTextSb, models.LOD0, models.LOD1, null, null, objectBuilder, null, models.LOD2);

            AsteroidType = objectBuilder.AsteroidType;

            SetWorldMatrix(matrix);

            FieldDir = objectBuilder.FieldDir;

            if (objectBuilder.AsteroidMaterial.HasValue)
            {
                VoxelMaterial   = objectBuilder.AsteroidMaterial.Value;
                VoxelMaterial1  = objectBuilder.AsteroidMaterial1;
                m_drawTechnique = MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID;
            }

            if (objectBuilder.UseModelTechnique)
            {
                m_meshMaterial  = MyVoxelMaterials.GetMaterialForMesh(VoxelMaterial);
                m_drawTechnique = MyMeshDrawTechnique.MESH;
            }

            InitDrawTechniques();

            InitPhysics();

            MyModels.OnContentLoaded += InitDrawTechniques;
            InitDrawTechniques();
        }
        public override void OnOkClick(MyGuiControlButton sender)
        {
            base.OnOkClick(sender);

            if (HasEntity())
            {
                if (m_changeMaterial.Checked)
                {
                    m_entity.VoxelMaterial = ((MyMwcVoxelMaterialsEnum)m_selectVoxelMapMaterialCombobox.GetSelectedKey());
                }

                float x, y, z;
                if (float.TryParse(m_positionX.Text, out x) && float.TryParse(m_positionY.Text, out y) && float.TryParse(m_positionZ.Text, out z))
                {
                    m_entity.SetPosition(new Vector3(x, y, z));
                }
            }
            else
            {
                if (GetAsteroidType() == MyGuiAsteroidTypesEnum.VOXEL)
                {
                    MyMwcObjectBuilder_SmallShip_TypesEnum shipType = (MyMwcObjectBuilder_SmallShip_TypesEnum)
                                                                      Enum.ToObject(typeof(MyMwcObjectBuilder_SmallShip_TypesEnum), m_selectVoxelMapCombobox.GetSelectedKey());
                    MyMwcVoxelFilesEnum voxelFileEnum = (MyMwcVoxelFilesEnum)
                                                        Enum.ToObject(typeof(MyMwcVoxelFilesEnum), m_selectVoxelMapCombobox.GetSelectedKey());
                    MyMwcVoxelMaterialsEnum materialEnum = (MyMwcVoxelMaterialsEnum)
                                                           Enum.ToObject(typeof(MyMwcVoxelMaterialsEnum), m_selectVoxelMapMaterialCombobox.GetSelectedKey());

                    MyMwcObjectBuilder_VoxelMap voxelMapBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.VoxelMap, null) as MyMwcObjectBuilder_VoxelMap;
                    voxelMapBuilder.VoxelMaterial = materialEnum;
                    voxelMapBuilder.VoxelFile     = voxelFileEnum;
                    MyEditor.Static.CreateFromObjectBuilder(voxelMapBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition);
                }
                else if (GetAsteroidType() == MyGuiAsteroidTypesEnum.STATIC)
                {
                    MyMwcObjectBuilder_StaticAsteroid_TypesEnum staticAsteroidType = (MyMwcObjectBuilder_StaticAsteroid_TypesEnum)
                                                                                     Enum.ToObject(typeof(MyMwcObjectBuilder_StaticAsteroid_TypesEnum), m_selectVoxelMapCombobox.GetSelectedKey());

                    MyMwcVoxelMaterialsEnum?materialEnum = null;
                    int materialKey = m_selectVoxelMapMaterialCombobox.GetSelectedKey();
                    if (materialKey != -1)
                    {
                        materialEnum = (MyMwcVoxelMaterialsEnum)Enum.ToObject(typeof(MyMwcVoxelMaterialsEnum), materialKey);
                    }

                    MyMwcObjectBuilder_StaticAsteroid staticAsteroidBuilder = new MyMwcObjectBuilder_StaticAsteroid(staticAsteroidType, materialEnum);
                    MyEditor.Static.CreateFromObjectBuilder(staticAsteroidBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition);
                }
            }

            MyGuiManager.CloseAllScreensExcept(MyGuiScreenGamePlay.Static);
        }
示例#4
0
        /// <summary>
        /// Inits the specified hud label text.
        /// </summary>
        /// <param name="hudLabelText">The hud label text.</param>
        /// <param name="objectBuilder">The object builder.</param>
        public void Init(string hudLabelText, MyMwcObjectBuilder_StaticAsteroid objectBuilder, Matrix matrix)
        {
            MyStaticAsteroidModels models = GetModelsFromType(objectBuilder.AsteroidType);

            StringBuilder hudLabelTextSb = (hudLabelText == null) ? null : new StringBuilder(hudLabelText);

            if (objectBuilder.Generated)
            {
                Flags &= ~EntityFlags.EditableInEditor;
                Flags &= ~EntityFlags.NeedsId;
            }
            else
            {
                Flags |= EntityFlags.EditableInEditor;
                Flags |= EntityFlags.NeedsId;
            }

            CastShadows = !objectBuilder.Generated;

            if (!objectBuilder.AsteroidMaterial1.HasValue && MySector.Area.HasValue)
            {
                var area = MySolarSystemConstants.Areas[MySector.Area.Value];
                objectBuilder.AsteroidMaterial1 = area.SecondaryStaticAsteroidMaterial;
                objectBuilder.FieldDir = MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized();
            }

            NeedsUpdate = false;

            Init(hudLabelTextSb, models.LOD0, models.LOD1, null, null, objectBuilder, null, models.LOD2);

            AsteroidType = objectBuilder.AsteroidType;

            SetWorldMatrix(matrix);

            FieldDir = objectBuilder.FieldDir;

            if (objectBuilder.AsteroidMaterial.HasValue)
            {
                VoxelMaterial = objectBuilder.AsteroidMaterial.Value;
                VoxelMaterial1 = objectBuilder.AsteroidMaterial1;
                m_drawTechnique = MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID;
            }

            if (objectBuilder.UseModelTechnique)
            {
                m_meshMaterial = MyVoxelMaterials.GetMaterialForMesh(VoxelMaterial);
                m_drawTechnique = MyMeshDrawTechnique.MESH;
            }

            InitDrawTechniques();

            InitPhysics();

            MyModels.OnContentLoaded += InitDrawTechniques;
            InitDrawTechniques();

        }
示例#5
0
        public static void Update()
        {
            //  Update only if sun wind is active
            if (IsActive == false)
            {
                return;
            }

            float darkeningPhase;
            float dt;
            int   relTime = GetDarkeningPhase(out darkeningPhase, out dt);

            if (relTime > MaxTimeMs)
            {
                Clear();
                return;
            }


            MyAudio.UpdateCuePosition(ambientSound,
                                      MyCamera.Position + MyCamera.ForwardVector * -MaxSoundDistance * (1 - darkeningPhase),
                                      MyCamera.ForwardVector, MyCamera.UpVector, Vector3.Zero);
            MyAudio.UpdateCueVolume(ambientSound, darkeningPhase * MaxAmbientVolume);

            // update smoke
            foreach (SmokeParticle part in smokeParticles)
            {
                Vector3 toCamera = (MyCamera.Position - part.Pos);
                toCamera.Normalize();
                float alpha = darkeningPhase * MaxSmokeAlpha;
                part.Color = new Vector4(alpha, alpha, alpha, alpha);
                //part.Color.W = darkeningPhase;
                part.Pos   += part.Velocity * dt + toCamera * CenterBias * dt;
                part.Angle += part.AngularVelocity * dt;
            }


            // remove old ice and sparks

            m_iceList.Clear();
            foreach (IceParticle particle in iceParticles)
            {
                if (particle.StartTime + 4000 < relTime)
                {
                    m_iceList.Add(particle);
                }
            }

            foreach (IceParticle ice in m_iceList)
            {
                ice.AsteroidEntity.MarkForClose();
                Debug.Assert(ice.TrailEffect != null, "ice.TrailEffect != null");
                ice.TrailEffect.Stop();
                ice.TrailEffect = null;
                StopCue(ice.Sound);
                iceParticles.Remove(ice);
            }

            int c = 0;

            while (c < storms.Count)
            {
                ElectricStorm storm = storms[c];
                if (storm.StartTime + 1500 < relTime)
                {
                    storms.RemoveAt(c);
                    continue;
                }
                c++;
            }



            // if its dark add new sparks and ice balls
            if (darkeningPhase >= 1)
            {
                if (storms.Count < MaxSparkCount && MyMwcUtils.GetRandomInt(SparkEveryMs) < dt * 1000.0f)
                {
                    var storm = new ElectricStorm
                    {
                        Position =
                            MyCamera.Position + MyCamera.ForwardVector * 250 +
                            MyMwcUtils.GetRandomVector3HemisphereNormalized(MyCamera.ForwardVector) *
                            MyMwcUtils.GetRandomFloat(0, 300),
                        StartTime = relTime,
                        Effect    =
                            MyParticlesManager.CreateParticleEffect(
                                (int)MyParticleEffectsIDEnum.Damage_Sparks),
                    };
                    storm.Effect.WorldMatrix = Matrix.CreateTranslation(storm.Position);
                    storm.Effect.AutoDelete  = true;
                    storm.Effect.UserScale   = 2;
                    storm.Sound = MyAudio.AddCue2D(MySoundCuesEnum.SfxSpark);
                    storms.Add(storm);
                }


                if (iceParticles.Count < MaxIceCount && MyMwcUtils.GetRandomInt(IceEveryMs) < dt * 1000.0f)
                {
                    Vector3 dir = MyMwcUtils.GetRandomVector3HemisphereNormalized(MyCamera.ForwardVector);
                    Vector3 pos = MyCamera.Position + MyCamera.ForwardVector * 250 +
                                  MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, 200) +
                                  dir * MyMwcUtils.GetRandomFloat(0, 500);
                    MyMwcObjectBuilder_StaticAsteroid rockModel =
                        MySectorGenerator.GenerateStaticAsteroid(MyMwcUtils.GetRandomFloat(0.1f, 2f),
                                                                 MyStaticAsteroidTypeSetEnum.A,
                                                                 MyMwcVoxelMaterialsEnum.Ice_01, pos, random,
                                                                 asteroidTypes);
                    Matrix matrix = Matrix.CreateFromAxisAngle(MyMwcUtils.GetRandomVector3Normalized(),
                                                               MyMwcUtils.GetRandomFloat(0, MathHelper.Pi));
                    matrix.Translation = pos;
                    MyEntity asteroid = MyEntities.CreateFromObjectBuilderAndAdd(null, rockModel, matrix);
                    asteroid.Physics.Enabled = false;
                    asteroid.CastShadows     = false;

                    MyParticleEffect effect =
                        MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_CannonShot);
                    Vector3 velocity = -dir *MyMwcUtils.GetRandomInt(150, 400);

                    iceParticles.Add(new IceParticle
                    {
                        StartTime       = relTime,
                        Position        = pos,
                        Direction       = -dir,
                        AsteroidEntity  = asteroid,
                        TrailEffect     = effect,
                        RotAxis         = MyMwcUtils.GetRandomVector3Normalized(),
                        RotAngle        = MyMwcUtils.GetRandomRadian(),
                        AngularVelocity = MyMwcUtils.GetRandomFloat(0.2f, 10f),
                        Velocity        = velocity,
                        Sound           =
                            MyAudio.AddCue3D(MySoundCuesEnum.WepSniperHighFire2d, pos, dir,
                                             dir * -dir, velocity)
                    });
                }
            }

            // update ice parts
            foreach (IceParticle particle in iceParticles)
            {
                particle.RotAngle += particle.AngularVelocity * dt;
                particle.Position += particle.Velocity * dt;
                Matrix matrix = Matrix.CreateFromAxisAngle(particle.RotAxis, particle.RotAngle);
                matrix.Translation = particle.Position;
                particle.AsteroidEntity.SetWorldMatrix(matrix);
                Matrix trans = Matrix.CreateTranslation(-particle.Direction * 10);
                particle.TrailEffect.WorldMatrix = matrix * trans;
                MyAudio.UpdateCuePosition(particle.Sound, particle.Position, particle.Direction,
                                          particle.Direction * -particle.Direction, particle.Velocity);
            }



            lastUpdateMs = MyMinerGame.TotalGamePlayTimeInMilliseconds;
        }
        private static MyMwcObjectBuilder_StaticAsteroid CloneStaticAsteroid(MyMwcObjectBuilder_StaticAsteroid source)
        {
            MyMwcObjectBuilder_StaticAsteroid clone = new MyMwcObjectBuilder_StaticAsteroid(source.AsteroidType, source.AsteroidMaterial, source.AsteroidMaterial1);
            clone.PositionAndOrientation = source.PositionAndOrientation;

            return clone;
        }
        public static MyMwcObjectBuilder_StaticAsteroid GenerateStaticAsteroid(float sizeInMeters, MyStaticAsteroidTypeSetEnum typeSet, MyMwcVoxelMaterialsEnum material, Vector3 position, Random rnd, List<MyMwcObjectBuilder_StaticAsteroid_TypesEnum> asteroids)
        {
            int size = FindAsteroidSize(sizeInMeters, MyMwcObjectBuilder_StaticAsteroid.AsteroidSizes);
            asteroids.Clear();
            MyMwcObjectBuilder_StaticAsteroid.GetAsteroids(size, typeSet, asteroids);
            int rndIndex = rnd.Next(0, asteroids.Count);
            
            var builder = new MyMwcObjectBuilder_StaticAsteroid(asteroids[rndIndex], material);
            builder.PositionAndOrientation.Position = position;
            builder.PositionAndOrientation.Forward = rnd.Vector(1);
            builder.PositionAndOrientation.Up = rnd.Vector(1);
            builder.IsDestructible = false;

            return builder;
        }
        public override void OnOkClick(MyGuiControlButton sender)
        {
            base.OnOkClick(sender);

            if (HasEntity())
            {
                if (m_changeMaterial.Checked)
                {
                    m_entity.VoxelMaterial = ((MyMwcVoxelMaterialsEnum)m_selectVoxelMapMaterialCombobox.GetSelectedKey());
                }
                
                float x,y,z;
                if (float.TryParse(m_positionX.Text, out x) && float.TryParse(m_positionY.Text, out y) && float.TryParse(m_positionZ.Text, out z))
	            {
                    m_entity.SetPosition(new Vector3(x, y, z));
	            }
            }
            else
            {
                if (GetAsteroidType() == MyGuiAsteroidTypesEnum.VOXEL)
                {
                    MyMwcObjectBuilder_SmallShip_TypesEnum shipType = (MyMwcObjectBuilder_SmallShip_TypesEnum)
                        Enum.ToObject(typeof(MyMwcObjectBuilder_SmallShip_TypesEnum), m_selectVoxelMapCombobox.GetSelectedKey());
                    MyMwcVoxelFilesEnum voxelFileEnum = (MyMwcVoxelFilesEnum)
                        Enum.ToObject(typeof(MyMwcVoxelFilesEnum), m_selectVoxelMapCombobox.GetSelectedKey());
                    MyMwcVoxelMaterialsEnum materialEnum = (MyMwcVoxelMaterialsEnum)
                        Enum.ToObject(typeof(MyMwcVoxelMaterialsEnum), m_selectVoxelMapMaterialCombobox.GetSelectedKey());

                    MyMwcObjectBuilder_VoxelMap voxelMapBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.VoxelMap, null) as MyMwcObjectBuilder_VoxelMap;
                    voxelMapBuilder.VoxelMaterial = materialEnum;
                    voxelMapBuilder.VoxelFile = voxelFileEnum;
                    MyEditor.Static.CreateFromObjectBuilder(voxelMapBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition);
                }
                else if (GetAsteroidType() == MyGuiAsteroidTypesEnum.STATIC)
                {
                    MyMwcObjectBuilder_StaticAsteroid_TypesEnum staticAsteroidType = (MyMwcObjectBuilder_StaticAsteroid_TypesEnum)
                        Enum.ToObject(typeof(MyMwcObjectBuilder_StaticAsteroid_TypesEnum), m_selectVoxelMapCombobox.GetSelectedKey());

                    MyMwcVoxelMaterialsEnum? materialEnum = null;
                    int materialKey = m_selectVoxelMapMaterialCombobox.GetSelectedKey();
                    if (materialKey != -1)
                    {
                        materialEnum = (MyMwcVoxelMaterialsEnum)Enum.ToObject(typeof(MyMwcVoxelMaterialsEnum), materialKey);
                    }

                    MyMwcObjectBuilder_StaticAsteroid staticAsteroidBuilder = new MyMwcObjectBuilder_StaticAsteroid(staticAsteroidType, materialEnum);
                    MyEditor.Static.CreateFromObjectBuilder(staticAsteroidBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition);
                }
            }

            MyGuiManager.CloseAllScreensExcept(MyGuiScreenGamePlay.Static);

        }