Beispiel #1
0
        public override void OnFixedUpdate()
        {
            /* FIXME: copy MJs logic that walks the parts tree and makes sure not to drop firing engines or draining tanks */
            if (!StageManager.CanSeparate)
            {
                return;
            }

            if (StageManager.CurrentStage <= maxstage)
            {
                return;
            }

            if (vesselState.thrustMaximum == 0.0)
            {
                Debug.Log("activating next stage");
                StageManager.ActivateNextStage();
            }

            if (FlamedOutEngines())
            {
                Debug.Log("activating next stage");
                StageManager.ActivateNextStage();
            }
        }
Beispiel #2
0
 private void toggleGroups(byte groups)
 {
     if ((groups & ActionGroupBits.StageBit) != 0)
     {
         if (KSPit.Config.Verbose)
         {
             Debug.Log("KerbalSimpit: Toggling stage");
         }
         FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Stage);
         StageManager.ActivateNextStage();
     }
     if ((groups & ActionGroupBits.GearBit) != 0)
     {
         if (KSPit.Config.Verbose)
         {
             Debug.Log("KerbalSimpit: Toggling gear");
         }
         FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Gear);
     }
     if ((groups & ActionGroupBits.LightBit) != 0)
     {
         if (KSPit.Config.Verbose)
         {
             Debug.Log("KerbalSimpit: Toggling light");
         }
         FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Light);
     }
     if ((groups & ActionGroupBits.RCSBit) != 0)
     {
         if (KSPit.Config.Verbose)
         {
             Debug.Log("KerbalSimpit: Toggling RCS");
         }
         FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.RCS);
     }
     if ((groups & ActionGroupBits.SASBit) != 0)
     {
         if (KSPit.Config.Verbose)
         {
             Debug.Log("KerbalSimpit: Toggling SAS");
         }
         FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.SAS);
     }
     if ((groups & ActionGroupBits.BrakesBit) != 0)
     {
         if (KSPit.Config.Verbose)
         {
             Debug.Log("KerbalSimpit: Toggling brakes");
         }
         FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Brakes);
     }
     if ((groups & ActionGroupBits.AbortBit) != 0)
     {
         if (KSPit.Config.Verbose)
         {
             Debug.Log("KerbalSimpit: Toggling abort");
         }
         FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(KSPActionGroup.Abort);
     }
 }
        void ApplyControl(FlightCtrlState s)
        {
            if (isOn && server.hasClient && lastReceivedData != null)
            {
                s.pitch       += -lastReceivedData.joystickR.y;
                s.yaw         += lastReceivedData.joystickL.x;
                s.roll        += lastReceivedData.joystickR.x;
                s.wheelSteer  += -lastReceivedData.steering;
                s.mainThrottle = lastReceivedData.throttle;

                var actions = targetVessel.ActionGroups;
                actions.SetIfNot(KSPActionGroup.SAS, lastReceivedData.SAS);
                actions.SetIfNot(KSPActionGroup.RCS, lastReceivedData.RCS);
                actions.SetIfNot(KSPActionGroup.Brakes, lastReceivedData.brake);
                actions.SetIfNot(KSPActionGroup.Light, lastReceivedData.light);
                actions.SetIfNot(KSPActionGroup.Gear, lastReceivedData.gear);
                for (int i = 0; i < lastReceivedData.actions.Length; i++)
                {
                    var group = (KSPActionGroup)(1 << (i + 6));
                    var value = lastReceivedData.actions[i];
                    //actions.ToggleGroup(group);
                    actions.SetIfNot(group, value);
                }
                if (IsFlipped(ref stage_, lastReceivedData.stage))
                {
                    StageManager.ActivateNextStage();
                }

                //CameraManager.Instance.SetCameraIVA();
            }
        }
Beispiel #4
0
            public Future <bool> Next()
            {
                if (!vessel.isActiveVessel || !StageManager.CanSeparate)
                {
                    return(new Future.Success <bool>(false));
                }

                StageManager.ActivateNextStage();
                return(new Future.Success <bool>(true));
            }
Beispiel #5
0
        public IList <Vessel> ActivateNextStage()
        {
            CheckActiveVessel();
            if (!StageManager.CanSeparate)
            {
                throw new YieldException(new ParameterizedContinuation <IList <Vessel> > (ActivateNextStage));
            }
            var preVessels = FlightGlobals.Vessels.ToArray();

            StageManager.ActivateNextStage();
            return(PostActivateStage(preVessels));
        }
Beispiel #6
0
 override public void activateAction()
 {
     base.activateAction();
     if (nextStage)
     {
         StageManager.ActivateNextStage();
     }
     else if (stage < StageManager.StageCount)
     {
         StageManager.ActivateStage(stage);
     }
     this.endAction();
 }
        void Activate(VesselSettings vessel)
        {
            Debug.Log($"[{nameof(AutoAction)}] flight: Activate");

            // Loading facility default settings
            FacilitySettings facility = GetFacilitySettings();

            // Selecting action set
            if (vessel.ActionSet is int set)
            {
                Static.Vessel.SetGroupOverride(FlightGlobals.ActiveVessel, set);
            }

            // Activating standard action groups
            ActionGroupList actionGroups = FlightGlobals.ActiveVessel.ActionGroups;

            actionGroups.SetGroup(KSPActionGroup.SAS, vessel.ActivateSAS ?? facility.ActivateSAS);
            actionGroups.SetGroup(KSPActionGroup.RCS, vessel.ActivateRCS ?? facility.ActivateRCS);
            actionGroups.SetGroup(KSPActionGroup.Brakes, vessel.ActivateBrakes ?? facility.ActivateBrakes);
            actionGroups.SetGroup(KSPActionGroup.Abort, vessel.ActivateAbort ?? facility.ActivateAbort);
            // Special treatment for the groups with the initial state determined by the part state
            SetAutoInitializingGroup(KSPActionGroup.Gear, vessel.ActivateGear);
            SetAutoInitializingGroup(KSPActionGroup.Light, vessel.ActivateLights);

            // Activating custom action groups
            foreach (int customGroup in vessel.CustomGroups.OfType <int>())
            {
                ActivateCustomActionGroup(customGroup);
            }

            // Setting precision control
            SetPrecisionMode(vessel.SetPrecCtrl ?? facility.SetPrecCtrl);

            // Setting throttle
            FlightInputHandler.state.mainThrottle = Mathf.Max(0, Mathf.Min(1, (vessel.SetThrottle ?? facility.SetThrottle) / 100F));

            // Setting trim
            FlightInputHandler.state.pitchTrim         = TrimStep * vessel.SetPitchTrim;
            FlightInputHandler.state.yawTrim           = TrimStep * vessel.SetYawTrim;
            FlightInputHandler.state.rollTrim          = TrimStep * vessel.SetRollTrim;
            FlightInputHandler.state.wheelThrottleTrim = TrimStep * vessel.SetWheelMotorTrim;
            FlightInputHandler.state.wheelSteerTrim    = -TrimStep * vessel.SetWheelSteerTrim;              // inverted

            // Staging
            if (vessel.Stage ?? facility.Stage)
            {
                StageManager.ActivateNextStage();
            }
        }
Beispiel #8
0
 override internal void Click(bool newState, Vessel vessel, RPMVesselComputer comp)
 {
     if (kspAction == KSPActionGroup.Stage)
     {
         if (InputLockManager.IsUnlocked(ControlTypes.STAGING))
         {
             vessel.ActionGroups.ToggleGroup(kspAction);
             StageManager.ActivateNextStage();
         }
     }
     else
     {
         vessel.ActionGroups.ToggleGroup(kspAction);
     }
 }
Beispiel #9
0
 public override void Execute(SharedObjects shared)
 {
     AssertArgBottomAndConsume(shared);
     if (StageManager.CanSeparate && shared.Vessel.isActiveVessel)
     {
         StageManager.ActivateNextStage();
     }
     else if (!StageManager.CanSeparate)
     {
         SafeHouse.Logger.Log("FAIL SILENT: Stage is called before it is ready, Use STAGE:READY to check first if staging rapidly");
     }
     else if (!shared.Vessel.isActiveVessel)
     {
         throw new KOSCommandInvalidHereException(LineCol.Unknown(), "STAGE", "a non-active SHIP, KSP does not support this", "Core is on the active vessel");
     }
 }
Beispiel #10
0
 public void Launch()
 {
     StageController.topFairingDeployed = false;
     if (StageManager.CurrentStage == StageManager.StageCount)
     {
         StageManager.ActivateNextStage();
     }
     InitializeNumbers(getVessel);
     getVessel.OnFlyByWire += new FlightInputCallback(fly);
     Launching              = true;
     PitchSet  = false;
     DebugShow = false;
     program   = AscentProgram.Landed;
     SaveParameters();
     LaunchName = new string(getVessel.vesselName.ToCharArray());
     LaunchBody = getVessel.mainBody;
 }
Beispiel #11
0
        public void OnGUI()
        {
            if (GUI.Button(new Rect(32, 64, 128, 32), "Stage All"))
            {
                foreach (Vessel v in FlightGlobals.Vessels)
                {
                    //v.ActionGroups.ToggleGroup(KSPActionGroup.Stage);
                    v.ResumeStaging();
                    FlightGlobals.SetActiveVessel(v);
                    StageManager.ActivateNextStage();

                    foreach (Part p in v.parts)
                    {
                        if (p.stageOffset == v.currentStage)
                        {
                            List <ModuleEngines> engines;
                            if (p.isEngine(out engines))
                            {
                                foreach (ModuleEngines e in engines)
                                {
                                    e.throttleMin     = 100.0f;
                                    e.currentThrottle = 100.0f;
                                    e.UpdateThrottle();
                                }
                            }
                        }
                    }
                }
            }

            if (GUI.Button(new Rect(32, 96, 128, 32), "Toggle SAS All"))
            {
                foreach (Vessel v in FlightGlobals.Vessels)
                {
                    v.ActionGroups.ToggleGroup(KSPActionGroup.SAS);
                }
            }

            if (GUI.Button(new Rect(32, 128, 128, 32), "Toggle RCS All"))
            {
                foreach (Vessel v in FlightGlobals.Vessels)
                {
                    v.ActionGroups.ToggleGroup(KSPActionGroup.RCS);
                }
            }
        }
 public override void OnFixedUpdate()
 {
     if (timedLaunch)
     {
         if (tMinus < 3 * vesselState.deltaT || (tMinus > 10.0 && lastTMinus < 1.0))
         {
             if (enabled && vesselState.thrustAvailable < 10E-4) // only stage if we have no engines active
             {
                 StageManager.ActivateNextStage();
             }
             timedLaunch = false;
         }
         else
         {
             if (core.node.autowarp)
             {
                 core.warp.WarpToUT(launchTime - warpCountDown);
             }
         }
         lastTMinus = tMinus;
     }
 }
Beispiel #13
0
        public static void fireNextNonEmptyStage(Vessel v)
        {
            // the parts to be fired
            List <Part> resultList = new List <Part>();

            int highestNextStage = getHighestNextStage(v.rootPart, v.currentStage);

            traverseChildren(v.rootPart, highestNextStage, ref resultList);

            foreach (Part stageItem in resultList)
            {
                Log.Info("Activate:" + stageItem);
                stageItem.activate(highestNextStage, stageItem.vessel);
                stageItem.inverseStage = v.currentStage;
            }
            v.currentStage = highestNextStage;
            //If this is the currently active vessel, activate the next, now empty, stage. This is an ugly, ugly hack but it's the only way to clear out the empty stage.
            //Switching to a vessel that has been staged this way already clears out the empty stage, so this isn't required for those.
            if (v.isActiveVessel)
            {
                StageManager.ActivateNextStage();
            }
        }
Beispiel #14
0
 public override void OnFixedUpdate()
 {
     FixupLaunchStart();
     if (timedLaunch)
     {
         if (tMinus < 3 * vesselState.deltaT || (tMinus > 10.0 && lastTMinus < 1.0))
         {
             if (enabled && vesselState.thrustAvailable < 10E-4) // only stage if we have no engines active
             {
                 StageManager.ActivateNextStage();
             }
             ascentPath.timedLaunchHook();  // let ascentPath modules do stuff edge triggered on launch starting
             timedLaunch = false;
         }
         else
         {
             if (core.node.autowarp)
             {
                 core.warp.WarpToUT(launchTime - warpCountDown);
             }
         }
         lastTMinus = tMinus;
     }
 }
Beispiel #15
0
        public void Update()
        {
            if (!vessel.isActiveVessel)
            {
                return;
            }

            GravityTurner.DebugMessage += String.Format("StageController is active {0}, {1}\n", StageManager.CurrentStage, vessel.currentStage);

            //if autostage enabled, and if we are not waiting on the pad, and if there are stages left,
            //and if we are allowed to continue staging, and if we didn't just fire the previous stage
            if (!vessel.LiftedOff() || StageManager.CurrentStage <= 0 || StageManager.CurrentStage <= turner.autostageLimit ||
                Math.Abs(vesselState.time - lastStageTime) < turner.autostagePostDelay)
            {
                return;
            }

            GravityTurner.DebugMessage += "  Lifted off\n";

            //only decouple fairings if the dynamic pressure and altitude conditions are respected
            if (!topFairingDeployed)
            {
                Part fairing = GetTopmostFairing(vessel);
                bool fairingReadyToDeploy = false;
                if (fairing == null)
                {
                    GravityTurner.DebugMessage += "  No top fairing\n";
                }
                else
                {
                    GravityTurner.DebugMessage += "  Has top fairing\n";

                    fairingReadyToDeploy = (vesselState.dynamicPressure <turner.FairingPressure && Math.Abs(vesselState.dynamicPressure - vesselState.maxQ)> 0.1) && ((VesselState.isLoadedFAR && (vesselState.maxQ > vessel.mainBody.GetPressure(0) * 1000 / 5)) || (vesselState.maxQ > vessel.mainBody.atmospherePressureSeaLevel / 2));

                    if (fairingReadyToDeploy)
                    {
                        GravityTurner.DebugMessage += "  Fairing ready to be deployed\n";
                    }
                }

                if (fairing != null && fairing.IsUnfiredDecoupler() && fairingReadyToDeploy)
                {
                    topFairingDeployed = true;
                    fairing.DeployFairing();
                    GravityTurner.Log("Top Fairing deployed.");
                    GravityTurner.Log("  fairing pressure: {0:0.0}", turner.FairingPressure);
                    GravityTurner.Log("  dynamic pressure: {0:0.0}", vesselState.dynamicPressure);
                    GravityTurner.Log("  vessel maxQ: {0:0.0}", vesselState.maxQ);
                    GravityTurner.DebugMessage += "  Deploying top Fairing!!!\n";
                    return;
                }
            }

            //don't decouple active or idle engines or tanks
            List <int> burnedResources = FindBurnedResources();

            if (InverseStageDecouplesActiveOrIdleEngineOrTank(StageManager.CurrentStage - 1, vessel, burnedResources))
            {
                return;
            }

            GravityTurner.DebugMessage += "  active/idle Engine\n";

            //Don't fire a stage that will activate a parachute, unless that parachute gets decoupled:
            if (HasStayingChutes(StageManager.CurrentStage - 1, vessel))
            {
                return;
            }

            GravityTurner.DebugMessage += "  HasStayingChute\n";

            //only fire decouplers to drop deactivated engines or tanks
            bool firesDecoupler = InverseStageFiresDecoupler(StageManager.CurrentStage - 1, vessel);

            if (firesDecoupler && !InverseStageDecouplesDeactivatedEngineOrTank(StageManager.CurrentStage - 1, vessel))
            {
                return;
            }

            GravityTurner.DebugMessage += "  deactivated Engine/Tank\n";

            //When we find that we're allowed to stage, start a countdown (with a
            //length given by autostagePreDelay) and only stage once that countdown finishes,
            if (countingDown)
            {
                GravityTurner.DebugMessage += "  Counting down\n";
                if (Math.Abs(vesselState.time - stageCountdownStart) > turner.autostagePreDelay)
                {
                    GravityTurner.DebugMessage += "    Countdown finished\n";
                    if (firesDecoupler)
                    {
                        //if we decouple things, delay the next stage a bit to avoid exploding the debris
                        lastStageTime = vesselState.time;
                    }
                    GravityTurner.DebugMessage += "    ActivateNextStage\n";
                    GravityTurner.Log("Activate next stage.");
                    StageManager.ActivateNextStage();
                    countingDown = false;
                    GravityTurner.RestoreTimeWarp();
                }
            }
            else
            {
                GravityTurner.DebugMessage += "  Stage Countdown\n";
                GravityTurner.StoreTimeWarp();
                GravityTurner.StopSpeedup();
                stageCountdownStart = vesselState.time;
                countingDown        = true;
            }
        }
        public override void OnUpdate()
        {
            if (!vessel.isActiveVessel)
            {
                return;
            }

            //if autostage enabled, and if we are not waiting on the pad, and if there are stages left,
            //and if we are allowed to continue staging, and if we didn't just fire the previous stage
            if (!vessel.LiftedOff() || StageManager.CurrentStage <= 0 || StageManager.CurrentStage <= autostageLimit ||
                vesselState.time - lastStageTime < autostagePostDelay)
            {
                return;
            }

            //don't decouple active or idle engines or tanks
            List <int> burnedResources = FindBurnedResources();

            if (InverseStageDecouplesActiveOrIdleEngineOrTank(StageManager.CurrentStage - 1, vessel, burnedResources))
            {
                return;
            }

            //Don't fire a stage that will activate a parachute, unless that parachute gets decoupled:
            if (HasStayingChutes(StageManager.CurrentStage - 1, vessel))
            {
                return;
            }

            //only fire decouplers to drop deactivated engines or tanks
            bool firesDecoupler = InverseStageFiresDecoupler(StageManager.CurrentStage - 1, vessel);

            if (firesDecoupler && !InverseStageDecouplesDeactivatedEngineOrTank(StageManager.CurrentStage - 1, vessel))
            {
                return;
            }

            //only decouple fairings if the dynamic pressure and altitude conditions are respected
            if ((core.vesselState.dynamicPressure > fairingMaxDynamicPressure || core.vesselState.altitudeASL < fairingMinAltitude) &&
                HasFairing(StageManager.CurrentStage - 1, vessel))
            {
                return;
            }

            //When we find that we're allowed to stage, start a countdown (with a
            //length given by autostagePreDelay) and only stage once that countdown finishes,
            if (countingDown)
            {
                if (vesselState.time - stageCountdownStart > autostagePreDelay)
                {
                    if (firesDecoupler)
                    {
                        //if we decouple things, delay the next stage a bit to avoid exploding the debris
                        lastStageTime = vesselState.time;
                    }

                    StageManager.ActivateNextStage();
                    countingDown = false;

                    if (autostagingOnce)
                    {
                        users.Clear();
                    }
                }
            }
            else
            {
                countingDown        = true;
                stageCountdownStart = vesselState.time;
            }
        }
Beispiel #17
0
        private void UpdateControls(VesselControls VCOld, VesselControls VC)
        {
            if (VC.RCS != VCOld.RCS)
            {
                AV.ActionGroups.SetGroup(KSPActionGroup.RCS, VC.RCS);
            }
            if (VC.SAS != VCOld.SAS)
            {
                AV.ActionGroups.SetGroup(KSPActionGroup.SAS, VC.SAS);
            }
            if (VC.Lights != VCOld.Lights)
            {
                AV.ActionGroups.SetGroup(KSPActionGroup.Light, VC.Lights);
            }
            if (VC.Gear != VCOld.Gear)
            {
                AV.ActionGroups.SetGroup(KSPActionGroup.Gear, VC.Gear);
            }
            if (VC.Brakes != VCOld.Brakes)
            {
                AV.ActionGroups.SetGroup(KSPActionGroup.Brakes, VC.Brakes);
            }
            if (VC.Abort != VCOld.Abort)
            {
                AV.ActionGroups.SetGroup(KSPActionGroup.Abort, VC.Abort);
            }
            if (VC.Stage != VCOld.Stage)
            {
                if (VC.Stage)
                {
                    StageManager.ActivateNextStage();
                }

                AV.ActionGroups.SetGroup(KSPActionGroup.Stage, VC.Stage);
            }

            //================ control groups

            for (int j = 0; j < 10; j++)
            {
                if (VC.ActionGroups[j] != VCOld.ActionGroups[j])
                {
                    AV.ActionGroups.SetGroup((KSPActionGroup)(1 << (7 + j)), VC.ActionGroups[j]);
                }
            }

            //Set TimeWarp rate
            if (VC.timeWarpRateIndex != VCOld.timeWarpRateIndex)
            {
                byte mode = VC.timeWarpRateIndex;
                if (mode >= 0 && mode <= 10)
                {
                    if (mode > 3)
                    {
                        TimeWarp.fetch.Mode = TimeWarp.Modes.HIGH;
                        TimeWarp.SetRate(mode - 3, false);
                    }
                    else
                    {
                        TimeWarp.fetch.Mode = TimeWarp.Modes.LOW;
                        TimeWarp.SetRate(mode, false);
                    }
                }
            }

            //Set sas mode
            if (VC.SASMode != VCOld.SASMode)
            {
                int setTo = VC.SASMode;
                if (setTo == 11)
                {
                    setTo = 1;
                    AxisInput.holdTargetVector = true;
                }
                else
                {
                    AxisInput.holdTargetVector = false;
                }
                if (setTo != 0 && setTo < 11)
                {
                    SetSASMode(setTo);
                }
            }

            //set navball mode
            if (VC.SpeedMode != VCOld.SpeedMode)
            {
                //  if (!((VC.SpeedMode == 0) || ((VC.SpeedMode == 3) && HasTarget())))
                // {
                FlightGlobals.SetSpeedMode((FlightGlobals.SpeedDisplayModes)(VC.SpeedMode - 1));
                // }
            }

            if (!float.IsNaN(VC.targetHeading) && !float.IsNaN(VC.targetPitch) && !float.IsNaN(VC.targetRoll))
            {
                AxisInput.targetPitch   = VC.targetPitch;
                AxisInput.targetRoll    = VC.targetRoll;
                AxisInput.targetHeading = VC.targetHeading;
            }
        }
        internal override void DrawWindow(Int32 id)
        {
            SetLocalVariables();

            try { GUILayout.BeginVertical(); }
            catch (Exception) { LogFormatted("DrawWindow: GUILayout not ready yet"); return; }

            if (mbARP.lstResourcesToDisplay.Count == 0)
            {
                GUILayout.Label("No current resources configured to display");
            }
            else
            {
                Int32 ResourceID;
                Rect  rectBar;
                for (int i = 0; i < mbARP.lstResourcesToDisplay.Count; i++)
                {
                    ResourceID = mbARP.lstResourcesToDisplay[i];
                    //Is it a separator - draw and skip?
                    if (ResourceID == 0)
                    {
                        GUILayout.Space(3 + settings.SpacerPadding);
                        GUILayout.Label("", Styles.styleSeparatorH, GUILayout.Width(WindowRect.width - 15), GUILayout.Height(2));
                        GUILayout.Space(settings.SpacerPadding);
                        continue;
                    }

                    //add space at top of window
                    if (i > 0)
                    {
                        GUILayout.Space(4);
                    }

                    GUILayout.BeginHorizontal();

                    //add title
                    Rect rectIcon = Drawing.DrawResourceIcon(lstResources[ResourceID].ResourceDef.name);

                    //If the global alarms setting is on
                    if (settings.AlarmsEnabled)
                    {
                        GUILayout.Space(1);
                        //work out the alarm ico to display
                        GUIContent contAlarm = new GUIContent(Resources.btnAlarm);
                        if (settings.Resources[ResourceID].AlarmEnabled)
                        {
                            contAlarm.image = Resources.btnAlarmEnabled;
                            switch (lstResources[ResourceID].MonitorState)
                            {
                            case ARPResource.MonitorStateEnum.Alert:
                                if (lstResources[ResourceID].AlarmState != ARPResource.AlarmStateEnum.Unacknowledged || DateTime.Now.Millisecond < 500)
                                {
                                    contAlarm.image = Resources.btnAlarmAlert;
                                }
                                break;

                            case ARPResource.MonitorStateEnum.Warn:
                                if (lstResources[ResourceID].AlarmState != ARPResource.AlarmStateEnum.Unacknowledged || DateTime.Now.Millisecond < 500)
                                {
                                    contAlarm.image = Resources.btnAlarmWarn;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        //Draw the button - if the alarm is unacknowledged then acknowledge, else toggle alarm status
                        if (GUILayout.Button(contAlarm, Styles.styleAlarmButton))
                        {
                            if (lstResources[ResourceID].AlarmState == ARPResource.AlarmStateEnum.Unacknowledged)
                            {
                                lstResources[ResourceID].SetAlarmAcknowledged();
                            }
                            else
                            {
                                settings.Resources[ResourceID].AlarmEnabled = !settings.Resources[ResourceID].AlarmEnabled;
                            }
                        }
                    }
                    //Is this resource selected
                    Boolean Highlight = SelectedResources.ContainsKey(ResourceID) && SelectedResources[ResourceID].AllVisible;

                    //For resources with no stage specifics - or the Resources is set to split display and values are different for all vessel and flow enabled ones
                    if (!settings.SplitLastStage || !lstResources[ResourceID].ResourceConfig.SplitLastStage || settings.ShowBase ||
                        (lstResources[ResourceID].ResourceDef.resourceFlowMode == ResourceFlowMode.ALL_VESSEL ||
                         lstResources[ResourceID].ResourceDef.resourceFlowMode == ResourceFlowMode.STAGE_PRIORITY_FLOW) &&
                        ((!settings.Resources[ResourceID].ShowReserveLevels) ||
                         (!lstResourcesLastStage.ContainsKey(ResourceID)))
                        )
                    {
                        //full width bar
                        rectBar = Drawing.CalcBarRect(rectIcon, Icon2BarOffset_Left, 275, 15);  //was 245
                        if (Drawing.DrawResourceBar(rectBar, lstResources[ResourceID], Styles.styleBarGreen_Back, Styles.styleBarGreen, Styles.styleBarGreen_Thin, settings.ShowRates, Highlight, Styles.styleBarHighlight))
                        {
                            //MonoBehaviourExtended.LogFormatted_DebugOnly("Clicked");
                            SelectedResources.TogglePartResourceVisible(ResourceID);
                        }
                    }
                    else
                    {
                        Int32 FullVesselBarOffset = settings.StageBarOnRight ? Icon2BarOffset_Left : Icon2BarOffset_Right;
                        Int32 StageBarOffset      = settings.StageBarOnRight ? Icon2BarOffset_Right : Icon2BarOffset_Left;

                        //need full Vessel and current stage bars
                        rectBar = Drawing.CalcBarRect(rectIcon, FullVesselBarOffset, 135, 15);  //was 120
                        if (Drawing.DrawResourceBar(rectBar, lstResources[ResourceID], Styles.styleBarGreen_Back, Styles.styleBarGreen, Styles.styleBarGreen_Thin, settings.ShowRates, Highlight, Styles.styleBarHighlight))
                        {
                            SelectedResources.TogglePartResourceVisible(ResourceID);
                        }

                        //get last stage of this resource and set it
                        if (lstResourcesLastStage.ContainsKey(ResourceID))
                        {
                            Highlight = SelectedResources.ContainsKey(ResourceID) && SelectedResources[ResourceID].LastStageVisible;
                            rectBar   = Drawing.CalcBarRect(rectIcon, StageBarOffset, 135, 15); //was 120
                            if (Drawing.DrawResourceBar(rectBar, lstResourcesLastStage[ResourceID], Styles.styleBarBlue_Back, Styles.styleBarBlue, Styles.styleBarBlue_Thin, settings.ShowRates, Highlight, Styles.styleBarHighlight))
                            {
                                SelectedResources.TogglePartResourceVisible(ResourceID, true);
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            GUILayout.BeginHorizontal();
            ////STAGING STUFF
            if (settings.StagingEnabled)
            {
                ////Keyboard Stage Lock
                //GUIContent contLock = new GUIContent(Resources.btnUnlock, "Keyboard Staging Unlocked\r\nClick to toggle");
                //if (FlightInputHandler.fetch.stageLock)
                //    contLock = new GUIContent(Resources.btnLock, "Keyboard Staging Locked\r\nClick to toggle");
                //if (GUILayout.Button(contLock, Styles.styleAlarmButton))
                //    FlightInputHandler.fetch.stageLock = !FlightInputHandler.fetch.stageLock;

                if (!settings.AutoStagingEnabled)
                {
                    //GUILayout.Label("Stage:", Styles.styleStageTextHead, GUILayout.Width(50));
                    if (GUILayout.Button("Stage:", Styles.styleStageTextHead, GUILayout.Width(50)))
                    {
                        settings.AutoStagingEnabled = !settings.AutoStagingEnabled;
                    }
                    GUIStyle   styleStageNum = new GUIStyle(Styles.styleStageTextHead);
                    GUIContent contStageNum  = new GUIContent(StageManager.CurrentStage.ToString());
                    //styleStageNum.normal.textColor=new Color(173,43,43);
                    //GUIContent contStageNum = new GUIContent(StageManager.CurrentStage.ToString(),"NO Active Engines");
                    //if (THERE ARE ACTIVE ENGINES IN STAGE)
                    //{
                    //contStageNum.tooltip="Active Engines";
                    styleStageNum.normal.textColor = new Color(117, 206, 60);
                    //}

                    GUILayout.Label(contStageNum, styleStageNum, GUILayout.Width(20));

                    if (settings.StagingEnabledInMapView || !MapView.MapIsEnabled)
                    {
                        if (mbARP.blnVesselIsControllable)
                        {
                            if (GUILayout.Button("Activate Stage", "ButtonGeneral", GUILayout.Width(100)))
                            {
                                StageManager.ActivateNextStage();
                            }
                            GUILayout.Space(21 + IconAlarmOffset);
                            //GUILayout.Space(51 + IconAlarmOffset);
                        }
                        else
                        {
                            GUILayout.Label("No Vessel Control", GUILayout.Width(120));
                            GUILayout.Space(1 + IconAlarmOffset);
                            //GUILayout.Space(31 + IconAlarmOffset);
                        }
                    }
                    //GUILayout.Space(48 + IconAlarmOffset);
                    //GUILayout.Space(21 + IconAlarmOffset);
                }
                else
                {
                    if (GUILayout.Button("Auto:", Styles.styleStageTextHead, GUILayout.Width(50)))
                    {
                        settings.AutoStagingEnabled = !settings.AutoStagingEnabled;
                    }
                    GUILayout.Label(StageManager.CurrentStage.ToString(), Styles.styleStageTextHead, GUILayout.Width(20));
                    GUILayout.Label("to", Styles.styleStageTextHead, GUILayout.Width(30));
                    GUILayout.Label(mbARP.AutoStagingTerminateAt.ToString(), Styles.styleStageTextHead, GUILayout.Width(30));
                    DrawHorizontalSlider(ref mbARP.AutoStagingTerminateAt, 0, mbARP.AutoStagingMaxStage);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();

                    String   strButtonArm = "Arm";
                    GUIStyle styleArm     = new GUIStyle(SkinsLibrary.CurrentSkin.button)
                    {
                        fontStyle = FontStyle.Bold
                    };
                    if (mbARP.AutoStagingArmed)
                    {
                        strButtonArm = "Disarm";
                        styleArm.normal.textColor = styleArm.hover.textColor = new Color32(207, 31, 31, 255);
                    }
                    else
                    {
                        styleArm.normal.textColor = styleArm.hover.textColor = new Color32(183, 254, 0, 255);
                    }

                    if (GUILayout.Button(strButtonArm, styleArm, GUILayout.Width(75)))
                    {
                        mbARP.AutoStagingArmed = !mbARP.AutoStagingArmed;
                    }

                    GUIStyle StatusStyle = new GUIStyle(SkinsLibrary.CurrentSkin.label);
                    StatusStyle.normal.textColor = mbARP.AutoStagingStatusColor;
                    //GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(147 + IconAlarmOffset));
                    GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(120 + IconAlarmOffset));
                    //GUILayout.Label(mbARP.AutoStagingStatus, StatusStyle, GUILayout.Width(150 + IconAlarmOffset));
                }
            }
            else
            {
                //GUILayout.Space(234 + IconAlarmOffset);
                GUILayout.Space(207 + IconAlarmOffset);
                //GUILayout.Space(237 + IconAlarmOffset);
            }

            // ShowBase Button
            Boolean blnShowBase = settings.ShowBase;

            if (DrawToggle(ref blnShowBase, new GUIContent(Resources.btnViewBaseActive, blnShowBase ? "Back to Vessel Display" : "Show Base Display\r\nAll resource within 2km of active vessel"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin, "ButtonToggle").PaddingChange(1), GUILayout.Width(23)))
            {
                settings.ShowBase = blnShowBase;
            }
            //if (GUILayout.Button(new GUIContent(settings.ShowBase ? Resources.btnViewBaseActive : Resources.btnViewBase, "Toggle Vessel/Base Display"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
            //{
            //    settings.ShowBase = !settings.ShowBase;
            //}

            // ShowTime Button
            Boolean blnShowTimeRem = settings.ShowTimeRem;

            if (DrawToggle(ref blnShowTimeRem, new GUIContent(Resources.btnViewTimes, blnShowTimeRem ? "Hide time Remianing": "Show Time Remaining"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin, "ButtonToggle").PaddingChange(1), GUILayout.Width(23)))
            {
                settings.ShowTimeRem = blnShowTimeRem;
            }
            //if (GUILayout.Button(new GUIContent(Resources.btnViewTimes, "Toggle Time Remaining"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
            //{
            //    settings.ShowTimeRem = !settings.ShowTimeRem;
            //}

            // ShowAll Button
            Boolean blnToggleHidden = KSPAlternateResourcePanel.ShowAll;

            if (DrawToggle(ref blnToggleHidden, new GUIContent(Resources.btnViewAll, "Toggle Hidden Resources"), SkinsLibrary.GetStyle(SkinsLibrary.CurrentSkin, "ButtonToggle").PaddingChange(1), GUILayout.Width(23)))
            {
                KSPAlternateResourcePanel.ShowAll = blnToggleHidden;
            }
            //if (GUILayout.Button(new GUIContent(Resources.btnViewAll, "Toggle Hidden Resources"), SkinsLibrary.CurrentSkin.button.PaddingChange(1), GUILayout.Width(23)))
            //{
            //    KSPAlternateResourcePanel.ShowAll = !KSPAlternateResourcePanel.ShowAll;
            //}

            //Settings Toggle button
            GUIContent btnMinMax = new GUIContent(Resources.btnChevronDown, "Show Settings...");

            if (windowSettings.Visible)
            {
                btnMinMax.image = Resources.btnChevronUp; btnMinMax.tooltip = "Hide Settings";
            }
            else if (settings.VersionAttentionFlag && DateTime.Now.Millisecond < 500)
            {
                btnMinMax.image = Resources.btnSettingsAttention;
            }

            if (settings.VersionAttentionFlag)
            {
                btnMinMax.tooltip = "Updated Version Available - " + btnMinMax.tooltip;
            }

            if (GUILayout.Button(btnMinMax, "ButtonSettings", GUILayout.Width(23)))
            {
                windowSettings.Visible = !windowSettings.Visible;
                if (windowSettings.Visible && settings.VersionAttentionFlag)
                {
                    windowSettings.ddlSettingsTab.SelectedIndex = (Int32)ARPWindowSettings.SettingsTabs.About;
                    settings.VersionAttentionFlag = false;
                }
                settings.Save();
            }

            GUILayout.EndHorizontal();

            //End window layout
            GUILayout.EndVertical();

            //If settings window is visible then position it accordingly
            if (mbARP.windowSettings.Visible)
            {
                mbARP.windowSettings.UpdateWindowRect();
            }
        }
        public override void OnUpdate()
        {
            if (!vessel.isActiveVessel)
            {
                return;
            }

            //if autostage enabled, and if we've already staged at least once, and if there are stages left,
            //and if we are allowed to continue staging, and if we didn't just fire the previous stage
            if (waitingForFirstStaging || StageManager.CurrentStage <= 0 || StageManager.CurrentStage <= autostageLimit ||
                vesselState.time - lastStageTime < autostagePostDelay)
            {
                return;
            }

            //don't decouple active or idle engines or tanks
            UpdateActiveModuleEngines();
            UpdateBurnedResources();
            if (InverseStageDecouplesActiveOrIdleEngineOrTank(StageManager.CurrentStage - 1, vessel, burnedResources, activeModuleEngines))
            {
                return;
            }

            //Don't fire a stage that will activate a parachute, unless that parachute gets decoupled:
            if (HasStayingChutes(StageManager.CurrentStage - 1, vessel))
            {
                return;
            }

            //Always drop deactivated engines or tanks
            if (!InverseStageDecouplesDeactivatedEngineOrTank(StageManager.CurrentStage - 1, vessel))
            {
                //only decouple fairings if the dynamic pressure, altitude, and aerothermal flux conditions are respected
                if ((core.vesselState.dynamicPressure > fairingMaxDynamicPressure || core.vesselState.altitudeASL < fairingMinAltitude || core.vesselState.freeMolecularAerothermalFlux > fairingMaxAerothermalFlux) &&
                    HasFairing(StageManager.CurrentStage - 1, vessel))
                {
                    return;
                }

                //only release launch clamps if we're at nearly full thrust
                if (vesselState.thrustCurrent / vesselState.thrustAvailable < clampAutoStageThrustPct &&
                    InverseStageReleasesClamps(StageManager.CurrentStage - 1, vessel))
                {
                    return;
                }
            }

            //When we find that we're allowed to stage, start a countdown (with a
            //length given by autostagePreDelay) and only stage once that countdown finishes,
            if (countingDown)
            {
                if (vesselState.time - stageCountdownStart > autostagePreDelay)
                {
                    if (InverseStageFiresDecoupler(StageManager.CurrentStage - 1, vessel))
                    {
                        //if we decouple things, delay the next stage a bit to avoid exploding the debris
                        lastStageTime = vesselState.time;
                    }

                    StageManager.ActivateNextStage();
                    countingDown = false;

                    if (autostagingOnce)
                    {
                        users.Clear();
                    }
                }
            }
            else
            {
                countingDown        = true;
                stageCountdownStart = vesselState.time;
            }
        }
Beispiel #20
0
        public void Click()
        {
            RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
            bool switchEnabled     = true;

            if (!forcedShutdown)
            {
                if (perPodMasterSwitchValid)
                {
                    switchEnabled = comp.GetPersistentVariable(perPodMasterSwitchName, false);
                }
                if (masterVariable != null)
                {
                    switchEnabled = masterVariable.IsInRange(comp);
                }
            }
            if (!switchEnabled)
            {
                // If the master switch is 'off' and we're not here because
                // of a forced shutdown, don't allow this switch to work.
                // early return
                return;
            }

            if (isCustomAction)
            {
                if (switchGroupIdentifier >= 0)
                {
                    if (!forcedShutdown && !customGroupState)
                    {
                        customGroupState = true;
                        if (persistentVarValid)
                        {
                            comp.SetPersistentVariable(persistentVarName, switchGroupIdentifier);
                        }
                    }
                    // else: can't turn off a radio group switch.
                }
                else if (customAction == CustomActions.Plugin && stateVariableValid)
                {
                    int ivalue = comp.ProcessVariable(stateVariable).MassageToInt();
                    customGroupState = (ivalue < 1) && !forcedShutdown;
                }
                else
                {
                    customGroupState = !customGroupState;
                    if (persistentVarValid)
                    {
                        comp.SetPersistentVariable(persistentVarName, customGroupState);
                    }
                }
            }
            else
            {
                vessel.ActionGroups.ToggleGroup(kspAction);
            }

            // Now we do extra things that with regular actions can't happen.
            switch (customAction)
            {
            case CustomActions.IntLight:
                SetInternalLights(customGroupState);
                break;

            case CustomActions.Plugin:
                actionHandler(customGroupState);
                break;

            case CustomActions.Stage:
                if (InputLockManager.IsUnlocked(ControlTypes.STAGING))
                {
                    StageManager.ActivateNextStage();
                }
                break;

            case CustomActions.TransferToPersistent:
                if (stateVariableValid)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = comp.ProcessVariable(stateVariable).MassageToInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                float getValue = comp.ProcessVariable(transferGetter).MassageToFloat();
                comp.SetPersistentVariable(transferPersistentName, getValue);
                break;

            case CustomActions.TransferFromPersistent:
                if (stateVariableValid)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = comp.ProcessVariable(stateVariable).MassageToInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                if (comp.HasPersistentVariable(transferPersistentName))
                {
                    transferSetter(comp.GetPersistentVariable(transferPersistentName, 0.0).MassageToDouble());
                }
                break;

            case CustomActions.TransferFromVariable:
                if (stateVariableValid)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = comp.ProcessVariable(stateVariable).MassageToInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                double xferValue = comp.ProcessVariable(transferGetter).MassageToDouble();
                transferSetter(xferValue);
                break;

            case CustomActions.Transfer:
                JUtil.LogInfo(this, "The deprecated CustomActions.Transfer path was executed");

                /*if (stateVariableValid)
                 * {
                 *  // stateVariable can disable the button functionality.
                 *  int ivalue = comp.ProcessVariable(stateVariable).MassageToInt();
                 *  if (ivalue < 1)
                 *  {
                 *      return; // early - button disabled
                 *  }
                 * }
                 * if (!string.IsNullOrEmpty(transferGetter))
                 * {
                 *  float value = comp.ProcessVariable(transferGetter).MassageToFloat();
                 *  comp.SetPersistentVariable(transferPersistentName, value);
                 * }
                 * else if (comp.HasPersistentVariable(transferPersistentName))
                 * {
                 *  transferSetter(comp.GetPersistentVariable(transferPersistentName, 0.0).MassageToDouble());
                 * }*/
                break;
            }
        }
Beispiel #21
0
 private StateFn Decouple2()
 {
     StageManager.ActivateNextStage();
     return(WarpToAtm);
 }
Beispiel #22
0
 private StateFn Decouple()
 {
     StageManager.ActivateNextStage();
     return(Sun);
 }
Beispiel #23
0
 private StateFn ReentryBurn()
 {
     StageManager.ActivateNextStage();
     return(WaitReentryBurn);
 }
Beispiel #24
0
        public void Click()
        {
            bool switchEnabled = true;

            if (!forcedShutdown)
            {
                if (perPodMasterSwitchValid)
                {
                    switchEnabled = rpmComp.GetPersistentVariable(perPodMasterSwitchName, false, false);
                }
                if (masterVariable != null)
                {
                    switchEnabled = masterVariable.IsInRange();
                }
            }
            if (!switchEnabled)
            {
                // If the master switch is 'off' and we're not here because
                // of a forced shutdown, don't allow this switch to work.
                // early return
                return;
            }

            if (isCustomAction)
            {
                if (switchGroupIdentifier >= 0)
                {
                    if (!forcedShutdown && !customGroupState)
                    {
                        customGroupState = true;
                        if (persistentVarValid)
                        {
                            rpmComp.SetPersistentVariable(persistentVarName, switchGroupIdentifier, perPodPersistenceIsGlobal);
                        }
                    }
                    // else: can't turn off a radio group switch.
                }
                else if (customAction == CustomActions.Plugin && stateVariable != null)
                {
                    int ivalue = stateVariable.AsInt();
                    customGroupState = (ivalue < 1) && !forcedShutdown;
                }
                else
                {
                    customGroupState = !customGroupState;
                    if (persistentVarValid)
                    {
                        rpmComp.SetPersistentVariable(persistentVarName, customGroupState, perPodPersistenceIsGlobal);
                    }
                }
            }
            else
            {
                vessel.ActionGroups.ToggleGroup(kspAction);
            }

            // Now we do extra things that with regular actions can't happen.
            switch (customAction)
            {
            case CustomActions.IntLight:
                SetInternalLights(customGroupState);
                break;

            case CustomActions.Plugin:
                actionHandler(customGroupState);
                break;

            case CustomActions.Stage:
                if (InputLockManager.IsUnlocked(ControlTypes.STAGING))
                {
                    StageManager.ActivateNextStage();
                }
                break;

            case CustomActions.TransferToPersistent:
                if (stateVariable != null)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = stateVariable.AsInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                float getValue = transferGetter.AsFloat();
                rpmComp.SetPersistentVariable(transferPersistentName, getValue, false);
                break;

            case CustomActions.TransferFromPersistent:
                if (stateVariable != null)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = stateVariable.AsInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                if (rpmComp.HasPersistentVariable(transferPersistentName, false))
                {
                    transferSetter(rpmComp.GetPersistentVariable(transferPersistentName, 0.0, false).MassageToDouble());
                }
                break;

            case CustomActions.TransferFromVariable:
                if (stateVariable != null)
                {
                    // stateVariable can disable the button functionality.
                    int ivalue = stateVariable.AsInt();
                    if (ivalue < 1)
                    {
                        return;     // early - button disabled
                    }
                }
                double xferValue = transferGetter.AsDouble();
                transferSetter(xferValue);
                break;
            }
        }
Beispiel #25
0
 public static void ActivateStage()
 {
     StageManager.ActivateNextStage();
 }
        public override void OnUpdate()
        {
            //Commenting this because now we support autostaging on non active vessels
            //if (!vessel.isActiveVessel)
            //    return;

            //if autostage enabled, and if we've already staged at least once, and if there are stages left,
            //and if we are allowed to continue staging, and if we didn't just fire the previous stage
            if (waitingForFirstStaging || vessel.currentStage <= 0 || vessel.currentStage <= autostageLimit || vessel.currentStage <= autostageLimitInternal ||
                vesselState.time - lastStageTime < autostagePostDelay)
            {
                return;
            }

            //don't decouple active or idle engines or tanks
            UpdateActiveModuleEngines();
            UpdateBurnedResources();
            if (InverseStageDecouplesActiveOrIdleEngineOrTank(vessel.currentStage - 1, vessel, burnedResources, activeModuleEngines))
            {
                return;
            }

            // prevent staging when the current stage has active engines and the next stage has any engines (but not decouplers or clamps)
            if (hotStaging && InverseStageHasActiveEngines(vessel.currentStage, vessel) && InverseStageHasEngines(vessel.currentStage - 1, vessel) && !InverseStageFiresDecoupler(vessel.currentStage - 1, vessel) && !InverseStageReleasesClamps(vessel.currentStage - 1, vessel) && LastNonZeroDVStageBurnTime() > hotStagingLeadTime)
            {
                return;
            }

            //Don't fire a stage that will activate a parachute, unless that parachute gets decoupled:
            if (HasStayingChutes(vessel.currentStage - 1, vessel))
            {
                return;
            }

            //Always drop deactivated engines or tanks
            if (!InverseStageDecouplesDeactivatedEngineOrTank(vessel.currentStage - 1, vessel))
            {
                //only decouple fairings if the dynamic pressure, altitude, and aerothermal flux conditions are respected
                if ((core.vesselState.dynamicPressure > fairingMaxDynamicPressure || core.vesselState.altitudeASL < fairingMinAltitude || core.vesselState.freeMolecularAerothermalFlux > fairingMaxAerothermalFlux) &&
                    HasFairing(vessel.currentStage - 1, vessel))
                {
                    return;
                }

                //only release launch clamps if we're at nearly full thrust
                if (vesselState.thrustCurrent / vesselState.thrustAvailable < clampAutoStageThrustPct &&
                    InverseStageReleasesClamps(vessel.currentStage - 1, vessel))
                {
                    return;
                }
            }

            //When we find that we're allowed to stage, start a countdown (with a
            //length given by autostagePreDelay) and only stage once that countdown finishes,
            if (countingDown)
            {
                if (vesselState.time - stageCountdownStart > autostagePreDelay)
                {
                    if (InverseStageFiresDecoupler(vessel.currentStage - 1, vessel))
                    {
                        //if we decouple things, delay the next stage a bit to avoid exploding the debris
                        lastStageTime = vesselState.time;
                    }

                    if (!this.vessel.isActiveVessel)
                    {
                        this.currentActiveVessel = FlightGlobals.ActiveVessel;
                        Debug.Log($"Mechjeb Autostage: Switching from {FlightGlobals.ActiveVessel.name} to vessel {this.vessel.name} to stage");

                        this.remoteStagingStatus = RemoteStagingState.WaitingFocus;
                        FlightGlobals.ForceSetActiveVessel(this.vessel);
                    }
                    else
                    {
                        Debug.Log($"Mechjeb Autostage: Executing next stage on {FlightGlobals.ActiveVessel.name}");

                        if (remoteStagingStatus == RemoteStagingState.Disabled)
                        {
                            StageManager.ActivateNextStage();
                        }
                        else if (remoteStagingStatus == RemoteStagingState.FocusFinished)
                        {
                            StageManager.ActivateNextStage();
                            FlightGlobals.ForceSetActiveVessel(currentActiveVessel);
                            Debug.Log($"Mechjeb Autostage: Has switching back to {FlightGlobals.ActiveVessel.name} ");
                            this.remoteStagingStatus = RemoteStagingState.Disabled;
                        }
                    }
                    countingDown = false;

                    if (autostagingOnce)
                    {
                        users.Clear();
                    }
                }
            }
            else
            {
                countingDown        = true;
                stageCountdownStart = vesselState.time;
            }
        }
Beispiel #27
0
        /// <summary>
        /// Send new control data to the active vessel.
        /// Checks the vesselSync value to prevent using old ControlPackets after vessel change.
        /// </summary>
        /// <param name="CPacket">Control data</param>
        /// <param name="sync">Current VesselData sync value</param>
        public void ControlsReceived(ControlPacket CPacket, byte sync)
        {
            if (CPacket.vesselSync == sync)
            {
                //Detect vessel change
                _vControls.vesselSync = CPacket.vesselSync;
                bool vesselChanged = _vControls.vesselSync != _vControlsOld.vesselSync;
                _vControlsOld.vesselSync = _vControls.vesselSync;


                _vControls.SAS           = BitMathByte(CPacket.MainControls, 7);
                _vControls.RCS           = BitMathByte(CPacket.MainControls, 6);
                _vControls.Lights        = BitMathByte(CPacket.MainControls, 5);
                _vControls.Gear          = BitMathByte(CPacket.MainControls, 4);
                _vControls.Brakes        = BitMathByte(CPacket.MainControls, 3);
                _vControls.Precision     = BitMathByte(CPacket.MainControls, 2);
                _vControls.Abort         = BitMathByte(CPacket.MainControls, 1);
                _vControls.Stage         = BitMathByte(CPacket.MainControls, 0);
                _vControls.Pitch         = (float)CPacket.Pitch / 1000.0F;
                _vControls.Roll          = (float)CPacket.Roll / 1000.0F;
                _vControls.Yaw           = (float)CPacket.Yaw / 1000.0F;
                _vControls.TX            = (float)CPacket.TX / 1000.0F;
                _vControls.TY            = (float)CPacket.TY / 1000.0F;
                _vControls.TZ            = (float)CPacket.TZ / 1000.0F;
                _vControls.WheelSteer    = (float)CPacket.WheelSteer / 1000.0F;
                _vControls.Throttle      = (float)CPacket.Throttle / 1000.0F;
                _vControls.WheelThrottle = (float)CPacket.WheelThrottle / 1000.0F;
                _vControls.SASMode       = (int)CPacket.NavballSASMode & 0x0F;
                _vControls.SpeedMode     = (int)(CPacket.NavballSASMode >> 4);
                _vControls.UiMode        = (int)CPacket.Mode & 0x0F;
                _vControls.CameraMode    = (int)(CPacket.Mode >> 4);
                _vControls.OpenMenu      = BitMathByte(CPacket.AdditionalControlByte1, 0);
                _vControls.OpenMap       = BitMathByte(CPacket.AdditionalControlByte1, 1);

                for (int j = 1; j <= 10; j++)
                {
                    _vControls.ControlGroup[j] = BitMathUshort(CPacket.ControlGroup, j);
                }


                //if (FlightInputHandler.RCSLock != VControls.RCS)
                if (_vControls.RCS != _vControlsOld.RCS || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.RCS, _vControls.RCS);
                    _vControlsOld.RCS = _vControls.RCS;
                    //ScreenMessages.PostScreenMessage("RCS: " + VControls.RCS.ToString(), 10f, KSPIOScreenStyle);
                }

                //if (ActiveVessel.ctrlState.killRot != VControls.SAS)
                if (_vControls.SAS != _vControlsOld.SAS || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, _vControls.SAS);
                    _vControlsOld.SAS = _vControls.SAS;
                    //ScreenMessages.PostScreenMessage("SAS: " + VControls.SAS.ToString(), 10f, KSPIOScreenStyle);
                }

                if (_vControls.Lights != _vControlsOld.Lights || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Light, _vControls.Lights);
                    _vControlsOld.Lights = _vControls.Lights;
                }

                if (_vControls.Gear != _vControlsOld.Gear || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Gear, _vControls.Gear);
                    _vControlsOld.Gear = _vControls.Gear;
                }

                if (_vControls.Brakes != _vControlsOld.Brakes || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, _vControls.Brakes);
                    _vControlsOld.Brakes = _vControls.Brakes;
                }

                if (_vControls.Abort != _vControlsOld.Abort || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Abort, _vControls.Abort);
                    _vControlsOld.Abort = _vControls.Abort;
                }

                if (_vControls.Stage != _vControlsOld.Stage || vesselChanged)
                {
                    if (_vControls.Stage)
                    {
                        StageManager.ActivateNextStage();
                    }

                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Stage, _vControls.Stage);
                    _vControlsOld.Stage = _vControls.Stage;
                }

                //================ control groups

                if (_vControls.ControlGroup[1] != _vControlsOld.ControlGroup[1] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom01, _vControls.ControlGroup[1]);
                    _vControlsOld.ControlGroup[1] = _vControls.ControlGroup[1];
                }

                if (_vControls.ControlGroup[2] != _vControlsOld.ControlGroup[2] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom02, _vControls.ControlGroup[2]);
                    _vControlsOld.ControlGroup[2] = _vControls.ControlGroup[2];
                }

                if (_vControls.ControlGroup[3] != _vControlsOld.ControlGroup[3] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom03, _vControls.ControlGroup[3]);
                    _vControlsOld.ControlGroup[3] = _vControls.ControlGroup[3];
                }

                if (_vControls.ControlGroup[4] != _vControlsOld.ControlGroup[4] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom04, _vControls.ControlGroup[4]);
                    _vControlsOld.ControlGroup[4] = _vControls.ControlGroup[4];
                }

                if (_vControls.ControlGroup[5] != _vControlsOld.ControlGroup[5] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom05, _vControls.ControlGroup[5]);
                    _vControlsOld.ControlGroup[5] = _vControls.ControlGroup[5];
                }

                if (_vControls.ControlGroup[6] != _vControlsOld.ControlGroup[6] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom06, _vControls.ControlGroup[6]);
                    _vControlsOld.ControlGroup[6] = _vControls.ControlGroup[6];
                }

                if (_vControls.ControlGroup[7] != _vControlsOld.ControlGroup[7] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom07, _vControls.ControlGroup[7]);
                    _vControlsOld.ControlGroup[7] = _vControls.ControlGroup[7];
                }

                if (_vControls.ControlGroup[8] != _vControlsOld.ControlGroup[8] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom08, _vControls.ControlGroup[8]);
                    _vControlsOld.ControlGroup[8] = _vControls.ControlGroup[8];
                }

                if (_vControls.ControlGroup[9] != _vControlsOld.ControlGroup[9] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom09, _vControls.ControlGroup[9]);
                    _vControlsOld.ControlGroup[9] = _vControls.ControlGroup[9];
                }

                if (_vControls.ControlGroup[10] != _vControlsOld.ControlGroup[10] || vesselChanged)
                {
                    _activeVessel.ActionGroups.SetGroup(KSPActionGroup.Custom10, _vControls.ControlGroup[10]);
                    _vControlsOld.ControlGroup[10] = _vControls.ControlGroup[10];
                }

                //Set sas mode
                if (_vControls.SASMode != _vControlsOld.SASMode || vesselChanged)
                {
                    if (_vControls.SASMode != 0 && _vControls.SASMode < 11)
                    {
                        if (!_activeVessel.Autopilot.CanSetMode((VesselAutopilot.AutopilotMode)(_vControls.SASMode - 1)))
                        {
                            ScreenMessages.PostScreenMessage("[KSPEthernetIO]: SAS mode " + _vControls.SASMode.ToString() + " not avalible");
                        }
                        else
                        {
                            _activeVessel.Autopilot.SetMode((VesselAutopilot.AutopilotMode)_vControls.SASMode - 1);
                        }
                    }
                    _vControlsOld.SASMode = _vControls.SASMode;
                }

                //set navball mode
                if (_vControls.SpeedMode != _vControlsOld.SpeedMode || vesselChanged)
                {
                    if (!((_vControls.SpeedMode == 0) || ((_vControls.SpeedMode == 3) && !TargetExists())))
                    {
                        FlightGlobals.SetSpeedMode((FlightGlobals.SpeedDisplayModes)(_vControls.SpeedMode - 1));
                    }
                    _vControlsOld.SpeedMode = _vControls.SpeedMode;
                }


                if (Math.Abs(_vControls.Pitch) > Settings.SASTol ||
                    Math.Abs(_vControls.Roll) > Settings.SASTol ||
                    Math.Abs(_vControls.Yaw) > Settings.SASTol)
                {
                    if ((_activeVessel.ActionGroups[KSPActionGroup.SAS]) && (_wasSASOn == false))
                    {
                        _wasSASOn = true;
                        _activeVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false);
                    }
                }
                else
                {
                    if (_wasSASOn == true)
                    {
                        _wasSASOn = false;
                        _activeVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);
                    }
                }

                if (_vControlsOld.UiMode != _vControls.UiMode || vesselChanged)
                {
                    if (FlightUIModeController.Instance != null)
                    {
                        switch (_vControls.UiMode)
                        {
                        case 0:
                            FlightUIModeController.Instance.SetMode(FlightUIMode.STAGING);
                            break;

                        case 1:
                            FlightUIModeController.Instance.SetMode(FlightUIMode.DOCKING);
                            break;

                        case 2:
                            FlightUIModeController.Instance.SetMode(FlightUIMode.MAPMODE);
                            break;

                        default:
                            break;
                        }
                        _vControlsOld.UiMode = _vControls.UiMode;
                    }
                }

                if (_vControlsOld.CameraMode != _vControls.CameraMode || vesselChanged)
                {
                    if (FlightCamera.fetch != null)
                    {
                        switch (_vControls.CameraMode)
                        {
                        case 0:
                            FlightCamera.fetch.setMode(FlightCamera.Modes.AUTO);
                            break;

                        case 1:
                            FlightCamera.fetch.setMode(FlightCamera.Modes.FREE);
                            break;

                        case 2:
                            FlightCamera.fetch.setMode(FlightCamera.Modes.ORBITAL);
                            break;

                        case 3:
                            FlightCamera.fetch.setMode(FlightCamera.Modes.CHASE);
                            break;

                        case 4:
                            FlightCamera.fetch.setMode(FlightCamera.Modes.LOCKED);
                            break;

                        default:
                            break;
                        }
                        _vControlsOld.CameraMode = _vControls.CameraMode;
                    }
                }

                if (_vControlsOld.OpenMenu != _vControls.OpenMenu || vesselChanged)
                {
                    if (_vControls.OpenMenu)
                    {
                        PauseMenu.Display();
                    }
                    else
                    {
                        PauseMenu.Close();
                    }
                    _vControlsOld.OpenMenu = _vControls.OpenMenu;
                }

                if (_vControlsOld.OpenMap != _vControls.OpenMap || vesselChanged)
                {
                    if (_vControls.OpenMap)
                    {
                        MapView.EnterMapView();
                    }
                    else
                    {
                        MapView.ExitMapView();
                    }
                    _vControlsOld.OpenMap = _vControls.OpenMap;
                }
            }
        }