private void CheckAcquire() { for (int i = AcquireTargets.Count - 1; i >= 0; i--) { var w = AcquireTargets[i]; var comp = w.Comp; if (w.Comp.IsAsleep || w.Comp.Ai == null || comp.Ai.MyGrid.MarkedForClose || !comp.Ai.HasPower || comp.Ai.Concealed || comp.MyCube.MarkedForClose || !comp.Ai.DbReady || !comp.IsWorking || w.NoMagsToLoad && w.Ammo.CurrentAmmo == 0 && Tick - w.LastMagSeenTick > 600) { w.AcquiringTarget = false; AcquireTargets.RemoveAtFast(i); continue; } if (!w.Acquire.Monitoring && IsServer && w.TrackTarget) { AcqManager.Monitor(w.Acquire); } var acquire = (w.Acquire.IsSleeping && AsleepCount == w.Acquire.SlotId || !w.Acquire.IsSleeping && AwakeCount == w.Acquire.SlotId); var seekProjectile = w.ProjectilesNear || w.System.TrackProjectile && w.Comp.Data.Repo.Base.Set.Overrides.Projectiles && w.Comp.Ai.CheckProjectiles; var checkTime = w.Target.TargetChanged || acquire || seekProjectile || w.FastTargetResetTick == Tick; if (checkTime || w.Comp.Ai.TargetResetTick == Tick && w.Target.HasTarget) { if (seekProjectile || comp.Data.Repo.Base.State.TrackingReticle || (comp.TargetNonThreats && w.Comp.Ai.TargetingInfo.OtherInRange || w.Comp.Ai.TargetingInfo.ThreatInRange) && w.Comp.Ai.TargetingInfo.ValidTargetExists(w)) { if (comp.TrackingWeapon != null && comp.TrackingWeapon.System.DesignatorWeapon && comp.TrackingWeapon != w && comp.TrackingWeapon.Target.HasTarget) { var topMost = comp.TrackingWeapon.Target.Entity?.GetTopMostParent(); GridAi.AcquireTarget(w, false, topMost); } else { GridAi.AcquireTarget(w, w.Comp.Ai.TargetResetTick == Tick); } } if (w.Target.HasTarget || !(comp.TargetNonThreats && w.Comp.Ai.TargetingInfo.OtherInRange || w.Comp.Ai.TargetingInfo.ThreatInRange)) { w.AcquiringTarget = false; AcquireTargets.RemoveAtFast(i); if (w.Target.HasTarget && MpActive) { w.Target.PushTargetToClient(w); } } } } }
private void CheckAcquire() { for (int i = AcquireTargets.Count - 1; i >= 0; i--) { var w = AcquireTargets[i]; using (w.Comp.MyCube.Pin()) using (w.Comp.Ai?.MyGrid.Pin()) { var comp = w.Comp; if (w.Comp.Ai == null || comp.Ai.MyGrid.MarkedForClose || !comp.Ai.HasPower || comp.Ai.Concealed || comp.MyCube.MarkedForClose || !comp.Ai.DbReady || !w.Set.Enable || !comp.State.Value.Online || !comp.Set.Value.Overrides.Activate) { w.AcquiringTarget = false; AcquireTargets.RemoveAtFast(i); continue; } var gridAi = w.Comp.Ai; var sinceCheck = Tick - w.Target.CheckTick; var seekProjectile = w.ProjectilesNear || w.TrackProjectiles && gridAi.CheckProjectiles; var checkTime = w.Target.TargetChanged || sinceCheck > 239 || sinceCheck > 60 && Count == w.LoadId || seekProjectile; if (checkTime || gridAi.TargetResetTick == Tick && w.Target.HasTarget) { if (seekProjectile || comp.TrackReticle || gridAi.TargetingInfo.TargetInRange && gridAi.TargetingInfo.ValidTargetExists(w)) { if (comp.TrackingWeapon != null && comp.TrackingWeapon.System.DesignatorWeapon && comp.TrackingWeapon != w && comp.TrackingWeapon.Target.HasTarget) { var topMost = comp.TrackingWeapon.Target.Entity?.GetTopMostParent(); GridAi.AcquireTarget(w, false, topMost); } else { GridAi.AcquireTarget(w, gridAi.TargetResetTick == Tick); } } if (w.Target.HasTarget || !gridAi.TargetingInfo.TargetInRange) { w.AcquiringTarget = false; AcquireTargets.RemoveAtFast(i); if (w.Target.HasTarget && MpActive) { w.Target.SyncTarget(comp.WeaponValues.Targets[w.WeaponId], w.WeaponId); if (WeaponsSyncCheck.Add(w)) { WeaponsToSync.Add(w); comp.Ai.NumSyncWeapons++; w.SendTarget = true; if (Tick - w.LastSyncTick > 20) { w.SendSync = true; } w.LastSyncTick = Tick; } } } } } } }