Updates to work with new, stub-ified, VesselSimulator.
Updates to work with new, stub-ified, VesselSimulator.

file:b/API/Enums.cs (new)
--- /dev/null
+++ b/API/Enums.cs
@@ -1,1 +1,25 @@
+// VOID © 2015 toadicus
+//
+// This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a
+// copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
+using System;
 
+namespace VOID
+{
+	public enum VOID_TimeScale : UInt32
+	{
+		KERBIN_TIME = 1, // Earth if 0
+		SOLAR_DAY = 4, // Sidereal if 0
+		ROUNDED_SCALE = 1024 // Real values if 0
+	}
+
+	public enum IconState : UInt32
+	{
+		PowerOff = 1,
+		PowerOn = 2,
+		Inactive = 4,
+		Active = 8
+	}
+}
+
+

--- a/API/VOIDCore.cs
+++ b/API/VOIDCore.cs
@@ -64,6 +64,8 @@
 		public abstract Stage LastStage { get; protected set; }
 		public abstract Stage[] Stages { get; protected set; }
 
+		public abstract VOID_TimeScale TimeScale { get; protected set; }
+
 		public abstract event VOIDEventHandler onApplicationQuit;
 		public abstract event VOIDEventHandler onSkinChanged;
 

--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs
@@ -39,7 +39,7 @@
 // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
 // The form "{Major}.{Minor}.*" will automatically update the build and revision,
 // and "{Major}.{Minor}.{Build}.*" will update just the revision.
-[assembly: AssemblyVersion("0.16.4.*")]
+[assembly: AssemblyVersion("0.17.1.*")]
 // The following attributes are used to specify the signing key for the assembly,
 // if desired. See the Mono documentation for more information about signing.
 //[assembly: AssemblyDelaySign(false)]

--- a/Tools/VOID_DataValue.cs
+++ b/Tools/VOID_DataValue.cs
@@ -229,7 +229,7 @@
 		}
 		
 		public virtual string ValueUnitString(int digits) {
-			return Tools.MuMech_ToSI(this, digits) + this.Units;
+			return string.Format("{0}{1}", SIFormatProvider.ToSI(this, digits), Units);
 		}
 
 		public virtual string ValueUnitString(int digits, int MinMagnitude, int MaxMagnitude)
@@ -264,26 +264,17 @@
 
 		public virtual int DoGUIHorizontalPrec(int digits)
 		{
-			double magnitude;
-			double magLimit;
-
-			magnitude = Math.Log10(Math.Abs((double)this));
-
-			magLimit = Math.Max(Math.Abs(magnitude), 3d) + 3d;
-			magLimit = Math.Round(Math.Ceiling(magLimit / 3f)) * 3d;
+			if (digits < 0 || digits > 8)
+			{
+				digits = 5;
+			}
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			GUILayout.Label(this.Label + "ⁱ:", GUILayout.ExpandWidth(true));
 			GUILayout.FlexibleSpace();
 
-			if (magnitude >= 0)
-			{
-				GUILayout.Label(this.ValueUnitString(3, int.MinValue, (int)magnitude - digits), GUILayout.ExpandWidth(false));
-			}
-			else
-			{
-				GUILayout.Label(this.ValueUnitString(3, (int)magnitude + digits, int.MaxValue), GUILayout.ExpandWidth(false));
-			}
+			GUILayout.Label(this.ValueUnitString(digits), GUILayout.ExpandWidth(false));
+
 			GUILayout.EndHorizontal();
 
 			if (Event.current.type == EventType.mouseUp)
@@ -291,33 +282,28 @@
 				Rect lastRect = GUILayoutUtility.GetLastRect();
 				if (lastRect.Contains(Event.current.mousePosition))
 				{
-					Tools.PostDebugMessage(string.Format("{0}: Changing digits from {1} within magLimit {2}.",
+					Tools.PostDebugMessage(string.Format("{0}: Changing digits from {1}",
 						this.GetType().Name,
-						digits,
-						magLimit));
+						digits
+					));
 
 					if (Event.current.button == 0)
 					{
-						digits = (digits + 3) % (int)magLimit;
+						digits = (digits + 3) % 9;
 					}
 					else if (Event.current.button == 1)
 					{
-						digits = (digits - 3) % (int)magLimit;
+						digits = (digits - 3) % 9;
 					}
 
 					if (digits < 0)
 					{
-						digits += (int)magLimit;
+						digits += 9;
 					}
 
-					Tools.PostDebugMessage(string.Format("{0}: Changed digits to {1}." +
-						"\n\tNew minMagnitude: {2}, maxMagnitude: {3}" +
-						"\n\tMagnitude: {4}",
+					Tools.PostDebugMessage(string.Format("{0}: Changed digits to {1}.",
 						this.GetType().Name,
-						digits,
-						magnitude >= 0 ? int.MinValue : (int)magnitude - 4 + digits,
-						magnitude >= 0 ? (int)magnitude - digits : int.MaxValue,
-						magnitude
+						digits
 					));
 				}
 			}

--- a/Tools/VOID_Tools.cs
+++ b/Tools/VOID_Tools.cs
@@ -414,28 +414,55 @@
 			{
 				get
 				{
-					if (GameSettings.KERBIN_TIME)
+					VOID_TimeScale flags = VOID_Data.Core.TimeScale &
+						(VOID_TimeScale.KERBIN_TIME | VOID_TimeScale.SOLAR_DAY | VOID_TimeScale.ROUNDED_SCALE);
+
+					switch (flags)
 					{
-						return 21600d;
+						// Earth day, sidereal
+						case 0:
+							return 86164.1d;
+						// Earth day, solar (also rounded)
+						case VOID_TimeScale.ROUNDED_SCALE | VOID_TimeScale.SOLAR_DAY:
+						case VOID_TimeScale.ROUNDED_SCALE:
+						case VOID_TimeScale.SOLAR_DAY:
+							return 86400d;
+						// Kerbin day, solar
+						case VOID_TimeScale.KERBIN_TIME | VOID_TimeScale.SOLAR_DAY:
+							return 21650.813d;
+						// Kerbin day, sidereal (also rounded)
+						default:
+							return 21600d;
 					}
-					else
+				}
+			}
+
+			public static double SecondsPerYear
+			{
+				get
+				{
+					VOID_TimeScale flags = VOID_Data.Core.TimeScale &
+						(VOID_TimeScale.KERBIN_TIME | VOID_TimeScale.SOLAR_DAY | VOID_TimeScale.ROUNDED_SCALE);
+
+					switch (flags)
 					{
-						return 86164.1d;
-					}
-				}
-			}
-
-			public static double SecondsPerYear
-			{
-				get
-				{
-					if (GameSettings.KERBIN_TIME)
-					{
-						return 9203545d;
-					}
-					else
-					{
-						return 31558149d;
+						// Earth year, rounded
+						case VOID_TimeScale.SOLAR_DAY | VOID_TimeScale.ROUNDED_SCALE:
+						case VOID_TimeScale.ROUNDED_SCALE:
+							return 60 * 60 * 24 * 365;
+						// Kerbin year, rounded
+						case VOID_TimeScale.KERBIN_TIME | VOID_TimeScale.SOLAR_DAY | VOID_TimeScale.ROUNDED_SCALE:
+						case VOID_TimeScale.KERBIN_TIME | VOID_TimeScale.ROUNDED_SCALE:
+							return 60 * 60 * 6 * 426;
+						// Earth year, solar time
+						case VOID_TimeScale.SOLAR_DAY:
+							return 31556925.2507328;
+						// Earth year, sidereal time
+						case 0:
+							return 31558149.7635456d;
+						// Kerbin year, solar & sidereal time
+						default:
+							return 9203544.61750141d;
 					}
 				}
 			}

--- a/VOID.csproj
+++ b/VOID.csproj
@@ -115,6 +115,7 @@
     <Compile Include="Tools\VOID_StageExtensions.cs" />
     <Compile Include="API\VOID_SingletonCore.cs" />
     <Compile Include="API\VOID_SingletonWindow.cs" />
+    <Compile Include="API\Enums.cs" />
   </ItemGroup>
   <ProjectExtensions>
     <MonoDevelop>

--- a/VOIDCore_Generic.cs
+++ b/VOIDCore_Generic.cs
@@ -26,6 +26,8 @@
 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+using KerbalEngineer.Editor;
+using KerbalEngineer.Helpers;
 using KerbalEngineer.VesselSimulator;
 using KSP;
 using System;
@@ -89,6 +91,9 @@
 
 		[AVOID_SaveValue("vesselSimActive")]
 		protected VOID_SaveValue<bool> vesselSimActive;
+
+		[AVOID_SaveValue("timeScaleFlags")]
+		protected VOID_SaveValue<UInt32> timeScaleFlags;
 
 		// Vessel Type Housekeeping
 		protected bool vesselTypesLoaded = false;
@@ -257,6 +262,18 @@
 			protected set;
 		}
 
+		public override VOID_TimeScale TimeScale
+		{
+			get
+			{
+				return (VOID_TimeScale)this.timeScaleFlags.value;
+			}
+			protected set
+			{
+				this.timeScaleFlags.value = (UInt32)value;
+			}
+		}
+
 		protected IconState activeState
 		{
 			get
@@ -597,6 +614,57 @@
 			this.vesselSimActive.value = GUITools.Toggle(this.vesselSimActive.value,
 				"Enable Engineering Calculations");
 
+			bool useEarthTime = (this.TimeScale & VOID_TimeScale.KERBIN_TIME) == 0u;
+			bool useSiderealTime = (this.TimeScale & VOID_TimeScale.SOLAR_DAY) == 0u;
+			bool useRoundedScale = (this.TimeScale & VOID_TimeScale.ROUNDED_SCALE) != 0u;
+
+			useEarthTime = GUITools.Toggle(useEarthTime, "Use Earth Time (changes KSP option)");
+
+			GameSettings.KERBIN_TIME = !useEarthTime;
+
+			useSiderealTime = GUITools.Toggle(
+				useSiderealTime,
+				string.Format(
+					"Time Scale: {0}",
+					useSiderealTime ? "Sidereal" : "Solar"
+				)
+			);
+
+			useRoundedScale = GUITools.Toggle(
+				useRoundedScale,
+				string.Format(
+					"Time Scale: {0}",
+					useRoundedScale ? "Rounded" : "True"
+				)
+			);
+
+			if (useEarthTime)
+			{
+				this.TimeScale &= ~VOID_TimeScale.KERBIN_TIME;
+			}
+			else
+			{
+				this.TimeScale |= VOID_TimeScale.KERBIN_TIME;
+			}
+
+			if (useSiderealTime)
+			{
+				this.TimeScale &= ~VOID_TimeScale.SOLAR_DAY;
+			}
+			else
+			{
+				this.TimeScale |= VOID_TimeScale.SOLAR_DAY;
+			}
+
+			if (useRoundedScale)
+			{
+				this.TimeScale |= VOID_TimeScale.ROUNDED_SCALE;
+			}
+			else
+			{
+				this.TimeScale &= ~VOID_TimeScale.ROUNDED_SCALE;
+			}
+
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 
 			GUILayout.Label("Skin:", GUILayout.ExpandWidth(false));
@@ -683,11 +751,22 @@
 				{
 					double radius = this.Vessel.Radius();
 					SimManager.Gravity = this.Vessel.mainBody.gravParameter / (radius * radius);
-				}
-
-				SimManager.minSimTime = new TimeSpan(0, 0, 0, 0, (int)(this.UpdatePeriod * 1000d));
+					SimManager.Atmosphere = this.Vessel.staticPressurekPa * PhysicsGlobals.KpaToAtmospheres;
+					SimManager.Mach = HighLogic.LoadedSceneIsEditor ? 1d :  this.Vessel.mach;
+					BuildAdvanced.Altitude = HighLogic.LoadedSceneIsEditor ? 0d : this.Vessel.altitude;
+					CelestialBodies.SelectedBody = HighLogic.LoadedSceneIsEditor ? this.HomeBody : this.Vessel.mainBody;
+				}
+
+				#if DEBUG
+				SimManager.logOutput = true;
+				#endif
 
 				SimManager.TryStartSimulation();
+
+				Tools.PostDebugMessage(this, "Started Engineer simulation with Atmosphere={0} atm and Gravity={1} m/s²",
+					SimManager.Atmosphere,
+					SimManager.Gravity
+				);
 			}
 			#if DEBUG
 			else
@@ -1038,6 +1117,8 @@
 			{
 				module.LoadConfig();
 			}
+
+			this.TimeScale |= GameSettings.KERBIN_TIME ? VOID_TimeScale.KERBIN_TIME : 0u;
 		}
 
 		public override void SaveConfig()
@@ -1119,14 +1200,6 @@
 			_instance = null;
 			_initialized = false;
 		}
-
-		protected enum IconState
-		{
-			PowerOff = 1,
-			PowerOn = 2,
-			Inactive = 4,
-			Active = 8
-		}
 	}
 }
 

--- a/VOID_CBInfoBrowser.cs
+++ b/VOID_CBInfoBrowser.cs
@@ -203,7 +203,7 @@
 				GUILayout.Label("Natural satellites:");
 				GUILayout.Label("Artificial satellites:");
 				GUILayout.Label("Surface gravity:");
-				GUILayout.Label("Atmosphere altitude:");
+				GUILayout.Label("Atmosphere Depth:");
 				GUILayout.Label("Atmospheric O\u2082:");
 				GUILayout.Label("Has ocean:");
 
@@ -393,7 +393,7 @@
 
 			if (body.atmosphere)
 			{
-				GUILayout.Label("≈ " + Tools.MuMech_ToSI(body.maxAtmosphereAltitude) + "m",
+				GUILayout.Label("≈ " + Tools.MuMech_ToSI(body.atmosphereDepth) + "m",
 					VOID_Styles.labelRight,
 					GUILayout.ExpandWidth(true));
 

--- a/VOID_Data.cs
+++ b/VOID_Data.cs
@@ -116,29 +116,29 @@
 		public static readonly VOID_DoubleValue atmDensity =
 			new VOID_DoubleValue(
 				"Atmosphere Density",
-				new Func<double>(() => Core.Vessel.atmDensity * 1000f),
+				new Func<double>(() => Core.Vessel.atmDensity * 1000d),
 				"g/m³"
 			);
 
-		public static readonly VOID_FloatValue atmLimit =
-			new VOID_FloatValue(
-				"Atmosphere Limit",
-				new Func<float>(() => Core.Vessel.mainBody.maxAtmosphereAltitude),
+		public static readonly VOID_DoubleValue atmLimit =
+			new VOID_DoubleValue(
+				"Atmosphere Depth",
+				new Func<double>(() => Core.Vessel.mainBody.atmosphereDepth),
 				"m"
 			);
 
 		public static readonly VOID_DoubleValue atmPressure =
 			new VOID_DoubleValue(
-				"Pressure",
-				new Func<double>(() => Core.Vessel.staticPressure),
-				"atm"
-			);
-
-		public static readonly VOID_FloatValue temperature =
-			new VOID_FloatValue(
+				"Static Pressure",
+				new Func<double>(() => Core.Vessel.staticPressurekPa * 1000d),
+				"Pa"
+			);
+
+		public static readonly VOID_DoubleValue temperature =
+			new VOID_DoubleValue(
 				"Temperature",
-				new Func<float>(() => Core.Vessel.flightIntegrator.getExternalTemperature()),
-				"°C"
+				new Func<double>(() => Core.Vessel.atmosphericTemperature),
+				"K"
 			);
 
 		#endregion
@@ -269,7 +269,7 @@
 						return double.NaN;
 					}
 
-					return Core.LastStage.totalMass - Core.LastStage.totalBaseMass;
+					return Core.LastStage.totalResourceMass;
 				},
 				"tons"
 			);
@@ -284,7 +284,7 @@
 						return double.NaN;
 					}
 
-					return Core.LastStage.mass - Core.LastStage.baseMass;
+					return Core.LastStage.resourceMass;
 				},
 				"tons"
 			);

--- a/VOID_DataLogger.cs
+++ b/VOID_DataLogger.cs
@@ -317,6 +317,8 @@
 					"\"Altitude above terrain (m)\"," +
 					"\"Surface Latitude (°)\"," +
 					"\"Surface Longitude (°)\"," +
+					"\"Apoapsis Altitude (m)\"," +
+					"\"Periapsis Altitude (m)\"," +
 					"\"Orbital Velocity (m/s)\"," +
 					"\"Surface Velocity (m/s)\"," +
 					"\"Vertical Speed (m/s)\"," +
@@ -358,6 +360,14 @@
 			line.Append('"');
 			line.Append(',');
 
+			// Apoapsis Altitude
+			line.Append(VOID_Data.orbitApoAlt.Value.ToString("G3"));
+			line.Append(',');
+
+			// Periapsis Altitude
+			line.Append(VOID_Data.oribtPeriAlt.Value.ToString("G3"));
+			line.Append(',');
+
 			//Orbital velocity
 			line.Append(VOID_Data.orbitVelocity.Value.ToString("F3"));
 			line.Append(',');

--- a/VOID_Orbital.cs
+++ b/VOID_Orbital.cs
@@ -39,7 +39,7 @@
 		protected VOID_SaveValue<bool> toggleExtended;
 
 		[AVOID_SaveValue("precisionValues")]
-		protected long _precisionValues;
+		protected VOID_SaveValue<long> _precisionValues;
 		protected IntCollection precisionValues;
 
 		public VOID_Orbital()
@@ -51,7 +51,7 @@
 
 			this.toggleExtended = (VOID_SaveValue<bool>)false;
 
-			this._precisionValues = 230584300921369395;
+			this._precisionValues = (VOID_SaveValue<long>)384307168202282325;
 		}
 
 		public override void ModuleWindow(int id)
@@ -125,7 +125,7 @@
 
 		public override void Save (KSP.IO.PluginConfiguration config)
 		{
-			this._precisionValues = this.precisionValues.collection;
+			this._precisionValues.value = this.precisionValues.collection;
 
 			base.Save (config);
 		}

--- a/VOID_StageInfo.cs
+++ b/VOID_StageInfo.cs
@@ -35,7 +35,7 @@
 
 		private bool showColumnSelection;
 
-		private CelestialBody selectedBody;
+		private CelestialBody _selectedBody;
 		[AVOID_SaveValue("bodyIdx")]
 		private VOID_SaveValue<int> bodyIdx;
 		private int lastIdx;
@@ -45,6 +45,19 @@
 		[AVOID_SaveValue("UseSealLevel")]
 		private VOID_SaveValue<bool> useSeaLevel;
 		private GUIContent seaLevelToggle;
+
+		private CelestialBody selectedBody
+		{
+			get
+			{
+				return this._selectedBody;
+			}
+			set
+			{
+				this._selectedBody = value;
+				KerbalEngineer.Helpers.CelestialBodies.SelectedBody = value;
+			}
+		}
 
 		public VOID_StageInfo() : base()
 		{
@@ -151,7 +164,7 @@
 
 			if (HighLogic.LoadedSceneIsEditor && this.selectedBody.atmosphere && this.useSeaLevel)
 			{
-				SimManager.Atmosphere = this.selectedBody.atmosphereMultiplier * 101.325d;
+				SimManager.Atmosphere = this.selectedBody.GetPressure(0) * PhysicsGlobals.KpaToAtmospheres;
 			}
 			else
 			{

--- a/VOID_SurfAtmo.cs
+++ b/VOID_SurfAtmo.cs
@@ -46,7 +46,7 @@
 			this.WindowPos.x = Screen.width - 260f;
 			this.WindowPos.y = 85;
 
-			this._precisionValues = (VOID_SaveValue<long>)230584300921369395;
+			this._precisionValues = (VOID_SaveValue<long>)384307168202282325;
 		}
 
 		public override void ModuleWindow(int id)
@@ -55,60 +55,61 @@
 
 			GUILayout.BeginVertical();
 
-			this.precisionValues [idx]= (ushort)VOID_Data.trueAltitude.DoGUIHorizontal (this.precisionValues [idx]);
+			this.precisionValues[idx] = (ushort)VOID_Data.trueAltitude.DoGUIHorizontal(this.precisionValues[idx]);
 			idx++;
 
-			VOID_Data.surfLatitude.DoGUIHorizontal ();
+			VOID_Data.surfLatitude.DoGUIHorizontal();
 
-			VOID_Data.surfLongitude.DoGUIHorizontal ();
+			VOID_Data.surfLongitude.DoGUIHorizontal();
 
-			VOID_Data.vesselHeading.DoGUIHorizontal ();
+			VOID_Data.vesselHeading.DoGUIHorizontal();
 
-			this.precisionValues [idx]= (ushort)VOID_Data.terrainElevation.DoGUIHorizontal (this.precisionValues [idx]);
+			this.precisionValues[idx] = (ushort)VOID_Data.terrainElevation.DoGUIHorizontal(this.precisionValues[idx]);
 			idx++;
 
 			this.precisionValues[idx] = (ushort)VOID_Data.downrangeDistance.DoGUIHorizontal(this.precisionValues[idx]);
 			idx++;
 
-			this.precisionValues [idx]= (ushort)VOID_Data.surfVelocity.DoGUIHorizontal (this.precisionValues [idx]);
+			this.precisionValues[idx] = (ushort)VOID_Data.surfVelocity.DoGUIHorizontal(this.precisionValues[idx]);
 			idx++;
 
-			this.precisionValues [idx]= (ushort)VOID_Data.vertVelocity.DoGUIHorizontal (this.precisionValues [idx]);
+			this.precisionValues[idx] = (ushort)VOID_Data.vertVelocity.DoGUIHorizontal(this.precisionValues[idx]);
 			idx++;
 
-			this.precisionValues [idx]= (ushort)VOID_Data.horzVelocity.DoGUIHorizontal (this.precisionValues [idx]);
+			this.precisionValues[idx] = (ushort)VOID_Data.horzVelocity.DoGUIHorizontal(this.precisionValues[idx]);
 			idx++;
 
-			VOID_Data.temperature.DoGUIHorizontal ("F2");
+			VOID_Data.temperature.DoGUIHorizontal("F2");
 
-			this.precisionValues [idx]= (ushort)VOID_Data.atmDensity.DoGUIHorizontal (this.precisionValues [idx]);
+			this.precisionValues[idx] = (ushort)VOID_Data.atmDensity.DoGUIHorizontal(this.precisionValues[idx]);
 			idx++;
 
-			VOID_Data.atmPressure.DoGUIHorizontal ("F2");
+			this.precisionValues[idx] = (ushort)VOID_Data.atmPressure.DoGUIHorizontal(this.precisionValues[idx]);
+			idx++;
 
-			this.precisionValues [idx]= (ushort)VOID_Data.atmLimit.DoGUIHorizontal (this.precisionValues [idx]);
+			this.precisionValues[idx] = (ushort)VOID_Data.atmLimit.DoGUIHorizontal(this.precisionValues[idx]);
 			idx++;
 
 			// Toadicus edit: added Biome
-			VOID_Data.currBiome.DoGUIHorizontal ();
+			VOID_Data.currBiome.DoGUIHorizontal();
 
 			GUILayout.EndVertical();
 
 			base.ModuleWindow(id);
 		}
 
-		public override void LoadConfig ()
+		public override void LoadConfig()
 		{
-			base.LoadConfig ();
+			base.LoadConfig();
 
-			this.precisionValues = new IntCollection (4, this._precisionValues);
+			this.precisionValues = new IntCollection(4, this._precisionValues);
 		}
 
-		public override void Save (KSP.IO.PluginConfiguration config)
+		public override void Save(KSP.IO.PluginConfiguration config)
 		{
 			this._precisionValues.value = this.precisionValues.collection;
 
-			base.Save (config);
+			base.Save(config);
 		}
 	}
 }