示例#1
0
 IEnumerable <string> Launch()
 {
     logScreen?.WriteText("", false);
     Message($"Target: {TargetLocation.ToString()}");
     if (ApproachIndex < 0)
     {
         var minkv = Approaches.MinBy((kv) => (float)(TargetLocation.CurrentPosition - kv.Value[0]).Length());
         ChosenApproach = minkv.Key;
         ApproachIndex  = minkv.Value.Count - 1;
     }
     if ((Approaches[ChosenApproach][0] - TargetLocation.CurrentPosition).Length() > AbortDistance)
     {
         Message("Target location is too far from the dock!");
         yield return("");
     }
     else
     {
         PreFlightPreparations();
         Clamp.Unlock();
         Vector3D detach = DockLocation - DockApproachVector * 2 * Me.CubeGrid.WorldVolume.Radius;
         Pilot.Tasks.Clear();
         var task = new UnaimedFlightStrategy(detach, Connector);
         task.MaxLinearSpeed = MaxSpeed;
         Pilot.Tasks.Add(task);
         while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
         {
             yield return(null);
         }
         foreach (var cam in Cameras)
         {
             cam.EnableRaycast = true;
         }
         yield return("LeaveDock");
     }
 }
示例#2
0
        IEnumerable <string> LaunchToGrind()
        {
            if (Vector3D.IsZero(GrinderApproach))
            {
                Message("No grinders configured!");
                yield return("");

                yield break;
            }
            if (Clamp.LockMode != LandingGearMode.Locked)
            {
                Message("Nothing to grind!");
                yield return("");

                yield break;
            }

            logScreen?.WriteText("", false);
            Message("Grinding target...");
            if (ApproachIndex < 0)
            {
                var minkv = Approaches.MinBy((kv) =>
                {
                    Vector3D offset   = kv.Value[0] - GrinderLocation;
                    double projection = offset.Dot(GrinderApproach);
                    if (projection < 0)
                    {
                        return(float.PositiveInfinity);
                    }
                    else
                    {
                        return((float)(GrinderApproach * projection - offset).Length());
                    }
                });
                ChosenApproach = minkv.Key;
                ApproachIndex  = minkv.Value.Count - 1;
            }
            if ((Approaches[ChosenApproach][0] - GrinderLocation).Length() > AbortDistance)
            {
                Message("Grinder location is too far from the dock!");
                yield return("");
            }
            else
            {
                PreFlightPreparations();
                Vector3D detach = DockLocation - DockApproachVector * 2 * Me.CubeGrid.WorldVolume.Radius;
                Pilot.Tasks.Clear();
                var task = new UnaimedFlightStrategy(detach, Connector);
                task.MaxLinearSpeed = MaxSpeed;
                Pilot.Tasks.Add(task);
                while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
                {
                    yield return(null);
                }
                yield return("LeaveDockForGrinders");
            }
        }
示例#3
0
        IEnumerable <string> BackOffFromGrinders()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;
            Message("Stop grinding on " + GrinderGroup);
            //Clamp.Unlock();
            Vector3D target = GrinderLocation + GrinderApproach * 2 * Controller.CubeGrid.WorldVolume.Radius;
            var      task   = new UnaimedFlightStrategy(target, Controller);

            Pilot.Tasks.Add(task);
            while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
            {
                yield return(null);
            }
            yield return("ReturnHome");
        }
示例#4
0
        IEnumerable <string> GoToGrinderApproachVector()
        {
            Message("Moving to grinder approach vector.");
            Vector3D offset   = Clamp.GetPosition() - GrinderLocation;
            Vector3D raypoint = Vector3D.ProjectOnVector(ref offset, ref GrinderApproach) + GrinderLocation;

            var task = new UnaimedFlightStrategy(raypoint, Controller);

            Pilot.Tasks.Add(task);
            while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
            {
                if (HasToAbort())
                {
                    yield return("ReturnHome");
                }
                else
                {
                    yield return(null);
                }
            }
            yield return("MoveToGrind");
        }