Refactored creation of EngineSim objects to avoid passing 20 params to a function.
Refactored creation of EngineSim objects to avoid passing 20 params to a function.

--- a/KerbalEngineer/VesselSimulator/EngineSim.cs
+++ b/KerbalEngineer/VesselSimulator/EngineSim.cs
@@ -72,26 +72,30 @@
         }
 
         public static EngineSim New(PartSim theEngine,
-                         double atmosphere,
-                         float machNumber,
-                         float maxFuelFlow,
-                         float minFuelFlow,
-                         float thrustPercentage,
-                         Vector3 vecThrust,
-                         FloatCurve atmosphereCurve,
-                         bool atmChangeFlow,
-                         FloatCurve atmCurve,
-                         FloatCurve velCurve,
-                         float currentThrottle,
-                         float IspG,
-                         bool throttleLocked,
-                         List<Propellant> propellants,
-                         bool active,
-                         float resultingThrust,
-                         List<Transform> thrustTransforms,
-                        LogMsg log)
-        {
-            EngineSim engineSim = pool.Borrow();
+									ModuleEngines engineMod,
+									double atmosphere,
+									float machNumber,
+									bool vectoredThrust,
+									bool fullThrust,
+									LogMsg log)
+        {
+            float maxFuelFlow = engineMod.maxFuelFlow;
+            float minFuelFlow = engineMod.minFuelFlow;
+            float thrustPercentage = engineMod.thrustPercentage;
+            Vector3 vecThrust = CalculateThrustVector(vectoredThrust ? engineMod.thrustTransforms : null, log);
+            FloatCurve atmosphereCurve = engineMod.atmosphereCurve;
+            bool atmChangeFlow = engineMod.atmChangeFlow;
+            FloatCurve atmCurve = engineMod.useAtmCurve ? engineMod.atmCurve : null;
+            FloatCurve velCurve = engineMod.useVelCurve ? engineMod.velCurve : null;
+            float currentThrottle = engineMod.currentThrottle;
+            float IspG = engineMod.g;
+            bool throttleLocked = engineMod.throttleLocked || fullThrust;
+            List<Propellant> propellants = engineMod.propellants;
+            bool active = engineMod.isOperational;
+            float resultingThrust = engineMod.resultingThrust;
+            List<Transform> thrustTransforms = engineMod.thrustTransforms;
+			
+			EngineSim engineSim = pool.Borrow();
 
             engineSim.isp = 0.0;
             engineSim.maxMach = 0.0f;
@@ -120,7 +124,7 @@
                     log.buf.AppendFormat("actual  = {0:g6}\n", engineSim.actualThrust);
                 }
 
-                if (throttleLocked)
+				if (throttleLocked)
                 {
                     if (log != null) log.buf.AppendLine("throttleLocked is true, using thrust for flowRate");
                     flowRate = GetFlowRate(engineSim.thrust, engineSim.isp);
@@ -129,7 +133,8 @@
                 {
                     if (currentThrottle > 0.0f && engineSim.partSim.isLanded == false)
                     {
-                        if (log != null) log.buf.AppendLine("throttled up and not landed, using actualThrust for flowRate");
+						// TODO: This bit doesn't work for RF engines
+						if (log != null) log.buf.AppendLine("throttled up and not landed, using actualThrust for flowRate");
                         flowRate = GetFlowRate(engineSim.actualThrust, engineSim.isp);
                     }
                     else
@@ -203,6 +208,32 @@
 
             return engineSim;
         }
+
+		private static Vector3 CalculateThrustVector(List<Transform> thrustTransforms, LogMsg log)
+		{
+			if (thrustTransforms == null)
+			{
+				return Vector3.forward;
+			}
+
+			Vector3 thrustvec = Vector3.zero;
+			for (int i = 0; i < thrustTransforms.Count; ++i)
+			{
+				Transform trans = thrustTransforms[i];
+
+				if (log != null) log.buf.AppendFormat("Transform = ({0:g6}, {1:g6}, {2:g6})   length = {3:g6}\n", trans.forward.x, trans.forward.y, trans.forward.z, trans.forward.magnitude);
+
+				thrustvec -= trans.forward;
+			}
+
+			if (log != null) log.buf.AppendFormat("ThrustVec  = ({0:g6}, {1:g6}, {2:g6})   length = {3:g6}\n", thrustvec.x, thrustvec.y, thrustvec.z, thrustvec.magnitude);
+
+			thrustvec.Normalize();
+
+			if (log != null) log.buf.AppendFormat("ThrustVecN = ({0:g6}, {1:g6}, {2:g6})   length = {3:g6}\n", thrustvec.x, thrustvec.y, thrustvec.z, thrustvec.magnitude);
+
+			return thrustvec;
+		}
 
         public ResourceContainer ResourceConsumptions
         {

--- a/KerbalEngineer/VesselSimulator/PartSim.cs
+++ b/KerbalEngineer/VesselSimulator/PartSim.cs
@@ -234,27 +234,13 @@
                     {
                         if (log != null) log.buf.AppendLine("Module: " + engine.moduleName);
 
-                        Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
-
                         EngineSim engineSim = EngineSim.New(
                             this,
-                            atmosphere,
+							engine,
+							atmosphere,
                             (float)mach,
-                            engine.maxFuelFlow,
-                            engine.minFuelFlow,
-                            engine.thrustPercentage,
-                            thrustvec,
-                            engine.atmosphereCurve,
-                            engine.atmChangeFlow,
-                            engine.useAtmCurve ? engine.atmCurve : null,
-                            engine.useVelCurve ? engine.velCurve : null,
-                            engine.currentThrottle,
-                            engine.g,
-                            engine.throttleLocked || fullThrust,
-                            engine.propellants,
-                            engine.isOperational,
-                            engine.resultingThrust,
-                            engine.thrustTransforms,
+							vectoredThrust,
+							fullThrust,
                             log);
                         allEngines.Add(engineSim);
                     }
@@ -268,28 +254,14 @@
                     ModuleEngines engine = engines[i];
                     if (log != null) log.buf.AppendLine("Module: " + engine.moduleName);
 
-                    Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
-
                     EngineSim engineSim = EngineSim.New(
                         this,
+						engine,
                         atmosphere,
                         (float)mach,
-                        engine.maxFuelFlow,
-                        engine.minFuelFlow,
-                        engine.thrustPercentage,
-                        thrustvec,
-                        engine.atmosphereCurve,
-                        engine.atmChangeFlow,
-                        engine.useAtmCurve ? engine.atmCurve : null,
-                        engine.useVelCurve ? engine.velCurve : null,
-                        engine.currentThrottle,
-                        engine.g,
-                        engine.throttleLocked || fullThrust,
-                        engine.propellants,
-                        engine.isOperational,
-                        engine.resultingThrust,
-                        engine.thrustTransforms,
-                        log);
+						vectoredThrust,
+						fullThrust,
+						log);
                     allEngines.Add(engineSim);
                 }
             }