Relicensed to Modified BSD.
[VOID.git] / VOID_Core.cs
blob:a/VOID_Core.cs -> blob:b/VOID_Core.cs
--- a/VOID_Core.cs
+++ b/VOID_Core.cs
@@ -38,6 +38,7 @@
 {
 	public class VOID_Core : VOID_Module, IVOID_Module
 	{
+		#region Singleton Members
 		/*
 		 * Static Members
 		 * */
@@ -72,13 +73,15 @@
 			_instance = null;
 			_initialized = false;
 		}
+		#endregion
 
 		public static double Constant_G = 6.674e-11;
+
 		/*
 		 * Fields
 		 * */
 		protected string VoidName = "VOID";
-		protected string VoidVersion = "0.10.0";
+		protected string VoidVersion = "0.11.0";
 
 		protected bool _factoryReset = false;
 
@@ -136,6 +139,9 @@
 		protected VOID_SaveValue<double> _updatePeriod = 1001f / 15000f;
 		protected float _updateTimer = 0f;
 		protected string stringFrequency;
+
+		[AVOID_SaveValue("vesselSimActive")]
+		protected VOID_SaveValue<bool> vesselSimActive;
 
 		// Vessel Type Housekeeping
 		protected List<VesselType> _allVesselTypes = new List<VesselType>();
@@ -311,7 +317,7 @@
 		{
 			get
 			{
-				return _UseToolbarManager;
+				return _UseToolbarManager & ToolbarManager.ToolbarAvailable;
 			}
 			set
 			{
@@ -472,11 +478,15 @@
 		{
 			this.LoadBeforeUpdate();
 
-			if (this.vessel != null)
+			if (this.vessel != null && this.vesselSimActive)
 			{
 				SimManager.Gravity = VOID_Core.Instance.vessel.mainBody.gravParameter /
 					Math.Pow(VOID_Core.Instance.vessel.Radius(), 2);
 				SimManager.TryStartSimulation();
+			}
+			else if (!this.vesselSimActive)
+			{
+				SimManager.ClearResults();
 			}
 
 			if (!this.guiRunning)
@@ -622,6 +632,9 @@
 
 			this.UseToolbarManager = GUILayout.Toggle(this.UseToolbarManager, "Use Blizzy's Toolbar If Available");
 
+			this.vesselSimActive.value = GUILayout.Toggle(this.vesselSimActive.value,
+				"Enable Engineering Calculations");
+
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 
 			GUILayout.Label("Skin:", GUILayout.ExpandWidth(false));
@@ -867,6 +880,12 @@
 
 		protected void InitializeToolbarButton()
 		{
+			// Do nothing if the Toolbar is not available.
+			if (!ToolbarManager.ToolbarAvailable)
+			{
+				return;
+			}
+
 			this.ToolbarButton = ToolbarManager.Instance.add(this.VoidName, "coreToggle");
 			this.ToolbarButton.Text = this.VoidName;
 			this.SetIconTexture(this.powerState | this.activeState);
@@ -982,6 +1001,8 @@
 			this.VOIDIconOffInactivePath = "VOID/Textures/void_icon_light";
 			this.VOIDIconOffActivePath = "VOID/Textures/void_icon_dark";
 
+			this.vesselSimActive = true;
+
 			this.UseToolbarManager = false;
 
 			this.LoadConfig();
@@ -1012,7 +1033,7 @@
 		{
 			get
 			{
-				return core.Kerbin.gravParameter / Math.Pow(core.Kerbin.Radius, 2);
+				return core.Kerbin.gravParameter / (core.Kerbin.Radius * core.Kerbin.Radius);
 			}
 		}
 	}