More changes to make bad relay detection work. Something's still fighting something.
More changes to make bad relay detection work. Something's still fighting something.

--- a/ARMapRenderer.cs
+++ b/ARMapRenderer.cs
@@ -131,9 +131,9 @@
 
 						log.Append("\tChecking connection status...\n");
 
-						if (vessel.HasConnectedRelay())
-						{
-							log.AppendLine("\tHas a connection, checking for the best relay to use for the line.");
+						/*if (vessel.HasConnectedRelay())
+						{
+							log.AppendLine("\tHas a connection, checking for the best relay to use for the line.");*/
 
 							IAntennaRelay vesselRelay = null;
 							float bestScore = float.PositiveInfinity;
@@ -158,12 +158,12 @@
 
 								this.SetRelayVertices(vesselRelay);
 							}
-						}
+						/*}
 						else if (this.vesselLineRenderers.ContainsKey(vessel.id))
 						{
 							log.AppendLine("\tDisabling line because vessel has no connection.");
 							this[vessel.id].enabled = false;
-						}
+						}*/
 					}
 				}
 			}
@@ -197,31 +197,38 @@
 
 				renderer.enabled = true;
 
-				if (relay.transmitDistance < relay.nominalTransmitDistance)
-				{
-					renderer.SetColors(Color.green, Color.green);
+				if (!relay.CanTransmit())
+				{
+					renderer.SetColors(Color.red, Color.red);
 				}
 				else
 				{
-					renderer.SetColors(Color.yellow, Color.yellow);
+					if (relay.transmitDistance < relay.nominalTransmitDistance)
+					{
+						renderer.SetColors(Color.green, Color.green);
+					}
+					else
+					{
+						renderer.SetColors(Color.yellow, Color.yellow);
+					}
 				}
 
 				start = ScaledSpace.LocalToScaledSpace(relay.vessel.GetWorldPos3D());
 
 				if (relay.KerbinDirect)
 				{
+					end = ScaledSpace.LocalToScaledSpace(AntennaRelay.Kerbin.position);
+				}
+				else
+				{
 					if (relay.firstOccludingBody != null && relay.bestOccludedRelay != null)
 					{
 						end = ScaledSpace.LocalToScaledSpace(relay.bestOccludedRelay.vessel.GetWorldPos3D());
 					}
 					else
 					{
-						end = ScaledSpace.LocalToScaledSpace(AntennaRelay.Kerbin.position);
-					}
-				}
-				else
-				{
-					end = ScaledSpace.LocalToScaledSpace(relay.nearestRelay.vessel.GetWorldPos3D());
+						end = ScaledSpace.LocalToScaledSpace(relay.nearestRelay.vessel.GetWorldPos3D());
+					}
 				}
 
 				float lineWidth;

--- a/AntennaRelay.cs
+++ b/AntennaRelay.cs
@@ -136,8 +136,13 @@
 					}
 				}
 
+				if (this.firstOccludingBody != null && this.bestOccludedRelay != null)
+				{
+					this.KerbinDirect = false;
+					return this.DistanceTo(this.bestOccludedRelay);
+				}
+
 				this.KerbinDirect = true;
-				
 
 				// .. return the distance to Kerbin
 				return kerbinDistance;
@@ -188,6 +193,12 @@
 			// @DONE TODO: Remove nearestRelay == null
 			// Because we're correctly falling back to Kerbin in transmitDistance the first test should always fail
 			// when we're out of range of anything, and the second will fail when LOS is blocked (and enforced).
+
+			Tools.PostDebugMessage(this.moduleRef, "Checking if CanTransmit with maxTransmitDistance={0}" +
+				"\n\ttransmitDistance={1}; KerbinDirect={2}, nearestRelay={3}, bestOccludedRelay={4}",
+				this.maxTransmitDistance, this.transmitDistance, this.KerbinDirect,
+				this.nearestRelay, this.bestOccludedRelay
+			);
 
 			// If our transmit distance is greater than our maximum range, we can't transmit and it doesn't matter why.
 			if (this.transmitDistance > this.maxTransmitDistance)

--- a/ModuleLimitedDataTransmitter.cs
+++ b/ModuleLimitedDataTransmitter.cs
@@ -176,8 +176,11 @@
 		// Returns the maximum distance this module can transmit
 		public float maxTransmitDistance
 		{
-			get;
-			private set;
+			get
+			{
+				// TODO: Cache this in a way that doesn't break everything.
+				return Mathf.Sqrt(this.maxPowerFactor) * this.nominalRange;
+			}
 		}
 
 		public CelestialBody firstOccludingBody
@@ -296,7 +299,6 @@
 
 			this._basepacketSize = base.packetSize;
 			this._basepacketResourceCost = base.packetResourceCost;
-			this.maxTransmitDistance = Mathf.Sqrt(this.maxPowerFactor) * this.nominalRange;
 
 			Tools.PostDebugMessage(string.Format(
 				"{0} loaded:\n" +

--- a/RelayExtensions.cs
+++ b/RelayExtensions.cs
@@ -78,7 +78,7 @@
 			return relay.vessel.sqrDistanceTo(body);
 		}
 
-		public static double sqrDistanceTo(this AntennaRelay relayOne, AntennaRelay relayTwo)
+		public static double sqrDistanceTo(this AntennaRelay relayOne, IAntennaRelay relayTwo)
 		{
 			return relayOne.vessel.sqrDistanceTo(relayTwo.vessel);
 		}