Example #1
0
        internal void ChangeFilledRatio(float newFilledRatio, bool updateSync = false)
        {
            m_nextGasTransfer = 0f;
            float oldFilledRatio = FilledRatio;

            if (oldFilledRatio != newFilledRatio || MySession.Static.CreativeMode)
            {
                if (!MySession.Static.CreativeMode || newFilledRatio > oldFilledRatio)
                {
                    if (updateSync)
                    {
                        this.ChangeFillRatioAmount(newFilledRatio);
                    }

                    FilledRatio = newFilledRatio;
                }

                if (MySession.Static.CreativeMode)
                {
                    SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, Capacity);
                }
                else
                {
                    SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, FilledRatio * Capacity);
                }

                ResourceSink.Update();
                UpdateEmissivity();
                UdpateText();
            }
        }
        private void SetStockpilingState(bool newState)
        {
            m_isStockpiling = newState;

            SourceComp.SetProductionEnabledByType(BlockDefinition.StoredGasId, !m_isStockpiling && CanStore);
            ResourceSink.Update();
        }
Example #3
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_AirVent)objectBuilder;

            InitializeConveyorEndpoint();
            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            SourceComp.Init(BlockDefinition.ResourceSourceGroup, new MyResourceSourceInfo {
                ResourceTypeId = m_oxygenGasId, DefinedOutput = BlockDefinition.VentilationCapacityPerSecond, ProductionToCapacityMultiplier = 1
            });
            SourceComp.OutputChanged += Source_OutputChanged;
            var sinkDataList = new List <MyResourceSinkInfo>
            {
                new MyResourceSinkInfo {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower
                },
                new MyResourceSinkInfo {
                    ResourceTypeId = m_oxygenGasId, MaxRequiredInput = BlockDefinition.VentilationCapacityPerSecond, RequiredInputFunc = () => VentingCapacity(1f)
                },
            };

            ResourceSink.Init(
                BlockDefinition.ResourceSinkGroup,
                sinkDataList);
            ResourceSink.IsPoweredChanged    += PowerReceiver_IsPoweredChanged;
            ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged;

            m_updateCounter        = 0;
            m_lastOutputUpdateTime = m_updateCounter;
            m_lastInputUpdateTime  = m_updateCounter;
            m_nextGasTransfer      = 0f;

            m_actionToolbar             = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1);
            m_actionToolbar.DrawNumbers = false;
            m_actionToolbar.Init(null, this);

            if (builder.OnFullAction != null)
            {
                m_onFullAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnFullAction);
            }

            if (builder.OnEmptyAction != null)
            {
                m_onEmptyAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnEmptyAction);
            }

            UpdateEmissivity();
            UdpateTexts();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyAirVent_IsWorkingChanged;

            SetDepressurizing(builder.IsDepressurizing);
        }
Example #4
0
        void VentToRoom(float amount)
        {
            if (amount == 0f || IsDepressurizing)
            {
                return;
            }

            Debug.Assert(!IsDepressurizing, "Vent asked to vent when it is supposed to depressurize");
            Debug.Assert(amount >= 0f);

            var oxygenBlock = GetOxygenBlock();

            if (oxygenBlock.Room == null || !oxygenBlock.Room.IsPressurized)
            {
                return;
            }

            oxygenBlock.Room.OxygenAmount += amount;
            if (oxygenBlock.Room.OxygenLevel(CubeGrid.GridSize) > 1f)
            {
                oxygenBlock.Room.OxygenAmount = oxygenBlock.Room.MaxOxygen(CubeGrid.GridSize);
            }

            SourceComp.SetRemainingCapacityByType(m_oxygenGasId, (float)oxygenBlock.Room.OxygenAmount);

            m_nextGasTransfer = 0;

            if (amount > 0)
            {
                m_producedSinceLastUpdate = true;
            }
        }
Example #5
0
        private float GasOutputPerSecond(ref MyDefinitionId gasId)
        {
            var currentOutput = SourceComp.CurrentOutputByType(gasId) * (this as IMyOxygenGenerator).ProductionCapacityMultiplier;

            Debug.Assert(SourceComp.ProductionEnabledByType(gasId) || currentOutput <= 0f, "Gas generator has output when production is disabled!");
            return(currentOutput);
        }
Example #6
0
        private void SetDepressurizing(bool newValue)
        {
            m_isDepressurizing = newValue;

            SourceComp.SetProductionEnabledByType(m_oxygenGasId, newValue);
            ResourceSink.Update();
        }
Example #7
0
        private void ConsumePower(float timeDeltaMs, float output)
        {
            if (!SourceComp.HasCapacityRemainingByType(MyResourceDistributorComponent.ElectricityId))
            {
                return;
            }

            float consumptionPerMillisecond = output / (SourceComp.ProductionToCapacityMultiplier * 1000f);
            float consumedPower             = timeDeltaMs * consumptionPerMillisecond;

            if (consumedPower == 0)
            {
                return;
            }

            if ((CurrentStoredPower - consumedPower) <= 0)
            {
                SourceComp.SetOutput(0);
                CurrentStoredPower = 0;
                TimeRemaining      = 0;
            }
            else
            {
                CurrentStoredPower -= consumedPower;
                if (m_isFull)
                {
                    m_isFull.Value = false;
                }
            }
            m_storedPower.Value = CurrentStoredPower;
        }
Example #8
0
        private float Sink_ComputeRequiredPower()
        {
            bool  canRecharge    = Enabled && IsFunctional && !m_isFull;
            bool  shouldRecharge = OnlyRecharge || !OnlyDischarge;
            float inputToFillInUpdateInterval = (MaxStoredPower - CurrentStoredPower) * VRage.Game.MyEngineConstants.UPDATE_STEPS_PER_SECOND / m_productionUpdateInterval * SourceComp.ProductionToCapacityMultiplierByType(MyResourceDistributorComponent.ElectricityId);
            float currentOutput = SourceComp.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId);

            return(canRecharge && shouldRecharge?Math.Min(inputToFillInUpdateInterval + currentOutput, ResourceSink.MaxRequiredInputByType(MyResourceDistributorComponent.ElectricityId)) : 0.0f);
        }
Example #9
0
        private float ComputeRequiredPower()
        {
            if (!MySession.Static.Settings.EnableOxygen && BlockDefinition.StoredGasId == m_oxygenGasId || !Enabled || !IsFunctional)
            {
                return(0f);
            }

            return((SourceComp.CurrentOutputByType(BlockDefinition.StoredGasId) > 0 || ResourceSink.CurrentInputByType(BlockDefinition.StoredGasId) > 0)
                    ? BlockDefinition.OperationalPowerConsumption : BlockDefinition.StandbyPowerConsumption);
        }
Example #10
0
        private float ComputeRequiredGas()
        {
            if (!CanStore)
            {
                return(0f);
            }

            float neededRatioToFillInUpdateInterval = (1 - FilledRatio) * MyEngineConstants.UPDATE_STEPS_PER_SECOND / m_updateInterval * SourceComp.ProductionToCapacityMultiplierByType(BlockDefinition.StoredGasId);
            float currentOutput = SourceComp.CurrentOutputByType(BlockDefinition.StoredGasId);

            return(Math.Min(neededRatioToFillInUpdateInterval * Capacity + currentOutput, m_maxFillPerSecond * Capacity));
        }
Example #11
0
        private bool CheckTransfer(float testTransfer)
        {
            if (testTransfer == 0f)
            {
                return(false);
            }

            float remainingCapacity    = SourceComp.RemainingCapacityByType(BlockDefinition.StoredGasId);
            float nextCapacity         = remainingCapacity + testTransfer;
            float gasTransferPerUpdate = GasInputPerUpdate - GasOutputPerUpdate;

            return(nextCapacity + gasTransferPerUpdate * 10 <= 0f || nextCapacity + gasTransferPerUpdate * 10 >= Capacity);
        }
Example #12
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (Sync.IsServer && IsWorking)
            {
                UpdateActions();
            }

            if (m_playVentEffect == false)
            {
                if (m_effect != null)
                {
                    m_effect.Stop();
                    m_effect = null;
                }
            }

            m_isProducing             = m_producedSinceLastUpdate;
            m_producedSinceLastUpdate = false;
            m_playVentEffect          = false;
            var block = GetOxygenBlock();

            int sourceUpdateFrames = (MySession.Static.GameplayFrameCounter - m_lastOutputUpdateTime);
            int sinkUpdateFrames   = (MySession.Static.GameplayFrameCounter - m_lastInputUpdateTime);

            m_lastOutputUpdateTime = MySession.Static.GameplayFrameCounter;
            m_lastInputUpdateTime  = MySession.Static.GameplayFrameCounter;

            float gasInput      = GasInputPerUpdate * sinkUpdateFrames;
            float gasOutput     = GasOutputPerUpdate * sourceUpdateFrames;
            float totalTransfer = gasInput - gasOutput + m_nextGasTransfer;

            if (totalTransfer != 0f)
            {
                Transfer(totalTransfer);
            }

            SourceComp.SetRemainingCapacityByType(m_oxygenGasId, (float)(block.Room != null && block.Room.IsPressurized ? block.Room.OxygenAmount : (MyOxygenProviderSystem.GetOxygenInPoint(WorldMatrix.Translation) != 0 ? BlockDefinition.VentilationCapacityPerSecond * 100 : 0f)));

            ResourceSink.Update();

            UpdateTexts();
            UpdateEmissivity();

            if (MyFakes.ENABLE_OXYGEN_SOUNDS)
            {
                UpdateSound();
            }
        }
Example #13
0
        void DrainFromRoom(float amount)
        {
            if (amount == 0f || !IsDepressurizing)
            {
                return;
            }

            Debug.Assert(IsDepressurizing, "Vent asked to depressurize when it is supposed to pressurize");
            Debug.Assert(amount >= 0f);

            var   oxygenBlock  = GetOxygenBlock();
            float oxygenInRoom = oxygenBlock.Room == null ? 0f : (float)oxygenBlock.Room.OxygenAmount;

            if (oxygenBlock.Room == null)
            {
                return;
            }

            if (oxygenBlock.Room.IsPressurized)
            {
                SourceComp.SetRemainingCapacityByType(m_oxygenGasId, oxygenInRoom);
                oxygenBlock.Room.OxygenAmount -= amount;
                if (oxygenBlock.Room.OxygenAmount < 0f)
                {
                    oxygenBlock.Room.OxygenAmount = 0f;
                }
            }
            //Take from environment
            else
            {
                float oxygenInEnvironment = MyOxygenProviderSystem.GetOxygenInPoint(WorldMatrix.Translation) != 0 ? BlockDefinition.VentilationCapacityPerSecond * 100 : 0f;
                SourceComp.SetRemainingCapacityByType(m_oxygenGasId, oxygenInEnvironment);
                m_producedSinceLastUpdate = true;
            }
            if (amount > 0)//some oxygen were vented
            {
                m_producedSinceLastUpdate = true;
                if (amount > 1)//enough oxygen were vented for sound and effects
                {
                    m_playVentEffect = true;
                    if (m_effect == null)//create air vent effect
                    {
                        CreateEffect();
                    }
                }
            }

            m_nextGasTransfer = 0f;
        }
Example #14
0
        private void SetDepressurizing()
        {
            if (m_isDepressurizing)
            {
                var tmpGasId = m_oxygenGasId;
                ResourceSink.RemoveType(ref tmpGasId);
            }
            else
            {
                ResourceSink.AddType(ref OxygenSinkInfo);
            }

            SourceComp.SetProductionEnabledByType(m_oxygenGasId, m_isDepressurizing);
            ResourceSink.Update();
        }
Example #15
0
        void RemainingCapacityChanged()
        {
            var before = IsWorking;

            SourceComp.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, m_remainingPowerCapacity);
            UpdateMaxOutputAndEmissivity();

            if (!before && IsWorking)
            {
                OnStartWorking();
            }
            else if (before && !IsWorking)
            {
                OnStopWorking();
            }
        }
Example #16
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (m_producedSinceLastUpdate)
            {
                if (m_effect == null)
                {
                    CreateEffect();
                }
            }
            else
            {
                if (m_effect != null)
                {
                    m_effect.Stop();
                    m_effect = null;
                }
            }

            if (MyFakes.ENABLE_OXYGEN_SOUNDS)
            {
                UpdateSound();
            }

            m_isProducing             = m_producedSinceLastUpdate;
            m_producedSinceLastUpdate = false;
            var block = GetOxygenBlock();

            int sourceUpdateFrames = (m_updateCounter - m_lastOutputUpdateTime);
            int sinkUpdateFrames   = (m_updateCounter - m_lastInputUpdateTime);

            float gasInput      = GasInputPerUpdate * sinkUpdateFrames;
            float gasOutput     = GasOutputPerUpdate * sourceUpdateFrames;
            float totalTransfer = gasInput - gasOutput + m_nextGasTransfer;

            Transfer(totalTransfer);

            SourceComp.SetRemainingCapacityByType(m_oxygenGasId, (float)(block.Room != null ? block.Room.OxygenAmount : 0));

            m_updateCounter        = 0;
            m_lastOutputUpdateTime = m_updateCounter;
            m_lastInputUpdateTime  = m_updateCounter;
            ResourceSink.Update();

            UdpateTexts();
        }
Example #17
0
        internal void ChangeFilledRatio(float newFilledRatio, bool updateSync = false)
        {
            m_nextGasTransfer = 0f;
            float oldFilledRatio = FilledRatio;

            if (oldFilledRatio != newFilledRatio)
            {
                if (updateSync)
                {
                    SyncObject.ChangeFillRatioAmount(newFilledRatio);
                }
                FilledRatio = newFilledRatio;
                SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, FilledRatio * Capacity);
                ResourceSink.Update();
                UpdateEmissivity();
                UdpateText();
            }
        }
Example #18
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            ResourceSink.Update();

            int updatesSinceSourceUpdate = (MySession.Static.GameplayFrameCounter - m_lastSourceUpdate);

            foreach (var gasId in SourceComp.ResourceTypes)
            {
                var   tmpGasId  = gasId;
                float gasOutput = GasOutputPerUpdate(ref tmpGasId) * updatesSinceSourceUpdate;
                ProduceGas(ref tmpGasId, gasOutput);
            }

            if (Sync.IsServer && IsWorking)
            {
                if (m_useConveyorSystem && this.GetInventory().VolumeFillFactor < 0.6f)
                {
                    MyGridConveyorSystem.PullAllRequest(this, this.GetInventory(), OwnerId, HasIce() ? this.GetInventory().Constraint : m_oreConstraint);
                }

                if (AutoRefill && CanRefill())
                {
                    RefillBottles();
                }
            }

            UpdateEmissivity();

            if (MyFakes.ENABLE_OXYGEN_SOUNDS)
            {
                UpdateSounds();
            }

            m_isProducing             = m_producedSinceLastUpdate;
            m_producedSinceLastUpdate = false;
            foreach (var gasId in SourceComp.ResourceTypes)
            {
                m_producedSinceLastUpdate = m_producedSinceLastUpdate || (SourceComp.CurrentOutputByType(gasId) > 0);
            }

            m_lastSourceUpdate = MySession.Static.GameplayFrameCounter;
        }
Example #19
0
        private void UpdateText()
        {
            DetailedInfo.Clear();
            DetailedInfo.AppendStringBuilder(MyTexts.Get(MyCommonTexts.BlockPropertiesText_Type));
            DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BatteryBlock));
            DetailedInfo.Append("\n");
            DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_MaxOutput));
            MyValueFormatter.AppendWorkInBestUnit(BlockDefinition.MaxPowerOutput, DetailedInfo);
            DetailedInfo.Append("\n");
            DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_MaxRequiredInput));
            MyValueFormatter.AppendWorkInBestUnit(BlockDefinition.RequiredPowerInput, DetailedInfo);
            DetailedInfo.Append("\n");
            DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_MaxStoredPower));
            MyValueFormatter.AppendWorkHoursInBestUnit(MaxStoredPower, DetailedInfo);
            DetailedInfo.Append("\n");
            DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertyProperties_CurrentInput));
            MyValueFormatter.AppendWorkInBestUnit(ResourceSink.CurrentInput, DetailedInfo);
            DetailedInfo.Append("\n");
            DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertyProperties_CurrentOutput));
            MyValueFormatter.AppendWorkInBestUnit(SourceComp.CurrentOutput, DetailedInfo);
            DetailedInfo.Append("\n");
            DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_StoredPower));
            MyValueFormatter.AppendWorkHoursInBestUnit(CurrentStoredPower, DetailedInfo);
            DetailedInfo.Append("\n");
            float currentInput  = ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId);
            float currentOutput = SourceComp.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId);

            if (currentInput > currentOutput)
            {
                DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_RechargedIn));
                MyValueFormatter.AppendTimeInBestUnit(m_timeRemaining, DetailedInfo);
            }
            else if (currentInput == currentOutput)
            {
                DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_DepletedIn));
                MyValueFormatter.AppendTimeInBestUnit(float.PositiveInfinity, DetailedInfo);
            }
            else
            {
                DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_DepletedIn));
                MyValueFormatter.AppendTimeInBestUnit(m_timeRemaining, DetailedInfo);
            }
            RaisePropertiesChanged();
        }
Example #20
0
        private float ComputeRequiredPower()
        {
            if ((!MySession.Static.Settings.EnableOxygen && BlockDefinition.ProducedGases.TrueForAll((info) => info.Id == m_oxygenGasId)) ||
                !Enabled ||
                !IsFunctional)
            {
                return(0f);
            }

            bool isProducing = false;

            foreach (var producedGas in BlockDefinition.ProducedGases)
            {
                isProducing = isProducing || (SourceComp.CurrentOutputByType(producedGas.Id) > 0 && (MySession.Static.Settings.EnableOxygen || producedGas.Id != m_oxygenGasId));
            }

            float powerConsumption = isProducing ? BlockDefinition.OperationalPowerConsumption : BlockDefinition.StandbyPowerConsumption;

            return(powerConsumption * m_powerConsumptionMultiplier);
        }
Example #21
0
        private bool CheckTransfer(float testTransfer)
        {
            if (testTransfer == 0f)
            {
                return(false);
            }

            float remainingCapacity    = SourceComp.RemainingCapacityByType(m_oxygenGasId);
            float nextCapacity         = remainingCapacity + testTransfer;
            float gasTransferPerUpdate = GasInputPerUpdate - GasOutputPerUpdate;
            float paddedNextCapacity   = nextCapacity + gasTransferPerUpdate * 15;
            var   maxCapacity          = paddedNextCapacity + 1;
            var   block = GetOxygenBlock();

            if (block.Room != null)
            {
                maxCapacity = (float)block.Room.MaxOxygen(CubeGrid.GridSize);
            }
            return(paddedNextCapacity <= 0f || paddedNextCapacity >= maxCapacity);
        }
Example #22
0
        private void StorePower(float timeDeltaMs, float input)
        {
            float inputPowerPerMillisecond = input / (SourceComp.ProductionToCapacityMultiplierByType(MyResourceDistributorComponent.ElectricityId) * 1000);
            float increment = (timeDeltaMs * inputPowerPerMillisecond) * 0.80f;

            if ((CurrentStoredPower + increment) < MaxStoredPower)
            {
                CurrentStoredPower += increment;
            }
            else
            {
                CurrentStoredPower = MaxStoredPower;
                TimeRemaining      = 0;
                if (!m_isFull)
                {
                    m_isFull.Value = true;
                }
            }

            m_storedPower.Value = CurrentStoredPower;
        }
Example #23
0
        void VentToRoom(float amount)
        {
            if (amount == 0f || IsDepressurizing)
            {
                return;
            }

            Debug.Assert(!IsDepressurizing, "Vent asked to vent when it is supposed to depressurize");
            Debug.Assert(amount >= 0f);

            var oxygenBlock = GetOxygenBlock();

            if (oxygenBlock.Room == null || !oxygenBlock.Room.IsPressurized)
            {
                return;
            }

            oxygenBlock.Room.OxygenAmount += amount;
            if (oxygenBlock.Room.OxygenLevel(CubeGrid.GridSize) > 1f)
            {
                oxygenBlock.Room.OxygenAmount = oxygenBlock.Room.MaxOxygen(CubeGrid.GridSize);
            }

            SourceComp.SetRemainingCapacityByType(m_oxygenGasId, (float)oxygenBlock.Room.OxygenAmount);

            m_nextGasTransfer = 0;

            if (amount > 0)//some oxygen were vented
            {
                m_producedSinceLastUpdate = true;
                if (amount > 1)//enough oxygen were vented for sound and effects
                {
                    m_playVentEffect = true;
                    if (m_effect == null)//create air vent effect
                    {
                        CreateEffect();
                    }
                }
            }
        }
Example #24
0
        void DrainFromRoom(float amount)
        {
            if (amount == 0f || !IsDepressurizing)
            {
                return;
            }

            Debug.Assert(IsDepressurizing, "Vent asked to depressurize when it is supposed to pressurize");
            Debug.Assert(amount >= 0f);

            var   oxygenBlock  = GetOxygenBlock();
            float oxygenInRoom = oxygenBlock.Room == null ? 0f : (float)oxygenBlock.Room.OxygenAmount;

            SourceComp.SetRemainingCapacityByType(m_oxygenGasId, oxygenInRoom);
            if (oxygenBlock.Room == null)
            {
                return;
            }

            if (oxygenBlock.Room.IsPressurized)
            {
                oxygenBlock.Room.OxygenAmount -= amount;
                if (oxygenBlock.Room.OxygenAmount < 0f)
                {
                    oxygenBlock.Room.OxygenAmount = 0f;
                }

                if (amount > 0)
                {
                    m_producedSinceLastUpdate = true;
                }
            }
            else
            {
                //Take from environment, nothing to do
                m_producedSinceLastUpdate = true;
            }

            m_nextGasTransfer = 0f;
        }
Example #25
0
        void ComponentStack_IsFunctionalChanged()
        {
            SourceComp.Enabled = CanStore;
            ResourceSink.Update();
            FilledRatio = 0;

            if (MySession.Static.CreativeMode)
            {
                SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, Capacity);
            }
            else
            {
                SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, FilledRatio * Capacity);
            }

            // ResourceDistributor could be null if the grid is falling apart for whatever reason (collisions, explosions, etc)
            if (CubeGrid != null && CubeGrid.GridSystems != null && CubeGrid.GridSystems.ResourceDistributor != null)
            {
                CubeGrid.GridSystems.ResourceDistributor.ConveyorSystem_OnPoweredChanged(); // Hotfix TODO
            }
            UdpateText();
        }
Example #26
0
        internal void ChangeFilledRatio(float newFilledRatio, bool updateSync = false)
        {
            float oldFilledRatio = FilledRatio;

            if (oldFilledRatio != newFilledRatio || MySession.Static.CreativeMode)
            {
                if (!MySession.Static.CreativeMode)
                {
                    if (updateSync)
                    {
                        this.ChangeFillRatioAmount(newFilledRatio);
                        return;
                    }

                    FilledRatio = newFilledRatio;
                }
                else
                {
                    //AB: In creative we allways have 50% filled so we can recieve and send gas
                    FilledRatio = 0.5f;
                }

                if (MySession.Static.CreativeMode && newFilledRatio > oldFilledRatio)
                {
                    SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, Capacity);
                }
                else
                {
                    SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, FilledRatio * Capacity);
                }

                ResourceSink.Update();
                UpdateEmissivity();
                UpdateText();
            }
        }
Example #27
0
        private float Sink_ComputeRequiredGas()
        {
            if (!CanVentToRoom)
            {
                return(0f);
            }

            var oxygenBlock = GetOxygenBlock();

            if (oxygenBlock.Room == null || !oxygenBlock.Room.IsPressurized)
            {
                return(0f);
            }

            float missingOxygen = (float)oxygenBlock.Room.MissingOxygen(CubeGrid.GridSize);

            float inputToFillInUpdateInterval = missingOxygen * VRage.Game.MyEngineConstants.UPDATE_STEPS_PER_SECOND / m_productionUpdateInterval * SourceComp.ProductionToCapacityMultiplierByType(m_oxygenGasId);

            return(Math.Min(inputToFillInUpdateInterval, BlockDefinition.VentilationCapacityPerSecond));
        }
Example #28
0
 void ProducerEnadChanged()
 {
     SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, m_producerEnabled.Value);
 }
Example #29
0
 private void UpdateMaxOutputAndEmissivity()
 {
     ResourceSink.Update();
     SourceComp.SetMaxOutputByType(MyResourceDistributorComponent.ElectricityId, (ComputeMaxPowerOutput()));
     UpdateEmissivity();
 }
Example #30
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (IsFunctional)
            {
                if (SemiautoEnabled)
                {
                    if (CurrentStoredPower == 0)
                    {
                        OnlyRecharge  = true;
                        OnlyDischarge = false;
                    }
                    else if (CurrentStoredPower == MaxStoredPower)
                    {
                        OnlyRecharge  = false;
                        OnlyDischarge = true;
                    }
                }

                UpdateMaxOutputAndEmissivity();

                float timeDeltaMs = (MySession.Static.GameplayFrameCounter - m_lastUpdateTime) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * 1000f;
                m_lastUpdateTime = MySession.Static.GameplayFrameCounter;
                if (!MySession.Static.CreativeMode)
                {
                    if ((Sync.IsServer && !CubeGrid.GridSystems.ControlSystem.IsControlled) ||
                        CubeGrid.GridSystems.ControlSystem.IsLocallyControlled)
                    {
                        if (OnlyRecharge)
                        {
                            StorePower(timeDeltaMs, ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId));
                        }
                        else if (OnlyDischarge)
                        {
                            ConsumePower(timeDeltaMs, SourceComp.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId));
                        }
                        else
                        {
                            TransferPower(timeDeltaMs, ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId), SourceComp.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId));
                        }
                    }
                }
                else
                {
                    if ((Sync.IsServer && IsFunctional && !CubeGrid.GridSystems.ControlSystem.IsControlled) ||
                        CubeGrid.GridSystems.ControlSystem.IsLocallyControlled)
                    {
                        if (OnlyRecharge || !OnlyDischarge)
                        {
                            float powerToStore = (SourceComp.ProductionToCapacityMultiplierByType(MyResourceDistributorComponent.ElectricityId) * MaxStoredPower) / 8f;
                            powerToStore *= Enabled && IsFunctional ? 1f : 0f;
                            StorePower(timeDeltaMs, powerToStore);
                        }
                        else
                        {
                            UpdateIsWorking();
                            if (!SourceComp.HasCapacityRemainingByType(MyResourceDistributorComponent.ElectricityId))
                            {
                                return;
                            }
                            CalculateOutputTimeRemaining();
                        }
                    }
                }
                ResourceSink.Update();

                if (OnlyRecharge)
                {
                    CalculateInputTimeRemaining();
                }
                else if (OnlyDischarge)
                {
                    CalculateOutputTimeRemaining();
                }
                else
                {
                    if (ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId) > SourceComp.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId))
                    {
                        CalculateInputTimeRemaining();
                    }
                    else
                    {
                        CalculateOutputTimeRemaining();
                    }
                }
            }
        }