@@ -11,6 +11,8 @@ public class PersistentEngine : PartModule {
1111 // Flag to activate force if it isn't to allow overriding stage activation
1212 [ KSPField ( isPersistant = true ) ]
1313 bool IsForceActivated ;
14+ // Flag if using PersistentEngine features
15+ public bool IsPersistentEngine = false ;
1416 // Flag whether to request massless resources
1517 public bool RequestPropMassless = false ;
1618 // Flag whether to request resources with mass
@@ -54,6 +56,7 @@ void FindModuleEngines () {
5456 foreach ( PartModule pm in part . Modules ) {
5557 if ( pm is ModuleEngines ) {
5658 engine = pm as ModuleEngines ;
59+ IsPersistentEngine = true ;
5760 } else {
5861 Debug . Log ( "No ModuleEngine found." ) ;
5962 }
@@ -66,27 +69,30 @@ void FindModuleEngines () {
6669 // Update
6770 public override void OnUpdate ( ) {
6871
69- // When transitioning from timewarp to real update throttle
70- if ( warpToReal ) {
71- vessel . ctrlState . mainThrottle = ThrottlePersistent ;
72- warpToReal = false ;
73- }
74-
75- // Persistent thrust GUI
76- Fields [ "Thrust" ] . guiActive = isEnabled ;
77- Fields [ "Isp" ] . guiActive = isEnabled ;
78- Fields [ "Throttle" ] . guiActive = isEnabled ;
79-
80- // Update display values
81- Thrust = Utils . FormatThrust ( thrust_d ) ;
82- Isp = Math . Round ( isp_d , 2 ) . ToString ( ) + " s" ;
83- Throttle = Math . Round ( throttle_d * 100 ) . ToString ( ) + "%" ;
84-
85- // Activate force if engine is enabled and operational
86- if ( ! IsForceActivated && engine . isEnabled && engine . isOperational )
87- {
88- IsForceActivated = true ;
89- part . force_activate ( ) ;
72+ if ( IsPersistentEngine ) {
73+
74+ // When transitioning from timewarp to real update throttle
75+ if ( warpToReal ) {
76+ vessel . ctrlState . mainThrottle = ThrottlePersistent ;
77+ warpToReal = false ;
78+ }
79+
80+ // Persistent thrust GUI
81+ Fields [ "Thrust" ] . guiActive = isEnabled ;
82+ Fields [ "Isp" ] . guiActive = isEnabled ;
83+ Fields [ "Throttle" ] . guiActive = isEnabled ;
84+
85+ // Update display values
86+ Thrust = Utils . FormatThrust ( thrust_d ) ;
87+ Isp = Math . Round ( isp_d , 2 ) . ToString ( ) + " s" ;
88+ Throttle = Math . Round ( throttle_d * 100 ) . ToString ( ) + "%" ;
89+
90+ // Activate force if engine is enabled and operational
91+ if ( ! IsForceActivated && engine . isEnabled && engine . isOperational )
92+ {
93+ IsForceActivated = true ;
94+ part . force_activate ( ) ;
95+ }
9096 }
9197 }
9298
@@ -98,12 +104,15 @@ public override void OnLoad(ConfigNode node) {
98104
99105 // Populate engine and engineFX fields
100106 FindModuleEngines ( ) ;
101-
102- // Initialize PersistentPropellant list
103- pplist = PersistentPropellant . MakeList ( engine . propellants ) ;
104107
105- // Initialize density of propellant used in deltaV and mass calculations
106- densityAverage = pplist . AverageDensity ( ) ;
108+ if ( IsPersistentEngine ) {
109+
110+ // Initialize PersistentPropellant list
111+ pplist = PersistentPropellant . MakeList ( engine . propellants ) ;
112+
113+ // Initialize density of propellant used in deltaV and mass calculations
114+ densityAverage = pplist . AverageDensity ( ) ;
115+ }
107116 }
108117
109118 void UpdatePersistentParameters ( ) {
@@ -176,7 +185,7 @@ public virtual Vector3d CalculateDeltaVV (double m0, double dT, float thrust, fl
176185
177186 // Physics update
178187 public override void OnFixedUpdate ( ) {
179- if ( FlightGlobals . fetch != null && isEnabled ) {
188+ if ( IsPersistentEngine && FlightGlobals . fetch != null && isEnabled ) {
180189 // Time step size
181190 var dT = TimeWarp . fixedDeltaTime ;
182191
0 commit comments