Пример #1
0
 private void SetGasSource(MyResourceSourceComponent characterSourceComponent)
 {
     foreach (GasData data in this.m_storedGases)
     {
         data.LastOutputTime = MySession.Static.GameplayFrameCounter;
         if (this.m_characterGasSource != null)
         {
             this.m_characterGasSource.SetRemainingCapacityByType(data.Id, 0f);
             if (Sync.IsServer)
             {
                 this.m_characterGasSource.OutputChanged -= new MyResourceOutputChangedDelegate(this.Source_CurrentOutputChanged);
             }
         }
         if (characterSourceComponent != null)
         {
             characterSourceComponent.SetRemainingCapacityByType(data.Id, data.FillLevel * data.MaxCapacity);
             characterSourceComponent.SetProductionEnabledByType(data.Id, data.FillLevel > 0f);
             if (Sync.IsServer)
             {
                 characterSourceComponent.OutputChanged += new MyResourceOutputChangedDelegate(this.Source_CurrentOutputChanged);
             }
         }
     }
     this.m_characterGasSource = characterSourceComponent;
 }
        private void SetGasSource(MyResourceSourceComponent characterSourceComponent)
        {
            foreach (var gasInfo in m_storedGases)
            {
                gasInfo.LastOutputTime = MySession.Static.GameplayFrameCounter;
                if (m_characterGasSource != null)
                {
                    m_characterGasSource.SetRemainingCapacityByType(gasInfo.Id, 0);

                    if (Sync.IsServer)
                    {
                        m_characterGasSource.OutputChanged -= Source_CurrentOutputChanged;
                    }
                }

                if (characterSourceComponent != null)
                {
                    characterSourceComponent.SetRemainingCapacityByType(gasInfo.Id, gasInfo.FillLevel * gasInfo.MaxCapacity);
                    characterSourceComponent.SetProductionEnabledByType(gasInfo.Id, gasInfo.FillLevel > 0);
                    if (Sync.IsServer)
                    {
                        characterSourceComponent.OutputChanged += Source_CurrentOutputChanged;
                    }
                }
            }
            m_characterGasSource = characterSourceComponent;
        }
Пример #3
0
        private void RefreshRemainingCapacity()
        {
            var   fuelAmount = m_inventory.GetItemAmount(m_reactorDefinition.FuelId);
            float remainingPowerCapacity;

            if (MySession.Static.CreativeMode && fuelAmount == 0)
            {
                remainingPowerCapacity = m_reactorDefinition.FuelDefinition.Mass;
            }
            else
            {
                remainingPowerCapacity = (float)fuelAmount;
            }
            SourceComp.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, remainingPowerCapacity);
            UpdateMaxOutputAndEmissivity();
        }
Пример #4
0
        private void RefreshRemainingCapacity()
        {
            if (this.GetInventory() == null)
            {
                Debug.Fail("Inventory component is missing! Can not refresh capacity.");
                return;
            }
            var fuelAmount = this.GetInventory().GetItemAmount(m_reactorDefinition.FuelId);

            if (MySession.Static.CreativeMode && fuelAmount == 0)
            {
                m_remainingPowerCapacity.Value = m_reactorDefinition.FuelDefinition.Mass;
            }
            else
            {
                m_remainingPowerCapacity.Value = (float)fuelAmount;
            }
            SourceComp.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, m_remainingPowerCapacity);
            UpdateMaxOutputAndEmissivity();
        }
Пример #5
0
        private void SetGasSource(MyResourceSourceComponent characterSourceComponent)
        {
            m_gasOutputTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            foreach (var gasInfo in m_storedGases)
            {
                if (m_characterGasSource != null)
                {
                    m_characterGasSource.SetRemainingCapacityByType(gasInfo.Id, 0);
                    m_characterGasSource.OutputChanged -= Source_CurrentOutputChanged;
                }

                if (characterSourceComponent != null)
                {
                    characterSourceComponent.SetRemainingCapacityByType(gasInfo.Id, gasInfo.FillLevel * gasInfo.MaxCapacity);
                    characterSourceComponent.SetProductionEnabledByType(gasInfo.Id, gasInfo.FillLevel > 0);
                    characterSourceComponent.OutputChanged += Source_CurrentOutputChanged;
                }
            }
            m_characterGasSource = characterSourceComponent;
        }
Пример #6
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sourceDataList = new List <MyResourceSourceInfo>();

            foreach (var producedInfo in BlockDefinition.ProducedGases)
            {
                sourceDataList.Add(new MyResourceSourceInfo
                {
                    ResourceTypeId = producedInfo.Id,
                    DefinedOutput  = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio * (MySession.Static.CreativeMode ? 10f : 1f),
                    ProductionToCapacityMultiplier = 1
                });
            }

            SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList);

            base.Init(objectBuilder, cubeGrid);

            var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator;

            InitializeConveyorEndpoint();
            m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            if (this.GetInventory() == null) // can be already initialized as deserialized component
            {
                MyInventory inventory = new MyInventory(BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive);
                inventory.Constraint = BlockDefinition.InputInventoryConstraint;
                Components.Add <MyInventoryBase>(inventory);
            }
            else
            {
                this.GetInventory().Constraint = BlockDefinition.InputInventoryConstraint;
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            m_oreConstraint = new MyInventoryConstraint(this.GetInventory().Constraint.Description, this.GetInventory().Constraint.Icon, this.GetInventory().Constraint.IsWhitelist);
            foreach (var id in this.GetInventory().Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject))
                {
                    m_oreConstraint.Add(id);
                }
            }

            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

            if (this.GetInventory() != null)
            {
                this.GetInventory().Init(generatorBuilder.Inventory);
            }
            else
            {
                Debug.Fail("Trying to init inventory, but it's null!");
            }

            AutoRefill = generatorBuilder.AutoRefill;



            SourceComp.Enabled = Enabled;
            if (Sync.IsServer)
            {
                SourceComp.OutputChanged += Source_OutputChanged;
            }
            float iceAmount = IceAmount();

            foreach (var gasId in SourceComp.ResourceTypes)
            {
                var tmpGasId = gasId;
                m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(ref tmpGasId, iceAmount));
            }

            m_lastSourceUpdate = MySession.Static.GameplayFrameCounter;

            ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo
            {
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                MaxRequiredInput  = BlockDefinition.OperationalPowerConsumption,
                RequiredInputFunc = ComputeRequiredPower
            });
            ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink.Update();

            UpdateEmissivity();
            UpdateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyGasGenerator_IsWorkingChanged;
        }