public bool IsChildOf(MyCubeGrid parentGrid, MyEntity entity) { HashSet <MyEntity> set; MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node node = base.GetNode(parentGrid); if ((node != null) && (node.Children.Count > 0)) { using (SortedDictionary <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node> .Enumerator enumerator = node.ChildLinks.GetEnumerator()) { while (true) { if (!enumerator.MoveNext()) { break; } KeyValuePair <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node> current = enumerator.Current; if ((this.GetParentLinkId(current.Value) == current.Key) && (current.Value.NodeData == entity)) { return(true); } } } } return((node != null) && (this.m_nonGridChildren.TryGetValue(parentGrid.EntityId, out set) && set.Contains(entity))); }
public bool IsCyclic(MyCubeGrid grid) { MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node node = base.GetNode(grid); if ((node != null) && (node.Children.Count > 0)) { using (SortedDictionary <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node> .Enumerator enumerator = node.ChildLinks.GetEnumerator()) { while (true) { bool flag; if (!enumerator.MoveNext()) { break; } KeyValuePair <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node> current = enumerator.Current; if (this.GetParentLinkId(current.Value) != current.Key) { flag = true; } else { if (!this.IsCyclic(current.Value.NodeData)) { continue; } flag = true; } return(flag); } } } return(false); }
public void ApplyOnAllChildren(MyEntity entity, Action <MyEntity> action) { MyCubeGrid grid = entity as MyCubeGrid; if (grid != null) { HashSet <MyEntity> set; MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node node = base.GetNode(grid); if ((node != null) && (node.Children.Count > 0)) { foreach (KeyValuePair <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node> pair in node.ChildLinks) { if (this.GetParentLinkId(pair.Value) == pair.Key) { action(pair.Value.NodeData); } } } if ((node != null) && this.m_nonGridChildren.TryGetValue(grid.EntityId, out set)) { foreach (MyEntity entity2 in set) { action(entity2); } } } }
public void UpdateDynamicState(MyCubeGrid grid) { bool flag = this.PhysicalDynamic.GetGroup(grid) != null; bool flag2 = !grid.IsStatic; if (flag && !flag2) { this.PhysicalDynamic.BreakAllLinks(grid); } else if (!flag & flag2) { MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node node = this.Physical.GetNode(grid); if (node != null) { foreach (KeyValuePair <long, MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node> pair in node.ChildLinks) { if (!pair.Value.NodeData.IsStatic) { this.PhysicalDynamic.CreateLink(pair.Key, grid, pair.Value.NodeData); } } foreach (KeyValuePair <long, MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node> pair2 in node.ParentLinks) { if (!pair2.Value.NodeData.IsStatic) { this.PhysicalDynamic.CreateLink(pair2.Key, pair2.Value.NodeData, grid); } } } } }
internal static bool IsMajorGroup(MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group a, MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group b) { float sum = 0; foreach (var n in a.Nodes) { if (n.NodeData.Physics != null) { sum += n.NodeData.Physics.Mass; } } foreach (var n in b.Nodes) { if (n.NodeData.Physics != null) { sum -= n.NodeData.Physics.Mass; } } return(sum > 0); // Default implementation so far //return MyGroups<MyCubeGrid, MyGridPhysicalGroupData>.IsMajorGroup(a, b); }
internal static bool HasSameGroupAndIsGrid <TGroupData>(this MyGroups <MyCubeGrid, TGroupData> groups, IMyEntity gridA, IMyEntity gridB) where TGroupData : IGroupData <MyCubeGrid>, new() { var a = gridA as MyCubeGrid; var b = gridB as MyCubeGrid; return(a != null && b != null && groups.HasSameGroup(a, b)); }
public static void MarkGroupDirty(MyCubeGrid grid) { MyGroups <MyCubeGrid, MySharedTensorData> .Group group = Static.GetGroup(grid); if (group != null) { group.GroupData.MarkDirty(); } }
public MyCubeGrid GetParent(MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node node) { if (node.m_parents.Count == 0) { return(null); } return(node.m_parents.FirstPair <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node>().Value.NodeData); }
public long GetParentLinkId(MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node node) { if (node.m_parents.Count == 0) { return(0L); } return(node.m_parents.FirstPair <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node>().Key); }
public static HashSetReader <MyGroups <MyCubeGrid, MySharedTensorData> .Node> GetGridsInSameGroup(MyCubeGrid groupRepresentative) { MyGroups <MyCubeGrid, MySharedTensorData> .Group group = Static.GetGroup(groupRepresentative); if (group != null) { return(group.Nodes); } return(new HashSetReader <MyGroups <MyCubeGrid, MySharedTensorData> .Node>()); }
public List <SelectableGroup> GetAllGroups(int without = -1) { if (MyPermission.Groups == true) { return(FillWithChildren(GetParentGroup(without), without).ConvertToViewModel()); } return(MyGroups.ConvertToViewModel()); }
private void FillPBComboBoxContent(ICollection <MyTerminalControlComboBoxItem> items) { MyTerminalControlComboBoxItem item = new MyTerminalControlComboBoxItem { Key = 0L, Value = MyCommonTexts.ScreenGraphicsOptions_AntiAliasing_None }; items.Add(item); bool flag = false; MyFatBlockReader <MyProgrammableBlock> fatBlocks = base.CubeGrid.GetFatBlocks <MyProgrammableBlock>(); foreach (MyProgrammableBlock block in fatBlocks) { item = new MyTerminalControlComboBoxItem { Key = block.EntityId, Value = MyStringId.GetOrCompute(block.CustomName.ToString()) }; items.Add(item); if (block.EntityId == this.m_attachedPB) { flag = true; } } MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Group group = MyCubeGridGroups.Static.Logical.GetGroup(base.CubeGrid); if (group != null) { foreach (MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Node node in group.Nodes) { if (node.NodeData != base.CubeGrid) { foreach (MyProgrammableBlock block2 in node.NodeData.GetFatBlocks <MyProgrammableBlock>()) { if (!block2.ShowInToolbarConfig) { continue; } item = new MyTerminalControlComboBoxItem { Key = block2.EntityId, Value = MyStringId.GetOrCompute(block2.CustomName.ToString()) }; items.Add(item); if (block2.EntityId == this.m_attachedPB) { flag = true; } } } } } if (!flag) { this.m_attachedPB.Value = 0L; } }
internal static void DebugDrawBlockGroups <TNode, TGroupData>(MyGroups <TNode, TGroupData> groups) where TGroupData : IGroupData <TNode>, new() where TNode : MySlimBlock { int hue = 0; BoundingBoxD aabb1, aabb2; foreach (var g in groups.Groups) { Color color = new Vector3((hue++ % 15) / 15.0f, 1, 1).HSVtoColor(); foreach (var m in g.Nodes) { try { m.NodeData.GetWorldBoundingBox(out aabb1); foreach (var child in m.Children) { m_tmpBlocksDebugHelper.Add(child); } // This is O(n^2), but it's only debug draw foreach (var child in m_tmpBlocksDebugHelper) { MyGroups <TNode, TGroupData> .Node node = null; int count = 0; foreach (var c in m.Children) { if (child == c) { node = c; count++; } } node.NodeData.GetWorldBoundingBox(out aabb2); MyRenderProxy.DebugDrawLine3D(aabb1.Center, aabb2.Center, color, color, false); MyRenderProxy.DebugDrawText3D((aabb1.Center + aabb2.Center) * 0.5f, count.ToString(), color, 1.0f, false); } var lightColor = new Color(color.ToVector3() + 0.25f); MyRenderProxy.DebugDrawSphere(aabb1.Center, 0.2f, lightColor.ToVector3(), 0.5f, false, true); MyRenderProxy.DebugDrawText3D(aabb1.Center, m.LinkCount.ToString(), lightColor, 1.0f, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); } finally { m_tmpBlocksDebugHelper.Clear(); } } } }
private void DrawNode(MyCubeGrid grid, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node node) { if (node.m_parents.Count <= 0) { MyRenderProxy.DebugDrawAxis(grid.PositionComp.WorldMatrix, 1f, false, false, false); } else { Color?colorTo = null; MyRenderProxy.DebugDrawArrow3D(grid.PositionComp.GetPosition(), node.m_parents.FirstPair <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node>().Value.NodeData.PositionComp.GetPosition(), Color.Orange, colorTo, false, 0.1, null, 0.5f, false); } }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); bool flag = base.HasLocalPlayerAccess(); if (base.IsWorking) { bool flag2 = false; if (flag && (MySession.Static.LocalCharacter != null)) { if (this.m_oreDetectorComponent.BroadcastUsingAntennas) { MyCharacter localCharacter = MySession.Static.LocalCharacter; MyCubeGrid topMostParent = base.GetTopMostParent(null) as MyCubeGrid; if (topMostParent != null) { MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Group group = MyCubeGridGroups.Static.Logical.GetGroup(topMostParent); if ((group != null) && localCharacter.HasAccessToLogicalGroup(group.GroupData)) { flag2 = true; } } } else { IMyControllableEntity controlledEntity = MySession.Static.ControlledEntity; if ((controlledEntity != null) && (controlledEntity.Entity != null)) { MyCubeGrid topMostParent = controlledEntity.Entity.GetTopMostParent(null) as MyCubeGrid; if (topMostParent != null) { MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Group group = MyCubeGridGroups.Static.Logical.GetGroup(topMostParent); MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Group group3 = MyCubeGridGroups.Static.Logical.GetGroup(base.CubeGrid); if (ReferenceEquals(topMostParent, base.CubeGrid) || (((group != null) && (group3 != null)) && (group.GroupData == group3.GroupData))) { flag2 = true; } } } } } if (flag2) { this.m_oreDetectorComponent.Update(base.PositionComp.GetPosition(), base.EntityId, false); this.m_oreDetectorComponent.SetRelayedRequest = true; } else { this.m_oreDetectorComponent.Clear(); } } }
internal static void DebugDrawBlockGroups <TNode, TGroupData>(MyGroups <TNode, TGroupData> groups) where TNode : MySlimBlock where TGroupData : IGroupData <TNode>, new() { int num = 0; using (HashSet <MyGroups <TNode, TGroupData> .Group> .Enumerator enumerator = groups.Groups.GetEnumerator()) { while (enumerator.MoveNext()) { num++; Color colorFrom = new Vector3(((float)(num % 15)) / 15f, 1f, 1f).HSVtoColor(); HashSetReader <MyGroups <TNode, TGroupData> .Node> nodes = enumerator.Current.Nodes; foreach (MyGroups <TNode, TGroupData> .Node node in nodes) { try { BoundingBoxD xd; node.NodeData.GetWorldBoundingBox(out xd, false); SortedDictionaryValuesReader <long, MyGroups <TNode, TGroupData> .Node> children = node.Children; foreach (MyGroups <TNode, TGroupData> .Node node2 in children) { m_tmpBlocksDebugHelper.Add(node2); } foreach (object obj2 in m_tmpBlocksDebugHelper) { BoundingBoxD xd2; MyGroups <TNode, TGroupData> .Node node3 = null; int num2 = 0; children = node.Children; foreach (MyGroups <TNode, TGroupData> .Node node4 in children) { if (obj2 == node4) { node3 = node4; num2++; } } node3.NodeData.GetWorldBoundingBox(out xd2, false); MyRenderProxy.DebugDrawLine3D(xd.Center, xd2.Center, colorFrom, colorFrom, false, false); MyRenderProxy.DebugDrawText3D((xd.Center + xd2.Center) * 0.5, num2.ToString(), colorFrom, 1f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false); } Color color = new Color(colorFrom.ToVector3() + 0.25f); MyRenderProxy.DebugDrawSphere(xd.Center, 0.2f, color.ToVector3(), 0.5f, false, true, true, false); MyRenderProxy.DebugDrawText3D(xd.Center, node.LinkCount.ToString(), color, 1f, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, -1, false); } finally { m_tmpBlocksDebugHelper.Clear(); } } } } }
public static bool IsRooted(MyCubeGrid grid) { if (!MyPhysics.InsideSimulation) { AssertThread(); } if (Static.m_roots.Contains(grid)) { return(true); } MyGroups <MyCubeGrid, MyFixedGridsGroupData> .Group group = Static.GetGroup(grid); return((group != null) ? group.GroupData.IsRooted : false); }
public MyEntity GetEntityConnectingToParent(MyCubeGrid grid) { MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node node = base.GetNode(grid); if (node == null) { return(null); } if (node.m_parents.Count == 0) { return(null); } return(MyEntities.GetEntityById(node.m_parents.FirstPair <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node>().Key, false)); }
public static BoundingBoxD GetWorldAABB(this MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group group) { var grids = group.Nodes.Select(n => n.NodeData); var startPos = grids.First().PositionComp.GetPosition(); var box = new BoundingBoxD(startPos, startPos); foreach (var aabb in grids.Select(g => g.PositionComp.WorldAABB)) { box.Include(aabb); } return(box); }
public void ApplyOnChildren(MyCubeGrid grid, Action <MyCubeGrid> action) { MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node node = base.GetNode(grid); if ((node != null) && (node.Children.Count > 0)) { foreach (KeyValuePair <long, MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node> pair in node.ChildLinks) { if (this.GetParentLinkId(pair.Value) == pair.Key) { action(pair.Value.NodeData); } } } }
private void RemoveChangedLargeBlockConnectionToSmallBlocks(MySlimBlock block, HashSet <MyCubeGrid> outSmallGrids) { MyGroups <MySlimBlock, MyBlockGroupData> .Group group = MyCubeGridGroups.Static.SmallToLargeBlockConnections.GetGroup(block); if (group != null) { m_tmpSlimBlocks.Clear(); foreach (MyGroups <MySlimBlock, MyBlockGroupData> .Node node in group.Nodes) { if (node.NodeData != block) { continue; } SortedDictionary <long, MyGroups <MySlimBlock, MyBlockGroupData> .Node> .ValueCollection.Enumerator enumerator = node.Children.GetEnumerator(); try { while (enumerator.MoveNext()) { MyGroups <MySlimBlock, MyBlockGroupData> .Node current = enumerator.Current; m_tmpSlimBlocks.Add(current.NodeData); } } finally { enumerator.Dispose(); continue; } break; } foreach (MySlimBlock block2 in m_tmpSlimBlocks) { this.DisconnectSmallToLargeBlock(block2, block); outSmallGrids.Add(block2.CubeGrid); } m_tmpSlimBlocks.Clear(); m_tmpGridList.Clear(); foreach (MyCubeGrid grid in outSmallGrids) { HashSet <MySlimBlockPair> set; if (this.m_mapSmallGridToConnectedBlocks.TryGetValue(grid, out set)) { m_tmpGridList.Add(grid); } } foreach (MyCubeGrid grid2 in m_tmpGridList) { outSmallGrids.Remove(grid2); } m_tmpGridList.Clear(); } }
public async Task <bool> SendGrid(string gridTarget, string serverTarget, string playername, long playerId, string ip, string targetAlias, bool debug = false) { var player = utils.GetPlayerByNameOrId(playername); string externalIP = utils.CreateExternalIP(Plugin.Config); string currentIp = externalIP + ":" + Sandbox.MySandboxGame.ConfigDedicated.ServerPort; try { Log.Warn("Getting Group"); MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group relevantGroup = utils.FindRelevantGroup(gridTarget, playerId); string pos = ""; foreach (var node in relevantGroup.Nodes) { MyCubeGrid grid = node.NodeData; pos = grid.PositionComp.GetPosition().ToString(); } if (relevantGroup == null) { utils.NotifyMessage("Cannot transfer somone elses grid!", player.SteamUserId); return(false); } Directory.CreateDirectory("SwitchTemp"); var path = string.Format(ExportPath, player.SteamUserId + "-" + gridTarget); if (!new GridImporter(Plugin, Context).SerializeGridsToPath(relevantGroup, gridTarget, path, player.DisplayName)) { return(false); } if (await UploadGridAsync(serverTarget, gridTarget, player.DisplayName, ip, currentIp, path, pos, targetAlias)) { /* Upload successful close the grids */ DeleteUploadedGrids(relevantGroup); /* Also delete local file */ File.Delete(path); return(true); } } catch (Exception e) { Log.Fatal(e, " Target: " + gridTarget + " Server: " + serverTarget + " id: " + playerId); return(false); } return(false); }
public MyCubeGrid GetRoot(MyCubeGrid grid) { MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Group group = base.GetGroup(grid); if (group == null) { return(grid); } MyCubeGrid root = group.GroupData.m_root; if (root == null) { root = grid; } return(root); }
private void DeleteUploadedGrids(MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group relevantGroup) { foreach (var node in relevantGroup.Nodes) { MyCubeGrid grid = node.NodeData; /* We wanna Skip Projections... always */ if (grid.Physics == null) { continue; } grid.Close(); } }
public static void UnmarkGridRoot(MyCubeGrid grid) { AssertThread(); if (Static.m_roots.Remove(grid)) { MyGroups <MyCubeGrid, MyFixedGridsGroupData> .Group group = Static.GetGroup(grid); if (group == null) { MyFixedGridsGroupData.ConvertGrid(grid, false); } else { group.GroupData.OnRootRemoved(); } } }
public static bool MajorSelector(MyGroups <MyCubeGrid, MyFixedGrids.MyFixedGridsGroupData> .Group major, MyGroups <MyCubeGrid, MyFixedGrids.MyFixedGridsGroupData> .Group minor) { bool flag = minor.GroupData.m_rootedGrids > 0; if (major.GroupData.m_rootedGrids > 0) { if (!flag) { return(true); } } else if (flag) { return(false); } return(major.Nodes.Count >= minor.Nodes.Count); }
public static async Task <IList <Group> > GetMyGroupsAsync() { GraphServiceClient client = new GraphServiceClient(new GraphAuthenticationProvider()); HttpRequestMessage reqMsg = client.Me.MemberOf.References.Request().GetHttpRequestMessage(); reqMsg.RequestUri = new Uri("https://graph.microsoft.com/v1.0/me/memberOf/$/microsoft.graph.group?$filter=groupTypes/any(a:a%20eq%20'unified')"); await client.AuthenticationProvider.AuthenticateRequestAsync(reqMsg); var response = await client.HttpProvider.SendAsync(reqMsg); var json = await response.Content.ReadAsStringAsync(); MyGroups grps = JsonConvert.DeserializeObject(json, typeof(MyGroups)) as MyGroups; return(grps.value.ToList()); }
public static bool Repair(MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group group, CommandContext Context) { foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes) { MyCubeGrid grid = groupNodes.NodeData; var gridOwner = OwnershipUtils.GetOwner(grid); HashSet <MySlimBlock> blocks = grid.GetBlocks(); foreach (MySlimBlock block in blocks) { long owner = block.OwnerId; if (owner == 0) { owner = gridOwner; } if (block.CurrentDamage > 0 || block.HasDeformation) { block.ClearConstructionStockpile(null); block.IncreaseMountLevel(block.MaxIntegrity, owner, null, 10000, true); MyCubeBlock cubeBlock = block.FatBlock; if (cubeBlock != null) { grid.ChangeOwnerRequest(grid, cubeBlock, 0, MyOwnershipShareModeEnum.Faction); if (owner != 0) { grid.ChangeOwnerRequest(grid, cubeBlock, owner, MyOwnershipShareModeEnum.Faction); } } } } } return(true); }
public void UpdateRoot(MyCubeGrid node) { if (!MyEntities.IsClosingAll) { MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Group group = base.GetGroup(node); if (group != null) { MyCubeGrid newRoot = this.CalculateNewRoot(group); group.GroupData.m_root = newRoot; if (newRoot != null) { base.ReplaceRoot(newRoot); using (HashSet <MyGroups <MyCubeGrid, MyGridPhysicalHierarchyData> .Node> .Enumerator enumerator = group.Nodes.GetEnumerator()) { while (enumerator.MoveNext()) { enumerator.Current.NodeData.HierarchyUpdated(newRoot); } } } } } }
private static CheckResult GetGroup(MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group group) { List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(); List <MyCubeGrid> gridsList = new List <MyCubeGrid>(); foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes) { MyCubeGrid grid = groupNodes.NodeData; gridsList.Add(grid); } foreach (MyCubeGrid grid in gridsList) { Log.Error(grid.DisplayName.ToString); var GridName = grid.DisplayName; var FolderDirectory = ReferralCore.Instance.StoragePath; GridMethods methods = new GridMethods(FolderDirectory, GridName); Task T = new Task(() => methods.SaveGrids(grid, GridName)); T.Start(); } return(CheckResult.SHIP_FIXED); }