public void Init(MyObjectBuilder_Battery builder, List<MyResourceSinkInfo> additionalSinks = null, List<MyResourceSourceInfo> additionalSources = null) { var defaultSinkInfo = new MyResourceSinkInfo { MaxRequiredInput = MyEnergyConstants.BATTERY_MAX_POWER_INPUT, ResourceTypeId = MyResourceDistributorComponent.ElectricityId, RequiredInputFunc = Sink_ComputeRequiredPower, }; if (additionalSinks != null) { additionalSinks.Insert(0, defaultSinkInfo); ResourceSink.Init(m_resourceSinkGroup, additionalSinks); } else { ResourceSink.Init(m_resourceSinkGroup, defaultSinkInfo); } ResourceSink.TemporaryConnectedEntity = m_owner; var defaultSourceInfo = new MyResourceSourceInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = MyEnergyConstants.BATTERY_MAX_POWER_OUTPUT, // TODO: Load max output from definitions ProductionToCapacityMultiplier = 60*60 }; if (additionalSources != null) { additionalSources.Insert(0, defaultSourceInfo); ResourceSource.Init(m_resourceSourceGroup, additionalSources); } else ResourceSource.Init(m_resourceSourceGroup, defaultSourceInfo); ResourceSource.TemporaryConnectedEntity = m_owner; m_lastUpdateTime = MySession.Static.GameplayFrameCounter; if (builder == null) { ResourceSource.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, true); ResourceSource.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, MyEnergyConstants.BATTERY_MAX_CAPACITY); ResourceSink.Update(); return; } ResourceSource.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, builder.ProducerEnabled); if (MySession.Static.SurvivalMode) ResourceSource.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, MathHelper.Clamp(builder.CurrentCapacity, 0f, MyEnergyConstants.BATTERY_MAX_CAPACITY)); else ResourceSource.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, MyEnergyConstants.BATTERY_MAX_CAPACITY); ResourceSink.Update(); }
private void FillSinkInfo() { OxygenSinkInfo = new MyResourceSinkInfo { ResourceTypeId = m_oxygenGasId, MaxRequiredInput = BlockDefinition.VentilationCapacityPerSecond, RequiredInputFunc = Sink_ComputeRequiredGas }; }
public void Init(MyStringHash group, MyResourceSinkInfo sinkData) { MyUtils.Init(ref m_singleHelperList); m_singleHelperList.Add(sinkData); Init(group, m_singleHelperList); m_singleHelperList.Clear(); }
public void AddType(ref MyResourceSinkInfo sinkData) { if (m_resourceIds.Contains(sinkData.ResourceTypeId) || m_resourceTypeToIndex.ContainsKey(sinkData.ResourceTypeId)) return; var newDataPerType = new PerTypeData[m_resourceIds.Count + 1]; for (int dataIndex = 0; dataIndex < m_dataPerType.Length; ++dataIndex) { newDataPerType[dataIndex] = m_dataPerType[dataIndex]; } m_dataPerType = newDataPerType; m_dataPerType[m_dataPerType.Length - 1] = new PerTypeData { MaxRequiredInput = sinkData.MaxRequiredInput, RequiredInputFunc = sinkData.RequiredInputFunc }; m_resourceIds.Add(sinkData.ResourceTypeId); m_resourceTypeToIndex.Add(sinkData.ResourceTypeId, m_dataPerType.Length - 1); if(OnAddType != null) OnAddType(this, sinkData.ResourceTypeId); }