Exemple #1
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);
            }
        }