11using RemoteTech . RangeModel ;
2+ using RemoteTech . Modules ;
23using RemoteTech . SimpleTypes ;
34using System ;
45using System . Collections . Generic ;
@@ -10,6 +11,12 @@ namespace RemoteTech.API
1011{
1112 public static class API
1213 {
14+ public static bool IsRemoteTechEnabled ( )
15+ {
16+ if ( RTCore . Instance == null ) return true ;
17+ return false ;
18+ }
19+
1320 public static bool HasLocalControl ( Guid id )
1421 {
1522 var vessel = RTUtil . GetVesselById ( id ) ;
@@ -83,6 +90,66 @@ public static bool HasConnectionToKSC(Guid id)
8390 return connectedToKerbin ;
8491 }
8592
93+ public static bool AntennaHasConnection ( Part part )
94+ {
95+ if ( RTCore . Instance == null ) return false ;
96+ var antennaModules = part . Modules . OfType < IAntenna > ( ) ;
97+
98+ return antennaModules . Any ( m => m . Connected ) ;
99+ }
100+
101+ public static Guid GetAntennaTarget ( Part part ) {
102+ ModuleRTAntenna module = part . Modules . OfType < ModuleRTAntenna > ( ) . First ( ) ;
103+
104+ if ( module == null )
105+ {
106+ throw new ArgumentException ( ) ;
107+ }
108+
109+ return module . Target ;
110+ }
111+
112+ public static void SetAntennaTarget ( Part part , Guid id ) {
113+ ModuleRTAntenna module = part . Modules . OfType < ModuleRTAntenna > ( ) . First ( ) ;
114+
115+ if ( module == null )
116+ {
117+ throw new ArgumentException ( ) ;
118+ }
119+
120+ module . Target = id ;
121+ }
122+
123+ public static IEnumerable < string > GetGroundStations ( )
124+ {
125+ return RTSettings . Instance . GroundStations . Select ( s => ( ( ISatellite ) s ) . Name ) ;
126+ }
127+
128+ public static Guid GetGroundStationGuid ( String name )
129+ {
130+ MissionControlSatellite groundStation = RTSettings . Instance . GroundStations . Where ( station => station . GetName ( ) . Equals ( name ) ) . FirstOrDefault ( ) ;
131+
132+ if ( groundStation == null )
133+ {
134+ return Guid . Empty ;
135+ }
136+
137+ return groundStation . mGuid ;
138+ }
139+
140+ public static Guid GetCelestialBodyGuid ( CelestialBody celestialBody )
141+ {
142+ return RTUtil . Guid ( celestialBody ) ;
143+ }
144+
145+ public static Guid GetNoTargetGuid ( ) {
146+ return new Guid ( RTSettings . Instance . NoTargetGuid ) ;
147+ }
148+
149+ public static Guid GetActiveVesselGuid ( ) {
150+ return new Guid ( RTSettings . Instance . ActiveVesselGuid ) ;
151+ }
152+
86153 public static double GetShortestSignalDelay ( Guid id )
87154 {
88155 if ( RTCore . Instance == null ) return double . PositiveInfinity ;
@@ -127,6 +194,7 @@ public static double GetSignalDelayToSatellite(Guid a, Guid b)
127194 //exposed method called by other mods, passing a ConfigNode to RemoteTech
128195 public static bool QueueCommandToFlightComputer ( ConfigNode externalData )
129196 {
197+ if ( RTCore . Instance == null ) return false ;
130198 //check we were actually passed a config node
131199 if ( externalData == null ) return false ;
132200 // check our min values
@@ -176,6 +244,28 @@ public static void InvokeOriginalEvent(BaseEvent e)
176244 {
177245 e . Invoke ( ) ;
178246 }
247+ }
248+
249+ public static Guid AddGroundStation ( string name , double latitude , double longitude , double height , int body )
250+ {
251+ RTLog . Notify ( "Trying to add groundstation {0}" , RTLogLevel . API , name ) ;
252+ Guid newStationId = RTSettings . Instance . AddGroundStation ( name , latitude , longitude , height , body ) ;
253+
254+ return newStationId ;
255+ }
256+
257+ public static bool RemoveGroundStation ( Guid stationid )
258+ {
259+ RTLog . Notify ( "Trying to remove groundstation {0}" , RTLogLevel . API , stationid ) ;
260+
261+ // do not allow to remove the default mission control
262+ if ( stationid . ToString ( "N" ) . Equals ( "5105f5a9d62841c6ad4b21154e8fc488" ) )
263+ {
264+ RTLog . Notify ( "Cannot remove KSC Mission Control!" , RTLogLevel . API ) ;
265+ return false ;
266+ }
267+
268+ return RTSettings . Instance . RemoveGroundStation ( stationid ) ;
179269 }
180270 }
181271}
0 commit comments