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); }
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( ); }
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)); }
/// <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); } }
/// <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); } }
/// <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); } }
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( ); }
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); }
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(); } }
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); } } } }
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 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; }
protected static void CreateGridGroupLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child) { MyCubeGridGroups.Static.CreateLink(type, linkId, parent, child); }
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(); }
public void RemoveNode(GridLinkTypeEnum type, MyCubeGrid grid) { GetGroups(type).RemoveNode(grid); }
public void AddNode(GridLinkTypeEnum type, MyCubeGrid grid) { GetGroups(type).AddNode(grid); }
public MyGroupsBase <MyCubeGrid> GetGroups(GridLinkTypeEnum type) { return(m_groupsByType[(int)type]); }
/// <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); }
public MyGroupsBase <MyCubeGrid> GetGroups(GridLinkTypeEnum type) => this.m_groupsByType[(int)type];
protected static bool BreakGridGroupLink(GridLinkTypeEnum type, long linkId, MyCubeGrid parent, MyCubeGrid child) { return(MyCubeGridGroups.Static.BreakLink(type, linkId, parent, child)); }
/// <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)); }