Exemplo n.º 1
0
        private void SelectTarget(int index, TextMenu.Item tmi)
        {
            List <MechJebModuleSmartASS.Target> activeTargets = null;

            switch (currentMenu)
            {
            case MJMenu.OrbitMenu:
                activeTargets = orbitalTargets;
                break;

            case MJMenu.SurfaceMenu:
                break;

            case MJMenu.TargetMenu:
                activeTargets = targetTargets;
                break;
            }

            UpdateJebReferences();

            if (activeSmartass != null && activeTargets != null)
            {
                activeSmartass.target = activeTargets[index];
                activeSmartass.Engage();
            }
        }
Exemplo n.º 2
0
        private void LandingGuidance(int index, TextMenu.Item tmi)
        {
            UpdateJebReferences();
            if (activeJeb != null)
            {
                var autopilot = activeJeb.GetComputerModule <MechJebModuleLandingAutopilot>();

                if (autopilot == null)
                {
                    return;
                }

                if (autopilot.enabled)
                {
                    autopilot.StopLanding();
                }
                else
                {
                    var landingGuidanceAP = activeJeb.GetComputerModule <MechJebModuleLandingGuidance>();
                    if (landingGuidanceAP != null)
                    {
                        if (activeJeb.target.PositionTargetExists)
                        {
                            autopilot.LandAtPositionTarget(landingGuidanceAP);
                        }
                        else
                        {
                            autopilot.LandUntargeted(landingGuidanceAP);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void DoCircularize(int index, TextMenu.Item tmi)
        {
            double   UT = 0.0;
            Vector3d dV = Vector3d.zero;
            Orbit    o  = vessel.orbit;

            switch (tmi.id)
            {
            case (int)MechJebModuleManeuverPlanner.TimeReference.APOAPSIS:
                UT = o.NextApoapsisTime(Planetarium.GetUniversalTime());
                dV = OrbitalManeuverCalculator.DeltaVToCircularize(o, UT);
                break;

            case (int)MechJebModuleManeuverPlanner.TimeReference.PERIAPSIS:
                UT = o.NextPeriapsisTime(Planetarium.GetUniversalTime());
                dV = OrbitalManeuverCalculator.DeltaVToCircularize(o, UT);
                break;

            case (int)MechJebModuleManeuverPlanner.TimeReference.X_FROM_NOW:
                UT = Planetarium.GetUniversalTime() + 15.0;
                dV = OrbitalManeuverCalculator.DeltaVToCircularize(o, UT);
                break;
            }

            if (UT > 0.0)
            {
                vessel.PlaceManeuverNode(o, dV, UT);
            }
        }
Exemplo n.º 4
0
 private void DockingGuidance(int index, TextMenu.Item tmi)
 {
     UpdateJebReferences();
     if (activeJeb != null)
     {
         var autopilot = activeJeb.GetComputerModule <MechJebModuleDockingAutopilot>();
         if (autopilot != null)
         {
             var autopilotController = activeJeb.GetComputerModule <MechJebModuleDockingGuidance>();
             if (autopilotController != null)
             {
                 if (autopilot.enabled)
                 {
                     autopilot.users.Remove(autopilotController);
                 }
                 else if (activeJeb.target.Target is ModuleDockingNode)
                 {
                     if (autopilot.speedLimit < 0)
                     {
                         autopilot.speedLimit = 0;
                     }
                     autopilot.users.Add(autopilotController);
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
        private void AscentGuidance(int index, TextMenu.Item tmi)
        {
            UpdateJebReferences();
            if (activeJeb != null)
            {
                MechJebModuleAscentAutopilot ap = activeJeb.GetComputerModule <MechJebModuleAscentAutopilot>();
                if (ap == null)
                {
                    return;
                }

                var agPilot = activeJeb.GetComputerModule <MechJebModuleAscentGuidance>();
                if (agPilot != null)
                {
                    if (ap.enabled)
                    {
                        ap.users.Remove(agPilot);
                    }
                    else
                    {
                        ap.users.Add(agPilot);
                    }
                }
            }
        }
Exemplo n.º 6
0
 private void ToggleForceRoll(int index, TextMenu.Item tmi)
 {
     UpdateJebReferences();
     if (activeSmartass != null)
     {
         activeSmartass.forceRol      = !activeSmartass.forceRol;
         forceRollMenuItem.isSelected = activeSmartass.forceRol;
         activeSmartass.Engage();
     }
 }
Exemplo n.º 7
0
        private void SmartASS_Node(int index, TextMenu.Item tmi)
        {
            UpdateJebReferences();

            if (activeSmartass != null)
            {
                activeSmartass.target = MechJebModuleSmartASS.Target.NODE;
                activeSmartass.Engage();
            }
        }
Exemplo n.º 8
0
        public void Start()
        {
            // I guess I shouldn't have expected Squad to actually do something nice for a modder like that.
            // In 0.23, loading in non-alphabetical order is still broken.

            // But now we have KSPAssembly and KSPAssemblyDependency, which actually sidestep the issue, and finally
            // Mu told someone about it and now I can avoid this path hardlinking.
            // Actually, better yet. Let it check for the new canonical location instead. Because f**k installation problems.
            if (!JSI.InstallationPathWarning.Warn())
            {
                return;
            }

            if (!string.IsNullOrEmpty(itemColor))
            {
                itemColorValue = ConfigNode.ParseColor32(itemColor);
            }
            if (!string.IsNullOrEmpty(selectedColor))
            {
                selectedColorValue = ConfigNode.ParseColor32(selectedColor);
            }
            if (!string.IsNullOrEmpty(unavailableColor))
            {
                unavailableColorValue = ConfigNode.ParseColor32(unavailableColor);
            }

            UpdateJebReferences();

            topMenu.labelColor    = JUtil.ColorToColorTag(itemColorValue);
            topMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            topMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);

            // If MechJeb is installed, but not found on the craft, menu options can't be populated correctly.
            if (activeJeb != null)
            {
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.OFF], SmartASS_Off));
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.KILLROT].Replace('\n', ' '), SmartASS_KillRot));
                nodeMenuItem = new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.NODE], SmartASS_Node);
                topMenu.Add(nodeMenuItem);
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.ORBITAL], OrbitalMenu));
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.SURFACE], SurfaceMenu));
                targetMenuItem = new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.TARGET], TargetMenu);
                topMenu.Add(targetMenuItem);
                // Analysis disable once RedundantCast
                forceRollMenuItem = new TextMenu.Item(String.Format("Force Roll: {0:f0}", (activeSmartass != null) ? (double)activeSmartass.rol : 0.0), ToggleForceRoll);
                topMenu.Add(forceRollMenuItem);
                topMenu.Add(new TextMenu.Item("Execute Next Node", ExecuteNode, (int)MJMenu.ExecuteNodeMenu));
                topMenu.Add(new TextMenu.Item("Ascent Guidance", AscentGuidance, (int)MJMenu.AscentGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Land Somewhere", LandingGuidance, (int)MJMenu.LandingGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Docking Guidance", DockingGuidance, (int)MJMenu.DockingGuidanceMenu));
                //topMenu.Add(new TextMenu.Item("Hold Alt & Heading", SpaceplaneGuidance, (int)MJMenu.SpacePlaneMenu));
                topMenu.Add(new TextMenu.Item("Circularize", CircularizeMenu, (int)MJMenu.CircularizeMenu));
            }
            activeMenu = topMenu;
        }
Exemplo n.º 9
0
        // MOARdV: Spaceplane Guidance can not be implemented cleanly, because
        // MJ's MechJebModuleSpaceplaneGuidance is missing the 'public'
        // keyword.  We could use another controller (like ourself), but that
        // means one is forced to use our menu to turn it off (the MJ GUI is
        // not able to change the setting), and vice versa.  Since every other
        // place where we interface with MJ, we use MJ's objects as the
        // controller, this breaks our design model.  If/when MJ makes the
        // module public, all of the commented code here related to it can be
        // uncommented, and this missive can be deleted.
        //private void SpaceplaneGuidance(int index, TextMenu.Item tmi)
        //{
        //	UpdateJebReferences();
        //	if (activeJeb != null) {
        //		var autopilot = activeJeb.GetComputerModule<MechJebModuleSpaceplaneAutopilot>();
        //		if (autopilot != null) {
        //			MechJebModuleSpaceplaneGuidance is not currently public.  Can't use it.
        //			var autopilotController = activeJeb.GetComputerModule<MechJebModuleSpaceplaneGuidance>();
        //			if (autopilotController != null) {
        //				if (autopilot.enabled && autopilot.mode == MechJebModuleSpaceplaneAutopilot.Mode.HOLD) {
        //					autopilot.AutopilotOff();
        //				} else if (!autopilot.enabled) {
        //					autopilot.HoldHeadingAndAltitude(autopilotController);
        //				}
        //			}
        //		}
        //	}
        //}

        private void CircularizeMenu(int index, TextMenu.Item tmi)
        {
            currentMenu = MJMenu.CircularizeMenu;

            activeMenu               = new TextMenu();
            activeMenu.labelColor    = JUtil.ColorToColorTag(itemColorValue);
            activeMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            activeMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);
            activeMenu.menuTitle     = "== Circularize Menu:";

            activeMenu.Add(new TextMenu.Item("At Next Ap", DoCircularize, (int)MechJebModuleManeuverPlanner.TimeReference.APOAPSIS));
            activeMenu.Add(new TextMenu.Item("At Next Pe", DoCircularize, (int)MechJebModuleManeuverPlanner.TimeReference.PERIAPSIS));
            activeMenu.Add(new TextMenu.Item("In 15s", DoCircularize, (int)MechJebModuleManeuverPlanner.TimeReference.X_FROM_NOW));
        }
Exemplo n.º 10
0
        private void TargetMenu(int index, TextMenu.Item tmi)
        {
            currentMenu = MJMenu.TargetMenu;

            activeMenu               = new TextMenu();
            activeMenu.labelColor    = JUtil.ColorToColorTag(itemColorValue);
            activeMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            activeMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);

            foreach (MechJebModuleSmartASS.Target target in targetTargets)
            {
                activeMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)target].Replace('\n', ' '), SelectTarget));
            }
        }
Exemplo n.º 11
0
        public void Start()
        {
            // I guess I shouldn't have expected Squad to actually do something nice for a modder like that.
            // In 0.23, loading in non-alphabetical order is still broken.
            JSI.InstallationPathWarning.Warn("MechJeb2RPM");

            if (!string.IsNullOrEmpty(itemColor))
            {
                itemColorValue = ConfigNode.ParseColor32(itemColor);
            }
            if (!string.IsNullOrEmpty(selectedColor))
            {
                selectedColorValue = ConfigNode.ParseColor32(selectedColor);
            }
            if (!string.IsNullOrEmpty(unavailableColor))
            {
                unavailableColorValue = ConfigNode.ParseColor32(unavailableColor);
            }


            UpdateJebReferences();

            topMenu.labelColor    = JUtil.ColorToColorTag(itemColorValue);
            topMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            topMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);

            // If MechJeb is installed, but not found on the craft, menu options can't be populated correctly.
            if (activeJeb != null)
            {
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.OFF], SmartASS_Off));
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.KILLROT].Replace('\n', ' '), SmartASS_KillRot));
                nodeMenuItem = new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.NODE], SmartASS_Node);
                topMenu.Add(nodeMenuItem);
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.ORBITAL], OrbitalMenu));
                targetMenuItem = new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.TARGET], TargetMenu);
                topMenu.Add(targetMenuItem);
                // Analysis disable once RedundantCast
                forceRollMenuItem = new TextMenu.Item(String.Format("Force Roll: {0:f0}", (double)activeSmartass.rol), ToggleForceRoll);
                topMenu.Add(forceRollMenuItem);
                topMenu.Add(new TextMenu.Item("Execute Next Node", ExecuteNode, (int)MJMenu.ExecuteNodeMenu));
                topMenu.Add(new TextMenu.Item("Ascent Guidance", AscentGuidance, (int)MJMenu.AscentGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Land Somewhere", LandingGuidance, (int)MJMenu.LandingGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Docking Guidance", DockingGuidance, (int)MJMenu.DockingGuidanceMenu));
                //topMenu.Add(new TextMenu.Item("Hold Alt & Heading", SpaceplaneGuidance, (int)MJMenu.SpacePlaneMenu));
                topMenu.Add(new TextMenu.Item("Circularize", CircularizeMenu, (int)MJMenu.CircularizeMenu));
            }
            activeMenu = topMenu;
        }
Exemplo n.º 12
0
 private void ExecuteNode(int index, TextMenu.Item tmi)
 {
     UpdateJebReferences();
     if (activeJeb != null)
     {
         MechJebModuleManeuverPlanner mp = activeJeb.GetComputerModule <MechJebModuleManeuverPlanner>();
         if (mp != null)
         {
             // We have a valid maneuver planner, which means we can
             // tell MJ to execute a node.  Or abort a node.
             if (activeJeb.node.enabled)
             {
                 activeJeb.node.Abort();
             }
             else
             {
                 activeJeb.node.ExecuteOneNode(mp);
             }
         }
     }
 }
Exemplo n.º 13
0
        public void Start()
        {
            // I guess I shouldn't have expected Squad to actually do something nice for a modder like that.
            // In 0.23, loading in non-alphabetical order is still broken.

            // But now we have KSPAssembly and KSPAssemblyDependency, which actually sidestep the issue, and finally
            // Mu told someone about it and now I can avoid this path hardlinking.
            // Actually, better yet. Let it check for the new canonical location instead. Because f**k installation problems.
            if (!JSI.InstallationPathWarning.Warn())
                return;

            if (!string.IsNullOrEmpty(itemColor))
                itemColorValue = ConfigNode.ParseColor32(itemColor);
            if (!string.IsNullOrEmpty(selectedColor))
                selectedColorValue = ConfigNode.ParseColor32(selectedColor);
            if (!string.IsNullOrEmpty(unavailableColor))
                unavailableColorValue = ConfigNode.ParseColor32(unavailableColor);

            UpdateJebReferences();

            topMenu.labelColor = JUtil.ColorToColorTag(itemColorValue);
            topMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            topMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);

            // If MechJeb is installed, but not found on the craft, menu options can't be populated correctly.
            if (activeJeb != null)
            {
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.OFF], SmartASS_Off));
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.KILLROT].Replace('\n', ' '), SmartASS_KillRot));
                nodeMenuItem = new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.NODE], SmartASS_Node);
                topMenu.Add(nodeMenuItem);
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.ORBITAL], OrbitalMenu));
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.SURFACE], SurfaceMenu));
                targetMenuItem = new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.TARGET], TargetMenu);
                topMenu.Add(targetMenuItem);
                // Analysis disable once RedundantCast
                forceRollMenuItem = new TextMenu.Item(String.Format("Force Roll: {0:f0}", (activeSmartass != null) ? (double)activeSmartass.rol : 0.0), ToggleForceRoll);
                topMenu.Add(forceRollMenuItem);
                topMenu.Add(new TextMenu.Item("Execute Next Node", ExecuteNode, (int)MJMenu.ExecuteNodeMenu));
                topMenu.Add(new TextMenu.Item("Ascent Guidance", AscentGuidance, (int)MJMenu.AscentGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Land Somewhere", LandingGuidance, (int)MJMenu.LandingGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Docking Guidance", DockingGuidance, (int)MJMenu.DockingGuidanceMenu));
                //topMenu.Add(new TextMenu.Item("Hold Alt & Heading", SpaceplaneGuidance, (int)MJMenu.SpacePlaneMenu));
                topMenu.Add(new TextMenu.Item("Circularize", CircularizeMenu, (int)MJMenu.CircularizeMenu));
            }
            activeMenu = topMenu;
        }
Exemplo n.º 14
0
        public void Start()
        {
            // I guess I shouldn't have expected Squad to actually do something nice for a modder like that.
            // In 0.23, loading in non-alphabetical order is still broken.
            JSI.InstallationPathWarning.Warn("MechJeb2RPM");

            if (!string.IsNullOrEmpty(itemColor))
                itemColorValue = ConfigNode.ParseColor32(itemColor);
            if (!string.IsNullOrEmpty(selectedColor))
                selectedColorValue = ConfigNode.ParseColor32(selectedColor);
            if (!string.IsNullOrEmpty(unavailableColor))
                unavailableColorValue = ConfigNode.ParseColor32(unavailableColor);

            UpdateJebReferences();

            topMenu.labelColor = JUtil.ColorToColorTag(itemColorValue);
            topMenu.selectedColor = JUtil.ColorToColorTag(selectedColorValue);
            topMenu.disabledColor = JUtil.ColorToColorTag(unavailableColorValue);

            // If MechJeb is installed, but not found on the craft, menu options can't be populated correctly.
            if (activeJeb != null) {
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.OFF], SmartASS_Off));
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.KILLROT].Replace('\n', ' '), SmartASS_KillRot));
                nodeMenuItem = new TextMenu.Item(MechJebModuleSmartASS.TargetTexts[(int)MechJebModuleSmartASS.Target.NODE], SmartASS_Node);
                topMenu.Add(nodeMenuItem);
                topMenu.Add(new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.ORBITAL], OrbitalMenu));
                targetMenuItem = new TextMenu.Item(MechJebModuleSmartASS.ModeTexts[(int)MechJebModuleSmartASS.Mode.TARGET], TargetMenu);
                topMenu.Add(targetMenuItem);
                // Analysis disable once RedundantCast
                forceRollMenuItem = new TextMenu.Item(String.Format("Force Roll: {0:f0}", (double)activeSmartass.rol), ToggleForceRoll);
                topMenu.Add(forceRollMenuItem);
                topMenu.Add(new TextMenu.Item("Execute Next Node", ExecuteNode, (int)MJMenu.ExecuteNodeMenu));
                topMenu.Add(new TextMenu.Item("Ascent Guidance", AscentGuidance, (int)MJMenu.AscentGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Land Somewhere", LandingGuidance, (int)MJMenu.LandingGuidanceMenu));
                topMenu.Add(new TextMenu.Item("Docking Guidance", DockingGuidance, (int)MJMenu.DockingGuidanceMenu));
                //topMenu.Add(new TextMenu.Item("Hold Alt & Heading", SpaceplaneGuidance, (int)MJMenu.SpacePlaneMenu));
                topMenu.Add(new TextMenu.Item("Circularize", CircularizeMenu, (int)MJMenu.CircularizeMenu));
            }
            activeMenu = topMenu;
        }