Ejemplo n.º 1
0
        public static HashSet <GridGroup> GetAllGroups(GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical)
        {
            HashSet <MyEntity> entities = new HashSet <MyEntity>();

            Wrapper.GameAction(() => entities = MyEntities.GetEntities(  ));
            return(GetGroups(entities, linkType));
        }
        public override bool HandleCommand(ulong userId, string[] words)
        {
            GridLinkTypeEnum connectionType = GridLinkTypeEnum.Logical;

            if (words.FirstOrDefault(x => x.ToLower( ) == "physical") != null)
            {
                connectionType = GridLinkTypeEnum.Physical;
            }

            HashSet <GridGroup> groups = GridGroup.GetAllGroups(connectionType);
            int groupsCount            = 0;
            int gridsCount             = 0;

            foreach (GridGroup group in groups)
            {
                if (!group.CubeBlocks.Any(x => x?.FatBlock is IMyBeacon))
                {
                    groupsCount++;
                    gridsCount += group.Grids.Count;
                    group.Close( );
                    Communication.SendPrivateInformation(userId, $"Found group with parent {group.Parent.DisplayName} ({group.Parent.EntityId}) at {group.Parent.PositionComp.GetPosition( )} with no beacon.");
                }
            }

            Communication.SendPrivateInformation(userId, $"Removed {gridsCount} grids in {groupsCount} groups with no beacon.");

            return(true);
        }
Ejemplo n.º 3
0
        public GridGroup( MyCubeGrid grid, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical )
        {
            _linkType = linkType;

            if ( grid.InScene )
            {
                List<MyCubeGrid> tmpList = new List<MyCubeGrid>( );

                //find the group containing this grid with the given link type
                Wrapper.GameAction( ( ) => tmpList = MyCubeGridGroups.Static.GetGroups( linkType ).GetGroupNodes( grid ) );

                _grids.UnionWith( tmpList );
            }
            //manually create a group for out of scene grids because they have a null group (yay Dusan fixed the crash)
            else
            {
                //use the old method to filter out grids with pistons or rotors, for safety
                HashSet<IMyEntity> thisEntity = new HashSet<IMyEntity>();
                HashSet<IMyEntity> returnSet = new HashSet<IMyEntity>();
                thisEntity.Add( (IMyEntity)grid );
                CubeGrids.GetGridsUnconnected( returnSet, thisEntity );

                if ( returnSet.Count > 0 )
                    _grids.Add( grid );
                else
                    return;
            }

            //populate our internal lists
            ComputeParent( );
            ComputeCubeBlocks( );
            ComputeFatBlocks( );
            ComputeSmallOwners( );
            ComputeBigOwners( );
        }
Ejemplo n.º 4
0
 public bool BreakLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child = null)
 {
     if (type == GridLinkTypeEnum.Physical)
     {
         this.PhysicalDynamic.BreakLink(linkId, parent, child);
     }
     return(this.GetGroups(type).BreakLink(linkId, parent, child));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates link between parent and child.
 /// Parent is owner of constraint.
 /// LinkId must be unique only for parent, for grid it can be packed position of block which created constraint.
 /// </summary>
 public void CreateLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child)
 {
     GetGroups(type).CreateLink(linkId, parent, child);
     if (type == GridLinkTypeEnum.Physical && !parent.IsStatic && !child.IsStatic)
     {
         PhysicalDynamic.CreateLink(linkId, parent, child);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Called by constraint owner
        /// </summary>
        protected virtual void OnConstraintRemoved(GridLinkTypeEnum type, Sandbox.ModAPI.IMyEntity detachedEntity)
        {
            var detachedGrid = detachedEntity as MyCubeGrid;

            if (detachedGrid != null)
            {
                MyCubeGridGroups.Static.BreakLink(type, EntityId, CubeGrid, detachedGrid);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called by constraint owner
        /// </summary>
        protected virtual void OnConstraintAdded(GridLinkTypeEnum type, Sandbox.ModAPI.IMyEntity attachedEntity)
        {
            var attachedGrid = attachedEntity as MyCubeGrid;

            if (attachedGrid != null)
            {
                // This crashes when connector (or anything else) connects to two things at the same time
                MyCubeGridGroups.Static.CreateLink(type, EntityId, CubeGrid, attachedGrid);
            }
        }
Ejemplo n.º 8
0
        public GridGroup(MyCubeGrid grid, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical)
        {
            _linkType = linkType;

            if (grid.InScene)
            {
                List <MyCubeGrid> tmpList = new List <MyCubeGrid>( );

                //find the group containing this grid with the given link type
                Wrapper.GameAction(() => tmpList = MyCubeGridGroups.Static.GetGroups(linkType).GetGroupNodes(grid));

                _grids.UnionWith(tmpList);
            }
            //manually create a group for out of scene grids because they have a null group (yay Dusan fixed the crash)
            else
            {
                //use the old method to filter out grids with pistons or rotors, for safety
                HashSet <IMyEntity> thisEntity = new HashSet <IMyEntity>();
                HashSet <IMyEntity> returnSet  = new HashSet <IMyEntity>();
                thisEntity.Add((IMyEntity)grid);
                CubeGrids.GetGridsUnconnected(returnSet, thisEntity);

                if (returnSet.Count > 0)
                {
                    _grids.Add(grid);
                }
                else
                {
                    return;
                }
            }

            //populate our internal lists
            ComputeParent( );
            ComputeCubeBlocks( );
            ComputeFatBlocks( );
            ComputeSmallOwners( );
            ComputeBigOwners( );
        }
Ejemplo n.º 9
0
        public static HashSet <GridGroup> GetGroups(HashSet <MyEntity> entities, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical)
        {
            HashSet <GridGroup> result = new HashSet <GridGroup>();

            //Create a copy of the entities list;
            //group processing can take so long that the internal list of entities can change
            //which is Bad.
            MyEntity[] entitiesCopy = new MyEntity[entities.Count];
            entities.CopyTo(entitiesCopy);

            //on large servers this can run into the tens of seconds, so parallelize it
            Parallel.ForEach(entitiesCopy, (entity) =>
            {
                MyCubeGrid grid = entity as MyCubeGrid;

                if (grid?.Physics == null || grid.Closed)
                {
                    return;
                }

                lock (result)
                    foreach (var item in result)
                    {
                        if (item._grids.Contains(grid))
                        {
                            return;
                        }
                    }

                var newGroup = new GridGroup(grid, linkType);

                lock (result)
                    result.Add(newGroup);
            });

            return(result);
        }
 public static bool BreakGridGroupLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child)
 {
     return MyCubeGridGroups.Static.BreakLink(type, linkId, parent, child);
 }
 public static void CreateGridGroupLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child)
 {
     MyCubeGridGroups.Static.CreateLink(type, linkId, parent, child);
 }
Ejemplo n.º 12
0
        public void CutGroup(MyCubeGrid grid, GridLinkTypeEnum groupType)
        {
            if (grid == null)
                return;

            CopyGroup(grid, groupType);

            if (MyFakes.ENABLE_COPY_GROUP)
            {
                var group = MyCubeGridGroups.Static.GetGroups(groupType).GetGroupNodes(grid);
                foreach (var node in group)
                {
                    node.SendGridCloseRequest();
                }
            }
            else
            {
                grid.SendGridCloseRequest();
            }
        }
Ejemplo n.º 13
0
        public void CopyGroup(MyCubeGrid gridInGroup, GridLinkTypeEnum groupType)
        {
            if (gridInGroup == null)
                return;
            m_copiedGrids.Clear();
            m_copiedGridOffsets.Clear();

            if (MyFakes.ENABLE_COPY_GROUP && MyFakes.ENABLE_LARGE_STATIC_GROUP_COPY_FIRST)
            {
                // Find large static grid, large grid or small static grid if present as first group.
                var group = MyCubeGridGroups.Static.GetGroups(groupType).GetGroupNodes(gridInGroup);

                MyCubeGrid staticLargeGrid = null;
                MyCubeGrid largeGrid = null;
                MyCubeGrid smallStaticGrid = null;
                if (gridInGroup.GridSizeEnum == MyCubeSize.Large)
                {
                    largeGrid = gridInGroup;
                    if (gridInGroup.IsStatic)
                        staticLargeGrid = gridInGroup;
                }
                else if (gridInGroup.GridSizeEnum == MyCubeSize.Small && gridInGroup.IsStatic)
                    smallStaticGrid = gridInGroup;

                foreach (var node in group)
                {
                    if (largeGrid == null && node.GridSizeEnum == MyCubeSize.Large)
                        largeGrid = node;

                    if (staticLargeGrid == null && node.GridSizeEnum == MyCubeSize.Large && node.IsStatic)
                        staticLargeGrid = node;

                    if (smallStaticGrid == null && node.GridSizeEnum == MyCubeSize.Small && node.IsStatic)
                        smallStaticGrid = node;
                }

                MyCubeGrid firstGrid = staticLargeGrid != null ? staticLargeGrid : null;
                firstGrid = firstGrid != null ? firstGrid : (largeGrid != null ? largeGrid : null);
                firstGrid = firstGrid != null ? firstGrid : (smallStaticGrid != null ? smallStaticGrid : null);
                firstGrid = firstGrid != null ? firstGrid : gridInGroup;

                group = MyCubeGridGroups.Static.GetGroups(groupType).GetGroupNodes(firstGrid);

                CopyGridInternal(firstGrid);

                foreach (var node in group)
                {
                    if (node != firstGrid)
                        CopyGridInternal(node);
                }
            }
            else
            {
                CopyGridInternal(gridInGroup);

                if (MyFakes.ENABLE_COPY_GROUP)
                {
                    var group = MyCubeGridGroups.Static.GetGroups(groupType).GetGroupNodes(gridInGroup);
                    foreach (var node in group)
                    {
                        if (node != gridInGroup)
                            CopyGridInternal(node);
                    }
                }
            }

        }
Ejemplo n.º 14
0
 public static HashSet<GridGroup> GetAllGroups( GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical )
 {
     HashSet<MyEntity> entities = new HashSet<MyEntity>();
     Wrapper.GameAction( () => entities = MyEntities.GetEntities(  ) );
     return GetGroups( entities, linkType );
 }
Ejemplo n.º 15
0
        public static HashSet<GridGroup> GetGroups( HashSet<MyEntity> entities, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical )
        {
            HashSet<GridGroup> result = new HashSet<GridGroup>();

            //Create a copy of the entities list;
            //group processing can take so long that the internal list of entities can change
            //which is Bad.
            MyEntity[] entitiesCopy = new MyEntity[entities.Count];
            entities.CopyTo( entitiesCopy );

                //on large servers this can run into the tens of seconds, so parallelize it
            Parallel.ForEach( entitiesCopy, ( entity ) =>
                                            {
                                                MyCubeGrid grid = entity as MyCubeGrid;

                                                if (grid?.Physics == null || grid.Closed)
                                                    return;

                                                lock (result)
                                                    foreach(var item in result)
                                                        if ( item._grids.Contains( grid ) )
                                                            return;

                                                var newGroup = new GridGroup( grid, linkType );

                                                lock (result)
                                                    result.Add( newGroup );
                                            } );

            return result;
        }
Ejemplo n.º 16
0
 protected static void CreateGridGroupLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child)
 {
     MyCubeGridGroups.Static.CreateLink(type, linkId, parent, child);
 }
Ejemplo n.º 17
0
        public void CutGroup(MyCubeGrid grid, GridLinkTypeEnum groupType)
        {
            if (grid == null)
                return;

            CopyGroup(grid, groupType);

            if (MyFakes.ENABLE_COPY_GROUP)
            {
                var group = MyCubeGridGroups.Static.GetGroups(groupType).GetGroupNodes(grid);
                foreach (var node in group)
                {
                    foreach (var block in node.GetBlocks())
                    {
                        var cockpit = block.FatBlock as MyCockpit;
                        if (cockpit != null && cockpit.Pilot != null)
                            cockpit.Use();
                    }
                    node.SyncObject.SendCloseRequest();
                }
            }
            else
            {
                foreach (var block in grid.GetBlocks())
                {
                    var cockpit = block.FatBlock as MyCockpit;
                    if (cockpit != null && cockpit.Pilot != null)
                        cockpit.Use();
                }
                grid.SyncObject.SendCloseRequest();
            }
            Deactivate();
        }
Ejemplo n.º 18
0
 public void RemoveNode(GridLinkTypeEnum type, MyCubeGrid grid)
 {
     GetGroups(type).RemoveNode(grid);
 }
Ejemplo n.º 19
0
 public void AddNode(GridLinkTypeEnum type, MyCubeGrid grid)
 {
     GetGroups(type).AddNode(grid);
 }
Ejemplo n.º 20
0
 public MyGroupsBase <MyCubeGrid> GetGroups(GridLinkTypeEnum type)
 {
     return(m_groupsByType[(int)type]);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Creates link between parent and child.
 /// Parent is owner of constraint.
 /// LinkId must be unique only for parent, for grid it can be packed position of block which created constraint.
 /// </summary>
 public void CreateLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child)
 {
     GetGroups(type).CreateLink(linkId, parent, child);
 }
Ejemplo n.º 22
0
 public MyGroupsBase <MyCubeGrid> GetGroups(GridLinkTypeEnum type) =>
 this.m_groupsByType[(int)type];
Ejemplo n.º 23
0
 protected static bool BreakGridGroupLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child)
 {
     return(MyCubeGridGroups.Static.BreakLink(type, linkId, parent, child));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Breaks link between parent and child, you can set child to null to find it by linkId.
 /// Returns true when link was removed, returns false when link was not found.
 /// </summary>
 public bool BreakLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child = null)
 {
     PhysicalDynamic.BreakLink(linkId, parent, child);
     return(GetGroups(type).BreakLink(linkId, parent, child));
 }