Merge branch 'master' into PrettyLinesDev2
Merge branch 'master' into PrettyLinesDev2

Conflicts:
ARFlightController.cs

--- a/ARFlightController.cs
+++ b/ARFlightController.cs
@@ -233,7 +233,7 @@
 			log.Print();
 		}
 
-		protected void Destroy()
+		protected void OnDestroy()
 		{
 			InputLockManager.RemoveControlLock(this.lockID);
 
@@ -249,6 +249,8 @@
 
 			GameEvents.onGameSceneLoadRequested.Remove(this.onSceneChangeRequested);
 			GameEvents.onVesselChange.Remove(this.onVesselChange);
+
+			print("ARFlightController: Destroyed.");
 		}
 		#endregion
 
@@ -257,7 +259,8 @@
 		{
 			if (scene != GameScenes.FLIGHT)
 			{
-				MonoBehaviour.DestroyImmediate(this, true);
+				print("ARFlightController: Requesting Destruction.");
+				MonoBehaviour.Destroy(this);
 			}
 		}
 

--- a/ARMapRenderer.cs
+++ b/ARMapRenderer.cs
@@ -73,6 +73,7 @@
 		#region MonoBehaviour Lifecycle
 		private void Awake()
 		{
+			this.vesselLineRenderers = new Dictionary<Guid, LineRenderer>();
 			this.vesselFrameCache = new Dictionary<Guid, bool>();
 		}
 
@@ -88,30 +89,13 @@
 			try
 			{
 				log.AppendFormat("OnPreCull.\n");
-
-				double sma;
-
-				switch (MapView.MapCamera.target.type)
-				{
-					case MapObject.MapObjectType.CELESTIALBODY:
-						sma = MapView.MapCamera.target.celestialBody.orbit.semiMajorAxis;
-						break;
-					case MapObject.MapObjectType.VESSEL:
-						sma = MapView.MapCamera.target.vessel.orbit.semiMajorAxis;
-						break;
-					default:
-						sma = ScaledSpace.ScaleFactor;
-						break;
-				}
 
 				log.AppendFormat("\tMapView: Draw3DLines: {0}\n" +
 					"\tMapView.MapCamera.camera.fieldOfView: {1}\n" +
-					"\tMapView.MapCamera.Distance: {2}\n" +
-					"\tDistanceVSSMAFactor: {3}\n",
+					"\tMapView.MapCamera.Distance: {2}\n",
 					MapView.Draw3DLines,
 					MapView.MapCamera.camera.fieldOfView,
-					MapView.MapCamera.Distance,
-					(float)((double)MapView.MapCamera.Distance / Math.Abs(sma) * ScaledSpace.InverseScaleFactor)
+					MapView.MapCamera.Distance
 				);
 
 				this.vesselFrameCache.Clear();
@@ -143,6 +127,8 @@
 								continue;
 						}
 
+						log.Append("\tChecking connection status...\n");
+
 						if (vessel.HasConnectedRelay())
 						{
 							log.AppendLine("\tHas a connection, checking for the best relay to use for the line.");
@@ -185,10 +171,11 @@
 			}
 		}
 
-		private void Destroy()
+		private void OnDestroy()
 		{
 			this.vesselLineRenderers.Clear();
 			this.vesselLineRenderers = null;
+			print("ARMapRenderer: Destroyed.");
 		}
 		#endregion
 
@@ -210,6 +197,15 @@
 
 					renderer.enabled = true;
 
+					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.nearestRelay == null)
@@ -235,8 +231,10 @@
 						end = MapView.MapCamera.camera.WorldToScreenPoint(end);
 
 						float d = Screen.height / 2f + 0.01f;
-						start.z = start.z >= 0.15f ? d : -d;
-						end.z = end.z >= 0.15f ? d : -d;
+						start.z = start.z >= 0f ? d : -d;
+						end.z = end.z >= 0f ? d : -d;
+
+						Debug.Log(string.Format("start.z: {0}", start.z));
 					}
 
 					renderer.SetWidth(lineWidth, lineWidth);

--- a/AntennaRelay.cs
+++ b/AntennaRelay.cs
@@ -117,6 +117,12 @@
 					return this.DistanceTo(nearestRelay);
 				}
 			}
+		}
+
+		public virtual double nominalTransmitDistance
+		{
+			get;
+			set;
 		}
 
 		/// <summary>

--- a/IAntennaRelay.cs
+++ b/IAntennaRelay.cs
@@ -50,6 +50,8 @@
 		/// <value>The distance to the nearest relay or Kerbin, whichever is closer.</value>
 		double transmitDistance { get; }
 
+		double nominalTransmitDistance { get; }
+
 		/// <summary>
 		/// The maximum distance at which this relay can operate.
 		/// </summary>

--- a/ModuleLimitedDataTransmitter.cs
+++ b/ModuleLimitedDataTransmitter.cs
@@ -145,6 +145,14 @@
 			get
 			{
 				return this.relay.transmitDistance;
+			}
+		}
+
+		public double nominalTransmitDistance
+		{
+			get
+			{
+				return this.nominalRange;
 			}
 		}
 
@@ -249,6 +257,7 @@
 			{
 				this.relay = new AntennaRelay(this);
 				this.relay.maxTransmitDistance = this.maxTransmitDistance;
+				this.relay.nominalTransmitDistance = this.nominalRange;
 
 				this.UImaxTransmitDistance = Tools.MuMech_ToSI(this.maxTransmitDistance) + "m";
 
@@ -354,6 +363,11 @@
 		// Override ModuleDataTransmitter.CanTransmit to return false when transmission is not possible.
 		public new bool CanTransmit()
 		{
+			if (this.relay == null)
+			{
+				return false;
+			}
+
 			PartStates partState = this.part.State;
 			if (partState == PartStates.DEAD || partState == PartStates.DEACTIVATED)
 			{

--- a/ProtoAntennaRelay.cs
+++ b/ProtoAntennaRelay.cs
@@ -47,6 +47,14 @@
 			get
 			{
 				return this.protoPart.pVesselRef.vesselRef;
+			}
+		}
+
+		public override double nominalTransmitDistance
+		{
+			get
+			{
+				return this.moduleRef.nominalTransmitDistance;
 			}
 		}