Example #1
0
 public void OnEditorAttach()
 {
     foreach (AttachNode attach_node in part.attachNodes)
     {
         if (attach_node.attachedPart != null)
         {
             List <FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing <FNThermalSource>();
             if (sources.Count > 0)
             {
                 myAttachedReactor = sources.First();
                 if (myAttachedReactor != null)
                 {
                     if (myAttachedReactor is FNFusionReactor && isupgraded)
                     {
                         // if we're attaching to a fusion reactor, swap over to direct conversion if we can
                         generatorType       = altUpgradedName;
                         chargedParticleMode = true;
                     }
                     else if (myAttachedReactor is FNAmatCatFissionFusionReactor && isupgraded)
                     {
                         // if we're attaching to a antimatter initiated reactor, swap over to direct conversion if we can
                         generatorType       = altUpgradedName;
                         chargedParticleMode = true;
                     }
                     else     // otherwise use a standard thermal generator
                     {
                         generatorType       = upgradedName;
                         chargedParticleMode = false;
                     }
                     break;
                 }
             }
         }
     }
 }
        public override void OnStart(PartModule.StartState state)
        {
            engineType = originalName;
            // check whether we have the technologies available to be able to perform an upgrade
            if (state == StartState.Editor)
            {
                if (hasTechsRequiredToUpgrade())
                {
                    isupgraded = true;
                    upgradePartModule();
                }
                return;
            }
            fuel_gauge       = part.stackIcon.DisplayInfo();
            myAttachedEngine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;
            // if engine isn't already initialised, initialise it
            if (engineInit == false)
            {
                engineInit = true;
            }
            // if we can upgrade, let's do so
            if (isupgraded && isJet)
            {
                upgradePartModule();
            }
            else
            {
                propellants = getPropellants(isJet);
            }
            // find attached thermal source
            foreach (AttachNode attach_node in part.attachNodes)
            {
                if (attach_node.attachedPart != null)
                {
                    List <FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing <FNThermalSource> ();
                    if (sources.Count > 0)
                    {
                        myAttachedReactor = sources.First();
                        if (myAttachedReactor != null)
                        {
                            break;
                        }
                    }
                }
            }

            setupPropellants();
            hasstarted = true;

            //print ("Start Complete");
        }
 public void OnEditorAttach()
 {
     foreach (AttachNode attach_node in part.attachNodes)
     {
         if (attach_node.attachedPart != null)
         {
             List <FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing <FNThermalSource>();
             if (sources.Count > 0)
             {
                 myAttachedReactor = sources.First();
                 if (myAttachedReactor != null)
                 {
                     break;
                 }
             }
         }
     }
     estimateEditorPerformance();
 }
		public override void OnStart(PartModule.StartState state) {
            engineType = originalName;
            myAttachedEngine = this.part.Modules["ModuleEngines"] as ModuleEngines;
            // find attached thermal source
            foreach (AttachNode attach_node in part.attachNodes) {
                if (attach_node.attachedPart != null) {
                    List<FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing<FNThermalSource>();
                    if (sources.Count > 0) {
                        myAttachedReactor = sources.First();
                        if (myAttachedReactor != null) {
                            break;
                        }
                    }
                }
            }

            if (state == StartState.Editor) {
                part.OnEditorAttach += OnEditorAttach;
                propellants = getPropellants(isJet);
                if (hasTechsRequiredToUpgrade() && isJet) {
                    isupgraded = true;
                    upgradePartModule();
                }
                setupPropellants();
                estimateEditorPerformance();
                return;
            }
			fuel_gauge = part.stackIcon.DisplayInfo();
			
            // if engine isn't already initialised, initialise it
			if (engineInit == false) {
				engineInit = true;
			}
			// if we can upgrade, let's do so
			if (isupgraded && isJet) {
				upgradePartModule ();
			} else {
                if (hasTechsRequiredToUpgrade() && isJet) {
                    hasrequiredupgrade = true;
                }
				// if not, use basic propellants
				propellants = getPropellants (isJet);
			}
			
			setupPropellants();
			hasstarted = true;

			//print ("Start Complete");
		}
 public void OnEditorAttach() {
     foreach (AttachNode attach_node in part.attachNodes) {
         if (attach_node.attachedPart != null) {
             List<FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing<FNThermalSource>();
             if (sources.Count > 0) {
                 myAttachedReactor = sources.First();
                 if (myAttachedReactor != null) {
                     break;
                 }
             }
         }
     }
     estimateEditorPerformance();
 }
		public override void OnStart(PartModule.StartState state) {
			String[] resources_to_supply = {FNResourceManager.FNRESOURCE_MEGAJOULES,FNResourceManager.FNRESOURCE_WASTEHEAT};
			this.resources_to_supply = resources_to_supply;
			base.OnStart (state);
            generatorType = originalName;
            if (state == StartState.Editor) {
                if (hasTechsRequiredToUpgrade()) {
                    isupgraded = true;
                    hasrequiredupgrade = true;
                    upgradePartModule();
                }
                part.OnEditorAttach += OnEditorAttach;
                return;
            }

            if (hasTechsRequiredToUpgrade()) {
                hasrequiredupgrade = true;
            }

			this.part.force_activate();
			

			anim = part.FindModelAnimators (animName).FirstOrDefault ();
			if (anim != null) {
				anim [animName].layer = 1;
				if (!IsEnabled) {
					anim [animName].normalizedTime = 1f;
					anim [animName].speed = -1f;

				} else {
					anim [animName].normalizedTime = 0f;
					anim [animName].speed = 1f;

				}
				anim.Play ();
			}

			if (generatorInit == false) {
				generatorInit = true;
				IsEnabled = true;
			}

			if (isupgraded) {
				upgradePartModule ();
			}

			foreach (AttachNode attach_node in part.attachNodes) {
				if(attach_node.attachedPart != null) {
					List<FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing<FNThermalSource> ();
					if (sources.Count > 0) {
						myAttachedReactor = sources.First ();
						if (myAttachedReactor != null) {
							break;
						}
					}
				}
			}

			print("[KSP Interstellar] Configuring Generator");
		}
 public void OnEditorAttach() {
     foreach (AttachNode attach_node in part.attachNodes) {
         if (attach_node.attachedPart != null) {
             List<FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing<FNThermalSource>();
             if (sources.Count > 0) {
                 myAttachedReactor = sources.First();
                 if (myAttachedReactor != null) {
                     if (myAttachedReactor is FNFusionReactor && isupgraded) {
                         // if we're attaching to a fusion reactor, swap over to direct conversion if we can
                         generatorType = altUpgradedName;
                         chargedParticleMode = true;
                     } else if (myAttachedReactor is FNAmatCatFissionFusionReactor && isupgraded) {
                         // if we're attaching to a antimatter initiated reactor, swap over to direct conversion if we can
                         generatorType = altUpgradedName;
                         chargedParticleMode = true;
                     } else { // otherwise use a standard thermal generator
                         generatorType = upgradedName;
                         chargedParticleMode = false;
                     }
                     break;
                 }
             }
         }
     }
 }
		public override void OnStart(PartModule.StartState state) {
            engineType = originalName;
            // check whether we have the technologies available to be able to perform an upgrade
            if (state == StartState.Editor) {
                if (hasTechsRequiredToUpgrade()) {
                    isupgraded = true;
                    upgradePartModule();
                }
                return;
            }
			fuel_gauge = part.stackIcon.DisplayInfo();
			myAttachedEngine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;
			// if engine isn't already initialised, initialise it
			if (engineInit == false) {
				engineInit = true;
			}
			// if we can upgrade, let's do so
			if (isupgraded && isJet) {
				upgradePartModule ();
			} else {
				propellants = getPropellants (isJet);
			}
			// find attached thermal source
			foreach (AttachNode attach_node in part.attachNodes) {
				if (attach_node.attachedPart != null) {
					List<FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing<FNThermalSource> ();
					if (sources.Count > 0) {
						myAttachedReactor = sources.First ();
						if (myAttachedReactor != null) {
							break;
						}
					}
				}
			}

			setupPropellants();
			hasstarted = true;

			//print ("Start Complete");
		}
        public override void OnStart(PartModule.StartState state)
        {
            engineType       = originalName;
            myAttachedEngine = this.part.Modules["ModuleEngines"] as ModuleEngines;
            // find attached thermal source
            foreach (AttachNode attach_node in part.attachNodes)
            {
                if (attach_node.attachedPart != null)
                {
                    List <FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing <FNThermalSource>();
                    if (sources.Count > 0)
                    {
                        myAttachedReactor = sources.First();
                        if (myAttachedReactor != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (state == StartState.Editor)
            {
                part.OnEditorAttach += OnEditorAttach;
                propellants          = getPropellants(isJet);
                if (hasTechsRequiredToUpgrade() && isJet)
                {
                    isupgraded = true;
                    upgradePartModule();
                }
                setupPropellants();
                estimateEditorPerformance();
                return;
            }
            fuel_gauge = part.stackIcon.DisplayInfo();

            // if engine isn't already initialised, initialise it
            if (engineInit == false)
            {
                engineInit = true;
            }
            // if we can upgrade, let's do so
            if (isupgraded && isJet)
            {
                upgradePartModule();
            }
            else
            {
                if (hasTechsRequiredToUpgrade() && isJet)
                {
                    hasrequiredupgrade = true;
                }
                // if not, use basic propellants
                propellants = getPropellants(isJet);
            }

            setupPropellants();
            hasstarted = true;

            //print ("Start Complete");
        }
        public override void OnFixedUpdate()
        {
            activeCount++;
            nuclear_power         = 0;
            solar_power           = 0;
            displayed_solar_power = 0;
            if (IsEnabled && !relay)
            {
                double powerDraw = 0.0;

                try
                {
                    ORSResourceManager manager = getOvermanagerForResource(FNResourceManager.FNRESOURCE_MEGAJOULES).getManagerForVessel(vessel);
                    if (manager != null)
                    {
                        powerDraw = manager.PowerDraws.Where(pm => !(pm.Key is MicrowavePowerTransmitter && (pm.Key as MicrowavePowerTransmitter) == this)).Sum(pm => pm.Value);
                    }
                }
                catch (ArgumentNullException)
                {
                    powerDraw = 0.0;
                }

                foreach (FNGenerator generator in generators)
                {
                    if (generator.isActive())
                    {
                        FNThermalSource thermal_source = generator.getThermalSource();
                        if (thermal_source != null && !thermal_source.isVolatileSource() && thermal_source.isActive())
                        {
                            double output = generator.getMaxPowerOutput();
                            output -= powerDraw / (double)generators.Count(g => g.isActive() && g.getThermalSource().isActive());
                            output  = output * transmitPower / 100.0;
                            double gpower = consumeFNResource(output * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
                            nuclear_power += gpower * 1000 / TimeWarp.fixedDeltaTime;
                        }
                    }
                }

                foreach (ModuleDeployableSolarPanel panel in panels)
                {
                    double output          = panel.flowRate;
                    double spower          = part.RequestResource("ElectricCharge", output * TimeWarp.fixedDeltaTime);
                    double inv_square_mult = Math.Pow(Vector3d.Distance(FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2) / Math.Pow(Vector3d.Distance(vessel.transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2);
                    displayed_solar_power += spower / TimeWarp.fixedDeltaTime;
                    //scale solar power to what it would be in Kerbin orbit for file storage
                    solar_power += spower / TimeWarp.fixedDeltaTime / inv_square_mult;
                }
            }

            if (double.IsInfinity(nuclear_power) || double.IsNaN(nuclear_power))
            {
                nuclear_power = 0;
            }

            if (double.IsInfinity(solar_power) || double.IsNaN(solar_power))
            {
                solar_power = 0;
            }

            if (activeCount % 1000 == 9)
            {
                ConfigNode config   = PluginHelper.getPluginSaveFile();
                string     vesselID = vessel.id.ToString();
                if (config.HasNode("VESSEL_MICROWAVE_POWER_" + vesselID))
                {
                    ConfigNode power_node = config.GetNode("VESSEL_MICROWAVE_POWER_" + vesselID);
                    if (power_node.HasValue("nuclear_power"))
                    {
                        power_node.SetValue("nuclear_power", MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel).ToString("E"));
                    }
                    else
                    {
                        power_node.AddValue("nuclear_power", MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel).ToString("E"));
                    }
                    if (power_node.HasValue("solar_power"))
                    {
                        power_node.SetValue("solar_power", MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel).ToString("E"));
                    }
                    else
                    {
                        power_node.AddValue("solar_power", MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel).ToString("E"));
                    }
                }
                else
                {
                    ConfigNode power_node = config.AddNode("VESSEL_MICROWAVE_POWER_" + vesselID);
                    power_node.AddValue("nuclear_power", MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel).ToString("E"));
                    power_node.AddValue("solar_power", MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel).ToString("E"));
                }

                if (config.HasNode("VESSEL_MICROWAVE_RELAY_" + vesselID))
                {
                    ConfigNode relay_node = config.GetNode("VESSEL_MICROWAVE_RELAY_" + vesselID);
                    if (relay_node.HasValue("relay"))
                    {
                        relay_node.SetValue("relay", MicrowavePowerTransmitter.vesselIsRelay(vessel).ToString());
                    }
                    else
                    {
                        relay_node.AddValue("relay", MicrowavePowerTransmitter.vesselIsRelay(vessel).ToString());
                    }
                }
                else
                {
                    ConfigNode relay_node = config.AddNode("VESSEL_MICROWAVE_RELAY_" + vesselID);
                    relay_node.AddValue("relay", MicrowavePowerTransmitter.vesselIsRelay(vessel).ToString());
                }

                config.Save(PluginHelper.getPluginSaveFilePath());
            }
            activeCount++;
        }
Example #11
0
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_MEGAJOULES, FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);
            generatorType = originalName;
            if (state == StartState.Editor)
            {
                if (hasTechsRequiredToUpgrade())
                {
                    isupgraded         = true;
                    hasrequiredupgrade = true;
                    upgradePartModule();
                }
                part.OnEditorAttach += OnEditorAttach;
                return;
            }

            if (hasTechsRequiredToUpgrade())
            {
                hasrequiredupgrade = true;
            }

            this.part.force_activate();


            anim = part.FindModelAnimators(animName).FirstOrDefault();
            if (anim != null)
            {
                anim [animName].layer = 1;
                if (!IsEnabled)
                {
                    anim [animName].normalizedTime = 1f;
                    anim [animName].speed          = -1f;
                }
                else
                {
                    anim [animName].normalizedTime = 0f;
                    anim [animName].speed          = 1f;
                }
                anim.Play();
            }

            if (generatorInit == false)
            {
                generatorInit = true;
                IsEnabled     = true;
            }

            if (isupgraded)
            {
                upgradePartModule();
            }

            foreach (AttachNode attach_node in part.attachNodes)
            {
                if (attach_node.attachedPart != null)
                {
                    List <FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing <FNThermalSource> ();
                    if (sources.Count > 0)
                    {
                        myAttachedReactor = sources.First();
                        if (myAttachedReactor != null)
                        {
                            break;
                        }
                    }
                }
            }

            print("[KSP Interstellar] Configuring Generator");
        }