Пример #1
0
        private void SetNewRatios(PropellantResources propellantResources, float startingEMR, float finalEMR, float emrSplitPercentage)
        {
            Dictionary <int, float> startRatios = GetRatiosForEMR(propellantResources, startingEMR);
            Dictionary <int, float> endRatios   = GetRatiosForEMR(propellantResources, finalEMR);

            foreach (var prop in engineModule.propellants)
            {
                if (endRatios.ContainsKey(prop.id) && startRatios.ContainsKey(prop.id))
                {
                    var ratioDiff = endRatios[prop.id] - startRatios[prop.id];
                    //EMRUtils.Log("Ratio Diff for ", prop.name, ": ", ratioDiff);
                    prop.ratio = startRatios[prop.id] + ((emrSplitPercentage / 100) * ratioDiff);
                }
                else
                {
                    prop.ratio = propellantResources.GetById(prop.id).Ratio;
                }
                //EMRUtils.Log("New ratio for ", prop.name, ": ", prop.ratio);
                if (propellantResources.Oxidizer.Id == prop.id && fuelReservePercentage > 0)
                {
                    //EMRUtils.Log("Adjusting oxidizer capacity to account for boiloff");
                    prop.ratio = prop.ratio * ((100 - fuelReservePercentage) / 100);
                }
                if (propellantResources.Oxidizer.Id != prop.id && fuelReservePercentage < 0)
                {
                    //EMRUtils.Log("Adjusting fuel capacity to account for boiloff");
                    prop.ratio = prop.ratio * ((100 + fuelReservePercentage) / 100);
                }
            }
        }
Пример #2
0
        private string BuildInFlightFuelReserveText()
        {
            //EMRUtils.Log("Building new PropellantResources to build fuel reserve text");
            PropellantResources propResources = new PropellantResources(engineModule);

            Dictionary <int, double> propAmounts = new Dictionary <int, double>();

            foreach (var prop in propResources)
            {
                double propVolume;
                double propMaxVolume;
                //EMRUtils.Log("About to get In Flight Fuel Reserve Text");
                try {
                    //EMRUtils.Log("Trying to get resource totals: ", prop.Name);
                    part.GetConnectedResourceTotals(prop.Id, out propVolume, out propMaxVolume);
                    propAmounts.Add(prop.Id, propVolume / prop.Ratio);
                    //EMRUtils.Log("Found for ", prop.Name, ": ", propVolume);
                }
                catch (Exception ex) {
                    //EMRUtils.Log("Error trying to get resource ", prop.Name, " (", ex.Message, ")");
                    return("UNKNOWN");
                }
            }

            double minAmount = propAmounts.Min(item => item.Value);
            //EMRUtils.Log("Min Amount: ", minAmount);

            StringBuilder result = StringBuilderCache.Acquire();

            foreach (var kvp in propAmounts)
            {
                double propDiff = kvp.Value - minAmount;
                //EMRUtils.Log("Diff from min: ", propDiff);
                if (propDiff > 0)
                {
                    //EMRUtils.Log("Diff GT 0");
                    if (result.Length > 0)
                    {
                        result.Append(Environment.NewLine);
                        //EMRUtils.Log("Adding newline");
                    }
                    PropellantResource propResource = propResources.GetById(kvp.Key);
                    double             fuelVolume   = propDiff * propResource.Ratio;
                    if (fuelVolume * propResource.Density > .001)
                    {
                        result.Append(propResource.Name).Append(": ").Append(FormatVolumeAndMass(fuelVolume, propResource.Density));
                    }
                    //EMRUtils.Log("Text now reads: ", result);
                }
            }
            if (result.Length == 0)
            {
                result.Append("None");
            }
            return(result.ToStringAndRelease());
        }
Пример #3
0
        private void SetNeededFuel()
        {
            if (!CurrentNodePair.Disabled)
            {
                if (propellantResources == null)
                {
                    propellantResources = new PropellantResources(engineModule);
                }

                SetNewRatios(propellantResources, startingEMR, finalEMR, emrSplitPercentage);
            }
        }
Пример #4
0
        private float GetOptimalRatioForRemainingFuel()
        {
            PropellantResources propResources = new PropellantResources(engineModule);

            if (propResources == null)
            {
                EMRUtils.Log("Could not find any connected resources");
                return(CurrentNodePair.Min.ratio);
            }

            double amount;
            double maxAmount;

            EMRUtils.Log("Getting resources totals from part");

            if (part == null)
            {
                //DELETE ME
                EMRUtils.Log("I don't know how, but part is null");
            }
            part.GetConnectedResourceTotals(propResources.Oxidizer.Id, out amount, out maxAmount);

            double remainingOxidizer = amount;

            double remainingFuel = 0;

            foreach (var fuel in propResources.Fuels)
            {
                part.GetConnectedResourceTotals(fuel.Id, out amount, out maxAmount);
                remainingFuel += amount;
            }

            EMRUtils.Log("Remaining Fuel: " + remainingFuel + ", Remaining Oxidier: " + remainingOxidizer);

            if (remainingOxidizer == 0)
            {
                return(CurrentNodePair.Min.ratio);
            }
            if (remainingFuel == 0)
            {
                return(CurrentNodePair.Max.ratio);
            }

            return((float)((remainingOxidizer * propResources.Oxidizer.Density) / (remainingFuel * propResources.AverageFuelDensity)));
        }
Пример #5
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (engineModule == null)
            {
                engineModule = part.FindModuleImplementing <ModuleEngines>();
            }

            if (engineModule == null)
            {
                EMRUtils.Log("ERROR! Could not find ModuleEngines");
            }

            if (propellantResources == null)
            {
                propellantResources = new PropellantResources(engineModule);
            }

            EMRUtils.Log("Detecting configs");
            DetectConfig();
            DeserializeNodes();
            BindCallbacks();

            ToggleControlsBasedOnConfigs();
            if (!CurrentNodePair.Disabled)
            {
                SetEditorFields();
            }
            SetActionsAndGui();

            if (HighLogic.LoadedSceneIsFlight)
            {
                BindInFlightCallbacks();
                UpdateInFlightEMRParams();
            }

            UpdateIspAndThrustDisplay();
            SetNeededFuel();

            if (HighLogic.LoadedSceneIsFlight)
            {
                InFlightUIChanged(null, null);
            }
        }
Пример #6
0
        Dictionary <int, float> GetRatiosForEMR(PropellantResources propellantResources, float EMR)
        {
            // right now, the ratio is a volume ratio, so we need to convert that to a mass ratio

            // EMR = oxidizer mass flow rate
            // 1 = fuel mass flow rate

            // let's sum up all the mass flows for our fuels
            var fuelMassFlow = propellantResources.Fuels.Sum(fuel => fuel.PropellantMassFlow);
            //EMRUtils.Log("Fuel mass flow: ", fuelMassFlow);

            // oxidizer mass flow will be that times the EMR
            var oxidizerMassFlow = fuelMassFlow * EMR;
            //EMRUtils.Log("Oxidier mass flow: ", oxidizerMassFlow);

            // dividing that by density should give us the ratios tha we want
            var oxidierRatio = oxidizerMassFlow / propellantResources.Oxidizer.Density;
            //EMRUtils.Log("Oxidier ratio: ", oxidierRatio);

            Dictionary <int, float> ratios = new Dictionary <int, float>();

            ratios.Add(propellantResources.Oxidizer.Id, oxidierRatio);
            return(ratios);
        }