Changed conversions of Isp to exhaust velocity using 9.82
Changed conversions of Isp to exhaust velocity using 9.82

--- a/Documents/CHANGES.txt
+++ b/Documents/CHANGES.txt
@@ -1,4 +1,22 @@
-1.0.11.0
+1.0.11.3, 11-11-2014
+    Changed: Gravity measurements for Isp to 9.82.
+
+1.0.11.2, 10-11-2014
+    Changed: Gravity measurements for Isp calculations from 9.81 to 9.8066 for accuracy.
+    Changed: Manoeuvre node burn times are now more accurate.
+    Fixed: Bug in the manoeuvre node burn time calculations where it was not averaging acceleration correctly.
+
+1.0.11.1, 07-11-2014
+    Changed: Build Engineer now shows stage part count as well as total.
+    Changed: Build Overlay Vessel tab data:
+        DeltaV: stage / total
+        Mass:   stage / total
+        TWR:    start (max)   <- shows for bottom stage only.
+        Parts:  stage / total
+
+    Fixed: Issue with the vessel tab vanishing from the editor.
+
+1.0.11.0, 06-11-2014
     Added: New readouts to the orbital category:
         - Current SOI
         - Manoeuvre Node DeltaV (Prograde)

--- a/KerbalEngineer/Editor/BuildAdvanced.cs
+++ b/KerbalEngineer/Editor/BuildAdvanced.cs
@@ -451,7 +451,7 @@
             {
                 if (this.showAllStages || stage.deltaV > 0)
                 {
-                    GUILayout.Label(stage.partCount.ToString("N0"), this.infoStyle);
+                    GUILayout.Label(stage.partCount + " / " + stage.totalPartCount, this.infoStyle);
                 }
             }
             GUILayout.EndVertical();

--- a/KerbalEngineer/Editor/BuildOverlayResources.cs
+++ b/KerbalEngineer/Editor/BuildOverlayResources.cs
@@ -70,7 +70,7 @@
         {
             try
             {
-                if (!BuildOverlay.Visible || this.resources.Count == 0 || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts)
+                if (!Visible || this.resources.Count == 0 || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts)
                 {
                     return;
                 }
@@ -104,7 +104,7 @@
         {
             try
             {
-                if (!BuildOverlay.Visible)
+                if (!Visible)
                 {
                     return;
                 }

--- a/KerbalEngineer/Editor/BuildOverlayVessel.cs
+++ b/KerbalEngineer/Editor/BuildOverlayVessel.cs
@@ -22,7 +22,7 @@
 using System;
 using System.Collections.Generic;
 
-using KerbalEngineer.Extensions;
+using KerbalEngineer.Helpers;
 using KerbalEngineer.VesselSimulator;
 
 using UnityEngine;
@@ -33,6 +33,12 @@
 {
     public class BuildOverlayVessel : MonoBehaviour
     {
+        #region Constants
+
+        private const float Width = 175.0f;
+
+        #endregion
+
         #region Fields
 
         private static bool visible = true;
@@ -45,7 +51,7 @@
         private GUIContent tabContent;
         private Rect tabPosition;
         private Vector2 tabSize;
-        private Rect windowPosition = new Rect(300.0f, 0.0f, BuildOverlay.MinimumWidth, 0.0f);
+        private Rect windowPosition = new Rect(300.0f, 0.0f, Width, 0.0f);
 
         #endregion
 
@@ -76,7 +82,7 @@
         {
             try
             {
-                if (!Visible || EditorLogic.startPod == null || this.lastStage == null || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts)
+                if (!Visible || EditorLogic.startPod == null || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts)
                 {
                     return;
                 }
@@ -110,7 +116,7 @@
         {
             try
             {
-                if (!BuildOverlay.Visible || EditorLogic.startPod == null)
+                if (!Visible || EditorLogic.startPod == null)
                 {
                     return;
                 }
@@ -144,6 +150,10 @@
             }
 
             this.windowPosition.y = Mathf.Lerp(Screen.height, Screen.height - this.windowPosition.height, this.openPercent);
+            if (this.windowPosition.width < Width)
+            {
+                this.windowPosition.width = Width;
+            }
             this.tabPosition.width = this.tabSize.x;
             this.tabPosition.height = this.tabSize.y;
             this.tabPosition.x = this.windowPosition.x;
@@ -174,10 +184,10 @@
             if (this.lastStage != null)
             {
                 this.infoItems.Clear();
-                this.infoItems.Add(new PartInfoItem("Delta-V", this.lastStage.totalDeltaV.ToString("N0") + "m/s"));
-                this.infoItems.Add(new PartInfoItem("Mass", this.lastStage.totalMass.ToMass()));
-                this.infoItems.Add(new PartInfoItem("TWR", this.lastStage.thrustToWeight.ToString("F2")));
-                this.infoItems.Add(new PartInfoItem("Parts", this.lastStage.partCount.ToString("N0")));
+                this.infoItems.Add(new PartInfoItem("Delta-V", this.lastStage.deltaV.ToString("N0") + " / " + this.lastStage.totalDeltaV.ToString("N0") + "m/s"));
+                this.infoItems.Add(new PartInfoItem("Mass", Units.ToMass(this.lastStage.mass, this.lastStage.totalMass)));
+                this.infoItems.Add(new PartInfoItem("TWR", this.lastStage.thrustToWeight.ToString("F2") + " (" + this.lastStage.maxThrustToWeight.ToString("F2") + ")"));
+                this.infoItems.Add(new PartInfoItem("Parts", this.lastStage.partCount + " / " + this.lastStage.totalPartCount));
             }
         }
 
@@ -198,7 +208,7 @@
                     if (item.Value != null)
                     {
                         GUILayout.Label(item.Name + ":", BuildOverlay.NameStyle);
-                        GUILayout.Space(50.0f);
+                        GUILayout.FlexibleSpace();
                         GUILayout.Label(item.Value, BuildOverlay.ValueStyle);
                     }
                     else

--- a/KerbalEngineer/EngineerGlobals.cs
+++ b/KerbalEngineer/EngineerGlobals.cs
@@ -33,7 +33,7 @@
         /// <summary>
         ///     Current version of the Kerbal Engineer assembly.
         /// </summary>
-        public const string AssemblyVersion = "1.0.11";
+        public const string AssemblyVersion = "1.0.11.3";
 
         #endregion
 

--- a/KerbalEngineer/Extensions/DoubleExtensions.cs
+++ b/KerbalEngineer/Extensions/DoubleExtensions.cs
@@ -28,6 +28,11 @@
     public static class DoubleExtensions
     {
         #region Methods: public
+
+        public static double Clamp(this double value, double lower, double higher)
+        {
+            return value < lower ? lower : value > higher ? higher : value;
+        }
 
         public static string ToAcceleration(this double value)
         {

--- a/KerbalEngineer/Flight/Readouts/Orbital/ManoeuvreNode/ManoeuvreProcessor.cs
+++ b/KerbalEngineer/Flight/Readouts/Orbital/ManoeuvreNode/ManoeuvreProcessor.cs
@@ -47,6 +47,7 @@
         public static double AvailableDeltaV { get; private set; }
 
         public static double BurnTime { get; private set; }
+
         public static int FinalStage { get; private set; }
 
         public static double HalfBurnTime { get; private set; }
@@ -110,7 +111,7 @@
 
             var burnTime = 0.0;
             var midPointTime = 0.0;
-            HasDeltaV = GetBurnTime((float)TotalDeltaV, ref burnTime, ref midPointTime);
+            HasDeltaV = GetBurnTime(TotalDeltaV, ref burnTime, ref midPointTime);
             AvailableDeltaV = SimulationProcessor.LastStage.totalDeltaV;
 
             BurnTime = burnTime;
@@ -123,47 +124,50 @@
 
         #region Methods: private
 
-        private static bool GetBurnTime(float deltaV, ref double burnTime, ref double midPointTime)
+        private static bool GetBurnTime(double deltaV, ref double burnTime, ref double midPointTime)
         {
             var setMidPoint = false;
-            var deltaVMidPoint = deltaV * 0.5f;
+            var deltaVMidPoint = deltaV * 0.5;
 
-            for (var i = SimulationProcessor.Stages.Length - 1; i >= 0; i--)
+            for (var i = SimulationProcessor.Stages.Length - 1; i > -1; i--)
             {
                 var stage = SimulationProcessor.Stages[i];
-                var stageDeltaV = (float)stage.deltaV;
+                var stageDeltaV = stage.deltaV;
+                var startMass = stage.totalMass;
 
                 ProcessStageDrain:
-                if (deltaV <= Single.Epsilon)
+                if (deltaV <= Double.Epsilon)
                 {
-                    FinalStage = ++i;
-                    return true;
+                    break;
                 }
-                if (stageDeltaV <= Single.Epsilon)
+                if (stageDeltaV <= Double.Epsilon)
                 {
                     continue;
                 }
 
-                float deltaVDrain;
+                FinalStage = i;
+
+                double deltaVDrain;
                 if (deltaVMidPoint > 0.0)
                 {
-                    deltaVDrain = Mathf.Clamp(deltaV, 0.0f, Mathf.Clamp(deltaVMidPoint, 0.0f, stageDeltaV));
+                    deltaVDrain = deltaV.Clamp(0.0, stageDeltaV.Clamp(0.0, deltaVMidPoint));
                     deltaVMidPoint -= deltaVDrain;
-                    setMidPoint = deltaVMidPoint <= Single.Epsilon;
+                    setMidPoint = deltaVMidPoint <= Double.Epsilon;
                 }
                 else
                 {
-                    deltaVDrain = Mathf.Clamp(deltaV, 0.0f, stageDeltaV);
+                    deltaVDrain = deltaV.Clamp(0.0, stageDeltaV);
                 }
 
-                var startMass = stage.totalMass - (stage.resourceMass * (1.0f - (stageDeltaV / stage.deltaV)));
-                var endMass = startMass - (stage.resourceMass * (deltaVDrain / stageDeltaV));
-                var minimumAcceleration = stage.thrust / startMass;
-                var maximumAcceleration = stage.thrust / endMass;
+                var exhaustVelocity = stage.isp * 9.82;
+                var flowRate = stage.thrust / exhaustVelocity;
+                var endMass = Math.Exp(Math.Log(startMass) - deltaVDrain / exhaustVelocity);
+                var deltaMass = (startMass - endMass) * Math.Exp(-(deltaVDrain * 0.001) / exhaustVelocity);
+                burnTime += deltaMass / flowRate;
 
-                burnTime += deltaVDrain / ((minimumAcceleration + maximumAcceleration) * 0.5);
                 deltaV -= deltaVDrain;
                 stageDeltaV -= deltaVDrain;
+                startMass -= deltaMass;
 
                 if (setMidPoint)
                 {
@@ -172,7 +176,7 @@
                     goto ProcessStageDrain;
                 }
             }
-            return false;
+            return deltaV <= Double.Epsilon;
         }
 
         #endregion

--- a/KerbalEngineer/VesselSimulator/EngineSim.cs
+++ b/KerbalEngineer/VesselSimulator/EngineSim.cs
@@ -116,14 +116,14 @@
                 if (throttleLocked)
                 {
                     //MonoBehaviour.print("throttleLocked is true");
-                    flowRate = this.thrust / (this.isp * 9.81d);
+                    flowRate = this.thrust / (this.isp * 9.82);
                 }
                 else
                 {
                     if (this.partSim.isLanded)
                     {
                         //MonoBehaviour.print("partSim.isLanded is true, mainThrottle = " + FlightInputHandler.state.mainThrottle);
-                        flowRate = Math.Max(0.000001d, this.thrust * FlightInputHandler.state.mainThrottle) / (this.isp * 9.81d);
+                        flowRate = Math.Max(0.000001d, this.thrust * FlightInputHandler.state.mainThrottle) / (this.isp * 9.82);
                     }
                     else
                     {
@@ -136,12 +136,12 @@
                             }
 
                             //MonoBehaviour.print("requestedThrust > 0");
-                            flowRate = requestedThrust / (this.isp * 9.81d);
+                            flowRate = requestedThrust / (this.isp * 9.82);
                         }
                         else
                         {
                             //MonoBehaviour.print("requestedThrust <= 0");
-                            flowRate = this.thrust / (this.isp * 9.81d);
+                            flowRate = this.thrust / (this.isp * 9.82);
                         }
                     }
                 }
@@ -174,7 +174,7 @@
                     //MonoBehaviour.print("thrust at velocity = " + thrust);
                 }
 
-                flowRate = this.thrust / (this.isp * 9.81d);
+                flowRate = this.thrust / (this.isp * 9.82);
             }
 
             if (SimManager.logOutput)

--- a/KerbalEngineer/VesselSimulator/Simulation.cs
+++ b/KerbalEngineer/VesselSimulator/Simulation.cs
@@ -32,8 +32,8 @@
 {
     public class Simulation
     {
-        private const double STD_GRAVITY = 9.81d;
-        private const double SECONDS_PER_DAY = 86400d;
+        private const double STD_GRAVITY = 9.82;
+        private const double SECONDS_PER_DAY = 86400;
         private readonly Stopwatch _timer = new Stopwatch();
         private List<EngineSim> activeEngines;
         private List<EngineSim> allEngines;
@@ -512,7 +512,7 @@
                 // Zero stage time if more than a day (this should be moved into the window code)
                 stage.time = (this.stageTime < SECONDS_PER_DAY) ? this.stageTime : 0d;
                 stage.number = this.doingCurrent ? -1 : this.currentStage; // Set the stage number to -1 if doing current engines
-                stage.partCount = this.allParts.Count;
+                stage.totalPartCount = this.allParts.Count;
                 stages[this.currentStage] = stage;
 
                 // Now activate the next stage
@@ -550,6 +550,7 @@
                     stages[i].totalMass += stages[j].mass;
                     stages[i].totalDeltaV += stages[j].deltaV;
                     stages[i].totalTime += stages[j].time;
+                    stages[i].partCount = i > 0 ? stages[i].totalPartCount - stages[i - 1].totalPartCount : stages[i].totalPartCount;
                 }
                 // We also total up the deltaV for stage and all stages below
                 for (int j = i; j < stages.Length; j++)

--- a/KerbalEngineer/VesselSimulator/Stage.cs
+++ b/KerbalEngineer/VesselSimulator/Stage.cs
@@ -45,6 +45,7 @@
         public double totalDeltaV = 0f;
         public double totalMass = 0f;
         public double totalTime = 0f;
+        public int totalPartCount = 0;
         public int partCount = 0;
         public double resourceMass = 0.0;
 

 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ
--- a/Output/KerbalEngineer/KerbalEngineer.version
+++ b/Output/KerbalEngineer/KerbalEngineer.version
@@ -6,7 +6,7 @@
 		"MAJOR":1,
 		"MINOR":0,
 		"PATCH":11,
-		"BUILD":0
+		"BUILD":3
 	},
 	"KSP_VERSION":
 	{