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; }
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(); } } } }
protected override bool CheckIsWorking() { return(Enabled && SourceComp.Enabled && SourceComp.HasCapacityRemainingByType(MyResourceDistributorComponent.ElectricityId) && base.CheckIsWorking()); }