-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mach scaling and flow modification based on velocity and atmosp…
…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
Showing
13 changed files
with
221 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -36,8 +32,6 @@ namespace KerbalEngineer | |
|
||
public static class CelestialBodies | ||
{ | ||
#region Constructors | ||
|
||
static CelestialBodies() | ||
{ | ||
try | ||
|
@@ -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> | ||
|
@@ -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) | ||
|
@@ -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; | ||
|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.