Example #1
0
        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 = () => (ResourceSource.RemainingCapacity < MyEnergyConstants.BATTERY_MAX_CAPACITY) ? MyEnergyConstants.BATTERY_MAX_POWER_INPUT : 0f,
            };

            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();
        }
	    public void Init(MyStringHash group, MyResourceSinkInfo sinkData)
	    {
	        m_singleHelperList.Add(sinkData);
	        Init(group, m_singleHelperList);
	        m_singleHelperList.Clear();
	    }
	    public void AddType(ref MyResourceSinkInfo sinkData)
	    {
	        var newDataPerType = new PerTypeData[m_dataPerType.Length + 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);
	        OnAddType(this);
	    }