Esempio n. 1
0
        void Update()
        {
            ActiveVessel = FlightGlobals.ActiveVessel;

            if (ActiveVessel != null)
            {
                #region outputs
                if ((Time.time - lastUpdate) > refreshrate && KSPSerialPort.Port.IsOpen)
                {

                    lastUpdate = Time.time;

                    KSPSerialPort.VData.AP = (float)ActiveVessel.orbit.ApA;
                    KSPSerialPort.VData.PE = (float)ActiveVessel.orbit.PeA;
                    KSPSerialPort.VData.SemiMajorAxis = (float)ActiveVessel.orbit.semiMajorAxis;
                    KSPSerialPort.VData.SemiMinorAxis = (float)ActiveVessel.orbit.semiMinorAxis;
                    KSPSerialPort.VData.e = (float)ActiveVessel.orbit.eccentricity;
                    KSPSerialPort.VData.inc = (float)ActiveVessel.orbit.inclination;
                    KSPSerialPort.VData.VVI = (float)ActiveVessel.verticalSpeed;
                    KSPSerialPort.VData.G = (float)ActiveVessel.geeForce;
                    KSPSerialPort.VData.TAp = (int)Math.Round(ActiveVessel.orbit.timeToAp);
                    KSPSerialPort.VData.TPe = (int)Math.Round(ActiveVessel.orbit.timeToPe);
                    KSPSerialPort.VData.Density = (float)ActiveVessel.atmDensity;
                    KSPSerialPort.VData.TrueAnomaly = (float)ActiveVessel.orbit.trueAnomaly;
                    KSPSerialPort.VData.period = (int)Math.Round(ActiveVessel.orbit.period);

                    double ASL = ActiveVessel.mainBody.GetAltitude(ActiveVessel.CoM);
                    double AGL = (ASL - ActiveVessel.terrainAltitude);

                    if (AGL < ASL)
                        KSPSerialPort.VData.RAlt = (float)AGL;
                    else
                        KSPSerialPort.VData.RAlt = (float)ASL;

                    KSPSerialPort.VData.Alt = (float)ASL;
                    KSPSerialPort.VData.Vsurf = (float)ActiveVessel.srfSpeed;
                    KSPSerialPort.VData.Lat = (float)ActiveVessel.latitude;
                    KSPSerialPort.VData.Lon = (float)ActiveVessel.longitude;

                    TempR = GetResourceTotal(ActiveVessel, "LiquidFuel");
                    KSPSerialPort.VData.LiquidFuelTot = TempR.Max;
                    KSPSerialPort.VData.LiquidFuel = TempR.Current;
                    TempR = GetResourceTotal(ActiveVessel, "Oxidizer");
                    KSPSerialPort.VData.OxidizerTot = TempR.Max;
                    KSPSerialPort.VData.Oxidizer = TempR.Current;
                    TempR = GetResourceTotal(ActiveVessel, "ElectricCharge");
                    KSPSerialPort.VData.EChargeTot = TempR.Max;
                    KSPSerialPort.VData.ECharge = TempR.Current;
                    TempR = GetResourceTotal(ActiveVessel, "MonoPropellant");
                    KSPSerialPort.VData.MonoPropTot = TempR.Max;
                    KSPSerialPort.VData.MonoProp = TempR.Current;
                    TempR = GetResourceTotal(ActiveVessel, "IntakeAir");
                    KSPSerialPort.VData.IntakeAirTot = TempR.Max;
                    KSPSerialPort.VData.IntakeAir = TempR.Current;
                    TempR = GetResourceTotal(ActiveVessel, "SolidFuel");
                    KSPSerialPort.VData.SolidFuelTot = TempR.Max;
                    KSPSerialPort.VData.SolidFuel = TempR.Current;
                    TempR = GetResourceTotal(ActiveVessel, "XenonGas");
                    KSPSerialPort.VData.XenonGasTot = TempR.Max;
                    KSPSerialPort.VData.XenonGas = TempR.Current;

                    //ScreenMessages.PostScreenMessage(KSPSerialPort.VData.Fuelp.ToString());
                    //ScreenMessages.PostScreenMessage(KSPSerialPort.VData.RAlt.ToString());
                    //KSPSerialPort.Port.WriteLine("Success!");
                    KSPSerialPort.sendPacket(KSPSerialPort.VData);

                } //end refresh
                #endregion
                #region inputs
                if (KSPSerialPort.ControlReceived)
                {/*
                    ScreenMessages.PostScreenMessage("SAS: " + KSPSerialPort.VControls.SAS.ToString() +
                    ", RCS: " + KSPSerialPort.VControls.RCS.ToString() +
                    ", Lights: " + KSPSerialPort.VControls.Lights.ToString() +
                    ", Gear: " + KSPSerialPort.VControls.Gear.ToString() +
                    ", Brakes: " + KSPSerialPort.VControls.Brakes.ToString() +
                    ", Precision: " + KSPSerialPort.VControls.Precision.ToString() +
                    ", Abort: " + KSPSerialPort.VControls.Abort.ToString() +
                    ", Stage: " + KSPSerialPort.VControls.Stage.ToString(), 10f, KSPIOScreenStyle);
                    */

                    //if (FlightInputHandler.RCSLock != KSPSerialPort.VControls.RCS)
                    if (KSPSerialPort.VControls.RCS != KSPSerialPort.VControlsOld.RCS)
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.RCS, KSPSerialPort.VControls.RCS);
                        KSPSerialPort.VControlsOld.RCS = KSPSerialPort.VControls.RCS;
                        //ScreenMessages.PostScreenMessage("RCS: " + KSPSerialPort.VControls.RCS.ToString(), 10f, KSPIOScreenStyle);
                    }

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

                    if (KSPSerialPort.VControls.Lights != KSPSerialPort.VControlsOld.Lights)
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Light, KSPSerialPort.VControls.Lights);
                        KSPSerialPort.VControlsOld.Lights = KSPSerialPort.VControls.Lights;
                    }

                    if (KSPSerialPort.VControls.Gear != KSPSerialPort.VControlsOld.Gear)
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Gear, KSPSerialPort.VControls.Gear);
                        KSPSerialPort.VControlsOld.Gear = KSPSerialPort.VControls.Gear;
                    }

                    if (KSPSerialPort.VControls.Brakes != KSPSerialPort.VControlsOld.Brakes)
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, KSPSerialPort.VControls.Brakes);
                        KSPSerialPort.VControlsOld.Brakes = KSPSerialPort.VControls.Brakes;
                    }

                    if (KSPSerialPort.VControls.Abort != KSPSerialPort.VControlsOld.Abort)
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Abort, KSPSerialPort.VControls.Abort);
                        KSPSerialPort.VControlsOld.Abort = KSPSerialPort.VControls.Abort;
                    }

                    if (KSPSerialPort.VControls.Stage != KSPSerialPort.VControlsOld.Stage)
                    {
                        if (KSPSerialPort.VControls.Stage)
                            Staging.ActivateNextStage();

                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Stage, KSPSerialPort.VControls.Stage);
                        KSPSerialPort.VControlsOld.Stage = KSPSerialPort.VControls.Stage;
                    }

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

                    if (KSPSerialPort.VControls.ControlGroup[1] != KSPSerialPort.VControlsOld.ControlGroup[1])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom01, KSPSerialPort.VControls.ControlGroup[1]);
                        KSPSerialPort.VControlsOld.ControlGroup[1] = KSPSerialPort.VControls.ControlGroup[1];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[2] != KSPSerialPort.VControlsOld.ControlGroup[2])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom02, KSPSerialPort.VControls.ControlGroup[2]);
                        KSPSerialPort.VControlsOld.ControlGroup[2] = KSPSerialPort.VControls.ControlGroup[2];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[3] != KSPSerialPort.VControlsOld.ControlGroup[3])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom03, KSPSerialPort.VControls.ControlGroup[3]);
                        KSPSerialPort.VControlsOld.ControlGroup[3] = KSPSerialPort.VControls.ControlGroup[3];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[4] != KSPSerialPort.VControlsOld.ControlGroup[4])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom04, KSPSerialPort.VControls.ControlGroup[4]);
                        KSPSerialPort.VControlsOld.ControlGroup[4] = KSPSerialPort.VControls.ControlGroup[4];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[5] != KSPSerialPort.VControlsOld.ControlGroup[5])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom05, KSPSerialPort.VControls.ControlGroup[5]);
                        KSPSerialPort.VControlsOld.ControlGroup[5] = KSPSerialPort.VControls.ControlGroup[5];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[6] != KSPSerialPort.VControlsOld.ControlGroup[6])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom06, KSPSerialPort.VControls.ControlGroup[6]);
                        KSPSerialPort.VControlsOld.ControlGroup[6] = KSPSerialPort.VControls.ControlGroup[6];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[7] != KSPSerialPort.VControlsOld.ControlGroup[7])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom07, KSPSerialPort.VControls.ControlGroup[7]);
                        KSPSerialPort.VControlsOld.ControlGroup[7] = KSPSerialPort.VControls.ControlGroup[7];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[8] != KSPSerialPort.VControlsOld.ControlGroup[8])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom08, KSPSerialPort.VControls.ControlGroup[8]);
                        KSPSerialPort.VControlsOld.ControlGroup[8] = KSPSerialPort.VControls.ControlGroup[8];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[9] != KSPSerialPort.VControlsOld.ControlGroup[9])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom09, KSPSerialPort.VControls.ControlGroup[9]);
                        KSPSerialPort.VControlsOld.ControlGroup[9] = KSPSerialPort.VControls.ControlGroup[9];
                    }

                    if (KSPSerialPort.VControls.ControlGroup[10] != KSPSerialPort.VControlsOld.ControlGroup[10])
                    {
                        ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.Custom10, KSPSerialPort.VControls.ControlGroup[10]);
                        KSPSerialPort.VControlsOld.ControlGroup[10] = KSPSerialPort.VControls.ControlGroup[10];
                    }

                    KSPSerialPort.ControlReceived = false;
                } //end ControlReceived
                #endregion
            }//end if null
        }
Esempio n. 2
0
        void Update()
        {
            if (FlightGlobals.ActiveVessel != null && KSPSerialPort.Port.IsOpen)
            {
                //Debug.Log("KSPSerialIO: 1");
                //If the current active vessel is not what we were using, we need to remove controls from the old
                //vessel and attache it to the current one
                if (ActiveVessel.id != FlightGlobals.ActiveVessel.id)
                {
                    ActiveVessel.OnFlyByWire -= new FlightInputCallback (AxisInput);
                    ActiveVessel = FlightGlobals.ActiveVessel;
                    ActiveVessel.OnFlyByWire += new FlightInputCallback (AxisInput);
                    //sync some inputs on vessel switch
                    ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.RCS, KSPSerialPort.VControls.RCS);
                    ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.SAS, KSPSerialPort.VControls.SAS);
                    Debug.Log ("KSPSerialIO: ActiveVessel changed");
                }
                else
                {
                    ActiveVessel = FlightGlobals.ActiveVessel;
                }

                #region outputs
                theTime = Time.unscaledTime;
                if ((theTime - lastUpdate) > refreshrate)
                {
                    //Debug.Log("KSPSerialIO: 2");

                    lastUpdate = theTime;

                    List<Part> ActiveEngines = new List<Part> ();
                    ActiveEngines = GetListOfActivatedEngines (ActiveVessel);

                    KSPSerialPort.VData.AP = (float)ActiveVessel.orbit.ApA;
                    KSPSerialPort.VData.PE = (float)ActiveVessel.orbit.PeA;
                    KSPSerialPort.VData.SemiMajorAxis = (float)ActiveVessel.orbit.semiMajorAxis;
                    KSPSerialPort.VData.SemiMinorAxis = (float)ActiveVessel.orbit.semiMinorAxis;
                    KSPSerialPort.VData.e = (float)ActiveVessel.orbit.eccentricity;
                    KSPSerialPort.VData.inc = (float)ActiveVessel.orbit.inclination;
                    KSPSerialPort.VData.VVI = (float)ActiveVessel.verticalSpeed;
                    KSPSerialPort.VData.G = (float)ActiveVessel.geeForce;
                    KSPSerialPort.VData.TAp = (int)Math.Round (ActiveVessel.orbit.timeToAp);
                    KSPSerialPort.VData.TPe = (int)Math.Round (ActiveVessel.orbit.timeToPe);
                    KSPSerialPort.VData.Density = (float)ActiveVessel.atmDensity;
                    KSPSerialPort.VData.TrueAnomaly = (float)ActiveVessel.orbit.trueAnomaly;
                    KSPSerialPort.VData.period = (int)Math.Round (ActiveVessel.orbit.period);

                    //Debug.Log("KSPSerialIO: 3");
                    double ASL = ActiveVessel.mainBody.GetAltitude (ActiveVessel.CoM);
                    double AGL = (ASL - ActiveVessel.terrainAltitude);

                    if (AGL < ASL)
                        KSPSerialPort.VData.RAlt = (float)AGL;
                    else
                        KSPSerialPort.VData.RAlt = (float)ASL;

                    KSPSerialPort.VData.Alt = (float)ASL;
                    KSPSerialPort.VData.Vsurf = (float)ActiveVessel.srfSpeed;
                    KSPSerialPort.VData.Lat = (float)ActiveVessel.latitude;
                    KSPSerialPort.VData.Lon = (float)ActiveVessel.longitude;

                    TempR = GetResourceTotal (ActiveVessel, "LiquidFuel");
                    KSPSerialPort.VData.LiquidFuelTot = TempR.Max;
                    KSPSerialPort.VData.LiquidFuel = TempR.Current;

                    KSPSerialPort.VData.LiquidFuelTotS = (float)ProspectForResourceMax ("LiquidFuel", ActiveEngines);
                    KSPSerialPort.VData.LiquidFuelS = (float)ProspectForResource ("LiquidFuel", ActiveEngines);

                    TempR = GetResourceTotal (ActiveVessel, "Oxidizer");
                    KSPSerialPort.VData.OxidizerTot = TempR.Max;
                    KSPSerialPort.VData.Oxidizer = TempR.Current;

                    KSPSerialPort.VData.OxidizerTotS = (float)ProspectForResourceMax ("Oxidizer", ActiveEngines);
                    KSPSerialPort.VData.OxidizerS = (float)ProspectForResource ("Oxidizer", ActiveEngines);

                    TempR = GetResourceTotal (ActiveVessel, "ElectricCharge");
                    KSPSerialPort.VData.EChargeTot = TempR.Max;
                    KSPSerialPort.VData.ECharge = TempR.Current;
                    TempR = GetResourceTotal (ActiveVessel, "MonoPropellant");
                    KSPSerialPort.VData.MonoPropTot = TempR.Max;
                    KSPSerialPort.VData.MonoProp = TempR.Current;
                    TempR = GetResourceTotal (ActiveVessel, "IntakeAir");
                    KSPSerialPort.VData.IntakeAirTot = TempR.Max;
                    KSPSerialPort.VData.IntakeAir = TempR.Current;
                    TempR = GetResourceTotal (ActiveVessel, "SolidFuel");
                    KSPSerialPort.VData.SolidFuelTot = TempR.Max;
                    KSPSerialPort.VData.SolidFuel = TempR.Current;
                    TempR = GetResourceTotal (ActiveVessel, "XenonGas");
                    KSPSerialPort.VData.XenonGasTot = TempR.Max;
                    KSPSerialPort.VData.XenonGas = TempR.Current;

                    missionTime = ActiveVessel.missionTime;
                    deltaT = missionTime - missionTimeOld;
                    missionTimeOld = missionTime;

                    KSPSerialPort.VData.MissionTime = (UInt32)Math.Round (missionTime);
                    KSPSerialPort.VData.deltaTime = (float)deltaT;

                    KSPSerialPort.VData.VOrbit = (float)ActiveVessel.orbit.GetVel ().magnitude;

                    //Debug.Log("KSPSerialIO: 4");

                    KSPSerialPort.VData.MNTime = 0;
                    KSPSerialPort.VData.MNDeltaV = 0;

                    if (ActiveVessel.patchedConicSolver != null)
                    {
                        if (ActiveVessel.patchedConicSolver.maneuverNodes != null)
                        {
                            if (ActiveVessel.patchedConicSolver.maneuverNodes.Count > 0)
                            {
                                KSPSerialPort.VData.MNTime = (UInt32)Math.Round (ActiveVessel.patchedConicSolver.maneuverNodes [0].UT - Planetarium.GetUniversalTime ());
                                KSPSerialPort.VData.MNDeltaV = (float)ActiveVessel.patchedConicSolver.maneuverNodes [0].DeltaV.magnitude;
                            }
                        }
                    }

                    //Debug.Log("KSPSerialIO: 5");

                    Quaternion attitude = updateHeadingPitchRollField (ActiveVessel);

                    KSPSerialPort.VData.Roll = (float)((attitude.eulerAngles.z > 180) ? (attitude.eulerAngles.z - 360.0) : attitude.eulerAngles.z);
                    KSPSerialPort.VData.Pitch = (float)((attitude.eulerAngles.x > 180) ? (360.0 - attitude.eulerAngles.x) : -attitude.eulerAngles.x);
                    KSPSerialPort.VData.Heading = (float)attitude.eulerAngles.y;

                    KSPSerialPort.ControlStatus ((int)enumAG.SAS, ActiveVessel.ActionGroups [KSPActionGroup.SAS]);
                    KSPSerialPort.ControlStatus ((int)enumAG.RCS, ActiveVessel.ActionGroups [KSPActionGroup.RCS]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Light, ActiveVessel.ActionGroups [KSPActionGroup.Light]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Gear, ActiveVessel.ActionGroups [KSPActionGroup.Gear]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Brakes, ActiveVessel.ActionGroups [KSPActionGroup.Brakes]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Abort, ActiveVessel.ActionGroups [KSPActionGroup.Abort]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom01, ActiveVessel.ActionGroups [KSPActionGroup.Custom01]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom02, ActiveVessel.ActionGroups [KSPActionGroup.Custom02]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom03, ActiveVessel.ActionGroups [KSPActionGroup.Custom03]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom04, ActiveVessel.ActionGroups [KSPActionGroup.Custom04]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom05, ActiveVessel.ActionGroups [KSPActionGroup.Custom05]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom06, ActiveVessel.ActionGroups [KSPActionGroup.Custom06]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom07, ActiveVessel.ActionGroups [KSPActionGroup.Custom07]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom08, ActiveVessel.ActionGroups [KSPActionGroup.Custom08]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom09, ActiveVessel.ActionGroups [KSPActionGroup.Custom09]);
                    KSPSerialPort.ControlStatus ((int)enumAG.Custom10, ActiveVessel.ActionGroups [KSPActionGroup.Custom10]);

                    #region debugjunk
                    /*
                    ScreenMessages.PostScreenMessage(KSPSerialPort.VData.OxidizerS.ToString() + "/" + KSPSerialPort.VData.OxidizerTotS +
                        "   " + KSPSerialPort.VData.Oxidizer.ToString() + "/" + KSPSerialPort.VData.OxidizerTot);
                    */
                    //KSPSerialPort.VData.Roll = Mathf.Atan2(2 * (x * y + w * z), w * w + x * x - y * y - z * z) * 180 / Mathf.PI;
                    //KSPSerialPort.VData.Pitch = Mathf.Atan2(2 * (y * z + w * x), w * w - x * x - y * y + z * z) * 180 / Mathf.PI;
                    //KSPSerialPort.VData.Heading = Mathf.Asin(-2 * (x * z - w * y)) *180 / Mathf.PI;
                    //Debug.Log("KSPSerialIO: Roll    " + KSPSerialPort.VData.Roll.ToString());
                    //Debug.Log("KSPSerialIO: Pitch   " + KSPSerialPort.VData.Pitch.ToString());
                    //Debug.Log("KSPSerialIO: Heading " + KSPSerialPort.VData.Heading.ToString());
                    //Debug.Log("KSPSerialIO: VOrbit" + KSPSerialPort.VData.VOrbit.ToString());
                    //ScreenMessages.PostScreenMessage(ActiveVessel.ActionGroups[KSPActionGroup.RCS].ToString());
                    //Debug.Log("KSPSerialIO: MNTime" + KSPSerialPort.VData.MNTime.ToString() + " MNDeltaV" + KSPSerialPort.VData.MNDeltaV.ToString());
                    //Debug.Log("KSPSerialIO: Time" + KSPSerialPort.VData.MissionTime.ToString() + " Delta Time" + KSPSerialPort.VData.deltaTime.ToString());
                    //Debug.Log("KSPSerialIO: Throttle = " + KSPSerialPort.CPacket.Throttle.ToString());
                    //ScreenMessages.PostScreenMessage(KSPSerialPort.VData.Fuelp.ToString());
                    //ScreenMessages.PostScreenMessage(KSPSerialPort.VData.RAlt.ToString());
                    //KSPSerialPort.Port.WriteLine("Success!");
                    /*
                    ScreenMessages.PostScreenMessage(KSPSerialPort.VData.LiquidFuelS.ToString() + "/" + KSPSerialPort.VData.LiquidFuelTotS +
                        "   " + KSPSerialPort.VData.LiquidFuel.ToString() + "/" + KSPSerialPort.VData.LiquidFuelTot);
                    */
                    #endregion
                    KSPSerialPort.sendPacket (KSPSerialPort.VData);
                } //end refresh
                #endregion
                #region inputs
                if (KSPSerialPort.ControlReceived)
                {
                    /*
                     ScreenMessages.PostScreenMessage("SAS: " + KSPSerialPort.VControls.SAS.ToString() +
                     ", RCS: " + KSPSerialPort.VControls.RCS.ToString() +
                     ", Lights: " + KSPSerialPort.VControls.Lights.ToString() +
                     ", Gear: " + KSPSerialPort.VControls.Gear.ToString() +
                     ", Brakes: " + KSPSerialPort.VControls.Brakes.ToString() +
                     ", Precision: " + KSPSerialPort.VControls.Precision.ToString() +
                     ", Abort: " + KSPSerialPort.VControls.Abort.ToString() +
                     ", Stage: " + KSPSerialPort.VControls.Stage.ToString(), 10f, KSPIOScreenStyle);

                     Debug.Log("KSPSerialIO: SAS: " + KSPSerialPort.VControls.SAS.ToString() +
                     ", RCS: " + KSPSerialPort.VControls.RCS.ToString() +
                     ", Lights: " + KSPSerialPort.VControls.Lights.ToString() +
                     ", Gear: " + KSPSerialPort.VControls.Gear.ToString() +
                     ", Brakes: " + KSPSerialPort.VControls.Brakes.ToString() +
                     ", Precision: " + KSPSerialPort.VControls.Precision.ToString() +
                     ", Abort: " + KSPSerialPort.VControls.Abort.ToString() +
                     ", Stage: " + KSPSerialPort.VControls.Stage.ToString());
                     */

                    if (Math.Abs (KSPSerialPort.VControls.Pitch) > SettingsNStuff.SASTol ||
                    Math.Abs (KSPSerialPort.VControls.Roll) > SettingsNStuff.SASTol ||
                    Math.Abs (KSPSerialPort.VControls.Yaw) > SettingsNStuff.SASTol)
                    {
                        ActiveVessel.Autopilot.SAS.ManualOverride (true);
                        //KSPSerialPort.VControlsOld.Pitch = KSPSerialPort.VControls.Pitch;
                        //KSPSerialPort.VControlsOld.Roll = KSPSerialPort.VControls.Roll;
                        //KSPSerialPort.VControlsOld.Yaw = KSPSerialPort.VControls.Yaw;
                    }
                    else
                    {
                        ActiveVessel.Autopilot.SAS.ManualOverride (false);
                    }

                    //if (FlightInputHandler.RCSLock != KSPSerialPort.VControls.RCS)
                    if (KSPSerialPort.VControls.RCS != KSPSerialPort.VControlsOld.RCS)
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.RCS, KSPSerialPort.VControls.RCS);
                        KSPSerialPort.VControlsOld.RCS = KSPSerialPort.VControls.RCS;
                        //ScreenMessages.PostScreenMessage("RCS: " + KSPSerialPort.VControls.RCS.ToString(), 10f, KSPIOScreenStyle);
                    }

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

                    if (KSPSerialPort.VControls.Lights != KSPSerialPort.VControlsOld.Lights)
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Light, KSPSerialPort.VControls.Lights);
                        KSPSerialPort.VControlsOld.Lights = KSPSerialPort.VControls.Lights;
                    }

                    if (KSPSerialPort.VControls.Gear != KSPSerialPort.VControlsOld.Gear)
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Gear, KSPSerialPort.VControls.Gear);
                        KSPSerialPort.VControlsOld.Gear = KSPSerialPort.VControls.Gear;
                    }

                    if (KSPSerialPort.VControls.Brakes != KSPSerialPort.VControlsOld.Brakes)
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Brakes, KSPSerialPort.VControls.Brakes);
                        KSPSerialPort.VControlsOld.Brakes = KSPSerialPort.VControls.Brakes;
                    }

                    if (KSPSerialPort.VControls.Abort != KSPSerialPort.VControlsOld.Abort)
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Abort, KSPSerialPort.VControls.Abort);
                        KSPSerialPort.VControlsOld.Abort = KSPSerialPort.VControls.Abort;
                    }

                    if (KSPSerialPort.VControls.Stage != KSPSerialPort.VControlsOld.Stage)
                    {
                        if (KSPSerialPort.VControls.Stage)
                            Staging.ActivateNextStage ();

                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Stage, KSPSerialPort.VControls.Stage);
                        KSPSerialPort.VControlsOld.Stage = KSPSerialPort.VControls.Stage;
                    }

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

                    if (KSPSerialPort.VControls.ControlGroup [1] != KSPSerialPort.VControlsOld.ControlGroup [1])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom01, KSPSerialPort.VControls.ControlGroup [1]);
                        KSPSerialPort.VControlsOld.ControlGroup [1] = KSPSerialPort.VControls.ControlGroup [1];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [2] != KSPSerialPort.VControlsOld.ControlGroup [2])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom02, KSPSerialPort.VControls.ControlGroup [2]);
                        KSPSerialPort.VControlsOld.ControlGroup [2] = KSPSerialPort.VControls.ControlGroup [2];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [3] != KSPSerialPort.VControlsOld.ControlGroup [3])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom03, KSPSerialPort.VControls.ControlGroup [3]);
                        KSPSerialPort.VControlsOld.ControlGroup [3] = KSPSerialPort.VControls.ControlGroup [3];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [4] != KSPSerialPort.VControlsOld.ControlGroup [4])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom04, KSPSerialPort.VControls.ControlGroup [4]);
                        KSPSerialPort.VControlsOld.ControlGroup [4] = KSPSerialPort.VControls.ControlGroup [4];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [5] != KSPSerialPort.VControlsOld.ControlGroup [5])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom05, KSPSerialPort.VControls.ControlGroup [5]);
                        KSPSerialPort.VControlsOld.ControlGroup [5] = KSPSerialPort.VControls.ControlGroup [5];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [6] != KSPSerialPort.VControlsOld.ControlGroup [6])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom06, KSPSerialPort.VControls.ControlGroup [6]);
                        KSPSerialPort.VControlsOld.ControlGroup [6] = KSPSerialPort.VControls.ControlGroup [6];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [7] != KSPSerialPort.VControlsOld.ControlGroup [7])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom07, KSPSerialPort.VControls.ControlGroup [7]);
                        KSPSerialPort.VControlsOld.ControlGroup [7] = KSPSerialPort.VControls.ControlGroup [7];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [8] != KSPSerialPort.VControlsOld.ControlGroup [8])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom08, KSPSerialPort.VControls.ControlGroup [8]);
                        KSPSerialPort.VControlsOld.ControlGroup [8] = KSPSerialPort.VControls.ControlGroup [8];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [9] != KSPSerialPort.VControlsOld.ControlGroup [9])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom09, KSPSerialPort.VControls.ControlGroup [9]);
                        KSPSerialPort.VControlsOld.ControlGroup [9] = KSPSerialPort.VControls.ControlGroup [9];
                    }

                    if (KSPSerialPort.VControls.ControlGroup [10] != KSPSerialPort.VControlsOld.ControlGroup [10])
                    {
                        ActiveVessel.ActionGroups.SetGroup (KSPActionGroup.Custom10, KSPSerialPort.VControls.ControlGroup [10]);
                        KSPSerialPort.VControlsOld.ControlGroup [10] = KSPSerialPort.VControls.ControlGroup [10];
                    }

                    KSPSerialPort.ControlReceived = false;
                } //end ControlReceived
                #endregion

            }//end if null and same vessel
            else
            {
                //Debug.Log("KSPSerialIO: ActiveVessel not found");
                //ActiveVessel.OnFlyByWire -= new FlightInputCallback(AxisInput);
            }
        }
Esempio n. 3
0
        private IOResource GetResourceTotal(Vessel V, string resourceName)
        {
            IOResource R = new IOResource();

            foreach (Part p in ActiveVessel.parts)
            {
                foreach (PartResource pr in p.Resources)
                {
                    if (pr.resourceName.Equals(resourceName))
                    {
                        R.Current += (float)pr.amount;
                        R.Max += (float)pr.maxAmount;
                        break;
                    }
                }
            }

            if (R.Max == 0)
                R.Current = 0;

            return R;
        }
Esempio n. 4
0
        private IOResource GetResourceTotal(Vessel V, string resourceName)
        {
            IOResource R = new IOResource ();

            foreach (Part p in ActiveVessel.parts)
            {
                foreach (PartResource pr in p.Resources)
                {
                    if (pr.resourceName.Equals (resourceName))
                    {
                        R.Current += (float)pr.amount;
                        R.Max += (float)pr.maxAmount;

                        /* shit doesn't work
                        int stageno = p.inverseStage;

                        Debug.Log(pr.resourceName + "  " + stageno.ToString() + "  " + Staging.CurrentStage.ToString());

                        //if (p.inverseStage == Staging.CurrentStage + 1)
                        if (stageno == Staging.CurrentStage)
                        {
                            R.CurrentStage += (float)pr.amount;
                            R.MaxStage += (float)pr.maxAmount;
                        }
                         */
                        break;
                    }
                }
            }

            if (R.Max == 0)
                R.Current = 0;

            return R;
        }