public override void UpdateOnceBeforeFrame() { if (!U.IsReal((MyCubeBlock)Block) || !MyAPIGateway.Multiplayer.IsServer) // ignore projected and other non-physical grids { return; } NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; // setup resources Sink = Entity.Components.Get <MyResourceSinkComponent>(); if (Sink == null) { Sink = new MyResourceSinkComponent(); Entity.Components.Add(Sink); } Source = Entity.Components.Get <MyResourceSourceComponent>(); if (Source == null) { Source = new MyResourceSourceComponent(); Entity.Components.Add(Source); } var subTanks = tankDefs.Select(def => new SubTankImpl(this, def)).ToList(); Sink.Init(MyStringHash.GetOrCompute("Factory"), subTanks.Select(x => x.sinkInfo).ToList()); Source.Init(MyStringHash.GetOrCompute("Reactors"), subTanks.Select(x => x.sourceInfo).ToList()); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { MyDebug.AssertDebug(BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Reactor)); m_reactorDefinition = BlockDefinition as MyReactorDefinition; MyDebug.AssertDebug(m_reactorDefinition != null); SourceComp.Init( m_reactorDefinition.ResourceSourceGroup, new MyResourceSourceInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = m_reactorDefinition.MaxPowerOutput, ProductionToCapacityMultiplier = 60 * 60 }); SourceComp.HasCapacityRemainingChanged += (id, source) => UpdateIsWorking(); SourceComp.OutputChanged += Source_OnOutputChanged; SourceComp.ProductionEnabledChanged += Source_ProductionEnabledChanged; SourceComp.Enabled = Enabled; base.Init(objectBuilder, cubeGrid); var obGenerator = (MyObjectBuilder_Reactor)objectBuilder; if (MyFakes.ENABLE_INVENTORY_FIX) { FixSingleInventory(); } if (this.GetInventory() == null) { MyInventory inventory = new MyInventory(m_reactorDefinition.InventoryMaxVolume, m_reactorDefinition.InventorySize, MyInventoryFlags.CanReceive); Components.Add <MyInventoryBase>(inventory); inventory.Init(obGenerator.Inventory); } Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!"); this.GetInventory().Constraint = m_reactorDefinition.InventoryConstraint; if (Sync.IsServer) { RefreshRemainingCapacity(); } UpdateText(); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; m_useConveyorSystem.Value = obGenerator.UseConveyorSystem; UpdateMaxOutputAndEmissivity(); }
public void AddResourceSourceComponent() { MyResourceSourceComponent source = new MyResourceSourceComponent(); MyResourceSourceInfo info = new MyResourceSourceInfo(); info.ResourceTypeId = defId; info.DefinedOutput = maxOutput; source.Init(MyStringHash.GetOrCompute("Battery"), info); source.Enabled = true; source.SetMaxOutput(maxOutput); cockpit.Components.Add(source); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); SyncObject = new MySyncBatteryBlock(this); MyDebug.AssertDebug(BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_BatteryBlock)); m_batteryBlockDefinition = BlockDefinition as MyBatteryBlockDefinition; MyDebug.AssertDebug(m_batteryBlockDefinition != null); var sourceDataList = new List <MyResourceSourceInfo> { new MyResourceSourceInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = m_batteryBlockDefinition.MaxPowerOutput, ProductionToCapacityMultiplier = 60 * 60 } }; SourceComp.Init(m_batteryBlockDefinition.ResourceSourceGroup, sourceDataList); SourceComp.HasCapacityRemainingChanged += (id, source) => UpdateIsWorking(); MaxStoredPower = m_batteryBlockDefinition.MaxStoredPower; ResourceSink.Init( m_batteryBlockDefinition.ResourceSinkGroup, m_batteryBlockDefinition.RequiredPowerInput, () => (Enabled && IsFunctional && !SourceComp.ProductionEnabled && !m_isFull) ? ResourceSink.MaxRequiredInput : 0.0f); ResourceSink.Update(); var obGenerator = (MyObjectBuilder_BatteryBlock)objectBuilder; CurrentStoredPower = obGenerator.CurrentStoredPower; SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, obGenerator.ProducerEnabled); SemiautoEnabled = obGenerator.SemiautoEnabled; UpdateMaxOutputAndEmissivity(); UpdateText(); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; this.IsWorkingChanged += MyBatteryBlock_IsWorkingChanged; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; if (IsWorking) { OnStartWorking(); } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); IsWorkingChanged += OnIsWorkingChanged; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; InitializeConveyorEndpoint(); SourceComp.Init( BlockDefinition.ResourceSourceGroup, new MyResourceSourceInfo { ResourceTypeId = BlockDefinition.ProducedGas, DefinedOutput = BlockDefinition.MaxGasOutput, ProductionToCapacityMultiplier = 1, IsInfiniteCapacity = true, }); SourceComp.Enabled = IsWorking; ResourceSink.Init( BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower, }); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.Update(); GameLogic = new MySolarGameLogicComponent(); SolarComponent = GameLogic as MySolarGameLogicComponent; SolarComponent.Initialize(BlockDefinition.PanelOrientation, BlockDefinition.IsTwoSided, BlockDefinition.PanelOffset, this); AddDebugRenderComponent(new MyDebugRenderComponentSolarPanel(this)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_OnIsFunctionalChanged; UpdateVisual(); UpdateDisplay(); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); MyDebug.AssertDebug(BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Reactor)); m_reactorDefinition = BlockDefinition as MyReactorDefinition; MyDebug.AssertDebug(m_reactorDefinition != null); SourceComp.Init( m_reactorDefinition.ResourceSourceGroup, new MyResourceSourceInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = m_reactorDefinition.MaxPowerOutput, ProductionToCapacityMultiplier = 60 * 60 }); SourceComp.HasCapacityRemainingChanged += (id, source) => UpdateIsWorking(); SourceComp.OutputChanged += Source_OnOutputChanged; SourceComp.ProductionEnabledChanged += Source_ProductionEnabledChanged; SourceComp.Enabled = Enabled; m_inventory = new MyInventory(m_reactorDefinition.InventoryMaxVolume, m_reactorDefinition.InventorySize, MyInventoryFlags.CanReceive, this); var obGenerator = (MyObjectBuilder_Reactor)objectBuilder; m_inventory.Init(obGenerator.Inventory); m_inventory.ContentsChanged += inventory_ContentsChanged; m_inventory.Constraint = m_reactorDefinition.InventoryConstraint; RefreshRemainingCapacity(); UpdateText(); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; m_useConveyorSystem = obGenerator.UseConveyorSystem; UpdateMaxOutputAndEmissivity(); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); SolarPanelDefinition = BlockDefinition as MySolarPanelDefinition; IsWorkingChanged += OnIsWorkingChanged; NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME; var sourceDataList = new List <MyResourceSourceInfo> { new MyResourceSourceInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = SolarPanelDefinition.MaxPowerOutput, IsInfiniteCapacity = true, ProductionToCapacityMultiplier = 60 * 60 } }; SourceComp.Init(SolarPanelDefinition.ResourceSourceGroup, sourceDataList); GameLogic = new MySolarGameLogicComponent(); SolarComponent = GameLogic as MySolarGameLogicComponent; SolarComponent.Initialize(SolarPanelDefinition.PanelOrientation, SolarPanelDefinition.IsTwoSided, SolarPanelDefinition.PanelOffset, this); AddDebugRenderComponent(new Sandbox.Game.Components.MyDebugRenderComponentSolarPanel(this)); }