-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTranslatron.cs
104 lines (87 loc) · 2.59 KB
/
Translatron.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
using System;
using System.Reflection;
using KRPC.MechJeb.ExtensionMethods;
using KRPC.Service.Attributes;
namespace KRPC.MechJeb {
/// <summary>
/// The Translatron module controls the vessel's throttle/velocity.
/// </summary>
[KRPCClass(Service = "MechJeb")]
public class Translatron : DisplayModule {
internal new const string MechJebType = "MuMech.MechJebModuleTranslatron";
// Fields and methods
private static FieldInfo transSpd;
private static MethodInfo setMode;
private static MethodInfo panicSwitch;
internal static new void InitType(Type type) {
transSpd = type.GetCheckedField("trans_spd");
setMode = type.GetCheckedMethod("SetMode");
panicSwitch = type.GetCheckedMethod("PanicSwitch");
}
/// <summary>
/// Speed which trasnlatron will hold
/// </summary>
[KRPCProperty]
public double TranslationSpeed {
get => EditableDouble.Get(transSpd, this.instance);
set {
EditableDouble.Set(transSpd, this.instance, value);
ThrustController.transSpdAct.SetValue(MechJeb.ThrustController.instance, (float)value);
}
}
/// <summary>
/// Kill horizontal speed
/// </summary>
[KRPCProperty]
public bool KillHorizontalSpeed {
get => (bool)ThrustController.transKillH.GetValue(MechJeb.ThrustController.instance);
set => ThrustController.transKillH.SetValue(MechJeb.ThrustController.instance, value);
}
/// <summary>
/// Current translatron mode.
/// </summary>
[KRPCProperty]
public TranslatronMode Mode {
get => (TranslatronMode)ThrustController.tMode.GetValue(MechJeb.ThrustController.instance, null);
set {
if(value == TranslatronMode.KeepRelative || value == TranslatronMode.Direct)
throw new MJServiceException("Cannot set TranslatronMode to internal values");
setMode.Invoke(this.instance, new object[] { (int)value });
}
}
/// <summary>
/// Abort mission by seperating all but the last stage and activating landing autopilot.
/// </summary>
[KRPCMethod]
public void PanicSwitch() {
panicSwitch.Invoke(this.instance, null);
}
[KRPCEnum(Service = "MechJeb")]
public enum TranslatronMode {
/// <summary>
/// Switch off Translatron.
/// </summary>
Off,
/// <summary>
/// Keep orbital velocity.
/// </summary>
KeepOrbital,
/// <summary>
/// Keep surface velocity.
/// </summary>
KeepSurface,
/// <summary>
/// Keep vertical velocity (climb/descent speed).
/// </summary>
KeepVertical,
/// <summary>
/// Internal mode, do not set.
/// </summary>
KeepRelative,
/// <summary>
/// Internal mode, do not set.
/// </summary>
Direct
}
}
}