VOID_VesselInfo: Converted to use VOID_DataValues.
VOID_VesselInfo: Converted to use VOID_DataValues.

// //
// VOID_Orbital.cs // VOID_Orbital.cs
// //
// Author: // Author:
// toadicus <> // toadicus <>
// //
// Copyright (c) 2013 toadicus // Copyright (c) 2013 toadicus
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using KSP; using KSP;
using System; using System;
  using System.Collections.Generic;
using UnityEngine; using UnityEngine;
   
namespace VOID namespace VOID
{ {
public class VOID_VesselInfo : VOID_WindowModule public class VOID_VesselInfo : VOID_WindowModule
{ {
[AVOID_SaveValue("toggleExtended")] [AVOID_SaveValue("toggleExtended")]
protected VOID_SaveValue<bool> toggleExtended = false; protected VOID_SaveValue<bool> toggleExtended = false;
   
public VOID_VesselInfo() protected VOID_DoubleValue geeForce = new VOID_DoubleValue(
  "G-force",
  new Func<double>(() => VOID_Core.Instance.vessel.geeForce),
  "gees"
  );
   
  protected VOID_IntValue partCount = new VOID_IntValue(
  "Parts",
  new Func<int>(() => VOID_Core.Instance.vessel.Parts.Count),
  ""
  );
   
  protected VOID_DoubleValue totalMass = new VOID_DoubleValue(
  "Total Mass",
  new Func<double>(() => VOID_Core.Instance.vessel.GetTotalMass()),
  "tons"
  );
   
  protected VOID_DoubleValue resourceMass = new VOID_DoubleValue(
  "Resource Mass",
  delegate()
  {
  double rscMass = 0;
  foreach (Part part in VOID_Core.Instance.vessel.Parts)
  {
  rscMass += part.GetResourceMass();
  }
  return rscMass;
  },
  "tons"
  );
   
  protected VOID_DoubleValue stageDeltaV = new VOID_DoubleValue(
  "DeltaV (Current Stage)",
  delegate()
  {
  if (Engineer.VesselSimulator.SimManager.Instance.Stages == null)
  return double.NaN;
  return Engineer.VesselSimulator.SimManager.Instance.Stages[Staging.lastStage].deltaV;
  },
  "m/s"
  );
   
  protected VOID_DoubleValue totalDeltaV = new VOID_DoubleValue(
  "DeltaV (Total)",
  delegate()
  {
  if (Engineer.VesselSimulator.SimManager.Instance.Stages == null)
  return double.NaN;
  return Engineer.VesselSimulator.SimManager.Instance.LastStage.totalDeltaV;
  },
  "m/s"
  );
   
  protected VOID_FloatValue mainThrottle = new VOID_FloatValue(
  "Throttle",
  new Func<float>(() => VOID_Core.Instance.vessel.ctrlState.mainThrottle * 100f),
  "%"
  );
   
  protected VOID_StrValue currmaxThrust = new VOID_StrValue(
  "Thrust (curr/max)",
  delegate()
  {
  if (Engineer.VesselSimulator.SimManager.Instance.Stages == null)
  return "N/A";
   
  double currThrust = Engineer.VesselSimulator.SimManager.Instance.LastStage.actualThrust;
  double maxThrust = Engineer.VesselSimulator.SimManager.Instance.LastStage.thrust;
   
  return string.Format(
  "{0} / {1}",
  currThrust.ToString("F1"),
  maxThrust.ToString("F1")
  );
  }
  );
   
  protected VOID_StrValue currmaxThrustWeight = new VOID_StrValue(
  "T:W (curr/max)",
  delegate()
  {
  if (Engineer.VesselSimulator.SimManager.Instance.Stages == null)
  return "N/A";
   
  double currThrust = Engineer.VesselSimulator.SimManager.Instance.LastStage.actualThrust;
  double maxThrust = Engineer.VesselSimulator.SimManager.Instance.LastStage.thrust;
  double mass = VOID_Core.Instance.vessel.GetTotalMass();
  double gravity = VOID_Core.Instance.vessel.mainBody.gravParameter /
  Math.Pow(
  VOID_Core.Instance.vessel.mainBody.Radius + VOID_Core.Instance.vessel.altitude,
  2
  );
  double weight = mass * gravity;
   
  return string.Format(
  "{0} / {1}",
  (currThrust / weight).ToString("F2"),
  (maxThrust / weight).ToString("F2")
  );
  }
  );
   
  protected VOID_DoubleValue surfaceThrustWeight = new VOID_DoubleValue(
  "Max T:W @ surface",
  delegate()
  {
  if (Engineer.VesselSimulator.SimManager.Instance.Stages == null)
  return double.NaN;
   
  double maxThrust = Engineer.VesselSimulator.SimManager.Instance.LastStage.thrust;
  double mass = VOID_Core.Instance.vessel.GetTotalMass();
  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;
   
  return maxThrust / weight;
  },
  ""
  );
   
  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 _)
{ {
  base.ModuleWindow (_);
   
if ((TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate)) if ((TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate))
{ {
Engineer.VesselSimulator.SimManager.Instance.RequestSimulation(); Engineer.VesselSimulator.SimManager.Instance.RequestSimulation();
} }
   
Engineer.VesselSimulator.Stage[] stages = Engineer.VesselSimulator.SimManager.Instance.Stages; Engineer.VesselSimulator.Stage[] stages = Engineer.VesselSimulator.SimManager.Instance.Stages;
   
GUILayout.BeginVertical(); GUILayout.BeginVertical();
   
GUILayout.Label( GUILayout.Label(
vessel.vesselName, vessel.vesselName,
VOID_Core.Instance.LabelStyles["center_bold"], VOID_Core.Instance.LabelStyles["center_bold"],
GUILayout.ExpandWidth(true)); GUILayout.ExpandWidth(true));
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); this.geeForce.DoGUIHorizontal ("F2");
GUILayout.Label("G-force:");  
GUILayout.Label(vessel.geeForce.ToString("F2") + " gees", GUILayout.ExpandWidth(false)); this.partCount.DoGUIHorizontal ();
GUILayout.EndHorizontal();  
  this.totalMass.DoGUIHorizontal ("F1");
int num_parts = 0;  
double total_mass = vessel.GetTotalMass(); this.resourceMass.DoGUIHorizontal ("F1");
double resource_mass = 0;  
double max_thrust = 0; if (stages != null) {
double final_thrust = 0; if (stages.Length > Staging.lastStage) {
  this.stageDeltaV.DoGUIHorizontal (3, false);
foreach (Part p in vessel.parts)  
{  
num_parts++;  
resource_mass += p.GetResourceMass();  
   
foreach (PartModule pm in p.Modules)  
{  
if ((pm.moduleName == "ModuleEngines") &&  
((p.State == PartStates.ACTIVE) ||  
((Staging.CurrentStage > Staging.lastStage) && (p.inverseStage == Staging.lastStage)))  
)  
{  
max_thrust += ((ModuleEngines)pm).maxThrust;  
final_thrust += ((ModuleEngines)pm).finalThrust;  
}  
}  
}  
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("Parts:");  
GUILayout.Label(num_parts.ToString("F0"), GUILayout.ExpandWidth(false));  
GUILayout.EndHorizontal();  
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("Total mass:");  
GUILayout.Label(total_mass.ToString("F1") + " tons", GUILayout.ExpandWidth(false));  
GUILayout.EndHorizontal();  
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("Resource mass:");  
GUILayout.Label(resource_mass.ToString("F1") + " tons", GUILayout.ExpandWidth(false));  
GUILayout.EndHorizontal();  
   
if (stages.Length > Staging.lastStage)  
{  
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("DeltaV (Current Stage):");  
GUILayout.Label(  
Tools.MuMech_ToSI(stages[Staging.lastStage].deltaV).ToString() + "m/s",  
GUILayout.ExpandWidth(false));  
GUILayout.EndHorizontal();  
}  
   
if (stages.Length > 0)  
{  
double totalDeltaV = 0d;  
   
for (int i = 0; i < stages.Length; ++i)  
{  
totalDeltaV += stages [i].deltaV;  
} }
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (stages.Length > 0) {
GUILayout.Label("DeltaV (Total):"); this.totalDeltaV.DoGUIHorizontal (3, false);
GUILayout.Label(Tools.MuMech_ToSI(totalDeltaV).ToString() + "m/s", GUILayout.ExpandWidth(false)); }
GUILayout.EndHorizontal(); }
}  
  this.mainThrottle.DoGUIHorizontal ("F0");
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("Throttle:"); this.currmaxThrust.DoGUIHorizontal ();
GUILayout.Label((vessel.ctrlState.mainThrottle * 100f).ToString("F0") + "%", GUILayout.ExpandWidth(false));  
GUILayout.EndHorizontal(); this.currmaxThrustWeight.DoGUIHorizontal ();
   
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); this.surfaceThrustWeight.DoGUIHorizontal ("F2");
GUILayout.Label("Thrust (curr/max):");  
GUILayout.Label(  
final_thrust.ToString("F1") +  
" / " + max_thrust.ToString("F1") + " kN",  
GUILayout.ExpandWidth(false));  
GUILayout.EndHorizontal();  
   
double gravity = vessel.mainBody.gravParameter / Math.Pow(vessel.mainBody.Radius + vessel.altitude, 2);  
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("T:W (curr/max):");  
GUILayout.Label(  
(final_thrust / (total_mass * gravity)).ToString("F2") +  
" / " + (max_thrust / (total_mass * gravity)).ToString("F2"),  
GUILayout.ExpandWidth(false));  
GUILayout.EndHorizontal();  
   
double g_ASL = (VOID_Core.Constant_G * vessel.mainBody.Mass) / Math.Pow(vessel.mainBody.Radius, 2);  
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));  
GUILayout.Label("Max T:W @ surface:");  
GUILayout.Label((max_thrust / (total_mass * g_ASL)).ToString("F2"), GUILayout.ExpandWidth(false));  
GUILayout.EndHorizontal();  
   
GUILayout.EndVertical(); GUILayout.EndVertical();
GUI.DragWindow(); GUI.DragWindow();
} }
} }
} }