Now maintaining a hash table for ProtoAntennaRelays and using prefab modules to do the maths and stuff, in lieu of messing with persistence and stuff. Also made the error message prettier. proto_to_prefab
[AntennaRange.git] / Extensions.cs
blob:a/Extensions.cs -> blob:b/Extensions.cs
--- a/Extensions.cs
+++ b/Extensions.cs
@@ -82,87 +82,10 @@
 		/// <param name="vessel">This <see cref="Vessel"/></param>
 		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 the vessel is loaded, we can fetch modules implementing IAntennaRelay directly.
-			if (vessel.loaded) {
-				Tools.PostDebugMessage(string.Format(
-					"{0}: vessel {1} is loaded.",
-					"IAntennaRelay",
-					vessel.name
-					));
-
-				// Gets a list of PartModules implementing IAntennaRelay
-				Transmitters = vessel.Parts
-					.SelectMany (p => p.Modules.OfType<IAntennaRelay> ())
-					.ToList();
-			}
-			// If the vessel is not loaded, we need to build ProtoAntennaRelays when we find relay ProtoPartSnapshots.
-			else
-			{
-				Tools.PostDebugMessage(string.Format(
-					"{0}: vessel {1} is not loaded.",
-					"IAntennaRelay",
-					vessel.name
-					));
-
-				Transmitters = new List<IAntennaRelay>();
-
-				// Loop through the ProtoPartModuleSnapshots in this Vessel
-				foreach (ProtoPartSnapshot pps in vessel.protoVessel.protoPartSnapshots)
-				{
-					IAntennaRelay relayModule;
-					ProtoAntennaRelay protoRelay;
-					int partHash;
-
-					relayModule = null;
-					protoRelay = null;
-					partHash = pps.GetHashCode();
-
-					if (prebuiltProtoRelays.ContainsKey(partHash))
-					{
-						protoRelay = prebuiltProtoRelays[partHash];
-					}
-					else
-					{
-						foreach (PartModule module in PartLoader.getPartInfoByName(pps.partName).partPrefab.Modules)
-						{
-							if (module is IAntennaRelay)
-							{
-								relayModule = module as IAntennaRelay;
-
-								protoRelay = new ProtoAntennaRelay(relayModule, vessel);
-								prebuiltProtoRelays[partHash] = protoRelay;
-								break;
-							}
-						}
-					}
-
-					if (protoRelay != null)
-					{
-						Transmitters.Add(protoRelay);
-					}
-				}
-			}
-
-			Tools.PostDebugMessage(string.Format(
-				"{0}: vessel {1} has {2} transmitters.",
-				"IAntennaRelay",
-				vessel.name,
-				Transmitters.Count
-				));
-
-			// Return the list of IAntennaRelays
-			return Transmitters;
+			return RelayDatabase.Instance[vessel].Values.ToList();
 		}
 
-		private static Dictionary<int, ProtoAntennaRelay> prebuiltProtoRelays = new Dictionary<int, ProtoAntennaRelay>();
+
 	}
 }