public MyObjectBuilder_Battery GetObjectBuilder() { MyObjectBuilder_Battery builder = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Battery>(); builder.ProducerEnabled = (this as IMyPowerProducer).Enabled; builder.CurrentCapacity = RemainingCapacity; return(builder); }
public MyObjectBuilder_Battery GetObjectBuilder() { MyObjectBuilder_Battery builder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Battery>(); builder.ProducerEnabled = ResourceSource.Enabled; builder.CurrentCapacity = ResourceSource.RemainingCapacityByType(MyResourceDistributorComponent.ElectricityId); return(builder); }
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(); }
public void Init(MyObjectBuilder_Battery builder) { PowerReceiver = new MyPowerReceiver( MyConsumerGroupEnum.Charging, true, MyEnergyConstants.BATTERY_MAX_POWER_INPUT, () => (RemainingCapacity < MyEnergyConstants.BATTERY_MAX_CAPACITY) ? MyEnergyConstants.BATTERY_MAX_POWER_INPUT : 0f); PowerReceiver.Update(); if (builder != null) { (this as IMyPowerProducer).Enabled = builder.ProducerEnabled; if (MySession.Static.SurvivalMode) { RemainingCapacity = MathHelper.Clamp(builder.CurrentCapacity, 0f, MyEnergyConstants.BATTERY_MAX_CAPACITY); } } RefreshHasRemainingCapacity(); }
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(); }