forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVesselExtension.cs
More file actions
28 lines (26 loc) · 1.36 KB
/
Copy pathVesselExtension.cs
File metadata and controls
28 lines (26 loc) · 1.36 KB
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
using System.Linq;
namespace RemoteTech
{
public static class VesselExtension
{
/// <summary>
/// Get whether a vessel has local control or not (that is, if it's Kerbal controlled or not).
/// </summary>
/// <param name="vessel">The vessel to check for.</param>
/// <returns>true if the vessel has a local control, false otherwise.</returns>
public static bool HasLocalControl(this Vessel vessel)
{
// vessel must be a control source and it must be crewed or not implementing a module processor
var hasLocalControl = vessel.parts.Any(p => (p.isControlSource > Vessel.ControlLevel.NONE) &&
(p.protoModuleCrew.Any() || !p.FindModulesImplementing<ISignalProcessor>().Any() ||
p.FindModulesImplementing<Modules.ModuleSPU>().Any(s => s.AlwaysAllowLocalControl)));
if (!hasLocalControl)
{
// check if theres's a SPU which is a command station.
// Command stations must have local control even if there's nobody in the command pod [see other checks in ModuleSPU.IsCommandStation]
hasLocalControl = vessel.parts.Any(part => part.FindModulesImplementing<ISignalProcessor>().Any(signalProcessor => signalProcessor.IsCommandStation));
}
return hasLocalControl;
}
}
}