Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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));
        }
Пример #5
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();
        }
Пример #6
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;
        }
Пример #7
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);
        }
Пример #8
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();
                    }
                }
            }
        }