/
AutopilotModule.cs
68 lines (55 loc) · 1.78 KB
/
AutopilotModule.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
using System;
using UnityEngine;
namespace MuMech
{
public class AutopilotModule : ComputerModule
{
protected AutopilotModule(MechJebCore core) : base(core)
{
}
public override void Drive(FlightCtrlState s)
{
if (CurrentStep == null) return;
try
{
CurrentStep = CurrentStep.Drive(s);
}
catch (Exception ex)
{
Debug.LogException(ex);
}
}
public override void OnFixedUpdate()
{
if (CurrentStep == null) return;
try
{
CurrentStep = CurrentStep.OnFixedUpdate();
}
catch (Exception ex)
{
Debug.LogException(ex);
}
}
protected void SetStep(AutopilotStep step) => CurrentStep = step;
public string Status => CurrentStep == null ? "Off" : CurrentStep.Status;
protected bool Active => CurrentStep != null;
public AutopilotStep CurrentStep { get; private set; }
}
public class AutopilotStep
{
protected readonly MechJebCore Core;
//conveniences:
protected VesselState VesselState => Core.VesselState;
protected Vessel Vessel => Core.part.vessel;
protected CelestialBody MainBody => Core.part.vessel.mainBody;
protected Orbit Orbit => Core.part.vessel.orbit;
protected AutopilotStep(MechJebCore core)
{
Core = core;
}
public virtual AutopilotStep Drive(FlightCtrlState s) => this;
public virtual AutopilotStep OnFixedUpdate() => this;
public string Status { get; protected set; }
}
}