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; }
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)); }
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(); } } } }
private void CalculateInputTimeRemaining() { if (ResourceSink.CurrentInput != 0) { TimeRemaining = (MaxStoredPower - CurrentStoredPower) / (ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId) / SourceComp.ProductionToCapacityMultiplierByType(MyResourceDistributorComponent.ElectricityId)); } else { TimeRemaining = 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); float requiredInput = 0; if (canRecharge && shouldRecharge) { float maxRequiredInput = ResourceSink.MaxRequiredInputByType(MyResourceDistributorComponent.ElectricityId); requiredInput = Math.Min(inputToFillInUpdateInterval + currentOutput, maxRequiredInput); } return(requiredInput); }
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)); }