-
Notifications
You must be signed in to change notification settings - Fork 3
/
ModuleControlSurface.cs
executable file
·71 lines (69 loc) · 1.63 KB
/
ModuleControlSurface.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
using UnityEngine;
using System;
namespace ClawKSP
{
[KSPAddon(KSPAddon.Startup.MainMenu, false)]
public class MCSHook : MonoBehaviour
{
public void Start()
{
Controller.HookModule("ModuleControlSurface", "MCS");
Controller.HookModule("ModuleAeroSurface", "MCS");
}
}
public class MCS : PartModule
{
ModuleControlSurface ControlSurfaceModule;
float ctrlSurfaceRange;
float vacuumRange = 1.0f;
[KSPField(isPersistant = true, guiName = "Locked in Vacum", guiActive = true, guiActiveEditor = true), UI_Toggle(enabledText = "True", disabledText = "False")]
public bool blockerEnabled = true;
public override void OnStart(StartState state)
{
try
{
base.OnStart(state);
ControlSurfaceModule = part.FindModuleImplementing<ModuleControlSurface>();
ctrlSurfaceRange = ControlSurfaceModule.ctrlSurfaceRange;
ControlSurfaceModule.ctrlSurfaceRange = ctrlSurfaceRange* vacuumRange;
}
catch (Exception ex)
{
Debug.LogError("PROBLEM.\n" + ex.Message + "\n" + ex.StackTrace);
}
}
public void FixedUpdate()
{
if (!ControlSurfaceModule.deploy&&blockerEnabled)
{
if (FlightGlobals.getStaticPressure(part.transform.position) < 0.001f)
{
if (vacuumRange > 0.001f)
{
vacuumRange -= 0.05f;
}
else
{
vacuumRange = 0.001f;
}
}
else
{
if (vacuumRange < 1.0f)
{
vacuumRange += 0.05f;
}
else
{
vacuumRange = 1.0f;
}
}
}
else
{
vacuumRange = 1.0f;
}
ControlSurfaceModule.ctrlSurfaceRange = ctrlSurfaceRange* vacuumRange * Mathf.Sign(ControlSurfaceModule.ctrlSurfaceRange);
}
}
}