-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLiquidEngine.cs
111 lines (99 loc) · 3.49 KB
/
LiquidEngine.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
namespace MajiirKerbalLib
{
public class LiquidEngine : global::LiquidEngine, IEngine
{
public bool EngineEnabled
{
get { return engineEnabled; }
private set
{
if (engineEnabled && !value)
{
realMaxThrust = maxThrust;
realMinThrust = minThrust;
maxThrust = minThrust = 0;
}
if (!engineEnabled && value)
{
maxThrust = realMaxThrust;
minThrust = realMinThrust;
}
engineEnabled = value;
}
}
[KSPField]
private bool engineEnabled = true;
private float realMaxThrust;
private float realMinThrust;
public float MaxThrust
{
get { return this.maxThrust; }
}
protected override void onCtrlUpd(FlightCtrlState s)
{
var state = Utilities.CopyFlightCtrlState(s);
state.mainThrottle = EngineEnabled ? EngineCommander.UpdateThrust(state.mainThrottle, this) : 0;
if (state.mainThrottle == 0)
{
state.pitch = state.roll = state.yaw = 0;
}
base.onCtrlUpd(state);
}
public float RealIsp
{
get
{
var massFlowrate = (this.fuelConsumption / Utilities.FuelDensity);
return this.MaxThrust / (massFlowrate * Utilities.SurfaceGravity);
}
}
[KSPField(guiActive = true, guiName = "Specific Impulse", guiUnits = "s", guiFormat = "F1", isPersistant = false)]
private float realIsp;
protected override void onActiveFixedUpdate()
{
var temp = this.temperature;
base.onActiveFixedUpdate();
if (!this.EngineEnabled)
{
this.temperature = temp;
}
}
protected override void onPartFixedUpdate()
{
base.onPartFixedUpdate();
var commander = VesselCommander.GetInstance(this.vessel).EngineCommander;
Events["DisableCommander"].active = commander.IsActive;
Events["EnableCommander"].active = !commander.IsActive;
realIsp = RealIsp;
}
[KSPEvent(guiActive = true, guiName = "Enable Command", active = false)]
public void EnableCommander()
{
Events["DisableCommander"].active = true;
Events["EnableCommander"].active = false;
VesselCommander.GetInstance(this.vessel).EngineCommander.IsActive = true;
}
[KSPEvent(guiActive = true, guiName = "Disable Command")]
public void DisableCommander()
{
Events["DisableCommander"].active = false;
Events["EnableCommander"].active = true;
VesselCommander.GetInstance(this.vessel).EngineCommander.IsActive = false;
}
[KSPEvent(guiActive = true, guiName = "Activate", active = false)]
public void EnableEngine()
{
Events["DisableEngine"].active = true;
Events["EnableEngine"].active = false;
EngineEnabled = true;
}
[KSPEvent(guiActive = true, guiName = "Deactivate")]
public void DisableEngine()
{
Events["DisableEngine"].active = false;
Events["EnableEngine"].active = true;
EngineEnabled = false;
}
}
}