public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); var builder = (MyObjectBuilder_AirVent)objectBuilder; InitializeConveyorEndpoint(); NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; SourceComp.Init(BlockDefinition.ResourceSourceGroup, new MyResourceSourceInfo { ResourceTypeId = m_oxygenGasId, DefinedOutput = BlockDefinition.VentilationCapacityPerSecond, ProductionToCapacityMultiplier = 1 }); SourceComp.OutputChanged += Source_OutputChanged; var sinkDataList = new List <MyResourceSinkInfo> { new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }, new MyResourceSinkInfo { ResourceTypeId = m_oxygenGasId, MaxRequiredInput = BlockDefinition.VentilationCapacityPerSecond, RequiredInputFunc = () => VentingCapacity(1f) }, }; ResourceSink.Init( BlockDefinition.ResourceSinkGroup, sinkDataList); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged; m_updateCounter = 0; m_lastOutputUpdateTime = m_updateCounter; m_lastInputUpdateTime = m_updateCounter; m_nextGasTransfer = 0f; m_actionToolbar = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1); m_actionToolbar.DrawNumbers = false; m_actionToolbar.Init(null, this); if (builder.OnFullAction != null) { m_onFullAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnFullAction); } if (builder.OnEmptyAction != null) { m_onEmptyAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnEmptyAction); } UpdateEmissivity(); UdpateTexts(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyAirVent_IsWorkingChanged; SetDepressurizing(builder.IsDepressurizing); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { var sourceDataList = new List <MyResourceSourceInfo> { new MyResourceSourceInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = BlockDefinition.MaxPowerOutput, ProductionToCapacityMultiplier = 60 * 60 } }; SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); SourceComp.HasCapacityRemainingChanged += (id, source) => UpdateIsWorking(); SourceComp.ProductionEnabledChanged += Source_ProductionEnabledChanged; var batteryBuilder = (MyObjectBuilder_BatteryBlock)objectBuilder; SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, batteryBuilder.ProducerEnabled); MaxStoredPower = BlockDefinition.MaxStoredPower; ResourceSink.Init( BlockDefinition.ResourceSinkGroup, BlockDefinition.RequiredPowerInput, Sink_ComputeRequiredPower); base.Init(objectBuilder, cubeGrid); ResourceSink.Update(); MyDebug.AssertDebug(BlockDefinition != null); MyDebug.AssertDebug(BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_BatteryBlock)); if (batteryBuilder.CurrentStoredPower >= 0) { CurrentStoredPower = batteryBuilder.CurrentStoredPower; } else { CurrentStoredPower = BlockDefinition.InitialStoredPowerRatio * BlockDefinition.MaxStoredPower; } m_storedPower.Value = CurrentStoredPower; SemiautoEnabled = batteryBuilder.SemiautoEnabled; OnlyRecharge = !batteryBuilder.ProducerEnabled; OnlyDischarge = batteryBuilder.OnlyDischargeEnabled; UpdateMaxOutputAndEmissivity(); UpdateText(); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyBatteryBlock_IsWorkingChanged; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; m_lastUpdateTime = MySession.Static.GameplayFrameCounter; if (IsWorking) { OnStartWorking(); } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; var sourceDataList = new List <MyResourceSourceInfo>(); foreach (var producedInfo in BlockDefinition.ProducedGases) { sourceDataList.Add(new MyResourceSourceInfo { ResourceTypeId = producedInfo.Id, DefinedOutput = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio * (MySession.Static.CreativeMode ? 10f : 1f), ProductionToCapacityMultiplier = 1 }); } SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); base.Init(objectBuilder, cubeGrid); var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator; InitializeConveyorEndpoint(); m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; if (this.GetInventory() == null) // can be already initialized as deserialized component { MyInventory inventory = new MyInventory(BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive); inventory.Constraint = BlockDefinition.InputInventoryConstraint; Components.Add <MyInventoryBase>(inventory); } else { this.GetInventory().Constraint = BlockDefinition.InputInventoryConstraint; } Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!"); m_oreConstraint = new MyInventoryConstraint(this.GetInventory().Constraint.Description, this.GetInventory().Constraint.Icon, this.GetInventory().Constraint.IsWhitelist); foreach (var id in this.GetInventory().Constraint.ConstrainedIds) { if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject)) { m_oreConstraint.Add(id); } } if (MyFakes.ENABLE_INVENTORY_FIX) { FixSingleInventory(); } if (this.GetInventory() != null) { this.GetInventory().Init(generatorBuilder.Inventory); } else { Debug.Fail("Trying to init inventory, but it's null!"); } AutoRefill = generatorBuilder.AutoRefill; SourceComp.Enabled = Enabled; if (Sync.IsServer) { SourceComp.OutputChanged += Source_OutputChanged; } float iceAmount = IceAmount(); foreach (var gasId in SourceComp.ResourceTypes) { var tmpGasId = gasId; m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(ref tmpGasId, iceAmount)); } m_lastSourceUpdate = MySession.Static.GameplayFrameCounter; ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.Update(); UpdateEmissivity(); UpdateText(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyGasGenerator_IsWorkingChanged; }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); var builder = (MyObjectBuilder_OxygenTank)objectBuilder; IsStockpiling = builder.IsStockpiling; InitializeConveyorEndpoint(); NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; m_inventory = new MyInventory( BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive, this) { Constraint = BlockDefinition.InputInventoryConstraint }; m_inventory.Init(builder.Inventory); m_inventory.ContentsChanged += m_inventory_ContentsChanged; m_autoRefill = builder.AutoRefill; var sourceDataList = new List <MyResourceSourceInfo> { new MyResourceSourceInfo { ResourceTypeId = BlockDefinition.StoredGasId, DefinedOutput = 0.05f * BlockDefinition.Capacity }, }; SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); SourceComp.OutputChanged += Source_OutputChanged; var sinkDataList = new List <MyResourceSinkInfo> { new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }, new MyResourceSinkInfo { ResourceTypeId = BlockDefinition.StoredGasId, MaxRequiredInput = Capacity, RequiredInputFunc = ComputeRequiredGas }, }; ResourceSink.Init( BlockDefinition.ResourceSinkGroup, sinkDataList); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged; m_lastOutputUpdateTime = m_updateCounter; m_lastInputUpdateTime = m_updateCounter; m_nextGasTransfer = 0f; ChangeFilledRatio(builder.FilledRatio); ResourceSink.Update(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyOxygenTank_IsWorkingChanged; }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); var builder = (MyObjectBuilder_OxygenTank)objectBuilder; IsStockpiling = builder.IsStockpiling; InitializeConveyorEndpoint(); NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; if (MyFakes.ENABLE_INVENTORY_FIX) { FixSingleInventory(); if (this.GetInventory() != null) { this.GetInventory().Constraint = BlockDefinition.InputInventoryConstraint; } } if (this.GetInventory() == null) { MyInventory inventory = new MyInventory(BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive); inventory.Constraint = BlockDefinition.InputInventoryConstraint; Components.Add <MyInventoryBase>(inventory); inventory.Init(builder.Inventory); } Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!"); m_autoRefill = builder.AutoRefill; var sourceDataList = new List <MyResourceSourceInfo> { new MyResourceSourceInfo { ResourceTypeId = BlockDefinition.StoredGasId, DefinedOutput = 0.05f * BlockDefinition.Capacity }, }; SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); SourceComp.OutputChanged += Source_OutputChanged; SourceComp.Enabled = Enabled; var sinkDataList = new List <MyResourceSinkInfo> { new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }, new MyResourceSinkInfo { ResourceTypeId = BlockDefinition.StoredGasId, MaxRequiredInput = Capacity, RequiredInputFunc = ComputeRequiredGas }, }; ResourceSink.Init( BlockDefinition.ResourceSinkGroup, sinkDataList); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged; m_lastOutputUpdateTime = MySession.Static.GameplayFrameCounter; m_lastInputUpdateTime = MySession.Static.GameplayFrameCounter; m_nextGasTransfer = 0f; ChangeFilledRatio(builder.FilledRatio); ResourceSink.Update(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyOxygenTank_IsWorkingChanged; }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator; InitializeConveyorEndpoint(); m_useConveyorSystem = generatorBuilder.UseConveyorSystem; NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; m_inventory = new MyInventory( BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive, this) { Constraint = BlockDefinition.InputInventoryConstraint }; m_oreConstraint = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist); foreach (var id in m_inventory.Constraint.ConstrainedIds) { if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject)) { m_oreConstraint.Add(id); } } m_inventory.Init(generatorBuilder.Inventory); m_inventory.ContentsChanged += Inventory_ContentsChanged; AutoRefill = generatorBuilder.AutoRefill; var sourceDataList = new List <MyResourceSourceInfo>(); foreach (var producedInfo in BlockDefinition.ProducedGases) { sourceDataList.Add(new MyResourceSourceInfo { ResourceTypeId = producedInfo.Id, DefinedOutput = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio, ProductionToCapacityMultiplier = 1 }); } SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); if (Sync.IsServer) { SourceComp.OutputChanged += Source_OutputChanged; } float iceAmount = IceAmount(); foreach (var gasId in SourceComp.ResourceTypes) { m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(gasId, iceAmount)); } m_updateCounter = 0; m_lastSourceUpdate = m_updateCounter; ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.Update(); UpdateEmissivity(); UpdateText(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyGasGenerator_IsWorkingChanged; }