Пример #1
0
        public KeyValuePair <bool, double> modReturn;   // Return from ECDevice

        public override void OnStart(StartState state)
        {
            // don't break tutorial scenarios & do something only in Flight scenario
            if (Lib.DisableScenario(this) || !Lib.IsFlight())
            {
                return;
            }

            Lib.Debug("Executing OnStart");
            // cache list of modules
            module = part.FindModulesImplementing <PartModule>().FindLast(k => k.moduleName == type);

            // get energy from cache
            resources = ResourceCache.Info(vessel, "ElectricCharge");
            hasEnergy = resources.amount > double.Epsilon;

            // Force the update to run at least once
            lastBrokenState       = !broken;
            hasEnergyChanged      = !hasEnergy;
            hasFixedEnergyChanged = !hasEnergy;

#if DEBUG
            // setup UI
            Fields["actualCost"].guiActive = true;
            Fields["broken"].guiActive     = true;
#endif
        }
Пример #2
0
        public IEnumerator NetworkInitialized()
        {
            yield return(new WaitForSeconds(2));

            Lib.Debug("NetworkInitialized");
            Communications.NetworkInitialized = true;
        }
Пример #3
0
        public static void AntennaUpdate(Vessel v, bool refresh = false)
        {
            // get vessel id
            UInt32 id = Lib.VesselID(v);

            bool hasEC = ResourceCache.Info(v, "ElectricCharge").amount > double.Epsilon;

            // get the info from the cache, if it exist update
            if (antennasCache.TryGetValue(id, out Antenna_Info info))
            {
                // EC state changed since last update?
                if (info.hasECChanged != hasEC || info.isTimeToUpdate)
                {
                    // Update old cache
                    Lib.Debug("Triggered: Update existing antenna cache");

                    // Update Antenna
                    antennasCache[id] = new Antenna_Info(v)
                    {
                        hasECChanged = hasEC
                    };
                }
            }
            else // Create a new entry
            {
                Lib.Debug("New antenna cache");
                info = new Antenna_Info(v)
                {
                    hasECChanged = hasEC
                };
                antennasCache.Add(id, info);
            }
        }
Пример #4
0
 public void Stop()
 {
     Lib.Debug("Stopping Transformation");
     if (transf != null)
     {
         rotationRateGoal = 0.0f;
     }
 }
Пример #5
0
 private void OnVesselCountChanged(Vessel v)
 {
     if (Lib.IsVessel(v))
     {
         Lib.Debug("Change in the vessel list detected. Cache refresh required");
         Cache.refreshCommNode = true;
     }
 }
Пример #6
0
 public void Play()
 {
     Lib.Debug("Playing Transformation");
     if (transf != null)
     {
         rotationRateGoal = 1.0f;
     }
 }
Пример #7
0
 public void ToggleActions(PartModule partModule, bool value)
 {
     Lib.Debug("Part '{0}'.'{1}', setting actions to {2}", partModule.part.partInfo.title, partModule.moduleName, value ? "ON" : "OFF");
     foreach (BaseAction ac in partModule.Actions)
     {
         ac.active = value;
     }
 }
Пример #8
0
        public override void OnUpdate()
        {
            if (!Lib.IsFlight() || module == null)
            {
                return;
            }

            // get energy from cache
            resources = ResourceCache.Info(vessel, "ElectricCharge");
            hasEnergy = resources.amount > double.Epsilon;

            // Update UI only if hasEnergy has changed or if is broken state has changed
            if (broken)
            {
                if (broken != lastBrokenState)
                {
                    lastBrokenState = broken;
                    Update_UI(!broken);
                }
            }
            else if (hasEnergyChanged != hasEnergy)
            {
                Lib.Debug("Energy state has changed: {0}", hasEnergy);

                // Wait 1 second before enabled UI.
                if (hasEnergy)
                {
                    Lib.Delay(1f);
                }

                hasEnergyChanged = hasEnergy;
                lastBrokenState  = false;
                // Update UI
                Update_UI(hasEnergy);
            }
            // Constantly Update UI for special modules
            if (broken)
            {
                Constant_OnGUI(!broken);
            }
            else
            {
                Constant_OnGUI(hasEnergy);
            }

            if (!hasEnergy || broken)
            {
                actualCost  = 0;
                isConsuming = false;
            }
            else
            {
                isConsuming = GetIsConsuming();
            }
        }
Пример #9
0
        // GameEvent of vessel being modified
        private void VesselModified(Vessel thisVessel)
        {
            if (Vessel.isActiveVessel && stageActivated) // decouple event
            {
                Lib.Debug("Active CommNet Vessel '{0}' is staged. Updating antenna cache...", thisVessel.vesselName);

                //force-update antenna cache
                Cache.AntennaInfo(thisVessel);

                stageActivated = false;
            }
        }
Пример #10
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            if (HighLogic.CurrentGame == null)
            {
                return;
            }

            GameEvents.onStageActivate.Remove(StageActivate);
            GameEvents.onVesselWasModified.Remove(VesselModified);

            Lib.Debug("Vessel '{0}' is destroyed.", Vessel.vesselName);
        }
Пример #11
0
        // enable/disable dialog "Transfer crew" on UI
        public void RefreshDialog()
        {
            Lib.Debug("Refreshing Dialog");
            if (HighLogic.LoadedSceneIsEditor)
            {
                GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartTweaked, part);
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
            }
            else if (HighLogic.LoadedSceneIsFlight)
            {
                GameEvents.onVesselWasModified.Fire(this.vessel);
            }

            part.CheckTransferDialog();
            MonoUtilities.RefreshContextWindows(part);
        }
Пример #12
0
		void SetPassable(bool isPassable)
		{
			if (hasCLS)
			{
				// for each module
				foreach (PartModule m in part.Modules)
				{
					if (m.moduleName == "ModuleConnectedLivingSpace")
					{
						Lib.ReflectionValue(m, "passable", isPassable);
						Lib.Debug("Part '{0}', CLS has been {1}", part.partInfo.title, isPassable ? "enabled" : "disabled");
					}
				}
			}

			Lib.Debug("CrewCapacity: '{0}'", part.CrewCapacity);
			Lib.Debug("CrewTransferAvailable: '{0}'", isPassable);
			part.crewTransferAvailable = isPassable;
		}
Пример #13
0
 // Enable/Disable IVA
 void UpdateIVA(bool ative)
 {
     if (Lib.IsFlight())
     {
         if (vessel.isActiveVessel)
         {
             if (ative)
             {
                 Lib.Debug("Part '{0}', Spawning IVA.", part.partInfo.title);
                 part.SpawnIVA();
             }
             else
             {
                 Lib.Debug("Part '{0}', Destroying IVA.", part.partInfo.title);
                 part.DespawnIVA();
             }
             RefreshDialog();
         }
     }
 }
Пример #14
0
        protected override void Start()
        {
            if (Features.KCommNet)
            {
                Instance = this;
                Cache.InitGroundStation();
                Cache.refreshCommNode = true;

                Lib.Debug("KCommNet Scenario loading ...");
                //Replace the CommNet user interface
                CommNetUI ui = FindObjectOfType <CommNetUI>();
                CustomCommNetUI = gameObject.AddComponent <KCommNetUI>();
                Destroy(ui);

                //Replace the CommNet network
                CommNetNetwork net = FindObjectOfType <CommNetNetwork>();
                CustomCommNetNetwork = gameObject.AddComponent <KCommNetNetwork>();
                Destroy(net);

                //Replace the CommNet ground stations
                CommNetHome[] homes = FindObjectsOfType <CommNetHome>();
                for (int i = 0; i < homes.Length; i++)
                {
                    KCommNetHome customHome = homes[i].gameObject.AddComponent(typeof(KCommNetHome)) as KCommNetHome;
                    customHome.CopyOf(homes[i]);
                    Destroy(homes[i]);
                    //DB.Station(customHome.nodeName);
                    Cache.LoadGroundStation(customHome);
                }

                //Replace the CommNet celestial bodies
                CommNetBody[] bodies = FindObjectsOfType <CommNetBody>();
                for (int i = 0; i < bodies.Length; i++)
                {
                    KCommNetBody customBody = bodies[i].gameObject.AddComponent(typeof(KCommNetBody)) as KCommNetBody;
                    customBody.CopyOf(bodies[i]);
                    Destroy(bodies[i]);
                }
                Lib.Verbose("CommNet Scenario loading done!");
            }
        }
Пример #15
0
        public static void CacheCommNetVessels()
        {
            if (!Cache.refreshCommNode)
            {
                return;
            }

            Cache.InitCommVessels();

            List <Vessel> allVessels = FlightGlobals.fetch.vessels;

            for (int i = 0; i < allVessels.Count; i++)
            {
                if (allVessels[i].connection != null && Lib.IsVessel(allVessels[i]))
                {
                    Lib.Debug("Caching CommNetVessel '{0}'", allVessels[i].vesselName);
                    Cache.CommNodeInfo(allVessels[i]);
                }
            }
            Cache.refreshCommNode = false;
        }
Пример #16
0
        public static Antenna_Info AntennaInfo(Vessel v)
        {
            // get vessel id
            UInt32 id = Lib.VesselID(v);

            // get the info from the cache, if it exist update
            if (antennasCache.TryGetValue(id, out Antenna_Info info))
            {
                // isTimeToUpdate is altered when Vessel was changed(stage, break), antenna has extended/retracted
                if (!info.isTimeToUpdate)
                {
                    return(info);
                }
            }
            else // Create a new entry
            {
                Lib.Debug("New antenna cache");
                info = new Antenna_Info(v);
                antennasCache.Add(id, info);
            }
            return(info);
        }
Пример #17
0
        public Transformator(Part p, string transf_name, float SpinRate, float spinAccel)
        {
            transf = null;
            name   = string.Empty;
            part   = p;

            if (transf_name.Length > 0)
            {
                Lib.Debug("Looking for : {0}", transf_name);
                Transform[] transfArray = p.FindModelTransforms(transf_name);
                if (transfArray.Length > 0)
                {
                    Lib.Debug("Transform has been found");
                    name = transf_name;

                    transf         = transfArray[0];
                    this.SpinRate  = SpinRate;
                    this.spinAccel = spinAccel;
                    baseAngles     = transf.localRotation;
                }
            }
        }
Пример #18
0
        public static void CommNodeInfo(Vessel v)
        {
            // get vessel id
            UInt32 id = Lib.VesselID(v);

            // get the info from the cache, if it exist update
            if (commVessels.TryGetValue(id, out KCommNetVessel info))
            {
                // needs to be refresh
                if (refreshCommNode)
                {
                    // Update old cache
                    Lib.Debug("Triggered: Update existing CommNode cache");

                    commVessels[id] = (KCommNetVessel)v.connection;
                }
            }
            else // Create a new entry
            {
                Lib.Debug("New CommNode has been cached");
                info = (KCommNetVessel)v.connection;
                commVessels.Add(id, info);
            }
        }
 private void OnAntennaDeployment(float data)
 {
     Lib.Debug("Antenna in active CommNet Vessel '{0}' is extended/retracted. Rebuilding the freq list ...", vessel.vesselName);
     // update antenna cache
     Cache.AntennaInfo(vessel).isTimeToUpdate = true;
 }
Пример #20
0
 public override void GUI_Update(bool hasEnergy)
 {
     Lib.Debug("Buttons is '{0}' for '{1}' landingGear", (hasEnergy == true ? "ON" : "OFF"), landingGear.part.partInfo.title);
     landingGear.Events["EventToggle"].active = hasEnergy;
 }
        //Edit the connectivity between two potential nodes
        protected override bool SetNodeConnection(CommNode a, CommNode b)
        {
            //stop links between ground stations
            if (a.isHome && b.isHome)
            {
                Disconnect(a, b, true);
                return(false);
            }

            List <short> aFreqs, bFreqs;

            //each CommNode has at least some frequencies?
            try
            {
                aFreqs = Cache.GetFrequencies(a);
                bFreqs = Cache.GetFrequencies(b);
            }
            catch (NullReferenceException e) // either CommNode could be a kerbal on EVA
            {
                Lib.Debug("Connection issue between '{0}' and '{1}'", a.name, b.name);
                Disconnect(a, b, true);
                return(false);
            }

            //share same frequency?
            for (int i = 0; i < aFreqs.Count; i++)
            {
                if (bFreqs.Contains(aFreqs[i]))
                {
                    AntennasByFrequency a_Antennas = Cache.GetNodeAntennaCache(a, aFreqs[i]);
                    AntennasByFrequency b_Antennas = Cache.GetNodeAntennaCache(b, aFreqs[i]);

                    if (a_Antennas.antennaPower + a_Antennas.relayPower == 0.0 || b_Antennas.antennaPower + b_Antennas.relayPower == 0.0)
                    {
                        Disconnect(a, b, true);
                        return(false);
                    }
                    Vector3d precisePosition1 = a.precisePosition;
                    Vector3d precisePosition2 = b.precisePosition;

                    double num      = (precisePosition2 - precisePosition1).sqrMagnitude;
                    double distance = a.distanceOffset + b.distanceOffset;
                    if (distance != 0.0)
                    {
                        distance = Math.Sqrt(num) + distance;
                        num      = distance <= 0.0 ? (distance = 0.0) : distance * distance;
                    }
                    bool bothRelay = CommNetScenario.RangeModel.InRange(a_Antennas.relayPower, b_Antennas.relayPower, num);
                    bool aCanRelay = bothRelay;
                    bool bCanRelay = bothRelay;
                    if (!bothRelay)
                    {
                        aCanRelay = CommNetScenario.RangeModel.InRange(a_Antennas.relayPower, b_Antennas.antennaPower, num);
                        bCanRelay = CommNetScenario.RangeModel.InRange(a_Antennas.antennaPower, b_Antennas.relayPower, num);
                    }
                    if (!aCanRelay && !bCanRelay)
                    {
                        Disconnect(a, b, true);
                        return(false);
                    }
                    if (num == 0.0 && (bothRelay || aCanRelay || bCanRelay))
                    {
                        return(TryConnectFreq(a, b, 1E-07, aCanRelay, bCanRelay, bothRelay, aFreqs[i]));
                    }
                    if (distance == 0.0)
                    {
                        distance = Math.Sqrt(num);
                    }
                    if (TestOcclusion(precisePosition1, a.occluder, precisePosition2, b.occluder, distance))
                    {
                        return(TryConnectFreq(a, b, distance, aCanRelay, bCanRelay, bothRelay, aFreqs[i]));
                    }

                    Disconnect(a, b, true);
                    return(false);
                }
            }

            Disconnect(a, b, true);
            return(false);
        }
Пример #22
0
 public static void InitCommVessels()
 {
     Lib.Debug("CommVessel cache has been initialized");
     commVessels = new Dictionary <uint, KCommNetVessel>();
 }
Пример #23
0
        // constructor
        /// <summary> Creates a <see cref="ConnectionInfo"/> object for the specified vessel from it's antenna modules</summary>
        public ConnectionInfo(Vessel v, bool powered, bool storm)
        {
            // set RemoteTech powered and storm state
            if (RemoteTech.Enabled)
            {
                RemoteTech.SetPoweredDown(v.id, !powered);
                RemoteTech.SetCommsBlackout(v.id, storm);
            }

            // return no connection if there is no ec left
            if (!powered)
            {
                // hysteresis delay
                if ((DB.Vessel(v).hyspos_signal >= 5.0))
                {
                    DB.Vessel(v).hyspos_signal = 5.0;
                    DB.Vessel(v).hysneg_signal = 0.0;
                    return;
                }
                DB.Vessel(v).hyspos_signal += 0.1;
            }
            else
            {
                // hysteresis delay
                DB.Vessel(v).hysneg_signal += 0.1;
                if (!(DB.Vessel(v).hysneg_signal >= 5.0))
                {
                    return;
                }
                DB.Vessel(v).hysneg_signal = 5.0;
                DB.Vessel(v).hyspos_signal = 0.0;
            }

            rate          = 0.0;
            internal_cost = 0.0;
            external_cost = 0.0;

            // CommNet or simple signal system
            if (!RemoteTech.Enabled)
            {
                List <ModuleDataTransmitter> transmitters;

                // if vessel is loaded
                if (v.loaded)
                {
                    // find transmitters
                    transmitters = v.FindPartModulesImplementing <ModuleDataTransmitter>();

                    if (transmitters != null)
                    {
                        foreach (ModuleDataTransmitter t in transmitters)
                        {
                            if (t.antennaType == AntennaType.INTERNAL)                             // do not include internal data rate, ec cost only
                            {
                                internal_cost += t.DataResourceCost * t.DataRate;
                            }
                            else
                            {
                                // do we have an animation
                                ModuleDeployableAntenna animation        = t.part.FindModuleImplementing <ModuleDeployableAntenna>();
                                ModuleAnimateGeneric    animationGeneric = t.part.FindModuleImplementing <ModuleAnimateGeneric>();
                                if (animation != null)
                                {
                                    // only include data rate and ec cost if transmitter is extended
                                    if (animation.deployState == ModuleDeployablePart.DeployState.EXTENDED)
                                    {
                                        rate          += t.DataRate;
                                        external_cost += t.DataResourceCost * t.DataRate;
                                    }
                                }
                                else if (animationGeneric != null)
                                {
                                    // only include data rate and ec cost if transmitter is extended
                                    if (animationGeneric.animSpeed > 0)
                                    {
                                        rate          += t.DataRate;
                                        external_cost += t.DataResourceCost * t.DataRate;
                                    }
                                }
                                // no animation
                                else
                                {
                                    rate          += t.DataRate;
                                    external_cost += t.DataResourceCost * t.DataRate;
                                }
                            }
                        }
                    }
                }

                // if vessel is not loaded
                else
                {
                    // find proto transmitters
                    foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)
                    {
                        // get part prefab (required for module properties)
                        Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab;

                        transmitters = part_prefab.FindModulesImplementing <ModuleDataTransmitter>();

                        if (transmitters != null)
                        {
                            foreach (ModuleDataTransmitter t in transmitters)
                            {
                                if (t.antennaType == AntennaType.INTERNAL)                                 // do not include internal data rate, ec cost only
                                {
                                    internal_cost += t.DataResourceCost * t.DataRate;
                                }
                                else
                                {
                                    // do we have an animation
                                    ProtoPartModuleSnapshot m = p.FindModule("ModuleDeployableAntenna") ?? p.FindModule("ModuleAnimateGeneric");
                                    if (m != null)
                                    {
                                        // only include data rate and ec cost if transmitter is extended
                                        string deployState = Lib.Proto.GetString(m, "deployState");
                                        float  animSpeed   = Lib.Proto.GetFloat(m, "animSpeed");
                                        if (deployState == "EXTENDED" || animSpeed > 0)
                                        {
                                            rate          += t.DataRate;
                                            external_cost += t.DataResourceCost * t.DataRate;
                                        }
                                    }
                                    // no animation
                                    else
                                    {
                                        rate          += t.DataRate;
                                        external_cost += t.DataResourceCost * t.DataRate;
                                    }
                                }
                            }
                        }
                    }
                }

                // if CommNet is enabled
                if (HighLogic.fetch.currentGame.Parameters.Difficulty.EnableCommNet)
                {
                    if (v.connection != null)
                    {
                        // force CommNet update of unloaded vessels
                        if (!v.loaded)
                        {
                            Lib.ReflectionValue(v.connection, "unloadedDoOnce", true);
                        }

                        // are we connected to DSN or control station(can be another vessel with 3 or more crew in CommNet)
                        if (v.connection.IsConnected)
                        {
                            linked   = true;
                            status   = v.connection.ControlPath.First.hopType == HopType.Home ? LinkStatus.direct_link : LinkStatus.indirect_link;
                            strength = v.connection.SignalStrength;

                            if (status != LinkStatus.direct_link)
                            {
                                Vessel firstHop = Lib.CommNodeToVessel(v.Connection.ControlPath.First.end);
                                // Get rate from the firstHop, each Hop will do the same logic, then we will have the min rate for whole path
                                rate = Math.Min(Cache.VesselInfo(FlightGlobals.FindVessel(firstHop.id)).connection.rate, rate);
                            }

                            rate       *= strength * PreferencesBasic.Instance.transmitFactor;
                            target_name = Lib.Ellipsis(Localizer.Format(v.connection.ControlPath.First.end.displayName).Replace("Kerbin", "DSN"), 20);
                        }

                        // is loss of connection due to plasma blackout
                        else if (Lib.ReflectionValue <bool>(v.connection, "inPlasma"))                         // calling InPlasma causes a StackOverflow :(
                        {
                            status        = LinkStatus.plasma;
                            rate          = 0.0;
                            internal_cost = 0.0;
                            external_cost = 0.0;
                        }
                    }
                    // no connection
                    else
                    {
                        rate          = 0.0;
                        internal_cost = 0.0;
                        external_cost = 0.0;
                    }
                    return;
                }
                // the simple stupid always connected signal system
                linked      = true;
                status      = LinkStatus.direct_link;
                strength    = 1;                 // 100 %
                target_name = "DSN: KSC";
                return;
            }

            // RemoteTech signal system
            else
            {
                // if vessel is loaded
                if (v.loaded)
                {
                    // find transmitters
                    foreach (Part p in v.parts)
                    {
                        foreach (PartModule m in p.Modules)
                        {
                            // calculate internal (passive) transmitter ec usage @ 0.5W each
                            if (m.moduleName == "ModuleRTAntennaPassive")
                            {
                                internal_cost += 0.0005;
                            }

                            // calculate external transmitters
                            else if (m.moduleName == "ModuleRTAntenna")
                            {
                                // only include ec cost if transmitter is active
                                if (Lib.ReflectionValue <bool>(m, "IsRTActive"))
                                {
                                    rate          += Lib.ReflectionValue <float>(m, "RTPacketSize") / Lib.ReflectionValue <float>(m, "RTPacketInterval");
                                    external_cost += m.resHandler.inputResources.Find(r => r.name == "ElectricCharge").rate;
                                }
                            }
                        }
                    }
                }

                // if vessel is not loaded
                else
                {
                    // find proto transmitters
                    foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)
                    {
                        // get part prefab (required for module properties)
                        Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab;
                        int  index       = 0;                       // module index

                        foreach (ProtoPartModuleSnapshot m in p.modules)
                        {
                            // calculate internal (passive) transmitter ec usage @ 0.5W each
                            if (m.moduleName == "ModuleRTAntennaPassive")
                            {
                                internal_cost += 0.0005;
                            }

                            // calculate external transmitters
                            else if (m.moduleName == "ModuleRTAntenna")
                            {
                                // only include data rate and ec cost if transmitter is active skip if index is out of range
                                if (Lib.Proto.GetBool(m, "IsRTActive") && index < part_prefab.Modules.Count)
                                {
                                    // get module prefab
                                    PartModule pm = part_prefab.Modules.GetModule(index);

                                    if (pm != null)
                                    {
                                        external_cost += pm.resHandler.inputResources.Find(r => r.name == "ElectricCharge").rate;
                                        // only include data rate if vessel is connected
                                        float?packet_size = Lib.SafeReflectionValue <float>(pm, "RTPacketSize");
                                        // workaround for old savegames
                                        if (packet_size == null)
                                        {
                                            Lib.Debug("Old SaveGame PartModule ModuleRTAntenna for part {0} on unloaded vessel {1}, using default values as a workaround", p.partName, v.vesselName);
                                            rate += 6.6666;                                              // 6.67 Mb/s
                                        }
                                        else
                                        {
                                            rate += (float)packet_size / Lib.ReflectionValue <float>(pm, "RTPacketInterval");
                                        }
                                    }
                                    else
                                    {
                                        Lib.Debug("Could not find PartModule ModuleRTAntenna for part {0} on unloaded vessel {1}, using default values as a workaround", p.partName, v.vesselName);
                                        rate          += 6.6666;                                         // 6.67 Mb/s in 100% factor
                                        external_cost += 0.025;                                          // 25 W/s
                                    }
                                }
                            }
                            index++;
                        }
                    }
                }

                // are we connected
                if (RemoteTech.Connected(v.id))
                {
                    linked      = RemoteTech.ConnectedToKSC(v.id);
                    status      = RemoteTech.TargetsKSC(v.id) ? LinkStatus.direct_link : LinkStatus.indirect_link;
                    strength    = RemoteTech.GetSignalDelay(v.id);
                    target_name = status == LinkStatus.direct_link ? Lib.Ellipsis("DSN: " + (RemoteTech.NameTargetsKSC(v.id) ?? ""), 20) :
                                  Lib.Ellipsis(RemoteTech.NameFirstHopToKSC(v.id) ?? "", 20);

                    if (linked)
                    {
                        controlPath = RemoteTech.GetCommsControlPath(v.id);
                    }

                    // Get the smaller rate of the path
                    if (controlPath != null)
                    {
                        // Get rate from the firstHop, each Hop will do the same logic, then we will have the min rate for whole path
                        if (controlPath.Length > 0)
                        {
                            rate = Math.Min(Cache.VesselInfo(FlightGlobals.FindVessel(controlPath[0])).connection.rate, rate);
                        }
                    }
                    rate *= PreferencesBasic.Instance.transmitFactor;
                }
                // is loss of connection due to a blackout
                else if (RemoteTech.GetCommsBlackout(v.id))
                {
                    status        = storm ? LinkStatus.storm : LinkStatus.plasma;
                    rate          = 0.0;
                    internal_cost = 0.0;
                    external_cost = 0.0;
                }
                else
                {
                    // no connection
                    rate          = 0.0;
                    internal_cost = 0.0;
                    external_cost = 0.0;
                }
            }
        }
Пример #24
0
        public override void FixModule(bool hasEnergy)
        {
            double right;

            if (Features.Signal)
            {
                if (animator != null)
                {
                    if (animator.isDeployed || (Settings.ExtendedAntenna == false))
                    {
                        antenna.extended = hasEnergy;
                    }
                    else
                    {
                        antenna.extended = false;
                    }
                }
                else
                {
                    // this means that antenna is fixed
                    antenna.extended = hasEnergy;
                }
                if (animator != null)
                {
                    ToggleActions(animator, hasEnergy);
                }
            }
            else if (Features.KCommNet)
            {
                // Save antennaPower
                antennaPower = (antennaPower != transmitter.antennaPower && transmitter.antennaPower > 0 ? transmitter.antennaPower : antennaPower);
                right        = hasEnergy ? antennaPower : 0;
                if (stockAnim != null)
                {
                    ToggleActions(stockAnim, hasEnergy);
                    if (stockAnim.deployState == ModuleDeployablePart.DeployState.EXTENDED)
                    {
                        // Recover antennaPower only if antenna is Extended
                        Lib.Debug("Setting antenna '{0}' power: {1}", transmitter.part.partInfo.title, right);
                        transmitter.antennaPower = right;
                    }
                    else
                    {
                        if (Settings.ExtendedAntenna)
                        {
                            Lib.Debug("Setting antenna '{0}' power: {1}", transmitter.part.partInfo.title, right);
                            transmitter.antennaPower = right;
                        }
                        else
                        {
                            Lib.Debug("Setting antenna '{0}' power: {1}", transmitter.part.partInfo.title, 0);
                            transmitter.antennaPower = 0;
                        }
                    }
                }
                else
                {
                    // Recover antennaPower for fixed antenna
                    Lib.Debug("Setting antenna '{0}' power: {1}", transmitter.part.partInfo.title, right);
                    transmitter.antennaPower = right;
                }
            }
        }
Пример #25
0
        public override void GUI_Update(bool hasEnergy)
        {
            if (Features.Signal)
            {
                if (hasEnergy)
                {
                    if (animator != null)
                    {
                        Lib.Debug("Activing buttons for '{0}' antenna", antenna.part.partInfo.title);
                        if (animator.DeployAnimation.isPlaying)
                        {
                            animator.Events["RetractModule"].active = false;
                            animator.Events["DeployModule"].active  = false;
                        }
                        if (animator.isDeployed)
                        {
                            animator.Events["RetractModule"].active = true;
                            animator.Events["DeployModule"].active  = false;
                        }
                        else
                        {
                            animator.Events["RetractModule"].active = false;
                            animator.Events["DeployModule"].active  = true;
                        }
                    }
                }
                else
                {
                    if (animator != null)
                    {
                        Lib.Debug("Desactiving buttons for '{0}' antenna", antenna.part.partInfo.title);
                        // Don't allow extending/retracting when has no ec

                        string ev = "";
                        foreach (var e in animator.Events)
                        {
                            ev += ("'" + e.name + "',");
                        }
                        ev = ev.Substring(0, ev.Length - 1);
                        Lib.Debug("Available events:" + ev);
                        animator.Events["RetractModule"].active = false;
                        animator.Events["DeployModule"].active  = false;
                    }
                }
            }
            else if (Features.KCommNet)
            {
                if (hasEnergy)
                {
                    if (stockAnim != null)
                    {
                        Lib.Debug("Activing buttons for '{0}' antenna", transmitter.part.partInfo.title);
                        if (stockAnim.deployState == ModuleDeployablePart.DeployState.EXTENDED)
                        {
                            stockAnim.Events["Retract"].active = true;
                            stockAnim.Events["Extend"].active  = false;
                        }
                        else if (stockAnim.deployState == ModuleDeployablePart.DeployState.RETRACTED)
                        {
                            stockAnim.Events["Retract"].active = false;
                            stockAnim.Events["Extend"].active  = true;
                        }
                        else
                        {
                            stockAnim.Events["Retract"].active = false;
                            stockAnim.Events["Extend"].active  = false;
                        }
                    }
                    else if (customAnim != null)
                    {
                        // Do not add log here, this interface has constantly update
                        if (customAnim.aniState == ModuleAnimateGeneric.animationStates.MOVING)
                        {
                            customAnim.Events["RetractModule"].active = false;
                            customAnim.Events["DeployModule"].active  = false;
                        }
                        else if (customAnim.animSpeed > 0 || (Settings.ExtendedAntenna == false))
                        {
                            customAnim.Events["RetractModule"].active = true;
                            customAnim.Events["DeployModule"].active  = false;
                        }
                        else
                        {
                            customAnim.Events["RetractModule"].active = false;
                            customAnim.Events["DeployModule"].active  = true;
                        }
                    }
                }
                else
                {
                    if (stockAnim != null)
                    {
                        Lib.Debug("Desactiving buttons for '{0}' antenna", transmitter.part.partInfo.title);
                        // Don't allow extending/retracting when has no ec
                        stockAnim.Events["Retract"].active = false;
                        stockAnim.Events["Extend"].active  = false;
                    }
                    else if (customAnim != null)
                    {
                        // Do not add log here, this interface has constantly update
                        // Don't allow extending/retracting when has no ec
                        customAnim.Events["Toggle"].active = false;
                    }
                }
            }
        }