public void UnRegisterSubGrid(MyCubeGrid grid, bool clean = false) { if (!SubGridsRegistered.Contains(grid)) { Log.Line($"sub Grid Already UnRegistered: [Main]:{grid == MyGrid}"); } if (!clean) { SubGrids.Remove(grid); } SubGridsRegistered.Remove(grid); grid.OnFatBlockAdded -= FatBlockAdded; grid.OnFatBlockRemoved -= FatBlockRemoved; foreach (var cube in grid.GetFatBlocks()) { var battery = cube as MyBatteryBlock; if (InventoryMonitor.ContainsKey(cube) || battery != null && Batteries.Contains(battery)) { FatBlockRemoved(cube); } } GridAi removeAi; if (!Session.GridTargetingAIs.ContainsKey(grid)) { Session.GridToMasterAi.TryRemove(grid, out removeAi); } }
/// <summary> /// This handles the creation of the /// </summary> private void Initialize() { byte[] overviewHeader = new byte[176]; using (Stream str = GetStream()) { if (str == null) { return; } str.Read(overviewHeader, 0, 176); } byte[] bCount = new byte[4]; Array.Copy(overviewHeader, 8 + 32, bCount, 0, 4); if (!BitConverter.IsLittleEndian) { Array.Reverse(bCount); } int numGrids = BitConverter.ToInt32(bCount, 0); long offset = 176; for (int iGrid = 0; iGrid < numGrids; iGrid++) { string location = FileIsEmbedded ? ManifestResourceString : GridFilePath; NadTable sub = new GsbNadTable(location, offset, FileIsEmbedded, RequiresDecompression); sub.ReadHeader(); offset += 176 + sub.NumPhis * sub.NumLambdas * 16; SubGrids.Add(sub); } }
private void InitCells() { Enumerable.Range(1, 9).ToList().ForEach((i) => _rows.Add(new SubCellsVM())); Enumerable.Range(1, 9).ToList().ForEach((i) => _columns.Add(new SubCellsVM())); foreach (SubGrid subGrid in _mainGrid.SubGrids3x3) { SubGrids.Add(new SubGridVM(subGrid, _selectedNumber)); } for (int rowId = 0; rowId < 9; rowId++) { var subGridOffset = 3 * (rowId / 3); var rowOffset = 3 * (rowId % 3); _rows[rowId].Cells.AddRange(SubGrids[subGridOffset].Cells.Skip(rowOffset).Take(3)); _rows[rowId].Cells.AddRange(SubGrids[subGridOffset + 1].Cells.Skip(rowOffset).Take(3)); _rows[rowId].Cells.AddRange(SubGrids[subGridOffset + 2].Cells.Skip(rowOffset).Take(3)); } for (int colId = 0; colId < 9; colId++) { for (int rowId = 0; rowId < 9; rowId++) { _columns[colId].Cells.Add(_rows[rowId].Cells[colId]); } } }
public List <Cell> GetDomainCells(Cell cell) { var cells = new List <Cell>(); cells.AddRange(Verticals.First(v => v.Contains(cell))); cells.AddRange(Horizontals.First(v => v.Contains(cell))); cells.AddRange(SubGrids.First(v => v.Contains(cell))); return(cells.Distinct().ToList()); }
internal void CleanUp() { RegisterMyGridEvents(false); foreach (var grid in SubGrids) { if (grid == MyGrid) { continue; } RemSubGrids.Add(grid); } AddSubGrids.Clear(); SubGridChanges(); SubGrids.Clear(); Obstructions.Clear(); TargetAis.Clear(); EntitiesInRange.Clear(); Batteries.Clear(); Targets.Clear(); SortedTargets.Clear(); BlockGroups.Clear(); Weapons.Clear(); WeaponsIdx.Clear(); WeaponBase.Clear(); AmmoInventories.Clear(); Inventories.Clear(); LiveProjectile.Clear(); DeadProjectiles.Clear(); ControllingPlayers.Clear(); SourceCount = 0; BlockCount = 0; MyOwner = 0; PointDefense = false; FadeOut = false; SupressMouseShoot = false; OverPowered = false; UpdatePowerSources = false; AvailablePowerChanged = false; PowerIncrease = false; RequestedPowerChanged = false; RequestIncrease = false; DbReady = false; Focus.Clean(); MyShieldTmp = null; MyShield = null; MyPlanetTmp = null; MyPlanet = null; TerminalSystem = null; LastWeaponTerminal = null; LastTerminal = null; PowerDistributor = null; }
public void CleanSubGrids() { foreach (var grid in SubGrids) { if (grid == MyGrid) { continue; } UnRegisterSubGrid(grid, true); } SubGrids.Clear(); RemSubGrids.Clear(); AddSubGrids.Clear(); TmpSubGrids.Clear(); SubGridsChanged = false; }
public void UnRegisterSubGrid(MyCubeGrid grid, bool clean = false) { if (!SubGridsRegistered.Contains(grid)) { Log.Line($"sub Grid Already UnRegistered: [Main]:{grid == MyGrid}"); } if (!clean) { SubGrids.Remove(grid); } SubGridsRegistered.Remove(grid); grid.OnFatBlockAdded -= FatBlockAdded; grid.OnFatBlockRemoved -= FatBlockRemoved; GridAi removeAi; if (!Session.GridTargetingAIs.ContainsKey(grid)) { Session.GridToMasterAi.TryRemove(grid, out removeAi); } }
public void SubGridChanges() { foreach (var grid in AddSubGrids) { if (grid == MyGrid) { continue; } grid.OnFatBlockAdded += FatBlockAdded; grid.OnFatBlockRemoved += FatBlockRemoved; FatMap fatMap; if (Session.GridToFatMap.TryGetValue(grid, out fatMap)) { var blocks = fatMap.MyCubeBocks; for (int i = 0; i < blocks.Count; i++) { FatBlockAdded(blocks[i]); } } } AddSubGrids.Clear(); foreach (var grid in RemSubGrids) { if (grid == MyGrid) { continue; } SubGrids.Remove(grid); grid.OnFatBlockAdded -= FatBlockAdded; grid.OnFatBlockRemoved -= FatBlockRemoved; } RemSubGrids.Clear(); UpdateConstruct(); }
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; } }