forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleSPUPassive.cs
More file actions
88 lines (80 loc) · 3.26 KB
/
Copy pathModuleSPUPassive.cs
File metadata and controls
88 lines (80 loc) · 3.26 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
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
using System;
using UnityEngine;
namespace RemoteTech.Modules
{
/// <summary>
/// This module allows any vessel with an antenna to participate in a RemoteTech network, even if it does not have a <see cref="ModuleSPU"/>.
/// <para>It should be included in all RemoteTech antennas. Unlike ModuleSPU, it does not filter commands or provide a flight computer.</para>
/// </summary>
public class ModuleSPUPassive : PartModule, ISignalProcessor
{
public string Name => $"ModuleSPUPassive({VesselName})";
public string VesselName
{
get { return vessel != null ? vessel.vesselName : "vessel-null"; }
set { if(vessel != null) vessel.vesselName = value; }
}
public bool VesselLoaded => vessel != null && vessel.loaded;
public Guid VesselId { get; private set; }
public Vector3 Position { get { return vessel != null ? vessel.GetWorldPos3D() : new Vector3d(); } }
public CelestialBody Body { get { return vessel != null ? vessel.mainBody : null; } }
public bool Visible => MapViewFiltering.CheckAgainstFilter(vessel);
public bool Powered => vessel != null && vessel.IsControllable;
public bool IsCommandStation => false;
public FlightComputer.FlightComputer FlightComputer => null;
public Vessel Vessel => vessel;
public bool IsMaster => false;
public bool CanRelaySignal => true;
[KSPField(isPersistant = true)] public bool IsRTPowered;
[KSPField(isPersistant = true)] public bool IsRTSignalProcessor = true;
[KSPField(isPersistant = true)] public bool IsRTCommandStation = false;
public override void OnStart(StartState state)
{
if (state != StartState.Editor)
{
GameEvents.onVesselWasModified.Add(OnVesselModified);
GameEvents.onPartUndock.Add(OnPartUndock);
VesselId = vessel.id;
if(RTCore.Instance != null)
{
RTCore.Instance.Satellites.Register(vessel, this);
}
}
}
private void FixedUpdate()
{
if (Vessel != null)
{
IsRTPowered = Powered;
}
}
public void OnDestroy()
{
RTLog.Notify("ModuleSPUPassive: OnDestroy");
GameEvents.onVesselWasModified.Remove(OnVesselModified);
GameEvents.onPartUndock.Remove(OnPartUndock);
if (RTCore.Instance != null)
{
RTCore.Instance.Satellites.Unregister(VesselId, this);
VesselId = Guid.Empty;
}
}
public void OnPartUndock(Part p)
{
OnVesselModified(p.vessel);
}
public void OnVesselModified(Vessel v)
{
if (RTCore.Instance != null && vessel != null && VesselId != vessel.id)
{
RTCore.Instance.Satellites.Unregister(VesselId, this);
VesselId = vessel.id;
RTCore.Instance.Satellites.Register(vessel, this);
}
}
public override string ToString()
{
return $"ModuleSPUPassive({(Vessel != null ? Vessel.vesselName : "null")}, {VesselId})";
}
}
}