public virtual void RemoveGroup(MyBlockGroup group)
 {
     if (TerminalSystem != null)
     {
         TerminalSystem.GroupRemoved -= m_terminalSystem_GroupRemoved;
         TerminalSystem.RemoveGroup(group);
         TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved;
     }
 }
 public virtual void AddGroup(MyBlockGroup group)
 {
     if (TerminalSystem != null)
     {
         TerminalSystem.GroupAdded -= m_terminalSystem_GroupAdded;
         TerminalSystem.AddUpdateGroup(group);
         TerminalSystem.GroupAdded += m_terminalSystem_GroupAdded;
     }
 }
        public virtual void DebugDraw()
        {
            if (MyDebugDrawSettings.DEBUG_DRAW_GRID_TERMINAL_SYSTEMS)
            {
                MyRenderProxy.DebugDrawText3D(m_cubeGrid.WorldMatrix.Translation, TerminalSystem.GetHashCode().ToString(), Color.NavajoWhite, 1.0f, false);
            }

            if (MyDebugDrawSettings.DEBUG_DRAW_CONVEYORS)
            {
                ConveyorSystem.DebugDraw(m_cubeGrid);
                ConveyorSystem.DebugDrawLinePackets();
            }

            if (MySession.Static.Settings.EnableOxygen && MySession.Static.Settings.EnableOxygenPressurization && MyDebugDrawSettings.DEBUG_DRAW_OXYGEN)
            {
                GasSystem.DebugDraw();
            }
        }
        public virtual void UnregisterFromSystems(MyCubeBlock block)
        {
            // Note: ResourceDistributor, WeaponSystem and TemrminalSystem can be null on closing (they are not in the ship but in the logical group). That's why they are null-checked
            if (ResourceDistributor != null)
            {
                ProfilerShort.Begin("Unregister Power producer");
                var powerProducer = block.Components.Get <MyResourceSourceComponent>();
                if (powerProducer != null)
                {
                    ResourceDistributor.RemoveSource(powerProducer);
                }

                ProfilerShort.BeginNextBlock("Unregister Power consumer");
                var powerConsumer = block.Components.Get <MyResourceSinkComponent>();
                if (!(block is MyThrust) && powerConsumer != null)
                {
                    ResourceDistributor.RemoveSink(powerConsumer);
                }

                ProfilerShort.End();

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

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

            ProfilerShort.BeginNextBlock("Unregister functional block");
            if (TerminalSystem != null)
            {
                var functionalBlock = block as MyTerminalBlock;
                if (functionalBlock != null)
                {
                    TerminalSystem.Remove(functionalBlock);
                }
            }

            // CH: We probably don't need to unregister controller blocks here. It's done in ShipController's OnUnregisteredFromGridSystems

            /*ProfilerShort.BeginNextBlock("Unregister controller block");
             * if (ControlSystem != null)
             * {
             *  var controllableBlock = block as MyShipController;
             *  if (controllableBlock != null && controllableBlock.ControllerInfo.Controller != null)
             *      ControlSystem.RemoveControllerBlock(controllableBlock);
             * }*/

            ProfilerShort.BeginNextBlock("Unregister inventory block");
            var inventoryBlock = (block != null && block.HasInventory) ? block : null;

            if (inventoryBlock != null && inventoryBlock.HasInventory)
            {
                ConveyorSystem.Remove(inventoryBlock);
            }

            ProfilerShort.BeginNextBlock("Unregister conveyor block");
            var conveyorBlock = block as IMyConveyorEndpointBlock;

            if (conveyorBlock != null)
            {
                ConveyorSystem.RemoveConveyorBlock(conveyorBlock);
            }

            ProfilerShort.BeginNextBlock("Unregister segment block");
            var segmentBlock = block as IMyConveyorSegmentBlock;

            if (segmentBlock != null)
            {
                ConveyorSystem.RemoveSegmentBlock(segmentBlock);
            }

            ProfilerShort.BeginNextBlock("Unregister Reflector light");
            var reflectorLight = block as MyReflectorLight;

            if (reflectorLight != null)
            {
                ReflectorLightSystem.Unregister(reflectorLight);
            }

            if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
            {
                ProfilerShort.BeginNextBlock("Unregister wheel");
                var wheel = block as MyMotorSuspension;
                if (wheel != null)
                {
                    WheelSystem.Unregister(wheel);
                }
            }

            ProfilerShort.BeginNextBlock("Unregister landing gear");
            var gear = block as IMyLandingGear;

            if (gear != null)
            {
                LandingSystem.Unregister(gear);
            }

            ProfilerShort.BeginNextBlock("Unregister gyro");
            var gyro = block as MyGyro;

            if (gyro != null)
            {
                GyroSystem.Unregister(gyro);
            }

            ProfilerShort.BeginNextBlock("Unregister camera");
            var camera = block as MyCameraBlock;

            if (camera != null)
            {
                CameraSystem.Unregister(camera);
            }

            ProfilerShort.BeginNextBlock("block.OnUnregisteredFromGridSystems()");
            block.OnUnregisteredFromGridSystems();

            ProfilerShort.End();
        }
        public virtual void RegisterInSystems(MyCubeBlock block)
        {
            if (ResourceDistributor != null)
            {
                var powerProducer = block.Components.Get <MyResourceSourceComponent>();
                if (powerProducer != null)
                {
                    ResourceDistributor.AddSource(powerProducer);
                }

                var powerConsumer = block.Components.Get <MyResourceSinkComponent>();
                if (!(block is MyThrust) && powerConsumer != null)
                {
                    ResourceDistributor.AddSink(powerConsumer);
                }

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

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

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

            // CH: We probably don't need to register controller blocks here. Block that's being added to a grid should not have a controller set
            var controllableBlock = block as MyShipController;

            Debug.Assert(controllableBlock == null || controllableBlock.ControllerInfo.Controller == null, "Controller of added block is not null. Call Cestmir");

            /*if (ControlSystem != null)
             * {
             *  var controllableBlock = block as MyShipController;
             *  if (controllableBlock != null && controllableBlock.ControllerInfo.Controller != null)
             *      ControlSystem.AddControllerBlock(controllableBlock);
             * }*/

            var inventoryBlock = (block != null && block.HasInventory) ? block : null;

            if (inventoryBlock != null)
            {
                ConveyorSystem.Add(inventoryBlock);
            }

            var conveyorBlock = block as IMyConveyorEndpointBlock;

            if (conveyorBlock != null)
            {
                conveyorBlock.InitializeConveyorEndpoint();
                ConveyorSystem.AddConveyorBlock(conveyorBlock);
            }

            var segmentBlock = block as IMyConveyorSegmentBlock;

            if (segmentBlock != null)
            {
                segmentBlock.InitializeConveyorSegment();
                ConveyorSystem.AddSegmentBlock(segmentBlock);
            }

            var reflectorLight = block as MyReflectorLight;

            if (reflectorLight != null)
            {
                ReflectorLightSystem.Register(reflectorLight);
            }

            if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
            {
                var wheel = block as MyMotorSuspension;
                if (wheel != null)
                {
                    WheelSystem.Register(wheel);
                }
            }

            var landingGear = block as IMyLandingGear;

            if (landingGear != null)
            {
                LandingSystem.Register(landingGear);
            }

            var gyro = block as MyGyro;

            if (gyro != null)
            {
                GyroSystem.Register(gyro);
            }

            var camera = block as MyCameraBlock;

            if (camera != null)
            {
                CameraSystem.Register(camera);
            }

            block.OnRegisteredToGridSystems();
        }
예제 #6
0
        internal void ReScanBlockGroups()
        {
            if (TerminalSystem == null)
            {
                TerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(MyGrid);
            }
            if (TerminalSystem != null)
            {
                TerminalSystem.GetBlockGroups(null, group =>
                {
                    GroupInfo groupInfo = null;
                    if (BlockGroups.TryGetValue(group.Name, out groupInfo))
                    {
                        groupInfo.ChangeState = GroupInfo.ChangeStates.None;
                        groupInfo.Name        = group.Name;
                    }

                    group.GetBlocks(null, block =>
                    {
                        var cube = (MyCubeBlock)block;
                        WeaponComponent comp;
                        if (cube.Components.TryGet(out comp) && SubGrids.Contains(cube.CubeGrid))
                        {
                            if (groupInfo == null)
                            {
                                groupInfo             = Session.GroupInfoPool.Get();
                                groupInfo.Name        = group.Name;
                                groupInfo.ChangeState = GroupInfo.ChangeStates.Add;
                                BlockGroups.Add(group.Name, groupInfo);
                            }
                            groupInfo.Comps.Add(comp);
                            if (groupInfo.ChangeState == GroupInfo.ChangeStates.None)
                            {
                                groupInfo.ChangeState = GroupInfo.ChangeStates.Modify;
                            }
                        }
                        return(false);
                    });

                    return(false);
                });
                BlockGroups.ApplyAdditionsAndModifications();
                foreach (var group in BlockGroups)
                {
                    if (group.Value.ChangeState == GroupInfo.ChangeStates.None)
                    {
                        group.Value.Comps.Clear();
                        Session.GroupInfoPool.Return(group.Value);
                        BlockGroups.Remove(group.Key);
                    }
                    else
                    {
                        group.Value.ChangeState = GroupInfo.ChangeStates.None;
                    }

                    if (Session.MpActive && group.Value.Comps != null)
                    {
                        foreach (var comp in group.Value.Comps)
                        {
                            if (comp.Set?.Value?.Overrides != null)
                            {
                                SyncGridOverrides(this, group.Key, comp.Set.Value.Overrides);
                            }
                            break;
                        }
                    }
                }
                BlockGroups.ApplyRemovals();

                ScanBlockGroups = false;
            }
        }
예제 #7
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;
        }
예제 #8
0
        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;

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

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

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

            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.Components.Get <MyResourceSourceComponent>();
                    if (producer != null)
                    {
                        ResourceDistributor.AddSource(producer);
                    }

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

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

                    var weapon = block.FatBlock 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;
            ResourceDistributor = group.ResourceDistributor;
            WeaponSystem        = group.WeaponSystem;

            if (string.IsNullOrEmpty(ResourceDistributor.DebugName))
            {
                ResourceDistributor.DebugName = m_cubeGrid.ToString();
            }

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

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

            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);
                    }
                }
            }
        }