A bunch more changes. Relays mostly work now, I think, except for the infinite recursion.
[AntennaRange.git] / Extensions.cs
blob:a/Extensions.cs -> blob:b/Extensions.cs
--- a/Extensions.cs
+++ b/Extensions.cs
@@ -6,25 +6,75 @@
 {
 	public static class Extensions
 	{
-		public static IEnumerable<ILimitedScienceDataTransmitter> GetTransmitters (this Vessel vessel)
+		public static double DistanceTo(this Vessel vesselOne, Vessel vesselTwo)
 		{
-			List<ILimitedScienceDataTransmitter> Transmitters;
+			return (vesselOne.GetWorldPos3D() - vesselTwo.GetWorldPos3D()).magnitude;
+		}
+
+		public static double DistanceTo(this Vessel vessel, CelestialBody body)
+		{
+			return (vessel.GetWorldPos3D() - body.position).magnitude;
+		}
+
+		public static double DistanceTo(this IAntennaRelay relay, Vessel Vessel)
+		{
+			return relay.vessel.DistanceTo(Vessel);
+		}
+
+		public static double DistanceTo(this IAntennaRelay relay, CelestialBody body)
+		{
+			return relay.vessel.DistanceTo(body);
+		}
+
+		public static double DistanceTo(this IAntennaRelay relayOne, IAntennaRelay relayTwo)
+		{
+			return relayOne.DistanceTo(relayTwo.vessel);
+		}
+
+		public static IEnumerable<IAntennaRelay> GetAntennaRelays (this Vessel vessel)
+		{
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Getting antenna relays from vessel {1}.",
+				"IAntennaRelay",
+				vessel.name
+			));
+
+			List<IAntennaRelay> Transmitters;
 
 			if (vessel.loaded) {
+				Tools.PostDebugMessage(string.Format(
+					"{0}: vessel {1} is loaded.",
+					"IAntennaRelay",
+					vessel.name
+					));
+
 				Transmitters = vessel.Parts
-					.SelectMany (p => p.Modules.OfType<ILimitedScienceDataTransmitter> ())
+					.SelectMany (p => p.Modules.OfType<IAntennaRelay> ())
 					.ToList();
 			} else {
-				Transmitters = new List<ILimitedScienceDataTransmitter>();
+				Tools.PostDebugMessage(string.Format(
+					"{0}: vessel {1} is not loaded.",
+					"IAntennaRelay",
+					vessel.name
+					));
+
+				Transmitters = new List<IAntennaRelay>();
 
 				foreach (ProtoPartModuleSnapshot ms in vessel.protoVessel.protoPartSnapshots.SelectMany(ps => ps.modules))
 				{
 					if (ms.IsAntenna())
 					{
-						Transmitters.Add(new ProtoDataTransmitter(ms, vessel));
+						Transmitters.Add(new ProtoAntennaRelay(ms, vessel));
 					}
 				}
 			}
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: vessel {1} has {2} transmitters.",
+				"IAntennaRelay",
+				vessel.name,
+				Transmitters.Count
+				));
 
 			return Transmitters;
 		}