@@ -158,6 +158,8 @@ private void onAppLaunchToggleOff()
158158 }
159159 }
160160
161+ #endregion App launcher
162+
161163 private void editNode ( PlanningNodeModel toEdit )
162164 {
163165 if ( editor != null ) {
@@ -193,6 +195,7 @@ private void openDialog(PlanningNodeModel toEdit)
193195 editDialog . PrevNode += ( ) => editNode ( PlanningNodesManager . Instance . PrevNode ( renderer . vessel , editDialog . editingNode ) ) ;
194196 editDialog . NextNode += ( ) => editNode ( PlanningNodesManager . Instance . NextNode ( renderer . vessel , editDialog . editingNode ) ) ;
195197 editDialog . BodyChanged += OnBodyChanged ;
198+ editDialog . WarpTo += WarpTo ;
196199 editDialog . Show ( launcher . GetAnchor ( ) ) ;
197200 } else {
198201 // Already open, just switch to this node
@@ -232,7 +235,41 @@ private void OnGameUnpause()
232235 }
233236 }
234237
235- #endregion App launcher
238+ private void WarpTo ( PlanningNodeModel node )
239+ {
240+ if ( TimeWarp . CurrentRate > 1 ) {
241+ TimeWarp . fetch . CancelAutoWarp ( ) ;
242+ TimeWarp . SetRate ( 0 , false ) ;
243+ } else {
244+ TimeWarp . fetch . WarpTo ( node . burnTime - WarpBuffer ( node . origin , ( float ? ) renderer . vessel ? . orbit . ApA ?? 100000f ) ) ;
245+ }
246+ }
247+
248+ /// <summary>
249+ /// Calculate a good buffer for transferring from the given orbit
250+ /// </summary>
251+ /// <param name="parent">Body we're orbiting</param>
252+ /// <param name="apoapsis">Furthest distance from parent</param>
253+ /// <returns>
254+ /// One fourth the orbital period of a transfer orbit from your apoapsis to the edge of the sphere of influence;
255+ /// From LKO this is about 10d, and escaping to Duna takes 3d
256+ /// </returns>
257+ private static float WarpBuffer ( CelestialBody parent , float apoapsis )
258+ {
259+ return 0.25f * OrbitalPeriod ( parent , ( float ) parent . sphereOfInfluence , apoapsis ) ;
260+ }
261+
262+ /// <returns>
263+ /// Period of an orbit with the given characteristics.
264+ /// </returns>
265+ /// <param name="parent">Body around which to orbit</param>
266+ /// <param name="apoapsis">Greatest distance from center of parent</param>
267+ /// <param name="periapsis">Smallest distance from center of parent</param>
268+ public static float OrbitalPeriod ( CelestialBody parent , float apoapsis , float periapsis )
269+ {
270+ float r = 0.5f * ( apoapsis + periapsis ) ;
271+ return 2 * Mathf . PI * Mathf . Sqrt ( r * r * r / ( float ) parent . gravParameter ) ;
272+ }
236273
237274 /// <summary>
238275 /// Manages the drawing of the markers
0 commit comments