protected override void WindowGUI(int windowID)
        {
            if (!core.target.NormalTargetExists)
            {
                GUILayout.Label("Select a target to rendezvous with.");
                base.WindowGUI(windowID);
                return;
            }

            MechJebModuleRendezvousAutopilot autopilot = core.GetComputerModule <MechJebModuleRendezvousAutopilot>();

            if (core.target.Orbit.referenceBody != orbit.referenceBody)
            {
                GUILayout.Label("Rendezvous target must be in the same sphere of influence.");
                if (autopilot.enabled)
                {
                    autopilot.users.Remove(this);
                }
                base.WindowGUI(windowID);
                return;
            }

            GUILayout.BeginVertical();

            if (autopilot != null)
            {
                GuiUtils.SimpleLabel("Rendezvous target", core.target.Name);

                if (!autopilot.enabled)
                {
                    if (GUILayout.Button("Engage autopilot"))
                    {
                        autopilot.users.Add(this);
                    }
                }
                else
                {
                    if (GUILayout.Button("Disengage autopilot"))
                    {
                        autopilot.users.Remove(this);
                    }
                }

                GuiUtils.SimpleTextBox("Desired final distance:", autopilot.desiredDistance, "m");

                if (autopilot.enabled)
                {
                    GUILayout.Label("Status: " + autopilot.status);
                }
            }

            core.node.autowarp = GUILayout.Toggle(core.node.autowarp, "Auto-warp");

            GUILayout.EndVertical();

            base.WindowGUI(windowID);
        }
Exemplo n.º 2
0
 public MechJebModuleScriptActionRendezvousAP(MechJebModuleScript scriptModule, MechJebCore core) : base(scriptModule, core, NAME)
 {
     this.autopilot = core.GetComputerModule <MechJebModuleRendezvousAutopilot>();
     this.module    = core.GetComputerModule <MechJebModuleRendezvousAutopilotWindow>();
     this.readModuleConfiguration();
 }
        protected override void WindowGUI(int windowID)
        {
            if (!core.target.NormalTargetExists)
            {
                GUILayout.Label("Select a target to rendezvous with.");
                base.WindowGUI(windowID);
                return;
            }

            if (core.target.Orbit.referenceBody != orbit.referenceBody)
            {
                GUILayout.Label("Rendezvous target must be in the same sphere of influence.");
                base.WindowGUI(windowID);
                return;
            }

            GUILayout.BeginVertical();

            step = (Step)GuiUtils.ArrowSelector((int)step, numSteps, stepStrings[(int)step]);

            double leadTime = 30;

            switch (step)
            {
            case Step.AlignPlanes:

                GUILayout.Label("First, bring your relative inclination to zero by aligning your orbital plane with the target's orbital plane:");
                GUILayout.Label("Relative inclination: " + orbit.RelativeInclination(core.target.Orbit).ToString("F2") + "º");

                if (GUILayout.Button("Align Planes"))
                {
                    double   UT;
                    Vector3d dV;
                    if (orbit.AscendingNodeExists(core.target.Orbit))
                    {
                        dV = OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesAscending(orbit, core.target.Orbit, vesselState.time, out UT);
                    }
                    else
                    {
                        dV = OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesDescending(orbit, core.target.Orbit, vesselState.time, out UT);
                    }
                    vessel.PlaceManeuverNode(orbit, dV, UT);
                }
                break;

            case Step.PhasingOrbit:

                double phasingOrbitRadius = 0.9 * core.target.Orbit.PeR;
                if (phasingOrbitRadius < orbit.referenceBody.Radius + orbit.referenceBody.RealMaxAtmosphereAltitude())
                {
                    phasingOrbitRadius = 1.1 * core.target.Orbit.ApR;
                }
                double phasingOrbitAltitude = phasingOrbitRadius - mainBody.Radius;
                GUILayout.Label("Next, establish a circular phasing orbit close to the target orbit.");
                GUILayout.Label("Target orbit: " + MuUtils.ToSI(core.target.Orbit.PeA, 3) + "m x " + MuUtils.ToSI(core.target.Orbit.ApA, 3) + "m");
                GUILayout.Label("Suggested phasing orbit: " + MuUtils.ToSI(phasingOrbitAltitude, 3) + "m x " + MuUtils.ToSI(phasingOrbitAltitude, 3) + "m");
                GUILayout.Label("Current orbit: " + MuUtils.ToSI(orbit.PeA, 3) + "m x " + MuUtils.ToSI(orbit.ApA, 3) + "m");

                if (GUILayout.Button("Establish Phasing Orbit"))
                {
                    if (orbit.ApR < phasingOrbitRadius)
                    {
                        double   UT1 = vesselState.time + leadTime;
                        Vector3d dV1 = OrbitalManeuverCalculator.DeltaVToChangeApoapsis(orbit, UT1, phasingOrbitRadius);
                        vessel.PlaceManeuverNode(orbit, dV1, UT1);
                        Orbit    transferOrbit = vessel.patchedConicSolver.maneuverNodes[0].nextPatch;
                        double   UT2           = transferOrbit.NextApoapsisTime(UT1);
                        Vector3d dV2           = OrbitalManeuverCalculator.DeltaVToCircularize(transferOrbit, UT2);
                        vessel.PlaceManeuverNode(transferOrbit, dV2, UT2);
                    }
                    else if (orbit.PeR > phasingOrbitRadius)
                    {
                        double   UT1 = vesselState.time + leadTime;
                        Vector3d dV1 = OrbitalManeuverCalculator.DeltaVToChangePeriapsis(orbit, UT1, phasingOrbitRadius);
                        vessel.PlaceManeuverNode(orbit, dV1, UT1);
                        Orbit    transferOrbit = vessel.patchedConicSolver.maneuverNodes[0].nextPatch;
                        double   UT2           = transferOrbit.NextPeriapsisTime(UT1);
                        Vector3d dV2           = OrbitalManeuverCalculator.DeltaVToCircularize(transferOrbit, UT2);
                        vessel.PlaceManeuverNode(transferOrbit, dV2, UT2);
                    }
                    else
                    {
                        double   UT = orbit.NextTimeOfRadius(vesselState.time, phasingOrbitRadius);
                        Vector3d dV = OrbitalManeuverCalculator.DeltaVToCircularize(orbit, UT);
                        vessel.PlaceManeuverNode(orbit, dV, UT);
                    }
                }

                break;

            case Step.Transfer:

                GUILayout.Label("Once in the phasing orbit, transfer to the target orbit at just the right time to intercept the target:");

                if (GUILayout.Button("Intercept with Hohmann transfer"))
                {
                    double   UT;
                    Vector3d dV = OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(orbit, core.target.Orbit, vesselState.time, out UT);
                    vessel.PlaceManeuverNode(orbit, dV, UT);
                }

                double closestApproachTime = orbit.NextClosestApproachTime(core.target.Orbit, vesselState.time);

                GUILayout.Label("Once on a transfer trajectory, match velocities at closest approach:");
                GUILayout.Label("Time until closest approach: " + GuiUtils.TimeToDHMS(closestApproachTime - vesselState.time));
                GUILayout.Label("Separation at closest approach: " + MuUtils.ToSI(orbit.Separation(core.target.Orbit, closestApproachTime), 0) + "m");

                if (GUILayout.Button("Match velocities at closest approach"))
                {
                    double   UT = closestApproachTime;
                    Vector3d dV = OrbitalManeuverCalculator.DeltaVToMatchVelocities(orbit, UT, core.target.Orbit);
                    vessel.PlaceManeuverNode(orbit, dV, UT);
                }

                break;

            case Step.GetCloser:
                GUILayout.Label("If you aren't close enough after matching velocities, thrust gently toward the target:");

                if (GUILayout.Button("Get closer"))
                {
                    double   UT          = vesselState.time;
                    double   interceptUT = UT + 100;
                    Vector3d dV          = OrbitalManeuverCalculator.DeltaVToInterceptAtTime(orbit, UT, core.target.Orbit, interceptUT, 10);
                    vessel.PlaceManeuverNode(orbit, dV, UT);
                }

                GUILayout.Label("Then match velocities again at closest approach");

                break;
            }

            GUILayout.EndVertical();

            MechJebModuleRendezvousAutopilot autopilot = core.GetComputerModule <MechJebModuleRendezvousAutopilot>();

            if (autopilot != null)
            {
                bool active = GUILayout.Toggle(autopilot.enabled, "Autopilot enable");
                if (autopilot.enabled != active)
                {
                    if (active)
                    {
                        autopilot.users.Add(this);
                    }
                    else
                    {
                        autopilot.users.Remove(this);
                    }
                }
                if (autopilot.enabled)
                {
                    GUILayout.Label("Status: " + autopilot.status);
                }
            }

            base.WindowGUI(windowID);
        }
        protected override void WindowGUI(int windowID)
        {
            if (!core.target.NormalTargetExists)
            {
                GUILayout.Label(Localizer.Format("#MechJeb_RZauto_label1"));//"Select a target to rendezvous with."
                base.WindowGUI(windowID);
                return;
            }

            MechJebModuleRendezvousAutopilot autopilot = core.GetComputerModule <MechJebModuleRendezvousAutopilot>();

            if (core.target.TargetOrbit.referenceBody != orbit.referenceBody)
            {
                GUILayout.Label(Localizer.Format("#MechJeb_RZauto_label2"));//"Rendezvous target must be in the same sphere of influence."
                if (autopilot.enabled)
                {
                    autopilot.users.Remove(this);
                }
                base.WindowGUI(windowID);
                return;
            }

            GUILayout.BeginVertical();

            if (autopilot != null)
            {
                GuiUtils.SimpleLabel(Localizer.Format("#MechJeb_RZauto_label3"), core.target.Name);//"Rendezvous target"

                if (!autopilot.enabled)
                {
                    if (GUILayout.Button(Localizer.Format("#MechJeb_RZauto_button1")))
                    {
                        autopilot.users.Add(this);                                                               //"Engage autopilot"
                    }
                }
                else
                {
                    if (GUILayout.Button(Localizer.Format("#MechJeb_RZauto_button2")))
                    {
                        autopilot.users.Remove(this);                                                               //"Disengage autopilot"
                    }
                }

                GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_RZauto_label4"), autopilot.desiredDistance, "m"); //"Desired final distance:"
                GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_RZauto_label5"), autopilot.maxPhasingOrbits);     //"Max # of phasing orbits:"

                if (autopilot.maxPhasingOrbits < 5)
                {
                    GUIStyle s = new GUIStyle(GUI.skin.label);
                    s.normal.textColor = Color.yellow;
                    GUILayout.Label(Localizer.Format("#MechJeb_RZauto_label6"), s);//"Max # of phasing orbits must be at least 5."
                }

                if (autopilot.enabled)
                {
                    GUILayout.Label(Localizer.Format("#MechJeb_RZauto_label7", autopilot.status));                    //"Status: <<1>>"
                }
            }

            core.node.autowarp = GUILayout.Toggle(core.node.autowarp, Localizer.Format("#MechJeb_RZauto_checkbox1"));//"Auto-warp"

            GUILayout.EndVertical();

            base.WindowGUI(windowID);
        }