-
Notifications
You must be signed in to change notification settings - Fork 32
/
TestFlightFailure_ShutdownEngine.cs
76 lines (70 loc) · 2.63 KB
/
TestFlightFailure_ShutdownEngine.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
using System.Collections.Generic;
namespace TestFlight
{
public class TestFlightFailure_ShutdownEngine : TestFlightFailure_Engine
{
public override void OnStart(StartState state)
{
base.OnStart(state);
if (Failed && IsMajor)
{
foreach (EngineHandler engine in engines)
{
engine.engine.DisableRestart();
engine.engine.failed = true;
engine.engine.failMessage = failureTitle;
}
}
}
/// <summary>
/// Triggers the failure controlled by the failure module
/// </summary>
public override void DoFailure()
{
base.DoFailure();
if (engineStates == null)
engineStates = new Dictionary<int, CachedEngineState>();
engineStates.Clear();
foreach (EngineHandler engine in engines)
{
int id = engines.IndexOf(engine);
var engineState = new CachedEngineState(engine.engine);
engine.engine.Shutdown();
var numIgnitionsToRemove = 1;
if (IsMajor)
{
numIgnitionsToRemove = -1;
engine.engine.DisableRestart();
engine.engine.failed = true;
engine.engine.failMessage = failureTitle;
}
engineStates.Add(id, engineState);
engine.engine.RemoveIgnitions(numIgnitionsToRemove);
}
}
public override float DoRepair()
{
// for each engine restore it
foreach (EngineHandler engine in engines)
{
int id = engines.IndexOf(engine);
CachedEngineState engineState = null;
if (engineStates?.TryGetValue(id, out engineState) ?? false)
{
engine.engine.enabled = true;
engine.engine.Events["Activate"].active = true;
engine.engine.Events["Activate"].guiActive = true;
engine.engine.Events["Shutdown"].guiActive = true;
engine.engine.allowShutdown = engineState.allowShutdown;
engine.engine.allowRestart = engineState.allowRestart;
engine.engine.SetIgnitionCount(engineState.numIgnitions);
engine.engine.failed = false;
engine.engine.failMessage = "";
}
}
engineStates.Clear();
base.DoRepair();
return 0;
}
}
}