csproj changes for Visual Studio
csproj changes for Visual Studio

--- a/ARConfiguration.cs
+++ b/ARConfiguration.cs
@@ -565,8 +565,10 @@
 
 						compileArgs[0] = availablePart;
 						compileArgs[1] = partPrefab;
-
-						partLoader_CompilePartInfo.Invoke(PartLoader.Instance, compileArgs);
+                        if (PartLoader.Instance != null)
+                            partLoader_CompilePartInfo.Invoke(PartLoader.Instance, compileArgs);
+                        else
+                            this.Log("PartLoader.Instance is null");
 
 						break;
 					}

--- a/ARFlightController.cs
+++ b/ARFlightController.cs
@@ -157,8 +157,8 @@
 				this.toolbarButton.TexturePath = this.toolbarTextures[ConnectionStatus.None];
 				this.toolbarButton.Text = "AntennaRange";
 				this.toolbarButton.Visibility = new GameScenesVisibility(GameScenes.FLIGHT);
-				this.toolbarButton.OnClick += (e) => (this.buttonToggle());
-			}
+                this.toolbarButton.OnClick += (e) => { this.buttonToggle(); };
+            }
 
 			GameEvents.onGameSceneLoadRequested.Add(this.onSceneChangeRequested);
 			GameEvents.onVesselChange.Add(this.onVesselChange);
@@ -173,7 +173,7 @@
 
 			VesselCommand availableCommand;
 
-			if (ARConfiguration.RequireConnectionForControl)
+			if (ARConfiguration.RequireConnectionForControl && this.vessel != null)
 			{
 				availableCommand = this.vessel.CurrentCommand();
 			}
@@ -334,8 +334,8 @@
 
 					log.AppendFormat("\nFinding nearest relay for active vessel relay {0}", relay);
 
+					relay.FindNearestRelay();
 					relay.RecalculateTransmissionRates();
-					relay.FindNearestRelay();
 				}
 
 				if (this.toolbarButton != null || this.appLauncherButton != null)

--- a/AntennaRange.csproj
+++ b/AntennaRange.csproj
@@ -1,10 +1,8 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug_win</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>8.0.30703</ProductVersion>
-    <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{B36F2C11-962E-4A75-9F41-61AD56D11493}</ProjectGuid>
     <OutputType>Library</OutputType>
     <RootNamespace>AntennaRange</RootNamespace>
@@ -103,13 +101,16 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
+    <None Include="GameData\AntennaRange\AntennaRange.cfg" />
+    <None Include="GameData\AntennaRange\ATM_AntennaRange.cfg" />
+  </ItemGroup>
+  <ItemGroup>
     <ProjectReference Include="..\ToadicusTools\ToadicusTools.csproj">
       <Project>{D48A5542-6655-4149-BC27-B27DF0466F1C}</Project>
       <Name>ToadicusTools</Name>
     </ProjectReference>
   </ItemGroup>
-  <ItemGroup>
-    <None Include="GameData\AntennaRange\AntennaRange.cfg" />
-    <None Include="GameData\AntennaRange\ATM_AntennaRange.cfg" />
-  </ItemGroup>
+  <PropertyGroup>
+    <PostBuildEvent>xcopy /Y $(TargetPath) $(ProjectDir)GameData\$(ProjectName)</PostBuildEvent>
+  </PropertyGroup>
 </Project>

--- a/GameData/AntennaRange/AntennaRange.cfg
+++ b/GameData/AntennaRange/AntennaRange.cfg
@@ -48,6 +48,9 @@
 		simpleRange = 20500000
 		maxPowerFactor = 8
 		maxDataFactor = 4
+
+		basePacketSize = #$packetSize$
+		basePacketResourceCost = #$packetResourceCost$
 	}
 
 	MODULE
@@ -70,6 +73,9 @@
 		simpleRange = 18000000000
 		maxPowerFactor = 4
 		maxDataFactor = 8
+
+		basePacketSize = #$packetSize$
+		basePacketResourceCost = #$packetResourceCost$
 	}
 
 	MODULE
@@ -93,6 +99,9 @@
 		simpleRange = 56250000000
 		maxPowerFactor = 16
 		maxDataFactor = 2
+
+		basePacketSize = #$packetSize$
+		basePacketResourceCost = #$packetResourceCost$
 	}
 
 	MODULE
@@ -118,6 +127,9 @@
 		simpleRange = 25030376544
 		maxPowerFactor = 2.6180339887498948
 		maxDataFactor = 9
+
+		basePacketSize = #$packetSize$
+		basePacketResourceCost = #$packetResourceCost$
 	}
 
 	MODULE
@@ -151,6 +163,9 @@
 	packetSize = 1
 	packetResourceCost = 6.25
 
+	basePacketSize = #$packetSize$
+	baseResourceCost = #$packetResourceCost$
+
 	requiredResource = ElectricCharge
 }
 

--- a/ModuleLimitedDataTransmitter.cs
+++ b/ModuleLimitedDataTransmitter.cs
@@ -52,9 +52,6 @@
 		: ModuleDataTransmitter, IScienceDataTransmitter, IAntennaRelay, IModuleInfo
 	{
 		private const string tooltipSkinName = "PartTooltipSkin";
-		private static GUISkin partTooltipSkin;
-		private static GUIStyle partTooltipBodyStyle;
-		private static GUIStyle partTooltipHeaderStyle;
 
 		// Every antenna is a relay.
 		private AntennaRelay relay;
@@ -62,8 +59,17 @@
 		// Sometimes we will need to communicate errors; this is how we do it.
 		private ScreenMessage ErrorMsg;
 
-		// Used in module info panes for part tooltips in the editor and R&D
-		private GUIContent moduleInfoContent;
+		/// <summary>
+		/// The base size of a transmission packet, in MiT.
+		/// </summary>
+		[KSPField(isPersistant = false)]
+		public float basePacketSize;
+
+		/// <summary>
+		/// The base resource cost of a transmission packet, presumably in EC.
+		/// </summary>
+		[KSPField(isPersistant = false)]
+		public float basePacketResourceCost;
 
 		/// <summary>
 		/// When additive ranges are enabled, the distance from Kerbin at which the antenna will perform exactly as
@@ -186,6 +192,7 @@
 			}
 		}
 
+		private RelayDataCost _currentLinkCost = new RelayDataCost();
 		/// <summary>
 		/// Gets the current link resource rate in EC/MiT.
 		/// </summary>
@@ -194,7 +201,9 @@
 		{
 			get
 			{
-				return new RelayDataCost(this.packetResourceCost, this.packetSize);
+				_currentLinkCost.PacketResourceCost = this.packetResourceCost;
+				_currentLinkCost.PacketSize = this.packetSize;
+				return _currentLinkCost;
 			}
 			set
 			{
@@ -479,16 +488,13 @@
 			this.packetThrottle = 100f;
 		}
 
+		#if DEBUG
 		/// <summary>
 		/// PartModule OnAwake override; runs at Unity Awake.
 		/// </summary>
 		public override void OnAwake()
 		{
 			base.OnAwake();
-
-			this.BaseLinkCost = new RelayDataCost(base.packetSize, base.packetResourceCost);
-
-			this.moduleInfoContent = new GUIContent();
 
 			this.LogDebug("{0} loaded:\n" +
 				"packetSize: {1}\n" +
@@ -504,6 +510,7 @@
 				this.maxDataFactor
 			);
 		}
+		#endif
 
 		/// <summary>
 		/// PartModule OnStart override; runs at Unity Start.
@@ -511,9 +518,10 @@
 		/// <param name="state">State.</param>
 		public override void OnStart (StartState state)
 		{
+			this.BaseLinkCost = new RelayDataCost(this.basePacketResourceCost, this.basePacketSize);
+			this.RecalculateMaxRange();
+
 			base.OnStart (state);
-
-			this.RecalculateMaxRange();
 
 			if (state >= StartState.PreLaunch)
 			{
@@ -541,6 +549,7 @@
 
 			base.OnLoad (node);
 
+			this.BaseLinkCost = new RelayDataCost(this.basePacketResourceCost, this.basePacketSize);
 			this.RecalculateMaxRange();
 		}
 
@@ -646,9 +655,9 @@
 
 				sb.AppendLine();
 
-				sb.AppendFormat("<b>Nominal Packet Size: </b>{0:S3}iT\n", this.BaseLinkCost.PacketSize * 1000000f);
+				sb.AppendFormat("<b>Nominal Packet Size: </b>{0:S2}iT\n", this.BaseLinkCost.PacketSize * 1000000f);
 				sb.AppendFormat(
-					"<b>Nominal Data Rate: </b>{0:S3}iT/sec\n",
+					"<b>Nominal Data Rate: </b>{0:S2}iT/sec\n",
 					this.BaseLinkCost.PacketSize / this.packetInterval * 1000000f
 				);
 
@@ -744,7 +753,14 @@
 			if (this.relay != null)
 			{
 				this.relay.RecalculateTransmissionRates();
-			}
+				this.LogDebug("Recalculated transmission rates in MLDT, cost is {0}", this.CurrentLinkCost);
+			}
+			#if DEBUG
+			else
+			{
+				this.LogDebug("Skipping recalculation; relay is null.");
+			}
+			#endif
 		}
 
 		/// <summary>
@@ -976,6 +992,8 @@
 				if (this.part != null && this.part.partInfo != null)
 				{
 					sb.Append(this.part.partInfo.title);
+					sb.Append('#');
+					sb.Append(this.part.flightID);
 				}
 				else
 				{

--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs
@@ -39,7 +39,7 @@
 // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
 // The form "{Major}.{Minor}.*" will automatically update the build and revision,
 // and "{Major}.{Minor}.{Build}.*" will update just the revision.
-[assembly: AssemblyVersion("1.11.1.*")]
+[assembly: AssemblyVersion("1.11.3.*")]
 // The following attributes are used to specify the signing key for the assembly,
 // if desired. See the Mono documentation for more information about signing.
 //[assembly: AssemblyDelaySign(false)]

--- a/ProtoAntennaRelay.cs
+++ b/ProtoAntennaRelay.cs
@@ -218,6 +218,8 @@
 
 				if (this.protoPart != null && this.protoPart.pVesselRef != null)
 				{
+					sb.Append('#');
+					sb.Append(this.protoPart.flightID);
 					sb.AppendFormat(" on {0}", this.protoPart.pVesselRef.vesselName);
 				}
 

--- a/RelayDataCost.cs
+++ b/RelayDataCost.cs
@@ -65,7 +65,7 @@
 				lcd.PacketResourceCost *= mul;
 			}
 
-			return new RelayDataCost(gcd.PacketResourceCost + lcd.PacketResourceCost, gcd.PacketSize + lcd.PacketSize);
+			return new RelayDataCost(gcd.PacketResourceCost + lcd.PacketResourceCost, gcd.PacketSize);
 		}
 
 		/// <param name="only">RelayDataCost to be negated</param>

--- a/RelayDatabase.cs
+++ b/RelayDatabase.cs
@@ -419,6 +419,8 @@
 			GameEvents.onVesselWasModified.Add(this.onVesselEvent);
 			GameEvents.onVesselChange.Add(this.onVesselEvent);
 			GameEvents.onVesselDestroy.Add(this.onVesselEvent);
+			GameEvents.onVesselGoOnRails.Add(this.onVesselEvent);
+			GameEvents.onVesselGoOffRails.Add(this.onVesselEvent);
 			GameEvents.onGameSceneLoadRequested.Add(this.onSceneChange);
 			GameEvents.onPartCouple.Add(this.onFromPartToPartEvent);
 			GameEvents.onPartUndock.Add(this.onPartEvent);
@@ -431,6 +433,8 @@
 			GameEvents.onVesselWasModified.Remove(this.onVesselEvent);
 			GameEvents.onVesselChange.Remove(this.onVesselEvent);
 			GameEvents.onVesselDestroy.Remove(this.onVesselEvent);
+			GameEvents.onVesselGoOnRails.Remove(this.onVesselEvent);
+			GameEvents.onVesselGoOffRails.Add(this.onVesselEvent);
 			GameEvents.onGameSceneLoadRequested.Remove(this.onSceneChange);
 			GameEvents.onPartCouple.Remove(this.onFromPartToPartEvent);
 			GameEvents.onPartUndock.Remove(this.onPartEvent);

--- a/RelayExtensions.cs
+++ b/RelayExtensions.cs
@@ -343,7 +343,13 @@
 		[System.Diagnostics.Conditional("DEBUG")]
 		public static void LogDebug(this AntennaRelay relay, string format, params object[] args)
 		{
-			ToadicusTools.Logging.PostDebugMessage(string.Format("[{0}] {1}", relay.ToString(), format), args);
+			using (var sb = ToadicusTools.Text.PooledStringBuilder.Get())
+			{
+				sb.AppendFormat("[{0}] ", relay == null ? "NULL" : relay.ToString());
+				sb.AppendFormat(format, args);
+
+				ToadicusTools.Logging.PostDebugMessage(sb.ToString());
+			}
 		}
 
 		/// <summary>
@@ -352,7 +358,13 @@
 		[System.Diagnostics.Conditional("DEBUG")]
 		public static void LogDebug(this AntennaRelay relay, string msg)
 		{
-			ToadicusTools.Logging.PostDebugMessage("[{0}] {1}", relay.ToString(), msg);
+			using (var sb = ToadicusTools.Text.PooledStringBuilder.Get())
+			{
+				sb.AppendFormat("[{0}] ", relay == null ? "NULL" : relay.ToString());
+				sb.Append(msg);
+
+				ToadicusTools.Logging.PostDebugMessage(sb.ToString());
+			}
 		}
 	}