IMyTerminalBlock getBlock string blockName return GridTerminalSystem G

 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
IMyTerminalBlock getBlock(string blockName)
{
return GridTerminalSystem.GetBlockWithName(blockName);
}
void applyAction(string blockName, string actionName)
{
IMyTerminalBlock block = getBlock(blockName);
ITerminalAction action = block.GetActionWithName(actionName);
action.Apply(block);
}
void applyAction(IMyTerminalBlock block, string actionName)
{
ITerminalAction action = block.GetActionWithName(actionName);
action.Apply(block);
}
void applyAction(string[] blockNames, string actionName)
{
for (int i = 0; i < blockNames.Length; ++i)
{
IMyTerminalBlock block = getBlock(blockNames[i]);
ITerminalAction action = block.GetActionWithName(actionName);
action.Apply(block);
}
}
void adjustToValue(string blockName, float targetValue, string increaseMethodName, string decreaseMethodName, Func<IMyTerminalBlock, float> valueGetter)
{
IMyTerminalBlock block = getBlock(blockName);
while (valueGetter(block) > targetValue)
{
applyAction(block, decreaseMethodName);
}
while (valueGetter(block) < targetValue)
{
applyAction(block, increaseMethodName);
}
}
float thrustOverrideValueGetter(IMyTerminalBlock block)
{
if (block is IMyThrust)
{
return ((IMyThrust)block).ThrustOverride;
}
return Single.NaN;
}
void setThrusterOverride(string blockName, float newValue)
{
adjustToValue(blockName, newValue, "IncreaseOverride", "DecreaseOverride", thrustOverrideValueGetter);
}