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
84 lines (74 loc) · 2.91 KB
/
Copy pathModuleSPUPassive.cs
File metadata and controls
84 lines (74 loc) · 2.91 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
using System;
using System.Linq;
using System.Text;
using UnityEngine;
namespace RemoteTech.Modules
{
public class ModuleSPUPassive : PartModule, ISignalProcessor
{
public String Name { get { return String.Format("ModuleSPUPassive({0})", VesselName); } }
public String VesselName { get { return vessel.vesselName; } set { vessel.vesselName = value; } }
public bool VesselLoaded { get { return vessel.loaded; } }
public Guid Guid { get { return mRegisteredId; } }
public Vector3 Position { get { return vessel.GetWorldPos3D(); } }
public CelestialBody Body { get { return vessel.mainBody; } }
public bool Visible { get { return MapViewFiltering.CheckAgainstFilter(vessel); } }
public bool Powered { get { return Vessel.IsControllable; } }
public bool IsCommandStation { get { return false; } }
public FlightComputer.FlightComputer FlightComputer { get { return null; } }
public Vessel Vessel { get { return vessel; } }
public bool IsMaster { get { return false; } }
private ISatellite Satellite { get { return RTCore.Instance.Satellites[mRegisteredId]; } }
private Guid mRegisteredId;
[KSPField(isPersistant = true)]
public bool
IsRTPowered = false,
IsRTSignalProcessor = true,
IsRTCommandStation = false;
public override void OnStart(StartState state)
{
if (state != StartState.Editor)
{
GameEvents.onVesselWasModified.Add(OnVesselModified);
GameEvents.onPartUndock.Add(OnPartUndock);
mRegisteredId = vessel.id;
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(mRegisteredId, this);
mRegisteredId = Guid.Empty;
}
}
public void OnPartUndock(Part p)
{
OnVesselModified(p.vessel);
}
public void OnVesselModified(Vessel v)
{
if ((mRegisteredId != vessel.id))
{
RTCore.Instance.Satellites.Unregister(mRegisteredId, this);
mRegisteredId = vessel.id;
RTCore.Instance.Satellites.Register(vessel, this);
}
}
public override string ToString()
{
return String.Format("ModuleSPUPassive({0}, {1})", Vessel != null ? Vessel.vesselName : "null", mRegisteredId);
}
}
}