forked from here-and-now/KRPC.MechJeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LandingAutopilot.cs
104 lines (86 loc) · 3.15 KB
/
LandingAutopilot.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 Landing Guidance module provides targeted and non-targeted landing autopilot.
/// </summary>
[KRPCClass(Service = "MechJeb")]
public class LandingAutopilot : AutopilotModule {
internal new const string MechJebType = "MuMech.MechJebModuleLandingAutopilot";
// Fields and methods
private static FieldInfo touchdownSpeedField;
private static FieldInfo deployGears;
private static FieldInfo limitGearsStageField;
private static FieldInfo deployChutes;
private static FieldInfo limitChutesStageField;
private static FieldInfo rcsAdjustment;
private static MethodInfo landAtPositionTarget;
private static MethodInfo landUntargeted;
private static MethodInfo stopLanding;
// Instance objects
private object touchdownSpeed;
private object limitGearsStage;
private object limitChutesStage;
internal static new void InitType(Type type) {
touchdownSpeedField = type.GetCheckedField("touchdownSpeed");
deployGears = type.GetCheckedField("deployGears");
limitGearsStageField = type.GetCheckedField("limitGearsStage");
deployChutes = type.GetCheckedField("deployChutes");
limitChutesStageField = type.GetCheckedField("limitChutesStage");
rcsAdjustment = type.GetCheckedField("rcsAdjustment");
landAtPositionTarget = type.GetCheckedMethod("LandAtPositionTarget");
landUntargeted = type.GetCheckedMethod("LandUntargeted");
stopLanding = type.GetCheckedMethod("StopLanding");
}
protected internal override void InitInstance(object instance) {
base.InitInstance(instance);
this.touchdownSpeed = touchdownSpeedField.GetInstanceValue(instance);
this.limitGearsStage = limitGearsStageField.GetInstanceValue(instance);
this.limitChutesStage = limitChutesStageField.GetInstanceValue(instance);
}
[KRPCProperty]
public double TouchdownSpeed {
get => EditableDouble.Get(this.touchdownSpeed);
set => EditableDouble.Set(this.touchdownSpeed, value);
}
[KRPCProperty]
public bool DeployGears {
get => (bool)deployGears.GetValue(this.instance);
set => deployGears.SetValue(this.instance, value);
}
[KRPCProperty]
public int LimitGearsStage {
get => EditableInt.Get(this.limitGearsStage);
set => EditableInt.Set(this.limitGearsStage, value);
}
[KRPCProperty]
public bool DeployChutes {
get => (bool)deployChutes.GetValue(this.instance);
set => deployChutes.SetValue(this.instance, value);
}
[KRPCProperty]
public int LimitChutesStage {
get => EditableInt.Get(this.limitChutesStage);
set => EditableInt.Set(this.limitChutesStage, value);
}
[KRPCProperty]
public bool RcsAdjustment {
get => (bool)rcsAdjustment.GetValue(this.instance);
set => rcsAdjustment.SetValue(this.instance, value);
}
[KRPCMethod]
public void LandAtPositionTarget() {
landAtPositionTarget.Invoke(this.instance, new object[] { this });
}
[KRPCMethod]
public void LandUntargeted() {
landUntargeted.Invoke(this.instance, new object[] { this });
}
[KRPCMethod]
public void StopLanding() {
stopLanding.Invoke(this.instance, null);
}
}
}