forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.cs
More file actions
93 lines (83 loc) · 4.17 KB
/
Copy pathAPI.cs
File metadata and controls
93 lines (83 loc) · 4.17 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
using System;
using System.Collections.Generic;
using System.Linq;
namespace RemoteTech
{
public static class API
{
public static bool HasFlightComputer(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
if (satellite == null) return false;
var hasFlightComputer = satellite.FlightComputer != null;
RTLog.Verbose("Flight: {0} HasFlightComputer: {1}", id, hasFlightComputer);
return hasFlightComputer;
}
public static void AddSanctionedPilot(Guid id, Action<FlightCtrlState> autopilot)
{
var satellite = RTCore.Instance.Satellites[id];
if (satellite == null) return;
foreach (var spu in satellite.SignalProcessors)
{
if (spu.FlightComputer == null) continue;
if (spu.FlightComputer.SanctionedPilots.Contains(autopilot)) continue;
RTLog.Verbose("Flight: {0} Adding Sanctioned Pilot", id);
spu.FlightComputer.SanctionedPilots.Add(autopilot);
}
}
public static void RemoveSanctionedPilot(Guid id, Action<FlightCtrlState> autopilot)
{
var satellite = RTCore.Instance.Satellites[id];
if (satellite == null) return;
foreach (var spu in satellite.SignalProcessors)
{
if (spu.FlightComputer == null) continue;
RTLog.Verbose("Flight: {0} Removing Sanctioned Pilot", id);
spu.FlightComputer.SanctionedPilots.Remove(autopilot);
}
}
public static bool HasAnyConnection(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
var hasConnection = RTCore.Instance.Network[satellite].Any();
RTLog.Verbose("Flight: {0} Has Connection: {1}", id, hasConnection);
return hasConnection;
}
public static bool HasConnectionToKSC(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
var connectedToKerbin = RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid));
RTLog.Verbose("Flight: {0} Has Connection to Kerbin: {1}", id, connectedToKerbin);
return connectedToKerbin;
}
public static double GetShortestSignalDelay(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
if (!RTCore.Instance.Network[satellite].Any()) return Double.PositiveInfinity;
var shortestDelay = RTCore.Instance.Network[satellite].Min().Delay;
RTLog.Verbose("Flight: Shortest signal delay from {0} to {1}", id, shortestDelay);
return shortestDelay;
}
public static double GetSignalDelayToKSC(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
if (!RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid))) return Double.PositiveInfinity;
var signalDelaytoKerbin = RTCore.Instance.Network[satellite].Where(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid)).Min().Delay;
RTLog.Verbose("Connection from {0} to Kerbin Delay: {1}", id, signalDelaytoKerbin);
return signalDelaytoKerbin;
}
public static double GetSignalDelayToSatellite(Guid a, Guid b)
{
var satelliteA = RTCore.Instance.Satellites[a];
var satelliteB = RTCore.Instance.Satellites[b];
if (satelliteA == null || satelliteB == null) return Double.PositiveInfinity;
Func<ISatellite, IEnumerable<NetworkLink<ISatellite>>> neighbors = RTCore.Instance.Network.FindNeighbors;
Func<ISatellite, NetworkLink<ISatellite>, double> cost = RangeModelExtensions.DistanceTo;
Func<ISatellite, ISatellite, double> heuristic = RangeModelExtensions.DistanceTo;
var path = NetworkPathfinder.Solve(satelliteA, satelliteB, neighbors, cost, heuristic);
var delayBetween = path.Delay;
RTLog.Verbose("Connection from {0} to {1} Delay: {2}", a, b, delayBetween);
return delayBetween;
}
}
}