override public void activateAction()
 {
     base.activateAction();
     this.smartAss.mode         = Target2Mode[(int)target];
     this.smartAss.target       = target;
     this.smartAss.srfHdg       = this.srfHdg;
     this.smartAss.srfPit       = this.srfPit;
     this.smartAss.srfRol       = this.srfRol;
     this.smartAss.srfVelYaw    = this.srfVelYaw;
     this.smartAss.srfVelPit    = this.srfVelPit;
     this.smartAss.srfVelRol    = this.srfVelRol;
     this.smartAss.rol          = this.rol;
     this.smartAss.advReference = this.advReference;
     this.smartAss.advDirection = this.advDirection;
     this.smartAss.forceRol     = this.forceRol;
     this.smartAss.forcePitch   = this.forcePitch;
     this.smartAss.forceYaw     = this.forceYaw;
     this.smartAss.Engage();
 }
Esempio n. 2
0
        protected override void WindowGUI(int windowID)
        {
            if (btNormal == null)
            {
                btNormal = new GUIStyle(GUI.skin.button);
                btNormal.normal.textColor   = btNormal.focused.textColor = Color.white;
                btNormal.hover.textColor    = btNormal.active.textColor = Color.yellow;
                btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
                btNormal.padding            = new RectOffset(8, 8, 8, 8);

                btActive           = new GUIStyle(btNormal);
                btActive.active    = btActive.onActive;
                btActive.normal    = btActive.onNormal;
                btActive.onFocused = btActive.focused;
                btActive.hover     = btActive.onHover;

                btAuto = new GUIStyle(btNormal);
                btAuto.normal.textColor = Color.red;
                btAuto.onActive         = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
            }

            // If any other module use the attitude controler then let them do it
            if (core.attitude.enabled && core.attitude.users.Count(u => !this.Equals(u)) > 0)
            {
                if (autoDisableSmartASS)
                {
                    target = Target.OFF;
                    if (core.attitude.users.Contains(this))
                    {
                        core.attitude.users.Remove(this);                                     // so we don't suddenly turn on when the other autopilot finishes
                    }
                }
                GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                TargetButton(Target.OFF);
                TargetButton(Target.KILLROT);
                if (vessel.patchedConicsUnlocked())
                {
                    TargetButton(Target.NODE);
                }
                else
                {
                    GUILayout.Button("-", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                }
                GUILayout.EndHorizontal();

                GUILayout.Label("Mode:");
                GUILayout.BeginHorizontal();
                ModeButton(Mode.ORBITAL);
                ModeButton(Mode.SURFACE);
                ModeButton(Mode.TARGET);
                ModeButton(Mode.ADVANCED);
                GUILayout.EndHorizontal();

                switch (mode)
                {
                case Mode.ORBITAL:

                    GUILayout.BeginHorizontal();
                    TargetButton(Target.PROGRADE);
                    TargetButton(Target.NORMAL_PLUS);
                    TargetButton(Target.RADIAL_PLUS);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.RETROGRADE);
                    TargetButton(Target.NORMAL_MINUS);
                    TargetButton(Target.RADIAL_MINUS);
                    GUILayout.EndHorizontal();

                    ForceRoll();

                    break;

                case Mode.SURFACE:
                    double val = (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1);     // change by 5 if the mod_key is held down, else by 1
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.SURFACE_PROGRADE);
                    TargetButton(Target.SURFACE_RETROGRADE);
                    TargetButtonNoEngage(Target.SURFACE);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.HORIZONTAL_PLUS);
                    TargetButton(Target.HORIZONTAL_MINUS);
                    TargetButton(Target.VERTICAL_PLUS);
                    GUILayout.EndHorizontal();
                    if (target == Target.SURFACE)
                    {
                        bool changed = false;
                        GUILayout.BeginHorizontal();
                        forceYaw = GUILayout.Toggle(forceYaw, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("HDG", srfHdg, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfHdg -= val;
                            changed = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfHdg += val;
                            changed = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfHdg  = 0;
                            changed = true;
                        }
                        if (GUILayout.Button("90", GUILayout.Width(35)))
                        {
                            srfHdg  = 90;
                            changed = true;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        forcePitch = GUILayout.Toggle(forcePitch, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("PIT", srfPit, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfPit -= val;
                            changed = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfPit += val;
                            changed = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfPit  = 0;
                            changed = true;
                        }
                        if (GUILayout.Button("90", GUILayout.Width(35)))
                        {
                            srfPit  = 90;
                            changed = true;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        forceRol = GUILayout.Toggle(forceRol, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("ROL", srfRol, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfRol -= val;
                            changed = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfRol += val;
                            changed = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfRol  = 0;
                            changed = true;
                        }
                        if (GUILayout.Button("180", GUILayout.Width(35)))
                        {
                            srfRol  = 180;
                            changed = true;
                        }
                        GUILayout.EndHorizontal();
                        if (GUILayout.Button("EXECUTE"))
                        {
                            Engage();
                        }
                        if (changed)
                        {
                            Engage(false);
                        }
                        core.attitude.AxisControl(forcePitch, forceYaw, forceRol);
                    }
                    else if (target == Target.SURFACE_PROGRADE || target == Target.SURFACE_RETROGRADE)
                    {
                        bool changed = false;
                        GUILayout.BeginHorizontal();
                        forceRol = GUILayout.Toggle(forceRol, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("ROL", srfVelRol, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfVelRol -= val;
                            changed    = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfVelRol += val;
                            changed    = true;
                        }
                        if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false)))
                        {
                            srfVelRol = -vesselState.vesselRoll.value;
                            changed   = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfVelRol = 0;
                            changed   = true;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        forcePitch = GUILayout.Toggle(forcePitch, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("PIT", srfVelPit, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfVelPit -= val;
                            changed    = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfVelPit += val;
                            changed    = true;
                        }
                        if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false)))
                        {
                            srfVelPit = vesselState.AoA.value;
                            changed   = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfVelPit = 0;
                            changed   = true;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        forceYaw = GUILayout.Toggle(forceYaw, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("YAW", srfVelYaw, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfVelYaw -= val;
                            changed    = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfVelYaw += val;
                            changed    = true;
                        }
                        if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false)))
                        {
                            srfVelYaw = -vesselState.AoS.value;
                            changed   = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfVelYaw = 0;
                            changed   = true;
                        }
                        GUILayout.EndHorizontal();
                        if (GUILayout.Button("EXECUTE"))
                        {
                            Engage();
                        }
                        if (changed)
                        {
                            Engage(false);
                        }
                        core.attitude.AxisControl(forcePitch, forceYaw, forceRol);
                    }
                    break;

                case Mode.TARGET:
                    if (core.target.NormalTargetExists)
                    {
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.TARGET_PLUS);
                        TargetButton(Target.RELATIVE_PLUS);
                        TargetButton(Target.PARALLEL_PLUS);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.TARGET_MINUS);
                        TargetButton(Target.RELATIVE_MINUS);
                        TargetButton(Target.PARALLEL_MINUS);
                        GUILayout.EndHorizontal();

                        ForceRoll();
                    }
                    else
                    {
                        GUILayout.Label("Please select a target");
                    }
                    break;

                case Mode.ADVANCED:
                    GUILayout.Label("Reference:");
                    advReference = (AttitudeReference)GuiUtils.ComboBox.Box((int)advReference, ReferenceTexts, this);

                    GUILayout.Label("Direction:");
                    advDirection = (Vector6.Direction)GuiUtils.ComboBox.Box((int)advDirection, directionTexts, directionTexts);

                    ForceRoll();

                    if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true)))
                    {
                        target = Target.ADVANCED;
                        Engage();
                    }
                    break;

                case Mode.AUTO:
                    break;
                }

                GUILayout.EndVertical();
            }

            base.WindowGUI(windowID);
        }
        override public void WindowGUI(int windowID)
        {
            base.preWindowGUI(windowID);
            base.WindowGUI(windowID);
            int modeSelectorIdx = TargetIsMode[(int)target]
                                ? targetModeSelectorIdxs[(int)target]
                                : modeModeSelectorIdxs[(int)Target2Mode[(int)target]];

            GUILayout.BeginHorizontal(GUILayout.Width(150));
            modeSelectorIdx = GuiUtils.ComboBox.Box(modeSelectorIdx, modeStrings.ToArray(), modeStrings);
            GUILayout.EndHorizontal();
            bool showForceRol = false;

            if (this.isTargetMode[modeSelectorIdx])
            {
                target       = this.targetModes[modeSelectorIdx];
                showForceRol = (target == MechJebModuleSmartASS.Target.NODE);
            }
            else
            {
                MechJebModuleSmartASS.Mode mode = this.modeModes[modeSelectorIdx];
                List <String> targetStrings     = this.targetStrings[(int)mode];
                if (targetStrings.Count == 1)
                {
                    target = this.targets[(int)mode][0];
                }
                else
                {
                    int targetSelectorIdx = (Target2Mode[(int)target] == mode) ? targetSelectorIdxs[(int)target] : 0;
                    GUILayout.BeginHorizontal(GUILayout.Width(160));
                    targetSelectorIdx = GuiUtils.ComboBox.Box(targetSelectorIdx, targetStrings.ToArray(), targetStrings);
                    GUILayout.EndHorizontal();
                    target = this.targets[(int)mode][targetSelectorIdx];
                }
                switch (mode)
                {
                case MechJebModuleSmartASS.Mode.ORBITAL:
                case MechJebModuleSmartASS.Mode.TARGET:
                    showForceRol = true;
                    break;

                case MechJebModuleSmartASS.Mode.ADVANCED:
                    GUILayout.BeginHorizontal(GUILayout.Width(220));
                    advReference = (AttitudeReference)GuiUtils.ComboBox.Box((int)advReference, ReferenceTexts, ReferenceTexts);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal(GUILayout.Width(200));
                    advDirection = (Vector6.Direction)GuiUtils.ComboBox.Box((int)advDirection, DirectionTexts, DirectionTexts);
                    GUILayout.EndHorizontal();
                    showForceRol = true;
                    break;
                }
                switch (target)
                {
                case MechJebModuleSmartASS.Target.SURFACE:
                    GUILayout.Label("", GUI.skin.label, GUILayout.ExpandWidth(true));
                    forceYaw    = GUILayout.Toggle(forceYaw, "Heading: ", GUILayout.ExpandWidth(false));
                    srfHdg.text = GUILayout.TextField(srfHdg.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(true));
                    forcePitch  = GUILayout.Toggle(forcePitch, "Pitch: ", GUILayout.ExpandWidth(false));
                    srfPit.text = GUILayout.TextField(srfPit.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(true));
                    forceRol    = GUILayout.Toggle(forceRol, "Roll: ", GUILayout.ExpandWidth(false));
                    srfRol.text = GUILayout.TextField(srfRol.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(false));
                    break;

                case MechJebModuleSmartASS.Target.SURFACE_PROGRADE:
                case MechJebModuleSmartASS.Target.SURFACE_RETROGRADE:
                    GUILayout.Label("", GUI.skin.label, GUILayout.ExpandWidth(true));
                    forcePitch     = GUILayout.Toggle(forcePitch, "Pitch: ", GUILayout.ExpandWidth(false));
                    srfVelPit.text = GUILayout.TextField(srfVelPit.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(true));
                    forceRol       = GUILayout.Toggle(forceRol, "Roll: ", GUILayout.ExpandWidth(false));
                    srfVelRol.text = GUILayout.TextField(srfVelRol.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(true));
                    forceYaw       = GUILayout.Toggle(forceYaw, "Yaw: ", GUILayout.ExpandWidth(false));
                    srfVelYaw.text = GUILayout.TextField(srfVelYaw.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(false));
                    break;
                }
            }
            GUILayout.Label("", GUILayout.ExpandWidth(true));
            if (showForceRol)
            {
                forceRol = GUILayout.Toggle(forceRol, "Force Roll: ", GUILayout.ExpandWidth(false));
                rol.text = GUILayout.TextField(rol.text, GUILayout.Width(37));
                GUILayout.Label("°", GUILayout.ExpandWidth(false));
            }
            targetName = TargetTexts[(int)target];
            base.postWindowGUI(windowID);
        }
Esempio n. 4
0
        protected override void WindowGUI(int windowID)
        {
            if (btNormal == null)
            {
                btNormal = new GUIStyle(GUI.skin.button);
                btNormal.normal.textColor   = btNormal.focused.textColor = Color.white;
                btNormal.hover.textColor    = btNormal.active.textColor = Color.yellow;
                btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
                btNormal.padding            = new RectOffset(8, 8, 8, 8);

                btActive           = new GUIStyle(btNormal);
                btActive.active    = btActive.onActive;
                btActive.normal    = btActive.onNormal;
                btActive.onFocused = btActive.focused;
                btActive.hover     = btActive.onHover;

                btAuto = new GUIStyle(btNormal);
                btAuto.normal.textColor = Color.red;
                btAuto.onActive         = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
            }

            // If any other module use the attitude controler then let them do it
            if (core.attitude.enabled && core.attitude.users.Count(u => !this.Equals(u)) > 0)
            {
                GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                TargetButton(Target.OFF);
                TargetButton(Target.KILLROT);
                TargetButton(Target.NODE);
                GUILayout.EndHorizontal();

                GUILayout.Label("Mode:");
                GUILayout.BeginHorizontal();
                ModeButton(Mode.ORBITAL);
                ModeButton(Mode.SURFACE);
                ModeButton(Mode.TARGET);
                ModeButton(Mode.ADVANCED);
                GUILayout.EndHorizontal();

                switch (mode)
                {
                case Mode.ORBITAL:
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.PROGRADE);
                    TargetButton(Target.NORMAL_PLUS);
                    TargetButton(Target.RADIAL_PLUS);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.RETROGRADE);
                    TargetButton(Target.NORMAL_MINUS);
                    TargetButton(Target.RADIAL_MINUS);
                    GUILayout.EndHorizontal();

                    ForceRoll();

                    break;

                case Mode.SURFACE:
                    GuiUtils.SimpleTextBox("HDG:", srfHdg);
                    GuiUtils.SimpleTextBox("PIT:", srfPit);
                    GuiUtils.SimpleTextBox("ROL:", srfRol);

                    if (GUILayout.Button("EXECUTE", GUILayout.ExpandWidth(true)))
                    {
                        target = Target.SURFACE;
                        Engage();
                    }
                    break;

                case Mode.TARGET:
                    if (core.target.NormalTargetExists)
                    {
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.TARGET_PLUS);
                        TargetButton(Target.RELATIVE_PLUS);
                        TargetButton(Target.PARALLEL_PLUS);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.TARGET_MINUS);
                        TargetButton(Target.RELATIVE_MINUS);
                        TargetButton(Target.PARALLEL_MINUS);
                        GUILayout.EndHorizontal();

                        ForceRoll();
                    }
                    else
                    {
                        GUILayout.Label("Please select a target");
                    }
                    break;

                case Mode.ADVANCED:
                    GUILayout.Label("Reference:");
                    advReference = (AttitudeReference)GuiUtils.ArrowSelector((int)advReference, Enum.GetValues(typeof(AttitudeReference)).Length, advReference.ToString());

                    GUILayout.Label("Direction:");
                    advDirection = (Vector6.Direction)GuiUtils.ArrowSelector((int)advDirection, Enum.GetValues(typeof(Vector6.Direction)).Length, advDirection.ToString());

                    if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true)))
                    {
                        target = Target.ADVANCED;
                        Engage();
                    }
                    break;

                case Mode.AUTO:
                    break;
                }

                GUILayout.EndVertical();
            }

            base.WindowGUI(windowID);
        }
        protected override void WindowGUI(int windowID)
        {
            if (btNormal == null)
            {
                btNormal = new GUIStyle(GUI.skin.button);
                btNormal.normal.textColor = btNormal.focused.textColor = Color.white;
                btNormal.hover.textColor = btNormal.active.textColor = Color.yellow;
                btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
                btNormal.padding = new RectOffset(8, 8, 8, 8);

                btActive = new GUIStyle(btNormal);
                btActive.active = btActive.onActive;
                btActive.normal = btActive.onNormal;
                btActive.onFocused = btActive.focused;
                btActive.hover = btActive.onHover;

                btAuto = new GUIStyle(btNormal);
                btAuto.normal.textColor = Color.red;
                btAuto.onActive = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
            }

            // If any other module use the attitude controler then let them do it
            if (core.attitude.enabled && core.attitude.users.Count(u => !this.Equals(u)) > 0)
            {
                if (autoDisableSmartASS)
                {
                    target = Target.OFF;
                    if (core.attitude.users.Contains(this)) core.attitude.users.Remove(this); // so we don't suddenly turn on when the other autopilot finishes
                }
                GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                TargetButton(Target.OFF);
                TargetButton(Target.KILLROT);
                if (vessel.patchedConicsUnlocked())
                {
                    TargetButton(Target.NODE);
                }
                else
                {
                    GUILayout.Button("-", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                }
                GUILayout.EndHorizontal();

                GUILayout.Label("Mode:");
                GUILayout.BeginHorizontal();
                ModeButton(Mode.ORBITAL);
                ModeButton(Mode.SURFACE);
                ModeButton(Mode.TARGET);
                ModeButton(Mode.ADVANCED);
                GUILayout.EndHorizontal();

                switch (mode)
                {
                    case Mode.ORBITAL:

                        GUILayout.BeginHorizontal();
                        TargetButton(Target.PROGRADE);
                        TargetButton(Target.NORMAL_PLUS);
                        TargetButton(Target.RADIAL_PLUS);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.RETROGRADE);
                        TargetButton(Target.NORMAL_MINUS);
                        TargetButton(Target.RADIAL_MINUS);
                        GUILayout.EndHorizontal();

                        ForceRoll();

                        break;
                    case Mode.SURFACE:
                    	double val = (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1); // change by 5 if the mod_key is held down, else by 1
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.SURFACE_PROGRADE);
                        TargetButton(Target.SURFACE_RETROGRADE);
                        TargetButtonNoEngage(Target.SURFACE);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.HORIZONTAL_PLUS);
                        TargetButton(Target.HORIZONTAL_MINUS);
                        TargetButton(Target.VERTICAL_PLUS);
                        GUILayout.EndHorizontal();
                        if (target == Target.SURFACE) {
                            bool changed = false;
                        	GUILayout.BeginHorizontal();
                            forceYaw = GUILayout.Toggle(forceYaw, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("HDG", srfHdg, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                            	srfHdg -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfHdg += val;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfHdg = 0;
                                changed = true;
                            }
                            if (GUILayout.Button("90", GUILayout.Width(35))) {
                                srfHdg = 90;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                        	GUILayout.BeginHorizontal();
                            forcePitch = GUILayout.Toggle(forcePitch, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("PIT", srfPit, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfPit -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfPit += val;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfPit = 0;
                                changed = true;
                            }
                            if (GUILayout.Button("90", GUILayout.Width(35))) {
                                srfPit = 90;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                        	GUILayout.BeginHorizontal();
                            forceRol = GUILayout.Toggle(forceRol, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("ROL", srfRol, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfRol -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfRol += val;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfRol = 0;
                                changed = true;
                            }
                            if (GUILayout.Button("180", GUILayout.Width(35))) {
                                srfRol = 180;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                            if (GUILayout.Button("EXECUTE")) {
                                Engage();
                            }
                            if (changed)
                            {
                                Engage(false);
                            }
                            core.attitude.AxisControl(forcePitch, forceYaw, forceRol);
                        } else if (target == Target.SURFACE_PROGRADE || target == Target.SURFACE_RETROGRADE)
                        {
                            bool changed = false;
                            GUILayout.BeginHorizontal();
                            forceRol = GUILayout.Toggle(forceRol, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("ROL", srfVelRol, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfVelRol -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfVelRol += val;
                                changed = true;
                            }
                            if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false))) {
                                srfVelRol = -vesselState.vesselRoll.value;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfVelRol = 0;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            forcePitch = GUILayout.Toggle(forcePitch, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("PIT", srfVelPit, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfVelPit -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfVelPit += val;
                                changed = true;
                            }
                            if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false))) {
                                srfVelPit = vesselState.AoA.value;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfVelPit = 0;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            forceYaw = GUILayout.Toggle(forceYaw, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("YAW", srfVelYaw, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfVelYaw -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfVelYaw += val;
                                changed = true;
                            }
                            if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false))) {
                                srfVelYaw = -vesselState.AoS.value;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfVelYaw = 0;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                            if (GUILayout.Button("EXECUTE"))
                            {
                                Engage();
                            }
                            if (changed)
                            {
                                Engage(false);
                            }
                            core.attitude.AxisControl(forcePitch, forceYaw, forceRol);
                        }
                        break;
                    case Mode.TARGET:
                        if (core.target.NormalTargetExists)
                        {
                            GUILayout.BeginHorizontal();
                            TargetButton(Target.TARGET_PLUS);
                            TargetButton(Target.RELATIVE_PLUS);
                            TargetButton(Target.PARALLEL_PLUS);
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            TargetButton(Target.TARGET_MINUS);
                            TargetButton(Target.RELATIVE_MINUS);
                            TargetButton(Target.PARALLEL_MINUS);
                            GUILayout.EndHorizontal();

                            ForceRoll();
                        }
                        else
                        {
                            GUILayout.Label("Please select a target");
                        }
                        break;
                    case Mode.ADVANCED:
                        GUILayout.Label("Reference:");
                        advReference = (AttitudeReference)GuiUtils.ComboBox.Box((int)advReference, ReferenceTexts, this);

                        GUILayout.Label("Direction:");
                        advDirection = (Vector6.Direction)GuiUtils.ComboBox.Box((int)advDirection, directionTexts, directionTexts);

                        ForceRoll();

                        if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true)))
                        {
                            target = Target.ADVANCED;
                            Engage();
                        }
                        break;
                    case Mode.AUTO:
                        break;
                }

                GUILayout.EndVertical();
            }

            base.WindowGUI(windowID);
        }
        public override void Drive(FlightCtrlState s)
        {
            setPIDParameters();

            switch (controlType)
            {
            case ControlType.TARGET_VELOCITY:
                // Removed the gravity since it also affect the target and we don't know the target pos here.
                // Since the difference is negligable for docking it's removed
                // TODO : add it back once we use the RCS Controler for other use than docking. Account for current acceleration beside gravity ?
                worldVelocityDelta = vesselState.orbitalVelocity - targetVelocity;
                //worldVelocityDelta += TimeWarp.fixedDeltaTime * vesselState.gravityForce; //account for one frame's worth of gravity
                //worldVelocityDelta -= TimeWarp.fixedDeltaTime * gravityForce = FlightGlobals.getGeeForceAtPosition(  Here be the target position  ); ; //account for one frame's worth of gravity
                break;

            case ControlType.VELOCITY_ERROR:
                // worldVelocityDelta already contains the velocity error
                break;

            case ControlType.VELOCITY_TARGET_REL:
                if (core.target.Target == null)
                {
                    rcsDeactivate();
                    return;
                }

                worldVelocityDelta = core.target.RelativeVelocity - targetVelocity;
                break;
            }

            // We work in local vessel coordinate
            Vector3d velocityDelta = Quaternion.Inverse(vessel.GetTransform().rotation) * worldVelocityDelta;

            if (!conserveFuel || (velocityDelta.magnitude > conserveThreshold))
            {
                if (!vessel.ActionGroups[KSPActionGroup.RCS])
                {
                    vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, true);
                }

                Vector3d rcs = new Vector3d();

                for (int i = 0; i < Vector6.Values.Length; i++)
                {
                    Vector6.Direction dir      = Vector6.Values[i];
                    double            dirDv    = Vector3d.Dot(velocityDelta, Vector6.directions[(int)dir]);
                    double            dirAvail = vesselState.rcsThrustAvailable[dir];
                    if (dirAvail > 0 && Math.Abs(dirDv) > 0.001)
                    {
                        double dirAction = dirDv / (dirAvail * TimeWarp.fixedDeltaTime / vesselState.mass);
                        if (dirAction > 0)
                        {
                            rcs += Vector6.directions[(int)dir] * dirAction;
                        }
                    }
                }

                Vector3d omega = Vector3d.zero;

                switch (controlType)
                {
                case ControlType.TARGET_VELOCITY:
                    omega = Quaternion.Inverse(vessel.GetTransform().rotation) * (vessel.acceleration - vesselState.gravityForce);
                    break;

                case ControlType.VELOCITY_TARGET_REL:
                case ControlType.VELOCITY_ERROR:
                    omega = (worldVelocityDelta - prev_worldVelocityDelta) / TimeWarp.fixedDeltaTime;
                    prev_worldVelocityDelta = worldVelocityDelta;
                    break;
                }

                rcs = pid.Compute(rcs, omega);

                // Disabled the low pass filter for now. Was doing more harm than good
                //rcs = lastAct + (rcs - lastAct) * (1 / ((Tf / TimeWarp.fixedDeltaTime) + 1));
                lastAct = rcs;

                s.X = Mathf.Clamp((float)rcs.x, -1, 1);
                s.Y = Mathf.Clamp((float)rcs.z, -1, 1); //note that z and
                s.Z = Mathf.Clamp((float)rcs.y, -1, 1); //y must be swapped
            }
            else if (conserveFuel)
            {
                if (vessel.ActionGroups[KSPActionGroup.RCS])
                {
                    vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, false);
                }
            }

            base.Drive(s);
        }
Esempio n. 7
0
        protected override void WindowGUI(int windowID)
        {
            if (btNormal == null)
            {
                btNormal = new GUIStyle(GUI.skin.button);
                btNormal.normal.textColor = btNormal.focused.textColor = Color.white;
                btNormal.hover.textColor = btNormal.active.textColor = Color.yellow;
                btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
                btNormal.padding = new RectOffset(8, 8, 8, 8);

                btActive = new GUIStyle(btNormal);
                btActive.active = btActive.onActive;
                btActive.normal = btActive.onNormal;
                btActive.onFocused = btActive.focused;
                btActive.hover = btActive.onHover;

                btAuto = new GUIStyle(btNormal);
                btAuto.normal.textColor = Color.red;
                btAuto.onActive = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
            }

            if (core.attitude.enabled && !core.attitude.users.Contains(this))
            {
                GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                TargetButton(Target.OFF);
                TargetButton(Target.KILLROT);
                TargetButton(Target.NODE);
                GUILayout.EndHorizontal();

                GUILayout.Label("Mode:");
                GUILayout.BeginHorizontal();
                ModeButton(Mode.ORBITAL);
                ModeButton(Mode.SURFACE);
                ModeButton(Mode.TARGET);
                ModeButton(Mode.ADVANCED);
                GUILayout.EndHorizontal();

                switch (mode)
                {
                    case Mode.ORBITAL:
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.PROGRADE);
                        TargetButton(Target.NORMAL_PLUS);
                        TargetButton(Target.RADIAL_PLUS);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.RETROGRADE);
                        TargetButton(Target.NORMAL_MINUS);
                        TargetButton(Target.RADIAL_MINUS);
                        GUILayout.EndHorizontal();

                        ForceRoll();

                        break;
                    case Mode.SURFACE:
                        GuiUtils.SimpleTextBox("HDG:", srfHdg);
                        GuiUtils.SimpleTextBox("PIT:", srfPit);
                        GuiUtils.SimpleTextBox("ROL:", srfRol);

                        if (GUILayout.Button("EXECUTE", GUILayout.ExpandWidth(true)))
                        {
                            target = Target.SURFACE;
                            Engage();
                        }
                        break;
                    case Mode.TARGET:
                        if (core.target.NormalTargetExists)
                        {
                            GUILayout.BeginHorizontal();
                            TargetButton(Target.TARGET_PLUS);
                            TargetButton(Target.RELATIVE_PLUS);
                            TargetButton(Target.PARALLEL_PLUS);
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            TargetButton(Target.TARGET_MINUS);
                            TargetButton(Target.RELATIVE_MINUS);
                            TargetButton(Target.PARALLEL_MINUS);
                            GUILayout.EndHorizontal();

                            ForceRoll();
                        }
                        else
                        {
                            GUILayout.Label("Please select a target");
                        }
                        break;
                    case Mode.ADVANCED:
                        GUILayout.Label("Reference:");
                        advReference = (AttitudeReference)GuiUtils.ArrowSelector((int)advReference, Enum.GetValues(typeof(AttitudeReference)).Length, advReference.ToString());

                        GUILayout.Label("Direction:");
                        advDirection = (Vector6.Direction)GuiUtils.ArrowSelector((int)advDirection, Enum.GetValues(typeof(Vector6.Direction)).Length, advDirection.ToString());

                        if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true)))
                        {
                            target = Target.ADVANCED;
                            Engage();
                        }
                        break;
                    case Mode.AUTO:
                        break;
                }

                GUILayout.EndVertical();
            }

            base.WindowGUI(windowID);
        }