Пример #1
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            SyncObject = new MySyncBatteryBlock(this);

            MyDebug.AssertDebug(BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_BatteryBlock));
            m_batteryBlockDefinition = BlockDefinition as MyBatteryBlockDefinition;
            MyDebug.AssertDebug(m_batteryBlockDefinition != null);

            var sourceDataList = new List <MyResourceSourceInfo>
            {
                new MyResourceSourceInfo {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = m_batteryBlockDefinition.MaxPowerOutput, ProductionToCapacityMultiplier = 60 * 60
                }
            };

            SourceComp.Init(m_batteryBlockDefinition.ResourceSourceGroup, sourceDataList);
            SourceComp.HasCapacityRemainingChanged += (id, source) => UpdateIsWorking();

            MaxStoredPower = m_batteryBlockDefinition.MaxStoredPower;

            ResourceSink.Init(
                m_batteryBlockDefinition.ResourceSinkGroup,
                m_batteryBlockDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional && !SourceComp.ProductionEnabled && !m_isFull) ? ResourceSink.MaxRequiredInput : 0.0f);
            ResourceSink.Update();

            var obGenerator = (MyObjectBuilder_BatteryBlock)objectBuilder;

            CurrentStoredPower = obGenerator.CurrentStoredPower;
            SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, obGenerator.ProducerEnabled);
            SemiautoEnabled = obGenerator.SemiautoEnabled;

            UpdateMaxOutputAndEmissivity();

            UpdateText();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            this.IsWorkingChanged += MyBatteryBlock_IsWorkingChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            if (IsWorking)
            {
                OnStartWorking();
            }
        }
Пример #2
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;
        }
Пример #4
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();
            if (CubeGrid.Physics == null)
            {
                return;
            }

            float maxPowerOutput = SolarComponent.MaxOutput * SolarPanelDefinition.MaxPowerOutput;

            SourceComp.SetMaxOutput(maxPowerOutput);
            SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, maxPowerOutput > 0f);
            UpdateDisplay();

            RaisePropertiesChanged();
        }
Пример #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 UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();
            m_soundEmitter.Update();
            if (CubeGrid.Physics == null)
            {
                return;
            }

            float maxPowerOutput = SolarComponent.MaxOutput * SolarPanelDefinition.MaxPowerOutput;

            if (maxPowerOutput != SourceComp.MaxOutput)
            {
                float oldPowerOutput = SourceComp.MaxOutput;
                SourceComp.SetMaxOutput(maxPowerOutput);
                if (oldPowerOutput != maxPowerOutput)
                {
                    SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, maxPowerOutput != 0f);
                    UpdateDisplay();
                }
            }
        }