public override void OnFixedUpdate() { if (!warping) { return; } if (warpTarget == WarpTarget.SuicideBurn) { try { targetUT = OrbitExtensions.SuicideBurnCountdown(orbit, vesselState, vessel) + vesselState.time; } catch { warping = false; } } double target = targetUT - leadTime; if (target < vesselState.time + 1) { core.warp.MinimumWarp(true); warping = false; } else { core.warp.WarpToUT(target); } }
public string SuicideBurnCountdown() { try { return(GuiUtils.TimeToDHMS(OrbitExtensions.SuicideBurnCountdown(orbit, vesselState, vessel))); } catch { return("N/A"); } }
override public void afterOnFixedUpdate() { //Check the end of the action if (this.isStarted() && !this.isExecuted() && !warping && startTime == 0f) { startTime = Time.time; } if (this.isStarted() && !this.isExecuted() && startTime > 0) { this.spendTime = initTime - (int)(Math.Round(Time.time - startTime)); //Add the end action timer if (this.spendTime <= 0) { this.endAction(); } } if (!warping) { return; } if (warpTarget == WarpTarget.SuicideBurn) { try { targetUT = OrbitExtensions.SuicideBurnCountdown(this.scriptModule.orbit, this.scriptModule.vesselState, this.scriptModule.vessel) + this.scriptModule.vesselState.time; } catch { warping = false; } } double target = targetUT - leadTime; if (target < this.scriptModule.vesselState.time + 1) { core.warp.MinimumWarp(true); warping = false; } else { core.warp.WarpToUT(target); } }
override public void activateAction() { base.activateAction(); warping = true; Orbit orbit = this.scriptModule.orbit; VesselState vesselState = this.scriptModule.vesselState; Vessel vessel = FlightGlobals.ActiveVessel; switch (warpTarget) { case WarpTarget.Periapsis: targetUT = orbit.NextPeriapsisTime(vesselState.time); break; case WarpTarget.Apoapsis: if (orbit.eccentricity < 1) { targetUT = orbit.NextApoapsisTime(vesselState.time); } break; case WarpTarget.SoI: if (orbit.patchEndTransition != Orbit.PatchTransitionType.FINAL) { targetUT = orbit.EndUT; } break; case WarpTarget.Node: if (vessel.patchedConicsUnlocked() && vessel.patchedConicSolver.maneuverNodes.Any()) { targetUT = vessel.patchedConicSolver.maneuverNodes[0].UT; } break; case WarpTarget.Time: targetUT = vesselState.time + timeOffset; break; case WarpTarget.PhaseAngleT: if (core.target.NormalTargetExists) { Orbit reference; if (core.target.TargetOrbit.referenceBody == orbit.referenceBody) { reference = orbit; // we orbit arround the same body } else { reference = orbit.referenceBody.orbit; } // From Kerbal Alarm Clock double angleChangePerSec = (360 / core.target.TargetOrbit.period) - (360 / reference.period); double currentAngle = reference.PhaseAngle(core.target.TargetOrbit, vesselState.time); double angleDigff = currentAngle - phaseAngle; if (angleDigff > 0 && angleChangePerSec > 0) { angleDigff -= 360; } if (angleDigff < 0 && angleChangePerSec < 0) { angleDigff += 360; } double TimeToTarget = Math.Floor(Math.Abs(angleDigff / angleChangePerSec)); targetUT = vesselState.time + TimeToTarget; } break; case WarpTarget.AtmosphericEntry: try { targetUT = OrbitExtensions.NextTimeOfRadius(vessel.orbit, vesselState.time, vesselState.mainBody.Radius + vesselState.mainBody.RealMaxAtmosphereAltitude()); } catch { warping = false; } break; case WarpTarget.SuicideBurn: try { targetUT = OrbitExtensions.SuicideBurnCountdown(orbit, vesselState, vessel) + vesselState.time; } catch { warping = false; } break; default: targetUT = vesselState.time; break; } }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WarpHelper_label1"), GUILayout.ExpandWidth(false));//"Warp to: " warpTarget = (WarpTarget)GuiUtils.ComboBox.Box((int)warpTarget, warpTargetStrings, this); GUILayout.EndHorizontal(); if (warpTarget == WarpTarget.Time) { GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WarpHelper_label2"), GUILayout.ExpandWidth(true));//"Warp for: " timeOffset.text = GUILayout.TextField(timeOffset.text, GUILayout.Width(100)); GUILayout.EndHorizontal(); } else if (warpTarget == WarpTarget.PhaseAngleT) { // I wonder if I should check for target that don't make sense if (!core.target.NormalTargetExists) { GUILayout.Label(Localizer.Format("#MechJeb_WarpHelper_label3"));//"You need a target" } else { GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_WarpHelper_label4"), phaseAngle, "ยบ", 60);//"Phase Angle:" } } GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_WarpHelper_label5"), leadTime, "");//"Lead time: " if (warping) { if (GUILayout.Button(Localizer.Format("#MechJeb_WarpHelper_button1")))//"Abort" { warping = false; core.warp.MinimumWarp(true); } } else { if (GUILayout.Button(Localizer.Format("#MechJeb_WarpHelper_button2")))//"Warp" { warping = true; switch (warpTarget) { case WarpTarget.Periapsis: targetUT = orbit.NextPeriapsisTime(vesselState.time); break; case WarpTarget.Apoapsis: if (orbit.eccentricity < 1) { targetUT = orbit.NextApoapsisTime(vesselState.time); } break; case WarpTarget.SoI: if (orbit.patchEndTransition != Orbit.PatchTransitionType.FINAL) { targetUT = orbit.EndUT; } break; case WarpTarget.Node: if (vessel.patchedConicsUnlocked() && vessel.patchedConicSolver.maneuverNodes.Any()) { targetUT = vessel.patchedConicSolver.maneuverNodes[0].UT; } break; case WarpTarget.Time: targetUT = vesselState.time + timeOffset; break; case WarpTarget.PhaseAngleT: if (core.target.NormalTargetExists) { Orbit reference; if (core.target.TargetOrbit.referenceBody == orbit.referenceBody) { reference = orbit; // we orbit arround the same body } else { reference = orbit.referenceBody.orbit; } // From Kerbal Alarm Clock double angleChangePerSec = (360 / core.target.TargetOrbit.period) - (360 / reference.period); double currentAngle = reference.PhaseAngle(core.target.TargetOrbit, vesselState.time); double angleDigff = currentAngle - phaseAngle; if (angleDigff > 0 && angleChangePerSec > 0) { angleDigff -= 360; } if (angleDigff < 0 && angleChangePerSec < 0) { angleDigff += 360; } double TimeToTarget = Math.Floor(Math.Abs(angleDigff / angleChangePerSec)); targetUT = vesselState.time + TimeToTarget; } break; case WarpTarget.AtmosphericEntry: try { targetUT = OrbitExtensions.NextTimeOfRadius(vessel.orbit, vesselState.time, vesselState.mainBody.Radius + vesselState.mainBody.RealMaxAtmosphereAltitude()); } catch { warping = false; } break; case WarpTarget.SuicideBurn: try { targetUT = OrbitExtensions.SuicideBurnCountdown(orbit, vesselState, vessel) + vesselState.time; } catch { warping = false; } break; default: targetUT = vesselState.time; break; } } } GUILayout.EndHorizontal(); core.warp.useQuickWarpInfoItem(); if (warping) { GUILayout.Label(Localizer.Format("#MechJeb_WarpHelper_label6") + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); //"Warping to " } core.warp.ControlWarpButton(); GUILayout.EndVertical(); base.WindowGUI(windowID); }