@@ -20,8 +20,10 @@ public static bool HasLocalControl(Guid id)
2020
2121 public static bool HasFlightComputer ( Guid id )
2222 {
23+ if ( RTCore . Instance == null ) return false ;
2324 var satellite = RTCore . Instance . Satellites [ id ] ;
2425 if ( satellite == null ) return false ;
26+
2527 var hasFlightComputer = satellite . FlightComputer != null ;
2628 RTLog . Verbose ( "Flight: {0} HasFlightComputer: {1}" , RTLogLevel . API , id , hasFlightComputer ) ;
2729
@@ -30,11 +32,13 @@ public static bool HasFlightComputer(Guid id)
3032
3133 public static void AddSanctionedPilot ( Guid id , Action < FlightCtrlState > autopilot )
3234 {
35+ if ( RTCore . Instance == null ) return ;
3336 var satellite = RTCore . Instance . Satellites [ id ] ;
34- if ( satellite == null ) return ;
37+ if ( satellite == null || satellite . SignalProcessor == null ) return ;
38+
3539 foreach ( var spu in satellite . SignalProcessors )
3640 {
37- if ( spu . FlightComputer == null ) continue ;
41+ if ( spu . FlightComputer == null || spu . FlightComputer . SanctionedPilots == null ) continue ;
3842 if ( spu . FlightComputer . SanctionedPilots . Contains ( autopilot ) ) continue ;
3943 RTLog . Verbose ( "Flight: {0} Adding Sanctioned Pilot" , RTLogLevel . API , id ) ;
4044 spu . FlightComputer . SanctionedPilots . Add ( autopilot ) ;
@@ -43,55 +47,70 @@ public static void AddSanctionedPilot(Guid id, Action<FlightCtrlState> autopilot
4347
4448 public static void RemoveSanctionedPilot ( Guid id , Action < FlightCtrlState > autopilot )
4549 {
50+ if ( RTCore . Instance == null ) return ;
4651 var satellite = RTCore . Instance . Satellites [ id ] ;
47- if ( satellite == null ) return ;
52+ if ( satellite == null || satellite . SignalProcessor == null ) return ;
53+
4854 foreach ( var spu in satellite . SignalProcessors )
4955 {
50- if ( spu . FlightComputer == null ) continue ;
56+ if ( spu . FlightComputer == null || spu . FlightComputer . SanctionedPilots == null ) continue ;
5157 RTLog . Verbose ( "Flight: {0} Removing Sanctioned Pilot" , RTLogLevel . API , id ) ;
5258 spu . FlightComputer . SanctionedPilots . Remove ( autopilot ) ;
5359 }
5460 }
5561
5662 public static bool HasAnyConnection ( Guid id )
5763 {
64+ if ( RTCore . Instance == null ) return false ;
5865 var satellite = RTCore . Instance . Satellites [ id ] ;
66+ if ( satellite == null ) return false ;
67+
5968 var hasConnection = RTCore . Instance . Network [ satellite ] . Any ( ) ;
6069 RTLog . Verbose ( "Flight: {0} Has Connection: {1}" , RTLogLevel . API , id , hasConnection ) ;
6170 return hasConnection ;
6271 }
6372
6473 public static bool HasConnectionToKSC ( Guid id )
6574 {
75+ if ( RTCore . Instance == null ) return false ;
6676 var satellite = RTCore . Instance . Satellites [ id ] ;
77+ if ( satellite == null ) return false ;
78+
6779 var connectedToKerbin = RTCore . Instance . Network [ satellite ] . Any ( r => RTCore . Instance . Network . GroundStations . ContainsKey ( r . Goal . Guid ) ) ;
6880 RTLog . Verbose ( "Flight: {0} Has Connection to Kerbin: {1}" , RTLogLevel . API , id , connectedToKerbin ) ;
6981 return connectedToKerbin ;
7082 }
7183
7284 public static double GetShortestSignalDelay ( Guid id )
7385 {
86+ if ( RTCore . Instance == null ) return double . PositiveInfinity ;
7487 var satellite = RTCore . Instance . Satellites [ id ] ;
75- if ( ! RTCore . Instance . Network [ satellite ] . Any ( ) ) return Double . PositiveInfinity ;
88+ if ( satellite == null ) return double . PositiveInfinity ;
89+
90+ if ( ! RTCore . Instance . Network [ satellite ] . Any ( ) ) return double . PositiveInfinity ;
7691 var shortestDelay = RTCore . Instance . Network [ satellite ] . Min ( ) . Delay ;
7792 RTLog . Verbose ( "Flight: Shortest signal delay from {0} to {1}" , RTLogLevel . API , id , shortestDelay ) ;
7893 return shortestDelay ;
7994 }
8095
8196 public static double GetSignalDelayToKSC ( Guid id )
8297 {
98+ if ( RTCore . Instance == null ) return double . PositiveInfinity ;
8399 var satellite = RTCore . Instance . Satellites [ id ] ;
84- if ( ! RTCore . Instance . Network [ satellite ] . Any ( r => RTCore . Instance . Network . GroundStations . ContainsKey ( r . Goal . Guid ) ) ) return Double . PositiveInfinity ;
100+ if ( satellite == null ) return double . PositiveInfinity ;
101+
102+ if ( ! RTCore . Instance . Network [ satellite ] . Any ( r => RTCore . Instance . Network . GroundStations . ContainsKey ( r . Goal . Guid ) ) ) return double . PositiveInfinity ;
85103 var signalDelaytoKerbin = RTCore . Instance . Network [ satellite ] . Where ( r => RTCore . Instance . Network . GroundStations . ContainsKey ( r . Goal . Guid ) ) . Min ( ) . Delay ;
86104 RTLog . Verbose ( "Connection from {0} to Kerbin Delay: {1}" , RTLogLevel . API , id , signalDelaytoKerbin ) ;
87105 return signalDelaytoKerbin ;
88106 }
89107
90108 public static double GetSignalDelayToSatellite ( Guid a , Guid b )
91109 {
110+ if ( RTCore . Instance == null ) return double . PositiveInfinity ;
92111 var satelliteA = RTCore . Instance . Satellites [ a ] ;
93112 var satelliteB = RTCore . Instance . Satellites [ b ] ;
94- if ( satelliteA == null || satelliteB == null ) return Double . PositiveInfinity ;
113+ if ( satelliteA == null || satelliteB == null ) return double . PositiveInfinity ;
95114
96115 Func < ISatellite , IEnumerable < NetworkLink < ISatellite > > > neighbors = RTCore . Instance . Network . FindNeighbors ;
97116 Func < ISatellite , NetworkLink < ISatellite > , double > cost = RangeModelExtensions . DistanceTo ;
0 commit comments