예제 #1
0
        private void UpdateVP()
        {
            List <Part> ActiveEngines = new List <Part>();

            ActiveEngines = GetListOfActivatedEngines(AV);

            VP.FlightStatus = (byte)AV.situation;

            //Orbit
            VP.CurrentOrbit = OrbUtil.GetOrbitData(AV.orbit);

            VP.VVI = (float)AV.verticalSpeed;
            VP.G   = (float)AV.geeForce;

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

            if (AGL < ASL)
            {
                VP.RAlt = (float)AGL;
            }
            else
            {
                VP.RAlt = (float)ASL;
            }

            VP.Alt   = (float)ASL;
            VP.Vsurf = (float)AV.srfSpeed;
            VP.Lat   = (float)AV.latitude;
            VP.Lon   = (float)AV.longitude;

            TempR            = GetResourceTotal(AV, "LiquidFuel");
            VP.LiquidFuelTot = TempR.Max;
            VP.LiquidFuel    = TempR.Current;

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

            TempR          = GetResourceTotal(AV, "Oxidizer");
            VP.OxidizerTot = TempR.Max;
            VP.Oxidizer    = TempR.Current;

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

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

            VP.MissionTime = (float)AV.missionTime;
            VP.UT          = (float)Planetarium.GetUniversalTime();

            VP.VOrbit = (float)AV.orbit.GetVel().magnitude;

            VP.MNTime     = 0;
            VP.MNDeltaV   = 0;
            VP.TargetDist = 0;
            VP.TargetV    = 0;

            VP.HasTarget = (byte)(HasTarget() ? 1 : 0);

            //mathy stuff
            Quaternion rotationSurface;

            CoM   = AV.CoM;
            up    = (CoM - AV.mainBody.position).normalized;
            north = Vector3d.Exclude(up, (AV.mainBody.position + AV.mainBody.transform.up * (float)AV.mainBody.Radius) - CoM).normalized;

            east = Vector3d.Cross(up, north);

            rotationSurface = Quaternion.LookRotation(north, up);

            Vector3d attitude = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(AV.GetTransform().rotation) * rotationSurface).eulerAngles;

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

            Vector3d prograde = new Vector3d(0, 0, 0);

            switch (FlightGlobals.speedDisplayMode)
            {
            case FlightGlobals.SpeedDisplayModes.Surface:
                prograde = AV.srf_velocity.normalized;
                break;

            case FlightGlobals.SpeedDisplayModes.Orbit:
                prograde = AV.obt_velocity.normalized;
                break;

            case FlightGlobals.SpeedDisplayModes.Target:
                prograde = FlightGlobals.ship_tgtVelocity;
                break;
            }

            VP.Prograde = WorldVecToNavHeading(up, north, east, prograde);

            if (HasTarget())
            {
                ITargetable t = AV.targetObject;

                VP.Target     = WorldVecToNavHeading(up, north, east, t.GetTransform().position - AV.transform.position);
                VP.TargetDist = (float)Vector3.Distance(t.GetTransform().position, AV.transform.position);
                VP.TargetV    = (float)FlightGlobals.ship_tgtVelocity.magnitude;

                if (t is Vessel)
                {
                    attitude = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(t.GetVessel().GetTransform().rotation) * rotationSurface).eulerAngles;
                    VP.TargetRotation.Pitch   = (float)((attitude.x > 180) ? (360.0 - attitude.x) : -attitude.x);
                    VP.TargetRotation.Heading = (float)attitude.y;
                }
                else if (t is ModuleDockingNode)
                {
                    VP.TargetRotation = WorldVecToNavHeading(up, north, east, t.GetFwdVector());
                }
            }

            if (AV.patchedConicSolver != null)
            {
                if (AV.patchedConicSolver.maneuverNodes != null)
                {
                    if (AV.patchedConicSolver.maneuverNodes.Count > 0)
                    {
                        VP.MNTime   = (UInt32)Math.Round(AV.patchedConicSolver.maneuverNodes[0].UT - Planetarium.GetUniversalTime());
                        VP.MNDeltaV = (float)AV.patchedConicSolver.maneuverNodes[0].GetBurnVector(AV.patchedConicSolver.maneuverNodes[0].patch).magnitude; //Added JS

                        VP.Maneuver = WorldVecToNavHeading(up, north, east, AV.patchedConicSolver.maneuverNodes[0].GetBurnVector(AV.patchedConicSolver.maneuverNodes[0].patch));
                    }
                }
            }

            VP.MainControls = CalcMainControls();

            VP.ActionGroups = CalcActionGroups();

            VP.MaxOverHeat = GetMaxOverHeat(AV);
            VP.IAS         = (float)AV.indicatedAirSpeed;

            VP.CurrentStage = (byte)StageManager.CurrentStage;
            VP.TotalStage   = (byte)StageManager.StageCount;

            VP.SpeedMode = (byte)(FlightGlobals.speedDisplayMode + 1);
            VP.SASMode   = GetSASMode(true);

            VP.timeWarpRateIndex = GetTimeWarpIndex();
        }
 public Vector3 GetFwdVector()
 {
     return(target == null? Vector3.up : target.GetFwdVector());
 }