Version 0.13 0.13
Version 0.13

// VOID // VOID
// //
// AssemblyInfo.cs // AssemblyInfo.cs
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// 3. Neither the name of the copyright holder nor the names of its contributors may be used // 3. Neither the name of the copyright holder nor the names of its contributors may be used
// to endorse or promote products derived from this software without specific prior written permission. // to endorse or promote products derived from this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // 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. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
   
[assembly: KSPAssemblyDependency("ToadicusTools", 0, 0)] [assembly: KSPAssemblyDependency("ToadicusTools", 0, 0)]
[assembly: KSPAssemblyDependency("VesselSimulator", 0, 0)] [assembly: KSPAssemblyDependency("VesselSimulator", 0, 0)]
   
// Information about this assembly is defined by the following attributes. // Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project. // Change them to the values specific to your project.
[assembly: AssemblyTitle("VOID")] [assembly: AssemblyTitle("VOID")]
[assembly: AssemblyDescription("A KSP mod that provides at-a-glance information about Vessels, Orbits, and their states.")] [assembly: AssemblyDescription("A KSP mod that provides at-a-glance information about Vessels, Orbits, and their states.")]
[assembly: AssemblyCopyright("toadicus")] [assembly: AssemblyCopyright("toadicus")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision, // The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision. // and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.12.0.*")] [assembly: AssemblyVersion("0.13.*")]
// The following attributes are used to specify the signing key for the assembly, // The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing. // if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)] //[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")] //[assembly: AssemblyKeyFile("")]
   
   
// VOID // VOID
// //
// VOID_HUD.cs // VOID_HUD.cs
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// 3. Neither the name of the copyright holder nor the names of its contributors may be used // 3. Neither the name of the copyright holder nor the names of its contributors may be used
// to endorse or promote products derived from this software without specific prior written permission. // to endorse or promote products derived from this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // 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. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
using Engineer.VesselSimulator; using Engineer.VesselSimulator;
using KSP; using KSP;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using ToadicusTools; using ToadicusTools;
using UnityEngine; using UnityEngine;
   
namespace VOID namespace VOID
{ {
public class VOID_HUDAdvanced : VOID_Module, IVOID_Module public class VOID_HUDAdvanced : VOID_Module, IVOID_Module
{ {
/* /*
* Fields * Fields
* */ * */
protected VOID_HUD primaryHUD; protected VOID_HUD primaryHUD;
   
protected Rect leftHUDdefaultPos; protected Rect leftHUDdefaultPos;
protected Rect rightHUDdefaultPos; protected Rect rightHUDdefaultPos;
   
[AVOID_SaveValue("leftHUDPos")] [AVOID_SaveValue("leftHUDPos")]
protected VOID_SaveValue<Rect> leftHUDPos; protected VOID_SaveValue<Rect> leftHUDPos;
[AVOID_SaveValue("rightHUDPos")] [AVOID_SaveValue("rightHUDPos")]
protected VOID_SaveValue<Rect> rightHUDPos; protected VOID_SaveValue<Rect> rightHUDPos;
   
[AVOID_SaveValue("positionsLocked")] [AVOID_SaveValue("positionsLocked")]
protected VOID_SaveValue<bool> positionsLocked; protected VOID_SaveValue<bool> positionsLocked;
   
/* /*
* Properties * Properties
* */ * */
public int ColorIndex public int ColorIndex
{ {
get get
{ {
if (this.primaryHUD == null) if (this.primaryHUD == null)
{ {
return 0; return 0;
} }
   
return this.primaryHUD.ColorIndex; return this.primaryHUD.ColorIndex;
} }
} }
   
/* /*
* Methods * Methods
* */ * */
public VOID_HUDAdvanced() : base() public VOID_HUDAdvanced() : base()
{ {
this._Name = "Advanced Heads-Up Display"; this._Name = "Advanced Heads-Up Display";
   
this._Active.value = true; this._Active.value = true;
   
this.leftHUDdefaultPos = new Rect( this.leftHUDdefaultPos = new Rect(
Screen.width * .5f - (float)GameSettings.UI_SIZE * .25f - 300f, Screen.width * .5f - (float)GameSettings.UI_SIZE * .25f - 300f,
Screen.height - 200f, Screen.height - 200f,
300f, 90f 300f, 90f
); );
this.leftHUDPos = new Rect(this.leftHUDdefaultPos); this.leftHUDPos = new Rect(this.leftHUDdefaultPos);
   
this.rightHUDdefaultPos = new Rect( this.rightHUDdefaultPos = new Rect(
Screen.width * .5f + (float)GameSettings.UI_SIZE * .25f, Screen.width * .5f + (float)GameSettings.UI_SIZE * .25f,
Screen.height - 200f, Screen.height - 200f,
300f, 90f 300f, 90f
); );
this.rightHUDPos = new Rect(this.rightHUDdefaultPos); this.rightHUDPos = new Rect(this.rightHUDdefaultPos);
   
this.positionsLocked = true; this.positionsLocked = true;
   
Tools.PostDebugMessage (this, "Constructed."); Tools.PostDebugMessage (this, "Constructed.");
} }
   
protected void leftHUDWindow(int id) protected void leftHUDWindow(int id)
{ {
StringBuilder leftHUD; StringBuilder leftHUD;
   
leftHUD = new StringBuilder(); leftHUD = new StringBuilder();
   
this.core.LabelStyles["hud"].alignment = TextAnchor.UpperRight; this.core.LabelStyles["hud"].alignment = TextAnchor.UpperRight;
   
if (this.core.powerAvailable) if (this.core.powerAvailable)
{ {
leftHUD.AppendFormat( leftHUD.AppendFormat(
string.Intern("Mass: {0}\n"), string.Intern("Mass: {0}\n"),
VOID_Data.totalMass.ToSIString(2) VOID_Data.totalMass.ToSIString(2)
); );
   
if (VOID_Data.vesselCrewCapacity > 0) if (VOID_Data.vesselCrewCapacity > 0)
{ {
leftHUD.AppendFormat( leftHUD.AppendFormat(
string.Intern("Crew: {0} / {1}\n"), string.Intern("Crew: {0} / {1}\n"),
VOID_Data.vesselCrewCount.Value, VOID_Data.vesselCrewCount.Value,
VOID_Data.vesselCrewCapacity.Value VOID_Data.vesselCrewCapacity.Value
); );
} }
   
leftHUD.AppendFormat( leftHUD.AppendFormat(
string.Intern("Acc: {0} T:W: {1}\n"), string.Intern("Acc: {0} T:W: {1}\n"),
VOID_Data.vesselAccel.ToSIString(2), VOID_Data.vesselAccel.ToSIString(2),
VOID_Data.currThrustWeight.Value.ToString("f2") VOID_Data.currThrustWeight.Value.ToString("f2")
); );
   
leftHUD.AppendFormat( leftHUD.AppendFormat(
string.Intern("Ang Vel: {0}\n"), string.Intern("Ang Vel: {0}\n"),
VOID_Data.vesselAngularVelocity.ToSIString(2) VOID_Data.vesselAngularVelocity.ToSIString(2)
); );
   
if (VOID_Data.stageNominalThrust != 0d) if (VOID_Data.stageNominalThrust != 0d)
{ {
leftHUD.AppendFormat( leftHUD.AppendFormat(
string.Intern("Thrust Offset: {0}\n"), string.Intern("Thrust Offset: {0}\n"),
VOID_Data.vesselThrustOffset.Value.ToString("F1") VOID_Data.vesselThrustOffset.Value.ToString("F1")
); );
} }
} }
else else
{ {
this.core.LabelStyles["hud"].normal.textColor = Color.red; this.core.LabelStyles["hud"].normal.textColor = Color.red;
leftHUD.Append(string.Intern("-- POWER LOST --")); leftHUD.Append(string.Intern("-- POWER LOST --"));
} }
   
GUILayout.Label(leftHUD.ToString(), this.core.LabelStyles["hud"], GUILayout.ExpandWidth(true)); GUILayout.Label(leftHUD.ToString(), this.core.LabelStyles["hud"], GUILayout.ExpandWidth(true));
   
if (!this.positionsLocked) if (!this.positionsLocked)
{ {
GUI.DragWindow(); GUI.DragWindow();
} }
   
GUI.BringWindowToBack(id); GUI.BringWindowToBack(id);
} }
   
protected void rightHUDWindow(int id) protected void rightHUDWindow(int id)
{ {
StringBuilder rightHUD; StringBuilder rightHUD;
   
rightHUD = new StringBuilder(); rightHUD = new StringBuilder();
   
this.core.LabelStyles["hud"].alignment = TextAnchor.UpperLeft; this.core.LabelStyles["hud"].alignment = TextAnchor.UpperLeft;
   
if (this.core.powerAvailable) if (this.core.powerAvailable)
{ {
rightHUD.AppendFormat( rightHUD.AppendFormat(
"Burn Δv (Rem/Tot): {0} / {1}\n", "Burn Δv (Rem/Tot): {0} / {1}\n",
VOID_Data.currManeuverDVRemaining.ValueUnitString("f2"), VOID_Data.currManeuverDVRemaining.ValueUnitString("f2"),
VOID_Data.currManeuverDeltaV.ValueUnitString("f2") VOID_Data.currManeuverDeltaV.ValueUnitString("f2")
); );
   
if (VOID_Data.upcomingManeuverNodes > 1) if (VOID_Data.upcomingManeuverNodes > 1)
{ {
rightHUD.AppendFormat("Next Burn Δv: {0}\n", rightHUD.AppendFormat("Next Burn Δv: {0}\n",
VOID_Data.nextManeuverDeltaV.ValueUnitString("f2") VOID_Data.nextManeuverDeltaV.ValueUnitString("f2")
); );
} }
   
rightHUD.AppendFormat("Burn Time (Rem/Total): {0} / {1}\n", rightHUD.AppendFormat("Burn Time (Rem/Total): {0} / {1}\n",
VOID_Tools.ConvertInterval(VOID_Data.currentNodeBurnRemaining.Value), VOID_Tools.ConvertInterval(VOID_Data.currentNodeBurnRemaining.Value),
VOID_Tools.ConvertInterval(VOID_Data.currentNodeBurnDuration.Value) VOID_Tools.ConvertInterval(VOID_Data.currentNodeBurnDuration.Value)
); );
   
if (VOID_Data.burnTimeDoneAtNode.Value != string.Empty) if (VOID_Data.burnTimeDoneAtNode.Value != string.Empty)
{ {
rightHUD.AppendFormat("{0} (done @ node)\n", rightHUD.AppendFormat("{0} (done @ node)\n",
VOID_Data.burnTimeDoneAtNode.Value VOID_Data.burnTimeDoneAtNode.Value
); );
   
rightHUD.AppendFormat("{0} (½ done @ node)", rightHUD.AppendFormat("{0} (½ done @ node)",
VOID_Data.burnTimeHalfDoneAtNode.Value VOID_Data.burnTimeHalfDoneAtNode.Value
); );
} }
else else
{ {
rightHUD.Append("Node is past"); rightHUD.Append("Node is past");
} }
} }
else else
{ {
this.core.LabelStyles["hud"].normal.textColor = Color.red; this.core.LabelStyles["hud"].normal.textColor = Color.red;
rightHUD.Append(string.Intern("-- POWER LOST --")); rightHUD.Append(string.Intern("-- POWER LOST --"));
} }
   
GUILayout.Label(rightHUD.ToString(), this.core.LabelStyles["hud"], GUILayout.ExpandWidth(true)); GUILayout.Label(rightHUD.ToString(), this.core.LabelStyles["hud"], GUILayout.ExpandWidth(true));
   
if (!this.positionsLocked) if (!this.positionsLocked)
{ {
GUI.DragWindow(); GUI.DragWindow();
} }
   
GUI.BringWindowToBack(id); GUI.BringWindowToBack(id);
} }
   
public override void DrawGUI() public override void DrawGUI()
{ {
if (this.primaryHUD == null) if (this.primaryHUD == null)
{ {
foreach (IVOID_Module module in this.core.Modules) foreach (IVOID_Module module in this.core.Modules)
{ {
if (module is VOID_HUD) if (module is VOID_HUD)
{ {
this.primaryHUD = module as VOID_HUD; this.primaryHUD = module as VOID_HUD;
} }
} }
} }
else else
{ {
if ((TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate)) if ((TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate))
{ {
SimManager.RequestSimulation(); SimManager.RequestSimulation();
} }
   
this.leftHUDPos.value = GUI.Window( this.leftHUDPos.value = GUI.Window(
this.core.windowID, this.core.windowID,
this.leftHUDPos, this.leftHUDPos,
VOID_Tools.GetWindowHandler(this.leftHUDWindow), VOID_Tools.GetWindowHandler(this.leftHUDWindow),
GUIContent.none, GUIContent.none,
GUIStyle.none GUIStyle.none
); );
   
if (VOID_Data.upcomingManeuverNodes > 0) if (VOID_Data.upcomingManeuverNodes > 0)
{ {
this.rightHUDPos.value = GUI.Window( this.rightHUDPos.value = GUI.Window(
this.core.windowID, this.core.windowID,
this.rightHUDPos, this.rightHUDPos,
VOID_Tools.GetWindowHandler(this.rightHUDWindow), VOID_Tools.GetWindowHandler(this.rightHUDWindow),
GUIContent.none, GUIContent.none,
GUIStyle.none GUIStyle.none
); );
} }
} }
} }
   
public override void DrawConfigurables() public override void DrawConfigurables()
{ {
this.positionsLocked = GUILayout.Toggle(this.positionsLocked, this.positionsLocked = GUILayout.Toggle(this.positionsLocked,
string.Intern("Lock Advanced HUD Positions"), string.Intern("Lock Advanced HUD Positions"),
GUILayout.ExpandWidth(false)); GUILayout.ExpandWidth(false));
} }
} }
   
public static partial class VOID_Data public static partial class VOID_Data
{ {
public static int upcomingManeuverNodes public static int upcomingManeuverNodes
{ {
get get
{ {
if (core.vessel == null || if (core.vessel == null ||
core.vessel.patchedConicSolver == null || core.vessel.patchedConicSolver == null ||
core.vessel.patchedConicSolver.maneuverNodes == null core.vessel.patchedConicSolver.maneuverNodes == null
) )
{ {
return 0; return 0;
} }
   
return core.vessel.patchedConicSolver.maneuverNodes.Count; return core.vessel.patchedConicSolver.maneuverNodes.Count;
} }
} }
   
public static readonly VOID_Vector3dValue vesselThrustOffset = new VOID_Vector3dValue( public static readonly VOID_Vector3dValue vesselThrustOffset = new VOID_Vector3dValue(
"Thrust Offset", "Thrust Offset",
delegate() delegate()
{ {
if (core.vessel == null) if (core.vessel == null)
{ {
return Vector3d.zero; return Vector3d.zero;
} }
   
List<PartModule> engineModules = core.vessel.getModulesOfType<PartModule>(); List<PartModule> engineModules = core.vessel.getModulesOfType<PartModule>();
   
Vector3d thrustPos = Vector3d.zero; Vector3d thrustPos = Vector3d.zero;
Vector3d thrustDir = Vector3d.zero; Vector3d thrustDir = Vector3d.zero;
float thrust = 0; float thrust = 0;
   
foreach (PartModule engine in engineModules) foreach (PartModule engine in engineModules)
{ {
float moduleThrust = 0; float moduleThrust = 0;
   
switch (engine.moduleName) switch (engine.moduleName)
{ {
case "ModuleEngines": case "ModuleEngines":
case "ModuleEnginesFX": case "ModuleEnginesFX":
break; break;
default: default:
continue; continue;
} }
   
if (!engine.isEnabled) if (!engine.isEnabled)
{ {
continue; continue;
} }
   
CenterOfThrustQuery cotQuery = new CenterOfThrustQuery(); CenterOfThrustQuery cotQuery = new CenterOfThrustQuery();
   
if (engine is ModuleEngines) if (engine is ModuleEngines)
{ {
ModuleEngines engineModule = engine as ModuleEngines; ModuleEngines engineModule = engine as ModuleEngines;
   
moduleThrust = engineModule.finalThrust; moduleThrust = engineModule.finalThrust;
   
engineModule.OnCenterOfThrustQuery(cotQuery); engineModule.OnCenterOfThrustQuery(cotQuery);
} }
else // engine is ModuleEnginesFX else // engine is ModuleEnginesFX
{ {
ModuleEnginesFX engineFXModule = engine as ModuleEnginesFX; ModuleEnginesFX engineFXModule = engine as ModuleEnginesFX;
   
moduleThrust = engineFXModule.finalThrust; moduleThrust = engineFXModule.finalThrust;
   
engineFXModule.OnCenterOfThrustQuery(cotQuery); engineFXModule.OnCenterOfThrustQuery(cotQuery);
} }
   
if (moduleThrust != 0d) if (moduleThrust != 0d)
{ {
cotQuery.thrust = moduleThrust; cotQuery.thrust = moduleThrust;
} }
   
thrustPos += cotQuery.pos * cotQuery.thrust; thrustPos += cotQuery.pos * cotQuery.thrust;
thrustDir += cotQuery.dir * cotQuery.thrust; thrustDir += cotQuery.dir * cotQuery.thrust;
thrust += cotQuery.thrust; thrust += cotQuery.thrust;
} }
   
if (thrust != 0) if (thrust != 0)
{ {
thrustPos /= thrust; thrustPos /= thrust;
thrustDir /= thrust; thrustDir /= thrust;
} }
   
Transform vesselTransform = core.vessel.transform; Transform vesselTransform = core.vessel.transform;
   
thrustPos = vesselTransform.InverseTransformPoint(thrustPos); thrustPos = vesselTransform.InverseTransformPoint(thrustPos);
thrustDir = vesselTransform.InverseTransformDirection(thrustDir); thrustDir = vesselTransform.InverseTransformDirection(thrustDir);
   
Vector3d thrustOffset = VectorTools.PointDistanceToLine( Vector3d thrustOffset = VectorTools.PointDistanceToLine(
thrustPos, thrustDir.normalized, core.vessel.findLocalCenterOfMass()); thrustPos, thrustDir.normalized, core.vessel.findLocalCenterOfMass());
   
Tools.PostDebugMessage(typeof(VOID_Data), "vesselThrustOffset:\n" + Tools.PostDebugMessage(typeof(VOID_Data), "vesselThrustOffset:\n" +
"\tthrustPos: {0}\n" + "\tthrustPos: {0}\n" +
"\tthrustDir: {1}\n" + "\tthrustDir: {1}\n" +
"\tthrustOffset: {2}\n" + "\tthrustOffset: {2}\n" +
"\tvessel.CoM: {3}", "\tvessel.CoM: {3}",
thrustPos, thrustPos,
thrustDir.normalized, thrustDir.normalized,
thrustOffset, thrustOffset,
core.vessel.findWorldCenterOfMass() core.vessel.findWorldCenterOfMass()
); );
   
return thrustOffset; return thrustOffset;
}, },
"m" "m"
); );
   
public static readonly VOID_DoubleValue vesselAccel = new VOID_DoubleValue( public static readonly VOID_DoubleValue vesselAccel = new VOID_DoubleValue(
"Acceleration", "Acceleration",
() => geeForce * KerbinGee, () => geeForce * KerbinGee,
"m/s" "m/s²"
); );
   
public static readonly VOID_IntValue vesselCrewCount = new VOID_IntValue( public static readonly VOID_IntValue vesselCrewCount = new VOID_IntValue(
"Crew Onboard", "Crew Onboard",
delegate() delegate()
{ {
if (core.vessel != null) if (core.vessel != null)
{ {
return core.vessel.GetCrewCount(); return core.vessel.GetCrewCount();
} }
else else
{ {
return 0; return 0;
} }
}, },
"" ""
); );
   
public static readonly VOID_IntValue vesselCrewCapacity = new VOID_IntValue( public static readonly VOID_IntValue vesselCrewCapacity = new VOID_IntValue(
"Crew Capacity", "Crew Capacity",
delegate() delegate()
{ {
if (core.vessel != null) if (core.vessel != null)
{ {
return core.vessel.GetCrewCapacity(); return core.vessel.GetCrewCapacity();
} }
else else
{ {
return 0; return 0;
} }
}, },
"" ""
); );
   
public static readonly VOID_DoubleValue vesselAngularVelocity = new VOID_DoubleValue( public static readonly VOID_DoubleValue vesselAngularVelocity = new VOID_DoubleValue(
"Angular Velocity", "Angular Velocity",
delegate() delegate()
{ {
if (core.vessel != null) if (core.vessel != null)
{ {
return core.vessel.angularVelocity.magnitude; return core.vessel.angularVelocity.magnitude;
} }
else else
{ {
return double.NaN; return double.NaN;
} }
}, },
"rad/s" "rad/s"
); );
   
public static readonly VOID_DoubleValue stageNominalThrust = new VOID_DoubleValue( public static readonly VOID_DoubleValue stageNominalThrust = new VOID_DoubleValue(
"Nominal Stage Thrust", "Nominal Stage Thrust",
delegate() delegate()
{ {
if (SimManager.LastStage == null) if (SimManager.LastStage == null)
{ {
return double.NaN; return double.NaN;
} }
   
if (SimManager.LastStage.actualThrust == 0d) if (SimManager.LastStage.actualThrust == 0d)
{ {
return SimManager.LastStage.thrust; return SimManager.LastStage.thrust;
} }
else else
{ {
return SimManager.LastStage.actualThrust; return SimManager.LastStage.actualThrust;
} }
}, },
"kN" "kN"
); );
   
public static readonly VOID_DoubleValue stageMassFlow = new VOID_DoubleValue( public static readonly VOID_DoubleValue stageMassFlow = new VOID_DoubleValue(
"Stage Mass Flow", "Stage Mass Flow",
delegate() delegate()
{ {
if (SimManager.LastStage == null) if (SimManager.LastStage == null)
{ {
return double.NaN; return double.NaN;
} }
   
double stageIsp = SimManager.LastStage.isp; double stageIsp = SimManager.LastStage.isp;
double stageThrust = stageNominalThrust; double stageThrust = stageNominalThrust;
   
Tools.PostDebugMessage(typeof(VOID_Data), "calculating stageMassFlow from:\n" + Tools.PostDebugMessage(typeof(VOID_Data), "calculating stageMassFlow from:\n" +
"\tstageIsp: {0}\n" + "\tstageIsp: {0}\n" +
"\tstageThrust: {1}\n" + "\tstageThrust: {1}\n" +
"\tKerbinGee: {2}\n", "\tKerbinGee: {2}\n",
stageIsp, stageIsp,
stageThrust, stageThrust,
KerbinGee KerbinGee
); );
   
return stageThrust / (stageIsp * KerbinGee); return stageThrust / (stageIsp * KerbinGee);
}, },
"Mg/s" "Mg/s"
); );
   
public static readonly VOID_DoubleValue currManeuverDeltaV = new VOID_DoubleValue( public static readonly VOID_DoubleValue currManeuverDeltaV = new VOID_DoubleValue(
"Current Maneuver Delta-V", "Current Maneuver Delta-V",
delegate() delegate()
{ {
if (upcomingManeuverNodes > 0) if (upcomingManeuverNodes > 0)
{ {
return core.vessel.patchedConicSolver.maneuverNodes[0].DeltaV.magnitude; return core.vessel.patchedConicSolver.maneuverNodes[0].DeltaV.magnitude;
} }
else else
{ {
return double.NaN; return double.NaN;
} }
}, },
"m/s" "m/s"
); );
   
public static readonly VOID_DoubleValue currManeuverDVRemaining = new VOID_DoubleValue( public static readonly VOID_DoubleValue currManeuverDVRemaining = new VOID_DoubleValue(
"Remaining Maneuver Delta-V", "Remaining Maneuver Delta-V",
delegate() delegate()
{ {
if (upcomingManeuverNodes > 0) if (upcomingManeuverNodes > 0)
{ {
return core.vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(core.vessel.orbit).magnitude; return core.vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(core.vessel.orbit).magnitude;
} }
else else
{ {
return double.NaN; return double.NaN;
} }
}, },
"m/s" "m/s"
); );
   
public static readonly VOID_DoubleValue nextManeuverDeltaV = new VOID_DoubleValue( public static readonly VOID_DoubleValue nextManeuverDeltaV = new VOID_DoubleValue(
"Current Maneuver Delta-V", "Current Maneuver Delta-V",
delegate() delegate()
{ {
if (upcomingManeuverNodes > 1) if (upcomingManeuverNodes > 1)
{ {
return core.vessel.patchedConicSolver.maneuverNodes[1].DeltaV.magnitude; return core.vessel.patchedConicSolver.maneuverNodes[1].DeltaV.magnitude;
} }
else else
{ {
return double.NaN; return double.NaN;
} }
}, },
"m/s" "m/s"
); );
   
public static readonly VOID_DoubleValue currentNodeBurnDuration = new VOID_DoubleValue( public static readonly VOID_DoubleValue currentNodeBurnDuration = new VOID_DoubleValue(
"Total Burn Time", "Total Burn Time",
delegate() delegate()
{ {
if (SimManager.LastStage == null || currManeuverDeltaV.Value == double.NaN) if (SimManager.LastStage == null || currManeuverDeltaV.Value == double.NaN)
{ {
return double.NaN; return double.NaN;
} }
double stageThrust = stageNominalThrust; double stageThrust = stageNominalThrust;
   
return burnTime(currManeuverDeltaV.Value, totalMass, stageMassFlow, stageThrust); return burnTime(currManeuverDeltaV.Value, totalMass, stageMassFlow, stageThrust);
}, },
"s" "s"
); );
   
public static readonly VOID_DoubleValue currentNodeBurnRemaining = new VOID_DoubleValue( public static readonly VOID_DoubleValue currentNodeBurnRemaining = new VOID_DoubleValue(
"Burn Time Remaining", "Burn Time Remaining",
delegate() delegate()
{ {
if (SimManager.LastStage == null || currManeuverDVRemaining == double.NaN) if (SimManager.LastStage == null || currManeuverDVRemaining == double.NaN)
{ {
return double.NaN; return double.NaN;
} }
   
double stageThrust = stageNominalThrust; double stageThrust = stageNominalThrust;
   
return burnTime(currManeuverDVRemaining, totalMass, stageMassFlow, stageThrust); return burnTime(currManeuverDVRemaining, totalMass, stageMassFlow, stageThrust);
}, },
"s" "s"
); );
   
public static readonly VOID_DoubleValue currentNodeHalfBurnDuration = new VOID_DoubleValue( public static readonly VOID_DoubleValue currentNodeHalfBurnDuration = new VOID_DoubleValue(
"Half Burn Time", "Half Burn Time",
delegate() delegate()
{ {
if (SimManager.LastStage == null || currManeuverDeltaV.Value == double.NaN) if (SimManager.LastStage == null || currManeuverDeltaV.Value == double.NaN)
{ {
return double.NaN; return double.NaN;
} }
   
double stageThrust = stageNominalThrust; double stageThrust = stageNominalThrust;
   
return burnTime(currManeuverDeltaV.Value / 2d, totalMass, stageMassFlow, stageThrust); return burnTime(currManeuverDeltaV.Value / 2d, totalMass, stageMassFlow, stageThrust);
}, },
"s" "s"
); );
   
public static readonly VOID_StrValue burnTimeDoneAtNode = new VOID_StrValue( public static readonly VOID_StrValue burnTimeDoneAtNode = new VOID_StrValue(
"Full burn time to be half done at node", "Full burn time to be half done at node",
delegate() delegate()
{ {
if (SimManager.LastStage == null && upcomingManeuverNodes < 1) if (SimManager.LastStage == null && upcomingManeuverNodes < 1)
{ {
return "N/A"; return "N/A";
} }
   
ManeuverNode node = core.vessel.patchedConicSolver.maneuverNodes[0]; ManeuverNode node = core.vessel.patchedConicSolver.maneuverNodes[0];
   
if ((node.UT - Planetarium.GetUniversalTime()) < 0) if ((node.UT - Planetarium.GetUniversalTime()) < 0)
{ {
return string.Empty; return string.Empty;
} }
   
double interval = (node.UT - currentNodeBurnDuration) - Planetarium.GetUniversalTime(); double interval = (node.UT - currentNodeBurnDuration) - Planetarium.GetUniversalTime();
   
if (double.IsNaN(interval)) if (double.IsNaN(interval))
{ {
return string.Intern("NaN"); return string.Intern("NaN");
} }
   
int sign = Math.Sign(interval); int sign = Math.Sign(interval);
interval = Math.Abs(interval); interval = Math.Abs(interval);
   
string format; string format;
   
if (sign >= 0) if (sign >= 0)
{ {
format = string.Intern("T - {0}"); format = string.Intern("T - {0}");
} }
else else
{ {
format = string.Intern("T + {0}"); format = string.Intern("T + {0}");
} }
   
return string.Format(format, VOID_Tools.ConvertInterval(interval)); return string.Format(format, VOID_Tools.ConvertInterval(interval));
} }
); );
   
public static readonly VOID_StrValue burnTimeHalfDoneAtNode = new VOID_StrValue( public static readonly VOID_StrValue burnTimeHalfDoneAtNode = new VOID_StrValue(
"Full burn time to be half done at node", "Full burn time to be half done at node",
delegate() delegate()
{ {
if (SimManager.LastStage == null && upcomingManeuverNodes < 1) if (SimManager.LastStage == null && upcomingManeuverNodes < 1)
{ {
return "N/A"; return "N/A";
} }
   
ManeuverNode node = core.vessel.patchedConicSolver.maneuverNodes[0]; ManeuverNode node = core.vessel.patchedConicSolver.maneuverNodes[0];
   
if ((node.UT - Planetarium.GetUniversalTime()) < 0) if ((node.UT - Planetarium.GetUniversalTime()) < 0)
{ {
return string.Empty; return string.Empty;
} }
   
double interval = (node.UT - currentNodeHalfBurnDuration) - Planetarium.GetUniversalTime(); double interval = (node.UT - currentNodeHalfBurnDuration) - Planetarium.GetUniversalTime();
   
int sign = Math.Sign(interval); int sign = Math.Sign(interval);
interval = Math.Abs(interval); interval = Math.Abs(interval);
   
string format; string format;
   
if (sign >= 0) if (sign >= 0)
{ {
format = string.Intern("T - {0}"); format = string.Intern("T - {0}");
} }
else else
{ {
format = string.Intern("T + {0}"); format = string.Intern("T + {0}");
} }
   
return string.Format(format, VOID_Tools.ConvertInterval(interval)); return string.Format(format, VOID_Tools.ConvertInterval(interval));
} }
); );
   
private static double burnTime(double deltaV, double initialMass, double massFlow, double thrust) private static double burnTime(double deltaV, double initialMass, double massFlow, double thrust)
{ {
Tools.PostDebugMessage(typeof(VOID_Data), "calculating burnTime from:\n" + Tools.PostDebugMessage(typeof(VOID_Data), "calculating burnTime from:\n" +
"\tdeltaV: {0}\n" + "\tdeltaV: {0}\n" +
"\tinitialMass: {1}\n" + "\tinitialMass: {1}\n" +
"\tmassFlow: {2}\n" + "\tmassFlow: {2}\n" +
"\tthrust: {3}\n", "\tthrust: {3}\n",
deltaV, deltaV,
initialMass, initialMass,
massFlow, massFlow,
thrust thrust
); );
return initialMass / massFlow * (Math.Exp(deltaV * massFlow / thrust) - 1d); return initialMass / massFlow * (Math.Exp(deltaV * massFlow / thrust) - 1d);
} }
} }
} }
   
// VOID // VOID
// //
// VOID_VesselInfo.cs // VOID_VesselInfo.cs
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// 3. Neither the name of the copyright holder nor the names of its contributors may be used // 3. Neither the name of the copyright holder nor the names of its contributors may be used
// to endorse or promote products derived from this software without specific prior written permission. // to endorse or promote products derived from this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // 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. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
using Engineer.VesselSimulator; using Engineer.VesselSimulator;
using Engineer.Extensions; using Engineer.Extensions;
using KSP; using KSP;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ToadicusTools; using ToadicusTools;
using UnityEngine; using UnityEngine;
   
namespace VOID namespace VOID
{ {
public class VOID_VesselInfo : VOID_WindowModule public class VOID_VesselInfo : VOID_WindowModule
{ {
public VOID_VesselInfo() : base() public VOID_VesselInfo() : base()
{ {
this._Name = "Vessel Information"; this._Name = "Vessel Information";
   
this.WindowPos.x = Screen.width - 260; this.WindowPos.x = Screen.width - 260;
this.WindowPos.y = 450; this.WindowPos.y = 450;
} }
   
public override void ModuleWindow(int _) public override void ModuleWindow(int _)
{ {
if ((TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate)) if ((TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate))
{ {
SimManager.RequestSimulation(); SimManager.RequestSimulation();
} }
   
GUILayout.BeginVertical(); GUILayout.BeginVertical();
   
GUILayout.Label( GUILayout.Label(
vessel.vesselName, vessel.vesselName,
core.LabelStyles["center_bold"], core.LabelStyles["center_bold"],
GUILayout.ExpandWidth(true)); GUILayout.ExpandWidth(true));
   
VOID_Data.geeForce.DoGUIHorizontal ("F2"); VOID_Data.geeForce.DoGUIHorizontal ("F2");
   
VOID_Data.partCount.DoGUIHorizontal (); VOID_Data.partCount.DoGUIHorizontal ();
   
VOID_Data.totalMass.DoGUIHorizontal ("F3"); VOID_Data.totalMass.DoGUIHorizontal ("F3");
   
VOID_Data.comboResourceMass.DoGUIHorizontal (); VOID_Data.comboResourceMass.DoGUIHorizontal ();
   
VOID_Data.stageDeltaV.DoGUIHorizontal (3, false); VOID_Data.stageDeltaV.DoGUIHorizontal (3, false);
   
VOID_Data.totalDeltaV.DoGUIHorizontal (3, false); VOID_Data.totalDeltaV.DoGUIHorizontal (3, false);
   
VOID_Data.mainThrottle.DoGUIHorizontal ("F0"); VOID_Data.mainThrottle.DoGUIHorizontal ("F0");
   
VOID_Data.currmaxThrust.DoGUIHorizontal (); VOID_Data.currmaxThrust.DoGUIHorizontal ();
   
VOID_Data.currmaxThrustWeight.DoGUIHorizontal (); VOID_Data.currmaxThrustWeight.DoGUIHorizontal ();
   
VOID_Data.surfaceThrustWeight.DoGUIHorizontal ("F2"); VOID_Data.surfaceThrustWeight.DoGUIHorizontal ("F2");
   
VOID_Data.intakeAirStatus.DoGUIHorizontal(); VOID_Data.intakeAirStatus.DoGUIHorizontal();
   
GUILayout.EndVertical(); GUILayout.EndVertical();
   
GUI.DragWindow(); GUI.DragWindow();
} }
} }
   
public static partial class VOID_Data public static partial class VOID_Data
{ {
public static readonly VOID_DoubleValue geeForce = new VOID_DoubleValue( public static readonly VOID_DoubleValue geeForce = new VOID_DoubleValue(
"G-force", "G-force",
new Func<double>(() => core.vessel.geeForce), new Func<double>(() => core.vessel.geeForce),
"gees" "gees"
); );
   
public static readonly VOID_IntValue partCount = new VOID_IntValue( public static readonly VOID_IntValue partCount = new VOID_IntValue(
"Parts", "Parts",
new Func<int>(() => core.vessel.Parts.Count), new Func<int>(() => core.vessel.Parts.Count),
"" ""
); );
   
public static readonly VOID_DoubleValue totalMass = new VOID_DoubleValue( public static readonly VOID_DoubleValue totalMass = new VOID_DoubleValue(
"Total Mass", "Total Mass",
delegate() delegate()
{ {
if (SimManager.Stages == null || SimManager.LastStage == null) if (SimManager.Stages == null || SimManager.LastStage == null)
{ {
return double.NaN; return double.NaN;
} }
   
return SimManager.LastStage.totalMass; return SimManager.LastStage.totalMass;
}, },
"tons" "tons"
); );
   
public static readonly VOID_DoubleValue resourceMass = new VOID_DoubleValue( public static readonly VOID_DoubleValue resourceMass = new VOID_DoubleValue(
"Resource Mass", "Resource Mass",
delegate() delegate()
{ {
if (SimManager.Stages == null || SimManager.LastStage == null) if (SimManager.Stages == null || SimManager.LastStage == null)
{ {
return double.NaN; return double.NaN;
} }
   
return SimManager.LastStage.totalMass - SimManager.LastStage.totalBaseMass; return SimManager.LastStage.totalMass - SimManager.LastStage.totalBaseMass;
}, },
"tons" "tons"
); );
   
public static readonly VOID_DoubleValue stageResourceMass = new VOID_DoubleValue( public static readonly VOID_DoubleValue stageResourceMass = new VOID_DoubleValue(
"Resource Mass (Current Stage)", "Resource Mass (Current Stage)",
delegate() delegate()
{ {
if (SimManager.LastStage == null) if (SimManager.LastStage == null)
{ {
return double.NaN; return double.NaN;
} }
   
return SimManager.LastStage.mass - SimManager.LastStage.baseMass; return SimManager.LastStage.mass - SimManager.LastStage.baseMass;
}, },
"tons" "tons"
); );
   
public static readonly VOID_StrValue comboResourceMass = new VOID_StrValue( public static readonly VOID_StrValue comboResourceMass = new VOID_StrValue(
"Resource Mass (curr / total)", "Resource Mass (curr / total)",
delegate() delegate()
{ {
return string.Format("{0} / {1}", stageResourceMass.ValueUnitString(), resourceMass.ValueUnitString()); return string.Format("{0} / {1}",
  stageResourceMass.ValueUnitString("F3"),
  resourceMass.ValueUnitString("F3")
  );
} }
); );
   
public static readonly VOID_DoubleValue stageDeltaV = new VOID_DoubleValue( public static readonly VOID_DoubleValue stageDeltaV = new VOID_DoubleValue(
"DeltaV (Current Stage)", "DeltaV (Current Stage)",
delegate() delegate()
{ {
if (SimManager.Stages == null || SimManager.LastStage == null) if (SimManager.Stages == null || SimManager.LastStage == null)
return double.NaN; return double.NaN;
return SimManager.LastStage.deltaV; return SimManager.LastStage.deltaV;
}, },
"m/s" "m/s"
); );
   
public static readonly VOID_DoubleValue totalDeltaV = new VOID_DoubleValue( public static readonly VOID_DoubleValue totalDeltaV = new VOID_DoubleValue(
"DeltaV (Total)", "DeltaV (Total)",
delegate() delegate()
{ {
if (SimManager.Stages == null || SimManager.LastStage == null) if (SimManager.Stages == null || SimManager.LastStage == null)
return double.NaN; return double.NaN;
return SimManager.LastStage.totalDeltaV; return SimManager.LastStage.totalDeltaV;
}, },
"m/s" "m/s"
); );
   
public static readonly VOID_FloatValue mainThrottle = new VOID_FloatValue( public static readonly VOID_FloatValue mainThrottle = new VOID_FloatValue(
"Throttle", "Throttle",
new Func<float>(() => core.vessel.ctrlState.mainThrottle * 100f), new Func<float>(() => core.vessel.ctrlState.mainThrottle * 100f),
"%" "%"
); );
   
public static readonly VOID_StrValue currmaxThrust = new VOID_StrValue( public static readonly VOID_StrValue currmaxThrust = new VOID_StrValue(
"Thrust (curr/max)", "Thrust (curr/max)",
delegate() delegate()
{ {
if (SimManager.Stages == null || SimManager.LastStage == null) if (SimManager.Stages == null || SimManager.LastStage == null)
return "N/A"; return "N/A";
   
double currThrust = SimManager.LastStage.actualThrust; double currThrust = SimManager.LastStage.actualThrust;
double maxThrust = SimManager.LastStage.thrust; double maxThrust = SimManager.LastStage.thrust;
   
return string.Format( return string.Format(
"{0} / {1}", "{0} / {1}",
currThrust.ToString("F1"), currThrust.ToString("F1"),
maxThrust.ToString("F1") maxThrust.ToString("F1")
); );
} }
); );
   
public static readonly VOID_DoubleValue currThrustWeight = new VOID_DoubleValue( public static readonly VOID_DoubleValue currThrustWeight = new VOID_DoubleValue(
"T:W Ratio", "T:W Ratio",
delegate() delegate()
{ {
if (SimManager.LastStage == null) if (SimManager.LastStage == null)
{ {
return double.NaN; return double.NaN;
} }
   
return SimManager.LastStage.actualThrustToWeight; return SimManager.LastStage.actualThrustToWeight;
}, },
"" ""
); );
   
public static readonly VOID_DoubleValue maxThrustWeight = new VOID_DoubleValue( public static readonly VOID_DoubleValue maxThrustWeight = new VOID_DoubleValue(
"T:W Ratio", "T:W Ratio",
delegate() delegate()
{ {
if (SimManager.LastStage == null) if (SimManager.LastStage == null)
{ {
return double.NaN; return double.NaN;
} }
   
return SimManager.LastStage.thrustToWeight; return SimManager.LastStage.thrustToWeight;
}, },
"" ""
); );
   
public static readonly VOID_StrValue currmaxThrustWeight = new VOID_StrValue( public static readonly VOID_StrValue currmaxThrustWeight = new VOID_StrValue(
"T:W (curr/max)", "T:W (curr/max)",
delegate() delegate()
{ {
if (SimManager.Stages == null || SimManager.LastStage == null) if (SimManager.Stages == null || SimManager.LastStage == null)
return "N/A"; return "N/A";
   
return string.Format( return string.Format(
"{0} / {1}", "{0} / {1}",
(VOID_Data.currThrustWeight.Value).ToString("F2"), (VOID_Data.currThrustWeight.Value).ToString("F2"),
(VOID_Data.maxThrustWeight.Value).ToString("F2") (VOID_Data.maxThrustWeight.Value).ToString("F2")
); );
} }
); );
   
public static readonly VOID_DoubleValue surfaceThrustWeight = new VOID_DoubleValue( public static readonly VOID_DoubleValue surfaceThrustWeight = new VOID_DoubleValue(
"Max T:W @ surface", "Max T:W @ surface",
delegate() delegate()
{ {
if (SimManager.Stages == null || SimManager.LastStage == null) if (SimManager.Stages == null || SimManager.LastStage == null)
return double.NaN; return double.NaN;
   
double maxThrust = SimManager.LastStage.thrust; double maxThrust = SimManager.LastStage.thrust;
double mass = SimManager.LastStage.totalMass; double mass = SimManager.LastStage.totalMass;
double gravity = (VOID_Core.Constant_G * core.vessel.mainBody.Mass) / double gravity = (VOID_Core.Constant_G * core.vessel.mainBody.Mass) /
(core.vessel.mainBody.Radius * core.vessel.mainBody.Radius); (core.vessel.mainBody.Radius * core.vessel.mainBody.Radius);
double weight = mass * gravity; double weight = mass * gravity;
   
return maxThrust / weight; return maxThrust / weight;
}, },
"" ""
); );
   
public static readonly VOID_StrValue intakeAirStatus = new VOID_StrValue( public static readonly VOID_StrValue intakeAirStatus = new VOID_StrValue(
"Intake Air (Curr / Req)", "Intake Air (Curr / Req)",
delegate() delegate()
{ {
double currentAmount; double currentAmount;
double currentRequirement; double currentRequirement;
   
currentAmount = 0d; currentAmount = 0d;
currentRequirement = 0d; currentRequirement = 0d;
   
foreach (Part part in core.vessel.Parts) foreach (Part part in core.vessel.Parts)
{ {
if (part.enabled) if (part.enabled)
{ {
ModuleEngines engineModule; ModuleEngines engineModule;
ModuleEnginesFX enginesFXModule; ModuleEnginesFX enginesFXModule;
List<Propellant> propellantList = null; List<Propellant> propellantList = null;
   
if (part.tryGetFirstModuleOfType<ModuleEngines>(out engineModule)) if (part.tryGetFirstModuleOfType<ModuleEngines>(out engineModule))
{ {
propellantList = engineModule.propellants; propellantList = engineModule.propellants;
} }
else if (part.tryGetFirstModuleOfType<ModuleEnginesFX>(out enginesFXModule)) else if (part.tryGetFirstModuleOfType<ModuleEnginesFX>(out enginesFXModule))
{ {
propellantList = enginesFXModule.propellants; propellantList = enginesFXModule.propellants;
} }
if (propellantList != null) if (propellantList != null)
{ {
foreach (Propellant propellant in propellantList) foreach (Propellant propellant in propellantList)
{ {
if (propellant.name == "IntakeAir") if (propellant.name == "IntakeAir")
{ {
currentRequirement += propellant.currentRequirement / TimeWarp.fixedDeltaTime; currentRequirement += propellant.currentRequirement / TimeWarp.fixedDeltaTime;
break; break;
} }
} }
} }
} }
   
ModuleResourceIntake intakeModule; ModuleResourceIntake intakeModule;
   
if (part.enabled && part.tryGetFirstModuleOfType<ModuleResourceIntake>(out intakeModule)) if (part.enabled && part.tryGetFirstModuleOfType<ModuleResourceIntake>(out intakeModule))
{ {
if (intakeModule.resourceName == "IntakeAir") if (intakeModule.resourceName == "IntakeAir")
{ {
currentAmount += intakeModule.airFlow; currentAmount += intakeModule.airFlow;
} }
} }
} }
   
if (currentAmount == 0 && currentRequirement == 0) if (currentAmount == 0 && currentRequirement == 0)
{ {
return "N/A"; return "N/A";
} }
   
return string.Format("{0:F3} / {1:F3}", currentAmount, currentRequirement); return string.Format("{0:F3} / {1:F3}", currentAmount, currentRequirement);
} }
); );
} }
} }