internal void MonitorRefreshTasks(int x, ref List <MyEntity> monitorList, bool reInforce, ref bool newSub) { var s = _workData.ShieldList[x]; if (reInforce) { var newMode = !s.ReInforcedShield; if (!newMode) { return; } HashSet <MyCubeGrid> subs; lock (s.SubLock) { subs = SetMyCubeGridPool.Get(); subs.UnionWith(s.ShieldComp.SubGrids); } foreach (var sub in subs) { if (!_globalEntTmp.ContainsKey(sub)) { newSub = true; } _entRefreshQueue.Enqueue(sub); if (!s.WasPaused) { _globalEntTmp[sub] = _workData.Tick; } } subs.Clear(); SetMyCubeGridPool.Return(subs); s.ReInforcedShield = true; s.TicksWithNoActivity = 0; s.LastWokenTick = _workData.Tick; s.Asleep = false; } else { var newMode = false; if (s.ReInforcedShield) { HashSet <MyCubeGrid> subs; lock (s.SubLock) { subs = SetMyCubeGridPool.Get(); subs.UnionWith(s.ShieldComp.SubGrids); } foreach (var sub in subs) { _entRefreshQueue.Enqueue(sub); if (!s.WasPaused) { _globalEntTmp[sub] = _workData.Tick; } } subs.Clear(); SetMyCubeGridPool.Return(subs); //if (Enforced.Debug >= 2) Log.Line($"found Reinforce"); s.ReInforcedShield = false; s.TicksWithNoActivity = 0; s.LastWokenTick = _workData.Tick; s.Asleep = false; newMode = true; } if (!newMode) { var foundNewEnt = false; var disableVoxels = Enforced.DisableVoxelSupport == 1 || s.ShieldComp.Modulator == null || s.ShieldComp.Modulator.ModSet.Settings.ModulateVoxels; MyGamePruningStructure.GetTopmostEntitiesInBox(ref s.WebBox, monitorList); if (!s.WasPaused) { foreach (var ent in monitorList) { var voxel = ent as MyVoxelBase; if (ent == null || ent.MarkedForClose || (voxel == null && (ent.Physics == null || ent.Physics.IsPhantom || ent.DefinitionId == null)) || (!s.GridIsMobile && voxel != null) || (disableVoxels && voxel != null) || (voxel != null && voxel != voxel.RootVoxel)) { continue; } if (ent is IMyFloatingObject || ent is IMyEngineerToolBase || !s.WebSphere.Intersects(ent.PositionComp.WorldVolume)) { continue; } if (CustomCollision.NewObbPointsInShield(ent, s.DetectMatrixOutsideInv) > 0) { if (!_globalEntTmp.ContainsKey(ent)) { foundNewEnt = true; s.Asleep = false; } _globalEntTmp[ent] = _workData.Tick; } s.NewEntByShield = foundNewEnt; } } else { s.NewEntByShield = false; } if (!s.NewEntByShield) { var foundPlayer = false; foreach (var player in Players.Values) { var character = player.Character; if (character == null) { continue; } if (Vector3D.DistanceSquared(character.PositionComp.WorldMatrixRef.Translation, s.DetectionCenter) < SyncDistSqr) { foundPlayer = true; break; } } s.PlayerByShield = foundPlayer; } if (!s.PlayerByShield) { s.MoverByShield = false; var newMover = false; var moverList = ListMyEntityPool.Get(); MyGamePruningStructure.GetTopMostEntitiesInBox(ref s.ShieldBox3K, moverList, MyEntityQueryType.Dynamic); for (int i = 0; i < moverList.Count; i++) { var ent = moverList[i]; var meteor = ent as IMyMeteor; if (meteor != null) { if (CustomCollision.FutureIntersect(s, ent, s.DetectMatrixOutside, s.DetectMatrixOutsideInv)) { if (Enforced.Debug >= 2) { Log.Line($"[Future Intersecting Meteor] distance from shieldCenter: {Vector3D.Distance(s.DetectionCenter, ent.WorldMatrix.Translation)} - waking:"); } newMover = true; break; } continue; } if (!(ent.Physics == null || ent.Physics.IsPhantom || ent is MyCubeGrid || ent is IMyCharacter)) { continue; } var entPos = ent.PositionComp.WorldAABB.Center; var keyFound = s.EntsByMe.ContainsKey(ent); if (keyFound) { if (!s.EntsByMe[ent].Pos.Equals(entPos, 1e-3)) { MoverInfo moverInfo; s.EntsByMe.TryRemove(ent, out moverInfo); s.EntsByMe.TryAdd(ent, new MoverInfo(entPos, _workData.Tick)); if (moverInfo.CreationTick == _workData.Tick - 1) { if (Enforced.Debug >= 3 && s.WasPaused) { Log.Line($"[Moved] Ent:{ent.DebugName} - howMuch:{Vector3D.Distance(entPos, s.EntsByMe[ent].Pos)} - ShieldId [{s.Shield.EntityId}]"); } newMover = true; } break; } } else { if (Enforced.Debug >= 3) { Log.Line($"[NewMover] Ent:{ent.DebugName} - ShieldId [{s.Shield.EntityId}]"); } s.EntsByMe.TryAdd(ent, new MoverInfo(entPos, _workData.Tick)); } } moverList.Clear(); ListMyEntityPool.Return(moverList); s.MoverByShield = newMover; } if (_workData.Tick < s.LastWokenTick + 400) { s.Asleep = false; return; } } if (s.EntCleanUpTime) { s.EntCleanUpTime = false; if (!s.EntsByMe.IsEmpty) { var entsByMeTmp = new List <KeyValuePair <MyEntity, MoverInfo> >(); entsByMeTmp.AddRange(s.EntsByMe.Where(info => !info.Key.InScene || _workData.Tick - info.Value.CreationTick > EntMaxTickAge)); for (int i = 0; i < entsByMeTmp.Count; i++) { MoverInfo mInfo; s.EntsByMe.TryRemove(entsByMeTmp[i].Key, out mInfo); } } } } }
public Ent EntType(MyEntity ent) { if (ent is IMyFloatingObject) { if (CustomCollision.AllAabbInShield(ent.PositionComp.WorldAABB, DetectMatrixOutsideInv, _obbCorners)) { return(Ent.Ignore); } return(Ent.Floater); } var voxel = ent as MyVoxelBase; if (voxel != null && (Session.Enforced.DisableVoxelSupport == 1 || ShieldComp.Modulator == null || ShieldComp.Modulator.ModSet.Settings.ModulateVoxels || !GridIsMobile)) { return(Ent.Ignore); } if (EntityBypass.Contains(ent)) { return(Ent.Ignore); } var character = ent as IMyCharacter; if (character != null) { var getComponentOwner = ent as IMyComponentOwner <MyIDModule>; long playerId; MyIDModule targetIdModule; if (getComponentOwner != null && getComponentOwner.GetComponent(out targetIdModule)) { playerId = targetIdModule.Owner; } else { var controllingId = character.ControllerInfo?.ControllingIdentityId; playerId = controllingId ?? 0; } if (playerId == 0 || character.IsDead || character.Integrity <= 0) { return(Ent.Ignore); } var playerrelationship = MyIDModule.GetRelationPlayerBlock(MyCube.IDModule.Owner, playerId, MyOwnershipShareModeEnum.Faction); var modulateAllies = (ShieldComp.Modulator != null && ShieldComp.Modulator.ModSet.Settings.AllowAllies); if (playerrelationship == MyRelationsBetweenPlayerAndBlock.Owner || playerrelationship == MyRelationsBetweenPlayerAndBlock.FactionShare || modulateAllies && playerrelationship == MyRelationsBetweenPlayerAndBlock.Friends) { var playerInShield = CustomCollision.PointInShield(ent.PositionComp.WorldAABB.Center, DetectMatrixOutsideInv); return(playerInShield ? Ent.Protected : Ent.Friendly); } if (CustomCollision.NewObbPointsInShield(ent, DetectMatrixOutsideInv, _obbPoints) == 9) { return(Ent.EnemyInside); } return(Ent.EnemyPlayer); } var grid = ent as MyCubeGrid; if (grid != null) { var modulateGrids = (ShieldComp.Modulator != null && ShieldComp.Modulator.ModSet.Settings.ModulateGrids) || Session.Enforced.DisableEntityBarrier == 1; ModulatorGridComponent modComp; grid.Components.TryGet(out modComp); if (!string.IsNullOrEmpty(modComp?.ModulationPassword) && modComp.ModulationPassword == Shield.CustomData) { var modShield = modComp.Modulator?.ShieldComp?.DefenseShields; if (modShield != null) { foreach (var subGrid in modShield.ShieldComp.SubGrids.Keys) { if (ShieldEnt.PositionComp.WorldVolume.Intersects(grid.PositionComp.WorldVolume)) { if (CustomCollision.CornerOrCenterInShield(grid, DetectMatrixOutsideInv, _resetEntCorners) > 0) { return(Ent.Protected); } AuthenticatedCache.Add(subGrid); } else { AuthenticatedCache.Add(subGrid); } } return(Ent.Authenticated); } foreach (var subGrid in modComp.SubGrids) { if (ShieldEnt.PositionComp.WorldVolume.Intersects(grid.PositionComp.WorldVolume)) { if (CustomCollision.CornerOrCenterInShield(grid, DetectMatrixOutsideInv, _resetEntCorners) > 0) { return(Ent.Protected); } AuthenticatedCache.Add((MyCubeGrid)subGrid); } else { AuthenticatedCache.Add((MyCubeGrid)subGrid); } } } List <long> bigOwners; int bigOwnersCnt; Session.ParentGrid parent; if (Session.Instance.GetParentGrid.TryGetValue(grid, out parent) && !CustomCollision.AllAabbInShield(parent.Parent.PositionComp.WorldAABB, DetectMatrixOutsideInv, _obbCorners)) { bigOwners = grid.BigOwners; bigOwnersCnt = bigOwners.Count; if (bigOwnersCnt == 0 || GridEnemy(grid, bigOwners)) { return(Ent.EnemyGrid); } } else { bigOwners = grid.BigOwners; bigOwnersCnt = bigOwners.Count; } if (CustomCollision.AllAabbInShield(ent.PositionComp.WorldAABB, DetectMatrixOutsideInv, _obbCorners)) { return(Ent.Protected); } if (!modulateGrids && bigOwnersCnt == 0) { return(Ent.NobodyGrid); } var enemy = !modulateGrids && GridEnemy(grid, bigOwners); if (!enemy) { if (ShieldComp.SubGrids.ContainsKey(grid)) { return(Ent.Protected); } var pointsInShield = CustomCollision.NewObbPointsInShield(grid, DetectMatrixOutsideInv, _obbPoints); return(pointsInShield > 0 ? Ent.Protected : Ent.Friendly); } ShieldGridComponent shieldComponent; grid.Components.TryGet(out shieldComponent); if (shieldComponent?.DefenseShields?.ShieldComp != null && shieldComponent.DefenseShields.NotFailed && shieldComponent.DefenseShields.DsState != null && !shieldComponent.DefenseShields.DsState.State.ReInforce) { var dsComp = shieldComponent.DefenseShields; var shieldEntity = MyCube.Parent; dsComp.EnemyShields.Add(shieldEntity); return(Ent.Shielded); } return(Ent.EnemyGrid); } if (ent is IMyMeteor || (ent.DefinitionId.HasValue && ent.DefinitionId.Value.TypeId == Session.Instance.MissileObj)) { return(Ent.Other); } if (voxel != null && GridIsMobile) { return(Ent.VoxelBase); } return(0); }
public Ent EntType(MyEntity ent) { if (ent is IMyFloatingObject) { if (CustomCollision.AllAabbInShield(ent.PositionComp.WorldAABB, DetectMatrixOutsideInv, _obbCorners)) { return(Ent.Ignore); } return(Ent.Floater); } var voxel = ent as MyVoxelBase; if (voxel != null && (Session.Enforced.DisableVoxelSupport == 1 || ShieldComp.Modulator == null || ShieldComp.Modulator.ModSet.Settings.ModulateVoxels || !GridIsMobile)) { return(Ent.Ignore); } if (EntityBypass.Contains(ent)) { return(Ent.Ignore); } var character = ent as IMyCharacter; if (character != null) { var dude = MyAPIGateway.Players.GetPlayerControllingEntity(ent)?.IdentityId; if (dude == null) { return(Ent.Ignore); } var playerrelationship = MyCube.GetUserRelationToOwner((long)dude); if (playerrelationship == MyRelationsBetweenPlayerAndBlock.Owner || playerrelationship == MyRelationsBetweenPlayerAndBlock.FactionShare) { var playerInShield = CustomCollision.PointInShield(ent.PositionComp.WorldAABB.Center, DetectMatrixOutsideInv); return(playerInShield ? Ent.Protected : Ent.Friendly); } if (character.IsDead) { return(Ent.Ignore); } if (CustomCollision.NewObbPointsInShield(ent, DetectMatrixOutsideInv, _obbPoints) == 9) { return(Ent.EnemyInside); } return(Ent.EnemyPlayer); } var grid = ent as MyCubeGrid; if (grid != null) { ModulateGrids = (ShieldComp.Modulator != null && ShieldComp.Modulator.ModSet.Settings.ModulateGrids) || Session.Enforced.DisableEntityBarrier == 1; ModulatorGridComponent modComp; grid.Components.TryGet(out modComp); if (!string.IsNullOrEmpty(modComp?.ModulationPassword) && modComp.ModulationPassword == Shield.CustomData) { var modShield = modComp.Modulator?.ShieldComp?.DefenseShields; if (modShield != null) { lock (modShield.SubLock) { foreach (var subGrid in modShield.ShieldComp.SubGrids) { if (ShieldEnt.PositionComp.WorldVolume.Intersects(grid.PositionComp.WorldVolume)) { if (CustomCollision.CornerOrCenterInShield(grid, DetectMatrixOutsideInv, _resetEntCorners) > 0) { return(Ent.Protected); } AuthenticatedCache.Add(subGrid); } else { AuthenticatedCache.Add(subGrid); } } } return(Ent.Authenticated); } foreach (var subGrid in modComp.SubGrids) { if (ShieldEnt.PositionComp.WorldVolume.Intersects(grid.PositionComp.WorldVolume)) { if (CustomCollision.CornerOrCenterInShield(grid, DetectMatrixOutsideInv, _resetEntCorners) > 0) { return(Ent.Protected); } AuthenticatedCache.Add(subGrid); } else { AuthenticatedCache.Add(subGrid); } } } var bigOwners = grid.BigOwners; var bigOwnersCnt = bigOwners.Count; if (CustomCollision.AllAabbInShield(ent.PositionComp.WorldAABB, DetectMatrixOutsideInv, _obbCorners)) { return(Ent.Protected); } if (!ModulateGrids && bigOwnersCnt == 0) { return(Ent.NobodyGrid); } var enemy = !ModulateGrids && GridEnemy(grid, bigOwners); if (!enemy) { lock (SubLock) if (ShieldComp.SubGrids.Contains(grid)) { return(Ent.Protected); } var pointsInShield = CustomCollision.NewObbPointsInShield(grid, DetectMatrixOutsideInv, _obbPoints); return(pointsInShield > 0 ? Ent.Protected : Ent.Friendly); } ShieldGridComponent shieldComponent; grid.Components.TryGet(out shieldComponent); if (shieldComponent?.DefenseShields?.ShieldComp != null && shieldComponent.DefenseShields.NotFailed) { var dsComp = shieldComponent.DefenseShields; var shieldEntity = MyCube.Parent; dsComp.EnemyShields.Add(shieldEntity); return(Ent.Shielded); } return(Ent.EnemyGrid); } if (ent is IMyMeteor || (ent.DefinitionId.HasValue && ent.DefinitionId.Value.TypeId == Session.Instance.MissileObj)) { return(Ent.Other); } if (voxel != null && GridIsMobile) { return(Ent.VoxelBase); } return(0); }
internal void MonitorRefreshTasks(int x, ref List <MyEntity> monitorList, bool reInforce, ref bool newSub) { var s = _workData.ShieldList[x]; if (reInforce) { HashSet <MyCubeGrid> subs; lock (s.GetCubesLock) subs = new HashSet <MyCubeGrid>(s.ShieldComp.GetSubGrids); var newMode = !s.ReInforcedShield; if (!newMode) { return; } foreach (var sub in subs) { //if (Enforced.Debug >= 2) Log.Line("Server queuing entFresh for reinforced shield"); if (!_globalEntTmp.ContainsKey(sub)) { newSub = true; } _entRefreshQueue.Enqueue(sub); if (!s.WasPaused) { _globalEntTmp[sub] = _workData.Tick; } } s.ReInforcedShield = true; s.TicksWithNoActivity = 0; s.LastWokenTick = _workData.Tick; s.Asleep = false; } else { var newMode = false; if (s.ReInforcedShield) { HashSet <MyCubeGrid> subs; lock (s.GetCubesLock) subs = new HashSet <MyCubeGrid>(s.ShieldComp.GetSubGrids); foreach (var sub in subs) { _entRefreshQueue.Enqueue(sub); if (!s.WasPaused) { _globalEntTmp[sub] = _workData.Tick; } } //if (Enforced.Debug >= 2) Log.Line($"found Reinforce"); s.ReInforcedShield = false; s.TicksWithNoActivity = 0; s.LastWokenTick = _workData.Tick; s.Asleep = false; newMode = true; } if (!newMode) { // var testMat = s.DetectMatrixOutside; // var shape1 = new Sphere(Vector3D.Zero, 1.0).Transformed(testMat); var foundNewEnt = false; var disableVoxels = Enforced.DisableVoxelSupport == 1 || s.ShieldComp.Modulator == null || s.ShieldComp.Modulator.ModSet.Settings.ModulateVoxels; MyGamePruningStructure.GetTopmostEntitiesInBox(ref s.WebBox, monitorList); foreach (var ent in monitorList) { var voxel = ent as MyVoxelBase; if (ent == null || ent.MarkedForClose || (voxel == null && (ent.Physics == null || ent.DefinitionId == null)) || (!s.GridIsMobile && voxel != null) || (disableVoxels && voxel != null) || (voxel != null && voxel != voxel.RootVoxel)) { continue; } if (ent is IMyFloatingObject || ent is IMyEngineerToolBase || !s.WebSphere.Intersects(ent.PositionComp.WorldVolume)) { continue; } // var halfExtents = ent.PositionComp.LocalAABB.HalfExtents; // if (halfExtents.X < 1) halfExtents.X = 10; // if (halfExtents.Y < 1) halfExtents.Y = 10; // if (halfExtents.Z < 1) halfExtents.Z = 10; // var shape2 = new Box(-halfExtents, halfExtents).Transformed(ent.WorldMatrix); // var test = Gjk.Intersects(ref shape1, ref shape2); // Log.Line($"{ent.DebugName} - {test}"); if (CustomCollision.NewObbPointsInShield(ent, s.DetectMatrixOutsideInv) > 0) { if (!s.WasPaused && !_globalEntTmp.ContainsKey(ent)) { foundNewEnt = true; s.Asleep = false; //if (Enforced.Debug >= 2) Log.Line($"New entity"); } if (!s.WasPaused) { _globalEntTmp[ent] = _workData.Tick; } } s.NewEntByShield = foundNewEnt; } if (!s.NewEntByShield) { var foundPlayer = false; foreach (var player in Players.Values) { var character = player.Character; if (character == null) { continue; } if (Vector3D.DistanceSquared(character.PositionComp.WorldMatrix.Translation, s.DetectionCenter) < SyncDistSqr) { foundPlayer = true; break; } } s.PlayerByShield = foundPlayer; } if (!s.PlayerByShield) { s.MoverByShield = false; var newMover = false; var moverList = new List <MyEntity>(); MyGamePruningStructure.GetTopMostEntitiesInBox(ref s.ShieldBox3K, moverList, MyEntityQueryType.Dynamic); for (int i = 0; i < moverList.Count; i++) { var ent = moverList[i]; if (!(ent.Physics == null || ent is MyCubeGrid || ent is IMyCharacter || ent is IMyMeteor)) { continue; } var entPos = ent.PositionComp.WorldMatrix.Translation; var keyFound = s.EntsByMe.ContainsKey(ent); if (keyFound) { if (!s.EntsByMe[ent].Pos.Equals(entPos, 1e-3)) { //if (Enforced.Debug >= 2) Log.Line($"[Moved] Ent:{ent.DebugName}"); MoverInfo moverInfo; s.EntsByMe.TryRemove(ent, out moverInfo); s.EntsByMe.TryAdd(ent, new MoverInfo(entPos, _workData.Tick)); newMover = true; break; } } else { s.EntsByMe.TryAdd(ent, new MoverInfo(entPos, _workData.Tick)); } } s.MoverByShield = newMover; } if (_workData.Tick < s.LastWokenTick + 400) { s.Asleep = false; return; } } if (s.EntCleanUpTime) { s.EntCleanUpTime = false; if (!s.EntsByMe.IsEmpty) { var entsByMeTmp = new List <KeyValuePair <MyEntity, MoverInfo> >(); entsByMeTmp.AddRange(s.EntsByMe.Where(info => !info.Key.InScene || _workData.Tick - info.Value.CreationTick > EntMaxTickAge)); for (int i = 0; i < entsByMeTmp.Count; i++) { MoverInfo mInfo; s.EntsByMe.TryRemove(entsByMeTmp[i].Key, out mInfo); } } } } }