forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVesselSatellite.cs
More file actions
144 lines (117 loc) · 5.5 KB
/
Copy pathVesselSatellite.cs
File metadata and controls
144 lines (117 loc) · 5.5 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using RemoteTech.Modules;
using RemoteTech.SimpleTypes;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace RemoteTech
{
/// <summary>
/// Represents a satellite. The concept of satellite is similar to a vessel.
/// </summary>
public class VesselSatellite : ISatellite
{
/// <summary>Gets whether or not the satellite if visible in the Tracking station or the Flight Map view.</summary>
public bool Visible => SignalProcessor.Visible;
/// <summary>Gets or sets the name of the satellite.</summary>
public string Name
{
get { return SignalProcessor.VesselName; }
set { SignalProcessor.VesselName = value; }
}
/// <summary>Gets the satellite id.</summary>
public Guid Guid => SignalProcessor.VesselId;
/// <summary>Get a double precision vector for the vessel's world space position.</summary>
public Vector3d Position => SignalProcessor.Position;
/// <summary>Gets the celestial body around which the satellite is orbiting.</summary>
public CelestialBody Body => SignalProcessor.Body;
/// <summary>Gets the color of the ground station mark in Tracking station or Flight map view.</summary>
public Color MarkColor => RTSettings.Instance.RemoteStationColorDot;
/// <summary>Gets or sets the list of signal processor (<see cref="ISignalProcessor"/>) for the satellite.</summary>
public List<ISignalProcessor> SignalProcessors { get; set; }
/// <summary>Gets if the satellite is actually powered or not.</summary>
public bool Powered
{
get { return (PowerShutdownFlag)? false : SignalProcessors.Any(s => s.Powered); }
}
/// <summary>Gets if the satellite is capable to forward other signals.</summary>
public bool CanRelaySignal
{
get { return RTSettings.Instance.SignalRelayEnabled ? SignalProcessors.Any(s => s.CanRelaySignal && !(s is ModuleSPUPassive)) : true; }
}
/// <summary>Indicates whether the satellite is in radio blackout.</summary>
public bool IsInRadioBlackout { get; set; }
/// <summary>Indicates whether the manual power override is engaged.</summary>
public bool PowerShutdownFlag { get; set; }
/// <summary>Gets if the satellite is a RemoteTech command station.</summary>
public bool IsCommandStation
{
get { return SignalProcessors.Any(s => s.IsCommandStation); }
}
/// <summary>Gets a signal processor.</summary>
public ISignalProcessor SignalProcessor
{
get
{
return SignalProcessors.FirstOrDefault(s => s.FlightComputer != null) ?? SignalProcessors[0];
}
}
/// <summary>Gets whether the satellite has local control or not (that is, if it is locally controlled or not).</summary>
public bool HasLocalControl
{
get
{
return RTUtil.CachePerFrame(ref _localControl, () => SignalProcessor.Vessel.HasLocalControl());
}
}
/// <summary>Indicates whether the ISatellite corresponds to a vessel.</summary>
/// <value><c>true</c> if satellite is vessel or asteroid; otherwise (e.g. a ground station), <c>false</c>.</value>
/// <remarks>Implementation note: always return true for a <see cref="VesselSatellite"/>.</remarks>
public bool isVessel => true;
/// <summary>The vessel hosting the satellite.</summary>
/// <value>The vessel corresponding to this ISatellite. Returns null if !isVessel.</value>
public Vessel parentVessel => SignalProcessor.Vessel;
/// <summary>Gets a list of antennas for this satellite.</summary>
public IEnumerable<IAntenna> Antennas => RTCore.Instance.Antennas[this];
/// <summary>Gets the flight computer for this satellite.</summary>
public FlightComputer.FlightComputer FlightComputer => SignalProcessor.FlightComputer;
/*
* Helpers
*/
/// <summary>List of network routes for the satellite.</summary>
public List<NetworkRoute<ISatellite>> Connections => RTCore.Instance.Network[this];
/// <summary>Called on connection refresh to update the connections.</summary>
/// <param name="routes">List of network routes.</param>
public void OnConnectionRefresh(List<NetworkRoute<ISatellite>> routes)
{
foreach (IAntenna a in Antennas)
{
a.OnConnectionRefresh();
}
}
/// <summary>Local control cache variable.</summary>
private CachedField<bool> _localControl;
/*
* Methods
*/
/// <summary>Build a new instance of VesselSatellite.</summary>
/// <param name="signalProcessors">List of signal processor for this satellites. Can't be null.</param>
public VesselSatellite(List<ISignalProcessor> signalProcessors)
{
if (signalProcessors == null)
{
RTLog.Notify("VesselSatellite constructor: signalProcessor parameter is null", RTLogLevel.LVL4);
throw new ArgumentNullException();
}
SignalProcessors = signalProcessors;
}
public override string ToString()
{
return $"VesselSatellite({Name}, {Guid})";
}
public override int GetHashCode()
{
return Guid.GetHashCode();
}
}
}