Example #1
0
        public void Do(Dictionary <MyTuple <IntelItemType, long>, IFleetIntelligence> IntelItems, TimeSpan canonicalTime, Profiler profiler)
        {
            IMyShipController controller = Autopilot.Controller;
            var      currentPosition     = controller.WorldMatrix.Translation;
            Vector3D linearVelocity      = controller.GetShipVelocities().LinearVelocity;

            if (!TargetPositionSet)
            {
                if (IntelKey.Item1 == IntelItemType.Waypoint && IntelItems.ContainsKey(IntelKey))
                {
                    TargetPosition = IntelItems[IntelKey].GetPositionFromCanonicalTime(canonicalTime);
                }
                TargetPositionSet = true;
            }

            Vector3D worldAttackPoint;

            if (TargetPositionSet && TargetPosition != Vector3D.Zero)
            {
                worldAttackPoint = TargetPosition;
            }
            else
            {
                if (IntelKey.Item1 != IntelItemType.Enemy || !IntelItems.ContainsKey(IntelKey))
                {
                    AgentSubsystem.AddTask(TaskType.Dock, MyTuple.Create(IntelItemType.NONE, (long)0), CommandType.Enqueue, 0, canonicalTime);
                    Status = TaskStatus.Aborted;
                    return;
                }

                var target = (EnemyShipIntel)IntelItems[IntelKey];
                worldAttackPoint = currentPosition + AttackHelpers.GetAttackPoint(target.GetVelocity(), target.GetPositionFromCanonicalTime(canonicalTime) + target.GetVelocity() * 0.08 - currentPosition, 98);
            }

            Vector3D dirToTarget = worldAttackPoint - currentPosition;

            if (dirToTarget.Length() < LocustCombatSystem.kEngageRange && deployTime == TimeSpan.Zero)
            {
                CombatSystem.Deploy();
                deployTime = canonicalTime;
            }

            dirToTarget.Normalize();
            LeadTask.Destination.Direction = dirToTarget;
            LeadTask.Destination.Position  = worldAttackPoint + dirToTarget * 400;

            if (deployTime != TimeSpan.Zero)
            {
                if (deployTime + TimeSpan.FromSeconds(2) < canonicalTime)
                {
                    AgentSubsystem.AddTask(TaskType.Dock, MyTuple.Create(IntelItemType.NONE, (long)0), CommandType.Enqueue, 0, canonicalTime);
                    Status = TaskStatus.Aborted;
                    return;
                }
                else
                {
                    LeadTask.Destination.DirectionUp = Math.Sin(kRotateTheta) * controller.WorldMatrix.Right + Math.Cos(kRotateTheta) * controller.WorldMatrix.Up;
                }
            }

            LeadTask.Do(IntelItems, canonicalTime, profiler);
        }