Skip to content

Commit

Permalink
Added mach scaling and flow modification based on velocity and atmosp…
Browse files Browse the repository at this point in the history
…heric curves.

Atmospheric scale is now based on altitude in the editor.
Clamped altitude to the atmospheric depth of the body.
Clamped mach speed on the maximum usabled mach value of engines on vessel.
  • Loading branch information
CYBUTEK committed Apr 26, 2015
1 parent aebe3e9 commit d190e91
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 263 deletions.
13 changes: 13 additions & 0 deletions Documents/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
1.0.16.1, 26-04-2015, KSP Build #828
Merged Sarbian's mach adjustments.
Fixed bugs relating to thrust and atmosphere/velocity curves.
Changed the atmospheric slider on the Build Engineer to work based on altitude.
Changed the atmospheric slider to clamp to the maximum altitude for the selected body.
Changed the velocity slider to clamp to the maximum usable mach value for the current vessel.

1.0.16.0, 25-04-2015, KSP Build #821
Fixed errors relating to KSP 1.0 update.
Fixed fuel simulation to account for new thrust system.
Fixed atmospheric engines to use the new velocity curve.
Fixed atmospheric readouts to work with the new atmospheric model.

1.0.15.2, 13-02-2015
Padishar's Fixes:
Fixed: Calculation of per-stage resource mass.
Expand Down
113 changes: 47 additions & 66 deletions KerbalEngineer/CelestialBodies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#region Using Directives

using System;
using System.Collections.Generic;
using System.Linq;

#endregion

namespace KerbalEngineer
{
using System;
using System.Collections.Generic;
using System.Linq;

/*
*
* With thanks to Nathaniel R. Lewis (aka. Teknoman117) ([email protected]) for working out
Expand All @@ -36,8 +32,6 @@ namespace KerbalEngineer

public static class CelestialBodies
{
#region Constructors

static CelestialBodies()
{
try
Expand All @@ -55,17 +49,9 @@ static CelestialBodies()
}
}

#endregion

#region Properties

public static BodyInfo SelectedBody { get; private set; }
public static BodyInfo SystemBody { get; private set; }

#endregion

#region Public Methods

/// <summary>
/// Gets a body given a supplied body name.
/// </summary>
Expand All @@ -89,7 +75,7 @@ public static bool SetSelectedBody(string bodyName)
{
try
{
var body = GetBodyInfo(bodyName);
BodyInfo body = GetBodyInfo(bodyName);
if (body != null)
{
if (SelectedBody != null)
Expand All @@ -108,71 +94,55 @@ public static bool SetSelectedBody(string bodyName)
return false;
}

#endregion

#region Nested type: BodyInfo

public class BodyInfo
{
#region Constructors

public BodyInfo(CelestialBody body, BodyInfo parent = null)
{
try
{
// Set the body information.
this.CelestialBody = body;
this.Name = body.bodyName;
this.Gravity = 9.81 * body.GeeASL;
this.Atmosphere = body.atmosphere ? body.atmospherePressureSeaLevel : 0;
this.Parent = parent;
CelestialBody = body;
Name = body.bodyName;
Gravity = 9.81 * body.GeeASL;
Parent = parent;

// Set orbiting bodies information.
this.Children = new List<BodyInfo>();
foreach (var orbitingBody in body.orbitingBodies)
Children = new List<BodyInfo>();
foreach (CelestialBody orbitingBody in body.orbitingBodies)
{
this.Children.Add(new BodyInfo(orbitingBody, this));
Children.Add(new BodyInfo(orbitingBody, this));
}

this.SelectedDepth = 0;
SelectedDepth = 0;
}
catch (Exception ex)
{
Logger.Exception(ex);
}
}

#endregion

#region Properties

public string Name { get; private set; }
public CelestialBody CelestialBody { get; private set; }
public List<BodyInfo> Children { get; private set; }
public double Gravity { get; private set; }
public double Atmosphere { get; private set; }
public string Name { get; private set; }
public BodyInfo Parent { get; private set; }
public List<BodyInfo> Children { get; private set; }
public CelestialBody CelestialBody { get; private set; }
public bool Selected { get; private set; }
public int SelectedDepth { get; private set; }

#endregion

#region Public Methods

public BodyInfo GetBodyInfo(string bodyName)
{
try
{
// This is the searched body.
if (String.Equals(this.Name, bodyName, StringComparison.CurrentCultureIgnoreCase))
if (String.Equals(Name, bodyName, StringComparison.CurrentCultureIgnoreCase))
{
return this;
}

// Check to see if any of this bodies children are the searched body.
foreach (var child in this.Children)
foreach (BodyInfo child in Children)
{
var body = child.GetBodyInfo(bodyName);
BodyInfo body = child.GetBodyInfo(bodyName);
if (body != null)
{
return body;
Expand All @@ -188,33 +158,44 @@ public BodyInfo GetBodyInfo(string bodyName)
return null;
}

public double GetDensity(double altitude)
{
return CelestialBody.GetDensity(GetPressure(altitude), GetTemperature(altitude));
}

public double GetPressure(double altitude)
{
return CelestialBody.GetPressure(altitude);
}

public double GetTemperature(double altitude)
{
return CelestialBody.GetTemperature(altitude);
}

public double GetAtmospheres(double altitude)
{
return GetPressure(altitude) * PhysicsGlobals.KpaToAtmospheres;
}

public void SetSelected(bool state, int depth = 0)
{
this.Selected = state;
this.SelectedDepth = depth;
if (this.Parent != null)
Selected = state;
SelectedDepth = depth;
if (Parent != null)
{
this.Parent.SetSelected(state, depth + 1);
Parent.SetSelected(state, depth + 1);
}
}

#endregion

#region Debugging

public override string ToString()
{
var log = "\n" + this.Name +
"\n\tGravity: " + this.Gravity +
"\n\tAtmosphere: " + this.Atmosphere +
"\n\tSelected: " + this.Selected;
string log = "\n" + Name +
"\n\tGravity: " + Gravity +
"\n\tSelected: " + Selected;

return this.Children.Aggregate(log, (current, child) => current + "\n" + child);
return Children.Aggregate(log, (current, child) => current + "\n" + child);
}

#endregion
}

#endregion
}
}
10 changes: 5 additions & 5 deletions KerbalEngineer/Editor/BuildAdvanced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ namespace KerbalEngineer.Editor
public class BuildAdvanced : MonoBehaviour
{
#region Fields
public static float Altitude = 500.0f;

private GUIStyle areaSettingStyle;
private GUIStyle areaStyle;
private float atmosphericPercentage = 1.0f;
private float atmosphericMach;
private GUIStyle bodiesButtonActiveStyle;
private GUIStyle bodiesButtonStyle;
Expand Down Expand Up @@ -256,7 +256,7 @@ protected void Update()

if (this.showAtmosphericDetails)
{
SimManager.Atmosphere = CelestialBodies.SelectedBody.Atmosphere * 0.01d * this.atmosphericPercentage;
SimManager.Atmosphere = CelestialBodies.SelectedBody.GetAtmospheres(Altitude);
}
else
{
Expand Down Expand Up @@ -296,9 +296,9 @@ private void DrawAtmosphericDetails()
{
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
GUILayout.Label("Pressure: " + (this.atmosphericPercentage * 100.0f).ToString("F1") + "%", this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
GUILayout.Label("Altitude: " + (Altitude * 0.001f).ToString("F1") + "km", this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
GUI.skin = HighLogic.Skin;
this.atmosphericPercentage = GUILayout.HorizontalSlider(this.atmosphericPercentage, 0, 1.0f);
Altitude = GUILayout.HorizontalSlider(Altitude, 0.0f, (float)(CelestialBodies.SelectedBody.CelestialBody.atmosphereDepth));
GUI.skin = null;
GUILayout.EndVertical();

Expand All @@ -307,7 +307,7 @@ private void DrawAtmosphericDetails()
GUILayout.BeginVertical();
GUILayout.Label("Mach: " + this.atmosphericMach.ToString("F1") + "m/s", this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
GUI.skin = HighLogic.Skin;
this.atmosphericMach = GUILayout.HorizontalSlider(this.atmosphericMach, 0, 25f); // the game limits mach to 50 but I did not see curve with more than 25
atmosphericMach = GUILayout.HorizontalSlider(atmosphericMach, 0.0f, SimManager.LastStage.maxMach); // the game limits mach to 50 but I did not see curve with more than 25
GUI.skin = null;
GUILayout.EndVertical();
GUILayout.EndHorizontal();
Expand Down
2 changes: 1 addition & 1 deletion KerbalEngineer/Editor/BuildOverlayVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void SetVesselInfo()

if (BuildAdvanced.Instance.ShowAtmosphericDetails)
{
SimManager.Atmosphere = CelestialBodies.SelectedBody.Atmosphere * 0.01;
SimManager.Atmosphere = CelestialBodies.SelectedBody.GetAtmospheres(BuildAdvanced.Altitude);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion KerbalEngineer/EngineerGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class EngineerGlobals
/// <summary>
/// Current version of the Kerbal Engineer assembly.
/// </summary>
public const string AssemblyVersion = "1.0.15.2";
public const string AssemblyVersion = "1.0.16.1";

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public class AtmosphericProcessor : IUpdatable, IUpdateRequest
/// </summary>
public static AtmosphericProcessor Instance
{
get { return instance; }
get
{
return instance;
}
}

#endregion
Expand Down
Loading

0 comments on commit d190e91

Please sign in to comment.