Exemple #1
0
        /// <summary>
        /// Finds the nearest avialable thermalsource and update effective part mass
        /// </summary>
        public void FindAndAttachToPowerSource()
        {
            partDistance = 0;

            // disconnect
            if (attachedPowerSource != null)
            {
                if (chargedParticleMode)
                {
                    attachedPowerSource.ConnectedChargedParticleElectricGenerator = null;
                }
                else
                {
                    attachedPowerSource.ConnectedThermalElectricGenerator = null;
                }
            }

            // first look if part contains an thermal source
            attachedPowerSource = part.FindModulesImplementing <IPowerSource>().FirstOrDefault();
            if (attachedPowerSource != null)
            {
                ConnectToPowerSource();
                Debug.Log("[KSPI] - Found power source localy");
                return;
            }

            if (!part.attachNodes.Any() || part.attachNodes.All(m => m.attachedPart == null))
            {
                Debug.Log("[KSPI] - not connected to any parts yet");
                UpdateTargetMass();
                return;
            }

            Debug.Log("[KSPI] - generator is currently connected to " + part.attachNodes.Count + " parts");
            // otherwise look for other non selfcontained thermal sources that is not already connected
            PowerSourceSearchResult searchResult = chargedParticleMode ? FindChargedParticleSource() : FindThermalPowerSource();

            // quit if we failed to find anything
            if (searchResult == null)
            {
                Debug.LogWarning("[KSPI] - Failed to find power source");
                return;
            }

            // verify cost is not higher than 1
            partDistance = (int)Math.Max(Math.Ceiling(searchResult.Cost), 0);
            if (partDistance > 1)
            {
                Debug.LogWarning("[KSPI] - Found power source but at too high cost");
                return;
            }

            // update attached thermalsource
            attachedPowerSource = searchResult.Source;

            Debug.Log("[KSPI] - succesfully connected to " + attachedPowerSource.Part.partInfo.title);

            ConnectToPowerSource();
        }
Exemple #2
0
        private PowerSourceSearchResult FindChargedParticleSource()
        {
            PowerSourceSearchResult searchResult =
                PowerSourceSearchResult.BreadthFirstSearchForThermalSource(part,
                                                                           p => p.IsThermalSource &&
                                                                           p.ConnectedChargedParticleElectricGenerator == null &&
                                                                           p.ChargedParticleEnergyEfficiency > 0, 3, 3, 3, true);

            return(searchResult);
        }
Exemple #3
0
        private PowerSourceSearchResult FindThermalPowerSource()
        {
            var searchResult =
                PowerSourceSearchResult.BreadthFirstSearchForThermalSource(part,
                                                                           p => p.IsThermalSource &&
                                                                           p.ConnectedThermalElectricGenerator == null &&
                                                                           p.ThermalEnergyEfficiency > 0, 3, 3, 3, true);

            return(searchResult);
        }