Changes throughout to avoid dirtying the cache unnecessarily.
[VOID.git] / VOID_VesselInfo.cs
blob:a/VOID_VesselInfo.cs -> blob:b/VOID_VesselInfo.cs
--- a/VOID_VesselInfo.cs
+++ b/VOID_VesselInfo.cs
@@ -23,6 +23,7 @@
 using System.Collections.Generic;
 using UnityEngine;
 using Engineer.VesselSimulator;
+using Engineer.Extensions;
 
 namespace VOID
 {
@@ -42,7 +43,7 @@
 
 		protected VOID_DoubleValue totalMass = new VOID_DoubleValue(
 			"Total Mass",
-			new Func<double>(() => VOID_Core.Instance.vessel.GetTotalMass()),
+			new Func<double> (() => SimManager.Instance.TryGetLastMass()),
 			"tons"
 		);
 
@@ -117,7 +118,7 @@
 
 				double currThrust = SimManager.Instance.LastStage.actualThrust;
 				double maxThrust = SimManager.Instance.LastStage.thrust;
-				double mass = VOID_Core.Instance.vessel.GetTotalMass();
+				double mass = SimManager.Instance.TryGetLastMass();
 				double gravity = VOID_Core.Instance.vessel.mainBody.gravParameter /
 				                 Math.Pow(
 					                 VOID_Core.Instance.vessel.mainBody.Radius + VOID_Core.Instance.vessel.altitude,
@@ -141,7 +142,7 @@
 					return double.NaN;
 
 				double maxThrust = SimManager.Instance.LastStage.thrust;
-				double mass = VOID_Core.Instance.vessel.GetTotalMass();
+				double mass = SimManager.Instance.TryGetLastMass();
 				double gravity = (VOID_Core.Constant_G * VOID_Core.Instance.vessel.mainBody.Mass) /
 				                 Math.Pow(VOID_Core.Instance.vessel.mainBody.Radius, 2);
 				double weight = mass * gravity;
@@ -151,6 +152,51 @@
 			""
 		);
 
+		protected VOID_StrValue intakeAirStatus = new VOID_StrValue(
+			"Intake Air (Curr / Req)",
+			delegate()
+			{
+				double currentAmount;
+				double currentRequirement;
+
+				currentAmount = 0d;
+				currentRequirement = 0d;
+
+				foreach (Part part in VOID_Core.Instance.vessel.Parts)
+				{
+					if (part.HasModule<ModuleEngines>() && part.enabled)
+					{
+						foreach (Propellant propellant in part.GetModule<ModuleEngines>().propellants)
+						{
+							if (propellant.name == "IntakeAir")
+							{
+								// currentAmount += propellant.currentAmount;
+								currentRequirement += propellant.currentRequirement / TimeWarp.fixedDeltaTime;
+								break;
+							}
+						}
+					}
+
+					if (part.HasModule<ModuleResourceIntake>() && part.enabled)
+					{
+						ModuleResourceIntake intakeModule = part.GetModule<ModuleResourceIntake>();
+
+						if (intakeModule.resourceName == "IntakeAir")
+						{
+							currentAmount += intakeModule.airFlow;
+						}
+					}
+				}
+
+				if (currentAmount == 0 && currentRequirement == 0)
+				{
+					return "N/A";
+				}
+
+				return string.Format("{0:F3} / {1:F3}", currentAmount, currentRequirement);
+			}
+		);
+
 		public VOID_VesselInfo() : base()
 		{
 			this._Name = "Vessel Information";
@@ -167,8 +213,6 @@
 			{
 				SimManager.Instance.RequestSimulation();
 			}
-
-			Stage[] stages = SimManager.Instance.Stages;
 
 			GUILayout.BeginVertical();
 
@@ -196,6 +240,8 @@
 			this.currmaxThrustWeight.DoGUIHorizontal ();
 
 			this.surfaceThrustWeight.DoGUIHorizontal ("F2");
+
+			this.intakeAirStatus.DoGUIHorizontal();
 
 			GUILayout.EndVertical();
 			GUI.DragWindow();