public void SubGridChanges(bool clean = false, bool dupCheck = false) { foreach (var grid in AddSubGrids) { if (grid == MyGrid) { continue; } RegisterSubGrid(grid, dupCheck); } AddSubGrids.Clear(); foreach (var grid in RemSubGrids) { if (grid == MyGrid) { continue; } UnRegisterSubGrid(grid); } RemSubGrids.Clear(); if (!clean) { UpdateRoot(); } }
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 SubGridDetect() { if (PrevSubGrids.Count == 0) { return; } AddSubGrids.Clear(); foreach (var sub in PrevSubGrids) { AddSubGrids.Add(sub); TmpSubGrids.Add(sub); } TmpSubGrids.IntersectWith(RemSubGrids); RemSubGrids.ExceptWith(AddSubGrids); AddSubGrids.ExceptWith(TmpSubGrids); TmpSubGrids.Clear(); SubGridsChanged = AddSubGrids.Count != 0 || RemSubGrids.Count != 0; }
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 Scan() { using (_scanLock.AcquireExclusiveUsing()) { if (!Scanning && Session.Tick - _lastScan > 100) { Scanning = true; _lastScan = Session.Tick; GridVolume.Radius = MaxTargetingRange; MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref GridVolume, _possibleTargets); foreach (var grid in PrevSubGrids) { RemSubGrids.Add(grid); } PrevSubGrids.Clear(); for (int i = 0; i < _possibleTargets.Count; i++) { var ent = _possibleTargets[i]; using (ent.Pin()) { if (ent is MyVoxelBase || ent.Physics == null || ent is MyFloatingObject || ent.MarkedForClose || !ent.InScene || ent.IsPreview || ent.Physics.IsPhantom) { continue; } var grid = ent as MyCubeGrid; if (grid != null && MyGrid.IsSameConstructAs(grid)) { PrevSubGrids.Add(grid); continue; } Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entInfo; if (!CreateEntInfo(ent, MyOwner, out entInfo)) { continue; } switch (entInfo.Relationship) { case MyRelationsBetweenPlayerAndBlock.Owner: case MyRelationsBetweenPlayerAndBlock.FactionShare: case MyRelationsBetweenPlayerAndBlock.Friends: continue; } if (grid != null) { FatMap fatMap; if (!Session.GridToFatMap.TryGetValue(grid, out fatMap) || fatMap.Trash) { continue; } var allFat = fatMap.MyCubeBocks; var fatCount = allFat.Count; if (fatCount <= 0 || !grid.IsPowered) { continue; } if (fatCount <= 20) // possible debris { var valid = false; for (int j = 0; j < fatCount; j++) { var fat = allFat[j]; if (fat is IMyTerminalBlock && fat.IsWorking) { valid = true; break; } } if (!valid) { continue; } } int partCount; GridAi targetAi; if (Session.GridTargetingAIs.TryGetValue(grid, out targetAi)) { targetAi.TargetAisTmp.Add(this); TargetAisTmp.Add(targetAi); partCount = targetAi.Construct.BlockCount; } else { partCount = fatMap.MostBlocks; } NewEntities.Add(new DetectInfo(Session, ent, entInfo, partCount, fatCount)); ValidGrids.Add(ent); } else { NewEntities.Add(new DetectInfo(Session, ent, entInfo, 1, 0)); } } } FinalizeTargetDb(); SubGridDetect(); } Scanning = false; } }
internal void Scan() { MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref ScanVolume, _possibleTargets); NearByEntitiesTmp = _possibleTargets.Count; foreach (var grid in PrevSubGrids) { RemSubGrids.Add((MyCubeGrid)grid); } PrevSubGrids.Clear(); for (int i = 0; i < NearByEntitiesTmp; i++) { var ent = _possibleTargets[i]; using (ent.Pin()) { if (ent is MyVoxelBase || ent.Physics == null || ent is MyFloatingObject || ent.MarkedForClose || !ent.InScene || ent.IsPreview || ent.Physics.IsPhantom) { continue; } var grid = ent as MyCubeGrid; if (grid != null && MyGrid.IsSameConstructAs(grid)) { PrevSubGrids.Add(grid); continue; } Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entInfo; if (!CreateEntInfo(ent, AiOwner, out entInfo)) { continue; } switch (entInfo.Relationship) { case MyRelationsBetweenPlayerAndBlock.Owner: case MyRelationsBetweenPlayerAndBlock.FactionShare: case MyRelationsBetweenPlayerAndBlock.Friends: continue; } if (grid != null) { GridMap gridMap; if (!Session.GridToInfoMap.TryGetValue(grid, out gridMap) || gridMap.Trash) { continue; } var allFat = gridMap.MyCubeBocks; var fatCount = allFat.Count; if (fatCount <= 0) { continue; } var loneWarhead = false; if (fatCount <= 20) // possible debris { var valid = false; for (int j = 0; j < fatCount; j++) { var fat = allFat[j]; var warhead = fat is IMyWarhead; if (warhead || fat is IMyTerminalBlock && fat.IsWorking) { loneWarhead = warhead && fatCount == 1; valid = true; break; } } if (!valid) { continue; } } int partCount; GridAi targetAi; if (Session.GridTargetingAIs.TryGetValue(grid, out targetAi)) { targetAi.TargetAisTmp.Add(this); TargetAisTmp.Add(targetAi); partCount = targetAi.Construct.BlockCount; } else { partCount = gridMap.MostBlocks; } NewEntities.Add(new DetectInfo(Session, ent, entInfo, partCount, !loneWarhead? fatCount : 2));// bump warhead to 2 fatblocks so its not ignored by targeting ValidGrids.Add(ent); } else { NewEntities.Add(new DetectInfo(Session, ent, entInfo, 1, 0)); } } } FinalizeTargetDb(); SubGridDetect(); }