public static void SetRedirect(DefenseShields ds, Session.ShieldSides side, int newValue) { if (!Session.Instance.DedicatedServer && Session.Instance.Settings.ClientConfig.Notices) { var pendingChanges = ds.DsSet.Settings.ShieldRedirects != ds.ShieldRedirectState; var enableText = SideEnabled(side, newValue) ? "Shunting" : "Normalizing"; var text = $"[{enableText} {side}] Shields in 2 seconds -- delaying previous changes: [{pendingChanges}]"; Session.Instance.SendNotice(text); } switch (side) { case Session.ShieldSides.Left: case Session.ShieldSides.Right: ds.DsSet.Settings.ShieldRedirects.X = newValue; break; case Session.ShieldSides.Up: case Session.ShieldSides.Down: ds.DsSet.Settings.ShieldRedirects.Y = newValue; break; case Session.ShieldSides.Forward: case Session.ShieldSides.Backward: ds.DsSet.Settings.ShieldRedirects.Z = newValue; break; } }
public void RemoveShield(DefenseShields shield) { if (shield.DtreeProxyId == -1) { return; } _aabbTree.RemoveProxy(shield.DtreeProxyId); shield.DtreeProxyId = -1; }
public void MoveShield(DefenseShields shield) { if (shield.DtreeProxyId == -1) { return; } BoundingBoxD worldAabb = shield.WebBox; _aabbTree.MoveProxy(shield.DtreeProxyId, ref worldAabb, Vector3.Zero); }
public void AddShield(DefenseShields shield) { if (shield.DtreeProxyId != -1) { return; } BoundingBoxD worldAabb = shield.WebBox; shield.DtreeProxyId = _aabbTree.AddProxy(ref worldAabb, shield, 0U, true); }
public static bool NewSideState(DefenseShields ds, Session.ShieldSides side, bool redirect, int currentState) { int newState; var enableValue = Session.Instance.SideControlMap[side]; var oppositeValue = enableValue * -1; if (redirect) { newState = currentState == oppositeValue ? 2 : enableValue; } else { newState = currentState == 2 ? oppositeValue : 0; } SetRedirect(ds, side, newState); return(newState != currentState); }
private void BroadCastLosMessage(int blocked, int needed, DefenseShields controller) { var sphere = new BoundingSphereD(Emitter.PositionComp.WorldAABB.Center, 1500); var sendMessage = false; foreach (var player in Session.Instance.Players.Values) { if (player.IdentityId != MyAPIGateway.Session.Player.IdentityId) { continue; } if (!sphere.Intersects(player.Character.WorldVolume)) { continue; } sendMessage = true; break; } if (sendMessage) { var sighted = _vertsSighted.Count; if (needed > 0) { needed = 0; } MyAPIGateway.Utilities.ShowNotification("The shield emitter DOES NOT have a CLEAR ENOUGH LINE OF SIGHT to the shield, SHUTTING DOWN.", 960, "Red"); MyAPIGateway.Utilities.ShowNotification($"Green means clear line of sight, Flashing Orange means blocked | Blocked: {blocked} | Clear: {sighted} | Needed (Approximate): {needed}", 960, "Red"); if (needed == 0 && controller.LosCheckTick != uint.MaxValue) { MyAPIGateway.Utilities.ShowNotification($"Needed is only an approximation, if shield does not start in 30 seconds or is unstable, then it is not clear.", 960, "White"); } else if (needed == 0 && _lCount % 2 == 1) { MyAPIGateway.Utilities.ShowNotification($"Shield is still not clear!", 960, "White"); } } }
private static IMyTerminalBlock TAPI_GetShieldBlock(IMyEntity entity) { var ent = entity as MyEntity; if (ent == null) { return(null); } MyProtectors protectors; if (Session.Instance.GlobalProtect.TryGetValue(ent, out protectors)) { DefenseShields firstShield = null; var grid = ent as MyCubeGrid; foreach (var s in protectors.Shields) { if (s == null) { continue; } if (firstShield == null) { firstShield = s; } lock (s.SubLock) if (grid != null && s.ShieldComp?.SubGrids != null && s.ShieldComp.SubGrids.Contains(grid)) { return(s.MyCube as IMyTerminalBlock); } } if (firstShield != null) { return(firstShield.MyCube as IMyTerminalBlock); } } return(null); }
private void LoadBalancer() { var shieldsWaking = 0; var entsUpdated = 0; var entsremoved = 0; var entsLostShield = 0; if (++RefreshCycle >= EntSlotScaler) { RefreshCycle = 0; } MyEntity ent; while (_entRefreshQueue.TryDequeue(out ent)) { MyProtectors myProtector; if (!GlobalProtect.TryGetValue(ent, out myProtector)) { continue; } var entShields = myProtector.Shields; var refreshCount = 0; DefenseShields iShield = null; var removeIShield = false; foreach (var s in entShields) { if (s.WasPaused) { continue; } lock (s.SubLock) { if (s.DsState.State.ReInforce && s.ShieldComp.SubGrids.Contains(ent)) { iShield = s; refreshCount++; } else if (!ent.InScene || !s.ResetEnts(ent, Tick)) { myProtector.Shields.Remove(s); entsLostShield++; } else { refreshCount++; } } if (iShield == null && myProtector.IntegrityShield == s) { removeIShield = true; myProtector.IntegrityShield = null; } var detectedStates = s.PlayerByShield || s.MoverByShield || Tick <= s.LastWokenTick + 580 || iShield != null || removeIShield; if (ScalerChanged || detectedStates) { s.Asleep = false; shieldsWaking++; } } if (iShield != null) { myProtector.Shields.Remove(iShield); myProtector.IntegrityShield = iShield; } myProtector.Shields.ApplyChanges(); if (refreshCount == 0) { GlobalProtect.Remove(ent); ProtSets.Return(myProtector); entsremoved++; } else { entsUpdated++; } } if (Tick1800 && Enforced.Debug >= 3) { for (int i = 0; i < SlotCnt.Length; i++) { SlotCnt[i] = 0; } foreach (var pair in GlobalProtect) { SlotCnt[pair.Value.RefreshSlot]++; } Log.Line($"[NewRefresh] SlotScaler:{EntSlotScaler} - EntsUpdated:{entsUpdated} - ShieldsWaking:{shieldsWaking} - EntsRemoved: {entsremoved} - EntsLostShield:{entsLostShield} - EntInRefreshSlots:({SlotCnt[0]} - {SlotCnt[1]} - {SlotCnt[2]} - {SlotCnt[3]} - {SlotCnt[4]} - {SlotCnt[5]} - {SlotCnt[6]} - {SlotCnt[7]} - {SlotCnt[8]}) \n" + $" ProtectedEnts:{GlobalProtect.Count} - FunctionalShields:{FunctionalShields.Count} - AllControllerBlocks:{Controllers.Count}"); } }
public ShieldGridComponent(DefenseShields defenseShields) { DefenseShields = defenseShields; }
internal void MonitorRefreshTasks(DefenseShields s, ref List <MyEntity> monitorList, bool reInforce, ref bool newSub) { if (reInforce) { var newMode = !s.ReInforcedShield; if (!newMode) { return; } foreach (var sub in s.ShieldComp.SubGrids.Keys) { if (!_globalEntTmp.ContainsKey(sub)) { newSub = true; } EntRefreshQueue.Enqueue(sub); if (!s.WasPaused) { _globalEntTmp[sub] = Tick; } } s.ReInforcedShield = true; s.TicksWithNoActivity = 0; s.LastWokenTick = Tick; s.Asleep = false; } else { var newMode = false; if (s.ReInforcedShield) { foreach (var sub in s.ShieldComp.SubGrids.Keys) { EntRefreshQueue.Enqueue(sub); if (!s.WasPaused) { _globalEntTmp[sub] = Tick; } } s.ReInforcedShield = false; s.TicksWithNoActivity = 0; s.LastWokenTick = 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] = 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, Tick)); if (moverInfo.CreationTick == 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, Tick)); } } moverList.Clear(); ListMyEntityPool.Return(moverList); s.MoverByShield = newMover; } if (Tick < s.LastWokenTick + 400) { s.Asleep = false; return; } } if (s.EntCleanUpTime) { s.EntCleanUpTime = false; foreach (var info in s.EntsByMe) { if (!info.Key.InScene || info.Key.MarkedForClose || Tick - info.Value.CreationTick > EntMaxTickAge) { MoverInfo mInfo; s.EntsByMe.TryRemove(info.Key, out mInfo); } } } } }