66
77namespace PersistentThrust {
88
9- public class PersistentEngine : ModuleEnginesFX {
9+ public class PersistentEngine : PartModule {
1010
1111 // Flag to activate force if it isn't to allow overriding stage activation
1212 [ KSPField ( isPersistant = true ) ]
@@ -26,6 +26,10 @@ public class PersistentEngine : ModuleEnginesFX {
2626 // Throttle
2727 [ KSPField ( guiActive = true , guiName = "Throttle" ) ]
2828 protected string Throttle = "" ;
29+
30+ // Engine module on the same part
31+ public ModuleEngines engine ;
32+ ModuleEnginesFX engineFX ;
2933
3034 // Numeric display values
3135 protected double thrust_d = 0 ;
@@ -45,6 +49,20 @@ public class PersistentEngine : ModuleEnginesFX {
4549 // Average density of propellants
4650 public double densityAverage ;
4751
52+ // Make "engine" and "engineFX" fields refer to the ModuleEngines and ModuleEnginesFX modules in part.Modules
53+ void FindModuleEngines ( ) {
54+ foreach ( PartModule pm in part . Modules ) {
55+ if ( pm is ModuleEngines ) {
56+ engine = pm as ModuleEngines ;
57+ } else {
58+ Debug . Log ( "No ModuleEngine found." ) ;
59+ }
60+ if ( pm is ModuleEnginesFX ) {
61+ engineFX = pm as ModuleEnginesFX ;
62+ }
63+ }
64+ }
65+
4866 // Update
4967 public override void OnUpdate ( ) {
5068
@@ -65,7 +83,7 @@ public override void OnUpdate() {
6583 Throttle = Math . Round ( throttle_d * 100 ) . ToString ( ) + "%" ;
6684
6785 // Activate force if engine is enabled and operational
68- if ( ! IsForceActivated && isEnabled && isOperational )
86+ if ( ! IsForceActivated && engine . isEnabled && engine . isOperational )
6987 {
7088 IsForceActivated = true ;
7189 part . force_activate ( ) ;
@@ -78,8 +96,11 @@ public override void OnLoad(ConfigNode node) {
7896 // Run base OnLoad method
7997 base . OnLoad ( node ) ;
8098
99+ // Populate engine and engineFX fields
100+ FindModuleEngines ( ) ;
101+
81102 // Initialize PersistentPropellant list
82- pplist = PersistentPropellant . MakeList ( propellants ) ;
103+ pplist = PersistentPropellant . MakeList ( engine . propellants ) ;
83104
84105 // Initialize density of propellant used in deltaV and mass calculations
85106 densityAverage = pplist . AverageDensity ( ) ;
@@ -88,13 +109,13 @@ public override void OnLoad(ConfigNode node) {
88109 void UpdatePersistentParameters ( ) {
89110 // Update values to use during timewarp
90111 // Update thrust calculation
91- this . CalculateThrust ( ) ;
112+ engine . CalculateThrust ( ) ;
92113 // Get Isp
93- IspPersistent = realIsp ;
114+ IspPersistent = engine . realIsp ;
94115 // Get throttle
95116 ThrottlePersistent = vessel . ctrlState . mainThrottle ;
96117 // Get final thrust
97- ThrustPersistent = this . finalThrust ;
118+ ThrustPersistent = engine . finalThrust ;
98119 }
99120
100121 // Calculate demands of each resource
0 commit comments