Added PreTransmit checks to the scoring properties to make sure nonfunctional antennas don't win the check.
Added PreTransmit checks to the scoring properties to make sure nonfunctional antennas don't win the check.

--- a/AntennaRange.cs
+++ b/AntennaRange.cs
@@ -68,16 +68,65 @@
 		// The distance from Kerbin at which the antenna will perform exactly as prescribed by packetResourceCost
 		// and packetSize.
 		[KSPField(isPersistant = false)]
-		public double nominalRange = 1500000d;
+		public float nominalRange;
 
 		// The multiplier on packetResourceCost that defines the maximum power output of the antenna.  When the power
 		// cost exceeds packetResourceCost * maxPowerFactor, transmission will fail.
 		[KSPField(isPersistant = false)]
-		public float maxPowerFactor = 8f;
+		public float maxPowerFactor;
 
 		// The multipler on packetSize that defines the maximum data bandwidth of the antenna.
 		[KSPField(isPersistant = false)]
-		public float maxDataFactor = 4f;
+		public float maxDataFactor;
+
+
+		/*
+		 * The next two functions overwrite the behavior of the stock functions and do not perform equivalently, except
+		 * in that they both return floats.  Here's some quick justification:
+		 * 
+		 * The stock implementation of GetTransmitterScore (which I cannot override) is:
+		 * 		Score = (1 + DataResourceCost) / DataRate
+		 * 
+		 * The stock DataRate and DataResourceCost are:
+		 * 		DataRate = packetSize / packetInterval
+		 * 		DataResourceCost = packetResourceCost / packetSize
+		 * 
+		 * So, the resulting score is essentially in terms of joules per byte per baud.  Rearranging that a bit, it
+		 * could also look like joule-seconds per byte per byte, or newton-meter-seconds per byte per byte.  Either way,
+		 * that metric is not a very reasonable one.
+		 * 
+		 * Two metrics that might make more sense are joules per byte or joules per byte per second.  The latter case
+		 * would look like:
+		 * 		DataRate = packetSize / packetInterval
+		 * 		DataResourceCost = packetResourceCost
+		 * 
+		 * The former case, which I've chosen to implement below, is:
+		 * 		DataRate = packetSize
+		 * 		DataResourceCost = packetResourceCost
+		 * 
+		 * So... hopefully that doesn't screw with anything else.
+		 * */
+		// Override ModuleDataTransmitter.DataRate to just return packetSize, because we want antennas to be scored in
+		// terms of joules/byte
+		public new float DataRate
+		{
+			get
+			{
+				PreTransmit_SetPacketSize();
+				return this.packetSize;
+			}
+		}
+
+		// Override ModuleDataTransmitter.DataResourceCost to just return packetResourceCost, because we want antennas
+		// to be scored in terms of joules/byte
+		public new float DataResourceCost
+		{
+			get
+			{
+				PreTransmit_SetPacketResourceCost();
+				return this.packetResourceCost;
+			}
+		}
 
 		// Build ALL the objects.
 		public ModuleLimitedDataTransmitter () : base() { }
@@ -108,9 +157,28 @@
 		// work.
 		public override void OnLoad(ConfigNode node)
 		{
+			this.Fields.Load(node);
+			base.Fields.Load(node);
+
 			base.OnLoad (node);
+
 			this._basepacketSize = base.packetSize;
 			this._basepacketResourceCost = base.packetResourceCost;
+
+			Tools.PostDebugMessage(string.Format(
+				"{0} loaded:\n" +
+				"packetSize: {1}\n" +
+				"packetResourceCost: {2}\n" +
+				"nominalRange: {3}\n" +
+				"maxPowerFactor: {4}\n" +
+				"maxDataFactor: {5}\n",
+				this.name,
+				base.packetSize,
+				this._basepacketResourceCost,
+				this.nominalRange,
+				this.maxPowerFactor,
+				this.maxDataFactor
+			));
 		}
 
 		// Post an error in the communication messages describing the reason transmission has failed.  Currently there
@@ -236,7 +304,10 @@
 				"maxTransmitDistance: {5}\n" +
 				"transmitDistance: {6}\n" +
 				"nominalRange: {7}\n" +
-				"CanTransmit: {8}",
+				"CanTransmit: {8}\n" +
+				"DataRate: {9}\n" +
+				"DataResourceCost: {10}\n" +
+				"TransmitterScore: {11}",
 				this.name,
 				this._basepacketSize,
 				base.packetSize,
@@ -245,7 +316,10 @@
 				this.maxTransmitDistance,
 				this.transmitDistance,
 				this.nominalRange,
-				this.CanTransmit()
+				this.CanTransmit(),
+				this.DataRate,
+				this.DataResourceCost,
+				ScienceUtil.GetTransmitterScore(this)
 				);
 			ScreenMessages.PostScreenMessage (new ScreenMessage (msg, 4f, ScreenMessageStyle.UPPER_RIGHT));
 		}
@@ -256,12 +330,18 @@
 	{
 		// When debugging, be verbose.  The Conditional attribute prevents this from firing when not DEBUGging.
 		[System.Diagnostics.Conditional("DEBUG")]
-		public static void PostDebugMessage(string Str)
-		{
-			ScreenMessage Message = new ScreenMessage (Str, 4f, ScreenMessageStyle.LOWER_CENTER);
-			ScreenMessages.PostScreenMessage (Message);
+		public static void PostDebugMessage(string Msg)
+		{
+			if (HighLogic.LoadedScene > GameScenes.SPACECENTER)
+			{
+				ScreenMessage Message = new ScreenMessage(Msg, 4f, ScreenMessageStyle.LOWER_CENTER);
+				ScreenMessages.PostScreenMessage(Message);
+			}
+			else
+			{
+				KSPLog.print(Msg);
+			}
 		}
 	}
 }
 
-