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(); }
private RawOrbitPlanData GenerateRawOrbitPlanData() { RawOrbitPlanData dataOut = new RawOrbitPlanData { CurrentOrbitPatches = new List <OrbitData>(), ManPatchNum = -1, PlannedOrbitPatches = new List <OrbitData>(), TargetName = "???", Mans = new List <ManData>(), }; Orbit patch, lastPatch = null; patch = AV.orbit; while (patch != null && patch.activePatch) { dataOut.CurrentOrbitPatches.Add(OrbUtil.GetOrbitData(lastPatch = patch)); patch = patch.nextPatch; } if (AV.patchedConicSolver != null) { if (AV.patchedConicSolver.maneuverNodes != null) { if (AV.patchedConicSolver.maneuverNodes.Count > 0) { for (int i = 0; i < AV.patchedConicSolver.flightPlan.Count; i++) { if (AV.patchedConicSolver.flightPlan[i].patchStartTransition == Orbit.PatchTransitionType.MANEUVER) { dataOut.ManPatchNum = i; break; } } patch = AV.patchedConicSolver.maneuverNodes[0].nextPatch; while (patch != null && patch.activePatch) { dataOut.PlannedOrbitPatches.Add(OrbUtil.GetOrbitData(lastPatch = patch)); patch = patch.nextPatch; } for (int i = 0; i < AV.patchedConicSolver.maneuverNodes.Count; i++) { ManeuverNode m = AV.patchedConicSolver.maneuverNodes[i]; dataOut.Mans.Add(new ManData { DV = (float)m.GetBurnVector(m.patch).magnitude, UT = m.UT, X = (float)m.DeltaV.x, Y = (float)m.DeltaV.y, Z = (float)m.DeltaV.z, }); } } } } if (HasTarget()) { dataOut.TargetName = AV.targetObject.GetName(); OrbitData o = OrbUtil.GetOrbitData(AV.targetObject.GetOrbit()); if (AV.targetObject is CelestialBody) { o.transEnd = (byte)PatchTransitionType.FINAL; o.anomolyEnd = o.anomoly + Math.PI * 2; } dataOut.TargetOrbit = (o); //lastPatch.GetDTforTrueAnomaly dataOut.Rendezvous.ANAnom = (float)(FinePrint.Utilities.OrbitUtilities.AngleOfAscendingNode(lastPatch, AV.targetObject.GetOrbit()) * Deg2Rad); dataOut.Rendezvous.TargetANAnom = (float)(FinePrint.Utilities.OrbitUtilities.AngleOfAscendingNode(AV.targetObject.GetOrbit(), lastPatch) * Deg2Rad); dataOut.Rendezvous.T2AN = (int)OrbUtil.T2TAnom(lastPatch, dataOut.Rendezvous.ANAnom) % o.period; dataOut.Rendezvous.T2DN = (int)OrbUtil.T2TAnom(lastPatch, dataOut.Rendezvous.ANAnom + Math.PI) % o.period; dataOut.Rendezvous.RelInc = (float)FinePrint.Utilities.OrbitUtilities.GetRelativeInclination(lastPatch, AV.targetObject.GetOrbit()); double dist; double time = OrbUtil.CalcClosestAproach(lastPatch, AV.targetObject.GetOrbit(), lastPatch.StartUT, out dist); dataOut.Rendezvous.T2CA = (int)(time - Planetarium.GetUniversalTime()); dataOut.Rendezvous.SepAtCA = (int)dist; dataOut.Rendezvous.CAAnom = (float)lastPatch.TrueAnomalyAtUT(time); dataOut.Rendezvous.TargetCAAnom = (float)AV.targetObject.GetOrbit().TrueAnomalyAtUT(time); } return(dataOut); }