-
Notifications
You must be signed in to change notification settings - Fork 6
/
BalloonProperties.cs
71 lines (60 loc) · 3.16 KB
/
BalloonProperties.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
using System.Collections.Generic;
using UnityEngine;
namespace KerBalloons
{
public class BalloonProperties
{
public static float getLift(ModuleKerBalloon thisBalloon)
{
float atmoPressure = (float)FlightGlobals.getStaticPressure(thisBalloon.part.transform.position);
float coefficient = (thisBalloon.minLift - thisBalloon.maxLift) / Mathf.Pow(thisBalloon.maxAtmoPressure, 2);
float x = Mathf.Pow(atmoPressure - thisBalloon.maxAtmoPressure - thisBalloon.minAtmoPressure, 2);
float yInt = thisBalloon.maxLift;
float lift = coefficient * x + yInt;
float max = lift;
float liftLimit = (thisBalloon.vessel.GetTotalMass() * (float)FlightGlobals.getGeeForceAtPosition(thisBalloon.transform.position).magnitude) / lift;
lift *= liftLimit * thisBalloon.targetTWR;
if (thisBalloon.speedLimiter)
{
if (thisBalloon.vessel.verticalSpeed < thisBalloon.maxSpeed * (1 - thisBalloon.maxSpeedTolerence))
{
thisBalloon.speedAdjust += thisBalloon.speedAdjustStep * (thisBalloon.maxSpeed - (float)thisBalloon.vessel.verticalSpeed);
}
else if (thisBalloon.vessel.verticalSpeed > thisBalloon.maxSpeed * (1 + thisBalloon.maxSpeedTolerence))
{
thisBalloon.speedAdjust -= thisBalloon.speedAdjustStep * ((float)thisBalloon.vessel.verticalSpeed - thisBalloon.maxSpeed);
}
thisBalloon.speedAdjust = Mathf.Clamp(thisBalloon.speedAdjust, thisBalloon.speedAdjustMin, thisBalloon.speedAdjustMax);
lift *= thisBalloon.speedAdjust;
}
if(thisBalloon.isInflated || thisBalloon.isInflating) lift /= getInflatedBalloons(thisBalloon.vessel).Count;
lift = Mathf.Clamp(lift, 0, max);
return lift;
}
public static float getScale(ModuleKerBalloon thisBalloon)
{
float atmoPressure = (float)FlightGlobals.getStaticPressure(thisBalloon.part.transform.position);
float coefficient = (thisBalloon.maxScale - thisBalloon.minScale) / Mathf.Pow(thisBalloon.maxAtmoPressure, 2);
float x = Mathf.Pow(atmoPressure - thisBalloon.maxAtmoPressure - thisBalloon.minAtmoPressure, 2);
float yInt = thisBalloon.minScale;
float scale = coefficient * x + yInt;
return scale;
}
public static List<ModuleKerBalloon> getInflatedBalloons(Vessel vessel)
{
List<ModuleKerBalloon> balloons = new List<ModuleKerBalloon>();
foreach(Part part in vessel.parts)
{
if (part.GetComponent<ModuleKerBalloon>())
{
ModuleKerBalloon balloon = part.GetComponent<ModuleKerBalloon>();
if ((balloon.isInflated || balloon.isInflating) && !balloon.hasBurst)
{
balloons.Add(balloon);
}
}
}
return balloons;
}
}
}