void DoTasks(TimeSpan timestamp)
 {
     while (true)
     {
         if (TaskQueue.Count == 0)
         {
             return;
         }
         ITask currentTask = TaskQueue.Peek();
         //profiler.StartSectionWatch(currentTask.Name);
         currentTask.Do(IntelProvider.GetFleetIntelligences(timestamp), timestamp + IntelProvider.CanonicalTimeDiff, null);
         //profiler.StopSectionWatch(currentTask.Name);
         if (currentTask.Status == TaskStatus.Complete)
         {
             TaskQueue.Dequeue();
         }
         else if (currentTask.Status == TaskStatus.Aborted)
         {
             TaskQueue.Dequeue();
         }
         else
         {
             break;
         }
     }
 }
        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 AimAtTarget(TimeSpan localTime)
        {
            var intelItems = IntelProvider.GetFleetIntelligences(localTime);

            if (!intelItems.ContainsKey(TargetKey))
            {
                SetTarget(0);
                ClearGyros();
            }
            else
            {
                // Update Attack Point

                // Compute errors and update PID

                // Set gyros to rorate
            }
        }
        void ReportAndUpdateHangars(TimeSpan timestamp)
        {
            var intelItems = IntelProvider.GetFleetIntelligences(timestamp);

            foreach (var hangar in Hangars)
            {
                if (IsHangarOk(hangar))
                {
                    IntelProvider.ReportFleetIntelligence(GetHangarIntel(hangar, timestamp), timestamp);
                    hangar.Update(timestamp, intelItems);

                    if (requestingRefresh == false && lastConnectorStatuses.ContainsKey(hangar) &&
                        ((lastConnectorStatuses[hangar] == MyShipConnectorStatus.Connected && hangar.Connector.Status != MyShipConnectorStatus.Connected) ||
                         (lastConnectorStatuses[hangar] != MyShipConnectorStatus.Connected && hangar.Connector.Status == MyShipConnectorStatus.Connected)))
                    {
                        requestingRefresh = true;
                    }
                    lastConnectorStatuses[hangar] = hangar.Connector.Status;
                }
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }