Esempio n. 1
0
        internal static void AddBillboardOriented(string material,
                                                  Color color, Vector3D origin, Vector3 leftVector, Vector3 upVector, float radius, int priority = 0, int customViewProjection = -1)
        {
            Debug.Assert(material != null);

            origin.AssertIsValid();
            leftVector.AssertIsValid();
            upVector.AssertIsValid();
            radius.AssertIsValid();
            MyDebug.AssertDebug(radius > 0);

            MyBillboard billboard = SpawnBillboard();

            if (billboard == null)
            {
                return;
            }

            billboard.Priority             = priority;
            billboard.CustomViewProjection = customViewProjection;

            MyQuadD quad;

            MyUtils.GetBillboardQuadOriented(out quad, ref origin, radius, ref leftVector, ref upVector);

            CreateBillboard(billboard, ref quad, material, ref color, ref origin);
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_BotCollectionDefinition;

            if (ob == null)
            {
                return;
            }

            MyDebug.AssertDebug(ob.Bots != null);

            List <MyDefinitionId> bots          = new List <MyDefinitionId>();
            List <float>          probabilities = new List <float>();

            for (int i = 0; i < ob.Bots.Length; i++)
            {
                var bot = ob.Bots[i];
                bots.Add(bot.Id);
                probabilities.Add(bot.Probability);
            }

            Bots = new MyDiscreteSampler <MyDefinitionId>(bots, probabilities);
        }
Esempio n. 3
0
            public virtual void Start(MatrixD position, Vector3D initialVelocity, float scale, bool randomRotation = true)
            {
                MyDebug.AssertDebug(!m_isStarted);
                m_createdTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                Container.Entity.PositionComp.Scale = RandomScale * scale;
                Container.Entity.WorldMatrix        = position;
                (Container.Entity.Physics as MyDebrisPhysics).ScalePhysicsShape(ref m_massProperties);
                Container.Entity.Physics.Clear();
                Container.Entity.Physics.LinearVelocity = initialVelocity;
                //apply random rotation impulse
                if (randomRotation)
                {
                    Container.Entity.Physics.AngularVelocity = new Vector3(MyUtils.GetRandomRadian(),
                                                                           MyUtils.GetRandomRadian(),
                                                                           MyUtils.GetRandomRadian());
                }
                MyEntities.Add(m_entity);
                Container.Entity.Physics.Enabled = true;
                float    simulationRatio = Sync.IsServer ? 1.0f : Sync.RelativeSimulationRatio * Sync.RelativeSimulationRatio;
                Vector3D gravity         = simulationRatio * MyGravityProviderSystem.CalculateNaturalGravityInPoint(position.Translation);

                ((MyPhysicsBody)Container.Entity.Physics).RigidBody.Gravity = gravity;
                (Container.Entity.Physics as MyPhysicsBody).HavokWorld.ActiveRigidBodies.Add((Container.Entity.Physics as MyPhysicsBody).RigidBody);
                m_isStarted = true;
            }
 private void VerifyInputItemType(MyObjectBuilderType inputType)
 {
     foreach (var item in Prerequisites)
     {
         MyDebug.AssertDebug(inputType == item.Id.TypeId, "Not all input objects are of same type. Is this on purpose?");
     }
 }
Esempio n. 5
0
        public void CreateDirectedDebris(Vector3 sourceWorldPosition,
                                         Vector3 offsetDirection,
                                         float minSourceDistance,
                                         float maxSourceDistance,
                                         float minDeviationAngle,
                                         float maxDeviationAngle,
                                         int debrisPieces,
                                         float scale,
                                         float initialSpeed)
        {
            MyDebug.AssertDebug(debrisPieces > 0);
            for (int i = 0; i < debrisPieces; ++i)
            {
                var newObj = CreateRandomDebris();
                if (newObj == null)
                {
                    break; // no point in continuing
                }

                float dist            = MyUtils.GetRandomFloat(minSourceDistance, maxSourceDistance);
                float angleX          = MyUtils.GetRandomFloat(minDeviationAngle, maxDeviationAngle);
                float angleY          = MyUtils.GetRandomFloat(minDeviationAngle, maxDeviationAngle);
                var   rotation        = Matrix.CreateRotationX(angleX) * Matrix.CreateRotationY(angleY);
                var   deviatedDir     = Vector3.Transform(offsetDirection, rotation);
                var   startPos        = sourceWorldPosition + deviatedDir * dist;
                var   initialVelocity = deviatedDir * initialSpeed;
                newObj.Debris.Start(startPos, initialVelocity, scale);
            }
        }
Esempio n. 6
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            MyDebug.AssertDebug(BlockDefinition is MyRefineryDefinition);
            m_refineryDef = BlockDefinition as MyRefineryDefinition;

            InputInventory.Constraint = m_refineryDef.InputInventoryConstraint;
            bool removed = InputInventory.FilterItemsUsingConstraint();

            Debug.Assert(!removed, "Inventory filter removed items which were present in the object builder.");
            InputInventory.ContentsChanged += inventory_OnContentsChanged;

            OutputInventory.Constraint = m_refineryDef.OutputInventoryConstraint;
            removed = OutputInventory.FilterItemsUsingConstraint();
            Debug.Assert(!removed, "Inventory filter removed items which were present in the object builder.");
            OutputInventory.ContentsChanged += inventory_OnContentsChanged;

            m_queueNeedsRebuild = true;

            UpgradeValues.Add("Productivity", 0f);
            UpgradeValues.Add("Effectiveness", 1f);
            UpgradeValues.Add("PowerEfficiency", 1f);

            PowerReceiver.RequiredInputChanged += PowerReceiver_RequiredInputChanged;
            OnUpgradeValuesChanged             += UpdateDetailedInfo;

            UpdateDetailedInfo();
        }
 public MyProjectorClipboard(MyProjector projector)
     : base(MyPerGameSettings.PastingSettings)
 {
     MyDebug.AssertDebug(projector != null);
     m_projector         = projector;
     m_calculateVelocity = false;
 }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var ob = builder as MyObjectBuilder_VoxelHandDefinition;

            MyDebug.AssertDebug(ob != null);
        }
        internal static void AddBillboardOriented(string material,
                                                  Color color, Vector3D origin, Vector3 leftVector, Vector3 upVector, float radius, int priority = 0, float softParticleDistanceScale = 1.0f,
                                                  int customViewProjection = -1)
        {
            if (!MyRender11.DebugOverrides.BillboardsDynamic)
            {
                return;
            }

            Debug.Assert(material != null);

            origin.AssertIsValid();
            leftVector.AssertIsValid();
            upVector.AssertIsValid();
            radius.AssertIsValid();
            MyDebug.AssertDebug(radius > 0);

            MyBillboard billboard = MyBillboardRenderer.AddBillboardOnce();

            if (billboard == null)
            {
                return;
            }

            billboard.Priority             = priority;
            billboard.CustomViewProjection = customViewProjection;

            MyQuadD quad;

            MyUtils.GetBillboardQuadOriented(out quad, ref origin, radius, ref leftVector, ref upVector);

            CreateBillboard(billboard, ref quad, material, ref color, ref origin, softParticleDistanceScale);
        }
Esempio n. 10
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            MyDebug.AssertDebug(builder is MyObjectBuilder_ProductionBlockDefinition);
            var obDefinition = builder as MyObjectBuilder_ProductionBlockDefinition;

            this.InventoryMaxVolume          = obDefinition.InventoryMaxVolume;
            this.InventorySize               = obDefinition.InventorySize;
            this.StandbyPowerConsumption     = obDefinition.StandbyPowerConsumption;
            this.OperationalPowerConsumption = obDefinition.OperationalPowerConsumption;

            System.Diagnostics.Debug.Assert(obDefinition.BlueprintClasses != null, "Production block has no blueprint classes specified");
            if (obDefinition.BlueprintClasses == null)
            {
                InitializeLegacyBlueprintClasses(obDefinition);
            }

            BlueprintClasses = new List <MyBlueprintClassDefinition>();
            for (int i = 0; i < obDefinition.BlueprintClasses.Length; ++i)
            {
                var className = obDefinition.BlueprintClasses[i];
                var classDef  = MyDefinitionManager.Static.GetBlueprintClass(className);
                System.Diagnostics.Debug.Assert(classDef != null, "Production block references non-existent blueprint class");
                if (classDef == null)
                {
                    continue;
                }

                BlueprintClasses.Add(classDef);
            }
        }
Esempio n. 11
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_WeaponDefinition;

            MyDebug.AssertDebug(ob != null);

            this.WeaponAmmoDatas      = new MyWeaponAmmoData[Enum.GetValues(typeof(MyAmmoType)).Length];
            this.NoAmmoSound          = new MySoundPair(ob.NoAmmoSoundName);
            this.ReloadSound          = new MySoundPair(ob.ReloadSoundName);
            this.DeviateShotAngle     = MathHelper.ToRadians(ob.DeviateShotAngle);
            this.ReleaseTimeAfterFire = ob.ReleaseTimeAfterFire;
            this.MuzzleFlashLifeSpan  = ob.MuzzleFlashLifeSpan;

            this.AmmoMagazinesId = new MyDefinitionId[ob.AmmoMagazines.Length];
            for (int i = 0; i < this.AmmoMagazinesId.Length; i++)
            {
                var ammoMagazine = ob.AmmoMagazines[i];
                this.AmmoMagazinesId[i] = new MyDefinitionId(ammoMagazine.Type, ammoMagazine.Subtype);

                var        ammoMagazineDefinition = MyDefinitionManager.Static.GetAmmoMagazineDefinition(this.AmmoMagazinesId[i]);
                MyAmmoType ammoType     = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagazineDefinition.AmmoDefinitionId).AmmoType;
                string     errorMessage = null;
                switch (ammoType)
                {
                case MyAmmoType.HighSpeed:
                    MyDebug.AssertDebug(ob.ProjectileAmmoData != null, "No weapon ammo data specified for projectile ammo");
                    if (ob.ProjectileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[(int)MyAmmoType.HighSpeed] = new MyWeaponAmmoData(ob.ProjectileAmmoData);
                    }
                    else
                    {
                        errorMessage = string.Format(ErrorMessageTemplate, "projectile", "Projectile");
                    }
                    break;

                case MyAmmoType.Missile:
                    MyDebug.AssertDebug(ob.MissileAmmoData != null, "No weapon ammo data specified for missile ammo");
                    if (ob.MissileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[(int)MyAmmoType.Missile] = new MyWeaponAmmoData(ob.MissileAmmoData);
                    }
                    else
                    {
                        errorMessage = string.Format(ErrorMessageTemplate, "missile", "Missile");
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    MyDefinitionErrors.Add(Context, errorMessage, ErrorSeverity.Critical);
                }
            }
        }
Esempio n. 12
0
        public void SetAsCurrent(MyCameraBlock newCamera)
        {
            MyDebug.AssertDebug(newCamera != null);

            if (m_currentCamera == newCamera)
            {
                return;
            }

            if (newCamera.BlockDefinition.OverlayTexture != null)
            {
                MyHudCameraOverlay.TextureName = newCamera.BlockDefinition.OverlayTexture;
                MyHudCameraOverlay.Enabled = true;
            }
            else
            {
                MyHudCameraOverlay.Enabled = false;
            }

            //By Gregory: Temporary fix cause Session component for antenna system hasn't been called yet and Static isn't assigned yet at game load(see BeforeStart function).
            string shipName = "";
            if (MyAntennaSystem.Static != null)
            {
                shipName = MyAntennaSystem.Static.GetLogicalGroupRepresentative(m_grid).DisplayName ?? "";
            }
            string cameraName = newCamera.DisplayNameText;

            MyHud.CameraInfo.Enable(shipName, cameraName);
            m_currentCamera = newCamera;
            m_ignoreNextInput = true;

            MySessionComponentVoxelHand.Static.Enabled = false;
            MyCubeBuilder.Static.Deactivate();
        }
Esempio n. 13
0
        public void Register(MyCameraBlock camera)
        {
            MyDebug.AssertDebug(camera != null);
            MyDebug.AssertDebug(!m_cameras.Contains(camera));

            m_cameras.Add(camera);
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_MultiBlockDefinition;

            MyDebug.AssertDebug(ob != null);

            if (ob.BlockDefinitions != null && ob.BlockDefinitions.Length > 0)
            {
                MinPosition = Vector3I.MaxValue;
                MaxPosition = Vector3I.MinValue;

                BlockDefinitions = new MyMultiBlockPartDefinition[ob.BlockDefinitions.Length];
                for (int i = 0; i < ob.BlockDefinitions.Length; ++i)
                {
                    BlockDefinitions[i] = new MyMultiBlockPartDefinition();

                    var obBlockDef = ob.BlockDefinitions[i];
                    BlockDefinitions[i].Id       = obBlockDef.Id;
                    BlockDefinitions[i].Position = obBlockDef.Position;
                    BlockDefinitions[i].Forward  = obBlockDef.Orientation.Forward;
                    BlockDefinitions[i].Up       = obBlockDef.Orientation.Up;

                    MinPosition = Vector3I.Min(MinPosition, obBlockDef.Position);
                    MaxPosition = Vector3I.Max(MaxPosition, obBlockDef.Position);
                }
            }
        }
        public void ChangeProducersState(MyMultipleEnabledEnum state, long playerId)
        {
            MyDebug.AssertDebug(state != MyMultipleEnabledEnum.Mixed, "You must NOT use this property to set mixed state.");
            MyDebug.AssertDebug(state != MyMultipleEnabledEnum.NoObjects, "You must NOT use this property to set state without any objects.");
            // You cannot change the state when there are no objects.
            if (ProducersEnabled != state && ProducersEnabled != MyMultipleEnabledEnum.NoObjects)
            {
                m_producersEnabled = state;
                bool enabled = (state == MyMultipleEnabledEnum.AllEnabled);
                foreach (var group in m_producersByPriority)
                {
                    foreach (var producer in group)
                    {
                        if (producer.HasPlayerAccess(playerId))
                        {
                            producer.MaxPowerOutputChanged -= producer_MaxPowerOutputChanged;
                            producer.Enabled = enabled;
                            producer.MaxPowerOutputChanged += producer_MaxPowerOutputChanged;
                        }
                    }
                }

                // recomputing power distribution here caused problems with
                // connecting to ship connector. The bug caused immediate disconnect
                // in only special cases.

                //RecomputePowerDistribution();
                m_producersEnabledDirty = false;
                m_needsRecompute        = true;
                m_allEnabledCounter     = 0;
            }
        }
Esempio n. 16
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            MyDebug.AssertDebug(BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Reactor));
            m_reactorDefinition = BlockDefinition as MyReactorDefinition;
            MyDebug.AssertDebug(m_reactorDefinition != null);

            CurrentPowerOutput = 0;
            m_inventory        = new MyInventory(m_reactorDefinition.InventoryMaxVolume, m_reactorDefinition.InventorySize, MyInventoryFlags.CanReceive, this);

            var obGenerator = (MyObjectBuilder_Reactor)objectBuilder;

            m_inventory.Init(obGenerator.Inventory);
            m_inventory.ContentsChanged += inventory_ContentsChanged;
            m_inventory.Constraint       = m_reactorDefinition.InventoryConstraint;
            RefreshRemainingCapacity();

            UpdateText();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
            //if (MyFakes.SHOW_DAMAGE_EFFECTS && IsWorking)
            //    NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;

            m_baseIdleSound = BlockDefinition.PrimarySound;

            m_useConveyorSystem = obGenerator.UseConveyorSystem;

            if (IsWorking)
            {
                OnStartWorking();
            }
        }
        private void Receiver_RequiredInputChanged(MyPowerReceiver changedConsumer, float oldRequirement, float newRequirement)
        {
            if (m_needsRecompute)
            {
                RecomputePowerDistribution();
            }

            // Go over all priorities, starting from the changedConsumer.
            int idx = (int)changedConsumer.Group;

            MyDebug.AssertDebug(m_consumerDataByPriority[idx].RequiredInput >= 0.0f);
            m_consumerDataByPriority[idx].RequiredInput = 0.0f;
            foreach (var consumer in m_consumersByPriority[idx])
            {
                m_consumerDataByPriority[idx].RequiredInput += consumer.PowerReceiver.RequiredInput;
            }

            // Update cumulative requirements.
            float cumulative = (idx != 0) ? m_consumerDataByPriority[idx - 1].RequiredInputCumulative
                                          : 0.0f;

            for (int i = idx; i < m_consumerDataByPriority.Length; ++i)
            {
                cumulative += m_consumerDataByPriority[i].RequiredInput;
                m_consumerDataByPriority[i].RequiredInputCumulative = cumulative;
            }

            RecomputePowerDistributionPartial(idx, m_consumerDataByPriority[idx].AvailablePower);
            MyDebug.AssertDebug(m_consumerDataByPriority[idx].RequiredInput >= 0.0f);
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var materialBuilder = builder as MyObjectBuilder_TransparentMaterialDefinition;

            MyDebug.AssertDebug(materialBuilder != null, "Initializing transparent material definition using wrong object builder.");

            Texture                   = materialBuilder.Texture;
            TextureType               = materialBuilder.TextureType;
            CanBeAffectedByLights     = materialBuilder.CanBeAffectedByOtherLights;
            AlphaMistingEnable        = materialBuilder.AlphaMistingEnable;
            IgnoreDepth               = materialBuilder.IgnoreDepth;
            NeedSort                  = materialBuilder.NeedSort;
            UseAtlas                  = materialBuilder.UseAtlas;
            AlphaMistingStart         = materialBuilder.AlphaMistingStart;
            AlphaMistingEnd           = materialBuilder.AlphaMistingEnd;
            SoftParticleDistanceScale = materialBuilder.SoftParticleDistanceScale;
            Emissivity                = materialBuilder.Emissivity;
            AlphaSaturation           = materialBuilder.AlphaSaturation;
            Reflection                = materialBuilder.Reflection;
            Reflectivity              = materialBuilder.Reflectivity;
            Color       = materialBuilder.Color;
            AlphaCutout = materialBuilder.AlphaCutout;
            TargetSize  = materialBuilder.TargetSize;
        }
Esempio n. 19
0
 private void UpdateNormalizedValue()
 {
     MyDebug.AssertDebug(m_minValue < m_maxValue);
     MyDebug.AssertDebug(m_value >= m_minValue);
     MyDebug.AssertDebug(m_value <= m_maxValue);
     ValueNormalized = (m_value - m_minValue) / (m_maxValue - m_minValue);
 }
Esempio n. 20
0
        public void CreateDirectedDebris(Vector3 sourceWorldPosition,
                                         Vector3 offsetDirection,
                                         float minSourceDistance,
                                         float maxSourceDistance,
                                         float minDeviationAngle,
                                         float maxDeviationAngle,
                                         int debrisPieces,
                                         float initialSpeed,
                                         float scale,
                                         MyVoxelMaterialDefinition material)
        {
            ProfilerShort.Begin("Create directed debris");
            MyDebug.AssertDebug(debrisPieces > 0);
            for (int i = 0; i < debrisPieces; ++i)
            {
                var newObj = CreateVoxelDebris();
                if (newObj == null)
                {
                    break; // no point in continuing
                }

                float dist            = MyUtils.GetRandomFloat(minSourceDistance, maxSourceDistance);
                float angleX          = MyUtils.GetRandomFloat(minDeviationAngle, maxDeviationAngle);
                float angleY          = MyUtils.GetRandomFloat(minDeviationAngle, maxDeviationAngle);
                var   rotation        = Matrix.CreateRotationX(angleX) * Matrix.CreateRotationY(angleY);
                var   deviatedDir     = Vector3.Transform(offsetDirection, rotation);
                var   startPos        = sourceWorldPosition + deviatedDir * dist;
                var   initialVelocity = deviatedDir * initialSpeed;
                (newObj.Debris as MyDebrisVoxel.MyDebrisVoxelLogic).Start(startPos, initialVelocity, scale, material);
            }
            ProfilerShort.End();
        }
Esempio n. 21
0
 public MyProjectorClipboard(MyProjectorBase projector, MyPlacementSettings settings)
     : base(settings) //Pasting Settings here ?
 {
     MyDebug.AssertDebug(projector != null);
     m_projector         = projector;
     m_calculateVelocity = false;
 }
Esempio n. 22
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_AnimationDefinition;

            MyDebug.AssertDebug(ob != null);

            this.AnimationModel    = ob.AnimationModel;
            this.AnimationModelFPS = ob.AnimationModelFPS;

            this.ClipIndex       = ob.ClipIndex;
            this.InfluenceArea   = ob.InfluenceArea;
            this.AllowInCockpit  = ob.AllowInCockpit;
            this.AllowWithWeapon = ob.AllowWithWeapon;
            if (!string.IsNullOrEmpty(ob.SupportedSkeletons))
            {
                SupportedSkeletons = ob.SupportedSkeletons.Split(' ');
            }
            this.Loop = ob.Loop;
            if (!ob.LeftHandItem.TypeId.IsNull)
            {
                this.LeftHandItem = ob.LeftHandItem;
            }
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_EnvironmentItemsDefinition;

            MyDebug.AssertDebug(ob != null);

            m_itemDefinitions = new HashSet <MyStringHash>(MyStringHash.Comparer);
            m_definitionList  = new List <MyStringHash>();

            System.Type classType = builder.Id.TypeId;
            var         attribs   = classType.GetCustomAttributes(typeof(MyEnvironmentItemsAttribute), inherit: false);

            Debug.Assert(attribs.Length <= 1, "Environment item class can only have one EnvironmentItemDefinition attribute!");
            if (attribs.Length == 1)
            {
                var attrib = attribs[0] as MyEnvironmentItemsAttribute;
                m_itemDefinitionType = attrib.ItemDefinitionType;
            }
            else
            {
                m_itemDefinitionType = typeof(MyObjectBuilder_EnvironmentItemDefinition);
            }

            Channel         = ob.Channel;
            MaxViewDistance = ob.MaxViewDistance;
            SectorSize      = ob.SectorSize;
            ItemSize        = ob.ItemSize;
            Material        = MyStringHash.GetOrCompute(ob.PhysicalMaterial);

            Frequencies = new List <float>();
        }
Esempio n. 24
0
        protected override void Init(MyObjectBuilder_DefinitionBase ob)
        {
            base.Init(ob);

            var builder = ob as MyObjectBuilder_VoxelMaterialDefinition;

            MyDebug.AssertDebug(builder != null);

            MaterialTypeName     = builder.MaterialTypeName;
            MinedOre             = builder.MinedOre;
            MinedOreRatio        = builder.MinedOreRatio;
            CanBeHarvested       = builder.CanBeHarvested;
            IsRare               = builder.IsRare;
            SpawnsInAsteroids    = builder.SpawnsInAsteroids;
            SpawnsFromMeteorites = builder.SpawnsFromMeteorites;
            DamageRatio          = builder.DamageRatio;
            DiffuseXZ            = builder.DiffuseXZ;
            DiffuseY             = builder.DiffuseY;
            NormalXZ             = builder.NormalXZ;
            NormalY              = builder.NormalY;
            SpecularPower        = builder.SpecularPower;
            SpecularShininess    = builder.SpecularShininess;
            MinVersion           = builder.MinVersion;
            if (!string.IsNullOrEmpty(builder.ParticleEffect))
            {
                ParticleEffect = (MyParticleEffectsIDEnum)Enum.Parse(typeof(MyParticleEffectsIDEnum), builder.ParticleEffect);
            }
            else
            {
                ParticleEffect = MyParticleEffectsIDEnum.None;
            }
            DamageThreshold = (int)(builder.DamageThreashold * 255);
            DamagedMaterial = MyStringHash.GetOrCompute(builder.DamagedMaterial);
        }
        //  Add billboard for one frame only. This billboard isn't particle (it doesn't survive this frame, doesn't have update/draw methods, etc).
        //  This billboard isn't facing the camera. It's always oriented in specified direction. May be used as thrusts, or inner light of reflector.
        //  It's used by other classes when they want to draw some billboard (e.g. rocket thrusts, reflector glare).
        public static void AddBillboardOriented(string material,
                                                Vector4 color, Vector3D origin, Vector3 leftVector, Vector3 upVector, float radius, int priority = 0, bool colorize = false, int customViewProjection = -1, float reflection = 0)
        {
            Debug.Assert(material != null);
            if (!IsEnabled)
            {
                return;
            }

            MyUtils.AssertIsValid(origin);
            MyUtils.AssertIsValid(leftVector);
            MyUtils.AssertIsValid(upVector);
            MyUtils.AssertIsValid(radius);
            MyDebug.AssertDebug(radius > 0);

            //VRageRender.MyBillboard billboard = new VRageRender.MyBillboard();// m_preallocatedBillboards.Allocate();
            VRageRender.MyBillboard billboard = VRageRender.MyRenderProxy.BillboardsPoolWrite.Allocate();
            if (billboard == null)
            {
                return;
            }

            billboard.Priority = priority;

            MyQuadD quad;

            MyUtils.GetBillboardQuadOriented(out quad, ref origin, radius, ref leftVector, ref upVector);

            CreateBillboard(billboard, ref quad, material, ref color, ref origin, colorize, false, false, customViewProjection, reflection);

            VRageRender.MyRenderProxy.AddBillboard(billboard);
        }
Esempio n. 26
0
        public void Init(MyObjectBuilder_GunBase objectBuilder, MyDefinitionId weaponDefinitionId, IMyGunBaseUser gunBaseUser)
        {
            m_user             = gunBaseUser;
            m_weaponProperties = new MyWeaponPropertiesWrapper(weaponDefinitionId);
            //MyDebug.AssertDebug(m_weaponProperties.AmmoMagazinesCount > 0, "Weapon definition has no ammo magazines attached.");

            // object builder area - Start
            m_remainingAmmos = new Dictionary <MyDefinitionId, int>(WeaponProperties.AmmoMagazinesCount);
            if (objectBuilder != null)
            {
                MyDefinitionId ammoMagazineDef = new MyDefinitionId(typeof(MyObjectBuilder_AmmoMagazine), objectBuilder.CurrentAmmoMagazineName);
                if (m_weaponProperties.CanChangeAmmoMagazine(ammoMagazineDef))
                {
                    CurrentAmmo = objectBuilder.RemainingAmmo;
                    m_weaponProperties.ChangeAmmoMagazine(ammoMagazineDef);
                }
                else
                {
                    if (WeaponProperties.WeaponDefinition.HasAmmoMagazines())
                    {
                        m_weaponProperties.ChangeAmmoMagazine(m_weaponProperties.WeaponDefinition.AmmoMagazinesId[0]);
                    }
                }

                foreach (var remainingAmmo in objectBuilder.RemainingAmmosList)
                {
                    m_remainingAmmos.Add(new MyDefinitionId(typeof(MyObjectBuilder_AmmoMagazine), remainingAmmo.SubtypeName), remainingAmmo.Amount);
                }

                LastShootTime = new DateTime(objectBuilder.LastShootTime);
            }
            else
            {
                if (WeaponProperties.WeaponDefinition.HasAmmoMagazines())
                {
                    m_weaponProperties.ChangeAmmoMagazine(m_weaponProperties.WeaponDefinition.AmmoMagazinesId[0]);
                }

                LastShootTime = new DateTime(0);
            }
            // object builder area - END

            if (m_user.AmmoInventory != null)
            {
                if (m_user.PutConstraint())
                {
                    MyDebug.AssertDebug(!String.IsNullOrEmpty(m_user.ConstraintDisplayName), "Display name of weapon is empty.");
                    m_user.AmmoInventory.Constraint = CreateAmmoInventoryConstraints(m_user.ConstraintDisplayName);
                }

                RefreshAmmunitionAmount();
            }

            if (m_user.Weapon != null)
            {
                m_user.Weapon.OnClosing        += Weapon_OnClosing;
                MySyncGunBase.AmmoCountChanged += MySyncGunBase_AmmoCountChanged;
            }
        }
Esempio n. 27
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_EnvironmentItemDefinition;

            MyDebug.AssertDebug(ob != null);
        }
Esempio n. 28
0
        void Assert()
        {
            //  If you forget to set default or pre-selected item, you must do it! It won't be assigned automaticaly!
            MyDebug.AssertDebug(m_selected != null);

            //  Combobox can't be empty!
            MyDebug.AssertDebug(m_items.Count > 0);
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            MyDebug.AssertDebug(builder is MyObjectBuilder_AssemblerDefinition);
            var obRefineryDef = builder as MyObjectBuilder_AssemblerDefinition;

            m_assemblySpeed = obRefineryDef.AssemblySpeed;
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_HandDrillDefinition;

            MyDebug.AssertDebug(ob != null);
            HarvestRatioMultiplier = ob.HarvestRatioMultiplier;
        }