Skip to content

Commit 557f45e

Browse files
authored
Merge pull request #14 from Falki-git/stage-in-oab
Show StageInfo window in OAB/VAB
2 parents 41cb413 + b3aa902 commit 557f45e

File tree

8 files changed

+778
-82
lines changed

8 files changed

+778
-82
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using KSP.Game;
2+
using KSP.Sim.Definitions;
3+
4+
namespace MicroMod
5+
{
6+
internal class MicroCelestialBodies
7+
{
8+
public List<CelestialBody> Bodies = new();
9+
10+
/// <summary>
11+
/// Refreshes the list of all CelestialBodies. Does nothing if list is already populated.
12+
/// </summary>
13+
/// <returns>True = refresh completed successfully or list is already populated</returns>
14+
internal bool GetBodies()
15+
{
16+
if (this.Bodies.Count > 0)
17+
return true;
18+
19+
Dictionary<string, CelestialBodyCore> bodies = GameManager.Instance?.Game?.CelestialBodies?.GetAllBodiesData();
20+
21+
if (bodies == null || bodies.Count == 0)
22+
return false;
23+
24+
foreach (var body in bodies)
25+
{
26+
this.Bodies.Add(new CelestialBody
27+
{
28+
Name = body.Value.data.bodyName,
29+
GravityASL = body.Value.data.gravityASL,
30+
HasAtmosphere = body.Value.data.hasAtmosphere,
31+
IsHomeWorld = body.Value.data.isHomeWorld
32+
});
33+
}
34+
35+
return true;
36+
}
37+
38+
/// <summary>
39+
/// Calculates what factor needs to be used for HomeWorld's TWR in order to compensate for gravity of the selected body
40+
/// </summary>
41+
/// <param name="bodyName">Name of the CelestialBody for which the TWR factor is calculated</param>
42+
/// <returns>TWR factor that needs to be multiplied with HomeWorld's TWR to get TWR at the selected body and information if target body has an atmosphere</returns>
43+
internal (double twrFactor, bool hasAtmosphere) GetTwrFactor(string bodyName)
44+
{
45+
if (Bodies.Count == 0) return (0, false);
46+
CelestialBody homeWorld = Bodies.Find(b => b.IsHomeWorld);
47+
CelestialBody targetBody = Bodies.Find(t => t.Name.ToLowerInvariant() == bodyName.ToLowerInvariant()) ?? null;
48+
if (targetBody == null) return (0, false);
49+
50+
return (homeWorld.GravityASL / targetBody.GravityASL, targetBody.HasAtmosphere);
51+
}
52+
}
53+
54+
internal class CelestialBody
55+
{
56+
public string Name;
57+
public double GravityASL;
58+
public bool HasAtmosphere;
59+
public bool IsHomeWorld;
60+
}
61+
}

0 commit comments

Comments
 (0)