private void UpdateEmissivity(bool force = false) { if (IsFunctional && IsWorking) { if (IsFull) { SetEmissive(Color.Cyan, 1.0f, 1.0f, force); } else if (!m_isRecharging) { SetEmissive(Color.Yellow, m_storedPower / BlockDefinition.PowerNeededForJump, 1.0f, force); } else if (ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId) > 0f) { SetEmissive(Color.Green, m_storedPower / BlockDefinition.PowerNeededForJump, 1.0f, force); } else { SetEmissive(Color.Red, m_storedPower / BlockDefinition.PowerNeededForJump, 0.0f, force); } } else { SetEmissive(Color.Red, 1.0f, 0.0f, force); } }
void UpdateText() { DetailedInfo.Clear(); DetailedInfo.AppendStringBuilder(MyTexts.Get(MyCommonTexts.BlockPropertiesText_Type)); DetailedInfo.Append(BlockDefinition.DisplayNameText); 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(BlockDefinition.PowerNeededForJump, DetailedInfo); DetailedInfo.Append("\n"); DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertyProperties_CurrentInput)); MyValueFormatter.AppendWorkInBestUnit(ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId), DetailedInfo); DetailedInfo.Append("\n"); DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_StoredPower)); MyValueFormatter.AppendWorkHoursInBestUnit(m_storedPower, DetailedInfo); DetailedInfo.Append("\n"); DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_RechargedIn)); MyValueFormatter.AppendTimeInBestUnit(m_timeRemaining, DetailedInfo); DetailedInfo.Append("\n"); int maxDistance = (int)(CubeGrid.GridSystems.JumpSystem.GetMaxJumpDistance(OwnerId) / 1000); DetailedInfo.Append("Max jump distance: "); DetailedInfo.Append(maxDistance).Append(" km"); if (m_jumpTarget != null) { DetailedInfo.Append("\n"); double distance = (m_jumpTarget.Coords - CubeGrid.WorldMatrix.Translation).Length(); float ratio = Math.Min(1.0f, (float)(maxDistance / distance)); DetailedInfo.Append("Current jump: " + (ratio * 100f).ToString("F2") + "%"); } RaisePropertiesChanged(); }
private void CalculateInputTimeRemaining() { if (ResourceSink.CurrentInput != 0) { TimeRemaining = (MaxStoredPower - CurrentStoredPower) / (ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId) / SourceComp.ProductionToCapacityMultiplierByType(MyResourceDistributorComponent.ElectricityId)); } else { TimeRemaining = 0; } }
private void UpdateText() { DetailedInfo.Clear(); DetailedInfo.AppendStringBuilder(MyTexts.Get(MyCommonTexts.BlockPropertiesText_Type)); DetailedInfo.Append(BlockDefinition.DisplayNameText); DetailedInfo.Append("\n"); DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertyProperties_CurrentMass)); DetailedInfo.Append(IsWorking ? BlockDefinition.VirtualMass.ToString() : "0"); DetailedInfo.Append(" kg\n"); DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertiesText_RequiredInput)); MyValueFormatter.AppendWorkInBestUnit(ResourceSink.RequiredInputByType(MyResourceDistributorComponent.ElectricityId), DetailedInfo); DetailedInfo.Append("\n"); DetailedInfo.AppendStringBuilder(MyTexts.Get(MySpaceTexts.BlockPropertyProperties_CurrentInput)); MyValueFormatter.AppendWorkInBestUnit(ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId), DetailedInfo); RaisePropertiesChanged(); }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (m_pilot != null && OxygenFillLevel < 0.2f && CubeGrid.GridSizeEnum == MyCubeSize.Small) { RefillFromBottlesOnGrid(); } float timeSinceLastUpdateSeconds = (MySession.Static.ElapsedPlayTime.Ticks - m_lastGasInputUpdateTick) / (float)TimeSpan.TicksPerSecond; float inputAmount = ResourceSink.CurrentInputByType(MyCharacterOxygenComponent.OxygenId) * timeSinceLastUpdateSeconds; ChangeGasFillLevel(OxygenFillLevel + inputAmount); m_lastGasInputUpdateTick = MySession.Static.ElapsedPlayTime.Ticks; ResourceSink.Update(); }
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(); }
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 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); }
protected override void UpdateProduction(int timeDelta) { if (!Enabled) { CurrentState = StateEnum.Disabled; return; } if (!ResourceSink.IsPoweredByType(MyResourceDistributorComponent.ElectricityId) || ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId) < GetOperationalPowerConsumption()) { if (!ResourceSink.IsPowerAvailable(MyResourceDistributorComponent.ElectricityId, GetOperationalPowerConsumption())) { CurrentState = StateEnum.NotEnoughPower; return; } } if (!IsWorking) { CurrentState = StateEnum.NotWorking; return; } if (IsQueueEmpty) { return; } var firstQueueItem = TryGetFirstQueueItem(); while (timeDelta > 0) { if (!firstQueueItem.HasValue) { CurrentProgress = 0f; if (IsQueueEmpty) { IsProducing = false; return; } if (!Sync.IsServer) { break; } firstQueueItem = TryGetFirstQueueItem(); } var currentBlueprint = firstQueueItem.Value.Blueprint; CurrentState = CheckInventory(currentBlueprint); if (CurrentState != StateEnum.Ok) { IsProducing = false; return; } var remainingTime = calculateBlueprintProductionTime(currentBlueprint) - CurrentProgress * calculateBlueprintProductionTime(currentBlueprint); if (timeDelta >= remainingTime) { if (Sync.IsServer) { if (DisassembleEnabled) { FinishDisassembling(currentBlueprint); } else { if (RepeatEnabled) { InsertQueueItemRequest(-1, currentBlueprint); } FinishAssembling(currentBlueprint); } RemoveFirstQueueItemAnnounce(1); } timeDelta -= (int)Math.Ceiling(remainingTime); CurrentProgress = 0; firstQueueItem = null; } else { CurrentProgress += timeDelta / calculateBlueprintProductionTime(currentBlueprint); timeDelta = 0; } } IsProducing = IsWorking && !IsQueueEmpty; }
public void UpdateOnServer() { if (!Sync.IsServer) { return; } MyEntity newParent = m_owner.Parent; if (m_lastParent != newParent) // Need to rethink batteries { ResourceSink.Update(); m_lastParent = newParent; } if (ResourceSource.HasCapacityRemainingByType(MyResourceDistributorComponent.ElectricityId) || ResourceSink.RequiredInputByType(MyResourceDistributorComponent.ElectricityId) > 0.0f) { float secondsSinceLastUpdate = (MySession.Static.GameplayFrameCounter - m_lastUpdateTime) * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; m_lastUpdateTime = MySession.Static.GameplayFrameCounter; var productionToCapacity = ResourceSource.ProductionToCapacityMultiplierByType(MyResourceDistributorComponent.ElectricityId); float consumptionPerSecond = ResourceSource.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId) / productionToCapacity; float rechargePerSecond = (MyFakes.ENABLE_BATTERY_SELF_RECHARGE ? ResourceSink.MaxRequiredInputByType(MyResourceDistributorComponent.ElectricityId) : ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId) / productionToCapacity); float consumedEnergy = (MySession.Static.CreativeMode) ? 0 : secondsSinceLastUpdate * consumptionPerSecond; float rechargedEnergy = secondsSinceLastUpdate * rechargePerSecond; float energyTransfer = rechargedEnergy - consumedEnergy; float newCapacity = ResourceSource.RemainingCapacityByType(MyResourceDistributorComponent.ElectricityId) + energyTransfer; ResourceSource.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, MathHelper.Clamp(newCapacity, 0f, MyEnergyConstants.BATTERY_MAX_CAPACITY)); } if (!ResourceSource.HasCapacityRemainingByType(MyResourceDistributorComponent.ElectricityId)) { ResourceSink.Update(); } SyncObject.SendCapacitySync(Owner, ResourceSource.RemainingCapacityByType(MyResourceDistributorComponent.ElectricityId)); }
public override void UpdateAfterSimulation100() { base.UpdateAfterSimulation100(); if (IsFunctional) { if (!IsFull && m_isRecharging) { StorePower(100f * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS, ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId)); } } UpdateEmissivity(); UpdateText(); }