1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Linq ;
44using System . Text ;
@@ -12,15 +12,22 @@ public class ManeuverCommand : AbstractCommand
1212 public double OriginalDelta { get ; set ; }
1313 public double RemainingTime { get ; set ; }
1414 public double RemainingDelta { get ; set ; }
15+ public bool EngineActivated { get ; set ; }
1516 public override int Priority { get { return 0 ; } }
1617
1718 public override string Description
1819 {
1920 get
2021 {
2122 if ( RemainingTime > 0 || RemainingDelta > 0 )
22- return "Executing maneuver: " + RemainingDelta . ToString ( "F2" ) + "m/s" + Environment . NewLine +
23- "Remaining duration: " + RTUtil . FormatDuration ( RemainingTime ) + Environment . NewLine + base . Description ;
23+ {
24+ string flightInfo = "Executing maneuver: " + RemainingDelta . ToString ( "F2" ) +
25+ "m/s" + Environment . NewLine + "Remaining duration: " ;
26+
27+ flightInfo += EngineActivated ? RTUtil . FormatDuration ( RemainingTime ) : "-:-" ;
28+
29+ return flightInfo + Environment . NewLine + base . Description ;
30+ }
2431 else
2532 return "Execute planned maneuver" + Environment . NewLine + base . Description ;
2633 }
@@ -29,10 +36,22 @@ public override string Description
2936 public override bool Pop ( FlightComputer f )
3037 {
3138 var burn = f . ActiveCommands . FirstOrDefault ( c => c is BurnCommand ) ;
32- if ( burn != null ) f . Remove ( burn ) ;
39+ if ( burn != null ) {
40+ f . Remove ( burn ) ;
41+ }
42+
3343 OriginalDelta = Node . DeltaV . magnitude ;
3444 RemainingDelta = Node . GetBurnVector ( f . Vessel . orbit ) . magnitude ;
35- RemainingTime = RemainingDelta / ( FlightCore . GetTotalThrust ( f . Vessel ) / f . Vessel . GetTotalMass ( ) ) ;
45+ EngineActivated = true ;
46+
47+ double thrustToMass = FlightCore . GetTotalThrust ( f . Vessel ) / f . Vessel . GetTotalMass ( ) ;
48+ if ( thrustToMass == 0.0 ) {
49+ EngineActivated = false ;
50+ RTUtil . ScreenMessage ( "[Flight Computer]: No engine to carry out the maneuver." ) ;
51+ } else {
52+ RemainingTime = RemainingDelta / thrustToMass ;
53+ }
54+
3655 return true ;
3756 }
3857
@@ -44,17 +63,32 @@ public override bool Execute(FlightComputer f, FlightCtrlState fcs)
4463 var up = ( f . SignalProcessor . Body . position - f . SignalProcessor . Position ) . normalized ;
4564 var orientation = Quaternion . LookRotation ( forward , up ) ;
4665 FlightCore . HoldOrientation ( fcs , f , orientation ) ;
66+
67+ double thrustToMass = ( FlightCore . GetTotalThrust ( f . Vessel ) / f . Vessel . GetTotalMass ( ) ) ;
68+ if ( thrustToMass == 0.0 ) {
69+ EngineActivated = false ;
70+ return false ;
71+ }
72+
73+ EngineActivated = true ;
4774 fcs . mainThrottle = 1.0f ;
48- RemainingTime -= TimeWarp . deltaTime ;
49- RemainingDelta -= ( FlightCore . GetTotalThrust ( f . Vessel ) / f . Vessel . GetTotalMass ( ) ) * TimeWarp . deltaTime ;
75+ RemainingTime = RemainingDelta / thrustToMass ;
76+ RemainingDelta -= thrustToMass * TimeWarp . deltaTime ;
5077 return false ;
5178 }
5279 f . Enqueue ( AttitudeCommand . Off ( ) , true , true , true ) ;
5380 return true ;
5481 }
5582
56- public static ManeuverCommand WithNode ( ManeuverNode node )
83+ public static ManeuverCommand WithNode ( ManeuverNode node , FlightComputer f )
5784 {
85+ double thrust = FlightCore . GetTotalThrust ( f . Vessel ) ;
86+ double advance = f . Delay ;
87+
88+ if ( thrust > 0 ) {
89+ advance += ( node . DeltaV . magnitude / ( thrust / f . Vessel . GetTotalMass ( ) ) ) / 2 ;
90+ }
91+
5892 var newNode = new ManeuverCommand ( )
5993 {
6094 Node = new ManeuverNode ( )
@@ -67,7 +101,7 @@ public static ManeuverCommand WithNode(ManeuverNode node)
67101 UT = node . UT ,
68102 nodeRotation = node . nodeRotation ,
69103 } ,
70- TimeStamp = node . UT ,
104+ TimeStamp = node . UT - advance ,
71105 } ;
72106 return newNode ;
73107 }
0 commit comments