// Finds a list of all fission containers
        List <FissionContainer> FindFissionContainers()
        {
            List <FissionContainer> fissionContainers = new List <FissionContainer>();
            List <Part>             allParts          = this.vessel.parts;

            foreach (Part pt in allParts)
            {
                PartModuleList pml = pt.Modules;
                for (int i = 0; i < pml.Count; i++)
                {
                    PartModule       curModule = pml.GetModule(i);
                    FissionContainer candidate = curModule.GetComponent <FissionContainer>();

                    if (candidate != null)
                    {
                        fissionContainers.Add(candidate);
                    }
                }
            }
            if (fissionContainers.Count == 0)
            {
                ScreenMessages.PostScreenMessage(new ScreenMessage("No nuclear fuel containers attached to this ship.", 4f, ScreenMessageStyle.UPPER_CENTER));
            }
            return(fissionContainers);
        }
        public void FindCapacitors()
        {
            activeVessel = FlightGlobals.ActiveVessel;
            partCount    = activeVessel.parts.Count;
            //Debug.Log("NFE: Capacitor Manager: Finding Capcitors");
            List <DischargeCapacitor> unsortedCapacitorList = new List <DischargeCapacitor>();
            // Get all parts
            List <Part> allParts = FlightGlobals.ActiveVessel.parts;

            foreach (Part pt in allParts)
            {
                PartModuleList modules = pt.Modules;
                for (int i = 0; i < modules.Count; i++)
                {
                    PartModule curModule = modules.GetModule(i);
                    if (curModule.ClassName == "DischargeCapacitor")
                    {
                        unsortedCapacitorList.Add(curModule.GetComponent <DischargeCapacitor>());
                    }
                }
            }

            //sort
            capacitorList = unsortedCapacitorList.OrderByDescending(x => x.dischargeActual).ToList();
            capacitorList = unsortedCapacitorList;
            // Debug.Log("NFE: Capacitor Manager: Found " + capacitorList.Count() + " capacitors");
        }
Exemple #3
0
        // Finds vVariablePowerEngines on the ship
        private void SetupVariableEngines()
        {
            allVariableEngines = new List <VariablePowerEngine>();

            for (int j = 0; j < this.vessel.parts.Count; j++)
            {
                PartModuleList pml = this.vessel.parts[j].Modules;
                for (int i = 0; i < pml.Count; i++)
                {
                    PartModule          curModule = pml.GetModule(i);
                    VariablePowerEngine candidate = curModule.GetComponent <VariablePowerEngine>();
                    if (candidate != null && candidate != this && !allVariableEngines.Contains(candidate))
                    {
                        allVariableEngines.Add(candidate);
                    }
                }
            }
        }
Exemple #4
0
        public override void OnStart(PartModule.StartState state)
        {
            Actions["ActivateTransmitterAction"].guiName   = Events["ActivateTransmitter"].guiName = String.Format("Activate Transmitter");
            Actions["DeactivateTransmitterAction"].guiName = Events["DeactivateTransmitter"].guiName = String.Format("Deactivate Transmitter");

            if (state == StartState.Editor)
            {
                return;
            }
            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();
            }

            List <Part> vesselparts = vessel.parts;

            for (int i = 0; i < vesselparts.Count; ++i)
            {
                Part           cPart = vesselparts.ElementAt(i);
                PartModuleList pml   = cPart.Modules;
                for (int j = 0; j < pml.Count; ++j)
                {
                    var curSolarPan = pml.GetModule(j) as ModuleDeployableSolarPanel;
                    if (curSolarPan != null)
                    {
                        //curSolarPan.powerCurve = PluginHelper.getSatFloatCurve();
                    }
                }
            }
        }
        private void SetupVariableEngines()
        {
            allVariableEngines = new List <VariableISPEngine>();

            List <Part> allParts = this.vessel.parts;

            foreach (Part pt in allParts)
            {
                PartModuleList pml = pt.Modules;
                for (int i = 0; i < pml.Count; i++)
                {
                    PartModule        curModule = pml.GetModule(i);
                    VariableISPEngine candidate = curModule.GetComponent <VariableISPEngine>();

                    if (candidate != null && candidate != this && !allVariableEngines.Contains(candidate))
                    {
                        allVariableEngines.Add(candidate);
                    }
                }
            }
        }
        // Finds all reactors on ship
        public void FindReactors()
        {
            //Debug.Log("NFT: Reactor UI: Finding reactors");
            reactorList = new List <FissionGenerator>();
            // Get all parts
            List <Part> allParts = FlightGlobals.ActiveVessel.parts;

            foreach (Part pt in allParts)
            {
                PartModuleList modules = pt.Modules;
                for (int i = 0; i < modules.Count; i++)
                {
                    PartModule curModule = modules.GetModule(i);
                    if (curModule.ClassName == "FissionGenerator")
                    {
                        reactorList.Add(curModule.GetComponent <FissionGenerator>());
                    }
                }
            }
            //Debug.Log("NFT: Reactor UI: Found " + reactorList.Count() + " reactors");
        }
 // Gets all attached radiators
 private void SetupRadiators()
 {
     Debug.Log("NFPP: Fission Reactor: begin radiator check....");
     radiators = new List <FissionRadiator>();
     // Get attached radiators
     Part[] children = this.part.FindChildParts <Part>();
     // Debug.Log("NFPP: Reactor has " + children.Length.ToString()+" children");
     foreach (Part pt in children)
     {
         PartModuleList modules = pt.Modules;
         for (int i = 0; i < modules.Count; i++)
         {
             PartModule      curModule = modules.GetModule(i);
             FissionRadiator candidate = curModule.GetComponent <FissionRadiator>();
             if (candidate != null)
             {
                 radiators.Add(candidate);
             }
         }
     }
     Debug.Log("NFPP: Fission Reactor: Completed radiator check");
 }
Exemple #8
0
        public override void OnFixedUpdate()
        {
            activeCount++;


            if (IsEnabled)
            {
                List <Part> vesselparts = vessel.parts;
                float       electrical_current_available = 0;
                for (int i = 0; i < vesselparts.Count; ++i)
                {
                    Part           cPart = vesselparts.ElementAt(i);
                    PartModuleList pml   = cPart.Modules;
                    for (int j = 0; j < pml.Count; ++j)
                    {
                        var curFNGen    = pml.GetModule(j) as FNGenerator;
                        var curMwRec    = pml.GetModule(j) as MicrowavePowerReceiver;
                        var curSolarPan = pml.GetModule(j) as ModuleDeployableSolarPanel;
                        if (curFNGen != null)
                        {
                            float consumeMJ = curFNGen.getMaxPowerOutput() * TimeWarp.fixedDeltaTime;
                            float cvalue    = consumeFNResource(consumeMJ, FNResourceManager.FNRESOURCE_MEGAJOULES);
                            electrical_current_available = cvalue * 1000 / TimeWarp.fixedDeltaTime;
                            nuclear = true;
                        }
                        else if (curMwRec != null && nuclear == false)
                        {
                            //electrical_current_available = curMwRec.powerInput;
                            part.RequestResource("ElectricCharge", electrical_current_available * TimeWarp.fixedDeltaTime);
                            microwave = true;
                        }
                        else if (curSolarPan != null && nuclear == false && microwave == false)
                        {
                            electrical_current_available += curSolarPan.flowRate;
                            part.RequestResource("ElectricCharge", electrical_current_available * TimeWarp.fixedDeltaTime);
                            solar = true;
                        }
                    }
                }
                inputPower = electrical_current_available;
            }
            else
            {
                inputPower = 0;
            }

            if (activeCount % 1000 == 9)
            {
                ConfigNode config  = PluginHelper.getPluginSaveFile();
                string     genType = "undefined";

                //float inputPowerFixedAlt = (float) ((double)inputPower * (Math.Pow(FlightGlobals.Bodies[0].GetAltitude(vessel.transform.position), 2)) / PluginHelper.FIXED_SAT_ALTITUDE / PluginHelper.FIXED_SAT_ALTITUDE);
                float inputPowerFixedAlt = 0;
                if (nuclear == true)
                {
                    inputPowerFixedAlt = inputPower;
                    //print ("warp: nuclear inputPower " + inputPowerFixedAlt);
                    genType = "nuclear";
                }
                else if (microwave == true)
                {
                    inputPowerFixedAlt = inputPower;
                    //print ("warp: relay inputPower " + inputPowerFixedAlt);
                    genType = "relay";
                }
                else if (solar == true)
                {
                    //inputPowerFixedAlt = inputPower / PluginHelper.getSatFloatCurve ().Evaluate ((float)FlightGlobals.Bodies [0].GetAltitude (vessel.transform.position));
                    //print ("warp: solar inputPower " + inputPowerFixedAlt);
                    genType = "solar";
                }

                if (genType != "undefined")
                {
                    string vesselIDSolar = vessel.id.ToString();
                    string outputPower   = inputPowerFixedAlt.ToString("0.000");
                    if (!config.HasValue(vesselIDSolar))
                    {
                        config.AddValue(vesselIDSolar, outputPower);
                    }
                    else
                    {
                        config.SetValue(vesselIDSolar, outputPower);
                    }

                    if (!config.HasValue(vesselIDSolar + "type"))
                    {
                        config.AddValue(vesselIDSolar + "type", genType);
                    }
                    else
                    {
                        config.SetValue(vesselIDSolar + "type", genType);
                    }

                    config.Save(PluginHelper.getPluginSaveFilePath());
                }
            }
        }
        void Start()
        {
            nonThrustMotor = true;
            attNode        = this.part.FindAttachNode(attachNode);
            activated      = false;
#if true
            base.Events["Activate"].active    = false;
            base.Events["Activate"].guiActive = false;

            base.Events["Shutdown"].active    = false;
            base.Events["Shutdown"].guiActive = false;

            base.Fields["independentThrottle"].guiActive       = false;
            base.Fields["independentThrottle"].guiActiveEditor = false;

            base.Fields["independentThrottlePercentage"].guiActive       = false;
            base.Fields["independentThrottlePercentage"].guiActiveEditor = false;

            base.Fields["thrustPercentage"].guiActive       = false;
            base.Fields["thrustPercentage"].guiActiveEditor = false;

            Actions["ToggleThrottle"].active       = false;
            Actions["ToggleThrottle"].activeEditor = false;



            foreach (var e in Events)
            {
                Log.Info("Event: " + e.name + ", guiName = " + e.GUIName);
            }
            foreach (var a in Actions)
            {
                Log.Info("Action: " + a.name + ", guiName: " + a.guiName);
            }
#endif
            if (HighLogic.LoadedSceneIsFlight)
            {
                PartModuleList pml = part.Modules;
                if (pml.Contains <MSSRB_Fuel_Segment>())
                {
                    thisSegment = pml.GetModule <MSSRB_Fuel_Segment>();
                }

                if (attNode != null && attNode.attachedPart != null)
                {
                    pml = attNode.attachedPart.Modules;
                    if (pml != null)
                    {
                        if (pml.Contains <MSSRB_Fuel_Segment>())
                        {
                            attachedSegment = pml.GetModule <MSSRB_Fuel_Segment>();
                        }

                        if (pml.Contains <MSSRB_Endcap>())
                        {
                            attachedEndCap = pml.GetModule <MSSRB_Endcap>();
                        }

                        if (pml.Contains <MSSRB_Engine>())
                        {
                            attachedMotor = pml.GetModule <MSSRB_Engine>();
                        }
                    }
                }
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            if (state != StartState.Editor)
            {
                started = true;
            }
            else
            {
                started = false;
            }
            // Get moduleEngines
            PartModuleList pml = this.part.Modules;

            for (int i = 0; i < pml.Count; i++)
            {
                PartModule curModule = pml.GetModule(i);
                engine = curModule.GetComponent <ModuleEnginesFX>();
            }

            if (engine != null)
            {
                Debug.Log("NFPP: Engine Check Passed");
            }

            foreach (Propellant prop in engine.propellants)
            {
                if (prop.name == FuelName)
                {
                    fuelPropellant = prop;
                }
                if (prop.name == "ElectricCharge")
                {
                    ecPropellant = prop;
                }
            }



            if (UseDirectThrottle)
            {
                ChangeIspAndThrust(engine.requestedThrottle);
            }
            else
            {
                ChangeIspAndThrust(CurThrustSetting / 100f);
            }

            if (state != StartState.Editor)
            {
                SetupVariableEngines();
            }


            CalculateCurves();

            Debug.Log("NFPP: Variable ISP engine setup complete");
            if (UseDirectThrottle)
            {
                Debug.Log("NFPP: Using direct throttle method");
            }
        }