public virtual void OnRemovedFromGroup(MyGridLogicalGroupData group)
        {
            Debug.Assert(TerminalSystem == group.TerminalSystem, "Removing grid from diferent group then it was added to!");
            if (m_blocksRegistered)
            {
                ProfilerShort.Begin("Removing block groups from grid group");
                TerminalSystem.GroupAdded   -= m_terminalSystem_GroupAdded;
                TerminalSystem.GroupRemoved -= m_terminalSystem_GroupRemoved;
                foreach (var g in m_cubeGrid.BlockGroups)
                {
                    TerminalSystem.RemoveGroup(g);
                }
                ProfilerShort.End();

                foreach (var block in m_cubeGrid.GetFatBlocks())
                {
                    var functionalBlock = block as MyTerminalBlock;
                    if (functionalBlock != null)
                    {
                        TerminalSystem.Remove(functionalBlock);
                    }

                    var producer = block.Components.Get <MyResourceSourceComponent>();
                    if (producer != null)
                    {
                        ResourceDistributor.RemoveSource(producer);
                    }

                    var consumer = block.Components.Get <MyResourceSinkComponent>();
                    if (consumer != null)
                    {
                        ResourceDistributor.RemoveSink(consumer, resetSinkInput: false, markedForClose: block.MarkedForClose);
                    }

                    var socketOwner = block as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                    {
                        socketOwner.RechargeSocket.ResourceDistributor = null;
                    }

                    var weapon = block as IMyGunObject <MyDeviceBase>;
                    if (weapon != null)
                    {
                        WeaponSystem.Unregister(weapon);
                    }
                }
            }

            ConveyorSystem.ResourceSink.IsPoweredChanged -= ResourceDistributor.ConveyorSystem_OnPoweredChanged;
            group.ResourceDistributor.RemoveSink(ConveyorSystem.ResourceSink, resetSinkInput: false);
            group.ResourceDistributor.RemoveSink(GyroSystem.ResourceSink, resetSinkInput: false);
            group.ResourceDistributor.UpdateBeforeSimulation10();

            m_cubeGrid.OnBlockAdded   -= ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;
            m_cubeGrid.OnBlockRemoved -= ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;

            ResourceDistributor = null;
            TerminalSystem      = null;
            WeaponSystem        = null;
        }
        public virtual void OnRemovedFromGroup(MyGridLogicalGroupData group)
        {
            if (m_blocksRegistered)
            {
                ProfilerShort.Begin("Removing block groups from grid group");
                TerminalSystem.GroupAdded   -= m_terminalSystem_GroupAdded;
                TerminalSystem.GroupRemoved -= m_terminalSystem_GroupRemoved;
                foreach (var g in m_cubeGrid.BlockGroups)
                {
                    TerminalSystem.RemoveGroup(g);
                }
                ProfilerShort.End();

                foreach (var block in m_cubeGrid.GetBlocks())
                {
                    if (block.FatBlock == null)
                    {
                        continue;
                    }

                    var functionalBlock = block.FatBlock as MyTerminalBlock;
                    if (functionalBlock != null)
                    {
                        TerminalSystem.Remove(functionalBlock);
                    }

                    var producer = block.FatBlock as IMyPowerProducer;
                    if (producer != null)
                    {
                        PowerDistributor.RemoveProducer(producer);
                    }

                    var consumer = block.FatBlock as IMyPowerConsumer;
                    if (consumer != null)
                    {
                        PowerDistributor.RemoveConsumer(consumer, resetConsumerInput: false, markedForClose: block.FatBlock.MarkedForClose);
                    }

                    var socketOwner = block.FatBlock as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                    {
                        socketOwner.RechargeSocket.PowerDistributor = null;
                    }

                    var weapon = block.FatBlock as IMyGunObject <MyDeviceBase>;
                    if (weapon != null)
                    {
                        WeaponSystem.Unregister(weapon);
                    }
                }
            }

            PowerDistributor.RemoveConsumer(ConveyorSystem, resetConsumerInput: false);
            PowerDistributor.RemoveConsumer(GyroSystem, resetConsumerInput: false);
            PowerDistributor.RemoveConsumer(ThrustSystem, resetConsumerInput: false);

            PowerDistributor = null;
            TerminalSystem   = null;
            WeaponSystem     = null;
        }
        public virtual void OnAddedToGroup(MyGridLogicalGroupData group)
        {
            Debug.Assert(group.TerminalSystem != null, "Terminal system is null!");
            TerminalSystem      = group.TerminalSystem;
            ResourceDistributor = group.ResourceDistributor;
            WeaponSystem        = group.WeaponSystem;

            m_cubeGrid.OnBlockAdded   += ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;
            m_cubeGrid.OnBlockRemoved += ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;

            ResourceDistributor.AddSink(GyroSystem.ResourceSink);
            ResourceDistributor.AddSink(ConveyorSystem.ResourceSink);
            ResourceDistributor.UpdateBeforeSimulation10();

            ConveyorSystem.ResourceSink.IsPoweredChanged += ResourceDistributor.ConveyorSystem_OnPoweredChanged;

            foreach (var g in m_cubeGrid.BlockGroups)
            {
                TerminalSystem.AddUpdateGroup(g);
            }
            TerminalSystem.GroupAdded   += m_terminalSystem_GroupAdded;
            TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved;

            foreach (var block in m_cubeGrid.GetFatBlocks())
            {
                if (!block.MarkedForClose)
                {
                    var functionalBlock = block as MyTerminalBlock;
                    if (functionalBlock != null)
                    {
                        TerminalSystem.Add(functionalBlock);
                    }

                    var producer = block.Components.Get <MyResourceSourceComponent>();
                    if (producer != null)
                    {
                        ResourceDistributor.AddSource(producer);
                    }

                    var consumer = block.Components.Get <MyResourceSinkComponent>();
                    if (consumer != null)
                    {
                        ResourceDistributor.AddSink(consumer);
                    }

                    var socketOwner = block as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                    {
                        socketOwner.RechargeSocket.ResourceDistributor = group.ResourceDistributor;
                    }

                    var weapon = block as IMyGunObject <MyDeviceBase>;
                    if (weapon != null)
                    {
                        WeaponSystem.Register(weapon);
                    }
                }
            }
        }
        public virtual void OnAddedToGroup(MyGridLogicalGroupData group)
        {
            Debug.Assert(group.TerminalSystem != null, "Terminal system is null!");
            TerminalSystem   = group.TerminalSystem;
            PowerDistributor = group.PowerDistributor;
            WeaponSystem     = group.WeaponSystem;

            PowerDistributor.AddConsumer(ThrustSystem);
            PowerDistributor.AddConsumer(GyroSystem);
            PowerDistributor.AddConsumer(ConveyorSystem);

            foreach (var g in m_cubeGrid.BlockGroups)
            {
                TerminalSystem.AddUpdateGroup(g);
            }
            TerminalSystem.GroupAdded   += m_terminalSystem_GroupAdded;
            TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved;

            foreach (var block in m_cubeGrid.GetBlocks())
            {
                if (block.FatBlock == null)
                {
                    continue;
                }
                if (!block.FatBlock.MarkedForClose)
                {
                    var functionalBlock = block.FatBlock as MyTerminalBlock;
                    if (functionalBlock != null)
                    {
                        TerminalSystem.Add(functionalBlock);
                    }

                    var producer = block.FatBlock as IMyPowerProducer;
                    if (producer != null)
                    {
                        PowerDistributor.AddProducer(producer);
                    }

                    var consumer = block.FatBlock as IMyPowerConsumer;
                    if (consumer != null)
                    {
                        PowerDistributor.AddConsumer(consumer);
                    }

                    var socketOwner = block.FatBlock as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                    {
                        socketOwner.RechargeSocket.PowerDistributor = group.PowerDistributor;
                    }

                    var weapon = block.FatBlock as IMyGunObject <MyDeviceBase>;
                    if (weapon != null)
                    {
                        WeaponSystem.Register(weapon);
                    }
                }
            }
        }
Exemple #5
0
        public virtual void OnAddedToGroup(MyGridLogicalGroupData group)
        {
            this.TerminalSystem      = group.TerminalSystem;
            this.ResourceDistributor = group.ResourceDistributor;
            this.WeaponSystem        = group.WeaponSystem;
            if (string.IsNullOrEmpty(this.ResourceDistributor.DebugName))
            {
                this.ResourceDistributor.DebugName = this.m_cubeGrid.ToString();
            }
            this.m_cubeGrid.OnFatBlockAdded   += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved);
            this.m_cubeGrid.OnFatBlockRemoved += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved);
            this.ResourceDistributor.AddSink(this.GyroSystem.ResourceSink);
            this.ResourceDistributor.AddSink(this.ConveyorSystem.ResourceSink);
            this.ConveyorSystem.ResourceSink.IsPoweredChanged += new Action(this.ResourceDistributor.ConveyorSystem_OnPoweredChanged);
            foreach (MyBlockGroup group2 in this.m_cubeGrid.BlockGroups)
            {
                this.TerminalSystem.AddUpdateGroup(group2, false, false);
            }
            this.TerminalSystem.GroupAdded   += this.m_terminalSystem_GroupAdded;
            this.TerminalSystem.GroupRemoved += this.m_terminalSystem_GroupRemoved;
            foreach (MyCubeBlock block in this.m_cubeGrid.GetFatBlocks())
            {
                if (!block.MarkedForClose)
                {
                    MyTerminalBlock block2 = block as MyTerminalBlock;
                    if (block2 != null)
                    {
                        this.TerminalSystem.Add(block2);
                    }
                    MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>();
                    if (source != null)
                    {
                        this.ResourceDistributor.AddSource(source);
                    }
                    MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>();
                    if (sink != null)
                    {
                        this.ResourceDistributor.AddSink(sink);
                    }
                    IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner;
                    if (owner != null)
                    {
                        owner.RechargeSocket.ResourceDistributor = group.ResourceDistributor;
                    }
                    IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>;
                    if (gun != null)
                    {
                        this.WeaponSystem.Register(gun);
                    }
                }
            }
            MyResourceDistributorComponent resourceDistributor = this.ResourceDistributor;

            resourceDistributor.OnPowerGenerationChanged = (Action <bool>)Delegate.Combine(resourceDistributor.OnPowerGenerationChanged, new Action <bool>(this.OnPowerGenerationChanged));
            this.TerminalSystem.BlockManipulationFinishedFunction();
            this.ResourceDistributor.UpdateBeforeSimulation();
        }
        public virtual void OnRemovedFromGroup(MyGridLogicalGroupData group)
        {
            Debug.Assert(TerminalSystem == group.TerminalSystem, "Removing grid from diferent group then it was added to!");
            if (m_blocksRegistered)
            {
                ProfilerShort.Begin("Removing block groups from grid group");
                TerminalSystem.GroupAdded -= m_terminalSystem_GroupAdded;
                TerminalSystem.GroupRemoved -= m_terminalSystem_GroupRemoved;
                foreach (var g in m_cubeGrid.BlockGroups)
                    TerminalSystem.RemoveGroup(g);
                ProfilerShort.End();

                foreach (var block in m_cubeGrid.GetFatBlocks())
                {
                    var functionalBlock = block as MyTerminalBlock;
                    if (functionalBlock != null)
                        TerminalSystem.Remove(functionalBlock);

                    var producer = block.Components.Get<MyResourceSourceComponent>();
                    if (producer != null)
                        ResourceDistributor.RemoveSource(producer);

                    var consumer = block.Components.Get<MyResourceSinkComponent>();
                    if (consumer != null)
                        ResourceDistributor.RemoveSink(consumer, resetSinkInput: false, markedForClose: block.MarkedForClose);

                    var socketOwner = block as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                        socketOwner.RechargeSocket.ResourceDistributor = null;

                    var weapon = block as IMyGunObject<MyDeviceBase>;
                    if (weapon != null)
                        WeaponSystem.Unregister(weapon);
                }
            }

            ConveyorSystem.ResourceSink.IsPoweredChanged -= ResourceDistributor.ConveyorSystem_OnPoweredChanged;
            group.ResourceDistributor.RemoveSink(ConveyorSystem.ResourceSink, resetSinkInput: false);
            group.ResourceDistributor.RemoveSink(GyroSystem.ResourceSink, resetSinkInput: false);
            group.ResourceDistributor.UpdateBeforeSimulation10();

            m_cubeGrid.OnBlockAdded -= ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;
            m_cubeGrid.OnBlockRemoved -= ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;

            ResourceDistributor = null;
            TerminalSystem = null;
            WeaponSystem = null;
        }
        public virtual void OnAddedToGroup(MyGridLogicalGroupData group)
        {
            Debug.Assert(group.TerminalSystem != null, "Terminal system is null!");
            TerminalSystem = group.TerminalSystem;
            ResourceDistributor = group.ResourceDistributor;
            WeaponSystem = group.WeaponSystem;

            m_cubeGrid.OnBlockAdded += ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;
            m_cubeGrid.OnBlockRemoved += ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;

            ResourceDistributor.AddSink(GyroSystem.ResourceSink);
            ResourceDistributor.AddSink(ConveyorSystem.ResourceSink);
            ResourceDistributor.UpdateBeforeSimulation10();

            ConveyorSystem.ResourceSink.IsPoweredChanged += ResourceDistributor.ConveyorSystem_OnPoweredChanged;

            foreach (var g in m_cubeGrid.BlockGroups)
                TerminalSystem.AddUpdateGroup(g);
            TerminalSystem.GroupAdded += m_terminalSystem_GroupAdded;
            TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved;

            foreach (var block in m_cubeGrid.GetFatBlocks())
            {
                if (!block.MarkedForClose)
                {
                    var functionalBlock = block as MyTerminalBlock;
                    if (functionalBlock != null)
                        TerminalSystem.Add(functionalBlock);

                    var producer = block.Components.Get<MyResourceSourceComponent>();
                    if (producer != null)
                        ResourceDistributor.AddSource(producer);

                    var consumer = block.Components.Get<MyResourceSinkComponent>();
                    if (consumer != null)
                        ResourceDistributor.AddSink(consumer);

                    var socketOwner = block as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                        socketOwner.RechargeSocket.ResourceDistributor = group.ResourceDistributor;

                    var weapon = block as IMyGunObject<MyDeviceBase>;
                    if (weapon != null)
                        WeaponSystem.Register(weapon);
                }
            }
        }
 private void CubeGrid_AddedToLogicalGroup(MyGridLogicalGroupData obj)
 {
     SetWeaponSystem(obj.WeaponSystem);
 }
        public virtual void OnRemovedFromGroup(MyGridLogicalGroupData group)
        {
            if (m_blocksRegistered)
            {
                ProfilerShort.Begin("Removing block groups from grid group");
                TerminalSystem.GroupAdded -= m_terminalSystem_GroupAdded;
                TerminalSystem.GroupRemoved -= m_terminalSystem_GroupRemoved;
                foreach (var g in m_cubeGrid.BlockGroups)
                    TerminalSystem.RemoveGroup(g);
                ProfilerShort.End();

                foreach (var block in m_cubeGrid.GetBlocks())
                {
                    if (block.FatBlock == null)
                        continue;

                    var functionalBlock = block.FatBlock as MyTerminalBlock;
                    if (functionalBlock != null)
                        TerminalSystem.Remove(functionalBlock);

                    var producer = block.FatBlock as IMyPowerProducer;
                    if (producer != null)
                        PowerDistributor.RemoveProducer(producer);

                    var consumer = block.FatBlock as IMyPowerConsumer;
                    if (consumer != null)
                    {
                        PowerDistributor.RemoveConsumer(consumer, resetConsumerInput: false, markedForClose: block.FatBlock.MarkedForClose);
                    }

                    var socketOwner = block.FatBlock as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                        socketOwner.RechargeSocket.PowerDistributor = null;

                    var weapon = block.FatBlock as IMyGunObject<MyDeviceBase>;
                    if (weapon != null)
                        WeaponSystem.Unregister(weapon);
                }
            }

            PowerDistributor.RemoveConsumer(ConveyorSystem, resetConsumerInput: false);
            PowerDistributor.RemoveConsumer(GyroSystem, resetConsumerInput: false);
            PowerDistributor.RemoveConsumer(ThrustSystem, resetConsumerInput: false);

            PowerDistributor = null;
            TerminalSystem = null;
            WeaponSystem = null;
        }
        public virtual void OnAddedToGroup(MyGridLogicalGroupData group)
        {
            Debug.Assert(group.TerminalSystem != null, "Terminal system is null!");
            TerminalSystem = group.TerminalSystem;
            PowerDistributor = group.PowerDistributor;
            WeaponSystem = group.WeaponSystem;

            PowerDistributor.AddConsumer(ThrustSystem);
            PowerDistributor.AddConsumer(GyroSystem);
            PowerDistributor.AddConsumer(ConveyorSystem);

            foreach (var g in m_cubeGrid.BlockGroups)
                TerminalSystem.AddUpdateGroup(g);
            TerminalSystem.GroupAdded += m_terminalSystem_GroupAdded;
            TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved;

            foreach (var block in m_cubeGrid.GetBlocks())
            {
                if (block.FatBlock == null)
                    continue;
                if (!block.FatBlock.MarkedForClose)
                {
                    var functionalBlock = block.FatBlock as MyTerminalBlock;
                    if (functionalBlock != null)
                        TerminalSystem.Add(functionalBlock);

                    var producer = block.FatBlock as IMyPowerProducer;
                    if (producer != null)
                        PowerDistributor.AddProducer(producer);

                    var consumer = block.FatBlock as IMyPowerConsumer;
                    if (consumer != null)
                        PowerDistributor.AddConsumer(consumer);

                    var socketOwner = block.FatBlock as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                        socketOwner.RechargeSocket.PowerDistributor = group.PowerDistributor;

                    var weapon = block.FatBlock as IMyGunObject<MyDeviceBase>;
                    if (weapon != null)
                        WeaponSystem.Register(weapon);
                }
            }
        }
        public virtual void OnRemovedFromGroup(MyGridLogicalGroupData group)
        {
            if (m_blocksRegistered)
            {
                ProfilerShort.Begin("Removing block groups from grid group");
                TerminalSystem.GroupAdded -= m_terminalSystem_GroupAdded;
                TerminalSystem.GroupRemoved -= m_terminalSystem_GroupRemoved;
                foreach (var g in m_cubeGrid.BlockGroups)
                    TerminalSystem.RemoveGroup(g);
                ProfilerShort.End();

                foreach (var block in m_cubeGrid.GetBlocks())
                {
                    if (block.FatBlock == null)
                        continue;

                    var functionalBlock = block.FatBlock as MyTerminalBlock;
                    if (functionalBlock != null)
                        TerminalSystem.Remove(functionalBlock);

                    var producer = block.FatBlock.Components.Get<MyResourceSourceComponent>();
                    if (producer != null)
                        ResourceDistributor.RemoveSource(producer);

                    var consumer = block.FatBlock.Components.Get<MyResourceSinkComponent>();
                    if (consumer != null)
                        ResourceDistributor.RemoveSink(consumer, resetSinkInput: false, markedForClose: block.FatBlock.MarkedForClose);

                    var socketOwner = block.FatBlock as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                        socketOwner.RechargeSocket.ResourceDistributor = null;

                    var weapon = block.FatBlock as IMyGunObject<MyDeviceBase>;
                    if (weapon != null)
                        WeaponSystem.Unregister(weapon);
                }
            }

            group.ResourceDistributor.RemoveSink(ConveyorSystem.ResourceSink, resetSinkInput: false);
            group.ResourceDistributor.RemoveSink(GyroSystem.ResourceSink, resetSinkInput: false);

            var gridThrustComponent = CubeGrid.Components.Get<MyEntityThrustComponent>();
            if (gridThrustComponent != null)
                group.ResourceDistributor.RemoveSink(gridThrustComponent.ResourceSink);

            m_cubeGrid.OnBlockAdded -= ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;
            m_cubeGrid.OnBlockRemoved -= ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;

            ResourceDistributor = null;
            TerminalSystem = null;
            WeaponSystem = null;
        }
Exemple #12
0
        public virtual void OnRemovedFromGroup(MyGridLogicalGroupData group)
        {
            if (m_blocksRegistered)
            {
                ProfilerShort.Begin("Removing block groups from grid group");
                TerminalSystem.GroupAdded   -= m_terminalSystem_GroupAdded;
                TerminalSystem.GroupRemoved -= m_terminalSystem_GroupRemoved;
                foreach (var g in m_cubeGrid.BlockGroups)
                {
                    TerminalSystem.RemoveGroup(g);
                }
                ProfilerShort.End();

                foreach (var block in m_cubeGrid.GetBlocks())
                {
                    if (block.FatBlock == null)
                    {
                        continue;
                    }

                    var functionalBlock = block.FatBlock as MyTerminalBlock;
                    if (functionalBlock != null)
                    {
                        TerminalSystem.Remove(functionalBlock);
                    }

                    var producer = block.FatBlock.Components.Get <MyResourceSourceComponent>();
                    if (producer != null)
                    {
                        ResourceDistributor.RemoveSource(producer);
                    }

                    var consumer = block.FatBlock.Components.Get <MyResourceSinkComponent>();
                    if (consumer != null)
                    {
                        ResourceDistributor.RemoveSink(consumer, resetSinkInput: false, markedForClose: block.FatBlock.MarkedForClose);
                    }

                    var socketOwner = block.FatBlock as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                    {
                        socketOwner.RechargeSocket.ResourceDistributor = null;
                    }

                    var weapon = block.FatBlock as IMyGunObject <MyDeviceBase>;
                    if (weapon != null)
                    {
                        WeaponSystem.Unregister(weapon);
                    }
                }
            }

            group.ResourceDistributor.RemoveSink(ConveyorSystem.ResourceSink, resetSinkInput: false);
            group.ResourceDistributor.RemoveSink(GyroSystem.ResourceSink, resetSinkInput: false);

            var gridThrustComponent = CubeGrid.Components.Get <MyEntityThrustComponent>();

            if (gridThrustComponent != null)
            {
                group.ResourceDistributor.RemoveSink(gridThrustComponent.ResourceSink);
            }

            m_cubeGrid.OnBlockAdded   -= ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;
            m_cubeGrid.OnBlockRemoved -= ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;

            ResourceDistributor = null;
            TerminalSystem      = null;
            WeaponSystem        = null;
        }