Ejemplo n.º 1
0
        public void SetupPropellant()
        {
            switch (type)
            {
            case ModuleType.MODULEENGINES:
                mE.SetupPropellant();
                break;

            case ModuleType.MODULEENGINESFX:
                mEFX.SetupPropellant();
                break;

            default:
                throw new InvalidProgramException();
            }
        }
Ejemplo n.º 2
0
        public void setupPropellants()
        {
            ConfigNode chosenpropellant = propellants[fuel_mode];

            ConfigNode[]      assprops            = chosenpropellant.GetNodes("PROPELLANT");
            List <Propellant> list_of_propellants = new List <Propellant>();

            // loop though propellants until we get to the selected one, then set it up
            foreach (ConfigNode prop_node in assprops)
            {
                fuelmode                 = chosenpropellant.GetValue("guiName");
                ispMultiplier            = float.Parse(chosenpropellant.GetValue("ispMultiplier"));
                isLFO                    = bool.Parse(chosenpropellant.GetValue("isLFO"));
                currentpropellant_is_jet = false;
                if (chosenpropellant.HasValue("isJet"))
                {
                    currentpropellant_is_jet = bool.Parse(chosenpropellant.GetValue("isJet"));
                }
                //print (currentpropellant_is_jet);

                Propellant curprop = new Propellant();
                curprop.Load(prop_node);
                if (curprop.drawStackGauge && HighLogic.LoadedSceneIsFlight)
                {
                    curprop.drawStackGauge = false;
                    if (currentpropellant_is_jet)
                    {
                        fuel_gauge.SetMessage("Atmosphere");
                    }
                    else
                    {
                        fuel_gauge.SetMessage(curprop.name);
                        myAttachedEngine.thrustPercentage = 100;
                        part.temperature = 1;
                    }
                    fuel_gauge.SetMsgBgColor(XKCDColors.DarkLime);
                    fuel_gauge.SetMsgTextColor(XKCDColors.ElectricLime);
                    fuel_gauge.SetProgressBarColor(XKCDColors.Yellow);
                    fuel_gauge.SetProgressBarBgColor(XKCDColors.DarkLime);
                    fuel_gauge.SetValue(0f);
                }
                list_of_propellants.Add(curprop);
            }

            // update the engine with the new propellants
            if (PartResourceLibrary.Instance.GetDefinition(list_of_propellants[0].name) != null)
            {
                myAttachedEngine.propellants.Clear();
                myAttachedEngine.propellants = list_of_propellants;
                myAttachedEngine.SetupPropellant();
            }

            if (HighLogic.LoadedSceneIsFlight)   // you can have any fuel you want in the editor but not in flight
            // should we switch to another propellant because we have none of this one?
            {
                bool next_propellant = false;
                List <Propellant> curEngine_propellants_list = new List <Propellant>();
                curEngine_propellants_list = myAttachedEngine.propellants;
                foreach (Propellant curEngine_propellant in curEngine_propellants_list)
                {
                    List <PartResource> partresources = part.GetConnectedResources(curEngine_propellant.name).ToList();

                    if (partresources.Count == 0 || !PartResourceLibrary.Instance.resourceDefinitions.Contains(list_of_propellants[0].name))
                    {
                        next_propellant = true;
                    }
                }

                // do the switch if needed
                if (next_propellant && fuel_mode != 1)
                {
                    TogglePropellant();
                }
            }
            else
            {
                if (!PartResourceLibrary.Instance.resourceDefinitions.Contains(list_of_propellants[0].name) && fuel_mode != 1)   // Still ignore propellants that don't exist
                {
                    TogglePropellant();
                }
                estimateEditorPerformance(); // update editor estimates
            }
        }
Ejemplo n.º 3
0
        private void SetupPropellants(bool moveNext)
        {
            try
            {
                Current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault();

                if ((Current_propellant.SupportedEngines & type) != type)
                {
                    _rep++;
                    togglePropellant(moveNext);
                    return;
                }

                Propellant new_propellant = Current_propellant.Propellant;
                if (fuel_gauge != null && new_propellant.drawStackGauge)
                {
                    new_propellant.drawStackGauge = false;
                    fuel_gauge.SetMessage(Current_propellant.PropellantGUIName);
                    fuel_gauge.SetMsgBgColor(XKCDColors.DarkLime);
                    fuel_gauge.SetMsgTextColor(XKCDColors.ElectricLime);
                    fuel_gauge.SetProgressBarColor(XKCDColors.Yellow);
                    fuel_gauge.SetProgressBarBgColor(XKCDColors.DarkLime);
                    fuel_gauge.SetValue(0f);
                }

                List <Propellant> list_of_propellants = new List <Propellant>();
                list_of_propellants.Add(new_propellant);
                if (!list_of_propellants.Exists(prop => PartResourceLibrary.Instance.GetDefinition(prop.name) == null))
                {
                    _attached_engine.propellants.Clear();
                    _attached_engine.propellants = list_of_propellants;
                    _attached_engine.SetupPropellant();
                }
                else if (_rep < _propellants.Count)
                {
                    _rep++;
                    togglePropellant(moveNext);
                    return;
                }


                if (HighLogic.LoadedSceneIsFlight)
                {
                    // you can have any fuel you want in the editor but not in flight
                    List <PartResource> totalpartresources = list_of_propellants.SelectMany(prop => part.GetConnectedResources(prop.name.Replace("LqdWater", "Water"))).ToList();

                    if (!list_of_propellants.All(prop => totalpartresources.Select(pr => pr.resourceName).Contains(prop.name.Replace("LqdWater", "Water"))) && _rep < _propellants.Count)
                    {
                        _rep++;
                        togglePropellant(moveNext);
                        return;
                    }
                }

                if (Current_propellant.Propellant.name == "LqdWater")
                {
                    if (fuel_gauge != null)
                    {
                        fuel_gauge.SetMessage("Water");
                    }

                    if (!part.Resources.Contains("LqdWater"))
                    {
                        ConfigNode node = new ConfigNode("RESOURCE");
                        node.AddValue("name", "LqdWater");
                        node.AddValue("maxAmount", this.maxPower / this.baseISP);
                        node.AddValue("possibleAmount", 0);
                        this.part.AddResource(node);
                        this.part.Resources.UpdateList();
                    }
                }
                else
                {
                    if (part.Resources.Contains("LqdWater"))
                    {
                        var partresource = part.Resources["LqdWater"];
                        if (partresource.amount > 0 && HighLogic.LoadedSceneIsFlight)
                        {
                            ORSHelper.fixedRequestResource(this.part, "Water", -partresource.amount);
                        }
                        this.part.Resources.list.Remove(partresource);
                        DestroyImmediate(partresource);
                    }
                }

                _rep = 0;
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError("[KSPI] - SetupPropellants ElectricEngineControllerFX " + e.Message);
            }
        }