-
Notifications
You must be signed in to change notification settings - Fork 0
/
VesselComputer.cs
166 lines (136 loc) · 4.01 KB
/
VesselComputer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
namespace FlightComputer
{
public class VesselComputer
{
public Vessel Vessel;
public VesselComputer(Vessel trackedVessel)
{
this.Vessel = trackedVessel;
}
// Various flight calculations.
public double GetCurrentGForces()
{
return this.Vessel.geeForce;
}
// Orbital data calculations.
public double GetApoapsisHeight()
{
return this.Vessel.orbit.ApA;
}
public double GetTimeToApoapsis()
{
return this.Vessel.orbit.timeToAp;
}
public double GetPeriapsisHeight()
{
return this.Vessel.orbit.PeA;
}
public double GetTimeToPeriapsis()
{
return this.Vessel.orbit.timeToPe;
}
public double GetOrbitalInclination()
{
return this.Vessel.orbit.inclination;
}
public double GetOrbitalEccentricity()
{
return this.Vessel.orbit.eccentricity;
}
public double GetOrbitalPeriod()
{
return this.Vessel.orbit.period;
}
public double GetLongitudeOfAN()
{
return this.Vessel.orbit.LAN;
}
public double GetLongitudeOfPe()
{
return this.Vessel.orbit.LAN + this.Vessel.orbit.argumentOfPeriapsis;
}
public double GetSemiMajorAxis()
{
return this.Vessel.orbit.semiMajorAxis;
}
public double GetSemiMinorAxis()
{
return this.Vessel.orbit.semiMinorAxis;
}
// Surface flight calculations.
public double GetSeaLevelAltitude()
{
return this.Vessel.mainBody.GetAltitude(this.Vessel.CoM);
}
public double GetTerrainAltitude()
{
return this.GetSeaLevelAltitude() - this.Vessel.terrainAltitude;
}
public double GetHorizontalSurfaceSpeed()
{
return this.Vessel.verticalSpeed;
}
public double GetVerticalSurfaceSpeed()
{
return this.Vessel.horizontalSrfSpeed;
}
public double GetLongitude()
{
return this.Vessel.longitude;
}
public double GetLatitude()
{
return this.Vessel.latitude;
}
public double GetGForce()
{
return this.Vessel.geeForce;
}
// Aerodynamic calculations.
public double GetTerminalVelocity()
{
if (this.Vessel.atmDensity <= 0)
{
return 0;
}
return Math.Sqrt(
(2 * this.GetTotalPartMass() * FlightGlobals.getGeeForceAtPosition(this.Vessel.CoM).magnitude)
/ (this.Vessel.atmDensity * this.GetTotalPartDrag() * FlightGlobals.DragMultiplier)
);
}
public double GetAtmosphericEfficiency()
{
double terminalVelocity = this.GetTerminalVelocity();
if (terminalVelocity <= 0)
{
return 0;
}
return FlightGlobals.ship_srfSpeed / terminalVelocity;
}
public double GetAtmosphericDragForce()
{
return (this.Vessel.atmDensity * Math.Pow(FlightGlobals.ship_srfSpeed, 2)
* this.GetTotalPartDrag() * FlightGlobals.DragMultiplier) / 2;
}
// Craft calculations.
public double GetTotalPartMass()
{
double totalMass = 0;
foreach (Part part in this.Vessel.parts)
{
totalMass += part.mass + part.GetResourceMass();
}
return totalMass;
}
public double GetTotalPartDrag()
{
double totalDrag = 0;
foreach (Part part in this.Vessel.parts)
{
totalDrag += (part.mass + part.GetResourceMass()) * part.maximum_drag;
}
return totalDrag;
}
}
}