void UpdateAlarms(TimeSpan localTime) { var intelItems = IntelProvider.GetFleetIntelligences(localTime); bool hasEnemy = false; foreach (var kvp in intelItems) { if (kvp.Key.Item1 == IntelItemType.Enemy && IntelProvider.GetPriority(kvp.Key.Item2) > 1 && (kvp.Value.GetPositionFromCanonicalTime(localTime + IntelProvider.CanonicalTimeDiff) - Controller.GetPosition()).Length() < alertDist) { hasEnemy = true; break; } } Alarm = hasEnemy; if (hasEnemy && AutoScramble) { Attack(localTime); } }
void TryScan(TimeSpan localTime) { // Go through each target var intelItems = IntelProvider.GetFleetIntelligences(localTime); var canonicalTime = localTime + IntelProvider.CanonicalTimeDiff; DetectedTargets.Clear(); // WC only... // Context.Log.Debug("A"); if (Context.WCAPI != null) { GetThreatsScratchpad.Clear(); Context.WCAPI.GetSortedThreats(Context.Reference, GetThreatsScratchpad); foreach (var target in GetThreatsScratchpad.Keys) { DetectedTargets[target.EntityId] = MyTuple.Create(target, true); } int priority = 0; while (true) { var selectedTarget = Context.WCAPI.GetAiFocus(Context.Reference.CubeGrid.EntityId, priority); if (selectedTarget == null) { break; } TryAddEnemyShipIntel(intelItems, localTime, canonicalTime, selectedTarget.Value, true, true); break; } } // Context.Log.Debug("B"); else { foreach (var turret in Turrets) { if (!turret.HasTarget) { continue; } var target = turret.GetTargetedEntity(); if (!target.IsEmpty() && !DetectedTargets.ContainsKey(target.EntityId)) { DetectedTargets[target.EntityId] = MyTuple.Create(target, false); } } } // Context.Log.Debug("C"); foreach (var target in DetectedTargets) { TryAddEnemyShipIntel(intelItems, localTime, canonicalTime, target.Value.Item1, target.Value.Item2); } // Context.Log.Debug("D"); foreach (var kvp in intelItems) { if (kvp.Key.Item1 != IntelItemType.Enemy) { continue; } EnemyShipIntel enemy = (EnemyShipIntel)kvp.Value; int priority = IntelProvider.GetPriority(kvp.Key.Item2); if (priority < 1) { continue; } if (!EnemyShipIntel.PrioritizeTarget(enemy)) { continue; } if (enemy.LastValidatedCanonicalTime + TimeSpan.FromSeconds(0.2) > canonicalTime) { continue; } if (enemy.LastValidatedCanonicalTime + TimeSpan.FromSeconds(0.4) > canonicalTime && priority < 4) { continue; } Vector3D targetPosition = kvp.Value.GetPositionFromCanonicalTime(canonicalTime); TryScanTarget(targetPosition, localTime, enemy); } }