/
Escape.cs
100 lines (81 loc) · 2.9 KB
/
Escape.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
using System.Linq;
using UnityEngine;
namespace PebkacLaunchEscape
{
/// <summary>
/// ModulePebkacLesEscape should be applied to the LES part that has an escape motor
/// </summary>
class ModulePebkacLesEscape : PartModule
{
private static string _myModTag = "[PEBKAC LES]";
#region PartModules contained on various LES parts
// the escape engine
private ModuleEnginesFX _escapeEngine;
// decoupler for the LES
private ModuleDecouple _escapeDecoupler;
#region Helpers
private ModuleEnginesFX GetEscapeEngine()
{
Debug.Log(string.Format("{0} ModulePebkacLesEscape.GetEscapeEngine", _myModTag));
ModuleEnginesFX myEngine = null;
try
{
myEngine = part.FindModulesImplementing<ModuleEnginesFX>().Where(e => e.engineID == "LES_Escape").FirstOrDefault();
}
catch (System.Exception x)
{
Debug.Log(string.Format("{0} ERROR: {1}", _myModTag, x.Message));
}
if (!myEngine)
{
// this shouldn't happen under normal circumstances
Debug.LogError("ERROR: Didn't find ModuleEnginesFX on LES escape rocket!");
}
return myEngine;
}
private ModuleDecouple GetEscapeDecoupler()
{
Debug.Log(string.Format("{0} ModulePebkacLesEscape.GetEscapeDecoupler", _myModTag));
ModuleDecouple myDecoupler = null;
try
{
myDecoupler = part.FindModulesImplementing<ModuleDecouple>().SingleOrDefault();
}
catch (System.Exception x)
{
Debug.Log(string.Format("{0} ERROR: {1}", _myModTag, x.Message));
}
if (!myDecoupler)
{
// this shouldn't happen under normal circumstances
Debug.LogError(string.Format("{0} ERROR: Didn't find ModuleDecouple on LES escape tower!", _myModTag));
}
return myDecoupler;
}
#endregion
#endregion
public override void OnStart(StartState state)
{
Debug.Log(string.Format("{0} ModulePebkacLesEscape.OnStart", _myModTag));
_escapeEngine = GetEscapeEngine();
_escapeDecoupler = GetEscapeDecoupler();
base.OnStart(state);
}
internal void Abort()
{
if (_escapeEngine != null)
{
_escapeEngine.Activate();
Debug.Log(string.Format("{0} Escape motor fired!", _myModTag));
}
}
internal void Decouple()
{
if (_escapeDecoupler != null)
{
_escapeDecoupler.Decouple();
Debug.Log(string.Format("{0} LES decoupled from CM", _myModTag));
}
}
}
}