public bool AttachComponent(Type componentType)
        {
            ModularCommNetVesselComponent modularCommNetVesselInstance = null;

            try
            {
                /*if (type.GetConstructor(new Type[] { typeof(ModularCommNetVesselModule) }) != null)
                 *  modularCommNetVesselInstance = Activator.CreateInstance(type, new object[] { this }) as ModularCommNetVessel;
                 * else
                 * {
                 *  modularCommNetVesselInstance = Activator.CreateInstance(type) as ModularCommNetVessel;
                 * }*/
                //modularCommNetVesselInstance = Activator.CreateInstance(type, new object[] { this }) as ModularCommNetVessel;
                modularCommNetVesselInstance = gameObject.AddComponent(componentType) as ModularCommNetVesselComponent;
                modularCommNetVesselInstance.CommNetVessel = this;
            }
            catch (Exception ex)
            {
                log.error("Encountered an exception while calling the constructor for " + componentType.Name);
                log.error(ex);
            }
            if (modularCommNetVesselInstance != null)
            {
                Components.Add(modularCommNetVesselInstance);
                modularRefs.Add(componentType, modularCommNetVesselInstance);
                log.debug("Activated an instance of type: " + componentType.Name);
                return(true);
            }
            else
            {
                log.warning("Failed to activate " + componentType.Name);
            }
            return(false);
        }
        /// <summary>
        /// Gets the signal strength modifier.
        /// </summary>
        /// <param name="callingInstance">The calling instance.</param>
        /// <param name="b">The other node.</param>
        /// <returns></returns>
        public double GetSignalStrengthModifier(ModularCommNetVesselComponent callingInstance, CommNode b)
        {
            double value = 0;

            for (int i = 0; i < Sequence_GetSignalStrengthModifier.EarlyLate.Count; i++)
            {
                if (Sequence_GetSignalStrengthModifier.MetaDict[Sequence_GetSignalStrengthModifier.EarlyLate[i]] == callingInstance)
                {
                    continue;
                }
                try { value += Sequence_GetSignalStrengthModifier.EarlyLate[i].Invoke(b); }
                catch (Exception ex) { Debug.LogError(ex); }
            }
            value += base.GetSignalStrengthModifier(b);
            for (int i = 0; i < Sequence_GetSignalStrengthModifier.Post.Count; i++)
            {
                if (Sequence_GetSignalStrengthModifier.MetaDict[Sequence_GetSignalStrengthModifier.Post[i]] == callingInstance)
                {
                    continue;
                }
                try { value += Sequence_GetSignalStrengthModifier.Post[i].Invoke(b); }
                catch (Exception ex) { Debug.LogError(ex); }
            }
            return(value);
        }
        /// <summary>
        /// Gets the best transmitter.
        /// </summary>
        /// <param name="callingInstance">The calling instance.</param>
        /// <returns></returns>
        public IScienceDataTransmitter GetBestTransmitter(ModularCommNetVesselComponent callingInstance)
        {
            IScienceDataTransmitter value;

            for (int i = 0; i < Sequence_GetBestTransmitter.EarlyLate.Count; i++)
            {
                if (Sequence_GetBestTransmitter.MetaDict[Sequence_GetBestTransmitter.EarlyLate[i]] == callingInstance)
                {
                    continue;
                }
                try { Sequence_GetBestTransmitter.EarlyLate[i].Invoke(); }
                catch (Exception ex) { Debug.LogError(ex); }
            }
            value = base.GetBestTransmitter();
            for (int i = 0; i < Sequence_GetBestTransmitter.Post.Count; i++)
            {
                if (Sequence_GetBestTransmitter.MetaDict[Sequence_GetBestTransmitter.Post[i]] == callingInstance)
                {
                    continue;
                }
                try { Sequence_GetBestTransmitter.Post[i].Invoke(); }
                catch (Exception ex) { Debug.LogError(ex); }
            }
            return(value);
        }
        /// <summary>
        /// Creates the control connection.
        /// </summary>
        /// <param name="callingInstance">The calling instance.</param>
        /// <returns></returns>
        public bool CreateControlConnection(ModularCommNetVesselComponent callingInstance)
        {
            bool value = true;

            for (int i = 0; i < Sequence_CreateControlConnection.EarlyLate.Count; i++)
            {
                if (Sequence_CreateControlConnection.MetaDict[Sequence_CreateControlConnection.EarlyLate[i]].b == callingInstance)
                {
                    continue;
                }
                try { value = AndOr(value, Sequence_CreateControlConnection.EarlyLate[i].Invoke(), Sequence_CreateControlConnection.MetaDict[Sequence_CreateControlConnection.EarlyLate[i]].a); }
                catch (Exception ex) { Debug.LogError(ex); }
            }
            value &= base.CreateControlConnection();
            for (int i = 0; i < Sequence_CreateControlConnection.Post.Count; i++)
            {
                if (Sequence_CreateControlConnection.MetaDict[Sequence_CreateControlConnection.Post[i]].b == callingInstance)
                {
                    continue;
                }
                try { value = AndOr(value, Sequence_CreateControlConnection.Post[i].Invoke(), Sequence_CreateControlConnection.MetaDict[Sequence_CreateControlConnection.Post[i]].a); }
                catch (Exception ex) { Debug.LogError(ex); }
            }
            return(value);
        }
 /// <summary>
 /// Updates the Comm field.
 /// </summary>
 /// <param name="callingInstance">The calling instance.</param>
 public void UpdateComm(ModularCommNetVesselComponent callingInstance)
 {
     for (int i = 0; i < Sequence_UpdateComm.EarlyLate.Count; i++)
     {
         if (Sequence_UpdateComm.MetaDict[Sequence_UpdateComm.EarlyLate[i]] == callingInstance)
         {
             continue;
         }
         try { Sequence_UpdateComm.EarlyLate[i].Invoke(); }
         catch (Exception ex) { Debug.LogError(ex); }
     }
     base.UpdateComm();
     for (int i = 0; i < Sequence_UpdateComm.Post.Count; i++)
     {
         if (Sequence_UpdateComm.MetaDict[Sequence_UpdateComm.Post[i]] == callingInstance)
         {
             continue;
         }
         try { Sequence_UpdateComm.Post[i].Invoke(); }
         catch (Exception ex) { Debug.LogError(ex); }
     }
 }
 /// <summary>
 /// Gets the control level.
 /// </summary>
 /// <param name="callingInstance">The calling instance.</param>
 public Vessel.ControlLevel GetControlLevel(ModularCommNetVesselComponent callingInstance)
 {
     Vessel.ControlLevel value;
     for (int i = 0; i < Sequence_GetControlLevel.EarlyLate.Count; i++)
     {
         if (Sequence_GetControlLevel.MetaDict[Sequence_GetControlLevel.EarlyLate[i]] == callingInstance)
         {
             continue;
         }
         try { Sequence_GetControlLevel.EarlyLate[i].Invoke(); }
         catch (Exception ex) { Debug.LogError(ex); }
     }
     value = base.GetControlLevel();
     for (int i = 0; i < Sequence_GetControlLevel.Post.Count; i++)
     {
         if (Sequence_GetControlLevel.MetaDict[Sequence_GetControlLevel.Post[i]] == callingInstance)
         {
             continue;
         }
         try { Sequence_GetControlLevel.Post[i].Invoke(); }
         catch (Exception ex) { Debug.LogError(ex); }
     }
     return(value);
 }
        private void ParseDelegates(string methodName, MethodInfo method, CNMAttrSequence.options sequence)
        {
            ModularCommNetVesselComponent instance = modularRefs[methodTypes[method]];

    #if DEBUG
            if (andOrList.ContainsKey(method))
            {
                Debug.LogFormat("ModularCommNetVessel: Parsing {0} from {1} as {2} with {3}.", methodName, instance.GetType().Name, sequence, andOrList[method]);
            }
            else
            {
                Debug.LogFormat("ModularCommNetVessel: Parsing {0} from {1} as {2}.", methodName, instance.GetType().Name, sequence);
            }
    #endif

            try
            {
                switch (methodName)
                {
                case "Awake":
                    Sequence_Awake.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnAwake":
                    Sequence_OnAwake.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnStart":
                    Sequence_OnStart.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnDestroy":
                    Sequence_OnDestroy.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnGoOffRails":
                    Sequence_OnGoOffRails.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnGoOnRails":
                    Sequence_OnGoOnRails.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnLoad":
                    Sequence_OnLoad.Add(sequence, Delegate.CreateDelegate(typeof(Action <ConfigNode>), instance, method) as Action <ConfigNode>, instance);
                    break;

                case "OnSave":
                    Sequence_OnSave.Add(sequence, Delegate.CreateDelegate(typeof(Action <ConfigNode>), instance, method) as Action <ConfigNode>, instance);
                    break;

                case "Update":
                    Sequence_Update.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "OnNetworkInitialized":
                    Sequence_OnNetworkInitialized.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkPreUpdate":
                    Sequence_OnNetworkPreUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "OnNetworkPostUpdate":
                    Sequence_OnNetworkPostUpdate.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action);
                    break;

                case "CalculatePlasmaMult":
                    Sequence_CalculatePlasmaMult.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "UpdateComm":
                    Sequence_UpdateComm.Add(sequence, Delegate.CreateDelegate(typeof(Action), instance, method) as Action, instance);
                    break;

                case "CreateControlConnection":
                    Sequence_CreateControlConnection.Add(sequence, Delegate.CreateDelegate(typeof(Func <bool>), instance, method) as Func <bool>, new Pair <CNMAttrAndOr.options, ModularCommNetVesselComponent>(andOrList[method], instance));
                    break;

                case "GetBestTransmitter":
                    Sequence_GetBestTransmitter.Add(sequence, Delegate.CreateDelegate(typeof(Func <IScienceDataTransmitter>), instance, method) as Func <IScienceDataTransmitter>, instance);
                    break;

                case "GetControlLevel":
                    Sequence_GetControlLevel.Add(sequence, Delegate.CreateDelegate(typeof(Func <Vessel.ControlLevel>), instance, method) as Func <Vessel.ControlLevel>, instance);
                    break;

                case "OnMapFocusChange":
                    Sequence_OnMapFocusChange.Add(sequence, Delegate.CreateDelegate(typeof(Action <MapObject>), instance, method) as Action <MapObject>);
                    break;

                case "GetSignalStrengthModifier":
                    Sequence_GetSignalStrengthModifier.Add(sequence, Delegate.CreateDelegate(typeof(Func <CommNode, double>), instance, method) as Func <CommNode, double>, instance);
                    break;

                default:
    #if DEBUG
                    log.warning("The method passed (" + methodName + ") was not a standard CommNet method.");
    #endif
                    return;
                }
                log.debug("Successfully parsed " + methodName + " from type " + instance.GetType().Name);
            }
            catch (Exception ex)
            {
                log.error("Encountered an error creating a delegate for " + methodName + " from type " + instance.GetType().Name);
                log.error(ex);
            }
        }